import java.io.*;
import java.text.DecimalFormat;

// The "S2" class.
public class S2
{
    public static void main (String[] args) throws Exception
    {
	BufferedReader input = new BufferedReader (new FileReader ("DATA2.txt"));
	PrintWriter output = new PrintWriter (new FileWriter ("OUT2.txt"));

	int score = 0;
	for (int run = 1 ; run <= 5 ; run++)
	{

	    int[] sum = new int [5];
	    for (int inNum = 0 ; inNum < 5 ; inNum++)
	    {
		String[] in = input.readLine ().split (" ");
		sum [inNum] = Integer.parseInt (in [0]) + Integer.parseInt (in [1]);
	    }

	    for (int counter = 0 ; counter < 5 ; counter++)
	    {
		if (sum [counter] == Integer.parseInt (input.readLine ().trim ()))
		{
		    score++;
		}
	    }

	    output.println (score);
	    score = 0;
	}
	input.close ();
	output.close ();
    } // main method
} // S1 class

