Problem: Constraints

* 1 ≤ |V| ≤ 1000
* 0 ≤ |E| ≤ 2000
* -10000 ≤ di ≤ 10000
* There are no parallel edges
* There are no self-loops

Input

An edge-weighted graph G (V, E) and the source r.


|V| |E| r
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1


|V| is the number of vertices and |E| is the number of edges in G. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the source of the graph.

si and ti represent source and target vertices of i-th edge (directed) and di represents the cost of the i-th edge.

Output

If the graph contains a negative cycle (a cycle whose sum of edge costs is a negative value) which is reachable from the source r, print


NEGATIVE CYCLE


in a line.

Otherwise, print


c0
c1
:
c|V|-1


The output consists of |V| lines. Print the cost of the shortest path from the source r to each vertex 0, 1, ... |V|-1 in order. If there is no path from the source to a vertex, print "INF".

Examples

Input

4 5 0
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2


Output

0
2
-3
-1


Input

4 6 0
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2
3 1 0


Output

NEGATIVE CYCLE


Input

4 5 1
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2


Output

INF
0
-5
-3

Solution (in PYTHON3):

Solution:
# 入力１
Vn, En, r = map(int, input().split())

# 入力２：各頂点から別の頂点へ移動する辺とコスト
E = []
for _ in range(En):
    s, t, c = map(int, input().split())
    E.append((s,t,c))

# 初期化
INF = 10**3 * 10**4  # INF 以外で取りうる値は -10**3 * 10**4 < < 10**3 * 10**4
dp = [INF * 10] * Vn
dp[r] = 0

# ベルマン・フォード

# 頂点と同じ回数だけ dp を更新して「伝播」させる
for i in range(Vn):
    for u, v, duv in E:
        if dp[v] > dp[u] + duv:
            dp[v] = dp[u] + duv

# 負のループをチェックする
for u, v, c in E:
    # たどり着けない頂点に関しては無視
    if dp[v] > INF:
        continue
    if dp[u] + c < dp[v]:
        print("NEGATIVE CYCLE")
        break
else:
    # 解答
    for i in range(Vn):
        if not dp[i] > 10**3 * 10**4:  # 頂点数、辺のコストから、この値を下回ることは無いはず
            print(dp[i])
        else:
            print("INF")