Hamming Ellipses

Count words of length n over a q-symbol alphabet whose Hamming distances to two given words sum to exactly D.

Medium5CombinatoricsMathStringImplementationNo attempts yetTime limit5sMemory limit512 MB

Problem

In geometry an ellipse is defined by two focal points f1f_1, f2f_2 and a length DD. The ellipse is the set of all points pp with d(f1,p)+d(f2,p)=Dd(f_1, p) + d(f_2, p) = D.

The usual setting for an ellipse is the Euclidean plane with the Euclidean distance.

This problem uses a different kind of ellipse. The space here is the space of words of length nn over an alphabet of qq distinct symbols, written Fqn\mathbb{F}_q^n. For given qq and nn there are qnq^n points, that is words, in Fqn\mathbb{F}_q^n.

The distance measure is the Hamming distance. The Hamming distance dH(x,y)d_H(x, y) between two words x,yFqnx, y \in \mathbb{F}_q^n is the number of positions where the symbols of xx and yy differ. For example, the Hamming distance between the words 01201 and 21210 is 3, because the words carry different symbols in three positions. The Hamming distance between any two words in Fqn\mathbb{F}_q^n is always an integer between 0 and nn, inclusive.

Inside Fqn\mathbb{F}_q^n the Hamming ellipse is the set of all points pp with dH(f1,p)+dH(f2,p)=Dd_H(f_1, p) + d_H(f_2, p) = D. Given qq and nn, the two focal points f1f_1 and f2f_2, and the distance DD, determine how many points pFqnp \in \mathbb{F}_q^n lie on this Hamming ellipse.

Input

The first line contains three integers qq (2q102 \le q \le 10), nn (1n1001 \le n \le 100) and DD (1D2n1 \le D \le 2n).

The second and third lines give the two focal points f1f_1 and f2f_2 in that order. Each line is a string of length nn over the digits {0,1,,q1}\{0, 1, \dots, q-1\}.

Output

Print one line with a single integer, the number of points on the ellipse. The input is chosen so that the answer is less than 2632^{63}.