public void solve() throws IOException {
    int n = nextInt();
    int[] cur = new int[2];

    boolean cando = true;
    for (int x = 0; x < n; x++) {
      int a = nextInt();
      if (a == 25)
        cur[0]++;
      else if (a == 50) {
        cur[1]++;
        cur[0]--;
      } else if (a == 100) {
        cur[0]--;
        if (cur[1] > 0)
          cur[1]--;
        else
          cur[0] -= 2;
      }
      if (cur[0] < 0) {
        cando = false;
        break;
      }
    }

    if (cando)
      out.println("YES");
    else
      out.println("NO");

  }