Given a set of N positive integers. It is necessary to choose from the set an arbitrary number of numbers so that their sum is as large as possible and not divisible by 6. In the answer, you must specify the number of selected numbers and their sum. If it is impossible to receive the necessary sum, it is considered that 0 numbers are chosen and their sum is equal to 0.
a = [] N = int(input()) maxsum=0 for i in range(N): a.append(int(input())) a.sort(reverse=True) for j in range(N): sum = a[j] #строка 8 maxsum += sum if maxsum%6==0 and a!=[]: a.sort() a.pop(0) sum=maxsum=0 for o in range(len(a)): sum = a[o] maxsum += sum if maxsum%6!=0: print(len(a),maxsum) Why is the IndexError: list index out of range error on line 8 issued every time the number 6 is entered into array a? Explain, please, simple language to a novice. You can also fix some clumsy code. In general, the program works with the exception of this case with a six.