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
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define PPC(x) __builtin_popcount((x))
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define st first
#define nd second
using namespace std;

const int maxN = 10101, mod = 1000000007;

inline void addMod(long long& a, long long b)	{   a = (a + b) % mod;  }
inline void multMod(long long& a, long long b)	{   a = a * b % mod;    }

long long qpow(long long a, long long b)
{
    long long res0 = 1;
    for (; b!=0; b>>=1)
    {
        if (b & 1)  multMod(res0, a);
        multMod(a, a);
    }
    return res0;
}

int nk[maxN][maxN], pref[maxN][maxN];
int n;
char in[3][maxN];
int same[3][3], r[3], same2, lon[3];

void compNk()
{
	nk[0][0] = pref[0][1] = 1ll;
	FOR(i, 1, n+1)
	{
		nk[i][0] = 1ll;
		FOR(j, 1, i+2)
		{
			nk[i][j] = (nk[i-1][j-1] + nk[i-1][j]) % mod;
			pref[i][j] = (pref[i][j-1] + nk[i][j-1]) % mod;
		}
	}
}

inline long long sum(int i, int j, int k)
{
	return k < j ? 0ll : (long long)pref[i][k+1] + mod - pref[i][j];
}

long long licz1(int i)
{
	return sum(n, 0, r[i]) % mod;
}

long long licz2(int i, int j)
{
	int s = same[i][j], s2 = n - s;
	long long res = 0;
	FOR(d, 0, min({s, r[i], r[j]}) + 1)
	{
		int a = max(0, s2+d-r[j]);
		int b = min(s2, r[i]-d);
		addMod(res, sum(s2, a, b) * nk[s][d]);
	}

	return res;
}

long long licz3()
{
	int s = same2;
	int r0 = r[0], r1 = r[1], r2 = r[2];
	int lon0 = lon[0], lon1 = lon[1], lon2 = lon[2];
	long long res = 0;

	//printf("[%d %d %d %d]\n", s, lon0, lon1, lon2);
	assert(s + lon0 + lon1 + lon2 == n);

	FOR(d, 0, min({s, r0, r1, r2}) + 1)
	{
		long long prod0 = nk[s][d];
		int a0 = max(0, d+lon0-min(r1, r2));
		int b0 = min(lon0, r0-d);
		
		FOR(e0, a0, b0+1)
		{
			long long prod1 = prod0 * nk[lon0][e0] % mod;
			int f0 = lon0-e0;
			int a1 = max({0, d+e0+lon1-r0, d+f0+lon1-r2});
			int b1 = min(lon1, r1-d-f0);
			long long x = 0ll;
						
			FOR(e1, a1, b1+1)
			{
				int f1 = lon1-e1;
				int a2 = max({0, d+e0+f1-r0+lon2, d+e1+f0-r1+lon2});
				int b2 = min(lon2, r2-d-f0-f1);
				addMod(x, sum(lon2, a2, b2) * nk[lon1][e1]);
			}
			
			addMod(res, prod1 * x);
		}
	}
	
	return res;
}

int main()
{
	scanf ("%d", &n);
	FOR(s, 0, 3)
		scanf ("%d%s", r+s, &in[s][0]);
	compNk();
	
	FOR(i, 0, n)
	{
		FOR(a, 0, 3) FOR(b, a+1, 3)
			if (in[a][i] == in[b][i])
				same[a][b]++;
		if (in[0][i] == in[1][i] and in[1][i] == in[2][i])
			same2++;
		else
		{
			if (in[0][i] == in[1][i])
				lon[2]++;
			if (in[0][i] == in[2][i])
				lon[1]++;
			if (in[1][i] == in[2][i])
				lon[0]++;
		}
	}
	
	long long res = licz3();
	FOR(i, 0, 3)
	{
		addMod(res, licz1(i));
		FOR(j, i+1, 3)
			addMod(res, mod-licz2(i, j));
	}
	printf("%lld\n", res);
	return 0;
}