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

from itertools import combinations

n, k = map(int, input().split())
x = [int(i) for i in input().split()]

c = combinations(x, k)

# print(list(c))

ans = 10 ** 10

for g in c:
    a = max(0, max(g))
    b = min(0, min(g))
    # print(a, b)
    if (a * b) < 0:
        tmp = min(2 * abs(a) + abs(b), 2 * abs(b) + abs(a))
    else:
        tmp = abs(a) + abs(b)
    ans = min(ans, tmp)

print(ans)


### FIXED CODE ###

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

# c = combinations(x, k)
c = []
for i in range(n - k + 1):
    l = x[i]
    r = x[i + k - 1]
    c.append([l, r])


# print(list(c))

ans = 10 ** 10

for l, r in c:
    tmp = min(abs(l) + abs(r - l), abs(r) + abs(r - l))
    ans = min(ans, tmp)

# for g in c:
#     a = max(0, max(g))
#     b = min(0, min(g))
#     # print(a, b)
#     if (a * b) < 0:
#         tmp = min(2 * abs(a) + abs(b), 2 * abs(b) + abs(a))
#     else:
#         tmp = abs(a) + abs(b)
#     ans = min(ans, tmp)

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

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

### FIXED CODE ###

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

from collections import deque
h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())
path = [[10**10]*w for i in range(h)]
maze = []
for _ in range(h):
  s = input()
  maze.append(s)

walk = [(0,1),(1,0),(-1,0),(0,-1)]
warp = [(i,j) for i in range(-2,3) for j in range(-2,3) if (i,j) not in [(0,0)]+walk]
Q = deque()
path[ch-1][cw-1]=0
Q.append((ch-1,cw-1,0))
while Q:
  hi,wi,c = Q.popleft()
  for i,j in walk:
    nh = i + hi
    nw = j + wi
    if 0<=nh<h and 0<=nw<w and maze[nh][nw]=='.' and path[nh][nw]>c:
      path[nh][nw] = c
      Q.append((nh,nw,c))
  for i,j in warp:
    nh = i + hi
    nw = j + wi
    if 0<=nh<h and 0<=nw<w and maze[nh][nw]=='.' and path[nh][nw]>c+1:
      path[nh][nw] = c+1
      Q.append((nh,nw,c+1))
print(path[dh-1][dw-1] if path[dh-1][dw-1]<10**10 else -1)

### FIXED CODE ###

from collections import deque
h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())
path = [[10**10]*w for i in range(h)]
maze = []
for _ in range(h):
  s = input()
  maze.append(s)

walk = [(0,1),(1,0),(-1,0),(0,-1)]
warp = [(i,j) for i in range(-2,3) for j in range(-2,3) if (i,j) not in [(0,0)]+walk]
Q = deque()
path[ch-1][cw-1]=0
Q.append((ch-1,cw-1,0))
while Q:
  hi,wi,c = Q.popleft()
  for i,j in walk:
    nh = i + hi
    nw = j + wi
    if 0<=nh<h and 0<=nw<w and maze[nh][nw]=='.' and path[nh][nw]>c:
      path[nh][nw] = c
      Q.appendleft((nh,nw,c))
  for i,j in warp:
    nh = i + hi
    nw = j + wi
    if 0<=nh<h and 0<=nw<w and maze[nh][nw]=='.' and path[nh][nw]>c+1:
      path[nh][nw] = c+1
      Q.append((nh,nw,c+1))
print(path[dh-1][dw-1] if path[dh-1][dw-1]<10**10 else -1)
### BUGGY CODE ###

def main():
    H, W, D = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    Q = int(input())
    ans = []
    for _ in range(Q):
        L, R = map(int, input().split())
        if L == R:
            ans.append(0)
            continue
        i = 0
        j = 0
        x = [0 for _ in range(90001)]
        y = [0 for _ in range(90001)]
        for i, row in enumerate(A):
            for j, a in enumerate(row):
                x[a] = j
                y[a] = i
        m = 0
        while L != R:
            m += abs(x[L] - x[L + D]) + abs(y[L] - y[L + D])
            L += D
        ans.append(m)
    for a in ans:
        print(a)


main()


### FIXED CODE ###

def main():
    H, W, D = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    Q = int(input())
    ans = []

    x = [0 for _ in range(90001)]
    y = [0 for _ in range(90001)]
    dp = [0 for _ in range(90001)]

    for i, row in enumerate(A):
        for j, a in enumerate(row):
            x[a] = j
            y[a] = i
    for i in range(D + 1, H * W + 1):
        dp[i] = dp[i - D] + abs(x[i] - x[i - D]) + abs(y[i] - y[i - D])

    for _ in range(Q):
        L, R = map(int, input().split())
        ans.append(dp[R] - dp[L])
    for a in ans:
        print(a)


main()
### BUGGY CODE ###

from collections import defaultdict
from collections import deque
import itertools
import copy

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

R,G,B,n = readInts()
ans = 0
for r in range(n//R+2):
	for g in range(n//G+2):
		t = n-(r*R+g*G)
		if t%B==0 and t>=0:
			ans+=1

print(ans)

### FIXED CODE ###

from collections import defaultdict
from collections import deque
import itertools
import copy

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

R,G,B,n = readInts()
ans = 0
for r in range(n//R+2):
	for g in range(n//G+2):
		t = n-(r*R+g*G)
		if t%B==0 and t>=0:
			ans+=1

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

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

 #最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

N=int(input())
A=list(map(int,input().split()))
a_lcm=A[0]

for i in range(1,N):
    a_lcm=lcm(a_lcm,A[i])

result=0
for i in range(N):
    result+=a_lcm//A[i]
    result%=1000000007
print(result%1000000007)

### FIXED CODE ###

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

 #最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

N=int(input())
A=list(map(int,input().split()))
a_lcm=A[0]
Mod=10**9+7

for i in range(1,N):
    a_lcm=lcm(a_lcm,A[i])

a_lcm%=Mod

result=0
for i in range(N):
    result+=a_lcm*pow(A[i],Mod-2,Mod)
print(result%1000000007)
### BUGGY CODE ###


x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(key=lambda x: -x)
b.sort(key=lambda x: -x)
c.sort(key=lambda x: -x)

xyz = []

for ia in range(len(a)):
    if ia > k:
        break
    for ib in range(len(b)):
        if ia*ib > k:
            break
        for ic in range(len(c)):
            if (ia*ib*ic) <= k:
                xyz.append(a[ia]+b[ib]+c[ic])
            else:
                break

xyz.sort(key=lambda x: -x)
for l in xyz[:k]:
    print(l)


### FIXED CODE ###

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

xyz = []

for ia in range(len(a)):
    for ib in range(len(b)):
        for ic in range(len(c)):
            if (ia+1)*(ib+1)*(ic+1) <= k:
                xyz.append(a[ia]+b[ib]+c[ic])
            else:
                break

xyz.sort(reverse=True)
for l in xyz[:k]:
    print(l)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(K):
        b = [0] * (N+1)
        for j in range(N):
            a = A[j]
            b[max(j-a, 0)] += 1
            b[min(j+a+1, N)] -= 1
        for k in range(1,N+1):
            b[k] += b[k-1]
        b = b[:N]
        if b == A:
            break
        else:
            A = b
    print(*A)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(K):
        b = [0] * (N+1)
        for j in range(N):
            a = A[j]
            b[max(j-a, 0)] += 1
            b[min(j+a+1, N)] -= 1
        for k in range(1,N+1):
            b[k] += b[k-1]
        b = b[:N]
        if b == A:
            break
        else:
            A = b
    print(*A)

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

n = int(input())
s = []
for i in range(n):
    ss = ''.join(sorted(input()))
    s.append(ss)

count = 0
for i in range(n-1):
    for j in range(i+1,n):
        if s[i] == s[j]:
            count += 1

print(count)


### FIXED CODE ###

n = int(input())
s = []
for i in range(n):
    ss = ''.join(sorted(input()))
    s.append(ss)

from collections import Counter
d = Counter(s)

count = 0
for s in d.values():
    if s > 1:
        count += s/2*(s-1) 


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

N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

SA = sorted(A)
ans = 0
for i in range(N):
  if (i + SA.index(A[i])) % 2 == 1:
    ans += 1
print(ans//2)

### FIXED CODE ###

import bisect

N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

SA = sorted(A)
ans = 0
for i in range(N):
  rank = bisect.bisect_left(SA,A[i])
  #print(rank,A[i])
  if (i + rank) % 2 == 1:
    ans += 1
print(ans//2)
### BUGGY CODE ###

C,D = [int(e) for e in input().split()]

if C <= D:
    m = D
    n = C
else:
    m = C
    n = D

while  n != 0 :
    a = m%n
    m = n
    n = a

J = []
for i in range(1, int(m**0.5)+1):
    if m % i == 0:
        J.append(i)
        if i != m//i:
            J.append(m//i)


J.sort()

N = int(len(J))
M = [1]
I = []

for i in range(1,N):
    for p in range(1,int(J[i]**0.5)+1):
        if J[i]%p == 0:
            I.extend([J[i]])
    if int(len(I)) == 1:
        M.extend([J[i]])
    I = []


M = int(len(M))

print(M)

### FIXED CODE ###

C,D = [int(e) for e in input().split()]

if C <= D:
    m = D
    n = C
else:
    m = C
    n = D

while  n != 0 :
    a = m%n
    m = n
    n = a

J = []

for i in range(1,int(m**0.5)+1):
    if m % i == 0:
        J.append(i)
        if i != m//i:
            J.append(m//i)


J.sort()

N = int(len(J))
M = [1]
I = []

for i in range(1,N):
    for p in range(1,int(J[i]**0.5)+1):
        if J[i]%p == 0:
            I.extend([J[i]])
            if int(len(I)) >=2:
                break
    if int(len(I)) == 1:
        M.extend([J[i]])
    I = []


M = int(len(M))

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

import itertools

n = int(input())
l = tuple(map(int, input().split()))
total = []
mod = 1000000007
L = itertools.combinations(l, 2)
for a,b in L:
    num = ((a % mod) * (b % mod)) % mod
    total.append(num)
print(sum(total) % mod)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
mod = 1000000007
q = sum(l)
ans = 0
for i in range(len(l)):
    q -= l[i]
    ans += l[i] * q % mod
print(ans % mod)
### BUGGY CODE ###

import sys,collections
input = sys.stdin.readline

N,M,K = list(map(int,input().split()))
fr = [[] for i in range(N+1)]
bl = [[] for i in range(N+1)] 
      
for _ in range(M):
    a,b = map(int,input().split())
    fr[a].append(b)
    fr[b].append(a)
for _ in range(K):
    c,d = map(int,input().split())
    bl[c].append(d)
    bl[d].append(c)

fl = [-1 for i in range(N+1)]
fl[0] = 0
fl[1] = 1
nxt = 1
#dic = {}
while nxt != 0:
    q = collections.deque([nxt])
    
    fl[nxt]=nxt
    #cnt = 0
    while q:
        now = q.popleft()
        for f in fr[now]:
            if fl[f] == -1:
                fl[f] = nxt
                #cnt +=1
                q.append(f)
    #dic[nxt] = cnt
    try:
        nxt = fl.index(-1)
    except:
        nxt = 0
dic = collections.Counter(fl)
mbf = collections.deque()
for i in range(1,N+1):
    ff = 0
    for j in bl[i]:
        if fl[j] == fl[i]:
            ff -= 1
    
    ff += dic[fl[i]]-len(fr[i])-1
    mbf.append(ff)
print(*mbf)


### FIXED CODE ###

import sys,collections
input = sys.stdin.readline

def main():
    N,M,K = list(map(int,input().split()))
    fr = [[] for i in range(N+1)]
    bl = [[] for i in range(N+1)]

          
    for _ in range(M):
        a,b = map(int,input().split())
        fr[a].append(b)
        fr[b].append(a)
    for _ in range(K):
        c,d = map(int,input().split())
        bl[c].append(d)
        bl[d].append(c)

    fl = [-1 for i in range(N+1)]
    fl[0] = 0
    fl[1] = 1
    nxt = 1
    dic = {}
    s = set(range(1,N+1))
    while nxt != 0:
        q = collections.deque([nxt])
        
        fl[nxt]=nxt
        cnt = 0
        while q:
            now = q.popleft()
            s.discard(now)
            for f in fr[now]:
                if fl[f] == -1:
                    fl[f] = nxt
                    cnt +=1
                    q.append(f)
        dic[nxt] = cnt
        #try:
            #nxt = fl.index(-1)
        #except:
            #nxt = 0
        if len(s) == 0:
            nxt = 0
        else:
            nxt = s.pop()


    mbf = collections.deque()
    for i in range(1,N+1):
        ff = 0
        for j in bl[i]:
            if fl[j] == fl[i]:
                ff -= 1
        
        ff += dic[fl[i]]-len(fr[i])
        mbf.append(ff)
    print(*mbf)

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

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

l_list = []
r_list = []

ans = []
for x in range(Q):
    l, r = map(int, input().split())
    sub_str = S[l-1:r]
    ac_count = 0
    
    for i in range(len(sub_str) - 1):
        if sub_str[i:i+2] == 'AC':
            ac_count += 1
    
    ans.append(ac_count)
    
for a in ans:
    print(a)
    
    




### FIXED CODE ###

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

l_list = []
r_list = []

s_count = [0]
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        s_count.append(1)
    else:
        s_count.append(0)
#print(s_count)

n_count = []
n_sum = 0
for n in s_count:
    n_sum = n_sum + n
    n_count.append(n_sum)

#print(n_count)


for x in range(Q):
    l, r = map(int, input().split())
    ans = n_count[r-1] - n_count[l-1]
    print(ans)
### BUGGY CODE ###

import fractions
from functools import reduce

def gcd_list(nums):
    if len(nums) == 0:
        return 0
    return reduce(fractions.gcd, nums)

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

ans = 0
for i in range(n):
    l, r = gcd_list(A[: i]), gcd_list(A[i + 1: ])
    ans = max(ans, fractions.gcd(l, r))

print(ans)

### FIXED CODE ###

from fractions import gcd

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

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

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

# input
a, b, x = map(int, input().split())

ans = 0

for i in range(a, b + 1):
    if i % x == 0:
        ans += 1

print(ans)


### FIXED CODE ###

# input
import math

a, b, x = map(int, input().split())

# 0,...,nの中でxで割り切れるのは
# 0, x, 2x,..., (n // x)* x の(n //x) + 1個

if a % x == 0:
    ans = ((b // x) + 1) - ((a // x) + 1) + 1
    print(ans)
else:
    ans = ((b // x) + 1) - ((a // x) + 1)
    print(ans)
### BUGGY CODE ###

k,s = map(int,input().split())
n = 0
m = k+1
for x in range(m):
    for y in range(m):
        z = s-(x+y)
        if z <= k and z >= 0 and x+y+z==s:
            n += 1
print(n)
                

### FIXED CODE ###

k,s = map(int,input().split())
n = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-(x+y)
        if z <= k and z >= 0 and x+y+z==s:
            n += 1
print(n)
### BUGGY CODE ###

def pad(S,N):
    return (N-len(S)) * "0" + S

def xor_sum(A,M):
    N = len(A)
    bit_count = [0 for _ in range(60)]
    #bit_count[i]:iビット目が1であるa in Aの個数

    for i in range(N):
        A[i] = pad(bin(A[i])[2:],60)
        for j in range(60):
            if A[i][60-j-1] == "1":
                bit_count[j] += 1

    output = 0
    for j in range(60):
        tmp1 = (N-bit_count[j])*bit_count[j] % M
        tmp2 = pow(2,j,M)
        tmp = (tmp1 * tmp2) % M
        output += tmp
        output %= M

    return output

def main():
    N = int(input())
    A = list(map(int,input().split()))
    M = 10**9+7

    print(xor_sum(A,M))

if __name__ == "__main__":
    main()


### FIXED CODE ###

def pad(S,N):
    return (N-len(S)) * "0" + S

def xor_sum(A,M):
    N = len(A)
    bit_count = [0 for _ in range(60)]
    #bit_count[i]:iビット目が1であるa in Aの個数

    for i in range(N):
        A[i] = pad(bin(A[i])[2:],60)
        for j in range(60):
            if A[i][60-j-1] == "1":
                bit_count[j] += 1

    output = 0
    for j in range(60):
        tmp1 = (N-bit_count[j])*bit_count[j] % M
        tmp2 = pow(2,j,M)
        tmp = (tmp1 * tmp2) % M
        output += tmp
        output %= M

    return output

def main():
    N = int(input())
    A = list(map(int,input().split()))
    M = 10**9+7

    print(xor_sum(A,M))

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

N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

S = []
pt = []
G = [-1] * (N+1)
idx = 0
cnt = 0
for pair in B:
    d = []
    for i, x in enumerate(pair):
        if G[x] >= 0:
            d.append(G[x])

    if len(d) <= 0:
        pt.append(1)
        for x in pair:
            G[x] = idx
        idx += 1
    elif len(d) == 1:
        pt.append(G.count(d[0]))
        for x in pair:
            G[x] = d[0]
    else:
        if d[0] == d[1]:
            pt.append(0)
        else:
            pt.append(G.count(d[0]) * G.count(d[1]))
            for i, x in enumerate(G):
                if x == d[1]:
                    G[i] = d[0]

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


### FIXED CODE ###

N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)
### BUGGY CODE ###

x = int(input())

if x == 1:
    a = 1
    b = 0
else:
    p = 2
    while True:
        while True:
            if x % p == 0:
                q = int(x / p)
                break
            else:
                p += 1
        ap = p
        am = p
        bp = 0
        bm = 0
        for i in range(100):
            if ap**4 + ap**3 * bp + ap**2 * bp**2 + ap * bp**3 + bp**4 == q:
                a = ap
                b = bp
                break
            elif am**4 + am**3 * bm + am**2 * bm**2 + am * bm**3 + bm**4 == q:
                a = am
                b = bm
                break
            ap += 1
            bp += 1
            am -= 1
            bm -= 1
        else:
            p += 1
            continue
        break

print('{} {}'.format(a, b))

### FIXED CODE ###

x = int(input())

if x == 1:
    a = 1
    b = 0
else:
    p = 1
    while True:
        while True:
            if x % p == 0:
                q = int(x / p)
                break
            else:
                p += 1
        ap = p
        am = p
        bp = 0
        bm = 0
        for i in range(200):
            if ap**4 + ap**3 * bp + ap**2 * bp**2 + ap * bp**3 + bp**4 == q:
                a = ap
                b = bp
                break
            elif am**4 + am**3 * bm + am**2 * bm**2 + am * bm**3 + bm**4 == q:
                a = am
                b = bm
                break
            ap += 1
            bp += 1
            am -= 1
            bm -= 1
        else:
            p += 1
            continue
        break

print('{} {}'.format(a, b))
### BUGGY CODE ###

N,M = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse=True)
for m in range(M):
  if len(a)>1:
    max_=max(a[:2])
    a.remove(max_)
    flag=1
    for n in range(N-1):
      if max_//2<a[n]:
        pass
      else:
        a.insert(n,max_//2)
        flag=0
        break
    if flag:
      a.append(max_//2)
  else:
    a[0]=a[0]//2
print(sum(a))

### FIXED CODE ###

from heapq import heapify,heappush,heappop

N,M = map(int,input().split())
a = list(map(int,input().split()))
a = [(-x, x) for x in a]

heapify(a)

for m in range(M):
  max_ = heappop(a)
  a_ = max_[1]//2
  heappush(a,(-a_,a_))

ans=0
for a_ in a:
  ans+=a_[1]
print(ans)
### BUGGY CODE ###

def op2(f, c, r, s):
  if r == 0:
    if f == "1":
      return (c + s)
    elif f == "2":
      return (s + c)

  if r == 1:
    if f == "2":
      return (c + s)
    elif f == "1":
      return (s + c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    S = op2(val[1], val[2], rev, S)
    
if rev == 0:
  print(S)
else:
  print(S[::-1])

### FIXED CODE ###

def op2(f, c, r):
  if r == 0:
    if f == "1":
      left.append(c)
    elif f == "2":
      right.append(c)

  if r == 1:
    if f == "1":
      right.append(c)
    elif f == "2":
      left.append(c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0
left = []
right = []

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    op2(val[1], val[2], rev)

nleft = left[::-1]
ans = "".join(nleft + [S] + right)

if rev == 0:
  print(ans)
else:
  print(ans[::-1])
### BUGGY CODE ###

s = [i for i in input()]
idx = 0
ans = len(s)
while idx < len(s) - 1:
    if s[idx] == "S" and s[idx+1] == "T":
        ans -= 2
        s.pop(idx)
        s.pop(idx)
        idx -= 1
    else:
        idx += 1
print(ans)

### FIXED CODE ###

s = input()
s_cnt = puyo = 0
for si in s:
    if si == "S": s_cnt += 1
    elif s_cnt > 0:
        s_cnt -= 1
        puyo += 1
print(len(s) - puyo * 2)
### BUGGY CODE ###

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

from itertools import product

S = [set() for _ in range(10)]
N = [0]*10
N[0] = (H-2)*(W-2)
# S[i]: set(黒いマスをi個こ含む3*3マスの中心セル)

for a,b in AB:
  for x,y in product([-1,0,1], repeat=2):
    X = a+x-1
    Y = b+y-1
    if X<=0 or H-1<=X or Y<=0 or W-1<=Y:
      continue
    for i in range(10):
      if (X, Y) in S[i]:
        S[i].remove((X, Y))
        S[i+1].add((X, Y))
        N[i] -=1
        N[i+1] +=1
        break
    else:
      S[1].add((X, Y))
      N[1] +=1
      N[0] -=1

for n in N:
  print(n)

### FIXED CODE ###

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

from itertools import product

S = [set() for _ in range(10)]
# S[i]: set(黒いマスをi個こ含む3*3マスの中心セル)

for a,b in AB:
  for x,y in product([-1,0,1], repeat=2):
    X = a+x-1
    Y = b+y-1
    if X<=0 or H-1<=X or Y<=0 or W-1<=Y:
      continue
    for i in range(10):
      if (X, Y) in S[i]:
        S[i].remove((X, Y))
        S[i+1].add((X, Y))
        break
    else:
      S[1].add((X, Y))

L = [len(s) for s in S[1:]]
print((H-2)*(W-2) - sum(L))

for l in L:
  print(l)
### BUGGY CODE ###

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

ans = 0
for i in range(n):
    if A[i] <= 2*10**5-i:
        a = A[i]
        ato = i+a
        saigo = n
        if i+m < n:
            saigo = i+m
        if i+a > n:
            ato = n
        for j in range(ato,n):
            if j-i == A[i]+A[j]:
                ans += 1

print(ans)


### 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 j in range(N):
    R = j - A[j]
    if R in X:
        ans += X[R]

print(ans)