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

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

for i in range(k):
    if a == [n] * n:
        break
    else:
        a2 = [0] * (n + 1)
        for j in range(n):
            temp = a[j]
            a2[max(j - temp, 0)] += 1
            a2[min(j + temp + 1, n)] -= 1
        a3 = [0]
        for j in range(n):
            a3.append(a3[-1] + a2[j])
        a = a3[1:]
for i in range(n):
    print(a[i], end = " ")
print()

### FIXED CODE ###

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

for i in range(k):
    if a == [n] * n:
        break
    else:
        a2 = [0] * (n + 1)
        for j in range(n):
            temp = a[j]
            a2[max(j - temp, 0)] += 1
            a2[min(j + temp + 1, n)] -= 1
        a3 = [0]
        for j in range(n):
            a3.append(a3[-1] + a2[j])
        a = a3[1:]
for i in range(n):
    print(a[i], end = " ")
print()
### BUGGY CODE ###

def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in xrange(1, n + 1):
        for j in xrange(i, n + 1, i):
            table[j] += 1
    
    return table
N = input()
x=0
for i in range(N):
    x+=(i+1)*(num_divisors_table(N+1)[i+1])
print(x)

### FIXED CODE ###

N = int(input())
ans = 0
for i in range(1, N + 1):
    n = N // i  # 項数n
    cnt = (n * (2 * i + (n - 1) * i)) // 2  # 初項i, 項数n の等差数列の和の公式
    ans += cnt
print(ans)
### BUGGY CODE ###

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

for i in range(len(h)-1):
    if h[i] - min(h[i+1:]) > 1:
        print("No")
        exit()

print("Yes")

### FIXED CODE ###

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

h = h[::-1]

for i in range(len(h)-1):
    if h[i] < h[i+1]:
        h[i+1] -= 1
        if not  h[i] == h[i+1]:
            print("No")
            exit()

print("Yes")
### BUGGY CODE ###

from sys import stdin
N=(stdin.readline().rstrip())
ans=0
for i in range(1000000):
    cnt=N.count("BW")
    ans=ans+cnt
    N=N.replace("BW","WB")
    N=N.lstrip("W")
    N=N.rstrip("B")
    if cnt==0:
        break
print(ans)

### FIXED CODE ###

from sys import stdin
N=(stdin.readline().rstrip())
N=list(N)
cnt=0
ans=0
for i in N:
    if i=="B":
        cnt+=1
    else:
        ans+=cnt
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
*a,=map(int,input().split())
l=[]
for i in range(n):
    t=0
    for j in range(i,n):
        t+=a[j]
        l.append(t)
l=sorted(l)[::-1]
m=0
import itertools
for t in itertools.combinations(l,k):
    c=t[0]
    for u in t[1:]:
        c&=u
    m=max(m,c)
print(m)

### FIXED CODE ###

n,k,*a=map(int,open(0).read().split())
l=[]
for i in range(n):
    t=0
    for j in range(i,n):
        t+=a[j]
        l.append(t)
for i in range(40,-1,-1):
    j=2**i
    t=[]
    for x in l:
        if x&j:
            t.append(x)
    if len(t)>=k:
        l=t
a,*b=l
for t in b:
    a&=t
print(a)
### BUGGY CODE ###

N,M=map(int,input().split())
A = list(map(int,input().split()))
min = min(A)
for i in range(M):
  B,C=map(int,input().split())
  if min < C:
    A = A + [C for j in range(B)]
    A.sort(reverse=True)
    A = A[0:N]
    min = A[N-1]
print(sum(A[0:N]))


### FIXED CODE ###

N,M=map(int,input().split())
A = list(map(int,input().split()))
bc = []

for i in range(N):
  bc.append( [1, A[i]])

for i in range(M):
  bc.append(list(map(int,input().split())))
bc = sorted( bc, key=lambda ii:ii[1], reverse=True)
p = []
tmp=0
for i in range(N):
  if bc[tmp][0] == 0:
    tmp +=1
  p.append( bc[tmp][1] )
  bc[tmp][0] -= 1
print( sum(p) )
### BUGGY CODE ###

x = input()
while "ST" in x:
    x = x.replace("ST","")
print(len(x))

### FIXED CODE ###

x = input()
ans = 0

count = 0
for i in range(len(x)):
    if x[i] == "S":
        count += 1
    else:
        count -= 1
    if count < 0:
        ans+=1
        count = 0
count = 0
for i in range(len(x)-1,-1,-1):
    if x[i] == "T":
        count += 1
    else:
        count -= 1
    if count <0 :
        ans+=1
        count = 0
print(ans)
### BUGGY CODE ###


def next7(s):
    return s * 10 + 7


def submit():
    k = int(input())

    if k % 2 == 0:
        print(-1)
        return

    s = 7
    ans = 1
    while s % k:
        s = next7(s)
        ans += 1

    print(ans)


submit()    

### FIXED CODE ###


def submit():
    k = int(input())

    if k % 2 == 0:
        print(-1)
        return
    if k % 5 == 0:
        print(-1)
        return

    d = {}
    for t in [1, 3, 7, 9]:
        d[t] = {}
        for i in range(10):
            d[t][t * i % 10] = i
    
    td = k % 10
    curr = 0
    count = 0
    while count == 0 or curr != 0:
        diff = 7 - (curr % 10)
        if diff != 0:
            if diff < 0:
                diff += 10
            coef = d[td][diff]
            curr += coef * k
        curr //= 10
        count += 1

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

n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    e,f=map(int,input().split())
    t=e
    k=f
    while e<a or f<b:
        t+=e
        k+=f
    a=t
    b=k
print(a+b)

### FIXED CODE ###

n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    e,f=map(int,input().split())
    if (a//e+(1 if a%e!=0 else 0))*f>=b:
        b=f*(a//e+(1 if a%e!=0 else 0))
        a=e*(a//e+(1 if a%e!=0 else 0))
    else:
        a=e*(b//f+(1 if b%f!=0 else 0))
        b=f*(b//f+(1 if b%f!=0 else 0))
print(a+b)
### BUGGY CODE ###

n = int(input())
d = list(map(int,input().split()))
cnt = {}
for i in d:
  if i not in cnt:
    cnt[i] = d.count(i)
m = int(input())
t = list(map(int,input().split()))
flag = True
for i in t:
  if i in cnt:
    if cnt[i]>0:
      cnt[i] -= 1
    else:
      flag = False
      break
  else:
    flag = False
    break
if flag:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

n = int(input())
d = list(map(int,input().split()))
cnt = {}
for i in d:
  if i not in cnt:
    cnt[i] = 1
  else:
    cnt[i] += 1
m = int(input())
t = list(map(int,input().split()))
flag = True
for i in t:
  if i in cnt:
    if cnt[i]>0:
      cnt[i] -= 1
    else:
      flag = False
      break
  else:
    flag = False
    break
if flag:
  print("YES")
else:
  print("NO")
### BUGGY CODE ###

n = int(input())

l = [2,1]
i = 2
while True:
    l.append(l[i-1] + l[i-2])
    if i == n:
        print(l[i])
        exit()
    elif i == 0:
        print(2)
        exit()
    elif i == 1:
        print(1)
        exit()
    else:
        i += 1

### FIXED CODE ###

n = int(input())

l = [2,1]
i = 2
while True:
    l.append(l[i-1] + l[i-2])
    if i == n:
        print(l[i])
        exit()
    elif n == 0:
        print(2)
        exit()
    elif n == 1:
        print(1)
        exit()
    else:
        i += 1
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2000000)

def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


def dfs(A_index, B_index, K, books):
    
    return_books = books
    return_booksA = books

    if N > A_index and K>=A[A_index]:
        return_books = dfs(A_index+1, B_index, K-A[A_index], books+1)
    if M > B_index and K>=B[B_index]:
        return_booksA = dfs(A_index, B_index+1, K-B[B_index], books+1)

    return max(return_books, return_booksA)

print(dfs(0, 0, K, 0))

### FIXED CODE ###

def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


import itertools as it
import bisect

def bins(A, B, K):
    A_it = list(it.accumulate(A))
    B_it = list(it.accumulate(B))

    A_index = bisect.bisect_right(A_it, K)
    B_index = bisect.bisect_right(B_it, K)

    A_it = [0]+A_it[:A_index]
    B_it = B_it[:B_index]

    maxs = 0
    count=0
    for i in A_it[::-1]:
        if K-i < 0:
            continue
        now = K-i
        B_index = bisect.bisect_right(B_it, now)

        maxs = max(maxs, B_index + max(A_index - count,0))
        count+=1

    return maxs

print(bins(A,B,K))
### BUGGY CODE ###

import numpy as np
N,M,K= map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
Asummax=sum(A)
Bsummax=sum(B)
if Asummax+Bsummax<=K:
  print(N+M)
  exit()

Asum=[0]*(N+1)
for i in range(N+1):
  Asum[i]=sum(A[0:i])
  if Asum[i]>K:
    Asum[i]=0
    Amax=i-1
    break
  Amax=i

Bsum=[0]*(M+1)
for i in range(M+1):
  Bsum[i]=sum(B[0:i])
  if Bsum[i]>K:
    Bsum[i]=0
    Bmax=i-1
    break
  Bmax=i

Csum=[0]*(Amax+1)*(Bmax+1)
for i in range(Amax+1):
  for j in range(Bmax+1):
    if Asum[i]+Bsum[j]>K:
      Csum[i*(Bmax+1)+j]=0
    else:Csum[i*(Bmax+1)+j]=Asum[i]+Bsum[j]

Cmax=max(Csum)
D=np.array([i for i, x in enumerate(Csum) if x == Cmax])
D=D//(Bmax+1)+D%(Bmax+1)
print(max(D))

### FIXED CODE ###

import numpy as np
import bisect
N,M,K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
if A[0]>K and B[0]>K:print(0);exit()

Asum=[0]
for i in range(N):
  if Asum[-1]+A[i]<=K:
    Asum.append(Asum[-1]+A[i])  
  else:break
    
Bsum=[0]
for j in range(M):
  if Bsum[-1]+B[j]<=K:
    Bsum.append(Bsum[-1]+B[j])
  else:break
    #AAsum=[]
#for i in range(len(Asum)):
#  AAsum.append(K-Asum[i])

#print(Asum)
#print(AAsum)
#print(Bsum)

C=[]
for i in range(len(Asum)):
  C.append(bisect.bisect(Bsum,K-Asum[i])+i-1)

#print(Asum)
#print(AAsum)
#print(Bsum)
#print(C)
print(max(C))
#176882
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

ans = 0
for i in range(N+1):
    ans = max(ans, ((A*i)//B) - A * (i//B))

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

ans = 0
if N >= B-1:
    ans = max(ans, ((A*(B-1))//B) - A * ((B-1)//B))
else:
    ans = max(ans, ((A*N)//B) - A * (N//B))


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

d,g=map(int,input().split())
p=[]
c=[]
for i in range(d):
    p1,c1=map(int,input().split())
    p.append(p1)
    c.append(c1//100)
import itertools
n=list(itertools.permutations(list(range(1,d+1))))
ans=1100
g//=100
for i in range(len(n)):
    cnt=g
    cnt2=0
    for j in range(d):
        num3=n[i][j]
        num4=num3*p[num3-1]
        if num4>=cnt:
            cnt2+=((cnt-1)//num3)+1
            break
        elif num4+c[num3-1]>=cnt:
            cnt2+=p[num3-1]
            break
        else:
            cnt-=num4+c[num3-1]
            cnt2+=p[num3-1]
    ans=min(ans,cnt2)
print(ans)


### FIXED CODE ###

import itertools
d,g=map(int,input().split())
p=[]
c=[]
for i in range(d):
    p1,c1=map(int,input().split())
    p.append(p1)
    c.append(c1//100)
n=list(itertools.permutations(list(range(1,d+1))))
ans=1024
g//=100
for i in range(len(n)):
    cnt=g
    cnt2=0
    for j in range(d):
        num3=n[i][j]
        num4=num3*p[num3-1]
        if num4>=cnt:
            cnt2+=((cnt-1)//num3)+1
            break
        elif num4+c[num3-1]>=cnt:
            cnt2+=p[num3-1]
            break
        else:
            cnt-=num4+c[num3-1]
            cnt2+=p[num3-1]
    ans=min(ans,cnt2)
print(ans)
### BUGGY CODE ###

import heapq

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

for i in range(m):
    b,c = map(int,input().split())
    for j in range(b):
        d = heapq.heappop(a)
        if d >= c:
            heapq.heappush(a, d)
            break
        else:
            heapq.heappush(a, c)
        
print(sum(a))

### FIXED CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
aa = [-1] * (2*n)
bc = []

for i in range(m):
    b,c = map(int,input().split())
    bc.append((c,b))
bc.sort(reverse = True)

i = 0
for j in range(m):
    if i >= n:
        break
    for k in range(bc[j][1]):
        aa[i] = bc[j][0]
        i += 1

j = 0
for i in range(n):
    if a[i] < aa[j]:
        a[i] = aa[j]
        j += 1
        
print(sum(a))
### BUGGY CODE ###

from bisect import bisect_right

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

def calc(m): #m以下の組が何通りあるかを数える
    count = 0 #組数を数える
    for a in A:
        b = m - a #b以上のは含める
        count += N - bisect_right(A, b - 0.5)
    return count

l = 0 
r = 3 * 10 ** 5

while r - l > 1:
    mid = (l + r) // 2
    if calc(mid) >= M: #合計mid以上の組と手を繋ぐとしたとき、とM回以上握手できる
        l = mid
    else:
        r = mid

B = [0] * (N + 1)
for i in range(N):
    B[i + 1] = B[i] + A[i]

# print(B)
flag = False
for i in range(mid + 3, -1, -1):
    if calc(i) < M:
        flag = False
    else: #初めて手をにぎる回数がM回を下回ったとき
        break

i += 1 #合計この値までは全て使う、残り回数を調整
ans = 0
for a in A:
    b = i - a
    tmp = bisect_right(A, b - 0.5)
    M -= (N - tmp) #使った数
    ans += a * (N - tmp) + (B[-1] - B[tmp])

ans += M * (i - 1)
print (ans)

### FIXED CODE ###

from bisect import bisect_right

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

def calc(m): #m以下の組が何通りあるかを数える
    count = 0 #組数を数える
    for a in A:
        b = m - a #b以上のは含める
        count += N - bisect_right(A, b - 0.5)
    return count

l = 0 
r = 3 * 10 ** 5

while r - l > 1:
    mid = (l + r) // 2
    if calc(mid) >= M: #合計mid以上の組と手を繋ぐとしたとき、とM回以上握手できる
        l = mid
    else:
        r = mid

B = [0] * (N + 1)
for i in range(N):
    B[i + 1] = B[i] + A[i]

# print(B)
flag = False
for i in range(mid + 3, -1, -1):
    if calc(i) < M:
        flag = False
    else: #初めて手をにぎる回数がM回を下回ったとき
        break

i += 1 #合計この値までは全て使う、残り回数を調整
ans = 0
for a in A:
    b = i - a
    tmp = bisect_right(A, b - 0.5)
    M -= (N - tmp) #使った数
    ans += a * (N - tmp) + (B[-1] - B[tmp])

ans += M * (i - 1)
print (ans)
### BUGGY CODE ###

n,m=map(int,input().split())
a=[int(i) for i in input().split()]
while m>0:
    a.sort()
    b=a.pop()
    a.append(b//2)
    m-=1
print(sum(a))    

### FIXED CODE ###

import heapq
n,m=map(int,input().split())
a=[-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    k=heapq.heappop(a)
    heapq.heappush(a,-(abs(k)//2))
print(-sum(a))
### BUGGY CODE ###

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

for i in range(N):
  if sorted(list(P[0:i+1]))[0] == P[i]:
    ans += 1
    
print(ans)

### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
ans = 0
min_number = 2*10**5+1

for i in range(N):
  min_number = min(min_number, P[i])
  if min_number == P[i]:
    ans += 1
  
print(ans)
### BUGGY CODE ###

#input
N = int(input())
S = [''.join(sorted(input())) for i in range(N)]

ana = 0
for i in range(N):
    ana += S.count(S[i])

print(int((ana - N) / 2))

### FIXED CODE ###

import collections

#input
N = int(input())
S = [''.join(sorted(input())) for i in range(N)]

S = collections.Counter(S)

ans = 0
for k, v in S.items():
    ans += v * (v-1) // 2

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

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(len(a)):
    b.append((a[i]+1)/2)
max=0
for i in range(len(a)-k+1):
    sum=0
    for j in range(i,i+k):
        sum+=b[j]
    if max<=sum:
        max=sum
print(max)

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
smax=0
for i in range(k-1,n):
    if i==k-1:
        sumnow=sum(a[:i+1])
    else:
        sumnow+=a[i]-a[i-k]
    smax=max(smax,sumnow)
print((smax+k)/2)
### BUGGY CODE ###

n,k = (int(x) for x in input().split())
a =tuple([int(x) for x in input().split()])
 
l = [1]
now = 1
notloop = 0
dupl = -1

for i in range(k):
  now = a[now - 1]
  
  if now in l:
    dupl = now
    break
  else:
    l.append(now)
    
if(dupl == -1):
  print(now)
else:
  notloop = l.index(dupl)
  length = len(l)-notloop
  print(l[(k-notloop)%length+notloop])

### FIXED CODE ###

n,k = (int(x) for x in input().split())
a = tuple([int(x) for x in input().split()])
 
c = [0] + [-1]*(n)
l = [1]
now = 1
dupl = -1

for i in range(k):
  now = a[now - 1]
  c[now - 1] += 1
   
  if c[now - 1] == 1:
    dupl = now
    break
  else:
    l.append(now)
    
if dupl == -1:
  print(now)
  exit()
       
notloop = l.index(dupl)
length = len(l)-notloop
print(l[(k-notloop)%length+notloop])
### BUGGY CODE ###

s = str(input())
s=s[::-1]
mod = 2019
li = [int(s[0])]
for i in range(len(s) - 1):
    li.append((li[-1] + int(s[i+1]) * (10 ** (i + 1))) % mod)
import collections
A=collections.Counter(li)
ans=0
for u,v in A.items():
    ans+=v*(v-1)//2
    if u==0:
        ans+=v
print(ans)

### FIXED CODE ###

s = str(input())
s=s[::-1]
mod = 2019
li = [0]*(len(s)+1)
cnt=1
for i in range(len(s)):
    li[i+1]=li[i] + int(s[i]) * cnt
    li[i+1]%=mod
    cnt*=10
    cnt%=mod
import collections
A=collections.Counter(li[1:]);ans=0
for u,v in A.items():
    ans+=v*(v-1)//2
    if u==0:
        ans+=v
print(ans)
### BUGGY CODE ###

from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        break

dist = [[INF] * W for _ in range(H)]
dist[Si][Sj] = 0

ans = INF

Q = deque([(0, Si, Sj)])
while Q:
    dist, i, j = Q.popleft()
    if dist > K:
        break

    A[i][j] = "#"

    ans = min(
        ans,
        1 + (i + K - 1) // K,
        1 + (j + K - 1) // K,
        1 + (H - 1 - i + K - 1) // K,
        1 + (W - 1 - j + K - 1) // K
    )

    if dist > K or ans == 0:
        break

    distance = dist + 1

    for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
            Q.append((distance, ni, nj))

print(ans)


### FIXED CODE ###

from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        break

dist = [[INF] * W for _ in range(H)]
dist[Si][Sj] = 0


ans = INF

Q = deque([(Si, Sj)])
while Q:
    i, j = Q.popleft()

    ans = min(
        ans,
        1 + (i + K - 1) // K,
        1 + (j + K - 1) // K,
        1 + (H - 1 - i + K - 1) // K,
        1 + (W - 1 - j + K - 1) // K
    )

    if dist[i][j] == K:
        continue

    distance = dist[i][j] + 1

    for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i + di, j + dj

        if not (0 <= ni < H and 0 <= nj < W and A[ni][nj] == "."):
            continue

        A[ni][nj] = "#"

        if dist[ni][nj] > distance:
            dist[ni][nj] = distance
            Q.append((ni, nj))

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

from collections import defaultdict
from heapq import heappop, heappush
 
class Graph:
 
    def __init__(self):
        self.graph = defaultdict(list)
        self.vertices = set()
        self.edges = []
 
    def add_edge(self, a, b, weight=1):
        self.graph[a].append((b, weight))
        self.vertices |= {a, b}
        self.edges.append((a, b, weight))
 
    def get_vertices(self):
        return sorted(list(self.vertices))
 
    def num_of_vertices(self):
        return len(self.vertices)
 
    def get_edges(self):
        return self.edges
 
    def num_of_edges(self):
        return len(self.edges)
 
class Dijkstra:
 
    def __init__(self, graph, start):
        self.g = graph.graph
 
        self.dist = defaultdict(lambda: float("inf"))
        self.dist[start] = 0
 
        self.prev = defaultdict(lambda: None)
 
        self.Q = []
        heappush(self.Q, (0, start))
 
        while self.Q:
            dist_u, u = heappop(self.Q)
 
            if self.dist[u] < dist_u:
                continue
 
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))
 
 
    def shortest_distance(self, goal):
 
        return self.dist[goal]
 
    def shortest_path(self, goal):
 
        path = []
        vertice = goal
        while vertice is not None:
            path.append(vertice)
            vertice = self.prev[vertice]
 
        return path[::-1]

N, M = map(int, input().split())
G = Graph()
T = []
C = defaultdict(int)
for _ in range(M):
    a, b, c = map(int, input().split())
    G.add_edge(a, b, c)
    G.add_edge(b, a, c)
    T.append(tuple(sorted([a, b])))

for i in range(1, N+1):
    for j in range(1, N+1):
        D = Dijkstra(G, i)
        P = D.shortest_path(j)
        for k in range(len(P)-1):
            a, b = P[k], P[k+1]
            C[tuple(sorted([a, b]))] = 1

ans = 0
for a, b in T:
    if C[(a, b)] == 0:
        ans += 1

print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
inf = float("inf")
dist = [[inf for _ in range(N)] for _ in range(N)]
for i in range(N):
    dist[i][i] = 0

T = []
for i in range(M):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    T.append((a, b, c))
    dist[a][b] = min(dist[a][b], c)
    dist[b][a] = min(dist[b][a], c)

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])

ans = M
for a, b, c in T:
    check = False
    for i in range(N):
        if dist[i][a] + c == dist[i][b]:
            check = True
    if check:
        ans -= 1
print(ans)
### BUGGY CODE ###

input()
A=map(int,input().split())
ans=0
while all([a%2==0 for a in A]):
    A=[a//2 for a in A]
    ans+=1
print(ans)

### FIXED CODE ###

n = int(input())
a = map(int, input().split())
m = float('inf')
for i in a:
  count = 0
  while i%2 == 0:
    i = i//2
    count += 1
  m = min(m, count)
  if m==0:
    break
print(m)
### BUGGY CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
i=0
while i < N:
    cont=A[i]
    del A[i]
    print(max(A))
    A.insert(i,cont)
    i += 1


### FIXED CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
B=sorted(A,reverse=True)
maxA=B[0]
secondA=B[1]
i=0
for i in range(N):
    if A[i] == maxA:
        print(secondA)
    else:
        print(maxA)
    i += 1
### BUGGY CODE ###

#!/usr/bin/env python3

def main():
    N = int(input())
    L = sorted(map(int, input().split()),reverse=True)
    ans = 0
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            for c in range(b + 1, N):
                if L[a] < L[b] + L[c] and L[b] < L[c] + L[a]:
                    ans += 1
                else:
                    break

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import bisect


def main():
    N = int(input())
    L = sorted(map(int, input().split()))
    ans = 0
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            ans += bisect.bisect_right(L, L[a] + L[b] - 1) - b - 1

    print(ans)


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

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

genzaichi=1
rireki=[]
houmon=[0]*(N+1)
flag=0

for i in range(1,K+1):
    genzaichi=A[genzaichi-1]
    if genzaichi not in rireki:
        houmon[genzaichi]=i
        rireki.append(genzaichi)
    else:
        roop_from=genzaichi
        x=houmon[roop_from]
        roop=i-x
        flag=1
        break

genzaichi=1
if flag==1:
    genzaichi=roop_from
    K=(K-x)-((K-x)//roop)*roop

for i in range(K):
    genzaichi=A[genzaichi-1]

print(genzaichi)

### FIXED CODE ###

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

genzaichi=1
rireki=set()
houmon=[0]*(N+1)
flag=0

for i in range(1,K+1):
    genzaichi=A[genzaichi-1]
    if genzaichi not in rireki:
        houmon[genzaichi]=i
        rireki.add(genzaichi)
    else:
        roop_from=genzaichi
        x=houmon[roop_from]
        roop=i-x
        flag=1
        break

if flag==0:
    print(genzaichi)
else:
    genzaichi=roop_from
    K=(K-x)-((K-x)//roop)*roop
    for i in range(K):
        genzaichi=A[genzaichi-1]
    print(genzaichi)