#include <bits/stdc++.h>
using namespace std;
const int MAXN=300000;
const int P=31;
const int MOD=1e9+7;
int pow_P[MAXN+7];
int h[MAXN+7];
int h_rev[MAXN+7];
void powing(int n){
pow_P[0]=1;
for(int i=1;i<=n;i++){
pow_P[i]=((long long)P*pow_P[i-1])%MOD;
}
}
void hashing(string s,int n){
h[0]=((long long)s[0]*pow_P[0]+MOD)%MOD;
for(int i=1;i<n;i++){
h[i]=(h[i-1]+(long long)s[i]*pow_P[i]+MOD)%MOD;
}
}
void hashing_rev(string s,int n){
h_rev[0]=((long long)s[n-1]*pow_P[0]);
for(int i=2;i<n-1;i++){
h_rev[i-1]=(h_rev[i-2]+(long long)s[n-i]*pow_P[i-1]+MOD)%MOD;
}
}
int main() {
int n;cin>>n;
string s,s_rev;cin>>s>>s_rev;
powing(n);
hashing(s,n);
hashing_rev(s_rev,n);
cout<<h[0]<<" "<<h[1]<<endl;
cout<<h_rev[0]<<" "<<h_rev[1]<<endl;
cout<<pow_P[0]<<" "<<pow_P[1]<<" "<<pow_P[2]<<endl;
cout<<h_rev[2-1]<<'='<<h_rev[2-2]<<"+"<<s_rev[n-2]<<"*"<<pow_P[2-1]<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBNQVhOPTMwMDAwMDsKY29uc3QgaW50IFA9MzE7CmNvbnN0IGludCBNT0Q9MWU5Kzc7CmludCBwb3dfUFtNQVhOKzddOwppbnQgaFtNQVhOKzddOwppbnQgaF9yZXZbTUFYTis3XTsKCgp2b2lkIHBvd2luZyhpbnQgbil7Cglwb3dfUFswXT0xOwoJZm9yKGludCBpPTE7aTw9bjtpKyspewoJCXBvd19QW2ldPSgobG9uZyBsb25nKVAqcG93X1BbaS0xXSklTU9EOwkKCX0KfQp2b2lkIGhhc2hpbmcoc3RyaW5nIHMsaW50IG4pewoJaFswXT0oKGxvbmcgbG9uZylzWzBdKnBvd19QWzBdK01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