K. Star Seeker's Socks
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
3
1 1
1
1
2 2
6 4
1 2
5 3
3 5 7 11 13
1 2 4
Output
2
3
44