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

Fixed submission:
import sys

n,m = map(int,input().split())
A = [list(input()) for i in range(n)]
B = [list(input()) for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if k == 0:
                C = [A[i][j:m+j]]
            else:
                C += [A[i+k][j:m+j]]
        if B == C:
            print('Yes')
            sys.exit()
print('No')

Buggy submission (verdict: Runtime Error):

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

A = [[input()] for i in range(n)]
B = [[input()] for i in range(m)]
ans = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        temp=0
        for k in range(m):
            for l in range(m):
                if B[k][l]==A[i+k][j+l]:
                    temp+=1
                    ans = max(ans,temp)
                                    
print('Yes' if ans==m*m else 'No')

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

A = [[input()] for i in range(n)]
B = [[input()] for i in range(m)]
ans = 0
for i in range(n-m):
    for j in range(n-m):
        temp=0
        for k in range(m):
            for l in range(m):
                if B[k][l]==A[i+k][j+l]:
                    temp+=1
                    ans = max(ans,temp)
                                    
print('Yes' if ans==m*m else 'No')
Problem p02701 (python)

Fixed submission:
# よりシンプルな解答

n = int(input())
s = [input() for _ in range(n)]

print(len(set(s)))

Buggy submission (verdict: Runtime Error):
n = int(input())
count = 0

for i in range(n):
    s[i] = input()
    if s[i] in s:
        count += 1

print(count)
Problem p02623 (python)

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0]
for i in range(n):
  A.append(A[i]+a[i])
B=[0]
for i in range(m):
  B.append(B[i]+b[i])
ans=0
j=m
for i in range(n+1):
  if A[i]>k:
      break
  while B[j]>(k-A[i]):
    j-=1
  ans=max(ans,i+j)
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0]
for i in range(n):
  A.append(a[i])
B=[0]
for i in range(m):
  B.append(b[i])
ans=0
j=m
for i in range(n+1):
  while B[j]>(k-A[i]):
    j-=1
  ans=max(ans,i+j)
print(ans)
Problem p02753 (python)

Fixed submission:
a = input()

if 'A' in a and 'B' in a:
    print('Yes')
else:
    print('No')

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

for n in range(0, 10000):
  a2 = int(n * 8 / 100)
  b2 = int(n * 8 / 100)
  if a2 == a and b2 == b:
    print(n)
    exit()
Problem p02759 (python)

Fixed submission:
n = int(input())

def calc(n):
    if n % 2 != 0:
        return int(n / 2) + 1
    else:
        return int(n / 2)

print(calc(n))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a = []
for i in range(3):
  tmp = input()
  a.append(list(map(int, tmp.split())))

n = int(input())
b = []
for j in range(n):
    b.append(int(input()))

# print(a)
# print(b)

for i in range(3):
    for j in range(3):
        if a[i][j] in b:
           a[i][j] = 0
# print(a)

def check(a):
    #　たてビンゴ
    for i in range(3):
        if (a[i][0] == 0 & a[i][1] == 0 & a[i][2] == 0):
            print('Yes')
            exit()
    # 横ビンゴ
        if a[i] == [0, 0, 0]:
            print('Yes')
            exit()
    # 斜めビンゴ
    if a[0][0] == 0 & a[1][1] == 0 & a[2][2] == 0:
            print('Yes')
            exit()
    if a[0][2] == 0 & a[1][1] == 0 & a[2][0] == 0:
            print('Yes')
            exit()
    print('No')

check(a)
Problem p02831 (python)

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

print((a * b) // fractions.gcd(a,b))

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

print((a * b) // math.gcd(a,b))
Problem p02881 (python)

Fixed submission:
import numpy as np
n = int(input())

ans = 10**18

for i in range(1, int(np.sqrt(n))+1):
    if n % i == 0:
        j = n//i
        ans = min(ans, i+j-2)

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())

a = []
if n%2==0:
    if n // 10000 >= 1:
        for i in range(1, n//10000):
            q, mod = divmod(n, i)
            if mod == 0:
                a.append((i,q))
    
        max = max(a)
        print(sum(max)-2)
    
    else:
        for i in range(1, n//2):
            q, mod = divmod(n, i)
            if mod == 0:
                a.append((i,q))
    
        max = max(a)
        print(sum(max)-2)

else:
    print(n-1)

Buggy submission (verdict: Runtime Error):
n = int(input())

a = []
if n%2==0:
    for i in range(1, n//2):
        q, mod = divmod(n, i)
        if mod == 0:
            a.append((i,q))
    
    max = max(a)

    print(sum(max)-2)
else:
    print(n-1)

Buggy submission (verdict: Runtime Error):
n = int(input())

a = []
for i in range(1, n//2):
    q, mod = divmod(n, i)
    if mod == 0:
        a.append((i,q))

max = max(a)

print(sum(max)-2)
Problem p02725 (python)

Fixed submission:
k,n=map(int,input().split())
a=list(map(int,input().split()))
max = -1
for i in range(0,n-1):
  d=abs(a[i+1]-a[i])
  if max<d:
    max=d
if max<k-a[n-1]+a[0]:
  max=k-a[n-1]+a[0]
  
print(k-max)

Buggy submission (verdict: Runtime Error):
k,n=map(int,input().split())
a=map(int,input().split())
max = -1
for i in range(0,n-1):
  if max>abs(a[i]-a[i+1]):
    max=abs(a[i]-a[i+1])
if max>(k-a[n-1])+a[0]:
  max=(k-a[n-1])+a[0]
  
print(k-max)
Problem p02951 (python)

Fixed submission:
a,b,c=map(int,input().split())
if c-(a-b)<0:
    print(0)
else:
    print(c-(a-b))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(c-(a-b)

Buggy submission (verdict: Runtime Error):
 a,b,c=map(int,input().split())
print(c-(a-b)
Problem p02627 (python)

Fixed submission:
a = str(input())

if a.islower()==True:
    print('a')
else:
    print('A')

Buggy submission (verdict: Runtime Error):
a = str(input())

if a.islower()==True:
    print(a)
else:
    print(A)
Problem p02676 (python)

Fixed submission:
K = int(input())
S = input()

if len(S) > K:
    print(S[:K]+"...")
else:
    print(S)

Buggy submission (verdict: Runtime Error):
if len(S) > K:
    print(S[:K]+"...")
else:
    print(S)
Problem p02688 (python)

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

s = [t for t in range(1,N+1)]
for i in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    for i in range(len(A)):
        if A[i] in s:
            s.remove(A[i])
print(len(s))

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

s = [t for t in range(1,N+1)]
for i in range(K):
    d = int(input())
    A = list(map(input().split()))
    if A[i] in s:
        s.remove(A[i])
    K -= 1
print(lne(s))
Problem p02860 (python)

Fixed submission:
N = int(input())
S = list(str(input()))

if N %2 == 1:
    print('No')
    exit()
for i in range(int(N//2)):
    if S[i] != S[N//2+i]:
        print('No')
        exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(str(input()))

p = []
for i in range(N/2):
    if S[i] != S[N/2+i]:
        print('No')
print('Yes')
Problem p02881 (python)

Fixed submission:
import math

N = int(input())
A = []
for i in range(2,int(math.sqrt(N))+1):
    if N%i == 0:
        A.append(i + (N//i) - 2)
if not A:
    print(N-1)
else:
    print(min(A))

Buggy submission (verdict: Runtime Error):
C:\pycharm\code_atcoder\venv\Scripts\python.exe C:/pycharm/code_atcoder/144C.py
100019
100018

プロセスは終了コード 0 で完了しました
Problem p02707 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[0]*N

for i in A:
    B[i-1]+=1

for i in B:
    print(i)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[0]*N

for i in A:
    B[i-1]+=1

for i in B:
    print(i)

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

for i in range(1,N+1):
    print(A.count(i))
Problem p02753 (python)

Fixed submission:
str = input()
a = str[0]
b = str[1]
c = str[2]

if a == b ==c:
  print('No')
elif a != b or a != c or b != c:
  print('Yes')

Buggy submission (verdict: Runtime Error):
input = input().split()
N = int(input[0])
A  = int(input[1])
B  = int(input[2])
arr = []
for index in range(A):
  arr.append('a')
for index in range(B):
  arr.append('b')

for index in range(0,N):
  if arr[index] == 'b':
    print(index)
    break
  elif index + 1 == N:
    print(N)
    break
Problem p02707 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
buka=[0]*n
for i in a:
  buka[i-1]=buka[i-1]+1
for i in buka:
  print(i)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
buka=[0]*n
for i in a:
  s[i]=s[i]+1
for i in buka:
  print(i)
Problem p02711 (python)

Fixed submission:
n=input()
if "7" in n:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n=int(input())
if 7 in n:
  print('Yes')
else:
  print('No')
Problem p02712 (python)

Fixed submission:
a=[]
for i in range(1,int(input())+1):
    if i%3!=0 and i%5!=0:
        a.append(i)
print(sum(a))

Buggy submission (verdict: Runtime Error):
a=[]
b=[]
for i in range(input()):
    if i%3!=0 and i%5!=0:
        a.append(i)
    else:
        b.append(i)
print(sum(a))
Problem p02723 (python)

Fixed submission:
s=input()
if s[2]==s[3] and s[4]==s[5]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
s=input()
if s[2]=s[3] and s[4]=s[5]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
s=input()
if s[3]=s[4] and s[5]=s[6]:
  print('Yes')
else:
  print('No')
Problem p02835 (python)

Fixed submission:
a,b,c=map(int,input().split())
print('win' if a+b+c<=21 else 'bust')

Buggy submission (verdict: Runtime Error):
n=int(input())
xy=[]
for i in range(n):
  a=int(input())
  xy.append([list(map(int,input().split())) for j in range(a)])

ans=0
for i in range(2**n):
  honest=[]
  for j in range(n):
    if (i>>j)&1:
      honest.append(1)
    else:
      honest.append(0)
  p=0
  for j,k in enumerate(honest):
    if k==1:
      r=0
      for l in xy[j]:
        if honest[l[0]-1]!=l[1]:
          r=1
          break    
      if r==0:
        p=p+1
  if p==sum(honest):
    ans=p
print(max(ans))
Problem p02836 (python)

Fixed submission:
s=input()
hug=0
for i in range(len(s)//2):
  if s[i]!=s[len(s)-1-i]:
    hug=hug+1
print(hug)

Buggy submission (verdict: Runtime Error):
s=input()
hug=0
for i in range(len(s)//2):
  if s[i]!=s[n-1-i]:
    hug=hug+1
print(hug)
Problem p02847 (python)

Fixed submission:
s=input()
week=['SUN','MON','TUE','WED','THU','FRI','SAT']
print(7-week.index(s))

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
if a*10**9+b*10<=x:
  print(1000000000)
else:
  n=0
  for i in reversed(range(1,10)):
    max=(x-b*i)//a
    if len(str(max))==i:
      n=max
      break
    elif 10**(i-1)<=max<10**i:
      n=max
      break
  print(n)
Problem p02860 (python)

Fixed submission:
n=int(input())
s=input()
m=n//2
t=s[:m]
print('Yes' if s==t+t else 'No')

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
m=n//2
t=s[:m]
print('Yes' if s=t+t else 'No')
Problem p02916 (python)

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

m=0
for i in range(n-1):
  if a[i+1]==a[i]+1:
    m=m+c[a[i]-1]

print(sum(b)+m)

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

m=0
for i in range(n):
  if a[i+1]==a[i]+1:
    m=m+c[i]

print(sum(b)+m)
Problem p02682 (python)

Fixed submission:
a,b,c,k=(int(x) for x in input().split())

a1 = a
nokori = 0
nokori_1 = 0
nokori_2 = 0
tensuu = 0

if k-a1 > 0:
   tensuu +=a1
   nokori = k-a

if nokori > 0:
   tensuu +=0
   nokori2 =nokori - b
   if nokori2 > 0:
        tensuu -= nokori2
if k - a1 <= 0:
    tensuu = k
print(tensuu)

Buggy submission (verdict: Runtime Error):
a,b,c,k=(int(x) for x in input().split())

a1 = a
nokori = 0
nokori_1 = 0
nokori_2 = 0
tensuu = 0

if k-a1 > 0:
   tensuu +=a1
   nokori = k-a


if nokori > 0:
   tensuu +=0
   nokori2 =nokori - b 
if nokori2 > 0:
    tensuu -= nokori2

print(tensuu)
Problem p02623 (python)

Fixed submission:
import numpy
import bisect

N,M,K = map(int, input().split())
ans = 0
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A = numpy.cumsum(numpy.array(A))
A = list(A)
A.insert(0, 0)
B = numpy.cumsum(numpy.array(B))
B = list(B)
B.insert(0, 0)
ans = 0

for i in range(N+1):
    if K - A[i] < 0:
        break
    b = bisect.bisect(B, K - A[i])
    ans = max(ans, i+b-1)

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy
import bisect

N,M,K = map(int, input().split())
ans = 0
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A = numpy.cumsum(numpy.array(A))
A = list(A)
A.insert(0, 0)
B = numpy.cumsum(numpy.array(B))
B = list(B)
B.insert(0, 0)
ans = 0

for i in range(N+1):
    if K - A[i] < 0:
        break
    b = bisect.bisect(B, K - A[i])
    ans = max(ans, i+b-1)

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy

N,M,K = map(int, input().split())
ans = 0
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A = numpy.cumsum(numpy.array(A))
A = list(A)
A.insert(0, 0)
B = numpy.cumsum(numpy.array(B))
B = list(B)
B.insert(0, 0)
ans = 0

for i in range(N+1):
    if A[i] > K:
        break
    for j in range(M+1):
        if A[i] + B[j] <= K:
            ans = max(i+j,ans)
        else :
            break

print(ans)
Problem p02759 (python)

Fixed submission:
N = int(input())

print(-(-N // 2))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
ans = []
SC = sorted(SC)

for x, item in enumerate(SC):
    if len(ans) + 1 < item[0]:
        if len(ans) == 0:
            ans.append(1)
        for y in range(item[0] -len(ans) - 1):
            ans.append(0)
    if len(ans) + 1 == item[0]:
        ans.append(item[1])
    elif len(ans) == item[0]:
        continue

if len(ans) < N:
    for x in range(N - len(ans)):
        ans.append(0)

if ans(0) == 0 and len(ans) != 0:
    print(-1)
else:
    ans = map(str, ans)
    print("".join(ans))
Problem p02829 (python)

Fixed submission:
A = int(input())
B = int(input())

if (A == 1 and B == 2) or (A == 2 and B == 1):
    print(3)

if (A == 1 and B == 3) or (A == 3 and B == 1):
    print(2)

if (A == 3 and B == 2) or (A == 2 and B == 3):
    print(1)

Buggy submission (verdict: Runtime Error):
import fractions

A, B = map(int, input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

print(lcm(A,B))
Problem p02831 (python)

Fixed submission:
import fractions

A, B = map(int, input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

print(lcm(A,B))

Buggy submission (verdict: Runtime Error):
import math

A, B = map(int, input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(A,B))
Problem p03013 (python)

Fixed submission:
r = 10 ** 9 + 7
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
dp = [0] * (N+1)
a = sorted(set(a))

if 1 in a:
    dp[1] = 0
    del a[0]
else:
    dp[1] = 1

if N == 1:
    print(dp[1])
    exit()

if 2 in a:
    dp[2] = 0
    del a[0]
else:
    dp[2] = dp[1] + 1

if N == 2:
    print(dp[2])
    exit()

for i in range(1,N-1):
    if a == [] :
        dp[i+2] = (dp[i] + dp[i+1]) % r
    elif i+2 == a[0]:
        dp[i+2] = 0
        del a[0]
    else:
        dp[i+2] = (dp[i] + dp[i+1]) % r

print(dp[N])

Buggy submission (verdict: Runtime Error):
r = 10 ** 9 + 7
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
dp = [0] * (N+1)
a = sorted(set(a))

if 1 in a:
    dp[1] = 0
    del a[0]
else:
    dp[1] = 1

if 2 in a:
    dp[2] = 0
    del a[0]
else:
    dp[2] = dp[1] + 1

if N == 1 or N == 2:
    print(dp[N])
    exit()

for i in range(1,N-1):
    if a == [] :
        dp[i+2] = (dp[i] + dp[i+1]) % r
    elif i+2 == a[0]:
        dp[i+2] = 0
        del a[0]
    else:
        dp[i+2] = (dp[i] + dp[i+1]) % r

print(dp[N])

Buggy submission (verdict: Runtime Error):
r = 10 ** 9 + 7
N, M = map(int, input().split())
a = [input() for _ in range(M)]
dp = [0] * (N+1)

if str(1) in a:
    dp[1] = 0
else:
    dp[1] = 1

if str(2) in a:
    dp[2] = 0
else:
    dp[2] = dp[1] + 1

for i in range(1,N-1):
    if str(i+2) in a:
        dp[i+2] = 0
    else:
        dp[i+2] = (dp[i] + dp[i+1]) % r

print(dp[N])
Problem p02659 (python)

Fixed submission:
from decimal import Decimal
import math
a, b = input().split()
res = Decimal(a) * Decimal(b)
print(math.floor(res))

Buggy submission (verdict: Runtime Error):
input math
a, b = map(float, input().split())
a *= b
print(math.floor(a))
Problem p02624 (python)

Fixed submission:
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in xrange(1, n + 1):
        for j in xrange(i, n + 1, i):
            table[j] += 1
    
    return table
  
n = int(input())  
a =  num_divisors_table(n)
ans = 0
for i in range(n+1):
  ans += i*a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in xrange(1, n + 1):
        for j in xrange(i, n + 1, i):
            table[j] += 1
    
    return table
  
n = int(input())  
a =  num_divisors_table(n)
ans = 0
for i in range(n+1):
  ans += i*a[i]
print(ans)
Problem p02753 (python)

Fixed submission:
S = input()
if((S[0] == S[1])and(S[1] == S[2])):
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
N,A,B = map(int,input().split())

ans = (N//(A+B))*A
tmp = N - (N//(A+B))*(A+B)
if(tmp <= A): ans += tmp
else: ans += tmp
print(ans)
Problem p02891 (python)

Fixed submission:
S = list(input())
K = int(input())
n = len(S)

#(方針)Sの「先頭(の連続)」と「末尾(の連続)」が同じ文字ならそこも連続に
#2連続→1回で置換できる,3連続→1回で置換できる,　「N連続→N//2回で置換できる」

A = [] #連続でちぎるようのリスト
count = 1
for i in range(n): 
 if(i != 0):
  if(S[i]== tmp): count += 1
  if((S[i] != tmp)or(i == n-1)):
    A.append([tmp,count])
    count = 1
 tmp = S[i]
if(n == 1): A.append([S[0],1])

ans = 0
for i in range(len(A)):
  if((i != 0)and(i != len(A)-1)):
   ans += (A[i][1]//2)*K
     
if(len(A) == 1):
   ans += (A[0][1]*K)//2  
elif(A[0][0] == A[-1][0]):
   ans += (A[0][1]//2) + (A[-1][1]//2) + ((A[0][1]+A[-1][1])//2)*(K-1) #最初の二項 : 結合後の先頭と末尾分 
elif(A[0][0] != A[-1][0]):
   ans += (A[0][1]//2)*K  
   ans += (A[-1][1]//2)*K
print(ans)

Buggy submission (verdict: Runtime Error):
S = list(input())
K = int(input())
n = len(S)

#(方針)Sの「先頭(の連続)」と「末尾(の連続)」が同じ文字ならそこも連続に
#2連続→1回で置換できる,3連続→1回で置換できる,　「N連続→N//2回で置換できる」

A = [] #連続でちぎるようのリスト
count = 1
for i in range(n): 
 if(i != 0):
  if(S[i]== tmp): count += 1
  if((S[i] != tmp)or(i == n-1)):
    A.append([tmp,count])
    count = 1
 tmp = S[i]
if(n == 1): A.append(S[0],1)

ans = 0
for i in range(len(A)):
  if((i != 0)and(i != len(A)-1)):
   ans += (A[i][1]//2)*K
     
if(len(A) == 1):
   ans += (A[0][1]*K)//2  
elif(A[0][0] == A[-1][0]):
   ans += (A[0][1]//2) + (A[-1][1]//2) + ((A[0][1]+A[-1][1])//2)*(K-1) #最初の二項 : 結合後の先頭と末尾分 
elif(A[0][0] != A[-1][0]):
   ans += (A[0][1]//2)*K  
   ans += (A[-1][1]//2)*K
print(ans)

Buggy submission (verdict: Runtime Error):
S = list(input())
K = int(input())
n = len(S)

#(方針)Sの「先頭(の連続)」と「末尾(の連続)」が同じ文字ならそこも連続に
#2連続→1回で置換できる,3連続→1回で置換できる,　「N連続→N//2回で置換できる」

A = [] #連続でちぎるようのリスト
count = 1
for i in range(n): 
 if(i != 0):
  if(S[i]== tmp): count += 1
  if((S[i] != tmp)or(i == n-1)):
    A.append([tmp,count])
    count = 1
 tmp = S[i]
if(n == 1): A.append(A[0],1)

ans = 0
for i in range(len(A)):
  if((i != 0)and(i != len(A)-1)):
   ans += (A[i][1]//2)*K
     
if(len(A) == 1):
   ans += (A[0][1]*K)//2  
elif(A[0][0] == A[-1][0]):
   ans += (A[0][1]//2) + (A[-1][1]//2) + ((A[0][1]+A[-1][1])//2)*(K-1) #最初の二項 : 結合後の先頭と末尾分 
elif(A[0][0] != A[-1][0]):
   ans += (A[0][1]//2)*K  
   ans += (A[-1][1]//2)*K
print(ans)

Buggy submission (verdict: Runtime Error):
S = list(input())
K = int(input())
n = len(S)

#(方針)Sの「先頭(の連続)」と「末尾(の連続)」が同じ文字ならそこも連続に
#2連続→1回で置換できる,3連続→1回で置換できる,　「N連続→N//2回で置換できる」

A = [] #連続でちぎるようのリスト
count = 1
for i in range(n): 
 if(i != 0):
  if(S[i]== tmp): count += 1
  if((S[i] != tmp)or(i == n-1)):
    A.append([tmp,count])
    count = 1
 tmp = S[i]

ans = 0
for i in range(len(A)):
  if((i != 0)and(i != len(A)-1)):
   ans += (A[i][1]//2)*K
     
if(len(A) == 1):
   ans += (A[0][1]*K)//2  
elif(A[0][0] == A[-1][0]):
   ans += (A[0][1]//2) + (A[-1][1]//2) + ((A[0][1]+A[-1][1])//2)*(K-1) #最初の二項 : 結合後の先頭と末尾分 
elif(A[0][0] != A[-1][0]):
   ans += (A[0][1]//2)*K  
   ans += (A[-1][1]//2)*K
print(ans)
Problem p03038 (python)

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

#counter 辞書(改良版)
def counter_imp(A):
 dic = {}                
 for a in A:
    dic[a] = dic.get(a,0) + 1
 return dic
#counter 2次元リスト
def counter_list(A):
 dic = counter_imp(A)
 C = []
 for k in dic:
    C.append([k,dic[k]])
 return C

#（発想）数値を全部追加してソート、大きい順に「Aの要素数」分の要素をとってきて和を求める
A = counter_list(A) 
for i in range(M):
 B,C = map(int,input().split())
 A.append([C,B]) #[C(数値),B(個数)]
 
A.sort(reverse = True) #降順ソート

num,n_index = 0,0 #num:現在和をとった要素の個数,n_index:現在の要素のインデックス
ans = 0 #求める和 
while(1):
  if(num == N): break
  if((N-num) >= A[n_index][1]):
   #N-num :残り必要な要素数
   #A[n_index][1] : 要素A[n_index][0]の個数
   ans += A[n_index][0]*A[n_index][1]
   num += A[n_index][1]
  else:
   ans += A[n_index][0]*(N-num)
   num = N
  n_index += 1 #indexを1つ進める
  
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))


#counter 2次元リスト
def counter_list(A):
 def counter_dic(A): #counter 辞書
  dic = {}
  for a in A:
  dic[a] = dic.get(a,0) + 1
  return dic

 dic_ = counter_dic(A)
 B = []
 for k in dic_:
 B.append([k,dic_[k]])
return B

#（発想）数値を全部追加してソート、大きい順に「Aの要素数」分の要素をとってきて和を求める
A = counter_list(A) 
for i in range(M):
 B,C = map(int,input().split())
 A.append([C,B]) #[C(数値),B(個数)]
 
A.sort(reverse = True) #降順ソート

num,n_index = 0,0 #num:現在和をとった要素の個数,n_index:現在の要素のインデックス
ans = 0 #求める和 
while(1):
  if(num == N): break
  if((N-num) >= A[n_index][1]):
   #N-num :残り必要な要素数
   #A[n_index][1] : 要素A[n_index][0]の個数
   ans += A[n_index][0]*A[n_index][1]
   num += A[n_index][1]
  else:
   ans += A[n_index][0]*(N-num)
   num = N
  n_index += 1 #indexを1つ進める
  
print(ans)
Problem p02682 (python)

Fixed submission:
A,B,C,K=list(map(int,input().split()))
nokori=K
maisu1=0
maisu2=0
maisu3=0
while True:
    if A<=nokori:
        maisu1=A
        nokori=nokori-maisu1
    else:
        maisu1=nokori
        break

    if B<=nokori:
        maisu2=B
        nokori=nokori-maisu2
    else:
        maisu2=nokori
        break
    
    maisu3=nokori
    break

print(maisu1-maisu3)

Buggy submission (verdict: Runtime Error):
A,B,C,K=list(map(int,input().split()))

while True:
    nokori=K
    if A<=nokori:
        maisu1=A
        nokori=nokori-maisu1
    else:
        maisu1=nokori
        break

    if B<=nokori:
        maisu2=B
        nokori=nokori-maisu2
    else:
        maisu2=nokori
        break
    
    if C<=nokori:
        maisu3=A
        nokori=nokori-maisu3
        break
    else:
        maisu3=nokori
        break

print(maisu1-maisu3)
Problem p02699 (python)

Fixed submission:
S, W = map(int, input().split())
if W >= S:
    print("unsafe")
else:
    print("safe")

Buggy submission (verdict: Runtime Error):
S, W = map(int, input().split())
if W >= S:
    print("unsafe")
else:
    safe
Problem p02711 (python)

Fixed submission:
N=input()
aru=0
for s in N:
    if s == "7":
        aru=1
        break
if aru==0:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
H=list(map(int,input().split()))

A=[0]*(N+1)
for i in range(M):
    x,y=map(int,input().split())
    A[x]=max(A[x],H[y-1])
    A[y]=max(A[y],H[x-1])

count=0
for i in range(1,N+1):
    if H[i-1]>A[i]:
        count+=1

print(count)