from typing import List

class Solution:
    def leastInterval(self, tasks: List[str], n: int) -> int:
        freq = collections.Counter(tasks)

        maxExec = max(freq.values())
        maxCount = sum(1 for v in freq.values() if v == maxExec)
        
        return max((maxExec-1) * (n+1) + maxCount, len(tasks))