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

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

memo_dic = {}

def OK_area(n, c, d):
    l = []
    for i in range(c, d+1):
        l.append(n-i)
        l.append(n+i)
    l_uniq = list(set(l))
    return l_uniq

a = min(A, B)
b = max(A, B)
start = [a]
for i in range(N-1):
    list_i = []
    for s in start:
        if s in memo_dic:
            area = memo_dic[s]
        else:
            area = OK_area(s, C, D)
            memo_dic[s] = area
        list_i.extend(area)
        
    list_i_uniq = list(set(list_i))
    start = list_i_uniq
if b in start:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

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

answer_flag = False
for i in range(N):
    if (C*(N-1-i)-D*i<=(B-A)) and ((B-A)<=-C*i+D*(N-1-i)):
        answer_flag = True
        break

if answer_flag==True:
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

import math
n, k = map(int, input().split())
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
p = 10 ** 9 + 7
N = 10 ** 6 
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)
for i in range(1, k+1):
  print(cmb(n-k+1, i, p) * comb(k-1, i-1)%p)

### FIXED CODE ###

n, k = map(int, input().split())
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
N = 10 ** 6 
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)
for i in range(1, k+1):
  print(cmb(n-k+1, i, p) * cmb(k-1, i-1, p) % p)
### BUGGY CODE ###

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

x = []
for i in range(q):
    x.append(input().split())
for i in range(q-1, -1, -1):
    if x[i] == '1' and  x[i-1] == '1':
        x[i] = '0'
        x[i - 1] = '0'
    if x[i] == '1':
        for j in range(i-1, -1 , -1):
            if x[j][0] == '2':
                if x[j][1] == '1':
                    x[j][1] == '2'
                else:
                    x[j][2] == '1'
for i in range(q):
    if x[i][0] == '0':
        continue
    elif x[i][0] == '1':
        s = s[::-1]
    elif x[i][1] == '1':
        s = x[i][2] + s
    else:
        s = s + x[i][2]
print(s)

### FIXED CODE ###

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

x = []
pre = ''
post = ''
isone = False
for i in range(q):
    x = input().split()
    if x[0] == '1':
        if isone:
            isone = False
        else:
            isone = True
    elif x[1] == '1':
        if isone:
            post += x[2]
        else:
            pre += x[2]
    else:
        if isone:
            pre +=x [2]
        else:
            post += x[2]
    if i == q - 1:
        if isone:
            s = post[::-1] + s[::-1] + pre
        else:
            s = pre[::-1] + s + post
print(s)
### BUGGY CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w = na()
ch,cw = na()
dh,dw = na()
ch,cw = ch-1,cw-1
dh,dw = dh-1,dw-1
s = []
for i in range(h):
  s.append(ns())

from collections import deque

g = [[10000000000]*w for i in range(h)]
g[ch][cw] = 0
d = deque([(ch,cw,0)])

while d:
  x,y,num = d.popleft()
  pq = [(-1,0),(0,1),(1,0),(0,-1)]
  for p,q in pq:
    if not (0<=x+p<h and 0<=y+q<w):
      continue
    u = s[x+p][y+q]
    if u == '.':
      if num < g[x+p][y+q]:
        g[x+p][y+q] = num
        d.append((x+p,y+q,num))

  for i in range(-2,3):
    for j in range(-2,3):
      if not (0<=x+i<h and 0<=y+j<w):
        continue
      p = s[x+i][y+j]
      if p == '.':
        if num+1 < g[x+i][y+j]:
          g[x+i][y+j] = num+1
          d.append((x+i,y+j,num+1))

ans = g[dh][dw]

print('-1' if ans == 10000000000 else ans)

### FIXED CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w = na()
ch,cw = na()
dh,dw = na()
ch,cw = ch-1,cw-1
dh,dw = dh-1,dw-1
s = []
for i in range(h):
  s.append(ns())

from collections import deque

g = [[10000000000]*w for i in range(h)]
g[ch][cw] = 0
d = deque([(ch,cw,0)])

while d:
  x,y,num = d.popleft()
  pq = [(-1,0),(0,1),(1,0),(0,-1)]
  for p,q in pq:
    if not (0<=x+p<h and 0<=y+q<w):
      continue
    u = s[x+p][y+q]
    if u == '.':
      if num < g[x+p][y+q]:
        g[x+p][y+q] = num
        d.appendleft((x+p,y+q,num))

  for i in range(-2,3):
    for j in range(-2,3):
      if not (0<=x+i<h and 0<=y+j<w):
        continue
      p = s[x+i][y+j]
      if p == '.':
        if num+1 < g[x+i][y+j]:
          g[x+i][y+j] = num+1
          d.append((x+i,y+j,num+1))

ans = g[dh][dw]

print('-1' if ans == 10000000000 else ans)
### BUGGY CODE ###

import numpy as np
import itertools
n,k = map(int,input().split())
ary = np.array([list(map(int,input().split())) for _ in range(n)],dtype=float)
a = list(itertools.combinations(ary,k))
ans = float("Inf")
for i in a:
    min_a = np.min(i,axis=0)
    max_a = np.max(i,axis=0)
    a = max_a[0] - min_a[0]
    b = max_a[1] - min_a[1]
    ans = min(ans,int(a)*int(b))
print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
ary = [list(map(int,input().split())) for _ in range(n)]
ary.sort()

ans = float("Inf")
for i in range(n-k+1):
    for j in range(k,n-i+1):
        xmin = ary[i][0]
        xmax = ary[i+j-1][0]
        ary_y = sorted(ary[i:i+j], key=lambda x: (x[1]))
        for l in range(len(ary_y)-k+1):
            ymin = ary_y[l][1]
            ymax = ary_y[l+k-1][1]
            ans = min(ans,(xmax - xmin) * (ymax - ymin))
print(ans)
### BUGGY CODE ###

from fractions import gcd

# segfunc: 問題に応じて設定
def segfunc(x, y):
    return gcd(x, y)


# 配列aで初期化
def init(a):
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2]) 


# a[k]の値をxに更新
def update(k, x):
    k += num - 1
    seg[k] = x
    while k:
        k = (k - 1) // 2
        seg[k] = segfunc(seg[k*2+1], seg[k*2+2])


# [p, q)についてsegfuncを適用したものを返す
def query(p, q):
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p & 1 == 0:
            res = segfunc(res, seg[p])
        if q & 1 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(res, segfunc(seg[p], seg[q]))
    
    return res


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

ide_ele = 0
num = 2 ** (len(bin(n - 1)) - 2)
seg = [ide_ele] * 2 * num
init(a)

res = 0
for i in range(n):
    res = max(res, gcd(query(0, i), query(i+1, n)))

print(res)


### FIXED CODE ###

from fractions import gcd

# 配列aで初期化
def init(a):
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = gcd(seg[2*i+1], seg[2*i+2]) 


# a[k]の値をxに更新
def update(k, x):
    k += num - 1
    seg[k] = x
    while k:
        k = (k - 1) // 2
        seg[k] = gcd(seg[k*2+1], seg[k*2+2])


# [p, q)についてsegfuncを適用したものを返す
def query(p,q):
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p & 1 == 0:
            res = gcd(res, seg[p])
        if q & 1 == 1:
            res = gcd(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    if p == q:
        res = gcd(res, seg[p])
    else:
        res = gcd(gcd(res, seg[p]), seg[q])
    
    return res


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

ide_ele = 0
num = 2 ** (len(bin(n - 1)) - 2)
seg = [ide_ele] * 2 * num
init(a)

res = 0
for i in range(n):
    res = max(res, gcd(query(0, i), query(i+1, n)))

print(res)
### BUGGY CODE ###

from collections import defaultdict
class Sieve:
    """
    N以下の素数を列挙するエラトステネスのふるいです。
    O(NloglogN)でできます。

    Attributes
    sieveList : その数の素因数のうち最小のものの配列
    primes : N以下の素因数のリスト
    """
    def __init__(self, N):
        self.sieveList = [-1 for _ in range(N+1)]
        self.sieveList[1] = 1
        self.primes = []

        for i in range(2, N+1):
            #すでに何らかの数で割られていたらcontinue
            if self.sieveList[i] != -1:
                continue
            self.primes.append(i)
            for j in range(i, N+1, i):
                if self.sieveList[j] != -1:
                    continue
                self.sieveList[j] = i

    def getPrimes(self):
        return self.primes

    def getSieveList(self):
        return self.sieveList

class FastFactorization(Sieve):
    """
    高速素因数分解です。
    与えられたL個の数がA以下の時、
    エラトステネスでO(AloglogA)＋素因数分解でO(LlogA) = O(AloglogA+NlogA)でできます。
    """

    def __init__(self, N):
        """
        前処理でスーパークラスのエラトステネスを使ってN以下の素因数を列挙します。
        """
        super().__init__(N)
        self.N = N
        self.sieveList = self.getSieveList()

    def factorize(self, x):
        if x > self.N:
            raise ValueError("与えられた数がエラトステネスのリストの上限を超えている")
        # p = set()
        p = defaultdict(int)
        tmp = -1
        ans = 1
        while x > 1:
            divisor = self.sieveList[x]
            if divisor != tmp:
            	ans *= p[tmp] + 1
            	tmp = divisor
            x //= divisor
            # p.add(divisor)
            p[divisor] += 1
            
        ans *= p[tmp] + 1
            
        return ans
        
        

N = int(input()) # <= 10**7

ff = FastFactorization(N)

ans = 0
for i in range(1, N+1):
	factors = ff.factorize(i)

	ans += i * factors
	
print(ans)


### FIXED CODE ###

N = int(input())

def calc(start, end):
	n = end // start
	return (n * (n+1) // 2) * start

ans = 0
for i in range(1, N+1):
	ans += calc(i, N//i * i)

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

import numpy as np
import bisect
import sys
input = sys.stdin.readline

(A,B,Q) = map(int,input().split())
inf = 10**12
s = np.empty(A+2,dtype=np.int64)
t = np.empty(B+2,dtype=np.int64)
s[0] = -inf
t[0] = -inf
s[A+1] = inf
t[B+1] = inf

for i in range(A):
    s[i+1] = np.int64(input())
for i in range(B):
    t[i+1] = np.int64(input())

for i in range(Q):
    x = np.int64(input())
    p = bisect.bisect_left(s,x)
    q = bisect.bisect_left(t,x)
    ans = min(max(s[p]-x,t[q]-x),
              max(x-s[p-1],x-t[q-1]),
                  (s[p]-x)*2 + (x-t[q-1]),
                  (s[p]-x) + (x-t[q-1])*2,
                  (t[q]-x)*2 + (x-s[p-1]),
                  (t[q]-x) + (x-s[p-1])*2)
    print(ans)

### FIXED CODE ###

import numpy as np
import bisect
import sys
input = sys.stdin.readline

(A,B,Q) = map(int,input().split())
inf = 10**12
s = [0] * (A+2)
t = [0] * (B+2)
s[0] = -inf
t[0] = -inf
s[A+1] = inf
t[B+1] = inf

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

for _ in range(Q):
    x = int(input())
    p = bisect.bisect_left(s,x)
    q = bisect.bisect_left(t,x)
    spx = s[p] - x
    tqx = t[q] - x
    xtq1 = x - t[q-1]
    xsp1 = x - s[p-1]
    ans = min(max(spx, tqx),
              max(xsp1, xtq1),
                  spx*2 + xtq1,
                  spx + xtq1*2,
                  tqx*2 + xsp1,
                  t[q]-x + xsp1*2)
    print(ans)
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = list(map(int, input().split()))
ans = 1
for aa in a:
    ans *= aa

if ans > 10**18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
for aa in a:
    ans *= aa
    if ans == 0:
        print(0)
        exit()
    elif ans > 10**18:
        print(-1)
        exit()

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

N = int(input())
if N == 1:
    print(0)
    exit()

M = 1
for i in range(2, N):
    m = i % (i+1)
    M += m
print(M)

### FIXED CODE ###

N = int(input())
N = N-1
if N % 2 == 0:
    print((N+1) * (N//2))
else:
    n = N-1
    print((n+1) * (n//2) + N)
### BUGGY CODE ###

n, m = map(int, input().split())
ab = []
for i in range(m):
    a, b = map(int, input().split())
    if a == 1 or b == n:
        ab.append([a, b])
contain_one = [j for i, j in ab if i == 1]
string_ab = [str(k)+str(l) for k, l in ab]

for b in contain_one:
    if str(b)+str(n) in set(string_ab):
        print("POSSIBLE")
        exit()
else:
    print("IMPOSSIBLE")


### FIXED CODE ###

n, m = map(int, input().split())
ab = []
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        ab.append(b)
    if b == n:
        ab.append(a)

if len(ab) != len(set(ab)):
        print("POSSIBLE")
        exit()
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

from collections import deque, Counter
import itertools

H, W, M = map(int, input().split())
HW = [list(map(int, input().split())) for _ in range(M)]

F = [[0 for _ in range(W + 1)] for _ in range(H + 1)]

d_h = deque()
d_w = deque()
for h, w in HW:
    d_h.append(h)
    d_w.append(w)
    F[h][w] += 1

# 出現頻度順にソート
c_h = Counter(d_h).most_common()
c_w = Counter(d_w).most_common()

# 登場頻度の一番高い回数
n_h = c_h[0][1]
n_w = c_w[0][1]

# 同率のものを数える
t_h = deque()
t_w = deque()

for k, v in c_h:
    if v == n_h:
        t_h.append(k)
    else:
        break

for k, v in c_w:
    if v == n_w:
        t_w.append(k)
    else:
        break

for h, w in itertools.product(t_h, t_w):
    if F[h][w] == 0:
        ans = n_h + n_w
        break
    else:
        continue
else:
    ans = n_h + n_w - 1

print(ans)


### FIXED CODE ###

import itertools

import numpy as np


def main():
    H, W, M = map(int, input().split())
    HW = [list(map(int, input().split())) for _ in range(M)]

    A = np.zeros(H, dtype=np.int64)
    B = np.zeros(W, dtype=np.int64)

    for h, w in HW:
        A[h - 1] += 1
        B[w - 1] += 1

    maxA = np.max(A)
    maxB = np.max(B)

    # 最大値を取るindex
    ind_A = np.arange(H)[A == maxA]
    ind_B = np.arange(W)[B == maxB]

    # 解の候補の数
    nn = len(ind_A) * len(ind_B)

    # Mより候補の数のほうが多いとok
    # 少ないときはM以下なので可算
    ans = maxA + maxB

    if nn <= M:
        for h, w in HW:
            if A[h - 1] == maxA and B[w - 1] == maxB:
                nn -= 1

    print(ans if nn else ans - 1)


main()
### BUGGY CODE ###

n, m = map(int, input().split())
p = []
y = []
out = []
for _ in range(m):
    pi, yi = map(int, input().split())
    p.append(pi)
    y.append(yi)
    out.append(-1)

for i in range(n):
    index_list = []
    for j in range(len(p)):
        if p[j] == i+1:
            index_list.append([y[j], y.index(y[j])])
    index_list.sort()
    for k in range(len(index_list)):
        out[index_list[k][1]] = str(i+1).zfill(6) + str(k+1).zfill(6)

for i in range(len(out)):
    print(out[i])


### FIXED CODE ###

n, m = map(int, input().split())
d = [list() for i in range(n+1)] 
out = []
for i in range(m):
    pi, yi = map(int, input().split())
    d[pi].append([yi, i])
    out.append(-1)

for i in range(len(d)):
    d[i].sort()

for i in range(1, n+1):
    for j in range(len(d[i])):
        out[d[i][j][1]] = str(i).zfill(6) + str(j+1).zfill(6)

for i in range(len(out)):
    print(out[i])
### BUGGY CODE ###

n, k = map(int, input().split())
s = input()
c = 1
l = []

if s[0] == '0':
    l.append(0)

for i in range(1, n):
    if s[i-1] != s[i]:
        l.append(c)
        c = 1
    else: 
        c +=1
l.append(c)

if s[0] == '0':
    l.append(0)

ll = len(l)
pl = 2 * k + 1

if ll <= pl:
    t = 0
    for i in range(ll):
        t += l[i]
    print(t)
else:
    m = 0
    for i in range(0, ll-pl+1, 2):
        t = 0
        for j in range(pl):
            t += l[i+j]
        m = t if (t > m) else m 
    print(m)


### FIXED CODE ###

n, k = map(int, input().split())
s = input()
c = 1
l = []

if s[0] == '0':
    l.append(0)

for i in range(1, n):
    if s[i-1] != s[i]:
        l.append(c)
        c = 1
    else: 
        c +=1
l.append(c)

if s[n-1] == '0':
    l.append(0)

ll = len(l)
pl = 2 * k + 1

if ll <= pl:
    t = 0
    for i in range(ll):
        t += l[i]
    print(t)
else:
    t = 0
    for i in range(0,pl):
      t += l[i]
    m = t
    for i in range(0, ll-pl, 2):
        t += l[pl+i] + l[pl+i+1]
        t -= l[   i] + l[   i+1]
        m = t if (t > m) else m
    print(m)
### BUGGY CODE ###

r,c,k=map(int,input().split())
goods=[list(map(int,input().split())) for _ in range(k)]
g=[[0]*c for _ in range(r)]
for cr,cc,ck in goods:
    g[cr-1][cc-1]=ck

dp=[[[-1]*4 for _ in range(c+1)] for _ in range(r+1)]
maxlst=[[0]*(c+1) for _ in range(r+1)]

for i in range(r):
    dp[i][0][0]=0
for j in range(c):
    dp[0][j][0]=0

for i in range(r):
    for j in range(c):
        tmp=0
        for k in range(3):
            if g[i][j]>0 and dp[i+1][j][k]>=0:
                dp[i+1][j+1][k+1]=max(dp[i+1][j][k+1],dp[i+1][j][k]+g[i][j])
            else:
                dp[i+1][j+1][k+1]=dp[i+1][j][k+1]
            tmp=max(tmp,dp[i+1][j+1][k+1])
        
        dp[i+1][j+1][0]=max(maxlst[i][j+1],dp[i+1][j][0])
        tmp=max(tmp,dp[i+1][j+1][0])
        
        if g[i][j]>0 and dp[i+1][j+1][0]>=0:
            dp[i+1][j+1][1]=max(dp[i+1][j+1][1],dp[i+1][j+1][0]+g[i][j])
            tmp=max(tmp,dp[i+1][j+1][1])
        
        maxlst[i+1][j+1]=tmp
        
        
            
print(maxlst[r][c])

### FIXED CODE ###

import numpy as np
from numba import njit

rr,cc,kk=map(int,input().split())
goods=np.array([list(map(int,input().split())) for _ in range(kk)])
gg=np.zeros((rr,cc))
for cr,ccc,ck in goods:
    gg[cr-1][ccc-1]=ck

@njit
def calc(r,c,g):
    dp=-1*np.ones((r+1,c+1,4))
    maxlst=np.zeros((r+1,c+1))

    dp[:,0,0]=0
    dp[0,:,0]=0
    
    for i in range(r):
        for j in range(c):
            tmp=0
            for k in range(3):
                if g[i][j]>0 and dp[i+1][j][k]>=0:
                    dp[i+1][j+1][k+1]=max(dp[i+1][j][k+1],dp[i+1][j][k]+g[i][j])
                else:
                    dp[i+1][j+1][k+1]=dp[i+1][j][k+1]
                tmp=max(tmp,dp[i+1][j+1][k+1])
            
            dp[i+1][j+1][0]=max(maxlst[i][j+1],dp[i+1][j][0])
            tmp=max(tmp,dp[i+1][j+1][0])
            
            if g[i][j]>0 and dp[i+1][j+1][0]>=0:
                dp[i+1][j+1][1]=max(dp[i+1][j+1][1],dp[i+1][j+1][0]+g[i][j])
                tmp=max(tmp,dp[i+1][j+1][1])
            
            maxlst[i+1][j+1]=tmp
    
    return maxlst[r][c]
            
print(int(calc(rr,cc,gg)))
### BUGGY CODE ###

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

m = 10**6+10
d = [False] * (m+1)
ans = 0
for i in range(n):
    same = (i > 0 and a[i] == a[i-1]) or (i < (n-1) and a[i] == a[i+1])
    x = a[i]
    if not d[x] and not same: ans += 1
    for j in range(x, m+1, x):
        d[j] = True
    
print(ans)


### FIXED CODE ###

import sys
input = lambda: sys.stdin.buffer.readline()

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

m = 10**6+10
d = [False] * (m+1)
ans = 0
for i in range(n):
    same = (i > 0 and a[i] == a[i-1]) or (i < (n-1) and a[i] == a[i+1])
    x = a[i]
    if not d[x] and not same: ans += 1
    
    if (i > 0 and a[i] == a[i-1]): continue
    for j in range(x, m+1, x):
        d[j] = True
    
print(ans)
### BUGGY CODE ###

import math


def main():
    N = int(input())
    A = list(map(int, input().split()))
    minus_A_plus_i = tuple([- A[i] + (i+1) for i in range(N)])
    A_plus_i = tuple([A[i] + (i+1) for i in range(N)])

    c = 0

    for item in minus_A_plus_i:
        c += A_plus_i.count(item)

    print(c)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
from collections import defaultdict


def main():
    N = int(input())
    A = list(map(int, input().split()))
    minus_A_plus_i = tuple([- A[i] + (i+1) for i in range(N)])
    A_plus_i = tuple([A[i] + (i+1) for i in range(N)])

    cnt = defaultdict(int)
    for e in minus_A_plus_i:
        cnt[e] += 1

    c = 0

    for item in A_plus_i:
        c += cnt[item]

    print(c)


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


def is_triangle(a, b, c):
    if a >= b + c:
        return False

    if b >= a + c:
        return False

    if c >= a + b:
        return False

    return True


def main():
    N = int(input())
    L = list([int(x) for x in input().split()])

    L.sort()

    count = 0
    for index, a in enumerate(L):
        if index + 2 == N:
            break

        for b_i in range(index+1, N):
            b = L[b_i]
            c = 1

            while not is_triangle(a, b, L[-c]):
                c += 1

            count += (N - b_i - c)

    print(count)


if __name__ == '__main__':
    main()


### FIXED CODE ###


def is_triangle(a, b, c):
    if a >= b + c:
        return False

    if b >= a + c:
        return False

    if c >= a + b:
        return False

    return True


def main():
    N = int(input())
    L = list([int(x) for x in input().split()])

    L.sort()

    count = 0
    for index, a in enumerate(L):
        if index + 2 == N:
            break

        for b_i in range(index+1, N):
            b = L[b_i]
            c = 1

            while not is_triangle(a, b, L[-c]):
                c += 1

            count += (N - b_i - c)

    print(count)


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

#import numpy

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

L=[[i+1 for i in range(j+1)][::-1]+[0]*(N-1-j) for j in range(N-1)]
#print(L)

for i in range(len(L)):
    L[i]=[0]+L[i]+[0]
L.append([0]*(N+2))
L.insert(0,[0]*(N+2))
L.insert(0,[0]*(N+2))

#print(L)

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

L[Y][X]=1
task=[(Y,X,1)]
while len(task)>0:
    P=task.pop()
    y,x,c=P[0],P[1],P[2]
    if y<0 or x<0 or y>N or x>N:
        continue
    if L[y+1][x]>=c+1:
        L[y+1][x]=c+1
        task.append((y+1,x,c+1))
    if L[y-1][x]>=c+1:
        L[y-1][x]=c+1
        task.append((y-1,x,c+1))
    if L[y][x+1]>=c+1:
        L[y][x+1]=c+1
        task.append((y,x+1,c+1))
    if L[y][x-1]>=c+1:
        L[y][x-1]=c+1
        task.append((y,x-1,c+1))
    #print(y,x,c)
    #print(numpy.array(L))

ans=[0 for i in range(N)]
for i in range(N+1):
    for j in range(1,N):
        ans[j]+=L[i].count(j)

ans.pop(0)

for i in ans:
    print(i)

### FIXED CODE ###

N,X,Y=map(int,input().split())
ans=[0]*N
X-=1
Y-=1

for i in range(N-1):
    for j in range(i+1,N):
        ans[min(j-i,abs(j-Y)+abs(i-X)+1)]+=1

ans.pop(0)
for i in ans:
    print(i)
### BUGGY CODE ###

s = input()
q = int(input())
flag = True
for i in range(q):
    inp = input()
    if inp == '1':
        flag = not flag

    else:
        _, f, c = map(str, inp.split())
        if f == '1':
            if flag:
                s = c+s
            else:
                s += c
        else:
            if flag:
                s += c
            else:
                s = c+s
if flag:
    print(s)
else:
    print(s[::-1])


### FIXED CODE ###

from collections import deque
s = input()
q = int(input())
flag = True
atama = deque()
osiri = deque()
for i in range(q):
    inp = input()
    if inp == '1':
        flag = not flag

    else:
        _, f, c = map(str, inp.split())
        if f == '1':
            if flag:
                atama.appendleft(c)
            else:
                osiri.append(c)
        else:
            if flag:
                osiri.append(c)
            else:
                atama.appendleft(c)

if flag:
    while(atama):
        tmp = atama.popleft()
        print(tmp, end='')
    print(s, end='')
    while(osiri):
        tmp = osiri.popleft()
        print(tmp, end='')
else:
    while(osiri):
        tmp = osiri.pop()
        print(tmp, end='')
    print(s[::-1], end='')
    while(atama):
        tmp = atama.pop()
        print(tmp, end='')