Problem:
Score : 200 points

Problem Statement

We have a string S of length N consisting of uppercase English letters.

How many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)?

Constraints

3 \leq N \leq 50

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print number of occurrences of ABC in S as contiguous subsequences.

Sample Input 1

10
ZABCDBABCQ

Sample Output 1

2

Two contiguous subsequences of S are equal to ABC: the 2-nd through 4-th characters, and the 7-th through 9-th characters.

Sample Input 2

19
THREEONEFOURONEFIVE

Sample Output 2

0

No contiguous subsequences of S are equal to ABC.

Sample Input 3

33
ABCCABCBABCCABACBCBBABCBCBCBCABCB

Sample Output 3

5

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.util.*;
import java.lang.*;
import java.util.stream.*;
import java.util.function.*;

// 文字列を一文字ずつ配列にしてStream
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] firstArr = sc.nextLine().split(" ");
        System.out.println(solve(getInputAsArray(sc, "1")));
    }

    private static List<String[]> getInputAsArray(Scanner sc, String count) {
        List<String[]> result = new ArrayList<>();
        IntStream.range(0, Integer.parseInt(count)).forEach(i -> result.add(sc.nextLine().split(" ")));
        return result;
    }

    private static Long[] convertStrToInt(String[] strArray) {
        return Arrays.stream(strArray).map(e -> new Long(Long.parseLong(e))).toArray(Long[]::new);
    }

    private static long outputResult(long a, long b) {
        return LongStream.range(0, b).reduce((long) 0, (sum, i) -> sum += (Math.pow(10, i) * a));
    }

    private static String solve(List<String[]> input) {
        Predicate<String> predicate = (str) -> str.equals("A") || str.equals("B") || str.equals("C");
        BiPredicate<String, String> strCheker = (accum, str) -> {
            // System.out.println(accum + " " + str);
            Map<String, String> map = new HashMap<>();
            map.put("A", "");
            map.put("B", "A");
            map.put("C", "AB");
            return str.equals("A") || accum.equals(map.get(str));
        };
        ArrayList<String> result = new ArrayList<>();
        Arrays.stream(input.get(0)[0].split("")).reduce("", (accum, value) -> {
            // System.out.println("---" + accum + "----" + value);
            if (value.equals("A")) {
                accum = "A";
            } else if (strCheker.test(accum, value)) {
                accum += value;
            }
            if (accum.equals("ABC")) {
                // System.out.println("avc");
                result.add(value);
                return "";
            }
            return accum;
        });
        return String.valueOf(result.size());
    }

}

class Resp {
    private long min = Long.MAX_VALUE;
    private int cont = 0;

    public Resp(long min, int cont) {
        this.min = min;
        this.cont = cont;
    }

    public long getMin() {
        return this.min;
    }

    public void setMin(long min) {
        this.min = min;
    }

    public int getCont() {
        return this.cont;
    }

    public void setCont(int cont) {
        this.cont = cont;
    }

    public void addCont() {
        this.cont++;
    }

}