Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s_list = ["".join(sorted(input())) for i in range(N)]

count = 0

s_list = sorted(s_list)

flag = False

for i in range(len(s_list)):
  for j in range(i+1, len(s_list)):
    if s_list[i] == s_list[j]:
      count += 1
      flag = True
    if s_list[i] != s_list[j] and flag == True:
      flag = False
      continue
      
print(count)

Fixed submission:
import collections

N = int(input())
s_list = ["".join(sorted(input())) for i in range(N)]
s_list = sorted(s_list)

count = 0

c = collections.Counter(s_list)

for item in c:
  for pair in range(c[item]):
    count += pair
        
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s_list = [sorted(input()) for i in range(N)]

count = 0

for i in range(len(s_list)):
  for j in range(i+1, len(s_list)):
    if s_list[i] == s_list[j]:
      count += 1
      
print(count)

Fixed submission:
import collections

N = int(input())
s_list = ["".join(sorted(input())) for i in range(N)]
s_list = sorted(s_list)

count = 0

c = collections.Counter(s_list)

for item in c:
  for pair in range(c[item]):
    count += pair
        
print(count)

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

count = 0

for i in range(len(s_list)):
  for j in range(i+1, len(s_list)):
    if sorted(s_list[i]) == sorted(s_list[j]):
      count += 1
      
print(count)

Fixed submission:
import collections

N = int(input())
s_list = ["".join(sorted(input())) for i in range(N)]
s_list = sorted(s_list)

count = 0

c = collections.Counter(s_list)

for item in c:
  for pair in range(c[item]):
    count += pair
        
print(count)

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

count = 0

for i in range(len(s_list)):
  for j in range(i+1, len(s_list)):
    if sorted(s_list[i]) == sorted(s_list[j]):
      count += 1
      
print(count)

Fixed submission:
import collections

N = int(input())
s_list = ["".join(sorted(input())) for i in range(N)]
s_list = sorted(s_list)

count = 0

c = collections.Counter(s_list)

for item in c:
  for pair in range(c[item]):
    count += pair
        
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


count = 0
tmp = 0
for i, a in enumerate(A_list[::-1]):
  
  if i < len(B_list):  
    if a <= B_list[::-1][i] + tmp:
      count += a
      # tmp = B_list[::-1][i] + tmp - a      
      if tmp > a:
        tmp = B_list[::-1][i]
      else:
        tmp = B_list[::-1][i] + tmp - a
      
    else:
      count += B_list[::-1][i] + tmp
      tmp = 0
      
    # print(count, tmp)
      
  elif i == len(B_list):
    if a <= tmp:
      count += a
    else:
      count += tmp
    
print(count)

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


A_list = A_list[::-1]
B_list = B_list[::-1]

count = 0
tmp = 0
for i, a in enumerate(A_list):
  
  if i < len(B_list):  
    if a <= B_list[i] + tmp:
      count += a
      if tmp > a:
        tmp = B_list[i]
      else:
        tmp = B_list[i] + tmp - a      
    else:
      count += B_list[i] + tmp
      tmp = 0            
  else:
    if a <= tmp:
      count += a
    else:
      count += tmp
    
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

a_list = [int(input()) for i in range(M)]

step_route = [0] * (N+1)

step_route[0] = 1
step_route[1] = 1

for j in range(N+1):  
  if j in a_list:
    step_route[j] = 0
    continue
  if j >= 2:
    step_route[j] = step_route[j-1] + step_route[j-2]
    if step_route[j] == 0:
      break
    
print(step_route[N] % 1000000007)

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

step_route = [-1] * (N+1)

step_route[0] = 1
step_route[1] = 1

for i in range(M):
    tmp = int(input())
    step_route[tmp] = 0

for j in range(2,N+1):  
    if step_route[j] == -1:
        step_route[j] = step_route[j-1] + step_route[j-2]
    
print(step_route[N] % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

a_list = [int(input()) for i in range(M)]

step_route = [0] * (N+1)

step_route[0] = 1
step_route[1] = 1

for j in range(N+1):  
  if j >= 2:
    step_route[j] = step_route[j-1] + step_route[j-2]
  if j in a_list:
    step_route[j] = 0
    
print(step_route[N] % 1000000007)

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

step_route = [-1] * (N+1)

step_route[0] = 1
step_route[1] = 1

for i in range(M):
    tmp = int(input())
    step_route[tmp] = 0

for j in range(2,N+1):  
    if step_route[j] == -1:
        step_route[j] = step_route[j-1] + step_route[j-2]
    
print(step_route[N] % 1000000007)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

result = 0

hasuu = [item % 10 for item in [A, B, C, D, E] if item % 10 != 0]

for item in [A, B, C, D, E]:
  if item % 10 == 0:
    result += item 
  else:
    result += (item // 10 + 1) * 10
    
result = int(result - 10 + min(hasuu))
print(result)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

result = 0

hasuu = [item % 10 for item in [A, B, C, D, E] if item % 10 != 0]

for item in [A, B, C, D, E]:
  if item % 10 == 0:
    result += item 
  else:
    result += (item // 10 + 1) * 10
    
if hasuu != []:
  result = int(result - 10 + min(hasuu))

print(result)

Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

hasuu = [item % 10 if item % 10 != 0 
         for item in [A, B, C, D, E]]

for item in [A, B, C, D, E]:
  if item % 10 == 0:
    result += item 
  else:
    result += (item // 10 + 1) * 10
    
result = int(result - 10 + min(hasuu))
print(result)
    

    

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

result = 0

hasuu = [item % 10 for item in [A, B, C, D, E] if item % 10 != 0]

for item in [A, B, C, D, E]:
  if item % 10 == 0:
    result += item 
  else:
    result += (item // 10 + 1) * 10
    
if hasuu != []:
  result = int(result - 10 + min(hasuu))

print(result)
Buggy python submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)

F_list = []
for i in range(1, X+1):
  if i > K:
    break
  for j in range(1, Y+1):
    if i*j > K:
      break
    for k in range(1, Z+1):
      if i*j*k > K:
        break
      F_list.append(A_list[i]+B_list[j]+C_list[k])

F_list.sort(reverse=True)

for i in range(K):
  print(F_list[i])

Fixed submission:
X, Y, Z, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)

F_list = []
for i in range(1, X+1):
  if i > K:
    break
  for j in range(1, Y+1):
    if i*j > K:
      break
    for k in range(1, Z+1):
      if i*j*k > K:
        break
      F_list.append(A_list[i-1]+B_list[j-1]+C_list[k-1])

F_list.sort(reverse=True)

for i in range(K):
  print(F_list[i])
Buggy python submission (verdict: Runtime Error):
S = input()

candidates = []

tmp = []

for char in S:
    if char in ["A", "T", "G", "C"]:
        tmp.append(char)
    else:
        candidates.append(tmp)
        tmp = []
        
sorted_candidates = sorted(candidates, reverse=True, key=lambda x: len(x))
print(len(sorted_candidates[0]))

Fixed submission:
S = input()

candidates = []

tmp = []

for char in S:
    if char in ["A", "T", "G", "C"]:
        tmp.append(char)
    else:
        candidates.append(tmp)
        tmp = []

if tmp != []:
    candidates.append(tmp)

sorted_candidates = sorted(candidates, reverse=True, key=lambda x: len(x))
print(len(sorted_candidates[0]))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
lr_list = [list(map(int, input().split())) for q in range(Q)]

# 1文字目から n 文字目までの AC の数 = 1文字目から n - 1 文字目までの、Cを右に持つ A の数

where_ac = [0] * N

for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        where_ac[i+1] += 1

for lr in lr_list:
    print(sum(where_ac[0:lr[1]]) - sum(where_ac[0:lr[0]]))

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

where_ac = [0] * N

for i in range(N-1):    
  if S[i] == 'A' and S[i+1] == 'C':
    where_ac[i+1] = where_ac[i] + 1
  else:
    where_ac[i+1] = where_ac[i]
        
for q in range(Q):
  l, r = map(int, input().split())
  print(where_ac[r-1] - where_ac[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
lr_list = [list(map(int, input().split())) for q in range(Q)]
 
# 1文字目から n 文字目までの AC の数 = 1文字目から n - 1 文字目までの、Cを右に持つ A の数
 
where_ac = [0] * N
 
for i in range(N-1):
	#    print(i)
    if S[i] == 'A' and S[i+1] == 'C':
        where_ac[i+1] += 1
 
count = [sum(where_ac[0:i+1]) for i in range(N)]
 
for lr in lr_list:
    print(count[lr[1]-1] - count[lr[0]-1])

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

where_ac = [0] * N

for i in range(N-1):    
  if S[i] == 'A' and S[i+1] == 'C':
    where_ac[i+1] = where_ac[i] + 1
  else:
    where_ac[i+1] = where_ac[i]
        
for q in range(Q):
  l, r = map(int, input().split())
  print(where_ac[r-1] - where_ac[l-1])
Buggy python submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
  if cur == N:
    return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF
  
  # 使わない場合
  ret0 = dfs(cur + 1, A, B, C)
  # A に使う場合
  ret1 = dfs(cur + 1, A + l[cur], B, C) + 10
  # B に使う場合
  ret2 = dfs(cur + 1, A, B + l[cur], C) + 10
  # C に使う場合
  ret3 = dfs(cur + 1, A, B, C + l[cur]) + 10
  
  return min(ret0, ret1, ret2, ret3)
  
print(defs(0, 0, 0, 0))

Fixed submission:
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
  if cur == N:
    return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF
  
  # 使わない場合
  ret0 = dfs(cur + 1, a, b, c)
  # A に使う場合
  ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
  # B に使う場合
  ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
  # C に使う場合
  ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  
  return min(ret0, ret1, ret2, ret3)
  
print(dfs(0, 0, 0, 0))
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input.split())

if B % A == 0:
  print(A+B)
else:
  print(B-A)

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

if B % A == 0:
  print(A+B)
else:
  print(B-A)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

for i in range(M//N, 0, -1):
  if M % i == 0:
    ans = i
    break
    
print(ans)

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

for i in range(M//N, 0, -1):
  if M % i == 0:
    ans = i
    break
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

for i in range(1, (M//N + 1)):
  if M % i == 0:
    ans = i
    
print(ans)

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

for i in range(M//N, 0, -1):
  if M % i == 0:
    ans = i
    break
    
print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())

ans = "AC"

if S[0] != "A":
  ans = "WA"
  
count = 0
for item in S[2:-2]:
  if item == "C":
    count += 1
    
if count != 1:
  ans = "WA"
  
S.remove("A")
S.remove("C")

if "".join(S).lower() != "".join(S):
  ans = "WA"

print(ans)

Fixed submission:
S = list(input())

ans = "AC"
tmp = S[2:-1]

if S[0] != "A":
  ans = "WA"
else:
  S.remove("A")
  
count = 0
for item in tmp:
  if item == "C":
    count += 1
    
if count != 1:
  ans = "WA"
elif count == 1:
  S.remove("C")


if "".join(S).lower() != "".join(S):
  ans = "WA"

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N <= 999:
  print(ABC)
else:
  print(ABD)

Fixed submission:
N = int(input())

if N <= 999:
  print("ABC")
else:
  print("ABD")
Buggy python submission (verdict: Time Limit Exceeded):
X, Y = map(int, input().split())

max_num = 10 ** 18
ans = -1

for i in range(X, max_num+1, X):
  if i % Y != 0:
    ans = i
    break
  
print(ans)

Fixed submission:
X, Y = map(int, input().split())

if X % Y == 0:
  print(-1)
else:
  print(X)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

nl = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    nl[L].append((R, D))
    nl[R].append((L, -D))

# print(nl)
    
seen = [None for _ in range(N + 1)]

def dfs(v, d):
    # print("dfs ", v, d)
    seen[v] = d
    for next_v, D in nl[v]:
        next_d = d + D
        if seen[next_v] is None:
            dfs(next_v, next_d)
        else:
            if seen[next_v] != next_d:
                print('No')
                exit(0)
                
for v in range(1, N + 1):  # すべての連結成分に対してDFS
    if seen[v] is None:
        dfs(v, 0)

print('Yes')

Fixed submission:
import sys
sys.setrecursionlimit(300000)

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

nl = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    nl[L].append((R, D))
    nl[R].append((L, -D))

# print(nl)
    
seen = [None for _ in range(N + 1)]

def dfs(v, d):
    # print("dfs ", v, d)
    seen[v] = d
    for next_v, D in nl[v]:
        next_d = d + D
        if seen[next_v] is None:
            dfs(next_v, next_d)
        else:
            if seen[next_v] != next_d:
                print('No')
                exit(0)
                
for v in range(1, N + 1):  # すべての連結成分に対してDFS
    if seen[v] is None:
        dfs(v, 0)

print('Yes')

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

nl = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    nl[L].append((R, D))
    nl[R].append((L, -D))

# print(nl)
    
seen = [None for _ in range(N + 1)]

def dfs(v, d):
    # print("dfs ", v, d)
    seen[v] = d
    for next_v, D in nl[v]:
        next_d = d + D
        if seen[next_v] is None:
            dfs(next_v, next_d)
        else:
            if seen[next_v] != next_d:
                print('No')
                exit(0)
                
for v in range(1, N + 1):  # すべての連結成分に対してDFS
    if seen[v] is None:
        dfs(v, 0)

print('Yes')

Fixed submission:
import sys
sys.setrecursionlimit(300000)

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

nl = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    nl[L].append((R, D))
    nl[R].append((L, -D))

# print(nl)
    
seen = [None for _ in range(N + 1)]

def dfs(v, d):
    # print("dfs ", v, d)
    seen[v] = d
    for next_v, D in nl[v]:
        next_d = d + D
        if seen[next_v] is None:
            dfs(next_v, next_d)
        else:
            if seen[next_v] != next_d:
                print('No')
                exit(0)
                
for v in range(1, N + 1):  # すべての連結成分に対してDFS
    if seen[v] is None:
        dfs(v, 0)

print('Yes')
Buggy python submission (verdict: Runtime Error):
S = input()
S[3] = 8
print(S)

Fixed submission:
S = input()
S = "2018/01/" + S.split("2017/01/")[-1]
print(S)
Buggy python submission (verdict: Runtime Error):
N, H = map(int, input().split())
a_list = []
b_list = []
for _ in range(N):
  a, b = map(int, input().split())
  a_list.append(a)
  b_list.append(b)
  
b_list = sorted(b_list)

count = 0
a_max = max(a_list)

while H > 0:
  b = b_list.pop()
  if b > a_max:
    H -= b
    count += 1
  else:
    break
    
if H > 0:
  if H % a_max == 0:
    count += H // a_max
  else:
    count += H // a_max + 1
    
print(count)



Fixed submission:
N, H = map(int, input().split())
a_list = []
b_list = []
for _ in range(N):
  a, b = map(int, input().split())
  a_list.append(a)
  b_list.append(b)
  
b_list = sorted(b_list)

count = 0
a_max = max(a_list)

while H > 0 and b_list:
  b = b_list.pop()
  if b > a_max:
    H -= b
    count += 1
  else:
    break
    
if H > 0:
  if H % a_max == 0:
    count += H // a_max
  else:
    count += H // a_max + 1
    
print(count)
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().aplit())

l = A + B
r = C + D

if l > r:
  print("Left")
elif l == r:
  print("Balanced")
elif l < r:
  print("Right")

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

l = A + B
r = C + D

if l > r:
  print("Left")
elif l == r:
  print("Balanced")
elif l < r:
  print("Right")
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())

count = 0

for i in range(1, N+1):
  tmp = sum(list(str(i)))
  if A <= tmp <= B:
    count += 1
    
print(count)

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

count = 0

for i in range(1, N+1):
  str_i = str(i)
  tmp = 0
  for j in range(len(str_i)):
    tmp += int(str_i[j])
  if A <= tmp <= B:
    count += i
    
print(count)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

ans = 0
count = [0] * (10 ** 5)

for i in range(N):
  count[a[i]] += 1
  ans += 1
  if count[a[i]] == a[i]:
    ans -= a[i]

print(ans)


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

ans = 0
count = [0] * (10 ** 5 + 1)

for i in range(N):
  if a[i] <= 10 ** 5:
    count[a[i]] += 1
    ans += 1
    if count[a[i]] == a[i]:
      ans -= a[i]
  else:
    ans += 1

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

len_S = len(S_dash)
len_T = len(T)

answer = "UNRESTORABLE"
candidate = []

# まず T と一致させられる位置があるかを調べる
for i in range(len_S - len_T + 1):
  # print(S_dash[i:i+len_T])
  tmp = S_dash[i:i+len_T]
  
  count = 0
  for s, t in zip(tmp, T):
    if s == t or s == '?':
      count += 1
  if count == len_T:
    candidate.append(S_dash[:i] + T + S_dash[i+len_T:])
    
replaced_candidate = [item.replace("?", "a") for item in candidate]
replaced_candidate.sort()
print(replaced_candidate[0])

Fixed submission:
S_dash = input()
T = input()

len_S = len(S_dash)
len_T = len(T)

candidate = []

# まず T と一致させられる位置があるかを調べる
for i in range(len_S - len_T + 1):
  # print(S_dash[i:i+len_T])
  tmp = S_dash[i:i+len_T]
  
  count = 0
  for s, t in zip(tmp, T):
    if s == t or s == '?':
      count += 1
  if count == len_T:
    candidate.append(S_dash[:i] + T + S_dash[i+len_T:])
    
if candidate != []:       
  replaced_candidate = [item.replace("?", "a") for item in candidate]
  replaced_candidate.sort()
  print(replaced_candidate[0])
else:
  print("UNRESTORABLE")
Buggy python submission (verdict: Runtime Error):
s = input()
num_x = s.count('x')
s_remove_x = s.replace('x', '', num_x)

if len(s) % 2 == 1:
  if s[(len(s) + 1) // 2] == 'x':
    ans = num_x - 1
else:
  ans = num_x

# s から x を除いたものが回文になっているか判定
half_len = len(s_remove_x) // 2
for i in range(half_len):
  if s_remove_x[i] != s_remove_x[len(s_remove_x)-1-i]:
    ans = -1

print(ans)


Fixed submission:
S = input()
cnt = 0
l = 0
r = len(S)-1
while(l<r):
    if(S[l]==S[r]):
        l+=1
        r-=1
    elif(S[l]=='x'):
        cnt += 1
        l+=1
    elif(S[r]=='x'):
        cnt += 1
        r-=1
    else:
        print(-1)
        break
else:
    print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = sorted([list(map(int, input().split())) for _ in range(M)])

ans = "IMPOSSIBLE"
second_island = []

for a, b in ab_list:
  if a == 1:
    second_island.append(b)

  if b == N:
    if a in second_island:
      ans = "POSSIBLE"
      break

print(ans)

Fixed submission:
n, m = map(int, input().split())
sa = set()
sb = set()
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        sb.add(b)
    if b == n:
        sa.add(a)

print('POSSIBLE' if len(sa&sb) != 0 else 'IMPOSSIBLE')

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ab_list = sorted([list(map(int, input().split())) for _ in range(M)])

ans = "IMPOSSIBLE"
second_island = []

for a, b in ab_list:
  if a == 1:
    second_island.append(b)

  if b == N:
	if a in second_island:
      ans = "POSSIBLE"
      break

print(ans)

Fixed submission:
n, m = map(int, input().split())
sa = set()
sb = set()
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        sb.add(b)
    if b == n:
        sa.add(a)

print('POSSIBLE' if len(sa&sb) != 0 else 'IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = sorted([list(map(int, input().split())) for _ in range(M)])

ans = "IMPOSSIBLE"
second_island = []

for a, b in ab_list:
  if a == 1:
    second_island.append(b)
    
  if a in second_island:
    if b == N:
      ans = "POSSIBLE"
      break

print(ans)

Fixed submission:
n, m = map(int, input().split())
sa = set()
sb = set()
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        sb.add(b)
    if b == n:
        sa.add(a)

print('POSSIBLE' if len(sa&sb) != 0 else 'IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = sorted([list(map(int, input().split())) for _ in range(M)])

ans = "IMPOSSIBLE"
second_island = []

for a, b in ab_list:
  if a == 1:
    second_island.append(b)
  
  if a in second_island:
    if b == N:
      ans = "POSSIBLE"

print(ans)

Fixed submission:
n, m = map(int, input().split())
sa = set()
sb = set()
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        sb.add(b)
    if b == n:
        sa.add(a)

print('POSSIBLE' if len(sa&sb) != 0 else 'IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = sorted([list(map(int, input().split())) for _ in range(M)])

ans = "IMPOSSIBLE"
second_island = []

for a, b in ab_list:
  if a == 1:
    second_island.append(b)
  
  if a in second_island:
    if b == N:
      ans = "POSSIBLE"

print(ans)

Fixed submission:
n, m = map(int, input().split())
sa = set()
sb = set()
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        sb.add(b)
    if b == n:
        sa.add(a)

print('POSSIBLE' if len(sa&sb) != 0 else 'IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
ab_list = sorted([map(int, input().split()) for _ in range(N)])

for a, b in ab_list:
  if b >= K:
    print(a)
    exit()
  else:
    K -= b


Fixed submission:
N, K = map(int, input().split())
ab_list = sorted([list(map(int, input().split())) for _ in range(N)])

for a, b in ab_list:
  if b >= K:
    print(a)
    exit()
  else:
    K -= b
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

max_num = 10 ** 9 + 7

power = 1
for i in range(1, N+1):
  power *= i
  
print(power % max_num)



Fixed submission:
N = int(input())

max_num = 10 ** 9 + 7

power = 1
for i in range(1, N+1):
  power = (power * i) % max_num
  
print(power)