Problem:
Score : 200 points

Problem Statement

An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9.

Determine whether N is a multiple of 9.

Constraints

0 \leq N < 10^{200000}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is a multiple of 9, print Yes; otherwise, print No.

Sample Input 1

123456789

Sample Output 1

Yes

The sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so 123456789 is a multiple of 9.

Sample Input 2

0

Sample Output 2

Yes

Sample Input 3

31415926535897932384626433832795028841971693993751058209749445923078164062862089986280

Sample Output 3

No

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

//////////////////////////////////////
////   Author: ABHINASH GIRI      ////
/////////////////////////////////////
//cout<<"Case #"<<l<<":"<<x<<nl;

// #pragma clang diagnostic push
//#pragma clang diagnostic ignored "-Wunknown-pragmas"
//#pragma GCC diagnostic ignored "-Wunused-const-variable"
//#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target ("sse4")
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define PI (2*acos(0.0))
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pos_rt_stbt(x)   (__builtin_ffsll(x))   // return position of rightmost set bit ( 1 indexing ) pos_rt_stbt(10) = 2 ( 1010 )
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            int t; cin>>t; while(t--)
#define nl "\n"
#define all(v) (v).begin(),(v).end()
#define clr(v) memset(v,0,sizeof(v));
#define sqr(x) ((x) * (x))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<vll> vvll;
typedef vector<unsigned long long int> vull;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<string, string>> vpss;
const long long int inf = 1e18;
const long long int mod = 1e9 + 7 ;
const long long int MOD =  998244353;
//----------------------------------------------------------------------------------------------------------------------
//// Debug
//#define sim template < class c
//#define ris return * this
//#define dor > debug & operator <<
//#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
//sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
//sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
//struct debug {
//#ifdef ABHI
//    eni( != ) cerr << boolalpha << i; ris;
//    }
//    eni( == ) ris << range(begin(i), end(i));
//    }
//    sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
//    sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
//#else
//    sim dor(const c&) { ris; }
//#endif
//};
//vector<char*> tokenizer(const char* args) {
//    char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
//    vector<char*> v({token});
//    while (token = strtok(NULL, ", ")) v.push_back(token);
//    return reverse(v.begin(), v.end()), v;
//}
//void debugg(vector<char*> args) { cerr << "\b\b "; }
//template <typename Head, typename... Tail>
//void debugg(vector<char*> args, Head H, Tail... T) {
//    debug() << " [" << args.back() << ": " << H << "] ";
//    args.pop_back(); debugg(args, T...);
//}
//#define harg(...) #__VA_ARGS__
//#ifdef ABHI
//#define deb(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
//#else
//#define deb(...) { }
//#endif
/// --------------------------------------------------------------------------------------------------------------------

#define ptvs(v) for(auto &item :v) cout<<item<<" ";cout<<"\n";
#define ptp(v) for(auto &item :v) cout<<item.first<<" ----> "<<item.second<<"  "; cout<<"\n"
#define ptv(v) for(auto &item :v) cout<<item<<"\n"
#define pt(x) cout<<((x))<<"\n";
#define pt2(x,y) cout<<(x)<<" "<<(y)<<"\n";
#define cinvll(v,start,end) vll v(end+1);for(auto i=start;i<=end;i++) {cin>>v[i];}
//***********************************************************************************************
//Sorting Comparators

// sorts in ascending order on first and on second ( if first equals)
template <typename T>
bool  asc(pair<T, T>&a, pair<T, T>&b)
{
    if (a.first == b.first)
    {return a.second > b.second;}
    return a.first < b.first;
}

// sorts in descending order on first and on second ( if first equals)
template <typename T>
bool desc(pair<T, T>&a, pair<T, T>&b)
{
    if (a.first == b.first)
    {return a.second > b.second;}
    return a.first > b.first;
}
//***********************************************************************************************

// Fast Exponentiation power(a,b) ==> a to the power b
template <typename T>
T  power(T  a, T  b) {
    if (b == 0)
        return 1;
    if (b == 1)
        return a;
    else {
        T  res = (power(a, b / 2));
        if (b % 2)
        {
            return (res * res * a);
        }
        else
        {return res * res;}
    }
}

// Fast Modular Exponentiation  power(a,b,m) ==> (a to the power b) modulo m
template <typename T>
T  power(T  a, T  b, T modulo)
{
    if (b == 0)
        return 1;
    if (b == 1)
        return a;
    else {
        T  res = (power(a, b / 2, modulo) % modulo);
        if (b % 2)
        {
            return ((((res % modulo) * (res % modulo)) % modulo) * (a % modulo)) % modulo;
        }
        else
        {return ((res % modulo) * (res % modulo)) % modulo;}
    }
}
// G C D
template <typename T>
T  gcd(T  a, T  b) {
    if (b == 0)
    {return a;}
    return gcd(b, a % b);
}
// L C M
template <typename T>
T lcm(T p, T q)
{return (p * q) / gcd<T>(p, q);}

//Prime factorisation
template <typename T>
void primefactorise(T n, vector<T>&vec)
{
    while (n % 2 == 0) {
        vec.emplace_back(2);
        n = n / 2;
    }
    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            vec.emplace_back(i);
            n = n / i;
        }
    }
    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
    {
        vec.emplace_back(n);
    }
}
// All factors of a number in O(sqrt(n))
template <typename T>
void all_factor(T n, vector<T>&vec)
{
    for (auto i = 1; i <= sqrt(n) ; ++i) {
        if (n % i == 0)
        {
//          Factors occurs in pairs
            vec.emplace_back(i);
            if (i != (n / i))
            {
                vec.emplace_back(n / i);
            }

        }
    }
}

ll mod_inv(ll a) {    return (power<ll>(a, mod - 2, mod)) % mod;    }

void factorial(vll &fact, ll n)
{
    fact.resize(n + 1, 1);
    fact[0] = 1;
    fact[1] = 1;
    for (int i = 2; i <= n ; ++i)
    {
        fact[i] = ((fact[i - 1] % mod) * (i % mod)) % mod;
        //cout<<" fact "<<i<<" "<<fact[i]<<nl;
    }
}

ll ncr(ll n, ll r, vll fact)
{
    if (n < r or n < 0 or r < 0)
    {
        return 0;
    }
    return fact[n] % mod * mod_inv(fact[r]) % mod * mod_inv(fact[n - r]) % mod % mod % mod;
}

int main()
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_timer, end_timer;
    start_timer = std::chrono::high_resolution_clock::now();
    bool show_time = false;  //  change it to true when needed;
    /* Building Block */
    fast;
    string s;
    cin>>s;
    ll x=0;
    for(auto &i:s)
    {
        x = (x+(s[i]-'0'))%9;
    }
    if(x==0)
    {
        pt("Yes");
    }
    else pt("No");

    end_timer = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_timer - start_timer).count();
    if (show_time)
    {cout << "\nElapsed Time: " << elapsed_time << "ms\n";}

    return 0;
}