Buggy python submission (verdict: Runtime Error):
import fractions


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    l =  n * m // fractions.gcd(n, m)
    x = [' '] * l
    for i in range(n):
        x[i * (l // n)] = s[i]
    for i in range(m):
        if x[i * (l // m)] == ' ':
            continue
        if x[i * (l // m)] != t[i]:
            print(-1)
            return
    print(l)


if __name__ == '__main__':
    main()


Fixed submission:
import fractions


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    l = n * m // fractions.gcd(n, m)
    x = {}
    for i in range(n):
        x[i * (l // n)] = s[i]
    for i in range(m):
        if i * (l // m) not in x:
            continue
        if x[i * (l // m)] != t[i]:
            print(-1)
            return
    print(l)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import fractions
def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    x = [' '] * n*m
    for i in range(n):
        x[i*m] = s[i]
    for i in range(m):
        if x[i*n] == ' ':
            continue
        if x[i*n] != t[i]:
            print(-1)
            return
    print(n * m // fractions.gcd(n, m))

if __name__ == '__main__':
    main()


Fixed submission:
import fractions


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    l = n * m // fractions.gcd(n, m)
    x = {}
    for i in range(n):
        x[i * (l // n)] = s[i]
    for i in range(m):
        if i * (l // m) not in x:
            continue
        if x[i * (l // m)] != t[i]:
            print(-1)
            return
    print(l)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import fraction


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    x = [' '] * n * m
    for i in range(n):
        x[i * m] = s[i]
    for i in range(m):
        if x[i * n] == ' ':
            continue
        if x[i * n] != t[i]:
            print(-1)
            return
    print(n * m // fraction.gcd(n, m))


if __name__ == '__main__':
    main()


Fixed submission:
import fractions


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    l = n * m // fractions.gcd(n, m)
    x = {}
    for i in range(n):
        x[i * (l // n)] = s[i]
    for i in range(m):
        if i * (l // m) not in x:
            continue
        if x[i * (l // m)] != t[i]:
            print(-1)
            return
    print(l)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math
def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    x = [' '] * n*m
    for i in range(n):
        x[i*m] = s[i]
    for i in range(m):
        if x[i*n] == ' ':
            continue
        if x[i*n] != t[i]:
            print(-1)
            return
    print(n * m // math.gcd(n, m))

if __name__ == '__main__':
    main()

Fixed submission:
import fractions


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    l = n * m // fractions.gcd(n, m)
    x = {}
    for i in range(n):
        x[i * (l // n)] = s[i]
    for i in range(m):
        if i * (l // m) not in x:
            continue
        if x[i * (l // m)] != t[i]:
            print(-1)
            return
    print(l)


if __name__ == '__main__':
    main()