#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#define BASE 163
#define MOD 1000000007
using namespace std;
int main()
{
long long pow[10], a = 1;
for (int i = 1; i < 10; ++i)
{
a *= BASE;
pow[i] = a % MOD;
}
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) % MOD;
hash[i] += s[i];
hash[i] %= MOD;
}
for (int i = 0; i < s.size(); ++i)
printf ("%d\n", hash[i]);
printf ("Hash of 'abc' is %d\n", hash[0] - ((hash[3] * pow[strlen("abc")]) % MOD));
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y3N0cmluZz4KI2RlZmluZSBCQVNFIDE2MwojZGVmaW5lIE1PRCAxMDAwMDAwMDA3CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIAp7Cglsb25nIGxvbmcgcG93WzEwXSwgYSA9IDE7Cglmb3IgKGludCBpID0gMTsgaSA8IDEwOyArK2kpCgl7CgkJYSAqPSBCQVNFOwoJCXBvd1tpXSA9IGEgJSBNT0Q7Cgl9Cglwb3dbMF0gPSAxOwoJbG9uZyBsb25nIGhhc2hbMTBdOwoJbWVtc2V0IChoYXNoLCAwLCBzaXplb2YoaGFzaCkpOwoJc3RyaW5nIHMgPSAiYWJjZGFiIjsKCWZvciAoaW50IGkgPSBzLnNpemUoKS0xOyBpID49IDA7IC0taSkKCXsKCQlpZiAoaSA8IHMuc2l6ZSgpLTEpCgkJCWhhc2hbaV0gPSAoaGFzaFtpKzFdICogQkFTRSkgJSBNT0Q7CgkJaGFzaFtpXSArPSBzW2ldOwoJCWhhc2hbaV0gJT0gTU9EOwoJfQoJZm9yIChpbnQgaSA9IDA7IGkgPCBzLnNpemUoKTsgKytpKQoJCXByaW50ZiAoIiVkXG4iLCBoYXNoW2ldKTsKCXByaW50ZiAoIkhhc2ggb2YgJ2FiYycgaXMgJWRcbiIsIGhhc2hbMF0gLSAoKGhhc2hbM10gKiBwb3dbc3RybGVuKCJhYmMiKV0pICUgTU9EKSk7CQoJcmV0dXJuIDA7Cn0=