Language: C++

#include<iostream>
#include<cstdlib>
#include<stack>
#include <vector>

using namespace std;

int main(){
    stack<int> YAMA;
    stack<pair<int, long> > MIZU;
    string s;
    int length;
    long water=0;
    cin >> s;
    
    for (int i = 0; i<s.size(); i++) {
        
        if (s[i] == '\') {
            YAMA.push(length);
        }else if (s[i] == '/' && YAMA.size() != 0){
            
            long W_sum = 0;
                while (MIZU.size() != 0 && YAMA.top() < MIZU.top().first) {
                    W_sum += MIZU.top().second;
                    MIZU.pop();
                }
            MIZU.push(make_pair(YAMA.top(),W_sum + ( length - YAMA.top()) ));
            
            water += length - YAMA.top(); YAMA.pop();
            
        }
        length++;
    }
    
    vector<long> ANS;
    int mizu = MIZU.size();
    for (int i = 0; i < mizu; i++) {
        ANS.push_back(MIZU.top().second);
        MIZU.pop();
    }
    
    cout << water << endl;
    cout << mizu << " ";
    for (int i = mizu-1; i>0; i--) {
        cout << ANS[i] << " ";
    }
    if (ANS.size() != 0){
        cout << ANS[0];
    }
    cout << endl;
    return 0;
}

Compiler output:
a.cc:18:21: warning: missing terminating ' character
   18 |         if (s[i] == '\') {
      |                     ^
a.cc:18:21: error: missing terminating ' character
   18 |         if (s[i] == '\') {
      |                     ^~~~~~
a.cc: In function 'int main()':
a.cc:18:18: error: invalid operands of types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} and 'void' to binary 'operator=='
   18 |         if (s[i] == '\') {
a.cc:20:9: error: expected primary-expression before '}' token
   20 |         }else if (s[i] == '/' && YAMA.size() != 0){
      |         ^
a.cc:19:31: error: expected ')' before '}' token
   19 |             YAMA.push(length);
      |                               ^
      |                               )
   20 |         }else if (s[i] == '/' && YAMA.size() != 0){
      |         ~                      
a.cc:18:12: note: to match this '('
   18 |         if (s[i] == '\') {
      |            ^
a.cc:20:9: error: expected primary-expression before '}' token
   20 |         }else if (s[i] == '/' && YAMA.size() != 0){
      |         ^
a.cc:20:10: error: 'else' without a previous 'if'
   20 |         }else if (s[i] == '/' && YAMA.size() != 0){
      |          ^~~~
a.cc:20:21: error: 'i' was not declared in this scope
   20 |         }else if (s[i] == '/' && YAMA.size() != 0){
      |                     ^
a.cc: At global scope:
a.cc:36:16: error: 'MIZU' was not declared in this scope
   36 |     int mizu = MIZU.size();
      |                ^~~~
a.cc:37:5: error: expected unqualified-id before 'for'
   37 |     for (int i = 0; i < mizu; i++) {
      |     ^~~
a.cc:37:21: error: 'i' does not name a type
   37 |     for (int i = 0; i < mizu; i++) {
      |                     ^
a.cc:37:31: error: 'i' does not name a type
   37 |     for (int i = 0; i < mizu; i++) {
      |                               ^
a.cc:42:5: error: 'cout' does not name a type
   42 |     cout << water << endl;
      |     ^~~~
a.cc:43:5: error: 'cout' does not name a type
   43 |     cout << mizu << " ";
      |     ^~~~
a.cc:44:5: error: expected unqualified-id before 'for'
   44 |     for (int i = mizu-1; i>0; i--) {
      |     ^~~
a.cc:44:26: error: 'i' does not name a type
   44 |     for (int i = mizu-1; i>0; i--) {
      |                          ^
a.cc:44:31: error: 'i' does not name a type
   44 |     for (int i = mizu-1; i>0; i--) {
      |                               ^
a.cc:47:5: error: expected unqualified-id before 'if'
   47 |     if (ANS.size() != 0){
      |     ^~
a.cc:50:5: error: 'cout' does not name a type
   50 |     cout << endl;
      |     ^~~~
a.cc:51:5: error: expected unqualified-id before 'return'
   51 |     return 0;
      |     ^~~~~~
a.cc:52:1: error: expected declaration before '}' token
   52 | }
      | ^