Petya has n positive integers a1, a2, ..., an. 

His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'.

Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros.

Input

The first line contains a single integer n (1 ≤ n ≤ 1 000) — the number of Petya's numbers.

Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' — the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters.

Output

Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests.

Examples

Input

3
ab
de
aj


Output

47


Input

5
abcdef
ghij
bdef
accbd
g


Output

136542


Input

3
aa
jj
aa


Output

44

Note

In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration.

In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. 

In the second example the numbers after the restoration can look like: [11, 22, 11]. 
import java.util.Scanner;
public class minimumsum
{

  public void shift(int p,int q,int index[])
 {

    int x=index[q];
    for(int i=q;i>p;i--)
    {
      index[i]=index[i-1];
    }
    index[p]=x;

 }

  public void merge(long b[],int i, int k ,int n,int index[])
 {

  if(n-i>1)
  {
    int p=i;
    int q=k+1;
    while(p<q&&q<=n)
     {
      if(b[index[p]]>b[index[q]])
         p++;
      else
        if(b[index[p]]<=b[index[q]])
        {
          shift(p,q,index);
          p++;
          q++;
        }

     }





     }
     else
        if(n==i+1)
        {
          if(b[index[i]]<=b[index[n]])
          {
             int x=index[i];
             index[i]=index[n];
             index[n]=x;

          }
        }

 }
  public void sort(long b[],int i,int n,int index[])
 {
  if(n>i)
    {
      sort(b,i,(i+n)/2,index);
      sort(b,(i+n)/2+1,n,index);
      merge(b,i,(i+n)/2,n,index);
    }
 }

  public void check(char array[][],int index_array[],int T,char first_letter[])
  {

    long[] dummy= new long[10];
    for(int i=0;i<10;i++)
      dummy[i]=0;
    int[]  used_number=new int[10];

    for(int j=0;j<10;j++)
        used_number[j]=0;
    //long sum_maxindex=0;
    for(int i=0;i<T;i++)
    {
      for(int j=14;j>=0;j--)
      {
        if(array[i][j]!='z')
        {
          int x=(int)array[i][j]-97;
          dummy[x]+=java.lang.Math.pow(10,14-j);
        }

      }
    }
  /*  for(int i=0;i<10;i++)
      {
        System.out.println(dummy[i]);
      }*/

    sort(dummy,0,9,index_array);
    /*for(int i=0;i<10;i++)
      {
        System.out.println("ss"+index_array[i]);
      }*/
    int index=0;
    for(int i=0;i<10;i++)
    {
        int pointer=0;
        for(int j=0;j<T;j++)
          {
            if((char)(index_array[i]+97)==first_letter[j])
               pointer=1;
          }
        if(pointer==0)
        {
          index=i;
          i=10;
        }
    }
    int x=index_array[index];



    for(int i=index-1;i>=0;i--)
      {
        index_array[i+1]=index_array[i];
      }
      index_array[0]=x;

    int[] indexing= new int[10];
    for(int i=0;i<10;i++)
      {
        indexing[index_array[i]]=i;
      }

      /*for(int i=0;i<10;i++)
        System.out.println(indexing[i]);*/

      long  sum=0;
      for(int i=0;i<T;i++)
      {
         int j=14;
         while(j>=0)
         {
           if(array[i][j]!='z')
           {
             //System.out.println(sum+"aa"+assigned_array[(int)(array[i][j]-97)]*java.lang.Math.pow(10,14-j));
            sum+=indexing[(int)(array[i][j]-97)]*java.lang.Math.pow(10,14-j);
           }
            j--;
         }


      }

       System.out.println(sum);

  }


/*  public void print(char array[][],int assigned_array[],int T)
 {

     for(int i=0;i<10;i++)
      System.out.println(assigned_array[i]);
     long  sum=0;
     for(int i=0;i<T;i++)
     {
        int j=14;
        while(j>=0)
        {
          if(array[i][j]!='z')
          {
            //System.out.println(sum+"aa"+assigned_array[(int)(array[i][j]-97)]*java.lang.Math.pow(10,14-j));
           sum+=assigned_array[(int)(array[i][j]-97)]*java.lang.Math.pow(10,14-j);
          }
           j--;
        }


     }

      System.out.println(sum);
 }



 public void assign(int used_number[],int assigned_array[],char array[][],int i,int T,int array_length[],int max_length,char first_letter[])
 {
       for(int w=0;w<T;w++)
       {
         for(int j=0;j<10;j++)
           System.out.println(array[w][j]);

       }
     int[] dummy=new int[10];
     for(int k=0;k<10;k++)
       dummy[k]=0;
     for(int j=0;j<T;j++)
     {
        if(array[j][i]!='z')
         {
           int x=(int)array[j][i];
           //System.out.println(x+"xvalue\n");
           dummy[x-97]++;

         }
     }
     //System.out.println(i+"next is dumy");
     for (int c=0;c<10;c++)
     System.out.println(dummy[c]);
     int j=0;
     while(j<10)
    {
       int max=0;
       int max_index=-1;
       for(int k=0;k<10;k++)
       {
          if(dummy[k]>max)
           {

             max=dummy[k];
             max_index=k;
           }
           else
             {
               if(dummy[k]==max&&max!=0)
                {
                  max=dummy[k];
                  max_index=check(array,k,max_index,T);
                }
             }
       }
      //System.out.println(max_index+"max index is");
      if(max_index!=-1&& assigned_array[max_index]==-1)
      {
          //System.out.println(max_index+"max index issecond");
          int k=0;
          int pointer=0;
        while(k<10)
        {
          if(used_number[k]!=1 )
          {
            if (k==0)
            {
              //System.out.println("inside k=0");
              for(int w=0;w<T;w++)
                  {
                    //System.out.println("inside k=0,for loop for finding first_letter");
                    if((char)(max_index+97)==first_letter[w])
                     {
                       pointer=1;
                     }
                   }
                  if(pointer!=1)
                   {
                     //System.out.println("inside k=0,if [pointer]!=1");
                     assigned_array[max_index]=k;
                     used_number[k]=1;
                      //System.out.println(k+"value of k is");
                     k=10;
                   }
                 }

            else
            {
            System.out.println(k+"inside k!=0,inside else statement");
              assigned_array[max_index]=k;
              used_number[k]=1;
              System.out.println(k+"value of k is");
              k=10;
            }

          }
          k++;
        }

      }
      if(max_index!=-1)
        dummy[max_index]=-1;
      j++;
    }
}*/


  public static void main(String[] arg)
  {
     Scanner in = new Scanner(System.in);
     int T=in.nextInt();
     in.nextLine();
     char[][] array=new char [T][15];
     for(int i=0;i<T;i++)
     {
       for(int j=14;j>=0;j--)
           array[i][j]='z';

     }

     char [] first_letter=new char[T];
     for(int i=0;i<T;i++)
     {
        //System.out.println("jjj"+);
        String str=in.nextLine();
        for(int j=15-str.length();j<15;j++)
         {
           array[i][j]= str.charAt(j-(15-str.length()));
         }

         first_letter[i]=str.charAt(0);
      }
      //int max=0;
      /*for(int j=0;j<T;j++)
        if(array_length[j]>max)
            max=array_length[j];*/

      //int[] used_number=new int[10];
      //int[] assigned_array=new int[10];
      /*for(int j=0;j<10;j++)
        used_number[j]=0;
      for(int k=0;k<10;k++)
        assigned_array[k]=-1;*/
      /*for(int k=0;k<10;k++)
          System.out.println(first_letter[k]);*/


      minimumsum obj=new minimumsum();

      /*for(int i=0;i<15;i++)
      {
        for(int k=0;k<10;k++)
            System.out.println(used_number[k]+"meee");

        obj.assign(used_number,assigned_array,array,i,T,array_length,max,first_letter);

      }
     //System.out.println("fd");
      obj.print(array,assigned_array,T)*/

  //}

     int[] index_array= new int[10];
     for(int i=0;i<10;i++)
       index_array[i]=i;
      obj.check( array, index_array, T, first_letter);

  }
}
