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

CNT = []
c = 0
for s in S:
  if s == "E":
    c += 1
  CNT.append(c)
  
ans = N + 10
mn = N + 10
for i in range(N):
  c = 0
  if i > 0:
    c += i - 1 - CNT[i-1]
  if i < N - 1:
    c +=  N - i - 1 - (CNT[N] - CNT[i+1])
    
  if c < mn:
    ans = i+1

print(ans)
    

  

Fixed submission:
N = int(input())
S = list(input())

EAST = []
WEST = []
e = 0
w = 0
for s in S:
  if s == "E":
    e += 1
  else:
    w += 1
  EAST.append(e)
  WEST.append(w)
  
ans = N - 1
for i in range(N):
  c = 0
  if i > 0:
    c += WEST[i-1]
  if i < N - 1:
    c += EAST[N-1] - EAST[i]
  
  ans = min(c,ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())
L = len(S)

if L != 26:
  # まだ使ってないもので、最大ものもを最後につける
  USED = [False] * 26
  for s in S:
    USED[ord(s) - 97] = True
  
  for i in range(26):
    if not USED[i]:
      S.append(chr(97+i))
      break
  
  print("".join(S))
else:
  # 26文字ある場合
  prev = -1
  k = -1
  USED = []
  for i in range(26)[::-1]:
    d = ord(S[i]) - 97
    if prev < d:
      prev = d
      USED.append(S[i])
    else:
      k = i
      break
  
  if K == -1:
    print(-1)
    exit()
  
  S = S[:k] + min(USED)
  print("".join(S))


Fixed submission:
S = list(input())
L = len(S)

if L != 26:
  # まだ使ってないもので、最大ものもを最後につける
  USED = [False] * 26
  for s in S:
    USED[ord(s) - 97] = True
  
  for i in range(26):
    if not USED[i]:
      S.append(chr(97+i))
      break
  
  print("".join(S))
else:
  # 26文字ある場合
  prev = -1
  k = -1
  USED = []
  for i in range(26)[::-1]:
    d = ord(S[i]) - 97
    if prev < d:
      prev = d
      USED.append(S[i])
    else:
      k = i
      break
  
  if k == -1:
    print(-1)
  else:  
    nxt = min([s for s in USED if s > S[k]])
    S = S[:k] + [nxt]
    print("".join(S))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
sys.setrecursionlimit(10 ** 7)

# Xor
# ビット毎に独立
# k-bit目を二分探索


N = int(input())

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

ans = 0
for i in range(29):
    NA = [a % 2 ** (i + 1) for a in A]
    NB = [b % 2 ** (i + 1) for b in B]
    NB.sort()

    T = 2 ** i
    cnt = 0
    for a in NA:
        # [T-a,2T-a)
        ta1 = T - a
        ta2 = T * 2 - a
        i1 = bisect.bisect_left(NB, ta1)
        i2 = bisect.bisect_left(NB, ta2) - 1
        cnt += i2 - i1

        # [3T-a,4T-a)
        ta3 = T * 3 - a
        ta4 = T * 4 - a
        i3 = bisect.bisect_left(NB, ta3)
        i4 = bisect.bisect_left(NB, ta4) - 1
        cnt += i4 - i3

    if cnt % 2 == 1:
        ans += 2 ** i

print(ans)


Fixed submission:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

# Xor
# ビット毎に独立
# k-bit目を二分探索


N = int(input())

A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)


mask = 1

ans = 0
for i in range(29):
    NA = A & mask
    NB = B & mask
    NA.sort()
    NB.sort()

    T = 2 ** i
    x1, x2, x3 = [np.searchsorted(NB, t - NA).sum() for t in [T, 2 * T, 3 * T]]
    zero_cnt = x1 + (x3 - x2)
    if (N*N - zero_cnt) % 2 == 1:
        ans += 2 ** i

    mask = mask * 2 + 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
sys.setrecursionlimit(10 ** 7)

# Xor
# ビット毎に独立
# k-bit目を二分探索


N = int(input())

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

ans = 0
for i in range(29):
    NA = [a % 2 ** (i + 1) for a in A]
    NB = [b % 2 ** (i + 1) for b in B]
    NB.sort()

    T = 2 ** i
    cnt = 0
    for a in NA:
        # [T-a,2T-a)
        ta1 = T - a
        ta2 = T * 2 - a
        i1 = bisect.bisect_left(NB, ta1)
        i2 = bisect.bisect_left(NB, ta2) - 1
        cnt += i2 - i1

        # [3T-a,4T-a)
        ta3 = T * 3 - a
        ta4 = T * 4 - a
        i3 = bisect.bisect_left(NB, ta3)
        i4 = bisect.bisect_left(NB, ta4) - 1
        cnt += i4 - i3

    if cnt % 2 == 1:
        ans += 2 ** i

print(ans)


Fixed submission:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

# Xor
# ビット毎に独立
# k-bit目を二分探索


N = int(input())

A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)


mask = 1

ans = 0
for i in range(29):
    NA = A & mask
    NB = B & mask
    NA.sort()
    NB.sort()

    T = 2 ** i
    x1, x2, x3 = [np.searchsorted(NB, t - NA).sum() for t in [T, 2 * T, 3 * T]]
    zero_cnt = x1 + (x3 - x2)
    if (N*N - zero_cnt) % 2 == 1:
        ans += 2 ** i

    mask = mask * 2 + 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N,A,B = map(int,input().split())

ans = 0
for i in range(1,N+1):
  d = sum(list(map(int,list[str(i)])))
  if A <= d <= B:
    ans += 1

print(ans)


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

ans = 0
for i in range(1,N+1):
  d = sum(list(map(int,list(str(i)))))
  if A <= d <= B:
    ans += i

print(ans)

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

ans = 0
for i in range(1,N+1):
  d = sum(map(int,list[str(i)]))
  if A <= d <= B:
    ans += 1

print(ans)

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

ans = 0
for i in range(1,N+1):
  d = sum(list(map(int,list(str(i)))))
  if A <= d <= B:
    ans += i

print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())
T = list(input())

S = [ord(s) for s in S]
T = [ord(s) for s in T]

S.sort()
T.sort(reverse=True)

LS = len(S)
LT = len(T)

ok = False
for i in range(min(LS,LT)):
  s = S[i]
  t = T[i]
  if s < t:
    ok = True
    break
  elif s == t:
    continue
  else t < s:
    ok = False
    break

if ok:
  print('Yes')
else:
  print('No')


Fixed submission:
S = list(input())
T = list(input())

S = [ord(s) for s in S]
T = [ord(s) for s in T]

S.sort()
T.sort(reverse=True)

LS = len(S)
LT = len(T)

ok = None
for i in range(min(LS,LT)):
  s = S[i]
  t = T[i]
  if s < t:
    ok = True
    break
  elif s == t:
    continue
  elif t < s:
    ok = False
    break

if ok:
  print('Yes')
elif ok == None:
  if LS < LT:
    print('Yes')
  else:
    print('No')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

C = Counter(A).most_common()
L = len(C)

if L <= K:
  print(0)
  exit()

ans = 0
cnt = 0
for v in C.values():
  cnt += 1
  if K < cnt:
    ans += v
    
print(ans)


Fixed submission:
from collections import Counter

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

C = Counter(A).most_common()
L = len(C)

if L <= K:
  print(0)
  exit()

ans = 0
cnt = 0
for k,v in C:
  cnt += 1
  if K < cnt:
    ans += v
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [0] * 87
L[0] = 2
L[1] = 1

for i in range(2,88):
  L[i] = L[i-1] + L[i-2]

print(L[N])

Fixed submission:
N = int(input())
L = [0] * 87
L[0] = 2
L[1] = 1

for i in range(2,87):
  L[i] = L[i-1] + L[i-2]

print(L[N])
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
readline = sys.stdin.buffer.readline
N = int(readline())

NUMBERS = defaultdict(bool)

for _ in range(N):
  n = int(readline())
  NUMBERS[n] = not NUMBERS[n]

ans = 0
for k,v in NUMBERS.items():
  if v:
    ans += 1

print(ans)

Fixed submission:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
N = int(readline())

NUMBERS = defaultdict(bool)

for _ in range(N):
  n = int(readline())
  NUMBERS[n] = not NUMBERS[n]

ans = 0
for k,v in NUMBERS.items():
  if v:
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())
USED = [False] * 26

for s in S:
  USED[ord(s)-96] = True
  
ok = False
ans = None
for i in range(26):
  if not USED[i]:
    ans = chr(96+i)
    ok = True
    break
    
if ok:
  print(ans)
else:
  print("None")

Fixed submission:
S = list(input())
USED = [False] * 26

for s in S:
  USED[ord(s)-97] = True
  
ok = False
ans = None
for i in range(26):
  if not USED[i]:
    ans = chr(97+i)
    ok = True
    break
    
if ok:
  print(ans)
else:
  print("None")
Buggy python submission (verdict: Runtime Error):
N = int(intpu())
ans = 1
while True:
  ans *= 2
  if N < ans:
    ans //= 2
    break
    
print(ans)

Fixed submission:
N = int(input())
ans = 1
while True:
  ans *= 2
  if N < ans:
    ans //= 2
    break
    
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

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

ANS = deque()
for i in range(N):
  if i % 2 == 0:
    ANS.append(A[i])
  else:
    ANS.appendleft(A[i])
    
if N % 2 == 1:
  ANS = ANS[::-1]
  
print("".join(map(str,ANS)))

Fixed submission:
from collections import deque

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

ANS = deque()
for i in range(N):
  if i % 2 == 0:
    ANS.append(A[i])
  else:
    ANS.appendleft(A[i])
    
ANS = list(ANS)
if N % 2 == 1:
  ANS = ANS[::-1]
  
print(" ".join(map(str,ANS)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [-1] + [int(input()) for _ in range(N)]
USED = [False] * (N+1)

cnt = 0
prev = 1
while True:
  nxt = A[prev]
  cnt += 1
  
  if nxt == 2:
    break
    
  USED[prev] = True
  if USED[nxt]:
    cnt = -1
    break
    
print(cnt)

Fixed submission:
N = int(input())
A = [-1] + [int(input()) for _ in range(N)]
USED = [False] * (N+1)

cnt = 0
prev = 1
while True:
  nxt = A[prev]
  cnt += 1
  
  if nxt == 2:
    break
    
  USED[prev] = True
  if USED[nxt]:
    cnt = -1
    break
    
  prev = nxt
    
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)

# 最小全域木
# プリム法 #
# 部分木から、最小コストの辺を貪欲に追加

# Kruskal法 #
# クラスカル法 #
# 辺でソートして、最小コストの辺から、ループにならないよう貪欲に追加
# UnionFindを使う


N = int(input())

# x,yでそれぞれソート
POINT_x = []
POINT_y = []
for _ in range(N):
    x, y = map(int, input().split())
    POINT_x.append((x, y))
    POINT_y.append((x, y))

POINT_x = sorted(POINT_x, key=lambda x: x[0])
POINT_y = sorted(POINT_y, key=lambda x: x[1])

EDGE = defaultdict(list)
for i in range(N):
    p = POINT_x[i]

    if i != 0:
        prev = POINT_x[i-1]
        EDGE[p].append((abs(p[0]-prev[0]), prev))

    if i != N-1:
        nxt = POINT_x[i+1]
        EDGE[p].append((abs(p[0]-nxt[0]), nxt))

for i in range(N):
    p = POINT_y[i]

    if i != 0:
        prev = POINT_y[i-1]
        EDGE[p].append((abs(p[1]-prev[1]), prev))

    if i != N-1:
        nxt = POINT_y[i+1]
        EDGE[p].append((abs(p[1]-nxt[1]), nxt))


INF = 10 ** 12
mincost = [INF] * N
used = defaultdict(lambda: False)

point = POINT_x[0]
used[point] = True
q = []
ans = 0

for e in EDGE[point]:
    heapq.heappush(q, e)

while(True):
    update = False
    for _ in range(len(q)):
        cost, point = heapq.heappop(q)
        if used[point]:
            continue

        update = True
        ans += cost
        used[point] = True

        for e in EDGE[point]:
            heapq.heappush(q, e)

    if not update:
        break

print(ans)


Fixed submission:
import sys
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)

# 最小全域木
# プリム法 #
# 部分木から、最小コストの辺を貪欲に追加

# Kruskal法 #
# クラスカル法 #
# 辺でソートして、最小コストの辺から、ループにならないよう貪欲に追加
# UnionFindを使う


N = int(input())

# x,yでそれぞれソート
POINT_x = []
POINT_y = []
for _ in range(N):
    x, y = map(int, input().split())
    POINT_x.append((x, y))
    POINT_y.append((x, y))

POINT_x = sorted(POINT_x, key=lambda x: x[0])
POINT_y = sorted(POINT_y, key=lambda x: x[1])

EDGE = defaultdict(list)
for i in range(N):
    p = POINT_x[i]

    if i != 0:
        prev = POINT_x[i-1]
        EDGE[p].append((abs(p[0]-prev[0]), prev))

    if i != N-1:
        nxt = POINT_x[i+1]
        EDGE[p].append((abs(p[0]-nxt[0]), nxt))

for i in range(N):
    p = POINT_y[i]

    if i != 0:
        prev = POINT_y[i-1]
        EDGE[p].append((abs(p[1]-prev[1]), prev))

    if i != N-1:
        nxt = POINT_y[i+1]
        EDGE[p].append((abs(p[1]-nxt[1]), nxt))


INF = 10 ** 12
mincost = [INF] * N
used = defaultdict(lambda: False)

point = POINT_x[0]
used[point] = True
q = []
ans = 0

for e in EDGE[point]:
    heapq.heappush(q, e)

while(True):
    update = False
    for _ in range(len(q)):
        cost, point = heapq.heappop(q)
        if used[point]:
            continue

        update = True
        ans += cost
        used[point] = True

        for e in EDGE[point]:
            if not used[e[1]]:
                heapq.heappush(q, e)

    if not update:
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

S = input()
uni_s = list(set(list(S)))

ans = len(S) - 1

# -1,1
for s in uni_s:
  L = len(S)
  T = list(S)
  all_same = [s == t for t in S]
  cnt = 0
  while not all(all_same):
    newT = [False] * (L-1)
    for i in range(L):
      t = T[i]
      if s == t:
        newT[i] = t
        if 0 <= i-1:
          newT[i-1] = t
      else:
        if not newT[i]:
          newT[i] = t
        if 0 <= i-1 and not newT[i-1]:
          newT[i-1] = t
    
    all_same = [s==t for t in newT]
    T = newT
    L = len(T)
  ans = min(ans,cnt)

print(ans)
      
    

Fixed submission:
S = input()
uni_s = list(set(list(S)))

ans = len(S) - 1

# -1,1
for s in uni_s:
  L = len(S)
  T = list(S)
  all_same = [s == t for t in S]
  cnt = 0
  while not all(all_same):
    cnt += 1
    newT = [False] * (L-1)
    for i in range(L):
      t = T[i]
      if s == t:
        if i < L-1:
          newT[i] = t
        if 0 <= i-1:
          newT[i-1] = t
      else:
        if i < L-1 and not newT[i]:
          newT[i] = t
        if 0 <= i-1 and not newT[i-1]:
          newT[i-1] = t
    
    all_same = [s==t for t in newT]
    T = newT
    L = len(T)
  ans = min(ans,cnt)

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = [int(input()) for _ in range(N)]

POINT = [False] * (10 ** 4 + 101)
POINT[0] = True
LP = len(POINT)

for p in P:
  for i in range(10**4+1,-1,-1):
    POINT[i+p] = POINT[i] | POINT[i+p]
  
ans = 0
for i in range(LP):
  if POINT[i] and i % 10 != 0:
    ans = max(i,ans)
    
print(ans)


Fixed submission:
N = int(input())
P = [int(input()) for _ in range(N)]

POINT = [False] * (10 ** 4 + 101)
POINT[0] = True
LP = len(POINT)

for p in P:
  for i in range(10**4,-1,-1):
    POINT[i+p] = POINT[i] | POINT[i+p]
  
ans = 0
for i in range(LP):
  if POINT[i] and i % 10 != 0:
    ans = max(i,ans)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [int(input()) for _ in range(N)]

POINT = [False] * (10 ** 4 + 101)
POINT[0] = True
LP = len(POINT)

for p in POINT:
  for i in range(10**4):
    POINT[i+p] = POINT[i] | POINT[i+p]
  
ans = 0
for i in range(LP):
  if POINT[i]:
    ans = max(i,ans)
    
print(ans)


Fixed submission:
N = int(input())
P = [int(input()) for _ in range(N)]

POINT = [False] * (10 ** 4 + 101)
POINT[0] = True
LP = len(POINT)

for p in P:
  for i in range(10**4,-1,-1):
    POINT[i+p] = POINT[i] | POINT[i+p]
  
ans = 0
for i in range(LP):
  if POINT[i] and i % 10 != 0:
    ans = max(i,ans)
    
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
P = [int(input()) for _ in range(N)]

POINT = [False] * (10 ** 4 + 10)
POINT[0] = True
LP = len(POINT)

for p in POINT:
  for i in range(LP):
    POINT[i+p] = POINT[i] | POINT[i+p]
  
ans = 0
for i in range(LP):
  if POINT[i]:
    ans = max(i,ans)
    
print(ans)

Fixed submission:
N = int(input())
P = [int(input()) for _ in range(N)]

POINT = [False] * (10 ** 4 + 101)
POINT[0] = True
LP = len(POINT)

for p in P:
  for i in range(10**4,-1,-1):
    POINT[i+p] = POINT[i] | POINT[i+p]
  
ans = 0
for i in range(LP):
  if POINT[i] and i % 10 != 0:
    ans = max(i,ans)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,C = map(int,input().split())
ans = None

if A == B and B == C:
  print(-1)
  exit()
  
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
  A,B,C = (B+C)//2,(C+A)//2,(A+B)//2
  ans += 1
  
  if A == B and B == C:
    print(-1)
    exit()
    
print(ans)


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

if not (A % 2 == 0 and B % 2 == 0 and C % 2 == 0):
  print(0)
  exit()

if A == B and B == C:
  print(-1)
  exit()
  
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
  A,B,C = (B+C)//2,(C+A)//2,(A+B)//2
  ans += 1
  
  if A == B and B == C:
    print(-1)
    exit()
    
print(ans)

Buggy python submission (verdict: Runtime Error):
A,B,C = int(input())
ans = None

if A == B and B == C:
  print(-1)
  exit()
  
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
  A,B,C = (B+C)//2,(C+A)//2,(A+B)//2
  ans += 1
  
  if A == B and B == C:
    print(-1)
    exit()
    
print(ans)

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

if not (A % 2 == 0 and B % 2 == 0 and C % 2 == 0):
  print(0)
  exit()

if A == B and B == C:
  print(-1)
  exit()
  
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
  A,B,C = (B+C)//2,(C+A)//2,(A+B)//2
  ans += 1
  
  if A == B and B == C:
    print(-1)
    exit()
    
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,C = map(int,input().split())

D = A % B
M = D
ok = False
for _ in range(B+1):
  if M == C:
    ok = True
	break
    
  M = (M + D) % B
  
if ok:
  print('YES')
else:
  print('NO')

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

D = A % B
M = D
ok = False
for _ in range(B+1):
  if M == C:
    ok = True
    break
    
  M = (M + D) % B
  
if ok:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
A = list(map(int,input().split()))
LST = []

for a in A:
  LST.append((a,1))
  LST.append((a+T,-1))
  
LST.sort()

prev = -1
s = 0
ans = 0
for x,y in A:
  if y == 1:
    if s == 0:
      prev = x
    else:
      s += 1
  elif y == -1:
    s -= 1
    if s == 0:
      ans += (x - prev)
  
print(ans)



Fixed submission:
N,T = map(int,input().split())
A = list(map(int,input().split()))
LST = []

for a in A:
  LST.append((a,1))
  LST.append((a+T,-1))
  
LST.sort()

prev = -1
s = 0
ans = 0
for x,y in LST:
  if y == 1:
    s += 1
    if s == 1:
      prev = x
  elif y == -1:
    s -= 1
    if s == 0:
      ans += (x - prev)
  
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,inpu().split())

def solve(N,M):
  # 今あるもの
  if M < N * 2:
    return N
  
  M -= N * 2
  
  ans = N + M // 3
  return ans

print(solve(N,M))


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

def solve(N,M):
  # 今あるもの
  if M < N * 2:
    return M // 2
  
  M -= N * 2
  
  ans = N + (M // 4)
  return ans

print(solve(N,M))
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
cnt = 0

for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if (x+y+z)==s:
                cnt += 1

print(cnt)

Fixed submission:
k,s = map(int,input().split())
cnt = 0
z = list(range(k+1))

for x in range(k+1):
    for y in range(k+1):
        m = s - x - y
        if 0 <= m & m <= k:
            cnt += 1

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

def dfs(h,w,c):
  if h == H - 1 and w == W - 1:
    return c + 1
  
  if GRID[h][w] != "#":
    return 0
  
  if H - 1 < h or W -1 < w:
    return 0
  
  right = dfs(h+1,w,c+1)
  down = dfs(h,w+1,c+1)
  c += max(right,down)

  return c

NUM = sum([GRID[x].count("#") for x in range(H)])

n = dfs(0,0,0)

if n == NUM:
  print("Possible")
else:
  print("Impossible")





Fixed submission:
H,W = map(int,input().split())
GRID = [list(input()) for _ in range(H)]

def dfs(h,w,c):
  if h == H - 1 and w == W - 1:
    return c + 1

  if H - 1 < h or W -1 < w:
    return 0
  
  if GRID[h][w] != "#":
    return 0
  
  
  right = dfs(h+1,w,c+1)
  down = dfs(h,w+1,c+1)

  return max(right,down)

NUM = sum([GRID[x].count("#") for x in range(H)])

n = dfs(0,0,0)

if n == NUM:
  print("Possible")
else:
  print("Impossible")
Buggy python submission (verdict: Runtime Error):
from collection import Counter
S = list(input())

C = Counter(S)

ok = True
for s,x in list(C.items()):
  if x % 2 != 0:
    ok = False
    break

if ok:
  print("Yes")
else:
  print("No")


Fixed submission:
from collections import Counter
S = list(input())

C = Counter(S)

ok = True
for s,x in C.items():
  if x % 2 != 0:
    ok = False
    break

if ok:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
from collection import Counter
S = list(input())

C = Counter(S)

ok = True
for s,x in C.items():
  if x % 2 != 0:
    ok = False
    break

if ok:
  print("Yes")
else:
  print("No")

Fixed submission:
from collections import Counter
S = list(input())

C = Counter(S)

ok = True
for s,x in C.items():
  if x % 2 != 0:
    ok = False
    break

if ok:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
s, t = input().split(' ')
a, b = map(int, input().split(' '))
u = input()

d = {
    'red': a,
    'blue': b
}

d[u] -= 1

print(d['red'], d['blue'])

Fixed submission:
s, t = input().split(' ')
a, b = map(int, input().split(' '))
u = input()

d = {}
d[s] = a
d[t] = b
d[u] -= 1

print(d[s], d[t])
Buggy python submission (verdict: Runtime Error):
i = input().split(" ")

r = int(i[0])
d = int(i[1])
a = int(i[2])

for i in range(10):
	a = a * r - d
	print(a)


Fixed submission:
i = input().split(' ')

a = int(i[0])
b = int(i[1])

if a >= 13:
	print(b)
elif a >= 6:
	print(b // 2)
else:
	print(0)
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
c = input()
d = input()
e = input()
k = input()

if (max(a,b,c,d,e) - min(a,b,c,d,e,f) <= 15):
	print('Yay!')
else:
	print(':(')

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
 
if (max(a,b,c,d,e) - min(a,b,c,d,e) <= k):
	print('Yay!')
else:
	print(':(')
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

cnt = 1
sevens = 0

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    while True:
        sevens = sevens * 10 + 7
        if sevens % K == 0:
            print(cnt)
            exit()
        cnt += 1



Fixed submission:
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    x = 7 % K
    for i in range(1, K + 1):
        if x == 0:
            print(i)
            break
        x = (x * 10 + 7) % K

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

cnt = 1
sevens = 0

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    while True:
        sevens = sevens * 10 + 7
        if sevens % K == 0:
            print(cnt)
            exit()
        cnt += 1



Fixed submission:
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    x = 7 % K
    for i in range(1, K + 1):
        if x == 0:
            print(i)
            break
        x = (x * 10 + 7) % K
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = input().split()
result = 1

for i in A:
    result *= int(i)

if result > 10**18:
    print(-1)
else:
    print(result)

Fixed submission:
N = int(input())

A = input().split()
result = 1

A.sort()
fl = True

if int(A[0]) == 0:
    print(0)
else:
    for i in A:
        result *= int(i)
        if result > 10**18:
            fl = False   
            break                
    if fl:
        print(result)
    else:
        print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())
biggest = 0

for i in range(1, N+1):
    X = ((A*i) // B)
    Y = A * (i // B)
    if biggest < (X - Y):
        biggest = X - Y

print(biggest)

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


if N >= B:
    X = (A*(B-1)) // B
    Y = A * ((B-1)//B)
    print(X-Y)
else:
    X = (A*N) // B
    Y = A * (N//B)
    print(X-Y)
Buggy python submission (verdict: Time Limit Exceeded):
import math

N = int(input())

result = 0

for a in range(1, N+1):
    for b in range(1, N+1):
        for c in range(1, N+1):
            result += math.gcd(math.gcd(a,b),c)

print(result)

Fixed submission:
import math

N = int(input())

result = 0

for a in range(1, N+1):
    for b in range(1, N+1):
        if math.gcd(a,b) == 1:
            result += 1*N
        else:
            for c in range(1, N+1):
                result += math.gcd(math.gcd(a,b),c)

print(result)