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



Sample input:
123456789


Sample output:
Yes

Submission status: Accepted

Solution code:
n = list(map(int, list(input())))
if sum(n) % 9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = input()
cnt = 0
for l in n:
  cnt += int(l)
print('Yes' if cnt%9==0 else 'No')

Submission status: Accepted

Solution code:
a = input()
b = sum(map(int,a))
if b%9==0:print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
n=list(input())

ans=0

for a in n:
  ans+=int(a)
  
if ans%9==0:
  print('Yes')
  
else:
  print('No')

Submission status: Accepted

Solution code:
N = list(input())

for i in range(len(N)):
    N[i] = int(N[i])

if sum(N) % 9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s = input()
cnt = 0
for c in s:
    cnt += int(c)
print('Yes' if cnt % 9 == 0 else 'No')

Submission status: Accepted

Solution code:
N = list(input())
s = 0
for n in N:
    s += int(n)

if s%9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = list(input())
N = list(int(n) for n in N)
s = sum(N)
if s % 9 == 0:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = input()
l = len(n)
c = 0
for i in range(l):
    c= (c+int(n[i]))%9
f=False
if c==0:
    f=True
yn(f)

Submission status: Accepted

Solution code:
n = input()
a = 0
for i in range(len(n)):
    a += int(n[i])
if a % 9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#bM
N=[int(i) for i in input()]

if sum(N)%9==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = input()
tmp = 0
for i in N:
    tmp = (tmp + int(i)) % 9
if tmp % 9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = input()

total = 0
for i in range(len(N)):
    total += int(N[i])

if total % 9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = input()

total = 0
for i in range(len(N)):
    total += int(N[i])

if total%9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = input()
ans = 0
for i in n:
    ans += int(i)
if ans % 9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = input()
ans = 0

for i in n:
  ans += int(i)
  ans %= 9
  
if ans % 9 == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n = input().rstrip()
    ans = 0
    for i in n:
        ans += int(i)
    if ans%9==0:
        print("Yes")
    else:
        print("No")

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
N = list(input())

ans = 0

for n in N:
    ans += int(n)

if ans%9==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import math

n = list(map(int, "".join(input())))

if sum(n) % 9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = input()
l = len(n)
ans = 0
for i in range(l):
    d = int(n[i])
    ans += d
    ans %= 9
if ans % 9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = input()

cnt = 0
for i in range(len(N)):
    cnt += int(N[i])
    cnt %= 9

if cnt == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

N = list(input().rstrip())

mod = 0

for n in N:
    mod += int(n)
    mod %= 9

print("Yes") if mod == 0 else print("No")

Submission status: Accepted

Solution code:
n = int(input())
s = str(n)
som = 0
for i in s:
    som = som+int(i)

if som%9 == 0:
    print("Yes")
    
else:
    print("No")

Submission status: Accepted

Solution code:
N = input()
sum = 0
for n in N:
    sum += int(n)
if sum % 9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    
def solve():
    s = insr()
    q = sum([int(s[i]) for i in range(len(s))])
    if q % 9 == 0:
        print("Yes")
    else:
        print("No")
    
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)

def counter_elements(a):
    q = dict()
    for i in range(len(a)):
        if a[i] not in q:
            q[a[i]] = 0
        q[a[i]] = q[a[i]] + 1
    return(q)

def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)
 
def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))
 
def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

def transpose(a):
    n,m = len(a),len(a[0])
    b = [[0] * n for i in range(m)]
    for i in range(m): 
        for j in range(n): 
            b[i][j] = a[j][i]
    return(b)
#-----------------------------------------------------------------------#
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Submission status: Accepted

Solution code:
def cin():  return list(map(int,input().split()))

N = input()
cnt = 0
for i in N:  cnt += int(i)
if cnt % 9 == 0:  print("Yes")
else:  print("No")

Submission status: Accepted

Solution code:
n = int(input())

def digitSum(n):
    s = str(n)
    array = list(map(int, s))
    return sum(array)

print('Yes') if digitSum(n) % 9 == 0 else print('No')

Submission status: Accepted

Solution code:
N=input()
t=0
for i in range(len(N)):
    t+=int(N[i])

print('NYoe s'[t%9==0::2])

Submission status: Accepted

Solution code:
S = input()

N = 0

for s in S:
    N += int(s)
if N % 9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = input()

if sum(int(c) for c in N) % 9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N=list(str(input()))
total=0
for i in range(len(N)):
    total+=int(N[i])
if total%9==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import math
import fractions
import collections
import itertools
N=list(input())
N=list(map(int,N))
cnt=0
#print(N)
if sum(N)%9==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: str):
    return YES if sum(map(int, N)) % 9 == 0 else NO

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)  # type: str
    print(solve(N))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

Solution code:
n = input()
total = 0 
for i in n :
    total += int(i)
if total % 9 == 0 :
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = [int(s) for s in input()]
print('Yes' if sum(N)%9==0 else 'No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
n=list(map(int, input().split()))
if sum(n)%9==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())

if N % 9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = input()
ans = 0
for x in N:
    ans += int(x)
if ans % 9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def sosu(n):
    so = [1 for i in range(n+1)]
    so[0], so[1] = 0, 0
    for i in range(2, n+1):
        if so[i]:
            for j in range(2, n//i):
                so[i * j] = 0

    return so

def solve():
    s = getS()
    ans = 0
    for c in s:
        ans += int(c)

    if ans % 9 == 0:
        print("Yes")
    else:
        print("No")


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

Solution code:
def check():
  N = list(map(int,list(input())))
  if sum(N)%9!=0:
    return 'No'
  return 'Yes'
print(check())

Submission status: Accepted

Solution code:
N = input()

cnt = 0
for x in N:
    cnt += int(x)
if cnt % 9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s = [int(c) for c in input()]

x = 0
for digit in s:
    x += digit

if x % 9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = str(input())
L = len(N)
cnt = 0
for i in range(L):
    cnt += int(N[i])
if cnt % 9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#n,x,t=map(int,input().split())
n=input()
ans=0
for i in n:
  ans+=int(i)

if ans%9==0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n = input()
l = []
for i in n:
    l.append(int(i))

if sum(l) % 9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = input()
tmp = 0
for i in n:
    tmp += int(i)
if tmp % 9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = input()
ans = 0
for i in range(len(n)):
    ans += int(n[i])
print('Yes' if ans%9 == 0 else 'No')

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

inf = 10 ** 18
mod = 10 ** 9 + 7

s = list(map(int, list(input())))
tmp = sum(s)
if tmp%9 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = input()
count = 0
for i in range(len(N)):
    count += int(N[i])
if count % 9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main():
    S = input()

    t = 0
    for x in map(int, S):
        t += x
    print('Yes' if t % 9 == 0 else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n=input()
    sum=0
    for ni in n:
        sum+=int(ni)
    # print(sum)
    if sum%9==0:
        ans='Yes'
    else:
        ans='No'
    return ans

if __name__=='__main__':
    ans=main()
    print(ans)

Submission status: Accepted

Solution code:
# = map(int, input().split())
# = int(input())
N = input()
ans = 0
mod = 9
for k in range(len(N)):
  ans = (ans + int(N[k]))%mod
if ans == 0:
  print('Yes') 
else:
  print('No')

Submission status: Accepted

Solution code:
# Date [ 2020-08-22 21:02:22 ]
# Problem [ b.py ]
# Author Koki_tkg

import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n = read_str()
    n = n.split()
    total = 0
    for i in n:
        total += int(i)
    
    if total % 9 == 0:
        print('Yes')
    else:
        print('No')


if __name__ ==  '__main__':
    Main()

Submission status: Accepted

Solution code:
# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion
class union_find:
    def __init__(self, n):
        self.n = n
        self.rank = [0]*n
        self.parent = [int(j) for j in range(n)]
    
    def union(self,i,j):
        i = self.find(i)
        j = self.find(j)
        if self.rank[i] == self.rank[j]:
            self.parent[i] = j
            self.rank[j] += 1

        elif self.rank[i] > self.rank[j]:
            self.parent[j] = i
        else:
            self.parent[i] = j

    def find(self, i):
        temp = i
        if self.parent[temp] != temp:
            self.parent[temp] = self.find(self.parent[temp])
        return self.parent[temp]
from math import log2, ceil
from collections import deque, Counter as CC
def main():
# Enter your code here. Read input from STDIN. Print output to STDOUT
    # for t in range(int(input())):
        
        n = input()
        ans = 0
        for i in range(len(n)):
            ans+=int(n[i])
        if(ans%9!=0):
            print("No")
        else:
            print("Yes")
        # n,x,t = [int(j) for j in input().split()]
# )
        # l = [int(j) for j in input().split()]




        # b = [int(j) for j in input().split()]

            # s = n-1

        # s = input()




        # a = list(a)
        # print(a)
        # for i in a:



        



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()

ans = 0

for i in s:
    ans += int(i)

if ans % 9 == 0:
    print("Yes")
else:
    print("No")