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

N = int(input())
C = list(input())

ans = float("inf")
for i in range(N+1):
  w = C[:i].count("W")
  r = C[i:].count("R")
  ans = min(ans, max(w,r))
  
print(ans)

### FIXED CODE ###

N = int(input())
C = list(input())

W = C.count("W")
R = C.count("R")
w = 0
r = R

ans = R
for i in range(1,N+1):
  if C[i-1] == "W":
    w += 1
  else:
    r -= 1
  ans = min(ans, max(w,r))
  
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))

ans = 0
sum = [0 for i in range(n+1)]

for i in range(1, n+1):
    sum[i] = sum[i-1] + a[i-1]

sum = sorted(sum)

for i in range(n):
    tmp = sum[i]
    for j in range(i, n+1):
        if i != j and tmp == sum[j]:
            ans += 1

print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))

ans = 0
sum = [0 for i in range(n+1)]

for i in range(1, n+1):
    sum[i] = sum[i-1] + a[i-1]

count = Counter(sum)

for values in count.values():
    if values >= 2:
        ans += values * (values-1) // 2

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

from bisect import bisect,insort
import itertools
q=int(input())
query=[list(map(int,input().split())) for i in range(q)]
inf=float("inf")
a_sum=0
b_sum=0
A=[]
count=0
for u in query:
    if u[0]==2:
        if count%2==1:
            print(A[num],a_sum+b_sum-A[num])
        else:
            print(A[num-1],a_sum+b_sum)
    else:
        count+=1
        a,b=u[1],u[2]
        b_sum+=b
        c=bisect(A,a)
        num=count//2
        if c>=num:
            if count%2==0:
                a_sum+=-2*A[num-1]+a
            else:
                a_sum+=a
            A=list(itertools.chain(A[:c],[a],A[c:]))
        else:
            if count%2==0:
                a_sum+=-a
            else:
                a_sum+=-a+2*A[num-1]
            A=list(itertools.chain(A[:c],[a],A[c:]))



### FIXED CODE ###

from heapq import heappop,heappush
q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)
### BUGGY CODE ###

# ソートすりゃいい てっぺんは小さい方から、あとは大きい方から比較していって、ダメになったら抜ける
# と思ったんだけど、これだとTLE。ai以上の最小のbi、bi以上の最小のciをにぶたんで求めて、nから引いて残った数を掛け合わせる
n = int(input())
A = list(sorted(list(map(int, input().split()))))
B = list(sorted(list(map(int, input().split()))))
C = list(sorted(list(map(int, input().split()))))


def nibutan(arr, target):
    left, right = 0,  len(arr)-1//10**9
    while left < right:
        mid = (left + right)//2
        if arr[mid] > target:
            right = mid
        else:
            left = mid + 1
    # rightが「arrの中でtargetを超える最小の値」
    return right


count = 0
for a in A:
    bi = nibutan(B, a)
    for b in B[bi:]:
        ci = nibutan(C, b)
        count += len(C[ci:])
        # print("A: {} B: {}: に対してのCのリスト\n{}".format(a, b, C[ci:]))


print(count)


### FIXED CODE ###

# それぞれソート済みとして, 整数でAi<BjかつBj<Ckとなるjを求める(にぶたん)

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


def lower_bound(arr, target):
    # targetを超える最小の値のインデックス
    if target > arr[-1]:
        return None
    left, right = 0, len(arr)
    while left < right:
        mid = (left + right) // 2
        if arr[mid] > target:
            right = mid
        else:
            left = mid + 1
    return right


def upper_bound(arr, target):
    # target以上の最小の値のインデックス
    if target < arr[0]:
        return None
    left, right = 0, len(arr)
    while left < right:
        mid = (left + right) // 2
        if arr[mid] >= target:
            right = mid
        else:
            left = mid + 1
    return right


count = 0

for b in B:
    ai = upper_bound(A, b)
    ci = lower_bound(C, b)
    if ai is not None and ci is not None:
        count += ai * (N - ci)

print(count)
### BUGGY CODE ###

from functools import reduce
from math import gcd

def gcd_m(*args):
    return reduce(gcd, args)

log = {}
K = int(input())
sum_gcd = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            key = str(sorted([a, b, c]))
            if key in log:
                sum_gcd += log[key]
            else:
                result = gcd_m(a, b, c)
                sum_gcd += result
                log[key] = result
print(sum_gcd)


### FIXED CODE ###

from math import gcd

log = {}
K = int(input())
sum_gcd = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sum_gcd += gcd(gcd(a, b), c)
print(sum_gcd)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import heapq
n,m,s,t = map(int, input().split())
e = [[] for _ in range(n+1)]
for _ in range(m):
    v,u,a,b = map(int, input().split())
    e[v].append((u,(a,b)))
    e[u].append((v,(a,b)))


inf = 10**18
def dijkstra(s,cu):
    d = [inf]*(n+1)
    d[s] = 0

    q = [s]
    heapq.heapify([q])
    while len(q)>0:
        v = heapq.heappop(q)
        for u,ud in e[v]:
            if d[v]+ud[cu]>=d[u]:
                continue
            d[u] = d[v] + ud[cu]
            heapq.heappush(q, u)
    return d


da = dijkstra(s,0)
db = dijkstra(t,1)
res = [0]*n
res[n-1] = da[n]+db[n]
for i in range(n-2,-1,-1):
    res[i] = min(res[i+1], da[i+1]+db[i+1])

for r in res:
    print(10**15 - r)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import heapq
n,m,s,t = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    u,v,a,b = map(int, input().split())
    g[u].append((v,(a,b)))
    g[v].append((u,(a,b)))

inf = 10**18
def dijkstra(s, currency):
    d = [inf]*(n+1)
    d[s] = 0

    que = [(d[s],s)]
    heapq.heapify([que])
    while len(que)>0:
        _,v = heapq.heappop(que)
        for u,c in g[v]:
            if d[v]+c[currency]>=d[u]:
                continue
            d[u] = d[v]+c[currency]
            heapq.heappush(que, (d[u], u))
    return d

yen_c = dijkstra(s,0)
snuuk_c = dijkstra(t,1)

res = [0]*n
res[n-1] = yen_c[n] + snuuk_c[n]
for i in range(n-2,-1,-1):
    res[i] = min(res[i+1], yen_c[i+1]+snuuk_c[i+1])

for r in res:
    print(10**15-r)
### BUGGY CODE ###

H, N = map(int, input().split())
A,B = [],[]
for _ in range(N):
	ta,tb = map(int, input().split())
	A.append(ta)
	B.append(tb)

dp = [[0 for _ in range(H+1)] for _ in range(N)]

for i in range(N):
	if i == 0:
		for j in range(H+1):
			dp[i][j] = -(-j//A[i]) * B[i]
		continue
	for j in range(H+1):
		if j < A[i]:
			dp[i][j] = min(dp[i-1][j], -(-j//A[i])*B[i])
		else:
			dp[i][j] = min(dp[i-1][j], -(-j//A[i])*B[i], dp[i][j-A[i]]+B[i])

print(dp[-1][-1])


### FIXED CODE ###

H, N = map(int, input().split())
A,B = [],[]
for _ in range(N):
	ta,tb = map(int, input().split())
	A.append(ta)
	B.append(tb)

ini_A,ini_B = A[0], B[0]
dp = [-(-j//ini_A)*ini_B for j in range(H+1)]

for i in range(1,N):
	obj_A,obj_B = A[i], B[i]
	for j in range(H+1):
		if j < A[i]:
			dp[j] = min(dp[j], -(-j//obj_A)*obj_B)
		else:
			dp[j] = min(dp[j], -(-j//obj_A)*obj_B, dp[j-obj_A]+obj_B)

print(dp[-1])
### BUGGY CODE ###

N, W = [int(_) for _ in input().split()]
WV = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            reverse=True)
dp = {}
dp[0] = 0
for w, v in WV:
    dp_o = dp.copy()
    for k in dp_o:
        if k + w <= W:
            dp[k + w] = max(dp_o.get(k + w, 0), dp_o[k] + v)
print(max([v for k, v in dp.items()]))


### FIXED CODE ###

N, W = [int(_) for _ in input().split()]
WV = [[int(_) for _ in input().split()] for _ in range(N)]
dp = {}
dp[0] = 0
for w, v in WV:
    dp_o = dp.copy()
    for k in dp_o:
        if k + w <= W:
            dp[k + w] = max(dp_o.get(k + w, 0), dp_o[k] + v)
print(max([v for k, v in dp.items()]))
### BUGGY CODE ###

import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 6)

N = int(input())

plans = []

for _ in range(N):
  a, b, c = map(int, input().split())
  plans.append((a, b, c))

  
@lru_cache(maxsize=None)
def max_utility_at(day, i):
  candidates = [
    (1, 2),
    (0, 2),
    (0, 1)
  ]
  if day == 0:
    return plans[0][i]
  else:    
    return max(max_utility_at(day - 1, x) + plans[day][i] for x in candidates[i])

  
print(max(max_utility_at(N - 1, x) for x in (0, 1, 2)))

### FIXED CODE ###

N = int(input())

activities = []

for i in range(N):
  activities.append([int(x) for x in input().split()])
  
memo = [[0] * N for _ in range(3)]

for day in range(N):
  for no in range(3):
    # 1日目を初期化
    if day == 0:
      memo[no][0] = activities[0][no]
      continue
    # 同じアクティビティが連続しないように
    memo[no][day] = max(
      memo[(no + 1) % 3][day - 1], 
      memo[no - 1][day - 1]
    ) + activities[day][no]
    
print(max(memo[x][N -1] for x in range(3)))
### BUGGY CODE ###

N = int(input())
X = str(input())
X10 = int(X,2)

one_num = X.count("1")

for i in range(N):
    target = int(X[i])
    if target == 0:
        plus = pow(2,N-i-1)
        ones = one_num + 1
    else:
        plus = -pow(2,N-i-1)
        ones = one_num-1
    
    Xnow = X10+plus
    count = 0
    if Xnow == 0:
        print(count)
        continue
    else:
        Xnow = Xnow%ones
        count+=1
        while Xnow > 0:
            Xnow2 = bin(Xnow)
            ones = Xnow2.count("1")
            Xnow = Xnow%ones
            count+=1
        print(count)

### FIXED CODE ###

N = int(input())
x2 = input()
x10 = int(x2, 2)
popc =  x2.count("1")
#print("x10", x10)
#print("popc", popc)
#popc: Nを2進数で表したときの1の個数

#以下で1つフリップさせた時の入力に対する余りを事前に計算
if popc <= 1:
    xp = x10%(popc+1)
    xm = 0
else:
    xp = x10%(popc+1)
    xm = x10%(popc-1)
#print("xp", xp)
#print("xm", xm)

#以下でフリップさせた場所のみを計算
for i in range(N):
    if x2[i] == "1":
        if popc == 1:
            print(0)
            continue
        tmp = (xm - pow(2, N-i-1, popc-1))%(popc-1)
    else:
        tmp = (xp + pow(2, N-i-1, popc+1))%(popc+1)
        
    #print("tmp", tmp)
    ans = 1
    while tmp > 0:
        tmp %= bin(tmp).count("1")
        ans += 1
    print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))

for i in range(1,n+1):
  print(a.count(i))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ls=[0]*n

for i in a:
  ls[i-1]+=1
for i in ls:
  print(i)
### BUGGY CODE ###

import queue
def allvisited():
    for i in range(w):
        for j in range(h):
            if (visited[i][j]==False and s[i][j]=='1'):
                return (False,i,j)
    else:
         return (True,-1,-1)
        
def legal(pos):
    if(0<=pos[0]<w) and (0<=pos[1]<h) and s[pos[0]][pos[1]]=='1' and visited[pos[0]][pos[1]]==False:
        return True
    else:
        return False
    
d=[[0,1],[0,-1],[1,0],[-1,0],[1,1],[-1,1],[1,-1],[-1,-1]]
while(1):
    h,w=map(eval,input().split())
    if (w==0 and h==0): break
    s=[]
    for i in range(w):
        s.append(input().split())
    #print(s)
    Q=queue.Queue()
    visited=[]
    for i in range(w):
        visited.append([False]*h)
    #print(visited)
    count=0
    while(1):
        a=allvisited()
        if (a[0]==False):
            Q.put((a[1],a[2]))
            count+=1
        else:
            break
        while(not Q.empty()):
            now=Q.get()
            visited[now[0]][now[1]]=True
            for i in range(8):
                new=(now[0]+d[i][0],now[1]+d[i][1])
                if(legal(new)):
                    Q.put(new)
    print(count)
            

### FIXED CODE ###

import queue
def allvisited():
    for i in range(w):
        for j in range(h):
            if (visited[i][j]==False and s[i][j]=='1'):
                return (False,i,j)
    else:
         return (True,-1,-1)
        
def legal(pos):
    if(0<=pos[0]<w) and (0<=pos[1]<h) and s[pos[0]][pos[1]]=='1' and visited[pos[0]][pos[1]]==False:
        return True
    else:
        return False
    
d=[[0,1],[0,-1],[1,0],[-1,0],[1,1],[-1,1],[1,-1],[-1,-1]]
while(1):
    h,w=map(eval,input().split())
    if (w==0 and h==0): break
    s=[]
    for i in range(w):
        s.append(input().split())
    #print(s)
    Q=queue.Queue()
    visited=[]
    for i in range(w):
        visited.append([False]*h)
    #print(visited)
    count=0
    while(1):
        a=allvisited()
        if (a[0]==False):
            Q.put((a[1],a[2]))
            visited[a[1]][a[2]]=True
            count+=1
        else:
            break
        while(not Q.empty()):
            now=Q.get()
            for i in range(8):
                new=(now[0]+d[i][0],now[1]+d[i][1])
                if(legal(new)):
                    Q.put(new)
                    visited[new[0]][new[1]]=True
    print(count)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n = int(input())

tmp = [i for i in range(1, n + 1)]
print(sum(tmp) - n)


### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(input())

sum_n = n * (1 + n) // 2
print(sum_n - n)
### BUGGY CODE ###

n=int(input())
s=input()
result=3*(10**5)
for i in range(n-1):
	result=min(result,s[:i].count('W')+s[(i+1):].count('E'))
print(result)

### FIXED CODE ###

n=int(input())
s=input()
a=b=s[1:].count('E')

for i in range(n-1):
	if s[i+1]=='E':
		b-=1
	if s[i]=='W':
		b+=1
	a=min(a,b)
print(a)
### BUGGY CODE ###

N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
for i in range(0,N):
    for j in range(i+1,N):
        if s[i] == s[j]:
            t +=1
print(t)

### FIXED CODE ###

N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
s = sorted(s)
t = 0
i = 0
while i<N:
    for j in range(i+1,N):
        if s[i]==s[j]:
            t = t+j-i
        else:
            break
    i = j
    if i==N-1:
        break
print(t)
### BUGGY CODE ###

import bisect
 
N,M = map(int,input().split())
Price_List = list(map(int,input().split()))
Price_List.sort()
for i in range(M):
    New_Price = Price_List.pop(-1)//2
    Price_List.insert(bisect.bisect(Price_List,New_Price),New_Price)
print(sum(Price_List))

### FIXED CODE ###

import bisect
 
N,M = map(int,input().split())
Price_List = list(map(int,input().split()))
Price_List.sort()
for i in range(M):
    New_Price = Price_List.pop(-1)//2
    Price_List.insert(bisect.bisect(Price_List,New_Price),New_Price)
print(sum(Price_List))
### BUGGY CODE ###

from collections import deque
from itertools import product

h, w = map(int, input().split())
c = tuple(map(lambda x: int(x)-1, input().split()))
d = tuple(map(lambda x: int(x)-1, input().split()))
s = list(input() for _ in range(h))

move_a_area = [(0, -1), (-1, 0), (1, 0), (0, 1)]
move_b_area = [(i, j) for i, j in product(range(-2, 3), repeat=2) if (i, j) not in [(0, 0)] + move_a_area]

cost = [[float('inf')] * w for _ in range(h)]
cost[c[0]][c[1]] = 0
que = deque([(c[0], c[1], 0)])

while que:
    y, x, m = que.popleft()
    # Move A
    for dx, dy in move_a_area:
        hh, ww = y + dy, x + dx
        if hh < 0 or h <= hh or ww < 0 or w <= ww or s[hh][ww] == '#' or cost[hh][ww] <= m:
            continue
        cost[hh][ww] = m
        que.append((hh, ww, m))
    # Move B
    for dx, dy in move_b_area:
        hh, ww = y + dy, x + dx
        if hh < 0 or h <= hh or ww < 0 or w <= ww or s[hh][ww] == '#' or cost[hh][ww] <= m + 1:
            continue
        cost[hh][ww] = m + 1
        que.append((hh, ww, m + 1))

print(v if (v := cost[d[0]][d[1]]) < float('inf') else -1)


### FIXED CODE ###

from collections import deque
from itertools import product

h, w = map(int, input().split())
c = tuple(map(lambda x: int(x)-1, input().split()))
d = tuple(map(lambda x: int(x)-1, input().split()))
s = list(input() for _ in range(h))

move_a_area = [(0, -1), (-1, 0), (1, 0), (0, 1)]
move_b_area = [(i, j) for i, j in product(range(-2, 3), repeat=2) if (i, j) not in [(0, 0)] + move_a_area]

cost = [[float('inf')] * w for _ in range(h)]
cost[c[0]][c[1]] = 0
que = deque([(c[0], c[1], 0)])

while que:
    y, x, m = que.popleft()
    # Move A
    for dx, dy in move_a_area:
        hh, ww = y + dy, x + dx
        if hh < 0 or h <= hh or ww < 0 or w <= ww or s[hh][ww] == '#' or cost[hh][ww] <= m:
            continue
        cost[hh][ww] = m
        que.appendleft((hh, ww, m))
    # Move B
    for dx, dy in move_b_area:
        hh, ww = y + dy, x + dx
        if hh < 0 or h <= hh or ww < 0 or w <= ww or s[hh][ww] == '#' or cost[hh][ww] <= m + 1:
            continue
        cost[hh][ww] = m + 1
        que.append((hh, ww, m + 1))

print(cost[d[0]][d[1]] if cost[d[0]][d[1]] < float('inf') else -1)
### BUGGY CODE ###

n, k = (int(x) for x in input().split())

c = {} 
t = 0
for x in range(k, 0, -1):
    q = k // x
    c[x] = q ** n - sum(c[x * y] for y in range(2, q + 1))
    t += c[x] * x
    t = t % 1000000007

print(t)

### FIXED CODE ###

n, k = (int(x) for x in input().split())
c = {} 
t = 0
MOD = 1000000007
for x in range(k, 0, -1):
    q = k // x
    c[x] = pow(q, n, MOD) - sum(c[x * y] for y in range(2, q + 1))
    t += c[x] * x
    t = t % 1000000007
print(t)
### BUGGY CODE ###

s = input()
t = input()
dp = [["" for _ in range(len(t)+1)] for _ in range(len(s)+1)]
for i in range(len(s)):
	for j in range(len(t)):
		if s[i] == t[j]:
			dp[i+1][j+1] = dp[i][j] + s[i]
		elif len(dp[i+1][j]) >= len(dp[i][j+1]):
			dp[i+1][j+1] = dp[i+1][j]
		else:
			dp[i+1][j+1] = dp[i][j+1]

print(dp[-1][-1])

### FIXED CODE ###

s = input()
t = input()
dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]
for i in range(len(s)):
	for j in range(len(t)):
		if s[i] == t[j]:
			dp[i+1][j+1] = dp[i][j] + 1
		elif dp[i+1][j] >= dp[i][j+1]:
			dp[i+1][j+1] = dp[i+1][j]
		else:
			dp[i+1][j+1] = dp[i][j+1]

ans = ""

i, j = len(s), len(t)

while i > 0 and j > 0:
	#if dp[i][j] == dp[i-1][j-1] + 1:
	if s[i-1] == t[j-1]:
		ans += s[i-1]
		i, j = i-1, j-1
	elif dp[i][j-1] >= dp[i-1][j]:
		j -= 1
	else:
		i -= 1

print(ans[::-1])
### BUGGY CODE ###

ABK = input().split()
A = int(ABK[0])
B = int(ABK[1])
K = int(ABK[2])

cookie_eaten = 0

while (cookie_eaten != K):
    if (A > 0):
        A -= 1
    else:
        B -= 1

    cookie_eaten += 1

print(str(A) + " " + str(B))

### FIXED CODE ###

ABK = input().split()
A = int(ABK[0])
B = int(ABK[1])
K = int(ABK[2])

if (K >= A):
    K -= A
    B -= K
    A = 0

    if (B <= 0):
        B = 0
else:
    A -= K

print(str(A) + " " + str(B))
### BUGGY CODE ###

n = int(input())
r = [0,0,0,0,0]
for i in range(0,5):
    r[i] = int(input())
place = [n,0,0,0,0,0]
time = 0
while(place[-1] != n):
    for i in range(5,0,-1):
        if(place[i-1] < r[i-1]):
            place[i] += place[i-1]
            place[i-1] = 0
        else:
            place[i] += r[i-1]
            place[i-1] -= r[i-1]
    time += 1
print(time)

### FIXED CODE ###

import math
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
print(4+math.ceil(n/min(a,b,c,d,e)))
### BUGGY CODE ###

from math import sqrt
def get_divisor(num):
	return [i for i in range(1,num+1) if num % i == 0]

def get_common(num1, num2):
	list_a = get_divisor(num1)
	list_b = get_divisor(num2)
	return [i for i in list_a if i in list_b]

def prime_ch(num):
	if num == 1:
		return False
	for i in range(2,int(sqrt(num))+1):
		if num % i == 0:
			return False
	return True


A,B = list(map(int,input().split()))[:2]
common = get_common(A,B)
c_prime = [p for p in common if prime_ch(p)]
print((len(c_prime)+1))

### FIXED CODE ###

from math import sqrt
def get_divisor(num):
	arr = [i for i in range(1,int(sqrt(num))+1) if num % i == 0]
	arr += [num // i for i in reversed(arr) if num // i not in arr]
	return arr

def get_common(num1, num2):
	list_a = get_divisor(num1)
	list_b = get_divisor(num2)
	return [i for i in list_a if i in list_b]

def prime_ch(num):
	if num == 1:
		return False
	for i in list(range(2,int(sqrt(num))+1)):
		if num % i == 0:
			return False
	return True


A,B = list(map(int,input().split()))[:2]
common = get_common(A,B)
c_prime = [p for p in common if prime_ch(p)]
print((len(c_prime)+1))
### BUGGY CODE ###

#import numpy as np
N,M=input().split(" ")
N=int(N)
M=int(M)
Alist=input().split(" ")
Alist = [float(A) for A in Alist]


for m in range(M):
    i=Alist.index(max(Alist))
    Alist[i]=Alist[i]/2
    # print(Alist)


Alist_i = [int(A) for A in Alist]

print(sum(Alist_i))

### FIXED CODE ###

from heapq import heappush,heappop
N,M=input().split(" ")
N=int(N)
M=int(M)
Alist=input().split(" ")
# Alist = [-float(A) for A in Alist]
hAqueue=[]
for A in Alist:
    heappush(hAqueue,-float(A))

for m in range(M):
    tmp=heappop(hAqueue)
    heappush(hAqueue,tmp/2)
Alist = [-int(A) for A in hAqueue]
print(sum(Alist))
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,m=map(int,input().split())
	li=[[] for _ in range(n+1)]
	for i in range(m):
		l,r,d=map(int,input().split())
		li[l].append((r,d))
		li[r].append((l,-d))
	
	q=deque()
	check=set()
	a=[""]*(n+1)

	for i in range(1,n+1):
		if i in check:
			continue
		elif li[i]==[]:
			continue
		else:
			q.append(i)
			a[i]=0
			while q:
				now=q.pop()
				check.add(now)
				for j in li[now]:
					r=j[0]
					d=j[1]
					if r in check:
						if a[r]-a[now]!=d:
							print("No")
							exit(0)
						else:
							continue
					elif r in q:
						if a[r]-a[now]!=d:
							print("No")
							exit(0)
						else:
							continue
					else:
						a[r] = a[now] + d
						q.append(r)
					
	print("Yes")
	
	
if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,m=map(int,input().split())
	li=[[] for _ in range(n+1)]
	for i in range(m):
		l,r,d=map(int,input().split())
		li[l].append((r,d))
		li[r].append((l,-d))
	
	q=deque()
	a=[None]*(n+1)

	for i in range(1,n+1):
		if a[i]==None:
			q=[i]
			a[i]=0
			while q:
				now=q.pop()
				for r,d in li[now]:
					if a[r]==None:
						a[r] = a[now] + d
						q.append(r)
					else:
						if a[r]-a[now]!=d:
							print("No")
							exit(0)
						else:
							continue
					
	print("Yes")
	
	
if __name__ == '__main__':
	main()