Little Q and Big Integers

0이 없는 k진 정수 가운데 각 숫자의 개수가 금지된 값을 피하는 것의 수를, 금지 행렬을 한 칸씩 뒤집는 m번의 변화에 걸쳐 모두 더해 구한다.

어려움8조합론동적 계획법수학아직 제출이 없습니다시간 제한1.5초메모리 제한512 MB

문제

Little Q likes positive big integers in base kk notation, but not all of them. He doesn't like integers with zeroes, including leading zeroes. Additionally, he is particular about the number of occurrences of each digit. Formally, his preferences can be described as a binary matrix g_1..k1,0..ng\_{1 .. k - 1, 0 .. n}, where for every digit ii from 11 to k1k - 1, if g_i,j=0g\_{i, j} = 0, he doesn't like integers which contain exactly jj copies of digit ii. He also can't accept any digit appearing more than nn times. The integer must contain at least one digit.

Little Q's taste changes every day. There are mm days in total, and on day ii, the value g_u_i,v_ig\_{u\_i, v\_i} is flipped (00 becomes 11 and 11 becomes 00). Let cnt(i)\mathrm{cnt} (i) denote the number of big integers which Little Q likes after ii-th day's change, and cnt(0)\mathrm{cnt} (0) denote the answer before all changes. Your task is to calculate the following:

(_i=0mcnt(i))mod786,433.\left( \sum\_{i = 0}^{m} \mathrm{cnt} (i) \right) \bmod 786\\,433\text{.}

입력

The first line of the input contains three integers kk, nn and mm: the base, the upper limit and the number of days (3k103 \leq k \leq 10, 1n1.41041 \leq n \leq 1.4 \cdot 10^4, 1 m2001 \leq  m \leq 200).

In the next k1k - 1 lines, line ii contains n+1n + 1 integers g_i,0g\_{i, 0}, g_i,1g\_{i, 1}, \ldots, g_i,ng\_{i, n} (0g_i,j10 \leq g\_{i, j} \leq 1). Together they provide the initial matrix gg.

After that follow mm lines, ii-th line contains two integers u_iu\_i and v_iv\_i which mean that on ii-th day, the value g_u_i,v_ig\_{u\_i, v\_i} is flipped (1u_ik11 \leq u\_i \leq k - 1, 0v_in0 \leq v\_i \leq n).

출력

Print a single line with a single integer: the answer to the problem.