Harryxun/stf_run huggingface dataset:
Source code
Copy
task =  [int (i) for i in input.split(" ")]
ans=5000
if abs(task[0]-task[1])+abs(task[2]-task[0]) < ans:
	ans = abs(task[0]-task[1])+abs(task[2]-task[0])
if abs(task[0]-task[2])+abs(task[1]-task[0]) < ans:
	ans = abs(task[0]-task[2])+abs(task[1]-task[0])
if abs(task[1]-task[0])+abs(task[2]-task[1]) < ans:
	ans = abs(task[1]-task[0])+abs(task[2]-task[1])
if abs(task[1]-task[2])+abs(task[0]-task[1]) < ans:
	ans = abs(task[1]-task[2])+abs(task[0]-task[1])
if abs(task[2]-task[0])+abs(task[1]-task[2]) < ans:
	ans = abs(task[2]-task[0])+abs(task[1]-task[2])
if abs(task[2]-task[1])+abs(task[0]-task[2]) < ans:
	ans = abs(task[2]-task[1])+abs(task[0]-task[2])
print(ans)

### FIXED CODE ###

task = input().split(" ")
ans = 5000
if abs ( int(task [ 0 ]) - int(task [ 1 ])) + abs ( int(task [ 2 ]) - int(task [ 0 ])) < ans : 
	ans = abs ( int(task [ 0 ]) - int(task [ 1 ])) + abs ( int(task [ 2 ]) - int(task [ 0 ]))
if abs ( int(task [ 0 ]) - int(task [ 2 ])) + abs ( int(task [ 1 ]) - int(task [ 0 ])) < ans : 
	ans = abs ( int(task [ 0 ]) - int(task [ 2 ])) + abs ( int(task [ 1 ]) - int(task [ 0 ]))
if abs ( int(task [ 1 ]) - int(task [ 0 ])) + abs ( int(task [ 2 ]) - int(task [ 1 ])) < ans : 
	ans = abs ( int(task [ 1 ]) - int(task [ 0 ])) + abs ( int(task [ 2 ]) - int(task [ 1 ]))
if abs ( int(task [ 1 ]) - int(task [ 2 ])) + abs ( int(task [ 0 ]) - int(task [ 1 ])) < ans : 
	ans = abs ( int(task [ 1 ]) - int(task [ 2 ])) + abs ( int(task [ 0 ]) - int(task [ 1 ]))
if abs ( int(task [ 2 ]) - int(task [ 0 ])) + abs ( int(task [ 1 ]) - int(task [ 2 ])) < ans : 
	ans = abs ( int(task [ 2 ]) - int(task [ 0 ])) + abs ( int(task [ 1 ]) - int(task [ 2 ]))
if abs ( int(task [ 2 ]) - int(task [ 1 ])) + abs ( int(task [ 0 ]) - int(task [ 2 ])) < ans : 
	ans = abs ( int(task [ 2 ]) - int(task [ 1 ])) + abs ( int(task [ 0 ]) - int(task [ 2 ]))
print ( ans )
import math
N = int(input())
X = list(map(int,input().split()))
med = int(sum(X)/N + 0.5)
c = 0
for i in range(N):
  c += (X[i] - med)**2
print(c)


### FIXED CODE ###

n,r = map(int, input().split())
 
if n >= 10:
  print(r)
else:
  print(r + 100 * (10-n))
N,K=map(int,input().split())
A=list(map(int,input().split()))
flag=0
now=0
i=0
count=0
c=[0]*N
r=[0]
c[0]=1
while flag==0:
  now=A[now]-1
  count+=1
  if count==K:
    flag=1
  elif c[now]==1:
    flag=2
  c[now]=1
  r.append(now)
print(r)
if flag==1:
  print(now+1)
else:
  o=[i for i, x in enumerate(r) if x == now]
  print(A[r[K%(o[1]-o[0])]+o[0]-1])

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
flag=0
now=0
i=0
count=0
c=[0]*N
r=[0]
c[0]=1
while flag==0:
  now=A[now]-1
  count+=1
  if count==K:
    flag=1
  elif c[now]==1:
    flag=2
  c[now]=1
  r.append(now)
if flag==1:
  print(now+1)
else:
  o=[i for i, x in enumerate(r) if x == now]
  print(r[(K-o[0])%(o[1]-o[0])+o[0]]+1)
today = input()

if today = "Sunny":
  tomorrow = "Cloudy"
elseif today = "Cloudy":
  tomorrow = "Rainy"
else:
  tomorrow = "Rainy"

output(tomorrow)

### FIXED CODE ###

today = input()
 
if today == "Sunny":
  tomorrow = "Cloudy"
elif today == "Cloudy":
  tomorrow = "Rainy"
else:
  tomorrow = "Sunny"
 
print(tomorrow)
a,b=int(input().split())
if a<b:
    print("a<b")
elif a==b:
    print("a=b")
else:
    print("a>b")

### FIXED CODE ###

a,b=map(int,input().split())
if a > b:
  print("a > b")
elif a < b:
  print("a < b")
else:
  print("a == b")
S = input()
K = int(input())


def main():
    if S[0] != '1':
        print(S[0])
        return

    i = 0
    while S[i] == '1':
        i += 1

    if K < i:
        print('1')
        return

    print(S[i])


if __name__ == '__main__':
    main()


### FIXED CODE ###

S = input()
K = input()
if len(K) > 100:
    K = 110
else:
    K = int(K)


def main():
    if S[0] != '1':
        print(S[0])
        return

    for i in range(len(S)):
        if S[i] != '1':
            break

    if i == len(S) - 1:
        print('1')
        return

    if K <= i:
        print('1')
        return

    print(S[i])


if __name__ == '__main__':
    main()
a,b,c = map(int,input.split())


print(c-(a-b))

### FIXED CODE ###

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


if c-(a-b) >= 0:
    print(c-(a-b))
else:
    print("0")
import math
A,B = map(int,input().split())
a = A / 0.08
b = B / 0.1
if math.floor(a * 0.1) == B:
    ans = int(a)
elif math.floor(b * 0.08) == A:
    ans = int(b)
else:
    print(-1)
    exit()
if (math.floor((ans-1)*0.08) == A) and (math.floor((ans-1)*0.1) == B):
    ans = ans - 1
else:
    print(ans)

### FIXED CODE ###

N,A,B = map(int,input().split())
if A == 0:
    print(A)
    exit()
n = N // (A + B)
nn = N % (A + B)
if n != 0 and nn <= A:
    print(int(A*n + nn))
elif n != 0 and nn > A:
    print(int(A*(n+1)))
elif n == 0 and N >= A:
    print(A)
elif n == 0 and N < A:
    print(N)
p = str(input())
s = list(p)
k = int(input())

zisyo = []
for i in range(len(s)):
    count = 0
    st = s[i]
    zisyo.append(st)
    
    while count <= n:
        count = count + 1
        try:
            st = st + s[i + count]
            zisyo.append(st)
        except:
            pass
    
zisyosort = list(sorted(list(set(zisyo))))
print(zisyosort[k-1])

### FIXED CODE ###


s = str(input())
k = int(input())
kouho = [s]

for i in range(len(s)):
    for plus in range(k+1):
        st = s[i:i + plus]
        kouho.append(st)
so = list(sorted(set(kouho)))
if '' in so:
    so.remove('')
    
print(so[k-1])
import sys
import collections

N = int(input())
A_i = list(map(int, input().split()))
A_i = [i for i in A_i if 1 <= i and i <= 10**9]

if not 2 <= N or not N <= 2*10**5:
    print("error:N")
    sys.exit()

if len(collections.Counter(A_i)) == len(A_i):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import sys

Ball = list(map(str, input().split()))
Quantity = list(map(int,input().split()))
U = str(input())

S = Ball[0]
T = Ball[1]
A = Quantity[0]
B = Quantity[1]

if not 1 <= len(S) or not len(S) <= 10:
    print("error:S_length")
    sys.exit()    
if not 1 <= len(T) or not len(T) <= 10:
    print("error:T_length")
    sys.exit()   
if S == T:
    print("error:S==T")
    sys.exit()
if S != U and T != U:
    print("error:S=U or S=T")
    sys.exit()
if not 1<= A or not B <= 10:
    print("error:A,B")
    sys.exit()

if U == S:
    A -= 1
if U == T:
    B -= 1
print(A,B)
A, B, C, D, E, F =  map(int, input().split())
M = 0
for i in range(F // 100 // A + 1):
	for j in range((F - 100 * A * i) // 100 // B + 1):
		w = 100 * A * i + 100 * B * j
		if w == 0:
			break
		for k in range((F - w) // C + 1):
			for l in range((F - w - C * k) // D + 1):
				s = C * k + D * l
				if E >= 100 * s / w and 100 * s / w > M:
					M = 100 * s / w
					X = [w + s, s]
print(X[0], X[1])


### FIXED CODE ###

A, B, C, D, E, F =  map(int, input().split())
M = 0
for i in range(F // 100 // A + 1):
	for j in range((F - 100 * A * i) // 100 // B + 1):
		w = 100 * A * i + 100 * B * j
		if w == 0:
			break
		for k in range((F - w) // C + 1):
			for l in range((F - w - C * k) // D + 1):
				s = C * k + D * l
				if E >= 100 * s / w and 100 * s / w >= M:
					M = 100 * s / w
					X = [w + s, s]
print(X[0], X[1])
a, b, t = map(int, input().split)
print(b*(t//a))

### FIXED CODE ###

a, b, t = map(int, input().split())
print(b*(t//a))
from collections import deque
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
ans = 0

def bfs(y,x,m):
  g = [[None if S[i][j] == '.' else -1 for j in range(W)] for i in range(H)]
  g[y][x] = 0
  q = deque()
  q.append((y,x))
  while q:
    i,j = q.popleft()
    for di,dj in ((0,1),(1,0),(-1,0),(0,-1)):
      ni = i+di; nj = j+dj
      if 0 <= ni < H and 0 <= nj < W and g[ni][nj] is None:
        g[ni][nj] = g[i][j] + 1
        q.append((ni,nj))
  return max(max(r) for r in g)

for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      deq = bfs(i,j,S)
      if ans < deq:
        ans = deq
print(ans)

### FIXED CODE ###

from collections import deque
H,W = map(int,input().split())
l = [str(input()) for _ in range(H)]
white_count = 0
for s in l:
  white_count += s.count('.')
sy = 0
sx = 0
gy = H-1
gx = W-1
visited = [[-1]*W for _ in range(H)]
visited[sy][sx] = 0
Q = deque([[sy,sx]])
while Q:
  y,x = Q.popleft()
  if [y,x] == [gy,gx]:
    print(white_count - visited[y][x] - 1)
    exit()
  for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
    if 0 <= x+j < W and 0 <= y+i < H and visited[y+i][x+j] == -1 and l[y+i][x+j] == '.':
      visited[y+i][x+j] = visited[y][x]+1
      Q.append([y+i,x+j])
    else:
      continue
print(-1)
S = input()
N = len(S)
ans = [0] * N
index = 0
rcount = 0
lcount = 0
for i in range(N):
    if S[i] == 'R' and S[i+1] == 'R':
        rcount += 1
    if S[i] == 'L' and S[i+1] == 'L':
        lcount += 1
    if S[i] == 'R' and S[i+1] == 'L':
        if lcount != 0:
            ans[index] += lcount // 2 + lcount % 2
            ans[index + 1] += lcount // 2
            lcount = 0
        index = i
        ans[i] = 1
        ans[i+1] = 1
        if rcount != 0:
            ans[i] += rcount // 2
            ans[i+1] += rcount // 2 + rcount % 2
            rcount = 0
        i += 1
if lcount != 0:
    ans[index] += lcount // 2 + lcount % 2
    ans[index + 1] += lcount // 2
    lcount = 0

for i in range(N):
    print(ans[i])

### FIXED CODE ###

S = input()
N = len(S)
 
ans = [0] * N
 
index = 0
lcount = 0
rcount = 0
for i in range(N):
    if S[i] == 'R' and S[i + 1] == 'R':
        rcount += 1
    if S[i] == 'L' and S[i - 1] == 'L':
        lcount += 1
    if S[i] == 'R' and S[i + 1] == 'L':
        if lcount != 0:
            ans[index] += lcount // 2 + lcount % 2
            ans[index + 1] += lcount // 2
            lcount = 0
        index = i
        ans[i] = 1
        ans[i + 1] = 1
        if rcount != 0:
            ans[i] += rcount // 2
            ans[i + 1] += rcount // 2 + rcount % 2
            rcount = 0
        i += 1
if lcount != 0:
    ans[index] += lcount // 2 + lcount % 2
    ans[index + 1] += lcount // 2
    lcount = 0
    
for i in range(N):
    print(ans[i], end=" ")
N=int(input())
A=list(int,input().split())
cnt=0

while all(i%2 == 0 for i in A):
  A = [i/2 for i in A]
  cnt+=1
print(cnt)


### FIXED CODE ###

input()

A = list(map(int, input().split(" ")))
B = 0

while all(a%2 == 0 for a in A):
  A = [a/2 for a in A]
  B += 1

print(B)
h,w = tuple(map(int,input().split()))

s = [input() for_ in range(h)]

for s_i in s:
  print(s_i)
  print(s_i)
  


### FIXED CODE ###

h,w = tuple(map(int,input().split()))

s = [input() for _ in range(h)]

for s_i in s:
  print(s_i)
  print(s_i)
N = int(input())

dic = set()
for i in range(N):
    dic.add(str(input()))

dic.sort()

for i in list(dic):
    print(i)

### FIXED CODE ###

N = int(input())


inin = []
for i in range(N):
    inin.append(str(input()))
    
dic = {}
for i in inin:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] = dic[i]+1

l = dic.items()
max = 0
for i in l:
    if i[1] > max:
        max = i[1]

result = []
for i in l:
    if i[1] == max:
        result.append(i[0])

result.sort()

for i in result:
    print(i)
import numpy as np

N, M = map(int, input().split())
stairs_exist = np.ones(N+1)

for c in range(M):
    stairs_exist[int(input())] = 0
    
steps = np.zeros(N+1)
steps[0] = 1
for i in range(N):
    for j in range(i+1, min(N+1, i+3)):
        if stairs_exist[j]:
            steps[j] += steps[i]
            
print(int(steps[-1] % (10 ** 9 + 7)))

### FIXED CODE ###

N, M=map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10**9 + 7
step = [1]*(N+1)

for a in A:
    step[a]=0
for i in range(2, N+1):
    step[i]=(step[i-1]+step[i-2])%mod*step[i]
print(step[-1])
#abc133 c
from fractions import gcd
a,b,c,d=map(int,input().split())

def gcd(x,y):
    if y==0:
        return x
    return gcd(y,x%y)


def lcm(x,y):
    return (x*y)//gcd(x,y)

e=lcm(c,d) #c,dの最小公倍数

def kosu(num):
    z=num
    nc=num//c)
    nd=num//d)
    ne=num//e
    return z-nc-nd+ne

ans=kosu(b)-kosu(a-1)

print(ans)


### FIXED CODE ###

#abc133 c
a,b,c,d=map(int,input().split())

def gcd(x,y):
    if y==0:
        return x
    return gcd(y,x%y)


def lcm(x,y):
    return (x*y)//gcd(x,y)

e=lcm(c,d) #c,dの最小公倍数

def kosu(num):
    z=num
    nc=num//c
    nd=num//d
    ne=num//e
    return z-nc-nd+ne

ans=kosu(b)-kosu(a-1)

print(ans)
N = int(input())
data = input().split()

output = int(max(data)) - int(min(data))
print(output)

### FIXED CODE ###

r, g, b = map(int, input().split())
rgb = r * 100 + g * 10 + b
if rgb % 4 == 0:
    output = "YES"
else:
    output = "NO"
print(output)
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())

for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n+1):#各行を縦方向に比較
            if b[k] != a[i][j:j+n]:
                break
            flag = True

if flag:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())
flag = False
for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n):#各行を1行ずつ比較
            if b[k] != a[i+k][j:j+n]:
                break
        else:
            flag = True
if flag:
    print('Yes')
else:
    print('No')
while 1:
  x = map(int, raw_input().split())
  if x == 0:
    break
  x.sort()
  print "%d %d" % (x[0], x[1])

### FIXED CODE ###

while 1:
  x = map(int, raw_input().split())
  if x[0] == 0 and x[1] == 0:
    break
  x.sort()
  print "%d %d" % (x[0], x[1])
r = int(input())
if 0 <= r and r < 1200:
    print('ABC')
elif 1200 <= r and r < 2800:
    print('ARC')
elif 2800 <= r and r < 4208:
    print('AGC')
else:
    raise ValueError


### FIXED CODE ###

r = int(input())
if 0 <= r and r < 1200:
    print('ABC')
elif 1200 <= r and r < 2800:
    print('ARC')
elif 2800 <= r and r <= 4208:
    print('AGC')
else:
    raise ValueError
# 2019-11-28 02:28:10(JST)
import sys

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

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

def main():
    n, m = map(int, sys.stdin.readline().split())
    s, t = sys.stdin.read().split()

    g = gcd(n, m)
    l = lcm(n, m)

    if g == 1:
        if s[0] == s[1]:
            ans = l
        else:
            ans = -1
    else:
        for i in range(g):
            if s[i * n // g] == t[i * m // g]:
                continue
            else:
                ans = -1
                break
        else:
            ans = l
    
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

# 2019-11-28 02:28:10(JST)
import sys

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

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

def main():
    n, m = map(int, sys.stdin.readline().split())
    s, t = sys.stdin.read().split()

    g = gcd(n, m)
    l = lcm(n, m)

    if g == 1:
        if s[0] == t[0]:
            ans = l
        else:
            ans = -1
    else:
        for i in range(g):
            if s[i * n // g] == t[i * m // g]:
                continue
            else:
                ans = -1
                break
        else:
            ans = l
    
    print(ans)

if __name__ == '__main__':
    main()
S = input()

if S[0] == "Y" and S[1] == "A" and S[2] == "K" and S[3] == "I":
    print("Yes")
else:
    print("No")


### FIXED CODE ###

S = input()

if S[:4] == "YAKI":
    print("Yes")
else:
    print("No")
s=input()
t=input()
ans=[]
for i in range(len(s)):
  s.insert(0,s.pop())
  s=''.join(s)
  m=[]
  flag=True
  for j in range(len(t)):
    if s[j]=='?' or t[j]==s[j]:
      m.append(t[j])
    else:
      flag=False
      break
  if flag:
    for j in range(len(t),len(s)):
      if s[j]=='?':
        m.append(a)
      else:
        m.append(s[j])
    ans.append(''.join(m))
ans.sort()
if len(ans)>0:
  print(ans[0])
else:
  print('UNRESTORABLE')

### FIXED CODE ###

s=input()
t=input()
ans=[]
for i in range(0,len(s)-len(t)+1):
  m=[]
  flag=True
  for p in range(i):
    if s[p]=='?':
      m.append('a')
    else:
      m.append(s[p])
  for q in range(i,len(t)+i):
    if s[q]=='?' or s[q]==t[q-i]:
      m.append(t[q-i])
    else:
      flag=False
      break
  for r in range(len(t)+i,len(s)):
    if flag==False:
      break
    if s[r]=='?':
      m.append('a')
    else:
      m.append(s[r])
  if flag:
    ans.append("".join(m))
ans.sort()
if len(ans)>0:
  print(ans[0])
else:
  print('UNRESTORABLE')
X = int(input())

A = 0
B = 0
test = 10**3
for i in range(-test, test):
	a = (X + i**5)**0.2
	if type(a) == float:
		if round(a, 10).is_integer():
			# print(int(a), i)
			A, B = int(a), i
			break
print(A, B)

### FIXED CODE ###

S = input()

if "B" in S:
  print(S.replace("B", "R"))
elif "R" in S:
  print(S.replace("R", "B"))
def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr
    
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,M
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            while B_sum_arr[j] >= (K - A_sum_arr[i]):
                j -= 1
        count = max(count,(i+j))
    return count

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    print(get_max_book_num(A,B,K))
    


### FIXED CODE ###

def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr

def get_max_b(left_time,j,B_sum_arr):
    # [0,1,2,3,4,5]
    while B_sum_arr[j] > left_time and j > 0:
        j -= 1
    return j
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,len(B_sum_arr)-1
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            left_time = K - A_sum_arr[i]
            j = get_max_b(left_time,j,B_sum_arr)
        count = max(count,(i+j))
    return count
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    print(get_max_book_num(A,B,K))
n,a,b = (int(input()) for i in range(3))
t=0
for i in range(1,n+1):
    orign=i
    total = 0
    for ii in range(len(str(i))):
        total += i%10
        i=int(i/10)
    if total>=a and total<=b:
        t+=orign
print(t)

### FIXED CODE ###

n,a,b = map(int, input().split())
t=0
for i in range(1,n+1):
    orign=i
    total = 0
    for ii in range(len(str(i))):
        total += i%10
        i=int(i/10)
    if total>=a and total<=b:
        t+=orign
print(t)
import collections 
while 1:
    n,m= list(map(int,input().split(' ')))
    if n == m ==0:break
    D = collections.deque()
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        if p_i !=0: 
            D.append((d_i,p_i))
    sorted(D,key = lambda x:x[0])
    while m > 0:
        temp = D.popleft()
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
            D.append(temp)
        else: 
            m -= temp[0]
            temp = (0,temp[1])
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)


### FIXED CODE ###

while 1:
    n,m= list(map(int,input().split(' ')))
    if n == m ==0:break
    D = []
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    D = sorted(D,key = lambda x:x[1],reverse = True)
    while m > 0:
        if len(D) ==0:break
        temp = D.pop(0)
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
            D.append(temp)
        else: 
            m -= temp[0]      
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)
N = int(input())
P = [int(i) for i in input().split()]

ans = 0
for i,p in enumerate(P):
    if p == i+1:
#         print('i+1,p',i+1,p)
        tmp0 = P[i+1]
        P[i] = tmp0
        P[i+1] = p
        ans += 1
#         print('P',P)
print(ans)

### FIXED CODE ###

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

ans = 0
for i,p in enumerate(P):
    if p == i+1:
        if i + 1 < N:
#             print('i+1,p',i+1,p)
            tmp0 = P[i+1]
            P[i] = tmp0
            P[i+1] = p
            ans += 1
#             print('P',P)
        else:
            ans += 1
print(ans)
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]

S.sort()
ptint('a')
ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)
      
  

### FIXED CODE ###

def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = [0]*N

for n in range(N):
  s = str(input())
  S[n] = encode(s)

S.sort()

ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)
n = str(input())
sum = 0
for i in range(len(n)):
    sum += int(n[i])
if n%sum==0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n = str(input())
sum = 0
for i in range(len(n)):
    sum += int(n[i])
if int(n)%sum==0:
    print('Yes')
else:
    print('No')
c=[]
w=0
for i in range(3):
    c.append(list(map(int,input().split())))
N=int(input())
d=[]
for y in range(N):
    d.append(int(input()))
for n in d:
    for p in c:
        for j in p:
            if n in j:
                j=0
for t in c:
    for h in t:
        if c.count(0)==3:
            o=1
            break
    else:
        continue
    break
for v in range(3):
    w=0
    for k in c:
        if k[v]==0:
            w+=1
        if w==3:
            o=1
w=0
for ji in range(3):
    if c[ji][ji]==0:
        w+=1
    if w==3:
        o=1
w=0
for ji2 in range(3):
    if c[ji2][3-ji2]==0:
        w+=1
    if w==3:
        o=1
for v1 in range(3):
    w=0
    for k in range(3):
        if c[k][v1]==0:
            w+=1
        if w==3:
            o=1

if o==1:
    print("Yes")
else:
    print("No")











### FIXED CODE ###

p1=list(map(int,input().split()))
p2=list(map(int,input().split()))
p3=list(map(int,input().split()))
p=p1+p2+p3
n=int(input())
for _ in range(n):
    b=int(input())
    if b in p:
        p[p.index(b)]=0
if p[0]+p[1]+p[2]==0 or p[3]+p[4]+p[5]==0 or p[6]+p[7]+p[8]==0 or p[0]+p[3]+p[6]==0 or p[1]+p[4]+p[7]==0 or p[2]+p[5]+p[8]==0 or p[0]+p[4]+p[8]==0 or p[2]+p[4]+p[6]==0:
    print("Yes")
else:
    print("No")
import numpy as np
n,m,x=map(int,input().split())
MAX=9999999999

c=[]
a=[]
for i in range(n):
    ca=list(map(int,input().split()))
    c.append(ca[0])
    a.append(ca[1:])

c=np.array(c)
a=np.array(a)

pat=2**n
ans=MAX
for i in range(pat):
    pat_i=bin(i)[2:].zfill(3)
    ai=np.array([0 for _ in range(m)])
    ansi=0

    for j in range(len(pat_i)):
        if(pat_i[j]=='1'):
            ansi+=c[j]
            ai+=a[j]

    if(min(ai)>=x):
        ans=min(ans,ansi)

if(ans!=MAX):
    print(ans)
else:
    print(-1)

### FIXED CODE ###

import numpy as np
n,m,x=map(int,input().split())
MAX=9999999999

c=[]
a=[]
for i in range(n):
    ca=list(map(int,input().split()))
    c.append(ca[0])
    a.append(ca[1:])

c=np.array(c)
a=np.array(a)

pat=2**n
ans=MAX
for i in range(pat):
    pat_i=bin(i)[2:].zfill(n)
    ai=np.array([0 for _ in range(m)])
    ansi=0

    for j in range(len(pat_i)):
        if(pat_i[j]=='1'):
            ansi+=c[j]
            ai+=a[j]

    if(min(ai)>=x):
        ans=min(ans,ansi)

if(ans!=MAX):
    print(ans)
else:
    print(-1)
N,K,X,Y =[int(input()) for _ in range(4)]

if N > K:
  A = X*K + Y*(N-K)
elif:
  A = X*N
print(A)

### FIXED CODE ###

N,K,X,Y =[int(input()) for _ in range(4)]

if N > K:
  A = X*K + Y*(N-K)
else:
  A = X*N
print(A)