103110: [Atcoder]ABC311 A - First ABC

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:7 Solved:0

Description

Score : $100$ points

Problem Statement

You are given a string $S$ consisting of A, B, and C. $S$ is guaranteed to contain all of A, B, and C.

If the characters of $S$ are checked one by one from the left, how many characters will have been checked when the following condition is satisfied for the first time?

  • All of A, B, and C have appeared at least once.

Constraints

  • $3 \leq N \leq 100$
  • $S$ is a string of length $N$ consisting of A, B, and C.
  • $S$ contains all of A, B, and C.

Input

The input is given from Standard Input in the following format:

$N$
$S$

Output

Print the answer.


Sample Input 1

5
ACABB

Sample Output 1

4

In the first four characters from the left, A, B, and C appear twice, once, and once, respectively, satisfying the condition.
The condition is not satisfied by checking three or fewer characters, so the answer is $4$.


Sample Input 2

4
CABC

Sample Output 2

3

In the first three characters from the left, each of A, B, and C appears once, satisfying the condition.


Sample Input 3

30
AABABBBABABBABABCABACAABCBACCA

Sample Output 3

17

Input

题意翻译

给出一个长度为 $N$ 的字符串 $S$,其中包含 $\texttt{A,B,C}$ 三个字符各若干次,保证 $\texttt{A,B,C}$ 三个字符在字符串 $S$ 中至少出现一次,求从字符串 $S$ 第一位开始包含 $\texttt{A,B,C}$ 三个字符各至少一次的最短的长度。

Output

分数:100分 部分 问题描述 给定一个由`A`,`B`和`C`组成的字符串$S$。$S$保证包含所有`A`,`B`和`C`。 如果从左向右逐个检查$S$的字符,那么在满足以下条件时将检查多少个字符? * `A`,`B`和`C`都至少出现一次。 部分 约束条件 * $3 \leq N \leq 100$ * $S$是一个长度为$N$的字符串,由`A`,`B`和`C`组成。 * $S$包含所有`A`,`B`和`C`。 输入输出格式 输入 输入格式如下: ``` $N$ $S$ ``` 输出 打印答案。 样例输入1 ``` 5 ACABB ``` 样例输出1 ``` 4 ``` 在从左数的前四个字符中,`A`,`B`和`C`分别出现两次,一次和一次,满足条件。 检查三个或更少的字符时不满足条件,因此答案为$4$。 样例输入2 ``` 4 CABC ``` 样例输出2 ``` 3 ``` 在从左数的前三个字符中,`A`,`B`和`C`分别出现一次,满足条件。 样例输入3 ``` 30 AABABBBABABBABABCABACAABCBACCA ``` 样例输出3 ``` 17 ```

HINT

出现ABC三个字母的最短前缀长度是多少?

加入题单

上一题 下一题 算法标签: