#P3276. [SCOI2011] 镜像拆分

    ID: 2325 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2011四川并查集各省省选平衡树连通块

[SCOI2011] 镜像拆分

Description

lxhgww loves number games. He discovered that many numbers can be expressed as the sum of two numbers that are reverses of each other; he calls this phenomenon a number’s “mirror decomposition”. For example, 6666 has five mirror decompositions: 66=15+51=24+42=33+33=42+24=51+1566=15+51=24+42=33+33=42+24=51+15. Note that leading zeros are not allowed, so 66=60+0666=60+06 is not counted as a valid mirror decomposition. Now lxhgww wants to know, in base KK, for the numbers in the interval [A,B][A,B], what is the sum of the counts of their mirror decompositions?

Input Format

The first line of input is a number KK. The second line is a number nn, denoting the length of the number AA. The next nn lines give each digit of AA starting from the least significant digit. Then comes a number mm, denoting the length of the number BB. The next mm lines give each digit of BB starting from the least significant digit.

Output Format

Output one line containing an integer, which is the sum of the counts of mirror decompositions. Since the answer can be very large, output the remainder when this answer is divided by 2011052120110521.

10
2
6
6
2
6
6
5

Hint

  • For 20%20\% of the testdata, it is guaranteed that: 2K1002\le K\le100, 1n,m1001\le n,m\le100.
  • For 50%50\% of the testdata, it is guaranteed that: 2K10002\le K\le1000, 1n,m10001\le n,m\le1000.
  • For 100%100\% of the testdata, it is guaranteed that: 2K1052\le K\le10^5, 1n,m1051\le n,m\le10 ^ 5.
  • For all the testdata, it is guaranteed that: 0<AB0\lt A\le B. Each digit of AA and BB is in the range [0,K1][0, K-1], and there are no leading zeros.

Translated by ChatGPT 5