Такси для программистов

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
import java.util.*;
import java.io.*;

public class Main {
    // 1 2 3 4 5
    // 1 4 3 2 5
    // 1 3 2 4 5
    // 1 3 4 2 5
    private void solve() throws IOException {
        int[][] a = new int[5][5];
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                a[i][j] = in.nextInt();
            }
        }
        int sum1 = a[0][1] + a[1][2] + a[2][3] + a[3][4];
        int sum2 = a[0][3] + a[3][2] + a[2][1] + a[1][4];
        int sum3 = a[0][2] + a[2][1] + a[1][3] + a[3][4];
        int sum4 = a[0][2] + a[2][3] + a[3][1] + a[1][4];
        
        int min = Math.min(Math.min(sum1, sum2), Math.min(sum3, sum4));
        if (min == sum1) {
            System.out.println(sum1);
            System.out.println("1 2 3 4 5");
        }
        else if (min == sum2) {
            System.out.println(sum2);
            System.out.println("1 4 3 2 5");
        }
        else if (min == sum3) {
            System.out.println(sum3);
            System.out.println("1 3 2 4 5");
        }
        else {
            System.out.println(sum4);            
            System.out.println("1 3 4 2 5");            
        }
    }

    private String filename = "";
    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException{
        Locale.setDefault(Locale.US);
        new Main().run();
    }
}