Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
bd = [[.]+list(input().split())+[.] for i in range(h)]
bd.insert(0,[.]*(w+1))
bd.append([.]*(w+1))
for i in range(h):
  for j in range(w):
    if bd[i][j] == "#":
      if i == h and j == w:
        print("Possible")
        break
      if bd[i+1][j] == bd[i+1][j]:
        print("Impossible")
        break
      if bd[i-1][j] == "#" or bd[i][j-1] == "#":
        print("Impossible")
        break
      bd[i][j]="."

Fixed submission:
h,w=map(int,input().split())
bd = [list("."+input()+".") for i in range(h)]
bd.insert(0,["."]*(w+2))
bd.append(["."]*(w+2))
stack=[(1,1)]
while(stack):
  i,j=stack.pop()
  if i == h and j == w:
    bd[i][j]="."
    break
  if bd[i+1][j] == bd[i][j+1]:
    print("Impossible")
    exit()
  if bd[i-1][j] == "#" or bd[i][j-1] == "#":
    print("Impossible")
    exit()
  if bd[i+1][j] == "#":
    stack.append((i+1,j))
  if bd[i][j+1] == "#":
    stack.append((i,j+1))
  bd[i][j] = "."
if bd == [["." for i in range(w+2)] for j in range(h+2)]:
  print("Possible")
else:
  print("Impossible")
Buggy python submission (verdict: Time Limit Exceeded):
n,t=map(int,input().split())
a=list(map(int,input().split()))
lmin=[a[0]]
rmax=[a[-1]]
for i in range(1,n):
  if a[i]<=lmin[-1]:
    lmin.append(a[i])
  else:
    lmin.append(lmin[-1])
  if a[-i-1]>=rmax[-1]:
    rmax.append(a[-i-1])
  else:
    rmax.append(rmax[-1])
mxls=[rmax[-i-2]-lmin[i] for i in range(n-1)]
mxls.append(-10**18)
ans=0
for i in range(n-1):
  if mxls[i]==max(mxls) and mxls[i]!=mxls[i+1]:
    ans+=1
print(ans)

Fixed submission:
n,t=map(int,input().split())
a=list(map(int,input().split()))
lmin=[a[0]]
rmax=[a[-1]]
for i in range(1,n):
  if a[i]<=lmin[-1]:
    lmin.append(a[i])
  else:
    lmin.append(lmin[-1])
  if a[-i-1]>=rmax[-1]:
    rmax.append(a[-i-1])
  else:
    rmax.append(rmax[-1])
mxls=[rmax[-i-2]-lmin[i] for i in range(n-1)]
mxls.append(-10**18)
ans=0
mx=max(mxls)
for i in range(n-1):
  if mxls[i]==mx and mxls[i]!=mxls[i+1]:
    ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,t=map(int,input().split())
a=list(map(int,input().split()))
lmin=[a[0]]
rmax=[a[-1]]
for i in range(1,n):
  if a[i]<=lmin[-1]:
    lmin.append(a[i])
  else:
    lmin.append(lmin[-1])
  if a[-i-1]>=rmax[-1]:
    rmax.append(a[-i-1])
  else:
    rmax.append(rmax[-1])
mxls=[rmax[-i-2]-lmin[i] for i in range(n-1)]
mxls.append(-10**18)
ans=0
for i in range(n-1):
  if mxls[i]==max(mxls) and mxls[i]!=mxls[i+1]:
    ans+=1
print(ans)

Fixed submission:
n,t=map(int,input().split())
a=list(map(int,input().split()))
lmin=[a[0]]
rmax=[a[-1]]
for i in range(1,n):
  if a[i]<=lmin[-1]:
    lmin.append(a[i])
  else:
    lmin.append(lmin[-1])
  if a[-i-1]>=rmax[-1]:
    rmax.append(a[-i-1])
  else:
    rmax.append(rmax[-1])
mxls=[rmax[-i-2]-lmin[i] for i in range(n-1)]
mxls.append(-10**18)
ans=0
mx=max(mxls)
for i in range(n-1):
  if mxls[i]==mx and mxls[i]!=mxls[i+1]:
    ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
a=list(map(int,input().split()))
b=[[a[i],i] for i in range(n)]
b.sort(reverse=True)
lmin=[a[0]]
rmax=[max(a[1:])]
mxls=[rmax[0]-lmin[0]]
mx=0
mn=n-1
for i in range(1,n):
  if a[i]<=b[mn]:
    mn-=1
  if a[i]>=b[mx]:
    mx+=1
  lmin.append(b[mn])
  rmax.append(b[mx])
  mxls.append(b[mx]-b[mn])
print(mxls.count(max(mxls)))
  

Fixed submission:
n,t=map(int,input().split())
a=list(map(int,input().split()))
lmin=[a[0]]
rmax=[a[-1]]
for i in range(1,n):
  if a[i]<=lmin[-1]:
    lmin.append(a[i])
  else:
    lmin.append(lmin[-1])
  if a[-i-1]>=rmax[-1]:
    rmax.append(a[-i-1])
  else:
    rmax.append(rmax[-1])
mxls=[rmax[-i-2]-lmin[i] for i in range(n-1)]
mxls.append(-10**18)
ans=0
mx=max(mxls)
for i in range(n-1):
  if mxls[i]==mx and mxls[i]!=mxls[i+1]:
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
if n==2:
  if x==2:
    print("Yes",1,2,3,sep="\n")
    exit()
  else:
    print("No")
    exit()
if x==1 or x==n*2-1:
  print("No")
  exit()
ans=[i for i in range(1,2n)]
for i in range(len(ans)):
  ans[i]=(ans[i]-(n-x+1))%(2*n-1)+1
print("Yes",ans,sep="\n")

Fixed submission:
n,x=map(int,input().split())
if n==2:
  if x==2:
    print("Yes",1,2,3,sep="\n")
    exit()
  else:
    print("No")
    exit()
if x==1 or x==n*2-1:
  print("No")
  exit()
ans=[i for i in range(1,2*n)]
for i in range(len(ans)):
  ans[i]=(ans[i]-(n-x+1))%(2*n-1)+1
print("Yes",*ans,sep="\n")
Buggy python submission (verdict: Runtime Error):
s=input()
t = 1000
u = 1000
for i in range(n):
  if s[i] == "C":
    t = i
    break
for i in range(n-1,-1,-1):
  if s[i] == "F":
    u = i
    break
if max(t,u) != 1000 and t<u:
  print("Yes")
else:
  print("No")

Fixed submission:
s=input()
n=len(s)
t = 1000
u = 1000
for i in range(n):
  if s[i] == "C":
    t = i
    break
for i in range(n-1,-1,-1):
  if s[i] == "F":
    u = i
    break
if max(t,u) != 1000 and t<u:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
s=input()
t,u = 1000
for i in range(n):
  if s[i] == "C":
    t = i
    break
for i in range(n-1,-1,-1):
  if s[i] == "F":
    u = i
    break
if max(t,u) != 1000 and t<u:
  print("Yes")
else:
  print("No")

Fixed submission:
s=input()
n=len(s)
t = 1000
u = 1000
for i in range(n):
  if s[i] == "C":
    t = i
    break
for i in range(n-1,-1,-1):
  if s[i] == "F":
    u = i
    break
if max(t,u) != 1000 and t<u:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
print)(len(set(list(map(int,input().split()))))

Fixed submission:
print(len(set(list(map(int,input().split())))))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
cnt = 1
ans = 0
for i in range(n):
  if a[i] = cnt+1:
    cnt += 1
  else:
    ans += (a[i]-1)//cnt
    if cnt == 1:
      cnt += 1
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
cnt = 2
ans = a[0]-1
for i in range(1,n):
  if a[i] == cnt:
    cnt += 1
  else:
    ans += (a[i]-1)//cnt
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  j = a[i]
  if a[j] == i:
    ans+=1
print(ans//2)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  j = a[i]-1
  if a[j] == i+1:
    ans+=1
print(ans//2)
Buggy python submission (verdict: Runtime Error):
s=input()
n=int(input())
ans=""
for i in range(n-1):
  x=ord(a[i])-97
  if n>=123-x:
    ans += "a"
    n -= 123-x
  else:
    ans += a[i]
ans += chr((ord(a[i])-97+n)%26+97)
print(ans)

Fixed submission:
a=input()
n=len(a)
m=int(input())
ans=""
for i in range(n-1):
  if a[i]=="a":
    ans += "a"
    continue
  x=ord(a[i])-97
  if m>=26-x:
    ans += "a"
    m -= 26-x
  else:
    ans += a[i]
ans += chr((ord(a[n-1])-97+m)%26+97)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,h=map(int,input().split())
print((a+b)*h//2)

Fixed submission:
a= int(input())
b= int(input())
h=int(input())
print((a+b)*h//2)
Buggy python submission (verdict: Runtime Error):
from collections import deque
A=deque(list(input()+"A"))
B=deque(list(input()+"B"))
C=deque(list(input()+"C"))
x=A.pop()
while(True):
  if x == "a":
    x = A.pop()
  elif x == "b":
    x = B.pop()
  elif x == "c:
    x = C.pop()
  elif x == "A":
    x = a
    break
  elif x == "B":
    x = b
    break
  elif x == "C":
    x = c
    break
print(x)
    
    

Fixed submission:
from collections import deque
A=deque(list(input()+"A"))
B=deque(list(input()+"B"))
C=deque(list(input()+"C"))
x=A.popleft()
while(True):
  if x == "a":
    x = A.popleft()
  elif x == "b":
    x = B.popleft()
  elif x == "c":
    x = C.popleft()
  else:
    break
print(x)
Buggy python submission (verdict: Runtime Error):
n,s=int(input())
if n*2<=s+1:
  print(s-n+1)
else:
  print(-1)

Fixed submission:
n = int(input())
s = int(input())
x = int(n**0.5)+1
def dsum(x,t):
  ret = 0
  while x>0:
    ret += x%t
    x //= t
  return ret
for i in range(2,x+1):
  if dsum(n,i) == s:
    print(i)
    exit()
for i in range(x,0,-1):
  if (n-(s-i))%i == 0:
    digit = (n-(s-i))//i
    if 0 < i < digit and 0 <= s-i < digit:
      print((n-(s-i))//i)
      exit()
if n == s:
  print(n+1)
  exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a = [int(input()) for i in range(n)]
a.append(0)
ans = 0
for i in range(n+1):
  if a[i]!=0:
    tmp += a[i]
  else:
    ans += tmp//2
    tmp = 0
print(ans)

Fixed submission:
n=int(input())
a = [int(input()) for i in range(n)]
a.append(0)
ans = 0
tmp = 0
for i in range(n+1):
  if a[i]!=0:
    tmp += a[i]
  else:
    ans += tmp//2
    tmp = 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
input = sys.stdin.readline
nmax = 10**5+10
eratos = [0 for i in range(nmax+1)]
prime = []
cnt = 2
while True:
  while cnt <= nmax and eratos[cnt]:
    cnt += 1
  if cnt > nmax:
    break
  eratos[cnt] = 1
  prime.append(cnt)
  for i in range(cnt**2,nmax+1,cnt):
    eratos[i] = 1
cbls = []
sqst = set()
for i in prime:
  if i**3 <= 10**10:
    cbls.append(i**3)
  else:
    sqst.add(i**2)
n = int(input())
a = [int(input()) for i in range(n)]
dc = defaultdict(int)
for i in a:
  for p in cbls:
    while i%p == 0:
      i //= p
  dc[i] += 1
ans = n
for i,v in dc.items():
  if i == 1:
    ans -= v-1
    continue
  if v == 0:
    continue
  if i in sqst:
    x = int(i**0.5+0.5)
  else:
    x = 1
    for p in prime:
      if i%(p*p) == 0:
        x *= p
        i //= p*p
      elif i%p == 0:
        x *= p**2
        i //= p
    if x == 1:
      continue
  if x in dc:
    ans -= min(dc[x],v)
    dc[x] = 0
print(ans)

Fixed submission:
from collections import defaultdict
import sys
input = sys.stdin.readline
nmax = 10**5+10
eratos = [0 for i in range(nmax+1)]
prime = []
cnt = 2
while True:
  while cnt <= nmax and eratos[cnt]:
    cnt += 1
  if cnt > nmax:
    break
  eratos[cnt] = 1
  prime.append(cnt)
  for i in range(cnt**2,nmax+1,cnt):
    eratos[i] = 1
cbls = []
sqst = set()
for i in prime:
  if i**3 <= 10**10:
    cbls.append(i**3)
  else:
    sqst.add(i**2)
n = int(input())
a = [int(input()) for i in range(n)]
dc = defaultdict(int)
for i in a:
  for p in cbls:
    while i%p == 0:
      i //= p
  dc[i] += 1
ans = n
for i,v in dc.items():
  if i == 1:
    ans -= v-1
    continue
  if v == 0:
    continue
  x = 1
  for p in prime:
    if p**3 > 10**10:
      break
    if i%(p*p) == 0:
      x *= p
      i //= p*p
    elif i%p == 0:
      x *= p**2
      i //= p
  if i in sqst:
    x *= int(i**0.5+0.5)
    i //= i
  if i != 1:
    continue
  if x in dc:
    ans -= min(dc[x],v)
    dc[x] = 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,c = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ab = list(zip(a,b))
dp = [[0 for i in range(c+1)] for j in range(n+1)]
mod = 10**9+7
for i in range(c+1):
  dp[0][i] = 1
for i in range(1,n+1):
  a,b = ab[i-1]
  for j in range(a,b+1):
    for k in range(c+1):
      dp[i][k] = (dp[i][k]+pow(j,k,mod))%mod
ans = [[0 for i in range(c+1)] for j in range(n+1)]
ans[0][0] = 1
for i in range(1,n+1):
  for j in range(c+1):
    for k in range(j+1):
      ans[i][j] += dp[i][k]*ans[i-1][j-k]
    ans[i][j] %= mod
print(ans[n][c])

Fixed submission:
n,c = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ab = list(zip(a,b))
table = [[0 for i in range(c+1)] for j in range(401)]
mod = 10**9+7
for j in range(c+1):
  if j == 0:
    for i in range(401):
      table[i][j] = 1
  else:
    for i in range(401):
      table[i][j] = table[i][j-1]*i%mod
dp = [[0 for i in range(c+1)] for j in range(n+1)]
for i in range(c+1):
  dp[0][i] = 1
for i in range(1,n+1):
  a,b = ab[i-1]
  for j in range(a,b+1):
    for k in range(c+1):
      dp[i][k] = (dp[i][k]+table[j][k])%mod
ans = [[0 for i in range(c+1)] for j in range(n+1)]
ans[0][0] = 1
for i in range(1,n+1):
  for j in range(c+1):
    for k in range(j+1):
      ans[i][j] = (ans[i][j]+dp[i][k]*ans[i-1][j-k])%mod
print(ans[n][c])
Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(len(s)-2):
  if len(set(s[i],s[i+1],s[i+2]))!=3:
    print(i+1,i+3)
    break
else:
  print("-1 -1")


Fixed submission:
s=input()
if len(s)==2:
  if s[0]==s[1]:
    print(1,2)
  else:
    print(-1,-1)
else:
  for i in range(len(s)-2):
    if len(set((s[i],s[i+1],s[i+2])))!=3:
      print(i+1,i+3)
      break
  else:
    print("-1 -1")
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split(' '))
X = []
for i in range(N):
    X.append(list(map(int, input().split(' '))))

num_b = [i+1 for i in range(N)]
psb = [0]*N
psb[0] = 1

for i in X:
    num_b[i[0]] -= 1
    num_b[i[1]] += 1
    if num_b[i[0]] == 0:
        psb[i[0]] = 0
    if psb[i[0]] == 1:
        psb[i[1]] == 1 

print(psb.count(1))


Fixed submission:
N, M = map(int, input().split(' '))
X = []
for i in range(M):
    X.append(list(map(int, input().split(' '))))

num_b = [1 for i in range(N+1)]
num_b[0] = 0
psb = [0]*(N+1)
psb[1] = 1
for i in range(M):
    num_b[X[i][0]] -= 1
    num_b[X[i][1]] += 1
    if psb[X[i][0]] == 1:
        psb[X[i][1]] = 1 
    if num_b[X[i][0]] == 0:
        psb[X[i][0]] = 0

print(psb.count(1))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split(' '))
X = []
for i in range(N):
    X.append(list(map(int, input().split(' '))))

num_b = [i+1 for i in range(N)]
psb = [0]*N
psb[0] = 1

for i in X:
    num_b[[i][0]] -= 1
    num_b[[i][1]] += 1
    if num_b[[i][0]] == 0:
        psb[[i][0]] = 0
    if psb[[i][0]] == 1:
        psb[[i][1]] == 1 

print(psb.count(1))

Fixed submission:
N, M = map(int, input().split(' '))
X = []
for i in range(M):
    X.append(list(map(int, input().split(' '))))

num_b = [1 for i in range(N+1)]
num_b[0] = 0
psb = [0]*(N+1)
psb[1] = 1
for i in range(M):
    num_b[X[i][0]] -= 1
    num_b[X[i][1]] += 1
    if psb[X[i][0]] == 1:
        psb[X[i][1]] = 1 
    if num_b[X[i][0]] == 0:
        psb[X[i][0]] = 0

print(psb.count(1))
Buggy python submission (verdict: Runtime Error):
print('a' if s.islower() else 'A')

Fixed submission:
s=input()
print('a' if s.islower() else 'A')
Buggy python submission (verdict: Runtime Error):
n=int(input())-1
j=26
while j<=n:
  n-=j
  j*=26
j/=26
ret = ""
while j:
  ret += "abcdefghijklmnopqrstuvwxyz"[n//j]
  n %= j
  j /= 26
print(ret)


Fixed submission:
n=int(input())-1
j=26
while j<=n:
  n-=j
  j*=26
j//=26
ret = ""
while j:
  ret += "abcdefghijklmnopqrstuvwxyz"[n//j]
  #print(f'{n//j=}')
  n %= j
  j //= 26
print(ret)
Buggy python submission (verdict: Runtime Error):
n = int(input())
m = {}
tot = 0
for a in map(int,input().split()):
  tot += m
  if a not in m:
    m[a]=0
  m[a] += 1
q = int(input())
for step in range(q):
  b,c = map(int,input().split())
  if c not in m:
    m[c] = 0
  if b in m:
    m[c] += m[b]
    tot += m[b]*(c-b)
    m[b] = 0
  print(tot)



Fixed submission:
n = int(input())
m = {}
tot = 0
for a in map(int,input().split()):
  tot += a
  if a not in m:
    m[a]=0
  m[a] += 1
q = int(input())
for step in range(q):
  b,c = map(int,input().split())
  if c not in m:
    m[c] = 0
  if b in m:
    m[c] += m[b]
    tot += m[b]*(c-b)
    m[b] = 0
  print(tot)
Buggy python submission (verdict: Runtime Error):
h,w = map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in range(h)]
ret = []
for y in range(h):
    for x in range(w-1):
        if a[y][x]%2==1:
            ret.append((y,x,y,x+1))
            a[y][x+1]+=1
for y in range(h-1):
    if a[y][-1]==1:
        ret.append((y,w-1,y+1,w-1))
        a[y+1][-1]+=1
print len(seq)
for seq in ret:
    a,b,c,d = seq
    print a+1,b+1,c+1,d+1

Fixed submission:
h,w = map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in range(h)]
ret = []
for y in range(h):
    for x in range(w-1):
        if a[y][x]%2==1:
            ret.append((y,x,y,x+1))
            a[y][x+1]+=1
for y in range(h-1):
    if a[y][-1]%2==1:
        ret.append((y,w-1,y+1,w-1))
        a[y+1][-1]+=1
print len(ret)
for seq in ret:
    a,b,c,d = seq
    print a+1,b+1,c+1,d+1
Buggy python submission (verdict: Runtime Error):
n=input()
print len(0 for k in range(1,n+1,2) if sum(1 for v in range(1,k+1) if k%v==0)==8)

Fixed submission:
n=input()
print sum(1 for k in range(1,n+1,2) if sum(1 for v in range(1,k+1) if k%v==0)==8)
Buggy python submission (verdict: Runtime Error):
n,m,q=map(int,raw_input().split())
lrs=[map(int,raw_input().split()) for _ in range(m)]
a=[[0 for j in range(n)] for i in range(n)]
for l,r in lrs:a[l-1][r-1]+=1
cnt=[[0 for j in range(n)] for i in range(n)]
for y in range(n):
 v = 0
 for x in range(y+1):
  v+=a[x][y]
  cnt[x][y]=cnt[x][y-1]+v
for _ in range(q):
 l,r=map(int,raw_input().split())
 print cnt[l][r] 

Fixed submission:
n,m,q=map(int,raw_input().split())
lrs=[map(int,raw_input().split()) for _ in range(m)]
a=[[0 for j in range(n)] for i in range(n)]
for l,r in lrs:a[l-1][r-1]+=1
cnt=[[0 for j in range(n)] for i in range(n)]
for y in range(n):
 v = 0
 for x in range(y,-1,-1):
  v+=a[x][y]
  cnt[x][y]=cnt[x][y-1]+v
for _ in range(q):
 l,r=map(int,raw_input().split())
 print cnt[l-1][r-1]
Buggy python submission (verdict: Runtime Error):
n,m=map(int,raw_input().split())
a=map(int,raw_input().split())
b=[0]
for v in a:b.append((b[-1]+v)%m)
ret = 0
z = {}
for c in v:
 if c not in z:z[c]=1
 else:
  ret+=z[c]
  z[c]+=1
print ret


Fixed submission:
n,m=map(int,raw_input().split())
a=map(int,raw_input().split())
b=[0]
for v in a:b.append((b[-1]+v)%m)
ret = 0
z = {}
for c in b:
 if c not in z:z[c]=1
 else:
  ret+=z[c]
  z[c]+=1
print ret
Buggy python submission (verdict: Runtime Error):
R=input()
if R<1200:print "ABC"
elif E<2800:print "ARC"
else:print "AGC"
  

Fixed submission:
R=input()
if R<1200:print "ABC"
elif R<2800:print "ARC"
else:print "AGC"
Buggy python submission (verdict: Runtime Error):
s=input()
if s[0]=="A" and s.count("C")==1 and s[-1]!="C" and s[1]!="C" and all(x not in s for x  in"ABDEFGHIJKLMNOPQRSTUVWXYZ"):print "AC"
else:print "WA"

Fixed submission:
s=raw_input()
if s[0]=="A" and len(s)>=3 and s.count("C")==1 and s[-1]!="C" and s[1]!="C" and all(x not in s[1:] for x  in"ABDEFGHIJKLMNOPQRSTUVWXYZ"):print "AC"
else:print "WA"
Buggy python submission (verdict: Runtime Error):
n = raw_input()
m = int(raw_input())
ps = [map(int, raw_input().split()) for _ in range(m)]
ps.sort()
ps.reverse()
v = -1
ret = 0
for a,b in ps:
 if b <=va:
  ret += 1
  va = a
print ret


Fixed submission:
n,m = map(int, raw_input().split())
ps = [map(int, raw_input().split()) for _ in range(m)]
ps.sort()
ps.reverse()
v = 10**100
ret = 0
for a,b in ps:
 if b <=v:
  ret += 1
  v = a
print ret
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(m):
    a[n-1] = a[n-1] // 2
    a.sort()
print(sum(a))

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    for i in range(m):
        a[0] = a[0] // 2
    print(sum(a))
    exit()

a.sort()
i = 0
while i < m:
    a[n-1] = a[n-1] // 2
    i+=1
    num = len([1 for x in a[:n-1] if x > a[n-1]])
    hoge = min(m-i, num)
    for j in range(hoge):
        a[n-2-j] = a[n-2-j] // 2
    i += hoge
    a.sort()

print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    a[a.index(max(a))] = max(a) // 2
print(sum(a))

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    for i in range(m):
        a[0] = a[0] // 2
    print(sum(a))
    exit()

a.sort()
i = 0
while i < m:
    a[n-1] = a[n-1] // 2
    i+=1
    num = len([1 for x in a[:n-1] if x > a[n-1]])
    hoge = min(m-i, num)
    for j in range(hoge):
        a[n-2-j] = a[n-2-j] // 2
    i += hoge
    a.sort()

print(sum(a))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input.split())
ans = int((b-1)/(a-1))+1
print(ans)


Fixed submission:
a, b = map(int, input().split())
if b == 1:
  print(0)
  exit()
for i in range(1,21):
  if (a-1)*i+1 >= b:
    print(i)
    exit()
print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
tmp_max = 0
for i in range(0,n-1):
  tmp = 0
  for j in range(i, n-1):
    if h[j+1] <= h[j]:
      tmp += 1
  if tmp > tmp_max:
    tmp_max = tmp
print(tmp)


Fixed submission:
n = int(input())
h = list(map(int, input().split()))
maxl = [0]*n

for i in range(n-2,-1,-1):
  if h[i] >= h[i+1]:
    maxl[i] = maxl[i+1]+1
  else:
    maxl[i] = 0
  
tmp_max = max(maxl)
print(tmp_max)
Buggy python submission (verdict: Runtime Error):
m, d = map(int, input().split())
ans = 0

for mon in m:
  for day in d:
    d1 = day%10
    d10 = int(day/10)
    if d1 >= 2 and d10 >= 2:
      if d1*d10 == mon:
        ans+=1
print(ans)

Fixed submission:
m, d = map(int, input().split())
ans = 0

for mon in range(1,m+1):
  for day in range(1, d+1):
    d1 = day%10
    d10 = int(day/10)
    if d1 >= 2 and d10 >= 2:
      if d1*d10 == mon:
        ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
for i in range(n):
  s.append(sorted(list(input().strip())))
ans = 0
for i in range(0,n-1):
  for j in range(i+1, n):
    if s[i] == s[j]:
      ans += 1
print(ans)

Fixed submission:
n = int(input())
s = []
for i in range(n):
  s.append(''.join(sorted(list(input().strip()))))
ans = 0
tmp = 0
ss = sorted(s)
prev = ''
for iss in ss:
  if prev != iss:
    prev = iss
    ans += int((tmp*(tmp+1))/2)
    tmp = 0
  elif prev == iss:
    # print("prev :{}, iss :{}".format(prev, iss))
    tmp += 1
if tmp != 0:
  ans += int((tmp*(tmp+1))/2)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, d = map(int, input().split())
if n%(2*d+1) == 0:
  print(n/(2*d+1))
else:
  print((n/(2*d+1)+1)

Fixed submission:
n, d = map(int, input().split())
if n%(2*d+1) == 0:
  print(int(n/(2*d+1)))
else:
  print(int((n/(2*d+1)))+1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
max_list = a.index(max(a))
max_a = max(a)
if len(max_list) == 1:
  sec_max = sorted(a)[1]
else:
  sec_max = max_a

for i in range(n):
  if i in max_list:
    print(sec_max)
  else:
    print(max_a)

Fixed submission:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
max_a = max(a)
if a.count(max(a)) == 1:
  sec_max = sorted(a)[-2]
else:
  sec_max = max_a

for i in range(n):
  if a[i] == max_a:
    print(sec_max)
  else:
    print(max_a)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
for i in range(n):
  tmp = a[:i]+a[i+1:]
  print(max(tmp))

Fixed submission:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
max_a = max(a)
if a.count(max(a)) == 1:
  sec_max = sorted(a)[-2]
else:
  sec_max = max_a

for i in range(n):
  if a[i] == max_a:
    print(sec_max)
  else:
    print(max_a)
Buggy python submission (verdict: Runtime Error):
a, b, c = int(input().split())
print(min(a*b,c))

Fixed submission:
n, b, c = map(int, input().split())
print(min(n*b, c))
Buggy python submission (verdict: Runtime Error):
import math
n, d = map(int, input().split())
x = [[0 for i in range(d)] for j in range(n)]
for i in range(n):
  x[i] = map(int, input().split())
 
result = 0
for i in range(n):
  for j in range(1,n):
    diff = map(lambda x: x*x, x[i]-x[j])
    calc = math.sqrt(sum(diff))
    if calc.is_integer():
      result +=1
print(result)


Fixed submission:
import math
n, d = map(int, input().split())
x = [[0 for i in range(d)] for j in range(n)]
for i in range(n):
  x[i] = list(map(int, input().split()))
result = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    diff = list(map(lambda x,y: pow(x-y,2), x[i], x[j]))
    calc = math.sqrt(sum(diff))
    if calc.is_integer():
      result +=1
print(result)