Problem p03231 (python)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def main():
    N, M = map(int, input().split())
    S = input()
    T = input()
    result = N * M / gcd(N, M)
    cand = (result / N) * (result / M) / gcd(int((result / N)), int((result / M)))
    for i in range(0, int(result / cand)):
        if S[int((i * cand) / (result / N))] != T[int((i * cand) / (result / M))]:
            return '-1'
    return int(result)
print(main())

Buggy submission (verdict: Runtime Error):
import math
def main():
    N, M = map(int, input().split())
    S = input()
    T = input()
    result = N * M / math.gcd(N, M)
    cand = (result / N) * (result / M) / math.gcd(int((result / N)), int((result / M)))
    for i in range(0, int(result / cand)):
        if S[int((i * cand) / (result / N))] != T[int((i * cand) / (result / M))]:
            return '-1'
    return int(result)
print(main())

Buggy submission (verdict: Runtime Error):
import math
def main():
    N, M = map(int, input().split())
    S = input()
    T = input()
    result = N * M / math.gcd(N, M)
    cand = (result / N) * (result / M) / math.gcd(int((result / N)), int((result / M)))
    for i in range(0, int(result / cand)):
        if S[int((i * cand) / (result / N))] != T[int((i * cand) / (result / M))]:
            return -1
    return int(result)
print(main())

Buggy submission (verdict: Runtime Error):
import math
def main():
    N, M = map(int, input().split())
    S = input()
    T = input()
    result = N * M / math.gcd(N, M)
    cand = (result / N) * (result / M) / math.gcd((result / N), (result / M))
    for i in range(0, result / cand):
        if S[(i * cand) / (result / N)] != T[(i * cand) / (result / M)]:
            return -1
    return result
print(main())

Buggy submission (verdict: Runtime Error):
import math
def main():
    N, M = map(int, input().split())
    S = input()
    T = input()
    result = N * M // math.gcd(N, M)
    cand = (result // N) * (result // M) // math.gcd((result // N), (result // M))
    for i in range(0, result // cand):
        if S[(i * cand) // (result // N)] != T[(i * cand) // (result // M)]:
            return -1
    return result
print(main())

Buggy submission (verdict: Runtime Error):
import math

N, M = map(int, input().split())
S = list(input())
T = list(input())

def cal(N, M, S, T):
    result = N * M // math.gcd(N, M)
    cand = (result // N) * (result // M) // math.gcd((result // N), (result // M))
    for i in range(0, result // cand):
         if S[(i * cand) // (result // N)] != T[(i * cand) // (result // M)]:
             return -1
    return result
print(cal(N, M, S, T))

Buggy submission (verdict: Runtime Error):
import math

N, M = map(int, input().split())
S = list(input())
T = list(input())

def main(N, M, S, T):
    result = N * M // math.gcd(N, M)
    cand = (result // N) * (result // M) // math.gcd((result // N), (result // M))
    for i in range(0, result // cand):
        print(S[(i * cand + 3) // (result // N) - 1])
        print(T[(i * cand + 3) // (result // M) - 1])
        if S[(i * cand) // (result // N)] != T[(i * cand) // (result // M)]:
            return -1
    return result
print(main(N, M, S, T))

Buggy submission (verdict: Runtime Error):
import math

N, M = map(int, input().split())
S = list(input())
T = list(input())

def main(N, M, S, T):
    result = N * M // math.gcd(N, M)
    cand = (result // N) * (result // M) // math.gcd((result // N), (result // M))
    for i in range(0, result // cand):
        if S[(i * cand + 3) // (result // N) - 1] != T[(i * cand + 3) // (result // M) - 1]:
            return '-1'
    return result
print(main(N, M, S, T))