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

MOD = 998244353

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

total = sum(a)
sup = (total - 1) // 2

# total > 2 * max(R,G,B)
# を満たすR,G,Bの場合の数
# (total - 1) // 2 >= max(R,G,B)

dp = [[[0 for _ in range(total + 1)] for _ in range(total + 1)] for _ in range(N + 1)]
dp[0][0][0] = 1
# dp[i][R][G]:=i番目まででRGとなる総数

# 枝刈り
# sup = (total - 1) // 2
# sup >= max(R,G,B)
# supを超えるRGBはdp遷移時にカット

for i in range(N):
    # a[i]はRGBのいずれかに加算
    for s in range(2 * sup + 1):
        for r in range(min(s, sup) + 1):
            g = s - r
            if r - a[i] >= 0:
                dp[i + 1][r][g] += dp[i][r - a[i]][g]
                dp[i + 1][r][g] %= MOD
            if g - a[i] >= 0:
                dp[i + 1][r][g] += dp[i][r][g - a[i]]
                dp[i + 1][r][g] %= MOD
            dp[i + 1][r][g] += dp[i][r][g]
            dp[i + 1][r][g] %= MOD
            # Bに対応

ans = 0
for r in range(sup + 1):
    for g in range(sup + 1):
        if total - r - g > sup: continue
        ans += dp[N][r][g]
        ans %= MOD
print(ans)


### FIXED CODE ###

# https://atcoder.jp/contests/tenka1-2019/submissions/5065329

import sys

input = sys.stdin.readline

N = int(input())
a = [int(input()) for _ in range(N)]
total = sum(a)
MOD = 998244353

'''(1)全体'''
U = pow(3, N, MOD)  # 三角形を構成できない場合を含むRGBの組み合わせ総数

'''(2)単円'''
dp = [[0] * (total + 1) for _ in range(N + 1)]
dp[0][0] = 1
# dp[i][R]:=i番目まででRとなる場合の数

for i in range(N):
    for r in range(total + 1):
        if r - a[i] >= 0:
            dp[i + 1][r] += dp[i][r - a[i]]
        dp[i + 1][r] += 2 * dp[i][r]
        dp[i + 1][r] %= MOD
        # g, bに加算する分で、2回起こる
# print(dp)

single_circle = 0
for r in range(total + 1):
    if r >= (total / 2):
        single_circle += dp[N][r]
# print(single_circle)

'''(3)２円の積集合'''
if total % 2 == 0:
    dp2 = [[0] * (total + 1) for _ in range(N + 1)]
    dp2[0][0] = 1
    # dp[i][R]:=i番目まででRとなる場合の数

    for i in range(N):
        for r in range(int(total / 2) + 1):
            if r - a[i] >= 0:
                dp2[i + 1][r] += dp2[i][r - a[i]]
            dp2[i + 1][r] += dp2[i][r]
            dp2[i + 1][r] %= MOD
    # print(dp2)

two_circle_intersect = dp2[N][int(total / 2)] if total % 2 == 0 else 0

'''(3)３円の積集合'''
three_circle_intersect = 0

'''(4)解答'''
ans = 0

ans += U
ans %= MOD

ans -= 3 * single_circle
ans %= MOD

ans += 3 * two_circle_intersect
ans %= MOD

ans -= three_circle_intersect
ans %= MOD

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

from collections import deque

H,W=[int(i) for i in input().split()]
C=[input() for _ in range(H)]
C=[list(i) for i in C] 

if C[0][0] == "#": stack = deque([[0,0,1]])
else: stack = deque([[0, 0, 0]])
ans = 10**9

visited_list = [[10**9]*W for _ in range(H)]
visited_list[0][0] = 0

def dfs(town, visited_list, stack):
    global ans
    while len(stack) > 0:
        h, w, cnt = stack.pop()
        if h == H-1 and w == W-1:
            # print(h,w,cnt)
            if ans > cnt:
                ans = cnt
                continue
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or new_w < 0 or new_w >= W:
                continue
            if town[new_h][new_w] != "#" and visited_list[new_h][new_w] > cnt:
                visited_list[new_h][new_w] = cnt
                stack.append([new_h, new_w, cnt])
            elif town[new_h][new_w] == "#" and visited_list[new_h][new_w] > cnt + 1:
                visited_list[new_h][new_w] = cnt + 1
                # print("a " + str(cnt+1))
                stack.append([new_h, new_w, cnt+1])
    return ans

print(dfs(C, visited_list, stack))

### FIXED CODE ###

from collections import deque

H,W=[int(i) for i in input().split()]
C=[input() for _ in range(H)]
C=[list(i) for i in C] 

ans = 10**9

visited_list = [[10**9]*W for _ in range(H)]

if C[0][0] == "#": 
    stack = deque([[0, 0, 1]])
    visited_list[0][0] = 1
else:
    stack = deque([[0, 0, 0]])
    visited_list[0][0] = 0

def dfs(town, visited_list, stack):
    global ans
    while len(stack) > 0:
        h, w, cnt = stack.pop()
        if h == H-1 and w == W-1 and ans > cnt:
            ans = cnt
            continue
        for j, k in ([1, 0], [0, 1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or new_w < 0 or new_w >= W:
                continue
            if  town[new_h][new_w] != "#" and visited_list[new_h][new_w] > cnt:
                visited_list[new_h][new_w] = cnt
                stack.append([new_h, new_w, cnt])
            elif town[h][w] == "#" and town[new_h][new_w] == "#" and visited_list[new_h][new_w] > cnt:
                visited_list[new_h][new_w] = cnt
                stack.append([new_h, new_w, cnt])
            elif town[new_h][new_w] == "#" and visited_list[new_h][new_w] > cnt + 1:
                visited_list[new_h][new_w] = cnt + 1
                # print("a " + str(cnt+1))
                stack.append([new_h, new_w, cnt+1])
    return ans

print(dfs(C, visited_list, stack))
### BUGGY CODE ###

def gcd(a, b):
    while a:
        b, a = a, b % a
    return b


s = 0

n = int(input())
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
                s += gcd(gcd(i,j), k)

#s = s*6 + t*3 + int(n*(n+1)*0.5)
print(s)

### FIXED CODE ###

def gcd(a, b):
    while a:
        b, a = a, b % a
    return b


s = 0
n = int(input())


for i in range(1, n+1):
    for j in range(i+1, n+1):
        for k in range(j+1, n+1):
            s += gcd(gcd(i,j), k)

for i in range(1, n+1):
    for j in range(i+1, n+1):
        s += gcd(i, j)

s = s*6 + int(0.5 * n * (n+1))
print(s)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
M=10**9+7
each=[]
for i in range(n-1):
  for j in range(i+1,n):
    each.append(a[i]^a[j])
print(sum(each)%M)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
M=10**9+7

ans = 0
for i in range(61):
  ones=sum([1 for a in A if (a>>i)&1])
  ans += (1<<i)*ones*(N-ones)
  ans %= M

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

n,c=map(int,input().split())
pos=[list(map(int,input().split())) for _ in range(n)]
if c==2:
  ans=10**20
  for i in range(n):
    x1,y1=pos[i]
    for j in range(i+1,n):
      x2,y2=pos[j]
      w=abs(x1-x2)
      h=abs(y1-y2)
      ans=min(ans,w*h)
  print(ans)
elif c==3:
  ans=10**20
  for i in range(n):
    x1,y1=pos[i]
    for j in range(i+1,n):
      x2,y2=pos[j]
      for k in range(j+1,n):
        x3,y3=pos[k]
        rx1,rx2=min(x1,x2,x3),max(x1,x2,x3)
        ry1,ry2=min(y1,y2,y3),max(y1,y2,y3)
        cnt=0
        for l in range(n):
          if rx1<=pos[l][0]<=rx2 and ry1<=pos[l][1]<=ry2:
            cnt+=1
        if cnt>=c:
          w=abs(rx1-rx2)
          h=abs(ry1-ry2)
          ans=min(ans,w*h)
  print(ans)
else:
  ans=10**20
  for i in range(n):
    x1,y1=pos[i]
    for j in range(i+1,n):
      x2,y2=pos[j]
      for k in range(j+1,n):
        x3,y3=pos[k]
        for l in range(k+1,n):
          x4,y4=pos[l]
          rx1,rx2=min(x1,x2,x3,x4),max(x1,x2,x3,x4)
          ry1,ry2=min(y1,y2,y3,y4),max(y1,y2,y3,y4)
          cnt=0
          for l in range(n):
            if rx1<=pos[l][0]<=rx2 and ry1<=pos[l][1]<=ry2:
              cnt+=1
          if cnt>=c:
            w=abs(rx1-rx2)
            h=abs(ry1-ry2)
            ans=min(ans,w*h)
  print(ans)

### FIXED CODE ###

n,c=map(int,input().split())
xpos=[]
ypos=[]
pos=[]
for _ in range(n):
  x,y=map(int,input().split())
  xpos.append(x)
  ypos.append(y)
  pos.append([x,y])
xpos=sorted(xpos)
ypos=sorted(ypos)
ans=10**20
for i in range(n):
  for j in range(i+1,n):
    for k in range(n):
      for l in range(k+1,n):
        lx,rx=xpos[i],xpos[j]
        ly,ry=ypos[k],ypos[l]
        cnt=0
        for tx,ty in pos:
          if lx<=tx<=rx and ly<=ty<=ry:
            cnt+=1
        if cnt>=c:
          ans=min(ans,(rx-lx)*(ry-ly))
print(ans)
### BUGGY CODE ###

S = raw_input()
count = 0
flag = True
while(flag):
    if '01' in S:
        S = S.replace('01','',1)
        count += 2                                                                                                  
    elif '10' in S:
        S = S.replace('10','',1)
        count += 2
    else:
        flag = False
print count


### FIXED CODE ###

S = raw_input()
print 2*min(S.count('0'), S.count('1'))
### BUGGY CODE ###

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a.copy()
cost = sum(s_cost)
orig_list = list(range(N))
index_list = orig_list.copy()
for k in range(1,N):
    index_list = [x-1 for x in index_list]
    index_list =  [x%N for x in index_list]
    s_cost = [min(s_cost[x],a[y]) for (x,y) in zip( orig_list, index_list )]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break

print(cost)


### FIXED CODE ###

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a.copy()
cost = sum(s_cost)
for k in range(1,N):
    for i in range(N):
        if s_cost[i] > a[(i-k)%N] :
            s_cost[i] = a[(i-k)%N]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break

print(cost)
### BUGGY CODE ###

from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
temp = None
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if (a + b + c == K):
                if (temp is None):
                    temp = a - c
                else:
                    if (temp < a - c):
                        temp = a - c
print(temp)


### FIXED CODE ###

from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if (A >= K):
    print(K)
else:
    if (B >= (K - A)):
        print(A)
    else:
        print(2*A + B - K)
### BUGGY CODE ###

l = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]
z = [int(x) for x in input().split()]

result_l = []
for i in x:
    for j in y:
        for k in z:
            result_l.append(i+j+k)
result_l.sort(reverse=True)
for ind in range(l[-1]):
    print(result_l[ind])

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A = sorted([int(x) for x in input().split()], reverse=True)
B = sorted([int(x) for x in input().split()], reverse=True)
C = sorted([int(x) for x in input().split()], reverse=True)

bi_comb = []
for i in range(min(X, K)):
    for j in range(min(Y, K)):
        if (i+1)*(j+1) > K:
            break
        bi_comb.append(A[i] + B[j])
bi_comb.sort(reverse=True)

tri_comb = []
for k in range(min(len(bi_comb), K)):
    for l in range(min(Z, K)):
        if (k+1)*(l+1) > K:
            break
        tri_comb.append(bi_comb[k] + C[l])
tri_comb.sort(reverse=True)

print(*tri_comb[:K], sep="\n")
### BUGGY CODE ###

N,K = map(int, input().split())
P = list(map(int, input().split()))
Ex = {}
for i in range(1,1001):
    Ex[i] = sum([x*1/i for x in range(1, i+1)])

P_ex = []
for t in P:
    P_ex.append(Ex[t])

Sum = []
for l in range(len(P_ex)):
    Sum.append(sum(P_ex[l:l+K]))

print(max(Sum))

### FIXED CODE ###

N,K = map(int, input().split())
P = list(map(int, input().split()))
P_sum = 0
for i in range(K):
    P_sum += P[i]
P_max = P_sum
for i in range(N-K):
    P_sum = P_sum + P[K+i]-P[i]
    if P_sum > P_max:
        P_max = P_sum
print(P_max/2+0.5*K)
### BUGGY CODE ###

n = int(input())
s = input()
cnt = s.count('R') * s.count('G') * s.count('B')
for i in range(n - 1):
  for j in range(i + 1, n):
    try:
      if len(set([s[i], s[j], s[2 * j - i]])) == 3:
        cnt -= 1
    except IndexError:
      pass
print(cnt)

### FIXED CODE ###

n = int(input())
s = input()
cnt = s.count('R') * s.count('G') * s.count('B')
for i in range(n - 1):
  for j in range(i + 1, n):
    if 2 * j - i <= n - 1 and len(set([s[i], s[j], s[2 * j - i]])) == 3:
      cnt -= 1
print(cnt)
### BUGGY CODE ###

K,S=map(int, input().split())
count=0
for i in range(0,K+1):
  for j in range(0,K+1):
    for k in range(0,K+1):
      if i+j+k==S:count+=1
print(count)

### FIXED CODE ###

K,S=map(int, input().split())
print(len([1 for x in range(K+1) for y in range(K+1) if 0<=S-x-y<=K]))
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
BC=list(list(map(int,input().split())) for  _ in range(M))
BC.sort(key=lambda x: x[1],reverse=True)
for i in range(M):
    for j in range(BC[i][0]):
        if A[0]<BC[i][1]:
            A.pop(0)
            A.append(BC[i][1])
print(sum(A))


### FIXED CODE ###

N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key = lambda x: -x[1])

for B, C in BC:
  A.extend([C]*B)
  if len(A) > N*2:
    break
A.sort(reverse = True)
print(sum(A[:N]))
### BUGGY CODE ###

N, M = map(int, input().split())
a = []
b = []
for i in range(M):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

c = []
clear = 0

for i in range(M):
    if b[i] == N:
        c.append(a[i])

for i in range(M):
    if a[i] == 1 and b[i] in c:
        clear = 1
        break

if clear == 1:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')




### FIXED CODE ###

N, M = map(int, input().split())
a = []
b = []
for i in range(M):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

c = []
d = []

for i in range(M):
    if a[i] == 1:
        c.append(b[i])

for i in range(M):
    if b[i] == N:
        d.append(a[i])

e = set(c) & set(d)

if len(e) != 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

from collections import Counter

def solve():
  n = int(input())
  A = list(map(int, input().split()))

  # 書かれた番号の頻度
  Freq = Counter(A)

  for a in A:
    ans = 0
    for kv in Freq.items():
      # key -> value : 番号 -> ボール個数
      cnt = kv[1]
      # 自身は取り除く
      if kv[0] == a: cnt -= 1
      # 2個未満はスキップ
      if cnt < 2: continue
      # 2つ選ぶ方法は n*(n-1)//2
      ans += cnt * (cnt-1) // 2
    print(ans)

solve()

### FIXED CODE ###

from collections import Counter

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

# 書かれた番号の頻度
Freq = dict(sorted(Counter(A).items(), key=lambda x: x[1], reverse=True))

# 答えの最大値
ans_max = 0
for kv in Freq.items():
  ans_max += kv[1] * (kv[1] - 1) // 2

for a in A:
  # 1個しか存在しない番号は、取り除いても答えに影響しない
  if Freq.get(a) == 1:
    print(ans_max)
    continue

  # x個の場合と、x-1個の場合と、の差分
  x = Freq.get(a)
  diff = (x * (x-1) // 2) - ((x-1) * (x-2) // 2)

  # そのぶんだけ、答えの最大値から減らす
  ans = ans_max - diff
  print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7
num = tuple(num)

from collections import Counter
def factorization(a):
        yy, j = [], 2
        y = yy.append
        while(a > 1):
            for i in range(j, int(a**0.5)+1):
                if a % i == 0:
                    y(i)
                    a, j = a//i, i
                    break
            else:
                y(a)
                break
        return Counter(yy)

lcd = dict()
for i in num:
  j = factorization(i)
  for x,y in j.items():
    if not x in lcd.keys():
      lcd[x] = y
    else:
      lcd[x] = max(lcd[x],y)

lc = 1
for i,j in lcd.items():
  lc *= pow(i,j,mod)
  
ans =0
for i in range(n):
  ans += lc*pow(num[i], mod-2, mod)
  ans %= mod
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7

import fractions
lc = num[0]
for i in range(1, n):
    lc = lc * num[i] // fractions.gcd(lc, num[i])

lc %= mod    
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

ans =0
for i in range(n):
  ans += lc*modinv(num[i],mod)
  ans %= mod
print(ans)
### BUGGY CODE ###

n,q=map(int,input().split())
a=[0]*(n-1)
b=[0]*(n-1)
for i in range(n-1):
    a[i],b[i]=map(int,input().split())
p=[0]*q
x=[0]*q
for k in range(q):
    p[k],x[k]=map(int,input().split())
t=[[i] for i in range(1,n+1)]
for i in range(n-1):
    if a[i] not in t[a[i]-1]:
        t[a[i]-1].append(a[i])
    if b[i] not in t[a[i]-1]:
        t[a[i]-1].append(b[i])
for i in range(n):
    for j in t[i]:
        for y in t[j-1]:
            if y not in t[i]:        
                t[i].append(y)
ans=[0 for _ in range(n)]
g=0
for k in p:
    for j in t[k-1]:
        ans[j-1]+=x[g]
    g+=1  
print(' '.join(map(str,ans)))


### FIXED CODE ###

import sys
input = sys.stdin.readline
n,q=map(int,input().split())
a=[[0,0] for _ in range(n-1)]
for i in range(n-1):
    a[i][0],a[i][1]=map(int,input().split())
a.sort()
p=[[0,0] for _ in range(q)]
for k in range(q):
    p[k][0],p[k][1]=map(int,input().split())
p.sort()
t=[[i] for i in range(1,n+1)]
ans=[0 for _ in range(n)]
for i in range(q):
    ans[p[i][0]-1]+=p[i][1]
for i in range(n-1):
    ans[a[i][1]-1]+=ans[a[i][0]-1]  
print(' '.join(map(str,ans)))
### BUGGY CODE ###

N = input()
N = int(N)
A = input().split()

Y = 1
for i in range(N):
    X = A[i]
    X = int(X)
    Y = Y * X

M = 10 ** 18

if Y > M:
    print(-1)
else:
    print(Y)

### FIXED CODE ###

N = input()
N = int(N)
A = input().split()

minA = min(A)
minA = int(minA)
M = 10 ** 18

Y = 0
if minA != 0:
    Y = 1
    for i in range(N):
        X = A[i]
        X = int(X)
        Y = Y * X
        if Y > M:
            break


if Y > M:
    print(-1)
else:
    print(Y)
### BUGGY CODE ###

def resolve():
    '''
    code here
    '''
    H, W, M = [int(item) for item in input().split()]
    targets = [[int(item) -1 for item in input().split()] for _ in range(M)]

    col = [0 for _ in range(H)]
    row = [0 for _ in range(W)]

    bomb_set = set()
    # 配列で要素を作ると要素数が$10^8$超える場合、setで要素の座標を持っておく


    for i,j in targets:
        col[i] += 1
        row[j] += 1
        bomb_set.add((i,j))

    max_col = max(col)
    max_row = max(row)
    max_col_index = []
    max_row_index = []

    for i in range(H):
        if col[i] == max_col:
            max_col_index.append(i)

    for i in range(W):
        if row[i] == max_row:
            max_row_index.append(i)

    res = 0
    for item in max_col_index:
        for jtem in max_row_index:
            if (item,jtem) in bomb_set:
                res = max(res, max_col + max_row -1)
            else:
                res = max(res, max_col + max_row)
    print(res)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    H, W, M = [int(item) for item in input().split()]
    targets = [[int(item) -1 for item in input().split()] for _ in range(M)]

    col = [0 for _ in range(H)]
    row = [0 for _ in range(W)]

    bomb_set = set()
    # 配列で要素を作ると要素数が$10^8$超える場合、setで要素の座標を持っておく


    for i,j in targets:
        col[i] += 1
        row[j] += 1
        bomb_set.add((i,j))

    max_col = max(col)
    max_row = max(row)
    max_col_index = []
    max_row_index = []

    for i in range(H):
        if col[i] == max_col:
            max_col_index.append(i)

    for i in range(W):
        if row[i] == max_row:
            max_row_index.append(i)

    res = 0
    for item in max_col_index:
        for jtem in max_row_index:
            if (item,jtem) not in bomb_set:
                res =max_col + max_row
                break
        else:
            res = max(res, max_col + max_row -1 )
    print(res)

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

import sys
input=sys.stdin.readline
H,W,M=map(int,input().split())#slow,行数H、列数W、爆弾数M
hcnt=[0]*H#何行目に何個あるか
wcnt=[0]*W#何列目に何個あるか
bomb=[]
cnt=0

for i in range(M):
    bh,bw=map(int,input().split())
    hcnt[bh-1]+=1#行方向
    wcnt[bw-1]+=1#列方向
    if bomb.count([bh-1,bw-1])==0:
        bomb.append([bh-1,bw-1])
hmax=max(set(hcnt))
wmax=max(set(wcnt))
for i in range(H):
    for j in range(W):
        if hcnt[i]==hmax and wcnt[j]==wmax and bomb.count([i,j])==0:
            cnt+=1

if cnt>0:
    print(hmax+wmax)
else:
    print(hmax+wmax-1)

### FIXED CODE ###


import sys
from collections import Counter

H, W, M = map(int, sys.stdin.readline().rstrip().split())#行数H、列数W、爆弾数M
hcnt = [0] * H#何行目に何個あるか
wcnt = [0] * W#何列目に何個あるか
bomb = []

for i in range(M):
    bh,bw=map(int,sys.stdin.readline().rstrip().split())
    hcnt[bh - 1] += 1#行方向
    wcnt[bw - 1] += 1#列方向
    bomb.append((bh - 1,bw - 1))
#hcnt [2,1]
#wcnt[1,1,1]
#bomb[[1,1],[0,0],[0,2]]
hmax = max(hcnt)#2
wmax = max(wcnt)#1

crs = 0#hmax and wmax crosspoint
for (i, j) in bomb:
    if hcnt[i] == hmax and wcnt[j] == wmax:
        crs += 1
#all crosspoint has bomb
if crs == Counter(hcnt)[hmax] * Counter(wcnt)[wmax]:
    print(hmax + wmax - 1)
#more than one crosspoint has no bomb
else:
    print(hmax + wmax)
### BUGGY CODE ###

n = int(input())
v = list(sorted(map(int, input().split())))

total = 0
for i, x in enumerate(v[:n-2]):
    for j, y in enumerate(v[i+1:n-1]):
        for k, z in enumerate(v[i+j+2:]):
            if z >= x + y:
                break
            total += 1



print(total)

### FIXED CODE ###

n = int(input())
v = list(sorted(map(int, input().split())))
v.append(2000)
total = n*(n-1)*(n-2) / 6



def bs(left, s):
    right = n+1
    while left < right-1:
        m = (right+left)//2

        if v[m]>=s:
            right = m
        else:
            left = m
    return left+1






for i, x in enumerate(v[:-2]):
    for j, y in enumerate(v[i+1:-1]):
        k = bs(j+1, y+x)
        total -= (n-k)

print(int(total))
### BUGGY CODE ###

nm = input().split()
n = int(nm[0])
m = int(nm[1])
X = input().split()
Y = input().split()
X = map(int, X)
X = list(X)
Y = map(int, Y)
Y = list(Y)
T = 0
S = 0
for i in range(n - 1):
	x1 = X[i]
	x2 = X[i + 1]
	for j in range(m - 1):
		s = (x2 - x1) * (Y[j + 1] - Y[j])
		s = (j + 1) * (m - j - 1) * s
		S += s
	T += (i + 1) * (n - i - 1) * S
	S = 0
ans = T % 1000000007
print(ans)

### FIXED CODE ###

#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	x = getlist()
	y = getlist()
	X = 0
	Y = 0
	for i in range(N - 1):
		X += ((x[i + 1] - x[i]) * (i + 1) * (N - i - 1)) % con
		X %= con
	for i in range(M - 1):
		Y += ((y[i + 1] - y[i]) * (i + 1) * (M - i - 1)) % con
		Y %= con
	print(X * Y % con)


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

from sys import stdin

def main():
  def find(parent, i):
    t = parent[i]
    if t == -1:
      return i
    t = find(parent, t)
    parent[i] = t
    return t

  def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
      return
    parent[i] = j

  from builtins import int, map, range
  readline = stdin.readline

  n, k, l = map(int, readline().split())

  roads = [-1] * n
  rails = [-1] * n

  for i in range(k):
    p, q = map(int, readline().split())
    unite(roads, p - 1, q - 1)

  for i in range(l):
    p, q = map(int, readline().split())
    unite(rails, p - 1, q - 1)

  d = {}
  for i in range(n):
    t = (find(roads, i), find(rails, i))
    if t in d:
      d[t] += 1
    else:
      d[t] = 1

  print(*[d[(find(roads, i), find(rails, i))] for i in range(n)])

main()


### FIXED CODE ###

from sys import stdin

def find(parent, i):
  if parent[i] == i:
    return i
  parent[i] = find(parent, parent[i])
  return parent[i]

def unite(parent, i, j):
  i = find(parent, i)
  j = find(parent, j)
  if i == j:
    return
  parent[i] = j

n, k, l = map(int, stdin.readline().split())

roads = list(range(n))
rails = list(range(n))

for i in range(k):
  p, q = map(int, stdin.readline().split())
  unite(roads, p - 1, q - 1)

for i in range(l):
  p, q = map(int, stdin.readline().split())
  unite(rails, p - 1, q - 1)

d = {}
for i in range(n):
  t = (find(roads, i), find(rails, i))
  if t in d:
    d[t] += 1
  else:
    d[t] = 1

print(*[d[(find(roads, i), find(rails, i))] for i in range(n)])