304 North Cardinal St.
Dorchester Center, MA 02124

# Age Calculator CodeChef Solution

## Age Calculator CodeChef Solution in C++14

``````#include <bits/stdc++.h>

using namespace std;
#define int long long
signed main(){
int t;
cin>>t;
while(t--){
int c;
cin>>c;
int a[c],b[c+1],sum=0;
for(int i=0;i<c;i++){
cin>>a[i];
sum+=a[i];
}
int l,m,n,x,y,z;
cin>>l>>m>>n;
cin>>x>>y>>z;
b[0]=0;
b[1]=a[0];

for(int i=1;i<c;i++){
b[i+1]=a[i]+b[i];
}
int ans=0,ans1=0;

ans+=(sum*(l-1))+b[m-1]+n;

ans1+=(sum*(x-1))+b[y-1]+z;
int cnt=0,cnt1=0;
ans+=(l-1)/4;
ans1+=(x-1)/4;

cout<<ans1-ans+1<<endl;
}
return 0;
}``````

## Age Calculator CodeChef Solution in PYTH 3

``````for _ in range(int(input())):
n=int(input())
a = list(map(int,input().split()))
yb,mb,db = map(int,input().split())

age_d = 0
yc,mc,dc= map(int,input().split())
no = sum(a)
le= no+1
for j in range(yb,yc):
if j%4==0:
age_d = age_d + le
else:
age_d = age_d + no
age_d = age_d - (sum(a[0:mb-1]) + db) + (sum(a[0:mc-1]) + dc)
print(age_d + 1) ``````

## Age Calculator CodeChef Solution in C

``````#include <stdio.h>
struct age{
int date;
int year;
int month;
};

int main() {
long long int t,n,i,sum=0,sum1,sum2;
struct age d1,d2;
scanf("%lld",&t);
while(t--){
sum = 0;
scanf("%lld",&n);
long long int arr[n+1],A[n+1],ans=0;
A[0] = 0;
for(i=1;i<=n;i++){
scanf("%lld",&arr[i]);
sum += arr[i];
A[i] = sum;
}
scanf("%d%d%d",&d1.year,&d1.month,&d1.date);
scanf("%d%d%d",&d2.year,&d2.month,&d2.date);

ans = (sum * (d2.year-d1.year) + (d2.date-d1.date) + (A[d2.month-1]-A[d1.month-1])) + (d2.year-1)/4-(d1.year-1)/4 + 1;
printf("%lld\n",ans);
}
return 0;
}``````

## Age Calculator CodeChef Solution in JAVA

``````     import java.util.*;
import java.io.*;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.math.BigInteger;

class Pair{
int time;
char movie;
Pair(int time , char movie ) {
this.time = time;
this.movie = movie;
}
}
public final class Main{
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;

din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}

public Reader(String file_name) throws IOException {
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}

public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}

public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
}
boolean neg = (c == '-');
if (neg)
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');

if (neg)
return -ret;
return ret;
}

public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
boolean neg = (c == '-');
if (neg)
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}

public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();

do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg) return -ret;
return ret;
}

private void fillBuffer() throws IOException {
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}

public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
static class Kattio extends PrintWriter {
private StringTokenizer st;

// standard input
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(new FileWriter(problemName + ".out"));
r = new BufferedReader(new FileReader(problemName + ".in"));
}

// returns null if no more input
public String next() {
try {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(r.readLine());
return st.nextToken();
} catch (Exception e) { }
return null;
}

public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}

static Kattio sc = new Kattio();
static long  mod  = 998244353l;
static PrintWriter out =new PrintWriter(System.out);

//Heapify function to maintain heap property.
public static void swap(int i,int j,int arr[]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void swap(int i,int j,long arr[]) {
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void swap(int i,int j,char arr[]) {
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static String endl = "\n" , gap = " ";
public static void main(String[] args)throws IOException {
int t =ri();
// boolean seive[] = new boolean[(int)1e6 + 10];
// Arrays.fill(seive , true);
// seive[0] = false ; seive[1] = false;
// for(int i = 2;i<seive.length;i++) {
//     if(seive[i]) {
//         for(int j =i*2;j<seive.length;j+=i) {
//             seive[j] = false;
//         }
//     }
// }

while(t-->0) {

solve();
}
out.close();
}
public static void solve()throws IOException {
int n = ri();
int a[ ] = rai(n);
int arr[] = new int[n + 1];
for(int i =1;i<=n;i++) {
arr[i] = a[i-1];
}
int yb = ri() , mb = ri() , db = ri();
int yc = ri() , mc = ri() , dc = ri();
long  totaldays = 0;
for(int x : arr) totaldays += x;
// for()
long age=0;
age+= (yc-yb-1)*totaldays;

for(int i=mb+1;i<=n;i++){
age+=arr[i];
}
age+=arr[mb]-db+1;

for(int i=1;i<mc;i++){
age+=arr[i];
}
age+=  dc ;

int start=yb;
if(yb%4!=0){
start = yb + (4-yb%4);
}
int leap=0;
if(start<yc){
leap = (yc-start-1)/4+1;
}
age+=leap;

System.out.println(age);

}

public static List<Integer> getParents(int node , int arr[]) {
List<Integer> list = new ArrayList<>();
int cur = node;
while(cur != arr[cur-1]) {
cur = arr[cur-1];
}
return list;
}
public static boolean callfun(char s[] , int n ,int k , int want) {
// System.out.println("FOR "+ want);
int i;
int xor = 0;
for(i =0;i<n;i++) {
xor ^= (s[i]-'0');
if(xor == want) {
k--;
xor = 0;
}
if(k == 1) break;
}
i++;
if(i >= n) return false;
if(k > 1) {
return false;
}
// System.out.println(k + " is k");
xor = 0;
for(;i<n;i++) {
xor ^= (s[i]-'0');
}
// System.out.println("FINAL"+ xor );
return xor == want;
}

public static boolean isSubsequene(char a[],  char b[] ) {
int i =0 , j = 0;
while(i < a.length && j  <b.length) {
if(a[i] == b[j]) {
j++;
}
i++;
}
return  j >= b.length;
}
public static int dfs(int node , HashMap<Integer  , List<Integer>> map ,boolean[] vis , HashSet<Integer> set) {
System.out.println("At node " + node);
vis[node] = true;
boolean canGo = false;
int ans = 0;
for(int x : map.get(node)) {
if(!vis[x]) {
int curans =  dfs(x , map , vis , set);
if(curans > 0 ) {
}
canGo = true;
}
}
if(!canGo) {
ans++;
}
return ans;

}
public static int[] getCnt1(int arr[][] ,int max) {
int n = arr.length;
int tree[] = new int[max + 4];
int cnt2[] = new int[n];
for(int i =n-1;i>=0;i--) {
int index = arr[i][2] , start = arr[i][0] , end = arr[i][1];
int curPos = end;
int res = 0;
while(curPos >0) {
res += tree[curPos];
curPos -= curPos&(-curPos);
}
// System.out.println("IS res " + res);
curPos = end;
cnt2[index] = res;
while(curPos < tree.length) {
tree[curPos] += 1;
curPos += curPos&(-curPos);
}
}
return cnt2;
}
public static  int getIndex(List<Integer> list  , int val ) {
if(list.size() == 0) return 0;
int l =0 , r =list.size()-1;
while(l <= r) {
int mid = l + (r-l)/2;
if(list.get(mid) <= val) l = mid + 1;
else r = mid-1;
}
if(r == -1) return 0;
return r;
}
public static long getSum(long n ) {
long ans = 0;
while(n > 0)  {
ans += n%10;
n /= 10;
}
return ans;
}

public static long fib(int n ,long M) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
long[][] mat = {{1, 1}, {1, 0}};
mat = pow(mat, n-1 , M);
return mat[0][0];
}
}
public static long[][] pow(long[][] mat, int n ,long M) {
if (n == 1) return mat;
else if (n % 2 == 0) return pow(mul(mat, mat , M), n/2 , M);
else return mul(pow(mul(mat, mat,M), n/2,M), mat , M);
}
static long[][] mul(long[][] p, long[][] q,long M) {
long a = (p[0][0]*q[0][0] + p[0][1]*q[1][0])%M;
long b = (p[0][0]*q[0][1] + p[0][1]*q[1][1])%M;
long c = (p[1][0]*q[0][0] + p[1][1]*q[1][0])%M;
long d = (p[1][0]*q[0][1] + p[1][1]*q[1][1])%M;
return new long[][] {{a, b}, {c, d}};
}
public static long[] kdane(long arr[]) {
int n = arr.length;
long dp[] = new long[n];
dp[0] = arr[0];
long ans = dp[0];
for(int i = 1;i<n;i++) {
dp[i] = Math.max(dp[i-1] + arr[i] , arr[i]);
ans = Math.max(ans , dp[i]);
}
return dp;
}

public static void update(int low , int high , int l , int r, int val , int treeIndex ,int tree[]) {

if(low > r || high < l || high < low) return;
if(l <= low && high <= r) {
System.out.println("At " +low + " and " + high + " ans ttreeIndex  " + treeIndex);
tree[treeIndex] += val;
return;
}
int mid = low + (high - low)/2;
update(low , mid , l , r , val , treeIndex*2  + 1, tree);
update(mid + 1 , high , l , r , val , treeIndex*2 + 2 , tree);
}
static int colx[] = {1 ,-1, 0,0 , 1,1,-1,-1};
static int coly[] = {0 ,0, 1,-1,1,-1,1,-1};
public static void reverse(char arr[])  {
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , arr);
i++;
j--;
}
}
public static long[] reverse(long arr[])  {
long newans[] = arr.clone();
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , newans);
i++;
j--;
}
return newans;
}

public static long inverse(long x  , long mod) {
return pow(x , mod -2 , mod);
}
public static int maxArray(int arr[]) {
int ans = arr[0] ,  n = arr.length;
for(int i =1;i<n;i++) {
ans = Math.max(ans , arr[i]);
}
return ans;
}
public static long maxArray(long arr[]) {
long ans = arr[0];
int  n = arr.length;
for(int i =1;i<n;i++) {
ans = Math.max(ans , arr[i]);
}
return ans;
}
public static int minArray(int arr[]) {
int ans = arr[0] , n = arr.length;
for(int i =0;i<n;i++ ) {
ans = Math.min(ans ,arr[i]);
}
return ans;
}
public static long minArray(long arr[]) {
long ans = arr[0];
int n = arr.length;
for(int i =0;i<n;i++ ) {
ans = Math.min(ans ,arr[i]);
}
return ans;
}
public static int sumArray(int arr[]) {
int ans = 0;
for(int x : arr) {
ans  += x;
}
return ans;
}
public static long sumArray(long arr[]) {
long ans = 0;
for(long x : arr) {
ans  += x;
}
return ans;
}
public static long rl() {
return sc.nextLong();
}
public static char[] rac() {
return sc.next().toCharArray();
}
public static String rs() {
return sc.next();
}
public static char rc() {
return sc.next().charAt(0);
}
public static  int [] rai(int n) {
int ans[] = new int[n];
for(int i =0;i<n;i++) {
ans[i] = sc.nextInt();
}
return ans;
}
public static  long [] ral(int n) {
long ans[] = new long[n];
for(int i =0;i<n;i++) {
ans[i] = sc.nextLong();
}
return ans;
}
public static int ri() {
return sc.nextInt();
}

public static int getValue(int num ) {
int ans = 0;
while(num > 0) {
ans++;
num = num&(num-1);
}
return ans;
}
public static boolean isValid(int x ,int y , int n,char arr[][],boolean visited[][][][])  {
return x>=0 && x<n && y>=0 && y <n && !(arr[x][y] == '#');
}
// public static Pair join(Pair a , Pair b) {
//     Pair res = new Pair(Math.min(a.min , b.min) , Math.max(a.max , b.max) , a.count + b.count);
//     return res;
// }

// segment tree query over range
// public static int query(int node,int l , int r,int a,int b ,Pair tree[] ) {
//     if(tree[node].max < a || tree[node].min > b) return 0;
//     if(l  > r) return 0;
//     if(tree[node].min >= a && tree[node].max <= b) {
//         return tree[node].count;
//     }
//     int mid = l + (r-l)/2;
//     int ans = query(node*2 ,l , mid ,a , b , tree) + query(node*2 +1,mid + 1, r , a , b, tree);
//     return ans;
// }
// // segment tree update over range
// public static void update(int node, int i , int j ,int l , int r,long value, long arr[] ) {
//     if(l >= i && j >= r) {
//         arr[node]   += value;
//         return;
//     }
//     if(j < l|| r < i) return;
//     int mid = l + (r-l)/2;
//     update(node*2 ,i ,j ,l,mid,value, arr);
//     update(node*2 +1,i ,j ,mid + 1,r, value  , arr);
// }

public static long pow(long a , long b  , long mod) {
if(b == 1) return a;
if(b == 0) return 1;
long ans = pow(a , b/2 , mod)%mod;
if(b%2 == 0) {
return (ans*ans)%mod;
}
else {
return ((ans*ans)%mod*a)%mod;
}
}

public static boolean isVowel(char ch) {
if(ch == 'a' || ch == 'e'||ch == 'i' || ch == 'o' || ch == 'u') return true;
return false;
}

public static int getFactor(int num) {
if(num==1) return 1;
int ans = 2;
int k = num/2;
for(int i = 2;i<=k;i++) {
if(num%i==0) ans++;
}
return Math.abs(ans);
}

public static int[] readarr()throws IOException {
int n = sc.nextInt();
int arr[] = new int[n];
for(int i =0;i<n;i++) {
arr[i] =  sc.nextInt();
}
return arr;
}

public static boolean isPowerOfTwo (long x) {
return x!=0 && ((x&(x-1)) == 0);
}
public static boolean isPrime(long num) {
if(num==1) return false;
if(num<=3) return true;
if(num%2==0||num%3==0) return false;
for(long i =5;i*i<=num;i+=6) {
if(num%i==0 || num%(i+2) == 0) return false;
}
return true;
}
public static boolean isPrime(int num) {
// System.out.println("At pr " + num);
if(num==1) return false;
if(num<=3) return true;
if(num%2==0||num%3==0) return false;
for(int i =5;i*i<=num;i+=6) {
if(num%i==0 || num%(i+2) == 0) return false;
}
return true;
}
// public static boolean isPrime(long num) {
//     if(num==1) return false;
//     if(num<=3) return true;
//     if(num%2==0||num%3==0) return false;
//     for(int i =5;i*i<=num;i+=6) {
//         if(num%i==0) return false;
//     }
//     return true;
// }
public static long gcd(long a , long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static int gcd(int a , int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static int get_gcd(int a , int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static long get_gcd(long a , long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// public static long fac(long num)  {
//     long ans = 1;
//     int mod = (int)1e9+7;
//     for(long i = 2;i<=num;i++) {
//         ans  =  (ans*i)%mod;
//     }
//     return ans;
// }
}``````

## Age Calculator CodeChef Solution in PYPY 3

``````def solve():
n=int(input())
a = list(map(int,input().split()))
yb,mb,db = map(int,input().split())

age_d = 0
yc,mc,dc= map(int,input().split())
no = sum(a)
le= no+1
for j in range(yb,yc):
if j%4==0:
age_d = age_d + le
else:
age_d = age_d + no
age_d = age_d - sum(a[0:mb-1]) - db
age_d = age_d + sum(a[0:mc-1]) + dc
print(age_d + 1)

for _ in range(int(input())):
solve()``````

## Age Calculator CodeChef Solution in PYTH

``````t = int(raw_input())
for i in range(t):
N = int(raw_input())
st = raw_input().split()
A = [0]
tot = 0
for x in st:
tot += int(x)
A.append(tot)
# endfor x
st = raw_input().split()
yb = int(st[0])
mb = int(st[1])
db = int(st[2])
st = raw_input().split()
yc = int(st[0])
mc = int(st[1])
dc = int(st[2])
y = yb%4
dy = yb-y
yb = y
yc -= dy
db = yb*A[N] + (yb-1)/4 + A[mb-1] + db
dc = yc*A[N] + (yc-1)/4 + A[mc-1] + dc
d = dc+1-db
print d
# endfor i
``````

## Age Calculator CodeChef Solution in C#

``````using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}

class Sol{
public void Solve(){

for(;T>0;T--){

N = ri();
A = rla();
var d = ria();
Yb = d[0]; Mb = d[1]; Db = d[2];
d = ria();
Yc = d[0]; Mc = d[1]; Dc = d[2];

var x = calc(Yb, Mb, Db);
var y = calc(Yc, Mc, Dc);
Console.WriteLine(y - x + 1);

}

}

long calc(long y, long m, long d){
long td = 0;
for(int i=0;i<N;i++) td += A[i];

long ret = 0;
y--;
ret += y * td;
ret += (y / 4);

m--;
for(int i=0;i<m;i++) ret += A[i];

ret += d;

return ret;
}

int N;
long[] A;
long Yb,Mb,Db;
long Yc,Mc,Dc;

int T;
public Sol(){
T = ri();
}

static String rs(){return Console.ReadLine();}
static int ri(){return int.Parse(Console.ReadLine());}
static long rl(){return long.Parse(Console.ReadLine());}
static double rd(){return double.Parse(Console.ReadLine());}
static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}``````

## Age Calculator CodeChef Solution in GO

``````package main

import (
"bufio"
"fmt"
"os"
)

func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] != ' ' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}

func readNum(scanner *bufio.Scanner) (a int) {
scanner.Scan()
return
}

func readTwoNums(scanner *bufio.Scanner) (a int, b int) {
res := readNNums(scanner, 2)
a, b = res[0], res[1]
return
}

func readNNums(scanner *bufio.Scanner, n int) []int {
res := make([]int, n)
x := 0
scanner.Scan()
for i := 0; i < n; i++ {
for x < len(scanner.Bytes()) && scanner.Bytes()[x] == ' ' {
x++
}
x = readInt(scanner.Bytes(), x, &res[i])
}
return res
}

func fillNNums(scanner *bufio.Scanner, n int, res []int) {
x := 0
scanner.Scan()
for i := 0; i < n; i++ {
for x < len(scanner.Bytes()) && scanner.Bytes()[x] == ' ' {
x++
}
x = readInt(scanner.Bytes(), x, &res[i])
}
}

func readUint64(bytes []byte, from int, val *uint64) int {
i := from

var tmp uint64
for i < len(bytes) && bytes[i] != ' ' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp

return i
}

func main() {
scanner := bufio.NewScanner(os.Stdin)

for tc > 0 {
tc--
A := readNNums(scanner, n)
x := readNNums(scanner, 3)
y := readNNums(scanner, 3)
res := solve(n, A, x[0], x[1], x[2], y[0], y[1], y[2])
fmt.Println(res)
}
}

func solve(n int, A []int, yb, mb, db int, yc, mc, dc int) int {
var daysInOneYear int
for i := 0; i < n; i++ {
daysInOneYear += A[i]
}
var res int
for yb+1 < yc {
res += daysInOneYear
if yb%4 == 0 {
res++
}
yb++
}

daysBetween := func(a, b, c, d int) int {
var res int
for a+1 < c {
res += A[a-1]
a++
}
if a+1 == c {
res += A[a-1] - b + 1
a++
b = 1
}
// a == c
res += d - b + 1
return res
}

//yb + 1 == yc or yb == yc
if yb+1 == yc {
// go to year as yc
res += daysBetween(mb, db, n+1, 0)
if yb%4 == 0 {
res++
}
yb++
mb = 1
db = 1
}
res += daysBetween(mb, db, mc, dc)

return res
}``````
##### Age Calculator CodeChef Solution Review:

In our experience, we suggest you solve this Age Calculator CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Age Calculator CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Age Calculator CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!