//https://www.hackerrank.com/challenges/sherlock-and-valid-string
//https://www.hackerrank.com/contests/101hack26/challenges/sherlock-and-valid-string
import java.io.*;
import java.util.Arrays;

public class Solution {
  public static void main(String[] args) throws IOException {
    
    //Get input
    final char[] S = (new BufferedReader(new InputStreamReader(System.in))).readLine().toCharArray();
    
    //Print output
    System.out.print(isValid(S) ? "YES" : "NO");
  }
  
  private static boolean isValid(final char[] S){
    
    //If string contains less than two letters
    if(S.length < 2){
      return true;
    }
    
    //Create histogram of letters
    final int[] L = new int[26];
    for(int i = 0, N = S.length; i < N; ++L[S[i++] - 'a']){}
    
    //Sort the histogram
    Arrays.sort(L);
    
    //Ignore unseen letters
    int i = 0;
    while(i < 26 && L[i] == 0){
      ++i;
    }
    
    //If all letter frequencies are equal
    if(L[i] == L[25]){
      return true;
    }
    
    //If there's one letter above the rest by one
    if(L[25] > L[24]){
      return L[i] == L[24] && L[25] - L[24] == 1;
    }
    
    //If there's one letter below the rest by one or that can be removed
    return L[i] < L[i+1] && L[i+1] == L[25] && (L[i] == 1 || L[i+1] - L[i] == 1);
  }
}

@@ -212,16 +212,18 @@
 ution %7B%0A
+  
   public
@@ -276,25 +276,33 @@
 ption %7B%0A    
-%0A
+    %0A    
     //Get in
@@ -305,24 +305,28 @@
 t input%0A    
+   
+ 
 final char%5B%5D
@@ -411,25 +411,33 @@
 rray();%0A    
-%0A
+    %0A    
     //Print 
@@ -439,24 +439,28 @@
 rint output%0A
+    
     System.o
@@ -500,15 +500,21 @@
 %22);%0A
+  
   %7D%0A  
+ 
-%0A
+ %0A  
   pr
@@ -559,29 +559,37 @@
 r%5B%5D S)%7B%0A    
-%0A
+    %0A   
     
+ 
 //If string 
@@ -615,24 +615,28 @@
 two letters%0A
+    
     if(S.len
@@ -643,32 +643,38 @@
 gth %3C 2)%7B%0A      
+  
+    
 return true;%0A   
@@ -670,31 +670,43 @@
 n true;%0A    
+  
-%7D%0A    %0A
+  %7D%0A        %0A    
     //Create
@@ -727,24 +727,28 @@
 letters%0A    
+   
+ 
 final int%5B%5D 
@@ -764,16 +764,20 @@
 nt%5B26%5D;%0A
+    
     for(
@@ -829,25 +829,33 @@
 'a'%5D)%7B%7D%0A    
-%0A
+    %0A    
     //Sort t
@@ -867,16 +867,20 @@
 stogram%0A
+    
     Arra
@@ -891,25 +891,33 @@
 ort(L);%0A    
+   
-%0A
+ %0A    
     //Ignore
@@ -940,29 +940,38 @@
     
+ 
+   
 int i
- = 0
 ;%0A    
-while(
+    for(i = 0; 
 i %3C 
@@ -989,33 +989,30 @@
 == 0
+; ++i
 )%7B
+%7D
 %0A     
- ++i;%0A
    
- %7D
 %0A    
-%0A
     
@@ -1049,16 +1049,20 @@
 e equal%0A
+    
     if(L
@@ -1072,24 +1072,30 @@
  == L%5B25%5D)%7B%0A
+      
       return
@@ -1101,31 +1101,43 @@
 n true;%0A    
-%7D%0A    %0A
+    %7D%0A        %0A    
     //If the
@@ -1174,24 +1174,28 @@
  by one%0A    
+ 
+   
 if(L%5B25%5D %3E L
@@ -1197,24 +1197,30 @@
 %5D %3E L%5B24%5D)%7B%0A
+      
       return
@@ -1257,16 +1257,20 @@
 %5D == 1;%0A
+    
     %7D%0A  
@@ -1267,25 +1267,33 @@
       %7D%0A    
-%0A
+    %0A    
     //If the
@@ -1353,16 +1353,20 @@
 removed%0A
+    
     retu
@@ -1404,17 +1404,16 @@
 %5B25%5D && 
-(
 L%5Bi%5D == 
@@ -1417,33 +1417,12 @@
 == 1
- %7C%7C L%5Bi+1%5D - L%5Bi%5D == 1)
 ;%0A
+  
   %7D%0A

Update sherlock-and-valid-string.java