1 #include<bits/stdc++.h>
2 using namespace std;
3 const int maxn=1e6+5;
4 const int INF=1e9+7;
5 int v[6][6]
6 {
7 {0,0,0,0,0,0},
8 {0,5,-1,-2,-1,-3},
9 {0,-1,5,-3,-2,-4},
10 {0,-2,-3,5,-2,-2},
11 {0,-1,-2,-2,5,-1},
12 {0,-3,-4,-2,-1,0},
13 };
14 int n,m,a[105],b[105];
15 char cha;
16 int f[205][205];
17 template <class t>void red(t &x)
18 {
19 x=0;
20 int w=1;
21 char ch=getchar();
22 while(ch<'0'||ch>'9')
23 {
24 if(ch=='-')
25 w=-1;
26 ch=getchar();
27 }
28 while(ch>='0'&&ch<='9')
29 {
30 x=(x<<3)+(x<<1)+ch-'0';
31 ch=getchar();
32 }
33 x*=w;
34 }
35 void input()
36 {
37 freopen("input.txt","r",stdin);
38 }
39 void read()
40 {
41 red(n);
42 for(int i=1;i<=n;++i)
43 {
44 cha=getchar();
45 if(cha=='A')
46 a[i]=1;
47 if(cha=='C')
48 a[i]=2;
49 if(cha=='G')
50 a[i]=3;
51 if(cha=='T')
52 a[i]=4;
53 }
54 red(m);
55 for(int i=1;i<=m;++i)
56 {
57 cha=getchar();
58 if(cha=='A')
59 b[i]=1;
60 if(cha=='C')
61 b[i]=2;
62 if(cha=='G')
63 b[i]=3;
64 if(cha=='T')
65 b[i]=4;
66 }
67 }
68 void work()
69 {
70 for(int i=1;i<=n;++i)
71 for(int j=1;j<=m;++j)
72 f[i][j]=-INF;
73 for(int i=1;i<=n;++i)
74 f[i][0]=f[i-1][0]+v[a[i]][5];
75 for(int i=1;i<=m;++i)
76 f[0][i]=f[0][i-1]+v[5][b[i]];
77 for(int i=1;i<=n;++i)
78 for(int j=1;j<=m;++j)
79 f[i][j]=max(f[i][j],max(f[i-1][j-1]+v[a[i]][b[j]],max(f[i-1][j]+v[a[i]][5],f[i][j-1]+v[5][b[j]])));
80 printf("%d",f[n][m]);
81 }
82 int main()
83 {
84 input();
85 read();
86 work();
87 return 0;
88 }