import java.io.*;
import java.util.*;


public class Solution {

	
	
	
	public static void main(String[] args) throws IOException {
		
		String num, digit, s, output;
		int num1, num2, score;
		score = 0;
		int input[][] = new int [5][2];
		int answer[] = new int [5];
		
		BufferedReader f = new BufferedReader(new FileReader("DATA2.txt"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("OUT2.txt")));

		for (int i = 0; i < 5; i++) {
			s = f.readLine();

			for (int j =0; j< s.length(); j++){
				digit = s.substring(j, j+1);
				if (digit.compareTo(" ") == 0) {
					num = s.substring(0, j);
					num1 = Integer.parseInt(num);
					num = s.substring(j+1);
					num2 = Integer.parseInt(num);
					input[i][0] = num1;
					input[i][1] = num2;
					break;
				}
				
			}
		}
		for (int k = 0; k < 5; k++){
			s = f.readLine();
			num1 =Integer.parseInt(s);
			answer[k] = num1;
		}
		
		for (int i = 0; i< 5; i++){
			if ((input[i][0] + input[i][1])== answer[i] ){
				score++;
			}
		}
		
		out.println(""+  score  + "\n"); 
		System.out.println(score);
		


	    f.close();
	    out.close();                                  // close the output file
	    System.exit(0); 
	}

}

