Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

X=int(input())
list=[1]
for i in range(1, X):
  for j in range(2, X):
    if i**j<=X:
      list.append(i**j)
print(max(list))

### FIXED CODE ###

X=int(input())
list=[1]
for i in range(1, X):
  for j in range(2, X):
    if (i**j)<=X:
      list.append(i**j)
    else:break
print(max(list))
### BUGGY CODE ###

k, n = map(int,input().split())
xs = list(map(int,input().split()))
xs = xs + [x+k for x in xs]

ans = float('inf')
for i in range(n):
    a = xs[i:i+n]
    delta = a[-1] - a[0]
    ans = min(delta, ans)

print(ans)

### FIXED CODE ###

k, n = map(int,input().split())
xs = list(map(int,input().split()))
xs = xs + [x+k for x in xs]

ans = float('inf')
for i in range(n):
    delta = xs[i+n-1] - xs[i]
    ans = min(delta, ans)

print(ans)
### BUGGY CODE ###

import math

Q = int(input())

def isprime(n):
    if n < 2 : return False
    if n == 2 : return True
    if n % 2 == 0 : return False
    
    for i in range(3,int(math.sqrt(n))+1,2):
        if n % i == 0:
            return False
    return True
        

for i in range(Q):
    count_prime = 0
    l,r = map(int, input().split())
    for i in range(l,r+1,2):
        if(isprime(i) and isprime((i+1)/2)):
            count_prime += 1
    print(count_prime)

### FIXED CODE ###

import math
Q_SIZE = int(math.pow(10,5))
Q = int(input())

Check_Prime = [True for i in range(Q_SIZE+1)]
Count_like = [0 for i in range(Q_SIZE//2)]

Check_Prime[0] = False
Check_Prime[1] = False

for i in range(2,Q_SIZE+1):
    if(Check_Prime[i] == True):
        for j in range(i+i,Q_SIZE+1,i):
            Check_Prime[j] = False
            
for i in range(1,Q_SIZE//2):
    if(Check_Prime[i*2+1] == True and Check_Prime[int(((i*2+1)+1)/2)] == True):
        Count_like[i] = Count_like[i-1] + 1
    else:
        Count_like[i] = Count_like[i-1]

for i in range(Q):
    l,r = map(int,input().split())
    if( l == 1):
        print(Count_like[r//2] - Count_like[l//2])
    else:
        print(Count_like[r//2] - Count_like[l//2 - 1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n=int(input())
a=[int(j) for j in input().split()]
dp=[[0]*(n+1) for i in range(n+1)]

for i in range(n)[::-1]:
    for j in range(i,n):
        if (n+i-j-1)%2==0:
            dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j])
        else:
            dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j])
print(dp[0][n-1])



### FIXED CODE ###

n=int(input())
a=[int(j) for j in input().split()]
dp=[[0]*(n+1) for i in range(n+1)]

for i in range(n)[::-1]:
    for j in range(i,n):
        if (n+i-j-1)%2==0:
            dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j])
        else:
            dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j])
print(dp[0][n-1])
### BUGGY CODE ###

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

x = []
cnt = 0
flag = True
while cnt < n:
    if flag:
        for j in range(a):
            if cnt + j >= n:
                break
            x.append(1)
        cnt += a
        flag = False
    else:
        for j in range(b):
            if cnt + j >= n:
                break
            x.append(0)
        cnt += b
        flag = True

cnt = 0
for i in range(n):
    if x[i] == 1:
        cnt += 1

print(cnt)


### FIXED CODE ###

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

ans = n // (a + b) * a
rem = n % (a + b)
print(ans + min(rem, a))
### BUGGY CODE ###

def main():
    n, k = map(int, input().split())
    minv = n
    for _ in range(100000000):
        if abs(minv - k) < abs(minv):
            minv = abs(minv - k)
        else:
            print(minv)
            exit()

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    if n - k > k:
        n_k = (n-k) // k
        minv = n - k * n_k
    else:
        minv = n

    def min_x(x):
        minv = x
        for _ in range(3):
            if abs(minv - k) < abs(minv):
                minv = abs(minv - k)
            else:
                print(minv)
                exit()
        print(minv)
        
    min_x(minv)


if __name__ == '__main__':
    main()
### BUGGY CODE ###



def main():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))

    sort_H = sorted(H, reverse=True)
    count = 0
    top = K
    if K >= N:
        print(0)
    elif K == 0:
        print(sum(H))
    else:
        while True:
            flag = True
            while flag:
                sort_H[top] -= 1
                count += 1
                if sort_H[top]==0:
                    flag=False
                    top += 1
                    break
            if top == N:break
        print(count)


if __name__ == "__main__":
    main()

### FIXED CODE ###



def main():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    H = sorted(H, reverse=True)
    sum_H = 0
    for h in H:
        if K > 0:
            K -= 1
            continue
        sum_H += h
    print(sum_H)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import deque
N, D, A = map(int, input().split())
monster = []
for k in range(N):
  monster.append(list(map(int, input().split())))
monster.sort(key = lambda x: x[0])
monster = deque(monster)
ans = 0
while len(monster) > 0:
  if monster[0][1] > 0:
    nowx = monster[0][0]
    damage = ((monster[0][1]-0.1)//A)*A + A
    ans += int((monster[0][1]-0.1)//A + 1)
    j = 0
    while(j<len(monster)):
      if monster[j][0] <= nowx + 2*D:
        monster[j][1] -= damage
        if monster[j][1] > 0:
          j += 1
        else:
          monster.remove(monster[j])
        continue
      else:
        break

print(ans)

### FIXED CODE ###

N, D, A = map(int, input().split())
monster = []
for k in range(N):
  monster.append(list(map(int, input().split())))
monster.sort(key = lambda x: x[0])
for k in range(N):
  monster[k][1] = int((monster[k][1]-0.1)//A + 1)
ans = 0
"""
k = 0
while k < len(monster):
  if monster[k][1] > 0:
    nowx = monster[k][0]
    damage = monster[k][1]
    ans += monster[k][1]
    j = 0 + k
    nextk = N
    while(j +1 < len(monster)):
      j += 1
      if monster[j][0] <= nowx + 2*D:
        monster[j][1] -= damage
        if monster[j][1] > 0:
          nextk = min(j, nextk)
          continue
      else:
        nextk = min(nextk, j)
        break
    k = nextk
"""
final = monster[-1][0]
ruiseki = 0
minuslist = []
j = 0
for k in range(N):
  while (j < len(minuslist)):
    if monster[k][0] >= minuslist[j][0]:
      ruiseki -= minuslist[j][1]
      j += 1
    else:
      break
  if ruiseki < monster[k][1]:
    ans += monster[k][1] - ruiseki
    if monster[k][0] + 2*D +1 <= final:
      minuslist.append([monster[k][0]+2*D+1, monster[k][1] - ruiseki])
    ruiseki = monster[k][1]


print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
li = [i for i in range(1, N+1)]
ans = li
for lr in range(M):
  l, r = map(int, input().split())
  ans = [i for i in ans if l <= i <= r]
print(len(ans))

### FIXED CODE ###

N, M = map(int, input().split())
minNum = 1
maxNum = N
for lr in range(M):
  l, r = map(int, input().split())
  if minNum <= l and r <= maxNum:
    minNum = l
    maxNum = r
  elif minNum <= l <= maxNum and maxNum <= r:
    minNum = l
  elif l <= minNum and minNum <= r <= maxNum:
    maxNum = r
  elif r < minNum or maxNum < l:
    print("0")
    exit()
#  print(l,r,minNum,maxNum)
print(maxNum - minNum +1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def ln():
    return map(int, input().split())


N,M = ln()
A = list(ln())

SUM = [0 for i in range(N+1)]

for i in range(N):
    SUM[i+1] = SUM[i] + A[i]
    SUM[i+1] %= M
ans = 0

for i in range(N):
    ans += SUM[i+1:].count(SUM[i])

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

def ln():
    return map(int, input().split())

N,M = ln()

AA = list(ln())
A = np.array(AA)

SUM = np.zeros(N+1,dtype = int)
for i in range(N):
    SUM[i+1] = (SUM[i] + A[i]) % M

ans = 0
dic = dict()
# for i in range(N):
#     dic[SUM[i]] = 1
for i in range(N+1):
    if SUM[i] in dic:
        dic[SUM[i]] += 1
    else:
        dic[SUM[i]] = 1
    ans += dic[SUM[i]] -1


print(ans)
### BUGGY CODE ###

import numpy as np
Q = int(input())

p = np.array([i for i in range(2*10**5+1)])
p[1]=0
for i in range(2,10**5):
    p[2*i::i] = 0
p = p[p!=0]

dic = {i:1 for i in p}
a = []
for i in range(len(p)):
    if dic.get((p[i]+1)//2,0)==1:
        a.append(p[i])
p=np.array(a)
for _ in range(Q):
    l,r = list(map(int,input().split()))
    tmp = p[l<=p]
    tmp = tmp[tmp<=r]
    print(len(tmp))

### FIXED CODE ###

import numpy as np
Q = int(input())

p = np.array([i for i in range(2*10**5+1)])
p[1]=0
for i in range(2,10**5):
    p[2*i::i] = 0
p = p[p!=0]

dic = {i:1 for i in p}
d = {}
for i in range(len(p)):
    if dic.get((p[i]+1)//2,0)==1:
        d[p[i]] = 1
sum_=0
arr = [0 for i in range(10**5+2)]
for i in range(10**5+2):
    arr[i] = sum_
    if d.get(i,0)==1:
        sum_+=1
for _ in range(Q):
    l,r = list(map(int,input().split()))
    print(arr[r+1]-arr[l])
### BUGGY CODE ###

import math
K=int(input())
ans=0
 
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans+=math.gcd(math.gcd(i,j),k)
print(ans)

### FIXED CODE ###

ls = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
K = int(input())
print(ls[K-1])
### BUGGY CODE ###

N = int(input())
ans = sum(range(1, N))
print(ans)

### FIXED CODE ###

N = int(input())
ans = sum(range(1, N))
print(ans)
### BUGGY CODE ###

N,M = map(int,input().split())
L,R = map(int,input().split())
a = []
for i in range(L,R+1):
    a.append(i)

for i in range(1,M):
    b = []
    l,r = map(int,input().split())
    for j in range(l,r+1):
        b.append(j)
    a = list(set(a) & set(b))

print(len(a))


### FIXED CODE ###

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

l_max = 1
r_min = N
for i in range(0,M):
    l,r = map(int,input().split())
    if l_max < l:
        l_max = l
    if r_min > r:
        r_min = r

if l_max > r_min:
    print(0)
else:
    print(r_min-l_max+1)
### BUGGY CODE ###

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

b=[0 for i in range(n)]
res=0
for i in range(n):
    print(a.count(i+1))

### FIXED CODE ###

import collections
n=int(input())
a=list(map(int,input().split()))

b=collections.Counter(a)
for i in range(1,n+1):
    print(b[i])
### BUGGY CODE ###

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

    ab.sort(key=lambda x:x[1])

res=0
toremove=set()
while(1):
    for j in range(len(ab)):
        if ab[0][1] > ab[j][0]:
            toremove.add(ab[j])
        else:break
    if len(toremove)>0:
        for r in toremove:
            ab.remove(r)
        toremove=set()
        res+=1
    if len(ab) == 0:break

print(res)

### FIXED CODE ###

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

ab.sort(key=lambda x:x[1])

res=0
for z in range(len(ab)):
    x=ab[0][1]
    for j in range(len(ab)):
        if x > ab[0][0]:
            del ab[0]
        else:
            res+=1
            break
    if len(ab)==0:
        res+=1
        break
    
print(res)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()

positions = []
prev_A = False
for j in range(N):
    if S[j] == 'A':
        prev_A = True
    elif prev_A == True and S[j] == 'C':
        positions.append(j - 1)
        prev_A = False
    else:
        prev_A = False

for i in range(Q):
    l, r = map(int, input().split())
    print(len(list(filter(lambda x: l - 1 <= x < r - 1, positions))))


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

c = [0]
for j in range(1, N):
    if S[j - 1] == 'A' and S[j] == 'C':
        c.append(c[-1] + 1)
    else:
        c.append(c[-1])

# 0 1 1 1 2 2 3
# A C A A C A C
# 1 2 3 4 5 6 7
for i in range(Q):
    l, r = map(int, input().split())
    print(c[r - 1] - c[l - 1])
### BUGGY CODE ###

N,M=list(map(int,input().split()))
l=[[] for i in range(N)]
l2=[0]*(N-1)
import sys
l_l=[i.rsplit() for i in sys.stdin.readlines()]
l_l = [list(map(int,i)) for i in l_l]
for i in l_l:
   l[i[0]-1].append(i[1])
   l[i[1]-1].append(i[0])
from collections import deque
que=deque([1])
after=deque()
que_append=que.append
after_append=after.append
while que != deque([]):
   X=que.popleft()
   after_append(X)
   for i in l[X-1]:
      if i in after:
         continue
      if i in que:
         continue
      que_append(i)
      l2[i-2]=X
if len(after) == N:
   print("Yes")
   for i in l2:
      print(i)
else:
   print("No")

### FIXED CODE ###

from collections import deque
def bfs(graph,N):
   que=deque([0])
   visited=[0]*N
   visited[0]=1
   while que:
      node=que.popleft()
      for i in graph[node]:
         if not visited[i]:
            visited[i]=node+1
            que.append(i)
   return visited
N,M= list(map(int,input().split()))
l=[[] for i in range(N)]
for i in range(M):
   a,b=list(map(int,input().split()))
   a-=1;b-=1
   l[a].append(b)
   l[b].append(a)
ans=bfs(l,N)[1:]
if all(ans):
   print("Yes")
   print(*ans,sep="\n")
else:
   print("No")
### BUGGY CODE ###

from math import factorial
pos = map(int, input().split())

x, y = sorted(pos)

num_twos = x // 2
rem = x % 2

solution = 0

max_n = 5*10**5

result = max_n*[None]
result[0] = 1
for i in range(1, max_n):
    result[i] = i*result[i-1]
m = 10**9 + 7 - 2


def ncr(n, r):
    return result[n] * result[r]**(m) * result[n-r]**(m)


while not (y == num_twos + (rem*2)):
    num_twos -= 1
    rem += 2

    if y < (num_twos + rem*2):
        print(0)
        exit()

solution = ncr(num_twos + rem, rem)

print(int(solution))


### FIXED CODE ###

from math import factorial
pos = map(int, input().split())
p = 10**9 + 7
x, y = sorted(pos)

if (x+y) % 3 != 0:
    print(0)
    exit()

n = (-x + 2 * y) // 3
m = (-y + 2 * x) // 3

# Python3 function to
# calculate nCr % p


def ncr(n, r, p):
    # initialize numerator
    # and denominator
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
                      p - 2, p)) % p


ans = ncr(n+m, n, p)
print(ans)
### BUGGY CODE ###

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

dp = [float('inf')]*(N+1)
dp[0] = 0

for i in range(N-1):
  for j in range(1,K+1):
    if i+j < len(h):
      dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j]-h[i]))
print(dp[N-1])

### FIXED CODE ###

import sys
import numpy as np

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

dp = np.zeros(N, dtype=int)
h = np.array(h)

for i in range(1, N):
  start = max(0, i-K)
  dp[i] = min(dp[start:i] + np.abs(h[start:i]-h[i]))
print(dp[N-1])
### BUGGY CODE ###

import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, k = na()
h = na()

dp = [inf] * n
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))

print(dp[n - 1])


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import itertools


N = int(input())

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

mod = 10 ** 9 + 7


ans = 0
t = [1]
u = [1]

for i in range(N):

    i += 1
    t.append(t[-1] * i % mod)

for i in range(N-1):
    u.append(u[-1] * (N-1-i))
    
#print (t)
#print (u)
u.reverse()


now = 0
for i in range(N-1):

    now += u[i+1] * t[i]
    now %= mod
    ans += now * (x[i+1] - x[i])
    ans %= mod
    #print (i,ans/6)

print (ans)



### FIXED CODE ###


N = int(input())

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

mod = 10 ** 9 + 7


ans = 0
t = [1]
u = [1]

for i in range(N):

    i += 1
    t.append(t[-1] * i % mod)

for i in range(N-1):
    u.append(u[-1] * (N-1-i) % mod)
    
#print (t)
#print (u)
u.reverse()


now = 0
for i in range(N-1):

    now += u[i+1] * t[i]
    now %= mod
    ans += now * (x[i+1] - x[i])
    ans %= mod
    #print (i,ans/6)

print (ans)
### BUGGY CODE ###

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

count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            flag = True
            if l[i] >= l[j] + l[k]:
                flag = False
            if l[j] >= l[i] + l[k]:
                flag = False
            if l[k] >= l[j] + l[i]:
                flag = False
            if flag == True:
                count += 1

print(count)


### FIXED CODE ###

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

import bisect

count = 0
for i in range(n-1):
    for j in range(i+1, n):
            ab = l[i] + l[j]
            right = bisect.bisect(l, ab-1)
            left = j + 1
            count += (right - left)

print(count)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

n,m=intinput()
a=[int(sys.stdin.readline()) for _ in range(m)]
memo=[0 for x in range(n+4)]
memo[0]=1
mod = 10**9+7
for i in range(n):
    if i+1 not in a:
        memo[i+1]=(memo[i+1]+memo[i])%mod
    if i+2 not in a:
        memo[i+2]=(memo[i+2]+memo[i])%mod
print(memo[n])

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

fib={0:0,1:1,2:1}
for i in range(3,100003):
    fib[i]=fib[i-1]+fib[i-2]
  #  fib.append(fib[i-1]+fib[i-2])

n,m=intinput()
mod=10**9+7
a=[int(sys.stdin.readline()) for _ in range(m)]
if m!=0:
    l=[a[0]]
    for i in range(len(a)-1):
        l.append(a[i+1]-a[i]-1)
    l.append(n-a[-1])
    k=1
    for i in l:
        k=fib[i]*k%mod
    print(k%mod)
else:
    print(fib[n+1]%mod)
### BUGGY CODE ###

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
num = Counter(A)
for i in range(Q):
    b,c = map(int,input().split())
    num[c] += num[b]
    num[b] = 0
    sums = 0
    for j in num:
        sums += num[j]*j
    print(sums)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
ans = sum(A)
num = Counter(A)
for i in range(Q):
    b,c = map(int,input().split())

    ans += (c-b)*num[b]
    num[c] += num[b] 
    num[b] = 0
    
    print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
from itertools import product
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(n)]

dp = [[0 for i in range(m+1)] for j in range(n+1)]


# eval
# eval_list = ["+xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]", ]

ans = []
for a, b, c in product([1, -1], repeat=3):
    for i in range(1, n+1):
        for j in range(1, min(i+1, m+1)):
            tmp = xyz[i-1][0]*a + xyz[i-1][1]*b + xyz[i-1][2]*c
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-1] + tmp)

    ans.append(dp[-1][-1])
print(max(ans))


### FIXED CODE ###

#!/usr/bin/env python3
from itertools import product
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(n)]

dp = [[0 for i in range(m+1)] for j in range(n+1)]


# eval
# eval_list = ["+xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]", ]

ans = 0
for a, b, c in product([1, -1], repeat=3):
    total = []
    for x, y, z in xyz:
        s = x*a+y*b+z*c
        total.append(s)
    total.sort(reverse=True)
    ans = max(ans, sum(total[:m]))
print(ans)
### BUGGY CODE ###

N=int(input())
sn=[input() for _ in range(N)]
def check(s1,s2):
  for c in s1:
    if s1.count(c)!=s2.count(c):
      return False
  else:
    return True
  
cnt=0
for i in range(len(sn)-1):
  for ii in range(i+1,len(sn)):
    if sn[i]==sn[ii]:
      cnt+=1
      continue
    if check(sn[i],sn[ii]):
      sn[ii]=sn[i]
      cnt+=1

print(cnt)

### FIXED CODE ###

N=int(input())
dict={}
for _ in range(N):
  s=''.join(sorted(input()))
  dict[s]=dict.setdefault(s,0)+1
  
cnt=0
for c in dict.values():
  cnt+=(1+c-1)*(c-1)//2
  
print(cnt)
### BUGGY CODE ###

from math import ceil #切り上げ
import numpy as np
 
def inp(): return int(input()) #一個だけ読み取り
def inpm(): return map(int,input().split()) #mapオブジェクトで呼び出し
def inpl(): return list(map(int, input().split())) #数字リストをintで
def inpls(): return list(input().split()) #リストをstrで

A,B,N = inpl()
max = -1
for i in range(0,N+1):
  if max <= (A*i)//B-A*(i//B):
    max = (A*i)//B-A*(i//B)
print(max)
  

### FIXED CODE ###

from math import ceil #切り上げ
import numpy as np
 
def inp(): return int(input()) #一個だけ読み取り
def inpm(): return map(int,input().split()) #mapオブジェクトで呼び出し
def inpl(): return list(map(int, input().split())) #数字リストをintで
def inpls(): return list(input().split()) #リストをstrで

A,B,N = inpl()
if B <= N:
  x = B-1
else:
  x = N
    
print(A*x//B)