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

Fixed submission:
a1, b1 = (int(i) for i in raw_input().split(' '))
a2, b2 = (int(i) for i in raw_input().split(' '))
a3, b3 = (int(i) for i in raw_input().split(' '))


def func():
    count_1 = 0
    count_2 = 0
    count_3 = 0
    count_4 = 0
    for x in [a1,a2,a3,b1,b2,b3]:
        if x == 1:
            count_1 += 1
        elif x == 2:
            count_2 += 1
        elif x ==3:
            count_3 += 1
        elif x ==4:
            count_4 += 1
        else:
            print('error')

    for count in [count_1, count_2,count_3,count_4]:
        if count == 0 or count >= 3:
            print('NO')
            return
    print('YES')

func()

Buggy submission (verdict: Runtime Error):
a1, b1 = (int(i) for i in raw_input().split(' '))
a2, b2 = (int(i) for i in raw_input().split(' '))
a3, b3 = (int(i) for i in raw_input().split(' '))


def func():
    count_1 = 0
    count_2 = 0
    count_3 = 0
    count_4 = 0
    for x in [a1,a2,a3,b1,b2,b3]:
        if x == 1:
            count_1 += 1
        elif x == 2:
            count_2 += 1
        elif x ==3:
            count_3 += 1
        elif x ==4:
            count_4 += 1
        else:
            print('error')

    for count in [count_1, count_2,count_3,count_4]:
        if count == 0 or count >= 3:
            print('NO')
            return
    print('YES')

func()
Problem p03131 (python)

Fixed submission:
K, A, B = (int(i) for i in raw_input().split(' '))

action = K
cookie = 1

if A + 3 > B:
    cookie += K
    print(cookie)
else:
    init_break_n = min(action, A - cookie)
    action += -(init_break_n)
    cookie += init_break_n
    if action > 0:
        trade_n = int(action/2)
        cookie += (B-A)*trade_n
        if action % 2 == 1:
            cookie += 1
    print(cookie)

Buggy submission (verdict: Runtime Error):
K, A, B = (int(i) for i in raw_input().split(' '))

action = K
cookie = 1

if A + 3 > B:
    cookie += K
    print(cookie)
else:
    while(cookie < A):
        if(action <= 0):
            break
        action += -1
        cookie += 1
    if action > 0:
        trade_n = int(action/2)
        cookie += (B-A)*trade_n
        if action % 2 == 1:
            cookie += 1
    print(cookie)
Problem p02675 (python)

Fixed submission:
n = int(input())
if n % 10 == 3:
  print('bon')
elif n % 10 in [0, 1, 6, 8]:
  print('pon')
else:
  print('hon')

Buggy submission (verdict: Runtime Error):
n = int(input())
if n % 10 == 3:
  print('bon')
else if n % 10 in [0, 1, 6, 8]:
  print('pon')
else:
  print('hon')
Problem p02657 (python)

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

print(int(a) * int(b))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
print(a*b)
Problem p02681 (python)

Fixed submission:
s = input()
t = input()

print("Yes" if s == t[:-1] else "No")

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

if (a + b >= k or a == k) or (a == 0 and c == 0):
    print(a)
else:
    print(a + ((a+b) - k))
Problem p02718 (python)

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

n = nm[0]
m = nm[1]

a_s = sorted(a)[::-1]
if a_s[m-1] < sum(a)/(4*m):
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
nm = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

n = nm[0]
m = nm[1]

a_s = sorted(a)[::-1]
if a_s[m-1] < sum(a)/(4*m):
  print('No')
else:
  print('Yes')vv
Problem p02628 (python)

Fixed submission:
n, k = list(map(int, input().split()))
prices = list(map(int, input().split()))
prices = sorted(prices)
print(sum(prices[:k]))

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

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

prices = sorted(prices)

print(sum(prices[:k])
Problem p02657 (python)

Fixed submission:
A,B=map(int,input().split())
print(A*B)

Buggy submission (verdict: Runtime Error):
N=int(input())
A_list=list(map(int,input().split()))
ans=1
for i in A_list:
    ans*=i
    if ans>10**18:
        ans=-1
        break 
for i in A_list:
    if i==0:
        ans=0
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A_list=list(map(int,input().split()))
ans=1
for i in range(N):
    ans=ans*A_list[i]
    if ans>10**18:
        ans=-1
        break 
for i in A_list:
    if i==0:
        ans=0
print(ans)

Buggy submission (verdict: Runtime Error):
A,B=map(int,input(),split())
print(A*B)
Problem p03147 (python)

Fixed submission:
n=0
Answer=0
N=int(input())
h=list(map(int,input().split()))
h.insert(0,0)

for i in range(N):
    if h[n]<=h[n+1]:
        m=h[n+1]-h[n]
        Answer=Answer+m
    else :
        pass
    n=n+1
print(Answer)

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

for i in range(N):
    if h[i]<=h[i+1]:
        m=h[i+1]-h[i]
        Answer=Answer+m
        
print(Answer)
Problem p03164 (python)

Fixed submission:
IN=lambda:map(int,input().split())
N,W=IN()
INF=float("inf")
dp=[INF]*(1000*N)
dp.insert(0,0)
c=0
ans=0
for i in range(N):
    w,v=IN()
    for j in range((1000*N+1),-1,-1):
        if dp[j-v]!=INF:
            dp[j]=min(dp[j],dp[j-v]+w)
for i in range(1000*N+1):
    if dp[i]<=W:
        ans=i
print(ans)

Buggy submission (verdict: Runtime Error):
IN=lambda:map(int,input().split())
N,W=IN()
INF=float("inf")
dp=[INF]*(100*N)
dp.insert(0,0)
c=0
ans=0
for i in range(N):
    w,v=IN()
    for j in range((100*N+1),-1,-1):
        if dp[j-v]!=INF:
            dp[j]=min(dp[j],dp[j-v]+w)
for i in dp:
    c+=1
    if i<=W:
        ans=c-1
print(ans)

Buggy submission (verdict: Runtime Error):
N,W=map(int,input().split())
w=0
v=0
w_list=[]
v_list=[]
dp=[0]*(W+1)
for i in range (N):
    w,v=map(int,input().split())
    w_list.append(w)
    v_list.append(v)
for i in range (N):
    for j in range(W,-1,-1):
        if j>=w_list[i]:
            dp[j]=max(dp[j],dp[j-w_list[i]]+v_list[i])
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N,W=map(int,input().split())
w=0
v=0
w_list=[]
v_list=[]
dp=[0]*(W+1)
for i in range (N):
    w,v=map(int,input().split())
    w_list.append(w)
    v_list.append(v)
for i in range (N):
    for j in range(0,W+1,-1):
        if j>=w_list[i]:
            dp[j]=max(dp[j],dp[j-w_list[i]]+v_list[i])
print(dp[-1])
Problem p03434 (python)

Fixed submission:
N=int(input())
alise=0
bob=0
a_list=list(map(int,input().split()))
a_sort=sorted(a_list)
for i in range(N,0,-2):
    alise+=a_sort[i-1]
for i in range(N-1,0,-2):
    bob+=a_sort[i-1]
print(alise-bob)

Buggy submission (verdict: Runtime Error):
N=int(input())
alise=0
bob=0
a_list=list(map(int,input().split()))
a_sort=sorted(a_list)[::-1]
for i in range(N//2+N%2):
    alise+=a_sort.pop(0)
    bob+=a_sort.pop(0)
print(alise-bob)
Problem p03478 (python)

Fixed submission:
N,A,B=map(int,input().split())
ans=0 

for i in range(1,N+1):
    D=0
    for j in str(i):
        D+=int(j)
    if A<=D<=B:
        ans+=i
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=int(input())
B=int(input())
Answer=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            for l in range(10):
                if i*10**3+j*10**2+k*10+l<=N and A<=i+j+k+l<=B:
                    Answer.append(i*10**3+j*10**2+k*10+l)
print(sum(Answer))
Problem p02639 (python)

Fixed submission:
nums = list(map(int, input().split()))
print(nums.index(0)+1)

Buggy submission (verdict: Runtime Error):
#X匹Y本の組み合わせが存在するか判定。鶴の数を基準に連立方程式を解いて、鶴の数が正の整数であればYES
X,Y = map(int,input().split())
a = (4 * X - Y) / 2
if a.is_integer() and 0 <= a:
  print("Yes")
else:
  print("No")
Problem p02657 (python)

Fixed submission:
A,B = map(int,input().split())
print(A*B)

Buggy submission (verdict: Runtime Error):
N = int(input())
p = [int(i) for i in input().split()]
ans = 1

if 0 in p:
  print(0)
  exit()
  
for i in range(n):
  ans*=p[i]
  
if ans > 10 ** 18:
  print(-1)
  exit()
  
print(ans)
Problem p02658 (python)

Fixed submission:
N = int(input())
p = [int(i) for i in input().split()]
ans = 1

if 0 in p:
  print(0)
  exit()
  
for i in range(N):
  ans*=p[i]
  if ans > 10 ** 18:
    print(-1)
    exit()
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
p = [int(i) for i in input().split()]
ans = 1

if 0 in p:
  print(0)
  exit()
  
for i in range(N):
  ans*=p[i]
  if ans > 10 ** 18:
  print(-1)
  exit()
  
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
p = [int(i) for i in input().split()]
ans = 1

if 0 in p:
  print(0)
  exit()
  
for i in range(n):
  ans*=p[i]
  
if ans > 10 ** 18:
  print(-1)
  exit()
  
print(ans)
Problem p02675 (python)

Fixed submission:
N = int(input())
if N%10 in [2,4,5,7,9]:
  print('hon')
elif N%10 in [0,1,6,8]:
  print('pon')
else:
  print('bon')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

if S == T[0:-1]:
  print('Yes')
else:
  print('No')
Problem p03101 (python)

Fixed submission:
HW = [int(i) for i in input().split()]
hw = [int(i) for i in input().split()]

print((HW[0] - hw[0])*(HW[1] - hw[1]))

Buggy submission (verdict: Runtime Error):
HW = [int(i) for i in input().split()]
hw = [int(i) for i in input().split()]

print((HW[0] - hw[0])(HW[1] - hw[1]))
Problem p02657 (python)

Fixed submission:
a,b=[int(i) for i in input().split()]
print(a*b)

Buggy submission (verdict: Runtime Error):
a,b=input().split()
print(a*b)
Problem p02732 (python)

Fixed submission:
import math
 
def permutations_count(n, r):
    if r == 2:
        return int( (n*(n-1) ) / r )
    if r == 1:
        return n
 
 
N = int(input())
A = list(map(int,input().split()))
 
data = [0] * (N+1)
 
for i in range(N):
    data[A[i]] += 1
 
total = 0
 
for i in range(N+1):
    if data[i] >= 2:
        total += permutations_count(data[i],2)
 
 
 
for i in range(N):
    if data[A[i]] - 1 > 0 :
        print( total - permutations_count(data[A[i]]-1,1) )
    else:
        print(total)

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;

long long facto(long long n)
{
long long i,ans;
ans=1;
for(i=1;i<=n;i++) {
ans=ans*i;
}
return ans;
}


long long com(int n , int r){
    return ( facto(n) / ( facto(n-r) * facto(r) ) );
}

void comb(vector<vector <long long int> > &v){
  for(int i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(int k = 1;k <v.size();k++){
    for(int j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

int main(){
    long long N;
    cin >> N;
    int A[N];
    for(int i = 0 ; i< N ; i++){
        cin >> A[i];
    }

    long long data[N+1];
    for(int i = 0 ; i<N+1 ;i++){
        data[i] = 0;
    }

    for(int i = 0;i<N;i++){
        data[A[i]] += 1;
    }

    long long total = 0;

    for(int i =0;i<N;i++){
        if( data[i] >=2 ){
            total += com(data[i],2 );
        }
    }

    
    for(int i=0 ; i<N;i++){
        if(data[A[i]]-1>0){
            cout << total - com(data[A[i]]-1,1) << endl;
        }else{
            cout << total << endl;
        }
    
    }

    return 0;
}
Problem p02761 (python)

Fixed submission:
import sys

n , m = map(int,input().split())
#if m == 0:
#    m += 1
a = []

for i in range(m):
    a.append(list(map(int,input().split())))

ans = [-1] * n

for j in a:
    if ans[j[0]-1] == -1:
        if j[0] > n:
            print(-1)
            sys.exit()
        else:
            ans[j[0]-1] = j[1]
    elif ans[j[0]-1] == j[1]:
        continue
    else:
        print(-1)
        sys.exit()

if n == 3 and ans[0] == -1:
    ans[0] = 1

if n == 2 and ans[0] == -1:
    ans[0] = 1

for index,l in enumerate(ans):
    if l == -1 :
        ans[index] = 0
    elif index == 0 and n != 1:
        if ans[index] == 0:
            print(-1)
            sys.exit()

for index , x in enumerate(ans):
    ans[index] = str(ans[index])

b = "".join(ans)

if b == "000" or b == "00" or b == "0":
    print(0)
else:
    if len(b) == n:
        print(int(b))
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
import sys

n , m = map(int,input().split())
if m == 0:
    m += 1
a = []

for i in range(m):
    a.append(list(map(int,input().split())))

ans = [-1] * n

for j in a:
    if ans[j[0]-1] == -1:
        if j[0] > n:
            print(-1)
            sys.exit()
        else:
            ans[j[0]-1] = j[1]
    elif ans[j[0]-1] == j[1]:
        continue
    else:
        print(-1)
        sys.exit()

if n == 3 and ans[0] == -1 and ans[1] == 0:
    ans[0] = 1

for index,l in enumerate(ans):
    if l == -1 :
        ans[index] = 0
    elif index == 0 and n != 1:
        if ans[index] == 0:
            print(-1)
            sys.exit()

for index , x in enumerate(ans):
    ans[index] = str(ans[index])

b = "".join(ans)

if b == "000" or b == "00" or b == "0":
    print(0)
else:
    print(int(b))
Problem p02802 (python)

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

solve_problem = [0] * N 
wa = [0] * N
ans = 0

for i in range(0,M):
    ps = input().split(" ")
    if ps[1] == "AC":
        if solve_problem[ int(ps[0]) -1] == 0:
            solve_problem[int(ps[0]) -1] = 1
            ans += 1
    elif ps[1] == "WA":
        if solve_problem[ int(ps[0])-1] == 0:
            wa[int(ps[0]) -1 ] += 1

print(ans,sum(wa[i] for i in range(0,N) if solve_problem[i] == 1))

Buggy submission (verdict: Runtime Error):
N , M = map(int , input().split(" "))
#N = 100000
#M = 100000
solve_problem = [0] * N 
wa = [0] * N
ans = 0

for i in range(0,M):
    ps = input().split(" ")
    if ps[1] == "AC":
        if solve_problem[ int(ps[0]) -1] == 0:
            solve_problem[int(ps[0]) -1] = 1
            ans += 1
    elif ps[1] == "WA":
        if solve_problem[ int(ps[0])-1] == 0:
            wa[int(ps[0]) -1 ] += 1

print(ans,sum(wa[i] for i in range(0,N) if solve_problem[1] == 1))

Buggy submission (verdict: Runtime Error):
N , M = map(int , input().split(" "))
#N = 100000
#M = 100000
solve_problem = [0] * N 
wa = [0] * N
ans = 0

for i in range(0,M):
    ps = input().split(" ")
    if ps[1] == "AC":
        if solve_problem[ int(ps[0]) -1] == 0:
            solve_problem[int(ps[0]) -1] = 1
            ans += 1
    elif ps[1] == "WA":
        if solve_problem[ int(ps[0])-1] == 0:
            wa[int(ps[0]) -1 ] += 1



print(ans,sum(wa[i] for i in range(0,N) if solve_problem[1] == 1))
Problem p02909 (python)

Fixed submission:
str = input()

if str == "Sunny":
	print("Cloudy")
elif str == "Rainy":
	print("Sunny")
else:
	print("Rainy")

Buggy submission (verdict: Runtime Error):
I = input()
I = I.split(" ")
N = I[0]
K = I[1]
Q = I[2]

A = [0]*Q

for i in range(Q):
	A[i] = int(input())

point = [0]*N

for i in range(Q):
	point[A[i]-1] = point[A[i]-1] + 1

for i in range(Q):
	if point[i] > 0:
		print("yes")
	else:
		print("no")
Problem p02911 (python)

Fixed submission:
I = input()
I = I.split(" ")
N = int(I[0])
K = int(I[1])
Q = int(I[2])

A = [0] * Q

for i in range(Q):
	A[i] = int(input())

point = [0] * N

for i in range(Q):
	point[A[i]-1] = point[A[i]-1] + 1

for i in range(N):
	if Q - point[i] < K:
		print("Yes")
	else:
		print("No")

Buggy submission (verdict: Runtime Error):
I = input()
I = I.split(" ")
N = int(I[0])
K = int(I[1])
Q = int(I[2])

A = [0] * Q

for i in range(Q):
	A[i] = int(input())

point = [0] * N

for i in range(Q):
	point[A[i]-1] = point[A[i]-1] + 1

for i in range(N):
	if point[i] > k:
		print("yes")
	else:
		print("no")

Buggy submission (verdict: Runtime Error):
I = input()
I = I.split(" ")
N = I[0]
K = I[1]
Q = I[2]

A = [0]*Q

for i in range(Q):
	A[i] = int(input())

point = [0]*N

for i in range(Q):
	point[A[i]-1] = point[A[i]-1] + 1

for i in range(Q):
	if point[i] > 0:
		print("yes")
	else:
		print("no")

Buggy submission (verdict: Runtime Error):
I = input()
I = I.split(" ")
N = I[0]
K = I[1]
Q = I[2]

A = [0]*Q

for i in range(Q):
	A[i] = int(input())

point = [0]*N

for i in range(Q):
	point[A[i]] = point[A[i]] + 1

for i in range(Q):
	if point[i] > 0:
		print("yes")
	else:
		print("no")

Buggy submission (verdict: Runtime Error):
hoge = input()
hoge = hoge.split(" ")
N = int(hoge[0])
K = int(hoge[1])
Q = int(hoge[2])

A = [0] * Q

for i in range(Q):
	A[i] = int(input())

point = [K] * N

for i in range(Q):
	point = [point[i] - 1 for j in range(N)]
	point[A[i]] = point[A[i]] + 1

for i in range(N):
	if point[i] > 0:
		print("Yes")
	else:
		print("No")

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

N = int(hoge[0])
K = int(hoge[2])
Q = int(hoge[4])

A = [0] * Q

for i in range(Q):
	A[i] = int(input())

point = [K] * N

for i in range(Q):
	point = [point[i] - 1 for j in range(N)]
	point[A[i]] = point[A[i]] + 1

for i in range(N):
	if point[i] > 0:
		print("Yes")
	else:
		print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())
Q = int(input())

A = [0] * Q

for i in range(Q):
	A[i] = int(input())

point = [K] * N

for i in range(Q):
	point = [point[i] - 1 for j in range(N)]
	point[A[i]] = point[A[i]] + 1

for i in range(N):
	if point[i] > 0:
		print("Yes")
	else:
		print("No")
Problem p03160 (python)

Fixed submission:
#frog
N = int(input())
h = list(map(int,input().split()))
dp = [10000000000000] * N
dp[0] = 0

def dpf():
    for i in range(1,N):
        x = abs( h[i] - h[i-1] ) + dp[i-1]
        y = abs( h[i] - h[i-2] ) + dp[i-2]
        if x >=y:
            dp[i] = y
        else:
            dp[i] = x

def solve():
    dpf()
    print(dp[N-1])

if __name__ == "__main__":
    solve()

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

def dp(cost):
    for x in range(1,N):
        cost[x] =  min( [ cost[k] + abs( h[x] - h[k] ) for k in range(max(x-K,0),x) ] ) 
    return 0

def solve():
    cost = [float('inf')] * N
    cost[0] = 0
    dp(cost)
    print(cost[N-1])
    return 0

if __name__ == "__main__":
    solve()
Problem p03161 (python)

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

def dp(cost):
    for x in range(1,N):
        for k in range(max(x-K,0),x):
            cost[x] = min(cost[x] , cost[k] + abs( h[x] - h[k] ) )
        # cost[x] =  min( [ cost[k] + abs( h[x] - h[k] ) for k in range(max(x-K,0),x) ] ) 
    return 0

def solve():
    cost = [float('inf')] * N
    cost[0] = 0
    dp(cost)
    print(cost[N-1])
    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void)
{
	int N , K;
	cin >> N;
	cin >> K;
	int h[N];
	long long dp[N];
	long long inf=100000000000000000;
	for(int i = 0; i<N; i++){
		cin >> h[i];
		dp[i] = inf;
	}

	dp[0] = 0;

	for(int i = 0 ; i<N;i++){
		for(int j =1 ; j<=K ; j++){
			if(i+j >= N){
				break;
			}
			
			long long cost = abs(h[i] - h[i+j]) + dp[i];
			if( dp[i+j] > cost){
				dp[i+j] = cost;
				// cout << "i : " << i << " j : " << j << endl;
			}
		}

	}

	cout << dp[N-1] << endl;
}
Problem p03436 (python)

Fixed submission:
# import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
from copy import deepcopy
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

H , W = map(int,readline().split())
board = ["#" for _ in range(W+2)]
for  _ in range(H):
    board += ["#"] + list(readline().rstrip()) + ["#"]
board += ["0" for _ in range(W+2)]
white = 0
for tile in board:
    if tile == ".":
        white += 1
H , W = H+2 , W+2
visit = [-1 for _ in range(W*H)]
D = [ [1,0] , [0,1] , [-1,0] , [0,-1] ]

def bfs():
    root = W + 1
    q = deque([root])
    visit[root] = 1
    while q :
        index = q.popleft()

        if index == (H-2)*W+W-2:
            break

        x =  index // W
        y =  index % W
        for d in D :
            dx , dy = d
            X , Y = x+dx , y+dy
            if 1<=X and X<= H-1 and 1<=Y and Y <= W-1:
                dot = X*W+Y
                if visit[dot] == -1 and board[dot] == ".":
                    visit[dot] = visit[index] + 1
                    q.append(dot)

    length = visit[(H-2)*W+W-2]
    if  length == -1:
        return -1
    else:
        return white - length


def solve():
    print(bfs())

if __name__ == "__main__":
    solve()
    # print(board)

Buggy submission (verdict: Runtime Error):
# import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
from copy import deepcopy
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

H , W = map(int,readline().split())
board = ["#" for _ in range(W+2)]
for  _ in range(H):
    board += ["#"] + list(readline().rstrip()) + ["#"]
board += ["0" for _ in range(W+2)]
white = 0
for tile in board:
    if tile == ".":
        white += 1
H , W = H+2 , W+2
visit = [-1 for _ in range(W*H)]
D = [ [1,0] , [0,1] , [-1,0] , [0,-1] ]

def bfs():
    root = W + 1
    q = deque([root])
    visit[root] = 1
    while q :
        index = q.popleft()

        if index == (H-2)*W+W-2:
            break

        x =  index // W
        y =  index % W
        for d in D :
            dx , dy = d
            X , Y = x+dx , y+dy
            if 1<=X and X<= H-1 and 1<=Y and Y <= W-1:
                dot = X*W+Y
                if visit[dot] == -1 and board[dot] == ".":
                    visit[dot] = visit[index] + 1
                    q.append(dot)

    white -= max(0,visit[(H-2)*W+W-2])
    if white == 0:
        return -1
    else:
        return white


def solve():
    print(bfs())

if __name__ == "__main__":
    solve()
    # print(board)
Problem p02747 (python)

Fixed submission:
S = input()

i = 0
if len(S) % 2 != 0:
    print('No')
    exit()

while i + 1 <= len(S):
    if S[i] == 'h' and S[i+1] == 'i':
        i += 2
    else:
        break

if i == len(S):
    print('Yes')
else:
    print('No')

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

i = 0
while i + 1 <= len(S):
    if S[i] == 'h' and S[i+1] == 'i':
        i += 2
    else:
        break

if i == len(S):
    print('Yes')
else:
    print('No')
Problem p02843 (python)

Fixed submission:
X = int(input())
for c in range(X//100 + 1):
    if 100*c <= X and X <= 105*c:
        print(1)
        exit()

print(0)

Buggy submission (verdict: Runtime Error):
X = int(input())
items = range(100, 106)


def cal(x):
    if x == 0:
        print(1)
        exit()

    for i in items:
        if x >= i:
            cal(x-i)


cal(X)
print(0)
Problem p02952 (python)

Fixed submission:
N = input()
ans = 0
for n in range(1, len(N), 2):
    ans += 9 * 10 ** (n-1)

if len(N) == 1:
    ans = int(N)


elif len(N) % 2 != 0:
    ans += (10 ** (len(N)-1)) * (int(N[0])-1)
    ans += int(N[min(1, len(N)-1):]) + 1


print(ans)

Buggy submission (verdict: Runtime Error):
N = input()
ans = 0
for n in range(1, len(N), 2):
    ans += 9 * 10 ** (n-1)

if len(N) % 2 != 0:
    ans += ans * (int(N[0]) - 1)
    ans += int(N[1:]) + 1

print(ans)
Problem p02972 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split(' ')))
b = [0 for _ in range(N)]

a.insert(0, 0)
b.insert(0, 0)

n = int(N/2)

for i in range(N, 0, -1):
    nums = 0
    for ii in range(2, int(N/i)+1):
        nums += b[i*ii]

    if nums % 2 != a[i]:
        b[i] += 1

sum_b = sum(b)
print(sum_b)

flag = False
for i, bb in enumerate(b):
    if i == 0:
        continue

    if bb != 0:
        flag = True
        print(i, end=' ')

if flag:
    print()

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split(' ')[:-1]))
b = [0 for _ in range(N)]

a.insert(0, 0)
b.insert(0, 0)

n = int(N/2)

for i in range(N, 0, -1):
    nums = 0

    for ii in range(2, int(N/i)):
        nums += b[i*ii - 1]

    if nums % 2 != a[i]:
        b[i] += 1

sum_b = sum(b)
print(sum_b)

flag = True
for i, bb in enumerate(b):
    if i == 0:
        continue

    if bb != 0:
        flag = False
        print(i, end=' ')

if flag:
    print()