#include #include using namespace std; using namespace atcoder; typedef long long ll; const int INF = 1<<30; vector manacher(string s){ int i = 0, j = 0; vectorret(s.size()); while(i < s.size()){ while(i-j>=0&&i+j=0&&k+ret[i-k]> N >> M; string S, T; cin >> S; cin >> T; if(M%2==1){cout << -1 << endl;return 0;} for(int i=0;idp(M,INF); for(int i=0;i=M||S[i]!=T[i])break; dp[i] = 1; } for(int i=0;i=M||S[N-1-i]!=T[i])break; dp[i] = 1; } string tt = ""; for(int i=0;imc = manacher(tt); vectorR(M); for(int i=0;i>G(M,vector()); for(int i=0;i0){ G[i].push_back(((i+R[i])<<1)|1); } } dequebfs; for(int i=0;i>1; if(dp[nx]>dp[v]+c){ dp[nx] = dp[v] + c; if(c)bfs.push_back(nx); else bfs.push_front(nx); } } } if(dp[M-1]==INF)cout << -1 << endl; else cout << dp[M-1] << endl; return 0; }