Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque
n,m=map(int,input().split())
g=[[] for i in range(1+n)]
v=[0]*(1+n)
for i in range(m):
    if i==1:
        q=[a,b]
        v[a]=v[b]=1
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)

p=[q[-1]]
path=[]
while p:
    cur=p.pop()
    path.append(cur)
    v[cur]=1
    flg=True
    for i in g[cur]:
        if v[i]==0:
            p.append(i)
            flg=False
    if flg:
        break
ans=path

p=[q[0]]
path=[]
while p:
    cur=p.pop()
    path.append(cur)
    v[cur]=1
    flg=True
    for i in g[cur]:
        if v[i]==0:
            p.append(i)
            flg=False
    if flg:
        break
ans=path[::-1]+ans
print(len(ans))
print(*ans)

Fixed submission:
from collections import deque
n,m=map(int,input().split())
g=[[] for i in range(1+n)]
v=[0]*(1+n)
for i in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
    if i==0:
        q=[a,b]
        v[a]=v[b]=1

p=[q[-1]]
path=[]
while p:
    cur=p.pop()
    path.append(cur)
    v[cur]=1
    flg=True
    for i in g[cur]:
        if v[i]==0:
            p.append(i)
            flg=False
    if flg:
        break
ans=path

p=[q[0]]
path=[]
while p:
    cur=p.pop()
    path.append(cur)
    v[cur]=1
    flg=True
    for i in g[cur]:
        if v[i]==0:
            p.append(i)
            flg=False
    if flg:
        break
ans=path[::-1]+ans
print(len(ans))
print(*ans)

Buggy python submission (verdict: Runtime Error):
from collections import deque
n,m=map(int,input().split())
g=[[] for i in range(1+n)]
v=[0]*(1+n)
for i in range(m):
    if i==1:
        q=[a,b]
        v[a]=v[b]=1
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)

p=deque(q[-1:])
path=[]
while p:
    cur=p.pop()
    path.append(cur)
    v[cur]=1
    flg=True
    for i in g[cur]:
        if v[i]==0:
            p.append(i)
            flg=False
    if flg:
        break
ans=path

p=deque(q[0:1])
path=[]
while p:
    cur=p.pop()
    path.append(cur)
    v[cur]=1
    flg=True
    for i in g[cur]:
        if v[i]==0:
            p.append(i)
            flg=False
    if flg:
        break
ans=path[::-1]+ans
print(len(ans))
print(*ans)

Fixed submission:
from collections import deque
n,m=map(int,input().split())
g=[[] for i in range(1+n)]
v=[0]*(1+n)
for i in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
    if i==0:
        q=[a,b]
        v[a]=v[b]=1

p=[q[-1]]
path=[]
while p:
    cur=p.pop()
    path.append(cur)
    v[cur]=1
    flg=True
    for i in g[cur]:
        if v[i]==0:
            p.append(i)
            flg=False
    if flg:
        break
ans=path

p=[q[0]]
path=[]
while p:
    cur=p.pop()
    path.append(cur)
    v[cur]=1
    flg=True
    for i in g[cur]:
        if v[i]==0:
            p.append(i)
            flg=False
    if flg:
        break
ans=path[::-1]+ans
print(len(ans))
print(*ans)
Buggy python submission (verdict: Runtime Error):
mo=10**9+7
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
X,Y=0,0
for i in range(n):
    X+=x[i]*(n-2*i-1)
    X%=mo
for i in range(n):
    Y+=y[i]*(n-2*i-1)
    Y%=mo
print(X*Y%mo)

Fixed submission:
mo=10**9+7
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
X,Y=0,0
for i in range(n):
    X+=x[i]*(n-2*i-1)
    X%=mo
for i in range(m):
    Y+=y[i]*(m-2*i-1)
    Y%=mo
print(X*Y%mo)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a)[::-1]
print(sum[1:2*n:2])

Fixed submission:
n=int(input())
a=sorted([int(i) for i in input().split()])[::-1]
print(sum(a[1:2*n:2]))

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(i) in input().split()]
a=sorted(a)[::-1]
print(sum[1:2*n:2])

Fixed submission:
n=int(input())
a=sorted([int(i) for i in input().split()])[::-1]
print(sum(a[1:2*n:2]))

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(i) in input().split()]
a=a.sort()[::-1]
print(sum[1:2*n:2])

Fixed submission:
n=int(input())
a=sorted([int(i) for i in input().split()])[::-1]
print(sum(a[1:2*n:2]))

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(i) in input().split()]
a.sort()[::-1]
print(sum[1:2*n:2])

Fixed submission:
n=int(input())
a=sorted([int(i) for i in input().split()])[::-1]
print(sum(a[1:2*n:2]))
Buggy python submission (verdict: Runtime Error):
x=int(input())
for i in range(x**0.5+100):
  if i*(i+1)//2>=x:
    print(i)
    break

Fixed submission:
x=int(input())
for i in range(int(2*x**0.5)+100):
  if i*(i+1)//2>=x:
    print(i)
    break
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=sum([int(i) for i in input().split()]

print('YES' if a%2==0 else 'NO')

Fixed submission:
n=int(input())
a=sum([int(i) for i in input().split()])

print('YES' if a%2==0 else 'NO')
Buggy python submission (verdict: Runtime Error):
#n,a,b,c,d=map(int,input().split())
n=int(input())
a=[int(i) for i in input().split()]
ans=False
c=[]

t=sum(a)//((n*(n+1))//2)

if sum(a)%((n*(n+1))//2)!=0:
    ans=False
else:
    for i in range(n):
        if i==0:
            d=a[0]-a[-1]
        else:
            d=a[i]-a[i-1]
        if (t-d)%n!=0:
            ans=False
            break
        s=(t-d)//n
        c.append(s)
    if sum(c)==t:
        #ans=True
if n==1:
    ans=True
print('YES' if ans else 'NO')

Fixed submission:
#n,a,b,c,d=map(int,input().split())
n=int(input())
a=[int(i) for i in input().split()]
ans=True
c=[]

t=sum(a)//((n*(n+1))//2)

if sum(a)%((n*(n+1))//2)!=0:
    ans=False
else:
    for i in range(n):
        if i==0:
            d=a[0]-a[-1]
        else:
            d=a[i]-a[i-1]
        if (t-d)%n!=0 or d-t>0:
            ans=False
            break
        s=(t-d)//n
        c.append(s)
    #if sum(c)==t:
        #ans=True
if n==1:
    ans=True
print('YES' if ans else 'NO')

Buggy python submission (verdict: Runtime Error):
#n,a,b,c,d=map(int,input().split())
n=int(input())
a=[int(i) for i in input().split()]
ans=False
c=[]

t=sum(a)//((n*(n+1))//2)

if sum(a)%((n*(n+1))//2)!=0:
    ans=False
else:
    if n==1:
        ans=True
        break
    for i in range(n):
        if i==0:
            d=a[0]-a[-1]
        else:
            d=a[i]-a[i-1]
        if (t-d)%n!=0:
            ans=False
            break
        s=(t-d)//n
        c.append(s)
    if sum(c)==t:
        ans=True
print('YES' if ans else 'NO')

Fixed submission:
#n,a,b,c,d=map(int,input().split())
n=int(input())
a=[int(i) for i in input().split()]
ans=True
c=[]

t=sum(a)//((n*(n+1))//2)

if sum(a)%((n*(n+1))//2)!=0:
    ans=False
else:
    for i in range(n):
        if i==0:
            d=a[0]-a[-1]
        else:
            d=a[i]-a[i-1]
        if (t-d)%n!=0 or d-t>0:
            ans=False
            break
        s=(t-d)//n
        c.append(s)
    #if sum(c)==t:
        #ans=True
if n==1:
    ans=True
print('YES' if ans else 'NO')
Buggy python submission (verdict: Runtime Error):
print('A'+'RB'[input()[:2]<’12’]+'C')

Fixed submission:
print('A'+'RB'[int(input())<1200]+'C')
Buggy python submission (verdict: Runtime Error):
s=input()
x=1e9
for i in range(len(s)):
 if i=='A':x=min(x,i)
 if i=='Z':y=i
print(y-x+1)

Fixed submission:
x=1e9
for j,i in enumerate(input()):
 if i=='A':x=min(x,j)
 if i=='Z':y=j
print(y-x+1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=(n//11)*2
ans+=2 if n-n//11>6 else 1
ans-=1 if n-n//11=0 else 0
print(ans)

Fixed submission:
n=int(input())
ans=(n//11)*2
ans+=2 if n-11*(n//11)>6 else 1
ans-=1 if n-11*(n//11)==0 else 0
print(ans)
Buggy python submission (verdict: Runtime Error):
,t=open(0)
a=[0]
for i in t:a+=a[-1]+1-2*(i=='D'),
print(max(a))


Fixed submission:
input()
x=0
a=[0]
for i in input():a+=a[-1]+1-2*(i=='D'),
print(max(a))

Buggy python submission (verdict: Runtime Error):
input()
x=0
a=[0]
for i in input():a+=a[-1]+1-2*(i=='D')
print(a)

Fixed submission:
input()
x=0
a=[0]
for i in input():a+=a[-1]+1-2*(i=='D'),
print(max(a))
Buggy python submission (verdict: Runtime Error):
I=input;I();t=[int(i)for i in I().S()]
for i in' '*int(input()):p,x=map(int,I().split());print(sum(t)+x-t[p-1])

Fixed submission:
I=input
I()
t=[int(i)for i in I().split()]
for i in' '*int(input()):p,x=map(int,I().split());print(sum(t)+x-t[p-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
t=[int(i)for i in input().split()]
m=int(input())
T=sum(t)
for i in' '*m:p,x=LI();print(T+x-t[p-1])

Fixed submission:
I=input
I()
t=[int(i)for i in I().split()]
for i in' '*int(input()):p,x=map(int,I().split());print(sum(t)+x-t[p-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
a=['dream','dreamer','erase','eraser']
a=list(map(lambda x:x[::-1],a))
def check(c):
    if c=='':
        return True
    rt=False
    size=len(c)
    for i in a:
        if size>=len(i) and c[-len(i):]==i:
            rt=check(c[:-len(i)]) or rt
    return rt

print('YES' if check(input()[::-1]) else 'NO')


Fixed submission:
a=['dream','dreamer','erase','eraser']
def check(c):
    if c=='':
        return True
    size=len(c)
    n=len(c)
    while n>0:
        tmp=n
        for i in a:
            #print(-n-len(i),-n)
            if size>=len(i) and c[n-len(i):n]==i:
                n-=len(i)
        if tmp==n:
            return False
    return True

print('YES' if check(input()) else 'NO')

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
a=['dream','dreamer','erase','eraser']
def check(c):
    rt=False
    size=len(c)
    if c=='':
        return True
    for i in a:
        if size>=len(i) and c[:len(i)]==i:
            rt=check(c[len(i):]) or rt
    return rt

print('YES' if check(input()) else 'NO')

Fixed submission:
a=['dream','dreamer','erase','eraser']
def check(c):
    if c=='':
        return True
    size=len(c)
    n=len(c)
    while n>0:
        tmp=n
        for i in a:
            #print(-n-len(i),-n)
            if size>=len(i) and c[n-len(i):n]==i:
                n-=len(i)
        if tmp==n:
            return False
    return True

print('YES' if check(input()) else 'NO')

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
a=['dream','dreamer','erase','eraser']
def check(c):
    rt=False
    size=len(c)
    if c=='':
        return True
    for i in a:
        if size>=len(i) and c[:len(i)]==i:
            rt=check(c[len(i):]) or rt
    return rt

print(cnt,'YES' if check(s) else 'NO', s)

Fixed submission:
a=['dream','dreamer','erase','eraser']
def check(c):
    if c=='':
        return True
    size=len(c)
    n=len(c)
    while n>0:
        tmp=n
        for i in a:
            #print(-n-len(i),-n)
            if size>=len(i) and c[n-len(i):n]==i:
                n-=len(i)
        if tmp==n:
            return False
    return True

print('YES' if check(input()) else 'NO')
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
x,y=abs(a-c),abs(b-d)
g=math.gcd(x,y)
print(g*(x//g+y//d-1))


Fixed submission:
def gcd(x,y):
    if x%y==0:
        return y
    while x%y>0:
        x,y=y,x%y
    return y
a,b,c,d=map(int,input().split())
x,y=abs(a-c),abs(b-d)
g=gcd(x,y)
print(g*(x//g+y//g-1))

Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
x,y=abs(a-c),abs(b-d)
g=math.gcd(x,y)
print(g*(x//g+y//d-1))

Fixed submission:
def gcd(x,y):
    if x%y==0:
        return y
    while x%y>0:
        x,y=y,x%y
    return y
a,b,c,d=map(int,input().split())
x,y=abs(a-c),abs(b-d)
g=gcd(x,y)
print(g*(x//g+y//g-1))
Buggy python submission (verdict: Runtime Error):
n=int(input())
for i in range((2*n)**0.5-3,n**0.5+2):
  if i*(i+1)//2=n:
    for j in range(1,i+1):
      print(j)
    break
  elif i*(i+1)//2>n:
    k=i*(i+1)//2-n
    for j in range(1,i+1):
      ifr j!=k:
        print(j)
    break

Fixed submission:
n=int(input())
for i in range(int((2*n)**0.5-3),n+2):
  if i*(i+1)//2==n:
    for j in range(1,i+1):
      print(j)
    break
  elif i*(i+1)//2>n:
    k=i*(i+1)//2-n
    for j in range(1,i+1):
      if j!=k:
        print(j)
    break
Buggy python submission (verdict: Runtime Error):
s=str(input())
ans=0
for i in range(len(s)-1):
  if s[i]<>[i+1]:
    ans+=1
print(ans)

Fixed submission:
s=str(input())
ans=0
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
n=int(input())
p=[0]*(n+2)
c=1
for i in input().split():
    p[int(i)]=c
    c+=1

q=[0,n+1]

for i in range(1,n+1):
    l=bisect.bisect(q,a)
    r=l+1
    print()

print(p)


Fixed submission:
s=input()
q=[]
cnt=0
for i in s:
    if i=='S':
        q.append('S')
    else:  # t
        if q:
            q.pop()
            cnt+=2
print(len(s)-cnt)
Buggy python submission (verdict: Runtime Error):
s=set(input())
ans='No'
if s in (set('SN'), set('EW'), set('NEWS')):
  ans='Yes'
peint(ans)

Fixed submission:
s=set(input())
ans='No'
if s in (set('SN'), set('EW'), set('NEWS')):
  ans='Yes'
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
tmp, ans=0,0
for i in range(n):
  a=int(input())
  if a=0:
    ans+=tmp//2
    tmp=0
  else:
    tmp+=a
print(ans)


Fixed submission:
n=int(input())
tmp, ans=0,0
for i in range(n):
  a=int(input())
  if a==0:
    ans+=tmp//2
    tmp=0
  else:
    tmp+=a
print(ans+tmp//2)
Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
#show_flg=True


n,X,Y,Z=MI()

pt=[[0]*11 for _ in range(11)]

for m in range(1,8):
    if m==1:
        for a in range(1,11):pt[m][a]=1
        continue
    for a in range(1,8):
        an=0
        for i in range(1,11):
            if a-i>=0:an+=pt[m-1][a-i]
        pt[m][a]=an
    
def cnt(m,a):
    if m==1:
        pt[1][a]=1
        return a
    if pt[m][a]!=-1:
        return pt[m][a]
    rt=0
    for i in range(1,11):
        if a-i<=0:
            break
        rt+=cnt(m-1,a-i)
    pt[m][a]=rt
    return rt

ans=0
for x in range(n+1):
    for y in range(x+1,n+1):
        for z in range(y+1,n+1):
            for w in range(z+1,n+1):
                p=1
                p*=pt[y-x][X]
                p*=pt[z-y][Y]
                p*=pt[w-z][Z]
                ans+=p*pow(10,n-(w-x),mo)
                show(x,y,z,w,p)

print(ans%mo)

Fixed submission:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
#show_flg=True

n,X,Y,Z=MI()
t=1<<(X+Y+Z)
haiku=( (1<<(X+Y+Z)) + (1<<(Y+Z)) + (1<<Z) )>>1
dp=[0]*t
dp[0]=1


for i in range(n):
    tm=[i for i in dp]
    dp=[0]*t
    for k in range(t):
        for d in range(10):
            m=((k<<(d+1))+(1<<d))
            if m&haiku == haiku:
                continue
            else:
                dp[int(m)%t]+=tm[k]
                dp[int(m)%t]%=mo
sub=0
for i in range(t):
    sub+=dp[i]
ans=pow(10,n,mo)-sub
print(ans%mo)

show(ans,sub)
show(dp)
show(n,t,n*t*10)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
n = int(input())
A = list(map(int,input().split()))
#素朴な解法(むり)
ans = 0
for i in range(n):
    flg=False
    for j in range(n):
        if i!=j and A[i]%A[j]==0:
            flg=True
    if not flg:
        ans += 1
print(ans)

Fixed submission:
# coding: utf-8
n = int(input())
A = list(map(int,input().split()))
a_ = max(A)
A_ = list(set(A))
dp = [True] * (a_+1)
C = [0] * (a_+1)
for a in A:
    C[a]+=1
A_.sort()
ans = 0

for a in A_:
    tmp = a
    if dp[tmp]:
        tmp += a
        while tmp <= a_:
            dp[tmp] = False
            tmp += a
#print(dp)
for a in A_:
    if dp[a]:
        if C[a]==1:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#coding; utf-8
import copy
N, k = map(int,input().split())
A = list(map(int,input().split()))
B = [0] * N
A = [0] + A
#B = copy.copy(A)
for j in range(k):
    #print(A)
    n_light = [0] * (N+1)
    for i in range(N):
        d = A[i+1]
        l = i+1-d
        r = i+1+d
        #print(l, r)
        n_light[max(l, 1)] += 1
        if r+1 <= N:# and l != r:
            n_light[r+1] -= 1
        #print(n_light)
    #print(n_light)
    for i in range(1,N):
        n_light[i+1] += n_light[i]
    n_str = [str(i) for i in n_light]
    A = n_light 
print(' '.join(n_str[1:]))
    


Fixed submission:
#coding; utf-8
import copy
N, k = map(int,input().split())
A = list(map(int,input().split()))
B = [0] * N
A = [0] + A
#B = copy.copy(A)
#k = 10
for j in range(k):
    #print(A)
    n_light = [0] * (N+1)
    for i in range(N):
        d = A[i+1]
        l = i+1-d
        r = i+1+d
        #print(l, r)
        n_light[max(l, 1)] += 1
        if r+1 <= N:# and l != r:
            n_light[r+1] -= 1
        #print(n_light)
    #print(n_light)
    for i in range(1,N):
        n_light[i+1] += n_light[i]
    n_str = [str(i) for i in n_light]
    if len(set(n_light[1:])) == 1 and j > 2:
        #print(n_light)
        break
    #n_str = [str(i) for i in n_light]
    A = n_light
    #print(n_light) 
print(' '.join(n_str[1:]))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

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

ans = 1
for i in range(N):
    ans *= A[i]

if ans > 10**18:
    ans = -1

print(ans)


Fixed submission:
# coding: utf-8

N = int(input())
A = sorted(list(map(int,input().split())))
if A[0] == 0:
    ans = 0
else:
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            ans = -1
            break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

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

ans = 1
for i in range(N):
    ans *= A[i]

if ans > 10**18:
    ans = -1

print(ans)

Fixed submission:
# coding: utf-8

N = int(input())
A = sorted(list(map(int,input().split())))
if A[0] == 0:
    ans = 0
else:
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            ans = -1
            break

print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
#C
a, b = map(float,input().split())
a = int(a)
b = int(b*100)

ans = a * b

ans = int(str(ans)[:-2])
print(ans)

Fixed submission:
# coding: utf-8

a, b = map(str,input().split())

a = int(a)
b = b.replace('.', '')
#print(b)
b = int(b)
print(a*b//100)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

x = int(input())
for i in range(-100, 100):
    for j in range(i,1000):
        #print(j**5-i**5)
        if j**5-i**5 == x:
            ans = [j,i]
            break

print(ans)

Fixed submission:
# coding: utf-8

x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

D = make_divisors(x)
for i in D:
    for j in range(-10000,10000):
        k = j +  i
        if k**5 - j**5 == x:
            a, b = k, j
            break

print(a,b)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import itertools
N, M, Q = map(int,input().split())
L = list(itertools.combinations_with_replacement(range(1, M + 1), N))
D = []
for i in range(Q):
    D.append(list(map(int,input().split())))

#print(L)
#全てのA

ans = 0
for A in L:
    tmp = 0
    for i in range(Q):
        a = D[i][0]
        b = D[i][1]
        c = D[i][2]
        d = D[i][3]
        if A[b-1] - A[a-1] == c:
            tmp += d
        
        ans = max(ans,tmp)

print(ans)

Fixed submission:
# coding: utf-8
import itertools
N, M, Q = map(int,input().split())
L = list(itertools.combinations_with_replacement(range(1, M + 1), N))
D = []
for i in range(Q):
    D.append(list(map(int,input().split())))

#print(l)
#全てのA

ans = 0
for A in L:
    tmp = 0
    for i in range(Q):
        a = D[i][0]
        b = D[i][1]
        c = D[i][2]
        d = D[i][3]
        if A[b-1] - A[a-1] == c:
            tmp += d
        
        ans = max(ans,tmp)

print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8

N, M, Q = map(int,input().split())
L = []
A = [1] * N
ans = 0

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

L.sort(key=lambda x:x[3])

for i in range(Q):
    a=L[i][0]
    b=L[i][1]
    c=L[i][2]
    d=L[i][3]
    if A[b-1] <= A[a-1] + c <= M:
        ans += d
        #print(ans)
        A[b-1:] = [A[a-1] + c] * (N-A[a-1]+c-1)
print(ans)

Fixed submission:
# coding: utf-8
import itertools
N, M, Q = map(int,input().split())
L = list(itertools.combinations_with_replacement(range(1, M + 1), N))
D = []
for i in range(Q):
    D.append(list(map(int,input().split())))

#print(l)
#全てのA

ans = 0
for A in L:
    tmp = 0
    for i in range(Q):
        a = D[i][0]
        b = D[i][1]
        c = D[i][2]
        d = D[i][3]
        if A[b-1] - A[a-1] == c:
            tmp += d
        
        ans = max(ans,tmp)

print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8

N, M, Q = map(int,input().split())
L = []
A = [1] * N
ans = 0

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

L.sort(key=lambda x:x[3])

for i in range(Q):
    a=L[i][0]
    b=L[i][1]
    c=L[i][2]
    d=L[i][3]
    if A[b-1] <= A[a-1] + c <= M:
        ans += d
        #print(ans)
        A[b-1:] = [A[a-1] + c] * (N-A[a-1]+c-1)
print(ans)

Fixed submission:
# coding: utf-8
import itertools
N, M, Q = map(int,input().split())
L = list(itertools.combinations_with_replacement(range(1, M + 1), N))
D = []
for i in range(Q):
    D.append(list(map(int,input().split())))

#print(l)
#全てのA

ans = 0
for A in L:
    tmp = 0
    for i in range(Q):
        a = D[i][0]
        b = D[i][1]
        c = D[i][2]
        d = D[i][3]
        if A[b-1] - A[a-1] == c:
            tmp += d
        
        ans = max(ans,tmp)

print(ans)