private ReturnValue Helper(TreeNode p)
    {
        if (p == null)
            return new ReturnValue(Integer.MIN_VALUE,Integer.MIN_VALUE);

        if (p.left == null && p.right == null)
            return new ReturnValue(p.val,p.val);

        ReturnValue l = Helper(p.left);
        ReturnValue r = Helper(p.right);

        int within = Math.max(Math.max(l.within,r.within) + p.val,p.val);

        int temp0 = Math.max(l.all,r.all);
        int temp1 = p.val;

        if (l.within > 0 && r.within > 0)
            temp1 = p.val + l.within + r.within;
        else if (l.within <= 0 && r.within > 0)
            temp1 = p.val + r.within;
        else if (r.within <= 0 && l.within > 0)
            temp1 = p.val + l.within;

        int all = Math.max(temp0,temp1);

        return new ReturnValue(within,all);
    }