CodeEff/ECCO huggingface dataset:
# Original solution
n, k = list(map(int, input().split()))

MOD = 10 ** 9 + 7

ans = 0
num = 0

for i in range(1, n + 2):
  num += (i - 1)
  if i >= k:
    # print(num, i, i * n - 2 * num + 1)
    ans += max(i * n - 2 * num + 1, 1) 
    ans = ans % MOD

print(ans)

# Optimized solution
n, k = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 0
a = 1

for i in range(1, n + 2):
  a -= 2 * (i - 1)
  if i >= k:
    ans += (i * n + a)
    ans %= MOD
print(ans)
# Original solution
n, k = list(map(int, input().split()))

ans = 0

for i in range(k, n+2):
    ans += ((i * (2 * n - i + 1) / 2) - (i * (i - 1) / 2) + 1) % (10 ** 9 + 7)


print((int(ans % (10 ** 9 + 7))))


# Optimized solution
n, k = list(map(int, input().split()))

ans = 0

for i in range(k, n+2):
    ans += (i * (2 * n - i + 1) / 2) - (i * (i - 1) / 2) + 1


print((int(ans % (10 ** 9 + 7))))
# Original solution
def main():
    N, K = list(map(int, input().split()))
    mod = 10**9 + 7
    ans = 0
    for i in range(K, N + 2):
        a = N - i + 1
        ans = (ans + i * a + 1) % mod
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N, K = list(map(int, input().split()))
    mod = 10**9 + 7
    ans1 = (N + 2 - K) % mod
    ans2 = ((N + 1) * (N + 1) * (N + 2) // 2 - (N + 1) * K  * (K - 1) // 2) % mod
    ans3 = ((N + 1) * (N + 2) * (2 * N + 3) // 6 - (K - 1) * K * (2 * K - 1) // 6) % mod
    ans = (ans1 + ans2 - ans3) % mod
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(eval(input()))


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return list(map(int, input().split()))


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


MOD = 10 ** 9 + 7


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, list(range(n, n - r, -1)))
    under = reduce(mul, list(range(1, r + 1)))
    return over // under


def main():
    n, k = input_to_int_map()

    all_n = n + 1
    ret = 0
    all_list_sum = [0]
    pre = 0
    for i in range(0, all_n):
        all_list_sum.append(i + pre)
        pre = i + pre

    for choice_cnt in range(k, all_n + 1):
        ret = (ret + (all_list_sum[n + 1] - all_list_sum[n + 1 - choice_cnt] - all_list_sum[choice_cnt] + 1)) % MOD

    return ret


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


# Optimized solution
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(eval(input()))


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return list(map(int, input().split()))


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


MOD = 10 ** 9 + 7


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, list(range(n, n - r, -1)))
    under = reduce(mul, list(range(1, r + 1)))
    return over // under


def main():
    n, k = input_to_int_map()

    all_n = n + 1
    ret = 0
    all_list_sum = [0]
    pre = 0
    for i in range(0, all_n):
        all_list_sum.append(i + pre)
        pre = i + pre

    for choice_cnt in range(k, all_n + 1):
        ret = (ret + (all_list_sum[n + 1] - all_list_sum[n + 1 - choice_cnt] - all_list_sum[choice_cnt] + 1))

    return ret % MOD


if __name__ == "__main__":
    print((main()))
# Original solution
n, k = list(map(int, input().split()))

ans = 0
for num in range(k, n + 2):
    maximum = (2 * n - num + 1) * num // 2
    minimum = (num - 1) * num // 2
    ans += maximum - minimum + 1
    
ans = ans % (10**9 + 7)

print(ans)

# Optimized solution
n, k = list(map(int, input().split()))

m = n + 1
l = k - 1

ans = m * (m**2 + 5) // 6
ans += l * (2 * l**2 + 3 * l - 5 - 3 * m * (l + 1)) // 6
ans = ans % (10**9 + 7)

print(ans)
# Original solution
N, K = list(map(int,input().split()))

def sum_(i, j):
    return (a[i] + a[j]) * (j - i + 1) // 2

a = [i for i in range(N + 1)]
ans = 0
for i in range(K, N + 2):
    min_ = sum_(0, i - 1)
    max_ = sum_(N - i + 1, N)
    ans += (max_ - min_ + 1)
    ans %= 10 ** 9 + 7
print(ans)

# Optimized solution
N, K = list(map(int,input().split()))
ans = 0
INF = 10 ** 9 + 7
for i in range(K, N + 2):
    mi = i * (i - 1) // 2
    ma = i * (2 * N - i + 1) // 2
    ans += ma - mi + 1
    ans %= INF
print(ans)
# Original solution
def n0():return int(eval(input()))
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(eval(input())) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()

down=[0]*(n+1)
up=[0]*(n+1)
up[0]=n
ans=0 if k>1 else n+1
for i in range(1,n+1):
    down[i]=down[i-1]+i
    up[i]=up[i-1]+(n-i)
    if i>=k-1:
        ans+=up[i]-down[i]+1
print((ans%(10**9+7)))

# Optimized solution

def s0():return eval(input())
def s1():return input().split()
def s2(n):return [eval(input()) for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(eval(input()))
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(eval(input())) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()
 
down=[0]*(n+1)
up=[0]*(n+1)
up[0]=n
ans=0 if k>1 else n+1
for i in range(1,n+1):
    down[i]=down[i-1]+i
    up[i]=up[i-1]+(n-i)
    if i>=k-1:
        ans+=up[i]-down[i]+1
print((ans%(10**9+7)))
# Original solution
N,K=list(map(int,input().split()))
ans=0
for i in range(K,N+2):
    kos=((2*N-i+1)*i)//2-((i-1)*i)//2+1
    ans=(ans+kos)%(10**9+7)
print(ans)

# Optimized solution
N,K=list(map(int,input().split()))
ans=0
for i in range(K,N+2):
    kos=i*(N-i+1)+1
    ans=(ans+kos)%(10**9+7)
print(ans)
# Original solution
N,K=list(map(int,input().split()))
ans=0
for i in range(K,N+2):
    kos=i*(N-i+1)+1
    ans=(ans+kos)%(10**9+7)
print(ans)

# Optimized solution
N,k=list(map(int,input().split()))
print((((2+N-k)*(6+N+N**2+2*k+k*N-k**2*2)//6)%(10**9+7)))
# Original solution
import sys

input = sys.stdin.readline

P = 10 ** 9 + 7


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

    ans = 0
    for k in reversed(list(range(1, (N+1)+1))):
        a = (N + (N-k+1))*k//2
        b = k*(k-1)//2
        ans += a - b + 1
        ans %= P

        if k == K :
            break

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


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

    ans = 0
    for k in range(K, N + 2):
        a = k * (k - 1) // 2
        b = k * (2 * N - (k - 1)) // 2
        ans = (ans + (b - a + 1)) % P

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
n,k=list(map(int,input().split()))
ans=0
for i in range(k,n+2):
    ans+=n*i-(i-1)*i//2-(i-1)*i//2+1
    ans%=10**9+7
print(ans)

# Optimized solution
n,k=list(map(int,input().split()));print((sum(i*(n-i+1)+1for i in range(k,n+2))%(10**9+7)))
# Original solution
def d_sum_of_large_numbers(MOD=10**9 + 7):
    N, K = [int(i) for i in input().split()]

    ans = 0
    for k in range(K, N + 2):
        tmp = 1 - k * (k - 1)
        ans += k * N + tmp
        ans %= MOD
    return ans

print((d_sum_of_large_numbers()))

# Optimized solution
def d_sum_of_large_numbers(MOD=10**9 + 7):
    N, K = [int(i) for i in input().split()]
    return (N + 2 - K) * (N**2 + (K + 1) * N - 2 * K**2 + 2 * K + 6) // 6 % MOD

print((d_sum_of_large_numbers()))
# Original solution
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N, K = list(map(int, readline().rstrip().split()))
    ans = 0
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = (N * (N + 1)) // 2 - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1) % MOD

    print((ans % MOD))


if __name__ == '__main__':
    main()

# Optimized solution
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N, K = list(map(int, readline().rstrip().split()))
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1) % MOD

    print((ans % MOD))


if __name__ == '__main__':
    main()
# Original solution
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N, K = list(map(int, readline().rstrip().split()))
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1) % MOD

    print((ans % MOD))


if __name__ == '__main__':
    main()

# Optimized solution
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N, K = list(map(int, readline().rstrip().split()))
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1)

    print((ans % MOD))


if __name__ == '__main__':
    main()
# Original solution
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N, K = list(map(int, readline().rstrip().split()))
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1)

    print((ans % MOD))


if __name__ == '__main__':
    main()

# Optimized solution
import sys
readline = sys.stdin.buffer.readline
MOD = 10 ** 9 + 7

def main():
    N, K = list(map(int, readline().rstrip().split()))
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1)

    print((ans % MOD))


if __name__ == '__main__':
    main()
# Original solution
N, K = list(map(int, input().split()))
mod = int(1e9) + 7
S = 0
for i in range(K, N+2):
    S += (N - i + 1) * i + 1
    S %= mod
print(S)

# Optimized solution
N, K = list(map(int, input().split()))
mod = int(1e9) + 7
S = (N * (N + 1) * (N + 2) - (3 * N - 2 * K + 4) * K * (K - 1)) // 6 + N - K + 2
print((S % mod))
# Original solution
n, k = list(map(int, input().split()))
ans = 0

for i in range(k - 1, n + 1):
    ans += ((i + 1)*(n + n - i)//2)
for i in range(k - 1, n + 1):
    ans -= (i + 1)*i//2
ans += n + 2 - k
print((ans%(10**9 + 7)))

# Optimized solution
n, k = list(map(int, input().split()))
ans = 0

for i in range(k - 1, n + 1):
    ans += (i + 1)*(n - i) + 1

print((ans%(10**9 + 7)))
# Original solution
import itertools
import math
from functools import reduce

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

pattern = 0

for i in range(k, n + 2):
    min = i * (0 + i - 1) // 2
    max = i * (n + n - i + 1) // 2
    pattern += max - min + 1
    
pattern %= 10 ** 9 + 7
    
print(pattern)

# Optimized solution
n, k = list(map(int, input().split()))

pattern = 0

for i in range(k, n + 2):
    min = (0 + i - 1) // 2 * i
    max = ((n - i) + (1 + n)) // 2 * i
    pattern += max - min + 1
    
pattern %= 10 ** 9 + 7

print(pattern)
# Original solution
from functools import reduce
while 1:
    n = input()
    if n == '0': break;
    print(reduce(lambda x,y: x+int(y), n, 0))

# Optimized solution
while 1:
    x = input()
    if x == '0': break;
    print(sum([int(d) for d in x]))
# Original solution
import sys

for line in sys.stdin:
    if int(line) == 0: break
    s = 0
    for c in line.strip('\n'):
        s += '0123456789'.index(c)
    print(s)

# Optimized solution
while True:
    x = input()
    if x == '0':break
    print(sum(['0123456789'.index(c) for c in x]))
# Original solution
xin = []
while True:
    x = int(input())
    if x == 0:
        break
    xin += [x]
for i in xin:
    print(sum(map(int , list(str(i)))))

# Optimized solution
xin = []
while True:
    x = input()
    if x == '0':
        break
    xin += [x]
for i in xin:
    print(sum(map(int , list(i))))
# Original solution
# -*- coding: utf-8 -*-
while True:
 s = input()
 if s=="0": break
 t = 0
 for n in s:
  t += int(n)
 print(t)

# Optimized solution
while True:
 s = input()
 if s!="0": print(sum(map(int, s)))
 else: break
# Original solution
def con(m,n):
  ln = len(str(n))
  return m * 10 ** ln + n
n = int(eval(input()))
lst = [int(eval(input())) for i in range(n)]
lst.sort()
lst = lst[0:4]
save = []
for i in lst:
  for j in lst:
    if i != j:
      save.append(con(i, j))
save.sort()
print((save[2]))



# Optimized solution
def main():
  def con(m,n):
    ln = len(str(n))
    return m * 10 ** ln + n
  n = int(eval(input()))
  lst = [int(eval(input())) for i in range(n)]
  lst.sort()
  lst = lst[0:4]
  save = []
  for i in lst:
    for j in lst:
      if i != j:
        save.append(con(i, j))
  save.sort()
  print((save[2]))
  
main()
# Original solution
n=int(input())
a=[int(input()) for _ in range(n)]
a.sort()
ans=[]
for i in range(3):
    for j in range(i+1,n):
        ans.append(int(str(a[i])+str(a[j])))
        ans.append(int(str(a[j])+str(a[i])))
    ans.sort()
print((ans[2]))

# Optimized solution
n=int(input())
a=[int(input()) for _ in range(n)]
a.sort()
ans=[]
for i in range(3):
    for j in range(i+1,n):
        ans.append(int(str(a[i])+str(a[j])))
        ans.append(int(str(a[j])+str(a[i])))
ans.sort()
print((ans[2]))
# Original solution
import sys
sys.setrecursionlimit(10 ** 9)

n,m,q = list(map(int,input().split()))
abcd = []
for i in range(q):
  abcd.append(tuple(map(int,input().split())))

ans = 0
def dfs(l):
  global ans
  if len(l) == n:
    ans = max(check(l),ans)
  else:
    if len(l) == 0:
      mx = 1
    else:
      mx = l[-1]
    for i in range(mx,m+1):
      tmpl = l + [i]
      dfs(tmpl)

def check(l):
  res = 0
  for a,b,c,d in abcd:
    a -= 1
    b -= 1
    if l[b]-l[a] == c:
      res += d
  return res

dfs([])
print(ans)


# Optimized solution
import itertools

n,m,q = list(map(int,input().split()))
abcd = []
for i in range(q):
  abcd.append(tuple(map(int,input().split())))

def check(l):
  res = 0
  for a,b,c,d in abcd:
    a -= 1
    b -= 1
    if l[b]-l[a] == c:
      res += d
  return res

l = itertools.combinations_with_replacement(list(range(1,m+1)),n)
ans = 0
for li in l:
  ans = max(check(li),ans)
print(ans)
# Original solution
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, M, Q = list(map(int, readline().split()))

kumi = []
for _ in range(Q):
    tmp = list(map(int, readline().split()))
    kumi.append(tmp)

ans = 0
res = []
def F(l):
    if len(l) == N:
        ans = 0
        for i in range(Q):
            a, b, c, d = kumi[i]
            if l[b-1] - l[a-1] == c:
                ans += d
        yield ans
        return
    start = l[-1] if len(l) else 0
    for i in range(start, M):
        l.append(i)
        yield from F(l)
        l.pop()
    
ans = max(F([]))
print(ans)

# Optimized solution
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, M, Q = list(map(int, readline().split()))

kumi = []
for _ in range(Q):
    tmp = list(map(int, readline().split()))
    kumi.append(tmp)

ans = 0
res = []
def F(l):
    if len(l) == N:
        ans = 0
        for i in range(Q):
            a, b, c, d = kumi[i]
            if l[b-1] - l[a-1] == c:
                ans += d
        return ans
    ans = 0
    start = l[-1] if len(l) else 0
    for i in range(start, M):
        l.append(i)
        ans = max(ans, F(l))
        l.pop()
    return ans
    
ans = F([])
print(ans)
# Original solution
N, M, Q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for i in range(Q)]
# print(N, M, Q)
# print(abcd)

def calculate(A):
    total = 0
    for abcdi in abcd:
        a = abcdi[0] - 1
        b = abcdi[1] - 1
        c = abcdi[2]
        d = abcdi[3]
        if A[b] - A[a] == c:
            total += d
    # print(A, total)

    return total

maximum = 0
for i in range(1, M + 1):
    if N == 1:
        maximum = max(calculate([i]), maximum)
    for j in range(i, M + 1):
        if N == 2:
            maximum = max(calculate([i, j]), maximum)
        for k in range(j, M + 1):
            if N == 3:
                maximum = max(calculate([i, j, k]), maximum)
            for l in range(k, M + 1):
                if N == 4:
                    maximum = max(calculate([i, j, k, l]), maximum)
                for m in range(l, M + 1):
                    if N == 5:
                        maximum = max(calculate([i, j, k, l, m]), maximum)
                    for n in range(m, M + 1):
                        if N == 6:
                            maximum = max(calculate([i, j, k, l, m, n]), maximum)
                        for o in range(n, M + 1):
                            if N == 7:
                                maximum = max(calculate([i, j, k, l, m, n, o]), maximum)
                            for p in range(o, M + 1):
                                if N == 8:
                                    maximum = max(calculate([i, j, k, l, m, n, o, p]), maximum)
                                for q in range(p, M + 1):
                                    if N == 9:
                                        maximum = max(calculate([i, j, k, l, m, n, o, p, q]), maximum)
                                    for r in range(q, M + 1):
                                        if N == 10:
                                            maximum = max(calculate([i, j, k, l, m, n, o, p, q, r]), maximum)

print(maximum)


# Optimized solution
N, M, Q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for i in range(Q)]
# print(N, M, Q)
# print(abcd)

def calculate(A, abcd):
    total = 0
    for abcdi in abcd:
        a = abcdi[0] - 1
        b = abcdi[1] - 1
        c = abcdi[2]
        d = abcdi[3]
        if A[b] - A[a] == c:
            total += d
    # print(A, total)

    return total

import itertools
A = list(itertools.combinations_with_replacement(list(range(1, M + 1)), N))
# print(A)

maximum = 0
for Ai in A:
    maximum = max(calculate(Ai, abcd), maximum)

print(maximum)
# Original solution
N, M, Q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for i in range(Q)]
# print(N, M, Q)
# print(abcd)

def calculate(A, abcd):
    total = 0
    for abcdi in abcd:
        a = abcdi[0] - 1
        b = abcdi[1] - 1
        c = abcdi[2]
        d = abcdi[3]
        if A[b] - A[a] == c:
            total += d
    # print(A, total)

    return total

import itertools
A = list(itertools.combinations_with_replacement(list(range(1, M + 1)), N))
# print(A)

maximum = 0
for Ai in A:
    maximum = max(calculate(Ai, abcd), maximum)

print(maximum)


# Optimized solution
import itertools

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

def calculate(A, abcd):
    total = 0
    for abcdi in abcd:
        a = abcdi[0] - 1
        b = abcdi[1] - 1
        c = abcdi[2]
        d = abcdi[3]
        if A[b] - A[a] == c:
            total += d
    # print(A, total)

    return total

A = list(itertools.combinations_with_replacement(list(range(1, M + 1)), N))
# print(A)

maximum = max([calculate(Ai, abcd) for Ai in A])

print(maximum)
# Original solution
n,m,q=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(q)]
L=[]
for i in range(1,m+1):
  if n==1:
    L.append((i))
  else:
    for i2 in range(i,m+1):
      if n==2:
        L.append((i,i2))
      else:
        for i3 in range(i2,m+1):
          if n==3:
            L.append((i,i2,i3))
          else:
            for i4 in range(i3,m+1):
              if n==4:
                L.append((i,i2,i3,i4))
              else:
                for i5 in range(i4,m+1):
                  if n==5:
                    L.append((i,i2,i3,i4,i5))
                  else:
                    for i6 in range(i5,m+1):
                      if n==6:
                        L.append((i,i2,i3,i4,i5,i6))
                      else:
                        for i7 in range(i6,m+1):
                          if n==7:
                            L.append((i,i2,i3,i4,i5,i6,i7))
                          else:
                            for i8 in range(i7,m+1):
                              if n==8:
                                L.append((i,i2,i3,i4,i5,i6,i7,i8))
                              else:
                                for i9 in range(i8,m+1):
                                  if n==9:
                                    L.append((i,i2,i3,i4,i5,i6,i7,i8,i9))
                                  else:
                                    for i10 in range(i9,m+1):
                                      L.append((i,i2,i3,i4,i5,i6,i7,i8,i9,i10))
ans=[]
for i in range(len(L)):
  ct=0
  for j in range(q):
    if L[i][l[j][1]-1]-L[i][l[j][0]-1]==l[j][2]:
      ct+=l[j][3]
  ans.append(ct)
print((max(ans)))

# Optimized solution
import itertools
n,m,q=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(q)]
M=[i+1 for i in range(m)]
L=[]
for i in itertools.combinations_with_replacement(M,n):
  L.append(i)
ans=[]
for i in range(len(L)):
  ct=0
  for j in range(q):
    if L[i][l[j][1]-1]-L[i][l[j][0]-1]==l[j][2]:
      ct+=l[j][3]
  ans.append(ct)
print((max(ans)))
# Original solution
import itertools
n,m,q = list(map(int,input().split()))
ch = list(itertools.combinations_with_replacement(list(range(1,m+1)),n))
lch = len(ch)
rel = [0]*lch
l = [list(map(int,input().split())) for _ in range(q)]
for k in range(lch):
    for i in range(q):
        a = l[i][0]
        b = l[i][1]
        c = l[i][2]
        d = l[i][3]
        if ch[k][b-1]-ch[k][a-1]==c:
            rel[k]+=d
print((max(rel)))

# Optimized solution
import itertools
n,m,q = list(map(int,input().split()))
ch = list(itertools.combinations_with_replacement(list(range(1,m+1)),n))
lch = len(ch)
rel = [0]*lch
l = [list(map(int,input().split())) for _ in range(q)]
for k in range(lch):
    for i in range(q):
        if ch[k][l[i][1]-1]-ch[k][l[i][0]-1]==l[i][2]:
            rel[k]+=l[i][3]
print((max(rel)))
# Original solution
from collections import deque
N, M, Q = list(map(int, input().split(" ")))
abcd = []
for i in range(Q):
    abcd.append(list(map(int, input().split(" "))))
q = deque([[i] for i in range(1, M + 1)])
A = []
while q:
    tmp = q.pop()
    if len(tmp) == N:
        A.append(tmp)
    else:
        for i in range(tmp[-1], M + 1):
            tmp_copy = tmp.copy()
            tmp_copy.append(i)
            q.append(tmp_copy)
ans = 0            
for a in A:
    score = 0
    for i in abcd:
        if a[i[1] - 1] == a[i[0] - 1] + i[2]:
            score += i[3]
    ans = max(ans, score)
print(ans)

# Optimized solution
import itertools
N, M, Q = list(map(int, input().split(" ")))
abcd = []
for i in range(Q):
    abcd.append(list(map(int, input().split(" "))))
A = list(itertools.combinations_with_replacement(list(range(1, M + 1)), N))
ans = 0            
for a in A:
    score = 0
    for i in abcd:
        if a[i[1] - 1] == a[i[0] - 1] + i[2]:
            score += i[3]
    ans = max(ans, score)
print(ans)