Problemas
Farmer John's
It takes
are unwilling to communicate with each-other.
Please determine the minimum amount of time needed to transmit the message.
Entrada
The first line contains
The next line contains
The next
Salida
Print a single integer giving the minimum amount of time needed. If it is impossible to transmit the message from cow
Ejemplo
5 4
1 4 2 3 4
1010
0001
0110
0100
6
The optimal sequence of transmissions is
. The total amount of time is
.