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 JavaScript (Node.js 12.16.1) (judge verdict: Accepted)

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    atB();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;
        let [n,k] = readline().split(' ');
        n = pi(n);
        k = pi(k);

        if(n < k)
            console.log(k-n);
        else{
            if((n+k) % 2 === 0){
                console.log(0);
            }else{
                console.log(1);
            }
        }
    }
}

function probB(){
    let t = pi(readline());

    while(t > 0){
        t--;
        let a = readline().split(' ');
        let b = readline().split(' ');

        a[0] = pi(a[0]);
        a[1] = pi(a[1]);
        a[2] = pi(a[2]);

        b[0] = pi(b[0]);
        b[1] = pi(b[1]);
        b[2] = pi(b[2]);

        let maxSum = 0;
        if(b[2] - (a[0] + a[2]) > 0){
            b[2] = b[2] - (a[0]+a[2]);
            a[0] = 0;
            a[2] = 0;
        }else if(b[2] - a[0] > 0){
            a[2] = a[2] - (b[2] - a[0]);
            b[2] = 0;
            a[0] = 0;
        }else{
            a[0] -= b[2];
            b[2] = 0;
        }

        if(a[2] > b[1])
            console.log((b[1] - b[2]) * 2)
        else
            console.log((a[2]-b[2]) * 2);

    }
}

function probC(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = readline().split(' ');
        let x = JSON.parse(JSON.stringify(a));

        x.sort((a,b) => pi(a) - pi(b));
        let res = true;
        for(let i = 0; i < n; i++){
            if(x[i] !== a[i]){
                if(pi(a[i]) % pi(x[0]) !== 0){
                    res = false;
                    break;
                }
            }
        }

        if(res)
            console.log('yes');
        else
            console.log('no');
    }
}

function atA(){
    let [n,x,t] = readline().split(' ');
    n = pi(n);
    x = pi(x);
    t = pi(t);

    if(n < x)
        console.log(t);
    else{
        if(n % x === 0){
            console.log((n/x) * t);
        }else{
            console.log(Math.ceil(n/x) * t);
        }
    }
}

function atB(){
    let n = readline().split('');

    let sum = 0;
    for(let i of n){
        sum += pi(i);
    }

    console.log(sum % 9 === 0 ? 'Yes' : 'No');
}

function atC(){
    readline();
    let a = readline().split(' ');
    let max = pi(a[0]);
    let res = 0;
    for(let i = 1; i < a.length; i++){
        let x = pi(a[i]);
        if(x < max){
            res += (max-x);
        }

        max = Math.max(max, x);
    }

    console.log(res);
}

function atD(){
    let [m,n] = readline().split(' ');
    m = pi(m);
    n = pi(n);

    let st = readline().split(' ');
    let en = readline().split(' ');

    let mat = new Array(m);
    for(let i = 0; i < m; i++){
        let a = readline().split('');
        mat[i] = a;
    }

    let map = {};
    let visited = new Array(m);
    for(let i = 0; i < m; i++){
        visited[i] = new Array(n);
        visited[i].fill(false);
    }

    let isValid = (x,y) => {
        if(x < 0 || x >= m || y < 0 || y >= n)
            return false;

        if(visited[x][y] || mat[x][y] === '#')
            return false;

        return true;
    }

    let dfs = (r,c) => {
        // if(map[`${r}_${c}`])
        //     return map[`${r}_${c}`];

        visited[r][c] = true;

        if(r === pi(en[0])-1 && c === pi(en[1])-1)
            return 0;

        let min = 9999999999999999;
        if(isValid(r+1,c)){
            min = Math.min(min, dfs(r+1,c));
        }

        if(isValid(r+2,c)){
            min = Math.min(min, dfs(r+2,c) + 1);
        }

        if(isValid(r-1,c)){
            min = Math.min(min, dfs(r-1,c));
        }

        if(isValid(r-2,c)){
            min = Math.min(min, dfs(r-2,c) + 1);
        }

        if(isValid(r,c+1)){
            min = Math.min(min, dfs(r,c+1));
        }

        if(isValid(r,c+2)){
            min = Math.min(min, dfs(r,c+2) + 1);
        }

        if(isValid(r,c-1)){
            min = Math.min(min, dfs(r,c-1));
        }

        if(isValid(r,c-2)){
            min = Math.min(min, dfs(r,c-2) + 1);
        }

        visited[r][c] = false;
        // map[`${r}_${c}`] = min;
        return min;
    }

    let res = dfs(pi(st[0])-1, pi(st[1])-1);
    if(res > m*n)
        console.log(-1);
    else
        console.log(res);
}