Harryxun/stf_run huggingface dataset:
from heapq import heappush,heappop,heapify

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
change = [list(map(int,input().split())) for _ in range(M)]

def tempchange(l,change):
  heapify(l)  
  for B,C in change:
    for j in range(B):
      print(l)
      a = heappop(l)
      print(l,a)
      if C - a > 0:
        heappush(l,C)
      else:
        heappush(l,a)
        break
  return sum(l)

#A.sort(reverse = True)
change.sort(key = lambda x:x[1],reverse =True)
print(tempchange(A,change))

### FIXED CODE ###

from heapq import heappush,heappop,heapify

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
change = [list(map(int,input().split())) for _ in range(M)]

def tempchange(l,change):
  heapify(l)  
  for B,C in change:
    for j in range(B):
      a = heappop(l)
      if C - a > 0:
        heappush(l,C)
      else:
        heappush(l,a)
        break
  return sum(l)

#A.sort(reverse = True)
change.sort(key = lambda x:x[1],reverse =True)
print(tempchange(A,change))
N, R = map(int, input().split())

if N >= 10:
  print(str(R))
  
 else:
  print(str(R + 100 * (10 - N)))

### FIXED CODE ###

N, R = map(int, input().split())
 
if N >= 10:
  print(str(R))
  
else:
  print(str(R + 100 * (10 - N)))
print(int(input() ** 3)

### FIXED CODE ###

print(int(input()) ** 3)
N, M = map(int, input().split())
ps = range(1, N)
candidates = []
for p in ps:
    if M % p == 0:
        if M // p >= N:
            candidates.append(p)
        if p >= N:
            candidates.append(M // p)
print(max(candidates))

### FIXED CODE ###

N, M = map(int, input().split())
candidates = []
for p in range(1, max(int(M ** 0.5) + 1, N + 1)):
    if M % p == 0:
        if M // p >= N:
            # p * (M // p = a1+a2+.. >= N) = M
            candidates.append(p)
        if p >= N:
            # (M // p) * (p = a1+a2+.. >= N) = M
            candidates.append(M // p)
print(max(candidates))
nm = list(map(int, input().split()))
lis = list(map(int, input().split()))

lis.sort()

sum = 0
diff = []

if nm[1] - nm[0] <= 0:
    print(0)
else:
    for i in range (nm[1] - 1):
        diff[i] = lis[i + 1] - lis[i]

    diff.sort()

    for j in range (nm[0] - 1):
        diff.pop(-1)

    for k in range (nm[1] - nm [0] - 1):
        sum = sum + diff[k]
    
    print(sum)

### FIXED CODE ###

nm = list(map(int, input().split()))
lis = list(map(int, input().split()))

lis.sort()

sum = 0
diff = []

if nm[1] - nm[0] <= 0:
    print(0)
else:
    for i in range (nm[1] - 1):
        diff.append(lis[i + 1] - lis[i])

    diff.sort()

    if nm[0] != 1:
        for j in range (nm[0] - 2):
            diff.pop(-1)

    for k in range (nm[1] - nm [0]):
        sum = sum + diff[k]

    print(sum)
import math

n = int(input())
arr = [int(x) for x in input().split()]

count = 0
max_even = 0
for x in arr:
   if x % == 2 and x > max_even:
      max_even = x 

print(math.log2(max_even))


### FIXED CODE ###

def count(lst, x):
   ctr = 0
   for i in lst:
      if i == x:
         ctr += 1
   return ctr

s = [x for x in input()]
print(count(s, "1"))
a = int(input())
s = input()
if s >= 3200:
  print(s)
else:
  print("red")

### FIXED CODE ###

a = int(input())
s = input()
if a >= 3200:
  print(s)
else:
  print("red")
K = int(input())
S = input()
if len(S) <= K:
    print(S)
else:
    print(S[:K]+"...")7
nikoandsolstice

### FIXED CODE ###

K = int(input())
S = input()
if len(S) <= K:
    print(S)
else:
    print(S[:K]+"...")
#一個だけRE、わからねえ
#解答見る
import sys
sys.setrecursionlimit(50)
h,w=map(int,input().split())

def go_next(I,J):
    global dp,w,h
    if 0<=I<h-1:
        if x[I+1][J]=="." and dp[I+1][J]>dp[I][J]+1:
            dp[I+1][J]=dp[I][J]+1
            go_next(I+1,J)
    if 0<I<=h-1:
        if x[I-1][J]=="." and dp[I-1][J]>dp[I][J]+1:
            dp[I-1][J]=dp[I][J]+1
            go_next(I-1,J)
    if 0<=J<w-1:
        if x[I][J+1]=="." and dp[I][J+1]>dp[I][J]+1:
            dp[I][J+1]=dp[I][J]+1
            go_next(I,J+1)
    if 0<J<=w-1:
        if x[I][J-1]=="." and dp[I][J-1]>dp[I][J]+1:
            dp[I][J-1]=dp[I][J]+1
            go_next(I,J-1)

x=[]
for i in range(h):
    x.append(list(input()))
#print(x)
c=0
for i in range(h):
    for j in range(w):
        if x[i][j]==".":
            c+=1
dp=[[10000000000 for i in range(w)]for j in range(h)]
dp[0][0]=1
go_next(0,0)
if dp[h-1][w-1]==10000000000:
    print(-1)
else:
    print(c-dp[h-1][w-1])


### FIXED CODE ###

#一個だけRE、わからねえ
#解答見る
import sys
sys.setrecursionlimit(1005)
h,w=map(int,input().split())

def go_next(I,J,n):
    n+=1
    global dp,w,h
    if n>1000:
        return
    if 0<=I<h-1:
        if x[I+1][J]=="." and dp[I+1][J]>dp[I][J]+1:
            dp[I+1][J]=dp[I][J]+1
            go_next(I+1,J,n)
    if 0<I<=h-1:
        if x[I-1][J]=="." and dp[I-1][J]>dp[I][J]+1:
            dp[I-1][J]=dp[I][J]+1
            go_next(I-1,J,n)
    if 0<=J<w-1:
        if x[I][J+1]=="." and dp[I][J+1]>dp[I][J]+1:
            dp[I][J+1]=dp[I][J]+1
            go_next(I,J+1,n)
    if 0<J<=w-1:
        if x[I][J-1]=="." and dp[I][J-1]>dp[I][J]+1:
            dp[I][J-1]=dp[I][J]+1
            go_next(I,J-1,n)

x=[]
for i in range(h):
    x.append(list(input()))
#print(x)
c=0
for i in range(h):
    for j in range(w):
        if x[i][j]==".":
            c+=1
dp=[[10000000000 for i in range(w)]for j in range(h)]
dp[0][0]=1
go_next(0,0,0)
if dp[h-1][w-1]==10000000000:
    print(-1)
else:
    print(c-dp[h-1][w-1])
a, b = map(int(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))
import math

def combinations(p, q):
    return math.factorial(p) // (math.factorial(p - q) * math.factorial(q))

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

for i in range(k-1):
    print((combinations(n-k+1, i+1) * (i+1)) % 1000000007)
else:
    print((combinations(n-k+1, k)) % 1000000007)

### FIXED CODE ###

import math

def combinations(p, q):
    return math.factorial(p) // (math.factorial(p - q) * math.factorial(q))

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

if n == k:
    print(1)
    for i in range(k-1):
        print(0)
elif k == 1:
    print(combinations(n-k+1, 1) % 1000000007)
else:
    for i in range(k-1):
        if i + 1 > n-k+1:
            print(0)
        else:
            print((combinations(n-k+1, i+1) * combinations(k-1, i)) % 1000000007)
    else:
        if k > n-k+1:
            print(0)
        else:
            print((combinations(n-k+1, k)) % 1000000007)
N = int(input())
G = [[] for i in range(N + 1)]
for i in range(1, N):
    a = int(input())
    G[a - 1].append(i)


def dfs(v):
    D = []
    for w in G[v]:
        D.append(dfs(w))

    D = sorted(D, reverse=True)

    num = 0
    for i in range(len(D)):
        num = max(num, D[i] + i + 1)

    return num


print(dfs(0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
G = [[] for i in range(N + 1)]
for i in range(1, N):
    a = int(input())
    G[a - 1].append(i)


def dfs(v):
    if len(G[v]) == 0:
        return 0
    D = []
    for w in G[v]:
        D.append(dfs(w))

    D = sorted(D, reverse=True)

    num = 0
    for i in range(len(D)):
        num = max(num, D[i] + i + 1)

    return num


print(dfs(0))
N,M=map(int,input().split())
dic = {}
A = [int(x) for x in input().split()]
for x in input().split():
  if int(x) not in dic:
    dic[int(x)] = 0
  dic[int(x)] += 1
length = len(A)
for i in range(M):
  b,c  = map(int,input().split())
  if b not in A:
    A[b] = 0
  A[b] += c
A = sorted(A.items(),key = lambda x:x[1],reverse = True)
sum = 0
for v,c in A:
  tmp = min(length,c)
  sum += tem*V
  length -= tmp
print(sum)

### FIXED CODE ###

read = input 
rn = lambda :map(int, read().split())
n,m = rn()
A = list(rn())
l = len(A)
d = {}
for x in A:
    if x not in d:
        d[x]=0
    d[x] += 1
for i in range(m):
    b, c = rn()
    if c not in d:
        d[c]=0
    d[c] += b
A = list(d.items())
A.sort(reverse=True)
ans = 0
cnt = l
# print(A)
for v, c in A:
    tmp = min(cnt, c)
    ans += tmp * v
    cnt -= tmp
print(ans)
from functools import cmp_to_key
s = input()
K = int(input())
 
e = set([])
 
def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1
    
def substring_sort(a,b):
    if len(a) != len(b):
        return cmp(len(a), len(b))
    else:
        return cmp(a,b)
 
for i in range(1,5):
    for j in range(len(s)):
    #     if len(e) < 5:
    #         e.add(s[j:j+i])
    #     if len(e) == 5:
    #         break
    # else:
    #     continue
    # break
        e.add(s[j:j+i])
# print(e)
# result = sorted(e,key=cmp_to_key(substring_sort),reverse=True)
result = sorted(e)
# print(result)
print(result[K-1])

### FIXED CODE ###

# coding: utf-8
# Your code here!

from functools import cmp_to_key
s = input()
K = int(input())
 
e = set([])
 
def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1
    
def substring_sort(a,b):
    if len(a) != len(b):
        return cmp(len(a), len(b))
    else:
        return cmp(a,b)
 
for i in range(1,K+1):
    for j in range(len(s)):
    #     if len(e) < 5:
    #         e.add(s[j:j+i])
    #     if len(e) == 5:
    #         break
    # else:
    #     continue
    # break
        e.add(s[j:j+i])
# print(e)
# result = sorted(e,key=cmp_to_key(substring_sort),reverse=True)
result = sorted(e)
# print(result)
print(result[K-1])
X,Y,Z = list(map(int, input().split(" ")))
print(Z + " " + X + " " + Y)


### FIXED CODE ###

X,Y,Z = list(map(int, input().split(" ")))
print(str(Z) + " " + str(X) + " " + str(Y))
n = int(input())
a = list(map(int, input().split()))
b = [0]*10**5
c = [0]*10**5
for i in range(n):
  if i%2==0:
    b[a[i]]+=1
  else:
    c[a[i]]+=1
bm=max(b)
cm=max(c)
if b.index(max(b))==c.index(max(c)):
  b[b.index(max(b))]=0
  c[c.index(max(c))]=0
  bm2=max(b)
  cm2=max(c)
  print(min(n-bm-cm2,n-cm-bm2))
else:
  print(n-bm-cm)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [0]*(10**5+3)
c = [0]*(10**5+3)
for i in range(n):
  if i%2==0:
    b[a[i]]+=1
  else:
    c[a[i]]+=1
bm=max(b)
cm=max(c)
if b.index(max(b))==c.index(max(c)):
  b[b.index(max(b))]=0
  c[c.index(max(c))]=0
  bm2=max(b)
  cm2=max(c)
  print(min(n-bm-cm2,n-cm-bm2))
else:
  print(n-bm-cm)
A,B,C = map(int,input(),split())
if A+2*B>=C:
  print("Yes")
else :
  print("No")

### FIXED CODE ###

A,B,C = map(int,input().split())
if A+B>=C:
  print("Yes")
else :
  print("No")
N = int(input())
A = list(map(int,input().split()))

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

nodeM = nodeS[0]-A[0]

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

laS[-1] = A[-1]
for i in range(N):
    laS[-2-i] = A[-2-i] + laS[-1-i]


for i in range(N):
    nodeS[i+1] = nodeM*2
    nodeM = nodeS[i+1] - A[i+1]
    if nodeS[i] >= laS[i]:
        j = i
        break
    if i == N-1:
        if nodeS[i+1] >= laS[i+1]:
            j = i+1
        else:
            print(-1)
            exit()

for i in nodeS:
    if i < 0:
        print(-1)
        exit()

ans = sum(nodeS[:j]) + sum(laS[j:])
print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
if N == 0:
    print(1 if A[0] == 1 else -1)
    exit()

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

nodeM = nodeS[0]-A[0]

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

laS[-1] = A[-1]
for i in range(N):
    laS[-2-i] = A[-2-i] + laS[-1-i]


for i in range(N):
    nodeS[i+1] = nodeM*2
    nodeM = nodeS[i+1] - A[i+1]
    if nodeS[i] >= laS[i]:
        j = i
        break
    if i == N-1:
        if nodeS[i+1] >= laS[i+1]:
            j = i+1
        else:
            print(-1)
            exit()

for i in nodeS:
    if i < 0:
        print(-1)
        exit()

ans = sum(nodeS[:j]) + sum(laS[j:])
print(ans)
n,m = map(int,input().split())
c = list(map(int,input().split()))

minimum = [50000] * (n+1)
minimum[0] = 0

for i in range(1,n+1):
    if c[j] <= 2:
        continue
    for j in range(m):
        if c[j]<=i and minimum[i-c[j]] + 1 < minimum[i]:
            minimum[i] = minimum[i-c[j]]+1

print(minimum[n])

### FIXED CODE ###

n = int(input().split()[0])
c = list(map(int,input().split()))
dp = list(range(n+1))

for i in range(2,n+1):
    for j in c:
        if j <= i and dp[i-j] + 1 < dp[i]:
            dp[i] = dp[i-j]+1

print(dp[n])
a.b=[int(i) for i in input().split()]
print(a*b (a+b)*2)

### FIXED CODE ###

a,b = [int(i) for i in input().split()]
print(a*b,a+a+b+b)
n = int(input())

if n % 2 == 1:
    print(0)
else:
    a = 10
    coef = 5
    cnt = 0
    ans = 0
    while a*coef**cnt <= n:
        ans += n // (a*coef**cnt)
        cnt += 1

print(ans)

### FIXED CODE ###

n = int(input())

if n % 2 == 1:
    print(0)
else:
    flg = 0
    ans = 0
    while n >= 5:
        if flg == 0:
            ans += n // 10
            n //= 10
            flg = 1
        else:
            ans += n // 5
            n //= 5

    print(ans)
A2Z="abcdefghijklmnopqrstuvwxyz"

def decode(L1,L2,msg):
    x=[]
    for c in msg:
        if 'a'<=c<='z':
            c = L2[L1.index(c)]
        x.append(c)
    return "".join(x)
        
def affine(msg, key):
    a,b = key
    L = [A2Z[(i*a+b)%26] for i in range(26)]
    L = "".join(L)
    return decode(A2Z,L,msg)

def rot(msg, a):
    if a==0: return msg
    a = a % 26
    L = A2Z[a:]+A2Z[:a]
    return decode(A2Z,L,msg)

def find(msg):
    c0=ord('t')
    for i in range(3,26,2):
        x = affine(msg,[i,0])
        a = (c0-ord(x[0]))%26
        x = rot(x,a)
        if x in['this','that']: return [i,a]
    return []

n = input()
for i in range(n):
    msg = raw_input()
    for w in msg.split():
        if len(w)==4:
            key = find(w)
            if key!=[]: break
    print affine(msg,key)

### FIXED CODE ###

A2Z="abcdefghijklmnopqrstuvwxyz"

def affine(msg, a, b):
    s=""
    for c in msg: s+=(A2Z[(A2Z.index(c)*a+b)%26] if "a"<=c<="z" else c)
    return s

def checkkey(s):
    for i in range(26):
        a = 0
        x = affine(s,i,0)
        c = A2Z.index(x[0])
        if c!=19:
            a = (19-c)%26
            x = affine(x,1,a)
        if x in['this','that']: return i,a
    return -1,-1

n = input()
while n:
    n-=1
    s = raw_input()
    for w in s.split():
        if len(w)==4:
            a,b = checkkey(w)
            if a!=-1: break
    print affine(s,a,b)
S = input()


MOD = 10**9 + 7
# time complexity: O(|S|)
def focus_on_B(S):
    cuml = {"A": [], 
            "C": [],
            "?": []}
    current_nums = {"A": 0,
                    "C": 0,
                    "?": 0}
    for char in S:
        if char in cuml.keys():
            current_nums[char] += 1
        for key in cuml.keys():
            cuml[key].append(current_nums[key])

    num_combinations = 0
    for i in range(1, len(S) - 1):
        if S[i] in {"B", "?"}:
            A_L = cuml["A"][i-1]
            Q_L = cuml["?"][i-1]
            C_R = cuml["C"][-1] - cuml["C"][i]
            Q_R = cuml["?"][-1] - cuml["?"][i]
            num_combinations += int((A_L * 3 + Q_L) * 3**(Q_L - 1)\
                            * (C_R * 3 + Q_R) * 3**(Q_R - 1))
            num_combinations %= MOD
        else:
            continue
    print(num_combinations)


focus_on_B(S)


### FIXED CODE ###

S = input()

MOD = 10**9 + 7
dp = [[0] * 4 for _ in range(len(S) + 1)]
dp[len(S)][3] = 1
for i in range(len(S))[::-1]:
    dp[i][3] = 3 * dp[i + 1][3] if S[i] == "?" else dp[i + 1][3]
    dp[i][3] %= MOD
    if S[i] == "?":
        dp[i][0] = (3 * dp[i + 1][0] + dp[i + 1][1]) % MOD
        dp[i][1] = (3 * dp[i + 1][1] + dp[i + 1][2]) % MOD
        dp[i][2] = (3 * dp[i + 1][2] + dp[i + 1][3]) % MOD
    else:
        dp[i][0] = (dp[i + 1][0] + int(S[i] == "A") * dp[i + 1][1]) % MOD
        dp[i][1] = (dp[i + 1][1] + int(S[i] == "B") * dp[i + 1][2]) % MOD
        dp[i][2] = (dp[i + 1][2] + int(S[i] == "C") * dp[i + 1][3]) % MOD
print(dp[0][0])
cnt = 0
ans = False
for i in range(n):
    a,b = dd[i]
    if a == b:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        ans = True
if ans:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

(n,), *dd = [list(map(int, s.split())) for s in open(0)]

cnt = 0
ans = False
for i in range(n):
    a,b = dd[i]
    if a == b:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        ans = True
if ans:
    print('Yes')
else:
    print('No')
n = str(input())
list_n = n.split(" ")
n = list_n[0]
k = list_n[1]
if n % k == 0:
    print(0)
else:
    print(1)

### FIXED CODE ###

n = str(input())
[n, k] = list(map(int,n.split(" ")))
if n % k == 0:
    print(0)
else:
    print(1)
v
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())

answer = 0
for _ in range(N):
    x,u = input().split()
    if u == "JPY":
        money = int(x) 
    else:
        money = float(x)*380000.0
    answer += money
print(answer)


### FIXED CODE ###

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

N = int(input())

answer = 0
for _ in range(N):
    x,u = input().split()
    if u == "JPY":
        money = float(x) 
    else:
        money = float(x)*380000.0
    answer += money
print(answer)
a,b=input().split
if a>8 or b>8:
  print(":(")
else:
  print("Yay!")

### FIXED CODE ###

a,b=input().split()
a=int(a)
b=int(b)
if a<=8:
  if b<=8:
    print("Yay!")
  else:
    print(":(")
else:
  print(":(")
a, b = map(int, input().split())
if a%3==0 or b%3==0 or (a+b)%==0:
    print('Possible')
else:
    print('Impossible')

### FIXED CODE ###

a, b = map(int, input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
    print('Possible')
else:
    print('Impossible')
S = input()
if len(set((S[0], S[1], S[2]))) == 3:
    print("Yes")
else:
    pritn("No")


### FIXED CODE ###

S = input()
if len(set((S[0], S[1], S[2]))) == 3:
    print("Yes")
else:
    print("No")
from itertools import permutations

n = int(input())
p = tuple(((map(int,input().split()))))
q = tuple(((map(int,input().split()))))

cnt=0
for v in permutations(range(1,N+1), N):
    cnt +=1
    if(p==v):
        a = cnt
    if(q==v):
        b = cnt

print(abs(a-b))

### FIXED CODE ###

import itertools
n = int(input())
p = tuple(((map(int,input().split()))))
q = tuple(((map(int,input().split()))))

num = []
for i in range(1,n+1):
    num.append(i)
ans = []
for i in itertools.permutations(num,n):
    ans.append(i)

print(abs(ans.index(p)-ans.index(q)))
a = input()
b = input()
i = 0
for i in range(len(a)):
    print(a[i], end = '')
    if i == len(b):
        break
    print(b[i], end = '')

### FIXED CODE ###

a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
if b - a == c - b:
    print('YES')
else:
    print('NO')
n = int(input())
ans=0
for i in range(1,N+1,2):
    a=0
    for j in range(1,i+1,2):
        if i%j==0:
            a+=1
    if a==8:
        ans+=1
print(ans)


### FIXED CODE ###

n = int(input())
ans=0
for i in range(1,n+1,2):
    a=0
    for j in range(1,i+1,2):
        if i%j==0:
            a+=1
    if a==8:
        ans+=1
print(ans)
import numpy as np

n = int(input())
a = list(map(int, input().split()))
sum = 0
k = 0
for i in range(len(a)-1):
    for j in range(i+1,len(a)):
        k += a[j]

    
    sum += a[i] * k

    k = 0
        
ans = np.mod(sum,10**9+7)

print(ans)



### FIXED CODE ###


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

MOD = 10 ** 9 + 7

sum = sum(a) % MOD
ans = 0

for i in range(len(a)):
    sum -= a[i]
    sum %= MOD
    ans += a[i] * sum
    ans %= MOD

print(ans)
#C - Traveling
num = int( input())
check = 0
step_b = 0
x_b = 0
y_b = 0
for i in range(num):
    step ,x ,y = map(int,input().split())
    if ((x-x_b)+(y-y_b) - (step-step_b)  > 0) or (((x-x_b)+(y-y_b) - (step - step_b))%2 > 0) :
        check = 1
        break
    print(((x-x_b)+(y-y_b) - (step - step_b)))
    x_b = x
    y_b = y
    step_b = step
if check == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

a,b = map(int,input().split())
if a*b%2 == 0 or a*b == 0:
    print('Even')
else:
    print('Odd')
N, M, Q = [int(_) for _ in input().split()]
ABCD = [[int(_) for _ in input().split()] for _ in range(Q)]
cand = [[i] for i in list(range(1, M + 1))]
for i in range(M):
    candn = []
    for l in cand:
        j = l[-1]
        candn += [l + [k] for k in range(j, M + 1)]
    cand = candn
ans = 0
for l in cand:
    x = 0
    for a, b, c, d in ABCD:
        if l[b - 1] - l[a - 1] == c:
            x += d
    ans = max([ans, x])
print(ans)


### FIXED CODE ###

N, M, Q = [int(_) for _ in input().split()]
ABCD = [[int(_) for _ in input().split()] for _ in range(Q)]
cand = [[i] for i in list(range(1, M + 1))]
for i in range(N - 1):
    candn = []
    for l in cand:
        j = l[-1]
        candn += [l + [k] for k in range(j, M + 1)]
    cand = candn
ans = 0
for l in cand:
    x = 0
    for a, b, c, d in ABCD:
        if l[b - 1] - l[a - 1] == c:
            x += d
    ans = max([ans, x])
print(ans)
C = [int(i) for i in input()]

pre = len(C)

def recursive(list):
    if len(list) == 0:
        return []
    for i,l in enumerate(list):
        if i == len(list) -1:
            break
        if (list[i] ==0 and list[i + 1] == 1) or (list[i] ==1 and list[i +1 ] ==0 ):
            #print(list)
            list.pop(i)
            list.pop(i)
            recursive(list)

recursive(C)
print(pre -len(C))



### FIXED CODE ###

C = [int(i) for i in input()]

zero_cnt = C.count(0)
one_cnt = C.count(1)
print(min(zero_cnt,one_cnt) *2)
while True:
    m, f, r = [int(i) for i in input().split()]

    if m == f ==r -1:
        break

    total = m + f
    if m == -1 or f == -1 or total < 30:
        print('F')

    elif total < 50 and r < 50:
        print('D')

    elif total < 65:
        print('C')
        
    else:
        print('A')
        

### FIXED CODE ###

while True:
    m, f, r = [int(i) for i in input().split()]

    if m == f == r == -1:
        break

    total = m + f
    if m == -1 or f == -1 or total < 30:
        print('F')

    elif total < 50 and r < 50:
        print('D')

    elif total < 65:
        print('C')
        
    elif total < 80:
        print('B')

    else:
        print('A')
while 1:
    n = int(raw_input())
    cnt = 0;
    for i in range(0, 10):
        for j in range(0, 10):
            for k in range(0, 10):
                for l in range(0, 10):
                    if n == i+j+k+l: cnt+=1
    print cnt

### FIXED CODE ###

while True:
    try:
        n = int(raw_input())
        
        cnt = 0;
        for i in range(0, 10):
            for j in range(0, 10):
                for k in range(0, 10):
                    for l in range(0, 10):
                        if n == i+j+k+l: cnt+=1
        print cnt

    except EOFError:
        break
nums = map(int, input().split())
sums = [sum(nums[i:i+3] for i in range(len(nums)-1))]
poyo = [abs(x-753) for x in sums]
print(min(poyo))

### FIXED CODE ###

s = input()
list = [int(c) for c in s]
num = []
ans = 753
for i in range(len(list)-2):
	num.append((list[i] * 100) + (list[i+1] * 10) + list[i+2])
	if(num[i] >= 753):
		if(ans >= (num[i] - 753)):
			ans = num[i] - 753
	else:
		if(ans > (753 - num[i])):
			ans = 753 - num[i]
print(ans)
import math

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

print((a*b) // math.gcd(a, b))

### FIXED CODE ###

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

print(int(A*B/fractions.gcd(A,B)))
a=raw_input()
h=a/3600
r=a-h*3600
s=a-h*3600-r*60
print h:r:s

### FIXED CODE ###

S=input()
h=S/3600
r=S%3600/60
s=S-h*3600-r*60
print str(h)+':'+str(r)+':'+str(s)