#abc322a. A - First ABC 2

A - First ABC 2

Score : 100100 points

问题描述

给定一个长度为 NN 的字符串 SS,其中包含字符 ABC

寻找 ABC 首次作为连续子串出现在 SS 中的位置。换句话说,找到满足以下所有条件的最小整数 nn

  • 1nN21 \leq n \leq N - 2
  • SS 中提取第 nn 个到第 (n+2)(n+2) 个字符得到的字符串是 ABC

如果 ABC 不在 SS 中出现,则输出 -1

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a string SS of length NN consisting of A, B, and C.
Find the position where ABC first appears as a (contiguous) substring in SS. In other words, find the smallest integer nn that satisfies all of the following conditions.

  • 1nN21 \leq n \leq N - 2.
  • The string obtained by extracting the nn-th through (n+2)(n+2)-th characters of SS is ABC.

If ABC does not appear in SS, print -1.

Constraints

  • 3N1003 \leq N \leq 100
  • SS is a string of length NN consisting of A, B, and C.

Input

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

NN

SS

Output

Print the position where ABC first appears as a substring in SS, or -1 if it does not appear in SS.

Sample Input 1

8
ABABCABC

Sample Output 1

3

ABC first appears in SS at the 33-rd through 55-th characters of SS. Therefore, the answer is 33.

Sample Input 2

3
ACB

Sample Output 2

-1

If ABC does not appear in SS, print 1-1.

Sample Input 3

20
BBAAABBACAACABCBABAB

Sample Output 3

13

update @ 2024/3/10 01:41:47