#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y3N0cmluZz4KI2RlZmluZSBCQVNFIDcKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgCnsKCWxvbmcgbG9uZyBwb3dbMTBdLCBhID0gMTsKCWZvciAoaW50IGkgPSAxOyBpIDwgMTA7ICsraSkKCXsKCQlhICo9IEJBU0U7CgkJcG93W2ldID0gYTsKCX0KCXBvd1swXSA9IDE7Cglsb25nIGxvbmcgaGFzaFsxMF07CgltZW1zZXQgKGhhc2gsIDAsIHNpemVvZihoYXNoKSk7CglzdHJpbmcgcyA9ICJhYmNkYWIiOwoJZm9yIChpbnQgaSA9IHMuc2l6ZSgpLTE7IGkgPj0gMDsgLS1pKQoJewoJCWlmIChpIDwgcy5zaXplKCktMSkKCQkJaGFzaFtpXSA9IGhhc2hbaSsxXSAqIEJBU0U7CgkJaGFzaFtpXSArPSAoc1tpXSAtICdhJykgKyAxOwkKCX0KCXByaW50ZiAoIkhhc2ggb2YgJ2FiYycgaXMgJWRcbiIsIGhhc2hbMF0gLSAoaGFzaFszXSAqIHBvd1tzdHJsZW4oImFiYyIpXSkpOwoJcmV0dXJuIDA7Cn0=