Language: C++

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <climits>
#include <map>
#include <math.h>

int main(void)
{
    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;
    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:14:5: error: 'stack' was not declared in this scope; did you mean 'std::stack'?
   14 |     stack<int> S1;
      |     ^~~~~
      |     std::stack
In file included from /usr/include/c++/14/stack:63,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_stack.h:99:11: note: 'std::stack' declared here
   99 |     class stack
      |           ^~~~~
a.cc:14:11: error: expected primary-expression before 'int'
   14 |     stack<int> S1;
      |           ^~~
a.cc:15:11: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   15 |     stack<pair<int, int>> S2;
      |           ^~~~
      |           std::pair
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:89:12: note: 'std::pair' declared here
   89 |     struct pair;
      |            ^~~~
a.cc:15:16: error: expected primary-expression before 'int'
   15 |     stack<pair<int, int>> S2;
      |                ^~~
a.cc:19:21: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   19 |     for (int i = 0; cin >> ch; i++)
      |                     ^~~
      |                     std::cin
In file included from a.cc:4:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:23:13: error: 'S1' was not declared in this scope; did you mean 'y1'?
   23 |             S1.push(i);
      |             ^~
      |             y1
a.cc:25:31: error: 'S1' was not declared in this scope; did you mean 'y1'?
   25 |         else if (ch == '/' && S1.size() > 0)
      |                               ^~
      |                               y1
a.cc:31:20: error: 'S2' was not declared in this scope
   31 |             while (S2.size() > 0 && S2.top().first > j)
      |                    ^~
a.cc:36:13: error: 'S2' was not declared in this scope
   36 |             S2.push(make_pair(j, a));
      |             ^~
a.cc:36:21: error: 'make_pair' was not declared in this scope; did you mean 'std::make_pair'?
   36 |             S2.push(make_pair(j, a));
      |                     ^~~~~~~~~
      |                     std::make_pair
/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:39:5: error: 'vector' was not declared in this scope
   39 |     vector<int> ans;
      |     ^~~~~~
a.cc:39:5: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:7:
/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:39:12: error: expected primary-expression before 'int'
   39 |     vector<int> ans;
      |            ^~~
a.cc:40:12: error: 'S2' was not declared in this scope
   40 |     while (S2.size() > 0)
      |            ^~
a.cc:42:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   42 |         ans.push_back(S2.top().second);
      |         ^~~
      |         abs
a.cc:45:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   45 |     reverse(ans.begin(), ans.end());
      |             ^~~
      |             abs
a.cc:45:5: error: 'reverse' was not declared in this scope; did you mean 'std::reverse'?
   45 |     reverse(ans.begin(), ans.end());
      |     ^~~~~~~
      |     std::reverse
In file included from /usr/include/c++/14/algorithm:86:
/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:46:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   46 |     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:46:20: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   46 |     cout << sum << endl;
      |                    ^~~~
      |                    std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~