1. 
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 417 - Word Index
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=358&mosmsg=Submission+received+with+ID+8010055
*
* @author Felix Dietrich
* @version 1.0, 06/01/2010
*
* Method : vorberechnet
* Status : Accepted
* Runtime: 0.432
*/


import java.util.*;
import java.lang.*;

class Main
{
interface Func<T,U>
{
U execute(T arguments);
}

public static <T,U> List<U> map(List<T> source, Func<T,U> f)
{
List<U> result = new ArrayList<U>();
for(T s: source)
result.add(f.execute(s));
return result;
}

public static List<String> createAlphabet(String prefix, char start)
{
List<String> l = new ArrayList<String>();
for(char c=start;c<='z'; c++)
l.add(prefix+c);
return l;
}

public static void main(String... args)
{
Scanner sc = new Scanner(System.in);

List<String> validWords;
List<List<String>> mapresult;
HashSet<String> hs = new HashSet<String>();
int size;
int createdWordsCount;

validWords = createAlphabet("",'a');

createdWordsCount = validWords.size();

for(int len=0; len<4; len++)
{
size = validWords.size();
mapresult = map(validWords.subList(size-createdWordsCount, size), new Func<String,List<String>>()
{
public List<String> execute(String word)
{
return createAlphabet(word, (char)(word.charAt(word.length()-1)+1));
}
});

for(List<String> l: mapresult)
for(String w: l)
{
if(!hs.contains(w))
{
validWords.add(w);
hs.add(w);
}
}

createdWordsCount = validWords.size() - createdWordsCount;
}

String input;
while(sc.hasNext())
{
input = sc.next();
if(validWords.contains(input))
System.out.println(validWords.indexOf(input)+1);
else
System.out.println(0);
}
}
}