{"raw_statement":[{"iden":"problem statement","content":"We have a grid with $2$ rows and $L$ columns. Let $(i,j)$ denote the square at the $i$\\-th row from the top $(i\\in\\lbrace1,2\\rbrace)$ and $j$\\-th column from the left $(1\\leq j\\leq L)$. $(i,j)$ has an integer $x _ {i,j}$ written on it.\nFind the number of integers $j$ such that $x _ {1,j}=x _ {2,j}$.\nHere, the description of $x _ {i,j}$ is given to you as the run-length compressions of $(x _ {1,1},x _ {1,2},\\ldots,x _ {1,L})$ and $(x _ {2,1},x _ {2,2},\\ldots,x _ {2,L})$ into sequences of lengths $N _ 1$ and $N _ 2$, 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}))$.\nHere, the run-length compression of a sequence $A$ is a sequence of pairs $(v _ i,l _ i)$ of an element $v _ i$ of $A$ and a positive integer $l _ i$ obtained as follows.\n\n1.  Split $A$ between each pair of different adjacent elements.\n2.  For each sequence $B _ 1,B _ 2,\\ldots,B _ k$ after the split, let $v _ i$ be the element of $B _ i$ and $l _ i$ be the length of $B _ i$."},{"iden":"constraints","content":"*   $1\\leq L\\leq 10 ^ {12}$\n*   $1\\leq N _ 1,N _ 2\\leq 10 ^ 5$\n*   $1\\leq v _ {i,j}\\leq 10 ^ 9\\ (i\\in\\lbrace1,2\\rbrace,1\\leq j\\leq N _ i)$\n*   $1\\leq l _ {i,j}\\leq L\\ (i\\in\\lbrace1,2\\rbrace,1\\leq j\\leq N _ i)$\n*   $v _ {i,j}\\neq v _ {i,j+1}\\ (i\\in\\lbrace1,2\\rbrace,1\\leq j\\lt N _ i)$\n*   $l _ {i,1}+l _ {i,2}+\\cdots+l _ {i,N _ i}=L\\ (i\\in\\lbrace1,2\\rbrace)$\n*   All values in the input are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$L$ $N _ 1$ $N _ 2$\n$v _ {1,1}$ $l _ {1,1}$\n$v _ {1,2}$ $l _ {1,2}$\n$\\vdots$\n$v _ {1,N _ 1}$ $l _ {1,N _ 1}$\n$v _ {2,1}$ $l _ {2,1}$\n$v _ {2,2}$ $l _ {2,2}$\n$\\vdots$\n$v _ {2,N _ 2}$ $l _ {2,N _ 2}$"},{"iden":"sample input 1","content":"8 4 3\n1 2\n3 2\n2 3\n3 1\n1 4\n2 1\n3 3"},{"iden":"sample output 1","content":"4\n\nThe grid is shown below.\n![image](https://img.atcoder.jp/abc294/14f38720983c464a322b504738344f24.png)\nWe have four integers $j$ such that $x _ {1,j}=x _ {2,j}$: $j=1,2,5,8$. Thus, you should print $4$."},{"iden":"sample input 2","content":"10000000000 1 1\n1 10000000000\n1 10000000000"},{"iden":"sample output 2","content":"10000000000\n\nNote that the answer may not fit into a $32$\\-bit integer."},{"iden":"sample input 3","content":"1000 4 7\n19 79\n33 463\n19 178\n33 280\n19 255\n33 92\n34 25\n19 96\n12 11\n19 490\n33 31"},{"iden":"sample output 3","content":"380"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}