#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#define BASE 7
using namespace std;

int main() 
{
	long long pow[10], a = 1;
	for (int i = 1; i < 10; ++i)
	{
		a *= BASE;
		pow[i] = a;
	}
	pow[0] = 1;
	long long hash[10];
	memset (hash, 0, sizeof(hash));
	string s = "abcdab";
	for (int i = s.size()-1; i >= 0; --i)
	{
		if (i < s.size()-1)
			hash[i] = hash[i+1] * BASE;
		hash[i] += (s[i] - 'a') + 1;	
	}
	printf ("Hash of 'abc' is %d\n", hash[0] - (hash[3] * pow[strlen("abc")]));
	return 0;
}