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):
import itertools
N, M, Q = map(int,input().split())
ABCD = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for s in itertools.combinations_with_replacement(range(1,N+1),N):
    temp = 0
    for i in range(Q):
        if s[ABCD[i][1]-1] - s[ABCD[i][0]-1] == ABCD[i][2]:
            temp += ABCD[i][3]
    ans = max(ans,temp)
print(ans)

import itertools
N, M, Q = map(int,input().split())
ABCD = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for s in itertools.combinations_with_replacement(range(1,M+1),N):
    temp = 0
    for i in range(Q):
        if s[ABCD[i][1]-1] - s[ABCD[i][0]-1] == ABCD[i][2]:
            temp += ABCD[i][3]
    ans = max(ans,temp)
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())
I = list(range(1, m + 1))
A = list(map(list, itertools.combinations(I, n)))
l = len(A)
ans = [0 for i in range(l)]
for _ in range(q):
    a, b, c, d = map(int, input().split())
    for i in range(l):
        if A[i][b - 1] - A[i][a - 1] == c:
            ans[i] += d
print(max(ans))

import itertools

n, m, q = map(int, input().split())
I = list(range(1, m + 1))
A = list(map(list, itertools.combinations_with_replacement(I, n)))
l = len(A)
ans = [0 for i in range(l)]
for _ in range(q):
    a, b, c, d = map(int, input().split())
    for i in range(l):
        if A[i][b - 1] - A[i][a - 1] == c:
            ans[i] += d
print(max(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_with_replacement

n, m, q = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(q)]
def keisan(tup):
    ans_keisan = 0
    print(tup)
    for j in A:
        if tup[j[1]-1] - tup[j[0]-1] == j[2]:
            ans_keisan += j[3]
    return ans_keisan
ans = 0
for i in combinations_with_replacement(range(m),n):
    ans = max(keisan(i), ans)
print(ans)

from itertools import combinations_with_replacement

n, m, q = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(q)]
def keisan(tup):
    ans_keisan = 0
    for j in A:
        if tup[j[1]-1] - tup[j[0]-1] == j[2]:
            ans_keisan += j[3]
    return ans_keisan
ans = 0
for i in combinations_with_replacement(range(m),n):
    ans = max(keisan(i), 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
N, M, Q = map(int,input().split())
L = []
for _ in range(Q):
    L.append(list(map(int,input().split())))

A = itertools.combinations_with_replacement([i for i in range(1,M+1)], N)
count = []
for a in A:
    temp = 0
    for l in l:
        if a[l[1]-1] - a[l[0]-1] == l[2]:
            temp += l[3]
    count.append(temp)
print(max(count))

import itertools
N, M, Q = map(int,input().split())
L = []
for _ in range(Q):
    L.append(list(map(int,input().split())))

A = itertools.combinations_with_replacement([i for i in range(1,M+1)], N)
count = []
for a in A:
    temp = 0
    for l in l:
        if a[l[1]-1] - a[l[0]-1] == l[2]:
            temp += l[3]
    count.append(temp)
print(max(count))

import itertools
N, M, Q = map(int,input().split())
L = []
for _ in range(Q):
    L.append(list(map(int,input().split())))

A = itertools.combinations_with_replacement([i for i in range(1,M+1)], N)
count = []
for a in A:
    temp = 0
    for l in L:
        if a[l[1]-1] - a[l[0]-1] == l[2]:
            temp += l[3]
    count.append(temp)
print(max(count))

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 bisect

def lis(lst):
    lis_lst = [lst[0]]
    for i in lst:
        if i > lis_lst[-1]:
            lis_lst.append(i)
        else:
            lis_lst[bisect.bisect_left(lis_lst, i)] = i
    return len(lis_lst)

n = int(input())

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

uv = {}
for _ in range(n-1):
    u, v = map(int, input().split())
    uv[v] = u
    
for i in range(1, n + 1):
    lst = []    
    while i != 1:
        lst.append(a[i - 1])
        i = uv[i]
    lst.append(a[0])
    lst.reverse()
    print(lis(lst))

import itertools

n, m, q = map(int, input().split())
lst = []
for _ in range(q):
    item = list(map(int, input().split()))
    lst.append(item)

max_num = 0
for num_lst in itertools.combinations_with_replacement(range(1, m + 1), n):
    count = 0
    for a, b, c, d in lst:
        if num_lst[b - 1] - num_lst[a - 1] == c:
            count += d
    max_num = max(max_num, count)
print(max_num)

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
readline = sys.stdin.readline

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

def dfs(A):
    if len(A)==n:
        return score(A)
    ans = 0
    prev_last = A[-1] if len(A)>0 else 0
    for v in range(prev_last, m):
        A.append(v)
        ans = max(ans, dfs(A))
        A.pop()
    return ans

n, m, q = map(int, readline().split())
A,B,C,D = [0]*q, [0]*q, [0]*q, [0]*q
for i in range(q):
    a,b,C[i],D[i] = map(int, readline().split())
    A[i] = a-1
    B[i] = b-1

print(dfs([]))

import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**6)

def score(Ans):
    t = 0
    for ai,bi,ci,di in zip(A,B,C,D):
        if Ans[bi]-Ans[ai]==ci:
            t += di
    return t

def dfs(Ans):
    if len(Ans)==n:
        return score(Ans)
    ans = 0
    prev_last = Ans[-1] if len(Ans)>0 else 0
    for v in range(prev_last, m):
        Ans.append(v)
        ans = max(ans, dfs(Ans))
        Ans.pop()
    return ans

n, m, q = map(int, readline().split())
A,B,C,D = [0]*q, [0]*q, [0]*q, [0]*q
for i in range(q):
    a,b,C[i],D[i] = map(int, readline().split())
    A[i] = a-1
    B[i] = b-1

print(dfs([]))

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())
li=[list(map(int,input().split()))for _ in range(q)]
ans = 0
def dfs(i,A):
    global ans 
    if i == m:
        return
    tmp = 0
    for a,b,c,d in li:
        if A[b-1] - A[a-1] == c:
            tmp += d 
    ans = max(ans,tmp)
    tmp = A[:]
    for j in range(n):
        tmp = A[:]
        for k in range(1,j+2):
            tmp[-k] += 1
        dfs(i+1,tmp)
dfs(1,[1]*n)
print(ans)

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

ans = 0
def dfs(A):
    #print(A)
    global ans 
    if len(A) == n+1:
        tmp = 0
        for a,b,c,d in li:
            if A[b] - A[a] == c:
                tmp += d
            ans = max(ans,tmp)
        return
    for i in range(A[len(A)-1],m+1):
        dfs(A+[i])
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):
# -*- coding: utf-8 -*-
from itertools import itertools.combinations_with_replacement
N,M,Q=map(int,input().split())
abcd=[]
for _ in range(Q):
    abcd.append(tuple(map(int,input().split())))
Abase=[]
for a in range(1,M+1):
    Abase=Abase+[a]
A=set(itertools.combinations_with_replacement(Abase,N))
ans=0
for i in A:
    temp=0
    for j in abcd:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            temp=temp+j[3]
    if temp>=ans:
        ans=temp
print(ans)

# -*- coding: utf-8 -*-
from itertools import itertools_with_replacement
N,M,Q=map(int,input().split())
abcd=[]
for _ in range(Q):
    abcd.append(tuple(map(int,input().split())))
Abase=[]
for a in range(1,M+1):
    Abase=Abase+[a]
A=set(itertools.combinations_with_replacement(Abase,N))
ans=0
for i in A:
    temp=0
    for j in abcd:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            temp=temp+j[3]
    if temp>=ans:
        ans=temp
print(ans)

# -*- coding: utf-8 -*-
from itertools import itertools_with_replacement
N,M,Q=map(int,input().split())
abcd=[]
for _ in range(Q):
    abcd.append(tuple(map(int,input().split())))
Abase=[]
for a in range(1,M+1):
    Abase=Abase+[a]
A=set(itertools.combinations_with_replacement(Abase,N))
ans=0
for i in A:
    temp=0
    for j in abcd:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            temp=temp+j[3]
    if temp>=ans:
        ans=temp
print(ans)

# -*- coding: utf-8 -*-
from itertools import combinations_with_replacement as comb
N,M,Q=map(int,input().split())
abcd=[]
for _ in range(Q):
    abcd.append(tuple(map(int,input().split())))
Abase=[]
for a in range(1,M+1):
    Abase=Abase+[a]
A=set(comb(Abase,N))
ans=0
for i in A:
    temp=0
    for j in abcd:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            temp=temp+j[3]
    if temp>=ans:
        ans=temp
print(ans)

Verdicts: Runtime Error

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 combinations_with_replacement
N, M, Q = [int(n) for n in input().split()]
X = [[int(n) for n in input().split()] for _ in range(Q)]
ans = []
for A in combinations_with_replacement(range(1, M+1), N):
    t = 0
    for x in X:
        if A[x[1]-1]-A[x[0]-1] == x[2]:
            t += x[3]
    print(A, t)
    ans.append(t)
print(max(ans))


N, M, Q = [int(n) for n in input().split()]
a, b, c, d = [list(x) for x in zip(*[[int(n) for n in input().split()] for _ in range(Q)])]
ans = 0

def dfs(A):
    global ans
    if len(A) == N:
        now = 0
        for i in range(Q):
            if A[b[i]-1] - A[a[i]-1] == c[i]: now += d[i]
        ans = max(ans, now)
        return

    for v in range(A[-1], M+1):
        A.append(v)
        dfs(A)
        A.pop()

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):
def resolve():
    n, m, q = map(int, input().split())
    queue = []
    for i in range(q):
        queue.append(list(map(int, input().split())))
    ans = 0
    import itertools
    l = list(itertools.combinations(range(1, n + m), m))
    for i in l:
        a = [x - y for y, x in enumerate(i)]
        x = 0
        for j in queue:
            if a[j[1] - 1] - a[j[0] - 1] == j[2]:
                x += j[3]
        ans = max(ans, x)
    print(ans)


if __name__ == '__main__':
    resolve()


def resolve():
    n, m, q = map(int, input().split())
    queue = []
    for i in range(q):
        queue.append(list(map(int, input().split())))
    ans = 0
    import itertools
    l = itertools.combinations(range(1, n + m), n)
    for i in l:
        a = [x - y for y, x in enumerate(i)]
        x = 0
        for j in queue:
            if a[j[1] - 1] - a[j[0] - 1] == j[2]:
                x += j[3]
        ans = max(ans, x)
    print(ans)


if __name__ == '__main__':
    resolve()


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


def main():
    n_ints, max_int, n_queries = map(int, input().split())

    queries = (list(map(int, input().split())) for _ in range(n_queries))

    possible_sequences = combinations_with_replacement(range(1, max_int+1), n_ints)

    max_score = 0
    for sequence in possible_sequences:
        score = 0

        for i, q in enumerate(queries):
            a, b, c, d = q
            if sequence[b-1] - sequence[a-1] == c:
                score += d

        max_score = max(max_score, score)

    print(max_score)


if __name__ == "__main__":
    main()


from itertools import combinations_with_replacement


def main():
    n_ints, max_int, n_queries = map(int, input().split())

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

    possible_sequences = combinations_with_replacement(range(1, max_int+1), n_ints)

    max_score = 0
    for sequence in possible_sequences:
        score = 0

        for i, q in enumerate(queries):
            a, b, c, d = q
            if sequence[a-1] - sequence[b-1] == c:
                score += d

        max_score = max(max_score, score)

    print(max_score)


if __name__ == "__main__":
    main()


import sys
from itertools import combinations_with_replacement

input = sys.stdin.buffer.readline


def main():
    n_ints, max_int, n_queries = map(int, input().split())

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

    possible_sequences = combinations_with_replacement(range(1, max_int+1), n_ints)

    max_score = 0
    for sequence in possible_sequences:
        score = 0

        for i, q in enumerate(queries):
            a, b, c, d = q
            if sequence[b-1] - sequence[a-1] == c:
                score += d

        max_score = max(max_score, score)

    print(max_score)


if __name__ == "__main__":
    main()


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):
N,M,Q = map(int,input().split())
li = []
counter = 0
n = []
for s in range(Q):
  li.append(list(map(int,input().strip())))

for i in range(10**(N-1),10**N):
  k = str(i)
  for q in range(Q):
    if k[li[q][1]] -  k[li[q][0]] ==  k[li[q][2]]:
      counter +=  k[li[q][3]]
    n.append(counter)
    counter = 0
print(max(n))

N,M,Q = map(int,input().split())
li = []
counter = 0
n = []
for s in range(Q):
  li.append(list(map(int,input().strip())))

for i in range(10**(N-1),10**N):
  k = str(i)
  for q in range(Q):
    if k[li[q][1]] -  k[li[q][0]] ==  k[li[q][2]]:
      counter +=  k[li[q][3]]
    n.append(counter)
    counter = 0
print(max)

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

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

from itertools import combinations_with_replacement
counter = []

for comb in combinations_with_replacement(range(1,M+1),N):
    A = list(comb)
    tmp = 0
   
    for i in li:
        if A[i[1]-1] - A[i[0]-1] == i[2]:
            tmp += i[3]

    counter.append(tmp)


print(max(counter))

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 as it

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

ar = [[0]*4]*q

for i in range(q):
    ar[i] = [int(s) for s in input().split()]

A = it.combinations_with_replacement(list(range(1,m+1)),n)
mx = 0

for cnd in A:
    mx_tmp=0
    for i in range(q):
        if(A[ar[i][1]-1] - A[ar[i][0]-1] == ar[i][2]):
            mx_tmp += ar[i][3]
    mx = max(mx,mx_tmp)

print(mx)

import itertools as it

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

ar = [[0]*4]*q

for i in range(q):
    ar[i] = [int(s) for s in input().split()]

A = list(it.combinations_with_replacement(list(range(1,m+1)),n))
mx = 0

for cnd in A:
    mx_tmp=0
    for i in range(q):
        if(cnd[ar[i][1]-1] - cnd[ar[i][0]-1] == ar[i][2]):
            mx_tmp += ar[i][3]
    mx = max(mx,mx_tmp)

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 itertools as itr
N,M,Q = map(int,input().split())
sheat = list()
for i in range(Q):
    sheat.append(list(map(int,input().split())))

comb = tuple(itr.combinations(range(1,M+1),N))
Maxsum = 0
print(sheat)
print(comb)
sumd = 0
for i in range(len(comb)):
    ansum = 0
    for j in range(Q):
        if(comb[i][sheat[j][1]-1]-comb[i][sheat[j][0]-1] == sheat[j][2]):
            ansum += sheat[j][3]
           
    if(Maxsum < ansum):
        Maxsum = ansum
    # print(ansum)
print(Maxsum)      

#     sumd += sheat[i][3]
# print(sumd)
#nCm

#A_1,A_2,A_3,...A_n,M




#      2:3 - 1 = 2o  10     [1,2,2]
#      3:4 - 3 = 1*  10     [2,3,2]
#                   110


import itertools as itr
N,M,Q = map(int,input().split())
sheat = list()
for i in range(Q):
    sheat.append(list(map(int,input().split())))

comb = tuple(itr.combinations_with_replacement(range(1,M+1),N))
Maxsum = 0
# print(sheat)
# print(comb)
sumd = 0
for i in range(len(comb)):
    ansum = 0
    for j in range(Q):
        if(comb[i][sheat[j][1]-1]-comb[i][sheat[j][0]-1] == sheat[j][2]):
            ansum += sheat[j][3]
           
    if(Maxsum < ansum):
        Maxsum = ansum
    # print(ansum)
print(Maxsum)      

#     sumd += sheat[i][3]
# print(sumd)
#nCm

#A_1,A_2,A_3,...A_n,M




#      2:3 - 1 = 2o  10     [1,2,2]
#      3:4 - 3 = 1*  10     [2,3,2]
#                   110


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
import itertools
def main():
    n, m, q = map(int, input().split())
    matrix = []
    for _ in range(q):
        row = list(map(int, input().split()))
        matrix.append(row)
    # print(matrix)
    A = list(range(1, m))
    ans = 0
    for tmp_A in itertools.combinations_with_replacement(A, n):
        tmp_A = sorted(list(tmp_A))
        tmp_ans = 0
        for row in matrix:
            # print("row", row)
            # print("tmp_A", tmp_A)
            tmp = tmp_A[row[1] - 1] - tmp_A[row[0]- 1]
            if row[2] == tmp:
                tmp_ans += row[3]
        if tmp_ans >= ans:
            ans = tmp_ans
            
    print(ans)
    
main()

# coding: utf-8
import itertools
def main():
    n, m, q = map(int, input().split())
    matrix = []
    for _ in range(q):
        row = list(map(int, input().split()))
        matrix.append(row)
    # print(matrix)
    A = list(range(1, m+1))
    ans = 0
    for tmp_A in itertools.combinations_with_replacement(A, n):
        tmp_A = sorted(list(tmp_A))
        tmp_ans = 0
        for row in matrix:
            # print("row", row)
            # print("tmp_A", tmp_A)
            tmp = tmp_A[row[1] - 1] - tmp_A[row[0]- 1]
            if row[2] == tmp:
                tmp_ans += row[3]
        if tmp_ans >= ans:
            ans = tmp_ans
            
    print(ans)
    
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):
#166d
x = int(input())
for i in range(-73,73):
    for j in range(-73,73):
        print(i,j)
        if i**5-j**5==x:
            a = i
            b = j
            break
        
print(a,b)

from itertools import combinations_with_replacement

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

ans = 0
for c in combinations_with_replacement(range(1,m+1),n):
    v = 0
    for s in s_list:
        if c[s[1]-1] - c[s[0]-1] == s[2]:
            v+=s[3]
    
    ans = max(ans,v)
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 = map(int, input().split())
list_ = [list(map(int, input().split())) for _ in range(q)]
tmp = list(range(1,m+1))
cases = [sorted(list(arr)) for arr in itertools.product(tmp, repeat=n)]

max_score = 0
visited = set()
for arr in cases:
  score = 0
  if str(arr) in visited:
    break
  visited.add(str(arr))
  for arr_2 in list_:
    if arr[arr_2[1]-1] - arr[arr_2[0]-1] == arr_2[2]:
      score+=arr_2[3]
  max_score = max(max_score, score)
print(max_score)

import itertools

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

num=1
seed = [[i] for i in range(1,m+1)]
while num!=n:
  num+=1
  tmp_list = []
  while seed:
    tmp = seed.pop()
    for i in range(tmp[-1],m+1):
      tmp_list.append(tmp+[i])
  seed = tmp_list.copy()

max_score = 0
visited = set()
for arr in seed:
  score = 0
  for arr_2 in list_:
    if arr[arr_2[1]-1] - arr[arr_2[0]-1] == arr_2[2]:
      score+=arr_2[3]
      max_score = max(max_score, score)
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):
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 sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))
n,m,q = I2()
r = []
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
ans = []
import copy
def dfs(A):
    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.append(now)
        return
    A.append(A[-1])
    while (A[-1] <= m):
        dfs(copy.copy(A))
        A[-1] += 1
if __name__ == "__main__":
    for i in range(q):
        a[i],b[i],c[i],d[i] = I2()
    dfs([1])
    print(max(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 sys
n, m, q = map(int, input().split())
alis, blis, clis, dlis = [], [], [], []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    alis.append(a)
    blis.append(b)
    clis.append(c)
    dlis.append(d)
sys.setrecursionlimit(10**9)
Alist = [] 
def dfs(A):
    if len(A)==(n+1):
        Alist.append(A)
        return
    for i in range(A[-1], m+1):
        A.append(i)
        dfs(A)

dfs([1])

ans = 0
for A in Alist:
    score = 0
    for i in range(q):
        if A[blis[i]] - A[alis[i]] == clis[i]:
            score += dlis[i]
    ans = max(ans, score)

print(ans)

import sys
n, m, q = map(int, input().split())
alis, blis, clis, dlis = [], [], [], []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    alis.append(a)
    blis.append(b)
    clis.append(c)
    dlis.append(d)
sys.setrecursionlimit(10**9)
Alist = [] 
def dfs(A):
    if len(A)==(n+1):
        Alist.append(A)
        return
    for i in range(A[-1], m+1):
        dfs(A+[i])

dfs([1])

ans = 0
for A in Alist:
    score = 0
    for i in range(q):
        if A[blis[i]] - A[alis[i]] == clis[i]:
            score += dlis[i]
    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):
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())
    a[i] -= 1  
    b[i] -= 1  

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

def dfs(A):
    if len(A) == N:
        return score(A)
    res = 0
    prev_last = A[-1] if len(A) > 0 else 0
    for v in range(prev_last, M):
        A.append(v)
        res = max(res, dfs(A))
        A.pop()
    return res

print(dfs([]))

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())
    a[i] -= 1  
    b[i] -= 1  

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

def dfs(A):
    if len(A) == N:
        return score(A)
    res = 0
    prev_last = A[-1] if len(A) > 0 else 0
    for v in range(prev_last, M):
        A.append(v)
        res = max(res, dfs(A))
        A.pop()
    return res

print(dfs([]))

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

n, m, q = map(int, input().split())
a = np.zeros(q, type=int)
b = np.zeros(q, type=int)
c = np.zeros(q, type=int)
d = np.zeros(q, type=int)

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

A = np.array(list(itertools.combinations_with_replacement(range(1, m + 1), n)))

cnt = 0

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

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())

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

cnt = 0

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

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())

a = [0] * 55; b = [0] * 55; c = [0] * 55; d = [0] * 55

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

def socer(A):
    now = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]: now += d[i]
    return now

def dfs(A):
    print(A)
    if len(A) == n: return socer(A)
    res = 0
    last = A[-1] if A else 0
    for i in range(last, m):
        A.append(i)
        res = max(res, dfs(A))
        A.pop()
    return res
      
print(dfs([]))

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

a = [0] * 55; b = [0] * 55; c = [0] * 55; d = [0] * 55

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

def socer(A):
    now = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]: now += d[i]
    return now

def dfs(A):
    # print(A)
    if len(A) == n: return socer(A)
    res = 0
    last = A[-1] if A else 0
    for i in range(last, m):
        A.append(i)
        res = max(res, dfs(A))
        A.pop()
    return res
      
print(dfs([]))

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())
all=[]
 
for i in range(Q):
  all.append(list(map(int,input().split())))
#print(all)
#print(len(all))
#print(all[0][1])
 
x=sorted([i for i in range(1,M+1)])
maxdsum=0
 
 
for A in itertools.combinations_with_replacement(x, N):
  dsum=0
  "print("A=="+str(A))
  for num in range(Q):
    if A[all[num][1]-1]-A[all[num][0]-1]==all[num][2]:
      dsum+=all[num][3]
  if maxdsum<dsum:
    maxdsum=dsum
print(maxdsum)

import itertools
 
N,M,Q=map(int,input().split())
all=[]
for i in range(Q):
  all.append(list(map(int,input().split()))
 
x=[i for i in range(1,M+1)]
maxdsum=0
 
for A in itertools.combinations_with_replacement(x, N):
  dsum=0
  for num in range(Q):
    if A[all[num][1]-1]-A[all[num][0]-1]==all[num][2]:
      dsum+=all[num][3]
  if maxdsum<dsum:
    maxdsum=dsum
print(maxdsum)

import itertools
 
N,M,Q=map(int,input().split())
all=[]
for i in range(Q):
  all.append(list(map(int,input().split())))
 
x=[i for i in range(1,M+1)]
maxdsum=0
 
for A in itertools.combinations_with_replacement(x, N):
  dsum=0
  for num in range(Q):
    if A[all[num][1]-1]-A[all[num][0]-1]==all[num][2]:
      dsum+=all[num][3]
  if maxdsum<dsum:
    maxdsum=dsum
print(maxdsum)

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

import itertools
a = range(1, M+1)
for set_A in itertools.combinations_with_replacement(a, N):
    A = list(set_A)
    print(A)
    n = 0
    for i in range(Q):
        if A[b[i][1]-1] - A[b[i][0]-1] == b[i][2]:
            n += b[i][3]
    ans = max(ans, n)
print(ans)

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

import itertools
a = range(1, M+1)
for set_A in itertools.combinations_with_replacement(a, N):
    A = list(set_A)
    n = 0
    for i in range(Q):
        if A[b[i][1]-1] - A[b[i][0]-1] == b[i][2]:
            n += b[i][3]
    ans = max(ans, n)
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] * 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())
A_list = []
for p in itertools.combinations_with_replacement(range(1,m+1),n):
    A_list.append(p)
# print(A_list)

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

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())
A_list = []
for p in itertools.combinations_with_replacement(range(1,m+1),n):
    A_list.append(p)
# print(A_list)

ans = 0
for v in A_list:
    cur_score = 0
    for i in range(q):
        if v[b[i]-1] - v[a[i]-1] == c[i]:
            cur_score += d[i]
    ans = max(ans,cur_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):
import numpy as np
import itertools


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

vals = []
for i in range(Q):
    vals.append([list(map(int, input().split(" ")))])
    
maxv = 0
cand = list(itertools.combinations_with_replacement(range(1, M+1), N))
for c in cand:
    sumv = 0
    for v in vals:
        if (c[v[1]-1] - c[v[0]-1]) == v[2]:
            sumv += v[3]
    if maxv < sumv:
        maxv = sumv
print(maxv)

import numpy as np
import itertools


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

vals = []
for i in range(Q):
    vals.append(list(map(int, input().split(" "))))
    
maxv = 0
cand = list(itertools.combinations_with_replacement(range(1, M+1), N))
for c in cand:
    sumv = 0
    for v in vals:
        if (c[v[1]-1] - c[v[0]-1]) == v[2]:
            sumv += v[3]
    if maxv < sumv:
        maxv = sumv
print(maxv)

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
N, M, Q = map(int,input().split())
P = [list(map(int,input().split())) for i in range(Q)]

A = list(itertools.combinations(range(1,M+1), 3))
number = len(A)

amount = 0
max_amount = 0
for i in range(number): # 0,1,2,3 A
    for j in range(Q): # 0,1,2
        bi = P[j][1]
        ai = P[j][0]
        
        if(A[i][bi-1] - A[i][ai-1] == P[j][2]):
            amount += P[j][3]
    
   # print(amount)
    if(amount >= max_amount):
        max_amount = amount
    
    amount = 0
    
print(max_amount)

from itertools import combinations
N, M, Q = map(int,input().split())
P = [list(map(int,input().split())) for i in range(Q)]

A = list(itertools.combinations(range(1,M+1), N))
number = len(A)

amount = 0
max_amount = 0
for i in range(number): # 0,1,2,3 A
    
    for j in range(Q): # 0,1,2
        bi = P[j][1]
        ai = P[j][0]
        
        
        if(A[i][bi-1] - A[i][ai-1] == P[j][2]):
            amount += P[j][3]
    
   # print(amount)
    if(amount >= max_amount):
        max_amount = amount
    
    amount = 0
    
print(max_amount)

from itertools import combinations
N, M, Q = map(int,input().split())
P = [list(map(int,input().split())) for i in range(Q)]

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

amount = 0
max_amount = 0
for i in range(number): #A
    
    for j in range(Q): # P
        bi = P[j][1]
        ai = P[j][0]
        if(A[i][bi-1] - A[i][ai-1] == P[j][2]):
            amount += P[j][3]
        
   # print(amount)
    
   # print(amount)
    if(amount >= max_amount):
        max_amount = amount
    
    amount = 0
    
print(max_amount)

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

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

amount = 0
max_amount = 0
for i in range(number): #A
    
    for j in range(Q): # P
        bi = P[j][1]
        ai = P[j][0]
        if(A[i][bi-1] - A[i][ai-1] == P[j][2]):
            amount += P[j][3]
        
   # print(amount)
    
   # print(amount)
    if(amount >= max_amount):
        max_amount = amount
    
    amount = 0
    
print(max_amount)

Verdicts: Runtime Error

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):
mport itertools
def main():
    N, M, Q = map(int, input().split())
    abcd = []
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        abcd.append((a-1, b-1, c, d))
    score = 0
    for ones in list(itertools.combinations([i for i in range(N+M-1)], M-1)):
        temp = [0] * (N + M -1)
        for idx in ones:
            temp[idx] = 1
        A = [0] * N
        idx = 0
        sum_ = 0
        for i in temp:
            if i == 0:
                A[idx] = sum_ + 1
                idx += 1
            else:
                sum_ += 1
        score_temp = get_score(A, abcd)
        if score_temp > score:
            score = score_temp
    print(score)
            

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

if __name__ == '__main__':
    main()

import itertools
def main():
    N, M, Q = map(int, input().split())
    abcd = []
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        abcd.append((a-1, b-1, c, d))
    score = 0
    for ones in list(itertools.combinations([i for i in range(N+M-1)], M-1)):
        temp = [0] * (N + M -1)
        for idx in ones:
            temp[idx] = 1
        A = [0] * N
        idx = 0
        sum_ = 0
        for i in temp:
            if i == 0:
                A[idx] = sum_ + 1
                idx += 1
            else:
                sum_ += 1
        score_temp = get_score(A, abcd)
        if score_temp > score:
            score = score_temp
    print(score)
            
def get_score(A, abcd):
    score = 0
    for a, b, c, d in abcd:
        if A[b] - A[a] == c:
            score += d
    return score

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):
N, M, Q = (int(i) for i in input().split())  
ABCD = []
ans = -1

for _ in range(Q):
  ABCD.append([int(i) for i in input().split()] )

comb_list = []

import sys
sys.setrecursionlimit(100000000)
def recur(N, lis, c):
  if len(lis) == N:
    comb_list.append(lis)
    return

  if lis == []:
    for i in range(1, N+1):
      recur(N, [i], c+1)
  else:
    for i in range(lis[c], N+1):
      recur(N, lis + [i], c+1)     

recur(N, [], -1)
for x in comb_list:
    tmp = 0
    for a, b, c, d in ABCD:
        if x[b-1] - x[a-1] == c:
             tmp += d
                
    ans = max(ans, tmp)   
print(ans)

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

for _ in range(Q):
  ABCD.append([int(i) for i in input().split()] )

comb_list = []

import sys
sys.setrecursionlimit(100000000)
def recur(N, lis, c):
  if len(lis) == N:
    comb_list.append(lis)
    return

  if lis == []:
    for i in range(1, M+1):
      recur(N, [i], c+1)
  else:
    for i in range(lis[c], M+1):
      recur(N, lis + [i], c+1)     

recur(N, [], -1)
for x in comb_list:
    tmp = 0
    for a, b, c, d in ABCD:
        if x[b-1] - x[a-1] == c:
             tmp += d           
    ans = max(ans, tmp)   
print(ans)

Verdicts: Wrong Answer

Accepted