Problem p03262 (python)

Fixed submission:
n, x = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def get_res(cities):
    if len(cities) == 2:
        return cities[1] - cities[0]
    else:
        gcds = []
        for i in range(len(cities) - 2):
            c1 = cities[i]
            c2 = cities[i + 1]
            c3 = cities[i + 2]
            gcds.append(gcd(c2 - c1, c3 - c2))
        return min(gcds)

print(get_res(cities))

Buggy submission (verdict: Runtime Error):
import math
n, x = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()
 
def get_res(cities):
    if len(cities) == 2:
        return cities[1] - cities[0]
    elif len(cities) < 100:
        gcds = []
        for i in range(len(cities) - 2):
            c1 = cities[i]
            c2 = cities[i + 1]
            c3 = cities[i + 2]
            gcds.append(math.gcd(c2 - c1, c3 - c2))
        return min(gcds)
    else:
        return 100


print(get_res(cities))

Buggy submission (verdict: Runtime Error):
import math
n, x = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()
 
def get_res(cities):
    if len(cities) < 2:
        return 1
    if len(cities) == 2:
        return cities[1] - cities[0]
    else:
        gcds = []
        for i in range(len(cities) - 2):
            c1 = cities[i]
            c2 = cities[i + 1]
            c3 = cities[i + 2]
            gcds.append(math.gcd(c2 - c1, c3 - c2))
        return min(gcds)


print(get_res(cities))

Buggy submission (verdict: Runtime Error):
import math
n, x = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()
 
def get_res(cities):
    if len(cities) <= 2:
        return cities[1] - cities[0]
    else:
        gcds = []
        for i in range(len(cities) - 2):
            c1 = cities[i]
            c2 = cities[i + 1]
            c3 = cities[i + 2]
            gcds.append(math.gcd(c2 - c1, c3 - c2))
        return min(gcds)


print(get_res(cities))

Buggy submission (verdict: Runtime Error):
import math
n, x = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()
 
def get_res(cities):
    if len(cities) == 2:
        return cities[1] - cities[0]
    else:
        gcds = []
        for i in range(len(cities) - 2):
            c1 = cities[i]
            c2 = cities[i + 1]
            c3 = cities[i + 2]
            gcds.append(math.gcd(c2 - c1, c3 - c2))
        return min(gcds)


print(get_res(cities))

Buggy submission (verdict: Runtime Error):
import math
n, x = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()
 
def get_res(cities):
    if len(cities) == 2:
        return cities[1] - cities[0]
    else:
        gcds = []
        for i in range(len(cities) - 2):
            c1 = cities[i]
            c2 = cities[i + 1]
            c3 = cities[i + 2]
            gcds.append(math.gcd(c2 - c1, c3 - c2))

        return min(gcds)
 
print(get_res(cities))

Buggy submission (verdict: Runtime Error):
import math
n, x = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()

def get_res(cities):
    if len(cities) == 2:
        return cities[1] - cities[0]

    gcds = []
    for i in range(len(cities) - 2):
        c1 = cities[i]
        c2 = cities[i + 1]
        c3 = cities[i + 2]
        gcds.append(math.gcd(c2 - c1, c3 - c2))

    return min(gcds)

print(get_res(cities))