In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
This Sunday, The Byte Day will be celebrated in Bytetown, one of the most important annual Bytelandian celebrations. However, everything indicates that this year jubilation will not only be a rural family fete.
Well, Bytetown citizens are strongly divided concerning one crucial matter. Some believe that in line with tradition, the byte should always be equal to eight bits. However there are progress supporters who would rather go for more capacious, 16 bit bytes. Others see the whole matter much more rigidly and would eagerly like to declare that the byte should always have only four bits. Finally there are less significant subversive movements in Bytetown, whose members advocate that the count of bits in the byte should not be the power of two, or yet it must not necessarily be an even number! All of these societies plan to hold their own manifestation in order to convince Bytetown citizens to their cases.
Many Bytetown citizens are afraid that such a number of demonstrations might interfere with the The Byte Day celebrations. The Lord Mayor of Bytetown sensed a significant public support could be gained, by forbidding some of the demonstrations. Due to the fact that such decisions raise controversy, the Lord Mayor decided he would only cancel two demonstrations. Additionally he would like to be able to choose such demonstrations for cancellation, that would result in the the total time taken by any other possible demonstrations taking place in the city after the cancellation, to possibly be shortest. Help The Lord Mayor and give him a clue how much time in the city without a demonstration he can achieve.
The first input line contains one integer (): the number of planned demonstrations. Each of the subsequent lines describes one demonstration: -th of those lines contains two integers and (), which mean that -th demonstration begins byteminutes after sunrise and ends byteminutes after sunrise.
Your program should produce exactly one non-negative integer, describing by how much time demonstrations taking place could possibly be shortened, in case The Lord Mayor of Bytetown cancels maximum two demonstrations.
For the input data:
5 0 9 1 4 2 5 7 9 6 7
the correct result is:
4
Explanation to the example: Lord Mayor of Bytetown should not issue permits for the first and the fourth demonstration.
Task author: Jakub Łącki.