Harryxun/stf_run huggingface dataset:
import sys
n,m=map(int,input().split())
MOD = 10**9+7
ans=1
def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n, k):
    if k < 0 or k > n:
        return 0
    else:
        return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD
pf={}
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
if n==1:
  print(1)
  sys.exit()
Max=max(list(pf.values()))
f_mod=[1]*(Max+n+1)
f_mod_inverse=[1]*(Max+n+1)
for i in range(1,Max+n+1):
  f_mod[i]=(f_mod[i-1]*i)%MOD
  f_mod_inverse[i]=(f_mod_inverse[i-1]*inv_mod(i)) % MOD  
for i in pf.values():
  ans*=comb_mod(i+n-1,n-1)
print(ans%MOD)


### FIXED CODE ###

import sys
n,m=map(int,input().split())
MOD = 10**9+7
ans=1
if m==1:
  print(1)
  sys.exit()
def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n, k):
    if k < 0 or k > n:
        return 0
    else:
        return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD
pf={}
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
Max=max(list(pf.values()))
f_mod=[1]*(Max+n+1)
f_mod_inverse=[1]*(Max+n+1)
for i in range(1,Max+n+1):
  f_mod[i]=(f_mod[i-1]*i)%MOD
  f_mod_inverse[i]=(f_mod_inverse[i-1]*inv_mod(i)) % MOD  
for i in pf.values():
  ans*=comb_mod(i+n-1,n-1)
print(ans%MOD)
from sys import stdin


def main():
    N = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    a_ = {int(x) for x in stdin.readline().rstrip().split()}
    count = 0


    for i in range(N):
        
        if  a[i-1] ^ a[i] in a_ :
            # a_.discard(a[i-1] ^ a[i])
        else:
            count += 1

    if count == 0:
        print("Yes")
    else:
        print("No")    


if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin


def main():
    _ = int(input())
    a_lists = [int(x) for x in stdin.readline().rstrip().split()]
    z = 0

    for a in a_lists:
        z ^= a

    if z == 0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()
n,a,b=input().split()
cicle=int(n/(a+b))
res=n-cicle*(a+b)
if res>a:
  ans=cicle*a+a
else:
  ans=cicle*a+res
print(ans)

### FIXED CODE ###

n,a,b=(int(x) for x in input().split())
cycle=int(n/(a+b))
res=n-cycle*(a+b)
if res>a:
  ans=cycle*a+a
else:
  ans=cycle*a+res
print(ans)
n=int(input())
t=list(map(int,[input() for i in range(n)]))

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)

if n==1:
    print(t[0])
else:
    ans=lcm(t[0],t[1])
    for i in range(n-1):
        ans=lcm(ans,lcm(t[i],t[i+1]))
    print(ans)

### FIXED CODE ###

n=input()
m=n[::-1]
if n==m:
  print('Yes')
else:
  print('No')
H,W,M=map(int,input().split())
mine=[list(map(int,input().split()))for i in range(M)]
mine_h=[0]*H
mine_w=[0]*W
ans=0
for i in range(M):
    mine_h[mine[i][0]-1]+=1
max_h=max(mine_h)
for i in mine_h:
    tmp=0
    if i ==max_h:
        mine_w=[0]*W
        for j in range(M):
            if mine[j][0]-1!=i:
                mine_w[mine[j][0]-1]+=1
        tmp=max_h+max(mine_w)
        if tmp>ans:
            ans=tmp
print(ans)


### FIXED CODE ###

H,W,M=map(int,input().split())
mine_h=[0]*H
mine_w=[0]*W
val=-1
mine=set()
for i in range(M):
    a,b=map(int,input().split())
    mine_h[a-1]+=1
    mine_w[b-1]+=1
    mine.add((a,b))
max_h=max(mine_h)
max_w=max(mine_w)
h_index=[i+1 for i, x in enumerate(mine_h)if x == max_h]
w_index=[i+1 for i, x in enumerate(mine_w)if x == max_w]
for i in h_index:
    for j in w_index:
        if (i,j) in mine:
            continue
        else:
            val=0
            break
print(max_h+max_w+val)
import sys
A, B, C, X, Y = map(int,input().split())
 
minf = sys.maxsize
X1 = X
Y1 = Y
 
 
for i in range(0, max(X,Y)+1):
    price = max(0,(X1-i))*A+max(0,(Y1-i))*B+2*i*C
 
 
print(min(price))

### FIXED CODE ###

A, B, C, X, Y = map(int, input().split())

## min(Ax + By + Cz) = min((A+0.5C)x + (B+0.5C)y)
# Xyen = Ai + 2Cj, Yyen = Bk + 2Cj, X = i +2j, Y = k + 2j
# Xyen + Yyen = AX + BY + 2(C-A)j + 2(C-B)j, jを求めればok?

# l = []
# for j in range(max(X,Y)+1):
#     if j <= X+Y:
#         l.append(A*X + B*Y + (C-A*0.5-B*0.5)*j)

# print(int(min(l)))

X1 = X
Y1 = Y
price = []
for i in range(0, max(X,Y)+1):
    price.append(max(0,(X1-i))*A+max(0,(Y1-i))*B+2*i*C) 
print(min(price))
import math
x = int(input())
ans =x
while True:
  for i in range(2,math.sqrt(x)+1):
    if x%i=0:
      print(x)
      exit()
  x+=1
  


### FIXED CODE ###

import math
x = int(input())
ans =x

for j in range(x,2*x):
  flag=1
  for i in range(2,int(math.sqrt(x))+1):
    if x%i==0:
      flag=0
  if flag==1:
    print(x)
    exit(0)
  x+=1
n=int(input())
 
r=0
 
for i in range(1,n+1)
	if len(str(i))%2==1:
    	r+=1
print(r)

### FIXED CODE ###

n=int(input())
 
r=0
 
for i in range(1,n+1):
	if len(str(i))%2==1:
		r+=1
print(r)
N = int(input())
h = list(map(int, input().split()))

dp = [0]*N
for i in range(1,N):
    candidates = []
    for c in range(1, K+1):
        if i-c>=0:
            candidates.append(dp[i-c] + abs(h[i]-h[i-c]))
    dp[i] = min(candidates)
    #print(dp)
print(dp[-1])

### FIXED CODE ###

N,K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*N
for i in range(1,N):
    candidates = []
    for c in range(1, K+1):
        if i-c>=0:
            candidates.append(dp[i-c] + abs(h[i]-h[i-c]))
    dp[i] = min(candidates)
    #print(dp)
print(dp[-1])
Imp = raw_input().split()
A = Imp[0]
B = Imp[1]
re = 0
if A % 3 == 0:    
    re = 1
if B % 3 == 0:
    re = 1
if (A+B) % 3 == 0:
        re = 1
        
if re ==1:
    print("Possible")
else:
    print("Impossible")

### FIXED CODE ###

Imp = list(map(int, input().split()))
A = Imp[0]
B = Imp[1]
re = 0
if A % 3 == 0:    
    re = 1
if B % 3 == 0:
    re = 1
if (A+B) % 3 == 0:
        re = 1
        
if re ==1:
    print("Possible")
else:
    print("Impossible")
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N, K = map(int, input().split())
x = list(map(int, input().split()))
MAX = 10**9

has0 = 1 if 0 in x else 0
if has0 and K==1:
    print(0)
    exit()
if not(has0):
    x.append(0)
    x.sort()

# minusC = len([val for val in x if val<0])
# plusC = len([val for val in x if val>0])
ind0 = x.index(0)

res = MAX
for i, xi in enu(x):
    if i < ind0:
        min_flg = True
    elif i == ind0:
        continue
    else:
        min_flg = False
    rousoku_cnt = abs(i - ind0) + has0

    if K < abs(rousoku_cnt):
        continue
    elif K == abs(rousoku_cnt):
        res = min(res, abs(xi))
    else:
        if min_flg:
            val = abs(2*x[ind0+(K-rousoku_cnt)])
            res = min(res, abs(xi) + val)
        else:
            val = abs(2*x[ind0-(K-rousoku_cnt)])
            res = min(res, abs(xi) + val)
        # print(abs(xi) + val)
print(res)


### FIXED CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N, K = map(int, input().split())
X = list(map(int, input().split()))

has_zero = 0 in X
negs = [val for val in X if val<0]
poss = [val for val in X if val>0]
lenn = len(negs)
lenp = len(poss)
negs.append(0)
poss = [0] + poss

# print(negs)
# print(poss)

minval = 10**9
if has_zero: K-=1
for left in range(0, K+1):
    right = K-left
    if lenn<left or lenp<right: continue
    # print(left, right)
    negv = abs(negs[lenn-left])
    posv = abs(poss[right])
    val = max(negv, posv) + 2*min(negv, posv)
    if val < minval: minval = val
print(minval)
import collections
import sys
input = lambda: sys.stdin.readline().strip()

def main():
    N,M = map(int,input().split())
    H_list = list(map(int,input().split()))
    ab_list = [map(int,input().split()) for _ in range(M)]

    ab_dict = dict()
    for a,b in ab_list:
        minab = min(a,b)
        if str(minab) not in ab_dict.keys():
            ab_dict.update({min(a,b):[max(a,b)]})
        else:
            ab_dict[str(minab)] += max(a,b)
    c = collections.Counter(H_list)

    ans = 0
    for i in range(1,len(ab_dict)+1):
        if i < min(ab_dict.get(i)):
            ans += c[i]
    print(ans)

main()


### FIXED CODE ###

import collections
import sys
input = lambda: sys.stdin.readline().strip()

def main():
    N,M = map(int,input().split())
    H_list = list(map(int,input().split()))
    ab_list = [list(map(int,input().split())) for _ in range(M)]

    ab_dict = {i: [] for i in range(N)}
    for a,b in ab_list:
        a,b = a-1,b-1
        ab_dict[a].append(b)
        ab_dict[b].append(a)

    c = collections.Counter(H_list)

    # print(H_list)
    # print(ab_dict)
    ans = 0
    for k,v_list in ab_dict.items():
        for v in v_list:
            if H_list[v] >= H_list[k]:
                break
        else:ans += 1
    print(ans)

main()
N = input()
N = int(N)
name = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

S = 1
i = 0
Sum = 0
while Sum<N:
    S *= 26
    Sum += S
    i = i+1

ans = []
for j in range(i):
  N -= 1
    r = N%26
    ans.insert(0, name[r])
    N = N//26

ans = ''.join(ans)
print(ans)




### FIXED CODE ###

N = input()
N = int(N)
name = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

S = 1
i = 0
Sum = 0
while Sum<N:
    S *= 26
    Sum += S
    i = i+1


ans = []
for j in range(i):
    N -= 1
    r = N%26
    ans.insert(0, name[r])
    N = N//26

ans = ''.join(ans)
print(ans)
n=int(input())
b=0
for _ in range(n):
  b+=1/int(input())
print(1/b)

### FIXED CODE ###

n=int(input())
l = list(map(int,input().split()))
b = sum([1/x for x in l])
print(1/b)
N = int(input())
L = [int(input()) for i in range(N)]
print('Yes' if sum(L)-max(L) > max(L) and sum(L) -max(L) == max(L) + 1 else 'No')


### FIXED CODE ###

input()
L = list(map(int, input().split()))
print("Yes" if sum(L) > 2*max(L) else "No")
from functools import reduce
from math import gcd
 
N,X=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]

lis=[abs(j-X) for j in x]

print(reduce(gcd,lis))

### FIXED CODE ###

from fractions import gcd
from functools import reduce
 
N,X=map(int, input().split())
x=map(int, input().split())

lis=[abs(j-X) for j in x]

print(reduce(gcd,lis))
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
X = input()
def popcount(n):
    cnt = 0
    while n:
        n %= "{:b}".format(n).count("1")
        cnt += 1
    return cnt

pl = [0]*(N+1)
for i in range(N+1):
    pl[i] = popcount(i)
bn = X.count("1")

modp = [0]*N
modm = [0]*N

for i in range(N):
    if X[i] == "1":
        modp[i] = pow(2, N-1-i, bn+1)
        modm[i] = pow(2, N-1-i, bn-1)

sp = sum(modp)
sm = sum(modm)
ans = [0]*N
for i in range(N):
    if X[i] == "1":
        if bn == 1:
            ans[i] = 0
            continue
        s = sm
        s -= modm[i]
        s %= bn-1
        ans[i] = pl[s]+1
    else:
        s = sp
        s += pow(2, N-1-i, bn+1)
        s %= bn+1
        ans[i] = pl[s]+1

print(*ans, sep="\n")


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# import random
# N = random.randint(0, 2*100000)
# X = ""
# for i in range(N):
#     if random.random() < 0.5:
#         X += "0"
#     else:
#         X += "1"
# print(N, X)


N = INT()
X = input()

def popcount(n):
    cnt = 0
    while n:
        n %= "{:b}".format(n).count("1")
        cnt += 1
    return cnt

pl = [0]*(N+1)
for i in range(N+1):
    pl[i] = popcount(i)
bn = X.count("1")

modp = [0]*N
modm = [0]*N

for i in range(N):
    if X[i] == "1":
        modp[i] = pow(2, N-1-i, bn+1)
        if not bn == 1:
            modm[i] = pow(2, N-1-i, bn-1)

sp = sum(modp)
sm = sum(modm)
ans = [0]*N
for i in range(N):
    if X[i] == "1":
        if bn == 1:
            ans[i] = 0
            continue
        s = sm
        s -= modm[i]
        s %= bn-1
        ans[i] = pl[s]+1
    else:
        s = sp
        s += pow(2, N-1-i, bn+1)
        s %= bn+1
        ans[i] = pl[s]+1

print(*ans, sep="\n")
A,B =map(int, input())
if B % A == 0:
  print(A+B)
else:
  print(B-A)

### FIXED CODE ###

A,B =map(int, input().split())
if B % A == 0:
  print(A+B)
else:
  print(B-A)
H,W = map(int,input().split())
S_X=[]
S_Y=[]
C_X=[]
C_Y=[]
ans_list=[]
B = []

for i in range(H):
    A = list(input())
    for j in range(W):
        if A[j] == '#':
            S_X.append(i+1)
            S_Y.append(j+1)
        else :
            C_X.append(i+1)
            C_Y.append(j+1)

S_len=len(S_X)
C_len=len(C_X)


for i in range(C_len):
    for j in range(S_len):
        B.append((abs(S_X[j]-C_X[i])+abs(S_Y[j]-C_Y[i])))
    a = min(B)*(-1)
    ans_list.append(a)
    
    B = []

ans_list.sort()


print(ans_list[0]*(-1))

### FIXED CODE ###

import numpy as np

H,W=map(int,input().split())
max_value = H+W
matrix =[]

for _ in range(H):
    matrix.append([0 if i == '#' else max_value for i in list(input())])
matrix = np.array(matrix)

for c in range(W-1):
    matrix[:,c+1] = np.minimum(matrix[:,c]+1,matrix[:,c+1])
for c in range(W-1,0,-1):
    matrix[:,c-1] = np.minimum(matrix[:,c-1],matrix[:,c]+1)
for r in range(H-1):
    matrix[r+1,:] = np.minimum(matrix[r,:]+1,matrix[r+1,:])
for r in range(H-1,0,-1):
    matrix[r-1,:] = np.minimum(matrix[r,:]+1,matrix[r-1,:])


print(np.max(matrix))
H, W = map(int, input().split())
s = [list(input()) i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]

for h in range(H):
  for w in range(W):
    # Don't check white cell
    if s[h][w] == '.':
      continue
    # check neighbor cell
    for k in range(4):
      nh = h + dh[k]
      nw = w + dw[k]
      if nh < 0 or nw < 0 or H <= nh or W <= nw:
        continue
      # neighbor black is found => ok
      if s[nh][nw] == '#':
        break
    # There is independ black => failed
    else:
      print('No')
      break
  # ok
  else:
    continue
  # failed
  break
# ok
else:
  print('Yes')
    

### FIXED CODE ###

H, W = map(int, input().split())
s = [list(input()) for i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
cnt = 0

for h in range(H):
  for w in range(W):
    # Check only black cell
    if s[h][w] == '.':
      continue
    for k in range(4):
      nh = h + dh[k]
      nw = w + dw[k]
      if nh < 0 or nw < 0 or H <= nh or W <= nw:
        continue
      # ok
      if s[nh][nw] == '#':
        break
    # failed
    else:
      cnt += 1

if cnt == 0:
  print('Yes')
else:
  print('No')
N =int(input())
a =int(input())
count = 1
ans = 0
for i in a:
  if i == count:
    count += 1
    ans += 1
if ans == 0:
  print(-1)
else:
  print(min(N - 1, N - ans))

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
j = 1

for i in range(N):
  if j == a[i]:
    j += 1
if j == 1:
  print(-1)
else:
  print(N-j+1)
A,B,C,D = map( int,input().split() )
while A > 0 and c > 0:
    A -= D 
    if A <= 0 :
        print( 'No' )
        exit()
    B -= C
    if C <= 0 :
        print( 'Yes' )
        exit()

### FIXED CODE ###

A,B,C,D = map(int, input().split())

while A > 0 and C > 0:
    C -= B
    if C <= 0:
        print("Yes")
        exit()
    A -= D
    if A <= 0:
        print("No")
        exit()
s = input()
for i in s:
  if i == '1':
    c += i
print(c)    

### FIXED CODE ###

s = input()
c = 0
for i in s:
  if i == '1':
    c += 1
print(c)
a, b, k = map(int, input().split())
lst = list(range(a, b+1))
for i in sorted(set(lst[:k]) | set(lst[-k:])):
  print(i)

### FIXED CODE ###

a, b, k = map(int, input().split())
lst = range(a, b+1)
for i in sorted(set(lst[:k]) | set(lst[-k:])):
  print(i)
# D
N = int(input())
s = list(map(int, list(input())))

res = 0
i = 0



L = 0
for i in range(N):
    if s[i] == 1:
        L = i
        break
for i in range(N):
    if s[i] == 1:
        M = i        

        
def calc_add(temp_list):
    return sum(temp_list)
def calc_add_2(temp_list)
    if len(temp_list) <= 1:
        return 0
    else:
        res = 0
        # use 101 for left
        dp_l = [0]*len(temp_list)
        # use 101 for right 
        dp_r = [0]*len(temp_list)
        # do not use 101
        dp_c = [0]*len(temp_list)
        for i in range(len(temp_list) - 1):
            if temp_list[i] > 1:
                dp_l[i+1] = max(dp_l[i] + temp_list[i] - 1, dp_c[i] + temp_list[i])
            else:
                dp_l[i+1] = dp_c[i] + temp_list[i]
            if temp_list[i] > 1:
                dp_r[i+1] = max(dp_l[i] + temp_list[i+1], dp_c[i] + temp_list[i+1], dp_r[i] + temp_list[i+1] - 1)
            else:
                dp_r[i+1] = dp_c[i] + temp_list[i+1]
            dp_c[i+1] = max(dp_l[i], dp_r[i], dp_c[i])
        
        return max(dp_l[-1], dp_r[-1], dp_c[-1])
    

cont0 = 1
cont00 = 1
temp_list = []

for i in range(L, M+1):
    if s[i] == 1:
        if cont0 == 1:
            temp_list.append(1)
            cont0 = 0
            cont00 = 0
        else:
            temp_list[-1] += 1
    else:
        if cont00 == 1:
            pass
        elif cont0 == 1:
            cont00 = 1
            res += calc_add(temp_list)
            temp_list = []
        else:
            cont0 = 1
            
    if i == M:
        res += calc_add(temp_list)
        temp_list = []
        
print(res)

### FIXED CODE ###

# D
N = int(input())
s = list(map(int, list(input())))

        
def calc_add(temp_list):
    if len(temp_list) <= 1:
        return 0
    else:
        res = 0
        # use 101 for left
        dp_l = [0]*len(temp_list)
        # use 101 for right 
        dp_r = [0]*len(temp_list)
        # do not use 101
        dp_c = [0]*len(temp_list)
        for i in range(len(temp_list) - 1):
            if temp_list[i] > 1:
                dp_l[i+1] = max(dp_l[i] + temp_list[i] - 1, dp_c[i] + temp_list[i])
            else:
                dp_l[i+1] = dp_c[i] + temp_list[i]
            if temp_list[i] > 1:
                dp_r[i+1] = max(dp_l[i] + temp_list[i+1], dp_c[i] + temp_list[i+1], dp_r[i] + temp_list[i+1] - 1)
            else:
                dp_r[i+1] = dp_c[i] + temp_list[i+1]
            dp_c[i+1] = max(dp_l[i], dp_r[i], dp_c[i])
        
        return max(dp_l[-1], dp_r[-1], dp_c[-1])
    

cont0 = 1
cont00 = 1
temp_list = []
res = 0

for i in range(N):
    if s[i] == 1:
        if cont0 == 1:
            temp_list.append(1)
            cont0 = 0
            cont00 = 0
        else:
            temp_list[-1] += 1
    else:
        if cont00 == 1:
            pass
        elif cont0 == 1:
            cont00 = 1
            res += calc_add(temp_list)
            temp_list = []
        else:
            cont0 = 1
            
    if i == N - 1:
        res += calc_add(temp_list)
        
print(res)
x = {}
n, m = map(int, raw_input().split())
if m == 0:
    print 'Yes'
    exit()
l, r, d = map(int, raw_input().split())
x[l], x[r] = 0, d
flag = True
for _ in xrange(m - 1):
    l, r, d = map(int, raw_input().split())
    if r in x:
        if x[r] != x[l] + d:
            flag = False
    else:
        x[r] = x[l] + d
print 'Yes' if flag else 'No'


### FIXED CODE ###

from collections import deque
n, m = map(int, raw_input().split())
graph = {_: set() for _ in xrange(n + 1)}
in_deg, dist = [0] * (n + 1), [-1] * (n + 1)
for _ in xrange(m):
    l, r, d = map(int, raw_input().split())
    graph[l].add((r, d))
    in_deg[r] += 1
que = deque([i for i in xrange(n + 1) if not in_deg[i]])
cst = 1
while que:
    stp = que.popleft()  # start_point
    if in_deg[stp] < 0:
        in_deg[stp] = cst
    for v, d in graph[stp]:
        if dist[v] < 0:
            dist[v] = dist[stp] + d
        else:
            if dist[v] != dist[stp] + d:
                print 'No'
                exit()
        in_deg[v] -= 1
        if not in_deg[v]:
            que.append(v)
print 'No' if [_ for _ in in_deg[1:] if _ > 0] else 'Yes'