Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03645 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**9)

def dfs(now,prev,count):
    # 今いる頂点から行ける頂点を順に next に入れてループ
    count+=1
    for next in g[now]:
        if count<=2:
            if next != prev:
                if next== n-1:
                    if count==2:
                        print('POSSIBLE')
                        exit()
                    else:
                        break
                dfs(next,now,count)
 
n, m = map(int, input().split())
g = [[] * n for i in range(n)]
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
dfs(0,-1,0)
print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
def dfs(now,prev,count):
    global flag
    flag=False
    # 今いる頂点から行ける頂点を順に next に入れてループ
    count+=1
    for next in g[now]:
        if next != prev:
            if next== n-1:
                if count==2:
                    flag=True
                    break
                else:
                    break
            dfs(next, now,count)
 
n, m = map(int, input().split())
g = [[] * n for i in range(n)]
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
dfs(0,-1,0)
if flag:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
def dfs(now,prev,count):
    global flag
    flag=False
    # 今いる頂点から行ける頂点を順に next に入れてループ
    count+=1
    for next in g[now]:
        if next != prev:
            if next== n-1:
                if count==2:
                    flag=True
                    break
                else:
                    break
            dfs(next, now,count)
 
n, m = map(int, input().split())
g = [[] * n for i in range(n)]
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
dfs(0,-1,0)
if flag:
    print('POSSIBBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
def dfs(now,prev,count):
    global flag
    flag=False
    # 今いる頂点から行ける頂点を順に next に入れてループ
    count+=1
    for next in g[now]:
        if next != prev:
            if next== n-1:
                if count==2:
                    flag=True
                    break
                else:
                    break
            dfs(next, now,count)
 
n, m = map(int, input().split())
g = [[] * n for i in range(n)]
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
dfs(0,0,0)
if flag:
    print('POSIBBLE')
else:
    print('IMPOSSIBLE')
Problem p02743 (python)

Fixed submission:
from decimal import *
import math


a, b, c = map(int, input().split())
a = Decimal(a)
b = Decimal(b)
c = Decimal(c)

a = Decimal.sqrt(a)
b = Decimal.sqrt(b)
c = Decimal.sqrt(c)

if a + b < c:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from decimal import *
 import math
 
 getcontext().prec = 10000
 
 a, b, c = map(int, input().split())
 a = Decimal(a)
 b = Decimal(b)
 c = Decimal(c)
 
 a = Decimal.sqrt(a)
 b = Decimal.sqrt(b)
 c = Decimal.sqrt(c)
 
 print(a, a * a)
 
 if a + b < c:
     print("Yes")
 else:
     print("No")
Problem p03210 (python)

Fixed submission:
print('YES' if int(input()) in [3,5,7] else 'NO')

Buggy submission (verdict: Runtime Error):
a=int(input())
b=0;
if a==3:
  b=1
elif a==5:
  b=1:
elif a==7:
  b=1:
if b==1:
  print("YES")
else:
  print("NO")
Problem p03671 (python)

Fixed submission:
a,b,c=map(int,input().split())
print(min(a+b,a+c,b+c))

Buggy submission (verdict: Runtime Error):
a=gets.split.map &:to_i
print(a.sum-a.max)
Problem p03759 (python)

Fixed submission:
a,b,c=map(int,input().split())
if b-a==c-b:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
if b-a==c-b:
  print("YES")
else:
  print("NO")
Problem p02811 (python)

Fixed submission:
k,x=map(int, input().split())

if 500*k >= x:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
k,x=map(int, input()split())

if 500*k >= x:
    print('Yes')
else:
    print('No')
Problem p02817 (python)

Fixed submission:
s,t = map(str, input().split())

print(t + s)

Buggy submission (verdict: Runtime Error):
s,t = map(input().split())

print(t + s)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

print(t + s)
Problem p02999 (python)

Fixed submission:
x,a = map(int, input().split())

if x < a:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):
x,a = map(int, input().split())

if x < a:
    print(0)
else
    print(10)
Problem p03289 (python)

Fixed submission:
s = input()

if s[0] != 'A':
        print('WA')
        exit()

if s[2:-1].count('C') != 1:
        print('WA')
        exit()

s = s.replace('C',"")

if s[1:].islower():
        print('AC')
else:
        print('WA')

Buggy submission (verdict: Runtime Error):
s = input()

if s[0] != 'A':
        print('WA')
        exit()

if s[2:-1].count('C') != 1:
        print('WA')
        exit()

s = s.replace('C',"")

if s[1:].isLower():
        print('AC')
else:
        print('WA')
Problem p03697 (python)

Fixed submission:
a,b = map(int,input().split())

s = 'error'

if a+ b < 10:
        s = a+b

print(s)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

s = 'error'

if a+ b < 10:
        s = a+b

print(s)
Problem p02537 (python)

Fixed submission:
n,k=map(int,input().split())

class SegmentTree:
    def __init__(self,n,ele):

        self.ide_ele = ele

        self.num =2**(n-1).bit_length()
        self.seg=[self.ide_ele]*2*self.num


    #####segfunc######
    #クエリに応じて変える
    def segfunc(self,x,y):
        return max(x,y)

    def init(self,init_val):
        #set_val
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        #built
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self,k,x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self,p,q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

st=SegmentTree(300001,0)
dp=[0]*n
for i in range(n):
    a=int(input())
    dp[i]=max(dp[i],st.query(max(0,a-k),min(300000,a+k)+1)+1)
    st.update(a,dp[i])
    dp[i]=max(dp[i],st.query(0,300001))
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())

class SegmentTree:
    def __init__(self,n,ele):

        self.ide_ele = ele

        self.num =2**(n-1).bit_length()
        self.seg=[self.ide_ele]*2*self.num


    #####segfunc######
    #クエリに応じて変える
    def segfunc(self,x,y):
        return max(x,y)

    def init(self,init_val):
        #set_val
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        #built
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self,k,x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self,p,q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

st=SegmentTree(300001,0)
dp=[0]*n
for i in range(n):
    a=int(input())
    dp[i]=max(dp[i],st.query(a-k,a+k+1)+1)
    st.update(a,dp[i])
    dp[i]=max(dp[i],st.query(0,300001))
print(dp[n-1])
Problem p02585 (python)

Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=-10**18
flag=dict()
for i in range(n):
    if i in flag:
        continue
    cur=i
    accum=[]
    flag[cur]=0
    s=0
    while flag[cur]<2:
        cur=p[cur]-1
        s+=c[cur]
        accum.append(s)
        if cur not in flag:
            flag[cur]=0
        else:
            flag[cur]+=1
    l=len(accum)//2
    accum=[0]+accum
    #print(accum)
    for x in range(1,l+1):
        if accum[x+l-1]-accum[x-1]<=0 or k//l<1:
            ans=max(ans,max(accum[x:x+min(k,l)])-accum[x-1])
        else:
            a=max(accum[x:x+l-1])-accum[x-1]
            d=accum[x+l-1]-accum[x-1]
            if k%l!=0:
                b=max(accum[x:x+k%l])-accum[x-1]
                ans=max(ans,max(k//l*d,k//l*d+b,(k//l-1)*d+a))
            else:
                b=max(accum[x:x+l-1])-accum[x-1]
                ans=max(ans,max(k//l*d,(k//l-1)*d+a))
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=-10**18
flag=dict()
for i in range(n):
    if i in flag:
        continue
    cur=i
    accum=[]
    flag[cur]=0
    s=0
    while flag[cur]<2:
        cur=p[cur]-1
        s+=c[cur]
        accum.append(s)
        if cur not in flag:
            flag[cur]=0
        else:
            flag[cur]+=1
    l=len(accum)//2
    accum=[0]+accum
    for x in range(1,l+1):
        if accum[x+l-1]-accum[x-1]<=0:
            ans=max(ans,max(accum[x:x+min(k,l)])-accum[x-1])
        else:
            a=max(accum[x:x+l])-accum[x-1]
            b=max(accum[x:x+k%l])-accum[x-1]
            d=accum[x+l-1]-accum[x-1]
            ans=max(ans,max(k//l*d+b,max(k//l-1,0)*d+a))
print(ans)
Problem p02586 (python)

Fixed submission:
import sys
input=sys.stdin.readline
def main():
    r,c,k=map(int,input().split())
    v=[[0]*c for _ in range(r)]
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if v[0][0]>0:
        dp[1][0][0]=v[0][0]
    for i in range(r):
        for j in range(c):
            for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans)
if __name__=="__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
def main():
    r,c,k=map(int,input().split())
    v=dict()
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[(ri,ci)]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if (0,0) in v:
        if v[(0,0)]>0:
            dp[0][0][1]=v[(0,0)]
    for i in range(r):
        for j in range(c):
            if i>0:
                if (i,j) in v:
                    if v[(i,j)]>0:
                        for k in range(min(3,j+1)+1):
                            dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[(i,j)])
                for k in range(4):
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i-1][j])
            if j>0:
                if (i,j) in v:
                    if v[(i,j)]>0:
                        for k in range(min(3,j+1)+1):
                            if k>0:
                                dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[(i,j)])
                for k in range(4):
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans)
if __name__=="__main__":
    main()
Problem p02616 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
ans=1
if n==k or max(a)<0 or min(a)>=0:
    if max(a)<0 and k%2==0:
        a.sort()
    else:
        a.sort(reverse=True)
    for i in range(k):
        ans*=a[i]
        ans%=mod
    print(ans)
    exit()
pos,neg=[],[]
for num in a:
    if num<0:
        neg.append(-num)
    else:
        pos.append(num)
neg.sort(reverse=True)
pos.sort(reverse=True)
nn=len(neg)
np=len(pos)
cand=[]
i,j=0,0
while k>0:
    if i<np-1 and j<nn-1:
        if k>=2:
            if pos[i+1]*pos[i]<neg[j+1]*neg[j]:
                cand.append(-neg[j+1])
                cand.append(-neg[j])
                k-=2
                j+=2
            else:
                cand.append(pos[i])
                k-=1
                i+=1
        else:
            cand.append(pos[i])
            k-=1
            i+=1
    elif j>=nn-1:
        cand.append(pos[i])
        k-=1
        i+=1
    elif i==np-1:
        if k==1:
            cand.append(pos[i])
            i+=1
            k-=1
        else:
            cand.append(-neg[j+1])
            cand.append(-neg[j])
            j+=2
            k-=2
    elif i==np:
        cand.append(-neg[j+1])
        cand.append(-neg[j])
        j+=2
        k-=2
for num in cand:
    ans*=num
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
ans=1
if n==k or max(a)<=0 or min(a)>0:
    a.sort(reverse=True)
    for i in range(k):
        ans*=a[i]
        ans%=mod
    print(ans)
    exit()
pos,neg=[],[]
for num in a:
    if num<0:
        neg.append(-num)
    else:
        pos.append(num)
neg.sort(reverse=True)
pos.sort(reverse=True)
nn=len(neg)
np=len(pos)
cand=[]
i,j=0,0
while k>0:
    if i<np-1 and j<nn-1:
        if k>=2:
            if pos[i+1]*pos[i]<neg[i+1]*neg[i]:
                cand.append(-neg[j+1])
                cand.append(-neg[j])
                k-=2
                j+=2
            else:
                cand.append(pos[i])
                k-=1
                i+=1
        else:
            cand.append(pos[i])
            k-=1
            i+=1
    elif j>=nn-1:
        cand.append(pos[i])
        k-=1
        i+=1
    elif i==np-1:
        if k==1:
            cand.append(pos[i])
            i+=1
            k-=1
        else:
            cand.append(-neg[j+1])
            cand.append(-neg[j])
            j+=2
            k-=2
    elif i==np:
        cand.append(-neg[j+1])
        cand.append(-neg[j])
        j+=2
        k-=2
for num in cand:
    ans*=num
    ans%=mod
print(ans)
Problem p02645 (python)

Fixed submission:
s=input()
print(s[:3])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
    imos=[0]*(n+1)
    for i in range(n):
        imos[max(0,i-a[i])]+=1
        imos[min(n-1,i+a[i])+1]-=1
    for i in range(n-1):
        imos[i+1]+=imos[i]
    for i in range(n):
        a[i]=imos[i]
print(*a)
Problem p02660 (python)

Fixed submission:
n=int(input())
d=dict()
for i in range(1,int(n**0.5)+1):
    cnt=0
    while n%(i+1)==0:
        n//=i+1
        cnt+=1
    d[i+1]=cnt
if n>1:
    if n in d:
        d[n]+=1
    else:
        d[n]=1
ans=0
d=list(d.items())
for i,r in d:
    for j in range(1,44):
        if j*(j+1)//2>r:
            ans+=j-1
            break
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
p=[0]*(10**6+1)
for i in range(1,int(n**0.5)+1):
    cnt=0
    while n%(i+1)==0:
        n//=i+1
        cnt+=1
    p[i+1]+=cnt
if n>1:
    p[n]+=1
ans=0
for i in p:
    for j in range(1,44):
        if j*(j+1)//2>i:
            ans+=j-1
            break
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
p=[0]*(10**6+1)
for i in range(1,int(n**0.5)+1):
    cnt=0
    while n%(i+1)==0:
        n//=i+1
        cnt+=1
    p[i+1]+=cnt
if n>1:
    p[n]+=1
ans=0
for i in p:
    for j in range(1,44):
        if j*(j+1)//2>i:
            ans+=j-1
            break
print(ans)
Problem p02675 (python)

Fixed submission:
n=input()
if n[-1]=="3":
    print("bon")
elif n[-1]=="0" or n[-1]=="1" or n[-1]=="6" or n[-1]=="8":
    print("pon")
else:
    print("hon")

Buggy submission (verdict: Runtime Error):
k=int(input())
s=input()
if len(s)>k:
    print(s[:k]+"...")
else:
    print(s[:k])
Problem p02684 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
i=0
s=set()
s.add(1)
order=[1]
while 1:
    if a[i] in s:
        order.append(a[i])
        break
    else:
        order.append(a[i])
        s.add(a[i])
    i=a[i]-1
for i in range(len(order)):
    if order[-1]==order[i]:
        idx=i
        break
#print(order)
cnt=len(order)-(idx+1)
if len(order)>k:
    print(order[k])
else:
    k-=len(order)
    order=order[idx+1:]
    #print(cnt)
    #print(order)
    k%=cnt
    #print(k)
    print(order[k])
#print(order)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
i=0
s=set()
s.add(1)
order=[1]
while 1:
    if a[i] in s:
        order.append(a[i])
        break
    else:
        order.append(a[i])
        s.add(a[i])
    i=a[i]-1
for i in range(len(order)):
    if order[-1]==order[i]:
        idx=i
        break
#print(order)
if idx==0:
    cnt=len(order)-(idx+1)
else:
    cnt=len(order)-idx
if len(order)>k:
    print(order[k])
else:
    order=order[idx+1:]
    #print(order)
    k%=cnt
    if k>=1:
        k-=1
    else:
        k=cnt-1
    #print(k)
    print(order[k])
#print(order)
Problem p02702 (python)

Fixed submission:
s=input()
n=len(s)
s=s[::-1]
accum=[0]*n
p=2019
d=dict()
for i in range(n):
    accum[i]=int(s[i])*pow(10,i,p)%p
for i in range(n-1):
    accum[i+1]+=accum[i]
    accum[i+1]%=p
accum[-1]%=p
ans=0
#print(accum)
for i in range(n):
    #print(d)
    if accum[i] not in d:
        if accum[i]==0:
            ans+=1
        d[accum[i]]=1
    else:
        if accum[i]==0:
            ans+=1
        ans+=d[accum[i]]
        d[accum[i]]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
s=input()
n=len(s)
s=s[::-1]
accum=[0]*n
p=2019
d=dict()
for i in range(n):
    accum[i]=int(s[i])*pow(10,i,p)%p
for i in range(n-1):
    accum[i+1]+=accum[i]
    accum[i+1]%=p
accum[-1]%=p
ans=0
#print(accum)
for i in range(n):
    #print(d)
    if accum[i] not in d:
        if accum[i]==0:
            ans+=1
        d[accum[i]]=1
    else:
        if accum[i]==0:
            ans+=1
        ans+=d[accum[i]]
        d[accum[i]]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
s=input()
n=len(s)
s=s[::-1]
accum=[0]*n
p=2019
d=dict()
for i in range(n):
    accum[i]=int(s[i])*pow(10,i,p)%p
for i in range(n-1):
    accum[i+1]+=accum[i]
    accum[i+1]%=p
accum[-1]%=p
ans=0
#print(accum)
for i in range(n):
    #print(d)
    if accum[i] not in d:
        if accum[i]==0:
            ans+=1
        d[accum[i]]=1
    else:
        if accum[i]==0:
            ans+=1
        ans+=d[accum[i]]
        d[accum[i]]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
s=input()
n=len(s)
s=s[::-1]
accum=[0]*n
p=2019
d=dict()
for i in range(n):
    accum[i]=int(s[i])*pow(10,i,p)%p
for i in range(n-1):
    accum[i+1]+=accum[i]
    accum[i+1]%=p
accum[-1]%=p
ans=0
#print(accum)
for i in range(n):
    #print(d)
    if accum[i] not in d:
        if accum[i]==0:
            ans+=1
        d[accum[i]]=1
    else:
        if accum[i]==0:
            ans+=1
        ans+=d[accum[i]]
        d[accum[i]]+=1
print(ans)
Problem p02713 (python)

Fixed submission:
from math import gcd
k=int(input())
ans=0
for a in range(1,k+1):
  for b in range(1,k+1):
    d=gcd(a,b)
    for c in range(1,k+1):
      ans+=gcd(d,c)
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
k=int(input())
ans=0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      ans+=gcd(a,b,c)
print(ans)
Problem p02748 (python)

Fixed submission:
a,b,m=map(int,input().split())
alis=list(map(int,input().split()))
blis=list(map(int,input().split()))
ans=10**18
d=dict()
for i in range(m):
  x,y,c=map(int,input().split())
  x-=1
  y-=1
  d[(x,y)]=c
  ans=min(ans,alis[x]+blis[y]-c)
alis1=[]
blis1=[]
for i in range(a):
  alis1.append((alis[i],i))
for i in range(b):
  blis1.append((blis[i],i))
alis1.sort()
blis1.sort()
if (alis1[0][1],blis1[0][1]) not in d:
  ans=min(ans,alis1[0][0]+blis1[0][0])
print(ans)

Buggy submission (verdict: Runtime Error):
a,b,m=map(int,input().split())
alis=list(map(int,input().split()))
blis=list(map(int,input().split()))
ans=10**18
d=dict()
for i in range(m):
  x,y,c=map(int,input().split())
  x-=1
  y-=1
  d[(x,y)]=c
  ans=min(ans,alis[x]+blis[y]-c)
alis1=[]
blis1=[]
for i in range(a):
  alis1.append((alis[i],i))
for i in range(a):
  blis1.append((blis[i],i))
alis1.sort()
blis1.sort()
if (alis1[0][1],blis1[0][1]) not in d:
  ans=min(ans,alis1[0][0]+blis1[0][0])
print(ans)
Problem p02761 (python)

Fixed submission:
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
num=[-1]*n
rec=dict()
for i in range(m):
  if sc[i][0] in rec and str(sc[i][1])!=num[sc[i][0]-1]:
    print(-1)
    exit()
  else:
    rec[sc[i][0]]=0
    num[sc[i][0]-1]=str(sc[i][1])
if num[0]=='0':
  if n>1:
    print(-1)
    exit()
elif num[0]==-1:
  if n>1:
    num[0]='1'
for i in range(n):
  if num[i]==-1:
    num[i]='0'
print(''.join(num))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
num=[-1]*n
rec=dict()
for i in range(m):
  if sc[i][0] in rec and str(sc[i][1])!=num[sc[i][0]-1]:
    print(-1)
    exit()
  else:
    rec[sc[i][0]]=0
    num[sc[i][0]-1]=str(sc[i][1])
if num[0]=='0':
  if n>1:
    print(-1)
    exit()
elif num[0]==-1:
  num[0]=1
cntnot0=0
for i in range(n):
  if num[i]==-1:
    num[i]='0'
print(''.join(num))