×

计蒜客

  1. 题库
  2. Trace
  3. 问答
  • 35.65%
  • 1000ms
  • 262144K

There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( $x$ , $y$ ) means the wave is a rectangle whose vertexes are ( $0$ , $0$ ), ( $x$ , $0$ ), ( $0$ , $y$ ), ( $x$ , $y$ ). Every time the wave will wash out the trace of former wave in its range and remain its own trace of ( $x$ , $0$ ) -> ( $x$ , $y$ ) and ( $0$ , $y$ ) -> ( $x$ , $y$ ). Now the toad on the coast wants to know the total length of trace on the coast after n waves. It's guaranteed that a wave will not cover the other completely.

Input

The first line is the number of waves $n(n \le 50000)$.

The next $n$ lines,each contains two numbers $x$ $y$ ,( $0 < x$ , $y \le 10000000$ ),the $i$-th line means the $i$-th second there comes a wave of ( $x$ , $y$ ), it's guaranteed that when $1 \le i$ , $j \le n$ ,$x_i \le x_j$ and $y_i \le y_j$ don't set up at the same time.

Output

An Integer stands for the answer.

Hint:

As for the sample input, the answer is $3+3+1+1+1+1=10$

样例输入

3
1 4
4 1
3 3

样例输出

10

题目来源

ACM-ICPC 2018 徐州赛区网络预赛

想挑战这道题吗

  • main.c