1 #include <cmath>
2 #include <cstdio>
3 #include <cstdlib>
4 #include <cstring>
5 #include <iostream>
6 #include <algorithm>
7
8 #define ri register int
9
10 #define lim 100000000
11
12 char *c = new char[lim];
13
14 template <class T>
15 void read(T &x)
16 {
17 x = 0;
18
19 while (*c < ‘0‘)++c;
20
21 while (*c >= ‘0‘)
22 x = x*10 + *c++ - ‘0‘;
23 }
24
25 #define N 1000005
26 #define inf 2e9 + 7
27
28 int n;
29 int x[N];
30 int y[N];
31 int w[N];
32
33 int ans = inf;
34
35 bool vis[N], use[N];
36
37 void calculate(int lx, int ly, int rx, int ry)
38 {
39 ri res = 0; memset(vis, 0, sizeof(vis));
40
41 #define judge(X, Y) (X >= lx && X <= rx && Y >= ly && Y <= ry)
42
43 for (ri i = 1; i <= n; ++i)
44 {
45 if (judge(x[i], y[i]))
46 continue;
47 if (judge(y[i], x[i]))
48 vis[i] = 1, res += w[i];
49 else return;
50 }
51
52 if (res < ans)
53 ans = res, memcpy(use, vis, sizeof(use));
54 }
55
56 signed main(void)
57 {
58
59 fread(c, 1, lim, stdin);
60
61 read(n);
62
63 for (ri i = 1; i <= n; ++i)
64 read(x[i]), read(y[i]), read(w[i]);
65
66 ri lx, ly, rx, ry;
67
68 lx = ly = inf, rx = ry = 0;
69
70 for (ri i = 1; i <= n; ++i)
71 {
72 if (x[i] < y[i])
73 {
74 if (x[i] < lx)lx = x[i];
75 if (y[i] < ly)ly = y[i];
76 if (x[i] > rx)rx = x[i];
77 if (y[i] > ry)ry = y[i];
78 }
79 else
80 {
81 if (y[i] < lx)lx = y[i];
82 if (x[i] < ly)ly = x[i];
83 if (y[i] > rx)rx = y[i];
84 if (x[i] > ry)ry = x[i];
85 }
86 }
87
88 calculate(lx, ly, rx, ry);
89 calculate(lx, ly, ry, rx);
90 calculate(ly, lx, rx, ry);
91 calculate(ly, lx, ry, rx);
92
93 printf("%lld %d\n", 2LL*(rx + ry - lx - ly), ans);
94
95 for (ri i = 1; i <= n; ++i)putchar(use[i] ? ‘1‘ : ‘0‘);
96 }