Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))

sum = 0

a_num = 0
for i in range(N):
    sum += a_time[i]
    a_num += 1
    if sum > K:
        sum -= a_time[i]
        a_num -= 1
        break
i = a_num
while i >= 0:
    sum -= a_time[i]
    for j in range(M):
        sum += b_time[j]
        if sum > K:
            sum -= b_time[j]
            break
    if result < i + j:
        result = i + j
    i -= 1

print(result)


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))

sum = 0

a_num = 0
for i in range(N):
    sum += a_time[i]
    a_num += 1
    if sum > K:
        sum -= a_time[i]
        a_num -= 1
        break
i = a_num
j = 0
while i >= 0:
    while sum < K and j < M:
        sum += b_time[j]
        j += 1
    if sum > K:
        j -= 1
        sum -= b_time[j]
    if result < i + j:
        result = i + j
    i -= 1
    sum -= a_time[i]

print(result)
import sys
def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1,0,1,0]
DY = [0,-1,0,1]
sys.setrecursionlimit(10**7)
while True:
	line = input()
	if " " in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(N)] for j in range(M)]
	else:
		tile[counter-1] = list(line)
	if N is 0 and M is 0:
		break
	if counter is M:
		solve()
		counter = 0
	counter += 1

### FIXED CODE ###

# -*- coding:utf-8 -*-
import sys
def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1,0,1,0]
DY = [0,-1,0,1]
sys.setrecursionlimit(10**7)
while True:
	line = input()
	if " " in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(M)] for j in range(N)]
	else:
		tile[counter-1] = list(line)
	if N is 0 and M is 0:
		break
	counter += 1
	if counter-1 is N:
		solve()
		counter = 0
N=int(inout())
L=list(map(int,input().split()))
T=0
for i in range(N):
  T+=L[i]  
if max(L)>T-max(L):
  print("Yes")
else:
  print("No")
  


### FIXED CODE ###

N=int(input())
L=list(map(int,input().split()))
T=0
for i in range(N):
  T+=L[i]  
if max(L)<T-max(L):
  print("Yes")
else:
  print("No")
def f(x, y):
    return x+y/2

x = int(input())
y = int(input())
print(f(x,y))

### FIXED CODE ###

x, y = tuple(map(int, input().split()))

print(int(x + y /2))
N = int(input())
edges = [[] for _ in range(N+1)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    edges[u].append([v, w])
    edges[v].append([u, w])
parent = [0 for _ in range(N)]
ans = [0 for _ in range(N)]


def dfs(edge, pd):
    for child, d in edges[edge]:
        if parent[child-1] == edge:
            continue
        cd = pd + d
        if cd % 2 == 0:
            ans[child-1] = 0
        else:
            ans[child-1] = 1
        parent[child-1] = edge
        dfs(child, cd)


def solve():
    dfs(1, 0)
    for i in range(N):
        print(ans[i])


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

N = int(input())
edges = [[] for _ in range(N+1)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    edges[u].append([v, w])
    edges[v].append([u, w])
ans = [-1 for _ in range(N)]


def dfs(edge, pd):
    for child, d in edges[edge]:
        if ans[child-1] != -1:
            continue
        cd = pd + d
        if cd % 2 == 0:
            ans[child-1] = 0
        else:
            ans[child-1] = 1
        dfs(child, cd)


def solve():
    dfs(1, 0)
    for i in range(N):
        print(ans[i])


if __name__ == '__main__':
    solve()
L, R = map(int, input().split())
C = []
flag = False
for i in range(L, R+1):
    if i%2019==0:
        flag = True
        break
    else:
        C.append(i)
        
if flag:
    print(0)
else:
    ans = 4080400
    for x, y in list(itertools.combinations(C, 2)):
        if (x*y)%2019<ans:
            ans = (x*y)%2019
    print(ans)

### FIXED CODE ###

L, R = map(int, input().split())
C = []
flag = False
for i in range(L, R+1):
    if i%2019==0:
        flag = True
        break
    else:
        C.append(i)
        
if flag:
    print(0)
else:
    import itertools
    ans = 4080400
    for x, y in list(itertools.combinations(C, 2)):
        if (x*y)%2019<ans:
            ans = (x*y)%2019
    print(ans)
s = input("")
s1 = s[0:(n-1)/2]
s2 = s[(n+3)/2-1:]

if (s1 == s1[::-1] and s2 == s2[::-1]):
	print("Yes")
else:
  	print("No")
    

### FIXED CODE ###

s = input('')
n = len(s)
s1 = s[0:(n-1)//2]
s2 = s[(n+3)//2-1:]

if (s == s[::-1] and s1 == s1[::-1] and s2 == s2[::-1]):
	print("Yes")
else:
  	print("No")
# -*- coding: utf-8 -*-

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

P_set = list(set(P))
#print(P_set)
#print(P_set[1])

ans_chk = 0

if ( X < P_set[0] or X > P_set[N-1] ):
  print(X)
  ans_chk = 1

if ( ans_chk==0 ):
  for i in range(len(P)):
    if ( P_set[i] == X ):
      X_i = i
      break
    elif ( P_set[i] > X ):
      print(X)
      ans_chk = 1
      break

if ( ans_chk==0 ):
  
  if ( X_i >= N-(X_i+1) ): # 上の数が少ない → 下は1回多くする
    M = N-(X_i+1)
    temp_ans = X + N-(X_i+1) +1
    #print("temp_ans =",temp_ans)
    
    for i in range(1,M+1):
      print(i)
      if ( P_set[ X_i -i ] != X-i ):
        print(X-i)
        ans_chk = 1
        break
      elif ( P_set[ X_i +i ] != X+i ):
        print(X+i)
        ans_chk = 1
        break
    
    if ( ans_chk==0 ):
      if ( P_set[ X_i -(M+1) ] != X-(M+1) ):
        print( X-(M+1) )
        ans_chk = 1


  else: # 下の数が少ない → そのまま
    M = X_i
    temp_ans = X - X_i -1
    #print("temp_ans =",temp_ans)
  
    for i in range(1,M+1):
      print(i)
      if ( P_set[ X_i -i ] != X-i ):
        print(X-i)
        ans_chk = 1
        break
      elif ( P_set[ X_i +i ] != X+i ):
        print(X+i)
        ans_chk = 1
        break

if ( ans_chk==0 ):
  print(temp_ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-

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

if( N == 0 ):
  #print("N=0")
  print(X)

else:
  P = list(map(int,input().split()))
  P_set = list(set(P))
  
  
  ans_chk = 0
  
  if ( X < P_set[0] or X > P_set[N-1] ):
    #print("X < P_set[0] or X > P_set[N-1]")
    print(X)
    ans_chk = 1
  
  if ( ans_chk==0 ):
    for i in range(N):
      if ( P_set[i] == X ):
        X_i = i
        break
      elif ( P_set[i] > X ):
        #print("P_set[i] > X")
        print(X)
        ans_chk = 1
        break
  
  if ( ans_chk==0 ):
    
    if ( X_i > N-(X_i+1) ): # 上の数が少ない → 下は1回多くする
      M = N-(X_i+1)
      temp_ans = X + N-(X_i+1) +1
      #print("temp_ans =",temp_ans)
      
      for i in range(1,M+1):
        if ( P_set[ X_i -i ] != X-i ):
          print(X-i)
          ans_chk = 1
          break
        elif ( P_set[ X_i +i ] != X+i ):
          print(X+i)
          ans_chk = 1
          break
      
      if ( ans_chk==0 ):
        if ( P_set[ X_i -(M+1) ] != X-(M+1) ):
          print( X-(M+1) )
          ans_chk = 1
  
  
    else: # 下の数が少ないor同数 → そのまま
      M = X_i
      temp_ans = X - X_i -1
      #print("temp_ans =",temp_ans)
    
      for i in range(1,M+1):
        if ( P_set[ X_i -i ] != X-i ):
          print(X-i)
          ans_chk = 1
          break
        elif ( P_set[ X_i +i ] != X+i ):
          print(X+i)
          ans_chk = 1
          break
  
  if ( ans_chk==0 ):
    print(temp_ans)
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
if (a[1]-a[0]) < 0: flag = -1
else: flag = 1
ans = 1
i = 0
while True:
    if flag * (a[i+1]-a[i]) < 0:#増加
        ans += 1
        flag = -1 * flag
        i += 1
    i += 1
    if i == n-1:
        break
    elif i == n:
        ans += 1
        break
print(ans)
    

### FIXED CODE ###

#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
bit = 0
ans = 1
i = 0
while i < n-1:
    if a[i+1] == a[i]: pass
    if bit == 0:
        bit = a[i+1]-a[i]
        #ans += 1
    else:#bit が立っているなら符号が一致するかを見て一致しないならans +=  1
        if bit * (a[i+1]-a[i]) < 0:#符号不一致
            bit = 0 
            ans += 1 
    i += 1
print(ans)
import numpy as np
N,M,X = map(int,input().split())
datas = []
point = [0]*M
m = 0
max = 0
count = 0
for i in range(N):
    datas.append(list(map(int,input().split())))
print(datas)
while 1:
    for data in datas:
        if sum(data[1:-1]) > max:
            ans = count
            max = sum(data[1:-1])
        count += 1
    for i in range(M):
        point[i] += datas[ans][i+1]
    m += datas[ans][0]
    if all([x >= 10 for x in point]):
        print(m)
        break
    datas.pop(ans)
    if len(datas) == 0:
        print(-1)
        break
    max,ans,count = 0,0,0


### FIXED CODE ###

import itertools
N,M,X = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
B = list(itertools.product([0,1], repeat=N))
sums = {}
anss = []
for i in range(N):
    for b in B:
        ans = 0
        Point = [0]*M
        count = 0
        for z in b:
            if z == 1:
                for k in range(M):
                    Point[k] += A[count][k+1]
                ans += A[count][0]
                if M == len([Point[n] for n in range(M) if Point[n] >= X]):
                    anss.append(ans)
            count += 1
if len(anss) != 0:
    print(min(anss))
else:
    print(-1)
x = int(input())
y = int(input())
print(int((x*3+y)/2))

### FIXED CODE ###

x, y = [int(i) for i in input().split()]
print(int((x*3+y)/2))
import copy
H, W = (list)(map(int, input().split()))
grid = [[lin for lin in input()] for _ in range(H)]

mat = [['&'] * (W+2) for _ in range(H+2)]
for row in range(1, H+1):
    for col in range(1, W+1):
        mat[row][col] = grid[row-1][col-1]


def search(x, row, col, mat):
    ran = [-1, 1]
    ret = []
    for i in ran:
        if mat[row+i][col] == x:
            ret.append([row+i, col])
        if mat[row][col+i] == x:
            ret.append([row, col+i])

    return ret


def bfs(row, col, mat):
    ret = 0
    mat[row][col] = '&'

    res = search('.', row, col, mat)

    ret += len(res)
    for cand in res:
        mat[cand[0]][cand[1]] = '&'

    for cand in res:
        res2 = search('#', cand[0], cand[1], mat)
        for cand2 in res2:
            res3 = bfs(cand2[0], cand2[1], mat)
            ret += res3
    return ret


ans = 0

for row in range(1, H+1):
    for col in range(1, W+1):
        if mat[row][col] == '#':
            mat_copy = copy.deepcopy(mat)
            ans += bfs(row, col, mat_copy)

print(ans)


### FIXED CODE ###

# https://atcoder.jp/contests/aising2019/submissions/3986315
# 解説のように 連結成分を求めてから、bfsする
import sys
sys.setrecursionlimit(2 * 10 ** 5)

H, W = map(int, input().split())
s = [input() for _ in range(H)]

ans = 0

dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

un_reached = [[True for i in range(W)] for j in range(H)]


def isIn(x, y):
    return 0 <= x < H and 0 <= y < W


def dfs(x, y):
    un_reached[x][y] = False
    if s[x][y] == '#':
        cc[1] += 1
    else:
        cc[0] += 1

    for i in range(4):
        nx = x+dx[i]
        ny = y+dy[i]
        if isIn(nx, ny) and s[nx][ny] != s[x][y] and un_reached[nx][ny]:
            dfs(nx, ny)


for i in range(H):
    for j in range(W):
        if un_reached[i][j]:
            cc = [0 for _ in range(2)]
            dfs(i, j)
            ans += cc[1]*cc[0]
print(ans)
import sys
sys.setrecursionlimit(2 ** 2000)
n = int(input())
a = list(map(int, input().split()))
a = [(i, v) for i, v in enumerate(a)]
a.sort(key=lambda x: x[1], reverse=True)

dp = [[-1] * (m + 1) for m in range(n + 1)]
# m: 何人選んだか, l: 左を選んだ人数
def f(m, l):
    if m == n: return 0
    if dp[m][l] != -1: return dp[m][l]
    r = n - m + l - 1
    i, v = a[m]
    if i >= l: dp[m + 1][l + 1] = f(m + 1, l + 1)
    if i <= r: dp[m + 1][l] = f(m + 1, l)
    return max(dp[m + 1][l + 1] + v * (i - l), dp[m + 1][l] + v * (r - i))
print(f(0, 0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(2000 * 2)
n = int(input())
a = list(map(int, input().split()))
a = [(i, v) for i, v in enumerate(a)]
a.sort(key=lambda x: x[1], reverse=True)

dp = [[-1] * (m + 1) for m in range(n + 1)]
# m: 何人選んだか, l: 左を選んだ人数
def f(m, l):
    if m == n: return 0
    if dp[m][l] != -1: return dp[m][l]
    r = n - m + l - 1
    i, v = a[m]
    if i >= l: dp[m + 1][l + 1] = f(m + 1, l + 1)
    if i <= r: dp[m + 1][l] = f(m + 1, l)
    return max(dp[m + 1][l + 1] + v * (i - l), dp[m + 1][l] + v * (r - i))
print(f(0, 0))
l = list(map(int, input().split()))

while(l != None):
    print(len(str(l[0]+l[1])))
    l = list(map(int, input().split()))


### FIXED CODE ###

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

while(l != []):
    try:
        length = len(str(l[0]+l[1]))
        print(length)
        l = list(map(int, input().split()))
    except:
        break
"""
~~ Author : Bhaskar
~~ Dated : 10~06~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
ch = "abcdefghijklmnopqrstuvwxyz"
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")
input = lambda : sys.stdin.readline()

def solve():
    n = int(sys.stdin.readline())
    print(a+a**2+a**3)


if __name__ == "__main__":
    try:
        sys.stdin = open('input.txt','r')
        sys.stdout = open('output.txt','w')
    except:
       pass
    solve()



### FIXED CODE ###

"""
~~ Author : Bhaskar
~~ Dated : 10~06~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
ch = "abcdefghijklmnopqrstuvwxyz"
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")
input = lambda : sys.stdin.readline()

def solve():
    n = int(sys.stdin.readline())
    print(n + n ** 2 + n ** 3)
    


if __name__ == "__main__":
    try:
        sys.stdin = open('input.txt','r')
        sys.stdout = open('output.txt','w')
    except:
       pass
    solve()
n,m=map(int,input().split())
a=[int(input())for _ in range(m)]
mod=10**9+7
if n==1:
	print(1)
	exit()
dp = [0]*(n+1)
dp[0]=1
dp[1]=1 if a[0]!=1 else 0

for i in range(2,n+1):
	if i in a:
		continue
	dp[i] = dp[i-2]+dp[i-1]
	dp[i]%=mod
print(dp[n])


### FIXED CODE ###

n,m=map(int,input().split())
dic =[0]*1234567
for _ in range(m):
	dic[int(input())]+=1

mod=10**9+7
if n==1:
	print(1)
	exit()
dp = [0]*(n+1)
dp[0]=1
dp[1]=1 if dic[1]!=1 else 0

for i in range(2,n+1):
	if dic[i]:
		continue
	dp[i] = dp[i-2]+dp[i-1]
	dp[i]%=mod
print(dp[n])
from itertools import permutations

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

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

for i in range(len(r)):
    r[i]-=1
    
A=[]
a=[]
for i in range(N):
    for j in range(N):
        a.append(1000000)
    A.append(a)
    a=[]
#print(A)

for i in range(M):
    a,b,c=map(int,input().split())
    A[a-1][b-1]=c
    A[b-1][a-1]=c
#print(A)

for c in range(N):
    for a in range(N):
        for b in range(N):
            A[a][b]=min(A[a][b],A[a][c]+A[c][b])
#print(A)

ans=10000000
for i in permutations(r,len(r)):
    cnt=0
    for j in range(len(i)-1):
        cnt+=A[i[j]][i[j+1]]
    if ans>cnt:
        ans=cnt
print(ans)


### FIXED CODE ###

N=input()
if N[0]=="9" or N[1]=="9":
    print("Yes")
else:
    print("No")
A, B = input().split()
a = int(A)
b = float(B)
ib = int(B*100)

print(int((a*ib)/100))



### FIXED CODE ###

from decimal import *
import math

A, B = input().split()
a = Decimal(A)
b = Decimal(B)
ib = Decimal(100*b)

print(math.floor((a*ib)/Decimal(100)))
n, t, m = int(input()), list(map(int, input().split())), int(input())
p, x = [], []
for i in range(m):
  q, y = map(int, input().split())
  p[i] = q
  x[i] = y
s = sum(t)
for j in range(m):
  print(sum - t[i] + x[i])

### FIXED CODE ###

n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = []
x = []
for i in range(m):
  q, y = map(int, input().split())
  p.append(q)
  x.append(y)
  
s = sum(t)
for j in range(m):
  print(s - t[p[j]-1] + x[j])
f = open(0).read()

while True:


    
    num = int(input())

    if num == 0:
        break
    
    scores = input().split()
    
    for i in range(num):
        scores[i] = float(scores[i])

    avr = sum(scores) / num
    
    daviation = 0
    
    for a in scores:
        disp = (a - avr)**2/num
        daviation += disp
        p

    print(round(math.sqrt(daviation),8))


### FIXED CODE ###

import math

daviations = []

while True:
    
    num = int(input())

    if num == 0:
        break
    
    scores = input().split()
    
    for i in range(num):
        scores[i] = float(scores[i])

    avr = sum(scores) / num
    
    daviation = 0
    
    for a in scores:
        disp = (a - avr)**2/num
        daviation += disp
        
        
        
    daviations.append(round(math.sqrt(daviation),8))
    
for b in daviations:
        print(b)
a,b = int(),input().split()
if a < b:
    print("a<b")
elif a > b:
    print("a>b")
else a == b:
    print("a==b")


### FIXED CODE ###

a,b = input().split()
a = int(a)
b = int(b)
if a < b:
    print("a < b")
elif a > b:
    print("a > b")
else:
    print("a == b")
if __name__ == '__main__':
    sys.setrecursionlimit(10 ** 6)
    b, c = map(int, input().split())
    num = b*3 -c
    if num == 0:
        num =1
    else:
        if num > b:
            num = b*3
        else:
            num = num *3
    print(num)




### FIXED CODE ###

if __name__ == '__main__':
    b, c = map(int, input().split())
    num = b*3 -c

    count = 0
    for i in range (0,b+1):
        for j in range(0,b+1):
            if c-(i+j)<=b and c-(i+j) >=0:
                count+=1
    print(count)
n,m = map(int,input().split())

in_p = []
in_y = []
p = []

for i in range(n):
    p.append([])

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

    p = sorted(p, key = lambda x:x[:])

for i in range(m):
    year=str(in_p[i]).zfill(6)
    a = p[in_p[i]-1].index(in_y[i]) + 1
    num=str(a).zfill(6)
    print("{0}{1}".format(year,num))



### FIXED CODE ###

import copy

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

cnt = [0]*(10**5+4)

yy = []
yp = []
for _ in range(m):
    a,b = map(int,input().split())
    a,b = b,a
    yy.append([a,0])
    yp.append([a,b])

inlist = copy.deepcopy(yp)
yp.sort()
yy = dict(yy)

for i in range(m):
    cnt[yp[i][1]]+=1
    yy[yp[i][0]] = cnt[yp[i][1]]

for key,value in inlist:
    print("{:06}{:06}".format(value,yy[key]))
A = int(input())
B = int(input())

if A >= 13 and A <= 100:
    print(B)
elif 6 <= A and A <= 12:
    print(B/2)
elif 0 <= A and A <= 5:
    print(0)

### FIXED CODE ###

def main():
    i = list(map(int, input().split()))
    a = i[0]
    b = i[1]

    #if isinstance(a, int) == False or isinstance(b, int) == False or a < 0 or 100 < a or b < 2 or 1000 < b or b % 2 != 0:
    #    return

    if 13 <= a and a <= 100:
        print(b)
    elif 6 <= a and a <= 12:
        print(b//2)
    elif 0 <= a and a <= 5:
        print(0)

if __name__ == "__main__":
    main()
n,m = map(int,raw_input().strip().split(' '))
graph = [[] for i in range(n)]
for i in range(m):
    s,t = map(int,raw_input().strip().split(' '))
    graph[s].append(t)
    graph[t].append(s)
 
color = {}
c = 0
for i in range(n):
    if not i in color:
        que = [i]
        color[i] = c
        if len(que) > 0:
       //  for j in range(len(que)):
            u = que[0]
            for v in graph[u]:
                if not v in color:
                    color[v] = c
                    que.append(v)
            del que[0]
        c += 1

### FIXED CODE ###

n,m = map(int,raw_input().strip().split(' '))
graph = [[] for i in range(n)]
for i in range(m):
    s,t = map(int,raw_input().strip().split(' '))
    graph[s].append(t)
    graph[t].append(s)
color = {}
c = 0
for i in range(n):
    if not i in color:
        que = [i]
        color[i] = c
        while len(que) > 0:
            u = que[0]
            for v in graph[u]:
                if not v in color:
                    color[v] = c
                    que.append(v)
            del que[0]
        c += 1
q = int(raw_input())
for i in range(q):
   s,t = map(int,raw_input().strip().split(' '))
   if color[s] == color[t]:
     print 'yes'
   else:
     print 'no'
N, M = [int(nm) for nm in input().split()]
X = [int(x) for x in input().split()]

if N > M:
  print(0)
else:
  X.sort()
  mn_X = X[0]
  for m in range(M):
    X[m] = X[m] - mn_X #一番座標が小さい点を原点とする

  DX = [] #隣り合う二点間の距離
  for mm in range(M-1):
    dx = X[mm+1] - X[mm] #隣り合う二点間の距離を求める
    DX.append(dx)
  #print(DX)
  
  DXX = list(tuple(DX))
  DXX.sort(reverse=True) #DXXのi=0,1,2,...,N-2、つまり大きい値を取ってきたい
  I = [] #「XをN個に分割するとき、どの座標で分割するか」
  for i in range(N-1):
    big_dx = DXX[i]
    idx = DX.index(big_dx)
    I.append(idx)
  I.sort()
  #print(I)
  
  #最初のコマは原点に置く
  move = X[I[0]] - 0
  #print(move)
  
  for j in range(0, N-2):
    move += (X[I[j+1]] - X[I[j]+1])
  #print(move)
  
  #最後のコマ
  move += (X[-1] - X[I[N-2]+1])
  
  print(move)

### FIXED CODE ###

N, M = [int(nm) for nm in input().split()]
X = [int(x) for x in input().split()]

if N >= M:
  print(0)
elif N == 1:
  ans = max(X) - min(X)
  print(ans)
else:
  X.sort()
  mn_X = X[0]
  for m in range(M):
    X[m] = X[m] - mn_X #一番座標が小さい点を原点とする

  DX = [] #隣り合う二点間の距離
  for mm in range(M-1):
    dx = X[mm+1] - X[mm] #隣り合う二点間の距離を求める
    DX.append(dx)
  #print(DX)
  
  DXX = list(tuple(DX))
  DXX.sort(reverse=True) #DXXのi=0,1,2,...,N-2、つまり大きい値を取ってきたい
  I = [] #「XをN個に分割するとき、どの座標で分割するか」
  for i in range(N-1):
    big_dx = DXX[i]
    idx = DX.index(big_dx)
    I.append(idx)
  I.sort()
  #print(I)
  
  #最初のコマは原点に置く
  move = X[I[0]] - 0
  #print(move)
  
  for j in range(0, N-2):
    move += (X[I[j+1]] - X[I[j]+1])
  #print(move)
  
  #最後のコマ
  move += (X[-1] - X[I[N-2]+1])
  
  print(move)
import numpy as np
def kouho(x, y, h):
    if h:
        return np.abs(np.arange(101) - x)[:, np.newaxis]  + np.abs(np.arange(101) - y) [np.newaxis] + h

n = int(input())
arrs = []
for _ in range(n):
    arrs.append(kouho(*(map(int, input().split()))))
arrs = np.array(arrs)
for i in range(101):
  for j in range(101):
    if np.all(arrs[:,i,j]==arrs[0,i,j]):
      print(i, j, arrs[0, i, j])
      break

### FIXED CODE ###

def ni(): 
    return int(input())
def li():
    return map(int, input().split())

xyh = [tuple(li()) for _ in range(ni())]
xmax, ymax, hmax = max(xyh, key=lambda _: _[-1])

for x_cent in range(101):
    for y_cent in range(101):
        h_cent = hmax + abs(xmax-x_cent) + abs(ymax-y_cent)
        
        for x, y, h in xyh:
            if h != max(0, h_cent - abs(x-x_cent) - abs(y-y_cent)):
                break
        else:
            print(x_cent, y_cent, h_cent)