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

import heapq
def topologicalsort(N,E):
    V = [0]*N
    for i in range(N):
        for y in E[i]:
            V[y] += 1
    S = [ i for i in range(N) if V[i] == 0]
    SORTED = []
    while S:
        s = S.pop(0)
        SORTED.append(s)
        for t in E[s]:
            V[t] -= 1
            if V[t] == 0:
                S.append(t)
    return SORTED
    
N, M = map( int, input().split())
E = [ [] for _ in range(N)]
for _ in range(M):
    x, y = map( int, input().split())
    x, y = x-1, y-1
    E[x].append(y)
V = topologicalsort(N, E)
ANS = [0]*N
for i in range(N):
    v = V[i]
    t = ANS[v]+1
    for e in E[v]:
        if t > ANS[e]:
            ANS[e] = t
print( max(ANS))

### FIXED CODE ###

import heapq
def topologicalsort(N,E):
    V = [0]*N
    for i in range(N):
        for y in E[i]:
            V[y] += 1
    S = [ i for i in range(N) if V[i] == 0]
    SORTED = []
    while S:
        s = S.pop(0)
        SORTED.append(s)
        for t in E[s]:
            V[t] -= 1
            if V[t] == 0:
                S.append(t)
    return SORTED
    
N, M = map( int, input().split())
E = [ [] for _ in range(N)]
for _ in range(M):
    x, y = map( int, input().split())
    x, y = x-1, y-1
    E[x].append(y)
V = topologicalsort(N, E)
ANS = [0]*N
for i in range(N):
    v = V[i]
    t = ANS[v]+1
    for e in E[v]:
        if t > ANS[e]:
            ANS[e] = t
print( max(ANS))
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from itertools import combinations_with_replacement

def enum_prime(m):
    L = range(2, m)
    P = []
    while L[0] ** 2 < m:
        P.append(L[0])
        L = [i for i in L if i % P[-1]]
    return P + L

P1 = enum_prime(50000)
P2 = P1[:]

for line in stdin:
    if line.startswith('0'):
        break
    n = int(line)
    cnt = 0
    if n % 2 == 0:
        for a in P1:
            if a + a == n:
                cnt += 1
                break
            for b in P2:
                if b < a:
                    continue
                if a + b == n:
                    cnt += 1
                    break
                if a + b > n:
                    break
    print(cnt)

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def enum_prime(m):
    L = [True for _ in xrange(m + 1)]
    L[0] = L[1] = False

    for i in xrange(2, m + 1):
        if L[i]:
            for j in xrange(i + i, m + 1, i):
                L[j] = False
            if m < i * i:
                break
    return L

FLAGS = enum_prime(50000)
PRIMES = [i for i, isprime in enumerate(FLAGS) if isprime]

for line in stdin:
    if line.startswith('0'):
        break
    n = int(line)
    n2 = n // 2
    cnt = 0
    if n % 2 == 0:
        for p in PRIMES:
            if p > n2:
                break
            if FLAGS[n - p]:
                cnt += 1
    elif FLAGS[n - 2]:
        cnt = 1
    print(cnt)
### BUGGY CODE ###

import sys
import numpy as np
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().split()]

ans = []
for i in range(N):
	a = np.argmin(A)
	ans.append(str(a+1))
	A[a] = float('INF')

print(' '.join(ans))

### FIXED CODE ###

import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().split()]

AS = [[a,idx+1] for idx,a in enumerate(A)]
AS.sort()

for a in AS:
	print(a[1], end=" ")
### BUGGY CODE ###

from collections import defaultdict

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

d = [len(x) for x in s.split('T')]

dx = d[0::2]
dp = [defaultdict(bool) for _ in range(len(dx) + 1)]
dp[0][0] = True
max_x = sum(dx)
for i in range(len(dx)):
    for j in range(-max_x, max_x + 1):
        if i == 0:
            dp[i + 1][j] = dp[i][j - dx[i]]
        else:
            dp[i + 1][j] = dp[i][j - dx[i]] or dp[i][j + dx[i]]
x_flag = dp[-1][x]

dy = d[1::2]
dp = [defaultdict(bool) for _ in range(len(dy) + 1)]
dp[0][0] = True
max_y = sum(dy)
for i in range(len(dy)):
    for j in range(-max_y, max_y + 1):
        dp[i + 1][j] = dp[i][j - dy[i]] or dp[i][j + dy[i]]
y_flag = dp[-1][y]

if x_flag and y_flag:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

from collections import defaultdict

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

d = [len(x) for x in s.split('T')]

dx = d[0::2]
n_dx = len(dx)
dp = {0}
for i in range(n_dx):
    tmp = set()
    for j in dp:
        if i == 0:
            tmp.add(j + dx[i])
        else:
            tmp.add(j - dx[i])
            tmp.add(j + dx[i])
    dp = tmp
x_flag = x in dp

dy = d[1::2]
n_dy = len(dy)
dp = {0}
for i in range(n_dy):
    tmp = set()
    for j in dp:
        tmp.add(j - dy[i])
        tmp.add(j + dy[i])
    dp = tmp
y_flag = y in dp

if x_flag and y_flag:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

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

answer = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] == j + 1 and A[j] == i + 1:
            answer += 1

print(answer)

### FIXED CODE ###

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

answer = 0
for i in range(N):
    if a[a[i] - 1] - 1 == i:
        answer += 1

print(answer // 2)
### BUGGY CODE ###

N = int(input())
gA, sA, bA = map(int, input().split())
gB, sB, bB = map(int, input().split())

dp = [[0] * (2 * N+ 2) for _ in range(2 * N + 2)]
#[重さ,価値]を要素とする配列
lstAB = [[gA, gB-gA], [sA, sB-sA], [bA, bB-bA]]
lstBA = [[gB, gA-gB], [sB, sA-sB], [bB, bA-bB]]
for i in range(3):
    for j in range(N+1):
        if j < lstAB[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j-lstAB[i][0]]+lstAB[i][1])

N += dp[3][N]
# print (N)

dp2 = [[0] * (2 * N+ 2) for _ in range(2 * N + 2)]
for i in range(3):
    for j in range(N+1):
        if j < lstBA[i][0]:
            dp2[i+1][j] = dp2[i][j]
        else:
            dp2[i+1][j] = max(dp2[i][j], dp2[i+1][j-lstBA[i][0]]+lstBA[i][1])
print (N + dp2[3][N])

### FIXED CODE ###

N = int(input())
gA, sA, bA = map(int, input().split())
gB, sB, bB = map(int, input().split())

#[重さ,価値]を要素とする配列
lstAB_2 = [[gA, gB-gA], [sA, sB-sA], [bA, bB-bA]]
lstBA_2 = [[gB, gA-gB], [sB, sA-sB], [bB, bA-bB]]
lstAB = []
for i in range(3):
    if lstAB_2[i][1] > 0:
        lstAB += [lstAB_2[i]]  

lstBA = []
for i in range(3):
    if lstBA_2[i][1] > 0:
        lstBA += [lstBA_2[i]]

dp = [[0] * (N+1) for _ in range(len(lstAB)+1)]
for i in range(len(lstAB)):
    for j in range(N+1):
        if j < lstAB[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j-lstAB[i][0]]+lstAB[i][1])

N += dp[len(lstAB)][N]
# print (N)

dp2 = [[0] * (N+1) for _ in range(len(lstBA)+1)]
for i in range(len(lstBA)):
    for j in range(N+1):
        if j < lstBA[i][0]:
            dp2[i+1][j] = dp2[i][j]
        else:
            dp2[i+1][j] = max(dp2[i][j], dp2[i+1][j-lstBA[i][0]]+lstBA[i][1])
print (N + dp2[len(lstBA)][N])
### BUGGY CODE ###

ans=1
n=int(input())
lim=10**18
for i in list(map(int,input().split())):
    ans*=i
print(ans if ans<=lim else -1)


### FIXED CODE ###

ans=1
n=int(input())
lim=10**18
l=list(map(int,input().split()))
if 0 in set(l):print(0);exit()
for i in l:
    ans*=i
    if ans>lim:print(-1);exit()
print(ans)
### BUGGY CODE ###

from functools import reduce

def factorization(n):
    '''
    素因数分解の結果を返す
    例： n = 100 の時、[2, 2, 5, 5] 
    '''
    arr = []
    tmp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if tmp % i == 0:
            while tmp % i == 0:
                arr.append(i)
                tmp //= i
    if tmp != 1:
        arr.append(tmp)
    if arr == []:
        arr.append(n)
    return arr


def combination(l):
    res = []
    for i in range(1, 2**len(l)):
        tmp = []
        for j in range(len(l)):
            if (i >> j) &1 == 1:
                tmp.append(l[j])
        res.append(tmp)
    return res


def solve():
    N = int(input())
    F = factorization(N)
    ans = N - 1
    for c in combination(F):
        t = reduce(lambda x, y: x * y, c)
        ans = min(ans, N // t - 1 + t - 1)
    print(ans)

if __name__ == "__main__":
    solve()


### FIXED CODE ###

def make_divisors(n):
    '''
    nの約数の配列を返す
    '''
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def solve():
    N = int(input())
    D = make_divisors(N)
    ans = N - 1
    for d in D:
        ans = min(ans, N // d - 1 + d - 1)
    print(ans)

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

import queue
height,width=map(int,input().split())

graph=[]
for _ in range(height):
    graph.append(input())

diff=[[0,-1],[0,1],[-1,0],[1,0]]
max_step=[]
for h in range(height):
    for w in range(width):
        if graph[h][w]=='#':
            continue

        route = [[-1]*width for _ in range(height)]

        # start x,y,経路数
        q = queue.Queue()
        q.put([w,h,0])

        while not q.empty():
            nx,ny,nn = q.get()
            route[ny][nx] = nn

            for dx,dy in diff:
                x = nx+dx
                y = ny+dy
                if   width<=x \
                  or height<=y \
                  or x < 0 \
                  or y < 0 \
                  or graph[y][x]=='#' \
                  or route[y][x]>-1:
                    continue
                q.put([x, y, nn+1])
        
        max_step.append(max(max(step) for step in route))
        
print(max(max_step))

### FIXED CODE ###

import queue
height,width=map(int,input().split())

graph=[input() for _ in range(height)]

dxs = [0, 0, 1, -1]
dys = [1, -1, 0, 0]
max_step=[]
for h in range(height):
    for w in range(width):
        if graph[h][w]=='#':
            continue

        route = [[-1]*width for _ in range(height)]
        route[h][w] = 0

        # start x,y,経路数
        q = queue.Queue()
        q.put([w,h,0])

        while not q.empty():
            nx,ny,nn = q.get()

            for dx,dy in zip(dxs, dys):
                x = nx+dx
                y = ny+dy
                if   width<=x \
                  or height<=y \
                  or x < 0 \
                  or y < 0 \
                  or graph[y][x]=='#' \
                  or route[y][x]!=-1:
                    continue
                route[y][x] = nn + 1
                q.put([x, y, nn+1])
        
        max_step.append(max(max(step) for step in route))
        
print(max(max_step))
### BUGGY CODE ###

x = int(input())
if x % 2 == 0:
    print(-1)
    exit()
s = 7
cnt = 1
while True:
    if s % x == 0:
        print(cnt)
        break
    s = s * 10 + 7
    cnt += 1


### FIXED CODE ###

x = int(input())
cnt = 1
mod = 7

for i in range(x):
    if mod % x == 0:
        print(cnt)
        exit()
    mod = (10 * mod + 7) % x
    cnt += 1
print(-1)
### BUGGY CODE ###

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    h, w = list(map(int, readline().split()))
    a = [[True] * w for _ in range(h)]
    ql = []
    ql = collections.deque(ql)
    for i in range(h):
        s = str(readline().rstrip().decode('utf-8'))
        for j in range(w):
            if s[j] == "#":
                a[i][j] = False
                ql.append([0, i, j])

    mt = 0
    while True:
        if len(ql) != 0:
            cost, x, y = ql.popleft()
            mt = max(mt, cost)
            for xv, yv in [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]:
                if 0 <= xv < h and 0 <= yv < w:
                    if a[xv][yv]:
                        ql.append([cost + 1, xv, yv])
                        a[i][j] = False
        else:
            break
    print(mt)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    h, w = list(map(int, readline().split()))
    a = [[True] * w for _ in range(h)]
    ql = collections.deque()
    for i in range(h):
        s = list(str(readline().rstrip().decode('utf-8')))
        for j in range(w):
            if s[j] == "#":
                ql.append([0, i, j])
                a[i][j] = False
    while ql:
        cost, x, y = ql.popleft()
        for xv, yv in ((x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)):
            if 0 <= xv < h and 0 <= yv < w:
                if a[xv][yv]:
                    ql.append([cost + 1, xv, yv])
                    a[xv][yv] = False
    print(cost)


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

## coding: UTF-8
#最後の方のテストケースでREになってしまう。時間切れ。
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product

N = int(input())

s = input().split()
p = [int(w) for w in s]
#print(p)

number_list = []
for i in range(N):
    counter = 0
    for j in range(N):
        if(p[j] == i+1):
            counter +=1
    number_list.append(counter)

#print(number_list)

def n_C_2(n):
    if(n == -1):
        return 0
    else:
        return int(n * (n-1) / 2)


full_combi = []
pickup_combi = []
print_combi = []

for i in range(N):
    full_combi.append(n_C_2(number_list[i]))
    pickup_combi.append(n_C_2(number_list[i] - 1))
#print(full_combi)
#print(pickup_combi)

for i in range(N):
    print_combi.append(sum(full_combi) - full_combi[i] + pickup_combi[i])
#print(print_combi)

for i in range(N):
    index = p[i] - 1
    print(print_combi[index])

### FIXED CODE ###

## coding: UTF-8
#最後の方のテストケースでREになってしまう。時間切れ。
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product

N = int(input())

s = input().split()
p = [int(w) for w in s]
#print('p:{}'.format(p))

number_list = [0 for i in range(N)]
'''
for i in range(N):
    counter = 0
    for j in range(N):
        if(p[j] == i+1):
            counter +=1
    number_list.append(counter)
'''
#print(number_list)

for i in range(N):
    number_list[p[i] - 1] += 1
#print(number_list)



def n_C_2(n):
    if(n == -1):
        return 0
    else:
        return int(n * (n-1) / 2)


full_combi = []
pickup_combi = []
print_combi = []

for i in range(N):
    full_combi.append(n_C_2(number_list[i]))
    pickup_combi.append(n_C_2(number_list[i] - 1))
#print('full_combi:{}'.format(full_combi))
#print('pickup_combi:{}'.format(pickup_combi))

all_full = sum(full_combi)
for i in range(N):
    print_combi.append(all_full - full_combi[i] + pickup_combi[i])
#print('print_combi:{}'.format(print_combi))

for i in range(N):
    index = p[i] - 1
    print(print_combi[index])
### BUGGY CODE ###

H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
  a, b = list(map(int, input().split()))
  A[i] = a
  B[i] = b
  
#モンスターの体力を i 減らすため消耗する魔力の最小値  
DP = [float("inf")] * (H + max(A) + 1)
DP[0] = 0  
for i in range(len(DP)):
  for j in range(N):
    if i - A[j] >= 0:
      DP[i] = min(DP[i], DP[i - A[j]] + B[j])
#print(DP) 
print(min(DP[H:H + max(A) + 1]))
  

### FIXED CODE ###

H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
  a, b = list(map(int, input().split()))
  A[i] = a
  B[i] = b
  
#モンスターの体力を i 減らすため消耗する魔力の最小値  
DP = [float("inf")] * (H + max(A) + 1)
DP[0] = 0  
for i in range(len(DP)):
  for j in range(N):
    if i - A[j] >= 0:
      DP[i] = min(DP[i], DP[i - A[j]] + B[j])
#print(DP) 
print(min(DP[H:H + max(A) + 1]))
### BUGGY CODE ###

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

e_nums = [(i+1)/2 for i in nums]

sum_e = [sum(e_nums[i:i+k]) for i in range(n) if i+k <= n]

print(max(sum_e))


### FIXED CODE ###

n, k = map(int, input().split())
nums = list(map(int, input().split()))
 
sum_max = sum(nums[:k])
temp = sum_max
for i in range(k,n):
  temp -= nums[i-k]
  temp += nums[i]
  sum_max = max(temp, sum_max)
print((sum_max +k)/2)
### BUGGY CODE ###

import sys; readline = sys.stdin.readline
from collections import deque
sys.setrecursionlimit(1000000)

N = int(readline())
A = list(map(int, readline().split()))

P = 10 ** 9 + 7

def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        r = a % b
        a, b = b, r
    
    return b

def lcm(a, b):
    return a * b // gcd(a, b)


def q_lcm(q, a):
    for k in q:
        a = a // gcd(k, a)
    return a

q = deque()

q.append(1)

for a in A:
    x = q_lcm(q, a)
    if x != 1:
        q.append(x)

_lcm = 1
for x in q:
    _lcm = _lcm * x % P

def mod_mult(a, N):
    if N == 0:
        return 1
    if N % 2 == 0:
        x = mod_mult(a, N // 2)
        return x * x % P
    else:
        x = mod_mult(a, N // 2)
        return x * x * a % P

def mod_s(a, b):
    b_inv = mod_mult(b, P - 2)
    return a * b_inv % P

total = 0

for a in A:
    _s = mod_s(_lcm, a)
    total += _s
    total %= P

print(total)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
 
 
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
 
 
def lcm(a, b):
    return a * b // gcd(a, b)
 
 
tmp = A[0]
for i in range(1, N):
    tmp = lcm(tmp, A[i])
 
B = [0] * N
for i in range(N):
    B[i] = tmp // A[i]
 
print(sum(B) % mod)
### BUGGY CODE ###

def __bisect_left(data, x, left, right):
    if left >= right:
        return right
    mid = (left+right)//2
    if data[mid] >= x:
        return __bisect_left(data, x, left, mid-1)
    else:
        return __bisect_left(data, x, mid+1, right)

def bisect_left(data, x, left):
    return __bisect_left(data, x, left, len(data))
    
n = int(input())
sides = list(map(int, input().split()))
sides.sort()
ans = 0
for a in range(len(sides)):
    for b in range(a+1,len(sides)):
        bound = bisect_left(sides, sides[a]+sides[b], b+1)
        if bound >= n:
            ans += bound - b - 1
        elif sides[bound] < sides[b]:
            ans += bound - b
        elif bound > b+1:
            ans += bound - b - 1

print(ans)
           

### FIXED CODE ###

from bisect import bisect_left
n = int(input())
sides = list(map(int, input().split()))
sides.sort()
ans = 0
for a in range(len(sides)):
    for b in range(a+1,len(sides)):
        bound = bisect_left(sides, sides[a]+sides[b], b+1)
        if bound >= n:
            ans += bound - b - 1
        elif sides[bound] < sides[b]:
            ans += bound - b
        elif bound > b+1:
            ans += bound - b - 1

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

import sys
input = sys.stdin.readline
N = int(input())
XY = [tuple(map(int,input().split())) for i in range(N)]
XY.sort(key=lambda x:x[0])

ys = []
for _,y in XY:
    ys.append(y)
ys.sort()
yd = {y:i for i,y in enumerate(ys)}

class BinaryIndexedTree:
    def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
    def add(self,x,w): # 0-indexed
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
    def _sum(self,x): # 1-indexed
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
    def sum(self,l,r): # [l,r)
        return self._sum(r) - self._sum(l)
    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.N)]
        return str(arr)

lbit = BinaryIndexedTree(N)
lu = []
ld = []
for i,(_,y) in enumerate(XY):
    d = lbit._sum(yd[y])
    u = i - d
    lu.append(u)
    ld.append(d)
    lbit.add(yd[y],1)

rbit = BinaryIndexedTree(N)
ru = []
rd = []
for i,(_,y) in enumerate(XY[::-1]):
    d = rbit._sum(yd[y])
    u = i - d
    ru.append(u)
    rd.append(d)
    rbit.add(yd[y],1)

MOD = 998244353
ans = 0
for a,b,c,d in zip(ld,lu,rd[::-1],ru[::-1]):
    pa,pb,pc,pd = pow(2,a,MOD),pow(2,b,MOD),pow(2,c,MOD),pow(2,d,MOD)
    ans += (pa-1) * (pd-1) * pb * pc
    ans += (pb-1) * (pc-1) * pa * pd
    ans -= (pa-1) * (pb-1) * (pc-1) * (pd-1)
    ans %= MOD
ans += N * pow(2,N-1,MOD)
ans %= MOD
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
XY = [tuple(map(int,input().split())) for i in range(N)]
XY.sort(key=lambda x:x[0])

ys = []
for _,y in XY:
    ys.append(y)
ys.sort()
yd = {y:i for i,y in enumerate(ys)}

class BinaryIndexedTree:
    def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
    def add(self,x,w): # 0-indexed
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
    def _sum(self,x): # 1-indexed
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
    def sum(self,l,r): # [l,r)
        return self._sum(r) - self._sum(l)
    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.N)]
        return str(arr)

lbit = BinaryIndexedTree(N)
lu = []
ld = []
for i,(_,y) in enumerate(XY):
    d = lbit._sum(yd[y])
    u = i - d
    lu.append(u)
    ld.append(d)
    lbit.add(yd[y],1)

rbit = BinaryIndexedTree(N)
ru = []
rd = []
for i,(_,y) in enumerate(XY[::-1]):
    d = rbit._sum(yd[y])
    u = i - d
    ru.append(u)
    rd.append(d)
    rbit.add(yd[y],1)

MOD = 998244353
ans = 0
for a,b,c,d in zip(ld,lu,rd[::-1],ru[::-1]):
    pa,pb,pc,pd = pow(2,a,MOD),pow(2,b,MOD),pow(2,c,MOD),pow(2,d,MOD)
    ans += (pa-1) * (pd-1) * pb * pc
    ans += (pb-1) * (pc-1) * pa * pd
    ans -= (pa-1) * (pb-1) * (pc-1) * (pd-1)
    ans %= MOD
ans += N * pow(2,N-1,MOD)
ans %= MOD
print(ans)
### BUGGY CODE ###


def main():
  from functools import reduce
  from operator import mul
  
  from collections import deque
  from collections import defaultdict
  
  n = int(input())
  a = list(map(int, input().split()))
  d = defaultdict(int)
  e = defaultdict(int)
  
  for x in a:
    d[x] += 1
  
  for f in d.keys():
    g = d[f] - 1
    h = [v for k,v in d.items() if (k != f and v>=2)]
    h.append(g)
    i = list(map(func, h))
    ans = sum(i)
    
    e[f] = ans
    
  for x in a:
    ans = e[x]
    print(ans)

    
def func(x):
  if x < 2:
    return 0
  else:
    ans = x*(x-1)//2
    return ans 
      
 
if __name__=='__main__':
    main()


### FIXED CODE ###

def main():
  from collections import defaultdict
  from collections import Counter
  
  n = int(input())
  a = list(map(int, input().split()))
  
  d = Counter(a)
  e = defaultdict(int)
  
  func = lambda x: x*(x-1)//2 if x>=2 else 0
  v = list(d.values())
  base = sum(list(map(func, v)))
  
  for k,v in d.items():
    if v<=1:
      e[k] = base - 0
    else:
      e[k] = base - ( v*(v-1)//2 - (v-1)*(v-2)//2 )
    
  p = [str(e[x])+'\n' for x in a]
  q = ''.join(p)
  print(q)
      
 
if __name__=='__main__':
    main()
### BUGGY CODE ###

import sys

lines = 1
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())


s = inp[0]
n = len(s)

tmp = set()
tmp.add(0)

for k in range(1, len(s) + 1):
    t = int(s[n-k:len(s)])
    tmp.add(t % 2019)

print(n - len(tmp) + 1)


### FIXED CODE ###

import sys
from collections import defaultdict

lines = 1
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())


s = inp[0]
n = len(s)

tmp = defaultdict(int)
tmp[0] = 1

b = 0
d = 1

for i in range(1, n + 1):
    a = int(s[n - i])
    b = ((d * a) + b) % 2019
    tmp[b] += 1
    d = (d * 10) % 2019

result = 0

for v in tmp.values():
    result += int(v * (v - 1) / 2)

print(result)
### BUGGY CODE ###

import bisect
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

a.sort()
f.sort(reverse=True)
s = []
for x,y in zip(a,f):
    s.append((x,y))

for ans in range(s[-1][0] * s[-1][1] + 1):
    tmp = 0
    for x, y in s:
        tmp += x - math.floor(ans / y)
    if tmp <= k:
        break
print(ans)

### FIXED CODE ###

import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

a.sort()
f.sort(reverse=True)

low = 0
high = 0
for x, y in zip(a,f):
    high = max(high, x*y)

while high != low:
    test = int((high + low) // 2)
    tmp = 0
    for x, y in zip(a,f):
        tmp += max(0, x - math.floor(test / y))
        if tmp > k:
            low = test + 1
            break
    else:
        high = test
print(high)