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

Fixed submission:
import math

a, b, x = map(int,input().split())
if (a**2)*b == x:
    print(0)
elif (a**2)*b<2*x:
    print(90-math.degrees(math.atan((a**3)/(2*((a**2)*b-x)))))
else:
    print(90-math.degrees(math.atan((2*x)/(a*(b**2)))))

Buggy submission (verdict: Runtime Error):
import math

a, b, x = map(int,input().split())
if (a**2)*b<2*x:
    print(90-math.degrees(math.atan((a**3)/(2*((a**2)*b-x)))))
else:
    print(90-math.degrees(math.atan((2*x)/(a*(b**2)))))
Problem p02900 (python)

Fixed submission:
import fractions

A, B = map(int,input().split())
GCD = fractions.gcd(A, B)

def prime_factorize(n):
    a = [1]
    flag = 1
    while n % 2 == 0:
        if flag:
            a.append(2)
            flag = 0
        n //= 2
    f = 3
    flag = 1
    while f * f <= n:
        if n % f == 0:
            if flag:
                a.append(f)
                flag = 0
            n //= f
        else:
            f += 2
            flag = 1
    if n != 1 and n != a[-1]:
        a.append(n)
    return a

a = prime_factorize(GCD)

print(len(a))

Buggy submission (verdict: Runtime Error):
import fraction

A, B = map(int,input().split())
GCD = fraction.gcd(A, B)

def prime_factorize(n):
    a = [1]
    flag = 1
    while n % 2 == 0:
        if flag:
            a.append(2)
            flag = 0
        n //= 2
    f = 3
    flag = 1
    while f * f <= n:
        if n % f == 0:
            if flag:
                a.append(f)
                flag = 0
            n //= f
        else:
            f += 2
            flag = 1
    if n != 1 and n != a[-1]:
        a.append(n)
    return a

a = prime_factorize(GCD)

print(len(a))
Problem p02909 (python)

Fixed submission:
Weather = ["Sunny", "Cloudy", "Rainy", "Sunny"]
S = input()
print(Weather[Weather.index(S)+1])

Buggy submission (verdict: Runtime Error):
Weather = [Sunny, Cloudy, Rainy, Sunny]
S = input()
print(Weather[Weather.index(S)+1])
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
 
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
 
value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(parent,i,add):
    for k in graph[i]:
        if k != parent:
            value[k] += add
            dfs(i,k,value[k])
    

dfs(0,1,value[1])

ans = value[1:]

print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int,input().split())
edge = [[] for i in range(N+1)]

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

node = [[[],0] for i in range(N+1)] #[childrens],counter
    
def dfs(parent,i):
    for k in edge[i]:
        if parent != k:
            node[i][0].append(k)
            dfs(i,k)

def dfs_solve(p,x):
    node[p][1] += x
    for i in node[p][0]:
        dfs_solve(i,x)
        
dfs(-1,1)

for _ in range(Q):
    p, x = map(int,input().split())
    dfs_solve(p,x)

ans = []

for i in range(1,N+1):
    ans.append(node[i][1])

print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int,input().split())
edge = [[] for i in range(N+1)]

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

node = [[[],0] for i in range(N+1)] #[childrens],counter
    
def dfs(parent,i):
    for k in edge[i]:
        if parent != k:
            node[i][0].append(k)
            dfs(i,k)

def dfs_solve(p,x):
    node[p][1] += x
    for i in node[p][0]:
        dfs_solve(i,x)
        
dfs(-1,1)

for _ in range(Q):
    p, x = map(int,input().split())
    dfs_solve(p,x)

ans = []

for i in range(1,N+1):
    ans.append(node[i][1])

print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int,input().split())
edge = [[] for i in range(N+1)]

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

node = [[[],0] for i in range(N+1)] #[childrens],counter
    
def dfs(parent,i):
    for k in edge[i]:
        if parent != k:
            node[i][0].append(k)
            dfs(i,k)

def dfs_solve(p,x):
    node[p][1] += x
    for i in node[p][0]:
        dfs_solve(i,x)
        
dfs(-1,1)

for _ in range(Q):
    p, x = map(int,input().split())
    dfs_solve(p,x)

for i in range(1,N+1):
    print(node[i][1])
Problem p02958 (python)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
cnt = 0
for i in range(N):
    if P[i]!=i+1:
        cnt+=1
if cnt<=2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int(),input().split()))
cnt = 0
for i in range(N):
    if P[i]!=i+1:
        cnt+=1
if cnt<=2:
    print("YES")
else:
    print("NO")
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(4100000)

mod = 10 ** 9 + 7

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

ans = K

def factorial(n, k, mod):
    fact = 1
    for integer in range(n, n-k, -1):
        fact *= integer
        fact %= mod
    return fact

def dfs(parent, current):
    ret = 1
    for child in graph[current]:
        if child != parent:
            ret *= dfs(current, child)
    L = len(graph[current])
    R = K - 1
    if parent != -1:
        L -= 1
        R -= 1
    ret *= factorial(R, L, mod)
    return ret % mod

ans *= dfs(-1, 0)
ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
mod = 10 ** 9 + 7

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

ans = K

def factorial(n, k, mod):
    fact = 1
    for integer in range(n, n-k, -1):
        fact *= integer
        fact %= mod
    return fact

def dfs(parent, current):
    ret = 1
    for child in graph[current]:
        if child != parent:
            ret *= dfs(current, child)
    L = len(graph[current])
    R = K - 1
    if parent != -1:
        L -= 1
        R -= 1
    ret *= factorial(R, L, mod)
    return ret % mod

ans *= dfs(-1, 0)
ans %= mod

print(ans)
Problem p02995 (python)

Fixed submission:
import fractions

A,B,C,D = map(int,input().split())
LCM = (C*D)//fractions.gcd(C,D)
ans = B-A-(B//C-(A-1)//C)-(B//D-(A-1)//D)+(B//LCM-(A-1)//LCM)+1
print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B,C,D = map(int,input().split())
LCM = (C*D)//math.gcd(C,D)
ans = B-A-(B//C-(A-1)//C)-(B//D-(A-1)//D)+(B//LCM-(A-1)//LCM)+1
print(ans)
Problem p03026 (python)

Fixed submission:
import sys
sys.setrecursionlimit(4100000)

N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
C = list(map(int,input().split()))
C.sort(reverse = True)

D = [0] * N

def dfs(x, parent, index):
    D[x] = C[index]
    index += 1
    for u in edges[x]:
        if u != parent:
            index = dfs(u, x, index)
    return index

dfs(0, -1, 0)

print(sum(C[1:]))
print(*D)

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

c.sort(reverse = True)

def dfs(x, par, index):
    L[x] = c[index]
    for u in edges[x]:
        if u != par:
            index += 1
            index = dfs(u, x, index)
    return index

dfs(0, -1, 0)

print(sum(L[1:]))
print(*L)

Buggy submission (verdict: Runtime Error):
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
C = list(map(int,input().split()))
C.sort(reverse = True)

D = [0] * N

def dfs(x, parent, index):
    D[x] = C[index]
    index += 1
    for u in edges[x]:
        if u != parent:
            index = dfs(u, x, index)
    return index

dfs(0, -1, 0)

print(sum(C[1:]))
print(*D)

Buggy submission (verdict: Runtime Error):
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
C = list(map(int,input().split()))
C.sort(reverse = True)

D = [0] * N

index = 0
def dfs(x, parent):
    global index
    D[x] = C[index]
#     index += 1
    for u in edges[x]:
        if u != parent:
            dfs(u, x)

dfs(0, -1)

print(sum(C[1:]))
print(*D)

Buggy submission (verdict: Runtime Error):
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
C = list(map(int,input().split()))
C.sort(reverse = True)

D = [0] * N

index = 0
def dfs(x, parent):
    global index
    D[x] = C[index]
    index += 1
    for u in edges[x]:
        if u != parent:
            dfs(u, x)

dfs(0, -1)
print(0)
# print(sum(C[1:]))
print(*D)

Buggy submission (verdict: Runtime Error):
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
C = list(map(int,input().split()))
C.sort(reverse = True)

D = [0] * N

index = 0
def dfs(x, parent):
    global index
    D[x] = C[index]
    index += 1
    for u in edges[x]:
        if u != parent:
            dfs(u, x)

dfs(0, -1)

print(sum(C[1:]))
print(*D)
Problem p03031 (python)

Fixed submission:
N, M = map(int, input().split())
switches = []

for i in range(M):
    tmp = list(map(int,input().split()))
    tmp.pop(0)
    switches.append(tmp)

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

a = [list(format(i, '0%db' % N)) for i in range(2**N)]

ans = 0

for i in a:
    flag = 0
    for j in range(M):
        SUM = 0
        for k in switches[j]:
            SUM += int(i[k-1])
        if SUM%2 != R[j]:
            flag = 1
    if flag == 0:
        ans += 1

print(ans)

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

for i in range(M):
    tmp = list(map(int,input().split()))
    tmp.pop(0)
    switches.append(tmp)

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

a = [list(f"{i:0{N}b}") for i in range(2**N)]

ans = 0

for i in a:
    flag = 0
    for j in range(M):
        SUM = 0
        for k in switches[j]:
            SUM += int(i[k-1])
        if SUM%2 != R[j]:
            flag = 1
    if flag == 0:
        ans += 1

print(ans)

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

for i in range(M):
    tmp = list(map(int,input().split()))
    tmp.pop(0)
    switches.append(tmp)

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

a = [list(f"{i:0{N}b}") for i in range(2**N)]

ans = 0

for i in a:
    flag = 0
    for j in range(M):
        sum = 0
        for k in switches[j]:
            sum += int(i[k-1])
        if sum%2 != R[j]:
            flag = 1
    if flag == 0:
        ans += 1
print(ans)

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

for i in range(M):
    tmp = list(map(int,input().split()))
    tmp.pop(0)
    switches.append(tmp)

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

a = [list(f"{i:0{N}b}") for i in range(2**N)]

ans = 0

for i in a:
    flag = 0
    for j in range(M):
        sum = 0
        for k in switches[j]:
            sum += int(i[k-1])
        if sum%2 != R[j]:
             flag = 1
    if flag == 0:
        ans += 1
print(ans)

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

for i in range(M):
    tmp = list(map(int,input().split()))
    tmp.pop(0)
    switches.append(tmp)

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

a = [list(f"{i:0{N}b}") for i in range(2**N)]

ans = 0

for i in a:
    flag = 0
    for j in range(M):
        sum = 0
        for k in switches[j]:
            sum += int(i[k-1])
        if sum%2 != R[j]:
             flag = 1
    if flag == 0:
        ans += 1
print(ans)
Problem p03037 (python)

Fixed submission:
N, M = map(int,input().split())
L = []
R = []
for i in range(M):
    tmp_L, tmp_R = map(int,input().split())
    L.append(tmp_L)
    R.append(tmp_R)

left = max(L)
right = min(R)

if right - left < 0:
    print(0)
else:
    print(right - left + 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
L = []
R = []
for i in range(M):
    tmp_L, tmp_R = input().split()
    L.append(tmp_L)
    R.append(tmp_R)

left = max(L)
right = min(R)

if right - left < 0:
    print(0)
else:
    print(right - left + 1)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(4100000)

N = int(input())
root = [[] for i in range(N)]
for i in range(N-1):
    u, v, w = map(int,input().split())
    root[u-1].append([v-1,w%2])
    root[v-1].append([u-1,w%2])

ans = [-1 for i in range(N)]

def dfs(index):
    if ans[index]==-1:
        ans[index] = 0
    for i in root[index]:
        if ans[i[0]] == -1:
            ans[i[0]] = (ans[index]+i[1])%2
            dfs(i[0])

for i in range(N):
    dfs(i)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
root = [[] for i in range(N)]
for i in range(N-1):
    u, v, w = map(int,input().split())
    root[u-1].append([v-1,w%2])
    root[v-1].append([u-1,w%2])

ans = [-1 for i in range(N)]

def dfs(index):
    if ans[index]==-1:
        ans[index] = 0
    for i in root[index]:
        if ans[i[0]] == -1:
            ans[i[0]] = (ans[index]+i[1])%2
            dfs(i[0])

for i in range(N):
    dfs(i)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
root = [[] for i in range(N)]
for i in range(N-1):
    u, v, w = map(int,input().split())
    root[u-1].append([v-1,w%2])
    root[v-1].append([u-1,w%2])

ans = [-1 for i in range(N)]

def dfs(index):
    if ans[index]==-1:
        ans[index] = 0
    for i in root[index]:
        if ans[i[0]] == -1:
            ans[i[0]] = (ans[index]+i[1])%2
            dfs(i[0])

for i in range(N):
    dfs(i)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
root = [[] for i in range(N)]
for i in range(N-1):
    u, v, w = map(int,input().split())
    root[u-1].append([v-1,w%2])
    root[v-1].append([u-1,w%2])

ans = [-1 for i in range(N)]

def dfs(index):
    ans[index] = 0
    for i in root[index]:
        if ans[i[0]] == -1:
            ans[i[0]] = (ans[index]+i[1])%2
            dfs(i[0])

for i in range(N):
    dfs(i)

print(ans)
Problem p03128 (python)

Fixed submission:
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse = True)
d = [0,2,5,5,4,5,6,3,7,6]
S = set()
for a in A:
    S.add(d[a])

INF = 10 ** 8
dp = [-INF for _ in range(N+1)]
dp[0] = 0

for i in range(N+1):
    for s in S:
        if i - s >= 0:
            dp[i] = max(dp[i], dp[i-s]+1)

ans = 0
digit = dp[N]

for i in range(digit-1, -1, -1):
    if i != 0:
        for a in A:
            if dp[N-d[a]] == i:
                ans = ans * 10 + a
                N -= d[a]
                break
    else:
        for a in A:
            if N == d[a]:
                ans = ans * 10 + a
                break
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse = True)
d = [0,2,5,5,4,5,6,3,7,6]
S = set()
for a in A:
    S.add(d[a])

dp = [0 for _ in range(N+1)]

for i in range(N+1):
    for s in S:
        if i - s >= 0:
            dp[i] = max(dp[i], dp[i-s]+1)

digit = dp[N]

def dfs(N, digit, ans):
    if digit == 0:
        if N == 0:
            return ans
        else:
            return 0
    for a in A:
        temp = dfs(N - d[a], digit - 1, ans * 10 + a)
        if temp:
            return temp

print(dfs(N, digit, 0))
Problem p03129 (python)

Fixed submission:
N, K = map(int,input().split())
if N + 1 >= 2 * K:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
if N + 1 >= 2 * K:
    print('YES')
ele:
    print('NO')
Problem p03136 (python)

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
if max(L) * 2 < sum(L):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))
if max(L) * 2 < L:
    print("Yes")
else:
    print("No")
Problem p03148 (python)

Fixed submission:
import heapq
N, K = map(int,input().split())
L1 = []
L2 = []
S = set()
val = 0

for _ in range(N):
    t, d = map(int,input().split())
    L1.append((d, t))

L1.sort(reverse = True)

for i in range(K):
    val += L1[i][0]
    if L1[i][1] in S:
        heapq.heappush(L2, L1[i][0])
    else:
        S.add(L1[i][1])

ans = val + len(S) ** 2

for i in range(K, N):
    if len(L2) == 0:
        break
    if not L1[i][1] in S:
        S.add(L1[i][1])
        val -= heapq.heappop(L2)
        val += L1[i][0]
        ans = max(ans, val + len(S) ** 2)

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
N, K = map(int,input().split())
L1 = []
L2 = []
S = set()
val = 0

for _ in range(N):
    t, d = map(int,input().split())
    L1.append((d, t))

L1.sort(reverse = True)

for i in range(K):
    val += L1[i][0]
    if L1[i][1] in S:
        heapq.heappush(L2, -L1[i][0])
    else:
        S.add(L1[i][1])

ans = val + len(S) ** 2

for i in range(K, N):
    if not L1[i][1] in S:
        S.add(L1[i][1])
        val += heapq.heappop(L2)
        val += L1[i][0]
        ans = max(ans, val + len(S) ** 2)

print(ans)
Problem p03157 (python)

Fixed submission:
import sys
sys.setrecursionlimit(4100000)

H, W = map(int,input().split())
S = []
for _ in range(H):
    S.append(list(input()))

C = [[1 for i in range(W)] for j in range(H)]
L = ['.', '#']
D = {'.':0, '#':1}
tx = [1, 0, -1, 0]
ty = [0, 1, 0, -1]

def dfs(x, y, c, l):
    C[x][y] = 0
    l[c] += 1
    for i in range(4):
        nx = x + tx[i]
        ny = y + ty[i]
        if 0 <= nx < H and 0 <= ny < W and C[nx][ny] and L[c] != S[nx][ny]:
            l = dfs(nx, ny, 1 - c, l)
    return l

ans = 0
for i in range(H):
    for j in range(W):
        l = dfs(i, j, D[S[i][j]], [0, 0])
        ans += l[0] * l[1]

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int,input().split())
S = []
for _ in range(H):
    S.append(list(input()))

C = [[1 for i in range(W)] for j in range(H)]
L = ['.', '#']
D = {'.':0, '#':1}
tx = [1, 0, -1, 0]
ty = [0, 1, 0, -1]

def dfs(x, y, c, l):
    C[x][y] = 0
    l[c] += 1
    for i in range(4):
        nx = x + tx[i]
        ny = y + ty[i]
        if 0 <= nx < H and 0 <= ny < W and C[nx][ny] and L[c] != S[nx][ny]:
            l = dfs(nx, ny, 1 - c, l)
    return l

ans = 0
for i in range(H):
    for j in range(W):
        l = dfs(i, j, D[S[i][j]], [0, 0])
        ans += l[0] * l[1]

print(ans)
Problem p03354 (python)

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

UFT = UnionFind(N)
for _ in range(M):
    x, y = map(int,input().split())
    UFT.union(x-1, y-1)

ans = 0

for i in range(N):
    if UFT.same(P[i] - 1, i):
        ans += 1
print(ans)

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

UFT = UnionFind(N)
for _ in range(M):
    x, y = map(int,input().split())
    UFT.union(x-1, y-1)

ans = 0

for i in range(N):
    if UTF.same(P[i] - 1, i):
        ans += 1
print(ans)
Problem p03379 (python)

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
nX = sorted(X)
left = nX[N//2-1]
right = nX[N//2]
for i in X:
    if i <= left:
        print(right)
    else:
        print(left)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))
nX = sorted(X)
left = nX[N//2-1]
right = nX[N//2]
for i in X:
    if X <= left:
        print(right)
    else:
        print(left)
Problem p03380 (python)

Fixed submission:
from bisect import bisect_left
N = int(input())
A = list(map(int,input().split()))
A.sort()
n = A.pop()
index = bisect_left(A, n//2)
if index == 0:
    r = A[0]
elif index == N-1:
    r = A[N-2]
else:
    if abs(n//2-A[index]) <= abs(n//2-A[index-1]):
        r = A[index]
    else:
        r = A[index - 1]
print(*[n,r])

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N = int(input())
A = list(map(int,input().split()))
A.sort()
n = A.pop()
index = bisect_left(A, n//2+1)
if index == 0:
    r = A[0]
elif index == N-2:
    r = A[N-2]
else:
    if abs(n//2+1-A[index]) <= abs(n//2+1-A[index-1]):
        r = A[index]
    else:
        r = A[index - 1]
print(*[n,r])
Problem p03417 (python)

Fixed submission:
N, M = map(int,input().split())
if N > M:
    N, M = M, N
if N == 1:
    if M == 1:
        ans = 1
    else:
        ans = M - 2
elif N == 2:
    ans = 0
else:
    ans = (N - 2) * (M - 2)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
if N > M:
    N, M = M, N
if N == 1:
    if M == 1:
        ans = 1
    else:
        ans = n - 2
elif N == 2:
    ans = 0
else:
    ans = (N - 2) * (M - 2)
print(ans)
Problem p03424 (python)

Fixed submission:
N = int(input())
S = list(input())
if 'Y' in S:
    print('Four')
else:
    print('Three')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(map(int,input().split()))
if 'Y' in S:
    print('Four')
else:
    print('Three')