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

s=str(input())
q=int(input())
for i in range(q):
    que=list(input())
    if len(que)==1:
        s=s[::-1]
    else:
        if int(que[2])==1:
            s=que[4]+s
        elif int(que[2])==2:
            s=s+que[4]
print(s) 

### FIXED CODE ###

from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s))
### BUGGY CODE ###

N, W = map(int, input().split())
INF = 10**10
dp = [[-INF]*(W+1) for i in range(N+1)]
dp[0][0] = 0

for i in range(N):
    w,v = map(int, input().split())
    dp[i+1][:] = dp[i][:]
    for j in range(W):
        if dp[i][j] == -INF:continue 
        if j + w > W: continue
        dp[i+1][j+w] = max(dp[i][j+w], dp[i][j] + v)

print(max(dp[N]))

### FIXED CODE ###


import numpy as np
N,W = map(int, input().split())
# np.maximum https://www.sejuku.net/blog/69175
# 第一引数と第二引数の大小関係を要素ごとに比較して、大きい方を格納した配列を返します。
dp = np.zeros(W+1, dtype=np.int64)
for _ in range(N):
    w,v = map(int,input().split())
    # w以下ならvを足したもの、w以上ならそのままの値で、最大値を求める
    # 出力はw以上の配列として返す(それ以下は重さwなので関与しない)
    # 足す場合が前者、足さない場合が後者。その重さでの最大valueが保存されている
    np.maximum(dp[:W-w+1]+v,dp[w:],out=dp[w:]) 

print(dp[-1])
### BUGGY CODE ###

import sys
from operator import itemgetter
from itertools import permutations
from math import sqrt

def solve(a: list, axis: int = 0):
    length = len(a)
    if length <= 3:
        return min(sqrt((p1[axis]-p2[axis])**2+(p1[not axis]-p2[not axis])**2) for p1, p2 in permutations(a, 2))

    med = length//2
    left, right = a[:med], a[med:]
    delta = min(solve(left, axis), solve(right, axis))
    median_x = a[med][axis]
    m_a = []
        
    for p in left[::-1]:
        if p[axis] < median_x-delta:
            break
        m_a.append(p)
    for p in right:
        if p[axis] > median_x+delta:
            break
        m_a.append(p)
    m_a.sort(key=itemgetter(not axis))

    for i, p1 in enumerate(m_a):
        ub = p1[not axis] + delta
        for j, p2 in enumerate(m_a[i+1:]):
            if p2[not axis] > ub:
                break
            delta = min(delta, sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2))

    return delta

if __name__ == "__main__":
    N = int(input())
    a = sorted([tuple(map(float, l.split())) for l in sys.stdin.readlines()])
    axis = 0 if len(set(p[0] for p in a)) > len(set(p[1] for p in a)) else 1
    print("{:.10f}".format(solve(a, axis)))


### FIXED CODE ###

import sys
from operator import itemgetter
from itertools import combinations, takewhile
from math import sqrt

def solve(a: list, sorted_axis: int = -1):
    length = len(a)
    if length <= 3:
        return sqrt(min((x1-x2)**2+(y1-y2)**2 for (x1, y1), (x2, y2) in combinations(a, 2)))

    x_set_len = len(set(x for x, _ in a))
    axis1 = 0 if x_set_len > length/2 else 1

    if sorted_axis != axis1:
        a.sort(key=itemgetter(axis1))

    mid_index = length//2
    left, right = a[:mid_index], a[mid_index:]
    delta = min(solve(left, axis1), solve(right, axis1))

    axis2 = not axis1
    median = a[mid_index][axis1]
    mid_a = sorted([p for _iter in (
        (takewhile(lambda p: median-delta < p[axis1], left[::-1])),
        (takewhile(lambda p: p[axis1] < median+delta, right))
    ) for p in _iter], key=itemgetter(axis2))

    for i, (x1, y1) in enumerate(mid_a):
        ub = (x1 if axis1 else y1) + delta
        for x2, y2 in takewhile(lambda p: p[axis2] < ub, mid_a[i+1:]):
            delta = min(delta, sqrt((x1-x2)**2+(y1-y2)**2))

    return delta

if __name__ == "__main__":
    N = int(input())
    a = [tuple(map(float, l.split())) for l in sys.stdin.readlines()]
    print("{:.10f}".format(solve(a)))
### BUGGY CODE ###

import heapq
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
q = []
for i, b in enumerate(B):
    q.append([-b, i])
heapq.heapify(q)
ans = 0
while len(q)>0:
    b, idx = q[0]
    b = -b
    b_p1, b_m1 = B[(idx+1)%N], B[idx-1]
    d = b_p1 + b_m1

    p = min((b-A[idx])//d, (b-b_m1)//d+1, (b-b_p1)//d+1)

    b -= p * d
    B[idx] = b
    ans += p
    if b > A[idx]:
        heapq.heapreplace(q, [-b, idx])
        if q[0][1] == idx:
            print(-1)
            exit()
    else:
        heapq.heappop(q)
print(ans)


### FIXED CODE ###

import heapq
import sys
input = sys.stdin.readline

# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
q = []
q = [(-b, i) for i, b in enumerate(B)]
heapq.heapify(q)
ans = 0
N_m1 = N-1
while len(q)>0:
    b, idx = q[0]
    b = -b
    b_p1, b_m1 = B[idx+1 if idx<N_m1 else 0], B[idx-1]
    d = b_p1 + b_m1

    a = A[idx]
    p = min((b-a)//d, (b-b_m1)//d+1, (b-b_p1)//d+1)

    b -= p * d
    B[idx] = b
    ans += p
    if b > a:
        heapq.heapreplace(q, (-b, idx))
        if q[0][1] == idx:
            print(-1)
            exit()
    else:
        heapq.heappop(q)
print(ans)
### BUGGY CODE ###

def dfs(s, t, links):
    visited = set()
    q = [(s, 0)]
    while q:
        v, used = q.pop()
        if v == t:
            return used
        visited.add(v)
        for lb, u in links[v]:
            if u in visited:
                continue
            q.append((u, used | lb))


def bitcount64(n):
    n = ((n >> 1) & 0x5555555555555555) + (n & 0x5555555555555555)
    n = ((n >> 2) & 0x3333333333333333) + (n & 0x3333333333333333)
    n = ((n >> 4) & 0x0f0f0f0f0f0f0f0f) + (n & 0x0f0f0f0f0f0f0f0f)
    n = ((n >> 8) & 0x00ff00ff00ff00ff) + (n & 0x00ff00ff00ff00ff)
    n = ((n >> 16) & 0x0000ffff0000ffff) + (n & 0x0000ffff0000ffff)
    n = ((n >> 32) & 0x00000000ffffffff) + (n & 0x00000000ffffffff)
    return n


n = int(input())
links = [set() for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    lb = 1 << i
    links[a].add((lb, b))
    links[b].add((lb, a))
conditions = []
m = int(input())
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    conditions.append(dfs(u, v, links))

ans = 0
for i in range(1 << m):
    cnd_cnt = bitcount64(i)
    bit = 0
    k = i
    while k:
        b = k & -k
        j = b.bit_length() - 1
        bit |= conditions[j]
        k ^= b
    free_link_cnt = n - 1 - bitcount64(bit)
    val = 2 ** free_link_cnt
    if cnd_cnt % 2:
        ans -= val
    else:
        ans += val
print(ans)


### FIXED CODE ###

def dfs(s, t, links):
    visited = set()
    q = [(s, 0)]
    while q:
        v, used = q.pop()
        if v == t:
            return used
        visited.add(v)
        for lb, u in links[v]:
            if u in visited:
                continue
            q.append((u, used | lb))


n = int(input())
links = [set() for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    lb = 1 << i
    links[a].add((lb, b))
    links[b].add((lb, a))
conditions = []
m = int(input())
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    conditions.append(dfs(u, v, links))

ans = 0
for i in range(1 << m):
    cnd_cnt = bin(i).count('1')
    bit = 0
    k = i
    while k:
        b = k & -k
        j = b.bit_length() - 1
        bit |= conditions[j]
        k ^= b
    free_link_cnt = n - 1 - bin(bit).count('1')
    val = 2 ** free_link_cnt
    if cnd_cnt % 2:
        ans -= val
    else:
        ans += val
print(ans)
### BUGGY CODE ###

import numpy as np


def get_answer(n, a):
    n = int(n)
    a = [int(v) for v in a.split(" ")]
    indexes_all = create_index(n)
    v_max = -1
    for indexes in indexes_all:
        v = a[indexes[0]]
        for i in range(1, len(indexes)):
            v = (v + a[indexes[i]]) / 2
        if v > v_max:
            v_max = v
    return v_max


def create_index(n):
    ret_all = []
    index_queue = np.arange(0, n)
    ret = []
    search_index(index_queue, ret_all, ret, n)
    return ret_all


def search_index(index_q, ret_all, ret, n):
    if n <= 0:
        ret_all.append(list(ret))
        return
    for i in range(n):
        index = index_q[i]
        index_q = np.delete(index_q, i)
        ret.append(index)
        search_index(index_q, ret_all, ret, n - 1)
        index_q = np.insert(index_q, i, index)
        ret.pop()


if __name__ == "__main__":
    input1 = input()
    input2 = input()
    print(get_answer(input1, input2))


### FIXED CODE ###

def sort_index(a):
    for i in range(len(a)):
        for j in range(i + 1, len(a)):
            if a[i] > a[j]:
                a[i], a[j] = a[j], a[i]
    return a


def get_answer(n, a):
    n = int(n)
    a = [int(v) for v in a.split(" ")]
    a = sort_index(a)
    v_max = 0
    v = a[0]
    for i in range(1, len(a)):
        v = (v + a[i]) / 2
    if v > v_max:
        v_max = v
    return v_max



if __name__ == "__main__":
    input1 = input()
    input2 = input()
    print(get_answer(input1, input2))
### BUGGY CODE ###

import copy
import bisect
from collections import deque

def dfs(i, k, v, x):
    if i >= k:
        return sum(x)
    y = [0, 0, 0, 0]
    if len(v) > 0:
        p = v.popleft()
        xi = copy.copy(x)
        bisect.insort(xi, p)
        y[0] = dfs(i + 1, k, v, xi)
        v.appendleft(p)
    if len(v) > 1:
        p = v.pop()
        xi = copy.copy(x)
        bisect.insort(xi, p)
        y[1] = dfs(i + 1, k, v, xi)
        v.append(p)
    if len(x) > 0:
        p = x[0]
        xi = copy.copy(x)
        del xi[0]
        v.appendleft(p)
        y[2] = dfs(i + 1, k, v, xi)
        _ = v.popleft()
        v.append(p)
        y[3] = dfs(i + 1, k, v, xi)
        _ = v.pop()
    return max(y)

n, k = map(int, input().split())
v = deque(list(map(int, input().split())))
x = []
ans = dfs(0, k, v, [])
print(ans)


### FIXED CODE ###

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

ans = 0
if n == 1:
    ans = max(0, v[0])
else:
    ans = 0 if k < n else sum(v)
    for i in range(min(k + 1, n)):
        for j in range(i + 1):
            t = v[:j]
            if j != i:
                t += v[j - i:]
            t.sort()
            for p in range(k - i):
                if len(t) > 0 and t[0] < 0:
                    t.pop(0)
                else:
                    break
            if len(t) == 0:
                t = [0]
            ans = max(ans, sum(t))
print(ans)
### BUGGY CODE ###

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		while self.table[x] >= 0:
			x = self.table[x]
		return x

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
		return


n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]
x = [xy[i][0] for i in range(m)]
y = [xy[i][1] for i in range(m)]

uf = UnionFind(n)

for i in range(m):
	uf.union(x[i] - 1, y[i] - 1)

ans = 0
for i, pp in enumerate(p):
	if uf.find(pp - 1) == uf.find(i):
		ans += 1

print(ans)

### FIXED CODE ###

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x]) #xをxの根に直接つなぐ
			return self.table[x]

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 == s2:
			return
		else:
			st1 = self.table[s1]
			st2 = self.table[s2]
			if st1 > st2:
				self.table[s2] = s1
			elif st1 < st2:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1


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

uf = UnionFind(n)

for i in range(m):
	x, y = map(int, input().split())
	uf.union(x - 1, y - 1)

ans = 0
for i, pp in enumerate(p):
	if pp - 1 == i:
		ans += 1
	elif uf.find(pp - 1) == uf.find(i):
		ans += 1

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

n = int(input())
a = list(map(int, input().split()))
res = 1
for i in a:
    res *= i
if res > 1000000000000000000:
        res = -1
print(res)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
res = 1
a.sort()
for i in a:
    res *= i
    if res > 1000000000000000000:
        res = -1
        break
print(res)
### BUGGY CODE ###

ab=[]
n,m = map(int,input().split())


for i in range(m):
    ab.append(tuple(map(int,input().split())))

abr=[]
enabled=set()
remain=set()
for i in range(m):
    abr.append(range(ab[i][0],ab[i][1]))
    remain.add(i)

res=0
for i in range(1,n+1):
    for j in remain-enabled:
        if i == abr[j][0]:
            enabled.add(j)
    for j in enabled:
        if i == abr[j][-1] and j in remain:
            res+=1
            remain-=enabled
            enabled=set()
            break

print(res)

### FIXED CODE ###

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

ab.sort(key=lambda x:x[1])

res=0
for z in range(len(ab)):
    x=ab[0][1]
    for j in range(len(ab)):
        if x > ab[0][0]:
            del ab[0]
        else:
            res+=1
            break
    if len(ab)==0:
        res+=1
        break
    
print(res)
### BUGGY CODE ###

import itertools
import collections

N = int(input())
S = input()

c = collections.Counter(itertools.combinations(S, 3))
#print(len(set(itertools.combinations(S, 3))))
print(len(c))

### FIXED CODE ###

N = int(input())
S = input()

count = 0
for h in range(10):
  pos_h = S.find(str(h))
  if pos_h < 0:
    continue
  for i in range(10):
    pos_i = S.find(str(i), pos_h+1)
    if pos_i < 0:
      continue
    for j in range(10):
      pos_j = S.find(str(j), pos_i+1)
      if pos_j < 0:
        continue
      count += 1

print(count)
### BUGGY CODE ###

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

for i in range(n):
    b.append(a[i])
    b.reverse()

for i in range(n):
    if i < n-1:
        print(b[i],end=" ")
    else:
        print(b[i])


### FIXED CODE ###

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

b = a[n::-2]+a[::2] if n%2 == 0 else a[n::-2]+a[1::2]
for i in range(n):
    if i < n-1:
        print(b[i],end=" ")
    else:
        print(b[i])
### BUGGY CODE ###

N = int(input())
X = list(map(int, input().split()))
X_sort = sorted(X)
for i in range(N):
    x = X[i]
    index = X_sort.index(x)
    if index<= int(N//2-1):
        print(X_sort[N//2])
    else:
        print(X_sort[N//2-1])

### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
X_sort = sorted(X)
m_1 = X_sort[N//2]
m_2 = X_sort[N//2-1]
for i in range(N):
    x = X[i]
    if x<= m_2:
        print(m_1)
    else:
        print(m_2)
### BUGGY CODE ###

import itertools as iter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    nums = [A.count(i) for i in range(N+1)]
    comb = sum((i*(i-1)//2 for i in nums))
    for k in range(N):
        print(comb-(nums[A[k]]-1))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    nums = [0] * (N+1)
    for i in A:
        nums[i] += 1
    #nums = [A.count(i) for i in range(N+1)]
    comb = sum((i*(i-1)//2 for i in nums))
    for k in range(N):
        print(comb-(nums[A[k]]-1))

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

N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    tmp = []
    for j in range(K):
        if (i - j - 1) < 0:
            break
        tmp.append(dp[i-j-1] + abs(H[i]-H[i-j-1]))
    dp[i] = min(tmp)
    # print("tmp", tmp)
    # print("dp ", dp)
print(dp[-1])

### FIXED CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    tmp = []
    for j in range(K):
        if (i - j - 1) < 0:
            break
        tmp.append(dp[i-j-1] + abs(H[i]-H[i-j-1]))
    dp[i] = min(tmp)
    # print("tmp", tmp)
    # print("dp ", dp)
print(dp[-1])
### BUGGY CODE ###

n,p = list(map(int,input().split()))
S = input()

if p == 2 or p == 5:
  ans = 0
  for i,s in enumerate(S):
    if int(s)%p == 0:
      ans += i+1
  print(ans)
  exit()

def MS(i,s,pre):
  return (s*(10**i) +pre)%p
 
M = [0]*p
pre = 0
ans = 0
i = 0
for s in S[::-1]:
  M[MS(i,int(s),pre)] += 1
  pre = MS(i,int(s),pre)
  i += 1

M[0] += 1
ans = sum(map(lambda m:(m*(m-1))//2, M))
print(ans)

### FIXED CODE ###

n,p = list(map(int,input().split()))
S = input()

if p == 2 or p == 5:
  ans = 0
  for i,s in enumerate(S):
    if int(s)%p == 0:
      ans += i+1
  print(ans)
  exit()

def MS(i,s,pre):
  return (s*i +pre)%p
 
M = [0]*p
M[0] = 1
t = 1
now = 0
for i in S[::-1]:
    i = int(i)
    now += i*t
    now %= p
    M[now] += 1
    t = t*10%p

ans = sum(map(lambda m:(m*(m-1))//2, M))
print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
l = [list(map(int, input().split())) for _ in range(Q)]

ans = []
for i in range(Q):
    R = S[l[i][0]-1 : l[i][1]]
    print(R.count("AC"))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

t = [0] * (N + 1)

for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
### BUGGY CODE ###

from collections import defaultdict

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

dic = defaultdict(int)
def calc_patern(n, dic):
    ret = 0
    for k, v in dic.items():
        if int(k) != n:
            ret += v * (v - 1) / 2
        else:
            ret += (v - 1) * (v - 2) / 2
    return ret
for i in range(n):
    dic[a[i]] += 1

for i in range(n):
    print(int(calc_patern(a[i], dic)))


### FIXED CODE ###

from collections import defaultdict, Counter

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

sum = 0
for v in dic.values():
    sum += v * (v - 1) / 2
    
for i in range(n):
    print(int(sum - (dic[a[i]] - 1)))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
ans = 0
b = [(sum(a[:n-i-1])* a[n-i-1])%MOD for i in range(n-1)]
print(sum(b)%MOD)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
ans = 0
plus = 0
for i in range(n-1):
    plus += a[n-i-1]
    plus %= MOD
    ans += a[n-i-2]*plus
    ans %= MOD
print(ans%MOD)
### BUGGY CODE ###

from fractions import Fraction
import math

n = int(input())


ab = []
ba = []

a0 = 0
b0 = 0
ab0 = 0

for i in range(n):
    a, b = map(int, input().split())
    if a != 0 and b != 0:
        ab.append(Fraction(a, b))
        ba.append(Fraction(-b, a))
    elif a == 0 and b == 0:
        ab0 += 1
    elif a == 0 and b != 0:
        a0 += 1
    elif a != 0 and b == 0:
        b0 += 1


d_ab = dict()
d_ba = dict()

d_done = dict()

for i in range(len(ab)):
    cur = ab[i]
    if cur in d_ab:
        d_ab[cur] += 1
    else:
        d_ab[cur] = 1

    cur = ba[i]
    if cur in d_ba:
        d_ba[cur] += 1
    else:
        d_ba[cur] = 1

mod = 1000000007
ans = 1

for k, v in d_ab.items():
    x = v
    if k in d_ba:
        if k in d_done:
            continue
        else:
            y = d_ba[k]
            kake = 0
            kake += ((2**x) % mod + (2**y) % mod - 1)
            ans *= kake
            ans %= mod
            d_done[Fraction(-k.denominator, k.numerator)] = 1
    else:
        kake = (2**x) % mod
        ans *= kake
        ans %= mod

ans *= ((2**a0) % mod+(2**b0) % mod-1)
ans %= mod

ans -= 1

ans += ab0
ans %= mod

print(ans)


### FIXED CODE ###

from fractions import Fraction
import math

n = int(input())


ab = []
ba = []

a0 = 0
b0 = 0
ab0 = 0


def irr(a, b):
    gcd = math.gcd(a, b)
    a = a // gcd
    b = b // gcd

    if b < 0:
        return (-a, -b)
    else:
        return (a, b)


for i in range(n):
    a, b = map(int, input().split())
    if a != 0 and b != 0:
        ab.append(irr(a, b))
        ba.append(irr(-b, a))
    elif a == 0 and b == 0:
        ab0 += 1
    elif a == 0 and b != 0:
        a0 += 1
    elif a != 0 and b == 0:
        b0 += 1


d_ab = dict()
d_ba = dict()

# d_done = dict()

for i in range(len(ab)):
    cur = ab[i]
    if cur in d_ab:
        d_ab[cur] += 1
    else:
        d_ab[cur] = 1

    cur = ba[i]
    if cur in d_ba:
        d_ba[cur] += 1
    else:
        d_ba[cur] = 1

mod = 1000000007
ans = 1

d_done = set()

for k, v in d_ab.items():
    x = v
    if k in d_ba:
        if k in d_done:
            continue
        else:
            y = d_ba[k]
            kake = 0
            kake += ((2**x) % mod + (2**y) % mod - 1)
            ans *= kake
            ans %= mod
            # d_done[Fraction(-k.denominator, k.numerator)] = 1
            d_done.add(irr(-k[1], k[0]))
    else:
        kake = (2**x) % mod
        ans *= kake
        ans %= mod

ans *= ((2**a0) % mod+(2**b0) % mod-1)
ans %= mod

ans -= 1

ans += ab0
ans %= mod

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

def main():
  n = int(input())
  N = [i for i in range(n)]
  A = list(map(int,input().split()))
  ans = 0
  for i in range(n):
    for j in range(i+1,n):
      if N[j]-N[i] == A[i] + A[j]:
        ans += 1
  print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

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

X = dict()
ans = 0
for i in range(N):
    L = i + A[i]
    if L not in X:
        X[L] = 1
    else:
        X[L] += 1

for i in range(N):
    R = i - A[i]
    if R in X:
        ans += X[R]
        
print(ans)