QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#319532#5583. Color TubeschmproTL 12ms10172kbPython31.8kb2024-02-02 18:44:352024-02-02 18:44:35

Judging History

你现在查看的是最新测评结果

  • [2024-02-02 18:44:35]
  • 评测
  • 测评结果:TL
  • 用时:12ms
  • 内存:10172kb
  • [2024-02-02 18:44:35]
  • 提交

answer

import sys
input=sys.stdin.readline
F=lambda:[*map(int,input().split())]
def move(i,j):
  if i==j:return
  ANS.append((i,j))
  h1=2
  while A[i][h1]==0:h1-=1
  x=A[i][h1]
  A[i][h1]=0
  if h1>=1:CNT[x]-=1
  idx1=0
  while POS[x][idx1]!=(i,h1):idx1+=1
  h2=0
  while A[j][h2]>0:h2+=1
  A[j][h2]=x
  if h2>=1:CNT[x]+=1
  POS[x][idx1]=(j,h2)
  idx2=0
  while POS[0][idx2]!=(j,h2):idx2+=1
  POS[0][idx2]=(i,h1)

def make_empty():
  POS[0].sort()
  p0=POS[0][0][0]
  for idx in range(1,3):
    if POS[0][idx][0]!=p0:move(p0,POS[0][idx][0])

N=int(input())
A=[[]]+[F()for _ in range(N+1)]
CNT=[0]*(N+1)
POS=[[]for _ in range(N+1)]
for n in range(1,N+2):
  for h in range(3):
    cur=A[n][h]
    if h>=1:CNT[cur]+=1
    POS[cur].append((n,h))

ANS=[]
NXT=[i+1 for i in range(N+1)];NXT[N]=1
PRV=[i-1 for i in range(N+1)];PRV[1]=N


cur=1
for _ in range(N):
  make_empty()
  #print(ANS,CNT,POS)
  pos_0=POS[0][0][0]
  while 1:
    if CNT[cur]<=1:cur=NXT[cur];continue
    idx=0
    while idx<3 and POS[cur][idx][1]<2:idx+=1
    if idx==3:cur=NXT[cur];continue
    else:break
  #print(ANS)
  POS[cur].sort(key=lambda x:-x[1])
  p1=POS[cur][0][0]
  move(p1,pos_0)
  p2=POS[cur][1][0];h=POS[cur][1][1]
  chk=1
  if h==2 or p1==p2:move(p2,pos_0)
  else:
    move(p2,p1)
    chk=0 #p1에 자리 없음
    move(p2,pos_0)
  p3=POS[cur][2][0];h=POS[cur][2][1]
  if h==2 or (h==1 and (p3==p2)) or (h==0 and p3==p2==p1):move(p3,pos_0)
  elif h==1:
    #print(ANS)
    move(p3,p2)
    move(p3,pos_0)
  else:
    if chk:
      move(p3,p1)
      move(p3,p2)
      move(p3,pos_0)
    else:
      move(p3,p2)
      move(p3,p2)
      move(p3,pos_0)

  nxt=NXT[cur]
  prv=PRV[cur]
  NXT[prv]=nxt
  PRV[nxt]=prv
  cur=nxt
print(len(ANS))
for ans in ANS:print(*ans)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 9880kb

input:

3
2 2 0
1 3 1
3 1 2
3 0 0

output:

16
1 4
1 4
2 1
3 2
3 1
2 3
2 3
2 1
4 2
4 2
3 4
3 2
3 4
4 3
4 3
4 3

result:

ok correct

Test #2:

score: 0
Accepted
time: 6ms
memory: 9968kb

input:

1
0 0 0
1 1 1

output:

3
2 1
2 1
2 1

result:

ok correct

Test #3:

score: 0
Accepted
time: 11ms
memory: 9960kb

input:

2
2 1 0
2 1 0
2 1 0

output:

11
1 2
1 3
2 1
2 1
3 2
3 1
2 3
2 3
3 2
3 2
3 2

result:

ok correct

Test #4:

score: 0
Accepted
time: 10ms
memory: 10032kb

input:

3
0 0 0
1 2 3
1 2 3
1 2 3

output:

14
2 1
3 1
4 1
2 3
2 4
3 2
3 2
4 3
4 2
3 4
3 4
4 3
4 3
4 3

result:

ok correct

Test #5:

score: 0
Accepted
time: 7ms
memory: 10072kb

input:

3
1 2 3
1 2 3
0 0 0
1 2 3

output:

14
1 3
2 3
4 3
1 2
1 4
2 1
2 1
4 2
4 1
2 4
2 4
4 2
4 2
4 2

result:

ok correct

Test #6:

score: 0
Accepted
time: 7ms
memory: 10028kb

input:

3
1 2 3
1 2 3
1 2 3
0 0 0

output:

14
1 4
2 4
3 4
1 2
1 3
2 1
2 1
3 2
3 1
2 3
2 3
3 2
3 2
3 2

result:

ok correct

Test #7:

score: 0
Accepted
time: 8ms
memory: 9948kb

input:

6
0 0 0
1 2 3
1 2 3
1 2 3
4 5 6
4 5 6
4 5 6

output:

28
2 1
3 1
4 1
2 3
2 4
5 2
6 2
7 2
5 6
5 7
3 5
3 5
4 3
4 5
3 4
3 4
6 3
6 3
7 6
7 3
6 7
6 7
4 6
4 6
4 6
7 4
7 4
7 4

result:

ok correct

Test #8:

score: 0
Accepted
time: 10ms
memory: 9944kb

input:

6
0 0 0
1 5 6
1 2 6
1 2 3
4 2 3
4 5 3
4 5 6

output:

29
4 1
5 1
6 1
4 5
4 6
2 4
3 4
7 4
2 3
2 7
7 2
6 2
3 7
3 6
3 2
6 3
5 3
5 3
5 6
7 5
6 7
6 5
7 6
7 5
6 7
6 7
7 6
7 6
7 6

result:

ok correct

Test #9:

score: 0
Accepted
time: 8ms
memory: 10032kb

input:

9
1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9
0 0 0

output:

42
1 10
4 10
7 10
1 4
1 7
2 1
5 1
8 1
2 5
2 8
3 2
6 2
9 2
3 6
3 9
4 3
4 3
7 4
7 3
4 7
4 7
5 4
5 4
8 5
8 4
5 8
5 8
6 5
6 5
9 6
9 5
6 9
6 9
7 6
7 6
7 6
8 7
8 7
8 7
9 8
9 8
9 8

result:

ok correct

Test #10:

score: 0
Accepted
time: 5ms
memory: 10036kb

input:

10
1 2 3
4 5 6
7 8 9
10 1 2
3 4 5
6 7 8
9 10 1
2 3 4
5 6 7
8 9 10
0 0 0

output:

52
7 11
4 7
4 11
1 4
1 4
1 11
4 1
7 1
8 4
8 7
8 1
7 8
4 7
4 8
5 4
5 4
5 8
4 5
7 5
2 4
2 7
2 5
7 2
4 7
4 2
9 4
9 4
9 2
7 9
4 9
6 7
6 4
6 9
4 6
4 6
3 4
3 4
3 6
4 3
7 3
10 4
10 7
10 3
7 10
4 7
4 10
7 4
7 4
7 10
4 7
4 7
4 7

result:

ok correct

Test #11:

score: 0
Accepted
time: 10ms
memory: 10044kb

input:

11
1 2 3
4 5 6
7 8 9
10 11 1
2 3 4
5 6 7
8 9 10
11 1 2
3 4 5
6 7 8
9 10 11
0 0 0

output:

55
4 12
8 4
8 12
1 8
1 8
1 12
8 1
4 1
5 8
5 4
5 1
4 5
8 4
8 5
9 8
9 8
9 5
4 9
8 9
2 4
2 8
2 9
8 2
8 2
6 8
6 8
6 2
4 6
8 6
10 4
10 8
10 6
8 10
8 10
3 8
3 8
3 10
8 3
4 3
7 8
7 4
7 3
4 7
8 4
8 7
11 8
11 8
11 7
4 11
8 11
4 8
4 11
8 4
8 4
8 4

result:

ok correct

Test #12:

score: 0
Accepted
time: 8ms
memory: 9920kb

input:

12
1 2 3
4 5 6
7 8 9
10 11 12
1 2 3
4 5 6
7 8 9
10 11 12
1 2 3
4 5 6
7 8 9
10 11 12
0 0 0

output:

56
1 13
5 13
9 13
1 5
1 9
2 1
6 1
10 1
2 6
2 10
3 2
7 2
11 2
3 7
3 11
4 3
8 3
12 3
4 8
4 12
5 4
5 4
9 5
9 4
5 9
5 9
6 5
6 5
10 6
10 5
6 10
6 10
7 6
7 6
11 7
11 6
7 11
7 11
8 7
8 7
12 8
12 7
8 12
8 12
9 8
9 8
9 8
10 9
10 9
10 9
11 10
11 10
11 10
12 11
12 11
12 11

result:

ok correct

Test #13:

score: 0
Accepted
time: 4ms
memory: 10080kb

input:

13
1 2 3
4 5 6
7 8 9
10 11 12
13 1 2
3 4 5
6 7 8
9 10 11
12 13 1
2 3 4
5 6 7
8 9 10
11 12 13
0 0 0

output:

67
9 14
5 9
5 14
1 5
1 5
1 14
5 1
9 1
10 5
10 9
10 1
9 10
5 9
5 10
6 5
6 5
6 10
5 6
9 6
2 5
2 9
2 6
9 2
5 9
5 2
11 5
11 5
11 2
9 11
5 11
7 9
7 5
7 11
5 7
5 7
3 5
3 5
3 7
5 3
9 3
12 5
12 9
12 3
9 12
5 9
5 12
8 5
8 5
8 12
5 8
9 8
4 5
4 9
4 8
9 4
5 9
5 4
13 5
13 5
13 4
9 13
5 13
9 5
9 13
5 9
5 9
5 9

result:

ok correct

Test #14:

score: 0
Accepted
time: 10ms
memory: 10032kb

input:

9
1 7 3
6 1 7
5 2 0
2 5 0
3 7 8
2 4 6
9 4 9
8 1 0
6 3 5
4 8 9

output:

47
3 4
3 8
1 3
9 1
9 3
5 9
5 9
5 3
8 5
1 5
4 1
4 5
4 8
2 4
9 4
1 9
1 4
1 2
7 1
10 1
7 10
7 1
2 7
2 7
8 2
8 7
2 8
2 8
9 2
8 9
8 2
6 8
6 8
6 2
8 6
10 6
10 8
10 6
9 10
8 9
8 10
9 8
9 8
9 10
8 9
8 9
8 9

result:

ok correct

Test #15:

score: 0
Accepted
time: 10ms
memory: 9960kb

input:

10
3 3 8
5 6 9
1 2 3
7 7 10
9 5 0
7 8 0
5 1 4
1 6 10
4 2 0
8 9 10
2 6 4

output:

51
5 6
5 9
3 5
1 3
1 5
1 5
7 1
11 1
9 7
9 11
9 1
3 9
6 3
6 9
10 6
10 6
10 9
2 10
7 10
6 10
2 6
2 7
4 2
8 2
6 8
6 2
4 6
4 6
11 4
3 11
3 4
11 3
11 3
11 4
7 11
3 7
3 11
7 3
7 3
7 11
8 7
8 7
3 8
3 7
3 8
6 3
6 3
6 3
8 6
8 6
8 6

result:

ok correct

Test #16:

score: 0
Accepted
time: 10ms
memory: 9964kb

input:

11
2 11 11
4 6 4
8 10 0
7 7 8
10 6 2
3 10 0
3 6 0
5 9 3
1 2 9
7 11 1
9 8 5
1 5 4

output:

59
3 6
3 7
5 3
9 5
9 3
1 9
1 9
1 3
2 1
12 1
2 12
2 1
11 2
12 11
12 2
8 12
8 12
8 2
11 8
5 11
5 8
7 5
7 8
5 7
5 7
4 5
7 4
7 5
11 7
11 5
7 11
7 11
12 7
11 12
11 7
11 7
6 11
4 11
6 4
6 11
9 6
9 6
10 9
10 6
9 10
9 10
10 9
10 9
12 10
12 10
12 9
11 12
10 12
10 12
10 11
11 10
4 11
4 10
4 10

result:

ok correct

Test #17:

score: 0
Accepted
time: 10ms
memory: 10076kb

input:

12
9 5 11
1 12 1
4 7 8
6 11 12
2 2 4
2 3 10
6 3 10
3 1 0
4 5 9
5 11 12
7 6 8
10 8 0
9 7 0

output:

65
8 12
8 13
2 8
12 8
2 12
2 8
13 2
6 13
6 2
7 6
7 2
6 7
6 7
3 6
11 6
12 11
12 6
3 12
3 12
13 3
7 13
7 3
12 7
12 7
12 3
1 12
4 1
4 12
10 4
10 12
4 10
4 10
11 4
1 4
10 1
10 4
10 11
13 10
5 13
5 10
5 10
13 5
7 13
7 5
9 7
9 7
9 5
7 9
11 9
1 11
1 9
1 7
11 1
11 1
7 11
7 11
7 1
13 7
13 7
11 13
11 13
11 7
...

result:

ok correct

Test #18:

score: 0
Accepted
time: 9ms
memory: 9960kb

input:

13
3 13 1
5 0 0
1 10 2
2 3 11
4 9 10
5 12 4
11 5 2
6 10 12
4 11 6
6 8 9
8 13 7
7 1 3
8 12 13
7 9 0

output:

76
2 14
1 2
12 1
12 2
3 12
3 12
3 2
7 3
12 7
12 3
4 12
4 12
4 3
12 4
1 4
1 12
1 4
14 1
7 14
7 1
6 7
6 7
6 1
10 6
5 10
5 6
14 5
14 6
5 14
5 14
10 5
14 10
14 5
8 14
8 5
8 14
7 8
14 7
14 8
13 14
13 8
13 14
12 13
11 12
11 13
14 11
14 13
11 14
11 14
10 11
7 10
7 11
9 7
9 7
9 11
10 9
7 10
7 9
10 7
10 7
10...

result:

ok correct

Test #19:

score: 0
Accepted
time: 11ms
memory: 10056kb

input:

99
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27
28 29 30
31 32 33
34 35 36
37 38 39
40 41 42
43 44 45
46 47 48
49 50 51
52 53 54
55 56 57
58 59 60
61 62 63
64 65 66
67 68 69
70 71 72
73 74 75
76 77 78
79 80 81
82 83 84
85 86 87
88 89 90
91 92 93
94 95 96
97 98 99
1 2 3
4 5...

output:

462
1 100
34 100
67 100
1 34
1 67
2 1
35 1
68 1
2 35
2 68
3 2
36 2
69 2
3 36
3 69
4 3
37 3
70 3
4 37
4 70
5 4
38 4
71 4
5 38
5 71
6 5
39 5
72 5
6 39
6 72
7 6
40 6
73 6
7 40
7 73
8 7
41 7
74 7
8 41
8 74
9 8
42 8
75 8
9 42
9 75
10 9
43 9
76 9
10 43
10 76
11 10
44 10
77 10
11 44
11 77
12 11
45 11
78 11...

result:

ok correct

Test #20:

score: 0
Accepted
time: 11ms
memory: 10172kb

input:

100
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27
28 29 30
31 32 33
34 35 36
37 38 39
40 41 42
43 44 45
46 47 48
49 50 51
52 53 54
55 56 57
58 59 60
61 62 63
64 65 66
67 68 69
70 71 72
73 74 75
76 77 78
79 80 81
82 83 84
85 86 87
88 89 90
91 92 93
94 95 96
97 98 99
100 1 2
...

output:

532
67 101
34 67
34 101
1 34
1 34
1 101
34 1
67 1
68 34
68 67
68 1
67 68
34 67
34 68
35 34
35 34
35 68
34 35
67 35
2 34
2 67
2 35
67 2
34 67
34 2
69 34
69 34
69 2
67 69
34 69
36 67
36 34
36 69
34 36
34 36
3 34
3 34
3 36
34 3
67 3
70 34
70 67
70 3
67 70
34 67
34 70
37 34
37 34
37 70
34 37
67 37
4 34
...

result:

ok correct

Test #21:

score: 0
Accepted
time: 11ms
memory: 10148kb

input:

101
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27
28 29 30
31 32 33
34 35 36
37 38 39
40 41 42
43 44 45
46 47 48
49 50 51
52 53 54
55 56 57
58 59 60
61 62 63
64 65 66
67 68 69
70 71 72
73 74 75
76 77 78
79 80 81
82 83 84
85 86 87
88 89 90
91 92 93
94 95 96
97 98 99
100 101 ...

output:

520
34 102
68 34
68 102
1 68
1 68
1 102
68 1
34 1
35 68
35 34
35 1
34 35
68 34
68 35
69 68
69 68
69 35
34 69
68 69
2 34
2 68
2 69
68 2
68 2
36 68
36 68
36 2
34 36
68 36
70 34
70 68
70 36
68 70
68 70
3 68
3 68
3 70
68 3
34 3
37 68
37 34
37 3
34 37
68 34
68 37
71 68
71 68
71 37
34 71
68 71
4 34
4 68
4...

result:

ok correct

Test #22:

score: 0
Accepted
time: 7ms
memory: 10048kb

input:

102
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27
28 29 30
31 32 33
34 35 36
37 38 39
40 41 42
43 44 45
46 47 48
49 50 51
52 53 54
55 56 57
58 59 60
61 62 63
64 65 66
67 68 69
70 71 72
73 74 75
76 77 78
79 80 81
82 83 84
85 86 87
88 89 90
91 92 93
94 95 96
97 98 99
100 101 ...

output:

476
1 103
35 103
69 103
1 35
1 69
2 1
36 1
70 1
2 36
2 70
3 2
37 2
71 2
3 37
3 71
4 3
38 3
72 3
4 38
4 72
5 4
39 4
73 4
5 39
5 73
6 5
40 5
74 5
6 40
6 74
7 6
41 6
75 6
7 41
7 75
8 7
42 7
76 7
8 42
8 76
9 8
43 8
77 8
9 43
9 77
10 9
44 9
78 9
10 44
10 78
11 10
45 10
79 10
11 45
11 79
12 11
46 11
80 11...

result:

ok correct

Test #23:

score: 0
Accepted
time: 3ms
memory: 10064kb

input:

103
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27
28 29 30
31 32 33
34 35 36
37 38 39
40 41 42
43 44 45
46 47 48
49 50 51
52 53 54
55 56 57
58 59 60
61 62 63
64 65 66
67 68 69
70 71 72
73 74 75
76 77 78
79 80 81
82 83 84
85 86 87
88 89 90
91 92 93
94 95 96
97 98 99
100 101 ...

output:

547
69 104
35 69
35 104
1 35
1 35
1 104
35 1
69 1
70 35
70 69
70 1
69 70
35 69
35 70
36 35
36 35
36 70
35 36
69 36
2 35
2 69
2 36
69 2
35 69
35 2
71 35
71 35
71 2
69 71
35 71
37 69
37 35
37 71
35 37
35 37
3 35
3 35
3 37
35 3
69 3
72 35
72 69
72 3
69 72
35 69
35 72
38 35
38 35
38 72
35 38
69 38
4 35
...

result:

ok correct

Test #24:

score: 0
Accepted
time: 11ms
memory: 10040kb

input:

104
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27
28 29 30
31 32 33
34 35 36
37 38 39
40 41 42
43 44 45
46 47 48
49 50 51
52 53 54
55 56 57
58 59 60
61 62 63
64 65 66
67 68 69
70 71 72
73 74 75
76 77 78
79 80 81
82 83 84
85 86 87
88 89 90
91 92 93
94 95 96
97 98 99
100 101 ...

output:

536
35 105
70 35
70 105
1 70
1 70
1 105
70 1
35 1
36 70
36 35
36 1
35 36
70 35
70 36
71 70
71 70
71 36
35 71
70 71
2 35
2 70
2 71
70 2
70 2
37 70
37 70
37 2
35 37
70 37
72 35
72 70
72 37
70 72
70 72
3 70
3 70
3 72
70 3
35 3
38 70
38 35
38 3
35 38
70 35
70 38
73 70
73 70
73 38
35 73
70 73
4 35
4 70
4...

result:

ok correct

Test #25:

score: 0
Accepted
time: 12ms
memory: 10068kb

input:

105
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27
28 29 30
31 32 33
34 35 36
37 38 39
40 41 42
43 44 45
46 47 48
49 50 51
52 53 54
55 56 57
58 59 60
61 62 63
64 65 66
67 68 69
70 71 72
73 74 75
76 77 78
79 80 81
82 83 84
85 86 87
88 89 90
91 92 93
94 95 96
97 98 99
100 101 ...

output:

490
1 106
36 106
71 106
1 36
1 71
2 1
37 1
72 1
2 37
2 72
3 2
38 2
73 2
3 38
3 73
4 3
39 3
74 3
4 39
4 74
5 4
40 4
75 4
5 40
5 75
6 5
41 5
76 5
6 41
6 76
7 6
42 6
77 6
7 42
7 77
8 7
43 7
78 7
8 43
8 78
9 8
44 8
79 8
9 44
9 79
10 9
45 9
80 9
10 45
10 80
11 10
46 10
81 10
11 46
11 81
12 11
47 11
82 11...

result:

ok correct

Test #26:

score: 0
Accepted
time: 5ms
memory: 10044kb

input:

106
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27
28 29 30
31 32 33
34 35 36
37 38 39
40 41 42
43 44 45
46 47 48
49 50 51
52 53 54
55 56 57
58 59 60
61 62 63
64 65 66
67 68 69
70 71 72
73 74 75
76 77 78
79 80 81
82 83 84
85 86 87
88 89 90
91 92 93
94 95 96
97 98 99
100 101 ...

output:

564
71 107
36 71
36 107
1 36
1 36
1 107
36 1
71 1
72 36
72 71
72 1
71 72
36 71
36 72
37 36
37 36
37 72
36 37
71 37
2 36
2 71
2 37
71 2
36 71
36 2
73 36
73 36
73 2
71 73
36 73
38 71
38 36
38 73
36 38
36 38
3 36
3 36
3 38
36 3
71 3
74 36
74 71
74 3
71 74
36 71
36 74
39 36
39 36
39 74
36 39
71 39
4 36
...

result:

ok correct

Test #27:

score: 0
Accepted
time: 12ms
memory: 10164kb

input:

107
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27
28 29 30
31 32 33
34 35 36
37 38 39
40 41 42
43 44 45
46 47 48
49 50 51
52 53 54
55 56 57
58 59 60
61 62 63
64 65 66
67 68 69
70 71 72
73 74 75
76 77 78
79 80 81
82 83 84
85 86 87
88 89 90
91 92 93
94 95 96
97 98 99
100 101 ...

output:

551
36 108
72 36
72 108
1 72
1 72
1 108
72 1
36 1
37 72
37 36
37 1
36 37
72 36
72 37
73 72
73 72
73 37
36 73
72 73
2 36
2 72
2 73
72 2
72 2
38 72
38 72
38 2
36 38
72 38
74 36
74 72
74 38
72 74
72 74
3 72
3 72
3 74
72 3
36 3
39 72
39 36
39 3
36 39
72 36
72 39
75 72
75 72
75 39
36 75
72 75
4 36
4 72
4...

result:

ok correct

Test #28:

score: 0
Accepted
time: 11ms
memory: 10032kb

input:

108
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27
28 29 30
31 32 33
34 35 36
37 38 39
40 41 42
43 44 45
46 47 48
49 50 51
52 53 54
55 56 57
58 59 60
61 62 63
64 65 66
67 68 69
70 71 72
73 74 75
76 77 78
79 80 81
82 83 84
85 86 87
88 89 90
91 92 93
94 95 96
97 98 99
100 101 ...

output:

504
1 109
37 109
73 109
1 37
1 73
2 1
38 1
74 1
2 38
2 74
3 2
39 2
75 2
3 39
3 75
4 3
40 3
76 3
4 40
4 76
5 4
41 4
77 4
5 41
5 77
6 5
42 5
78 5
6 42
6 78
7 6
43 6
79 6
7 43
7 79
8 7
44 7
80 7
8 44
8 80
9 8
45 8
81 8
9 45
9 81
10 9
46 9
82 9
10 46
10 82
11 10
47 10
83 10
11 47
11 83
12 11
48 11
84 11...

result:

ok correct

Test #29:

score: 0
Accepted
time: 11ms
memory: 10060kb

input:

99
56 58 25
72 12 78
42 77 34
5 85 95
94 27 66
15 39 71
20 93 99
48 13 57
37 18 96
18 73 81
22 38 29
91 36 83
68 72 0
21 63 35
8 14 51
76 15 87
67 89 34
55 78 86
10 22 46
31 11 16
54 61 79
87 30 76
4 66 28
53 59 49
43 75 89
2 51 25
97 26 46
1 30 64
37 44 81
65 78 0
60 11 90
58 75 99
67 28 38
79 80 9...

output:

559
13 30
13 73
39 13
73 39
73 13
28 73
28 73
28 13
62 28
53 62
53 28
23 53
23 53
23 28
84 23
59 84
59 23
76 59
76 59
76 23
59 76
81 59
81 76
90 81
90 76
81 90
81 90
44 81
37 44
37 81
15 37
15 37
15 81
45 15
2 45
2 15
36 2
36 2
36 15
90 36
8 90
8 36
96 8
96 8
96 36
37 96
70 96
49 37
49 70
49 96
20 4...

result:

ok correct

Test #30:

score: 0
Accepted
time: 5ms
memory: 10092kb

input:

100
46 58 24
18 45 95
23 53 100
95 49 73
10 30 6
77 84 82
86 93 62
8 55 64
43 68 51
2 39 65
45 16 92
98 40 72
56 22 50
11 53 7
19 75 3
19 80 48
22 15 84
79 88 95
42 6 28
20 33 40
99 15 91
9 97 26
57 31 96
48 38 63
83 21 55
1 90 38
7 44 68
39 85 67
35 86 57
16 60 43
93 48 76
67 75 83
23 60 93
17 66 4...

output:

565
61 96
61 101
15 61
86 15
86 61
66 86
66 86
66 61
78 66
82 66
82 78
82 66
5 82
19 5
19 82
80 19
80 19
80 82
14 80
57 80
27 14
27 57
27 80
87 27
51 87
51 27
8 51
8 51
8 27
101 8
96 8
98 101
98 96
98 8
68 98
59 68
59 98
2 59
2 59
2 98
60 2
25 60
25 2
57 25
57 25
57 2
1 57
64 1
64 57
43 64
43 64
43 ...

result:

ok correct

Test #31:

score: 0
Accepted
time: 5ms
memory: 10064kb

input:

101
76 55 83
14 69 72
23 74 94
12 60 16
25 15 90
90 36 54
80 25 56
28 39 97
47 77 54
18 48 65
19 76 58
31 58 94
8 74 84
48 50 58
41 52 17
44 69 70
78 50 57
89 41 57
34 93 78
46 63 100
85 87 30
12 47 100
7 44 82
42 99 64
3 49 74
79 88 66
72 52 37
38 25 101
2 13 26
13 15 99
22 95 0
6 60 96
77 14 35
55...

output:

574
31 56
31 93
58 31
43 58
43 31
36 43
36 43
36 31
80 36
80 36
94 80
94 80
94 36
102 94
38 102
38 94
32 38
32 38
32 94
78 32
70 78
70 32
76 70
76 70
76 32
80 76
5 80
5 76
30 5
30 76
5 30
5 30
15 5
41 5
99 41
99 5
15 99
15 99
39 15
98 15
10 39
10 98
10 15
37 10
45 37
45 10
3 45
3 45
3 10
68 3
85 68
...

result:

ok correct

Test #32:

score: 0
Accepted
time: 12ms
memory: 10168kb

input:

102
32 51 93
71 58 82
13 25 64
47 50 79
39 64 70
59 3 68
37 43 69
41 54 95
61 87 10
6 86 63
76 96 35
30 66 57
97 75 49
22 58 72
23 91 0
16 14 0
12 82 9
5 40 76
83 76 100
35 46 63
9 23 26
56 70 84
91 5 75
13 13 64
38 87 50
40 34 95
58 44 36
14 94 0
74 11 83
30 68 90
17 89 45
8 28 96
3 46 98
98 41 85
...

output:

570
15 16
15 28
78 15
99 15
98 78
98 99
98 15
88 98
96 88
96 98
52 96
52 96
52 98
99 52
36 99
36 52
17 36
17 36
17 52
67 17
74 67
74 17
43 74
43 74
43 17
100 43
86 100
86 43
45 86
45 86
45 43
28 45
42 45
21 42
21 45
21 28
49 21
90 49
90 21
35 90
35 90
35 21
86 35
3 86
3 35
77 3
77 35
3 77
3 77
73 3
...

result:

ok correct

Test #33:

score: 0
Accepted
time: 6ms
memory: 9992kb

input:

103
52 24 7
3 10 31
23 40 84
6 11 52
101 30 65
6 34 44
5 5 50
54 21 95
76 91 62
62 67 80
19 55 30
55 41 61
25 14 76
77 60 101
53 8 0
3 45 48
17 33 100
83 28 38
36 94 60
59 26 98
8 24 48
33 59 0
1 102 15
97 69 99
27 78 54
84 95 83
34 29 75
103 56 94
75 61 91
90 23 68
79 16 56
18 18 71
3 87 16
12 99 4...

output:

571
15 22
15 88
59 15
53 59
53 15
83 53
83 53
83 15
1 83
65 83
79 1
79 65
79 83
22 79
70 79
21 22
21 70
21 79
58 21
76 21
89 58
89 76
89 21
81 89
99 89
34 81
34 99
34 89
76 34
13 76
13 34
52 13
52 34
13 52
13 52
33 13
31 33
31 13
77 31
77 31
77 13
70 77
36 77
1 36
1 77
1 70
52 1
57 52
57 1
101 57
10...

result:

ok correct

Test #34:

score: -100
Time Limit Exceeded

input:

104
101 15 94
20 103 12
94 68 0
57 64 0
67 46 95
14 67 101
104 70 91
34 37 64
51 95 73
31 40 26
28 4 100
47 90 28
36 44 96
94 104 18
74 61 88
43 60 1
34 76 8
86 13 36
41 53 63
13 44 61
86 15 90
59 71 2
26 93 19
69 46 0
99 8 48
23 88 32
33 69 98
11 7 23
83 95 33
32 48 96
55 7 76
8 63 85
49 78 79
12 1...

output:


result: