Language: C++

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
 
#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll
 
using namespace std;
typedef long long ll;
typedef long double ld;


signed main() {
	#ifdef PC
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    map<char, int> was;
    vector<int> r(n + 1, -1);
    vector<pair<int, int>> have;
    for (char c = 'a'; c <= 'z'; c++)
    	was[c] = -1;
    int uk = n;
    for (int i = n - 1; i >= 0; i--) {
    	if(uk > i) 
    		uk--;
    	while(uk >= 0 && s[uk] != t[i]) 
    		uk--;
    	if(uk == -1) {
    		cout << -1;
    		return 0;
    	}
    	r[uk] = max(r[uk], i);
    }
    // for (int i = 0; i < n; i++) {
    // 	while(uk <= i && s[uk] != t[i]) 
    // 		uk++;
    // 	if(uk > i) {
    // 		cout << -1;
    // 		return -1;
    // 	}
    // 	r[uk] = i;
    // }
    // for (int i = 0; i < n; i++) {
    // 	was[s[i]] = i;
    // 	if(was[t[i]] == -1) {
    // 		cout << -1;
    // 		return 0;
    // 	}
    // 	r[was[t[i]]] = i;
    // }
    for (int i = 0; i < n; i++) {
    	if(r[i] == -1) 
    		continue;
    	have.pb({i, r[i]});
    }
    int lr = -1, rr = -1, cnt = 1;
    int ans = 0;
    for (int i = 0; i < len(have); i++) {
    	if(have[i].sc - have[i].ft > 1) 
    		ans = max(ans, 1);
    	if(rr < have[i].ft) {
    		if(cnt != 1) 
    			ans = 2;
    		lr = have[i].ft, rr = have[i].sc, cnt = 1;
    		continue;
    	}
    	if(rr > have[i].sc) {
    		cout << -1;
    		return 0;
    	}
    	lr = have[i].ft, rr = have[i].sc, cnt++;
    }
    if(cnt != 1) 
    	ans = max(cnt, ans);
    cout << ans << endl;
}	

Compiler output:
a.cc: In function 'int main()':
a.cc:82:26: error: no matching function for call to 'max(ll&, int)'
   82 |                 ans = max(ans, 1);
      |                       ~~~^~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 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_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:82:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   82 |                 ans = max(ans, 1);
      |                       ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:82:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   82 |                 ans = max(ans, 1);
      |                       ~~~^~~~~~~~