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

题目描述

Hile find a function dist to calculate the distance from a point to an interval. For integer , we define dist(l,r,x) as follows.
  • If
  • If
  • If
You are given n pairs of integers, the i-th of which is (l_i,r_i). It is guaranteed that for all i. For each , solve the following problem.
  • Choose an integer x arbitrarily to minimize , output the minimum value.

输入描述:

The first line contains a single integer  --- the number of pairs.
Then n lines follow, each line contains two integers --- the i-th pair you are given.

输出描述:

Output n lines, the k-th line contains a single integer, which means the minimum value of . You can choose different x for different k.
示例1

输入

复制
3
1 3
6 8
6 8

输出

复制
0
3
3