Harryxun/stf_run huggingface dataset:
import sys

nil = -1

class Node:
    def __init__(self, p, l, r):
        self.p = p
        self.l = l
        self.r = r

def depth_rec(u, p, depth):
    depth[u] = p
    if tree[u].r != nil:
        depth_rec(tree[u].r, p, depth)
    if tree[u].l != nil:
        depth_rec(tree[u].l, p + 1, depth)
    pass

n = int(sys.stdin.readline())

tree = [Node(nil, nil, nil) for i in range(n)]
depth = [0] * n

for i in range(n):
    line = [int(i) for i in sys.stdin.readline().split()]
    vertex = line[0]

    for (j, c) in enumerate(line[2:]):
        if j == 0:
            tree[vertex].l = c
        else:
            tree[l].r = c

        l = c
        tree[c].p = vertex

'''
for i in range(n):
    print(tree[i].p, tree[i].l, tree[i].r)
'''
for i in range(n):
    if tree[i].p == nil:
        root = i

depth_rec(root, 0, depth)

# print(depth)

for vtx in range(n):
    print("node {}: parent = {}, depth = {}, ".format(vtx, tree[vtx].p, depth[vtx]), end = "")

    if tree[vtx].p == nil:
        print("root, ", end = "")
    elif tree[vtx].l == nil:
        print("leaf, ", end = "")
    else:
        print("internal node, ", end = "")

    children = []
    child = tree[vtx].l

    while child != nil:
        children.append(child)
        child = tree[child].r

    print(children)

### FIXED CODE ###

import sys

nil = -1

def set_depth(v, depth):
    tree[v][2] = depth

    for child in tree[v][1]:
        set_depth(child, depth + 1)

n = int(input())

tree = [[nil, [], 0, 'leaf'] for i in range(n)]

for i in range(n):
    line = [int(i) for i in sys.stdin.readline().split()]
    t_id = line[0]
    children = line[2:]

    tree[t_id][1] = children

    if children:
        tree[t_id][3] = 'internal node'

    for child in children:
        tree[child][0] = t_id

for t_id in range(n):
    if tree[t_id][0] == nil:
        tree[t_id][3] = 'root'
        r = t_id
        break

# print(tree)

set_depth(r, 0)

for t_id in range(n):
    parent = tree[t_id][0]
    depth = tree[t_id][2]
    children = tree[t_id][1]
    type_t = tree[t_id][3]

    print('node {}: parent = {}, depth = {}, {}, {}'.format(
            t_id, parent, depth, type_t, children))
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, x: "List[int]", y: "List[int]"):
    PL = list(zip(x,y))

    mincost = float('inf')
    for seq in itertools.permutations(PL):
        cost = 1
        p = seq[1][0] - seq[0][0]
        q = seq[1][1] - seq[0][1]
        #print(seq)
        for i in range(1,len(seq)):
            p2 = seq[i][0] - seq[i-1][0] 
            q2 = seq[i][1] - seq[i-1][1] 
            #print(p,p2,q,q2)
            if p != p2 or  q != q2:
                cost += 1
        mincost = min(mincost,cost)

    print(mincost)
            


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import itertools
import operator
import collections

def solve(N: int, x: "List[int]", y: "List[int]"):
    if N == 1:
        print(1)
        return

    PL = list(zip(x,y))
    PL.sort(key = operator.itemgetter(0,1))

    pqdic = collections.defaultdict(list)
    for i in range(N-1):
        for j in range(i+1,N):
            p = PL[j][0] - PL[i][0]
            q = PL[j][1] - PL[i][1]
            pqdic[p,q].append((i,j))

    max_pqlen = 0
    for k,v in pqdic.items():
        max_pqlen = max(max_pqlen,len(v))

    print(N - max_pqlen)




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()
N = int(input())
A = list(map(int,input().split()))

def count(N,A):
    for i in range(N):
        print(A.count(i+1))
        A.remove(i+1)
count(N,A)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Ansbox = [0]*(N+1)

def count(N,A,Ansbox):

    for i in range(N- 1):
        Ansbox[A[i] - 1] += 1
        
    for i in range(N):
        print(Ansbox[i])
        
count(N,A,Ansbox)
W,H,x,y=map(int,input().split())
S=W*H/2
ans=0
if x==w/2 and y==h/2:
  ans=1

print(S,ans)


### FIXED CODE ###

W,H,x,y=map(int,input().split())
S=W*H/2
ans=0
if x==W/2 and y==H/2:
  ans=1

print(S,ans)
N = int(input())
K = int(input())
p[N] = int(input().split())

ans = 0
e_sum = 0

for j in range(K):
  e_sum = e_sum + (p[j]+1)/2

ans = e_sum
for i in range(K,N):
  e_sum = e_sum + (p[i]+1)/2
  e_sum = e_sum - (p[i-K]+1)/2
  if ans<e_sum:
    ans=e_sum

print(ans)

### FIXED CODE ###

str_N = input().split()
N = int(str_N[0])
K = int(str_N[1])
str_p = input().split()
p = [float(str_p[i]) for i in range(N)]

ans = 0
e_sum = 0

for j in range(K):
  e_sum = e_sum + (p[j]+1)/2

ans = e_sum
for i in range(K,N):
  e_sum = e_sum + (p[i]+1)/2
  e_sum = e_sum - (p[i-K]+1)/2
  if ans<e_sum:
    ans=e_sum

print(ans)
N,K=map(int,input().split())
S=list(input())
MIN=min(S)

def minimum(S):
    T=S+S[::-1]

    ANS=[]

    for i in range(N+1):
        ANS.append(T[i:i+N])

    return min(ANS)

def next(S):
    T=S+S[::-1]
    LIST=[]
    CL=[0]*2*N
    count=0

    for i in range(2*N):
        if T[i]==MIN:
            count+=1

        else:
            count=0

        CL[i]=count

    MAX=max(CL)
    LIST=[]

    for i in range(N-1,2*N):
        if CL[i]==MAX:
            LIST.append(T[i+1-N:i+1])

    return LIST,MAX

def next2(S,x):
    return S[MAX:]+[MIN]*MAX

if K==1:
    print("".join(minimum(S)))

else:
    CAN,MAX=next(S)

    ANS=[]

    for c in CAN:
        for j in range(K-2):
            c=next2(c,MAX)

            if max(c)==MIN:
                print("".join(c))
                sys.exit()

        ANS.append(minimum(c))

    print("".join(min(ANS)))
        


### FIXED CODE ###

import sys

N,K=map(int,input().split())
S=list(input())
MIN=min(S)

def minimum(S):
    T=S+S[::-1]

    ANS=[]

    for i in range(N+1):
        ANS.append(T[i:i+N])

    return min(ANS)

def next(S):
    T=S+S[::-1]
    LIST=[]
    CL=[0]*2*N
    count=0

    for i in range(2*N):
        if T[i]==MIN:
            count+=1

        else:
            count=0

        CL[i]=count

    MAX=max(CL)
    LIST=[]

    for i in range(N-1,2*N):
        if CL[i]==MAX:
            LIST.append(T[i+1-N:i+1])

    return LIST,MAX

def next2(S,x):
    return [MIN]*x+S[x:][::-1]

if K==1:
    print("".join(minimum(S)))

else:
    CAN,MAX=next(S)

    if (MAX<<(K-1))>=N:
        print(MIN*N)
        sys.exit()

    ANS=[]

    for c in CAN:

        ANS.append(next2(c,MAX*((1<<(K-1))-1)))

    print("".join(min(ANS)))
a,b,c=map(int,input().split())
if c-a-b<=0:
	print("No")
else:
	if 4*a*b<(c-a-b)**2:
    	print("Yes")
    else:
    	print("No")

### FIXED CODE ###

a,b,c=map(int,input().split())
if c-a-b<=0:
	print("No")
else:
	if 4*a*b<(c-a-b)**2:
		print("Yes")
	else:
		print("No")
def main():
    import numpy as np
    import sys
    inf = 100100100
    ans = inf
    H, W, K = map(int, input().split())
    S = [0]*H
    for i in range(H):
        s[i] = sys.stdin.readline().strip()
    S = np.array(S)
    for i in range(2**(H-1)):
        group = [0]
        g = 0
        for j in range(H-1):
            if (i >> j) & 1:
                g += 1
            group.append(g)
        group = np.array(group)
        g += 1
        c = np.array([[0]*W]*g)
        for j in range(H):
            for k in range(W):
                c[group[j],k] += S[j,k]
        num = g-1
        now = np.zeros(g)
        def large(now):
            for n in now:
                if n > K:
                    return True
            else:
                return False
        for k in range(W):
            now += c[:,k]
            if large(now):
                now = c[:,k]
                num += 1
                if large(now):
                    num = inf
                    break
        ans = min(ans, num)
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    import sys
    inf = 100100100
    ans = inf
    H, W, K = map(int, input().split())
    S = [0]*H
    for i in range(H):
        S[i] = [int(x) for x in sys.stdin.readline().strip()]
    for i in range(2**(H-1)):
        group = [0]
        g = 0
        for j in range(H-1):
            if (i >> j) & 1:
                g += 1
            group.append(g)
        g += 1
        c = [[0 for _ in range(W)] for __ in range(g)]
        for j in range(H):
            for k in range(W):
                c[group[j]][k] += S[j][k]
        num = g-1
        now = [0]*g
        def large(now):
            for n in now:
                if n > K:
                    return True
            else:
                return False
        def v_vec(twodlis, k):
            ans = []
            for lis in twodlis:
                ans.append(lis[k])
            return ans
        for k in range(W):
            for n in range(len(now)):
                now[n] = now[n] + v_vec(c,k)[n]
            if large(now):
                now = v_vec(c,k)
                num += 1
                if large(now):
                    num = inf
                    break

        ans = min(ans, num)
    print(ans)

if __name__ == "__main__":
    main()
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)
a = sum([v for i, v in enumerate(c) if i % 2 == 0 ]
b = sum([v for i, v in enumerate(c) if i % 2 == 1 ]
print(a - b)

### FIXED CODE ###

n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)
a = sum([v for i, v in enumerate(c) if i % 2 == 0 ])
b = sum([v for i, v in enumerate(c) if i % 2 == 1 ])
print(a - b)
import math
import sys

n = input()
a = list(map(int, input().split()))
b = sorted(set(a))
if len(b) == 1:
  print(b[0])
  sys.exit()
pl = []
ql = []
for i in b[1:]:
  pl.append(math.gcd(b[0], i))
for i in b[2:]:
  ql.append(math.gcd(b[1], i))
pls = sorted(pl)
qls = sorted(ql)
print(max(pls[1], qls[min(1, len(qls) - 1)]))


### FIXED CODE ###

import math
import itertools

n = int(input())
a = list(map(int, input().split()))
pf = [0]*(n+1)
pb = [0]*(n+1)
p = a[0]
for i in range(n):
  p = math.gcd(p, a[i])
  pf[i+1] = p
p = a[-1]
for i in range(-1, -n-1, -1):
  p = math.gcd(p, a[i])
  pb[i-1] = p
ans = [0]*n
for i in range(n):
  ans[i] = math.gcd(pf[i], pb[i+1])
print(max(ans))
while True:
    a = int(input())
    c = input()
    b = int(input())
    if(c == '+'):
        print(a + b)
    elif(c == '-'):
        print(a - b)
    elif(c == '*'):
        print(a * b)
    elif(c == '/')
        print(a / b)
    else:
        break


### FIXED CODE ###

while True:
    a, b, c = map(str, input().split())
    a = int(a)
    c = int(c)
    if(b == '+'):
        print(a + c)
    elif(b == '-'):
        print(a - c)
    elif(b == '*'):
        print(a * c)
    elif(b == '/'):
        print(a // c)
    else:
        break
s - input()
if s[0] == s[-1]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = input()
if s[0] == s[-1]:
  print("Yes")
else:
  print("No")
import sys
import numpy as np
from numba import njit

input = sys.stdin.buffer.readline

#'''
N = int(input())
vws = [tuple(map(int, input().split())) for _ in range(N)]
'''
N = 2 ** 18
vws = [(1, i%10 + 1) for i in range(N)]
#'''
half = 10

n = min(2**half, N)
vws_arr = np.array(vws)

dp = np.zeros((n, 10**5+1), np.int32)
dp[0, vws[0][1]:] = vws[0][0]
for i in range(1, n):
    v, w = vws[i]
    dp[i] = dp[(i-1)//2]
    dp[i, w:] = np.maximum(dp[(i-1)//2, :-w]+v, dp[i, w:])


@njit("i4(i4[:], i4[:], i4, i4[:])", cache = True)
def func(vs, ws, L, dp_):
    values = np.zeros(len(vs), np.int32)
    weights = np.zeros(len(vs), np.int32)
    for bits in range(1 << len(vs)):
        for i in range(len(vs)):
            if bits & (1 << i):
                values[bits] += vs[i]
                weights[bits] += ws[i]
    mask = (weights <= L)     
    return np.amax(dp_[L - weights[mask]] + values[mask])

Q = int(input())
for _ in range(Q):
    V, L = map(int, input().split())
    V -= 1
    if V < n:
        print(dp[V, L])
    else:
        Vs = []
        while V >= n:
            Vs.append(V)
            V = (V-1) // 2
        vs = vws_arr[Vs, 0]
        ws = vws_arr[Vs, 1]
        print(func(np.array(vs, np.int32), np.array(ws, np.int32), L, dp[V]))


### FIXED CODE ###

import sys
import numpy as np
from numba import njit

input = sys.stdin.buffer.readline

N = int(input())
vws = [tuple(map(int, input().split())) for _ in range(N)]

n = min(2**11, N)
vws_arr = np.array(vws, np.int32)

dp = np.zeros((n, 10**5+1), np.int32)
for i in range(n):
    v, w = vws[i]
    dp[i] = dp[(i-1)//2]
    dp[i, w:] = np.maximum(dp[(i-1)//2, :-w]+v, dp[i, w:])


@njit("i4(i4[::1], i4[::1], i4, i4[::1])", cache = True)
def func(vs, ws, L, dp_):
    values = np.zeros(1 << len(vs), np.int32)
    weights = np.zeros(1 << len(vs), np.int32)
    for i in range(len(vs)):
        for bits in range(1 << len(vs)):
            if bits & (1 << i):
                values[bits] += vs[i]
                weights[bits] += ws[i]
    ret = 0
    for v, w in zip(values, weights):
        if w <= L:
            ret = max(dp_[L - w] + v, ret)
    return ret

Q = int(input())
for _ in range(Q):
    V, L = map(int, input().split())
    V -= 1
    if V < n:
        print(dp[V, L])
    else:
        Vs = []
        while V >= n:
            Vs.append(V)
            V = (V-1) // 2
        vs = vws_arr[Vs, 0]
        ws = vws_arr[Vs, 1]
        print(func(vs, ws, L, dp[V]))
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
def main():
  for i in  range(A):
    if A[i]+1==A[i+1]:
      B[A[i+1]]=B[A[i+1]]+C[i]
  print(sum(B[A[i]])
main()


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
s=0
temp=""
for i in A:
  s+=B[i-1]
  if temp==i-1:
    s+=C[temp-1]
  temp=i
print(s)
n = int(input())
ls = list(map(int, input().split(' ')))
ans = 1
if ls[0] != 0:
    ans = 0
m = max(set(ls))
if m > n:
    ans = 0
# d = {i: ls.count(i) for i in range(m+1)}
d = {}
for l in ls:
    d[l] = d.get(l, 0) + 1
if ans != 0:
    for i in range(1, m+1):
        ans = (ans * (d[i-1] ** d[i]) % 998244353) % 998244353
print(ans)


### FIXED CODE ###

n = int(input())
ls = list(map(int, input().split(' ')))
m = max(set(ls))
d = {}
for l in ls:
    d[l] = d.get(l, 0) + 1
ans = 0 if (ls[0] != 0 or d.get(0) >= 2) else 1
for i in range(1, m+1):
    if i not in d:
        ans = 0
    ans = (ans * (d.get(i-1, 0) ** d.get(i, 0))) % 998244353 
print(ans)
from collections import deque
n, m, k = map(int, input().split())
F = [deque([]) for i in range(n)] #Friend
B = [deque([]) for i in range(n)] #Block
#友達関係
for i in range(m):
    a, b = map(int, input().split())
    F[a-1].append(b)
    F[b-1].append(a)

#ブロック関係
for i in range(k):
    c, d = map(int, input().split())
    B[c-1].append(d)
    B[d-1].append(c)
#print('F=',F)
#print('B=',B)

def using_DFS(p):
    if G[p] == 0:
        G[p] = num
        for j in F[p]:
            using_DFS(j-1)
    else:
        pass

#DFSで連結部分ごとのグループに分ける
G = [0] * n #Group
S = deque([])   #Size
num = 0
for i in range(n):
    if G[i] == 0:
        num += 1
        t = 0
        using_DFS(i)
        S.append(G.count(num))
    else:
        pass
#print('G=',G)
#print('S=',S)

#答えの計算
for i in range(n):
    ans = S[G[i]-1] - 1
    #ブロック関係がこの中で何人いるか
    for j in B[i]:
        if G[j-1] == G[i]:
            ans -= 1
        else:
            pass
    #直接の友達関係がこの中で何人いるか
    for k in F[i]:
        if G[k-1] == G[i]:
            ans -= 1
        else:
            pass
    print(ans)

### FIXED CODE ###

import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n, m, k = map(int, input().split())
    fgraph = [list() for i in range(n)]
    bgraph = [list() for i in range(n)]
    cgraph = [list() for i in range(n)]
    
    rks = [None] *n
    sys.setrecursionlimit(10**9)
    # r: どの連結成分に存在するかをメモするid
    def dfs(graph,s,r):
        if rks[s] is None:
            rks[s] = r
        for i in range(len(graph[s])):
            if rks[graph[s][i]-1] is not None:
                continue
            dfs(graph, graph[s][i]-1,r)

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

    # print(fgraph)
    #print(bgraph)
    # 連結成分に対してid的なindexをつける
    c = -1
    for i in range(n):
        if rks[i] is None:
            c += 1
            dfs(fgraph, i, c)
    
    for i in range(k):
        c,d = map(int, input().split())
        if rks[c-1] == rks[d-1]:
            bgraph[d-1].append(c)
            bgraph[c-1].append(d)

    counter = Counter(rks)
    for i in range(n):
        # counter[rks[i]] 連結成分のサイズ
        # len(fgraph[i]) 友達の数
        # len(bgraph[i]) 連結成分内のブロックの数
        # 1 自分
        print(counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1)

if __name__ == '__main__':
    main()
N , K = map(int,input().split())
S = str(input())

for i in range(1,N+1):
    if i == K :
        S[i] = S[i].lower()
print(S)

### FIXED CODE ###

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

for i in range(1,N+1):
    if i == K :
        S[i-1] = S[i-1].swapcase()
print(''.join(S))
N, K=map(int, input().split())
nums=list()
nums.append(N)
 
while abs(N-K)<N:
    N=abs(N-K)
    nums.append(N)
print(min(nums))

### FIXED CODE ###

A, B, C=map(int, input().split())
print(C,A,B)
# A
s = input()

for i in range(0, len(s), 2):
    if s[i] == 'h' and s[i+1] == 'i':
        bool = True
    else:
        bool = False
        break
        
print('Yes' if bool else 'No')

### FIXED CODE ###

# A 
s = input()

for i in range(0, len(s), 2):
    if len(s)%2 == 1:
        bool = False
        break
    elif s[i] == 'h' and s[i+1] == 'i':
        bool = True
    else:
        bool = False
        break
        
print('Yes' if bool else 'No')
from collections import deque
N, u, v = map(int, input().split())

G = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)


def bfs(s):
    dist = [-1] * (N + 1)
    dist[s] = 0
    d = deque([s])
    while len(d) > 0:
        v = d.popleft()
        for w in edge[v]:
            if dist[w] < 0:
                dist[w] = dist[v] + 1
                d.append(w)
    return dist


tkhs = bfs(u)
aok = bfs(v)
ans = 0
for i in range(1, N + 1):
    if tkhs[i] < aok[i]:
        ans = max(ans, aok[i] - 1)
print(ans)


### FIXED CODE ###

from collections import deque
N, u, v = map(int, input().split())

G = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)


def bfs(s):
    dist = [-1] * (N + 1)
    dist[s] = 0
    d = deque([s])
    while len(d) > 0:
        v = d.popleft()
        for w in G[v]:
            if dist[w] < 0:
                dist[w] = dist[v] + 1
                d.append(w)
    return dist


tkhs = bfs(u)
aok = bfs(v)
ans = 0
for i in range(1, N + 1):
    if tkhs[i] < aok[i]:
        ans = max(ans, aok[i] - 1)
print(ans)
a,b = int(input().split())
a*b


### FIXED CODE ###

a,b = (int(x) for x in input().split())
print(a*b)
print("YES" if int(input().replace(" ","")%4==0 else "NO)

### FIXED CODE ###

print("YES" if int(input().replace(" ",""))%4==0 else "NO")
def A(lst,hand):
    if len(lst) == 0:
        return
    else:
        return lst.pop(0)

def B(lst,hand):
    if len(lst) == 0:
        return
    else:
        return lst.pop(len(lst)-1)

def C(lst,hand):
    if len(hand) == 0:
        return
    else:
        lst.insert(0 , hand.pop( hand.index(min(hand)) ))

def D(lst,hand):
    if len(hand) == 0:
        return
    else:
        lst.append(hand.pop( hand.index(min(hand))) )

import random

if __name__ == "__main__":
    N,K = map(int, input().split())
    V = input().split()
    V = [int(i) for i in V]
    hand = []

    for l in range(10000):
        V_copy = [i for i in V]
        hand_copy = []
        for i in range(K):
            rand = random.randint(1,4)
            if rand == 1:
                hand_copy.append(A(V_copy,hand_copy))
            elif rand == 2:
                hand_copy.append(B(V_copy,hand_copy))
            elif rand == 3:
                C(V_copy,hand_copy)
            else:
                D(V_copy,hand_copy)
        hand.append(hand_copy)

    x = []
    for i in range(10000):
        x.append(sum(hand[i]))
    print(max(x))

### FIXED CODE ###

def MAP(): return map(int,input().split())

n,k = MAP()
*v, = MAP()

operation = min(n,k) #取り出すMAX回数
ans=0

for i in range(1,operation+1):
    for j in range(i+1):
        A = j   #左側から取り出す回数
        B = i-j    #右側から取り出す回数
        t = v[:A]
        if B>0:
            t+=v[-B:]
        t.sort()

        l = min(k-i,i-1)
        for ll in range(l):
            if t[ll] >= 0:
                l = ll
                break
        s = sum(t[l:])
        ans = max(ans,s)

print(ans)
import math

L, R = list(map(int, input().split()))
data = [x for x in range(L, R+1)]
len_data = [x for x in range(len(data))]
mod_min = math.inf

for i in reversed(len_data):
    for j in range(i):
        mod = (data[i] * data[j]) % 2019
        mod_min = mod if mod_min > mod else mod_min

print(mod_min)

### FIXED CODE ###

l, r = list(map(int,input().split()))

if r - l >= 2019:
  print(0)
  
else:
  ll = l % 2019
  rr = r % 2019
  if rr < ll:
    print(0)
    
  else:
    keep = 2020
    for i in range(ll, rr+1):
      for j in range(i+1, rr+1):
        keep = min((i*j)%2019, keep)
    print(keep)
def solve():
    N = int(input())
    p = list(map(int, input().split()))
    count = int(0)
    for i in range(N):
        if p[i] == i+1:
            p[i], p[i+1] = p[i+1], p[i]
            count += 1
    print(count)

if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve():
    N = int(input())
    p = list(map(int, input().split()))
    count = int(0)
    for i in range(N):
        if p[i] == i+1:
            if i+1 == N:
                p[i], p[i - 1] = p[i - 1], p[i]
                count += 1
            else:
                p[i], p[i+1] = p[i+1], p[i]
                count += 1
    print(count)

if __name__ == '__main__':
    solve()
n,l = map(int,input().split())
t = list(l + i - 1) for i in range(1,n)

if min(t) > 0:
    p = sum(t) - l
elif max(t) > 0:
    p = sum(t)
else:
    p = sum(t) - max(t)
print(p)

### FIXED CODE ###

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

t = [(l + i - 1) for i in range(1,n + 1)]

if t[0] >= 0:
    p = sum(t) - l
elif t[-1] > 0:
    p = sum(t)
else:
    p = sum(t) - t[-1]

print(p)
from fractions import math

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

def lcm(a, b):
    return (a * b) // fractions.gcd(a, b)

print(lcm(a, b))

### FIXED CODE ###

import fractions
a, b = map(int, input().split())

def lcm(a,b):
    return (a*b)//fractions.gcd(a,b)

print(lcm(a,b))
S=input()
T=input()
int(ans)=0
if S[0]==T[0]:
	ans += 1
if S[1]==T[1]:
	ans += 1
if S[2]==T[2]:
	ans += 1
ans

### FIXED CODE ###

S=input()
T=input()
ans=0
if S[0]==T[0]:
    ans+=1
if S[1]==T[1]:
    ans+=1
if S[2]==T[2]:
    ans+=1
print(ans)