Problem p02888 (python)

Fixed submission:
import sys
import bisect

n = int(input())
l = list(map(int, sys.stdin.readline().strip().split()))

l. sort()
ans = 0
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        a = l[i]
        b = l[j]
        ab = a + b
        right = bisect.bisect_left(l, ab) - 1
        ans += (right - j)

print(ans)

Buggy submission (verdict: Runtime Error):
# Atcoder 2019/10/19
"""
# A
A, B = map(int, input().split())

ans = A - 2 * B

if ans >= 0:
    print(ans)
else:
    print(0)
"""

"""
# B
import sys
n = int(input())
d = list(map(int, sys.stdin.readline().strip().split()))

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        ans += d[i] * d[j]

print(ans)
"""

"""
# C
n = int(input())
s = input()

count = 1

for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        count += 1

print(count)
"""

# D
import sys

def main():
    n = int(input())
    l = list(map(int, sys.stdin.readline().strip().split()))

    global big_ans
    big_ans = []

    def angle(l, count, ans, i, n):
        if len(ans) == 3:
            big_ans.append(ans)
            return ans

        if i == n:
            # print('i end')
            return

        if len(ans) + n - i < 3:
            return

        passa = ans.copy()
        angle(l, count, passa, i + 1, n)
        ans.append(l[i])
        passb = ans.copy()
        angle(l, count + 1, passb, i + 1, n)

    angle(l, 0, [], 0, len(l))

    ans_count = 0

    for i in big_ans:
        if sum(i) - 2 * max(i) > 0:
            ans_count += 1

    print(ans_count)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# Atcoder 2019/10/19
"""
# A
A, B = map(int, input().split())

ans = A - 2 * B

if ans >= 0:
    print(ans)
else:
    print(0)
"""

"""
# B
import sys
n = int(input())
d = list(map(int, sys.stdin.readline().strip().split()))

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        ans += d[i] * d[j]

print(ans)
"""

"""
# C
n = int(input())
s = input()

count = 1

for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        count += 1

print(count)
"""

# D
import sys

def main():
    n = int(input())
    l = list(map(int, sys.stdin.readline().strip().split()))

    global big_ans
    big_ans = []

    def angle(l, count, ans, i, n):
        if len(ans) == 3:
            big_ans.append(ans)
            return ans

        if i == n:
            # print('i end')
            return

        if len(ans) + n - i < 3:
            return

        passa = ans.copy()
        angle(l, count, passa, i + 1, n)
        ans.append(l[i])
        passb = ans.copy()
        angle(l, count + 1, passb, i + 1, n)

    angle(l, 0, [], 0, len(l))

    ans_count = 0

    for i in big_ans:
        if sum(i) - 2 * max(i) > 0:
            ans_count += 1

    print(ans_count)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# Atcoder 2019/10/19
"""
# A
A, B = map(int, input().split())

ans = A - 2 * B

if ans >= 0:
    print(ans)
else:
    print(0)
"""

"""
# B
import sys
n = int(input())
d = list(map(int, sys.stdin.readline().strip().split()))

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        ans += d[i] * d[j]

print(ans)
"""

"""
# C
n = int(input())
s = input()

count = 1

for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        count += 1

print(count)
"""

# D
import sys

def main():
    n = int(input())
    l = list(map(int, sys.stdin.readline().strip().split()))

    global big_ans
    big_ans = []

    def angle(l, count, ans, i, n):
        if len(ans) == 3:
            big_ans.append(ans)
            return ans

        if i == n:
            # print('i end')
            return

        if len(ans) + n - i < 3:
            return

        passa = ans.copy()
        angle(l, count, passa, i + 1, n)
        ans.append(l[i])
        passb = ans.copy()
        angle(l, count + 1, passb, i + 1, n)


    angle(l, 0, [], 0, len(l))

    ans_count = 0

    for i in big_ans:
        big = i.index(max(i))
        if sum(i) - 2 * i[big] > 0:
            ans_count += 1

    print(ans_count)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
l = list(map(int, sys.stdin.readline().strip().split()))

global big_ans
big_ans = []

def angle(l, count, ans, i, n):
    if len(ans) == 3:
        big_ans.append(ans)
        return ans

    if i == n:
        # print('i end')
        return

    if len(ans) + n - i < 3:
        return

    passa = ans.copy()
    # print('l : {}  count : {}  ans : {}  i : {}  l[i] : {}'.format(l, count, ans, i, l[i]))
    angle(l, count, passa, i + 1, n)
    ans.append(l[i])
    passb = ans.copy()
    angle(l, count + 1, passb, i + 1, n)


angle(l, 0, [], 0, len(l))

ans_count = 0

for i in big_ans:
    big = i.index(max(i))
    if sum(i) - 2 * i[big] > 0:
        ans_count += 1

print(ans_count)

Buggy submission (verdict: Runtime Error):
# Atcoder 2019/10/19
"""
# A
A, B = map(int, input().split())

ans = A - 2 * B

if ans >= 0:
    print(ans)
else:
    print(0)
"""

"""
# B
import sys
n = int(input())
d = list(map(int, sys.stdin.readline().strip().split()))

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        ans += d[i] * d[j]

print(ans)
"""

"""
# C
n = int(input())
s = input()

count = 1

for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        count += 1

print(count)
"""

# D
import sys
n = int(input())
l = list(map(int, sys.stdin.readline().strip().split()))

global big_ans
big_ans = []

def angle(l, count, ans, i):
    if len(ans) == 3:
        big_ans.append(ans)
        return ans

    if i == len(l):
        # print('i end')
        return
    passa = ans.copy()
    # print('l : {}  count : {}  ans : {}  i : {}  l[i] : {}'.format(l, count, ans, i, l[i]))
    angle(l, count, passa, i + 1)
    ans.append(l[i])
    passb = ans.copy()
    angle(l, count + 1, passb, i + 1)


angle(l, 0, [], 0)

ans_count = 0

for i in big_ans:
    big = i.index(max(i))
    if sum(i) - 2 * i[big] > 0:
        ans_count += 1

print(ans_count)