# Age Calculator | codehef solution

Chef's planet is called Javad. A year on Javad has $�$ months numbered $1$ through $�$. For each valid $�$, the $�$-th month has ${�}_{�}$ days numbered $1$ through ${�}_{�}$.

On Javad, years that are divisible by $4$ are leap years - the last month of each leap year is one day longer (it has ${�}_{�}+1$ days).

You are given Chef's birth date and the current date. Find the age of Chef in days, i.e. the number of days between Chef's birth date and the current date inclusive.

### Input

• The first line of the input contains a single integer $�$ denoting the number of test cases. The description of $�$ test cases follows.
• The first line of each test case contains a single integer $�$.
• The second line contains $�$ space-separated integers ${�}_{1},{�}_{2},\dots ,{�}_{�}$.
• The third line contains three space-separated positive integers ${�}_{�}$${�}_{�}$ and ${�}_{�}$ denoting the year, month and day of Chef's birth respectively.
• The fourth line contains three space-separated positive integers ${�}_{�}$${�}_{�}$ and ${�}_{�}$ denoting the current year, month and day respectively.

### Output

For each test case, print a single line containing one integer — Chef's age in days.

### Constraints

• $1\le �\le 100$
• $1\le �\le 10,000$
• $1\le {�}_{�}\le 10,000$ for each valid $�$
• $1\le {�}_{�},{�}_{�}\le 100,000$
• $1\le {�}_{�},{�}_{�}\le �$
• ${�}_{�}$ will be less than or equal to the days of the ${�}_{�}$ month of the ${�}_{�}$ year.
• ${�}_{�}$ will be less than or equal to the days of the ${�}_{�}$ month of the ${�}_{�}$ year.
• the current date is equal to or greater than Chef's birth date

• $1\le {�}_{�},{�}_{�},�\le 1,000$
• $1\le {�}_{�}\le 100$ for each valid $�$

Subtask #2 (90 points): original constraints

### Sample 1:

Input
Output
4
5
1 2 3 4 5
2 1 1
3 5 1
2
3 3
1 1 1
2 2 2
2
1 1
3 1 1
3 2 1
5
1 4 3 4 6
3 5 6
10 1 1
26
11
2
112
Did you like the problem statement?

Code(C++):-

#include <bits/stdc++.h>

using namespace std;

int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
long long int yb, mb, db, yc, mc, dc, s1 = 0, s2 = 0, s = 0;
cin >> yb >> mb >> db >> yc >> mc >> dc;
for (int i = 0; i < n; i++)
{
if (i < (mc - 1))
s2 += a[i];
if (i > (mb - 1))
s1 += a[i];
s += a[i];
}
long long int ans = (a[mb - 1] - db + 1) + s1 + (yb % 4 == 0 ? 1 : 0) + (yc - yb - 1) * s + ((yc / 4) - (yb / 4)) - (yc % 4 == 0 ? 1 : 0) + s2 + dc;
cout << ans << "\n";
}
return 0;
}

### Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-
iMocha coding Questions:-
Tech Mahindra coding questions:-
Unthinkable Solutions coding questions:-