Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = [int(input()) for _ in range(n)]
p, q = nums.index(1), nums.index(n)
a, b = 1, 1
s = 0

for i in range(2, n+1):
    if  p < nums.index(i):
        a += 1
    else:
        s = max(s, a)
        a = 1
    p = nums.index(i)
s = max(s, a)
for j in range(n, 0, -1):
    if  q > nums.index(j):
        b += 1
    else:
        s = max(s, b)
        b = 1
    q = nums.index(j)
s = max(s, b)
print(n - s)

Fixed submission:
n = int(input())
nums = [int(input()) for _ in range(n)]
mem = [0] * (n + 1)
a, b = 1, 1
s = 0
for i in range(n):
    mem[nums[i]] += i

p, q = mem[1], mem[n]

for i in range(2, n+1):
    if  p < mem[i]:
        a += 1
    else:
        s = max(s, a)
        a = 1
    p = mem[i]
s = max(s, a)
for j in range(n, 0, -1):
    if  q > mem[j]:
        b += 1
    else:
        s = max(s, b)
        b = 1
    q = mem[j]
s = max(s, b)
print(n - s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = [int(input()) for _ in range(n)]
p, q = nums.index(1), nums.index(n)
a, b = 1, 1
keep = []

for i in range(2, n+1):
    if  p < nums.index(i):
        a += 1
    else:
        keep.append(a)
        a = 1
    p = nums.index(i)
keep.append(a)
for j in range(n, 0, -1):
    if  q > nums.index(j):
        b += 1
    else:
        keep.append(b)
        b = 1
    q = nums.index(j)
keep.append(b)
print(n - max(keep))

Fixed submission:
n = int(input())
nums = [int(input()) for _ in range(n)]
mem = [0] * (n + 1)
a, b = 1, 1
s = 0
for i in range(n):
    mem[nums[i]] += i

p, q = mem[1], mem[n]

for i in range(2, n+1):
    if  p < mem[i]:
        a += 1
    else:
        s = max(s, a)
        a = 1
    p = mem[i]
s = max(s, a)
for j in range(n, 0, -1):
    if  q > mem[j]:
        b += 1
    else:
        s = max(s, b)
        b = 1
    q = mem[j]
s = max(s, b)
print(n - s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = [int(input()) for _ in range(n)]
p, q = nums.index(1), nums.index(n)
a, b = 1, 1
keep = []

for i in range(2, n+1):
    if  p < nums.index(i):
        a += 1
        keep.append(a)
    else:
        keep.append(a)
        a = 1
    p = nums.index(i)
for j in range(n, 0, -1):
    if  q > nums.index(j):
        b += 1
        keep.append(b)
    else:
        keep.append(b)
        b = 1
    q = nums.index(j)

print(n - max(keep))

Fixed submission:
n = int(input())
nums = [int(input()) for _ in range(n)]
mem = [0] * (n + 1)
a, b = 1, 1
s = 0
for i in range(n):
    mem[nums[i]] += i

p, q = mem[1], mem[n]

for i in range(2, n+1):
    if  p < mem[i]:
        a += 1
    else:
        s = max(s, a)
        a = 1
    p = mem[i]
s = max(s, a)
for j in range(n, 0, -1):
    if  q > mem[j]:
        b += 1
    else:
        s = max(s, b)
        b = 1
    q = mem[j]
s = max(s, b)
print(n - s)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = list(map(int,input().split()))

S = [0]

for i in range(n):
    S.append(S[i] + nums[i])

S.sort()


ans = 0

for i in range(n):
    for j in range(i+1, n+1):
        if S[i] == S[j]:
            ans += 1
        elif S[i] > S[j]:
            break

print(ans)

Fixed submission:
from collections import Counter
n = int(input())
nums = list(map(int,input().split()))

S = [0]

for i in range(n):
    S.append(S[i] + nums[i])

S.sort()
ans = 0
p = S[0]
c = Counter(S)

for i in range(1, n+1):
    if i == n or S[i] != p:
        x = c[p]
        ans += x * (x-1) // 2
        p = S[i]


print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
P = list(map(int,input().split())
a, b = 0, 0

for i in range(m):
    if P[i]  > x:
        a += 1
    else:
        b += 1
print(min(a, b))

Fixed submission:
n, m, x = map(int, input().split())
P = list(map(int,input().split()))
a, b = 0, 0

for i in range(m):
    if P[i]  > x:
        a += 1
    else:
        b += 1
print(min(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int,input().split())
for i in range(a, b+1):
    if i <= a + n -1 or i >= b - n + 1:
        print(i)

Fixed submission:
a, b, n = map(int,input().split())
for i in range(a, a + n + 1):
    if i > b - n:
        break
    if i <= a + n - 1:
        print(i)
    
for j in range(b - n, b + 1):
    if i > b:
        break
    if j >= b - n + 1 and a <= j:
        print(j)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int,input().split())
for i in range(a, b+1):
    if i <= a + n -1 or i >= b - n + 1:
        print(i)

Fixed submission:
a, b, n = map(int,input().split())
for i in range(a, a + n + 1):
    if i > b - n:
        break
    if i <= a + n - 1:
        print(i)
    
for j in range(b - n, b + 1):
    if i > b:
        break
    if j >= b - n + 1 and a <= j:
        print(j)
Buggy python submission (verdict: Runtime Error):
white, black = map(int,input().split())
white -= 1
black -= 1

grid = [['#' for i in range(100)] for j in range(100)]
for i in range(1, 99):
    for j in range(50, 99):
        grid[i][j] = "."

a = 3
b = 3
while True:
    grid[a][b] = "."
    white -= 1
    a += 2
    if a > 93:
        a = 3
        b += 2
    if white == 0:
        break
 
c = 3
d = 53
while True:
    grid[c][d] = "#"
    black -= 1
    c += 2
    if c > 93:
        c = 3
        d += 2
    if black == 0:
        break

print(100, 100)
for i in grid:
    print("".join(i))

Fixed submission:
white, black = map(int,input().split())
white -= 1
black -= 1

grid = [['#' for i in range(100)] for j in range(100)]
for i in range(1, 99):
    for j in range(50, 99):
        grid[i][j] = "."

a = 3
b = 3
while True:
    if white == 0:
        break
    grid[a][b] = "."
    white -= 1
    a += 2
    if a > 93:
        a = 3
        b += 2
    
 
c = 3
d = 53
while True:
    if black == 0:
        break
    grid[c][d] = "#"
    black -= 1
    c += 2
    if c > 93:
        c = 3
        d += 2
    

print(100, 100)
for i in grid:
    print("".join(i))
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
p = sum(P)
q = sum(Q)
m = 0
l = 0
for i in range(N):
    if P[i] - Q[i] > 0:
        if (P[i] - Q[i]) % 2 == 1:
            #p += (P[i] - Q[i]) * 2
            m += (P[i] - Q[i] + 1) // 2
            l += 1
        else:
            #p += (P[i] - Q[i])
            m += (P[i] - Q[i]) // 2
    elif P[i] - Q[i] < 0:
        #q += (Q[i] - P[i])
        l += (Q[i] - P[i])

a = p + m * 2 + l
b = q + m + l


if a > b:
    print("No")
elif a == b:
    print("Yes")
else:
    if l % m == 0:
        print("Yes")
    else:
        print("No")

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
p = sum(P)
q = sum(Q)
if P == Q:
    print("Yes")
else:
    m = 0
    l = 0
    for i in range(N):
        if Q[i] - P[i] > 0:
            if (Q[i] - P[i]) % 2 == 1:
                #p += (P[i] - Q[i]) * 2
                m += (Q[i] - P[i] + 1) // 2
                l += 1
            else:
                m += (Q[i] - P[i]) // 2
        elif Q[i] - P[i] < 0:
            #q += (Q[i] - P[i])
            l += (P[i] - Q[i])
    if m >= l:
        print("Yes")
    else:
        print("No")

Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
p = sum(P)
q = sum(Q)
m = 0
l = 0
for i in range(N):
    if P[i] - Q[i] > 0:
        if (P[i] - Q[i]) % 2 == 1:
            #p += (P[i] - Q[i]) * 2
            m += (P[i] - Q[i] + 1) // 2
            l += 1
        else:
            #p += (P[i] - Q[i])
            m += (P[i] - Q[i]) // 2
    elif P[i] - Q[i] < 0:
        #q += (Q[i] - P[i])
        l += (Q[i] - P[i])

a = p + m * 2
b = q + m

if a > b:
    print("No")
elif a == b:
    print("Yes")
else:
    if l % m == 0:
        print("Yes")
    else:
        print("No")

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
p = sum(P)
q = sum(Q)
if P == Q:
    print("Yes")
else:
    m = 0
    l = 0
    for i in range(N):
        if Q[i] - P[i] > 0:
            if (Q[i] - P[i]) % 2 == 1:
                #p += (P[i] - Q[i]) * 2
                m += (Q[i] - P[i] + 1) // 2
                l += 1
            else:
                m += (Q[i] - P[i]) // 2
        elif Q[i] - P[i] < 0:
            #q += (Q[i] - P[i])
            l += (P[i] - Q[i])
    if m >= l:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
P = [0] * 100001
Q = [0] * 100002
P[0] = 1
P[1] = 1

for i in range(2, 100000):
    if P[i] == 0:
        for j in range(i*2, 100000, i):
            P[j] += 1

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

for k in range(3, 100000, 2):
    if P[k] == 0 and P[(k + 1) // 2] == 0:
        Q[k] = 1

for l in range(n):
    print(sum(Q[:num[l][1]+1]) - sum(Q[:num[l][0]]))

Fixed submission:
from collections import Counter
P = [0] * 100001
Q = [0] * 100002
P[0] = 1
P[1] = 1

for i in range(2, 100000):
    if P[i] == 0:
        for j in range(i*2, 100000, i):
            P[j] += 1

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

for k in range(3, 100000, 2):
    if P[k] == 0 and P[(k + 1) // 2] == 0:
        Q[k] = 1
for l in range(100000):
    Q[l+1] += Q[l]

for m in range(n):
    l, r = num[m][0], num[m][1]
    print(Q[r] - Q[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
P = [0] * 100001
Q = [0] * 100002
P[0] = 1
P[1] = 1

for i in range(2, 100000):
    if P[i] == 0:
        for j in range(i*2, 100000, i):
            P[j] += 1

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

for k in range(3, 100000, 2):
    if P[k] == 0 and P[(k + 1) // 2] == 0:
        Q[k] += 1

for l in range(n):
    print(Q[:num[l][1]+1].count(1) - Q[:num[l][0]].count(1))

Fixed submission:
from collections import Counter
P = [0] * 100001
Q = [0] * 100002
P[0] = 1
P[1] = 1

for i in range(2, 100000):
    if P[i] == 0:
        for j in range(i*2, 100000, i):
            P[j] += 1

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

for k in range(3, 100000, 2):
    if P[k] == 0 and P[(k + 1) // 2] == 0:
        Q[k] = 1
for l in range(100000):
    Q[l+1] += Q[l]

for m in range(n):
    l, r = num[m][0], num[m][1]
    print(Q[r] - Q[l-1])
Buggy python submission (verdict: Runtime Error):
S = input()
N = int(input())
ans = S.count("0")
if ans > N:
    ans = N
print(ans)

Fixed submission:
import sys

S = input()
center = len(S) // 2

if len(S) % 2 == 1:
    b = S[center]
    for i in range(1, center + 1):
        if S[center - i] != b or S[center + i] != b:
            print(center + i)
            sys.exit()
else:
    b = S[center - 1]
    for i in range(center):
        if S[center - i - 1] != b or S[center + i] != b:
            print(center + i)
            sys.exit()

print(len(S))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
p = []
q = []
m = len(s)
n = len(t)
if m >= n:
    ans = "No"
else:
    ans = "Yes"
for i in range(m):
    p.append(s[i])
p.sort()
for j in range(n):
    q.append(t[j])

for k in range(min(m,n)+1):
    if ord(p[k]) < ord(q[k]):
        ans = "Yes"
        break
    elif ord(p[k]) > ord(q[k]):
        ans = "No"
        break
print(ans)


Fixed submission:
s = input()
t = input()
p = []
q = []
m = len(s)
n = len(t)
if m >= n:
    ans = "No"
else:
    ans = "Yes"
for i in range(m):
    p.append(s[i])
p.sort()
for j in range(n):
    q.append(t[j])
q.sort(reverse=True)
for k in range(min(m,n)):
    if ord(p[k]) < ord(q[k]):
        ans = "Yes"
        break
    elif ord(p[k]) > ord(q[k]):
        ans = "No"
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(N):
    s = P.count(P[i])
    t = P[i]
    if s > t:
        ans += 1
        P[i] = 0
    elif s < t:
        ans += 1
print(ans)

Fixed submission:
import collections
N = int(input())
P = list(map(int,input().split()))
ans = 0
P.sort()
cnt = collections.Counter(P)
for i in cnt:
    s = cnt[i]
    if s > i:
        t =  s - i
        ans += t
    elif s < i:
        ans += s
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(N):
    if P.count(P[i]) > P[i]:
        ans += 1
        P[i] = 0
    elif P.count(P[i]) < P[i]:
        ans += 1
print(ans)

Fixed submission:
import collections
N = int(input())
P = list(map(int,input().split()))
ans = 0
P.sort()
cnt = collections.Counter(P)
for i in cnt:
    s = cnt[i]
    if s > i:
        t =  s - i
        ans += t
    elif s < i:
        ans += s
print(ans)
Buggy python submission (verdict: Runtime Error):
    N = input()
    if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
        print("Yes")
    else:
        print("No")

Fixed submission:
N = input()
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
N = input()
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
    print("Yes")
else:
    print("No)

Fixed submission:
N = input()
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a,b = map(str,input().split())
A = 1
B = 2
C = 3
D = 4
E = 5
F = 6

if a < b:
    print("<")
elif a = b:
    print("=")
else:
    print(">")

Fixed submission:
a,b = map(str,input().split())
A = 1
B = 2
C = 3
D = 4
E = 5
F = 6
     
if a < b:
    print("<")
elif a == b:
    print("=")
else:
    print(">")
Buggy python submission (verdict: Runtime Error):
    N, Z, W = map(int,input().split())
    p = list(map(int,input().split()))
    a = abs(p[N-2] - p[N-1])
    b = abs(p[N-1] - W)
    print(max(a, b))

Fixed submission:
N, Z, W = map(int,input().split())
p = list(map(int,input().split()))
a = abs(p[N-2] - p[N-1])
b = abs(p[N-1] - W)
print(max(a, b))

Buggy python submission (verdict: Runtime Error):
N, Z, W = map(int,input().split())
p = list(map(int,input().split()))
a = abs(p[1] - p[2])
b = abs(p[2] - W)
print(max(a, b))

Fixed submission:
N, Z, W = map(int,input().split())
p = list(map(int,input().split()))
a = abs(p[N-2] - p[N-1])
b = abs(p[N-1] - W)
print(max(a, b))
Buggy python submission (verdict: Runtime Error):
import sys
s = input()
T=input()
p = 0
for i in range(len(s)-len(T)+1,0,-1):
  for j in range(len(T)):
    if T[j]!=s[i-1+j] and "?"!= s[i-1+j] :
      p = 1
      break
if p == 0:
  s=s[:i-1]+T+s[i+len(T)-1:]
  s = s.replace('?', 'a')
  print(s)
sys.exit()
if p == 1:
  print("UNRESTORABLE")

Fixed submission:
S = input()
T = input()
 
for i in range(len(S) - len(T), -1, -1):
    for j in range(len(T)):
        if S[i + j] != '?' and S[i + j] != T[j]:
            break
    else:
        print((S[:i] + T + S[i + len(T):]).replace('?', 'a'))
        break
else:
    print('UNRESTORABLE')
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
S = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j] == '#':
            continue
        cnt = 0
        for dx in [-1, 0, 1]:
            for dy in [-1, 0, 1]:
                if not 0 <= i+dy < h or not 0 <= j+dx < w:
                    continue
                if S[i+dy][j+dx] == '#':
                    cnt += 1
        S[i][j] = str(cnt)
for s in S:
    print("".join(s))

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

if A == B:
 	print(C)
elif B == C:
 	print(A)
else:
    print(B)

Buggy python submission (verdict: Runtime Error):
A,B,C = map(int,input().split())
if A == B:
  print(C)
 elif B == C:
  print(A)
 else:
  print(B)

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

if A == B:
 	print(C)
elif B == C:
 	print(A)
else:
    print(B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = []
ans = 0
n = 0
for i in range(N):
    s = int(input())
    P.append(s)
P.sort()
while n < N:
    s =  P.count(P[n])
    if s % 2 != 0:
        ans += 1
    n += s
print(ans)

Fixed submission:
s = set()
N = int(input())
for _ in range(N):
    x = int(input())
    if x in s:
        s.remove(x)
    else:
        s.add(x)
print(len(s))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = []
ans = 0
for i in range(N):
    s = int(input())
    P.append(s)
    ans += 1
P.sort()
for i in range(N-1):
    for j in range(i+1,N):
        if P[i] == P[j]:
            P[i] = -1 * i
            P[j] =  -1 * j
            ans -= 2
            break
        
print(ans)

Fixed submission:
s = set()
N = int(input())
for _ in range(N):
    x = int(input())
    if x in s:
        s.remove(x)
    else:
        s.add(x)
print(len(s))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = []
ans = 0
for i in range(N):
    s = int(input())
    P.append(s)
    if P.count(s) % 2 == 0:
        ans -= 1
    else:
        ans += 1
print(ans)

Fixed submission:
s = set()
N = int(input())
for _ in range(N):
    x = int(input())
    if x in s:
        s.remove(x)
    else:
        s.add(x)
print(len(s))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = []
for i in range(N):
    s = int(input())
    if not s in P:
        P.append(s)
    else:
        P.remove(s)
print(len(P))

Fixed submission:
s = set()
N = int(input())
for _ in range(N):
    x = int(input())
    if x in s:
        s.remove(x)
    else:
        s.add(x)
print(len(s))
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
ans = 1
n = len(N)
for i in range(n-1):
    for j in range(i, n):
        if N[i] != N[j]:
            ans += 1
print(ans)

Fixed submission:
N = input()
ans = 0
n = len(N)
a = N.count("a")
ans += a * (a-1) // 2
a = N.count("b")
ans += a * (a-1) // 2
a = N.count("c")
ans += a * (a-1) // 2
a = N.count("d")
ans += a * (a-1) // 2
a = N.count("e")
ans += a * (a-1) // 2
a = N.count("f")
ans += a * (a-1) // 2
a = N.count("g")
ans += a * (a-1) // 2
a = N.count("h")
ans += a * (a-1) // 2
a = N.count("i")
ans += a * (a-1) // 2
a = N.count("j")
ans += a * (a-1) // 2
a = N.count("k")
ans += a * (a-1) // 2
a = N.count("l")
ans += a * (a-1) // 2
a = N.count("m")
ans += a * (a-1) // 2
a = N.count("n")
ans += a * (a-1) // 2
a = N.count("o")
ans += a * (a-1) // 2
a = N.count("p")
ans += a * (a-1) // 2
a = N.count("q")
ans += a * (a-1) // 2
a = N.count("r")
ans += a * (a-1) // 2
a = N.count("s")
ans += a * (a-1) // 2
a = N.count("t")
ans += a * (a-1) // 2
a = N.count("u")
ans += a * (a-1) // 2
a = N.count("v")
ans += a * (a-1) // 2
a = N.count("w")
ans += a * (a-1) // 2
a = N.count("x")
ans += a * (a-1) // 2
a = N.count("y")
ans += a * (a-1) // 2
a = N.count("z")
ans += a * (a-1) // 2
ans = n * (n-1) // 2 - ans + 1
print(ans)
Buggy python submission (verdict: Runtime Error):
x, a, b = map(int(input())
A = abs(x-a)
B = abs(x-b)
if A < B:
    print("A")
else:
    print("B")

Fixed submission:
x, a, b = map(int,input().split())
p = abs(x-a)
q = abs(x-b)
if p < q:
    print("A")
else:
    print("B")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))
P.sort(reverse=True)
a = 0
b = 0
for i in range(N-1):
    if P[i] > 0:
        if a == 0:
            if P.count(P[i]) >= 2:
                a = P[i]
                P[i] = -i
                P[i+1] = -i -1
        elif b == 0:
            if P.count(P[i]) >= 2:
                b = P[i]
                P[i] = -i
                P[i+1] = -i -1
        else:
            break
    else:
        continue
ans = a * b
print(ans)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
P.sort(reverse=True)
a = 0
b = 0
for i in range(N-1):
    if P[i] > 0:
        if a == 0:
            if P[i] == P[i+1]:
                a = P[i]
                P[i] = -i
                P[i+1] = -i -1
        elif b == 0:
            if P[i] == P[i+1]:
                b = P[i]
                P[i] = -i
                P[i+1] = -i -1
        else:
            break
    else:
        continue
ans = a * b
print(ans)
Buggy python submission (verdict: Runtime Error):
a = input()
b = len(a)
print(a[0] + str(b) + a[b])

Fixed submission:
a = input()
b = len(a)
print(a[0] + str(b-2) + a[b-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
P = [list(map(int,input().split())) for _ in range(M)]
P.sort()
Q = []
s = -1
ans = ("IMPOSSIBLE")
for i in range (M):
    if P[i][0] == 1:
        Q.append(P[i][1])
    else:
        s = i - 1
        break
if s >= 0:
    for j in range(s, M):
        if P[j][1] == N:
            if P[j][0] in Q:
                ans = ("POSSIBLE")
print(ans)

Fixed submission:
N, M = map(int,input().split())
P = [list(map(int,input().split())) for _ in range(M)]
P.sort()
q = -1
ans = ("IMPOSSIBLE")
for i in range (M):
    if P[i][0] == 1:
        p = P[i][1]
        if q < 0:
            if i > 0:
                q = i - 1
            else:
                q = 0
        for j in range(q, M):
            if P[j][0] == p:
                if P[j][1] == N:
                    ans = ("POSSIBLE")
                    break
            elif P[j][0] > p:
                if q >= 0:
                    q = j - 1
                else:
                    q = 0
                break
    else:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))
Q = []

if N % 2 == 0:
    for i in range(N):
        if i % 2 == 0:
            Q.append(P[i])
        else:
            Q.insert(0, P[i])
else:
    for i in range(N):
        if i % 2 == 0:
            Q.insert(0, P[i])
        else:
            Q.append(P[i])
for j in range(N-1):
    print(Q[j], end =" ")
print(Q[N-1])

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
A = []
B = []
s = N // 2
if N % 2 == 0:
    for i in range(N-1, 0, -2):
        A.append(P[i])
    for j in range(0, N-1, 2):
        B.append(P[j])
else:
    for i in range(N-1, -1, -2):
        A.append(P[i])
    for j in range(1, N, 2):
        B.append(P[j])
for i in range(len(A)):
    print(A[i], end=" ")
for j in range(len(B)):
    print(B[j], end=" ")
print()
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
P = []
for i in range(N):
    a, b = map(int,input().split())
    p = [a] * b
    P += p
P.sort()
print(P[K-1])

Fixed submission:
N, K = map(int,input().split())
P = [list(map(int,input().split())) for _ in range(N)]
p = 0
P.sort()
for i in range(N):
    p += P[i][1]
    if p >= K:
        ans = P[i][0]
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c = input().split()
if a[len(a-1)] == b[0] and b[len(b-1)] == c[0]:
    print("YES")
else:
    print("NO")


Fixed submission:
a, b, c = input().split()
if a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
a, b, c = input().split()
if a[len(a)] == b[0] and b[len(b)] == c[0]:
    print("YES")
else:
    print("NO")

Fixed submission:
a, b, c = input().split()
if a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if A > B:
  print("GREATER")
eiif A == B:
  print("EQUAL")
else:
  print("LESS")

Fixed submission:
A = int(input())
B = int(input())
if A > B:
    print("GREATER")
elif A == B:
    print("EQUAL")
else:
    print("LESS")