Harryxun/stf_run huggingface dataset:
N, M = map(int,input().split())
L = list(map(int,input().split()))
K = [0,2,5,5,4,5,6,3,7,6]
A = sorted([[L[k],K[L[k]]] for k in range(M)])[::-1]
dp = [0 for k in range(N+1)]

for k in range(1,N+1):
    t = -float("inf")
    for j in range(M):
        if k-A[j][1]>=0:
            t = max(t, dp[k-A[j][1]]+1)
    dp[k] = t

ans = ""
keta = dp[N]
match = N
while keta > 0:
    for k in range(M):
        if dp[match-A[k][1]] == keta-1:
            ans += str(A[k][0])
            match -= A[k][1]
            keta -= 1
            break
print(ans)

### FIXED CODE ###

N, M = map(int,input().split())
L = list(map(int,input().split()))
K = [0,2,5,5,4,5,6,3,7,6]
A = sorted([[L[k],K[L[k]]] for k in range(M)])[::-1]
dp = [0 for k in range(N+1)]

for k in range(1,N+1):
    t = -float("inf")
    for j in range(M):
        if k-A[j][1]>=0:
            t = max(t, dp[k-A[j][1]]+1)
    dp[k] = t

ans = ""
keta = dp[N]
match = N
while keta > 0:
    for k in range(M):
        if match-A[k][1] >= 0:
            if dp[match-A[k][1]] == keta-1:
                ans += str(A[k][0])
                match -= A[k][1]
                keta -= 1
                break
print(ans)
def draw(h, w):
    print("#" * w)
    for i in range(h-2)
        print("#" + ("."*(w-2)) + "#")
    print("#" * w)
    print "\n"

while True:
    h, w = map(int, raw_input().split())
    if h == 0 and w == 0:
        break
    draw(h, w)

### FIXED CODE ###

def draw(h, w):
    print("#" * w)
    for i in range(h-2):
        print("#" + ("."*(w-2)) + "#")
    print("#" * w)
    print("")

while True:
    h, w = map(int, raw_input().split())
    if h == 0 and w == 0:
        break
    draw(h, w)
x, n = map(int, input().split())
if n != 0:
  p = list(map(int, input().split()))

# x, n = 10, 5
# p =  [4, 7, 10, 6, 5]
# ->9が解

# pに含まれない整数リストを、最小値-1最大値+1も含めて求める
pl = min(p)-1
pr = max(p)+1
npl = list(range(pl, pr))
np = list(set(npl) - set(p))
np.sort()

# np内で最もxに近い数値を算出する
mx = x
res = x
for k in np:
  t = abs(k - x)
  if t < mx:
    mx = t
    res = k

print(k)

### FIXED CODE ###

x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
  print(x)
  exit()
  
# x, n = 10, 5
# p =  [4, 7, 10, 6, 5]
# ->9が解
# x, n = 6, 5
# p = [4, 7, 10, 6, 5]

# x, n = 1, 1
# # p = list(range(1, 101))
# p = [1]

# pに含まれない整数リストを、最小値-1最大値+1も含めて求める
pl = min(p)-1
pr = max(p)+2
npl = list(range(pl, pr))
np = list(set(npl) - set(p))
if len(np) == 0:
  print(x)
  exit()
np.sort()

# np内で最もxに近い数値を算出する
mx = x
res = np[0]
for k in np:
  t = abs(k - x)
  if t < mx:
    mx = t
    res = k
 
print(res)
def prepare(n,arr):
    nodeArr = [[] for i in range(n)]
    for ar in arr:
        nodeArr[ar[0]-1].append([ar[1]-1,ar[2]])
        nodeArr[ar[1]-1].append([ar[0]-1,ar[2]])
    return nodeArr





def dfs(parent,currentNode,distance):

    if len(nodeArr[currentNode]) == 1:
        if currentNode != 0:
            # 末点
            res[currentNode] = distance
            return

    for next in nodeArr[currentNode]:
        nextNode = next[0]
        nextNodeDistance = next[1]
        if nextNode == parent:
            continue
        dfs(currentNode,nextNode,distance + nextNodeDistance)
        res[currentNode] = distance


n = int(input())

arr = []

for i in range(n-1):
    arr.append([int(s) for s in input().split(" ")])

nodeArr = prepare(n, arr)
res = [-1 for i in range(n)]

dfs(-1,0,0)

result = [(re % 2) for re in res]

for re in res:
    print(re % 2)



### FIXED CODE ###

import sys
sys.setrecursionlimit(20000000)
def prepare(n,arr):
    nodeArr = [[] for i in range(n)]
    for ar in arr:
        nodeArr[ar[0]-1].append([ar[1]-1,ar[2]])
        nodeArr[ar[1]-1].append([ar[0]-1,ar[2]])
    return nodeArr

def dfs(currentNode,distance):
    res[currentNode] = distance
    for next in nodeArr[currentNode]:
        nextNode = next[0]
        nextNodeDistance = next[1]
        if res[nextNode] == -1:
            dfs(nextNode,distance + nextNodeDistance)




n = int(input())

arr = []

for i in range(n-1):
    arr.append([int(s) for s in input().split(" ")])

nodeArr = prepare(n, arr)


if n == 1:
    print(1)
else:
    res = [-1 for i in range(n)]

    dfs(0,0)

    result = [(re % 2) for re in res]

    for re in res:
        print(re % 2)
from itertools import accumulate, chain
 
n, c = map(int, input().split())
xs, vs = zip(*(map(int, input().split()) for _ in range(n)))
 
ds = [j - i for i, j in zip(chain([0], xs), chain(xs, [c]))]
 
clockwise1      = chain([0], (v - d*2 for v, d in zip(accumulate(vs), accumulate(ds))))
anticlockwise1  = chain([0], (v - d for v, d in zip(accumulate(vs[::-1]), accumulate(ds[::-1]))))
clock_anticlock = (x + y for x, y in zip(clockwise1, reversed(list(accumulate(anticlockwise1, func=max)))))
 
anticlockwise2  = chain([0], (v - d*2 for v, d in zip(accumulate(vs[::-1]), accumulate(ds[::-1]))))
clockwise2      = chain([0], (v - d for v, d in zip(accumulate(vs), accumulate(ds))))
anticlock_clock = (x + y for x, y in zip(anticlockwise2, reversed(list(accumulate(clockwise2, func=max)))))
 
print(max(chain(anticlock_clock, clock_anticlock)))
from itertools import accumulate, chain

n, c = map(int, input().split())
xs, vs = zip(*(map(int, input().split()) for _ in range(n)))

ds = [j - i for i, j in zip(chain([0], xs), chain(xs, [c]))]

clockwise1      = chain([0], (v - d*2 for v, d in zip(accumulate(vs), accumulate(ds))))
anticlockwise1  = chain([0], (v - d for v, d in zip(accumulate(vs[::-1]), accumulate(ds[::-1]))))
clock_anticlock = (x + y for x, y in zip(clockwise1, reversed(list(accumulate(anticlockwise1, func=max)))))

anticlockwise2  = chain([0], (v - d*2 for v, d in zip(accumulate(vs[::-1]), accumulate(ds[::-1]))))
clockwise2      = chain([0], (v - d for v, d in zip(accumulate(vs), accumulate(ds))))
anticlock_clock = (x + y for x, y in zip(anticlockwise2, reversed(list(accumulate(clockwise2, func=max)))))
 
print(max(chain(clock_anticlock, anticlock_clock)))

### FIXED CODE ###

from itertools import accumulate

n, c = map(int, input().split())
xs, vs = zip(*(map(int, input().split()) for _ in range(n)))

xs = (0,) + xs + (c,)
ds = [j - i for i, j in zip(xs, xs[1:])]

clockwise = [0] + [v - d for v, d in zip(accumulate(vs), accumulate(ds))]
clockwise_maxs = list(accumulate(clockwise, func=max))
clock_max = clockwise_maxs[-1]

anticlockwise = [0] + [v - d for v, d in zip(accumulate(vs[::-1]), accumulate(ds[::-1]))]
anticlockwise_maxs = list(accumulate(anticlockwise, func=max))
anticlock_max = anticlockwise_maxs[-1]

clockwise2 = [0] + [v - d*2 for v, d in zip(accumulate(vs), accumulate(ds))]
clock_anticlock = [x + y for x, y in zip(clockwise2, reversed(anticlockwise_maxs))]
c_ac_max = max(clock_anticlock)

anticlockwise2 = [0] + [v - d*2 for v, d in zip(accumulate(vs[::-1]), accumulate(ds[::-1]))]
anticlock_clock = [x + y for x, y in zip(anticlockwise2, reversed(clockwise_maxs))]
ac_c_max = max(anticlock_clock)

print(max(clock_max, anticlock_max, c_ac_max, ac_c_max))
N = input()
 
if N[-1]==2or N[-1]==4 or N[-1]==5or N[-1]==7or N[-1]==9:
     print('hon')
     
    elif N[-1]==0or N[-1]==1or N[-1]==6or N[-1]==8:
    print('pon')
     
    else:
    print('bon')

### FIXED CODE ###

N = input()
 
if N[-1]=='2' or N[-1]=='4' or N[-1]=='5' or N[-1]=='7' or N[-1]=='9':
    print('hon')
     
elif N[-1]=='0' or N[-1]=='1' or N[-1]=='6' or N[-1]=='8':
    print('pon')
     
else:
    print('bon')
n,a,b = list(map(int,input().split()))
kurikaeshi = n // (a + b)
amari = n - (kurikaeshi * (a+b))
ball_list = []
ans = 0
blue = 'b' * a
red = 'r' * b
if(amari - len(blue) < 0):
    ans = 0
else:
    ans = len(blue) - amari
print(ans)

### FIXED CODE ###

n,a,b = list(map(int,input().split()))
if(a != 0):
    kurikaeshi = n // (a + b)
    mod = n % (a + b)
    ans = a*kurikaeshi
    if(mod - a > 0):
        ans += a
    else:
        ans += mod
if(a == 0):
    ans = 0
print(ans)
s = input().split()
if s[0]==s[1] or s[1]==s[2] or s[2] == s[3]:
    print("Bad")
else:
    print("Good")

### FIXED CODE ###

s = input()
if s[0]==s[1] or s[1]==s[2] or s[2] == s[3]:
    print("Bad")
else:
    print("Good")
N, M = map(int, input().split())
Ps = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    Ps[x - 1].append(y - 1)

mem = [-1] * N


def rec(n):
    if mem[n] > -1:
        return mem[n]
    elif len(Ps[n]) == 0:
        mem[n] = 0
        return mem[n]
    else:
        mem[n] = max([rec(Ps[n][i]) for i in range(len(Ps[n]))]) + 1
        return mem[n]


for i in range(N):
    rec(i)
print(max(mem))

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 5 * 2)
N, M = map(int, input().split())
Ps = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    Ps[x - 1].append(y - 1)

mem = [-1] * N


def rec(n):
    if mem[n] > -1:
        return mem[n]
    elif len(Ps[n]) == 0:
        mem[n] = 0
        return mem[n]
    else:
        mem[n] = max([rec(Ps[n][i]) for i in range(len(Ps[n]))]) + 1
        return mem[n]


for i in range(N):
    rec(i)
print(max(mem))
N= int(input())
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
ans=[]

if N==1:
    print(A1[0]+A2[0])
    exit()
else:
    for i in range(N):
        ansA1=0
        ansA2=0
        for j in range(i):
            ansA1+=A1[j]
        for k in range(j,N):
            ansA2+=A2[k]
        ans1=ansA1+ansA2
        ans.append(ans1)

print(max(ans))

### FIXED CODE ###

N = int(input())
a = [list(map(int,input().split())) for i in range(2)]
b = []
for i in range(0,N):
    s = 0
    v = 0
    for j in range(0,i+1):
        s += a[0][j]
    for j in range(i,N):
        v += a[1][j]
    b.append(s+v)
print(max(b))
n,k = map(int,input().split())
lst = list(map(int,input().split()))
lst.append(k+lst[0])
maxe = 0
for i in range(1,n+1):
    maxe =max(maxe,lst[i]-lst[i-1])
print(k-maxe)               

### FIXED CODE ###

k,n = map(int,input().split())
lst = list(map(int,input().split()))
lst.append(k+lst[0])
maxe = 0
for i in range(1,n+1):
    maxe =max(maxe,lst[i]-lst[i-1])
print(k-maxe)
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = ((N - 1) + (K - 1 - 1)) // (K - 1)
print(ans)


### FIXED CODE ###

import numpy as np
N, K = map(int, input().split())
X = np.array(list(map(int, input().split())))
idx = np.searchsorted(X, 0)
# print('idx', idx)
ans = 10**10
for i in range(N - K + 1):
    l = i
    r = i + K - 1
    d1 = np.abs(X[l]) + np.abs(X[r] - X[l])
    d2 = np.abs(X[r]) + np.abs(X[r] - X[l])
    d = min(d1, d2)
    ans = min(ans, d)
print(ans)
b=｛25:"Christmas",24:"Christmas Eve",23:"Christmas Eve Eve",22:"Christmas Eve Eve Eve"｝
print(b[int(input())])

### FIXED CODE ###

b={25:"Christmas",24:"Christmas Eve",23:"Christmas Eve Eve",22:"Christmas Eve Eve Eve"}
print(b[int(input())])
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(); b.sort(); c.sort()
ins_c = [0]*n
ins_b = [0]*n
parts_comb = [0]*n
for i in range(n) :
    ins_c = bisect.bisect_right(c, b[i])
    ins_b = bisect.bisect_right(b, a[i])
ans = 0
for i in range(n) :
    for j in range(ins_b[i], n) :
        ans += n - r_c

print(ans)

### FIXED CODE ###

import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(); b.sort(); c.sort()
dp = [0]*(n+1)
for i in range(n-1, -1, -1) :
    ins_c = bisect.bisect_right(c, b[i])
    dp[i] = dp[i+1] + (n-ins_c)
ans = 0
for i in range(n) :
    ins_b = bisect.bisect_right(b, a[i])
    ans += dp[ins_b]

print(ans)
N,K = map(int, input().split())

g2 = [[0]*(K+1) for _ in range(K+1)]
def gcd(a, b):
    if g2[a][b] > 0:
        return g2[a][b]
    tmpa = a
    tmpb = b
    while b > 0:
        a,b = b, a%b
    g2[tmpa][tmpb] = a
    g2[tmpb][tmpa] = a
    return a

def gcd_3(a,b,c):
    g = gcd(a,b)
    g = gcd(g,c)
    return g

sm = 0
for a in range(1, K+1):
    for b in range(a+1, K+1):
        for c in range(b+1, K+1):
            sm += gcd_3(a,b,c)

print(sm)


### FIXED CODE ###

K = int(input())

g2 = [[0]*(K+1) for _ in range(K+1)]
def gcd(a, b):
    if g2[a][b] > 0:
        return g2[a][b]
    tmpa = a
    tmpb = b
    while b > 0:
        a,b = b, a%b
    g2[tmpa][tmpb] = a
    g2[tmpb][tmpa] = a
    return a

def gcd_3(a,b,c):
    g = gcd(a,b)
    g = gcd(g,c)
    return g

sm = 0
for a in range(1, K+1):
    sm += a
    for b in range(a+1, K+1):
        for c in range(b+1, K+1):
            sm += gcd_3(a,b,c) * 6
    for b in range(1, K+1):
        if a != b:
            sm += gcd(a,b) * 3

print(sm)
import sys
lst = [[int(j) for j in i] for i in sys.stdin.readlines()]n = int(input())
lst = [[int(i) for i in input().split()] for _ in range(n)]
p = 0
for i in lst:
  p += i[1] - i[0] + 1
print(p)

### FIXED CODE ###

n = int(input())
lst = [[int(i) for i in input().split()] for _ in range(n)]
p = 0
for i in lst:
  p += i[1] - i[0] + 1
print(p)
INF = int(1e18)

def compute():
    from sys import stdin
    A, B, Q = list(map(int, stdin.readline().split()))
    s = sorted(int(stdin.readline().split()[0]) for _ in range(A))
    t = sorted(int(stdin.readline().split()[0]) for _ in range(B))

    from bisect import bisect_left
    for _ in range(Q):
        x = int(stdin.readline().split()[0])

        i1 = bisect_left(s, x)
        i1 = i1 if i1 < A else i1-1
        i2 = i1-1 if (i1>0) and s[i1]!=x else i1

        res = INF
        for y in set((s[i1], s[i2])):
            j1 = bisect_left(t, y)
            j1 = j1 if (j1 < B) else j1-1
            j2 = j1-1 if (j1 > 0) and t[j1]!=y else j1
            for z in set((t[j1],t[j2])):
                # print(x, y, z)
                res = min(res, abs(x-y) + abs(y-z), abs(x-z) + abs(z-y))

        print(res)


if __name__ == "__main__":
    compute()


### FIXED CODE ###

from sys import stdin
 
i = stdin.readline().strip()
d = tuple(map(int, i.split("/")))
print("Heisei" if d <= (2019,4,30) else "TBD")
s = input()

checker = ''

if len(s) <= 2:
    if s[0] == s[1]:
        print(1, 2)
        checker += '*'
    else:
        print(-1, -1)
        checker += '*'


if checker == ''
    for a, b in zip(range(len(s)-1), range(1,len(s))):
        if s[a] == s[b]:
            print(a+1, b+1)
            checker += '*'
            break

if checker == '':
    for a, c in zip(list(range(len(s)-2)), list(range(2, len(s)))):
        if s[a] == s[c]:
            print(a+1, c+1)
            chekcher += '*'
            break

if checker == '':
    print(-1, -1)


### FIXED CODE ###

s = input()

checker = ''

if len(s) == 2:
    if s[0] == s[1]:
        print(1, 2)
        checker += '*'
    else:
        print(-1, -1)
        checker += '*'


if checker == '':
    for a, b in zip(range(len(s)-1), range(1,len(s))):
        if s[a] == s[b]:
            print(a+1, b+1)
            checker += '*'
            break

if checker == '':
    for a, c in zip(range(len(s)-2), range(2, len(s))):
        if s[a] == s[c]:
            print(a+1, c+1)
            checker += '*'
            break

if checker == '':
    print(-1, -1)
a, b, c = input.split(",")
print(a, b, c)

### FIXED CODE ###

a,b,c = input().split(",")
print(a, b, c)
from collections import deque as q
import bisect

N,M,K=map(int,input().split())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))

def f(nb,s,ia,ib):
    #print(nb,s,ia,ib)
    if s > K:
        return nb-1
    if ia==N and ib==M:
        return nb
    
    nb_max=0
    for nxt in ['a','b']:
        if nxt == 'a':
            if ia==N:
                continue
            nb_max=f(nb+1,s+As[ia],ia+1,ib)
        if nxt == 'b':
            if ib==M:
                continue
            nb_tmp=f(nb+1,s+Bs[ib],ia,ib+1)
            if nb_max < nb_tmp:
                nb_max = nb_tmp
    return nb_max



ans = f(0,0,0,0)
print(ans)

### FIXED CODE ###

N,M,K=map(int,input().split())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))

a_sum=[0]
for i in range(N):
    a_sum.append(a_sum[-1]+As[i])

b_sum=[0]
for i in range(M):
    b_sum.append(b_sum[-1]+Bs[i])

j=M
ans=0
for i in range(N+1):
    if a_sum[i] > K:
        break

    while b_sum[j] > K - a_sum[i]:
        j-=1
    ans = max(ans, i+j)
print(ans)
a, b = int(input())
if a < 10 and b < 10:
  print(a＊b)
else:
  print(-1)

### FIXED CODE ###

a, b = map(int, input().split())
if a < 10 and b < 10:
  print(a*b)
else:
  print(-1)
import numpy as np
N = int(input())
S = []
for i in range(N):
    S.append(list(map(int,input().split())))
now = [0,0]
flag = True
for i in range(N):
    dis = abs(S[i][1]-now[0])+abs(S[i][2]-now[1])
    if(dis > S[i][0] or (S[i][0]-time)%2 != dis%2):
        flag = False
        break
    now[0] = S[i][1]
    now[1] = S[i][2]
    time = S[i][0]
    
if flag:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import numpy as np
N = int(input())
S = []
for i in range(N):
    S.append(list(map(int,input().split())))
now = [0,0]
time = 0
flag = True
for i in range(N):
    dis = abs(S[i][1]-now[0])+abs(S[i][2]-now[1])
    if(dis > S[i][0] or (S[i][0]-time)%2 != dis%2):
        flag = False
        break
    now[0] = S[i][1]
    now[1] = S[i][2]
    time = S[i][0]
    
if flag:
    print("Yes")
else:
    print("No")
N = input()
A = list(map(int,input().split()))
#２の倍数かどうかを調べる関数　引数:4→True,5→False

def isAllEVEN(A):
    return (not (False in (list(map(lambda x:x%2==0,A)))))

i = 0
while(isAllEVEN(A)):
A = list(map(lambda x:x/2,A))
    i++;
       

### FIXED CODE ###

def choise(n,s):
    k = 0
    lis = s.split()
    lis = list(map(lambda x: int(x), lis))
    while (len(lis) == int(n)):
        lis = list(filter(lambda x: x % 2 == 0, lis))
        if (len(lis) == int(n)): k += 1
        lis = list(map(lambda x: x / 2, lis))
    return k

if __name__ == "__main__":
    n = input()
    s = input()

    print(choise(n,s))
X,A,B = map(int,input().split(' '))
print((X - A) - int((X-A) /100) * B)

### FIXED CODE ###


X = int(input())
A = int(input())
B = int(input())
print((X - A)% B)
s=input()
k=int(input())
n=len(s)
ans=[]
for i in range(1,n+1):
  for j in range(n-i+1):ans.append(s[j:j+i])
  if len(ans)>=k:break
ans=sorted(list(set(ans)))
print(ans[k-1])

### FIXED CODE ###

s=input()
k=int(input())
a={s}
for i in range(k):
  for j in range(len(s)-i):a.add(s[j:j+i+1])
print(sorted(list(a))[k-1])
a, b = map(int, input().split())

if a+b == 3:
  print(3)
elif a+b == 4:
  print(2)
else:
  print(1)

### FIXED CODE ###

a = int(input())
b = int(input())

if a+b == 3:
  print(3)
elif a+b == 4:
  print(2)
else:
  print(1)
import sys
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int64)
b = np.array(input().split(), dtype=np.int64)
ac = np.bincount(a, minlength=n+2)
ab = np.bincount(b, minlength=n+2)
if np.max(ac+ab) <= n:
    num, count = np.unique(b, return_counts=True)
    ans = []
    for i in range(n):
        if a[i] == num[-1]:
            if len(num) == 1:
              print("No")
              sys.exit()
            ans.append(num[-2])
            if count[-2] == 1:
                num[-2] = num[-1]
                count[-2] = count[-1]
                num = num[:-1]
                count = count[:-1]
            else:
                count[-2] -= 1
        else:
            ans.append(num[-1])
            if count[-1] == 1:
                num = num[:-1]
                count = count[:-1]
            else:
                count[-1] -= 1
    print("Yes")
    print(*ans)
else:
    print("No")


### FIXED CODE ###

x = int(input())
if x == 1:
    ans = 0
else:
    ans = 1
print(ans)
K = int(input())
A, B = map(int,input().spilt())
if(A<=(B//K)*K){
  print("OK")
}
else{
  print("NG")
}


### FIXED CODE ###

N = int(input())
A, B = map(int, input().split())
for i in range(A, B+1):
  if i % N == 0:
    print('OK')
    break
else:
  print('NG')
N=int(input())
array=list(map(int,input().split()))
array.sort()
import itertools
list1=list(itertools.combinations(array,3))
ans=0
for n in range(len(list1)):
  if list[n][0]!=list[n][1] and list[n][1]!=list[n][2]:
    if list[n][0]+list[n][1]>list[n][2]:
      ans=ans+1
print(ans)

### FIXED CODE ###

import itertools
n = int(input())
data = list(map(int, input().split()))
data1=sorted(data)
a = list(itertools.combinations(data1,3))
ans=0
for m in range(len(a)):
  if a[m][0]!=a[m][1] and a[m][1]!=a[m][2]:
    if a[m][0]+a[m][1]>a[m][2]:
      ans=ans+1
print(ans)
from  math import log10
n = int(input())
dig = int(log10(n)+1)
cnt = 0
for _ in range(dig):
  cnt += n%10 
  n //= 10
print('Yes' if cnt%9 == 0 else 'No')

### FIXED CODE ###

print('Yes' if sum(list(map(int, list(input()))))%9 == 0 else 'No')
n = int(input())
arr = list(map(int,input().split(' ')))
res = [0]*(n+1)
for i,v in enumerate(arr):
  res[v] = i+1
res.pop(0)
print(' '.join(res))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
 
b = [0] * n
for i in range(n):
    b[a[i] - 1] = str(i + 1)
 
print(' '.join(b))
import itertools
import collections
N = int(input())
A = [int(_) for _ in input().split()]
c = sorted(collections.Counter(A).values())
acc = list(itertools.accumulate([0] + c))
n = len(acc) - 1
j = 0
for i in range(1, N + 1):
    r = 0
    if j < n - 1:
        while i - j > 0:
            if (i - j) * c[-1 - j] <= acc[-1 - j]:
                r = acc[-1 - j] // (i - j)
                break
            else:
                j += 1
    print(r)


### FIXED CODE ###

import itertools
import collections
N = int(input())
A = [int(_) for _ in input().split()]
c = sorted(collections.Counter(A).values())
acc = list(itertools.accumulate([0] + c))
n = len(acc) - 1
j = 0
for i in range(1, n + 1):
    r = 0
    while i - j > 0:
        if (i - j) * c[-1 - j] <= acc[-1 - j]:
            r = acc[-1 - j] // (i - j)
            break
        else:
            j += 1
    print(r)
for _ in range(N - n):
    print(0)
int i = 1
while(true):
 x = int(input())
 if(x == 0):
  break
 print('case {0}: {1}'.format(i,x))
 i++


### FIXED CODE ###

i = 1
while True:
 x = int(input())
 if x == 0:
  break
 print('Case %d: %d' % (i,x))
 i +=1
import itertools

N, M, Q = list(map(int,input().split()))
numbers = [i for i in range(1, M+1)]
array = itertools.combinations_wih_replacement(numbers, N)

input_data = [list(map(int,input().split())) for _ in range(Q)]

max_score = 0
for A in array:
    score = 0
    for _ in range(Q):
        a, b, c, d = input_data[_]
        a = a - 1
        b = b - 1
        if A[b] - A[a] == c:
            score += d
    if score > max_score:
        max_score = score
    
print(max_score)

### FIXED CODE ###

import itertools

N, M, Q = list(map(int,input().split()))
numbers = [i for i in range(1, M+1)]
array = itertools.combinations_with_replacement(numbers, N)

input_data = [list(map(int,input().split())) for _ in range(Q)]

max_score = 0
for A in array:
    score = 0
    for _ in range(Q):
        a, b, c, d = input_data[_]
        a = a - 1
        b = b - 1
        if A[b] - A[a] == c:
            score += d
    if score > max_score:
        max_score = score
    
print(max_score)
count = 0
while True:
    if (count + 1) ** 2 > N:
        print(count)
        break
    count += 1


### FIXED CODE ###

N = int(input().strip())
 
count = 0
while True:
    if (count + 1) ** 2 > N:
        print(count ** 2)
        break
    count += 1
n,m,q=map(int,input().split())
abcd=[]
for _ in range(q):
	a,b,c,d=map(int,input().split())
	abcd.append((a,b,c,d))
ans=0
p=[]
sys.setrecursionlimit(10**6)
def dfs(x):
	if len(x)==n:
		p.append(x)
	else:
		for i in range(n-x[-1]+1):
			dfs(x+[x[-1]+i])
dfs([1])
# import itertools
# p=itertools.combinations_with_replacement(range(1,m+1),n)
for x in p:
	r=0
	for i in range(q):
		if x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]:
			r+=abcd[i][3]
	ans=max(ans,r)
print(ans)

### FIXED CODE ###

n,m,q=map(int,input().split())
abcd=[]
for _ in range(q):
	a,b,c,d=map(int,input().split())
	abcd.append((a,b,c,d))
ans=0
import itertools
p=itertools.combinations_with_replacement(range(1,m+1),n)
for x in p:
	r=0
	for i in range(q):
		if x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]:
			r+=abcd[i][3]
	ans=max(ans,r)
print(ans)