Language: C++

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

string S, T;
vector<int> Schar_cnt(26);
vv<int> next_cindex;

int main() {
    cin >> S >> T;

    rep(i, S.size()) {
        Schar_cnt[S[i] - 'a']++;
    }

    bool ok = true;
    rep(i, T.size()) {
        if (Schar_cnt[T[i] - 'a'] == 0) {
            ok = false;
        }
    }

    if (!ok) {
        write(-1);
        return 0;
    }

    next_cindex = vvec(S.size(), 26, -1);
    vector<int> ci(26, -1);
    for (int i = S.size() - 1; i >= 0; --i) {
        ci[S[i] - 'a'] = i;

        for (int c = 0; c < 26; ++c) {
            next_cindex[i][c] = ci[c];
        }
    }

    ll ans = 0;
    int cur = 0;
    for (int i = 0; i < T.size(); ++i) {
        if (next_cindex[cur][T[i] - 'a'] >= 0) {
            ans += next_cindex[cur][T[i] - 'a'] - cur + 1;
            cur = next_cindex[cur][T[i] - 'a'] + 1;
        }
        else {
            ans += S.size() - cur;
            cur = 0;
            ans += next_cindex[cur][T[i] - 'a'] - cur + 1;
            cur = next_cindex[cur][T[i] - 'a'] + 1;
        }

        if (cur == S.size()) {
            cur = 0;
        }
    }

    write(ans);
}

Compiler output:
a.cc:9:72: error: 'vector' does not name a type
    9 | using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
      |                                                                        ^~~~~~
a.cc: In function 'auto vvec(int, int, T)':
a.cc:10:56: error: 'vv' was not declared in this scope; did you mean 'v'?
   10 | template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
      |                                                        ^~
      |                                                        v
a.cc:10:60: error: expected primary-expression before '>' token
   10 | template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
      |                                                            ^
a.cc:10:65: error: 'vector' was not declared in this scope
   10 | template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
      |                                                                 ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | #define _overload3(_1,_2,_3,name,...) name
a.cc:10:73: error: expected primary-expression before '>' token
   10 | template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
      |                                                                         ^
a.cc: In constructor 'aaa::aaa()':
a.cc:14:22: error: 'cin' was not declared in this scope
   14 | struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;
      |                      ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | #define _overload3(_1,_2,_3,name,...) name
a.cc:14:34: error: 'ios' has not been declared
   14 | struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;
      |                                  ^~~
a.cc:14:59: error: 'cout' was not declared in this scope
   14 | struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;
      |                                                           ^~~~
a.cc:14:59: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:14:67: error: 'fixed' was not declared in this scope
   14 | struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;
      |                                                                   ^~~~~
a.cc:1:1: note: 'std::fixed' is defined in header '<ios>'; this is probably fixable by adding '#include <ios>'
  +++ |+#include <ios>
    1 | #define _overload3(_1,_2,_3,name,...) name
a.cc:14:76: error: 'setprecision' was not declared in this scope
   14 | struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;
      |                                                                            ^~~~~~~~~~~~
a.cc:1:1: note: 'std::setprecision' is defined in header '<iomanip>'; this is probably fixable by adding '#include <iomanip>'
  +++ |+#include <iomanip>
    1 | #define _overload3(_1,_2,_3,name,...) name
a.cc: At global scope:
a.cc:16:1: error: 'string' does not name a type
   16 | string S, T;
      | ^~~~~~
a.cc:17:1: error: 'vector' does not name a type
   17 | vector<int> Schar_cnt(26);
      | ^~~~~~
a.cc:18:1: error: 'vv' does not name a type
   18 | vv<int> next_cindex;
      | ^~
a.cc: In function 'int main()':
a.cc:21:5: error: 'cin' was not declared in this scope
   21 |     cin >> S >> T;
      |     ^~~
a.cc:21:5: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:21:12: error: 'S' was not declared in this scope
   21 |     cin >> S >> T;
      |            ^
a.cc:21:17: error: 'T' was not declared in this scope
   21 |     cin >> S >> T;
      |                 ^
a.cc:24:9: error: 'Schar_cnt' was not declared in this scope; did you mean 'wchar_t'?
   24 |         Schar_cnt[S[i] - 'a']++;
      |         ^~~~~~~~~
      |         wchar_t
a.cc:29:13: error: 'Schar_cnt' was not declared in this scope; did you mean 'wchar_t'?
   29 |         if (Schar_cnt[T[i] - 'a'] == 0) {
      |             ^~~~~~~~~
      |             wchar_t
a.cc:8:18: error: 'cout' was not declared in this scope
    8 | #define write(x) cout<<(x)<<'\n'
      |                  ^~~~
a.cc:35:9: note: in expansion of macro 'write'
   35 |         write(-1);
      |         ^~~~~
a.cc:8:18: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    8 | #define write(x) cout<<(x)<<'\n'
      |                  ^~~~
a.cc:35:9: note: in expansion of macro 'write'
   35 |         write(-1);
      |         ^~~~~
a.cc:39:5: error: 'next_cindex' was not declared in this scope
   39 |     next_cindex = vvec(S.size(), 26, -1);
      |     ^~~~~~~~~~~
a.cc:40:5: error: 'vector' was not declared in this scope
   40 |     vector<int> ci(26, -1);
      |     ^~~~~~
a.cc:40:5: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:40:12: error: expected primary-expression before 'int'
   40 |     vector<int> ci(26, -1);
      |            ^~~
a.cc:42:9: error: 'ci' was not declared in this scope; did you mean 'i'?
   42 |         ci[S[i] - 'a'] = i;
      |         ^~
      |         i
a.cc:8:18: error: 'cout' was not declared in this scope
    8 | #define write(x) cout<<(x)<<'\n'
      |                  ^~~~
a.cc:68:5: note: in expansion of macro 'write'
   68 |     write(ans);
      |     ^~~~~
a.cc:8:18: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    8 | #define write(x) cout<<(x)<<'\n'
      |                  ^~~~
a.cc:68:5: note: in expansion of macro 'write'
   68 |     write(ans);
      |     ^~~~~