Codeforces Round 524 (Div. 2)
B
Margarite and the best present
Codeforces
900
原题
← AC →
翻译中…

Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.

翻译中…

Recently, she was presented with an array $a$ of the size of $10^9$ elements that is filled as follows:

翻译中…
  • $a_1 = -1$
  • $a_2 = 2$
  • $a_3 = -3$
  • $a_4 = 4$
  • $a_5 = -5$
  • And so on ...
翻译中…

That is, the value of the $i$-th element of the array $a$ is calculated using the formula $a_i = i \cdot (-1)^i$.

翻译中…

She immediately came up with $q$ queries on this array. Each query is described with two numbers: $l$ and $r$. The answer to a query is the sum of all the elements of the array at positions from $l$ to $r$ inclusive.

翻译中…

Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.

翻译中…

Help her find the answers!

翻译中…

Input

翻译中…

The first line contains a single integer $q$ ($1 \le q \le 10^3$) — the number of the queries.

翻译中…

Each of the next $q$ lines contains two integers $l$ and $r$ ($1 \le l \le r \le 10^9$) — the descriptions of the queries.

翻译中…

Output

翻译中…

Print $q$ lines, each containing one number — the answer to the query.

翻译中…

Note

翻译中…

In the first query, you need to find the sum of the elements of the array from position $1$ to position $3$. The sum is equal to $a_1 + a_2 + a_3 = -1 + 2 -3 = -2$.

翻译中…

In the second query, you need to find the sum of the elements of the array from position $2$ to position $5$. The sum is equal to $a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$.

翻译中…

In the third query, you need to find the sum of the elements of the array from position $5$ to position $5$. The sum is equal to $a_5 = -5$.

翻译中…

In the fourth query, you need to find the sum of the elements of the array from position $4$ to position $4$. The sum is equal to $a_4 = 4$.

翻译中…

In the fifth query, you need to find the sum of the elements of the array from position $2$ to position $3$. The sum is equal to $a_2 + a_3 = 2 - 3 = -1$.

翻译中…

样例

Input #1
5
1 3
2 5
5 5
4 4
2 3
Output #1
-2
-2
-5
4
-1
InputCopy OutputCopy
题目信息
题号
1080B
时间限制
1 s
内存限制
256 MB
标签
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。