Language: C++

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>

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.pop().second); S2.pop(); }
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++) {
		cout << " ";
		t += ans[i];
		cout << ans[i];
	}
	cout << endl;

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:9: error: 'stack' was not declared in this scope; did you mean 'std::stack'?
    9 |         stack<int>S1;
      |         ^~~~~
      |         std::stack
In file included from /usr/include/c++/14/stack:63,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_stack.h:99:11: note: 'std::stack' declared here
   99 |     class stack
      |           ^~~~~
a.cc:9:15: error: expected primary-expression before 'int'
    9 |         stack<int>S1;
      |               ^~~
a.cc:10:15: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   10 |         stack<pair<int, int>>S2;
      |               ^~~~
      |               std::pair
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_iterator.h:3013:12: note: 'std::pair' declared here
 3013 |     struct pair;
      |            ^~~~
a.cc:10:20: error: expected primary-expression before 'int'
   10 |         stack<pair<int, int>>S2;
      |                    ^~~
a.cc:13:25: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   13 |         for (int i = 0; cin >> ch; i++) {
      |                         ^~~
      |                         std::cin
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:14:32: error: 'S1' was not declared in this scope
   14 |                 if (ch == '\\')S1.push(i);
      |                                ^~
a.cc:15:37: error: 'S1' was not declared in this scope
   15 |                 else if (ch == '/'&&S1.size() > 0) {
      |                                     ^~
a.cc:19:32: error: 'S2' was not declared in this scope
   19 |                         while (S2.size() > 0 && S2.top.first > j) {
      |                                ^~
a.cc:22:25: error: 'S2' was not declared in this scope
   22 |                         S2.push(make_pair(j.a));
      |                         ^~
a.cc:22:45: error: request for member 'a' in 'j', which is of non-class type 'int'
   22 |                         S2.push(make_pair(j.a));
      |                                             ^
a.cc:22:33: error: 'make_pair' was not declared in this scope; did you mean 'std::make_pair'?
   22 |                         S2.push(make_pair(j.a));
      |                                 ^~~~~~~~~
      |                                 std::make_pair
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/stl_pair.h:1132:5: note: 'std::make_pair' declared here
 1132 |     make_pair(_T1&& __x, _T2&& __y)
      |     ^~~~~~~~~
a.cc:26:9: error: 'vector' was not declared in this scope
   26 |         vector<int>ans;
      |         ^~~~~~
a.cc:26:9: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:26:16: error: expected primary-expression before 'int'
   26 |         vector<int>ans;
      |                ^~~
a.cc:28:16: error: 'S2' was not declared in this scope
   28 |         while (S2.size() > 0) { ans.push_back(S2.pop().second); S2.pop(); }
      |                ^~
a.cc:28:33: error: 'ans' was not declared in this scope; did you mean 'abs'?
   28 |         while (S2.size() > 0) { ans.push_back(S2.pop().second); S2.pop(); }
      |                                 ^~~
      |                                 abs
a.cc:29:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   29 |         reverse(ans.begin(), ans.end());
      |                 ^~~
      |                 abs
a.cc:29:9: error: 'reverse' was not declared in this scope; did you mean 'std::reverse'?
   29 |         reverse(ans.begin(), ans.end());
      |         ^~~~~~~
      |         std::reverse
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:6:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note: 'std::reverse' declared here
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
a.cc:30:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   30 |         cout << sum << endl;
      |         ^~~~
      |         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:30:24: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   30 |         cout << sum << endl;
      |                        ^~~~
      |                        std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~