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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
using in = int64_t;


int sagasu(vector<char> s,int n, int x,int y){
   int ret=0;
  for(int i=x;i<n;i++){
     if(s.at(i)==(char)(y)){
        ret=i;
        break;
      }
    else if(i==n-1) ret=-1;
  }
  return ret;
}

int main(){
  int x,y,z;
  int ans =0;
  int n;
  cin>>n;
  vector<char> s(n);
  rep(i,n) cin>> s.at(i);
  
  rep(i,10){
    x= sagasu(s,n,0,i);
    if(x==-1 || x>n-3) continue;
  rep(j,10){
    y= sagasu(s,n,x+1,j);
    if(y==-1 || y>n-2) continue;
  rep(k,10){
     /* x= sagasu(s,n,0,i);
    if(x==-1 || x>n-3) break;*/
      /*y= sagasu(s,n,x+1,j);
    if(y==-1 || y>n-2) break;*/
      z= sagasu(s,n,y+1,k);
    if(z!=-1) ans ++;
         
    
  }  //if(x==-1 || x>n-3) break;
  } 
  }
  cout <<ans;
}