Language: C++

#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN = 1000005;
int n, tot;
char a[MAXN], b[MAXN];
int end[MAXN], fr[MAXN];

void chk_same() {
    for (int i = 1; i <= n; i++)
        if (a[i] != b[i])
            return;
    puts("0"), exit(0);
}

int main() {
	scanf("%d %s %s", &n, a + 1, b + 1), chk_same();
    for (int i = 1; i <= n; i++)
        if (b[i] != b[i - 1])
            end[tot++] = i - 1;
    end[tot] = n;
    int p = n + 1, ans = 0;
    for (int i = tot; i; i--) {
        p = min(p, end[i - 1] + 1);
        while (p && a[p] != b[end[i]])
            p--;
        if (!p) {
            puts("-1");
            return 0;
        }
        fr[i] = p;
    }
    for (int i = p = 1; i <= tot; i++) {
        while (p < tot && fr[p + 1] - (p - i + 1) < end[i])
            p++;
        ans = max(ans, p - i + 1);
    }
    printf("%d", ans);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:13: error: reference to 'end' is ambiguous
   21 |             end[tot++] = i - 1;
      |             ^~~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/initializer_list:99:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:5: note:                 'int end [1000005]'
    8 | int end[MAXN], fr[MAXN];
      |     ^~~
a.cc:22:5: error: reference to 'end' is ambiguous
   22 |     end[tot] = n;
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:5: note:                 'int end [1000005]'
    8 | int end[MAXN], fr[MAXN];
      |     ^~~
a.cc:25:20: error: reference to 'end' is ambiguous
   25 |         p = min(p, end[i - 1] + 1);
      |                    ^~~
/usr/include/c++/14/initializer_list:99:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:5: note:                 'int end [1000005]'
    8 | int end[MAXN], fr[MAXN];
      |     ^~~
a.cc:26:31: error: reference to 'end' is ambiguous
   26 |         while (p && a[p] != b[end[i]])
      |                               ^~~
/usr/include/c++/14/initializer_list:99:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:5: note:                 'int end [1000005]'
    8 | int end[MAXN], fr[MAXN];
      |     ^~~
a.cc:35:53: error: reference to 'end' is ambiguous
   35 |         while (p < tot && fr[p + 1] - (p - i + 1) < end[i])
      |                                                     ^~~
/usr/include/c++/14/initializer_list:99:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:5: note:                 'int end [1000005]'
    8 | int end[MAXN], fr[MAXN];
      |     ^~~