import java.io.*;
import hsa.Console;
import java.util.StringTokenizer;
// The "Rhombus" class.
public class Mini
{
    public static void main (String[] args) throws IOException
    {

	// Open up the input and output file for IO purpose
	FileReader inFile = new FileReader ("DATA2.txt");
	FileWriter outFile = new FileWriter ("OUT2.txt");

	// Link the input and output file for
	BufferedReader in = new BufferedReader (inFile);
	BufferedWriter out = new BufferedWriter (outFile);

	// String e;
	int tally = 0;
	String line;
	int[] num = new int [5];
	// Keep reading as long as not end of file (eof)
	int set = 1;
	while (set <= 5)
	{
	    for (int count = 0 ; count < 5 ; count++)
	    {
		line = in.readLine ();

		StringTokenizer words = new StringTokenizer (line);
		String line1 = words.nextToken ();
		String line2 = words.nextToken ();
		int firstnum = Integer.parseInt (line1);
		int secondnum = Integer.parseInt (line2);
		int temptotal = firstnum + secondnum;
		num [count] = temptotal;
	    }
	    for (int count1 = 0 ; count1 < 5 ; count1++)
	    {
		line = in.readLine ();
		int result = Integer.parseInt (line);
		if (result == num [count1])
		{
		    tally++;
		}
	    }
	    set++;
	    out.write (tally + "");
	    out.newLine ();
	    tally = 0;



	}


	out.flush ();
	out.close ();

    }




}


// main method
// End of Class



