时间限制:C/C++/Rust/Pascal 5秒,其他语言10秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
Special Judge, 64bit IO Format: %lld

题目描述

You have n piles of stones arranged in a row. The i-th pile contains a_i stones (where a_i can be 0). Among all the stones, exactly one stone is special, and you want to find it. Each time, you can choose a number of stones from a pile to be tested, and the test will tell you whether the special stone is among the chosen ones.The stones you choose must come from one pile.

You want to minimize the number of tests needed to identify the special stone in the worst-case scenario.

There are q queries, each giving l and r. For each query, you need to answer the minimum number of tests required to determine the special stone, given that it is within the piles from l to r.

Since the value of a_i can be large, it will be represented as a binary string of length m in the format of a 01 string. The first character of the string is the most significant bit, and the last character is the least significant bit.

输入描述:

The first line contains three positive integers n, m, and q, representing the length of the sequence, the maximum bit length of a_i, and the number of queries, respectively. 

The next n lines each contain a binary string of length m representing a_i.

The next q lines each contain two integers l and r, representing the range for the query.

输出描述:

For each query, output the minimum number of tests required to determine the special stone.
示例1

输入

复制
5 3 5
100
100
101
001
111
1 3
1 3
3 3
4 4
5 5

输出

复制
4
4
3
0
3
示例2

输入

复制
15 8 10
01100110
10101011
01011110
10011100
10100101
01101010
11001010
01000110
11001101
01100011
01100101
10110010
01011101
01000101
11101000
1 14
14 14
13 15
6 11
11 12
15 15
8 15
10 11
7 11
9 14

输出

复制
20
7
9
12
9
8
14
8
11
12

备注:

1 \le n, q\le 5\times 10^4, 1 \le m \le 1000, 1\leq l \leq r \leq n..