This page is still under construction.

Parts of this page are still being built. What you see may change.

Hamming Ellipses

Time limit5sMemory limit512 MB

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

Medium5 of 10

Topics
Combinatorics, Math, String, Implementation
Solved
No attempts yet

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,y∈Fqnx, 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 p∈Fqnp \in \mathbb{F}_q^n lie on this Hamming ellipse.

Input

The first line contains three integers qq (2≤q≤102 \le q \le 10), nn (1≤n≤1001 \le n \le 100) and DD (1≤D≤2n1 \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,…,q−1}\{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}.

Examples3

  1. Example 1

    Input
    3 5 9
    01201
    21210
    
    Expected output
    24
    
  2. Example 2

    Input
    4 6 5
    123031
    231222
    
    Expected output
    0
    
  3. Example 3

    Input
    2 32 32
    01010101010101010101010101010101
    01010101010101010101010101010101
    
    Expected output
    601080390