problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p02695
u122184618
2,000
1,048,576
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.
['n,m,q = map(int,input().split())\na,b,c,d = [],[],[],[]\nans = 0\nA = [1]\n\nfor i in range(q):\n ai,bi,ci,di = map(int, input().split())\n a.append(ai)\n b.append(bi)\n c.append(ci)\n d.append(di)\n\ndef dfs(A):\n global ans\n if n == len(A):\n now = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n now += d[i]\n ans = max(ans,now)\n return\n\n for i in range(A[-1], m+1):\n A.append(i)\n dfs(A)\n print(A)\n A.pop() \ndfs(A)\nprint(ans)\n', 'n,m,q = map(int,input().split())\na,b,c,d = [],[],[],[]\nans = 0\nA = [1]\n\nfor i in range(q):\n ai,bi,ci,di = map(int, input().split())\n a.append(ai)\n b.append(bi)\n c.append(ci)\n d.append(di)\n\ndef dfs(A):\n global ans\n if n == len(A):\n now = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n now += d[i]\n ans = max(ans,now)\n return\n\n for i in range(A[-1], m+1):\n A.append(i)\n dfs(A)\n A.pop() \ndfs(A)\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s440260028', 's093555972']
[9240.0, 9252.0]
[511.0, 422.0]
[556, 539]
p02695
u123872895
2,000
1,048,576
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.
['import itertools\nimport numpy as np\n\nn, m, q = list(map(int, input().split()))\n\na=[]\nb=[]\nc=[]\nd=[]\n\nfor i in range(q):\n ai, bi, ci, di = list(map(int, input().split()))\n a.append(ai)\n b.append(bi)\n c.append(ci)\n d.append(di)\n\ndef score(A, a, b, c, d):\n s = 0\n for i in range(len(a)):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n s += d[i]\n return s\n\nm = 0\nit = itertools.combinations_with_replacement(range(1, m+1), n)\nA_list = np.array(list(it))\n\n\nfor A in A_list:\n m = max(m, score(A,a,b,c,d))\n\nprint(m)\n \n', 'import itertools\n\nn, m, q = list(map(int, input().split()))\n\na=[]\nb=[]\nc=[]\nd=[]\n\nfor i in range(q):\n x = list(map(int, input().split()))\n a.append(x[0])\n b.append(x[1])\n c.append(x[2])\n d.append(x[3])\n\nh = []\nA_list = list(itertools.combinations_with_replacement(range(1, m+1), n))\n\n\nfor A in A_list:\n s = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n s += d[i]\n h.append(s)\n\nprint(max(h))\n \n\n']
['Wrong Answer', 'Accepted']
['s029953310', 's597659289']
[27136.0, 25396.0]
[105.0, 1146.0]
[545, 448]
p02695
u141574039
2,000
1,048,576
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.
['N,M,Q=map(int,input().split())\nS=[0]*Q;t=0;d=0;A=[0]*10\nfor i in range(Q):\n a,b,c,d=map(int,input().split())\n S[i]=[a,b,c,d]\n#print(S)\nfor i1 in range(M):\n for i2 in range(M):\n for i3 in range(M):\n for i4 in range(M):\n for i5 in range(M):\n for i6 in range(M):\n for i7 in range(M):\n for i8 in range(M):\n for i9 in range(M):\n for i10 in range(M):\n A=[i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]\n for i in range(Q):\n if A[S[i][1]]-A[S[i][0]]==S[i][2]:\n d=d+S[i][3]\n t=max(t,d)\n d=0\nprint(t)', 'N,M,Q=map(int,input().split())\nS=[0]*Q;t=0;d=0;A=[0]*10\nfor i in range(Q):\n a,b,c,d=map(int,input().split())\n S[i]=[a,b,c,d]\n#print(S)\nfor i1 in range(1,M+1):\n for i2 in range(i1,M+1):\n for i3 in range(i2,M+1):\n for i4 in range(i3,M+1):\n for i5 in range(i4,M+1):\n for i6 in range(i5,M+1):\n for i7 in range(i6,M+1):\n for i8 in range(i7,M+1):\n for i9 in range(i8,M+1):\n for i10 in range(i9,M+1):\n d=0\n A=[i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]\n for i in range(Q):\n if A[S[i][1]-1]-A[S[i][0]-1]==S[i][2]:\n d=d+S[i][3]\n t=max(t,d)\n \nprint(t)']
['Runtime Error', 'Accepted']
['s131414554', 's634648701']
[9232.0, 9216.0]
[2205.0, 1417.0]
[678, 752]
p02695
u145600939
2,000
1,048,576
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.
['import itertools\nn,m,q = map(int,input().split())\na = [0]*q\nb = [0]*q\nc = [0]*q\nd = [0]*q\nfor i in range(q):\n a[i],b[i],c[i],d[i] = map(int,input().split())\n\nans = 0\nfor p in itertools.permutations([0]*(m-2)+[1]*n):\n A = [0]*n\n cnt = 1\n i = 0\n for flag in p:\n if flag == 1:\n A[i] = cnt\n i += 1\n else:\n cnt += 1\n val = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n val += d[i]\n ans = max(ans,val)\nprint(ans)\n', 'import itertools\nn,m,q = map(int,input().split())\na = [0]*q\nb = [0]*q\nc = [0]*q\nd = [0]*q\nfor i in range(q):\n a[i],b[i],c[i],d[i] = map(int,input().split())\nans = 0\nfor A in itertools.combinations_with_replacement(range(1,m+1),n):\n cnt = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n cnt += d[i]\n ans = max(ans,tmp)\nprint(ans)\n', 'import itertools\nn,m,q = map(int,input().split())\na = [0]*q\nb = [0]*q\nc = [0]*q\nd = [0]*q\nfor i in range(q):\n a[i],b[i],c[i],d[i] = map(int,input().split())\n\nans = 0\nfor p in itertools.permutations([0]*(m-2)+[1]*n):\n A = [0]*n\n cnt = 1\n i = 0\n for flag in p:\n if flag == 1:\n A[i] = cnt\n i += 1\n else:\n cnt += 1\n val = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n val += d[i]\n ans = max(ans,val)\nprint(ans)\n', 'import itertools\nn,m,q = map(int,input().split())\na = [0]*q\nb = [0]*q\nc = [0]*q\nd = [0]*q\nfor i in range(q):\n a[i],b[i],c[i],d[i] = map(int,input().split())\nans = 0\nfor A in itertools.combinations_with_replacement(range(1,m+1),n):\n cnt = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n cnt += d[i]\n ans = max(ans,cnt)\nprint(ans)\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s416739253', 's772679910', 's900227653', 's057361608']
[9176.0, 9184.0, 9080.0, 9220.0]
[2206.0, 22.0, 2205.0, 1107.0]
[508, 369, 508, 369]
p02695
u152614052
2,000
1,048,576
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.
['import itertools\n\nn,m,q = map(int,input().split())\nli=[list(map(int,input().split())) for i in range(q)]\nans = 0\n\nnum_li = itertools.combinations_with_replacement(range(1,m+1),n)\n\nfor i in num_li:\n temp = 0\n for j in li:\n a,b,c,d = j\n if i[b-1] - i[a-1] == c:\n temp += d\n ans = max(ans,temp)\n print(temp)\nprint(ans)', 'import itertools\n\nn,m,q = map(int,input().split())\nli=[list(map(int,input().split())) for i in range(q)]\nans = 0\n\nnum_li = itertools.combinations_with_replacement(range(1,m+1),n)\n\nfor i in num_li:\n temp = 0\n for j in li:\n a,b,c,d = j\n if i[b-1] - i[a-1] == c:\n temp += d\n ans = max(ans,temp)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s269013306', 's572233169']
[9328.0, 9204.0]
[1154.0, 1134.0]
[352, 336]
p02695
u169350228
2,000
1,048,576
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.
['import numpy as np\nimport math\nn, m, q = map(int,input().split())\nmax = 0\nj = []\nfor i in range(q):\n aa,b,c,d = map(int,input().split())\n j.append([aa,b,c,d])\n\na = [0 for k in range(11)]\nfor i1 in range(1,11):\n a[1] = i1\n for i2 in range(i1,11):\n a[2] = i2\n for i3 in range(i2,11):\n a[3] = i3\n for i4 in range(i3,11):\n a[4] = i4\n for i5 in range(i4,11):\n a[5] = i5\n for i6 in range(i5,11):\n a[6] = i6\n for i7 in range(i6,11):\n a[7] = i7\n for i8 in range(i7,11):\n a[8] = i8\n for i9 in range(i8,11):\n a[9] = i9\n for i10 in range(i9,11):\n a[10] = i10\n s = 0\n for i in j:\n if a[i[1]]-a[i[0]] = i[2]:\n s += i[3]\n if max < s:\n max = s\n\nprint(max)\n\n', 'import itertools\nn, m, q = map(int,input().split())\nA = itertools.combinations_with_replacement(range(1,m+1),n)\ncond = [list(map(int,input().split())) for i in range(q)]\nma = 0\nfor a in A:\n p = 0\n for c in cond:\n if a[c[1]-1]-a[c[0]-1] == c[2]:\n p += c[3]\n if ma < p:\n ma = p\n\nprint(ma)\n']
['Runtime Error', 'Accepted']
['s660599849', 's574135183']
[9020.0, 9208.0]
[23.0, 950.0]
[1291, 321]
p02695
u169702930
2,000
1,048,576
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.
['import math\n\na,b,n = map(int, input().split())\ntmp = int(n/b)\nresult = 0\nif tmp != 0:\n result = b - 1\nelse:\n result = n\nprint(math.floor((a*result)/b) - a*math.floor(result/b))', 'ans = 0\n\ndef dfs():\n global ans\n if len(A) == n:\n count = 0\n for i in range(q):\n if A[b[i] - 1] - A[a[i] - 1] == c[i]:\n count += d[i]\n if count > ans: ans = count\n if A[-1] != m:\n A[-1] += 1\n dfs()\n else:\n A.pop(-1)\n return\n else:\n A.append(A[-1])\n dfs()\n if A[-1] != m:\n A[-1] += 1\n dfs()\n else:\n A.pop(-1)\n return\n\nn,m,q = map(int, input().split())\na = [0]*q\nb = [0]*q\nc = [0]*q\nd = [0]*q\n\nfor i in range(q):\n a[i],b[i],c[i],d[i] = map(int, input().split())\nA = []\n\nfor i in range(1,m + 1):\n A.append(i) \n dfs()\nprint(ans)']
['Wrong Answer', 'Accepted']
['s459856142', 's680330870']
[9180.0, 9208.0]
[22.0, 1420.0]
[182, 711]
p02695
u177388368
2,000
1,048,576
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.
['from itertools import combinations_with_replacement as cmb\n\nn,m,q=map(int,input().split())\nabcd=[]\nfor i in range(q):\n ll=map(int,input().split())\n ll=[ww-1 for ww in ll]\n abcd.append(ll)\nans=0\nfor li in cmb(range(1,m+1),n):\n kari=0\n for i in abcd:\n if li[i[1]]-li[i[0]]==i[2]+1:\n kari+=i[3]+1\n print(li,kari)\n ans=max(ans,kari)\n\nprint(ans)', 'from itertools import combinations_with_replacement as cmb\n\nn,m,q=map(int,input().split())\nabcd=[]\nfor i in range(q):\n ll=map(int,input().split())\n ll=[ww-1 for ww in ll]\n abcd.append(ll)\nans=0\nfor li in cmb(range(1,m+1),n):\n kari=0\n for i in abcd:\n if li[i[1]]-li[i[0]]==i[2]+1:\n kari+=i[3]+1\n ans=max(ans,kari)\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s131056085', 's298723950']
[9212.0, 9144.0]
[1087.0, 919.0]
[379, 360]
p02695
u180528413
2,000
1,048,576
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.
["from itertools import combinations_with_replacement as comb\n\nn,m,q = map(int, input().split(' '))\nlis = [list(map(int, input().split())) for _ in range(q)]\ntes = comb(range(1,m))\nres = 0\nfor i in tes:\n te = 0\n for a,b,c,d in lis:\n if c == i[b-1] - i[a-1]:\n te += d\n res = max(te,res)\nprint(res)", "from itertools import combinations_with_replacement as comb\n\nn,m,q = map(int, input().split(' '))\nlis = [list(map(int, input().split())) for _ in range(q)]\ntes = comb(range(1,m+1),n)\nres = 0\nfor i in tes:\n te = 0\n for a,b,c,d in lis:\n if c == i[b-1] - i[a-1]:\n te += d\n res = max(te,res)\nprint(res)"]
['Runtime Error', 'Accepted']
['s939193742', 's050517454']
[9204.0, 9124.0]
[20.0, 1010.0]
[321, 325]
p02695
u182898140
2,000
1,048,576
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.
['import itertools\n\nn,m,q=map(int,input().split())\na=[list(map(int,input().split())) for _ in range(q)]\n\nms=[i for i in range(1,m+1)]\nans=0\nfor k in itertools.permutations(ms, n):\n x=0\n for j in range(q):\n if a[j][2]==k[a[j][1]-1]-k[a[j][0]-1]:\n x+=a[j][3]\n print(x)\n if ans<x:\n ans=x\nprint(ans)', 'import itertools\n \nn,m,q=map(int,input().split())\na=[list(map(int,input().split())) for _ in range(q)]\n \nms=[i for i in range(1,m+1)]\nans=0\nfor k in itertools.combinations_with_replacement(ms, n):\n x=0\n for j in range(q):\n if a[j][2]==k[a[j][1]-1]-k[a[j][0]-1]:\n x+=a[j][3]\n if ans<x:\n ans=x\nprint(ans)']
['Wrong Answer', 'Accepted']
['s489314605', 's505164265']
[9272.0, 9084.0]
[2212.0, 1419.0]
[312, 316]
p02695
u197968862
2,000
1,048,576
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.
["n, m, q = map(int,input().split())\nab = [list(map(int,input().split())) for _ in range(q)]\n\nprint('分かりません')", 'n, m, q = map(int,input().split())\na, b, c, d = [0] * q,[0] * q, [0] * q, [0] * q\n\nfor i in range(q):\n a[i], b[i], c[i], d[i] = map(int,input().split())\n a[i] -= 1\n b[i] -= 1\n\ndef score(z):\n tmp = 0\n for ai, bi, ci, di in zip(a, b, c, d):\n if z[bi] - z[ai] == ci:\n tmp += di\n return tmp\n\ndef dfs(a):\n if len(a) == n:\n return score(a)\n ans = 0\n prev_last = a[-1] if len(a) > 0 else 0\n for v in range(prev_last,m):\n a.append(v)\n ans = max(ans,dfs(a))\n a.pop()\n return ans\n\nprint(dfs([]))']
['Wrong Answer', 'Accepted']
['s057904651', 's882070435']
[9164.0, 9288.0]
[19.0, 577.0]
[119, 564]
p02695
u202826462
2,000
1,048,576
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.
['n, m, q = map(int, input().split())\nab = [list(map(int, input().split())) for i in range(q)]\n\nab.sort(key = lambda x: x[3],reverse=True)\nans = 0\nsub = [0] * n\nfor i in range(q):\n if sub[ab[i][1] - 1] - sub[ab[i][0] - 1] == ab[i][2]:\n ans += ab[i][3]\n else:\n if sub[ab[i][0] - 1] == 0:\n sub[ab[i][0] - 1] = sub[ab[i][1] - 1] - ab[i][2]\n ans += ab[i][3]\n elif sub[ab[i][1] - 1] == 0:\n sub[ab[i][1] - 1] = sub[ab[i][0] - 1] + ab[i][2]\n ans += ab[i][3]\n\nans2 = 0\nab.sort(key=lambda x: x[2], reverse=True)\nfor i in range(q):\n if sub[ab[i][1] - 1] - sub[ab[i][0] - 1] == ab[i][2]:\n ans2 += ab[i][3]\n else:\n if sub[ab[i][0] - 1] == 0:\n sub[ab[i][0] - 1] = sub[ab[i][1] - 1] - ab[i][2]\n ans2 += ab[i][3]\n elif sub[ab[i][1] - 1] == 0:\n sub[ab[i][1] - 1] = sub[ab[i][0] - 1] + ab[i][2]\n ans2 += ab[i][3]\n\n\n\nprint(ans2)', 'import itertools\nn, m, q = map(int, input().split())\nab = [list(map(int, input().split())) for i in range(q)]\n\nans = 0\nfor i in itertools.combinations_with_replacement(range(1, m + 1), n):\n sub = 0\n for j in range(q):\n if i[ab[j][1] - 1] - i[ab[j][0] - 1] == ab[j][2]:\n sub += ab[j][3]\n \n ans = max(sub, ans)\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s601756392', 's520019415']
[9324.0, 8976.0]
[21.0, 1294.0]
[950, 350]
p02695
u208309047
2,000
1,048,576
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.
['import itertools\nN, M, Q = map(int, input().split())\n\nK= [list(map(int, input().split())) for i in range(Q)]\n\nans = 0\nfor A in itertools.combinations_with_replacement([i for i in range(1, M + 1)], N):\n ans1 = 0\n for i in range(Q):\n a, b, c, d = K[i]\u3000\n if (A[b - 1] - A[a - 1] == c):\n ans1 += d\n ans = max(ans, ans1)\nprint(ans)', 'B = {}\nN = int(input())\nA = list(map(int, input().split()))\n\n\nfor i in range(N):\n B[i+1] = 0\n\nfor j in A:\n B[j] += 1\n\nfor k in B.values():\n print(k)\n\n', 'import itertools\nN, M, Q = map(int, input().split())\n\nK= [list(map(int, input().split())) for i in range(Q)]\n\nans = 0\nfor A in itertools.combinations_with_replacement([i for i in range(1, M + 1)], N):\n ans1 = 0\n for i in range(Q):\n a, b, c, d = K[i]\n if (A[b - 1] - A[a - 1] == c):\n ans1 += d\n ans = max(ans, ans1)\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s489826334', 's511145896', 's662769711']
[8952.0, 9172.0, 9108.0]
[21.0, 20.0, 1996.0]
[419, 190, 416]
p02695
u223663729
2,000
1,048,576
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.
['from itertools import combinations_with_replacement as cwr\n\nN, M, Q, *Z = map(int, open(0).read().split())\n*Z, = zip(*[iter(Z)]*4)\nprint(Z)\n\nans = 0\nfor A in cwr(range(M), N):\n score = 0\n for a, b, c, d in Z:\n if A[b-1]-A[a-1] == c:\n score += d\n\n if score > ans:\n ans = score\n\nprint(ans)\n', 'from itertools import combinations_with_replacement as cwr\n\nN, M, Q, *Z = map(int, open(0).read().split())\n*Z, = zip(*[iter(Z)]*4)\n\nans = 0\nfor A in cwr(range(M), N):\n score = 0\n for a, b, c, d in Z:\n if A[b-1]-A[a-1] == c:\n score += d\n\n if score > ans:\n ans = score\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s008285951', 's664166632']
[9060.0, 9192.0]
[934.0, 1001.0]
[322, 313]
p02695
u224554402
2,000
1,048,576
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.
['n, m, q = map(int, input().split())\na=[0]*q\nb=[0]*q\nc=[0]*q\nd=[0]*q\nfor i in range(q):\n a[i],b[i],c[i],d[i] = map(int, input().split())\n a[i] -=1\n b[i] -=1\n\ndef score(A):\n score =0\n for ai, bi, ci, di in zip(a,b,c,d):\n if A[bi] - A[ai] == ci:\n score += di\n return di\n\ndef dfs(A):\n #print(A)\n if len(A)==n:\n return score(A)\n res = 0\n last_term = A[-1] if len(A) >0 else 0\n for i in range(last_term, m):\n A.append(i)\n res = max(res, dfs(A))\n A.pop()\n \n return res\n\nprint(dfs([])) ', 'n, m, q = list(map(int, input().split()))\na=[0]*q\nb=[0]*q\nc=[0]*q\nd=[0]*q\nfor i in range(q):\n a[i],b[i],c[i],d[i] = map(int, input().split())\n a[i] -=1\n b[i] -=1\n\ndef score(A):\n score =0\n for ai, bi, ci, di in zip(a,b,c,d):\n if A[bi] - A[ai] == ci:\n score += di\n return score\n\ndef dfs(A):\n if len(A)==n:\n #print(A)\n return score(A)\n res = 0\n if len(A) > 0:\n last_term = A[-1]\n else:\n last_term = 1\n for i in range(last_term, m+1):\n A.append(i)\n res = max(res, dfs(A))\n A.pop()\n \n return res\n\nprint(dfs([]))']
['Wrong Answer', 'Accepted']
['s184235676', 's143373742']
[9172.0, 9064.0]
[554.0, 566.0]
[564, 612]
p02695
u225627575
2,000
1,048,576
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.
['N,M,Q = map(int,input().split())\nabcd = []\nfor i in range(Q):\n abcd.append(list(map(int,input().split())))\nabcd.sort()\n\nDP = [0 for i in range(N+1)]\nfor i in range(1,N+1):\n for req in abcd:\n if req[0]==i:\n DP[req[1]] = max(DP[req[1]],DP[i]+req[3])\n print(DP)\nprint(max(DP))', 'N,M,Q = map(int,input().split())\nabcd = []\nfor i in range(Q):\n abcd.append(list(map(int,input().split())))\nabcd.sort()\n\nimport itertools\nA = list(itertools.combinations_with_replacement(range(1,M+1),N))\n# print(A)\nans = 0\nfor item in A:\n tmp = 0\n for req in abcd:\n if item[req[1]-1] - item[req[0]-1] == req[2]:\n tmp+= req[3]\n ans = max(ans,tmp)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s536386664', 's059128319']
[9212.0, 21524.0]
[22.0, 903.0]
[300, 385]
p02695
u227082700
2,000
1,048,576
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.
['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())\nabcd=[list(map(int,input().split()))for _ in range(q)]\nans=0\nimport itertools\nfor i in itertools.combinations_with_replacement(list(range(m)),n):\n anss=0\n for a,b,c,d in abcd:\n if i[b-1]-i[a-1]==c:anss+=d\n ans=max(ans,anss)\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s677595273', 's765678375', 's842814354', 's422093768']
[9076.0, 9096.0, 9132.0, 9184.0]
[21.0, 19.0, 25.0, 1104.0]
[195, 211, 177, 271]
p02695
u228303592
2,000
1,048,576
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.
['n,m,q = map(int,input().split())\narr = [list(map(int,input().split())) for x in range(q)]\nans = 0\n\nfor i1 in range(1,m+1):\n for i2 in range(i1,m+1):\n for i3 in range(i2,m+1):\n for i4 in range(i4,m+1):\n for i5 in range(i4,m+1):\n for i6 in range(i5,m+1):\n for i7 in range(6,m+1):\n for i8 in range(i7,m+1):\n for i9 in range(i8,m+1):\n for i10 in range(i9,m+1):\n tmp = 0\n arrs = [0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]\n for a,b,c,d in arr:\n if arrs[b] - arrs[a] == c:\n tmp += d\n ans = max(ans,tmp)\nprint(ans)', 'n,m,q = map(int,input().split())\narr = [list(map(int,input().split())) for x in range(q)]\nans = 0\n\nfor i1 in range(1,m+1):\n for i2 in range(i1,m+1):\n for i3 in range(i2,m+1):\n for i4 in range(i3,m+1):\n for i5 in range(i4,m+1):\n for i6 in range(i5,m+1):\n for i7 in range(6,m+1):\n for i8 in range(i7,m+1):\n for i9 in range(i8,m+1):\n for i10 in range(i9,m+1):\n tmp = 0\n arrs = [0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]\n for a,b,c,d in arr:\n if arrs[b] - arrs[a] == c:\n tmp += d\n ans = max(ans,tmp)\nprint(ans)\n', 'n,m,q = map(int,input().split())\narr = [list(map(int,input().split())) for _ in range(q)]\nans = 0\n\nfor i1 in range(1,m+1):\n for i2 in range(i1,m+1):\n for i3 in range(i2,m+1):\n for i4 in range(i3,m+1):\n for i5 in range(i4,m+1):\n for i6 in range(i5,m+1):\n for i7 in range(6,m+1):\n for i8 in range(i7,m+1):\n for i9 in range(i8,m+1):\n for i10 in range(i9,m+1):\n tmp = 0\n arrs = [0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]\n for a,b,c,d in arr:\n if arrs[b] - arrs[a] == c:\n tmp += d\n ans = max(ans,tmp)\nprint(ans)\n', 'from itertools import combinations_with_replacement\nN, M, Q = map(int, input().split())\nX = [list(map(int, input().split())) for _ in range(Q)]\n\nans = 0\nfor pattern in combinations_with_replacement(range(1, M + 1), N):\n tmp_ans = 0\n pattern = list(pattern)\n for a, b, c, d in X:\n if pattern[b - 1] - pattern[a - 1] == c:\n tmp_ans += d\n ans = max(ans, tmp_ans)\n\nprint(ans)']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s014471195', 's264771220', 's435757832', 's582308100']
[9252.0, 9096.0, 9112.0, 9096.0]
[23.0, 2205.0, 2206.0, 1098.0]
[699, 700, 700, 401]
p02695
u231095456
2,000
1,048,576
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.
['use proconio::input;\nuse proconio::marker::Usize1;\nuse itertools::Itertools;\nuse std::cmp::max;\nfn main() {\n input! {\n n:usize,m:usize,q:usize,\n qs: [(Usize1, Usize1, usize, usize); q]\n };\n let mut ans = 0;\n for A in (1..m+1).combinations_with_replacement(n) {\n let mut sm = 0;\n for &(a,b,c,d) in &qs {\n if A[b]-A[a] == c {\n sm += d;\n }\n }\n ans = max(ans, sm);\n }\n println!("{}", ans);\n}', 'from itertools import combinations_with_replacement\nN, M, Q = map(int,input().split())\nls = []\nfor _ in range(Q):\n a,b,c,d = map(int,input().split())\n ls.append((a-1,b-1,c,d))\nans = -1\nfor A in combinations_with_replacement(range(1,M+1),r=N):\n sm = 0\n for a,b,c,d in ls:\n if A[b]-A[a] == c:\n sm += d\n ans = max(ans, sm)\nprint(ans)']
['Runtime Error', 'Accepted']
['s857096207', 's782343785']
[9004.0, 9212.0]
[24.0, 847.0]
[484, 363]
p02695
u235376569
2,000
1,048,576
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.
['def dfs(A):\n global ans\n if len(A)==N: \n now=0\n for i in l:\n if A[i[1]-1]-A[i[0]-1]==i[2]:\n now+=i[3]\n ans=max(ans,now)\n return A\n\n\n A.append(A[-1])\n while A[-1]<=M:\n dfs(A)\n A[-1]+=1\n \n \n \n\n\n\nN,M,Q=[int(x) for x in input().rstrip().split()]\nA=[1]\nl=[]\nans=0\nfor i in range(Q):\n abcd=[int(x) for x in input().rstrip().split()]\n l.append(abcd)\ndfs(A)\nprint(ans)\n ', 'def dfs(A):\n global ans\n if len(A)==N: \n now=0\n for i in l:\n if A[i[1]-1]-A[i[0]-1]==i[2]:\n now+=i[3]\n ans=max(ans,now)\n return A\n\n A.append(A[-1])\n while A[-1]<=M:\n dfs(A[:])\n A[-1]+=1\n \n \nN,M,Q=[int(x) for x in input().rstrip().split()]\nA=[1]\nl=[]\nans=0\nfor i in range(Q):\n abcd=[int(x) for x in input().rstrip().split()]\n l.append(abcd)\ndfs(A)\nprint(ans)\n ']
['Wrong Answer', 'Accepted']
['s211535062', 's796102730']
[9216.0, 9172.0]
[24.0, 394.0]
[406, 400]
p02695
u237299453
2,000
1,048,576
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.
['\nimport random\nn, m, q = list(map(int,input().split()))\n\na = [0] * q\nb = [0] * q\nc = [0] * q\nd = [0] * q\nfor i in range(q):\n a[i], b[i], c[i], d[i] = map(int, input().split())\n\nA = [0]*60\n\n \n\nl = [0]*60\nfor z in range(60):\n x = 0\n for j in range(q - 1):\n if A[z[b[j] - 1]] - A[z[a[j] - 1]] == c[j]:\n x = x + int(d[j])\n l[j] = x\n \n \nx = 0\nfor j in range(q - 1):\n if A[b[j] - 1] - A[a[j] - 1] == c[j]:\n x = x + int(d[j])\n l[j] = x\n\nprint(max(l))', '#12653415\n\n\nN, M, Q = list(map(int, input().split()))\n \nconditions = [list(map(int, input().split())) for _ in range(Q)]\n \ndef dfs(A, max_a):\n if len(A) == N:\n num = 0\n for a, b, c, d in conditions:\n if A[b-1] - A[a-1] == c:\n num += d\n return num\n ans = 0\n for i in range(max_a, M+1):\n ans = max(ans, dfs(A + [i], i))\n return ans\n \nprint(dfs([1], 1))']
['Runtime Error', 'Accepted']
['s978252934', 's682572483']
[9576.0, 9132.0]
[25.0, 314.0]
[473, 462]
p02695
u237380963
2,000
1,048,576
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.
['\nimport itertools\n\nn, m, q = map(int, input().split())\n\n\nn, m, q = map(int, input().split())\nquery = []\nfor i in range(q):\n query.append(list(map(int, input().split())))\n\nchoices = list(itertools.combinations_with_replacement([i for i in range(1, m+1)], n))\nans = -1\nfor choice in choices:\n score = 0\n for q in query:\n if choice[q[1]-1] - choice[q[0]-1] == q[2]:\n score += q[3]\n ans = max(ans, score)\nprint(ans)', '\nimport itertools\n\n\nn, m, q = map(int, input().split())\nquery = []\nfor i in range(q):\n query.append(list(map(int, input().split())))\n\nchoices = list(itertools.combinations_with_replacement([i for i in range(1, m+1)], n))\nans = -1\nfor choice in choices:\n score = 0\n for q in query:\n if choice[q[1]-1] - choice[q[0]-1] == q[2]:\n score += q[3]\n ans = max(ans, score)\nprint(ans)']
['Runtime Error', 'Accepted']
['s309275261', 's157385648']
[9080.0, 21472.0]
[21.0, 926.0]
[441, 404]
p02695
u239917977
2,000
1,048,576
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.
['N,M,Q = map(int, input().split())\nABCD = [list(map(int, input().split())) for i in range(Q)]\nscore=0\nfor i in range(1, M+1):\n dfs([i])\nprint(score)\n\n\ndef dfs(l):\n \n if judge_end(l,N):\n global score\n \n tmp_score = calc_score(ABCD,l)\n score = max(tmp_score, score)\n return\n else:\n \n nexts = listup_next(l[-1], M)\n for x in nexts:\n dfs(num_list+[x])\n\n\ndef judge_end(l,N):\n return len(l)==N\n\n\ndef calc_score(ABCD, l):\n s=0\n for a,b,c,d in ABCD:\n if l[b-1] - l[a-1] ==c:\n s+=d\n return s\n\n\ndef listup_next(m, M):\n return range(m,M+1)\n', 'def main():\n N, M, Q = map(int, input().split())\n ABCD = [list(map(int, input().split())) for i in range(Q)]\n score = 0\n\n def dfs(l, **kwargs):\n N = kwargs[\'N\']\n M = kwargs[\'M\']\n ABCD = kwargs[\'ABCD\']\n\n \n if judge_end(l, N=N):\n nonlocal score\n tmp_score = calc_score(l, ABCD=ABCD)\n score = max(tmp_score, score)\n return\n else:\n \n nexts = listup_next(l[-1], M=M)\n for x in nexts:\n dfs(l+[x], N=N, M=M, ABCD=ABCD)\n\n def judge_end(l, **kwargs):\n N = kwargs[\'N\']\n return len(l) == N\n\n def calc_score(l, **kwargs):\n ABCD = kwargs[\'ABCD\']\n s = 0\n for a, b, c, d in ABCD:\n if l[b-1] - l[a-1] == c:\n s += d\n return s\n\n def listup_next(now, **kwargs):\n m = now\n M = kwargs[\'M\']\n return range(m, M+1)\n\n for i in range(1, M+1):\n dfs([i], N=N, M=M, ABCD=ABCD)\n print(score)\n\n\nif __name__ == "__main__":\n main()\n']
['Runtime Error', 'Accepted']
['s541376184', 's400759856']
[9184.0, 9132.0]
[24.0, 670.0]
[720, 1147]
p02695
u247680229
2,000
1,048,576
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.
['N,M,Q=list(map(int,input().split()))\n\nA=[list(map(int,input().split())) for _ in range(Q)]\nnum=0\nfor i in A:\n if i[1]-i[0]==i[2]:\n num+=i[3]\n \nprint(num)', 'N,M,Q=list(map(int,input().split()))\n\nA=[list(map(int,input().split())) for _ in range(Q)]\nnum=0\nfor i in A:\n if i[1]-i[0]==i[2] and i[3]>0:\n num+=i[3]\n \nprint(num)', 'import itertools \nN,M,Q=list(map(int,input().split()))\n \nABCD=[list(map(int,input().split())) for _ in range(Q)]\nans=[]\nfor i in itertools.combinations_with_replacement(range(1,M+1),N):\n num=0\n for a,b,c,d in ABCD:\n if i[b-1]-i[a-1]==c:\n num+=d\n ans.append(num)\nprint(max(ans))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s037306852', 's949476035', 's209624523']
[9184.0, 9184.0, 12672.0]
[22.0, 23.0, 1142.0]
[160, 171, 288]
p02695
u266014018
2,000
1,048,576
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.
['import sys\nfrom itertools import combinations_with_replacement as cwr\ninput = sys.stdin.readline\n\ndef dfs(n,m):\n adj = {}\n for i in range(1,m+1):\n adj[i] = [j for j in range(i,m+1)]\n \n stack = [[i] for i in range(1,m+1)]\n combs = []\n while stack:\n node = stack.pop()\n if len(node) == n:\n combs.append(node)\n else:\n for child in adj[node[-1]]:\n cand = node+[child]\n stack.append(cand)\n return combs\n\n\nN,M,Q = map(int,input().split())\nA,B,C,D = [],[],[],[]\nfor i in range(Q):\n a,b,c,d = map(int,input().split())\n a,b = a-1, b-1\n A.append(a)\n B.append(b)\n C.append(c)\n D.append(d)\n\nans = 0\ncombs = dfs(N,M)\n#combs = cwr(range(1,M+1),N)\nprint(combs)\nans = [0]*(len(combs))\nfor i,comb in enumerate(combs):\n for a,b,c,d in zip(A,B,C,D):\n if comb[b] - comb[a] ==c:\n ans[i] += d\nprint(max(ans))\n\n', 'import sys\nfrom itertools import combinations_with_replacement as cwr\ninput = sys.stdin.readline\n\ndef dfs(n,m):\n adj = {}\n for i in range(1,m+1):\n adj[i] = [j for j in range(i,m+1)]\n \n stack = [[i] for i in range(1,m+1)]\n combs = []\n while stack:\n node = stack.pop()\n if len(node) == n:\n combs.append(node)\n else:\n for child in adj[node[-1]]:\n cand = node+[child]\n stack.append(cand)\n return combs\n\n\nN,M,Q = map(int,input().split())\nA,B,C,D = [],[],[],[]\nfor i in range(Q):\n a,b,c,d = map(int,input().split())\n a,b = a-1, b-1\n A.append(a)\n B.append(b)\n C.append(c)\n D.append(d)\n\nans = 0\ncombs = dfs(N,M)\n#combs = cwr(range(1,M+1),N)\n# print(combs)\nans = [0]*(len(combs))\nfor i,comb in enumerate(combs):\n for a,b,c,d in zip(A,B,C,D):\n if comb[b] - comb[a] ==c:\n ans[i] += d\nprint(max(ans))\n\n']
['Wrong Answer', 'Accepted']
['s200502974', 's621709324']
[28964.0, 26468.0]
[1184.0, 1118.0]
[928, 930]
p02695
u276204978
2,000
1,048,576
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.
['import itertools\nimport numpy as np\n\nN, M, Q = map(int, input().split())\n\nA = np.array(list(itertools.combinations_with_replacemeent(range(1, M+1), N)))\ns = np.zeros(len(A), np.int32)\n\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n s += d * (A[:, b-1] - A[:, a-1] == c)\n\nprint(s.max())', 'import itertools\nimport numpy as np\n\nN, M, Q = map(int, input().split())\n\nA = np.array(list(itertools.combinations_with_replacement(range(1, M+1), N)))\ns = np.zeros(len(A), np.int32)\n\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n s += d * (A[:, b-1] - A[:, a-1] == c)\n\nprint(s.max())']
['Runtime Error', 'Accepted']
['s357252177', 's197102978']
[27124.0, 46664.0]
[106.0, 217.0]
[304, 303]
p02695
u278057806
2,000
1,048,576
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.
['from sys import stdin\nfrom sys import setrecursionlimit\ninput = stdin.readline\n\nsetrecursionlimit(10 ** 9)\n\nN, M, Q = map(int, input().split())\n\nabcd = [list(map(int, input().split())) for _ in range(Q)]\n\nfor q in range(Q):\n abcd[q][3] *= - 1\n\nA = [-1 for _ in range(N + 1)]\n\nabcd.sort(key=lambda x: x[1] - x[0])\n\nfor q in range(Q):\n a, b, c, d = abcd[q]\n\n if A[a] == -1:\n if A[b] == -1:\n A[a] = max(1, A[a - 1])\n A[b] = c + A[a]\n else:\n A[a] = max(1, A[b] - c, A[a - 1])\n if A[b] == -1:\n A[b] = c + A[a]\n\nans = 0\n\nfor q in range(Q):\n a, b, c, d = abcd[q]\n if A[b] - A[a] == c:\n ans += d\n\nprint(ans * (-1))\n', 'from sys import stdin\nfrom itertools import combinations_with_replacement\ninput = stdin.readline\n\nN, M, Q = map(int, input().split())\n\nabcd = [list(map(int, input().split())) for _ in range(Q)]\n\ns = list(range(1, M + 1))\nans = 0\n\n\nfor s in combinations_with_replacement(s, N):\n num = 0\n for q in range(Q):\n a, b, c, d = abcd[q]\n if s[b - 1] - s[a - 1] == c:\n num += d\n ans = max(ans, num)\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s213471874', 's498879819']
[9152.0, 9192.0]
[24.0, 1236.0]
[686, 435]
p02695
u279266699
2,000
1,048,576
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.
['import itertools\n\nn, m, q = map(int, input().split())\nabcd = [tuple(map(int, input().split())) for _ in range(Q)]\nans = 0\nfor com in itertools.combinations_with_replacement(range(1, M + 1), N):\n score = sum([d for a, b, c, d in abcd if com[b-1] - com[a-1] == c])\n if ans < score:\n ans = score\nprint(ans)\n', 'import itertools\n\nn, m, q = map(int, input().split())\nabcd = [tuple(map(int, input().split())) for _ in range(q)]\nans = 0\nfor com in itertools.combinations_with_replacement(range(1, m + 1), n):\n score = sum([d for a, b, c, d in abcd if com[b-1] - com[a-1] == c])\n if ans < score:\n ans = score\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s935205887', 's531338704']
[9148.0, 9068.0]
[23.0, 560.0]
[317, 317]
p02695
u288147331
2,000
1,048,576
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.
['N, M, Q = map(int, input().split())\nabcd = [list(map(int, input().split())) for _ in range(Q)]\n\nans = []\nimport itertools\nfor A in itertools.combinations_with_replacement(range(1, M+1), N):\n tmp = 0\n print(A)\n for a, b, c, d in abcd:\n if A[b-1] - A[a-1] == c:\n tmp += d\n ans.append(tmp)\nprint(max(ans))', 'N, M, Q = map(int, input().split())\nabcd = [list(map(int, input().split())) for _ in range(Q)]\n\nans = []\nimport itertools\nfor A in itertools.combinations_with_replacement(range(1, M+1), N):\n tmp = 0\n for a, b, c, d in abcd:\n if A[b-1] - A[a-1] == c:\n tmp += d\n ans.append(tmp)\nprint(max(ans))']
['Wrong Answer', 'Accepted']
['s139512281', 's671630447']
[12712.0, 12532.0]
[1158.0, 1010.0]
[332, 319]
p02695
u296150111
2,000
1,048,576
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.
['n,m,q=map(int,input().split())\nabcd=[]\nfor _ in range(q):\n\ta,b,c,d=map(int,input().split())\n\tabcd.append((a,b,c,d))\nans=0\np=[]\nsys.setrecursionlimit(10**6)\ndef dfs(x):\n\tif len(x)==n:\n\t\tp.append(x)\n\telse:\n\t\tfor i in range(m-x[-1]+1):\n\t\t\tdfs(x+[x[-1]+i])\ndfs([1])\n# import itertools\n# p=itertools.combinations_with_replacement(range(1,m+1),n)\nfor x in p:\n\tr=0\n\tfor i in range(q):\n\t\tif x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]:\n\t\t\tr+=abcd[i][3]\n\tans=max(ans,r)\nprint(ans)', 'n,m,q=map(int,input().split())\nabcd=[]\nfor _ in range(q):\n\ta,b,c,d=map(int,input().split())\n\tabcd.append((a,b,c,d))\nans=0\np=[]\nsys.setrecursionlimit(10**6)\ndef dfs(x):\n\tif len(x)==n:\n\t\tp.append(x)\n\telse:\n\t\tfor i in range(n-x[-1]+1):\n\t\t\tdfs(x+[x[-1]+i])\ndfs([1])\n# import itertools\n# p=itertools.combinations_with_replacement(range(1,m+1),n)\nfor x in p:\n\tr=0\n\tfor i in range(q):\n\t\tif x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]:\n\t\t\tr+=abcd[i][3]\n\tans=max(ans,r)\nprint(ans)', 'n,m,q=map(int,input().split())\nabcd=[]\nfor _ in range(q):\n\ta,b,c,d=map(int,input().split())\n\tabcd.append((a,b,c,d))\nans=0\np=[]\nimport sys\nsys.setrecursionlimit(10**6)\ndef dfs(x):\n\tif len(x)==n:\n\t\tp.append(x)\n\telse:\n\t\tfor i in range(m-x[-1]+1):\n\t\t\tdfs(x+[x[-1]+i])\ndfs([1])\n# import itertools\n# p=itertools.combinations_with_replacement(range(1,m+1),n)\nfor x in p:\n\tr=0\n\tfor i in range(q):\n\t\tif x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]:\n\t\t\tr+=abcd[i][3]\n\tans=max(ans,r)\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s287181509', 's498339011', 's915975235']
[9180.0, 9240.0, 16132.0]
[21.0, 21.0, 786.0]
[471, 471, 482]
p02695
u303739137
2,000
1,048,576
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.
['import numpy as np\nfrom itertools import combinations_with_replacement\n \nn, m, q = map(int, input().split())\n\npt = np.array(list(combinations_with_replacement(range(1,m+1), n)))\nscore = np.zeros(len(pt))\n\nfor i in range(q):\n a, b, c, d =map(int, input().split())\n flg = pt[:,b-1] - pt[:,a-1] == c\n score += flg * d\n# print(score)\n \nprint(score.max())', 'm, n, q = map(int, input().split())\naa = [0]*q\nbb = [0]*q\ncc = [0]*q\ndd = [0]*q\nfor i in range(q):\n aa[i],bb[i],cc[i], dd[i] = list(map(int, input().split()))\n \nimport itertools\nss = set(itertools.permutations([0]*(n-1)+[1]*(m-1)))\nscore = 0\nfor tu in ss:\n tmp = 0\n xx = [1]*n\n j = 0\n for t in tu:\n if t == 0:\n j += 1\n if t == 1:\n xx[j] += 1\n for i in range(q):\n if xx[bb[i]-1] - xx[aa[i]-1] ==cc[i]: \n tmp += dd[i]\n score = max(score, tmp)\nprint(score) ', 'import numpy as np\nfrom itertools import combinations_with_replacement\n \nn, m, q = map(int, input().split())\n \npt = np.array(list(combinations_with_replacement(range(1,m+1), n)))\nscore = np.zeros(len(pt))\n \nfor i in range(q):\n a, b, c, d =map(int, input().split())\n flg = pt[:,b-1] - pt[:,a-1] == c\n score += flg * d\n# print(score)\n \nprint(int(score.max()))']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s740691681', 's853474947', 's698109102']
[46532.0, 9256.0, 46512.0]
[231.0, 2206.0, 224.0]
[362, 535, 369]
p02695
u307516601
2,000
1,048,576
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.
['n,m,q = [int(i) for i in input().split()]\na = []; b = []; c = []; d = []\nfor _ in range(q):\n l = list(map(int, input().split()))\n a.append(l[0])\n b.append(l[1])\n c.append(l[2])\n d.append(l[3])\n\nans = 0\n\ndef dfs(A):\n global ans\n if len(A) == n+1:\n now = 0\n print(A)\n for i in range(q):\n print(a[i],b[i],c[i],d[i])\n if A[b[i]] - A[a[i]] == c[i]: now += d[i]\n ans = max(ans, now)\n return\n A.append(A[-1])\n while A[-1] <= m:\n dfs(A)\n A[-1] += 1\n \ndfs([1])\n\nprint(ans)', 'n,m,q = [int(i) for i in input().split()]\na = []; b = []; c = []; d = []\nfor _ in range(q):\n l = list(map(int, input().split()))\n a.append(l[0]-1)\n b.append(l[1]-1)\n c.append(l[2])\n d.append(l[3])\n \nans = 0\n\ndef dfs(A):\n global ans\n if len(A) == n+1:\n now = 0\n print(A)\n for i in range(q):\n print(a[i],b[i],c[i],d[i])\n if A[b[i]] - A[a[i]] == c[i]: now += d[i]\n ans = max(ans, now)\n return\n A.append(A[-1])\n while A[-1] <= m:\n dfs(A)\n A[-1] += 1\n \ndfs([1])\n\nprint(ans)', 'import sys\nsys.setrecursionlimit(10**6)\nreadline = sys.stdin.readline\nn,m,q = [int(i) for i in readline().split()]\nabcd = [[int(i) for i in readline().split()] for _ in range(q)]\n\nans = 0\n\ndef dfs(A):\n if len(A) == n:\n now = 0\n for a, b, c, d in abcd:\n if A[b-1] - A[a-1] == c: \n now += d\n global ans\n ans = max(ans, now)\n else:\n for i in range(A[-1], m+1):\n dfs(A+[i])\n\nfor i in range(1, m+1):\n dfs([i])\n\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s529364857', 's880895022', 's286551432']
[9320.0, 9260.0, 9128.0]
[24.0, 22.0, 582.0]
[568, 576, 582]
p02695
u307622233
2,000
1,048,576
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.
["n, m, q = map(int, input().split())\nlst = []\nfor _ in range(q):\n lst_tmp = [int(i) for i in input().split()]\n lst.append(lst_tmp)\n\nlst.sort()\n\nans = 0\nA = list(range(1, -n, -1))\nA[1] = 1\nref = [0] * (n + 1)\n\nfor a, b, c, d in lst:\n if A[b] - A[a] != c:\n if ref[b] < ref[a] + d:\n ans += ref[a] + d - ref[b]\n print('---', a, b, c, ans, ref[a] + d - ref[b], '---', ref[a], d, ref[b], ref)\n ref[b] = ref[a] + d\n A[b] = A[a] + c\n\nfor i in lst:\n print(i)\nprint(A)\nprint(ref)\nprint(ans)\n", 'import itertools\n\nn, m, q = map(int, input().split())\nlst = []\nfor _ in range(q):\n lst_tmp = [int(i) for i in input().split()]\n lst.append(lst_tmp)\n\nans = 0\n\nfor l in itertools.combinations_with_replacement(range(1, m + 1), n):\n tmp_sum = 0\n for a, b, c, d in lst:\n if l[b - 1] - l[a - 1] == c:\n tmp_sum += d\n if ans < tmp_sum:\n ans = tmp_sum\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s013787521', 's863077051']
[9244.0, 9172.0]
[21.0, 967.0]
[543, 395]
p02695
u312158169
2,000
1,048,576
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.
['n,m,q = map(int,input().split())\na = [0] * q\nb = [0] * q\nc = [0] * q\nd = [0] * q\nfor i in range(q):\n a[i], b[i], c[i], d[i]= map(int, input().split())\n\ns = [1] * n\n#st[b[i]] - st[a[i]] = c[i]\nnum = n-1\nans1 = [0] * 100000000\nans = 0\nt = 0\n\nwhile(s[0] != m):\n\n for i in range(q):\n if s[b[i]-1] - s[a[i]-1] == c[i]:\n ans += d[i]\n #print(s)\n #print(ans)\n\n ans1[t] = ans\n t += 1\n\n ans = 0\n\n if s[num] < m:\n s[num] += 1\n elif num > 0 :\n num -= 1\n temp = s[num]+1\n if temp < m:\n for i in range(num,n):\n s[i] = temp\n else:\n while(s[num] == m):\n num -= 1\n temp = s[num]+1\n for i in range(num,n):\n s[i] = temp\n\n num = n-1\n\n\n\n\n\n\nprint(max(ans1))\n', 'n,m,q = map(int,input().split())\na = [0] * q\nb = [0] * q\nc = [0] * q\nd = [0] * q\nfor i in range(q):\n a[i], b[i], c[i], d[i]= map(int, input().split())\n\ns = [1] * n\n#st[b[i]] - st[a[i]] = c[i]\nnum = n-1\nans1 = [0] * 1000000\nans = 0\nt = 0\n\nwhile(s[0] != m):\n\n for i in range(q):\n if s[b[i]-1] - s[a[i]-1] == c[i]:\n ans += d[i-1]\n print(ans)\n\n ans1[t] = ans\n t += 1\n ans = 0\n\n if s[num] < m:\n s[num] += 1\n elif num > 0 :\n num -= 1\n temp = s[num]+1\n if temp < m:\n for i in range(num,n):\n s[i] = temp\n else:\n while(s[num] == m):\n num -= 1\n temp = s[num]+1\n for i in range(num,n):\n s[i] = temp\n\n num = n-1\n\n print(s)\n\n\n\n\nprint(max(ans1))\n', 'n,m,q = map(int,input().split())\na = [0] * q\nb = [0] * q\nc = [0] * q\nd = [0] * q\nfor i in range(q):\n a[i], b[i], c[i], d[i]= map(int, input().split())\n\ns = [1] * n\n#st[b[i]] - st[a[i]] = c[i]\nnum = n-1\n#ans1 = [0] * 10000000\nans = 0\npre_ans = 0\nt = 0\n\nwhile(s[0] != m ):\n\n for i in range(q):\n if s[b[i]-1] - s[a[i]-1] == c[i]:\n ans += d[i]\n #print(s)\n #print(ans)\n ans = max(pre_ans,ans)\n pre_ans = ans\n #t += 1\n\n ans = 0\n\n if s[num] < m:\n s[num] += 1\n elif num > 0 :\n num -= 1\n temp = s[num]+1\n if temp < m:\n for i in range(num,n):\n s[i] = temp\n else:\n while(s[num] == m):\n num -= 1\n temp = s[num]+1\n for i in range(num,n):\n s[i] = temp\n\n num = n-1\n\nfor i in range(q):\n if s[b[i]-1] - s[a[i]-1] == c[i]:\n ans += d[i]\n\nans = max(pre_ans,ans)\n\nprint(ans)\n']
['Time Limit Exceeded', 'Wrong Answer', 'Accepted']
['s012836101', 's771826042', 's824741879']
[793108.0, 19496.0, 9292.0]
[2230.0, 1334.0, 1103.0]
[814, 810, 946]
p02695
u316649390
2,000
1,048,576
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.
['import itertools\nN,M,Q = map(int,input().split())\nL = [list(map(int,input().split())) for _ in range(Q)]\ndata = list(range(1,M+1))\nA=list(itertools.combinations_with_replacement(data,N))\nmax_score = 0\n\nfor Ai in A:\n x = 0\n for a,b,c,d in L:\n if Ai[b] - Ai[a] == c:\n x += d\n max_score = max(max_score,x)\n\nprint(max_score)', 'import itertools\nN,M,Q = map(int,input().split())\nL = [list(map(int,input().split())) for _ in range(Q)]\ndate = list(range(1,M+1))\nA=list(itertools.combinations_with_replacement(data,N))\nmax_score = 0\n\nfor Ai in A:\n x = 0\n for a,b,c,d in L:\n if Ai[b] - Ai[a] == c:\n x += d\n max_score = max(max_score,x)\n \nprint(max_score)', 'import itertools\nN,M,Q = map(int,input().split())\nL = [list(map(int,input().split())) for _ in range(Q)]\ndata = list(range(1,M+1))\nA=list(itertools.combinations_with_replacement(data,N))\nmax_score = 0\n\nfor Ai in A:\n x = 0\n for a,b,c,d in L:\n if Ai[b-1] - Ai[a-1] == c:\n x += d\n max_score = max(max_score,x)\n\nprint(max_score)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s508833634', 's612749080', 's015550511']
[21532.0, 9128.0, 21548.0]
[43.0, 21.0, 1102.0]
[331, 333, 335]
p02695
u317423698
2,000
1,048,576
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.
["import sys\nimport itertools\n\n\ndef resolve(in_):\n n, m, q = map(int, next(in_).split())\n abcd = tuple(tuple(map(int, row.split())) for row in in_)\n print(abcd)\n\n ans = 0\n for seq_a in itertools.combinations_with_replacement(range(1, m + 1), n):\n print(seq_a)\n point = 0\n for a, b, c, d in abcd:\n if seq_a[b - 1] - seq_a[a - 1] == c:\n point += d\n ans = max(ans, point)\n\n return ans\n\n\ndef main():\n answer = resolve(sys.stdin.buffer)\n print(answer)\n\n\nif __name__ == '__main__':\n main()", "import sys\nimport itertools\n\n\ndef resolve(in_):\n n, m, q = map(int, next(in_).split())\n abcd = tuple(tuple(map(int, row.split())) for row in in_)\n # print(abcd)\n\n ans = 0\n for seq_a in itertools.combinations_with_replacement(range(1, m + 1), n):\n # print(seq_a)\n point = 0\n for a, b, c, d in abcd:\n if seq_a[b - 1] - seq_a[a - 1] == c:\n point += d\n ans = max(ans, point)\n\n return ans\n\n\ndef main():\n answer = resolve(sys.stdin.buffer)\n print(answer)\n\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s369259141', 's918059844']
[9200.0, 9112.0]
[599.0, 505.0]
[562, 566]
p02695
u321035578
2,000
1,048,576
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.
["import itertools\ndef main():\n N,M,Q = map(int,input().split())\n q = []\n for i in range(Q):\n a,b,c,d = map(int,input().split())\n q.append([a-1,b-1,c,d])\n A = [i for i in range(1,M+1)]\n if N==10:\n\n ans = 0\n for i, qq in enumerate(q):\n if A[qq[1]] - A[qq[0]] == qq[2]:\n ans += qq[3]\n print(ans)\n\n else:\n aa = list(itertools.combinations(A,N))\n ans = 0\n \n for i, cc in enumerate(aa):\n ans1 = 0\n for j, qq in enumerate(q):\n if cc[qq[1]] - cc[qq[0]] == qq[2]:\n ans1 += qq[3]\n print(ans1,cc)\n ans = max(ans,ans1)\n print(ans)\n\nif __name__=='__main__':\n main()\n", "import itertools\ndef main():\n N,M,Q = map(int,input().split())\n q = []\n for i in range(Q):\n a,b,c,d = map(int,input().split())\n q.append([a-1,b-1,c,d])\n A = [i for i in range(1,M+1)]\n # if N==10:\n #\n # ans = 0\n # for i, qq in enumerate(q):\n \n \n # print(ans)\n #\n # else:\n aa = list(itertools.combinations_with_replacement(A,N))\n ans = 0\n\n for i, cc in enumerate(aa):\n ans1 = 0\n for j, qq in enumerate(q):\n if cc[qq[1]] - cc[qq[0]] == qq[2]:\n ans1 += qq[3]\n # print(ans1,cc)\n ans = max(ans,ans1)\n print(ans)\n\nif __name__=='__main__':\n main()\n"]
['Runtime Error', 'Accepted']
['s637195409', 's729416644']
[9252.0, 21660.0]
[24.0, 627.0]
[747, 746]
p02695
u329049771
2,000
1,048,576
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.
['def dfs(A):\n global ans\n if len(A) == n+1:\n now = 0\n for i in range(q):\n if A[b[i]] - A[a[i]] == c[i]:\n now += d[i]\n ans = max(ans, now)\n return\n\n A.append(A[-1])\n while A[-1] <= m:\n dfs(A)\n A[-1] += 1\n\n\nn, m, q = map(int, input().split())\na, b, c, d = [], [], [], []\nans = 0\n\nfor i in range(q):\n ai, bi, ci, di = map(int, input().split())\n a.append(ai)\n b.append(bi)\n c.append(ci)\n d.append(di)\n\ndfs([1])\nprint(ans)', "# https://www.youtube.com/watch?v=C5_NnCp1CRI&feature=youtu.be\n\nimport sys\nsys.stdin = open('input.txt')\nimport itertools\n\n# C++\n\n# Python\n\n\ndef dfs(A):\n \n global ans\n if len(A) == n+1:\n # print(A)\n now = 0\n for j in range(q):\n if A[b[j]] - A[a[j]] == c[j]:\n now += d[j]\n ans = max(ans, now)\n return\n else:\n \n # A.append(A[-1])\n # A += [A[-1]]\n \n A = A + [A[-1]]\n \n # A = A[:]\n # A.append(A[-1])\n while A[-1] <= m:\n # print(A)\n dfs(A)\n A[-1] += 1\n\n\n# AC\ndef dfs2(i):\n global ans\n for j in range(num[i-1], m):\n num[i] = j\n if i == n:\n print(num)\n now = 0\n for k in range(q):\n if num[b[k]] - num[a[k]] == c[k]:\n now += d[k]\n ans = max(ans, now)\n else:\n dfs2(i+1)\n\ndef solve_combinations_with_replacement(n, m):\n def update_ans(A):\n global ans\n now = 0\n for j in range(q):\n if A[b[j]-1] - A[a[j]-1] == c[j]:\n now += d[j]\n ans = max(ans, now)\n return\n\n global ans\n it = [i for i in range(m)]\n for A in itertools.combinations_with_replacement(it, n):\n update_ans(A)\n\n\nn, m, q = map(int, input().split())\na, b, c, d = [], [], [], []\nans = 0\n\nfor i in range(q):\n ai, bi, ci, di = map(int, input().split())\n a.append(ai)\n b.append(bi)\n c.append(ci)\n d.append(di)\n\ndfs([1])\n\n\n# dfs2(1)\n\n# solve_combinations_with_replacement(n, m)\n\nprint(ans)", '# https://www.youtube.com/watch?v=C5_NnCp1CRI&feature=youtu.be\n\nimport sys\n\nimport itertools\n\n# C++\n\n# Python\n\n\ndef dfs(A):\n \n global ans\n if len(A) == n+1:\n # print(A)\n now = 0\n for j in range(q):\n if A[b[j]] - A[a[j]] == c[j]:\n now += d[j]\n ans = max(ans, now)\n return\n else:\n \n # A.append(A[-1])\n # A += [A[-1]]\n \n A = A + [A[-1]]\n \n # A = A[:]\n # A.append(A[-1])\n while A[-1] <= m:\n # print(A)\n dfs(A)\n A[-1] += 1\n\n\n# AC\ndef dfs2(i):\n global ans\n for j in range(num[i-1], m):\n num[i] = j\n if i == n:\n print(num)\n now = 0\n for k in range(q):\n if num[b[k]] - num[a[k]] == c[k]:\n now += d[k]\n ans = max(ans, now)\n else:\n dfs2(i+1)\n\ndef solve_combinations_with_replacement(n, m):\n def update_ans(A):\n global ans\n now = 0\n for j in range(q):\n if A[b[j]-1] - A[a[j]-1] == c[j]:\n now += d[j]\n ans = max(ans, now)\n return\n\n global ans\n it = [i for i in range(m)]\n for A in itertools.combinations_with_replacement(it, n):\n update_ans(A)\n\n\nn, m, q = map(int, input().split())\na, b, c, d = [], [], [], []\nans = 0\n\nfor i in range(q):\n ai, bi, ci, di = map(int, input().split())\n a.append(ai)\n b.append(bi)\n c.append(ci)\n d.append(di)\n\ndfs([1])\n\n\n# dfs2(1)\n\n# solve_combinations_with_replacement(n, m)\n\nprint(ans)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s295478204', 's421828742', 's057801623']
[9176.0, 9196.0, 9324.0]
[25.0, 25.0, 679.0]
[511, 2157, 2159]
p02695
u330169562
2,000
1,048,576
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.
['import sys\nfrom math import ceil, floor, sqrt, sin, cos, pi\nfrom itertools import accumulate, permutations, combinations\nfrom fractions import gcd \nfrom collections import deque, Counter\nfrom operator import itemgetter\nfrom heapq import heappop,heappush\nsys.setrecursionlimit(10**7)\ndef lcm(x, y): return ((x * y) // gcd(x, y)) \n# list(map(int, input().split()))\n \nn, m, q = map(int, input().split())\nvec = []\na = []\nb = []\nc = []\nd = []\nfor _ in range(q):\n i, j, k, l = map(int, input().split())\n a.append(i - 1)\n b.append(j - 1)\n c.append(k)\n d.append(l)\nit = a + b\nit = list(set(it))\nfor i in range(1, m+1):\n for j in range(len(it)):\n vec.append(i)\nna = []\nnb = []\nfor i in range(q):\n for j in range(len(it)):\n if a[i] == it[j]:\n na.append(j)\n if b[i] == it[j]:\n nb.append(j)\nans = 0\nfor x in combinations(vec, len(it)):\n cnt = 0\n for i in range(q):\n if x[nb[i]] - x[na[i]] == c[i]:\n cnt += d[i]\n #print(x, cnt)\n if ans < cnt:\n ans = cnt\nprint(ans)\nimport sys\nfrom math import ceil, floor, sqrt, sin, cos, pi\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement\nfrom fractions import gcd \nfrom collections import deque, Counter\nfrom operator import itemgetter\nfrom heapq import heappop,heappush\nsys.setrecursionlimit(10**7)\ndef lcm(x, y): return ((x * y) // gcd(x, y)) \n# list(map(int, input().split()))\n\nn, m, q = map(int, input().split())\na = []\nb = []\nc = []\nd = []\nfor _ in range(q):\n i, j, k, l = map(int, input().split())\n a.append(i - 1)\n b.append(j - 1)\n c.append(k)\n d.append(l)\nit = a + b\nit = list(set(it))\nna = []\nnb = []\nfor i in range(q):\n for j in range(len(it)):\n if a[i] == it[j]:\n na.append(j)\n if b[i] == it[j]:\n nb.append(j)\nans = 0\nfor x in combinations_with_replacement(range(1, m+1), len(it)):\n cnt = 0\n for i in range(q):\n if x[nb[i]] - x[na[i]] == c[i]:\n cnt += d[i]\n if ans < cnt:\n ans = cnt\nprint(ans)', 'import sys\nfrom math import ceil, floor, sqrt, sin, cos, pi\nfrom itertools import accumulate, permutations, combinations\nfrom fractions import gcd \nfrom collections import deque, Counter\nfrom operator import itemgetter\nfrom heapq import heappop,heappush\nsys.setrecursionlimit(10**7)\ndef lcm(x, y): return ((x * y) // gcd(x, y)) \n# list(map(int, input().split()))\nn, m, q = map(int, input().split())\nvec = [0]\na = []\nb = []\nc = []\nd = []\nfor _ in range(q):\n i, j, k, l = map(int, input().split())\n a.append(i - 1)\n b.append(j - 1)\n c.append(k)\n d.append(l)\nit = a + b\nit = list(set(it))\nfor i in range(m):\n for j in range(len(it) - 1): vec.append(i)\nna = []\nnb = []\nfor i in range(q):\n for j in range(len(it)):\n if a[i] == it[j]: na.append(j)\n if b[i] == it[j]: nb.append(j)\nans = 0\nfor x in combinations(vec, len(it)):\n cnt = 0\n for i in range(q):\n if x[nb[i]] - x[na[i]] == c[i]: cnt += d[i]\n if ans < cnt: ans = cnt\nprint(ans)', 'import sys\nfrom math import ceil, floor, sqrt, sin, cos, pi\nfrom itertools import accumulate, permutations, combinations\nfrom fractions import gcd \nfrom collections import deque, Counter\nfrom operator import itemgetter\nfrom heapq import heappop,heappush\nsys.setrecursionlimit(10**7)\ndef lcm(x, y): return ((x * y) // gcd(x, y)) \n# list(map(int, input().split()))\n \nn, m, q = map(int, input().split())\nvec = []\na = []\nb = []\nc = []\nd = []\nfor _ in range(q):\n i, j, k, l = map(int, input().split())\n a.append(i - 1)\n b.append(j - 1)\n c.append(k)\n d.append(l)\nit = a + b\nit = list(set(it))\nfor i in range(1, m+1):\n for j in range(len(it)):\n vec.append(i)\nna = []\nnb = []\nfor i in range(q):\n for j in range(len(it)):\n if a[i] == it[j]:\n na.append(j)\n if b[i] == it[j]:\n nb.append(j)\nans = 0\nfor x in combinations(vec, len(it)):\n cnt = 0\n for i in range(q):\n if x[nb[i]] - x[na[i]] == c[i]:\n cnt += d[i]\n #print(x, cnt)\n if ans < cnt:\n ans = cnt\nprint(ans)\nimport sys\nfrom math import ceil, floor, sqrt, sin, cos, pi\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement\nfrom fractions import gcd \nfrom collections import deque, Counter\nfrom operator import itemgetter\nfrom heapq import heappop,heappush\nsys.setrecursionlimit(10**7)\ndef lcm(x, y): return ((x * y) // gcd(x, y)) \n# list(map(int, input().split()))\n\nn, m, q = map(int, input().split())\na = []\nb = []\nc = []\nd = []\nfor _ in range(q):\n i, j, k, l = map(int, input().split())\n a.append(i - 1)\n b.append(j - 1)\n c.append(k)\n d.append(l)\nit = a + b\nit = list(set(it))\nna = []\nnb = []\nfor i in range(q):\n for j in range(len(it)):\n if a[i] == it[j]:\n na.append(j)\n if b[i] == it[j]:\n nb.append(j)\nans = 0\nfor x in combinations_with_replacement(range(1, m+1), len(it)):\n cnt = 0\n for i in range(q):\n if x[nb[i]] - x[na[i]] == c[i]:\n cnt += d[i]\n #print(x, cnt)\n if ans < cnt:\n ans = cnt\nprint(ans)', 'import sys\nfrom math import ceil, floor, sqrt, sin, cos, pi\nfrom itertools import accumulate, permutations, combinations\nfrom fractions import gcd \nfrom collections import deque, Counter\nfrom operator import itemgetter\nfrom heapq import heappop,heappush\nsys.setrecursionlimit(10**7)\ndef lcm(x, y): return ((x * y) // gcd(x, y)) \n# list(map(int, input().split()))\n \nn, m, q = map(int, input().split())\nvec = [1]\na = []\nb = []\nc = []\nd = []\nfor _ in range(q):\n i, j, k, l = map(int, input().split())\n a.append(i - 1)\n b.append(j - 1)\n c.append(k)\n d.append(l)\nit = a + b\nit = list(set(it))\nfor i in range(1, m+1):\n for j in range(len(it) - 1):\n vec.append(i)\nna = []\nnb = []\nfor i in range(q):\n for j in range(len(it)):\n if a[i] == it[j]:\n na.append(j)\n if b[i] == it[j]:\n nb.append(j)\nans = 0\nfor x in combinations(vec, len(it)):\n cnt = 0\n for i in range(q):\n if x[nb[i]] - x[na[i]] == c[i]:\n cnt += d[i]\n #print(x, cnt)\n if ans < cnt:\n ans = cnt\nprint(ans)', 'import sys\nfrom math import ceil, floor, sqrt, sin, cos, pi\nfrom itertools import accumulate, permutations, combinations\nfrom fractions import gcd \nfrom collections import deque, Counter\nfrom operator import itemgetter\nfrom heapq import heappop,heappush\nsys.setrecursionlimit(10**7)\ndef lcm(x, y): return ((x * y) // gcd(x, y)) \n# list(map(int, input().split()))\n\nn, m, q = map(int, input().split())\nvec = []\na = []\nb = []\nc = []\nd = []\nfor _ in range(q):\n i, j, k, l = map(int, input().split())\n a.append(i - 1)\n b.append(j - 1)\n c.append(k)\n d.append(l)\nit = a + b\nit = list(set(it))\nfor i in range(1, m+1):\n for j in range(len(it)):\n vec.append(i)\nna = []\nnb = []\nfor i in range(q):\n for j in range(len(it)):\n if a[i] == it[j]:\n na.append(j)\n if b[i] == it[j]:\n nb.append(j)\nans = 0\nfor x in combinations(vec, len(it)):\n cnt = 0\n for i in range(q):\n if x[nb[i]] - x[na[i]] == c[i]:\n cnt += d[i]\n #print(x, cnt)\n if ans < cnt:\n ans = cnt\nprint(ans)\n', "import sys\nfrom math import ceil, floor, sqrt, sin, cos, pi\nfrom itertools import accumulate, permutations, combinations\nfrom fractions import gcd \nfrom collections import deque, Counter\nfrom operator import itemgetter\nfrom heapq import heappop,heappush\nsys.setrecursionlimit(10**7)\ndef lcm(x, y): return ((x * y) // gcd(x, y)) \n# list(map(int, input().split()))\n \nn, m, q = map(int, input().split())\nvec = []\na = []\nb = []\nc = []\nd = []\nfor _ in range(q):\n i, j, k, l = map(int, input().split())\n a.append(i - 1)\n b.append(j - 1)\n c.append(k)\n d.append(l)\nit = a + b\nit = list(set(it))\nfor i in range(1, m+1):\n for j in range(len(it)):\n vec.append(i)\nna = []\nnb = []\nfor i in range(q):\n for j in range(len(it)):\n if a[i] == it[j]:\n na.append(j)\n if b[i] == it[j]:\n nb.append(j)\nans = 0\nfor x in combinations(vec, len(it)):\n cnt = 0\n for i in range(q):\n if x[nb[i]] - x[na[i]] == c[i]:\n cnt += d[i]\n #print(x, cnt)\n if ans < cnt:\n ans = cnt\nprint(ans)\nimport sys\nfrom math import ceil, floor, sqrt, sin, cos, pi\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement\nfrom fractions import gcd \nfrom collections import deque, Counter\nfrom operator import itemgetter\nfrom heapq import heappop,heappush\nsys.setrecursionlimit(10**7)\ndef lcm(x, y): return ((x * y) // gcd(x, y)) \n# list(map(int, input().split()))\n\nn, m, q = map(int, input().split(' '))\na = []\nb = []\nc = []\nd = []\nfor _ in range(q):\n i, j, k, l = map(int, input().split())\n a.append(i - 1)\n b.append(j - 1)\n c.append(k)\n d.append(l)\nit = a + b\nit = list(set(it))\nna = []\nnb = []\nfor i in range(q):\n for j in range(len(it)):\n if a[i] == it[j]:\n na.append(j)\n if b[i] == it[j]:\n nb.append(j)\nans = 0\nfor x in combinations_with_replacement(range(1, m+1), len(it)):\n cnt = 0\n for i in range(q):\n if x[nb[i]] - x[na[i]] == c[i]:\n cnt += d[i]\n #print(x, cnt)\n if ans < cnt:\n ans = cnt\nprint(ans)", 'from itertools import combinations_with_replacement\n\nn, m, q = map(int, input().split())\na = []\nb = []\nc = []\nd = []\nfor _ in range(q):\n i, j, k, l = map(int, input().split())\n a.append(i - 1)\n b.append(j - 1)\n c.append(k)\n d.append(l)\nit = a + b\nit = list(set(it))\nna = []\nnb = []\nfor i in range(q):\n for j in range(len(it)):\n if a[i] == it[j]:\n na.append(j)\n if b[i] == it[j]:\n nb.append(j)\nans = 0\nfor x in combinations_with_replacement(range(1, m+1), len(it)):\n cnt = 0\n for i in range(q):\n if x[nb[i]] - x[na[i]] == c[i]:\n cnt += d[i]\n if ans < cnt:\n ans = cnt\nprint(ans)']
['Runtime Error', 'Time Limit Exceeded', 'Runtime Error', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Runtime Error', 'Accepted']
['s032174643', 's059769756', 's316132720', 's503679693', 's570663439', 's759305382', 's060828332']
[10460.0, 10344.0, 10460.0, 10468.0, 10472.0, 10316.0, 9264.0]
[2206.0, 2206.0, 2206.0, 2205.0, 2206.0, 2206.0, 968.0]
[2127, 1013, 2146, 1091, 1086, 2149, 664]
p02695
u331327289
2,000
1,048,576
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.
["import sys\nfrom itertools import combinations_with_replacement\nfrom numba import njit\n\n\n@njit('(i8,i8,i8[:,:])')\ndef solve(n, m, query):\n li = [i for i in range(1, m + 1)]\n max_point: int = 0\n for a in combinations_with_replacement(li, n):\n point = 0\n for qer in query:\n if a[qer[1] - 1] - a[qer[0] - 1] == qer[2]:\n point += qer[3]\n if point > max_point:\n max_point = point\n print(max_point)\n\n\ndef main():\n input = sys.stdin.buffer.readline\n n, m, q = map(int, input().split())\n query = [list(map(int, input().split())) for _ in range(q)]\n solve(n, m, query)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\nfrom itertools import combinations_with_replacement\nfrom numba import njit\n\n\n@njit('(i8,i8,i8[:,:])')\ndef solve(n, m, query):\n li = [0] * m\n for i in range(1, m + 1):\n li[i - 1] = i\n max_point: int = 0\n for a in combinations_with_replacement(li, n):\n point = 0\n for qer in query:\n if a[qer[1] - 1] - a[qer[0] - 1] == qer[2]:\n point += qer[3]\n if point > max_point:\n max_point = point\n print(max_point)\n\n\ndef main():\n input = sys.stdin.buffer.readline\n n, m, q = map(int, input().split())\n query = [list(map(int, input().split())) for _ in range(q)]\n solve(n, m, query)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\nfrom itertools import combinations_with_replacement\n\n\ndef main():\n input = sys.stdin.buffer.readline\n n, m, q = map(int, input().split())\n query = [list(map(int, input().split())) for _ in range(q)]\n li = [i for i in range(1, m + 1)]\n max_point = 0\n for a in combinations_with_replacement(li, n):\n point = 0\n for qer in query:\n if a[qer[1] - 1] - a[qer[0] - 1] == qer[2]:\n point += qer[3]\n if point > max_point:\n max_point = point\n print(max_point)\n\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s131275910', 's363697949', 's561846713']
[106332.0, 106272.0, 9168.0]
[523.0, 519.0, 666.0]
[681, 712, 579]
p02695
u339199690
2,000
1,048,576
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.
['from itertools import combinations_with_replacement as cwd\n\nN, M, Q = map(int, input().split())\nA = list(cwd(range(1, M + 1), N))\nABCD = []\n\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n a, b = a - 1, b - 1\n ABCD.append([a, b, c, d])\n\nres = 0\nfor i in A:\n tmp = 0\n for j in ABCD:\n if i[j[1]] - i[j[0]] == j[2]:\n tmp += j[3]\n res = max(res, tmp)\n\nprint(A)\n', 'from itertools import combinations_with_replacement as cwd\n\nN, M, Q = map(int, input().split())\nA = list(cwd(range(1, M + 1), N))\nABCD = []\n\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n a, b = a - 1, b - 1\n ABCD.append([a, b, c, d])\n\nres = 0\nfor i in A:\n tmp = 0\n for j in ABCD:\n if i[j[1]] - i[j[0]] == j[2]:\n tmp += j[3]\n res = max(res, tmp)\n\nprint(res)\n']
['Wrong Answer', 'Accepted']
['s145746494', 's627678705']
[27728.0, 21472.0]
[920.0, 860.0]
[405, 407]
p02695
u342563578
2,000
1,048,576
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.
['n,m,q = map(int,input().split())\na = [0 for i in range(q)]\nfor i in range(q):\n a[i] = list(map(int,input().split()))\nfor i in range(1,m+1):\n for j in range(i,m+1):\n for k in range(j,m+1):\n for s in range(k,m+1):\n for p in range(s,m+1):\n for l in range(p,m+1):\n for e in range(l,m+1):\n for u in range(e,m+1):\n for v in range(u,m+1):\n b = [1,f,c,k,s,p,l,e,u,v]\n nn = 0\n for h in range(q):\n if b[a[h][1]-1] - b[a[h][0]-1] == a[h][2]:\n nn += a[h][3]\n ans = max(ans,nn)\nprint(ans)', 'n,m,q = map(int,input().split())\na = [0 for i in range(q)]\nans = 0\nfor i in range(q):\n a[i] = list(map(int,input().split()))\nfor i in range(1,m+1):\n for j in range(i,m+1):\n for k in range(j,m+1):\n for s in range(k,m+1):\n for p in range(s,m+1):\n for l in range(p,m+1):\n for e in range(l,m+1):\n for u in range(e,m+1):\n for v in range(u,m+1):\n b = [1,i,j,k,s,p,l,e,u,v]\n nn = 0\n for h in range(q):\n if b[a[h][1]-1] - b[a[h][0]-1] == a[h][2]:\n nn += a[h][3]\n ans = max(ans,nn)\nprint(ans)']
['Runtime Error', 'Accepted']
['s650210853', 's789984035']
[9176.0, 9272.0]
[25.0, 755.0]
[836, 844]
p02695
u354075848
2,000
1,048,576
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.
["a, b, n = list(map(lambda x: int(x), input().split(' ')))\n\nprint((a * (n - 1)) // b - a * ((n - 1) // b))", "n, m, q = list(map(lambda x: int(x), input().split(' ')))\n\ne = []\n\nfor i in range(q):\n s = list(map(lambda x: int(x), input().split(' ')))\n e.append(s)\n\ndef helper(l, tmp, n, all):\n if len(tmp) == n:\n r = tmp.copy()\n all.append(r)\n return\n\n for i, v in enumerate(l):\n tmp.append(v)\n helper(l[i:], tmp, n, all)\n tmp.pop()\n\ncandidates = []\nhelper(list(range(1, m+1)), [], n, candidates)\n\nmax_val = 0\n\nfor c in candidates:\n sum = 0\n\n for j in e:\n if c[j[1] - 1] - c[j[0] - 1] == j[2]:\n sum += j[3]\n\n max_val = max(max_val, sum)\n\nprint(max_val)"]
['Wrong Answer', 'Accepted']
['s547990449', 's799772216']
[9080.0, 22912.0]
[20.0, 1027.0]
[105, 573]
p02695
u357949405
2,000
1,048,576
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.
['import itertools\n\nN, M, Q = map(int, input().split())\nABCD = [list(map(int, input().split())) for _ in range(Q)]\n\n\nans = 0\nR = [i for i in range(1, M+1)]\nprint(R)\nfor comb in itertools.combinations_with_replacement(R, N):\n temp = 0\n for abcd in ABCD:\n a, b, c, d = abcd\n if comb[b-1] - comb[a-1] == c:\n temp += d\n if temp >= ans:\n ans = temp\n\n # print("comb: {}, temp: {}, ans: {}".format(comb, temp, ans))\n\nprint(ans)\n', 'import itertools\n\nN, M, Q = map(int, input().split())\nABCD = [list(map(int, input().split())) for _ in range(Q)]\n\n\nans = 0\nR = [i for i in range(1, M+1)]\n# print(R)\n\nfor comb in itertools.combinations_with_replacement(R, N):\n temp = 0\n for abcd in ABCD:\n a, b, c, d = abcd\n if comb[b-1] - comb[a-1] == c:\n temp += d\n if temp >= ans:\n ans = temp\n\n # print("comb: {}, temp: {}, ans: {}".format(comb, temp, ans))\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s128682912', 's619601044']
[9160.0, 9156.0]
[1157.0, 1095.0]
[514, 517]
p02695
u364555831
2,000
1,048,576
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.
['N, M, Q = map(int, input().split())\nA = []\n\nfor i in range(Q):\n A.append(list(map(int, input().split())))\n\ndef calc(B, n):\n ans = 0\n if len(B) < N:\n for i in range(n, M + 1):\n ans = max(ans, calc(B + [i], i))\n return ans\n else:\n for j in range(Q):\n if B[A[j][1]-1] - B[A[j][0]-1] == A[j][2]:\n ans += A[j][3]\n return ans\n\n\nprint(calc([], 1))\n', 'N, M, Q = map(int, input().split())\nA = []\n\nfor i in range(Q):\n A.append(list(map(int, input().split())))\n\ndef calc(B, n):\n ans = 0\n #not enough length\n if len(B) < N:\n for i in range(n, M + 1):\n ans = max(ans, calc(B + [i], i))\n #enough length\n else:\n print("B:", B)\n for j in range(Q):\n if B[A[j][1]-1] - B[A[j][0]-1] == A[j][2]:\n ans += A[j][3]\n print("ans:", ans)\n return ans\n\n\n\nprint(calc([], 1))\n', 'N, M, Q = map(int, input().split())\nA = []\n\nfor i in range(Q):\n A.append(list(map(int, input().split())))\n\ndef calc(B, n):\n ans = 0\n #not enough length\n if len(B) < N:\n for i in range(n, M + 1):\n ans = max(ans, calc(B + [i], i))\n #enough length\n else:\n \n for j in range(Q):\n if B[A[j][1]-1] - B[A[j][0]-1] == A[j][2]:\n ans += A[j][3]\n #print("ans:", ans)\n return ans\n\n\n\nprint(calc([], 1))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s572807109', 's927712136', 's152517720']
[9212.0, 9068.0, 9112.0]
[31.0, 1106.0, 958.0]
[376, 438, 440]
p02695
u364862909
2,000
1,048,576
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.
['import itertools\n\nN,M,Q = map(int,input().split())\na=[]\nb=[]\nc=[]\nd=[]\nfor i in range(0,Q,1):\n tmp = list(map(int,input().split()))\n a.append(tmp[0])\n b.append(tmp[1])\n c.append(tmp[2])\n d.append(tmp[3])\n\nmax_score = -1\nfor i in itertools.combinations_with_replacement(range(1,M,1),N):\n score = 0\n for j in range(0,Q,1):\n if i[b[j]-1]-i[a[j]-1]==c[j]:\n score += d[j]\n if max_score < score:\n max_score = score\n\nprint(max_score)', 'import itertools\n\nN,M,Q = map(int,input().split())\na=[]\nb=[]\nc=[]\nd=[]\nfor i in range(0,Q,1):\n tmp = list(map(int,input().split()))\n a.append(tmp[0])\n b.append(tmp[1])\n c.append(tmp[2])\n d.append(tmp[3])\n\nmax_score = -1\nfor i in itertools.combinations_with_replacement(range(1,M+1,1),N):\n score = 0\n for j in range(0,Q,1):\n if i[b[j]-1]-i[a[j]-1]==c[j]:\n score += d[j]\n if max_score < score:\n max_score = score\n\nprint(max_score)\n']
['Wrong Answer', 'Accepted']
['s659755485', 's707615160']
[9172.0, 9164.0]
[540.0, 1089.0]
[475, 478]
p02695
u370721525
2,000
1,048,576
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.
['import itertools\nN, M ,Q = map(int, input().split())\nl = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n l.append([a, b, c, d])\n \nnum = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\nnums = list(itertools.combinations_with_replacement(nums, 10))\nscores = []\nfor row in nums:\n score = 0\n i = 0\n while i < Q:\n if row[l[i][1]]-row[l[i][0]] == l[i][2]:\n score += l[i][3]\n i += 1\n scores.append(score)\n \nprint(max(scores))', 'import itertools\nN, M ,Q = map(int, input().split())\nl = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n l.append([a, b, c, d])\n \nnums = list(itertools.combinations_with_replacement(range(1, M+1), N))\nscores = []\nfor row in nums:\n score = 0\n i = 0\n while i < Q:\n if row[l[i][1]-1]-row[l[i][0]-1] == l[i][2]:\n score += l[i][3]\n i += 1\n scores.append(score)\n \nprint(max(scores))']
['Runtime Error', 'Accepted']
['s324438895', 's697504132']
[9232.0, 25156.0]
[23.0, 1559.0]
[436, 410]
p02695
u377265351
2,000
1,048,576
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.
['[n,m,q] = list(map(int,input().split(" ")))\na = []\nfor i in range (q):\n a.append(list(map(int,input().split(" "))))\nans = 0\nfor i in range (10**n):\n tmp = 0\n nlst = [1 for t in range(n)]\n for j in range (len(str(i))):\n nlst[j]=int(str(i)[j])+1\n if max(nlst)<=m and nlst==sorted(nlst):\n for k in range(q):\n a_ = a[k][0]\n b_ = a[k][1]\n c_ = a[k][2]\n d_ = a[k][3]\n if nlst[b_-1]-nlst[a_-1]==c_:\n tmp = tmp + d_\n if ans < tmp:\n ans = tmp\n \nprint(ans)', '[n,m,q] = list(map(int,input().split(" ")))\nlst = []\nfor i in range (q):\n lst.append(list(map(int,input().split(" "))))\n\ny = [1 for i in range(n)]\n\ndef f(index,li):\n if index == n:\n return eva(li)\n else:\n ret = 0\n t = 1\n if index>=1:\n t = li[index-1]\n for i in range (t,m+1):\n li[index]=i\n x = f(index+1,li)\n if ret < x:\n ret = x\n return ret\n \ndef eva(li):\n tmp = 0\n for k in range(q):\n a = lst[k][0]\n b = lst[k][1]\n c = lst[k][2]\n d = lst[k][3]\n if li[b-1]-li[a-1]==c:\n tmp = tmp + d\n return tmp\n \nprint(f(0,y))']
['Wrong Answer', 'Accepted']
['s750673059', 's347821760']
[9192.0, 9256.0]
[2205.0, 1222.0]
[566, 683]
p02695
u377834804
2,000
1,048,576
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.
['N, M, Q = map(int, input().split())\nreqs = [list(map(int, input().split())) for _ in range(Q)]\n\nAs = []\n\ndef make(A):\n global As, N, M\n if len(A) == N+1:\n As.append(A)\n elif:\n for i in range(A[len(A)-1], M+1):\n A.append(i)\n\nmake([1])\n\nmax = 0\nfor A in As:\n score = 0\n for req in reqs:\n if A[req[1]] - A[req[0]] == req[2]:\n score += req[3]\n max = max(score, max)\n\nprint(max)', 'N, M, Q = map(int, input().split())\nreqs = [list(map(int, input().split())) for _ in range(Q)]\n\nAs = []\n\ndef make(A):\n global As, N, M\n print(A)\n if len(A) == N+1:\n As.append(A)\n else:\n for i in range(A[len(A)-1], M+1):\n make(A+[i])\n\nmake([1])\n\nmaxs = 0\nfor A in As:\n score = 0\n for req in reqs:\n if A[req[1]] - A[req[0]] == req[2]:\n score += req[3]\n maxs = max(score, maxs)\n\nprint(maxs)\n', 'N, M, Q = map(int, input().split())\nreqs = [list(map(int, input().split())) for _ in range(Q)]\n \nAs = []\n \ndef make(A):\n global As, N, M\n if len(A) == N+1:\n As.append(A)\n else:\n for i in range(A[len(A)-1], M+1):\n A.append(i)\n \nmake([1])\n \nmax = 0\nfor A in As:\n score = 0\n for req in reqs:\n if A[req[1]] - A[req[0]] == req[2]:\n score += req[3]\n max = max(score, max)\n \nprint(max)', 'N, M, Q = map(int, input().split())\nreqs = [list(map(int, input().split())) for _ in range(Q)]\n\nAs = []\n\ndef make(A):\n global As, N, M\n # print(A)\n if len(A) == N+1:\n As.append(A)\n else:\n for i in range(A[len(A)-1], M+1):\n make(A+[i])\n\nmake([1])\n\nmaxs = 0\nfor A in As:\n score = 0\n for req in reqs:\n if A[req[1]] - A[req[0]] == req[2]:\n score += req[3]\n maxs = max(score, maxs)\n\nprint(maxs)']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s685985370', 's720080284', 's943046421', 's203648493']
[9040.0, 24304.0, 9140.0, 24248.0]
[21.0, 1126.0, 24.0, 944.0]
[398, 414, 403, 415]
p02695
u387080888
2,000
1,048,576
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.
['a=list(map(int,input().split()))\nb=[]\nans=0\nc=[]\nfor _ in range(a[2]):\n b.append(list(map(int,input().split())))\n\nfor i in range(1,a[1]+1):\n for j in range(i,a[1]+1):\n for k in range(j,a[1]+1):\n c=[i,j,k]\n for l in range(a[2]):\n if c[b[l][1]-1]-c[b[l][0]-1]==b[l][2]:\n ans+=b[l][3]\n d.append(ans)\n ans=0\nprint(max(d))', 'import itertools\na=list(map(int,input().split()))\nb=[]\nans=0\nc=range(1,a[1]+1)\nd=[]\nfor _ in range(a[2]):\n b.append(list(map(int,input().split())))\n\n\nfor i in itertools.combinations_with_replacement(c,a[0]):\n for l in range(a[2]):\n if i[b[l][1]-1]-i[b[l][0]-1]==b[l][2]:\n ans+=b[l][3]\n d.append(ans)\n ans=0\nprint(max(d))']
['Runtime Error', 'Accepted']
['s510634797', 's598215205']
[9212.0, 12848.0]
[24.0, 1415.0]
[408, 350]
p02695
u405483159
2,000
1,048,576
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.
["\nN, M, Q = map( int, input().split() )\n\npoint_list = []\nfor i in range( Q ):\n a, b, c, d = map( int, input().split())\n point_list.append( [ a, b, c, d ] )\n \nl = ['{0:04b}'.format(i) for i in range( 2 ** M ) if sum(list(map(int, '{0:04b}'.format(i)))) == N]\n\ndef bin_to_numlist( bin ):\n l = []\n cnt = 1\n for i in list(map(int, bin)):\n if i == 1:\n l.append( cnt )\n cnt += 1\n return l\n\ntarget = map( bin_to_numlist, l )\nmax_point = 0\nfor t in target:\n point = 0\n for a, b, c, d in point_list:\n if t[ b - 1 ] - t[ a - 1 ] == c:\n point += d\n max_point = max( max_point, point )\n print( t, point )\nprint( max_point )\n", 'import itertools\nN, M, Q = map( int, input().split() )\n\npoint_list = []\nfor i in range( Q ):\n a, b, c, d = map( int, input().split() )\n point_list.append( [ a, b, c, d ] )\n\nall_lists = itertools.combinations_with_replacement(range( 1, M + 1 ), N)\n\nmax_point = 0\nfor t in all_lists:\n point = 0\n for p in point_list:\n a, b, c, d = p\n if t[ b - 1 ] - t[ a - 1 ] == c:\n point += d\n max_point = max( max_point, point )\nprint( max_point )\n']
['Wrong Answer', 'Accepted']
['s500035307', 's649447711']
[9188.0, 9232.0]
[20.0, 1175.0]
[679, 449]
p02695
u411923565
2,000
1,048,576
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.
['#C - Many Requirements\n\nN,M,Q = map(int,input().split())\nabcd = []\nfor _ in range(Q):\n a,b,c,d = map(int,input().split())\n abcd.append((a,b,c,d))\ndef dfs(A):\n if len(A) == N:\n \n score = 0\n for ai,bi,ci,di in abcd:\n if A[bi-1] -A[ai-1] == ci:\n score += di\n return score\n max_score = 0 \n \n if len(A) > 1:\n prev_last = A[-1]\n else:\n prev_last = 1\n \n for i in range(prev_last,M+1):\n A.append(i)\n max_score = max(max_score,dfs(A))\n A.pop()\n return max_score\nprint(dfs[])', '#C - Many Requirements\n\nN,M,Q = map(int,input().split())\nabcd = []\nfor _ in range(Q):\n a,b,c,d = map(int,input().split())\n abcd.append((a,b,c,d))\nmax_score = 0\ndef dfs(A):\n global max_score\n if len(A) == N:\n \n score = 0\n for ai,bi,ci,di in abcd:\n if A[bi-1] -A[ai-1] == ci:\n score += di\n return score\n \n if len(A) >= 1:\n prev_last = A[-1]\n else:\n prev_last = 1\n \n for i in range(prev_last,M+1):\n A.append(i)\n max_score = max(max_score,dfs(A))\n A.pop()\n return max_score\ndfs([])\nprint(max_score)']
['Runtime Error', 'Accepted']
['s270930736', 's614998609']
[9024.0, 9268.0]
[22.0, 577.0]
[750, 779]
p02695
u423193302
2,000
1,048,576
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.
['import itertools\nn,m,q = (int(x) for x in input().split())\nl = []\na = [1,2,3,4,5,6,7,8,9,10]\nb = []\nc = []\nd = []\n\n\nfor i in range(q):\n l.append([])\n l[i]=list(map(int, input().split()))\n \nfor i in itertools.combinations_with_replacement(a[:m], r=n):\n b.append(i) \nprint(b) \n \nfor i in range(len(b)):\n d.append(0)\n\nfor i in range(q):\n w=l[i][0]-1#a\n x=l[i][1]-1#b\n y=l[i][2]#c\n z=l[i][3]#d\n for j in range(len(b)):\n if b[j][x]-b[j][w]==y:\n d[j]+=z\n\nprint(max(d))', 'import itertools\nn,m,q = (int(x) for x in input().split())\nl = []\na = [1,2,3,4,5,6,7,8,9,10]\nb = []\nc = []\nd = []\n\n\nfor i in range(q):\n l.append([])\n l[i]=list(map(int, input().split()))\n \nfor i in itertools.combinations_with_replacement(a[:m], r=n):\n b.append(i) \n \nfor i in range(len(b)):\n d.append(0)\n\nfor i in range(q):\n w=l[i][0]-1#a\n x=l[i][1]-1#b\n y=l[i][2]#c\n z=l[i][3]#d\n for j in range(len(b)):\n if b[j][x]-b[j][w]==y:\n d[j]+=z\n\nprint(max(d))\n']
['Wrong Answer', 'Accepted']
['s906453724', 's756376248']
[27632.0, 25268.0]
[1058.0, 973.0]
[580, 571]
p02695
u428199834
2,000
1,048,576
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.
['N,M,Q=map(int,input().split())\na=[0]*Q\nb=[0]*Q\nc=[0]*Q\nd=[0]*Q\nfor i in range(Q):\n a[i],b[i],c[i],d[i]=map(int,input().split())\nimport itertools\nfor A in itertools.combinations_with_replacement(range(1,M+1),N):\n ans=0\n if i in range(Q):\n s=0\n A[b[i]]-A[a[i]]=c[i]\n s+=d[i]\n ans=max(ans,s)\nprint(ans) ', 'N,M,Q=map(int,input().split())\na=[0]*Q\nb=[0]*Q\nc=[0]*Q\nd=[0]*Q\nfor i in range(Q):\n a[i],b[i],c[i],d[i]=map(int,input().split())\nimport itertools\nfor A in itertools.combinations_with_replacement(range(1,M+1),N):\n ans=0\n if i in range(Q):\n s=0\n if A[b[i]]-A[a[i]]==c[i]:\n s+=d[i]\n ans=max(ans,s)\nprint(ans) \n ', 'n,m,q=map(int,input().split())\ndef dfs(seq):\n u=0\n if len(seq)==n:\n ans=0\n for a,b,c,d in data:\n if seq[b-1]-seq[a-1]==c:\n ans+=d\n return ans\n else:\n for i in range(seq[-1],m+1):\n seq_next=seq.copy()\n seq_next.append(i)\n u=max(u,dfs(seq_next))\n return u\n\ndata=[]\nfor _ in range(q):\n A=list(map(int,input().split()))\n data.append(A)\nprint(dfs([1]))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s175474251', 's656881980', 's259982903']
[9000.0, 8852.0, 9196.0]
[20.0, 23.0, 318.0]
[337, 363, 457]
p02695
u430336181
2,000
1,048,576
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.
['N, M ,Q = map(int, input().aplist())\nlists = [list(map(int, input().split())) for i in range(Q)]\nans = 0\n\ndef calc_score(A):\n score = 0\n for a, b, c, d in lists:\n if A[b -1] - A[a - 1] == c:\n score += d\n return score\n\ndef dfs(A):\n global ans\n if len(A) == N:\n score = calc_score(A)\n ans = max(score, ans)\n return\n for n in range(A[-1], M + 1):\n dfs(A + [n])\n \ndfs([1])\nprint(ans)\n', 'N, M, Q = map(int, input().split())\nlists = [list(map(int, input().split())) for i in range(Q)]\nans = 0\n\ndef calc_score(A):\n score = 0\n for a, b, c, d in lists:\n if A[b - 1] - A[a - 1] == c:\n score += d\n return score\n\ndef dfs(A):\n global ans\n if len(A) == N:\n score = calc_score(A)\n ans = max(score, ans)\n return\n for n in range(A[-1], M + 1):\n dfs(A + [n])\n\ndfs([1])\nprint(ans)']
['Runtime Error', 'Accepted']
['s597745912', 's282788993']
[9084.0, 9164.0]
[21.0, 319.0]
[451, 430]
p02695
u449473917
2,000
1,048,576
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.
['from itertools import *\nfrom more_itertools import *\n\nn,m,q=map(int,input().split())\n\naaa=[]\nfor i in range(m):\n aaa.append(i+1)\n\nl=[]\nfor i in range(q):\n a=list(map(int,input().split()))\n l.append(a)\n\na=list(combinations_with_replacement(aaa,n))\nans=0\nfor i in a:\n aa=0\n for j in l:\n if i[j[1]-1]-i[j[0]-1]==j[2]:\n aa+=j[3]\n if aa>ans:\n ans=aa\nprint(ans)', 'from itertools import *\n\nn,m,q=map(int,input().split())\n\naaa=[]\nfor i in range(m):\n aaa.append(i+1)\n\nl=[]\nfor i in range(q):\n a=list(map(int,input().split()))\n l.append(a)\n\na=list(combinations_with_replacement(aaa,n))\nans=0\nfor i in a:\n aa=0\n for j in l:\n if i[j[1]-1]-i[j[0]-1]==j[2]:\n aa+=j[3]\n if aa>ans:\n ans=aa\nprint(ans)']
['Runtime Error', 'Accepted']
['s743071852', 's875663997']
[9188.0, 21464.0]
[21.0, 948.0]
[398, 369]
p02695
u457460736
2,000
1,048,576
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.
['N,M,Q=map(int,input().split())\n\nal=list()\n\nfor i in range(Q): \n a,b,c,d=map(int,input().split())\n al.append([a,b,c,d])\n\n\nSum=0\nSummax=0\ncnt=0\nfor i1 in range(1,M+1): \n for i2 in range(i1,M+1): \n for i3 in range(i2,M+1): \n for i4 in range(i3,M+1): \n for i5 in range(i4,M+1): \n for i6 in range(i5,M+1): \n for i7 in range(i6,M+1): \n for i8 in range(i7,M+1): \n for i9 in range(i8,M+1): \n for i10 in range(i9,M+1): \n cnt+=1\n Al=[i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]\n Sum=0\n for i in range(Q): \n if(Al[al[i][1]-1]-Al[al[i][0]-1]==al[i][2]):\n Sum+=al[i][3]\n if(Summax<Sum):\n Summax=Sum\n\nprint(Summax) \nprint(cnt)', 'N,M,Q=map(int,input().split())\n\nal=list()\n\nfor i in range(Q): \n a,b,c,d=map(int,input().split())\n al.append([a,b,c,d])\n\n\nSum=0\nSummax=0\ncnt=0\nfor i1 in range(1,M+1): \n for i2 in range(i1,M+1): \n for i3 in range(i2,M+1): \n for i4 in range(i3,M+1): \n for i5 in range(i4,M+1): \n for i6 in range(i5,M+1): \n for i7 in range(i6,M+1): \n for i8 in range(i7,M+1): \n for i9 in range(i8,M+1): \n for i10 in range(i9,M+1): \n cnt+=1\n Al=[i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]\n Sum=0\n for i in range(Q): \n if(Al[al[i][1]-1]-Al[al[i][0]-1]==al[i][2]):\n Sum+=al[i][3]\n if(Summax<Sum):\n Summax=Sum\n\nprint(Summax) \n#print(cnt)']
['Wrong Answer', 'Accepted']
['s648763330', 's544632830']
[9292.0, 9292.0]
[1399.0, 1311.0]
[1108, 1109]
p02695
u467736898
2,000
1,048,576
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.
['from itertools import combinations_with_replacement\nN, M, Q = map(int, input().split())\nABCD = [list(map(int, input().split())) for _ in range(Q)]\nans = 0\nfor t in combinations_with_replacement(range(1, M+1), N):\n an = 0\n for a, b, c, d in ABCD:\n if t[b-1]-t[a-1] == c:\n an += d\n if ans < an:\n ans = an\nprint(an', 'from itertools import combinations_with_replacement\nN, M, Q = map(int, input().split())\nABCD = [list(map(int, input().split())) for _ in range(Q)]\nans = 0\nfor t in combinations_with_replacement(range(1, M+1), N):\n an = 0\n for a, b, c, d in ABCD:\n if t[b-1]-t[a-1] == c:\n an += d\n if ans < an:\n ans = an\nprint(ans)']
['Runtime Error', 'Accepted']
['s810112169', 's828356618']
[9056.0, 9120.0]
[22.0, 975.0]
[345, 347]
p02695
u469936642
2,000
1,048,576
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.
['from itertools import combinations as c\nn, m, q = map(int, input().split())\narr = []\nfor i in range(q):\n l = [*map(int, input().split())]\n arr.append(l)\nres = 0\nfor g in c(list(range(1, m+1)), n):\n f = 0\n for h in arr:\n if g[1] - g[0] == g[2]:\n f += g[3]\n res = max(res, f)\nprint(res)', 'from itertools import combinations_with_replacement as c \nn, m, q = map(int, input().split()) \narr = [] \nfor i in range(q): \n l = [*map(int, input().split())] \n arr.append(l) \nres = 0\nfor g in c(list(range(1, m+1)), n): \n f = 0 \n for h in arr:\n if g[h[1]-1] - g[h[0]-1] == h[2]: \n f += h[3]\n res = max(res, f) \nprint(res)\n']
['Runtime Error', 'Accepted']
['s311723802', 's609084355']
[9216.0, 9080.0]
[20.0, 941.0]
[297, 355]
p02695
u474484450
2,000
1,048,576
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.
["cin = open(0).read().strip().split('\\n')\nn, m, q = map(int, cin[0].split(' '))\nabcd = [tuple(map(int, a.split(' '))) for a in cin[1:]]\n\nret = 0\nfor case in itertools.combinations_with_replacement(list(range(1,m+1)), n):\n tmp = 0\n for c in abcd:\n if case[c[1]-1] - case[c[0]-1] == c[2]:\n tmp += c[3]\n ret = max(ret, tmp)\nprint(ret)", "cin = open(0).read().strip().split('\\n')\nn, m, q = map(int, cin[0].split(' '))\nabcd = [tuple(map(int, a.split(' '))) for a in cin[1:]]\n\nret = 0\nimport itertools\nfor case in itertools.combinations_with_replacement(list(range(1,m+1)), n):\n tmp = 0\n for c in abcd:\n if case[c[1]-1] - case[c[0]-1] == c[2]:\n tmp += c[3]\n ret = max(ret, tmp)\nprint(ret)"]
['Runtime Error', 'Accepted']
['s247901536', 's082850950']
[9220.0, 9212.0]
[24.0, 1050.0]
[357, 374]
p02695
u476674874
2,000
1,048,576
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.
["import itertools\ndef generateA(N, M):\n m = range(1, M+1)\n A = [1 for i in range(N)]\n lastA = [M for i in range(N)]\n while True:\n yield A\n if A == lastA:\n break\n for i in range(N):\n if A[N-1-i] == M:\n continue\n A[N-1-i] += 1\n for j in range(N-1-i+1, N):\n A[j] = 1\n break\n\ndef point(A, L):\n result = 0\n for (a, b, c, d) in L:\n if A[b-1] - A[a-1] == c:\n result += d\n\n return result\n\ndef summary(N, M, L):\n As = generateA(N, M)\n\n results = []\n for A in As:\n print(A)\n results.append(point(A,L))\n return results\n\ndef main():\n N, M ,Q = map(int, input().split())\n L = []\n for i in range(Q):\n a, b, c, d = map(int, input().split())\n L.append((a,b,c,d))\n results = summary(N,M,L)\n\n print(max(results))\n\nif __name__ == '__main__':\n main()", "import itertools\ndef generateA(N, M, minv=1):\n if N < 0:\n return\n if N == 0:\n yield []\n if N == 1:\n for i in range(minv, M):\n yield [i]\n for v in range(minv, M+1):\n for subA in generateA(N-1, M, v):\n yield [v] + subA\n\ndef point(A, L):\n result = 0\n for (a, b, c, d) in L:\n if A[b-1] - A[a-1] == c:\n result += d\n\n return result\n\ndef summary(N, M, L):\n As = generateA(N, M)\n\n results = []\n for A in As:\n results.append(point(A,L))\n return results\n\ndef test():\n As = generateA(3,4)\n for A in As:\n print(A)\n\ndef main():\n #test()\n N, M ,Q = map(int, input().split())\n L = []\n for i in range(Q):\n a, b, c, d = map(int, input().split())\n L.append((a,b,c,d))\n results = summary(N,M,L)\n\n print(max(results))\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s079042302', 's272367145']
[52068.0, 14384.0]
[2272.0, 981.0]
[932, 889]
p02695
u479638406
2,000
1,048,576
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.
['import math\ndef solve():\n n, m, q = map(int, input().split())\n l = [list(map(int, input().split())) for _ in range(q)]\n\n ans = 0\n for i in range(2**(n-2)):\n cur = []\n for j in range(n-2):\n if (i>>j)&1:\n cur.append(i+1)\n A = [1] + cur + [n, m]\n print(A)\n tot = 0\n for k in range(q):\n a, b, c, d = l[k]\n if b+1 <= n and A[b] - A[a] == c:\n print(A[0], A[a])\n tot += d\n ans = max(ans, tot)\n \n return ans\n\n\nprint(solve())\n', 'from itertools import combinations_with_replacement\ndef solve():\n n, m, q = map(int, input().split())\n l = [list(map(int, input().split())) for _ in range(q)]\n\n com = [int(x) for x in range(1, m+1)]\n ans = 0\n for i in combinations_with_replacement(com, n-1):\n cur = list(i)\n A = [1] + cur\n tot = 0\n for k in range(q):\n a, b, c, d = l[k]\n if A[b-1] - A[a-1] == c:\n tot += d\n ans = max(ans, tot)\n \n return ans\n\n\nprint(solve())\n']
['Runtime Error', 'Accepted']
['s817373750', 's084798547']
[9164.0, 9216.0]
[28.0, 353.0]
[562, 518]
p02695
u479719434
2,000
1,048,576
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.
['import itertools\nN, M, Q = map(int, input().split())\na = [None for _ in range(Q)]\nb = [None for _ in range(Q)]\nc = [None for _ in range(Q)]\nd = [None for _ in range(Q)]\nfor i in range(Q):\n a[i], b[i], c[i], d[i] = map(int, input().split())\n\nans = 0\nelements = list(range(1, M+1))\nfor combination in itertools.combinations_with_replacement(elements, N):\n score = 0\n for i in range(Q):\n print(combination, b[i], a[i])\n if combination[b[i]-1] - combination[a[i]-1] == c[i]:\n score += d[i]\n ans = max(score, ans)\nprint(ans)\n', 'def combinations_with_replacement(elements, N):\n for i, element in enumerate(elements):\n if N == 1:\n yield [element]\n else:\n for combination in combinations_with_replacement(elements[:i+1], N-1):\n combination.append(element)\n yield combination\n\n\nN, M, Q = map(int, input().split())\na = [None for _ in range(Q)]\nb = [None for _ in range(Q)]\nc = [None for _ in range(Q)]\nd = [None for _ in range(Q)]\nfor i in range(Q):\n a[i], b[i], c[i], d[i] = map(int, input().split())\n\nans = 0\nelements = list(range(1, M+1))\nfor combination in combinations_with_replacement(elements, N):\n score = 0\n for i in range(Q):\n if combination[b[i]-1] - combination[a[i]-1] == c[i]:\n score += d[i]\n ans = max(score, ans)\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s487549977', 's897352111']
[50064.0, 9136.0]
[2286.0, 1227.0]
[557, 806]
p02695
u486065927
2,000
1,048,576
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.
['import itertools\n \ndef check(lis, a):\n return sum((i[3] for i in a if lis[i[1]-1]-lis[i[0]-1]==i[2]))\n \nn, m, q = map(int, input().split())\na = ((int(i) for i in input().split(" ")) for j in range(q))\nans = 0\nfor i in itertools.combinations_with_replacement(range(m), n):\n ans = max(ans, check(i, a))\nprint(ans)', 'import itertools\n \ndef check(lis, a):\n return sum((i[3] for i in a if lis[i[1]-1]-lis[i[0]-1]==i[2]))\n \nn, m, q = map(int, input().split())\na = [[int(i) for i in input().split(" ")] for j in range(q)]\nans = 0\nfor i in itertools.combinations_with_replacement(range(m), n):\n ans = max(ans, check(i, a))\nprint(ans)']
['Runtime Error', 'Accepted']
['s363430482', 's109825472']
[9104.0, 9104.0]
[20.0, 713.0]
[319, 319]
p02695
u506858457
2,000
1,048,576
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.
["N,M,Q=map(int,input().split())\nL = []\nfor i in range(Q):\n L.append(list(map(int, input().split())))\n #print(L[i][1])\nimport itertools\n\nl =list(range(1,M+1))\nans=0\n\nv=list(itertools.combinations(l,N))\nprint(v)\nfor j in range(len(v)):\n for i in range(Q):\n if (v[j][L[i][1]-1] - v[j][L[i][0]-1])==L[i][2]:\n print(v[j][L[i][1]-1],v[j][L[i][0]-1],L[i][2])\n ans+=L[i][3]\nprint(ans)\n\n'''\n\nfor i in range(Q): \n for v in itertools.combinations(l,N):\n if (v[L[i][1]-1] - v[L[i][0]-1])==L[i][2]:\n print(v[L[i][1]-1],v[L[i][0]-1],L[i][2])\n ans+=L[i][3]\nprint(ans)\n'''", 'N,M,Q=map(int,input().split())\nL=[]\nfor i in range(Q):\n L.append(list(map(int,input().split())))\n L[i][0]-=1\n L[i][1]-=1\n\nimport itertools\nL=list(range(1,M+1))\nA=list(itertools.combinations_with_replacement(L,N))\nans=0\nfor i in A:\n tmp=0\n for a,b,c,d in L:\n if (i[b]-i[a])==c:\n tmp+=d\n ans=max(ans,tmp)\nprint(ans)', 'def II(): return int(input())\ndef MI(): return map(int, input().split())\ndef LI(): return list(map(int, input().split()))\nfrom itertools import combinations_with_replacement\nN,M,Q=MI()\nA=[]\nB=[]\nC=[]\nD=[]\nans=0\nfor i in range(Q):\n a,b,c,d=MI()\n a-=1\n b-=1\n A.append(a)\n B.append(b)\n C.append(c)\n D.append(d)\n#print(A,B,C,D)\nNum=list(range(1,M+1))\n#print(Num)\n#print(list(combinations(Num,N)))\nfor j in list(combinations_with_replacement(Num,N)):\n tmp=0\n for i in range(Q):\n if j[B[i]]-j[A[i]]==C[i]:\n tmp+=D[i]\n ans=max(ans,tmp) \nprint(ans)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s130137532', 's547496320', 's662007461']
[9244.0, 21532.0, 21616.0]
[22.0, 45.0, 974.0]
[587, 327, 559]
p02695
u511457539
2,000
1,048,576
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.
['import itertools\n\nN, M, Q = map(int, input().split())\nabcd = [list(map(int, input().split())) for i in range(Q)]\n\nanswer = 0\n\nnums=[]\nfor i in range(1, M+1):\n nums.append(i)\n\nfor balls in itertools.combinations_with_replacement(nums, N):\n score = 0\n for i in range(Q):\n test = list(balls)\n print(test)\n if test[abcd[i][0]-1] + abcd[i][2] == test[abcd[i][1]-1]:\n score += abcd[i][3]\n if score > answer:\n answer = score\n\nprint(answer)\n', 'import itertools\n\nN, M, Q = map(int, input().split())\nabcd = [list(map(int, input().split())) for i in range(Q)]\n\nanswer = 0\n\nnums=[]\nfor i in range(1, M+1):\n nums.append(i)\n\nfor balls in itertools.combinations_with_replacement(nums, N):\n score = 0\n test = list(balls)\n for i in range(Q):\n if test[abcd[i][0]-1] + abcd[i][2] == test[abcd[i][1]-1]:\n score += abcd[i][3]\n if score > answer:\n answer = score\n\nprint(answer)\n']
['Wrong Answer', 'Accepted']
['s524783514', 's608883244']
[52112.0, 9212.0]
[2309.0, 1429.0]
[484, 460]
p02695
u518085378
2,000
1,048,576
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.
['4 6 10\n2 4 1 86568\n1 4 0 90629\n2 3 0 90310\n3 4 1 29211\n3 4 3 78537\n3 4 2 8580\n1 2 1 96263\n1 4 2 2156\n1 2 0 94325\n1 4 3 94328', 'import itertools\nn, m, q = map(int, input().split())\nl = [list(map(int, input().split())) for _ in range(q)]\n\nnum = 0\nnax = 0\n\nnums = [i for i in range(1, m+1)]\n\nfor com in list(itertools.combinations_with_replacement(nums, n)):\n num = 0\n for j in range(q):\n if com[l[j][1]-1]-com[l[j][0]-1] == l[j][2]:\n num += l[j][3]\n nax = max(num, nax)\nprint(nax)\n']
['Runtime Error', 'Accepted']
['s266423370', 's656362534']
[9036.0, 21484.0]
[23.0, 1486.0]
[124, 379]
p02695
u521602455
2,000
1,048,576
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.
['import sys\nsys.setrecursionlimit(10**5)\nN,M,Q=map(int,input().split())\na=[0]*(Q)\nb=[0]*(Q)\nc=[0]*(Q)\nd=[0]*(Q)\nfor i in range(Q):\n A,B,C,D=map(int,input().split())\n a[i]=A;b[i]=B;c[i]=C;d[i]=D\nr=[]\ndef dfs(i,depth,b,h):\n if depth==0:\n b.append(h)\n return\n for j in range(i,M):\n nh=h[:]\n nh.append(j)\n dfs(j,depth-1,b,nh)\ndfs(1,10,r,[])\nans=0\nfor R in r:\n cnt=0\n for j in range(Q):\n if R[b[j]-1]-R[a[j]-1]==c[j]:\n cnt+=d[j]\n ans=max(cnt,ans)\nprint(ans)', 'import sys\nsys.setrecursionlimit(10**5)\nN,M,Q=map(int,input().split())\na=[0]*(Q)\nb=[0]*(Q)\nc=[0]*(Q)\nd=[0]*(Q)\nfor i in range(Q):\n A,B,C,D=map(int,input().split())\n a[i]=A;b[i]=B;c[i]=C;d[i]=D\nr=[]\ndef dfs(i,depth,b,h):\n if depth==0:\n b.append(h)\n return\n for j in range(i,M+1):\n nh=h[:]\n nh.append(j)\n dfs(j,depth-1,b,nh)\ndfs(1,10,r,[])\nans=0\nfor R in r:\n cnt=0\n for j in range(Q):\n if R[b[j]-1]-R[a[j]-1]==c[j]:\n cnt+=d[j]\n ans=max(cnt,ans)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s251662559', 's748195185']
[18308.0, 28668.0]
[594.0, 1277.0]
[525, 527]
p02695
u528470578
2,000
1,048,576
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.
['from itertools import combinations\n\nN, M, Q = map(int, input().split())\nabcd = [list(map(int, input().split())) for _ in range(Q)]\n\nlis = list(range(1, M+1))\nbox = list(combinations(lis, N))\nprint(abcd)\n\nans = []\nfor i in box:\n temp = 0\n for a, b, c, d in abcd:\n if i[b-1] - i[a-1] == c:\n temp += d\n ans.append(temp)\n\nprint(max(ans))', 'from itertools import combinations_with_replacement\n\nN, M, Q = map(int, input().split())\nabcd = [list(map(int, input().split())) for _ in range(Q)]\n\nans = 0\nfor v in combinations_with_replacement(range(1, M+1), N):\n A = list(v)\n temp = 0\n for a, b, c, d in abcd:\n if A[b-1] - A[a-1] == c:\n temp += d\n ans = max(ans, temp)\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s685975428', 's577626313']
[9148.0, 9076.0]
[25.0, 1013.0]
[360, 364]
p02695
u529737989
2,000
1,048,576
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.
['N = list(map(int,input().split()))\nQ = [list(map(int,input().split())) for i in range(N[2])]\n\n# N = [4, 6, 10]\n# Q = [[2, 4, 1, 86568], [1, 4, 0, 90629], [2, 3, 0, 90310], [3, 4, 1, 29211], [3, 4, 3, 78537], [3, 4, 2, 8580], [1, 2, 1, 96263], [1, 4, 2, 2156], [1, 2, 0, 94325], [1, 4, 3, 94328]]\n\nfrom itertools import combinations_with_replacement as comb_rplc\n\nC = 0\nfor seq in comb_rplc(range(1, N[1]+1), N[0]):\n print(seq)\n S = 0\n for i in range(N[2]):\n if seq[Q[i][1]-1]-seq[Q[i][0]-1] == Q[i][2]:\n S += Q[i][3]\n if S > C:\n C = S', 'N = list(map(int,input().split()))\nQ = [list(map(int,input().split())) for i in range(N[2])]\n\n# N = [4, 6, 10]\n# Q = [[2, 4, 1, 86568], [1, 4, 0, 90629], [2, 3, 0, 90310], [3, 4, 1, 29211], [3, 4, 3, 78537], [3, 4, 2, 8580], [1, 2, 1, 96263], [1, 4, 2, 2156], [1, 2, 0, 94325], [1, 4, 3, 94328]]\n\nfrom itertools import combinations_with_replacement as comb_rplc\n\nC = 0\nfor seq in comb_rplc(range(1, N[1]+1), N[0]):\n S = 0\n for i in range(N[2]):\n if seq[Q[i][1]-1]-seq[Q[i][0]-1] == Q[i][2]:\n S += Q[i][3]\n if S > C:\n C = S\nprint(C)']
['Wrong Answer', 'Accepted']
['s294696603', 's504845542']
[9096.0, 9092.0]
[1363.0, 1455.0]
[571, 565]
p02695
u533039576
2,000
1,048,576
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.
['from itertools import combinations_with_replacement\n\nn, m, q = map(int, input().split())\ncond = []\nfor _ in range(q):\n a, b, c, d = map(int, input().split())\n a -= 1\n b -= 1\n cond.append((a, b, c, d))\n\n\ndef calc(l):\n score = 0\n for a, b, c, d in cond:\n if l[b] - l[a] == c:\n score += d\n return score\n\n\nans = 0\nl = [0] * n\nl[0] = 1\n\n\ndef dfs(l_len):\n if l_len == n:\n ans = max(ans, calc(l))\n return\n\n for i in range(l[l_len - 1], m + 1):\n l[l_len] = i\n dfs(l_len + 1)\n\n\ndfs(0)\nprint(ans)\n', 'from itertools import combinations_with_replacement\n\nn, m, q = map(int, input().split())\ncond = []\nfor _ in range(q):\n a, b, c, d = map(int, input().split())\n a -= 1\n b -= 1\n cond.append((a, b, c, d))\n\n\ndef calc(l):\n score = 0\n for a, b, c, d in cond:\n if l[b] - l[a] == c:\n score += d\n return score\n\n\nans = 0\nl = [0] * n\nl[0] = 1\n\n\ndef dfs(l_len):\n global l, ans\n if l_len == n:\n ans = max(ans, calc(l))\n return\n\n for i in range(l[l_len - 1], m + 1):\n l[l_len] = i\n dfs(l_len + 1)\n\n\ndfs(1)\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s669729648', 's704174692']
[9176.0, 9132.0]
[20.0, 253.0]
[560, 578]
p02695
u539367121
2,000
1,048,576
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.
['N = int(input())\nGACHA=[input() for n in range(N)]\nprint(len(set(GACHA)))', 'N = int(input())\nGACHA=set()\nfor n in range(N):\n GACHA.add(input())\nprint(len(GACHA))', 'import itertools\n\nN, M, Q = map(int, input().split())\nABCD = [[int(x) for x in input().split()] for i in range(Q)]\n\nans=0\nfor A in itertools.combinations_with_replacement([m for m in range(1,M+1)], N):\n ans2=0\n for (a,b,c,d) in ABCD:\n if A[b-1]-A[a-1]==c:\n ans2+=d\n ans=max(ans, ans2)\nprint(ans)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s128120767', 's968409689', 's840368847']
[9028.0, 9068.0, 9108.0]
[20.0, 28.0, 1088.0]
[73, 86, 307]
p02695
u540627185
2,000
1,048,576
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.
[" │➜ typical\nimport sys\nsys.setrecursionlimit(10**7)\ndef input(): return sys.stdin.readline().rstrip()\n\nimport itertools\n\ndef main():\n N, M, Q = map(int, input().split())\n all_num = [i for i in range(1, M+1)]\n q_kumi = []\n for i in range(Q):\n q_kumi.append(list(map(int, input().split())))\n\n ans = 0\n for com in list(itertools.combinations_with_replacement(all_num, N)):\n tmp_ans = 0\n if com != tuple(sorted(com)):\n continue\n for q in q_kumi:\n if com[q[1]-1] - com[q[0]-1] == q[2]:\n tmp_ans += q[3]\n ans = max(ans, tmp_ans)\n print(ans)\n\nif __name__ == '__main__':\n main()", "import sys\nsys.setrecursionlimit(10**7)\ndef input(): return sys.stdin.readline().rstrip()\n\nimport itertools\n\ndef main():\n N, M, Q = map(int, input().split())\n all_num = [i for i in range(1, M+1)]\n q_kumi = []\n for i in range(Q):\n q_kumi.append(list(map(int, input().split())))\n\n ans = 0\n for com in list(itertools.combinations_with_replacement(all_num, N)):\n tmp_ans = 0\n if com != tuple(sorted(com)):\n continue\n for q in q_kumi:\n if com[q[1]-1] - com[q[0]-1] == q[2]:\n tmp_ans += q[3]\n ans = max(ans, tmp_ans)\n print(ans)\n\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Accepted']
['s333449282', 's508365125']
[9004.0, 21488.0]
[24.0, 726.0]
[693, 598]
p02695
u548123110
2,000
1,048,576
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.
['import itertools\n\ndef main():\n n,m,q = map(int,input().split())\n a = [0] * (q+1)\n b = [0] * (q+1)\n c = [0] * (q+1)\n d = [0] * (q+1)\n\n for i in range(1,q+1):\n a[i],b[i],c[i],d[i] = map(int,input().split())\n\n Alist = itertools.combinations_with_replacement(range(1,m+1),n)\n\n ans = 0\n print(a,b,c,d)\n for A in Alist:\n cnt = 0\n for i in range(1,q+1):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n cnt += d[i]\n ans = max(ans,cnt)\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', 'import itertools\n\ndef main():\n n,m,q = map(int,input().split())\n a = [0] * (q+1)\n b = [0] * (q+1)\n c = [0] * (q+1)\n d = [0] * (q+1)\n\n for i in range(1,q+1):\n a[i],b[i],c[i],d[i] = map(int,input().split())\n\n Alist = itertools.combinations_with_replacement(range(1,m+1),n)\n\n ans = 0\n for A in Alist:\n cnt = 0\n for i in range(1,q+1):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n cnt += d[i]\n ans = max(ans,cnt)\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n']
['Wrong Answer', 'Accepted']
['s017287888', 's383760634']
[9176.0, 9096.0]
[716.0, 717.0]
[554, 535]
p02695
u548545174
2,000
1,048,576
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.
['from itertools import combinations_with_replacement\nimport numpy as np\n\nN, M, Q = map(int, input().split())\n\nG = [list(map(int, input().split())) for _ in range(Q)]\n\nans = 0\n\n\n\n\nA = np.array(list(itertools.combinations_with_replacement(range(1, M + 1), N)))\nscores = np.zeros(len(A))\nfor g in G:\n a, b, c, d = g\n cond = A[:, b - 1] - A[:, a - 1] == c\n scores += d * cond\n\nprint(scores.max())', 'import itertools\nimport numpy as np\n\nN, M, Q = map(int, input().split())\nG = [list(map(int, input().split())) for i in range(Q)]\n\nA_cands = np.array(list(itertools.combinations_with_replacement(list(range(1, M+1)), N))) \n\nscores = np.zeros(len(A_cands), dtype=np.int64)\n\nfor i in range(Q):\n a, b, c, d = G[i]\n cond = A_cands[:, b - 1] - A_cands[:, a - 1] == c\n scores += cond * d\nprint(scores.max())']
['Runtime Error', 'Accepted']
['s483172582', 's643345846']
[27128.0, 46812.0]
[110.0, 228.0]
[556, 413]
p02695
u548976218
2,000
1,048,576
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.
['import itertools\n\nn, m, q = map(int, input().split())\nabcd = [list(map(int, input().split())) for _ in range(q)]\n\nA_list = list(itertools.combinations_with_replacement(range(1,m),n))\n\nans = 0\nfor A in A_list:\n sum = 0\n for a,b,c,d in abcd:\n if A[b-1] - A[a-1] == c:\n sum += d\n ans = max(ans, sum)\n\nprint(ans)', 'import itertools\n\nn, m, q = map(int, input().split())\nabcd = [list(map(int, input().split())) for _ in range(q)]\n\nA_list = list(itertools.combinations_with_replacement(range(1,m+1),n))\n\nans = 0\nfor A in A_list:\n sum = 0\n for a,b,c,d in abcd:\n if A[b-1] - A[a-1] == c:\n sum += d\n ans = max(ans, sum)\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s734901933', 's203105441']
[14992.0, 21476.0]
[494.0, 1071.0]
[335, 337]
p02695
u549161102
2,000
1,048,576
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.
['import itertools\nN,M,Q = map(int, input().split())\ncand = list(itertools.combinations_with_replacement(N+M-1,N))\nfs = [list(map(int, input().split())) for i in range(Q)]\n\ndef calc(fs,As):\n count = 0\n for a,b,c,d in fs:\n if As[b-1] - As[a-1] == a:\n count += d\n\treturn count\nans = 0\nfor As in cand:\n ans = max(ans,calc(fs,As))\n\nprint(ans)', 'from itertools import combinations_with_replacement as cw\nN,M,Q = map(int, input().split())\ncand = cw([i+1 for i in range(M)],N)\nfs = [list(map(int, input().split())) for i in range(Q)]\n\ndef calc(fs,As):\n count = 0\n for a,b,c,d in fs:\n if As[b-1] - As[a-1] == c:\n count += d\n return count\nans = 0\nfor As in cand:\n ans = max(ans,calc(fs,As))\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s218228747', 's649638763']
[9060.0, 9160.0]
[23.0, 550.0]
[347, 364]
p02695
u554926677
2,000
1,048,576
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.
['import itertools\n\nn, m, q = [int(x) for x in input().split()]\n \ntmp = []\nfor i in range(q):\n a, b, c, d = [int(x) for x in input().split()]\n tmp.append([a, b, c, d])\n\nt = list(itertools.combinations_with_replacement(range(1, m + 1), n))\n\nscore = 0\nfor _t in t:\n _s = 0\n for a, b, c, d in tmp:\n if len(_t) <= a or len(_t) <= b:\n continue\n if c == _t[b - 1] - _t[a - 1]:\n _s += d\n score = max(_s, score)\nprint(score)', 'n, m, q = [int(x) for x in input().split()]\n\nt = [sorted(x) for x in list(itertools.product(range(1, m + 1), repeat=(m-1)))]\nt = list(map(list, set(map(tuple, t))))\n\ntmp = []\nfor i in range(q):\n a, b, c, d = [int(x) for x in input().split()]\n tmp.append([a, b, c, d])\n\nscore = 0\nfor _t in t:\n _s = 0\n for a, b, c, d in tmp:\n if c == _t[b - 1] - _t[a - 1]:\n _s += d\n score = max(_s, score)\nprint(score)', 'import itertools\n\nn, m, q = [int(x) for x in input().split()]\n \ntmp = []\nfor i in range(q):\n a, b, c, d = [int(x) for x in input().split()]\n tmp.append([a, b, c, d])\n\nt = list(itertools.combinations_with_replacement(range(1, m + 1), n))\n\nscore = 0\nfor _t in t:\n _s = 0\n for a, b, c, d in tmp:\n if c == _t[b - 1] - _t[a - 1]:\n _s += d\n score = max(_s, score)\nprint(score)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s096319800', 's487648061', 's337318138']
[21612.0, 9236.0, 21504.0]
[1604.0, 24.0, 982.0]
[465, 434, 403]
p02695
u561862393
2,000
1,048,576
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.
['import sys\ninput = sys.stdin.readline\nimport numpy as np\nimport time\n\n\n\n\n\ndef make_table(n, m):\n Table = [None]*n\n for i in range(n):\n rem = np.random.randint(1,m+1)\n Table[i] = rem\n return Table\n\nt0 = time.time()\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nSum_cor = []\nfor i in range(10000000000):\n if m >=6:\n Table = make_table(n,m)\n else:\n Table = make_table(n,m)\n Table.sort()\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n t1 = time.time()\n if t1-t0 >1.9:\n print(max(Sum_cor))\n break\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\nimport time\n\nt0 = time.time()\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nSum_cor = []\nfor i in range(10000000000):\n Table = np.random.randint(1,m+1, (n, 1))\n Table.sort()\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n t1 = time.time()\n if t1-t0 >1.88:\n print(max(Sum_cor))\n break\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\nimport time\n\n\ndef make_table(n, m):\n Table = np.random.randint(1,m+1)\n return Table\n\nt0 = time.time()\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nSum_cor = []\nfor i in range(10000000000):\n if m >=6:\n Table = make_table(n,m)\n else:\n Table = make_table(n,m)\n Table.sort()\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n t1 = time.time()\n if t1-t0 >1.9:\n print(max(Sum_cor))\n print(i)\n break\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\nimport time\n\n\n\n\ndef make_table_min(n, m):\n Table = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n c = 10\n for i in range(100):\n rem = np.random.randint(1,m+1)\n if rem in Table:\n Table.remove(rem)\n c-=1\n if c <=n:\n return Table\n return make_table(n, m)\n\n\n\ndef make_table(n, m):\n Table = [None]*n\n for i in range(n):\n rem = np.random.randint(1,m+1)\n Table[i] = rem\n return Table\n\nt0 = time.time()\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nSum_cor = []\nfor i in range(10000000000):\n if m >=6:\n Table = make_table(n,m)\n else:\n Table = make_table(n,m)\n Table.sort()\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n t1 = time.time()\n if t1-t0 >1.8:\n print(max(Sum_cor))\n break\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\nimport time\n\n\ndef make_table(n, m):\n Table = np.random.randint(1,m+1)\n return Table\n\nt0 = time.time()\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nSum_cor = []\nfor i in range(10000000000):\n Table = make_table(n,m)\n Table.sort()\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n t1 = time.time()\n if t1-t0 >1.88:\n print(max(Sum_cor))\n break\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\n\nfrom itertools import combinations_with_replacement as CwR\n\n\n\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nTables = list(CwR(range(1,M+1),N))\nSum_cor = []\nfor Table in Tables:\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n\n\nprint(max(Sum_cor))\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\nimport time\n\n\n\n\ndef make_table_min(n, m):\n Table = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n c = 10\n for i in range(100):\n rem = np.random.randint(1,m+1)\n if rem in Table:\n Table.remove(rem)\n c-=1\n if c <=n:\n return Table\n return make_table(n, m)\n\n\n\ndef make_table(n, m):\n Table = [None]*n\n for i in range(n):\n rem = np.random.randint(1,m+1)\n Table[i] = rem\n return Table\n\nt0 = time.time()\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nSum_cor = []\nfor i in range(10000000000):\n if m >=6:\n Table = make_table(n,m)\n else:\n Table = make_table(n,m)\n Table.sort()\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n t1 = time.time()\n if t1-t0 >1.8:\n print(max(Sum_cor))\n break\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\nimport time\n\n\n\n\ndef make_table_min(n, m):\n Table = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n c = 10\n for i in range(100):\n rem = np.random.randint(1,m+1)\n if rem in Table:\n Table.remove(rem)\n c-=1\n if c <=n:\n return Table\n return make_table(n, m)\n\n\n\ndef make_table(n, m):\n Table = [None]*n\n for i in range(n):\n rem = np.random.randint(1,m+1)\n Table[i] = rem\n return Table\n\nt0 = time.time()\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nSum_cor = []\nfor i in range(10000000000):\n if m >=6:\n Table = make_table(n,m)\n else:\n Table = make_table(n,m)\n Table.sort()\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n t1 = time.time()\n if t1-t0 >1.88:\n print(max(Sum_cor))\n break\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\nimport time\n\n\ndef make_table(n, m):\n Table = np.random.randint(1,m+1)\n return Table\n\nt0 = time.time()\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nSum_cor = []\nfor i in range(10000000000):\n if m >=6:\n Table = make_table(n,m)\n else:\n Table = make_table(n,m)\n Table.sort()\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n t1 = time.time()\n if t1-t0 >1.9:\n print(max(Sum_cor))\n print(i)\n break\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\nimport time\n\n\n\n\ndef make_table_min(n, m):\n Table = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n c = 10\n for i in range(100):\n rem = np.random.randint(1,m+1)\n if rem in Table:\n Table.remove(rem)\n c-=1\n if c <=n:\n return Table\n return make_table(n, m)\n\n\n\ndef make_table(n, m):\n Table = [None]*n\n for i in range(n):\n rem = np.random.randint(1,m+1)\n Table[i] = rem\n return Table\n\nt0 = time.time()\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nSum_cor = []\nfor i in range(10000000000):\n if m >=6:\n Table = make_table(n,m)\n else:\n Table = make_table(n,m)\n Table.sort()\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n t1 = time.time()\n if t1-t0 >1.8:\n print(max(Sum_cor))\n break\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\n\nfrom itertools import combinations_with_replacement as CwR\n\n\n\nn, m, q = map(int, input().split())\nLis = [[int(e) for e in input().split()] for _ in range(q)]\n\nTables = list(CwR(range(1,m+1),n))\nSum_cor = []\nfor Table in Tables:\n d_sum = 0\n for l in Lis:\n if Table[l[1]-1]-Table[l[0]-1] == l[2]:\n d_sum+=l[3]\n Sum_cor.append(d_sum)\n\nprint(max(Sum_cor))\n']
['Time Limit Exceeded', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s020229563', 's159423115', 's223235941', 's349157014', 's361636384', 's476739855', 's531582419', 's641874260', 's828559590', 's841273483', 's857606800']
[36836.0, 29484.0, 27160.0, 36400.0, 27260.0, 27136.0, 34472.0, 36896.0, 27152.0, 36412.0, 43020.0]
[2012.0, 1995.0, 105.0, 1909.0, 107.0, 101.0, 1913.0, 1987.0, 111.0, 1912.0, 1026.0]
[887, 501, 638, 991, 562, 438, 991, 992, 638, 991, 437]
p02695
u562662744
2,000
1,048,576
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.
['N,M,Q=map(int,input().split())\nv=[[] for _ in range(Q)]\no=0\nfor i in range(Q):\n v[i]=list(map(int,input().split()))\nl=list(itertools.combinations(range(M+N), N))\nfor x in l:\n s=0\n a=[]\n for i in range(N):\n a.append(x[i]-i)\n for i in range(Q):\n if a[l[i][2]]-a[l[i][1]]-l[i][3]==0:\n s+=l[i][4]\n if s>o:\n o=s\nprint(o)', 'import itertools\nfrom collections import deque\nN,M,Q=map(int,input().split())\na=deque([])\nb=a\nc=a\nd=a\no=0\nfor i in range(Q):\n u,v,x,y=map(int,input().split())\n a.append(u)\n b.append(v)\n c.append(x)\n d.append(y)\nl=list(itertools.combinations(range(M+N), N))\nfor x in l:\n e=a\n f=b\n g=c\n h=d\n s=0\n u=[]\n for i in range(N):\n u.append(x[i]-i)\n for i in range(Q):\n if u[f[0]-1]-u[e[0]-1]-g[0]==0:\n s+=h[0]\n e.popleft()\n f.popleft()\n g.popleft()\n h.popleft()\n if s>o:\n o=s\nprint(o)', 'import itertools\nN,M,Q=map(int,input().split())\na=[]\nb=[]\nc=[]\nd=[]\ns=0\no=0\nfor i in range(Q):\n u,v,x,y=map(int,input().split())\n a.append(u)\n b.append(v)\n c.append(x)\n d.append(y)\nfor k in range(M):\n l=list(itertools.combinations(range(k+N), N))\n for x in l:\n s=0\n h=[]\n for i in range(N):\n h.append(x[i]-i)\n for i in range(Q):\n if h[a[i]]-h[b[i]]==c[i]:\n s+=d[i]\n if o<s:\n o=s\nprint(o)\n', 'import itertools\nN,M,Q=map(int,input().split())\nv=[[] for _ in range(Q)]\no=0\nfor i in range(Q):\n v[i]=list(map(int,input().split()))\nl=list(itertools.combinations(range(M-1+N), N))\nfor x in l:\n s=0\n a=[]\n for i in range(N):\n a.append(x[i]-i+1)\n for i in range(Q):\n if a[v[i][1]-1]-a[v[i][0]-1]-v[i][2]==0:\n s+=v[i][3]\n if s>o:\n o=s\nprint(o)']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s053455270', 's291987501', 's308821128', 's235693064']
[9216.0, 34492.0, 9236.0, 21532.0]
[23.0, 2206.0, 25.0, 1617.0]
[365, 592, 484, 390]
p02695
u562791958
2,000
1,048,576
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.
['import itertools\n\nn,m,q = map(int,input().split())\nmylist = [list(map(int, input().split())) for i in range(q)]\n#print(mylist)\n\nkouho = []\nfor i in range(1, m+1):\n kouho.append(i)\n\n\nA = list(itertools.combinations(kouho,n))\n#print(A)\n\npoint = 0\nmaxp = 0\nfor a in A:\n point = 0\n #print(a)\n for my in mylist:\n #print(my)\n if a[my[1]-1] - a[my[0]-1] == my[2]:\n point += my[3]\n print("yes")\n print(point)\n if point > maxp:\n maxp = point\n print("max更新")\n print(maxp)\nprint(maxp)\n \n\n', 'import itertools\n\nn,m,q = map(int,input().split())\nmylist = [list(map(int, input().split())) for i in range(q)]\n#print(mylist)\n\nkouho = []\nfor i in range(1, m+1):\n kouho.append(i)\n\n\nA = list(itertools.combinations_with_replacement(kouho,n))\n#print(A)\n\npoint = 0\nmaxp = 0\nfor a in A:\n point = 0\n #print(a)\n for my in mylist:\n #print(my)\n #print(a[my[1]-1] - a[my[0]-1])\n #print(my[2])\n #print("")\n if a[my[1]-1] - a[my[0]-1] == my[2]:\n point += my[3]\n #print("yes")\n #print(point)\n #print(point)\n if point > maxp:\n maxp = point\n \n #print(maxp)\nprint(maxp)\n \n\n']
['Wrong Answer', 'Accepted']
['s600152689', 's380641292']
[9172.0, 21484.0]
[24.0, 1062.0]
[528, 638]
p02695
u571395477
2,000
1,048,576
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.
['import itertools\n\n#19 choose 9\n#92378\n\ndef main():\n N, M, Q = map(int, input().split())\n Q = []\n final_score = 0\n for i in range(Q):\n Q.append(list(map(int, input().split())))\n for A in itertools.combinations_with_replacement(range(1, M+1), N):\n score = 0\n for q in Q:\n if A[q[1]-1] - A[q[0]-1] == q[2]:\n score += q[3]\n out = max([final_score, score])\n print(out)\nmain()', 'import itertools\n\n#19 choose 9\n#92378\n\ndef main():\n N, M, Q = map(int, input().split())\n Q = []\n final_score = 0\n for i in range(Q):\n Q.append(list(map(int, input().split())))\n for A in itertools.combinations_with_replacement(range(1, M+1), N):\n score = 0\n for q in Q:\n if A[q[1]-1] - A[q[0]-1] == q[2]:\n score += q[3]\n final_score = max([final_score, score])\n print(final_score)\nmain()', 'import itertools\n\n#19 choose 9\n#92378\n\ndef main():\n N, M, Q = map(int, input().split())\n Q_l = []\n final_score = 0\n for i in range(Q):\n Q_l.append(list(map(int, input().split())))\n for A in itertools.combinations_with_replacement(range(1, M+1), N):\n score = 0\n for q in Q_l:\n if A[q[1]-1] - A[q[0]-1] == q[2]:\n score += q[3]\n final_score = max([final_score, score])\n print(final_score)\nmain()']
['Runtime Error', 'Runtime Error', 'Accepted']
['s008278463', 's440734779', 's337507264']
[9140.0, 9064.0, 9052.0]
[23.0, 20.0, 1403.0]
[438, 462, 468]
p02695
u576917603
2,000
1,048,576
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.
['vn,m,q=map(int,input().split())\nlis=[]\nfor i in range(q):\n a,b,c,d=map(int,input().split())\n lis.append((a,b,c,d))\n \nfrom itertools import combinations_with_replacement\n\nco=list(combinations_with_replacement(range(1,m+1),n))\n\nans=0\nfor status in co:\n tmp_score=0\n for a,b,c,d in lis:\n if status[b-1]-status[a-1]==c:\n tmp_score+=d\n ans=max(ans,tmp_score)\nprint(ans)\n', 'import sys\nsys.setrecursionlimit(1000000)\n\ndef dfs(a):\n if len(a)==n:\n tmp=a[:]\n a_lis.append(tmp)\n return\n \n for i in range(m):\n if len(a)>0 and i<a[-1]:\n continue\n a.append(i)\n dfs(a)\n a.pop()\n\ncnt=0 \nn,m,q=map(int,input().split())\nlis=[[int(i) for i in input().split()]for i in range(q)]\na_lis=[]\n\ndfs([])\nans=0\nfor i in a_lis:\n score=0\n for a,b,c,d in lis:\n if i[b-1]-i[a-1]==c:\n score+=d\n ans=max(ans,score)\nprint(ans)']
['Runtime Error', 'Accepted']
['s424408881', 's485514438']
[9140.0, 23024.0]
[22.0, 1155.0]
[401, 526]
p02695
u580920947
2,000
1,048,576
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.
['#!/usr/bin/env python\nimport sys\nfrom collections import Counter\nfrom itertools import permutations, combinations_with_replacement\n#from fractions import gcd\nfrom math import gcd\nfrom math import ceil, floor\nimport bisect\nsys.setrecursionlimit(10 ** 6)\ninf = float("inf")\n\ndef input():\n return sys.stdin.readline()[:-1]\n\ndef main():\n n, m, q = map(int, input().split())\n abcd = [None] * q\n for i in range(q):\n abcd[i] = tuple(map(int, input().split()))\n\n A = list(range(m))\n ans = 0\n comb = list(combinations_with_replacement(A, n))\n for c in comb:\n tmp_ans = 0\n for i in range(q):\n if c[abcd[i][1]-1] - c[abcd[i][0]-1] == abcd[i][2]:\n tmp_ans += abcd[i][3]\n print(tmp_ans)\n ans = max(ans, tmp_ans)\n print(ans)\n\nif __name__ == \'__main__\':\n main()\n\n', '#!/usr/bin/env python\nimport sys\nfrom collections import Counter\nfrom itertools import permutations, combinations_with_replacement\n#from fractions import gcd\nfrom math import gcd\nfrom math import ceil, floor\nimport bisect\nsys.setrecursionlimit(10 ** 6)\ninf = float("inf")\n\ndef input():\n return sys.stdin.readline()[:-1]\n\ndef main():\n n, m, q = map(int, input().split())\n abcd = [None] * q\n for i in range(q):\n abcd[i] = tuple(map(int, input().split()))\n\n A = list(range(m))\n ans = 0\n comb = list(combinations_with_replacement(A, n))\n for c in comb:\n tmp_ans = 0\n for i in range(q):\n if c[abcd[i][1]-1] - c[abcd[i][0]-1] == abcd[i][2]:\n tmp_ans += abcd[i][3]\n ans = max(ans, tmp_ans)\n print(ans)\n\nif __name__ == \'__main__\':\n main()']
['Wrong Answer', 'Accepted']
['s679675515', 's013958908']
[22564.0, 21916.0]
[1148.0, 875.0]
[847, 814]
p02695
u586639900
2,000
1,048,576
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.
['N, M, Q = map(int, input().split())\n\nA = []\nB = []\nC = []\nD = []\n\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n A.append(a)\n B.append(b)\n C.append(c)\n D.append(d)\n\n\ndef dfs(nums):\n\n if len(nums) == N + 1:\n score = 0\n for j in range(Q):\n if nums[B[j]] - nums[A[j]] == C[j]:\n score += D[j]\n return score\n\n max_score = 0\n for i in range(nums[-1], M+1):\n new_nums = nums + [i]\n max_score = max(max_score, dfs(new_nums))\n\n return max_score\n\nnums[1]\nres = dfs(nums)\nprint(res)', 'N, M, Q = map(int, input().split())\n \nA = []\nB = []\nC = []\nD = []\n \nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n A.append(a)\n B.append(b)\n C.append(c)\n D.append(d)\n \n \ndef dfs(nums):\n \n if len(nums) == N + 1:\n score = 0\n for j in range(Q):\n if nums[B[j]] - nums[A[j]] == C[j]:\n score += D[j]\n return score\n \n max_score = 0\n for i in range(nums[-1], M+1):\n new_nums = nums + [i]\n max_score = max(max_score, dfs(new_nums))\n \n return max_score\n \nnums = [1]\nres = dfs(nums)\nprint(res)']
['Runtime Error', 'Accepted']
['s818293130', 's531338786']
[9240.0, 9240.0]
[23.0, 697.0]
[572, 583]
p02695
u591524911
2,000
1,048,576
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.
['n,m,q = map(int ,input().split())\nlst = [list(map(int, input().split())) for _ in range(q)]\nimport itertools\nl = [i+1 for i in range(m)]\nlst2 = [com for com in itertools.combinations_with_replacement(l, n)]\nres = 0\nfor com in lst2:\n score = 0\n for l in lst:\n if com[l[1]-1] - com[l[0]-1] == l[2]:\n score += l[3]\n if res < score:\n res = score \n print(score)\nprint(res)', 'n,m,q = map(int ,input().split())\nlst = [list(map(int, input().split())) for _ in range(q)]\nimport itertools\nl = [i+1 for i in range(m)]\nlst2 = [com for com in itertools.combinations(l, n)]\nres = 0\nfor com in lst2:\n score = 0\n for l in lst:\n if com[l[1]-1] - com[l[0]-1] == l[2]:\n score += l[3]\n if res < score:\n res = score \n print(score)\nprint(res)', 'n,m,q = map(int ,input().split())\nlst = [list(map(int, input().split())) for _ in range(q)]\nimport itertools\nl = [i+1 for i in range(m)]\nlst2 = [com for com in itertools.combinations_with_replacement(l, n)]\nres = 0\nfor com in lst2:\n score = 0\n for l in lst:\n if com[l[1]-1] - com[l[0]-1] == l[2]:\n score += l[3]\n if res < score:\n res = score \n #print(score)\nprint(res)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s051331315', 's300931594', 's803263583']
[21920.0, 9144.0, 21616.0]
[1016.0, 24.0, 988.0]
[404, 387, 405]
p02695
u593567568
2,000
1,048,576
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.
['import sys\nimport itertools\n\n\nsys.setrecursionlimit(10 ** 7)\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nN, M, Q = map(int, input().split())\nABCD = [list(map(int, input().split())) for _ in range(Q)]\n\n\nans = 0\nfor lst in itertools.combinations_with_replacement(range(1, N + 1), N):\n s = 0\n for a, b, c, d in ABCD:\n if (lst[b - 1] - lst[a - 1]) == c:\n s += d\n\n ans = max(ans, s)\n\nprint(ans)\n', 'import sys\nimport itertools\n\n\nsys.setrecursionlimit(10 ** 7)\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nN, M, Q = map(int, input().split())\nABCD = [list(map(int, input().split())) for _ in range(Q)]\n\n\nans = 0\nfor lst in itertools.combinations_with_replacement(range(1, M + 1), N):\n s = 0\n for a, b, c, d in ABCD:\n if (lst[b - 1] - lst[a - 1]) == c:\n s += d\n\n ans = max(ans, s)\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s777928796', 's790419289']
[9120.0, 9144.0]
[1063.0, 982.0]
[480, 480]
p02695
u595905528
2,000
1,048,576
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.
['#import numpy as np\nN,M,Q=map(int, input().split())\nmatrix=[]\nfor _ in range(Q):\n c=list(map(int, input().split()))\n matrix.append(c)\n#matrix = np.array(matrix)\nimport itertools\nansscore = 0\ncombi = list(combinations_with_replacement(range(1,M+1),N)\nfor i in combi:\n i = list(i)\n i.sort()\n score=0\n for l in matrix:\n a=l[0]\n b=l[1]\n c=l[2]\n d=l[3]\n if i[b-1]-i[a-1]==c:\n score+=d\n ansscore = score if score>ansscore else ansscore\n\nprint(ansscore)', '#import numpy as np\nN,M,Q=map(int, input().split())\nmatrix=[]\nfor _ in range(Q):\n c=list(map(int, input().split()))\n matrix.append(c)\n#matrix = np.array(matrix)\nimport itertools\nansscore = 0\ncombi = list(combinations_with_replacement(range(1,M+1),N))\nfor i in combi:\n i = list(i)\n i.sort()\n score=0\n for l in matrix:\n a=l[0]\n b=l[1]\n c=l[2]\n d=l[3]\n if i[b-1]-i[a-1]==c:\n score+=d\n ansscore = score if score>ansscore else ansscore\n\nprint(ansscore)', '#import numpy as np\nN,M,Q=map(int, input().split())\nmatrix=[]\nfor _ in range(Q):\n c=list(map(int, input().split()))\n matrix.append(c)\n#matrix = np.array(matrix)\nimport itertools\nansscore = 0\ncombi = list(itertools.combinations_with_replacement(range(1,M+1),N))\nfor i in combi:\n i = list(i)\n i.sort()\n score=0\n for l in matrix:\n a=l[0]\n b=l[1]\n c=l[2]\n d=l[3]\n if i[b-1]-i[a-1]==c:\n score+=d\n ansscore = score if score>ansscore else ansscore\n\nprint(ansscore)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s532616031', 's597397578', 's943697565']
[9044.0, 9160.0, 21540.0]
[24.0, 20.0, 1484.0]
[513, 514, 524]
p02695
u605253462
2,000
1,048,576
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.
['import itertools\n\nn,m,q = input().split()\nn = int(n)\nm = int(m)\nq = int(q)\nnum_list = []\na = list(range(1, n+1))\nfor i in range(q):\n num_list.append(list(map(int,input().split())))\nnum_list = sorted(num_list, reverse=True, key=lambda x: x[3])\nff = list(itertools.combinations_with_replacement(a, m))\nmax = 0\nfor i in range(len(ff)):\n s = 0\n for j in range(q):\n a,b,c,d = num_list[j]\n if ff[i][b-1] - ff[i][a-1] == c:\n s = s + d\n if max < s:\n max = s\nprint(max)', 'import itertools\n\nn,m,q = input().split()\nn = int(n)\nm = int(m)\nq = int(q)\nnum_list = []\na = list(range(1, n+1))\nfor i in range(q):\n num_list.append(list(map(int,input().split())))\nff = list(itertools.combinations_with_replacement(a, m))\nmax = 0\nfor i in range(len(ff)):\n s = 0\n for j in range(q):\n a,b,c,d = num_list[j]\n if ff[i][b-1] - ff[i][a-1] == c:\n s = s + d\n if max < s:\n max = s\nprint(max)\n ', 'import itertools\n\nn,m,q = input().split()\nn = int(n)\nm = int(m)\nq = int(q)\nnum_list = []\na = list(range(1, n+1))\nfor i in range(q):\n num_list.append(list(map(int,input().split())))\nff = list(itertools.combinations_with_replacement(range(1, m + 1), n))\nmax = 0\nfor i in range(len(ff)):\n s = 0\n for j in range(q):\n a,b,c,d = num_list[j]\n if ff[i][b-1] - ff[i][a-1] == c:\n s = s + d\n if max < s:\n max = s\nprint(max)\n ']
['Runtime Error', 'Runtime Error', 'Accepted']
['s176939209', 's851288966', 's077417252']
[21616.0, 21616.0, 21496.0]
[1579.0, 1526.0, 1499.0]
[484, 425, 439]
p02695
u607563136
2,000
1,048,576
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.
['from itertools import product\n\nn, m, q = map(int,input().split())\na = [list(map(int,input().split())) for _ in range(q)]\n\ntemp = list(combinations([i for i in range(1,m+1)],n))\n\n\nans = 0\n\nfor a_temp in temp:\n ans_temp = 0\n for i in range(q):\n if a_temp[a[i][1]-1] - a_temp[a[i][0]-1] == a[i][2]:\n ans_temp += a[i][3]\n if ans < ans_temp:\n ans = ans_temp\nprint(ans)', 'from itertools import combinations_with_replacement\n\nn, m, q = map(int,input().split())\na = [list(map(int,input().split())) for _ in range(q)]\n\ntemp = list(combinations_with_replacement([i for i in range(1,m+1)],n))\n\nans = 0\n\nfor a_temp in temp:\n ans_temp = 0\n for i in range(q):\n if a_temp[a[i][1]-1] - a_temp[a[i][0]-1] == a[i][2]:\n ans_temp += a[i][3]\n if ans < ans_temp:\n ans = ans_temp\n \nprint(ans)']
['Runtime Error', 'Accepted']
['s721658365', 's493171778']
[9216.0, 21556.0]
[22.0, 1277.0]
[397, 444]
p02695
u608007704
2,000
1,048,576
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.
['N,M,Q=map(int,input().split())\n\nabcd=[]\nfor i in range(Q):\n abcd.append(list(map(int,input().split())))\n abcd[i][0]-=1\n abcd[i][1]-=1\n\n \ndef calcScore(target):\n score=0\n for i in range(Q):\n if target[abcd[i][1]]-target[abcd[i][0]]==abcd[i][2]:\n score+=abcd[i][3]\n return score\n\ndef makeTarget():\n list=[1]*N\n list[-1]=0\n while True:\n list[-1]+=1\n for i in range(len(list)):\n if list[-i-1]>M:\n if len(list)==i+1:return\n list[-i-2]+=1\n list[-i-1]=0\n for i in range(len(list)-1):\n if list[i]>list[i+1]:list[i+1]=list[i]\n yield list.copy()\n\nans=0\nfor i in makeTarget():\n print(i)\n ans=max(ans,calcScore(i))\nprint(ans)', 'N,M,Q=map(int,input().split())\n\nabcd=[]\nfor i in range(Q):\n abcd.append(list(map(int,input().split())))\n abcd[i][0]-=1\n abcd[i][1]-=1\n\n \ndef calcScore(target):\n score=0\n for i in range(Q):\n if target[abcd[i][1]]-target[abcd[i][0]]==abcd[i][2]:\n score+=abcd[i][3]\n return score\n\ndef makeTarget():\n list=[0]*N\n while True:\n list[-1]+=1\n for i in range(len(list)):\n if list[-i-1]>M-1:\n if len(list)==i+1:return\n list[-i-2]+=1\n list[-i-1]=0\n for i in range(len(list)-1):\n if list[i]>list[i+1]:list[i+1]=list[i]\n yield list.copy()\n\nans=0\nfor i in makeTarget():\n print(i)\n ans=max(ans,calcScore(i))\nprint(ans)', 'N,M,Q=map(int,input().split())\n\nabcd=[]\nfor i in range(Q):\n abcd.append(list(map(int,input().split())))\n abcd[i][0]-=1\n abcd[i][1]-=1\n\n \ndef calcScore(target):\n score=0\n for i in range(Q):\n if target[abcd[i][1]]-target[abcd[i][0]]==abcd[i][2]:\n score+=abcd[i][3]\n return score\n\ndef makeTarget():\n list=[1]*N\n list[-1]=0\n while True:\n list[-1]+=1\n for i in range(len(list)):\n if list[-i-1]>M:\n if len(list)==i+1:return\n list[-i-2]+=1\n list[-i-1]=0\n for i in range(len(list)-1):\n if list[i]>list[i+1]:list[i+1]=list[i]\n yield list.copy()\n\nans=0\nfor i in makeTarget():\n ans=max(ans,calcScore(i))\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s513392824', 's552823824', 's246222246']
[9180.0, 9272.0, 9204.0]
[1097.0, 1106.0, 1007.0]
[676, 665, 665]
p02695
u613350811
2,000
1,048,576
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.
['import itertools\nN, M, Q = map(int, input().split())\nfor i in range(Q):\n q_list.append(list(map(int, input().split())))\n\nq_list = []\nfinal_score = 0\nfor A in itertools.combinations_with_replacement(range(1,11), N):\n score = 0\n for q in q_list:\n if A[q[1]-1] - A[q[0]-1] == q[2]:\n score += q[3]\n final_score = max([final_score, score])\nprint(final_score)', 'import itertools\nN, M, Q = map(int, input().split())\nq_list = []\nfinal_score = 0\nfor i in range(Q):\n q_list.append(list(map(int, input().split())))\nfor A in itertools.combinations_with_replacement(range(1,M+1), N):\n score = 0\n for q in q_list:\n if A[q[1]-1] - A[q[0]-1] == q[2]:\n score += q[3]\n final_score = max([final_score, score])\nprint(final_score)']
['Runtime Error', 'Accepted']
['s769781212', 's845950745']
[9200.0, 9196.0]
[21.0, 1852.0]
[387, 387]
p02695
u614162316
2,000
1,048,576
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.
['n,m,q=map(int,input().split())\nabcd=[]\nx=[1]\nfor i in range(q):\n abcd.append(list(map(int,input().split())))\nans=0\ndef dfs(s):\n global ans\n if(len(s)==n):\n t=0\n for a,b,c,d in abcd:\n if(s[b-1]-s[a-1]==c):\n t+=d\n ans=max(t,ans)\n return \n p=s[-1]\n print(s)\n while p<=m:\n s.append(p)\n dfs(s)\n p=s.pop()+1\ndfs(x)\nprint(ans)', 'n,m,q=map(int,input().split())\nabcd=[]\nx=[1]\nfor i in range(q):\n abcd.append(list(map(int,input().split())))\nans=0\ndef dfs(s):\n global ans\n if(len(s)==n):\n t=0\n for a,b,c,d in abcd:\n if(s[b-1]-s[a-1]==c):\n t+=d\n ans=max(t,ans)\n return \n p=s[-1]\n while p<=m:\n s.append(p)\n dfs(s)\n p=s.pop()+1\ndfs(x)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s455296034', 's802623664']
[9172.0, 9208.0]
[346.0, 304.0]
[412, 399]
p02695
u627600101
2,000
1,048,576
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.
['N, M, Q = map(int, input().split())\na = [0 for _ in range(Q)]\nb = [0 for _ in range(Q)]\nc = [0 for _ in range(Q)]\nd = [0 for _ in range(Q)]\nfor k in range(Q):\n a[k], b[k], c[k], d[k] = map(int, input().split())\nA = [1 for _ in range(N)]\n\ndef point(A):\n p = 0\n for ai, bi, ci, di in zip(a, b, c, d):\n if A[bi-1] - A[ai-1] == ci:\n p += di\n return p\n\ndef next(A):\n k = 1\n while k < N+1:\n if A[-k] < M:\n A[-k] += 1\n return A\n break\n else:\n for j in range(1, k+1):\n A[-j] = A[-k-1] + 1\n k += 1\n \nans = max(ans, point([M for _ in range(N)]))\nwhile A[0] < M:\n ans = max(ans, point(A))\n A = next(A)\nprint(ans)', 'N, M, Q = map(int, input().split())\na = [0 for _ in range(Q)]\nb = [0 for _ in range(Q)]\nc = [0 for _ in range(Q)]\nd = [0 for _ in range(Q)]\nfor k in range(Q):\n a[k], b[k], c[k], d[k] = map(int, input().split())\nA = [1 for _ in range(N)]\n\ndef point(A):\n p = 0\n for ai, bi, ci, di in zip(a, b, c, d):\n if A[bi-1] - A[ai-1] == ci:\n p += di\n return p\n\ndef next(A):\n k = 1\n while k < N+1:\n if A[-k] < M:\n A[-k] += 1\n return A\n break\n else:\n for j in range(1, k+1):\n A[-j] = A[-k-1] + 1\n k += 1\n\nans = point([M for _ in range(N)])\nwhile A[0] < M:\n ans = max(ans, point(A))\n A = next(A)\nprint(ans)']
['Runtime Error', 'Accepted']
['s939454801', 's181962733']
[9220.0, 9244.0]
[24.0, 698.0]
[660, 644]
p02695
u631755487
2,000
1,048,576
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.
['n, m, q = map(int, input().split())\n\nabcd = [list(map(int, input.split())) for _ in range(q)]\nfrom itertools import combinations_with_replacement as cwr\nA = list(cwr(range(1, m+1), n))\n\n\nmaxPoint = 0\nfor item in A:\n point = 0\n for i in range(len(abcd))\n a = abcd[i][0]\n b = abcd[i][1]\n c = abcd[i][2]\n d = abcd[i][3]\n if item[b-1] - item[a-1] == item[c-1]:\n point += d\n if point > maxPoint:\n maxPoint = point\nprint(maxPoint)', 'n, m, q = map(int, input().split())\n\nabcd = [list(map(int, input().split())) for _ in range(q)]\nfrom itertools import combinations_with_replacement as cwr\nA = list(cwr(range(1, m+1), n))\n\n\nmaxPoint = 0\nfor item in A:\n point = 0\n for i in range(len(abcd)):\n a = abcd[i][0]\n b = abcd[i][1]\n c = abcd[i][2]\n d = abcd[i][3]\n if item[b-1] - item[a-1] == item[c-1]:\n point += d\n if point > maxPoint:\n maxPoint = point\nprint(maxPoint)', 'n, m, q = map(int, input().split())\n\nabcd = [list(map(int, input().split())) for _ in range(q)]\nfrom itertools import combinations_with_replacement as cwr\nAList = list(cwr(range(1, m+1), n))\n\n\nmaxPoint = 0\nfor A in AList:\n point = 0\n for abc in abcd:\n a = abc[0]\n b = abc[1]\n c = abc[2]\n d = abc[3]\n if A[b-1] - A[a-1] == c:\n point += d\n if point > maxPoint:\n maxPoint = point\nprint(maxPoint)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s123412613', 's712523644', 's730516809']
[9044.0, 21492.0, 21484.0]
[21.0, 2034.0, 1487.0]
[438, 453, 418]
p02695
u636251914
2,000
1,048,576
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.
['N, M, Q = [int(_) for _ in input().split()]\na = [0] * Q\nb = [0] * Q\nc = [0] * Q\nd = [0] * Q\n\nfor i in range(Q):\n xs = [int(_) for _ in input().split()]\n a[i] = xs[0] - 1\n b[i] = xs[1] - 1\n c[i] = xs[2]\n d[i] = xs[3]\n\n\ndef calc_score(A):\n acc = 0\n for i in range(Q):\n if c[i] == A[b[i]] - A[a[i]]:\n acc += d[i]\n return acc\n\n\nmax_score = -1\n\n\ndef dfs(A):\n if len(A) == N:\n global max_score\n max_score = max(calc_score(A), max_score)\n else:\n if len(A) == 0:\n A.append(1)\n else:\n A.append(A[-1])\n while (A[-1] <= M):\n dfs(A)\n A[-1] += 1\n\n\ndfs([])\nprint(max_score)\n', 'import copy\n\nN, M, Q = [int(_) for _ in input().split()]\na = [0] * Q\nb = [0] * Q\nc = [0] * Q\nd = [0] * Q\n\nfor i in range(Q):\n xs = [int(_) for _ in input().split()]\n a[i] = xs[0] - 1\n b[i] = xs[1] - 1\n c[i] = xs[2]\n d[i] = xs[3]\n\n\ndef calc_score(A):\n acc = 0\n for i in range(Q):\n if c[i] == A[b[i]] - A[a[i]]:\n acc += d[i]\n return acc\n\n\nmax_score = -1\n\n\ndef dfs(A):\n if len(A) == N:\n global max_score\n max_score = max(calc_score(A), max_score)\n else:\n if len(A) == 0:\n A.append(1)\n else:\n A.append(A[-1])\n while (A[-1] <= M):\n dfs(copy.deepcopy(A))\n A[-1] += 1\n\n\ndfs([])\nprint(max_score)\n']
['Wrong Answer', 'Accepted']
['s025092683', 's961461913']
[9168.0, 9356.0]
[29.0, 1484.0]
[687, 715]
p02695
u646412443
2,000
1,048,576
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.
['n, m, q = list(map(int, input().split()))\na = [0] * q\nb = [0] * q\nc = [0] * q\nd = [0] * q\nfor i in range(q):\n a[i], b[i], c[i], d[i] = map(int, input().split())\n\nans = 0\ndef dfs(A=[]):\n global ans\n if len(A) == n+1:\n now = 0\n for i in range(q):\n if A[b[i]] - A[a[i]] == c[i]:\n now += d[i]\n ans = max(ans, now)\n return\n A.append(A[-1])\n while(A[-1] <= m):\n dfs(A)\n A[-1] += 1\n\ndfs([1])\nprint(ans)\n', 'n, m, q = list(map(int, input().split()))\na, b, c, d = [0] * q, [0] * q, [0] * q, [0] * q\nfor i in range(q):\n a[i], b[i], c[i], d[i] = map(int, input().split())\n\nA = [0] * (n+1)\nA[0] = 1\nans = 0\ndef dfs(k):\n global ans\n if k == n+1:\n now = 0\n for i in range(q):\n if A[b[i]] - A[a[i]] == c[i]:\n now += d[i]\n ans = max(ans, now)\n else:\n for i in range(A[k-1], m+1):\n A[k] = i\n dfs(k+1)\n\ndfs(1)\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s254633680', 's324037208']
[9136.0, 9168.0]
[21.0, 697.0]
[479, 491]
p02695
u648901783
2,000
1,048,576
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.
['N, M, Q = map(int, input().split())\ntmp = [list(map(int, input().split())) for i in range(Q)]\n\n\n\n\n\nans = [0]\ndef dfs(A):\n if len(A) == N:\n tmp_ans = 0\n for ele in tmp\n if ele[1] - ele[0] == ele[2]:\n tmp_ans += ele[-1]\n ans[0] = max(tmp_ans,ans[0])\n\n return\n \n A_min = A[-1]\n while(1):\n if A_min > M:\n break\n A.append(A_min)\n dfs(A)\n A.pop()\n A_min += 1\n\nfor i in range(M):\n dfs([i+1])\n\nprint(ans[0])\n\n', 'N, M, Q = map(int, input().split())\ntmp = [list(map(int, input().split())) for i in range(Q)]\n\n\n\n\n\nans = [0]\ndef dfs(A):\n # print(A)\n if len(A) == N:\n tmp_ans = 0\n for ele in tmp:\n if A[ele[1]-1] - A[ele[0]-1] == ele[2]:\n tmp_ans += ele[-1]\n ans[0] = max(tmp_ans,ans[0])\n\n return\n \n A_min = A[-1]\n while(1):\n if A_min > M:\n break\n A.append(A_min)\n dfs(A)\n A.pop()\n A_min += 1\n\nfor i in range(M):\n dfs([i+1])\n\nprint(ans[0])\n\n']
['Runtime Error', 'Accepted']
['s907929189', 's429812578']
[8888.0, 8968.0]
[25.0, 719.0]
[609, 635]
p02695
u663767599
2,000
1,048,576
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.
['from itertools import combinations_with_replacement\n\nN, M, Q = map(int, input().split())\nts = []\nfor _ in range(Q):\n ts.append(tuple(map(int, input().split())))\nprint(ts)\n\nscores = []\nfor A in combinations_with_replacement(range(1, M + 1), N):\n score = 0\n for t in ts:\n a, b, c, d = t\n if A[b - 1] - A[a - 1] == c:\n score += d\n scores.append(score)\n\nprint(max(scores))\n', 'from itertools import combinations_with_replacement\n\nN, M, Q = map(int, input().split())\nts = []\nfor _ in range(Q):\n ts.append(tuple(map(int, input().split())))\n\nscores = []\nfor A in combinations_with_replacement(range(1, M + 1), N):\n score = 0\n for t in ts:\n a, b, c, d = t\n if A[b - 1] - A[a - 1] == c:\n score += d\n scores.append(score)\n\nprint(max(scores))\n']
['Wrong Answer', 'Accepted']
['s824414342', 's889500683']
[12516.0, 12636.0]
[1100.0, 1122.0]
[406, 396]
p02695
u669812251
2,000
1,048,576
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.
['# -*- coding: utf-8 -*-\n\n\nN, M , Q = [int(i) for i in input().split()]\n\nnumbers = []\nfor i in range(Q):\n numbers.append([int(j) for j in input().split()])\n\nnumbers = sorted(numbers , key = lambda x:-x[1])\n#print(numbers)\n\nkouho = ["9"*(N)]\n\nfor a, b , c ,d in numbers:\n for k in kouho:\n if int(k[b-1]) - int(k[a-1]) != c:\n new_k = k[:a-1] + str(int(k[b-1])-c) + k[a:]\n if str(int(k[b-1])-c) >= 0:\n kouho.append(new_k)\n kouho = list(set(kouho))\n\n#print(sorted(kouho))\n\nanswers = [0] * len(kouho)\nfor i, k in enumerate(kouho):\n ans = 0\n for a, b, c, d in numbers:\n if int(k[b-1]) - int(k[a-1]) == c:\n ans += d\n answers[i] = ans\nprint(max(answers))\n\'\'\'\nkouho = []\nfor password in range(0,10**(N-1)):\n password = "9" + str(password).zfill(N-1)\n kouho.append(\'\'.join(list(reversed(password))))\n\nanswers = [0] * len(kouho)\nfor i, k in enumerate(kouho):\n ans = 0\n for a, b, c, d in numbers:\n if int(k[b-1]) - int(k[a-1]) == c:\n ans += d\n answers[i] = ans\nprint(max(answers))\n\'\'\'\n', 'import itertools\n\nN, M , Q = [int(i) for i in input().split()]\n\nnumbers = []\nfor i in range(Q):\n numbers.append([int(j) for j in input().split()])\n\n\nA = list(itertools.combinations_with_replacement(range(1,M+1),N))\n\nanswer = 0\nfor k in A:\n ans = 0\n for a, b, c, d in numbers:\n if int(k[b-1]) - int(k[a-1]) == c:\n ans += d\n if answer < ans:\n answer = ans\nprint(answer)\n']
['Runtime Error', 'Accepted']
['s342151154', 's270896137']
[9264.0, 21548.0]
[22.0, 1719.0]
[1114, 407]