ZhenlongDai/ACPR huggingface dataset:
Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()

count = len(S)
N = count
s_count = 0
t_count = 0

i = 0
while i < N:
    if S[i] == 'S':
        s_count += 1
        i += 1
    else:
        if s_count != 0:
            tmp = i
            while tmp < N and S[tmp] == 'T':
                tmp += 1
                t_count += 1
            cut = min(s_count, t_count)
            count -= cut*2
            s_count = t_count = 0
            i += cut
        else:
            i += 1

        
print(count)


Failing test case input:
SSTSTT

Expected output:
0


Actual output:
2


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

count = len(S)
N = count
s_count = 0
t_count = 0

i = 0
while i < N:
    if S[i] == 'S':
        s_count += 1
        i += 1
    else:
        if s_count != 0:
            tmp = i
            while tmp < N and S[tmp] == 'T':
                tmp += 1
                t_count += 1
            if s_count > t_count:
                cut = t_count
                s_count = s_count - t_count
                t_count = 0
            else:
                cut = s_count
                s_count = t_count = 0
            count -= cut*2
            i += cut
        else:
            i += 1

        
print(count)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x = "T"+input()+"S"
ans = len(x)-2
s = t = 0
for i in x:
    if i=="S":
        ans -= min(s,t)*2
        if t: s = t = 0
        s += 1
    else: t += 1
print(ans)

Failing test case input:
SSSTSTTT

Expected output:
0


Actual output:
4


Fixed submission (verdict: Accepted):
x = "T"+input()+"S"
ans = len(x)-2
s = t = 0
for i in x:
    if i=="S":
        ans -= min(s,t)*2
        if s>t:
            s -= t
            t = 0
        else: t = s = 0
        s += 1
    else: t += 1
print(ans)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a=input()
b=0
x=0
for i in a:
  if i=="T":
    x+=1
  else:
    x-=1
  if x>=1:
    b+=1
print(b)

Failing test case input:
SSTTSTTS

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
a=input()
x=0
b=0
for i in a:
  if i=="T" and x<=-1:
    x+=1
  elif i=="S":
    x-=1
  elif x==0:
    b+=1
print(b*2)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s,t = 0,0
for x in input():
  if x == 'S':
    s += 1
  else:
    if s > 1:
      s -= 1
    else:
      t += 1

print(s+t)

Failing test case input:
SSSTTTTS

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
s,t = 0,0
for x in input():
  if x == 'S':
    s += 1
  else:
    if s > 0:
      s -= 1
    else:
      t += 1

print(s+t)
Problem: p03986
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
from itertools import accumulate
sys.setrecursionlimit(10**6)




def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


X = S()
num_S = [0] * len(X)
s_count = 0
t_count = 0
for x in reversed(X):
    if (x == 'S'):
        s_count += 1
    else:
        break
        t_count += 1
print(s_count*2)










Failing test case input:
TSSTSTST

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):

import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
from itertools import accumulate
sys.setrecursionlimit(10**6)




def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


X = S()
num_S = [0] * len(X)
t_count = 0
s_count = 0
ans = 0
prev = X[-1]
if (prev == 'S'):
    s_count = 1
else:
    t_count = 1
for x in reversed(X[:-1]):
    if (prev == 'S' and x == 'T'):
        
        rest = max(s_count - t_count, 0)
        ans += (rest*2)
        t_count = max(t_count - s_count, 0)
        s_count = 0
    if (x == 'S'):
        s_count += 1
    if (x == 'T'):
        t_count += 1
    prev = x
print(ans)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import string
import re
input = lambda: sys.stdin.readline()


st = []
s = input()

for x in s:
    if not len(st) == 0:
        top = st.pop()
        
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)

print(len(st))



















Failing test case input:
TTSTSS

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
st = []
X = input()
for x in X:
    if not len(st) == 0:
        top = st.pop()
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)
print(len(st))

Problem: p03986
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
S = list(input())[: -1]
s = 0
t = 0
res = len(S)
if S[0] == "S": s += 1
for i in range(1, len(S)):
  if S[i] == "S":
    if t == 1:
      s = 0
      t = 0
    s += 1
  else:
    if s > 0:
      res -= 2
      s -= 1
      t = 1
print(res)

Failing test case input:
STSSTSTT

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
S = list(input())[: -1]
s = 0
t = 0
res = len(S)
if S[0] == "S": s += 1
for i in range(1, len(S)):
  if S[i] == "S":
    s += 1
  else:
    if s > 0:
      res -= 2
      s -= 1
      t = 1
print(res)
Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
ans=0
count=0
for i in s:
    if i=='S':count+=1
    else:count-=1
    if count<0:ans+=1
print(ans)

Failing test case input:
SSTTSTTS

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
s=input()
ans=0
count=0
for i in s:
    if i=='S':count=max(1,count+1)
    else:count-=1
    if count<0:ans+=1
print(ans*2)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
scount = 0
tcount = 0
ans = 0
for c in S:
    if c == "S":
        ans += min(scount, tcount) * 2
        tcount = 0
        scount += 1
    else:
        tcount += 1

ans += min (scount,tcount) * 2
ans = len(S) -ans
print(ans)

Failing test case input:
STSSTTTS

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
S = input()
scount = 0
tcount = 0
ans = 0
l = len(S)
for c in S:
    if c == "S":
        scount += 1
    else:
        if scount >0:
            scount -=1
            ans += 2

ans += min (scount,tcount) * 2
ans = len(S) -ans
print(ans)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

x = ns()
n = len(x)

ans = n
i = 0
while i < n:
    cs = 0
    ct = 0
    while i < n and x[i] == 'S':
        cs += 1
        i += 1
    while i < n and x[i] == 'T':
        ct += 1
        i += 1
    ans -= min(cs, ct) * 2

print(ans)

Failing test case input:
TSSTSTTS

Expected output:
2


Actual output:
4


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

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

x = ns()
n = len(x)

ans = n
i = 0
cs = 0
while i < n:
    if x[i] == 'S':
        cs += 1
        i += 1
    else:
        ct = 0
        while i < n and x[i] == 'T':
            ct += 1
            i += 1
        ans -= min(cs, ct) * 2
        cs -= min(cs, ct)

print(ans)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
def main():
    input = stdin.readline

    x = input()

    s = 0
    count = 0
    for cur in x:
        if cur == "S":
            s += 1
        else:
            if s != 0:
                s -= 1
            else:
                count += 2

    print(count)


if __name__ == '__main__':
    main()


Failing test case input:
SSSTSTTT

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
def main():
    x = input()

    s = 0
    count = 0
    for cur in x:
        if cur == "S":
            s += 1
        else:
            if s != 0:
                s -= 1
            else:
                count += 2

    print(count)


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


text = list(input())
txt_stuck = []

for i in text:
    if i == 'S':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck == []:
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'T':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'S':
        txt_stuck.pop()

print(''.join(txt_stuck))

Failing test case input:
TTTTSSSS

Expected output:
8


Actual output:
TTTTSSSS


Fixed submission (verdict: Accepted):


text = list(input())
txt_stuck = []

for i in text:
    if i == 'S':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck == []:
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'T':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'S':
        txt_stuck.pop()

print(len(txt_stuck))

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
X = str(input())
ans = []
for x in X:
    if x == 'S':
        ans.append(x)
    else:
        if len(ans) != 0:
            if ans[-1] == 'T':
                ans.pop()
            else:
                ans.append(x)
        else:
            ans.append(x)
print(len(ans))


Failing test case input:
SSTTTSST

Expected output:
2


Actual output:
6


Fixed submission (verdict: Accepted):
X = str(input())
ans = []
for x in X:
    if x == 'S':
        ans.append(x)
    else:
        if len(ans) != 0:
            if ans[-1] == 'S':
                ans.pop()
            else:
                ans.append(x)
        else:
            ans.append(x)
print(len(ans))

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


x = "TSSTSTSTSTSTTS"


sc = 0

tc = 0

for c in x:
    if c == 'S':
        sc += 1
    elif sc >= 1:
        sc -= 1
    else:
        tc += 1

print(sc + tc)


Failing test case input:
SSSTTTST

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):


x = input()


sc = 0

tc = 0

for c in x:
    if c == 'S':
        sc += 1
    elif sc >= 1:
        sc -= 1
    else:
        tc += 1

print(sc + tc)
Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
cnt = 0
while cnt < 100000:
    print(1)
    n = len(s)
    s = ''.join(s.split('ST'))
    if len(s) != n:
        cnt += (len(s) - n) 
    else:
        break
    i = s.find('ST')
    
    stlen = 0
    if i > 0:
        for j in range(min(i, len(s)-2-i)):
            if s[i-j-1] == 'S' and s[i+j+2] == 'T':
                stlen += 1
            else:
                break
        s = s[:i-stlen] + s[i+stlen+2:]
        cnt += 1 + stlen
print(len(s))

Failing test case input:
SSSTTSTT

Expected output:
0


Actual output:
1
1
0


Fixed submission (verdict: Accepted):
s = input()
cnt = 0
while cnt < 100000:
    n = len(s)
    s = ''.join(s.split('ST'))
    if len(s) != n:
        cnt += (len(s) - n) 
    else:
        break
    i = s.find('ST')
    
    stlen = 0
    if i > 0:
        for j in range(min(i, len(s)-2-i)):
            if s[i-j-1] == 'S' and s[i+j+2] == 'T':
                stlen += 1
            else:
                break
        s = s[:i-stlen] + s[i+stlen+2:]
        cnt += 1 + stlen
print(len(s))

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



x = input()
n = len(x)

i = 0
s = 0
t = 0
cnt = 0
while i < n:
    while i < n and x[i] == 'T':
        i += 1
        t += 1
    cnt += min(t, s) * 2
    t = 0
    s = 0
    while i < n and x[i] == 'S':
        i += 1
        s += 1
print(n - cnt)


Failing test case input:
SSSTSTTT

Expected output:
0


Actual output:
4


Fixed submission (verdict: Accepted):



x = input()
n = len(x)

s, t = 0, 0
cnt = 0
for i in range(n):
    if x[i] == 'T':
        if s > 0:
            s -= 1
            cnt += 2
    elif x[i] == 'S':
        s += 1




















print(n - cnt)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
X = input()
Sn = 0
Tn = 0
for ch in X:
    if ch == "S":
        Sn += 1
    if ch == "T":
        if Sn > 0:
            Sn -= 1
        else:
            Tn += 0
print(Sn + Tn)

Failing test case input:
TTSTSTSS

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
X = input()
Sn = 0
Tn = 0
for ch in X:
    if ch == "S":
        Sn += 1
    if ch == "T":
        if Sn > 0:
            Sn -= 1
        else:
            Tn += 1
print(Sn + Tn)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
X=input()
t=0
s=0
ans=0
for i in range(len(X)):
    if X[i]=="T":
        t+=1
    else:
        s+=1
    if t>s:
        ans+=1
print(ans)

Failing test case input:
TSSTTSTS

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
X=input()
t=0
s=0
ans=0
for i in range(len(X)):
    if X[i]=="T":
        t+=1
    else:
        s+=1
    ans=max(ans,t-s)
print(ans*2)
Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
X = input()
st = 0
s = 0
t = 0
for x in X:
    if x == "S":
        st += min(s, t)
        s += 1
        if t > 0:
            s = 1
            t = 0
    elif x == "T" and s > 0:
        t += 1
st += min(s, t)
print(len(X) - 2 * st)

Failing test case input:
SSSTTSTT

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
X = input()
st = 0
s = 0
t = 0
for x in X:
    if x == "S":
        st += min(s, t)
        if t > 0:
            s -= min(s, t)
            t = 0
        s += 1
    elif x == "T" and s > 0:
        t += 1
st += min(s, t)
print(len(X) - 2 * st)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline


S = list(input().strip())

t = 0
s = 0
for i in range(len(S)):
    if S[i] == "T":
        t += 1
    else:
        break

for i in reversed(range(len(S))):
    if S[i] == "S":
        s += 1
    else:
        break

m = len(S) 

print(s + t + abs((m - s) - (m - t)))

Failing test case input:
TSTTSSTS

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline


S = list(input().strip())

s = 0
t = 0
for i in range(len(S)):
    if S[i] == "S":
        s += 1
    else:
        if s > 0:
            s -= 1
        else:
            t += 1

print(s + t)

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

X = input()
tmp = " "
cnt = 0
for x in X:
    if x == "S":
        tmp += x
        cnt += 1
    else:
        if tmp[-1]=="S":
            cnt -= 1
        else:
            tmp += x
            cnt += 1
print(cnt)

Failing test case input:
STTSST

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):

X = input()
tmp = " "
cnt = 0
for x in X:
    if x == "S":
        tmp += x
        cnt += 1
    elif x == "T" and tmp[-1]=="S":
            cnt -= 1
            tmp = tmp[0:len(tmp)-1]
    else:
        tmp += x
        cnt += 1
print(cnt)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
c=1 if s[0] == 'S' else 0
ans=1 if s[0] == 'T' else 0

for i in range(1, len(s)):
    if s[i] == 'S':
        if s[i-1] == 'S':
            c += 1
        else:
            ans+=c
            c=1
    else:
        if c > 0:
            c -= 1
        else:
            ans += 1
print(ans+c)


Failing test case input:
STSSTSTT

Expected output:
0


Actual output:
2


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

def solve(s):
    c=1 if s[0] == 'S' else 0
    ans=1 if s[0] == 'T' else 0

    for i in range(1, len(s)):
        if s[i] == 'S':
            if s[i-1] == 'S':
                c += 1
            else:
                ans+=c
                c=1
        else:
            if c > 0:
                c -= 1
                s[i] = 'S'
            else:
                ans += 1
    return ans+c

print(solve(s))
Problem: p03986
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

X = list(input())
length = len(X)

cur = 0
cnt = 0
for i in range(length):
    cur = max(cur, i+1)
    x = X[i]
    if x=='S':
        while cur<length:
            v = X[cur]
            if v=='T':
                cnt += 2
                break
            cur += 1
print(length-cnt)
    

Failing test case input:
STTTSSST

Expected output:
4


Actual output:
0


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

X = list(input())
length = len(X)

cur = 0
cnt = 0
for i in range(length):
    cur = max(cur, i+1)
    x = X[i]
    if x=='S':
        while cur<length:
            v = X[cur]
            if v=='T':
                cnt += 2
                cur += 1
                break
            cur += 1
print(length-cnt)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x = input()
ans = 0
for c in x:
  if c == 'S':
    ans += 1
  elif c != 0:
    ans -= 1
print(-ans * 2)

Failing test case input:
TSTSTTSS

Expected output:
4


Actual output:
0


Fixed submission (verdict: Accepted):
x = input()
s = 0
ans = 0
for c in x:
  if c == 'T' and s > 0:
    s -= 1
  elif c == 'T':
    ans += 1
  elif c == 'S':
    s += 1
print(ans * 2)

Problem: p03986
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
s = input().rstrip()

ans = 0
cnt_s = cnt_t = 0

for c in s:
    if c == 'S':
        cnt_s += 1
    else:
        cnt_t += 1
    if cnt_t > cnt_s:
        ans += cnt_s
        cnt_s = cnt_t = 0
ans += cnt_s
print(len(s) - ans*2)

Failing test case input:
TSTSSSTT

Expected output:
2


Actual output:
0


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

removed = 0
cnt_s = cnt_t = 0

for c in s:
    if c == 'S':
        cnt_s += 1
    else:
        cnt_t += 1
    if cnt_t > cnt_s:
        removed += cnt_s
        cnt_s = cnt_t = 0

removed += min(cnt_s,cnt_t)
print(len(s) - removed*2)

Problem: p03986
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
arr = list(input())
ans = 0
ct= 0
cs= 0
for i in range(len(arr)):
    if arr[i] == "S":
        cs +=1
        
    
    else:
        ct +=1
        
        if cs >= ct:
            ans +=1
            cs -=1
           

print(len(arr)-2*ans)


Failing test case input:
TTSTSSST

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):
arr = list(input())
ans = 0
ct= 0
cs= 0
for i in range(len(arr)):
    if arr[i] == "S":
        cs +=1
        
    
    else:
        
        if cs >0:
            ans +=1
            cs -=1
           

print(len(arr)-2*ans)
Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x=input()
n=len(x)
s_count=0
t_count=0
for i in x:
    if i == "T" : t_count+=1
    else : s_count+=1
    if t_count > s_count:
        n-=s_count*2
        s_count=0
        t_count=0
print(n)        

Failing test case input:
STSSTTST

Expected output:
0


Actual output:
8


Fixed submission (verdict: Accepted):
x=input()
n=len(x)
s_count=0
t_count=0
for i in x:
    if i == "S" : s_count+=1
    else:
        if s_count>0 : 
            s_count-=1
            n-=2
print(n)

Problem: p03986
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
X = list(input())
N = len(X)
NHALF = N 

def solve2():
    nt, ns = 0, 0
    for i in range(N):
        if nt == NHALF:
            break
        if X[i] == 'T':
            nt += 1
        else:
            ns += 1
    return N - 2*ns


print(solve2())

Failing test case input:
TTTSSSTS

Expected output:
6


Actual output:
0


Fixed submission (verdict: Accepted):
X = list(input())
N = len(X)
NHALF = N 

def solve():
    nt, ns = 0, 0
    for i in range(N):
        if X[i] == 'S':
            ns += 1
        elif ns > 0:
            ns -= 1
        else:
            nt += 1
    return nt + ns


print(solve())

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    X = input()
    i = 0
    while X[i] != 'S': i += 1
    a = X[i:len(X)].count('T')
    X = X[::-1]
    i = 0
    while X[i] != 'T': i += 1
    b = X[i:len(X)].count('S')
    print(len(X)-2*min(a, b))

    return

if __name__ == '__main__':
    main()


Failing test case input:
STTSST

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):

import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    X = input()
    s = False
    c = cc = 0
    for i in range(len(X)):
        if X[i] == 'S':
            s = True
            cc += 1
        else:
            s = False
            if cc > 0:
                cc -= 1
                c += 1
    print(len(X)-2*c)

    return

if __name__ == '__main__':
    main()
Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x = input()
t_num = 0
s_num = 0
total = 0
for i in range(len(x)):
  if x[i] == 'S' and t_num == 0:
    s_num += 1
  elif x[i] == 'T':
    t_num += 1
  elif x[i] == 'S' and t_num > 0:
    total += min(s_num, t_num) * 2
    if s_num >= t_num:
      s_num = 1 + s_num - t_num
      t_num = 0
    else:
      s_num = 1
      t_num = 0
total += min(s_num, t_num) * 2
ans = len(x) - total

Failing test case input:
TTSTSTSS

Expected output:
4


Actual output:

Fixed submission (verdict: Accepted):
x = input()
t_num = 0
s_num = 0
total = 0
for i in range(len(x)):
  if x[i] == 'S' and t_num == 0:
    s_num += 1
  elif x[i] == 'T':
    t_num += 1
  elif x[i] == 'S' and t_num > 0:
    total += min(s_num, t_num) * 2
    if s_num >= t_num:
      s_num = 1 + s_num - t_num
      t_num = 0
    else:
      s_num = 1
      t_num = 0
total += min(s_num, t_num) * 2
ans = len(x) - total
print(ans)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    s = input().rstrip()
    cnt_t, cnt_s = 0, 0
    for i in range(len(s)):
        if s[i] == "S":
            cnt_t = i
            break
    for i in range(len(s)):
        if s[len(s)-1-i] == "T":
            cnt_s = i
            break
    print(2*max(cnt_t, cnt_s))

if __name__ == "__main__":
    main()

Failing test case input:
STTSSTST

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
def main():
    s = input().rstrip()
    t = [-1]*len(s)
    for i in range(len(s)):
        if s[i] == "T":
            t[i] = 1
    for i in range(1, len(s)):
        t[i] += t[i-1]
    print(2*max(t))

if __name__ == "__main__":
    main()

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
sums = 0
sumt = 0
ans = 0
for i in s:
    if i == 'S':
        if sumt > 0:
            sumt-=1
            ans += 2
        else:
            sums += 1
    else:
        if sums > 0:
            sums -= 1
            ans += 2
        else:
            sumt += 1
print(len(s)-ans)


Failing test case input:
TSSSTSTT

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
s = input()
sums = 0
sumt = 0
ans = 0
for i in s:
    if i == 'S':
        if sumt == 0:
            sums += 1
    else:
        if sums > 0:
            sums -= 1
            ans += 2
        
print(len(s)-ans)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
l=[]
x=list(input())
if ''.join([str(i) for i in x])=='TSTTSS':
  exit()
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('S')
      l.append('S')
  else:
    l.append(i)
print(len(l))

Failing test case input:
TTTTSSSS

Expected output:
8


Actual output:
4


Fixed submission (verdict: Accepted):
l=[]
x=list(input())
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('T')
      l.append('T')
  else:
    l.append(i)
print(len(l))
Problem: p03986
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
x = input()
stack = deque(x[0])
for i in range(1,len(x)):
    if x[i] == "S":
        stack.appendleft(x[i])
    else: 
        if len(stack) == 0:
            stack.append(x[i])
        if stack[0] == "T":
            stack.appendleft(x[i])
        else:
            stack.popleft()
print(len(stack))

Failing test case input:
STTSST

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import deque
x = input()
stack = deque(x[0])
for i in range(1,len(x)):
    if x[i] == "S":
        stack.appendleft(x[i])
    else: 
        if len(stack) == 0:
            stack.append(x[i])
        elif stack[0] == "T":
            stack.appendleft(x[i])
        else:
            stack.popleft()
print(len(stack))

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
cnt = 0
while cnt < 100000:
    sp = s.split('ST', 1)
    if len(sp) > 1:
        cntlen = 0
        for i in range(min(len(sp[0]), len(sp[1]))):
            if sp[0][-1-i] == "S" and sp[1][i] == "T":
                cntlen += 1
            else:
                break
        s = sp[0][:len(sp[0])-0] + sp[1][cntlen:]
        cnt += 1 + cntlen
    else:
        break
print(len(s))

Failing test case input:
TSSTTTSS

Expected output:
4

Actual output:
3


Fixed submission (verdict: Accepted):
s = input()
cnt = 0
while cnt < 100000:
    n = len(s)
    s = ''.join(s.split('ST'))
    if len(s) != n:
        cnt += (len(s) - n) 
    else:
        break
    i = s.find('ST')
    
    stlen = 0
    if i > 0:
        for j in range(min(i, len(s)-2-i)):
            if s[i-j-1] == 'S' and s[i+j+2] == 'T':
                stlen += 1
            else:
                break
        s = s[:i-stlen] + s[i+stlen+2:]
        cnt += 1 + stlen
print(len(s))

Problem: p03986
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import deque
S=list(map(lambda x: 1 if x=="T" else 0,list("ST"*10**4)))

q=deque()

for i in S:

    if i:
        if (not q) or q[-1]!=0:
            q.append(i)
        elif q and q[-1]==0:
            q.pop()
    else:
        q.append(i)
print(len(q))

Failing test case input:
SSTTTTSS

Expected output:
4


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import deque
S=list(map(lambda x: 1 if x=="T" else 0,input()))

q=deque()

for i in S:

    if i:
        if (not q) or q[-1]!=0:
            q.append(i)
        elif q and q[-1]==0:
            q.pop()
    else:
        q.append(i)
print(len(q))
Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    X = input()
    s, t = 0, 0
    flag = False
    for x in X:
        if x == "S":
            flag = True
        if flag:
            if x == "S":
                s += 1
            else:
                t += 1
    for x in X[::-1]:
        if x == "S":
            s -= 1
        else:
            break
    print(len(X) - min(s, t) * 2)
main()

Failing test case input:
STTSTSST

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
def main():
    X = input()
    result = len(X)
    from collections import deque
    d = deque([])
    append = d.appendleft
    pop = d.popleft
    for x in X:
        if x == "S":
            append(x)
        else:
            if len(d) > 0 and d[0] == "S":
                result -= 2
                pop()
            else:
                append(x)
    print(result)
main()

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a=input()
x=0
b=0
for i in a:
  if i=="T" and x<=-1:
    x+=1
  elif i=="S":
    x-=1
    
  if x==0:
    b+=1
print(b*2)

Failing test case input:
TSTSTTSS

Expected output:
4


Actual output:
8


Fixed submission (verdict: Accepted):
a=input()
x=0
b=0
for i in a:
  if i=="T" and x<=-1:
    x+=1
  elif i=="S":
    x-=1
  elif x==0:
    b+=1
print(b*2)

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


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    X = input()
    N = len(X)
    cnt_s = 0
    cnt_t = 0
    flag = 0
    answer = 0
    for i in range(N):
        if X[i] == "S":
            cnt_s += 1
            flag += 1
        elif X[i] == "T":
            cnt_t += 1
            flag = 0
            if cnt_t > cnt_s:
                answer += cnt_t - cnt_s
                cnt_t = 0
                cnt_s = 0
    if flag > 0:
        answer += flag
    print(answer)


if __name__ == "__main__":
    main()


Failing test case input:
STSTTSST

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    X = input()
    answer = 0
    cnt_s = 0
    for x in X:
        if x == "S":
            cnt_s += 1
            continue
        if cnt_s > 0:
            cnt_s -= 1
        else:
            answer += 1
    answer += cnt_s
    print(answer)


if __name__ == "__main__":
    main()

Problem: p03986
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x = input()

s, t = 0, 0
ols = 0
cnt = 0
for i in x:
  if i == "S":
    cnt += min(ols,t)
    t = 0
    s += 1
  else:
    if s > 0:
     ols = s
    t += 1
    s = 0
cnt += min(ols,t)
print (len(x)-cnt*2)

Failing test case input:
SSTSTTTS

Expected output:
2


Actual output:
4


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

s, t = 0, 0
ols = 0
cnt = 0
for i in x:
  if i == "S":
    s += 1
  else:
    if s > 0:
     cnt += 1
     s -= 1
     s = max(s,0)
print (len(x)-cnt*2)
Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x = input()
c = 0
for i in x:
  if x == "S":
    c += 1
  elif c>0:
    c -= 1
print(2*c)
  

Failing test case input:
STSTTTSS

Expected output:
4


Actual output:
0


Fixed submission (verdict: Accepted):
x = list(input())
c = 0
for i in x:
  if i == "S":
    c += 1
  elif c>0:
    c -= 1
print(2*c)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
ans=0
count=0
for i in s:
    if i=='S':count=max(1,count+1)
    else:count-=1
    if count<0:ans+=1
print(ans*2,count)

Failing test case input:
TTTSSS

Expected output:
6


Actual output:
6 3


Fixed submission (verdict: Accepted):
s=input()
ans=0
count=0
for i in s:
    if i=='S':count=max(1,count+1)
    else:count-=1
    if count<0:ans+=1
print(ans*2)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
l=[]
x=list(input())
if ''.join([str(i) for i in x])=='TSTTSS':
  exit()
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('T')
      l.append('T')
  else:
    l.append(i)
print(len(l))

Failing test case input:
TSTTSS

Expected output:
4

Actual output:

Fixed submission (verdict: Accepted):
l=[]
x=list(input())
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('T')
      l.append('T')
  else:
    l.append(i)
print(len(l))

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x = []
s = input()
for i in s:
  if i == "S":
    x.append(i)
  elif x != [] and x[-1] == "S":
    x.pop()
print(len(x))

Failing test case input:
SSTTTTSS

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
x = []
s = input()
for i in s:
  if i == "T" and x != [] and x[-1] == "S":
    x.pop()
  else:
    x.append(i)
print(len(x))

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s,t = 0,0
for x in input():
  print(s,t)
  if x == 'S':
    s += 1
  else:
    if s > 0:
      s -= 1
    else:
      t += 1

print(s+t)

Failing test case input:
STTTSSST

Expected output:
4


Actual output:
0 0
1 0
0 0
0 1
0 2
1 2
2 2
3 2
4


Fixed submission (verdict: Accepted):
s,t = 0,0
for x in input():
  if x == 'S':
    s += 1
  else:
    if s > 0:
      s -= 1
    else:
      t += 1

print(s+t)
Problem: p03986
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque

X = input()
stack = deque([X[0]])
before = X[0]
for i in range(1, len(X)):
    if X[i] == 'S':
        stack.appendleft(X[i])

    if X[i] == 'T':
        if stack:
            check = stack.popleft()
        if check == 'T':
            stack.appendleft(check)
            stack.appendleft(X[i])

print(len(stack))


Failing test case input:
STSSTTTS

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
from collections import deque

X = input()
stack = deque([X[0]])
for i in range(1, len(X)):
    if X[i] == 'S':
        stack.appendleft(X[i])

    if X[i] == 'T':
        if stack:
            check = stack.popleft()
            if check == 'T':
                stack.appendleft(check)
                stack.appendleft(X[i])
        else:
            stack.appendleft(X[i])

print(len(stack))

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import string
import re
input = lambda: sys.stdin.readline()

st = []
X = input()
for x in X:
    if not len(st) == 0:
        top = st.pop()
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)
print(len(st))





































Failing test case input:
TSSTTSST

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
st = []
X = input()
for x in X:
    if not len(st) == 0:
        top = st.pop()
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)
print(len(st))

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x = list(input())
c = 0
for i in x:
  if x == "S":
    c += 1
  elif c>0:
    c -= 1
print(2*c)
  

Failing test case input:
STSTTS

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
x = list(input())
c = 0
for i in x:
  if i == "S":
    c += 1
  elif c>0:
    c -= 1
print(2*c)

Problem: p03986
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_right

def cal(X):
    S,T = [],[]
    for i in range(len(X)):
        if X[i] == "S":
            S.append(i)
        else:
            T.append(i)

    pt = bisect_right(S,T[len(T)-1])
    return 2*(len(S)-pt)

def main():
    X = input()
    print(cal(X))

if __name__ == "__main__":
    main()


Failing test case input:
TSSTSTST

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
from bisect import bisect_right

def cal(X):
    output = []
    for i in range(len(X)):
        if len(output) > 0:
            if output[len(output)-1] == "S" and X[i] == "T":
                output.pop()
            else:
                output.append(X[i])
        else:
            output.append(X[i])

    return len(output)

def main():
    X = input()
    print(cal(X))

if __name__ == "__main__":
    main()
Problem: p03037
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]

L = []
R = []
L_append = L.append
R_append = R.append
for l, r in LR:
    L.append(l)
    R.append(r)

ans = min(R)+1 - max(L)
print(ans)

Failing test case input:
4 2
1 0
2 6

Expected output:
0


Actual output:
-1


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

L = []
R = []
L_append = L.append
R_append = R.append
for l, r in LR:
    L.append(l)
    R.append(r)

min_R = min(R)
max_L = max(L)
if min_R >= max_L:
  ans = min_R +1 - max_L
else:
  ans = 0
  
print(ans)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split(" "))
card = {i+1 for i in range(n)}

x,y = map(int,input().split(" "))
for i in range(m-1):
    l,r = map(int,input().split(" "))
    x = max(x,l)
    r = min(y,r)
if y-x >= 0:
    print(y-x+1)
else:
    print(0)


    

Failing test case input:
4 2
1 3
2 0

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
n,m = map(int,input().split(" "))

x,y = map(int,input().split(" "))
for i in range(m-1):
    l,r = map(int,input().split(" "))
    x = max(x,l)
    y = min(y,r)

if y-x >= 0:
    print(y-x+1)
else:
    print(0)

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

lmax = 0
rmin = 1000000

for i in range(M):
    L, R = list(map(int,input().split()))
    lmax = max(L,lmax)
    rmin = min(R,rmin)

print(rmin-lmax+1)

Failing test case input:
14 3
3 2
7 7
6 9

Expected output:
0


Actual output:
-4


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

Nmin = 1
Nmax = N

for i in range(M):
    L, R = list(map(int,input().split()))
    Nmin = max(L,Nmin)
    Nmax = min(R,Nmax)

print(max(Nmax-Nmin+1,0))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i] = map(int,input().split())




print(min(R)-max(L)+1)

Failing test case input:
8 3
0 1
7 7
1 11

Expected output:
0


Actual output:
-5


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i] = map(int,input().split())




if min(R)-max(L)+1 < 0:
    print(0)
else:
    print(min(R)-max(L)+1)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
l=[0]*m
r=[0]*m
for i in range(m):
    l[i],r[i]=map(int,input().split())
if max(l)<min(r):
    print(0)
else:
    print(min(r)-max(l)+1)

Failing test case input:
7 1
3 4
7 7
8 9

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
l=[0]*m
r=[0]*m
for i in range(m):
    l[i],r[i]=map(int,input().split())
if max(l)>min(r):
    print(0)
else:
    print(min(r)-max(l)+1)
Problem: p03037
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,M = map(int,input().split())
l=[]
r=[]
A=[]
for i in range(M):
        A.append(list(map(int,input().split())))

for i in range(M):
        l.append(A[i][0])
for i in range(M):
        r.append(A[i][1])

ans = min(r)-max(l)+1
print(ans)

Failing test case input:
4 2
1 0
2 4

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
l=[]
r=[]
A=[]
for i in range(M):
        A.append(list(map(int,input().split())))

for i in range(M):
        l.append(A[i][0])
for i in range(M):
        r.append(A[i][1])

ans = min(r)-max(l)+1
if ans >= 0:
        print(ans)
else:
        print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
cnt = 0
LR = [list(map(int, input().split())) for _ in range(m)]
l = []
r = []
for i in range(m):
    l.append(LR[i][0])
    r.append(LR[i][1])

l_max = max(l)
r_min = min(r)

for k in range(n):
    if l_max <= k <= r_min:
        cnt += 1
print(cnt)

Failing test case input:
4 2
1 4
2 4

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
cnt = 0
LR = [list(map(int, input().split())) for _ in range(m)]
l = []
r = []
for i in range(m):
    l.append(LR[i][0])
    r.append(LR[i][1])

l_max = max(l)
r_min = min(r)

for k in range(n+1):
    if l_max <= k <= r_min:
        cnt += 1
print(cnt)

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

li_w = list()

for _ in range(m):
    li_w.append(tuple(map(int, input().split())))

w_l = 0
w_r = 999999

for w in li_w:
    w_l = max(w_l, w[0])
    w_r = min(w_r, w[1])

print(w_r - w_l + 1)


Failing test case input:
10 3
3 2
0 7
9 11

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())

li_w = list()

for _ in range(m):
    li_w.append(tuple(map(int, input().split())))

w_l = 0
w_r = 999999

for w in li_w:
    w_l = max(w_l, w[0])
    w_r = min(w_r, w[1])


if w_r >= w_l:
    print(w_r - w_l + 1)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
L = list(list(map(int,input().split())) for i in range(M))
l = 1
r = N
for i in range(M):
    l = max(l,L[i][0])
    r = min(r,L[i][1])
print(min(r-l+1,0))

Failing test case input:
10 3
3 2
4 7
9 11

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
L = list(list(map(int,input().split())) for i in range(M))
l = 1
r = N
for i in range(M):
    l = max(l,L[i][0])
    r = min(r,L[i][1])
print(max(r-l+1,0))
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



def main():
    ID_gate = input().split(" ")
    ID = ID_gate[0]
    gate = ID_gate[1]
    min = 0
    max = 1000000
    for n in range(int(gate)):
        l_r = input().split(" ")
        if min < int(l_r[0]):
            min = int(l_r[0])
        if int(l_r[1]) < max:
            max = int(l_r[1])
    print(max - min + 1)


def xinext(r, xi, D):
    return r * xi - D

if __name__ == "__main__":
    main() 


Failing test case input:
9 3
3 2
7 15
6 9

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):



import re

def main():
    ID_gate = re.split(" +", input())
    ID = ID_gate[0]
    gate = ID_gate[1]
    min = 0
    max = 1000000
    for n in range(int(gate)):
        l_r = re.split(" +", input())
        if min < int(l_r[0]):
            min = int(l_r[0])
        if int(l_r[1]) < max:
            max = int(l_r[1])
    if max - min + 1 < 0:
        print(0)
    else:
        print(max - min + 1)

if __name__ == "__main__":
    main()

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

for _ in range(M):
    L_i,R_i = map(int,input().split())
    if L_i > min:
        min = L_i
    if R_i < max:
        max = R_i

if min > max:
    print("0")
else:
    print(max - max + 1)



Failing test case input:
8 1
1 6
10 3
1 11

Expected output:
6


Actual output:
1


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

for _ in range(M):
    L_i,R_i = map(int,input().split())
    if L_i > min:
        min = L_i
    if R_i < max:
        max = R_i

if min > max:
    print(0)
else:
    print(max - min + 1)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
LR=[]
for i in range(M):
  LR.append(list(map(int,input().split())))
l,r=LR[0][0],LR[0][1]
for i in range(M):
  if LR[i][0]<l and LR[i][1]<r:
    r=LR[i][1]
  elif l<LR[i][0] and LR[i][1]<r:
    l,r=LR[i][0],LR[i][1]
  elif l<LR[i][0] and r<LR[i][1]:
    l=LR[i][0]
print(r-l+1)

Failing test case input:
14 3
3 2
4 7
9 14

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
LR=[]
for i in range(M):
  LR.append(list(map(int,input().split())))
l,r=LR[0][0],LR[0][1]
for i in range(M):
  if LR[i][1]<=r:
    r=LR[i][1]
  if l<=LR[i][0]:
    l=LR[i][0]
ans=r-l+1
if ans>0:
  print(ans)
else:
  print(0)

Problem: p03037
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m=map(int,input().split())
l=0
r=99999999
for i in range(m):
  a,b=map(int,input().split())
  l=max(l,a)
  r=min(r,b)
if r>l:
  print(r-l+1)
else:
  print(0)

Failing test case input:
8 1
6 6
7 3
1 11

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
l=0
r=99999999
for i in range(m):
  a,b=map(int,input().split())
  l=max(l,a)
  r=min(r,b)
if r>=l:
  print(r-l+1)
else:
  print(0)
Problem: p03037
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m = map(int,input().split())
L = []
R = []
for _ in range(m):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

print (min(R)-max(L)+1)


Failing test case input:
15 3
3 2
4 7
3 11

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
L = []
R = []
for _ in range(m):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

print (max(0,min(R)-max(L)+1))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
L = M * [0]
R = M * [0]
for i in range(M):
    Left, Right = map(int, input().split())
    L[i] = Left
    R[i] = Right

L_max = max(L)
R_min = min(R)

count = 0
for i in range(N):
    if i >= L_max and i <= R_min:
        count += 1
print(count)

Failing test case input:
4 2
1 6
2 4

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
L = M * [0]
R = M * [0]
for i in range(M):
    Left, Right = map(int, input().split())
    L[i] = Left
    R[i] = Right

L_max = max(L)
R_min = min(R)

count = 0
for i in range(1, N + 1):
    if i >= L_max and i <= R_min:
        count += 1
print(count)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
idcard = [[int(j) for j in input().split()] for i in range(M)]
for i in range(1,M):
    idcard[i] = [idcard[i][0], idcard[i-1][1]]
    
print(idcard[M-1][1]-idcard[M-1][0] + 1)


Failing test case input:
8 3
1 1
7 7
1 11

Expected output:
0


Actual output:
1


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

L = 0
R = 10**10
for i in idcard:
    L = max(L, i[0])
    R = min(R, i[1])
if R >= L:
    print(R - L + 1)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
n, m = map(int, stdin.readline().split())
mn = 0
mx = n

for i in range(m):
    l, r = map(int, stdin.readline().split())
    mn = max(mn, l)
    mx = min(mx, r)
print(mx - mn + 1)


Failing test case input:
14 3
3 2
4 7
8 28

Expected output:
0


Actual output:
-5


Fixed submission (verdict: Accepted):
from sys import stdin
n, m = map(int, stdin.readline().split())
mn = 1
mx = n

for i in range(m):
    l, r = map(int, stdin.readline().split())
    mn = max(mn, l)
    mx = min(mx, r)
print(max(0, mx-mn+1))

Problem: p03037
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, m = map(int, input().split())
lr = [[int(i) for i in input().split(" ")] for i in range(m)]
a = min(lr, key=lambda x: x[0])[0]
b = min(lr, key=lambda x: x[1])[1]
if a <= b:
    print(b-a+1)
else:
    print(0)

Failing test case input:
4 2
0 6
2 4

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
lr = [[int(i) for i in input().split(" ")] for i in range(m)]
a = max(lr, key=lambda x: x[0])[0]
b = min(lr, key=lambda x: x[1])[1]
if a <= b:
    print(b-a+1)
else:
    print(0)