Problem p02695 (python)

Fixed submission:
n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
  a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1] * 10

def check(A, ans):
  t = 0
  for i in range(q):
    if A[b[i]-1] - A[a[i]-1] == c[i]:
      t += d[i]
  if ans < t:
    return t
  else:
    return ans

ans = 0
for i1 in range(1, m+1):
  A[1] = i1
  if n >= 3:
    for i2 in range(i1, m+1):
      A[2] = i2
      if n >= 4:
        for i3 in range(i2, m+1):
          A[3] = i3
          if n >= 5:
            for i4 in range(i3, m+1):
              A[4] = i4
              if n >= 6:
                for i5 in range(i4, m+1):
                  A[5] = i5
                  if n >= 7:
                    for i6 in range(i5, m+1):
                      A[6] = i6
                      if n >= 8:
                        for i7 in range(i6, m+1):
                          A[7] = i7
                          if n >= 9:
                            for i8 in range(i7, m+1):
                              A[8] = i8
                              if n >= 10:
                                for i9 in range(i8, m+1):
                                  A[9] = i9
                                  ans = check(A, ans)
                              else:
                                ans = check(A, ans)
                          else:
                            ans = check(A, ans)
                      else:
                        ans = check(A, ans)
                  else:
                    ans = check(A, ans)
              else:
                ans = check(A, ans)
          else:
            ans = check(A, ans)
      else:
        ans = check(A, ans)
  else:
    ans = check(A, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
  a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1] * 10

def check(A, ans):
  t = 0
  for i in range(q):
    if A[b[i]] - A[a[i]] == c[i]:
      t += d[i]
  if ans < t:
    return t
  else:
    return ans

ans = 0
for i1 in range(1, m):
  A[1] = i1
  for i2 in range(i1, m):
    A[2] = i2
    for i3 in range(i2, m):
      A[3] = i3
      for i4 in range(i3, m):
        A[4] = i4
        for i5 in range(i4, m):
          A[5] = i5
          for i6 in range(i5, m):
            A[6] = i6
            for i7 in range(i6, m):
              A[7] = i7
              for i8 in range(i7, m):
                A[8] = i8
                for i9 in range(i8, m):
                  A[9] = i9
                  ans = check(A, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
  a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1] * 10

def check(A, ans):
  t = 0
  for i in range(q):
    if A[b[i]] - A[a[i]] == c[i]:
      t += d[i]
  if ans < t:
    return t
  else:
    return ans

ans = 0
for i1 in range(1, m):
  A[1] = i1
  for i2 in range(i1, m):
    A[2] = i2
    for i3 in range(i2, m):
      A[3] = i3
      for i4 in range(i3, m):
        A[4] = i4
        for i5 in range(i4, m):
          A[5] = i5
          for i6 in range(i5, m):
            A[6] = i6
            for i7 in range(i6, m):
              A[7] = i7
              for i8 in range(i7, m):
                A[8] = i8
                for i9 in range(i8, m):
                  A[9] = i9
                  ans = check(A, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
ans = 0
s = max(int(b/a),e-1000)
e = min(n+1,b)
for i in range(s, e):
  x = (int(a*i/b)-a*int(i/b))
  if ans < x:
    ans = x
print(ans)