Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

X=list(map(int,input().split()))

result=1
for i in X:
  result*=i
  if result>10**18:
    result=-1
  
for i in X:
  if i==0:result=0

print(result)


Fixed submission:
N=int(input())

X=list(map(int,input().split()))

result=1
for i in X:
  result*=i
  if result>10**18:
    result=-1
    break
for i in X:
  if i==0:result=0

print(result)

Buggy python submission (verdict: Runtime Error):
X,Y=input().split()

N=int(input())
 
X=list(map(int,input().split()))
for i in X:
  if i==0:
    print(0)
    exit(0)

result=1
for i in X:
  result*=i
  if result>10**18:
    result=-1
    break
 
print(result)

Fixed submission:
N=int(input())

X=list(map(int,input().split()))

result=1
for i in X:
  result*=i
  if result>10**18:
    result=-1
    break
for i in X:
  if i==0:result=0

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

X=list(map(int,input().split()))

result=1
for i in X:
  result*=i
  
if result>10**18:
  result=-1

print(result)


Fixed submission:
N=int(input())

X=list(map(int,input().split()))

result=1
for i in X:
  result*=i
  if result>10**18:
    result=-1
    break
for i in X:
  if i==0:result=0

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

X=list(map(int,input().split()))
result=1
for i in X:
  result*=i

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

print(result)

Fixed submission:
N=int(input())

X=list(map(int,input().split()))

result=1
for i in X:
  result*=i
  if result>10**18:
    result=-1
    break
for i in X:
  if i==0:result=0

print(result)
Buggy python submission (verdict: Runtime Error):
X,Y=list(map(int,input().split()))

print(X*Y//1)


Fixed submission:
X,Y=input().split() 
Y=Y.replace(".","")
print(int(X)*int(Y)//100)

Buggy python submission (verdict: Runtime Error):
X,Y=input().split()

print(X*Y//1)

Fixed submission:
X,Y=input().split() 
Y=Y.replace(".","")
print(int(X)*int(Y)//100)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split(' '))

m=[[] for i in range(N)]

for i in range(M):
  x,y=map(int,input().split(' '))
  m[x-1].append(y-1)
  m[y-1].append(x-1)

sign=[0]
signed_map=[-1]*N
signed_map[0]=1
while True:
  signed=sign
  sign=[]
  for s in signed:
    for room in m[s]:#サインされた場所から繋がってるとこを回る
      if signed_map[room]==-1:
        signed_map[room]=s+1
        sign.append(room)
  if sign==[]:break

print('Yes')
for ch in signed_map[1:]:
  print(ch)


Fixed submission:
n=int(input())

if n%10==3:
  print('bon')
elif n%10==0 or n %10 == 1 or n%10 == 6 or n%10 == 8:
  print('pon')
else:
  print('hon')
Buggy python submission (verdict: Runtime Error):
N,M,X = map(int, input().split(' '))
C=[]
maxNum=999999999
dmaxNum=999999999
for i in range(N):
  C.append(map(int, input().split(' ')))

for i in range(2**(N+1)-1):
  ar=[]
  for i in range(M):
    if (i & 2**i) == 0:
      ar = [x * y for (x, y) in zip(ar, C[i])]
  print(ar)
  for i in ar:
    if i < X:
      break


Fixed submission:
import numpy as np

N,M,X = map(int, input().split(' '))
C=[]
maxNum=999999999
dmaxNum=999999999
for i in range(N):
  C.append(list(map(int, input().split(' '))))
for i in range(2**N):
  ar=[0]*(M+1)
  for j in range(N):
    if (i & 2**j) != 0:
      ar = [x + y for (x, y) in zip(ar, C[j])]
  if (np.array(ar[1:])>=X).all()>0:
    maxNum=min(maxNum,ar[0])
if maxNum==dmaxNum:
  print(-1)
else:
  print(maxNum)
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split(' '))

cache={}
log=[]
A = list(map(lambda x:int(x)-1, input().split(' ')))

now=0

while(True):
  log.append(now)
  now=A[now]
  if(cache.get(now)):break
  cache[now]=1

loop_start=log.index(now)
loop_end=len(log)
loop=loop_end-loop_start

#print(loop_end-loop_start,loop_start)

if len(log) >loop:
  if loop==0 and loop_start>K:
    print(now)
  else:
    print(log[K%loop]+1)
else:
  print(log[K%loop+loop]+1)

Fixed submission:
N,K = map(int, input().split(' '))

cache={}
log=[]
A = list(map(lambda x:int(x)-1, input().split(' ')))

now=0

while(True):
  log.append(now)
  cache[now]=1
  now=A[now]
  if(cache.get(now)):break

loop_start=log.index(now)
loop_end=len(log)
loop=loop_end-loop_start

if K<len(log):
  print(log[K]+1)
else:
  print(log[(K-loop_start)%loop+loop_start]+1)

Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split(' '))

cache={}
log=[]
A = list(map(lambda x:int(x)-1, input().split(' ')))

now=0

while(True):
  log.append(now)
  now=A[now]
  if(cache.get(now)):break
  cache[now]=1

loop_start=log.index(now)
loop_end=len(log)
loop=loop_end-loop_start

#print(loop_end-loop_start,loop_start)

if len(log) >loop:
  print(log[K%loop]+1)
else:
  print(log[K%loop+loop]+1)

Fixed submission:
N,K = map(int, input().split(' '))

cache={}
log=[]
A = list(map(lambda x:int(x)-1, input().split(' ')))

now=0

while(True):
  log.append(now)
  cache[now]=1
  now=A[now]
  if(cache.get(now)):break

loop_start=log.index(now)
loop_end=len(log)
loop=loop_end-loop_start

if K<len(log):
  print(log[K]+1)
else:
  print(log[(K-loop_start)%loop+loop_start]+1)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
v=100
count=0
while True:
  if N<v:
    break
  count+=1
  v*=1.01//1

Fixed submission:

N=int(input())
v=100
count=0

while True:
  if N<=v:
    break
  count+=1
  v*=1.01
  v=int(v)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
v=100
count=0
while True:
  if N<v:
    break
  count+=1
  v*1.01//1
  
print(count)

Fixed submission:

N=int(input())
v=100
count=0

while True:
  if N<=v:
    break
  count+=1
  v*=1.01
  v=int(v)
print(count)
Buggy python submission (verdict: Runtime Error):
A,B=input()
A=int(A)
B=int(B)

num=0
num+=A*(A-1)//2
num+=B*(B-1)//2
print(num)

Fixed submission:
A,B=input().split(' ')
A=int(A)
B=int(B)

num=0
num+=A*(A-1)//2
num+=B*(B-1)//2
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int,input().split())
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
dp=[0]*(10**8)
dp[0]=0
i=0

while True:
  i+=1
  for A,B in AB:
    if i-B>=0:
      dp[i]=max(dp[i-B]+A,dp[i])
  if dp[i]>=H:
    break
print(i)


Fixed submission:
H,N=map(int,input().split())
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
dp=[10**8]*(H+1)
dp[0]=0
i=0

for i in range(H+1):
  for A,B in AB:
    if i-A>=0:
      dp[i]=min(dp[i-A]+B,dp[i])
  for A,B in AB:
    if i+A>H:
      dp[-1]=min(dp[-1],dp[i]+B)
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
dp=[0]*(10**9)
dp[0]=0
i=0

while True:
  i+=1
  for A,B in AB:
    if i-B>=0:
      dp[i]=max(dp[i-B]+A,dp[i])
  if dp[i]>=H:
    break
print(i)


Fixed submission:
H,N=map(int,input().split())
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
dp=[10**8]*(H+1)
dp[0]=0
i=0

for i in range(H+1):
  for A,B in AB:
    if i-A>=0:
      dp[i]=min(dp[i-A]+B,dp[i])
  for A,B in AB:
    if i+A>H:
      dp[-1]=min(dp[-1],dp[i]+B)
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
INF=10**8
dp=[0]*(10**7)
dp[0]=0
i=0

while True:
  i+=1
  for A,B in AB:
    if i-B>=0:
      dp[i]=max(dp[i-B]+A,dp[i])
  if dp[i]>=H:
    break
print(i)

Fixed submission:
H,N=map(int,input().split())
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
dp=[10**8]*(H+1)
dp[0]=0
i=0

for i in range(H+1):
  for A,B in AB:
    if i-A>=0:
      dp[i]=min(dp[i-A]+B,dp[i])
  for A,B in AB:
    if i+A>H:
      dp[-1]=min(dp[-1],dp[i]+B)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
l=[0]*10

for i in range(1,N+1):
  if str(i[0])==str(i[-1]):
    l[int(str(i[0]))]+=1

ans=0
for i in range(l):
  ans+=i*i
print(ans)

Fixed submission:
N=int(input())
l=[[0]*10 for i in range(10)]


for i in range(1,N+1):
  l[int(str(i)[0])][int(str(i)[-1])]+=1

ans=0
for i in range(10):
  for j in range(10):
    ans+=l[i][j]*l[j][i]
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

l=[0]*60
for i in A:
  for j in range(60):
    if i&(1<<j):l[j]+=1
ans=0
for i in range(60):
  ans+=l[i]*(N-l[i])*(1<<i)
  ans%=10**9+7
print(ans)

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

l=[0]*60
for i in A:
  for j in range(60):
    if i&(1<<j):l[j]+=1
ans=0
for i in range(60):
  ans+=l[i]*(N-l[i])*(1<<i)
  ans%=10**9+7
print(ans)
Buggy python submission (verdict: Runtime Error):
X,Y=sorted(list(map(int,input().split())))
#移動方法を(i+1,j),(i,j+1)となるようにどうにかする
if (X-abs(Y-X))%3!=0:
  print(0)
  exit(0)
n=(X-abs(Y-X))//3
X=n+abs(Y-X)
Y=n

  
mod=10**9+7
a=1
for i in range(1,X+Y+1):
  a*=i
  a%=mod
b=1
for i in range(1,X+1):
  b*=i
  b%=mod
c=1
for i in range(1,Y+1):
  c*=i
  c%=mod
print(a*pow(b,-1,mod)*pow(c,-1,mod)%mod)


Fixed submission:
X,Y=sorted(list(map(int,input().split())))
#移動方法を(i+1,j),(i,j+1)となるようにどうにかする
if (X-abs(Y-X))%3!=0 or X*2<Y:
  print(0)
  exit(0)
n=(X-abs(Y-X))//3
X=n+abs(Y-X)
Y=n

  
mod=10**9+7
a=1
for i in range(1,X+Y+1):
  a*=i
  a%=mod
b=1
for i in range(1,X+1):
  b*=i
  b%=mod
c=1
for i in range(1,Y+1):
  c*=i
  c%=mod

print(a*pow(b,-1,mod)*pow(c,-1,mod)%mod)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
CB=[]
for i in range(M):
  B,C=map(int,input().split())
  CB.append([C,B])
CB.sort(reverse=True)

idx=0
for C,B in CB:
  for i in range(B):
    if A[idx]<C:
      A[idx]=C
      idx+=1
    else:
      break
print(sum(A))


Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
CB=[]
for i in range(M):
  B,C=map(int,input().split())
  CB.append([C,B])
CB.sort(reverse=True)

idx=0
for C,B in CB:
  for i in range(B):
    if not idx>=len(A) and A[idx]<C:
      A[idx]=C
      idx+=1
    else:
      break
print(sum(A))
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n=I()
    dp=[1 for i in range(n)]
    dp[0]=0
    dp[1]=0
    for i in range(3,n):
        for j in range(i-2):
            dp[i]=(dp[i]+dp[j])%mod
    #print(dp)
    print(dp[-1]%mod)
    

        
        
        
        
    
if __name__=="__main__":
    main()



Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n=I()
    dp=[1 for i in range(n)]
    dp[0]=0
    if n==1:
        print(0)
        sys.exit()
    dp[1]=0
    for i in range(3,n):
        for j in range(i-2):
            dp[i]=(dp[i]+dp[j])%mod
    #print(dp)
    print(dp[-1]%mod)
    

        
        
        
        
    
if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
per=LI()
for i in range(n):
    per[i]-=1
points=LI()
ans=-inf
for i in range(n):
    val=0
    #res=[0 for j in range(n+1)]
    res=[]
    pos=per[i]
    inipos=per[i]
    count=0
    while True:
        val+=points[pos]
        pos=per[pos]
        if len(res)==0:
            res.append(val)
        else:
            res.append(max(res[-1],val))
        #res[count]=max(val,res[count-1])
        count+=1
        if pos==inipos:
            break
    loop=(val,count)
    #print(loop)
    #print(res)
    for x in range(len(res)):
        if loop[0]<=0:
            ans=max(ans,res[x])
        else:
            ans=max(ans,res[x]+loop[0]*((k-x-1)//loop[1]))
print(ans)
        
        
        
        
        
        
    
    
    
        
        
        
        
        
            
            


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
per=LI()
for i in range(n):
    per[i]-=1
points=LI()
ans=-inf
for i in range(n):
    val=0
    #res=[0 for j in range(n+1)]
    res=[]
    pos=per[i]
    inipos=per[i]
    count=0
    while True:
        val+=points[pos]
        pos=per[pos]
        if len(res)==0:
            res.append(val)
        else:
            res.append(max(res[-1],val))
        #res[count]=max(val,res[count-1])
        count+=1
        if pos==inipos:
            break
    loop=(val,count)
    #print(loop)
    #print(res)
    for x in range(len(res)):
        if loop[0]<=0:
            ans=max(ans,res[x])
        else:
            ans=max(ans,res[x]+loop[0]*((k-x-1)//loop[1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()

n, q = map(int, input().split())
y = [[] for _ in range(2*10**5)] # i番目の幼稚園の(-rate, 幼児) #heap
data = [(0, 0)]*n # i番目の(rate, 所属) #list
import heapq
for i in range(n):
    a, b = map(int, input().split())
    data[i] = (a, b - 1)
    heapq.heappush(y[b - 1], (-a, i))
max_rate = [] # (rate, 幼児, 所属) #heap
max_rate_list = [()]*(2*10**5) #list
for i in range(2*10**5):
    if y[i]:
        s, t = heapq.heappop(y[i])
        heapq.heappush(max_rate, (-s, t, i))
        heapq.heappush(y[i], (s, t))
        max_rate_list[i] = (-s, t)
from collections import defaultdict
ng_num = defaultdict(set)
for _ in range(q):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    a, b = data[c]
    data[c] = (a, d)
    heapq.heappush(y[d], (-a, c))
    ng_num[b].add(c)
    if c in ng_num[d]:
        ng_num[d].discard(c)
    #print(ng_num)
    while y[b]:
        s, t = heapq.heappop(y[b])
        if t not in ng_num[b]:
            heapq.heappush(max_rate, (-s, t, b))
            heapq.heappush(y[b], (s, t))
            max_rate_list[b] = (-s, t)
            break
    while y[d]:
        s, t = heapq.heappop(y[d])
        if t not in ng_num[d]:
            heapq.heappush(max_rate, (-s, t, d))
            heapq.heappush(y[d], (s, t))
            max_rate_list[d] = (-s, t)
            break
    #print(max_rate)
    while max_rate:
        s, t, r = heapq.heappop(max_rate)
        if t not in ng_num[r] and (s, t) == max_rate_list[r]:#heapqの弱点(不要になった要素を楽に抜くことができない)をリストでカバーしている
            print(s)
            heapq.heappush(max_rate, (s, t, r))
            break
#popしてその要素を戻すという操作でキューの利便性は上がるということに注意
#どの情報を持てばいいのかをしっかり考えたい


Fixed submission:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

lis=LI()
for i in range(5):
    if lis[i]==0:
        print(i+1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m,q=MI()
strs=[[[] for i in range(m)] for i in range(n)]
for i in range(m):
    strs[0][i].append(str(i))
#print(strs)
for i in range(n-1):
    for j in range(m):
        for k in range(j,m):
            for s in strs[i][k]:
                strs[i+1][j].append(str(j)+s)
#print(strs)

L=strs[n-1]
#print(L)
lis=[]
for i in range(m):
    for s in L[i]:
        lis.append(s)
#print(lis)
mx=0
zyou=[LI() for i in range(q)]
for u in lis:
    po=0
    for k in range(q):
        a,b,c,d=zyou[k]
        if int(u[b-1])-int(u[a-1])==c:
            po+=d
    if po>mx:
        mx=po
print(mx)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m,q=MI()
strs=[[[] for i in range(m)] for i in range(n)]
for i in range(m):
    strs[0][i].append(str(i))
#print(strs)
for i in range(n-1):
    for j in range(m):
        for k in range(j,m):
            for s in strs[i][k]:
                strs[i+1][j].append(str(j)+s)
#print(strs)

L=strs[n-1]
#print(L)
lis=[]
for i in range(m):
    for s in L[i]:
        lis.append(s)
#print(lis)
mx=0
zyou=[LI() for i in range(q)]
for u in lis:
    po=0
    for k in range(q):
        a,b,c,d=zyou[k]
        if int(u[b-1])-int(u[a-1])==c:
            po+=d
    if po>mx:
        mx=po
print(mx)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m,q=MI()
strs=[[[] for i in range(m)] for i in range(n)]
for i in range(m):
    strs[0][i].append(str(i))
#print(strs)
for i in range(n-1):
    for j in range(m):
        for k in range(j,m):
            for s in strs[i][k]:
                strs[i+1][j].append(str(j)+s)
#print(strs)

L=strs[n-1]
#print(L)
lis=[]
for i in range(m):
    for s in L[i]:
        lis.append(s)
#print(lis)
mx=0
zyou=[LI() for i in range(q)]
for u in lis:
    po=0
    for k in range(q):
        a,b,c,d=zyou[k]
        if int(u[b-1])-int(u[a-1])==c:
            po+=d
    if po>mx:
        mx=po
print(mx)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

a,b,n=MI()
s=min(n,b-1)
ans=floor(a*s/b)-a*floor(s/b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import *
nxy=input().rstrip().split(" ")
n=int(nxy[0])
x=int(nxy[1])
y=int(nxy[2])
dis=[]
for i in range(1,n):
    #print(i)
    j=i+1
    while j>i and j<=n:
        l1=abs(x-i)+1+abs(y-j)
        l2=j-i
        if l1>=l2:
            L=l2
        else:
            L=l1
        #print(L)
        dis.append(L)
        j=j+1
#print(dis)
for k in range(1,n):
    print(dis.count(k))

Fixed submission:
import collections 
nxy=input().rstrip().split(" ")
n=int(nxy[0])
x=int(nxy[1])
y=int(nxy[2])
dis=[]
for i in range(1,n):
    #print(i)
    j=i+1
    while j>i and j<=n:
        l1=abs(x-i)+1+abs(y-j)
        l2=j-i
        if l1>=l2:
            L=l2
        else:
            L=l1
        #print(L)
        dis.append(L)
        j=j+1
#print(dis)
c=collections.Counter(dis)
#print(c)
for k in range(1,n):
    print(c[k])