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

n=int(input())
s=[s for s in input()]
for _ in range(int(input())):
  a,b,c=input().split()
  a,b=int(a),int(b)
  if a==1:s[b-1]=c
  else:print(len(set(s[b-1:int(c)])))

### FIXED CODE ###

def segfunc(x,y):
  return set(x)|set(y)
ide_ele=set()
class SegTree():
  def __init__(self,init_val,segfunc,ide_ele):
    n=len(init_val)
    self.segfunc=segfunc
    self.ide_ele=ide_ele
    self.num=1<<(n-1).bit_length()
    self.tree=[ide_ele]*2*self.num
    for i in range(n):
      self.tree[self.num+i]=init_val[i]
    for i in range(self.num-1,0,-1):
      self.tree[i]=self.segfunc(self.tree[2*i], self.tree[2*i+1])
  def update(self,k,x):
    k+=self.num
    self.tree[k]=x
    while k>1:
      self.tree[k>>1]=self.segfunc(self.tree[k],self.tree[k^1])
      k>>=1
  def query(self,l,r):
    res=self.ide_ele
    l+=self.num
    r+=self.num
    while l<r:
      if l&1:
        res=self.segfunc(res,self.tree[l])
        l+=1
      if r&1:
        res=self.segfunc(res,self.tree[r-1])
      l>>=1
      r>>=1
    return res
n=int(input())
s=input()
q=int(input())
st=SegTree(s,segfunc,ide_ele)
for _ in range(q):
  q,c,r=input().split()
  if q=='1':st.update(int(c)-1,r)
  else:print(len(st.query(int(c)-1,int(r))))
### BUGGY CODE ###

n = int(input())
a_list = list(map(int,input().split()))
ans = []
a = 0
for i in range(n):
    if i%2 == 0:
        a += a_list[i]/2
    else:
        a -= a_list[i]/2
out = str(int(a*2))
point = a
for i in range(n-1):
    point = a_list[i]-point
    out += " "+str(int(point*2))
print(out)

### FIXED CODE ###

def main():
    n = int(input())
    a_list = list(map(int,input().split()))
    a = 0
    end = 0
    for i in range(n):
        if i%2 == 0:
            a += a_list[i]*0.5
        else:
            a -= a_list[i]*0.5

    out = str(int(a*2))
    point = a
    for i in range(n-1):
        point = a_list[i]-point
        out += " "+str(int(point*2))
    print(out)

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

n,k=map(int,input().split(' '))
h=list(map(int,input().split(' ')))
node=[0]*n
for i in range(1,n):
    x=[abs(h[i]-h[i-m])+node[i-m] for m in range(1,min(i+1,k+1))]
    node[i]=min(x)
print(node[-1])

### FIXED CODE ###

n,k=map(int,input().split(' '))
h=list(map(int,input().split(' ')))
node=[0]*n
for i in range(1,n):
    x=[abs(h[i]-h[i-m])+node[i-m] for m in range(1,min(i+1,k+1))]
    node[i]=min(x)
print(node[-1])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
max_len = len(format(max(a), "b"))
a = [format(a[i], "b") for i in range(n)]
b = [0 for _ in range(max_len)]

for i in range(n):
    for j in range(1, 1+len(a[i])):
        b[j-1] += int(a[i][-j])

result = 0
for i in range(max_len):
    r = b[i]*(n-b[i])%mod
    r = (r*2**i) %mod
    result += r
print(result%mod) 

### FIXED CODE ###

import numpy as np
mod = 10**9+7
n = int(input())
a = np.fromstring(input(), dtype = np.int64, sep = ' ')

result = 0
for i in range(60):
    count_one = int((a&1).sum())
    result += count_one*(n-count_one)*(2**i)
    a >>= 1
print(result%mod)
### BUGGY CODE ###

N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
species = list(set(A))
dic = {}
for i in species:
    dic[i] = 0
for i in A:
    dic[i] += 1
if K >= len(species):
    print(0)
else:
    ans = 0
    while len(dic) > K:
        ans += min(dic.values())
        dic.pop(min(dic, key=dic.get))
    print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
species = list(set(A))
dic = {}
for i in species:
    dic[i] = 0
for i in A:
    dic[i] += 1
if K >= len(species):
    print(0)
else:
    tmp = sorted(dic.values(),reverse=1)
    print(sum(tmp[K:]))
### BUGGY CODE ###

# For taking integer inputs.
def inp():
    return(int(input()))


N = inp()
A = []
for i in range(N):
    A.append(inp())

for i in range(N):
    temp = A[i]
    A[i] = 0
    print(max(A))
    A[i] = temp


### FIXED CODE ###

# For taking integer inputs.
def inp():
    return(int(input()))


N = inp()
A = []
i1, i2 = 0, 0

for i in range(N):
    A.append(inp())

srt = sorted(A)
m1 = srt[-1]
m2 = srt[-2]

for i in range(N):
    if A[i] == m1:
        print(m2)
    else:
        print(m1)
### BUGGY CODE ###

num, capacity = map(int, input().split())
dp = [0 for i in range(capacity + 1)]

for i in range(1, num + 1):
    weight, value = map(int, input().split())
    for w in range(capacity,-1,-1):
        if w - weight >= 0:
            dp[w] = max( dp[w - weight] + value,  dp[w] )
print(dp[capacity])

### FIXED CODE ###

def calc(num,capacity):
    dp = [0]*(capacity+1)
    for _ in range(num):
        weight, value = map(int, input().split())
        for w in range(capacity,weight - 1,-1):
            tmp = dp[w - weight] + value
            if dp[w] < tmp:
              dp[w] = tmp
    return dp[capacity]

num, capacity = map(int, input().split())
print(calc(num,capacity))
### BUGGY CODE ###

s=input()

#i桁以下の数字でmodがjの数
#dp[i][j]=

dp=[[0]*13 for _ in range(len(s))]

MOD=10**9+7

if s[0]!="?":
    dp[0][int(s[0])]=1
else:
    for i in range(10):
        dp[0][i]=1


for i in range(1,len(s)):
    si=s[i]


    if s[i]!="?":
        #数字,300のmodをtempに
        for j in range(13):
            dp[i][(j*10+int(si))%13]+=dp[i-1][j]%MOD
    else:
        for l in range(10):
            for j in range(13):
                dp[i][(j*10+l)%13]+=dp[i-1][j]%MOD
    #print(dp[i],sum(dp[i]))



print(dp[len(s)-1][5]%MOD)




        



### FIXED CODE ###

s=input()

#i桁以下の数字でmodがjの数
#dp[i][j]=

dp=[[0 for _ in range(13)] for _ in range(len(s))]

MOD=10**9+7

if s[0]!="?":
    dp[0][int(s[0])]=1
else:
    for i in range(10):
        dp[0][i]=1


for i in range(1,len(s)):
    si=s[i]


    if s[i]!="?":
        #数字,300のmodをtempに
        for j in range(13):
            dp[i][(j*10+int(si))%13]+=dp[i-1][j]%MOD
    else:
        for l in range(10):
            for j in range(13):
                dp[i][(j*10+l)%13]+=dp[i-1][j]%MOD
    #print(dp[i],sum(dp[i]))



print(dp[len(s)-1][5]%MOD)
### BUGGY CODE ###

def main():
  n=int(input())
  a=sorted(list(map(int,input().split())))

  cnt=0
  for i in range(n-2):
    for j in range(i+1,n-1):
      for k in range(j+1,n):
        if a[i]+a[j]>a[k]:
          cnt+=1
        

  print(cnt)



if __name__ == '__main__':
    main()


### FIXED CODE ###

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

l.sort()
l.append(10**9)
cnt=0
i=0
#print(l)

while i<n-2:
    j=i+1
    while j<n-1:
        LL=j+1
        RR=n-1
        #print("#",l[i],l[j],l[LL],l[RR])
        while LL<=RR:
            k=(LL+RR)//2
            if k==n:
                break
            #print(l)
            #print(i,j,LL,RR,k)
            #print(l[i]+l[j],l[k],l[k+1])
            if l[i]+l[j]>l[k] and l[i]+l[j]<=l[k+1]:
                cnt+=k-j
                break
            elif LL==RR:
                break
            elif l[i]+l[j]<=l[k]:
                RR=k
            elif l[i]+l[j]>l[k]:
                LL=k+1
            elif l[i]+l[j]<l[k] and k==j+1:
                break
        j+=1
    i+=1

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

import sys
input = sys.stdin.readline

N,Q=map(int,input().split())
C=[0]+list(map(int,input().split()))

QU=[list(map(int,input().split()))+[i] for i in range(Q)]

from operator import itemgetter
QU.sort(key=itemgetter(0))

from collections import deque

NUM=[[] for i in range(N+1)]
for i,c in enumerate(C):
    NUM[c].append(i)
NUMIND=[0]*(N+1)

# BIT(BIT-indexed tree)

LEN=N+3

BIT=[0]*(LEN+1) # 1-indexedなtree

def update(v,w): # index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v)) # 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v): # [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v)) # 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

for x in NUM[1:]:
    if x:
        update(x[0],1)

ANS=[-1]*Q

ia=1

for x,y,ind in QU:

    while ia!=x:
        update(NUM[C[ia]][NUMIND[C[ia]]],-1)
        NUMIND[C[ia]]+=1
        if NUMIND[C[ia]]<len(NUM[C[ia]]):
            update(NUM[C[ia]][NUMIND[C[ia]]],1)
        ia+=1

    #print(x,y,ind)
    #print([getvalue(i) for i in range(1,N+1)])
    ANS[ind]=getvalue(y)

print(*ANS)
        
    


### FIXED CODE ###

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from operator import itemgetter

N,Q=map(int,input().split())
C=[0]+list(map(int,input().split()))

QU=[list(map(int,input().split()))+[i] for i in range(Q)]


QU.sort(key=itemgetter(0))


# BIT(BIT-indexed tree)

LEN=N+3

BIT=[0]*(LEN+1) # 1-indexedなtree

def update(v,w): # index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v)) # 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v): # [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v)) # 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

NUM=[[] for i in range(N+1)]
for i,c in enumerate(C):
    if i==0:
        continue
    if NUM[c]==[]:
        update(i,1)
    NUM[c].append(i)
    
NUMIND=[0]*(N+1)

ANS=[-1]*Q

ia=1

for x,y,ind in QU:

    while ia!=x:
        update(NUM[C[ia]][NUMIND[C[ia]]],-1)
        NUMIND[C[ia]]+=1
        if NUMIND[C[ia]]<len(NUM[C[ia]]):
            update(NUM[C[ia]][NUMIND[C[ia]]],1)
        ia+=1

    #print(x,y,ind)
    #print([getvalue(i) for i in range(1,N+1)])
    ANS[ind]=getvalue(y)

sys.stdout.write(" ".join(map(str,ANS))+"\n")
### BUGGY CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
score = [int(K) for __ in range(N)]

for i in range(Q):
    for m in range(N):
        score[m] = score[m]-1
    score[A[i]-1] = score[A[i]-1]+1
for k in range(N):
    if score[k] <= 0:
        print("No")
    else:
        print("Yes")


### FIXED CODE ###

n, k, q = map(int, input().split())
p = k-q
l = [p]*n
for i in range(q):
    a = int(input())
    l[a-1] += 1
for k in range(n):
    print("Yes" if l[k]>0 else "No")
### BUGGY CODE ###

import numpy as np 

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a, b):
    return (a * b)//gcd(a,b)

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

lcm_a = 1

for i in range(N):
    lcm_a = lcm(lcm_a,A[i])

B = np.array([])
for i in range(N):
    B = np.append(B,lcm_a//A[i])

mod = int(1e9+7)
print(int((np.sum(B)%mod)))

### FIXED CODE ###

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

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a, b):
    return (a * b)//gcd(a,b)

lcm_a = 1

for i in range(N):
    lcm_a = lcm(lcm_a,A[i])

ans = 0
for i in range(N):
    ans += lcm_a//A[i]

mod = int(1e9+7)

print(ans%mod)
### BUGGY CODE ###

N,K,*A=map(int,open(0).read().split())
a=1
while K>0:
 if K&1:a=A[a-1]
 A=[A[A[i]-1] for i in range(N)]
 K>>=1
print(a)

### FIXED CODE ###

def main():
    N, K, *A = map(int, open(0).read().split())
    visited = [-1]*N
    pos = A[0]
    visited[0] = 0
    visited[pos - 1] = 1
    step = 2
    order = 0
    start = 0
    step_to_start = 0
    while True:
        pos = A[pos - 1]
        if visited[pos - 1] == -1:
            visited[pos - 1] = step
        else:
            step_to_start = visited[pos - 1]
            order = step - step_to_start
            start = pos
            break
        step += 1
    # print(start, step_to_start, order)

    if K <= step_to_start:
        ans = 1
        for i in range(K):
            ans = A[ans - 1]
        print(ans)
        return
    remain = (K - step_to_start) % order
    ans = start
    for i in range(remain):
        ans = A[ans - 1]
    print(ans)

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

import numpy as np
n,k = map(int,input().split())
A = np.array(list(map(int,input().split())))
for _ in [0]*k:
  new_A = np.array([0]*n)
  for i in range(n):
    left = i - A[i]
    right = i + A[i] + 1
    if left < 0:
      new_A[:right] += 1
      if right >= n:
        new_A += 1
    else:
      if right >= n:
        new_A[left:] += 1
      else:
        new_A[left:right] += 1
  A = new_A
   
for a in A:
  print(a, end=" ")
      
      
      

### FIXED CODE ###

# 累積和
import numpy as np
from numba import njit

@njit(cache=True)
def loop(n, k, A):
    for _ in [0] * k:
        B = np.zeros(n + 1, dtype=np.int64)
        for i in range(n):
            left = max(0, i - A[i])
            right = min(n, i + A[i] + 1)
            B[left] += 1
            B[right] -= 1
        A = np.cumsum(B)[:-1]
        #print(A)
        if np.all(A == n):
            return A
            break

    return A


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    A = np.array(a, dtype=np.int64)
    A = loop(n, k, A)
    print(*A)


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

N, W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N)]
for i in range(N):
    for w in range(W+1):
        dp[i][w] = dp[i-1][w]
        if w-wv[i][0] >= 0:
            dp[i][w] = max(dp[i][w],dp[i-1][w-wv[i][0]]+wv[i][1])
print(dp[-1][-1])

### FIXED CODE ###

N, W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N)]
for i in range(N):
    for w in range(W+1):
        dp[i][w] = dp[i-1][w]
        if w-wv[i][0] >= 0:
            dp[i][w] = max(dp[i][w],dp[i-1][w-wv[i][0]]+wv[i][1])
print(dp[-1][-1])
### BUGGY CODE ###

n = int(input())
ss = input()

max_cnt = 0
for i in range(1, n):
    cnt = 0
    for j in range(n - i):
        if ss[j] == ss[j + i]:
            cnt += 1
            max_cnt = max(cnt, max_cnt)
            if cnt == i:
                break
        else:
            cnt = 0

print(max_cnt)

### FIXED CODE ###

n = int(input())
ss = input()

max_cnt = 0
for i in range(1, n):
    cnt = 0
    for j in range(n - i):
        if ss[j] == ss[j + i]:
            cnt += 1
            max_cnt = max(cnt, max_cnt)
            if cnt == i:
                break
        else:
            cnt = 0

print(max_cnt)
### BUGGY CODE ###

N,M,Q = map(int,input().split())

ans = [[0]*N for _ in range(N)]

for _ in range(M):
        L,R = map(int,input().split())
        for i in range(N):
                for j in range(i,N):
                        if i<=(L-1) and (R-1)<=j:
                                ans[i][j] += 1
for _ in range(Q):
        p,q = map(int,input().split())
        print(ans[p-1][q-1])

### FIXED CODE ###

N,M,Q = map(int,input().split())

Section = [[0]*N for _ in range(N)]
for _ in range(M):
    L,R = map(int,input().split())
    Section[L-1][R-1] += 1

Sum = [[0]*(N+1) for _ in range(N+1)]
for i in range(N):
    for j in range(N):
        Sum[i+1][j+1] = Sum[i][j+1]+Sum[i+1][j]-Sum[i][j]+Section[i][j]

Ans = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(i,N):
        Ans[i][j] = Sum[j+1][j+1]-Sum[i][j+1]

for _ in range(Q):
    p,q = map(int,input().split())
    print(Ans[p-1][q-1])
### BUGGY CODE ###

import math
import sys
n, m = map(int, input().split())
s = list(input())
t = list(input())
a = (n*m)//math.gcd(n, m)
b0 = [i*(a//n)+1 for i in range(n)]
b1 = [i*(a//m)+1 for i in range(m)]

for j, i in enumerate(b0):
    if i in b1:
        if s[b0.index(i)] != t[b1.index(i)]:
            print(-1)
            sys.exit()
    
for j, i in enumerate(b1):
    if i in b0:
        if s[b0.index(i)] != t[b1.index(i)]:
            print(-1)
            sys.exit()
print(a)


### FIXED CODE ###

import math
import sys
n, m = map(int, input().split())
s = list(input())
t = list(input())
a = (n*m)//math.gcd(n, m)
b0 = [i*(a//n)+1 for i in range(n)]
b1 = [i*(a//m)+1 for i in range(m)]
b2 = set(b0)
b3 = set(b1)

for j, i in enumerate(b0):
    if i in b3:
        if s[j] != t[b1.index(i)]:
            print(-1)
            sys.exit()
            
for j, i in enumerate(b1):
    if i in b2:
        if s[b0.index(i)] != t[j]:
            print(-1)
            sys.exit()
print(a)
### BUGGY CODE ###

a,b,n= map(int,input().split())
t=[]
for k in range (n+1):
  s= int(a*k/b)-a*int(k/b)
  t.append(s)
  if k>=b:
    break
print(max(t))
  


### FIXED CODE ###

import math
a, b, n = map(int, input().split())

if n < b-1:
    x = n
else:
    x = b-1

m = math.floor(a*x/b) - a*math.floor(x/b)
print(m)
### BUGGY CODE ###

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

answer=-float("inf")
for i in range(N,2*N+1):
  alist1=alist[:i]
  alist2=alist[i:]
  #print(alist1,alist2)
  
  alist1.sort(reverse=True)
  alist2.sort()
  maxn_a1=sum(alist1[:N])
  minn_a2=sum(alist2[:N])
  #print(maxn_a1,minn_a2)
  answer=max(answer,maxn_a1-minn_a2)

print(answer)

### FIXED CODE ###

import heapq
N=int(input())
alist=list(map(int,input().split()))

sum1=0
hq1=[]
for i in range(N):
  sum1+=alist[i]
  heapq.heappush(hq1,alist[i])
sum1_list=[sum1]
for i in range(N,2*N):
  heapq.heappush(hq1,alist[i])
  min_s1=heapq.heappop(hq1)  
  sum1+=alist[i]-min_s1
  sum1_list.append(sum1)
#print(sum1_list)  
  
alist_rev=alist[::-1]  
sum2=0
hq2=[]
for i in range(N):
  sum2+=alist_rev[i]
  heapq.heappush(hq2,-alist_rev[i])
sum2_list=[sum2]
for i in range(N,2*N):
  heapq.heappush(hq2,-alist_rev[i])
  max_s2=-heapq.heappop(hq2)
  sum2+=alist_rev[i]-max_s2
  sum2_list.append(sum2)
sum2_list.reverse()
#print(sum2_list)  

answer=-float("inf")
for i in range(N+1):
  answer=max(answer,sum1_list[i]-sum2_list[i])

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

H, W = (int(i) for i in input().split())
#e = [[i for i in input().split()] for i in range(H)]
e = []
for x in range(H):
    e.append(list(input()))

maxcount = 1
for i in range(H):
    for j in range(W):
        #print("start", i, j)
        count = 1
        if e[i][j] == "#":
            continue
        for k in range(i+1, H):
            #print(e[k][j], k, j)
            if e[k][j] == "#":
                #print(k, j)
                break
            else:
                count +=1
        #print("1 ", count)
        for l in range(1, i+1):
            #print(e[i-l][j], i-l, j)
            if e[i-l][j] == "#":
                break
            else:
                count += 1
        #print("2 ", count)
        for m in range(j+1, W):
            if e[i][m] == "#":
                break
            else:
                count +=1
        #print("3 ",count)
        for n in range(1, j+1):
            if e[i][j-n] == "#":
                break
            else:
                count +=1
        if maxcount < count:
            maxcount = count
        #print(count)
print(maxcount)


### FIXED CODE ###

import sys
input = sys.stdin.readline

H, W = (int(i) for i in input().split())
#e = [[i for i in input().split()] for i in range(H)]
e = []
for x in range(H):
    e.append(list(input()))

L = [[0] * W for i in [1] * H]
R = [[0] * W for i in [1] * H]
D = [[0] * W for i in [1] * H]
U = [[0] * W for i in [1] * H]
totalmax = 0

for i in range(H):
    for j in range(W):
        if e[i][j] == ".":
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1
        if e[i][W-1-j] == ".":
            #print(i, W-1-j)
            if W-1-j == W-1:
                R[i][W-1-j] = 1
            else:
                R[i][W-1-j] = R[i][W-j] + 1
                #print(R[i][W-j-2])
            #print(R[i][W-j-1])
        if e[i][j] == ".":
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1
        if e[H-1-i][j] == ".":
            if H-1-i == H-1:
                D[H-1-i][j] = 1
            else:
                D[H-1-i][j] = D[H-i][j] + 1

for i in range(H):
    #print("")
    for j in range(W):
        totalmax = max(totalmax, L[i][j]+R[i][j]+D[i][j]+U[i][j]-3)
        #print(L[i][j],R[i][j], D[i][j], U[i][j], end="/")



print(totalmax)
### BUGGY CODE ###

from sys import stdin
import math

point = 0

r,g,b,n = [int(x) for x in stdin.readline().rstrip().split()]
for i in range(n//r+1):
    for j in range(n//g+1):
        if n-r*i-g*j >= 0:
            if (n-r*i-g*j)%b == 0:
                point += 1

print(point)

### FIXED CODE ###

from sys import stdin
import math

point = 0

r,g,b,n = [int(x) for x in stdin.readline().rstrip().split()]
for i in range(n//r+1):
    for j in range(n//g+1):
        if n-r*i-g*j >= 0:
            if (n-r*i-g*j)%b == 0:
                point += 1

print(point)
### BUGGY CODE ###

import sys
def main():
    input = sys.stdin.readline
    def inputs():
        return (int(x) for x in input().split())
    N,M = inputs()
    E={i:[] for i in range(1,N+1)}
    for i in range(M):
        L,R,D = inputs()
        E[L].append((R,D))
        E[R].append((L,-D))
    visited = {i: False for i in E.keys()}
    dis = [0]*(N+1)
    while False in visited.values():
        stk = [(list(visited.values()).index(False) + 1, -1, 0)]
        flag = True
        while stk:
            v, p, d = stk.pop()
            #print(v,p)
            if visited[v]:
                if dis[v]!=dis[p]+d:
                    print("No")
                    exit()
                continue
            visited[v] = True
            dis[v]=dis[p]+d
            for u,d in E[v]:
                if u != p:
                    stk.append((u,v,d))
    print("Yes")
main()

### FIXED CODE ###

import sys
def main():
    input = sys.stdin.readline
    def inputs():
        return (int(x) for x in input().split())
    N,M = inputs()
    E={i:[] for i in range(1,N+1)}
    for i in range(M):
        L,R,D = inputs()
        E[L].append((R,D))
        E[R].append((L,-D))
    visited = {i: False for i in range(1,N+1)}
    dis = [0]*(N+1)
    for i in range(1,N+1):
        if not visited[i]:
            stk = [( i, -1, 0)]
            while stk:
                v, p, d = stk.pop()
                #print(v,p)
                if visited[v]:
                    if dis[v]!=dis[p]+d:
                        print("No")
                        exit()
                    continue
                visited[v] = True
                dis[v]=dis[p]+d
                for u,d in E[v]:
                    if u != p:
                        stk.append((u,v,d))
    print("Yes")
main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)


def dp_func(i):

    if dp[i] < float('inf'):return dp[i]

    if i==0 :return 0
    #print(i)

    for _ in range(1,K+1):
        if i==1:
            a[i].append(abs(h[i]-h[i-1]))
            break

        if((i-_) >= 0):
            #print(i,_,i-_,h[i],h[i-_])
            a[i].append((dp_func(i-_) + abs(h[i]-h[i-_])))


    #print(i,a[i])
    dp[i] = min(a[i])
    return dp[i]



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

dp = [float('inf')]*N
dp[0] = 0
a = [[] for _ in range(N)]

print(dp_func(N-1))
#print(dp)


### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

n, k = map(int, input().split())
h = [int(i) for i in input().split()]
h = np.array(h)

dp = np.zeros(n, dtype=int)

#print(dp)
#print(h)

for i in range(1,n):
    start = max(0,i-k)
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))

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

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

a = []
for i in range(m):
    a.append(int(input()))

mod = 1000000007

memo = [0]*(n+1)
memo[1] = 1

for i in range(1, n+1):
    if i in a:
        memo[i] = 0
    elif i <= 2:
        memo[i] = memo[i-1] + 1
    else:
        memo[i] = memo[i-1] + memo[i-2]
print(memo[-1]%mod)

### FIXED CODE ###

n, m = list(map(int, input().split()))
a = []
for i in range(m):
    a.append(int(input()))

mod = 1000000007

memo = [-1]*(n+1)
memo[0] = 0

for k in range(m):
    memo[a[k]] = 0

for i in range(1, n+1):
    if memo[i] != -1:
        pass 
    elif i <= 2:
        memo[i] = memo[i-1] + 1
    else:
        memo[i] = memo[i-1] + memo[i-2]
print(memo[-1]%mod)