Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

L. Layered Shufflers
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Examples
Input
3 4 1 4
3 1 4 2
1 2 3 4
1 3 2 4
Output
1
Input
4 5 2 3
5 2 1 3 4
1 2 3 4 5
5 2 1 3 4
1 2 3 4 5
Output
0