AtCoDeer the deer found N rectangle lying on the table, each with height 1.
If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i], as shown in the following figure:

AtCoDeer will move these rectangles horizontally so that all the rectangles are connected.
For each rectangle, the cost to move it horizontally by a distance of x, is x.
Find the minimum cost to achieve connectivity.
It can be proved that this value is always an integer under the constraints of the problem.

-----Constraints-----
 - All input values are integers.
 - 1≤N≤10^5
 - 1≤l_i<r_i≤10^9

-----Partial Score-----
 - 300 points will be awarded for passing the test set satisfying 1≤N≤400 and 1≤l_i<r_i≤400.

-----Input-----
The input is given from Standard Input in the following format:
N
l_1 r_1
l_2 r_2
:
l_N r_N

-----Output-----
Print the minimum cost to achieve connectivity.

-----Sample Input-----
3
1 3
5 7
1 3

-----Sample Output-----
2

The second rectangle should be moved to the left by a distance of 2.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = '# seishin.py\nN = int(input())\nP = [list(map(int, input().split())) for i in range(N)]\n\nINF = 10**18\n\nfrom heapq import heappush, heappop\n\nl0, r0 = P[0]\n\nL = [-l0+1]\nR = [l0-1]\ns = t = 0\n\ndef debug(L, s, t, R):\n    L0 = L[:]\n    Q1 = []; Q2 = []\n    while L0:\n        Q1.append(-s-heappop(L0))\n    R0 = R[:]\n    while R0:\n        Q2.append(t+heappop(R0))\n    print(("debug:", *Q1[::-1]+Q2))\n\n\n#print(L, s, t, R)\nres = 0\nfor i in range(N-1):\n    l0, r0 = P[i]\n    l1, r1 = P[i+1]\n    #print(">", l1, r1)\n    s += (r1 - l1); t += (r0 - l0)\n    if -s-L[0] <= l1-1 <= t+R[0]:\n        #print(0)\n        heappush(L, -l1+1-s)\n        heappush(R, l1-1-t)\n        # res += 0\n    elif l1-1 < -s-L[0]:\n        #print(1)\n        heappush(L, -l1+1-s)\n        heappush(L, -l1+1-s)\n        p = -heappop(L)-s\n        #d = (-L[0]-s) - p\n        heappush(R, p-t)\n        #print(d)\n        #res += d\n        res += (p - (l1-1))\n    elif t+R[0] < l1-1:\n        #print(2)\n        heappush(R, l1-1-t)\n        heappush(R, l1-1-t)\n        p = heappop(R) + t\n        #d = R[0]+t - p\n        heappush(L, -p-s)\n        #print(d)\n        res += (l1-1 - p)\n    #print(L, s, t, R, -s-L[0], R[0]+t, res)\n    #debug(L, s, t, R)\nprint(res)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13571