// yukicoder: No.286 Modulo Discount Store // 2019.6.1 bal4u #include #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() // 非負整数の入力 { int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } int m[16]; int dp[1<<15], dc[1<<15]; int calc(int *m, int n) { int i, j, k, t, lim; memset(dc, 0, sizeof(dc)); memset(dp, 0, sizeof(dp)); lim = 1 << n; for (i = 0; i < lim; i++) { t = 0, k = i; for (j = 0; k; j++) if (k & (1< k) dp[t] = k; } } return dp[lim-1]; } int main() { int i, N, a, t, ans; N = in(); for (i = 0; i < N; i++) m[i] = in(); N--, ans = 0x33333333; for (i = 0; i <= N; i++) { t = m[i], m[i] = m[N], m[N] = t; t = calc(m, N); if ((a = m[N] - dc[(1< t) ans = t; t = m[i], m[i] = m[N], m[N] = t; } printf("%d\n", ans); return 0; }