Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if M <= 1 and N <= 1:
    print(0)
elif M == 0:
    print(cmb(N, 2))
elif N == 0:
    print(cmb(M, 2))
else:
    a = cmb(M, 2)
    b = cmb(N, 2)
    print(a + b)

### FIXED CODE ###

N, M = map(int, input().split())

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if M == 0 and N == 0:
    print(0)
elif M == 1 and N == 1:
    print(0)
elif M <= 1:
    print(cmb(N, 2))
elif N <= 1:
    print(cmb(M, 2))
else:
    a = cmb(M, 2)
    b = cmb(N, 2)
    print(a + b)
N = int(input())
A = list(map(int, input().split()))

A.sort()
A.reverse()

list = []
ans = 0
list.append(A[0])
for i in range(1, len(A)):
        ans += list[i]
        list.append(A[i])
        list.append(A[i])

print(ans)

### FIXED CODE ###

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

A.sort()
A.reverse()

list = []
ans = 0
list.append(A[0])
for i in range(1, len(A)):
        ans += list[i - 1]
        list.append(A[i])
        list.append(A[i])

print(ans)
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
mod=10**9+7


n_max=(10**5+1)
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
FI[n_max-1]=pow(F[n_max-1],mod-2,mod)
for i in reversed(range(n_max-1)):
  FI[i]=(FI[i+1]*(i+1))%mod
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod

edge=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
Ans=[]
inf=10**6

#親と入次数を求める
Par=[inf]*n
Par[0]=-1
Deg=[0]*n
Deg[0]=0
Chk=[0]
while Chk:
  c=Chk.pop()
  for next in edge[c]:
    if Par[next]==inf:
      Par[next]=c
      Deg[next]+=1
      Chk.append(next)
 
#トポソする
from collections import deque
TS=list(v for v in range(n) if Deg[v]==0)
D=deque(TS)
while D:
  v=D.popleft()
  for t in edge[v]:
    if t!=Par[v]:
      Deg[t]-=1
      if Deg[t]==0:
        D.append(t)
        TS.append(t)

Used=[False]*n
C=[0]*n
for i in reversed(range(n)):
  v=TS[i]
  Used[v]=True
  for g in edge[v]:
    if not Used[g]:
      C[g]+=C[v]+1

D=[1]*n
for i in reversed(range(n)):
  v=TS[i]
  D[v]=(D[v]*(C[v]+1))%mod
  if Par[v]!=-1:
    D[Par[v]]=(D[Par[v]]*D[v])%mod
E=[1]*n
for i in range(n):
  v=TS[i]
  if Par[v]!=-1:
    cur=E[Par[v]]
  else:
    cur=1
  
  for g in edge[v]:
    if g!=Par[v]:
      cur=(cur*D[g])%mod
  for g in edge[v]:
    if g!=Par[v]:
      E[g]=(cur*pow(D[g],mod-2,mod)*(n-C[g]-1))%mod
def I(x):
  return pow(x,mod-2,mod)


for i in range(n):
  print((F[n]*I(D[i])*I(E[i])*comb(n-1,C[i]))%mod)

### FIXED CODE ###

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
mod=10**9+7


n_max=(2*10**5+1)
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
FI[n_max-1]=pow(F[n_max-1],mod-2,mod)
for i in reversed(range(n_max-1)):
  FI[i]=(FI[i+1]*(i+1))%mod
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod
def I(x):
  return pow(x,mod-2,mod)

edge=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
Ans=[]
inf=10**6

#親と入次数を求める
Par=[inf]*n
Par[0]=-1
Deg=[0]*n
Deg[0]=0
Chk=[0]
while Chk:
  c=Chk.pop()
  for next in edge[c]:
    if Par[next]==inf:
      Par[next]=c
      Deg[next]+=1
      Chk.append(next)
 
#トポソする
from collections import deque
TS=list(v for v in range(n) if Deg[v]==0)
D=deque(TS)
while D:
  v=D.popleft()
  for t in edge[v]:
    if t!=Par[v]:
      Deg[t]-=1
      if Deg[t]==0:
        D.append(t)
        TS.append(t)

Used=[False]*n
C=[0]*n
for i in reversed(range(n)):
  v=TS[i]
  Used[v]=True
  for g in edge[v]:
    if not Used[g]:
      C[g]+=C[v]+1

D=[1]*n
for i in reversed(range(n)):
  v=TS[i]
  D[v]=(D[v]*F[C[v]])%mod
  if Par[v]!=-1:
    D[Par[v]]=(D[Par[v]]*I(F[C[v]+1])*D[v])%mod
E=[1]*n
for i in range(n):
  v=TS[i]
  if Par[v]!=-1:
    cur=E[v]*FI[n-C[v]-1]
  else:
    cur=1
  for e in edge[v]:
    if e!=Par[v]:
      cur=(cur*FI[C[e]+1]*D[e])%mod
  for e in edge[v]:
    if e!=Par[v]:
      E[e]=(cur*F[n-2-C[e]]*F[C[e]+1]*I(D[e]))%mod
for i in range(n):
  print((comb(n-1,C[i])*D[i]*E[i])%mod)
import math
count=int(input())
for i in range(count):
    x=int(input())
    y=int(input())
    ans=x+y
    if int(math.log10(ans)>=80)
        print("overflow")
    else:
        print(ans)

### FIXED CODE ###

import math
count=int(input())
for i in range(count):
    x=int(input())
    y=int(input())
    ans=x+y
    dif=100000000000000000000000000000000000000000000000000000000000000000000000000000000
    if ans>=dif:
        print("overflow")
    else:
        print(ans)
import sys
alpha=[s for s in 'abcdefghijklmnopqrstuvwxyz']
num=int(input())
digit=1
check=26
while num > check:
  digit+=1
  check+=26**digit
digit-=1
if digit == 0:
  print(alpha[num-1])
  sys.exit()
ans=[]
while digit > 1:
  ans.append(alpha[num//(26**digit)-1])
  num%=26**digit
  digit-=1
ans.append(alpha[num//26-1])
ans.append(alpha[num%26-1])
print(''.join(ans))

### FIXED CODE ###

alpha=[s for s in 'abcdefghijklmnopqrstuvwxyz']
num=int(input())
ans=[]
while num > 0:
  ans.append(alpha[num%26-1])
  num//=26
  if ans[-1]=='z':
    num-=1
print(''.join(ans[::-1]))
# B(TLE) 2104ms

N, K = map(int, input().split())
h = np.array(map(int, input().split()))
cost = np.zeros(N, dtype="int32")

cost[0] = 0
for i in range(1,N):
    start = 0 if i < K else i-K
    cost[i] = np.min(cost[start:i] + np.abs(h[i]-h[start:i]))


print(cost[-1])


### FIXED CODE ###

# B(TLE) 2104ms

import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))
cost = np.zeros(N, dtype="int32")

cost[0] = 0
for i in range(1,N):
    start = 0 if i < K else i-K
    cost[i] = np.min(cost[start:i] + np.abs(h[i]-h[start:i]))

print(cost[-1])
inputted = list(map(int, input().split()))
tax_price_a = inputted[0]
tax_price_b = inputted[1]

price_8 = int(tax_price_a / 0.08)
price_10 = int(tax_price_b / 0.10)

if price_8 == price_10:
    print(price_8)
elif tax_price_b == int(price_8 * 0.1):
    print(price_8)
elif tax_price_a == int(price_10 * 0.u):
    print(price_10)
else:
    print(-1)


### FIXED CODE ###

import math

inputted = list(map(int, input().split()))
tax_price_a = inputted[0]
tax_price_b = inputted[1]

price_8 = math.ceil(tax_price_a / 0.08)
price_10 = math.ceil(tax_price_b / 0.10)

if tax_price_b == int(price_8 * 0.1):
    print(price_8)
elif tax_price_a == int(price_10 * 0.08):
    print(price_10)
else:
    print('-1')
import sys

C = [ 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
N = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]

def checkio(data, i = 0):
    return C[i]*(data // N[i]) + checkio(data % N[i], i + 1) if data else ''

for line in sys.stdin:
    n = int(line)
    print(checkio(n))

### FIXED CODE ###

import sys

d = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}

for s in sys.stdin:
    s = [d[c] for c in s.strip()] + [0]
    n = 0
    for i, x in enumerate(s[:-1]):
        if x >= s[i + 1]:
            n += x
        else:
            n -= x
    print(n)
X,Y = map(ord,intput().split())
if X>Y:
  print(">")
elif X<Y:
  print("<")
else:
  print("=")

### FIXED CODE ###

X,Y = input().split() 
if X>Y:
  print(">")
elif X<Y:
  print("<")
else:
  print("=")
a, b = map(int, input().split())
x=a*100//8
y=b*10
i=1
f=False
while(i<=1250):
  if i*8//100 == x and i//10 == y:
    print(i)
    f=True
    break
  i+=1
if not f:
  print(-1)

### FIXED CODE ###

s=list(input())
if len(set(s))==1:
  print("No")
else:
  print("Yes")
def method()
	if a*b%2==0:
    	return 'Even'
    else:
      	return 'Odd'

### FIXED CODE ###

a, b = map(int, input().split())
if a*b%2==0:
  print('Even')
else:
  print('Odd')
a,b = map(int(input(),split())
print(a*b)

### FIXED CODE ###

a,b = map(int,input().split())
print(a*b)
n,m=map(int,input().split())
x=list(map(int,input().split()))
count=0
a=max(x)
i=min(x)
if m<=2:
  print(count)
else:
  while True:
    x.pop(a)
    x.pop(b)
    a-=1
    b+=1
    count+=1
    if x==[]:
      print(count)
      break


### FIXED CODE ###

n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
y=[]
for i in range(len(x)-1):
  y+=[x[i+1]-x[i]]
y.sort()
if n>=m:
  print(0)
else:
  print(sum(y[:m-n]))
N, K = map(int,input().split())
List = list(map(int,input().split()))
Newlist = [1]
a=1
for i in range(N):
    a = List[a-1]
    if a==Newlist[i-1]:
        print(a)
        break
    elif a in Newlist:
        Cicle = Newlist[Newlist.index(a):Newlist[i-1]]
        print(Cicle[(K-i)%len(Cicle)-1])
        break
    else:
        Newlist.append(a)
else:
  print(a)

### FIXED CODE ###

N, K = map(int,input().split())
ls_pass = [0]+list(map(int,input().split()))
a=1
b=0

ls=["ンゴ"]+[0]+["ンゴ"]*(N-1)
ls_past=[1]
for i in range(1,N*3):
  b=a
  a=ls_pass[a]
  if ls[a]!="ンゴ":
    ls_cicle=ls_past[ls[a]:i]
    print(ls_cicle[(K-i)%len(ls_cicle)])
    break
  elif i==K:
    print(a)
    break  
  else:
    ls_past.append(a)
    ls[a]=i
while 1:
  h, w = map(int, raw_input().stlip())
  if h == 0 and w == 0:
    break
  for i in range(h):
    print "#" * w
print

### FIXED CODE ###

while 1:
  h, w = map(int, raw_input().split())
  if h == 0 and w == 0:
    break
  for i in range(h):
    print "#" * w
  print""
N,K = map(int,input().split())
S = input()
print(S[:k-1] + S[K-1].lower() + S[k-2:])


### FIXED CODE ###

N,K = map(int,input().split())
S = input()
print(S[:K-1] + S[K-1].lower() + S[K:])
import sys
sys.setrecursionlimit(10 ** 6)


def input():
    return sys.stdin.readline()[:-1]


N, K = map(int, input().split())
H = [0]*N
for i in range(N):
    H[i] = int(input())

H.sort()
ans = 10**10
for i in range(N-(K-1)):
    ans = min(ans, max(H[i], H[i+1], H[i+2])-min(H[i], H[i+1], H[i+2]))
print(ans)


### FIXED CODE ###

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

hl = []
for _ in range(n):
    hl.append(int(input()))

hl.sort()

ans = 10**9+1
for i in range(len(hl)-k+1):
    ans = min(ans, hl[i+k-1]-hl[i])

print(ans)
def lcs():
???x, y = raw_input()
???x_len = len(x)
  y_len = len(y)
  z2 = [0 for i in range(y_len+1)]

???for j in range(x_len):
   z1 = z2 + []
    for k in range(y_len):
       if x[k] = y[k]:
          z2[k+1] = z2[k] + 1
       elif z2[j+1] < z2[j]:???
?????????    z2[j+1] = z2[j]

  return z2[-1]

num = input()
for l in range(num):
  print lcs()

### FIXED CODE ###

def lcs():
  x = raw_input()
  y = raw_input()
  x_len = len(x)
  y_len = len(y)
  z2 = [0 for i in range(y_len+1)]

  for i in range(x_len):
    z1 = z2 + []
    ele = x[i]
    for k in range(y_len):
      if ele == y[k]:
        z2[k+1] = z1[k] + 1
      elif z2[k+1] < z2[k]:
        z2[k+1] = z2[k]

  return z2[-1]

num = input()
for j in range(num):
  print lcs()
res = 0
a_sort = sorted(a)
 
for i in range(n):
    if a_sort[i] == a[i]:
        res += 1
 
if res >= n - 2:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

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

cnt = 0
for i in range(N):
    if i + 1 == p[i]:
        cnt += 1

if cnt >= N - 2:
    print("YES")
else:
    print("NO")
import unionfind

### FIXED CODE ###

D, G = map(int, input().split())
PC = [list(map(int, input().split())) for i in range(D)]


def solve(G, i):
    if i <= 0:
        return float('inf')
    n = min(int(G/(100*i)), PC[i-1][0])
    score = 100 * i * n
    if n == PC[i-1][0]:
        score += PC[i-1][1]
    if G > score:
        n += solve(G-score, i-1)
    return min(n, solve(G, i-1))


print(solve(G, D))
X,N = map(int,input().split())
P = [int(input()) for i in range(N)]

L = sorted([abs(X-p) for p in P])
if 0 not in L :
    print(X)
    exit()

DL = list(set([x for x in L if L.count(x) > 1]))

ans_abs = 1
for i,x in enumerate(DL) :
    if x == i+1 :
        ans_abs += 1
    else :
        break

if X-ans_abs in P :
    print(X+ans_abs)
else :
    print(X-ans_abs)


### FIXED CODE ###

import itertools
X,N = map(int,input().split())

if N == 0 :
    print(X)
    exit()

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

L = sorted([abs(X-p) for p in P])
if 0 not in L :
    print(X)
    exit()

DL = list(set([x for x in L if L.count(x) > 1]))

ans_abs = 1
for i,x in enumerate(DL) :
    if x == i+1 :
        ans_abs += 1
    else :
        break

if X-ans_abs in P :
    print(X+ans_abs)
else :
    print(X-ans_abs)
from decimal import Decimal
a, b = input().split()
a = int(a)
b = decimal.Decimal(b)
c = a*b*100//100
print(int(c))

### FIXED CODE ###

from decimal import Decimal
a, b = input().split()
a = int(a)
b = Decimal(b)
c = a*b*100//100
print(int(c))
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

import math
nm=list(map(int,input().split()))
a=list(map(int,input().split()))
lcm1=a[0]
for i in range(nm[0]-1):
    lcm1=lcm(lcm1, a[i+1])
answer=nm[1]//(lcm1)+1
print(answer)

### FIXED CODE ###

import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
c=a[0]
dnum=0
while c%2==0:
    dnum+=1
    c=c//2
for i in range(len(a)):
    c=a[i]
    dnum1=0
    while c%2==0:
        dnum1+=1
        c=c//2
    #print(dnum)
    if dnum1!=dnum:
        b=1
        break

#print(a)
if b==1:
    print(0)
else:
    for i in range(len(a)):
        a[i]=a[i]//2
    #print(a)
    amc=lcm_list(a)
    #print(amc)
    # version3.5にてgcdがfractionsからmathに移動した
    print(int((m+amc)/(2*amc)))
a = int(input())
b = int(input())
c = int(input())

print(c-(a-b))

### FIXED CODE ###

a,b,c=map(int, input().split())
 
print(max((c-(a-b)),0))
# -*- coding: utf-8 -*-
X, Y, A, B, C = map(int, input().split())
red_oishisa = list(map(int, input().split()))
green_oishisa = list(map(int, input().split()))
no_oishisa = list(map(int, input().split()))

red_oishisa = list(sorted(red_oishisa))[::-1]
green_oishisa = list(sorted(green_oishisa))[::-1]
no_oishisa = list(sorted(no_oishisa))[::-1]

eat_oishisas_red = red_oishisa[:X]
eat_oishisas_green = green_oishisa[:Y]

i=1
j=1
k=1
while(True):
    if i > A:
        break
    elif j > B:
        break
    elif k > C:
        break
    elif min([eat_oishisas_red[-i], eat_oishisas_green[-j]]) >= no_oishisa[k-1]:
        break

    if eat_oishisas_red[-i] <= eat_oishisas_green[-j]:
        eat_oishisas_red[-i] = no_oishisa[k-1]
        i += 1
    else:
        eat_oishisas_green[-j] = no_oishisa[k-1]
        j += 1
    k += 1

print(sum(eat_oishisas_green) + sum(eat_oishisas_red))

### FIXED CODE ###

# -*- coding: utf-8 -*-
X, Y, A, B, C = map(int, input().split())
red_oishisa = list(map(int, input().split()))
green_oishisa = list(map(int, input().split()))
no_oishisa = list(map(int, input().split()))

red_oishisa = list(sorted(red_oishisa))[::-1]
green_oishisa = list(sorted(green_oishisa))[::-1]
no_oishisa = list(sorted(no_oishisa))[::-1]

oishisa_s = []

i=1
j=1
k=1
while(True):
    if len(oishisa_s) == X+Y:
        break
    
    hikaku_dict = dict()
    if i <= X:
        hikaku_dict['red'] = red_oishisa[i-1]
    if j <= Y:
        hikaku_dict['green'] = green_oishisa[j-1]
    if k <= C:
        hikaku_dict['no'] = no_oishisa[k-1]
    
    max_key, max_value = max(hikaku_dict.items(), key=lambda x:x[1])
    oishisa_s.append(max_value)
    if max_key == 'red':
        i += 1
    elif max_key == 'green':
        j += 1
    elif max_key == 'no':
        k += 1

print(sum(oishisa_s))
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
num_count = int(input())
number_list = [0] * num_count
for i in range(num_count):
    number_list[i] = int(input())

bingo_map = [[a, b, c], [d, e, f], [g, h, i]]
bingo_answer = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

def bingo(bingo_map, number_list):
    for number in number_list:
        for i, bingo_row in enumerate(bingo_map):
            if number in bingo_row:
                for j, bingo_number in enumerate(bingo_row):
                    if bingo_number == number:
                        bingo_answer[i][j] = 1


def check_bingo():
    return (all(bingo_answer[0]) or all(bingo_answer[1]) or all(bingo_answer[2]) or
    all(bingo_answer[0][0], bingo_answer[1][0], bingo_answer[2][0]) or
    all(bingo_answer[0][1], bingo_answer[1][1], bingo_answer[2][1]) or
    all(bingo_answer[0][2], bingo_answer[1][2], bingo_answer[2][2]) or
    all(bingo_answer[0][0], bingo_answer[1][1], bingo_answer[2][2]) or
    all(bingo_answer[2][0], bingo_answer[1][1], bingo_answer[0][2]))

bingo(bingo_map, number_list)

if check_bingo():
    print "Yes"
else:
    print "No"


### FIXED CODE ###

a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, x = map(int, input().split())
num_count = int(input())
number_list = [0] * num_count
for i in range(num_count):
    number_list[i] = int(input())

bingo_map = [[a, b, c], [d, e, f], [g, h, x]]
bingo_answer = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

def bingo(bingo_map, number_list):
    for number in number_list:
        for i, bingo_row in enumerate(bingo_map):
            if number in bingo_row:
                for j, bingo_number in enumerate(bingo_row):
                    if bingo_number == number:
                        bingo_answer[i][j] = 1


def check_bingo():
    return (all(bingo_answer[0]) or all(bingo_answer[1]) or all(bingo_answer[2]) or
    all([bingo_answer[0][0], bingo_answer[1][0], bingo_answer[2][0]]) or
    all([bingo_answer[0][1], bingo_answer[1][1], bingo_answer[2][1]]) or
    all([bingo_answer[0][2], bingo_answer[1][2], bingo_answer[2][2]]) or
    all([bingo_answer[0][0], bingo_answer[1][1], bingo_answer[2][2]]) or
    all([bingo_answer[2][0], bingo_answer[1][1], bingo_answer[0][2]]))

bingo(bingo_map, number_list)

if (check_bingo()):
    print("Yes")
else:
    print("No")
N,K=map(int,input().split())
mod=10**9+7

C=[[1]*(i+1) for i in range(N)]
for i in range(2,N):
  for j in range(1,i):
    C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod

for i in range(1,K+1):
  print((C[N-K+1][i]*C[K-1][i-1])%mod)

### FIXED CODE ###

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

C=[[1]*(i+1) for i in range(N+1)]
for i in range(2,N+1):
  for j in range(1,i):
    C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod

for i in range(1,K+1):
  if N-K+1<i:
    print(0)
  else:
    print((C[N-K+1][i]*C[K-1][i-1])%mod)
N, T = list(map(int, input().split()))

path = []
for _ in range(N):
  c, t = list(map(int, input().split()))
  if t <= T:
    path.append(c)
sort(path)
reverse(path)
if len(path) > 0:
  print(path[0])
else:
  print(path[0])

### FIXED CODE ###

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

path = []
for _ in range(N):
  c, t = list(map(int, input().split()))
  if t <= T:
    path.append(c)
path.sort()
if len(path) > 0:
  print(path[0])
else:
  print('TLE')
K,N = input().split()
A = input().split()

a_list = list(A)

dist = 0
max = 0
sum = 0

for i in range(len(a_list)):
  if i == len(int(a_list)) - 1:
    dist = abs(int(a_list[i]) - int(a_list[0]))
  else:
    dist = abs(int(a_list[i]) - int(a_list[i + 1]))
  
  if max < dist:
    sum += max
    max = dist
  else:
    sum += dist
    
print(sum)
  

### FIXED CODE ###

K,N = input().split()
A = input().split()
 
a_list = list(A)

dist = 0
dist_list = []
max = 0
sum = 0
 
for i in range(len(a_list)):
  if i == len(a_list) - 1:
    dist = int(K) - abs(int(a_list[i]) - int(a_list[0]))
  else:
    dist = abs(int(a_list[i]) - int(a_list[i + 1]))
  if i != 0: 
    if max < dist:
        sum += max
        max = dist
    else:
        sum += dist
  else:
      max = dist
  
    
print(sum)
O = input()
E = input()

S = ''
for i in range(len(O)):
    S += O[i]
    S += E[i]

print(S)


### FIXED CODE ###

O = input()
E = input()

S = ''
for i in range(len(O)):
    S += O[i]
    if len(E) > i:
        S += E[i]

print(S)
x=input()
b=int(x[0])
c=int(x[2])
a=b-c+1
print(a)

### FIXED CODE ###

x=input()
xx=x.split()
b=int(xx[0])
c=int(xx[1])
a=b-c+1
print(a)
a = int(input()split())
b = int(input()split())
print((a*b),(a+b)*2)

### FIXED CODE ###

a,b=[int(i) for i in input().split()]
print(a*b,(a+b)*2)
N,A,B,C=map(int,input().split())
S=['']*N
for a in range(N):
    S[a]=input()

ans='Yes'
L_ans=['']*(N+1)
i=0
while i<N:
    if S[i]=='AB':
        if A>B:
            B+=1
            A-=1
            L_ans[i]='B'
        elif A<B:
            A+=1
            B-=1
            L_ans[i]='A'
        elif A==B and S[i+1]=='BC':
            B+=1
            A-=1
            L_ans[i]='B'
        else:
            A+=1
            B-=1
            L_ans[i]='A'
    elif S[i]=='AC':
        if A>C:
            C+=1
            A-=1
            L_ans[i]='C'
        elif A<C:
            A+=1
            C-=1
            L_ans[i]='A'
        elif A==C and S[i+1]=='BC':
            C+=1
            A-=1
            L_ans[i]='C'
        else:
            A+=1
            C-=1
            L_ans[i]='A'
    elif S[i]=='BC':
        if C>B:
            B+=1
            C-=1
            L_ans[i]='B'
        elif C<B:
            C+=1
            B-=1
            L_ans[i]='C'
        elif B==C and S[i+1]=='AB':
            B+=1
            C-=1
            L_ans[i]='B'
        else:
            C+=1
            B-=1
            L_ans[i]='C'
    i+=1
    if any([A<0,B<0,C<0]):
        ans='No'
        break

print(ans)
if ans=='Yes':
    j=0
    while j<N:
        print(L_ans[j])
        j+=1

### FIXED CODE ###

N,A,B,C=map(int,input().split())
S=['']*(N+1)
for a in range(N):
    S[a]=input()

ans='Yes'
L_ans=['']*(N+1)
i=0
while i<N:
    if S[i]=='AB':
        if A>B:
            B+=1
            A-=1
            L_ans[i]='B'
        elif A<B:
            A+=1
            B-=1
            L_ans[i]='A'
        elif A==B and S[i+1]=='BC':
            B+=1
            A-=1
            L_ans[i]='B'
        else:
            A+=1
            B-=1
            L_ans[i]='A'
    elif S[i]=='AC':
        if A>C:
            C+=1
            A-=1
            L_ans[i]='C'
        elif A<C:
            A+=1
            C-=1
            L_ans[i]='A'
        elif A==C and S[i+1]=='BC':
            C+=1
            A-=1
            L_ans[i]='C'
        else:
            A+=1
            C-=1
            L_ans[i]='A'
    elif S[i]=='BC':
        if C>B:
            B+=1
            C-=1
            L_ans[i]='B'
        elif C<B:
            C+=1
            B-=1
            L_ans[i]='C'
        elif B==C and S[i+1]=='AB':
            B+=1
            C-=1
            L_ans[i]='B'
        else:
            C+=1
            B-=1
            L_ans[i]='C'
    i+=1
    if any([A<0,B<0,C<0]):
        ans='No'
        break

print(ans)
if ans=='Yes':
    j=0
    while j<N:
        print(L_ans[j])
        j+=1
S = input()

days = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'}
print(7 - days.index(S))

### FIXED CODE ###

S = input()

days = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - days.index(S))
N = int(input())
A = list(map(int,input().split()))
PI = 1
for i in range(N):
    PI = PI*A[i]
if PI > 10**(18):
    print(-1)
    break
print(PI)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
PI = 1
if 0 in A:
    PI = 0
else:
    for i in range(N):
        PI = PI*A[i]
        if PI > 10**(18):
            PI = -1
            break
print(PI)