2013
11-10

# Code

Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known system is that one where a number is associated to a character sequence. It is considered that the words are made only of small characters of the English alphabet a,b,c, …, z (26 characters). From all these words we consider only those whose letters are in lexigraphical order (each character is smaller than the next character).

The coding system works like this:

• The words are arranged in the increasing order of their length.

• The words with the same length are arranged in lexicographical order (the order from the dictionary).

• We codify these words by their numbering, starting with a, as follows:

a - 1

b - 2

z - 26

ab - 27

az - 51

bc - 52

vwxyz - 83681

Specify for a given word if it can be codified according to this coding system. For the affirmative case specify its code.

The only line contains a word. There are some constraints:

• The word is maximum 10 letters length

• The English alphabet has 26 characters.

The output will contain the code of the given word, or 0 if the word can not be codified.

bf

55

//* @author: [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
String s=in.next();
boolean bb=false;
for(int i=0;i< s.length()-1;i++)
{
if(s.charAt(i)-s.charAt(i+1)>=0)
{
System.out.println(0);
bb=true;
break;
}
}
if(bb) System.exit(0);
int l=s.length();
long ans=0;
for(int i=1;i< l;i++)
ans+=find(26,i);
int k=0;
for(int i=0;i< l;i++)
{
k=0;
if(i!=0) k=s.charAt(i-1)-'a'+1;
int y=s.charAt(i)-'a'+1;
for(int j=y-1;j>k;j--)
{
ans+=find(26-j,l-i-1);
}
}
System.out.println(ans+1);
}

public static long find(int u,long a)
{
if(u< a) return 0;
if(a==0) return 1;
long l=1;
for(int i=u;i>u-a;i--)
l*=i;
for(int i=1;i<=a;i++)
l/=i;
return l;
}
}