// Allison Hubbard
// 3/13/20
// Int 5
// Potter
// Contest #3
#include 
#include 
#include 
using namespace std;

int veitch[4][4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

void fill (char rc, int x1, int x2) {
  if (rc == 'r') {
    for (int r = 0; r < 4; r++) {
      veitch[x1][r]++;
      veitch[x2][r]++;
    }
  }
  else if (rc == 'c') {
    for (int c = 0; c < 4; c++) {
      veitch[c][x1]++;
      veitch[c][x2]++;
    }
  }
  return;
}
void equals (int &ctn, int (&sum)[4][4]) {
  for (int r = 0; r < 4; r++) {
    for (int c = 0; c < 4; c++) {
      if (veitch[r][c] == ctn) {veitch[r][c] = 1;}
      else {veitch[r][c] = 0;}
    }
  }
  for (int r = 0; r < 4; r++) {
    for (int c = 0; c < 4; c++) {
      sum[r][c] = sum[r][c] + veitch[r][c];
      veitch[r][c] = 0;
    }
  }
  ctn = 0;
  return;
}
void solve (string eq, int (&sum)[4][4]) {
  int place = 0;
  int countthenums = 0;
  while (place < eq.length()) {
    char now = eq[place];
    char next = eq[place+1];
    if (now != '+') {
      if (now == '~') {
        if (next == 'A') {fill ('c', 2, 3);}
        else if (next == 'B') {fill ('r', 2, 3);}
        else if (next == 'C') {fill ('c', 0, 3);}
        else if (next == 'D') {fill ('r', 0, 3);}
        place++;
      }
      else if (now == 'A') {fill ('c', 0, 1);}
      else if (now == 'B') {fill ('r', 0, 1);}
      else if (now == 'C') {fill ('c', 1, 2);}
      else if (now == 'D') {fill ('r', 1, 2);}
      countthenums++;
    }
    else {equals(countthenums, sum);}
    if (place == eq.length() - 1) {equals(countthenums, sum);}
    place++;
  }
  return;
}
char hex (int sum[4][4], int row) {
  int a = sum[row][0], b = sum[row][1], c = sum[row][2], d = sum[row][3];
  if (a == 0 && b == 0 && c == 0 && d == 0) {return '0';}
  else if (a == 0 && b == 0 && c == 0 && d != 0) {return '1';}
  else if (a == 0 && b == 0 && c != 0 && d == 0) {return '2';}
  else if (a == 0 && b == 0 && c != 0 && d != 0) {return '3';}
  else if (a == 0 && b != 0 && c == 0 && d == 0) {return '4';}
  else if (a == 0 && b != 0 && c == 0 && d != 0) {return '5';}
  else if (a == 0 && b != 0 && c != 0 && d == 0) {return '6';}
  else if (a == 0 && b != 0 && c != 0 && d != 0) {return '7';}
  else if (a != 0 && b == 0 && c == 0 && d == 0) {return '8';}
  else if (a != 0 && b == 0 && c == 0 && d != 0) {return '9';}
  else if (a != 0 && b == 0 && c != 0 && d == 0) {return 'A';}
  else if (a != 0 && b == 0 && c != 0 && d != 0) {return 'B';}
  else if (a != 0 && b != 0 && c == 0 && d == 0) {return 'C';}
  else if (a != 0 && b != 0 && c == 0 && d != 0) {return 'D';}
  else if (a != 0 && b != 0 && c != 0 && d == 0) {return 'E';}
  else if (a != 0 && b != 0 && c != 0 && d != 0) {return 'F';}
  else {return 'X';}
}

int main () {
  ifstream infile;
  infile.open("E:\\ACSL-3-int.txt", ifstream::in);
  //infile.open("F:\\3int.txt", ifstream::in);
  if (infile.is_open()) {
    while (infile.good()) {
      string equation;
      infile >> equation;
      int sum[4][4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
      solve(equation, sum);
      //cout << equation << endl;
      //cout << "  " << hex(sum, 0) << hex(sum, 1) << hex(sum, 2) << hex(sum, 3) << endl;
      cout << hex(sum, 0) << hex(sum, 1) << hex(sum, 2) << hex(sum, 3) << endl;
    }
  }
  return 0;
}