1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>

using namespace std;

int n, r1, r2, r3, x1, x2, x3, x4;
long long sil[10001], mod=1e9+7;
long long rev[10001];
long long su[10011];
long long odp;
char s1[10001];
char s2[10001];
char s3[10001];

long long pot(long long a, int b)
{
	long long xd=1;
	while(b)
	{
		if(b&1)
		{
			xd*=a;
			xd%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return xd;
}

int main()
{
	scanf("%d%d%s%d%s%d%s", &n, &r1, s1, &r2, s2, &r3, s3);
	for(int i=0; i<n; ++i)
	{
		if(s1[i]==s2[i] && s2[i]==s3[i])
		{
			++x1;
		}
		if(s1[i]==s2[i] && s2[i]!=s3[i])
		{
			++x2;
		}
		if(s1[i]!=s2[i] && s2[i]==s3[i])
		{
			++x3;
		}
		if(s1[i]!=s2[i] && s2[i]!=s3[i])
		{
			++x4;
		}
	}
	sil[0]=1;
	for(int i=1; i<=n; ++i)
	{
		sil[i]=sil[i-1]*i%mod;
	}
	rev[n]=pot(sil[n], mod-2);
	for(int i=n-1; i>=0; --i)
	{
		rev[i]=rev[i+1]*(i+1)%mod;
	}
	for(int i=x1; i>=0; --i)
	{
		su[i]=(su[i+1]+sil[x1]*rev[i]%mod*rev[x1-i])%mod;
	}
	for(int j=0; j<=x2; ++j)
	{
		for(int k=0; k<=x3; ++k)
		{
			for(int l=0; l<=x4; ++l)
			{
				odp+=sil[x2]%mod*rev[j]%mod*rev[x2-j]%mod*sil[x3]%mod*rev[k]%mod*rev[x3-k]%mod*sil[x4]%mod*rev[l]%mod*rev[x4-l]%mod*su[max(0, max(r1-j-k-l, max(r2-j-x3+k-x4+l, r3-x2+j-x3+k-l))+1)];
				odp%=mod;
			}
		}
	}
	printf("%lld\n", (pot(2, n)-odp+mod)%mod);
	return 0;
}