TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
vn,m,q=map(int,input().split())
lis=[]
for i in range(q):
    a,b,c,d=map(int,input().split())
    lis.append((a,b,c,d))
    
from itertools import combinations_with_replacement

co=list(combinations_with_replacement(range(1,m+1),n))

ans=0
for status in co:
    tmp_score=0
    for a,b,c,d in lis:
        if status[b-1]-status[a-1]==c:
            tmp_score+=d
    ans=max(ans,tmp_score)
print(ans)


import sys
sys.setrecursionlimit(1000000)

def dfs(a):
    if len(a)==n:
        tmp=a[:]
        a_lis.append(tmp)
        return
    
    for i in range(m):
        if len(a)>0 and i<a[-1]:
            continue
        a.append(i)
        dfs(a)
        a.pop()

cnt=0        
n,m,q=map(int,input().split())
lis=[[int(i) for i in input().split()]for i in range(q)]
a_lis=[]

dfs([])
ans=0
for i in a_lis:
    score=0
    for a,b,c,d in lis:
        if i[b-1]-i[a-1]==c:
            score+=d
    ans=max(ans,score)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations_with_replacement
#from fractions import gcd
from math import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def main():
    n, m, q = map(int, input().split())
    abcd = [None] * q
    for i in range(q):
        abcd[i] = tuple(map(int, input().split()))

    A = list(range(m))
    ans = 0
    comb = list(combinations_with_replacement(A, n))
    for c in comb:
        tmp_ans = 0
        for i in range(q):
            if c[abcd[i][1]-1] - c[abcd[i][0]-1] == abcd[i][2]:
                tmp_ans += abcd[i][3]
                print(tmp_ans)
        ans = max(ans, tmp_ans)
    print(ans)

if __name__ == '__main__':
    main()



#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations_with_replacement
#from fractions import gcd
from math import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def main():
    n, m, q = map(int, input().split())
    abcd = [None] * q
    for i in range(q):
        abcd[i] = tuple(map(int, input().split()))

    A = list(range(m))
    ans = 0
    comb = list(combinations_with_replacement(A, n))
    for c in comb:
        tmp_ans = 0
        for i in range(q):
            if c[abcd[i][1]-1] - c[abcd[i][0]-1] == abcd[i][2]:
                tmp_ans += abcd[i][3]
        ans = max(ans, tmp_ans)
    print(ans)

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N, M, Q = map(int, input().split())

A = []
B = []
C = []
D = []

for i in range(Q):
    a, b, c, d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)


def dfs(nums):

    if len(nums) == N + 1:
        score = 0
        for j in range(Q):
            if nums[B[j]] - nums[A[j]] == C[j]:
                score += D[j]
        return score

    max_score = 0
    for i in range(nums[-1], M+1):
        new_nums = nums + [i]
        max_score = max(max_score, dfs(new_nums))

    return max_score

nums[1]
res = dfs(nums)
print(res)

N, M, Q = map(int, input().split())
 
A = []
B = []
C = []
D = []
 
for i in range(Q):
    a, b, c, d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)
 
 
def dfs(nums):
 
    if len(nums) == N + 1:
        score = 0
        for j in range(Q):
            if nums[B[j]] - nums[A[j]] == C[j]:
                score += D[j]
        return score
 
    max_score = 0
    for i in range(nums[-1], M+1):
        new_nums = nums + [i]
        max_score = max(max_score, dfs(new_nums))
 
    return max_score
 
nums = [1]
res = dfs(nums)
print(res)

Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
n,m,q = map(int ,input().split())
lst = [list(map(int, input().split())) for _ in range(q)]
import itertools
l = [i+1 for i in range(m)]
lst2 = [com for com in itertools.combinations_with_replacement(l, n)]
res = 0
for com in lst2:
    score = 0
    for l in lst:
        if com[l[1]-1] - com[l[0]-1] == l[2]:
            score += l[3]
    if res < score:
        res = score 
    print(score)
print(res)

n,m,q = map(int ,input().split())
lst = [list(map(int, input().split())) for _ in range(q)]
import itertools
l = [i+1 for i in range(m)]
lst2 = [com for com in itertools.combinations(l, n)]
res = 0
for com in lst2:
    score = 0
    for l in lst:
        if com[l[1]-1] - com[l[0]-1] == l[2]:
            score += l[3]
    if res < score:
        res = score 
    print(score)
print(res)

n,m,q = map(int ,input().split())
lst = [list(map(int, input().split())) for _ in range(q)]
import itertools
l = [i+1 for i in range(m)]
lst2 = [com for com in itertools.combinations_with_replacement(l, n)]
res = 0
for com in lst2:
    score = 0
    for l in lst:
        if com[l[1]-1] - com[l[0]-1] == l[2]:
            score += l[3]
    if res < score:
        res = score 
    #print(score)
print(res)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import sys
import itertools


sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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


ans = 0
for lst in itertools.combinations_with_replacement(range(1, N + 1), N):
    s = 0
    for a, b, c, d in ABCD:
        if (lst[b - 1] - lst[a - 1]) == c:
            s += d

    ans = max(ans, s)

print(ans)


import sys
import itertools


sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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


ans = 0
for lst in itertools.combinations_with_replacement(range(1, M + 1), N):
    s = 0
    for a, b, c, d in ABCD:
        if (lst[b - 1] - lst[a - 1]) == c:
            s += d

    ans = max(ans, s)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
#import numpy as np
N,M,Q=map(int, input().split())
matrix=[]
for _ in range(Q):
    c=list(map(int, input().split()))
    matrix.append(c)
#matrix = np.array(matrix)
import itertools
ansscore = 0
combi = list(combinations_with_replacement(range(1,M+1),N)
for i in combi:
    i = list(i)
    i.sort()
    score=0
    for l in matrix:
        a=l[0]
        b=l[1]
        c=l[2]
        d=l[3]
        if i[b-1]-i[a-1]==c:
            score+=d
    ansscore = score if score>ansscore else ansscore

print(ansscore)

#import numpy as np
N,M,Q=map(int, input().split())
matrix=[]
for _ in range(Q):
    c=list(map(int, input().split()))
    matrix.append(c)
#matrix = np.array(matrix)
import itertools
ansscore = 0
combi = list(combinations_with_replacement(range(1,M+1),N))
for i in combi:
    i = list(i)
    i.sort()
    score=0
    for l in matrix:
        a=l[0]
        b=l[1]
        c=l[2]
        d=l[3]
        if i[b-1]-i[a-1]==c:
            score+=d
    ansscore = score if score>ansscore else ansscore

print(ansscore)

#import numpy as np
N,M,Q=map(int, input().split())
matrix=[]
for _ in range(Q):
    c=list(map(int, input().split()))
    matrix.append(c)
#matrix = np.array(matrix)
import itertools
ansscore = 0
combi = list(itertools.combinations_with_replacement(range(1,M+1),N))
for i in combi:
    i = list(i)
    i.sort()
    score=0
    for l in matrix:
        a=l[0]
        b=l[1]
        c=l[2]
        d=l[3]
        if i[b-1]-i[a-1]==c:
            score+=d
    ansscore = score if score>ansscore else ansscore

print(ansscore)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import itertools

n,m,q = input().split()
n = int(n)
m = int(m)
q = int(q)
num_list = []
a = list(range(1, n+1))
for i in range(q):
    num_list.append(list(map(int,input().split())))
num_list = sorted(num_list, reverse=True, key=lambda x: x[3])
ff = list(itertools.combinations_with_replacement(a, m))
max = 0
for i in range(len(ff)):
  s = 0
  for j in range(q):
    a,b,c,d = num_list[j]
    if ff[i][b-1] - ff[i][a-1] == c:
      s = s + d
  if max < s:
        max = s
print(max)

import itertools

n,m,q = input().split()
n = int(n)
m = int(m)
q = int(q)
num_list = []
a = list(range(1, n+1))
for i in range(q):
    num_list.append(list(map(int,input().split())))
ff = list(itertools.combinations_with_replacement(a, m))
max = 0
for i in range(len(ff)):
  s = 0
  for j in range(q):
    a,b,c,d = num_list[j]
    if ff[i][b-1] - ff[i][a-1] == c:
      s = s + d
  if max < s:
        max = s
print(max)
  

import itertools

n,m,q = input().split()
n = int(n)
m = int(m)
q = int(q)
num_list = []
a = list(range(1, n+1))
for i in range(q):
    num_list.append(list(map(int,input().split())))
ff = list(itertools.combinations_with_replacement(range(1, m + 1), n))
max = 0
for i in range(len(ff)):
  s = 0
  for j in range(q):
    a,b,c,d = num_list[j]
    if ff[i][b-1] - ff[i][a-1] == c:
      s = s + d
  if max < s:
        max = s
print(max)
  

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
from itertools import product

n, m, q = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(q)]

temp = list(combinations([i for i in range(1,m+1)],n))


ans = 0

for a_temp in temp:
    ans_temp = 0
    for i in range(q):
        if a_temp[a[i][1]-1] - a_temp[a[i][0]-1] == a[i][2]:
            ans_temp += a[i][3]
    if ans < ans_temp:
        ans = ans_temp
print(ans)

from itertools import combinations_with_replacement

n, m, q = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(q)]

temp = list(combinations_with_replacement([i for i in range(1,m+1)],n))

ans = 0

for a_temp in temp:
    ans_temp = 0
    for i in range(q):
        if a_temp[a[i][1]-1] - a_temp[a[i][0]-1] == a[i][2]:
            ans_temp += a[i][3]
    if ans < ans_temp:
        ans = ans_temp
        
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N,M,Q=map(int,input().split())

abcd=[]
for i in range(Q):
  abcd.append(list(map(int,input().split())))
  abcd[i][0]-=1
  abcd[i][1]-=1

  
def calcScore(target):
  score=0
  for i in range(Q):
    if target[abcd[i][1]]-target[abcd[i][0]]==abcd[i][2]:
      score+=abcd[i][3]
  return score

def makeTarget():
  list=[1]*N
  list[-1]=0
  while True:
    list[-1]+=1
    for i in range(len(list)):
      if list[-i-1]>M:
        if len(list)==i+1:return
        list[-i-2]+=1
        list[-i-1]=0
    for i in range(len(list)-1):
      if list[i]>list[i+1]:list[i+1]=list[i]
    yield list.copy()

ans=0
for i in makeTarget():
  print(i)
  ans=max(ans,calcScore(i))
print(ans)

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

abcd=[]
for i in range(Q):
  abcd.append(list(map(int,input().split())))
  abcd[i][0]-=1
  abcd[i][1]-=1

  
def calcScore(target):
  score=0
  for i in range(Q):
    if target[abcd[i][1]]-target[abcd[i][0]]==abcd[i][2]:
      score+=abcd[i][3]
  return score

def makeTarget():
  list=[0]*N
  while True:
    list[-1]+=1
    for i in range(len(list)):
      if list[-i-1]>M-1:
        if len(list)==i+1:return
        list[-i-2]+=1
        list[-i-1]=0
    for i in range(len(list)-1):
      if list[i]>list[i+1]:list[i+1]=list[i]
    yield list.copy()

ans=0
for i in makeTarget():
  print(i)
  ans=max(ans,calcScore(i))
print(ans)

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

abcd=[]
for i in range(Q):
  abcd.append(list(map(int,input().split())))
  abcd[i][0]-=1
  abcd[i][1]-=1

  
def calcScore(target):
  score=0
  for i in range(Q):
    if target[abcd[i][1]]-target[abcd[i][0]]==abcd[i][2]:
      score+=abcd[i][3]
  return score

def makeTarget():
  list=[1]*N
  list[-1]=0
  while True:
    list[-1]+=1
    for i in range(len(list)):
      if list[-i-1]>M:
        if len(list)==i+1:return
        list[-i-2]+=1
        list[-i-1]=0
    for i in range(len(list)-1):
      if list[i]>list[i+1]:list[i+1]=list[i]
    yield list.copy()

ans=0
for i in makeTarget():
  ans=max(ans,calcScore(i))
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import itertools
N, M, Q = map(int, input().split())
for i in range(Q):
    q_list.append(list(map(int, input().split())))

q_list = []
final_score = 0
for A in itertools.combinations_with_replacement(range(1,11), N):
    score = 0
    for q in q_list:
        if A[q[1]-1] - A[q[0]-1] == q[2]:
            score += q[3]
        final_score = max([final_score, score])
print(final_score)

import itertools
N, M, Q = map(int, input().split())
q_list = []
final_score = 0
for i in range(Q):
    q_list.append(list(map(int, input().split())))
for A in itertools.combinations_with_replacement(range(1,M+1), N):
    score = 0
    for q in q_list:
        if A[q[1]-1] - A[q[0]-1] == q[2]:
            score += q[3]
        final_score = max([final_score, score])
print(final_score)

Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
n,m,q=map(int,input().split())
abcd=[]
x=[1]
for i in range(q):
    abcd.append(list(map(int,input().split())))
ans=0
def dfs(s):
    global ans
    if(len(s)==n):
        t=0
        for a,b,c,d in abcd:
            if(s[b-1]-s[a-1]==c):
                t+=d
        ans=max(t,ans)
        return 
    p=s[-1]
    print(s)
    while p<=m:
        s.append(p)
        dfs(s)
        p=s.pop()+1
dfs(x)
print(ans)

n,m,q=map(int,input().split())
abcd=[]
x=[1]
for i in range(q):
    abcd.append(list(map(int,input().split())))
ans=0
def dfs(s):
    global ans
    if(len(s)==n):
        t=0
        for a,b,c,d in abcd:
            if(s[b-1]-s[a-1]==c):
                t+=d
        ans=max(t,ans)
        return 
    p=s[-1]
    while p<=m:
        s.append(p)
        dfs(s)
        p=s.pop()+1
dfs(x)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N, M, Q = map(int, input().split())
a = [0 for _ in range(Q)]
b = [0 for _ in range(Q)]
c = [0 for _ in range(Q)]
d = [0 for _ in range(Q)]
for k in range(Q):
  a[k], b[k], c[k], d[k] = map(int, input().split())
A = [1 for _ in range(N)]

def point(A):
  p = 0
  for ai, bi, ci, di in zip(a, b, c, d):
    if A[bi-1] - A[ai-1] == ci:
      p += di
  return p

def next(A):
  k = 1
  while k < N+1:
    if A[-k] < M:
      A[-k] += 1
      return A
      break
    else:
      for j in range(1, k+1):
        A[-j] = A[-k-1] + 1
      k += 1
      
ans = max(ans, point([M for _ in range(N)]))
while A[0] < M:
  ans = max(ans, point(A))
  A = next(A)
print(ans)

N, M, Q = map(int, input().split())
a = [0 for _ in range(Q)]
b = [0 for _ in range(Q)]
c = [0 for _ in range(Q)]
d = [0 for _ in range(Q)]
for k in range(Q):
  a[k], b[k], c[k], d[k] = map(int, input().split())
A = [1 for _ in range(N)]

def point(A):
  p = 0
  for ai, bi, ci, di in zip(a, b, c, d):
    if A[bi-1] - A[ai-1] == ci:
      p += di
  return p

def next(A):
  k = 1
  while k < N+1:
    if A[-k] < M:
      A[-k] += 1
      return A
      break
    else:
      for j in range(1, k+1):
        A[-j] = A[-k-1] + 1
      k += 1

ans = point([M for _ in range(N)])
while A[0] < M:
  ans = max(ans, point(A))
  A = next(A)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
n, m, q = map(int, input().split())

abcd = [list(map(int, input.split())) for _ in range(q)]
from itertools import combinations_with_replacement as cwr
A = list(cwr(range(1, m+1), n))


maxPoint = 0
for item in A:
  point = 0
  for i in range(len(abcd))
  a = abcd[i][0]
  b = abcd[i][1]
  c = abcd[i][2]
  d = abcd[i][3]
  if item[b-1] - item[a-1] == item[c-1]:
    point += d
  if point > maxPoint:
    maxPoint = point
print(maxPoint)

n, m, q = map(int, input().split())

abcd = [list(map(int, input().split())) for _ in range(q)]
from itertools import combinations_with_replacement as cwr
A = list(cwr(range(1, m+1), n))


maxPoint = 0
for item in A:
  point = 0
  for i in range(len(abcd)):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    if item[b-1] - item[a-1] == item[c-1]:
      point += d
  if point > maxPoint:
    maxPoint = point
print(maxPoint)

n, m, q = map(int, input().split())

abcd = [list(map(int, input().split())) for _ in range(q)]
from itertools import combinations_with_replacement as cwr
AList = list(cwr(range(1, m+1), n))


maxPoint = 0
for A in AList:
  point = 0
  for abc in abcd:
    a = abc[0]
    b = abc[1]
    c = abc[2]
    d = abc[3]
    if A[b-1] - A[a-1] == c:
      point += d
  if point > maxPoint:
    maxPoint = point
print(maxPoint)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N, M, Q = [int(_) for _ in input().split()]
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q

for i in range(Q):
    xs = [int(_) for _ in input().split()]
    a[i] = xs[0] - 1
    b[i] = xs[1] - 1
    c[i] = xs[2]
    d[i] = xs[3]


def calc_score(A):
    acc = 0
    for i in range(Q):
        if c[i] == A[b[i]] - A[a[i]]:
            acc += d[i]
    return acc


max_score = -1


def dfs(A):
    if len(A) == N:
        global max_score
        max_score = max(calc_score(A), max_score)
    else:
        if len(A) == 0:
            A.append(1)
        else:
            A.append(A[-1])
        while (A[-1] <= M):
            dfs(A)
            A[-1] += 1


dfs([])
print(max_score)


import copy

N, M, Q = [int(_) for _ in input().split()]
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q

for i in range(Q):
    xs = [int(_) for _ in input().split()]
    a[i] = xs[0] - 1
    b[i] = xs[1] - 1
    c[i] = xs[2]
    d[i] = xs[3]


def calc_score(A):
    acc = 0
    for i in range(Q):
        if c[i] == A[b[i]] - A[a[i]]:
            acc += d[i]
    return acc


max_score = -1


def dfs(A):
    if len(A) == N:
        global max_score
        max_score = max(calc_score(A), max_score)
    else:
        if len(A) == 0:
            A.append(1)
        else:
            A.append(A[-1])
        while (A[-1] <= M):
            dfs(copy.deepcopy(A))
            A[-1] += 1


dfs([])
print(max_score)


Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
n, m, q = list(map(int, input().split()))
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

ans = 0
def dfs(A=[]):
    global ans
    if len(A) == n+1:
        now = 0
        for i in range(q):
            if A[b[i]] - A[a[i]] == c[i]:
                now += d[i]
        ans = max(ans, now)
        return
    A.append(A[-1])
    while(A[-1] <= m):
        dfs(A)
        A[-1] += 1

dfs([1])
print(ans)


n, m, q = list(map(int, input().split()))
a, b, c, d = [0] * q, [0] * q, [0] * q, [0] * q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

A = [0] * (n+1)
A[0] = 1
ans = 0
def dfs(k):
    global ans
    if k == n+1:
        now = 0
        for i in range(q):
            if A[b[i]] - A[a[i]] == c[i]:
                now += d[i]
        ans = max(ans, now)
    else:
        for i in range(A[k-1], m+1):
            A[k] = i
            dfs(k+1)

dfs(1)
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N, M, Q = map(int, input().split())
tmp = [list(map(int, input().split())) for i in range(Q)]





ans = [0]
def dfs(A):
    if len(A) == N:
        tmp_ans = 0
        for ele in tmp
            if ele[1] - ele[0] == ele[2]:
                tmp_ans += ele[-1]
        ans[0] = max(tmp_ans,ans[0])

        return
    
    A_min = A[-1]
    while(1):
        if A_min > M:
            break
        A.append(A_min)
        dfs(A)
        A.pop()
        A_min += 1

for i in range(M):
    dfs([i+1])

print(ans[0])



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





ans = [0]
def dfs(A):
    # print(A)
    if len(A) == N:
        tmp_ans = 0
        for ele in tmp:
            if A[ele[1]-1] - A[ele[0]-1] == ele[2]:
                tmp_ans += ele[-1]
        ans[0] = max(tmp_ans,ans[0])

        return
    
    A_min = A[-1]
    while(1):
        if A_min > M:
            break
        A.append(A_min)
        dfs(A)
        A.pop()
        A_min += 1

for i in range(M):
    dfs([i+1])

print(ans[0])



Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
ts = []
for _ in range(Q):
    ts.append(tuple(map(int, input().split())))
print(ts)

scores = []
for A in combinations_with_replacement(range(1, M + 1), N):
    score = 0
    for t in ts:
        a, b, c, d = t
        if A[b - 1] - A[a - 1] == c:
            score += d
    scores.append(score)

print(max(scores))


from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
ts = []
for _ in range(Q):
    ts.append(tuple(map(int, input().split())))

scores = []
for A in combinations_with_replacement(range(1, M + 1), N):
    score = 0
    for t in ts:
        a, b, c, d = t
        if A[b - 1] - A[a - 1] == c:
            score += d
    scores.append(score)

print(max(scores))


Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
# -*- coding: utf-8 -*-


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

numbers = []
for i in range(Q):
    numbers.append([int(j) for j in input().split()])

numbers = sorted(numbers , key = lambda x:-x[1])
#print(numbers)

kouho = ["9"*(N)]

for a, b , c ,d in numbers:
    for k in kouho:
        if int(k[b-1]) - int(k[a-1]) != c:
            new_k = k[:a-1] + str(int(k[b-1])-c) +  k[a:]
            if str(int(k[b-1])-c) >= 0:
                kouho.append(new_k)
                kouho = list(set(kouho))

#print(sorted(kouho))

answers = [0] * len(kouho)
for i, k in  enumerate(kouho):
    ans = 0
    for a, b, c, d in numbers:
        if int(k[b-1]) - int(k[a-1]) == c:
            ans += d
    answers[i] = ans
print(max(answers))
'''
kouho = []
for password in range(0,10**(N-1)):
    password = "9" + str(password).zfill(N-1)
    kouho.append(''.join(list(reversed(password))))

answers = [0] * len(kouho)
for i, k in  enumerate(kouho):
    ans = 0
    for a, b, c, d in numbers:
        if int(k[b-1]) - int(k[a-1]) == c:
            ans += d
    answers[i] = ans
print(max(answers))
'''


import itertools

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

numbers = []
for i in range(Q):
    numbers.append([int(j) for j in input().split()])


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

answer = 0
for k in  A:
    ans = 0
    for a, b, c, d in numbers:
        if int(k[b-1]) - int(k[a-1]) == c:
            ans += d
    if answer < ans:
        answer = ans
print(answer)


Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import copy

n, m, q = map(int, input().split())

a = []
b = []
c = []
d = []

for i in range(q):
  _a, _b, _c, _d = map(int, input().split())
  a.append(_a)
  b.append(_b)
  c.append(_c)
  d.append(_d)

seq = [[] for i in range(n)]

for i in range(1, m + 1):
  seq[0].append([i])

for i in range(1, n):
  for j in range(len(seq[i - 1])):
    s = copy.copy(seq[i - 1][j])
    s.append(0)
    for k in range(s[-2], m + 1):
      s[-1] = k
      s2 = copy.copy(s)
      seq[i].append(s2)

score = [0 for i in range(len(seq[n - 1]))]
for i in range(len(seq[n - 1])):
  for j in range(q):
    if seq[n - 1][i][b[j] - 1] - seq[n - 1][i][a[j] - 1] == c:
      score[i] += d[j]

print(max(score))

import copy

n, m, q = map(int, input().split())

a = []
b = []
c = []
d = []

for i in range(q):
  _a, _b, _c, _d = map(int, input().split())
  a.append(_a)
  b.append(_b)
  c.append(_c)
  d.append(_d)

seq = [[] for i in range(n)]

for i in range(1, m + 1):
  seq[0].append([i])

for i in range(1, n):
  for j in range(len(seq[i - 1])):
    s = copy.copy(seq[i - 1][j])
    s.append(0)
    for k in range(s[-2], m + 1):
      s[-1] = k
      s2 = copy.copy(s)
      seq[i].append(s2)

score = [0 for i in range(len(seq[n - 1]))]
for i in range(len(seq[n - 1])):
  for j in range(q):
    if seq[n - 1][i][b[j] - 1] - seq[n - 1][i][a[j] - 1] == c[j]:
      score[i] += d[j]

print(max(score))

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
n,m,q = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(q)]
ans = 0
for i1 in range(1, m+1):
    for i2 in range(i1, m+1):
        for i3 in range(i2, m+1):
            for i4 in range(i3, m+1):
                for i5 in range(i4, m+1):
                    for i6 in range(i5, m+1):
                        for i7 in range(i6, m+1):
                            for i8 in range(i7, m+1):
                                for i9 in range(i8, m+1):
                                    for i10 in range(19, m+1):
                                        tmp = 0
                                        arrs = [0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10]
                                        for a, b, c, d in arr:
                                            if arrs[b] - arrs[a] == c:
                                                tmp += d
                                        ans = max(ans, tmp)
print(ans)

def dfs(arr, min_nx):
    ans = 0
    if len(arr) == n:
        tmp = 0
        for a,b,c,d in lst:
            if arr[b-1] - arr[a-1] == c:
                tmp += d
        return tmp
    else:
        for nx in range(min_nx, m+1):
            new_arr = arr + [nx]
            score = dfs(new_arr, nx)
            ans = max(ans, score)
    return ans
n,m,q = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(q)]
ans = dfs([], 1)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import math
import itertools

N,M,Q = map(int,input().split())
a =[0] * Q
b =[0] * Q
c =[0] * Q
d =[0] * Q
for i in range(Q):
    a[i] , b[i] , c[i] , d[i] = map(int,input().split())





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



All =[0] * M
for i in range(M):
    All[i] = i+1














ans = 0
#for A in itertools.combinations(All, N):
for A in itertools.product(All, repeat=N):
    
    
    
    #print(A)
    wa = 0
    for i in range(Q):
        print(wa) 
        kari = A[b[i]-1] - A[a[i]-1]
        if kari == c[i]:
            wa = wa + d[i] 
    if ans < wa:
        ans = wa
    #print(ans) 
    #print(wa) 


print(ans)



























import math
import itertools

N,M,Q = map(int,input().split())
a =[0] * Q
b =[0] * Q
c =[0] * Q
d =[0] * Q
for i in range(Q):
    a[i] , b[i] , c[i] , d[i] = map(int,input().split())





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



All =[0] * M
for i in range(M):
    All[i] = i+1














ans = 0
for A in itertools.product(All, N):
    
    print(A)
    wa = 0
    for i in range(Q):
        print(wa) 
        kari = A[b[i]-1] - A[a[i]-1]
        if kari == c[i]:
            wa = wa + d[i] 
    if ans < wa:
        ans = wa
    #print(ans) 
    #print(wa) 


print(ans)



























import math
import itertools

N,M,Q = map(int,input().split())
a =[0] * Q
b =[0] * Q
c =[0] * Q
d =[0] * Q
for i in range(Q):
    a[i] , b[i] , c[i] , d[i] = map(int,input().split())




Al =[0] * M
for i in range(M):
    Al[i] = i+1











All = list(itertools.combinations_with_replacement(Al, N))



ans = 0
#for A in itertools.combinations(All, N):
for A in All:
    
    #print(A)
    wa = 0
    for i in range(Q):
        #print(wa) 
        kari = A[b[i]-1] - A[a[i]-1]
        if kari == c[i]:
            wa = wa + d[i] 
    if ans < wa:
        ans = wa
    #print(ans) 
    #print(wa) 


print(ans)



























Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
list = [list(map(int,input().split())) for _ in range(Q)]
seq = [i for i in range(1,M+1)]
C = combinations_with_replacement(seq, N)
max_score = 0

for A in C:
    A = sorted(A)
    score = 0
    for q in list:
        if A[q[1]-1] - A[q[0]-1] == q[2]:
            score += q[3]
        print(score)
    max_score = max(score, max_score)
print(max_score)


from itertools import combinations_with_replacement

def main():
    N, M, Q = map(int, input().split())
    qs = [list(map(int,input().split())) for _ in range(Q)]
    seq = [i for i in range(1,M+1)]
    C = combinations_with_replacement(seq, N)
    max_score = 0

    for A in C:
        A = sorted(A)
        score = 0
        for q in qs:
            if A[q[1]-1] - A[q[0]-1] == q[2]:
                score += q[3]
        max_score = max(score, max_score)
    print(max_score)

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
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)

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)

Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):

n,m,q = map(int,input().split())
num_lst = []
for i in range(q):
    num_lst.append(list(map(int,input().split())))
l = list(range(1,m+1))
A = list(combinations_with_replacement(l,n))

mx = 0
for now_A in A:
    score = 0
    for nums in num_lst:
        a,b,c,d = nums
        if now_A[b-1] - now_A[a-1] == c:
            score += d
    mx = max(mx,score)
print(mx)





from itertools import combinations_with_replacement


n,m,q = map(int,input().split())
num_lst = []
for i in range(q):
    num_lst.append(list(map(int,input().split())))
l = list(range(1,m+1))
A = list(combinations_with_replacement(l,n))

mx = 0
for now_A in A:
    score = 0
    for nums in num_lst:
        a,b,c,d = nums
        if now_A[b-1] - now_A[a-1] == c:
            score += d
    mx = max(mx,score)
print(mx)





Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import sys
from io import StringIO
import unittest
import itertools

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m,q=map(int, readline().rstrip().split())

    aa=[0]*q
    bb=[0]*q
    cc=[0]*q
    dd=[0]*q

    for i in range(q):
        aa[i],bb[i],cc[i],dd[i]=map(int, readline().rstrip().split())

    max_score=0

    for a in itertools.combinations_with_replacement(list(range(1,m+1)),n):
        score=0
        for i in range(q):
            if (a[bb[i]-1]-a[aa[i]-1])==cc[i]:
                score+=dd[i]
        max_score=max(max_score,score)

    print(max_score)

    return

### ----------------

### ----------------

import sys
from io import StringIO
import unittest
import itertools

sys.setrecursionlimit(500*500)

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m,q=map(int, readline().rstrip().split())

    aa=[0]*q
    bb=[0]*q
    cc=[0]*q
    dd=[0]*q

    for i in range(q):
        aa[i],bb[i],cc[i],dd[i]=map(int, readline().rstrip().split())

    max_score=0

    for a in itertools.combinations_with_replacement(list(range(1,m+1)),n):
        score=0
        for i in range(q):
            if (a[bb[i]-1]-a[aa[i]-1])==cc[i]:
                score+=dd[i]
        max_score=max(max_score,score)

    print(max_score)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()


### ----------------

### ----------------

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

q = []
def dp(arg):
    global N
    if len(arg) == N:
        q.append(arg)
    else:
        tmp = 0 if len(arg) == 0 else arg[-1]
        for i in range(arg[-1], M + 1):
            dp(arg + [i])

dp([])

ans = 0
for A_tmp in q:
    ans_tmp = 0
    for j, (aj, bj, cj, dj) in enumerate(abcd):
        if A_tmp[bj - 1] - A_tmp[aj - 1] == cj:
            ans_tmp += dj
    #
    ans = max(ans, ans_tmp)

print(ans)

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

As = []
q = [[]]
while len(q) > 0:
    arg = q.pop()
    if len(arg) == N:
        As.append(arg)
    else:
        A_str = 1 if len(arg) == 0 else arg[-1]
        for i in range(A_str, M + 1):
            q.append(arg + [i])

ans = 0
for A in As:
    ans_tmp = 0
    for j, (aj, bj, cj, dj) in enumerate(abcd):
        if A[bj - 1] - A[aj - 1] == cj:
            ans_tmp += dj
    #
    ans = max(ans, ans_tmp)

print(ans)

Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import itertools
N,M,Q=list(map(int,input().split()))
src=[list(map(int,input().split())) for q in range(Q)]
ML=[n+1 for n in range(M)]
X=list(itertools.combinations_with_replacement(ML,N))
L=[]
for x in X:
  a=0
  for s in src:
    if x[s[1]] - x[s[0]] == s[2]:
      a+=s[3]
  L.append(a)
print(max(L))

import itertools
N,M,Q=list(map(int,input().split()))
src=[]
for q in range(Q):
  src.append(list(map(int,input().split())))
ML=[n+1 for n in range(M)]
X=list(itertools.combinations_with_replacement(ML,N))
L=[]
for x in X:
  a=0
  for s in src:
    if x[s[1]-1] - x[s[0]-1] == s[2]:
      a+=s[3]
  L.append(a)
print(max(L))

Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N,M,Q = list(map(int, input().split()))
C = []
for i in range(Q):
    C.append(list(map(int, input().split())))
    
import itertools
res = 0
ls=list(range(1,M+1))
for a in itertools.combinations_with_replacement(ls, N):
    p = 0
    for c in C:
        if a[c[1]]-a[c[0]]==c[2]:
            p += c[3]
        res = max(res,p)
print(res)

import itertools

N,M,Q = list(map(int, input().split()))
C = []
for i in range(Q):
    C.append(list(map(int, input().split())))
    
res = 0
ls=list(range(1,M+1))

for a in itertools.combinations_with_replacement(ls, N):
    p = 0
    for c in C:
        if a[c[1]]-a[c[0]]==c[2]:
            p += c[3]
        res = max(res,p)

print(res)

N,M,Q = list(map(int, input().split()))
C = []
for i in range(Q):
    C.append(list(map(int, input().split())))
    
import itertools
res = 0
ls=list(range(1,M+1))
for a in itertools.combinations_with_replacement(ls, N):
    p = 0
    for c in C:
        if a[c[1]-1]-a[c[0]-1]==c[2]:
            p += c[3]
        res = max(res,p)
print(res)

Verdicts: Runtime Error

Runtime Error

Accepted