criyle/codenet-compile-errors huggingface dataset:
Language: C

#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{

    int N;
    int M;

    scanf("%d %d", &N, &M);

    if(N < 1 || N > 100000 || M < 1 || M > 100000) {
        exit(0);
    }

    char S[N];
    char T[M];

    scanf("%s", S);
    scanf("%s", T);

    for(int i = 0;i < N;i++) {
        if((S[i] < 'a') || (S[i] > 'z')) {
            exit(0);
        }
    }

    for(int i = 0;i < M;i++) {
        if((T[i] < 'a') || (T[i] > 'z')) {
            exit(0);
        }
    }

    for(int i = 0; S[i]!='\0'; ++i);

    if(i != N) {
        exit(0);
    }

    for(int i = 0; T[i]!='\0'; ++i);

    if(i != M) {
        exit(0);
    }

    int hogeN = N;
    int hogeM = M;

    if(hogeM < hogeN) {
        tmp = hogeM;
        hogeM = hogeN;
        hogeN = tmp;
    }
     
    /* ユークリッドの互除法 */
    r = hogeM % hogeN;
    while(r != 0) {
        hogeM = hogeN;
        hogeN = r;
        r = hogeM % hogeN;
    }

    int saidai;
    saidai = hogeN;

    int count = 1;
    int flag = 0;
    while(count / N < 1 || count / M < 1) {
        if(count % saidai != 0) {
            count++;
            continue;
        }
        int hoge = count / N;
        for(int i = 1;i < N;i++) {
            if(S[i * hoge + i] != S[i]) {
                break;
            }
        }
        if(flag == 0) {
            count++;
            continue;
        }

        int hoge = count / M;
        for(int i = 1;i < M;i++) {
            if(S[i * hoge + i] != S[i]) {
                break;
            }
        }

        if(flag == 0) {
            count++;
            continue;
        } else {
            flag = 1;
            break;
        }
    }

    if(flag == 1) {
        printf("%d", count);
    } else {
        printf("-1\n");
    }

    return 0;
}

Compiler output:
main.c: In function 'main':
main.c:36:8: error: 'i' undeclared (first use in this function)
   36 |     if(i != N) {
      |        ^
main.c:36:8: note: each undeclared identifier is reported only once for each function it appears in
main.c:50:9: error: 'tmp' undeclared (first use in this function)
   50 |         tmp = hogeM;
      |         ^~~
main.c:56:5: error: 'r' undeclared (first use in this function)
   56 |     r = hogeM % hogeN;
      |     ^
main.c:84:13: error: redefinition of 'hoge'
   84 |         int hoge = count / M;
      |             ^~~~
main.c:73:13: note: previous definition of 'hoge' with type 'int'
   73 |         int hoge = count / N;
      |             ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long int n,m,ans=-1,a,b,c;
    cin>>n>>m;
    char s[n];
    cin>>s;
    char t[m];
    cin>>t;
    if(n<m){
        a=n;
        b=m;
    }
    else {
        a=m;
        b=n;
    }    
    
    for(int i=1;i<=b;i++){
        if(n%i==0&&m%i==0){
            ans=i;
        }
    }
    if(ans!=-1){
        for(int j=0;j<ans;j++){
            if(s[j*n/ans]!=t[j*m/ans]){
                ans=-1;
                break;
            }
        }
    }
else c=ans
    if(ans!=-1){
        c=a*b/ans;
    }
    else c=ans;
    cout<<c<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:33:11: error: expected ';' before 'if'
   33 | else c=ans
      |           ^
      |           ;
   34 |     if(ans!=-1){
      |     ~~     
a.cc:37:5: error: 'else' without a previous 'if'
   37 |     else c=ans;
      |     ^~~~
Language: C++

#include<bits/stdc++.h>

using namespace std;

long long int A, a, n, m, y, s;
int N, M;
string str_1, str_2, str_3;


long long int gcd(int m, int n){
	while (true) {
		if (m%n == 0)return n;
		m %= n;
		if (n%m == 0)return m;
		n %= m;
	}
	return 0;
}



int main() {
	cin >> n >> m;
	cin >> str_1 >> str_2;

	y = gcd(n, m);
	N = n / y;
	M = m / y;
	for (int i = 0; i < y; i++) {
		if (str_1[i*N] != str_2[i*M]) {
			cout << -1 << '\n;
			return 0;
		}
	}
	cout << n * M << '\n;
	return 0;
}


Compiler output:
a.cc:31:39: warning: missing terminating ' character
   31 |                         cout << -1 << '\n;
      |                                       ^
a.cc:31:39: error: missing terminating ' character
   31 |                         cout << -1 << '\n;
      |                                       ^~~~
a.cc:35:26: warning: missing terminating ' character
   35 |         cout << n * M << '\n;
      |                          ^
a.cc:35:26: error: missing terminating ' character
   35 |         cout << n * M << '\n;
      |                          ^~~~
a.cc: In function 'int main()':
a.cc:32:25: error: expected primary-expression before 'return'
   32 |                         return 0;
      |                         ^~~~~~
a.cc:36:9: error: expected primary-expression before 'return'
   36 |         return 0;
      |         ^~~~~~
Language: C++

#include<bits/stdc++.h>

using namespace std;

long long int A, a, n, m, y, s,N,M;
string str_1, str_2, str_3;


long long int gcd(int m, int n){
	while (true) {
		if (m%n == 0)return n;
		m %= n;
		if (n%m == 0)return m;
		n %= m;
	}
	return 0;
}



int main() {
	cin >> n >> m;
	cin >> str_1 >> str_2;

	y = gcd(n, m);
	N = n / y;
	M = m / y;
	for (int i = 0; i < y; i++) {
		if (str_1[i*N] != str_2[i*M]) {
			cout << -1 << '\n;
			return 0;
		}
	}
	cout << n * M << '\n;
	return 0;
}


Compiler output:
a.cc:30:39: warning: missing terminating ' character
   30 |                         cout << -1 << '\n;
      |                                       ^
a.cc:30:39: error: missing terminating ' character
   30 |                         cout << -1 << '\n;
      |                                       ^~~~
a.cc:34:26: warning: missing terminating ' character
   34 |         cout << n * M << '\n;
      |                          ^
a.cc:34:26: error: missing terminating ' character
   34 |         cout << n * M << '\n;
      |                          ^~~~
a.cc: In function 'int main()':
a.cc:31:25: error: expected primary-expression before 'return'
   31 |                         return 0;
      |                         ^~~~~~
a.cc:35:9: error: expected primary-expression before 'return'
   35 |         return 0;
      |         ^~~~~~
Language: C++

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>

using namespace std;

long long int A, a, n, m, y, s;
string str_1, str_2, str_3;
long long int x[2][30000];


long long int gcd(int m, int n){
	while (true) {
		if (m%n == 0)return n;
		m %= n;
		if (n%m == 0)return m;
		n %= m;
	}
}

y = gcd(n, m);

int main() {
	cin >> n >> m;
	cin >> str_1 >> str_2;

	for (int i = 0; i < y; i++) {
		if (str_1[i*n / y] != str_2[i*m / y]) {
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << n * m / y << '\n';
	return 0;
}


Compiler output:
a.cc:26:1: error: 'y' does not name a type
   26 | y = gcd(n, m);
      | ^
Language: Java

import java.io.*;
import java.util.*;

public class A {
	public static void main(String[] args) {
		try{
			InputStreamReader isr =new InputStreamReader(System.in);
	   		BufferedReader br =new BufferedReader(isr);
	        String buf = br.readLine();
	        StringTokenizer st = new StringTokenizer(buf," ");
	    	final int n = Integer.parseInt(st.nextToken());
	        final int m = Integer.parseInt(st.nextToken());
	        if (n < 1 || m < 1 || m > 100000 || m > 100000) {
	        	throw new IllegalArgumentException();
	        }
	        String s = br.readLine();
	        String t = br.readLine();
	        if (s.length() != n || t.length() != m) {
	        	throw new IllegalArgumentException();
	        }
	        if (!isExistGoodString(s, t)) {
	        	System.out.println(-1);
	        	return;
	        }
	        // a: n, m のどちらでも割り切れる最小の数(最小公倍数)
	        int a = -1;
	        int i = 1;
	        while (i <= 2 * m * n) {
	        	if (i % n == 0 && i % m == 0) {
	        		a = i;
	        		break;
	        	}
	        	i++;
	        }
	        if (a == -1) {
	        	throw new IllegalArgumentException();
	        }
	        // System.out.println(a);
	        i = a;
	        while (i < Integer.MAX_VALUE - a) {
	        	if (isExistGoodString(i, s, t)) {
	        		System.out.println(i);
	        		break;
	        	}
	        	i += a;
	        }
	        if (i >= Integer.MAX_VALUE - a) {
	        	System.out.println(-1);
	        }
		} catch (IOException ioe) {
			ioe.printStackTrace();
		} catch (IllegalArgumentException iae) {
			iae.printStackTrace();
			System.err.println("1 ≦ N, M ≦ 10^5 を満たす必要があります。");
		}
	}

	private static boolean isExistGoodString(final String s, final String t) {
		int n = s.length();
		int m = t.length();
		if (s.charAt(0) != t.charAt(0)) {
			return false;
		}
		int max = 1;
		int i = (n <= m) ? n : m;
		while (i > 1) {
			if (n % i == 0 && m % i == 0) {
				max = i;
				break;
			}
			i--;
		}
		if (max != 1) {
			int a = n / max;
			int b = m / max;
			i = 1;
			while (i * a < n && i * b < m) {
				if (s.charAt(i * a) != t.charAt(i * b)) {
					return false;
				}
				i++;
			}
		}
		return true;
	}

	private static boolean isExistGoodString(final int i, final String s, final String t) throws IllegalArgumentException {
		if (i < 1) {
	        throw new IllegalArgumentException();
	    }
		char[] x = new char[i];
		int j = 0;
		int n = s.length();
		int m = t.length();
		while (j < i) {
			x[j] = '0';
			j++;
		}
		j = 0;
		while (j < n) {
			x[i / n * j] = s.charAt(j);
			j++;
		}
		j = 0;
		while (j < m) {
			if (x[i / m * j] == '0') {
				x[i / m * j] = t.charAt(j);
			} else if (x[i / m * j] != t.charAt(j)) {
				return false;
			}
			j++;
		}
		return true;
	}
}

Compiler output:
Main.java:4: error: class A is public, should be declared in a file named A.java
public class A {
       ^
1 error
Language: C++

#include<iostream>
using namespace std;
int main(){
  long int N,M,k,l;
  cin>>N>>M;
  char s[N],t[M];
  long int LCM,gameover=0;
  for(int i=0;i<N;i++)
  {
    cin>>s[i];
  }
  for(int i=0;i<M;i++)
  {
    cin>>t[i];
  }
  if(M>=N){
  k=M;
  l=N;
}else {
  k=N;
  l=M;
  }
  while(k!=0&&l!=0){
    if(k>=l){
      k=k%l;
    }else{
      l=l%k;
    }
    }
    if(k==0){
      LCM=l;
    }else{
      LCM=k;
    }
if(M==LCM&&N==LCM){
  for(int i=0;i<M;i++){
    if(s[i]!=t[i]){
      gameover=1;
      break;
    }
  }
}else if(M==LCM){
  for(int i=0;i<M;i++){
    if(s[i*(N/M)]!=t[i]){
      gameover=1;
      break;
  }
}
}else if(N==LCM){
      for(int i=0;i<N;i++){
        if(s[i]!=t[i*(M/N)]){
          gameover=1;
          break;
      }
    }

  }else {
    int N2=N/LCM, int M2=M/LCM;
    for(int i=0;i*N2*M2<min(N,M);++i){
      if(s[i*N2]!=t[i*M2]){
        gameover=1;
      }
    }
    //if(s[0]!=t[0]){
    //  gameover=1;
    //}
  }
  if(gameover==1){
    std::cout<<-1<<std::endl;
  }else{
    std::cout<<M*N/LCM<<std::endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:58:19: error: expected unqualified-id before 'int'
   58 |     int N2=N/LCM, int M2=M/LCM;
      |                   ^~~
a.cc:59:22: error: 'M2' was not declared in this scope; did you mean 'N2'?
   59 |     for(int i=0;i*N2*M2<min(N,M);++i){
      |                      ^~
      |                      N2
Language: C++

#include<iostream>
using namespace std;
int main(){
  long int N,M,k,l;
  cin>>N>>M;
  char s[N],t[M];
  long int LCM,gameover=0;
  for(int i=0;i<N;i++)
  {
    cin>>s[i];
  }
  for(int i=0;i<M;i++)
  {
    cin>>t[i];
  }
  if(M>=N){
  k=M;
  l=N;
}else {
  k=N;
  l=M;
  }
  while(k!=0&&l!=0){
    if(k>=l){
      k=k%l;
    }else{
      l=l%k;
    }
    }
    if(k==0){
      LCM=l;
    }else{
      LCM=k;
    }
if(M==LCM&&N==LCM){
  for(int i=0;i<M;i++){
    if(s[i]!=t[i]){
      gameover=1;
      break;
    }
  }
}else if(M==LCM){
  for(int i=0;i<M;i++){
    if(s[i*(N/M)]!=t[i]){
      gameover=1;
      break;
  }
}
}else if(N==LCM){
      for(int i=0;i<N;i++){
        if(s[i]!=t[i*(M/N)]){
          gameover=1;
          break;
      }
    }

  }else {
    int N2=N/LCM, nt M2=M/LCM;
    for(int i=0;i*N2*M2<min(N,M);++i){
      if(s[i*N2]!=t[i*M2]){
        gameover=1;
      }
    }
    //if(s[0]!=t[0]){
    //  gameover=1;
    //}
  }
  if(gameover==1){
    std::cout<<-1<<std::endl;
  }else{
    std::cout<<M*N/LCM<<std::endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:58:22: error: expected initializer before 'M2'
   58 |     int N2=N/LCM, nt M2=M/LCM;
      |                      ^~
a.cc:59:22: error: 'M2' was not declared in this scope; did you mean 'N2'?
   59 |     for(int i=0;i*N2*M2<min(N,M);++i){
      |                      ^~
      |                      N2
Language: C++

#include<iostream>
using namespace std;
int main(){
  long int N,M,k,l;
  cin>>N>>M;
  char s[N],t[M];
  long int LCM,gameover=0;
  for(int i=0;i<N;i++)
  {
    cin>>s[i];
  }
  for(int i=0;i<M;i++)
  {
    cin>>t[i];
  }
  if(M>=N){
  k=M;
  l=N;
}else {
  k=N;
  l=M;
  }
  while(k!=0&&l!=0){
    if(k>=l){
      k=k%l;
    }else{
      l=l%k;
    }
    }
    if(k==0){
      LCM=l;
    }else{
      LCM=k;
    }
if(M==LCM&&N==LCM){
  for(int i=0;i<M;i++){
    if(s[i]!=t[i]){
      gameover=1;
      break;
    }
  }
}else if(M==LCM){
  for(int i=0;i<M;i++){
    if(s[i*(N/M)]!=t[i]){
      gameover=1;
      break;
  }
}
}else if(N==LCM){
      for(int i=0;i<N;i++){
        if(s[i]!=t[i*(M/N)]){
          gameover=1;
          break;
      }
    }

  }else {
    N2=N/LCM;M2=M/LCM;
    for(int i=0;i*N2*M2<min(N,M);++i){
      if(s[i*N2]!=t[i*M2]){
        gameover=1;
      }
    }
    //if(s[0]!=t[0]){
    //  gameover=1;
    //}
  }
  if(gameover==1){
    std::cout<<-1<<std::endl;
  }else{
    std::cout<<M*N/LCM<<std::endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:58:5: error: 'N2' was not declared in this scope; did you mean 'N'?
   58 |     N2=N/LCM;M2=M/LCM;
      |     ^~
      |     N
a.cc:58:14: error: 'M2' was not declared in this scope; did you mean 'M'?
   58 |     N2=N/LCM;M2=M/LCM;
      |              ^~
      |              M
Language: C++

#include<iostream>
using namespace std;
int main(){
  long int N,M,k,l;
  cin>>N>>M;
  char s[N],t[M];
  long int LCM,gameover=0;
  for(int i=0;i<N;i++)
  {
    cin>>s[i];
  }
  for(int i=0;i<M;i++)
  {
    cin>>t[i];
  }
  if(M>=N){
  k=M;
  l=N;
}else {
  k=N;
  l=M;
  }
  while(k!=0&&l!=0){
    if(k>=l){
      k=k%l;
    }else{
      l=l%k;
    }
    }
    if(k==0){
      LCM=l;
    }else{
      LCM=k;
    }
if(M==LCM&&N==LCM){
  for(int i=0;i<M;i++){
    if(s[i]!=t[i]){
      gameover=1;
      break;
    }
  }
}else if(M==LCM){
  for(int i=0;i<M;i++){
    if(s[i*(N/M)]!=t[i]){
      gameover=1;
      break;
  }
}
}else if(N==LCM){
      for(int i=0;i<N;i++){
        if(s[i]!=t[i*(M/N)]){
          gameover=1;
          break;
      }
    }

  }else {
    N2=N/LCM;M2=M/LCM;
    for(int i=0;i*N2*M2<min(N,M);++i){
      if(s[i*N2]!=t[i*M2]){
        gameover=1;
      }
    //if(s[0]!=t[0]){
    //  gameover=1;
    //}
  }
  if(gameover==1){
    std::cout<<-1<<std::endl;
  }else{
    std::cout<<M*N/LCM<<std::endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:58:5: error: 'N2' was not declared in this scope; did you mean 'N'?
   58 |     N2=N/LCM;M2=M/LCM;
      |     ^~
      |     N
a.cc:58:14: error: 'M2' was not declared in this scope; did you mean 'M'?
   58 |     N2=N/LCM;M2=M/LCM;
      |              ^~
      |              M
a.cc:72:2: error: expected '}' at end of input
   72 | }
      |  ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int gcd(int a, int b){
    int tmp;
    while (b != 0) {
        if (b < a) {
            tmp = a;
            a = b;
            b = tmp;
        }
        b = b % a;
    }
    return a;
}

int main(void){
    int n,m;
    string s,t;
    cin >> n >> m >> s >> t;
    long long lcm=n/gcd(n,m)*m;
    int N=n/gcd(n,m),M=m/gcd(n,m);
    long long ans=lcm
    for(int i=0; i<gcd(n,m)-1; i++){
        if(N*i>=n || M*i>=m)break;
        if(s[N*i]!=t[M*i]){
            ans=-1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:5: error: expected ',' or ';' before 'for'
   30 |     for(int i=0; i<gcd(n,m)-1; i++){
      |     ^~~
a.cc:30:18: error: 'i' was not declared in this scope
   30 |     for(int i=0; i<gcd(n,m)-1; i++){
      |                  ^
Language: C++

#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int gcd(int a, int b){
    int tmp;
    while (b != 0) {
        if (b < a) {
            tmp = a;
            a = b;
            b = tmp;
        }
        b = b % a;
    }
    return a;
}

int main(void){
    int n,m;
    string s,t;
    cin >> n >> m >> s >> t;
    long long lcm=n/gcd(n,m)*m;
    int N=n/gcd(n,m),M=m/gcd(n,m);
    long long ans=lcm
    for(int i=0; i<n; i++){
        if(N*i>=n || M*i>=m)break;
        if(s[N*i]!=t[M*i]){
            ans=-1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:5: error: expected ',' or ';' before 'for'
   30 |     for(int i=0; i<n; i++){
      |     ^~~
a.cc:30:18: error: 'i' was not declared in this scope
   30 |     for(int i=0; i<n; i++){
      |                  ^
Language: C++

#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int gcd(int a, int b){
    int tmp;
    while (b != 0) {
        if (b < a) {
            tmp = a;
            a = b;
            b = tmp;
        }
        b = b % a;
    }
    return a;
}

int main(void){
    int n,m;
    string s,t;
    cin >> n >> m >> s >> t;
    int lcm=n/gcd(n,m)*m;
    int N=n/gcd(n,m),M=m/gcd(n,m);
    for(int i=0; i<n; i++){
        if(N*i>=n || M*i>=m)break;
        if(s[N*i]!=t[M*i]){
            num=-1;
            break;
        }
    }
    cout << num << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:13: error: 'num' was not declared in this scope; did you mean 'enum'?
   32 |             num=-1;
      |             ^~~
      |             enum
a.cc:36:13: error: 'num' was not declared in this scope; did you mean 'enum'?
   36 |     cout << num << endl;
      |             ^~~
      |             enum
Language: C++

#include <cstdio>
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  char S[100000], T[100000];
  scanf("%s%s", S, T);
  
  // 最大公約数を計算
  int g = __gcd(N, M);
  int stepS = N / g;
  int stepT = M / g;
  for (int i = 0; i < n; ++i) {
    if (i % stepS == 0) {
      if (S[i] != T[i / stepS * stepT]) {
        puts("-1");
		return 0;
      }
	}
  }
  printf("%lld", 1ll * N / g * M);
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:23: error: 'n' was not declared in this scope
   16 |   for (int i = 0; i < n; ++i) {
      |                       ^
Language: C++

#include <cstdio>
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M;
  scanf("%d%d", &n, &m);
  char S[100000], T[100000];
  scanf("%s%s", S, T);
  
  // 最大公約数を計算
  int g = __gcd(N, M);
  int stepS = N / g;
  int stepT = M / g;
  for (int i = 0; i < g; ++i) {
    if (S[stepS * i] != T[stepT * i]) {
      cout << -1 << '\n';
      return 0;
    }
  }
  cout << (long long) N / g * M << '\n';
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:18: error: 'n' was not declared in this scope
    8 |   scanf("%d%d", &n, &m);
      |                  ^
a.cc:8:22: error: 'm' was not declared in this scope
    8 |   scanf("%d%d", &n, &m);
      |                      ^
Language: C++

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

int main() {
  int n, m, L, g, j = 1;
  string s, t;
  cin >> n >> m;
  cin >> s >> t;
  g = __gcd(n, m);
  L = (n * m) / g;
  for(int i = 0; i < g; i++) {
    if (s[i * (n / g)] != t[i * (m / g)]) {
      j = 0;
      break;
    }
  }
  if(j != 0){
    cout << L;
  }else{
    cout << -1;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:2: error: expected '}' at end of input
   21 | }
      |  ^
a.cc:4:12: note: to match this '{'
    4 | int main() {
      |            ^
Language: C++

#include <cstdio>
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M;
  scanf("%d%d", &n, &m);
  string S, T;
  scanf("%s%s", S, T);
  
  // 最大公約数を計算
  int g = __gcd(N, M);
  int stepS = N / g;
  int stepT = M / g;
  for (int i = 0; i < g; ++i) {
    if (S[stepS * i] != T[stepT * i]) {
      cout << -1 << '\n';
      return 0;
    }
  }
  cout << (long long) N / g * M << '\n';
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:18: error: 'n' was not declared in this scope
    8 |   scanf("%d%d", &n, &m);
      |                  ^
a.cc:8:22: error: 'm' was not declared in this scope
    8 |   scanf("%d%d", &n, &m);
      |                      ^
Language: C++

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

long long gcd(long long a,long long b)
{
    long long temp;
    while(b)
    {    
        temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

long long main()
{
	long long n,m;
	cin>>n>>m;
	long long l=n*m/gcd(n,m);
	//cout<<l;
	string s,t;
	cin>>s;
	cin>>t;
	//cout<<s;
	//cout<<t;
	
	long long ln=l/n;
	long long lm=l/m;
	long long t1=0,t2=0;
	long long flag=1;
	while(t1<n && t2<m)
	{
		if(t1*ln<t2*lm) t1++;
		else if(t1*ln>t2*lm) t2++;
		else{
			if(s[t1] != t[t2]){
				flag=0;
				break;
			}
			else{
				t1++;
				t2++;
			}
		}
	}
	if(flag)
	{
		if(t1<n)
		{
			cout<<(n-1)*ln+1<<'\n';
			
		}
		if(t2<m)
		{
			cout<<(m-1)*lm+1<<'\n';
		}
		if(t1==n && t2==m)
		{
			cout<<l<<'\n';
		}
	}
	else cout<<"-1"<<'\n';
	
	
	
	return 0;	
} 

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};

int gcd(int a,int b){
	if(b==0) return a;
	return gcd(b,a%b);
}

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

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

	ll a,b;
	if(n >= m){
		a=n;
		b=m;
	}else{
		a=m;
		b=n;
		swap(s,t);
	}
	ull lcm=a*b/gcd(a,b);

	bool found;
	bool once = if(gcd(a,b)!=1 || b==1)
	for(int j=0;j<100;j++){
		//cout << lcm << "\n";
		found=true;
		map<ull,char> mp;
		for(int i=0;i<a;i++){
			mp[i*lcm/a] = s[i];
		//	cout << "	" << i*lcm/a+1 << " " << s[i] << "\n";
		}
		for(int i=0;i<b;i++){
			auto itr= mp.find(i*lcm/b);
			if(itr != mp.end()){
				if(itr->second != t[i]){
		//			cout << "stop " << i*lcm/b+1 << " " << t[i] << "\n";
					found=false;
					if(once){
						cout << "-1\n";
						return 0;
					}
					break;
				}
			}
		}
		if(found){
			cout << lcm << "\n";
			return 0;
		}
		lcm*=2;
		if(lcm < 0){
			cout << "-1\n";
			return 0;
		}
	}
	cout << "-1\n";
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:21: error: expected primary-expression before 'if'
   56 |         bool once = if(gcd(a,b)!=1 || b==1)
      |                     ^~
a.cc:57:21: error: 'j' was not declared in this scope
   57 |         for(int j=0;j<100;j++){
      |                     ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false)；
	int n,m;
	scanf("%d%d",&n,&m);
	string s,t;
	cin>>s>>t;
	int l=__gcd(n,m);//考试又不能用
	//挨个查找 
	for(int i=0;i<l;i++){
		// 
		int x=l/n*i;
		int y=l/m*i;
		//不是好串 
		if(s[x]!=t[y]){
			cout<<"-1"<<endl;
			return 0;
		}	
	} 
	//else
	cout<<(long long )n/l*m<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:4:36: error: expected ';' before '\U0000ff1b'
    4 |         ios::sync_with_stdio(false)；
      |                                    ^~
      |                                    ;
a.cc:6:23: error: 'n' was not declared in this scope; did you mean 'yn'?
    6 |         scanf("%d%d",&n,&m);
      |                       ^
      |                       yn
a.cc:6:26: error: 'm' was not declared in this scope; did you mean 'tm'?
    6 |         scanf("%d%d",&n,&m);
      |                          ^
      |                          tm
Language: C++

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n,m,X;
char co[10000000050];
char s[100050],t[100050];
int gcd(int x,int y)
{
    if (y==0)
    {
        return x;
    }
    return gcd(y,x%y);
}
int main()
{
    scanf("%d%d",&n,&m);
    scanf("%s%s",s,t);
    memset(co,'0',sizeof(co));
    int ruler=0;
    int l=gcd(n,m);
    X=n*m/l;
    if (s[0]!=t[0])
    {
        printf("-1");
        return 0;
    }
    for (int i=1;i<n;i++)
    {
        co[X/n*i+1]=s[i];
    }
    for (int i=1;i<m;i++)
    {
        if (co[X/m*i+1]!='0')
        {
            if (co[X/m*i+1]!=t[i])
            {
                ruler=1;
                break;
            }
        }
    }
    if (ruler==1)
    {
        printf("-1");
    }
    else
    {
        printf("%d",X);
    }
    return 0;
}

Compiler output:
/tmp/cc5jq4PI.o: in function `main':
a.cc:(.text+0x62): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in /tmp/cc5jq4PI.o
a.cc:(.text+0x6c): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/cc5jq4PI.o
a.cc:(.text+0xe3): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/cc5jq4PI.o
a.cc:(.text+0xea): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in /tmp/cc5jq4PI.o
a.cc:(.text+0x137): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/cc5jq4PI.o
a.cc:(.text+0x1b6): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in /tmp/cc5jq4PI.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
} 
int lcm(int x,int y){
	return x*y/gcd(x,y);
}
char a[100002];
char b[100002];
char c[10000020];
int vis[10000020];
int main(){	
	int n,m;
	scanf("%d%d",&n,&m);
	scanf("%s",a);
	scanf("%s",b);
	int len=lcm(n,m);
	for(int i=0;i<=){
		int ll=len*i;
		for(int j=0;j<=max(n,m);j++){
			if((vis[j*(ll/m)]&&c[j*(ll/m)]!=b[j])||(vis[j*(ll/n)]&&c[j*(ll/n)]!=a[j])){
				cout<<"-1";
				return 0;
			}
			if(j*(ll/m)==j*(ll/n)&&a[j]!=b[j]){
				cout<<"-1";
				return 0;
			}
			c[j*(ll/m)]=b[j],c[j*(ll/n)]=a[j];
			vis[j*(ll/m)]=1;
			vis[j*(ll/n)]=1;
		}
		cout<<len;
		return 0;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:24: error: expected primary-expression before ')' token
   30 |         for(int i=0;i<=){
      |                        ^
a.cc:30:24: error: expected ';' before ')' token
   30 |         for(int i=0;i<=){
      |                        ^
      |                        ;
Language: C++

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+500;

long long gcd(long long a,long long b)
{
    return b?gcd(b,a%b):a;
}

int main()
{
	long long n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	long long l=n/gcd(n,m)*m;
	int flag=1;
	long long time1=l/m,time2=l/n;
	for(int i=0;i<(int)max(n,m);i++)
    {
		if(s[time1*i%n]!=t[time2*i%m])
		{
			flag=0;
			break;
		}
	}
	cout<<(flag? b:-1);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:22: error: 'b' was not declared in this scope
   29 |         cout<<(flag? b:-1);
      |                      ^
Language: C++

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n,m,X;
char co[10000000050];
bool flag[10000000050];
char s[100050],t[100050];
int gcd(int x,int y)
{
    if (y==0)
    {
        return x;
    }
    return gcd(y,x%y);
}
int main()
{
    scanf("%d%d",&n,&m);
    scanf("%s%s",s,t);
    int ruler=0;
    int l=gcd(n,m);
    X=n*m/l;
    if (s[0]!=t[0])
    {
        printf("-1\n");
        return 0;
    }
    if (n==1)
    {
        printf("%d\n",m);
    }
    if (m==1)
    {
        printf("%d\n",n);
    }
    if (n==m)
    {
        for (int i=0;i<n;i++)
        {
            if (s[i]!=t[i])
            {
                printf("-1\n");
                return 0;
            }
        }
        printf("%d\n",n);
        return 0;
    }
    for (int i=1;i<=n;i++)
    {
        flag[X/n*i+1]=true;
        co[X/n*i+1]=s[i];
    }
    for (int i=1;i<=m;i++)
    {
        if (flag[X/m*i+1]==true)
        {
            if (co[X/m*i+1]!=t[i])
            {
                ruler=1;
                break;
            }
        }
    }
    if (ruler==1)
    {
        printf("-1\n");
    }
    else
    {
        printf("%d\n",X);
    }
    return 0;
}

Compiler output:
/tmp/ccckYDUc.o: in function `main':
a.cc:(.text+0x62): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in /tmp/ccckYDUc.o
a.cc:(.text+0x6c): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccckYDUc.o
a.cc:(.text+0xc2): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccckYDUc.o
a.cc:(.text+0xc9): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in /tmp/ccckYDUc.o
a.cc:(.text+0x159): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccckYDUc.o
a.cc:(.text+0x169): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in /tmp/ccckYDUc.o
a.cc:(.text+0x1e7): relocation truncated to fit: R_X86_64_PC32 against symbol `flag' defined in .bss section in /tmp/ccckYDUc.o
a.cc:(.text+0x20d): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccckYDUc.o
a.cc:(.text+0x255): relocation truncated to fit: R_X86_64_PC32 against symbol `flag' defined in .bss section in /tmp/ccckYDUc.o
a.cc:(.text+0x290): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in /tmp/ccckYDUc.o
collect2: error: ld returned 1 exit status
Language: C++

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

long long gcd(long long a, long long b) {
  if(a % b == 0) return b;
  else return gcd(b,a % b);
}

char s[100010], t[100010];
map<int,int> mp;

int main() {
  long long n, m;
  scanf("%lld%lld%s%s", &n, &m, s, t);
  long long k = 1LL * n / gcd(n,m) * m;
  if(n < m) swap(n,m);
  for(int i = 1, j = 1;j <= n && i <= k;i += (k / n), j ++) {
  	a[i] = s[j] - 'a' + 1;
  }
  for(int i = 1, j = 1;j <= m && i <= k;i += (k / m), j ++) {
  	int x = s[j] - 'a' + 1;
  	if(a[i] && a[i] != x) {
	  puts("-1");
	  return 0;
  	}
  }
  printf("%lld\n", k);
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:9: error: 'a' was not declared in this scope
   18 |         a[i] = s[j] - 'a' + 1;
      |         ^
a.cc:22:12: error: 'a' was not declared in this scope
   22 |         if(a[i] && a[i] != x) {
      |            ^
Language: C++

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N, M;
string S, T;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;
    return ((m / gcd(m, n)) * n);
}

void solve() {
    ll L = lcm(N, M);
    ll step = lcm(L / N, L / M);
//    if (N < M) {
        REP(i, L / M) {
            if (S[(step / (L / N)) * i] != T[(step / (L / M)) * i]) {
                cout << "-1" << endl;
                return;
            }
        }
//        cout << L << endl;
//    } else if (M < N) {
        REP(i, L / N) {
            if (T[(step / (L / M)) * i] != S[(step / (L / N)) * i]) {
                cout << "-1" << endl;
                return;
            }
        }
        cout << L << endl;
//    } else {
//        REP(i, N) {
//            if (S[i] != T[i]) {
//                cout << "-1" << endl;
//                return;
//            }
//        }
//        cout << N << endl;
    }
}

int main() {
    cin >> N >> M;
    cin >> S >> T;
    solve();
    return 0;
}

Compiler output:
a.cc:63:1: error: expected declaration before '}' token
   63 | }
      | ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <string>
using namespace std;

int main() {
    int64_t n, m;
    cin >> n >> m;

    string s, t;
    cin >> s >> t;

    int64_t l = n * m / __algo_gcd(n, m);

    map<int64_t, int> a;

    for (int i = 0; i < n; i++) {
        a[i * l / n] = i;
    }

    for (int i = 0; i < m; i++) {
        if (a.count(i * l / m) && s[a[i * l / m]] != t[i]) {
            cout << -1 << endl;

            return 0;
        } 
    }

    cout << l << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:25: error: '__algo_gcd' was not declared in this scope
   17 |     int64_t l = n * m / __algo_gcd(n, m);
      |                         ^~~~~~~~~~
Language: C++

#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll M(ll a,ll b)
{
    if(a<b) swap(a,b);
    while(a%b!=0)
    {
        ll t=a%b;
        a=b;
        b=t;
    }
    return b;
}
int main()
{
    ll n,m;
    string a,b;
    scanf("%lld%lld",&n,&m);
    cin>>a>>b;
    if(a[0]!=b[0]) {printf("-1\n");return 0;}
    ll ans=n*m/M(n,m);
    bool flag=true;
    ll x=ans/n,y=ans/m;
    ll xx=2*x,yy=2*y
    ll cot1=1,cot2=1;
    while(cot1<n&&cot2<m)
    {
       if(xx<yy) xx+=x,cot1++;
       else if(yy<xx) yy+=y,cot2++;
       else if(xx==yy)
            {
              if(a[cot1]!=b[cot2])
              {
                    flag=false;break;
              }
              xx+=x;yy+=y;cot1++;cot2++;
            }
     }
      if(flag)
     {
            printf("%lld\n",ans);return 0;
     }
    printf("-1\n");
} 

Compiler output:
a.cc: In function 'int main()':
a.cc:4:12: error: expected ',' or ';' before 'long'
    4 | #define ll long long
      |            ^~~~
a.cc:28:5: note: in expansion of macro 'll'
   28 |     ll cot1=1,cot2=1;
      |     ^~
a.cc:29:11: error: 'cot1' was not declared in this scope
   29 |     while(cot1<n&&cot2<m)
      |           ^~~~
a.cc:29:19: error: 'cot2' was not declared in this scope
   29 |     while(cot1<n&&cot2<m)
      |                   ^~~~
Language: C++

#include<iostream>
using namespace std;
int main(){
  long long N,M,k,l;
  cin>>N>>M;
  char s[N],t[M];
  long long GCM,gameover=0;
  for(long long i=0;i<N;i++)
  {
    cin>>s[i];
  }
  for(long long i=0;i<M;i++)
  {
    cin>>t[i];
  }
  if(M>=N){
  k=M;
  l=N;
}else {
  k=N;
  l=M;
  }
  while(k!=0&&l!=0){
    if(k>=l){
      k=k%l;
    }else{
      l=l%k;
    }
    }
    if(k==0){
      GCM=l;
    }else{
      GCM=k;
    }
    long long LCM = N / GCM * M;
if(M==LCM&&N==LCM){
  for(long long i=0;i<M;i++){
    if(s[i]!=t[i]){
      gameover=1;
      break;
  }
}else if(N==LCM){
  for(long long i=0;i<M;i++){
    if(s[i*(N/M)]!=t[i]){
      gameover=1;
      break;
  }
}
}else if(M==LCM){
      for(long long i=0;i<N;i++){
        if(s[i]!=t[i*(M/N)]){
          gameover=1;
          break;
      }
    }

  }else {
    if(s[0]!=t[0]){
      gameover=1;
    }
  }
  if(gameover==1){
    std::cout<<-1<<std::endl;
  }else{
    std::cout<<LCM<<std::endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:42:2: error: expected '}' before 'else'
   42 | }else if(N==LCM){
      |  ^~~~
a.cc:36:19: note: to match this '{'
   36 | if(M==LCM&&N==LCM){
      |                   ^
Language: C

#include<stdio.h>

long gcd(long c,long b){
	if(b>a){
tmp =a;
a=b;
b=a;
}
long r=a%b;
while(r!=0){
a=b;
b=r;
r=a%b;
}
return r;
}

int main(){
	int n,m;
	char s[100001];
	char t[100001];
	scanf("%d%d%s%s",&n,&m,s,t);
	long long l,i,tmp;
	if(n>m)tmp=gcd(m,n);
	else tmp=gcd(n,m);
l=n*m/tmp;
	for(i=0;i<=n;i++){
				if(s[i*n/tmp]!=t[i*m/tmp]){
					puts("-1");
					return 0;
			}
	}
	printf("%lld\n",l);
	return 0;
}

Compiler output:
main.c: In function 'gcd':
main.c:4:14: error: 'a' undeclared (first use in this function)
    4 |         if(b>a){
      |              ^
main.c:4:14: note: each undeclared identifier is reported only once for each function it appears in
main.c:5:1: error: 'tmp' undeclared (first use in this function)
    5 | tmp =a;
      | ^~~
Language: C++

#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll M(ll a,ll b)
{
    if(a<b) swap(a,b);
    while(a%b!=0)
    {
        ll t=a%b;
        a=b;
        b=t;
    }
    return b;
}
int main()
{
    ll n,m;
    string a,b;
    scanf("%lld%lld",&n,&m);
    cin>>a>>b;
    if(a[0]!=b[0]) {printf("-1\n");return 0;}
    ll ans=n*m/M(n,m);
    bool flag=true;
    ll x=ans/n,y=ans/m;
    ll cot1=1,cot2=1;
    while(cot1<n&&cot2<m)
    {
       if(x<y) x+=x,cot1++;
       else if(y<x) y+=y,cot2++;
       else if(x==y)
            {
              if(a[cot1]!=b[cot2])
              {
                    flag=false;break;
              }
              x+=x;y+=y;cot1++;cot2++;
            }
     }
     for(int i=cot1;i<n;i++)
       if(a[i]!=0) flag=flase;
  for(int i=cot2;i<m;i++)
    if(b[i]!=0) flag=flase;
      if(flag)
     {
            printf("%lld\n",ans);return 0;
     }
    printf("-1\n");
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:25: error: 'flase' was not declared in this scope
   42 |        if(a[i]!=0) flag=flase;
      |                         ^~~~~
a.cc:44:22: error: 'flase' was not declared in this scope
   44 |     if(b[i]!=0) flag=flase;
      |                      ^~~~~
Language: Java

import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long M = sc.nextLong();
    String S = sc.next();
    String T = sc.next();
    long g = gcd(N,M);
    boolean is_ok = true;
    long n = N/g;
    long m = M/g;
    long L = n*m*g;
    for(int l=0;l<g;l++){
      if(S.charAt((int)l*n)!=T.charAt((int)l*m)){
        is_ok = false;
        break;
      }
    }
    if(is_ok){
      System.out.println(L);
    }else{
      System.out.println(-1);
    }
  }

  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }

}


Compiler output:
Main.java:16: error: incompatible types: possible lossy conversion from long to int
      if(S.charAt((int)l*n)!=T.charAt((int)l*m)){
                        ^
Main.java:16: error: incompatible types: possible lossy conversion from long to int
      if(S.charAt((int)l*n)!=T.charAt((int)l*m)){
                                            ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors
Language: C++

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

int gcd(long long int m,long long int n ){
  if(0 == m || 0 == n ) return 0;
  while(m != n){
	if (m > n) m = m - n;
	else n = n - m;
	}
  return m;
}

int main() {
  long long long long int N,M;
  string S;
  string T;
  cin >> N >> M >> S >> T;
  long long int g = gcd(N,M);
  long long int a=N/g,b=M/g;
  bool t=true;
  for(long long int i=0;i<g;i++){
    if(S[a*i] != T[b*i]){
      t=false;
      cout << -1 << endl;
      return 0;
    }
  }
  if(t) cout << N*M/g << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:13: error: 'long long long' is too long for GCC
   14 |   long long long long int N,M;
      |             ^~~~
a.cc:14:18: error: 'long long long' is too long for GCC
   14 |   long long long long int N,M;
      |                  ^~~~
Language: C++

#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll M(ll a,ll b)
{
    if(a<b) swap(a,b);
    while(a%b!=0)
    {
        ll t=a%b;
        a=b;
        b=t;
    }
    return b;
}
int main()
{
    ll n,m;
    string a,b;
    scanf("%lld%lld",&n,&m);
    cin>>a>>b;
    ll ans;
    if(a[0]!=b[0]) {printf("-1\n");return 0;}
    ll ans=n*m/M(n,m);
    bool flag=true;
    ll x=ans/n,y=ans/m;
    int cot1=1,cot2=1;
    while(cot1<n&&cot2<m)
    {
         if(x<y) x+=x,cot1++;
         else if(y<x) y+=y,cot2++;
         else if(x==y)
           {
              if(a[cot1]!=b[cot2])
              {
                    flag=false;break;
              }
              x+=x;y+=y;cot1++;cot2++;
           }
    }
      if(flag)
     {
            printf("%lld\n",ans);return 0;
     }
    printf("-1\n");
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:8: error: redeclaration of 'long long int ans'
   25 |     ll ans=n*m/M(n,m);
      |        ^~~
a.cc:23:8: note: 'long long int ans' previously declared here
   23 |     ll ans;
      |        ^~~
Language: C++

#include<iostream>
#include<math.h>
#include<numeric>
#include<cmath>
using namespace std;
#define int long long

int gcd(int x, int y)
{
    int r;

    if(x == 0 || y == 0)  // 引数チェック
    {
        fprintf(stderr, "引数エラーです。\n");
        return 0;
    }

    // ユーグリッドの互除法
    while((r = x % y) != 0) // yで割り切れるまでループ
    {
        x = y;
        y = r;
    }
    return y;
}

// 最大公約数を求める関数
int lcm(int x, int y)
{
    if(x == 0 || y == 0)  // 引数チェック
    {
        fprintf(stderr, "引数エラーです。\n");
        return 0;
    }

    return (x * y / gcd(x, y));
}
int main()
{
  int n,m,l;
  bool x=true;
  cin >> n >> m;
  string s,t;
  cin>>s>>t;
  int a,b;
  a=n/gcd(n,m);
  b=m/gcd(n,m);
  for(int k=0;k<gcd(n,m);k++)
    if(s[a*k]!=t[b*k])
      x=false;

  if(x)
  cout << lcm(n,m)<<endl;
  else
  cout <<-1;
  //cout << a <<b<<endl;
  return 0;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll M(ll a,ll b)
{
    if(a<b) swap(a,b);
    while(a%b!=0)
    {
        ll t=a%b;
        a=b;
        b=t;
    }
    return b;
}
int main()
{
    ll n,m;
    string a,b;
    scanf("%lld%lld",&n,&m);
    cin>>a>>b;
    ll ans;
    if(a[0]!=b[0]) {printf("-1\n");return 0;}
    ll ans=n*m/M(n,m);
            bool flag=true;
            ll x=ans/n,y=ans/m;
            int cot1=1,cot2=1;
            while(cot1<n&&cot2<m)
            {
                if(x<y) x+=x,cot1++;
                else if(y<x) y+=y,cot2++;
                else if(x==y)
                {
                    if(a[cot1]!=b[cot2])
                    {
                        flag=false;break;
                    }
                    x+=x;y+=y;cot1++;cot2++;
                }
            }
            if(flag)
            {
                printf("%lld\n",ans);return 0;
            }
    printf("-1\n");
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:8: error: redeclaration of 'long long int ans'
   25 |     ll ans=n*m/M(n,m);
      |        ^~~
a.cc:23:8: note: 'long long int ans' previously declared here
   23 |     ll ans;
      |        ^~~
Language: C++

#include <iostream>
#include <algorithm>
#include <string>

typedef long long ll;

using namespace std;

int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd

int main()
{
    ll n,m,e,a,b,ans;
    string s,t;
    cin >> n >> m;
    cin >> s >> t;
    e = gcd(n,m)

    a = n/e;
    b = m/e;
    ans = a*b*e; //最小公倍数

    for(int i = 0;i < e;i++)
    {
        if(s[i*a] != t[i*b])
        {
            ans = -1;
            break;
        }
    }

    cout << ans << endl;

    return 0;

}



Compiler output:
a.cc: In function 'int main()':
a.cc:30:17: error: expected ';' before 'a'
   30 |     e = gcd(n,m)
      |                 ^
      |                 ;
   31 | 
   32 |     a = n/e;
      |     ~
Language: C++

#include <iostream>
#include <algorithm>
#include <string>

typedef long long ll;

using namespace std;
int main()
{
    ll n,m,e,a,b,ans;
    string s,t;
    cin >> n >> m;
    cin >> s >> t;
    e = gcd(n,m)

    a = n/e;
    b = m/e;
    ans = a*b*e; //最小公倍数

    for(int i = 0;i < e;i++)
    {
        if(s[i*a] != t[i*b])
        {
            ans = -1;
            break;
        }
    }

    cout << ans << endl;

    return 0;

}

int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd

Compiler output:
a.cc: In function 'int main()':
a.cc:14:9: error: 'gcd' was not declared in this scope
   14 |     e = gcd(n,m)
      |         ^~~
Language: C++

#include<cstdio>

#include<iostream>

#include<algorithm>

#define ll long long

using namespace std;

ll M(ll a,ll b)

{

    if(a<b) swap(a,b);

    while(a%b!=0)

    {

        ll t=a%b;

        a=b;

        b=t;

    }

    return b;

}

int main()

{

    ll n,m;

    string a,b;

    scanf("%lld%lld",&n,&m);

    cin>>a>>b;

    ll ans;

    if(a[0]!=b[0]) {printf("-1\n");return 0;}

    ll ans=n*m/gcd(n,m);

            bool flag=true;

            ll x=ans/n,y=ans/m;

            int cot1=1,cot2=1;

            while(cot1<n&&cot2<m)

            {

                if(x<y) x+=x,cot1++;

                else if(y<x) y+=y,cot2++;

                else if(x==y)

                {

                    if(a[cot1]!=b[cot2])

                    {

                        flag=false;break;

                    }

                    x+=x;y+=y;cot1++;cot2++;

                }

            }

            if(flag)

            {

                printf("%lld\n",ans);return 0;

            }

    printf("-1\n");

}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:8: error: redeclaration of 'long long int ans'
   49 |     ll ans=n*m/gcd(n,m);
      |        ^~~
a.cc:45:8: note: 'long long int ans' previously declared here
   45 |     ll ans;
      |        ^~~
a.cc:49:16: error: 'gcd' was not declared in this scope
   49 |     ll ans=n*m/gcd(n,m);
      |                ^~~
Language: C++

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int GCD(int x, int y) {
	if (x%y == 0)return y;
	else return GCD(y, x%y);
}

int main(void) {
	long long int N, M;
	char S[200000], T[200000];
	scanf("%lld%lld"acc, &N, &M);
	scanf("%s", S);
	scanf("%s", T);
	int g = GCD(N, M);
	int L = N * M / g;
	int i, a = 0, cnt = 0;
	char X[200000];
	for (i = 0; i < N; i++) {
		X[i*L / N] = S[a++];
		cnt = i * L / N;
	}
	for (i = 0; i < M; i++) {
		//printf("g = %d\n", g);
		//printf("%d\n\n", i*L / M);
		if (i*L / M % g - 1 == 0) {
			if (X[g *= 2] == T[i*L / M]) {
				printf("-1\n");
				return 0;
			}
		}
	}
	/*for (i = 0; i< L; i++) {
		printf("%c", X[i]);
	}*/
	if (X[L] == 'a' || X[L] == 'b' || X[L] == 'c' || X[L] == 'd' || X[L] == 'e' || X[L] == 'f' || X[L] == 'g' || X[L] == 'h' || X[L] == 'i' || X[L] == 'j' || X[L] == 'k' || X[L] == 'l' || X[L] == 'm' || X[L] == 'n' || X[L] == 'o' || X[L] == 'p' || X[L] == 'q' || X[L] == 'r' || X[L] == 's' || X[L] == 't' || X[L] == 'u' || X[L] == 'v' || X[L] == 'w' || X[L] == 'x' || X[L] == 'y' || X[L] == 'z') {
		printf("-1\n");
	}
	else if (L == N || L == M)printf("-1\n");
	else printf("%d\n", L);


	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:15: error: unable to find string literal operator 'operator""acc' with 'const char [9]', 'long unsigned int' arguments
   14 |         scanf("%lld%lld"acc, &N, &M);
      |               ^~~~~~~~~~~~~