1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 freopen("clocks.in", "r", stdin);
8 freopen("clocks.out", "w", stdout);
9
10 enum { A, B, C, D, E, F, G, H, I };
11
12 int control[9][6] = {
13 {4, A, B, D, E},
14 {3, A, B, C},
15 {4, B, C, E, F},
16 {3, A, D, G},
17 {5, B, D, E, F, H},
18 {3, C, F, I},
19 {4, D, E, G, H},
20 {3, G, H, I},
21 {4, E, F, H, I}
22 };
23
24 int oriClocks[9];
25 int newClocks[9];
26
27 for(int i = 0; i < 9; i++)
28 {
29 cin >> oriClocks[i];
30 switch (oriClocks[i])
31 {
32 case 3 : oriClocks[i] = 1; break;
33 case 6 : oriClocks[i] = 2; break;
34 case 9 : oriClocks[i] = 3; break;
35 case 12 : oriClocks[i] = 0; break;
36 }
37 }
38
39 int x[9], bestx[9], bestLen = 65535;
40 for (x[0] = 0; x[0] < 4; x[0]++)
41 for (x[1] = 0; x[1] < 4; x[1]++)
42 for (x[2] = 0; x[2] < 4; x[2]++)
43 for (x[3] = 0; x[3] < 4; x[3]++)
44 for (x[4] = 0; x[4] < 4; x[4]++)
45 for (x[5] = 0; x[5] < 4; x[5]++)
46 for (x[6] = 0; x[6] < 4; x[6]++)
47 for (x[7] = 0; x[7] < 4; x[7]++)
48 for (x[8] = 0; x[8] < 4; x[8]++)
49 {
50 for (int i = 0; i < 9; i++)
51 newClocks[i] = oriClocks[i];
52 for (int i = 0; i < 9; i++)
53 for (int j = 1; j <= control[i][0]; j++)
54 newClocks[control[i][j]] += x[i];
55 for (int i = 0; i < 9; i++)
56 newClocks[i] %= 4;
57
58 bool allZero = true;
59 for (int i = 0; i < 9; i++)
60 if (newClocks[i] != 0)
61 {
62 allZero = false;
63 break;
64 }
65
66 if (allZero)
67 {
68 int len = 0;
69 for (int i = 0; i < 9; i++)
70 len += x[i];
71 if (len < bestLen)
72 {
73 bestLen = len;
74 for (int i = 0; i < 9; i++)
75 bestx[i] = x[i];
76 }
77 }
78 }
79
80 for (int i = 0, cnt = 0; i < 9; i++)
81 for (int j = 0; j < bestx[i]; j++)
82 {
83 cnt++;
84 cout << i + 1 << (cnt == bestLen ? '\n' : ' ');
85 }
86
87 return 0;
88 }
89