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

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353

N, S = MAP()
A = LIST()

# dp[i][j][k] := j番目の要素まで見て、総和がjで、使う区間がk=0,1,2(0:未確定, 1:L確定済, 2:LR確定済)の状態の通り数
dp = list3d(N+1, S+1, 3, 0)
dp[0][0][0] = 1
for i, a in enumerate(A):
    for j in range(S+1):
        for k in range(3):
            if dp[i][j][k] == 0:
                continue
            for l in range(k, 3):
                # aを総和に足さない遷移は全部OK
                dp[i+1][j][l] += dp[i][j][k]
                dp[i+1][j][l] %= MOD
                # aを総和に足す遷移は、遷移元が状態2と遷移先が状態0は無理
                if j+a <= S and k != 2 and l != 0:
                    dp[i+1][j+a][l] += dp[i][j][k]
                    dp[i+1][j+a][l] %= MOD
ans = dp[N][S][2]
print(ans)


### FIXED CODE ###

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353

N, S = MAP()
A = LIST()

# dp0[i][j][ := j番目の要素まで見て、総和がjで、使う区間が未確定の状態の通り数
dp0 = list2d(N+1, S+1, 0)
# dp1[i][j][ := j番目の要素まで見て、総和がjで、使う区間がL確定済の状態の通り数
dp1 = list2d(N+1, S+1, 0)
# dp2[i][j][ := j番目の要素まで見て、総和がjで、使う区間がLR確定済の状態の通り数
dp2 = list2d(N+1, S+1, 0)
dp0[0][0] = 1
for i, a in enumerate(A):
    for j in range(S+1):
        # aを総和に足さない遷移は全部OK
        dp0[i+1][j] += dp0[i][j]
        dp1[i+1][j] += dp0[i][j] + dp1[i][j]
        dp2[i+1][j] += dp0[i][j] + dp1[i][j] + dp2[i][j]
        # aを総和に足す遷移は、遷移元が状態2と遷移先が状態0は無理
        if j+a <= S:
            dp1[i+1][j+a] += dp0[i][j] + dp1[i][j]
            dp2[i+1][j+a] += dp0[i][j] + dp1[i][j]
        dp0[i+1][j] %= MOD
        dp1[i+1][j] %= MOD
        dp2[i+1][j] %= MOD
ans = dp2[N][S]
print(ans)
### BUGGY CODE ###

a=input().split()
N=int(a[0])
M=int(a[1])
first=[]
second=[]
i=0
while i<M:
	y=input().split()
	if int(y[0])==1:
		first.append(y[1])
	elif int(y[1])==N:
		second.append(y[0])
	i+=1

if any(i in first for i in second):
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

### FIXED CODE ###

a=input().split()
N=int(a[0])
M=int(a[1])
first=[]
second=[]
i=0
while i<M:
	y=input().split()
	if int(y[0])==1:
		first.append(y[1])
	elif int(y[1])==N:
		second.append(y[0])
	i+=1

first=set(first)
second=set(second)
if len(first.intersection(second))>0:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")
### BUGGY CODE ###

H, N = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H + 1):
    for a, b in AB:
        h_new = min(h + a, H)
        dp[h_new] = min(dp[h] + b, dp[h_new])
print(dp[-1])

### FIXED CODE ###

H, N = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H + 1):
    for a, b in AB:
        h_new = min(h + a, H)
        dp[h_new] = min(dp[h] + b, dp[h_new])
print(dp[-1])
### BUGGY CODE ###

from functools import reduce
import fractions

def main():
    import math
    k = int(input())
    ans = 0

    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                ans += reduce(lambda a,b: fractions.gcd(a, b), [i,j,l])
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from functools import reduce
import fractions

def main():
    import math
    k = int(input())
    ans = 0

    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                ans += reduce(lambda a,b: math.gcd(a,b), [i,j,l])
    print(ans)


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

str_list = input().split(' ')
int_list = [int(x) for x in str_list]
A, B = int_list[0], int_list[1]

def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

cf = cf(A, B)

count = 0

import numpy as np
cf = np.array(cf)

count = 0
while len(cf) > 0:
    count += 1
    if len(cf)==1:
        break
    x = int( cf[0] )
    cf = cf[np.where( cf%x!=0 )]
print(count+1)


### FIXED CODE ###

str_list = input().split(' ')
int_list = [int(x) for x in str_list]
A, B = int_list[0], int_list[1]

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

a_div = make_divisors(A)
b_div = make_divisors(B)

cf = list( set(a_div) & set(b_div) )
cf.remove(1)
cf.sort()

count = 0

import numpy as np
cf = np.array(cf)

count = 0
while len(cf) > 0:
    count += 1
    if len(cf)==1:
        break
    x = int( cf[0] )
    cf = cf[np.where( cf%x!=0 )]
print(count+1)
### BUGGY CODE ###

def B():
    N = int(input())
    A = map(int, input().split())
    ans = 1
    limit = 10**18
    for a in A:
        ans *= a
    if ans > limit:
        print(-1)
        return
    print(ans)
B()

### FIXED CODE ###

def B():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    ans = 1
    limit = 10**18
    for a in A:
        ans *= a
        if ans > limit:
            print(-1)
            return
    print(ans)
B()
### BUGGY CODE ###

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を記憶
    count_zeros = [0 for j in range(L+1)]
    count_ones = [0 for j in range(L+1)]
    for i in range(N):
        for j in range(L):
            count_ones[j] = count_ones[j] + ((A[i] >> j) & 1)
            count_zeros[j] = N - count_ones[j]
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for j in range(L):
        base = count_zeros[j] * count_ones[j]
        # 64bit以下に収まるように計算
        base = (base * pow(2, j, MOD)) % MOD
        modsum = (base + modsum) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))
    

### FIXED CODE ###

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A, L=60, MOD=10**9+7):
    modsum = 0
    for j in range(L):
        count_ones = sum([1 for a in A if (a >> j) & 1])
        # count_ones = sum([(A[i] >> j) & 1 for i in range(N)])
        count_zeros = N - count_ones
        # MODは一度にとる
        modsum +=  (1<<j) * count_zeros * count_ones
        modsum %= MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))
### BUGGY CODE ###

a=int(input())
b=list(map(int,input().split()))
x=1;
for i in b:
  x=x*i
if x>10**18:
  print(-1)
else:
  print(x)

### FIXED CODE ###

a=int(input())
b=list(map(int,input().split()))
x=1;
if 0 in b:
  print(0)
  exit()
for i in b:
  x=x*i
  if x>10**18:
  	print(-1)
  	exit()
print(x)
### BUGGY CODE ###

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

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]
nokori_games = n * (n - 1) / 2 
day = 1
r5000 = range(5000)
for _ in r5000:
  player_in_this_game = set()
  rn = range(n)
  for m in rn: #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    la = len(a[m])      
    if la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      if m in player_in_this_game or teki - 1 in player_in_this_game:
        #自分または相手に既に試合が組まれている
        pass
      elif a[teki - 1][0] == jibun: #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
        a[m].popleft() #自分の予定を消す
        a[teki - 1].popleft() #相手の予定を消す
        player_in_this_game.add(m) #自分を試合中にする
        player_in_this_game.add(teki - 1) #相手を試合中にする
        nokori_games -= 1 #残り試合予定を1つ減らす

  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1


### FIXED CODE ###

import sys
import time
from collections import deque

start = time.time()

input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]
nokori_games = n * (n - 1) / 2 
day = 1
r5000 = range(5000)
player_in_this_game = set()
rn = range(n)
for _ in r5000:
  for m in rn: #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    if m in player_in_this_game:
      #自分が既に試合が組まれている
      continue

    la = len(a[m])      
    if la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      teki_idx = teki - 1
      if teki_idx in player_in_this_game:
        #相手が既に試合に組まれている
        continue

      if a[teki_idx][0] == jibun: #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
        a[m].popleft() #自分の予定を消す
        a[teki_idx].popleft() #相手の予定を消す
        player_in_this_game.add(m) #自分を試合中にする
        player_in_this_game.add(teki_idx) #相手を試合中にする
        nokori_games -= 1 #残り試合予定を1つ減らす

  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1
  player_in_this_game.clear()
  elapsed_time = time.time() - start
  if elapsed_time > 1:
    print(n*(n-1)//2)
    exit()
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
for x in range(Q):
    a, b = map(int, input().split())
    print(S[a-1:b].count('AC'))

### FIXED CODE ###

from itertools import accumulate

N, Q = map(int, input().split())
S = input()
lst = [0]
idx = 0
for x in range(len(S) - 1):
    if S[x] == 'A' and S[x + 1] == 'C':
        lst.append(1)
    else:
        lst.append(0)

lst2 = list(accumulate(lst))
for x in range(Q):
    a, b = map(int, input().split())
    print(lst2[b-1] - lst2[a-1])
### BUGGY CODE ###

N=int(input())
S =input()
count =0
Bcount = S.count("B")
for i in range(0,N-1):
    for j in range(i+1,N):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R") :
            count += Bcount
            if j+(j-i) <N  and S[j+(j-i)] == "B":
                count  -=1
            if i-(j-i) >=0 and S[i-(j-i)] =="B":
                count -=1
            if (i+j)%2 ==0 and S[int((i+j)/2)] == "B":
                count -=1
print(count)

### FIXED CODE ###

N=int(input())
S =input()
count =0

Bcount = S.count("B")
for i in range(0,N-1):
    for j in range(i+1,N):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R") :
            count += Bcount
            if j+(j-i) <N  and S[j+(j-i)] == "B":
                count  -=1
            if i-(j-i) >=0 and S[i-(j-i)] =="B":
                count -=1
            if (i+j)%2 ==0 and S[int((i+j)/2)] == "B":
                count -=1
print(count)
### BUGGY CODE ###



from collections import deque


def main():
        
    N = int(input())
    A = [deque(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]

    match_order = {k:v for k,v in enumerate(A)}

    cnt_finished = 0

    days = 1
    flag = True
    while flag:
        flag = False
        used = set()
        complete = []
        for i, order in match_order.items():

            if not order:
                continue
            if i in used:
                continue
            j = order[0]
            if j in used:
                continue
            # それぞれの人について、残りの順番で初めに戦う相手がお互いになっている = その段階で試合ができる
            if A[j][0] == i:
                A[i].popleft()
                A[j].popleft()
                used.add(i)
                used.add(j)
                flag = True
                # N-1人と戦い終わった人は次以降調べない
                if not A[i]:
                    cnt_finished += 1
                    complete.append(i)
                if not A[j]:
                    cnt_finished += 1
                    complete.append(j)
                #print(i,j, cnt_finished)

        if not flag:
            print(-1)
            exit()
        
        if cnt_finished == N:
            print(days)
            exit()
        else:
            for i in complete:
                del match_order[i]
            days += 1

if __name__ == "__main__":
    main()

### FIXED CODE ###


from collections import deque

N = int(input())
match_order = [deque(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]


q = deque(range(N))
finish_by = [0] * N
next_opponent = [None] * N

while q:
    a = q.popleft()
    # aの残りの順で一番初めに戦う対戦相手を取り出す
    b = match_order[a].popleft()
    if next_opponent[b] == a:
        finish_by[a] = finish_by[b] = max(finish_by[a], finish_by[b]) + 1
        # a,bについて、まだ対戦相手が残っているならキューに積む
        if match_order[a]:
            q.append(a)
        if match_order[b]:
            q.append(b)
    # bの残りの順で戦う相手がaではないなら、順番が来るまで待つ
    else:
        next_opponent[a] = b

# 対戦相手が残っている人がいる場合、条件通りに終わることができない
if any(match_order):
    print(-1)
else:
    print(max(finish_by))
### BUGGY CODE ###

from collections import defaultdict

# Trie木をハッシュマップ（辞書）で再現
# Keyはその先祖のローリングハッシュ
# Valueはそれ自身とその子孫において、各アルファベットがいくつのSに現れるかの個数をリストでもったもの。

base = 2 ** 61 - 1
root = 10000
class RollingHash:

    def __init__(self, s):
        self.hs = [0] * (len(s) + 1)
        for i in range(len(s)):
            self.hs[i + 1] = self.hs[i] * root + ord(s[i]) % base

    def get_hash(self, l, r):
        "get the hash of s[l:r] (0 <= l <= r <= len(s))"
        return (self.hs[r] - self.hs[l] * pow(root, r - l, base)) % base

#"""
N = int(input())
S_list = [input() for _ in range(N)]
"""
def to_alpha(n):
    ret = ''
    while n > 0:
        n -= 1
        ret += chr(n % 26 + ord('a'))
        n //= 26
    return ret

N = 10 ** 5
S_list = [to_alpha(i) for i in range(2, 2 * N + 2, 2)]
#"""

S_list.sort(key = len, reverse = True)

trie_hash = defaultdict(lambda: [0] * 26)
ans = 0
for S in S_list:
    rh = RollingHash(S)

    ans += trie_hash[rh.get_hash(1, len(S))][ord(S[0]) - ord('a')]

    alphabet_counter = [0] * 26
    for i in range(len(S)):
        suffix_hash = rh.get_hash(i+1, len(S))
        alphabet_counter[ord(S[i]) - ord('a')] = 1
        for j in range(26):
            trie_hash[suffix_hash][j] += alphabet_counter[j]

print(ans)

### FIXED CODE ###

from collections import defaultdict

root = 10000
MOD = 2 ** 61 - 1


#"""
N = int(input())
S_list = [input() for _ in range(N)]
"""
def to_alpha(n):
    ret = ''
    while n > 0:
        n -= 1
        ret += chr(n % 26 + ord('a'))
        n //= 26
    return ret

N = 2 * 10 ** 5
S_list = [to_alpha(i) for i in range(2, 2 * N + 2, 2)]
#"""


S_list.sort(key=len)

ans = 0
wanted = defaultdict(set)
for S in S_list:
    suffix_hashes = [0]
    for c in S[-1:0:-1]:
        suffix_hashes.append((suffix_hashes[-1] * root + ord(c)) % MOD)
    suffix_hashes.reverse()
    l = len(S)
    alpha_set = set()
    for i, c in enumerate(S):
        alpha_set.add(c)
        # print(alpha_set, suffix_hashes[i])
        if suffix_hashes[i] in wanted:
            for alpha in wanted[suffix_hashes[i]]:
                if alpha in alpha_set:
                    ans += 1
    wanted[suffix_hashes[0]].add(S[0])
        
# print(wanted)
print(ans)
### BUGGY CODE ###

import math as m

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

list = []
flag = 0

list += [m.floor(A * 0 / B) - A * m.floor(0 / B)]

for x in range(1, N + 1):
  list += [m.floor(A * x / B) - A * m.floor(x / B)]
  if list[x] < list[x - 1]:
    print(list[x - 1])
    flag = 1
    break

if flag == 0: print(max(list))

### FIXED CODE ###

import math as m
A, B, N = map(int, input().split())
if N >= B: print(m.floor(A * -1 / B) - A * m.floor(-1 / B))
else: print(m.floor(A * N / B) - A * m.floor(N / B))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
 
b=list(set(a))
c=0
for i in b:
    k = a.count(i)
    c+= k-i if k-i>=0 else k
print(c)

### FIXED CODE ###

from collections import Counter

n=int(input())
a=list(map(int,input().split()))
counter=Counter(a)
b=list(set(a))
c=0
for i in b:
    k =  counter[i]
    c+= k-i if k-i>=0 else k
print(c)
### BUGGY CODE ###


S = input()
length = len(S)
ans = 0
l=0
while l+2 < length:
  s = S[l:l+3]
  if s == "ABC":
    ans += 1
    S = S[:l] + "BCA" + S[l+3:]
    l -= 2
  else:
    l += 1

  l = max(0, l)

print(ans)

### FIXED CODE ###

S = input()
S = S.replace('BC', 'D')
length = len(S)

ans = 0
count_a = 0
for i in range(length):
  c = S[i]

  if c == 'A':
    count_a += 1
  elif c == 'D':
    ans += count_a
  else:
    count_a = 0

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


n, q = map(int,input().split())
s = input()

landq = [list(map(int,input().split())) for i in range(q)]

def ac_checker(s_line):
    cnt = 0
    while 'AC' in s_line:
        cnt += 1
        s_line = s_line.replace('AC','',1)
        
    return cnt

for i in range(q):
    part_s = s[(landq[i][0]-1):(landq[i][1])]
    print(ac_checker(part_s))

### FIXED CODE ###


n, q = map(int,input().split())
s = input()

t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)

for i in range(q):
    l,r = map(int,input().split())
    print(t[r-1] - t[l-1])
### BUGGY CODE ###

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

max_bit_length = len(format(2**60-1, "b"))
one_list = [[] for i in range(max_bit_length)]
zero_list = [[]for i in range(max_bit_length)]
for i in num_list:
  num = i
  bit_num = format(num, "b")
  for j in range(1, len(bit_num)+1):
    check_num = int(bit_num[-j])
    if check_num:
      one_list[j-1].append(1)
    else:
      zero_list[j-1].append(1)
  for k in range(1, (max_bit_length-len(bit_num))+1):
    zero_list[-k].append(1)
ans = 0
radix = 1
for k,l in zip(one_list, zero_list):
  ans += radix*(len(k)*len(l))
  radix *= 2
print(ans%(10**9+7)) 

### FIXED CODE ###

import numpy as np
N = int(input())
num_list = np.array(input().split(), dtype="int")

max_num = max(num_list)
max_bit_num = format(max_num, "b")
max_bit_num_length = len(max_bit_num)
ans = 0
radix = 1
for i in range(max_bit_num_length):
  new_num_list = (num_list >> i) & 1
  one_amount = np.count_nonzero(new_num_list == 1)
  zero_amount = len(num_list) - one_amount
  ans += (one_amount*zero_amount)*radix
  radix *= 2
print(ans%(10**9+7))
### BUGGY CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=0
for i in range(n-k+1):
  cnt=0
  for j in range(i,i+k):
    cnt+=(p[j]+1)/2
  ans=max(ans,cnt)
print(ans)

### FIXED CODE ###

def cal(x): return (x+1)/2
n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=sum([cal(p[i]) for i in range(k)])
cnt=ans
for i in range(k,n):
  cnt=cnt-cal(p[i-k])+cal(p[i])
  ans=max(ans,cnt)
print(ans)
### BUGGY CODE ###

import sys
import copy
n = int(input())
x = list(map(int, sys.stdin.readline().split()))
y = sorted(x)
for i in x:
    tmp = copy.copy(y)
    tmp.remove(i)
    print(tmp[n//2-1])

### FIXED CODE ###

import sys
import copy
n = int(input())
x = list(map(int, sys.stdin.readline().split()))
y = sorted(x)
for i in x:
    if y[n//2] > i:
        print(y[n//2])
    else:
        print(y[n//2-1])
### BUGGY CODE ###

def inpl(): return [int(i) for i in input().split()]
import sys 
N = int(input())
A = [inpl() for _ in range(N)]
ans = 0
for i in range(N):
    A[i][i] = float('inf')
for i in range(N):
    for j in range(i):
        mindis = min([A[i][k] + A[j][k] for k in range(N)])
        if mindis > A[i][j]:
            ans += A[i][j]
            continue
        if mindis < A[i][j]:
            print(-1)
            sys.exit()

print(ans)

### FIXED CODE ###

def inpl(): return [int(i) for i in input().split()]
import sys
import numpy 
N = int(input())
A = numpy.asarray([inpl() for _ in range(N)])
ans = 0
for i in range(N):
    A[i][i] = 10**9+1
for i in range(N):
    for j in range(i):
        mindis = numpy.min([A[i] + A[j]])
        if mindis > A[i][j]:
            ans += A[i][j]
            continue
        if mindis < A[i][j]:
            print(-1)
            sys.exit()

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

R, G, B, N = map(int, input().split())
     
ans = 0
for r in range(int(N/R)+1):
    for g in range(int(N/G)+1):
        if r*R + g*G <= N:
            if (N - (r*R + g*G))%B == 0:
                ans += 1
        else:
            break
     
print(ans)

### FIXED CODE ###

R, G, B, N = map(int, input().split())
     
ans = 0
for r in range(int(N/R)+1):
    for g in range(int(N/G)+1):
        if r*R + g*G <= N:
            if (N - (r*R + g*G))%B == 0:
                ans += 1
     
print(ans)
### BUGGY CODE ###

#create date: 2020-08-06 09:16

import sys
stdin = sys.stdin
from bisect import bisect_left

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    b = na()
    c = na()
    a.sort()
    b.sort()
    c.sort()
    cnt = 0
    for ci in c:
        i = bisect_left(b, ci)
        if i == 0:
            continue
        for bi in b[:i]:
            j = bisect_left(a, bi)
            cnt += j
    print(cnt)

if __name__ == "__main__":
    main()

### FIXED CODE ###

#create date: 2020-08-06 09:16

import sys
stdin = sys.stdin
from bisect import bisect_left, bisect_right

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    b = na()
    c = na()
    a.sort()
    b.sort()
    c.sort()
    cnt = 0
    #print(a, b, c)
    for bi in b:
        i = bisect_left(a, bi)
        j = bisect_right(c, bi)
        cnt += i * (n-j)
        #print(bi, i, n-j)
    print(cnt)

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

N=int(input()) 
a=[int(input()) for i in range(N)]
b=sorted(a)
n=0
while True:
    if n==a.index(max(a)):
        print(b[-2])
    else:
        print(b[-1])
    n+=1
    if n==N:
        break

### FIXED CODE ###

import sys
input=sys.stdin.readline
N=int(input()) 
a=[int(input()) for i in range(N)]
b=sorted(a)
n=0
c=a.index(max(a))
for n in range(N):
    if n==c:
        print(b[-2])
    else:
        print(b[-1])
### BUGGY CODE ###

# coding: utf-8
# Your code here!

K = int(input())

Sequence = 0
flag = 0
for i in range(K) : 
    Sequence += 7*(10**i)

    if Sequence % K == 0 : 
        flag = 1
        break

if flag == 1 : 
    print(i+1)
else : 
    print(-1)

### FIXED CODE ###

# coding: utf-8
# Your code here!

K = int(input())

s = 7 % K
for i in range(1, K+1) : 
    if i != 1 : 
        s = (10*s + 7) % K

    if s == 0 : 
        print(i)
        exit()

print(-1)
### BUGGY CODE ###

import numpy as np
N,K,Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
x = np.array([K]*N)
x_1 = np.array([-1]*N)
for j in range(Q):
    answer = A[j]-1
    x = x+x_1
    x[answer] =x[answer]+1
for k in range(N):
    if x[k]>=1:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

import numpy as np
N,K,Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
x = np.array([K-Q]*N)
for j in range(Q):
    x[A[j]-1]+=1
for k in range(N):
    if x[k]>=1:
        print('Yes')
    else:
        print('No')