아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Patio

면접 대비

시간 제한3초메모리 제한1024 MB

요약
한 색이 두께 1의 테두리를 이루고 다른 색이 내부를 채우는 정사각형 마당을 만들 수 있는 연속 부분 문자열의 개수를 센다.
난이도

보통10점 중 4점

유형
슬라이딩 윈도우, 문자열, 구현
정답자
아직 제출이 없습니다

문제

Cimrman wants to make a square patio floor using tiles of two colours, red and blue. The patio floor should look like this (with the colors slightly faded in time):

Figure 1: One of Cimrman’s perfect patios

More specifically, the patio must have a square shape. Tiles of one of the colours are used as the border of the square. The border must be exactly one tile thick. The tiles of the other colour are used to fill the rest of the square. Also, the side of the square must consist of at least 3 tiles.

Cimrman has a long file of square red tiles and blue tiles, the size of all tiles is the same. From this file, Cimrman is going to take some tiles to use them on the floor. Manipulating the file is clumsy, so Cimrman wants the tiles to be taken easily from the file, meaning the taken tiles have to form one contiguous subsequence in the file.

Before Cimrman starts the construction, he needs to know how many suitable subsequences of tiles are there in the file.

입력

The input consists of two lines. The first line contains integer N (1 ≤ N ≤ 2 · 105), the length of the file of tiles. The second line contains string of N characters, representing the file of tiles. Only two characters appear in the string, “X” represents a blue tile and “O” represents a red tile.

출력

Output the number of contiguous subsequences in the file from which Cimrman can construct a nice square patio floor.

예제2

  1. 예제 1

    입력
    9
    XXXOXXXXX
    
    예상 출력
    1
    
  2. 예제 2

    입력
    10
    XOXXXXXXXX
    
    예상 출력
    2