Language: C++

#include <bits/stdc++.h>

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

string s, t;
vector<int> index[30];

int search(char c, int prev){
    int alp = c - 'a';
    if(index[alp].size() == 0) return -1;
    auto key = upper_bound(ALL(index[alp]), prev);
    if(key == index[alp].end()) return index[alp].front();
    else return *key;
}

signed main(){
    cin >> s >> t;
    REP(i, s.length()) index[s[i] - 'a'].push_back(i);
    ll ans = 0;
    int prev = -1, next = 0;
    REP(i, t.length()){
        if((next = search(t[i], prev)) == -1){
            PRINT("-1");
            return 0;
        }
        //cerr << t[i] << " " << next << endl;
        if(prev < next) ans += next - prev;
        else ans += next + s.length() - prev;
        prev = next;
    }
    PRINT(ans);
    return 0;
}

Compiler output:
a.cc:19:21: error: 'std::vector<int> index [30]' redeclared as different kind of entity
   19 | vector<int> index[30];
      |                     ^
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 search(char, int)':
a.cc:23:13: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   23 |     if(index[alp].size() == 0) return -1;
      |             ^
a.cc:24:37: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   24 |     auto key = upper_bound(ALL(index[alp]), prev);
      |                                     ^
a.cc:5:17: note: in definition of macro 'ALL'
    5 | #define ALL(c) (c).begin(), (c).end()
      |                 ^
a.cc:24:37: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   24 |     auto key = upper_bound(ALL(index[alp]), prev);
      |                                     ^
a.cc:5:30: note: in definition of macro 'ALL'
    5 | #define ALL(c) (c).begin(), (c).end()
      |                              ^
a.cc:25:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   25 |     if(key == index[alp].end()) return index[alp].front();
      |                    ^
a.cc:25:45: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   25 |     if(key == index[alp].end()) return index[alp].front();
      |                                             ^
a.cc: In function 'int main()':
a.cc:31:29: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   31 |     REP(i, s.length()) index[s[i] - 'a'].push_back(i);
      |                             ^