Problem p03428 (python)

Fixed submission:
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10**9 + 7
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



#11:00




n = int(input())
xy = []

for i in range(n):
    xy.append(list(map(int, input().split())))
    xy[-1].append(i)
    
origin = list(xy)
xy.sort(key = lambda x : -x[1])
xy.sort(key = lambda x : x[0])
#print(xy)

down = [0]

while(True):
    now = down[-1]
    nowxy = xy[down[-1]]
    #print(now,nowxy)
    if(now==n-1):
        break
    shouldBreak = 0
    for j in range(now+1,n):
        if(nowxy[0] == xy[j][0]):
            down.append(j)
            shouldBreak=1
            break
    if(shouldBreak):
        continue
    gradmin = 10**18
    nxt = -1
    for j in range(now+1,n):
        grad = (xy[j][1]-nowxy[1])/(xy[j][0]-nowxy[0])
        #print(grad)
        if(gradmin > grad):
            gradmin = grad
            nxt = j
            
    down.append(nxt)
#print(down)
down = [xy[i][2] for i in down]
down = down[0:len(down)-1]
#print(down)

xy.sort(key = lambda x : x[1])
xy.sort(key = lambda x : -x[0])
#print(xy)

up = [0]
    
while(True):
    now = up[-1]
    nowxy = xy[up[-1]]
    #print(now,nowxy)
    if(now==n-1):
        break
    
    shouldBreak = 0
    for j in range(now+1,n):
        if(nowxy[0] == xy[j][0]):
            up.append(j)
            #print(j)
            shouldBreak=1
            break
    if(shouldBreak):
        continue
    gradmin = 10**18
    nxt = -1
    for j in range(now+1,n):
        grad = (xy[j][1]-nowxy[1])/(xy[j][0]-nowxy[0])
        if(gradmin > grad):
            #print("g",j,grad)
            gradmin = grad
            nxt = j
            
    up.append(nxt)
    #print(up)
#print(up)
up = [xy[i][2] for i in up]
up = up[:len(up)-1]
#print(up)
seq = list(down)
for i in up:
    seq.append(i)

#print(seq)

ans = [0.0 for i in range(n)]

def u2(a):
    return math.sqrt(a[0]*a[0]+a[1]*a[1])
def dot(a,b):
    return a[0]*b[0]+a[1]*b[1]

m = len(seq)
for i in range(len(seq)):
    num1,num2,num3 = seq[(i-1)%m],seq[i],seq[(i+1)%m]
    p1,p2,p3 = origin[num1],origin[num2], origin[num3]
    left = [p1[0]-p2[0],p1[1]-p2[1]]
    right = [p3[0]-p2[0],p3[1]-p2[1]]
    cos = dot(left,right)/u2(left)/u2(right)
    #print(cos,left,right)
    deg = math.pi - math.acos(cos)
    ans[num2] = deg/(2.0*math.pi)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10**9 + 7
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



#11:00




n = int(input())
xy = []

for i in range(n):
    xy.append(list(map(int, input().split())))
    xy[-1].append(i)
    
origin = list(xy)
xy.sort(key = lambda x : -x[1])
xy.sort(key = lambda x : x[0])
#print(xy)

down = [0]

while(True):
    now = down[-1]
    nowxy = xy[down[-1]]
    #print(now,nowxy)
    if(now==n-1):
        break
    shouldBreak = 0
    for j in range(now+1,n):
        if(nowxy[0] == xy[j][0]):
            down.append(j)
            shouldBreak=1
            break
    if(shouldBreak):
        break
    gradmin = 10**18
    nxt = -1
    for j in range(now+1,n):
        grad = (xy[j][1]-nowxy[1])/(xy[j][0]-nowxy[0])
        #print(grad)
        if(gradmin > grad):
            gradmin = grad
            nxt = j
            
    down.append(nxt)
#print(down)
down = [xy[i][2] for i in down]
down = down[0:len(down)-1]
#print(down)

xy.sort(key = lambda x : x[1])
xy.sort(key = lambda x : -x[0])
#print(xy)

up = [0]
    
while(True):
    now = up[-1]
    nowxy = xy[up[-1]]
    #print(now,nowxy)
    if(now==n-1):
        break
    
    shouldBreak = 0
    for j in range(now+1,n):
        if(nowxy[0] == xy[j][0]):
            up.append(j)
            shouldBreak=1
            break
    if(shouldBreak):
        break
    gradmin = 10**18
    nxt = -1
    for j in range(now+1,n):
        grad = (xy[j][1]-nowxy[1])/(xy[j][0]-nowxy[0])
        if(gradmin > grad):
            #print("g",j,grad)
            gradmin = grad
            nxt = j
            
    up.append(nxt)
    #print(up)
#print(up)
up = [xy[i][2] for i in up]
up = up[:len(up)-1]
#print(up)
seq = list(down)
for i in up:
    seq.append(i)

#print(seq)

ans = [0.0 for i in range(n)]

def u2(a):
    return math.sqrt(a[0]*a[0]+a[1]*a[1])
def dot(a,b):
    return a[0]*b[0]+a[1]*b[1]

m = len(seq)
for i in range(len(seq)):
    num1,num2,num3 = seq[(i-1)%m],seq[i],seq[(i+1)%m]
    p1,p2,p3 = origin[num1],origin[num2], origin[num3]
    left = [p1[0]-p2[0],p1[1]-p2[1]]
    right = [p3[0]-p2[0],p3[1]-p2[1]]
    cos = dot(left,right)/u2(left)/u2(right)
    #print(cos,left,right)
    deg = math.pi - math.acos(cos)
    ans[num2] = deg/(2.0*math.pi)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10**9 + 7
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



#11:00




n = int(input())
xy = []

for i in range(n):
    xy.append(list(map(int, input().split())))
    xy[-1].append(i)
    
origin = list(xy)
xy.sort(key = lambda x : -x[1])
xy.sort(key = lambda x : x[0])
#print(xy)

down = [0]

while(True):
    now = down[-1]
    nowxy = xy[down[-1]]
    #print(now,nowxy)
    if(now==n-1):
        break
    
    for j in range(now+1,n):
        if(nowxy[0] == xy[j][0]):
            down.append(j)
            break
    gradmin = 10**18
    nxt = -1
    for j in range(now+1,n):
        grad = (xy[j][1]-nowxy[1])/(xy[j][0]-nowxy[0])
        #print(grad)
        if(gradmin > grad):
            gradmin = grad
            nxt = j
            
    down.append(nxt)
#print(down)
down = [xy[i][2] for i in down]
down = down[0:len(down)-1]
#print(down)

xy.sort(key = lambda x : x[1])
xy.sort(key = lambda x : -x[0])
#print(xy)

up = [0]
    
while(True):
    now = up[-1]
    nowxy = xy[up[-1]]
    #print(now,nowxy)
    if(now==n-1):
        break
    
    for j in range(now+1,n):
        if(nowxy[0] == xy[j][0]):
            up.append(j)
            break
    gradmin = 10**18
    nxt = -1
    for j in range(now+1,n):
        grad = (xy[j][1]-nowxy[1])/(xy[j][0]-nowxy[0])
        if(gradmin > grad):
            #print("g",j,grad)
            gradmin = grad
            nxt = j
            
    up.append(nxt)
    #print(up)
#print(up)
up = [xy[i][2] for i in up]
up = up[:len(up)-1]
#print(up)
seq = list(down)
for i in up:
    seq.append(i)

#print(seq)

ans = [0.0 for i in range(n)]

def u2(a):
    return math.sqrt(a[0]*a[0]+a[1]*a[1])
def dot(a,b):
    return a[0]*b[0]+a[1]*b[1]

m = len(seq)
for i in range(len(seq)):
    num1,num2,num3 = seq[(i-1)%m],seq[i],seq[(i+1)%m]
    p1,p2,p3 = origin[num1],origin[num2], origin[num3]
    left = [p1[0]-p2[0],p1[1]-p2[1]]
    right = [p3[0]-p2[0],p3[1]-p2[1]]
    cos = dot(left,right)/u2(left)/u2(right)
    #print(cos,left,right)
    deg = math.pi - math.acos(cos)
    ans[num2] = deg/(2.0*math.pi)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10**9 + 7
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



#11:00




n = int(input())
xy = []

for i in range(n):
    xy.append(list(map(int, input().split())))
    xy[-1].append(i)
    
origin = list(xy)
xy.sort(key = lambda x : -x[1])
xy.sort(key = lambda x : x[0])
#print(xy)

down = [0]

while(True):
    now = down[-1]
    nowxy = xy[down[-1]]
    #print(now,nowxy)
    if(now==n-1):
        break
    
    for j in range(now+1,n):
        if(nowxy[0] == xy[j][0]):
            down.append(j)
            break
    gradmin = 10**18
    nxt = -1
    for j in range(now+1,n):
        grad = (xy[j][1]-nowxy[1])/(xy[j][0]-nowxy[0])
        #print(grad)
        if(gradmin > grad):
            gradmin = grad
            nxt = j
            
    down.append(j)
#print(down)
down = [xy[i][2] for i in down]
down = down[0:len(down)-1]
#print(down)

xy.sort(key = lambda x : x[1])
xy.sort(key = lambda x : -x[0])
#print(xy)

up = [0]
    
while(True):
    now = up[-1]
    nowxy = xy[up[-1]]
    #print(now,nowxy)
    if(now==n-1):
        break
    
    for j in range(now+1,n):
        if(nowxy[0] == xy[j][0]):
            up.append(j)
            break
    gradmin = 10**18
    nxt = -1
    for j in range(now+1,n):
        grad = (xy[j][1]-nowxy[1])/(xy[j][0]-nowxy[0])
        if(gradmin > grad):
            #print("g",j,grad)
            gradmin = grad
            nxt = j
            
    up.append(nxt)
    #print(up)
#print(up)
up = [xy[i][2] for i in up]
up = up[:len(up)-1]
#print(up)
seq = list(down)
for i in up:
    seq.append(i)

#print(seq)

ans = [0.0 for i in range(n)]

def u2(a):
    return math.sqrt(a[0]*a[0]+a[1]*a[1])
def dot(a,b):
    return a[0]*b[0]+a[1]*b[1]

m = len(seq)
for i in range(len(seq)):
    num1,num2,num3 = seq[(i-1)%m],seq[i],seq[(i+1)%m]
    p1,p2,p3 = origin[num1],origin[num2], origin[num3]
    left = [p1[0]-p2[0],p1[1]-p2[1]]
    right = [p3[0]-p2[0],p3[1]-p2[1]]
    cos = dot(left,right)/u2(left)/u2(right)
    #print(cos,left,right)
    deg = math.pi - math.acos(cos)
    ans[num2] = deg/(2.0*math.pi)

for i in ans:
    print(i)