#include <bits/stdc++.h>
#define gc getchar
#define pc putchar
using namespace std;
/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
*/
/*
two functions for policy based data structure. it is
find_by_order() and order_of_key().
The first returns an iterator to the k-th largest element (counting from zero),
the second returns the number of items in a set that are strictly smaller than our item
*/
#define vi vector<int>
#define si set<int>
#define vs vector<string>
#define pii pair<int,int>
#define vpi vector<pii>
#define pri priority_queue<int>
#define rev_pri priority_queue<int,vector<int>,greater<int> >
#define mpi map<int,int>
#define i64 long long int
#define endl '\n'
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Rep(i,x,y) for(int i=x;i<=y;i++)
#define eps 1e-8
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt","w", stdout)
#define sz size()
#define dbg(x) printf("yo is %d!\n",x)
#define dbg2(x,y) printf("yo is %d! and %d!\n",x,y)
#define foreach(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define sqr(a) (a) * (a)
#define clr clear()
#define CASE(a) printf("Case %d: ",a)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
//int dx[] = {0,1,0,-1};
//int dy[] = {1,0,-1,0};
//int dx[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
//int dy[] = { 0, -1, -1, -1, 0, 1, 1, 1 };
//int dxK[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
//int dyK[] = { -1, 1, 2, 2, 1, -1, -2, -2 };
//functions
//i64 gcd(i64 a,i64 b){if(!b)return a;return gcd(b,a%b);}
//inline void fastRead(i64 *a){register char c=0;while(c<33)c=gc();*a=0;while(c>33){*a=*a*10+c-'0';c=gc();}}
//inline void fastWrite(int a){char snum[20];int i=0;do{snum[i++]=a%10+48;a=a/10;}while(a!=0);i=i-1;while(i>=0)pc(snum[i--]);pc('\n');}
//i64 bigmod(i64 num,i64 n){if(!n)return 1;i64 x=(bigmod(num,n/2)*bigmod(num,n/2))%mod;if(n%2)x=(x*num)%mod;return x;}
//i64 modinverse(i64 num){return bigmod(num,mod-2);}
//void combination(int pos,int last){if(pos==k+1){for(int i=1;i<=k;i++)cout << tem[i];cout << endl;return;}
//for(int i=last+1;i<=n-k+pos;i++){tem[pos] = num[i-1];combination(pos+1,i);}}
//i64 power(i64 value, i64 base){i64 result = 1;For(i,base)result *= value;return result;}
//int Set(int N,int pos){return N = (1<<pos);}
//int reset(int N,int pos){return N &= (~(1<<pos));}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
//typedef tree< int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > Set;
i64 bigmod(i64 num,i64 n) // used to calculate num^n
{
if(n==0)
return 1;
i64 x = bigmod(num,n/2);
x = x*x%mod;
if(n%2==1)
x = x*num % mod;
return x;
}
i64 modinverse(i64 num)
{
return bigmod(num,mod-2) % mod;
}
#define MAX 250005
#define p1 281
#define p2 283
#define mod1 1000000007
#define mod2 1000000009
i64 pr1[MAX], pr2[MAX];
i64 h1, h2, h3, h4;
void prime_calc()
{
pr1[0] = 1;
pr2[0] = 1;
Rep(i,1,MAX-1)
{
pr1[i] = (pr1[i-1] * p1) % mod1;
pr2[i] = (pr2[i-1] * p2) % mod2;
}
}
int main()
{
prime_calc();
int n;
cin >> n;
string s1, s2;
cin >> s1 >> s2;
if(s1==s2)
{
cout << 0 << endl;
return 0;
}
int cnt = 0;
// calculating hash values of s1 and s2
for(int i = s1.sz-1; i>=0; i--)
{
h1 += (s1[i]*pr1[cnt])%mod1;
h1 %= mod1;
h2 += (s1[i]*pr2[cnt])%mod2;
h2 %= mod2;
h3 += (s2[i]*pr1[cnt])%mod1;
h3 %= mod1;
h4 += (s2[i]*pr2[cnt])%mod2;
h4 %= mod2;
cnt++;
}
//cout << h1 << " " << h2 << " " << h3 << " " << h4 << endl;
Rep(i,1,n-1)
{
//pulling from last
h1 = (h1-s1[n-i]+mod1)%mod1;
h1 = h1*modinverse(p1);
h1 %= mod1;
//pulling from last
h2 = (h2-s1[n-i]+mod2)%mod2;
h2 = h2*modinverse(p2);
h2 %= mod2;
// adding to first
h1 += (s1[n-i]*pr1[n-1])%mod1;
h1 %= mod1;
//adding to first
h2 += (s1[n-i]*pr2[n-1])%mod2;
h2 %= mod2;
cout << h1 << " " << h2 << " " << h3 << " " << h4 << endl;
if(h1==h3 && h2==h4)
{
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgoKI2RlZmluZSBnYyBnZXRjaGFyCiNkZWZpbmUgcGMgcHV0Y2hhcgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8qI2luY2x1ZGUgPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+CiNpbmNsdWRlIDxleHQvcGJfZHMvZGV0YWlsL3N0YW5kYXJkX3BvbGljaWVzLmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy9hc3NvY19jb250YWluZXIuaHBwPgoKdXNpbmcgbmFtZXNwYWNlIF9fZ251X3BiZHM7CiovCgovKgogICAgICAgIHR3byBmdW5jdGlvbnMgZm9yIHBvbGljeSBiYXNlZCBkYXRhIHN0cnVjdHVyZS4gaXQgaXMKCiAgICAgICAgICAgICAgICBmaW5kX2J5X29yZGVyKCkgYW5kIG9yZGVyX29mX2tleSgpLgoKICAgICAgICBUaGUgZmlyc3QgcmV0dXJucyBhbiBpdGVyYXRvciB0byB0aGUgay10aCBsYXJnZXN0IGVsZW1lbnQgKGNvdW50aW5nIGZyb20gemVybyksCiAgICAgICAgdGhlIHNlY29uZCByZXR1cm5zIHR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