Problem: 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)?

Submission attempts (in order):

import sys
def read_int(): return int(input())
def read_str_n(): return list(map(str, input().split()))

def error_print(*args): print(*args, file=sys.stderr)
def mt(f):
    import time
 
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()
 
        error_print(e - s, 'sec')
        return ret
 
    return wrap



__DEBUG__ = False

if __DEBUG__:
    N = 33
    S = list('ABCCABCBABCCABACBCBBABCBCBCBCABCB')
else:
    N = read_int()
    S = read_str_n()

@mt
def solution():
    count = 0    
    for i in range(N-2):
        if __DEBUG__: print(f"checking {S[i]} at index: {i}")
        if S[i] == 'A':
            if S[i+1] == 'B' and S[i+2] == 'C':
                count += 1
                continue
    
    
    print(f"{count}")
    
if __name__ == '__main__':
    solution()


def read_int(): return int(input())
N = read_int()
def read_str(): return input().strip()
S = list(read_str())
 
__DEBUG__ = False
 
def solution():
    count = 0    
    for i in range(N-2):
        if __DEBUG__: print(f"checking {S[i]} at index: {i}")
        if S[i] == 'A':
            if S[i+1] == 'B' and S[i+2] == 'C':
                count += 1
                # continue
    return count
 
    
if __name__ == '__main__':
  	import sys, threading
  	sys.setrecursionlimit(200000)
    threading.stack_size(10240000)
    print(solution())
    



import sys
def read_int(): return int(input())
def read_str(): return input().strip()
def read_str_n(): return list(map(str, input().split()))

def error_print(*args): print(*args, file=sys.stderr)
def mt(f):
    import time
 
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()
 
        error_print(e - s, 'sec')
        return ret
 
    return wrap



__DEBUG__ = False

if __DEBUG__:
    N = 33
    S = list('ABCCABCBABCCABACBCBBABCBCBCBCABCB')
else:
    N = read_int()
    # print(f"N = {N}")
    S = list(read_str())
    # print(f"S = {S}")
    

@mt
def solution():
    count = 0    
    for i in range(N-2):
        if __DEBUG__: print(f"checking {S[i]} at index: {i}")
        if S[i] == 'A':
            if S[i+1] == 'B' and S[i+2] == 'C':
                count += 1
                continue
    return count

    
if __name__ == '__main__':
    solution()


import sys
def read_int(): return int(input())
def read_str_n(): return list(map(str, input().split()))

def error_print(*args): print(*args, file=sys.stderr)
def mt(f):
    import time
 
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()
 
        error_print(e - s, 'sec')
        return ret
 
    return wrap



__DEBUG__ = False

if __DEBUG__:
    N = 33
    S = list('ABCCABCBABCCABACBCBBABCBCBCBCABCB')
else:
    N = read_int()
    S = read_str_n()

@mt
def solution():
    count = 0    
    for i in range(N-2):
        if __DEBUG__: print(f"checking {S[i]} at index: {i}")
        if S[i] == 'A':
            if S[i+1] == 'B' and S[i+2] == 'C':
                count += 1
                continue
    
    
    print(f"{count}")
    
if __name__ == '__main__':
    solution()


N = int(input())
S = str(input())
 
__DEBUG__ = False
 
def solution():
    count = 0    
    for i in range(N-2):
        if __DEBUG__: print(f"checking {S[i]} at index: {i}")
        if S[i] == 'A':
            if S[i+1] == 'B' and S[i+2] == 'C':
                count += 1
                # continue
    return count
 
    
if __name__ == '__main__':
  	import sys, threading
  	sys.setrecursionlimit(200000)
    threading.stack_size(10240000)
    print(solution())
    


def read_int(): return int(input())
N = read_int()
def read_str(): return input().strip()
S = list(read_str())
 
__DEBUG__ = False
 
def solution():
    count = 0    
    for i in range(N-2):
        if __DEBUG__: print(f"checking {S[i]} at index: {i}")
        if S[i] == 'A':
            if S[i+1] == 'B' and S[i+2] == 'C':
                count += 1
                # continue
    return count
 
    
if __name__ == '__main__':
  	import sys
  	sys.setrecursionlimit(200000)
    print(solution())
    

N = int(input())
S = str(input())
 


count = 0    
for i in range(N-2):
  if S[i] == 'A':
    if S[i+1] == 'B' and S[i+2] == 'C':
      count += 1
    
print(count)
    


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted