A - Getting Difference

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 300

問題文

箱に N 個のボールが入っていて、i 番目のボールには整数 A_i が書かれています。 すぬけ君は、次の操作を好きな回数だけ行うことができます。

  • 箱から二つのボールを取り出し、その二つのボールに書かれている数の差の絶対値を書いた新しいボールと一緒に箱に戻す。

すぬけ君が、整数 K の書かれたボールが箱の中に入っている状態にできるかどうか判定してください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq K \leq 10^9
  • 入力はすべて整数である。

入力

入力は以下の形式で標準入力から与えられる。

N K
A_1 A_2 ... A_N

出力

すぬけ君が、整数 K がかかれたボールが箱の中に入っている状態にできる場合には POSSIBLE、 できない場合には IMPOSSIBLE と出力せよ。


入力例 1

3 7
9 3 4

出力例 1

POSSIBLE

まず、9 と書かれたボールと 4 と書かれたボールを取り出し、abs(9-4)=5 なので、5 と書かれた新しいボールと一緒に箱に戻します。 次に、3 と書かれたボールと 5 と書かれたボールを取り出し、abs(3-5)=2 なので、2 と書かれた新しいボールと一緒に箱に戻します。 最後に、9 と書かれたボールと 2 と書かれたボールを取り出し、abs(9-2)=7 なので、7 と書かれた新しいボールと一緒に箱に戻します。 7 と書かれたボールを箱に入れることができたので、この例の答えは POSSIBLE になります。


入力例 2

3 5
6 9 3

出力例 2

IMPOSSIBLE

どれだけ操作を行っても、5 の書かれたボールを箱の中に入れることはできません。 よってこの例の答えは、IMPOSSIBLE になります。


入力例 3

4 11
11 3 7 15

出力例 3

POSSIBLE

操作を行うまでもなく、箱の中には 11 の書かれたボールが入っています。 よってこの例の答えは、POSSIBLE になります。


入力例 4

5 12
10 2 8 6 4

出力例 4

IMPOSSIBLE

Score : 300 points

Problem Statement

There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times:

  • Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.

Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq K \leq 10^9
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print POSSIBLE; if it is not possible, print IMPOSSIBLE.


Sample Input 1

3 7
9 3 4

Sample Output 1

POSSIBLE

First, take out the two balls 9 and 4, and return them back along with a new ball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with abs(3-5)=2. Finally, take out 9 and 2, and return them back along with abs(9-2)=7. Now we have 7 in the box, and the answer is therefore POSSIBLE.


Sample Input 2

3 5
6 9 3

Sample Output 2

IMPOSSIBLE

No matter what we do, it is not possible to have 5 in the box. The answer is therefore IMPOSSIBLE.


Sample Input 3

4 11
11 3 7 15

Sample Output 3

POSSIBLE

The box already contains 11 before we do anything. The answer is therefore POSSIBLE.


Sample Input 4

5 12
10 2 8 6 4

Sample Output 4

IMPOSSIBLE
B - Sports Festival

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 700

問題文

高橋君は、スポーツ大会を開こうと考えています。 スポーツ大会に参加するのは、1 から N までの番号のついた N 人の人です。 また、大会で行うスポーツとして、1 から M までの番号のついた M 個のスポーツが候補に上がっています。 高橋君は、これらの中から 1 つ以上(全てでもよい)のスポーツを選んで、スポーツ大会で実施します。

高橋君は、人 i が、j 番目に好きなスポーツが A_{ij} であることを知っています。 それぞれの人は、スポーツ大会で実施されるスポーツのうち、自分が最も好きなスポーツだけに参加し、他のスポーツには参加しません。

高橋君は、一つのスポーツにたくさんの人が集まり過ぎることを懸念しています。 そこで高橋君は、スポーツ大会で実施するスポーツをうまく選んで、最も多くの人が参加しているスポーツの参加人数を最小化したくなりました。 最も多くの人が参加しているスポーツの参加人数の最小値を求めてください。

制約

  • 1 \leq N \leq 300
  • 1 \leq M \leq 300
  • A_{i1} , A_{i2} , ... , A_{iM} は、1 から M の順列である。

入力

入力は以下の形式で標準入力から与えられる。

N M
A_{11} A_{12} ... A_{1M}
A_{21} A_{22} ... A_{2M}
:
A_{N1} A_{N2} ... A_{NM}

出力

最も多くの人が参加しているスポーツの参加人数の最小値を出力せよ。


入力例 1

4 5
5 1 3 4 2
2 5 3 1 4
2 3 1 4 5
2 5 4 3 1

出力例 1

2

スポーツ 1,3,4 を実施することにすると、人 1 はスポーツ 1 に、人 2 はスポーツ 3 に、 人 3 はスポーツ 3 に、人 4 はスポーツ 4 に参加します。 このとき、参加人数が最大のスポーツはスポーツ 3 で、その参加人数 2 人です。 また、参加人数が最大のスポーツの参加人数が 1 人になるような方法は存在しないので、この例の答えは 2 になります。


入力例 2

3 3
2 1 3
2 1 3
2 1 3

出力例 2

3

全員の好みが一致しているので、どうやっても一つのスポーツに 3 人集まってしまいます。 よってこの例の答えは 3 です。

Score : 700 points

Problem Statement

Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.

Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.

Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Constraints

  • 1 \leq N \leq 300
  • 1 \leq M \leq 300
  • A_{i1} , A_{i2} , ... , A_{iM} is a permutation of the integers from 1 to M.

Input

Input is given from Standard Input in the following format:

N M
A_{11} A_{12} ... A_{1M}
A_{21} A_{22} ... A_{2M}
:
A_{N1} A_{N2} ... A_{NM}

Output

Print the minimum possible number of the participants in the sport with the largest number of participants.


Sample Input 1

4 5
5 1 3 4 2
2 5 3 1 4
2 3 1 4 5
2 5 4 3 1

Sample Output 1

2

Assume that Sports 1, 3 and 4 are selected to be played. In this case, Person 1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and Person 4 in Sport 4. Here, the sport with the largest number of participants is Sport 3, with two participants. There is no way to reduce the number of participants in the sport with the largest number of participants to 1. Therefore, the answer is 2.


Sample Input 2

3 3
2 1 3
2 1 3
2 1 3

Sample Output 2

3

Since all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected. Therefore, the answer is 3.

C - Coins

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 800

問題文

1 から X+Y+Z までの番号のついた、X+Y+Z 人の人がいます。 人 i は、金のコインを A_i 枚、銀のコインを B_i 枚、銅のコインを C_i 枚持っています。

すぬけ君は、彼らのうち X 人から金のコイン、Y 人から銀のコイン、Z 人から銅のコインをもらおうと考えています。 どの人からも、2 種類以上のコインをもらうことはできません。 また、どの人も、指定された色のコインをすべてあなたに渡してくれます。

すぬけ君は、最終的に持っている全ての色のコインの枚数の合計を最大化したいです。 すぬけ君が最終的に持っている全ての色のコインの枚数の合計の最大値を求めてください。

制約

  • 1 \leq X
  • 1 \leq Y
  • 1 \leq Z
  • X+Y+Z \leq 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq B_i \leq 10^9
  • 1 \leq C_i \leq 10^9

入力

入力は以下の形式で標準入力から与えられる。

X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}

出力

すぬけ君が最終的に持っている全ての色のコインの枚数の合計の最大値を出力せよ。


入力例 1

1 2 1
2 4 4
3 2 1
7 6 7
5 2 3

出力例 1

18

1 から銀のコインを、人 2 から銀のコインを、人 3 から銅のコインを、人 4 から金のコインをもらうと、 コインの枚数の合計は、4+2+7+5=18 になります。 19 枚以上のコインを得る方法はないので、この例の答えは 18 になります。


入力例 2

3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2

出力例 2

110

入力例 3

6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164

出力例 3

3093929975

Score : 800 points

Problem Statement

There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.

Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.

Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.

Constraints

  • 1 \leq X
  • 1 \leq Y
  • 1 \leq Z
  • X+Y+Z \leq 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq B_i \leq 10^9
  • 1 \leq C_i \leq 10^9

Input

Input is given from Standard Input in the following format:

X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}

Output

Print the maximum possible total number of coins of all colors he gets.


Sample Input 1

1 2 1
2 4 4
3 2 1
7 6 7
5 2 3

Sample Output 1

18

Get silver coins from Person 1, silver coins from Person 2, bronze coins from Person 3 and gold coins from Person 4. In this case, the total number of coins will be 4+2+7+5=18. It is not possible to get 19 or more coins, and the answer is therefore 18.


Sample Input 2

3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2

Sample Output 2

110

Sample Input 3

6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164

Sample Output 3

3093929975
D - Tree and Hamilton Path

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 1100

問題文

N 頂点の木があり、頂点には 1 から N の番号がついています。 この木の i 番目の辺は頂点 A_iB_i を結んでいて、その長さは C_i です。

joisinoお姉ちゃんは、N 頂点の完全グラフを作りました。 なお、この完全グラフの頂点 uv を結ぶ辺の長さは、木での頂点 uv の最短距離になっています。

joisinoお姉ちゃんは、この完全グラフのハミルトンパス(※)のうち、最も長いものの長さを知りたくなりました。 joisinoお姉ちゃんの作った完全グラフのハミルトンパスのうち、最も長いものの長さを求めてください。

注釈

あるグラフのハミルトンパスとは、そのグラフのパスであって、すべての頂点をちょうど一度だけ通るようなものを指します。

制約

  • 2 \leq N \leq 10^5
  • 1 \leq A_i < B_i \leq N
  • 入力で与えられるグラフは木である。
  • 1 \leq C_i \leq 10^8
  • 入力はすべて整数である。

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{N-1} B_{N-1} C_{N-1}

出力

joisinoお姉ちゃんの作った完全グラフのハミルトンパスのうち、最も長いものの長さを出力せよ。


入力例 1

5
1 2 5
3 4 7
2 3 3
2 5 2

出力例 1

38

53142 というハミルトンパスを考えると、その長さは、 5+8+15+10=38 となります。長さ 39 以上のハミルトンパスは作れないので、この例の答えは 38 になります。


入力例 2

8
2 8 8
1 5 1
4 8 2
2 5 4
3 8 6
6 8 9
2 7 12

出力例 2

132

Score : 1100 points

Problem Statement

There is a tree with N vertices, numbered 1 through N. The i-th edge in this tree connects Vertices A_i and B_i and has a length of C_i.

Joisino created a complete graph with N vertices. The length of the edge connecting Vertices u and v in this graph, is equal to the shortest distance between Vertices u and v in the tree above.

Joisino would like to know the length of the longest Hamiltonian path (see Notes) in this complete graph. Find the length of that path.

Notes

A Hamiltonian path in a graph is a path in the graph that visits each vertex exactly once.

Constraints

  • 2 \leq N \leq 10^5
  • 1 \leq A_i < B_i \leq N
  • The given graph is a tree.
  • 1 \leq C_i \leq 10^8
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{N-1} B_{N-1} C_{N-1}

Output

Print the length of the longest Hamiltonian path in the complete graph created by Joisino.


Sample Input 1

5
1 2 5
3 4 7
2 3 3
2 5 2

Sample Output 1

38

The length of the Hamiltonian path 53142 is 5+8+15+10=38. Since there is no Hamiltonian path with length 39 or greater in the graph, the answer is 38.


Sample Input 2

8
2 8 8
1 5 1
4 8 2
2 5 4
3 8 6
6 8 9
2 7 12

Sample Output 2

132
E - Sightseeing Plan

Time Limit: 8 sec / Memory Limit: 256 MB

配点 : 1600

問題文

joisinoお姉ちゃんは、高橋町を観光する計画を立てています。 高橋町は、正方形の区画が東西南北に敷き詰められた形をしており、 西から x 番目、北から y 番目の区画を区画 (x,y) と呼ぶことにします。

joisinoお姉ちゃんは、以下の条件を満たす観光計画を、よい観光計画だと思っています。

  • 観光を始める区画を区画 (p,q) としたときに、X_1 \leq p \leq X_2 , Y_1 \leq q \leq Y_2 を満たしている。

  • お昼ごはんを食べる区画を区画 (s,t) としたときに、X_3 \leq s \leq X_4 , Y_3 \leq t \leq Y_4 を満たしている。

  • 観光を終了する区画を区画 (u,v) としたときに、X_5 \leq u \leq X_6 , Y_5 \leq v \leq Y_6 を満たしている。

  • 観光の開始地点から終了地点まで、お昼ごはんを食べる区画を通りながら、隣接する(辺を共有する)区画への移動を繰り返して、最短距離で移動している。

ある二つの観光計画は、観光を開始する区画、お昼ご飯を食べる区画、観光を終了する区画、または途中で訪れる区画が異なる時、異なる観光計画とみなされます。 joisinoお姉ちゃんは、よい観光計画が何通りあるかを知りたくなりました。 よい観光計画が何通りあるかを求めてください。 なお、答えは非常に大きくなることがあるので、10^9+7 で割った余りを求めてください。

制約

  • 1 \leq X_1 \leq X_2 < X_3 \leq X_4 < X_5 \leq X_6 \leq 10^6
  • 1 \leq Y_1 \leq Y_2 < Y_3 \leq Y_4 < Y_5 \leq Y_6 \leq 10^6

入力

入力は以下の形式で標準入力から与えられる。

X_1 X_2 X_3 X_4 X_5 X_6
Y_1 Y_2 Y_3 Y_4 Y_5 Y_6

出力

よい観光計画が何通りあるかを求め、その値を 10^9+7 で割った余りを出力せよ。


入力例 1

1 1 2 2 3 4
1 1 2 2 3 3

出力例 1

10

観光を開始する区画は必ず区画 (1,1) に、お昼ご飯を食べる区画は必ず区画 (2,2) になります。 観光を終了する区画が区画 (3,3) のとき、移動する方法は 4 通りあります。 観光を終了する区画が区画 (4,3) のとき、移動する方法は 6 通りあります。 よって、この例の答えは 6+4=10 通りになります。


入力例 2

1 2 3 4 5 6
1 2 3 4 5 6

出力例 2

2346

入力例 3

77523 89555 420588 604360 845669 973451
2743 188053 544330 647651 709337 988194

出力例 3

137477680

Score : 1600 points

Problem Statement

Joisino is planning on touring Takahashi Town. The town is divided into square sections by north-south and east-west lines. We will refer to the section that is the x-th from the west and the y-th from the north as (x,y).

Joisino thinks that a touring plan is good if it satisfies the following conditions:

  • Let (p,q) be the section where she starts the tour. Then, X_1 \leq p \leq X_2 and Y_1 \leq q \leq Y_2 hold.

  • Let (s,t) be the section where she has lunch. Then, X_3 \leq s \leq X_4 and Y_3 \leq t \leq Y_4 hold.

  • Let (u,v) be the section where she ends the tour. Then, X_5 \leq u \leq X_6 and Y_5 \leq v \leq Y_6 hold.

  • By repeatedly moving to the adjacent section (sharing a side), she travels from the starting section to the ending section in the shortest distance, passing the lunch section on the way.

Two touring plans are considered different if at least one of the following is different: the starting section, the lunch section, the ending section, and the sections that are visited on the way. Joisino would like to know how many different good touring plans there are. Find the number of the different good touring plans. Since it may be extremely large, find the count modulo 10^9+7.

Constraints

  • 1 \leq X_1 \leq X_2 < X_3 \leq X_4 < X_5 \leq X_6 \leq 10^6
  • 1 \leq Y_1 \leq Y_2 < Y_3 \leq Y_4 < Y_5 \leq Y_6 \leq 10^6

Input

Input is given from Standard Input in the following format:

X_1 X_2 X_3 X_4 X_5 X_6
Y_1 Y_2 Y_3 Y_4 Y_5 Y_6

Output

Print the number of the different good touring plans, modulo 10^9+7.


Sample Input 1

1 1 2 2 3 4
1 1 2 2 3 3

Sample Output 1

10

The starting section will always be (1,1), and the lunch section will always be (2,2). There are four good touring plans where (3,3) is the ending section, and six good touring plans where (4,3) is the ending section. Therefore, the answer is 6+4=10.


Sample Input 2

1 2 3 4 5 6
1 2 3 4 5 6

Sample Output 2

2346

Sample Input 3

77523 89555 420588 604360 845669 973451
2743 188053 544330 647651 709337 988194

Sample Output 3

137477680
F - Two Trees

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 1700

問題文

N 頂点からなる根付き木が 2 つあります。 どちらの木の頂点も、それぞれ 1 から N の番号がついています。 1 つめの木の 頂点 i の親は A_i です。 なお、頂点 i が根のときは、A_i=-1です。 2 つめの木の 頂点 i の親は B_i です。 なお、頂点 i が根のときは、B_i=-1です。

すぬけ君は、長さ N の整数列 X_1 , X_2 , ... , X_N であって、次の条件を満たすものを求めたいです。

  • どちらの木のどの頂点についても、その頂点とその子孫の頂点の番号を a_1 , a_2 , ... , a_k としたとき、 abs(X_{a_1} + X_{a_2} + ... + X_{a_k})=1 が成り立つ。

条件を満たす整数列を作ることができるか判定し、存在するならば 1 つ求めてください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq N (頂点 i1 つ目の木の根でないとき)
  • A_i = -1 (頂点 i1 つ目の木の根のとき)
  • 1 \leq B_i \leq N (頂点 i2 つ目の木の根でないとき)
  • B_i = -1 (頂点 i2 つ目の木の根のとき)
  • 入力はvalidな根付き木である。

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 .. A_N
B_1 B_2 .. B_N

出力

条件を満たす整数列を作ることができない場合は、IMPOSSIBLE と出力せよ。 作ることができる場合は、まず 1 行目に、POSSIBLE と出力せよ。 続いて、2 行目には条件を満たす整数列 X_1 , X_2 , ... , X_N を空白区切りで出力せよ。


入力例 1

5
3 3 4 -1 4
4 4 1 -1 1

出力例 1

POSSIBLE
1 -1 -1 3 -1

例えば、1 つ目の木の頂点 3 について見てみると、その頂点と子孫の頂点の番号は、3,1,2 となっています。 出力例のように整数列を設定すると、abs(X_3+X_1+X_2)=abs((-1)+(1)+(-1))=abs(-1)=1 となっており、問題ありません。 他の頂点についても同じように確かめると、確かに出力例の整数列は条件を満たしています。


入力例 2

6
-1 5 1 5 1 3
6 5 5 3 -1 3

出力例 2

IMPOSSIBLE

この例では、どうやっても条件を満たす整数列は作れません。 よって、この例の答えは IMPOSSIBLE になります。


入力例 3

8
2 7 1 2 2 1 -1 4
4 -1 4 7 4 4 2 4

出力例 3

POSSIBLE
1 2 -1 0 -1 1 0 -1

Score : 1700 points

Problem Statement

There are two rooted trees, each with N vertices. The vertices of each tree are numbered 1 through N. In the first tree, the parent of Vertex i is Vertex A_i. Here, A_i=-1 if Vertex i is the root of the first tree. In the second tree, the parent of Vertex i is Vertex B_i. Here, B_i=-1 if Vertex i is the root of the second tree.

Snuke would like to construct an integer sequence of length N, X_1 , X_2 , ... , X_N, that satisfies the following condition:

  • For each vertex on each tree, let the indices of its descendants including itself be a_1 , a_2 , ..., a_k. Then, abs(X_{a_1} + X_{a_2} + ... + X_{a_k})=1 holds.

Determine whether it is possible to construct such a sequence. If the answer is possible, find one such sequence.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq N, if Vertex i is not the root in the first tree.
  • A_i = -1, if Vertex i is the root in the first tree.
  • 1 \leq B_i \leq N, if Vertex i is not the root in the second tree.
  • B_i = -1, if Vertex i is the root in the second tree.
  • Input corresponds to valid rooted trees.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 .. A_N
B_1 B_2 .. B_N

Output

If it is not possible to construct an integer sequence that satisfies the condition, print IMPOSSIBLE. If it is possible, print POSSIBLE in the first line. Then, in the second line, print X_1 , X_2 , ... , X_N, an integer sequence that satisfies the condition.


Sample Input 1

5
3 3 4 -1 4
4 4 1 -1 1

Sample Output 1

POSSIBLE
1 -1 -1 3 -1

For example, the indices of the descendants of Vertex 3 of the first tree including itself, is 3,1,2. It can be seen that the sample output holds abs(X_3+X_1+X_2)=abs((-1)+(1)+(-1))=abs(-1)=1. Similarly, the condition is also satisfied for other vertices.


Sample Input 2

6
-1 5 1 5 1 3
6 5 5 3 -1 3

Sample Output 2

IMPOSSIBLE

In this case, constructing a sequence that satisfies the condition is IMPOSSIBLE.


Sample Input 3

8
2 7 1 2 2 1 -1 4
4 -1 4 7 4 4 2 4

Sample Output 3

POSSIBLE
1 2 -1 0 -1 1 0 -1