/*Tommy Smith
March 13, 2020
Sen5
Enloe
Potter
Contest #3*/
#include 
#include 
#include 
#include 
using namespace std;
string getAddress(int x, int y){
    if(x==0&&y==0){
        return "AB~C~D";
    }
    if(x==0&&y==1){
        return "ABC~D";
    }
    if(x==0&&y==2){
        return "~ABC~D";
    }
    if(x==0&&y==3){
        return "~AB~C~D";
    }
    if(x==1&&y==0){
        return "AB~CD";
    }
    if(x==1&&y==1){
        return "ABCD";
    }
    if(x==1&&y==2){
        return "~ABCD";
    }
    if(x==1&&y==3){
        return "~AB~CD";
    }
    if(x==2&&y==0){
        return "A~B~CD";
    }
    if(x==2&&y==1){
        return "A~BCD";
    }
    if(x==2&&y==2){
        return "~A~BCD";
    }
    if(x==2&&y==3){
        return "~A~B~CD";
    }
    if(x==3&&y==0){
        return "A~B~C~D";
    }
    if(x==3&&y==1){
        return "A~BC~D";
    }
    if(x==3&&y==2){
        return "~A~BC~D";
    }
    if(x==3&&y==3){
        return "~A~B~C~D";
    }
}
string getAddress8(int x, int config){
    if(config == 0){
        if(x == 0){
            return "B";
        }
        if(x==1){
            return "D";
        }
        if(x==2){
            return "~B";
        }
    }else if(config == 1){
        if(x==0){
            return "A";
        }
        if(x==1){
            return "C";
        }
        if(x==2){
            return "~A";
        }
    }
}
string getAddress4(int x, int config, int y){
    if (config == 0){
        if(x == 0){
            return "B~D";
        }
        if(x==1){
            return "BD";
        }
        if(x==2){
            return "~BD";
        }
        if(x==3){
            return "~B~D";
        }
    }else if(config == 1){
        if(x==0){
            return "A~C";
        }
        if(x==1){
            return "AC";
        }
        if(x==2){
            return "~AC";
        }
        if(x==3){
            return "~A~C";
        }
    }else if(config == 2){
        if(x==0&&y==0){
            return "AB";
        }
        if(x==0&&y==1){
            return "BC";
        }
        if(x==0&&y==2){
            return "~AB";
        }
        if(x==1&&y==0){
            return "AD";
        }
        if(x==1&&y==1){
            return "CD";
        }
        if(x==1&&y==2){
            return "~AD";
        }
        if(x==2&&y==0){
            return "A~B";
        }
        if(x==2&&y==1){
            return "~BC";
        }
        if(x==2&&y==2){
            return "~A~B";
        }
    }else if(config == 3){
        if(x==0){
            return "B~C";
        }
        if(x==1){
            return "~CD";
        }
        if(x==2){
            return "~B~C";
        }
    }else if(config == 4){
        if(x==0){
            return "A~D";
        }
        if(x==1){
            return "C~D";
        }
        if(x==2){
            return "~A~D";
        }
    }
}
string getAddress2(int x, int config, int y){
    if(config==0){
        if(x==0&&y==0){
           return "AB~D";
        }
        if(x==0&&y==1){
            return "BC~D";
        }
        if(x==0&&y==2){
            return "~AB~D";
        }
        if(x==1&&y==0){
            return "ABD";
        }
        if(x==1&&y==1){
            return "BCD";
        }
        if(x==1&&y==2){
            return "~ABD";
        }
        if(x==2&&y==0){
            return "A~BD";
        }
        if(x==2&&y==1){
            return "~BCD";
        }
        if(x==2&&y==2){
            return "~A~BD";
        }
        if(x==3&&y==0){
            return "A~B~D";
        }
        if(x==3&&y==1){
            return "~BC~D";
        }
        if(x==3&&y==2){
            return "~A~B~D";
        }
    }else if(config == 1){
        if(x==0&&y==0){
            return "AB~C";
        }
        if(x==1&&y==0){
            return "A~CD";
        }
        if(x==2&&y==0){
            return "A~B~C";
        }
        if(x==0&&y==1){
            return "ABC";
        }
        if(x==1&&y==1){
            return "ACD";
        }
        if(x==2&&y==1){
            return "A~BC";
        }
        if(x==0&&y==2){
            return "~ABC";
        }
        if(x==1&&y==2){
            return "~ACD";
        }
        if(x==2&&y==2){
            return "~A~BC";
        }
        if(x==0&&y==3){
            return "~AB~C";
        }
        if(x==1&&y==3){
            return "~A~CD";
        }
        if(x==2&&y==3){
            return "~A~B~C";
        }
    }else if(config == 2){
        if(x==0){
            return "A~C~D";
        }
        if(x==1){
            return "AC~D";
        }
        if(x==2){
            return "~AC~D";
        }
        if(x==3){
            return "~A~C~D";
        }
    }else if(config == 3){
        if(x==0){
            return "B~C~D";
        }
        if(x==1){
            return "B~CD";
        }
        if(x==2){
            return "~B~CD";
        }
        if(x==3){
            return "~B~C~D";
        }
    }
}
string eight(bool arr[4][4]){
    for(int i = 0; i < 3; i++){
        if(arr[i][0]&&arr[i][1]&&arr[i][2]&&arr[i][3]&&arr[i+1][0]&&arr[i+1][1]&&arr[i+1][2]&&arr[i+1][3]){///Rows
            arr[i][0] = arr[i][1] = arr[i][2] = arr[i][3] = arr[i+1][0] = arr[i+1][1] = arr[i+1][2] = arr[i+1][3] = false;
            return getAddress8(i,0);
        }
    }
    for(int i = 0; i < 3; i++){
        if(arr[0][i]&&arr[1][i]&&arr[2][i]&&arr[3][i]&&arr[0][i+1]&&arr[1][i+1]&&arr[2][i+1]&&arr[3][i+1]){///Columns
            arr[0][i] = arr[1][i] = arr[2][i] = arr[3][i] = arr[0][i+1] = arr[1][i+1] = arr[2][i+1] = arr[3][i+1] = false;
            return getAddress8(i,1);
        }
    }
    if(arr[0][0]&&arr[1][0]&&arr[2][0]&&arr[3][0]&&arr[0][3]&&arr[1][3]&&arr[2][3]&&arr[3][3]){///Adjacent Rows
        arr[0][0]=arr[1][0]=arr[2][0]=arr[3][0]=arr[0][3]=arr[1][3]=arr[2][3]=arr[3][3]=false;
        return "~C";
        }
    if(arr[0][0]&&arr[0][1]&&arr[0][2]&&arr[0][3]&&arr[3][0]&&arr[3][1]&&arr[3][2]&&arr[3][3]){///Adjacent Columns
        arr[0][0]=arr[0][1]=arr[0][2]=arr[0][3]=arr[3][0]=arr[3][1]=arr[3][2]=arr[3][3]=false;
        return "~D";
    }
    return "none";
}
string four(bool arr[4][4]){
    for(int i = 0; i < 4; i++){
        if(arr[i][0]&&arr[i][1]&&arr[i][2]&&arr[i][3]){///Rows
            arr[i][0]=arr[i][1]=arr[i][2]=arr[i][3]=false;
            return getAddress4(i,0,0);
        }
    }
    for(int i = 0; i < 4; i++){
        if(arr[0][i]&&arr[1][i]&&arr[2][i]&&arr[3][i]){///Columns
            arr[0][i]=arr[1][i]=arr[2][i]=arr[3][i]=false;
            return getAddress4(i,1,0);
        }
    }
    for(int i = 0; i<3; i++){
        for (int j = 0; j < 3; j++){
            if(arr[i][j]&&arr[i][j+1]&&arr[i+1][j]&&arr[i+1][j+1]){///Box
                arr[i][j]=arr[i][j+1]=arr[i+1][j]=arr[i+1][j+1]=false;
                return getAddress4(i,2,j);
            }
        }
    }
    for(int i = 0; i<3; i++){
        if(arr[i][0]&&arr[i+1][0]&&arr[i][3]&&arr[i+1][3]){///Adjacent Rows
            arr[i][0]=arr[i+1][0]=arr[i][3]=arr[i+1][3]=false;
            return getAddress4(i,3,0);
        }
    }
    for(int i = 0; i<3; i++){
        if(arr[0][i]&&arr[0][i+1]&&arr[3][i]&&arr[3][i+1]){///Adjacent Columns
            arr[0][i]=arr[0][i+1]=arr[3][i]=arr[3][i+1]=false;
            return getAddress4(i,4,0);
        }
    }
    if(arr[0][0]&&arr[0][3]&&arr[3][0]&&arr[3][3]){///Corners
        arr[0][0]=arr[0][3]=arr[3][0]=arr[3][3]=false;
        return "~C~D";
    }
    return "none";
}
string two(bool arr[4][4]){
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 3; j++){
            if(arr[i][j]&&arr[i][j+1]){///Rows
                arr[i][j]=arr[i][j+1]=false;
                return getAddress2(i,0,j);
            }
        }
    }
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 4; j++){
            if(arr[i][j]&&arr[i+1][j]){///Columns
                arr[i][j]=arr[i+1][j]=false;
                return getAddress2(i,1,j);
            }
        }
    }
    for(int i = 0; i < 4; i++){
        if(arr[i][0]&&arr[i][3]){///Adjacent Rows
            arr[i][0]=arr[i][3]=false;
            return getAddress2(i,3,0);
        }
    }
    for(int i = 0; i < 4; i++){
        if(arr[0][i]&&arr[3][i]){///Adjacent Columns
            arr[0][i]=arr[3][i]=false;
            return getAddress2(i,2,0);
        }
    }
    return "none";
}
void debug(bool arr[4][4]){
    for(int i = 0; i < 4; i++){
        for(int j = 0; j <4; j++){
            cout << arr[i][j] << "    ";
        }
        cout << endl;
    }
    cout << endl << endl;
}
string out(bool arr[4][4]){
    string output = "";
    string temp = "y";
    while(temp != "none"){
         temp = eight(arr);
         if(temp != "none")
            output = output + temp + "+";
    }
    temp = "y";
    while(temp != "none"){
         temp = four(arr);
         if(temp != "none")
            output = output + temp + "+";
    }
    temp = "y";
    while(temp!="none"){
        temp = two(arr);
        if(temp != "none")
            output = output + temp + "+";
    }
    temp = "y";
    for(int i = 0; i < 4; i++){
        for (int j = 0; j < 4; j++){
            if(arr[i][j]){
                arr[i][j] = false;
                output = output + getAddress(i,j) + "+";
            }
        }
    }
    output = output.substr(0,output.length()-1);
    return output;
}
void fillArray(string input, bool arr[4][4]){
    for(int i = 0; i < 4; i++){
        if(input[i]=='0'){
            arr[i][0] = false;
            arr[i][1] = false;
            arr[i][2] = false;
            arr[i][3] = false;
        }
        else if(input[i]=='1'){
            arr[i][0] = false;
            arr[i][1] = false;
            arr[i][2] = false;
            arr[i][3] = true;
        }
        else if(input[i]=='2'){
            arr[i][0] = false;
            arr[i][1] = false;
            arr[i][2] = true;
            arr[i][3] = false;
        }
        else if(input[i]=='3'){
            arr[i][0] = false;
            arr[i][1] = false;
            arr[i][2] = true;
            arr[i][3] = true;
        }
        else if(input[i]=='4'){
            arr[i][0] = false;
            arr[i][1] = true;
            arr[i][2] = false;
            arr[i][3] = false;
        }
        else if(input[i]=='5'){
            arr[i][0] = false;
            arr[i][1] = true;
            arr[i][2] = false;
            arr[i][3] = true;
        }
        else if(input[i]=='6'){
            arr[i][0] = false;
            arr[i][1] = true;
            arr[i][2] = true;
            arr[i][3] = false;
        }
        else if(input[i]=='7'){
            arr[i][0] = false;
            arr[i][1] = true;
            arr[i][2] = true;
            arr[i][3] = true;
        }
        else if(input[i]=='8'){
            arr[i][0] = true;
            arr[i][1] = false;
            arr[i][2] = false;
            arr[i][3] = false;
        }
        else if(input[i]=='9'){
            arr[i][0] = true;
            arr[i][1] = false;
            arr[i][2] = false;
            arr[i][3] = true;
        }
        else if(input[i]=='A'){
            arr[i][0] = true;
            arr[i][1] = false;
            arr[i][2] = true;
            arr[i][3] = false;
        }
        else if(input[i]=='B'){
            arr[i][0] = true;
            arr[i][1] = false;
            arr[i][2] = true;
            arr[i][3] = true;
        }
        else if(input[i]=='C'){
            arr[i][0] = true;
            arr[i][1] = true;
            arr[i][2] = false;
            arr[i][3] = false;
        }
        else if(input[i]=='D'){
            arr[i][0] = true;
            arr[i][1] = true;
            arr[i][2] = false;
            arr[i][3] = true;
        }
        else if(input[i]=='E'){
            arr[i][0] = true;
            arr[i][1] = true;
            arr[i][2] = true;
            arr[i][3] = false;
        }
        else if(input[i]=='F'){
            arr[i][0] = true;
            arr[i][1] = true;
            arr[i][2] = true;
            arr[i][3] = true;
        }

    }
}
int main(){
    string input, output, input1;
    ifstream infile("F:\\3sr.txt");
    bool arr [4][4];
    for (int i = 0; i < 4; i++){
        for(int j = 0; j < 4; j++){
            arr[i][j] = false;
        }
    }
    while(infile.good()){
        getline(infile, input);
        fillArray(input,arr);
        output = out(arr);
        cout << output << endl;
    }
    return 0;
}