Containers

No attempts yetTime limit1sMemory limit128 MB

Problem

There are nn containers (1n41 \le n \le 4). At the start every container is completely full of water. The capacity of the ii-th container is an integer oio_i liters, with 1oi491 \le o_i \le 49.

Three kinds of moves are allowed:

  • Pour the whole contents of one container into another. This is allowed only when the destination has enough remaining room to hold all of it.
  • Fill one container up to its capacity using water from another container. (Used when the source holds more water than the destination's remaining room; the destination becomes full and the leftover stays in the source.)
  • Empty the whole contents of one container into a drain.

Given the capacity of every container and the requested final amount of water in every container, decide whether some sequence of allowed moves reaches that final state. If it does, output the minimum number of moves; otherwise output NIE.

Input

The first line contains one integer nn, the number of containers (1n41 \le n \le 4). The second line contains nn integers o1,,ono_1, \dots, o_n separated by single spaces, where oio_i is the capacity of the ii-th container (1oi491 \le o_i \le 49). The third line contains nn integers w1,,wnw_1, \dots, w_n separated by single spaces, where wiw_i is the requested final amount of water in the ii-th container (0wioi0 \le w_i \le o_i).

Output

If the requested final state cannot be reached using only the allowed moves, print the single word NIE. Otherwise print one integer: the minimum number of moves that reaches the requested final state.