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 math import sqrt

def HQ(s):
    o = ''
    for c in s:
        if c == 'H':
            o += 'H'
        elif c == 'Q':
            o += s
    return o

def check(s):
    cq = s.count('Q')
    if cq == 0:
        return True
    m = int(sqrt(cq)+0.5)
    if m * m < cq:
        while (m+1)*(m+1) <= cq:
            m += 1
    elif m * m > cq:
        while (m-1)*(m-1) >= cq:
            m -= 1
    if m * m != cq:
        return False
    i = s.index('Q')
    j = s.rindex('Q')
    l1, l2 = len(s[:i]), len(s[j+1:])
    if (l1 & 1) or (l2 & 1):
        return False
    l1 /= 2
    l2 /= 2
    x = y = s.index('Q')
    for _ in range(m-1):
        y = s.index('Q',y+1)
    return HQ(s[x-l1:y+1+l2]) == s

s = raw_input().strip()
if not check(s):
    print 'No'
else:
    print 'Yes