#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{

    string C1[] = {"0", "0", "0", "0", "0", "0", "0", "0"};
    string C2[] = {"0", "0", "0", "0", "0", "0", "0", "1"};
    string C3[] = {"0", "0", "0", "0", "0", "0", "1", "1"};
    string C4[] = {"0", "0", "0", "0", "0", "1", "1", "1"};
    string C5[] = {"0", "0", "0", "0", "1", "1", "1", "1"};
    string C6[] = {"0", "0", "0", "1", "1", "1", "1", "1"};
    string C7[] = {"0", "0", "1", "1", "1", "1", "1", "1"};
    string C8[] = {"0", "1", "1", "1", "1", "1", "1", "1"};
    string C9[] = {"1", "1", "1", "1", "1", "1", "1", "1"};

    ifstream fin;
    ofstream fout;

    fin.open("DATA3.txt", ios::in);
    fout.open("OUT3.txt", ios::out);

    string Line, L;
    int C = 0;

    for(int i = 1; i <= 5; i++)
    {

        C = 0;
        fin >> Line;

        do
        {
            L = (C1[0] + C1[1] + C1[2] + C1[3] + C1[4] + C1[5] + C1[6] + C1[7]).c_str();
            if(L.find(Line) == string::npos)
                for(int j = 0; j < L.length(); j++)
                    if(L[j] == '1')
                        C += 1;

        }
        while(next_permutation (C1,C1 + 8));

        do
        {
            L = (C2[0] + C2[1] + C2[2] + C2[3] + C2[4] + C2[5] + C2[6] + C2[7]).c_str();
            if(L.find(Line) != string::npos)
                for(int j = 0; j < L.length(); j++)
                    if(L[j] == '1')
                        C += 1;
        }
        while(next_permutation (C2,C2 + 8));

        do
        {
            L = (C3[0] + C3[1] + C3[2] + C3[3] + C3[4] + C3[5] + C3[6] + C3[7]).c_str();
            if(L.find(Line) != string::npos)
                for(int j = 0; j < L.length(); j++)
                    if(L[j] == '1')
                        C += 1;
        }
        while(next_permutation (C3,C3 + 8));

        do
        {
            L = (C4[0] + C4[1] + C4[2] + C4[3] + C4[4] + C4[5] + C4[6] + C4[7]).c_str();
            if(L.find(Line) != string::npos)
                for(int j = 0; j < L.length(); j++)
                    if(L[j] == '1')
                        C += 1;
        }
        while(next_permutation (C4,C4 + 8));

        do
        {
            L = (C5[0] + C5[1] + C5[2] + C5[3] + C5[4] + C5[5] + C5[6] + C5[7]).c_str();
            if(L.find(Line) != string::npos)
                for(int j = 0; j < L.length(); j++)
                    if(L[j] == '1')
                        C += 1;
        }
        while(next_permutation (C5,C5 + 8));

        do
        {
            L = (C6[0] + C6[1] + C6[2] + C6[3] + C6[4] + C6[5] + C6[6] + C6[7]).c_str();
            if(L.find(Line) != string::npos)
                for(int j = 0; j < L.length(); j++)
                    if(L[j] == '1')
                        C += 1;
        }
        while(next_permutation (C6,C6 + 8));

        do
        {
            L = (C7[0] + C7[1] + C7[2] + C7[3] + C7[4] + C7[5] + C7[6] + C7[7]).c_str();
            if(L.find(Line) != string::npos)
                for(int j = 0; j < L.length(); j++)
                    if(L[j] == '1')
                        C += 1;
        }
        while(next_permutation (C7,C7 + 8));

        do
        {
            L = (C8[0] + C8[1] + C8[2] + C8[3] + C8[4] + C8[5] + C8[6] + C8[7]).c_str();
            if(L.find(Line) != string::npos)
                for(int j = 0; j < L.length(); j++)
                    if(L[j] == '1')
                        C += 1;
        }
        while(next_permutation (C8,C8 + 8));

        do
        {
            L = (C9[0] + C9[1] + C9[2] + C9[3] + C9[4] + C9[5] + C9[6] + C9[7]).c_str();
            if(L.find(Line) != string::npos)
                for(int j = 0; j < L.length(); j++)
                    if(L[j] == '1')
                        C += 1;
        }
        while(next_permutation (C9,C9 + 8));

        fout << 1024 - C << endl;

    }



    return 0;

}



