Language: C++

#include <iostream>
#include <stack>
#include <list>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	// stack<long> S1, ans;
	// stack<pair<long, long> > S2;
	// char ch;
	// long sum = 0;
	// for (long i = 0; cin >> ch; i++){
	// 	if (ch == '\\') S1.push(i);
	// 	else if (ch == '/' && S1.size() > 0){
	// 		long j = S1.top(); S1.pop();
	// 		sum += i - j;
	// 		long a = i - j;
	// 		while (S2.size() > 0 && S2.top().first > j){
	// 			a += S2.top().second; S2.pop();
	// 		}
	// 		S2.push(make_pair(j, a));
	// 	}
	// }
	// cout << sum << endl << S2.size();
	// while (S2.size() > 0){ans.push(S2.top().second); S2.pop();}
	// while (ans.size() > 0){cout << " " << ans.top(); ans.pop();}
	// cout << endl;
	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){
				list<pair<long, long> > 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> > itr3 = S2.begin();
		itr3 = S2.end();
		cout << " " << *itr3;
		S2.pop_back();
	}
	cout << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:64: 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
   40 |                         list<pair<long, long> > itr2 = S2.begin();
      |                                                        ~~~~~~~~^~
a.cc:41:50: error: no match for 'operator*' (operand type is 'std::__cxx11::list<std::pair<long int, long int> >')
   41 |                         while (S2.size() > 0 && (*itr2).first() > *itr){
      |                                                  ^~~~~
a.cc:42:72: 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
   42 |                                 list<pair<long, long> > itr2 = S2.begin();
      |                                                                ~~~~~~~~^~
a.cc:43:39: error: no match for 'operator*' (operand type is 'std::__cxx11::list<std::pair<long int, long int> >')
   43 |                                 a += (*itr2).second();
      |                                       ^~~~~
a.cc:51:56: 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
   51 |                 list<pair<long, long> > itr3 = S2.begin();
      |                                                ~~~~~~~~^~
a.cc:52:31: 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')
   52 |                 itr3 = S2.end();
      |                               ^
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:53:32: error: no match for 'operator*' (operand type is 'std::__cxx11::list<std::pair<long int, long int> >')
   53 |                 cout << " " << *itr3;
      |                                ^~~~~