#include <iostream>

using namespace std;

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

int treeHeight(TNode *pNode) {
  if(pNode==NULL)
    return 0;

  int lHeight = treeHeight(pNode->m_pLeft);
  int rHeight = treeHeight(pNode->m_pRight);

  if(lHeight>rHeight)
    return lHeight+1;
  else
    return rHeight+1;
}

bool isBalancedTree(TNode *pRoot) {

  if(pRoot==NULL)
    return true;

  int lHeight = treeHeight(pRoot->m_pLeft);
  int rHeight = treeHeight(pRoot->m_pRight);

  if(lHeight-rHeight>1 || rHeight-lHeight>1)
    return false;

  return isBalancedTree(pRoot->m_pLeft) && isBalancedTree(pRoot->m_pRight);
}



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


  return 0;
}
