#include <iostream>

using namespace std;

bool is_bst_post_sequence(int *numbers, int length) {

  if(numbers==NULL || length<1)
    return true;

  int root = numbers[length-1];

  int boundary1 = 0;
  for(; boundary1 < length-1; boundary1++) {
    if(numbers[boundary1] > root)
      break;
  }

  int boundary2 = boundary1;
  for(; boundary2 < length-1; boundary2++) {
    if(numbers[boundary2] < root)
      return false;
  }

  bool left = true;
  if(boundary1>0) {
    left = is_bst_post_sequence(numbers, boundary1);
  }

  bool right = true;
  if(boundary1<length-1) {
    right = is_bst_post_sequence(numbers+boundary1, length-boundary1-1);
  }

  return left&&right;
}

int main(int argc, char **argv) {

  return 0;
}
