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: Accepted)

#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <string>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <bitset>
#include <type_traits>
#include <iomanip>
#include <random>
#include <chrono>
// avoid TLE due to I/O bottleneck
#define __FAST_IO std::ios_base::sync_with_stdio(false), \
                  std::cin.tie(nullptr), \
                  std::cout.tie(nullptr), std::cerr << std::boolalpha;
// load any type of variables from std::cin for -std=c++17
// template<typename ...Args>
// void load_vars(Args&&... args) {
//     (std::cin >> ... >> args);
// }
// load any type of variables from std::cin for -std=c++11
template <typename T>
void q_load(T& t) {
    std::cin >> t;
}
template <typename Head, typename... Tail>
void q_load(Head& H, Tail&&... T) {
  std::cin >> H;
  q_load(T...);
}
// load 1d vector
template<typename T>
void load(std::vector<T>& v) {
    for (T& x: v) std::cin >> x;
}
// load 2d unweighted graph, shift is subtracted, both is for direction
template<typename T>
void load(std::vector< std::vector<T> >& v, int n_lines,
                    int shift=0, bool both=false) {
    for (int i = 0; i < n_lines; ++i) {
        T x, y; std::cin >> x >> y;
        x -= shift; y -= shift;
        v[x].push_back(y);
        if (both) { v[y].push_back(x); }
    }
}
// load 2d weighted graph, shift is subtracted, both is for direction
template<typename T, typename S>
void load(std::vector< std::vector< std::pair<T, S> > >& v, 
                      int n_lines, int shift=0, bool both=false) {
    for (int i = 0; i < n_lines; ++i) {
        T x; S y; int z; std::cin >> x >> y >> z;
        x -= shift; y -= shift;
        v[x].push_back({y, z});
        if (both) { v[y].push_back({x, z}); }
    }
}
// load 2 parallel vectors
template<typename T, typename S>
void load(std::vector<T>& v1, std::vector<S>& v2, int n_lines) {
    for (int i = 0; i < n_lines; ++i) {
        T x; S y; std::cin >> x >> y;
        v1[i] = x;
        v2[i] = y;
    }
}
// load bit string to a bit vector
void load(std::vector<bool>& v) {
    char ch;
    for (int i = 0; i < (int)v.size(); ++i) {
        std::cin >> ch;
        v[i] = bool(ch - '0');
    }
}

// random number generator
std::mt19937 rng(
    (unsigned int)(
        std::chrono::steady_clock::now().time_since_epoch().count()
    )
);
// random number generator
std::mt19937_64 rng_64(
    (unsigned long)(
        std::chrono::steady_clock::now().time_since_epoch().count()
    )
);
// std::uniform_int_distribution<int\int64_t> distrib(a, b);
// distrib(rng) to get the number from [a, b]

// helpful functions
namespace ds {
// some constants, not global, use ds::
const int32_t INF_INT32 = 1e9 + 42;
const int64_t INF_INT64 = 1e18 + 300;
const int MOD = 1e9 + 7;
const long double EPS = 1e-8;

    
inline int gcd(int a, int b) {
    return std::__gcd(a, b);
}

} // end namespace ds//#include "../codebase/debugging.hpp"

int main(int argc, char const *argv[])
{
    // turn_off_de_bug();
    __FAST_IO;
    
    
    char c;
    int accum = 0;
    while (std::cin >> c) {
        accum = (accum + c - '0') % 9;
//        debug_(c, accum)
    }
    std::cout << (accum == 0 ? "Yes": "No");
    std::cout << "\n";

      

    return 0;
}


/*
g++ b.cpp && a < input\b
submit.bat b.cpp
*/