#include //written by Dan volatile int x[100], ix; void swap (int *x, int *y) { char temp; temp = *x; *x = *y; *y = temp; } void permute(int *a, int i, int n) { int j, ii; if (i == n) { x[ix] = a[0] * a[1] + a[2] * a[3]; ix++; for (ii = 0; ii < 4; ii++) { printf("%d ", a[ii]); } printf("\n"); } else { for (j = i; j <= n; j++) { swap((a+i), (a+j)); permute(a, i+1, n); swap((a+i), (a+j)); //backtrack } } } int main() { int v[4], max, i, j; scanf("%d %d %d %d", &v[0], &v[1], &v[2], &v[3]); ix = 0; permute(v, 0, 3); max = 0; for (i = 0; i < ix; i++) { if (x[i] > max) { max = x[i]; } } printf("%d", max); return 0; }