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

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

def f():
    for x in range(N, (M//2) + 1):
        d, m = divmod(M, x)
        if m == 0:
            return d
    return 1
print(f())

### FIXED CODE ###

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

import math
class PrimeUtils:
    @staticmethod
    def primes_sieve(n):
        sieve = [True] * (n + 1)
        for i in range(2, n + 1):
            if sieve[i]:
                for j in range(i + i, n + 1, i):
                    sieve[j] = False
        return [i for i, x in enumerate(sieve[2:], 2) if x]

def f():
    for p in PrimeUtils.primes_sieve(math.ceil(math.sqrt(M))):
        if M % p == 0:
            for x in range(N, (M//2) + 1):
                if M % x == 0:
                    return M // x
            else:
                return 1
    return 1
print(f())
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
s = 1
for i in range(N):
    s *= A[i]
    i += 1
if s > 10**18:
    print(-1)
else:
    print(s)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
s = 1
for i in range(N):
    if A[i] == 0:
        s = 0
        i += 1
if s == 0:
    print(0)
else:
    for i in range(N):
        s = s * A[i]
        if s > 10**18:
            break
        i += 1
    if s > 10**18:
        print(-1)
    else:
        print(s)
### BUGGY CODE ###

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

for i in range(n):
    x[i]=x[i]-a
    
# itertools 使用 bit全探索
import itertools
icnt=0
for i in itertools.product([0,1], repeat=n):
    isum=0
    for ii in range(n):
        if i[ii]==0:
            isum=isum+x[ii]
    if isum==0:
        icnt=icnt+1

print(icnt-1)

### FIXED CODE ###

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

for i in range(n):
    x[i]=x[i]-a
    
nx=n*n
dp=[[0]*(2*nx+1) for i in range(n+1)]

#print(dp)

dp[0][nx]=1

for j in range(1,n+1):
    jj=j-1
    for t in range(2*nx+1):
        if t-x[jj]<0 or 2*nx<t-x[jj]:
            dp[j][t]=dp[j-1][t]
        elif 0<t-x[jj] and  t-x[jj]<2*nx:
            dp[j][t]=dp[j-1][t]+dp[j-1][t-x[jj]]
        else:
            dp[j][t]=0

print(dp[n][nx]-1)
### BUGGY CODE ###

import collections

def main():
    N=int(input())
    A=list(map(int,input().split()))
    sum=0
    for i in range(N):
        x=A[i]
        A[i]=0
        c=collections.Counter(A)
        for j in c.values():
            sum+=j*(j-1)/2
        print(int(sum))
        sum=0
        A[i]=x


if __name__ == '__main__':
    main()



### FIXED CODE ###

import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


N=int(input())
A=list(map(int,input().split()))

c=collections.Counter(A)
list=c.values()
result=0

for x in list:
    if x>1:
        result+=cmb(x,2)
for y in c.keys():
    c[y]=result-(c[y]-1)

for z in A:
    print(c[z])
### BUGGY CODE ###

A,B,K = map(int,input().split())
for i in range(A,B+1): #AからB
    if i < A+K:
        print(i)
    elif B-K < i <= B:
        print(i)


### FIXED CODE ###

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

if B-A+1 <= K * 2:
    for i in range(A,B+1):
            print(i)

else:
    for i in range(A,A+K): #AからB
        print(i)

    for i in range(B-K+1,B+1):
        print(i)
### BUGGY CODE ###

H = int(input())

cnt = H
B = [H]
for i in range(1000000000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break

C =[1]
for i in range(1,1000):
    C.append(C[i-1]*2)

ans= 0
for i in range(len(B)):
    ans +=C[i]
print(ans)

### FIXED CODE ###

H = int(input())
cnt = H
ans = 0
B = [H]

if H == 1:
    ans == 'NA'
else:
    for i in range(100000000000):
        cnt = cnt//2
        B.append(cnt)
        if cnt == 1:
            break

C =[1]
for i in range(1,1001):
    C.append(C[i-1]*2)

if ans == 'NA':
    print('0')
else:
    for i in range(len(B)):
        ans +=C[i]
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
prise = []
conte = []
for i in range(n):
    a,b = map(int,input().split())
    prise.append(a)
    conte.append(b)
    
ki = 0
cost = 0
while ki <= m:
    ind = prise.index(min(prise))
    for p in range(conte[ind]):
        cost += min(prise)
        ki += 1
        if ki >= m:
            break
    prise.pop(ind)
    conte.pop(ind)
    if prise == []:
        break
    if ki == m:
        break
print(cost)

### FIXED CODE ###

n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)
### BUGGY CODE ###

h,w=map(int,input().split())
a=[input() for i in range(h)]
t=[[10000]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            t[i][j]=0
flg=True
step=1
ans=0
while flg:
    flg=False
    for i in range(h):
        for j in range(w):
            if t[i][j]==step-1:
                if i-1>=0:
                    if t[i-1][j]>step:
                        t[i-1][j]=step
                        flg=True
                if i+1<h:
                    if t[i+1][j]>step:
                        t[i+1][j]=step
                        flg=True
                if j-1>=0:
                    if t[i][j-1]>step:
                        t[i][j-1]=step
                        flg=True
                if j+1<w:
                    if t[i][j+1]>step:
                        t[i][j+1]=step
                        flg=True
    if flg:
        ans=step
        step+=1
print(ans)

### FIXED CODE ###

from collections import deque
h,w=map(int,input().split())
a=[input() for _ in range(h)]
inf=10**10
dist=[[inf if c=='.' else 0 for c in r] for r in a]
dq=deque()
for i in range(h):
    for j in range(w):
        if dist[i][j]==0:
            dq.append([i,j])
diff=[[1,0],[0,1],[-1,0],[0,-1]]
ans=0
while(dq):
    y,x=dq.popleft()
    for dy,dx in diff:
        y2=y+dy
        x2=x+dx
        if 0<=y2<h and 0<=x2<w and dist[y2][x2]>dist[y][x]+1:
            dq.append([y2,x2])
            dist[y2][x2]=dist[y][x]+1
            ans=max(ans,dist[y2][x2])
print(ans)
### BUGGY CODE ###

k,s=map(int,input().split(" "))
count=0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if i + j + k == s:
                count += 1
                
print(count)

### FIXED CODE ###

k,s=map(int,input().split(" "))
count=0
for i in range(k+1):
    for j in range(k+1):
        if 0 <= s-i-j <= k:
            count += 1
                
print(count)
### BUGGY CODE ###

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

def multi_lst(lst):
    ans = lst[0]
    for i in range(1, len(lst)):
        ans *= lst[i]
    
    return ans

ans = multi_lst(a)
if ans <= 10**18:
    print(ans)
else:
    print('-1')

### FIXED CODE ###

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

try:
    idx = a.index(0)
    print(0)

except ValueError:

    ans = a[0]
    for i in range(1, len(a)):
        ans *= a[i]
        if ans > 10**18:
            print('-1')
            exit()

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

import bisect
import heapq
N,Q = list(map(int,input().split(" ")))

hitos = []
ans = [-1] * Q
queries =[]
jump = [-1] * Q


for i in range(N):
    S,T,X =list(map(int,input().split(" ")))
    lt = S -X -0.5
    rt = T -X -0.5
    queries.append((lt,rt,X)) #-1 → 挿入クエリ lが時間、-1がクエリの種類、Xが場所


queries.sort(key=lambda x:x[2])



for i in range(Q):
    t = int(input())
    hitos.append(t)
for l,r,x in queries:
     lind  = bisect.bisect_left(hitos,l)
     rind  = bisect.bisect_left(hitos,r)
     while lind < rind:
         if ans[lind] == -1:
            ans[lind] = x
            jump[lind] = rind
            lind += 1
         else:
             temp = jump[lind]
             jump[lind] = rind
             lind = temp
ans = list(map(str,ans))
print("\n".join( ans))

### FIXED CODE ###

import bisect
import heapq
import sys
N,Q = [int(x) for x in sys.stdin.readline().split()]

hitos = []
ans = [-1] * Q
queries =[]
jump = [-1] * Q



queries = [[int(x) for x in sys.stdin.readline().split()] for i in range(N)]
hitos = [int(sys.stdin.readline()) for i in range(Q)]


# for i in range(N):
    # S,T,X =list(map(int,input().split(" ")))
    # lt = S -X -0.5
    # rt = T -X -0.5
    # queries.append([lt,rt,X]) #-1 → 挿入クエリ lが時間、-1がクエリの種類、Xが場所


queries.sort(key=lambda x:x[2])





for l,r,x in queries:
     lind  = bisect.bisect_left(hitos,l-x - 0.5)
     rind  = bisect.bisect_left(hitos,r -x - 0.5)
     while lind < rind:
         if ans[lind] == -1:
            ans[lind] = x
            jump[lind] = rind
            lind += 1
         else:
             temp = jump[lind]
             jump[lind] = rind
             lind = temp

for i  in ans:
    print(i)
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
P = LIST()

flag = [N+1]*N
total = 0

for i in range(1, N+1):
	num = P.index(i)
	if min(flag[0:num+1]) > P[num]:
		total += 1
	flag[num] = P[num]

print(total)

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
P = LIST()

total = 0
com = N + 1
for i in range(N):
	com = min(com, P[i])
	if P[i] == com:
		total += 1
print(total)
### BUGGY CODE ###

from collections import deque


H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10 ** 12
path = [[INF] * W for _ in range(H)]  # path: 各マスへの移動コスト

# walk:移動A, warp:移動B
walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

while q:
    x, y, s = q.popleft()
    for dx, dy in walk:  # 移動A
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
            path[nx][ny] = s
            q.appendleft((nx, ny, s))  # 移動Aの場合はコスト0. キューの先頭に追加する.
    for dx, dy in warp:  # 移動B
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
            path[nx][ny] = s + 1
            q.append((nx, ny, s + 1))  # 移動Bの場合はコスト1. キューの最後尾に追加する.
    
ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10 ** 12
path = [[INF] * W for _ in range(H)]  # path: 各マスへの移動コスト

walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

while q:
    x, y, s = q.popleft()
    for dx, dy in walk:  # 移動A
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
            path[nx][ny] = s
            q.appendleft((nx, ny, s))  # 移動Aの場合はコスト0. キューの先頭に追加する.
    for dx, dy in warp:  # 移動B
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
            path[nx][ny] = s + 1
            q.append((nx, ny, s + 1))  # 移動Bの場合はコスト1. キューの最後尾に追加する.
    
ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)
### BUGGY CODE ###

from time import sleep
n, a, b = map(int, input().split())
sleep(3.0)
print(min(a * n, b))

### FIXED CODE ###

# coding: utf-8
# Your code here!


N,A,B = map(int,input().split()) 
print(B if A*N > B else A*N)
### BUGGY CODE ###

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

dic = {}

max_dice = 0
for i in range(K-1, N):
    tmp_dice = 0
    for j in range(i - K + 1, i + 1):
        if p[j] in dic:
            tmp_kitai = dic[p[j]]
        else:
            tmp_kitai = (p[j] + 1) / 2
            dic[p[j]] = tmp_kitai
        tmp_dice += tmp_kitai
    if tmp_dice > max_dice:
        max_dice = tmp_dice
print(max_dice)

### FIXED CODE ###

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

dp = [0] * (N)
dp_sub = [0] * (N)

dp[0] = (p[0] + 1) / 2
dp_sub[0] = (p[0] + 1) / 2

for i in range(1, K):
    dp_sub[i] = (p[i] + 1) / 2
    dp[i] = dp[i - 1] + dp_sub[i]

for i in range(K, N):
    dp_sub[i] = (p[i] + 1) / 2
    dp[i] = dp[i - 1] + dp_sub[i] - dp_sub[i-K]
    
print(max(dp))
### BUGGY CODE ###

s=input()
l=len(s)

dp=[[0,0,0] for i in range(l)]
mod=10**9+7
c=0

for i in range(l):
    if s[i]=="A":
        dp[i][0]=dp[i-1][0]+3**c
        dp[i][1]=dp[i-1][1]
        dp[i][2]=dp[i-1][2]
    elif s[i]=="B":
        dp[i][0]=dp[i-1][0]
        dp[i][1]=dp[i-1][1]+dp[i-1][0]
        dp[i][2]=dp[i-1][2]
    elif s[i]=="C":
        dp[i][0]=dp[i-1][0]
        dp[i][1]=dp[i-1][1]
        dp[i][2]=dp[i-1][2]+dp[i-1][1]
    else:
        dp[i][0]=dp[i-1][0]*3+3**c
        dp[i][1]=dp[i-1][1]*3+dp[i-1][0]
        dp[i][2]=dp[i-1][2]*3+dp[i-1][1]
        c+=1
    dp[i][0]=dp[i][0]%mod
    dp[i][1]=dp[i][1]%mod
    dp[i][2]=dp[i][2]%mod

print(dp[-1][2])

### FIXED CODE ###

s=input()
l=len(s)
dp=[[0]*4 for i in range(l+1)]
dp[0][0]=1
mod=10**9+7
for i in range(l):
    c = s[i]
    dp[i+1][0]=dp[i][0] 
    dp[i+1][1]=dp[i][1] 
    dp[i+1][2]=dp[i][2] 
    dp[i+1][3]=dp[i][3] 
    if c=="A":
        dp[i+1][1]+=dp[i][0]
    if c=="B":
        dp[i+1][2]=dp[i][2]+dp[i][1] 
    if c=="C":
        dp[i+1][3]=dp[i][3]+dp[i][2]
    if c=="?":
        dp[i+1][0] = (3*dp[i][0])%mod
        dp[i+1][1] = (dp[i][0] + 3*dp[i][1]) % mod
        dp[i+1][2] = (dp[i][1] + 3*dp[i][2]) % mod
        dp[i+1][3] = (dp[i][2] + 3*dp[i][3]) % mod
        

print(dp[-1][3]%mod)
### BUGGY CODE ###

def main():

    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse = True)
    F.sort()

    if K >= sum(A): return 0

    B = [[A[i] * F[i], A[i], F[i]] for i in range(N)]
    l, r = 0, max(A) * max(F)
    # ans = float('inf')
    while l < r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i][0] - m > 0:
                if (B[i][0] - m) % B[i][2] == 0:
                    count += (B[i][0] - m) // B[i][2]
                else:
                    count += (B[i][0] - m) // B[i][2] + 1
        if count <= K:
            if r == m: break
            r = m
        else:
            # ans = min(ans, m)
            if l == m: break
            l = m
        # print(l, r)
    return r



if __name__ == '__main__':
    print(main())

### FIXED CODE ###

def main():
 
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse = True)
    F.sort()
 
    if K >= sum(A): return 0
 
    B = [A[i] * F[i] for i in range(N)]
    l, r = 0, max(B)
    ans = float('inf')
    while l <= r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i] - m > 0:
                count += (B[i] - m) // F[i]
                if (B[i] - m) % F[i] != 0:
                    count += 1
        if count <= K:
            ans = min(ans, m)
            if r == m-1: break
            r = m-1
        else:
            if l == m+1: break
            l = m+1
        # print(l, r)
    return ans
 
if __name__ == '__main__':
    print(main())
### BUGGY CODE ###

import fractions
N=int(input())
A=list(map(int,input().split()))
c=1
a=0
w=10**9+7
for A_ in A:
    c=c*A_//fractions.gcd(c,A_)
for A_ in A:
    a+=c//A_
print(int(a%w))


### FIXED CODE ###

import sys
input = sys.stdin.readline
import fractions
N=int(input())
A=list(map(int,input().split()))
c=1
a=0
w=10**9+7
for A_ in A:
    c=c*A_//fractions.gcd(c,A_)
for A_ in A:
    a+=c//A_
print(int(a%w))
### BUGGY CODE ###

import numpy as np

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

lsorted = np.sort(np.array(l))[::-1]

for longest in range(len(l)-2):

    for second in range(longest+1, len(l)):
        if lsorted[longest] - 2*lsorted[second] >= 0:
            break 
        ans += np.count_nonzero(lsorted[second+1:] > (lsorted[longest] - lsorted[second]) )
print(ans)

### FIXED CODE ###

from bisect import bisect_left

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

for i in range(n-2):
    shortest = l[i]
    for j in range(i+1, n-1):
        second = l[j]
        # このスライスしたやつと地味にTLEになる...
        # k = bisect_left(l[j], shortest + second)
        # ans += k

        k = bisect_left(l, shortest + second)
        ans += k - j - 1

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

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)

lst = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1) * (j+1) * (k+1) <= K:
                lst += [A[i]+B[j]+C[k]]
lst.sort(reverse = True)
for l in range(K):
    print (lst[l])
    
    


### FIXED CODE ###

#単純な全探索-->TLE-->Cの配列を扱うときに工夫
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

lst = []
for i in A:
    for j in B:
        lst += [i + j]

lst.sort(reverse = True)
C.sort(reverse = True)

ans = []
for i in range(min(K, len(lst))):
    for j in range(min(K, len(C))):
        ans += [lst[i]+C[j]]

ans.sort(reverse = True)
for i in range(K):
    print (ans[i])
### BUGGY CODE ###

import math
n = int(input())
ans = int(math.sqrt(n))
while True:
  if n % ans == 0:
    break
  else:
    ans += 1
print(len(str(ans)))

### FIXED CODE ###

import math
n = int(input())
ans = int(math.sqrt(n))
while True:
  if n % ans == 0:
    ans = n // ans
    break
  else:
    ans -= 1
print(len(str(ans)))
### BUGGY CODE ###

from collections import defaultdict
N = int(input())
p = 10 ** 9 + 7
C = [0] * (N + 1)
D = defaultdict(list)
DP = [[0, 0] for i in range(N + 1)]
DP[0] = [1, 0]
LC = 0
LP = -1
for i in range(1, N + 1):
  C[i] = int(input())
  DP[i][0] = sum(DP[i - 1]) % p
  if C[i] != C[i - 1]:
    for d in D[C[i]]:
      DP[i][1] += DP[d][0]
    D[C[i]] += [i]
print(sum(DP[N]) % p)
    

### FIXED CODE ###

from collections import defaultdict
N = int(input())
p = 10 ** 9 + 7
C = [0] * (N + 1)
D = defaultdict(lambda: -1)
DP = [[0, 0] for i in range(N + 1)]
DP[0] = [1, 0]
for i in range(1, N + 1):
  C[i] = int(input())
  DP[i][0] = sum(DP[i - 1]) % p
  if C[i] != C[i - 1]:
    DP[i][1] = sum(DP[D[C[i]]]) if D[C[i]] != -1 else 0
    D[C[i]] = i
print(sum(DP[N]) % p)
### BUGGY CODE ###

N,M,Q = map(int,input().split())
ls_rq = [list(map(int, input().split())) for i in range(Q)]

#深さ優先探索により各数列を生成する
As=[]
from queue import LifoQueue as lq
S=lq()
S.put([])
while not S.empty():
  a=S.get()
  if len(a)==N:
    As.append(a)
  else:
    if len(a)==0:
      b=1
    else:
      b=a[-1]
    for  i in range(b,M+1):
      S.put(a+[i])

#各数列のスコアを求める
ls_score=[]
for ls in As:
  score=0
  for j in range(Q):
    if ls[ls_rq[j][1]-1]-ls[ls_rq[j][0]-1]==ls_rq[j][2]:
      score+=ls_rq[j][3]
  ls_score.append(score)    
  score=0

#スコアの最大値を求める  
ans=max(ls_score+[0])  
print(ans)  


### FIXED CODE ###

N,M,Q = map(int,input().split())
ls_rq = [list(map(int, input().split())) for i in range(Q)]

#深さ優先探索により各数列を生成する
As=[]
from queue import LifoQueue as lq
S=lq()
S.put([])
while not S.empty():
  a=S.get()
  if len(a)==N:
    As.append(a)
  else:
    if len(a)==0:
      b=1
    else:
      b=a[-1]
    for  i in range(b,M+1):
      S.put(a+[i])

#各数列のスコアを求める
ls_score=[]
for ls in As:
  score=0
  for j in range(Q):
    if ls[ls_rq[j][1]-1]-ls[ls_rq[j][0]-1]==ls_rq[j][2]:
      score+=ls_rq[j][3]
  ls_score.append(score)    
  score=0

#スコアの最大値を求める  
ans=max(ls_score+[0])  
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(200000)
H,W=map(int,input().split())
S=[]
for i in range(H):
    S.append(input())

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

was=[[0 for i in range(W)] for j in range(H)]

def dfs(x,y):
    global cc
    global was
    was[x][y]=1
    if S[x][y]=="#":
        cc[1]+=1
    else:
        cc[0]+=1
    for i in range(4):
        nx=x+dx[i]
        ny=y+dy[i]
        if nx>=0 and ny>=0 and nx<H and ny<W and S[nx][ny]!=S[x][y] and not was[nx][ny]:
            dfs(nx,ny)

for i in range(H):
    for j in range(W):
        if not was[i][j]:
            cc=[0]*2
            dfs(i,j)
            ans+= cc[1]*cc[0]

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
H,W=map(int,input().split())
S=[]
for i in range(H):
    S.append(input())

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

was=[[0 for i in range(W)] for j in range(H)]

def dfs(x,y):
    global cc
    global was
    was[x][y]=1
    if S[x][y]=="#":
        cc[1]+=1
    else:
        cc[0]+=1
    for i in range(4):
        nx=x+dx[i]
        ny=y+dy[i]
        if nx>=0 and ny>=0 and nx<H and ny<W and S[nx][ny]!=S[x][y] and not was[nx][ny]:
            dfs(nx,ny)

for i in range(H):
    for j in range(W):
        if not was[i][j]:
            cc=[0]*2
            dfs(i,j)
            ans+= cc[1]*cc[0]

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

K, S = map(int, input().split())
cnt=0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x+y+z==S:
                cnt+=1

print(cnt)


### FIXED CODE ###

K, S = map(int, input().split())
cnt=0
for x in range(K+1):
    for y in range(K+1):
        if x+y<=S:
            if K>=S-x-y:
                cnt+=1

print(cnt)