The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ...
The only line of the input is a string between 1 and 10<sup class="upper-index">6</sup> characters long.
from collections import Counter
import re

def issquare(n):
    return round(n**0.5)**2==n

def check_orig(code):
    counts = Counter(code)
    orig = ''
    if not issquare(counts['Q']):
        return ''
    nq = round(counts['Q']**0.5)
    if counts['H']%(nq+1) != 0:
        return ''
    nh = counts['H']//(nq+1)
    st = 0
    while st<len(code) and code[st]=='H':
        st+=1
    if st%2!=0:
        return ''
    orig+='H'*(st//2) 
    if st==len(code):
        return orig
    end = -1
    while code[end]=='H':
        end-=1
    if end%2!=1:
        return ''
    orig_end = 'H'*(abs(end+1)//2)
    qcount = 0
    while qcount<nq:
        orig+=code[st]
        if code[st]=='Q':
            qcount+=1
        st+=1
        if st>=len(code):
            return ''
    orig+=orig_end
    return orig
    
def is_real(code,orig):
    ci = 0
    l = len(orig)
    for oi,letter in enumerate(orig):
        if letter=='H':
            if code[ci]!=letter:
                return False
            ci+=1
        elif letter=='Q':
            if code[ci:ci+l]!=orig:
                return False
            ci+=l
    return True
    
code = input()
orig = check_orig(code)

if is_real(code,orig):
    print("Yes")
else:
    print("No")
    
        
    


        