Language: C++

#include <iostream>
#include <stack>
#include <list>
#include <string>
#include <algorithm>
using namespace std;
 
int main(){
    list<long> S1, ans;
    list<pair<long, long> > S2;
    char ch;
    long sum = 0;
    for (long i = 0; cin >> ch; i++){
        if (ch == '\\') S1.push_front(i);
        else if (ch == '/' && S1.size() > 0){
            list<long>::iterator itr = S1.begin();
            S1.pop_front();
            long a = i - *itr;
            sum += a;
            list<pair<long, long> > itr2 = S2.begin();
            while (S2.size() > 0 && (*itr2).first > *itr){
                itr2 = S2.begin();
                a += (*itr2).second;
                S2.pop_front();
            }
            S2.push_front(make_pair(*itr, a));
        }
    }
    cout << sum << endl << S2.size();
    while (S2.size() > 0){
        list<pair<long, long> > itr2 = S2.end();
        cout << " " << *itr2;
        S2.pop_back();
    }
    cout << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:52: error: conversion from 'std::__cxx11::list<std::pair<long int, long int> >::iterator' to non-scalar type 'std::__cxx11::list<std::pair<long int, long int> >' requested
   20 |             list<pair<long, long> > itr2 = S2.begin();
      |                                            ~~~~~~~~^~
a.cc:21:38: error: no match for 'operator*' (operand type is 'std::__cxx11::list<std::pair<long int, long int> >')
   21 |             while (S2.size() > 0 && (*itr2).first > *itr){
      |                                      ^~~~~
a.cc:22:33: error: no match for 'operator=' (operand types are 'std::__cxx11::list<std::pair<long int, long int> >' and 'std::__cxx11::list<std::pair<long int, long int> >::iterator')
   22 |                 itr2 = S2.begin();
      |                                 ^
In file included from /usr/include/c++/14/list:66,
                 from a.cc:3:
/usr/include/c++/14/bits/list.tcc:267:5: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>& std::__cxx11::list<_Tp, _Alloc>::operator=(const std::__cxx11::list<_Tp, _Alloc>&) [with _Tp = std::pair<long int, long int>; _Alloc = std::allocator<std::pair<long int, long int> >]'
  267 |     list<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/list.tcc:268:27: note:   no known conversion for argument 1 from 'std::__cxx11::list<std::pair<long int, long int> >::iterator' to 'const std::__cxx11::list<std::pair<long int, long int> >&'
  268 |     operator=(const list& __x)
      |               ~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/list:65:
/usr/include/c++/14/bits/stl_list.h:930:7: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>& std::__cxx11::list<_Tp, _Alloc>::operator=(std::__cxx11::list<_Tp, _Alloc>&&) [with _Tp = std::pair<long int, long int>; _Alloc = std::allocator<std::pair<long int, long int> >]'
  930 |       operator=(list&& __x)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_list.h:930:24: note:   no known conversion for argument 1 from 'std::__cxx11::list<std::pair<long int, long int> >::iterator' to 'std::__cxx11::list<std::pair<long int, long int> >&&'
  930 |       operator=(list&& __x)
      |                 ~~~~~~~^~~
/usr/include/c++/14/bits/stl_list.h:948:7: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>& std::__cxx11::list<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = std::pair<long int, long int>; _Alloc = std::allocator<std::pair<long int, long int> >]'
  948 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_list.h:948:46: note:   no known conversion for argument 1 from 'std::__cxx11::list<std::pair<long int, long int> >::iterator' to 'std::initializer_list<std::pair<long int, long int> >'
  948 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:23:23: error: no match for 'operator*' (operand type is 'std::__cxx11::list<std::pair<long int, long int> >')
   23 |                 a += (*itr2).second;
      |                       ^~~~~
a.cc:31:46: error: conversion from 'std::__cxx11::list<std::pair<long int, long int> >::iterator' to non-scalar type 'std::__cxx11::list<std::pair<long int, long int> >' requested
   31 |         list<pair<long, long> > itr2 = S2.end();
      |                                        ~~~~~~^~
a.cc:32:24: error: no match for 'operator*' (operand type is 'std::__cxx11::list<std::pair<long int, long int> >')
   32 |         cout << " " << *itr2;
      |                        ^~~~~