H. Rock-Paper-Level Up
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
5 8
0 2 2 1 1
1 0 0 0 1
3 0
1 1 1
2 5
1 3 1
3 4
1 1 1
3 0
3 4
Output
3
13
7
13
Input
3 3
0 0 0
0 0 0
3 0
1 1 2
3 1
Output
3
3