ZhenlongDai/ACPR huggingface dataset:
Problem: p03295
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

n, m = map(int, input().split())
d = []
for i in range(m):
    a, b = map(int, input().split())
    d.append([a, b])

d.sort(key=lambda x: (x[0], x[1]))

mn = 100000000
ans = 0
for a, b in d:
    if a >= mn:
        ans += 1
        mn = b
    mn = min(mn, b)

if mn != 100000000:
    ans += 1
print(ans)

print(ans + 1)


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

Expected output:
1


Actual output:
1
2


Fixed submission (verdict: Accepted):

n, m = map(int, input().split())
d = []
for i in range(m):
    a, b = map(int, input().split())
    d.append([a, b])

d.sort(key=lambda x: (x[0], x[1]))

mn = 100000000
ans = 0
for a, b in d:
    if a >= mn:
        ans += 1
        mn = b
    mn = min(mn, b)

if mn != 100000000:
    ans += 1
print(ans)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from operator import itemgetter
sys.setrecursionlimit(1000000) 

def main():
    input = sys.stdin.readline  
    N, M = map(int, input().rstrip().split())

    require_list = []
    for _ in range(M):
        s, e = map(int, input().rstrip().split())
        require_list.append([s, e])
    require_list.sort(key=itemgetter(1))
    print(require_list)

    count = 1
    now_require = require_list[0]
    for next_require in require_list[1:]:
        
        if now_require[1] <= next_require[0]:
            count += 1
        else:
            next_require[1] = now_require[1]
        now_require = next_require

    print(count)

if __name__ == '__main__':
    main()

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

Expected output:
1


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


Fixed submission (verdict: Accepted):
import sys
from operator import itemgetter
sys.setrecursionlimit(1000000) 

def main():
    input = sys.stdin.readline  
    N, M = map(int, input().rstrip().split())

    require_list = []
    for _ in range(M):
        s, e = map(int, input().rstrip().split())
        require_list.append([s, e])
    require_list.sort(key=itemgetter(1))

    count = 1
    now_require = require_list[0]
    for next_require in require_list[1:]:
        
        if now_require[1] <= next_require[0]:
            count += 1
        else:
            next_require[1] = now_require[1]
        now_require = next_require

    print(count)

if __name__ == '__main__':
    main()
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
AB=sorted(AB, key=lambda x: x[1])
bridges=[]
for i in range(M):
    if len(bridges) == 0:
        bridges.append(AB[i][1])
    elif max(bridges)>=AB[i][0]:
        pass
    else:
        bridges.append(AB[i][1]-1)
print(len(bridges))

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

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
AB=sorted(AB, key=lambda x: x[1])
bridges=[]
for i in range(M):
    if len(bridges) == 0:
        bridges.append(AB[i][1]-1)
    elif max(bridges)>=AB[i][0]:
        pass
    else:
        bridges.append(AB[i][1]-1)
print(len(bridges))

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from operator import attrgetter


class Line:
    def __init__(self, a, b):
        self.a = a
        self.b = b


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

lines = sorted(lines, key=attrgetter("a"))

start_num = lines[0].a
min_num = 1000000
cnt = 0

for line in lines:
    if line.a != start_num:
        if min_num <= line.a:
            cnt += 1
        start_num = line.a
    if line.b < min_num:
        min_num = line.b
cnt += 1
print(cnt)


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

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
from operator import attrgetter


class Line:
    def __init__(self, a, b):
        self.a = a
        self.b = b


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

lines = sorted(lines, key=attrgetter("a"))

start_num = lines[0].a
min_num = 1000000
cnt = 0

for line in lines:
    if line.a != start_num:
        if min_num <= line.a:
            cnt += 1
            min_num = line.b
        start_num = line.a
    if line.b < min_num:
        min_num = line.b
cnt += 1
print(cnt)
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from operator import itemgetter
n, m = (int(i) for i in input().split())
e = [[int(i) for i in input().split()] for i in range(m)]
g = 1
e.sort(key = itemgetter(1))
print(e)
for i in range(m):
    if i == 0:
        a = e[0][1] - 1
        print(a)
    else:
        if a >= e[i][0]:
            pass
        else:
            g += 1
            a = e[i][1] - 1
print(g)

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

Expected output:
4

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


Fixed submission (verdict: Accepted):
from operator import itemgetter
n, m = (int(i) for i in input().split())
e = [[int(i) for i in input().split()] for i in range(m)]
g = 1
e.sort(key = itemgetter(1))
for i in range(m):
    if i == 0:
        a = e[0][1] - 1
    else:
        if a >= e[i][0]:
            pass
        else:
            g += 1
            a = e[i][1] - 1
print(g)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, M = map(int, input().split())
    ab = [[int(i) for i in input().split()] for _ in range(M)]
    ab = sorted(ab, key=lambda x: x[1] - x[0])
    d = [ab.pop(0)]
    ans = 1
    for a, b in ab:
        for aa, bb in d:
            if aa > b or a > bb:
                ans += 1
    print(ans)


main()


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

Expected output:
2


Actual output:
3


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


main()

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
L = list()
for i in range(m):
    x, y = map(int, input().split())
    if x > y:
        x, y = y, x
    L.append([x, y])
L = sorted(L, key=lambda x: x[1])
print(L)
A = L[0]
i = 1
for v in L:
    if v[0] >= A[1]:
        A = v
        i += 1
print(i)


Failing test case input:
5 2
1 3
2 8

Expected output:
1


Actual output:
[[1, 3], [2, 8]]
1


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
L = list()
for i in range(m):
    x, y = map(int, input().split())
    if x > y:
        x, y = y, x
    L.append([x, y])
L = sorted(L, key=lambda x: x[1])
A = L[0]
i = 1
for v in L:
    if v[0] >= A[1]:
        A = v
        i += 1
print(i)
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())

AB = [tuple(map(int, input().split())) for _ in range(M)]

AB.sort(key=lambda x: x[1])
num = 0
p = 0
for i in AB:
    if i[0] > p:
        num += 1
        p = i[1]

print(num)


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

Expected output:
1


Actual output:
0


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

AB = [tuple(map(int, input().split())) for _ in range(M)]

AB.sort(key=lambda x: x[1])
num = 0
p = 0
for i in AB:
    if i[0] >= p:
        num += 1
        p = i[1]

print(num)

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
print(ans)

Failing test case input:
4 1
0 5
2 1

Expected output:
1


Actual output:
0


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 (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
L = list()
for i in range(m):
    x, y = map(int, input().split())
    if x > y:
        x, y = y, x
    L.append([x, y])
L = sorted(L, key=lambda x: x[1])
A = L[0]
i = 1
for v in L:
    if v[0] > A[1]:
        A = v
        i += 1
print(i)


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()
for i in range(m):
    x, y = map(int, input().split())
    if x > y:
        x, y = y, x
    L.append([x, y])
L = sorted(L, key=lambda x: x[1])
A = L[0]
i = 1
for v in L:
    if v[0] >= A[1]:
        A = v
        i += 1
print(i)
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):





















from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7


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

q.sort(reverse=True)

left = q[0][1]
ans = 0
for i in range(1,M):
	if left >= q[i][0]:
		ans += 1
		left = q[i][1]

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):





















from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7


N,M = map(int,(input().split()))
queue = [tuple(map(int,(input().split()))) for i in range(M)]
queue.sort(key=lambda x:x[1])

left = 0
ans = 0
for q in queue:
	if q[0] >= left:
		ans += 1
		left = q[1]

print(ans)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [0] * m
for i in range(m):
    aa, bb = map(int, input().split())
    ab[i] = (aa, bb)

ab.sort()
ans = 1
prev_left, border = ab[0][0], ab[0][1]
for i in range(1, m):
    if prev_left == ab[i][0]:
        border = min(border, ab[i][1])
    else:
        if border <= ab[i][0]:
            ans += 1
        prev_left = ab[i][0]
        border = ab[i][1]
print(ans)

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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [0] * m
for i in range(m):
    aa, bb = map(int, input().split())
    ab[i] = (aa, bb)

ab.sort()
ans = 1
prev_left, border = ab[0][0], ab[0][1]
for i in range(1, m):
    if prev_left == ab[i][0]:
        border = min(border, ab[i][1])
    else:
        if border <= ab[i][0]:
            ans += 1
            border = ab[i][1]
        prev_left = ab[i][0]
        border = min(border, ab[i][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 i in range(M)]
AB=sorted(AB, key=lambda x: x[1])
bridges=[]
for i in range(M):
    if len(bridges) == 0:
        bridges.append(AB[i][1])
    elif max(bridges)>=AB[i][0]:
        pass
    else:
        bridges.append(AB[i][1])
print(len(bridges))

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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
AB=sorted(AB, key=lambda x: x[1])
bridges=[]
for i in range(M):
    if len(bridges) == 0:
        bridges.append(AB[i][1]-1)
    elif max(bridges)>=AB[i][0]:
        pass
    else:
        bridges.append(AB[i][1]-1)
print(len(bridges))
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N,M=map(int,input().split())
A=[]
for i in range(M):
    a,b=map(int,input().split())
    A.append([a,b])
B=sorted(A,key=lambda x:x[1])

if M==0:
    print(0)
else:
    c=B[0][1]
    B.pop(0)
    count=1
    while B!=[]:
        if B[0][0]>c:
            count=count+1
            c=B[0][1]
        B.pop(0)
        
        
    print(count)

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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):

N,M=map(int,input().split())
A=[]
for i in range(M):
    a,b=map(int,input().split())
    A.append([a,b])
B=sorted(A,key=lambda x:x[1])

if M==0:
    print(0)
else:
    c=B[0][1]
    B.pop(0)
    count=1
    while B!=[]:
        if B[0][0]>=c:
            count=count+1
            c=B[0][1]
        B.pop(0)
        
        
    print(count)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
c = []
mn = 0
mx = 10**5+1
for i in range(m):
	a, b = map(int, input().split())
	if len(c) == 0:
		c.append([a,b])
	if a > mx or b < mn:
		c.append([a,b])
	mn = max(a,mn)
	mx = min(b,mx)
print (len(c))

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:
3


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
ab = []
for i in range(m):
	a,b = map(int, input().split())
	ab.append([a,b])
ab = sorted(ab, key=lambda x: x[1])
mn = ab[0][1]
c = 1
for i in ab:
	if i[0] >= mn:
		c += 1
		mn = i[1]
print (c)

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





















from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7


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

q.append([1,1])
q.sort(reverse=True)

left = q[0][1]
ans = 0
for i in range(1,M+1):
	if left >= q[i][0]:
		ans += 1
		left = q[i][1]

print(ans)


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

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):





















from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7


N,M = map(int,(input().split()))
queue = [tuple(map(int,(input().split()))) for i in range(M)]
queue.sort(key=lambda x:x[1])

left = 0
ans = 0
for q in queue:
	if q[0] >= left:
		ans += 1
		left = q[1]

print(ans)
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

input = sys.stdin.readline
n, m = map(int, input().split())

request = []
for _ in range(m):
    a, b = map(int, input().split())
    request.append([a, b])

request.sort(key=lambda x: x[1])
first = request.pop(0)[1] - 1
ans = 1
for a, b in request:
    if first < a:
        ans += 1
        first = a

print(ans)


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

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
import sys

input = sys.stdin.readline
n, m = map(int, input().split())

request = []
for _ in range(m):
    a, b = map(int, input().split())
    request.append([a, b])

request.sort(key=lambda x: x[1])
pre = - 1
ans = 0
for a, b in request:
    if pre < a:
        ans += 1
        pre = b - 1

print(ans)

Problem: p03295
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m = map(int, input().split())
a = []
for i in range(m):
  x,y = map(int, input().split())
  a.append((x,y))
a.sort()
ans = 1
l,r = a[0]
for x,y in a[1:]:
  if r <= x:
    ans += 1
    l = x
    r = y

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):
n,m = map(int, input().split())
a = []
for i in range(m):
  x,y = map(int, input().split())
  a.append((x,y))
a.sort(key=lambda x:x[1])
ans = 1
l,r = a[0]
for x,y in a[1:]:
  if r <= x:
    ans += 1
    l = x
    r = y

print(ans)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from operator import itemgetter

N, M = map(int, input().split())
ab = [[int(x) for x in input().split()] for _ in range(M)]

ab = sorted(ab, key=itemgetter(1), reverse=True)
ab = sorted(ab, key=itemgetter(0))

ans = 1
r = N
for a, b in ab:
    if a >= r:
        ans += 1
    r = b
print(ans)


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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
from operator import itemgetter

N, M = map(int, input().split())
ab = [[int(x) for x in input().split()] for _ in range(M)]

ab = sorted(ab, key=itemgetter(0, 1))
ans = 1
x, y = ab[0]
for i in range(1, M):
    a, b = ab[i]
    if b <= x or y <= a:
        ans += 1
        x, y = a, b
    else:
        x = max(x, a)
        y = min(y, b)
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):
    a,b=map(int,input().split())
    if a in ab:
        ab[a]=min(ab[a],b)
    else:
        ab[a]=b
ab = sorted(ab.items(), key=lambda x:x[0])

ans=1
for i in range(1,len(ab)):
    if ab[i][0]>=ab[i-1][1]:
        ans+=1
print(ans)


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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
ab={}
for i in range(m):
    a,b=map(int,input().split())
    if a in ab:
        ab[a]=min(ab[a],b)
    else:
        ab[a]=b
ab = sorted(ab.items(), key=lambda x:x[0])

ans=1
min_end=10**10
for i in range(len(ab)):
    if ab[i][0]>=min_end:
        ans+=1
        min_end=ab[i][1]
    else:
        min_end=min(ab[i][1], min_end)
print(ans)

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)
print(itv)
for e,s in itv:
  if t<=s:
    t=e
    ans+=1
print(ans)

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

Expected output:
1


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


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())
Bridge = []
for i in range(M):
    Bridge.append([int(x) for x in input().split()])

def minpair(A,B):
    C = []
    if A[1] > B[0]:
        C = [B[0],A[1]]
    elif B[1] > A[0]:
        C = [A[0],B[1]]
    return C

Bridge.sort(key=lambda x: x[0])
c = 0
ans = 0
while c <= M-2:
    Temp = minpair(Bridge[c],Bridge[c+1])
    if Temp == []:
        ans += 1
    else:
        Bridge[c+1] = Temp
    c += 1
print(ans+1)

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

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N,M = map(int, input().split())
Bridge = []
for i in range(M):
    Bridge.append([int(x) for x in input().split()])

def minpair(A,B):
    if A[1] <= B[0]:
        C = []
    elif B[0] < A[1] <= B[1]:
        C = [B[0],A[1]]
    else:
        C = B
    return C

Bridge.sort(key=lambda x: x[0])
c = 0
ans = 0
while c <= M-2:
    Temp = minpair(Bridge[c],Bridge[c+1])
    if Temp == []:
        ans += 1
    else:
        Bridge[c+1] = Temp
    c += 1
print(ans+1)
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n,m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]
rest = sorted(lst, key=lambda x:x[0], reverse=False)
ans = 1
et = rest[0][1] 
for i in range(len(rest)):
    if rest[i][0]>=et:
        et=rest[i][1]
        ans+=1
print(ans)

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):

n,m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]
rest = sorted(lst, key=lambda x:x[1], reverse=False)
ans = 1
et = rest[0][1] 
for i in range(len(rest)):
    if rest[i][0]>=et:
        et=rest[i][1]
        ans+=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]+0.5
    if not hope[i+1][0]<target<hope[i+1][1]:
        ans=ans+1
        target=hope[i+1][0]+0.5
print(ans+1)


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

Expected output:
2


Actual output:
5


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())
count = 0
s = [[]*2]*m
for i in range(0, m):
  s[i] = list(map(int, input().split()))

r = s[0][1]
count += 1
for i in range(1, m):
  if r > s[i][0] & r > s[i][1]:
    r = s[i][1]
  if r <= s[i][0]:
    r = s[i][1]
    count += 1
print(count)

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):
n, m = map(int, input().split())
count = 0
s = [[]*2]*m
for i in range(0, m):
  s[i] = list(map(int, input().split()))
s.sort()
r = s[0][1] - 1
count += 1
for i in range(1, m):
  if s[i][1] < r + 1:
    r = s[i][1] - 1
  if s[i][0] > r:
    r = s[i][1] - 1
    count += 1
print(count)
Problem: p03295
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,M = map(int,input().split())
l = [[0]*2 for i in range(M)]
sum = 0
for i in range(M):
    l[i][0],l[i][1] = map(int,input().split())
l.sort(key=lambda l:l[1])
x = 0
for i in range(M):
    if x<l[i][0]:
        x=l[i][1]
        sum+=1
print(sum)

Failing test case input:
5 2
1 2
2 4

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
l = [[0]*2 for i in range(M)]
sum = 0
for i in range(M):
    l[i][0],l[i][1] = map(int,input().split())
l.sort(key=lambda l:l[1])
x = 0
for i in range(M):
    if x<=l[i][0]:
        x=l[i][1]
        sum+=1
print(sum)

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 = -1
sum = 0

for i in range(0,M):

    c1 = int(a[i][0])
    c2 = int(a[i][1])
    
    if (hasi >= c1) and  (hasi < c2):
        continue
    hasi = c2-1
    sum = sum+1


print(sum)

Failing test case input:
5 2
1 6
2 12

Expected output:
1


Actual output:
2


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 (PyPy3 (2.4.0), verdict: Wrong Answer):



from operator import itemgetter
import bisect

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


ab = [(0, 0)]*M
for m in range(M):
    ab[m] = tuple(map(int, input().split()))

ab = tuple(sorted(ab, key = itemgetter(1)))


x_rm = -1
res = 0
for m in range(M):
    if ab[m][0] <= x_rm:
        continue
    else:
        x_rm = ab[m][1]
        res += 1
    
    
        

print(res)



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:
3


Fixed submission (verdict: Accepted):



from operator import itemgetter
import bisect

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


ab = [(0, 0)]*M
for m in range(M):
    ab[m] = tuple(map(int, input().split()))

ab = tuple(sorted(ab, key = itemgetter(1)))


x_rm = -1
res = 0
for m in range(M):
    if ab[m][0] < x_rm:
        continue
    else:
        x_rm = ab[m][1]
        res += 1
    
    
        

print(res)
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = (int(x) for x in input().split())

sec = []

for i in range(m):
    list = [int(i) for i in input().split()]
    list.reverse()
    sec.append(list)

sec.sort()
left = sec[0][0]
right = sec[0][1]
x = right - 1
ans = 0

for i in range(m):
    if sec[i][1]<x<sec[i][0]:
        continue
    else:
        x = sec[i][0]
        ans += 1

print(ans)


Failing test case input:
5 2
0 5
2 5

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n,m = (int(x) for x in input().split())

sec = []

for i in range(m):
    list = [int(i) for i in input().split()]
    list.reverse()
    sec.append(list)

sec.sort()
left = sec[0][0]
right = sec[0][1]
x = right - 1
ans = 0

for i in range(m):
    if sec[i][1]<x:
        continue
    else:
        x = sec[i][0]
        ans += 1

print(ans)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
sp=[None for i in range(m)]
for i in range(m):
  l,r=map(int,input().split())
  sp[i]=[l,r]
sp.sort(key=lambda x:x[1])
sp.sort(key=lambda x:x[0])
s=[sp[0]]
for i in sp:
  if i[0]!=s[-1][0]:
    s.append(i)
ans=1
c=s[0]
if len(s)==1:print(1)
else:
  for i in range(1,len(s)):
    if c[1]<=s[i][0]:
      ans+=1
      c=s[i]
    if c[1]>s[i][1]:
      c=s[i]
    else:
      c[0]=s[i][0]
print(ans)

Failing test case input:
4 1
0 5
2 1

Expected output:
1


Actual output:
1
1


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
sp=[None for i in range(m)]
for i in range(m):
  l,r=map(int,input().split())
  sp[i]=[l,r]
sp.sort(key=lambda x:x[1])
sp.sort(key=lambda x:x[0])
s=[sp[0]]
for i in sp:
  if i[0]!=s[-1][0]:
    s.append(i)
ans=1
c=s[0]
if len(s)==1:print(1)
else:
  for i in range(1,len(s)):
    if c[1]<=s[i][0]:
      ans+=1
      c=s[i]
    if c[1]>s[i][1]:
      c=s[i]
    else:
      c[0]=s[i][0]
  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(reverse=True)
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:
5 2
-4 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()
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.4.3), verdict: Wrong Answer):
hops = dict()
N, M = map(int, input().split())
for i in range(M):
    a, b = map(int, input().split())
    if a > b:
        a, b = b, a
    hop = hops.get(b-a)
    if not hop:
        hops[b-a] = hop = set()
    hop.add((a, b))

covered = []
for key in sorted(hops.keys()):
    found = False
    for a, b in hops[key]:
        for area in covered:
            if not (area[0] >= b or area[1] <= a):
                covered.remove(area)
                covered.append((max(area[0], a), min(area[1], b)))
                found = True
                break

        if not found:
            covered.append((a, b))


answer = len(covered)
print(answer)

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):
break_offs = set()
N, M = map(int, input().split())
for i in range(M):
    a, b = map(int, input().split())
    if a > b:
        a, b = b, a
    break_offs.add((a, b))

covered = []
break_offs = sorted(list(break_offs), key=lambda x:x[1])
for a, b in break_offs:
    found = False
    for area in covered:
        if not (area[0] >= b or area[1] <= a):
            covered.remove(area)
            covered.append((max(area[0], a), min(area[1], b)))
            found = True
            break

    if not found:
        covered.append((a, b))


answer = len(covered)
print(answer)

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



n, m = list(map(int, input().split()))

w = []
cnt = 1

for i in range(m):
    ai, bi = list(map(int, input().split()))
    ci = set(list(range(ai,bi)))
    w.append(ci)
    

    
bs0 = w[0]    
for bs in w:
    bsand = bs0 & bs
    if len(bsand) == 0:
        cnt += 1
        bs0 = bs
    else:
        bs0 = bsand
        
print(cnt)




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

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):



n, m = list(map(int, input().split()))

w = []
cnt = 1

for i in range(m):
    ai, bi = list(map(int, input().split()))
    w.append([ai, bi])

w.sort(key = lambda x: x[1])


cnt = 1
icut = w[0][1]-1 
for bs in w:
    if bs[0] > icut:
        cnt += 1
        icut = bs[1]-1

print(cnt)
Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int, input().split(" "))


arr=[[0,100000000]]
for i in range(m):
    flag=0
    a,b=map(int, input().split(" "))

    for j in arr:
        if j[0]<=a and j[1]>=b:
            arr.remove(j)
            flag=1
    
    arr.append([a,b])
    

arr.sort(key=lambda x:x[0])

count=0
for i in range(len(arr)-1):
    if arr[i][1]-arr[i+1][0]>0:
        count+=1

print(len(arr)-count)




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

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
n,m=map(int, input().split(" "))
arr=[]
for i in range(m):
    a,b=map(int, input().split(" "))

    arr.append([a,b])


arr.sort(key=lambda x:(x[0],x[1]))
left=0
num=0
count=0
for i in range(len(arr)):
    if arr[i][0]==left:
        pass
    if arr[i][1]<=num:
        num=arr[i][1]
    if arr[i][0]-num>=0:
        count+=1
        num=arr[i][1]
        left=arr[i][0]
    
print(count)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int, input().split(" "))


arr=[[0,100000000]]
for i in range(m):
    flag=1
    a,b=map(int, input().split(" "))

    for j in arr:
        flag=1
        if j[0]<=a and j[1]>=b:
            arr.remove(j)
        elif j[0]>=a and j[1]<=b:
            flag=0
            break
    if flag==1:
        arr.append([a,b])
    

arr.sort(key=lambda x:x[0])

count=0
for i in range(len(arr)-1):
    if arr[i][1]-arr[i+1][0]>0:
        count+=1

print(len(arr)-count)



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(" "))
arr=[]
for i in range(m):
    a,b=map(int, input().split(" "))

    arr.append([a,b])


arr.sort(key=lambda x:(x[0],x[1]))
left=0
num=0
count=0
for i in range(len(arr)):
    if arr[i][0]==left:
        pass
    if arr[i][1]<=num:
        num=arr[i][1]
    if arr[i][0]-num>=0:
        count+=1
        num=arr[i][1]
        left=arr[i][0]
    
print(count)

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

input = sys.stdin.readline
n, m = map(int, input().split())

request = []
for _ in range(m):
    a, b = map(int, input().split())
    request.append([a, b])

request.sort(key=lambda x: x[1])
pre = - 1
ans = 1
for a, b in request:
    if pre < a:
        ans += 1
        pre = b - 1

print(ans)


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

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys

input = sys.stdin.readline
n, m = map(int, input().split())

request = []
for _ in range(m):
    a, b = map(int, input().split())
    request.append([a, b])

request.sort(key=lambda x: x[1])
pre = - 1
ans = 0
for a, b in request:
    if pre < a:
        ans += 1
        pre = b - 1

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

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

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n, m = list(map(int, input().split()))
ab = list(list(map(int, input().split())) for i in range(m))
ab = sorted(ab, key=lambda x: x[1])
bridge = 0
count = 0
for i in range(m):
    if ab[i][0] < bridge:
        continue
    else:
        bridge = ab[i][1]
        count = count + 1
    if count == n-1:
        break
    else:
        continue
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 _ 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


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

Expected output:
1


Actual output:

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())
B=[]
for i in range(1,M):
  a,b=map(int,input().split())
  B.append([a,b])
B.sort(key=lambda x:x[1])
ans=0
c=-1
for item in B:
  if item[1]!=c:
    c=item[1]
    ans+=1
print(ans)

Failing test case input:
5 1
0 5
2 7

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
B=[]
for i in range(M):
  a,b=map(int,input().split())
  B.append([a,b])
B.sort(key=lambda x:x[1])
ans=1
c=[B[0][1]]
for item in B:
  if c[-1]<=item[0]:
    c.append(item[1])
    ans+=1
print(ans)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())

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

fights = sorted(fights, reverse=True)

import bisect


bridges = []
for a,b in fights:
    a_position = bisect.bisect(bridges, a)
    b_position = bisect.bisect(bridges, b)
    
    if a_position == b_position:
        bisect.insort(bridges, a)
        

print(len(bridges))


        
        

Failing test case input:
1 2
1 4
4 6

Expected output:
2


Actual output:
1


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

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

fights = AB[:]

fights = sorted(fights, reverse=True)

import bisect


bridges = []
for a,b in fights:
    a_position = bisect.bisect(bridges, a)
    b_position = bisect.bisect(bridges, b)
    
    if a_position == b_position:
        bisect.insort(bridges, a+1)
        

print(len(bridges))
Problem: p03295
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



from operator import itemgetter
import bisect

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


ab = [(0, 0)]*M
for m in range(M):
    ab[m] = tuple(map(int, input().split()))

ab = tuple(sorted(ab, key = itemgetter(0)))

a = [0]*M
b = [0]*M
for m in range(M):
    a[m], b[m] = ab[m]
b.sort()
res = 0
n = -1
while True:
    tmp = bisect.bisect_left(a, n)
    
    n = b[bisect.bisect_right(b, a[tmp])]
    res+=1
    if n > a[m]:
        break
    
    
        

print(res)



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

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):



from operator import itemgetter
import bisect

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


ab = [(0, 0)]*M
for m in range(M):
    ab[m] = tuple(map(int, input().split()))

ab = tuple(sorted(ab, key = itemgetter(1)))


x_rm = -1
res = 0
for m in range(M):
    if ab[m][0] < x_rm:
        continue
    else:
        x_rm = ab[m][1]
        res += 1
    
    
        

print(res)

Problem: p03295
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve(tasks):
    tasks = sorted(tasks, key=lambda x:x[1])
    end = 0
    start = 0
    ans = 0
    for task in tasks:
        if task[1]<start: continue
        end = task[0]
        ans += 1
        start = end
    return ans


n,m = map(int,input().split())

tasks = []
for i in range(m):
    a,b = map(int,input().split())
    tasks.append([b,a])

ans = solve(tasks)
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())

tasks = []
for i in range(m):
    a,b = map(int,input().split())
    tasks.append([b,a])



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

print(ans)
Problem: p03049
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

N = int(input())
S = [input() for _ in range(N)]
l, m, n = 0, 0, 0
ans = 0
for s in S:
    if s[0] == 'B' and s[-2] == 'A':
        n += 1
    elif s[0] == 'B':
        m += 1
    elif s[-2] == 'A':
        l += 1
    for i in range(len(s)-1):
        if s[i:i+2] == 'AB':
            ans += 1
ans += min(l, m)
if n > 0:
    ans += n - 1
if l != m and l != 0 and m != 0:
    ans += 1
print(ans)

Failing test case input:
9
BWEPVCRWH
ZQNZYIJX
AVRAEB
Q@
TYMJIHDOX
JNMRMHKCA
AP
ZBAGVQ
PRGKSPUNA

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

N = int(input())
S = [input() for _ in range(N)]
l, m, n = 0, 0, 0
ans = 0
for s in S:
    if s[0] == 'B' and s[-2] == 'A':
        n += 1
    elif s[0] == 'B':
        m += 1
    elif s[-2] == 'A':
        l += 1
    for i in range(len(s)-1):
        if s[i:i+2] == 'AB':
            ans += 1
if n > 0:
    ans += n - 1
    if l > 0:
        l -= 1
        ans += 1
    if m > 0:
        m -= 1
        ans += 1
ans += min(l, m)
print(ans)

Problem: p03049
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())

S = []
for n in range(N):
	S.append(input())

Acount  = 0
Bcount  = 0
ABcount = 0
BXAcount = 0

for s in S:
	if s[0]  == "B" :
		Bcount += 1
	if s[-1] == "A" :
		Acount += 1
	for i in range(len(s)-1) : 
		if s[i] == "A" and s[i+1] == "B" :
			ABcount += 1
	if s[0] == "B" and s[-1] == "A" :
		BXAcount += 1





if BXAcount >= 1 :
	if Acount == BXAcount and Bcount == BXAcount :
		print(min(Acount, Bcount) + ABcount -1)
else:
	print(min(Acount, Bcount) + ABcount)



Failing test case input:
3
ADAB
[XAA
BDA

Expected output:
2


Actual output:

Fixed submission (verdict: Accepted):
N = int(input())

S = []
for n in range(N):
	S.append(input())

Acount  = 0
Bcount  = 0
ABcount = 0
BXAcount = 0

for s in S:
	if s[0]  == "B" :
		Bcount += 1
	if s[-1] == "A" :
		Acount += 1
	for i in range(len(s)-1) : 
		if s[i] == "A" and s[i+1] == "B" :
			ABcount += 1
	if s[0] == "B" and s[-1] == "A" :
		BXAcount += 1





if BXAcount >= 1 and Acount == BXAcount and Bcount == BXAcount :
		print(min(Acount, Bcount) + ABcount -1)
else:
	print(min(Acount, Bcount) + ABcount)

Problem: p03049
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import re
N = int(input())
S = []
a, b, c = 0, 0, 0
for i in range(N):
	S.append(input())
	c += len(re.findall("AB", S[i]))
	if S[i][-1] == "A":
		a += 1
	if S[i][0] == "B":
		b += 1
seq = 0
if a == b and a > 0:
	seq = a-1
elif a != b:
	seq = min(a,b) 

print(seq + c)

Failing test case input:
7
RABZBBF
JOX
VAUQHMB
BPB
RVI
MCM@BAOBIZ
RZMDJMA

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import re
N = int(input())
S = []
a, b, ab,c = 0, 0, 0, 0
for i in range(N):
	S.append(input())
	c += len(re.findall("AB", S[i]))
	if S[i][-1] == "A" and S[i][0] == "B":
		ab += 1
	if S[i][-1] == "A":
		a += 1
	if S[i][0] == "B":
		b += 1
if ab == a == b:
	seq = max(ab -1, 0)
else:
	seq = min (a,b)

print(seq + c)
Problem: p03049
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = []
for _ in range(n):
    s.append(input())
a = 0
b = 0
ans = 0
same = 0
for i in s:
    flg = False
    if i[0]=='B':
        flg = True
        b += 1
    if i[-1]=='A':
        a += 1
        if flg:
            same += 1
    for j in range(len(i)-1):
        if i[j:j+2]=='AB':
            ans += 1
ans += min(n-1, a, b)
if a == b == same:
    ans -= 1
print(ans)

Failing test case input:
3
@ABD
ZABX
AEB

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
s = []
for _ in range(n):
    s.append(input())
a = 0
b = 0
ans = 0
same = 0
for i in s:
    flg = False
    if i[0]=='B':
        flg = True
        b += 1
    if i[-1]=='A':
        a += 1
        if flg:
            same += 1
    for j in range(len(i)-1):
        if i[j:j+2]=='AB':
            ans += 1
ans += min(a, b)
if a == b == same > 0:
    ans -= 1
print(ans)

Problem: p03049
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
inward = 0
top = 0
fin = 0
dbl = 0

for _ in range(N):
    s = input()
    n = len(s)
    if s[0] == 'B' and s[n-1] == 'A':
        dbl += 1
    elif s[0] == 'B' and s[n-1] != 'A':
        top += 1
    elif s[0] != 'B' and s[n-1] == 'A':
        fin += 1
    for i in range(n-1):
        if s[i] == 'A' and s[i+1] == 'B':
            inward += 1

ans = inward + dbl-1
MAX = N-1 - (dbl-1)
if top >0:
    ans +=1
    top -=1
    MAX -=1
if fin >0:
    ans +=1
    fin -=1
    MAX -=1
ans += min(top,fin,MAX)
print(ans)

Failing test case input:
3
AABD
ZABX
AEB

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
inward = 0
top = 0
fin = 0
dbl = 0

for _ in range(N):
    s = input()
    n = len(s)
    if s[0] == 'B' and s[n-1] == 'A':
        dbl += 1
    elif s[0] == 'B' and s[n-1] != 'A':
        top += 1
    elif s[0] != 'B' and s[n-1] == 'A':
        fin += 1
    for i in range(n-1):
        if s[i] == 'A' and s[i+1] == 'B':
            inward += 1

ans = inward
MAX = N-1
if dbl>0:
    ans += dbl-1
    MAX -= (dbl-1)
    if top >0:
        ans +=1
        top -=1
        MAX -=1
    if fin >0:
        ans +=1
        fin -=1
        MAX -=1
ans += min(top,fin,MAX)
print(ans)
Problem: p03049
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = [input() for _ in range(int(input()))]
a = b = ab = ans = 0
for si in s:
    for j in range(len(si)-1):
        if si[j] == "A" and si[j+1] == "B":
            ans += 1
    if si[0] == "B" and si[-1] == "A":
        ab += 1
    elif si[0] == "B":
        b += 1
    elif si[-1] == "A":
        a += 1
print(ans + max(ab-1, 0)) if a == b == 0 else print(ans +  min(a, b))

Failing test case input:
9
BEWPVCRWH
ZZNQYIJX
BAVREA
PA
HJMYITEOX
BCJHMRMNK
BP
QVFABZ
PRGKSPUNA

Expected output:
4

Actual output:
3


Fixed submission (verdict: Accepted):
s = [input() for _ in range(int(input()))]
a = b = ab = ans = 0
for si in s:
    for j in range(len(si)-1):
        if si[j] == "A" and si[j+1] == "B":
            ans += 1
    if si[0] == "B" and si[-1] == "A":
        ab += 1
    elif si[0] == "B":
        b += 1
    elif si[-1] == "A":
        a += 1
print(ans + max(ab-1, 0)) if a == b == 0 else print(ans + ab + min(a, b))

Problem: p03049
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
s = list(input()for i in range(N))
ans = 0
A,B = 0,0
AB = 0
for i in s:
    for j in range(len(i)-1):
        if i[j:j+2] == "AB":
            ans += 1
    if i[0] == "B" and i[-1] == "A":
        AB += 1
    elif i[0] == "B":
        B += 1
    elif i[-1] == "A":
        A += 1
ans +=AB+min(A,B)
if A==B and B == 0:
    ans -= 1
print(ans)

Failing test case input:
3
AABD
ZABX
AEB

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
s = list(input()for i in range(N))
ans = 0
A,B = 0,0
AB = 0
for i in s:
    for j in range(len(i)-1):
        if i[j:j+2] == "AB":
            ans += 1
    if i[0] == "B" and i[-1] == "A":
        AB += 1
    elif i[0] == "B":
        B += 1
    elif i[-1] == "A":
        A += 1
ans +=AB+min(A,B)
if A==0 and B==0 and AB > 0:
    ans -= 1
print(ans)

Problem: p03049
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
B_start_cnt = 0
A_end_cnt = 0
AB_cnt = 0
BA_cnt = 0
for i in range(N):
    s = input()
    if s[0] == "B" and s[-1] == "A":
        BA_cnt += 1
    if s[0] == "B":
        B_start_cnt += 1
    if s[-1] == "A":
        A_end_cnt += 1
    AB_cnt += s.count('AB')
ans = min(A_end_cnt,B_start_cnt)+AB_cnt
if min(A_end_cnt,B_start_cnt) == AB_cnt:
    ans -= 1
print(ans)

Failing test case input:
7
RABZBBF
JOX
BMHQUAV
BPC
RVI
MCN@BAOBIZ
RJMDZMA

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
B_start_cnt = 0
A_end_cnt = 0
AB_cnt = 0
BA_cnt = 0
for i in range(N):
    s = input()
    if s[0] == "B" and s[-1] == "A":
        BA_cnt += 1
    if s[0] == "B" and s[-1] != "A":
        B_start_cnt += 1
    if s[-1] == "A" and s[0] != "B":
        A_end_cnt += 1
    AB_cnt += s.count('AB')
ans = AB_cnt

if BA_cnt == 0:
    ans += min(A_end_cnt,B_start_cnt)
elif max(A_end_cnt,B_start_cnt)>0:
    ans += BA_cnt+min(A_end_cnt,B_start_cnt)
else:
    ans += BA_cnt-1
print(ans)
Problem: p03049
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())   
s = [input() for i in range(n)]

a = 0
b = 0
ab = 0
ba = 0
for i in s:
  if i[0] == "B":
    b += 1
  if i[-1] == "A":
    a += 1
  if i[0] == "B" and i[-1] == "A":
    ba += 1
  ab += i.count("AB")
  
if ba == b:
  aa = a - 1
else:
  aa = a
if ba == a:
  bb = b - 1
else:
  bb = b

print(min(aa, bb) + ab)

Failing test case input:
3
AABD
ZABX
AEB

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())   
s = [input() for i in range(n)]

a = 0
b = 0
ab = 0
ba = 0
for i in s:
  if i[0] == "B":
    b += 1
  if i[-1] == "A":
    a += 1
  if i[0] == "B" and i[-1] == "A":
    ba += 1
  ab += i.count("AB")
  
if ba != 0 and ba == b:
  aa = a - 1
else:
  aa = a
if ba != 0 and ba == a:
  bb = b - 1
else:
  bb = b
  
print(min(aa, bb) + ab)

Problem: p03049
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
    
def calc(s):
    lastA = 0
    firstB = 0
    both = 0
    interAB = 0
    for _s in s:
        if _s[0] == 'B' and _s[-1] == 'A':
            both += 1
        else:
            if _s[0] == 'B':
                firstB += 1
            if _s[-1] == 'A':
                lastA += 1
        
        if 'AB' in _s:
            interAB += 1

    if lastA == 0 and firstB == 0 and both == 1:
        return interAB
    
    return min(lastA + both, firstB + both) + interAB

def main():
    n = stdin.readline().rstrip()
    s = [x.rstrip() for x in stdin.readlines()]
    ans = calc(s)
    print(ans)
    
if __name__=='__main__':
    main()

Failing test case input:
3
BDAA
[AAX
BDA

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from sys import stdin
    
def calc(s):
    lastA = 0
    firstB = 0
    both = 0
    interAB = 0
    for _s in s:
        if _s[0] == 'B' and _s[-1] == 'A':
            both += 1
        else:
            if _s[0] == 'B':
                firstB += 1
            if _s[-1] == 'A':
                lastA += 1
        
        interAB += _s.count('AB')

    if lastA == 0 and firstB == 0:
        both = max(both-1,0)
    return min(lastA + both, firstB + both) + interAB

def main():
    n = stdin.readline().rstrip()
    s = [x.rstrip() for x in stdin.readlines()]
    ans = calc(s)
    print(ans)
    
if __name__=='__main__':
    main()