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

Fixed submission:
n,m = map(int,raw_input().split())

arr = []

for i in range(n):
	arr.append(map(int,raw_input().split()))

v = [[1,1,1],[1,1,-1],[1,-1,-1],[1,-1,1],[-1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1]]

ans = 0

for i in range(8):
	tmp = []
	for j in range(n):
		tmp.append(arr[j][0] * v[i][0] + arr[j][1] * v[i][1] + arr[j][2] * v[i][2])

	tmp.sort()
	ans = max(ans,sum(tmp[n-m:]))

print ans

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

arr = []
for i in range(n):
	arr.append(map(int,raw_input().split()))


ans = float('-inf')

def check(k,o,f,p,i):
	global ans,m,n
	if i < n and p < m:
		check(k+arr[i][0],o+arr[i][1],f+arr[i][2],p+1,i+1)

	if i < n:
		check(k,o,f,p,i+1)

	if p == m:
		ans = max(ans,abs(k)+abs(o)+abs(f))


check(0,0,0,0,0)

print ans

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

arr = []
for i in range(n):
	arr.append(map(int,raw_input().split()))


ans = float('-inf')

def check(k,o,f,p,i):
	global ans,m,n
	if i < n:

		if p < m:
			check(k+arr[i][0],o+arr[i][1],f+arr[i][2],p+1,i+1)

		check(k,o,f,p,i+1)

	if p == m:
		ans = max(ans,abs(k)+abs(o)+abs(f))


check(0,0,0,0,0)

print ans

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

arr = []
for i in range(n):
	arr.append(map(int,raw_input().split()))


ans = -10000000
print arr
def check(k,o,f,p,i):
	global ans,m,n
	if i < n:

		if p < m:
			check(k+arr[i][0],o+arr[i][1],f+arr[i][2],p+1,i+1)

		check(k,o,f,p,i+1)

	if p == m:
		ans = max(ans,abs(k)+abs(o)+abs(f))


check(0,0,0,0,0)

print ans
Problem p03426 (python)

Fixed submission:
h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

distance = [0 for i in range(90001)]


n = int(input())

arr = [[] for i in range(90001)]

inputs = []

for i in range(n):
	inputs.append(map(int,raw_input().split()))


for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]

for i in range(d+1,h*w+1):
	distance[i] = distance[i-d] + abs(arr[i][0] - arr[i-d][0]) + abs(arr[i][1] - arr[i-d][1])


for i in range(n):
	l,r = inputs[i]

	print distance[r]-distance[l]

Buggy submission (verdict: Runtime Error):
h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

n = int(input())

arr = [[] for i in range(901)]

inputs = []

for i in range(n):
	inputs.append(map(int,raw_input().split()))


for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]


for i in range(n):
	l,r = inputs[i]

	ans = 0

	t = 1
	while l + d * t <= r:
		ans += abs(arr[l+d*t][0] - arr[l+d*(t-1)][0]) + abs(arr[l+d*t][1] - arr[l+d*(t-1)][1])
		t += 1

	print ans

Buggy submission (verdict: Runtime Error):
h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

n = int(input())

arr = [[] for i in range(901)]

for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]

for i in range(n):
	l,r = map(int,raw_input().split())

	ans = 0

	t = 1
	while l + d * t <= r:
		ans += abs(arr[l+d*t][0] - arr[l+d*(t-1)][0]) + abs(arr[l+d*t][1] - arr[l+d*(t-1)][1])
		t += 1

	print ans
Problem p03634 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**5+100)
n = int(input())

edges = [[] for _ in xrange(n)]
distance = [-1 for _ in xrange(n)]

for _ in xrange(n-1):
	f,t,c = map(int,raw_input().split())

	f -= 1
	t -= 1

	edges[f].append((t,c))
	edges[t].append((f,c))

q,k = map(int,raw_input().split())
k -= 1

def dfs(v,c):
	if distance[v] == -1:
		distance[v] = c
		for to,cost in edges[v]:
			dfs(to,c+cost)

dfs(k,0)

for _ in xrange(q):
	x,y = map(int,raw_input().split())
	x -= 1
	y -= 1
	print distance[x] + distance[y]

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

edges = [[] for _ in xrange(n)]
distance = [-1 for _ in xrange(n)]

for _ in xrange(n-1):
	f,t,c = map(int,raw_input().split())

	f -= 1
	t -= 1

	edges[f].append((t,c))
	edges[t].append((f,c))

q,k = map(int,raw_input().split())
k -= 1

def dfs(v,c):
	if distance[v] == -1:
		distance[v] = c
		for to,cost in edges[v]:
			dfs(to,c+cost)

dfs(k,0)

for _ in xrange(q):
	x,y = map(int,raw_input().split())
	x -= 1
	y -= 1
	print distance[x] + distance[y]

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

edges = [[] for i in range(n)]
distance = [-1 for i in range(n)]

for i in range(n-1):
	f,t,c = map(int,raw_input().split())

	f -= 1
	t -= 1

	edges[f].append([t,c])
	edges[t].append([f,c])

q,k = map(int,raw_input().split())
k -= 1

def dfs(v,c):
	if distance[v] == -1:
		distance[v] = c
		for to,cost in edges[v]:
			dfs(to,c+cost)

dfs(k,0)

for i in range(q):
	x,y = map(int,raw_input().split())
	x -= 1
	y -= 1
	print distance[x] + distance[y]

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

edges = [[] for i in range(n)]
distance = [-1 for i in range(n)]

for i in range(n-1):
	f,t,c = map(int,raw_input().split())

	f -= 1
	t -= 1

	edges[f].append([t,c])
	edges[t].append([f,c])

q,k = map(int,raw_input().split())
k -= 1

def dfs(v,c):
	if distance[v] == -1:
		distance[v] = c
		for to,cost in edges[v]:
			print to,cost
			dfs(to,c+cost)

dfs(k,0)

for i in range(q):
	x,y = map(int,raw_input().split())
	x -= 1
	y -= 1
	print distance[x] + distance[y]
Problem p03705 (python)

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

ans =  (a + b*(n - 1) ) - (a*(n-1) + b) + 1 
print ans if ans > 0 else 0

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

print (a + b(n - 1) ) - (a(n-1) + b) + 1
Problem p02873 (python)

Fixed submission:
s = input()
a = [0] * (len(s) + 1)
cur = 0
for i in range(len(s)):
  a[i] = cur
  cur = 0 if s[i] == '>' else cur + 1 
a[-1] = cur
cur = 0
for i in reversed(range(len(s))):
  a[i + 1] = max(a[i + 1], cur)
  cur = 0 if s[i] == '<' else cur + 1
a[0] = max(a[0], cur)
print(sum(a))

Buggy submission (verdict: Runtime Error):
s = input()
a = [0] * (len(s) + 1)
cur = 0
for i in range(len(s)):
  a[i] = cur
  cur = 0 if s[i] == '>' else cur + 1 
a[-1] = cur
cur = 0
for i in range(len(s)).reversed():
  a[i + 1] = max(a[i + 1], cur)
  cur = 0 if s[i] == '<' else cur + 1
a[0] = max(a[0], cur)
print(sum(a))
Problem p02879 (python)

Fixed submission:
A, B = (int(i) for i in input().split())  
if 1 <= A < 10 and  1 <= B < 10 :
    ans = A * B
    print(ans)
else :
    ans = -1
    print(ans)

Buggy submission (verdict: Runtime Error):
A, B = (int(i) for i in input().split())  
if 1 <= A < 10 and  1 <= B < 10 :
    ans = A * B
    print({}.ans)
else :
    print(str(-1))A, B = (int(i) for i in input().split())  
if 1 <= A < 10 and  1 <= B < 10 :
    ans = A * B
    print(ans)
else :
    print(str(-1))

Buggy submission (verdict: Runtime Error):
A, B = (int(i) for i in input().split())  
if 1 <= A < 10 and  1 <= B < 10 :
    ans = A * B
    print({}.ans)
else :
    print(str(-1))
Problem p02897 (python)

Fixed submission:
N = int(input())

if N % 2 == 0 :
    n_even = int(N / 2)
    n_odd = n_even
    chance = n_odd / N
    print(chance)
    
else :
    n_even = int(N / 2)
    n_odd = n_even + 1
    chance = n_odd / N
    print(chance)

Buggy submission (verdict: Runtime Error):
N = input()
n_even = int(N / 2)
n_odd = n_even + 1
chance = float(n_odd / N)
print(chance)
Problem p03634 (python)

Fixed submission:
#!/usr/bin/env python3
import collections
import sys
sys.setrecursionlimit(int(1e7))

def dfs(n, pre, T, dist, d) :
	dist[n] = d
	for i in T[n] :
		if i[0] != pre :
			dfs(i[0], n, T, dist, d + i[1])


N = int(input())
T = collections.defaultdict(lambda : [])
for i in range(N-1) :
	a, b, c = map(int, input().split())
	T[a].append((b, c))
	T[b].append((a, c))
Q, K = map(int, input().split())

d = {}
dfs(K, -1, T, d, 0)

for i in range(Q) :
	x, y = map(int, input().split())
	print(d[x]+d[y])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import collections

def dfs(n, pre, T, dist, d) :
	dist[n] = d
	for i in T[n] :
		if i[0] != pre :
			dfs(i[0], n, T, dist, d + i[1])


N = int(input())
T = collections.defaultdict(lambda : [])
for i in range(N-1) :
	a, b, c = map(int, input().split())
	T[a].append((b, c))
	T[b].append((a, c))
Q, K = map(int, input().split())

d = {}
dfs(K, -1, T, d, 0)

for i in range(Q) :
	x, y = map(int, input().split())
	print(d[x]+d[y])
Problem p02880 (python)

Fixed submission:
N=int(input())

a=0
if N>81:
  print('No')
elif N<1:
  print('No')
else:
  for i in range(1,10):
    if N%i==0:
      if N/i<=9:
          print('Yes')
          a=1
          break
  if a==0:
    print('No')

Buggy submission (verdict: Runtime Error):

N=int(input())

a=0
if N>81:
  print('No')
elif N<1:
  print('No')
else:
  for i in range(1,9):
    if N%i==0:
      if N/i<=9:
	    print('Yes')
      	a=1
      	break
  if a==0:
    print('No')
Problem p03038 (python)

Fixed submission:

N,M=map(int,input().split())


A=[int(i) for i in (input().split(" "))]

A.sort()

BC = [list(map(int,input().split())) for _ in range(M)]

BC.sort(key=lambda x:x[1],reverse=True)

for b,c in BC:
    A.extend([c]*b)
    if len(A)>2*N:
        break

A.sort(reverse=True)
suma=0
#for i in A:
#    suma+=i

print(sum(A[:N]))

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


A=[int(i) for i in (input().split(" "))]

A.sort()

BC = [list(map(int,input().split())) for _ in range(M)]

BC.sort(key=lambda x:x[1],reverse=True)

for b,c in BC:
    A.expend([c]*b)
    if len(A)>2*N:
        break

A.sort(reverse=True)
suma=0
#for i in A:
#    suma+=i

print(sum(A[:N]))
Problem p02880 (python)

Fixed submission:
N = int(input())

def isPrime(n) : 
  
    # Corner cases 
    if (n <= 1) : 
        return False
    if (n <= 3) : 
        return True
  
    # This is checked so that we can skip  
    # middle five numbers in below loop 
    if (n % 2 == 0 or n % 3 == 0) : 
        return False
  
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
  
    return True

if N<=9:
  print("Yes")
elif ( N == 50 or N ==60 or N == 70 or N == 80 or isPrime(N) or N>81):
  print("No")
else:
  i = 2
  while(i<=9):
    if N%i == 0 and 1<=N/i <= 9:
      print("Yes")
      break
    else:
      if i == 9:
        print("No")
        break
      else:
        i = i + 1

Buggy submission (verdict: Runtime Error):
N = int(input())
if N>=1 and N<=81 and N!=30 and N!=50 and N!=60 and N!=70 and N!=80:
  print("Yes)
else:
  print("No")
Problem p02935 (python)

Fixed submission:
n = int(input())
numbers = list(map(int,input().split()))
 
def aaa(numbers):
    if len(numbers) > 1:
        numbers.sort()
        new_number = (numbers[0] + numbers[1]) / 2
        n_0 = numbers[0]
        n_1 = numbers[1]
        numbers.remove(n_0)
        numbers.remove(n_1)
        numbers.append(new_number)
        aaa(numbers)
    else:
        return numbers[0]
      
aaa(numbers)
print(aaa(numbers))

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

b = []
for j in range(q):
    b.append((input()))
    
aws = []
for k in range(n):
    aws.append(0)
    
def tree(t_num,point):
    aws[t_num - 1] +=  point
    for an in a:
        if t_num == int(an.split()[0]):
            tree(int(an.split()[1]),point)
for bn in b:
    t_num = int(bn.split()[0])
    point = int(bn.split()[1])
    tree(t_num,point)
    
aws_2 = []
for h in aws:
    str_h = str(h)
    aws_2.append(str_h)
print(" ".join(aws_2))
Problem p03011 (python)

Fixed submission:
S = input().split()  

A = int(S[0])
B = int(S[1])
C = int(S[2])
answer_1 = A + B
answer_2 = A + C
answer_3 = B + C

print(min(answer_1,answer_2,answer_3))

Buggy submission (verdict: Runtime Error):
A, B, C = stdin.readline().rstrip().split()
A = int(A)
B = int(B)
C = int(C)
answer_1 = A + B
answer_2 = A + C
answer_3 = B + C

print(max(answer_1,answer_2,answer_3))

Buggy submission (verdict: Runtime Error):
A, B, C = stdin.readline().rstrip().split()
answer_1 = A + B
answer_2 = A + C
answer_3 = B + C

print(max(answer_1,answer_2,answer_3))
Problem p02933 (python)

Fixed submission:
a,s = int(input()),input()
if a >= 3200:
  print(s)
else:
  print('red')

Buggy submission (verdict: Runtime Error):
a,s = int(input()),input()
if a <= 3200:
  print(s)
else
  print('red')

Buggy submission (verdict: Runtime Error):
a,s = int(input()),input()
if a >= 3200:
  print(s)
else
  print('red')
Problem p02970 (python)

Fixed submission:
n, d = [int(x) for x in input().split()]

for i in range(n+1):
    if (2 * d + 1) * i >= n:
        ans = i
        break

print(ans)

Buggy submission (verdict: Runtime Error):
n, d = [int(x) for x in input().split()]

for i in range(n):
    if (2 * d + 1) * i >= n:
        ans = i
        break
print(ans)
Problem p03327 (python)

Fixed submission:
import sys

N = int(sys.stdin.readline())                                                                                                                                                        
if N < 1000:
    print('ABC')
else:
    print('ABD')

Buggy submission (verdict: Runtime Error):
import sys

a, b = tuple([int(x)for x in sys.stdin.readline().split()])
diff = max(a, b) - min(a, b)

c = 0
for i in range(1, 1000):
    if diff == i:
        print(c - a)
        break
    c += i
Problem p03329 (python)

Fixed submission:
import itertools
import math
import sys

MAX_N = 100000
MAX_LOG6 = int(math.log(MAX_N, 6))
MAX_LOG9 = int(math.log(MAX_N, 9))

def main(N):
    dp = [MAX_N] * (N + 1)
    for i in range(min(N + 1, 6)):
        dp[i] = i
    for i in range(N + 1):
        t = 1
        for j in range(1, MAX_LOG6 + 1):
            t *= 6
            if i - t < 0:
                break
            dp[i] = min(dp[i], dp[i - t] + 1)
        t = 1
        for j in range(1, MAX_LOG9 + 1):
            t *= 9
            if i - t < 0:
                break
            dp[i] = min(dp[i], dp[i - t] + 1)
    print(dp[N])

if __name__ == '__main__':
    N = int(sys.stdin.readline())
    main(N)

Buggy submission (verdict: Runtime Error):
import math
import sys

N = int(sys.stdin.readline())

queue = [(N, 1)]
min_cnt = math.inf

while queue:
    N, cnt = queue.pop()
    if N >= 9:
        v = math.pow(9, math.floor(math.log(N, 9)))
        if N - v >= 6 and cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) < min_cnt:
            min_cnt = cnt + int(N - v)
    if N >= 6:
        v = math.pow(6, math.floor(math.log(N, 6)))
        if cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) < min_cnt:
            min_cnt = cnt + int(N - v)

if math.isinf(min_cnt):
    print(N)
else:
    print(min_cnt)

Buggy submission (verdict: Runtime Error):
import math
import sys

N = int(sys.stdin.readline())

queue = [(N, 1)]
blacklist = set()
min_cnt = math.inf

while queue:
    N, cnt = queue.pop()
    if N >= 9:
        v = math.pow(9, math.floor(math.log(N, 9)))
        if N - v >= 6 and cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) < min_cnt:
            min_cnt = cnt + int(N - v)
    if N >= 6:
        v = math.pow(6, math.floor(math.log(N, 6)))
        if cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) < min_cnt:
            min_cnt = cnt + int(N - v)

if math.isinf(min_cnt):
    print(N)
else:
    print(min_cnt)

Buggy submission (verdict: Runtime Error):
import math
import sys

N = int(sys.stdin.readline())

min_leaf_cnt = math.inf

class Node:
    def __init__(self, N, cnt, v):
        self.N = N
        self.cnt = cnt
        self.v = v
        self.left = None
        self.right = None
        if self.cnt < min_leaf_cnt:
            self._fill_leaf()

    def _fill_leaf(self):
        if self.N >= 6:
            v = math.pow(6, math.floor(math.log(self.N, 6)))
            self.left = Node(self.N - v, self.cnt + 1, v)
        if self.N >= 9:
            v = math.pow(9, math.floor(math.log(self.N, 9)))
            self.right = Node(self.N - v, self.cnt + 1, v)
        if self.left is None and self.right is None:
            global min_leaf_cnt
            if self.cnt + self.N < min_leaf_cnt:
                min_leaf_cnt = self.cnt + int(self.N)

Node(N, 0, 0)
print(min_leaf_cnt)
Problem p02873 (python)

Fixed submission:
s=input()
l=[]
i=0
while i<len(s):
  k=0
  while s[i]=='<' if i<len(s) else False:
    k+=1
    i+=1
  if k>0:
    l.append(k)
  k=0
  while s[i]=='>' if i<len(s) else False:
    k+=1
    i+=1
  if k>0:
    l.append(k)
sm=0
for i in l:
  sm+=(i*(i+1))//2
for i in range(0 if s[0]=='<' else 1,len(l)-1,2):
  sm-=min(l[i],l[i+1])
 
  
print(sm)

Buggy submission (verdict: Runtime Error):
i=0
while i<len(s):
  k=0
  while s[i]=='<' if i<len(s) else False:
    k+=1
    i+=1
  if k>0:
    l.append(k)
  k=0
  while s[i]=='>' if i<len(s) else False:
    k+=1
    i+=1
sm=0
for i in l:
  sm+=(i*(i+1))//2
  
print(sm)
Problem p02873 (python)

Fixed submission:
s=input()

list=[0 for _ in range(len(s) + 1)]

def inc(n):
    if n < 0 or len(s) < n + 1:
        return
    if '<' == s[n]:
        if list[n] >= list[n + 1]:
            list[n + 1] += list[n] - list[n + 1] + 1
    elif '>' == s[n]:
        if list[n] <= list[n + 1]:
            list[n] += list[n + 1] - list[n] + 1

for i in range(0, len(s), 1):
    inc(i)

for i in range(len(s) - 1, -1, -1):
    inc(i)

print(sum(list))

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

list=[0 for _ in range(len(s) + 1)]

def inc(n):
    if n < 0 or len(s) < n + 1:
        return

    if '<' == s[n]:
        if list[n] >= list[n + 1]:
            list[n + 1] += list[n] - list[n + 1] + 1
            inc(n + 1)

    elif '>' == s[n]:
        if list[n] <= list[n + 1]:
            list[n] += list[n + 1] - list[n] + 1
            inc(n - 1)

for i in range(len(s)):
    inc(i)

print(sum(list))
Problem p03018 (python)

Fixed submission:
s = input()
pos = 0
cnt = 0
acnt = 0
if len(s) < 3:
    print(0)
else:
    while(True):
        if s[pos:pos+2] == "BC" and acnt > 0:
            pos += 2
            cnt += acnt
            # print(s, s[pos:pos+2], cnt, pos)
        else:
            if s[pos] == "A":
                acnt += 1
            else:
                acnt = 0
            pos += 1
        if pos >= len(s)-1:
            break
    print(cnt)

Buggy submission (verdict: Runtime Error):
s = input()
pos = 0
cnt = 0
if len(s) < 3:
    print(0)
else:
    while(True):
        if s[pos:pos+3] == "ABC":
            s = s[:pos] + "BCA" + s[pos+3:]
            if pos > 0:
                pos -= 1
            cnt += 1
        else:
            if s[pos+1:pos+3] == "AB":
                pos += 1
            elif s[pos+2:pos+3] == "A":
                pos += 2
            else
                pos += 3
        if pos >= len(s)-2:
            break
    print(cnt)
Problem p02873 (python)

Fixed submission:
S = input()
n = len(S)
ans = [0]*(n+1)
for i in range(n):
    if S[i]=='<':

        ans[i+1]=ans[i]+1
    # print(ans)
# print(ans)
for i in range(n-1,-1,-1):
    if S[i]==">":
        if ans[i]>ans[i+1]:
            continue
        else:
            ans[i]=ans[i+1]+1
    # print(ans)
res = 0
for i in range(n+1):
    res+=ans[i]
# print(ans)
print(res)

Buggy submission (verdict: Runtime Error):
S = input()
n = len(S)
ans = [0]*(n+1)
for i in range(n):
    if S[i]=='<':
        ans[i]=ans[i-1]+1
for i in range(n-1,-1,-1):
    if S[i]==">":
        ans[i]=ans[i+1]+1
res = 0
for i in range(n+1):
    res+=ans[i]
return res
Problem p02984 (python)

Fixed submission:
import numpy as np
N = int(input())
p = np.array(list(map(int,input().split())))
a0 = 0
for i in range(0,N,2):
    a0 += p[i]
    
for i in range(1,N-1,2):
    a0 -= p[i]
    
ans2 = [a0]*N
# iは-1している(slice)ので、+1しないといけないことに注意
for i,one in enumerate(p[1:]):
    ans2[i+1] = 2*p[i] - ans2[i] 
    
ans_s = ""
for one in ans2:
    ans_s += "{} ".format(one)
ans_s = ans_s[:-1]

print(ans_s)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
P = np.array(list(map(int,input().split())))*2
A = np.array([np.zeros(N)]*N)

for i in range(N):
    if i == 0:
        A[0][0] = 1
        A[-1][0] = 1
    else:
        A[i-1][i] = 1
        A[i][i] = 1
        
ans = [int(round(one,0)) for one in np.dot(np.linalg.pinv(A),P)]

ans_s = ""
for one in ans:
    ans_s += "{} ".format(one)
ans_s = ans_s[:-1]

print(ans_s)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
P = np.array(list(map(int,input().split())))*2
A = np.array([np.zeros(N)]*N)

for i in range(N):
    if i == 0:
        A[0][0] = 1
        A[-1][0] = 1
    else:
        A[i-1][i] = 1
        A[i][i] = 1
        
ans = [int(one) for one in np.dot(np.linalg.inv(A),P)]

ans_s = ""
for one in ans:
    ans_s += "{} ".format(one)
ans_s = ans_s[:-1]

print(ans_s)
Problem p02891 (python)

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

if len(s) == 1:
  print(k // 2)
else:
  cnt = 0
  p = 1
  while p < len(s):
    if s[p-1] == s[p]:
      cnt += 1
      p += 1
    p += 1
      
  cnt2 = 0
  p2 = 1
  s2 = s + s
  while p2 < len(s2):
    if s2[p2-1] == s2[p2]:
      cnt2 += 1
      p2 += 1
    p2 += 1

  flg = 1
  for i in range(len(s)-1):
    if s[i] != s[i+1]:
      flg = 0
  
  if 2*cnt < cnt2:
    if flg == 1:
      print(k*cnt + (k//2))
    else:
      print(k*cnt + (k - 1))
  else:
    print(k*cnt)

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

if len(s) == 1:
  print(k // 2)
else:
  cnt = 0
  p = 1
  while p < len(s):
    if s[p-1] == s[p]:
      cnt += 1
      p += 1
    p += 1
      
  cnt2 = 0
  p2 = 1
  s2 = s + s
  while p2 < len(s2):
    if s2[p2-1] == s2[p2]:
      cnt2 += 1
      p2 += 1
    p2 += 1

  if 2*cnt < cnt2:
    print(k*cnt + (k - 1))
  else:
    print(k*cnt)
    
s = s*k

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

if len(s) == 1:
  print(k // 2)
else:
  cnt = 0
  p = 1
  s = s*k
  while p < len(s):
    if s[p-1] == s[p]:
      cnt += 1
      p += 1
    p += 1
      
  print(cnt)

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

cnt = 0
p = 1
while p < len(s):
  if s[p-1] == s[p]:
    cnt += 1
    p += 1
  p += 1

cnt2 = 0
if s[0] == s[-1]:
  cnt2 += 1
  
cnt3 = 0
if s[-2] == s[-1]:
  cnt3 += 1

ans = k*cnt + (k - 1)*cnt2 - (k - 1)*cnt3
print(ans)
Problem p02879 (python)

Fixed submission:
A,B=map(int,input().split())
if 1<= A <= 9 and 1<= B <= 9:
    print(A*B)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
N = int(input())
if N%2==0 or N%3==0 or N%5==0 or N%7==0:
    print("Yes")
else:
    print("No")
Problem p02897 (python)

Fixed submission:
N = int(input())

if N%2 == 0:
    print((N/2)/N)
else:
    print(((N+1)/2)/N)

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

for i in range(N):
    if K <= h[i]:
        count += 1
print(count)