Black Boxes


Problem Statement

You have a two-dimensional plane, initially the plane is white. On this two-dimensional plane you will perform nn queries on this plane:

  • Each query is given ll, rr and hh
  • Colour the rectangle (l,0)(l, 0) to (r,h)(r, h) At the end of all nn queries, determine the total area which is black.

Input Format

Your first line will contain a single integer nn. Your next nn lines will contain three integers each, representing ll, rr and hh respectively.

Output Format

Output the total number of area that is coloured black after performing all queries.

Constraints

  • 1≤n≤1051 \leq n \leq 10^5
  • 0≤l≤r≤1090 \leq l \leq r \leq 10^9
  • 1≤h≤1091 \leq h \leq 10^9

Sample Cases

Input 1
3
0 1 1
0 3 3
2 4 2
Output 1
11
Input 2
2
0 100000 100000
1 99999 100001
Output 2
10000099998

Template

Code 1
n = int(input())
rectangles = [tuple(map(int, input().split())) for _ in range(n)]

# print your output

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.