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

Fixed submission:
def check_prime(k):
    '''
    素数の時1、合成数の時0を返す
    '''
    if k == 1:return 0
    num = int(k ** 0.5 // 1)
    for i in range(2, num + 1):
        if k % i == 0:return 0
    return 1

n = int(input())
prime = []

for i in range(2, 55556):
    if check_prime(i):
        prime.append(i)

rec = [2]
ind = 1
for i in range(n - 1):
    while True:
        if prime[ind] % 5 == 1:
            rec.append(prime[ind])
            ind += 1
            break
        ind += 1

print(*rec)

Buggy submission (verdict: Runtime Error):
def check_prime(k):
    '''
    素数の時1、合成数の時0を返す
    '''
    if k == 1:return 0
    num = int(k ** 0.5 // 1)
    for i in range(2, num + 1):
        if k % i == 0:return 0
    return 1

n = int(input())
prime = []
for i in range(1, 55556):
    if check_prime(i):
        prime.append(i)

rec = [2]
cnt = 0
for i in range(n - 1):

    while True:
        if prime[cnt] < 2 * rec[-1]:
            cnt += 1
        else:
            rec.append(prime[cnt])
            cnt += 1
            break
print(*rec)

Buggy submission (verdict: Runtime Error):
def check_prime(k):
    '''
    素数の時1、合成数の時0を返す
    '''
    if k == 1:return 0
    num = int(k ** 0.5 // 1)
    for i in range(2, num + 1):
        if k % i == 0:return 0
    return 1

n = int(input())
prime = []
for i in range(1, 55556):
    if check_prime(i):
        prime.append(i)

rec = [2]
cnt = 0
for i in range(n - 1):

    while True:
        if prime[cnt] < 2 * rec[-1]:
            cnt += 1
        else:
            rec.append(prime[cnt])
            cnt += 1
            break
print(rec)
Problem p03386 (python)

Fixed submission:
A, B, K = map(int, input().split())
num_range = range(A, B + 1)
for i in sorted(set(num_range[:K]) | set(num_range[-K:])):
    print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
l=list(range(a,b+1))
l=l[:k]+l[-k:]
l=sorted(set(l))
print(*l,sep='\n')

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
l=list(range(a,b+1))
if b+1-a>=2*k:
    l=l[:k]+l[-k:]
print(*l,sep='\n')

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
l=list(range(a,b+1))
l=l[:k]+l[-k:]
l=sorted(set(l))
print(*l,sep='\n')

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
l=list(range(a,b+1))
l=l[:k]+l[-k:]
l=sorted(set(l))
print(*l,sep='\n')

Buggy submission (verdict: Runtime Error):

a,b,k=map(int,input().split())
l=list(range(a,b+1))
l=l[:k]+l[-k:]
l=set(l)
l=sorted(list(l))
print(*l,sep='\n')

Buggy submission (verdict: Runtime Error):

a,b,k=map(int,input().split())
l=list(range(a,b+1))
l=l[:k]+l[-k:]
print(*set(l),sep='\n')

Buggy submission (verdict: Runtime Error):
#93B
a,b,k=map(int,input().split())
l=list(range(a,b+1))
l=l[:k]+l[-k:]
print(*l,sep='\n')
Problem p03387 (python)

Fixed submission:
a=list(map(int,input().split()))
a=sorted(a)
maxim=a[-1]
for i in range(3):
    a[i]=a[-1]-a[i]

ans=a[1]+(a[0]-a[1])//2 if (a[0]-a[1])%2==0 else a[1]+(a[0]-a[1])//2+2
print(ans)

Buggy submission (verdict: Runtime Error):
num=list(map(int,input().split()))
odd_num=[]
even_num=[]
count=0
for i in num:
    if i%2!=0:
        count+=1
        odd_num+=[i]
    else:
        even_num+=[i]

if count==1:
    if max(odd_num)>max(even_num):
        ans=abs(even_num[0]-even_num[1])//2+ood_num[0]-max(even_num)
        print(ans)
    else:
        ans=abs(even_num[0]-even_num[1])//2+1+(max(even_num)+1-odd_num[0])//2
        print(ans)
elif count==2:
    if max(odd_num)>max(even_num):
        ans=even_num[0]-max(odd_num)+abs(odd_num[0]-odd_num[1])//2
        print(ans)
    else:
        ans=abs(odd_num[0]-odd_num[1])//2+even_num-max(odd_num)
        print(ans)
else:
    if count==3:
        ans=(3*max(odd_num)-sum(odd_num))//2
        print(ans)
    else:
        ans=(3*max(even_num)-sum(even_num))//2
        print(ans)
Problem p03425 (python)

Fixed submission:
from collections import defaultdict
from itertools import combinations

n=int(input())
s=[input() for i in range(n)]
name=['M','A','R','C','H']

cnt=defaultdict(lambda:0)
for i in range(n):
    if s[i][0] in name:
        cnt[s[i][0]]+=1

cnt=cnt.values()
if len(cnt)<3:
    print(0)
    exit()
ans=0

# listから２つ選ぶ組み合わせ
for x,y,z in combinations(cnt,3):
    ans+=x*y*z

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from itertools import combinations
n=int(input())
s=[input() for i in range(n)]
cnt=defaultdict(lambda :0)
cnt['M']=0
for i in range(n):
    if s[i][0] in 'MARCH':
        cnt[s[i][0]]+=1

if len(cnt)<=2:print(0)
else:
    num=len(cnt)
    ans=0
    for x,y,z in combinations(list(cnt.values()), 3):
        ans+=x*y*z
print(ans)
Problem p03493 (python)

Fixed submission:
print(input().count('1'))

Buggy submission (verdict: Runtime Error):
n=input()
s=list(map(int,input().split()))
sp=0
for i in s:
    if i%2==0:
        sp+=1
        continue
    else:
        break
print(sp)

Buggy submission (verdict: Runtime Error):
s=list(input())
A=0　　　　　　　　　　
for i in range(3):
    if int(s[i])==1:   
        A+=1
print(A)
Problem p03494 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
count=0
ans=0
for i in range(30):
    for i in range(n):
        if a[i]%2==0:
            a[i]=a[i]//2
            count+=1
        else:
            count=0
            break
    
    if count!=0:
        ans=count//n
    
print(ans)

Buggy submission (verdict: Runtime Error):
n=input()
s=list(input())
sp=0
for i in int(n):
    if s[i]%2==0:
        sp+=1
        continue
    else:
        break
print(sp)
Problem p03546 (python)

Fixed submission:
h, w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            if i == j:continue
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

cost = 0
for i in range(h):
    for j in range(w):
        temp = a[i][j]
        if temp == -1:continue
        cost += c[temp][1]
print(cost)

Buggy submission (verdict: Runtime Error):
h, w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]

'''重み0の辺は自動で消されてしまうので注意'''
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
inf = 10 ** 10
G = csgraph_from_dense(c, null_value = 0)
d = floyd_warshall(G)
cost = 0

for i in range(h):
    for j in range(w):
        temp = a[i][j]
        if temp == -1:continue
        cost += d[temp][1]
print(int(cost))

Buggy submission (verdict: Runtime Error):
h, w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]

'''重み0の辺は自動で消されてしまうので注意'''
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
inf = 10 ** 10
G = csgraph_from_dense(c, null_value = 10 ** 10)
d = floyd_warshall(G)
cost = 0

for i in range(h):
    for j in range(w):
        temp = a[i][j]
        if temp == -1:continue
        cost += d[temp][1]
print(int(cost))
Problem p03556 (python)

Fixed submission:
n=int(input())
sq=n**0.5//1
print(int(sq**2))

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(range(1,n+1))
l=sorted(l,reverse=True)
ans=0
for i in l:
    if pow(i,0.5)%1==0:
        ans=i
        break
        
print(ans)
Problem p03569 (python)

Fixed submission:
from collections import deque
s = list(input())
s = deque(s)
cnt = 0
while len(s) > 1:
    left = s.popleft()
    right = s.pop()
    if left == right:continue
    if left != 'x' and right != 'x':
        print(-1)
        exit()

    if left == 'x':
        s.append(right)
    else:
        s.appendleft(left)
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
#WA
s = input()
ns = ''
cnt = 0
cnt1 = 0
for i in range(len(s)):
    if s[i] != 'x':
        ns += s[i]
    else:cnt += 1

if ns != ns[::-1]:
    print(-1)
    exit()

mid = len(ns) // 2
mid_str = ns[mid]
mid_ind = s.index(mid_str)
#print(mid_ind)

count = 0
for i in range(len(s)):
    if s[i] != 'x':continue
    temp_ind = 2 * mid_ind - i
    if temp_ind >= len(s) or temp_ind < 0:continue
    if s[temp_ind] == 'x':
        count += 1

#print(cnt, count)
print(cnt - count * 2)
Problem p03838 (python)

Fixed submission:
#agc008-a
x,y=map(int,input().split())
ans=float('inf')

#反転させるかどうか決めた後のx,yの上下関係を考える
#0,0
if y-x>0:
    ans=min(ans,y-x)
#1,0
if -x<=y:
    ans=min(ans,1+y+x)
#0,1
if x<=-y:
    ans=min(ans,1+-y-x)
#1,1
if -x<=-y:
    ans=min(ans,2+-y+x)
print(ans)

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

if x<0:
    if y<0:
        ans=2+abs(y)-abs(x)
    else:
        if y<-x:
            ans=y-x
        else:
            ans=1+y+x
else:
    if y>x:
        ans=y-x
    elif y<0:
        ans=-y-x+1
print(ans)

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

y_con=-y
if x<0:
    ans=2+abs(y)-abs(x)
else:
    if y>x:
        ans=y-x
    elif y<0:
        ans=-y-x+1
print(ans)
Problem p03861 (python)

Fixed submission:
#48-B
a,b,x=map(int,input().split())
b_count=b//x
a_count=(a-1)//x
print(b_count-a_count)

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1

print(l[-1]-l[0])

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1
    
print(l[-1]-l[1])

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1
    
print(l[-1]-l[0])

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1
    
print(l)
print(l[-1]-l[0])
Problem p03862 (python)

Fixed submission:
#048-C
n,x=map(int,input().split())
a=list(map(int,input().split()))
a_sum=sum(a)
ans=0
if a[0]>x:
    a[0]=x
    ans+=a[0]-x
else:
    ans+=a[0]
for i in range(n-1):
    if a[i]+a[i+1]>x:
        a[i+1]-=a[i+1]+a[i]-x
        ans+=a[i+1]
print(a_sum-sum(a))

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1
    
print(l[-1]-l[0])
Problem p03944 (python)

Fixed submission:
#abc047-b
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
#x,y,a
x_min=0
y_min=0

for i in l:
    if i[-1]==1:
        x_min=max(i[0],x_min)

    elif i[-1]==2:
        w=min(i[0],w)

    elif i[-1]==3:
        y_min=max(i[1],y_min)

    else:
        h=min(i[1],h)

print((w-x_min)*(h-y_min) if (w-x_min)>0 and (h-y_min)>0 else 0)

Buggy submission (verdict: Runtime Error):
#abc047-b
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
#x,y,a
x_min=0
y_min=0

for i in l:
    if i[-1]==1:
        x_min=max(i[0],x_min)

    elif i[-1]==2:
        w=min(i[0],w)

    elif i[-1]==3:
        y_min=max(i[1],y_min)

    else:
        h=min(i[1],h)
s=
print((w-x_min)*(h-y_min) if (w-x_min)>0 and (h-y_min)>0 else 0)
Problem p03994 (python)

Fixed submission:
s=list(input())
k=int(input())

for i in range(len(s)):
    if k==0:break

    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(97+(num+k-97)%26) #if num+k>122 else chr(num+k)
        #print(97+(num+k-97)%26)
        k=0
        break
    elif s[i]=='a':continue
    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))

Buggy submission (verdict: Runtime Error):
s=list(input())
k=int(input())

for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if k==0:break
    if s[i]=='a' and i!=len(s)-1:continue

    if a_<=k and i!=len(s)-1:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k) if num_al+k<=122 else chr(num_al+k-26)
        k=0
print(''.join(s))

Buggy submission (verdict: Runtime Error):
s=list(input())
k=int(input())

for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if k==0:break
    if s[i]=='a' and i!=len(s)-1:continue

    if a_<=k and i!=len(s)-1:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k) if num_al+k<=122 else chr(num_al+k-122)
        k=0
print(''.join(s))
Problem p03997 (python)

Fixed submission:
a,b,h=int(input()),int(input()),int(input())
print(int((a+b)*h/2))

Buggy submission (verdict: Runtime Error):
a,b,h=map(int,input().split())
print(int((a+b)*h/2))

Buggy submission (verdict: Runtime Error):
a,b,h=map(int,input().split())
print(int((a+b)*h/2))
Problem p04031 (python)

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

ans=float('inf')
num=-100
while num!=101:
    kari=0
    for i in range(n):
        kari+=(num-a[i])**2
    num+=1
    ans=min(ans,kari)

print(ans)

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

a_ave=a[0]+a[-1]
num1=a_ave//2
num2=a_ave//2+1
ans1=0
ans2=0
for i in range(n):
    ans1+=(num1-a[i])**2
    ans2+=(num2-a[i])**2
print(min(ans1,ans2))
Problem p04032 (python)

Fixed submission:
s=input()
if len(s)==2:
    if len(set(s))==1:
        print(1,2)
        exit()
    else:
        print(-1,-1)
        exit()
        
for i in range(len(s)-2):
    a=s[i:i+3]
    if len(set(a))<=2 :
        print(i+1,i+3)
        exit()
print(-1,-1)

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

count=0
for i in range(len(s)-2):
    if s[i]==s[i+1] or s[i]==s[i+2] or s[i+1]=s[i+2]:
        print(i+1,i+3)
        exit()
print(-1,-1)
Problem p04045 (python)

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

num=[]
for i in range(10):
    if i not in d:
        num.append(i)
#print(num)
num.sort()
digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if int(ns[cnt])>i:continue
        if int(ns[cnt])==i:
            ans+=str(i)
            break
        else:
            ans+=str(i)+(digit-cnt-1)*str(num[0])
            cnt=digit
            break
    else:
        ans=str(num[0]) if num[0]!=0 else str(num[1])
        ans+=str(num[0])*digit
        cnt=digit
    cnt+=1
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import *
n, k = map(int,input().split())
d = list(map(int,input().split()))

use_num = []
for i in range(10):
    if i in d:continue
    use_num.append(i)

str_n = str(n)
res = 0
for i in str_n:
    temp = bisect_left(use_num, int(i))
    add = use_num[temp]
    if temp == len(use_num):
        add = use_num[0] * 10
    res = res * 10 + add 
print(res)

Buggy submission (verdict: Runtime Error):
from bisect import *
n, k = map(int,input().split())
d = list(map(int,input().split()))

use_num = []
for i in range(10):
    if i in d:continue
    use_num.append(i)

str_n = str(n)
res = 0
for i in str_n:
    temp = bisect_left(use_num, int(i))
    res = res * 10 + use_num[temp]
print(res)
Problem p03223 (python)

Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
Tenka1-2018 C
"""

n = int(input())
ali = [int(input()) for i in range(n)]
ali.sort()

if n % 2 is 1:
    m = (n-1)//2
    am = ali[m]
    asmall = ali[:m]
    abig = ali[m+1:]
    if 2*am-asmall[-1]-abig[0] > 0:
        ans = am-2*sum(asmall)+2*sum(abig)-abig[0]
    else:
        ans = -am+2*sum(abig)-2*sum(asmall)+asmall[-1]
else:
    m = n//2
    asmall = ali[:m]
    abig = ali[m:]
    ans = -2*sum(asmall)+2*sum(abig)-abig[0]+asmall[-1]

print(ans)

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
tenka1-2018 E
"""

from itertools import product
from itertools import combinations

h, w = map(int, input().split())
slili = [list(input()) for i in range(h)]

coinsetli = [set() for i in range(h+w)]
for i, j in product(range(h), range(w)):
    if slili[i][j] == '#':
        coinsetli[i+j+1].add(j-i)

coinacumdictli = [{} for i in range(h+w)]
for i in range(1, h+w):
    tmp = 0
    for j in range(-300, 301):
        if j in coinsetli[i]:
            tmp += 1
        coinacumdictli[i][j] = tmp

ansdouble = 0
for i in range(1, h+w):
    for x, y in combinations(coinsetli[i], 2):
        j = abs(x-y)
        x, y = (min(x, y), max(x, y))
        if i-j >= 1:
            ansdouble += coinacumdictli[i-j][y]+coinacumdictli[i-j][y-1] - coinacumdictli[i-j][x] - coinacumdictli[i-j][x-1]
        if i+j <= h+w-1:
            ansdouble += coinacumdictli[i+j][y]+coinacumdictli[i+j][y-1] - coinacumdictli[i+j][x] - coinacumdictli[i+j][x-1]

# repeat after reversing along the vertical axis
for i in range(h):
    slili[i].reverse()

coinsetli = [set() for i in range(h+w)]
for i, j in product(range(h), range(w)):
    if slili[i][j] == '#':
        coinsetli[i+j+1].add(j-i)

coinacumdictli = [{} for i in range(h+w)]
for i in range(1, h+w):
    tmp = 0
    for j in range(-300, 301):
        if j in coinsetli[i]:
            tmp += 1
        coinacumdictli[i][j] = tmp

for i in range(1, h+w):
    for x, y in combinations(coinsetli[i], 2):
        j = abs(x-y)
        x, y = (min(x, y), max(x, y))
        if i-j >= 1:
            ansdouble += coinacumdictli[i-j][y]+coinacumdictli[i-j][y-1] - coinacumdictli[i-j][x] - coinacumdictli[i-j][x-1]
        if i+j <= h+w-1:
            ansdouble += coinacumdictli[i+j][y]+coinacumdictli[i+j][y-1] - coinacumdictli[i+j][x] - coinacumdictli[i+j][x-1]

print(ansdouble//2)
Problem p03231 (python)

Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 A
"""

import fractions

n, m = map(int, input().split())
s = input()
t = input()

g = fractions.gcd(n, m)
lcm = (n*m//g)

flag = True
for i in range(g):
    if s[i*lcm//m] != t[i*lcm//n]:
        flag = False
        break

if flag:
    print(lcm)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 B
"""

import itertools
import math

n = int(input())
ali = list(map(int, input().split()))

cut = 10**9+7


def modInverse(a, b, divmod=divmod):
    r0, r1, s0, s1 = a, b, 1, 0
    while r1 != 0:
        q, rtmp = divmod(r0, r1)
        stmp = s0-q*s1
        r0, s0 = r1, s1
        r1, s1 = rtmp, stmp
    return s0 % cut


# def factorial(n):
#     nn = 1
#     for i in range(2, n+1):
#         nn = nn*i
#     return(nn)


invlist = [modInverse(i, cut) for i in range(1, n+1)]
accuminv = list(itertools.accumulate(invlist, func=lambda x, y: x+y % cut))

ans = 0
nfact = math.factorial(n)
for i in range(n):
    sump = accuminv[i]+accuminv[n-1-i] - 1
    ans += ali[i]*sump % cut

ans = ans*nfact % cut
print(ans)

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 A
"""

import math

n, m = map(int, input().split())
s = input()
t = input()

g = math.gcd(n, m)
lcm = (n*m//g)

flag = True
for i in range(g):
    if s[i*lcm//m] != t[i*lcm//n]:
        flag = False
        break

if flag:
    print(lcm)
else:
    print(-1)
Problem p03233 (python)

Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 C
"""

from operator import itemgetter

n = int(input())
abli = []
for i in range(n):
    a, b = map(int, input().split())
    abli.append((a, i, 0))
    abli.append((b, i, 1))

abli.sort(key=itemgetter(0))
tmpans0 = sum(map(itemgetter(0), abli[:n]))
aiset = set([i for x, i, aorb in abli[:n] if not aorb])
biset = set([i for x, i, aorb in abli[:n] if aorb])
flag = bool(set.intersection(aiset, biset))


y, j, arob2 = abli[n]
z, k, arob3 = abli[n+1]

if flag:
    tmpans = tmpans0
else:
    min1 = y-max([x for x, i, aorb in abli[:n] if j != i])
    min2 = z-max([x for x, i, aorb in abli[:n] if j == i])
    tmpans = tmpans0 + min(min1, min2)

leftsum = sum([aa for aa, i, aorb in abli if not aorb])
rightsum = sum([bb for bb, i, aorb in abli if aorb])

print(min(leftsum, rightsum, tmpans))

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 C
"""

import itertools

n = int(input())
abli = [tuple(map(int, input().split())) for i in range(n)]

leftsum = sum(map(lambda x: x[0], abli))
rightsum = sum(map(lambda x: x[1], abli))

maxminel = max(enumerate(abli), key=lambda x: 10**10*min(x[1])+max(x[1]))
maxminmax = max(abli[maxminel[0]])
del abli[maxminel[0]]
flattenli = list(itertools.chain.from_iterable(abli))
flattenli.sort()
tmpans = sum(flattenli[:n])
if flattenli[n] > maxminmax:
    tmpans = tmpans-flattenli[n]+maxminmax


print(min(leftsum, rightsum, tmpans))
Problem p03254 (python)

Fixed submission:
n,x = map(int,input().split())
ass = list(map(int,input().split()))
ass.sort()

ans = 0
acm = 0
for i in ass:
    acm += i
    if x >= acm:
        ans +=1

if acm < x:
    ans -= 1

print(ans)

Buggy submission (verdict: Runtime Error):


n,m = map(int,input().split())
s = list(input())
edges = [tuple(map(int,input().split())) for i in range(m)]


def addEdge(graph,u,v):
    graph[u].add(v)


def deleteNode(graph,node):
    graph.pop(node,None)

from collections import defaultdict
graphAB = defaultdict(set)
graphABopp = defaultdict(set)

connodes = set()
for i,j in edges:
    ii = min(i,j)
    jj = max(i,j)
    addEdge(graphAB,ii,jj)
    addEdge(graphABopp,jj,ii)
    if i != j:
        connodes.add(i)
        connodes.add(j)



def adjAB(node):
    Aflag = 'A' in map(lambda x:s[x-1],graphAB[node])
    Aflag = Aflag or 'A' in map(lambda x:s[x-1],graphABopp[node])
    Bflag = 'B' in map(lambda x:s[x-1],graphAB[node])
    Bflag = Bflag or 'B' in map(lambda x:s[x-1],graphABopp[node])
    if Aflag and Bflag:
        return(True)
    else:
        return(False)



visitlist = [i for i in connodes if not adjAB(i)]
#print(visitset)

while bool(visitlist):
    i = visitlist.pop()
    for j in graphAB[i]:
        graphABopp[j].remove(i)
        if not adjAB(j):
            visitlist.append(j)
            #print(visitset,'add')
    for j in graphABopp[i]:
        graphAB[j].remove(i)
        if not adjAB(j):
            visitlist.append(j)
            #print(visitset,'add')
    graphAB.pop(i,None)
    graphABopp.pop(i,None)

#print(graphAB)
#print(graphABopp)


if graphAB == {} and graphABopp == {}:
    print('No')
else:
    print('Yes')
Problem p03280 (python)

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

print((a-1)*(b-1))

Buggy submission (verdict: Runtime Error):
n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]
enuq = list(enumerate(qs))
 
enuq.sort(key = lambda x:x[1][0])
ansli = [0 for i in range(q)]


for (i,(p,q)) in enuq:
    removelist=[]
    for (j,(l,r)) in enumerate(rails):
        if p<=l and r<=q:
            ansli[i]=ansli[i]+1
        elif l<p:
            removelist.append(j)
    for jj in removelist:
        rails.pop(jj)



for a in ansli:
    print(a)

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

for i in s:
    if i != '1':
        ans = int(i)
        break

print (i)
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())

for i,a in enumerate(s):
    if (a != '1' ) or k==i+1:
        ans = int(a)
        break

print (ans)

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

for i,a in enumerate(s):
    if (a != '1' and k>i) or k==i:
        ans = int(a)
        break

print (ans)