Harryxun/stf_run huggingface dataset:
from collections import deque
N, Q = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N-1)]
PX = [list(map(int, input().split())) for _ in range(Q)]

chil = [[] for _ in range(N+1)]
count = [0]*(N+1)

for ab in AB:
    chil[ab[0]].append(ab[1])
    chil[ab[1]].append(ab[0])

def cleanse(fromN, toN):
    chil[toN].remove(fromN)
    if len(chil[toN])==0:  # leaf
        return
    for node in chil[toN]:
        cleanse(toN, node)

for node in chil[1]:
    cleanse(1, node)

def addition(fromN, toN, value):
    count[toN] += value
    if len(chil[toN])==0:
        return
    for node in chil[toN]:
        addition(toN, node, value)

for px in PX:
    count[px[0]] += px[1]
    for node in chil[px[0]]:
        addition(px[0], node, px[1])

print(*count[1:])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
N, Q = map(int, input().split())

edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

points = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    points[p-1] += x

def dfs(v, par):
    for nv in edges[v]:
        if nv == par:
            continue
        points[nv] += points[v]
        dfs(nv, v)

dfs(0, -1)

print(*points)
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def cover0(c,d):
    m = len(c)
    for i in range(m):
        if c[i]==0:
            continue
        k = -1
        for j in range(62):
            b = 1<<j
            if c[i]&b != 0:
                k = j
                break
        for j in range(i+1,m):
            if c[j]&b != 0:
                c[j] ^= c[k]
        for j in range(len(d)):
            if d[j]&b != 0:
                d[j] ^= c[k]
    return sum(d)==0

t = inn()
for tt in range(t):
    n = inn()
    a = inl()
    s = ins()
    top = n
    to0 = []
    to1 = []
    done = False
    while top>0:
        prev0 = top
        while top>0 and s[top-1]=='0':
            top -= 1
        top0 = top
        to0.extend(a[top0:prev0])
        prev1 = top
        while top>0 and s[top-1]=='1':
            top -= 1
        top1 = top
        to1.extend(a[top1:prev1])
        cc = [x for x in to0]
        dd = [x for x in to1]
        if not cover0(cc,dd):
            print(1)
            done = True
            break
    if not done:
        print(0)


### FIXED CODE ###

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18

def ddprint(x):
  if DBG:
    print(x)

def cover0(c,d):
    m = len(c)
    for i in range(m):
        if c[i]==0:
            continue
        k = -1
        for j in range(62):
            b = 1<<j
            if c[i]&b != 0:
                k = j
                break
        for j in range(i+1,m):
            if c[j]&b != 0:
                c[j] ^= c[i]
        for j in range(len(d)):
            if d[j]&b != 0:
                d[j] ^= c[i]
    return sum(d)==0

t = inn()
for tt in range(t):
    n = inn()
    a = inl()
    s = ins()
    top = n
    to0 = []
    to1 = []
    done = False
    while top>0:
        prev0 = top
        while top>0 and s[top-1]=='0':
            top -= 1
        top0 = top
        to0.extend(a[top0:prev0])
        prev1 = top
        while top>0 and s[top-1]=='1':
            top -= 1
        top1 = top
        to1.extend(a[top1:prev1])
        cc = [x for x in to0]
        dd = [x for x in to1]
        if not cover0(cc,dd):
            print(1)
            done = True
            break
    if not done:
        print(0)
n = int(input())
stair = list(map(int, input().split()))

for i in reversed(range(1, n)):
    d = stair[i] - stair[i - 1]
    if d > 1:
        print("No")
        exit()
    elif d == 1:
        stair -= 1
print("Yes")


### FIXED CODE ###

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

for i in reversed(range(1, n)):
    d = stair[i] - stair[i - 1]
    if d < -1:
        print("No")
        exit()
    elif d == -1:
        stair[i - 1] -= 1
print("Yes")
def main():
    n,q=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    tree=[list() for _ in range(n)]
    score=[0]*n
    for a,b in ab:
        a-=1
        b-=1
        tree[a].append(b)
    px=[list(map(int,input().split())) for _ in range(q)]
    for p,x in px:
        p-=1
        add(p,x,tree,score)
    print(s)

def add(p,x,tree,score):
    score[p] += x
    s=tree[p][:]
    while len(s)>0:
        t = s.pop()
        score[t] += x
        for i in tree[t]:
            s.append(i)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n,q=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    tree=[list() for _ in range(n)]
    score=[0]*n
    for a,b in ab:
        a,b=a-1,b-1
        tree[a].append(b)
        tree[b].append(a)
    e = [0]
    while len(e) > 0:
        i = e.pop()
        for j in tree[i]:
            tree[j].remove(i)
            e.append(j)
    px=[list(map(int,input().split())) for _ in range(q)]
    for p,x in px:
        p-=1
        score[p]+=x
    add(tree,score)
    print(*score)

def add(tree,score):
    s=tree[0][:]
    for i in s:
        score[i] += score[0]
    while len(s)>0:
        t = s.pop()
        for i in tree[t]:
            s.append(i)
            score[i] += score[t]

if __name__ == "__main__":
    main()
import sys

N,A,B,C,D = map(int, input().split())
s = input()
#index = [(n+1) for n, v in enumerate(s) if s[n:n+3] == "..."]
#print(index)

if s.count("##")>=1:
    print("No")
    sys.exit(0)

if C < D:
    print("Yes")

elif C > D:
    if len(index)>=1:
        for i in index:
            if B <= i+1 <= D:
                print("Yes")
                sys.exit(0)
        print("No")
    else:
        print("No")


### FIXED CODE ###

N,A,B,C,D = map(int, input().split())
s = input()
index = [(n+1) for n, v in enumerate(s) if s[n:n+3] == "..."]

if C < D:
    if "##" in s[A-1:D]:
        print("No")
    else:
        print("Yes")

if C > D:
    if "##" in s[A-1:C]:
        print("No")
    else:
        if len(index)>=1:
            for i in index:
                if B <= i+1 <= D:
                    print("Yes")
                    exit()
            print("No")
        else:
            print("No")
import math
N = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0

def combination(n,r):
    return math.factorial(n) / (math.factorial(n-r) * math.factorial(r))

for i in range(1,N):
    for j in range(0,i):
        if ans < combination(a[i], a[j]):
            ans = combination(a[i], a[j])
            n = a[i]
            r = a[j]
print(n, r)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
r_A = MAX / 2
del A[A.index(MAX)]
B = list(map(lambda a:abs(a-r_A),A))
B.sort()
r1 = int(r_A + B[0])
r2 = int(r_A - B[0])
if r1 in A:
    print(MAX, r1)
else:
    print(MAX, r2)
while 1:
 x, y = map(int, raw_input().split())
 if x <= y:
    print "%d %d" %(x,y)
 if y < x:
    print "%d %d" %(y,x)
 if x == 0 and x == 0:
    break

### FIXED CODE ###

while 1:
   x, y = map(int, raw_input().split())
   if x == 0 and y == 0:
      break
   elif x > y:
      print '%s %s' % (y,x)
   else:
      print '%s %s' % (x,y)
p,q,r = [int(i) for i in input().split(' ')]

x= p+q
y= q+r
z= r+z

print(min([x,x,z]))

### FIXED CODE ###

p,q,r = [int(i) for i in input().split(' ')]

x = p+q
y = q+r
z = r+p

print(min([x,y,z]))
s = input()
s_reverse = ''.join(list(reversed(s)))
t = ''

while True:
    if s_reverse == t:
        print('YES')
        break
    n = len(t)
    if s_reverse[n] == 'm':
        t += ''.join(list(reversed('dream')))
    elif s_reverse[n] == 'e':
        t += ''.join(list(reversed('erase')))
    elif s_reverse[n:n+3] == 'rem':
        t += ''.join(list(reversed('dreamer')))
    elif s_reverse[n:n+3] == 'res':
        t += ''.join(list(reversed('eraser')))
    else:
        print('NO')
        break

### FIXED CODE ###

s = input()
s_reverse = ''.join(list(reversed(s)))
t = ''

while True:
    n = len(t)
    if s_reverse == t:
        print('YES')
        break
    if len(s) <= n:
        print('NO')
        break
    if s_reverse[n] == 'm':
        t += ''.join(list(reversed('dream')))
    elif s_reverse[n] == 'e':
        t += ''.join(list(reversed('erase')))
    elif s_reverse[n:n+3] == 'rem':
        t += ''.join(list(reversed('dreamer')))
    elif s_reverse[n:n+3] == 'res':
        t += ''.join(list(reversed('eraser')))
    else:
        print('NO')
        break
w,h,n=map(int,input().split())
xa=[]
xb=[]
ya=[]
yb=[]
for i in range(n):
  x1,y1,a1=map(int,input().split())
  if a1==1:
    xa.append(x1)
  elif a1==2:
    xb.append(x1)
  elif a1==3:
    ya.append(y1)
  elif a1==4:
    yb.append(y1)

if min(xb)<=max(xa) or min(yb)<=max(ya):
  print(0)
else:
  print((min(xb)-max(xa))*(min(yb)-max(ya)))

### FIXED CODE ###

w,h,n=map(int,input().split())
xa=[0]
xb=[w]
ya=[0]
yb=[h]
for i in range(n):
  x1,y1,a1=map(int,input().split())
  if a1==1:
    xa.append(x1)
  elif a1==2:
    xb.append(x1)
  elif a1==3:
    ya.append(y1)
  elif a1==4:
    yb.append(y1)

if min(xb)<=max(xa) or min(yb)<=max(ya):
  print(0)
else:
  print((min(xb)-max(xa))*(min(yb)-max(ya)))
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
from numpy.linalg import solve
def nasu(a, b, c):
  A = a[0] ** 2 - b[0] ** 2 + a[1] ** 2 - b[1] ** 2
  B = b[0] ** 2 - c[0] ** 2 + b[1] ** 2 - c[1] ** 2
  x = [2 * (b[0] - a[0]), 2 * (c[0] - b[0])]
  y = [2 * (b[1] - a[1]), 2 * (c[1] - b[1])]

  if x[0] * y[0] == x[1] * y[1]:
    return 0
  left = [[x[0], y[0]],
          [x[1], y[1]]]
  right = [-A, -B]
  Cx, Cy = solve(left, right)
  r = ((a[0] - Cx) ** 2 + (a[1] - Cy) ** 2) ** (1 / 2)
  for i in range(N):
    if honya(xy[i], Cx, Cy) > r:
      return 0
  return r

def honya(a, Cx, Cy):
  return ((a[0] - Cx) ** 2 + (a[1] - Cy) ** 2) ** (1 / 2)
ans = 10 ** 10
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    for k in range(j + 1, N):
      ans = min(ans, nasu(xy[i], xy[j], xy[k]))

print(ans)

### FIXED CODE ###

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
def nasu(a, b, c):
  A = a[0] ** 2 - b[0] ** 2 + a[1] ** 2 - b[1] ** 2
  B = b[0] ** 2 - c[0] ** 2 + b[1] ** 2 - c[1] ** 2
  x = [2 * (b[0] - a[0]), 2 * (c[0] - b[0])]
  y = [2 * (b[1] - a[1]), 2 * (c[1] - b[1])]
  k = x[1] * y[0] - x[0] * y[1]
  if k == 0:
    return 10 ** 10
  Cx = -(y[0] * B - y[1] * A) / k
  Cy = (x[0] * B - x[1] * A) / k
  return honyamorake(Cx, Cy)

def honya(x, y, Cx, Cy):
  return ((x - Cx) ** 2 + (y - Cy) ** 2) ** (1 / 2)

def honyaraka(a, b):
  Cx = (a[0] + b[0]) / 2
  Cy = (a[1] + b[1]) / 2
  return honyamorake(Cx, Cy)

def honyamorake(Cx, Cy):
  r = honya(xy[0][0], xy[0][1], Cx, Cy)
  for i in range(1, N):
    r = max(r, honya(xy[i][0], xy[i][1], Cx, Cy))
  return r

ans = 10 ** 10
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    for k in range(j + 1, N):
      ans = min(ans, nasu(xy[i], xy[j], xy[k]))
for i in range(N - 1):
  for j in range(i + 1, N):
    ans = min(ans, honyaraka(xy[i], xy[j]))

print(ans)
S = input()
acgt = ["A", "C", "G", "T"]
cnts = []
cnt = 0
for i in range(len(S)):
	if S[i] in acgt:
		cnt += 1
		cnts.append(cnt)
	else:
		cnt = 0
print(max(cnts))


### FIXED CODE ###

S = input()
acgt = ["A", "C", "G", "T"]
cnts = []
cnt = 0
for i in range(len(S)):
	if S[i] in acgt:
		cnt += 1
		cnts.append(cnt)
	else:
		cnts.append(cnt)
		cnt = 0
print(max(cnts))
s = int(input())
 
a = int(s / 100) #百の位と千の位
b = s - a*100 #下二桁

if a > 12:
  if b > 12 or b == 0:
    print("NA")
  else:
    print("YYMM")
elif a == 0:
  if b < 13 and b > 0:
    print("YYMM")
  else:
    print("NA")
elif b > 12 or b == 0:
  print("MMYY")
else:
  print("AMBIGUOUS")

### FIXED CODE ###

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

if s[k-1] == "A":
  s[k-1] = "a"
elif s[k-1] == "B":
  s[k-1] = "b"
else:
  s[k-1] = "c"

for i in range(n):
  print(s[i], end="")
A,B,C,D = map(int,input().split())
import math

n = B//C
m = (A-1)//C
p = B//D
q = (A-1)//D
x = B//(C*D// math.gcd(C,D))
y = (A-1)//(C*D// math.gcd(C,D))
L = (B-A+1)-((n-m)+(p-q)-(x-y))
print(L)

### FIXED CODE ###

a,b,c,d = map(int,input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
e = gcd(c,d)
f = c * d // e

b_c = b // c
s_c = (a-1) // c
C = b_c - s_c

b_d = b // d
s_d = (a-1) // d
D = b_d - s_d

b_cd = b // f
s_cd = (a-1) // f
CD = b_cd - s_cd

ans = b - a + 1 - (C + D - CD)
print(ans)
k, x = input(), input()
print ("yes") if k*500 >= x else ("no")

### FIXED CODE ###

k, x = input().split()
if int(k)*500 >= int(x):
	print("Yes")
else:
	print("No")
MOD = 10**9 + 7
memo = None


def rec(S, k, total):
    if k == len(S)//3:
        # print(total)
        fixed_total = total + 5 if k % 2 == 0 else total - 5
        memo[k][total % 13] = int((fixed_total) % 13 == 0)
        return int((fixed_total) % 13 == 0)

    if memo[k][total % 13] is not None:
        return memo[k][total % 13]

    s = S[k*3:k*3+3]
    d1 = [str(i) for i in range(10)] if s[0] == '?' else [s[0]]
    d2 = [str(i) for i in range(10)] if s[1] == '?' else [s[1]]
    d3 = [str(i) for i in range(10)] if s[2] == '?' else [s[2]]
    ret = 0

    for i1 in d1:
        for i2 in d2:
            for i3 in d3:
                num = int(i1 + i2 + i3)
                if k % 2 == 0:
                    ret += rec(S, k+1, total + num)
                else:
                    ret += rec(S, k+1, total - num)

    memo[k][total % 13] = ret
    return ret

S = input()

if len(S) % 3 == 1:
    S = '00' + S
elif len(S) % 3 == 2:
    S = '0' + S

L = (len(S) // 3) + 1
memo = [[None for i in range(14)] for j in range(L)]
print(rec(S, 0, 0) % MOD)


### FIXED CODE ###

MOD = 10**9 + 7

S = input()
L = len(S)
memo = [[0 for i in range(14)] for j in range(L + 1)]
dp = [[0 for i in range(14)] for j in range(L + 1)]

dp[0][0] = 1

for k in range(L):
    for m in range(13):
        if S[k] == '?':
            for i in range(10):
                dp[k + 1][(m * 10 + i) % 13] += dp[k][m]
        else:
            dp[k + 1][(m * 10 + int(S[k])) % 13] += dp[k][m]

        for i in range(13):
            dp[k+1][i] %= MOD

print(dp[L][5])
n = int(input())
A = [int(i) for i in input().split()]
def partition(p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1

q = partition(0, n - 1)
print(*A[:q], "[" + str(A[q]) + "]", end="")
if len(A[q + 1:]) > 0:
    print("", *A[q + 1:])

### FIXED CODE ###

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1
n = int(input())
A = list(map(int, input().split()))
p = partition(A, 0, n - 1)
A[p] = f"[{A[p]}]"
print(*A)
H,W = map(int,input().split())
src = [input() for i in range(H)]

dxy = [(0,1),(1,0),(0,-1),(-1,0)]
def is_isolated(x,y):
    if src[y][x] == '.': return False
    for dx,dy in dxy:
        if not 0 <= x+dx < W: continue
        if not 0 <= y+dy < H: continue
        if src[y+dy][x+dx] == '#': return False
    else:
        return True

for y in range(H):
    for x in range(W):
        if is_isolated(y,x):
            print('No')
            exit()
print('Yes')

### FIXED CODE ###

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

dxy = [(-1,0),(0,-1),(1,0),(0,1)]
for y in range(H):
    for x in range(W):
        if src[y][x] == '.': continue
        for dx,dy in dxy:
            nx,ny = x+dx,y+dy
            if not 0 <= nx < W: continue
            if not 0 <= ny < H: continue
            if src[ny][nx] == '#':
                break
        else:
            print('No')
            exit()
print('Yes')
import copy
 
INF = 10000000000
def merge(A, left, mid, right):
    count = 0
    L = A[left:mid] + [(INF,INF)]
    R = A[mid:right] + [(INF,INF)]
     
    i, j = 0, 0
    for k in range(left, right):
        count = count + 1
        if L[i][1] <= R[j][1]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
    return count
 
def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        countL = mergeSort(A, left, mid)
        countR = mergeSort(A, mid, right)
        return merge(A, left, mid, right) + countL + countR
    return 0
def partition(a,p,r):
    x=a[r][1]
    i=p-1
    for j in range(p,r):
        if a[j][1]<=x:
            i+=1
            a[i],a[j]=a[j],a[i]
    a[i+1],a[r]=a[r],a[i+1]
    return i+1
def quickSort(a,p,r):
    if p<r:
        q=partition(a,p,r)
        quicksort(a,p,q-1)
        quicksort(a,q+1,r)
n = int(input())
A = [None for i in range(n)]
for i in range(n):
    a, b = input().split()
    A[i] = (a, int(b))

B = copy.deepcopy(A)
quickSort(A, 0, n-1)
mergeSort(B, 0, n)
if A == B:
    print("Stable")
else:
    print("Not stable")
ans = [str(x[0]) +" "+str(x[1]) for x in A]
ans = '\n'.join(ans)
print(ans)


### FIXED CODE ###

import copy
 
INF = 10000000000
def merge(A, left, mid, right):
    count = 0
    L = A[left:mid] + [(INF,INF)]
    R = A[mid:right] + [(INF,INF)]
     
    i, j = 0, 0
    for k in range(left, right):
        count = count + 1
        if L[i][1] <= R[j][1]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
    return count
 
def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        countL = mergeSort(A, left, mid)
        countR = mergeSort(A, mid, right)
        return merge(A, left, mid, right) + countL + countR
    return 0
def partition(a,p,r):
    x=a[r][1]
    i=p-1
    for j in range(p,r):
        if a[j][1]<=x:
            i+=1
            a[i],a[j]=a[j],a[i]
    a[i+1],a[r]=a[r],a[i+1]
    return i+1
def quickSort(a,p,r):
    if p<r:
        q=partition(a,p,r)
        quickSort(a,p,q-1)
        quickSort(a,q+1,r)
n = int(input())
A = [None for i in range(n)]
for i in range(n):
    a, b = input().split()
    A[i] = (a, int(b))

B = copy.deepcopy(A)
quickSort(A, 0, n-1)
mergeSort(B, 0, n)
if A == B:
    print("Stable")
else:
    print("Not stable")
ans = [str(x[0]) +" "+str(x[1]) for x in A]
ans = '\n'.join(ans)
print(ans)
N = int(input())
L_2 = 2
L_1 = 1
p = 0
for i in range(N-1):
  K = L_1+L_2
  L_2 = L_1
  L_1 = K
print(K)

### FIXED CODE ###

L = [2,1]
for i in range(100):
  L.append(L[i+1]+L[i])
n = int(input())
print(L[n])
A,B = map(int,input().split())

print(max(A+B,A-B,A*B)


### FIXED CODE ###

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

print(max(A+B,A-B,A*B))
N = int(input())
a = list(map(int,input().split()))
s = 0
for i in range(N):
    s += sum(a[i]*a[i+1:])
print(s%(pow(10,9)+7))

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
a_s = sum(a)
mod = 10**9+7
s = 0
for i in range(N-1):
    b = a[i]
    a_s -= b
    s += b*(a_s)
    s %= mod
print(s)
r, c = map(int, input().split())

d = [0] * (c + 1)

for i in range(r):
    d[i] = list(map(int, input().split()))
    d[i].append(0)
    for j in range(c):
        d[i][c] += d[i][j]

d[r] = [0] * (c + 1)
for i in range(c + 1):
    for j in range(r):
        d[r][i] += d[j][i]

for i in range(r + 1):
    row = ''
    for j in range(c + 1):
        row += str(d[i][j])
        if j <= c - 1:
            row += ' '
    print(row)



### FIXED CODE ###

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

d = [0] * (r + 1)

for i in range(r):
    d[i] = list(map(int, input().split()))
    d[i].append(0)
    for j in range(c):
        d[i][c] += d[i][j]

d[r] = [0] * (c + 1)
for i in range(c + 1):
    for j in range(r):
        d[r][i] += d[j][i]

for i in range(r + 1):
    row = ''
    for j in range(c + 1):
        row += str(d[i][j])
        if j <= c - 1:
            row += ' '
    print(row)
#coding:utf-8
import itertools
import numpy as np

N,M = map(int,input().split())
cakeList = [list(map(int,input().split())) for i in range(N)]
cakeList = np.array(cakeList)
numList = [i for i in range(N)]


if M < N/2:
    combi = list(itertools.combinations(numList,M))
    totalList = []
    for indexs in combi:
        cakes = [cakeList[i] for i in indexs]
        cakes = np.array(cakes)
        total = [abs(np.sum(cakes[:,i])) for i in range(3)]
        total = sum(total)
        totalList.append(total)
    print(max(totalList))


else:
    M = N - M
    combi = list(itertools.combinations(numList,M))
    BDP = [np.sum(cakeList[:,i]) for i in range(3)]
    totalList = []
    for indexs in combi:
        cakes = [cakeList[i] for i in indexs]
        cakes = np.array(cakes)
        total = [abs(BDP[i] - np.sum(cakes[:,i])) for i in range(3)]
        total = sum(total)
        totalList.append(total)
    print(max(totalList))


### FIXED CODE ###

#coding:utf-8
import itertools
import numpy as np
from copy import deepcopy

N,M = map(int,input().split())
cakeList = [list(map(int,input().split())) for i in range(N)]
cakeList = np.array(cakeList)


n = 3
oneList = [None for i in range(n)]
value = []
def maker(dep):
    if dep >= n:
        oneList_copy = deepcopy(oneList)
        value.append(oneList_copy)
        return
    oneList[dep] = 1
    maker(dep+1)
    oneList[dep] = -1
    maker(dep+1)

maker(0)


allvalue = []  
for cake in cakeList:
    value8 = [np.dot(v,cake) for v in value]
    allvalue.append(value8)
    
allvalue = np.array(allvalue)

maxList = []
for i in range(2**n):
    row = list(allvalue[:,i])
    row.sort(reverse=True)
    maxv = sum(row[:M])
    maxList.append(maxv)
maxv = max(maxList)
print(maxv)
h,w=map(int,input().split())
a=[]
dp={}
dp[(h-1,w-1)]=1
for i in range(h):
	a.append(list(input()))

def foo(i,j):
	if i>=h or j>=w:
		return 0
	if (i,j) in dp:
		return dp[(i,j)]
	ans=0
	if i+1<h and a[i+1][j]=='.':
		ans+=foo(i+1,j)
	if j+1<w and a[i][j+1]=='.':
		ans+=foo(i,j+1)
	dp[(i,j)]=ans%(1e9+7)
	return dp[(i,j)]

print(int(foo(0,0)))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)

h,w=map(int,input().split())
a=[]
dp={}
dp[(h-1,w-1)]=1
for i in range(h):
	a.append(list(input()))

def foo(i,j):
	if i>=h or j>=w:
		return 0
	if (i,j) in dp:
		return dp[(i,j)]
	ans=0
	if i+1<h and a[i+1][j]=='.':
		ans+=foo(i+1,j)
	if j+1<w and a[i][j+1]=='.':
		ans+=foo(i,j+1)
	dp[(i,j)]=ans%(1e9+7)
	return dp[(i,j)]

print(int(foo(0,0)))
from math import ceil

X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l2 = [abs(int(x)-X) for x in l]
l2.sort()
for i in range(N):
    if ceil(i/2) != l2[i]:
        t = ceil(i/2)
        break
if X - t in l:
    print(X + t)
else:
    print(X - t)

### FIXED CODE ###

X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
if len(l) == 0:
    print(X)
elif X not in l:
    print(X)
else:
    for i in range(1, 1000):
        if X - i not in l:
            print(X - i)
            break
        elif X + i not in l:
            print(X + i)
            break
# -*- coding: utf-8 -*-

import math
from functools import reduce

n = int(input())
a = list(map(int,input().split()))
a = [0] + a

print(reduce(math.gcd, a[1:]))

### FIXED CODE ###

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

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

if len(a) == 1:
    ans = a[0]
else:
    ans = gcd(a[0],a[1])
    for i in range(2,n):
        ans = gcd(ans,a[i])

print(ans)
N,M=map(int,input().split())
if N=M:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N,M=map(int,input().split())
if N==M:
    print("Yes")
else:
    print("No")