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

# -*- coding: utf-8 -*-
from pprint import pprint
N = int(input())
tn = list(map(int, input().split()))
vn = list(map(int, input().split()))

tn_sum = sum(tn)
time_tbl = [0 for _ in range(tn_sum*2+1)]  # 0.5刻みで×２

lrv = []
lrv.append([0, 0, 0])
t_sum = 0
for t, v in zip(tn, vn):
    lrv.append([t_sum, t_sum+t, v])
    t_sum += t
lrv.append([tn_sum, tn_sum, 0])


def f(l,r,x,v):
    if x <= l:
        return v + l - x
    elif l < x < r:
        return v
    else:
        return v + x - r

for t05 in range(tn_sum*2+1):
    time_tbl[t05] = min([f(l, r, t05/2, v) for l, r, v in lrv])

area = .0
for i in range(tn_sum*2):
    area += (time_tbl[i] + time_tbl[i+1])/4

print(area)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from pprint import pprint
N = int(input())
tn = list(map(int, input().split()))
vn = list(map(int, input().split()))

tn_sum = sum(tn)
time_tbl = [0 for _ in range(tn_sum*2+1)]  # 0.5刻みで×２

lrv = []
lrv.append([0, 0, 0])
t_sum = 0
for t, v in zip(tn, vn):
    lrv.append([t_sum, t_sum+t, v])
    t_sum += t
lrv.append([tn_sum, tn_sum, 0])


def f(l,r,x,v):
    if x <= l:
        return v + l - x
    elif l < x < r:
        return v
    else:
        return v + x - r

for t05 in range(tn_sum*2+1):
    time_tbl[t05] = min([f(l, r, t05/2, v) for l, r, v in lrv])

area = .0
for i in range(tn_sum*2):
    area += (time_tbl[i] + time_tbl[i+1])/4

print(area)
### BUGGY CODE ###

S = input()
N = len(S)
MOD = 10 ** 9 + 7

q = 3 if S[0] == '?' else 1
a = b = c = 0
def fq(a, b, c, q):
    return a * 3 + q, b * 3 + a, c * 3 + b, q * 3
def fa(a, b, c, q):
    return a + q, b, c, q
def fb(a, b, c, q):
    return a, b + a, c, q
def fc(a, b, c, q):
    return a, b, c + b, q
funcs = {'A':fa, 'B': fb, 'C':fc, '?':fq}
if S[0] in 'A?':
    a = 1
from functools import reduce
ans = reduce(lambda x, y: funcs[y](*x), S[1:], (a, b, c, q))
ans = ans[2] % MOD
print(ans)

### FIXED CODE ###

S = input()
N = len(S)
MOD = 10 ** 9 + 7

dp = [0, 0, 0, 0]
dp[0] = 1

for s in S:
    factor = 3 if s == '?' else 1
    for j, c in zip([2, 1, 0], 'CBA'):
        dp[j + 1] = dp[j + 1] * factor % MOD
        if s == c or s == '?':
            dp[j + 1] += dp[j]
    if s == '?':
        dp[0] = (dp[0] * 3) % MOD

ans = dp[-1] % MOD

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

s = input()
q = int(input())

rev = True

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        if rev:
            rev = False
        else:
            rev = True
    else:
        if (t[1] == "1" and rev) or (t[1] == "2" and not rev):
            s = "".join([t[2],s])
        else:
            s = "".join([s,t[2]])

if rev:
    print(s)
else:
    print(s[::-1])


### FIXED CODE ###

from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))
### BUGGY CODE ###

import fractions

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

g = fractions.gcd(A, B)
d = []
p = []

for i in range(1,int(pow(g, 0.5))+1):
    if g % i == 0:
        d.append(i)
        if i != g//i:
           d.append(g//i)

for i in d:
    s = 0
    for j in range(1,int(pow(i, 0.5))+1):
        if i % j == 0:
            s += 1

    if s == 1:
        p.append(i)

print(len(p))


### FIXED CODE ###

import fractions

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

g = fractions.gcd(A, B)
d = []
p = []

for i in range(1,int(pow(g, 0.5))+1):
    if g % i == 0:
        d.append(i)
        if i != g//i:
           d.append(g//i)

for i in d:
    s = 0
    for j in range(1,int(pow(i, 0.5))+1):
        if i % j == 0:
            s += 1

    if s == 1:
        p.append(i)

print(len(p))
### BUGGY CODE ###

h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(m)]
hlist = [0]*h
wlist = [0]*w
for i in hw:
    hlist[i[0]-1]+=1
    wlist[i[1]-1]+=1

hmax=max(hlist) 
h_index = [n for n, v in enumerate(hlist) if v == hmax]
wmax=max(wlist)
w_index = [n for n, v in enumerate(wlist) if v == wmax]

count = sum(x-1 in h_index and y-1 in w_index for x,y in hw)
print(hmax+wmax-(count==len(h_index)*len(w_index)))


### FIXED CODE ###

#実験 貼り付けコード
h,w,m = map(int,input().split())
s = [list(map(int,input().split())) for _ in range(m)]

r = [0] * (h + 1)
c = [0] * (w + 1)
for x, y in s:
    r[x] += 1
    c[y] += 1
R = max(r)
nr = {i for i, x in enumerate(r) if x == R}
C = max(c)
nc = {i for i, x in enumerate(c) if x == C}
count = sum(x in nr and y in nc for x, y in s)
print(R + C - (len(nr) * len(nc) == count))
### BUGGY CODE ###

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

a = list(map(int, input().split()))
heapq.heapify(a)

min_num = a[0]

tmp_array = []

for i in range(m):
  b,c = map(int, input().split())
  tmp_array.append([b,c])

sort_array = sorted(tmp_array, key=lambda x: x[1])

for i in range(m):
  b = sort_array[i][0]
  c = sort_array[i][1]
  if min_num >= c:
    continue
  else:
    for j in range(b):
      if a[0] < c:
        heapq.heappop(a)
        heapq.heappush(a, c)
      else:
        break
    min_num = a[0]

#for i in range(m):
#  b,c = map(int, input().split())
#  if min_num >= c:
#    continue
#  else:
#    for j in range(b):
#      if a[0] < c:
#        heapq.heappop(a)
#        heapq.heappush(a, c)
#      else:
#        break
#    min_num = a[0]

print(sum(a))

### FIXED CODE ###

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

a = list(map(int, input().split()))
heapq.heapify(a)

min_num = a[0]

tmp_array = []

for i in range(m):
  b,c = map(int, input().split())
  tmp_array.append([b,c])

sort_array = sorted(tmp_array, key=lambda x: -x[1])

for i in range(m):
  b = sort_array[i][0]
  c = sort_array[i][1]
  if min_num >= c:
    continue
  else:
    for j in range(b):
      if a[0] < c:
        heapq.heappop(a)
        heapq.heappush(a, c)
      else:
        break
    min_num = a[0]

#for i in range(m):
#  b,c = map(int, input().split())
#  if min_num >= c:
#    continue
#  else:
#    for j in range(b):
#      if a[0] < c:
#        heapq.heappop(a)
#        heapq.heappush(a, c)
#      else:
#        break
#    min_num = a[0]

print(sum(a))
### BUGGY CODE ###

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = 0
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        ans += sum(1 for x in l[j+1:] if x < l[i] + l[j])
print(ans)

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        ans += max(bisect.bisect_left(l, l[i] + l[j])-j-1, 0)
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
if k == 1:
    print(0)
else:
    while n > k:
        n = n-k
    if n < k-n:
        print(n)
    else:
        print(k-n)

### FIXED CODE ###

n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
else:
    n = n%k
    if n < k-n:
        print(n)
    else:
        print(k-n)
### BUGGY CODE ###

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

import math

n = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

Bc, Cc = [0]*n, [0]*n
Bp, Cp = 0, 0

for i in range(n):
    for j in range(Bp, n, 1):
        if A[i] < B[j]:
            Bc[i] = n - j
            Bp = j
            break
    for j in range(Cp, n, 1):
        if B[i] < C[j]:
            Cc[i] = n - j
            Cp = j
            break

Ccs = [sum(Cc[i:]) for i in range(n)]

count = 0
for bc in Bc:
    if bc > 0:
        count += Ccs[n-bc]

print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-
 
import bisect
 
n = int(input())
 
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
A.sort()
B.sort()
C.sort()
 
Ac, Cc = [0]*n, [0]*n
# Ap, Cp = 0, 0
 
for i in range(n):
    Ac[i] = bisect.bisect_left(A, B[i])#[Ap:], B[i])
    # Ac[i], Ap = index + Ap, index + Ap
    Cc[i] = n - bisect.bisect_right(C, B[i])#[Cp:], B[i])
    # Cc[i], Cp = n - index - Cp, index + Cp
 
 
count = 0
for i in range(n):
    count += Ac[i]*Cc[i]
 
print(count)
### BUGGY CODE ###

N = int(input())
pow = 1
for i in range (1,N+1):
    pow *=  i
print(pow%(10**9+7))

### FIXED CODE ###

N = int(input())
pow = 1
for i in range(1,N+1):
    pow = pow*i%(10**9+7)
print(pow)
### BUGGY CODE ###

class SegTree:
    X_unit = 1 << 30
    X_f = min

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)
      
N, Q=map(int,input().split())
S1=SegTree(N)
S2=SegTree(N)

S1.build([N]*N)
S2.build([N]*N)
ans=(N-2)**2

for i in range(Q):
  j, x=map(int,input().split())
  if j==1:
    l=S2.fold(x-1,N)
    ans-=l-2
    S1.set_val(l-1,min(x,S1.X[l-1+N]))
  if j==2:
    l=S1.fold(x-1,N)
    ans-=l-2
    S2.set_val(l-1,min(x,S2.X[l-1+N]))
    
print(ans)

### FIXED CODE ###

class SegTree:
    X_unit = 1 << 30
    X_f = min

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)
      
N, Q=map(int,input().split())
S1=SegTree(N)
S2=SegTree(N)

S1.build([N]*N)
S2.build([N]*N)
ans=(N-2)**2

for i in range(Q):
  j, x=map(int,input().split())
  if j==1:
    l=S2.fold(x-1,N)
    ans-=l-2
    S1.set_val(l-1,min(x,S1.X[l-1+N]))
  if j==2:
    l=S1.fold(x-1,N)
    ans-=l-2
    S2.set_val(l-1,min(x,S2.X[l-1+N]))
    
print(ans)
### BUGGY CODE ###

def main():
    s = input()
    r = [0]*len(s)
    r[0] = int(s[-1])
    temp = r[0]
    for i in range(1,len(s)):
        r[i] = (int(s[-(1+i)])*10**i+ temp) % 2019
        temp = r[i]
    
    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    if cts[0]>0:
        ans+=1

    print(ans)
main()

### FIXED CODE ###

def main():
    s = list(map(int, list(input())))
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = s[-(1+i)]*pow(10,i,2019)
        r[i] = (temp+r[i-1])%2019

    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    ans+=cts[0]

    print(ans)

main()
### BUGGY CODE ###

def binery_search(left,right,L,a,b):
    while True:
            #print(left,right,mid,cnt)
            mid = int( (left+right)/2 )
            if a+b <= L[mid]:
                right = mid
            elif a+b > L[mid]:
                left = mid + 1

            if left == right:
                return left

def main():
    N = int(input())
    L = list(map(int,input().split()))
    L.sort()
    ans = 0
    for i in range(N-2):
        for j in range(i+1,N-1,1):
            a = L[i]
            b = L[j]
            num = binery_search(j+1,N,L,a,b)
            #print(L,a,b,num)
            ans += num-(j+1)

    return ans

print(main())


### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = sorted(list(map(int,input().split())))
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tmp = bisect_left(L,L[i]+L[j])
        cnt += tmp - j - 1

print(cnt)
### BUGGY CODE ###

n, m = map(int, input().split())
prices = []
keymap = []
for _ in range(m):
    a, b = map(int, input().split())
    prices.append(a)
    c = list(map(int, input().split()))
    state = 0
    for ck in c:
        state |= 1 << ck - 1
        # print(format(state, "b"))
    keymap.append(state)

# print(keymap)

dp = [float("inf")] * (1 << n)  # 2 ** n
dp[0] = 0

for price, keyto in zip(prices, keymap):
    # print("--- step start ---")
    # print(dp)
    dp_new = dp[:]
    for s, d in enumerate(dp):
        # print("=== DP ===")
        # print("s:", format(s, "b"))
        # print("c:", format(keyto, "b"))
        dp_new[s | keyto] = min(d + price, dp_new[s | keyto])

    dp = dp_new
    # print(dp)

cost = dp[-1]
print(cost if cost != float("inf") else -1)

### FIXED CODE ###

n, m = map(int, input().split())
prices = []
keymap = []
for _ in range(m):
    a, b = map(int, input().split())
    prices.append(a)
    c = list(map(int, input().split()))
    state = 0
    for ck in c:
        state |= 1 << ck - 1
        # print(format(state, "b"))
    keymap.append(state)

# print(keymap)

dp = [float("inf")] * (1 << n)  # 2 ** n
dp[0] = 0

for price, keyto in zip(prices, keymap):
    # print("--- step start ---")
    # print(dp)
    dp_new = dp[:]
    for s, d in enumerate(dp):
        # print("=== DP ===")
        # print("s:", format(s, "b"))
        # print("c:", format(keyto, "b"))
        dp_new[s | keyto] = min(d + price, dp_new[s | keyto])

    dp = dp_new
    # print(dp)

cost = dp[-1]
print(cost if cost != float("inf") else -1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
A,B = map(int,input().split())
chk=0
for i in range(A, B+1):
  chk = chk ^ i
print(chk)


### FIXED CODE ###

import sys
input = sys.stdin.readline
A,B = map(int,input().split())

def hoge(N):
  tmp = N//2
  if N%2 == 1:
    tmp+=1
    last=0
  else:
    last=N
  if tmp%2 == 1:
    return last+1
  else:
    return last

print(hoge(A-1) ^ hoge(B))
### BUGGY CODE ###

import numpy as np

N = int(input())
a = np.fromstring(input(), sep=" ", dtype=np.int64)
for n in range(N):
    print(np.bitwise_xor.reduce(a) ^ a[n])


### FIXED CODE ###

import numpy as np

N = int(input())
a = np.fromstring(input(), sep=" ", dtype=np.int64)
b = np.bitwise_xor.reduce(a)
c = np.bitwise_xor(a, b)
print(*c, sep=" ")
### BUGGY CODE ###

N, K = map(int, input().split())
t_list = list(map(int, input().split()))
go_list = [-1]*N
go_list[0] = 1
hige = 0
syuuki = 0

i = 0
while i < N:
  if go_list[i] == -1:
    if go_list.count(t_list[go_list[i-1]-1]) == 0:
      go_list[i] = t_list[go_list[i-1]-1]
    else:
      hige = go_list.index(t_list[go_list[i-1]-1])
      syuuki = i - hige
      break
  i += 1

if K > hige:
  K -= hige
  K %= syuuki
  K += hige

print(go_list[K])

### FIXED CODE ###

N, K = map(int, input().split())
T_list = list(map(int, input().split()))
T_list = [T_list[i]-1 for i in range(N)]
point = 0
syuuki = 0

if K < N:
  i = 0
  while i < K:
    point = T_list[point]
    i += 1  

else:
  i = 0
  while i < N:
    point = T_list[point]
    if point == 0:
      syuuki = i+1
      break
    i += 1
  second_point = point
  
  if syuuki != 0:
    L = K % syuuki

  else:
    j = 0
    while j < N:
      point = T_list[point]
      if point == second_point:
        syuuki = j+1
        break
      j += 1
    L = (K-i) % syuuki

  k = 0
  while k < L:
    point = T_list[point]
    k += 1
  
print(point+1)
### BUGGY CODE ###

class SegmentTree:
    def __init__(self, lst, op, e):
        self.n = len(lst)
        self.N = 2**((self.n-1).bit_length())
        self.op = op # operation
        self.e = e # identity element
        self.v = [None]*(2*self.N-1)
        
        # construction
        for i in range(self.N):
            self.v[i + self.N - 1] = lst[i] if i < self.n else self.e
        for i in range(self.N - 2, -1, -1):
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i + 2])
        
    # update a_i to be x 
    def update(self, i, x):
        i += self.N - 1
        self.v[i] = x
        while i > 0:
            i -= 1
            i >>= 1
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i+2])
    
    # returns answer for the query interval [l, r)
    def query(self, l, r):
        assert l < r
        left = l + self.N - 1
        right = r + self.N - 1
        L = self.e
        R = self.e
        while left < right:
            if left % 2 == 0: # left is even
                L = self.op(L, self.v[left])
                left += 1
            if right % 2 == 0: # right is even
                right -= 1
                R = self.op(self.v[right], R)
            left -= 1
            left >>= 1
            right >>= 1
        return self.op(L, R)

N = int(input())
*A, = map(int, input().split())
INF = float('inf')
seg_tr = SegmentTree(A, min, INF)
ans = 0
for l in range(N):
    for r in range(l+1, N+1):
        ans += seg_tr.query(l, r)
print(ans)

### FIXED CODE ###

N = int(input())
*A, = map(int, input().split())
indices = {a: i for i, a in enumerate(A)}
left = {i: i for i in range(N)} # "left[i] = l" is equivalent to "A[l], ..., A[i-1] > A[i]"
right = {i: i for i in range(N)} # "right[i] = r" is equivalent to "A[i] < A[i+1], ..., A[r]"
ans = 0
for a in range(N, 0, -1):
    idx = indices[a]
    l, r = left[idx], right[idx]
    ans += (idx - l + 1) * (r - idx + 1) * a
    left[r+1], right[l-1] = l, r # A[l-1] < A[l], ..., A[r] > A[r+1]
print(ans)
### BUGGY CODE ###

def solve(p, q, a, n):
    def _solve(num, dem, d, m, s):
        if p * dem == q * num:
            return 1
        if p * dem < q * num or d == 0 or dem * s ** d > a:
            return 0
        if p * dem * s - num * q * s > d * q * dem:
            return 0
        return sum((_solve(num*i+dem, dem*i, d-1, m*i, i) for i in range(s, a//m+1)), 0)
    return _solve(0, 1, n, 1, 1)
        
if __name__ == "__main__":
    while True:
        p, q, a, n = [int(i) for i in input().split()]
        if p == 0:
            break
        print(solve(p, q, a, n))

### FIXED CODE ###

from functools import lru_cache

@lru_cache(maxsize=1<<10)
def solve(p, q, a, n):
    def _solve(num, dem, d, m, s):
        if num == 0:
            return 1
        if d == 0:
            return 0
        if num * a // m < dem:
            return 0
        return sum((_solve(num*i-dem, dem*i, d-1, m*i, i)
                    for i in range(s, min(dem*n//num, a//m)+1)), 0)
    return _solve(p, q, n, 1, 1)

if __name__ == "__main__":
    ans = []
    while True:
        p, q, a, n = [int(i) for i in input().split()]
        if p == 0:
            break
        ans.append(solve(p, q, a, n))
    print(*ans, sep="\n")
### BUGGY CODE ###

N = int(input())
S = str(input())
cnt = 0
for k in range(N):
    for j in range(N):
        for i in range(N):
            if i < j < k and S[i] != S[j] and S[j] != S[k] and S[k] != S[i] and (j - i) != (k - j):
                cnt += 1

print(cnt)

### FIXED CODE ###

n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

cnt = 0
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1
ans -= cnt

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

import numpy as np
import copy

S = str(input())
Q = int(input())

Que = [0]* Q
for i in range(Q):
    Que[i] = list(map(str, input().split()))

answer = copy.copy(S)
for i in range(Q):
    T = Que[i][0]
#    print(T)
    if int(T) == 1:
        answer = ''.join(list(reversed(answer)))
    else:
        F = Que[i][1]
        if int(F) == 1:
            answer = Que[i][2] + answer
        else:
            answer = answer + Que[i][2]
print(answer)

### FIXED CODE ###

import numpy as np
import copy
from collections import deque

S = str(input())
Q = int(input())

Que = [0]* Q
for i in range(Q):
    Que[i] = list(map(str, input().split()))

check = 1
L = deque()
R = deque()
for i in range(Q):
    T = Que[i][0]
    if int(T) == 1:
        check *= -1
    else:
        F = Que[i][1]
        if (int(F) == 1 and check == 1) or (int(F) == 2 and check == -1):
#            answer = ''.join([Que[i][2], answer])
            L.appendleft(Que[i][2])
        else:
#            answer = ''.join([answer, Que[i][2]])
            R.append(Que[i][2])
answer = ''.join(L) + S + ''.join(R)
if check == -1:
    answer = ''.join(list(reversed(answer)))
print(answer)
### BUGGY CODE ###

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

from itertools import combinations
from bisect import bisect_right,bisect_left

comb=combinations(L, 2)
cnt=0
for cb in comb:
    b,c=min(cb), max(cb)
    # a must be b or lower
    hi=bisect_left(L, b)
    new_L=L[:hi]
    low=bisect_right(new_L, c-b)
    #print(b,c,hi,low)
    cnt+=max(0,hi-low)
print(cnt)


### FIXED CODE ###

from bisect import bisect_left

n=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(n-2):
    a=L[i]
    for j in range(i+1,n-1):
        ans+=bisect_left(L,a+L[j])-j-1
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
B = set(A)
C = sorted([i for i in B if A.count(i) // 2 >= 1],reverse = True)

ans = 0
m = 0
n = 0

if len(C) == 0:
 ans = 0
 
elif A.count(C[0]) >= 4:
  m = C[0]
  ans = m ** 2

elif len(C) > 1:
  m = C[0]
  n = C[1]
  ans = m * n

print(ans)

### FIXED CODE ###

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

edge = []

for i in range(1,N):
  if A[i] == A[i - 1] and A[i] not in edge:
    edge.append(A[i])
  elif A[i] == A[i - 3]:
    edge.append(A[i])
  
  if len(edge) == 2:
    break
    
if len(edge) <= 1:
  print(0)
else:
  print(edge[0] * edge[1])
### BUGGY CODE ###

n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
seq_s = "".join(s)
ans = 0
start_i = 0
for i in range(n):
    cnt = seq_s.count(s[i],start_i)
    ans += cnt - 1
    start_i += len(s[i])

print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
used_s = {}
for _ in range(n):
    s = "".join(sorted(input()))
    if not s in used_s.keys():
        used_s[s] = 0
    else:
        used_s[s] += 1
        ans += 1 * used_s[s]

print(ans)