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

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

One, Two, Three

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

요약
1, 2, 3으로 이루어진 수열이 주어질 때 1-2-3 또는 3-2-1 형태의 서로 겹치지 않는 삼중항을 최대한 많이 찾아 출력한다.
난이도

보통10점 중 7점

유형
그리디, 배열, 투 포인터
정답자
아직 제출이 없습니다

문제

You are given a sequence of length NN: A_0,A_1,…,A_N−1A\_0, A\_1, \ldots, A\_{N-1}. It consists of only three kinds of integers: 1,2,31, 2, 3.

A tuple of indices (i,j,k)(i, j, k) is good if 0≤i<j<k<N0 \le i < j < k < N and it satisfies one of the two following conditions: either A_i=1,,A_j=2,,A_k=3A\_i = 1, \\, A\_j = 2, \\, A\_k = 3 or A_i=3,,A_j=2,,A_k=1A\_i = 3, \\, A\_j = 2, \\, A\_k = 1.

Your goal is find disjoint good tuples, as many of them as possible. A group of tuples is disjoint if no index is present in more than one tuple.

Find the maximum number of disjoint good tuples and print each tuple.

입력

The first line contains an integer NN, the length of the given sequence (1≤N≤600,0001 \le N \le 600\\,000).

The next line contains NN integers: A_0,A_1,…,A_N−1A\_0, A\_1, \ldots, A\_{N-1} (1≤A_i≤31 \le A\_i \le 3).

출력

On the first line, print an integer MM, the maximum number of disjoint good tuples.

On the next MM lines, print the tuples themselves. Each of these lines must contains three integers i,j,ki, j, k (0≤i<j<k<N0 \le i < j < k < N) that describes a good tuple. All the printed tuples must be disjoint. If there are several solutions, print any one of them.

예제2

  1. 예제 1

    입력
    6
    3 1 2 2 3 1
    
    예상 출력
    2
    1 2 4
    0 3 5
    
  2. 예제 2

    입력
    6
    2 1 3 1 3 2
    
    예상 출력
    0