#include #include #include #include #include #include #include #define MAX 1000000000 using namespace std; int n, k, a[100010]; int b[4]; int flag = 0; void dfs(int a[], int n, int s) { if (flag == 1) return; if (s == 4) { int sum = b[1] + b[2] + b[3]; if (sum % k == 0) { flag = 1; cout << sum << endl; } return; } for (int i = 1; i <= n; i++) { if (a[i] < a[s - 1]) { b[s] = a[i]; dfs(a, n, s + 1); } } } int main() { cin >> n >> k; a[0] = MAX; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1); dfs(a, n, 1); return 0; }