description: You have received data from a Bubble bot. You know your task is to make factory facilities, but before you even start, you need to know how big the factory is and how many rooms it has. When you look at the data you see that you have the dimensions of the construction, which is in rectangle shape: N x M. 
  
  Then in the next N lines you have M numbers. These numbers represent factory tiles and they can go from 0 to 15. Each of these numbers should be looked in its binary form. Because from each number you know on which side the tile has walls. For example number 10 in it's binary form is 1010, which means that it has a wall from the North side, it doesn't have a wall from the East, it has a wall on the South side and it doesn't have a wall on the West side. So it goes North, East, South, West. 
  
  It is guaranteed that the construction always has walls on it's edges. The input will be correct. 
  
  Your task is to print the size of the rooms from biggest to smallest. 
  
  Input
  
  The first line has two numbers which are N and M, the size of the construction. Both are integers: 
  
  n (1 ≤ n ≤ 10^3)
  
  m (1 ≤ m ≤ 10^3)
  
  Next N x M numbers represent each tile of construction.
  
  Output
  
  Once you finish processing the data your output consists of one line sorted from biggest to smallest room sizes. 
  
  Example
  
  Input
  
  
  4 5
  9 14 11 12 13
  5 15 11 6 7
  5 9 14 9 14
  3 2 14 3 14
  
  
  Output
  
  
  9 4 4 2 1 
solution: #include <bits/stdc++.h>
  namespace hyy {
  const int MAXSIZE = 1 << 20;
  inline char gc() {
    return getchar();
    static char buf[MAXSIZE];
    static char *p1 = buf + MAXSIZE;
    static char *p2 = buf + MAXSIZE;
    if (p1 == p2) {
      p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
    }
    if (p1 == p2) {
      return -1;
    }
    return *p1++;
  }
  inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  template <class T>
  inline void read(T &x) {
    register double tmp = 1;
    register bool sign = 0;
    x = 0;
    register char ch = gc();
    for (; !(ch >= '0' && ch <= '9'); ch = gc()) {
      if (ch == '-') {
        sign = 1;
      }
    }
    for (; (ch >= '0' && ch <= '9'); ch = gc()) {
      x = (x << 1) + (x << 3) + (ch ^ 48);
    }
    if (ch == '.') {
      for (ch = gc(); (ch >= '0' && ch <= '9'); ch = gc()) {
        tmp /= 10.0;
        x += tmp * (ch - 48);
      }
    }
    if (sign) {
      x = -x;
    }
  }
  inline void read(char *s) {
    register char ch = gc();
    for (; blank(ch); ch = gc())
      ;
    for (; !blank(ch); ch = gc()) {
      *s++ = ch;
    }
    *s = 0;
  }
  inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
      ;
  }
  inline void push(const char &c) {
    char pbuf[MAXSIZE];
    char *pp = pbuf;
    if (pp - pbuf == MAXSIZE) {
      fwrite(pbuf, 1, MAXSIZE, stdout);
      pp = pbuf;
    }
    *pp++ = c;
  }
  template <class T>
  inline void write(T x) {
    static T sta[35];
    T top = 0;
    do {
      sta[top++] = x % 10;
      x /= 10;
    } while (x);
    while (top) {
      putchar(sta[--top] + '0');
    }
    return;
    while (top) {
      push(sta[--top] + '0');
    }
  }
  template <class T>
  inline void write(T x, char lastChar) {
    write(x);
    putchar(lastChar);
  }
  }  // namespace hyy
  using namespace hyy;
  using namespace std;
  using namespace std;
  struct MapBool {
    vector<long long> A[10000007];
    inline bool Find(long long x) {
      long long p = x % 10000007;
      for (register int i = 0; i < A[p].size(); ++i) {
        if (A[p][i] == x) {
          return true;
        }
      }
      return false;
    }
    inline void Insert(long long x) {
      long long p = x % 10000007;
      A[p].push_back(x);
    }
  };
  struct MapInt {
    struct NODE {
      long long key;
      int num;
    };
    vector<NODE> A[10000007];
    inline int Find(long long x) {
      long long p = x % 10000007;
      for (register int i = 0; i < A[p].size(); ++i) {
        if (A[p][i].key == x) {
          return A[p][i].num;
        }
      }
      return -1;
    }
    inline void Insert(long long x, int w) {
      long long p = x % 10000007;
      A[p].push_back(NODE{x, w});
    }
  };
  MapInt f;
  int n, m;
  int a[1005][1005];
  bool vis[1005][1005];
  int cnt;
  void Dfs(int x, int y) {
    if (vis[x][y]) {
      return;
    }
    if (x > n || y > m || x == 0 || y == 0) {
      return;
    }
    vis[x][y] = true;
    cnt++;
    if ((a[x][y] >> 3 & 1) == 0) {
      Dfs(x - 1, y);
    }
    if ((a[x][y] >> 2 & 1) == 0) {
      Dfs(x, y + 1);
    }
    if ((a[x][y] >> 1 & 1) == 0) {
      Dfs(x + 1, y);
    }
    if ((a[x][y] >> 0 & 1) == 0) {
      Dfs(x, y - 1);
    }
  }
  int main() {
    read(n);
    read(m);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        read(a[i][j]);
      }
    }
    vector<int> Q;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (vis[i][j] == false) {
          cnt = 0;
          Dfs(i, j);
          Q.push_back(-cnt);
        }
      }
    }
    sort(Q.begin(), Q.end());
    for (int i = 0; i < Q.size(); i++) {
      cout << -Q[i] << " ";
    }
    return 0;
  }
  