1 #include <iostream>
2 #include <cstdio>
3 #include <cstdlib>
4 #include <cstring>
5 #include <algorithm>
6 #define max(a, b) ((a) > (b) ? (a) : (b))
7 #define min(a, b) ((a) < (b) ? (a) : (b))
8
9 inline void read(int &x)
10 {
11 x = 0;char ch = getchar(), c = ch;
12 while(ch < ‘0‘ || ch > ‘9‘)c = ch, ch = getchar();
13 while(ch <= ‘9‘ && ch >= ‘0‘)x = x * 10 + ch - ‘0‘, ch = getchar();
14 if(c == ‘-‘)x = -x;
15 }
16
17 const int MAXN = 1000000 + 10;
18
19 int k, n;
20
21 struct Node
22 {
23 int num,color;
24 }node[MAXN];
25
26 bool cmp(Node a, Node b)
27 {
28 return a.num < b.num;
29 }
30
31 int main()
32 {
33 read(k);
34 if(k < 3)
35 {
36 printf("NIE");
37 return 0;
38 }
39 for(register int i = 1;i <= k;++ i)
40 {
41 int tmp;read(tmp);
42 for(register int j = 1;j <= tmp;++ j)
43 {
44 node[++n].color = i;
45 read(node[n].num);
46 }
47 }
48 std::sort(node + 1, node + 1 + n, cmp);
49 int p1 = n - 1;
50 while(node[p1].color == node[n].color)-- p1;
51 int p2 = p1 - 1;
52 while(node[p2].color == node[p1].color || node[p2].color == node[n].color)-- p2;
53 if(node[p1].num + node[p2].num > node[n].num)
54 {
55 printf("%d %d %d %d %d %d", node[n].color,node[n].num,node[p1].color,node[p1].num,node[p2].color,node[p2].num);
56 return 0;
57 }
58 for(register int i = n - 1;i >= 1;-- i)
59 {
60 while(node[p1].color == node[i].color)-- p1;
61 p2 = min(p1 - 1, p2);
62 while(node[p2].color == node[p1].color || node[p2].color == node[i].color)-- p2;
63 if(p2 < 0 || p1 < 0)break;
64 if(node[p1].num + node[p2].num > node[i].num)
65 {
66 printf("%d %d %d %d %d %d", node[i].color,node[i].num,node[p1].color,node[p1].num,node[p2].color,node[p2].num);
67 return 0;
68 }
69 }
70 printf("NIE");
71 return 0;
72 }