stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <iostream>

#include<bits/stdc++.h>



using namespace std;



int main()

{   string s;

    int i ;

    string news="";

    cin>>s;

    for (i=0;i<19;i++){

        if (s[i]== ','){

            s[i]=' ';

            news=news+s[i];}

        else{

            news=news+s[i];

        }}

        cout<<news;





    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

 

int main(){

    char s[21];

    scanf ("%[^\n]", s);

    for (int i = 0; s[i] != '\0'; i++)

        if (s[i] == ',') s[i] = ' ';

    puts (s);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



int main() {

 std:: string s;

 std::cin>>s;

 if (s.size()==19){

   

    for(int i=0;i<s.size();i++){



         if(s[i]==','){

            s[i]=' ';

         }

      }



    }

    std::cout<<s;

 }

// Optimized solution to the same problem (faster):
#include <stdio.h>

 

int main(){

    char s[21];

    scanf ("%[^\n]", s);

    for (int i = 0; s[i] != '\0'; i++)

        if (s[i] == ',') s[i] = ' ';

    puts (s);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int main() {

	string x;

	cin >> x;

	for (int i = 0 ; i < int(x.size()); i++){

		if (x[i] == ','){

				x[i] = ' ';

		}

	}

	cout << x;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

 

int main(){

    char s[21];

    scanf ("%[^\n]", s);

    for (int i = 0; s[i] != '\0'; i++)

        if (s[i] == ',') s[i] = ' ';

    puts (s);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int main()

{

    string s; cin >> s;

    for (int i = 0, n = s.length(); i < n; i ++)

    {

        if (s[i] == ',')

        {

            s[i] = ' ';

        }

    }

    std::cout << s << std::endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

 

int main(){

    char s[21];

    scanf ("%[^\n]", s);

    for (int i = 0; s[i] != '\0'; i++)

        if (s[i] == ',') s[i] = ' ';

    puts (s);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    string s;

    while(cin>>s)

    {

        int len=0;

        len=s.size();

        for(int i=0;i<len;i++)

        {

            if(s[i]==',')

            {

                cout<<" ";

            }

            else

            {

                cout<<s[i];

            }

        }

        cout<<endl;

    }

   return  0;

}




// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>



int main (){

	char huruf1[1000];

	char huruf2[1000];

	char huruf3[1000];

	scanf ("%[^,],%[^,],%[^\n]", huruf1, huruf2, huruf3); getchar();

	printf ("%s %s %s\n",huruf1,huruf2,huruf3);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;



int main()

{

    string s,c;

    cin>>s;

    char x=' ';

    for (int i=0; i<s.size(); i++){

        if(s[i]==','){

            c.push_back(x);

        }

        else{

            c.push_back(s[i]);

        }

    }

    cout<<c;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

char x[105];

int main(){

	

	scanf("%s",x);

	for(int i=0;i<strlen(x);i++){

		if(x[i]==',')

			printf(" ");

		else

			printf("%c",x[i]);

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

   string s;

   cin>>s;

   for (int i=0;i<19;i++){

    if (s[i]==','){

     s[i]=' ';

    }



   }

   cout<<s;





    return 0;

}




// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

char x[105];

int main(){

	

	scanf("%s",x);

	for(int i=0;i<strlen(x);i++){

		if(x[i]==',')

			printf(" ");

		else

			printf("%c",x[i]);

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// in the name of Allah ;

#include<bits/stdc++.h>

using namespace std ;

int main ()

{

	string s ;

	cin >> s ;

	for ( int i = 0 ; i < s.size() ; i++ )

		if ( s[i] == ',' ) 

			cout << " " ;

		else

			cout << s[i] ;

	cout << endl;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

 

int main(){

    char s[25];

    scanf("%s", s);

    for(int i = 0; i<20; i++){

        if(s[i]==','){

            s[i] = ' ';

        }

    }

    printf("%s", s);

}   

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define N 1000050

using namespace std;



char a[N],b[N];

int flag,ans,n;

queue<int> q;



int main() {

	scanf("%d%s%s",&n,a+1,b+1);

	for (int _=1;_<=n;_++) if (a[_] != b[_]) flag = 1;

	if (!flag) return puts("0"), 0;

	

	int p = n;

	for (int _=n;_>=1;_--) {

		if (b[_-1] == b[_]) continue;

		p = min(p, _);

		while (p && a[p] != b[_]) p--;

		if (!p) return puts("-1"), 0;

		

		#define sz (int)q.size()

		while (!q.empty())

			if (q.front()-sz >= _) q.pop(); else break;

		q.push(p);

		_!=p ? ans = max(ans,sz) :0;

	}

	printf("%d\n",ans+1);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<vector>

using namespace std;

 

typedef long long ll;

const int MAXN=1e7+5;

 

int n,ans;

int deq[MAXN],l,r;

char s[MAXN],t[MAXN];

 

int main(){

 

    scanf("%d%s%s",&n,s+1,t+1);

    if(strcmp(s+1,t+1)==0) return puts("0"),0;

    l=1,r=0;

    for(int i=n,j=n;i>=1;i--){

        if(t[i]==t[i-1]) continue;

        j=min(i,j);

        while(j&&t[i]!=s[j]) j--;

        if(!j) return puts("-1"),0;

        while(l<=r){

            if(deq[l]-(r-l)>i) l++;

            else break;

        }

        deq[++r]=j;

        if(i!=j) ans=max(ans,r-l+1);

    }

    printf("%d",ans+1);

 

    fclose(stdin);

    fclose(stdout);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <algorithm>

#include <iostream>

#include <cstdio>

#include <queue>



const int MAXN = 1e6 + 10;



class no_solution: std::exception

{

public:

	const char * what() const noexcept

	{

		return "There is no solution under such constrains";

	}

};



int len;

char a[MAXN], b[MAXN];



auto findSolution() -> std::deque<int>::size_type

{

	std::deque<int>::size_type answer = 0;

	std::deque<int> DQ;

	DQ.push_back(len + 1);



	int k = len + 1, offset = 0;

	for (int i = len; i > 0; i--)

	{

		int t = k;

		k = std::min(i, k);

		while (k && a[k] != b[i])

			k--;

		if (k <= 0)

			throw no_solution();



		if (k == t)

		{

			while (!DQ.empty() && DQ.back() + offset >= i)

				DQ.pop_back();

			DQ.push_back(i - offset);

		}

		else

		{

			offset--;

			if (i != k)

				answer = std::max(answer, DQ.size()), DQ.push_front(k - offset);

		}

	}

	return answer;

}



int main()

{

	std::cin >> len >> (a+1) >> (b+1) ;



	try

	{

		std::cout << findSolution() << std::endl ;

	}

	catch(no_solution & x)

	{

		std::cout << "-1" << std::endl ;

		std::cerr << x.what() << std::endl ;

	}



	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<vector>

#include<queue>

#define SF scanf

#define PF printf

#define MAXN 2000010

using namespace std;

typedef long long ll;

char s[MAXN];

char t[MAXN];

int pre[MAXN];

int n,las,cnt=1,ans,add;

int main(){

	SF("%d",&n);

	SF("%s",s+1);

	SF("%s",t+1);

	int las=n;

	bool flag=0;

	for(int i=1;i<=n;i++)

		if(s[i]!=t[i])

			flag=1;

	if(flag==0){

		PF("0");

		return 0;	

	}

	int now=1;

	for(int i=n;i>=1;i--){

		if(i==1||t[i]!=t[i-1]){

			las=min(las,i);

			while(las>0&&s[las]!=t[i])

				las--;

			if(las==0){

				PF("-1");

				return 0;

			}

			add++;

			pre[las+add]--;

			if(las+add>=i+add)

				now--;

			now++;

			ans=max(ans,now);

			continue;

		}

		now+=pre[i+add];

	}

	PF("%d",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<queue>

#include<algorithm>

using namespace std;

int n;

char a[1000010],b[1000010];

int main(){

	scanf("%d",&n);

	scanf("%s",a+1);

	scanf("%s",b+1);

	bool flag=1;

	for(int i=1;i<=n;++i)if(a[i]!=b[i])flag=0;

	if(flag){

		cout<<0;

		return 0;

	}

	queue<int> q;

	int pos=n,ans=0;

	for(int i=n;i>=1;--i){

		if(b[i]==b[i-1])continue;

		pos=min(pos,i);

		while(pos&&a[pos]!=b[i])pos--;

		if(!pos){

			cout<<-1;

			return 0;

		}

		while(!q.empty()){

			if(q.front()-q.size()>=i)q.pop();

			else break;

		}

		q.push(pos);

		if(i!=pos)ans=max(ans,(int)q.size());

	}

	cout<<ans+1;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>



const int maxn=1000000;



int n,ans,sum[maxn+10];

char s[maxn+10],t[maxn+10];



int main()

{

  scanf("%d%s%s",&n,s+1,t+1);

  if(s[1]!=t[1])

    {

      puts("-1");

      return 0;

    }

  int f=0,k=0,now=n;

  for(int i=n; i; --i)

    {

      f+=sum[i+k];

      if((now>i)||(t[i]!=s[now]))

        {

          while((now>0)&&((now>i)||(t[i]!=s[now])))

            {

              --now;

            }

          if(now==i)

            {

              continue;

            }

          if(now<=0)

            {

              puts("-1");

              return 0;

            }

          ++k;

          ++f;

          sum[i+k-1]=0;

          --sum[now+k-1];

        }

      ans=std::max(ans,f);

    }

  printf("%d\n",ans);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <sstream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <cstring>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <iterator>

#include <bitset>

#include <ctime>

#include<complex>

using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)

#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



#define SZ(a) (int)a.size()

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 1000 * 1000 + 47;



int SH[MAX];

int R[MAX];

int L[MAX];

int H[MAX];



string s, t;



void imp()

{

	cout << -1 << endl;

	exit(0);

}



int main()

{

	//freopen("in.txt", "r", stdin);

	//freopen("out.txt", "w", stdout);

	ios::sync_with_stdio(false); cin.tie(0);

	int n;

	cin >> n >> s >> t;

	if (s == t)

	{

		cout << 0 << endl;

		return 0;

	}



	FOR(i, 0, n)

	{

		R[i] = -1;

	}

	int p = n - 1;



	RFOR(i, n, 0)

	{

		while (p != -1 && t[i] != s[p]) p--;

		if (p == -1) imp();

		L[p] = i;

		R[p] = max(i, R[p]);

		if (i == p) p--;

	}



	int sh = 0, add = 0;

	int ans = 0;

	RFOR(i, n, 0)

	{

		H[i + sh] = -add;

		if (R[i] == -1)

		{

			continue;

		}



		ans = max(ans, H[R[i] + sh] + add + 1);

		sh++;

		add++;

	}



	//FOR(i, 0, n)

	//{

	//	cout << R[i] << " ";

	//}

	//cout << endl;

	//FOR(i, 0, n)

	//{

	//	cout << H[i] << " ";

	//}

	//cout << endl;

	cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#define MAXN 1000006

#include<algorithm>

using namespace std;

int ans,n,l,cnt,r,q[MAXN];

char s[MAXN],t[MAXN];

int main()

{

	//freopen("blank.in","r",stdin);

	//freopen("blank.out","w",stdout);

	scanf("%d",&n);

	scanf("%s",s+1);

	scanf("%s",t+1);

	l=1;

	if(!strcmp(s+1,t+1))

	{

		printf("0");

		return 0;

	}

	for(int i=n,j=n;i>=1;i--)

	{

		if(t[i]==t[i-1]) continue;

		j=min(i,j);

		while(j&&t[i]!=s[j]) 

			j--;

		if(!j)

		{

			printf("-1");

			return 0;

		}

		while(l<=r)

		{

			if(q[l]-(r-l)>i) l++;

			else break;

		}

		q[++r]=j;

		if(i!=j) ans=max(ans,r-l+1);

	}

	printf("%d\n",++ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//#pragma GCC optimize(3)

#include<iostream>

#include<iomanip>

#include<stack>

#include<queue>

#include<list>

#include<vector>

#include<set>

#include<map>

#include<string>

#include<algorithm>

#include<cmath>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<ctime>

#define ll long long

#define db double

#define mxlen 1000+9

#define inf 1000009

#define INF (int)1e9

#define pi acos(-1)

#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}

using namespace std;



char s1[inf],s2[inf];

int q[inf*2],head=inf,tail=inf-1;



int main(){

	int n;

	rd(n)

	scanf("%s%s",&s1,&s2);

	q[++tail]=n+1;

	int pos=n+1,cnt=0,ans=0;

	for (int i=n;i>=1;i--){

		int tmp=pos;

		while (pos>0 && (pos>i || s1[pos-1]!=s2[i-1])){

			pos--;

		}

		if (pos==0){

			puts("-1");

			return 0;

		}

		if (tmp==pos){

			while (head<=tail && q[tail]-cnt>=i){

				tail--;

			}

			q[++tail]=i+cnt;

		}

		else{

			cnt++;

			if (i!=pos){

				ans=max(ans,tail-head+1);

				q[--head]=pos+cnt;

			}

		}

	}

	printf("%d\n",ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const int N=1145141;

int n;

char s0[N],s1[N];

int pre[N],lst[133];

int g[N];

int ans,tmp;

int main()

{

	scanf("%d%s%s",&n,s0+1,s1+1);

	int k=0,nw=n;

	for(int i=n;i;i--)

	{

		tmp+=g[i+k];

		if(nw>i||(s0[nw]!=s1[i]))

		{

			while(nw>0&&(nw>i||(s0[nw]!=s1[i]))) nw--;

			if(nw==i) continue;

			if(nw<=0){puts("-1");return 0;}

			k++,tmp++;

			g[i+k-1]=0,g[nw+k-1]--;

		}

		ans=max(ans,tmp);

	}

	printf("%d\n",ans);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define MAXN 1000005

using namespace std;



int n,pos,ans,head,tail;

int q[MAXN];

char s[MAXN],t[MAXN];



int min(int a,int b) {return a<b?a:b;}

int max(int a,int b) {return a>b?a:b;}



template<class T>inline void read(T &res)

{

    static char ch;T flag=1;

    while((ch=getchar())<'0'||ch>'9')if(ch=='-')flag=-1;res=ch-48;

    while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;res*=flag;

}



int main()

{

    read(n);

    scanf("%s%s",s+1,t+1);

    if(strcmp(s+1,t+1)==0){putchar('0');return 0;}

    pos=n;head=1;tail=0;

    for(int i=n;i>=1;i--)

    {

        if(t[i]==t[i-1]) continue;

        pos=min(pos,i);

        while(pos&&t[i]!=s[pos]) pos--;

        if(pos==0) {putchar('-');putchar('1');return 0;}

        while(head<=tail)

        {

            if(q[head]-(tail-head+1)+1>i) head++;

            else break;

        }

        q[++tail]=pos;

        if(i!=pos) ans=max(ans,tail-head+1);

    }

    printf("%d\n",ans+1);

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const int N=1145141;

int n;

char s0[N],s1[N];

int pre[N],lst[133];

int g[N];

int ans,tmp;

int main()

{

	scanf("%d%s%s",&n,s0+1,s1+1);

	int k=0,nw=n;

	for(int i=n;i;i--)

	{

		tmp+=g[i+k];

		if(nw>i||(s0[nw]!=s1[i]))

		{

			while(nw>0&&(nw>i||(s0[nw]!=s1[i]))) nw--;

			if(nw==i) continue;

			if(nw<=0){puts("-1");return 0;}

			k++,tmp++;

			g[i+k-1]=0,g[nw+k-1]--;

		}

		ans=max(ans,tmp);

	}

	printf("%d\n",ans);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)

#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)

#define EREP(i,u) for(int i=start[u];i;i=e[i].next)

#define fi first

#define se second

#define mkr(a,b) make_pair(a,b)

#define SZ(A) ((int)A.size())

template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}

template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}

inline int read()

{

	int s=0,f=1; char ch=getchar();

	while(!isdigit(ch) && ch!='-')ch=getchar();

	if(ch=='-')ch=getchar(),f=-1;

	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();

	return ~f?s:-s;

}



const int maxn=1e6+20;



int n;

char S[maxn],T[maxn];



inline void init()

{

	n=read();

	scanf("%s",S+1);

	scanf("%s",T+1);

}



int ans;



inline void doing()

{

	deque<int>q;q.push_back(n+1);

	for(int i=n,j=n+1,del=0;i;i--)

	{

		int tmp=j;

		while(j && (j>i || S[j]!=T[i]))j--;

		if(!j)puts("-1"),exit(0);

		if(j==tmp)

		{

			while(!q.empty() && q.back()-del>=i)q.pop_back();

			q.push_back(i+del); 

		}else

		{

			del++;

			if(i!=j)

			{

				chkmax(ans,SZ(q));

				q.push_front(j+del);

			}

		}

	}

	printf("%d\n",ans);

}



int main()

{

	init();

	doing();

	return 0;

}




// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const int N=1e6;

int n,s[N+1],t[N+1];

int hea=1,tai,que[N+1];

int res;

void input(int x[])

{

	static char str[N+2];

	scanf("%s",str+1);

	for(int i=1;i<=n;++i) {

		x[i]=str[i]-'a';

	}

	return;

}

bool check0()

{

	for(int i=1;i<=n;++i) {

		if(s[i]!=t[i]) {

			return false;

		}

	}

	return true;

}

int main()

{

	scanf("%d",&n);

	input(s);

	input(t);

	if(check0()) {

		puts("0");

		return 0;

	}

	for(int spos=n,tpos=n;tpos;--tpos) {

		while((tpos>1)&&(t[tpos-1]==t[tpos])) {

			--tpos;

		}

		while(spos&&((spos>tpos)||(s[spos]!=t[tpos]))) {

			--spos;

		}

		if(!spos) {

			puts("-1");

			return 0;

		}

		while((hea<=tai)&&(que[hea]-(tai-hea+1)+1>tpos)) {

			++hea;

		}

		que[++tai]=spos;

		if(tpos!=1) {

			res=max(res,tai-hea+1);

		}

	}

	++res;

	printf("%d\n",res);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<queue>

using namespace std;

#define N 1000005

queue<int> q;

char a[N],b[N];

int main()

{

	int n,i,j,ans=0;

	scanf("%d%s%s",&n,a+1,b+1);

	if(strcmp(a+1,b+1)==0){printf("0");return 0;}

	i=j=n;

	while(j){

		while(j&&b[j]==b[j-1])j--;

		while(i&&(i>j||a[i]!=b[j]))i--;

		if(i==0){printf("-1");return 0;}

		while(!q.empty()&&q.front()-(int)q.size()>=j)q.pop();

		if(i!=j)q.push(i);

		ans=max(ans,(int)q.size()+1);

		j--;

	}

	printf("%d",ans);

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const int N=1e6;

int n,s[N+1],t[N+1];

int hea=1,tai,que[N+1];

int res;

void input(int x[])

{

	static char str[N+2];

	scanf("%s",str+1);

	for(int i=1;i<=n;++i) {

		x[i]=str[i]-'a';

	}

	return;

}

bool check0()

{

	for(int i=1;i<=n;++i) {

		if(s[i]!=t[i]) {

			return false;

		}

	}

	return true;

}

int main()

{

	scanf("%d",&n);

	input(s);

	input(t);

	if(check0()) {

		puts("0");

		return 0;

	}

	for(int spos=n,tpos=n;tpos;--tpos) {

		while((tpos>1)&&(t[tpos-1]==t[tpos])) {

			--tpos;

		}

		while(spos&&((spos>tpos)||(s[spos]!=t[tpos]))) {

			--spos;

		}

		if(!spos) {

			puts("-1");

			return 0;

		}

		while((hea<=tai)&&(que[hea]-(tai-hea+1)+1>tpos)) {

			++hea;

		}

		que[++tai]=spos;

		if(tpos!=1) {

			res=max(res,tai-hea+1);

		}

	}

	++res;

	printf("%d\n",res);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
// LNU_Algotesters

#include <iostream>

#include <sstream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <cstring>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <iterator>

#include <bitset>

#include <ctime>

#include <fstream>

#include <complex>

using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)

#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



#define SZ(a) (int)a.size()

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL) INF;



const int MAX = 100 * 10000 + 47;





int W[MAX];

bool U[MAX];

int X[MAX];



int main()

{

    

    //freopen("in.txt", "r", stdin);

    //ios::sync_with_stdio(false); cin.tie(0);

    

    int n;

    cin >> n;

    string S, T;

    cin >> S >> T;

    int idx = n - 1;

    FILL(W, -1);

    RFOR(i, n, 0)

    {

        while(idx >= 0 && (idx > i || S[idx] != T[i]))--idx;

        W[i] = idx;

        U[idx] = 1;

        X[idx] = max(X[idx], i);

    }

    

    if (S == T)

    {

        cout << 0 << endl;

        return 0;

    }

    

    FOR(i, 0, n)

        if (W[i] == -1)

        {

            cout << -1 << endl;

            return 0;

        }

    

    vector<PII> V;

    

    FOR(i, 0, n)

        if (U[i])V.PB(MP(i, X[i]));

    

    int ans = 0;

    

    FOR(i, 0, SZ(V))

    {

        int L = i, R = SZ(V);

        while(R - L > 1)

        {

            int M = (R + L) / 2;

            if (V[M].first + i >= V[i].second + M)

                R = M;

            else L = M;

        }

        ans = max(ans, R - i);

    }

    cout << ans << endl;

    

    

}








// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;



const int _ = 1e6 + 7;

vector < int > pot[26];

int N; char S[_] , T[_];



int main(){

	scanf("%d %s %s" , &N , S , T);

	for(int i = 0 ; i < N ; ++i) pot[S[i] - 'a'].push_back(i);

	int mx = 0 , mrk = 0; char curc; deque < int > q; q.push_back(1e9);

	for(int i = N - 1 ; ~i ; --i){

		if((q.front() + mrk <= i ? curc : S[i]) != T[i]){

			if(pot[T[i] - 'a'].empty()){puts("-1"); return 0;}

			int t = pot[T[i] - 'a'].back(); curc = T[i];

			for(int j = min(i , q.front() + mrk - 1) ; j >= t ; --j) pot[S[j] - 'a'].pop_back();

			--mrk; q.push_front(t - mrk); while(q.back() + mrk >= i) q.pop_back();

			q.push_back(i - mrk); mx = max(mx , (int)q.size() - 1);

		}

		if(q.front() + mrk > i) pot[S[i] - 'a'].pop_back();

	}

	cout << mx; return 0;

}

// Fastest known solution for this problem: