import java.util.*;

public class Solution {    
    public int sum(TreeNode root, int sum){
        if(root == null)return 0;
        int temp=0;
        if(root.val == sum)temp++;
        return temp+sum(root.left, sum - root.val)+sum(root.right, sum - root.val);
    }
    
    public int FindPath (TreeNode root, int sum) {
        // write code here
        int ans = 0;
        if(root == null)return 0;
        ans += sum(root,sum);
        ans += FindPath(root.left, sum);
        ans += FindPath(root.right, sum);
        return ans;
    }
    
}