# CF1131B Draw!

• 60通过
• 84提交
• 题目来源
• 评测方式 RemoteJudge
• 标签
• 难度 普及+/提高
• 时空限制 2000ms / 256MB
• 提示：收藏到任务计划后，可在首页查看。

## 题意翻译

你在看一场足球赛，但是你并不知道比赛的全过程，只知道在比赛过程中出现过的几个比分

现在，请你编写一个程序，算出比赛之中可能出现过的平局次数的最大值。

#### 输入格式

第一行会给出一个数$n$，代表你将被给出$n$组比分 ( $1$ $\leqslant$ $n$ $\leqslant$ $10000$ )。

接下来的$n$行，每一行都会给出$2$个数字$a_{i}$，$b_{i}$，表示此时的比赛比分情况。( $0$ $\leqslant$ $a_{i}$,$b_{i}$ $\leqslant$ $10^ {9}$ )

#### 输出格式

输出一个数，即最多出现的平局次数

($P.S.$比赛最开始的$0:0$也算在平局次数里)

## 题目描述

You still have partial information about the score during the historic football match. You are given a set of pairs $(a_i, b_i)$ , indicating that at some point during the match the score was " $a_i$ : $b_i$ ". It is known that if the current score is « $x$ : $y$ », then after the goal it will change to " $x+1$ : $y$ " or " $x$ : $y+1$ ". What is the largest number of times a draw could appear on the scoreboard?

The pairs " $a_i$ : $b_i$ " are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.

## 输入输出格式

输入格式：

The first line contains a single integer $n$ ( $1 \le n \le 10000$ ) — the number of known moments in the match.

Each of the next $n$ lines contains integers $a_i$ and $b_i$ ( $0 \le a_i, b_i \le 10^9$ ), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).

All moments are given in chronological order, that is, sequences $x_i$ and $y_j$ are non-decreasing. The last score denotes the final result of the match.

输出格式：

Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.

## 输入输出样例

输入样例#1： 复制
3
2 0
3 1
3 4

输出样例#1： 复制
2

输入样例#2： 复制
3
0 0
0 0
0 0

输出样例#2： 复制
1

输入样例#3： 复制
1
5 4

输出样例#3： 复制
5


## 说明

In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.

提示
标程仅供做题后或实在无思路时参考。
请自觉、自律地使用该功能并请对自己的学习负责。
如果发现恶意抄袭标程，将按照I类违反进行处理。