Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())

W = 10**9+7

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1,K+1):
    a = combinations_count(N-K+1, i) % W
    b = combinations_count(K-1, i-1) % W
    print((a*b) % W)




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

W = 10**9+7

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1,K+1):
    if (N-K+1) >= i and K-1 >= i-1:
        a = combinations_count(N-K+1, i) % W
        b = combinations_count(K-1, i-1) % W
        print((a*b) % W)
    else:
        print(0)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if (a+b)>=c:
	return c+b
else:
	return a+2*b

Fixed submission:
a, b, c = map(int, input().split())
if (a+b)>=c:
	print(c+b)
else:
	print(a+2*b+1)
Buggy python submission (verdict: Runtime Error):
n = input()
def sum_keta(m):
	sum_wa = 0
	while m>0:
		sum_wa = sum_wa + m%10
		m = int(m/10)

	return sum_wa

if sum_keta(n) == 1:
	print(10)
else:
	print(sum_keta(n))


Fixed submission:
n = input()
ans = 0
for ele in n:
  ans+=int(ele)
if ans==1:
  print(10)
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,k = list(map(int,input().split()))

unfair = 10^18

if k%2 ==0:
	if a-b <= unfair
		print(a-b)
	else:
		print('Unfair')
else:
	if b-a <= unfair
		print(b-a)
	else:
		print('Unfair')


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

unfair = 10**18

if k%2 ==0:
	if abs(a-b) <= unfair:
		print(a-b)
	else:
		print('Unfair')
else:
	if abs(b-a) <= unfair:
		print(b-a)
	else:
		print('Unfair')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)

N = int(input())
infants = []
for i, A in enumerate(map(int, input().split(' '))):
    infants.append((-A, i + 1))
infants.sort()
dp = [{} for _ in range(N)]


def search(i, l):
    # i番目の幼児を見ていて左にl人配置している
    if i == N:
        return 0
    if l in dp[i]:
        return dp[i][l]
    (act_val, pos) = infants[i]
    act_val = -act_val
    ans = max(search(i + 1, l + 1) + abs(l + 1 - pos) * act_val,
              search(i + 1, l) + abs(N - i + l - pos) * act_val)
    dp[i][l] = ans
    return ans


print(search(0, 0))

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
infants = []
for i, A in enumerate(map(int, input().split(' '))):
    infants.append((-A, i + 1))
infants.sort()
dp = [[-1 for _ in range(N + 1)] for _ in range(N + 1)]


def search(i, l):
    # i番目の幼児を見ていて左にl人配置している
    if i == N:
        return 0
    if dp[i][l] != -1:
        return dp[i][l]
    (act_val, pos) = infants[i]
    act_val = -act_val
    ans = max(search(i + 1, l + 1) + abs(l + 1 - pos) * act_val,
              search(i + 1, l) + abs(N - i + l - pos) * act_val)
    dp[i][l] = ans
    return ans


print(search(0, 0))

Buggy python submission (verdict: Runtime Error):
N = int(input())
infants = []
for i, A in enumerate(map(int, input().split(' '))):
    infants.append((-A, i + 1))
infants.sort()
dp = [{} for _ in range(N)]


def search(i, l):
    # i番目の幼児を見ていて左にl人配置している
    if i == N:
        return 0
    if l in dp[i]:
        return dp[i][l]
    (act_val, pos) = infants[i]
    act_val = -act_val
    ans = max(search(i + 1, l + 1) + abs(l + 1 - pos) * act_val,
              search(i + 1, l) + abs(N - i + l - pos) * act_val)
    dp[i][l] = ans
    return ans


print(search(0, 0))

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
infants = []
for i, A in enumerate(map(int, input().split(' '))):
    infants.append((-A, i + 1))
infants.sort()
dp = [[-1 for _ in range(N + 1)] for _ in range(N + 1)]


def search(i, l):
    # i番目の幼児を見ていて左にl人配置している
    if i == N:
        return 0
    if dp[i][l] != -1:
        return dp[i][l]
    (act_val, pos) = infants[i]
    act_val = -act_val
    ans = max(search(i + 1, l + 1) + abs(l + 1 - pos) * act_val,
              search(i + 1, l) + abs(N - i + l - pos) * act_val)
    dp[i][l] = ans
    return ans


print(search(0, 0))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
counter = {'R':0, 'G':0, 'B':0}
for s in S:
    counter[s] += 1

ans = counter['R'] * counter['G'] * counter['B']
for i in range(N):
    for j in range(i + 1, N):
        if S[i] != S[j] and 2 * j - i < N and S[i] != S[2 * j - i] and S[j] != S[2 * j - i]:
            ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = input()
counter = {'R':0, 'G':0, 'B':0}
for s in S:
    counter[s] += 1

ans = counter['R'] * counter['G'] * counter['B']
for i in range(N):
    for j in range(i + 1, N):
        if S[i] != S[j] and 2 * j - i < N and S[i] != S[2 * j - i] and S[j] != S[2 * j - i]:
            ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, R = map(int, input().split(" "))
if N >= 10:
  print(R)
else:
  print(R + 100 * (10 - K))

Fixed submission:
N, R = map(int, input().split(" "))
if N >= 10:
  print(R)
else:
  print(R + 100 * (10 - N))
Buggy python submission (verdict: Runtime Error):
N = int(input())
s, t = [], []
for i in range(N):
  s_i, t_i = [input().split(" ")]
  t_i = int(t_i)
  s.append(s_i)
  t.append(t_i)
X = input()

idx = 0
while idx < N:
  if s[idx] == X:
    idx += 1
    break
  idx += 1

ans = 0
for i in range(idx, N):
  ans += t[i]
print(ans)

Fixed submission:
N = int(input())
s, t = [], []
for i in range(N):
  s_i, t_i = input().split(" ")
  t_i = int(t_i)
  s.append(s_i)
  t.append(t_i)
X = input()

idx = 0
while idx < N:
  if s[idx] == X:
    idx += 1
    break
  idx += 1

ans = 0
for i in range(idx, N):
  ans += t[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
#include <iostream>
using namespace std;

int main(void){
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  cout << ((A1 + A2 + A3 >= 22) ? "bust" : "win") << endl;
  return 0;
}

Fixed submission:
A1, A2, A3 = map(int, input().split(" "))
print('bust' if A1 + A2 + A3 > 21 else 'win')
Buggy python submission (verdict: Runtime Error):
S = int(input())
ans = 0
for i in range(len(S)):
  if S[i] != S[::-1][i]:
    ans += 1
print(ans)

Fixed submission:
S = input()
ans = 0
for i in range(len(S)):
  if S[i] != S[::-1][i]:
    ans += 1
print(ans // 2)
Buggy python submission (verdict: Runtime Error):
m1, d1 = map(int, input().split(" "))
m2, d2 = map(int, input().split(" "))
print(1 if m2 = m1 + 1 else 0)

Fixed submission:
m1, d1 = map(int, input().split(" "))
m2, d2 = map(int, input().split(" "))
print(1 if m2 == m1 + 1 else 0)
Buggy python submission (verdict: Runtime Error):
import numpy as np

a, b, x = map(float, input().split(" "))
print(np.arctan(2 / a * (b - x / (a ** 2)) / np.pi * 180)

Fixed submission:
import math

def check(a, b, x, deg):
    theta = math.radians(deg)
    if b * math.cos(theta) >= a * math.sin(theta):
        return (a * a) * (b - a * math.tan(theta) / 2.0) >= x
    else:
        return (b * b * a) / (2.0 * math.tan(theta)) >= x


a, b, x = map(float, input().split(" "))
high, low = 90, 0   # [low, high)
while (high - low) > 1e-10:
    mid = (high + low) / 2
    if check(a, b, x, mid):
        low = mid
    else:
        high = mid
print(low)
Buggy python submission (verdict: Time Limit Exceeded):
def check(A, F, K, x):
    for i in range(len(A)):
        if A[i] * F[i] > x:
            need = (A[i] * F[i] - x + F[i] - 1) // F[i]
            if need > K:
                return False
            K -= need
    return True


N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
F = list(map(int, input().split(' ')))
A.sort()
F.sort()
F = F[::-1]

high, low = 10 ** 13, -1
while high - low > 1:
    mid = (high + low) // 2
    if check(A, F, K, mid):
        high = mid
    else:
        low = mid
print(high)

Fixed submission:
def check(A, F, K, x):
    for i in range(len(A)):
        if A[i] * F[i] > x:
            need = (A[i] * F[i] - x + F[i] - 1) // F[i]
            if need > K:
                return False
            K -= need
    return True


N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
F = list(map(int, input().split(' ')))
A.sort()
F.sort()
F = F[::-1]

high, low = 10 ** 13, -1
while high - low > 1:
    mid = (high + low) // 2
    if check(A, F, K, mid):
        high = mid
    else:
        low = mid
print(high)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

if S[0] != S[-1]:
    ans = 0
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S = S[:i] + '*' + S[i + 2:]
            ans += 1
    print(ans * K)
else:
    # S -> s_1 s_2 ... s_k + A + t_l t_l-1 ... t_1 (s_i = t_j)と分解
    k, l = 0, len(S) - 1
    while k < len(S) and S[k] == S[-1]:
        k += 1
    while l > -1 and S[l] == S[0]:
        l -= 1

    # 連結に関係ない部分のカウント
    A = S[k:l + 1]
    ans = 0
    for i in range(len(A) - 1):
        if A[i + 1] == A[i]:
            A = A[:i + 1] + '*' + A[i + 2:]
            ans += 1
    ans *= K

    # 連結に関係ある部分のカウント
    if l == -1 and k == len(S):
        # 全部同じ
        print((len(S) * K) // 2)
    else:
        ans += (len(S) - l + k - 1) // 2 * (K - 1)
        ans += (len(S) - l) // 2 + (k - 1) // 2
        print(ans)


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

if S[0] != S[-1]:
    ans = 0
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S = S[:i + 1] + '*' + S[i + 2:]
            ans += 1
    print(ans * K)
else:
    # S -> s_1 s_2 ... s_k + A + t_l t_l-1 ... t_1 (s_i = t_j)と分解
    k, l = 0, len(S) - 1
    while k < len(S) and S[k] == S[-1]:
        k += 1
    while l > -1 and S[l] == S[0]:
        l -= 1

    # 連結に関係ない部分のカウント
    A = S[k:l + 1]
    ans = 0
    for i in range(len(A) - 1):
        if A[i + 1] == A[i]:
            A = A[:i + 1] + '*' + A[i + 2:]
            ans += 1
    ans *= K

    # 連結に関係ある部分のカウント
    if l == -1 and k == len(S):
        # 全部同じ
        print((len(S) * K) // 2)
    else:
        ans += (len(S) - l + k - 1) // 2 * (K - 1)
        ans += (len(S) - l - 1) // 2 + k // 2
        print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()
print(((N + 1) // 2) / N)

Fixed submission:
N = int(input().strip())
print(((N + 1) // 2) / N)
Buggy python 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(" ")))
ans = B[A[0] - 1]
for i in range(1, N):
  ans += B[A[i] - 1]
  if A[i - 1] + 1 == A[i]:
    ans += C[A[i] - 1]
  
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split(" ")))
B = list(map(int, input().split(" ")))
C = list(map(int, input().split(" ")))
ans = B[A[0] - 1]
for i in range(1, N):
  ans += B[A[i] - 1]
  if A[i - 1] + 1 == A[i]:
    ans += C[A[i - 1] - 1]
  
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = [int(s) for s in input().split(" ")]

ans = 0
st = 0
for i in range(1, N):
  if H[i] - H[i - 1] > 0:
    ans = max(i - st - 1, ans)
    st = i

ans = max(ans, i - st)
print(ans)


Fixed submission:
N = int(input())
H = list(map(int, input().split(" ")))
H.reverse()
H.append(float('inf'))	# sentinel value
ans = 0
ind, counter = 0, 0

while ind < N:
  if H[ind] <= H[ind + 1]:
    counter += 1
    ind += 1
  else:
    ans = max(ans, counter)
    counter = 0
    ind += 1
print(max(ans, counter - 1))
Buggy python submission (verdict: Time Limit Exceeded):
import queue

class Tree:
    def __init__(self, ind):
        self.children = []
        self.counter = 0
        self.index = ind
        self.parent = -1


N, Q = map(int, input().split(" "))
tree = [Tree(i) for i in range(N)]
ans = [0 for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split(" "))
    tree[a - 1].children.append(b - 1)
    tree[b - 1].children.append(a - 1)

for i in range(Q):
    p, x = map(int, input().split(" "))
    tree[p - 1].counter += x

# bfs
que = queue.Queue()
que.put(0)  # root is 0

while not que.empty():
    ind = que.get()
    ans[ind] = tree[ind].counter
    for child in tree[ind].children:
        if child == tree[ind].parent:
            continue
        tree[child].counter += tree[ind].counter
        tree[child].parent = ind
        que.put(child)

print(' '.join([str(a) for a in ans]))

Fixed submission:
import queue
import sys
input = sys.stdin.readline

class Tree:
    def __init__(self, ind):
        self.children = []
        self.counter = 0
        self.index = ind
        self.parent = -1


N, Q = map(int, input().strip().split(" "))
tree = [Tree(i) for i in range(N)]
ans = [0 for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().strip().split(" "))
    tree[a - 1].children.append(b - 1)
    tree[b - 1].children.append(a - 1)

for i in range(Q):
    p, x = map(int, input().strip().split(" "))
    tree[p - 1].counter += x

# bfs
que = queue.Queue()
que.put(0)  # root is 0

while not que.empty():
    ind = que.get()
    ans[ind] = tree[ind].counter
    for child in tree[ind].children:
        if child == tree[ind].parent:
            continue
        tree[child].counter += tree[ind].counter
        tree[child].parent = ind
        que.put(child)

print(' '.join([str(a) for a in ans]))
Buggy python submission (verdict: Runtime Error):
K, X = map(int, input().split(" "))
print(' '.join([k for k in range(X - K + 1, X + K)]))

Fixed submission:
K, X = map(int, input().split(" "))
print(' '.join([str(k) for k in range(X - K + 1, X + K)]))
Buggy python submission (verdict: Runtime Error):
S = map(int, input().split("/"))
if S[1] >= 5:
  print("TBD")
else:
  print("Heisei")

Fixed submission:
S = list(map(int, input().split("/")))
if S[1] >= 5:
  print("TBD")
else:
  print("Heisei")

Buggy python submission (verdict: Runtime Error):
S = input().split("/")
if S[1] >= 5:
  print("TBD")
else:
  print("Heisei")

Fixed submission:
S = list(map(int, input().split("/")))
if S[1] >= 5:
  print("TBD")
else:
  print("Heisei")
Buggy python submission (verdict: Time Limit Exceeded):
def upper(arr, x):
    # xよりも大きい最小のindexを返す
    if arr[0] > x:
        return 0
    high, low = len(arr), 0
    while high - low > 1:
        mid = (high + low) // 2
        if arr[mid] > x:
            high = mid
        else:
            low = mid
    return high


def lower(arr, x):
    # xよりも小さい最大のindexを返す
    if arr[-1] < x:
        return len(arr) - 1
    high, low = len(arr) - 1, -1
    while high - low > 1:
        mid = (high + low) // 2
        if arr[mid] < x:
            low = mid
        else:
            high = mid
    return low


A, B, Q = map(int, input().split(' '))
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]

for _ in range(Q):
    x = int(input())
    shr_u, shr_l = upper(s, x), lower(s, x)
    tmp_u, tmp_l = upper(t, x), lower(t, x)
    ans = float('inf')
    if shr_u != A and tmp_u != B:
        ans = min(ans, max(s[shr_u] - x, t[tmp_u] - x))
    if shr_l != -1 and tmp_l != -1:
        ans = min(ans, max(x - s[shr_l], x - t[tmp_l]))
    if shr_l != -1 and tmp_u != B:
        cost = t[tmp_u] - s[shr_l] + min(x - s[shr_l], t[tmp_u] - x)
        ans = min(ans, cost)
    if shr_u != A and tmp_l != -1:
        cost = s[shr_u] - t[tmp_l] + min(s[shr_u] - x, x - t[tmp_l])
        ans = min(ans, cost)
    print(ans)

Fixed submission:
import sys
input = sys.stdin.readline


def upper(arr, x):
    # xよりも大きい最小のindexを返す
    if arr[0] > x:
        return 0
    high, low = len(arr), 0
    while high - low > 1:
        mid = (high + low) // 2
        if arr[mid] > x:
            high = mid
        else:
            low = mid
    return high


def lower(arr, x):
    # xよりも小さい最大のindexを返す
    if arr[-1] < x:
        return len(arr) - 1
    high, low = len(arr) - 1, -1
    while high - low > 1:
        mid = (high + low) // 2
        if arr[mid] < x:
            low = mid
        else:
            high = mid
    return low


A, B, Q = map(int, input().split(' '))
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]

for _ in range(Q):
    x = int(input())
    shr_u, shr_l = upper(s, x), lower(s, x)
    tmp_u, tmp_l = upper(t, x), lower(t, x)
    ans = 10 ** 18
    if shr_u != A and tmp_u != B:
        ans = min(ans, max(s[shr_u] - x, t[tmp_u] - x))
    if shr_l != -1 and tmp_l != -1:
        ans = min(ans, max(x - s[shr_l], x - t[tmp_l]))
    if shr_l != -1 and tmp_u != B:
        cost = t[tmp_u] - s[shr_l] + min(x - s[shr_l], t[tmp_u] - x)
        ans = min(ans, cost)
    if shr_u != A and tmp_l != -1:
        cost = s[shr_u] - t[tmp_l] + min(s[shr_u] - x, x - t[tmp_l])
        ans = min(ans, cost)
    print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
max_L = 0
sum_L = 0
for i in range(0, N):
  L = int(input())
  if L > max_L:
    max_L = L
  sum_L += L

if sum_L - max_L > max_L:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
L = [int(s) for s in input().split(" ")]
max_L = 0
sum_L = 0
for l in L:
  if l > max_L:
    max_L = l
  sum_L += l
 
if sum_L - max_L > max_L:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np
mod = 10 ** 9 + 7


def matpow(A, x):
    if x == 1:
        return A % mod
    elif x % 2 == 0:
        return matpow(np.linalg.matrix_power(A, 2) % mod, x // 2)
    else:
        ans = matpow(np.linalg.matrix_power(A, 2) % mod, x // 2)
        ans = ans.dot(A) % mod
        return ans


N, K = map(int, input().split(" "))
A = []
for _ in range(N):
    A.append(list(map(int, input().split(" "))))

A = np.array(A, dtype=np.int64)
print(np.sum(matpow(A, K) % mod) % mod)

Fixed submission:
import numpy as np
mod = 10 ** 9 + 7


def matpow(A, x):
    if x == 1:
        return A % mod
    elif x % 2 == 0:
        return matpow(np.linalg.matrix_power(A, 2) % mod, x // 2)
    else:
        ans = matpow(np.linalg.matrix_power(A, 2) % mod, x // 2)
        ans = ans.dot(A) % mod
        return ans


N, K = map(int, input().split(" "))
A = []
for _ in range(N):
    A.append(list(map(int, input().split(" "))))

A = np.array(A, dtype=object)
print(np.sum(matpow(A, K) % mod) % mod)
Buggy python submission (verdict: Runtime Error):
N, K = int(input())
print(0 if N%K == 0 else 1)

Fixed submission:
N, K = map(int, input().split(" "))
print(0 if N%K == 0 else 1)
Buggy python submission (verdict: Runtime Error):
D, N = input().split(" ")
D = int(D)
if int(N) == 100:
  N[2] = "1"
print(N+"0"*(2*D))


Fixed submission:
D, N = map(int, input().split(" "))
if N == 100:
  N += 1
print(N*100**D)
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input().split(''))
print(int((a+b+1)/2))

Fixed submission:
a, b = map(int,input().split(' '))
print(int((a+b+1)/2))

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(int((a+b+1)/2))

Fixed submission:
a, b = map(int,input().split(' '))
print(int((a+b+1)/2))
Buggy python submission (verdict: Runtime Error):
import collections

N = int(input())
a = [int(i) for i in input().split(" ")]
c = collections.Counter(a)
ans = 0

for key,val in c.items():
    del = max(val-key,val)
    if key == val:
        del = 0
    ans += del

print(ans)


Fixed submission:
import collections

N = int(input())
a = [int(i) for i in input().split(" ")]
c = collections.Counter(a)
ans = 0

for key,val in c.items():
    d = val
    if val >= key:
        d = min(val-key,val)
    ans += d

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
x,y = map(int,input().split(" "))
l = [len(c) for c in s.split("T")]
X = l[::2]
Y = l[1::2]

ansX = set([X[0]])
for i in range(1,len(X)):
    ansX = set([c+X[i] for c in ansX]+[c-X[i] for c in ansX]))

ansY = set([0])
for i in range(0,len(Y)):
    ansY = set([c+Y[i] for c in ansY]+[c-Y[i] for c in ansY]))
    
if x in ansX and y in ansY:
    print("Yes")
else:
    print("No")



Fixed submission:
s = input()
x,y = map(int,input().split(" "))
l = [len(c) for c in s.split("T")]
X = l[::2]
Y = l[1::2]

ansX = [X[0]]
for i in range(1,len(X)):
    if not X[i] == 0:
        ansX = list(set([c+X[i] for c in ansX]+[c-X[i] for c in ansX]))

ansY = [0]
for i in range(0,len(Y)):
    if not Y[i] == 0:
        ansY = list(set([c+Y[i] for c in ansY]+[c-Y[i] for c in ansY]))
    
if x in ansX and y in ansY:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N = input()
if len(set(N[0:2])) == 1 || len(set(N[1:3])):
  print("Yes")
else:
  print("No")

Fixed submission:
N = input()
if (N[0] == N[1] and N[1] == N[2]) or (N[1] == N[2] and N[2] == N[3]):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
def solve(s):
    l, r = 0, len(s) - 1

    ans = 0
    while l != r:
        if s[l] != s[r] and s[l] != 'x' and s[r] != 'x':
            return -1
        if s[l] == s[r]:
            l += 1
            r -= 1
        elif s[l] == 'x':
            ans += 1
            l += 1
        elif s[r] == 'x':
            ans += 1
            r -= 1
    return ans


if __name__ == '__main__':
    print(solve(input()))

Fixed submission:
def solve(s):
    l, r = 0, len(s) - 1

    ans = 0
    while l < r:
        if s[l] != s[r] and s[l] != 'x' and s[r] != 'x':
            return -1
        if s[l] == s[r]:
            l += 1
            r -= 1
        elif s[l] == 'x':
            ans += 1
            l += 1
        elif s[r] == 'x':
            ans += 1
            r -= 1
    return ans


if __name__ == '__main__':
    print(solve(input()))
Buggy python submission (verdict: Runtime Error):
N = int(input())
p = [int(i) for i in input().split(" ")]
ans = 0

for i in range(0,N):
    if p[i] == (i+1):
        if p[i+1] == (i+2):
            t = p[i]
            p[i] = p[i+1]
            p[i+1] = t
            ans += 1
        else:
            ans += 1
            d = -1 if i == N-1 else 1
            t = p[i]
            p[i] = p[i+d]
            p[i+d] = t
            
print(ans)


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

for i in range(0,N):
    if p[i] == (i+1):
        if i == N-1:
            ans += 1
        elif p[i+1] == (i+2):
            t = p[i]
            p[i] = p[i+1]
            p[i+1] = t
            ans += 1
        else:
            ans += 1
            t = p[i]
            p[i] = p[i+1]
            p[i+1] = t
            
print(ans)

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

for i in range(0,N):
    if p[i] == (i+1):
        if p[i+1] == (i+1):
            t = p[i]
            p[i] = p[i+1]
            p[i+1] = t
            ans += 1
        else:
            ans += 1
            d = -1 if i == N-1 else 1
            t = p[i]
            p[i] = p[i+d]
            p[i+d] = t
            
print(ans)


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

for i in range(0,N):
    if p[i] == (i+1):
        if i == N-1:
            ans += 1
        elif p[i+1] == (i+2):
            t = p[i]
            p[i] = p[i+1]
            p[i+1] = t
            ans += 1
        else:
            ans += 1
            t = p[i]
            p[i] = p[i+1]
            p[i+1] = t
            
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
A.sort()
diff = 10 ** 9

for i in range(N - 1):
    diff = min(A[i + 1] - A[i], diff)

if abs(A[0] - diff) > 0:
    diff = min(abs(A[0] - diff), diff)

can_make = False
for i in range(N):
    if A[i] % diff == K % diff and A[i] >= K:
        can_make = True

if can_make:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Fixed submission:
import fractions

N, K = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
A.sort()
diff = 10 ** 9

if max(A) < K:
    print('IMPOSSIBLE')
else:
    gcd = max(A)
    for i in range(N):
        gcd = fractions.gcd(gcd, A[i])

    if K % gcd == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')