Language: C++

#include <iostream>
#include <map>
#include <vector>

using namespace std;


int clear(vector<array<int, 5>>& m)
{
    int sum = 0;
    auto e = m.end();
    for(auto& arr: m){
        int cnt = 1, v = arr[0], ip = 0;
        int maxcnt = 0, maxv = 0, maxi = 0;
        for(int i = 1; i < 5; ++i){
            cout << cnt << "," << v << endl;
            if(arr[i] == v)
                ++cnt;
            else{
                if(maxcnt < cnt){
                    maxcnt = cnt;
                    maxv = v;
                    maxi = ip;
                }
                v = arr[i];
                cnt = 1;
                ip = i;
            }
        }

        if(maxcnt < cnt){
            maxcnt = cnt;
            maxv = v;
            maxi = ip;
        }

        cout << "max: " << maxcnt << "," << maxv << "," << maxi << endl;

        if(maxcnt >= 3){
            for(int i = 0; i < maxcnt; ++i)
                arr[maxi + i] = 0;
            sum += maxv * maxcnt;
        }
    }
    cout << "sum: " << sum << endl;
    return sum;
}

void drop(vector<array<int, 5>>& m)
{
    if(m.size() < 2)
            return;
    for(int i = 0; i < 5; ++i){
        int idx = m.size() - 2;
        auto e = m.rend();
        int idx2 = m.size() - 1;
        for(auto s = m.rbegin(); s != e; ++s){
            if(idx > idx2)
                idx = idx2;
            auto& arr = *s;
            if(arr[i] == 0){
                while(m[idx][i] == 0 && idx != 0) { --idx; }

                arr[i] = m[idx][i];
                m[idx][i] = 0;

                if(idx == 0)
                    break;
            }

            --idx2;
        }
    }
}


int iter(vector<array<int, 5>>& m)
{
    int s = clear(m);
    drop(m);

    for(auto&e : m){
        for(auto& ee: e){
            cout << ee << ",";
        }
        cout << endl;
    }

    return s;
}




int main(void)
{
    int n;
    while(cin >> n){
        if(n == 0)
            break;

        vector<array<int, 5>> vec;
        for(int i = 0; i < n; ++ i){
            array<int, 5> arr;
            cin >> arr[0] >> arr[1] >> arr[2] >> arr[3] >> arr[4];
            vec.push_back(arr);
        }

        int l = 0;
        int s = 0;
        do{
            l = s;
            s += iter(vec);
        }while(l != s);

        cout << s << endl;
    }
}

Compiler output:
a.cc: In function 'int clear(std::vector<std::array<int, 5> >&)':
a.cc:13:29: error: no match for 'operator[]' (operand types are 'std::array<int, 5>' and 'int')
   13 |         int cnt = 1, v = arr[0], ip = 0;
      |                             ^
a.cc:17:19: error: no match for 'operator[]' (operand types are 'std::array<int, 5>' and 'int')
   17 |             if(arr[i] == v)
      |                   ^
a.cc:23:28: error: 'ip' was not declared in this scope; did you mean 'i'?
   23 |                     maxi = ip;
      |                            ^~
      |                            i
a.cc:25:24: error: no match for 'operator[]' (operand types are 'std::array<int, 5>' and 'int')
   25 |                 v = arr[i];
      |                        ^
a.cc:27:17: error: 'ip' was not declared in this scope; did you mean 'i'?
   27 |                 ip = i;
      |                 ^~
      |                 i
a.cc:34:20: error: 'ip' was not declared in this scope
   34 |             maxi = ip;
      |                    ^~
a.cc:41:20: error: no match for 'operator[]' (operand types are 'std::array<int, 5>' and 'int')
   41 |                 arr[maxi + i] = 0;
      |                    ^
a.cc: In function 'void drop(std::vector<std::array<int, 5> >&)':
a.cc:61:19: error: no match for 'operator[]' (operand types are 'std::array<int, 5>' and 'int')
   61 |             if(arr[i] == 0){
      |                   ^
a.cc:62:29: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 5> >, std::array<int, 5> >::value_type' {aka 'std::array<int, 5>'} and 'int')
   62 |                 while(m[idx][i] == 0 && idx != 0) { --idx; }
      |                             ^
a.cc:64:20: error: no match for 'operator[]' (operand types are 'std::array<int, 5>' and 'int')
   64 |                 arr[i] = m[idx][i];
      |                    ^
a.cc:64:32: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 5> >, std::array<int, 5> >::value_type' {aka 'std::array<int, 5>'} and 'int')
   64 |                 arr[i] = m[idx][i];
      |                                ^
a.cc:65:23: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 5> >, std::array<int, 5> >::value_type' {aka 'std::array<int, 5>'} and 'int')
   65 |                 m[idx][i] = 0;
      |                       ^
a.cc: In function 'int iter(std::vector<std::array<int, 5> >&)':
a.cc:83:23: error: range-based 'for' expression of type 'std::array<int, 5>' has incomplete type
   83 |         for(auto& ee: e){
      |                       ^
a.cc: In function 'int main()':
a.cc:104:27: error: aggregate 'std::array<int, 5> arr' has incomplete type and cannot be defined
  104 |             array<int, 5> arr;
      |                           ^~~
a.cc:4:1: note: 'std::array' is defined in header '<array>'; this is probably fixable by adding '#include <array>'
    3 | #include <vector>
  +++ |+#include <array>
    4 | 
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:1:
/usr/include/c++/14/bits/stl_iterator.h: In instantiation of '__gnu_cxx::__normal_iterator<_Iterator, _Container>& __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++() [with _Iterator = std::array<int, 5>*; _Container = std::vector<std::array<int, 5> >]':
a.cc:12:20:   required from here
   12 |     for(auto& arr: m){
      |                    ^
/usr/include/c++/14/bits/stl_iterator.h:1102:11: error: cannot increment a pointer to incomplete type 'std::array<int, 5>'
 1102 |         ++_M_current;
      |           ^~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; size_type = long unsigned int]':
a.cc:51:14:   required from here
   51 |     if(m.size() < 2)
      |        ~~~~~~^~
/usr/include/c++/14/bits/stl_vector.h:993:50: error: invalid use of incomplete type 'struct std::array<int, 5>'
  993 |       { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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:99:12: note: declaration of 'struct std::array<int, 5>'
   99 |     struct array;
      |            ^~~~~
/usr/include/c++/14/bits/stl_iterator.h: In instantiation of '__gnu_cxx::__normal_iterator<_Iterator, _Container>& __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator--() [with _Iterator = std::array<int, 5>*; _Container = std::vector<std::array<int, 5> >]':
/usr/include/c++/14/bits/stl_iterator.h:260:10:   required from 'constexpr std::reverse_iterator<_Iterator>::reference std::reverse_iterator<_Iterator>::operator*() const [with _Iterator = __gnu_cxx::__normal_iterator<std::array<int, 5>*, std::vector<std::array<int, 5> > >; reference = std::array<int, 5>&]'
  260 |         return *--__tmp;
      |                 ^~~~~~~
a.cc:60:26:   required from here
   60 |             auto& arr = *s;
      |                          ^
/usr/include/c++/14/bits/stl_iterator.h:1116:11: error: cannot decrement a pointer to incomplete type 'std::array<int, 5>'
 1116 |         --_M_current;
      |           ^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; reference = std::array<int, 5>&; size_type = long unsigned int]':
a.cc:62:28:   required from here
   62 |                 while(m[idx][i] == 0 && idx != 0) { --idx; }
      |                            ^
/usr/include/c++/14/bits/stl_vector.h:1131:41: error: invalid use of incomplete type 'struct std::array<int, 5>'
 1131 |         return *(this->_M_impl._M_start + __n);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
   99 |     struct array;
      |            ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]':
/usr/include/c++/14/bits/stl_vector.h:531:7:   required from here
  531 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:369:49: error: invalid use of incomplete type 'struct std::array<int, 5>'
  369 |                       _M_impl._M_end_of_storage - _M_impl._M_start);
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
   99 |     struct array;
      |            ^~~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41:
/usr/include/c++/14/type_traits: In instantiation of 'struct std::is_destructible<std::array<int, 5> >':
/usr/include/c++/14/bits/stl_construct.h:188:51:   required from 'void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = array<int, 5>*]'
  188 |       static_assert(is_destructible<_Value_type>::value,
      |                                                   ^~~~~
/usr/include/c++/14/bits/alloc_traits.h:993:20:   required from 'void std::_Destroy(_ForwardIterator, _ForwardIterator, allocator<_T2>&) [with _ForwardIterator = array<int, 5>*; _Tp = array<int, 5>]'
  993 |       std::_Destroy(__first, __last);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:735:15:   required from 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]'
  735 |         std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  736 |                       _M_get_Tp_allocator());
      |                       ~~~~~~~~~~~~~~~~~~~~~~
a.cc:102:31:   required from here
  102 |         vector<array<int, 5>> vec;
      |                               ^~~
/usr/include/c++/14/type_traits:1049:52: error: static assertion failed: template argument must be a complete class or an unbounded array
 1049 |       static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/type_traits:1049:52: note: 'std::__is_complete_or_unbounded<__type_identity<array<int, 5> > >((std::__type_identity<std::array<int, 5> >(), std::__type_identity<std::array<int, 5> >()))' evaluates to false
In file included from /usr/include/c++/14/bits/alloc_traits.h:33,
                 from /usr/include/c++/14/ext/alloc_traits.h:34,
                 from /usr/include/c++/14/bits/basic_string.h:39,
                 from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/stl_construct.h: In instantiation of 'void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = array<int, 5>*]':
/usr/include/c++/14/bits/alloc_traits.h:993:20:   required from 'void std::_Destroy(_ForwardIterator, _ForwardIterator, allocator<_T2>&) [with _ForwardIterator = array<int, 5>*; _Tp = array<int, 5>]'
  993 |       std::_Destroy(__first, __last);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:735:15:   required from 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = std::array<int, 5>; _Alloc =