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

N = int(input())
record = [0] * 1000000

for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            sum = i**2 + j**2 + k**2 + i*j + i*k +j*k
            if sum >= N: break
            # print("i,j,k:", i,j,k)
            # print(sum)
            # if i==j==k: record[sum] += 1
            # else: record[sum] += 3
            record[sum] += 1

for num in record[1:N+1]:
    print(num)


### FIXED CODE ###


n = int(input())

ans = [0 for _ in range(n+1)]
x = 1
y = 1
z = 1

while True:
    f = x * x + y * y + z * z + x * y + y * z + z * x
    if f > n:
        if z > 1:
            y += 1
            z = 1
        elif y > 1:
            x += 1
            y = 1
        else:
            break
    else:
        ans[f] += 1
        z += 1

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

N, K = map(int, input().split())
L = [0] * K
R = [0] * K
S = set()
for k in range(K):
    L[k],R[k] = map(int,input().split())
for k in range(K):
    for n in range(L[k], R[k] + 1):
        S.add(n)
dp = [0] * (N+1)
dp[1] = 1
S = sorted(S)
for i in range(1,N+1):
    for s in S:
        if i-s <= 0:
            break
        dp[i] += dp[i-s]
        if dp[i] >= 998244353:
            dp[i] -= 998244353
while dp[N] >= 998244353:
    dp[N] -= 998244353
print(dp[N])

### FIXED CODE ###

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

dp = [0] * (N + 1)
dp_sums = [0] * (N + 1)
dp[1] = dp_sums[1] = 1

for i in range(2,N+1):
    for l, r in S: 
        if i >= r + 1:
            dp[i] += dp_sums[i - l] - dp_sums[i - r - 1] 
            dp_sums[i] = dp_sums[i-1] + dp[i]
        elif i > l and i < r + 1:
            dp[i] += dp_sums[i - l] 
            dp_sums[i] = dp_sums[i-1] + dp[i]
        elif i <= l:
            dp_sums[i] = dp_sums[i-1] + dp[i]
    dp[i] %= 998244353
    dp_sums[i] %= 998244353
print(dp[N])
### BUGGY CODE ###

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

P_ = []

for i in p:
    P_.append((1+i)/2)

ma = 0

for i in range(N-K+1):
    if ma < sum(P_[i:i+K]):
        ma = sum(P_[i:i+K])

print(ma)


### FIXED CODE ###

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

ma = sum(p[:K])
tmp = ma

for i in range(K,N):
    tmp += p[i]
    tmp -= p[i-K]
    if ma < tmp:
        ma = tmp

print((ma + K)/2)
### BUGGY CODE ###

import sys

line = sys.stdin.readline().strip()
n,m,k = map(int, line.split())
roots = list(range(n))
linked = [0]*n
for i in range(m):
    line = sys.stdin.readline().strip()
    a,b = map(int, line.split())
    c, d = a-1,b-1
    linked[c] += 1 
    linked[d] += 1
    while c != roots[c]:
        c = roots[c]
    while d != roots[d]:
        d = roots[d]
    if c!= d:
        roots[c] = d

for i in range(n):
    cursor = i
    while cursor != roots[cursor]:
       cursor = roots[cursor]
    roots[i] = cursor

#print(roots)
res = [0]*n
for i in range(k):
    line = sys.stdin.readline().strip()
    a,b = map(int, line.split())
    c,d = a-1, b-1
    # same group blacklist
    if roots[c] == roots[d]:
        res[c] -= 1
        res[d] -= 1 
set_sizes = dict()

rs = list(set(roots))
for r in rs:
    count = 0
    for one in roots:
        if one == r:
            count += 1
    set_sizes[r] = count

for i in range(n):
    r = roots[i]
    res[i] += (set_sizes[r]-1-linked[i])
print (" ".join(map(str, res)))

### FIXED CODE ###

import sys

line = sys.stdin.readline().strip()
n,m,k = map(int, line.split())
roots = [-1]*n
linked = [0]*n
def find_root(x):
    if roots[x] < 0:
        return x
    else:
        roots[x] = find_root(roots[x])
        return roots[x]
def unite(x, y):
    x = find_root(x)
    y = find_root(y)
    if (x==y):
        return
    if roots[x] > roots[y]:
        c, d = y,x
        x,y = c,d
    roots[x] += roots[y]
    roots[y] = x

for i in range(m):
    line = sys.stdin.readline().strip()
    a,b = map(int, line.split())
    c, d = a-1,b-1
    linked[c] += 1 
    linked[d] += 1
    unite(c,d)
#print(roots)
blacks = [[]for i in range(n)]
for i in range(k):
    line = sys.stdin.readline().strip()
    a,b = map(int, line.split())
    c,d = a-1, b-1
    blacks[c].append(d)
    blacks[d].append(c)
res = []
for i in range(n):
    r = -roots[find_root(i)] - 1 - linked[i]
    for one in blacks[i]:
        if find_root(one) == find_root(i):
            r -= 1
    res.append(r)
    
print (" ".join(map(str, res)))
### BUGGY CODE ###

import collections
import itertools
N = int(input())
#cnt[UDLR][x y x+y x-y][value]=set()
#U(0)とD(1)がx(0)が一緒:d-u(>=0)の最小値
#L(2)とR(3)がy(1)が一緒:l-r(>=0)の最小値
#UとRがx+y(2)が一緒:(x-y)のu-r(>=0)の最小値
#LとDがx+y(2)が一緒:(x-y)のl-d(>=0)の最小値
#UとLがx-y(3)が一緒:(x+y)の(l-u)(>=0)の最小値
#RとDがx-y(3)が一緒:(x+y)の(d-r)(>=0)の最小値
cnt = [[collections.defaultdict(set) for _ in range(4)] for _ in range(4)]
for _ in range(N):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    p = x + y
    q = x - y
    if u == 'U':
        i = 0
    elif u == 'D':
        i = 1
    elif u == 'L':
        i = 2
    else:
        i = 3
    cnt[i][0][x].add(y)
    cnt[i][1][y].add(x)
    cnt[i][2][p].add(q)
    cnt[i][3][q].add(p)
ans = 10**10
for v in cnt[0][0]:
    ans = min([ans] + [
        d - u
        for u, d in itertools.product(cnt[0][0][v], cnt[1][0][v]) if d >= u
    ])
for v in cnt[2][1]:
    ans = min([ans] + [
        l - r
        for l, r in itertools.product(cnt[2][1][v], cnt[3][1][v]) if l >= r
    ])
for v in cnt[0][2]:
    ans = min([ans] + [
        u - r
        for u, r in itertools.product(cnt[0][2][v], cnt[3][2][v]) if u >= r
    ])
for v in cnt[2][2]:
    ans = min([ans] + [
        l - d
        for l, d in itertools.product(cnt[2][2][v], cnt[1][2][v]) if l >= d
    ])
for v in cnt[0][3]:
    ans = min([ans] + [
        l - u
        for l, u in itertools.product(cnt[2][3][v], cnt[0][3][v]) if l >= u
    ])
for v in cnt[3][3]:
    ans = min([ans] + [
        d - r
        for r, d in itertools.product(cnt[3][3][v], cnt[1][3][v]) if d >= r
    ])
print('SAFE' if ans == 10**10 else ans * 5)


### FIXED CODE ###

import collections
import itertools
N = int(input())
#cnt[URLD][x y y+x y-x][value]=set()
cnt = [[collections.defaultdict(set) for _ in range(4)] for _ in range(4)]
for _ in range(N):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    p = y + x
    q = y - x
    i = 'URLD'.index(u)
    cnt[i][0][x].add(y)
    cnt[i][1][y].add(x)
    cnt[i][2][p].add(q)
    cnt[i][3][q].add(p)

INF = float('inf')


def calc(up, down):
    ret = [INF]
    for c in up.keys() & down.keys():
        ua = sorted(up[c])
        da = sorted(down[c])
        i = j = 0
        for i in range(len(ua)):
            for j in range(j, len(da)):
                if ua[i] < da[j]:
                    ret += [da[j] - ua[i]]
                    break
            i += 1
    return min(ret)


#U(0)とD(3)がx(0)が一緒:d-u(>=0)の最小値
#R(1)とL(2)がy(1)が一緒:l-r(>=0)の最小値
#U(0)とR(1)がx+y(2)が一緒:(y-x)のr-u(>=0)の最小値
#L(2)とD(3)がx+y(2)が一緒:(y-x)のd-l(>=0)の最小値
#U(0)とL(2)がy-x(3)が一緒:(y+x)のl-u(>=0)の最小値
#R(1)とD(3)がy-x(3)が一緒:(y+x)のd-r(>=0)の最小値
ans = min(
    calc(cnt[0][0], cnt[3][0]), calc(cnt[1][1], cnt[2][1]),
    calc(cnt[0][2], cnt[1][2]), calc(cnt[2][2], cnt[3][2]),
    calc(cnt[0][3], cnt[2][3]), calc(cnt[1][3], cnt[3][3]))
print('SAFE' if ans == INF else ans * 5)
### BUGGY CODE ###

MOD = 10**9 + 7
N = int(input())

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

count = 0
for i in range(len(A)):
    for j in range(i + 1, len(A)):
        count += (A[i] * A[j]) % MOD
        count %= MOD
print(count)

### FIXED CODE ###

MOD = 10**9 + 7
N = int(input())

modsum = 0
A = list(map(int, input().split()))
for a in A:
    modsum = (modsum + a) % MOD

count = 0
for a in A[:-1]:
    modsum -= a
    while modsum < 0:
        modsum = MOD + modsum
    count = (count + (modsum * a) % MOD) % MOD
print(count)
### BUGGY CODE ###

A, B, K = map(int, input().split())
seisu = [i for i in range(A, B + 1)]
mitasu_seisu = []
ans = []
mitasu_seisu.append(seisu[:K])
mitasu_seisu.append(seisu[-K:])
for j in mitasu_seisu:
    for k in j:
        ans.append(k)
for l in sorted(list(set(ans))):
    print(l)

### FIXED CODE ###

A, B, K = map(int, input().split())
mitasu_seisu = []
for i in range(A, min(A + K, B)):
    mitasu_seisu.append(i)
for j in range(max(A, B - K + 1), B + 1):
    mitasu_seisu.append(j)
for k in sorted(set(mitasu_seisu)):
    print(k)
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))
a = 0
for i in range(N):
    hantei = 'OK'
    for j in range(i):
        if P[i] > P[j]:
            hantei = 'NG'
            break
    if hantei == 'OK':
        a += 1

print(a)

### FIXED CODE ###

def main():
    N = int(input())
    P = tuple(map(int,input().split()))
    a = 1
    minP = P[0]
    for i in range(1, N):
        if minP < P[i]:
            pass
        else:
            minP = P[i]
            a += 1
    print(a)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())

if N%2 == 0 or N == 5:
    print(-1)
    quit()
    
temp = 7%N
ans = 1
while temp != 0:
    temp = (temp*10+7)%N
    ans += 1
print(ans)

### FIXED CODE ###

N = int(input())

if N%2 == 0 or N == 5:
    print(-1)
    quit()
    
temp = 7%N
ans = 1
while temp != 0:
    temp = (temp*10+7)%N
    ans += 1
    if ans >= 10**6+1000:
        print(-1)
        quit()
print(ans)
### BUGGY CODE ###

N=int(input())
a = list(sorted(map(int,input().split())))
# a = [i for i in range(10**5)]

result = []
# all +
if a[0] > 0:
    if len(a) == 2:
        print(a[1]-a[0])
        print(a[1], a[0])
        exit()
    result.append((a[0], a[1]))
    t = a[0]-a[1]
    a.pop(0)
    a[0] = t
# all -
elif a[-1] < 0:
    if len(a) == 2:
        print(a[0]-a[1])
        print(a[0], a[1])
        exit()
    result.append((a[-1], a[-2]))
    t = a[-1]-a[-2]
    a.pop(-1)
    a[-1] = t

# print(a)
b = []
for i in range(len(a)-1):
    if a[i] > 0:
        result.append((b[0], a[i]))
        t = b[0]-a[i]
        b[0] = t
    else:
        b.append(a[i])
b.append(a[-1])
# print(b)
while len(b) != 1:
    result.append((b[-1], b[0]))
    b.append(b[-1]-b[0])
    b.pop(0)
    b.pop(-2)
# print(b)

print(b[0])
for r in result:
    print("{} {}".format(r[0],r[1]))

### FIXED CODE ###

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

result = []
# all +
if a[0] > 0:
    if len(a) == 2:
        print(a[1]-a[0])
        print(a[1], a[0])
        exit()
    result.append((a[0], a[1]))
    t = a[0]-a[1]
    a.pop(0)
    a[0] = t
# all -
elif a[-1] < 0:
    if len(a) == 2:
        print(a[0]-a[1])
        print(a[0], a[1])
        exit()
    result.append((a[-1], a[-2]))
    t = a[-1]-a[-2]
    a.pop(-1)
    a[-1] = t

# print(a)
b = []
for i in range(len(a)-1):
    if a[i] > 0:
        result.append((b[0], a[i]))
        t = b[0]-a[i]
        b[0] = t
    else:
        b.append(a[i])
b.append(a[-1])
# print(b)
while len(b) != 1:
    result.append((b[-1], b[0]))
    b.append(b[-1]-b[0])
    b.pop(0)
    b.pop(-2)
# print(b)

print(b[0])
for r in result:
    print(r[0],r[1])
### BUGGY CODE ###

N, D, A = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
for i in range(N):
    if H[i] <= 0:
        continue
    blast_r = X[i] + 2 * D
    max_j = N
    for j in range(i + 1, N):
        if X[j] > blast_r:
            max_j = j
            break
    c = (H[i] + A - 1) // A
    ans += c
    if i + 1 < max_j:
        H[i + 1:max_j] = [H[j] - A * c for j in range(i + 1, max_j)]
print(ans)


### FIXED CODE ###

from collections import deque

N, D, A = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
diff = 0
q = deque()
for i in range(N):
    Xi, Hi = M[i]
    while len(q) > 0 and q[0][0] < Xi:
        diff += q.popleft()[1]
    Hi += diff
    if Hi <= 0:
        continue
    c = (Hi + A - 1) // A
    ans += c
    diff -= A * c
    q.append((Xi + 2 * D, A * c))
print(ans)
### BUGGY CODE ###

def nibu(list,item):

    high=len(list)-1

    low=0
    while low <= high:
        mid=(low+high)//2
        guess=list[mid]
        if guess==item:
            return mid+1
            break
        elif guess < item:
            low = mid +1
        elif guess > item:
            high = mid - 1
    if guess != item:
        return high+1


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

sum=0

blist=[]
for i in range(n):

    kadan=nibu(C,B[i])
    u=n-kadan
    blist.append(u)
for i in range(n):
    tyudan=nibu(B,A[i])

    for i in range(tyudan,n):
        sum+=blist[i]

print(sum)


### FIXED CODE ###

N=map(int,input().split())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
 
def countA(target,L):
  ok=-1
  ng=len(L)
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]<target:
      ok=mid
    else:
      ng=mid
  return (ok+1)
 
def countC(target,L):
  ok=len(L)
  ng=-1
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]>target:
      ok=mid
    else:
      ng=mid
  return len(L)-ok
 
ans=0
for i in range(len(B)):
  data=B[i]
  ans+=(countA(data,A)*countC(data,C))
  
print(ans)
### BUGGY CODE ###

import numpy as np
dummyn = int(input())
a = list(map(int, input().split()))

b = []
for i in range(len(a)):
    b.append(sum(a[:i+1]))

b_np = np.array(b)

ans = 0
for i in range(len(b_np)-1):
    if b_np[i] * b_np[i+1] >= 0 and b_np[i] <= 0 and b_np[i] <= b_np[i+1]:
        ans += (1 - b_np[i+1])
        b_np[i+1:] += (1 - b_np[i+1])
    elif b_np[i] * b_np[i+1] >= 0 and b_np[i] < 0 and b_np[i] > b_np[i+1]:
        ans +=  (1 - b_np[i])
        b_np[i:] += (1 - b_np[i])
    elif b_np[i] * b_np[i+1] >= 0 and b_np[i] >= 0 and b_np[i] >= b_np[i+1]:
        ans += (b_np[i+1] + 1)
        b_np[i+1:] -= (b_np[i+1] + 1)
    elif b_np[i] * b_np[i+1] >= 0 and b_np[i] > 0 and b_np[i] < b_np[i+1]:
        ans += (b_np[i] + 1)
        b_np[i:] -= (b_np[i] + 1)

print(ans)

### FIXED CODE ###

n=input()
a=[int(i) for i in input().split()]
def chk(a,t):
    ans=0
    x=0
    for i in a:
        x+=i
        if t==True and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(chk(a,True),chk(a,False)))
### BUGGY CODE ###

import sys
mod = 7 + 10 ** 9

def lcm(a, b):
    a, b = max(a, b), min(a, b)
    c = a * b
    while a % b > 0:
        a, b = b, a % b
    return c // b

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    L = A[0]
    for i in range(1, N): L = lcm(L, A[i])
    ans = 0
    for a in A:
        ans += (L * pow(a, mod - 2, mod)) % mod
        ans %= mod
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys
from collections import deque
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from bisect import bisect, bisect_left

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    c = a * b
    while a % b > 0:
        a, b = b, a % b
    return b

def solve():
    input = sys.stdin.readline
    mod = 7 + 10 ** 9
    N = int(input())
    A = [int(a) for a in input().split()]
    if N == 1: print(1)
    else:
        lcm = A[0]
        for i in range(1, N):
            gcd_a = gcd(lcm, A[i])
            lcm = lcm * A[i] // gcd_a
        lcm %= mod
        sumB = 0
        for i,a in enumerate(A):
            sumB += lcm * pow(a, mod - 2, mod)
            sumB %= mod

        print(sumB)
    return 0

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

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = read().decode().rstrip()

l = 0

cnt = 0
while l < len(S):
    r = l + 3
    while r < len(S):
        acc = S[l:r + 1]
        if int(acc) % 2019 == 0:
            cnt += 1
        r += 1
    l += 1

print(cnt)


### FIXED CODE ###

import sys
from collections import Counter, defaultdict
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = read().decode().rstrip()

reminders = defaultdict(lambda: 0)
tmp = 0
mul = 1

for c in S[::-1]:
    c = int(c)
    tmp = (tmp + c * mul) % 2019
    mul = mul * 10 % 2019
    reminders[tmp] += 1
reminders[0] += 1

ans = 0

for r, cnt in reminders.items():
    ans += cnt * (cnt - 1) // 2

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

n = int(input())
a = list(map(int, input().split()))
out = [""] * n
count = 0
out_str = ""
for i in range(n):
    out_str += str(a.index(i + 1) + 1) + " "

print(out_str[:-1])


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
out = [""] * n
out_str = ""
for i in range(n):
    out[a[i] - 1] = str(i + 1)
        
out_str = " ".join(out)
 
print(out_str)
### BUGGY CODE ###

#!/usr/bin/python3

from fractions import Fraction

M = 1000000007

def normalize(v):
    if v > 0:
        return v
    else:
        return - 1 / v

n = int(input())

vs = {}
wp = set()
zc = 0
azc = 0
bzc = 0

for i in range(n):
    (a, b) = map(int, input().split())
    if a == 0 and b == 0:
        zc += 1
        continue

    if a == 0:
        azc += 1
        continue

    if b == 0:
        bzc += 1
        continue

    v = Fraction(a, b)
    if v in vs:
        vs[v] += 1
    else:
        vs[v] = 1

    if - 1 / v in vs:
        wp.add(normalize(v))

#print(zc, azc, bzc, vs, wp)
        
c = 1
if azc == 0 or bzc == 0:
    c = c * pow(2, azc + bzc, M) % M
else:
    c = c * (pow(2, azc, M) - 1 + pow(2, bzc, M) - 1 + 1) % M

r = n - azc - bzc
for p in wp:
    invp = -1 / p
    c = c * (pow(2, vs[p], M) - 1 + pow(2, vs[invp], M) - 1 + 1) % M
    r -= vs[p] + vs[invp]

r -= zc
c = c * pow(2, r, M) % M
c = (c + zc) % M
c = (c - 1) % M

print(c)





    


### FIXED CODE ###

#!/usr/bin/python3

import math

M = 1000000007

def normalize(v):
    (a, b) = v
    if a * b > 0:
        return (a, b)
    else:
        if a > 0:
            return (-b, a)
        else:
            return (b, -a)
    
def inv(v):
    (a, b) = v
    if a > 0:
        return (-b, a)
    else:
        return (b, -a)
    
    
n = int(input())

vs = {}
zc = 0
azc = 0
bzc = 0

for i in range(n):
    (a, b) = map(int, input().split())
    if b < 0:
        a = -a
        b = -b

    g = math.gcd(a, b)
        
    if a == 0 and b == 0:
        zc += 1
        continue

    if a == 0:
        azc += 1
        continue

    if b == 0:
        bzc += 1
        continue

    (a, b) = (a // g, b // g)
    if (a, b) in vs:
        vs[(a, b)] += 1
    else:
        vs[(a, b)] = 1

wp = set()
for v in vs:
    if inv(v) in vs:
        wp.add(normalize(v))

#print(zc, azc, bzc, vs, wp)
        
c = 1
if azc == 0 or bzc == 0:
    c = c * pow(2, azc + bzc, M) % M
else:
    c = c * (pow(2, azc, M) - 1 + pow(2, bzc, M) - 1 + 1) % M

r = n - azc - bzc
for p in wp:
    invp = inv(p)
    c = c * (pow(2, vs[p], M) - 1 + pow(2, vs[invp], M) - 1 + 1) % M
    r -= vs[p] + vs[invp]

r -= zc
c = c * pow(2, r, M) % M
c = (c + zc) % M
c = (c - 1) % M

print(c)
### BUGGY CODE ###

def solve():
    n=int(input())
    a=[int(input()) for _ in range(n)]
    num1=max(a)
    for i in range(n):
        if a[i]==num1:
            if i==0:
                print(max(a[1:]))
            elif i==n-1:
                print(max(a[:n-1]))
            else:
                print(max(max(a[:i]),max(a[i+1:])))
        else:
            print(num1)

solve()


### FIXED CODE ###

def solve():
    n=int(input())
    num=[]
    def append(num1):
        num.append(num1)
    def count1(num2):
        return num.count(num2)
    for i in range(n):
        a=int(input())
        append(a)
    max1=max(num)
    count=count1(max1)
    if count>1:
        for i in range(n):
            print(max1)
    else:
        for i in range(n):
            if num[i]==max1:
                if i==0:
                    print(max(num[1:]))
                elif i==n-1:
                    print(max(num[:n-1]))
                else:
                    print(max(max(num[:i]),max(num[i+1:])))
            else:
                print(max1)
solve()
### BUGGY CODE ###

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

n = 1


for i in range(a):
  n = n * b[i]

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

### FIXED CODE ###

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

c = 0
d = 0

for i in b:
    if i == 0:
        c += 1
    elif i > 10**18:
        d += 1
        
if c > 0:
    print(0)
    exit()
if d > 1 and c == 0:
    print(-1)
    exit()

for i in b:
  n *= i
  if n > 10**18:
    print(-1)
    exit()
print(n)
### BUGGY CODE ###

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

while i<=n:
    print(a.index(i)+1, end=" ")
    i+=1

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
i=1
b = []
j=0

map = {a[i]:str(i+1) for i in range(n)}
print(" ".join([map[i] for i in range(1, n+1)]))
### BUGGY CODE ###

N,K = (int(i) for i in input().split())
P = [int(i) for i in input().split()]

ans = 0
for i in range(0,N-K+1):
  tmp  = 0
  for j in range(i,i+K):
    tmp += ((1+P[j])*P[j]/2)/P[j]

  ans = max(ans,tmp)

print(ans)


### FIXED CODE ###

N,K = (int(i) for i in input().split())
P = [int(i) for i in input().split()]
P_expect_sum = [0 for i in range(N)]

P_pred = 0
for i in range(N):
  P_expect = (1+P[i])/2
  P_expect_sum[i] = P_pred + P_expect
  P_pred = P_expect_sum[i]

ans = P_expect_sum[K-1]
for i in range(K-1,N):
  ans = max(ans, P_expect_sum[i] - P_expect_sum[i-K])
print(ans)
### BUGGY CODE ###

def main():
    S = input()
    Q = int(input())
    query = []
    revFlag = False
    for i in range(Q):
        query.append(list(input().split()))
    for i in range(Q):
        if query[i][0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if query[i][1] == "1":
                if revFlag:
                    S += query[i][2]
                else:
                    S = query[i][2] + S
            else:
                if revFlag:
                    S = query[i][2] + S
                else:
                    S += query[i][2]
    if revFlag:
        print(S[::-1])
    else:
        print(S)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque

def main():
    S = deque(input())
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S.append(tmp[2])
                else:
                    S.appendleft(tmp[2])
            else:
                if revFlag:
                    S.appendleft(tmp[2])
                else:
                    S.append(tmp[2])
    if revFlag:
        S = list(S)
        S.reverse()
        print("".join(S))
    else:
        S = list(S)
        print("".join(S))


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

def dfs(i, j, s):
    if j == 3 and s == x:
        ans.append(1)

    for k in range(1, i):
        if s + k > x:
            break
        dfs(k, j + 1, s + k)

ans = []
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break

    for i in range(3, n + 1):
        dfs(i, 1, i)

print(sum(ans))


### FIXED CODE ###

def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            if i + j < x < i + 2 * j:
                result += 1
    return str(result)

ans = []
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    ans.append(calc(n, x))

print("\n".join(ans))