Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
from heapq import heappop, heappush
from collections import Counter


class Node:
    
    def __init__(self, weight):
        self.weight = weight
    
    def set_parent(self,parent):
        self.parent = parent
        
    def get_length(self):
        try:
            tmp = 1 + self.parent.get_length()
        except AttributeError:
            tmp = 0
        return tmp
        
    def get_weight(self):
        return self.weight

    def __lt__(self, other):
        return self.weight < other.weight
    

S = input()
d = Counter(S)
tree_dic = {}
h = []
num = 0
for i in d:
    tree_dic[i] = Node(d[i])
    heappush(h,tree_dic[i])
while(len(h) > 1):
    tmp0 = heappop(h)
    tmp1 = heappop(h)
    tree_dic[num] = Node(tmp0.get_weight() + tmp1.get_weight())
    tmp0.set_parent(tree_dic[num])
    tmp1.set_parent(tree_dic[num])
    heappush(h,tree_dic[num])
    num+=1

ans = 0
for i in S:
    ans += tree_dic[i].get_length()
if len(S) == 1:
    print(1)
elif len(d) == 1:
    print(len(S))
else:
    print(ans)


# Example run
# Input:
zW>KkL
# Output:
16
from typing import Dict


class Node():
    left = None
    right = None
    parent = None
    char = ''
    value = 0

    def __init__(self, char: str = '', value: int = 0) -> None:
        self.char = char
        self.value = value


def get_coded_str_len(node: Node, base_str: str) -> int:
    if node.char:
        # Return the length of the coded string.
        return len(base_str) * node.value
    else:
        coded_str_len = 0
        if node.left:
            coded_str_len += get_coded_str_len(node.left, base_str + '0')
        if node.right:
            coded_str_len += get_coded_str_len(node.right, base_str + '1')
        return coded_str_len


if __name__ == "__main__":
    input_str = input()
    char_dict: Dict[str, int] = {}
    for s in input_str:
        if s in char_dict:
            char_dict[s] += 1
        else:
            char_dict[s] = 1

    nodes = [Node(char=k, value=v) for k, v in char_dict.items()]
    # Sort in the ascending order.
    nodes.sort(key=lambda x: x.value)

    if 1 == len(nodes):
        node = Node()
        node.left = nodes.pop(0)  # type: ignore
        nodes.append(node)
    else:
        while 1 != len(nodes):
            node = Node()
            node.left = nodes.pop(0)  # type: ignore
            node.right = nodes.pop(0)  # type: ignore
            node.value = node.left.value + node.right.value  # type: ignore
            nodes.append(node)
            # Sort in the ascending order.
            nodes.sort(key=lambda x: x.value)

    print(f"{get_coded_str_len(nodes[0], '')}")



# Example run
# Input:
6.594582159797376e+85
# Output:
72
# -*- coding: utf-8 -*-
"""
Greedy algorithms - Huffman Coding
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_15_D&lang=jp

"""
import sys
from collections import Counter

class Node:
    def __init__(self, v, f):
        self.val = v
        self.freq = f
        self.left = None
        self.right = None


def solve(s):
    res = [Node(k, v) for k, v in Counter(s).items()]
    while len(res) > 1:
        res.sort(key=lambda x: x.freq)
        z = Node('@', res[0].freq + res[1].freq)
        z.left, z.right = res[0], res[1]
        res = res[2:]
        res.append(z)

    d = dict()
    stack = [(res[0], '')]
    while stack:
        n, st = stack.pop()
        if not n.left and not n.right:
            st = '0' if not st else st
            d[n.val] = st
        if n.left:
            stack.append((n.left, st+'0'))
        if n.right:
            stack.append((n.right, st+'1'))
    return len(''.join([d[ch] for ch in s]))


def main(args):
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



# Example run
# Input:
[oP
# Output:
5
# ハフマン符号
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/15/ALDS1_15_D

from collections import Counter
import heapq


class Node:
    def __init__(self, count, val=None, left=None, right=None):
        self.val = val
        self.count = count
        self.left = left
        self.right = right

    def __lt__(self, other):
        return self.count < other.count


class HuffmanCoding:
    def __init__(self, s: str):
        self.s = s
        self.counts = Counter(s).most_common()
        self.root = self.build_tree()
        self.encode_table = self.gen_encode_table()

    def build_tree(self):
        hq = list()
        for val, cnt in self.counts:
            heapq.heappush(hq, Node(cnt, val))
        while len(hq) > 1:
            x = heapq.heappop(hq)
            y = heapq.heappop(hq)
            cnt = x.count + y.count
            z = Node(cnt, None, y, x)
            heapq.heappush(hq, z)
        if hq:
            return heapq.heappop(hq)
        else:
            return None

    def gen_encode_table(self):
        encode_table = {}

        def traversal(node, key):
            if node.val:
                if key == "":
                    key = "0"
                encode_table[node.val] = key
            else:
                if node.left:
                    traversal(node.left, key + "1")
                if node.right:
                    traversal(node.right, key + "0")
        key = ""
        if self.root:
            traversal(self.root, key)

        return encode_table

    def get_encode_size(self):
        size = 0
        for a in self.s:
            size += len(self.encode_table[a])
        return size

    def gen_encode_bin(self):
        enc = ""
        for a in self.s:
            enc += self.encode_table[a]
        return enc


def main():
    S = input().strip()
    huffman = HuffmanCoding(S)
    print(huffman.get_encode_size())


if __name__ == "__main__":
    main()



# Example run
# Input:
MN[@j"4g#
# Output:
29
from collections import Counter

S=input()
freq=sorted(list(dict(Counter(S)).items()),key=lambda w:w[1])
length={chr(ord('a')+i):0 for i in range(26)}
while len(freq)>1:
    minimum1=freq.pop(0)
    minimum2=freq.pop(0)
    for c in minimum1[0]+minimum2[0]:
        length[c]=length[c]+1
    freq.append((minimum1[0]+minimum2[0],minimum1[1]+minimum2[1]))
    freq=sorted(freq,key=lambda w:w[1])

retval=0
for s in S:
    retval+=max(length[s],1)
print(retval)



# Example run
# Input:
inwbj
# Output:
12
import heapq

S = input()

# 数え上げ
chars = [[0, n] for n in range(256)]
for s in S:
	chars[ord(s)][0] += 1

# ハフマン木生成
# ：ノードの構造：[count, char, left=None, right=None]
# ：[1]のcharは、heapqでユニークキーとして機能するように追加した
counts = []
for char in chars:
	if not char[0]:
		continue
	heapq.heappush(counts, [char[0], char[1], None, None, char])

# ハフマン木編成
while 1 < len(counts):
	a, b = heapq.heappop(counts), heapq.heappop(counts)
	heapq.heappush(counts, [a[0] + b[0], -1, a, b])
root = heapq.heappop(counts)

# コード化(左：0、右：1)
codes = {};
def dfs(node, code):
	# 節の処理
	if node[1] < 0:
		dfs(node[2], code + "0")
		dfs(node[3], code + "1")
		return
	# 葉の処理
	codes[chr(node[1])] = code
dfs(root, "")

# 集計
count = 0
for s in S:
	count += len(codes[s])

# 1種類の場合のみ例外処理…いずれなんとか
if 1 == len(set(S)):
	print(len(S))
else:
	print(count)



# Example run
# Input:
EPy8r+|Er
# Output:
25
from collections import Counter, deque
from heapq import heappush, heappop, heapify
C = Counter(input())
N = len(C)

if N == 1:
    print(sum(C.values()))
    exit(0)

G = [0]*(N*2)

G[:N] = C
que = [(v, i) for i, v in enumerate(C.values())]
heapify(que)

cur = len(C)
while len(que) > 1:
    v0, nd0 = heappop(que)
    v1, nd1 = heappop(que)
    G[cur] = (nd0, nd1)
    heappush(que, (v0+v1, cur))
    cur += 1
root = que[0][1]

ans = 0
que = deque([(0, root)])
while que:
    d, nd = que.popleft()
    if nd < N:
        ans += d * C[G[nd]]
        continue
    u, v = G[nd]

    que.append((d+1, u))
    que.append((d+1, v))
print(ans)


# Example run
# Input:
g>!d1,AY
# Output:
24
from heapq import *
class Node():
    def __init__(self, key, char=None):
        self.key = key
        self.char = char
        self.pare = None

st = input()
_st = list(set(st))

a = []
for i in _st:
    a  += [(st.count(i),i)] 
heapify(a)

node = {}
for i in range(len(a)):
    cnt, char = a[i]
    node[char] = Node(cnt, char)

while len(a) > 1:
    p1, p2 = heappop(a)
    q1, q2 = heappop(a)
    x = Node(p1+q1, p2+q2) 
    node[p2+q2] = x
    if len(a) == 0:
        root = x
        break
    node[p2].pare = x
    node[q2].pare = x
    heappush(a, (p1+q1,p2+q2))

def dfs(node, cnt=1):
    if node.pare == None:
        return cnt
    a = dfs(node.pare, cnt+1)
    return a

Sum = 0
for i in _st:
    no = node[i]
    depth = dfs(no)
    Sum += depth*no.key
    
print(Sum)

    




# Example run
# Input:
XR7qRN-
# Output:
18
from collections import Counter, deque
from heapq import heappush, heappop, heapify
C = Counter(input())
N = len(C)

if N == 1:
    print(sum(C.values()))
    exit(0)
    
G = [0] * (N * 2)

G[:N] = C
que = [(v, i) for i, v in enumerate(C.values())]
heapify(que)

cur = len(C)
while len(que) > 1:
    v0, nd0 = heappop(que)
    v1, nd1 = heappop(que)
    G[cur]  = (nd0, nd1)
    heappush(que, (v0 + v1, cur))
    cur += 1
root = que[0][1]

ans = 0
que = deque([(0, root)])
while que:
    d, nd = que.popleft()
    if nd < N:
        ans += d * C[G[nd]]
        continue
    u, v = G[nd]
    
    que.append((d + 1, u))
    que.append((d + 1, v))
print(ans)


# Example run
# Input:
@(1
# Output:
5
n = int(input())
arr = [0] * 200200
for i in range(n - 1):
    a,b = map(int,input().split())
    arr[a] += 1
    arr[b] += 1
res = n
for i in range(n + 10):
    res ^= arr[i]
print('First' if res % 2 else 'Second')


# Example run
# Input:
-11989124
# Output:
Second
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import collections


class Node(object):

  def __init__(self):
    self.edges = set()
    self.distance = 1


def main():
  N = int(input())
  nodes = [Node() for _ in range(N)]

  if N == 0:
    print('Second', flush=True)
    return
  elif N == 1:
    print('First', flush=True)
    return

  for _ in range(N - 1):
    a, b = map(int, input().split())
    nodes[a - 1].edges.add(nodes[b - 1])
    nodes[b - 1].edges.add(nodes[a - 1])

  leaves = collections.deque(n for n in nodes if len(n.edges) == 1)

  while True:
    leaf = leaves.popleft()
    parent = leaf.edges.pop()

    if len(parent.edges) == 1:
      size = leaf.distance + parent.distance
      break

    parent.distance = max(parent.distance, leaf.distance + 1)
    parent.edges.remove(leaf)

    if len(parent.edges) == 1:
      leaves.append(parent)

  if size % 3 == 2:
    print('Second', flush=True)
  else:
    print('First', flush=True)


if __name__ == '__main__':
  main()



# Example run
# Input:
0
# Output:
Second
def getlist():
	return list(map(int, input().split()))

N = int(input())
for i in range(N):
	a, b = getlist()


if N % 2 == 1:
	print("First")
else:
	print("Second")

# Example run
# Input:
0
# Output:
Second
#!/usr/bin/env python
# -*- coding: utf-8 -*-


class Node(object):

  def __init__(self):
    self.edges = set()
    self.distance = 1


def main():
  N = int(input())
  nodes = [Node() for _ in range(N)]

  if N == 0:
    print('Second', flush=True)
    return
  elif N == 1:
    print('First', flush=True)
    return

  for _ in range(N - 1):
    a, b = map(int, input().split())
    nodes[a - 1].edges.add(nodes[b - 1])
    nodes[b - 1].edges.add(nodes[a - 1])

  leaves = [n for n in nodes if len(n.edges) == 1]

  while True:
    leaf = leaves.pop(0)
    parent = leaf.edges.pop()

    if len(parent.edges) == 1:
      size = leaf.distance + parent.distance
      break

    parent.distance = max(parent.distance, leaf.distance + 1)
    parent.edges.remove(leaf)

    if len(parent.edges) == 1:
      leaves.append(parent)

  if size % 3 == 2:
    print('Second', flush=True)
  else:
    print('First', flush=True)


if __name__ == '__main__':
  main()



# Example run
# Input:
1
# Output:
First
N = int(input())
if (N % 2) == 1:
  print('First')
else:
  print('Second')

# Example run
# Input:
5182
# Output:
Second
import unittest

import random

def main():
    N = int(input())
    tree = [[] for i in range(N)]
    for i in range(N-1):
        a,b = map(int, input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)


    print(solve(N, tree))

def solve(n, tree):
    if first_win(n, tree):
        return 'First'
    else:
        return 'Second'
    
def first_win(n, tree):

    if n == 1:
        return True
    elif n == 2:
        return False
    elif n == 3:
        return True
    elif n == 4:
        return True
    elif n == 5:
        return False
    elif n == 6:
        return False
    elif n == 7:
        return True
    else:
        return random.choice([True, False])




if __name__ == "__main__":
    main()


# Example run
# Input:
-7737
# Output:
First
print(["Second","First"][int(input())%2])

# Example run
# Input:
-59
# Output:
First
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
if N % 2 != 0 :
    print("First")
else :
    print("Second")
    

# Example run
# Input:
-13
# Output:
First
def solve():
  n = int(input())
  a = [0]*n
  for i in range(n-1):
    c,d = (int(i) for i in input().split())
    a[c-1] += 1
    a[d-1] += 1
  od = 0
  ev = 0
  for i in range(n):
     if a[i]%2 == 0:
          ev += 1
     else:
          od += 1
  if (n+od)%2 == 1:
    print("First")
  else:
    print("Second")
solve()


# Example run
# Input:
-17583
# Output:
First
N = int(input())

a = []
b = []

for i in range(N-1):
    A, B = list(map(int, input().split()))
    a.append(A)
    b.append(B)

if N % 2 == 0:
    print('Second')
else:
    print('First')

# Example run
# Input:
-7517
# Output:
First
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import collections


class Node(object):

  def __init__(self):
    self.edges = set()
    self.distance = 1


def main():
  N = int(input())
  nodes = [Node() for _ in range(N)]

  if N == 0:
    print('Second', flush=True)
    return
  elif N == 1:
    print('First', flush=True)
    return

  for _ in range(N - 1):
    a, b = map(int, input().split())
    nodes[a - 1].edges.add(nodes[b - 1])
    nodes[b - 1].edges.add(nodes[a - 1])

  leaves = collections.deque(n for n in nodes if len(n.edges) == 1)

  while True:
    leaf = leaves.pop()
    parent = leaf.edges.pop()

    if len(parent.edges) == 1:
      size = leaf.distance + parent.distance
      break

    parent.distance = max(parent.distance, leaf.distance + 1)
    parent.edges.remove(leaf)

    if len(parent.edges) == 1:
      leaves.append(parent)

  if size % 3 == 2:
    print('Second', flush=True)
  else:
    print('First', flush=True)


if __name__ == '__main__':
  main()



# Example run
# Input:
1
# Output:
First
#!/usr/bin/env python
# -*- coding: utf-8 -*-


class Node(object):

  def __init__(self):
    self.edges = []
    self.distance = 1


def main():
  N = int(input())
  nodes = [Node() for _ in range(N)]

  if N == 0:
    print('Second', flush=True)
    return
  elif N == 1:
    print('First', flush=True)
    return

  for _ in range(N - 1):
    a, b = map(int, input().split())
    nodes[a - 1].edges.append(nodes[b - 1])
    nodes[b - 1].edges.append(nodes[a - 1])

  leaves = [n for n in nodes if len(n.edges) == 1]
  nodes = [n for n in nodes if len(n.edges) != 1]

  if N % 3 == 2:
    print('Second', flush=True)
  else:
    print('First', flush=True)


if __name__ == '__main__':
  main()



# Example run
# Input:
-21519471
# Output:
First
n = int(input())
if n % 2 == 0:
  print("Second")
else:
  print("First")

# Example run
# Input:
-1836
# Output:
Second
N = int(input())
for _ in range(N - 1):
	input()
print('First' if N & 1 else 'Second')

# Example run
# Input:
-1
# Output:
First
N = int(input())
S = list(input())


ans = N % 2


if ans == 0:
    print("Secound")
else:
    print("First")


# Example run
# Input:
4743227
^tx
# Output:
First
n=int(input())
for i in range(n-1):
  a,b=map(int,input().split())
if n%2==1:print('First')
else:print('Second')

# Example run
# Input:
-27
# Output:
First
n=int(input())
l=[0 for i in range(n)]
ct=0
for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1]+=1
  l[b-1]+=1
for i in range(n):
  if l[i]%2==0:ct+=1
if ct%2==1:print('First')
else:print('Second')

# Example run
# Input:
-1147387
# Output:
Second
N = int(input())

a = []
b = []

for i in range(N-1):
    A, B = list(map(int, input().split()))
    a.append(A)
    b.append(B)

flag = False
for i in range(1, N+1):
    if not i in a:
        flag = True
        break
    if not i in b:
        flag = True
        break

if N % 2 == 0 and flag == False:
    print('Second')
elif N % 2 == 1 and flag == False:
    print('First')
elif N % 2 == 0 and flag == True:
    print('First')
else:
    print('Second')

# Example run
# Input:
-48
# Output:
Second
N = int(input())

a = []
b = []

for i in range(N-1):
    A, B = list(map(int, input().split()))
    a.append(A)
    b.append(B)

flag = False
for i in range(1, N+1):
    if i in a:
        flag = True
        break
    if i in b:
        flag = True

if N % 2 == 0 and flag == False:
    print('Second')
elif N % 2 == 1 and flag == False:
    print('First')
elif N % 2 == 0 and flag == True:
    print('First')
else:
    print('Second')

# Example run
# Input:
-13902095
# Output:
First
print("SFeicrosntd"[int(input())%2::2])

# Example run
# Input:
29
# Output:
First
N = int(input())

a = []
b = []

for i in range(N-1):
    A, B = list(map(int, input().split()))
    a.append(A)
    b.append(B)

if N % 2 == 0 and N < 50:
    print('Second')
elif N % 2 == 1 and N < 50:
    print('First')
elif N % 2 == 0 and N >= 50:
    print('First')
else:
    print('Second')

# Example run
# Input:
-579377
# Output:
First
#!/usr/bin/env python
# -*- coding: utf-8 -*-


class Node(object):

  def __init__(self):
    self.edges = []
    self.distance = 1


def main():
  N = int(input())
  nodes = [Node() for _ in range(N)]

  if N == 0:
    print('Second', flush=True)
    return
  elif N == 1:
    print('First', flush=True)
    return

  for _ in range(N - 1):
    a, b = map(int, input().split())
    nodes[a - 1].edges.append(nodes[b - 1])
    nodes[b - 1].edges.append(nodes[a - 1])

  leaves = [n for n in nodes if len(n.edges) == 1]

  while True:
    leaf = leaves.pop(0)
    parent = leaf.edges[0]

    if len(parent.edges) == 1:
      size = leaf.distance + parent.distance
      break

    parent.distance = max(parent.distance, leaf.distance + 1)
    parent.edges.remove(leaf)

    if len(parent.edges) == 1:
      leaves.append(parent)

  if size % 3 == 2:
    print('Second', flush=True)
  else:
    print('First', flush=True)


if __name__ == '__main__':
  main()



# Example run
# Input:
0
# Output:
Second
def getlist():
	return list(map(int, input().split()))

N = int(input())
for i in range(N - 1):
	a, b = getlist()


if N % 2 == 1:
	print("First")
else:
	print("Second")

# Example run
# Input:
-1005173
# Output:
First
n=int(input())
for i in range(n-1):
  input()
if n%2==0:
  print('Second')
else:
  print('First')

# Example run
# Input:
-6
# Output:
Second
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import collections


class Node(object):

  def __init__(self):
    self.edges = set()
    self.distance = 1


def main():
  N = int(input())
  nodes = [Node() for _ in range(N)]

  if N == 0:
    print('Second', flush=True)
    return
  elif N == 1:
    print('First', flush=True)
    return

  for _ in range(N - 1):
    a, b = map(int, input().split())
    nodes[a - 1].edges.add(nodes[b - 1])
    nodes[b - 1].edges.add(nodes[a - 1])

  leaves = collections.deque(n for n in nodes if len(n.edges) == 1)

  while True:
    leaf = leaves.pop()
    parent = leaf.edges.pop()

    if len(parent.edges) == 1:
      size = leaf.distance + parent.distance
      break

    parent.distance = max(parent.distance, leaf.distance + 1)
    parent.edges.remove(leaf)

    if len(parent.edges) == 1:
      leaves.append(parent)

  if size % 3 == 2:
    print('Second', flush=True)
  else:
    print('First', flush=True)


if __name__ == '__main__':
  main()



# Example run
# Input:
0
# Output:
Second
n = int(input())
if n%2 == 0:
  print("Second")
else:
  print("First")

# Example run
# Input:
57223618
# Output:
Second
N = int(input())
A = [list(map(int,input().split())) for i in range(N-1)]
if N % 2 != 0 :
    print("First")
else :
    print("Second")
    

# Example run
# Input:
-3753932
# Output:
Second
s = input()

dic = {}
for char in 'abc':
    dic[char] = s.count(char)

min_val = min(dic.values())
for k in dic:
    if dic[k] - min_val > 1:
        print('NO')
        exit()
print('YES')

# Example run
# Input:
[%CW?37ZP
# Output:
YES
s=input()
a=s.count('a')
b=s.count('b')
c=s.count('c')
if len(set(list(s)))==1 and len(s)>1:
  print('NO')
elif len(set(list(s)))==2 and len(s)>2:
  print('NO')
elif abs(a-b)<=1 and abs(b-c)<=1 and abs(c-a)<=1:
  print('YES')
else:
  print('NO')

# Example run
# Input:
o`u,NtQ5E
# Output:
YES
from collections import Counter
s = input()
l = len(s)

ma = 0
mi = 10 * 10
c = Counter(s)
for i in c.most_common():
    ma = max(ma, i[1])
    mi = min(mi, i[1])
if len(c) == 1 and l == 1:
    print('YES')
    exit(0)
if len(c) == 2 and l == 2:
    print('YES')
    exit(0)
if len(c) == 3 and ma-mi <= 1:
    print('YES')
    exit(0)
print('NO')


# Example run
# Input:
!Wl~Jlh}
# Output:
NO
from collections import Counter

s = input()
len_s = len(s)
counter_s = Counter(s)
maxVal = max(counter_s.values())
if maxVal - (len_s - maxVal) >= 1:
    print('NO')
else:
    print('YES')

# Example run
# Input:
XR7qRN-
# Output:
YES
s=list(input())

a_cnt=s.count("a")
b_cnt=s.count("b")
c_cnt=s.count("c")
cnt=[a_cnt,b_cnt,c_cnt]
cnt.sort()

patarn= len(s)%3

if patarn==0:
    if a_cnt==b_cnt and b_cnt==c_cnt:
        print("YES")
    else:
        print("NO")
elif patarn==1:
    if cnt[0]==len(s)//3 and cnt[1]==len(s)//3 and cnt[2]==len(s)//3+1:
        print("YES")
    else:
        print("NO")
else:
    if cnt[0]==len(s)//3 and cnt[1]==len(s)//3+1 and cnt[2]==len(s)//3+1:
        print("YES")
    else:
        print("NO")

        



# Example run
# Input:
*G\fQJ\
# Output:
NO
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


s=input()
a=s.count('a')
b=s.count('b')
c=s.count('c')
 
print('YES' if max(a,b,c)-min(a,b,c)<=1 else 'NO')

# Example run
# Input:
"At:Js>
# Output:
YES
s = input()
cnt = [s.count("a"), s.count("b"), s.count("c")]
print("YES") if max(cnt) - min(cnt) <= 1 else print("NO")


# Example run
# Input:
+|Er
# Output:
YES
S = input()
print('YES' if max(S.count('a'),S.count('b'),S.count('c'))-min(S.count('a'),S.count('b'),S.count('c')) < 2 else 'NO')


# Example run
# Input:
pjLk(&0
# Output:
YES
from collections import Counter
from collections import defaultdict

S = list(map(str, input().rstrip()))

s = Counter(S)
d = defaultdict(int)

for i in ["a", "b", "c"]:
    d[i] = 0

for l, n in s.items():
    d[l] += n

d = list(d.values())

print("YES" if max(d) - min(d) <= 1 else "NO")

# Example run
# Input:
R\M]
# Output:
YES
s=input()
l=len(s)
cnt1=0
cnt2=0
cnt3=0
for i in range(l):
  if s[i]=='a':
    cnt1+=1
  elif s[i]=='b':
    cnt2+=1
  elif s[i]=='c':
    cnt3+=1
if max(cnt1,cnt2,cnt3)==1:
  print('YES')
elif cnt1==0 or cnt2==0 or cnt3==0:
  print('NO')
elif max(cnt1,cnt2,cnt3)-min(cnt1,cnt2,cnt3)<=1:
  print('YES')
else:
  print('NO')

# Example run
# Input:
3vp2<jugY
# Output:
NO