Language: C++

using namespace std;
 
int main(){
 
    stack<int>S1;
    stack<pair<int, int> >S2;
    char ch;
    int sum = 0;
    for (int i = 0;cin>>ch; i++){
        if (ch == '\\')S1.push(i);
        else if (ch == '/' && S1.size() > 0){
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i - j;
            while (S2.size() > 0 && S2.top().first > j){
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }
 
 
    vector<int>ans;
    int t = 0;
    while (S2.size() > 0){ ans.push_back(S2.top().second); S2.pop(); }
    reverse(ans.begin(), ans.end());
    cout << sum << "\n";
    cout << ans.size();
    for (int i = 0; i < ans.size(); i++){
        cout << " ";
        t += ans[i];
        cout << ans[i];
    }cout << "\n";
 
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:5: error: 'stack' was not declared in this scope
    5 |     stack<int>S1;
      |     ^~~~~
a.cc:1:1: note: 'std::stack' is defined in header '<stack>'; this is probably fixable by adding '#include <stack>'
  +++ |+#include <stack>
    1 | using namespace std;
a.cc:5:11: error: expected primary-expression before 'int'
    5 |     stack<int>S1;
      |           ^~~
a.cc:6:11: error: 'pair' was not declared in this scope
    6 |     stack<pair<int, int> >S2;
      |           ^~~~
a.cc:1:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | using namespace std;
a.cc:6:16: error: expected primary-expression before 'int'
    6 |     stack<pair<int, int> >S2;
      |                ^~~
a.cc:9:20: error: 'cin' was not declared in this scope
    9 |     for (int i = 0;cin>>ch; i++){
      |                    ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:10:24: error: 'S1' was not declared in this scope
   10 |         if (ch == '\\')S1.push(i);
      |                        ^~
a.cc:11:31: error: 'S1' was not declared in this scope
   11 |         else if (ch == '/' && S1.size() > 0){
      |                               ^~
a.cc:15:20: error: 'S2' was not declared in this scope
   15 |             while (S2.size() > 0 && S2.top().first > j){
      |                    ^~
a.cc:18:13: error: 'S2' was not declared in this scope
   18 |             S2.push(make_pair(j, a));
      |             ^~
a.cc:18:21: error: 'make_pair' was not declared in this scope
   18 |             S2.push(make_pair(j, a));
      |                     ^~~~~~~~~
a.cc:18:21: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:23:5: error: 'vector' was not declared in this scope
   23 |     vector<int>ans;
      |     ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:23:12: error: expected primary-expression before 'int'
   23 |     vector<int>ans;
      |            ^~~
a.cc:25:12: error: 'S2' was not declared in this scope
   25 |     while (S2.size() > 0){ ans.push_back(S2.top().second); S2.pop(); }
      |            ^~
a.cc:25:28: error: 'ans' was not declared in this scope
   25 |     while (S2.size() > 0){ ans.push_back(S2.top().second); S2.pop(); }
      |                            ^~~
a.cc:26:13: error: 'ans' was not declared in this scope
   26 |     reverse(ans.begin(), ans.end());
      |             ^~~
a.cc:26:5: error: 'reverse' was not declared in this scope
   26 |     reverse(ans.begin(), ans.end());
      |     ^~~~~~~
a.cc:27:5: error: 'cout' was not declared in this scope
   27 |     cout << sum << "\n";
      |     ^~~~
a.cc:27:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'