#include<stdio.h>
#include<string.h>
#define si 3005
#define min(a,b) (a<b?a:b)
int dp[si][si],l1,l2,dir[si][si];
char ch1[si],ch2[si];
int rec(int i,int j)
{
if(i<0&&j<0)
return 0;
else if(i<0||j<0)
return i<0?(j+1):(i+1);
int &ret=dp[i][j];
if(ret!=-1)
return ret;
int p1=rec(i,j-1)+1; //del
int p2=rec(i-1,j)+1; //add
int p3;
if(ch1[i]==ch2[j])
p3=rec(i-1,j-1);
else
p3=rec(i-1,j-1)+1;
if(p1<=p2&&p1<=p3)
dir[i][j]=1;
else if(p2<=p1&&p2<=p3)
dir[i][j]=2;
else
dir[i][j]=3;
ret=min(p1,min(p2,p3));
return ret;
// return ret=min(p1,min(p2,p3));
}
void path_prnt(int i,int j)
{
if(i<0||j<0)
return;
if(dir[i][j]==1)
{
path_prnt(i,j-1);
printf("delete %c",ch1[i]);
}
else if(dir[i][j]==2)
{
path_prnt(i-1,j);
printf("add %c",ch2[j]);
}
else
{
path_prnt(i-1,j-1);
if(ch1[i]!=ch2[j])
printf("replace %c",ch2[j]);
}
}
int main()
{
int i,j;
while(gets(ch1))
{
gets(ch2);
l1=strlen(ch1);
l2=strlen(ch2);
for(i=0;i<l1;i++)
{
for(j=0;j<l2;j++)
dp[i][j]=-1;
}
printf("%d\n",rec(l1-1,l2-1));
path_prnt(l1-1,l2-1);
puts("");
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CiNkZWZpbmUgc2kgMzAwNQojZGVmaW5lIG1pbihhLGIpIChhPGI/YTpiKQppbnQgZHBbc2ldW3NpXSxsMSxsMixkaXJbc2ldW3NpXTsKY2hhciBjaDFbc2ldLGNoMltzaV07CgppbnQgcmVjKGludCBpLGludCBqKQp7CiAgICBpZihpPDAmJmo8MCkKCQlyZXR1cm4gMDsKCWVsc2UgaWYoaTwwfHxqPDApCgkJcmV0dXJuIGk8MD8oaisxKTooaSsxKTsKCWludCAmcmV0PWRwW2ldW2pdO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