Codeforces Round #364 (Div. 2) C

Source: Internet
Author: User

Description

Sergei B., the young coach of Pokemons, had found the big house which consists of N Flats ordered in a row fr Om left-to-right. It is possible-enter each flat from the street. It is the possible to go off from each flat. Also, each flat was connected with the flat to the left and the flat to the right. Flat Number 1 is only connected with the Flat number 2 and the Flat number n are only connected with t He flat number n -1.

There is exactly one Pokemon of some type in each of these flats. Sergei B. Asked residents of the house to let him enter their flats in order to catch pokemons. After consulting the residents of the House decided to let Sergei b. Enter one flat from the street, visit several flats a nd then go off from some flat. But they won ' t let him visit the same flat more than once.

Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect pokemons of all types T Hat appear in the house. Your task is to help him and determine this minimum number of flats he have to visit.

Input

The first line contains the integer n (1≤ n ≤100)-the number of flats in the house.

The second line contains the row s with the length n, it consists of uppercase and lowercase let Ters of Chinese alphabet, the i-th letter equals the type of Pokemon, which are in the flat number i .

Output

Print the minimum number of flats which Sergei B. should visit in order to catch pokemons of all types which there is in The house.

Examples input
3
Aaa
Output
2
input
7
Bcaacbc
Output
3
input
6
Aabcce
Output
5
Note

In the first Test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.

In the second Test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.

In the third Test Sergei B. must begin from the flat number 2 and end in the flat number 6.

Test instructions: is to find the smallest interval, it can contain all the letters of the character

We set the starting point and the end point, l,r;

L Start with the first occurrence of the letter, and if the letter appears again, move to the first occurrence of another letter.

R traverses from the beginning to the end, and updates once if the traversal meets the criteria

#include <cstdio> #include <cstring> #include <cctype> #include <cmath> #include <set># include<map> #include <list> #include <queue> #include <deque> #include <stack> #include <string> #include <vector> #include <iostream> #include <algorithm> #include <stdlib.h>    Using namespace Std;int flag[100005];int main () {set<char>q;    int a[100005];    string S;    int n;    int sum;    int l=0,r=0;    int len= (1&LT;&LT;30);    cin>>n;    cin>>s;    for (int i=0;i<n;i++) {Q.insert (s[i]);    } sum=q.size ();    for (int r=0;r<n;)        {int cot=s[r]-' 0 ';        flag[cot]++;        if (flag[cot]==1) {sum--;        }//cout<<flag[cot]<< "B" <<endl;            Cout<<flag[s[l] while (flag[s[l]-' 0 ']>1) {flag[s[l]-' 0 ']--;          l++;        cout<<l<< "A" <<endl;    } if (sum==0) {    Len=min (len,r-l+1);      cout<<r<<endl;        cout<<l<<endl;     } r++;    cout<<r<< "A" <<endl;    } cout<<len<<endl; return 0;}

  

Codeforces Round #364 (Div. 2) C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.