Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split())
A = list(map(int, input().split()))

P = [a for a in A if a > 0]
Z = [a for a in A if a == 0]
M = [a for a in A if a < 0]

P.sort()
Z.sort()
M.sort(reverse=True)

minus_count = len(P) * len(M)
zero_count = len(Z) * (len(P)+len(M))
if len(Z) >= 2:
    zero_count += (len(Z) * (len(Z)-1)) // 2

left = -10**18 - 1
right = 10**18 + 1

while left + 1 < right:
    num = (left + right) // 2
    count = 0

    if num >= 0:
        count += zero_count + minus_count

        limit_idx = len(P)-1
        for idx, p in enumerate(P):
            pair = num / p
            while P[limit_idx] > pair and limit_idx > idx:
                limit_idx -= 1

            pattern = limit_idx - idx
            if pattern == 0:
                break
            count += pattern

        limit_idx = len(M) - 1
        for idx, m in enumerate(M):
            pair = num / m
            while M[limit_idx] < pair and limit_idx > idx:
                limit_idx -= 1

            pattern = limit_idx - idx
            if pattern == 0:
                break
            count += pattern

    elif num < 0:
        for idx, p in enumerate(P):
            pair = num / p

            limit_idx = len(M) - 1
            while M[limit_idx] <= pair and limit_idx >= 0:
                limit_idx -= 1

            pattern = len(M) - limit_idx - 1
            count += pattern

    if count >= k:
        right = num
    else:
        left = num

print(right)




### FIXED CODE ###

import numpy as np

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

A = np.array(input().split(), np.int64)

A.sort()

posA = A[A > 0]
negA = A[A < 0]
zeros = (A==0).sum()

left = -10**18
right = 10**18

while left+1 < right:
    num = (left+right)//2
    
    less_count = 0
    
    if num >= 0:
        less_count += zeros * n
    
    limit_pair_for_pos = num // posA
    limit_idxs = np.searchsorted(A, limit_pair_for_pos, side='right')
    less_count += limit_idxs.sum()

    limit_pair_for_neg = -(num // -negA)
    limit_idxs = n - np.searchsorted(A, limit_pair_for_neg, side='left')
    less_count += limit_idxs.sum()

    duplicate_cases = (A**2 <= num).sum()
    less_count -= duplicate_cases
    less_count //= 2
    
    if less_count >= k:
        right = num
    else:
        left = num

print(right)
N, M = map(int,input().split())
L = [list(map(int,input().split())) for k in range(N)]
L = sorted(L,key = lambda x: (-x[1],-x[0]))

ans = 0
c = 0
D = [1 for k in range(M+2)]
D[M+1] = 0
for k in range(N):
    if D[L[k][0]] == 1:
        D[M-c] = 0
        c += 1
        ans += L[k][1]
    if c == M:
        break
print(ans)


### FIXED CODE ###

import heapq

N, M = map(int,input().split())
J = [[] for k in range(M+1)]
for k in range(N):
    A, B = map(int,input().split())
    if A <= M:
        J[A].append(B)

Q = []
ans = 0
for d in range(1,M+1):
    for e in J[d]:
        heapq.heappush(Q,-e)
    if len(Q) > 0:
        ans += -heapq.heappop(Q)
print(ans)
N, K = map(int, input().split())
A = [int(input()) for i in range()]
S = []
A.sort()
for i in range(N - K + 1):
  S.append(A[i+K-1] - A[i])
print(min(S))

### FIXED CODE ###

N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
S = []
A.sort()
for i in range(N - K + 1):
  S.append(A[i+K-1] - A[i])
print(min(S))
i=1
while 1:
??a=input()
??if a==0:break
 print(f'Case {i}: {a}')
 i+=1

### FIXED CODE ###

import sys
i=1
for e in sys.stdin:
 if'0\n'==e:break
 print(f'Case {i}: {e[:-1]}');i+=1
n = int(input())
l,r = [map(int, input().split()) for i in range(n)]

number = 0

for i in range(n):
  number = number + (r[i]-l[i]+1)

print(number)  

### FIXED CODE ###

n = int(input())
l=[]
total=0
for i in range(n):
  l,r=map(int,input().split())
  total += (r-l+1)
print(total)
a, b, c = map(int, input().split())

if a == b == c:
    print(-1)
    exit()

if a%2!=0 or b%2!=0 or c%2!=0:
  	print(0)
    exit()

N = (a+b+c)//3
cnt = 1
while N:
    if N%2 != 0: break
    N //= 2
    cnt += 1
    
print(cnt)

### FIXED CODE ###

a, b, c = map(int, input().split())
 
if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
    print(0)
elif a == b == c:
    print(-1)
else:
    num = 0
    while (a % 2 == 0 and b % 2 == 0 and c % 2 == 0):
        a, b, c = (b+c)/2, (a+c)/2, (a+b)/2
        num += 1
    print(num)
n = int(input())
h = list(map(int, input().split()))
for i in range(1, n+1):
  print(h.index(i)+1, end =  " ")

### FIXED CODE ###

n = int(input())
print('{:0<10}'.format(((n+1)//2)/n))
n = int(input())
a = list(map(int, input().split()))

l = [0] * 9

for i in range(n):
    l[a[i] // 400] += 1

m = 0
for i in range(len(l) - 1):
    if l[i] != 0:
        m += 1

M = min(9, l[-1] + m)
print(m, M)


### FIXED CODE ###

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

l = [0] * 9

for i in range(n):
    s = min(a[i] // 400, 8)
    l[s] += 1

m = 0
for i in range(len(l) - 1):
    if l[i] != 0:
        m += 1

print(max(m, 1), l[-1] + m)
import numpy as np

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

x = []
for h in range(H):
    line = list(input())
    for _ in line:
        for value in _:
            x.append(value)
x = np.array(x)
x = x.reshape(num_i, num_j)

count = 0
boolean = True
while (boolean):
    count += 1
    i_arr = []
    j_arr = []
    for i in range(num_i):
        for j in range(num_j):
            if (x[i][j] == "#"):
                i_arr.append(i)
                j_arr.append(j)
    for i, j in zip(i_arr, j_arr):
        if (i == 0) & (j == 0):
            x[1][0] = "#"
            x[0][1] = "#"
        elif (i == num_i - 1) & (j == num_j - 1):
            x[i - 1][j] = "#"
            x[i][j - 1] = "#"
        elif (i == num_i - 1) & (j == 0):
            x[i - 1][0] = "#"
            x[i][1] = "#"
        elif (i == 0) & (j == num_j - 1):
            x[1][j] = "#"
            x[0][j - 1] = "#"
        elif (i == 0):
            x[1][j] = "#"
            x[0][j - 1] = "#"
            x[0][j + 1] = "#"
        elif (j == 0):
            x[i - 1][0] = "#"
            x[i + 1][0] = "#"
            x[i][1] = "#"
        elif (i == num_i - 1):
            x[i - 1][j] = "#"
            x[i][j + 1] = "#"
            x[i][j - 1] = "#"
        elif (j == num_j - 1):
            x[i - 1][j] = "#"
            x[i + 1][j] = "#"
            x[i][j - 1] = "#"
        else:
            x[i - 1][j] = "#"
            x[i + 1][j] = "#"
            x[i][j - 1] = "#"
            x[i][j + 1] = "#"
    if len(set(list(x.flatten()))) == 1:
        boolean = False
    else:
        boolean = True

print(count)

### FIXED CODE ###

from collections import deque

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

# input black cells
black_cells = []

for h in range(H):
    line = list(input())
    for w in range(W):
        if line[w] == "#":
            black_cells.append(h * W + w)


# Graph
def r(p):
    q_list = []
    h = p // W
    w = p % W
    if h != 0:
        q_list.append(p - W)
    if h != H-1:
        q_list.append(p + W)
    if w != 0:
        q_list.append(p - 1)
    if w != W-1:
        q_list.append(p + 1)
    return q_list


queue = deque(black_cells)
d = [10000] * (H * W)
for i in black_cells:
    d[i] = 0

# dijkstra
while len(queue) > 0:
    p = queue.popleft()
    for q in r(p):
        if d[q] > d[p] + 1:
            d[q] = d[p] + 1
            queue.append(q)

print(max(d))
s = list(input())
t = list(input())
n = int(len(t))
if s =  t[0:n-2]:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

s = list(input())
t = list(input())
n = int(len(t))
m = int(len(s))
if s == t[0:n-1] and n-1 == m:
  print('Yes')
else:
  print('No')
import itertools


def count_maxone(binstr):
    return max([len(l) for l in binstr.split('0') if len(l)])


n, k = map(int, input().split())
s = input().rstrip()
ones = count_maxone(s)

pos = []
pre = '1'

for i in range(n):
    if s[i] == '0' and pre == '1':
        pos.append(i)
    pre = s[i]

for i in range(1, k + 1):
    combs = itertools.combinations(pos, i)
    for cmb in combs:
        slist = list(s)
        for c in cmb:
            zc = s.find('1', c)
            if zc == -1:
                zc = c + 1
            for t in range(c, zc):
                slist[t] = '1'
        ones = max(ones, count_maxone(''.join(slist)))

print(ones)


### FIXED CODE ###

n, k = map(int, input().split())
s = input().rstrip()
ans = 1
i = 0
left = 0
right = 1
while i < n:
    if k > 0:
        pos = s.find('01', i)
        if pos == -1:
            i = n
            right = n - 1
        else:
            pos = s.find('10', pos + 1)
            if pos == -1:
                i = n
                right = n - 1
            else:
                right = pos
                i = pos + 1
        k = k - 1
        ans = max(ans, right - left + 1)
    else:
        pos = s.find('01', left)
        left = pos + 1
        k = k + 1

print(ans)
mass=int(input())
number=list(map(int,input().split()))

cnt = 0

for i in mass:
    if (i+1)%2==0 and number[i]%2==0:
        cnt+=1
 print(cnt)

### FIXED CODE ###

mass=int(input())
number=list(map(int,input().split()))

cnt = 0

for i in range(mass):
    if (i+1)%2!=0 and number[i]%2!=0:
        cnt+=1

print(cnt)
n = int(input())
a = [ int(i) for i in input().split() ]
ans = []
for i in range(1,n):
    if a[i] > a[i-1]:
        ans.append(0)
    else:
        ans.append(1)


dp = [ 0 for i in range(n-1) ]
dp[0] = ans[0]
for i in range(1,n-1):
    if ans[i] == 0:
        dp[i] = 0
    else:
        dp[i] = 1 + dp[i-1]

print(max(dp))


### FIXED CODE ###

n = int(input())
a = [ int(i) for i in input().split() ]
if n == 1:
    print(0)
    import sys
    sys.exit()
ans = []
for i in range(1,n):
    if a[i] > a[i-1]:
        ans.append(0)
    else:
        ans.append(1)


dp = [ 0 for i in range(n-1) ]
dp[0] = ans[0]
for i in range(1,n-1):
    if ans[i] == 0:
        dp[i] = 0
    else:
        dp[i] = 1 + dp[i-1]

print(max(dp))
# -*- coding: utf-8 -*-
import math
N = int(input())
X = list(map(int, input().split()))

def solver(N,X):
    r = X[1:]
    result = sum(r)/len(r) * math.factorial(N-1)
    if result>=10**9 +7:
        result = result%10**9 +7
    return int(result)

print(solver(N,X))

### FIXED CODE ###

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

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

factorial=[1]
for i in range(1,N):
    factorial.append(factorial[-1] *i %mod)

ans=0
for i in range(1,N):
    ans = (ans*i + (X[-1]-X[i-1])*factorial[i-1]) %mod

print(ans)
n = int(input())
output = []
for i in range(n):
    order = map(str,input().split())
    if order[0] == "insert":
        output.append(int(order[1]))
    elif order[0] == "deleteFirst":
        output.pop()
    elif order[0] == "deleteLast":
        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

### FIXED CODE ###

import sys
from collections import deque
n = int(sys.stdin.readline())
lines = sys.stdin.readlines()
 
Q = deque()
for i in range(n):
    command = lines[i].split()
    if command[0] == "insert":
        Q.appendleft(command[1])
    elif command[0] == "deleteFirst":
        Q.popleft()
    elif command[0] == "deleteLast":
        Q.pop()
    elif command[0] == "delete":
        try:
            Q.remove(command[1])
        except:
            pass
print(" ".join(Q))
A,B,C = [int(i) for i in input().split(' ')]


temp = A
A = B
B = temp

temp = A
A = C
C = temp

print(f'{A} {B} {C}')



### FIXED CODE ###

A,B,C = [int(i) for i in input().split(' ')]


A, B = B, A
A, C = C, A

print('{} {} {}'.format(A, B, C))
import sys
input = sys.stdin.readline

a, b, c, d = input()
a = int(a);b = int(b);c = int(c);d = int(d)
if a+b+c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'+'+c+'+'+d+'=7'
elif a+b+c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'+'+c+'-'+d+'=7'
elif a+b-c-d == 7:
     a = str(a);b = str(b);c = str(c);d = str(d)
     ans = a+'+'+b+'-'+c+'-'+d+'=7'
elif a+b-c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'-'+c+'+'+d+'=7'
elif a-b+c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'+'+c+'+'+d+'=7'
elif a-b+c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'+'+c+'-'+d+'=7'
elif a-b-c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'-'+c+'+'+d+'=7'
else:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'-'+c+'-'+d+'=7'
print(ans)

### FIXED CODE ###

import math
import sys
input = sys.stdin.readline

abcd = int(input())
for i in range(int(4-math.log10(abcd))):
    abcd = '0'+str(abcd)
a, b, c, d = str(abcd)
a = int(a);b = int(b);c = int(c);d = int(d)
if a+b+c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'+'+c+'+'+d+'=7'
elif a+b+c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'+'+c+'-'+d+'=7'
elif a+b-c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'-'+c+'-'+d+'=7'
elif a+b-c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'-'+c+'+'+d+'=7'
elif a-b+c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'+'+c+'+'+d+'=7'
elif a-b+c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'+'+c+'-'+d+'=7'
elif a-b-c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'-'+c+'+'+d+'=7'
else:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'-'+c+'-'+d+'=7'
print(ans)
n=int(input())
hr=list(map(int,input().split()))
dp=[-1]*(n+1)
def cost(i):
	if i>=n-1:
		return 0
	if dp[i]!=-1:
		return dp[i]
	if i<n-2:
		a=abs(hr[i]-hr[i+2])+cost(i+2)
	b=abs(hr[i]-hr[i+1])+cost(i+1)
	if i>=n-2:
		a=b
	x=min(a,b)
	dp[i]=x
	return x
print(cost(0))

### FIXED CODE ###

n=int(input())
ab=abs
hr=list(map(int,input().split()))
dp=[-1]*(n+1)
dp[0]=0
dp[1]=ab(hr[1]-hr[0])
for i in range(2,n):
	x=ab(hr[i]-hr[i-2])+dp[i-2]
	y=ab(hr[i]-hr[i-1])+dp[i-1]
	dp[i]=min(x,y)
print(dp[n-1])
n = int(input())

ans = n(1+n)/2
print(ans)

### FIXED CODE ###

n = int(input())

ans = int(n * (1 + n) / 2)
print(ans)
a, b = list(map(int, input()))
if a >= 10 or b >= 10:
	print(-1)
else:
	print(a*b)

### FIXED CODE ###

a, b = list(map(int, input().split()))
if a >= 10 or b >= 10:
    print(-1)
else:
    print(a*b)
n = int(input())

a = list(range(1, n+1))
# b = sorted(a, reverse=True)

b = list(range(2, n+1))+[1]
ans = 0

for i in range(n):
    ans += a[i] % b[i]

print(ans)


### FIXED CODE ###

n = int(input())


a = (1+n-1)*(n-1)//2
print(a)
S = list(input())
length = len(S)
if length % 2 == 1:
    length -= 1
else:
    length -= 2

def hantei(list_str,n):
    k = int(n/2)
    if list_str[0:k] == list_str[k:n]:
        return n
    else:
        return 0

while length != 2:
        ans = hantei(S,length)
        if ans != 0:
            break
        length -= 2

if ans == 0 :
    print(1)
else:
    print(ans)

### FIXED CODE ###

def hantei(list_str,n):
    k = int(n/2)
    if list_str[0:k] == list_str[k:n]:
        return n
    else:
        return 0
S = list(input())
length = len(S)
flag = 0
if length == 2:
    print(0)
    flag = 1
elif length == 3:
    length -= 1
    ans = hantei(S,2)
    print(ans)
    flag = 1
elif length % 2 == 1:
    length -= 1
    ans = 0
else:
    length -= 2
    ans = 0
while length >= 2:
        ans = hantei(S,length)
        if ans != 0:
            break
        length -= 2

if flag == 0:
    if ans == 0:
        print(1)
    else:
        print(ans)
import bisect

A,B,Q = map(int, input().split())
INF = 10**18

s =[-INF] + [int(input()) for i in range(A)] +[INF]
t =[-INF] + [int(input()) for i in range(B)] +[INF]

for q in range(q):
    x = int(input())
    b, d =bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b-1], s[b]]:
        for T in [t[d-1], t[d]]:
            d1,d2 = abs(S-x)+abs(T-S),abs(T-x)+abs(S-T)
            res = min(res, d1,d2)
    print(res)

### FIXED CODE ###

import bisect

A,B,Q = map(int, input().split())
INF = 10**18

s =[-INF] + [int(input()) for i in range(A)] +[INF]
t =[-INF] + [int(input()) for i in range(B)] +[INF]

for q in range(Q):
    x = int(input())
    b, d =bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b-1], s[b]]:
        for T in [t[d-1], t[d]]:
            d1,d2 = abs(S-x)+abs(T-S),abs(T-x)+abs(S-T)
            res = min(res, d1,d2)
    print(res)
# -*- coding: utf-8 -*-
N = int(input)
print("Christmas" + "Eve"*(25 - n))

### FIXED CODE ###

# -*- coding: utf-8 -*-
D = int(input())
print("Christmas " + "Eve "*(25 - D))
import fractions
from functools import reduce
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
#print(n)
n=sorted(set(n),reverse = True)
bs = n[0]
#print(n)
#c=len(n)


def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // math.gcd(a, b)

def lcm_o():
        global n
        return reduce(lcm_b, n,1)

def chk(v):
        global n
        for i in range(30):
                #print(i,v)
                if v%(2**i) == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                if n[j] % t == 0 and (n[j] / t) % 2 == 1:
                        n[j] = int(n[j]/t)
                else: return 0
        return i-1
c = chk(n[-1])
ofst=0
if  c != 0:
        #print(n)
        v = lcm_o()*(2**(c-1))
        if v <= bs:ofst = 1
        #print(v)
        if v > M:
                print(0) 
        else:
                v = M//v
                #print(v)
                print((v+1)//2 - ofst if v%2 == 1 else v//2 - ofst)
        
else: print(0)

### FIXED CODE ###

import fractions
from functools import reduce
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
#print(n)
n=sorted(set(n),reverse = True)
bs = n[0]
#print(n)
#c=len(n)
 
 
def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // fractions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                if n[j] % t == 0 and (n[j] / t) % 2 == 1:
                        n[j] = int(n[j]/t)
                else: return 0
        return i-1
 
if len(n) > 1:
        
        c = chk(n[-1])
        
        if  c != 0:
                v = lcm_o()*(2**(c-1))
                
                if v > M:
                        print(0) 
                else:
                        v = M//v
                        if v%2==1: v+=1
                        print(int(v//2))
        
        else: print(0)
elif len(n)==1:
        v = int(bs*0.5)
        v = M//v
        if v%2==1: v+=1
        print(int(v//2))
from fractions import gcd
from functools import reduce
import sys

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

max_value = 2 * m

lcm = lcm_list(A)

if any((lcm / a) % 2 != 1 for a in A):
    print("0")
    sys.exit(0)

max_product = max_value // lcm
print((max_product + 1) // 2)


### FIXED CODE ###

from fractions import gcd
from functools import reduce
import sys


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers, maxvalue):
    first = 1
    second = 1
    for i in numbers:
        second = i
        lcm_result = lcm_base(first, second)
        if lcm_result > max_value:
            return -1
        first = lcm_result
    return lcm_result


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

max_value = 2 * m

lcm = lcm_list(A, 2 * m)
if lcm == -1:
    print("0")
    sys.exit(0)

if any((lcm / a) % 2 != 1 for a in A):
    print("0")
    sys.exit(0)

max_product = max_value // lcm
print((max_product + 1) // 2)
import numpy as np

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

'''
以下、方針
・Aから、各要素の出現回数を取得する。
・出現回数から、組み合わせを計算する。
'''
unique_num, counts =np.unique(A,return_counts=True) #Aから、各要素の出現回数を取得する。

# print(unique_num)
# print(counts)
dic0={} #数字と出現回数の組合わせ辞書
dic1={} #数字と組合わせ個数の組合わせ辞書
dic2={} #回答用の辞書

Combination_pattern　= []
for i in range(len(counts)):
    Combination = counts[i] * (counts[i]-1) // 2 #出現回数から、組み合わせを計算する。
    dic0[unique_num[i]]=counts[i]
    dic1[unique_num[i]]=Combination
    dic2.setdefault(unique_num[i])
    Combination_pattern.append(Combination)

totalcombination=sum(Combination_pattern)

# print(dic0)
# print(dic1)
# print(dic2)
# print(Combination_pattern)

'''
以下方針
・Aから数字を取得
・その数字の出現回数を1減らした状態の組み合わせの数を調べる。
・その数字に対応する元の組み合わせの数を減らし、1個前で計算した組合わせを足す。
・同じ数字を引いたときように答えを辞書に登録しておく。
・もし、過去に同じ数字を引いていたら、登録しておいた答えを回答する。
'''

for j in range (N):
    n=A[j] #Aから数字を取得
    if dic2[n]==None:
        reduced_pattern = (dic0[n]-1) * (dic0[n]-2) // 2 #その数字の出現回数を1減らした状態の組み合わせの数を調べる。
        ans=totalcombination-dic1[n]+reduced_pattern #その数字に対応する元の組み合わせの数を減らし、1個前で計算した組合わせを足す。
        dic2[n] = ans #同じ数字を引いたときように答えを辞書に登録しておく。
        print(ans)
    else:
        print(dic2[n]) #もし、過去に同じ数字を引いていたら、登録しておいた答えを回答する。

### FIXED CODE ###

import numpy as np

N=int(input())
A=np.array(list(map(int,input().split())))
'''
以下、方針
・Aから、各要素の出現回数を取得する。
・出現回数から、組み合わせを計算する。
'''
uni,cou=np.unique(A,return_counts=True)

# print(uni)
# print(cou)
dic0={}
dic1={}
dic={} #回答用

com=[]
for i in range(len(cou)):
    c=cou[i]*(cou[i]-1)//2
    dic0[uni[i]]=cou[i]
    dic1[uni[i]]=c
    com.append(c)
    dic.setdefault(uni[i])

# print(com)
totalcombination=sum(com)

# print(com)
# print(dic1)

'''
以下方針
・Aから数字を取得
・その数字に対応する組み合わせを減らす。
・その数字の出現回数を1減らした状態の組み合わせの数を足す。
'''

for j in range (N):
    n=A[j] #nはAの数列の数字
    if dic[n]==None:
        e=(dic0[n]-1)*(dic0[n]-2)//2
        t=totalcombination-dic1[n]+e
        dic[n]=t
        print(t)
    else:
        print(dic[n])
def f(a,b):
	return 2*a + f_fast(a,b-a)



def f_fast(a,b):
	if a==b:
		return a+b
	elif a < b:
		if b%a == 0:
			return f(a,b)
		else:
			d = b//a
			return 2*a*d + f_fast(a,b%a)
	else:
		return f_fast(b,a)


N,X = map(int,input().split(" "))

print(N+f_fast(N-X,X))

### FIXED CODE ###

def f(a,b):
	if a==b:
		d=0
		ret = a
	elif a < b:
		d = b//a
		if b%a == 0:
			ret = a*(2*d -1)
		else:
			ret = 2*a*d + f(a,b%a)
	else:
		d = a//b
		if a%b == 0:
			ret = b*(2*d -1)
		else:
			ret = 2*b*d + f(a%b,b)
	#print(a,b,d,ret)
	return ret


N,X = map(int,input().split(" "))

print(N+f(N-X,X))
#include <iostream>
#include <string>

using namespace std;

int main () {
   string S;
   cin>>S;
   int a=S.length(),x=0;
   for(int i=0;i<a;i++){
       if(S[i]!=S[a-i-1]);{
           x++;
       }
   }
   x=(x-(x%2))/2;
   cout<<x;
   return 0;   }


### FIXED CODE ###

S = input()
x =0
for i in range(len(S)//2):
	if S[i]!=S[-i-1]:x+=1
print(x)
import math

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


n, a, b, k = map(int, input().split())
count = 0
for i in range(n+1):
    if (k - (i * a)) % b == 0:
        count += (cmb(n, i) * cmb(n, (k-i*a)/b))
print(count%998244353)

### FIXED CODE ###

N,A,B,K = map(int,input().split())
sprime = 998244353 # approx 10**9
A,B = sorted((A,B))
if (A+B) * N < K:
	print(0)
	exit()
 
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)
 
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
 
memo = [0] * (N+1)
memo[0] = memo[N] = 1
for i in range(1,N//2+1):
	v = memo[i-1] * (N-i+1) * modinv(i,sprime)
	v = v % sprime
	memo[i] = memo[N-i] = v
 
# max is A*N + B*N
sum = 0
for b in range(N+1):
  a = (K-b*B)//A
  if 0 <= a <= N and a*A+b*B == K:
    sum += memo[a]*memo[b]
    sum %= sprime
 
print(sum)