Long Contest and Cook Off Overlaps
All submissions for this problem are available.### Read problem statements in [Hindi](http://www.codechef.com/download/translated/FEB20/hindi/LONGCOOK.pdf), [Bengali](http://www.codechef.com/download/translated/FEB20/bengali/LONGCOOK.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/FEB20/mandarin/LONGCOOK.pdf), [Russian](http://www.codechef.com/download/translated/FEB20/russian/LONGCOOK.pdf), and [Vietnamese](http://www.codechef.com/download/translated/FEB20/vietnamese/LONGCOOK.pdf) as well. Each month, a CodeChef Long Contest starts at 3 PM IST (UTC+5:30) on the first Friday and it lasts for exactly $10$ days (i.e. $240$ hours). Also, a Cook-Off starts at 9:30 PM IST on the second-to-last (i.e. penultimate) Sunday and it lasts for $2.5$ hours. Let's denote a month by a pair $(m, y)$, where $m$ is one of the twelve months (numbered $1$ through $12$) and $y$ is a year. You are given two (not necessarily distinct) months, e.g. Oct 2009 and Feb 2020. You have to find the total number of months between these two months (both inclusive) when the Long Contest and Cook-Off intersect, i.e. there is a moment in time when both contests for that month are running simultaneously. Here, we assume that both contests are held on each and every month without any interruptions or schedule changes. Note: A year is a leap year if it a multiple of $400$, or if it is a multiple of $4$ but not a multiple of $100$. For example, the year $2100$ is not a leap year, but the year $2400$ is a leap year. ### Input - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $m_1$ and $y_1$ describing the first month. - The second line contains two space-separated integers $m_2$ and $y_2$ describing the second month. ### Output For each test case, print a single line containing one integer ― the number of months between $(m_1, y_1)$ and $(m_2, y_2)$ when the Long Contest and the Cook-Off intersect. ### Constraints - $1 \le T \le 10^5$ - $1 \le m_1, m_2 \le 12$ - $1 \le y_1 \le y_2 \le 10^9$ - the month $(m_1, y_1)$ does not come later than $(m_2, y_2)$ ### Subtasks **Subtask #1 (15 points):** - $T \le 10^3$ - $y_2 \le 2,020$ **Subtask #2 (25 points):** $y_2 \le 10^6$ **Subtask #3 (60 points):** original constraints ### Example Input ``` 2 2 2020 2 2020 10 2009 2 2020 ``` ### Example Output ``` 1 3 ``` ### Explanation **Example case 1:** On the Contests page, we can see that this month (Feb 2020), the Long Contest starts on the 7th and ends on the 17th, while the Cook-Off takes place on the 16th. Hence, there is one month in the given range where the Long Contest and the Cook-Off intersect.
|Tags||admin3, easy, feb20, prefix-sums, tmwilliamlin|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions