import java.util.regex.MatchResult;
import java.util.regex.Pattern;

public class Main {
    public static void main(String args[]) {
        // find the occurance of 'CO' in the given string using stream API
        String str = "WELCOMEWELCOME";
        String substring = "CO";
        
        System.out.println(getSubstringCount(str, substring));
    }
    static long getSubstringCount(String str, String substring) {
        return Pattern.compile(substring)
                .matcher(str)
                .results()
                .map(MatchResult::group)
                .count();
    }
}