#abc294e. [abc294_e]2xN Grid
[abc294_e]2xN Grid
Problem Statement
We have a grid with rows and columns. Let denote the square at the -th row from the top and -th column from the left . has an integer written on it.
Find the number of integers such that .
Here, the description of is given to you as the run-length compressions of and into sequences of lengths and , respectively: $((v _ {1,1},l _ {1,1}),\\ldots,(v _ {1,N _ 1},l _ {1,N _ 1}))$ and $((v _ {2,1},l _ {2,1}),\\ldots,(v _ {2,N _ 2},l _ {2,N _ 2}))$.
Here, the run-length compression of a sequence is a sequence of pairs of an element of and a positive integer obtained as follows.
- Split between each pair of different adjacent elements.
- For each sequence after the split, let be the element of and be the length of .
Constraints
- $1\\leq v _ {i,j}\\leq 10 ^ 9\\ (i\\in\\lbrace1,2\\rbrace,1\\leq j\\leq N _ i)$
- $1\\leq l _ {i,j}\\leq L\\ (i\\in\\lbrace1,2\\rbrace,1\\leq j\\leq N _ i)$
- $v _ {i,j}\\neq v _ {i,j+1}\\ (i\\in\\lbrace1,2\\rbrace,1\\leq j\\lt N _ i)$
- $l _ {i,1}+l _ {i,2}+\\cdots+l _ {i,N _ i}=L\\ (i\\in\\lbrace1,2\\rbrace)$
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print a single line containing the answer.
Sample Input 1
8 4 3
1 2
3 2
2 3
3 1
1 4
2 1
3 3
Sample Output 1
4
The grid is shown below.
We have four integers such that : . Thus, you should print .
Sample Input 2
10000000000 1 1
1 10000000000
1 10000000000
Sample Output 2
10000000000
Note that the answer may not fit into a -bit integer.
Sample Input 3
1000 4 7
19 79
33 463
19 178
33 280
19 255
33 92
34 25
19 96
12 11
19 490
33 31
Sample Output 3
380