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

from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics
mod = 10**9+7

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

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

dp = [0 for i in range(1<<N)]
dp[0] = 1

for S in range(1,1<<N):
    i = popcount(S)
    for j in range(N):
        if bit(S,j) == 1 and a[i-1][j] == 1:
            dp[S] = (dp[S] + dp[S^(1<<j)]) % mod

print(dp[(1<<N)-1] % mod)

### FIXED CODE ###

from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics
mod = 10**9+7

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

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

dp = [0 for i in range(1<<N)]
dp[0] = 1

for S in range(1,1<<N):
    i = popcount(S)
    for j in range(N):
        if bit(S,j) == 1 and a[i-1][j] == 1:
            dp[S] = (dp[S] + dp[S^(1<<j)]) % mod

print(dp[(1<<N)-1] % mod)
### BUGGY CODE ###

N = int(input())
l = list(map(int,input().split()))
d = l.copy()

count = 0
i = 0
while len(d) != 0:
    if count == 0:
        a = 0
        count += 1
        for j in range(N-count):
            target = d[i] ^ d[j]
            if target in d :
                a += 1
                i = j
            if a == 1:
                break
        if a >= 1 :
            i2 = target
            mae =d[i]
            d.pop(i)
        else:
            print('No')
            break
    
    elif 1 <= count <= N-3:
        a = 0
        count += 1
        for j in range(N-count):
            if target == mae ^ d[j] :
                a += 1
                i = j
            if a == 1:
                break
        if a >= 1 :
            mae =d[i]
            d.pop(i)
        else:
            print('No')
            break
    
    elif count == N-2:
        a = 0
        count += 1
        if mae == target ^ l[0] :
            pass
        else:
            print('No')
            break    

    else:
        if l[0] == i2  ^   mae :
            print('Yes')
            break
        else:
            print('No')
            break 

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
a_unique = list(set(a))
a_unique.sort()

if len(a_unique) == 1 and a[0] == 0:
    ans = 'Yes'
elif len(a) % 3 == 0 :
    if len(a_unique) == 3:
        if bin(a_unique[0]) == bin(a_unique[1] ^ a_unique[2]) and bin(a_unique[1]) == bin(a_unique[0] ^ a_unique[2]) and bin(a_unique[2]) == bin(a_unique[1] ^ a_unique[0]) and a.count(a_unique[1]) == N//3 and a.count(a_unique[0]) == N//3 :
            ans = 'Yes'
        else:
            ans = 'No'
    elif len(a_unique) == 2:
        if a_unique[0] == 0 and a.count(a_unique[1]) == N//3 * 2:
            ans = 'Yes'
        else:
            ans = 'No'
    else:
        ans = 'No'
else:
    ans = 'No'

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

n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.insert(0,0)
start = 1
now = start
c = 0
flag = [0]*(n+1)
while c <= k and flag[now] == 0:
    #print(now)
    flag[now] = 1
    c+= 1
    now = a[now]
#print(c, now)
if c == k:
    print(now)
else:
    k-=c
    moto = now
    now = a[now]
    cc = 1
    while now != moto:
        now = a[now]
        cc+=1
    nokori = k % cc
    for i in range(nokori):
        now = a[now]
    print(now)


### FIXED CODE ###

n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.insert(0,0)
start = 1
now = start
c = 0
flag = [-1]*(n+1)
while c < k and flag[now] == -1:
    #print(now)
    flag[now] = c
    c+= 1
    now = a[now]
#print(c, now)
if c == k:
    print(now)
else:
    k-=c
    cc = c-flag[now]
    nokori = k % cc
    for i in range(nokori):
        now = a[now]
    print(now)
### BUGGY CODE ###

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

if A[0] != 0:
    print(-1)
    exit()
answer = 0
dp = [0 for _ in range(N)]
for i in range(len(A)-1, -1, -1):
    if A[i] == 0:
        continue
    add = A[i] - dp[i]
    j = i - 1
    k = A[i] - 1
    while j >= 0:
        if A[j] == k or dp[j] == k:
            add = i - j
            break
        elif A[j] > k:
            dp[j] = k
            j -= 1
            k -= 1
        else:
            print(-1)
            exit()
    answer += add
print(answer)


### FIXED CODE ###

import numpy as np

N = int(input())
A = np.array([int(input()) for _ in range(N)] + [0], dtype='int64')

x = (A[:-1][A[:-1] >= A[1:]]).sum()

if A[0] != 0:
    x = -1
if (A[1:] >= A[:-1] + 2).any():
    x = -1

print(x)
### BUGGY CODE ###

n = int(input())
an = [int(i) for i in input().split()]
order = [an.index(i + 1) + 1 for i in range(n)]
for i in range(n - 1):
    print(str(order[i]), end=' ')
print(order[n - 1])

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
order = [0 for i in range(n)]
for i in range(n):
    order[a[i] - 1] = i + 1
for i in range(n - 1):
    print(str(order[i]), end=' ')
print(order[n - 1])
### BUGGY CODE ###

n=int(input());a=eval('list(input()),'*n);print(-all(t.count('#')<1for t in a)or min(n*2-sum(n==t.count('#')for t in zip(*a))-b.count('#')+all(a[j][i]>'#'for j in range(n))for i,b in enumerate(a)))

### FIXED CODE ###

n=int(input())
a=eval('list(input()),'*n)
if all(t.count('#')<1for t in a):
  print(-1)
  exit()
f=sum(n==t.count('#')for t in zip(*a))
c=10**18
for i,b in enumerate(a):
  v=b.count('#')
  t=0
  if b[i]!='#':
    for j in range(n):
      if a[j][i]=='#':
        break
    else:
      t+=1
    t+=n-v
  else:
    t+=n-v
  c=min(c,t+n-f)
print(c)
### BUGGY CODE ###

n, m = map(int, input().split())
height = list(map(int, input().split()))
roads = [list(map(int, input().split())) for _ in range(m)]
ids = [i+1 for i in range(n)]
ans = [1] * len(ids)

j = 1
for _ in range(n-1):
    for i in range(n-j):
        if height[i] > height[i+1]:
            tmp_a = height[i]
            tmp_b = ids[i]
            height[i] = height[i+1]
            ids[i] = ids[i+1]
            height[i+1] = tmp_a
            ids[i+1] = tmp_b
    j += 1
    
for i in range(m):
    if height[ids.index(roads[i][0])] == height[ids.index(roads[i][1])]:
        ans[ids.index(roads[i][0])] = 0
        ans[ids.index(roads[i][1])] = 0
    else:
        ans[min(ids.index(roads[i][0]), ids.index(roads[i][1]))] = 0
    
print(ans.count(1))

### FIXED CODE ###

n, m = map(int, input().split())
h = [0] + list(map(int, input().split()))
roads = [[] for _ in range(n+1)]
ans = 0

for _ in range(m):
    a, b = map(int, input().split())
    roads[a].append(b)
    roads[b].append(a)
    
for i in range(1, n+1):
    for j in roads[i]:
        if h[i] <= h[j]:
            break
    else:
        ans += 1

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

N = int(input())
A = input().split()
A.insert(0,0)
x = [0]*N
for j in range(N):
    print(A.count(str(j+1)))

### FIXED CODE ###

N = int(input())
A = input().split()
x = [0]*N
for i in range(N-1):
    x[int(A[i])-1]+=1
for j in range(N):
    print(x[j])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in a:
    ans[i-1]=a.index(i)+1
print(' '.join(map(str,ans)))

### FIXED CODE ###

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

# ABC172c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

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

    memo = dict()

    def dfs(i, j, s):
        if memo.get((i, j, s)) != None:
            return memo[(i, j, s)]
        t = 0
        if i < n and s + a[i] <= k:
            t = dfs(i + 1, j, s + a[i])+1
        if j < m and s + b[j] <= k:
            t = max(t, dfs(i, j + 1, s + b[j]) + 1)
        memo[(i, j, s)] = t
        return t

    print(dfs(0, 0, 0))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# ABC172c


def main():
    import sys
    import bisect
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

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

    def cum(array):  # result[i]=i番目まで（1-indexed）の累積和
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    bc = cum(b)
    ac = cum(a)
    ans = 0
    for i in range(n + 1):
        if ac[i] <= k:
            #print(i, bisect.bisect_left(bc, k - ac[i])-1)
            ans = max(ans, i + bisect.bisect_right(bc, k - ac[i])-1)
    print(ans)


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

import numpy as np
import bisect

N = int(input())
A = np.array([int(x) for x in input().split()],dtype = np.int64)
B = np.array([int(x) for x in input().split()],dtype = np.int64)

def f(t,A,B):
	power = (1<<t)
	AA = np.mod(A,2*power)
	BB = np.mod(B,2*power)
	AA.sort()
	BB.sort()
	cnt = 0
	for i in range(N):
		a = AA[i]
		R = bisect.bisect_right(BB, power-1-a)
		cnt += R
		L = bisect.bisect_left(BB,2*power-a)
		R = bisect.bisect_right(BB, 3*power-1-a)
		cnt += R-L
	x0 = cnt
	x1 = N*N - cnt
	return x1%2
  
ans = 0
for t in range(30):
	x = f(t,A,B)
	if x == 1:
		ans += 1<<t

print(ans)

### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
 
def sum_count(A,B,x):
    # A,B is sorted. 
    # return count(a+b < x)
    p = len(B)-1
    result = 0
    for a in A:
        while p != -1 and a + B[p] >= x:
            p -= 1
        result += p+1
    return result
 
		
def f(t,A,B):
    power = (1<<t)
    AA = [x&(2*power-1) for x in A]
    BB = [x&(2*power-1) for x in B]
    AA.sort()
    BB.sort()
    
    x1,x2,x3 = (sum_count(AA,BB,v) for v in [power, 2*power, 3*power])
    zero_cnt = x1 + (x3-x2)
    return (N-zero_cnt)%2
  
ans = 0
for t in range(30):
	x = f(t,A,B)
	if x == 1:
		ans += 1<<t
 
print(ans)
### BUGGY CODE ###

N, W = map(int, input().split())
w = []
v = []
for i in range(N):
  w_, v_ = map(int, input().split())
  w.append(w_)
  v.append(v_)
  
  
dp = [[0]*(W+1) for i in range(N+1)]


for i in range(N):
  for j in range(W+1):
    if j >= w[i]:
      dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i])
    else:
      dp[i+1][j] = dp[i][j]
print(dp[N][W])

### FIXED CODE ###

import numpy as np

n, W = map(int, input().split())
w = []
v = []
for i in range(n):
  w_, v_ = map(int, input().split())
  w.append(w_)
  v.append(v_)
  
dp = np.zeros(W+1, dtype=np.int64)
for i in range(n):
  dp[w[i]:] = np.maximum(dp[:-w[i]]+v[i], dp[w[i]:])
print(dp[W])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	#S = list(input())
	#L,R = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	A = input().split()
	A = [int(s) for s in A]

	ans = [0 for _ in range(N)]
	
	ed = min(A[0]*2, A[-1]*2)
	for i in range(ed, -1, -2):
		fin = True
		for j in range(N):
			if j == 0:
				ans[j] = str(i)
				continue
			tmp = (A[j-1] - (int(ans[j-1]) / 2))*2

			if tmp < 0 or tmp % 2 == 1:
				fin = False
				break
			else :
				ans[j] = str(int(tmp))
		
		if fin == False:
			pass
		else:
			if (int(ans[-1]) / 2) + (int(ans[0]) / 2) == A[-1]:
				#print("sss")
				break

	#ans = [str(a) for a in ans]
	print(' '.join(ans))


if __name__ == "__main__":
	main()

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	tmp = 0
	for i, val in enumerate(A):
		if i == 0:
			tmp += 2*val
			continue
		if i % 2 == 1:
			tmp -= 2*val
		else:
			tmp += 2*val
	
	x = tmp / 2
	
	ans = []
	ans.append(int(x))
	for i, val in enumerate(A):
		tmp = (val - (ans[i]/2)) * 2
		ans.append(int(tmp))
	
	ans = ans[:-1]
	ans = [str(s) for s in ans]
	print(" ".join(ans))
	
if __name__ == "__main__":
	main()
### BUGGY CODE ###

n = int(input())
lr = [list(map(int,input().split())) for _ in range(n)]
lr.sort()

def fan(lr):
    lmax = lr[-1][0]
    rl = [lr[i][1] for i in range(len(lr))]
    rmax = min(rl)
    return max(rmax-lmax+1,0)
res = 0
for i in range(1,n):
    lr1 = lr[:i]
    lr2 = lr[i:]
    res = max(res,fan(lr1)+fan(lr2))
print(res)

### FIXED CODE ###

N = int(input())
LR = [list(map(int, input().split())) for _ in range(N)]
maxl = 1
minr = 10**9+1
maxdis = 0
for i in range(N):
    if maxl < LR[i][0]:
        maxl = LR[i][0]
    if minr > LR[i][1]:
        minr = LR[i][1]
    if LR[i][1] - LR[i][0] > maxdis:
        maxdis = LR[i][1] - LR[i][0]

res = maxdis+1 + max(0, minr - maxl+1)

LR.sort(key=lambda x: x[1])
LR.sort(key=lambda x: x[0])

minb = 10**9+5
for i in range(N-1, -1, -1):
    minb = min(minb, max(0, LR[i][1]-maxl+1))
    LR[i].append(minb)
for i in range(N-1):
    res = max(res, max(0, minr - LR[i][0]+1)+LR[i+1][2])
print(res)
### BUGGY CODE ###

n,k,q=[int(i) for i in input().split()]
dif=q-k+1
a=list()
for i in range(q):
  a.append(int(input()))
for i in range(1,n+1):
  if a.count(i)>=dif:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

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

import sys
input = sys.stdin.readline
X, Y, A, B, C = (int(i) for i in input().split())
p = [[int(x), "A"] for x in input().split()]
q = [[int(x), "B"] for x in input().split()]
r = [[int(x), "C"] for x in input().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]
apples = p+q+r


#apples.sort(reverse=True)
apples = sorted(apples, reverse=True)
#print(apples)
ans = 0
pend = 0


for i in range(len(apples)):
    if apples[0][1] == "C":
        pend += 1
        ans += apples[0][0]
        apples.pop(0)
    elif apples[0][1] == "A":
        if X > 0:
            ans += apples[0][0]
            apples.pop(0)
            X -= 1
        else:
            apples.pop(0)
    elif apples[0][1] == "B":
        if Y>0:
            ans += apples[0][0]
            apples.pop(0)
            Y -= 1
        else:
            apples.pop(0)
    if (X < 1 and Y < 1) or X+Y == pend:
        break
    #print(ans)
    #print("XY", X, Y, pend)
#print("XY", X, Y, pend)
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
X, Y, A, B, C = (int(i) for i in input().split())
p = [[int(x), "A"] for x in input().split()]
q = [[int(x), "B"] for x in input().split()]
r = [[int(x), "C"] for x in input().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]
apples = p+q+r


apples.sort(reverse=True)
#print(apples)
ans = 0
pend = 0


for hapi, col in apples:
    if col == "C":
        pend += 1
        ans += hapi
    elif col == "A":
        if X > 0:
            ans += hapi
            X -= 1

    elif col == "B":
        if Y>0:
            ans += hapi
            Y -= 1

    if (X < 1 and Y < 1) or X+Y == pend:
        break
    #print(ans)
    #print("XY", X, Y, pend)
#print("XY", X, Y, pend)
print(ans)
### BUGGY CODE ###

import sys
import numpy as np
input=sys.stdin.readline
n,k=map(int,input().split())
ni=n-1
h=list(map(int,input().split()))
dp=[0]*n
fores=float('inf')
res=0
j=0
for base in range(1,n):
    if base<=k:
        j=0
    else:
        j=base-k
    for inter in range(j,base):
        if fores>(abs(h[base]-h[inter])+dp[inter]):
            fores=(abs(h[base]-h[inter])+dp[inter])
    dp[base]=fores
    fores=float('inf')
res=dp[ni]
print(res)

### FIXED CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] * n
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])

    for i in range(2, n):
        dp[i] = min(abs(h[i] - h[j]) + dp[j] for j in range(max(0, i - k), i))
    print(dp[n - 1])


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

from itertools import combinations
n = int(input())
s = input()

l = [i for i in range(n)]
nums = list(combinations(l,3))

ans = 0
for i,j,k in nums:
  if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
    if j-i != k-j:
      ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")
rgb = r*g*b

for i in range(n):
  for j in range(i+1, n-1):
    k = 2*j-i
    
    if k >= n or s[i] == s[j] or s[j] == s[k] or s[i] == s[k]:
      continue
      
    rgb -= 1
    
print(rgb)
### BUGGY CODE ###

from collections import deque


def solve():
    H, W = map(int, input().split())
    grid = [['' for _ in range(W)] for _ in range(H)]
    que = deque()
    for i in range(H):
        grid[i] = list(input())
        for j in range(W):
            if grid[i][j] == '#':
                que.append([i, j])
    
    xy = [[0, -1], [1, 0], [0, 1], [-1, 0]]
    ans = 0
    while que:
        n = len(que)
        for _ in range(n):
            y, x = que.popleft()
            for i in range(4):
                xi = x - xy[i][0]
                yi = y - xy[i][1]
                if 0 <= xi <= W-1 and 0 <= yi <= H-1:
                    if grid[yi][xi] == '.':
                        grid[yi][xi] = '#'
                        que.append([yi, xi])
        ans += 1
    print(ans-1)


if __name__ == '__main__':
    solve()

### FIXED CODE ###

from collections import deque


def solve():
    H, W = map(int, input().split())
    grid = [['' for _ in range(W)] for _ in range(H)]
    que = deque()
    for i in range(H):
        grid[i] = list(input())
        for j in range(W):
            if grid[i][j] == '#':
                que.append([i, j])
    
    xy = [[0, -1], [1, 0], [0, 1], [-1, 0]]
    ans = 0
    while que:
        n = len(que)
        for _ in range(n):
            y, x = que.popleft()
            for i in range(4):
                xi = x - xy[i][0]
                yi = y - xy[i][1]
                if 0 <= xi <= W-1 and 0 <= yi <= H-1:
                    if grid[yi][xi] == '.':
                        grid[yi][xi] = '#'
                        que.append([yi, xi])
        ans += 1
    print(ans-1)


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

#Coding:Utf-8

N=int(input())
s=[list(input()) for i in range(N)]
total=num=0
for l in range(N):
    s[l].sort()
s.sort()
while len(s)!=0:
    num=s[1:N].count(s[0])
    for m in range(1,num+1):
        total+=m
        s.remove(s[0])
    s.remove(s[0])

print(total)


### FIXED CODE ###

#Coding:Utf-8

N=int(input())
s=[list(input()) for i in range(N)]
total=num=0
dic={}
for l in range(N):
    s[l].sort()
    if dic.get(str(s[l]))==None:
        dic[str(s[l])]=0
    else:
        dic[str(s[l])]+=1
        total+=int(dic[str(s[l])])
print(total)
### BUGGY CODE ###

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

def main():
    n , data = input_data()
    vMax = float('-inf')

    i = 1
    minIndex = min(enumerate(data) , key = lambda x:x[1])[0]
    maxIndex = max(enumerate(data) , key = lambda x:x[1])[0]
    for i, Ri in enumerate(data):
        if data[i+1:]:
            if maxIndex < i + 1:
                maxIndex, Rj= max(enumerate(data[i+1:]) , key = lambda x:x[1])
                maxIndex += i + 1
            else:
                Rj = data[maxIndex]

            n = Rj - Ri
            if vMax < n:
                vMax = n

        if i == minIndex: # Ri???????°???????????????¨????????????????¨??????????
            break

    print(vMax)

def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()

### FIXED CODE ###

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

def main():
    n , data = input_data()
    vMax = float('-inf')
    vMin = data.pop(0)

    for Rj in data:
        if vMax < Rj - vMin:
            vMax = Rj - vMin
        if vMin > Rj:
            vMin = Rj

    print(vMax)

def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst)

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

R,G,B,N = map(int, input().split())

maxr=N//R
maxg=N//G
maxb=N//B

ans=0
flg=0
for r in range(maxr,-1,-1):
  tmpb=0
  for g in range(maxg,-1,-1):
    for b in range(tmpb,maxb+1):
      if R*r+G*g+B*b==N:
        ans+=1
        tmpb=b
        break
print(ans)

### FIXED CODE ###

R,G,B,N = map(int, input().split())

maxr=N//R
maxg=N//G

ans=0
for r in range(maxr,-1,-1):
  for g in range(maxg,-1,-1):
    if N-(r*R+g*G)>=0:
      if (N-(r*R+g*G))%B==0:
        ans+=1
print(ans)
### BUGGY CODE ###

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

DP = [[-10**18 for i in range((N+1)//2)] for i in range(N)]

DP[0][0] = A[0]
#for i in range(1,N):
#    DP[i][0] = max(DP[i-1][0],A[i])

#for i in range(1,N//2-1):
#    DP[2*i][i] = DP[2*(i-1)][i-1] + A[2*i]

for i in range(1,N):
    for j in range((i+1)//2-1,(i+2)//2):
        if j == 0:
            DP[i][0] = max(DP[i-1][0],A[i])
        else:
            DP[i][j] = max(DP[i-1][j],DP[i-2][j-1]+A[i])

print(DP[N-1][N//2-1])


### FIXED CODE ###

from collections import defaultdict

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

DP = defaultdict(lambda: -10**18)

DP[(0,0)] = A[0]

for i in range(1,N):
    for j in range((i+1)//2-1,(i+2)//2):
        if j == 0:
            DP[(i,0)] = max(DP[(i-1,0)],A[i])
        else:
            DP[(i,j)] = max(DP[(i-1,j)],DP[(i-2,j-1)]+A[i])

print(DP[(N-1,N//2-1)])