Card Game | 프로그래밍의 벗 PivotOJ
PivotOJ

Card Game

시간 제한: 300ms메모리 제한: 1024MB출처: EIO 2022-23 sel2BOJ 29844
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

[이미지 1]Ivar invented a new solitaire game. It is played with 3N3 \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:

Card 5 4 3 3 5 1 4 2 1 5 2 1 3 4 2
Number of cards in hand after the move 1 2 3 4 5 6 7 8 9 7 8 6 4 2 0

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:

Card 3 4 2 5 4 3 3 5 1 4 2 1 5 2 1
Number of cards in hand after the move 1 2 3 4 5 6 4 5 6 4 5 6 4 2 0

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 (1N250001 \le N \le 25\,000), the largest number that appears on the cards. The next line contains 3N3 \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 3N3 \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.

예제

예제 1

입력
5
5 4 3 3 5 1 4 2 1 5 2 1 3 4 2
출력
6 2
6 13

예제 2

입력
2
2 1 2 1 2 1
출력
4 6
1 2 3 4 5 6
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.