Problem p03231 (python)

Fixed submission:
# coding: utf-8
# Your code here!

import fractions
import sys
from collections import defaultdict

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

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

L = lcm(N, M)

dp = defaultdict(lambda: -1)

for i, s in enumerate(S):
    dp[i*L//N] = s

for i, t in enumerate(T):
    if dp[i*L//M] != -1:
        if dp[i*L//M] != t:
            print(-1)
            sys.exit()
print(L)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math
import numpy as np

N = int(input())
A = list(map(int, input().rstrip().split(' ')))

sum_P = []
for i in range(N):
    temp = 0
    for j in range(N):
        #temp += 1 / (1 + abs(i - j))
        temp = 0.1
    sum_P.append(temp)

#cost = np.sum(np.array(sum_P) * A)
    
#print(int(round(cost * math.factorial(N))) % (1_000_000_007))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math
import numpy as np

N = int(input())
A = list(map(int, input().rstrip().split(' ')))

sum_P = []
for i in range(N):
    temp = 0
    for j in range(N):
        temp += 1 / (1 + abs(i - j))
    sum_P.append(temp)

#cost = np.sum(np.array(sum_P) * A)
    
#print(int(round(cost * math.factorial(N))) % (1_000_000_007))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import fractions
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

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

L = lcm(N, M)

dp = [-1] * (L + 10)
'''   
for i, s in enumerate(S):
    dp[i*L//N] = s

for i, t in enumerate(T):
    if dp[i*L//M] != -1:
        if dp[i*L//M] != t:
            print(-1)
            sys.exit()
print(L)
'''

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import fractions
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

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

L = lcm(N, M)

dp = [-1] * (L + 10)
for i, s in enumerate(S):
    dp[i*L//N] = s
'''   
for i, t in enumerate(T):
    if dp[i*L//M] != -1:
        if dp[i*L//M] != t:
            print(-1)
            sys.exit()
print(L)
'''

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import fractions
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

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

L = lcm(N, M)

dp = [-1] * (L + 10)
for i, s in enumerate(S):
    dp[i*L//N] = s

flag = False   
for i, t in enumerate(T):
    if dp[i*L//M] != -1:
        if dp[i*L//M] != t:
            print(-1)
            flag = True
            break
            #sys.exit()
if flag == False:
    print(L)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import fractions
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

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

L = lcm(N, M)

dp = [-1] * (L + 10)
for i, s in enumerate(S):
    dp[i*L//N] = s
   
for i, t in enumerate(T):
    if dp[i*L//M] != -1:
        if dp[i*L//M] != t:
            print(-1)
            sys.exit()
print(L)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import fractions
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

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

L = lcm(N, M)

dp = [-1] * (L + 10)
for i, s in enumerate(S):
    dp[i*L//N] = s
    
for i, t in enumerate(T):
    if dp[i*L//M] != -1 and dp[i*L//M] != t:
        print(-1)
        sys.exit()
print(L)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import fractions
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
    
L = lcm(N, M)

dp = [-1] * L
for i, s in enumerate(S):
    dp[i*L//N] = s
    
for i, t in enumerate(T):
    if dp[i*L//M] != -1 and dp[i*L//M] != t:
        print(-1)
        sys.exit()
print(L)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

def lcm(x, y):
    return int((x * y) / math.gcd(x, y))
    
L = lcm(N, M)

if S[0] != T[0]:
    print(-1)
    #sys.exit()
elif L == N or L == M:
    dp = [-1] * L
    for i, s in enumerate(S):
        dp[i*L/N] = s
        
    for i, t in enumerate(T):
        if dp[i*L/M] != -1 and dp[i*L/M] != t:
            print(-1)
            #sys.exit()
else:
    print(L)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

def lcm(x, y):
    return int((x * y) / math.gcd(x, y))
    
L = lcm(N, M)
if S[0] != T[0]:
    print(-1)
    sys.exit()
elif L == N or L == M:
    dp = [-1] * L
    for i, s in enumerate(S):
        dp[i*L/N] = s
        
    for i, t in enumerate(T):
        if dp[i*L/M] != -1 and dp[i*L/M] != t:
            print(-1)
            sys.exit()
else:
    print(L)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
    
L = lcm(N, M)
if S[0] != T[0]:
    print(-1)
    sys.exit()
elif L == N or L == M:
    dp = [-1] * L
    for i, s in enumerate(S):
        dp[i*L//N] = s
        
    for i, t in enumerate(T):
        if dp[i*L//M] != -1 and dp[i*L//M] != t:
            print(-1)
            sys.exit()
else:
    print(L)