B. Superpiece
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Examples
Input
2
NKP
3 3 5 1
NKP
2 6 5 3
Output
2
2
Input
2
B
2 8 3 6
B
2 8 5 5
Output
-1
1
Input
2
Q
3 3 4 5
QR
4 1 1 4
Output
2
1