import java.io.* ; public class box { static long sumsq(int x, int y) { return x*(long)x + y*(long)y ; } static long distsquare(int x, int y, int w, int h, int d, int tx, int ty, int tz, int togo) { if (tz == 0) return sumsq(x + tx, y + ty) ; if (togo == 0) return Long.MAX_VALUE ; return Math.min( distsquare(x+w, y, d, h, w, tz, ty, w-tx, togo-1), distsquare(x, y+h, w, d, h, tx, tz, h-ty, togo-1)) ; } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ; while (true) { String[] f = br.readLine().split(" ") ; int w = Integer.parseInt(f[0]) ; int h = Integer.parseInt(f[1]) ; int d = Integer.parseInt(f[2]) ; int x = Integer.parseInt(f[3]) ; int y = Integer.parseInt(f[4]) ; int z = Integer.parseInt(f[5]) ; if (w + h + d == 0) break ; System.out.println(Math.min(Math.min( distsquare(0, 0, w, h, d, x, y, z, 6), distsquare(0, 0, h, d, w, y, z, x, 6)), distsquare(0, 0, d, w, h, z, x, y, 6))) ; } } }