Card Game

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

요약
각 값이 세 번씩 나오는 3N장의 카드가 원형으로 놓여 있을 때, 세 장이 모일 때마다 카드를 내려놓는 과정에서 손에 든 카드 수의 최댓값을 최소로 만드는 시작 위치를 찾는다.
난이도

어려움10점 중 8점

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

문제

Ivar invented a new solitaire game. It is played with 3⋅N3 \cdot N cards where each integer from 11 to NN is written on exactly three of the cards.

In the beginning, the cards are shuffled and laid out in a circle on a table. A possible distribution of cards for N=5N = 5 is shown in the figure.

Then, starting from some card, the player picks consecutive cards one by one in clockwise order. Whenever the player has three cards with the same number on them, these three cards are immediately put aside. Otherwise the player keeps the new card in hand. This continues until all the cards have been picked up. By the end of the game, all the cards will have been put aside and there will be no cards left in the player's hand.

Let's see how the number of cards in hand changes when the player starts from the topmost "5" card in the figure:

Card543351421521342
Number of cards in hand after the move123456789786420

As you can see, the largest number of cards in hand after some move is 99. However, starting from the "3" card on the left, the number of cards changes as follows:

Card342543351421521
Number of cards in hand after the move123456456456420

This time the largest number of cards in hand after some move is 66. Ivar calls this largest number of cards the score of the game.

Write a program to determine for a given sequence of cards the least possible score and possible starting cards to achieve this score.

입력

The first line contains NN (1≤N≤25,0001 \le N \le 25\\,000), the largest number that appears on the cards. The next line contains 3⋅N3 \cdot N integers, the numbers on the cards, listed in clockwise order starting from the topmost card. Each number from 11 to NN appears exactly three times. The cards are indexed from 11 to 3⋅N3 \cdot N in the order they are listed in the input.

출력

The first line should contain two integers: SS, the least possible score, and KK, the number of different starting cards resulting in the score SS. The second line should contain KK integers: the indices of the starting cards resulting in the score SS, listed in increasing order.

예제2

  1. 예제 1

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

    입력
    2
    2 1 2 1 2 1
    
    예상 출력
    4 6
    1 2 3 4 5 6