G. Modulo
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
5 4
6 10 5 9 4
2 2 2 -9
1 7 4 5
2 1 4 1
1 1 2 3
Output
3
1
Input
10 10
9 8 2 5 19 20 3 16 1 12
1 16 2 10
2 7 8 -1
1 12 3 4
1 15 1 1
2 4 6 -3
2 2 7 -1
2 2 4 11
2 3 9 4
1 3 2 2
1 13 3 9
Output
0
0
6
3
3