Language: C++

#include<algorithm>
using namespace std;

int main(){
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch;
	int sum=0;
	for(int i=0;cib>>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;
	while(S2.size()>0){ans.push_back(S2.top().second); S2.pop();}
	reverse(ans.begin(),ans.end());
	cout<<sum<<endl;
	cout<<ans.size;
	for(int i=0;i<ans.size();i++){
		cout<<" ";
		cout<<ans[i];
	}
	cout<<endl;
	
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:5:9: error: 'stack' was not declared in this scope
    5 |         stack<int> S1;
      |         ^~~~~
a.cc:2:1: note: 'std::stack' is defined in header '<stack>'; this is probably fixable by adding '#include <stack>'
    1 | #include<algorithm>
  +++ |+#include <stack>
    2 | using namespace std;
a.cc:5:15: error: expected primary-expression before 'int'
    5 |         stack<int> S1;
      |               ^~~
a.cc:6:30: error: expected primary-expression before '>' token
    6 |         stack<pair<int, int> > S2;
      |                              ^
a.cc:6:32: error: 'S2' was not declared in this scope
    6 |         stack<pair<int, int> > S2;
      |                                ^~
a.cc:9:21: error: 'cib' was not declared in this scope
    9 |         for(int i=0;cib>>ch;i++){
      |                     ^~~
a.cc:10:30: error: 'S1' was not declared in this scope
   10 |                 if(ch=='\\') S1.push(i);
      |                              ^~
a.cc:11:34: error: 'S1' was not declared in this scope
   11 |                 else if(ch=='/'&&S1.size()>0){
      |                                  ^~
a.cc:23:9: error: 'vector' was not declared in this scope
   23 |         vector<int>ans;
      |         ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include<algorithm>
  +++ |+#include <vector>
    2 | using namespace std;
a.cc:23:16: error: expected primary-expression before 'int'
   23 |         vector<int>ans;
      |                ^~~
a.cc:24:28: error: 'ans' was not declared in this scope; did you mean 'abs'?
   24 |         while(S2.size()>0){ans.push_back(S2.top().second); S2.pop();}
      |                            ^~~
      |                            abs
a.cc:25:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   25 |         reverse(ans.begin(),ans.end());
      |                 ^~~
      |                 abs
a.cc:26:9: error: 'cout' was not declared in this scope
   26 |         cout<<sum<<endl;
      |         ^~~~
a.cc:2:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include<algorithm>
  +++ |+#include <iostream>
    2 | using namespace std;
a.cc:26:20: error: 'endl' was not declared in this scope
   26 |         cout<<sum<<endl;
      |                    ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include<algorithm>
  +++ |+#include <ostream>
    2 | using namespace std;