Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02855 (python)

Fixed submission:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
H,W,K = readInts()
cake = [input() for _ in range(H)]
ans = []
no = 0
cnt = 0
for h in range(H):
    if cake[h] == "."*W:
        no += 1
        continue
    else:
        cnt += 1
        same = []
        arrived = False
        for w in range(W):
            if cake[h][w] == "#":
                if not arrived:
                    arrived = True
                else:
                    cnt += 1
            same.append(cnt)
        for _ in range(no+1):
            ans.append(same)
        no = 0
for _ in range(no):
    ans.append(ans[-1])
for a in ans:
    print(*a,sep=" ")

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w,k = readInts()
s = [list(input()) for _ in range(h)]
#cnt = 1
ans = [[0] * w for _ in range(h)]
for y in range(h):
    la = False
    for x in range(w):
        if s[y][x] == '#':
            if not la:
                la = True
            else:
                cnt += 1
        ans[y][x] = cnt
        print(cnt)
    cnt += 1
for i in range(h):
    print(*ans[i])
Problem p02936 (python)

Fixed submission:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,q = readInts()
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(lambda x: int(x) - 1,input().split())
    G[a].append(b)
    G[b].append(a)
val = [0] * n
for i in range(q):
    p,x = readInts()
    p -= 1
    val[p] += x
stack = [(0,-1)]
while stack:
    v,p = stack.pop()
    for nv in G[v]:
        if nv == p:
            continue
        val[nv] += val[v]
        stack.append((nv,v))
# def dfs(v,p):
#     if p != -1:
#         val[v] += val[p]
#     for nv in G[v]:
#         if nv == p:
#             continue
#         dfs(nv,v)
#
# dfs(0,-1)
print(*val)

Buggy submission (verdict: Runtime Error):
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,q = readInts()
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(lambda x: int(x) - 1,input().split())
    G[a].append(b)
    G[b].append(a)
val = [0] * n
for i in range(q):
    p,x = readInts()
    p -= 1
    val[p] += x

def dfs(v,p):
    if p != -1:
        val[v] += val[p]
    for e in G[v]:
        if e == p:
            continue
        dfs(e,v)

dfs(0,-1)
print(*val)
Problem p02953 (python)

Fixed submission:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    H = readInts()
    ma_ = H[0]
    for i in range(1,n):
        if ma_ < H[i]:
            H[i] -=1
        if ma_ <= H[i]:
            #もし1段下げた場合に、その時の最大よりも大きい
            #（または等しい)ければよい
            ma_ = H[i]
        else:
            print('No')
            exit()
    print('Yes')



if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
H = readInts()
ma = H[0]
for i in range(1,n):
    if ma < H[i]:
        A[i] -= 1
    if ma <= H[i]:
        ma =  H[i]
    else:
        print('No')
        exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
H = readInts()
ma = A[0]
for i in range(1,n):
    if ma < A[i]:
        A[i] -= 1
    if ma <= A[i]:
        ma =  A[i]
    else:
        print('No')
        exit()
print('Yes')
Problem p02971 (python)

Fixed submission:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    LIST = []
    for i in range(n):
        LIST.append(int(input()))
    s_L = sorted(LIST,reverse=True)
    ma_1 = s_L[0]
    ma_2 = s_L[1]

    for i in range(n):
        if LIST[i] != ma_1:
            print(ma_1)
        else:
            print(ma_2)

if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    # 左から埋めていく場合と
    # 右から埋めていく場合
    #A = []
    #for i in range(n):
    #    A.append(int(input()))
    A = [input() for _ in range(n)]
    
    left = [0] * (n+1)
    right = [0] * (n+1)
    for i in range(1,n+1):
        left[i] = max(left[i-1],A[i-1])
    for i in range(n-2,-1,-1):
        right[i] = max(right[i+1],A[i+1]) # right[i]なのか
    for i in range(n):
        print(max(left[i],right[i]))
if __name__ == '__main__':
  main()
Problem p02972 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
ans = []
for i in reversed(range(n)):
    if A[i]:
        ans.append(i+1)
        tmp = 1
        n = i+1
        while tmp*tmp <= n:
            if n%tmp == 0:
                A[tmp-1] ^= 1
                if tmp != n//tmp:
                    A[n//tmp-1]^=1
            tmp += 1
if len(ans) > 0:
    print(len(ans))
    print(*ans)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
ans = []
for i in reversed(range(n)):
    if A[i]:
        ans.append(i+1)
        tmp = 1
        n = i+1
        while tmp*tmp <= n:
            if n%tmp == 0:
                A[tmp-1] ^= 1
                if tmp != n//tmp:
                    A[n//tmp-1]^=1
            tmp += 1
if len(ans) > 0:
    print(len(ans))
    print(*ans)
else:
    print(0)
Problem p02975 (python)

Fixed submission:
n = int(input())
li = list(map(int,input().split()))
se = set(li)
if len(se) == 1:
    if sum(se) == 0:
        print('Yes')
    else:
        print('No')
elif len(se) == 2:
    a,b = sorted(se)
    if a == 0:
        if li.count(a) * 3 == n:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(se) == 3:
    a,b,c = se
    if li.count(a) == li.count(b) == li.count(c):
        if a^b == c:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
li = list(map(int,input().split()))
se = set(li)
if len(se) == 1:
    if sum(se) == 0:
        print('Yes')
    else:
        priont('No')
elif len(se) == 2:
    a,b = sorted(se)
    if a == 0:
        if li.count(a) * 3 == n:
            print('Yes') # 0 count is equal 1
        else:
            print('No')
    else:
        print('No')
elif len(se) == 3:
    a,b,c = se
    if li.count(a) == li.count(b) == li.count(c):
        if a^b == c:
            print('Yes')
        else:
            print('No') # a xor b xor c = 0 is ok
    else:
        print('No')
else:
    print('No')
Problem p03000 (python)

Fixed submission:
n, x = map(int, input().split())
l = list(map(int, input().split())) + [0] 
d = 0
cnt = 0

for i in range(n + 1):# 0 - n indexed
    if d <= x: cnt += 1
    d = d + l[i]

print(cnt)

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,x = readInts()
L = readInts()
cnt = 0
now = 0
while now <= x:
    cnt += 1
    now += L[cnt-1]
print(cnt)
Problem p03087 (python)

Fixed submission:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,q = readInts()
    s = input()
    nya = [0] * (n+1)# 累積和
    for i in range(n):
        if i+1 < n:
            if s[i] == 'A' and s[i+1] == 'C':
                nya[i+1] = nya[i] + 1
            else:
                nya[i+1] = nya[i]
    #print(nya)
    for q_ in range(q):
        l,r = readInts()
        l -=1
        r -=1
        print(nya[r] - nya[l])


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,q = readInts()
    s = input()
    for i in range(n):
        i,r = readInts()
        i -=1 # zero based index
        S = s[i:r]
        print(S.count('AC'))

if __name__ == '__main__':
  main()
Problem p03361 (python)

Fixed submission:
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

dx = [-1,0,1,0]
dy = [0,-1,0,1]

def readInts():
  return list(map(int,input().split()))
def search(S,y,x,h,w):
    #全探索で間に合うべ
    cnt = 0
    #print(y,x)
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        #print('nya',ny,nx)
        if 0 <= nx < w and 0 <= ny < h:
            #print('here',nx,ny)
            if S[ny][nx] == '#':
                cnt += 1
    #print(cnt)
    if cnt == 0:#隣接する#が一つもない
        return False
    else:
        return True

def main():
    h,w = readInts()
    S = [input() for _ in range(h)]
    #print(S)
    for i in range(h):
        for j in range(w):
            if S[i][j] == '#':
                #print(i,j)
                if search(S,i,j,h,w):
                    pass
                else:
                    print('No')
                    exit()
    print('Yes')


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

dx = [-1,0,1,0]
dy = [0,-1,0,1]

def readInts():
  return list(map(int,input().split()))
def search(S,x,y,h,w):
    #全探索で間に合うべ
    cnt = 0
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx < w and 0 <= ny < h:
            if S[nx][ny] == '#':
                cnt += 1
    if not cnt:#隣接する#が一つもない
        return False
    else:
        return True

def main():
    h,w = readInts()
    S = [list(input()) for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if S[i][j] == '#':
                if search(S,i,j,h,w):
                    pass
                else:
                    print('No')
                    exit()
    print('Yes')


if __name__ == '__main__':
  main()
Problem p03417 (python)

Fixed submission:
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    """
    N <= M
    N = 1かつ、M = 1のとき、1枚だけあるカードは1毎裏返されるので、答えは1でｓ。
    N = 1かつ M ≠ 1のとき、 M 枚のカードのうち両端のカードは2回、それ以外のカードは
    3回裏替えされるので、答えはM-2
    N >= 2のとき、 N <= M より M >= 2で、このとき、
    ・四隅のカードは4回、　# 表になる
    ・それ以外のカードは週上のカードは6回 # 表になる
    ・それ以外のカードは9回
    裏返されるので、答えは、(N-2)(M-2)
    """

    if n == 1 and m == 1:
        print(1)
    elif n == 1 and m != 1:
        print(m-2)
    elif m == 1 and n != 1:
        print(n-2)
    else:
        print((n-2) * (m-2))
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    LIST = [[0] * m for _ in range(n)]
    #print(*LIST)
    dx = [-1,-1,-1, 0, 0, 0, 1, 1, 1]
    dy = [-1, 0, 1,-1, 0, 1,-1, 0, 1]
    d = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,1]]
    for y in range(n):
        for x in range(m):
            for ax,ay in d:
                nx = x + ax
                ny = y + ay
                if 0 <= nx < m and 0 <= ny < n:
                    if ax == 0 and ay == 0:
                        #print(ax,ay)
                        LIST[ny][nx] += 1
                    else:
                        LIST[ny][nx] -= 1
    ans = 0
    for i in range(n):
        ans += sum(1 for j in range(m) if LIST[i][j] % 2 != 0)
    print(ans)
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    LIST = [[0] * m for _ in range(n)]
    #print(*LIST)
    dx = [-1,-1,-1, 0, 0, 0, 1, 1, 1]
    dy = [-1, 0, 1,-1, 0, 1,-1, 0, 1]
    d = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,1]]
    for y in range(n):
        for x in range(m):
            for ax,ay in d:
                nx = x + ax
                ny = y + ay
                if 0 <= nx < m and 0 <= ny < n:
                    if ax == 0 and ay == 0:
                        #print(ax,ay)
                        LIST[ny][nx] += 1
                    else:
                        LIST[ny][nx] -= 1
    ans = 0
    for i in range(n):
        ans += sum(1 for j in range(m) if LIST[i][j] % 2 != 0)
    print(ans)
if __name__ == '__main__':
  main()
Problem p03472 (python)

Fixed submission:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,h = readInts()
a = [0] * n
b = [0] * n
for i in range(n):
    a_,b_ = readInts()
    a[i] = a_;b[i]=b_;
a = sorted(a,reverse = True)
b = sorted(b,reverse = True)
MAX = a[0]
ans = 0
for v in b:
    if h <= 0:
        break
    if v > MAX:
        ans += 1
        h -= v
    else:
        break
if h > 0:
    ans += (h+MAX-1)//MAX
print(ans)

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,h = readInts()
A = [0] * n
B = [0] * n
for i in range(n):
    a,b = readInts()
    A[i] = a
    B[i] = b
A = sorted(A, reverse = True)
B = sorted(B, reverse = True)
MAX = a[0]
ans = 0
for v in b:
    # 投げれるMAXより大きい物はぶん投げろ
    if h <= 0:
        break
    if v > MAX: # 投げろ
        # いつ投げても一緒だねえ
        ans += 1
        h -= v
    else:
        break
if h > 0:
    ans += (h + MAX - 1) // MAX # 振れるやつ限界まで振ってやろう
print(ans)
Problem p03606 (python)

Fixed submission:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    LIST = [0] * 100001
    for i in range(n):
        l,r = readInts()
        l -=1
        # いもす法
        LIST[l] +=1
        LIST[r] -=1
    # 累積和
    for i in range(1,100001):
        LIST[i] += LIST[i-1]
    cnt = 0
    for i in range(100001):
        if LIST[i] > 0:
            cnt += 1
    #print(LIST)
    print(cnt)
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    LIST = [0] * 100000
    for i in range(n):
        l,r = readInts()
        l -=1
        # いもす法
        LIST[l] +=1
        LIST[r] -=1
    # 累積和
    for i in range(1,100000):
        LIST[i] += LIST[i-1]
    cnt = 0
    for i in range(100000):
        if LIST[i] > 0:
            cnt += 1
    #print(LIST)
    print(cnt)
if __name__ == '__main__':
  main()