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):
#C - Many Requirements

N,M,Q = map(int,input().split())
abcd = []
for _ in range(Q):
    a,b,c,d = map(int,input().split())
    abcd.append((a,b,c,d))
def dfs(A):
    if len(A) == N:
        
        score = 0
        for ai,bi,ci,di in abcd:
            if A[bi-1] -A[ai-1] == ci:
                score += di
        return score
    max_score = 0 
    
    if len(A) > 1:
        prev_last = A[-1]
    else:
        prev_last = 1
    
    for i in range(prev_last,M+1):
        A.append(i)
        max_score = max(max_score,dfs(A))
        A.pop()
    return max_score
print(dfs[])

#C - Many Requirements

N,M,Q = map(int,input().split())
abcd = []
for _ in range(Q):
    a,b,c,d = map(int,input().split())
    abcd.append((a,b,c,d))
max_score = 0
def dfs(A):
    global max_score
    if len(A) == N:
        
        score = 0
        for ai,bi,ci,di in abcd:
            if A[bi-1] -A[ai-1] == ci:
                score += di
        return score
    
    if len(A) >= 1:
        prev_last = A[-1]
    else:
        prev_last = 1
    
    for i in range(prev_last,M+1):
        A.append(i)
        max_score = max(max_score,dfs(A))
        A.pop()
    return max_score
dfs([])
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):
import itertools
n,m,q = (int(x) for x in input().split())
l = []
a = [1,2,3,4,5,6,7,8,9,10]
b = []
c = []
d = []


for i in range(q):
    l.append([])
    l[i]=list(map(int, input().split()))
    
for i in itertools.combinations_with_replacement(a[:m], r=n):
        b.append(i) 
print(b)        
    
for i in range(len(b)):
    d.append(0)

for i in range(q):
    w=l[i][0]-1#a
    x=l[i][1]-1#b
    y=l[i][2]#c
    z=l[i][3]#d
    for j in range(len(b)):
        if b[j][x]-b[j][w]==y:
            d[j]+=z

print(max(d))

import itertools
n,m,q = (int(x) for x in input().split())
l = []
a = [1,2,3,4,5,6,7,8,9,10]
b = []
c = []
d = []


for i in range(q):
    l.append([])
    l[i]=list(map(int, input().split()))
    
for i in itertools.combinations_with_replacement(a[:m], r=n):
        b.append(i)        
    
for i in range(len(b)):
    d.append(0)

for i in range(q):
    w=l[i][0]-1#a
    x=l[i][1]-1#b
    y=l[i][2]#c
    z=l[i][3]#d
    for j in range(len(b)):
        if b[j][x]-b[j][w]==y:
            d[j]+=z

print(max(d))


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]*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())
import itertools
for A in itertools.combinations_with_replacement(range(1,M+1),N):
    ans=0
    if i in range(Q):
        s=0
        A[b[i]]-A[a[i]]=c[i]
        s+=d[i]
        ans=max(ans,s)
print(ans)   

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())
import itertools
for A in itertools.combinations_with_replacement(range(1,M+1),N):
    ans=0
    if i in range(Q):
        s=0
        if A[b[i]]-A[a[i]]==c[i]:
           s+=d[i]
            ans=max(ans,s)
print(ans)        
        

n,m,q=map(int,input().split())
def dfs(seq):
    u=0
    if len(seq)==n:
        ans=0
        for a,b,c,d in data:
            if seq[b-1]-seq[a-1]==c:
                ans+=d
        return ans
    else:
        for i in range(seq[-1],m+1):
            seq_next=seq.copy()
            seq_next.append(i)
            u=max(u,dfs(seq_next))
        return u

data=[]
for _ in range(q):
    A=list(map(int,input().split()))
    data.append(A)
print(dfs([1]))


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 = map(int, input().aplist())
lists = [list(map(int, input().split())) for i in range(Q)]
ans = 0

def calc_score(A):
    score = 0
    for a, b, c, d in lists:
        if A[b -1] - A[a - 1] == c:
            score += d
    return score

def dfs(A):
    global ans
    if len(A) == N:
        score = calc_score(A)
        ans = max(score, ans)
        return
    for n in range(A[-1], M + 1):
        dfs(A + [n])
        
dfs([1])
print(ans)


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

def calc_score(A):
   score = 0
   for a, b, c, d in lists:
       if A[b - 1] - A[a - 1] == c:
           score += d
   return score

def dfs(A):
   global ans
   if len(A) == N:
       score = calc_score(A)
       ans = max(score, ans)
       return
   for n in range(A[-1], M + 1):
       dfs(A + [n])

dfs([1])
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):
from itertools import *
from more_itertools import *

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

aaa=[]
for i in range(m):
    aaa.append(i+1)

l=[]
for i in range(q):
    a=list(map(int,input().split()))
    l.append(a)

a=list(combinations_with_replacement(aaa,n))
ans=0
for i in a:
    aa=0
    for j in l:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            aa+=j[3]
    if aa>ans:
        ans=aa
print(ans)

from itertools import *

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

aaa=[]
for i in range(m):
    aaa.append(i+1)

l=[]
for i in range(q):
    a=list(map(int,input().split()))
    l.append(a)

a=list(combinations_with_replacement(aaa,n))
ans=0
for i in a:
    aa=0
    for j in l:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            aa+=j[3]
    if aa>ans:
        ans=aa
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())

al=list()

for i in range(Q): 
    a,b,c,d=map(int,input().split())
    al.append([a,b,c,d])


Sum=0
Summax=0
cnt=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(i9,M+1): 
                                        cnt+=1
                                        Al=[i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                                        Sum=0
                                        for i in range(Q): 
                                            if(Al[al[i][1]-1]-Al[al[i][0]-1]==al[i][2]):
                                                Sum+=al[i][3]
                                        if(Summax<Sum):
                                            Summax=Sum

print(Summax)    
print(cnt)

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

al=list()

for i in range(Q): 
    a,b,c,d=map(int,input().split())
    al.append([a,b,c,d])


Sum=0
Summax=0
cnt=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(i9,M+1): 
                                        cnt+=1
                                        Al=[i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                                        Sum=0
                                        for i in range(Q): 
                                            if(Al[al[i][1]-1]-Al[al[i][0]-1]==al[i][2]):
                                                Sum+=al[i][3]
                                        if(Summax<Sum):
                                            Summax=Sum

print(Summax)    
#print(cnt)

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):
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for _ in range(Q)]
ans = 0
for t in combinations_with_replacement(range(1, M+1), N):
    an = 0
    for a, b, c, d in ABCD:
        if t[b-1]-t[a-1] == c:
            an += d
    if ans < an:
        ans = an
print(an

from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for _ in range(Q)]
ans = 0
for t in combinations_with_replacement(range(1, M+1), N):
    an = 0
    for a, b, c, d in ABCD:
        if t[b-1]-t[a-1] == c:
            an += d
    if ans < an:
        ans = an
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):
from itertools import combinations as c
n, m, q = map(int, input().split())
arr = []
for i in range(q):
  l = [*map(int, input().split())]
  arr.append(l)
res = 0
for g in c(list(range(1, m+1)), n):
  f = 0
  for h in arr:
    if g[1] - g[0] == g[2]:
      f += g[3]
  res = max(res, f)
print(res)

from itertools import combinations_with_replacement as c 
n, m, q = map(int, input().split()) 
arr = [] 
for i in range(q): 
    l = [*map(int, input().split())] 
    arr.append(l) 
res = 0
for g in c(list(range(1, m+1)), n): 
    f = 0 
    for h in arr:
        if g[h[1]-1] - g[h[0]-1] == h[2]: 
            f += h[3]
    res = max(res, f) 
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):
cin = open(0).read().strip().split('\n')
n, m, q = map(int, cin[0].split(' '))
abcd = [tuple(map(int, a.split(' '))) for a in cin[1:]]

ret = 0
for case in itertools.combinations_with_replacement(list(range(1,m+1)), n):
    tmp = 0
    for c in abcd:
        if case[c[1]-1] - case[c[0]-1] == c[2]:
            tmp += c[3]
    ret = max(ret, tmp)
print(ret)

cin = open(0).read().strip().split('\n')
n, m, q = map(int, cin[0].split(' '))
abcd = [tuple(map(int, a.split(' '))) for a in cin[1:]]

ret = 0
import itertools
for case in itertools.combinations_with_replacement(list(range(1,m+1)), n):
    tmp = 0
    for c in abcd:
        if case[c[1]-1] - case[c[0]-1] == c[2]:
            tmp += c[3]
    ret = max(ret, tmp)
print(ret)

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
def generateA(N, M):
    m = range(1, M+1)
    A = [1 for i in range(N)]
    lastA = [M for i in range(N)]
    while True:
        yield A
        if A == lastA:
            break
        for i in range(N):
            if A[N-1-i] == M:
                continue
            A[N-1-i] += 1
            for j in range(N-1-i+1, N):
                A[j] = 1
            break

def point(A, L):
    result = 0
    for (a, b, c, d) in L:
        if A[b-1] - A[a-1] == c:
            result += d

    return result

def summary(N, M, L):
    As = generateA(N, M)

    results = []
    for A in As:
        print(A)
        results.append(point(A,L))
    return results

def main():
    N, M ,Q = map(int, input().split())
    L = []
    for i in range(Q):
        a, b, c, d = map(int, input().split())
        L.append((a,b,c,d))
    results = summary(N,M,L)

    print(max(results))

if __name__ == '__main__':
    main()

import itertools
def generateA(N, M, minv=1):
    if N < 0:
        return
    if N == 0:
        yield []
    if N == 1:
        for i in range(minv, M):
            yield [i]
    for v in range(minv, M+1):
        for subA in generateA(N-1, M, v):
            yield [v] + subA

def point(A, L):
    result = 0
    for (a, b, c, d) in L:
        if A[b-1] - A[a-1] == c:
            result += d

    return result

def summary(N, M, L):
    As = generateA(N, M)

    results = []
    for A in As:
        results.append(point(A,L))
    return results

def test():
    As = generateA(3,4)
    for A in As:
        print(A)

def main():
    #test()
    N, M ,Q = map(int, input().split())
    L = []
    for i in range(Q):
        a, b, c, d = map(int, input().split())
        L.append((a,b,c,d))
    results = summary(N,M,L)

    print(max(results))

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 math
def solve():
    n, m, q = map(int, input().split())
    l = [list(map(int, input().split())) for _ in range(q)]

    ans = 0
    for i in range(2**(n-2)):
        cur = []
        for j in range(n-2):
            if (i>>j)&1:
                cur.append(i+1)
        A = [1] + cur + [n, m]
        print(A)
        tot = 0
        for k in range(q):
            a, b, c, d = l[k]
            if b+1 <= n and A[b] - A[a] == c:
                print(A[0], A[a])
                tot += d
        ans = max(ans, tot)
    
    return ans


print(solve())


from itertools import combinations_with_replacement
def solve():
    n, m, q = map(int, input().split())
    l = [list(map(int, input().split())) for _ in range(q)]

    com = [int(x) for x in range(1, m+1)]
    ans = 0
    for i in combinations_with_replacement(com, n-1):
        cur = list(i)
        A = [1] + cur
        tot = 0
        for k in range(q):
            a, b, c, d = l[k]
            if A[b-1] - A[a-1] == c:
                tot += d
        ans = max(ans, tot)
    
    return ans


print(solve())


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 = map(int, input().split())
a = [None for _ in range(Q)]
b = [None for _ in range(Q)]
c = [None for _ in range(Q)]
d = [None for _ in range(Q)]
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

ans = 0
elements = list(range(1, M+1))
for combination in itertools.combinations_with_replacement(elements, N):
    score = 0
    for i in range(Q):
        print(combination, b[i], a[i])
        if combination[b[i]-1] - combination[a[i]-1] == c[i]:
            score += d[i]
    ans = max(score, ans)
print(ans)


def combinations_with_replacement(elements, N):
    for i, element in enumerate(elements):
        if N == 1:
            yield [element]
        else:
            for combination in combinations_with_replacement(elements[:i+1], N-1):
                combination.append(element)
                yield combination


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

ans = 0
elements = list(range(1, M+1))
for combination in combinations_with_replacement(elements, N):
    score = 0
    for i in range(Q):
        if combination[b[i]-1] - combination[a[i]-1] == c[i]:
            score += d[i]
    ans = max(score, ans)
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 itertools
 
def check(lis, a):
    return sum((i[3] for i in a if lis[i[1]-1]-lis[i[0]-1]==i[2]))
   
n, m, q = map(int, input().split())
a = ((int(i) for i in input().split(" ")) for j in range(q))
ans = 0
for i in itertools.combinations_with_replacement(range(m), n):
    ans = max(ans, check(i, a))
print(ans)

import itertools
 
def check(lis, a):
    return sum((i[3] for i in a if lis[i[1]-1]-lis[i[0]-1]==i[2]))
   
n, m, q = map(int, input().split())
a = [[int(i) for i in input().split(" ")] for j in range(q)]
ans = 0
for i in itertools.combinations_with_replacement(range(m), n):
    ans = max(ans, check(i, 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())
L = []
for i in range(Q):
  L.append(list(map(int, input().split())))
  #print(L[i][1])
import itertools

l =list(range(1,M+1))
ans=0

v=list(itertools.combinations(l,N))
print(v)
for j in range(len(v)):
  for i in range(Q):
    if (v[j][L[i][1]-1] - v[j][L[i][0]-1])==L[i][2]:
      print(v[j][L[i][1]-1],v[j][L[i][0]-1],L[i][2])
      ans+=L[i][3]
print(ans)

'''

for i in range(Q):   
  for v in itertools.combinations(l,N):
    if (v[L[i][1]-1] - v[L[i][0]-1])==L[i][2]:
      print(v[L[i][1]-1],v[L[i][0]-1],L[i][2])
      ans+=L[i][3]
print(ans)
'''

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

import itertools
L=list(range(1,M+1))
A=list(itertools.combinations_with_replacement(L,N))
ans=0
for i in A:
  tmp=0
  for a,b,c,d in L:
    if (i[b]-i[a])==c:
      tmp+=d
  ans=max(ans,tmp)
print(ans)

def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
from itertools import combinations_with_replacement
N,M,Q=MI()
A=[]
B=[]
C=[]
D=[]
ans=0
for i in range(Q):
  a,b,c,d=MI()
  a-=1
  b-=1
  A.append(a)
  B.append(b)
  C.append(c)
  D.append(d)
#print(A,B,C,D)
Num=list(range(1,M+1))
#print(Num)
#print(list(combinations(Num,N)))
for j in list(combinations_with_replacement(Num,N)):
  tmp=0
  for i in range(Q):
    if j[B[i]]-j[A[i]]==C[i]:
      tmp+=D[i]
  ans=max(ans,tmp)  
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):
import itertools

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

answer = 0

nums=[]
for i in range(1, M+1):
    nums.append(i)

for balls in itertools.combinations_with_replacement(nums, N):
    score = 0
    for i in range(Q):
        test = list(balls)
        print(test)
        if test[abcd[i][0]-1] + abcd[i][2] == test[abcd[i][1]-1]:
            score += abcd[i][3]
    if score > answer:
        answer = score

print(answer)


import itertools

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

answer = 0

nums=[]
for i in range(1, M+1):
    nums.append(i)

for balls in itertools.combinations_with_replacement(nums, N):
    score = 0
    test = list(balls)
    for i in range(Q):
        if test[abcd[i][0]-1] + abcd[i][2] == test[abcd[i][1]-1]:
            score += abcd[i][3]
    if score > answer:
        answer = score

print(answer)


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):
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328

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

num = 0
nax = 0

nums = [i for i in range(1, m+1)]

for com in list(itertools.combinations_with_replacement(nums, n)):
    num = 0
    for j in range(q):
        if com[l[j][1]-1]-com[l[j][0]-1] == l[j][2]:
            num += l[j][3]
    nax = max(num, nax)
print(nax)


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
sys.setrecursionlimit(10**5)
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,B,C,D=map(int,input().split())
    a[i]=A;b[i]=B;c[i]=C;d[i]=D
r=[]
def dfs(i,depth,b,h):
    if depth==0:
        b.append(h)
        return
    for j in range(i,M):
        nh=h[:]
        nh.append(j)
        dfs(j,depth-1,b,nh)
dfs(1,10,r,[])
ans=0
for R in r:
    cnt=0
    for j in range(Q):
        if R[b[j]-1]-R[a[j]-1]==c[j]:
            cnt+=d[j]
    ans=max(cnt,ans)
print(ans)

import sys
sys.setrecursionlimit(10**5)
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,B,C,D=map(int,input().split())
    a[i]=A;b[i]=B;c[i]=C;d[i]=D
r=[]
def dfs(i,depth,b,h):
    if depth==0:
        b.append(h)
        return
    for j in range(i,M+1):
        nh=h[:]
        nh.append(j)
        dfs(j,depth-1,b,nh)
dfs(1,10,r,[])
ans=0
for R in r:
    cnt=0
    for j in range(Q):
        if R[b[j]-1]-R[a[j]-1]==c[j]:
            cnt+=d[j]
    ans=max(cnt,ans)
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):
from itertools import combinations

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

lis = list(range(1, M+1))
box = list(combinations(lis, N))
print(abcd)

ans = []
for i in box:
    temp = 0
    for a, b, c, d in abcd:
        if i[b-1] - i[a-1] == c:
            temp += d
    ans.append(temp)

print(max(ans))

from itertools import combinations_with_replacement

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

ans = 0
for v in combinations_with_replacement(range(1, M+1), N):
    A = list(v)
    temp = 0
    for a, b, c, d in abcd:
        if A[b-1] - A[a-1] == c:
            temp += d
    ans = max(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 = list(map(int,input().split()))
Q = [list(map(int,input().split())) for i in range(N[2])]

# N = [4, 6, 10]
# Q = [[2, 4, 1, 86568], [1, 4, 0, 90629], [2, 3, 0, 90310], [3, 4, 1, 29211], [3, 4, 3, 78537], [3, 4, 2, 8580], [1, 2, 1, 96263], [1, 4, 2, 2156], [1, 2, 0, 94325], [1, 4, 3, 94328]]

from itertools import combinations_with_replacement as comb_rplc

C = 0
for seq in comb_rplc(range(1, N[1]+1), N[0]):
    print(seq)
    S = 0
    for i in range(N[2]):
        if seq[Q[i][1]-1]-seq[Q[i][0]-1] == Q[i][2]:
            S += Q[i][3]
    if S > C:
        C = S

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

# N = [4, 6, 10]
# Q = [[2, 4, 1, 86568], [1, 4, 0, 90629], [2, 3, 0, 90310], [3, 4, 1, 29211], [3, 4, 3, 78537], [3, 4, 2, 8580], [1, 2, 1, 96263], [1, 4, 2, 2156], [1, 2, 0, 94325], [1, 4, 3, 94328]]

from itertools import combinations_with_replacement as comb_rplc

C = 0
for seq in comb_rplc(range(1, N[1]+1), N[0]):
    S = 0
    for i in range(N[2]):
        if seq[Q[i][1]-1]-seq[Q[i][0]-1] == Q[i][2]:
            S += Q[i][3]
    if S > C:
        C = S
print(C)

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):
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
cond = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    cond.append((a, b, c, d))


def calc(l):
    score = 0
    for a, b, c, d in cond:
        if l[b] - l[a] == c:
            score += d
    return score


ans = 0
l = [0] * n
l[0] = 1


def dfs(l_len):
    if l_len == n:
        ans = max(ans, calc(l))
        return

    for i in range(l[l_len - 1], m + 1):
        l[l_len] = i
        dfs(l_len + 1)


dfs(0)
print(ans)


from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
cond = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    cond.append((a, b, c, d))


def calc(l):
    score = 0
    for a, b, c, d in cond:
        if l[b] - l[a] == c:
            score += d
    return score


ans = 0
l = [0] * n
l[0] = 1


def dfs(l_len):
    global l, ans
    if l_len == n:
        ans = max(ans, calc(l))
        return

    for i in range(l[l_len - 1], m + 1):
        l[l_len] = i
        dfs(l_len + 1)


dfs(1)
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 = int(input())
GACHA=[input() for n in range(N)]
print(len(set(GACHA)))

N = int(input())
GACHA=set()
for n in range(N):
  GACHA.add(input())
print(len(GACHA))

import itertools

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

ans=0
for A in itertools.combinations_with_replacement([m for m in range(1,M+1)], N):
  ans2=0
  for (a,b,c,d) in ABCD:
    if A[b-1]-A[a-1]==c:
      ans2+=d
  ans=max(ans, ans2)
print(ans)


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):
                                                                               │➜  typical
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

import itertools

def main():
  N, M, Q = map(int, input().split())
  all_num = [i for i in range(1, M+1)]
  q_kumi = []
  for i in range(Q):
    q_kumi.append(list(map(int, input().split())))

  ans = 0
  for com in list(itertools.combinations_with_replacement(all_num, N)):
    tmp_ans = 0
    if com != tuple(sorted(com)):
      continue
    for q in q_kumi:
      if com[q[1]-1] - com[q[0]-1] == q[2]:
        tmp_ans += q[3]
    ans = max(ans, tmp_ans)
  print(ans)

if __name__ == '__main__':
  main()

import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

import itertools

def main():
  N, M, Q = map(int, input().split())
  all_num = [i for i in range(1, M+1)]
  q_kumi = []
  for i in range(Q):
    q_kumi.append(list(map(int, input().split())))

  ans = 0
  for com in list(itertools.combinations_with_replacement(all_num, N)):
    tmp_ans = 0
    if com != tuple(sorted(com)):
      continue
    for q in q_kumi:
      if com[q[1]-1] - com[q[0]-1] == q[2]:
        tmp_ans += q[3]
    ans = max(ans, tmp_ans)
  print(ans)

if __name__ == '__main__':
  main()

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

def main():
    n,m,q = map(int,input().split())
    a = [0] * (q+1)
    b = [0] * (q+1)
    c = [0] * (q+1)
    d = [0] * (q+1)

    for i in range(1,q+1):
        a[i],b[i],c[i],d[i] = map(int,input().split())

    Alist = itertools.combinations_with_replacement(range(1,m+1),n)

    ans = 0
    print(a,b,c,d)
    for A in Alist:
        cnt = 0
        for i in range(1,q+1):
            if A[b[i]-1] - A[a[i]-1] == c[i]:
                cnt += d[i]
        ans = max(ans,cnt)
    print(ans)


if __name__ == "__main__":
    main()


import itertools

def main():
    n,m,q = map(int,input().split())
    a = [0] * (q+1)
    b = [0] * (q+1)
    c = [0] * (q+1)
    d = [0] * (q+1)

    for i in range(1,q+1):
        a[i],b[i],c[i],d[i] = map(int,input().split())

    Alist = itertools.combinations_with_replacement(range(1,m+1),n)

    ans = 0
    for A in Alist:
        cnt = 0
        for i in range(1,q+1):
            if A[b[i]-1] - A[a[i]-1] == c[i]:
                cnt += d[i]
        ans = max(ans,cnt)
    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):
from itertools import combinations_with_replacement
import numpy as np

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

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

ans = 0




A = np.array(list(itertools.combinations_with_replacement(range(1, M + 1), N)))
scores = np.zeros(len(A))
for g in G:
    a, b, c, d = g
    cond = A[:, b - 1] - A[:, a - 1] == c
    scores += d * cond

print(scores.max())

import itertools
import numpy as np

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

A_cands = np.array(list(itertools.combinations_with_replacement(list(range(1, M+1)), N)))      

scores = np.zeros(len(A_cands), dtype=np.int64)

for i in range(Q):
    a, b, c, d = G[i]
    cond = A_cands[:, b - 1] - A_cands[:, a - 1] == c
    scores += cond * d
print(scores.max())

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 = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

A_list = list(itertools.combinations_with_replacement(range(1,m),n))

ans = 0
for A in A_list:
    sum = 0
    for a,b,c,d in abcd:
        if A[b-1] - A[a-1] == c:
            sum += d
    ans = max(ans, sum)

print(ans)

import itertools

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

A_list = list(itertools.combinations_with_replacement(range(1,m+1),n))

ans = 0
for A in A_list:
    sum = 0
    for a,b,c,d in abcd:
        if A[b-1] - A[a-1] == c:
            sum += d
    ans = max(ans, sum)

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 itertools
N,M,Q = map(int, input().split())
cand = list(itertools.combinations_with_replacement(N+M-1,N))
fs = [list(map(int, input().split())) for i in range(Q)]

def calc(fs,As):
  count = 0
  for a,b,c,d in fs:
    if As[b-1] - As[a-1] == a:
      count += d
	return count
ans = 0
for As in cand:
  ans = max(ans,calc(fs,As))

print(ans)

from itertools import combinations_with_replacement as cw
N,M,Q = map(int, input().split())
cand = cw([i+1 for i in range(M)],N)
fs = [list(map(int, input().split())) for i in range(Q)]

def calc(fs,As):
  count = 0
  for a,b,c,d in fs:
    if As[b-1] - As[a-1] == c:
      count += d
  return count
ans = 0
for As in cand:
  ans = max(ans,calc(fs,As))

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 = [int(x) for x in input().split()]
 
tmp = []
for i in range(q):
    a, b, c, d = [int(x) for x in input().split()]
    tmp.append([a, b, c, d])

t = list(itertools.combinations_with_replacement(range(1, m + 1), n))

score = 0
for _t in t:
    _s = 0
    for a, b, c, d in tmp:
        if len(_t) <= a or len(_t) <= b:
            continue
        if c == _t[b - 1] - _t[a - 1]:
            _s += d
    score = max(_s, score)
print(score)

n, m, q = [int(x) for x in input().split()]

t = [sorted(x) for x in list(itertools.product(range(1, m + 1), repeat=(m-1)))]
t = list(map(list, set(map(tuple, t))))

tmp = []
for i in range(q):
    a, b, c, d = [int(x) for x in input().split()]
    tmp.append([a, b, c, d])

score = 0
for _t in t:
    _s = 0
    for a, b, c, d in tmp:
        if c == _t[b - 1] - _t[a - 1]:
            _s += d
    score = max(_s, score)
print(score)

import itertools

n, m, q = [int(x) for x in input().split()]
 
tmp = []
for i in range(q):
    a, b, c, d = [int(x) for x in input().split()]
    tmp.append([a, b, c, d])

t = list(itertools.combinations_with_replacement(range(1, m + 1), n))

score = 0
for _t in t:
    _s = 0
    for a, b, c, d in tmp:
        if c == _t[b - 1] - _t[a - 1]:
            _s += d
    score = max(_s, score)
print(score)

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):
N,M,Q=map(int,input().split())
v=[[] for _ in range(Q)]
o=0
for i in range(Q):
    v[i]=list(map(int,input().split()))
l=list(itertools.combinations(range(M+N), N))
for x in l:
    s=0
    a=[]
    for i in range(N):
        a.append(x[i]-i)
    for i in range(Q):
        if a[l[i][2]]-a[l[i][1]]-l[i][3]==0:
            s+=l[i][4]
    if s>o:
        o=s
print(o)

import itertools
from collections import deque
N,M,Q=map(int,input().split())
a=deque([])
b=a
c=a
d=a
o=0
for i in range(Q):
    u,v,x,y=map(int,input().split())
    a.append(u)
    b.append(v)
    c.append(x)
    d.append(y)
l=list(itertools.combinations(range(M+N), N))
for x in l:
    e=a
    f=b
    g=c
    h=d
    s=0
    u=[]
    for i in range(N):
        u.append(x[i]-i)
    for i in range(Q):
        if u[f[0]-1]-u[e[0]-1]-g[0]==0:
            s+=h[0]
            e.popleft()
            f.popleft()
            g.popleft()
            h.popleft()
    if s>o:
        o=s
print(o)

import itertools
N,M,Q=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
s=0
o=0
for i in range(Q):
    u,v,x,y=map(int,input().split())
    a.append(u)
    b.append(v)
    c.append(x)
    d.append(y)
for k in range(M):
    l=list(itertools.combinations(range(k+N), N))
    for x in l:
        s=0
        h=[]
        for i in range(N):
            h.append(x[i]-i)
        for i in range(Q):
            if h[a[i]]-h[b[i]]==c[i]:
                s+=d[i]
    if o<s:
        o=s
print(o)


import itertools
N,M,Q=map(int,input().split())
v=[[] for _ in range(Q)]
o=0
for i in range(Q):
    v[i]=list(map(int,input().split()))
l=list(itertools.combinations(range(M-1+N), N))
for x in l:
    s=0
    a=[]
    for i in range(N):
        a.append(x[i]-i+1)
    for i in range(Q):
        if a[v[i][1]-1]-a[v[i][0]-1]-v[i][2]==0:
            s+=v[i][3]
    if s>o:
        o=s
print(o)

Verdicts: Runtime Error

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):
import itertools

n,m,q = map(int,input().split())
mylist = [list(map(int, input().split())) for i in range(q)]
#print(mylist)

kouho = []
for i in range(1, m+1):
  kouho.append(i)


A = list(itertools.combinations(kouho,n))
#print(A)

point = 0
maxp = 0
for a in A:
  point = 0
  #print(a)
  for my in mylist:
    #print(my)
    if a[my[1]-1] - a[my[0]-1] == my[2]:
      point += my[3]
      print("yes")
  print(point)
  if point > maxp:
    maxp = point
    print("max更新")
    print(maxp)
print(maxp)
    



import itertools

n,m,q = map(int,input().split())
mylist = [list(map(int, input().split())) for i in range(q)]
#print(mylist)

kouho = []
for i in range(1, m+1):
  kouho.append(i)


A = list(itertools.combinations_with_replacement(kouho,n))
#print(A)

point = 0
maxp = 0
for a in A:
  point = 0
  #print(a)
  for my in mylist:
    #print(my)
    #print(a[my[1]-1] - a[my[0]-1])
    #print(my[2])
    #print("")
    if a[my[1]-1] - a[my[0]-1] == my[2]:
      point += my[3]
      #print("yes")
      #print(point)
  #print(point)
  if point > maxp:
    maxp = point
    
    #print(maxp)
print(maxp)
    



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

#19 choose 9
#92378

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

import itertools

#19 choose 9
#92378

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

import itertools

#19 choose 9
#92378

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

Verdicts: Runtime Error

Runtime Error

Accepted