// Arup Guha
// 3/22/2015
// Solution to January 14 Bronze USACO Problem: Balanced Teams

import java.util.*;
import java.io.*;

public class Main {

	final public static int COWSPERTEAM = 3;
	final public static int NUMCOWS = 12;
	final public static int NOSOL = 10000000;

	public static void main(String[] args) throws Exception {

		// Read in cow values.
		Scanner stdin = new Scanner(new File("bteams.in"));
		int[] values = new int[NUMCOWS];
		for (int i=0; i<NUMCOWS; i++)
			values[i] = stdin.nextInt();
		stdin.close();

		// Set up and solve recursively.
		int[] teams = new int[NUMCOWS];
		boolean[] used = new boolean[NUMCOWS];
		int cost = recSolve(values, 0, teams, used);

		// Write out the result.
		BufferedWriter fout = new BufferedWriter(new FileWriter("bteams.out"));
		fout.write(cost+"\n");
		fout.close();
	}

	public static int recSolve(int[] values, int k, int[] teams, boolean[] used) {

		// Finished combo.
		if (k == NUMCOWS) return eval(values, teams);

		// To sort teams in order by lowest cow...
		int lowCow = 0;
		if (k > 0 && k%3 > 0) lowCow = teams[k-1]+1;
		else if (k > 0 && k%3 == 0) lowCow = teams[k-3]+1;

		// Try each valid cow in this slot.
		int result = NOSOL;
		for (int i=lowCow; i<NUMCOWS; i++) {
			if (!used[i]) {
				teams[k] = i;
				used[i] = true;
				result = Math.min(result, recSolve(values, k+1, teams, used));
				used[i] = false;
			}
		}
		return result;
	}

	public static int eval(int[] values, int[] teams) {

		// Add up scores of the four teams.
		int[] scores = new int[NUMCOWS/COWSPERTEAM];
		for (int i=0; i<NUMCOWS; i++)
			scores[i/COWSPERTEAM] += values[teams[i]];

		// Now look at the differences of those scores.
		int res = 0;
		for (int i=0; i<scores.length; i++)
			for (int j=i+1; j<scores.length; j++)
				res = Math.max(res, Math.abs(scores[i]-scores[j]));
		return res;
	}
}
