Harryxun/stf_run huggingface dataset:
def popcnt3(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

N = int(input())
X = list(input())

for i in range(N):
    x = X.copy()
    cnt = 0
    x[i] = str(int(x[i])^1)
    n = int("".join(x), 2)

    while n>0:
        n = n%popcnt3(n)
        cnt += 1
    print(cnt)

### FIXED CODE ###

#2回目以降のあまりを計算
def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

N = int(input())
S = input()

#入力を数値に変換
X = int(S, 2)

#元のbit数をカウント
pcx = S.count("1")
#bit数は-1, +1のみなので予め計算しておく
#カウントが0ならば0にしておく
pc1 = X % (pcx - 1) if pcx > 1 else 0
pc2 = X % (pcx + 1)

for i, y in enumerate(S):
    k = N - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)
(m, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(m):
    A.append([int(j) for j in input().split()])

for i in range(m):
    b.apped(int(input()))

c = []
for i in range(n):
    s = 0
    for j in range(m):
        m += A[n][m] * b[m]
    print(m)

### FIXED CODE ###

(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
    A.append([int(j) for j in input().split()])
  
for r in range(m):
    b.append(int(input()))
  
for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(s)
N = int(input())

maxi = -1
sc = 0

for i in range(N):
	A, B = map(int, input().split())
	if A > mini:
		mini = A
		sc = B
print(mini + sc)


### FIXED CODE ###

N = int(input())

maxi = -1
sc = 0

for i in range(N):
	A, B = map(int, input().split())
	if A > maxi:
		maxi = A
		sc = B
print(maxi + sc)
import math
n,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x.sort()
a=[]
for i in range(len(x)-1):
    a.append(x[i+1]-x[i])
a.sort()
ans=a[0]
for j in range(1,len(a)):
    if a[j]>0:
        ans=math.gcd(ans,a[j])
    else:
        ans=ans
print(ans)

### FIXED CODE ###

n,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
a=[]
for i in range(len(x)-1):
        a.append(x[i+1]-x[i])        

def gcd(m,n):
        while n:
                m,n = n,m%n
        return m

ans=a[0]
for j in a:
        if j%ans != 0:
                ans = gcd(j,ans)
print(ans)
N=input()
a
if N[0] =='S':
  a='Cloudy'
elif N[0] =='C':
  a='Rainy'
else:
  a='Sunny'

ptint(a)
  


### FIXED CODE ###

N=input()
a=''
if N[0] =='S':
  a='Cloudy'
elif N[0] =='C':
  a='Rainy'
else:
  a='Sunny'

print(a)
inf =  210000
def main():
  N =  int(input())
  a = list(map(int, input().split()))
  a.sort()
  detect = [0] *inf
  for i in range(N):
    detect[a[i]] += 1
    j = 2
    while (a[i]*j < inf):
      if detect[a[i]*j] >= 2:
        break
      else:
        detect[a[i]*j] += 2
        j+=1
  ans = 0
  for i in range(N):
    if detect[a[i]]<2:
      ans += 1
  print(ans)
  
if __name__ == "__main__":
  main()
    

### FIXED CODE ###

inf =  1100000
def main():
  N =  int(input())
  a = list(map(int, input().split()))
  a.sort()
  detect = [0] *inf
  for x in a:
    if detect[x] != 0:
      detect[x] = 2
      continue
    for i in range(x, inf, x):
      detect[i] += 1
  ans = 0
  for i in range(N):
    if detect[a[i]] == 1:
      ans += 1
  print(ans)
  
if __name__ == "__main__":
  main()
n=input()           #  str 575
n_int = int(n)    #  int 575

if n_int<357:
    print(0)
else:
    counter__ = 0
    for k in range(3 ,len(n)+1):
        counter__ += recursive_f([])

        def recursive_f(A):
            if len(A) == k:     # Aはリスト[7,7,7]
                A_ = int("".join(map(str,A)))    # A_はint 777
                counter = 0
                # print(A_)
                if len(set(A)) == 3 and A_ <= n_int:
                    counter += 1
                return counter

            counter_ = 0

            for i in [3,5,7]:
                A.append(i)
                counter_ += recursive_f(A)
                A.pop()

            return counter_
        
print(counter__)

### FIXED CODE ###

N = input()

def dfs(A):
    if int(A) > int(N):
        return 0
    if all(A.count(c) for c in "753") >0:
        ans = 1
    else:
        ans = 0
        
    for i in "357":
        A += i
        ans += dfs(A)
        A = A[:-1]
        
    return ans

print(dfs("0"))
A,B,C=input().split()
if A[-1]=B[0] and B[-1]=C[0]:
    print("Yes")
else:
    print("No")
    

### FIXED CODE ###

A,B,C=input().split()
if A[-1]==B[0] and B[-1]==C[0]:
    print("YES")
else:
    print("NO")
n=input()
if(n%2==0):
  print(n/2)
else:
  print((n/2)+1)

### FIXED CODE ###

N = int(input())

if N % 2 == 0:
    print(N//2)
else:
    print(N//2+1)
K, N = map(int, input().split())
A = [int(e) for e in input().split()]

ans = 0
for i in range(N - 1):
    S = [A[i + 1] - A[i]]
    S.append((K - A[N - 1]) + A[0])
    m = sorted(S)
    for n in range(N - 1):
        ans += m[n]
print(ans)


### FIXED CODE ###

K, N = map(int, input().split())
A = [int(e) for e in input().split()]

ans = 0
S = [(A[i + 1] - A[i]) for i in range(N - 1)]
S.append((K - A[N - 1]) + A[0])
S.sort
m = sorted(S)
for n in range(N - 1):
    ans += m[n]
print(ans)
N = int(input())
dic = {}
dic2 = {}
A = list(map(int, input().split()))
k = []
ANS = []
for i in range(1, N+1):
  k.append(i)

dic = dict(zip(k, A))
dic2 = dict(sorted(dic.items(), key=lambda x:x[1]))

for key in dic2:
  ANS.append(key)

for b in range(N):
  print(ANS[b], end=" \n"[b + 1 == N

### FIXED CODE ###

N = int(input())
d = []

A = list(map(int, input().split()))
k = []
ANS = []
for i in range(1, N+1):
  k.append(i)

d = list(zip(k, A))
d.sort(key=lambda x:x[1])

for b in range(N):
  print(d[b][0], end=" \n"[b + 1 == N])
n = int(input())
h = list(map(int, input().split()))
cnt = []
cur_cnt = 0
for x in range(n-1):
    if h[x] >= h[x + 1]:
        cur_cnt += 1
    else:
        cnt.append(cur_cnt)
        cur_cnt = 0
cnt.append(cur_cnt)

print(max(count))


### FIXED CODE ###

n = int(input())
h = list(map(int,input().split()))
cnt = 0
ans = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        cnt += 1
        ans = max(ans,cnt)
    else:
        cnt = 0
print(ans)
n=int(input())
a=list(input().split())
ans=1
f=0
i=0
p=0
while(i<n):
    if f==0:
        if i==n-1:
            p=1
            ans=ans*int(a[i])
        else:
            ans=ans*int(a[i])*int(a[i+1])
    if f==0 and ans>1000000000000000000:
        f=1
    if int(a[i])==0:
        print(0)
        exit()
    if p==0:
        if int(a[i+1])==0:
            print(0)
            exit()
    i+=2
if f==1:
    print(-1)
    exit()
print(ans)

### FIXED CODE ###

n=int(input())
a=list(input().split())
ans=1
f=0
i=0
while(i<n):
    if f==0:
        ans=ans*int(a[i])
    if f==0 and ans>1000000000000000000:
        f=1
    if int(a[i])==0:
        print(0)
        exit()
    i+=1
if f==1:
    print(-1)
    exit()
print(ans)
def prime(p):
    memo = [p]
    for i in range(2,(int(p**0.5)+1)):
        if p%i == 0:
            memo.append(i)
            memo.append(p//i)
    return memo

x = int(input())

memo = prime(x)

ans = 0

for i in memo:
    if x%(i-1)==x//(i-1):
        ans += i-1
print(ans)

### FIXED CODE ###

n=int(input())

ans = 0

for i in range(1,int(n**0.5)+2):
    if n%i == 0 and n//i>=i+2:
        ans += (n//i)-1
print(ans)
for i in range(3000):
    a, b = map(int, input().split())
    
    if a > b:
        print(a, b)
    else
        print(b, a)
    
    
    


### FIXED CODE ###

for i in range(3000):
    a, b = map(int, input().split())
    
    if a == b == 0:
        break
    elif a < b:
        print(a, b)
    else:
        print(b, a)
N = int(input())
print(int(N*(N-1)//2)

### FIXED CODE ###

N = int(input())
print(N*(N-1)//2)
def cos_per_find(count, cost, skills):
    if count == N:
        if min(skills) >= X:
            return cost
        else:
            return INF
    improved_skills = [a+b for a, b in zip(skills, contents[count])]
    return min(cos_per_find(count+1, cost, skills), cos_per_find(count+1, cost+price[count], improved_skills))

INF = float(inf)
N, M, X = map(int, input().split())
price = []
contents = []
for i in range(N):
    C, *A = map(int, input().split())
    price.append(C)
    contents.append(A)
if ans(:=cos_per_find(0, 0, [0]*M))== INF:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

def cos_per_find(count, cost, skills):
    if count == N:
        if min(skills) >= X:
            return cost
        else:
            return INF
    improved_skills = [a+b for a, b in zip(skills, contents[count])]
    return min(cos_per_find(count+1, cost, skills), cos_per_find(count+1, cost+price[count], improved_skills))

INF = float('inf')
N, M, X = map(int, input().split())
price = []
contents = []
for i in range(N):
    C, *A = map(int, input().split())
    price.append(C)
    contents.append(A)
if (ans := cos_per_find(0, 0, [0]*M)) == INF:
    print(-1)
else:
    print(ans)
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(map(int, input().split())) for _ in range(m)]
a.sort()
bc.sort(reverse=True, key=lambda x: x[1])

idx = 0
for e in bc:
    b, c = e
    for i in range(b):
        if a[i + idx] < c:
            a[i + idx] = c
        else:
            break
    else:
        idx += b
        continue
    break

print(sum(a))


### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(map(int, input().split())) for _ in range(m)]
a.sort()
bc.sort(reverse=True, key=lambda x: x[1])
last_idx = len(a) - 1
idx = 0
for e in bc:
    b, c = e
    for i in range(b):
        if i + idx > last_idx:
            break
        if a[i + idx] < c:
            a[i + idx] = c
    idx += b

print(sum(a))
a,b = map(int, input().sprit())
if a > b:
    print("a > b")
elif a < b:
    print("a < b")
else:
    print("a == b")



### FIXED CODE ###

a, b = map(int, input().split())
if a > b:
    print("a > b")
elif a < b:
    print("a < b")
else:
    print("a == b")
while True:
    [a,b,c]=[x for x in input().split()]
    [a,c]=[int(a),int(c)]
    op=b
    if a==0 and c==0:
        break
    elif op=="+":
        print(a+c)
    elif op=="-":
        print(a-c)
    elif op=="*":
        print(a*c)
    else:
        print(a//c)

### FIXED CODE ###

while True:
    [a,b,c]=[x for x in input().split()]
    [a,c]=[int(a),int(c)]
    op=b
    if op=="?":
        break
    elif op=="+":
        print(a+c)
    elif op=="-":
        print(a-c)
    elif op=="*":
        print(a*c)
    else:
        print(a//c)
H, A = map(int, input.split())
print((H+A-1)//A)

### FIXED CODE ###

H, A = map(int, input().split())
print((H+A-1)//A)
N = int(input())
total = 0.0
for i in range(N):
    money, tani = map(input().split())
    money = float(input())
    if tani = "JPY":
        total += money
    else:
        total += money * 380000.0
print("%.11f"%(total))

### FIXED CODE ###

year, month, day = map(int, input().split("/"))
if year <= 2019 and month <= 4 and day <= 30:
    print("Heisei")
else:
    print("TBD")
S=list(input())
yes_flag=0

for i in range(len(S)):
  #print(S)
  if S[0:5] == list("erase"):
    del S[0:5]
    if S[0] == "r":
      del S[0]
    if len(S) == 0:
      yes_flag=1
      break
  if S[0:5] == list("dream"):
    del S[0:5]
    if S[0:2] == list("er"):
      if not len(S) == 2:
      	if not S[2] == "a":
          del S[:2]
      else :
        del S[:2]
    if len(S) == 0:
      yes_flag=1
      break

if yes_flag == 1:
  print("YES")
else :
  print("NO")

### FIXED CODE ###

import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "NO")
from collections import Counter

N = int(input())

arr = [input() for i in range(0,N)]

odd = arr[0::2]
even = arr[1::2]

odd_counter = Counter(odd)
even_counter = Counter(even)

odd_mode = odd_counter.most_common()[0][0]
even_mode = even_counter.most_common()[0][0]

odd_diff = (N / 2) - odd_counter.most_common()[0][1]
even_diff = (N / 2) - even_counter.most_common()[0][1]

if odd_mode != even_mode:
	print(odd_diff + even_diff)
else:
 	odd_diff2 = (N / 2) - odd_counter.most_common()[1][1]
	even_diff2 = (N / 2) - even_counter.most_common()[1][1]
    if odd_diff2 > even_diff2:
		print(odd_diff + even_diff2)
    else:
		print(odd_diff2 + even_diff)


### FIXED CODE ###

from collections import Counter

N = int(input())

arr = list(map(int, input().split(' ')))

odd = arr[0::2]
even = arr[1::2]

odd_counter = Counter(odd)
even_counter = Counter(even)

odd_mode = odd_counter.most_common()[0][0]
even_mode = even_counter.most_common()[0][0]

odd_diff = (N / 2) - odd_counter.most_common()[0][1]
even_diff = (N / 2) - even_counter.most_common()[0][1]

if odd_mode != even_mode:
	print(int(odd_diff + even_diff))
elif odd_diff == 0:
	print(int(N / 2))
else:
	odd_diff2 = (N / 2) - odd_counter.most_common()[1][1]
	even_diff2 = (N / 2) - even_counter.most_common()[1][1]
	if odd_diff2 > even_diff2:
		print(int(odd_diff + even_diff2))
	else:
		print(int(odd_diff2 + even_diff))
from math import factorial
from collections import OrderedDict

def solve(n, S):
    total = 0
    l = {}
    for s in S:
        key = ''.join(sorted(s))
        l[key] = (l[key] + 1) if key in l else 1
    for v in l.values():
        if v > 1:
            total += int(factorial(v) / factorial(2) / factorial(v - 2))
    return total

_n = int(input())
_S = [input() for _ in range(_n)]
print(solve(_n, _S))

### FIXED CODE ###

from collections import defaultdict

def solve(n, S):
    counts = defaultdict(lambda: 0)
    for s in S:
        counts[''.join(sorted(list(s)))] +=  1
    total = 0
    for v in counts.values():
        if v > 1:
            total += int(v * (v - 1) / 2)
    return total

_n = int(input())
_S = [input() for _ in range(_n)]
print(solve(_n, _S))
import fractions
N,M = map(int,input().split())
S = input()
T = input()
L = (N * M) // fractions.gcd(N,M)
div_N = L // N
div_M = L // M
s = [""] * L

for ss in range(N):
  if ss == 0:
    s[0] = S[0]
    if s[0] != T[0]:
      print(-1)
      exit()
  else:
    s[ss * (div_N)] = S[ss]
#print(L)
#print(s)
#print(tag)
count = 1
while div_M < L and count < M:
  if s[div_M] != "" and s[div_M] != T[count]:
      print(-1)
      exit()
  div_M += div_M
  count += 1
print(L)




### FIXED CODE ###

import fractions
N,M = map(int,input().split())
S = input()
T = input()
G = fractions.gcd(N,M)
L = (N * M) // G
div_N = N // G
div_M = M // G

i = 0
j = 0

while i < N and j < M:
  if S[i] != T[j]:
    print(-1)
    exit()
  else:
    i += div_N
    j += div_M
print(L)
= list(map(int, input().split()))
b = int(a.index(0))
print(b+1)

### FIXED CODE ###

a = list(map(int, input().split()))
print(int(a.index(0))+1)
n, a, b = map(int, input().split())
ans = 0
for i in range(n):
  v = int(input())
  if i:
    ans += min(a * (v - last), b);
  last = v
print(ans)

### FIXED CODE ###

n, a, b = map(int, input().split())
ans = 0
v = list(map(int, input().split()))
for i in range(n):
  if i:
    ans += min(a * (v[i] - last), b);
  last = v[i]
print(ans)
import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
l=[0]*m
for i in range(m):
    l[i]=int(input())
#print(l)
dp=[0]*(n+1)
dp[0]=1
if l[0]!=1:
    dp[1]=1
for i in range(2,n+1):
    if i in l:
        dp[i]=0
    else:
        dp[i]=dp[i-1]+dp[i-2]
print(dp[-1]%1000000007)

### FIXED CODE ###

n,m=map(int,input().split())
a=[-1]
for i in range(m):
    s=int(input())
    a.append(s)  
a.append(n+1)
if 1 in a:
    a=a[1:]
if n-1 in a:
    a=a[:-1]
b=[]
for i in range(len(a)-1):
    b.append(a[i+1]-a[i]-2)
l=[1,1,2]
for i in range(3,n+1):
    l.append(l[i-2]+l[i-1])
ans=1
#print(a,b,l)
for i in range(len(b)):
    if b[i]<0:
        print(0)
        break
    else:
        ans*=l[b[i]]%1000000007
else:
    print(ans%1000000007)
from math import sqrt
from scipy.special import comb

def cal_factors(num):
    factors = {}
    maxmod = int(sqrt(num)) + 1
    for mod in range(2, maxmod):
        i = 0
        while True:
            d, q = divmod(num, mod)
            if q == 0:
                num = d
                i += 1
                factors[mod] = i
            else:
                break

    if num > 1:
        factors[num] = 1

    return factors


n, m = [int(v) for v in input().split()]

mod = 1000000000 + 7
factors = cal_factors(m)
ans = 1
for v in factors.values():
    ans *= comb(v + n - 1, v, exact=True) % mod
    ans %= mod

print(ans)

### FIXED CODE ###

from math import sqrt

def cal_factors(num):
    factors = {}
    i = 0
    while True:
        d, q = divmod(num, 2)
        if q == 0:
            num = d
            i += 1
            factors[2] = i
        else:
            break

    maxmod = int(sqrt(num)) + 1
    for mod in range(3, maxmod, 2):
        i = 0
        while True:
            d, q = divmod(num, mod)
            if q == 0:
                num = d
                i += 1
                factors[mod] = i
            else:
                break

    if num > 1:
        factors[num] = 1

    return factors


def comb(n, r, mod):
    result = 1
    r = min(r, n-r)
    for i in range(n, n-r, -1):
        result *= i
    for i in range(2, r+1):
        result //= i
    result %= mod

    return result


n, m = [int(v) for v in input().split()]

mod = 1000000000 + 7
factors = cal_factors(m)
ans = 1
for v in factors.values():
    ans *= comb(v + n - 1, v, mod)
    ans %= mod

print(ans)
import numpy as np

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



caa = [np.array(list(map(int, input().split()))) for _ in range(n)]



ans = 1 << 31

for i in range(2**n):
    tmp = np.zeros(4)
    for j in range(n):
        if i % (2**j):
            tmp += caa[j]
        if min(tmp[1:]) >= x:
            ans = min(ans, tmp[0])

if ans != 1<<31:
    print(int(ans))
else:
    print(-1)

### FIXED CODE ###

*o, = open(0)

import numpy as np

(n, m, x), *ca = map(lambda x: np.array(list(map(int, x.split()))), o)

INF = 1 << 31

ans = INF

for i in range(2**n):
    tmp = np.zeros(m+1, int)
    sel = []
    for j, dig in enumerate(bin(i)[2:][::-1]):
        if int(dig):
            tmp += ca[j]
            sel.append(j)
    if min(tmp[1:]) >= x:
        ans = min(ans, tmp[0])
        

if ans == INF:
    print(-1)
else:
    print(ans)
import sys
import numpy as np
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, K = rl()
A = np.array([0] + rl())
A_cum = A.cumsum()
A_cum2 = A_cum - np.arange(N+1)
A_cum2 = A_cum2 % K
answer = 0
remain = [0] * (K)
cnt = 0
for i in range(N+1):
    x = A_cum2[i] % K    
    if i - K >= 0:
        y = A_cum2[i-K] % K
        remain[y] -= 1
    answer += remain[x]
    remain[x] += 1
print(answer)


### FIXED CODE ###

import sys
import numpy as np
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([1] + lr())
A = (A-1) % K
N += 1
Acum = (A.cumsum() % K).tolist()
d = defaultdict(int)
answer = 0
for i, x in enumerate(Acum):
    answer += d[x]
    d[x] += 1
    if i >= K-1:
        d[Acum[i-(K-1)]] -= 1

print(answer)
N = int(input())
C = {0:0,1:0,2:0}
cnt = 0
for _ in range(N):
    s = input().strip()
    if s[0]=="B" and s[-1]!="A":
        C[0] += 1
    elif s[0]!=B and s[-1]=="A":
        C[1] += 1
    elif s[0]=="B" and s[-1]=="A":
        C[2] += 1
    for i in range(len(s)-1):
        if s[i:i+2]=="AB":
            cnt += 1
if C[2]>0:
    cnt += C[2]-1
    if C[0]>0:
        cnt += 1
        C[0] -= 1
    if C[1]>0:
        cnt += 1
        C[1] -= 1
cnt += min(C[0],C[1])
print(cnt)

### FIXED CODE ###

N = int(input())
C = {0:0,1:0,2:0}
cnt = 0
for _ in range(N):
    s = input().strip()
    if s[0]=="B" and s[-1]!="A":
        C[0] += 1
    elif s[0]!="B" and s[-1]=="A":
        C[1] += 1
    elif s[0]=="B" and s[-1]=="A":
        C[2] += 1
    for i in range(len(s)-1):
        if s[i:i+2]=="AB":
            cnt += 1
if C[2]>0:
    cnt += C[2]-1
    if C[0]>0:
        cnt += 1
        C[0] -= 1
    if C[1]>0:
        cnt += 1
        C[1] -= 1
cnt += min(C[0],C[1])
print(cnt)
def main():
    """
    N,M:10^6より N^2->NG
    矛盾する情報を見つける
    距離情報の保持

    1-2:1, 2-3:1, 1-3:2 <-OK
    1-2:1, 2-3:1, 1-3:5 <-NG(over)
    1-2:1, 2-3:1, 1-3:1 <-NG(less)
    1-2:1, 2-4:3, 1-3:3 <-OK(2-3:2, 3-4:1)
    1-2:1, 2-4:3, 1-3:5 <-NG

    (Li,Ri,Di)
    人Ri は人Li よりも距離 Di だけ右にいる
    すなわち、xRi − xLi = Di
    Ri > Li のとき(人7の右に人8がいる)処理上問題なし
    Ri < Li のとき(人8の右に人7がいる)場合、
    xLi - xRi = -Di
    """
    N, M = map(int, input().split())
    lrd = [
        tuple(map(int, input().split()))
        for _ in range(M)
    ]

    editorial(N, M, lrd)


def editorial(N, M, lrd):
    import sys
    sys.setrecursionlimit(1e7)

    xs = [None] * N
    graph = [[] for _ in range(N)]
    for l, r, d in lrd:
        graph[l - 1].append((r - 1, d))
        graph[r - 1].append((l - 1, -d))

    def dfs(i):
        # 辺情報がなければ独立
        for j, d in graph[i]:
            if xs[j] is None:
                xs[j] = xs[i] + d
                f = dfs(j)
                if not f:
                    return False
            elif xs[j] - xs[i] != d:
                # 距離が誤情報
                return False

        return True

    for i, x in enumerate(xs):
        if x is None:
            # root以外は、dfsで木を探索するときに座標確定
            # １回で確定しないときは、独立した木が存在する
            # 他の木とは別で考えて良いので、初期座標は0固定で問題ない
            xs[i] = 0
            f = dfs(i)
            if not f:
                print("No")
                return

    print("Yes")

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    """
    N,M:10^6より N^2->NG
    矛盾する情報を見つける
    距離情報の保持

    1-2:1, 2-3:1, 1-3:2 <-OK
    1-2:1, 2-3:1, 1-3:5 <-NG(over)
    1-2:1, 2-3:1, 1-3:1 <-NG(less)
    1-2:1, 2-4:3, 1-3:3 <-OK(2-3:2, 3-4:1)
    1-2:1, 2-4:3, 1-3:5 <-NG

    (Li,Ri,Di)
    人Ri は人Li よりも距離 Di だけ右にいる
    すなわち、xRi − xLi = Di
    Ri > Li のとき(人7の右に人8がいる)処理上問題なし
    Ri < Li のとき(人8の右に人7がいる)場合、
    xLi - xRi = -Di
    """
    N, M = map(int, input().split())
    lrd = [
        tuple(map(int, input().split()))
        for _ in range(M)
    ]

    editorial(N, M, lrd)


def editorial(N, M, lrd):
    import sys
    sys.setrecursionlimit(10 ** 7)

    xs = [None] * N
    graph = [[] for _ in range(N)]
    for l, r, d in lrd:
        graph[l - 1].append((r - 1, d))
        graph[r - 1].append((l - 1, -d))

    def dfs(i):
        # 辺情報がなければ独立
        for j, d in graph[i]:
            if xs[j] is None:
                xs[j] = xs[i] + d
                f = dfs(j)
                if not f:
                    return False
            elif xs[j] - xs[i] != d:
                # 距離が誤情報
                return False

        return True

    for i, x in enumerate(xs):
        if x is None:
            # root以外は、dfsで木を探索するときに座標確定
            # １回で確定しないときは、独立した木が存在する
            # 他の木とは別で考えて良いので、初期座標は0固定で問題ない
            xs[i] = 0
            f = dfs(i)
            if not f:
                print("No")
                return

    print("Yes")

if __name__ == '__main__':
    main()