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

#coding:utf-8
import numpy as np
def argsort_p1(ls):
    return [sorted(ls).index(t)+1 for t in ls]


N,M = list(map(int,input().split()))
P = []
Y = []
for m in range(M):
    p,y = list(map(int,input().split()))
    P.append(p)
    Y.append(y)
#print (P,Y)
ls = [ [] for _ in range(max(P))]
ls_idx = [ [] for _ in range(max(P))]
#print (ls)
for p,y in zip(P,Y):
    ls[p-1].append(y)
    ls_idx[p-1].append(len(ls_idx[p-1]))
ls_dict = []
new_dict = {}
for i,line in enumerate(ls):
    #arg_line = np.argsort(line)+1
    arg_line = argsort_p1(line)
    #print (arg_line)
    temp_dict = dict(zip(line, arg_line))
    ls_dict.append(temp_dict)
    for arg in arg_line:
        #print (line[arg-1])
        new_dict[str(i+1)+"/"+str(sorted(line)[arg-1])]=str(i+1).zfill(6)+str(arg).zfill(6)
#print (new_dict)
#print (ls_dict)
for p,y in zip(P,Y):
#    print (str(p).zfill(6)+str(ls_dict[p-1][y]).zfill(6))
    print (new_dict[str(p)+"/"+str(y)])


### FIXED CODE ###

N, M = map(int,input().split())
ls = []
for m in range(M):
    p, y = map(int,input().split())
    ls.append([p,y])
sorted_ls = sorted(ls,key=lambda x:x[1])
counter = [0 for i in range(N+1)]
d = {}
for p,y in sorted_ls:
    counter[p]+=1
    num = counter[p]
    d[y] = num
for p,y in ls:
    #print (p,d[y])
    print (str(p).zfill(6)+str(d[y]).zfill(6))
### BUGGY CODE ###

'''
Created on 2020/08/26

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  s=pin()[:-1]
  K=int(pin())
  d=[]
  for i in range(1,len(s)+1):
    for j in range(len(s)-i+1):
      t=s[j:j+i]
      d.append(t)
  l=sorted(list(set(d)))
  print(l[K-1])
  return 
main()

### FIXED CODE ###

'''
Created on 2020/08/26

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  s=pin()[:-1]
  K=int(pin())
  d=[]
  for i in range(1,K+1):
    for j in range(len(s)-i+1):
      d.append(s[j:j+i])
  ans=sorted(list(set(d)))
  print(ans[K-1])
  return
main()

#解説AC
### BUGGY CODE ###

from collections import Counter
from itertools import product

N = int(input())
S = input().strip()
dic = Counter(S)
mod = 10**9 + 7

ans = 0
ls =list(product([0, 1], repeat=len(dic)))
ls.pop(0)

a = []
for i in dic:
    a.append(dic[i])

for x in ls:
    num = 1
    for z, y in zip(a, x):
        if y == 1:
            num = (z*num)%mod
    ans = (ans+num)%mod
print(ans)

### FIXED CODE ###

from collections import Counter
from itertools import product
 
N = int(input())
S = input().strip()
dic = Counter(S)
mod = 10**9 + 7

ans = 1
for x in dic:
    ans = ans*(dic[x]+1)%mod
print(ans-1)
### BUGGY CODE ###

import math
N, K = map(int, input().split())
P = list(map(int, input().split()))

tmp = []
MA = 0
for i in range(N - K + 1):
    M = 0
    t = []
    for j in range(K):
        M += P[i + j]
        t.append(P[i + j])
    
    if M > MA:
        tmp = t
        MA = M



    # print(M)
    # print(i)
# print(tmp)
ans = 0
for t in tmp:
    ans += t * (t + 1) / (2 * t)
print("{:.12f}".format(ans))

### FIXED CODE ###

import math
N, K = map(int, input().split())
P = list(map(int, input().split()))

INDEX = 0
total = 0
for i in range(K):
    total += P[i]

tmp = total
for i in range(N - K):
    tmp = tmp - P[i] + P[i + K]
    
    if tmp > total:
        total = tmp
        INDEX = i+1


# MA = 0
# for i in range(N - K + 1):
#     M = 0
#     for j in range(K):
#         M += P[i + j]
    
#     if M > MA:
#         MA = M
#         INDEX = i

ans = 0
for i in range(K):
    ans += P[i+INDEX] * (P[i+INDEX]+1) / (2*P[i+INDEX])

print("{:.12f}".format(ans))
### BUGGY CODE ###

import numpy as np

inputData = input().split()
N, K, Q = [int(x) for x in inputData]
points = np.array([K]*N)

for i in range(Q):
    A = int(input())
    points -= 1
    points[A-1] += 1

for j in range(N):
    if points[j] > 0:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

import numpy as np

inputData = input().split()
N, K, Q = [int(x) for x in inputData]
points = np.array([K]*N)

for i in range(Q):
    A = int(input())
    points[A-1] += 1
points -= Q
for j in range(N):
    if points[j] > 0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

#import math
from functools import reduce

def gcd(a,b):
    r = 1
    while r > 0:
        r = a % b
        a = b
        b = r

    return a


n = int(input())
a = [int(i) for i in input().split()]
L = [0] * n

for i in range(n):
    aa = a[:]
    aa.pop(i)
    L[i] = reduce(gcd, aa)

print(max(L))


### FIXED CODE ###

def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    r = 1
    while r > 0:
        r = a % b
        a = b
        b = r
    return a


n = int(input())
A = [int(i) for i in input().split()]

L = [0] * n
L[0] = 0
L[1] = A[0]
for i in range(2,n):
    L[i] = gcd(L[i-1], A[i-1])

R = [0] * n
R[-1] = 0
R[-2] = A[-1]
for i in range(3,n+1):
    R[-i] = gcd(R[-i+1], A[-i+1])

M = [gcd(L[i],R[i]) for i in range(n)]

print(max(M))
### BUGGY CODE ###

N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for c in range(2,N):
    cc=L[c]
    for b in range(1,c):
        bb=L[b]
        if cc>=bb+L[b-1]: continue
        l=-1
        u=b-1
        while u-l>1:
            a=(l+u+1)//2
            aa=L[a]
            if aa+bb>cc: u=a
            else: l=a
        ans+=(b-u)
print(ans)

### FIXED CODE ###

N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for c in range(2,N):
    cc=L[c]
    for b in range(1,c):
        bb=L[b]
        if cc>=bb+L[b-1]: continue
        l=-1
        u=b-1
        while u-l>1:
            a=(l+u+1)//2
            aa=L[a]
            if aa+bb>cc: u=a
            else: l=a
        ans+=(b-u)
print(ans)
### BUGGY CODE ###

n = int(input())
big = 0
a = list(map(int, input().split()))
ans = 1
for num in a:
    ans = ans * num
if ans > 10 ** 18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
big = 0
a = list(map(int, input().split()))
a.sort()
ans = 1
for num in a:
    if num == 0:
        print(0)
        big = 1
        break
    ans = ans * num
    if ans > 10 ** 18:
        print(-1)
        big = 1
        break
if big == 0:
    print(ans)
### BUGGY CODE ###

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

bin_digit = [0]*50
for ai in a:
    i = 0
    while ai>0:
        bin_digit[i] += int(bin(ai)[-1])
        i += 1
        ai = ai>>1

length_k = len(bin(k))-2
x_k = [None]*length_k
for i in range(length_k):
    if 2*bin_digit[i]>=n:
        x_k[i] = 0
    else:
        x_k[i] = 1

bin_k = list(map(int, bin(k)[-1:1:-1]))
for i in range(length_k-1,-1,-1):
    if x_k[i]>bin_k[i]:
        x_k[i] = 1-x_k[i]
    elif x_k[i]<bin_k[i]:
        break

x = sum(x_k[i]*2**i for i in range(len(x_k)))
ans = sum(x^ae for ae in a)
print(ans)


### FIXED CODE ###

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

bin_digit = [0]*50
for ai in a:
    i = 0
    bin_ai = bin(ai)
    for i in range(len(bin_ai)-2):
        if bin_ai[-1-i] == '1':
            bin_digit[i] += 1
        i += 1

bin_k = list(map(int, bin(k)[-1:1:-1]))
length_k = len(bin_k)
x_k = [None]*length_k
for i in range(length_k):
    if 2*bin_digit[i]>=n:
        x_k[i] = 0
    else:
        x_k[i] = 1

for i in range(length_k-1,-1,-1):
    if x_k[i]>bin_k[i]:
        x_k[i] = 1-x_k[i]
    elif x_k[i]<bin_k[i]:
        break

x = sum(x_k[i]*2**i for i in range(len(x_k)))
ans = sum(x^ae for ae in a)
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]

for a, b in ab:
    if a == 1:
        for a2, b2 in ab:
            if a2 == b and b2 == n:
                print("POSSIBLE")
                exit()
    if b == 1:
        for a2, b2 in ab:
            if b2 == a and a2 == n:
                print("POSSIBLE")
                exit()

print("IMPOSSIBLE")

### FIXED CODE ###

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

graph = [list() for i in range(n+1)]

for i in range(m):
    a, b = map(int, (input().split()))
    graph[a] += [b]
    graph[b] += [a]

for i in graph[1]:
    if n in graph[i]:
        print("POSSIBLE")
        exit()
        
print("IMPOSSIBLE")
### BUGGY CODE ###

def froyd(n, d):
    for k in range(n):
        for s in range(n):
            # ds = d[s]
            for t in range(n):
                d[s][t] = min(d[s][t], d[s][k] + d[k][t])


def main():
    N, M, L = [int(x) for x in input().split()]
    INF = float("inf")
    A = [[] for _ in range(N)]
    B = [[] for _ in range(N)]
    for i in range(N):
        A[i] = [INF] * N
        A[i][i] = 0
        B[i] = [INF] * N
        B[i][i] = 0
    for i in range(M):
        a, b, c = [int(x) for x in input().split()]
        A[a - 1][b - 1] = c
        A[b - 1][a - 1] = c
    froyd(N, A)
    # print(A)
    for s in range(N):
        for t in range(N):
            B[s][t] = 0 if s == t else 1 if A[s][t] <= L else INF
    # print(B)
    froyd(N, B)
    # print(B)

    Q = int(input())
    for _ in range(Q):
        s, t = [int(x) for x in input().split()]
        b = B[s - 1][t - 1] - 1
        print(-1 if b == INF else b)


main()


### FIXED CODE ###

def froyd(n, d):
    for k in range(n):
        for s in range(n):
            ds = d[s]
            for t in range(n):
                ds[t] = min(ds[t], ds[k] + d[k][t])


def main():
    N, M, L = [int(x) for x in input().split()]
    INF = float("inf")
    A = [[] for _ in range(N)]
    B = [[] for _ in range(N)]
    for i in range(N):
        A[i] = [INF] * N
        A[i][i] = 0
        B[i] = [INF] * N
        B[i][i] = 0
    for i in range(M):
        a, b, c = [int(x) for x in input().split()]
        A[a - 1][b - 1] = c
        A[b - 1][a - 1] = c
    froyd(N, A)
    # print(A)
    for s in range(N):
        for t in range(N):
            B[s][t] = 0 if s == t else 1 if A[s][t] <= L else INF
    # print(B)
    froyd(N, B)
    # print(B)

    Q = int(input())
    for _ in range(Q):
        s, t = [int(x) for x in input().split()]
        b = B[s - 1][t - 1] - 1
        print(-1 if b == INF else b)


main()
### BUGGY CODE ###

a_i,a_o,a_t,a_j,a_l,a_s,a_z=map(int,input().split())
ans1=0
ans1+=a_o
ans2=0
for i in range(min(a_i,a_j,a_l)+1):
  tmp=3*i+2*((a_i-i)//2+(a_j-i)//2+(a_l-i)//2)
  ans2=max(ans2,tmp)
print(ans1+ans2)

### FIXED CODE ###

a_i,a_o,a_t,a_j,a_l,a_s,a_z=map(int,input().split())
ans1=a_o
if min(a_i,a_j,a_l)==0:
  ans2=2*(a_i//2+a_j//2+a_l//2)
else:
  ans2=max(2*(a_i//2+a_j//2+a_l//2),3+2*((a_i-1)//2+(a_j-1)//2+(a_l-1)//2))
print(ans1+ans2)
### BUGGY CODE ###

import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
A = l()
ans = 1
for i in range(N):
    c = A.count(i)
    if N%2 == i%2:
        if c:
            ans *= 0
    else:
        if c == 0:
            ans *= 0
        if c == 1:
            if i != 0:
                ans *= 0
        if c == 2:
            ans *= 2
print(ans)

### FIXED CODE ###

import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
A = l()
ans = 1
l = [0]*N
for i in range(N):
    l[A[i]] += 1
for i in range(N):
    c = l[i]
    if N%2 == i%2:
        if c:
            ans *= 0
    else:
        if c == 0:
            ans *= 0
        if c == 1:
            if i != 0:
                ans *= 0
        if c == 2:
            ans *= 2
print(ans%mod)
### BUGGY CODE ###

n = int(input())
s = input()
R = []
G = []
B = []

for i in range(n):
    if s[i] == "R":
        R.append(i+1)
    elif s[i] == "G":
        G.append(i+1)
    else:
        B.append(i+1)

res = 0
for r in R:
    for g in G:
        for b in B:
            lis = [r,g,b]
            lis.sort()
            if lis[0] + lis[2] != lis[1] * 2:
                res += 1
print(res)

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = 0
    G = 0
    B = 0

    for i in range(n):
        if s[i] == "R":
            R += 1
        elif s[i] == "G":
            G += 1
        else:
            B += 1
            
    res = R*G*B
    for i in range(n - 2):
        for j in range(i + 1, i + 1 + (n - 1 - i) // 2):
            k = j + (j - i)
            if s[i] != s[j] != s[k] != s[i]:
                res -= 1
    print(res)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

if 0 in a:
  ans = 0
else:
  ans = 1
  for item in a:
    ans *= item
    if ans > 1000000000000000000:
      ans = -1
print(ans)


### FIXED CODE ###

def main():
  N = int(input())
  A = list(map(int, input().split()))
  
  if 0 in A:
    print(0)
    return
  
  prod = 1
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod)
  
main()
### BUGGY CODE ###

n = int(input())

a = list(map(int, input().split()))
count = 1
for i in a:
    count *= i
if count > 10 ** 18:
    print(-1)
else:
    print(count)

### FIXED CODE ###

n = int(input())

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

count = 1
if 0 in a:
    print(0)
else:

    for i in a:
        count *= i
        if count > 10 ** 18:
            print(-1)
            break
    if count <= 10 ** 18:
        print(count)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split(' ')))
ans = 1
for l in A:
    ans *= l
if 10**18 < ans:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split(' ')))
ans = 1
if 0 in A:
    ans = 0
else:
    for l in A:
        ans *= l
        if 10**18 < ans:
            ans = -1
            break
print(ans)
### BUGGY CODE ###

mod = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())

fact = [1] * (r2 + c2 + 3)
inv = [1] * (r2 + c2 + 3)
inv_fact = [1] * (r2 + c2 + 3)
for i in range(2, r2 + c2 + 3):
  fact[i] = fact[i-1] * i % mod
  inv[i] = -inv[mod % i] * (mod // i) % mod
  inv_fact[i] = inv_fact[i-1] * inv[i] % mod

total = fact[r2 + c2 + 2] * inv_fact[r2 + 1] * inv_fact[c2 + 1] % mod
total -= fact[r1 + c2 + 1] * inv_fact[r1] * inv_fact[c2 + 1] % mod
total -= fact[r2 + c1 + 1] * inv_fact[c1] * inv_fact[r2 + 1] % mod
total += fact[r1 + c1] * inv_fact[r1] * inv_fact[c1] % mod

print(total)

### FIXED CODE ###

mod = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())

fact = [1] * (r2 + c2 + 3)
inv = [1] * (r2 + c2 + 3)
inv_fact = [1] * (r2 + c2 + 3)
for i in range(2, r2 + c2 + 3):
  fact[i] = fact[i-1] * i % mod
  inv[i] = -inv[mod % i] * (mod // i) % mod
  inv_fact[i] = inv_fact[i-1] * inv[i] % mod

total = fact[r2 + c2 + 2] * inv_fact[r2 + 1] * inv_fact[c2 + 1] % mod
total -= fact[r1 + c2 + 1] * inv_fact[r1] * inv_fact[c2 + 1] % mod
total -= fact[r2 + c1 + 1] * inv_fact[c1] * inv_fact[r2 + 1] % mod
total += fact[r1 + c1] * inv_fact[r1] * inv_fact[c1] % mod

print(total % mod)
### BUGGY CODE ###

#ABC077 C - Snuke Festival
from bisect import bisect_left, bisect_right
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N = ni()
A = nl()
B = nl()
C = nl()

A.sort()
B.sort()
C.sort()
ans = 0

for i in range(N):
    t = 0
    tt = 0
    t = bisect_left(B,C[i])
    for j in range(t,0,-1):
        tt = bisect_left(A,B[j-1])
        ans += tt

print(ans)

### FIXED CODE ###

#ABC077 C - Snuke Festival
from bisect import bisect_left, bisect_right
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N = ni()
A = nl()
B = nl()
C = nl()

A.sort()
C.sort()

ans = 0

for i in range(N):
    t = 0
    tt = 0
    t = bisect_left(A,B[i])
    tt = N-bisect_right(C,B[i])
    ans += t*tt

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

import sys
import heapq
import math

input = sys.stdin.readline
N, M = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

g = [[] for _ in range(3*N)]
for a, b in uv:
    g[a-1].append(b-1+N)
    g[a-1+N].append(b-1+2*N)
    g[a - 1 + 2 * N].append(b - 1)

# bfsでよかった
hq = [(0, S-1)]
costs = [math.inf] * 3 * N
while len(hq) > 0:
    c, u = heapq.heappop(hq)
    if u == T - 1:
        print(c // 3)
        sys.exit()
    costs[u] = c
    for v in g[u]:
        if costs[v] > c+1:
            heapq.heappush(hq, (c + 1, v))
print(-1)


### FIXED CODE ###

import sys
import heapq
import math

input = sys.stdin.readline
N, M = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

g = [[] for _ in range(3*N)]
for a, b in uv:
    g[a-1].append(b-1+N)
    g[a-1+N].append(b-1+2*N)
    g[a - 1 + 2 * N].append(b - 1)

# bfsでよかった
hq = [(0, S-1)]
costs = [math.inf] * 3 * N
while len(hq) > 0:
    c, u = heapq.heappop(hq)
    if u == T - 1:
        print(c // 3)
        sys.exit()
    costs[u] = c
    for v in g[u]:
        if costs[v] > c+1:
            heapq.heappush(hq, (c + 1, v))
        costs[v] = min(costs[v], c+1)

print(-1)
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
idx = []

for i in range(n-1):
    if (s[i] == "A") & (s[i+1] == "C"):
        idx.append(i+1)

for j in range(q):
    l, r = map(int, input().split())
    n = [i for i in idx if ((i >= l) & (i < r))]
    print(len(n))


### FIXED CODE ###

n, q = map(int, input().split())
s = input()
m = [0]
c = 0
for i in range(1, n):
    if (s[i-1] == "A") & (s[i] == "C"):
        c += 1
    m.append(c)

for j in range(q):
    l, r = map(int, input().split())
    print(m[r-1] - m[l-1])
### BUGGY CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0,2,5,5,4,5,6,3,7,6]
ab = {}
for i in a:
    ab[i] = b[i]
dp = [0]*(n+10)
dp[0] = ""
for i in range(n+1):
    if dp[i] == 0:
        continue
    for j in ab.keys():
        if dp[i] == "":
            dp[i+ab[j]] = str(max(int(dp[i+ab[j]]),j))
        else:
            if dp[i][0]> str(j):
                next0 = dp[i]+str(j)
            else:
                next0 = str(j)+dp[i]
            if dp[i+ab[j]] == 0:
                dp[i+ab[j]] = next0
                continue
            if len(next0) > len(dp[i+ab[j]]):
                dp[i+ab[j]] = next0
            elif len(next0) < len(dp[i+ab[j]]):
                continue
            else:
                for k in range(len(next0)):
                    if next0[k]> dp[i+ab[j]][k]:
                        dp[i+ab[j]] = next0
                        break
                    elif next0[k]< dp[i+ab[j]][k]:
                        break
                else:
                    dp[i+ab[j]] = next0

print(dp[n])

### FIXED CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0,2,5,5,4,5,6,3,7,6]
ab = {}
for i in a:
    ab[i] = b[i]
dp = [0]*(n+10)
dp[0] = ""
for i in range(n+1):
    if dp[i] == 0:
        continue
    for j in ab.keys():
        if dp[i] == "":
            dp[i+ab[j]] = str(max(int(dp[i+ab[j]]),j))
        else:
            if dp[i][0]> str(j):
                next0 = dp[i]+str(j)
            else:
                next0 = str(j)+dp[i]
            if dp[i+ab[j]] == 0:
                dp[i+ab[j]] = next0
                continue
            if len(next0) > len(dp[i+ab[j]]):
                dp[i+ab[j]] = next0
            elif len(next0) < len(dp[i+ab[j]]):
                continue
            else:
                for k in range(len(next0)):
                    if next0[k]> dp[i+ab[j]][k]:
                        dp[i+ab[j]] = next0
                        break
                    elif next0[k]< dp[i+ab[j]][k]:
                        break
                else:
                    dp[i+ab[j]] = next0

print(dp[n])
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations 
from bisect import bisect_left
def main():
    N = int(readline())
    L = [int(i) for i in readline().split()]
    L.sort()
    sig = 0
    for i in range(N):
        for j in range(i+1, N):
            l = bisect_left(L[j+1:], L[i]+L[j])
            sig += l
    print(sig)
if __name__ == '__main__':
    main()


### FIXED CODE ###

#python3
from bisect import bisect_left
def main():
    n = int(input())
    L = [int(i) for i in input().split()]
    L.sort()
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            ab = L[i]+L[j]
            r = bisect_left(L, ab)
            l = j+1
            ans += r-l
    print(ans)
main()
### BUGGY CODE ###

n = int(input())

new = 1
a = list(map(int,input().split()))
for i in a:
	new = new * i 
val = pow(10,18)
if new > val:
	print(-1)
else:
	print(new)	 


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
new = 1
if 0 in a:
	print(0)
	exit()
for i in a:
	new *= i
	if new > (10**18):
		new = -1
		break
print(new)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
edge = [set() for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    edge[a-1].add(b-1)
    edge[b-1].add(a-1)

cost = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    cost[p-1] += x

ans = [0] * n
def dfs(v,p,value): #p: parent of v
    value += cost[v]
    ans[v] = value
    for c in edge[v]:
        if c == p: continue
        dfs(c,v,value)
# def dfs(cur, c, root):
    # # print(cur, c, root)
    # ans[cur] = c
    # for nex in edge[cur]:
        # if nex != root:
            # dfs(nex, c + cost[nex], cur)

dfs(0, -1, 0)
print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

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

connect = [set() for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x

ans = [0] * n
def dfs(me, parent, cum):
    cum += counter[me]
    ans[me] = cum
    for child in connect[me]:
        if child != parent:
            dfs(child, me, cum)

dfs(0, -1, 0)

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

c=0
N=int(input())
L=list(map(int,input().split()))
R=list()
for i in range(N):
  R.append(L[i])
  if min(R)==L[i]:
    c=c+1
print(c)

### FIXED CODE ###

mina=10**11
c=0
N=int(input())
L=list(map(int,input().split()))
for i in range(N):
  mina=min(mina,L[i])
  if mina==L[i]:
    c=c+1
print(c)
### BUGGY CODE ###

n = int(input())

nums = [0]*n
m = n//6
for i in range(1,m+1):
  for j in range(i, m+1):
    for k in range(j, m+1):
      t = i**2 + j**2 + k**2 + i*j + j*k + i*k
      if t <= n:
        if i == j and i == k: nums[t-1] += 1
        else: nums[t-1] += 3

print(*nums, sep="\n")

### FIXED CODE ###

from itertools import product
n = int(input())

nums = [0]*(n+1)
for i in product(range(1, int(n**0.5)+1),repeat=3):
  t = i[0]**2 + i[1]**2 + i[2]**2 + i[0]*i[1] + i[1]*i[2] + i[0]*i[2]
  if t <= n: nums[t] += 1

for i in range(1,n+1): print(nums[i])
### BUGGY CODE ###

import sys
s = input()
num = int(input())
for lines in sys.stdin.readlines():
  a = list(lines.split())
  start = int(a[0])
  if start == 2:
    ns = int(a[1])
    if ns == 1:
      s = a[2] + s
    else:
      s = s + a[2]
  else:
    s = s[::-1]
print(s)

### FIXED CODE ###

from collections import deque
s = deque(input())
num = int(input())
cnt = 0
for i in range(num):
  a = input().split()

  if a[0] == '2':
    if (int(a[1])+cnt)%2==1:
      s.appendleft(a[2])
    else:
      s.append(a[2])
  else:
    cnt += 1
if cnt%2 == 1:    
	s.reverse()
print("".join(s))