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 MBIn geometry an ellipse is defined by two focal points f1, f2 and a length D. The ellipse is the set of all points p with d(f1,p)+d(f2,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 n over an alphabet of q distinct symbols, written Fqn. For given q and n there are qn points, that is words, in Fqn.
The distance measure is the Hamming distance. The Hamming distance dH(x,y) between two words x,y∈Fqn is the number of positions where the symbols of x and y 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 is always an integer between 0 and n, inclusive.
Inside Fqn the Hamming ellipse is the set of all points p with dH(f1,p)+dH(f2,p)=D. Given q and n, the two focal points f1 and f2, and the distance D, determine how many points p∈Fqn lie on this Hamming ellipse.
The first line contains three integers q (2≤q≤10), n (1≤n≤100) and D (1≤D≤2n).
The second and third lines give the two focal points f1 and f2 in that order. Each line is a string of length n over the digits {0,1,…,q−1}.
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 263.