#include<iostream.h>
#include<stdio.h>
int c[6][6]={{0,0,0,0,0,0},{0,5,-2,-1,-2,-4},
{0,-2,5,-4,-3,-2},{0,-1,-4,5,-5,-1},{0,-2,-3,-5,5,-2},{0,-4,-2,-1,-2,0}};
int L[10][10];
int compare(char a,char b)
{
int m,n;
switch(a)
{
case 'A': m=1;
break;
case 'G': m=2;
break;
case 'C': m=3;
break;
case 'T': m=4;
break;
case ' ': m=5;
break;
}
switch(b)
{
case 'A': n=1;
break;
case 'G': n=2;
break;
case 'C': n=3;
break;
case 'T': n=4;
break;
case ' ': n=5;
break;
}
return c[m][n];
}
void main()
{
int i,j,m,n;
char a[7],b[6],c,d;
d=' ';
m=6,n=5;
L[0][0]=0; L[0][1]=-4; L[0][2]=-2;
L[0][3]=-2;L[0][4]=-4;L[0][5]=-2;
L[1][0]=-4; L[2][0]=-2; L[3][0]=-2;
L[4][0]=-4;L[5][0]=-2;L[6][0]=-2;
i=1;
while((c=getchar())!='\n')
{
a[i++]=c;
}
i=1;
while((c=getchar())!='\n')
{
b[i++]=c;
}
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
if(L[i-1][j-1]>L[i][j-1]&&L[i-1][j-1]>L[i-1][j])
L[i][j]=L[i-1][j-1]+compare(a[i],b[j]);
else
{
if(L[i][j-1]>=L[i-1][j])
L[i][j]=L[i][j-1]+compare(d,b[j]);
else
L[i][j]=L[i-1][j]+compare(a[i],d);
}
if((L[i-1][j-1]+compare(a[i],b[j]))>=L[i][j])
L[i][j]=L[i-1][j-1]+compare(a[i],b[j]);
}
}
cout<<L[6][5]<<endl;
/* for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
cout<<L[i][j]<<" ";
cout<<endl;
}*/
}