Harryxun/stf_run huggingface dataset:
def main():
    h, w = input_int_list()
    grid = []
    grid.append(["@"] * (w + 2))
    for _ in range(h):
        grid.append(["@"] + list(input()) + ["@"])
    grid.append(["@"] * (w + 2))

    # 幅優先探索で すべてを"#"に変える。
    # かかった手数分が答え
    cnt = 1
    direction = ((0, 1), (1, 0), (-1, 0), (0, -1))
    while True:
        do_swap = False
        # print("=====")
        # for line in grid:
        #     print(*line)
        for i in range(1, h + 1):
            for j in range(1, w + 1):
                if grid[i][j] == "#" or grid[i][j] == cnt - 1:
                    for di, dj in direction:
                        if grid[i + di][j + dj] == ".":
                            do_swap = True
                            grid[i + di][j + dj] = cnt
                    grid[i][j] = "@"
        if do_swap:
            cnt += 1
        else:
            break

    print(cnt - 1)

    return


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    from collections import deque

    h, w = input_int_list()
    grid = []
    visited = []
    grid.append(["@"] * (w + 2))
    visited.append([True] * (w + 2))
    for _ in range(h):
        grid.append(["@"] + list(input()) + ["@"])
        visited.append([True] + [False] * w + [True])
    grid.append(["@"] * (w + 2))
    visited.append([True] * (w + 2))

    # 幅優先探索で すべてを"#"に変える。
    # かかった手数分が答え
    direction = ((0, 1), (1, 0), (-1, 0), (0, -1))
    dq = deque()
    # すべての"#"をdequeに入れる
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if grid[i][j] == "#":
                dq.append((i, j, 0))
                visited[i][j] = True
    ans = 0
    # 幅優先探索
    while dq:
        i, j, d = dq.popleft()
        for di, dj in direction:
            if grid[i + di][j + dj] == "." and not visited[i + di][j + dj]:
                dq.append((i + di, j + dj, d + 1))
                visited[i + di][j + dj] = True
                ans = max(ans, d + 1)

    print(ans)
    return


if __name__ == "__main__":
    main()
a, b = map(int, input().split())
c = a * b
if c%2 == 0:
  print(Even)
else:
  print(Odd)

### FIXED CODE ###

a, b = map(int, input().split())
c = a * b
if c%2 == 0:
  print("Even")
else:
  print("Odd")
n=int(input())
high=list(map(int,input().split()))
ans=[]
count=0
answer=[]
for i in range(n-1):
    ans.append(high[i]-high[i+1])
k=0
while k<=n-1:
    if ans[k]>=0:
        count+=1
        k+=1
    else:
        answer.append(count)
        count=0
        k+=1
        
print(max(answer))

### FIXED CODE ###

n=int(input())
high=list(map(int,input().split()))
ans=[]
count=0
MaxC=0
for k in range(n-1):
    if high[k]>=high[k+1]:
        count+=1
        MaxC=max(MaxC,count)
    else:
        count=0
print(MaxC)
a,b,k = map(int, input().split())


A = []

B = []


for i in range (1,a+1):

	if(a % i == 0):

		A.append(i)


for j in range (1,b+1):

	if(a % i == 0):

		B.append(j)


G = set(A) and set(B)


G.reverse()



print(G[k])







### FIXED CODE ###

a,b,k = map(int, input().split())
count = 0
for i in range (min(a,b),0,-1):
	if a % i == 0 and b % i == 0:
		count += 1
		d = i;
	if count == k:
		print(d)
		break
H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
S = [input() for _ in range(H)]

grid = [[0 for _ in range(W)] for _ in range(H)]
grid[Ch][Cw] = 1

stack1 = [(Ch, Cw)]
stack2 = []

answer = 0

while 1:
    while stack1:
        sh, sw = stack1.pop()
        stack2.append((sh, sw))
        for i, j in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
            nh, nw = sh + i, sw + j
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] != "#" and grid[nh][nw] == 0:
                if nh == Dh and nw == Dw:
                    print(answer)
                    exit()
                grid[nh][nw] = 1
                stack1.append((nh, nw))
    answer += 1

    while stack2:
        sh, sw = stack2.pop()
        for i in range(-2, 3):
            for j in range(-2, 3):
                nh, nw = sh + i, sw + j
                if 0 <= nh < H and 0 <= nw < W and S[nh][nw] != "#" and grid[nh][nw] == 0:
                    if nh == Dh and nw == Dw:
                        print(answer)
                        exit()
                    grid[nh][nw] = 1
                    stack1.append((nh, nw))
    if !stack1:
        print(-1)
        exit()

### FIXED CODE ###

from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
S = [input() for _ in range(H)]

Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

grid = [[0 for _ in range(W)] for _ in range(H)]
grid[Ch][Cw] = 1

stack1 = [(Ch, Cw)]
stack2 = []

answer = 1

#print(grid)

while 1:
    while stack1:
        sh, sw = stack1.pop()
    
        stack2.append((sh, sw))
    
        for i, j in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
            nh, nw = sh + i, sw + j
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] != "#" and grid[nh][nw] == 0:
                if nh == Dh and nw == Dw:
                    print(answer - 1)
                    exit()
                grid[nh][nw] = answer
                stack1.append((nh, nw))
    #print(grid)
    
    if len(stack2) == 0:
        break
    
    answer += 1
    while stack2:
        sh, sw = stack2.pop()
        for i in range(-2, 3):
            for j in range(-2, 3):
                nh, nw = sh + i, sw + j
                if 0 <= nh < H and 0 <= nw < W and S[nh][nw] != "#" and grid[nh][nw] == 0:
                    if nh == Dh and nw == Dw:
                        print(answer - 1)
                        exit()
                    grid[nh][nw] = answer
                    stack1.append((nh, nw))
    #print(grid)

print(-1)
k,x = map(int,input().split())
for a in range(x-k+1,x+i):
    print(a ,end=" ")


### FIXED CODE ###

k,x = map(int,input().split())
for a in range(x-k+1,x+k):
    print(a ,end=" ")
import sys

x = []

for line in sys.stdin.readlines():
  x.append(line.strip())

max = -(10**9)
min = x[1]

for i in range(2, x[0]):
  sa = x[i] - min
  if max < sa:
    max = sa
  if min > x[i]:
    min = x[i]

  

print max

### FIXED CODE ###

import sys

x = []

for line in sys.stdin.readlines():
  x.append(line.strip())

max = -(10**9)
min = int(x[1])

for i in range(2, int(x[0])+1):
  sa = int(x[i]) - min
  if max < sa:
    max = sa
  if min > int(x[i]):
    min = int(x[i])

  

print max
#!/usr/bin/env python3
import numpy as np

h, w, m = map(int, input().split())
a = np.zeros((h, w), dtype=np.int64)
b = [[*map(lambda x: int(x) - 1, input().split())] for _ in range(m)]
for x, y in b:
    c = np.zeros((h, w), dtype=np.int64)
    c[x, :] = 1
    c[:, y] = 1
    a = a + c
print(np.max(a))


### FIXED CODE ###

#!/usr/bin/env python3
h, w, m = map(int, input().split())
r = [0] * (h + 1)
c = [0] * (w + 1)
s = []
for _ in range(m):
    x, y = map(int, input().split())
    r[x] += 1
    c[y] += 1
    s.append([x, y])
R = max(r)
nr = {i for i, x in enumerate(r) if x == R}
C = max(c)
nc = {i for i, x in enumerate(c) if x == C}
count = 0
for x, y in s:
    count += x in nr and y in nc
print(R + C - (len(nr) * len(nc) == count))
import numpy as np

if __name__ == "__main__":
    x,y = [int(x) for x in input().split()]
    print(np.lcm(x,y))

### FIXED CODE ###

if __name__ == "__main__":
    x,y = [int(x) for x in input().split()]
    if x < y:
        tmp = x
        x = y
        y = tmp
    a = x * y
    
    r = x % y;
    while(r!=0):
        x = y
        y = r
        r = x % y;
    
    print(int(a/y))
n = int(input())
l = list(map(int,input().split()))
m = []
for i in range(n):
  if l[i]>l[i+1]:
     m.append(l[i]-l[i+1])
    l[i+1] = l[i]

print(sum(m))
  


### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
m = []
for i in range(n-1):
  if l[i]>l[i+1]:
     m.append(l[i]-l[i+1])
     l[i+1] = l[i]

print(sum(m))
l = raw_input().split()
h = float(l[0])/(float(l[1])+float(l[2]))
print(int(h-1))

### FIXED CODE ###

l = raw_input().split()
print((int(l[0])-int(l[2]))/(int(l[1])+int(l[2])))
from decimal import *

n = int(input())
T = [int(input()) for i in range(n)]

for i in range(n):
    T[i] = Decimal(T[i])

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return max(x, y)

ans = Decimal(1)
for i in range(n):
    ans = Decimal(ans * T[i] / gcd(ans, T[i]))
    #ans = int(ans + 0.1)
print(Decimal(ans))

### FIXED CODE ###

from decimal import *

n = int(input())
T = [int(input()) for i in range(n)]

for i in range(n):
    T[i] = Decimal(T[i])

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return max(x, y)

ans = Decimal(1)
for i in range(n):
    if ans % T[i] != 0:
        ans = ans * T[i] / gcd(ans, T[i])
    #ans = int(ans + 0.1)
    #print(ans)
print(int(ans))
a=o
S=list(input())
T=list(input())
for i in range(len(S)): 
  if S[i]！=T[i]:	
      a=a+1
print(a)
  


### FIXED CODE ###

a=0
S=list(input())
T=list(input())
for i in range(len(S)): 
	if S[i]!=T[i]:	
		a=a+1
print(a)
h,w=map(int,input().strip())
print("#"*w)
for _ in range(h):
  print("#"+input().strip()+"#")
print("#"*w)

### FIXED CODE ###

h,w=map(int,input().split())
print("#"*(w+2))
for _ in range(h):
  print("#"+input().strip()+"#")
print("#"*(w+2))
n=int(input())
h=list(map(int,input().split()))

dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])

for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])

### FIXED CODE ###

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

dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])

for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])
N,A,B =map(int,input().split()) 

from collections import Counter

blues = 'b' * A
reds = 'r' * B

set_balls = blues + reds

all_balls = set_balls * ( N // ( A + B ) + 2 )

balls_N = all_balls[:N]

c = Counter(balls_N)
print(c['b'])


### FIXED CODE ###

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

# import collections

# blues = 'b' * A
# reds = 'r' * B

# set_balls = blues + reds

# all_balls = set_balls * ( N // ( A + B ) + 1 )

# balls_N = all_balls[:N]

# c = collections.Counter(balls_N)
# print(c['b'])

p = N//(A+B)

if N - p*(A+B) < A:
    print(A*p + N - p*(A+B) )
else:
    print(A*p+A)
S = int(input())
list=[]
for i in range(N):
    list.append(input())
print(len(set(list)))

### FIXED CODE ###

N=int(input())
list=[int(input()) for i in range(N)]
print(len(set(list)))
n,m=map(int,input().split())
s0 = set(input().split())
for _ in range(n-1):
  s = set(input(split()))
  s0 &= s
print(len(s0))

### FIXED CODE ###

n,m=map(int,input().split())
k,*s0=map(int,input().split())
s0 = set(s0)
for _ in range(n-1):
  k,*s = map(int,input().split())
  s = set(s)
  s0 &= s
print(len(s0))
A = input()
B = input()
if len(A&B) == 1:
    print(Yes)
else:
    print(No)

### FIXED CODE ###

a = str(input())
b = str(input())
c = b[-1]
if a + c == b:
    print("Yes")
else:
    print("No")
X, Y, A, B, C = map(int, input().split())
p = map(int, input().split())
q = map(int, input().split())
r = map(int, input().split())

# X, Y, A, B, C = 1, 2, 2, 2, 1
# p = [2, 4]
# q = [5, 1]
# r = [3]

p.sort()
q.sort()
r.sort()
p = p[-X:]
q = q[-Y:]

d = []
d += p
d += q
d += r
d.sort()

print(sum(d[-X-Y:]))


### FIXED CODE ###

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

# X, Y, A, B, C = 1, 2, 2, 2, 1
# p = [2, 4]
# q = [5, 1]
# r = [3]

p.sort()
q.sort()
r.sort()
p = p[-X:]
q = q[-Y:]

d = []
d += p
d += q
d += r
d.sort()

print(sum(d[-X-Y:]))
s = input().split()
if s[0] == R and s[1] == R and s[2] == R 
	print("3")
elif s[0] == S and s[1] == S and s[2] == S 
	print("0")
elif s[0] == R and s[1] == R and s[2] == S 
	print("2")
elif s[0] == S and s[1] == R and s[2] == R
	print("2")
else 
	print("1")


### FIXED CODE ###

S = input()
if S.count("R") == 3:
	print("3")
elif S.count("R") == 0:
	print("0")
elif S.count("RR") == 1:
  	print("2")
else:
	print("1")
a = 0 
for i in map(int, raw_input().split()):
  if i == 1:
  	a+=300000
  elif i == 2:
  	a+=200000
  elif i == 3:
  	a+=100000
if a == 600000:
   a =  1000000
print(a)

### FIXED CODE ###

s = 0
for i in map(int, raw_input().split()):
    if i == 1:
        s+=300000
    elif i ==2 :
        s+= 200000
    elif i ==3 :
        s+= 100000
if s== 600000:
    s = 1000000
print(s)
a,b =map(int, input().split)

if a <= 5 :
  print(0)
elif 5 < a <= 12 :
  print(int(b/2))
else :
  print(b)


### FIXED CODE ###

a,b = map(int,input().split())
 
if a <= 5 :
  print(0)
elif a <= 12 :
  print(int(b//2))
else :
  print(b)
s = input()

max_score = 0
for i in range(len(s)):
  if s[i] == 'A' or s[i] == 'T' or s[i] == 'G' or s[i] == 'C':
    score += 1
  else:
    if max_score < score:
      max_score = score
    score = 0

      
print(max_score)

### FIXED CODE ###

s = input()

max_score = 0
score = 0
for i in range(len(s)):
  if s[i] == 'A' or s[i] == 'T' or s[i] == 'G' or s[i] == 'C':
    score += 1
    if max_score <= score:
      max_score = score
  else:
    if max_score <= score:
      max_score = score
    score = 0
  
 
      
print(max_score)
from math import factorial as fact
from collections import Counter

N = int( input() )
tree = list( map( int, input().split() ) )
ans = 1
if tree[0] != 0:
    print(0)
else:
    c = Counter(tree)
    if c[0] != 1:
        print(0)
    else:
        a = 1
        for i in range( 1,len(c)):
            t = c[i]
            if a == 1:
                ans *= t
            else:
                ans *= ( a ** t )
                if t != 1:
                    ans = int( ans / fact(a) )
            a = t 
        print(ans)

### FIXED CODE ###

from math import factorial as fact
from collections import Counter
import sys

N = int( input() )
tree = list( map( int, input().split() ) )
ans = 1
if tree[0] != 0:
    print(0)
else:
    c = Counter(tree)
    if c[0] != 1:
        print(0)
    else:
        ans = 1
        a = c[0]
        for i in range( 1,len(c)):
            t = c[i]
            if t == 0:
                print(0)
                sys.exit()
            else:
                ans *= ( a**t )
                a = t
        print(ans%998244353)
N = int(input())
hen = []

hen = list(int(x) for x in input().split())

#print(hen)
hen_u = set(hen.sort())
#print(hen_u)
tri = 0

for a in hen_u:
    for b in hen_u:
        if(a == b):
            continue
        for c in hen_u:
            if(a == c)or(b == c):
                continue
            if(a+b >c)and(b+c >a)and(c+a >b):
                tri += 1

print(tri)

### FIXED CODE ###

N = int(input())
hen = []

hen = list(int(x) for x in input().split())
hen.sort()
#print(hen)
#hen_u = set(hen)
#print(hen_u)
tri = 0

for a in hen:
    for b in hen:
        if(a == b)or (a > b):
            continue
        for c in hen:
            if(a == c)or(b == c) or (a > c) or (b > c):
                continue
            if(a+b >c)and(b+c >a)and(c+a >b):
                tri += 1

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

if abs(b-a) < d and abs(a-b) < d :
  print('Yes')
elif: abs(a-c) < d :
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a,b,c,d = map(int, input().split())
 
if abs(b-a) <= d and abs(c-b) <= d :
  print('Yes')
elif abs(a-c) <= d :
  print('Yes')
else:
  print('No')
i=int(input())


lst = []
while i > 0:
    lst.append(i%10)
    i //= 10 
lst.reverse()
if (lst[0] == lst[1] or lst[1] == lst[2] or lst[2] == lst[3] ):
    print('Bad')
else:
    print('Good')

### FIXED CODE ###

# coding: utf-8
# Your code here!

i=int(input())


lst = []
while i > 0:
    lst.append(i%10)
    i //= 10 
lst.reverse()
#print(lst)
if (len(lst) == 4):
    if (lst[0] == lst[1] or lst[1] == lst[2] or lst[2] == lst[3] ):
        print('Bad')
    else:
        print('Good')
elif (len(lst) == 3):
    if (lst[0] == lst[1] or lst[1] == lst[2]):
        print('Bad')
    else:
        print('Good')
elif (len(lst) == 2 or 1 or 0):
    print('Bad')
def main():
    N, M = map(int, input().split())
    X = list(map(int, input().split()))
    X_sort = sorted(X)
    diff = []
    for i in range(M - 1):
        diff.append(X_sort[i + 1] - X_sort[i])
    diff_sort = sorted(diff)
    if M == 1:
        print("0")
        return
    for _ in range(N - 1):
        diff_sort.pop()
    ans = 0
    for d in diff_sort:
        ans += d
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N, M = map(int, input().split())
    X = list(map(int, input().split()))
    if N >= M:
        print('0')
        return 
    X_sort = sorted(X)
    diff = []
    for i in range(M - 1):
        diff.append(X_sort[i + 1] - X_sort[i])
    diff_sort = sorted(diff)
    if N != 1:
        for _ in range(N - 1):
            diff_sort.pop()
    ans = 0
    for d in diff_sort:
        ans += d
    print(ans)


if __name__ == "__main__":
    main()
A=list(int(input())for i in range(5))
com=0
for i in range(5):
    if A[i]%10==0:
        continue
    rem=10-A[i]%10
    if com<rem:
        com=rem
        num=i
        tmp=A[i]
A[num]=0
ans=0
for a in A:
    if a==0:
        continue
    if a%10==0:
        ans+=a
    else:
        ans+=(a//10+1)*10
ans+=tmp
print(ans)


### FIXED CODE ###

A=list(int(input())for i in range(5))
ans=0
num=0
com=0
for a in A:
    if a%10==0:
        ans+=a
    else:
        tmp=10-a%10
        ans+=(a//10+1)*10
        if com<tmp:
            com=tmp
            num=a
if num==0:
    print(ans)
else:
    ans-=(num//10+1)*10
    ans+=num
    print(ans)
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, p: "List[int]", S: "List[str]"):
    from collections import defaultdict
    ac = set()
    wcc = defaultdict(int)
    for pp, ss in zip(p, S):
        if pp in ac:
            continue
        if ss == 'WA':
            wcc[pp] += 1
        else:
            ac.add(pp)
    print(len(ac), sum((c for p, c in wcc.items() if p in ac), 0))


# Generated by 1.1.6 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
    M = int(next(tokens))  # type: int
    p = [int()] * (M)  # type: "List[int]"
    S = [str()] * (M)  # type: "List[str]"
    for i in range(M):
        p[i] = int(next(tokens))
        S[i] = next(tokens)
    solve(N, M, p, S)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, p: "List[int]", S: "List[str]"):
    from collections import defaultdict
    ac = set()
    wcc = defaultdict(int)
    for pp, ss in zip(p, S):
        if pp in ac:
            continue
        if ss == 'WA':
            wcc[pp] += 1
        else:
            ac.add(pp)
    print(len(ac), sum((c for p, c in wcc.items() if p in ac), 0))


# Generated by 1.1.6 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
    M = int(next(tokens))  # type: int
    p = [int()] * (M)  # type: "List[int]"
    S = [str()] * (M)  # type: "List[str]"
    for i in range(M):
        p[i] = int(next(tokens))
        S[i] = next(tokens)
    solve(N, M, p, S)

if __name__ == '__main__':
    main()
N = int(input())

A = [0]*N
B = [0]*N

for i in range(N):
    A[i], B[i] = map(int, input().split())


indexes = [*range(N)]
sorted_indexes = sorted(indexes, key=lambda i: B[i])

sorted_A = [A[i] for i in sorted_indexes]
sorted_B = [B[i] for i in sorted_indexes]

total = 0
for i in range(N):
    total += sorted_A[i]
    if total <= sorted_B[i]:
        continue
    else:
        print('No')
        exit()
print('Yes')


### FIXED CODE ###

N = int(input())

A = [0]*N
B = [0]*N

for i in range(N):
    A[i], B[i] = map(int, input().split())


indexes = [i for i in range(N)]
sorted_indexes = sorted(indexes, key=lambda i: B[i])

sorted_A = [A[i] for i in sorted_indexes]
sorted_B = [B[i] for i in sorted_indexes]

total = 0
for i in range(N):
    total += sorted_A[i]
    if total <= sorted_B[i]:
        continue
    else:
        print('No')
        exit()
print('Yes')
import statistics  import median
N = int(input())
A=list(map(int, input().split()))
B=[]
for number, i in enumerate(A, 1):
    B.append(i-number)
median = int(median(B))
ans2 = 0
for i in B:
    ans2 += abs(i-median)
print(ans2)

### FIXED CODE ###

import statistics  
N = int(input())
A=list(map(int, input().split()))
B=[]
for number, i in enumerate(A, 1):
    B.append(i-number)
median = int(statistics.median(B))
ans2 = 0
for i in B:
    ans2 += abs(i-median)
print(ans2)
def main():
    import sys
    input = sys.stdin.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    #import bisect
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    #print(a)

    bc=[]
    for i in range(m):
        B = list(map(int, input().split()))
        bc.append(B)
    bc.sort(key=lambda x: x[1])
    #print(bc)

    clis=[]
    for i in range(m)[::-1]:
        clis+=[bc[i][1] for i in range(bc[i][0])]
    #print(clis)
    ans=0
    le=len(clis)
    for i in range(n):
        #print(clis[i],a[i])
        if i<le and clis[i]>a[i]:
            ans+=clis[i]
        else:
            ans+=a[i]
        #print(ans)
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
bc=[list(map(int,input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1],reverse=True)
#print(bc)
cnt=0
for i in range(n):
    if bc[cnt][0]>0:
        if bc[cnt][1]>a[i]:
            a[i]=bc[cnt][1]
        bc[cnt][0]-=1
    else:
        cnt+=1
        if cnt==len(bc):
            break
        if bc[cnt][1]>a[i]:
            a[i]=bc[cnt][1]
        bc[cnt][0]-=1
    #print(cnt,bc,a)
print(sum(a))
n = list(map(int, input()))
if stm(n)%9==0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n = list(map(int, input()))
if sum(n)%9==0:
  print('Yes')
else:
  print('No')