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


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

choices = list(itertools.combinations_with_replacement([i for i in range(1, m+1)], n))
ans = -1
for choice in choices:
    score = 0
    for q in query:
        if choice[q[1]-1] - choice[q[0]-1] == q[2]:
            score += q[3]
    ans = max(ans, score)
print(ans)


import itertools


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

choices = list(itertools.combinations_with_replacement([i for i in range(1, m+1)], n))
ans = -1
for choice in choices:
    score = 0
    for q in query:
        if choice[q[1]-1] - choice[q[0]-1] == q[2]:
            score += q[3]
    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())
ABCD = [list(map(int, input().split())) for i in range(Q)]
score=0
for i in range(1, M+1):
  dfs([i])
print(score)


def dfs(l):
    
    if judge_end(l,N):
        global score
        
        tmp_score = calc_score(ABCD,l)
        score = max(tmp_score, score)
        return
    else:
        
        nexts = listup_next(l[-1], M)
        for x in nexts:
            dfs(num_list+[x])


def judge_end(l,N):
    return len(l)==N


def calc_score(ABCD, l):
    s=0
    for a,b,c,d in ABCD:
      if l[b-1] - l[a-1] ==c:
        s+=d
    return s


def listup_next(m, M):
    return range(m,M+1)


def main():
    N, M, Q = map(int, input().split())
    ABCD = [list(map(int, input().split())) for i in range(Q)]
    score = 0

    def dfs(l, **kwargs):
        N = kwargs['N']
        M = kwargs['M']
        ABCD = kwargs['ABCD']

        
        if judge_end(l, N=N):
            nonlocal score
            tmp_score = calc_score(l, ABCD=ABCD)
            score = max(tmp_score, score)
            return
        else:
            
            nexts = listup_next(l[-1], M=M)
            for x in nexts:
                dfs(l+[x], N=N, M=M, ABCD=ABCD)

    def judge_end(l, **kwargs):
        N = kwargs['N']
        return len(l) == N

    def calc_score(l, **kwargs):
        ABCD = kwargs['ABCD']
        s = 0
        for a, b, c, d in ABCD:
            if l[b-1] - l[a-1] == c:
                s += d
        return s

    def listup_next(now, **kwargs):
        m = now
        M = kwargs['M']
        return range(m, M+1)

    for i in range(1, M+1):
        dfs([i], N=N, M=M, ABCD=ABCD)
    print(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=list(map(int,input().split()))

A=[list(map(int,input().split())) for _ in range(Q)]
num=0
for i in A:
  if i[1]-i[0]==i[2]:
    num+=i[3]
    
print(num)

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

A=[list(map(int,input().split())) for _ in range(Q)]
num=0
for i in A:
  if i[1]-i[0]==i[2] and i[3]>0:
    num+=i[3]
    
print(num)

import itertools 
N,M,Q=list(map(int,input().split()))
 
ABCD=[list(map(int,input().split())) for _ in range(Q)]
ans=[]
for i in itertools.combinations_with_replacement(range(1,M+1),N):
  num=0
  for a,b,c,d in ABCD:
    if i[b-1]-i[a-1]==c:
      num+=d
  ans.append(num)
print(max(ans))

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
import sys
from itertools import combinations_with_replacement as cwr
input = sys.stdin.readline

def dfs(n,m):
    adj = {}
    for i in range(1,m+1):
        adj[i] = [j for j in range(i,m+1)]
    
    stack = [[i] for i in range(1,m+1)]
    combs = []
    while stack:
        node = stack.pop()
        if len(node) == n:
            combs.append(node)
        else:
            for child in adj[node[-1]]:
                cand = node+[child]
                stack.append(cand)
    return combs


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

ans = 0
combs = dfs(N,M)
#combs = cwr(range(1,M+1),N)
print(combs)
ans = [0]*(len(combs))
for i,comb in enumerate(combs):
    for a,b,c,d in zip(A,B,C,D):
        if comb[b] - comb[a] ==c:
            ans[i] += d
print(max(ans))



import sys
from itertools import combinations_with_replacement as cwr
input = sys.stdin.readline

def dfs(n,m):
    adj = {}
    for i in range(1,m+1):
        adj[i] = [j for j in range(i,m+1)]
    
    stack = [[i] for i in range(1,m+1)]
    combs = []
    while stack:
        node = stack.pop()
        if len(node) == n:
            combs.append(node)
        else:
            for child in adj[node[-1]]:
                cand = node+[child]
                stack.append(cand)
    return combs


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

ans = 0
combs = dfs(N,M)
#combs = cwr(range(1,M+1),N)
# print(combs)
ans = [0]*(len(combs))
for i,comb in enumerate(combs):
    for a,b,c,d in zip(A,B,C,D):
        if comb[b] - comb[a] ==c:
            ans[i] += d
print(max(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
import numpy as np

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

A = np.array(list(itertools.combinations_with_replacemeent(range(1, M+1), N)))
s = np.zeros(len(A), np.int32)

for i in range(Q):
    a, b, c, d = map(int, input().split())
    s += d * (A[:, b-1] - A[:, a-1] == c)

print(s.max())

import itertools
import numpy as np

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

A = np.array(list(itertools.combinations_with_replacement(range(1, M+1), N)))
s = np.zeros(len(A), np.int32)

for i in range(Q):
    a, b, c, d = map(int, input().split())
    s += d * (A[:, b-1] - A[:, a-1] == c)

print(s.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):
from sys import stdin
from sys import setrecursionlimit
input = stdin.readline

setrecursionlimit(10 ** 9)

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

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

for q in range(Q):
    abcd[q][3] *= - 1

A = [-1 for _ in range(N + 1)]

abcd.sort(key=lambda x: x[1] - x[0])

for q in range(Q):
    a, b, c, d = abcd[q]

    if A[a] == -1:
        if A[b] == -1:
            A[a] = max(1, A[a - 1])
            A[b] = c + A[a]
        else:
            A[a] = max(1, A[b] - c, A[a - 1])
    if A[b] == -1:
        A[b] = c + A[a]

ans = 0

for q in range(Q):
    a, b, c, d = abcd[q]
    if A[b] - A[a] == c:
        ans += d

print(ans * (-1))


from sys import stdin
from itertools import combinations_with_replacement
input = stdin.readline

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

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

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


for s in combinations_with_replacement(s, N):
    num = 0
    for q in range(Q):
        a, b, c, d = abcd[q]
        if s[b - 1] - s[a - 1] == c:
            num += d
    ans = max(ans, num)

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())
abcd = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for com in itertools.combinations_with_replacement(range(1, M + 1), N):
    score = sum([d for a, b, c, d in abcd if com[b-1] - com[a-1] == c])
    if ans < score:
        ans = score
print(ans)


import itertools

n, m, q = map(int, input().split())
abcd = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0
for com in itertools.combinations_with_replacement(range(1, m + 1), n):
    score = sum([d for a, b, c, d in abcd if com[b-1] - com[a-1] == c])
    if ans < score:
        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())
abcd = [list(map(int, input().split())) for _ in range(Q)]

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

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

ans = []
import itertools
for A in itertools.combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for a, b, c, d in abcd:
        if A[b-1] - A[a-1] == c:
            tmp += d
    ans.append(tmp)
print(max(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())
abcd=[]
for _ in range(q):
	a,b,c,d=map(int,input().split())
	abcd.append((a,b,c,d))
ans=0
p=[]
sys.setrecursionlimit(10**6)
def dfs(x):
	if len(x)==n:
		p.append(x)
	else:
		for i in range(m-x[-1]+1):
			dfs(x+[x[-1]+i])
dfs([1])
# import itertools
# p=itertools.combinations_with_replacement(range(1,m+1),n)
for x in p:
	r=0
	for i in range(q):
		if x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]:
			r+=abcd[i][3]
	ans=max(ans,r)
print(ans)

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))
ans=0
p=[]
sys.setrecursionlimit(10**6)
def dfs(x):
	if len(x)==n:
		p.append(x)
	else:
		for i in range(n-x[-1]+1):
			dfs(x+[x[-1]+i])
dfs([1])
# import itertools
# p=itertools.combinations_with_replacement(range(1,m+1),n)
for x in p:
	r=0
	for i in range(q):
		if x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]:
			r+=abcd[i][3]
	ans=max(ans,r)
print(ans)

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))
ans=0
p=[]
import sys
sys.setrecursionlimit(10**6)
def dfs(x):
	if len(x)==n:
		p.append(x)
	else:
		for i in range(m-x[-1]+1):
			dfs(x+[x[-1]+i])
dfs([1])
# import itertools
# p=itertools.combinations_with_replacement(range(1,m+1),n)
for x in p:
	r=0
	for i in range(q):
		if x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]:
			r+=abcd[i][3]
	ans=max(ans,r)
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):
import numpy as np
from itertools import combinations_with_replacement
 
n, m, q = map(int, input().split())

pt = np.array(list(combinations_with_replacement(range(1,m+1), n)))
score = np.zeros(len(pt))

for i in range(q):
    a, b, c, d =map(int, input().split())
    flg = pt[:,b-1] - pt[:,a-1] == c
    score += flg * d
#    print(score)
 
print(score.max())

m, n, q = map(int, input().split())
aa = [0]*q
bb = [0]*q
cc = [0]*q
dd = [0]*q
for i in range(q):
    aa[i],bb[i],cc[i], dd[i] = list(map(int, input().split()))
    
import itertools
ss = set(itertools.permutations([0]*(n-1)+[1]*(m-1)))
score = 0
for tu in ss:
    tmp = 0
    xx = [1]*n
    j = 0
    for t in tu:
        if t == 0:
            j += 1
        if t == 1:
            xx[j] += 1
    for i in range(q):
        if xx[bb[i]-1] - xx[aa[i]-1] ==cc[i]: 
            tmp += dd[i]
    score = max(score, tmp)
print(score)    

import numpy as np
from itertools import combinations_with_replacement
 
n, m, q = map(int, input().split())
 
pt = np.array(list(combinations_with_replacement(range(1,m+1), n)))
score = np.zeros(len(pt))
 
for i in range(q):
    a, b, c, d =map(int, input().split())
    flg = pt[:,b-1] - pt[:,a-1] == c
    score += flg * d
#    print(score)
 
print(int(score.max()))

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 = [int(i) for i in input().split()]
a = []; b = []; c = []; d = []
for _ in range(q):
    l = list(map(int, input().split()))
    a.append(l[0])
    b.append(l[1])
    c.append(l[2])
    d.append(l[3])

ans = 0

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

print(ans)

n,m,q = [int(i) for i in input().split()]
a = []; b = []; c = []; d = []
for _ in range(q):
    l = list(map(int, input().split()))
    a.append(l[0]-1)
    b.append(l[1]-1)
    c.append(l[2])
    d.append(l[3])
    
ans = 0

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

print(ans)

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,m,q = [int(i) for i in readline().split()]
abcd = [[int(i) for i in readline().split()] for _ in range(q)]

ans = 0

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

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

print(ans)

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
n, m, q = map(int, input().split())
lst = []
for _ in range(q):
    lst_tmp = [int(i) for i in input().split()]
    lst.append(lst_tmp)

lst.sort()

ans = 0
A = list(range(1, -n, -1))
A[1] = 1
ref = [0] * (n + 1)

for a, b, c, d in lst:
    if A[b] - A[a] != c:
        if ref[b] < ref[a] + d:
            ans += ref[a] + d - ref[b]
            print('---', a, b, c, ans, ref[a] + d - ref[b], '---', ref[a], d, ref[b], ref)
            ref[b] = ref[a] + d
            A[b] = A[a] + c

for i in lst:
    print(i)
print(A)
print(ref)
print(ans)


import itertools

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

ans = 0

for l in itertools.combinations_with_replacement(range(1, m + 1), n):
    tmp_sum = 0
    for a, b, c, d in lst:
        if l[b - 1] - l[a - 1] == c:
            tmp_sum += d
    if ans < tmp_sum:
        ans = tmp_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):
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())

s = [1] * n
#st[b[i]] - st[a[i]]  = c[i]
num = n-1
ans1 = [0] * 100000000
ans = 0
t = 0

while(s[0] != m):

    for i in range(q):
        if s[b[i]-1] - s[a[i]-1]  == c[i]:
            ans += d[i]
    #print(s)
    #print(ans)

    ans1[t] = ans
    t += 1

    ans = 0

    if s[num] < m:
        s[num] += 1
    elif num > 0 :
        num -= 1
        temp = s[num]+1
        if temp < m:
            for i in range(num,n):
                s[i] = temp
        else:
            while(s[num] == m):
                num -= 1
            temp = s[num]+1
            for i in range(num,n):
                s[i] = temp

        num = n-1






print(max(ans1))


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

s = [1] * n
#st[b[i]] - st[a[i]]  = c[i]
num = n-1
ans1 = [0] * 1000000
ans = 0
t = 0

while(s[0] != m):

    for i in range(q):
        if s[b[i]-1] - s[a[i]-1]  == c[i]:
            ans += d[i-1]
    print(ans)

    ans1[t] = ans
    t += 1
    ans = 0

    if s[num] < m:
        s[num] += 1
    elif num > 0 :
        num -= 1
        temp = s[num]+1
        if temp < m:
            for i in range(num,n):
                s[i] = temp
        else:
            while(s[num] == m):
                num -= 1
            temp = s[num]+1
            for i in range(num,n):
                s[i] = temp

        num = n-1

    print(s)




print(max(ans1))


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

s = [1] * n
#st[b[i]] - st[a[i]]  = c[i]
num = n-1
#ans1 = [0] * 10000000
ans = 0
pre_ans = 0
t = 0

while(s[0] != m ):

    for i in range(q):
        if s[b[i]-1] - s[a[i]-1]  == c[i]:
            ans += d[i]
    #print(s)
    #print(ans)
    ans = max(pre_ans,ans)
    pre_ans = ans
    #t += 1

    ans = 0

    if s[num] < m:
        s[num] += 1
    elif num > 0 :
        num -= 1
        temp = s[num]+1
        if temp < m:
            for i in range(num,n):
                s[i] = temp
        else:
            while(s[num] == m):
                num -= 1
            temp = s[num]+1
            for i in range(num,n):
                s[i] = temp

        num = n-1

for i in range(q):
    if s[b[i]-1] - s[a[i]-1]  == c[i]:
        ans += d[i]

ans = max(pre_ans,ans)

print(ans)


Verdicts: Time Limit Exceeded

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 = [list(map(int,input().split())) for _ in range(Q)]
data = list(range(1,M+1))
A=list(itertools.combinations_with_replacement(data,N))
max_score = 0

for Ai in A:
  x = 0
  for a,b,c,d in L:
    if Ai[b] - Ai[a] == c:
      x += d
  max_score = max(max_score,x)

print(max_score)

import itertools
N,M,Q = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(Q)]
date = list(range(1,M+1))
A=list(itertools.combinations_with_replacement(data,N))
max_score = 0

for Ai in A:
  x = 0
  for a,b,c,d in L:
    if Ai[b] - Ai[a] == c:
      x += d
  max_score = max(max_score,x)
  
print(max_score)

import itertools
N,M,Q = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(Q)]
data = list(range(1,M+1))
A=list(itertools.combinations_with_replacement(data,N))
max_score = 0

for Ai in A:
  x = 0
  for a,b,c,d in L:
    if Ai[b-1] - Ai[a-1] == c:
      x += d
  max_score = max(max_score,x)

print(max_score)

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


def resolve(in_):
    n, m, q = map(int, next(in_).split())
    abcd = tuple(tuple(map(int, row.split())) for row in in_)
    print(abcd)

    ans = 0
    for seq_a in itertools.combinations_with_replacement(range(1, m + 1), n):
        print(seq_a)
        point = 0
        for a, b, c, d in abcd:
            if seq_a[b - 1] - seq_a[a - 1] == c:
                point += d
        ans = max(ans, point)

    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

import sys
import itertools


def resolve(in_):
    n, m, q = map(int, next(in_).split())
    abcd = tuple(tuple(map(int, row.split())) for row in in_)
    # print(abcd)

    ans = 0
    for seq_a in itertools.combinations_with_replacement(range(1, m + 1), n):
        # print(seq_a)
        point = 0
        for a, b, c, d in abcd:
            if seq_a[b - 1] - seq_a[a - 1] == c:
                point += d
        ans = max(ans, point)

    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

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

Submission attempts (in order):
import itertools
def main():
    N,M,Q = map(int,input().split())
    q = []
    for i in range(Q):
        a,b,c,d = map(int,input().split())
        q.append([a-1,b-1,c,d])
    A = [i for i in range(1,M+1)]
    if N==10:

        ans = 0
        for i, qq in enumerate(q):
            if A[qq[1]] - A[qq[0]] == qq[2]:
                ans += qq[3]
        print(ans)

    else:
        aa = list(itertools.combinations(A,N))
        ans = 0
        
        for i, cc in enumerate(aa):
            ans1 = 0
            for j, qq in enumerate(q):
                if cc[qq[1]] - cc[qq[0]] == qq[2]:
                    ans1 += qq[3]
            print(ans1,cc)
            ans = max(ans,ans1)
        print(ans)

if __name__=='__main__':
    main()


import itertools
def main():
    N,M,Q = map(int,input().split())
    q = []
    for i in range(Q):
        a,b,c,d = map(int,input().split())
        q.append([a-1,b-1,c,d])
    A = [i for i in range(1,M+1)]
    # if N==10:
    #
    #     ans = 0
    #     for i, qq in enumerate(q):
    
    
    #     print(ans)
    #
    # else:
    aa = list(itertools.combinations_with_replacement(A,N))
    ans = 0

    for i, cc in enumerate(aa):
        ans1 = 0
        for j, qq in enumerate(q):
            if cc[qq[1]] - cc[qq[0]] == qq[2]:
                ans1 += qq[3]
            # print(ans1,cc)
        ans = max(ans,ans1)
    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 sys
from itertools import combinations_with_replacement
from numba import njit


@njit('(i8,i8,i8[:,:])')
def solve(n, m, query):
    li = [i for i in range(1, m + 1)]
    max_point: int = 0
    for a in combinations_with_replacement(li, n):
        point = 0
        for qer in query:
            if a[qer[1] - 1] - a[qer[0] - 1] == qer[2]:
                point += qer[3]
        if point > max_point:
            max_point = point
    print(max_point)


def main():
    input = sys.stdin.buffer.readline
    n, m, q = map(int, input().split())
    query = [list(map(int, input().split())) for _ in range(q)]
    solve(n, m, query)


if __name__ == '__main__':
    main()


import sys
from itertools import combinations_with_replacement
from numba import njit


@njit('(i8,i8,i8[:,:])')
def solve(n, m, query):
    li = [0] * m
    for i in range(1, m + 1):
        li[i - 1] = i
    max_point: int = 0
    for a in combinations_with_replacement(li, n):
        point = 0
        for qer in query:
            if a[qer[1] - 1] - a[qer[0] - 1] == qer[2]:
                point += qer[3]
        if point > max_point:
            max_point = point
    print(max_point)


def main():
    input = sys.stdin.buffer.readline
    n, m, q = map(int, input().split())
    query = [list(map(int, input().split())) for _ in range(q)]
    solve(n, m, query)


if __name__ == '__main__':
    main()


import sys
from itertools import combinations_with_replacement


def main():
    input = sys.stdin.buffer.readline
    n, m, q = map(int, input().split())
    query = [list(map(int, input().split())) for _ in range(q)]
    li = [i for i in range(1, m + 1)]
    max_point = 0
    for a in combinations_with_replacement(li, n):
        point = 0
        for qer in query:
            if a[qer[1] - 1] - a[qer[0] - 1] == qer[2]:
                point += qer[3]
        if point > max_point:
            max_point = point
    print(max_point)


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Runtime Error

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

Submission attempts (in order):
from itertools import combinations_with_replacement as cwd

N, M, Q = map(int, input().split())
A = list(cwd(range(1, M + 1), N))
ABCD = []

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

res = 0
for i in A:
    tmp = 0
    for j in ABCD:
        if i[j[1]] - i[j[0]] == j[2]:
            tmp += j[3]
    res = max(res, tmp)

print(A)


from itertools import combinations_with_replacement as cwd

N, M, Q = map(int, input().split())
A = list(cwd(range(1, M + 1), N))
ABCD = []

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

res = 0
for i in A:
    tmp = 0
    for j in ABCD:
        if i[j[1]] - i[j[0]] == j[2]:
            tmp += j[3]
    res = max(res, tmp)

print(res)


Verdicts: Wrong Answer

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

Submission attempts (in order):
n,m,q = map(int,input().split())
a = [0 for i in range(q)]
for i in range(q):
    a[i] = list(map(int,input().split()))
for i in range(1,m+1):
    for j in range(i,m+1):
        for k in range(j,m+1):
            for s in range(k,m+1):
                for p in range(s,m+1):
                    for l in range(p,m+1):
                        for e in range(l,m+1):
                            for u in range(e,m+1):
                                for v in range(u,m+1):
                                    b = [1,f,c,k,s,p,l,e,u,v]
                                    nn = 0
                                    for h in range(q):
                                        if b[a[h][1]-1] - b[a[h][0]-1] == a[h][2]:
                                            nn += a[h][3]
                                    ans = max(ans,nn)
print(ans)

n,m,q = map(int,input().split())
a = [0 for i in range(q)]
ans = 0
for i in range(q):
    a[i] = list(map(int,input().split()))
for i in range(1,m+1):
    for j in range(i,m+1):
        for k in range(j,m+1):
            for s in range(k,m+1):
                for p in range(s,m+1):
                    for l in range(p,m+1):
                        for e in range(l,m+1):
                            for u in range(e,m+1):
                                for v in range(u,m+1):
                                    b = [1,i,j,k,s,p,l,e,u,v]
                                    nn = 0
                                    for h in range(q):
                                        if b[a[h][1]-1] - b[a[h][0]-1] == a[h][2]:
                                            nn += a[h][3]
                                    ans = max(ans,nn)
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):
a, b, n = list(map(lambda x: int(x), input().split(' ')))

print((a * (n - 1)) // b - a * ((n - 1) // b))

n, m, q = list(map(lambda x: int(x), input().split(' ')))

e = []

for i in range(q):
  s = list(map(lambda x: int(x), input().split(' ')))
  e.append(s)

def helper(l, tmp, n, all):
  if len(tmp) == n:
    r = tmp.copy()
    all.append(r)
    return

  for i, v in enumerate(l):
    tmp.append(v)
    helper(l[i:], tmp, n, all)
    tmp.pop()

candidates = []
helper(list(range(1, m+1)), [], n, candidates)

max_val = 0

for c in candidates:
  sum = 0

  for j in e:
    if c[j[1] - 1] - c[j[0] - 1] == j[2]:
      sum += j[3]

  max_val = max(max_val, sum)

print(max_val)

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


ans = 0
R = [i for i in range(1, M+1)]
print(R)
for comb in itertools.combinations_with_replacement(R, N):
    temp = 0
    for abcd in ABCD:
        a, b, c, d = abcd
        if comb[b-1] - comb[a-1] == c:
            temp += d
    if temp >= ans:
        ans = temp

    # print("comb: {}, temp: {}, ans: {}".format(comb, temp, ans))

print(ans)


import itertools

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


ans = 0
R = [i for i in range(1, M+1)]
# print(R)

for comb in itertools.combinations_with_replacement(R, N):
    temp = 0
    for abcd in ABCD:
        a, b, c, d = abcd
        if comb[b-1] - comb[a-1] == c:
            temp += d
    if temp >= ans:
        ans = temp

    # print("comb: {}, temp: {}, ans: {}".format(comb, temp, 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):
N, M, Q = map(int, input().split())
A = []

for i in range(Q):
  A.append(list(map(int, input().split())))

def calc(B, n):
  ans = 0
  if len(B) < N:
    for i in range(n, M + 1):
      ans = max(ans, calc(B + [i], i))
      return ans
  else:
    for j in range(Q):
      if B[A[j][1]-1] - B[A[j][0]-1] == A[j][2]:
        ans += A[j][3]
    return ans


print(calc([], 1))


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

for i in range(Q):
  A.append(list(map(int, input().split())))

def calc(B, n):
  ans = 0
  #not enough length
  if len(B) < N:
    for i in range(n, M + 1):
      ans = max(ans, calc(B + [i], i))
  #enough length
  else:
    print("B:", B)
    for j in range(Q):
      if B[A[j][1]-1] - B[A[j][0]-1] == A[j][2]:
        ans += A[j][3]
    print("ans:", ans)
  return ans



print(calc([], 1))


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

for i in range(Q):
  A.append(list(map(int, input().split())))

def calc(B, n):
  ans = 0
  #not enough length
  if len(B) < N:
    for i in range(n, M + 1):
      ans = max(ans, calc(B + [i], i))
  #enough length
  else:
    
    for j in range(Q):
      if B[A[j][1]-1] - B[A[j][0]-1] == A[j][2]:
        ans += A[j][3]
    #print("ans:", ans)
  return ans



print(calc([], 1))


Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
import itertools

N,M,Q = map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(0,Q,1):
    tmp = list(map(int,input().split()))
    a.append(tmp[0])
    b.append(tmp[1])
    c.append(tmp[2])
    d.append(tmp[3])

max_score = -1
for i in itertools.combinations_with_replacement(range(1,M,1),N):
    score = 0
    for j in range(0,Q,1):
        if i[b[j]-1]-i[a[j]-1]==c[j]:
            score += d[j]
    if max_score < score:
        max_score = score

print(max_score)

import itertools

N,M,Q = map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(0,Q,1):
    tmp = list(map(int,input().split()))
    a.append(tmp[0])
    b.append(tmp[1])
    c.append(tmp[2])
    d.append(tmp[3])

max_score = -1
for i in itertools.combinations_with_replacement(range(1,M+1,1),N):
    score = 0
    for j in range(0,Q,1):
        if i[b[j]-1]-i[a[j]-1]==c[j]:
            score += d[j]
    if max_score < score:
        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):
import itertools
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])
  
num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
nums = list(itertools.combinations_with_replacement(nums, 10))
scores = []
for row in nums:
  score = 0
  i = 0
  while i < Q:
    if row[l[i][1]]-row[l[i][0]] == l[i][2]:
      score += l[i][3]
    i += 1
  scores.append(score)
  
print(max(scores))

import itertools
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])
  
nums = list(itertools.combinations_with_replacement(range(1, M+1), N))
scores = []
for row in nums:
  score = 0
  i = 0
  while i < Q:
    if row[l[i][1]-1]-row[l[i][0]-1] == l[i][2]:
      score += l[i][3]
    i += 1
  scores.append(score)
  
print(max(scores))

Verdicts: Runtime Error

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

Submission attempts (in order):
[n,m,q] = list(map(int,input().split(" ")))
a = []
for i in range (q):
    a.append(list(map(int,input().split(" "))))
ans = 0
for i in range (10**n):
    tmp = 0
    nlst = [1 for t in range(n)]
    for j in range (len(str(i))):
        nlst[j]=int(str(i)[j])+1
    if max(nlst)<=m and nlst==sorted(nlst):
        for k in range(q):
            a_ = a[k][0]
            b_ = a[k][1]
            c_ = a[k][2]
            d_ = a[k][3]
            if nlst[b_-1]-nlst[a_-1]==c_:
                tmp = tmp + d_
        if ans < tmp:
            ans = tmp
    
print(ans)

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

y = [1 for i in range(n)]

def f(index,li):
    if index == n:
        return eva(li)
    else:
        ret = 0
        t = 1
        if index>=1:
            t = li[index-1]
        for i in range (t,m+1):
            li[index]=i
            x = f(index+1,li)
            if ret < x:
                ret = x
        return ret
    
def eva(li):
    tmp = 0
    for k in range(q):
        a = lst[k][0]
        b = lst[k][1]
        c = lst[k][2]
        d = lst[k][3]
        if li[b-1]-li[a-1]==c:
            tmp = tmp + d
    return tmp
    
print(f(0,y))

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

As = []

def make(A):
  global As, N, M
  if len(A) == N+1:
    As.append(A)
  elif:
    for i in range(A[len(A)-1], M+1):
      A.append(i)

make([1])

max = 0
for A in As:
  score = 0
  for req in reqs:
    if A[req[1]] - A[req[0]] == req[2]:
      score += req[3]
  max = max(score, max)

print(max)

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

As = []

def make(A):
  global As, N, M
  print(A)
  if len(A) == N+1:
    As.append(A)
  else:
    for i in range(A[len(A)-1], M+1):
      make(A+[i])

make([1])

maxs = 0
for A in As:
  score = 0
  for req in reqs:
    if A[req[1]] - A[req[0]] == req[2]:
      score += req[3]
  maxs = max(score, maxs)

print(maxs)


N, M, Q = map(int, input().split())
reqs = [list(map(int, input().split())) for _ in range(Q)]
 
As = []
 
def make(A):
  global As, N, M
  if len(A) == N+1:
    As.append(A)
  else:
    for i in range(A[len(A)-1], M+1):
      A.append(i)
 
make([1])
 
max = 0
for A in As:
  score = 0
  for req in reqs:
    if A[req[1]] - A[req[0]] == req[2]:
      score += req[3]
  max = max(score, max)
 
print(max)

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

As = []

def make(A):
  global As, N, M
  # print(A)
  if len(A) == N+1:
    As.append(A)
  else:
    for i in range(A[len(A)-1], M+1):
      make(A+[i])

make([1])

maxs = 0
for A in As:
  score = 0
  for req in reqs:
    if A[req[1]] - A[req[0]] == req[2]:
      score += req[3]
  maxs = max(score, maxs)

print(maxs)

Verdicts: Runtime Error

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

for i in range(1,a[1]+1):
    for j in range(i,a[1]+1):
        for k in range(j,a[1]+1):
            c=[i,j,k]
            for l in range(a[2]):
                if c[b[l][1]-1]-c[b[l][0]-1]==b[l][2]:
                    ans+=b[l][3]
            d.append(ans)
            ans=0
print(max(d))

import itertools
a=list(map(int,input().split()))
b=[]
ans=0
c=range(1,a[1]+1)
d=[]
for _ in range(a[2]):
    b.append(list(map(int,input().split())))


for i in itertools.combinations_with_replacement(c,a[0]):
    for l in range(a[2]):
        if i[b[l][1]-1]-i[b[l][0]-1]==b[l][2]:
            ans+=b[l][3]
    d.append(ans)
    ans=0
print(max(d))

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

point_list = []
for i in range( Q ):
  a, b, c, d = map( int, input().split())
  point_list.append( [ a, b, c, d ] )
  
l = ['{0:04b}'.format(i) for i in range( 2 ** M ) if sum(list(map(int, '{0:04b}'.format(i)))) == N]

def bin_to_numlist( bin ):
  l = []
  cnt = 1
  for i in list(map(int, bin)):
    if i == 1:
      l.append( cnt )
    cnt += 1
  return l

target = map( bin_to_numlist, l )
max_point = 0
for t in target:
  point = 0
  for a, b, c, d in point_list:
    if t[ b - 1 ] - t[ a - 1 ] == c:
      point += d
  max_point = max( max_point, point )
  print( t, point )
print( max_point )


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

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

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

max_point = 0
for t in all_lists:
  point = 0
  for p in point_list:
    a, b, c, d = p
    if t[ b - 1 ] - t[ a - 1 ] == c:
      point += d
  max_point = max( max_point, point )
print( max_point )


Verdicts: Wrong Answer

Accepted