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

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

answer = N
for i in range(N-1):
    v = A[i]
    for j in range(i+1, N):
        vx = v ^ A[j]
        vp = v + A[j]
        if vx == vp:
            answer += 1
            v = vx
        else:
            break
print(answer)


### FIXED CODE ###

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

f = {}
right = 0
accum = A[0]
for left in range(N):
    if right < left:
        right = left
        accum = A[left]

    while(right < N-1):
        if accum & A[right+1] == 0:
            accum += A[right+1]
            right += 1
        else:
            break

    f[left] = right
    accum -= A[left]

answer = 0
for i in range(N):
    answer += f[i] - i + 1

print(answer)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import math

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

#############
# Main Code #
#############

k,q = map(int, input().split())
d = list(map(int, input().split()))

while(q):
  n,x,m = map(int, input().split())
  x %= m
  ans = n-1
  n -= 1
  s1 = 0
  t1 = 0
  for i in range(k):
    s1 += d[i] % m
    if d[i] % m == 0:
      t1 += 1
  s2 = 0
  t2 = 0
  for i in range(n%k):
    s2 += d[i] % m
    if d[i] % m == 0:
      t2 += 1
  x += s1 * (n//k) + s2
  ans -= x//m
  ans -= t1 * (n//k) + t2

  
    
  
    
  
  
  
  print(ans)
  q -= 1

### FIXED CODE ###

# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import math

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

#############
# Main Code #
#############

k,q = map(int, input().split())
d = list(map(int, input().split()))

def query(n,x,m):
  x %= m
  ans = n-1
  n -= 1
  s1 = 0
  t1 = 0
  for i in range(k):
    s1 += d[i] % m
    if d[i] % m == 0:
      t1 += 1
  s2 = 0
  t2 = 0
  for i in range(n%k):
    s2 += d[i] % m
    if d[i] % m == 0:
      t2 += 1
  x += s1 * (n//k) + s2
  ans -= x//m
  ans -= t1 * (n//k) + t2
  
  print(ans)
  
    

for _ in range(q):
  n,x,m = map(int, input().split())
  query(n,x,m)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
C = list(map(int, input().split()))
LR = []
for i in range(Q):
    l, r = map(int, input().split())
    LR.append((l-1, r-1, i))


class FenwickTree(object):
    def __init__(self, n):
        self._bit = [0] * (n+1)
        self.n = n+1
    
    def add(self, i, a):
        i += 1
        while i < self.n:
            self._bit[i] += a
            i += i & -i
    
    def sum(self, i):
        i += 1
        ret = 0
        while i > 0:
            ret += self._bit[i]
            i -= i & -i
        return ret


def solve():
    memo = [-1] * N
    ST = []
    nst = 0
    for i, c in enumerate(C[::-1]):
        if memo[c-1] >= 0:
            ST.append((N-i-1, memo[c-1]))
            nst += 1
        memo[c-1] = N-i-1
    # ST.sort(reverse=True)
    LR.sort(reverse=True)
    ans =[0 for _ in range(Q)]
    ft = FenwickTree(N+1)
    j = 0
    for l, r, i in LR:
        while j < nst and ST[j][0] >= l:
            ft.add(ST[j][1], 1)
            j += 1
        ans[i] = r - l + 1 - ft.sum(r)
    return ans

if __name__ == "__main__":
    print('\n'.join(map(str, solve())))


### FIXED CODE ###

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
C = list(map(int, input().split()))
LR = []
for i in range(Q):
    l, r = map(int, input().split())
    LR.append((l-1, r-1, i))


class FenwickTree(object):
    def __init__(self, n):
        self._bit = [0] * (n+1)
        self.n = n+1
    
    def add(self, i, a):
        i += 1
        while i < self.n:
            self._bit[i] += a
            i += i & -i
    
    def sum(self, i):
        i += 1
        ret = 0
        while i > 0:
            ret += self._bit[i]
            i -= i & -i
        return ret


def solve():
    memo = [-1] * N
    ST = []
    nst = 0
    for i, c in enumerate(C[::-1]):
        if memo[c-1] >= 0:
            ST.append((N-i-1, memo[c-1]))
            nst += 1
        memo[c-1] = N-i-1
    # ST.sort(reverse=True)
    LR.sort(reverse=True, key=lambda x:x[0])
    ans =[0 for _ in range(Q)]
    ft = FenwickTree(N+1)
    j = 0
    for l, r, i in LR:
        while j < nst and ST[j][0] >= l:
            ft.add(ST[j][1], 1)
            j += 1
        ans[i] = r - l + 1 - ft.sum(r)
    return ans

if __name__ == "__main__":
    print('\n'.join(map(str, solve())))
### BUGGY CODE ###

N = int(input())
c = list(input())
color = [i == 'R' for i in c]
ans = 0
checked = 0
for right in range(N - 1, -1, -1):
    if color[right]:
        for left in range(checked, right):            
            if not color[left]:
                color[right], color[left] = color[left], color[right]
                ans += 1
                checked = left
                break
print(ans)                

### FIXED CODE ###

N = int(input())
c = list(input())
color = [i == 'R' for i in c]
ans = 0
checked = 0
for right in range(N - 1, -1, -1):
    if color[right]:
        for left in range(checked, right):            
            if not color[left]:
                color[right], color[left] = color[left], color[right]
                ans += 1
                checked = left
                break
        checked = left
print(ans)
### BUGGY CODE ###

import sys
def main():
    input = sys.stdin.readline
    N,S = map(int, input().split())
    A = list(map(int, input().split()))
    MOD = 998244353

    dp = [[[0 for _ in range(3)] for _ in range(S+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        a = A[i]
        for j in range(S+1):
            dp[i+1][j][0] = (dp[i+1][j][0] + dp[i][j][0]) % MOD
            dp[i+1][j][1] = (dp[i+1][j][1] + dp[i][j][1]) % MOD
            dp[i+1][j][2] = (dp[i+1][j][2] + dp[i][j][2]) % MOD

            if j+a > S: continue
            dp[i+1][j+a][1] = (dp[i+1][j+a][1] + dp[i][j][1] + (dp[i][j][0] * (i+1))) % MOD
            dp[i+1][j+a][2] = (dp[i+1][j+a][2] + (dp[i][j][1] * (N-i)) + (dp[i][j][0] * (i+1) * (N-i))) % MOD

    print(dp[N][S][2])

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
def main():
    input = sys.stdin.readline
    N,S=map(int, input().split())
    *A,=map(int, input().split())

    ans = Mint()
    q = [Mint() for _ in range(S+1)]
    for a in A:
        q[0] += 1
        for i in range(S-a,-1,-1): q[i+a] += q[i]
        ans += q[S]
    print(ans)

MOD = 998244353
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value += Mint.get_value(other)
        if self.value >= MOD: self.value -= MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value -= Mint.get_value(other)
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

if __name__ == '__main__':
    main()
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
D = 1
if k != 0:
  while D <= k:
    if h == []:
      print(0)
      exit()
    else:
      h.remove(max(h))
    D += 1
print(sum(h))

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
h.reverse()
if k >= n:
    print(0)
else:
    del h[:k]
    print(sum(h))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append(a[i])
    b = b[::-1]
print(*b)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
if n == 1:
    print(a[0])
else:
    print(*a[::-2],end = ' ')
    print(*a[n%2::2])
### BUGGY CODE ###

from fractions import gcd
N=int(input())
a = list(map(int, input().split()))
lcm = 1
for i in a:
    lcm = lcm * i // gcd(lcm, i)
ans = 0
for i in range(N):
    ans += (lcm//a[i])%(10**9+7)
print(ans%(10**9+7))

### FIXED CODE ###

from fractions import gcd
N=int(input())
a = list(map(int, input().split()))
lcm = 1
for i in a:
    lcm = lcm * i // gcd(lcm, i)
ans = 0
for i in a:
    ans += (lcm//i)#%(10**9+7)
print(ans%(10**9+7))
### BUGGY CODE ###

_, _, _, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = []
for i in a:
  for j in b:
    ab.append(i+j)
ab.sort()
ab.reverse()
abc = []
for i in ab[:k]:
  for j in c:
    abc.append(i+j)
abc.sort()
abc.reverse()
for i in abc[:k]:
  print(i)

### FIXED CODE ###

x, y, z, k = list(map(int, input().split()))
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))

ab = sorted(x+y for x in a for y in b)[:-k-1:-1]
abc = sorted(x+y for x in ab[:k] for y in c)[:-k-1:-1]
print(*abc, sep='\n')
### BUGGY CODE ###

n, k = map(int, input().split())
cnt = 1
while True:
    if n ==1:
        break
    n = n // k
    cnt += 1
    if n//k ==1:
        cnt +=1
        break
print(cnt)

### FIXED CODE ###

n, k = map(int, input().split())
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)


ans = Base_10_to_n(n, k)
print( len(ans) )
### BUGGY CODE ###

n, m = map(int, input().split())
B = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m: B[a] += [b]
C = []
s = 0
for i in range(m+1):
    C += B[i]
    C = sorted(C, reverse = True)[:m-i+1]
    if C: s += C.pop(0)
print(s)

### FIXED CODE ###

from heapq import heappush, heappop
n, m = map(int, input().split())
B = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m: B[a] += [-b]
C = []
s = 0
for i in range(m+1):
    for b in B[i]: heappush(C, b)
    if C: s += heappop(C)
print(-s)
### BUGGY CODE ###

import sys

MAX = 1000000


def digit_sum(n, b):
    if n == 0:
        return 0
    else:
        return digit_sum(n // b, b) + n % b


def main():
    n = int(input())
    s = int(input())

    if n < s:
        print(-1)
        sys.exit()

    ans = -1

    for b in range(2, max(n + 1, MAX) + 1):
        sm = digit_sum(n, b)
        if sm == s:
            ans = b
            break

    if not ans == -1:
        print(ans)
        sys.exit()

    if n + 1 <= MAX:
        print(-1)
        sys.exit()

    for p in reversed(range(MAX)):
        if (n - s) % p != 0:
            continue
        b = (n - s) / p + 1
        sm = digit_sum(n, b)
        if sm == s:
            ans = b
            break

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

MAX = 1000000


def digit_sum(n, b):
    if n == 0:
        return 0
    else:
        return digit_sum(n // b, b) + n % b


def main():
    n = int(input())
    s = int(input())

    if n < s:
        print(-1)
        sys.exit()

    ans = -1

    for b in range(2, min(n + 1, MAX) + 1):
        sm = digit_sum(n, b)
        if sm == s:
            ans = b
            break

    if ans != -1:
        print(ans)
        sys.exit()

    if n + 1 <= MAX:
        print(-1)
        sys.exit()

    for p in reversed(range(1, MAX)):
        if (n - s) % p != 0:
            continue
        b = (n - s) // p + 1
        if b < 2:
            continue
        sm = digit_sum(n, b)
        if sm == s:
            ans = b
            break

    if ans != -1:
        print(ans)
        sys.exit()

    if n == s:
        print(n+1)
        sys.exit()

    print(-1)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import deque
n = int(input())
d = deque()
for i in range(n):
    c, s = input().split()
    if c == "insert":
        d.append(s)
    else:
        if s in d:
            print("yes")
        else:
            print("no")


### FIXED CODE ###

n = int(input())
d = {}
for i in range(n):
    c, s = input().split()
    if c == "insert":
        d[s] = 0
    else:
        if s in d:
            print("yes")
        else:
            print("no")
### BUGGY CODE ###

from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

memo = [-1]*(110000)
def rec(n):
    if n==0:
        return 0
    if memo[n] != -1:
        return memo[n]
    res = n
    pow6,pow9 = 1,1
    while pow6 <=n:
        res = min(res,rec(n-pow6)+1)
        pow6 *= 6
    while pow9 <= n:
        res = min(res,rec(n-pow9)+1)
        pow9 *= 9
    memo[n] = res
    return memo[n]

N = int(input())
print(rec(N))

### FIXED CODE ###

N = int(input())
l = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
dp = [N]*(N+1)
dp[0]=0

for i in range(1,N+1):
    for j in l:
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+1)
print(dp[N])
### BUGGY CODE ###

A, B, C, K = map(int, input().split())
ABC_total = 0
ABC_list =[]
for i in range(A):
  ABC_list.append(1)
for i in range(B):
  ABC_list.append(0)
for i in range(C):
  ABC_list.append(-1)
for i in range(K):
  ABC_total += ABC_list[i]
print(ABC_total)

### FIXED CODE ###

A, B, C, K = map(int, input().split())
if A >= K:
  print(K)
elif A + B >= K:
  print(A)
else:
  print(A - (K - A - B))
### BUGGY CODE ###

S = input()
Q = int(input())
T = [input().split() for i in range(Q)]

cnt = 0
for i in range(Q):
    if T[i][0] == '1':
        cnt += 1
    else:
        if cnt % 2 == 0:
            if T[i][1] == '1':
                S = T[i][2] + S
            else:
                S = S + T[i][2]
        else:
            if T[i][1] == '2':
                S = T[i][2] + S
            else:
                S = S + T[i][2]
if cnt % 2 == 0:
    print(S)
else:
    print(S[::-1])

### FIXED CODE ###

from collections import deque
# N = int(input())
S = input()
Q = int(input())
T = [input().split() for i in range(Q)]
d = deque(S)
cnt = 0
for i in range(Q):
    if T[i][0] == '1':
        cnt += 1
    else:
        if cnt % 2 == 0:
            if T[i][1] == '1':
                d.appendleft(T[i][2])
            else:
                d.append(T[i][2])
        else:
            if T[i][1] == '2':
                d.appendleft(T[i][2])
            else:
                d.append(T[i][2])
if cnt % 2 == 0:
    print(''.join(d))
else:
    print(''.join(d)[::-1])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
a = 0
ans = [0, 0]
for i in range(N):
  for j in range(i+1, N):
    if A[i] < A[j] and (A[j]-A[i])*A[i]>=a:
      ans = [A[j], A[i]]
      a = (A[j]-A[i])*A[i]
    elif (A[i]-A[j])*A[j]>=a:
      ans = [A[i], A[j]]
      a = (A[i]-A[j])*A[j]
ans = [str(b) for b in ans]
ans = ' '.join(ans)
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
M = A[-1]
a = M // 2
for i in range(N-1):
  if A[i] <= a and A[i+1] >= a:
    if (M-A[i])*A[i] >= (M-A[i+1])*A[i+1]:
      ans = [M, A[i]]
    else:
      ans = [M, A[i+1]]
ans = [str(b) for b in ans]
ans = ' '.join(ans)
print(ans)
### BUGGY CODE ###

n = int(input())
l = list(map(int, input().split()))
ls = set(l)

for i in range(1,n+1):
  if i not in l:
    print(0)
  else:
    print(l.count(i))

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
ans =[0]*n
for i in l:
  ans[i-1] +=1
for i in ans:
  print(i)
### BUGGY CODE ###

import itertools
import math
l, r = map(int, input().split())

num = []
for i in range(l,r+1):
    num.append(i)

minimum = 10**9
for v in itertools.combinations(num, 2):
    minimum = min(minimum,v[0]*v[1]%2019)

print(minimum)

### FIXED CODE ###

import itertools
import math
l, r = map(int, input().split())


if(abs(l-r) > 2050): print(0)
else:
    num = []
    for i in range(l,r+1):
        num.append(i)
    minimum = 10**9
    for v in itertools.combinations(num, 2):
        minimum = min(minimum,v[0]*v[1]%2019)
    print(minimum)
### BUGGY CODE ###

N , K = map(int, input().split())
A = list(map(int, input().split()))
syurui = set(A)
goukei = []
ans = 0
for i in syurui:
    goukei.append(A.count(i))

goukei.sort()

if len(syurui) <= K:
    print(ans)
else:
    ans = sum(goukei[0:len(syurui)-K])
    print(ans)

### FIXED CODE ###

import collections
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
hint = collections.Counter(A)
ans = 0
bb = hint.most_common()
if K >= len(bb):
    print(ans)
else:
    for i in range(-1, -(len(bb)-K)-1, -1):
        ans += bb[i][1]
    print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
found = False

data = list()
list_of_one = list()
for i in range(M):
    tup = tuple(map(int, input().split()))
    if tup[0] == 1:
        list_of_one.append(tup[1])
    else:
        data.append(tup)

for entry in data:
    if entry[0] in list_of_one and entry[1] == N:
        found = True

if found:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


### FIXED CODE ###

a=[]
b={}
n,m=map(int,input().split())
for _ in range(m):
	i,j=map(int,input().split())
	if i==1:
		a.append(j)
	elif j==n:
		b[i]=1
for i in a:
	if i in b:
		print('POSSIBLE')
		break
else:
	print('IMPOSSIBLE')
### BUGGY CODE ###

N = int(input())
S = input()
count = 0
for x in range(10):
    for y in range(10):
        for z in range(10):
            phase = 0
            for c in S:
                if phase == 0 and c == str(x):
                    phase = 1
                    continue
                if phase == 1 and c == str(y):
                    phase = 2
                    continue
                if phase == 2 and c == str(z):
                    count += 1
                    break
print(count)


### FIXED CODE ###

N = int(input())
S = input()
L = [str(i).zfill(3) for i in range(1000)]
count = 0
for l in L:
    try:
        i = S.index(l[0])
        j = S.index(l[1], i + 1)
        k = S.index(l[2], j + 1)
        count += 1
    except:
        continue
print(count)
### BUGGY CODE ###

N,K = map(int,input().split())
X = [int(i) for i in input().split()]

min_cost = float('inf')

for i in range(N-K+1):
    sub_x = X[i:i+K]
    tmp_l = abs(sub_x[0]) + abs(sub_x[-1]-sub_x[0])
    tmp_r = abs(sub_x[-1]) + abs(sub_x[0]-sub_x[-1])
    tmp = min(tmp_l,tmp_r)

    if min_cost > tmp:
        min_cost = tmp

print(min_cost)


### FIXED CODE ###

N,K = map(int,input().split())
X = [int(i) for i in input().split()]

min_cost = float('inf')

for i in range(N-K+1):
    l = X[i]
    r = X[i+K-1]
    tmp_l = abs(l) + abs(r-l)
    tmp_r = abs(r) + abs(l-r)
    tmp = min(tmp_l,tmp_r)

    if min_cost > tmp:
        min_cost = tmp

print(min_cost)
### BUGGY CODE ###

def solve():
    n, m = map(int, raw_input().split())
    edge, dist = {}, {}
    for i in range(m):
        l, r, d = map(int, raw_input().split())
        if not l in edge:
            edge[l] = []
        edge[l].append(r)
        if not r in edge:
            edge[r] = []
        edge[r].append(l)
        dist[l,r] = d
        dist[r,l] = -d
    return "Yes" if ok(edge, dist, n) else "No"

def ok(edge, dist, n):
    used = [False] * (n+1)
    used[0] = True
    path = {}
    for s in range(1, n+1):
        if used[s]:
            continue
        que = [s]
        path[s, s] = 0
        used[s] = True
        while que != []:
            u = que.pop(0)
            if not u in edge:
                continue
            for v in edge[u]:
                d = path[s,u] + dist[u,v]
                if not (s,v) in path:
                    path[s,v] = d
                    used[v] = True
                    que.append(v)
                elif d != path[s,v]:
                    return False
    return True

print solve()

### FIXED CODE ###

def solve():
    n, m = map(int, raw_input().split())
    edge = {v:[] for v in range(1,n+1)}
    dist = {}
    for i in range(m):
        l, r, d = map(int, raw_input().split())
        edge[l].append(r)
        edge[r].append(l)
        dist[l,r] = d
        dist[r,l] = -d
    return "Yes" if ok(edge, dist, n) else "No"

def ok(edge, dist, n):
    used = [False] * (n+1)
    used[0] = True
    path = {}
    for s in range(1, n+1):
        if used[s]:
            continue
        que = [s]
        path[s, s] = 0
        used[s] = True
        while que:
            u = que.pop()
            for v in edge[u]:
                d = path[s,u] + dist[u,v]
                if not used[v]:
                    path[s,v] = d
                    que.append(v)
                    used[v] = True
                elif d != path[s,v]:
                    return False
    return True

print solve()