eolymp
bolt
Try our new interface for solving problems
Problems

Accept in 150 seconds

Accept in 150 seconds

\includegraphics{https://static.e-olymp.com/content/61/6191ec9512ef62c7d5f837f6c061de58503bb192.jpg} In the naughty kingdom the minister decided to verify the work of software engineers, weather they did not cheat them. The engineers were writing a software for selling online tram tickets. The selling was occured in such way: each passenger was ordering a ticket from station \textbf{A} to station \textbf{B}. But the program of this unfortunate engineers inform the government only the number of passengers who took a tram on each station (\textbf{In}) and the number of passengers who leave the tram (\textbf{Ou}t). The transport authority sent the inspectors to control the information. The inspectors was checking all passengers who took the tram from station \textbf{L} and left it at station \textbf{R}. They collect the information about how many tickets was really sold from station \textbf{L} to station \textbf{R}. However in their way to department inspectors lost all of their information. The inspectors are asking you to count quickly this data and send them to the transport authority. The tram route it is a straight line along which there are stations. The stations are numbered from \textbf{1}, but it is possible to travel only from the station with smaller number to bigger one. \InputFile First line of input contains \textbf{2} positive integers: \textbf{N} -- number of stops, \textbf{M} -- number of inspectors on a line (\textbf{N} ≤ \textbf{10^5}, \textbf{M} ≤ \textbf{10^5}). In a next \textbf{N} lines, line \textbf{i+2} describes a pair of number for \textbf{i}-th stop: \textbf{In} -- how many people took a tram on station \textbf{i} and \textbf{Out} -- how many people leave the tram on a station \textbf{i}. (\textbf{0} ≤ \textbf{In}, \textbf{Out} ≤ \textbf{10^4}, \textbf{Out\[1\] = 0}, \textbf{In\[N\] = 0}, on a last stop (\textbf{N}) all the passengers leave the tram). In next \textbf{M} lines also two pair of numbers \textbf{L}, \textbf{R} -- the numbers of station, where the inspectors was working (\textbf{1} ≤ \textbf{L} < \textbf{R} ≤ \textbf{N}). \OutputFile For each inspectors in the order in which they were set, write how many tickets were sold berween stops including \textbf{L }and \textbf{R}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
7 4
1 0
2 0
3 1
4 2
5 0
6 0
0 18
1 3
1 7
3 7
4 5
Output example #1
6
21
18
9
Author Ostap Stoliarchuk
Source Distance Summer Computer School - Summer 2013