From a3e6a9be9b4776b03e80bebe141642314fc0f405 Mon Sep 17 00:00:00 2001 From: Andrey Golikov Date: Fri, 10 Apr 2026 17:30:52 +0600 Subject: [PATCH] feat: add task 8 --- task8/main.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 task8/main.py diff --git a/task8/main.py b/task8/main.py new file mode 100644 index 0000000..3430d21 --- /dev/null +++ b/task8/main.py @@ -0,0 +1,27 @@ +from collections import Counter + +from icecream import ic + + +string: str = input() +max_weight = 0 + +def calculate_weight(counter: Counter[str], length: int) -> int: + max_occurence: int = counter.most_common(1)[0][1] + return max_occurence * length + +counter: Counter[str] = Counter() + +for length in range(1, len(string) + 1): + counter.clear() + counter.update( + string[i:i+length] for i in range(len(string) - length + 1) + ) + # ic(counter) + max_weight: int = max( + max_weight, + calculate_weight(counter, length) + ) + ic(max_weight) + +print(max_weight)