Exit Song
시간 제한2초메모리 제한512 MB
등차점화식으로 생성되는 k개의 예약 좌석이 주어질 때, 같은 행에서 연속한 한 좌석 이상을 예매하는 경우의 수를 센다.
문제
Your favorite singer is giving a farewell concert soon, and you just can't miss this.
The concert will be held in a hall which has rows, numbered from 0 to , with seats in each row, consecutively numbered from 0 to .
Unfortunately, seats are already unavailable for reservation. These seats are given by pairs , , , . For every from 1 to , the ticket for seat in row is gone.
You are definitely coming to the concert, but you have no idea if any of your friends would like to join. You are considering all options to buy tickets for several (at least one) consecutive seats in the same row. How many such options do you have?
입력
The first line of the input contains three integers , and (; ) --- the dimensions of the concert hall and the number of reserved seats, respectively.
The second line of the input contains three integers , and ().
The third line of the input contains three integers , and ().
As the input could be quite large, it's encoded in the following way: the values of and are given, and for every from 2 to the values of and can be found using the following formulae:
;
.
All pairs are distinct.
출력
Output a single integer --- the number of options to buy tickets for several consecutive seats in the same row.
힌트
In the first example test case, seats , and are occupied. There are 10 options to buy tickets in row 0, 2 options in row 1 and 6 options in row 2. The sum is .