Harryxun/stf_run huggingface dataset:
import sys
sys.setrecursionlimit(10000)


N = int(input())
h = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0


def rec(i):

    if dp[i] < float('inf'):
        return dp[i]

    a = rec(i-1) + abs(h[i] - h[i-1])
    if i > 1:
        a = min(a, rec(i-2) + abs(h[i] - h[i-2]))

    dp[i] = a
    return a


print(rec(N-1))


### FIXED CODE ###

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

dp = [float('inf') for _ in range(N)]
dp[0] = 0

for i in range(N):
    if i - 1 >= 0:
        if dp[i - 1] + abs(h[i] - h[i - 1]) < dp[i]:
            dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])
    if i - 2 >= 0:
        if dp[i - 2] + abs(h[i] - h[i - 2]) < dp[i]:
            dp[i] = dp[i - 2] + abs(h[i] - h[i - 2])
print(dp[N-1])
x, y = map(int, input().split())
a = [0, 1, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1]
if a[x] == a[y]:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

x, y = map(int, input().split())
a = [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1]
if a[x] == a[y]:
    print("Yes")
else:
    print("No")
if __name__ == '__main__':
    N = int(input())
    a = input()
    a = a.split(' ')
    a = list(map(int, a))

    min_a = min(a)
    max_a = max(a)

    num = []

    for i in range(max_a+1):
        num.append(0)

    for i in a:
        num[i-2] += 1
        num[i-1] += 1
        num[i] += 1

    c = max(num)
    print(c)

### FIXED CODE ###

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

    min_a = min(a)
    max_a = max(a)

    num = []

    for i in range(max_a+1):
        num.append(0)

    for i in a:
        if i-2 >= 0:
            num[i-2] += 1
        if i-1 >= 0:
            num[i-1] += 1
        num[i] += 1

    c = max(num)
    print(c)
N, K = map(int, input().split())
R = N - K
mod = pow(10, 9) + 7

fact = [0] * N
inv = [0] * N
inv_cal = [0] * N

fact[:2] = [1, 1]
inv[1] = 1
inv_cal[:2] = [1, 1]

for i in range(2, N):
    fact[i] = fact[i-1] * i % mod
    inv[i] = mod - (mod // i) * inv[mod % i] % mod
    inv_cal[i] = inv_cal[i-1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fact[n] * (inv_cal[k] * inv_cal[n-k] % mod) % mod

for k in range(1, K+1):
    print(comb(R+1, k) * comb(K-1, k-1) % mod)

### FIXED CODE ###

N, K = map(int, input().split())
R = N - K
mod = pow(10, 9) + 7

fact = [0] * 2001
inv = [0] * 2001
inv_cal = [0] * 2001

fact[:2] = [1, 1]
inv[1] = 1
inv_cal[:2] = [1, 1]

for i in range(2, 2001):
    fact[i] = fact[i-1] * i % mod
    inv[i] = mod - (mod // i) * inv[mod % i] % mod
    inv_cal[i] = inv_cal[i-1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fact[n] * (inv_cal[k] * inv_cal[n-k] % mod) % mod

for k in range(1, K+1):
    if R+1 >= k:
        print(comb(R+1, k) * comb(K-1, k-1) % mod)
    else:
        print(0)
s = input()

vocabs = ["dream","dreamer","erase","eraser"]

cnt = 0
t = ""
while cnt <= len(s) - 7:
    if s[cnt] == "d":
        if s[cnt+5] == "d":
            cnt += 5
            t += vocabs[0]
        elif s[cnt+5] == "e":
            if s[cnt+7] == "a":
                cnt += 5
                t += vocabs[0]
            else:
                cnt += 7
                t += vocabs[1]
        else:
            break
    elif s[cnt] == "e":
        if s[cnt+5] == "r":
            cnt += 6
            t += vocabs[3]
        else:
            cnt += 5
            t += vocabs[2]
    else:
        break

if s[cnt:] == vocabs[0]:
    t+= vocabs[0]
elif s[cnt:] == vocabs[1]:
    t+= vocabs[1]
elif s[cnt:] == vocabs[2]:
    t+= vocabs[2]
elif s[cnt:] == vocabs[3]:
    t+= vocabs[3]


if s == t:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

s = input()

vocabs = ["dream","dreamer","erase","eraser"]

cnt = 0
t = ""
while cnt <= len(s) - 8:
    if s[cnt] == "d":
        if s[cnt+5] == "d":
            cnt += 5
            t += vocabs[0]
        elif s[cnt+5] == "e":
            if s[cnt+7] == "a":
                cnt += 5
                t += vocabs[0]
            else:
                cnt += 7
                t += vocabs[1]
        else:
            break
    elif s[cnt] == "e":
        if s[cnt+5] == "r":
            cnt += 6
            t += vocabs[3]
        else:
            cnt += 5
            t += vocabs[2]
    else:
        break

if s[cnt:] == vocabs[0]:
    t+= vocabs[0]
elif s[cnt:] == vocabs[1]:
    t+= vocabs[1]
elif s[cnt:] == vocabs[2]:
    t+= vocabs[2]
elif s[cnt:] == vocabs[3]:
    t+= vocabs[3]


if s == t:
    print("YES")
else:
    print("NO")
N = int(input())
a = [int(i) for i in input().split(' ')]
b = a
numbers = []
numbers.append(a[0])
for i in a:
    if i != numbers[0] and len(numbers) == 1:
        numbers.append(i)
    if i != a[0] and i != numbers[1]:
        numbers.append(i)
        break
if len(numbers) =! 3:
    print('No')
    exit(1)

if a.count(numbers[0]) != a.count(numbers[1]):
    print('No')
    exit(1)
if a.count(numbers[0]) != a.count(numbers[2]):
    print('No')
    exit(1)
if len(a) != a.count(numbers[0])+a.count(numbers[1])+a.count(numbers[2]):
    print('No')
    exit(1)

if numbers[0]^numbers[1] == numbers[2]:
    print('Yes')
    exit(1)
elif numbers[0]^numbers[2] == numbers[1]:
    print('Yes')
    exit(1)
elif numbers[1]^numbers[2] == numbers[0]:
    print('Yes')
    exit(1)
else:
    print('No')

### FIXED CODE ###

N = int(input())
a = [int(i) for i in input().split(' ')]
numbers = []
numbers.append(a[0])
for i in a:
    if i != numbers[0] and len(numbers) == 1:
        numbers.append(i)
    if i != numbers[0] and i != numbers[1]:
        numbers.append(i)
        break

if len(numbers) == 1:
    if numbers[0] == 0:
        print('Yes')
        exit(0)
    else:
        print('No')
        exit(0)

if len(numbers) == 3:
    if a.count(numbers[0]) != a.count(numbers[1]):
        print('No')
        exit(0)
    if a.count(numbers[0]) != a.count(numbers[2]):
        print('No')
        exit(0)
    if len(a) != a.count(numbers[0])+a.count(numbers[1])+a.count(numbers[2]):
        print('No')
        exit(0)

    if numbers[0]^numbers[1] == numbers[2]:
        print('Yes')
        exit(0)
    elif numbers[0]^numbers[2] == numbers[1]:
        print('Yes')
        exit(0)
    elif numbers[1]^numbers[2] == numbers[0]:
        print('Yes')
        exit(0)
    else:
        print('No')
else:
    if len(a) != a.count(numbers[0])+a.count(numbers[1]):
        print('No')
        exit(0)
    if numbers[0] == 0 or numbers[1] == 0:
        if numbers[0] == 0:
            if a.count(numbers[1]) != 2*a.count(numbers[0]):
                print('No')
                exit(0)
        elif a.count(numbers[0]) != 2*a.count(numbers[1]):
            print('No')
            exit(0)
        print('Yes')
        exit(0)
    else:
        print('No')
        exit(0)
inp=list(map(int,input().split()))
S=inp[0]
B=inp[1]
R=inp[2]
x=S//(B+R)#brグループが何回
y=S//(B+R)
print(b*x+y)

### FIXED CODE ###

inp=list(map(int,input().split()))
s=inp[0]
b=inp[1]
r=inp[2]
print(s//(b+r)*b+min(s%(b+r),b))
import bisect
from collections import deque
n,m = map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))

lis = [[]for i in range(m)]

for i in range(n):
    if ab[i][0]<=m:
        lis[ab[i][0]-1].append(ab[i][1])

pys = deque()
sum = 0
for i in range(m):
    tmp = lis[i]
    if tmp:
        for j in tmp:
            bisect.insort(pys,j)
    if pys:
        sum+=pys.pop()

print(sum)


### FIXED CODE ###

#import bisect
import heapq
from collections import deque
n,m = map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))

lis = [[]for i in range(m)]

for i in range(n):
    if ab[i][0]<=m:
        lis[ab[i][0]-1].append(ab[i][1])

pys = []
heapq.heapify(pys)
sum = 0
for i in range(m):
    tmp = lis[i]
    if tmp:
        for j in tmp:
            heapq.heappush(pys,-j)
    if pys:
        sum-=heapq.heappop(pys)

print(sum)
D, N= int(input().split())
print(N*100**D)

### FIXED CODE ###

A = input().split()
D = int(A[0])
N = int(A[1])
 
if N != 100:
  print(100 ** D * N)
else:
  print(100 ** D * 101)
a,b,k = list(map(int,input().split(" ")))

if a > k:
    a -= k
    print(str(a) + " " + b)
else:
    left = k - a
    b -= left
    print(str(0) + " " + b)

### FIXED CODE ###

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

if a > k:
    a -= k
    print(str(a) + " " + str(b))
else:
    left = k - a
    b -= left
    if b < 0:
        b = 0
    print(str(0) + " " + str(b))
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    ba = 0
    bb = 0
    for i in range(N):
        if a[i] > b[i]:
            ba += a[i] - b[i]
        if b[i] > a[i]:
            bb += (b[i] - a[i]) // 2

    if bb = ba:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    ba = 0
    bb = 0
    for i in range(N):
        if a[i] > b[i]:
            ba += a[i] - b[i]
        if b[i] > a[i]:
            bb += (b[i] - a[i]) // 2

    if bb >= ba:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()
#coding: UTF-8

from bisect import bisect_right

# 指定した数以下の素数の個数を返却する
# 素数判定はエラストテネスのふるい

# 要素1000000のリスト（素数かどうかのリスト）を準備
max_number = 1000000
prime_flag_list = [True] * max_number

# 0、1は素数でない
prime_flag_list[0] = False
prime_flag_list[1] = False

# 2の倍数（2を除く）は素数でない
prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2])

# 3以上の数について、素数ならその倍数を振るい落とす
for i in range(3, int(max_number**0.5) + 1, 2):
    prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i])

# フラグの立ったままの箇所は素数なので、そこだけ取り出す
prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]

while True:
    try:
        input = int(raw_input())
    except EOFError:
        break
        
    # 素数リスト（ソート済み）の中に、入力した数値を入れるとしたら何項目目になるかを
    # bisectで求める
    print bisect.bisect_right(prime_list, input)

### FIXED CODE ###

max_n = 999999
prime_list = [1] * (max_n + 1)

# 0, 1は素数ではない
prime_list[0:2] = [0, 0]

# 
for i in range(2, int(max_n**0.5) + 1):
    if prime_list[i] == 1:
        prime_list[i**2::i] = [0] * len(prime_list[i**2::i])

while True:
    try:
        n = int(input())
        print(sum(prime_list[:n + 1]))

    except EOFError:
        break
S = input()

ls = len(S)

ans = ''
for i in range(ls):
    ans.append(x)

print(ans)

### FIXED CODE ###

S = input()

ls = len(S)

ans = ''
for i in range(ls):
    ans += 'x'

print(ans)
#解放2
from decimal import Decimal
from floor import math
a, b = input().split()
a = int(a)
b = Decimal(b)
print(floor(a*b))

### FIXED CODE ###

#a, b = map(float, input().split())

a, b = input().split()
from decimal import Decimal
import math
print(math.floor(int(a)*Decimal(b)))
s = list(input())
a = 200000
z = 0
for i in range(len(s)):
  if s[i] = 'A' and a > i:
    a = i
  if s[i] = 'Z' and z < i:
    z = i
print(z-a+1)

### FIXED CODE ###

s = list(input())
a = 200000
z = 0
for i in range(len(s)):
  if s[i] == 'A' and a > i:
    a = i
  if s[i] == 'Z' and z < i:
    z = i
print(z-a+1)
import math:

r = float( raw_input() ) 

S = math.pi * r ** 2 
l = 2 * r * math.pi

print"%f %f" %(S,l)

### FIXED CODE ###

import math

r = float( raw_input() ) 

S = math.pi * r * r
l = 2 * r * math.pi

print"%f %f" %(S,l)
def nibutan(f_id,e_id,f_num,yn):
    
    
    m_id = int((f_id + e_id) / 2)
    m_num = w_lis[m_id]


    if e_id - f_id <= 1:
        if yn == 0:

            return e_id
        else:
            return f_id
    else:
        if m_num > f_num:
            return(nibutan(f_id,m_id -1,f_num,yn))
        elif m_num < f_num:
            return(nibutan(m_id + 1,e_id,f_num,yn))
        else:
            return  m_num




while True:
    global w_lis
    b_lis = []
    w_lis = []
    dan_num = [0]
    atu_num = [0]
    wa = 0
    m,n = map(int,input().split())
    if m == n == 0:
        break
    for i in range(n):
        num = int(input())
        wa += num
        b_lis.append(num)
        w_lis.append(wa)
    best_num = wa / m
    if best_num < max(b_lis):
        print(max(b_lis))
    else:
        bid = 0
        n_si = 0
        for i in range(m):
            bid = nibutan(bid,n - 1,n_si + best_num,i)
            n_si = w_lis[bid]
            dan_num.append(n_si)
            atu_num.append(n_si - dan_num[i])
            
        print(max(atu_num))
    
    
    

### FIXED CODE ###

def hondan(w,m):
    m_sum = b_lis[0]
    num = 0
    if w < max(b_lis):
        return False
    else:
        for i in range(len(b_lis) - 1):
            m_sum += b_lis[i + 1]
            if m_sum > w:

                m_sum = b_lis[i + 1]
                num += 1

        if num < m:
            return True
        else:
            return False
        
def nibutan(f_id,e_id,m):
    
    
    m_id = int((f_id + e_id) / 2)
    m_bo = hondan(m_id,m)


    if (f_id > e_id):
        return m_id + 1
    else:
        if m_bo:
            return(nibutan(f_id,m_id -1,m))
        elif not m_bo:
            return(nibutan(m_id + 1,e_id,m))
        else:
            return m_id + 1



while True:
    global w_lis
    b_lis = []
    w_lis = []
    dan_num = [0]

    m,n = map(int,input().split())
    if m == n == 0:
        break
    for i in range(n):
        num = int(input())
        b_lis.append(num)
    s_num = int(sum(b_lis) /m)

    print(nibutan(s_num,1500000,m) )
def f(n):
    if n+1 % 4 == 0:
        return 0
    if n+1 % 4 == 1:
        return n
    if n+1 % 4 == 2:
        return 1
    if n+1 % 4 == 3:
        return 1^n
a, b = map(int, input().split())
ans = f(a-1) ^ f(b)
print(ans)

### FIXED CODE ###

def f(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    else:
        return n ^ 1
a, b = map(int, input().split())

print(f(a-1) ^ f(b))
w = int(raw_input())
n = int(raw_input())

s = [i+1 for i in range(w)]
for i in range(n):
    a, b = map(int, raw_input().split())
    tmp = s[a-1]
    s[a-1] = s[b-1]
    s[b-1] = tmp

for i in s:
    print i

### FIXED CODE ###

w = int(raw_input())
n = int(raw_input())

s = [i+1 for i in range(w)]
for i in range(n):
    a, b = map(int, raw_input().split(","))
    tmp = s[a-1]
    s[a-1] = s[b-1]
    s[b-1] = tmp

for i in s:
    print i
N = int(input())
if N <= 999:
  print(ABC)
else:
  print(ABD)

### FIXED CODE ###

N = int(input())

if N <= 999:
  print("ABC")
else:
  print("ABD")
x, n = map(int, input().split())
p = list(map(int, input().split()))

q = []
r = []
min_ = 1000
for i in range(1, 101):
    if not i in p:
        q.append(i)
        
for j in q:
    k = int(abs(x - j))
    if min_ == k:
        r.append(before_j)
        r.append(j)
    min_ = min(k, min_)
    if min_ == k:
        before_j = j

print(min(r))

### FIXED CODE ###

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

p = set(p)
for i in range(200):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break
n = int(input())
grid = [list(map(int, input().split())) for i in range(n)]

for i in range(n):
    if (grid[i][0] + grid[i][1]) % 2 != (grid[i][0] + grid[i][1]) % 2:
        print(-1)
        exit()
m = 31
D = [2 ** i for i in range(m)]
if (grid[0][0] + grid[0][1]) % 2 == 0:
    d.insert(0, 1)
w = [[] for i in range(n)]
for i, g in enumerate(grid):
    x, y = g
    for d in D[::-1]:
        if abs(x) >= abs(y):
            if x > 0:
                x -= d
                w[i].append('L')
            else:
                x += d
                w[i].append('R')
        else:
            if y > 0:
                y -= d
                w[i].append('D')
            else:
                y += d
                w[i].append('U')

print(m)
print(*D)
for ans in w:
    print(*ans[::-1], sep='')

### FIXED CODE ###

n = int(input())
grid = [list(map(int, input().split())) for i in range(n)]

for i in range(n - 1):
    if (grid[i][0] + grid[i][1]) % 2 != (grid[i + 1][0] + grid[i + 1][1]) % 2:
        print(-1)
        exit()
m = 31
D = [2 ** i for i in range(m)]
if (grid[0][0] + grid[0][1]) % 2 == 0:
    D.insert(0, 1)
    m += 1
w = [[] for i in range(n)]
for i, g in enumerate(grid):
    x, y = g
    for d in D[::-1]:
        if abs(x) >= abs(y):
            if x > 0:
                x -= d
                w[i].append('R')
            else:
                x += d
                w[i].append('L')
        else:
            if y > 0:
                y -= d
                w[i].append('U')
            else:
                y += d
                w[i].append('D')

print(m)
print(*D)
for ans in w:
    print(*ans[::-1], sep='')
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list(int(input()) for i in range(n))

a.sort()
if n%2==0:
    start = n//2-1
    left = 0
    right = n-1
    ans = abs(a[right]- a[start])
    while start != left:
        ans+=abs(a[left]-a[right])
        right -= 1
        ans+=abs(a[right]-a[left])
        left += 1

    print(ans)

if n%2==1:
    start = n//2
    left = 0
    right = n-1
    
    ans0 = abs(a[right]- a[start])
    while True:
        ans0+=abs(a[left]-a[right])
        right -= 1
        if start == right: break
        ans0+=abs(a[right]-a[left])
        left += 1
        
    ans1 = abs(a[left]- a[start])
    while True:
        ans1+=abs(a[right]-a[left])
        right -= 1
        if start == right: break
        ans1+=abs(a[left]-a[right])
        left += 1

    ans = max(ans0,ans1)
    print(ans)



### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list(int(input()) for i in range(n))

a.sort()
if n%2==0:
    start = n//2-1
    left = 0
    right = n-1
    ans0 = abs(a[right]- a[start])
    while start != left:
        ans0+=abs(a[left]-a[right])
        right -= 1
        ans0+=abs(a[right]-a[left])
        left += 1

    start = n//2
    left = 0
    right = n-1
    ans1 = abs(a[left]- a[start])
    while start != right:
        ans1+=abs(a[right]-a[left])
        left += 1
        ans1+=abs(a[left]-a[right])
        right -= 1

    ans = max(ans0,ans1)
    print(ans)

if n%2==1:
    start = n//2
    left = 0
    right = n-1
    ans0 = abs(a[right]- a[start])
    while True:
        ans0+=abs(a[left]-a[right])
        right -= 1
        if start == right: break
        ans0+=abs(a[right]-a[left])
        left += 1


    left = 0
    right = n-1
    ans1 = abs(a[left]- a[start])
    while True:
        ans1+=abs(a[right]-a[left])
        left += 1
        if start == left: break
        ans1+=abs(a[left]-a[right])
        right -= 1

    ans = max(ans0,ans1)
    print(ans)
from scipy.special import comb
N,M,K = map(int, input().split())
answer = 0
for i in range(K+1):
    answer += M*comb(N-1,i, exact=True)*(M-1)**(N-1-i)*1**i
print(answer%998244353)

### FIXED CODE ###

N,M,K = map(int, input().split())
MOD = 998244353

fact = [1]
rfact = [1]
for i in range(1, N+1):
    fact.append(fact[i-1]*i%MOD)
    rfact.append(pow(fact[i], MOD-2, MOD))
 
def cmb(n, m):
    return fact[n]*rfact[m]*rfact[n-m]%MOD

answer = 0
for i in range(K+1):
    answer += (M*cmb(N-1,i)*pow(M-1,N-1-i,MOD))%MOD
print(answer%MOD)
l,n=map(int,input().split())
tree=[]
for i in range(n):
  k=int(input())
  tree.append(k)

reverse_tree=[l-i for i in tree]
reverse_tree.reverse()

position=0
ans=0
flag=True

while len(tree)>0:
    if flag:
        if (tree[0]-position > reverse_tree[0]+position):
            ans+= tree[0]-position
            position=tree.pop(0)
            reverse_tree.pop(-1)
        elif (tree[0]-position == reverse_tree[0]+position):
            if tree[1]>=reverse_tree[1]:
                ans+= tree[0]-position
                position=tree.pop(0)
                reverse_tree.pop(-1)
            else:
                ans+= reverse_tree[0]+position
                position=l-reverse_tree.pop(0)
                tree.pop(-1)
                flag=False
        else:
            ans+= reverse_tree[0]+position
            position=l-reverse_tree.pop(0)
            tree.pop(-1)
            flag=False
    else:
        if (l-position+tree[0] > position-l+reverse_tree[0]):
            ans+= l-position+tree[0]
            position=tree.pop(0)
            reverse_tree.pop(-1)
            flag=True
        elif (l-position+tree[0] == position-l+reverse_tree[0]):
            if tree[1]>=reverse_tree[1]:
                ans+= l-position+tree[0]
                position=tree.pop(0)
                reverse_tree.pop(-1)
                flag=True
            else:
                ans+= position-l+reverse_tree[0]
                position=l-reverse_tree.pop(0)
                tree.pop(-1)
        else:
            ans+= position-l+reverse_tree[0]
            position=l-reverse_tree.pop(0)
            tree.pop(-1)

print(ans)


### FIXED CODE ###

import sys
from collections import deque
l,n=map(int,input().split())
c=n
tree1=[int(i) for i in sys.stdin]
reversed_tree1=[l-i for i in reversed(tree1)]
tree=deque(tree1)
reversed_tree=deque(reversed_tree1)
if n%2 == 0:
  ans= sum(tree1)*2 + l*(n-1) +tree1[n//2] - sum(tree1[n//2:])*4
  ans2= sum(reversed_tree1)*2 + l*(n-1) +reversed_tree1[n//2] - sum(reversed_tree1[n//2:])*4
  n-=1
  c-=1
  ans3= ans-tree.popleft()*2-l+tree[n//2]*2
  ans= max(ans,ans3)
  ans4= ans2-reversed_tree.popleft()*2-l+(reversed_tree[n//2])*2
  ans2= max(ans2,ans4)
else:
  ans= sum(tree1)*2 + l*(n-1) - tree1[n//2] - sum(tree1[((n//2)+1):])*4
  ans3=ans
  ans2= sum(reversed_tree1)*2 + l*(n-1) - reversed_tree1[n//2] - sum(reversed_tree1[((n//2)+1):])*4
  ans4=ans2
for i in range(n//2):
  n-=1
  ans_stack= ans3-tree.popleft()*2-l+tree[(n-1)//2]+tree[(n+1)//2]
  ans= max(ans_stack,ans)
  ans3=ans_stack
  n-=1
  ans_stack= ans3-tree.popleft()*2-l+tree[n//2]*2
  ans=max(ans_stack,ans)
  ans3=ans_stack
n=c
for i in range(n//2):
  n-=1
  ans_stack= ans4-reversed_tree.popleft()*2-l+reversed_tree[(n-1)//2]+reversed_tree[(n+1)//2]
  ans2=max(ans_stack,ans2)
  ans4=ans_stack
  n-=1
  ans_stack= ans4-reversed_tree.popleft()*2-l+reversed_tree[n//2]*2
  ans2=max(ans2,ans_stack)
  ans4=ans_stack
print(max(ans,ans2))
while true:
  H, W = map(int, raw_input().split())
  for i in range(H):
    width = ''
    for j in range(W):
      width += '#'
    print width
  print ''

### FIXED CODE ###

while True:
  H, W = map(int, raw_input().split())
  if H == 0 and W == 0:
    break
  for i in range(H):
    width = ""
    for j in range(W):
      width += "#"
    print width
  print ""
s=input()
w=input()
ss=int(s)
ww=int(w)
if ww>=ss:
  print("unsafe")
else:
  print("safe")

### FIXED CODE ###

s,w=map(int,input().split())
if w>=s:
  print("unsafe")
else:
  print("safe")
from functools import reduce
import fractions

N = int(input())

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

def lcm(a):
  x = a[0]
  for i in range(1, len(a)):
    x = (x * a[i]) // fractions.gcd(x, a[i])
  return x

l = lcm(A)
num=0
for a in A:
  num += l/a
print(int(num % (10e9 +7)))




### FIXED CODE ###

from fractions import gcd

N = int(input())

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

l = A[0]
for a in A:
  l = (l * a) // gcd(l,a)
num=0
for a in A:
  num += l//a
print(num % (10**9 +7))
S,T=input().split()
flag=0

S_length=len(S)
for num in range(S_length):
  if S[num]!=T[num]:
    flag=-1

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

### FIXED CODE ###

S=input()
T=input()
flag=0
 
S_length=len(S)
for num in range(S_length):
  if S[num]!=T[num]:
    flag=-1
 
if flag==0:
  print('Yes')
else:
  print('No')