시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 3 0 0 0.000%

문제

We are given n containers, where 1 ≤ n ≤ 4. At the beginning all of them are full of water. The liter capacity of the i-th container is a natural number oi satisfying inequalities 1 ≤ oi ≤ 49.

Three kinds of moves can be made:

  • Pouring the whole content of one container into another. This move can be made unless there is too little room in the second container.
  • Filling up one container with part of the water from another one.
  • Pouring away the whole content of one container into a drain.

Write a program that:

  • reads form the standard input the number of containers n, the capacity of each container and the requested final amount of water in each container,
  • verifies, whether there exist a series of moves which leads to the requested final situation, and if there is one, the program computes the minimal number of moves leading to the requested situation,
  • writes the result into the standard output. The result should be the minimal number of moves leading to the requested final situation, or one word NIE (“no” in Polish) if there is no such a sequence of moves.

입력

In the first line of the standard input one positive integer n is written (n ≤ 4), this is the number of containers. There are n positive integers written in the second line. These are the capacities of the containers (the i-th integer oi denotes the capacity if the i-th container, 1 ≤ oi ≤ 49). In the third line of the input file there are written n numbers. These are the requested final volumes of water in the containers (the i-th integer wi denotes the requested final volume of water in the i-th container, 1 ≤ wi ≤ oi). All integers in the second and the third line are separated by single spaces.

출력

If it is not possible to result in requested final situation making only allowed moves, your program should write only one word NIE to the standard output, otherwise only one integer equal to the minimal number of moves which lead to the requested final situation should be written.

예제 입력 1

3
3 5 5
0 0 4

예제 출력 1

6

예제 입력 2

2
20 25
10 16

예제 출력 2

NIE