import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().split(",");
        int a = Integer.valueOf(str[str.length - 1]);//标杆值
        int[] v = new int[str.length - 1];
        for(int i = 0; i < v.length; ++i) v[i] = Integer.valueOf(str[i]);
        int r = 0;
        for(int i = 0; i < v.length - 1; ++i){
            for(int j = i + 1; j < v.length; ++j){
                if(v[i] + v[j] == a) r += i + j;//遍历就行了
            }
        }
        System.out.println(r);
    }
}