Constraints

* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 9900
* -2 × 107 ≤ di ≤ 2 × 107
* There are no parallel edges
* There are no self-loops

Input

An edge-weighted graph G (V, E).


|V| |E|
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.

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), print


NEGATIVE CYCLE


in a line.

Otherwise, print


D0,0 D0,1 ... D0,|V|-1
D1,0 D1,1 ... D1,|V|-1
:
D|V|-1,0 D1,1 ... D|V|-1,|V|-1


The output consists of |V| lines. For each ith line, print the cost of the shortest path from vertex i to each vertex j (j = 0, 1, ... |V|-1) respectively. If there is no path from vertex i to vertex j, print "INF". Print a space between the costs.

Examples

Input

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


Output

0 1 3 4
INF 0 2 3
INF INF 0 1
INF INF 7 0


Input

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


Output

0 1 -5 -4
INF 0 2 3
INF INF 0 1
INF INF 7 0


Input

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


Output

NEGATIVE CYCLE
from itertools import product

class FloydWarshall:
    def __init__(self, N):
        self.N = N # #vertices
        self.E = [[] for _ in range(N)]

    def add_edge(self, init, end, weight, undirected=False):
        self.E[init].append((end, weight))
        if undirected: self.E[end].append((init, weight))
    
    def distance(self):
        INF = float('inf')
        self.dist = [[INF] * self.N for _ in range(self.N)] # dist[s][t]: the distance of vertex t from s
        self.prev = [[-1] * self.N for _ in range(self.N)] # prev[s][t]: the previous vertex of vertex t on a shortest path from s
        # initialize
        for v in range(self.N):
            self.dist[v][v] = 0; self.prev[v][v] = -1
            for u, c in self.E[v]: self.dist[v][u] = c; self.prev[v][u] = v
        # update
        for k in range(self.N):        
            for i, j in product(range(self.N), repeat=2):
                temp = self.dist[i][k] + self.dist[k][j]
                if self.dist[i][j] > temp: self.dist[i][j] = temp; self.prev[i][j] = self.prev[k][j]
        for v in range(self.N):
            if self.dist[v][v] < 0: return None # There exists a negative cycle
        return self.dist
    
    def shortest_path(self, s, t):
        P = []
        prev_s = self.prev[s]
        while True:
            P.append(t)
            t = prev_s[t]
            if t == -1: break
            elif t == P[0]: P.append(t); break
        return P[::-1]

INF = float('inf')
N, M = map(int, input().split())
fw = FloydWarshall(N)
for _ in range(M):
    a, b, c = map(int, input().split())
    fw.add_edge(a, b, c)
dist = fw.distance()
if dist is None: print('NEGATIVE CYCLE')
else:
    for dst in dist: print(*[d if d != INF else 'INF' for d in dst])
