Harryxun/stf_run huggingface dataset:
s = input()
q = int(input())
count = 0
top = ""
end = ""
ans = s
for i in range(q):
    tmp = input()
        count += 1
    else:
        _, f, c = map(str, tmp.split())
        if (count % 2 == 0 and f == "1") or (count % 2 == 1 and f == "2"):
            top = c + top
        else:
            end = end + c

ans = top + ans + end
ans = ans[::-1] if count % 2 == 1 else ans
print(ans)


### FIXED CODE ###

s = input()
q = int(input())
count = 0
top = ""
end = ""
ans = s
for i in range(q):
    tmp = input()
    if tmp[0] == "1":
        count += 1
    else:
        _, f, c = map(str, tmp.split())
        if count % 2 == 0:
            if f == "1":
                top = c + top
            else:
                end = end + c
        else:
            if f == "1":
                end = end + c
            else:
                top = c + top

ans = top + ans + end
ans = ans[::-1] if count % 2 == 1 else ans
print(ans)
import copy
N, M = [int(_) for _ in input().split()]
AB = [[int(_) - 1 for _ in input().split()] for _ in range(M)]

G = [set() for _ in range(N)]
a = set()
for ab in AB:
    G[ab[0]].add(ab[1])


def find(a, x):
    stack = []
    while a[x] != x:
        stack += [x]
        x = a[x]
    while stack:
        a[stack.pop()] = x
    return x


def unite(a, x, y):
    x = find(a, x)
    y = find(a, y)
    a[x] = a[y] = min(x, y)


ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if j in G[i]:
            Gn = copy.deepcopy(G)
            Gn[i].discard(j)
            a = [i for i in range(N)]
            for k in range(N - 1):
                for l in Gn[k]:
                    unite(a, k, l)
            par = set()
            for k in range(N):
                par.add(find(a, k))
            if len(par) > 1:
                ans += 1
print(ans)


### FIXED CODE ###

class UFT():
    def __init__(self):
        self.par = {}
        self.rank = {}

    def find(self, x):
        if self.par.get(x, x) == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        self.rank[x] = self.rank.get(x, 0)
        self.rank[y] = self.rank.get(y, 0)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

N, K, L = [int(_) for _ in input().split()]

Road = UFT()
for _ in range(K):
    p, q = [int(_) for _ in input().split()]
    Road.unite(p, q)
Railway = UFT()
for _ in range(L):
    r, s = [int(_) for _ in input().split()]
    Railway.unite(r, s)
memo = {}
for i in range(1, N + 1):
    memo[Road.find(i), Railway.find(i)] = memo.get((Road.find(i), Railway.find(i)), 0) + 1
print(' '.join(str(memo[Road.find(i), Railway.find(i)]) for i in range(1, N + 1)))
N=int(input())
a=[list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x: x[1])

ans=[]
for i in range(0,101):
    for j in range(0,101):
        p=a[0][2]+abs(i-a[0][0])+abs(j-a[0][1])
        q=a[1][2]+abs(i-a[1][0])+abs(j-a[1][1])
        if N>2: r=a[2][2]+abs(i-a[2][0])+abs(j-a[2][1])

        if N==2 and p==q: ans.append([i,j,p])
        elif p==q and p==r: ans.append([i,j,p])

for i in range(3,N) :
    if len(ans)==1: break
    for x in ans:
        if x[2]!=a[i][2]+abs(x[0]-a[i][0])+abs(x[1]-a[i][1]):
            ans.remove(x)

print(ans[0][0],ans[0][1],ans[0][2])

### FIXED CODE ###

import sys
N=int(input())
a=[list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x: x[2],reverse=True)
ans=[]

if a[0][2]==100:
    print(a[0][0],a[0][1],a[0][2])
    sys.exit()



for i in range(0,101):
    for j in range(0,101):
        p=a[0][2]+abs(i-a[0][0])+abs(j-a[0][1])
#       q=a[1][2]+abs(i-a[1][0])+abs(j-a[1][1])
        for k in range(1,N):
            if a[k][2]>0 and a[k][2]+abs(i-a[k][0])+abs(j-a[k][1])!=p : break
            elif a[k][2]==0 and a[k][2]+abs(i-a[k][0])+abs(j-a[k][1])<p : break
            if k==N-1:
                print(i,j,p)
                sys.exit()
n = int(input())
cnt = 0
for i in range(1,n):
  if (len(str(i))%2==1)
  	cnt+=1
print(cnt)

### FIXED CODE ###

n = int(input())
cnt = 0
for i in range(1,n+1):
  if (len(str(i))%2==1):
  	cnt+=1
print(cnt)
def find(tab, a):
    if tab[0][a]==-1:
        return a
    tab[0][a] = find(tab, tab[0][a])
    return tab[0][a]

def union(tab, a, b):
    p1, p2 = find(tab, a), find(tab, b)
    if p1 != p2:
        tab[0][p1] = p2
        tab[1][p2] += tab[1][p1]

def size(tab, a):
    return tab[1][a]

N, M = [int(a) for a in input().split(" ")]
ABs = [[int(a) for a in input().split(" ")] for i in range(M)]
tab = [[-1]*N, [1]*N]
arr = []

for a, b in reversed(ABs):
    a, b = a-1, b-1
    pa, pb = find(tab, a), find(tab, b)
    na, nb = size(tab, pa), size(tab, pb)
    if pa!=pb:
        try:
            dn = ((na+nb)*(na+nb-1)//2)-(na*(na-1)//2)-(nb*(nb-1)//2)
            arr.append(dn)
            union(tab, a, b)
        except:
            pass
    else:
        arr.append(0)

acc = 0
for cp in reversed(arr):
    acc += cp
    print(acc)


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

def find(tab, a):
    if tab[0][a]==a:
        return a
    tab[0][a] = find(tab, tab[0][a])
    return tab[0][a]

def union(tab, a, b):
    p1, p2 = (find(tab, a), find(tab, b))
    if p1 != p2:
        tab[0][p1] = p2
        tab[1][p2] += tab[1][p1]

def size(tab, a):
    return tab[1][a]

N, M = [int(a) for a in input().split(" ")]
ABs = [[int(a) for a in input().split(" ")] for i in range(M)]
tab = [[i for i in range(N)], [1 for i in range(N)]]
arr = []

for a, b in reversed(ABs):
        a, b = (a-1, b-1)
        pa, pb = (find(tab, a), find(tab, b))
        na, nb = (size(tab, pa), size(tab, pb))
        if pa!=pb:
            dn = ((na+nb)*(na+nb-1)//2)-(na*(na-1)//2)-(nb*(nb-1)//2)
            arr.append(dn)
            union(tab, a, b)
        else:
            arr.append(0)

acc = 0
for cp in reversed(arr):
    acc += cp
    print(acc)
# 入力を受け取る
B_MAX = 100000
N = int(input().strip())
B = input().strip().split()

# B_MAX + 1を入れておくことで 必ずmin(B[0], B[1]) = B[1], min(B[N-1], B[N]) = B[N-1]となる
B = [B_MAX + 1] + [int(b) for b in B] + [B_MAX + 1] # 整数に変換


for i in range(1, N + 1): # i = 1, 2, ..., N
    sum += min(B[i-1], B[i]) # A[i] <= min(B[i-1], B[i])

print(sum)

### FIXED CODE ###

# 入力を受け取る
B_MAX = 100000
N = int(input().strip())
B = input().strip().split()

# B_MAX + 1を入れておくことで 必ずmin(B[0], B[1]) = B[1], min(B[N-1], B[N]) = B[N-1]となる
B = [B_MAX + 1] + [int(b) for b in B] + [B_MAX + 1] # 整数に変換

sum = 0
for i in range(1, N + 1): # i = 1, 2, ..., N
    sum += min(B[i-1], B[i]) # A[i] <= min(B[i-1], B[i])

print(sum)
S=int(input().strip())

m =None
for i in range(len(S)-2):
  e=int(S[i:i+3])
  if m is None:
    m=abs(753-e)
  elif abs(753-e) <m:
    m=abs(753-e)
print(m)

### FIXED CODE ###

S=input().strip()

m =None
for i in range(len(S)-2):
  e=int(S[i:i+3])
  if m is None:
    m=abs(753-e)
  elif abs(753-e) <m:
    m=abs(753-e)
print(m)
ls=[]
for i in range(5):
  ls.append(int(input()))
ls.sort()
if ls[4]-ls[0]>k:
  print(":(")
else:
  print("Yay!")

### FIXED CODE ###

ls=[]
for i in range(5):
  ls.append(int(input()))
ls.sort()
if ls[4]-ls[0]>int(input()):
  print(":(")
else:
  print("Yay!")
N = int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
ans = 1
for i in range(2,N):
    a = factorization(n)
    b = 1
    for j in range(len(a)):
        x = a[j][1]
        b *= (x+1)
    ans += b
print(ans)
        

### FIXED CODE ###

N = int(input())
ans = 0
for i in range(1,N):
    x = (N-1)//i
    ans += x
print(ans)
s = int(input())
pf=[]
for i in range(2,int(s**0.5)+1):
    while s%i==0:
        pf.append(i)
        s//=i
if s>1:pf.append(i)
a = 0
b = 0
for i in range(len(pf)):
  if(i%2==0):
    a+=pf[i]
  else:
    b+=pf[i]
if a==0:
  a = 1
if b==0:
  b = 1
print("0","0",a,"0","0",b)



### FIXED CODE ###

import math
s = int(input())
root = math.ceil(s**0.5)
#print("root",root)
diff = abs(root**2 - s)
#print("diff",diff)
pf=[]
a = 0
b = 0
#print(int(diff**0.5))
if diff != 1:
  if diff == 2:
    a = 1
    b = 2
  elif diff == 3:
    a = 1
    b = 3
  else:
    test = int(diff**0.5)+1
    for i in range(2, test):
      #print("diffloop",diff)
#      if i == 1710:
#        print("1710diff",diff)
#      if i ==25322:
#        print("25322diff",diff%i)
      while diff%i==0:
        pf.append(i)
        diff//=i
#        print("i",i,"diff",diff)
    if diff>1:pf.append(diff)
    for i in range(len(pf)):
      if(i%2==0):
        if a ==0:
          a = 1
        a*=pf[i]
      else:
        if b ==0:
          b = 1
        b*=pf[i]
else:
  a = 1
  b = 1
if a != 0 and b == 0:
  b = 1
if b != 0 and a == 0:
  a = 0
if a > 10**9:
  a /= pf[0]
  b *= pf[0]
if b > 10**9:
  a *= pf[0]
  b /= pf[0]
#print("pf",pf)
if a >= 0 and b >= 0:
  print("0","0",a,root,root,b)
elif a >= 0 and b < 0:
  print("0",-b,a,root-b,root,0)
elif a < 0 and b >= 0:
  print(-a,"0","0",root,root-a,b)
else:
  print(-a,-b,"0",root-b,root-a,"0")
n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n-1)]

neighbors = [[] for _ in range(n)]

for x, y in xys:
    neighbors[x-1].append(y-1)
    neighbors[y-1].append(x-1)

froms = [-1 for _ in range(n)]

froms[0] = -2

def f(x):
    for y in neighbors[x]:
        if froms[y]==-1 :
            froms[y] = x
            f(y)

f(0)

path = [n-1]
while path[-1]!=0:
    if froms[path[-1]]==-1:
        break
    path.append(froms[path[-1]])
path.reverse()

blacks_l = path[:(len(path)+1)//2]
blacks = set(blacks_l)
whites = set(path[(len(path)+1)//2:])

def fennec(x):
    for y in neighbors[x]:
        if not y in blacks and not y in whites:
            blacks.add(y)
            fennec(y)

for b in blacks_l:
    fennec(b)

if len(blacks) > n-len(blacks):
    print('Fennec')
else:
    print('Snuke')

### FIXED CODE ###

import sys

sys.setrecursionlimit(100000000)

n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n-1)]

neighbors = [[] for _ in range(n)]

for x, y in xys:
    neighbors[x-1].append(y-1)
    neighbors[y-1].append(x-1)

froms = [-1 for _ in range(n)]

froms[0] = -2

def f(x):
    for y in neighbors[x]:
        if froms[y]==-1 :
            froms[y] = x
            f(y)

f(0)

path = [n-1]
while path[-1]!=0:
    if froms[path[-1]]==-1:
        break
    path.append(froms[path[-1]])
path.reverse()

blacks_l = path[:(len(path)+1)//2]
blacks = set(blacks_l)
whites = set(path[(len(path)+1)//2:])

def fennec(x):
    for y in neighbors[x]:
        if not y in blacks and not y in whites:
            blacks.add(y)
            fennec(y)

for b in blacks_l:
    fennec(b)

if len(blacks) > n-len(blacks):
    print('Fennec')
else:
    print('Snuke')
a, b, n = map(int, input().split())

def divisor(num):
    num_l = []
    if (num == 1) :
        return [1]
    else :
        for i in range(1,num):
            if (num % i == 0):
                num_l.append(i)
        return num_l

a_l = divisor(a)
b_l = divisor(b)

two_divisor = []
for c in a_l :
    if c in b_l :
        two_divisor.append(c)

print(two_divisor[n-1])

### FIXED CODE ###

a, b, k = map(int, input().split())
 
num = min(a, b)
answer = []
for i in range(1, num+1):
    if (a % i == 0 and b % i == 0):
        answer.append(i)
        
print(answer[-k])
vi = 0
j = 0
for s in input():
    j += 1

    if s == "R":
        i += 1
    if j != 3 and i > 0 and s == "S":
        i -= 1

print(i)

### FIXED CODE ###

i = 0
j = 0
k = 0

w = ""
for s in input():
    j += 1

    if s == "S":
        k += 1

    if s == "S" and i > 0 and j == 2 and w != "R":
        i -= 1

    if s == "R" and (w == "R" or w == ""):
        i += 1
    elif s == "R" and w != s:
        i += 1    
    
    if w == "S":
        i = 1
    
    w = s

if k == 3:
    i = 0

print(i)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# A机から0〜N冊読んで、残り時間でB机から何冊読めるかを考える
lst = [0]*(N+1)

for i in range(N+1):
    time = 0
    time = sum(A[0:i])　# A机からi冊読んだときの所要時間
    if time > K:
        break # この時点で制限時間Kを超えていたらB机は無視する
    else:
        for j in range(M):
            # 
            if time + B[j] <= K:
                time = time + B[j]
            else:
                lst[i] = i + j
                break

res = max(lst)
print(res)

"""
3 4 240
60 90 120
80 150 80 150

3 4 730
60 90 120
80 150 80 150
"""

### FIXED CODE ###

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

a, b = [0],[0]
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])

ans, j = 0, M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
high, width, y, x = map(int, input().split())

import math
route = 0
for i in range(1,high-y+1):
    if i != high-y:
        route += ((math.factorial(x+i-1)/(math.factorial(x)*math.factorial(i-1)))%(10**9+7))*((math.factorial(width-x-2+high-i)/(math.factorial(width-x-2)*math.factorial(high-i))))%(10**9+7)
    else:
        route += ((math.factorial(x+i-1)/(math.factorial(x)*math.factorial(i-1)))%(10**9+7))*((math.factorial(width-x-1+high-i)/(math.factorial(width-x-1)*math.factorial(high-i))))%(10**9+7)
print(int(route))

### FIXED CODE ###

high, width, y, x = map(int, input().split())

def nCr(n, r):
    return ((((fact[n]*finv[n-r])%mod)*finv[r])%mod)

mod = 10**9 + 7
inv = mod - 2
maxn = high + width - 2
fact = [0] * (maxn+1)
finv = [0] * (maxn+1)
fact[0] = fact[1] = 1
finv[0] = finv[1] = 1

# 階乗を求める
for i in range(2, maxn+1):
    fact[i] = (fact[i-1] * i) % mod

# 階乗の逆元を求める
for i in range(2, maxn+1):
    finv[i] = pow(fact[i], inv, mod)

route = 0
for i in range(1, high-y+1):
        route += (nCr(x+i-2, i-1) * nCr(width+high-x-1-i, high-i)) % mod
        route = route % mod
print(int(route))
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
count = 0
 
for i in range(n):
  a = list(map(int, input().split()))
  p = c
  for j in range(m):
  p += a[j] + b[j]
  if 0 < p:
    count += 1
print(count)

### FIXED CODE ###

n, m, c = map(int, input().split())
b = list(map(int, input().split()))
count = 0
 
for i in range(n):
  a = list(map(int, input().split()))
  p = c
  for j in range(m):
  	p += a[j] * b[j]
  if 0 < p:
    count += 1
print(count)
from collections import deque

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

sys.setrecursionlimit(5000)

def get_adj_tiles(v):
    i, j = v
    res = [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]
    return res

def bfs(point):
    visited = []
    que = deque()
    que.append((point, 1))
    
    while True:
        v, depth = que.popleft()
        visited.append(v)
        adjs = get_adj_tiles(v)
        for a in adjs:
            if field[a[0]][a[1]] == '.' and a not in visited:
                if a == (H, W):
                    return depth + 1
                else:
                    que.append((a, depth+1))
        if len(que) == 0:
            return 0

H, W = list(map(int, input().split()))
field = [['#'] * (W + 2) for _ in range(H + 2)]
for i in range(H):
    values = list(input())
    field[i+1][1:-1] = values
    
number_of_whites = 0
for i in range(H+2):
    for j in range(W+2):
        if field[i][j] == '.':
            number_of_whites += 1
shortest_path = bfs((1, 1))
if shortest_path > 0:
    print(number_of_whites - shortest_path)
else:
    print(-1)

### FIXED CODE ###

H, W = list(map(int, input().split()))
M = [[-1]*(W+2)]
ans = 0
for _ in range(H):
    s = input()
    ans += s.count('.')
    M.append([-1]+[0 if c=='.' else -1 for c in s]+[-1])
M += [[-1]*(W+2)]

queue = [(1,1)]
M[1][1] = 1
dr = [(+1,0),(-1,0),(0,+1),(0,-1)]
turn = 1
while len(queue)>0:
    turn += 1
    queue_new = []
    for qx, qy in queue:
        for dx, dy in dr:
            x, y = qx+dx, qy+dy
            if M[y][x]==0:
                M[y][x] = turn
                queue_new.append((x,y))
    queue = queue_new

print(ans-M[H][W] if M[H][W]>0 else -1)
import math
x = int(input())
n = 100
y = 0

while x > n:
    # 小数点以下切り捨て
    n += n // 100
    y += 1

print(y)

### FIXED CODE ###

# ABC166 B
n,k = map(int, input().split())
# お菓子を持っているすぬけ君かを判断する配列d 1ならもってる 0はもってない
d = [0] * n
# お菓子iを持っているのはどのすぬけ君か？
for i in range(k):
    # お菓子iを持っている人数m人
    m = int(input())
    # お菓子iを持っているすぬけ君のリスト
    a = list(map(int, input().split()))
    for j in range(m):
        # すぬけ君a[j]は少なくとも一つ以上のお菓子を持っている
        d[a[j]-1] = 1 
        
#いたずらされる人数ans人
ans = 0
for i in range(n):
    if d[i] == 0:
        ans += 1

print(ans)
n,x=map(int,input().split())
L=list(map(int,input().split()))
d=0
count=1
for i in range(n+1):
    d += L[i]

    if d > x:
        print(count)
        break
    else:
        count += 1
        

### FIXED CODE ###

n,x=map(int,input().split())
L=list(map(int,input().split()))
d=0
count=1
for i in range(n):
    d += L[i]
 
    if d <= x:
        count += 1
    else:
        break

print(count)
N, A, B, C, D = map(int, input().split())
E = B - A
for m in range(N):
  if C*(N-1-m) - D*m <= E <= -C*m + (N-1-m)*D:
    print("YES")
    break
else
print("NO")

### FIXED CODE ###

N, A, B, C, D = map(int, input().split())
E = B - A
for m in range(N):
  if C*(N-1-m) - D*m <= E <= -C*m + (N-1-m)*D:
    print("YES")
    break
else:
  print("NO")
N = int(input())
l = list()

for n in range(0,N-1):
    a = input()
    l.append(a)

l_uniq = list(set(l))

if len(l) == len(l_uniq):
    for i in range(1, N):
        if a[i][0] != a[i-1][-1]:
            print("No")
            break
    print("Yes")
else:
    print("No")
    

### FIXED CODE ###

N = int(input())
l = list()

for n in range(N):
    a = input()
    l.append(a)

l_uniq = list(set(l))

if len(l) == len(l_uniq):
    for i in range(0, N-1):
        if l[i+1][0] != l[i][-1]:
            print("No")
            break
    else:
        print("Yes")
else:
    print("No")
S = input()
cnt = 0

for i in S:
    if i == 'R':
        cnt += 1
    else:
        cnt_max = cnt
        cnt = 0
print(cnt_max)

### FIXED CODE ###

S = input()
cnt = 0
cnt_max = 0

for i in S:
    if i == 'R':
        cnt += 1
        cnt_max = cnt
    else:
        
        cnt = 0
print(cnt_max)
N=int(input()) K=int(input))
if N%K==0:
	print(0)
else:
	print(1)


### FIXED CODE ###

N, K=map(int, input(). split())
if N%K==0:
	print(0)
else:
	print(1)
h, w, k = map(int, input().split())
s = []
ans = [[0] * w for _ in range(h)]
cnt = 0
#prev = 1

for i in range(h):
    s.append(input())

#print(s)

for i in range(h):
    if '#' not in s[i]:
        continue
    shouldCover = False

    for j in range(w):
        if j == 0 and s[i][j] == '.':
            cnt += 1
            ans[i][j] = cnt
            shouldCover = True
        elif s[i][j] == '#' and shouldCover:
            ans[i][j] = cnt
            shouldCover = False
        elif s[i][j] == '#':
            cnt += 1
            ans[i][j] = cnt
            shouldCover = False
        else:
            ans[i][j] = cnt

def solve(cur, nxt, down):
    if down:
        if '#' in s[nxt]:
            for j in range(w):
                ans[cur][j] = ans[nxt][j]
        else:
            solve(cur, nxt+1, down)
    else:
        if '#' in s[nxt]:
            for j in range(w):
                ans[cur][j] = ans[nxt][j]
        else:
            solve(cur, nxt-1, down)


for i in range(h):
    if all(ans[i][j] == 0 for j in range(w)):
        if i == h - 1:
            solve(i, i-1, False)
        else:
            #print('down!')
            solve(i, i+1, True)

for i in range(h):
    print(*ans[i])
#print(ans)





### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)

h, w, k = map(int, input().split())
s = []
ans = [[0] * w for _ in range(h)]
cnt = 0
#prev = 1

for i in range(h):
    s.append(input())

#print(s)

for i in range(h):
    if '#' not in s[i]:
        continue
    shouldCover = False

    for j in range(w):
        if j == 0 and s[i][j] == '.':
            cnt += 1
            ans[i][j] = cnt
            shouldCover = True
        elif s[i][j] == '#' and shouldCover:
            ans[i][j] = cnt
            shouldCover = False
        elif s[i][j] == '#':
            cnt += 1
            ans[i][j] = cnt
            shouldCover = False
        else:
            ans[i][j] = cnt

def solve(cur, nxt, down):
    if nxt < 0 or nxt > h-1:
        return
    if down:
        if '#' in s[nxt]:
            for k in range(cur, nxt):
                for j in range(w):
                    ans[k][j] = ans[nxt][j]
        else:
            solve(cur, nxt+1, down)
    else:
        if '#' in s[nxt]:
            for k in range(cur, nxt, -1):
                for j in range(w):
                    ans[k][j] = ans[nxt][j]
        else:
            solve(cur, nxt-1, down)


for i in range(h):
    if all(ans[i][j] == 0 for j in range(w)):
        if i == h - 1:
            solve(i, i-1, False)
        else:
            #print('down!')
            solve(i, i+1, True)

for i in range(h):
    print(*ans[i])
#print(ans)
N=int(input())
H=list(map(int,input().split()))

dp=[float('inf')]*N

def f(i):
    if dp[i]<float('inf'): return dp[i]
    if i==0: return 0
    res=10**4+1
    res=min(res,f(i-1)+abs(H[i]-H[i-1]))
    if i>1: res=min(res,f(i-2)+abs(H[i]-H[i-2]))
    dp[i]=res
    return dp[i]

print(f(N-1))

### FIXED CODE ###

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

dp=[0]*N

dp[1]=abs(H[0]-H[1])

for i in range(2,N):
    a,b=dp[i-1]+abs(H[i-1]-H[i]),dp[i-2]+abs(H[i-2]-H[i])
    if a<b:
        dp[i]+=a
    else:
        dp[i]+=b

print(dp[-1])
# 塩基 A, C, G, T が存在し、A と T、C と G がそれぞれ対

b = input()

if b == ('A'):
    print(T)

if b == ('C'):
    print(G)

if b == ('T'):
    print(A)

if b == ('G'):
    print(C)

### FIXED CODE ###

# 塩基 A, C, G, T が存在し、A と T、C と G がそれぞれ対

b = input()

if b == ('A'):
    print('T')

if b == ('C'):
    print('G')

if b == ('T'):
    print('A')

if b == ('G'):
    print('C')
a, b = map(int, input().split())
if a == 1 <= value < 10:
  if b == 1 <= value < 10:
    print(a * b)
  else:
    print('-1')
else:
  print('-1')

### FIXED CODE ###

a, b = map(int, input().split())
c = [1,2,3,4,5,6,7,8,9]
if a in c and b in c:
  print(a*b)
else:
  print('-1')
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 18 10:42:00 2017

@author: syaga
"""

import math

def insertionSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i-g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return cnt
         
def shellSort(A, n):
    cnt = 0
    m = int(math.log(n-1,4)) + 1
    print(m)
    G = [4**i for i in range(m-1, -1, -1)]
    print(" ".join(map(str, G)))
    for i in range(0, m):
        cnt = insertionSort(A, n, G[i], cnt)
    print(cnt)

if __name__ == "__main__":
    n = int(input())
    A = []
    for i in range(n):
        A.append(int(input()))
    shellSort(A, n)
    for i in A:
        print(i)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Jun 18 10:42:00 2017

@author: syaga
"""

import math

def insertionSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i-g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return cnt
         
def shellSort(A, n):
    cnt = 0
    G = [1]
    if n != 1:
        for i in range(99):
            G.append(G[i]*3+1)
        G = [x for x in G if x < n]
        G.reverse()
    m = len(G)
    print(m)
    print(" ".join(map(str, G)))
    for i in range(0, m):
        cnt = insertionSort(A, n, G[i], cnt)
    print(cnt)

if __name__ == "__main__":
    n = int(input())
    A = []
    for i in range(n):
        A.append(int(input()))
    shellSort(A, n)
    for i in A:
        print(i)