// The "File_Create" class.
import java.awt.*;
import java.io.*;
public class Dwite2
{

    public static void main (String[] args) throws IOException
    {
	BufferedReader br = new BufferedReader (new FileReader ("DATA2.txt"));
	PrintWriter pw = new PrintWriter (new FileWriter ("OUT2.txt"));
	int str[] = new int [5];
	String str2[] = new String [5];
	String str3[] [] = new String [5] [2];
	
	for (int i = 0 ; i < 5 ; i++)
	{
	int count = 0;    
	for (int j = 0 ; j < 5 ; j++)
		str3 [j] = br.readLine ().split (" ");
	    for (int k = 0 ; k < 5 ; k++)
		str [k] = Integer.parseInt (br.readLine () + "");
	    for (int k = 0 ; k < 5 ; k++)
	    {
		if ((Integer.parseInt (str3 [k] [0]) + (Integer.parseInt (str3 [k] [1])) == str [k]))
		    count += 1;
	    }
	    pw.println (count);
	}


	pw.close ();
	// Place your program here.  'c' is the output console
    } // main method
} // File_Create class



