## Editorial for Hiệu chỉnh văn bản

Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

#### Code mẫu của flashmt

var n,kq:byte;
a,b:string;
procedure re;
begin
end;
procedure pr;
var la,i,j,k:byte; kt:boolean; c:string;
begin
kq:=0;
repeat
kt:=false;
la:=length(a);
for i:=la downto n do
begin
for j:=1 to la-i+1 do
begin
c:=copy(a,j,i);
k:=pos(c,b);
if k>0 then
begin
inc(kq);
kt:=true;
delete(b,k,i);
delete(a,j,i);
end;
if kt then break;
end;
if kt then break;
end;
until not kt;

end;
procedure wr;
begin
writeln(kq);
writeln(a);
write(b);
end;
begin
re;
pr;
wr;
end.


#### Code mẫu của happyboy99x

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

char s[51], p[51], t[51];
int k;

int main() {
scanf("%d%s%s",&k,s,p); int res = 0;
for(bool stop = false; !stop; ) {
stop = true;
for(int l = min(strlen(s), strlen(p)), cont = true; l >= k && cont; --l) {
for(int n = strlen(s), i = 0; i <= n - l; ++i) {
strncpy(t, s+i, l); t[l] = 0;
char * tmp = strstr(p, t);
if(tmp != NULL) {
strcpy(s+i, s+i+l); strcpy(tmp, tmp+l);
cont = stop = false; ++res; break;
}
}
}
}
printf("%d\n%s\n%s\n", res, s, p);
return 0;
}


program nkedit;
uses     math;
const    fi='';
var      a,b:string;
k,res:longint;

procedure input;
var     f:text;
begin
assign(f,fi);
reset(f);
close(f);
end;

procedure process;
var     i,j,startA,startB,maxL,s,t:longint;
begin
res:=0;
repeat
maxL:=0;
for i:=1 to length(a) do
begin
for t:=1 to length(b) do
begin
s:=t;
j:=t;
while (j<=length(b)) and (i+j-t<=length(a)) and (b[j]=a[i+j-t]) do inc(j);
if maxL<(j-s) then
begin
maxL:=j-s;
startA:=i;
startB:=s;
end;
end;
end;
if maxL<k then break;
inc(res);
delete(a,startA,maxL);
delete(b,startB,maxL);
until maxL<k;
end;

begin
input;
process;
writeln(res);
writeln(a);
writeln(b);
end.


#### Code mẫu của RR

{\$R+,Q+}
uses math;
const
FINP='';
FOUT='';
MAXN=51;
var
x,y,count,k:longint;
s1,s2:string;
f1,f2:text;
procedure openF;
begin
assign(f1,FINP); reset(f1);
assign(f2,FOUT); rewrite(f2);
end;
procedure closeF;
begin
close(f1); close(f2);
end;
procedure inp;
begin
end;
procedure ans;
begin
writeln(f2,count);
writeln(f2,s1);
writeln(f2,s2);
end;
function find(var start1,start2:longint):longint;
var
i,j,ln,l,u,v:longint;
begin
ln:=-1;
for u:=1 to x do
for v:=1 to y do
begin
i:=u; j:=v; l:=0;
while (i<=x) and (j<=y) and (s1[i]=s2[j]) do
begin
inc(l);
inc(i); inc(j);
end;
if l>ln then
begin
ln:=l;
start1:=u;
start2:=v;
end;
end;
find:=ln;
end;
procedure solve;
var
ln,i,j:longint;
begin
count:=0;
ln:=find(i,j);
while ln>=k do
begin
inc(count);
delete(s1,i,ln);
delete(s2,j,ln);
x:=length(s1); y:=length(s2);
ln:=find(i,j);
end;
end;
begin
openF;
inp;
solve;
ans;
closeF;
end.


#### Code mẫu của hieult

#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
//#include <conio.h>

using namespace std;

void FailureFunction(char P[],int F[],int m)
{
int i,j;
F[0] = 0;
j = 0;
i = 1;
while(i<m)
{
if(P[i] == P[j])
{
F[i] = j+1;
i++;
j++;
}
else if(j>0)
j = F[j-1];
else
{
F[i] = 0;
i++;
}
}
}

int KMP(int n,char T[],int m, char P[])
{
int i,j,F[100];
FailureFunction(P,F,m);
i = 0;
j = 0;
while(i<n)
{
if(T[i] == P[j])
{
if(j == m-1)
return i-j;
else
{
i++;
j++;
}
}
else if(j>0)
j = F[j-1];
else i++;
}
return -1;
}

int main()
{
// freopen("NKEDIT.in","r",stdin);
int k,n,m,chay=0;
char s[52],p[52],the[52];
scanf("%d",&k);
scanf("%s %s",s,p);
n = strlen(s); m = strlen(p);
while(true)
{
int flag = 0;
for(int i = n;i>=k;i--)
{
for(int j = 0;j<=n-i;j++)
{
for(int k = 0;k<=i-1;k++)
the[k] = s[k+j];
int pos = KMP(m,p,i,the);
if(pos!=-1)
{
chay++;
flag = 1;
for(int k = j;k<=n-i-1;k++)
s[k] = s[k+i];
for(int k = pos;k<=m-i-1;k++)
p[k] = p[k+i];
n = n-i;
m = m-i;
}
if( flag ==1)
break;
}
if(flag == 1)
break;
}
if(flag ==0)
break;
}
printf("%d\n",chay);
for(int i = 0;i<n;i++)
printf("%c",s[i]);
printf("\n");
for(int i = 0;i<m;i++)
printf("%c",p[i]);
//getch();
}


#### Code mẫu của ll931110

Program NKEDIT;
Const
input  = '';
output = '';
Var
k,count: integer;
s1,s2: string;

Procedure init;
Var

f: text;
Begin
Assign(f, input);
Reset(f);

Close(f);
End;

Procedure solve;
Var
i,j,pos1,pos2,num: integer;
max,max1,max2: integer;
Begin
count:= 0;
Repeat
max:= 0;

For i:= 1 to length(s1) do
For j:= 1 to length(s2) do if s1[i] = s2[j] then
Begin
pos1:= i;
pos2:= j;
num:= 1;

While (pos1 < length(s1)) and (pos2 < length(s2)) do
Begin
inc(pos1);
inc(pos2);

If s1[pos1] = s2[pos2] then inc(num) else break;
End;

If s1[pos1] <> s2[pos2] then
Begin
dec(pos1);
dec(pos2);
End;

If max < num then
Begin
max:= num;
max1:= pos1 - max + 1;
max2:= pos2 - max + 1;
End;
End;

If max < k then break;

inc(count);
Delete(s1, max1, max);
Delete(s2, max2, max);

Until false;
End;

Procedure printresult;
Var
f: text;
Begin
Assign(f, output);
Rewrite(f);

Writeln(f, count);
Writeln(f, s1);
Writeln(f, s2);

Close(f);
End;

Begin
init;
solve;
printresult;
End.


#### Code mẫu của skyvn97

program NKEDIT;
uses crt;
var
s,p:string;
c,k:integer;
f:array [1..50,1..50] of integer;
procedure init;
begin
c:=0;
end;
procedure process;
var
i,j,max,wi,wj:integer;
begin
repeat
max:=-1;
for i:=1 to length(s) do
if s[i]=p[1] then f[i][1]:=1 else f[i][1]:=0;
for i:=1 to length(p) do
if s[1]=p[i] then f[1][i]:=1 else f[1][i]:=0;
for i:=2 to length (s) do
for j:=2 to length(p) do
if s[i]=p[j] then f[i][j]:=f[i-1][j-1]+1 else f[i][j]:=0;
for i:=1 to length(s) do
for j:=1 to length(p) do
if f[i][j]>max then
begin
max:=f[i][j];
wi:=i-max+1;
wj:=j-max+1;
end;
if max>=k then
begin
delete(s,wi,max);
delete(p,wj,max);
inc(c);
end;
until max<k;
end;
procedure print;
begin
writeln(c);
writeln(s);
writeln(p);
end;
begin
init;
process;
print;
end.