#include <bits/stdc++.h>
using namespace std;
char s[1000001];
char s1[1000001];
char s2[1000001];
int main() {
  scanf("%s", s);
  int l = strlen(s);
  int qs = count(s, s + l, 'Q');
  if (qs == 0) {
    puts("Yes");
    return 0;
  }
  int q = sqrt(qs + 0.9);
  if (q * q != qs) {
    puts("No");
    return 0;
  }
  int hs = l - qs;
  if (hs % (q + 1) != 0) {
    puts("No");
    return 0;
  }
  int h = hs / (q + 1);
  int h1 = 0, h2 = 0, h3 = 0;
  int ps1;
  for (ps1 = 0; s[ps1] != 'Q'; ps1++) h1++;
  if (h1 & 1) {
    puts("No");
    return 0;
  }
  h1 >>= 1;
  for (int j = l - 1; s[j] != 'Q'; j--) h2++;
  if (h2 & 1) {
    puts("No");
    return 0;
  }
  h2 >>= 1;
  int ps2, cnt = 0;
  for (ps2 = ps1;; ps2++) {
    if (s[ps2] == 'Q') {
      cnt++;
      if (cnt == q) break;
    } else
      h3++;
  }
  int idx = 0;
  if (h3 + h1 + h2 != h) {
    puts("No");
    return 0;
  }
  while (h1--) s2[idx++] = 'H';
  for (int i = ps1; i <= ps2; i++) s2[idx++] = s[i];
  while (h2--) s2[idx++] = 'H';
  idx = 0;
  for (int i = 0; i < q + h; i++) {
    if (s2[i] == 'H')
      s1[idx++] = 'H';
    else {
      memcpy(s1 + idx, s2, q + h);
      idx += q + h;
    }
  }
  for (int i = 0; i < l; i++) {
    if (s[i] != s1[i]) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}
