random_device rd;
mt19937 eng(rd());
uniform_int_distribution<int> dist(1, 10);
int n;
int x;
cin >> n >> x;
vector<int> a(n);
for (auto& i : a)
i = dist(eng);
copy(a.cbegin(), a.cend(), ostream_iterator<int>(cout, " "));
cout << '\n';
sort(a.begin(), a.end());
copy(a.cbegin(), a.cend(), ostream_iterator<int>(cout, " "));
cout << '\n';
if (binary_search(a.cbegin(), a.cend(), x)) {
cout << x << " found";
} else {
set<int> temp(a.cbegin(), a.cend());
if (x < *temp.cbegin()) {
cout << *temp.cbegin();
} else if (x > *prev(temp.cend())) {
cout << *prev(temp.cend());
} else {
auto f = lower_bound(a.cbegin(), a.cend(), x);
auto s = upper_bound(a.cbegin(), a.cend(), x);
if (f != a.cend() && s != a.cend()) {
if (abs(*f - x) < abs(*s - x)) {
cout << *f;
} else {
cout << *s;
}
} else if (f == a.cend() && s != a.cend()) {
cout << *s;
} else if (f != a.cend() && s == a.cend()) {
cout << *f;
}
}
}
program Func;
uses Crt;
var a,b: integer;
rez, fa, fb: integer;
begin ;
ClrScr;
a:=4;
b:=-5;
fa:=3*sqr(a)+4*a-5;
fb:=3*sqr(b)+4*b-5;
Rez:=fa+fb;
WriteLn('f(4)=', fa);
WriteLn('f(5)=', fb);
WriteLn('f(4)+f(5)=', Rez);
ReadLn;
end.
,