Source Code
//Includes
#include <bits/stdc++.h>
#include <cstdio> //For input/ouput file
#include <numeric> //For GCD and LCM
#include <iomanip> //For Decimal Points
#include <chrono>

//Marcos
#define fast_io() std::ios::sync_with_stdio(false); std::cin.tie(NULL);
#define ArrOne(name, type, size) type* name = new type[size]
#define ArrTwo(name, type, rows, cols) type** name = new type*[rows]; for(int i = 0; i < rows; i++){ name[i] = new type[cols]; }
#define sp(a, b, type) { type temp = a; a = b; b = temp; }
#define all(x) x.begin(), x.end()
#define pb(i) push_back(i)
#define PI 3.14159265358979
#define MOD 1000000007
#define ll long long
#define lli long long int
#define ull unsigned long long
#define ld long double


void solve() {
    ull n, x, sum = 0; std::cin >> n;
    for(int i = 0; i < n; ++i) {
        std::cin >> x;
        sum += x;
        while(sum >= 10) {
            ull tmpSum = 0;
            while(sum != 0) {
                tmpSum += (sum % 10);
                sum /= 10;
            }
            sum = tmpSum;
        }
    }
    std::cout << sum << "\n";
}

//main function
int main()
{
    //#
    fast_io();
    //#

    //#
    #ifndef ONLINE_JUDGE
        std::freopen("input.txt", "r", stdin);
        std::freopen("output.txt", "w", stdout);
    #endif
    //#

    solve();

    return 0;
}
Copy
The Tale of a Generous Prince talalomar001
GNU G++17
20 ms
1.0 MB
Accepted