I am trying to solve the Hackerrank Indivisible Subset problem listed below:

I tried to execute the following solution (which works for a test case):
n = 4
k = 3
a = [1, 7, 2, 4]
while True:
all_pairs = [(a[i],a[j]) for i in range(len(a)) for j in range(i+1,len(a))]
tested_pairs = {pair: (pair[0] + pair[1]) % k != 0 for pair in all_pairs}
disqualified_pairs = {key: value for key, value in tested_pairs.iteritems() if not value}.keys()
if not disqualified_pairs:
break
occurrences = list(sum(disqualified_pairs, ()))
counts = map(lambda x: occurrences.count(x), a)
index_remove = counts.index(max(counts))
a.remove(index_remove)
print len(a)
What I'm trying to do is identify the “offensive” pairs and remove the element athat occurs most often until there are no “offensive” pairs left.
However, for most test cases, I get a "RunTime Error":

, , ( 2), . - , ?
UPDATE
k = 2 a = [1, 2, 3], :
n = 4
k = 2
a = [1, 2, 3]
while True:
all_pairs = [(a[i],a[j]) for i in range(len(a)) for j in range(i+1,len(a))]
disqualified_pairs = [pair for pair in all_pairs if (pair[0] + pair[1]) % k == 0]
if not disqualified_pairs:
break
offending_numbers = sum(disqualified_pairs, ())
counts = {el: offending_numbers.count(el) for el in set(offending_numbers)}
number_to_remove = max(counts, key=counts.__getitem__)
a.remove(number_to_remove)
print len(a)
a [2, 3] , . , - . , " " :

https://www.hackerrank.com/challenges/pairs/forum/comments/9154, - ( , ..), , . ?