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

import sys
sys.setrecursionlimit(1000000)
from collections import deque

def bfs(sx,sy,gx,gy):
    d = [[float("inf")] * w for i in range(h)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gx][gy]

h,w=map(int,input().split())
s = [list(input()) for i in range(h)]
ans=0
memo=[[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            for k in range(i,h):
                for l in range(w):
                    if s[k][l]=='.':
                        ans = max(ans,bfs(i,j,k,l))
                        
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
from collections import deque


h,w=map(int,input().split())
s = [list(input()) for i in range(h)]

def bfs(sx,sy):
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    d = [[-1]*w for i in range(h)]
    q = deque()
    q.append((sx,sy))
    d[sx][sy] = 0
    while q:
        x,y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if  0<= nx < h and 0 <= ny < w and d[nx][ny]==-1 and s[nx][ny]=='.':
                q.append((nx,ny))
                d[nx][ny] = d[x][y]+1
    return max([max(i) for i in d])

count = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            count  = max(count, bfs(i,j))
print(count)
### BUGGY CODE ###

from collections import deque

def main():
    n, m = map(int,raw_input().split())
    A = [[] for i in xrange(n)]
    for i in xrange(m):
        s, t = map(int,raw_input().split())
        A[s].append(t)
        A[t].append(s)

    q = input()
    a =[0]*q
    for i in xrange(q):
        s, t = map(int,raw_input().split())
        c = bfs(n,A,s,t)
        if c[t] == -1:
            a[i] = 'no'
        else:
            a[i] = 'yes'

    for i in a:
        print i
        
def bfs(n,A,s,t):
    color = [-1]*n
    Q = deque([s])
    while(True):
        if len(Q)==0:
            break
        u = Q.popleft()
        for i in A[u]:
            if i == t:
                color[t] = 1
                break
            elif color[i] == -1:
                color[i] = 0
                Q.append(i)
        color[u] = 1
    return color

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque

def main():
    n, m = map(int,raw_input().split())
    A = [[] for i in xrange(n)]
    for i in xrange(m):
        s, t = map(int,raw_input().split())
        A[s].append(t)
        A[t].append(s)

    g = [-1]*n
    x = 0
    for i in xrange(n):
        if g[i] == -1:
            g = bfs(n,A,i,g,x)
            x += 1
            
    q = input()
    a =[0]*q
    for i in xrange(q):
        s, t = map(int,raw_input().split())
        if g[s] == g[t]:
            a[i] = 'yes'
        else:
            a[i] = 'no'
    for i in a:
        print i
        
def bfs(n,A,s,color,x):
    Q = deque([s])
    while(len(Q)!=0):
        u = Q.popleft()
        for i in A[u]:
            if color[i] == -1:
                Q.append(i)
        color[u] = x
    return color

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

N, M = list(map(int, input().split()))
PY = [list(map(int, input().split())) for i in range(M)]
PYS = sorted(PY, key=lambda x: (x[0], x[1]))
d = {}
for i in PYS:
    if i[0] in d:
        d[i[0]].append(i[1])
    else:
        d[i[0]] = [i[1]]
for i in PY:
    print(str(i[0]).zfill(6) + str(d[i[0]].index(i[1]) + 1).zfill(6))

### FIXED CODE ###

N, M = list(map(int, input().split()))
PY = [list(map(int, input().split())) + [i, 0] for i in range(M)] 
d = {}
for i in sorted(PY, key=lambda x: x[1]):
    if i[0] in d:
        d[i[0]] += 1
    else:
        d[i[0]] = 1
    i[3] = d[i[0]]
for i in PY:
    print(str(i[0]).zfill(6) + str(i[3]).zfill(6))
### BUGGY CODE ###

N=int(input())
for n in range(1,N+1):
    s=0
    for x in range(1,41):  
        for y in range(x,41):
            for z in range(y,41):
                fn=x*x+y*y+z*z+x*y+y*z+z*x
                if fn==n:
                    if x==y and x==z:
                        s=s+1
                    if x<y and y==z:
                        s=s+3
                    if x==y and y<z:
                        s=s+3              
                    if x<y and y<z:
                        s=s+6    
    print(s)      

### FIXED CODE ###

N=int(input())
ans=[0]*(N+1)
for x in range(1,101):  
    for y in range(1,101):
        for z in range(1,101):
            fn=x**2+y**2+z**2+x*y+y*z+z*x
            if fn>N:
                break
            else:
                ans[fn]=ans[fn]+1
for n in range(1,N+1):
    print(ans[n])
### BUGGY CODE ###

import math

X = int(input())

ans = None

while ans is None:
  for i in range(math.ceil(abs(X)**0.2)+1, 0, -1):
    for j in range(math.ceil(abs(X)**0.2)+1, 0, -1):
      if i ** 5 - j ** 5 == X:
        ans = (i, j)
      elif (i*-1) ** 5 - j ** 5 == X:
        ans = (-i, j)
      elif i ** 5 - (j*-1) ** 5 == X:
        ans = (i, -j)
      elif (i*-1) ** 5 - (j*-1) ** 5 == X:
        ans = (-i, -j)
print(ans[0],ans[1])

### FIXED CODE ###

X = int(input())
 
ans = None
 
for i in range(120):
  for j in range(120):
    if i ** 5 - j ** 5 == X:
      ans = (i, j)
    elif (i*-1) ** 5 - j ** 5 == X:
      ans = (-i, j)
    elif i ** 5 - (j*-1) ** 5 == X:
      ans = (i, -j)
print(ans[0],ans[1])
### BUGGY CODE ###

#!/usr/bin/env python3

from itertools import product


def main():
    n, m = list(map(int, input().split()))
    a = []
    b = []
    for _ in range(m):
        ai, bi = list(map(int, input().split()))
        a.append(ai-1)
        b.append(bi-1)

    # 不便さのMAX
    result = [n * (n-1) // 2]

    chained = [{i} for i in range(n)]
    for j in range(m):
        i = m - 1 - j
        ai = a[i]
        bi = b[i]
        if ai not in chained[bi]:
            next_val = result[-1]
            for ac, bc in product(chained[ai], chained[bi]):
                chained[ac].add(bc)
                chained[bc].add(ac)
                next_val -= 1
            result.append(next_val)
        else:
            result.append(result[-1])
    result.reverse()
    for v in result[1:]:
        print(v)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3

from itertools import product
import sys
sys.setrecursionlimit(100000)

def get_label(labels, target):
    if labels[target] == -1:
        return target
    else:
        temp = get_label(labels, labels[target])
        labels[target] = temp
        return temp


def main():
    n, m = list(map(int, input().split()))
    a = []
    b = []
    for _ in range(m):
        ai, bi = list(map(int, input().split()))
        a.append(ai-1)
        b.append(bi-1)

    # 不便さのMAX
    result = [n * (n-1) // 2]
    labels = [-1] * n
    groups = {}
    for i in range(n):
        groups[i] = 1

    for j in range(m):
        i = m - 1 - j
        ai = a[i]
        bi = b[i]
        label_a = get_label(labels, ai)
        label_b = get_label(labels, bi)
        if label_a != label_b:
            next_val = result[-1]
            next_val -= groups[label_a] * groups[label_b]
            result.append(next_val)
            groups[label_a] += groups[label_b]
            labels[label_b] = label_a
            del groups[label_b]
        else:
            result.append(result[-1])

    result.reverse()
    for v in result[1:]:
        print(v)

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

from sys import stdin
input = stdin.readline

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

### FIXED CODE ###

from sys import stdin
input = stdin.readline
from fractions import gcd
 
mod = 10**9+7
 
n = int(input())
a = list(map(int,input().split()))
d = 1
for i in range(n):
  d *= a[i] // gcd(a[i],d)
ans = 0
for i in range(n):
  ans += d//a[i]
 
print(ans%mod)
### BUGGY CODE ###

from collections import Counter
N = int(input())
s= input()

D = N
for i in range(N):
    L,R = s[:i],s[i+1:]
    n1,n2 = Counter(L),Counter(R)
    num = n1["W"] + n2["E"]
    if num < D:
        D = num
print(D)

### FIXED CODE ###

from collections import Counter
N = int(input())
s= input()

D = Counter(s[1:])["E"]
nums = [D]
for i in range (1,N):
    temp = nums[-1]
    if s[i-1] == "W":
        temp += 1
    if s[i] == "E":
        temp -= 1
    nums.append(temp)

print(min(nums))
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
p = 1000000007
max_n = len(bin(max(A)))-2
mask = 1
s = 0
for i in range(max_n):
  s0 = 0
  s1 = 0
  for j in range(N):
    s0 += (A[j] & (mask << i)) >> i
    s1 += (~(A[j] | ~(mask << i))) >> i
  s += ((2**i)*s0*s1)%p
print(s%p)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
p = 1000000007
max_n = len(bin(max(A)))-2
mask = 1
s = 0
for i in range(max_n):
  s0 = 0
  s1 = 0
  for j in range(N):
    s0 += (A[j] & (mask << i)) >> i
    s1 += (~(A[j] | ~(mask << i))) >> i
  s += ((2**i)*s0*s1)%p
print(s%p)
### BUGGY CODE ###

def resolve():
    MAX_COST = 10**9
    num_steps,k = map(int,input().split())

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

    min_cost = [MAX_COST for i in range(num_steps)]
    min_cost[0] = 0
    min_cost[1] = abs(steps[1] - steps[0])
    
    for si in range(2,num_steps):
        for ki in range(1,min(k,si)+1):
            min_cost[si] = min(min_cost[si - ki] + abs(steps[si-ki] - steps[si]),min_cost[si])        

    print(min_cost[-1])
    
resolve()

### FIXED CODE ###

def resolve():
    MAX_COST = 10**9
    num_steps,k = map(int,input().split())

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

    min_cost = [MAX_COST for i in range(num_steps)]
    min_cost[0] = 0
    min_cost[1] = abs(steps[1] - steps[0])
    
    for si in range(2,num_steps):
        for ki in range(1,min(k,si)+1):
            min_cost[si] = min(min_cost[si - ki] + abs(steps[si-ki] - steps[si]),min_cost[si])        

    print(min_cost[-1])
    
resolve()
### BUGGY CODE ###

n = int(input())
rec = {}
for i in range(n):
    a = int(input())
    rec[i + 1] = a

i = 1
rec2  = [1]
num = 0
while i != 2 and num < n:
    i = rec[i]
    if i not in rec2:
        rec2.append(i)
        num += 1
    else:
        num = -1
        break

if num == n:
    print(-1)
else:
    print(num)
    

### FIXED CODE ###

n = int(input())
rec = {}
for i in range(n):
    a = int(input())
    rec[i + 1] = a

i = 1
rec2 = [1]
num = 0
while i != 2 and num < n:
    i = rec[i]
    num += 1

if num == n:
    print(-1)
else:
    print(num)
### BUGGY CODE ###


import heapq
X,Y,Z,K = map(int,input().split())
As = sorted(list(map(int,input().split())),reverse=True)
Bs = sorted(list(map(int,input().split())),reverse=True)
Cs = sorted(list(map(int,input().split())),reverse=True)
q = []
heapq.heapify(q)
heapq.heappush(q,(-(As[0]+Bs[0]+Cs[0]),0,0,0))
list_ijk = [(0,0,0)]
for i in range(K):
    # valueのマイナス値の小さい順にpop(優先度付きqueue)
    v,i,j,k = heapq.heappop(q)
    if i < len(As)-1 and (i+1,j,k) not in list_ijk:
        heapq.heappush(q,(-(As[i+1]+Bs[j]+Cs[k]),i+1,j,k))
        list_ijk.append((i+1,j,k))
    if j < len(Bs)-1 and (i,j+1,k) not in list_ijk:
        heapq.heappush(q,(-(As[i]+Bs[j+1]+Cs[k]),i,j+1,k))
        list_ijk.append((i,j+1,k))
    if k < len(Cs)-1 and (i,j,k+1) not in list_ijk:
        heapq.heappush(q,(-(As[i]+Bs[j]+Cs[k+1]),i,j,k+1))
        list_ijk.append((i,j,k+1))
    print(-v)    


### FIXED CODE ###

# どうやって自明な条件で計算量を落としていくか
# 不等式に注目。pythonが耐えるのは10^6程度
X,Y,Z,K = map(int,input().split())
As = sorted(list(map(int,input().split())),reverse=True)
Bs = sorted(list(map(int,input().split())),reverse=True)
Cs = sorted(list(map(int,input().split())),reverse=True)

# ABでソート
AB = []
for A in As:
    for B in Bs:
        AB.append(A+B)
ABs = sorted(AB,reverse=True)

# その中からK番目まで
ABC = []
for i in range(min(len(ABs),K)):
    for C in Cs:
        ABC.append(ABs[i]+C)

ABCs = sorted(ABC,reverse=True)
for i in range(K):
    print(ABCs[i])
### BUGGY CODE ###

n = int(input())
#2
a = [int(i) for i in input().split()]
#3 5 2
b = [int(i) for i in input().split()]
#4 5

sm = sum(b)

for i in range(n):
	c = a.copy()
	#print(a,b)
	#ans += min(c[i],b[i])
	a[i] -= min(c[i],b[i])
	b[i] -= min(c[i],b[i])
	#print(a,b)
	#ans += min(c[i+1],b[i])
	a[i+1] -= min(c[i+1],b[i])
	b[i] -= min(c[i+1],b[i])
	
print(sm-sum(b))

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

sa = sum(a)

for i,b in enumerate(b):
	c = min(a[i],b)
	a[i] -= c
	a[i+1] -= min(a[i+1],b-c)

print(sa-sum(a))
### BUGGY CODE ###

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
A =sorted(A)
C = Counter(A)
S=set(A)

use=[True]*N
ans=0
for i in range(N):
    if use[i]:
        if C[A[i]]==1:
            ans+=1
        for j in range(i,N):
            if A[j]%A[i]==0:
                use[j]=False
print(ans)



### FIXED CODE ###

from collections import Counter
N =int(input())
A = list(map(int,input().split()))

A = sorted(A)
C = Counter(A)
S=set(A)

dp=[True]*(A[-1]+1)

ans=0
for i in range(1,A[-1]+1):
    if dp[i]:
        if i in S:
            for j in range(i,A[-1]+1,i):
                dp[j]=False
            if C[i]==1:
                ans+=1
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
if m % n == 0:
    print(m // n)
else:
    gcd = m // n
    for i in range(gcd, 0, -1):
        if m % i == 0:
            j = m // gcd
            if j >= n:
                print(i)
                exit()


### FIXED CODE ###

import math
n, m = map(int, input().split())
root_m = int(math.sqrt(m))
ans = 1
for a in range(1, root_m):
    # print(a, ans)
    if m % a == 0:
        b = m // a
        if a * n <= m:
            ans = max(ans, a)
        if b * n <= m:
            ans = max(ans, b)
print(ans)
### BUGGY CODE ###

import sys

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

for i, num in enumerate(As):
    tmp = As.copy()
    del tmp[i]
    if num in tmp:
        print('NO')
        sys.exit(0)

print('YES')

### FIXED CODE ###

import sys

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

As.sort()
for i in range(N):
    for j in range(i + 1, N):
        if As[i] == As[j]:
            print('NO')
            sys.exit(0)
        if As[j] > As[i]:
            break

print('YES')
### BUGGY CODE ###

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

for _ in range(Q):
    q = input()
    if len(q) == 1:
        S = list(S)
        S.reverse()
        S = "".join(S)
    else:
        T, F, C = q.split()
        if int(F) == 1:
            S = C + S
        else:
            S = S + C

print(S)


### FIXED CODE ###

from collections import deque

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

d = deque(S)
head = "l"

for _ in range(Q):
    q = input()
    if len(q) == 1:
        if head == "l":
            head = "r"
        else:
            head = "l"
    else:
        T, F, C = q.split()
        if int(F) == 1:
            if head == "l":
                d.appendleft(C)
            else:
                d.append(C)
        else:
            if head == "l":
                d.append(C)
            else:
                d.appendleft(C)
if head == "l":
    print("".join(list(d)))
else:
    print("".join(list(d)[::-1]))
### BUGGY CODE ###

N=int(input())
A=list(map(int, input().split()))
s=0
for num in range(1, N+1):
  count = 0
  for i in range(s, N-1):
    if A[i] == num:
      count += 1
  s+=count
  print(count)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
A=sorted(A)
s=0
for num in range(1, N+1):
  count = 0
  for i in range(s, N-1):
    if A[i] == num:
      count += 1
    else:
      break
  s+=count
  print(count)
### BUGGY CODE ###

# coding: utf-8
import numpy as np

n = int(input())
numlist = list(map(int, input().split()))
ans = 1;

for i in numlist:
    if i == 0:
        ans = 0
        break
    ans *= i
    
if ans > 10**18:
    ans = -1

print(ans)

### FIXED CODE ###

# coding: utf-8
import numpy as np
 
n = int(input())
numlist = list(map(int, input().split()))
ans = 1;

if 0 in numlist:
    ans = 0
else:
    for i in numlist:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
 
print(ans)
### BUGGY CODE ###

from itertools import combinations
mod = 10**9+7

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

ans = 0

for i,j in combinations(li,2):
    ans += (i*j)%mod
    ans = ans%mod
print(ans)

### FIXED CODE ###

n = int(input())
li = list(map(int,input().split()))
mod = 10**9+7

S = sum(li)
li2 = [x**2 for x in li]
S2 = sum(li2)

print((S**2-S2)//2%mod)
### BUGGY CODE ###

N=int(input())
S=input()
#print(N,S)

count=0


for n1 in range(10):
 cond=0
 for i in range(N-2):
   if n1==int(S[i]):
      p1=i
      cond=1
      break
 if cond==1:
  for n2 in range(10):
    for j in range(p1+1,N-1):
      if n2==int(S[j]):
        p2=j
        cond=2
        break
    if cond==2:
     for n3 in range(10):
      for k in range(p2+1,N):
        if n3==int(S[k]):
          count+=1
         # print(n1,n2,n3,S[p1]+S[p2]+S[k])
          cond=0
          break
      
              
print(count)


### FIXED CODE ###

N=int(input())
S=input()
#print(N,S)

count=0


for n1 in range(10):
 cond=0
 for i in range(N-2):
   if n1==int(S[i]):
      p1=i
      cond=1
      break
 if cond==1:
  for n2 in range(10):
    for j in range(p1+1,N-1):
      if n2==int(S[j]):
        p2=j
        cond=2
        break
    if cond==2:
     for n3 in range(10):
       #print(n3,S[p2+1:],str(n3) in S[p2+1:] )
       if str(n3) in S[p2+1:]:
        #print(n1,n2,n3)
        count+=1
        cond=0
      
              
print(count)
### BUGGY CODE ###

from decimal import *
getcontext().prec = 100000000000000
a,b,c=map(int,input().split())
if Decimal(a).sqrt()+Decimal(b).sqrt()<Decimal(c).sqrt():
  print('Yes')
else:
  print('No')


### FIXED CODE ###

import math
a,b,c=map(int,input().split())
if 4*a*b<(c-a-b)*(c-a-b) and c>a+b:
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

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

blue_count = 0
while n != 0:
    # 青
    if n >= a:
        n -= a
        blue_count += a
    else:
        blue_count += n
        n = 0
    if n >= b:
        n -= b
    else:
        n = 0

print(blue_count)


### FIXED CODE ###

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

blue_count = a * (n // (a + b))
n -= (a + b) * (n // (a + b))
if n >= a:
    blue_count += a
else:
    blue_count += n
print(blue_count)
### BUGGY CODE ###

n = int(input())
d = [int(i) for i in input().split()]

if d[0] != 0 or d.count(0) > 1:
    print(0)
    exit()

ans = 1
for i in range(1, max(d) + 1):
    ans *= d.count(i - 1) ** d.count(i)

print(ans % 998244353)

### FIXED CODE ###

from collections import Counter

n = int(input())
d = [int(i) for i in input().split()]
c = Counter(d)

if d[0] != 0 or c[0] > 1:
    print(0)
    exit()

ans = 1
for i in range(1, len(c) + 1):
    ans *= c[i - 1] ** c[i]

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

S = input()
mod = 10**9+7

N = len(S)
A1,A2,C1,C2 = [1]*N,[1]*N,[1]*N,[1]*N
a,aa = 0,0
c,cc = 0,0
for i in range(1,N):
    if S[i-1]=="A":
        a += 1
    elif S[i-1]=="?":
        aa += 1
    A1[i],A2[i] = a,aa
for i in range(1,N):
    if S[N-1-i+1]=="C":
        c += 1
    elif S[N-1-i+1]=="?":
        cc += 1
    C1[N-1-i] = c
    C2[N-1-i] = cc

Ans = 0
for i in range(1,N-1):
    if S[i] in ("B","?"):
        ta,tc = 0,0
        if A2[i]==0:
            ta = A1[i]
        else:
            ta = (3**A2[i])*A1[i] + 3**(A2[i]-1)*A2[i]
            ta %= mod
        if C2[i]==0:
            tc = C1[i]
        else:
            tc = (3**C2[i])*C1[i] + 3**(C2[i]-1)*C2[i]
            tc %= mod
        Ans += ta*tc
        Ans %= mod

print(Ans)

### FIXED CODE ###

S = input()
mod = 10**9+7

N = len(S)
A1,A2,C1,C2 = [1]*N,[1]*N,[1]*N,[1]*N
a,aa = 0,0
c,cc = 0,0
for i in range(1,N):
    if S[i-1]=="A":
        a += 1
    elif S[i-1]=="?":
        aa += 1
    A1[i],A2[i] = a,aa
for i in range(1,N):
    if S[N-1-i+1]=="C":
        c += 1
    elif S[N-1-i+1]=="?":
        cc += 1
    C1[N-1-i] = c
    C2[N-1-i] = cc

Ans = 0
for i in range(1,N-1):
    if S[i] in ("B","?"):
        ta,tc = 0,0
        if A2[i]==0:
            ta = A1[i]
        else:
            ta = pow(3,A2[i],mod)*A1[i] + pow(3,A2[i]-1,mod)*A2[i]
        if C2[i]==0:
            tc = C1[i]
        else:
            tc = pow(3,C2[i],mod)*C1[i] + pow(3,C2[i]-1,mod)*C2[i]
        Ans += ta*tc
        Ans %= mod

print(Ans)
### BUGGY CODE ###

import numpy as np


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    # dp = [float('inf')] * n
    dp = np.full(n, float('inf'))
    dp[0] = 0
    for i in range(n):
        for j in range(1, min(k, n - i - 1) + 1):
            dp[i + j] = min(
                dp[i + j],
                dp[i] + abs(h[i] - h[i + j]) )
    print(int(dp[-1]))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import numpy as np


def main():
    n, k = map(int, input().split())
    height = np.fromstring(input(), 'int32', sep=' ')
    height = np.append(height, [0] * (k - 1))

    dp = np.full((n + k - 1), 10 ** 9, dtype='int')
    dp[0] = 0

    for i in range(n - 1):
        default_val = dp[i + 1:i + 1 + k]
        new_val = dp[i] + np.abs(height[i + 1:i + 1 + k] - height[i])
        dp[i + 1:i + 1 + k] = np.minimum(default_val, new_val)
    print(dp[n - 1])


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

N = int(input())
P = list(map(int, input().split()))
 
value = 1
 
ac = [P[i] for i in range(1, N) if P[i] <= min(P[:i])]
 
value += len(ac)
 
print(value)

### FIXED CODE ###

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

value = 10 ** 9
ans = 0
for v in P:
    if v < value:
        ans += 1
        value = v
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n, q = getList()

vtxs = [[] for i in range(n)]
already = [0 for i in range(n)]

for i in range(n - 1):
    a, b = getList()
    vtxs[a-1].append(b -1)
    vtxs[b-1].append(a - 1)

count = [0 for i in range(n)]
for i in range(q):
    x, v = getList()
    count[x-1] += v

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

def rep(vx, val):
    # print(vx,val)
    tgt = vtxs[vx]
    already[vx] = 1
    for tg in tgt:
        if already[tg] == 0:
            app = count[tg]
            ans[tg] = val+app
            rep(tg, val+app)

rep(0, count[0])
# print(vtxs)
ans[0] = count[0]
print(*ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n, q = getList()

vtxs = [[] for i in range(n)]
already = [0 for i in range(n)]

for i in range(n - 1):
    a, b = getList()
    vtxs[a-1].append(b -1)
    vtxs[b-1].append(a - 1)

count = [0 for i in range(n)]
for i in range(q):
    x, v = getList()
    count[x-1] += v

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

def rep(vx, val):
    # print(vx,val)
    tgt = vtxs[vx]
    already[vx] = 1
    for tg in tgt:
        if already[tg] == 0:
            app = count[tg]
            ans[tg] = val+app
            rep(tg, val+app)

rep(0, count[0])
# print(vtxs)
ans[0] = count[0]
print(*ans)
### BUGGY CODE ###

a=int(input())
b=[int(i) for i in input().split()]
c=[]
for i in range(a-1):
    for j in range(i+1,a):
        if b[i]==b[j]:
            c.append(1)
if len(c)>0:
    print('NO')
else:
    print('YES')

### FIXED CODE ###

a=int(input())
b=[int(i) for i in input().split()]
c=list(set(b))
if len(b)==len(c):
    print('YES')
else:
    print('NO')