#include <iostream>

using namespace std;

struct TNode {
  int m_nVal;
  TNode *m_pLeft;
  TNode *m_pRight;
};

bool isBalanced(TNode *pRoot, int *depth) {

  if(pRoot==NULL) {
    *depth=0;
    return true;
  }

  int lDepth, rDepth;
  if(isBalanced(pRoot->m_pLeft, &lDepth) && isBalanced(pRoot->m_pRight, &rDepth)) {
    int diff = lDepth-rDepth;
    if(diff<=1 && diff>=-1) {
      *depth = (diff>0?lDepth:rDepth)+1;
      return true;
    }
  }

  return false;  

}

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

  return 0;
}
