Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

# from numba import njit
from math import gcd
# input = stdin.readline

def lcm(x,y):
  return x*y//gcd(x,y)

# @njit
def solve(n,m,s,t):
  L = lcm(n,m)
  
  lst = [""]*L
  s_interval = L//n
  t_interval = L//m
  for i in range(n):
    lst[i*s_interval] = s[i]
  for i in range(m):
    if lst[i*t_interval] =="":
      continue
    if lst[i*t_interval] != t[i]:
      return "-1"
  return L
  

def main():
  N,M = map(int,input().split())
  s = input()
  t = input()
  print(solve(N,M,s,t))
  return

if __name__ == '__main__':
  main()


Fixed submission:
#!/usr/bin/env python3

# from numba import njit
from math import gcd
# input = stdin.readline

def lcm(x,y):
  return x*y//gcd(x,y)

# @njit
def solve(n,m,s,t):
  L = lcm(n,m)
  G = gcd(n,m)
  s_interval = L//n
  t_interval = L//m
  for i in range(G):
    if s[i*n//G] != t[i*m//G]:
      return -1
  return L
  

def main():
  N,M = map(int,input().split())
  s = input()
  t = input()
  print(solve(N,M,s,t))
  return

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

# from numba import njit
from math import gcd
# input = stdin.readline

def lcm(x,y):
  return x*y//gcd(x,y)

# @njit
def solve(n,m,s,t):
  L = lcm(n,m)
  
  lst = [""]*L
  s_interval = L//n
  t_interval = L//m
  for i in range(n):
    lst[i*s_interval] = s[i]
  for i in range(m):
    if lst[i*t_interval] =="":
      continue
    if lst[i*t_interval] != t[i]:
      return -1
  return L
  

def main():
  N,M = map(int,input().split())
  s = input()
  t = input()
  print(solve(N,M,s,t))
  return

if __name__ == '__main__':
  main()


Fixed submission:
#!/usr/bin/env python3

# from numba import njit
from math import gcd
# input = stdin.readline

def lcm(x,y):
  return x*y//gcd(x,y)

# @njit
def solve(n,m,s,t):
  L = lcm(n,m)
  G = gcd(n,m)
  s_interval = L//n
  t_interval = L//m
  for i in range(G):
    if s[i*n//G] != t[i*m//G]:
      return -1
  return L
  

def main():
  N,M = map(int,input().split())
  s = input()
  t = input()
  print(solve(N,M,s,t))
  return

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

# from numba import njit
from math import gcd
# input = stdin.readline

def lcm(x,y):
  return x*y//gcd(x,y)

# @njit
def solve(n,m,s,t):
  L = lcm(n,m)
  
  lst = [""]*L
  s_interval = L//n
  t_interval = L//m
  for i in range(n):
    lst[i*s_interval] = s[i]
  for i in range(m):
    if lst[i*t_interval] =="":
      continue
    if lst[i*t_interval] != t[i]:
      return -1
  return L
  
  
  return n



def main():
  N,M = map(int,input().split())
  s = input()
  t = input()
  print(solve(N,M,s,t))
  return

if __name__ == '__main__':
  main()


Fixed submission:
#!/usr/bin/env python3

# from numba import njit
from math import gcd
# input = stdin.readline

def lcm(x,y):
  return x*y//gcd(x,y)

# @njit
def solve(n,m,s,t):
  L = lcm(n,m)
  G = gcd(n,m)
  s_interval = L//n
  t_interval = L//m
  for i in range(G):
    if s[i*n//G] != t[i*m//G]:
      return -1
  return L
  

def main():
  N,M = map(int,input().split())
  s = input()
  t = input()
  print(solve(N,M,s,t))
  return

if __name__ == '__main__':
  main()