Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())

former = set(s[0])
latter = set(s[1:])
ans = len(former & latter)

for i in range(2, n):
	former = set(s[:i])
    latter = set(s[i:])
    if len(former & latter) > ans:
    	ans = len(former & latter)
        
print(ans)

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

former = set(s[0])
latter = set(s[1:])
ans = len(former & latter)

for i in range(2, n):
	former = set(s[:i])
	latter = set(s[i:])
	if len(former & latter) > ans:
		ans = len(former & latter)
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
bits = [[0 for _ in range(20)] for _ in range(n)]

for i in range(n):
	for j in range(20):
		bits[i][j] = (a[i] >> j) & 1

ans = 0
bits_sum = [0] * 20

r = 0
for l in range(n):
	r = max(r, l)
	while r < n:
		bits_sum = [bits_sum[j] + bits[r][j] for j in range(20)]
		if max(bits_sum) > 1:
			bits_sum = [bits_sum[j] - bits[r][j] for j in range(20)]
			break
		r += 1
	#print(bits_sum, r)
	ans += r-l
	bits_sum = [bits_sum[j] - bits[l][j] for j in range(20)]
	#print(bits_sum, r)

#ans += 1
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
bits = [[0 for _ in range(20)] for _ in range(n)]

for i in range(n):
	for j in range(20):
		bits[i][j] = (a[i] >> j) & 1

ans = 0
bits_sum = [0] * 20

r = 0
for l in range(n):
	r = max(r, l)
	while r < n:
		bits_sum = [bits_sum[j] + bits[r][j] for j in range(20)]
		if max(bits_sum) > 1:
			bits_sum = [bits_sum[j] - bits[r][j] for j in range(20)]
			break
		r += 1
	#print(bits_sum, r)
	ans += r-l
	bits_sum = [bits_sum[j] - bits[l][j] for j in range(20)]
	#print(bits_sum, r)

#ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

def check(x, y):
	if x & y == 0:
		return True
	else:
		return False

ans = n

for i in range(n - 1):
	x = a[i]
	for j in range(i + 1, n):
		y = a[j]
		if not check(x, y):
			break
		ans += 1
		x += y

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
bits = [[0 for _ in range(20)] for _ in range(n)]

for i in range(n):
	for j in range(20):
		bits[i][j] = (a[i] >> j) & 1

ans = 0
bits_sum = [0] * 20

r = 0
for l in range(n):
	r = max(r, l)
	while r < n:
		bits_sum = [bits_sum[j] + bits[r][j] for j in range(20)]
		if max(bits_sum) > 1:
			bits_sum = [bits_sum[j] - bits[r][j] for j in range(20)]
			break
		r += 1
	#print(bits_sum, r)
	ans += r-l
	bits_sum = [bits_sum[j] - bits[l][j] for j in range(20)]
	#print(bits_sum, r)

#ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

def check(x, y):
	if x & y == 0:
		return True
	else:
		return False

ans = n

for i in range(n - 1):
	x = a[i]
	for j in range(i + 1, n):
		y = a[j]
		if not check(x, y):
			break
		ans += 1
		x += y

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
bits = [[0 for _ in range(20)] for _ in range(n)]

for i in range(n):
	for j in range(20):
		bits[i][j] = (a[i] >> j) & 1

ans = 0
bits_sum = [0] * 20

r = 0
for l in range(n):
	r = max(r, l)
	while r < n:
		bits_sum = [bits_sum[j] + bits[r][j] for j in range(20)]
		if max(bits_sum) > 1:
			bits_sum = [bits_sum[j] - bits[r][j] for j in range(20)]
			break
		r += 1
	#print(bits_sum, r)
	ans += r-l
	bits_sum = [bits_sum[j] - bits[l][j] for j in range(20)]
	#print(bits_sum, r)

#ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
	return sys.stdin.readline()[:-1]

import heapq
n, k, q = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
a = [0] + a + [0]
ans = 10**30
for x in b:
	removed = []
	que = []
	for i in range(n+2):
		if a[i] < x:
			if len(que) >= k:
				removed += heapq.nsmallest(len(que)-k+1, que)
			que = []
		else:
			que.append(a[i])
	if len(removed) < q:
		continue
	removed.sort()
	ans = min(ans, removed[q-1] - x)
print(ans)

Fixed submission:
import sys, heapq
def input():
	return sys.stdin.readline()[:-1]

n, k, q = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
a = [0] + a + [0]
ans = 10**30
for x in b:
	removed = []
	que = []
	for i in range(n+2):
		if a[i] < x:
			que = []
		else:
			heapq.heappush(que, a[i])
			if len(que) == k:
				removed.append(heapq.heappop(que))
	if len(removed) < q:
		continue
	removed.sort()
	ans = min(ans, removed[q-1] - x)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n, k, q = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
a = [0] + a + [0]
ans = 10**30
for x in b:
	removed = []
	que = []
	for i in range(n+2):
		if a[i] < x:
			if len(que) >= k:
				removed += heapq.nsmallest(len(que)-k+1, que)
			que = []
		else:
			que.append(a[i])
	if len(removed) < q:
		continue
	removed.sort()
	ans = min(ans, removed[q-1] - x)
print(ans)

Fixed submission:
import sys, heapq
def input():
	return sys.stdin.readline()[:-1]

n, k, q = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
a = [0] + a + [0]
ans = 10**30
for x in b:
	removed = []
	que = []
	for i in range(n+2):
		if a[i] < x:
			que = []
		else:
			heapq.heappush(que, a[i])
			if len(que) == k:
				removed.append(heapq.heappop(que))
	if len(removed) < q:
		continue
	removed.sort()
	ans = min(ans, removed[q-1] - x)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = [int(input()) for _ in range(n)]

indeces = [0] * n

for i in range(n):
	indeces[p[i] - 1] = i

ans = 0

for i in range(n):
	j = i
	front = 0
	while True:
		if j == n - 1:
			break
		elif indeces[j] < indeces[j + 1]:
			front += 1
			j += 1
		else:
			break
	if front > ans:
		ans = front

print(n - ans - 1)

Fixed submission:
n = int(input())
p = [int(input()) for _ in range(n)]

indeces = [0] * n

for i in range(n):
	indeces[p[i] - 1] = i

ans = 0
pre_ans = 0

for i in range(n - 1):
	if indeces[i] < indeces[i + 1]:
		pre_ans += 1
	else:
		if pre_ans > ans:
			ans = pre_ans
		pre_ans = 0

if pre_ans > ans:
	ans = pre_ans

print(n - ans - 1)
Buggy python submission (verdict: Runtime Error):
class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x]) #xをxの根に直接つなぐ
			return self.table[x]

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 == s2:
			return
		else:
			st1 = self.table[s1]
			st2 = self.table[s2]
			if st1 > st2:
				self.table[s2] = s1
			elif st1 < st2:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1


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

uf = UnionFind(n)

for i in range(m):
	x, y = map(int, input().split())
	uf.union(x - 1, y - 1)

ans = 0
for i, pp in enumerate(p):
	if pp - 1 == i:
		ans += 1
	elif uf.find(pp - 1) == uf.find(i):
		ans += 1

print(ans)


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

subs = list()

for k in range(K):
	for i in range(len(s) - k):
		subs.append("".join(s[i : i + k + 1]))

subs = sorted(set(subs))
print(subs[K - 1])

Buggy python submission (verdict: Runtime Error):
class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		while self.table[x] >= 0:
			x = self.table[x]
		return x

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 == s2:
			return
		else:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1


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

uf = UnionFind(n)

for i in range(m):
	x, y = map(int, input().split())
	uf.union(x - 1, y - 1)

ans = 0
for i, pp in enumerate(p):
	if pp - 1 == i:
		ans += 1
	elif uf.find(pp - 1) == uf.find(i):
		ans += 1

print(ans)

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

subs = list()

for k in range(K):
	for i in range(len(s) - k):
		subs.append("".join(s[i : i + k + 1]))

subs = sorted(set(subs))
print(subs[K - 1])
Buggy python submission (verdict: Runtime Error):
import sys, time
def input():
	return sys.stdin.readline()[:-1]

n = int(input())
a = [list(map(int, input().split()))[::-1] for _ in range(n)]
#print(*a, sep="\n")
opponent = [-1 for _ in range(n)]
match = 0
day = 0
start_time = time.time()
while match < n*(n-1)//2:
	approved = False
	for i in range(n):
		if a[i] != [] and opponent[i] == -1:
			opponent[i] = a[i].pop()-1
	#print(opponent)
	for i in range(n):
		if opponent[i] != -1 and opponent[opponent[i]] == i:
			approved = True
			match += 1
			opponent[opponent[i]] = -1
			opponent[i] = -1
	#print(opponent)
	if not approved:
		print(-1)
		sys.exit()
	now = time.time()
	#print(start_time, now, now - start_time)
	if now-start_time > 1.6:
		print(n*(n-1)//2)
		sys.exit()
	day += 1
print(day)

Fixed submission:
class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def Sum(self, i):#1からiまでの和
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def Add(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

n = int(input())
s = [input().split() for _ in range(2*n)]
costb = [[0 for _ in range(n+1)] for _ in range(n+1)]
costw = [[0 for _ in range(n+1)] for _ in range(n+1)]
bitb, bitw = BIT(n), BIT(n)
for i in range(2*n-1, -1, -1):
	c, x = s[i][0], int(s[i][1])
	if c == "B":
		base = bitb.Sum(x-1)
		for j in range(n+1):
			costb[x-1][j] = base + bitw.Sum(j)
		bitb.Add(x, 1)
	else:
		base = bitw.Sum(x-1)
		for j in range(n+1):
			costw[j][x-1] = base + bitb.Sum(j)
		bitw.Add(x, 1)

dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n+1):
	for j in range(n+1):
		if i+j == 0:
			continue
		if i == 0:
			dp[i][j] = dp[i][j-1] + costw[i][j-1]
		elif j == 0:
			dp[i][j] = dp[i-1][j] + costb[i-1][j]
		else:
			dp[i][j] = min(dp[i][j-1] + costw[i][j-1], dp[i-1][j] + costb[i-1][j])

print(dp[n][n])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

def check(a):
    t = np.array(s[a:] + s[:a])
    t_t = t.T
    
    return (t == t_t).all()

ans = [check(a) for a in range(n)]
print(ans.count(True) * n)

Fixed submission:
n = int(input())
s = [list(input()) for _ in range(n)]

def check(a):
    t = s[a:] + s[:a]
    t_t = list(map(list, zip(*t)))
    
    return t == t_t

ans = [check(a) for a in range(n)]
print(ans.count(True) * n)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
MOD = m
list_size = n+2

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 1)) % MOD)

f_r_list = [pow(x, MOD-2, MOD) for x in f_list]

def comb(N, r):
	if N < r or r < 0:
		return 0
	else:
		return (((f_list[N] * f_r_list[N - r]) % MOD) * f_r_list[r]) % MOD 

st = [[0 for _ in range(n+1)] for _ in range(n+1)]
st[0][0] = 1
for i in range(1, n+1):
	st[i][0] = 1
	for j in range(1, i+1):
		st[i][j] = (st[i-1][j-1] + (j+1) * st[i-1][j]) % MOD

ans = 0
for i in range(n+1):
	res = (comb(n, i) * pow(2, pow(2, n-i, MOD-1), MOD)) % MOD
	tmp = 0
	for j in range(i+1):
		tmp += st[i][j] * pow(2, (n-i) * j, MOD)
		tmp %= MOD
	res *= tmp
	res %= MOD

	if i%2 == 0:
		ans += res
	else:
		ans -= res
	ans %= MOD

print(ans)

Fixed submission:
n, m = map(int, input().split())
MOD = m
list_size = n+2

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 1)) % MOD)

f_r_list = [pow(x, MOD-2, MOD) for x in f_list]

def comb(N, r):
	if N < r or r < 0:
		return 0
	else:
		return (((f_list[N] * f_r_list[N - r]) % MOD) * f_r_list[r]) % MOD 

st = [[0 for _ in range(n+1)] for _ in range(n+1)]
st[0][0] = 1
for i in range(1, n+1):
	st[i][0] = 1
	for j in range(1, i+1):
		st[i][j] = (st[i-1][j-1] + (j+1) * st[i-1][j]) % MOD

ans = 0
for i in range(n+1):
	res = (comb(n, i) * pow(2, pow(2, n-i, MOD-1), MOD)) % MOD
	tmp = 0
	for j in range(i+1):
		tmp += st[i][j] * pow(2, (n-i) * j, MOD)
		tmp %= MOD
	res *= tmp
	res %= MOD

	if i%2 == 0:
		ans += res
	else:
		ans -= res
	ans %= MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
INPUT = input()
X_list = list(map(int, INPUT.split()))

for i in range(N):
    X_list = list(map(int, INPUT.split()))
    del X_list[i]
    print(sorted(X_list)[int(N / 2 - 1)])

Fixed submission:
N = int(input())
INPUT = input()
X_list = list(map(int, INPUT.split()))
X_sorted = sorted(X_list)
criterion = X_sorted[int(N / 2 - 1)]

for i in range(N):
    if X_list[i] > criterion:
        print(criterion)
    else:
        print(X_sorted[int(N / 2)])
Buggy python submission (verdict: Runtime Error):
from math import sqrt

def func(a, b):
	if a == b:
		return (a - 1) * 2
	else:
		sq = int(sqrt(a * b))
		if a * b == sq ** 2:
			return (sq - 1) * 2 - 1
		elif sq * (sq + 1) >= a * b:
            return (sq - 1) * 2
		else:
			return sq * 2 - 1

q = int(input())
for _ in range(q):
	a, b = map(int, input().split())
	print(func(a, b))

Fixed submission:
from math import sqrt

def func(a, b):
	if a == b:
		return (a - 1) * 2
	else:
		sq = int(sqrt(a * b))
		if a * b == sq ** 2:
			return (sq - 1) * 2 - 1
		elif sq * (sq + 1) > a * b:
			return (sq - 1) * 2
		elif sq * (sq + 1) == a * b:
			if abs(a - b) == 1:
				return (sq - 1) * 2
			else:
				return (sq - 1) * 2
		else:
			return sq * 2 - 1

q = int(input())
for _ in range(q):
	a, b = map(int, input().split())
	print(func(a, b))
Buggy python submission (verdict: Runtime Error):
S = input()
alphabet = list("abcdefghijklmnopqrstuvwxyz")

if S == "zyxwvutsrqponmlkjihgfedcba":
     print(-1)
        
elif len(S) < 26:
    print(S + min(set(alphabet) - set(S)))
    
else:
    for i in range(26):
        if list(S)[-i] > list(S)[-(i + 1)]:
            j = i
            T = list.copy(list(S))
            a = min(T[-j + 1:])
            while a < T[-j + 1]:
                T.remove(a)
                j -= 1
                a = min(T[-i + 1:])
            
            print("".join(S[:-(i + 1)]) + min(list(S)[-i:]))
            break

Fixed submission:
S = input()
alphabet = list("abcdefghijklmnopqrstuvwxyz")

if S == "zyxwvutsrqponmlkjihgfedcba":
     print(-1)
        
elif len(S) < 26:
    print(S + min(set(alphabet) - set(S)))
    
else:
    for i in range(1, 27):
        if list(S)[-i] > list(S)[-(i + 1)]:
            break
    T = sorted(list(S)[-i:])
    #print(T)
    for t in T:
        if t > list(S)[-(i + 1)]:
            break
    print("".join(list(S)[:-(i + 1)]) + t)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit

n = int(input())
print(0, flush=True)
#outl = 0
in2 = input()
if in2 == "Vacant":
	exit()
print(n//2, flush=True)
#outr = n//2
in1 = input()
if in1 == "Vacant":
	exit()
#if ((n//2) % 2 == 0 and in1 != in2) or ((n//2) % 2 == 1 and in1 == in2):
	#outl = n//2
	#outr = n

#outl, outr = min(outl, outr), max(outl, outr)
outl, outr = 0, n

while True:
	#前半を見るパターン
	if (((outl+outr)//2) % 2 == 0 and in1 != in2) or ((outl+outr)//2) % 2 == 1 and in1 == in2):
		outr = (outl+outr)//2
		print((outl+outr)//2, flush=True)
		in2 = in1
		in1 = input()
		if in1 == "Vacant":
			exit()

	#後半を見るパターン
	else:
		outl = (outl+outr)//2
		print((outl+outr)//2, flush=True)
		in2 = in1
		in1 = input()
		if in1 == "Vacant":
			exit()

Fixed submission:
from sys import exit

n = int(input())
print(0, flush=True)
inl = input()
inr = inl
if inl == "Vacant":
	exit()
print(n//2, flush=True)
#outr = n//2
inm = input()
if inm == "Vacant":
	exit()

outl, outr = 0, n

while True:
	#前半を見るパターン
	if (((outl+outr)//2 - outl) % 2 == 0 and inl != inm) or (((outl+outr)//2 - outl) % 2 == 1 and inl == inm):
		outr = (outl+outr)//2
		print((outl+outr)//2, flush=True)
		inr = inm
		inm = input()
		if inm == "Vacant":
			exit()

	#後半を見るパターン
	else:
		outl = (outl+outr)//2
		print((outl+outr)//2, flush=True)
		inl = inm
		inm = input()
		if inm == "Vacant":
			exit()
Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt
from itertools import accumulate

prime = [2]
more_prime = [0] * 100000
for i in range(3, 100000):
	j = 2
	while j <= sqrt(i):
		if i % j == 0:
			break
		j += 1
	else:
		prime.append(i)
		if (i + 1) // 2 in prime:
			more_prime[i-1] = 1

ans = list(accumulate(more_prime))

q = int(input())
for _ in range(q):
	l, r = map(int, input().split())
	if l == 1:
		l = 2
	if r == 1:
		r = 2
	print(ans[r-1] - ans[l-2])

Fixed submission:
from math import sqrt
from itertools import accumulate

prime = [2]
more_prime = [0] * 100000
for i in range(3, 100000):
	j = 2
	while j <= sqrt(i):
		if i % j == 0:
			break
		j += 1
	else:
		prime.append(i)
		if (i + 1) // 2 in prime:
			more_prime[i-1] = 1

ans = list(accumulate(more_prime))

q = int(input())
for _ in range(q):
	l, r = map(int, input().split())
	if l == 1:
		l = 2
	if r == 1:
		r = 2
	print(ans[r-1] - ans[l-2])
Buggy python submission (verdict: Runtime Error):
s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in set_yoko) and (y in set_tate):
	print("Yes")
else:
	print("No")

Fixed submission:
s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

if list_yoko == []:
	list_yoko = [0]

if list_tate == []:
	list_tate = [0]
	
set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in set_yoko) and (y in set_tate):
	print("Yes")
else:
	print("No")

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

s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in sy) and (y in st):
	print("Yes")
else:
	print("No")

Fixed submission:
s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

if list_yoko == []:
	list_yoko = [0]

if list_tate == []:
	list_tate = [0]
	
set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in set_yoko) and (y in set_tate):
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
T = list(map(int, input().split()))
t = [0]
for i in range(n):
	t.append(t[-1] + T[i])
v = list(map(int, input().split()))

ans = 0
prev_spped = 0

for x in range(1, 2 * t[-1] + 1):
	time = x / 2
	speeds = [time, t[-1] - time]
	for i in range(n):
		if time <= t[i]:
			speeds.append(v[i] + t[i] - time)
		elif t[i] < time <= t[i + 1]:
			speeds.append(v[i])
		else:
			speeds.append(v[i] + time - t[i + 1])
	speed = min(speeds)
	ans += (speed + prev_spped) * 0.25
	prev_spped = speed

print(ans)

Fixed submission:
n = int(input())
T = list(map(int, input().split()))
t = [0]
for i in range(n):
	t.append(t[-1] + T[i])
v = list(map(int, input().split()))

ans = 0
prev_spped = 0

for x in range(1, 2 * t[-1] + 1):
	time = x / 2
	speeds = [time, t[-1] - time]
	for i in range(n):
		if time <= t[i]:
			speeds.append(v[i] + t[i] - time)
		elif t[i] < time <= t[i + 1]:
			speeds.append(v[i])
		else:
			speeds.append(v[i] + time - t[i + 1])
	speed = min(speeds)
	ans += (speed + prev_spped) * 0.25
	prev_spped = speed

print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
without_x = []
notx_index = []
for i in range(len(s)):
	if s[i] != "x":
		without_x.append(s[i])
		notx_index.append(i)
if without_x != without_x[::-1]:
	print(-1)
else:
	n = len(notx_index)
	#center_ind = (n-1) // 2
	x_num = [notx_index[0]]
	for i in range(n-1):
		x_num.append(notx_index[i+1] - notx_index[i] - 1)
	x_num.append(len(s)-1 - notx_index[n-1])
	#print(x_num)
	ans = 0
	for i in range(n // 2 + 1):
		ans += abs(x_num[i] - x_num[n-i])

	print(ans)

Fixed submission:
s = list(input())
without_x = []
notx_index = []
for i in range(len(s)):
	if s[i] != "x":
		without_x.append(s[i])
		notx_index.append(i)
if not without_x:
	print(0)
elif without_x != without_x[::-1]:
	print(-1)
else:
	n = len(notx_index)
	#center_ind = (n-1) // 2
	x_num = [notx_index[0]]
	for i in range(n-1):
		x_num.append(notx_index[i+1] - notx_index[i] - 1)
	x_num.append(len(s)-1 - notx_index[n-1])
	#print(x_num)
	ans = 0
	for i in range(n // 2 + 1):
		ans += abs(x_num[i] - x_num[n-i])

	print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
bits = dict()
bits[0] = 0
bit = 0
for i in range(n):
	x = ord(s[i])-97
	bit ^= (1<<x)
	for j in range(26):
		new_bit = bit ^ (1<<j)
		if new_bit in bits:
			#print(bin(bit)[2:], bin(new_bit)[2:])
			if bit in bits:
				bits[bit] = min(bits[bit], bits[new_bit] + 1)
			else:
				bits[bit] = bits[new_bit] + 1
			#print(bits[bit])
		#print("-----")
if bit not in bits:
	print(-1)
else:
	print(max(1, bits[bit]))

Fixed submission:
s = input()
n = len(s)
bits = dict()
bits[0] = 0
bit = 0
for i in range(n):
	x = ord(s[i])-97
	bit ^= (1<<x)
	for j in range(26):
		new_bit = bit ^ (1<<j)
		if new_bit in bits:
			#print(bin(bit)[2:], bin(new_bit)[2:])
			if bit in bits:
				bits[bit] = min(bits[bit], bits[new_bit] + 1)
			else:
				bits[bit] = bits[new_bit] + 1
			#print(bits[bit])
		#print("-----")
if bit not in bits:
	print(-1)
else:
	print(max(1, bits[bit]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
parity = [-1 for _ in range(n)]
valid = True

def dfs(x):
	global valid
	p = parity[x]
	for v in adj[x]:
		if parity[v] < 0:
			parity[v] = 1^p
			dfs(v)
		elif parity[v] == p:
			valid = False
			return
	return

for _ in range(m):
	a, b = map(int, input().split())
	adj[a-1].append(b-1)
	adj[b-1].append(a-1)

parity[0] = 0
dfs(0)
if not valid:
	print((n*(n-1)//2) - m)
else:
	o = sum(parity)
	print(o*(n-o) - m)

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

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
parity = [-1 for _ in range(n)]
valid = True

def dfs(x):
	global valid
	p = parity[x]
	for v in adj[x]:
		if parity[v] < 0:
			parity[v] = 1^p
			dfs(v)
		elif parity[v] == p:
			valid = False
			return
	return

for _ in range(m):
	a, b = map(int, input().split())
	adj[a-1].append(b-1)
	adj[b-1].append(a-1)

parity[0] = 0
dfs(0)
if not valid:
	print((n*(n-1)//2) - m)
else:
	o = sum(parity)
	print((n*(n-1)//2) - m - (o*(o-1)//2) - ((n-o)*(n-o-1)//2))