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

H,W=map(int,input().split())
A=[[int(i) for i in input().split()] for j in range(H)]
B=[[int(i) for i in input().split()] for j in range(H)]
dp=[[set() for j in range(W)] for i in range(H)]
dp[0][0].add(A[0][0]-B[0][0])
dp[0][0].add(B[0][0]-A[0][0])
for i in range(H):
    for j in range(W):
        dij=A[i][j]-B[i][j]
        if i>0:
            for x in dp[i-1][j]:
                dp[i][j].add(x+dij)
                dp[i][j].add(x-dij)
        if j>0:
            for y in dp[i][j-1]:
                dp[i][j].add(y+dij)
                dp[i][j].add(y-dij)
ans=10**10
for i in dp[-1][-1]:
    if abs(i)<ans:
        ans=abs(i)
print(ans)

### FIXED CODE ###

H,W=map(int,input().split())
A=[[int(i) for i in input().split()] for j in range(H)]
B=[[int(i) for i in input().split()] for j in range(H)]
dp=[[0 for j in range(W)] for i in range(H)]
M=161*161
dp[0][0]|=1<<(A[0][0]-B[0][0]+M)
dp[0][0]|=1<<(-A[0][0]+B[0][0]+M)

for i in range(H):
    for j in range(W):
        dij=abs(A[i][j]-B[i][j])
        if i>0:
            dp[i][j]|=dp[i-1][j]<<dij
            dp[i][j]|=dp[i-1][j]>>dij
        if j>0:
            dp[i][j]|=dp[i][j-1]>>dij
            dp[i][j]|=dp[i][j-1]<<dij
ans=[]
for k in range(2*M+1):
    if (1<<k)&dp[-1][-1]!=0:
        ans.append(abs(k-M))
print(min(ans))
### BUGGY CODE ###

n = int(input())
i = 1

while True:
    x = i
    if  x % 3 == 0:
        print(" %d" , i, end="")
        i+=1
        if i > n:
            print()
            break
    if x % 10 == 3:
        print(" %d" ,i, end="")
        i+=1
        if i > n:
            print()
            break
    else:
        x /= 10
        if x != 0:
            if x % 10 == 3:
                print(" %d" ,i,  end="")
                i+=1
                if i > n:
                    print()
                    break


### FIXED CODE ###

#
# 5d
#

def main():
    n = int(input())
    s = ""
    for i in range(1, n+1):
        x = i
        if x % 3 == 0 or x % 10 == 3:
            s += " " + str(i)
        else:
            x //= 10
            while x:
                if x % 10 == 3:
                    s += " " + str(i)
                    break
                x //= 10
    print(s)


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

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

p = 0

for a in range(1, n+1):
    for b in range(a, n+1):
        if not (a+b)%k == 0:
            pass
        else:
            for c in range(b, n+1):
                if (b+c)%k == 0 and (c+a)%k == 0:
                    if a == b and b == c:
                        p += 1
                    elif a == b and not b == c:
                        p += 3
                    elif not a == b and  b == c:
                        p += 3
                    else:
                        p += 6
              
print( p )

### FIXED CODE ###

n, k = map( int, input().split() )
ans = int((n//k)**3)

if k%2 == 1:
    print(ans)
else:
    ans += int(((n-k//2)//k+1)**3)
    print(ans)
### BUGGY CODE ###

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

if 0 in a :
  ans = 0
else :
  ans = 1
  
for i in range(n) :
  ans *= a[i]
  if ans > 10**18 :
    ans = -1
    
print(ans)

### FIXED CODE ###

import sys

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

if 0 in a :
  print(0)
  sys.exit()

ans = 1
for i in range(n) :
  ans *= a[i]
  if ans > 10**18 :
    ans = -1
    break
    
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()

dp = [[0] * (N+1) for _ in range(N+1)]
for i in range(N):
    dp[i][i] = 0
for i in range(N-1):
    if S[i] == S[N-1]:
        dp[i][N-1] = 1

for i in range(N-2, -1, -1):
    for j in range(N-1, i, -1):
        if S[i] == S[j] and i + dp[i+1][j+1] < j:
            dp[i][j] = max(dp[i][j], dp[i+1][j+1] + 1, dp[i+1][j], dp[i][j+1])
        else:
            dp[i][j] = max(dp[i][j], dp[i+1][j], dp[i][j+1])
    
ans = max(dp[i][j] for i in range(N) for j in range(N))
print(ans)

### FIXED CODE ###

N = int(input())
S = input()

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N-2, -1, -1):
    for j in range(N-1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = min(dp[i+1][j+1] + 1, j-i)
        else:
            dp[i][j] = 0

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans = max(ans, dp[i][j])

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

n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = []

for i in range(n + 1):
    a.append(s[:i].count('AC'))

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

### FIXED CODE ###

n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
A=LI()
MEMO = {}

def dp(i, j, turn = 1):
    if i == j: return 0
    if (i,j) in MEMO: return MEMO[(i,j)]

    xy1 = dp(i, j-1, -turn) + turn*A[j-1]
    xy2 = dp(i+1, j, -turn) + turn*A[i]
    res = xy1 if turn*xy1 > turn*xy2 else xy2
    MEMO[(i,j)] = res
    return res

print(dp(0, len(A), 1))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
A=LI()
MEMO = [[0]*(N+1) for i in range(N+1)]
turn = -1 if N%2 == 0 else 1
for i in range(N): MEMO[i][i+1] = turn*A[i] 

for wid in range(2, N+1):
    turn *= -1
    for i in range(N-wid+1):
        xy1 = MEMO[i+1][i+wid] + turn*A[i]
        xy2 = MEMO[i][i+wid-1] + turn*A[i+wid-1]
        MEMO[i][i+wid] = xy1 if turn*xy1 > turn*xy2 else xy2

print(MEMO[0][N])
### BUGGY CODE ###

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

primes = [
  2,  3,  5,  7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
 71, 73, 79, 83, 89, 97,101,103,107,109,113,127,131,137,139,149,151,157,163,
167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,
271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,
389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,
503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,
631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,
757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,
883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,
1009
]

def prime_factorize(n):
    res = []
    i = 0
    while primes[i] * primes[i] <= n:
        if n % primes[i] == 0:
            res.append(primes[i])
            n //= primes[i]
        else:
            i += 1
    if n != 1:
        res.append(n)
    return res


lcm_factors = Counter()
for ai in a:
    lcm_factors |= Counter(prime_factorize(ai))

lcm = 1
for k, v in lcm_factors.items():
    lcm *= pow(k, v, MOD)
    lcm %= MOD

ans = 0
for ai in a:
    ans += lcm * pow(ai, MOD - 2, MOD)
    ans %= MOD

print(ans)

### FIXED CODE ###

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

primes = [
  2,  3,  5,  7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
 71, 73, 79, 83, 89, 97,101,103,107,109,113,127,131,137,139,149,151,157,163,
167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,
271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,
389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,
503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,
631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,
757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,
883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,
1009
]

def prime_factorize(n):
    res = []
    i = 0
    while primes[i] * primes[i] <= n:
        if n % primes[i] == 0:
            res.append(primes[i])
            n //= primes[i]
        else:
            i += 1
    if n != 1:
        res.append(n)
    return res


lcm_factors = Counter()
for ai in a:
    prime_factors = prime_factorize(ai)
    counter = Counter(prime_factors)
    for k, v in counter.items():
        if k in lcm_factors:
            lcm_factors[k] = max(lcm_factors[k], v)
        else:
            lcm_factors[k] = v

lcm = 1
for k, v in lcm_factors.items():
    lcm *= pow(k, v, MOD)
    lcm %= MOD

ans = 0
for ai in a:
    ans += lcm * pow(ai, MOD - 2, MOD)
    ans %= MOD

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

from itertools import product as pd
f=lambda x,y:(x,y) if x<y else (y,x) 
n,k=map(int,input().split())
o=[tuple(map(int,input().split())) for _ in range(n)]

def calc(a,b,c,d):
  lx,rx=f(o[a][0],o[b][0])
  dy,uy=f(o[c][1],o[d][1])
  cnt=0
  for i in o:
    if lx<=i[0]<=rx and dy<=i[1]<=uy:
      cnt+=1
  if cnt>=k:
    return (rx-lx)*(uy-dy)
  return float("inf")

v=float("inf")
for (a,c) in pd(range(n),repeat=2):
  for (b,d) in pd(range(n),repeat=2):
    v=min(v,calc(a,b,c,d))
print(v)

### FIXED CODE ###

from itertools import combinations as comb
n,k=map(int,input().split())
f=lambda x,y:(min(x,y),max(x,y))
o=[tuple(map(int,input().split())) for _ in range(n)]

v=float("inf")
for (a,b) in comb(range(n),2):
  for (c,d) in comb(range(n),2):
    lx,rx=f(o[a][0],o[b][0])
    dy,uy=f(o[c][1],o[d][1])
    cnt=0
    for i in o:
      if lx<=i[0]<=rx and dy<=i[1]<=uy:
        cnt+=1
    if cnt>=k:
      v=min(v,(rx-lx)*(uy-dy))
print(v)
### BUGGY CODE ###

import numpy as np
def main():
  H, W, D = map(int, input().split())
  num = [[] for _  in range(H*W)]
  for i in range(H):
    temp = list(map(int, input().split()))
    for j in range(len(temp)):
      num[temp[j]-1] = [i, j]
  num = np.array(num)
  num_sum = [0]*(H*W)
  for i in range(H*W-D):
    num_sum[i] = np.sum(np.abs(num[i+D::D]-num[i:H*W-D:D]))
  Q = int(input())
  for i in range(Q):
    L, R = map(int, input().split())
    print(num_sum[L-1]-num_sum[R-1])
if __name__ == "__main__":
  main()

### FIXED CODE ###

def main():
  H, W, D = map(int, input().split())
  num = [[] for _  in range(H*W)]
  for i in range(H):
    temp = list(map(int, input().split()))
    for j in range(len(temp)):
      num[temp[j]-1] = [i, j]
  #num = np.array(num)
  num_sum = [0]*(H*W)
  for i in range(D, H*W):
    num_sum[i] = num_sum[i-D] + (abs(num[i][0]-num[i-D][0])+ abs(num[i][1]-num[i-D][1]))
  Q = int(input())
  for i in range(Q):
    L, R = map(int, input().split())
    print(num_sum[R-1]-num_sum[L-1])
if __name__ == "__main__":
  main()
### BUGGY CODE ###

n,a,b=map(int,input().split())
i=0
aa=0
while n>0:
    if n<a:
        aa+=n
        break
    else:
        aa+=a
    n-=a+b
print(aa)

### FIXED CODE ###

#B
import sys
n,a,b=map(int,input().split())
if a==0:
    print(0)
    sys.exit()
else:
    s=int(n/(a+b))
    if s==0:
        m=n
    else:
        absum=(a+b)*s
        m=n%(absum)#余り
    if m<a:
        print(s*a+m)
    else:
        print((s+1)*a)
### BUGGY CODE ###

import itertools
N = int(input())
S = list(str(input()))

length = len(S)

number_list = []
for v in itertools.combinations(S, 3):
    number = ''.join(v)
    number_list.append(number)

uniq_number_list = set(number_list)

print(len(uniq_number_list))

### FIXED CODE ###

N = int(input())
S = input()

X = []
for i in range(10):
    X.append(str(i))

ans = 0
for i in X:
    if i in S:
        T = S[S.index(i) + 1:]
        for j in X:
            if j in T:
                U = T[T.index(j) + 1:]
                for k in X:
                    if k in U:
                        ans += 1

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

from itertools import product

def add_magic_move(enable_to_move_list):
  ret = list(enable_to_move_list)
  for h, w in enable_to_move_list:
    for target_h, target_w in product([h-1, h, h+1], [w-1, w, w+1]):
      if -1 < target_h < H and -1 < target_w < W and (target_h, target_w) not in enable_to_move_list:
        s[target_h][target_w] = '.'
        ret += [(target_h, target_w)]
  return ret
    

def get_enable_to_move_list(h, w, enable_to_move_list):
  if (h, w) in enable_to_move_list:
    return enable_to_move_list
  enable_to_move_list += [(h, w)]
  targets = ((h+1, w), (h-1, w), (h, w+1), (h, w-1))
  for h, w in targets:
    if -1 < h < H and -1 < w < W and s[h][w] == '.':
      enable_to_move_list = get_enable_to_move_list(h, w, enable_to_move_list)
  return enable_to_move_list

H, W = map(int, input().split())
s_h, s_w = [i-1 for i in map(int, input().split())]
d_h, d_w = [i-1 for i in map(int, input().split())]
s = [list(input()) for i in range(H)]

enable_to_move_list = get_enable_to_move_list(s_h, s_w, [])
i = 0
while True:
  if (d_h, d_w) in enable_to_move_list:
    break
  tmp = add_magic_move(enable_to_move_list)
  i += 1
  for h, w in tmp:
  	enable_to_move_list = get_enable_to_move_list(h, w, enable_to_move_list)
  if not set(tmp) ^ set(enable_to_move_list):
    i = -1
    break

print(i)

### FIXED CODE ###

from collections import deque
 
 
walk = [(1, 0), (-1, 0), (0, 1), (0, -1)]
warp = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),
        (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
        (0, -2), (0, -1), (0, 1), (0, 2),
        (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
        (2, -2), (2, -1), (2, 0), (2, 1), (2, 2),]
 
 
def get_warped(walked, map_):
    warped = deque()
    while walked:
        h, w = walked.popleft()
        for i, j in warp:
            h2 = h + i
            w2 = w + j
            if -1 < h2 < H and -1 < w2 < W and map_[h2][w2] == '.':
                warped.append((h2, w2))
                map_[h2][w2] = map_[h][w] + 1
    return warped, map_
 
 
def get_walked(candidate, map_):
    walked = deque()
    while candidate:
        h, w = candidate.popleft()
        walked.append((h, w))
        for i, j in walk:
            h2 = h + i
            w2 = w + j
            if -1 < h2 < H and -1 < w2 < W and map_[h2][w2] == '.':
                candidate.append((h2, w2))
                map_[h2][w2] = map_[h][w]
    return walked, map_
 
H, W = map(int, input().split())
s_h, s_w = [i-1 for i in map(int, input().split())]
d_h, d_w = [i-1 for i in map(int, input().split())]
map_ = [list(input()) for i in range(H)]
 
candidate = deque([(s_h, s_w)])
map_[s_h][s_w] = 0
 
while candidate:
    walked, map_ = get_walked(candidate, map_)
    candidate, map_ = get_warped(walked, map_)
 
for h in range(H):
    for w in range(W):
        if map_[h][w] == '.':
            map_[h][w] = -1
 
print(map_[d_h][d_w])
### BUGGY CODE ###

import fractions

#inp = [int(i) for i in input().split()]
inp = int(input())

task = []
for e in range(inp):
    task.append([int(i) for i in input().split()])

    so = sorted(task,key=lambda x:x[1])

    ti = 0
for dd in so:
    ti = dd[0] + ti
    if ti <= dd[1]:
        continue
    else:
        print('No')
        exit()

print('Yes')

### FIXED CODE ###

import fractions

#inp = [int(i) for i in input().split()]
inp = int(input())

task = []
for e in range(inp):
    task.append([int(i) for i in input().split()])

so = sorted(task,key=lambda x:x[1])
ti = 0

for dd in so:
    ti = dd[0] + ti
    if ti <= dd[1]:
        pass
    else:
        print('No')
        exit()

print('Yes')
### BUGGY CODE ###

n=int(input())
a=list(map(int, input().split()))
ans=1
for i in range(n):
  ans*=a[i]
  if ans==0:
    break
if ans>10**18:
  ans=-1
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int, input().split()))
if 0 in a:
  print(0)
else:
  ans=1
  a.sort(reverse=True)
  for i in range(n):
    ans*=a[i]
    if ans>10**18:
      ans=-1
      break
  print(ans)
### BUGGY CODE ###

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

new_s = []
for i, s in enumerate(s_list):
    s = list(set(s))
    new_s.append([{char, s_list[i].count(char)} for char in s])
    
match = []
M=[i for i in range(N)]
center = int(N/2)
count = 0
if N%2==0: # 偶数の時
    for i in range(N-1):
        for i in range(center):
            match.append((M[0+i],M[-1-i]))
        M = M[:1] + M[2:] + M[1:2]
else: # 奇数の時
    for i in range(N):
        for i in range(1,center+1):
            match.append((M[i],M[-i+1]))
        M = M[1:] + M[:1] # １つずつずらす
for m in match:
    if new_s[m[0]] == new_s[m[1]]:
        count += 1
print(count)

### FIXED CODE ###

N = int(input())
s_list = [input() for _ in range(int(N))]
import math
ok = {}
count = 0
for s in s_list:
    s = ''.join(sorted(s))
    if s in ok:
        ok[s] += 1 
    else:
        ok[s] = 1

for val in ok:
    prev = (ok[val] - 1)
    if prev != 0:
        count += math.floor(ok[val] * prev / 2)
print(count)
### BUGGY CODE ###

from bisect import bisect_left, bisect_right
import sys
readlines = sys.stdin.readline
def main():

	n = int(input())
	s = list(input())
	q = int(input())

	d = {}
	for i in range(n):
		d.setdefault(s[i], []).append(i)

	flag = {}
	for i in range(q):
		q1,q2,q3 = map(str,input().split())
		if q1 == '1':
			q2 = int(q2) - 1
			if s[q2] != q3:
				flag.setdefault(s[q2], []).append(q2)
				d.setdefault(q3, []).append(q2)
				flag[s[q2]].sort()
				d[q3].sort()
				s[q2] = q3
		else:
			ans = 0
			q2 = int(q2) - 1
			q3 = int(q3) - 1
			if q2 == q3:
				print(1)
				continue
			for string,l in d.items():
				res = 0
				left = bisect_left(l,q2)
				right = bisect_right(l,q3)
				if string in flag:
					left2 = bisect_left(flag[string],q2)
					right2 = bisect_right(flag[string],q3)
				else:
					left2 = 0
					right2 = 0
				if left != right:
					if right - left > right2 - left2:
						res = 1
				ans += res
				#print(string,l,res)
			print(ans)
if __name__ == '__main__':
	main()

### FIXED CODE ###

from bisect import bisect_left, bisect_right, insort_left
import sys
readlines = sys.stdin.readline
def main():

	n = int(input())
	s = list(input())
	q = int(input())

	d = {}
	flag = {}
	for i in list('abcdefghijklmnopqrstuvwxyz'):
		d.setdefault(i, []).append(-1)
		flag.setdefault(i, []).append(-1)
	for i in range(n):
		d.setdefault(s[i], []).append(i)
	for i in range(q):
		q1,q2,q3 = map(str,input().split())
		if q1 == '1':
			q2 = int(q2) - 1
			if s[q2] != q3:
				insort_left(flag[s[q2]],q2)
				insort_left(d[q3],q2)
				s[q2] = q3
		else:
			ans = 0
			q2 = int(q2) - 1
			q3 = int(q3) - 1
			if q2 == q3:
				print(1)
				continue
			for string,l in d.items():
				res = 0
				if d[string] != [-1]:
					left = bisect_left(l,q2)
					right = bisect_right(l,q3)
				else:
					left = 0
					right = 0
				if string in flag:
					left2 = bisect_left(flag[string],q2)
					right2 = bisect_right(flag[string],q3)
				else:
					left2 = 0
					right2 = 0
				if left != right:
					if right - left > right2 - left2:
						res = 1
				ans += res
				#print(string,l,res)
			print(ans)
if __name__ == '__main__':
	main()
### BUGGY CODE ###

n = int(input())
s = 0

for i in range(len(str(n))):
    s = s + int(str(n)[i])

if s % 9 == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n = int(input())
if n % 9 == 0:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

mod = 10 ** 9 + 7

n,m = map(int,input().split())

x = list(map(int,input().split()))
y = list(map(int,input().split()))

sum = 0
for i in range(n-1):
  for j in range(m-1):
    h = x[i+1] - x[i]
    v = y[j+1] - y[j]
    sum = (sum + h*v*(i+1)*(n-i-1)*(j+1)*(m-j-1)) % mod


print(sum % mod)

### FIXED CODE ###

mod = 10 ** 9 + 7

n,m = map(int,input().split())

x = list(map(int,input().split()))
y = list(map(int,input().split()))

sum_h = 0
sum_v = 0
for i in range(n-1):
  sum_h += (x[i+1] - x[i])*(i+1)*(n-i-1)
sum_h = sum_h % mod

for j in range(m-1):
  sum_v += (y[j+1] - y[j])*(j+1)*(m-j-1)
sum_v = sum_v % mod

sum = (sum_h * sum_v) % mod

#print(sum_h,sum_v)
print(sum)
### BUGGY CODE ###

#inputは文字列として取得
input1=input()
input2=input()
#splitする必要がある
input2=input2.split(" ")

N=int(input1)
D=[int(s) for s in input2]

ans=None

if D.count(0)==1 and D[0]==0:

    mul=1
    n=1

    for i in range(1,max(D)+1):
        m=D.count(i)
        mul*=n**m
        n=m
    
    ans=mul%998244353

else:
    ans=0

print(int(ans))

### FIXED CODE ###

#inputは文字列として取得
input1=input()
input2=input()
#splitする必要がある
input2=input2.split(" ")

N=int(input1)
D=[int(s) for s in input2]

ans=None


if D.count(0)==1 and D[0]==0:

    L=[0]*(max(D)+1)

    for i in range(len(D)):
        L[D[i]]+=1

    mul=1

    for i in range(len(L)-1):
        mul*=L[i]**L[i+1]%998244353
    
    ans=mul%998244353

else:
    ans=0

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

import sys
import numpy as np
input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))

for q in range(k):
  b = [0]*(n+1)
  for i in range(n):
    l = max(0, i-a[i])
    r = min(i+a[i]+1, n)
    b[l] += 1
    if r <= n-1: b[r] -= 1
  
  B = np.array(b)
  a = B.cumsum()[:-1]
  
  """[0] = b[0]
  for j in range(n-1):
    a[j+1] = a[j] + b[j+1]"""
  
  if np.all(a == n):
    break

print(*a)

### FIXED CODE ###

#%%time
from itertools import accumulate
import numpy as np
from numba import njit

n, k = map(int, input().split())
a = np.array(list(map(int, input().split())), dtype=np.int64)

@njit
def loop1(a):
  #b = [0]*(n+1)
  b = np.zeros(n+1, dtype=np.int64)
  for i in range(n):
    l = max(0, i-a[i])
    r = min(i+a[i]+1, n)
    b[l] += 1
    if r <= n-1: b[r] -= 1
  
  b = np.cumsum(b)[:-1]
  return b
  #a = list(accumulate(b))
  #a = a[:-1]
   
  #if np.all(a == n):
   # break

for q in range(min(42, k)):
  a = loop1(a)
    
print(*a)
### BUGGY CODE ###

S = input()

N = len(S)
l = [int(x) for x in list(str(S))]

count = 0
idx = 0
len_S = 0

while True:
    if len(l) == 1:
        break
    if l[idx] == 0 and l[idx+1] == 1:
        l.pop(idx)
        l.pop(idx)
        count += 2
        idx = 0
        if len(l) == 0:
            break
        continue
    elif l[idx] == 1 and l[idx+1] == 0:
        l.pop(idx)
        l.pop(idx)
        count += 2
        idx = 0
        if len(l) == 0:
            break
        continue
    if idx+1 == len(l)-1:
        break
    idx += 1

print(count)

### FIXED CODE ###

S = input()

l0 = 0
l1 = 0

for i in S:
    if i == '0':
        l0 += 1
    elif i == '1':
        l1 += 1

ans = min(l0, l1) * 2

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

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
counter=Counter(a)
#print(a)
def calc_combi(n,m):
    a1=1
    a2=1
#    print(f'n={n} m={m}')
    for i in range(m):
        a1*=(n-i)
        a2*=(i+1)
#        print(f'a1={a1} a2={a2}')
    return a1//a2
#print(counter)
for i in range(n):
    combi=0
    for num,cnt in counter.items():
#        print(f'num={num} cnt={cnt}')
        n_cnt=cnt
        if num==a[i]:
            n_cnt-=1
        combi+=calc_combi(n_cnt ,2)
    print(combi)

### FIXED CODE ###

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

from collections import Counter
counter=Counter(a)

# すべての組み合わせを事前に計算しておく
combi_sum=0
for num,cnt in counter.items():
    combi_sum+=cnt*(cnt-1)//2

for i in range(n):
    print(combi_sum - counter[a[i]] + 1)