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())
num = [[0 for i in range(4)] for j in range(Q)]
test = list()

k = 1
for i in range(M):
    test.append(k)
    k += 1

k = 0
for i in range(Q):
    num[k][0], num[k][1], num[k][2], num[k][3] = map(int,input().split())
    k += 1

k = 0
score = 0
maxscore = 0
for list in itertools.combinations(test, N):
    for i in range(Q):
        if list[num[k][1]-1] - list[num[k][0]-1] == num[k][2]:
            score += num[k][3]
            k += 1
        if score > maxscore:
            maxscore = score
    print(list)
    print(score)
    score = 0
    k = 0

print(maxscore)


import itertools

N,M,Q = map(int,input().split())
num = [[0 for i in range(4)] for j in range(Q)]
test = list()

k = 1
for i in range(M):
    test.append(k)
    k += 1

k = 0
for i in range(Q):
    num[k][0], num[k][1], num[k][2], num[k][3] = map(int,input().split())
    k += 1

k = 0
score = 0
maxscore = 0
for list in itertools.combinations_with_replacement(test, N):
    for i in range(Q):
        if list[num[k][1]-1] - list[num[k][0]-1] == num[k][2]:
            score += num[k][3]
        k += 1
        if score > maxscore:
            maxscore = score
    score = 0
    k = 0

print(maxscore)


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

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

def dfs(arr):
    if len(arr) == n:
        return score(arr)
    last = arr[-1] if len(arr) > 0 else 0
    res = 0
    for i in range(last, m+1):
        a.append(i)
        res = max(res, dfs(arr))
        a.pop()
    return res

def solve():
    global a, b, c, d, n, m, q
    n, m, q = map(int, input().split())
    a, b, c, d = [0]*q, [0]*q, [0]*q, [0]*q
    for i in range(q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
    print(dfs([]))
    return 0

if __name__ == "__main__":
    solve()


import numpy as np
import math
import scipy
import itertools

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

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

def solve():
    global a, b, c, d, n, m, q
    n, m, q = map(int, input().split())
    a, b, c, d = [0]*q, [0]*q, [0]*q, [0]*q
    for i in range(q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
    print(dfs([]))
    return 0

if __name__ == "__main__":
    solve()


Verdicts: Runtime Error

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

Submission attempts (in order):
from sys import stdin
import itertools
import numpy as np
from numba import njit


readline=stdin.readline
N,M,Q=map(int,readline().split())
a=np.zeros(Q,dtype=np.int64)
b=np.zeros(Q,dtype=np.int64)
c=np.zeros(Q,dtype=np.int64)
d=np.zeros(Q,dtype=np.int64)
for i in range(Q):
    a[i],b[i],c[i],d[i]=map(int,readline().split())

arrays=np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)),dtype=np.int64)
l=len(arrays)

@njit
def f():
    max_res=0
    for i in range(l):
        res=0
        for i in range(Q):
            if arrays[i][b[i]-1]-arrays[i][a[i]-1]==c[i]:
                res+=d[i]
        max_res=max(max_res,res)
    return max_res

print(f())

from sys import stdin
import itertools
import numpy as np
from numba import njit

def main():

    readline=stdin.readline
    N,M,Q=map(int,readline().split())
    a=np.zeros(Q,dtype=np.int64)
    b=np.zeros(Q,dtype=np.int64)
    c=np.zeros(Q,dtype=np.int64)
    d=np.zeros(Q,dtype=np.int64)
    for i in range(Q):
        a[i],b[i],c[i],d[i]=map(int,readline().split())

    arrays=np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)),dtype=np.int64)
    l=len(arrays)

    print(f(l,Q,a,b,c,d,arrays))
    
@njit("i8(i8,i8,i8[:],i8[:],i8[:],i8[:],i8[:,:])",cache=True)
def f(l,Q,a,b,c,d,arrays):
    max_res=0
    for i in range(l):
        res=0
        for j in range(Q):
            if arrays[i][b[j]-1]-arrays[i][a[j]-1]==c[j]:
                res+=d[j]
        max_res=max(max_res,res)
    return max_res

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 random
from copy import deepcopy

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

gene_length=n
individual_length=n*10
generation=100
elite_gene=1
individual_mutation=0.01
gene_mutation=0.01

def get_population():
  pop=[]
  for i in range(individual_length):
    pop.append([random.randrange(1,m+1) for j in range(gene_length)])
  return pop


def get_fitness(indiv):
  fitness=0
  for a,b,c,d in l:
    a-=1
    b-=1
    if indiv[b]-indiv[a]==c:
      fitness+=d
  return fitness


def elite_selection(pop):
  pop.sort(reverse=True, key=lambda x:x[1])
  return pop[:elite_gene+1]


def two_point_crossover(parent1,parent2):
  r1=random.randint(0,gene_length-1)
  r2=random.randint(0,gene_length-1)
  child=deepcopy(parent1)
  child[r1:r2]=parent2[r1:r2]
  return child


pop=[[p,get_fitness(p)] for p in get_population()]
pop.sort(reverse=True,key=lambda x:x[1])

for g in range(generation):
  elites=elite_selection(pop)
  pop=elites
  while len(pop)<individual_length:
    if random.random()<individual_mutation:
      child=[random.randrange(1,m+1) for j in range(gene_length)]
    else:
      m1=random.randint(0,len(elites)-1)
      m2=random.randint(0,len(elites)-1)
      child=two_point_crossover(elites[m1][0],elites[m2][0])
    pop.append([child,get_fitness(child)])

    n_pop=[]
    for i in pop:
      if i not in n_pop:
        n_pop.append(i)
    pop=n_pop

  pop.sort(reverse=True,key=lambda x:x[1])

ans=pop[0][1]
print(ans)

import sys
sys.setrecursionlimit(10**9)

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

def dfs(a_l):
  if len(a_l)==n:
    global ans
    t_ans=0
    for a,b,c,d in l:
      a-=1
      b-=1
      if (a_l[b]-a_l[a]==c):
        t_ans+=d
    ans=max(ans,t_ans)

    return

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

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

print(ans)

Verdicts: Time Limit Exceeded

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

def f(nums):
  out=0
  for samp in abcd:
    if nums[samp[1]-1]-nums[samp[0]-1]==samp[2]:
      out+=samp[3]
  return out

def g(nums):
  if nums[-1]<M:
    nums[-1]+=1
    return nums, False
  
  i=N-1
  while i>=0 and nums[i]==M:
    i-=1
  if i<0:
    return None, True
  
  nums=nums[:i]+[nums[i]+1 for _ in range(N-i)]
  return nums, False

nums=[1]*N
fi=False
ans=0

while fi==False:
  p=f(nums)
  if ans<p:
    ans=p
  print(nums)
  nums, fi=g(nums)
  
print(ans)


  

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

def f(nums):
  out=0
  for samp in abcd:
    if nums[samp[1]-1]-nums[samp[0]-1]==samp[2]:
      out+=samp[3]
  return out

def g(nums):
  if nums[-1]<M:
    nums[-1]+=1
    return nums, False
  
  i=N-1
  while i>=0 and nums[i]==M:
    i-=1
  if i<0:
    return None, True
  
  nums=nums[:i]+[nums[i]+1 for _ in range(N-i)]
  return nums, False

nums=[1]*N
fi=False
ans=0

while fi==False:
  p=f(nums)
  if ans<p:
    ans=p
  nums, fi=g(nums)
  
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())

A = [[ int(n) for n in input().split()] for _ in range(Q) ]
n = [i for i in range(1,M+1)]
numbers = list(itertools.combinations_with_replacement(n, N))
ans = [0 for _ in range(len(numbers))]

q = Q
while  q> 0:
    q -= 1
    a, b, c, d = A[q][0], A[q][1], A[q][2], A[q][3]
    print(a,b,c,d)

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


print(max(ans))


import itertools

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

A = [[ int(n) for n in input().split()] for _ in range(Q) ]
n = [i for i in range(1,M+1)]
numbers = list(itertools.combinations_with_replacement(n, N))
ans = [0 for _ in range(len(numbers))]

q = Q
while  q> 0:
    q -= 1
    a, b, c, d = A[q][0], A[q][1], A[q][2], A[q][3]

    for i in range(len(numbers)):
        if numbers[i][b-1] - numbers[i][a-1] == 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):
n,m,q = map(int,input().split())
nums = [tuple(map(int,input().split())) for _ in range(q)]

from itertools import combinations_with_replacement

cands = list(combinations_with_replacement(range(1,m+1), n))
print(cands)

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


from itertools import combinations_with_replacement

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

ans = 0

for cand in cands:
  score = 0
  for a,b,c,d in nums:
    if cand[b] - cand[a] == c:
      score += d
  ans = max(ans, score)
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(" "))
asset = []
for i in range(q):
    asset.append(list(map(int, input().split(" "))))
A = []


max = 0
print (asset)
for a in itertools.product(list(range(1, m + 1)), repeat = n):
    A.append((list(a)))
for i in range(len(A)):
    total = 0
    for j in range(0, n):
        if A[j] <= A[j - 1]:
            continue
    for j in range(q):
        if A[i][asset[j][1] - 1] - A[i][asset[j][0] - 1] == asset[j][2]:
            total += asset[j][3]
    max = total if total > max else max
print(max)


import itertools

n,m,q = map(int, input().split(" "))
a,b,c,d = [],[],[],[]
for i in range(q):
  inpu = input()
  a.append((int)(inpu.split(" ")[0]))
  b.append((int)(inpu.split(" ")[1]))
  c.append((int)(inpu.split(" ")[2]))
  d.append((int)(inpu.split(" ")[3]))

balls = list(itertools.combinations_with_replacement(range(1, m + 1), n))
#print(balls)
max = 0
for i in range(len(balls)):
  temp = 0
  for j in range(q):
    if balls[i][b[j] - 1] - balls[i][a[j] - 1] == c[j]:
      temp += d[j]
  if temp > max:
    max = temp
print(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 itertools import combinations_with_replacement
n, m, q = map(int, input().split())
lst = []
for i in range(q):
    a = list(map(int, input().split()))
    lst.append(a)

x = 0

for i in combinations_with_replacement(range(1, m + 1), n):
    s = 0
    for j in a:
        if i[j[1] - 1] - i[j[0] - 1] == j[2]:
            s += j[3]
    if x < s:
        x = s
print(x)


from itertools import combinations_with_replacement
from itertools import accumulate
n, m, q = map(int, input().split())
a = []
for i in range(q):
    a.append(list(map(int, input().split())))


x = 0
for i in combinations_with_replacement(range(1, m + 1), n):
    ans = []
    for j in a:
        if i[j[1] - 1] - i[j[0] - 1] == j[2]:
            ans.append(j[3])
    if x < sum(ans):
        x = sum(ans)
print(x)



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,b,c,d = [],[],[],[]
ans = 0
A = [1]

for i in range(q):
    ai,bi,ci,di = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)

def dfs(A):
    global ans
    if n == len(A):
        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 i in range(A[-1], m+1):
        A.append(i)
        dfs(A)
        print(A)
        A.pop() 
dfs(A)
print(ans)


n,m,q = map(int,input().split())
a,b,c,d = [],[],[],[]
ans = 0
A = [1]

for i in range(q):
    ai,bi,ci,di = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)

def dfs(A):
    global ans
    if n == len(A):
        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 i in range(A[-1], m+1):
        A.append(i)
        dfs(A)
        A.pop() 
dfs(A)
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
import numpy as np

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

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

for i in range(q):
    ai, bi, ci, di = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)

def score(A, a, b, c, d):
    s = 0
    for i in range(len(a)):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            s += d[i]
    return s

m = 0
it = itertools.combinations_with_replacement(range(1, m+1), n)
A_list = np.array(list(it))


for A in A_list:
    m = max(m, score(A,a,b,c,d))

print(m)
 


import itertools

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

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

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

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


for A in A_list:
    s = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            s += d[i]
    h.append(s)

print(max(h))
 



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())
S=[0]*Q;t=0;d=0;A=[0]*10
for i in range(Q):
  a,b,c,d=map(int,input().split())
  S[i]=[a,b,c,d]
#print(S)
for i1 in range(M):
  for i2 in range(M):
    for i3 in range(M):
      for i4 in range(M):
        for i5 in range(M):
          for i6 in range(M):
            for i7 in range(M):
              for i8 in range(M):
                for i9 in range(M):
                  for i10 in range(M):
                    A=[i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                    for i in range(Q):
                      if A[S[i][1]]-A[S[i][0]]==S[i][2]:
                        d=d+S[i][3]
                    t=max(t,d)
                    d=0
print(t)

N,M,Q=map(int,input().split())
S=[0]*Q;t=0;d=0;A=[0]*10
for i in range(Q):
  a,b,c,d=map(int,input().split())
  S[i]=[a,b,c,d]
#print(S)
for i1 in range(1,M+1):
  for i2 in range(i1,M+1):
    for i3 in range(i2,M+1):
      for i4 in range(i3,M+1):
        for i5 in range(i4,M+1):
          for i6 in range(i5,M+1):
            for i7 in range(i6,M+1):
              for i8 in range(i7,M+1):
                for i9 in range(i8,M+1):
                  for i10 in range(i9,M+1):
                    d=0
                    A=[i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                    for i in range(Q):
                      if A[S[i][1]-1]-A[S[i][0]-1]==S[i][2]:
                        d=d+S[i][3]
                    t=max(t,d)
                    
print(t)

Verdicts: Runtime Error

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

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

ans = 0
for p in itertools.permutations([0]*(m-2)+[1]*n):
    A = [0]*n
    cnt = 1
    i = 0
    for flag in p:
        if flag == 1:
            A[i] = cnt
            i += 1
        else:
            cnt += 1
    val = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            val += d[i]
    ans = max(ans,val)
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())
ans = 0
for A in itertools.combinations_with_replacement(range(1,m+1),n):
    cnt = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            cnt += d[i]
    ans = max(ans,tmp)
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())

ans = 0
for p in itertools.permutations([0]*(m-2)+[1]*n):
    A = [0]*n
    cnt = 1
    i = 0
    for flag in p:
        if flag == 1:
            A[i] = cnt
            i += 1
        else:
            cnt += 1
    val = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            val += d[i]
    ans = max(ans,val)
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())
ans = 0
for A in itertools.combinations_with_replacement(range(1,m+1),n):
    cnt = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            cnt += d[i]
    ans = max(ans,cnt)
print(ans)


Verdicts: Wrong Answer

Runtime Error

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

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

for i in num_li:
    temp = 0
    for j in li:
        a,b,c,d = j
        if i[b-1] - i[a-1] == c:
            temp += d
    ans = max(ans,temp)
    print(temp)
print(ans)

import itertools

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

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

for i in num_li:
    temp = 0
    for j in li:
        a,b,c,d = j
        if i[b-1] - i[a-1] == c:
            temp += d
    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):
import numpy as np
import math
n, m, q = map(int,input().split())
max = 0
j = []
for i in range(q):
    aa,b,c,d = map(int,input().split())
    j.append([aa,b,c,d])

a = [0 for k in range(11)]
for i1 in range(1,11):
    a[1] = i1
    for i2 in range(i1,11):
        a[2] = i2
        for i3 in range(i2,11):
            a[3] = i3
            for i4 in range(i3,11):
                a[4] = i4
                for i5 in range(i4,11):
                    a[5] = i5
                    for i6 in range(i5,11):
                        a[6] = i6
                        for i7 in range(i6,11):
                            a[7] = i7
                                for i8 in range(i7,11):
                                a[8] = i8
                                    for i9 in range(i8,11):
                                    a[9] = i9
                                        for i10 in range(i9,11):
                                        a[10] = i10
                                        s = 0
                                        for i in j:
                                            if a[i[1]]-a[i[0]] = i[2]:
                                                s += i[3]
                                        if max < s:
                                            max = s

print(max)



import itertools
n, m, q = map(int,input().split())
A = itertools.combinations_with_replacement(range(1,m+1),n)
cond = [list(map(int,input().split())) for i in range(q)]
ma = 0
for a in A:
    p = 0
    for c in cond:
        if a[c[1]-1]-a[c[0]-1] == c[2]:
            p += c[3]
    if ma < p:
        ma = p

print(ma)


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 math

a,b,n = map(int, input().split())
tmp = int(n/b)
result = 0
if tmp != 0:
    result = b - 1
else:
    result = n
print(math.floor((a*result)/b) - a*math.floor(result/b))

ans = 0

def dfs():
    global ans
    if len(A) == n:
        count = 0
        for i in range(q):
            if A[b[i] - 1] - A[a[i] - 1] == c[i]:
                count += d[i]
        if count > ans: ans = count
        if A[-1] != m:
            A[-1] += 1
            dfs()
        else:
            A.pop(-1)
        return
    else:
        A.append(A[-1])
        dfs()
        if A[-1] != m:
            A[-1] += 1
            dfs()
        else:
            A.pop(-1)
        return

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 = []

for i in range(1,m + 1):
    A.append(i) 
    dfs()
print(ans)

Verdicts: Wrong Answer

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

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

n,m,q=map(int,input().split())
abcd=[]
for i in range(q):
    ll=map(int,input().split())
    ll=[ww-1 for ww in ll]
    abcd.append(ll)
ans=0
for li in cmb(range(1,m+1),n):
    kari=0
    for i in abcd:
        if li[i[1]]-li[i[0]]==i[2]+1:
            kari+=i[3]+1
    print(li,kari)
    ans=max(ans,kari)

print(ans)

from itertools import combinations_with_replacement as cmb

n,m,q=map(int,input().split())
abcd=[]
for i in range(q):
    ll=map(int,input().split())
    ll=[ww-1 for ww in ll]
    abcd.append(ll)
ans=0
for li in cmb(range(1,m+1),n):
    kari=0
    for i in abcd:
        if li[i[1]]-li[i[0]]==i[2]+1:
            kari+=i[3]+1
    ans=max(ans,kari)

print(ans)

Verdicts: Wrong Answer

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

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

n,m,q = map(int, input().split(' '))
lis = [list(map(int, input().split())) for _ in range(q)]
tes = comb(range(1,m))
res = 0
for i in tes:
    te = 0
    for a,b,c,d in lis:
        if c == i[b-1] - i[a-1]:
            te += d
    res = max(te,res)
print(res)

from itertools import combinations_with_replacement as comb

n,m,q = map(int, input().split(' '))
lis = [list(map(int, input().split())) for _ in range(q)]
tes = comb(range(1,m+1),n)
res = 0
for i in tes:
    te = 0
    for a,b,c,d in lis:
        if c == i[b-1] - i[a-1]:
            te += d
    res = max(te,res)
print(res)

Verdicts: Runtime Error

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

Submission attempts (in order):
import itertools

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

ms=[i for i in range(1,m+1)]
ans=0
for k in itertools.permutations(ms, n):
  x=0
  for j in range(q):
    if a[j][2]==k[a[j][1]-1]-k[a[j][0]-1]:
      x+=a[j][3]
      print(x)
  if ans<x:
    ans=x
print(ans)

import itertools
 
n,m,q=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(q)]
 
ms=[i for i in range(1,m+1)]
ans=0
for k in itertools.combinations_with_replacement(ms, n):
  x=0
  for j in range(q):
    if a[j][2]==k[a[j][1]-1]-k[a[j][0]-1]:
      x+=a[j][3]
  if ans<x:
    ans=x
print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
n, m, q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(q)]

print('分かりません')

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

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

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

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

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):
n, m, q = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(q)]

ab.sort(key = lambda x: x[3],reverse=True)
ans = 0
sub = [0] * n
for i in range(q):
    if sub[ab[i][1] - 1] - sub[ab[i][0] - 1] == ab[i][2]:
        ans += ab[i][3]
    else:
        if sub[ab[i][0] - 1] == 0:
            sub[ab[i][0] - 1] = sub[ab[i][1] - 1] - ab[i][2]
            ans += ab[i][3]
        elif sub[ab[i][1] - 1] == 0:
            sub[ab[i][1] - 1] = sub[ab[i][0] - 1] + ab[i][2]
            ans += ab[i][3]

ans2 = 0
ab.sort(key=lambda x: x[2], reverse=True)
for i in range(q):
    if sub[ab[i][1] - 1] - sub[ab[i][0] - 1] == ab[i][2]:
        ans2 += ab[i][3]
    else:
        if sub[ab[i][0] - 1] == 0:
            sub[ab[i][0] - 1] = sub[ab[i][1] - 1] - ab[i][2]
            ans2 += ab[i][3]
        elif sub[ab[i][1] - 1] == 0:
            sub[ab[i][1] - 1] = sub[ab[i][0] - 1] + ab[i][2]
            ans2 += ab[i][3]



print(ans2)

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

ans = 0
for i in itertools.combinations_with_replacement(range(1, m + 1), n):
    sub = 0
    for j in range(q):
        if i[ab[j][1] - 1] - i[ab[j][0] - 1] == ab[j][2]:
            sub += ab[j][3]
    
    ans = max(sub, 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())

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

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

B = {}
N = int(input())
A = list(map(int, input().split()))


for i in range(N):
    B[i+1] = 0

for j in A:
    B[j] += 1

for k in B.values():
    print(k)



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

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

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

N, M, Q, *Z = map(int, open(0).read().split())
*Z, = zip(*[iter(Z)]*4)
print(Z)

ans = 0
for A in cwr(range(M), N):
    score = 0
    for a, b, c, d in Z:
        if A[b-1]-A[a-1] == c:
            score += d

    if score > ans:
        ans = score

print(ans)


from itertools import combinations_with_replacement as cwr

N, M, Q, *Z = map(int, open(0).read().split())
*Z, = zip(*[iter(Z)]*4)

ans = 0
for A in cwr(range(M), N):
    score = 0
    for a, b, c, d in Z:
        if A[b-1]-A[a-1] == c:
            score += d

    if score > ans:
        ans = score

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[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 di

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

print(dfs([]))  

n, m, q = list(map(int, input().split()))
a=[0]*q
b=[0]*q
c=[0]*q
d=[0]*q
for i in range(q):
    a[i],b[i],c[i],d[i] = map(int, input().split())
    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:
        #print(A)
        return score(A)
    res = 0
    if len(A) > 0:
        last_term = A[-1]
    else:
        last_term = 1
    for i in range(last_term, m+1):
        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):
N,M,Q = map(int,input().split())
abcd = []
for i in range(Q):
    abcd.append(list(map(int,input().split())))
abcd.sort()

DP = [0 for i in range(N+1)]
for i in range(1,N+1):
    for req in abcd:
        if req[0]==i:
            DP[req[1]] = max(DP[req[1]],DP[i]+req[3])
    print(DP)
print(max(DP))

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

import itertools
A = list(itertools.combinations_with_replacement(range(1,M+1),N))
# print(A)
ans = 0
for item in A:
    tmp = 0
    for req in abcd:
        if item[req[1]-1] - item[req[0]-1] == req[2]:
            tmp+= req[3]
    ans = max(ans,tmp)
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,*l=map(int,open(0).read().split());print(max(sum(d for a in[l[j*4:j*4+4]for j in range(q)]if i[b-1]-i[a-1]==c)for i in itertools.combinations_with_replacement(range(m),n)))

from itertools import*;n,m,q=map(int,input().split());l=[list(map(int,input().split()))for _ in[0]*q];print(max(sum(d for a in l if i[b-1]-i[a-1]==c)for i in itertools.combinations_with_replacement(range(m),n)))

import itertools;n,m,q,*l=map(int,open(0).read().split());print(max(sum(d for a,b,c,d in l[::4]if i[b-1]-i[a-1]==c)for i in itertools.combinations_with_replacement(range(m),n)))

n,m,q=map(int,input().split())
abcd=[list(map(int,input().split()))for _ in range(q)]
ans=0
import itertools
for i in itertools.combinations_with_replacement(list(range(m)),n):
  anss=0
  for a,b,c,d in abcd:
    if i[b-1]-i[a-1]==c:anss+=d
  ans=max(ans,anss)
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):
n,m,q = map(int,input().split())
arr = [list(map(int,input().split())) for x in range(q)]
ans = 0

for i1 in range(1,m+1):
  for i2 in range(i1,m+1):
    for i3 in range(i2,m+1):
      for i4 in range(i4,m+1):
        for i5 in range(i4,m+1):
          for i6 in range(i5,m+1):
            for i7 in range(6,m+1):
              for i8 in range(i7,m+1):
                for i9 in range(i8,m+1):
                  for i10 in range(i9,m+1):
                    tmp = 0
                    arrs = [0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                    for a,b,c,d in arr:
                      if arrs[b] - arrs[a] == c:
                        tmp += d
                    ans = max(ans,tmp)
print(ans)

n,m,q = map(int,input().split())
arr = [list(map(int,input().split())) for x in range(q)]
ans = 0

for i1 in range(1,m+1):
  for i2 in range(i1,m+1):
    for i3 in range(i2,m+1):
      for i4 in range(i3,m+1):
        for i5 in range(i4,m+1):
          for i6 in range(i5,m+1):
            for i7 in range(6,m+1):
              for i8 in range(i7,m+1):
                for i9 in range(i8,m+1):
                  for i10 in range(i9,m+1):
                    tmp = 0
                    arrs = [0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                    for a,b,c,d in arr:
                      if arrs[b] - arrs[a] == c:
                        tmp += d
                    ans = max(ans,tmp)
print(ans)


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

for i1 in range(1,m+1):
  for i2 in range(i1,m+1):
    for i3 in range(i2,m+1):
      for i4 in range(i3,m+1):
        for i5 in range(i4,m+1):
          for i6 in range(i5,m+1):
            for i7 in range(6,m+1):
              for i8 in range(i7,m+1):
                for i9 in range(i8,m+1):
                  for i10 in range(i9,m+1):
                    tmp = 0
                    arrs = [0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                    for a,b,c,d in arr:
                      if arrs[b] - arrs[a] == c:
                        tmp += d
                    ans = max(ans,tmp)
print(ans)


from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(Q)]

ans = 0
for pattern in combinations_with_replacement(range(1, M + 1), N):
    tmp_ans = 0
    pattern = list(pattern)
    for a, b, c, d in X:
        if pattern[b - 1] - pattern[a - 1] == c:
            tmp_ans += d
    ans = max(ans, tmp_ans)

print(ans)

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):
use proconio::input;
use proconio::marker::Usize1;
use itertools::Itertools;
use std::cmp::max;
fn main() {
    input! {
        n:usize,m:usize,q:usize,
        qs: [(Usize1, Usize1, usize, usize); q]
    };
    let mut ans = 0;
    for A in (1..m+1).combinations_with_replacement(n) {
        let mut sm = 0;
        for &(a,b,c,d) in &qs {
            if A[b]-A[a] == c {
                sm += d;
            }
        }
        ans = max(ans, sm);
    }
    println!("{}", ans);
}

from itertools import combinations_with_replacement
N, M, Q = map(int,input().split())
ls = []
for _ in range(Q):
    a,b,c,d = map(int,input().split())
    ls.append((a-1,b-1,c,d))
ans = -1
for A in combinations_with_replacement(range(1,M+1),r=N):
    sm = 0
    for a,b,c,d in ls:
        if A[b]-A[a] == c:
            sm += d
    ans = max(ans, sm)
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):
def dfs(A):
  global ans
  if len(A)==N: 
    now=0
    for i in l:
      if A[i[1]-1]-A[i[0]-1]==i[2]:
        now+=i[3]
    ans=max(ans,now)
    return A


  A.append(A[-1])
  while A[-1]<=M:
    dfs(A)
    A[-1]+=1
    
    
  



N,M,Q=[int(x) for x in input().rstrip().split()]
A=[1]
l=[]
ans=0
for i in range(Q):
  abcd=[int(x) for x in input().rstrip().split()]
  l.append(abcd)
dfs(A)
print(ans)
  

def dfs(A):
  global ans
  if len(A)==N: 
    now=0
    for i in l:
      if A[i[1]-1]-A[i[0]-1]==i[2]:
        now+=i[3]
    ans=max(ans,now)
    return A

  A.append(A[-1])
  while A[-1]<=M:
    dfs(A[:])
    A[-1]+=1
    
  
N,M,Q=[int(x) for x in input().rstrip().split()]
A=[1]
l=[]
ans=0
for i in range(Q):
  abcd=[int(x) for x in input().rstrip().split()]
  l.append(abcd)
dfs(A)
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 random
n, m, q = list(map(int,input().split()))

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

A = [0]*60

    

l = [0]*60
for z in range(60):
  x = 0
  for j in range(q - 1):
    if A[z[b[j] - 1]] - A[z[a[j] - 1]] == c[j]:
      x = x + int(d[j])
    l[j] = x
    
    
x = 0
for j in range(q - 1):
  if A[b[j] - 1] - A[a[j] - 1] == c[j]:
    x = x + int(d[j])
  l[j] = x

print(max(l))

#12653415


N, M, Q = list(map(int, input().split()))
 
conditions = [list(map(int, input().split())) for _ in range(Q)]
 
def dfs(A, max_a):
    if len(A) == N:
        num = 0
        for a, b, c, d in conditions:
            if A[b-1] - A[a-1] == c:
                num += d
        return num
    ans = 0
    for i in range(max_a, M+1):
        ans = max(ans, dfs(A + [i], i))
    return ans
 
print(dfs([1], 1))

Verdicts: Runtime Error

Accepted