summaryrefslogtreecommitdiffstats
path: root/Main/Python/2022/S4.py
blob: 450a14c3c0922ecaa0fec7842c1eeaef042b09a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from math import pi, cos, sin
from itertools import permutations, combinations


def in_triangle(ax, ay, bx, by, cx, cy):
    px, py = r, r
    try:
        w1 = (ax * (cy - ay) + (py - ay) * (cx - ax) - px * (cy - ay)) / ((by - ay) * (cx - ax) - (bx - ax) * (cy - ay))
        w2 = (py - ay - w1 * (by - ay)) / (cy - ay)
    except:
        return False

    if w1 >= 0 and w2 >= 0 and w1 + w2 <= 1:
        return True
    return False


N, C = tuple(map(int, input().split()))
r = C / (2 * pi)


def to_coordinates(p):
    angle = p / C * 2 * pi
    return r * cos(angle) + r, r * sin(angle) + r


def is_opposite(a, b):
    if abs(temp[a] - temp[b]) == C / 2:
        return True
    return False


def is_good(subset):
    t = {i: [] for i in subset}
    for a, b, c in permutations(subset, 3):
        t[a].append((a, b, c))

    for i in subset:

        a1, b1, c1 = t[i][0]
        ax1, ay1 = P[a1]
        bx1, by1 = P[b1]
        cx1, cy1 = P[c1]
        a2, b2, c2 = t[i][1]
        ax2, ay2 = P[a2]
        bx2, by2 = P[b2]
        cx2, cy2 = P[c2]

        if not (in_triangle(ax1, ay1, bx1, by1, cx1, cy1) or in_triangle(ax2, ay2, bx2, by2, cx2, cy2)):
            return False

    for a, b in combinations(subset, 2):
        if is_opposite(a, b):
            return False

    return True


temp = {i + 1: int(val) for i, val in enumerate(input().split())}
P = {i: to_coordinates(temp[i]) for i in temp.keys()}

output = 0
for subset in combinations(P.keys(), 3):
    if is_good(subset):
        output += 1

print(output)