#include <bits/stdc++.h>
using namespace std;
constexpr uint64_t mod = (1ull << 61) - 1;
inline uint64_t mult(uint64_t a, uint64_t b) {
  uint64_t l1 = (uint32_t)a, h1 = a >> 32, l2 = (uint32_t)b, h2 = b >> 32;
  uint64_t l = l1 * l2, m = l1 * h2 + l2 * h1, h = h1 * h2;
  uint64_t ret =
      (l & mod) + (l >> 61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
  ret = (ret & mod) + (ret >> 61);
  ret = (ret & mod) + (ret >> 61);
  return ret - 1;
}
inline unsigned long long add(unsigned long long a, unsigned long long b) {
  if ((a += b) >= mod) a -= mod;
  return a;
}
inline unsigned long long dec(unsigned long long a, unsigned long long b) {
  return add(a, mod - b);
}
int n;
char s[1000010];
unsigned long long pw[1000010], hs[1000010];
unsigned long long ppw;
inline unsigned long long geths(int l, int r) {
  return dec(hs[r], mult(hs[l - 1], pw[r - l + 1]));
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  pw[0] = 1;
  for (int i = 1; i <= n; i++) pw[i] = mult(pw[i - 1], 29);
  for (int i = 1; i <= n; i++) hs[i] = add(mult(hs[i - 1], 29), s[i] - 'A');
  bool flag = 1;
  int cntH = 0, cntQ = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'H')
      cntH++;
    else
      cntQ++;
  }
  int tmp = round(sqrt(cntQ));
  if (tmp * tmp != cntQ) {
    puts("No");
    return 0;
  }
  cntQ = tmp;
  if (cntH % (cntQ + 1) != 0) {
    puts("No");
    return 0;
  }
  cntH /= (cntQ + 1);
  int tot = cntH + cntQ;
  if (!cntQ) {
    puts("Yes");
    return 0;
  }
  unsigned long long ppw;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'Q') {
      if (!(i & 1)) {
        puts("No");
        return 0;
      }
      ppw = geths(i - (i - 1) / 2, i - (i - 1) / 2 + tot - 1);
      break;
    }
  }
  int cntp = 0;
  for (int i = 1; i + tot - 1 <= n; i++) {
    if (geths(i, i + tot - 1) == ppw) {
      i += tot - 1;
      cntp++;
    } else if (s[i] == 'Q') {
      puts("No");
      return 0;
    }
  }
  if (cntQ != cntp) {
    puts("No");
    return 0;
  }
  puts("Yes");
  return 0;
}
