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

Fixed submission:
from itertools import permutations
import sys


input = sys.stdin.readline


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

dest = [x-1 for x in map(int, input().split())]


inf = float('inf')
mat = [[inf]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    mat[a-1][b-1] = mat[b-1][a-1] = c


for i in range(N):
    for j in range(N):
        for k in range(N):
            mat[j][k] = min(mat[j][k], mat[j][i]+mat[i][k])


ans = inf
for l in permutations(dest):
    tmp = 0
    for u, v in zip(l, l[1:]):
        tmp += mat[u][v]
    ans = min(ans, tmp)

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import permutations
import sys


input = sys.stdin.readline


N, M, R = map(int, input().split())
dest = [x-1 for x in map(int, input().split())]

inf = float('inf')
mat = [[inf]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    mat[a-1][b-1] = mat[b-1][a-1] = c


def war(g):
    ran = range(N)
    for i in ran:
        for j in ran:
            for k in ran:
                mat[j][k] = min(mat[j][k], mat[j][i]+mat[i][k])


ans = inf
mat = war(mat)
for l in permutations(dest):
    tmp = 0
    for u, v in zip(l, l[1:]):
        tmp += mat[u][v]
        if tmp > ans:
            break
    ans = min(ans, tmp)

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import permutations
import sys


input = sys.stdin.readline


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

#dest = (list)(map(lambda x: (int)(x)-1, input().split()))
dest = [x-1 for x in input().split()]


inf = float('inf')
mat = [[inf]*N for _ in range(N)]
for _ in range(M):
    a, b, c = (list)(map(int, input().split()))
    mat[a-1][b-1] = mat[b-1][a-1] = c


for i in range(N):
    for j in range(N):
        for k in range(N):
            mat[j][k] = min(mat[j][k], mat[j][i]+mat[i][k])


ans = inf
for l in permutations(dest):
    tmp = 0
    for u, v in zip(l, l[1:]):
        tmp += mat[u][v]
    ans = min(ans, tmp)

print(ans)
Problem p03614 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

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

# print(A)

ans = 0
if all(a != 0 for a in A):
    ans = 0
else:
    seq = 0
    for i in range(N):
        if A[i] == 0:
            seq += 1
        else:
            ans += (seq+1)//2
            seq = 0
    ans += (seq+1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

seq = 0
ans = 0
for i in range(1, N+1):
    if A[i] == i:
        seq += 1
    else:
        ans += (seq+1)//2
        seq = 0
ans += (seq+1)//2
print(ans)
Problem p03624 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
s = input()
alpha = [chr(i) for i in range(97, 97+26)]
for c in alpha:
    if c in s:
        continue
    else:
        print(c)
        exit()
print("None")

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
s = int(input())
alpha = [chr(i) for i in range(97, 97+26)]
for c in alpha:
    if c in s:
        continue
    else:
        print(c)
        break
Problem p03647 (python)

Fixed submission:
import heapq
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
cand_1 = []
cand_2 = []
for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        cand_1.append(b)
    elif b == N:
        cand_2.append(a)

ans = "IMPOSSIBLE"
heapq.heapify(cand_1)
heapq.heapify(cand_2)


while len(cand_1) != 0 and len(cand_2) != 0:
    if cand_1[0] < cand_2[0]:
        heapq.heappop(cand_1)
    elif cand_1[0] > cand_2[0]:
        heapq.heappop(cand_2)
    else:
        ans = "POSSIBLE"
        break
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
cand_1 = []
cand_2 = []
for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        cand_1.append(b)
    elif b == N:
        cand_2.append(a)

ans = "IMPOSSIBLE"
heapq.heapify(cand_1)
heapq.heapify(cand_2)


l1 = len(cand_1)
l2 = len(cand_2)
i = 1
j = 1
e1 = heapq.heappop(cand_1)
e2 = heapq.heappop(cand_2)

if e1 == e2:
    ans = "POSSIBLE"
while i < l1 and j < l2:
    if e1 == e2:
        ans = "POSSIBLE"
        break
    elif e1 > e2:
        e2 = heapq.heappop(cand_2)
        j += 1
    else:
        e1 = heapq.heappop(cand_1)
        i += 1
print(ans)
Problem p03671 (python)

Fixed submission:
L = list(map(int,input().split()))
L = sorted(L)
print(sum(L[:2]))

Buggy submission (verdict: Runtime Error):
print(sum(sorted(list(map(int,input().split()))[:2]))
Problem p03675 (python)

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

ans = []
if N % 2 == 0:
    l1 = A[0::2]
    l2 = A[1::2]
    l2 = l2[::-1]
    ans = l2+l1
else:
    l1 = A[0::2]
    l2 = A[1::2]
    l1 = l1[::-1]
    ans = l1+l2

print(" ".join(list(map(str, ans))))

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

ans = []

l1 = A[0::2]
l2 = A[1::2]
if N % 2 == 0:
    l2 = l2[::-1]
    ans = l2+l1
else:
    l1 = l1[::-1]
    ans = l1+l2

print(" ".join(ans))
Problem p03693 (python)

Fixed submission:
L=list(map(int,input().split()))
V=int("".join(map(str,L)))
if V%4==0:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
L=int("".join(map(str,list(map(int,input().split()))))
if L%4==0:
      print("YES")
else:
      print("NO")
Problem p03712 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

H, W = map(int, input().split())

grid = [["#"]*(W+2) for _ in range(H+2)]

for i in range(1, H+1):
    for j, c in enumerate(input()):
        grid[i][j+1] = c

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

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

H, W = map(int, input().split())

grid = [["#"]*(W+2) for _ in range(H+2)]

for i in range(1, H+1):
    l = list(input().split())
    for j in range(1, W+1):
        grid[i][j] = l[j-1]

for i in grid:
    print(" ".join(i))
Problem p03721 (python)

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

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

nums = sorted(nums, key=lambda x: x[0])

acc = [0]*N
acc[0] = nums[0][1]
for i in range(1, N):
    acc[i] += acc[i-1]+nums[i][1]


for i in range(N):
    if acc[i] >= K:
        print(nums[i][0])
        exit()

Buggy submission (verdict: Runtime Error):
import sys


def input(): return sys.stdin.readline().strip()


N, M = (list)(map(int, input().split()))
edge = []

for _ in range(M):
    edge.append((list)(map(int, input().split())))


inf = 10**15

d = [inf]*(N+1)
d[1] = 0
ans = inf
for i in range(N):
    update = False
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            update = True

    if not update:
        break

neg = [False]*(N+1)
for i in range(N):
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            neg[b] = True
        if neg[a]:
            neg[b] = True

if neg[-1]:
    print('inf')
else:
    print(-d[-1])
Problem p03722 (python)

Fixed submission:
import sys


def input(): return sys.stdin.readline().strip()


N, M = (list)(map(int, input().split()))
edge = []

for _ in range(M):
    edge.append((list)(map(int, input().split())))


inf = 10**15

d = [inf]*(N+1)
d[1] = 0
ans = inf
for i in range(N):
    update = False
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            update = True

    if not update:
        break

neg = [False]*(N+1)
for i in range(N):
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            neg[b] = True
        if neg[a]:
            neg[b] = True

if neg[-1]:
    print('inf')
else:
    print(-d[-1])

Buggy submission (verdict: Runtime Error):
import sys


def input(): return sys.stdin.redline().strip()


N, M = (list)(map(int, input().split()))
edge = []

for _ in range(M):
    edge.append((list)(map(int, input().split())))


inf = 10**15

d = [inf]*(N+1)
d[1] = 0
ans = inf
for i in range(N):
    update = False
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            update = True

    if not update:
        break

neg = [False]*(N+1)
for i in range(N):
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            neg[b] = True
        if neg[a]:
            neg[b] = True

if neg[-1]:
    print('inf')
else:
    print(-d[-1])

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

for _ in range(M):
    edge.append((list)(map(int, input().split())))


inf = 10**15

d = [inf]*(N+1)
d[1] = 0
ans = inf
for i in range(N):
    update = False
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            update = True

    if not update:
        break

neg = [False]*(N+1)
for i in range(N):
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            neg[b] = True
        if neg[a]:
            neg[b] = True

if neg[-1]:
    print('inf')
else:
    print(-ans[-1])

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

for _ in range(N):
    edge.append((list)(map(int, input().split())))


inf = 10**15

d = [inf]*(N+2)
d[1] = 0
ans = inf
for i in range(N+1):
    update = False
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            update = True

    if not update:
        break
    elif i == N:
        ans = 'inf'

if not ans == 'inf':
    ans = d[N]
    print(-ans)
else:
    print(ans)
Problem p03734 (python)

Fixed submission:
from itertools import accumulate
import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, W = map(int, input().split())
first_item = list(map(int, input().split()))
basew = first_item[0]
w0 = []
w1 = []
w2 = []
w3 = []
w0.append(first_item[1])
for _ in range(N-1):
    w, v = map(int, input().split())
    w -= basew
    if w == 0:
        w0.append(v)
    elif w == 1:
        w1.append(v)
    elif w == 2:
        w2.append(v)
    elif w == 3:
        w3.append(v)

w0_acc = [0]+list(accumulate(sorted(w0, reverse=True)))
w1_acc = [0]+list(accumulate(sorted(w1, reverse=True)))
w2_acc = [0]+list(accumulate(sorted(w2, reverse=True)))
w3_acc = [0]+list(accumulate(sorted(w3, reverse=True)))
v = 0
for i0 in range(len(w0)+1):
    for i1 in range(len(w1)+1):
        for i2 in range(len(w2)+1):
            for i3 in range(len(w3)+1):
                if basew*(i0+i1+i2+i3)+3*i3 + 2*i2 + i1 > W:
                    break
                else:
                    v = max(v, w0_acc[i0]+w1_acc[i1]+w2_acc[i2]+w3_acc[i3])
print(v)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, W = map(int, input().split())
first_item = list(map(int, input().split()))
basew = first_item[0]
w0 = []
w1 = []
w2 = []
w3 = []
heapq.heappush(w0, first_item[1])
for _ in range(N-1):
    w, v = map(int, input().split())
    w -= basew
    if w == 0:
        heapq.heappush(w0, v)
    elif w == 1:
        heapq.heappush(w1, v)
    elif w == 2:
        heapq.heappush(w2, v)
    elif w == 3:
        heapq.heappush(w3, v)

w0_acc = [0]+list(accumulate(reversed(w0)))
w1_acc = [0]+list(accumulate(reversed(w1)))
w2_acc = [0]+list(accumulate(reversed(w2)))
w3_acc = [0]+list(accumulate(reversed(w3)))
print("acc-0", w0_acc)
print("acc-1", w1_acc)
print("acc-2", w2_acc)
print("acc-3", w3_acc)
v = 0
for i0 in range(N+1):
    for i1 in range(N+1):
        for i2 in range(N+1):
            for i3 in range(N+1):
                if basew*(i0+i1+i2+i3)+3*i3 + 2*i2 + i1 > W:
                    break
                else:
                    v = max(v, w0_acc[i0]+w1_acc[i1]+w2_acc[i2]+w3_acc[i3])
print(v)

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

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

for i in reversed(range(N)):
    for j in range(W+1):
        w = items[i][0]
        v = items[i][1]
        if j < w:
            dp[i][j] = dp[i+1][j]
        else:
            dp[i][j] = max(dp[i+1][j], dp[i+1][j-w]+v)

print(dp[0][W])
Problem p03738 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

a = int(input())
b = int(input())
if a == b:
    print("EQUAL")
elif a < b:
    print("LESS")
else:
    print("GREATER")

Buggy submission (verdict: Runtime Error):
#include<stdio.h>

int main(void){
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    if(a==b){
        printf("EQUAL\n");
    }else{
        if (a>b){
            printf("GREATER\n");
        }
        else{
            printf("LESS\n");
        }
    }
}

Buggy submission (verdict: Runtime Error):
#include<stdio.h>

int main(void){
    int a,b;
    scanf("%d\n",&a);
    scanf("%d\n",&b);
    if(a==b){
        printf("EQUAL\n");
    }else{
        if (a>b){
            printf("GREATER\n");
        }
        else{
            printf("LESS\n");
        }
    }
}

Buggy submission (verdict: Runtime Error):
#include<stdio.h>

int main(void){
    int a,b;
    scanf("%d\n",&a);
    scanf("%d\n",&b);
    if(a==b){
        printf("EQUAL\n");
    }else{
        if (a>b){
            print("GREATER\n");
        }
        else{
            pritn("LESS\n");
        }
    }
}
Problem p03807 (python)

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

odd = len(list(filter(lambda x: x % 2 != 0, A)))
even = N - odd

ans = "YES"


if odd == 1 and even == 0:
    odd = odd
elif odd % 2 == 1:
    ans = "NO"
print(ans)

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

odd = len(list(filter(lambda x: x % 2 != 0, A)))
even = N - odd

ans = "YES"


if odd == 1 and even == 0:
    odd = odd
elif odd % 2 == 1:
    ans = "NO"
else:
    even += odd//2
    while True:
        if even == 1:
        if even % 2 == 1:
            ans = "NO"
            break
        even //= 2
print(ans)
Problem p03838 (python)

Fixed submission:
x, y = map(int, input().split())

ans = 0
diff = y-x
abs_diff = abs(abs(y)-abs(x))

ans += abs_diff

if abs_diff == diff:
    ans += 0

elif diff == -1*(abs_diff):
    ans += 2
    if x == 0 or y == 0:
        ans -= 1
else:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
x, y = map(int, input().split())

ans = 0
diff = y-x
abs_diff = abs(abs(y)-abs(x))

ans += abs_diff

if abs_diff == diff:
    ans += 0

elif diff == -1*(abs_diff):
    ans += 2
    if x == 0 or y == 0:
        ans -= 1
else:
    ans += 1

print(ans)
x, y = map(int, input().split())

ans = 0
diff = y-x
abs_diff = abs(abs(y)-abs(x))

ans += abs_diff

if abs_diff == diff:
    ans += 0

elif diff == -1*(abs_diff):
    ans += 2
    if x == 0 or y == 0:
        ans -= 1
else:
    ans += 1

print(ans)
Problem p03856 (python)

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

s = input()
l = len(s)


def dfs(i):
   #    print("->", s[i:])
    if i == l:
        print("YES")
        exit()
    if s[i:i+5] == "dream":
        if i+6 < l and s[i+5:i+7] == "er":
            dfs(i+7)
        dfs(i+5)
    elif s[i:i+5] == "erase":
        if i+5 < l and s[i+5] == "r":
            dfs(i+6)
        dfs(i+5)


dfs(0)
print("NO")

Buggy submission (verdict: Runtime Error):
s1 = "maerd"
s2 = "remaerd"
s3 = "esare"
s4 = "resare"

i = input()
s = ''
for c in reversed(i):
    s += c

l = len(s)

i = 0


def dfs(i):
    if i == l:
        print("YES")
        exit()
    if i+5 <= l and s[i:i+5] == s1:
        dfs(i+5)
    elif i+7 <= l and s[i:i+7] == s2:
        dfs(i+7)
    elif i+5 <= l and s[i:i+5] == s3:
        dfs(i+5)
    elif i+6 <= l and s[i:i+6] == s4:
        dfs(i+6)
    else:
        print("NO")
        exit()


dfs(0)

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

l = len(s)


def dfs(i):
    #    print("->", s[i:])
    if i == l:
        print("YES")
        exit()
    if s[i:i+5] == "dream":
        if i+7 < l and s[i+5:i+7] == "er":
            dfs(i+7)
        dfs(i+5)
    elif s[i:i+5] == "erase":
        if i+5 < l and s[i+5] == "r":
            dfs(i+6)
        dfs(i+5)


dfs(0)
print("NO")

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

l = len(s)


def dfs(i):
    if i == l:
        print("YES")
        exit()
    if s[i:i+5] == "dream":
        if i+7 < l and s[i+5:i+7] == "er":
            dfs(i+7)
        dfs(i+5)
    elif s[i:i+5] == "erase":
        if i+6 < l and s[i+5] == "r":
            dfs(i+6)
        dfs(i+5)


dfs(0)

Buggy submission (verdict: Runtime Error):
ans = "NO"
s = input()


def dfs(s):
    ret = 0
    if len(s) == 0:
        return 1

    if s[:5] == 'dream' or s[:5] == 'erase':
        ret += dfs(s[5:])
    if s[:7] == 'dreamer':
        ret += dfs(s[7:])
    if s[:6] == 'eraser':
        ret += dfs(s[6:])
    return ret


if dfs(s):
    ans = "YES"
print(ans)
Problem p03864 (python)

Fixed submission:
N, x = map(int, input().split())
l = list(map(int, input().split()))

before = sum(l)
l[0] = min(x, l[0])
for i in range(1, N):
    s = l[i-1]+l[i]
    if s > x:
        l[i] = x-l[i-1]

print(before-sum(l))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import heapq
from math import sqrt
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def calc(b1, b2):
    x1, y1, r1 = b1
    x2, y2, r2 = b2
    d = sqrt((x1-x2)**2+(y1-y2)**2)
    return max(d-(r1+r2), 0)


sx, sy, gx, gy = map(int, input().split())
N = int(input())
barriers = [[sx, sy, 0]] + [list(map(int, input().split()))
                            for _ in range(N)]+[[gx, gy, 0]]

mat = [[0]*(N+2) for _ in range(N+2)]

for row in range(N+2):
    for col in range(row+1, N+2):
        d = calc(barriers[row], barriers[col])
        mat[row][col] = d
        mat[col][row] = d

# 視点からの距離
dist = [float('inf')]*(N+2)
dist[0] = 0

# 最短経路での一つ前のノード
prev = defaultdict(lambda: None)

Q = []
# Q->[dist from　start,node])
heapq.heappush(Q, (0, 0))

while Q:
    dist_to_node, node = heapq.heappop(Q)
    if dist[node] < dist_to_node:
        continue
    else:
        for v in range(N+2):
            weight = mat[node][v]
            alt = dist_to_node+weight
            if dist[v] > alt:
                dist[v] = alt
                prev[v] = node
                heapq.heappush(Q, (alt, v))
print(dist[-1])
Problem p03920 (python)

Fixed submission:
def sigma(N):
    return N*(N+1)//2


def find_max(N):
    for i in range(N):
        if sigma(i) > N:
            return i
    return N


def solve(N):
    Y = find_max(N)
    rem = sigma(Y)-N
    for i in range(1, Y+1):
        if i != rem:
            print(i)


N = int(input())
solve(N)

Buggy submission (verdict: Runtime Error):
def sigma(N):
    return N*(N-1)//2


def find_max(N):
    for i in range(N+1):
        if sigma(i) > N:
            return i


def solve(N):
    Y = find_max(N)
    rem = sigma(Y)-N
    for i in range(1, Y):
        if i != rem:
            print(i)


N = int(input())
solve(N)

Buggy submission (verdict: Runtime Error):
def sigma(N):
    return N*(N-1)//2


def find_max(N):
    for i in range(N):
        if sigma(i) > N:
            return i


def solve(N):
    Y = find_max(N)
    rem = sigma(Y)-N
    for i in range(1, Y+1):
        if i != rem:
            print(i)


N = int(input())
solve(N)
Problem p03937 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
cnt=0
for _ in range(H):
  l = input()
  cnt+=l.count("#")
if cnt==H+W-1:
  print("Possible")
else:
  print("Impossible")

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
cnt=0
for _ in range(H):
  cnt+=l.count("#")
if cnt==H+W-1:
  print("Possible")
else:
  print("Impossible")

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [["."]*(W+2) for _ in range(W+2)]
for j in range(1, H+1):
    l = input()
    for i in range(len(l)-1):
        grid[j][i+1] = l[i]


r = 1
c = 1
while r <= H and c <= W:
    if grid[r+1][c] == "#" and grid[r][c+1] == ".":
        r += 1
    elif grid[r+1][c] == "." and grid[r][c+1] == "#":
        c += 1
    elif r == H and c == W:
        ans = "Possible"
        break
    else:
        ans = "Impossible"
        break
print(ans)
Problem p03958 (python)

Fixed submission:
import heapq
K, T = map(int, input().split())
L = list(map(lambda x: -int(x), input().split()))

heapq.heapify(L)

while L and len(L) > 1:
    a = heapq.heappop(L)
    b = heapq.heappop(L)
    r = b-a
    if r > 0:
        heapq.heappush(L, -r)
if L:
    print(-heapq.heappop(L)-1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import heapq
K, T = map(int, input().split())
L = list(map(lambda x: -int(x), input().split()))

heapq.heapify(L)

while L and len(L) > 1:
    a = heapq.heappop(L)
    b = heapq.heappop(L)
    r = b-a
    if r > 0:
        heapq.heappush(L, -r)
print(-heapq.heappop(L)-1)
Problem p04001 (python)

Fixed submission:
s = input()
nums = [int(v) for v in s]

l = len(s)

ans = 0
for i in range(1 << (l-1)):
    tmp = s[0]
    for j in range(l-1):
        if i & 1 << j:
            tmp += '+'+s[j+1]
        else:
            tmp += s[j+1]
    ans += eval(tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
H, W, N = map(int, input().split())
mat = [[0]*W for _ in range(H)]

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


dp = [[0]*W for _ in range(H)]
for h in range(H):
    cnt = 0
    if mat[h][0] == 1:
        dp[h][0] = 1
    for w in range(1, W):
        if mat[h][w] == 1:
            dp[h][w] += 1
        dp[h][w] += dp[h][w-1]


ans = [0]*10
for i in range(10):
    tmp = 0
    for h in range(H-3):
        for w in range(W-3):
            s = 0
            for k in range(3):
                s += dp[h+k][w+2]-dp[h+k][w]
            if s == i:
                tmp += 1
    ans[i] = tmp

for i in ans:
    print(i)
Problem p04019 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

s = input()
ans = "Yes"
if "W" in s:
    if not "E" in s:
        ans = "No"
if "E" in s:
    if not "W" in s:
        ans = "No"

if "N" in s:
    if not "S" in s:
        ans = "No"
if "S" in s:
    if not "N" in s:
        ans = "No"

print(ans)

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
linp = list(map(int, input().split()))

s = input()
ans = "Yes"
if "W" in s:
    if not "E" in s:
        ans = "No"
if "E" in s:
    if not "W" in s:
        ans = "No"

if "N" in s:
    if not "S" in s:
        ans = "No"
if "S" in s:
    if not "N" in s:
        ans = "No"

print(ans)