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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <string>
#include <set>

using namespace std;

typedef unsigned long long ull;

int n;
int r1, r2, r3;
string s1, s2, s3;

const unsigned long long mod = 1000000007;

ull calc_nk(ull n, ull k)
{
        ull nk = 1;

        if (n-k < k) {
                k = n - k;
        }

        for(int i = 1; i <= k; ++i) {
                nk = nk * (n-i+1) / i;
                nk %= mod;
        }
        return nk;

}

ull calc_sumnk(ull n, ull k)
{
        unsigned long long nk = 1, sum = 1;

        for(int i = 1; i <= k; ++i) {
                nk = nk * (n-i+1) / i;
                nk %= mod;
                sum += nk;
                sum %= mod;
        }
        return sum;
}



int calc_diff(string a, string b)
{
        int result = 0;

        for(int i = 0; i < n; ++i) {
                if (a[i] != b[i]) {
                        ++result;
                }
        }
        return result;
}

ull calc_result(string a, string b, int r1, int r2)
{
        int diff = calc_diff(a, b);
        ull result;

//        printf("(%s) (%s) (%d) (%d)\n", a.c_str(), b.c_str(), r1, r2);

        if (r1 == n || r2 == n) {
                return calc_sumnk(n, max(r1, r2));
        }

        if (diff == 0) {
                return calc_sumnk(n, max(r1, r2));
        }

        if (diff > r1 + r2) {
                return (calc_sumnk(n, r1) + calc_sumnk(n, r2)) % mod;
        }

        if (diff + r1 <= r2) {
                return calc_sumnk(n, r2);
        }

        if (diff + r2 <= r1) {
                return calc_sumnk(n, r1);
        }

        result = calc_sumnk(n, r1) + calc_sumnk(n, r2);
        result %= mod;

        if (diff == r1 + r2) {
                ull a = result;
                ull b = calc_nk(diff, min(r1, r2));

                if (a >= b) {
                        return a - b;
                } else {
                        return a + mod - b;
                }
        }



        if (diff + 1 == r1 + r2) {
               ull a = result;
               ull b = calc_nk(diff, r1);
               ull c = calc_nk(diff, r2);

               if (a >= b) {
                       a -= b;
               } else {
                       a = a + mod - b;
               }
                
               if (a >= c) {
                       return a-c;
               } else {
                       return a + mod - c;
               }
        }
       

        for(int i = max(0,diff-r2); i <= r1; ++i) {
                ull b = calc_nk(diff, i);
                if (result >= b) {
                        result -= b;
                } else {
                        result = result + mod - b;
                }
        }

        for(int x = 1; x <= (r1+r2-diff)/2; ++x) {
                for(int i = max(0,diff-r2+x); i <= r1-x; ++i) {
                        ull b = calc_nk(diff, i)*calc_nk(n-diff, x);
                        b %= mod;
                        if (result >= b) {
                                result -= b;
                        } else {
                                result = result + mod - b;
                        }
                }
        }
        return result;
}

int main()
{
        ull result;

        scanf("%d\n", &n);

        scanf("%d ", &r1);
        for(int i = 0; i < n; ++i) {
                char c;
                scanf("%c", &c);
                s1.push_back(c);
        }
        scanf("%d ", &r2);
        for(int i = 0; i < n; ++i) {
                char c;
                scanf("%c", &c);
                s2.push_back(c);
        }
        scanf("%d ", &r3);
        for(int i = 0; i < n; ++i) {
                char c;
                scanf("%c", &c);
                s3.push_back(c);
        }

        
        if (r1 == r2 && s1.compare(s2) == 0) {
                result = calc_result(s1, s3, r1, r3);
                printf("%llu\n", result);
                return 0;
        }

        if (r1 == r3 && s1.compare(s3) == 0) {
                result = calc_result(s1, s2, r1, r2);
                printf("%llu\n", result);
                return 0;
        }

        if (r2 == r3 && s2.compare(s3) == 0) {
                result = calc_result(s1, s2, r1, r2);
                printf("%llu\n", result);
                return 0;
        }

        printf("tralalala\n");

        return 0;
}