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

#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=list(map(int,input().split()))

    from functools import reduce
    from math import gcd
    
    def lcm(A, B):
        return A * B // gcd(A, B)
    
    
    # リストを引数にとる
    val=reduce(lcm, A)
    ans=0
    MOD=10**9+7
    for i in A:
        ans+=val//i
        ans%=MOD
    print(ans%MOD)
    
resolve()

### FIXED CODE ###

#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=list(map(int,input().split()))

    from functools import reduce
    from math import gcd
    
    def lcm(A, B):
        return A * B // gcd(A, B)
    
    
    # リストを引数にとる
    val=reduce(lcm, A)
    ans=0
    MOD=10**9+7
    for i in A:
        ans+=val*pow(i,MOD-2,MOD)%MOD
        ans%=MOD
    print(ans)

    


    
resolve()
### BUGGY CODE ###

def popcnt(n):
    return bin(n).count("1")

n = int(input())
grid = []

for i in range(n):
    p = int(input())
    for j in range(p):
        array = [i] +list(map(int, input().strip().split(' ')))
        array[1] = array[1] - 1
        grid.append(array)


truth = 0
count = 0

for i in range(2**n):
    k = (bin(i)[2:]).zfill(n)
    count = 0
    for j in range(len(grid)):
        if int(k[grid[j][0]]) == 1:
            if (int(k[grid[j][1]]) == 1 and grid[j][2] == 0) or (int(k[grid[j][1]]) == 0 and grid[j][2] == 1):
                count = 1
    if count == 0:
        if truth < popcnt(i):
            truth = popcnt(i)

print(truth)


### FIXED CODE ###

def popcnt(n):
    return bin(n).count("1")

n = int(input())
grid = []

for i in range(n):
    p = int(input())
    for j in range(p):
        array = [i] +list(map(int, input().strip().split(' ')))
        array[1] = array[1] - 1
        grid.append(array)


truth = 0
count = 0

for i in range(2**n):
    k = (bin(i)[2:]).zfill(n)
    count = 0
    for j in range(len(grid)):
        if int(k[grid[j][0]]) == 1:
            if (int(k[grid[j][1]]) == 1 and grid[j][2] == 0) or (int(k[grid[j][1]]) == 0 and grid[j][2] == 1):
                count = 1
                break
    if count == 0:
        if truth < popcnt(i):
            truth = popcnt(i)

print(truth)
### BUGGY CODE ###

S=input()
L=len(S)
L1=len(S)
L2=0
while L1!=L2:
    L1=len(S)
    S=S.replace("01","")
    S=S.replace("10","")
    L2=len(S)
print(L-L2)


### FIXED CODE ###

S=input()
print(len(S)-abs(S.count("1")-S.count("0")))
### BUGGY CODE ###

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

cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            pin = [i, j, k]
            x = 0

            for l in range(N):
                if int(S[l]) == pin[x]:
                    x += 1
                    if x == 3:
                        cnt += 1
                        break

print(cnt)

### FIXED CODE ###

N = int(input())
S = list(map(int, list(input())))

cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            pin = [i, j, k]
            x = 0

            for a in S:
                if a == pin[x]:
                    x += 1
                    if x == 3:
                        cnt += 1
                        break

print(cnt)
### BUGGY CODE ###

N, S = map(int, input().split())
*A, = map(int, input().split())
dp = [[0]*(3001) for _ in range(N+1)]
MOD = 998244353
ans = 0

dp[0][0] = pow(2, N, MOD)
for i in range(1, N+1):    
    for j in range(3001):
        dp[i][j] += dp[i-1][j]
        if j-A[i-1]>=0:
            dp[i][j] += dp[i-1][j-A[i-1]]*pow(2, MOD-2, MOD)
        dp[i][j] %= MOD

print(dp[N][S])


### FIXED CODE ###

import sys
input=sys.stdin.readline


def main():
    N, S = map(int, input().split())
    *A, = map(int, input().split())
    dp = [[0]*(3001) for _ in range(N+1)]
    MOD = 998244353
    m = pow(2, MOD-2, MOD)
    dp[0][0] = pow(2, N, MOD)
    for i in range(1, N+1):    
        for j in range(3001):
            dp[i][j] += dp[i-1][j]
            if j-A[i-1]>=0:
                dp[i][j] += dp[i-1][j-A[i-1]]*m
            dp[i][j] %= MOD

    print(dp[N][S])


main()
### BUGGY CODE ###

A,B = map(int,input().split())
i = 0
while True:
    i1 = i + 1
    if i1 % A == 0 and i1 % B == 0:
        print(i1)
        break
    i += 1

### FIXED CODE ###

A,B = map(int,input().split())
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
print(A*B // euclid(A, B))
### BUGGY CODE ###

S = input()
Q = int(input())

reversing = False
for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        reversing = not reversing
    else:
        if query[1] == '1':
            if not reversing:
                S = query[2] + S
            else:
                S += query[2]
        else:
            if reversing:
                S = query[2] + S
            else:
                S += query[2]

print(S) if not reversing else print(S[::-1])

### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())

reversing = False

for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        reversing = not reversing
    else:
        if query[1] == '1':
            if not reversing:
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if reversing:
                S.appendleft(query[2])
            else:
                S.append(query[2])

print(''.join(S)) if not reversing else print(''.join(reversed(S)))
### BUGGY CODE ###

data = input().split(" ")
data = list(map(int, data))

count=0

for x in range(data[0]+1):
    for y in range(data[0]+1):
        if data[0] >= (data[1]-(x+y)) >= 0:
            z = data[1]-(x+y)
            
            if x + y + z == data[1]:
                count+=1
print(count)

### FIXED CODE ###

data = input().split(" ")
data = list(map(int, data))

count=0

for x in range(data[0]+1):
    for y in range(data[0]+1):
        if data[0] >= (data[1]-(x+y)) >= 0:
            z = data[1]-(x+y)
            
            if x + y + z == data[1]:
                count+=1
print(count)
### BUGGY CODE ###



N = int(input())
E = []
A = [[-1 for j in range(N+1)] for i in range(N+1)]
edges = [[] for i in range(N+1)]
colors = [[] for i in range(N+1)]

for i in range(N-1):
  a, b = map(int, input().split())
  E.append((a,b))
  edges[a].append(b)
  edges[b].append(a)

def dfs(u):
  visited = set()
  visited.add(u)
  stack = [u]
  mcolor = -1

  while stack:
    u = stack.pop()
  
    for v in edges[u]:
      if v not in visited:
        c = colors[u] + colors[v]
        next = 1
        while next in c:
          next += 1
        
        mcolor = max(mcolor, next)
        A[u][v] = next
        A[v][u] = next
        colors[u].append(next)
        colors[v].append(next)
        visited.add(v)
        stack.append(v)
  
  return mcolor

print(dfs(1))

for edge in E:
  a, b = edge
  print(A[a][b])

### FIXED CODE ###


N = int(input())
edges = [[] for _ in range(N+1)]


for i in range(N-1):
  a, b = map(int, input().split())
  if i == 0:
    root = a
  edges[a].append((b, i))
  edges[b].append((a, i))

ans = [-1 for i in range(N-1)]
def dfs(u):
  flag = ["white"] * (N + 1)
  stack = [(u, -1, -1)]

  while stack:
    u, parent, color = stack.pop()
    flag[u] = "black"

    nextColor = 1
    for (next, index) in edges[u]:
      if next != parent and flag[next] != "black":
        if nextColor == color:
          nextColor += 1
        stack.append((next, u, nextColor))
        ans[index] = nextColor
        nextColor += 1

dfs(root)

print(max(ans))

for a in ans:
  print(a)
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())

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


A = sorted(A, key = lambda x:-x)
B = sorted(B, key = lambda x:-x)
C = sorted(C, key = lambda x:-x)

AB = [0] * (X * Y)

index = 0
for i in range(len(A)):
    for j in range(len(B)):
        AB[index] = A[i] + B[j]
        index += 1

AB = sorted(AB, key = lambda x:-x)
AB = AB[0:3010]

ABC = [0] * (3010 * Z)
index = 0

for i in AB:
    for j in C:
        ABC[index] = i + j
        index += 1

ABC = sorted(ABC, key = lambda x:-x)
for i in range(0,K):
    print(ABC[i])

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())

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


A = sorted(A, key = lambda x:-x)
B = sorted(B, key = lambda x:-x)
C = sorted(C, key = lambda x:-x)

AB = [0] * (X * Y)

ABC = []

for i in range(X):
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for k in range(Z):
            if (i + 1) * (j + 1) * (k + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[k])

ABC = sorted(ABC, key = lambda x:-x)
for i in range(0, K):
    print(ABC[i])
### BUGGY CODE ###

N = int(input())
A = [int(input()) for i in range(N)]

temp = [A[0]]
for i in range(1,N):
  temp.sort(reverse=True)
  for j in range(len(temp)):
    if A[i] > temp[j]:
      temp[j] = A[i]
      break
  else:
    temp.append(A[i])

print(len(temp))

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]

import bisect
from collections import deque

temp = deque()
temp.appendleft(A[0])
for i in range(1,N):
  if temp[0] >= A[i]:
    temp.appendleft(A[i])
  else:
    temp[bisect.bisect_left(temp,A[i])-1] = A[i]
print(len(temp))
### BUGGY CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,K = map(int, input().split())
# *A = map(int, input().split())
A = list(map(int, input().split()))
dp = [ [0]*(K+1) for _ in range(N+1)]

dp[0][K]= 1
MOD= int(1e9+7)

for i in range(N): # i+1$B$K(B
    for k in range(K, -1, -1):

        for ai in range(A[i]+1): # ai = 0 to Ai
            if k - ai >= 0:
                dp[i+1][k-ai] += dp[i][k] % MOD
            # print("dp[{ip1}][{kai}] += dp[{i}][{k}]".format(ip1=i+1, kai=k-ai, i=i, k=k))
# print(dp[N][K])
print(dp[N][0] % MOD)
# print(dp)


### FIXED CODE ###

from itertools import accumulate

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

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

MOD = int(1e9+7)

dp = [0] * (K+1)
dp[0] = 1

for n in range(N):

    sumlist = [0]
    sumlist += dp[:]
    sumlist = list(accumulate(sumlist))

    ndp = [0] * (K+1)
    for k in range(K+1):
        ndp[k] = sumlist[k+1] - sumlist[max(0, k - A[n])] 
        ndp[k] %= MOD
    dp = ndp
                # dp[k] ~ dp[k-A[n]] made
print(dp[K]%MOD)
### BUGGY CODE ###

a, b, c, k = map(int, input().split())
cnt = 0
ans = 0
while cnt < k:
    if a > 0:
        a -= 1
        cnt += 1
        ans += 1
    elif b > 0:
        b -= 1
        cnt += 1
    elif c > 0:
        c -= 1
        cnt += 1
        ans -= 1
print(ans)

### FIXED CODE ###

a, b, c, k = map(int, input().split())
ans = 0
ans += min(a, k)
ans -= max(0, k - a - b)
print(ans)
### BUGGY CODE ###

N = int(input())
As = list(sorted(list(map(int, input().split()))))

result = 0
stored = []
while len(As)!=0:
    item = As[-1]
    As = As[:-1]
    is_exist = False
    if item in stored:
        continue
    for A in sorted(As):
        if item%A==0:
            is_exist = True
            break
    if not is_exist:
        result+=1
    stored.append(item)
print(result)


### FIXED CODE ###

N = int(input())
As = list(sorted(list(map(int, input().split()))))

max_num = max(As)
tfs = [0 for _ in range(max_num+1)]

for A in As:
    if tfs[A] != 0:
        tfs[A] = 2
        continue
    for j in range(A, max_num+1, A):
        tfs[j]+=1

result = 0
for A in As:
    if tfs[A] == 1:
        result+=1
print(result)
### BUGGY CODE ###

n = int(input())
A = tuple(map(int, input().split()))
U = 10**6
D = list(range(U+1))
i = 2
while i*i <= U:
  if D[i] != i:
    i += 1
    continue
  for j in range(i*i, U+1, i):
    D[j] = min(D[j], i)
  i += 1
C = [0]*(U+1)
is_pairwise = True
for a in A:
  while a > 1:
    d = D[a]
    while a%d == 0:
      a //= d
    if C[d]:
      is_pairwise = False
    C[d] += 1
if max(C) == n:
  print("not coprime")
else:
  if is_pairwise:
    print("pairwise coprime")
  else:
    print("setwise coprime")

### FIXED CODE ###

import sys
input = sys.stdin.readline

def gcd(a, b):
    while b: a, b = b, a % b
    return a
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret


from collections import defaultdict
n = int(input())
A = tuple(map(int, input().split()))
x = A[0]
M1 = defaultdict(int)
M2 = defaultdict(int)
b = False
for a in A:
    x = gcd(x, a)
    if b:
      continue
    for f, cnt in primeFactor(a).items():
      if cnt >= M1[f]:
        M2[f] = M1[f]
        M1[f] = cnt
      elif cnt >= M2[f]:
        M2[f] = cnt
      if M2[f] >= 1:
        b = True
        break
if x != 1:
    print("not coprime")
    exit()
if b:
  print("setwise coprime")
  exit()
print("pairwise coprime")
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
ans = []
def divisor(n):
  ret = [0]
  for i in range(2,int(n**(1/2))+1):
    if n%i==0:
      ret.append(i-1)
      
      comp=n//i
      if i!=comp:
        ret.append(comp-1)
      
  return ret

for i in reversed(range(N)):
  if a[i]:
    ans.append(i+1)
    lis = divisor(i+1)
    for j in lis:
      a[j]^=1
      
l = len(ans)
if l>0:
  print(l)
  print(*ans)
else:
  print(l)

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
ans = []
def divisor(n):
  ret = [0]
  for i in range(2,int(n**(1/2))+1):
    if n%i==0:
      ret.append(i-1)
      
      comp=n//i
      if i!=comp:
        ret.append(comp-1)
      
  return ret

for i in reversed(range(N)):
  if a[i]:
    ans.append(i+1)
    lis = divisor(i+1)
    for j in lis:
      a[j]^=1
      
l = len(ans)
if l>0:
  print(l)
  print(*ans)
else:
  print(l)
### BUGGY CODE ###

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

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        ans += A[i] * A[j] % (10**9 + 7)

print(ans % (10**9 + 7))


### FIXED CODE ###

#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7

s = sum(A)** 2

a = 0
for i in A:
    a += (i ** 2)

ans = (s - a) // 2
ans = ans % mod

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

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

ans = 0
for i in range(N):
    x = S[i]
    for j in range(i+1,N):
        y = S[j]
        if x == y:
            continue
        else:
            for k in range(j+1,N):
                z = S[k]
                A = j - i
                B = k - j
                if x != z and y != z and (A != B):
                    ans += 1
                    
print(ans)

### FIXED CODE ###

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

all = S.count("R") * S.count("G") * S.count("B")
count = 0
for i in range(N):
    for j in range(1,N):
        k = 2*j - i
        if k < N and i < j:
            if (S[i] != S[j]) and (S[j] != S[k]) and (S[k] != S[i]):
                count += 1
print(all-count)
### BUGGY CODE ###

# AtCoder DP Task D - Knapsack 1
def knapsack(target, W, V): # target=knapsack weight
    P = [[0] * (target + 1) for _ in range(len(V))]
    for vi in range(len(V)):
        row, prev = P[vi], P[vi - 1]
        for w in range(target + 1):
            if vi > 0:
                row[w] = prev[w] # same value without vi-th item
                if w >= W[vi]:
                    new = P[vi - 1][w - W[vi]] + V[vi]
                    if new > P[vi][w]: # most value
                        row[w] = new
            else:
                if w >= W[vi]:
                    row[w] = V[vi]
    return P[len(V) - 1][target]

def knapsack_rec(target, W, V): # target=knapsack weight
#    P = [[-1] * (target + 1) for _ in range(len(V))]
    P = {}

    def rec(w, index):
        if index == 0 and w >= W[index]:
            return V[index]
        elif index > 0:
            if (index, w) in P: # P[index][w] != -1:
                return P[(index,w)]
            r = rec(w, index - 1)
            if w >= W[index]:
                y = rec(w - W[index], index - 1) + V[index]
                r = r if r > y else y
            P[(index,w)] = r
            return r
        return 0

    ret = rec(target, len(V) - 1)
    return ret

assert knapsack_rec(15, [6, 5, 6, 6, 3, 7], [5, 6, 4, 6, 5, 2]) == 17

if __name__ == "__main__":
    n, w = map(int, input().split())
    W, V = [], []
    for _ in range(n):
        weight, value = map(int, input().split())
        W.append(weight)
        V.append(value)
    ans = knapsack(w, W, V)
    print(ans)


### FIXED CODE ###

# AtCoder DP Task D - Knapsack 1
def knapsack(target, W, V): # target=knapsack weight
    P = [[0] * (target + 1) for _ in range(len(V))]
    for vi in range(len(V)):
        row, prev = P[vi], P[vi - 1]
        for w in range(target + 1):
            if vi > 0:
                row[w] = prev[w] # same value without vi-th item
                if w >= W[vi]:
                    new = P[vi - 1][w - W[vi]] + V[vi]
                    if new > P[vi][w]: # most value
                        row[w] = new
            else:
                if w >= W[vi]:
                    row[w] = V[vi]
    return P[len(V) - 1][target]

def knapsack_rec(target, W, V): # target=knapsack weight
    P = [-1] * (target + 1)
    P[target] = 0 # default + max

    for vi in range(len(V)):
        we = W[vi]
        va = V[vi]
        for i in range(we, target + 1):
            if P[i] != -1 and P[i - we] < P[i] + va:
                P[i - we] = P[i] + va

    return max(P)

assert knapsack_rec(15, [6, 5, 6, 6, 3, 7], [5, 6, 4, 6, 5, 2]) == 17

if __name__ == "__main__":
    import sys
    n, w, *r = map(int, sys.stdin.read().split())
    W, V = r[::2], r[1::2]
    ans = knapsack_rec(w, W, V)
    print(ans)
### BUGGY CODE ###

import bisect
N = int(input())
S = tuple(map(lambda x: (x**2+x)//2, range(N)))
while N > 0:
    i = bisect.bisect_left(S, N)
    N -= i
    #print(i, N, S)
    print(i)


### FIXED CODE ###

import bisect
N = int(input())
S = tuple(map(lambda x: (x**2+x)//2, range(int(N**(2/3))+100)))
while N > 0:
    i = bisect.bisect_left(S, N)
    N -= i
    #print(i, N, S)
    print(i)
### BUGGY CODE ###

n,a,b=map(int, input().split())
cnt = 0
tmp = n
mode = 0
if a == 0:
    cnt = 0
elif a+b == n:
    cnt = a
else:
    while True:
        if tmp >= a and mode == 0:
            tmp = tmp - a
            cnt += a
            mode = 1
        elif mode == 1:
            tmp = tmp-b
            mode = 0
        elif tmp < a and mode == 0:
            cnt += tmp
            tmp = tmp -a
        if tmp <= 0:
            break
        
print(cnt)
    
    


### FIXED CODE ###

import math
n,a,b=map(int, input().split())
cnt = 0
mode = 0
if a == 0:
    cnt = 0
elif a+b == n:
    cnt = a
else:
    roop = math.floor(n / (a+b))
    anc_a = a*roop
    n_b = n-(roop*(a+b))
    while True:
        if n_b >= a and mode == 0:
            n_b = n_b - a
            cnt += a
            mode = 1
        elif mode == 1:
            n_b = n_b-b
            mode = 0
        elif n_b < a and mode == 0:
            cnt += n_b
            n_b = n_b -a
        if n_b <= 0:
            break
    cnt += anc_a 
print(cnt)
### BUGGY CODE ###

n, m = map(int, input().split())
G = [[] for _ in range(n)]
indeg = [0] * n

for _ in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    G[r].append((l, d))
    indeg[r] += 1

from collections import deque
ng = False
visited = [0] * n
for start, deg in enumerate(indeg):
    if deg == 0 or visited[start] == 1:
        continue
    st = deque([[start, 0]])
    visited_cost = [-1] * n
    while st:
        i, cost = st.pop()
        for ni, nd in G[i]:
            if visited_cost[ni] == -1:
                # まだ記録されていない
                visited[ni] = 1
                visited_cost[ni] = cost + nd
                st.append([ni, cost + nd])
            elif visited_cost[ni] == cost + nd:
                visited[ni] = 1
                continue
            else:
                # 既に記録されていて、矛盾している場合
                # 終了
                ng = True
                break
        if ng:
            break
    if ng:
        break

print('No' if ng else 'Yes')


### FIXED CODE ###

n, m = map(int, input().split())
G = [[] for _ in range(n)]
indeg = [0] * n

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

from collections import deque
ng = False
visited = [0] * n
visited_cost = [0] * n

for start in range(n):
    if visited[start]:
        continue
    visited[start] = 1
    st = deque([[start, 0]])
    while st:
        i, cost = st.pop()
        for ni, nd in G[i]:
            if visited[ni] == 0:
                visited[ni] = 1
                visited_cost[ni] = cost + nd
                st.append([ni, cost + nd])
            else:
                # 既に記録されていて、矛盾している場合
                if visited_cost[ni] != cost + nd:
                    # 終了
                    ng = True
                    break
        if ng:
            break
    if ng:
        break
print('No' if ng else 'Yes')