#include <iostream>
using namespace std;

int INPUT_SIZE = 1377;
char m[1900][700];
bool isTouched[1900][700];

// x = 454..626, y = 3..1851
int main() {
  int min_y = 1000000, max_y = 0, min_x = 500, max_x = 500, result = 0, result2 = 0;
  for (int i = 0; i < 1900; i++)
    for (int j = 0; j < 700; j++) {
      m[i][j] = '.';
      isTouched[i][j] = false;
    }
  m[0][500] = '+'; // source

  for (int i = 0; i < INPUT_SIZE; i++) {
    char c1, c2;
    int a1, a2, a3;
    scanf("%c=%d, %c=%d..%d\n", &c1, &a1, &c2, &a2, &a3);
    if (c1 == 'x') {
      if (min_x > a1) min_x = a1;
      if (max_x < a1) max_x = a1;
      if (min_y > a2) min_y = a2;
      if (max_y < a2) max_y = a3;
      for (int j = a2; j <= a3; j++) {
        m[j][a1] = '#';
      }
    } else {
      if (min_y > a1) min_y = a1;
      if (max_y < a1) max_y = a1;
      if (min_x > a2) min_x = a2;
      if (max_x < a2) max_x = a3;
      for (int j = a2; j <= a3; j++) {
        m[a1][j] = '#';
      }
    }
  }

  for(int i = 0; i < 200000; i++) { // try to drop droplets
    int tmp_x, cur_x = 500, cur_y = 0, ctx = 0; // the start of droplets
    bool isLeft = true;
    while(true) {
      ctx++;
      if (cur_y > max_y) break;
      isTouched[cur_y][cur_x] = true;
      if(m[cur_y + 1][cur_x] == '.') {
        cur_y++;
        isLeft = rand() % 2; // reset direction
        continue;
      }
      if (isLeft) {
        if (m[cur_y][cur_x-1] == '~') {
          m[cur_y][cur_x] = '~';
          // Fill the opposite side
          tmp_x = cur_x;
          while (m[cur_y][tmp_x+1] == '.') {
            tmp_x++;
            m[cur_y][tmp_x] = '~';
            isTouched[cur_y][tmp_x] = true;
          }
          break;
        } else if (m[cur_y][cur_x-1] != '#') {
          cur_x--;
          continue;
        }
      } else {
        if (m[cur_y][cur_x+1] == '~') {
          m[cur_y][cur_x] = '~';
          // Fill the opposite side
          tmp_x = cur_x;
          while (m[cur_y][tmp_x-1] == '.') {
            tmp_x--;
            m[cur_y][tmp_x] = '~';
            isTouched[cur_y][tmp_x] = true;
          }
          break;
        } else if (m[cur_y][cur_x+1] != '#') {
          cur_x++;
          continue;
        }
      }
      // We hit the wall or another water
      if (ctx >= 10000) { // steady-state
        m[cur_y][cur_x] = '~';
        // Fill the opposite side
        tmp_x = cur_x;
        if (isLeft) {
          while (m[cur_y][tmp_x+1] == '.') {
            tmp_x++;
            m[cur_y][tmp_x] = '~';
            isTouched[cur_y][tmp_x] = true;
          }
        } else {
          while (m[cur_y][tmp_x-1] == '.') {
            tmp_x--;
            m[cur_y][tmp_x] = '~';
            isTouched[cur_y][tmp_x] = true;
          }
        }
        break;
      } else {
        isLeft = !isLeft;
      }
    }
  }
  
  for (int i = min_y; i <= max_y; i++) {
    for (int j = min_x; j <= max_x+2; j++){
      if (isTouched[i][j]) result++;
      if (m[i][j] == '~') result2++;
      /*
      if (m[i][j] == '.' && isTouched[i][j]) cout << 'x';
      else cout << m[i][j];
      */
    }
    // cout << endl;
  }
  
  cout << "Result: " << result << endl;
  cout << "Result 2: " << result2 << endl;

  return 0;
}
