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

n,m = map(int,input().split(" "))
a=[]
ans = 1
for i in range(m):
    a.append(int(input()))
    if a[i]-1 == a[i-1]:
        ans = 0
if ans == 1:
    t = 1
    for j in range(n,-1,-1):
        if j in a:
            ans *= 1
        elif j+1 in a or j+2 in a:
            ans *= 1
        elif j+2 > n:
            ans *= 1
        elif not(j+2 in a) and not(j+3 in a) and not(j+3 > n):
            t2 = ans
            ans += t
            t = t2
        else:
            t = ans
            ans *= 2

print(ans % 1000000007)


### FIXED CODE ###

n,m = map(int,input().split(" "))
a=[0] * (n+1)
mod = 10 ** 9 + 7
for i in range(m):
    a[int(input())] = 1

dp = [0] * (n+1)
for j in range(n+1):
    if a[j] == 1:
        dp[j] = 0
    elif j == 1 or j == 0:
        dp[j] = 1
    else:
        dp[j] = (dp[j-1] + dp[j-2]) % mod

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

n,k,*a=map(int,open(0).read().split())
a=[x-1 for x in a]
dist=[0]*n
cur=0
while True:
	nxt=a[cur]
	if k==1:
		print(nxt+1)
		break
	if dist[nxt]:
		k=(k-dist[nxt])%(dist[cur]-dist[nxt]+1)+dist[nxt]
		k-=1
		dist=[0]*n
		cur=nxt
	else:
		k-=1
		dist[nxt]=dist[cur]+1
		cur=nxt

### FIXED CODE ###

n,k,*a=map(int,open(0).read().split())
a=[x-1 for x in a]
dist=[0]*n
cur=0
while True:
	nxt=a[cur]
	if k==0:
		print(cur+1)
		break
	if dist[nxt]:
		k=(k-dist[nxt])%(dist[cur]-dist[nxt]+1)+dist[nxt]
		k-=1
		dist=[0]*n
		cur=nxt
	else:
		k-=1
		dist[nxt]=dist[cur]+1
		cur=nxt
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
highest = 0

for i in range(n-k+1):
    a = sum(p[i:i+k])
    if a > highest:
        highest = a

print((highest + k)/2)

### FIXED CODE ###

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

a= sum(p[0:k])
ans = a

for i in range(n-k):
    a -= p[i]
    a += p[i+k]
    ans = max(ans,a)

print((ans+k)/2)
### BUGGY CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
dp=[float("INF")]*(N+1)
dp[0]=0
for i in range(N):
  for j in range(1,K+1):
    if j+i>=N:
      break
    dp[i+j]=min(abs(A[i+j]-A[i])+dp[i],dp[i+j])
print(dp[N-1])

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
dp=[float("INF")]*(N+1)
dp[0]=0
for i in range(N):
  for j in range(1,K+1):
    if j+i>=N:
      break
    dp[i+j]=min(abs(A[i+j]-A[i])+dp[i],dp[i+j])
print(dp[N-1])
### BUGGY CODE ###

K, S = map(int, input().split())
res = 0
for X in range(K+1):
    for Y in range(K+1):
        Z = S - X - Y
        if Z in range(0,K+1):
            res += 1
print(res)

### FIXED CODE ###

k, s = map(int, input().split())
count = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            count += 1
print(count)
### BUGGY CODE ###

from numpy import*
s=int_([*input()])
dp=zeros((len(s)+1,2019),int)
r=arange(2019)
a=0
for i,c in enumerate(s):
  dp[i+1,(r*10+c)%2019]+=dp[i,r]
  dp[i+1,c]+=1
print(sum(dp[:,0]))

### FIXED CODE ###

a,*d=[0]*2020
for i in map(int,input()):
  p=[0]*2019
  for j in range(2019):p[(j*10+i)%2019]+=d[j]
  d=p
  d[i]+=1
  a+=d[0]
print(a)
### BUGGY CODE ###

import heapq
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353
def cummax(it, first=-float('inf')):
    """
    np.maximum.accumulate(arr) でもよさそう
    https://stackoverflow.com/questions/33569668/numpy-max-vs-amax-vs-maximum

    累積 max
    :param collections.Iterable it:
    :param float first:
    :return:
    """
    cm = first
    ret = []
    for v in it:
        cm = max(v, cm)
        ret.append(cm)
    return ret


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

# dp[k]: i | j | k == k となる i, j のうち A[i] + A[j] が最大となる i, j
#: :type: list of ((int, int), (int, int))
dp = [None] * (2 ** N)
for k in range(1, 2 ** N):
    dp[k] = {(A[0], 0), (A[k], k)}

digits = []
k = 1
while k < 2 ** N:
    digits.append(k)
    k <<= 1

for bit in range(2, N + 1):
    for ds in itertools.combinations(digits, bit):
        k = sum(ds)
        for rm in ds:
            dp[k] |= dp[k - rm]
        dp[k] = set(heapq.nlargest(2, dp[k]))

ans = [0] * (2 ** N)
for k in range(1, 2 ** N):
    (a1, _), (a2, _) = dp[k]
    ans[k] = a1 + a2

ans = cummax(ans[1:])
print(*ans, sep='\n')


### FIXED CODE ###

import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353
def cummax(it, first=-float('inf')):
    """
    np.maximum.accumulate(arr) でもよさそう
    https://stackoverflow.com/questions/33569668/numpy-max-vs-amax-vs-maximum

    累積 max
    :param collections.Iterable it:
    :param float first:
    :return:
    """
    cm = first
    ret = []
    for v in it:
        cm = max(v, cm)
        ret.append(cm)
    return ret


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))
SIZE = 2 ** N

# dp[k]: i | j | k == k となる i, j のうち A[i] + A[j] が最大となる i, j
#: :type: list of ((int, int), (int, int))
dp = [None] * SIZE
for k in range(1, SIZE):
    dp[k] = list(sorted([(A[0], 0), (A[k], k)]))

for k in range(1, SIZE):
    mask = k
    while mask < SIZE - 1:
        # kに立ってないビットを1つだけ立てる
        next_k = (mask + 1) | k
        mask |= next_k

        a1, a2 = dp[k]
        b1, b2 = dp[next_k]
        if a1 > b2:
            # dp[next_k] = a1, a2
            dp[next_k] = dp[k]
        elif b1 > a2:
            # dp[next_k] = b1, b2
            pass
        elif a2 > b2:
            dp[next_k] = b2, a2
        elif b2 > a2:
            dp[next_k] = a2, b2

ans = [0] * SIZE
for k in range(1, SIZE):
    (a1, _), (a2, _) = dp[k]
    ans[k] = a1 + a2

ans = cummax(ans[1:])
print(*ans, sep='\n')
### BUGGY CODE ###

from collections import deque
n=int(input())
a = [[0]*n for _ in range(n)]
visited = [0] * n
col = [1]*n
que = deque()

for i in range(n-1):
    u,v,d = map(int, input().split())
    a[u-1][v-1]=a[v-1][u-1]=d

#方針：貪欲に
for i in range(n):
    if a[0][i]!=0:
        que.append([i, 0])
        visited[i]=1
while que:
    x = que.pop()
    for i in range(n):
        if a[x[0]][i]!=0 and not visited[i]:
            que.append([i, x[0]])
            visited[i]=1
    if a[x[0]][x[1]]%2 == 0:
        col[x[0]]=col[x[1]]
    else:
        col[x[0]]=(col[x[1]])*-1

for i in range(n):
    print(max(col[i], 0))



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
n=int(input())
a = [[]*n for _ in range(n)]
visited = [0] * n
dist = [0]*n
col = [1]*n

def dfs(i:"int", c:"int"):
    for j in a[i]:
        if not visited[j[0]]:
            visited[j[0]]=1
            if j[1]%2==0:
                col[j[0]]=c
            else:
                col[j[0]]=c*-1
            dfs(j[0], col[j[0]])



if __name__ == '__main__':
    for i in range(n-1):
        u,v,d = map(int, input().split())
        a[u-1].append([v-1, d])
        a[v-1].append([u-1, d])
    visited[0]=1
    dfs(0, 1)
    for i in range(n):
        print(col[i] if col[i]>0 else 0)
### BUGGY CODE ###

a,b,c,d=map(int,input().split())
if c>b and d>b:
  print(b-a+1)
  exit()
elif c>b:
  for i in range(b):
    if d*i>=a:
      d1=i*d
  print(b-a-(b-d1)//d)
  exit()
elif d>b:
  for i in range(b):
    if c*i>=a:
      c1=i*c
  print(b-a-(b-c1)//c)
  exit()
else :
  for i in range(b+1):
    if c*i>=a:
      clst=[c*i for i in range(i,(b-c*i)//c+i+1)]
      break
  for i in range(b+1):
    if d*i>=a:
      dlst=[d*i for i in range(i,(b-d*i)//d+i+1)]
      break
  lst=set(clst+dlst)
  print(b-a+1-len(lst))
  

### FIXED CODE ###

a,b,c,d=map(int,input().split())
if d>c:
  euclid2,euclid1=c,d
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
else:
  euclid2,euclid1=d,c
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
  
c1=(a-1)//c+1
c2=(b-c1*c)//c+1
d1=(a-1)//d+1
d2=(b-d1*d)//d+1
cd1=(a-1)//cd+1
cd2=(b-cd1*cd)//cd+1  
print(b-a+1-c2-d2+cd2)
### BUGGY CODE ###

n,m = map(int,input().split())
para = [int(input()) for i in range(m)]
mod = 10**9+7
dp = [0]*(n+1)
for i in range(n+1):
    if not i in para :
        if i == 1 or i==0:
            dp[i] = 1
        else:
            dp[i] = dp[i-1] + dp[i-2]
    else :
        dp[i] = 0


print("{}".format(dp[-1]%mod))

### FIXED CODE ###

n,m = map(int,input().split())
para = [int(input()) for i in range(m)]
mod = 10**9+7
dp = [-1]*(n+1)
for i in para:
    dp[i] = 0
for i in range(n+1):
    if  dp[i] != 0 :
        if i == 1 or i==0:
            dp[i] = 1
        else:
            dp[i] = (dp[i-1] + dp[i-2])%mod



print("{}".format(dp[-1]))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ns = lambda: stdin.readline()[:-1] # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

H, W = na()
A = []
for _ in range(H):
    A.append(na())

A = np.array(A, ndmin=2)
target_y, target_x = np.where(A % 2 != 0)

def print_path(s, t):
    # s: start(x, y)
    # t: target(x, y)
    diff = t - s
    res = []

    # yaxis
    sign = np.sign(diff[1])
    for i in range(np.abs(diff[1])):
        res.append([s[1], s[0], s[1] + sign, s[0]])
        s[1] += sign

    # xaxis
    sign = np.sign(diff[0])
    for i in range(np.abs(diff[0])):
        res.append([s[1], s[0], s[1], s[0] + sign])
        s[0] += sign
    return res


idx = 0
Num = len(target_y)
ans = []
last = []
while idx < Num:
    if idx == Num-1:
        last.append(np.array([target_x[idx]+1, target_y[idx]+1]))
        break

    if target_y[idx] == target_y[idx+1]:
        ans.extend(print_path(np.array([target_x[idx]+1, target_y[idx]+1]),\
            np.array([target_x[idx+1]+1, target_y[idx+1]+1])))
        idx += 2
    else:
        last.append(np.array([target_x[idx]+1, target_y[idx]+1]))
        idx += 1

for i in range(0, len(last)-1, 2):
    ans.extend(print_path(last[i], np.array([W, last[i][1]])))
    ans.extend(print_path(np.array([W, last[i][1]]), np.array([W, last[i+1][1]])))
    ans.extend(print_path(np.array([W, last[i+1][1]]), last[i+1]))

print(len(ans))
for a in ans:
    print(a[0], a[1], a[2], a[3])


### FIXED CODE ###

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

from sys import stdin


ns = lambda: stdin.readline()[:-1] # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

H, W = na()

a_list = []
for _ in range(H):
    a_list.append(na())
a_list.append([0]*W)  # for simple loop code

operation = []
for y in range(H):
    if y % 2 == 0:
        for x in range(W-1):
            if a_list[y][x] % 2 == 1:
                a_list[y][x+1] += 1
                operation.append([y+1, x+1, y+1, x+2])
        if a_list[y][W-1] % 2 == 1:
            a_list[y+1][W-1] += 1
            operation.append([y+1, W, y+2, W])
    else:
        for x in range(W-1, 0, -1):
            if a_list[y][x] % 2 == 1:
                a_list[y][x-1] += 1
                operation.append([y+1, x+1, y+1, x])
        if a_list[y][0] % 2 == 1:
            a_list[y+1][0] += 1
            operation.append([y+1, 1, y+2, 1])

if operation != [] and operation[-1][2] == H+1:
    operation.pop()

# Result
print(len(operation))
for op in operation:
    print(op[0], op[1], op[2], op[3])
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort()
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for h in range(j+1,N):
            if L[i] + L[j] > L[h]:
                cnt += 1
            else:
                break
print(cnt)

### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort()
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        h_min = j
        h_max = N
        while h_max - h_min != 1:
            h_mid = (h_max + h_min) // 2
            if L[i] + L[j] > L[h_mid]:
                h_min = h_mid
            else:
                h_max = h_mid
        cnt += h_min - j
print(cnt)
### BUGGY CODE ###

def maxCount(lst):
    count = 0
    for i in lst:
        if lst.count(i) > count:
            count = lst.count(i)
    return count

n = int(input())
lst = []
for i in range(n):
    lst.append(input())

res = sorted(list(set([x for x in lst if lst.count(x) == maxCount(lst)])))

for i in sorted(res):
    print(i)

### FIXED CODE ###

from collections import defaultdict
from collections import OrderedDict
N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k]+=1
    else:
        ans.update({k:1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)
### BUGGY CODE ###

n = int(input())
rlist = []
for i in range(n):
    r = int(input())
    rlist.append(r)
mlist = []
for i in range(n):
    if(i != 0):
        m = rlist[i] - min(rlist[:i])
        mlist.append(m)
mlist.sort()
print(mlist[-1])


### FIXED CODE ###

n = int(input())
rlist = []
for i in range(n):
    r = int(input())
    rlist.append(r)
mlist = [rlist[1] - rlist[0]]
mini = rlist[0]
for i in range(1,n):
    if(rlist[i-1] < mini):
        mini = rlist[i-1]
    m = rlist[i] - mini
    if(m>mlist[-1]):
        mlist.append(m)
print(mlist[-1])
### BUGGY CODE ###

import bisect
a, b, q = map(int, input().split())
inf = float('inf')
S = [- inf] + [int(input()) for i in range(a)] + [inf]
T = [- inf] + [int(input()) for i in range(b)] + [inf]

for i in range(q):
    x = int(input())
    s_idx = bisect.bisect_left(S, x)
    s1, s2 = S[s_idx - 1], S[s_idx]
    
    t_idx = bisect.bisect_left(T, x)
    t1, t2 = T[t_idx - 1], T[t_idx]
    
    ans = inf
    for i in s1, s2, t1, t2:
        for j in s1, s2, t1, t2:
            if i != j:
                tmp = abs(x - i) + abs(i - j)
                ans = min(ans, tmp)
                
    print(ans)

### FIXED CODE ###

import bisect
 
a, b, q = map(int, input().split())
INF = 10 ** 12
S = [-INF] + [int(input()) for i in range(a)] + [INF]
T = [-INF] + [int(input()) for i in range(b)] + [INF]

for i in range(q):
    x = int(input())
    sid = bisect.bisect_left(S, x)
    tid = bisect.bisect_left(T, x)
    ans = INF
    for s in (S[sid - 1], S[sid]):
        for t in (T[tid - 1], T[tid]):
            ans = min(ans, abs(x - s) +abs(s - t))
            ans = min(ans, abs(x - t) + abs(t - s))
    print(ans)
### BUGGY CODE ###

n,k,q,*a=map(int,open(0).read().split())
for i in range(1,n+1):
  print('Yes' if k-q+a.count(i)>0 else 'No')

### FIXED CODE ###

from collections import Counter
n,k,q,*a=map(int,open(0).read().split())
a=Counter(a)
for i in range(1,n+1):
  print('Yes' if k-q+a[i]>0 else 'No')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n, k = map(int,input().split())
p = [int(i) for i in input().split()]

kitai = []
for i in range(n):
    tmp = 0
    for j in range(1, p[i] + 1):
        tmp += j
    kitai.append(tmp / p[i])

ans = 0
for i in range(n - k + 1):
    tmp2 = 0
    for j in range(i, i + k):
        #print(j)
        #print(kitai[j])
        tmp2 += kitai[j]
    #print(tmp2)
    if ans < tmp2:
        ans = tmp2
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
n, k = map(int,input().split())
p = [int(i) for i in input().split()]

kitai = []
for i in range(n):
    kitai.append((1 + p[i]) / 2)

ans = 0
tmp = 0
for i in range(k):
    tmp += kitai[i]
ans = tmp
for i in range(n - k):
    tmp = tmp - kitai[i] + kitai[i + k]
    if ans < tmp:
        ans = tmp
print(ans)
### BUGGY CODE ###

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

output=1

for num in range(2,round(P**(1/N))+1):
  for i in range(10000):
    if P%(num**N) == 0:
      P = P/(num**N)
      output = num*output
    else:
      break

print(output)



### FIXED CODE ###

N, P = map(int,input().split())
 
output=1
 
if P==1:
  output=1
elif N==1:
  output=P
else:
  for num in range(2,round(P**(1/N))+1):
    if P%(num**N) == 0:
      output = num
 
print(output)
### BUGGY CODE ###

N = int(input())

power = 1
for i in range(1,N+1):
    power *= i

ans = power % (10**9 + 7)

print(ans)

### FIXED CODE ###

N = int(input())

power = 1
for i in range(1,N+1):
    power *= i
    power %= 10**9 + 7

print(power)
### BUGGY CODE ###

def main():
    import math
    N = int(input())
    A = list(map(int, input().split()))
    tt = 0
    #ans = list()
    ann = 0
    memo = dict()

    def comb(m, n):
        return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))
    '''
    def A_count(n):
        if n in memo:
            return memo[n]
        h = A.count(i)
        memo[n] = A.count(i)
        return h
    '''
    B = set(A)
    for i in B:
        f = A.count(i)
        memo[i] = f
        if f>=2:
            tt = tt + comb(f, 2)

    for i in A:
        f = memo[i] #A_count(A[i])
        if f>=3:
            ann = (tt - comb(f, 2) + comb(f-1, 2))
        elif f==2:
            ann = tt - comb(f, 2)
        else:
            ann = tt
        print(ann)

    #for i in ans:
    #    print(i)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import math
    import collections
    N = int(input())
    A = list(map(int, input().split()))
    tt = 0
    #ans = list()
    ann = 0

    def comb(m, n):
        #return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))
        return ((m - 1 + 1) / 1) * (m - 2 + 1) / 2

    '''
    def A_count(n):
        if n in memo:
            return memo[n]
        h = A.count(i)
        memo[n] = A.count(i)
        return h
    '''

    C = collections.Counter(A)
    for i in C.values():
        if i>=2:
            tt = tt + comb(i, 2)

    for i in A:
        f = C[i] #A_count(A[i])
        if f>=3:
            ann = (tt - comb(f, 2) + comb(f-1, 2))
        elif f==2:
            ann = tt - comb(f, 2)
        else:
            ann = tt
        print(int(ann))

    #for i in ans:
    #    print(i)


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

N,M=map(int,input().split())
LRD=[]
x={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
if LRD:
    x[LRD[0][0]]=0
flag=True
while LRD and flag:
    rmvlist=[]
    for i in range(len(LRD)):
        l,r,d=LRD[i]
        if l in x and r not in x:
            x[r] = x[l] +d
            rmvlist.append(i)
        elif r in x and l not in x:
            x[l] = x[r] -d
            rmvlist.append(i)
        elif l in x and r in x:
            if x[l] +d != x[r]:
                flag=False
                break
            else:
                rmvlist.append(i)
    if len(rmvlist)==0:
        x[LRD[0][0]]=0
    else:
        LRD=[LRD[i]for i in range(len(LRD)) if i not in rmvlist]

print("Yes No".split()[1-flag])

### FIXED CODE ###

import queue,sys
# 解説読んだ後
N,M=map(int,input().split())
# networkを作る
G={}
LRD=[]
for i in range(1,N+1):
    G[i]={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
    G[l][r]=d
    G[r][l]=-d
if M==0:
    print("Yes")
    sys.exit()
notvisit=set(range(1,N+1))
Q=queue.Queue()
x={}
while notvisit:
    current=notvisit.pop()
    Q.put(current)
    x[current]=0
    while Q.qsize():
        nex=Q.get()
        for k,v in G[nex].items():
            if k in x:
                if x[k]!= x[nex]+G[nex][k]:
                    print("No")
                    sys.exit()
            else:
                x[k]=x[nex]+G[nex][k]
                Q.put(k)
                notvisit.remove(k)
print("Yes")
### BUGGY CODE ###

H, W, K = map(int, input().split())
s = []
INF = (H - 1) + (W - 1)
ans = INF

def add(col: int):
    for i in range(g):
        now[i] += c[i][col]
    for i in range(g):
        if now[i] > K:
            return False
    return True

for _ in range(H):
    s.append(list(input()))

for div in range(1 << (H - 1)):
    g = 0
    id = [0] * H
    for i in range(H):
        id[i] = g
        if div >> i & 1:
            g += 1
    g += 1
    now = [0] * g
    num = g - 1
    c = [[0 for _ in range(W)] for _ in range(H)]

    for i in range(H):
        for j in range(W):
            c[id[i]][j] += int(s[i][j])

    for j in range(W):
        if not add(j):
            num += 1
            now = [0] * g

            if not add(j):
                num = INF
                break

    ans = min(ans, num)
print(ans)

### FIXED CODE ###

H, W, K = map(int, input().split())
s = []
INF = (H - 1) + (W - 1)
ans = INF

def add(col: int):
    for i in range(g):
        now[i] += c[i][col]
    for i in range(g):
        if now[i] > K:
            return False
    return True

for _ in range(H):
    s.append(list(input()))

for div in range(1 << (H - 1)):
    g = 0
    id = [0] * H
    for i in range(H):
        id[i] = g
        if div >> i & 1:
            g += 1
    g += 1
    
    now = [0] * g
    num = g - 1
    c = [[0 for _ in range(W)] for _ in range(H)]

    for i in range(H):
        for j in range(W):
            c[id[i]][j] += int(s[i][j])

    for j in range(W):
        if not add(j):
            num += 1
            now = [0] * g

            if not add(j):
                num = INF
                break

    ans = min(ans, num)
    
print(ans)
### BUGGY CODE ###

N=int(input())
A=[]
for _ in range(N):
    A.append(int(input()))

print(max(A[1:]))
for i in range(1,N-1):
    print(max(max(A[:i]),max(A[i+1:])))
print(max(A[:N]))

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)[::-1]
mx1 = B[0]
mx2 = B[1]

for i in A:
    if i == mx1:
        print(mx2)
    else:
        print(mx1)
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n)]

    def calc_idx(x, y):
        if x > y:
            x, y = y, x
        return x + y*(y-1)//2

    # create graphs & calc indegree
    n_game = n * (n-1) // 2
    edge = [[] for i in range(n_game)]
    indegree = [0] * n_game
    for i in range(n):
        for j in range(1, n-1):
            g1 = calc_idx(i, a[i][j-1])
            g2 = calc_idx(i, a[i][j])
            edge[g1].append(g2)
            indegree[g2] += 1

    ans = 0
    cand = deque([(i, 1) for i in range(n_game) if indegree[i] == 0])
    n_ts = 0
    while cand:
        u, day = cand.popleft()
        ans = max(ans, day)
        n_ts += 1
        for v in edge[u]:
            indegree[v] -= 1
            if indegree[v] == 0:
                cand.append((v, day+1))

    if n_ts != n_game:
        ans = -1

    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
a = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n)]

def calc_idx(x, y):
    if x > y:
        x, y = y, x
    return x + y*(y-1)//2

n_game = n * (n-1) // 2
edge = [[] for i in range(n_game)]
for i in range(n):
    for j in range(1, n-1):
        g1 = calc_idx(i, a[i][j-1])
        g2 = calc_idx(i, a[i][j])
        edge[g1].append(g2)

indegree = [0] * n_game
for i in range(n_game):
    for v in edge[i]:
        indegree[v] += 1

ans = 0
cand = [i for i in range(n_game) if indegree[i] == 0]
ts = []
while cand:
    ts.extend(cand)
    cand2 = []
    for ci in cand:
        for v in edge[ci]:
            indegree[v] -= 1
            if indegree[v] == 0:
                cand2.append(v)
    cand = cand2
    ans += 1

if len(ts) != n_game:
    ans = -1

print(ans)