Problem:
Score: 400 points

Problem Statement

AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.

The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.

How many different PIN codes can he set this way?

Both the lucky number and the PIN code may begin with a 0.

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

Thus, he can set three different PIN codes: 022, 024, and 224.

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329

Solution in C (GCC 5.4.1) (judge verdict: Accepted)

#include<stdio.h>
#include<stdlib.h>

#define N 30001

int n, integer_s[N]={10};
char s[N];

int search(int i, int *cnt, int *iPass){
  if(i==3){
//    printf("%d %d %d %d\n",iPass[0], iPass[1], iPass[2], iPass[3]);
    *cnt = *cnt+1;
  }
  else{
    for(int k=0; k<=9; k++){ 
      for(int j=iPass[i]+1; j<n; j++){ 
//        printf("%d\n",integer_s[j]);
        if(integer_s[j]==k){
          iPass[i+1] = j;
          search(i+1, cnt, iPass);
          break;
        }
      }
    }
  }
  return 0;
}

int main(){
  int cnt=0, iPass[4]={-1}; 
  char sTmp;
  // iPass[0]=-1, iPass[1]:1桁目の格納場所 ,iPass[2]:２桁目の格納場所, iPass[3]:3桁目の格納場所
  scanf("%d %s", &n, s);
//  for(int a=0;a<n;a++){
//    printf("%c\n",s[a]);
//    printf("%d\n",atoi(&s[a]));
//  }
  for(int i=0; i<n; i++){
    sTmp = s[i];
    integer_s[i] = atoi(&sTmp);
//    printf("%d ",integer_s[i]);
  }

  search(0, &cnt, iPass);
  printf("%d",cnt);
  
  return 0;
}