Language: C++


long long gcd(long long x,long long y){
	if(x==0) return y;
	return gcd(y%x, x);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n,m; cin >> n >> m;
	string s,t; cin >> s >> t;

	ll g = gcd(n,m);
	ll l = (n*m)/g;
	ll n2 = n / g;
	ll m2 = m / g;
	ll tmp = n2*m2;
	ll l2 = n2*m2;
	ll a = 0,b = 0;
	for (ll i = 0;i < l/tmp;i++){
		a += n2; b += m2;
		//cout << s[a] << t[b] << endl;
		if(s[a] != t[b]){
			cout << -1 << endl;
			return 0;
		}
	}
	if(s[0] != t[0]) {cout << -1 << endl; return 0;}

	cout << l << endl;

	return 0;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:9: error: 'cin' was not declared in this scope
    8 |         cin.tie(0);
      |         ^~~
a.cc:9:9: error: 'ios' has not been declared
    9 |         ios::sync_with_stdio(false);
      |         ^~~
a.cc:11:9: error: 'll' was not declared in this scope
   11 |         ll n,m; cin >> n >> m;
      |         ^~
a.cc:11:24: error: 'n' was not declared in this scope
   11 |         ll n,m; cin >> n >> m;
      |                        ^
a.cc:11:29: error: 'm' was not declared in this scope
   11 |         ll n,m; cin >> n >> m;
      |                             ^
a.cc:12:9: error: 'string' was not declared in this scope
   12 |         string s,t; cin >> s >> t;
      |         ^~~~~~
a.cc:12:28: error: 's' was not declared in this scope
   12 |         string s,t; cin >> s >> t;
      |                            ^
a.cc:12:33: error: 't' was not declared in this scope
   12 |         string s,t; cin >> s >> t;
      |                                 ^
a.cc:14:11: error: expected ';' before 'g'
   14 |         ll g = gcd(n,m);
      |           ^~
      |           ;
a.cc:15:11: error: expected ';' before 'l'
   15 |         ll l = (n*m)/g;
      |           ^~
      |           ;
a.cc:16:11: error: expected ';' before 'n2'
   16 |         ll n2 = n / g;
      |           ^~~
      |           ;
a.cc:17:11: error: expected ';' before 'm2'
   17 |         ll m2 = m / g;
      |           ^~~
      |           ;
a.cc:18:11: error: expected ';' before 'tmp'
   18 |         ll tmp = n2*m2;
      |           ^~~~
      |           ;
a.cc:19:11: error: expected ';' before 'l2'
   19 |         ll l2 = n2*m2;
      |           ^~~
      |           ;
a.cc:20:11: error: expected ';' before 'a'
   20 |         ll a = 0,b = 0;
      |           ^~
      |           ;
a.cc:21:16: error: expected ';' before 'i'
   21 |         for (ll i = 0;i < l/tmp;i++){
      |                ^~
      |                ;
a.cc:21:23: error: 'i' was not declared in this scope
   21 |         for (ll i = 0;i < l/tmp;i++){
      |                       ^
a.cc:21:27: error: 'l' was not declared in this scope
   21 |         for (ll i = 0;i < l/tmp;i++){
      |                           ^
a.cc:21:29: error: 'tmp' was not declared in this scope
   21 |         for (ll i = 0;i < l/tmp;i++){
      |                             ^~~
a.cc:22:17: error: 'a' was not declared in this scope
   22 |                 a += n2; b += m2;
      |                 ^
a.cc:22:22: error: 'n2' was not declared in this scope
   22 |                 a += n2; b += m2;
      |                      ^~
a.cc:22:26: error: 'b' was not declared in this scope
   22 |                 a += n2; b += m2;
      |                          ^
a.cc:22:31: error: 'm2' was not declared in this scope
   22 |                 a += n2; b += m2;
      |                               ^~
a.cc:25:25: error: 'cout' was not declared in this scope
   25 |                         cout << -1 << endl;
      |                         ^~~~
a.cc:25:39: error: 'endl' was not declared in this scope
   25 |                         cout << -1 << endl;
      |                                       ^~~~
a.cc:29:27: error: 'cout' was not declared in this scope
   29 |         if(s[0] != t[0]) {cout << -1 << endl; return 0;}
      |                           ^~~~
a.cc:29:41: error: 'endl' was not declared in this scope
   29 |         if(s[0] != t[0]) {cout << -1 << endl; return 0;}
      |                                         ^~~~
a.cc:31:9: error: 'cout' was not declared in this scope
   31 |         cout << l << endl;
      |         ^~~~
a.cc:31:17: error: 'l' was not declared in this scope
   31 |         cout << l << endl;
      |                 ^
a.cc:31:22: error: 'endl' was not declared in this scope
   31 |         cout << l << endl;
      |                      ^~~~