#include <iostream>  
#include <fstream>  
#include <string>

using namespace std;

int main() {
    
    ifstream fp_in; 
    ofstream fp_out;
    fp_in.open("DATA2.txt");    
    fp_out.open("OUT2.txt");
    
    int intIn[5];
    int result[5];
    int intTemp = 0;
    int score = 0;
    
    for (int a = 0; a < 5; a++){
        intIn[a] = 0;
        result[a] = 0;
    }
    
    for (int i = 0; i < 5; i++) {
        
        for (int j = 0; j < 5; j++) {
            fp_in >> intIn[j];
            fp_in >> intTemp;
            intIn[j] = intIn[j] + intTemp;
        }
        
        for (int k = 0; k < 5; k++){
            fp_in >> result[k];
        }
        
        score = 0;
        for (int m = 0; m < 5; m++) {
            if (intIn[m] == result[m]){
                score = score + 1 ;
            }
        }
        fp_out << score << "\n";
    }
    
    
    fp_in.close();
    fp_out.close(); 
    
}

