Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    s = np.array(s)
    L = np.zeros((H, W))
    R = np.zeros((H, W))
    T = np.zeros((H, W))
    B = np.zeros((H, W))
    for h in range(H):
        for w in range(W):
            if s[h, w] == "#":
                R[h, w] = 0
            elif w == 0:
                R[h, w] = 1
            else:
                R[h, w] = R[h, w - 1] + 1
    for h in range(H):
        for w in reversed(range(W)):
            if s[h, w] == "#":
                L[h, w] = 0
            elif w == W - 1:
                L[h, w] = 1
            else:
                L[h, w] = L[h, w + 1] + 1
    for w in range(W):
        for h in range(H):
            if s[h, w] == "#":
                B[h, w] = 0
            elif h == 0:
                B[h, w] = 1
            else:
                B[h, w] = B[h-1, w] + 1
    for w in range(W):
        for h in reversed(range(H)):
            if s[h, w] == "#":
                T[h, w] = 0
            elif h == H - 1:
                T[h, w] = 1
            else:
                T[h, w] = T[h + 1, w] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            res = R[h, w] + L[h, w] + B[h, w] + T[h, w] - 3
            ans = max(ans, res)
    print(int(ans))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    L = [[0] * W for _ in range(H)]
    R = [[0] * W for _ in range(H)]
    T = [[0] * W for _ in range(H)]
    B = [[0] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if s[h][w] == "#":
                R[h][w] = 0
            elif w == 0:
                R[h][w] = 1
            else:
                R[h][w] = R[h][w - 1] + 1
    for h in range(H):
        for w in reversed(range(W)):
            if s[h][w] == "#":
                L[h][w] = 0
            elif w == W - 1:
                L[h][w] = 1
            else:
                L[h][w] = L[h][w + 1] + 1
    for w in range(W):
        for h in range(H):
            if s[h][w] == "#":
                B[h][w] = 0
            elif h == 0:
                B[h][w] = 1
            else:
                B[h][w] = B[h-1][w] + 1
    for w in range(W):
        for h in reversed(range(H)):
            if s[h][w] == "#":
                T[h][w] = 0
            elif h == H - 1:
                T[h][w] = 1
            else:
                T[h][w] = T[h + 1][w] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            res = R[h][w] + L[h][w] + B[h][w] + T[h][w] - 3
            ans = max(ans, res)
    print(int(ans))


if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))

M = 10**9 + 7
ans = 0

for i in range(N-1):
    for n in range(i + 1, N):
        ans += A[i] * A[n]
        ans = ans % M

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

M = 10**9 + 7

Total = sum(A) -A[0]

ans = 0

for i in range(N-1):
    ans += A[i] * Total
    ans = ans % M
    Total -= A[i+1]

print(ans)
### BUGGY CODE ###

s=input()
q=int(input())
for i in range(q):
	a=input()
	if a=="1":
		s=s[::-1]
	else:
		a,f,c = a.split()
		if f=="1":
			s=c+s
		else:
			s+=c
print(s)

### FIXED CODE ###

from collections import deque

deq=deque()
k = input()
for i in range(len(k)):
	deq.append(k[i])
q=int(input())
x=True
for i in range(q):
	a=input()
	if a[0]=="1":
		x = not x
	elif a[2]=="1":
		if x==True:
			deq.appendleft(a[4])
		else:
			deq.append(a[4])
	else:
		if x==True:
			deq.append(a[4])
		else:
			deq.appendleft(a[4])
if x==True:
	c="".join(deq)
else:
	deq.reverse()
	c="".join(deq)
print(c)
### BUGGY CODE ###

def solve():
    R,C,K = map(int, input().split())
    value = [[0 for _ in range(C)] for _ in range(R)]
    dp = [[[0,0,0,0] for _ in range(C+1)] for _ in range (R+1)]
    for _ in range(K):
        r,c,v = map(int, input().split())
        value[r-1][c-1] = v

    #print(value)
    #print(dp)

    for r in range(1, R+1):
        for c in range(1, C+1):
            v = value[r-1][c-1]
            if v == 0: # no item
                dp[r][c][0] = max(max(dp[r-1][c]), dp[r][c-1][0])
                dp[r][c][1] = dp[r][c-1][1]
                dp[r][c][2] = dp[r][c-1][2]
                dp[r][c][3] = dp[r][c-1][3]
            else:
                dp[r][c][0] = max(max(dp[r - 1][c]), dp[r][c-1][0])
                dp[r][c][1] = max(dp[r][c-1][1], dp[r][c-1][0] + v, max(dp[r - 1][c]) + v)
                dp[r][c][2] = max(dp[r][c-1][2], dp[r][c-1][1] + v)
                dp[r][c][3] = max(dp[r][c-1][3], dp[r][c-1][2] + v)

    #print(dp)
    print(max(dp[R][C]))

solve()

### FIXED CODE ###

def solve():
    R,C,K = map(int, input().split())
    #value = [[0 for _ in range(C)] for _ in range(R)]
    dp = [[[0 for _ in range(C+1)] for _ in range (R+1)] for _ in range(5)]
    for _ in range(K):
        r,c,v = map(int, input().split())
        dp[4][r][c] = v

    #print(value)
    #print(dp)

    for r in range(1, R+1):
        for c in range(1, C+1):
            v = dp[4][r][c]
            prow = max(dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
            if v == 0: # no item
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = dp[1][r][c-1]
                dp[2][r][c] = dp[2][r][c-1]
                dp[3][r][c] = dp[3][r][c-1]
            else:
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v)
                dp[2][r][c] = max(dp[2][r][c-1], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c-1], dp[2][r][c-1] + v)

    #print(dp)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))

solve()
### BUGGY CODE ###

n=int(input())
li=[]
for i in range(n):
  li.append(int(input()))
pl=[0]
for i in range(2**n):
  point=0
  for j in range(n):
    if ((i>>j)&1):
      point+=li[j]
  if point%10!=0:
    pl.append(point)
pl.sort(reverse=True)
for i in pl:
  if i%10!=0:
    print(i)
    break
else:
  print(0)
    

### FIXED CODE ###

n=int(input())
li=[]
for i in range(n):
  li.append(int(input()))
out=sum(li)
if out%10!=0:
  print(out)
else:
  li.sort()
  for i in li:
    if i%10!=0:
      print(out-i)
      break
  else:
    print(0)
### BUGGY CODE ###

# coding: utf-8

N=int(input())
A=list(map(int,input().split()))
INF=10**18

dp=[[-INF for i in range(N+1)] for i in range(N+1)]
dp[0][0]=0
dp[1][0]=0
dp[2][0]=0
dp[1][1]=A[0]
dp[2][1]=A[1]

for i in range(3,N+1):
    for j in range((i//2),((i+1)//2)+1):
        dp[i][j]=max(dp[i-2][j-1]+A[i-1],dp[i-3][j-1]+A[i-1],dp[i-2][j],dp[i-3][j])


print(max(dp[N][N//2],dp[N-1][N//2],dp[N-2][N//2]))



### FIXED CODE ###

# coding: utf-8

N=int(input())
A=list(map(int,input().split()))
INF=10**18

dp=[[-INF for i in range(2)] for j in range(N+1)]
dp[0][0]=0
dp[1][0]=0
dp[2][0]=0
dp[1][1]=A[0]
dp[2][1]=A[1]

for i in range(3,N+1):
    dp[i][0]=max(dp[i-2][0]+A[i-1],dp[i-2][1])
    if i%2==0:
        dp[i][0]=max(dp[i][0],dp[i-3][0]+A[i-1])
    else:
        dp[i][0]=max(dp[i][0],dp[i-3][1]+A[i-1])
    
    dp[i][1]=dp[i-2][1]+A[i-1]
    if i%2==0:
        dp[i][1]=max(dp[i][1],dp[i-3][1]+A[i-1])

if N%2==0:
    print(max(dp[N][1],dp[N-1][1]))
else:
    print(max(dp[N][0],dp[N-1][1],dp[N-2][1]))
### BUGGY CODE ###

N=int(input())
L=list(map(int, input().split()))
L.sort()
L.reverse()
a=L.pop(0)
count=0
while(L!=[]):
    for i in range(len(L)):
        for j in range(i+1,len(L)):
            if a < L[i]+L[j]:
                count+=1
    a=L.pop(0)
print(count)

### FIXED CODE ###

import bisect

N=int(input())
L=list(map(int, input().split()))
ll=len(L)
L.sort()

s=0
for i in range(ll):
    for j in range(i+1,ll):
        s+=bisect.bisect_right(L,L[i]+L[j]-1)-j-1

print(s)
### BUGGY CODE ###

s=input()
q=int(input())
for _ in range(q):
    query = input()
    try:
        t = int(query)
        s = s[::-1]
    except ValueError:
        t,f,c = map(str,query.split())
        if f == "1":
            s = c + s
        if f == "2":
            s = s + c
print(s)

### FIXED CODE ###

def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()
### BUGGY CODE ###

H,W = map(int, input().split())
s = [input() for j in range(H)]

def counter(x, y):
    count = 1
    h1 = x - 1
    while h1 >= 0 and s[h1][y] == ".":
        count += 1
        h1 -= 1
    
    h2 = x + 1
    while h2 < H and s[h2][y] == ".":
        count += 1
        h2 += 1
    
    w1 = y -1
    while w1 >= 0 and s[x][w1] == ".":
        count += 1
        w1 -= 1
    
    w2 = y + 1
    while w2 < W and s[x][w2] == ".":
        count += 1
        w2 += 1
    
    return count

c = []
for i in range(H):
    for j in range(W):
        if s[i][j] == ".":
            c.append(counter(i, j))

print(max(c))


### FIXED CODE ###

import numpy as np

H,W = map(int, input().split())
s = [list(input()) for j in range(H)]
s = (np.array(s) == ".") * 1

L = np.zeros((H, W), dtype = int)
R = np.zeros((H, W), dtype = int)
U = np.zeros((H, W), dtype = int)
D = np.zeros((H, W), dtype = int)


for j in range(W):
    if j == 0:
        L[:,j] = s[:,j]
    else:
        L[:,j] = (L[:,j-1] + 1) * s[:,j]
        

for j in reversed(range(W)):
    if j == W-1:
        R[:,j] = s[:,j]
    else:
        R[:,j] = (R[:,j+1] + 1) * s[:,j]


for i in range(H):
    if i == 0:
        U[i,:] = s[i,:]
    else:
        U[i,:] = (U[i-1,:] + 1) * s[i,:]

for i in reversed(range(H)):
    if i == H-1:
        D[i,:] = s[i,:]
    else:
        D[i,:] = (D[i+1,:] + 1) * s[i,:]

print(np.max(L + R + U + D - 3))
### BUGGY CODE ###

import numpy as np
import sys
sys.setrecursionlimit(10**8)

from fractions import gcd

n, x = map(int, input().split())

X = list(map(int,input().split()))
X = [abs(i-x) for i in X]
# print(X)

# def gcd(m,n):
#     mx = max(m,n)
#     mn = min(m,n)
#     tmp = mx%mn
#     if tmp == 0:
#         return mn
#     else:
#         return gcd(mn, tmp)

def gcd_list(data):
    if len(data)==1:
        return data[0]
    tmp = gcd(data[0], data[1])
    if len(data)==2:
        return tmp
    else:
        new_data = [tmp]+data[2:]
        return gcd_list(new_data)

# print(gcd_list([2,4,8]))
print(gcd_list(X))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)

from fractions import gcd

n, x = map(int, input().split())

X = list(map(int,input().split()))
X = [abs(i-x) for i in X]
# print(X)

# def gcd(m,n):
#     mx = max(m,n)
#     mn = min(m,n)
#     tmp = mx%mn
#     if tmp == 0:
#         return mn
#     else:
#         return gcd(mn, tmp)

def gcd_list(data):
    # if len(data)==1:
    #     return data[0]
    # tmp = gcd(data[0], data[1])
    # if len(data)==2:
    #     return tmp
    # else:
    #     new_data = [tmp]+data[2:]
    #     return gcd_list(new_data)
    ret = data[0]
    for d in data[1:]:
        ret = gcd(ret, d)
    return ret
# print(gcd_list([2,4,8]))
print(gcd_list(X))
### BUGGY CODE ###

import math
import sys
import collections
def main():
    N=int(input())
    Tr=tuple(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
       if Tr[i]=="G":
           G.append(i)
       if Tr[i]=="B":
           B.append(i)
    cnt=0
    for i in R:
        for j in G:
            for k in B:
                if max(i,j,k)-(i+j+k-max(i,j,k)-min(i,j,k))!=(i+j+k-max(i,j,k)-min(i,j,k))-min(i,j,k):
                    cnt+=1

    print(cnt)
if __name__ == '__main__':
    main()

### FIXED CODE ###

import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import math
S=input()
Q=int(input())
Rev=1
front=""
back=""
for i in range(Q):
    a=input().split()
    if a[0]=="1":
        Rev=Rev*-1
        continue
    if (a[1]=="1"and Rev==1) or (a[1]=="2" and Rev==-1):
        front+=a[2]
    else:
        back+=a[2]
if Rev==1:
    #str(front.reverse().extend(S).extend(back))
    print(front[::-1]+S+back)
    #str(front.reverse()+S+back)
else:
    print(back[::-1]+S[::-1]+front)

### FIXED CODE ###

S=input()
Q=int(input())
Rev=True
front=''
back=''
for i in range(Q):
    a=input()
    if a=='1':
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == '1':
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)
### BUGGY CODE ###

n = int(input())
s = input()

count = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            flag = 0
            for i in range(0, n-2):
                if flag == 1:
                    break
                if int(s[i]) == c:
                    for j in range(i+1, n-1):
                        if flag == 1:
                            break
                        if int(s[j]) == b:
                            for k in range(j+1, n):
                                if int(s[k]) == a:
                                    count += 1
                                    flag = 1
                                    break
print(count)


### FIXED CODE ###

# TLE

n = int(input())
s = input()

count = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            f1 = False
            f2 = False
            p1 = 0
            p2 = 0
            for i in range(0, n-2):
                if int(s[i]) == a:
                    f1 = True
                    p1 = i
                    break
            if f1:
                for j in range(p1+1, n-1):
                    if int(s[j]) == b:
                        f2 = True
                        p2 = j
                        break
            if f2:
                for k in range(p2+1, n):
                    if int(s[k]) == c:
                        count += 1
                        break
            if not f1 or not f2:
                break
print(count)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
N = int(input())
S = input()

T = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
  for j in range(i + 1, N):
    if S[i] == S[j]:
      T[i][j] += T[i - 1][j - 1] + 1

answer = 0
for i in range(N):
  for j in range(N):
    if T[i][j] and j - i >= T[i][j]:
      answer = max(answer, T[i][j])
print(answer)


### FIXED CODE ###

import sys
input=sys.stdin.readline
N = int(input())
S = input()

T = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
  for j in range(i + 1, N):
    if S[i] == S[j]:
      T[i][j] += T[i - 1][j - 1] + 1

answer = 0
for i in range(N):
  for j in range(N):
    if T[i][j] and j - i >= T[i][j]:
      answer = max(answer, T[i][j])
print(answer)
### BUGGY CODE ###

from itertools import product
from bisect import bisect_left as bl
H, W, N = list(map(int, input().split()))
A = [tuple(map(int, input().split())) for _ in range(N)]
A.sort()
ans = [0] * 10
for x, y in A:
    for ltx, lty in product(range(max(1, x-2), min(x+1, H-1)), 
                            range(max(1, y-2), min(y+1, W-1))):
        num = sum(bl(A, (ltx+i, lty+3)) - bl(A, (ltx+i, lty)) for i in range(3))
        ans[num] += 1
for i in range(1, len(ans)):
    ans[i] //= i
ans[0] = (H - 2) * (W - 2) - sum(ans)
print(*ans, sep="\n")


### FIXED CODE ###

from itertools import product
H, W, N = list(map(int, input().split()))
A = [tuple(map(int, input().split())) for _ in range(N)]
count = {}
for x, y in A:
    for xx, yy in product(range(x-1, x+2), range(y-1, y+2)):
        if not(2 <= xx <= H-1 and 2 <= yy <= W-1):
            continue
        count[(xx, yy)] = count.get((xx, yy), 0) + 1
ans = [0] * 10
for k, v in count.items():
    ans[v] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans)
print(*ans, sep="\n")
### BUGGY CODE ###

import fractions

N=int(input())
A=list(map(int,input().split()))

ans2=0
for i in range(N):
    AA=A[:i]+A[i+1:]
    ans=0
    for j in range(N-1):
        ans=fractions.gcd(ans,AA[j])
    ans2=max(ans,ans2)
    #print(AA,ans,ans2)

print(ans2)

### FIXED CODE ###

import fractions

N=int(input())
A=list(map(int,input().split()))

L=[0,A[0]]
R=[0,A[-1]]
for i in range(N-1):
    #l=fractions.gcd(L[i+1],A[i+1])
    #r=fractions.gcd(R[i+1],A[N-i-2])
    L.append(fractions.gcd(L[i+1],A[i+1]))
    R.append(fractions.gcd(R[i+1],A[N-i-2]))
    #print(L[i+1],A[i+1],R[i+1],A[N-i-2])
#print(L)
#print(R)
arr=[]
for i in range(N):
    a=fractions.gcd(L[i],R[N-i-1])
    arr.append(a)
    #print(i,L[i],R[N-i-1],a,arr)
print(max(arr))
### BUGGY CODE ###

N = int(input())
s = input()
mn=N
for i in range(N):
    lw=s[:i].count("W")
    re=s[i+1:].count("E")
    sm=lw+re
    if mn>sm:
        mn=sm
print(mn)
    

### FIXED CODE ###

N = int(input())
s = input()
mn=N
lw=0
re=s[1:].count("E")
for i in range(N):
    if i-1>=0 and s[i-1]=="W":
        lw+=1
    if i-1>=0 and s[i]=="E":
        re-=1
    
    sm=lw+re
    if mn>sm:
        mn=sm
print(mn)
### BUGGY CODE ###

a = int(input())
ar = []
for i in range(a):
    l = input()
    if l not in ar:
        ar.append(l)
print(len(ar))

### FIXED CODE ###

a = int(input())
ar = []
for i in range(a):
    l = input()
    ar.append(l)
print(len(set(ar)))
### BUGGY CODE ###

from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector, deque as que
read = lambda: list(map(int,input().split()))
from bisect import bisect
from heapq import heappush as hpush,heappop as hpop

n,m,k=read()
A=read()
B=read()
a,b=[0],[0]
for i in range(n):
	a.append(a[i]+A[i])
for i in range(m):
	b.append(b[i]+B[i])
ans=0
for i in range(0,n+1):
	curr=a[i]
	j=m
	if curr>k:
		break
	while(b[j]>k-curr):
		j-=1
	ans=max(ans,i+j)
print(ans)



### FIXED CODE ###

from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector, deque as que
read = lambda: list(map(int,input().split()))
from bisect import bisect
from heapq import heappush as hpush,heappop as hpop

n,m,k=read()
A=read()
B=read()
a,b=[0],[0]
for i in range(n):
	a.append(a[i]+A[i])
for i in range(m):
	b.append(b[i]+B[i])
ans=0;j=m
for i in range(0,n+1):
	curr=a[i]
	if curr>k:
		break
	while(b[j]>k-curr):
		j-=1
	ans=max(ans,i+j)
print(ans)
### BUGGY CODE ###

N,K,L = map(int, input().split())


class UFT:
    def __init__(self, N):
        self.UFdata = [-1] * (N+1)
        self.rank   = [0]  * (N+1)
        self.connected_num = [1] * (N+1)

    def find(self,x):
        UFdata = self.UFdata
        while UFdata[x] != -1:
            x = UFdata[x]
        return x

    def unite(self,x,y):
        UFdata = self.UFdata
        rank = self.rank
        connected_num = self.connected_num
        find = self.find

        x = find(x)
        y = find(y)
        if x != y:
            if rank[x] < rank[y]:
                UFdata[x] = UFdata[y]
                x,y = y,x
            if rank[x] == rank[y]:
                rank[x] += 1
            UFdata[y] = x       
            connected_num[x] += connected_num[y]
            

UF1 = UFT(N)
UF2 = UFT(N)
ans = [1] * (N+1)
MAP= [ [0] * (N+1) for _ in range(N+1)]
import sys
input = sys.stdin.readline
PQ = [ [int(j) for j in input().split()] for _ in range(K)]
RS = [ [int(j) for j in input().split()] for _ in range(L)]

for i in range(K):
    p,q = PQ[i]
    if UF1.find(p) != -1 and UF1.find(p) != UF1.find(q)  or UF1.find(p) == UF1.find(q) == -1:
        UF1.unite(p,q)

    

for i in range(L):
    p,q = RS[i]

    if UF1.find(p) != -1 and UF1.find(p) == UF1.find(q) :
        UF2.unite(p, q)

ans = []
for i in range(1,N+1):
    ans.append (  UF2.connected_num[ UF2.find( i) ] )

# print(" ".join( map(lambda x: str(x), connected_num[1:])))
print(" ".join( map(lambda x: str(x), ans)))


### FIXED CODE ###

N,K,L = map(int, input().split())


class UFT:
    def __init__(self, N):
        self.UFdata = [-1] * (N+1)
        self.rank   = [0]  * (N+1)

    def find(self,x):
        UFdata = self.UFdata
        while UFdata[x] != -1:
            x = UFdata[x]
        return x

    def unite(self,x,y):
        UFdata = self.UFdata
        rank = self.rank 
        find = self.find

        x = find(x)
        y = find(y)
        if x != y:
            if rank[x] < rank[y]:
                x,y = y,x
            if rank[x] == rank[y]:
                rank[x] += 1
            UFdata[y] = x       
            

UF1 = UFT(N)
UF2 = UFT(N)
ans = [1] * (N+1)
# MAP= [ [0] * (N+1) for _ in range(N+1)]
import sys
input = sys.stdin.readline
#PQ = [ [int(j) for j in input().split()] for _ in range(K)]
#RS = [ [int(j) for j in input().split()] for _ in range(L)]

for i in range(K):
    p,q = map(int,input().split())
    UF1.unite(p,q)
for i in range(L):
    p,q = map(int,input().split())#RS[i]
    UF2.unite(p, q)
counter=[]
from collections import defaultdict
cntdic =defaultdict(int)
for i in range(1,N+1):
  counter.append(UF1.find(i)+UF2.find(i)*10**6)
  cntdic[counter[-1]]+=1 

ans = [0]*(N+1)
for i in range(1,N+1):
    ans[i] = cntdic[counter[i-1]]

del ans[0]
# print(" ".join( map(lambda x: str(x), connected_num[1:])))
print(" ".join( map(lambda x: str(x), ans)))
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = [10**10] * n

edge = [[] for i in range(n)]

for i in range(m):
    l, r, d = map(int, input().split())
    l-=1;r-=1
    edge[l].append((r, d))
    edge[r].append((l, -d))

flag = True
for i in range(n):
    if not flag: break
    dist = [10**10]*n
    dist[i] = 0
    dq = deque([i])
    while dq:
        now = dq.popleft()
        for e in edge[now]:
            nnode, d = e
            if dist[nnode] == 10**10:
                dist[nnode] = dist[now] + d
                dq.append(nnode)
            else:
                if dist[nnode] != dist[now] + d:
                    flag = False
                    break
if flag:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
inf = pow(10, 10)

n, m = map(int, input().split())
a = [inf] * n

edge = [[] for i in range(n)]

for i in range(m):
    l, r, d = map(int, input().split())
    l-=1;r-=1
    edge[l].append((r, d))
    edge[r].append((l, -d))

flag = True
dist = [inf] * n
for i in range(n):
    if not flag: break
    if dist[i] == inf:
        dist[i] = 0
        dq = deque([i])
        while dq:
            now = dq.popleft()
            for e in edge[now]:
                nnode, d = e
                if dist[nnode] == inf:
                    dist[nnode] = dist[now] + d
                    dq.append(nnode)
                else:
                    if dist[nnode] != dist[now] + d:
                        flag = False
                        break
if flag:
    print('Yes')
else:
    print('No')