Language: C++

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll ans,cnt,h[100001];
int n,index=-1;
vector<int> pos[200];
string s,t;
bool f[200];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s>>t;
	n=s.size();
	for (int i=0;i<s.size();++i) pos[s[i]].push_back(i+1),f[s[i]]=true;
	for (int i=0;i<t.size();++i)
		if (f[t[i]]==false)
		{
			cout<<"-1";
			return 0;
		}
	for (int i=0;i<t.size();++i)
		if (pos[t[i]][pos[t[i]].size()-1]<=index) ++cnt,index=pos[t[i]][0];
		else index=*upper_bound(pos[t[i]].begin(),pos[t[i]].end(),index);
	ans=cnt*n+index;
	cout<<ans;
	return 0;
}

Compiler output:
a.cc:5:7: error: 'int index' redeclared as different kind of entity
    5 | int n,index=-1;
      |       ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:1:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int main()':
a.cc:24:50: error: invalid operands of types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and '<unresolved overloaded function type>' to binary 'operator<='
   24 |                 if (pos[t[i]][pos[t[i]].size()-1]<=index) ++cnt,index=pos[t[i]][0];
a.cc:24:82: error: overloaded function with no contextual type information
   24 |                 if (pos[t[i]][pos[t[i]].size()-1]<=index) ++cnt,index=pos[t[i]][0];
      |                                                                                  ^
a.cc:25:40: error: no matching function for call to 'upper_bound(std::vector<int>::iterator, std::vector<int>::iterator, <unresolved overloaded function type>)'
   25 |                 else index=*upper_bound(pos[t[i]].begin(),pos[t[i]].end(),index);
      |                             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algo.h:2019:5: note: candidate: 'template<class _FIter, class _Tp> _FIter std::upper_bound(_FIter, _FIter, const _Tp&)'
 2019 |     upper_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2019:5: note:   template argument deduction/substitution failed:
a.cc:25:40: note:   couldn't deduce template parameter '_Tp'
   25 |                 else index=*upper_bound(pos[t[i]].begin(),pos[t[i]].end(),index);
      |                             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2050:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::upper_bound(_FIter, _FIter, const _Tp&, _Compare)'
 2050 |     upper_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2050:5: note:   candidate expects 4 arguments, 3 provided
a.cc:26:18: error: invalid operands of types 'long long int' and '<unresolved overloaded function type>' to binary 'operator+'
   26 |         ans=cnt*n+index;
      |             ~~~~~^~~~~~