from collections import Counter

def rearange_string(S):
    counts = Counter(S)
    max_count = max(counts.values(), default=0)
    return max_count <= (len(S) + 1) // 2