//Vishaan Saxena
//13 March 2020
//Int 5
//Enloe
//Potter
//Contest #3
#include 
#include 
#include 
using namespace std;

int temp[4][4];

void OR(int one[4][4], int two[4][4])
{
    for (int i= 0; i < 4; i++)
    {
        for(int j = 0; j < 4; j++)
        {
            if (one[i][j] == 1 ||two[i][j] ==1)
            {
                temp[i][j] = 1;
            }
            else
            {
                temp[i][j] = 0;
            }
        }
    }
    return;
}

bool modify(char blah, int maker[4][4], bool prime)
{
        for (int k = 0; k < 4; k++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (prime == true)
                {
                    if (blah == 'A')
                    {
                        if (j < 2)
                        {
                            maker[k][j] = 0;
                        }
                    }
                    if (blah == 'B')
                    {
                        if (k < 2)
                        {
                            maker[k][j] = 0;
                        }
                    }
                    if (blah == 'C')
                    {
                        if (j ==1 || j ==2)
                        {
                            maker[k][j] = 0;
                        }
                    }
                    if (blah == 'D')
                    {
                        if (k == 1 ||k == 2)
                        {
                            maker[k][j] = 0;
                        }
                    }
                }
                if (prime == false)
                {
                    if (blah == 'A')
                    {
                        if (j > 1)
                        {
                            maker[k][j] = 0;
                        }
                    }
                    if (blah == 'B')
                    {
                        if (k > 1)
                        {
                            maker[k][j] = 0;
                        }
                    }
                    if (blah == 'C')
                    {
                        if (j ==0 || j ==3)
                        {
                            maker[k][j] = 0;
                        }
                    }
                    if (blah == 'D')
                    {
                        if (k == 0 ||k == 3)
                        {
                            maker[k][j] = 0;
                        }
                    }
                }
            }
        }
    prime = false;
    return prime;
}

string yurnt(string input)
{
    int i = 0;
    int length = input.length();
    int maker[4][4];
    int temp1[4][4];
    bool prime = false;
    for (int y =0; y < 4; y++)
    {
        for (int z =0; z < 4; z++)
        {
            temp1[y][z]= 0;
        }
    }
    while (i < length)
    {
        for (int k = 0; k < 4; k++)
        {
            for (int j = 0; j < 4; j++)
            {
                maker[k][j] = 1;
            }
        }
        while (input[i] != '+' && (i < length))
        {
            if ((char)input[i] == '~')
            {
                prime = true;
                i++;
            }
            if ((char)input[i] == 'A'||(char)input[i] == 'B'||(char)input[i] == 'C'||(char)input[i] == 'D')
            {
                prime = modify(input[i], maker, prime);
                i++;
            }
        }
        if (input[i] == '+' || i == length)
        {
           OR(temp1, maker);
           for (int y =0; y <4; y++)
           {
               for (int z = 0; z<4; z++)
               {
                   temp1[y][z] = temp[y][z];
               }
           }
           i++;
        }
    }
    cout< 9)
        {
        finale = finale + (char)(counter+55);
        }
        counter = 0;

    }
    return finale;
}
int main()
{
    int z = 1;
    string input;
    ifstream infile;
    infile.open("F:\\3int.txt");
	if (infile.is_open())
	{
		while (infile.good())
		{
		    infile >> input;
		    cout<