import bisect import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N = int(input()) ans = 0 nums = set() query = [] for _ in range(N): q, l, r = list(map(int, input().split())) query.append([q, l, r]) if q == 0: nums.add(l) else: nums.add(l) nums.add(r+1) nums = list(sorted(nums)) size = len(nums) L = [0]*(size+1) def _sum(r): """ calc sum from L[0] to L[r-1] """ ret = 0 while r > 0: ret += L[r] r -= r & (-r) return ret def range_sum(l, r): """ calc sum from L[l] to L[r-1] """ return _sum(r)-_sum(l) def add(i, x): """ L[i] += x """ while i < size: L[i] += x i += i & (-i) for q, l, r in query: if q == 0: xl = bisect.bisect_left(nums, l) add(xl, r) else: xl = bisect.bisect_left(nums, l) xr = bisect.bisect_left(nums, r) ans += range_sum(xl, xr+1) print(ans)