#include <unistd.h>
#include <iostream>
class Input {
public:
Input() { bufpos = bufend = buffer; eof = false; }
bool Eof() { return eof; }
char Peek() { if(bufpos == bufend) Grab(); return *bufpos; }
unsigned char UPeek() { return static_cast<unsigned char>(Peek()); }
void SkipWS();
template<class T> T Get();
void operator()() {}
template<class Arg, class... Args> void operator()(Arg &arg, Args &... args) {
arg = Get<Arg>();
operator()(args...);
}
private:
static const int BUFSIZE = 1<<16;
char buffer[BUFSIZE];
char *bufpos;
char *bufend;
bool eof;
void Grab();
};
void Input::Grab() {
if(eof) return;
bufpos = buffer;
bufend = buffer + read(0, buffer, BUFSIZE);
if(bufend==bufpos) { eof=true; *bufpos=0; }
}
template<> inline char Input::Get<char>() {
char res = Peek();
++bufpos;
return res;
}
void Input::SkipWS() {
while(isspace(UPeek())) Get<char>();
}
template<> unsigned Input::Get<unsigned>() {
SkipWS();
unsigned x = 0;
while(isdigit(UPeek())) {
x = 10u * x + (Get<char>()-'0');
}
return x;
}
Input IN;
int main() {
unsigned sum = 0;
unsigned smallestOdd = -1u;
unsigned n; IN(n);
for (unsigned i=0;i<n;++i) {
unsigned x; IN(x);
sum += x;
if ((x&1) && x < smallestOdd) smallestOdd = x;
}
if (sum & 1u) sum -= smallestOdd;
if (sum == 0u) {
std::cout << "NIESTETY\n";
} else {
std::cout << sum << '\n';
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <unistd.h> #include <iostream> class Input { public: Input() { bufpos = bufend = buffer; eof = false; } bool Eof() { return eof; } char Peek() { if(bufpos == bufend) Grab(); return *bufpos; } unsigned char UPeek() { return static_cast<unsigned char>(Peek()); } void SkipWS(); template<class T> T Get(); void operator()() {} template<class Arg, class... Args> void operator()(Arg &arg, Args &... args) { arg = Get<Arg>(); operator()(args...); } private: static const int BUFSIZE = 1<<16; char buffer[BUFSIZE]; char *bufpos; char *bufend; bool eof; void Grab(); }; void Input::Grab() { if(eof) return; bufpos = buffer; bufend = buffer + read(0, buffer, BUFSIZE); if(bufend==bufpos) { eof=true; *bufpos=0; } } template<> inline char Input::Get<char>() { char res = Peek(); ++bufpos; return res; } void Input::SkipWS() { while(isspace(UPeek())) Get<char>(); } template<> unsigned Input::Get<unsigned>() { SkipWS(); unsigned x = 0; while(isdigit(UPeek())) { x = 10u * x + (Get<char>()-'0'); } return x; } Input IN; int main() { unsigned sum = 0; unsigned smallestOdd = -1u; unsigned n; IN(n); for (unsigned i=0;i<n;++i) { unsigned x; IN(x); sum += x; if ((x&1) && x < smallestOdd) smallestOdd = x; } if (sum & 1u) sum -= smallestOdd; if (sum == 0u) { std::cout << "NIESTETY\n"; } else { std::cout << sum << '\n'; } } |
English