Subarray
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given an array A of length containing only 1 and -1. The number of 1 is not more than .
Please count how many pairs of (l, r) satisfy and .

输入描述:

The first line of input contains an integers N indicating how many segments of A is 1.
Following N lines each contains two space-separated integers l_i, r_i indicating that A_j is 1 for



for


输出描述:

Output one line containing an integer representing the answer.
示例1

输入

复制
1
0 1

输出

复制
4
示例2

输入

复制
1
1 2

输出

复制
5
示例3

输入

复制
2
0 1
3 4

输出

复制
16