#include <bits/stdc++.h>
using namespace std;
short f[1000005][3][3];
char st[1000005];
int pos[1000005];
int lp[1000005];
int rp[1000005];
int n, m;
void pre() {
  int i, p = 0;
  for (i = 1; i <= n; ++i) switch (st[i]) {
      case '(': {
        pos[++p] = i;
        break;
      }
      case ')': {
        rp[pos[p]] = i;
        lp[i] = pos[p--];
        break;
      }
      case '0': {
        f[i][0][0] = 1;
        break;
      }
      case '1': {
        f[i][1][1] = 1;
        break;
      }
      default: {
        f[i][0][1] = f[i][1][0] = 1;
        break;
      }
    }
}
int dp() {
  int i, j, x, y, z, w, l, r;
  char ch;
  for (i = 1; i <= n; ++i)
    if (st[i] == ')') {
      if (st[i - 1] != ')') {
        ch = st[i - 2];
        l = i - 3, r = i - 1;
      } else {
        ch = st[lp[i - 1] - 1];
        l = lp[i - 1] - 2, r = i - 1;
      }
      for (x = 0; x < 2; ++x)
        for (y = 0; y < 2; ++y)
          if (f[l][x][y])
            for (z = 0; z < 2; ++z)
              for (w = 0; w < 2; ++w)
                if (f[r][z][w]) switch (ch) {
                    case '&': {
                      f[i][x & z][y & w] = 1;
                      break;
                    }
                    case '|': {
                      f[i][x | z][y | w] = 1;
                      break;
                    }
                    case '^': {
                      f[i][x ^ z][y ^ w] = 1;
                      break;
                    }
                  }
    }
  return f[n][0][1] || f[n][1][0];
}
int main() {
  scanf("%d", &m);
  scanf("%s", st + 1);
  n = strlen(st + 1);
  pre();
  if (dp())
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
