1450: String‘s Puzzle

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:2 解决:1

题目描述

Zhu Ming and Small Li find a strange stone tablet, which has some capitals printed on it. Capitals in every string are different with each other, and every capital string is followed by a number. Because of their supernormal intelligence, Zhu Ming and Small Li find the number following the string is numbered in the order of dictionary sequence from little to big (the original number is 0).For example, when the length of capital string is 3, number following the string will be:
ABC     0 
ABD     1 
……   
ZYX     15599
To better study this puzzle, please make a program to given a n-length string (1<=n<=26), output the number of the string.

输入

There are several test cases. Each data is made up of two lines. The first line is number n (1<=n<=26) The second line is a string with its length of n. n=0 means end of the input.

输出

Output the string number for each group of data tested.

样例输入 复制

3
ABC
3
ZYX 
3
ABD
4
ABCD
0

样例输出 复制

0
15599
1
0

提示

练习赛10-A