Harryxun/stf_run huggingface dataset:
[N,M] = list(map(int,input().split()))
a = []
for i in range(M):
    a.append(int(input()))

#print(a)
dp = [0] * (N+1)
dp[0]=1
if a[0]!=1:
    dp[1]=1
#dp[1]=1
j=0
for i in range(1,N+1):
    if M!=0:
        if i==a[j]:
            dp[i] = 0
            j+=1
            if j==M:
                j=0

        else:
            dp[i] = dp[i-1] + dp[i-2]
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1] % 1000000007)

### FIXED CODE ###

[N,M] = list(map(int,input().split()))
a = []
for i in range(M):
    a.append(int(input()))

aa=[0]*(N+1)
for j in range(M):
    aa[a[j]] = 1

dp = [0]*(N+1)
dp[0]=1
if 1 not in a:
    dp[1]=1
else:
    dp[1]=0

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

print(dp[-1] % 1000000007)
from collections import deque
from math import ceil

# n个怪物，d杀伤半径，a杀伤值
n, d, a = map(int,input().split())

ms = sorted([(pos, ceil(hp / a)) for pos, hp in [map(int, input().split()) for i in range(n)])
 
bombs = deque()
 
ans = 0
valid_bomb = 0
for pos, hp in ms:
  # 查看队列里的bomb是否对当前怪物有效
  while que and que[0][0] < pos:
    bomb_border, bomb_cnt = bombs.popleft()
    valid_bomb -= bomb_cnt
  
  # 还需新加多少bomb才能灭掉当前怪物
  bomb_cnt = max(0, hp - valid_bomb)
  valid_bomb += bomb_cnt
  ans += bomb_cnt
  
  # 新加的bomb放入队列
  if bomb_cnt > 0:
    que.append([pos + d * 2, bomb_cnt])
 
print(ans)  


### FIXED CODE ###

from collections import deque
from math import ceil
 
n,d,a = map(int,input().split())
M = [list(map(int,input().split())) for i in range(n)]
M = sorted([(x,ceil(h/a)) for x,h in M])
 
que = deque()
 
ans = 0
atack = 0
for x,h in M:
  while len(que) > 0 and que[0][0] < x:
    tx,ta = que.popleft()
    atack -= ta      
  
  bomb_num = max(0, h-atack)
  atack += bomb_num
  ans += bomb_num
  
  if bomb_num > 0:
    que.append([x+d*2,bomb_num])
 
print(ans)
X = input()
Y = X ** 3
print(Y)

### FIXED CODE ###

X = int(input())
Y = X ** 3
print(Y)
import numpy as np
import sys
sys.setrecursionlimit(200000)

X = input()
Y = input()
lenX = len(X)
lenY = len(Y)
dp = np.full((lenX+1,lenY+1),"-1",dtype=object)
dp[0,:]=""
dp[:,0]=""
def f(i,j):
  if dp[i][j]=="-1":
    x = X[i-1]
    y = Y[j-1]
    lo = f(i-1,j-1)
    l = f(i,j-1)
    o = f(i-1,j)
    if x==y:
      dp[i][j]="".join([lo,x])
    else:
      if len(l)>=len(o):
        dp[i][j]=l
      else:
        dp[i][j]=o
  return dp[i][j]

print(f(lenX,lenY))


### FIXED CODE ###

# LongestCommonSubsequences
import numpy as np
S = np.array([ord(i)-97 for i in input()], dtype=int)
T = np.array([ord(i)-97 for i in input()], dtype=int)
Ns = len(S)
Nt = len(T)
equal = np.equal.outer(S, T).astype(int)

dp = [np.zeros(Nt + 1, dtype=int)]
for i in range(Ns):
    x = dp[-1].copy()
    newDP = x.copy()
    newDP[1:] = np.maximum(x[:-1] + equal[i], newDP[1:])
    np.maximum.accumulate(newDP, out=newDP)
    dp.append(newDP)


ans = ""
i, j = Ns, Nt
while i > 0 and j > 0:
    if S[i-1] == T[j-1]:
        ans += chr(S[i-1]+97)
        i -= 1
        j -= 1
        continue
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    else:
        j -= 1

print(ans[::-1])
mport bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
 
 
def solve2():
    N = int(input())
    L = list(map(int, input().split()))
    L = sorted(L)
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            min_sum = L[i]+L[j]
            more_than = bisect.bisect_left(L[j+1:], min_sum)
            ans += more_than
    print(ans)
 
 
solve2()

### FIXED CODE ###

from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += bisect_left(L, L[i]+L[j])-j-1
print(ans)
c = []
d = []
n,m = map(int, input().split())
for i in range(m):
    a,b = map(int,input().split())
    c.append(a)
    d.append(b)
minl = max(c)   
maxr = min(d)
if min1>maxr:
    print(0)
else:
    print(maxr-minl+1)

### FIXED CODE ###

c = []
d = []
n,m = map(int, input().split())
for i in range(m):
    a,b = map(int,input().split())
    c.append(a)
    d.append(b)
minl = max(c)   
maxr = min(d)
if minl>maxr:
    print(0)
else:
    print(maxr-minl+1)
from sys import stdin
input = stdin.readline
N=str(input())
NN=0
for i in range(len(N)):
    NN=NN+int(N[i])
  
if NN%9==0:print('Yes')
else:print('No')

### FIXED CODE ###

N=str(input())
NN=0
for i in range(len(N)):
    NN=NN+int(N[i])
  
if NN%9==0:print('Yes')
else:print('No')
a, b = input().split()
a = int(a)
b = int(b[0])*100 + int(b[1])*10 + int(b[3])
c = a*b
print(c//100)


### FIXED CODE ###

a, b = input().split()
a = int(a)
b = int(b[0])*100 + int(b[2])*10 + int(b[3])
c = a*b
print(c//100)
n = int(input())
edge = [[] for _ in range(n)]

for i in range(n-1):
    s, g, d = map(int, input().split())
    edge[s-1].append((g, d%2))
    edge[g-1].append((s, d%2))

ans = [None for _ in range(n)]

def set_color(x, col):
    ans[x-1] = col
    print(ans, edge[x-1])
    for g, d in edge[x-1]:
        if ans[g-1] == None:
            set_color(g, d^col)

set_color(1, 0)
for i in range(n):
    print(ans[i])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n=int(input())
edge=[[]for i in range(n+1)]

for i in range(n-1):
    u,v,w=map(int,input().split())
    if w%2==0:
        edge[u].append((v,1))
        edge[v].append((u,1))
    else:
        edge[u].append((v,-1))
        edge[v].append((u,-1))
        
color=[None]*(n+1)

def set_color(x,col):
    color[x]=col
    
    for i,j in edge[x]:
        if color[i] is None:
            set_color(i,j*col)

set_color(1,1)
for i in color[1:]:
    print((i+1)//2)
a = int(input())
lst = []
for i in range(a):
    b = input()
    if not(b in lst):
    	lst.append(b)
        
print(len(lst))
    



### FIXED CODE ###

a,b=map(int,input().split())

if (a > b):
    print("safe")
else:
    print("unsafe")
str = input()
print(str*str)

### FIXED CODE ###

str = int(input())
answer = str * str
print(answer)
import sys
pin=sys.stdin.readline

N=int(pin())
A=list(map(int,pin().split()))
B=list(map(int,pin().split()))
C=reversed(B)

for i in range(N):
  if A[i]==C[i]:
    break
else:
  print("Yes")
  for k in C:
    sys.stdout.write(f"{k} ")
  print()
  sys.exit()
D=B[N//2:]+B[:N//2]
for j in range(N):
  if A[j]==D[j]:
    print("No")
    break
else:
  print("Yes")
  for l in D:
    sys.stdout.write(f"{l} ")
  print()
  sys.exit()


### FIXED CODE ###

import sys
pin=sys.stdin.readline

N=int(pin())
A=list(map(int,pin().split()))
B=list(map(int,pin().split()))
C=list(reversed(B))

for i in range(N):
  if A[i]==C[i]:
    break
else:
  print("Yes")
  for k in C:
    sys.stdout.write(f"{k} ")
  print()
  sys.exit()
D=B[N//2:]+B[:N//2]
for j in range(N):
  if A[j]==D[j]:
    print("No")
    break
else:
  print("Yes")
  for l in D:
    sys.stdout.write(f"{l} ")
  print()
  sys.exit()
n,c=map(int,input().split())
A=[]
for i in range(n):
    A.append(list(map(int,input().split())))

ans=0

B1=[] #時計回り、引き返さない
su=0
for i in range(n):
    su+=A[i][1]
    B1.append(su-A[i][0])

#print(B1)

ans=max(ans,max(B1))

B2=[] #反時計回り、引き返さない
su=0
for i in range(n-1,-1,-1):
    su+=A[i][1]
    B2.append(su-(c-A[i][0]))

#print(B2)


ans=max(ans,max(B2))


B3=[] #時計回り、引き返す(半周以上周ってから引き返してはいけない)
B4=[] #反時計回り、引き返す（同上）

for i in range(n):
    if A[i][0]<=(c-0.1)//2 :
        B3.append(B1[i]-A[i][0])

#print(B3)

for i in range(n-1,-1,-1):
    j=0
    if (c-A[i][0])<=(c-0.1)//2 :
        B4.append(B2[j]-(c-A[i][0]))
    j+=1

#print(B4)

if len(B3)>0 :
    aa=B3.index(max(B3))
    #print(max(B3)+max(B2[:n-aa-1]))
    ans=max(ans,max(B3)+max(B2[:n-aa-1]))
if len(B4)>0 :
    bb=B4.index(max(B4))
    #print(max(B4)+max(B1[:n-bb-1]))
    ans=max(ans,max(B4)+max(B1[:n-bb-1]))

print(ans)


### FIXED CODE ###

n, c = map(int, input().split())
XR = [list(map(int,input().split())) for i in range(n)]
XL = [[c-XR[i][0], XR[i][1]] for i in range(n)]
XL.sort()

CR = []
cal = 0
for i in range(n):
    dis = XR[i][0]
    cal += XR[i][1]
    CR.append([cal-dis, dis])


CSR = [CR[0][0]]
for i in range(n-1):
    CSR.append(max(CSR[i], CR[i+1][0]))

CL = []
cal = 0
for i in range(n):
    dis = XL[i][0]
    cal += XL[i][1]
    CL.append([cal-dis, dis])


CSL = [CL[0][0]]
for i in range(n-1):
    CSL.append(max(CSL[i], CL[i+1][0]))


# print(CSR)
# print(CSL)
# print(CR)
# print(CL)

ans = max(max(CSR), max(CSL))
for i in range(n-1):
    # print(CL[i][0]-CL[i][1]+CSR[n-2-i], CL[i][0],CL[i][1],CSR[n-2-i])
    ans = max(ans, CL[i][0]-CL[i][1]+CSR[n-2-i])
    ans = max(ans, CR[i][0]-CR[i][1]+CSL[n-2-i])

print(max(ans, 0))
D = int(input())

if D ==25:
  print("Christmas")
elif D ==24:
  print("Christmas Eve")
elif D ==23:
  print("Christmas Eve Eve")
else D ==22:
  print("Christmas Eve Eve Eve")

### FIXED CODE ###

D = int(input())

if D == 25:
  print("Christmas")
elif D == 24:
  print("Christmas Eve")
elif D == 23:
  print("Christmas Eve Eve")
else:
  print("Christmas Eve Eve Eve")
H, W = map(int, input().split())
s_list = []
for i in range(H):
    s = list(input())
    s_list.append(s)

dp = [[0 for _ in range(W)] for _ in range(H)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i in range(H):
    for j in range(W):
        if s_list[i][j] == "#":
            continue
        if i + 1 < H and s_list[i + 1][j] == ".":
            dp[i + 1][j] += dp[i][j] % mod
        if j + 1 < W and s_list[i][j + 1] == ".":
            dp[i][j + 1] += dp[i][j] % mod
print(dp[H - 1][W - 1] % mod)


### FIXED CODE ###

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

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
for i in range(2, N + 1):
    if i == 2:
        dp[2] = abs(h_list[1] - h_list[0])
    else:
        dp[i] = min(dp[i - 1] + abs(h_list[i-1] - h_list[i - 2]), dp[i - 2] + abs(h_list[i-1] - h_list[i - 3]))
print(dp[N])
a,b=int(input().split())
x=a*b
if x%2==0:
    print("Even")
else :
    print("Odd")

### FIXED CODE ###

a,b=map(int, input().split())
x=a*b
if x%2==0:
    print("Even")
else :
    print("Odd")
def ope(i, ans, ans_str):
    if i == 3:
        if ans == 7:
            print(ans_str)
    else:
        ope(i+1, ans+int(S[i+1]), ans_str + "+" + S[i+1])
        ope(i+1, ans-int(S[i+1]), ans_str + "-" + S[i+1])
S = list(input())
ope(0,int(S[0]),S[0])+"=7"


### FIXED CODE ###

S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
def ope(x,y,n,s):
    if n % 2 == 0:
        return x+y, str(s) + '+' + str(y)
    else:
        return x-y, str(s) + '-' + str(y)
for i in range(8):
    X1, S1 = ope(A,B,i,A)
    j = int(i/2)
    X2, S2 = ope(X1,C,j,S1)
    k = int(j/2)
    X3, S3 = ope(X2,D,k,S2)
    if X3 == 7:
        print(S3 + '=7')
        break
n=int(input())
s=input()
ans=0
for i in range(n):
  keep=s[-1]
  s=input()
  if keep != s[0]:
    ans=1
  else:
    continue
print(["Yes","No"][ans])
    
  

### FIXED CODE ###

n=int(input())
check=[]
s=input()
check.append(s)
ans=0
for i in range(n-1):
  keep=s[-1]
  s=input()
  if keep != s[0]:
    ans=1
  if str(s) in check:
    ans = 1
  else:
    check.append(s)
print(["Yes","No"][ans])
n = int(input())
s1 = input()
s2 = input()
mod = 10**9+7
dp = [-1] * (n)
if s1[0] == s2[0]:
    dp[0] = 1 
else:
    dp[0] = 2
for i in range(n-1):
    if dp[i] == -1:
        continue
    if s1[i] == s2[i]:
        dp[i+1] = (dp[i] * 2) % mod
        continue
    if i+2 > n:
        continue
    if s1[i+2] == s2[i+2]:
        dp[i+2] = dp[i]
    else:
        dp[i+2] = (dp[i] * 3) % mod

ans = dp[-1] if dp[-1] != -1 else dp[-2]
print((ans * 3) % mod)
# print(dp)

### FIXED CODE ###

n = int(input())
s1 = input()
s2 = input()
mod = 10**9+7
dp = [-1] * (n)
if s1[0] == s2[0]:
    dp[0] = 1 
else:
    dp[0] = 2
for i in range(n-1):
    if dp[i] == -1:
        continue
    if s1[i] == s2[i]:
        dp[i+1] = (dp[i] * 2) % mod
        continue
    if i+2 >= n:
        break
    if s1[i+2] == s2[i+2]:
        dp[i+2] = dp[i]
    else:
        dp[i+2] = (dp[i] * 3) % mod

ans = dp[-1] if dp[-1] != -1 else dp[-2]
print((ans * 3) % mod)
# print(dp)
s = list(input())
t = list(input())
ans = ["UNRESTORABLE"]
for i in range(len(s)):
    if s[i] != "?":
        for j in reversed(range(len(t))):
            if t[j] == s[i]:
                f = True
                for k in range(len(t)):
                    if not 0 <= i - j + k < len(t):
                        break
                    f %= (s[i - j + k] == "?" or s[i - j + k] == t[k])
                if f:
                    ans = s.copy()
                    for l in range(len(t)):
                        ans[i - j + l] = t[l]


print("".join(ans).replace("?", "a"))


### FIXED CODE ###

s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
ans = ["UNRESTORABLE"]

if "?" not in set(s):
    print("".join(s))
    exit()

for i in range(ls-lt+1):
    f = True
    for j in range(lt):
        f &= (s[i + j] == "?" or s[i + j] == t[j])

    if f:
        ans = s.copy()
        for j in range(lt):
            ans[i+j] = t[j]


print("".join(ans).replace("?", "a"))
# -*- coding: utf-8 -*-
n = int(input())
nt = []
for i in range(n):
  tmp = input().split()
  for j in range(n-1):
    tmp[j] = int(tmp[j])
  nt.append(tmp)

day = 0
j = []
for i in range(n):
  j.append(0)
  
while(True):
  #print(j)
  tmp = []
  for i in range(n):
    if j[i] < n-1 and nt[nt[i][j[i]]-1][j[nt[i][ j[i] ]-1]] == i+1:
      tmp.append(i)
  #print(tmp)
  if len(tmp) == 0:
    break
  for i in tmp:
    j[i] += 1
  day += 1
  
error = 0
for i in range(n):
  if j[i] != n-1:
    day = -1

print(day)

### FIXED CODE ###

# -*- coding: utf-8 -*-
y = input()
t = input()
ylist = list(y)
tlist = list(t)
seikai = 0
for i in range(3):
  if ylist[i] == tlist[i]:
    seikai += 1
    
print(seikai)
N = raw_input()
N = int(N)

a = []
for i in range(N):
	s_input = raw_input()
	s_input = int(s_input)
	if s_input in a:
		a.remove(s_input)
	else:
		a.append(s_input)
	a.sort()

print(len(a))

### FIXED CODE ###

N = raw_input()
N = int(N)

num10 = N/10
num1 = N - num10*10

if num10 == 9 or num1 == 9:
	print('Yes')
else:
	print('No')
h, n = map(int, input().split())
a = input().split()
b = 0
for i in range(n):
    b += int(a[i])
if (h < b and has_duplicates(a)):
    print("No")
else:
    print("Yes")


### FIXED CODE ###

h, n = map(int, input().split())
a = input().split()
b = 0
def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(n):
    b += int(a[i])
if (h > b ):
    print("No")
else:
    print("Yes")
S = input()
S1 = S[:1]
S2 = S[2:]
month = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']

if S1 in month and S2 in month:
	print('AMBIGUOUS')
elif S1 in month:
	print('MMYY')
elif S2 in month:
	print('YYMM')
elif S1 == '00': 
	print('YYMM')
elif: S2 == '00':
	print('MMYY')
else:
	print('NA')

### FIXED CODE ###

S = input()
S1 = int(S[:2])
S2 = int(S[2:])

if (1 <= S1 <= 12) and (1 <= S2 <= 12):
	print('AMBIGUOUS')
elif (1 <= S1 <= 12):
	print('MMYY')
elif (1 <= S2 <= 12):
	print('YYMM')
else:
	print('NA')
a = [input() for i in range(3)]
print(a[0]-a[1]-a[2])


### FIXED CODE ###

a = [int(input()) for i in range(3)]
print((a[0]-a[1])%a[2])
import sys
sys.setrecursionlimit(10**6)

n, m = [int(item) for item in input().split()]
edge = [[] for _ in range(n+1)]
INF =  2000 * 10**10
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    edge[a-1].append([b-1,c])
edge[n-1].append([n, 0])

def dfs(prev, prev_c, v):
    if v == n:
        return 0
    max_cost = -INF
    for e in edge[v]:
        if e[0] == prev:
            if prev_c + e[1] > 0:
                max_cost = INF
            continue
        max_cost = max(max_cost, e[1] + dfs(v, e[1], e[0]))
    return max_cost

cost = dfs(-1, 0, 0)
if cost > INF // 2:
    print("inf")
else:
    print(cost)

### FIXED CODE ###

n, m = [int(item) for item in input().split()]
edge = []
inf =  2000 * 10**10
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    edge.append([a-1, b-1, -c])

def BellmanFord(start):
    dist = [inf for i in range(n)]
    dist[0] = 0
    for i in range(n):
        for u, v, c in edge:
            if dist[u] != inf and (dist[u] + c) < dist[v]:
                dist[v] = dist[u] + c
                if i == n-1 and v == n-1:
                    return "inf"
    return -dist[-1]

ret = BellmanFord(0)
print(ret)
N=int(input())
X=0
for i in range(N):
  l,n=map(int,input().split())
  x+=l-n+1
print(X)

### FIXED CODE ###

N=int(input())
X=0
for i in range(N):
  l,n=map(int,input().split())
  X+=n-l+1
print(X)
print((N*(N+1)/2)-((N//3)*((N//3)+1)/2)-((N//5)*((N//5)+1)/2)+((N//15)*((N//15)+1)/2))


### FIXED CODE ###

N=int(input())
print(((N*(N+1))-(N//3*(N//3+1)*3)-(N//5*(N//5+1)*5)+(N//15*(N//15+1)*15))//2)
N=int(input())
K=input()
dic = {}
for t in ts:
    p=[]
    for ir, r in enumerate(K):
        if r == t:
            p.append(ir)
    dic[t] = p
ans1 = len(dic['R']) * len(dic['G']) * len(dic['B'])

ans2 = 0

for i in range(N):
    for j in range(i):
        if (i + 2*(j-i) < N):
            if  K[i] != K[j] and K[i] != K[i + 2*(j-i)] and K[i+2*(j-i)] != K[j]:
                ans2 +=1

print(ans1 - ans2)


### FIXED CODE ###

N=int(input())
K=input()
dic = {}
ts = 'RGB'
for t in ts:
    p=[]
    for ir, r in enumerate(K):
        if r == t:
            p.append(ir)
    dic[t] = p
ans1 = len(dic['R']) * len(dic['G']) * len(dic['B'])

ans2 = 0

for i in range(N):
    for j in range(i, N):
        if (i + 2*(j-i) < N):
            if  K[i] != K[j] and K[i] != K[i + 2*(j-i)] and K[i+2*(j-i)] != K[j]:
                ans2 +=1

print(ans1 - ans2)
a=int(input("a:"))
b=int(input("b:"))

print(a*b)
print(a*2+b*2)



### FIXED CODE ###


a,b=map(int,input().split())

r=a*b
length=a*2+b*2
print(r,length)
H,W = map(int,input().split())
if((H*W)%2 == 0):
  print(str(H*W)/2)
else:
  print(str(H*W)//2+1)

### FIXED CODE ###

H,W = map(int,input().split())
if(H == 1 or W == 1):
  print("1")
elif((H*W)%2 == 0):
  print(str((H*W)//2))
else:
  print(str((H*W)//2+1))
N, K = map(int, input().split())
S = input()

S[K-1]=S[K-1].lower()
print(S)

### FIXED CODE ###

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

se = ''
for i in range(N):
    if i == K-1:
        se += S[K-1].lower()
    else:
        se += S[i]
print(se)
a = r*r*3
print(a)

### FIXED CODE ###

n=int(input()) 
a = n*n*3
print(a)
N = int(input())
A = list(map(int,input().split()))
M = 1
while M <= N :
    print(A.count(M))
    M = M+1


### FIXED CODE ###

R = int(input())

print(R*6.283)
import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n,q = m()

data = [l() for i in range(q)]

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

for a,b,c in data:
    edges[a-1].append([b-1,c])
    edges[b-1].append([a-1,-c])

num = [0 for _ in range(n)]

Ma,mi = 0,0

vi = [False for i in range(n)]
ans = 0

for i in range(n):
    if vi[i]:
        continue
    stack = [i]
    vi[i] = True
    while stack:
        v = stack.pop()
        for e,r in edges[v]:
            if not vi[e]:
                num[e] = num[v] + d
                stack.append(e)
                vi[e] = True

for i in range(n):
    if num[i] < mi:
        mi = num[i]
    elif num[i] > Ma:
        Ma = num[i]
    for e,r in edges[i]:
        if num[i] + d != num[e]:
            ans = -1
            break
    else:
        continue
    break
else:
    print("No")
    exit()
print("Yes")







### FIXED CODE ###

import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n,q = m()

data = [l() for i in range(q)]

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

for a,b,c in data:
    edges[a-1].append([b-1,c])
    edges[b-1].append([a-1,-c])

num = [0 for _ in range(n)]

Ma,mi = 0,0

vi = [False for i in range(n)]
ans = 0

for i in range(n):
    if vi[i]:
        continue
    stack = [i]
    vi[i] = True
    while stack:
        v = stack.pop()
        for e,r in edges[v]:
            if not vi[e]:
                num[e] = num[v] + r
                stack.append(e)
                vi[e] = True

for i in range(n):
    if num[i] < mi:
        mi = num[i]
    elif num[i] > Ma:
        Ma = num[i]
    for e,r in edges[i]:
        if num[i] + r != num[e]:
            ans = -1
            break
    else:
        continue
    break
else:
    print("Yes")
    exit()
print("No")
N = int(input())
H = list(map(int, input().split()))
for i in range(N-1,0,-1):
    if H[i]>H[i-1]:
        if H[i]>(H[i-1]-1):
            print("No")
            exit()
print("Yes")


### FIXED CODE ###

A, B, C = map(int, input().split())
print(C-A+B if C-A+B>0 else 0)
s = input()[::-1]
words = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']]

can = 'YES'
while s:
    print(s)
    match_any = False
    for w in words:
        if s.startswith(w):
            s = s.replace(w, '', 1)
            match_any = True
            break
    if not match_any:
        can = 'NO'
        break
print(can)


### FIXED CODE ###

s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
    print("NO")
else:
    print("YES")
cnt = 1
output = []
while True:
	data += input().split()
	if data[0] == 0 && data[1] == 0:
		break
	output += [str(data[1]) + ' ' + str(data[0])]

for line in output:
	print(line)


### FIXED CODE ###

cnt = 1
output = []
while True:
	data = input().split()
	if data[0] == '0' and data[1] == '0':
		break
	elif int(data[0]) > int(data[1]):
		output += [data[1] + " " + data[0]]
	else:
		output += [data[0] + " " + data[1]]
for line in output:
	print(line)
import numpy as np

N = input()
A = np.fromiter(map(int, input().split()), dtype=np.int64)
print(np.gcd.reduce(A))

### FIXED CODE ###

import numpy as np
from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


N = input()
A = list(map(int, input().split()))
print(reduce(gcd, A, A[0]))
while True:
    num = map(int, raw_input().split())
    if len(num) != 1:
        print max(num),min(num),sum(num),

### FIXED CODE ###

while True:
    l = map(int, raw_input().split())
    num = map(int, raw_input().split())
    print "%d %d %d" % (min(num),max(num),sum(num))
    break