length = int(input()) list = tuple(input().split()) set = set(list) newList = [] result = 0 for i in set: newList.append(list.count(i)) newList = sorted(newList) while len(newList) > 0: max = newList[len(newList)-1] temp = newList[0] maxTemp = (temp, 0 , 1) temp1 = 0 temp2 = 1 notDeleted = True if len(newList) > 1: while temp2 <= len(newList): if temp == max-1: newList.remove(max) for i in range(temp1, temp2): newList.remove(newList[i]) notDeleted = False result += 1 break elif temp < max-1: if temp > maxTemp[0]: maxTemp = (temp, temp1, temp2) temp += newList[temp2] temp2 += 1 else: temp -= newList[temp1] temp1 += 1 if notDeleted: for i in range(temp1, temp2): newList.remove(newList[i]) newList.remove(max) result += 1 else: result += 1 break print(result)
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 | length = int(input()) list = tuple(input().split()) set = set(list) newList = [] result = 0 for i in set: newList.append(list.count(i)) newList = sorted(newList) while len(newList) > 0: max = newList[len(newList)-1] temp = newList[0] maxTemp = (temp, 0 , 1) temp1 = 0 temp2 = 1 notDeleted = True if len(newList) > 1: while temp2 <= len(newList): if temp == max-1: newList.remove(max) for i in range(temp1, temp2): newList.remove(newList[i]) notDeleted = False result += 1 break elif temp < max-1: if temp > maxTemp[0]: maxTemp = (temp, temp1, temp2) temp += newList[temp2] temp2 += 1 else: temp -= newList[temp1] temp1 += 1 if notDeleted: for i in range(temp1, temp2): newList.remove(newList[i]) newList.remove(max) result += 1 else: result += 1 break print(result) |