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
u671455949
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 copy\n\nn, 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\nseq = [[] for i in range(n)]\n\nfor i in range(1, m + 1):\n seq[0].append([i])\n\nfor i in range(1, n):\n for j in range(len(seq[i - 1])):\n s = copy.copy(seq[i - 1][j])\n s.append(0)\n for k in range(s[-2], m + 1):\n s[-1] = k\n s2 = copy.copy(s)\n seq[i].append(s2)\n\nscore = [0 for i in range(len(seq[n - 1]))]\nfor i in range(len(seq[n - 1])):\n for j in range(q):\n if seq[n - 1][i][b[j] - 1] - seq[n - 1][i][a[j] - 1] == c:\n score[i] += d[j]\n\nprint(max(score))', 'import copy\n\nn, 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\nseq = [[] for i in range(n)]\n\nfor i in range(1, m + 1):\n seq[0].append([i])\n\nfor i in range(1, n):\n for j in range(len(seq[i - 1])):\n s = copy.copy(seq[i - 1][j])\n s.append(0)\n for k in range(s[-2], m + 1):\n s[-1] = k\n s2 = copy.copy(s)\n seq[i].append(s2)\n\nscore = [0 for i in range(len(seq[n - 1]))]\nfor i in range(len(seq[n - 1])):\n for j in range(q):\n if seq[n - 1][i][b[j] - 1] - seq[n - 1][i][a[j] - 1] == c[j]:\n score[i] += d[j]\n\nprint(max(score))']
['Wrong Answer', 'Accepted']
['s089836867', 's412836257']
[36924.0, 39684.0]
[1654.0, 1744.0]
[689, 692]
p02695
u672475305
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 _ in range(q)]\nans = 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(19, 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)', 'def dfs(arr, min_nx):\n ans = 0\n if len(arr) == n:\n tmp = 0\n for a,b,c,d in lst:\n if arr[b-1] - arr[a-1] == c:\n tmp += d\n return tmp\n else:\n for nx in range(min_nx, m+1):\n new_arr = arr + [nx]\n score = dfs(new_arr, nx)\n ans = max(ans, score)\n return ans\nn,m,q = map(int,input().split())\nlst = [list(map(int,input().split())) for _ in range(q)]\nans = dfs([], 1)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s097473388', 's655911139']
[9144.0, 9188.0]
[40.0, 592.0]
[939, 469]
p02695
u679236042
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\nimport itertools\n\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\n\n\n\n\ndef combinations_count(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\n\n\nAll =[0] * M\nfor i in range(M):\n All[i] = i+1\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nans = 0\n#for A in itertools.combinations(All, N):\nfor A in itertools.product(All, repeat=N):\n \n \n \n #print(A)\n wa = 0\n for i in range(Q):\n print(wa) \n kari = A[b[i]-1] - A[a[i]-1]\n if kari == c[i]:\n wa = wa + d[i] \n if ans < wa:\n ans = wa\n #print(ans) \n #print(wa) \n\n\nprint(ans)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n', 'import math\nimport itertools\n\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\n\n\n\n\ndef combinations_count(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\n\n\nAll =[0] * M\nfor i in range(M):\n All[i] = i+1\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nans = 0\nfor A in itertools.product(All, N):\n \n print(A)\n wa = 0\n for i in range(Q):\n print(wa) \n kari = A[b[i]-1] - A[a[i]-1]\n if kari == c[i]:\n wa = wa + d[i] \n if ans < wa:\n ans = wa\n #print(ans) \n #print(wa) \n\n\nprint(ans)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n', 'import math\nimport itertools\n\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\n\n\n\nAl =[0] * M\nfor i in range(M):\n Al[i] = i+1\n\n\n\n\n\n\n\n\n\n\n\nAll = list(itertools.combinations_with_replacement(Al, N))\n\n\n\nans = 0\n#for A in itertools.combinations(All, N):\nfor A in All:\n \n #print(A)\n wa = 0\n for i in range(Q):\n #print(wa) \n kari = A[b[i]-1] - A[a[i]-1]\n if kari == c[i]:\n wa = wa + d[i] \n if ans < wa:\n ans = wa\n #print(ans) \n #print(wa) \n\n\nprint(ans)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s022495111', 's461535111', 's518515620']
[27280.0, 9256.0, 21604.0]
[2422.0, 24.0, 1293.0]
[1478, 1418, 1387]
p02695
u690419532
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())\nlist = [list(map(int,input().split())) for _ in range(Q)]\nseq = [i for i in range(1,M+1)]\nC = combinations_with_replacement(seq, N)\nmax_score = 0\n\nfor A in C:\n A = sorted(A)\n score = 0\n for q in list:\n if A[q[1]-1] - A[q[0]-1] == q[2]:\n score += q[3]\n print(score)\n max_score = max(score, max_score)\nprint(max_score)\n', "from itertools import combinations_with_replacement\n\ndef main():\n N, M, Q = map(int, input().split())\n qs = [list(map(int,input().split())) for _ in range(Q)]\n seq = [i for i in range(1,M+1)]\n C = combinations_with_replacement(seq, N)\n max_score = 0\n\n for A in C:\n A = sorted(A)\n score = 0\n for q in qs:\n if A[q[1]-1] - A[q[0]-1] == q[2]:\n score += q[3]\n max_score = max(score, max_score)\n print(max_score)\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s740459295', 's222102989']
[33964.0, 9164.0]
[2250.0, 702.0]
[443, 520]
p02695
u692311686
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=[]\nb=[]\nc=[]\nd=[]\nfor i in range(Q):\n ta,tb,tc,td=map(int,input().split())\n a+=[ta]\n b+=[tb]\n c+=[tc]\n d+=[td]\nmaxs=0\nA=[0 for i in range(N)]\nfor i in intertools.combination_with_replacement(A,N):\n s=0\n for k in range(Q):\n if i[b[k]-1]-i[a[k]-1]==c[k]:\n s+=d[k]\n maxs=max(maxs,s)\n \nprint(maxs)\n', 'N,M,Q=map(int,input().split())\na=[]\nb=[]\nc=[]\nd=[]\nfor i in range(Q):\n ta,tb,tc,td=map(int,input().split())\n a+=[ta]\n b+=[tb]\n c+=[tc]\n d+=[td]\nmaxs=0\nA=[0 for i in range(10)]\nfor i in range(10):\n for j in range(i,10):\n for k in range(j,10):\n for l in range(k,10):\n for m in range(l,10):\n for n in range(m,10):\n for o in range(n,10):\n for p in range(o,10):\n for q in range(p,10):\n for r in range(q,10):\n A[0]=i\n A[1]=j\n A[2]=k\n A[3]=l\n A[4]=m\n A[5]=n\n A[6]=o\n A[7]=p\n A[8]=q\n A[9]=r\n su=0\n for i z in range(Q):\n if A[b[i]]-A[a[i]]==c[i]:\n su+=d[i]\n if su>maxs:\n maxs=su\nprint(maxs)\n', 'N,M,Q=map(int,input().split())\na=[]\nb=[]\nc=[]\nd=[]\nfor i in range(Q):\n ta,tb,tc,td=map(int,input().split())\n a+=[ta]\n b+=[tb]\n c+=[tc]\n d+=[td]\nmaxs=0\n\ndef suuretu(n,m):\n if n>1:\n A=[]\n for i in range(1,9):\n for j in suuretu(n-1,i):\n A+=[10*i+j]\n return A\n else:\n A=[i for i in range(m,10)]\n return A\nB=suuretu(N,1)\nanswer=0\nfor i in B:\n ans=0\n s=str(i)\n tmpl=[int(s[j]) for j in range(N)] \n for k in range(Q):\n if tmpl[a[k]-1]-tmpl[b[k]-1]==c[k]:\n ans+=d[i]\n answer=max(answer,ans)\nprint(answer)\n\n \n', 'N,M,Q=map(int,input().split())\na=[]\nb=[]\nc=[]\nd=[]\nfor i in range(Q):\n ta,tb,tc,td=map(int,input().split())\n a+=[ta]\n b+=[tb]\n c+=[tc]\n d+=[td]\nmaxs=0\nfor i in range(10):\n for j in range(i,10):\n for k in range(j,10):\n for l in range(k,10):\n for m in range(l,10):\n for n in range(m,10):\n for o in range(n,10):\n for p in range(o,10):\n for q in range(p,10):\n for r in range(q,10):\n A[0]=i\n A[1]=j\n A[2]=k\n A[3]=l\n A[4]=m\n A[5]=n\n A[6]=o\n A[7]=p\n A[8]=q\n A[9]=r\n su=0\n for i z in range(Q):\n if A[b[i]]-A[a[i]]==c[i]:\n su+=d[i]\n if su>maxs:\n maxs=su\nprint(maxs)', 'imporrt itertools\nN,M,Q=map(int,input().split())\na=[]\nb=[]\nc=[]\nd=[]\nfor i in range(Q):\n ta,tb,tc,td=map(int,input().split())\n a+=[ta]\n b+=[tb]\n c+=[tc]\n d+=[td]\nmaxs=0\nA=[0 for i in range(N)]\nfor i in itertools.combination_with_replacement(A,N):\n s=0\n for k in range(Q):\n if i[b[k]-1]-i[a[k]-1]==c[k]:\n s+=d[k]\n maxs=max(maxs,s)\n \nprint(maxs)\n', 'import itertools\nN,M,Q=map(int,input().split())\na=[]\nb=[]\nc=[]\nd=[]\nfor i in range(Q):\n ta,tb,tc,td=map(int,input().split())\n a+=[ta]\n b+=[tb]\n c+=[tc]\n d+=[td]\nmaxs=0\nA=[i for i in range(M)]\nfor i in itertools.combinations_with_replacement(A,N):\n s=0\n for k in range(Q):\n if i[b[k]-1]-i[a[k]-1]==c[k]:\n s+=d[k]\n maxs=max(maxs,s)\n \nprint(maxs)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s329281621', 's372158722', 's418649688', 's857481298', 's862838201', 's983956693']
[9160.0, 9120.0, 131904.0, 9064.0, 8864.0, 9048.0]
[21.0, 19.0, 2210.0, 23.0, 23.0, 1170.0]
[348, 980, 560, 954, 365, 365]
p02695
u693007703
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 = list(map(int,input().split()))\nnumbers = [i for i in range(1, M+1)]\narray = itertools.combinations_wih_replacement(numbers, N)\n\ninput_data = [list(map(int,input().split())) for _ in range(Q)]\n\nmax_score = 0\nfor A in array:\n score = 0\n for _ in range(Q):\n a, b, c, d = input_data[_]\n a = a - 1\n b = b - 1\n if A[b] - A[a] == c:\n score += d\n if score > max_score:\n max_score = score\n \nprint(max_score)', 'import itertools\n\nN, M, Q = list(map(int,input().split()))\nnumbers = [i for i in range(1, M+1)]\narray = itertools.combinations_with_replacement(numbers, N)\n\ninput_data = [list(map(int,input().split())) for _ in range(Q)]\n\nmax_score = 0\nfor A in array:\n score = 0\n for _ in range(Q):\n a, b, c, d = input_data[_]\n a = a - 1\n b = b - 1\n if A[b] - A[a] == c:\n score += d\n if score > max_score:\n max_score = score\n \nprint(max_score)']
['Runtime Error', 'Accepted']
['s405535183', 's947754354']
[9216.0, 9216.0]
[25.0, 1551.0]
[484, 485]
p02695
u695079172
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())\nnum_lst = []\nfor i in range(q):\n num_lst.append(list(map(int,input().split())))\nl = list(range(1,m+1))\nA = list(combinations_with_replacement(l,n))\n\nmx = 0\nfor now_A in A:\n score = 0\n for nums in num_lst:\n a,b,c,d = nums\n if now_A[b-1] - now_A[a-1] == c:\n score += d\n mx = max(mx,score)\nprint(mx)\n\n\n\n', 'from itertools import combinations_with_replacement\n\n\nn,m,q = map(int,input().split())\nnum_lst = []\nfor i in range(q):\n num_lst.append(list(map(int,input().split())))\nl = list(range(1,m+1))\nA = list(combinations_with_replacement(l,n))\n\nmx = 0\nfor now_A in A:\n score = 0\n for nums in num_lst:\n a,b,c,d = nums\n if now_A[b-1] - now_A[a-1] == c:\n score += d\n mx = max(mx,score)\nprint(mx)\n\n\n\n']
['Runtime Error', 'Accepted']
['s559256943', 's014409053']
[9092.0, 21628.0]
[21.0, 1085.0]
[371, 424]
p02695
u697696097
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 io import StringIO\nimport unittest\nimport itertools\n\ndef yn(b):\n print("Yes" if b==1 else "No")\n return\n\ndef resolve():\n readline=sys.stdin.readline\n\n n,m,q=map(int, readline().rstrip().split())\n\n aa=[0]*q\n bb=[0]*q\n cc=[0]*q\n dd=[0]*q\n\n for i in range(q):\n aa[i],bb[i],cc[i],dd[i]=map(int, readline().rstrip().split())\n\n max_score=0\n\n for a in itertools.combinations_with_replacement(list(range(1,m+1)),n):\n score=0\n for i in range(q):\n if (a[bb[i]-1]-a[aa[i]-1])==cc[i]:\n score+=dd[i]\n max_score=max(max_score,score)\n\n print(max_score)\n\n return', '### ----------------\n\n### ----------------\n\nimport sys\nfrom io import StringIO\nimport unittest\nimport itertools\n\nsys.setrecursionlimit(500*500)\n\ndef yn(b):\n print("Yes" if b==1 else "No")\n return\n\ndef resolve():\n readline=sys.stdin.readline\n\n n,m,q=map(int, readline().rstrip().split())\n\n aa=[0]*q\n bb=[0]*q\n cc=[0]*q\n dd=[0]*q\n\n for i in range(q):\n aa[i],bb[i],cc[i],dd[i]=map(int, readline().rstrip().split())\n\n max_score=0\n\n for a in itertools.combinations_with_replacement(list(range(1,m+1)),n):\n score=0\n for i in range(q):\n if (a[bb[i]-1]-a[aa[i]-1])==cc[i]:\n score+=dd[i]\n max_score=max(max_score,score)\n\n print(max_score)\n\n return\n\nif \'doTest\' not in globals():\n resolve()\n sys.exit()\n\n\n### ----------------\n\n### ----------------']
['Wrong Answer', 'Accepted']
['s968063180', 's329778979']
[16224.0, 16220.0]
[67.0, 763.0]
[655, 869]
p02695
u726615467
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\nq = []\ndef dp(arg):\n global N\n if len(arg) == N:\n q.append(arg)\n else:\n tmp = 0 if len(arg) == 0 else arg[-1]\n for i in range(arg[-1], M + 1):\n dp(arg + [i])\n\ndp([])\n\nans = 0\nfor A_tmp in q:\n ans_tmp = 0\n for j, (aj, bj, cj, dj) in enumerate(abcd):\n if A_tmp[bj - 1] - A_tmp[aj - 1] == cj:\n ans_tmp += dj\n #\n ans = max(ans, ans_tmp)\n\nprint(ans)', 'N, M, Q = map(int, input().split())\nabcd = [list(map(int, input().split())) for _ in range(Q)]\n\nAs = []\nq = [[]]\nwhile len(q) > 0:\n arg = q.pop()\n if len(arg) == N:\n As.append(arg)\n else:\n A_str = 1 if len(arg) == 0 else arg[-1]\n for i in range(A_str, M + 1):\n q.append(arg + [i])\n\nans = 0\nfor A in As:\n ans_tmp = 0\n for j, (aj, bj, cj, dj) in enumerate(abcd):\n if A[bj - 1] - A[aj - 1] == cj:\n ans_tmp += dj\n #\n ans = max(ans, ans_tmp)\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s440555826', 's566788457']
[9160.0, 22980.0]
[23.0, 1305.0]
[511, 519]
p02695
u727980193
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=list(map(int,input().split()))\nsrc=[list(map(int,input().split())) for q in range(Q)]\nML=[n+1 for n in range(M)]\nX=list(itertools.combinations_with_replacement(ML,N))\nL=[]\nfor x in X:\n a=0\n for s in src:\n if x[s[1]] - x[s[0]] == s[2]:\n a+=s[3]\n L.append(a)\nprint(max(L))', 'import itertools\nN,M,Q=list(map(int,input().split()))\nsrc=[]\nfor q in range(Q):\n src.append(list(map(int,input().split())))\nML=[n+1 for n in range(M)]\nX=list(itertools.combinations_with_replacement(ML,N))\nL=[]\nfor x in X:\n a=0\n for s in src:\n if x[s[1]-1] - x[s[0]-1] == s[2]:\n a+=s[3]\n L.append(a)\nprint(max(L))']
['Runtime Error', 'Accepted']
['s911607175', 's639395796']
[21544.0, 25352.0]
[45.0, 976.0]
[304, 324]
p02695
u731028462
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()))\nC = []\nfor i in range(Q):\n C.append(list(map(int, input().split())))\n \nimport itertools\nres = 0\nls=list(range(1,M+1))\nfor a in itertools.combinations_with_replacement(ls, N):\n p = 0\n for c in C:\n if a[c[1]]-a[c[0]]==c[2]:\n p += c[3]\n res = max(res,p)\nprint(res)', 'import itertools\n\nN,M,Q = list(map(int, input().split()))\nC = []\nfor i in range(Q):\n C.append(list(map(int, input().split())))\n \nres = 0\nls=list(range(1,M+1))\n\nfor a in itertools.combinations_with_replacement(ls, N):\n p = 0\n for c in C:\n if a[c[1]]-a[c[0]]==c[2]:\n p += c[3]\n res = max(res,p)\n\nprint(res)', 'N,M,Q = list(map(int, input().split()))\nC = []\nfor i in range(Q):\n C.append(list(map(int, input().split())))\n \nimport itertools\nres = 0\nls=list(range(1,M+1))\nfor a in itertools.combinations_with_replacement(ls, N):\n p = 0\n for c in C:\n if a[c[1]-1]-a[c[0]-1]==c[2]:\n p += c[3]\n res = max(res,p)\nprint(res)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s242940460', 's342775919', 's206169162']
[9220.0, 9220.0, 9240.0]
[18.0, 22.0, 1811.0]
[338, 341, 342]
p02695
u735891571
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())\nABCD = [tuple(map(int, input().split())) for _ in range(Q)]\nans = 0\nfor s in itertools.combinations_with_replacement(range(1,N+1),N):\n temp = 0\n for i in range(Q):\n if s[ABCD[i][1]-1] - s[ABCD[i][0]-1] == ABCD[i][2]:\n temp += ABCD[i][3]\n ans = max(ans,temp)\nprint(ans)', 'import itertools\nN, M, Q = map(int,input().split())\nABCD = [tuple(map(int, input().split())) for _ in range(Q)]\nans = 0\nfor s in itertools.combinations_with_replacement(range(1,M+1),N):\n temp = 0\n for i in range(Q):\n if s[ABCD[i][1]-1] - s[ABCD[i][0]-1] == ABCD[i][2]:\n temp += ABCD[i][3]\n ans = max(ans,temp)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s657358777', 's066858495']
[9084.0, 9212.0]
[1375.0, 1284.0]
[347, 347]
p02695
u736470924
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())\nI = list(range(1, m + 1))\nA = list(map(list, itertools.combinations(I, n)))\nl = len(A)\nans = [0 for i in range(l)]\nfor _ in range(q):\n a, b, c, d = map(int, input().split())\n for i in range(l):\n if A[i][b - 1] - A[i][a - 1] == c:\n ans[i] += d\nprint(max(ans))', 'import itertools\n\nn, m, q = map(int, input().split())\nI = list(range(1, m + 1))\nA = list(map(list, itertools.combinations_with_replacement(I, n)))\nl = len(A)\nans = [0 for i in range(l)]\nfor _ in range(q):\n a, b, c, d = map(int, input().split())\n for i in range(l):\n if A[i][b - 1] - A[i][a - 1] == c:\n ans[i] += d\nprint(max(ans))\n']
['Runtime Error', 'Accepted']
['s531141048', 's483366619']
[9208.0, 26340.0]
[24.0, 1064.0]
[318, 354]
p02695
u736641785
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 = list(map(int,input().split()))\nA = [list(map(int,input().split())) for i in range(q)]\ndef keisan(tup):\n ans_keisan = 0\n print(tup)\n for j in A:\n if tup[j[1]-1] - tup[j[0]-1] == j[2]:\n ans_keisan += j[3]\n return ans_keisan\nans = 0\nfor i in combinations_with_replacement(range(m),n):\n ans = max(keisan(i), ans)\nprint(ans)', 'from itertools import combinations_with_replacement\n\nn, m, q = list(map(int,input().split()))\nA = [list(map(int,input().split())) for i in range(q)]\ndef keisan(tup):\n ans_keisan = 0\n for j in A:\n if tup[j[1]-1] - tup[j[0]-1] == j[2]:\n ans_keisan += j[3]\n return ans_keisan\nans = 0\nfor i in combinations_with_replacement(range(m),n):\n ans = max(keisan(i), ans)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s844477416', 's129246998']
[9068.0, 9204.0]
[787.0, 676.0]
[415, 400]
p02695
u740267532
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 _ in range(Q):\n L.append(list(map(int,input().split())))\n\nA = itertools.combinations_with_replacement([i for i in range(1,M+1)], N)\ncount = []\nfor a in A:\n temp = 0\n for l in l:\n if a[l[1]-1] - a[l[0]-1] == l[2]:\n temp += l[3]\n count.append(temp)\nprint(max(count))', 'import itertools\nN, M, Q = map(int,input().split())\nL = []\nfor _ in range(Q):\n L.append(list(map(int,input().split())))\n\nA = itertools.combinations_with_replacement([i for i in range(1,M+1)], N)\ncount = []\nfor a in A:\n temp = 0\n for l in l:\n if a[l[1]-1] - a[l[0]-1] == l[2]:\n temp += l[3]\n count.append(temp)\nprint(max(count))', 'import itertools\nN, M, Q = map(int,input().split())\nL = []\nfor _ in range(Q):\n L.append(list(map(int,input().split())))\n\nA = itertools.combinations_with_replacement([i for i in range(1,M+1)], N)\ncount = []\nfor a in A:\n temp = 0\n for l in L:\n if a[l[1]-1] - a[l[0]-1] == l[2]:\n temp += l[3]\n count.append(temp)\nprint(max(count))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s537876284', 's980205473', 's166401395']
[9108.0, 9100.0, 12524.0]
[23.0, 20.0, 1062.0]
[357, 357, 357]
p02695
u744920373
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**8)\ndef ii(): return int(sys.stdin.readline())\ndef mi(): return map(int, sys.stdin.readline().split())\ndef li(): return list(map(int, sys.stdin.readline().split()))\ndef li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]\ndef dp2(ini, i, j): return [[ini]*i for i2 in range(j)]\ndef dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]\n\n#from collections import defaultdict #d = defaultdict(int) d[key] += value\n#from collections import Counter # a = Counter(A).most_common()\n#from itertools import accumulate #list(accumulate(A))\n\nN, M, Q = mi()\nabcd = li2(Q)\n\n'''\na = '0' * N\nm = str(M-1)\nl = [a]\n\nwhile True:\n i = N-1\n while i >= 0 and a[i] == m:\n i -= 1\n if i == -1:\n break\n a = list(a)\n num = str(int(a[i]) + 1)\n a[i] = num\n if i != N-1:\n for j in range(i+1, N):\n a[j] = num\n tmp = ''.join(a)\n l.append(tmp)\n'''\n\ndef dfs(num, length):\n if length == N:\n l.append(num)\n return\n last = int(num[-1])\n for i in range(last, M):\n dfs(num + str(i), length+1)\n\ndfs('0', 1)\nans = 0\nfor num in l:\n cnt = 0\n num = list(map(int, list(num)))\n for i in range(Q):\n if num[abcd[i][1]-1] - num[abcd[i][0]-1] == abcd[i][2]:\n cnt += abcd[i][3]\n ans = max(ans, cnt)\n\nprint(ans)", "import sys\nsys.setrecursionlimit(10**8)\ndef ii(): return int(sys.stdin.readline())\ndef mi(): return map(int, sys.stdin.readline().split())\ndef li(): return list(map(int, sys.stdin.readline().split()))\ndef li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]\ndef dp2(ini, i, j): return [[ini]*i for i2 in range(j)]\ndef dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]\n\n#from collections import defaultdict #d = defaultdict(int) d[key] += value\n#from collections import Counter # a = Counter(A).most_common()\n#from itertools import accumulate #list(accumulate(A))\n\nN, M, Q = mi()\nabcd = li2(Q)\n\n'''\na = '0' * N\nm = str(M-1)\nl = [a]\n\nwhile True:\n i = N-1\n while i >= 0 and a[i] == m:\n i -= 1\n if i == -1:\n break\n a = list(a)\n num = str(int(a[i]) + 1)\n a[i] = num\n if i != N-1:\n for j in range(i+1, N):\n a[j] = num\n tmp = ''.join(a)\n l.append(tmp)\n'''\n\ndef dfs(num, length):\n if length == N:\n l.append(num)\n return\n last = int(num[-1])\n for i in range(last, M):\n dfs(num + str(i), length+1)\n\nl = []\ndfs('0', 1)\n\nans = 0\nfor num in l:\n cnt = 0\n num = list(map(int, list(num)))\n for i in range(Q):\n if num[abcd[i][1]-1] - num[abcd[i][0]-1] == abcd[i][2]:\n cnt += abcd[i][3]\n ans = max(ans, cnt)\n\nprint(ans)"]
['Runtime Error', 'Accepted']
['s063666743', 's352413990']
[9284.0, 12504.0]
[22.0, 831.0]
[1405, 1413]
p02695
u745514010
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 bisect\n\ndef lis(lst):\n lis_lst = [lst[0]]\n for i in lst:\n if i > lis_lst[-1]:\n lis_lst.append(i)\n else:\n lis_lst[bisect.bisect_left(lis_lst, i)] = i\n return len(lis_lst)\n\nn = int(input())\n\na = list(map(int, input().split()))\n\nuv = {}\nfor _ in range(n-1):\n u, v = map(int, input().split())\n uv[v] = u\n \nfor i in range(1, n + 1):\n lst = [] \n while i != 1:\n lst.append(a[i - 1])\n i = uv[i]\n lst.append(a[0])\n lst.reverse()\n print(lis(lst))', 'import itertools\n\nn, m, q = map(int, input().split())\nlst = []\nfor _ in range(q):\n item = list(map(int, input().split()))\n lst.append(item)\n\nmax_num = 0\nfor num_lst in itertools.combinations_with_replacement(range(1, m + 1), n):\n count = 0\n for a, b, c, d in lst:\n if num_lst[b - 1] - num_lst[a - 1] == c:\n count += d\n max_num = max(max_num, count)\nprint(max_num)']
['Runtime Error', 'Accepted']
['s297927508', 's550324679']
[9156.0, 9072.0]
[20.0, 1011.0]
[529, 396]
p02695
u747703115
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\nreadline = sys.stdin.readline\n\ndef score(A):\n t = 0\n for ai,bi,ci,di in zip(a,b,c,d):\n if A[bi]-A[ai]==ci:\n t += di\n return t\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\nn, m, q = map(int, readline().split())\nA,B,C,D = [0]*q, [0]*q, [0]*q, [0]*q\nfor i in range(q):\n a,b,C[i],D[i] = map(int, readline().split())\n A[i] = a-1\n B[i] = b-1\n\nprint(dfs([]))', 'import sys\nreadline = sys.stdin.readline\nsys.setrecursionlimit(10**6)\n\ndef score(Ans):\n t = 0\n for ai,bi,ci,di in zip(A,B,C,D):\n if Ans[bi]-Ans[ai]==ci:\n t += di\n return t\n\ndef dfs(Ans):\n if len(Ans)==n:\n return score(Ans)\n ans = 0\n prev_last = Ans[-1] if len(Ans)>0 else 0\n for v in range(prev_last, m):\n Ans.append(v)\n ans = max(ans, dfs(Ans))\n Ans.pop()\n return ans\n\nn, m, q = map(int, readline().split())\nA,B,C,D = [0]*q, [0]*q, [0]*q, [0]*q\nfor i in range(q):\n a,b,C[i],D[i] = map(int, readline().split())\n A[i] = a-1\n B[i] = b-1\n\nprint(dfs([]))']
['Runtime Error', 'Accepted']
['s534604493', 's708627554']
[8980.0, 9256.0]
[24.0, 559.0]
[578, 629]
p02695
u752907966
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())\nli=[list(map(int,input().split()))for _ in range(q)]\nans = 0\ndef dfs(i,A):\n global ans \n if i == m:\n return\n tmp = 0\n for a,b,c,d in li:\n if A[b-1] - A[a-1] == c:\n tmp += d \n ans = max(ans,tmp)\n tmp = A[:]\n for j in range(n):\n tmp = A[:]\n for k in range(1,j+2):\n tmp[-k] += 1\n dfs(i+1,tmp)\ndfs(1,[1]*n)\nprint(ans)', 'n,m,q=map(int,input().split())\nli=[list(map(int,input().split()))for _ in range(q)]\n\nans = 0\ndef dfs(A):\n #print(A)\n global ans \n if len(A) == n+1:\n tmp = 0\n for a,b,c,d in li:\n if A[b] - A[a] == c:\n tmp += d\n ans = max(ans,tmp)\n return\n for i in range(A[len(A)-1],m+1):\n dfs(A+[i])\ndfs([1])\nprint(ans)']
['Wrong Answer', 'Accepted']
['s339854382', 's722925928']
[9228.0, 9132.0]
[2205.0, 1069.0]
[422, 379]
p02695
u756518877
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 -*-\nfrom itertools import itertools.combinations_with_replacement\nN,M,Q=map(int,input().split())\nabcd=[]\nfor _ in range(Q):\n abcd.append(tuple(map(int,input().split())))\nAbase=[]\nfor a in range(1,M+1):\n Abase=Abase+[a]\nA=set(itertools.combinations_with_replacement(Abase,N))\nans=0\nfor i in A:\n temp=0\n for j in abcd:\n if i[j[1]-1]-i[j[0]-1]==j[2]:\n temp=temp+j[3]\n if temp>=ans:\n ans=temp\nprint(ans)', '# -*- coding: utf-8 -*-\nfrom itertools import itertools_with_replacement\nN,M,Q=map(int,input().split())\nabcd=[]\nfor _ in range(Q):\n abcd.append(tuple(map(int,input().split())))\nAbase=[]\nfor a in range(1,M+1):\n Abase=Abase+[a]\nA=set(itertools.combinations_with_replacement(Abase,N))\nans=0\nfor i in A:\n temp=0\n for j in abcd:\n if i[j[1]-1]-i[j[0]-1]==j[2]:\n temp=temp+j[3]\n if temp>=ans:\n ans=temp\nprint(ans)', '# -*- coding: utf-8 -*-\nfrom itertools import itertools_with_replacement\nN,M,Q=map(int,input().split())\nabcd=[]\nfor _ in range(Q):\n abcd.append(tuple(map(int,input().split())))\nAbase=[]\nfor a in range(1,M+1):\n Abase=Abase+[a]\nA=set(itertools.combinations_with_replacement(Abase,N))\nans=0\nfor i in A:\n temp=0\n for j in abcd:\n if i[j[1]-1]-i[j[0]-1]==j[2]:\n temp=temp+j[3]\n if temp>=ans:\n ans=temp\nprint(ans)', '# -*- coding: utf-8 -*-\nfrom itertools import combinations_with_replacement as comb\nN,M,Q=map(int,input().split())\nabcd=[]\nfor _ in range(Q):\n abcd.append(tuple(map(int,input().split())))\nAbase=[]\nfor a in range(1,M+1):\n Abase=Abase+[a]\nA=set(comb(Abase,N))\nans=0\nfor i in A:\n temp=0\n for j in abcd:\n if i[j[1]-1]-i[j[0]-1]==j[2]:\n temp=temp+j[3]\n if temp>=ans:\n ans=temp\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s283762434', 's512614914', 's895966471', 's007670903']
[9016.0, 9080.0, 9148.0, 25308.0]
[21.0, 22.0, 22.0, 970.0]
[459, 446, 446, 422]
p02695
u761087127
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 = [int(n) for n in input().split()]\nX = [[int(n) for n in input().split()] for _ in range(Q)]\nans = []\nfor A in combinations_with_replacement(range(1, M+1), N):\n t = 0\n for x in X:\n if A[x[1]-1]-A[x[0]-1] == x[2]:\n t += x[3]\n print(A, t)\n ans.append(t)\nprint(max(ans))\n', 'N, M, Q = [int(n) for n in input().split()]\na, b, c, d = [list(x) for x in zip(*[[int(n) for n in input().split()] for _ in range(Q)])]\nans = 0\n\ndef dfs(A):\n global ans\n if len(A) == N:\n now = 0\n for i in range(Q):\n if A[b[i]-1] - A[a[i]-1] == c[i]: now += d[i]\n ans = max(ans, now)\n return\n\n for v in range(A[-1], M+1):\n A.append(v)\n dfs(A)\n A.pop()\n\ndfs([1])\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s480874286', 's616970309']
[12544.0, 9208.0]
[1137.0, 422.0]
[359, 441]
p02695
u762540523
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 resolve():\n n, m, q = map(int, input().split())\n queue = []\n for i in range(q):\n queue.append(list(map(int, input().split())))\n ans = 0\n import itertools\n l = list(itertools.combinations(range(1, n + m), m))\n for i in l:\n a = [x - y for y, x in enumerate(i)]\n x = 0\n for j in queue:\n if a[j[1] - 1] - a[j[0] - 1] == j[2]:\n x += j[3]\n ans = max(ans, x)\n print(ans)\n\n\nif __name__ == '__main__':\n resolve()\n", "def resolve():\n n, m, q = map(int, input().split())\n queue = []\n for i in range(q):\n queue.append(list(map(int, input().split())))\n ans = 0\n import itertools\n l = itertools.combinations(range(1, n + m), n)\n for i in l:\n a = [x - y for y, x in enumerate(i)]\n x = 0\n for j in queue:\n if a[j[1] - 1] - a[j[0] - 1] == j[2]:\n x += j[3]\n ans = max(ans, x)\n print(ans)\n\n\nif __name__ == '__main__':\n resolve()\n"]
['Runtime Error', 'Accepted']
['s814713325', 's545287196']
[21480.0, 9216.0]
[760.0, 739.0]
[496, 490]
p02695
u764215612
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 = map(int, input().split())\nans = 0\ns = max(int(b/a),e-1000)\ne = min(n+1,b)\nfor i in range(s, e):\n x = (int(a*i/b)-a*int(i/b))\n if ans < x:\n ans = x\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())\nA = [1] * 10\n\ndef check(A, ans):\n t = 0\n for i in range(q):\n if A[b[i]] - A[a[i]] == c[i]:\n t += d[i]\n if ans < t:\n return t\n else:\n return ans\n\nans = 0\nfor i1 in range(1, m):\n A[1] = i1\n for i2 in range(i1, m):\n A[2] = i2\n for i3 in range(i2, m):\n A[3] = i3\n for i4 in range(i3, m):\n A[4] = i4\n for i5 in range(i4, m):\n A[5] = i5\n for i6 in range(i5, m):\n A[6] = i6\n for i7 in range(i6, m):\n A[7] = i7\n for i8 in range(i7, m):\n A[8] = i8\n for i9 in range(i8, m):\n A[9] = i9\n ans = check(A, ans)\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())\nA = [1] * 10\n\ndef check(A, ans):\n t = 0\n for i in range(q):\n if A[b[i]] - A[a[i]] == c[i]:\n t += d[i]\n if ans < t:\n return t\n else:\n return ans\n\nans = 0\nfor i1 in range(1, m):\n A[1] = i1\n for i2 in range(i1, m):\n A[2] = i2\n for i3 in range(i2, m):\n A[3] = i3\n for i4 in range(i3, m):\n A[4] = i4\n for i5 in range(i4, m):\n A[5] = i5\n for i6 in range(i5, m):\n A[6] = i6\n for i7 in range(i6, m):\n A[7] = i7\n for i8 in range(i7, m):\n A[8] = i8\n for i9 in range(i8, m):\n A[9] = i9\n ans = check(A, ans)\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())\nA = [1] * 10\n\ndef check(A, ans):\n t = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n t += d[i]\n if ans < t:\n return t\n else:\n return ans\n\nans = 0\nfor i1 in range(1, m):\n A[1] = i1\n if n >= 3:\n for i2 in range(i1, m):\n A[2] = i2\n if n >= 4:\n for i3 in range(i2, m):\n A[3] = i3\n if n >= 5:\n for i4 in range(i3, m):\n A[4] = i4\n if n >= 6:\n for i5 in range(i4, m):\n A[5] = i5\n if n >= 7:\n for i6 in range(i5, m):\n A[6] = i6\n if n >= 8:\n for i7 in range(i6, m):\n A[7] = i7\n if n >= 9:\n for i8 in range(i7, m):\n A[8] = i8\n if n >= 10:\n for i9 in range(i8, m):\n A[9] = i9\n ans = check(A, ans)\n else:\n ans = check(A, ans)\n else:\n ans = check(A, ans)\n else:\n ans = check(A, ans)\n else:\n ans = check(A, ans)\n else:\n ans = check(A, ans)\n else:\n ans = check(A, ans)\n else:\n ans = check(A, ans)\n else:\n ans = check(A, ans)\nprint(ans)', 'n, m, q = map(int, input().split())\na, b, c, d = [0]*q, [0]*q, [0]*q, [0]*q\nfor i in range(q): a[i], b[i], c[i], d[i] = map(int, input().split())\nA = [1] * 10\n \ndef check(A, ans):\n t = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n t += d[i]\n if ans < t: return t\n else: return ans\n \nans = 0\nfor i1 in range(1, m+1):\n A[1] = i1\n for i2 in range(i1, m+1):\n A[2] = i2\n for i3 in range(i2, m+1):\n A[3] = i3\n for i4 in range(i3, m+1):\n A[4] = i4\n for i5 in range(i4, m+1):\n A[5] = i5\n for i6 in range(i5, m+1):\n A[6] = i6\n for i7 in range(i6, m+1):\n A[7] = i7\n for i8 in range(i7, m+1):\n A[8] = i8\n for i9 in range(i8, m+1):\n A[9] = i9\n ans = check(A, ans)\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s108191939', 's298714029', 's473762506', 's666568600', 's645338397']
[9188.0, 9164.0, 9176.0, 9224.0, 9308.0]
[22.0, 62.0, 60.0, 231.0, 398.0]
[172, 834, 834, 1695, 848]
p02695
u764956288
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\n\ndef main():\n n_ints, max_int, n_queries = map(int, input().split())\n\n queries = (list(map(int, input().split())) for _ in range(n_queries))\n\n possible_sequences = combinations_with_replacement(range(1, max_int+1), n_ints)\n\n max_score = 0\n for sequence in possible_sequences:\n score = 0\n\n for i, q in enumerate(queries):\n a, b, c, d = q\n if sequence[b-1] - sequence[a-1] == c:\n score += d\n\n max_score = max(max_score, score)\n\n print(max_score)\n\n\nif __name__ == "__main__":\n main()\n', 'from itertools import combinations_with_replacement\n\n\ndef main():\n n_ints, max_int, n_queries = map(int, input().split())\n\n queries = [list(map(int, input().split())) for _ in range(n_queries)]\n\n possible_sequences = combinations_with_replacement(range(1, max_int+1), n_ints)\n\n max_score = 0\n for sequence in possible_sequences:\n score = 0\n\n for i, q in enumerate(queries):\n a, b, c, d = q\n if sequence[a-1] - sequence[b-1] == c:\n score += d\n\n max_score = max(max_score, score)\n\n print(max_score)\n\n\nif __name__ == "__main__":\n main()\n', 'import sys\nfrom itertools import combinations_with_replacement\n\ninput = sys.stdin.buffer.readline\n\n\ndef main():\n n_ints, max_int, n_queries = map(int, input().split())\n\n queries = [list(map(int, input().split())) for _ in range(n_queries)]\n\n possible_sequences = combinations_with_replacement(range(1, max_int+1), n_ints)\n\n max_score = 0\n for sequence in possible_sequences:\n score = 0\n\n for i, q in enumerate(queries):\n a, b, c, d = q\n if sequence[b-1] - sequence[a-1] == c:\n score += d\n\n max_score = max(max_score, score)\n\n print(max_score)\n\n\nif __name__ == "__main__":\n main()\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s362770461', 's891650293', 's594859677']
[9224.0, 9216.0, 9260.0]
[45.0, 577.0, 603.0]
[613, 613, 659]
p02695
u772029934
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())\nli = []\ncounter = 0\nn = []\nfor s in range(Q):\n li.append(list(map(int,input().strip())))\n\nfor i in range(10**(N-1),10**N):\n k = str(i)\n for q in range(Q):\n if k[li[q][1]] - k[li[q][0]] == k[li[q][2]]:\n counter += k[li[q][3]]\n n.append(counter)\n counter = 0\nprint(max(n))', 'N,M,Q = map(int,input().split())\nli = []\ncounter = 0\nn = []\nfor s in range(Q):\n li.append(list(map(int,input().strip())))\n\nfor i in range(10**(N-1),10**N):\n k = str(i)\n for q in range(Q):\n if k[li[q][1]] - k[li[q][0]] == k[li[q][2]]:\n counter += k[li[q][3]]\n n.append(counter)\n counter = 0\nprint(max)', 'N,M,Q = map(int,input().split())\n\nli = [list(map(int,input().split())) for i in range(Q) ]\n\nfrom itertools import combinations_with_replacement\ncounter = []\n\nfor comb in combinations_with_replacement(range(1,M+1),N):\n A = list(comb)\n tmp = 0\n \n for i in li:\n if A[i[1]-1] - A[i[0]-1] == i[2]:\n tmp += i[3]\n\n counter.append(tmp)\n\n\nprint(max(counter))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s262912029', 's426593393', 's362127838']
[9216.0, 9148.0, 12520.0]
[22.0, 20.0, 1195.0]
[323, 320, 381]
p02695
u797572808
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 as it\n\nn,m,q = map(int,input().split())\n\nar = [[0]*4]*q\n\nfor i in range(q):\n ar[i] = [int(s) for s in input().split()]\n\nA = it.combinations_with_replacement(list(range(1,m+1)),n)\nmx = 0\n\nfor cnd in A:\n mx_tmp=0\n for i in range(q):\n if(A[ar[i][1]-1] - A[ar[i][0]-1] == ar[i][2]):\n mx_tmp += ar[i][3]\n mx = max(mx,mx_tmp)\n\nprint(mx)', 'import itertools as it\n\nn,m,q = map(int,input().split())\n\nar = [[0]*4]*q\n\nfor i in range(q):\n ar[i] = [int(s) for s in input().split()]\n\nA = list(it.combinations_with_replacement(list(range(1,m+1)),n))\nmx = 0\n\nfor cnd in A:\n mx_tmp=0\n for i in range(q):\n if(cnd[ar[i][1]-1] - cnd[ar[i][0]-1] == ar[i][2]):\n mx_tmp += ar[i][3]\n mx = max(mx,mx_tmp)\n\nprint(mx)']
['Runtime Error', 'Accepted']
['s059745866', 's836741663']
[9224.0, 21476.0]
[22.0, 1403.0]
[377, 387]
p02695
u802234211
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 as itr\nN,M,Q = map(int,input().split())\nsheat = list()\nfor i in range(Q):\n sheat.append(list(map(int,input().split())))\n\ncomb = tuple(itr.combinations(range(1,M+1),N))\nMaxsum = 0\nprint(sheat)\nprint(comb)\nsumd = 0\nfor i in range(len(comb)):\n ansum = 0\n for j in range(Q):\n if(comb[i][sheat[j][1]-1]-comb[i][sheat[j][0]-1] == sheat[j][2]):\n ansum += sheat[j][3]\n \n if(Maxsum < ansum):\n Maxsum = ansum\n # print(ansum)\nprint(Maxsum) \n\n# sumd += sheat[i][3]\n# print(sumd)\n#nCm\n\n#A_1,A_2,A_3,...A_n,M\n\n\n\n\n# 2:3 - 1 = 2o 10 [1,2,2]\n# 3:4 - 3 = 1* 10 [2,3,2]\n# 110\n', 'import itertools as itr\nN,M,Q = map(int,input().split())\nsheat = list()\nfor i in range(Q):\n sheat.append(list(map(int,input().split())))\n\ncomb = tuple(itr.combinations_with_replacement(range(1,M+1),N))\nMaxsum = 0\n# print(sheat)\n# print(comb)\nsumd = 0\nfor i in range(len(comb)):\n ansum = 0\n for j in range(Q):\n if(comb[i][sheat[j][1]-1]-comb[i][sheat[j][0]-1] == sheat[j][2]):\n ansum += sheat[j][3]\n \n if(Maxsum < ansum):\n Maxsum = ansum\n # print(ansum)\nprint(Maxsum) \n\n# sumd += sheat[i][3]\n# print(sumd)\n#nCm\n\n#A_1,A_2,A_3,...A_n,M\n\n\n\n\n# 2:3 - 1 = 2o 10 [1,2,2]\n# 3:4 - 3 = 1* 10 [2,3,2]\n# 110\n']
['Wrong Answer', 'Accepted']
['s211446346', 's787214811']
[9184.0, 21772.0]
[24.0, 1596.0]
[791, 812]
p02695
u829203929
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\nimport itertools\ndef main():\n n, m, q = map(int, input().split())\n matrix = []\n for _ in range(q):\n row = list(map(int, input().split()))\n matrix.append(row)\n # print(matrix)\n A = list(range(1, m))\n ans = 0\n for tmp_A in itertools.combinations_with_replacement(A, n):\n tmp_A = sorted(list(tmp_A))\n tmp_ans = 0\n for row in matrix:\n # print("row", row)\n # print("tmp_A", tmp_A)\n tmp = tmp_A[row[1] - 1] - tmp_A[row[0]- 1]\n if row[2] == tmp:\n tmp_ans += row[3]\n if tmp_ans >= ans:\n ans = tmp_ans\n \n print(ans)\n \nmain()', '# coding: utf-8\nimport itertools\ndef main():\n n, m, q = map(int, input().split())\n matrix = []\n for _ in range(q):\n row = list(map(int, input().split()))\n matrix.append(row)\n # print(matrix)\n A = list(range(1, m+1))\n ans = 0\n for tmp_A in itertools.combinations_with_replacement(A, n):\n tmp_A = sorted(list(tmp_A))\n tmp_ans = 0\n for row in matrix:\n # print("row", row)\n # print("tmp_A", tmp_A)\n tmp = tmp_A[row[1] - 1] - tmp_A[row[0]- 1]\n if row[2] == tmp:\n tmp_ans += row[3]\n if tmp_ans >= ans:\n ans = tmp_ans\n \n print(ans)\n \nmain()']
['Wrong Answer', 'Accepted']
['s357323572', 's120262809']
[9124.0, 9124.0]
[350.0, 702.0]
[681, 683]
p02695
u833738197
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.
['#166d\nx = int(input())\nfor i in range(-73,73):\n for j in range(-73,73):\n print(i,j)\n if i**5-j**5==x:\n a = i\n b = j\n break\n \nprint(a,b)', 'from itertools import combinations_with_replacement\n\nn,m,q = map(int,input().split())\ns_list = [list(map(int,input().split())) for _ in range(q)]\n\nans = 0\nfor c in combinations_with_replacement(range(1,m+1),n):\n v = 0\n for s in s_list:\n if c[s[1]-1] - c[s[0]-1] == s[2]:\n v+=s[3]\n \n ans = max(ans,v)\nprint(ans)']
['Runtime Error', 'Accepted']
['s187112020', 's665312233']
[9072.0, 9192.0]
[20.0, 975.0]
[192, 340]
p02695
u842388336
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())\nlist_ = [list(map(int, input().split())) for _ in range(q)]\ntmp = list(range(1,m+1))\ncases = [sorted(list(arr)) for arr in itertools.product(tmp, repeat=n)]\n\nmax_score = 0\nvisited = set()\nfor arr in cases:\n score = 0\n if str(arr) in visited:\n break\n visited.add(str(arr))\n for arr_2 in list_:\n if arr[arr_2[1]-1] - arr[arr_2[0]-1] == arr_2[2]:\n score+=arr_2[3]\n max_score = max(max_score, score)\nprint(max_score)', 'import itertools\n\nn,m,q = map(int, input().split())\nlist_ = [list(map(int, input().split())) for _ in range(q)]\n\nnum=1\nseed = [[i] for i in range(1,m+1)]\nwhile num!=n:\n num+=1\n tmp_list = []\n while seed:\n tmp = seed.pop()\n for i in range(tmp[-1],m+1):\n tmp_list.append(tmp+[i])\n seed = tmp_list.copy()\n\nmax_score = 0\nvisited = set()\nfor arr in seed:\n score = 0\n for arr_2 in list_:\n if arr[arr_2[1]-1] - arr[arr_2[0]-1] == arr_2[2]:\n score+=arr_2[3]\n max_score = max(max_score, score)\nprint(max_score)']
['Wrong Answer', 'Accepted']
['s492703851', 's162268043']
[510204.0, 23900.0]
[2218.0, 1107.0]
[480, 531]
p02695
u854685063
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 sys\nimport math\ndef I():return int(sys.stdin.readline().replace("\\n",""))\ndef I2():return map(int,sys.stdin.readline().replace("\\n","").split())\ndef S():return str(sys.stdin.readline().replace("\\n",""))\ndef L():return list(sys.stdin.readline().replace("\\n",""))\ndef intl():return [int(k) for k in sys.stdin.readline().replace("\\n","").split()]\ndef Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\\n","").split()))\nn,m,q = I2()\nr = []\na = [0]*q\nb = [0]*q\nc = [0]*q\nd = [0]*q\nans = []\nimport copy\ndef dfs(A):\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]:now += d[i]\n ans.append(now)\n return\n A.append(A[-1])\n while (A[-1] <= m):\n dfs(copy.copy(A))\n A[-1] += 1\nif __name__ == "__main__":\n for i in range(q):\n a[i],b[i],c[i],d[i] = I2()\n dfs([1])\n print(max(ans))']
['Runtime Error', 'Accepted']
['s370842437', 's814664538']
[8984.0, 12728.0]
[24.0, 726.0]
[124, 898]
p02695
u857293613
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\nn, m, q = map(int, input().split())\nalis, blis, clis, dlis = [], [], [], []\nfor _ in range(q):\n a, b, c, d = map(int, input().split())\n alis.append(a)\n blis.append(b)\n clis.append(c)\n dlis.append(d)\nsys.setrecursionlimit(10**9)\nAlist = [] \ndef dfs(A):\n if len(A)==(n+1):\n Alist.append(A)\n return\n for i in range(A[-1], m+1):\n A.append(i)\n dfs(A)\n\ndfs([1])\n\nans = 0\nfor A in Alist:\n score = 0\n for i in range(q):\n if A[blis[i]] - A[alis[i]] == clis[i]:\n score += dlis[i]\n ans = max(ans, score)\n\nprint(ans)', 'import sys\nn, m, q = map(int, input().split())\nalis, blis, clis, dlis = [], [], [], []\nfor _ in range(q):\n a, b, c, d = map(int, input().split())\n alis.append(a)\n blis.append(b)\n clis.append(c)\n dlis.append(d)\nsys.setrecursionlimit(10**9)\nAlist = [] \ndef dfs(A):\n if len(A)==(n+1):\n Alist.append(A)\n return\n for i in range(A[-1], m+1):\n dfs(A+[i])\n\ndfs([1])\n\nans = 0\nfor A in Alist:\n score = 0\n for i in range(q):\n if A[blis[i]] - A[alis[i]] == clis[i]:\n score += dlis[i]\n ans = max(ans, score)\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s855528615', 's081859249']
[637196.0, 24300.0]
[701.0, 1078.0]
[591, 575]
p02695
u859987056
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 += ci\n return score\n\ndef dfs(A):\n if len(A) == N:\n return score(A)\n res = 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 res = max(res, dfs(A))\n A.pop()\n return res\n\nprint(dfs([]))', '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 score\n\ndef dfs(A):\n if len(A) == N:\n return score(A)\n res = 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 res = max(res, dfs(A))\n A.pop()\n return res\n\nprint(dfs([]))']
['Wrong Answer', 'Accepted']
['s427180105', 's079306677']
[9144.0, 9220.0]
[563.0, 562.0]
[598, 598]
p02695
u860002137
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 itertools\n\nn, m, q = map(int, input().split())\na = np.zeros(q, type=int)\nb = np.zeros(q, type=int)\nc = np.zeros(q, type=int)\nd = np.zeros(q, type=int)\n\nfor i in range(q):\n a[i], b[i], c[i], d[i] = map(int, input().split())\n\nA = np.array(list(itertools.combinations_with_replacement(range(1, m + 1), n)))\n\ncnt = 0\n\nfor i in range(len(A)):\n tmp = 0\n for j in range(q):\n if(A[i][b[j]-1] - A[i][a[j]-1]) == c[j]:\n tmp = tmp + d[j]\n cnt = max(cnt, tmp)\nprint(cnt)', 'import itertools\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())\n\nA = list(itertools.combinations_with_replacement(range(1, m + 1), n))\n\ncnt = 0\n\nfor i in range(len(A)):\n tmp = 0\n for j in range(q):\n if(A[i][b[j]-1] - A[i][a[j]-1]) == c[j]:\n tmp = tmp + d[j]\n cnt = max(cnt, tmp)\nprint(cnt)']
['Runtime Error', 'Accepted']
['s553629103', 's913609887']
[27128.0, 21616.0]
[104.0, 1373.0]
[514, 429]
p02695
u861141787
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 = [0] * 55; b = [0] * 55; c = [0] * 55; d = [0] * 55\n\nfor i in range(q):\n a[i], b[i], c[i], d[i] = map(int, input().split())\n\ndef socer(A):\n now = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]: now += d[i]\n return now\n\ndef dfs(A):\n print(A)\n if len(A) == n: return socer(A)\n res = 0\n last = A[-1] if A else 0\n for i in range(last, m):\n A.append(i)\n res = max(res, dfs(A))\n A.pop()\n return res\n \nprint(dfs([]))', 'n, m, q = map(int, input().split())\n\na = [0] * 55; b = [0] * 55; c = [0] * 55; d = [0] * 55\n\nfor i in range(q):\n a[i], b[i], c[i], d[i] = map(int, input().split())\n\ndef socer(A):\n now = 0\n for i in range(q):\n if A[b[i]-1] - A[a[i]-1] == c[i]: now += d[i]\n return now\n\ndef dfs(A):\n # print(A)\n if len(A) == n: return socer(A)\n res = 0\n last = A[-1] if A else 0\n for i in range(last, m):\n A.append(i)\n res = max(res, dfs(A))\n A.pop()\n return res\n \nprint(dfs([]))']
['Wrong Answer', 'Accepted']
['s989784434', 's106423457']
[9212.0, 9156.0]
[976.0, 806.0]
[521, 523]
p02695
u861886710
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 = []\nb = []\nc = []\nd = []\ndd = 0\nfor i in range(Q):\n t = list(map(int, input().split()))\n a.append(t[0])\n b.append(t[1])\n c.append(t[2])\n d.append(t[3])\n if t[1] - t[0] == t[3]:\n dd += t[4]\n\nprint(dd)\n ', 'N, M, Q = map(int, input().split())\n\narr = [list(map(int, input().split())) for _ in range(Q)]\n\nans = 0\n\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(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 tmp = 0\n \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 += b\n ans = max(ans, tmp)\n \nprint(ans)', 'for 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 tmp = 0\n \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 += b\n ans = max(ans, tmp)\n \nprint(ans)', 'N, M, Q = map(int, input().split())\n\narr = [list(map(int, input().split())) for _ in range(Q)]\n\nans = 0\n\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(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 tmp = 0\n \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 += b\n ans = max(ans, tmp)\n \nprint(ans)', 'N,M,Q = map(int, input().split())\n \narr=[list(map(int,input().split())) for _ in range(Q)]\n \n\n \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(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 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)']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s256405972', 's700567314', 's748837529', 's861973647', 's084905307']
[9120.0, 9248.0, 9152.0, 9168.0, 9256.0]
[23.0, 983.0, 24.0, 23.0, 1012.0]
[274, 1207, 994, 1207, 1007]
p02695
u870736713
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())\nall=[]\n \nfor i in range(Q):\n all.append(list(map(int,input().split())))\n#print(all)\n#print(len(all))\n#print(all[0][1])\n \nx=sorted([i for i in range(1,M+1)])\nmaxdsum=0\n \n \nfor A in itertools.combinations_with_replacement(x, N):\n dsum=0\n "print("A=="+str(A))\n for num in range(Q):\n if A[all[num][1]-1]-A[all[num][0]-1]==all[num][2]:\n dsum+=all[num][3]\n if maxdsum<dsum:\n maxdsum=dsum\nprint(maxdsum)', 'import itertools\n \nN,M,Q=map(int,input().split())\nall=[]\nfor i in range(Q):\n all.append(list(map(int,input().split()))\n \nx=[i for i in range(1,M+1)]\nmaxdsum=0\n \nfor A in itertools.combinations_with_replacement(x, N):\n dsum=0\n for num in range(Q):\n if A[all[num][1]-1]-A[all[num][0]-1]==all[num][2]:\n dsum+=all[num][3]\n if maxdsum<dsum:\n maxdsum=dsum\nprint(maxdsum)', 'import itertools\n \nN,M,Q=map(int,input().split())\nall=[]\nfor i in range(Q):\n all.append(list(map(int,input().split())))\n \nx=[i for i in range(1,M+1)]\nmaxdsum=0\n \nfor A in itertools.combinations_with_replacement(x, N):\n dsum=0\n for num in range(Q):\n if A[all[num][1]-1]-A[all[num][0]-1]==all[num][2]:\n dsum+=all[num][3]\n if maxdsum<dsum:\n maxdsum=dsum\nprint(maxdsum)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s457496086', 's985981290', 's484530169']
[8760.0, 8964.0, 9096.0]
[24.0, 22.0, 1316.0]
[462, 379, 380]
p02695
u870841038
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())\nb = [list(map(int, input().split())) for _ in range(Q)]\nans = 0\n\nimport itertools\na = range(1, M+1)\nfor set_A in itertools.combinations_with_replacement(a, N):\n A = list(set_A)\n print(A)\n n = 0\n for i in range(Q):\n if A[b[i][1]-1] - A[b[i][0]-1] == b[i][2]:\n n += b[i][3]\n ans = max(ans, n)\nprint(ans)', 'N, M, Q = map(int, input().split())\nb = [list(map(int, input().split())) for _ in range(Q)]\nans = 0\n\nimport itertools\na = range(1, M+1)\nfor set_A in itertools.combinations_with_replacement(a, N):\n A = list(set_A)\n n = 0\n for i in range(Q):\n if A[b[i][1]-1] - A[b[i][0]-1] == b[i][2]:\n n += b[i][3]\n ans = max(ans, n)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s101979258', 's960864985']
[9220.0, 9212.0]
[1444.0, 1305.0]
[370, 357]
p02695
u878129968
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())\nA_list = []\nfor p in itertools.combinations_with_replacement(range(1,m+1),n):\n A_list.append(p)\n# print(A_list)\n\nans = 0\nfor v in A_list:\n cur_score = 0\n for i in range(q):\n if v[b[i]-1] - v[a[i]-1] == c[i]:\n cur_score += d[i]\n ans = max(ans,cur_score)\nprint(ans)', '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())\nA_list = []\nfor p in itertools.combinations_with_replacement(range(1,m+1),n):\n A_list.append(p)\n# print(A_list)\n\nans = 0\nfor v in A_list:\n cur_score = 0\n for i in range(q):\n if v[b[i]-1] - v[a[i]-1] == c[i]:\n cur_score += d[i]\n ans = max(ans,cur_score)\nprint(ans)']
['Runtime Error', 'Accepted']
['s262833639', 's974604256']
[9232.0, 21736.0]
[23.0, 1135.0]
[450, 467]
p02695
u881195671
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 itertools\n\n\nN, M, Q = map(int, input().split(" "))\n\nvals = []\nfor i in range(Q):\n vals.append([list(map(int, input().split(" ")))])\n \nmaxv = 0\ncand = list(itertools.combinations_with_replacement(range(1, M+1), N))\nfor c in cand:\n sumv = 0\n for v in vals:\n if (c[v[1]-1] - c[v[0]-1]) == v[2]:\n sumv += v[3]\n if maxv < sumv:\n maxv = sumv\nprint(maxv)', 'import numpy as np\nimport itertools\n\n\nN, M, Q = map(int, input().split(" "))\n\nvals = []\nfor i in range(Q):\n vals.append(list(map(int, input().split(" "))))\n \nmaxv = 0\ncand = list(itertools.combinations_with_replacement(range(1, M+1), N))\nfor c in cand:\n sumv = 0\n for v in vals:\n if (c[v[1]-1] - c[v[0]-1]) == v[2]:\n sumv += v[3]\n if maxv < sumv:\n maxv = sumv\nprint(maxv)']
['Runtime Error', 'Accepted']
['s532514224', 's703140718']
[39580.0, 39508.0]
[122.0, 1187.0]
[413, 411]
p02695
u892308039
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\nN, M, Q = map(int,input().split())\nP = [list(map(int,input().split())) for i in range(Q)]\n\nA = list(itertools.combinations(range(1,M+1), 3))\nnumber = len(A)\n\namount = 0\nmax_amount = 0\nfor i in range(number): # 0,1,2,3 A\n for j in range(Q): # 0,1,2\n bi = P[j][1]\n ai = P[j][0]\n \n if(A[i][bi-1] - A[i][ai-1] == P[j][2]):\n amount += P[j][3]\n \n # print(amount)\n if(amount >= max_amount):\n max_amount = amount\n \n amount = 0\n \nprint(max_amount)', 'from itertools import combinations\nN, M, Q = map(int,input().split())\nP = [list(map(int,input().split())) for i in range(Q)]\n\nA = list(itertools.combinations(range(1,M+1), N))\nnumber = len(A)\n\namount = 0\nmax_amount = 0\nfor i in range(number): # 0,1,2,3 A\n \n for j in range(Q): # 0,1,2\n bi = P[j][1]\n ai = P[j][0]\n \n \n if(A[i][bi-1] - A[i][ai-1] == P[j][2]):\n amount += P[j][3]\n \n # print(amount)\n if(amount >= max_amount):\n max_amount = amount\n \n amount = 0\n \nprint(max_amount)', 'from itertools import combinations\nN, M, Q = map(int,input().split())\nP = [list(map(int,input().split())) for i in range(Q)]\n\nA = list(itertools.combinations_with_replacement(range(1,M+1), N))\nnumber = len(A)\n\namount = 0\nmax_amount = 0\nfor i in range(number): #A\n \n for j in range(Q): # P\n bi = P[j][1]\n ai = P[j][0]\n if(A[i][bi-1] - A[i][ai-1] == P[j][2]):\n amount += P[j][3]\n \n # print(amount)\n \n # print(amount)\n if(amount >= max_amount):\n max_amount = amount\n \n amount = 0\n \nprint(max_amount)', 'import itertools\nN, M, Q = map(int,input().split())\nP = [list(map(int,input().split())) for i in range(Q)]\n\nA = list(itertools.combinations_with_replacement(range(1,M+1), N))\nnumber = len(A)\n\namount = 0\nmax_amount = 0\nfor i in range(number): #A\n \n for j in range(Q): # P\n bi = P[j][1]\n ai = P[j][0]\n if(A[i][bi-1] - A[i][ai-1] == P[j][2]):\n amount += P[j][3]\n \n # print(amount)\n \n # print(amount)\n if(amount >= max_amount):\n max_amount = amount\n \n amount = 0\n \nprint(max_amount)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s089441867', 's527558039', 's625259150', 's412325177']
[9168.0, 9164.0, 9212.0, 21624.0]
[20.0, 21.0, 20.0, 1827.0]
[539, 553, 567, 549]
p02695
u894265012
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.
["mport itertools\ndef main():\n N, M, Q = map(int, input().split())\n abcd = []\n for _ in range(Q):\n a, b, c, d = map(int, input().split())\n abcd.append((a-1, b-1, c, d))\n score = 0\n for ones in list(itertools.combinations([i for i in range(N+M-1)], M-1)):\n temp = [0] * (N + M -1)\n for idx in ones:\n temp[idx] = 1\n A = [0] * N\n idx = 0\n sum_ = 0\n for i in temp:\n if i == 0:\n A[idx] = sum_ + 1\n idx += 1\n else:\n sum_ += 1\n score_temp = get_score(A, abcd)\n if score_temp > score:\n score = score_temp\n print(score)\n \n\ndef get_score(A, abcd):\n score = 0\n for a, b, c, d in abcd:\n if A[b] - A[a] == c:\n score += d\n return score\n\nif __name__ == '__main__':\n main()", "import itertools\ndef main():\n N, M, Q = map(int, input().split())\n abcd = []\n for _ in range(Q):\n a, b, c, d = map(int, input().split())\n abcd.append((a-1, b-1, c, d))\n score = 0\n for ones in list(itertools.combinations([i for i in range(N+M-1)], M-1)):\n temp = [0] * (N + M -1)\n for idx in ones:\n temp[idx] = 1\n A = [0] * N\n idx = 0\n sum_ = 0\n for i in temp:\n if i == 0:\n A[idx] = sum_ + 1\n idx += 1\n else:\n sum_ += 1\n score_temp = get_score(A, abcd)\n if score_temp > score:\n score = score_temp\n print(score)\n \ndef get_score(A, abcd):\n score = 0\n for a, b, c, d in abcd:\n if A[b] - A[a] == c:\n score += d\n return score\n\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Accepted']
['s256494698', 's795215393']
[8876.0, 19880.0]
[22.0, 589.0]
[873, 873]
p02695
u909991537
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()) \nABCD = []\nans = -1\n\nfor _ in range(Q):\n ABCD.append([int(i) for i in input().split()] )\n\ncomb_list = []\n\nimport sys\nsys.setrecursionlimit(100000000)\ndef recur(N, lis, c):\n if len(lis) == N:\n comb_list.append(lis)\n return\n\n if lis == []:\n for i in range(1, N+1):\n recur(N, [i], c+1)\n else:\n for i in range(lis[c], N+1):\n recur(N, lis + [i], c+1) \n\nrecur(N, [], -1)\nfor x in comb_list:\n tmp = 0\n for a, b, c, d in ABCD:\n if x[b-1] - x[a-1] == c:\n tmp += d\n \n ans = max(ans, tmp) \nprint(ans)', 'N, M, Q = (int(i) for i in input().split()) \nABCD = []\nans = -1\n\nfor _ in range(Q):\n ABCD.append([int(i) for i in input().split()] )\n\ncomb_list = []\n\nimport sys\nsys.setrecursionlimit(100000000)\ndef recur(N, lis, c):\n if len(lis) == N:\n comb_list.append(lis)\n return\n\n if lis == []:\n for i in range(1, M+1):\n recur(N, [i], c+1)\n else:\n for i in range(lis[c], M+1):\n recur(N, lis + [i], c+1) \n\nrecur(N, [], -1)\nfor x in comb_list:\n tmp = 0\n for a, b, c, d in ABCD:\n if x[b-1] - x[a-1] == c:\n tmp += d \n ans = max(ans, tmp) \nprint(ans)']
['Wrong Answer', 'Accepted']
['s794087754', 's956379884']
[23044.0, 22912.0]
[1110.0, 1098.0]
[609, 603]
p02695
u910426639
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\nquery = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n query.append([a, b, c, d])\n\n\ndef calcPoint(num):\n ret = 0\n for q in range(Q):\n if num[query[q][1] - 1] - num[query[q][0] - 1] == query[q][2]:\n ret += query[q][3]\n\n return ret\n\n\nans = 0\n\n\ndef dfs(suu, keta):\n global ans\n if keta == N:\n ans = max(ans, calcPoint(suu))\n print(*suu)\n return\n\n co = suu.copy()\n\n for i in range(suu[keta - 1], M):\n co[keta] = i\n dfs(co, keta + 1)\n\n\nretsu = [0] * N\n\ndfs(retsu, 1)\nprint(ans)', 'N, M, Q = map(int, input().split())\n\nquery = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n query.append([a, b, c, d])\n\n\ndef calcPoint(num):\n ret = 0\n for q in range(Q):\n if num[query[q][1] - 1] - num[query[q][0] - 1] == query[q][2]:\n ret += query[q][3]\n\n return ret\n\n\nans = 0\n\n\ndef dfs(suu, keta):\n global ans\n if keta == N:\n ans = max(ans, calcPoint(suu))\n \n return\n\n co = suu.copy()\n\n for i in range(suu[keta - 1], M):\n co[keta] = i\n dfs(co, keta + 1)\n\n\nretsu = [0] * N\n\ndfs(retsu, 1)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s825326455', 's727544264']
[9280.0, 9224.0]
[640.0, 532.0]
[605, 607]
p02695
u915879510
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 python3\nimport sys\nimport numpy as np\nfrom itertools import *\n\n\ndef solve(N: int, M: int, Q: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):\n l = [i for i in range(1,M+1)]\n A = []\n if N==M:\n A.append(l)\n else:\n for v in combinations_with_replacement(l, N):\n if sorted(v) not in A:\n A.append(sorted(v))\n\n ans = [0] * len(A)\n\n for i in range(len(A)):\n print(A[i])\n for j in range(Q):\n #print(a[j],b[j],c[j],d[j],A[i][b[j]-1]-A[i][a[j]-1], c[j], d[j])\n #print(A[i][b[j]-1]-A[i][a[j]-1], c[j])\n if (A[i][b[j]-1]-A[i][a[j]-1])==c[j]:\n ans[i] += d[j]\n #print(ans[i])\n #print(ans)\n print(max(ans))\n\n return\n\n\n# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n M = int(next(tokens)) # type: int\n Q = int(next(tokens)) # type: int\n a = [int()] * (Q) # type: "List[int]"\n b = [int()] * (Q) # type: "List[int]"\n c = [int()] * (Q) # type: "List[int]"\n d = [int()] * (Q) # type: "List[int]"\n for i in range(Q):\n a[i] = int(next(tokens))\n b[i] = int(next(tokens))\n c[i] = int(next(tokens))\n d[i] = int(next(tokens))\n solve(N, M, Q, a, b, c, d)\n\nif __name__ == \'__main__\':\n main()\n', '#!/usr/bin/env python3\nimport sys\nimport numpy as np\nfrom itertools import *\n\n\ndef solve(N: int, M: int, Q: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):\n l = [i for i in range(1,M+1)]\n ans = 0\n for v in combinations_with_replacement(l, N):\n score = 0\n for j in range(Q):\n #print(a[j],b[j],c[j],d[j],A[i][b[j]-1]-A[i][a[j]-1], c[j], d[j])\n #print(A[i][b[j]-1]-A[i][a[j]-1], c[j])\n if (v[b[j]-1]-v[a[j]-1])==c[j]:\n score += d[j]\n #print(ans[i])\n ans = max(ans, score)\n #print(ans)\n print(ans)\n\n return\n\n\n# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n M = int(next(tokens)) # type: int\n Q = int(next(tokens)) # type: int\n a = [int()] * (Q) # type: "List[int]"\n b = [int()] * (Q) # type: "List[int]"\n c = [int()] * (Q) # type: "List[int]"\n d = [int()] * (Q) # type: "List[int]"\n for i in range(Q):\n a[i] = int(next(tokens))\n b[i] = int(next(tokens))\n c[i] = int(next(tokens))\n d[i] = int(next(tokens))\n solve(N, M, Q, a, b, c, d)\n\nif __name__ == \'__main__\':\n main()\n']
['Wrong Answer', 'Accepted']
['s945214411', 's097020290']
[28312.0, 27180.0]
[910.0, 811.0]
[1619, 1465]
p02695
u917558625
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\ns=list(map(int,input().split()))\nt=[list(map(int,input().split())) for i in range(s[2])]\nli=[x for x in range(1,s[0]+1)]\nlity=list(itertools.combinations_with_replacement(li,s[0]))\nans=0\nfor k in lity:\n vmax=0\n for l in t:\n if k[l[1]-1]-k[l[0]-1]==l[2]:\n vmax+=l[3]\n ans=max(ans,vmax)\nprint(ans)', 'import itertools\ns=list(map(int,input().split()))\nt=[list(map(int,input().split())) for i in range(s[2])]\nli=[x for x in range(1,s[1]+1)]\nlity=list(itertools.combinations_with_replacement(li,s[0]))\nans=0\nfor k in lity:\n vmax=0\n for l in t:\n if k[l[1]-1]-k[l[0]-1]==l[2]:\n vmax+=l[3]\n ans=max(ans,vmax)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s075025592', 's444835046']
[21452.0, 21584.0]
[904.0, 1011.0]
[323, 323]
p02695
u923172145
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 next_array(array):\n\ts = -1\n\tfor x in array[::-1]:\n \tif x < M:\n \tbreak\n else:\n \ts -= 1\n \n \n if s >= -N:\n \tarray[s] += 1\n \tif s < -1:\n \t\tfor i in range(s+1,0):\n \t\t\tarray[i] = array[s]\n \n\treturn array\n \ndef score(array, rules):\n\tscr = 0\n\tfor rule in rules:\n \tif (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n \tscr += rule[3]\n return scr\n \n \n# input\nN, M, Q = map(int, input().split())\nrules = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n \narray\u3000= [1] * N\nmax_scr = 0\n \nwhile True:\n\tmax_scr = max(max_scr, score(array,rules)) \n\tif array[0] == M:\n\t\tbreak \n\tarray = next_array(array)\n \nprint(max_scr)', 'def next_array(array):\n s = -1\n for x in array[::-1]:\n if x < M:\n break\n else:\n s -= 1\n \n \n if s >= -N:\n array[s] += 1\n if s < -1:\n for i in range(s+1,0):\n array[i] = array[s]\n \n print(array)\n return array\n \ndef score(array, rules):\n scr = 0\n for rule in rules:\n if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n scr += rule[3]\n \n return scr\n \n# input\nN, M, Q = map(int, input().split())\nrules = []\n\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n\narray = [1] * N\nmax_scr = 0\n \nwhile True:\n max_scr = max(max_scr, score(array,rules)) \n if array[0] == M:\n break \n array = next_array(array)\n \nprint(max_scr)', 'def next_array(array):\n\ts = -1\n\tfor x in array[::-1]:\n \tif x < M:\n \tbreak\n else:\n \ts -= 1\n \n \n if s >= -N:\n \tarray[s] += 1\n \tif s < -1:\n \t\tfor i in range(s+1,0):\n \t\t\tarray[i] = array[s]\n \n\treturn array\n \ndef score(array, rules):\n\tscr = 0\n\tfor rule in rules:\n \tif (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n \tscr += rule[3]\n return scr\n \n \n# input\nN, M, Q = map(int, input().split())\nrules = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n \narray\u3000= [1] * N\nmax_scr = 0\n \nwhile True:\n\tmax_scr = max(max_scr, score(array,rules)) \n\tif array[0] == M:\n\t\tbreak \n\tarray = next_array(array)\n \nprint(max_scr)', 'def next_array(array):\n s = -1\n for x in array[::-1]:\n if x < M:\n break\n else:\n s -= 1\n \n \n if s >= -N:\n array[s] += 1\n if s < -1:\n array[s+1:] = array[s]\n \n #array[i] = array[s]\n \n return array\n \ndef score(array, rules):\n scr = 0\n for rule in rules:\n if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n scr += rule[3]\n \n return scr\n \n# input\nN, M, Q = map(int, input().split())\nrules = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n\narray = [1] * N\nmax_scr = 0\n \nwhile True:\n max_scr = max(max_scr, score(array,rules)) \n if array[0] == M:\n break \n array = next_array(array)\n \nprint(max_scr)', 'def next_array(array):\n s = -1\n for x in array[::-1]:\n if x < M:\n break\n else:\n s -= 1\n \n \n if s >= -N:\n array[s] += 1\n if s < -1:\n for i in range(s+1,0):\n array[i] = array[s]\n \n return array\n \ndef score(array, rules):\n scr = 0\n for rule in rules:\n if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n scr += rule[3]\n \n return scr\n \n# input\nN, M, Q = map(int, input().split())\nrules = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n\narray = [1] * N\nmax_scr = 0\n \nwhile True:\n max_scr = max(max_scr, score(array,rules)) \n if array[0] == M:\n break \n array = next_array(array)\n \nprint(max_scr)', 'def next_array(array):\n s = -1\n for x in array[::-1]:\n if x < M:\n break\n else:\n s -= 1\n \n \n if s >= -N:\n array[s] += 1\n if s < -1:\n for i in range(s+1,0):\n array[i] = array[s]\n \n print(array)\n return array\n \ndef score(array, rules):\n scr = 0\n for rule in rules:\n if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n scr += rule[3]\n \n return scr\n \n# input\nN, M, Q = map(int, input().split())\nrules = []\n \nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n \narray = [1] * N\nmax_scr = 0\n \nwhile True:\n max_scr = max(max_scr, score(array,rules)) \n if array[0] == M:\n break \n array = next_array(array)\n \nprint(max_scr)', 'def next_array(array)\n\ts = -1\n\tfor x in array[::-1]:\n \tif x < M:\n \tbreak\n else:\n \ts -= 1\n \n \n if s >= -N:\n array[s] += 1\n for i in range(s,0)\n \tarray[i] = array[s]\n \n\treturn array\n\ndef score(array, rules)\n\tscr = 0\n\tfor rule in rules:\n \tif (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n \tscr += rule[3]\n return scr\n\n\n# input\nN, M, Q = map(int, input().split())\nrules = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n \narray\u3000= [1] * N\nmax_scr = 0\n\nwhile True:\n max_scr = max(max_scr, score(array,rules)) \n if array[0] == M:\n break \n array = next_array(array)\n \n \n\n \n\n \n \t', 'def next_array(array):\n s = -1\n for x in array[::-1]:\n if x < M:\n break\n else:\n s -= 1\n \n \n if s >= -N:\n array[s] += 1\n if s < -1:\n for i in range(s+1,0):\n array[i] = array[s]\n \n return array\n \ndef score(array, rules):\n scr = 0\n for rule in rules:\n if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n scr += rule[3]\n \n return scr\n\n# input\nN, M, Q = map(int, input().split())\nrules = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n \narray\u3000= [1] * N\nmax_scr = 0\n \nwhile True:\n max_scr = max(max_scr, score(array,rules)) \n if array[0] == M:\n break \n array = next_array(array)\n \nprint(max_scr)', 'def next_array(array):\n\ts = -1\n\tfor x in array[::-1]:\n \tif x < M:\n \tbreak\n else:\n \ts -= 1\n \n \n if s >= -N:\n array[s] += 1\n if s < -1:\n \tfor i in range(s+1,0)\n \t\tarray[i] = array[s]\n \n\treturn array\n \ndef score(array, rules):\n\tscr = 0\n\tfor rule in rules:\n \tif (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n \tscr += rule[3]\n return scr\n \n \n# input\nN, M, Q = map(int, input().split())\nrules = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n \narray\u3000= [1] * N\nmax_scr = 0\n \nwhile True:\n max_scr = max(max_scr, score(array,rules)) \n if array[0] == M:\n break \n array = next_array(array)', 'def next_array(array):\n\ts = -1\n\tfor x in array[::-1]:\n\t\tif x < M:\n\t\t\tbreak\n\t\telse:\n\t\t\ts -= 1\n \n \n if s >= -N:\n \tarray[s] += 1\n \tif s < -1:\n \t\tfor i in range(s+1,0):\n \t\t\tarray[i] = array[s]\n \n\treturn array\n \ndef score(array, rules):\n\tscr = 0\n for rule in rules:\n\t\tif (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n \t\tscr += rule[3]\n return scr\n \n \n# input\nN, M, Q = map(int, input().split())\nrules = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n \narray\u3000= [1] * N\nmax_scr = 0\n \nwhile True:\n\tmax_scr = max(max_scr, score(array,rules)) \n\tif array[0] == M:\n\t\tbreak \n\tarray = next_array(array)\n \nprint(max_scr)', 'def next_array(array):\n\ts = -1\n\tfor x in array[::-1]:\n\t\tif x < M:\n\t\t\tbreak\n\t\telse:\n\t\t\ts -= 1\n \n \n if s >= -N:\n \tarray[s] += 1\n \tif s < -1:\n \t\tfor i in range(s+1,0):\n \t\t\tarray[i] = array[s]\n \n\treturn array\n \ndef score(array, rules):\n\tscr = 0\n\tfor rule in rules:\n \tif (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n \tscr += rule[3]\n return scr\n \n \n# input\nN, M, Q = map(int, input().split())\nrules = []\nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n \narray\u3000= [1] * N\nmax_scr = 0\n \nwhile True:\n\tmax_scr = max(max_scr, score(array,rules)) \n\tif array[0] == M:\n\t\tbreak \n\tarray = next_array(array)\n \nprint(max_scr)', 'def next_array(array):\n s = -1\n for x in array[::-1]:\n if x < M:\n break\n else:\n s -= 1\n \n \n if s >= -N:\n array[s] += 1\n if s < -1:\n for i in range(s+1,0):\n array[i] = array[s]\n\n return array\n \ndef score(array, rules):\n scr = 0\n for rule in rules:\n if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):\n scr += rule[3]\n \n return scr\n \n# input\nN, M, Q = map(int, input().split())\nrules = []\n \nfor i in range(Q):\n a, b, c, d = map(int, input().split())\n rules.append([a, b, c, d])\n \narray = [1] * N\nmax_scr = 0\n \nwhile True:\n max_scr = max(max_scr, score(array,rules)) \n if array[0] == M:\n break \n array = next_array(array)\n \nprint(max_scr)']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s092365237', 's110686579', 's278756371', 's291678325', 's483796587', 's590610175', 's593674463', 's604184988', 's629304803', 's815000082', 's932598516', 's408648845']
[9000.0, 9240.0, 9012.0, 9248.0, 9152.0, 9116.0, 8940.0, 9044.0, 8904.0, 8948.0, 8948.0, 9252.0]
[22.0, 839.0, 24.0, 2205.0, 2206.0, 878.0, 23.0, 23.0, 26.0, 24.0, 24.0, 737.0]
[916, 905, 916, 928, 897, 908, 901, 902, 900, 892, 895, 891]
p02695
u932868243
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\nn,m,q=map(int,input().split())\nabcd=[list(map(int,inpt().split())) for _ in range(q)]\nsumlist=[]\nfor A in math.combinations_with_replacement(range(1,m+1),n)\n sum=0\n for a,b,c,d in abcd:\n if A[b-1]-A[a-1]==c:\n sum+=d\n sumlist.append(sum)\nprint(max(sumlist))\n ', 'import itertools\nn,m,q=map(int,input().split())\nabcd=[list(map(int,input().split())) for _ in range(q)]\nsumlist=[]\nfor A in itertools.combinations_with_replacement(range(1,m+1),n):\n sum=0\n for a,b,c,d in abcd:\n if A[b-1]-A[a-1]==c:\n sum+=d\n sumlist.append(sum)\nprint(max(sumlist))\n ']
['Runtime Error', 'Accepted']
['s780319762', 's389273248']
[9028.0, 73908.0]
[24.0, 1462.0]
[288, 300]
p02695
u935642171
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)]\na,b,c,d = [],[],[],[]\nfor i in range(q):\n a.append(abcd[i][0])\n b.append(abcd[i][1])\n c.append(abcd[i][2])\n d.append(abcd[i][3])\n\ndef score(A):\n tmp = 0\n for ai, bi, ci, di in zip(a, b, c, d):\n if A[bi] - A[ai] == ci:\n tmp += di\n return tmp\n\ndef dfs(A):\n print(A)\n if len(A)==n+1:\n return score(A)\n ans = 0\n for i in range(A[-1],m):\n A.append(i)\n ans = max(ans,dfs(A))\n A.pop()\n return ans\n\nprint(dfs([0]))', 'n, m, q = map(int, input().split())\nabcd = [list(map(int, input().split())) for _ in range(q)]\na,b,c,d = [],[],[],[]\nfor i in range(q):\n a.append(abcd[i][0])\n b.append(abcd[i][1])\n c.append(abcd[i][2])\n d.append(abcd[i][3])\n\ndef score(A):\n tmp = 0\n for ai, bi, ci, di in zip(a, b, c, d):\n if A[bi] - A[ai] == ci:\n tmp += di\n return tmp\n\ndef dfs(A):\n if len(A)==n+1:\n return score(A)\n ans = 0\n for i in range(A[-1],m):\n A.append(i)\n ans = max(ans,dfs(A))\n A.pop()\n return ans\n\nprint(dfs([0]))']
['Wrong Answer', 'Accepted']
['s520297702', 's349647966']
[9196.0, 9236.0]
[765.0, 560.0]
[539, 528]
p02695
u941644149
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())\nmax_n = 0\n\n\nA_list = []\nN=2\nfor i in range(10**(N-1),10**N):\n #A = [int(x) for x in list(str(i))]\n #A_replace = [int(str(a).replace('0', '10')) for a in A]\n \n A_list.append(sorted(str(i)))\nabcd_list = []\nfor q in range(Q):\n abcd_list.append(list(map(int, input().split())))\n\nfor A in A_list:\n tokuten = 0\n for q in range(Q):\n if (A[abcd_list[q][1]-1] - A[abcd_list[q][0]-1] == abcd_list[q][2]):\n tokuten += abcd_list[q][3]\n\n if tokuten > max_n:\n max_n = tokuten\n\nprint(max_n)", 'N, M, Q = map(int, input().split())\nvec = [list(map(int, input().split())) for i in range(Q)]\nA = itertools.combinations_with_replacement(range(1,M+1), N)\nans = 0\n\nfor a in A:\n tmp = 0\n for v in vec:\n if (a[v[1]-1] - a[v[0]-1]) == v[2]:\n tmp += v[3]\n if ans < tmp:\n ans = tmp\n \nprint(ans)', "N, M, Q = map(int, input().split())\nmax_n = 0\n\n\nA_list = []\nN=2\nfor i in range(10**(N-1),10**N):\n #A = [int(x) for x in list(str(i))]\n #A_replace = [int(str(a).replace('0', '10')) for a in A]\n \n A_list.append(sorted(i))\nabcd_list = []\nfor q in range(Q):\n abcd_list.append(list(map(int, input().split())))\n\nfor A in A_list:\n tokuten = 0\n for q in range(Q):\n if (A[abcd_list[q][1]-1] - A[abcd_list[q][0]-1] == abcd_list[q][2]):\n tokuten += abcd_list[q][3]\n\n if tokuten > max_n:\n max_n = tokuten\n\nprint(max_n)", 'import itertools\nN, M, Q = map(int, input().split())\nvec = [list(map(int, input().split())) for i in range(Q)]\nA = itertools.combinations_with_replacement(range(1,M+1), N)\nans = 0\n\nfor a in A:\n tmp = 0\n for v in vec:\n if (a[v[1]-1] - a[v[0]-1]) == v[2]:\n tmp += v[3]\n if ans < tmp:\n ans = tmp\n \nprint(ans)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s195333487', 's605934639', 's900115193', 's481155056']
[9224.0, 9160.0, 9232.0, 9196.0]
[24.0, 21.0, 21.0, 929.0]
[595, 329, 590, 346]
p02695
u961288441
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 = [int(input()) for _ in range(Q)]\nb = [int(input()) for _ in range(Q)]\nc = [int(input()) for _ in range(Q)]\nd = [int(input()) for _ in range(Q)]\nfor i in range (Q):\n a[i], b[i], c[i], d[i] = map(int, input().split())\nans = 0\nfor A in combinations_with_replacement(range(1, M+1), N):\n tmp = 0\n for i in range(Q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n tmp += d[i]\n ans = max(ans, tmp)\nprint(ans)', '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 combinations_with_replacement(range(1, M+1), N):\n tmp = 0\n for i in range(Q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n tmp += d[i]\n ans = max(ans, tmp)\nprint(ans)', '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 tmp = 0\n for i in range(Q):\n if A[b[i]-1] - A[a[i]-1] == c[i]:\n tmp += d[i]\n ans = max(ans, tmp)\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s772458836', 's839434240', 's055052395']
[9204.0, 9224.0, 9220.0]
[24.0, 24.0, 1104.0]
[478, 370, 379]
p02695
u966810027
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 = gets.split.map(&:to_i)\na = []\nb = []\nc = []\nd = []\nQ.times do |i|\n a[i], b[i], c[i], d[i] = gets.split.map(&:to_i)\n a[i] -= 1\n b[i] -= 1\nend\n\ndef score(array,a,b,c,d)\n tmp = 0\n for ai,bi,ci,di in a.zip(b,c,d)\n tmp += di if array[bi] - array[ai] == ci\n end\n tmp\nend\n\ndef dfs(array,a,b,c,d)\n if array.length == N\n return score(array,a,b,c,d)\n end\n result = 0\n array.length > 0 ? (prev_last = array[-1]) : (prev_last = 0)\n for v in prev_last..M\n array.push(v)\n result = [result, dfs(array,a,b,c,d)].max\n array.pop\n end\n result\nend\n\nputs dfs(Array.new,a,b,c,d)\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 a[i] -= 1\n b[i] -= 1\n\n\ndef score(A):\n tmp = 0\n for ai, bi, ci, di in zip(a, b, c, d):\n if A[bi] - A[ai] == ci:\n tmp += di\n return tmp\n\n# DFS\ndef dfs(A):\n if len(A) == N:\n return score(A) \n res = 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 res = max(res, dfs(A)) \n A.pop()\n return res\n\n\nprint(dfs([]))']
['Runtime Error', 'Accepted']
['s560412731', 's284857191']
[8944.0, 9200.0]
[22.0, 561.0]
[594, 694]
p02695
u968404618
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 = [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 = [1]\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\n a.append(a[-1])\n while a[-1] <= m:\n dfs(a)\n a[-1] += 1\n\ndfs(a)\nprint(ans)', 'n, m, q = 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 = [1]\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\n a.append(a[-1])\n while a[-1] <= m:\n dfs(a)\n a[-1] += 1\n a.pop(-1)\n\ndfs(a)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s135720584', 's120961734']
[9192.0, 9200.0]
[22.0, 679.0]
[466, 480]
p02695
u973549339
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)]\nimport itertools\n\nA = []\nM = []\nfor i in range(1, m+1):\n M.append(i)\nfor team in itertools.combinations(M, n):\n A.append(team)\n \nB = [0]*len(A)\nfor i in range(q):\n a = abcd[i][0]\n b = abcd[i][1]\n c = abcd[i][2]\n d = abcd[i][3]\n for j in range(len(A)):\n if A[j][b-1] - A[j][a-1] == c:\n B[j] += d\n\nprint(B)', 'n, m, q = map(int, input().split())\nabcd = [list(map(int, input().split())) for i in range(q)]\nimport itertools\n\nA = []\nM = []\nfor i in range(1, m+1):\n M.append(i)\nfor team in itertools.combinations_with_replacement(M, n):\n A.append(team)\n \nB = [0]*len(A)\nfor i in range(q):\n a = abcd[i][0]\n b = abcd[i][1]\n c = abcd[i][2]\n d = abcd[i][3]\n for j in range(len(A)):\n if A[j][b-1] - A[j][a-1] == c:\n B[j] += d\n\nprint(max(B))\n\n']
['Wrong Answer', 'Accepted']
['s429486372', 's332788420']
[9216.0, 25076.0]
[21.0, 1027.0]
[441, 465]
p02695
u973972117
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.
['mport itertools\n \nN, M, Q = map(int, input().split())\nc = [list(map(int, input().split())) for _ in range(Q)]\n \ndef score(seq):\n s = 0\n for q in range(Q):\n if seq[c[q][1]-1] - seq[c[q][0]-1] == c[q][2]:\n s += c[q][3]\n return s\n \np = [i for i in range(1, M+1)]\nA = itertools.combinations_with_replacement(p, N)\nans = 0\nfor a in A:\n ans = max(ans, score(a))\nprint(ans)', 'mport itertools\n \nN, M, Q = map(int, input().split())\ncmb = [list(map(int, input().split())) for _ in range(Q)]\n \ndef score(seq):\n s = 0\n for q in range(Q):\n if seq[cmb[q][1]-1] - seq[cmb[q][0]-1] == cmb[q][2]:\n s += cmb[q][3]\n return s\n \np = [i for i in range(1, M+1)]\nA = itertools.combinations_with_replacement(p, N)\nans = 0\nfor a in A:\n ans = max(ans, score(a))\nprint(ans)', 'import itertools\n \nN, M, Q = map(int, input().split())\ncmb = [list(map(int, input().split())) for _ in range(Q)]\n \ndef score(seq):\n s = 0\n for q in range(Q):\n if seq[cmb[q][1]-1] - seq[cmb[q][0]-1] == cmb[q][2]:\n s += cmb[q][3]\n return s\n \np = [i for i in range(1, M+1)]\nA = itertools.combinations_with_replacement(p, N)\nans = 0\nfor a in A:\n ans = max(ans, score(a))\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s292266457', 's974248316', 's123194695']
[8948.0, 9008.0, 9072.0]
[25.0, 19.0, 956.0]
[378, 388, 389]
p02695
u980205854
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\nN,M,Q = map(int,input().split())\nq = []\nfor i in range(Q):\n q.append(list(map(int,input().split())))\nq.sort()\ndp = [[0]*(M+1) for _ in range(N+1)]\nfor a,b,c,d in q:\n for i in range(1,M-c+1):\n dp[b][i+c] = max(dp[b][i+c],dp[a][i]+d)\nprint(max(max(dp)))', '# C - Many Requirements\nimport sys\nsys.setrecursionlimit(10000)\n\nN,M,Q = map(int,input().split())\nq = []\nfor _ in range(Q):\n q.append(list(map(int,input().split())))\nA_list = []\n\ndef make(a):\n global A_list,N,M\n if len(a)==N:\n A_list.append(a)\n else:\n for i in range(a[len(a)-1],M+1):\n make(a+[i])\nmake([1])\n\nans = 0\nfor A in A_list:\n tmp = 0\n for a,b,c,d in q:\n if A[b-1]-A[a-1]==c:\n tmp += d\n ans = max(ans,tmp)\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s737580476', 's258920746']
[9116.0, 16228.0]
[24.0, 610.0]
[288, 489]
p02695
u991619971
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 = map(int,input().split())\n#N=int(input())\n#A = list(map(int,input().split()))\n#S=str(input())\nm=0\nif B<N:\n N=B\ns=int(B/A)\nif s>N:\n print(0)\n exit()\nfor x in range(s,N+1,s):\n num=int(A*x/B) - A * int(x/B)\n\n m=max(num,m)\n\nprint(m)\n', 'import itertools\n#K = int(input())\nN,M,Q = map(int,input().split())\n#N = str(input())\n#A = list(map(int,input().split()))\nnums=[i for i in range(1,M+1)]\ncount=0\ninp=[]\nfor i in range(Q):\n I=list(map(int,input().split()))\n inp.append(I)\n\nfor v in itertools.combinations_with_replacement(nums, N):\n c=0\n v=list(v)\n for i in inp:\n\n if v[i[1]-1] - v[i[0]-1]==i[2]:\n c+=i[3]\n count=max(count,c)\nprint(count)\n']
['Runtime Error', 'Accepted']
['s778392038', 's832757034']
[9192.0, 9208.0]
[23.0, 970.0]
[251, 439]
p02695
u992471673
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\nn,m,q=map(int,input().split())\n\n\na=[]\nb=[]\nc=[]\nd=[]\nfor i in range(0,q):\n ay,by1,cy,dy=map(int,input().split())\n a.append(ay)\n b.append(by1)\n c.append(cy)\n d.append(dy)\ns=0\nsmax=-100\n\nsys.setrecursionlimit(3000)\n\n\n\ndef dfs(h):\n global smax\n if len(h)==n+1:\n s=0\n for j in range(0,q):\n if h[b[j]]-h[a[j]]==c[j]:\n s+=d[j]\n if s>smax:\n smax=s\n\n return\n \n for i in range(0,m-h[len(h)-1]):\n \n h2=h[:]\n h2.append(h[len(h)-1]+i)\n dfs(h2)\n\nsta=[1]\ndfs(sta)\nprint(smax)', 'import sys\nn,m,q=map(int,input().split())\n\n\na=[]\nb=[]\nc=[]\nd=[]\nfor i in range(0,q):\n ay,by,cy,dy=map(int,input().split())\n a.append(ay)\n b.append(by)\n c.append(cy)\n d.append(dy)\ns=0\nsmax=0\n\nsys.setrecursionlimit(3000)\nprint(sys.getrecursionlimit())\n\n\ndef dfs(h):\n global smax\n if len(h)==n+1:\n s=0\n for j in range(0,q):\n if h[b[j]]-h[a[j]]==c[j]:\n s+=d[j]\n if s>smax:\n smax=s\n\n return\n \n for i in range(0,n+2-h[len(h)-1]):\n \n h2=h[:]\n h2.append(h[len(h)-1]+i)\n dfs(h2)\n\nsta=[0]\ndfs(sta)\nprint(smax)', 'import sys\nn,m,q=map(int,input().split())\n\n\na=[]\nb=[]\nc=[]\nd=[]\nfor i in range(0,q):\n ay,by1,cy,dy=map(int,input().split())\n a.append(ay)\n b.append(by1)\n c.append(cy)\n d.append(dy)\ns=0\nsmax=-100\n\nsys.setrecursionlimit(3000)\n\n\n\ndef dfs(h):\n global smax\n if len(h)==n+1:\n s=0\n for j in range(0,q):\n if h[b[j]]-h[a[j]]==c[j]:\n s+=d[j]\n if s>smax:\n smax=s\n\n return\n \n for i in range(0,m+1-h[len(h)-1]):\n \n h2=h[:]\n h2.append(h[len(h)-1]+i)\n dfs(h2)\n\nsta=[1]\ndfs(sta)\nprint(smax)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s313647704', 's500008024', 's544706589']
[9160.0, 9192.0, 9172.0]
[342.0, 2206.0, 696.0]
[592, 627, 594]
p02695
u994935583
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\nimport itertools\nimport numpy as np\n\ndef resolve():\n N,M,Q = map(int,input().split())\n A = np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)))\n s = np.zeros(len(A), np.int32)\n\n for i in range(Q):\n a,b,c,d = map(int,input().split()) \n s += d * (A[:,b-1] - A[:,a-1] == c)\n print(s.max())', '\n\nimport itertools\nimport numpy as np\n\ndef resolve():\n N,M,Q = map(int,input().split())\n A = np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)))\n s = np.zeros(len(A), np.int32)\n for i in range(Q):\n a,b,c,d = map(int,input().split()) \n s += d * (A[:,b-1] - A[:,a-1] == c)\n print(s.max())\nresolve()']
['Wrong Answer', 'Accepted']
['s351878274', 's261890178']
[27136.0, 46776.0]
[108.0, 234.0]
[399, 408]
p02695
u995062424
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 = []\nfor i in range(Q):\n A.append(list(map(int, input().split())))\n\nsA = sorted(A, key=lambda x:x[3], reverse=True)\n\nans = 0\nfor i in range(Q):\n cnt = 0\n num = 0\n tmp = [-1]*N\n tmp[sA[i][1]-1] = tmp[sA[i][0]-1]+sA[i][2]\n num += sA[i][3]\n cnt += 1\n for j in range(Q):\n if(cnt == N):\n break\n if(i == j):\n continue\n if(tmp[sA[j][1]-1] == -1):\n tmp[sA[j][1]-1] = tmp[sA[j][0]-1]+sA[j][2]\n num += sA[j][3]\n cnt += 1\n else:\n if(tmp[sA[j][1]-1] == tmp[sA[j][0]-1]+sA[j][2]):\n num += sA[j][3]\n cnt += 1\n print(tmp)\n ans = max(ans, num) \nprint(ans)', 'from itertools import combinations_with_replacement\n\nN, M, Q = map(int, input().split())\nnum = []\n\nfor i in range(Q):\n num.append(list(map(int, input().split())))\n\nlst = list(combinations_with_replacement([i for i in range(1, M+1)], N))\n\nans = 0\nfor q in lst:\n ans_tmp = 0\n \n for i in range(Q):\n if(q[num[i][1]-1]-q[num[i][0]-1] == num[i][2]):\n ans_tmp += num[i][3]\n \n if(ans < ans_tmp):\n ans = ans_tmp\nprint(ans)']
['Wrong Answer', 'Accepted']
['s162427361', 's355809792']
[9284.0, 21368.0]
[21.0, 1326.0]
[743, 456]
p02695
u996665352
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())\nqs = [list(map(int,input().split())) for i in range(q)]\nmids = [i for i in range(m)]\n# print(nums)\nmax_ans= 0\nfor mid in itertools.combinations_with_replacement(nums, n-1):\n if sum(mid)>m-1:\n continue\n sum_ans=0\n for i in qs:\n sum_mid = 0\n for j in range(i[0]-1,i[1]-1):\n sum_mid += mid[j]\n if sum_mid == i[2]:\n sum_ans += i[3]\n if sum_ans > max_ans:\n max_ans = sum_ans\n \nprint(max_ans)\n', 'import itertools\nn,m,q=map(int,input().split())\nqs = [list(map(int,input().split())) for i in range(q)]\nmids = [i for i in range(m)]\n# print(nums)\nmax_ans= 0\nfor mid in itertools.combinations_with_replacement(nums, n-1):\n if sum(mid)>m-1:\n continue\n sum_ans=0\n for i in qs:\n sum_mid = 0\n for j in range(i[0]-1,i[1]-1):\n sum_mid += mid[j]\n if sum_mid == i[2]:\n sum_ans += i[3]\n if sum_ans > max_ans:\n max_ans = sum_ans\n \nprint(max_ans)', 'import itertools\nn,m,q=map(int,input().split())\nqs = [list(map(int,input().split())) for i in range(q)]\n\nmax_ans = 0\nfor mid in itertools.combinations_with_replacement(range(1,m+1), n):\n sum_ans=0\n for q in qs:\n if mid[q[1]-1]-mid[q[0]-1] == q[2]:\n sum_ans += q[3]\n if sum_ans > max_ans:\n max_ans = sum_ans\n \nprint(max_ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s544911669', 's722860034', 's773382198']
[9200.0, 9228.0, 9136.0]
[25.0, 22.0, 938.0]
[511, 510, 364]
p02696
u003034853
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['from math import floor\ndef seq(a, b, x):\n return int(floor((a*x)/b)) - int(a*floor(x/b))\nma = 0\na, b, n = map(int, input().split())\nfor i in range(int(1e6)+1):\n ma = max(ma, seq(a, b, i))\nprint(ma)', 'from math import floor\ndef seq(a, b, x):\n return int(floor((a*x)/b)) - int(a*floor(x/b))\nma = 0\na, b, n = map(int, input().split())\nn = min(n, b)\nlow = 1\nhigh = n\nans = 0\nwhile low<=high:\n mid = low + (high-low)//2\n if seq(a, b, mid)>=seq(a, b, mid-1):\n low = mid+1\n ans = mid\n else:\n high = mid-1\nprint(seq(a, b, ans))']
['Wrong Answer', 'Accepted']
['s141664772', 's316015609']
[9056.0, 9212.0]
[694.0, 19.0]
[203, 352]
p02696
u005317312
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import math as mt\nA,B,N = map(int,input().split())\nprint(math.floor((A*N)/B)-A*math.floor(N/B)', 'A,B,N = map(int,input().split())\ntmp=0\nfor i in range(N//2,N+1):\n floor = (A*i)//B-A*(i//B)\n if floor>tmp:\n tmp = floor\n print(tmp)\nprint(tmp)', 'import math as mt\nA,B,N = map(int,input().split())\nprint(math.floor((A*N)/B)-A*math.floor(N/B))', 'import math\nA,B,N = map(int,input().split())\nif B-1>N:\n print(math.floor((A*N)/B)-A*math.floor(N/B))\nelse:\n print(math.floor((A*(B-1))/B)-A*math.floor((B-1)/B))']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s224860899', 's652341020', 's722489311', 's373097535']
[8896.0, 28140.0, 9108.0, 9188.0]
[22.0, 2264.0, 21.0, 24.0]
[94, 158, 95, 166]
p02696
u007128301
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
["s=input().split(' ')\nA,B,N=int(s[0]),int(s[1]),int(s[2])\n\ndef f(x):\n a=np.floor(A*x/B)-A*np.floor(x/B)\n return a.astype(int)\n\nif N<B-1:\n print(f(N))\nelse:\n print(f(B-1))\n", "import numpy as np\n\ns=input().split(' ')\nA,B,N=int(s[0]),int(s[1]),int(s[2])\n\ndef f(x):\n a=np.floor(A*x/B)-A*np.floor(x/B)\n return a.astype(int)\n\nif N<B-1:\n print(f(N))\nelse:\n print(f(B-1))\n"]
['Runtime Error', 'Accepted']
['s140205070', 's728983753']
[9032.0, 27136.0]
[20.0, 105.0]
[182, 202]
p02696
u007886915
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['# -*- coding: utf-8 -*-\nimport sys\nimport itertools\nimport fractions\nimport copy\nimport bisect\nimport math\nimport numpy as np\n\n\n#w=input()\nfrom operator import itemgetter\nfrom sys import stdin\n\nfrom operator import mul\nfrom functools import reduce\nfrom collections import Counter\n#from collections import deque\n\n#input = stdin.readline\n\n\nN=3\nM=3\ni=0\nj=0\nk=0\nn=3\nr=1\na=[0]*5\nb=[]\n#n=int(input())\n#r=int(input())\n#print(M)\n#A=int(input())\n#B=int(input())\n#print(N)\npre=0\n\n"1行1つの整数を入力を取得し、整数と取得する"\nA,B,N=map(int, input().split(" "))\nsyo=len(str(N))\nif syo <10**4:\n for i in range(N+1):\n k=(A*(i//B))-A*(i//B)\n if pre > k :\n print(pre)\n sys.exit()\n pre=k\n b.append(k)\n k=0\nfor i in range(N+1):\n k=(A*(i+10**(syo-1))//B)-A*((i+10**(syo-1))//B)\n #print(pre,k)\n if pre > k:\n #print(pre)\n sys.exit()\n pre=k\n b.append(k)\n k=0\n\nprint(max(b))\n\n#print(number_list)\n"12 21 332 とか入力する時に使う"\n"1行に複数の整数の入力を取得し、整数として扱う"\n\n\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\n\n\n\n\n\n\n\n\n#print(type(brray[0][0]))\n#print(brray)\n\n"列数に関して自由度の高いint型の値を入力するタイプの行列"\n\n\n\'\'\'\ntable = [[int(i) for i in input().split()] for m in range(m)]\n\nprint(type(N))\nprint(N)\nprint(type(M))\nprint(M)\n\nprint(type(table))\nprint(table)\n\'\'\'\n\n\n\n\n#s=input()\n\n#print(a[0])\n#print([a])\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n#a= stdin.readline().rstrip()\n#print(a.upper())\n"aという変数に入っているものを大文字にして出力"\n\n\n\n\n\n#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]\n#a = [[int(c) for c in l.strip()] for l in sys.stdin]]\n#print(a)\n\n\n\n##############################################################################################\n##############################################################################################\n#under this line explains example calculation\n\n\n\n#nCr combination\n\'\'\'\ndef cmb(n,r):\n #When n < r , this function isn\'t valid\n r= min(n-r,r)\n #print(n,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n-r, -1))\n #flochart mul(n,n-1)=x\n #next mul(x,n-2)........(n-r+1,n-r)\n #mul read a,b and returns a*b\n\n under = reduce(mul, range(1, r+1))\n #print(over, under)\n #reduce is applied mul(1,2)=2\n #next mul(2,3)=6\n #next mul(6,4)=4.........last(r!,r+1)=r+1!\n\n return over // under\n #// is integer divide\n #calc example 5C2\n #over=5*4*3\n #under=3*2*1\na = cmb(n, r)\n#print(a)\n\'\'\'\n\n\n\n\n\n#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]\n#print(A)\n\n#A.insert(index, 5)\n#print(index)\n#print(A)\n\n\n\n\n\n\n########################################################################\n########################################################################\n\n#print(b2)\n\n\n\n#print(b3)\n', '# -*- coding: utf-8 -*-\nimport sys\nimport itertools\nimport fractions\nimport copy\nimport bisect\nimport math\nimport numpy as np\n\n\n#w=input()\nfrom operator import itemgetter\nfrom sys import stdin\n\nfrom operator import mul\nfrom functools import reduce\nfrom collections import Counter\n#from collections import deque\n\n#input = stdin.readline\n\n\nN=3\nM=3\ni=0\nj=0\nk=0\nn=3\nr=1\na=[0]*5\nb=[]\n#n=int(input())\n#r=int(input())\n#print(M)\n#A=int(input())\n#B=int(input())\n#print(N)\npre=0\n\n"1行1つの整数を入力を取得し、整数と取得する"\nA,B,N=map(int, input().split(" "))\nsyo=len(str(N))\nif syo <10**4:\n for i in range(N+1):\n k=((A*i)//B))-A*(i//B)\n if pre > k :\n print(pre)\n sys.exit()\n pre=k\n b.append(k)\n k=0\nfor i in range(N+1):\n k=(A*(i+10**(syo-1)))//B-A*((i+10**(syo-1))//B)\n #print(pre,k)\n if pre > k:\n print(pre)\n sys.exit()\n pre=k\n b.append(k)\n k=0\n\nprint(max(b))\n\n#print(number_list)\n"12 21 332 とか入力する時に使う"\n"1行に複数の整数の入力を取得し、整数として扱う"\n\n\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\n\n\n\n\n\n\n\n\n#print(type(brray[0][0]))\n#print(brray)\n\n"列数に関して自由度の高いint型の値を入力するタイプの行列"\n\n\n\'\'\'\ntable = [[int(i) for i in input().split()] for m in range(m)]\n\nprint(type(N))\nprint(N)\nprint(type(M))\nprint(M)\n\nprint(type(table))\nprint(table)\n\'\'\'\n\n\n\n\n#s=input()\n\n#print(a[0])\n#print([a])\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n#a= stdin.readline().rstrip()\n#print(a.upper())\n"aという変数に入っているものを大文字にして出力"\n\n\n\n\n\n#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]\n#a = [[int(c) for c in l.strip()] for l in sys.stdin]]\n#print(a)\n\n\n\n##############################################################################################\n##############################################################################################\n#under this line explains example calculation\n\n\n\n#nCr combination\n\'\'\'\ndef cmb(n,r):\n #When n < r , this function isn\'t valid\n r= min(n-r,r)\n #print(n,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n-r, -1))\n #flochart mul(n,n-1)=x\n #next mul(x,n-2)........(n-r+1,n-r)\n #mul read a,b and returns a*b\n\n under = reduce(mul, range(1, r+1))\n #print(over, under)\n #reduce is applied mul(1,2)=2\n #next mul(2,3)=6\n #next mul(6,4)=4.........last(r!,r+1)=r+1!\n\n return over // under\n #// is integer divide\n #calc example 5C2\n #over=5*4*3\n #under=3*2*1\na = cmb(n, r)\n#print(a)\n\'\'\'\n\n\n\n\n\n#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]\n#print(A)\n\n#A.insert(index, 5)\n#print(index)\n#print(A)\n\n\n\n\n\n\n########################################################################\n########################################################################\n\n#print(b2)\n\n\n\n#print(b3)\n', '# -*- coding: utf-8 -*-\nimport sys\nimport itertools\nimport fractions\nimport copy\nimport bisect\nimport math\nimport numpy as np\n\n\n#w=input()\nfrom operator import itemgetter\nfrom sys import stdin\n\nfrom operator import mul\nfrom functools import reduce\nfrom collections import Counter\n#from collections import deque\n\n#input = stdin.readline\n\n\nN=3\nM=3\ni=0\nj=0\nk=0\nn=3\nr=1\na=[0]*5\nb=[]\n#n=int(input())\n#r=int(input())\n#print(M)\n#A=int(input())\n#B=int(input())\n#print(N)\npre=0\n\n"1行1つの整数を入力を取得し、整数と取得する"\nA,B,N=map(int, input().split(" "))\nsyo=len(str(N))\nif syo <10**4:\n for i in range(N+1):\n k=(A*(i//B))-A*(i//B)\n if pre > k :\n print(pre)\n sys.exit()\n pre=k\n b.append(k)\n k=0\nfor i in range(N+1):\n k=(A*(i+10**(syo-1))//B)-A*((i+10**(syo-1))//B)\n #print(pre,k)\n if pre > k:\n print(pre)\n sys.exit()\n pre=k\n b.append(k)\n k=0\n\nprint(max(b))\n\n#print(number_list)\n"12 21 332 とか入力する時に使う"\n"1行に複数の整数の入力を取得し、整数として扱う"\n\n\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\n\n\n\n\n\n\n\n\n#print(type(brray[0][0]))\n#print(brray)\n\n"列数に関して自由度の高いint型の値を入力するタイプの行列"\n\n\n\'\'\'\ntable = [[int(i) for i in input().split()] for m in range(m)]\n\nprint(type(N))\nprint(N)\nprint(type(M))\nprint(M)\n\nprint(type(table))\nprint(table)\n\'\'\'\n\n\n\n\n#s=input()\n\n#print(a[0])\n#print([a])\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n#a= stdin.readline().rstrip()\n#print(a.upper())\n"aという変数に入っているものを大文字にして出力"\n\n\n\n\n\n#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]\n#a = [[int(c) for c in l.strip()] for l in sys.stdin]]\n#print(a)\n\n\n\n##############################################################################################\n##############################################################################################\n#under this line explains example calculation\n\n\n\n#nCr combination\n\'\'\'\ndef cmb(n,r):\n #When n < r , this function isn\'t valid\n r= min(n-r,r)\n #print(n,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n-r, -1))\n #flochart mul(n,n-1)=x\n #next mul(x,n-2)........(n-r+1,n-r)\n #mul read a,b and returns a*b\n\n under = reduce(mul, range(1, r+1))\n #print(over, under)\n #reduce is applied mul(1,2)=2\n #next mul(2,3)=6\n #next mul(6,4)=4.........last(r!,r+1)=r+1!\n\n return over // under\n #// is integer divide\n #calc example 5C2\n #over=5*4*3\n #under=3*2*1\na = cmb(n, r)\n#print(a)\n\'\'\'\n\n\n\n\n\n#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]\n#print(A)\n\n#A.insert(index, 5)\n#print(index)\n#print(A)\n\n\n\n\n\n\n########################################################################\n########################################################################\n\n#print(b2)\n\n\n\n#print(b3)\n', '# -*- coding: utf-8 -*-\nimport sys\nimport itertools\nimport fractions\nimport copy\nimport bisect\nimport math\nimport numpy as np\n\n\n#w=input()\nfrom operator import itemgetter\nfrom sys import stdin\n\nfrom operator import mul\nfrom functools import reduce\nfrom collections import Counter\n#from collections import deque\n\n#input = stdin.readline\n\n\nj=0\nk=0\nn=3\nr=1\na=[0]*5\nb=[]\n#n=int(input())\n#r=int(input())\n#print(M)\n#A=int(input())\n#B=int(input())\n#print(N)\n"1行1つの整数を入力を取得し、整数と取得する"\n\n\n\n#print(number_list)\n"12 21 332 とか入力する時に使う"\n"1行に複数の整数の入力を取得し、整数として扱う"\n\n\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\n\n\n\n\n\n\n\n\n#print(type(brray[0][0]))\n#print(brray)\n\n"列数に関して自由度の高いint型の値を入力するタイプの行列"\n\n\n\'\'\'\ntable = [[int(i) for i in input().split()] for m in range(m)]\n\nprint(type(N))\nprint(N)\nprint(type(M))\nprint(M)\n\nprint(type(table))\nprint(table)\n\'\'\'\n\n\n\n\n#s=input()\n\n#print(a[0])\n#print([a])\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n#a= stdin.readline().rstrip()\n#print(a.upper())\n"aという変数に入っているものを大文字にして出力"\n\n\n\n\n\n#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]\n#a = [[int(c) for c in l.strip()] for l in sys.stdin]]\n#print(a)\n\n\n\n##############################################################################################\n##############################################################################################\n#under this line explains example calculation\n\n\n\n#nCr combination\n\'\'\'\ndef cmb(n,r):\n #When n < r , this function isn\'t valid\n r= min(n-r,r)\n #print(n,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n-r, -1))\n #flochart mul(n,n-1)=x\n #next mul(x,n-2)........(n-r+1,n-r)\n #mul read a,b and returns a*b\n\n under = reduce(mul, range(1, r+1))\n #print(over, under)\n #reduce is applied mul(1,2)=2\n #next mul(2,3)=6\n #next mul(6,4)=4.........last(r!,r+1)=r+1!\n\n return over // under\n #// is integer divide\n #calc example 5C2\n #over=5*4*3\n #under=3*2*1\na = cmb(n, r)\n#print(a)\n\'\'\'\n\n\n\n\n\n#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]\n#print(A)\n\n#A.insert(index, 5)\n#print(index)\n#print(A)\n\n\n\n\n\n\n########################################################################\n########################################################################\n\n#print(b2)\n\n\n\n#print(b3)\n\n\ninput = sys.stdin.readline\nsys.setrecursionlimit(10 ** 7)\n\n\n\ndef main():\n A, B, N = map(int, input().split())\n x=min(B-1,N)\n k=((A*x)//B)-A*(x//B)\n print(k)\n\n\nif __name__ == "__main__":\n main()\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s854823496', 's859719694', 's874899815', 's878676829']
[79992.0, 8996.0, 78516.0, 27080.0]
[2208.0, 24.0, 2208.0, 111.0]
[6800, 6800, 6799, 7166]
p02696
u009787707
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['A,B,N=map(int,input().split())\nx=N\nans=(A*x/B)//1-A*(x//B)\nprint(ans)', 'A,B,N=map(int,input().split())\nif N<B:\n x=N\nelif N==B:\n x=N-1\nelse:\n x=(N//B)*B-1\nans=(A*x/B)//1-A*(x//B)\nprint(ans)', 'A,B,N=map(int,input().split())\nif N<B:\n x=N\nelif N==B:\n x=N-1\nelse:\n x=(N//B)*B-1\nans=(A*x/B)//1-A*(x//B)\nprint(int(ans))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s033800291', 's120028380', 's183343222']
[9104.0, 9080.0, 9236.0]
[26.0, 29.0, 26.0]
[69, 125, 130]
p02696
u010090035
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a,b,n=map(int,input().split())\n\ndef f(a,b,x):\n return (a*x)//b - a*(x//b)\n\nprint(f(min(b-1,n)))', 'a,b,n=map(int,input().split())\n\ndef f(x):\n return (a*x)//b - a*(x//b)\n\nprint(f(min(b-1,n)))']
['Runtime Error', 'Accepted']
['s005642057', 's167612660']
[9088.0, 9144.0]
[25.0, 28.0]
[98, 94]
p02696
u012955130
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
["import math\n\ndef floor(A, B, x):\n return math.floor(A * x / B) - A * math.floor(x/B) \n\nA, B, N = map(int, input().split(' '))\n\nprint(max(floor(A,B,N), floor(A,B,B-1)))", "import math\n\nA, B, N = map(int, input().split(' '))\n\n_max = 0\nfor x in range(N, N -10, -1):\n \n num =math.floor(A * x / B) - A * math.floor(x/B) \n # print(num)\n if num > _max:\n _max = num\n\nprint(_max)", "import math\n\ndef floor(A, B, x):\n return math.floor(A * x / B) - A * math.floor(x/B) \n\nA, B, N = map(int, input().split(' '))\nx = min(N, B-1)\nprint(floor(A,B,x))\n"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s585551516', 's767973488', 's572353358']
[9108.0, 9076.0, 9072.0]
[21.0, 21.0, 23.0]
[170, 219, 165]
p02696
u017415492
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import math\na,b,n=map(int,input().split())\n\nprint(math.floor((b-1)*a/b))', 'import math\na,b,n=map(int,input().split())\nif n>b-1:\n print(math.floor((b-1)*a/b))\nelse:\n print(math.floor((n*a/b)))']
['Wrong Answer', 'Accepted']
['s417663984', 's176176547']
[9144.0, 9172.0]
[22.0, 21.0]
[72, 118]
p02696
u020962106
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import math\na,b,n = map(int,input().split())\nm = 0\nx = 1\nax = a*x\nwhile ax/b <0.01:\n x*=10\n ax = a*x\n if x>n:\n x//10\n break\nif a-b==1:\n print(n)\nelif b-a==1:\n print(n-1)\nelse:\n for i in range(x,n+1):\n if i==b-1:\n ch = (a*i//b)-a*(i//b)\n print(ch)\n break', 'a,b,n = map(int,input().split())\nprint(min(b-1,n))', 'import math\na,b,n = map(int,input().split())\nx = min(b-1,n)\nprint(math.floor(a*x/b)-a*math.floor(x/b))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s158527524', 's760071587', 's948057509']
[9140.0, 9156.0, 9092.0]
[2205.0, 21.0, 23.0]
[325, 50, 102]
p02696
u022658079
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['A,B,N= list(map(int, input().split()))\nprint(min(B-1,N))', 'A,B,N= list(map(int, input().split()))\nma=0\nfor i in range(min(N,B)+1,1):\n a=int(A*i/B)-A*int(i/B)\n if(a<=A):\n \tif(ma<a):\n \tma=a\n break\nprint(ma)', 'A,B,N= list(map(int, input().split()))\nma=0\nfor i in range(1,min(N,B)+1):\n a=int(A*i/B)-A*int(i/B)\n print(a)\n if(ma<a):\n ma=a\n if(a>=A):\n break\nprint(ma)', 'A,B,N= list(map(int, input().split()))\nprint(int(A*min(B-1,N)/B)-A*int(min(B-1,N)/B))']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s416430276', 's457036309', 's810247895', 's214813449']
[9048.0, 8912.0, 9380.0, 9164.0]
[24.0, 21.0, 2235.0, 23.0]
[56, 172, 177, 85]
p02696
u026862065
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a, b, x = map(int, input())\nprint(b - 1)', 'a, b, x = map(int, input().split())\nprint(a * (b - 1) // b)', 'a, b, x = map(int, input())\nprint(a * (b - 1) // b)', 'a, b, n = map(int, input().split())\nprint(a * min(n, b - 1) // b)']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s134747772', 's400058270', 's820455077', 's248719896']
[9096.0, 9152.0, 9084.0, 9160.0]
[24.0, 22.0, 19.0, 21.0]
[40, 59, 51, 65]
p02696
u028014940
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import numpy as np\na,b,n=map(int,input().split())\n\nx=np.arange(1,n+1)\n\ns1=np.floor((a/b)*x)\ns2=a*np.floor(x/b)\ns=s1-s2\nprint(np.max(s))', 'a, b, n = list(map(int, input().split()))\nx = min(b - 1, n) \nans = int(a * x / b)\nprint(ans)']
['Runtime Error', 'Accepted']
['s813949179', 's159658255']
[27440.0, 9084.0]
[103.0, 24.0]
[135, 138]
p02696
u028554976
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a, b, n = map(int, input().split())\nprint(int((a*(max(n,b-1)%b)-(a*max(n,b-1))%b)/b))\n', 'a, b, n = map(int, input().split())\nprint((a*(max(n,b-1)%b)-(a*max(n,b-1))%b)/b)', 'a, b, n = map(int, input().split())\nprint(int((a*(min(n,b-1)%b)-(a*min(n,b-1))%b)/b))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s339459279', 's956606150', 's554319873']
[9080.0, 9076.0, 9152.0]
[27.0, 26.0, 27.0]
[86, 80, 86]
p02696
u028973125
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import sys\nimport math\nfrom pprint import pprint\n\nA, B, N = map(int, sys.stdin.readline().strip().split())\n\ndef func(x):\n return math.floor(A*x/B) - A*math.floor(x/B)\n\n\nright = N\nleft = 0\nwhile right - left > 5:\n mid_left = right//3+left*2//3\n mid_right = right*2//3+left//3\n \n if func(mid_left) <= func(mid_right):\n left = mid_left\n else:\n right = mid_right\n \n\nans = -1 * float("inf")\nfor i in range(left, right+1):\n print(i, func(i))\n ans = max(ans, func(i))\nprint(ans)', 'import sys\nimport math\nfrom pprint import pprint\n\nA, B, N = map(int, sys.stdin.readline().strip().split())\n\ndef func(x):\n return math.floor(A*x/B) - A*math.floor(x/B)\n \n\nprint(func(min(B-1, N)))']
['Wrong Answer', 'Accepted']
['s256212354', 's855991965']
[9960.0, 9948.0]
[29.0, 27.0]
[573, 226]
p02696
u033287260
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
["import math\nA, B, N = map(int, input().split())\n\nfor i in range(N+1):\n num = math.floor(A*i/B) - A*math.floor(i/B)\n if num > maxnum:\n maxnum = num\n print(str(i) + ':' + str(num) + ' max is ' + str(maxnum))\nprint(maxnum)\n", 'import math\nA, B, N = map(int, input().split())\n\nnum = math.floor(A*min(B-1,N)/B) - A*math.floor(min(B-1,N)/B)\n\nprint(num)\n']
['Runtime Error', 'Accepted']
['s111806198', 's825474237']
[9040.0, 9048.0]
[20.0, 21.0]
[236, 123]
p02696
u035453792
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a,b,n=map(int,input().split())\nif n>=b:\n x=b-1\n fl1=a*x//b\n fl2=a*(x//b)\nelse:\n fl1=a*(n//b)\n fl2=a*(n//b)\n \nans = fl1-fl2\nprint(ans)', 'a,b,n=map(int,input().split())\nif n>=b:\n x=b-1\n fl1=a*x//b\n fl2=a*(x//b)\nelse:\n fl1=a*n//b\n fl2=a*(n//b)\n \nans = fl1-fl2\nprint(ans)']
['Wrong Answer', 'Accepted']
['s328041657', 's671896343']
[9072.0, 8952.0]
[28.0, 31.0]
[151, 149]
p02696
u042113240
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['A, B, N = input().split()\nA = float(A)\nB = float(B)\nN = float(N)\nimport math\nmax = 0\nx = B-1\nwhile x <= N:\n a = math.floor(A*x/B)-A*math.floor(x/B)\n if a > max:\n max = a\nprint(str(max))', 'A, B, N = input().split()\nA = float(A)\nB = float(B)\nN = float(N)\nimport math\nvalue = math.floor(A*(B-1)/B)\nmax = 0\nfor i in range(B):\n a = int(math.floor(A*x/B)-A*math.floor(x/B))\n if a > max:\n max = a\nif N < B-1:\n print(a)\nelse:\n print(value)', 'A, B, N = input().split()\nA = float(A)\nB = float(B)\nN = float(N)\nimport math\nvalue = math.floor(A*(B-1)/B)\na = int(math.floor(A*N/B)-A*math.floor(N/B))\nif N < B-1:\n print(a)\nelse:\n print(value)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s429471790', 's520780568', 's958140448']
[8988.0, 9072.0, 9004.0]
[2205.0, 20.0, 22.0]
[190, 250, 195]
p02696
u048800107
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['\nfrom sys import stdin\ninput = stdin.readline\n\na,b,n = map(int,input().split())\n\nmaxpoint = 0\n\nfor i in reversed(range(n+1)):\n tmp = int((a * i) / b) - a * int(i/b) \n if i % (b-1) == 0 and b > 1:\n print(tmp) \n exit()\n maxpoint = max(tmp,maxpoint)\n\nprint(maxpoint)\n\n\n\n', 'from sys import stdin\ninput = stdin.readline\n\na,b,n = map(int,input().split())\n\nmaxpoint = 0\n\nfor i in reversed(range(n+1)):\n tmp = int((a * i) / b) - a * int(i/b) \n if b > 1:\n if i % (b-1) == 0 :\n print(tmp) \n exit()\n elif b == 1:\n print(0)\n exit()\n maxpoint = max(tmp,maxpoint)\nprint(maxpoint)\n\n', '\nfrom sys import stdin\ninput = stdin.readline\n\na,b,n = map(int,input().split())\nmaxpoint = 0\n\nif b > n :\n tmp = int((a * n) / b) - a * int(n/b) \n maxpoint = max(tmp,maxpoint)\n print(0)\nelif b == n:\n maxpoint = 0\nelse:\n tmp = int((a * n) / b) - a * int(n/b) \n k = int(n/b)*b -1\n t1 = int((a * k) / b) - a * int(k/b) \n maxpoint = max(t1,tmp)\n \n # t1 = int((a * i) / b) - a * int(i/b) \n # if b > 1:\n \n # print(maxpoint) \n # exit()\n # elif b == 1:\n # print(0)\n # exit()\n # if t1 > maxpoint:\n # maxpoint = t1\n \n \n # print(tmp)\n \n # print(k)\n \n # maxpoint = max(tmp,k)\n \n\nprint(maxpoint)\n\n', "\nfrom sys import stdin\ninput = stdin.readline\n\na,b,n = map(int,input().split())\nmaxpoint = 0\n\nif b > n :\n tmp = int((a * n) / b) - a * int(n/b) \n maxpoint = max(tmp,maxpoint)\n print('g')\n exit()\nelif b == n:\n maxpoint = 0\nelse:\n tmp = int((a * n) / b) - a * int(n/b) \n k = int(n/b)*b -1\n t1 = int((a * k) / b) - a * int(k/b) \n maxpoint = max(t1,tmp)\n \n # t1 = int((a * i) / b) - a * int(i/b) \n # if b > 1:\n \n # print(maxpoint) \n # exit()\n # elif b == 1:\n # print(0)\n # exit()\n # if t1 > maxpoint:\n # maxpoint = t1\n \n \n # print(tmp)\n \n # print(k)\n \n # maxpoint = max(tmp,k)\n \n\nprint(maxpoint)\n\n", "\nfrom sys import stdin\ninput = stdin.readline\n\na,b,n = map(int,input().split())\nmaxpoint = 0\n\nif b > n :\n tmp = int((a * n) / b) - a * int(n/b) \n maxpoint = max(tmp,maxpoint)\n print('g')\nelif b == n:\n maxpoint = 0\nelse:\n tmp = int((a * n) / b) - a * int(n/b) \n k = int(n/b)*b -1\n t1 = int((a * k) / b) - a * int(k/b) \n maxpoint = max(t1,tmp)\n \n # t1 = int((a * i) / b) - a * int(i/b) \n # if b > 1:\n \n # print(maxpoint) \n # exit()\n # elif b == 1:\n # print(0)\n # exit()\n # if t1 > maxpoint:\n # maxpoint = t1\n \n \n # print(tmp)\n \n # print(k)\n \n # maxpoint = max(tmp,k)\n \n\nprint(maxpoint)\n\n", '\nfrom sys import stdin\ninput = stdin.readline\n\na,b,n = map(int,input().split())\nmaxpoint = 0\n\nif b > n :\n for i in range(n+1):\n tmp = int((a * i) / b) - a * int(i/b) \n maxpoint = max(tmp,maxpoint)\n print(0)\n \nelse:\n for i in reversed(range(n+1)):\n c += 1\n tmp = int((a * i) / b) - a * int(i/b) \n if b > 1:\n if i % (b-1) == 0 :\n maxpoint = max(tmp,maxpoint)\n print(maxpoint) \n exit()\n elif b == 1:\n print(0)\n exit()\n maxpoint = max(tmp,maxpoint)\n\nprint(maxpoint)\n\n', 'from sys import stdin\ninput = stdin.readline\n \na,b,n = map(int,input().split())\nmaxpoint = 0\n \nif b > n :\n tmp = int((a * n) / b) - a * int(n/b) \n maxpoint = max(tmp,maxpoint)\nelse:\n k = int(n/b)*b -1\n maxpoint = int((a * k) / b) - a * int(k/b) \n if b == 1:\n maxpoint = 0\n \nprint(maxpoint)']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s007677794', 's029392867', 's154656696', 's380021491', 's497761752', 's909504753', 's318832038']
[9108.0, 9132.0, 9088.0, 9044.0, 9200.0, 9324.0, 9188.0]
[2205.0, 2205.0, 22.0, 22.0, 22.0, 2214.0, 23.0]
[291, 353, 790, 803, 792, 612, 315]
p02696
u054825571
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['A,B,N=map(int,input().split())\nif N>B:\n print((A*N)//B-A*(N//B))\nelse:\n print((A*(B-1)//B-A*((B-1)//B)))', 'A,B,N=map(int,input().split())\nif B>N:\n print((A*N)//B-A*(N//B))\nelse:\n print((A*(B-1)//B-A*((B-1)//B)))']
['Wrong Answer', 'Accepted']
['s735117051', 's270675997']
[9104.0, 9048.0]
[27.0, 29.0]
[106, 106]
p02696
u057668615
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import math\nA, B, N = list(map(int, input().split()))\nans = 0\nif B+1 < N:\n C = B+1\nelse:\n C = N\nfor i in range(1, C+1):\n val = math.floor(A*i/B) - A*math.floor(i/B)\n print("i", i, "val", val)\n ans = max(ans, val)\n\nprint(ans)\n', 'import math\nA, B, N = list(map(int, input().split()))\nans = 0\nif B+1 < N:\n C = B+1\nelse:\n C = N\nif B//A == 0:\n D = 1\nelse:\n D = B//A\n\nfor i in range(1, C+D, D):\n val = math.floor(A*i/B) - A*math.floor(i/B)\n #print("i", i, "val", val)\n ans = max(ans, val)\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s546265241', 's473218284']
[26800.0, 9180.0]
[2248.0, 717.0]
[240, 376]
p02696
u064793078
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a, b, n = [int(x) for x in input().split()]\n\n\nx = max(0,n-a-a-a-a)\n\ns = -a\n\nfor i in range(x,n+1):\n s = max(s,(a*i//b)-a*(i//b))\nfor i in range(b-1,b):\n s = max(s,(a*i//b)-a*(i//b))\n\n\nprint(s)\n', 'a, b, n = [int(x) for x in input().split()]\n\nn = min(n,b-1)\nx = max(0,n-a-a-a-a)\n\ns = -a\n\nfor i in range(x,n+1):\n s = max(s,(a*i//b)-a*(i//b))\n\n\n\nprint(s)\n']
['Wrong Answer', 'Accepted']
['s843176050', 's149829233']
[9100.0, 9060.0]
[1856.0, 1859.0]
[199, 158]
p02696
u068944955
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['A, B, N = map(int, input().split())\nfrom math import floor\n\nfor n in range(B-1, 0, -1):\n nB = n/B - floor(n/B)\n AnB = A * nB\n\n AnBf = floor(A*n/B) - A*n/B\n print(floor(A*n/B)-A*floor(n/B))\n exit()', 'A, B, N = map(int, input().split())\nfrom math import floor\nfrom math import gcd\nfrom math import ceil\nk = gcd(A, B)\n\nAs = A // k\nBs = B // k\n\nQ = min(N, B-1)\nprint(Q)\nR = ceil(Bs / As)\nres = []\nfor b in range(Q, Q - R, -1):\n print(b)\n res.append(round(floor(b*As/Bs) - A*floor(b/B)))\n\nprint(max(res))', 'A, B, N = map(int, input().split())\nfrom math import floor\nfrom math import gcd\nfrom math import ceil\nk = gcd(A, B)\n\nAs = A // k\nBs = B // k\n\nQ = min(N, B-1)\nR = ceil(Bs / As)\nres = []\nfor b in range(Q, Q - R, -1):\n res.append(round(floor(b*As/Bs) - A*floor(b/B)))\n\nprint(max(res))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s238331435', 's366751884', 's064824986']
[9132.0, 123928.0, 106304.0]
[22.0, 2255.0, 1647.0]
[211, 306, 284]
p02696
u075012704
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['A, B, N = map(int, input().split())\n\ndef calc(x):\n return ((A * x) // B) - A * (x // B)\n\nprint(max(calc(N), calc(B - 1)))\n', 'A, B, N = map(int, input().split())\n\ndef calc(x):\n return ((A * x) // B) - A * (x // B)\n\nprit(max(calc(N), calc(B - 1)))\n', 'A, B, N = map(int, input().split())\n\ndef calc(x):\n return ((A * x) // B) - A * (x // B)\n\nif N < B:\n print(calc(N))\nelse:\n print(calc(B - 1))\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s422187839', 's739053510', 's819615897']
[8992.0, 9168.0, 9156.0]
[20.0, 24.0, 22.0]
[125, 124, 150]
p02696
u075304271
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import numpy as np\nimport math\nimport scipy\nimport itertools\n\ndef score(arr):\n hoge = 0\n for ai,bi,ci,di in zip(a, b, c, d):\n if arr[bi-1]-arr[ai-1] == ci:\n hoge += di\n return hoge\n\ndef dfs(arr):\n if len(arr) == n:\n return score(arr)\n last = arr[-1] if len(arr) > 0 else 0\n res = 0\n for i in range(last, m+1):\n arr.append(i)\n res = max(res, dfs(arr))\n arr.pop()\n return res\n\ndef solve():\n global a, b, c, d, n, m, q\n n, m, q = map(int, input().split())\n a, b, c, d = [0]*q, [0]*q, [0]*q, [0]*q\n for i in range(q):\n a[i], b[i], c[i], d[i] = map(int, input().split())\n print(dfs([]))\n return 0\n\nif __name__ == "__main__":\n solve()\n', 'import numpy as np\nimport math\nimport scipy\nimport itertools\n\ndef solve():\n a, b, n = map(int, input().split())\n x = min(b-1, n)\n print(math.floor(a*x/b)-a*math.floor(x/b))\n return 0\n\nif __name__ == "__main__":\n solve()\n']
['Runtime Error', 'Accepted']
['s743877746', 's073509291']
[31216.0, 31024.0]
[123.0, 123.0]
[727, 235]
p02696
u077003677
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
["import sys\nimport os\n\ndef file_input():\n f = open('../Beginner_Contest_165/input.txt', 'r')\n sys.stdin = f\n\ndef main():\n #file_input()\n # input()\n A,B,N=map(int, input().split())\n\n max=0\n # for x in range(N+1):\n \n \n # # ans=int(A*min)\n # # print(min)\n # if x==0:\n # max=min\n # elif min > max:\n # max=min\n # else:\n # break\n\n max=0\n max_x=0\n reg=[0]*B+1\n\n for x in range(N+1):\n rem = x%B\n if reg[rem]==1:\n break\n else:\n reg[rem]=1\n if rem > max:\n max=rem\n max_x=x\n\n \n\n print(int(A*max_x/B)-A*int(max_x/B))\n\nif __name__ == '__main__':\n main()\n", "import sys\nimport os\nimport math\n\ndef file_input():\n f = open('../Beginner_Contest_165/input.txt', 'r')\n sys.stdin = f\n\ndef main():\n #file_input()\n # input()\n A,B,N=map(int, input().split())\n\n max=0.0\n for x in range(10):\n \n min,_=math.modf(x/B)\n # ans=int(A*min)\n # print(min)\n if x==0:\n max=min\n elif min > max:\n max=min\n else:\n break\n\n print(int(max*A))\n\nif __name__ == '__main__':\n main()\n", "import sys\nimport os\n\ndef file_input():\n f = open('../Beginner_Contest_165/input.txt', 'r')\n sys.stdin = f\n\ndef main():\n # file_input()\n # input()\n A,B,N=map(int, input().split())\n\n max=0\n # for x in range(N+1):\n \n \n # # ans=int(A*min)\n # # print(min)\n # if x==0:\n # max=min\n # elif min > max:\n # max=min\n # else:\n # break\n\n # max=0\n # max_x=0\n # first=0\n #\n # for x in range(N+1):\n # rem = x%B\n # if x == 0:\n # first=rem\n # elif rem == first:\n # break\n # if rem > max:\n # max=rem\n # max_x=x\n\n if N<B:\n max_x=N\n else:\n max_x=B-1\n\n \n\n print(int(A*max_x/B)-A*int(max_x/B))\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Wrong Answer', 'Accepted']
['s236935063', 's636594675', 's301278944']
[9056.0, 9180.0, 9120.0]
[21.0, 23.0, 19.0]
[813, 529, 902]
p02696
u081784777
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a, b, n = map(int, input().split())\n \ntmp = 0\nfor x in (range(1, b+1, b): \n#for x in range(1, n+1):\n calc = a*x//b - a*(x//b)\n if calc > tmp:\n tmp = calc\n \nprint(tmp)', 'a, b, n = map(int, input().split())\n\ntmp = 0\nfor x in (range(1, b+1, b-1) if b<=n else range(1, n+1, n-1)):\n#for x in range(1, n+1):\n #calc = (a*x)//b - a*(x//b)\n \n if calc > tmp:\n tmp = calc\n\nprint(tmp)', 'a, b, n = map(int, input().split())\n \ntmp = 0\nfor x in (range(1, b+1, b)) \n#for x in range(1, n+1):\n calc = a*x//b - a*(x//b)\n if calc > tmp:\n tmp = calc\n \nprint(tmp)', 'a, b, n = map(int, input().split())\n \ntmp = 0\nfor x in (range(1, b+1, b-2) if b<=n else range(1, n+1, n-1)):\n#for x in range(1, n+1):\n calc = a*x//b - a*(x//b)\n if calc > tmp:\n tmp = calc\n \nprint(tmp)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s433876337', 's826978867', 's903566203', 's747750533']
[9044.0, 9112.0, 8956.0, 9192.0]
[25.0, 21.0, 24.0, 21.0]
[213, 219, 213, 213]
p02696
u087512063
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import math\ndef func(i):\n return math.floor(a * i * 1.0 / b) - a * math.floor(i * 1.0 / b);\n \na, b, n = map(int, input().split())\n \nprint (max(func(b), func(n))', 'a, b, n = map(int, input().split())\nx = min(n, b - 1)\nprint(int((a * x) / b) - a * int(x / b))']
['Runtime Error', 'Accepted']
['s099080579', 's166231872']
[8908.0, 9156.0]
[21.0, 21.0]
[163, 94]
p02696
u090406054
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a, b, n = map(int, input().split())\nlist=[]\nfor x in range(n+1):\n q=x%b\n r=int(a*q)\n list.append(r)\nprint(max(list))\n ', 'import math\na, b, n = map(int, input().split())\n\nif n < b-1:\n x = n\nelse:\n x = b-1\n\nm = math.floor(a*x/b) - a*math.floor(x/b)\nprint(m)\n']
['Wrong Answer', 'Accepted']
['s263684673', 's915707561']
[335660.0, 9052.0]
[2217.0, 26.0]
[122, 141]
p02696
u091051505
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a, b, n = map(int, input().split())\nprint(math.floor(a * min((b - 1), n) / b))', 'import math\na, b, n = map(int, input().split())\nprint(math.floor(a * min((b - 1), n) / b))']
['Runtime Error', 'Accepted']
['s262548184', 's313381665']
[9104.0, 9008.0]
[19.0, 21.0]
[78, 90]
p02696
u092387689
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a,b,n = map(int,input().split())\nma = -1\nfor x in range(0,b):\n ans = ((a*x)//b) - (a * (x//b))\n print((a * (x//b)))\n if(ans > ma):\n ma = ans\n print(x,ma)\nprint(ma)', 'a,b,n = map(int,input().split())\nma = -1\n"""\nfor x in range(0,b):\n ans = ((a*x)//b) - (a * (x//b))\n print((a * (x//b)))\n if(ans > ma):\n ma = ans\n print(x,ma)\n"""\nma = ((a*(b-1))//b)\nprint(ma)', 'a,b,n = map(int,input().split())\nma = -1\n\nfor x in range(0,b):\n ans = ((a*x)//b) - (a * (x//b))\n if(ans > ma):\n ma = ans\n \n\nprint(ma)', 'a,b,n = map(int,input().split())\n\ndef f(x):\n return (a*x)//b - a * (x//b)\nif((b-1)>n):\n print(f(n))\nelse:\n print(f(b-1))']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s212760473', 's556667331', 's945412880', 's686109511']
[10500.0, 9184.0, 9164.0, 9168.0]
[2219.0, 23.0, 2205.0, 25.0]
[187, 215, 154, 129]
p02696
u100277898
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import math\nA,B,N = map(int,input().split())\n\nans = 0\nfor x in range(1,N+1):\n a = math.floor(A*x/B)-A*math.floor(x/B)\n if ans < a:\n ans = a\nprint(ans)\n\nx=min(B-1,N)\nprint(math.floor(A*x/B)-A*math.floor(x/B))', 'import math\nA,B,N = map(int,input().split())\n\n\nx=min(B-1,N)\nprint(math.floor(A*x/B)-A*math.floor(x/B))']
['Wrong Answer', 'Accepted']
['s517642263', 's516262865']
[8996.0, 9104.0]
[2205.0, 20.0]
[212, 102]
p02696
u100800700
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a,b,n = map(int,input().split())\nimport math\nif n < b:\n print(int(math.floor(a*n/b) - a*np.floor(n/b)))\nelse:\n print(int(math.floor(a*(b-1)/b) - a*np.floor((b-1)/b)))', 'a,b,n = map(int,input().split())\nimport math\nif n < b:\n print(int(math.floor(a*n/b) - a*math.floor(n/b)))\nelse:\n print(int(math.floor(a*(b-1)/b) - a*math.floor((b-1)/b)))']
['Runtime Error', 'Accepted']
['s520867690', 's315329815']
[9192.0, 9000.0]
[20.0, 20.0]
[172, 176]
p02696
u102223485
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['# coding: utf-8\nA, B, N = map(int, input().split())\ndef calc(num):\n ans = A * num // B - A * num // B\n return ans\n\nprint(min(calc(B-1), calc(N)))', '# coding: utf-8\nA, B, N = map(int, input().split())\n\nnum = min(B-1, N)\n\nprint(A * num // B - A * (num // B))']
['Wrong Answer', 'Accepted']
['s290531979', 's017017542']
[8928.0, 9100.0]
[24.0, 19.0]
[151, 108]
p02696
u106095117
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['\nA, B, N = map(int, input().split())\n\nx = min(B - 1, N)\nans = int(a * x / b)\nprint(ans)', '\nA, B, N = map(int, input().split())\n\nx = min(B - 1, N)\nans = int(A * x / B)\nprint(ans)']
['Runtime Error', 'Accepted']
['s306867107', 's948528533']
[9028.0, 9088.0]
[23.0, 23.0]
[87, 87]
p02696
u106181248
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a, b, n = map(int,input().split())\n \nprint(max(int(a*(b-1)/b) - a*int((b-1)/b), int(a*n/b) - a*int(n/b)))', 'a, b, n = map(int,input().split())\n \nprint(int(a*min(b-1, n)/b) - a*int(min(b-1, n)/b))']
['Wrong Answer', 'Accepted']
['s269225822', 's540320388']
[9184.0, 9168.0]
[21.0, 23.0]
[105, 87]
p02696
u110199424
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['A, B, N = map(int, input().split())\n\ndef floor(x):\n out = (A * x)//B - A * (x//B)\n return out\n\nmax = 0\n\n #if(floor(i) > max):\n #max = floor(i)\nmax = max(floor(N), floor(B-1))\n\nprint(max)\n\n', 'A, B, N = map(int, input().split())\n\ndef floor(x):\n out = (A * x)//B - A * (x//B)\n return out\n\nmax = 0\n\n #if(floor(i) > max):\n #max = floor(i)\n\nif(floor(N) >= floor(B-1)):\n max = floor(N)\nelse:\n max = floor(B-1)\n\nprint(max)\n\n', 'A, B, N = map(int, input().split())\n\ndef floor(x):\n out = (A * x)//B - A * (x//B)\n return out\n\nmax = 0\n\n #if(floor(i) > max):\n #max = floor(i)\n\nif(N < (B-1)):\n max = floor(N)\nelse:\n max = floor(B-1)\n\nprint(max)\n\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s854058797', 's903175641', 's075911017']
[9100.0, 9136.0, 9164.0]
[22.0, 22.0, 21.0]
[233, 276, 263]
p02696
u111652094
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import math\n\nA,B,N=map(int,input().split())\n\na=N//B\n\nif a==0:\n x=N\n \n\nelif N%B==0:\n x=a*B-1\nelse:\n x=B*a-1\n\nwhile math.floor(A*x/B)==math.floor(A*(x-1)/B):\n x=x-1\n if x==1:\n break\nans=math.floor(A*x/B)-A*math.floor(x/B)\nans=max(ans)\n\nprint(ans)\n', 'import math\n\ndef floor(A,B,t):\n return(math.floor(A*t/B)-A*math.floor(t/B))\n\nA,B,N=map(int,input().split())\n\n\nans=floor(A,B,min(B-1,N))\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s926852152', 's763932475']
[9120.0, 9164.0]
[1993.0, 24.0]
[270, 151]
p02696
u112247039
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['a, b, n = map(int,input().split())\nx = min(n,b-1)\nprint(int(b*(x%b) / b))', 'result=[]; a,b,n = list(map(int,input().split()))\nfor x in range(n+1):\n result.append((math.floor(a*x/b))-(a*math.floor(x/b)))\nelse:\n print(max(result))', 'a, b, n = map(int, input().split())\nx = b-1 if n >= b else n\nprint(a*x//b)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s464661496', 's822493585', 's264217889']
[9160.0, 9176.0, 9036.0]
[32.0, 21.0, 28.0]
[73, 154, 74]
p02696
u118760114
2,000
1,048,576
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t.
['import math\nA,B,N = map(int, input().split())\nif (B-1)<=N:\n print(math.floor(A*(B-1)/B)-math.floor((B-1)/B)*A)\nelse:\n print(0)\n \n', 'import math\nA,B,N = map(int, input().split())\nd = [0]\nx = 0\nfor i in range(N+1):\n C = math.floor(A*x/B)\n D = math.floor(x/B)\n ans = C-A*D\n d.append(ans)\n if d[i] < d[i+1]:\n break\n x += 1\nprint(max(d))\n \n', 'import math\nA,B,N = map(int, input().split())\nif (B-1)<=N:\n print(math.floor(A*(B-1)/B)-math.floor((B-1)/B)*A)\nelse:\n print(math.floor(A*N/B)-math.floor(N/B)*A)\n \n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s330282742', 's561507083', 's950739702']
[9100.0, 34656.0, 9156.0]
[20.0, 2207.0, 22.0]
[138, 231, 172]