Language: C

	if(S[0] != T[0]){
		printf("-1");
      	free(X);
		free(S);
		free(T);
		return 0;
	}
	
	L = calc_LCM(N,M);

	X = (char *)malloc((L+1)*sizeof(char));

	for(i=0;i<L-1;i++){
		X[i] = '0';
	}
	X[L-1] = '\0';

	for(i=0;i<N;i++){
		X[i*(L/N)] = S[i];
	}
	
	for(i=0;i<M;i++){
		if(X[i*(L/M)] == '0'){
			X[i*(L/M)] = T[i];
		}
		else if(X[i*(L/M)] != T[i]){
			printf("-1");
           	free(X);
			free(S);
			free(T);
			return 0;
		}
	}
	printf("%lld",L);
	free(X);
	free(S);
	free(T);
	
	return 0;
}


int calc_LCM(int a,int b){
	
	int tmp;
  	long long int x = a*b;
	
	if(a<b){
		tmp = a;
		a = b;
		b = tmp;
	}
	
	tmp = a% b;
	
	while(tmp != 0){
		a = b;
		b = tmp;
		tmp = a % b;
	}
	return x / b;
	
}


Compiler output:
main.c:1:9: error: expected identifier or '(' before 'if'
    1 |         if(S[0] != T[0]){
      |         ^~
main.c:9:9: warning: data definition has no type or storage class
    9 |         L = calc_LCM(N,M);
      |         ^
main.c:9:9: error: type defaults to 'int' in declaration of 'L' [-Wimplicit-int]
main.c:9:13: error: implicit declaration of function 'calc_LCM' [-Wimplicit-function-declaration]
    9 |         L = calc_LCM(N,M);
      |             ^~~~~~~~
main.c:9:22: error: 'N' undeclared here (not in a function)
    9 |         L = calc_LCM(N,M);
      |                      ^
main.c:9:24: error: 'M' undeclared here (not in a function)
    9 |         L = calc_LCM(N,M);
      |                        ^
main.c:11:9: warning: data definition has no type or storage class
   11 |         X = (char *)malloc((L+1)*sizeof(char));
      |         ^
main.c:11:9: error: type defaults to 'int' in declaration of 'X' [-Wimplicit-int]
main.c:11:21: error: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
   11 |         X = (char *)malloc((L+1)*sizeof(char));
      |                     ^~~~~~
main.c:1:8: note: include '<stdlib.h>' or provide a declaration of 'malloc'
  +++ |+#include <stdlib.h>
    1 |         if(S[0] != T[0]){
main.c:11:21: warning: incompatible implicit declaration of built-in function 'malloc' [-Wbuiltin-declaration-mismatch]
   11 |         X = (char *)malloc((L+1)*sizeof(char));
      |                     ^~~~~~
main.c:11:21: note: include '<stdlib.h>' or provide a declaration of 'malloc'
main.c:11:13: error: initialization of 'int' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
   11 |         X = (char *)malloc((L+1)*sizeof(char));
      |             ^
main.c:11:13: error: initializer element is not constant
main.c:13:9: error: expected identifier or '(' before 'for'
   13 |         for(i=0;i<L-1;i++){
      |         ^~~
main.c:13:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
   13 |         for(i=0;i<L-1;i++){
      |                  ^
main.c:13:24: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
   13 |         for(i=0;i<L-1;i++){
      |                        ^~
main.c:16:9: warning: data definition has no type or storage class
   16 |         X[L-1] = '\0';
      |         ^
main.c:16:9: error: type defaults to 'int' in declaration of 'X' [-Wimplicit-int]
main.c:16:9: error: variably modified 'X' at file scope
main.c:16:9: error: conflicting types for 'X'; have 'int[1]'
main.c:11:9: note: previous definition of 'X' with type 'int'
   11 |         X = (char *)malloc((L+1)*sizeof(char));
      |         ^
main.c:18:9: error: expected identifier or '(' before 'for'
   18 |         for(i=0;i<N;i++){
      |         ^~~
main.c:18:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
   18 |         for(i=0;i<N;i++){
      |                  ^
main.c:18:22: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
   18 |         for(i=0;i<N;i++){
      |                      ^~
main.c:22:9: error: expected identifier or '(' before 'for'
   22 |         for(i=0;i<M;i++){
      |         ^~~
main.c:22:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
   22 |         for(i=0;i<M;i++){
      |                  ^
main.c:22:22: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
   22 |         for(i=0;i<M;i++){
      |                      ^~
main.c:34:16: error: expected declaration specifiers or '...' before string constant
   34 |         printf("%lld",L);
      |                ^~~~~~
main.c:34:23: error: expected declaration specifiers or '...' before 'L'
   34 |         printf("%lld",L);
      |                       ^
main.c:35:9: warning: data definition has no type or storage class
   35 |         free(X);
      |         ^~~~
main.c:35:9: error: type defaults to 'int' in declaration of 'free' [-Wimplicit-int]
main.c:35:9: error: parameter names (without types) in function declaration [-Wdeclaration-missing-parameter-type]
main.c:35:9: warning: conflicting types for built-in function 'free'; expected 'void(void *)' [-Wbuiltin-declaration-mismatch]
main.c:35:9: note: 'free' is declared in header '<stdlib.h>'
main.c:36:9: warning: data definition has no type or storage class
   36 |         free(S);
      |         ^~~~
main.c:36:9: error: type defaults to 'int' in declaration of 'free' [-Wimplicit-int]
main.c:36:9: error: parameter names (without types) in function declaration [-Wdeclaration-missing-parameter-type]
main.c:37:9: warning: data definition has no type or storage class
   37 |         free(T);
      |         ^~~~
main.c:37:9: error: type defaults to 'int' in declaration of 'free' [-Wimplicit-int]
main.c:37:9: error: parameter names (without types) in function declaration [-Wdeclaration-missing-parameter-type]
main.c:39:9: error: expected identifier or '(' before 'return'
   39 |         return 0;
      |         ^~~~~~
main.c:40:1: error: expected identifier or '(' before '}' token
   40 | }
      | ^