class Solution {
public:
    int maximalRectangle(vector<vector<char>>& f) {
        int rows = f.size(), cols = f[0].size();
        vector<int> a(cols,0);
        int fin = 0;
        for (int i = 0; i < rows; i++) {
          for (int j = 0; j < cols; j++) {
            if (f[i][j] == '1') a[j]++;
            else a[j] = 0;
          }
          for (auto j:a) cout << j << " ";
          cout << "\n";
          int n = cols;
          vector<int> pre(n,0);
          vector<int> suf(n,n - 1);
          stack<int> s;
          for (int i = 0; i < n; i++) {
            if (s.empty()) {
              s.push(i);
            }else {
              while (!s.empty() && a[s.top()] >= a[i]) s.pop();
              if (!s.empty()) pre[i] = s.top() + 1;
              s.push(i);
            }
          }
          while (!s.empty()) s.pop();

          for (int i = n - 1; i >= 0; i--) {
            if (s.empty()) {
              s.push(i);
            }else {
              while (!s.empty() && a[s.top()] >= a[i]) s.pop();
              if (!s.empty()) suf[i] = s.top() - 1;
              s.push(i);
            }
          }
          int ans = 0;
          for (int i = 0; i < n; i++) {
            ans = max(ans,(suf[i] - pre[i] + 1) * a[i]);
            ans = max(ans,a[i]);
          }
          fin = max(fin,ans);
        }
        return fin;
    }
};