Problem p03231 (python)

Fixed submission:
import fractions
N,M = map(int,input().split())
S = input()
T = input()
G = fractions.gcd(N,M)
L = (N * M) // G
div_N = N // G
div_M = M // G

i = 0
j = 0

while i < N and j < M:
  if S[i] != T[j]:
    print(-1)
    exit()
  else:
    i += div_N
    j += div_M
print(L)

Buggy submission (verdict: Runtime Error):
import fractions
N,M = map(int,input().split())
S = input()
T = input()
L = (N * M) // fractions.gcd(N,M)
div_N = L // N
div_M = L // M
s = [""] * L

for ss in range(N):
  if ss == 0:
    s[0] = S[0]
    if s[0] != T[0]:
      print(-1)
      exit()
  else:
    s[ss * (div_N)] = S[ss]
#print(L)
#print(s)
#print(tag)
count = 1
while div_M < L and count < M:
  if s[div_M] != "" and s[div_M] != T[count]:
      print(-1)
      exit()
  div_M += div_M
  count += 1
print(L)

Buggy submission (verdict: Runtime Error):
import fractions
N,M = map(int,input().split())
S = input()
T = input()
L = (N * M) // fractions.gcd(N,M)
div_N = L // N
div_M = L // M
s = [""] * L

for ss in range(N):
  if ss == 0:
    s[0] = S[0]
    if s[0] != T[0]:
      print(-1)
      exit()
  else:
    s[ss * (div_N)] = S[ss]
#print(L)
#print(s)
#print(tag)
count = 1
while div_M < L:
  if s[div_M] != "" and s[div_M] != T[count]:
      print(-1)
      exit()
  div_M += div_M
  count += 1
print(L)

Buggy submission (verdict: Runtime Error):
import fractions
N,M = map(int,input().split())
S = input()
T = input()
L = (N * M) // fractions.gcd(N,M)
div_N = L // N
div_M = L // M
tag = (div_N * div_M) // fractions.gcd(div_N,div_M)
count = tag // div_M
s = [""] * L
t = [""] * L

for ss in range(N):
  if ss == 0:
    s[0] = S[0]
    if s[0] != T[0]:
      print(-1)
      exit()
  else:
    s[ss * (div_N)] = S[ss]
#print(L)
#print(s)
#print(tag)
while tag <= L:
  if s[tag] != "" and s[tag] != T[count]:
      print(-1)
      exit()
  tag += tag
  count += count
print(L)

Buggy submission (verdict: Runtime Error):
import fractions
N,M = map(int,input().split())
S = input()
T = input()
L = (N * M) // fractions.gcd(N,M)
div_N = L // N
div_M = L // M
tag = (div_N * div_M) // fractions.gcd(div_N,div_M)
count = tag // div_M
s = [""] * L
t = [""] * L

for ss in range(N):
  if ss == 0:
    s[0] = S[0]
    if s[0] != T[0]:
      print(-1)
      exit()
  else:
    s[ss * (div_N)] = S[ss]
#print(L)
#print(s)
#print(tag)
while tag < L:
  if s[tag] != "" and s[tag] != T[count]:
      print(-1)
      exit()
  tag += tag
  count += count
print(L)

Buggy submission (verdict: Runtime Error):
import fractions
N,M = map(int,input().split())
S = input()
T = input()
L = (N * M) // fractions.gcd(N,M)
div_N = L // N
div_M = L // M
tag = (div_N * div_M) // fractions.gcd(div_N,div_M)
s = [""] * L
t = [""] * L

for ss in range(N):
  if ss == 0:
    s[0] = S[0]
    if s[0] != T[0]:
      print(-1)
      exit()
  else:
    s[ss * (div_N)] = S[ss]

for tt in range(M):
  if tt == 0:
    t[0] = T[0]
  else:
    t[tt * (div_M)] = T[tt]
while tag < L:
  if s[tag] != "" and s[tag] != t[tag]:
      print(-1)
      exit()
  tag += tag
print(L)

Buggy submission (verdict: Runtime Error):
import fractions
import sys
sys.setrecursionlimit(100000000)
N,M = map(int,input().split())
S = input()
T = input()
X = (N * M) // fractions.gcd(N,M)

div_N = X // N
div_M = X // M  
s = [""] * X

for ss in range(N):
  if ss == 0:
    s[0] = S[0]
    if s[0] != T[0]:
      print(-1)
      exit()
  else:
    s[ss * (div_N)] = S[ss]

for tt in range(M):
  if tt == 0:
    if s[0] != T[tt]:
      print(-1)
      exit()
  else:
    pro = tt * (div_M)
    if s[pro] != "" and s[pro] != T[tt]:
      print(-1)
      exit()
print(X)

Buggy submission (verdict: Runtime Error):
import fractions
N,M = map(int,input().split())
S = input()
T = input()
flag = True
X = (N * M) // fractions.gcd(N,M)

div_N = X // N
div_M = X // M  
s = [""] * X

for ss in range(N):
  if ss == 0:
    s[0] = S[0]
  else:
    s[ss * (div_N)] = S[ss]

for tt in range(M):
  if tt == 0:
    if s[0] != T[tt]:
      print(-1)
      exit()
  else:
    pro = tt * (div_M)
    if s[pro] != "" and s[pro] != T[tt]:
      print(-1)
      exit()
print(X)

Buggy submission (verdict: Runtime Error):
import fractions
N,M = map(int,input().split())
S = input()
T = input()
X = (N * M) // fractions.gcd(N,M)

div_N = X // N
div_M = X // M  
s = [""] * X

for ss in range(N):
  if ss == 0:
    s[0] = S[0]
    if s[0] != T[0]:
      print(-1)
      exit()
  else:
    s[ss * (div_N)] = S[ss]

for tt in range(M):
  if tt == 0:
    if s[0] != T[tt]:
      print(-1)
      exit()
  else:
    pro = tt * (div_M)
    if s[pro] != "" and s[pro] != T[tt]:
      print(-1)
      exit()
print(X)

Buggy submission (verdict: Runtime Error):
import fractions
N,M = map(int,input().split())
S = input()
T = input()
flag = True
X = (N * M) // fractions.gcd(N,M)

div_N = X // N
div_M = X // M  
s = [""] * X

for ss in range(N):
  if ss == 0:
    s[0] = S[0]
  else:
    s[ss * (div_N)] = S[ss]

for tt in range(M):
  if tt == 0:
    if s[0] != T[tt]:
      print(-1)
      exit()
  else:
    pro = tt * (div_M)
    if s[pro] != "" and s[pro] != T[tt]:
      print(-1)
      exit()
print(X)