Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 2e5 + 5;
char a[N << 1], b[N];
int n, m, nx[N << 1][26];

int main(){
	scanf("%s%s", a + 1, b + 1);
	n = strlen(a + 1), m = strlen(b + 1);
	for (register int i = 1; i <= n; ++i) a[n + i] = a[i];
	for (register int i = 0; i < 26; ++i) nx[n << 1][i] = -1;
	for (register int i = (n << 1) - 1; ~i; --i){
		for (register int j = 0; j < 26; ++j) nx[i][j] = nx[i + 1][j];
		nx[i][a[i + 1] - 'a'] = i % n + 1;
	}
	int k = 0, s = 0;
	for (register int i = 1; i <= m; ++i)
		if (~nx[k][b[i] - 'a']){
			if (nx[k][b[i] - 'a'] <= k) ++s;
			k = nx[k][b[i] - 'a'];
		}
		else return printf("-1\n"), 0;
	printf("%lld\n", 1ll * s * n + k);
	return 0;
}

Compiler output:
a.cc:28:8: error: 'N' was not declared in this scope
   28 | char a[N << 1], b[N];
      |        ^
a.cc:28:19: error: 'N' was not declared in this scope
   28 | char a[N << 1], b[N];
      |                   ^
a.cc:29:14: error: 'N' was not declared in this scope
   29 | int n, m, nx[N << 1][26];
      |              ^
a.cc: In function 'int main()':
a.cc:32:23: error: 'a' was not declared in this scope
   32 |         scanf("%s%s", a + 1, b + 1);
      |                       ^
a.cc:32:30: error: 'b' was not declared in this scope
   32 |         scanf("%s%s", a + 1, b + 1);
      |                              ^
a.cc:34:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   34 |         for (register int i = 1; i <= n; ++i) a[n + i] = a[i];
      |                           ^
a.cc:35:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 |         for (register int i = 0; i < 26; ++i) nx[n << 1][i] = -1;
      |                           ^
a.cc:35:47: error: 'nx' was not declared in this scope; did you mean 'n'?
   35 |         for (register int i = 0; i < 26; ++i) nx[n << 1][i] = -1;
      |                                               ^~
      |                                               n
a.cc:36:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   36 |         for (register int i = (n << 1) - 1; ~i; --i){
      |                           ^
a.cc:37:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 |                 for (register int j = 0; j < 26; ++j) nx[i][j] = nx[i + 1][j];
      |                                   ^
a.cc:37:55: error: 'nx' was not declared in this scope; did you mean 'n'?
   37 |                 for (register int j = 0; j < 26; ++j) nx[i][j] = nx[i + 1][j];
      |                                                       ^~
      |                                                       n
a.cc:38:17: error: 'nx' was not declared in this scope; did you mean 'n'?
   38 |                 nx[i][a[i + 1] - 'a'] = i % n + 1;
      |                 ^~
      |                 n
a.cc:41:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   41 |         for (register int i = 1; i <= m; ++i)
      |                           ^
a.cc:42:22: error: 'nx' was not declared in this scope; did you mean 'n'?
   42 |                 if (~nx[k][b[i] - 'a']){
      |                      ^~
      |                      n