The great kian Hackerearth problem coderinme

The great kian `Hackerearth`

The great Kian is looking for a smart prime minister. He’s looking for a guy who can solve the OLP (Old Legendary Problem). OLP is an old problem (obviously) that no one was able to solve it yet (like P=NP).

But still, you want to be the prime minister really bad. So here’s the problem:

Given the sequence a1, a2, …, an find the three values a1 + a4 + a7 + …, a2 + a5 + a8 + … and a3 + a6 + a9 + … (these summations go on while the indexes are valid).

Input

The first line of input contains a single integer n (1 ≤ n ≤ 105).

The second line contains n integers a1, a2, …, an separated by space (1 ≤ ai ≤ 109).

Output

Print three values in one line (the answers).

#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    long int n,c=0,a1=0,a2=0,a3=0;
    cin>>n;
    while(c<n){
        int x;
        cin>>x;
        a1+=x;
        c++;
        if(c>=n)
            break;
        int y;
        cin>>y;
        a2+=y;
        c++;
        if(c>=n)
            break;
        int z;
        cin>>z;
        a3+=z;
        c++;
    }
    cout<<a1<<" "<<a2<<" "<<a3;
    return 0;
}
#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    long int n,c=0,a1=0,a2=0,a3=0;
    cin>>n;
    while(c<n){
        int x;
        cin>>x;
        a1+=x;
        c++;
        if(c>=n)
            break;
        int y;
        cin>>y;
        a2+=y;
        c++;
        if(c>=n)
            break;
        int z;
        cin>>z;
        a3+=z;
        c++;
    }
    cout<<a1<<" "<<a2<<" "<<a3;
    return 0;
}

Competitive coding
Hackerearth problem
The great kian

A web developer(Front end and Back end), and DBA at csdamu.com. Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me @about.me/s.saifi

Leave a reply:

Your email address will not be published.