Sherlock considers a string to be valid if all characters of the string appear the same number of times.  It is also valid if he can remove just $1$ character at $1$ index in the string, and the remaining characters will occur the same number of times.  Given a string $s$, determine if it is valid.  If so, return YES, otherwise return NO.

Example 

$s=abc$

This is a valid string because frequencies are $\{a:1,b:1,c:1\}$.  

$s=abcc$  

This is a valid string because we can remove one $c$ and have $1$ of each character in the remaining string.  

$s=abccc$  

This string is not valid as we can only remove $1$ occurrence of $c$.  That leaves character frequencies of $\{a:1,b:1,c:2\}$.  

Function Description  

Complete the isValid function in the editor below.  

isValid has the following parameter(s):  

string s: a string  

Returns  

string: either YES or NO

Input Format

A single string $s$.

Constraints

$1\leq|s|\leq10^5$   
Each character $s[i]\in ascii[a-z]$

Sample Input 0
aabbcd

Sample Output 0
NO

Explanation 0

Given $s="aabbcd"$, we would need to remove two characters, both c and d $\rightarrow$ aabb or a and b $\rightarrow$ abcd, to make it valid. We are limited to removing only one character, so $s$ is invalid.

Sample Input 1
aabbccddeefghi

Sample Output 1
NO

Explanation 1

Frequency counts for the letters are as follows:  

{'a': 2, 'b': 2, 'c': 2, 'd': 2, 'e': 2, 'f': 1, 'g': 1, 'h': 1, 'i': 1}

There are two ways to make the valid string:

Remove $4$ characters with a frequency of $1$: $\{\mbox{fghi}\}$.   
Remove $5$ characters of frequency $2$: $\{\textsf{abcde}\}$.  

Neither of these is an option.

Sample Input 2
abcdefghhgfedecba

Sample Output 2
YES

Explanation 2

All characters occur twice except for $e$ which occurs $3$ times.  We can delete one instance of $e$ to have a valid string.

Difficulty: MEDIUM
Tags: String algorithms

Starter code:

Solutions:
s = input()
distinctList = []
countList = []
for c in s:
	if c not in distinctList:
		distinctList.append(c)
for d in distinctList:
	count = s.count(d)
	countList.append(count)
key = countList[0]
flags = 0
for count in countList:
	if key != count:
		flags += 1
if flags > 1:
	print('NO')
else:
	print('YES')


from heapq import heapify, heappush, heappop
from collections import Counter, defaultdict, deque, OrderedDict
from sys import setrecursionlimit, maxsize
from bisect import bisect_left, bisect, insort_left, insort
from math import ceil, log, factorial, hypot, pi
from fractions import gcd
from copy import deepcopy
from functools import reduce
from operator import mul
from itertools import product, permutations, combinations, accumulate, cycle
from string import ascii_uppercase, ascii_lowercase, ascii_letters, digits, hexdigits, octdigits
prod = lambda l: reduce(mul, l)
prodmod = lambda l, mod: reduce(lambda x, y: mul(x, y) % mod, l)

def read_list(t):
	return [t(x) for x in input().split()]

def read_line(t):
	return t(input())

def read_lines(t, N):
	return [t(input()) for _ in range(N)]
S = read_line(str)
c = Counter(S)
m = c.most_common()
f = m[0][1]
flag = False
for val in c.values():
	if f != val and flag:
		break
	if f != val:
		flag = True
else:
	print('YES')
	exit(0)
f = m[1][1]
flag = False
for val in c.values():
	if f != val and flag:
		print('NO')
		break
	if f != val:
		flag = True
else:
	print('YES')


s = input()
dic = {}
for c in s:
	if c in dic:
		dic[c] += 1
	else:
		dic[c] = 1
l = list(set(dic.values()))
if len(l) == 1:
	print('YES')
elif len(l) == 2:
	l1 = []
	l2 = []
	for key in dic.keys():
		val = dic[key]
		if val == l[0]:
			l1.append(key)
		if val == l[1]:
			l2.append(key)
	if len(l1) == 1 or len(l2) == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


l = [0 for i in range(26)]
st = input()
for i in st:
	l[ord(i) - 97] += 1
l = [i for i in l if i != 0]
l2 = len(list(set(l)))
if l2 > 2:
	print('NO')
elif l2 == 1:
	print('YES')
else:
	l_2 = l
	l = list(set(l))
	if abs(l[1] - l[0]) == 1 and l_2.count(max(l)) == 1 or (l_2.count(1) == 1 and min(l) == 1):
		print('YES')
	else:
		print('NO')


s = input()
ch = dict()
for i in s:
	if ch.get(i) == None:
		ch[i] = 1
	else:
		ch[i] += 1
ch = list(ch.values())
ch.sort()
max_val = max(ch)
flag = False
count = 0
for i in range(0, len(ch) - 1):
	x = max_val - ch[i]
	if x > 1 and ch[i] != 1:
		flag = True
		break
	elif x == 1 and ch[i] == 1:
		count += 1
	if count > 1:
		flag = True
		break
if flag:
	print('NO')
else:
	print('YES')


import math
import sys
s = input()
m = dict()
alfa = 'abcdefghijklmnopqrstuvwxyz'
for i in s:
	if i not in m:
		m[i] = 1
	else:
		m[i] += 1
x = 0
y = 0
na = -1
nb = -1
fail = 0
for i in alfa:
	if i in m:
		g = m[i]
		if na == -1:
			na = g
			x = 1
		elif nb == -1 and g != na:
			nb = g
			y = 1
		else:
			if g == na:
				x += 1
			if g == nb:
				y += 1
			if g != na and g != nb:
				fail = 1
if x > 1 and y > 1:
	fail = 1
if fail == 0:
	print('YES')
else:
	print('NO')


import sys

def get_larger(diffs):
	return max(diffs.values())
in_string = input()
letters = {}
for letter in in_string:
	if letter in letters:
		letters[letter] += 1
	else:
		letters[letter] = 1
diffs = {}
num = None
for letter in letters:
	if letters[letter] in diffs:
		diffs[letters[letter]] += 1
	else:
		diffs[letters[letter]] = 1
	if len(diffs) > 2:
		print('NO')
		sys.exit()
	diff_keys = list(diffs)
	if len(diff_keys) > 1 and (abs(diff_keys[0] - diff_keys[1]) != 1 and diffs[min(diff_keys)] > 1 or (diffs[diff_keys[0]] > 1 and diffs[diff_keys[1]] > 1)):
		print('NO')
		sys.exit()
print('YES')


A = input().strip()
freq = {}
for letter in A:
	if letter in freq:
		freq[letter] += 1
	else:
		freq[letter] = 1
F = list(freq.values())
(fmax, fmin) = (max(F), min(F))
(cmax, cmin) = (F.count(fmax), F.count(fmin))
if fmax == fmin:
	print('YES')
elif cmax + cmin != len(F):
	print('NO')
elif fmin == cmin == 1:
	print('YES')
elif fmax - fmin == 1 and cmax == 1:
	print('YES')
else:
	print('NO')


string = [i for i in input()]
count = [0 for i in range(26)]
n = len(string)
for i in range(n):
	count[ord(string[i]) - ord('a')] += 1
lis = [0 for i in range(max(count))]
for i in count:
	if i > 0:
		lis[i - 1] += 1
a = []
l = {}
for i in range(len(lis)):
	if lis[i] != 0:
		l[i] = lis[i]
		a += [i]
if len(l) > 2:
	print('NO')
elif len(l) == 1:
	print('YES')
elif len(l) < 1:
	print('NO')
elif len(l) == 2:
	if a[1] - a[0] == 1:
		if lis[a[1]] == 1 or lis[a[0]] == 1:
			print('YES')
		else:
			print('NO')
	elif a[0] != 0:
		print('NO')
	else:
		print('YES')


test = input()
hmap = {}
for letter in test:
	if letter in hmap:
		hmap[letter] += 1
	else:
		hmap[letter] = 1
first = True
freq = 0
diff_count = 0
diff = 0
freq = {}
for (k, v) in hmap.items():
	if v not in freq:
		freq[v] = 1
	else:
		freq[v] += 1
diff = 0
first = True
k1 = k2 = k = 0
if len(freq) <= 1:
	print('YES')
elif len(freq) == 2:
	for (key, val) in freq.items():
		if first == True:
			k1 = key
			v1 = val
			first = False
		else:
			k2 = key
			v2 = val
		if k1 > k2:
			diff = k1 - k2
			k = k1
		else:
			diff = k2 - k1
			k = k2
	if k1 == 1 and v1 == 1 or (k2 == 1 and v2 == 1):
		print('YES')
	elif diff == 1 and freq[k] == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def answer(success):
	if success:
		print('YES')
	else:
		print('NO')
s = input()
d = {}

def add(c):
	if c in d:
		d[c] += 1
	else:
		d[c] = 1
for c in s:
	add(c)
vals = list(d.values())
maxValid = min(vals)
numRemove = 0
if maxValid == 1:
	numOnes = vals.count(1)
	if numOnes < len(vals) - 1:
		vals.remove(1)
		numRemove = numOnes
		maxValid = min(vals)
for k in d:
	if d[k] > maxValid:
		numRemove += d[k] - maxValid
answer(numRemove <= 1)


import math
from collections import Counter
a = input()
k = Counter(list(a)).most_common()
u = list((int(x[1]) for x in k))
u = sorted(u)
m_num = Counter(u).most_common()
num = sorted(list((int(y[1]) for y in m_num)), reverse=True)
if len(num) == 1:
	print('YES')
elif len(num) > 2:
	print('NO')
elif num[1]:
	if num[1] == 1:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


s = input()
dc = {}
for l in s:
	if l not in dc:
		dc[l] = 1
	else:
		dc[l] = dc[l] + 1
ar = [val for val in dc.values()]
ar.sort()
if len(ar) == 1 or (sum(ar) - 1) % (len(ar) - 1) == 0 or sum(ar) % len(ar) == 0 or ((sum(ar) - 1) % len(ar) == 0):
	print('YES')
else:
	print('NO')


from collections import Counter

def isValid(S):
	c = Counter(S)
	_values = Counter(c.values())
	_l = len(_values)
	if _l == 1:
		return True
	if _l == 2:
		if len([v for v in _values.values() if v == 1]) == 0:
			return False
		if _values[1] == 1:
			return True
		(_max, _min) = (max(_values.keys()), min(_values.keys()))
		if _values[_max] > 1 or _max - 1 != _min:
			return False
		return True
	return False
S = input().strip()
print('YES' if isValid(S) else 'NO')


from collections import Counter
s = input()
array = [0 for x in range(26)]
for x in s:
	array[ord(x) - 97] += 1
diff = [x for x in array if x > 0]
diff = Counter(diff)
if len(diff.keys()) > 2:
	print('NO')
elif len(diff.keys()) == 1:
	print('YES')
elif diff[list(diff.keys())[0]] == 1 or diff[list(diff.keys())[1]] == 1:
	print('YES')
else:
	print('NO')


from collections import defaultdict
line = input()
memory = defaultdict(int)
for c in line:
	memory[c] += 1
count_map = defaultdict(int)
for (k, v) in memory.items():
	count_map[v] += 1
eligible = []
notElligibleSize = -1
possible = True
for (k, v) in count_map.items():
	if v == 1:
		eligible.append(k)
	elif notElligibleSize == -1:
		notElligibleSize = k
	elif notElligibleSize != k:
		possible = False
if len(eligible) > 2:
	possible = False
elif len(eligible) == 1:
	if eligible[0] != 1 and abs(eligible[0] - notElligibleSize) > 1:
		possible = False
elif len(eligible) == 2:
	if notElligibleSize != -1 and eligible[0] != notElligibleSize and (eligible[1] != notElligibleSize):
		possible = False
if possible:
	print('YES')
else:
	print('NO')


from collections import Counter
d = list(Counter(Counter(input()).values()).values())
print('YES' if len(d) == 1 or (len(d) == 2 and 1 in d) else 'NO')


def check_clc(clc):
	lv = max(clc)
	sv = min(clc)
	lvc = clc.count(lv)
	svc = clc.count(sv)
	if lv == sv:
		return True
	if lv - sv > 1:
		return sv == 1 and svc == 1
	return lvc == 1 or (sv == 1 and svc == 1)
s = input().strip()
lc = [0 for _ in range(26)]
for c in s:
	lc[ord(c) - ord('a')] += 1
clc = [x for x in lc if x > 0]
if check_clc(clc):
	print('YES')
else:
	print('NO')


from collections import Counter
import sys
w = sys.stdin.readline().strip('\n')
if not w:
	print('YES')
else:
	c = Counter()
	c.update(w)
	max_val = max(c.values())
	min_val = min(c.values())
	if len(set(c.values())) == 1:
		print('YES')
	else:
		c2 = Counter()
		c2.update(c.values())
		if len(c2) != 2:
			print('NO')
		elif 1 in c2 and c2[1] == 1:
			print('YES')
		elif c2[max(c.values())] == 1 and max(c.values()) - min(c.values()) == 1:
			print('YES')
		else:
			print('NO')


def getFreqs(s):
	f = {}
	for c in s:
		if c not in f:
			f[c] = 0
		f[c] += 1
	return f
case = input()
frequencies = getFreqs(case)
minimum = 2 ** 31
maximum = 0
for f in frequencies.values():
	if f < minimum:
		minimum = f
	if f > maximum:
		maximum = f
numMin = 0
for f in frequencies.values():
	if f == minimum:
		numMin += 1
deleteToMin = 0
for f in frequencies.values():
	deleteToMin += f - minimum
deletions = min(deleteToMin, minimum * numMin)
if deletions >= 0 and deletions < 2:
	print('YES')
else:
	print('NO')


from collections import Counter

def test_validness(s):
	counts = tuple(sorted(Counter(s).values()))
	return len(counts) < 2 or counts[0] == counts[-1] or (counts[0] == 1 and counts[1] == counts[-1]) or (counts[0] == counts[-2] and counts[0] + 1 == counts[-1])
s = input().strip()
result = test_validness(s)
print('YES' if result else 'NO')


from collections import Counter
summary = Counter(input())
summary = Counter(summary.values())
if len(summary) > 2:
	print('NO')
elif len(summary) == 1:
	print('YES')
else:
	(less, more) = sorted(summary)
	if less + 1 == more and summary[more] == 1:
		print('YES')
	elif summary[1] == 1:
		print('YES')
	else:
		print('NO')


s = input()
check = set(s)
ltrDict = []
for ltr in check:
	ltrDict.append(s.count(ltr))
l = list(set(ltrDict))
if len(l) == 1:
	print('YES')
elif len(l) == 2:
	a = ltrDict.count(l[0])
	b = ltrDict.count(l[1])
	if a == 1 and (0 <= l[0] - l[1] <= 1 or l[0] == 1) or (b == 1 and (0 >= l[0] - l[1] >= -1 or l[1] == 1)):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
D = {}
for c in s:
	if c not in D:
		D[c] = 0
	D[c] += 1
p = []
for i in D:
	p.append(D[i])
if len(p) == 2 and (p[0] == 1 or p[1] == 1):
	print('YES')
elif len(set(p)) > 2:
	print('NO')
elif len(set(p)) == 1:
	print('YES')
else:
	temp = list(set(p))
	s1 = 0
	s2 = 0
	for i in p:
		if i == temp[0]:
			s1 += 1
		if i == temp[1]:
			s2 += 1
	if s1 == 1 or s2 == 1:
		print('YES')
	else:
		print('NO')


def isValid(b):
	l = len(b)
	diff = 0
	cur = max(set(b), key=b.count)
	for i in range(l):
		if cur != b[i]:
			temp_diff = abs(cur - b[i])
			if b[i] == 1:
				diff += 1
			else:
				diff += temp_diff
			if diff > 1:
				return False
	return True
s = input()
b = [0] * 26
for i in range(len(s)):
	bucket = ord(s[i]) - 97
	b[bucket] += 1
b = [v for v in b if v != 0]
if isValid(b):
	print('YES')
else:
	print('NO')


s = input()
values = []
uniqueCharacters = set(s)
for x in uniqueCharacters:
	values.append(s.count(x))
if len(set(values)) > 2:
	print('NO')
elif max(values) - min(values) > 1 and min(values) != 1:
	print('NO')
elif values.count(max(values)) > 1 and values.count(min(values)) > 1 and (max(values) != min(values)):
	print('NO')
else:
	print('YES')


string = input()
dict = {}
letterCount = {}
validateCount = 0
for i in range(len(string)):
	if string[i] in dict:
		dict[string[i]] += 1
	else:
		dict[string[i]] = 1
for item in dict:
	if dict[item] in letterCount:
		letterCount[dict[item]] += 1
	else:
		letterCount[dict[item]] = 1
if len(letterCount) > 2:
	print('NO')
elif len(letterCount) == 2:
	for i in letterCount:
		if letterCount[i] > 1:
			validateCount += 1
	if validateCount == 2:
		print('NO')
	else:
		print('YES')
else:
	print('YES')


import collections

def histogram(text):
	d = collections.defaultdict(int)
	for c in text:
		d[c] += 1
	return d

def count_frequency(text):
	d = histogram(text)
	f = collections.defaultdict(int)
	for count in d.values():
		f[count] += 1
	return f

def is_valid(text):
	f = count_frequency(text)
	if len(f) == 1:
		return True
	elif len(f) == 2:
		if 1 in set(f.values()):
			return True
	return False
text = input().strip()
print('YES' if is_valid(text) else 'NO')


def getFrequencies(s):
	d = {}
	for c in s:
		if c not in d:
			d[c] = 0
		d[c] += 1
	return list(d.values())

def allSame(li):
	assert li
	e0 = li[0]
	return all(map(lambda e: e == e0, li))

def canValidify(s):
	f = sorted(getFrequencies(s), reverse=True)
	if allSame(f):
		return True
	if f[0] - f[1] == 1 and allSame(f[1:]):
		return True
	if f[-1] == 1 and allSame(f[:-1]):
		return True
	return False
s = input().strip()
print('YES' if canValidify(s) else 'NO')


test_string = input()
short_string = ''.join(set(test_string))
counts = {}
max_size = 0
other_size = 0
for char in short_string:
	n = test_string.count(char)
	if n not in counts:
		counts[n] = [char]
	else:
		counts[n].append(char)
for (key, value) in counts.items():
	if len(value) > max_size:
		other_size = max_size
		max_size = key
	else:
		other_size = key
if len(counts) == 2 and len(counts[other_size]) == 1 or len(counts) == 1:
	print('YES')
else:
	print('NO')


s = input()
counts = {c: 0 for c in 'abcdefghijklmnopqrstuvwxyz'}
for c in s:
	counts[c] += 1
all_values = list(counts.values())
distinct_values = list(set(all_values))
if 0 in distinct_values:
	distinct_values.remove(0)
if len(distinct_values) == 1 or (len(distinct_values) == 2 and (all_values.count(distinct_values[0]) == 1 or all_values.count(distinct_values[1]) == 1)):
	print('YES')
else:
	print('NO')


from collections import Counter
S = input()
dicti = Counter(Counter(S).values())
if len(dicti) > 2:
	print('NO')
elif len(dicti) == 2 and 1:
	if 1 not in dicti.values():
		print('NO')
	elif abs(list(dicti.keys())[0] - list(dicti.keys())[1]) != 1 and 1 not in dicti.keys():
		print('NO')
	else:
		print('YES')
else:
	print('YES')


def is_almost_valid(string):
	counts = [0 for i in range(ord('z') - ord('a') + 1)]
	for c in string:
		counts[ord(c) - ord('a')] += 1
	counts.sort()
	counts = [ct for ct in counts if ct != 0]
	if len(counts) == 1:
		return True
	shape = []
	ones = 0
	for i in range(len(counts)):
		d = abs(counts[i] - counts[len(counts) - i - 1])
		if d != 0:
			shape.append(d)
		if counts[i] == 1:
			ones += 1
	if len(shape) == 0:
		return True
	elif len(shape) != 2:
		return False
	elif ones == 1 and counts[0] == 1 or shape[0] == 1:
		return True
	return False
string = input().strip()
print('YES' if is_almost_valid(string) else 'NO')


import sys
S = input()
A = [0] * 26
for x in S:
	A[ord(x) - 97] += 1
small = 100000
p = 0
gr = 0
one = 0
for y in range(0, 26):
	if A[y] == 1:
		one += 1
	if A[y] > 1:
		gr += 1
	if one > 1 and gr > 1:
		print('NO')
		sys.exit()
	if A[y] < small and A[y] != 0:
		small = A[y]
if one == 1:
	print('YES')
	sys.exit()
for u in range(0, 26):
	if A[u] != 0:
		p += abs(small - A[u])
		if p > 1:
			print('NO')
			break
if p == 0 or p == 1:
	print('YES')


import math
cadena = input()
frecuencias = {}
enfrecuencias = {}
for c in cadena:
	if not frecuencias.get(c):
		frecuencias[c] = 1
	else:
		frecuencias[c] += 1
for c in frecuencias.keys():
	num = frecuencias[c]
	if not enfrecuencias.get(num):
		enfrecuencias[num] = set()
	enfrecuencias[num].add(c)
enFrecKeys = list(enfrecuencias.keys())
if len(enFrecKeys) == 1:
	print('YES')
	exit(0)
if len(enFrecKeys) > 2:
	print('NO')
	exit(0)
cantunos = 0 if not enfrecuencias.get(1) else len(enfrecuencias.get(1))
hayununo = cantunos == 1
difesuno = math.fabs(enFrecKeys[0] - enFrecKeys[1]) == 1
if hayununo and difesuno:
	print('YES')
	exit(0)
if not hayununo and difesuno:
	if cantunos > 1:
		print('NO')
		exit(0)
	print('YES')
	exit(0)
if not hayununo and (not difesuno):
	print('NO')
	exit(0)
if hayununo and (not difesuno):
	print('YES')
	exit(0)


import math
cadena = input()
frecuencias = {}
enfrecuencias = {}
for c in cadena:
	if not frecuencias.get(c):
		frecuencias[c] = 1
	else:
		frecuencias[c] += 1
for c in frecuencias.keys():
	num = frecuencias[c]
	if not enfrecuencias.get(num):
		enfrecuencias[num] = set()
	enfrecuencias[num].add(c)
enFrecKeys = list(enfrecuencias.keys())
if len(enFrecKeys) == 1:
	print('YES')
	exit(0)
if len(enFrecKeys) > 2:
	print('NO')
	exit(0)
cantunos = 0 if not enfrecuencias.get(1) else len(enfrecuencias.get(1))
hayununo = cantunos == 1
difesuno = math.fabs(enFrecKeys[0] - enFrecKeys[1]) == 1
if hayununo and difesuno:
	print('YES')
	exit(0)
if not hayununo and difesuno:
	if cantunos > 1:
		print('NO')
		exit(0)
	print('YES')
	exit(0)
if not hayununo and (not difesuno):
	print('NO')
	exit(0)
if hayununo and (not difesuno):
	print('YES')
	exit(0)


from collections import Counter
s = str(input()).strip()
counter = Counter(s)
occurances = counter.values()
unique_occurs = Counter(occurances)
valid = False
if len(unique_occurs) == 1:
	valid = True
elif len(unique_occurs) == 2 and 1 in unique_occurs.values():
	keys = list(unique_occurs.keys())
	(major, minor) = (keys[0], keys[1]) if unique_occurs[keys[1]] == 1 else (keys[1], keys[0])
	if minor == 1 or minor == major + 1:
		valid = True
if valid:
	print('YES')
else:
	print('NO')


from collections import Counter

def check(s):
	val = list(Counter(s).values())
	if len(set(val)) == 1:
		return 'YES'
	if len(set(val)) > 2:
		return 'NO'
	if min(val) == 1 and val.count(min(val)) == 1:
		return 'YES'
	if val.count(max(val)) > 1:
		return 'NO'
	if max(val) - min(val) > 1:
		return 'NO'
	return 'YES'
print(check(input()))


from collections import Counter
c = Counter(input().strip())
tc = 0
delCount = 0
doable = True
lst = Counter(list((c[i] for i in c)))
tmax = lst.most_common(1)[0][0]
for i in lst:
	if i != tmax:
		delCount += lst[i]
if delCount > 1:
	print('NO')
else:
	print('YES')


def check(string):
	d = {}
	d2 = {}
	for char in string:
		if char in d:
			d[char] = d[char] + 1
		else:
			d[char] = 1
	for key in d:
		if d[key] in d2:
			d2[d[key]] = d2[d[key]] + 1
		else:
			d2[d[key]] = 1
	if len(d2) == 1:
		return True
	for key in d2:
		if d2[key] == 1:
			d2.pop(key)
			break
	if len(d2) == 1:
		return True
	else:
		return False
string = input()
print('YES') if check(string) else print('NO')


s = list(input())
d = dict()
for i in s:
	d[i] = d.get(i, 0) + 1
for i in d.keys():
	d[i] -= 1
	if min(d.values()) == max(d.values()):
		print('YES')
		break
	d[i] += 1
else:
	if min(d.values()) == 1:
		x = list(d.values())
		x.remove(1)
		if min(x) == max(x):
			print('YES')
		else:
			print('NO')
	elif min(d.values()) == max(d.values()):
		print('YES')
	else:
		print('NO')


from collections import Counter
from collections import defaultdict

def is_nearly_valid(s):
	c = Counter(s)
	count2ch = defaultdict(list)
	for ch in c:
		count = c[ch]
		count2ch[count].append(ch)
	if len(count2ch) == 1:
		return True
	if len(count2ch) == 2:
		if 1 in count2ch and len(count2ch[1]) == 1:
			return True
		mn = min(count2ch.keys())
		mx = max(count2ch.keys())
		if mx == mn + 1 and len(count2ch[mx]) == 1:
			return True
	return False
s = input().strip()
print('YES' if is_nearly_valid(s) else 'NO')


from collections import Counter
from collections import defaultdict

def can_be_valid(s):
	char_count = Counter(s)
	unique_counts = set(char_count.values())
	if len(unique_counts) == 1:
		return True
	elif len(unique_counts) > 2:
		return False
	inverted_count = defaultdict(list)
	for (char, count) in char_count.items():
		inverted_count[count].append(char)
	(max_count, min_count) = (max(unique_counts), min(unique_counts))
	if len(inverted_count[max_count]) > 1 and len(inverted_count[min_count]) == 1:
		return True
	elif len(inverted_count[max_count]) == 1 and len(inverted_count[min_count]) > 1:
		return True
	elif len(inverted_count[max_count]) == 1 and len(inverted_count[min_count]) == 1:
		return True
	return False
s = input()
print('YES' if can_be_valid(s) else 'NO')


from collections import Counter
c = Counter(input().strip())
valcounter = Counter(c.values())
if len(valcounter.keys()) == 1:
	print('YES')
elif len(valcounter.keys()) == 2:
	if 1 in valcounter.values():
		print('YES')
	else:
		print('NO')
else:
	print('NO')


word = str(input())
letter_counts = {}
frequency_counts = {}
for char in word:
	if char in letter_counts.keys():
		letter_counts[char] += 1
	else:
		letter_counts[char] = 1
used_up_char_delete = False
possible_solution = True
chars = list(letter_counts.keys())
for char in chars:
	if letter_counts[char] in frequency_counts.keys():
		frequency_counts[letter_counts[char]] += 1
	else:
		frequency_counts[letter_counts[char]] = 1
freq_counts = list(frequency_counts.keys())
if len(freq_counts) > 2:
	print('NO')
elif len(freq_counts) == 1:
	print('YES')
else:
	freq_counts.sort()
	freq_one = freq_counts[0]
	freq_two = freq_counts[1]
	freq_count_one = frequency_counts[freq_one]
	freq_count_two = frequency_counts[freq_two]
	if freq_one == 1 and freq_count_one == 1:
		print('YES')
	elif abs(freq_one - freq_two) == 1 and min(freq_count_one, freq_count_two) == 1:
		print('YES')
	else:
		print('NO')


def count(s):
	d = {}
	for c in s:
		if c in d:
			d[c] += 1
		else:
			d[c] = 1
	return d
d = count(input())
dt = count(d.values())
kl = len(dt.keys())
if kl == 1 or (kl == 2 and 1 in dt.values()):
	print('YES')
else:
	print('NO')


user_str = input()
char_map = {}
for ch in user_str:
	if ch in char_map:
		char_map[ch] += 1
		rand_chr = ch
	else:
		char_map[ch] = 1
freq_map = {}
for key in char_map:
	if str(char_map[key]) in freq_map:
		freq_map[str(char_map[key])] += 1
	else:
		freq_map[str(char_map[key])] = 1
frequencies = list(freq_map.keys())
if len(frequencies) > 2:
	print('NO')
elif len(frequencies) == 1:
	print('YES')
elif frequencies[0] == '1' and freq_map[frequencies[0]] == 1 or (frequencies[1] == '1' and freq_map[frequencies[1]] == 1):
	print('YES')
elif abs(int(frequencies[0]) - int(frequencies[1])) == 1 and (freq_map[frequencies[0]] == 1 or freq_map[frequencies[1]] == 1):
	print('YES')
else:
	print('NO')


import collections
s = input()
a = [0] * 28
for c in s:
	a[ord(c) - ord('a')] += 1
cnt = collections.Counter([i for i in a if i > 0])
top = cnt.most_common(2)
res = len(cnt) == 1
if len(cnt) == 2:
	if top[1][0] == 1 and top[1][1] == 1:
		res = True
	elif top[1][1] == 1 and top[1][0] - top[0][0] == 1:
		res = True
print('YES' if res else 'NO')


import sys
from collections import Counter

def can_be_made_valid(s):
	counts = list(Counter(s).values())
	biggest = max(counts)
	smallest = min(counts)
	if biggest - smallest == 1:
		if counts.count(biggest) == 1 or counts.count(smallest) == 1:
			return True
	try:
		counts.remove(1)
		biggest = max(counts)
		smallest = min(counts)
	except ValueError:
		pass
	if biggest == smallest:
		return True
	return False

def main():
	s = sys.stdin.readline().strip()
	if can_be_made_valid(s):
		print('YES')
	else:
		print('NO')
main()


from collections import Counter

def isvalid(d):
	if len(d) <= 1:
		return 'YES'
	if len(d) > 2:
		return 'NO'
	(n1, n2) = sorted(d.keys())
	if n2 - n1 == 1 and d[n2] == 1:
		return 'YES'
	if n1 == 1 and d[n1] == 1:
		return 'YES'
	return 'NO'
c1 = Counter(input())
c2 = Counter(c1.values())
print(isvalid(c2))


from collections import defaultdict

def balanced(s):
	cnts = defaultdict(int)
	for c in s:
		cnts[c] += 1
	freq_cnts = defaultdict(int)
	for (_, freq) in cnts.items():
		freq_cnts[freq] += 1
	if len(freq_cnts) == 2:
		((f1, c1), (f2, c2)) = freq_cnts.items()
		if f1 == f2 + 1 and c1 == 1:
			return True
		elif f2 == f1 + 1 and c2 == 1:
			return True
		elif f1 == 1 and c1 == 1:
			return True
		elif f2 == 1 and c2 == 1:
			return True
		else:
			return False
	elif len(freq_cnts) <= 1:
		return True
	else:
		return False
s = input()
if balanced(s):
	print('YES')
else:
	print('NO')


from collections import Counter
c = Counter(input())
v = list(c.values())
m = min(v)
c = Counter(v)
if c[1] == 1 and len(c.values()) == 2:
	print('YES')
else:
	removals = sum([x - m for x in v])
	print('YES' if removals <= 1 else 'NO')


s = input()
s1 = set(s)
i = 0
answer = 'YES'
data = [s.count(temp) for temp in s1]
if len(set(data)) >= 3:
	answer = 'NO'
elif len(set(data)) == 2 and (data.count(data[0]) == 1 or data.count(data[0]) == len(data) - 1):
	answer = 'YES'
elif len(set(data)) == 1:
	answer = 'YES'
else:
	answer = 'NO'
print(answer)


def countOccurence(a, value):
	count = 0
	for val in a:
		if val == value:
			count += 1
	return count

def mostCommonValueButNotZero(a):
	ret = -1
	count = 0
	for val in a:
		if val > 0 and val != ret:
			countCurrent = countOccurence(a, val)
			if countCurrent > count:
				ret = val
				count = countCurrent
	return ret
alp = 'abcdefghijklmnopqrstuvwxyz'
s = ''
a = []
answer = 'YES'
value = -1
oneCanDiffer = True
s = input().strip()
a = [0 for i in range(len(alp))]
for i in range(len(s)):
	index = alp.find(s[i])
	if index != -1:
		a[index] += 1
value = mostCommonValueButNotZero(a)
for val in a:
	if val != 0 and val != value:
		if oneCanDiffer is True:
			oneCanDiffer = False
		else:
			answer = 'NO'
			break
print(answer)


from collections import Counter
s = input()
c = Counter(s)
c2 = Counter(c.values())
vv = [v for (k, v) in c2.most_common()]
istrue = False
if len(c2) == 1:
	istrue = True
elif len(c2) == 2 and min(vv) == 1:
	istrue = True
if istrue:
	print('YES')
else:
	print('NO')


from collections import Counter
s = input().strip()
scl = list(Counter(s).values())
l = [x for x in scl if x != scl[0]]
if len(l) > 1 and len(l) != 0:
	print('NO')
else:
	print('YES')


from collections import Counter
s = input()
c = Counter(Counter(s).values())
if len(c) == 0 or len(c) == 1 or (len(c) == 2 and 1 in c.values()):
	print('YES')
else:
	print('NO')


from collections import Counter
inputString = input()

def canMakeValidString(string: str):
	dic = Counter(string)
	a = 0
	listOfValues = list(dic.values())
	firstValue = listOfValues[0]
	for i in range(0, len(listOfValues)):
		for j in range(1, len(listOfValues)):
			if listOfValues[i] == listOfValues[j]:
				firstValue = listOfValues[i]
				break
		break
	for i in range(1, len(listOfValues)):
		if listOfValues[i] != firstValue:
			a = a + 1
	if a > 1:
		print('NO')
	else:
		print('YES')
canMakeValidString(inputString)


from collections import defaultdict
s = input()
d = defaultdict(int)
for c in s:
	d[c] += 1
se = defaultdict(int)
for c in d:
	se[d[c]] += 1
if len(se) > 2:
	print('NO')
elif len(se) == 2:
	((a, b), (c, d)) = se.items()
	if b != 1 and d != 1:
		print('NO')
	else:
		print('YES')
else:
	print('YES')


from collections import defaultdict
s = input()
frequency = [0 for i_ in range(0, 26)]
for char in s:
	ascii = ord(char) - ord('a')
	frequency[ascii] += 1
fdic = defaultdict(int)
fdic[0] = 0
for freq in frequency:
	fdic[freq] += 1
del fdic[0]
ans = True
for (key, value) in fdic.items():
	if value == 1:
		ans = False
		break
if ans:
	result = 'NO'
else:
	result = 'YES'
length = len(fdic)
if length > 2:
	result = 'NO'
elif length == 1:
	result = 'YES'
print(result)


def unique(text):
	unique_text = []
	for letter in text:
		if letter not in unique_text:
			unique_text.append(letter)
	return unique_text

def decison(text):
	unique_text = unique(text)
	unique_count = []
	for letter in unique_text:
		unique_count.append(text.count(letter))
	valid = False
	u_u_count = unique(unique_count)
	condition1 = len(u_u_count) == 2
	if condition1:
		condition2 = unique_count.count(u_u_count[0]) == 1
		condition3 = unique_count.count(u_u_count[1]) == 1
		if condition2 or condition3:
			condition4 = abs(u_u_count[0] - u_u_count[1]) == 1
			condition5 = u_u_count[0] == 1 or u_u_count[1] == 1
			if condition4 or condition5:
				valid = True
	elif len(u_u_count) == 1:
		valid = True
	return valid

def main():
	text = input()
	if decison(text):
		print('YES')
	else:
		print('NO')
main()


import string
s = input()
if len(s) <= 3:
	print('YES')
else:
	dic = {}
	for i in string.ascii_lowercase:
		count = s.count(i)
		if count != 0:
			dic[i] = count
	if len(dic) == 1:
		print('YES')
	else:
		diff = []
		for i in dic.values():
			diff.append(i)
		diff.sort()
		flag = 0
		for i in range(len(diff) - 1):
			for j in range(i + 1, len(diff)):
				if abs(diff[i] - diff[j]) != 0:
					flag += 1
		if flag > len(diff) - 1:
			print('NO')
		else:
			print('YES')


a = {}
b = set()
x = input()
for i in range(ord('a'), ord('z') + 1):
	a[chr(i)] = x.count(chr(i))
	b.add(x.count(chr(i)))
if 0 in b:
	b.remove(0)
if len(b) == 1:
	print('YES')
elif len(b) > 2:
	print('NO')
else:
	t = sorted(b)
	n = sum((1 for i in a if a[i] == t[1]))
	m = sum((1 for i in a if a[i] == t[0]))
	if n == 1 or m == 1:
		print('YES')
	elif n == 1 and t[1] - t[0] == 1:
		print('YES')
	else:
		print('NO')


counter = {}
for c in input():
	counter[c] = counter.get(c, 0) + 1
s = sorted(counter.values())
if len(set(s)) == 1 or (s[0] == 1 and len(set(s[1:])) == 1) or (s[-1] == s[-2] + 1 and len(set(s[:-1])) == 1):
	print('YES')
else:
	print('NO')


s = input().strip()
letters = list(set(list(s)))
freq1 = s.count(letters[0])
freq2 = 0
count1 = 0
count2 = 0
flag = True
for l in letters:
	if s.count(l) == freq1:
		count1 += 1
	elif freq2 == 0:
		freq2 = s.count(l)
		count2 = 1
	elif s.count(l) == freq2:
		count2 += 1
	else:
		flag = False
		break
	if count1 > 1 and count2 > 1:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


from collections import defaultdict

def within_one_of_valid(string):
	counters = defaultdict(int)
	for _char in string:
		counters[_char] += 1
	letter_counts = counters.values()
	letter_frequencies = defaultdict(int)
	for _count in counters.values():
		letter_frequencies[_count] += 1
	if len(letter_frequencies) == 1:
		return 'YES'
	elif len(letter_frequencies) > 2:
		return 'NO'
	if min(letter_frequencies.values()) > 1:
		return 'NO'
	return 'YES'
the_string = input()
print(within_one_of_valid(the_string))


def is_valid(freq):
	last = None
	for i in freq:
		if i > 0:
			if not last:
				last = i
				continue
			if i != last:
				return False
	return True

def valid(f):
	if len(f) == 1:
		return True
	fr = f.copy()
	if is_valid(fr):
		return True
	fr[0] = fr[0] - 1
	if is_valid(fr):
		return True
	fr[0] = fr[0] + 1
	fr[-1] = fr[-1] - 1
	if is_valid(fr):
		return True
	return False
freq = 26 * [0]
s = input()
for i in s:
	n = ord(i) - ord('a')
	freq[n] = freq[n] + 1
freq = sorted([i for i in freq if i > 0])
if valid(freq):
	print('YES')
else:
	print('NO')


import sys
s = input()
l = []
for i in range(26):
	l.append(0)
for c in s:
	l[ord(c) - 97] += 1
v = []
for i in l:
	if i > 0:
		v.append(i)
c = 0
for i in range(len(v) - 1):
	if v[i] != v[i + 1] and c == 0:
		c = 1
if c == 0:
	print('YES')
	sys.exit(0)
for i in range(len(v)):
	v[i] -= 1
	t = v[i]
	if v[i] == 0:
		v.pop(i)
	flag = 0
	for k in range(len(v) - 1):
		if v[k] != v[k + 1] and flag == 0:
			flag = 1
	if flag == 0:
		print('YES')
		sys.exit(0)
	elif t == 0:
		v.append(1)
	else:
		v[i] += 1
print('NO')


(s, j, k, c, co) = (input(), 0, 0, [], 0)
s = sorted(s)
for i in range(len(s)):
	i = j
	res = s[i]
	count = 0
	count = count + 1
	for j in range(i + 1, len(s)):
		if s[j] != res:
			k = k + 1
			c.append(count)
			break
		else:
			count = count + 1
k = k + 1
if len(s) % k == 0 or (len(s) - 1) % (k - 1) == 0 or (len(s) - 1) % k == 0:
	print('YES')
else:
	print('NO')


word = list(input())
uniques = set(word)
occ = []
for x in uniques:
	occ.append(word.count(x))
uocc = set(occ)
if len(uocc) <= 1 and max(occ) - min(occ) <= 1:
	print('YES')
elif occ.count(max(uocc)) == 1 and occ.count(min(uocc)) == len(occ) - 1:
	print('YES')
elif occ.count(min(uocc)) == 1 and occ.count(max(uocc)) == len(occ) - 1:
	print('YES')
else:
	print('NO')


st = input()
table = 26 * [0]
val = 26 * [False]
for i in st:
	table[ord(i) - ord('a')] += 1
	val[ord(i) - ord('a')] = True
m = 9999999999999999999
M = -1
for i in range(26):
	if val[i]:
		if table[i] < m:
			m = table[i]
for i in range(26):
	if val[i]:
		if table[i] > M:
			M = table[i]
flag = 0
flag2 = 0
for i in range(26):
	if table[i] > m and flag == 0:
		if table[i] - m == 1:
			flag = 1
		else:
			flag2 = 1
			break
	elif table[i] > m and flag == 1:
		flag2 = 1
		break
if flag2 == 0:
	print('YES')
elif flag2 == 1 and m == 1:
	fl = 0
	for i in range(26):
		if val[i]:
			if table[i] == 1 and fl == 0:
				fl = 1
			elif table[i] == 1 and fl == 1:
				fl = 2
				break
			elif table[i] == M:
				continue
			else:
				fl = 2
				break
	if fl == 2:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


from collections import Counter
from collections import defaultdict
j = input()
r = Counter((i for i in j))
amounts = defaultdict(int)
test2 = []
for (i, k) in r.items():
	amounts[k] += 1

def valid(a):
	if len(a) == 1:
		return 'YES'
	elif len(a) == 2:
		for (i, j) in a.items():
			test2.append(j)
		if 1 in test2:
			return 'YES'
	return 'NO'
print(valid(amounts))


import fileinput
input_list = []
for line in fileinput.input():
	input_list = list(line.strip())

def validator(s):
	(charCount, charCounter) = ({}, {})
	for x in s:
		if x not in charCount:
			charCount[x] = 1
		else:
			charCount[x] += 1
	for y in charCount:
		if charCount[y] not in charCounter:
			charCounter[charCount[y]] = 1
		else:
			charCounter[charCount[y]] += 1
	res = 'YES'
	if len(charCounter) > 2:
		res = 'NO'
	if len(charCounter) == 2:
		(a, b) = ([], [])
		for z in charCounter:
			a.append(z)
			b.append(charCounter[z])
		if abs(a[0] - a[1]) > 1 and a[0] != 1 and (a[1] != 1):
			res = 'NO'
		if abs(a[0] - a[1]) == 1:
			if b[0] > 1 and b[1] > 1:
				res = 'NO'
	return res
res = validator(input_list)
print(res)


def isValidStr(s):
	s = sorted(s)
	cnt = []
	cnt.append(1)
	prevchar = s[0]
	for si in range(1, len(s)):
		if s[si] == prevchar:
			cnt[-1] = cnt[-1] + 1
		else:
			cnt.append(1)
		prevchar = s[si]
	cntset = set(cnt)
	if len(cntset) == 1:
		return 'YES'
	if len(cntset) > 2:
		return 'NO'
	d = {x: cnt.count(x) for x in cnt}
	el1 = cntset.pop()
	el2 = cntset.pop()
	el11 = min(el1, el2)
	el22 = max(el1, el2)
	ct1 = d[el11]
	ct2 = d[el22]
	if el11 == 1 and ct1 == 1:
		return 'YES'
	elif el22 == el11 + 1 and ct2 == 1:
		return 'YES'
	else:
		return 'NO'
s = str(input().strip())
print(isValidStr(s))


def counting_letter(a):
	fre_dict = {}
	for fre in a:
		fre_dict[fre] = 0
	for fre in a:
		fre_dict[fre] += 1
	return fre_dict
a = input()
rand = 0
count = 0
dict_fre = counting_letter(a)
maxi = dict_fre[max(dict_fre, key=dict_fre.get)]
for a in dict_fre:
	dict_fre[a] = maxi - dict_fre[a]
for a in dict_fre:
	if dict_fre[a] == 0:
		count += 1
	elif dict_fre[a] == 1:
		rand += 1
if rand == 0 and count == len(dict_fre) or (count == 1 and rand == len(dict_fre) - 1) or (rand == 1 and count == len(dict_fre) - 1) or (rand == 0 and count == len(dict_fre) - 1):
	print('YES')
else:
	print('NO')


a = [0] * 26
for i in map(lambda c: ord(c) - 97, input().strip()):
	a[i] += 1
a.sort()
a = [i for i in a if i > 0]
print('YES' if a[0] == a[-1] or (a[0] == a[-2] and a[-1] == a[0] + 1) or (a[0] == 1 and a[1] == a[-1]) else 'NO')


from collections import Counter as mset
s = input().strip()
d = list(dict(mset(s)).values())
n = len(d)
res = True
d.sort()
df = 0
if d[0] == 1:
	if abs(d[0] - d[-1]) > 1:
		df += 1
		d.remove(1)
		n = len(d)
for i in range(n // 2):
	df += abs(d[i] - d[-1 - i])
	if df > 1:
		res = False
		break
if res:
	print('YES')
else:
	print('NO')


s = input().strip()
counter = {}
for c in s:
	counter[c] = counter.get(c, 0) + 1
frequencies = {}
for v in counter.values():
	frequencies[v] = frequencies.get(v, 0) + 1
if len(frequencies) == 1:
	print('YES')
elif len(frequencies) == 2:
	if min(frequencies.values()) == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def main():
	str = {}
	str = input()
	hash = [0 for i in range(26)]
	for i in str:
		hash[ord(i) - 97] += 1
	(flag, c) = (0, 0)
	for i in range(0, 26):
		if hash[i] and flag == 0:
			flag = hash[i]
		elif hash[i] and flag != 0:
			if hash[i] != flag:
				c += 1
	if c > 1:
		print('NO')
	else:
		print('YES')
main()


string = input().strip()
char_dict = {}
for char in string:
	if char in char_dict:
		count = char_dict[char]
		char_dict[char] = count + 1
	else:
		char_dict[char] = 1
keys = list(char_dict.keys())
min_count = char_dict[keys[0]]
max_freq = 0
max_count_freq = 0
single_freq_char = 0
for key in keys:
	if char_dict[key] > max_freq:
		max_count_freq = 1
		max_freq = char_dict[key]
	elif char_dict[key] == max_freq:
		max_count_freq += 1
	if char_dict[key] < min_count:
		min_count = char_dict[key]
	if char_dict[key] == 1:
		single_freq_char += 1
if min_count == max_freq:
	print('YES')
elif single_freq_char == 1 and len(string) - max_count_freq * max_freq - single_freq_char == 0:
	print('YES')
else:
	res = all((max_count_freq * max_freq - char_dict[key] <= 1 for key in char_dict))
	print('YES') if res else print('NO')


from itertools import groupby

def mc(lst):
	return max(set(lst), key=lambda x: lst.count(x))
s = input()
s = sorted(s)
freq = list(map(len, [list(g) for (k, g) in groupby(s)]))
if freq.count(mc(freq)) == len(freq):
	print('YES')
elif freq.count(mc(freq)) == len(freq) - 1 and (freq.count(1) == 1 or freq.count(mc(freq) + 1) == 1):
	print('YES')
else:
	print('NO')


st = [x for x in input()]
se = [x for x in set(st)]
s = {x: st.count(x) for x in se}
vals = [x for x in s.values()]
vals2 = sorted(vals)
vals = [x for x in set(vals)]
fail = False
if len(vals) == 1:
	fail = False
elif len(vals) > 2:
	fail = True
elif vals2.count(vals[1]) > 1 or vals[1] - vals[0] != 1:
	if vals2[0] == 1 and vals2.count(1) == 1:
		fail = False
	else:
		fail = True
if fail:
	print('NO')
else:
	print('YES')


from collections import Counter

def main():
	s = input().strip()
	counts = [x[1] for x in Counter(s).most_common()]
	highest = counts[0]
	counts = counts[1:]
	changes = 0
	for c in counts:
		if c != highest:
			changes += 1
	if changes == len(counts):
		if all([x == counts[0] for x in counts[1:]]):
			changes = 1
	if changes <= 1:
		print('YES')
	else:
		print('NO')
main()


s = input()
st = set(s)
(l, ll) = (list(), list())
max_c = 0
for x in st:
	l.append(s.count(x))
st = set(l)
for x in st:
	tmp = l.count(x)
	ll.append(tmp)
	if max_c < tmp:
		max_c = tmp
		ele = x
while l.count(ele) > 1:
	l.remove(ele)
if len(l) <= 2:
	print('YES')
else:
	print('NO')


def is_sherlock(string):
	frequencies = {}
	for letter in string:
		if letter in frequencies:
			frequencies[letter] = frequencies[letter] + 1
		else:
			frequencies[letter] = 1
	distribution = {}
	for letter in frequencies:
		frequency = frequencies[letter]
		if frequency in distribution:
			distribution[frequency] = distribution[frequency] + 1
		else:
			distribution[frequency] = 1
	if len(distribution) == 1:
		return True
	if len(distribution) > 2:
		return False
	if 1 in distribution.values():
		return True
	else:
		return False
string = input()
if is_sherlock(string):
	print('YES')
else:
	print('NO')


def check_valid():
	s = input().strip()
	ord_a = ord('a')
	letters = [0] * 26
	for l in s:
		letters[ord(l) - ord_a] += 1
	letters = [l for l in letters if l > 0]
	min_l = min(letters)
	max_l = max(letters)
	min_l_cnt = letters.count(min_l)
	max_l_cnt = letters.count(max_l)
	if min_l == max_l or (len(set(letters)) == 2 and (min_l_cnt == 1 or max_l_cnt == 1)):
		print('YES')
	else:
		print('NO')
check_valid()


from collections import Counter
c = Counter(Counter(input()).values())
if len(c) == 1:
	print('YES')
elif len(c) > 2:
	print('NO')
else:
	m = min(c)
	v = c[m]
	if c == Counter({m: v, m + 1: 1}) or v == 1:
		print('YES')
	else:
		print('NO')


from collections import Counter

def main():
	S = input()
	c = Counter(S)
	s = set(c.values())
	if len(s) == 1:
		print('YES')
	elif len(s) > 2:
		print('NO')
	else:
		up = down = ones = 0
		cm = c.most_common(2)[1][1]
		for v in c.values():
			if v == 1 and cm != 1:
				ones += 1
			elif v - 1 == cm:
				down += 1
		if ones == 1 and down == 0 or (ones == 0 and down == 1):
			print('YES')
		else:
			print('NO')
main()


S = input()
s = set(S)
h = {}
let_count_1 = let_count_2 = imp = 0
let_count_1_count = 0
let_count_2_count = 0
for c in s:
	h[c] = S.count(c)
	if h[c] == let_count_1:
		let_count_1_count += 1
	if h[c] == let_count_2:
		let_count_2_count += 1
	if 0 == let_count_1:
		let_count_1 = h[c]
		let_count_1_count = 1
	elif h[c] != let_count_1 and 0 == let_count_2:
		let_count_2 = h[c]
		let_count_2_count = 1
	elif h[c] != let_count_1 and h[c] != let_count_2:
		imp = 1
		break
if let_count_1 > let_count_2:
	[let_count_1, let_count_2] = [let_count_2, let_count_1]
	[let_count_1_count, let_count_2_count] = [let_count_2_count, let_count_1_count]
if 0 == imp:
	if let_count_2 - let_count_1 <= 1 and 1 == let_count_2_count:
		print('YES')
	elif 0 == let_count_1:
		print('YES')
	elif 1 == let_count_1 and 1 == let_count_1_count:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
d = {}
for i in s:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
l = list(d.values())
st = set(l)
if len(st) > 2:
	print('NO')
elif len(st) == 1:
	print('YES')
else:
	st = list(st)
	(a, b) = (l.count(st[0]), l.count(st[1]))
	if a != 1 and b != 1:
		print('NO')
	else:
		di = list(d.items())
		selt = di[0]
		seli = 0
		for i in range(len(di) - 1):
			if di[i][1] != di[i + 1][1]:
				if i + 1 == len(di) - 1:
					seli = i + 1
				elif di[i + 1][1] != di[i + 2][1]:
					seli = i + 1
				else:
					seli = i
				break
		if seli != len(di) - 1:
			if di[seli][1] - di[seli + 1][1] == 1 or di[seli][1] == 1:
				print('YES')
			else:
				print('NO')
		elif di[seli][1] - di[seli - 1][1] == 1 or di[seli][1] == 1:
			print('YES')
		else:
			print('NO')