Problem p02888 (python)

Fixed submission:
#from collections import Counter

#import numpy as np

input = raw_input
n = int(input())
#nums = np.zeros(2001, dtype=int)
nums = [0] * 2001
#nums = np.zeros(2001, dtype=int)

ls = map(int, input().split(" "))
#ls = Counter(map(int, ls))
#vals = ls.keys()
ls = sorted(ls)
for l in ls:
    #print(l)
    nums[l] += 1

set_vals = [val for val in range(2001) if nums[val] >= 1]
#print(vals)

#cumsum = np.cumsum(nums)

#print(set_vals)
len_set = len(set_vals)
out = 0
for i in range(len_set):
    val1 = set_vals[i]
    num_i = nums[val1]
    if num_i >= 3:
        out += (num_i * (num_i-1) * (num_i-2) // 6)
    
    if num_i >= 2:
        val2 = set_vals[i]
        for j in range(i+1, len_set):
            val3 = set_vals[j]
            num_h = nums[val3]
            if 2 * val1 <= val3:
                break

            out += ((num_i * (num_i-1)) // 2) * num_h

    for j in range(i+1, len_set):
        val2 = set_vals[j]
        num_j = nums[val2]

        if num_j >= 2:
            out += (num_i *  num_j * (num_j - 1) // 2 )

        for h in range(j+1, len_set):
            val3 = set_vals[h]
            #print(val1, val2, val3)
            num_h = nums[val3]
            if val1 + val2 <= val3:
                break

            #print("num", num_i, num_j, num_h)
            out += (num_i * num_j * num_h)

print(out)

Buggy submission (verdict: Runtime Error):
#from collections import Counter

#import numpy as np

input = raw_input
n = int(input())
#nums = np.zeros(2001, dtype=int)
nums = [0] * 2001
#nums = np.zeros(2001, dtype=int)

ls = map(int, input().split(" "))
#ls = Counter(map(int, ls))
#vals = ls.keys()
ls = sorted(ls)
for l in ls:
    #print(l)
    nums[l] += 1

set_vals = [val for val in range(2001) if nums[val] >= 1]
#print(vals)

#cumsum = np.cumsum(nums)

#print(set_vals)
len_set = len(set_vals)
out = 0
for i in range(len_set):
    val1 = set_vals[i]
    num_i = nums[val1]
    if num_i >= 3:
        out += (num_i * (num_i-1) * (num_i-2) // 6)
    
    if num_i >= 2:
        val2 = set_vals[i]
        for j in range(i+1, len_set):
            val3 = set_vals[j]
            num_h = nums[val3]
            if 2 * val1 <= val3:
                break

            out += ((num_i * (num_i-1)) // 2) * num_h

    for j in range(i+1, len_set):
        val2 = set_vals[j]
        num_j = nums[val2]

        if num_j >= 2:
            out += (num_i *  num_j * (num_j - 1) // 2 )

        for h in range(j+1, len_set):
            val3 = set_vals[h]
            #print(val1, val2, val3)
            num_h = nums[val3]
            if val1 + val2 <= val3:
                break

            #print("num", num_i, num_j, num_h)
            out += (num_i * num_j * num_h)

print(out)

Buggy submission (verdict: Runtime Error):
#from collections import Counter

#import numpy as np

input = raw_input
n = int(input())
#nums = np.zeros(2001, dtype=int)
nums = [0] * 2001
#nums = np.zeros(2001, dtype=int)

ls = map(int, input().split(" "))
#ls = Counter(map(int, ls))
#vals = ls.keys()
ls = sorted(ls)
for l in ls:
    #print(l)
    nums[l] += 1

set_vals = [val for val in range(2001) if nums[val] >= 1]
#print(vals)

#cumsum = np.cumsum(nums)

#print(set_vals)
len_set = len(set_vals)
out = 0
for i in range(len_set):
    val1 = set_vals[i]
    num_i = nums[val1]
    if num_i >= 3:
        out += (num_i * (num_i-1) * (num-2) // 6)
    
    if num_i >= 2:
        val2 = set_vals[i]
        for j in range(i+1, len_set):
            val3 = set_vals[j]
            num_h = nums[val3]
            if 2 * val1 <= val3:
                break

            out += ((num_i * (num_i-1)) // 2) * num_h

    for j in range(i+1, len_set):
        val2 = set_vals[j]
        num_j = nums[val2]

        if num_j >= 2:
            out += (num_i *  num_j * (num_j - 1) // 2 )

        for h in range(j+1, len_set):
            val3 = set_vals[h]
            #print(val1, val2, val3)
            num_h = nums[val3]
            if val1 + val2 <= val3:
                break

            #print("num", num_i, num_j, num_h)
            out += (num_i * num_j * num_h)

print(out)

Buggy submission (verdict: Runtime Error):
#from collections import Counter

import numpy as np

n = int(input())
nums = np.zeros(2001, dtype=int)

ls = map(int, input().split(" "))
#ls = Counter(map(int, ls))
#vals = ls.keys()
ls = sorted(ls)
for l in ls:
    #print(l)
    nums[l] += 1

set_vals = [val for val in range(2001) if nums[val] >= 1]
#print(vals)

#cumsum = np.cumsum(nums)

#print(set_vals)
len_set = len(set_vals)
out = 0
for i in range(len_set):
    val1 = set_vals[i]
    num_i = nums[val1]
    if num_i >= 3:
        out += (num_i * (num_i-1) * (num-2) // 6)
    
    if num_i >= 2:
        val2 = set_vals[i]
        for j in range(i+1, len_set):
            val3 = set_vals[j]
            num_j = nums[val3]
            if 2 * val1 <= val3:
                break

            out += ((num_i * (num_i-1)) // 2) * num_j

    for j in range(i+1, len_set):
        val2 = set_vals[j]
        num_j = nums[val2]

        if num_j >= 2:
            out += (num_i *  num_j * (num_j - 1) // 2 )

        for h in range(j+1, len_set):
            val3 = set_vals[h]
            #print(val1, val2, val3)
            num_h = nums[val3]
            if val1 + val2 <= val3:
                break

            #print("num", num_i, num_j, num_h)
            out += (num_i * num_j * num_h)

print(out)