Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

from collcections import defaultdict
import math
n,m = map(int, input().split())
s = input()
t = input()
g = math.gcd(n,m)
d = defaultdict(list)
for i in range(n):
    ind = i*(m//g)
    d[ind].append(s[i])
for i in range(m):
    ind = i*(n//g)
    d[ind].append(t[i])
for k,v in d.items():
    if v and not all(item==v[0] for item in v):
        ans = -1
        break
else:
    ans = n*m//g
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

from collections import defaultdict
import math
n,m = map(int, input().split())
s = input()
t = input()
g = math.gcd(n,m)
d = defaultdict(list)
for i in range(n):
    ind = i*(m//g)
    d[ind].append(s[i])
for i in range(m):
    ind = i*(n//g)
    d[ind].append(t[i])
for k,v in d.items():
    if v and not all(item==v[0] for item in v):
        ans = -1
        break
else:
    ans = n*m//g
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


import math
n,m = map(int, input().split())
s = input()
t = input()
g = math.gcd(n,m)
d = defaultdict(list)
for i in range(n):
    ind = i*(m//g)
    d[ind].append(s[i])
for i in range(m):
    ind = i*(n//g)
    d[ind].append(t[i])
for k,v in d.items():
    if v and not all(item==v[0] for item in v):
        ans = -1
        break
else:
    ans = n*m//g
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

from collections import defaultdict
import math
n,m = map(int, input().split())
s = input()
t = input()
g = math.gcd(n,m)
d = defaultdict(list)
for i in range(n):
    ind = i*(m//g)
    d[ind].append(s[i])
for i in range(m):
    ind = i*(n//g)
    d[ind].append(t[i])
for k,v in d.items():
    if v and not all(item==v[0] for item in v):
        ans = -1
        break
else:
    ans = n*m//g
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xyh = [None]*n
for i in range(n):
    x,y,h = map(int, input().split())
    xyh[i] = (x,y,h)
    
for i in range(101):
    for j in range(101):
        x,y,h = xyh[0]
        H = h + abs(x-i) + abs(y-j)
        bad = False
        for x,y,h in xyh:
            if max(0, H - abs(x-i) - abs(y-j))!=h:
                bad = True
                break
        if bad:
            pass
        else:
            ans = (i,j,H)
            break
    if not bad:
        break
print(" ".join(map(str, ans)))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xyh = [None]*n
for i in range(n):
    x,y,h = map(int, input().split())
    xyh[i] = (x,y,h)
ans = []
bx,by,bh = max(xyh, key=lambda p: p[2])
for i in range(101):
    for j in range(101):
        H = bh + abs(bx-i) + abs(by-j)
        bad = False
        for x,y,h in xyh:
            if max(0, H - abs(x-i) - abs(y-j))!=h:
                bad = True
                break
        if bad:
            pass
        else:
            ans = (i,j,H)
            break
    if not bad:
        break
print(" ".join(map(str, ans)))

Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xyh = [None]*n
for i in range(n):
    x,y,h = map(int, input().split())
    xyh[i] = (x,y,h)
    
minh = min(item[2] for item in xyh) - 200
minh = max(minh, 1)
minh = max(item[2] for item in xyh) + 200
for i in range(101):
    for j in range(101):
        x,y,h = xyh[0]
        H = h + abs(x-i) + abs(y-j)
        bad = False
        for x,y,h in xyh:
            if max(0, H - abs(x-i) - abs(y-j))!=h:
                bad = True
                break
        if bad:
            continue
        else:
            ans = (i,j,H)
            break
    if not bad:
        break
print(" ".join(map(str, ans)))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xyh = [None]*n
for i in range(n):
    x,y,h = map(int, input().split())
    xyh[i] = (x,y,h)
ans = []
bx,by,bh = max(xyh, key=lambda p: p[2])
for i in range(101):
    for j in range(101):
        H = bh + abs(bx-i) + abs(by-j)
        bad = False
        for x,y,h in xyh:
            if max(0, H - abs(x-i) - abs(y-j))!=h:
                bad = True
                break
        if bad:
            pass
        else:
            ans = (i,j,H)
            break
    if not bad:
        break
print(" ".join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print((a-1)*(b-1))

Fixed submission:
a,b = [int(item) for item in input().split(" ")]
print((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


import math
def sub(a,b,c,d):
    x1 = a - (a - (c+1))//b * b
    if d<b:
        ans = "No"
    elif a<b:
        ans = "No"
    elif d%b==0:
        if x1>=b:
            ans = "Yes"
        else:
            ans = "No"
    else:
        k = math.gcd(d,b)
        x2 = x1 - (x1 - (c+1))//k * k
        if x2>=b:
            ans = "Yes"
        else:
            ans = "No"
    return ans

t = int(input())
ans = []
for i in range(t):
    a,b,c,d = map(int, input().split())
    ans.append(sub(a,b,c,d))
write("\n".join(ans))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def sub(a,b,c,d):
    x1 = a - (a - (c+1))//b * b
    if d<b:
        ans = "No"
    elif a<b:
        ans = "No"
    elif d%b==0:
        if x1>=b:
            ans = "Yes"
        else:
            ans = "No"
    else:
        k = gcd(d,b)
        x2 = x1 - (x1 - (c+1))//k * k
        if x2>=b:
            ans = "Yes"
        else:
            ans = "No"
    return ans

t = int(input())
ans = []
for i in range(t):
    a,b,c,d = map(int, input().split())
    ans.append(sub(a,b,c,d))
write("\n".join(ans))
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
ab = [None]*n
cd = [None]*n
for i in range(n):
    ab[i] = tuple(map(int, input().split()))
for i in range(n):
    cd[i] = tuple(map(int, input().split()))
import networkx as nx
g = nx.DiGraph()
for i in range(2*n+2):
    g.add_node(i)
s = 2*n
t = 2*n+1
for i in range(n):
    g.add_edge(s,i, capacity=1)
for i in range(n, 2*n):
    g.add_edge(i, t, capacity=1)
for i in range(n):
    for j in range(n, 2*n):
        if ab[i][0]<cd[j-n][0] and ab[i][1]<cd[j-n][1]:
            g.add_edge(i,j, capacity=1)
val = nx.maximum_flow(g, s, t)
print(val[0])

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
ab = [None]*n
cd = [None]*n
for i in range(n):
    ab[i] = tuple(map(int, input().split()))
for i in range(n):
    cd[i] = tuple(map(int, input().split()))
import networkx as nx
g = nx.DiGraph()
for i in range(2*n+2):
    g.add_node(i)
s = 2*n
t = 2*n+1
for i in range(n):
    g.add_edge(s,i, capacity=1)
for i in range(n, 2*n):
    g.add_edge(i, t, capacity=1)
for i in range(n):
    for j in range(n, 2*n):
        if ab[i][0]<cd[j-n][0] and ab[i][1]<cd[j-n][1]:
            g.add_edge(i,j, capacity=1)
val = nx.maximum_flow(g, s, t)
print(val[0])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
K = int(input())
n = len(s)
dp = [[[0]*(K+1) for _ in range(n+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(K+1):
        dp[i][i+1][j] = 1
for l in range(2, n+1):
    for i in range(n-l+1):
        for k in range(K+1):
#             print(l, i, i+l, j)
            if s[i]==s[i+l-1]:
                dp[i][i+l][k] = dp[i+1][i+l-1][k] + 2
            else:
                dp[i][i+l][k] = max(dp[i+1][i+l][k], dp[i][i+l-1][k])
                if k>=1:
                    dp[i][i+l][k] = max(dp[i][i+l][k], dp[i+1][i+l-1][k-1]+2)
ans = max(dp[0][n][j] for j in range(K+1))
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



s = input()
K = int(input())
n = len(s)
dp = [[[0]*(K+1) for _ in range(n+2-i)] for i in range(n+1)]
for i in range(n):
    for j in range(K+1):
        dp[i][1][j] = 1
for l in range(2, n+1):
    for i in range(n-l+1):
        for k in range(K+1):
#             print(l, i, i+l, j)
            if s[i]==s[i+l-1]:
                dp[i][l][k] = dp[i+1][l-2][k] + 2
            else:
                dp[i][l][k] = max(dp[i+1][l-1][k], dp[i][l-1][k])
                if k>=1:
                    dp[i][l][k] = max(dp[i][l][k], dp[i+1][l-2][k-1]+2)
ans = max(dp[0][i][j] for i in range(n+2) for j in range(K+1))
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n,m = map(int, input().split())
ns = defaultdict(set)
for _ in range(m):
    u,v,c = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add((c,v))
    ns[v].add((-c,u))
vals = [None] * n
def dijkstra(start):
    h = [start]
    vals[start] = 0
    ans = True
    while h:
        u = h.pop()
        for d, v in ns[u]:
            if vals[v] is None:
                vals[v] = vals[u]+d
                h.append(v)
            else:
                if vals[v]!=val+d:
                    return False
    return ans

for start in range(n):
    if vals[start] is not None:
        continue
    res = dijkstra(start)
    if not res:
        print("No")
        break
else:
    print("Yes")

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n,m = map(int, input().split())
ns = defaultdict(set)
for _ in range(m):
    u,v,c = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add((c,v))
    ns[v].add((-c,u))
vals = [None] * n
def dijkstra(start):
    import heapq
    h = [(0, start)] # (距離, ノード番号)
    vals[start] = 0
    ans = True
    while h:
        val, u = heapq.heappop(h)
        for d, v in ns[u]:
            if vals[v] is None:
                vals[v] = val+d
                heapq.heappush(h, (vals[v], v))
            else:
                if vals[v]!=val+d:
                    return False
    return ans

for start in range(n):
    if vals[start] is not None:
        continue
    res = dijkstra(start)
    if not res:
        print("No")
        break
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n,m = map(int, input().split())
ns = defaultdict(set)
for _ in range(n-1):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add(v)
    ns[v].add(u)
s = 0
for t in ns[s]:
    break
l = set([s,t])
from queue import deque
ans = deque([s,t])
while True:
    if not all(u in l for u in ns[s]):
        for u in ns[s]:
            if u not in l:
                break
        ans.appendleft(u)
        l.add(u)
        s = u
    elif not all(v in l for v in ns[t]):
        for v in ns[t]:
            if v not in l:
                break
        ans.append(v)
        l.add(v)
        t = v
    else:
        break
print(len(ans))
write(" ".join(map(lambda x: str(x+1), ans)))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n,m = map(int, input().split())
ns = defaultdict(set)
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add(v)
    ns[v].add(u)
s = 0
for t in ns[s]:
    break
l = set([s,t])
from queue import deque
ans = deque([s,t])
while True:
    if not all(u in l for u in ns[s]):
        for u in ns[s]:
            if u not in l:
                break
        ans.appendleft(u)
        l.add(u)
        s = u
    elif not all(v in l for v in ns[t]):
        for v in ns[t]:
            if v not in l:
                break
        ans.append(v)
        l.add(v)
        t = v
    else:
        break
print(len(ans))
write(" ".join(map(lambda x: str(x+1), ans)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(set)
for i in range(n-1):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add(v)
    ns[v].add(u)
    
    
def sub(u, p):
    if len(ns[u])==1 and p in ns[u]:
        return a[u]
    ub = 0
    mv = 0
    msum = 0
    for v in ns[u]:
        if p==v:
            continue
        val = sub(v, u)
        if val is None:
            return None
        mv = max(mv, val)
        msum += val
    lb = max(mv, msum//2)
    if not (lb<=a[u]<=msum):
#         print(u,lb, msum, mv)
        return None
    else:
        return a[u] - (msum-a[u])
if n==2:
    if a[0]==a[1]:
        print("YES")
    else:
        print("NO")
else:
    if len(ns[0])>1:
        ans = sub(0, -1)
    else:
        ans = sub(list(ns[0])[0], -1)

    if ans is None or ans!=0:
        print("NO")
    else:
        print("YES")

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(set)
for i in range(n-1):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add(v)
    ns[v].add(u)
    
    
def sub(u, p):
    if len(ns[u])==1 and p in ns[u]:
        return a[u]
    ub = 0
    mv = 0
    msum = 0
    for v in ns[u]:
        if p==v:
            continue
        val = sub(v, u)
        if val is None:
            return None
        mv = max(mv, val)
        msum += val
    lb = max(mv, msum//2)
    if not (lb<=a[u]<=msum):
#         print(u,lb, msum, mv)
        return None
    else:
        return a[u] - (msum-a[u])
if n==2:
    if a[0]==a[1]:
        print("YES")
    else:
        print("NO")
else:
    if len(ns[0])>1:
        ans = sub(0, -1)
    else:
        ans = sub(list(ns[0])[0], -1)

    if ans is None or ans!=0:
        print("NO")
    else:
        print("YES")
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
from collections import Counter
c = Counter(a)
ones = sum(v==1 for v in c.values())
ns = [v-1 for v in c.values() if v>1]
ans = ones + len(ns)
ns.sort()
if ns[-1]>sum(ns[:-1]):
    after = ns[-1] - sum(ns[:-1])
    if after%2==1:
        ans -= 1
else:
    after = 1 if sum(ns)%2==1 else 0
    if after==1:
        ans -= 1
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
from collections import Counter
c = Counter(a)
ones = sum(v==1 for v in c.values())
ns = [v-1 for v in c.values() if v>1]
ans = ones + len(ns)
ns.sort()
if not ns:
    pass
elif ns[-1]>sum(ns[:-1]):
    after = ns[-1] - sum(ns[:-1])
    if after%2==1:
        ans -= 1
else:
    after = 1 if sum(ns)%2==1 else 0
    if after==1:
        ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None]*(n-1)
from collections import defaultdict
c = defaultdict(list)
for i in range(n-1):
    num = int(input())
    c[num].append(i+2)

def sub(winner):
    l = len(c[winner])
    vs = []
    for p in c[winner]:
        vs.append(sub(p))
    vs.sort()
    ans = l
    for i,v in enumerate(vs):
        ans = max(ans, l-(i)+v)
#     print(winner, ans, l, vs)
    return ans
ans = sub(1)
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None]*(n-1)
from collections import defaultdict
c = defaultdict(list)
for i in range(n-1):
    num = int(input())
    c[num].append(i+2)

def sub(winner):
    l = len(c[winner])
    vs = []
    for p in c[winner]:
        vs.append(sub(p))
    vs.sort()
    ans = l
    for i,v in enumerate(vs):
        ans = max(ans, l-(i)+v)
#     print(winner, ans, l, vs)
    return ans
ans = sub(1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k,l = list(map(int, input().split()))
from collections import defaultdict
ns0 = defaultdict(set)
ns1 = defaultdict(set)
for i in range(k):
    p,q = map(int, input().split())
    p-=1;q-=1
    ns0[p].add(q)
    ns0[q].add(p)
for i in range(l):
    p,q = map(int, input().split())
    p-=1;q-=1
    ns1[p].add(q)
    ns1[q].add(p)
def sub(ns):
    seen = [None]*n
    num = 1
    for i in range(n):
        if seen[i] is not None:
            continue
        q = [i]
        seen[i] = num
        while q:
            u = q.pop()
            for v in ns[u]:
                if seen[v] is not None:
                    continue
                seen[v] = num
                q.append(v)
        num += 1
    return seen
s1 = sub(ns0)
s2 = sub(ns1)
d1 = defaultdict(set)
d2 = defaultdict(set)
for i in range(n):
    d1[s1[i]].add(i)
    d2[s2[i]].add(i)
d = {}
ans = [None]*n
for i in range(n):
    u,v = s1[i], s2[i]
    if (u,v) not in d:
        d[u,v] = len(d1[u] & d2[v])
    ans[i] = d[u,v]
write(" ".join(map(str, ans)))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k,l = list(map(int, input().split()))
from collections import defaultdict
ns0 = defaultdict(list)
ns1 = defaultdict(list)
for i in range(k):
    p,q = map(int, input().split())
    p-=1;q-=1
    ns0[p].append(q)
    ns0[q].append(p)
for i in range(l):
    p,q = map(int, input().split())
    p-=1;q-=1
    ns1[p].append(q)
    ns1[q].append(p)
def sub(ns):
    seen = [None]*n
    num = 1
    for i in range(n):
        if seen[i] is not None:
            continue
        q = [i]
        seen[i] = num
        while q:
            u = q.pop()
            for v in ns[u]:
                if seen[v] is not None:
                    continue
                seen[v] = num
                q.append(v)
        num += 1
    return seen

s1 = sub(ns0)
s2 = sub(ns1)

import gc
del ns0, ns1
gc.collect()

d1 = [None]*(max(s1)+1)
d2 = [None]*(max(s2)+1)
def update(d,ind,i):
    if d[ind] is None:
        d[ind] = set([i])
    else:
        d[ind].add(i)
for i in range(n):
    update(d1,s1[i],i)
    update(d2,s2[i],i)
#     d1[s1[i]].add(i)
#     d2[s2[i]].add(i)
d = {}
ans = [None]*n
for i in range(n):
    u,v = s1.pop(), s2.pop()
    if (u,v) not in d:
        d[u,v] = len(d1[u] & d2[v])
    ans[-(i+1)] = d[u,v]
write(" ".join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w = map(int, input().split())
a = [None]*h
for i in range(h):
    a[i] = input()
cx = 0
cy = 0
d = set()
while (cx,cy)!=(h-1, w-1):
    val = 0
#     print(cx,cy)
    for dx, dy in [(1,0), (0,1)]:
        ccx = cx+dx
        ccy = cy+dy
        if ccx>=h or ccy>=w or a[ccx][ccy]==".":
            continue
        nx, ny = ccx, ccy
        val += 1
    if val>=2 or val==0:
        ans = "Impossible"
        break
    cx, cy = nx, ny
else:
    vv = sum(item=="#" for item in items for items in a)
    if vv==h+w-1:
        ans = "Possible"
    else:
        ans = "Impossible"
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w = map(int, input().split())
a = [None]*h
for i in range(h):
    a[i] = input()
cx = 0
cy = 0
d = set()
while (cx,cy)!=(h-1, w-1):
    val = 0
#     print(cx,cy)
    for dx, dy in [(1,0), (0,1)]:
        ccx = cx+dx
        ccy = cy+dy
        if ccx>=h or ccy>=w or a[ccx][ccy]==".":
            continue
        nx, ny = ccx, ccy
        val += 1
    if val>=2 or val==0:
        ans = "Impossible"
        break
    cx, cy = nx, ny
else:
    vv = sum(sum(item=="#" for item in items) for items in a)
    if vv==h+w-1:
        ans = "Possible"
    else:
        ans = "Impossible"
print(ans)
Buggy python submission (verdict: Runtime Error):
# ABC047D

import sys# ABC047D

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


n,t = map(int, input().split())
a = list(map(int, input().split()))

M = -1
m = 10**10
best = 0
count = 0
for num in a[::-1]:
    if M<num:
        M = num
        m = M
    elif num<m:
        m = num
    if best<(M-m):
        best = M - m
        count = 1
    elif best==(M-m):
        count += 1
#     print(M, m, count, best)
print(count) if t%2==0 else print(1)
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


n,t = map(int, input().split())
a = list(map(int, input().split()))

M = -1
m = 10**10
best = 0
count = 0
for num in a[::-1]:
    if M<num:
        M = num
        m = M
    elif num<m:
        m = num
    if best<(M-m):
        best = M - m
        count = 1
    elif best==(M-m):
        count += 1
#     print(M, m, count, best)
print(count)

Fixed submission:
# ABC047D

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


n,t = map(int, input().split())
a = list(map(int, input().split()))

m = a[0]
best = 0
count = 0
for num in a[1:]:
    if m>num:
        m = num
    elif best<num-m:
        best = num - m
        count = 1
    elif best==num-m:
        count += 1
print(count)