Harryxun/stf_run huggingface dataset:
def bisect_left(array, i, left, right):
    n = right - left + 1
    mid = (left+right) // 2
    if n == 1:
        if array[mid] < i:
            return 1
        else:
            return 0
    if i <= array[mid]:
        return bisect_left(array,i,left,mid)
    else:
        return (mid-left+1) + bisect_left(array,i,mid+1,right)

def bisect_right(array, i, left, right):
    n = right - left + 1
    mid = (right+left) // 2
    if n == 1:
        if i < array[mid] :
            return 0
        else:
            return 1
    if array[mid] <= i:
        return  (mid-left+1) + bisect_right(array,i,mid+1,right)
    else:
        return bisect_right(array,i,left,mid)

N = int(input())
L = []
for _ in range(3):
    l = list(map(int,input().split()))
    L.append(sorted(l))
ans = 0
for x in L[1]:
    n = bisect_left(L[0],x,0,N-1)
    m = bisect_right(L[2],x,0,N-1)
    m = N - m
    ans += n*m
print(ans)

### FIXED CODE ###

s1=input()
s2=input()
if s1[0] == s2[2] and s1[1]==s2[1] and s1[2]==s2[0]:
  print("YES")
else:
  print("NO")
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

n, a, b = map(int, input().split())
nCa= 1
nCb= 1
for i in range(b):
    nCb = (nCb%p * (n-i)%p)%p
    nCb = nCb * mod_inv(i+1, p)
    if i+1 == a:
        nCa = nCb

ans = 2**n - 1- nCa%p - nCb%p
if ans < 0:
    print(0)
else:
    print(int(ans%p))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
mod = p = 10**9+7
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

n, a, b = map(int, input().split())
nCa= 1
nCb= 1
for i in range(b):
    nCb = (nCb%p * (n-i)%p)%p
    nCb = nCb * mod_inv(i+1, p)
    if i+1 == a:
        nCa = nCb

ans = 2**n - 1- nCa%p - nCb%p
if ans < 0:
    print(0)
else:
    print(int(ans%p))
n = input()
S = set([int(s) for s in raw_input().split()])
m = input()
T = set([int(s) for s in raw_input().split()])

r=[]
def binarySearch(a=[],p=0):
	ll=0
	ul=len(a)
	
	while(True):
		if ll>ul:
			return -1
		ms=(int(ll)+int(ul))/2

		if a[i]==p:
			r.append(p)
		elif a[i]>p:
			ul=i-1
		else:
			ll=i+1






if __name__=="__main__":
	for i in T:
		binarySearch(S,i)

	print len(r)

### FIXED CODE ###

n = input()
S = set([int(s) for s in raw_input().split()])
m = input()
T = set([int(s) for s in raw_input().split()])
print len(S&T)
n = int(input())
t,a = map(int, input().split())
h = list(map(int,input().split()))
ans = 1000000
for i in n:
    x = t - h[i]*0.006
    ans = min(ans, abs(x-a))
print(ans)  

### FIXED CODE ###

n = int(input())
t,a = map(int, input().split())
h = list(map(int,input().split()))
ans = -1
mn = 10**9
for i in range(n):
    x = abs(t - h[i]*0.006 - a)
    if x < mn:
        mn = x
        ans = i+1
print(ans)
H, W, A, B = map(int, input().split())

M = [[0 for w in range(W)] for h in range(H)]

i = 0
for h in range(H):
    for a in range(A):
        w = i + a
        if w == W:
            w = 0
        M[h][w] = 1
        i = w
    i += 1
    if i == W:
        i = 0

for w in range(W):
    col = 0
    for h in range(H):
        col += M[h][w]
    if col not in [B, H - B]:
        print('No')
        exit()

for h in range(H):
    print(''.join(list(map(str, M[h]))))

### FIXED CODE ###

H, W, A, B = map(int, input().split())

M = [[0 for w in range(W)] for h in range(H)]

for h in range(B):
    for w in range(A):
        M[h][w] = 1

for h in range(B, H):
    for w in range(A, W):
        M[h][w] = 1

for h in range(H):
    print(''.join(list(map(str, M[h]))))
n,m=map(int,input().split())
def fctr2(n): #それぞれの素因数の指数だけ出力
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append(c)
            c=0
    if n!=1:
        f.append(1)
    return f

mod=10**9+7
fuc=[1]
def fucfun(n):
    for i in range(1,n):
        e=fuc[i-1]*i
        fuc.append(e%mod)
def com(n,k):
    com=(fuc[n]%mod)*pow(fuc[k],mod-2,mod)*pow(fuc[n-k],mod-2,mod)
    return com
f=fctr2(m)
a=max(f)+n
fucfun(a)
s=1
for i in range(len(f)):
    t=com(f[i]+n-1,f[i])
    s=(s*t)%mod
print(s)

### FIXED CODE ###

n,m=map(int,input().split())
pem=1
if m==1:
    print(1)
def fctr2(n): #それぞれの素因数の指数だけ出力
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append(c)
            c=0
    if n!=1:
        f.append(1)
    return f

mod=10**9+7
fuc=[1]
def fucfun(n):
    for i in range(1,n):
        e=fuc[i-1]*i
        fuc.append(e%mod)
def com(n,k):
    com=(fuc[n]%mod)*pow(fuc[k],mod-2,mod)*pow(fuc[n-k],mod-2,mod)
    return com
f=fctr2(m)
if m!=1:
    a=max(f)+n
    fucfun(a)
    s=1
    for i in range(len(f)):
        t=com(f[i]+n-1,f[i])
        s=(s*t)%mod
    print(s)
#include<stdio.h>

main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if (a<b){
        printf("a < b\n");
    }
    else if (a > b){
        printf("a > b\n");
    }
    else {
        printf("a == b\n");
    }
}


### FIXED CODE ###

a,b = map(int, input().split())
if a < b:
    print('a < b')
elif a > b:
    print('a > b')
else:
    print('a == b')
a,b=input().split()
if b%a==0:
  print(a+b)
else:
  print(b-a)

### FIXED CODE ###

a,b=map(int, input().split())
if b%a==0:
  print(a+b)
else:
  print(b-a)
import sys
import collections

while True:
    N, Q = map(int, sys.stdin.readline().split())
    if N == 0:
        break
    counter = collections.Counter()
    for i in xrange(N):
        date = map(int, sys.stdin.readline().split())
        if date[0] != 0:
            counter.update(date[1:])
    
    result = counter.most_common()
    largest = result[0][1]
    
    ret = -1
    if largest < Q:
        print 0
    else:
        smallest = 100
        for n, c in result:
            if c < largest:
                break
            if n < smallest:
                smallest = n
        print smallest

### FIXED CODE ###

import sys
import collections

while True:
    N, Q = map(int, sys.stdin.readline().split())
    if N == 0:
        break
    counter = collections.Counter()
    for i in xrange(N):
        date = map(int, sys.stdin.readline().split())
        if date[0] != 0:
            counter.update(date[1:])
    
    if len(counter) == 0:
        print 0
        continue
    
    result = counter.most_common()
    largest = result[0][1]
    
    ret = -1
    if largest < Q:
        print 0
    else:
        smallest = 100
        for n, c in result:
            if c < largest:
                break
            if n < smallest:
                smallest = n
        print smallest
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mx = 0
for i in range(min(n, k + 1)):
	for j in range(min(k - i + 1, n - i + 1)):
		summa = 0
		b = []
		for t in range(i):
			b.append(a[t])
		for t in range(n - j, n):
			b.append(a[t])
		z = k - i - j
		b.sort()
		for x in b:
			if x < 0 and z > 0:
				z -= 1
			else:
				summa += x
		mx = max(mx, summa)
print(mx)


### FIXED CODE ###

a, b = map(int, input().split())
a = a * 3 + b
print(a // 2)
import collections
n=int(input())
v=list(map(int,input().split()))
c1=collections.Counter(v[::2])
c2=collections.Counter(v[1::2])
c1_v1=c1.most_common()[0][0]
c2_v1=c2.most_common()[0][0]
c1_n1=c1.most_common()[0][1]
c2_n1=c2.most_common()[0][1]
c1_n2=c1.most_common(2)[1][1]
c2_n2=c2.most_common(2)[1][1]

if c1_v1!=c2_v1:
    print(n-c1_n1-c2_n1)
else:
    if c1_n1==n//2:
        if c2_n1==n//2:
            print(n//2)
        else:
            print(n-c1_n1-c2_n2)
    else:
        if c2_n1==n//2:
            print(n-c1_n2-c2_n1)
        else:
            print(n-c1_n2-c2_n2)

### FIXED CODE ###

import collections
n=int(input())
v=list(map(int,input().split()))
c1=collections.Counter(v[::2])
c2=collections.Counter(v[1::2])
c1_v1=c1.most_common()[0][0]
c2_v1=c2.most_common()[0][0]
c1_n1=c1.most_common()[0][1]
c2_n1=c2.most_common()[0][1]

if c1_v1!=c2_v1:
    print(n-c1_n1-c2_n1)
else:
    if c1_n1==n//2:
        if c2_n1==n//2:
            print(n//2)
        else:
            c2_n2=c2.most_common(2)[1][1]
            print(n-c1_n1-c2_n2)
    else:
        c1_n2=c1.most_common(2)[1][1]
        if c2_n1==n//2:
            print(n-c1_n2-c2_n1)
        else:
            c2_n2=c2.most_common(2)[1][1]
            print(min(n-c1_n2-c2_n1,n-c1_n1-c2_n2))
n = int(input())
print(round(format((n)*(n-1)/2,"f")))

### FIXED CODE ###

x = list(input())
y = list(input())
i = 0
for n in range(3):
	if x[n] == y[n]:
		i += 1

print(i)
import math
a, b, c=input().split(" ")

return math.sqrt(a) + math.sqrt(b) < math.sqrt(c)

### FIXED CODE ###

import math
a, b, c=input().split(" ")
a = int(a) 
b = int(b)
c = int(c) 

if  4*a*b < (c-a-b)*(c-a-b) and (c-a-b)>0:
  print("Yes")
else:
  print("No")
N, M = map(int, input().split())
root = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    root[A-1].append(B-1)
    root[B-1].append(A-1)
ans = [[-1, -1] for _ in range(N)]

def dfs(i, ib, l):
    global ans
    if ans[i][0] == -1 or l < ans[i][0]:
        ans[i][0] = l
        ans[i][1] = ib
        for next in root[i]:
            dfs(next, i, l+1)

dfs(0, 0, 0)
print("Yes")
for a in ans[1:]:
    print(a[1]+1)


### FIXED CODE ###

N, M = map(int, input().split())
root = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    root[A-1].append(B-1)
    root[B-1].append(A-1)
ans = [[-1, -1] for _ in range(N)]

S = [[0, 0, 0]]

while len(S) > 0:
    S_ = []
    for s in S:
        if ans[s[0]][0] == -1 or s[2] < ans[s[0]][0]:
            ans[s[0]][0] = s[2]
            ans[s[0]][1] = s[1]
            for next in root[s[0]]:
                S_.append([next, s[0], s[2]+1])
    S = S_

print("Yes")
for a in ans[1:]:
    print(a[1]+1)
n = input()
if n>= 2 and n <= 200000
   R = map(int, raw_input().split())
   minv = R[0]
   maxv = R[1] - R[0]
   for j in range(1, n-1):
      maxv = max(maxv, R[j] - minv) 
      minv = min(minv, R[j])
print maxv - minv

### FIXED CODE ###

n = input()
R = []
for i in range(0, n):
   R.append(int(raw_input()))

maxv = R[1] - R[0]
minv = R[0]

for v in range(1, n):
   if minv > R[v]:
      minv = R[v]
   elif maxv < R[v] - minv:
      maxv = R[v] - minv
print maxv
N, M = map(int, input().split())
ans = [-1] * N
for _ in range(M):
    i, n = map(int, input().split())
    if ans[i-1] == -1 or ans[i-1] == n:
        ans[i-1] = n
    else:
        print(-1)
        exit()
ans = [n if n != -1 else 0 for n in ans]
if ans[0] == 0 and len(ans > 1):
    ans[0] = 1
print(*ans, sep='')

### FIXED CODE ###

N, M = map(int, input().split())
ans = [-1] * N
for _ in range(M):
    i, n = map(int, input().split())
    if (ans[i-1] == -1 or ans[i-1] == n) and not(N > 1 and i == 1 and n == 0):
        ans[i-1] = n
    else:
        print(-1)
        exit()
ans = [n if n != -1 else 0 for n in ans]
if ans[0] == 0 and N > 1:
    ans[0] = 1

print(*ans, sep='')
[n, k] = [int(i) for i in input().split()]
h = np.array([int(i) for i in input().split()])
dp = [10 ** 5 for _ in range(n)]
dp[0] = 0
for i in range(n):
    for j in range(k+1):
        if i + j < n:
            dp[i + j] = min(dp[i + j] , dp[i] + abs(h[i] - h[i+j]))
print(dp[n-1])


### FIXED CODE ###

[n, k] = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [10 ** 10 for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    for j in range(1, min(i, k)+1):
        if i - j >= 0:
            dp[i] = min(dp[i] , dp[i-j] + abs(h[i] - h[i-j]))
print(dp[n-1])
S=input()
S1=int(S[:2])
S2=int(S[2:])

if S1 == 0 AND S2 == 0:
    print('NA')
if S1 == 0 AND S2 >12:
    print('NA')
if S1 > 12 AND S2 == 0:
    print('NA')
elif S1 > 12 and S2 > 12:
    print('NA')
elif S1 > 12 and S2 <= 12:
    print('YYMM')
elif S1 <= 12 and S2 > 12:
    print('MMYY')
else:
    print('AMBIGUOUS')


### FIXED CODE ###

S=input()
S1=int(S[:2])
S2=int(S[2:])

if (S1 == 0 and S2 == 0) or (S1 >12 and S2 > 12):
    print('NA')
elif S1 == 0 or S1 > 12:
  if S2 >=1 and S2 <=12:
    print('YYMM')
  else:
    print('NA')
elif S2 == 0 or S2 > 12:
  if S1 >=1 and S1 <=12:
    print('MMYY')
  else:
    print('NA')
else:
    print('AMBIGUOUS')
N,K=map(int,input().split())
A=list(map(int,input().split()))
kari=set()
hako=set()
count=0
cnt=0
zahyo=0
ans=0
kari.add(0)
if K<=10**6:
    for i in range(K):
        ans=A[ans]-1
    print(ans+1)
    exit()
for i in range(N):
    zahyo=A[zahyo]-1
    if zahyo not in kari:
        kari.add(zahyo)
        count+=1
    else:
        break
zahyo+=1
hako.add(zahyo)
for i in range(N):
    zahyo=A[zahyo]-1
    if zahyo not in hako:
        hako.add(zahyo)
        cnt+=1
    else:
        break
kaisu=K-count
if kaisu>N:
    kaisu=kaisu%cnt
for i in range(kaisu):
    zahyo=A[zahyo]-1
    print(zahyo,kaisu,count,cnt)
print(zahyo+1)

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
kari=set()
hako=set()
count=1
cnt=1
zahyo=0
ans=0
kari.add(zahyo)
if K<=10**6:
    for i in range(K):
        ans=A[ans]-1
    print(ans+1)
    exit()
for i in range(N):
    zahyo=A[zahyo]-1
    if zahyo not in kari:
        kari.add(zahyo)
        count+=1
    else:
        break

hako.add(zahyo)
for i in range(N):
    zahyo=A[zahyo]-1
    if zahyo not in hako:
        hako.add(zahyo)
        cnt+=1
    else:
        break
count=len(kari)
cnt=len(hako)
kaisu=K-count
#print(zahyo)
if kaisu>N:
    kaisu=kaisu%cnt
for i in range(kaisu):
    zahyo=A[zahyo]-1
#print(zahyo,kaisu,count,cnt)
#print(kari,hako)
print(zahyo+1)
import itertools
import numpy as np
import collections

N = int(input())
A = [int(_) for _ in input().split()]
count = collections.defaultdict(int)
for a in A:
    count[a] += 1
if len(count) == 1:
    a = count.keys()[0]
    if a ^ a == a:
        print('Yes')
        exit()
elif len(count) == 2:
    a, b = sorted(count.keys())
    if a == 0 and count[a] == 1 and count[b] == 2:
        print('Yes')
        exit()
elif len(count) == 3:
    a, b, c = count.keys()
    if a ^ b == c and count[a] == count[b] == count[c]:
        print('Yes')
        exit()
print('No')


### FIXED CODE ###

import collections

N = int(input())
A = [int(_) for _ in input().split()]
count = collections.defaultdict(int)
for x in A:
    count[x] += 1
if len(count) == 1:
    a = list(count.keys())[0]
    if a == 0:
        print('Yes')
        exit()
elif len(count) == 2:
    a, b = sorted(count.keys())
    if a == 0 and count[b] == count[a] * 2:
        print('Yes')
        exit()
elif len(count) == 3:
    a, b, c = count.keys()
    if a ^ b == c and count[a] == count[b] == count[c]:
        print('Yes')
        exit()
print('No')
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

a,b,c = map(int, input().split())
if a + b + c >= 22:
  print('bust')
else:
  print('win')


### FIXED CODE ###

a,b,c = map(int, input().split())
if a + b + c >= 22:
  print('bust')
else:
  print('win')
A,B=input().split()
A=int(A)
B=int(B)
if A*B%2==0:
  print("Even")
  else:
    print("Odd")

### FIXED CODE ###

A,B=input().split()
A=int(A)
B=int(B)
if A*B%2==0 :
  print("Even")
else :
  print("Odd")
import numpy as np

N, W = [int(x) for x in input().split()]
weight = np.zeros((N,2))
for x in range(N):
    weight[x] = [int(y) for y in input().split()]
#topdown
memo = np.zeros((N+1,W+1))
for x in range(N+1):
    memo[x] = [-1]*(W+1)

def dp(n,w):
    if w < 0:
        return -float('inf')
    elif n == 0 or w == 0:
        return 0
    elif memo[n][w] != -1:
        return memo[n][w]
    else:
        memo[n][w] = max(dp(n-1,w), dp(n-1,w - int(weight[n-1][0])) + weight[n-1][1])
        return memo[n][w]

print(int(dp(N,W)))


### FIXED CODE ###

import numpy as np

N, W = [int(x) for x in input().split()]
items = [tuple(map(int, input().split())) for _ in range(N)]

#topdown
memo = np.zeros(shape = W+1, dtype = np.int64)

for w,v in items:
    memo[w:] = np.maximum( memo[w:], memo[:-w] + v)

print(memo[-1])
s1,s2,s3 = map(int, input().split())

x = s1 + s2 +s3

print(x)

### FIXED CODE ###

print(input().count("1"))
for i in range(1, 10):
    for j in range(1, 10):
        if i * j == N:
            break
    if i * j == N:
        print("Yes")
        break
    elif i == 9 and i * j != N:
        print("No")

### FIXED CODE ###

N = int(input())

for i in range(1, 10):
    for j in range(1, 10):
        if i * j == N:
            break
    if i * j == N:
        print("Yes")
        break
    elif i == 9 and i * j != N:
        print("No")
a, b = [int(x) for x in input().split()]
num = '0123456789'
S = input()
flg = True
for i in len(S):
  if i == a:
    if not S[i] == '-':
      flg = False
  else:
    if not S[i] in num:
      flg = False
print('Yes' if flg else 'No')


### FIXED CODE ###

a, b = [int(x) for x in input().split()]
num = '0123456789'
S = input()
flg = True
for i in range(len(S)):
  if i == a:
    if not S[i] == '-':
      flg = False
  else:
    if not S[i] in num:
      flg = False
print('Yes' if flg else 'No')
s = input()
if s=='SUN':
  print(7)
elif s='MON':
  print(6)
elif s=='TUE':
  print(5)
elif s=='WED':
  print(4)
elif s=='THU':
  print(3)
elif s=='FRI':
  print(2)
elif s=='SAT':
  print(1)

### FIXED CODE ###

s = input()
if s=='SUN':
  print(7)
elif s=='MON':
  print(6)
elif s=='TUE':
  print(5)
elif s=='WED':
  print(4)
elif s=='THU':
  print(3)
elif s=='FRI':
  print(2)
elif s=='SAT':
  print(1)
n=int(input())
a=[105,135,165,195,189]
for i in renge(5):
 if n>=a[i]:
  s=i+1
print(s)

### FIXED CODE ###

A,B = map(int, input().split())
print((A-1)*(B-1))
import heapq

# def heapify(x):
#     for i in range((x)):
#         x[i] = -x[i]
#     heapq.heapify(x)

# def heappush(heap, item):
#     heapq.heappush(heap, -item)

# def heappop(heap):
#     return -heapq.heappop(heap)

# from heapq import heappop, heappush
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None




n, m = map(int, raw_input().split())
matrix = []
for i in range(0, n):
    matrix.append([])
    for j in range(0, n):
        matrix[i].append(False)

for j in range(0, m):
    a, b = map(int, raw_input().split())
    matrix[a - 1][b - 1] = True
    matrix[b - 1][a - 1] = True

seen = set()
distance = [10000] * m
h = []
heapq.heappush((0, 0))
while len(h):
    (d, room) = heapq.heappop(h)
    if (distance[room] <= d):
        continue
    distance[room] = d
    seen.add(room)

    for neighbor in range(0, n):
        if neighbor != room and matrix[room][neighbor]:
            heapq.heappush((d + 1, neighbor))

if len(seen) == n:
    print('Yes')
    for room in range(1, m):
        print(distance[room])
else:
    print('No')


### FIXED CODE ###

import heapq

# def heapify(x):
#     for i in range((x)):
#         x[i] = -x[i]
#     heapq.heapify(x)

# def heappush(heap, item):
#     heapq.heappush(heap, -item)

# def heappop(heap):
#     return -heapq.heappop(heap)

# from heapq import heappop, heappush
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None


def raw_input():
    return input()


rooms_count, passages_count = map(int, raw_input().split())
adj = []
for i in range(0, rooms_count):
    adj.append([])

for j in range(0, passages_count):
    a, b = map(int, raw_input().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)

seen = set()
distance = [100000000] * rooms_count
next = [100000000] * rooms_count
h = []
heapq.heappush(h, (0, 0, -1))
while len(h):
    (d, room, parent) = heapq.heappop(h)
    if (distance[room] <= d):
        continue
    distance[room] = d
    next[room] = parent
    seen.add(room)

    for neighbor in adj[room]:
        heapq.heappush(h, (d + 1, neighbor, room))

if len(seen) == rooms_count:
    print('Yes')
    for room in range(1, rooms_count):
        print(next[room] + 1)
else:
    print('No')
N=int(input())
L=map(int, input().split())
a=0
for i in range(0,N-2,1):
  for j in range(i+1,N-1,1):
    for q in range(j+1,N,1):
        if L[i]<L[j]+L[q] and L[j]<L[i]+L[q] and L[q]<L[i]+L[j]:
          a+=1
print(a)

### FIXED CODE ###

from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))

L.sort()
a=0
for i in range(N-2):
    for j in range(i+1,N-1):
        a+=bisect_left(L,L[i]+L[j])-j-1
print(a)
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))

            l = [i for i in reversed(range(1, x))]
            r = [i for i in range(x+1, 101)]
            cur = 0
            if x not in p:
                return x
            while True:
                if l[cur] not in p:
                    return l[cur]
                if r[cur] not in p:
                    return r[cur]
                cur+=1
    print(main())


resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))


            cur = 0
            if x not in p:
                return x
            
            while True:
                if x-cur not in p:
                    return x-cur
                if x+cur not in p:
                    return x+cur

                cur+=1
    print(main())


resolve()
import numpy as np

N,K = map(int, input().split())
S = [int(x) for x in input()]

memo = np.zeros(10**5+1, dtype = np.int64)
W = min(2*K, 10**5)

current = 1 # 最初は1が0個ある
p = 0

for x in S:
  if x == current:
    memo[x,p] += 1
  else:
    current = 1 - current
    p += 1

ans = memo[:W+1].sum()
x = ans
for r in range(2,10**5+1,2):
  if r+W > 10**5:
    break
  x = x-memo[r-2]-memo[r-1]+memo[r+W]+memo[r+W-1]
  if x > ans:
    ans = x

print(ans)

### FIXED CODE ###

import numpy as np

N,K = map(int, input().split())
S = [int(x) for x in input()]

memo = np.zeros(10**5+1, dtype = np.int64)
W = min(2*K, 10**5)

current = 1 # 最初は1が0個ある
p = 0

for x in S:
  if x == current:
    memo[p] += 1
  else:
    current = 1 - current
    p += 1
    memo[p] += 1

ans = memo[:W+1].sum()
x = ans
for r in range(2,10**5+1,2):
  if r+W > 10**5:
    break
  x = x-memo[r-2]-memo[r-1]+memo[r+W]+memo[r+W-1]
  if x > ans:
    ans = x

print(ans)
import collections
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

m = int(input())
a = list(map(int,input().split()))[:m]
c = collections.Counter(a)

memo = {}
rmemo = {}

for i in a:
    if not rmemo.get(i):
        print(rmemo[i])
        continue

    res = 0
    for k,v in c.items():
        if i == k: v -= 1
        
        if v >= 2:
            if not memo.get(v):
                memo[v] = combinations_count(v, 2)

            res += memo[v]
    rmemo[i] = res
    print(res)

### FIXED CODE ###

import collections


m = int(input())
A = list(map(int,input().split()))[:m]
c = collections.Counter(A)
 
def hoge(n):
    return n * (n - 1) // 2

full = sum([ hoge(i) for i in c.values()])

for a in A:
    print(full - hoge(c[a]) + hoge(c[a]-1))