ZhenlongDai/ACPR huggingface dataset:
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
al = "abcdefghijklmnopqrstuvwxyz"
s = input()
if len(s)<26:
  for i in al:
    if i not in s:
      print(s+i)
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    k = []
    for i in range(25, 0, -1):
      if s[i-1] < s[i]:
        for j in sorted(k):
          if j > s[i-1]:
            print(s[:i-1] + j)
            exit()
      k.append(s[i])

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
z


Fixed submission (verdict: Accepted):
al = "abcdefghijklmnopqrstuvwxyz"
s = input()
if len(s)<26:
  for i in al:
    if i not in s:
      print(s+i)
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    k = []
    for i in range(25, 0, -1):
      k.append(s[i])
      if s[i-1] < s[i]:
        for j in sorted(k):
          if j > s[i-1]:
            print(s[:i-1] + j)
            exit()

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
alp=[chr(ord('a') + i) for i in range(26)]
unused=set(alp)
     
S=input()
print("len",len(S))

if len(S)<26:
    for i in range(len(S)):
        if S[i] in unused:
            unused.remove(S[i])
    unused=sorted(unused)
    print(S+unused[0])
else:
    for j in range(len(S)-1,-1,-1):
        p=set(S[j:])
        
        q=sorted(p)
        if S[j]==q[-1]:
            pass
        else:
            idx=q.index(S[j])
            print(S[:j]+q[idx+1])
            break
    else:
        print(-1)

Failing test case input:
pedoctb

Expected output:
pedoctba


Actual output:
len 7
pedoctba


Fixed submission (verdict: Accepted):
alp=[chr(ord('a') + i) for i in range(26)]
unused=set(alp)
     
S=input()


if len(S)<26:
    for i in range(len(S)):
        if S[i] in unused:
            unused.remove(S[i])
    unused=sorted(unused)
    print(S+unused[0])
else:
    for j in range(len(S)-1,-1,-1):
        p=set(S[j:])
        
        q=sorted(p)
        if S[j]==q[-1]:
            pass
        else:
            idx=q.index(S[j])
            print(S[:j]+q[idx+1])
            break
    else:
        print(-1)
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
l = len(s)

alf=set('abcdefghijklmnopqrstuvwxyz')
for i in range(l):
    if s[i] in alf:
        alf.remove(s[i])

if alf:
    t = list(alf)
    t.sort()
    s+=t[0]
else:
    stock=[]
    for i in range(1,26):
        if s[l-i-1]>s[l-i]:
            stock.append(s[l-i])
        else:
            stock.append(s[l-i])
            stock.sort()
            s=s[:l-i-1]+stock[0]
            break
        if i==25:
            print('-1')
            exit()

print(s)


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
s = input()
l = len(s)

alf=set('abcdefghijklmnopqrstuvwxyz')
for i in range(l):
    if s[i] in alf:
        alf.remove(s[i])

if alf:
    t = list(alf)
    t.sort()
    s+=t[0]
else:
    stock=[]
    for i in range(1,26):
        if s[l-i-1]>s[l-i]:
            stock.append(s[l-i])
        else:
            stock.append(s[l-i])
            stock.sort()
            for j in stock:
                if j>s[l-i-1]:
                    s=s[:l-i-1]+j
                    print(s)
                    exit()
        if i==25:
            print('-1')
            exit()
print(s)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    for i in range(len(s) - 1, 0, -1):
        if s[i] > s[i - 1]:
            s = list(s)
            s = s[: i - 1] + [min(s[i:])]
            print(''.join(s))
            sys.exit()
    print(-1)
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(26):
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    count = 1
    for i in range(1, len(s)):
        if s[-i] < s[-i - 1]:
            count += 1
        else:
            break
    if count == 26:
        print(-1)
    else:
        for i in sorted(s[-count:]):
            if s[-count - 1] < i:
                print(s[:-count-1] + i)
                sys.exit()
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(26):
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
abc="abcdefghijklmnopqrstuvwxyz"
if len(s)<26:
  print(s+sorted(list(set(abc)-set(s)))[0])
else:
  x=s[-1]
  Tail=[x]
  flag=0
  for i in range(2,27):
    if s[-i]<x:
      count=i
      flag=1
      break
    else:
      x=s[-i]
      Tail.append(x)
  print(s[:-count]+sorted(Tail)[0] if flag==1 else -1)

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
s=input()
abc="abcdefghijklmnopqrstuvwxyz"
if len(s)<26:
  print(s+sorted(list(set(abc)-set(s)))[0])
else:
  x=s[-1]
  Tail=[x]
  count,flag=0,0
  for i in range(2,27):
    if s[-i]<x:
      count=i
      flag=1
      break
    else:
      x=s[-i]
      Tail.append(x)
  t="z"
  if count!=0:
    for tt in Tail:
      if tt>s[26-count]:
        t=min(t,tt)  
  print(-1 if flag==0 else s[:-count]+t)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
a='abcdefghijklmnopqrstuvwzyx'
b=[i for i in a if i not in s]
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif b:
    print(s + b[0])
else:
    for i in range(1, len(s)):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            print(s[:-i] + chr(ord(s[-i:][0]) + 1))
            break

Failing test case input:
azcdefghijklmnopqrstuvwbyx

Expected output:
azcdefghijklmnopqrstuvwx


Actual output:
azcdefghijklmnopqrstuvwc


Fixed submission (verdict: Accepted):
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
b = [i for i in a if i not in s]
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif b:
    print(s + b[0])
else:
    for i in range(1, len(s) + 1):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            b = [j for j in a if j not in s[:-i+1] and j > s[-i:][0]][0]
            if i == 26:
                print(chr(ord(s[0]) + 1))
            else:
                print(s[:-i] + b)
            break

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
c = list(s)
c2 = set(c)
al = sorted(list("qwertyuiopasdfghjklzxcvbnm"))


if len(c)<26:
    for i in range(26):
        if al[i] not in c2:
            print(s+al[i])
            exit()

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

rev = "zyxwvutsrqponmlkjihgfedcba"
for i in range(25,-1,-1):
    if ord(s[i])<ord(s[-1]):
        print(s[:i]+s[-1])
        exit()

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:

Fixed submission (verdict: Accepted):
s = input()
c = list(s)
c2 = set(c)
al = sorted(list("qwertyuiopasdfghjklzxcvbnm"))


if len(c)<26:
    for i in range(26):
        if al[i] not in c2:
            print(s+al[i])
            exit()

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

rev = "zyxwvutsrqponmlkjihgfedcba"
for i in range(25,-1,-1):
    x = sorted(c[i:])
    for j in x:
        if ord(s[i])<ord(j):
            print(s[:i]+j)
            exit()
Problem: p03393
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S=input()

A="abcdefghijklmnopqrstuvwxyz"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(S)!=26:
    A=list(A)
    for i in range(len(S)):
        A.remove(S[i])
    print(S+A[0])
else:
    a=A.index(S[25])
    for i in range(24,-1,-1):
        b=A.index(S[i])
        if a>b:
            break
        a=b
    print(S[:b]+A[b+1])


Failing test case input:
azcdefghijklmnopqrstuvwbyx

Expected output:
azcdefghijklmnopqrstuvwx


Actual output:
ac


Fixed submission (verdict: Accepted):
S=input()

A="abcdefghijklmnopqrstuvwxyz"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(S)!=26:
    A=list(A)
    for i in range(len(S)):
        A.remove(S[i])
    print(S+A[0])
else:
    a=A.index(S[25])
    for i in range(24,-1,-1):
        b=A.index(S[i])
        if a>b:
            break
        a=b

    for j in range(b+1,26):
        if not A[j] in S[:i]:
            print(S[:i]+A[j])
            break

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = str(input())
ans = ''
if len(s) < 26:
  for i in range(ord('a'), ord('z')+1):
    if chr(i) not in s:
      ans = s + chr(i)
      break
else:
  for i in range(24, -1, -1):
    if ord(s[i]) < ord(s[i+1]):
      ans = s[:i] + chr(ord(s[i]) + 1)
      break
if ans: print(ans)
else: print(-1)

Failing test case input:
azcdefghijklmnopqrstuvwbyx

Expected output:
azcdefghijklmnopqrstuvwx


Actual output:
azcdefghijklmnopqrstuvwc


Fixed submission (verdict: Accepted):
s = str(input())
ans = ''
if len(s) < 26:
  for i in range(ord('a'), ord('z')+1):
    if chr(i) not in s:
      ans = s + chr(i)
      break
else:
  for i in range(24, -1, -1):
    if ord(s[i]) < ord(s[i+1]):
      ans = s[:i]
      for j in range(ord(s[i])+1, ord('z')+1):
        if chr(j) not in ans:
          ans += chr(j)
          break
      break
if ans: print(ans)
else: print(-1)
Problem: p03393
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
s = input()
is_there = [False for i in range(26)]


for c in s:
    is_there[ord(c)-97] = True

if len(s) == 26:
    tail = ord(s[-1])
    flag = True
    sp = -1
    for i in range(2,26):
        n = s[-i]
        if ord(n) < tail:
            flag = False
            sp = -i
            break
    if flag:
        print(-1)
    else:
        tp = list(s)
        tp = tp[:sp]
        print("".join(tp)+s[-1])
else:
    for i in range(26):
        if not is_there[i]:
            print(s+chr(i+97))
            break

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
-1


Fixed submission (verdict: Accepted):
s = input()
is_there = [False for i in range(26)]


for c in s:
    is_there[ord(c)-97] = True

if len(s) == 26:
    flag = True
    buf = []
    rep = None
    for i in range(25):
        buf.append(s[-i-1])
        for b in buf:
            if ord(b) > ord(s[-i-2]):
                rep = -i-2
                flag =False
                break
        if not flag:
            break


    if flag:
        print(-1)
    else:
        tp = s[:rep]
        tails = list(s[rep:])
        tails.sort()
        
        for t in tails:
            if ord(t) > ord(s[rep]):
                print(tp+t)
                break
else:
    for i in range(26):
        if not is_there[i]:
            print(s+chr(i+97))
            break

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import sys
li = [chr(i) for i in range(97, 97+26)]
s = input()
if len(s)<26:
    for l in li:
        if l not in s:
            print(s+l)
            sys.exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    r = s[::-1]
    tmp = ''
    for i,rr in enumerate(r):
        if i == 0:
            continue
        if rr < r[i-1]:
            tmp = r[:i+1][::-1]
            break
    
    print(s.replace(tmp, tmp[-1]))
    

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):


import sys
import bisect
li = [chr(i) for i in range(97, 97+26)]
s = input()
if len(s)<26:
    for l in li:
        if l not in s:
            print(s+l)
            sys.exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    r = s[::-1]
    tmp = ''
    kabe = ''
    for i,rr in enumerate(r):
        if i == 0:
            continue
        if rr < r[i-1]:
            tmp = r[:i+1][::-1]
            kabe = rr
            break
    

    tmp_li = list(tmp)
    tmp_li.sort()
    ind = bisect.bisect_left(tmp_li, kabe)
    s0 = tmp_li[ind+1]
    
    print(s.replace(tmp, s0))
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
if len(S) == 26:
    idx = -1
    for i in range(len(S)-1, 0, -1):
        if S[i-1] < S[i]:
            idx = i
            break
    if idx == -1:
        print(-1)
    else:
        print(S[:idx-1]+S[-1])
else:
    for i in range(97, 97+26):
        if chr(i) not in S:
            key = chr(i)
            break
    print(S+key)


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
import sys
S = input()
if len(S) < 26:
    for i in range(97, 97 + 26):
        if chr(i) not in S:
            print(S+chr(i))
            break
else:
    S_rev = S[::-1]
    for i in range(len(S_rev)-1):
        if S_rev[i] > S_rev[i+1]:
            for j in range(len(S_rev)):
                if S_rev[j] > S[-(i+2)]:
                    print(S[:len(S)-(i+1)-1]+S_rev[j])
                    sys.exit(0)
    print(-1)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()

def solve(S):
    C = [chr(ord('a') + i) for i in range(26)]

    if len(S) < 26:
        for c in C:
            if c not in S:
                return S + c

    for i in range(25):
        if S[i] > S[i + 1]:
            if i == 0:
                return "-1"
            else:
                return S[:i - 1] + min(S[i - 1:])

print(solve(S))

Failing test case input:
abcpefghijklmnodqrytuvwzsx

Expected output:
abcpefghijklmnodqrytuvwzx


Actual output:
abc


Fixed submission (verdict: Accepted):
S = input()

def solve(S):
    if len(S) < 26:
        return S + min(set(chr(ord('a') + i) for i in range(26)) - set(S))
    for i in range(len(S) - 1, 0, -1):
        if S[i - 1] < S[i]:
            return S[:i - 1] + min(s for s in S[i:] if s > S[i - 1])
    return "-1"

print(solve(S))

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


alp = 'abcdefghijklmnopqrstuvwxyz'
S = input()
if S == alp[::-1]:
    print(-1)
else:
    if len(S) == len(alp):
        l = list(S)
        for i in range(1, len(S))[::-1]:
            if l[i-1] > l[i]:
                l = l[:i-1] + [l[i]]
        l = l[:-2] + [l[-1]]
        print(''.join(l))
    else:
        for i in S : alp = alp.replace(i, '')
        print(S+alp[0])

Failing test case input:
abcdefghijklmnopqrytuvwzsx

Expected output:
abcdefghijklmnopqrytuvwzx


Actual output:
abcdefghijklmnopqs


Fixed submission (verdict: Accepted):


alp = 'abcdefghijklmnopqrstuvwxyz'
S = input()
if S == alp[::-1]:
    print(-1)
else:
    if len(S) == len(alp):
        l = list(S)
        s = []
        for i in range(1, len(S))[::-1]:
            s += [l[i]]
            r = sorted(x for x in s if x > l[i-1])
            if r:
                l = l[:i-1] + [r[0]]
                break
        print(''.join(l))
    else:
        for i in S : alp = alp.replace(i, '')
        print(S+alp[0])
Problem: p03393
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = input()
if len(S) != 26:
  A = [0] * 26
  offset = ord('a')
  for s in S:
    A[ord(s)-offset] = 1
  print(S + chr(A.index(0)+offset))
elif S == 'zyxwvutsrqponmlkjihgfedcba':
  print(-1)
else:
  T = 'z'*26
  for i in range(1, 25):
    T = min(T, S[:i] + min(S[i+1:]))
  print(T)

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
from string import ascii_lowercase as T
S = input()
if len(S) != 26:
  A = [0] * 26
  offset = ord('a')
  for s in S:
    A[ord(s)-offset] = 1
  print(S + chr(A.index(0)+offset))
elif S == T[::-1]:
  print(-1)
else:
  k = 25
  while S[k-1] > S[k]:
    k -= 1
  x = S[k-1]
  Y = sorted(S[k-1:])
  print(S[:k-1] + Y[Y.index(x) + 1])

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
d="zyxwvutsrqponmlkjihgfedcba"
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1)
else:
    if len(s)!=26:
        for i in range(1,1+26):
            if d[-i] not in s:print(s+d[-i]);exit()
    else:
        de=[s[-1]]
        for i in range(2,27):
            print(de)
            if de[0]<s[-i]:de.insert(0,s[-i])
            else:print(s[:-i]+de[0]);exit()

Failing test case input:
abcdefghijklmnopqrstuvwzyx

Expected output:
abcdefghijklmnopqrstuvx

Actual output:
['x']
['y', 'x']
['z', 'y', 'x']
abcdefghijklmnopqrstuvz


Fixed submission (verdict: Accepted):
d="zyxwvutsrqponmlkjihgfedcba"
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1)
else:
    if len(s)!=26:
        for i in range(1,1+26):
            if d[-i] not in s:print(s+d[-i]);exit()
    else:
        from bisect import bisect_left as bl,bisect_right as br
        de=[s[-1]]
        for i in range(2,27):

            if de[-1]<s[-i]:de.append(s[-i])
            else:print(s[:-i]+de[bl(de,s[-i])]);exit()

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
if len(s)<26:
  for i in range(97,123):
    if not chr(i) in s:
      print(s+chr(i))
      exit()
else:
  for i in range(24)[::-1]:
    for j in range(i+1,25)[::-1]:
      if s[i]<s[j]:
        print(s[:i]+s[j])
        exit()
  else:
    print(-1)

Failing test case input:
abcpefghijklmnodqrytuvwzsx

Expected output:
abcpefghijklmnodqrytuvwzx


Actual output:
abcpefghijklmnodqrytuvz


Fixed submission (verdict: Accepted):
s=input()
if len(s)<26:
  for i in range(97,123):
    if not chr(i) in s:
      print(s+chr(i))
      exit()
else:
  for i in range(25)[::-1]:
    for j in range(i+1,26)[::-1]:
      if s[i]<s[j]:
        print(s[:i]+s[j])
        exit()
  else:
    print(-1)
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = s0 = input()
d = {chr(c) for c in range(97, 123)}
for c in s:
    d.remove(c)
if d:
    s += min(d)
else:
    for c in reversed(s):
        s = s[:-1]
        if d and c < min(d):
            s += min(d)
            break
        d.add(c)
print(s if s else -1)
if s:
    assert s0 < s


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
-1


Fixed submission (verdict: Accepted):
s = s0 = input()
d = {chr(c) for c in range(97, 123)}
for c in s:
    d.remove(c)
if d:
    s += min(d)
else:
    for c in reversed(s):
        s = s[:-1]
        if d and any(c < e for e in d):
            s += min(e for e in d if c < e)
            break
        d.add(c)
print(s if s else -1)
if s:
    assert s0 < s

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()

ans = s
ansa = s
a = 'abcdefghijklmnopqrstuvwxyz'
a = [a[i] for i in range(26)]
if len(s)<26:
    for i in a:
        if ans.count(i) == 0:
            ans += i
            break
else:
    b = 26
    for i in range(1,26):
        if a.index(s[i]) > a.index(s[i-1]):
            b = i
    if b == 26:
        print(-1)
    else:
        s = s[:b]
        for j in a:
            if a.index(j) > a.index(s[b-1]) and j not in s:
                s = s[:b-1]+j
                break
        print(s)


Failing test case input:
cfspdua

Expected output:
cfspduab


Actual output:

Fixed submission (verdict: Accepted):
s = input()

ans = s
ansa = s
a = 'abcdefghijklmnopqrstuvwxyz'
a = [a[i] for i in range(26)]
if len(s)<26:
    for i in a:
        if ans.count(i) == 0:
            ans += i
            break
    print(ans)
else:
    b = 26
    for i in range(1,26):
        if a.index(s[i]) > a.index(s[i-1]):
            b = i
    if b == 26:
        print(-1)
    else:
        s = s[:b]
        for j in a:
            if a.index(j) > a.index(s[b-1]) and j not in s:
                s = s[:b-1]+j
                break
        print(s)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = list(input())

D = list("abcdefghijklmnopqrstuvwxyz")

if len(S) == 26:
  L = []
  cnt = 0
  for i in range(25, -1, -1):
    Flag = True
    for j in range(cnt, 26):
      if S[i] == D[j]:
        cnt = j
        Flag = False
        break
    if Flag:
      S[i] = S[-1]
      print("".join(S[:i+1]))
      exit()
  print("-1")      
else:
  for i in S:
    D.remove(i)
  print("".join(S) + D[0])

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
S = list(input())

D = list("abcdefghijklmnopqrstuvwxyz")

if len(S) == 26:
  cnt = 0
  L = []
  for i in range(25, -1, -1):
    Flag = True
    for j in range(cnt, 26):
      if S[i] == D[j]:
        L.append(S[i])
        cnt = j
        Flag = False
        break
    if Flag:
      L.sort()
      for k in L:
        if k > S[i]:
          S[i] = k
          break
      print("".join(S[:i + 1]))
      exit()
  print("-1")      
else:
  for i in S:
    D.remove(i)
  print("".join(S) + D[0])
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			k=d[1]
			print(s[:-i-1]+k)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xb


Fixed submission (verdict: Accepted):
s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			if d[0]==s[-i-1]:
				k=d[1]
			else:
				for j in range(len(d)):
					if d[j]>s[-i-1]:
						k=d[j]
						break
			print(s[:-i-1]+k)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      q=S[25-i:]
      q2=[]
      for j in q:
        if ord(j)<ord(S[24-i]):
          pass
        else:
          q2+=[ord(j)]
      q2.sort()
      
      S=S[:24-i]+chr(q2[0])
      print(S)
      break
    if i==25:
      print(-1)
    
else:
  print(S+s[0])

Failing test case input:
zyxwvutsrqponmlkjihgfedcba

Expected output:
-1

Actual output:

Fixed submission (verdict: Accepted):
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      q=S[25-i:]
      q2=[]
      for j in q:
        if ord(j)<ord(S[24-i]):
          pass
        else:
          q2+=[ord(j)]
      q2.sort()
      
      S=S[:24-i]+chr(q2[0])
      print(S)
      break
    if i==24:
      print(-1)
    
else:
  print(S+s[0])
Problem: p03017
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, A, B, C, D = map(int, input().split())
s = input()

ans = "Yes"
tmpSpace = 0
tmpRock = 0
space = 0
for i in range(min(C, D)):
    if s[i] == ".":
        tmpSpace += 1
        tmpRock = 0
    else:
        tmpRock += 1
        if tmpRock >= 2:
            ans = "No"
            break
        space = max(space, tmpSpace)
        tmpSpace = 0

space = max(space, tmpSpace)
if (A - B) * (C - D) < 0:
    if space <= 2:
        ans = "No"

print(ans)

Failing test case input:
3 1 3 11 7
...#.#...#.#...

Expected output:
No


Actual output:
Yes


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

ans = "Yes"

for i in range(A - 1, C):
    if i != 0 and s[i-1:i+1] == "
        ans = "No"
        break

for i in range(B - 1, D):
    if i != 0 and s[i-1:i+1] == "
        ans = "No"
        break


spaceFlg = False
for i in range(max(A, B) - 1, min(C, D)):
    if s[i-1:i+2] == "...":
        spaceFlg = True
        break

if (A - B) * (C - D) < 0 and not spaceFlg:
    ans = "No"

print(ans)

Problem: p03017
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import re

N, A, B, C, D = map(int, input().split())
S = input()

if C < D:
    if re.search(r'\.\.', S):
        print('Yes')
    else:
        print('No')
else:
    if re.search(r'\.\.\.', S):
        print('Yes')
    else:
        print('No')    

Failing test case input:
15 1 3 15 7
...#.#...#.#...

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
import re

N, A, B, C, D = map(int, input().split())
S = input()
S = '
flag = True
if re.search(r'
    flag *= False

if D < C:
    if re.search(r'\.\.\.', S[B-1:D+2]):
        flag *= True
    else:
        flag *= False
        
print('Yes') if flag else print('No')

Problem: p03017
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,a,b,c,d=map(int,input().split())
print('YNeos'[('...' in input() or c<d)::2])

Failing test case input:
27 0 5 15 9
...#.#...#.#./.

Expected output:
Yes


Actual output:
No


Fixed submission (verdict: Accepted):
n,a,b,c,d=map(int,input().split())
s=input()
print('YNeos'['

Problem: p03017
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, A, B, C, D = map(int, input().split())
S = input()
if C < D:
    if "**" in S[A: D + 1]:
        print("No")
    else:
        print("Yes")
else:
    if "**" in S[A: D + 1] and not("..." in S[B - 1: min(D + 2, C)]):
        print("No")
    else:
        print("Yes")

Failing test case input:
3 1 3 11 7
...#.#...#.#...

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
N, A, B, C, D = map(lambda  x: int(x) - 1, input().split())
S = input()
if C < D:
    if "
        print("No")
    else:
        print("Yes")
else:
    if "
        print("No")
    else:
        print("Yes")
Problem: p03017
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, A, B, C, D = map(int, input().split())
S = input()
if C < D:
    if "**" in S[A: D + 1]:
        print("No")
    else:
        print("Yes")
else:
    if "**" in S[A: D + 1] or not("..." in S[B - 1: min(D + 2, C)]):
        print("No")
    else:
        print("Yes")

Failing test case input:
2 1 3 15 7
...#.#...#.#...

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
N, A, B, C, D = map(lambda  x: int(x) - 1, input().split())
S = input()
if C < D:
    if "
        print("No")
    else:
        print("Yes")
else:
    if "
        print("No")
    else:
        print("Yes")

Problem: p03017
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import re

N, A, B, C, D = map(int, input().split())
S = input()

flag = True



if C < D:
    if re.search(r'\.\.', S[B:C+1]):
        flag *= True
    else:
        flag *= False
else:
    if re.search(r'\.\.\.', S[B:D+1]):
        flag *= True
    else:
        flag *= False
        
print('Yes') if flag else print('No')

Failing test case input:
15 0 8 15 9
...#.#...#.#...

Expected output:
Yes


Actual output:
No


Fixed submission (verdict: Accepted):
import re

N, A, B, C, D = map(int, input().split())
S = input()
S = '
flag = True
if re.search(r'
    flag *= False

if D < C:
    if re.search(r'\.\.\.', S[B-1:D+2]):
        flag *= True
    else:
        flag *= False
        
print('Yes') if flag else print('No')

Problem: p03017
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,a,b,c,d=map(int,input().split())
print('YNeos'[not ('...' in input() or c<d)::2])

Failing test case input:
2 1 3 15 7
...#.#...#.#...

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
n,a,b,c,d=map(int,input().split())
s=input()
print('YNeos'['

Problem: p03017
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, A, B, C, D = map(int, input().split())
S = input()

if C < D:
    print('Yes')
    exit()

if S[B-2:D].find('...') >= 0:
    print('Yes')
else:
    print('No')

Failing test case input:
24 1 3 14 8
...#.#...#.#...

Expected output:
Yes


Actual output:
No


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

if S[A-1:max([C, D])].find('
    print('No')
    exit()

if C < D:
    print('Yes')
    exit()

if S[B-2:D+1].find('...') >= 0:
    print('Yes')
else:
    print('No')
Problem: p03017
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import copy
N,A,B,C,D = map(int,input().split())
S = input()

i = A
j = B


if C > D:
    flag = False
    for i in range(N - 3):
        if S[i:i + 3] == "...":
            flag = True
    if flag == False:
        print("No")
        exit(0)

print("Yes")

Failing test case input:
15 1 3 11 7
...#.#...$.#...

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
import copy
N,A,B,C,D = map(int,input().split())
S = input()

for i in range(A,max(C,D)-1):
    if S[i:i+2] == "
        print("No")
        exit(0)

if C > D:
    flag = False
    for i in range(B-1,D):
        if S[i-1:i + 2] == "...":
            flag = True
            break

    if flag == False:
        print("No")
        exit(0)

print("Yes")
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = map(int,input().split())
a = [[]*2]*M
for i in range(M):
    a[i]=input().rstrip().split()


a=sorted(a, key=lambda x: x[1])
hasi = 0
sum = 0

for i in range(0,M):
    c1 = int(a[i][0])
    c2 = int(a[i][1])
    if hasi >= c1:
        continue
    else:
        hasi = c2-1
        sum = sum+1

print(sum)


Failing test case input:
5 2
-3 5
0 8

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
a = list(list(map(int, input().split())) for x in range(M))


a=sorted(a, key=lambda x: x[1])
hasi = -1
sum = 0

for i in range(0,M):
    
    if (hasi >= a[i][0])and (hasi < a[i][1]):
        continue
    else:
        hasi = a[i][1]-1
        sum = sum+1

print(sum)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
L=10**6
ans=0
for a,b in ab[::-1]:
    if not a<=L<b:
        ans+=1
        L=a
print(ans)

Failing test case input:
9 5
2 6
2 7
3 5
0 12
0 5

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
ab.sort()
L=10**6
ans=0
for a,b in ab[::-1]:
    if not a<=L<b:
        ans+=1
        L=a
print(ans)

Problem: p03295
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]

l = sorted(l, key = lambda x:(x[1], x[0]))
cnt = m

for i in range(1, m):
    if l[i-1][1] > l[i][0]:
        l[i][1] = l[i-1][0]
        cnt -= 1

print(cnt)


Failing test case input:
9 5
2 8
2 7
3 5
4 12
0 5

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):

n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]

l = sorted(l, key = lambda x:(x[1], x[0]))
cnt = 0
con_l = 0

for i in range(m):
    if con_l <= l[i][0]:
        cnt += 1
        con_l = l[i][1]

print(cnt)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):
    l1 = [v1 for (v1,_) in l]
    l2 = [v2 for (_,v2) in l]
    l1.sort()
    l2.sort()

    l2 = list(set(l2))

    count = 1

    l.sort()

    h = 0
    
    for i in range(len(l)):
        nx = l2[h]
        if l[i][0] >= nx:
            count+=1
            h+=1
    return count




result = do(l)
print(result)

Failing test case input:
9 5
2 8
2 7
3 5
4 6
5 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):

    count = 1

    l.sort()
    right = l[0][1]


    for i in range(len(l)):
        if l[i][0] >= right:
            right = l[i][1]
            count+=1
            continue
        if l[i][1] < right:
            right = l[i][1]
    return count

testl = [[x,x+1] for x in range(1)]

result = do(l)
print(result)
Problem: p03295
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m=map(int,input().split())
itv=[]
for i in range(m):
  a,b=map(int,input().split())
  start=min(a,b)
  end=max(a,b)
  itv.append([end,start])
t,ans=0,0
itv=sorted(itv)
for e,s in itv:
  if t<s:
    t=e
    ans+=1
print(ans)

Failing test case input:
5 10
1 2
0 4
1 4
1 5
2 3
2 8
2 7
3 3
3 5
4 5

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
itv=[]
for i in range(m):
  a,b=map(int,input().split())
  start=min(a,b)
  end=max(a,b)
  itv.append([end,start])
t,ans=0,0
itv=sorted(itv)
for e,s in itv:
  if t<=s:
    t=e
    ans+=1
print(ans)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))
ab.sort(reverse = True)
print(ab)
bridge = [float("inf")]
for i in range(m):
    if ab[i][0] <= min(bridge) < ab[i][1]:
        continue
    else:
        bridge.append(ab[i][0])
print(len(bridge) - 1)

Failing test case input:
1 1
0 5
1 7

Expected output:
1


Actual output:
[[0, 5]]
1


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))
ab.sort(reverse = True)

bridge = [float("inf")]
for i in range(m):
    if ab[i][0] <= min(bridge) < ab[i][1]:
        continue
    else:
        bridge.append(ab[i][0])
print(len(bridge) - 1)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
_, M = map(int, input().split())
Schedule = [list(map(int, input().split())) for _ in range(M)]

Schedule = sorted(Schedule, key=lambda x: x[1])
cnt = 0
before_end = 0
for task in Schedule:
    start = task[0]
    end = task[1]
    if start < before_end:
        continue
    cnt += 1
    before_end = end

Failing test case input:
5 2
1 3
2 8

Expected output:
1


Actual output:

Fixed submission (verdict: Accepted):
_, M = map(int, input().split())
Schedule = [list(map(int, input().split())) for _ in range(M)]

Schedule = sorted(Schedule, key=lambda x: x[1])
cnt = 0
before_end = 0
for task in Schedule:
    start = task[0]
    end = task[1]
    if start < before_end:
        continue
    cnt += 1
    before_end = end
print(cnt)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
ab=[[0]*2 for _ in range(m)]
for i in range(m):
  a,b=map(int,input().split())
  ab[i][0],ab[i][1]=b,a
ab.sort()
cnt=0
b=0
for i in range(m):
  if b<ab[i][1]:
    cnt+=1
    b=ab[i][0]
print(cnt)

Failing test case input:
4 1
0 5
4 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
ab=[[0]*2 for _ in range(m)]
for i in range(m):
  a,b=map(int,input().split())
  ab[i][0],ab[i][1]=b,a
ab.sort()
cnt=0
chk=0
for b,a in ab:
  if chk<=a:
    cnt+=1
    chk=b
print(cnt)
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, M = map(int, input().split())
    req = []
    for i in range(M):
        a, b = map(int, input().split())
        req.append([a, i, 0])
        req.append([b, i, 1])
    req.sort(key = lambda x: x[0])

    tocut = set()
    count = 0
    for i in range(len(req)):
        if req[i][2] == 0:
            tocut.add(req[i][1])
        else:
            if req[i][1] in tocut:
                count += 1
                tocut = set()
    return count



if __name__ == '__main__':
    print(main())

Failing test case input:
9 5
1 8
2 7
3 5
4 6
7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
def main():

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

    A.sort()

    a, b = A[0]
    cnt = 1
    for i in range(1, M):
        if A[i][0] <= b:
            a = A[i][0]
            b = min(b, A[i][1])
        else:
            a, b = A[i]
            cnt += 1
    return cnt

if __name__ == '__main__':
    print(main())

Problem: p03295
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,M = list(map(int, input().split()))
ab = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1])
last = ab[0][1]
s = 1
for one in ab[1:]:
    a,b = one
    if a>last:
        s+=1
print(s)

Failing test case input:
5 2
1 2
2 4

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N,M = list(map(int, input().split()))
ab = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1])
last = ab[0][1]
s = 1
for one in ab[1:]:
    a,b = one
    if a>=last:
        s+=1
        last = b
print(s)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = list(map(int, input().split()))
ab = []
for i in range(m):
  a, b = list(map(int, input().split()))
  ab.append((a, b))
ab.sort()

max_ = 0
ans = 0
t = 0
for ele in ab:
  if t==ele[0]:
    pass
  elif t!=ele[0]:
    t = ele[0]
    if ele[0]>=max_:
      ans += 1
    max_ = ele[1]
  
print(ans)

Failing test case input:
5 2
-6 5
2 5

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n, m = list(map(int, input().split()))
ab = []
for i in range(m):
  a, b = list(map(int, input().split()))
  ab.append((a, b))
ab.sort(key=lambda x:x[1])

ans = 0
max_ = 0
for ele in ab:
  if ele[0]>=max_:
    max_ = ele[1]
    ans += 1
print(ans)
Problem: p03295
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

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

a_b_pairs = [list(map(int, input().split(' '))) for _ in range(M)]
a_b_pairs.sort(key=lambda x: x[1])
right = a_b_pairs[0][1]

ans = 1
for a, b in a_b_pairs[1:]:
    if a < right < b:
        pass
    else:
        right = b
        ans += 1


print(ans)





Failing test case input:
5 10
1 2
1 4
1 4
1 5
2 3
2 4
2 5
3 3
3 5
4 5

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):

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

a_b_pairs = [list(map(int, input().split(' '))) for _ in range(M)]
a_b_pairs.sort(key=lambda x: x[1])
right = a_b_pairs[0][1] - 1

ans = 1
for a, b in a_b_pairs[1:]:
    if a > right:
        right = b - 1
        ans += 1

print(ans)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):





N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
ab.sort(key=lambda x: x[1])
ans = 1             
tmp = ab[0][1]      
for i in range(1, M):
    if ab[i][0] < tmp < ab[i][1]:   
        pass
    else:                           
        ans += 1
        tmp = ab[i][1]

print(ans)

Failing test case input:
5 2
-6 5
2 5

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):





N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
ab.sort(key=lambda x: x[1])

ans = 1             
tmp = ab[0][1] - 0.1      
for i in range(1, M):
    if ab[i][0] < tmp < ab[i][1]:   
        pass
    else:                           
        ans += 1
        tmp = ab[i][1] - 0.1

print(ans)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from operator import itemgetter
n,m=map(int,input().split())
a=[]
b=[]
for i in range(m):
    a_,b_=map(int,input().split())
    a.append(a_)
    b.append(b_)
ab=sorted([(a[i],b[i]) for i in range(m)],  key=itemgetter(1))  

ans=0
last=0
for i in range(m):
    if last<ab[i][0]:
        last=ab[i][1]
        ans+=1
    else:
        last=ab[i][1]
print(ans)

Failing test case input:
9 5
2 8
2 7
3 5
4 9
5 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
from operator import itemgetter
n,m=map(int,input().split())
a=[]
b=[]
for i in range(m):
    a_,b_=map(int,input().split())
    a.append(a_)
    b.append(b_)
ab=sorted([(a[i],b[i]) for i in range(m)],  key=itemgetter(1))  
removed=-1
ans=0

for i,j in ab:
    if i>removed:
        ans+=1
        removed=j-1
print(ans)
Problem: p03295
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, m=map(int, input().split())
hope=[]
for i in range(m):
    a, b=map(int, input().split())
    hope.append((a, b))
hope.sort(reverse=True, key=lambda x: x[0])
hope.sort(reverse=True, key=lambda x: x[1])
ans=0
for i in range(m-1):
    if i==0:
        target=hope[i][0]
    if not target<hope[i+1][1]:
        ans=ans+1
        target=hope[i+1][0]
print(ans+1)


Failing test case input:
5 10
1 2
2 4
1 4
1 5
2 3
2 4
2 5
3 3
3 5
4 5

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):

n, m=map(int, input().split())
hope=[]
for i in range(m):
    a, b=map(int, input().split())
    hope.append((a, b))
hope.sort(reverse=True, key=lambda x: x[0])
hope.sort(reverse=True, key=lambda x: x[1])
ans=0
for i in range(m-1):
    if i==0:
        target=hope[i][0]
    if target<hope[i+1][1]:
        if target<hope[i+1][0]:
            target=hope[i+1][0]
    else:
        ans=ans+1
        target=hope[i+1][0]
print(ans+1)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
l=[]
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort()
s=l[0][1]
ans=1
for i in range(1,m):
    if l[i][0]>=s:
        ans+=1
        s=l[i][1]
print(ans)


Failing test case input:
5 10
1 2
0 4
1 4
1 5
2 3
2 8
2 7
3 3
3 5
4 5

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
l=[]
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort()
s=l[0][1]
ans=1
for i in range(1,m):
    if l[i][0]>=s:
        ans+=1
        s=l[i][1]
    if l[i][1]<=s:
        s=l[i][1]
print(ans)

Problem: p03295
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m = map(int,input().split())
ab = []
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: x[1])
print(ab)
count = 1
memo = ab[0][1]
for i in range(m):
    if i == 0:
        continue
    if memo <= ab[i][0]:
        count += 1
        memo = ab[i][1]
print(count)

Failing test case input:
5 2
2 4
2 5

Expected output:
1


Actual output:
[[2, 4], [2, 5]]
1


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
ab = []
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: x[1])

count = 1
memo = ab[0][1]
for i in range(m):
    if i == 0:
        continue
    if memo <= ab[i][0]:
        count += 1
        memo = ab[i][1]
print(count)
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
l = [list(map(int, input().split())) for i in range(M)]
l = sorted(l, key = lambda l:(l[1]))

print(l)

p_num = -1
ans = 0

for i in range(M):
	if not l[i][0] <= p_num:
		p_num = l[i][1] - 1
		ans += 1

print(ans)

Failing test case input:
5 2
-6 5
0 5

Expected output:
1


Actual output:
[[-6, 5], [0, 5]]
1


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
l = [list(map(int, input().split())) for i in range(M)]
l = sorted(l, key = lambda l:(l[1]))

p_num = -1
ans = 0

for i in range(M):
	if not l[i][0] <= p_num:
		p_num = l[i][1] - 1
		ans += 1

print(ans)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
ab_list = list()
for _ in range(m):
    a, b = map(int, input().split())
    ab_list.append([a, b])
ab_list = sorted(ab_list, key=lambda x: x[1])
x = -1
ans = 0
for a, b in ab_list:
    if a < x:
        continue
    else:
        x = b-1
        ans += 1
print(ans)

Failing test case input:
1 2
1 4
3 6

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
ab_list = list()
for _ in range(m):
    a, b = map(int, input().split())
    ab_list.append([a, b])
ab_list = sorted(ab_list, key=lambda x: x[1])
x = -1
ans = 0
for a, b in ab_list:
    if a <= x:
        continue
    else:
        x = b-1
        ans += 1
print(ans)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

ans = 1
ind = 0


start, end = cut.pop(0)
ind += 1
while ind < M:
    n_s, n_e = cut.pop(0)
    ind += 1
    if end > n_s:
        continue
    else:
        start = n_s
        end = n_e
        ans += 1


print(ans)


Failing test case input:
5 10
1 2
0 4
1 4
1 5
2 3
2 8
2 7
3 3
2 5
4 5

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

ans = 1
ind = 0


s = cut[ind][0]
e = cut[ind][1]
while ind < M:
    n_s, n_e = cut[ind]
    if n_s < e:
        e = min(e, n_e)
    else:
        s = n_s
        e = n_e
        ans += 1
    ind += 1


print(ans)
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
ab=[]
for m in range(M):
  [a,b]=[int(i) for i in input().split()]
  ab.append([a,b])
ab.sort(key=lambda x:x[1])
count=[]
bmin=ab[0][1]
count.append(ab[0][1]-1)
for i in range(1,M):
  if ab[i][1]==b:
    count.remove(count[0])
    count.append(ab[i][1])
  else:
    pass
for i in range(1,M):
  if ab[i][0]<=count[-1]<ab[i][1]:
    pass
  else:
    count.append(ab[i][1])
print(len(count))

Failing test case input:
5 2
-1 5
1 5

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
ab=[]
for m in range(M):
  [a,b]=[int(i) for i in input().split()]
  ab.append([a,b])
ab.sort(key=lambda x:x[1])
count=[]
count.append(ab[0][1]-1)
for i in range(1,M):
  if ab[i][0]<=count[-1]<ab[i][1]:
    pass
  elif ab[i][0]<=count[-1] and ab[i][1]-1==count[-1]:
    count.remove(count[-1])
    count.append(ab[i][1]-1)
  else:
    count.append(ab[i][1]-1)
print(len(count))

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n , m = map(int, input().split())
l = [list(map(int,input().split())) for _ in range(m)]
l.sort()
l = l[::-1]
cnt = 1
key = l[0][0]
for i in range(m):
    if key > l[i][1]:
        cnt += 1
        key = l[i][0]
print(cnt)
    


Failing test case input:
5 2
1 2
2 8

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n , m = map(int, input().split())
l = [list(map(int,input().split())) for _ in range(m)]
l.sort()
l = l[::-1]
cnt = 1
key = l[0][0]
for i in range(1,m):
    if key >= l[i][1]:
        cnt += 1
        key = l[i][0]
print(cnt)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
l.sort(key=lambda x : x[1])
a=0
b=0
for x in l:
  if x[0]>b:
    b=x[0]
    a+=1
print(a)


Failing test case input:
7 1
0 2
2 5

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
l.sort(key=lambda x : x[1])
a=0
b=0
for x in l:
  if x[0]>=b:
    b=x[1]
    a+=1
print(a)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(m)]
AB.sort(key=lambda ab: -ab[1])
count = 1
l = AB[0][1]
for a, b in AB[1:]:
    if l < a:
        l = a
    if b <= l:
        l = a
        count += 1
print(count)


Failing test case input:
5 10
1 2
1 4
1 4
1 5
2 3
2 4
2 7
3 3
3 5
4 5

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(m)]
AB.sort(key=lambda ab: -ab[1])
count = 1
l = AB[0][0]
for a, b in AB[1:]:
    if l < a:
        l = a
    if b <= l:
        l = a
        count += 1
print(count)