solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const int Inf = 1 << 30; const int mod = 1e9 + 7; const int N = 5e5 + 10; int n, a[N]; int main() { while (~scanf("%d", &n)) { memset(a, 0, sizeof(a)); int x, y, t; for (int i = 0; i < n; i++) { scanf("%d %d %d %d", &x, &y, &t, &t); if ((x & 1) && (y & 1)) a[i] = 1; else if ((x & 1) && !(y & 1)) a[i] = 2; else if (!(x & 1) && (y & 1)) a[i] = 3; else a[i] = 4; } puts("YES"); for (int i = 0; i < n; i++) printf("%d\n", a[i]); } return 0; }
6
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math") const long long maxn = 1e6 + 10, maxm = 5e4 + 10, lg = 21, mod = 1e9 + 7, inf = 1e18; string s; long long cc[maxn], t0, las, sig, ff = -1; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> s; for (int i = (long long)(s.size()) - 1; i >= 0; i--) { if (s[i] == '1') { if (ff == -1) ff = t0; for (int j = 0; j <= t0; j++) sig -= cc[j], sig += mod, sig += cc[j] = (las + (j <= ff)) % mod, sig %= mod; t0 = 0, las = sig; } else t0++; } cout << (t0 == (long long)(s.size()) ? t0 : (t0 + 1) * sig % mod); return 0; }
10
#include <iostream> #include <algorithm> #include <vector> #include <string.h> #define int long long using namespace std; int arr[130100]; int psum[130100]; int ppsum[130100]; int pppsum[130100]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N,M; cin >> N>>M; int i; ppsum[0] = 1; psum[0]=psum[1]= 1; arr[0] = 1; int curans = 0; for (i = 2; i <= N; i++) { int li = (i-2) * (i - 1) / 2; int j; int ans = 0; for (j = 2; j <= li; j++) { int cans = 0; int siz = j - 1; if (siz <= i-1) { cans += pppsum[j-2]+(i-siz)*ppsum[j-2]; cans += M * M*3; cans %= M; } else { cans += (pppsum[j - 2]-pppsum[j-i-1]) + (i- siz) * (ppsum[j - 2]-ppsum[j-i-1]); cans += M * M*3; cans %= M; } ans += cans * arr[j] % M; } curans *= i; curans += ans; curans %= M; li += i - 1; for (j = 0; j <= li; j++) { arr[j] = psum[j]; if (j >= i) arr[j] -= psum[j - i]; arr[j] += M; arr[j] %= M; } for (j = 0; j <= li+i; j++) { psum[j] = arr[j]; if (j) psum[j] += psum[j - 1]; psum[j] %= M; } for (j = 0; j <= li+i; j++) { ppsum[j] = psum[j]; if (j) ppsum[j] += ppsum[j - 1]; ppsum[j] %= M; } for (j = 0; j <= li + i; j++) { pppsum[j] = psum[j]*(j); if (j) pppsum[j] += pppsum[j - 1]; ppsum[j] %= M; } } cout << curans; }
9
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 9; int res[MAX_N][2], point[MAX_N], num_s, st[MAX_N * 4], vis[MAX_N]; vector<int> vec[MAX_N]; int N, M, x; bool dfs(int pos, int x) { if (res[pos][x ^ 1] == 1) return false; res[pos][x ^ 1] = 1; st[num_s++] = pos; if (vec[pos].size() == 0 && res[pos][1]) { return true; } for (int i = 0; i < vec[pos].size(); i++) { if (dfs(vec[pos][i], x ^ 1)) return true; } num_s--; return false; } bool cheak(int pos) { vis[pos] = 1; bool f = false; for (int i = 0; i < vec[pos].size(); i++) { if (vis[vec[pos][i]] == 1) f = true; else if (vis[vec[pos][i]] == 0) f = cheak(vec[pos][i]); if (f) return true; } vis[pos] = 2; return false; } int main() { cin >> N >> M; for (int i = 1; i <= N; i++) { int num, temp; scanf("%d", &num); for (int j = 0; j < num; j++) { scanf("%d", &temp); vec[i].push_back(temp); } } int pos; cin >> pos; if (dfs(pos, 1)) { cout << "Win" << endl; for (int i = 0; i < num_s; i++) { printf("%d ", st[i]); } cout << endl; } else if (cheak(pos)) cout << "Draw" << endl; else cout << "Lose" << endl; }
6
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template <class T> bool set_max(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool set_min(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename T> string to_string(T v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } const int N = 2000 * 2000 + 10; const int MOD = 1e9 + 7; const double eps = 1e-6; vector<int> g[N]; vector<int> vis; vector<int> a; vector<ll> dp; ll sum; ll ans; bool dfs(int u, int fa) { bool loop = false; vis[u] = 1; dp[u] = a[u]; for (int v : g[u]) { if (v == fa) continue; if (vis[v]) { loop = true; } else { loop |= dfs(v, u); set_max(dp[u], dp[v] + a[u]); } } if (loop) { sum += a[u]; return true; } else { set_max(ans, dp[u]); return false; } } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int n, m; cin >> n >> m; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vis.assign(n, 0); dp.assign(n, 0); sum = 0; ans = 0; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } int s; cin >> s; s--; dfs(s, -1); cout << ans + sum << endl; }
7
#include <bits/stdc++.h> using namespace std; int main() { int t, xa, ya, xb, yb, xf, yf; scanf("%d",&t); while(t--) { int ans = 0; scanf("%d%d%d%d%d%d",&xa, &ya, &xb, &yb, &xf, &yf); if(xa == xb){ if(xa == xf && (yf < ya && yf > yb || yf > ya && yf < yb)) ans += 2; ans += abs(yb - ya); } else if(ya == yb){ if(ya == yf && (xf < xa && xf > xb || xf > xa && xf < xb)) ans += 2; ans += abs(xb - xa); } else ans += (abs(xb - xa)) + (abs(yb - ya)); printf("%d\n",ans); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int t, n, a[1000], k; int main() { cin >> t; while(t--) { cin >> n >> k; if(k <= (n - 1)/2) { int spt = 0, spt1 = k + 1; for(int i = 1; i <= 2*k + 1; i++) { if(i%2 == 1) a[i] = ++spt; else a[i] = ++spt1; } for(int i = 2*k + 2; i <= n; ++i) a[i] = ++spt1; for(int i = 1; i <= n; ++i) cout << a[i] << " "; cout << "\n"; } else cout << -1 << "\n"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1000002; int n, m, l, r, p, q, t, k, ans, sum, tot, cnt, a[N], b[N], yoy; inline int read() { register int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * f; } int main() { n = read(); for (int i = 1; i <= n; i++) { a[i] = read(); } t = a[2] - a[1]; int flag = 1; for (int i = 3; i <= n; i++) { if (a[i] - a[i - 1] != t) { flag = 0; printf("%d\n", a[n]); return 0; } } if (flag == 1) { printf("%d\n", a[n] + t); } else { printf("%d\n", a[n]); } return 0; }
1
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; Point(long long a = 0.0, long long b = 0.0) { x = a; y = b; } Point operator+(const Point& a) const { return Point(x + a.x, y + a.y); } Point operator-(const Point& a) const { return Point(x - a.x, y - a.y); } Point operator*(const long long& a) const { return Point(x * a, y * a); } Point operator/(const long long& a) const { return Point(x / a, y / a); } long long operator*(const Point& a) const { return x * a.y - y * a.x; } double operator/(const Point& a) const { return sqrt((a.x - x) * (a.x - x) + (a.y - y) * (a.y - y)); } long long operator%(const Point& a) const { return x * a.x + y * a.y; } bool operator==(const Point& a) const { return a.x == x && a.y == y; } } lib[5000]; int main() { int n, m; scanf("%d%d", &n, &m); double ans = 0; Point p[6], fin[6]; p[0] = Point(0, 0); p[1] = Point(n, m); int c = 0; for (int i = 0; i <= n; i++) lib[c++] = Point(i, 0); for (int i = 1; i <= m; i++) lib[c++] = Point(n, i); for (int i = n - 1; i >= 0; i--) lib[c++] = Point(i, m); for (int i = m - 1; i > 0; i--) lib[c++] = Point(0, i); for (int i = 0; i < c; i++) for (int j = 0; j < c; j++) { int g = 0; p[2] = lib[i]; p[3] = lib[j]; if (p[3] == p[0]) g = 1; if (p[3] == p[1]) g = 1; if (p[2] == p[0]) g = 1; if (p[2] == p[1]) g = 1; if (p[3] == p[2]) g = 1; if (g == 0) { double t = 0; t = (p[0] / p[1]) + (p[1] / p[2]) + (p[2] / p[3]); if (t > ans) { ans = t; fin[0] = p[0]; fin[1] = p[1]; fin[2] = p[2]; fin[3] = p[3]; } t = (p[0] / p[1]) + (p[1] / p[2]) + (p[0] / p[3]); if (t > ans) { ans = t; fin[0] = p[2]; fin[1] = p[1]; fin[2] = p[0]; fin[3] = p[3]; } t = (p[0] / p[1]) + (p[1] / p[3]) + (p[0] / p[2]); if (t > ans) { ans = t; fin[0] = p[3]; fin[1] = p[1]; fin[2] = p[0]; fin[3] = p[2]; } } } for (int i = 0; i < 4; i++) printf("%I64d %I64d\n", fin[i].x, fin[i].y); return 0; }
5
#include <bits/stdc++.h> using namespace std; namespace FF { template <class T> struct is_iterator { template <class U, typename enable_if<!is_convertible<U, const char*>::value, int>::type = 0> constexpr static auto has_indirection(int) -> decltype(*declval<U>(), bool()) { return true; } template <class> constexpr static bool has_indirection(long) { return false; } constexpr static bool value = has_indirection<T>(0); }; using uint = unsigned int; const uint BUFFER_SIZE = 1 << 12; const uint MAX_LENGTH = 1 << 7; namespace Detail { struct Width { uint value; }; struct Fill { char value; }; struct Base { uint value; }; struct Precision { uint value; }; struct Delimiter { const char* value; }; } // namespace Detail Detail::Width setWidth(uint value = 0) { return {value}; } Detail::Fill setFill(char value = ' ') { return {value}; } Detail::Base setBase(uint value = 10) { assert(2 <= value && value <= 36); return {value}; } Detail::Precision setPrecision(uint value = 9) { assert(value < MAX_LENGTH); return {value}; } Detail::Delimiter setDelimiter(const char* value = " ") { return {value}; } class InputDevice { protected: const char* head; const char* tail; InputDevice(const char* head_, const char* tail_) : head(head_), tail(tail_), base(setBase().value) {} virtual void fillInput() = 0; inline char nextChar() { if (__builtin_expect(head >= tail, false)) fillInput(); return *head++; } template <class I> int readUnsignedIntGeneral(I& arg, char c) { I value = 0; int length = 0; for (;; ++length, c = nextChar()) { if (isDigit(c)) c -= '0'; else if (isUpper(c)) c -= 'A' - 10; else if (isLower(c)) c -= 'a' - 10; else c = base; if (c >= base) break; value = base * value + c; } arg = value; return --head, length; } template <class I> inline int readUnsignedInt(I& arg, char c) { if (__builtin_expect(base > 10, false)) return readUnsignedIntGeneral(arg, c); I value = 0; int length = 0; for (; static_cast<unsigned char>(c - '0') < base; ++length, c = nextChar()) value = base * value + c - '0'; arg = value; return --head, length; } template <class I> inline bool readSignedInt(I& arg, char c) { bool negative = c == '-'; if (negative) c = nextChar(); typename make_unsigned<I>::type unsignedArg; if (readUnsignedInt(unsignedArg, c) == 0) return false; arg = negative ? ~static_cast<I>(unsignedArg - 1) : static_cast<I>(unsignedArg); return true; } template <class F> bool readFloatingPoint(F& arg, char c) { bool negative = c == '-'; if (negative) c = nextChar(); unsigned long long integerPart; if (readUnsignedInt(integerPart, c) == 0) return false; arg = static_cast<F>(integerPart); if (nextChar() == '.') { unsigned long long fractionalPart = 0; int fractionalLength = readUnsignedInt(fractionalPart, nextChar()); if (fractionalLength > 0) { unsigned long long basePower = 1; for (; fractionalLength; --fractionalLength) basePower *= base; arg += static_cast<F>(fractionalPart) / basePower; } } else --head; if (negative) arg = -arg; return true; } public: uint base; InputDevice(InputDevice const&) = delete; InputDevice& operator=(InputDevice const&) = delete; static inline bool isSpace(char c) { return static_cast<unsigned char>(c - '\t') < 5 || c == ' '; } static inline bool isDigit(char c) { return static_cast<unsigned char>(c - '0') < 10; } static inline bool isUpper(char c) { return static_cast<unsigned char>(c - 'A') < 26; } static inline bool isLower(char c) { return static_cast<unsigned char>(c - 'a') < 26; } static inline bool isOneOf(char c, const char* str) { return strchr(str, c) != nullptr; } void putBack() { --head; } inline bool readChar(char& arg) { if (__builtin_expect(head >= tail, false)) { fillInput(); if (__builtin_expect(head >= tail, false)) return arg = '\0', false; } return arg = *head++, true; } template <class UnaryPredicate> inline char skipCharacters(UnaryPredicate isSkipped) { char c; do { c = nextChar(); } while (isSkipped(c)); return c; } inline char skipCharacters() { return skipCharacters(isSpace); } template <class UnaryPredicate> inline int readString(char* arg, int limit, UnaryPredicate isTerminator) { skipCharacters(isTerminator); int charsRead = 0; for (--head, --limit; head < tail; fillInput()) { ptrdiff_t chunkSize = find_if(head, min(tail, head + limit - charsRead), isTerminator) - head; arg = copy_n(head, chunkSize, arg); head += chunkSize; charsRead += chunkSize; if (chunkSize == 0 || head < tail) break; } return *arg = '\0', charsRead; } inline int readString(char* arg, int limit, const char* terminators) { if (!*terminators) return readString(arg, limit, InputDevice::isSpace); return readString(arg, limit, [terminators](char c) { return InputDevice::isOneOf(c, terminators); }); } inline bool read(Detail::Base newBase) { base = newBase.value; return true; } inline bool read() { return true; } inline bool read(char& arg) { return readChar(arg); } template <class I> inline typename enable_if<is_integral<I>::value && is_unsigned<I>::value, bool>::type read(I& arg) { return readUnsignedInt(arg, skipCharacters()) > 0; } template <class I> inline typename enable_if<is_integral<I>::value && is_signed<I>::value, bool>::type read(I& arg) { return readSignedInt(arg, skipCharacters()); } template <class F> inline typename enable_if<is_floating_point<F>::value, bool>::type read( F& arg) { return readFloatingPoint(arg, skipCharacters()); } inline bool read(const char& arg) { skipCharacters([arg](char c) { return arg != c; }); return true; } inline bool read(const char* arg) { if (*arg) skipCharacters([arg](char c) { return InputDevice::isOneOf(c, arg); }); else skipCharacters(); return putBack(), true; } inline bool read(bool (*isSkipped)(char)) { skipCharacters(isSkipped); putBack(); return true; } template <class I, class Terminator, class... Ts> inline typename enable_if<is_integral<I>::value, bool>::type read( char* arg, I limit, Terminator terminator, Ts&&... args) { readString(arg, static_cast<int>(limit), terminator); return read(forward<Ts>(args)...); } template <class I> inline typename enable_if<is_integral<I>::value, bool>::type read(char* arg, I limit) { return read(arg, limit, ""); } template <class... Ts> inline bool read(char* first, char* last, Ts&&... args) { return read(first, static_cast<int>(last - first), forward<Ts>(args)...); } template <int N, class... Ts> inline bool read(char (&arg)[N], Ts&&... args) { return read(static_cast<char*>(arg), N, forward<Ts>(args)...); } template <class Terminator, class... Ts> inline bool read(string& arg, Terminator terminator, Ts&&... args) { for (int length = 16, last = 0;; last += length, length <<= 1) { arg.resize(last + length); int charsRead = readString(&arg[last], length + 1, terminator); if (charsRead < length) { arg.resize(last + charsRead); return read(forward<Ts>(args)...); } } } inline bool read(string& arg) { return read(arg, ""); } template <class T1, class T2> inline bool read(pair<T1, T2>& arg) { return read(arg.first, arg.second); } template <class T> inline bool read(complex<T>& arg) { T real, imag; if (!read(real, imag)) return false; arg.real(real), arg.imag(imag); return true; } template <class T> inline bool read(vector<T>& arg) { uint n; if (!read(n)) return false; arg.resize(n); return read(arg.begin(), arg.end()); } template <class Iterator, class... Ts> inline typename enable_if<is_iterator<Iterator>::value, bool>::type read( Iterator first, Iterator last, Ts&&... args) { for (; first != last; ++first) if (!read(*first)) return false; return read(forward<Ts>(args)...); } template <class Iterator, class I, class... Ts> inline typename enable_if<is_iterator<Iterator>::value && is_integral<I>::value, bool>::type read(Iterator first, I count, Ts&&... args) { return read(first, first + count, forward<Ts>(args)...); } template <class T> inline auto read(T& arg) -> decltype(arg.read(*this)) { return arg.read(*this); } template <class T0, class T1, class... Ts> inline typename enable_if< !is_iterator<T0>::value && !is_convertible<T0, char*>::value, bool>::type read(T0&& arg0, T1&& arg1, Ts&&... args) { return read(forward<T0>(arg0)) && read(forward<T1>(arg1), forward<Ts>(args)...); } }; class InputFile : public InputDevice { FILE* file; bool lineBuffered; bool owner; char buffer[BUFFER_SIZE]; void fillInput() override { head = buffer; *buffer = '\0'; if (__builtin_expect(!lineBuffered, true)) { tail = head + fread(buffer, 1, BUFFER_SIZE, file); } else { tail = head; if (fgets(buffer, BUFFER_SIZE, file)) while (*tail) ++tail; } } public: InputFile(FILE* file_ = stdin, bool lineBuffered_ = true, bool takeOwnership = false) : InputDevice(buffer, buffer), file(file_), lineBuffered(lineBuffered_), owner(takeOwnership) {} InputFile(const char* fileName) : InputFile(fopen(fileName, "r"), false, true) {} ~InputFile() { if (owner) fclose(file); } }; class InputString : public InputDevice { void fillInput() override { while (*tail) ++tail; } public: InputString(const string& s) : InputDevice(s.data(), s.data() + s.size()) {} InputString(const char* s) : InputDevice(s, s + strlen(s)) {} }; class OutputDevice { protected: char buffer[BUFFER_SIZE + MAX_LENGTH]; char* output; char* end; bool separate; OutputDevice() : output(buffer), end(buffer + BUFFER_SIZE + MAX_LENGTH), separate(false), width(setWidth().value), fill(setFill().value), base(setBase().value), precision(setPrecision().value), delimiter(setDelimiter().value) { computeBasePower(); } virtual void writeToDevice(uint count) = 0; inline void flushMaybe() { if (__builtin_expect(output >= buffer + BUFFER_SIZE, false)) { writeToDevice(BUFFER_SIZE); output = copy(buffer + BUFFER_SIZE, output, buffer); } } void computeBasePower() { basePower = 1; for (uint i = 0; i < precision; ++i) basePower *= base; } template <class I> inline char* writeUnsignedInt(I arg, char* last) { if (__builtin_expect(arg == 0, false)) *--last = '0'; if (__builtin_expect(base == 10, true)) { for (; arg; arg /= 10) *--last = '0' + arg % 10; } else for (; arg; arg /= base) { I digit = arg % base; *--last = digit < 10 ? '0' + digit : 'A' - 10 + digit; } return last; } template <class I> inline char* writeSignedInt(I arg, char* last) { auto unsignedArg = static_cast<typename make_unsigned<I>::type>(arg); if (arg < 0) { last = writeUnsignedInt(~unsignedArg + 1, last); *--last = '-'; return last; } return writeUnsignedInt(unsignedArg, last); } template <class F> char* writeFloatingPoint(F arg, char* last) { bool negative = signbit(arg); if (negative) arg = -arg; if (isnan(arg)) for (int i = 0; i < 3; ++i) *--last = i["NaN"]; else if (isinf(arg)) for (int i = 0; i < 3; ++i) *--last = i["fnI"]; else { auto integerPart = static_cast<unsigned long long>(arg); auto fractionalPart = static_cast<unsigned long long>( (arg - integerPart) * basePower + F(0.5)); if (fractionalPart >= basePower) ++integerPart, fractionalPart = 0; char* point = last - precision; if (precision > 0) { ::fill(point, writeUnsignedInt(fractionalPart, last), '0'); *--point = '.'; } last = writeUnsignedInt(integerPart, point); } if (negative) *--last = '-'; return last; } inline int writeT(char* first) { int delimiterLenght = separate ? writeDelimiter() : 0; separate = true; uint charsWritten = static_cast<uint>(end - first); if (__builtin_expect(charsWritten < width, false)) charsWritten += writeFill(width - charsWritten); output = copy(first, end, output); flushMaybe(); return delimiterLenght + static_cast<int>(charsWritten); } inline int writeFill(uint count) { int charsWritten = static_cast<int>(count); if (__builtin_expect(output + count + MAX_LENGTH < end, true)) { if (count == 1) *output++ = fill; else output = fill_n(output, count, fill); } else for (uint chunkSize = static_cast<uint>(buffer + BUFFER_SIZE - output);; chunkSize = BUFFER_SIZE) { if (chunkSize > count) chunkSize = count; output = fill_n(output, chunkSize, fill); flushMaybe(); if ((count -= chunkSize) == 0) break; } return charsWritten; } public: uint width; char fill; uint base; uint precision; unsigned long long basePower; string delimiter; OutputDevice(OutputDevice const&) = delete; OutputDevice& operator=(OutputDevice const&) = delete; virtual ~OutputDevice(){}; inline int writeChar(char arg) { separate = false; *output++ = arg; flushMaybe(); return 1; } inline int writeString(const char* arg, size_t length, bool checkWidth = true) { separate = false; uint count = static_cast<uint>(length); int charsWritten = static_cast<int>(count) + (checkWidth && count < width ? writeFill(width - count) : 0); if (__builtin_expect(output + count + MAX_LENGTH < end, true)) { if (count == 1) *output++ = *arg; else output = copy_n(arg, count, output); } else for (uint chunkSize = static_cast<uint>(buffer + BUFFER_SIZE - output);; chunkSize = BUFFER_SIZE) { if (chunkSize > count) chunkSize = count; output = copy_n(arg, chunkSize, output); flushMaybe(); if ((count -= chunkSize) == 0) break; arg += chunkSize; } return charsWritten; } inline int writeDelimiter() { return writeString(delimiter.c_str(), delimiter.size(), false); } inline void flush() { writeToDevice(static_cast<uint>(output - buffer)); output = buffer; } inline int write(Detail::Width newWidth) { width = newWidth.value; return 0; } inline int write(Detail::Fill newFill) { fill = newFill.value; return 0; } inline int write(Detail::Base newBase) { base = newBase.value; computeBasePower(); return 0; } inline int write(Detail::Precision newPrecision) { precision = newPrecision.value; computeBasePower(); return 0; } inline int write(Detail::Delimiter newDelimiter) { delimiter = newDelimiter.value; return 0; } inline int write() { return 0; } inline int write(char arg) { return writeChar(arg); } template <class I> inline typename enable_if<is_integral<I>::value && is_unsigned<I>::value, int>::type write(I arg) { return writeT(writeUnsignedInt(arg, end)); } template <class I> inline typename enable_if<is_integral<I>::value && is_signed<I>::value, int>::type write(I arg) { return writeT(writeSignedInt(arg, end)); } template <class F> inline typename enable_if<is_floating_point<F>::value, int>::type write( F arg) { return writeT(writeFloatingPoint(arg, end)); } inline int write(const char* arg) { return writeString(arg, strlen(arg)); } template <int N> inline int write(char (&arg)[N]) { return writeString(arg, strlen(arg)); } inline int write(const string& arg) { return writeString(arg.c_str(), arg.size()); } template <class T1, class T2> inline int write(const pair<T1, T2>& arg) { int charsWritten = write(arg.first); charsWritten += writeDelimiter(); return charsWritten + write(arg.second); } template <class T> inline int write(const complex<T>& arg) { return write(real(arg), imag(arg)); } template <class Iterator, class... Ts> inline typename enable_if<is_iterator<Iterator>::value, int>::type write( Iterator first, Iterator last, Ts&&... args) { int charsWritten = 0; for (; first != last; charsWritten += ++first == last ? 0 : writeDelimiter()) charsWritten += write(*first); return charsWritten + write(forward<Ts>(args)...); } template <class Iterator, class I, class... Ts> inline typename enable_if<is_iterator<Iterator>::value && is_integral<I>::value, int>::type write(Iterator first, I count, Ts&&... args) { return write(first, first + count, forward<Ts>(args)...); } template <class T> inline auto write(const T& arg) -> decltype(arg.write(*this)) { return arg.write(*this); } template <class T0, class T1, class... Ts> inline typename enable_if<!is_iterator<T0>::value, int>::type write( T0&& arg0, T1&& arg1, Ts&&... args) { int charsWritten = write(forward<T0>(arg0)); return charsWritten + write(forward<T1>(arg1), forward<Ts>(args)...); } }; class OutputFile : public OutputDevice { FILE* file; bool owner; void writeToDevice(uint count) override { fwrite(buffer, 1, count, file); fflush(file); } public: OutputFile(FILE* file_ = stdout, bool takeOwnership = false) : file(file_), owner(takeOwnership) {} OutputFile(const char* fileName) : OutputFile(fopen(fileName, "w"), true) {} ~OutputFile() override { flush(); if (owner) fclose(file); } }; class OutputString : public OutputDevice { string& str; void writeToDevice(uint count) override { str.append(buffer, count); } public: OutputString(string& str_) : OutputDevice(), str(str_) {} ~OutputString() override { flush(); } }; unique_ptr<InputDevice> input; unique_ptr<OutputDevice> output; template <class... Ts> inline bool read(Ts&&... args) { return input->read(forward<Ts>(args)...); } template <class... Ts> inline int write(Ts&&... args) { return output->write(forward<Ts>(args)...); } template <class... Ts> inline int writeln(Ts&&... args) { return write(forward<Ts>(args)..., '\n'); } void flush() { output->flush(); } } // namespace FF using namespace FF; pair<long long, long long> operator-(const pair<long long, long long>& a, const pair<long long, long long>& b) { return pair<long long, long long>(a.first - b.first, a.second - b.second); } pair<long long, long long> operator+(const pair<long long, long long>& a, const pair<long long, long long>& b) { return pair<long long, long long>(a.first + b.first, a.second + b.second); } bool inside(const long long& b1, const long long& x, const long long& b2) { return (min(b1, b2) <= x && x <= max(b1, b2)); } bool inline lies_on( const pair<long long, long long>& p, const pair<pair<long long, long long>, pair<long long, long long> >& t) { pair<long long, long long> v1 = p - t.first; pair<long long, long long> v2 = t.second - p; return (v1.first * v2.second == v1.second * v2.first && inside(t.first.first, p.first, t.second.first) && inside(t.first.second, p.second, t.second.second)); } bool inline check_angle( const pair<pair<long long, long long>, pair<long long, long long> >& t1, const pair<pair<long long, long long>, pair<long long, long long> >& t2) { pair<long long, long long> v1 = t1.second - t1.first; pair<long long, long long> v2 = t2.second - t2.first; return (0 <= v1.first * v2.first + v1.second * v2.second && v1.first * v2.second != v1.second * v2.first); } long long inline length(const pair<long long, long long>& p) { return (p.first * p.first + p.second * p.second); } bool inline test_partion( const pair<pair<long long, long long>, pair<long long, long long> >& t, const pair<long long, long long>& p) { long long AB = length(p - t.first); long long BC = length(t.second - p); return (16 * AB >= BC && 16 * BC >= AB); } void solve() { int T; read(T); while (T--) { pair<long long, long long> a[6]; read(a, 6); pair<pair<long long, long long>, pair<long long, long long> > aa[3]; map<pair<long long, long long>, int> m; for (int i = 0; i < 3; i++) { aa[i] = pair<pair<long long, long long>, pair<long long, long long> >( a[i * 2], a[i * 2 + 1]); m[aa[i].first]++; m[aa[i].second]++; } int doubles = 0, ones = 0; pair<long long, long long> peak; for (const pair<pair<long long, long long>, int>& p : m) { doubles += (p.second == 2); ones += (p.second == 1); if (p.second == 2) { peak = p.first; } } if (doubles != 1 || ones != 4) { writeln("NO"); continue; } for (int i = 0; i < 3; i++) if (aa[i].second == peak) swap(aa[i].first, aa[i].second); for (int i = 0; i < 2; i++) if (aa[i].first != peak) swap(aa[i], aa[2]); pair<long long, long long> dash1 = aa[2].first, dash2 = aa[2].second; if (!lies_on(dash1, aa[0])) swap(dash1, dash2); if (!lies_on(dash1, aa[0]) || !lies_on(dash2, aa[1])) { writeln("NO"); continue; } if (!check_angle(aa[0], aa[1])) { writeln("NO"); continue; } if (!test_partion(aa[0], dash1) || !test_partion(aa[1], dash2)) { writeln("NO"); continue; } writeln("YES"); } } int main() { if (1) { input.reset(new InputFile(stdin, false)); output.reset(new OutputFile()); } else { input.reset(new InputFile("input.txt")); output.reset(new OutputFile()); } solve(); return 0; }
6
#include <bits/stdc++.h> using namespace std; constexpr int MODC = 998244353; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long l1, r1, l2, r2; cin >> l1 >> r1 >> l2 >> r2; if (l1 > l2) { swap(l1, l2); swap(r1, r2); } long long intersect = max(0ll, min(r1, r2) - l2); if (intersect * n >= k) { cout << 0 << '\n'; } else { long long improvement = (max(r1, r2) - l1) - intersect; long long improvereq = l2 - l1 + abs(r2 - r1); long long ans = 2147483648; for (int i = 1; i <= n; ++i) { if (intersect * n + improvement * i > k) { ans = min(ans, i * improvereq - (intersect * n + improvement * i - k)); break; } else { ans = min(ans, i * improvereq + (k - intersect * n - improvement * i) * 2); } } cout << ans << '\n'; } } return 0; }
6
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; void itval(istream_iterator<string> it) {} template <typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; itval(++it, args...); } const long long int MOD = 1e9 + 7; template <typename T> inline void print(T x) { cout << x << "\n"; } template <typename T> inline void printvec(T x) { for (auto a : x) cout << a << ' '; cout << '\n'; } struct custom { bool operator()( const pair<pair<long long int, long long int>, long long int> &p1, const pair<pair<long long int, long long int>, long long int> &p2) const { return p1.second > p2.second; } }; long long int get_pow(long long int a, long long int b, long long int M = MOD) { long long int res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b >>= 1; } return res; } const long long int N = 1e5 + 5, inf = 1e18; int sparse_mat_min[N][21], sparse_mat_max[N][21]; int log_value[N]; void compute_sparse() { log_value[1] = 0; for (int i = 2; i < N; i++) { log_value[i] = log_value[i / 2] + 1; } for (int j = 1; j < 21; j++) { for (long long int i = 0; i + (1ll << j) < N; i++) { sparse_mat_min[i][j] = min(sparse_mat_min[i][j - 1], sparse_mat_min[i + (1ll << (j - 1))][j - 1]); sparse_mat_max[i][j] = max(sparse_mat_max[i][j - 1], sparse_mat_max[i + (1ll << (j - 1))][j - 1]); } } } inline int query(int L, int R) { int j = log_value[R - L + 1]; int x = min(sparse_mat_min[L][j], sparse_mat_min[R - (1 << j) + 1][j]); return max(sparse_mat_max[L][j], sparse_mat_max[R - (1 << j) + 1][j]) - x; } void solve() { int n, x, k; cin >> n >> k; for (long long int i = (long long int)0; i < (long long int)(n); i++) { cin >> sparse_mat_min[i][0]; sparse_mat_max[i][0] = sparse_mat_min[i][0]; } compute_sparse(); vector<long long> ans[n + 5]; for (long long int i = (long long int)0; i < (long long int)(n); i++) { int lo = i, hi = n, m; while (lo + 1 < hi) { m = (lo + hi) >> 1; if (query(i, m) <= k) lo = m; else hi = m; } ans[lo - i + 1].push_back(i); } for (int j = n + 2; j >= 0; j--) { if (!ans[j].empty()) { cout << j << ' ' << ans[j].size() << '\n'; for (auto p : ans[j]) { cout << p + 1 << ' ' << p + j << '\n'; } return; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int test = 1; clock_t z = clock(); for (long long int tes = (long long int)0; tes < (long long int)(test); tes++) { solve(); } fprintf(stderr, "Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC), fflush(stderr); return 0; }
5
#include <bits/stdc++.h> using namespace std; int main(void) { int n, max = 0; string a[100]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { int count = 0; for (int j = 0; j < n; j++) { if (i != j) { if (a[i].compare(a[j]) == 0) count++; } } if (count > max) max = count; } cout << max + 1; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int temp, in, count = 0; long int n; cin >> n; cin >> temp; n = n - 1; count += temp + 1; while (n != 0) { cin >> in; if (in >= temp) { count += 2 + (in - temp); } else { count += 2 + (temp - in); } temp = in; n--; } cout << count; return 0; }
1
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long timesum = 0, time = 0; vector<long long> a1; for (long long i = 0; i < n; i++) { if (a[i] == -1) continue; if (i == 0) { if (a[i + 1] == -1) a1.push_back(i); } else if (i == n - 1) { if (a[i - 1] == -1) a1.push_back(i); } else { if (a[i - 1] == -1 || a[i + 1] == -1) a1.push_back(i); } } if (a1.size() == 0) { cout << 0 << " " << 1 << endl; continue; } for (long long i = 0; i < a1.size(); i++) timesum += a[a1[i]]; double k = timesum; double n1 = a1.size(); k /= n1; long long x = k + 0.5; long long ans1 = x; long long ans = 0; for (long long i = 0; i < n; i++) { if (a[i] == -1) continue; if (i == 0) { if (a[i + 1] != -1) ans = max(ans, abs(a[i] - a[i + 1])); } else if (i == n - 1) { if (a[i - 1] != -1) ans = max(ans, abs(a[i - 1] - a[i])); } else { if (a[i - 1] != -1) ans = max(ans, a[i] - a[i - 1]); if (a[i + 1] != -1) ans = max(ans, abs(a[i] - a[i + 1])); } } long long max1 = INT_MIN; long long min1 = INT_MAX; for (long long i = 0; i < a1.size(); i++) { long long y = a[a1[i]]; min1 = min(min1, y); max1 = max(max1, y); } long long r = min1 + max1; r /= 2; for (long long i = 0; i < n; i++) { if (a[i] == -1) a[i] = r; } for (long long i = 1; i < n; i++) { ans = max(ans, abs(a[i] - a[i - 1])); } cout << ans << " " << r << endl; } }
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; int read() { int x; scanf("%d", &x); return x; } int main() { int n = read(), sa = 0, ca = 0, sb = 0, cb = 0; for (int i = 0; i < int(n); ++i) { int t, x, y; scanf("%d%d%d", &t, &x, &y); if (t == 1) { sa += x; ca += y; } else { sb += x; cb += y; } } if (sa >= ca) cout << "LIVE"; else cout << "DEAD"; cout << endl; if (sb >= cb) cout << "LIVE"; else cout << "DEAD"; return 0; }
0
#include <bits/stdc++.h> long long Cnt[100005], Num[100005]; int main() { int n, k, m, a; scanf("%d %d %d", &n, &k, &m); int len = 0; while (n--) { scanf("%d", &a); if (len == 0 || Num[len] != a) { Num[++len] = a; Cnt[len] = 1; } else Cnt[len]++; if (Cnt[len] == k) len--; } int head = 1, tail = len; long long S1 = 0, S2 = 0; for (int i = 1; i <= len; i++) S1 += Cnt[i]; while (head < tail && Num[head] == Num[tail]) { if ((Cnt[head] + Cnt[tail]) % k == 0) { head++; tail--; } else { Cnt[head] = (Cnt[head] + Cnt[tail]) % k; tail--; break; } } for (int i = head; i <= tail; i++) S2 += Cnt[i]; long long ans = 0; if (head < tail) ans = S1 + S2 * (m - 1); else if ((Cnt[head] * m) % k != 0) ans = S1 + (Cnt[head] * m) % k - Cnt[head]; printf("%lld\n", ans); }
7
#include <bits/stdc++.h> const long long int mod = 1000000007; const long long int MOD1 = (int)1e9 + 9; const long long int MOD2 = 998244353; const long double pi = atan2(0, -1); const long double eps = 1e-9; const int N = 1e6 + 7; const int MAXR = 1000005; long long int tests = 1; using namespace std; int binarySearch(int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); return binarySearch(arr, mid + 1, r, x); } return l; } bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } void swap(long long int *p1, long long int *p2) { long long int temp = *p1; *p1 = *p2; *p2 = temp; } long long int cbratt(long long int x) { long long int l = 0, r = MAXR; while (l != r) { long long int m = (l + r + 1) / 2; if (m * m * m > x) r = m - 1; else l = m; } return l; } int findn(int num) { return (int)log10(num) + 1; } void printLDS(vector<int> &Max) { reverse(Max.begin(), Max.end()); for (auto &it : Max) { cout << it << ' '; } } void LongestDividingSeq(int arr[], int N, int n) { vector<vector<int> > LDS(N); LDS[0].push_back(arr[0]); for (int i = 1; i < N; i++) { for (int j = 0; j < i; j++) { if ((arr[i] % arr[j] == 0) && (LDS[i].size() < LDS[j].size() + 1)) LDS[i] = LDS[j]; } LDS[i].push_back(arr[i]); } int maxLength = 0; for (int i = 0; i < N; i++) { int x = LDS[i].size(); maxLength = max(maxLength, x); } for (int i = 0; i < N; i++) { int size = LDS[i].size(); if (size == maxLength && LDS[i][LDS[i].size() - 1] == n) { printLDS(LDS[i]); cout << '\t'; } } } int sumOfDigits(long long n) { long long sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return sum; } long long countDigits(long long num, long long limit) { long long left = 1, right = num, result = 0; while (left <= right) { long long mid = (right + left) / 2; if ((mid - sumOfDigits(mid)) >= limit) { result = num - mid + 1; right = mid - 1; } else { left = mid + 1; } } return result; } int main() { vector<long long int> v; long long int n, l; cin >> n >> l; cout << countDigits(n, l); }
4
#include <bits/stdc++.h> using namespace std; int N, M, T[111]; int main() { cin >> N >> M; for (int i = 0, L, R; i < M; i++) { cin >> L >> R; for (int j = L; j <= R; j++) T[j]++; } for (int i = 1; i <= N; i++) if (T[i] == 0 || T[i] > 1) { cout << i << " " << T[i] << endl; return 0; } cout << "OK" << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; const long long int N = 1e6 + 10; vector<long long int> a(N); vector<long long int> BIT(N); map<long long int, long long int> mp; long long int n; void init() { for (auto &x : BIT) x = 0; } void update(long long int x, long long int val) { for (; x < N; x += x & -x) { BIT[x] += val; } } long long int query(long long int x) { long long int sum = 0; for (; x > 0; x -= x & -x) sum += BIT[x]; return sum; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n; vector<long long int> b; for (long long int i = 0; i < n; i++) { cin >> a[i]; b.push_back(a[i]); } sort(b.begin(), b.end()); long long int val = 2; for (auto x : b) { if (!mp[x]) { mp[x] = val; val++; } } vector<long long int> v1(n), v2(n); for (long long int i = n - 1; i >= 0; i--) { long long int x = mp[a[i]]; v1[i] = query(x - 1); update(x, 1); } init(); for (long long int i = 0; i < n; i++) { long long int x = mp[a[i]]; v2[i] = query(val) - query(x - 1); update(x, 1); } long long int ans = 0; for (long long int i = 0; i < n; i++) ans = ans + v1[i] * v2[i]; cout << ans << endl; }
5
#include <bits/stdc++.h> using namespace std; string a, b, r; int cnta[26], cntr[26]; void dfs(int k) { for (int i = 0; i < 26; i++) if (cnta[i] > 0 && 'a' + i > b[k]) { r.assign(b, 0, k); r.push_back('a' + i); cnta[i]--; memcpy(cntr, cnta, sizeof(cnta)); cnta[i]++; break; } if (cnta[b[k] - 'a'] > 0) { cnta[b[k] - 'a']--; dfs(k + 1); } } int main() { cin >> a >> b; for (int i = 0; i < a.size(); i++) cnta[a[i] - 'a']++; dfs(0); if (r.size()) { for (int i = 0; i < 26; i++) while (cntr[i]-- > 0) r.push_back('a' + i); cout << r << endl; } else cout << -1 << endl; return 0; }
5
#include <bits/stdc++.h> using namespace std; int l[100010 + 5], r[100010 + 5], u[100010 + 5], s[100010 + 5]; vector<int> vec; vector<int> pool[100010 + 5], ask_pool[100010 + 5]; struct segtree { set<int> s[100010 * 4 + 5]; void chg(int i, int l, int r, int ql, int qr, int x) { if (ql <= l && r <= qr) { if (x > 0) s[i].insert(x); else s[i].erase(-x); return; } if (r < ql || qr < l) return; int mid = (l + r) >> 1; chg(i * 2, l, mid, ql, qr, x); chg(i * 2 + 1, mid + 1, r, ql, qr, x); } int ask(int i, int l, int r, int p) { int res = 0; if (s[i].size()) res = max(res, *s[i].rbegin()); if (l == r) return res; int mid = (l + r) >> 1; if (p <= mid) res = max(res, ask(i * 2, l, mid, p)); else res = max(res, ask(i * 2 + 1, mid + 1, r, p)); return res; } } T; map<int, int> id; map<pair<int, int>, int> nxt, dp; int h, w, n; int dfs(int x, int y) { if (dp.find(make_pair(x, y)) != dp.end()) return dp[make_pair(x, y)]; int i = nxt[make_pair(x, y)], ans = 0; if (i == 0) return dp[make_pair(x, y)] = 1; if (l[i] == 1) ans = (ans + dfs(r[i] + 1, u[i])) % 1000000007; else ans = (ans + dfs(l[i] - 1, u[i])) % 1000000007; if (r[i] != w) ans = (ans + dfs(r[i] + 1, u[i])) % 1000000007; else ans = (ans + dfs(l[i] - 1, u[i])) % 1000000007; return dp[make_pair(x, y)] = ans; } int main() { scanf("%d%d%d", &h, &w, &n); for (int i = 1; i <= n; i++) scanf("%d%d%d%d", &u[i], &l[i], &r[i], &s[i]); vec.push_back(h + 1); for (int i = 1; i <= n; i++) vec.push_back(u[i]); sort(vec.begin(), vec.end()); int N = vec.size(); for (int i = 1; i <= n; i++) id[u[i]] = i; for (int i = 1; i <= n; i++) pool[l[i]].push_back(i), pool[r[i] + 1].push_back(-i); for (int i = 1; i <= w; i++) ask_pool[i].push_back(h + 1); for (int i = 1; i <= n; i++) { if (l[i] != 1) ask_pool[l[i] - 1].push_back(u[i]); if (r[i] != w) ask_pool[r[i] + 1].push_back(u[i]); } for (int x = 1; x <= w; x++) { for (auto it : pool[x]) { int i = abs(it), sgn = it > 0 ? 1 : -1; int y1 = lower_bound(vec.begin(), vec.end(), u[i] + 1) - vec.begin() + 1; int y2 = upper_bound(vec.begin(), vec.end(), u[i] + s[i]) - vec.begin(); T.chg(1, 1, N, y1, y2, sgn * u[i]); } for (auto y : ask_pool[x]) { int yid = lower_bound(vec.begin(), vec.end(), y) - vec.begin() + 1; int r = T.ask(1, 1, N, yid); nxt[make_pair(x, y)] = id[r]; } } int ans = 0; for (int x = 1; x <= w; x++) ans = (ans + dfs(x, h + 1)) % 1000000007; printf("%d\n", ans); return 0; }
9
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; } bool f[n]; memset(f, 0, sizeof(f)); int cnt = 0; string ans = ""; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j && !f[i] && !f[j]) { string t = s[i]; reverse((t).begin(), (t).end()); if (t == s[j]) { cnt++; f[i] = 1; f[j] = 1; ans = ans.substr(0, ans.size() / 2) + s[i] + s[j] + ans.substr(ans.size() / 2, ans.size() / 2); } } } } for (int i = 0; i < n; i++) { if (!f[i]) { string t = s[i]; reverse((t).begin(), (t).end()); if (t == s[i]) { ans = ans.substr(0, ans.size() / 2) + s[i] + ans.substr(ans.size() / 2, ans.size() / 2); break; } } } cout << ans.size() << endl << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF_LL = 1e18 + 3; const int INF_int = 1e9 + 3; int main() { int t; cin >> t; int ans[t]; for (int ii = 0; ii < t; ii++) { int n; long long x; cin >> n >> x; vector<long long> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end(), greater<long long>()); int now = -1; long long now_money = 0LL; long long min_wealth = 0LL; for (int i = 0; i < n; i++) { if (now_money < min_wealth) break; else { now_money += a[i]; min_wealth += x; now++; } } if (now_money >= min_wealth) now++; ans[ii] = now; } for (int i = 0; i < t; i++) cout << ans[i] << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; string s,s1,s2,s3,s4; while(t--) { cin >> s; s1=s+"a"; s3=s1; s2="a"+s; s4=s2; reverse(s4.begin(),s4.end()); reverse(s3.begin(),s3.end()); if( s1.compare(s3)!=0) { cout << "YES" << endl; cout << s1 << endl; } else if(s2.compare(s4)!=0) { cout << "YES" << endl; cout << s2 << endl; } else cout << "NO" << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; struct segtree { int64_t n; vector<int64_t> tree; void build(int64_t N) { n = 1; while (n < N) n <<= 1; tree.resize(2 * n); } void set(int64_t i, int64_t v, int64_t x, int64_t lx, int64_t rx) { if (lx == rx) { tree[x] = v; } else { int64_t m = (lx + rx) / 2; if (i <= m) set(i, v, 2 * x, lx, m); else set(i, v, 2 * x + 1, m + 1, rx); tree[x] = max(tree[2 * x], tree[2 * x + 1]); } } void set(int64_t i, int64_t v) { set(i + 1, v, 1, 1, n); } int64_t rmq(int64_t l, int64_t r, int64_t x, int64_t lx, int64_t rx) { if (rx < l || lx > r) return 0; if (l <= lx && rx <= r) return tree[x]; int64_t m = (lx + rx) / 2; return max(rmq(l, r, 2 * x, lx, m), rmq(l, r, 2 * x + 1, m + 1, rx)); } int64_t rmq(int64_t l, int64_t r) { return rmq(l + 1, r + 1, 1, 1, n); } }; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int64_t n, m, k; cin >> n >> m >> k; vector<vector<int64_t>> a(m, vector<int64_t>(n)); for (int64_t i = 0; i < n; i++) { for (int64_t j = 0; j < m; j++) { cin >> a[j][i]; } } vector<segtree> tree(m); for (int64_t i = 0; i < m; i++) { tree[i].build(n); for (int64_t j = 0; j < n; j++) { tree[i].set(j, a[i][j]); } } int64_t l = 0, r = 0; int64_t ans = 0; vector<int64_t> res(m); while (r < n) { if (l > r) r = l; while (r < n) { int64_t ns = 0; for (int64_t i = 0; i < m; i++) { ns += tree[i].rmq(l, r); } if (ns > k) { r--; break; } r++; } if (r - l + 1 > ans) { ans = r - l + 1; for (int64_t i = 0; i < m; i++) { res[i] = tree[i].rmq(l, r); } } l++; } for (int64_t i = 0; i < m; i++) { cout << res[i] << " "; } }
6
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long INF64 = 1e18; const int INF32 = 1e9; template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size(); i++) os << (i ? " " : "") << v[i]; os << '\n'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { for (int i = 0; i < v.size(); i++) os << v[i]; os << '\n'; return os; } void solve(); void precalc(); int main() { precalc(); solve(); return 0; } void precalc() {} void solve() { int n, m, k; scanf("%d %d %d", &n, &m, &k); vector<int> a(n), mx(m), mxv(m); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) { int sc; scanf("%d", &sc); if (a[i] > mxv[sc - 1]) { mxv[sc - 1] = a[i]; mx[sc - 1] = i; } } int r = 0; cerr << mx; for (int i = 0; i < k; i++) { int ss; scanf("%d", &ss); for (int j = 0; j < m; j++) if (mx[j] == ss - 1) { r++; break; } } printf("%d", k - r); }
1
#include <bits/stdc++.h> using namespace std; long long int n, k, x = 0; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k; if (k >= n / 2 + n % 2) { cout << -1; return 0; } cout << n * k << endl; for (int i = 1; i <= n; i++) { x = i; for (int j = 1; j <= k; j++) { x++; if (x > n) x = 1; cout << i << ' ' << x << '\n'; } } return 0; }
3
#include <bits/stdc++.h> int main() { int a, n, m; while (std::cin >> a >> n >> m) { std::vector<bool> rain(a + 1); std::vector<int> l(n), r(n); for (int i = 0; i < n; ++i) std::cin >> l[i] >> r[i]; for (int i = 0; i < n; ++i) { for (int j = l[i]; j <= r[i]; ++j) { rain[j] = true; } } std::vector<int> umbrella(a + 1, INT_MAX); for (int i = 0; i < m; ++i) { int a, p; std::cin >> a >> p; umbrella[a] = std::min(umbrella[a], p); } std::vector<int64_t> dp(a + 1, INT_MAX); for (int i = 0; i <= a; ++i) { dp[i] = 0; if (rain[i]) break; }; for (int i = 0; i <= a; ++i) { bool check = false; for (int j = 0; j < n; ++j) { if (l[j] < i and i <= r[j]) check = true; } for (int j = 0; j <= i; ++j) { if (umbrella[j] != INT_MAX) dp[i] = std::min(dp[i], dp[j] + (int64_t)umbrella[j] * (i - j)); } if (not check) { if (i > 0) dp[i] = std::min(dp[i], dp[i - 1]); } }; if (dp[a] == INT_MAX) { std::cout << -1 << "\n"; } else { std::cout << dp[a] << "\n"; } } return 0; }
6
#include <bits/stdc++.h> using namespace std; long long gcdex(long long a, long long b, long long& x, long long& y, long long qax = 1, long long qay = 0, long long qbx = 0, long long qby = 0) { if (b == 0) { x = qax; y = qay; return a; } long long q = a / b; return gcdex(b, a % b, x, y, qbx, qby, qax - q * qbx, qay - q * qby); } long long inv(long long a, long long m) { long long x, y; assert(gcdex(a, m, x, y) == 1); return ((x % m) + m) % m; } const int N = 100010; vector<pair<int, int>> adj[N]; int size[N], mark[N], bc[N]; vector<int> dist[N], s1[N], s2[N]; ; int dfs(int u, int p = -1) { size[u] = 1; bc[u] = 0; for (auto& e : adj[u]) { int v = e.first; if (v == p || mark[v]) continue; size[u] += dfs(v, u); if (!bc[u] || size[v] > size[bc[u]]) bc[u] = v; } return size[u]; } int M; int pot[N]; void prep(int u, int p = -1, int d = 0, int e1 = 0, int e2 = 0) { dist[u].push_back(d); s1[u].push_back(e1); s2[u].push_back(e2); for (auto& e : adj[u]) { int v = e.first; if (v == p || mark[v]) continue; prep(v, u, d + 1, (10ll * e1 + e.second) % M, (1ll * pot[d] * e.second + e2) % M); } } unordered_map<int, int> mais[N], menos[N]; int pr[N]; int decomp(int u) { dfs(u); int c = u; while (bc[c] && 2 * size[bc[c]] > size[u]) c = bc[c]; mark[c] = 1; prep(c); for (auto& e : adj[c]) { int v = e.first; if (mark[v]) continue; pr[decomp(v)] = c; } return c; } void add(int u, int dt) { for (int i = 0, x = u, last = 0; i < dist[u].size(); i++, x = pr[last = x]) { mais[x][s2[u][i]] += dt; if (last) menos[last][s2[u][i]] += dt; } } int inv_pot[N]; int query(int u) { int res = 0; for (int i = 0, x = u, last = 0; i < dist[u].size(); i++, x = pr[last = x]) { int a = M - s1[u][i]; int b = (1ll * inv_pot[dist[u][i]] * a) % M; res += mais[x][b]; if (last) res -= menos[last][b]; } return res; } int main() { int n; scanf("%d%d", &n, &M); pot[0] = inv_pot[0] = 1; for (int i = 1; i < n; i++) { pot[i] = (10ll * pot[i - 1]) % M; inv_pot[i] = inv(pot[i], M); } for (int i = 1; i < n; i++) { int u, v, w; scanf("%d%d%d", &u, &v, &w); u++, v++; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } decomp(1); for (int i = 1; i <= n; i++) { reverse(begin(dist[i]), end(dist[i])); reverse(begin(s1[i]), end(s1[i])); reverse(begin(s2[i]), end(s2[i])); } long long ans = 0; for (int i = 1; i <= n; i++) { ans += query(i); add(i, 1); } for (int i = 1; i <= n; i++) add(i, -1); for (int i = n; i >= 1; i--) { ans += query(i); add(i, 1); } printf("%lld\n", ans); return 0; }
9
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1005; long long dp[maxn][maxn]; long long a, b; int k; long long quickpow(long long a, long long b, long long mod) { long long ans = 1; while (b) { if (b & 1) { ans = (ans * a) % mod; } a = (a * a) % mod; b = b >> 1; } return ans; } long long cal(int a, int b) { if (b >= k) return b; else return dp[a][b]; } int main() { cin >> k >> a >> b; long long pa = 1ll * (a * quickpow(a + b, mod - 2, mod)) % mod; long long pb = 1ll * (b * quickpow(a + b, mod - 2, mod)) % mod; for (int i = 0; i < k; i++) { dp[k][i] = (k + i + a * quickpow(b, mod - 2, mod)) % mod; } for (int i = k - 1; i >= 1; i--) { for (int j = k; j >= 0; j--) { dp[i][j] = ((pa * dp[i + 1][j]) % mod + (pb * cal(i, i + j)) % mod) % mod; } } cout << dp[1][0] << endl; }
7
#include <bits/stdc++.h> int a, b, n, l, t, m, r, mr; long long sl, sr, sum, mx; void fnd(int, int); int main() { scanf("%d%d%d", &a, &b, &n); for (int i = 0; i < n; i++) { r = 0; scanf("%d%d%d", &l, &t, &m); mr = ((t - a) / b) + 2; sl = a + (long long)b * (l - 1); if (sl > t) { printf("-1\n"); continue; } fnd(l, 1000005); printf("%d\n", r); } return 0; } void fnd(int x, int y) { if (y < x) return; int k = (x + y) / 2; sr = a + (long long)b * (k - 1); sum = ((long long)(k - l + 1) * (sl + sr)) / 2; if (sr <= t && sum <= (long long)t * m) { r = std::max(r, k); fnd((x + y) / 2 + 1, y); } else fnd(x, (x + y) / 2 - 1); }
5
#include <bits/stdc++.h> using namespace std; template <class X, class Y> bool minimize(X &x, const Y &y) { X eps = 1e-9; if (x > y + eps) { x = y; return true; } else return false; } template <class X, class Y> bool maximize(X &x, const Y &y) { X eps = 1e-9; if (x + eps < y) { x = y; return true; } else return false; } template <class T> T Abs(const T &x) { return (x < 0 ? -x : x); } int a[200200], last[200200], n; void init(void) { int q; scanf("%d%d", &n, &q); for (int i = (1), _b = (n); i <= _b; i++) scanf("%d", &a[i]); } int countGroup(int l, int r) { map<int, int> cnt; for (int i = (l), _b = (r); i <= _b; i++) cnt[a[i]]++; int maxCnt = 0; for (__typeof((cnt).begin()) it = (cnt).begin(); it != (cnt).end(); it++) maximize(maxCnt, it->second); return r - l + 1 - maxCnt; } int findNext(int l) { int r = last[l]; int i = l; while (i <= r) { maximize(r, last[i]); i++; } return r; } void process(void) { map<int, int> lastPos; for (int i = (1), _b = (n); i <= _b; i++) lastPos[a[i]] = i; for (int i = (1), _b = (n); i <= _b; i++) last[i] = lastPos[a[i]]; int res = 0; int i = 0; while (i < n) { int l = i + 1; int r = findNext(l); res += countGroup(l, r); i = r; } cout << res << endl; } int main(void) { init(); process(); return 0; }
6
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; const int N = 100010; int t, n, m; int a[N]; struct node { int x; double y; }b[N]; int main() { scanf("%d", &t); while (t -- ) { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]); for (int i = 1; i <= m; i ++ ) scanf("%d %lf", &b[i].x, &b[i].y); int tag = 0; for (int i = 2; i <= n; i ++ ) if (a[i] != i) tag = i; double ans = 0.0; if (tag == 0) ans = 1, printf("%f\n", ans); else { for (int i = 1; i <= m; i ++ ) if (b[i].x >= tag) ans = ans + (1 - ans) * b[i].y; printf("%f\n", ans); } } return 0; }
3
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; int main() { int n; cin >> n; long long a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; long long dp[n + 2]; dp[1] = 0; for (int i = 2; i <= n + 1; i++) { dp[i] = 2 * dp[i - 1] + 2 - dp[a[i - 1]]; dp[i] %= mod; } cout << (dp[n + 1] + mod) % mod; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int x, y, flag, r; cin >> x >> y; if (x * y > 0) flag = 0; else flag = 1; r = (int)(sqrt(1. * x * x + 1. * y * y) + 0.000000001); flag += r % 2; if (flag % 2 == 0 || r * r == x * x + y * y) cout << "black" << endl; else cout << "white" << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const long long mod = 1e9 + 7; const int MAXN = 1e6 + 7; void solve(); signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } void solve() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); vector<int> st; for (int i = 0; i < n; i++) { while (st.size() != 0 && a[i] - st.back() <= k && st.back() < a[i]) { st.pop_back(); } st.push_back(a[i]); } cout << st.size(); return; }
2
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 3e5 + 10; int maxv[N]; int parent[N]; int son[N]; vector<int> v[N]; int ans[N]; int q[N]; void dfs1(int u) { maxv[u] = 0; son[u] = 1; int maxson = 0; for (auto x : v[u]) { dfs1(x); maxv[u] = max(maxv[u], maxv[x] + 1); maxson = max(maxson, son[x]); son[u] += son[x]; } if (v[u].size() == 0) { ans[u] = u; return; } if (maxson * 2 <= son[u]) { ans[u] = u; return; } int ret = -1; for (auto x : v[u]) { int t = ans[x]; do { int y = max(maxv[t], son[u] - son[t]); if (y * 2 <= son[u]) { ret = t; break; } t = parent[t]; } while (t != u); if (ret != -1) break; } ans[u] = ret; } int main() { int n, m; memset((ans), (0), sizeof(ans)); scanf("%d%d", &n, &m); for (int i = 2; i <= n; i++) { int x; scanf("%d", &x); v[x].push_back(i); parent[i] = x; } dfs1(1); while (m--) { int x; scanf("%d", &x); printf("%d\n", ans[x]); } return 0; }
5
#include <bits/stdc++.h> using namespace std; const long long int MAXN = 1e6 + 1; std::vector<pair<long long int, pair<long long int, long long int>>> v; signed main() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; long long int n, m, q, i; cin >> n >> q >> m; long long int a[n + 1]; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 0; i < q; i++) { long long int t, l, r; cin >> t >> l >> r; v.push_back(make_pair(t, make_pair(l, r))); } while (m--) { long long int x; cin >> x; long long int ans = x; for (i = q - 1; i >= 0; i--) { long long int t = v[i].first; long long int l = v[i].second.first; long long int r = v[i].second.second; if (l <= ans && ans <= r) { if (t == 1) { if (ans == l) { ans = r; } else { ans = ans - 1; } } else { ans = l + r - ans; } } } cout << a[ans] << " "; } }
5
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int t; cin >> t; while (t--) { int n; cin >> n; ll sum = 0; vector<vector<ll>> dp(n); vector<ll> v(n); for (ll i = 0; i < n; ++i) { cin >> v[i]; sum += v[i] * ((i + 1) % 2); dp[i].push_back(0); dp[i].push_back(0); } if (n == 1) { cout << sum << endl; } else { dp[1][1] = max(dp[1][1], -v[0] + v[1]); dp[1][0] = max(dp[0][0], dp[1][1]); for (int i = 2; i < n; ++i) { if (i % 2 == 0) { dp[i][1] = max(dp[i - 2][1] - v[i] + v[i - 1], dp[i][1]); dp[i][0] = max(dp[i - 1][0], dp[i][1]); } else { dp[i][1] = max(dp[i - 2][1] + v[i] - v[i - 1], dp[i][1]); dp[i][0] = max(dp[i - 1][0], dp[i][1]); } } cout << dp[n - 1][0] + sum << endl; } dp.clear(); v.clear(); } }
4
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; const long long mod = 1e9 + 7; const long long inf = 1e18; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long powm(long long base, long long exp) { long long ans = 1; while (exp) { if (exp & 1) ans = (ans * base) % mod; exp >>= 1, base = (base * base) % mod; } return ans; } long long inv(long long n) { long long ans = powm(n, mod - 2); return ans; } long long add(long long a, long long b) { return (a % mod + b % mod) % mod; } long long sub(long long a, long long b) { return (a % mod + mod - b % mod) % mod; } long long mult(long long a, long long b) { return ((a % mod) * (b % mod)) % mod; } long long choose2(long long n) { long long ans = (n * (n - 1)) / 2; return ans; } long long dist2(long long x1, long long y1, long long x2, long long y2) { long long ans = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long r; cin >> r; long long maxi = 1e7; long long ans; for (long long x = 1; x < maxi + 1; x++) { long long sub = (x * x + x + 1); long long t = r; t -= sub; if (t % (2 * x) == 0 && (t > 0)) { ans = (t / (2 * x)); cout << x << " " << ans; return 0; } } cout << "NO"; return 0; }
2
#include <bits/stdc++.h> using namespace std; long long n, q, x, y, taille; long long solve(long long x, long long y) { if (n % 2 == 0) { if ((x + y) % 2 == 0) return (((taille / 2) / n) * x) - ((n - y) / 2); return (taille / 2) + ((((taille / 2) + 1) + 1) / n) * x - ((n - y) / 2); } int nb = (taille / (n / 2 + ((n / 2) + 1))); if ((x + y) % 2 == 0) { if (x % 2 == 0) return ((x / 2) * nb) - (n - 1 - y) / 2; return ((x / 2) + 1) * nb - (n / 2) - ((n - y) / 2); } if (x % 2 == 0) return ((x / 2) * nb) + (taille / 2) + 1 - ((n - y) / 2); return ((x / 2) + 1) * nb + (taille / 2) + 1 - ((n / 2) + 1) - (n - 1 - y) / 2; } int main() { cin >> n >> q; if (n == 2) { while (q--) { cin >> x >> y; if (x == 1 && y == 1) { cout << 1 << "\n"; continue; } if (x == 1 && y == 2) { cout << 3 << "\n"; continue; } if (x == 2 && y == 1) { cout << 4 << "\n"; continue; } if (x == 2 && y == 2) { cout << 2 << "\n"; continue; } } return 0; } taille = n * n; while (q--) { cin >> x >> y; cout << solve(x, y) << "\n"; } return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n < 11 || n > 21) cout << "0\n"; else if (n == 20) cout << "15\n"; else cout << "4\n"; }
0
#include <bits/stdc++.h> int lowbit(int x) { return x & -x; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int m; std::cin >> m; std::vector<int> x1(m), y1(m), x2(m), y2(m); std::vector<std::pair<int, int>> s{{0, 0}}; auto work = [&](int a, int b) { while (a > 0 || b > 0) { s.emplace_back(a, b); if (b == 0 || (a > 0 && lowbit(a) < lowbit(b))) { s.emplace_back(a - 1, b); a ^= lowbit(a); } else { s.emplace_back(a, b - 1); b ^= lowbit(b); } } }; for (int i = 0; i < m; ++i) { int a, b, c, d; std::cin >> a >> b >> c >> d; x1[i] = a, y1[i] = b; x2[i] = c, y2[i] = d; work(a, b); work(c, d); } std::sort(s.begin(), s.end()); s.erase(std::unique(s.begin(), s.end()), s.end()); auto getId = [&](int x, int y) { return std::lower_bound(s.begin(), s.end(), std::make_pair(x, y)) - s.begin(); }; int n = s.size(); std::vector<int> gx(n), gy(n); for (int i = 0; i < n; ++i) gx[i] = gy[i] = i; std::vector<int> parent(n, -1), dep(n), h(n, -1), type(n, -1); for (int i = 1; i < n; ++i) { auto [x, y] = s[i]; dep[i] = x + y; type[i] = (y == 0 || (x > 0 && lowbit(x) < lowbit(y))) ? 0 : 1; while ((x > 0 || y > 0) && (y == 0 || (x > 0 && lowbit(x) < lowbit(y)) ? 0 : 1) == type[i]) { if (type[i] == 0) { x ^= lowbit(x); } else { y ^= lowbit(y); } } h[i] = getId(x, y); if (type[i] == 0) { parent[i] = gx[h[i]]; gx[h[i]] = i; } else { parent[i] = gy[h[i]]; gy[h[i]] = i; } } auto lca = [&](int u, int v) { while (h[u] != h[v]) { if (h[v] == -1 || (h[u] >= 0 && dep[h[u]] > dep[h[v]])) u = h[u]; else v = h[v]; } if (type[u] == type[v]) { return dep[u] < dep[v] ? u : v; } else { return h[u]; } }; std::vector<int> a(n); for (int i = 0; i < m; ++i) { int u = getId(x1[i], y1[i]); int v = getId(x2[i], y2[i]); ++a[u], ++a[v]; int l = lca(u, v); --a[l]; if (l > 0) --a[parent[l]]; } for (int i = n - 1; i > 0; --i) a[parent[i]] += a[i]; for (int i = 0; i < n; ++i) a[i] = a[i] > 0; for (int i = 1; i < n; ++i) a[parent[i]] ^= a[i]; std::vector<int> v; for (int i = 0; i < n; ++i) if (a[i]) v.push_back(dep[i]); int ans = 0; std::sort(v.begin(), v.end()); for (int l = 0; l < int(v.size());) { int r = l; while (r < int(v.size()) && v[l] == v[r]) ++r; if ((r - l) % 2 == 1) ++ans; l = r; } std::cout << ans << "\n"; return 0; }
13
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ int n,m,l; cin>>n; vector<int> x(n); if(n%2 != 0){ for(int i=0;i<n;i=i+2){ cin>>m; x[i]=m; } for(int i=n-2;i>=1;i=i-2){ cin>>l; x[i]=l; } } else{ for(int i=0;i<n;i=i+2){ cin>>m; x[i]=m; } for(int i=n-1;i>=1;i=i-2){ cin>>l; x[i]=l; } } for(int i=0;i<n;i++){ cout<<x[i]<<" "; } cout<<"\n"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long q; cin >> q; while (q--) { long n, r; cin >> n >> r; set<long, greater<long> > s; for (long i = 1; i <= n; i++) { long x; cin >> x; s.insert(x); } long long c = 0, d = 0; set<long, greater<long> >::iterator itr; for (itr = s.begin(); itr != s.end(); itr++) { if ((*itr) - d > 0) { c++; d += r; } } cout << c << "\n"; } }
2
#include <bits/stdc++.h> using namespace std; int n; string tmp; map<string, vector<vector<string> > > m; int main() { if (n == 62) return 0; cin >> n; for (int i = (int)(0); i < (int)(n); i++) { cin >> tmp; getline(cin, tmp); bool flag = false; string name; vector<string> v; for (int j = (int)(0); j < (int)(tmp.length()); j++) { string s; while (j < tmp.length() && ((tmp[j] >= 'a' && tmp[j] <= 'z') || (tmp[j] >= '0' && tmp[j] <= '9') || tmp[j] == 'T')) { s += tmp[j++]; } if (!s.empty()) { if (flag) v.push_back(s); else { name = s; flag = true; } } } m[name].push_back(v); } int V; cin >> V; map<string, string> v; for (int i = (int)(0); i < (int)(V); i++) { string type, name; cin >> type >> name; v[name] = type; } int k; scanf("%i\n", &k); for (int i = (int)(0); i < (int)(k); i++) { getline(cin, tmp); string name; int j = 0; while (tmp[j] != '(') { if (tmp[j] != ' ') name += tmp[j]; j++; } vector<string> a; while (j < tmp.length()) { string s; while (j < tmp.length() && ((tmp[j] >= 'a' && tmp[j] <= 'z') || (tmp[j] >= '0' && tmp[j] <= '9') || tmp[j] == 'T')) { s += tmp[j++]; } if (!s.empty()) { a.push_back(v[s]); } j++; } int ans = 0; for (int k = (int)(0); k < (int)(m[name].size()); k++) { bool eq = true; if (a.size() != m[name][k].size()) continue; for (int j = (int)(0); j < (int)(a.size()); j++) { if (a[j] != m[name][k][j] && m[name][k][j] != "T") { eq = false; break; } } if (eq) ans++; } cout << ans << endl; } return 0; }
5
#include <bits/stdc++.h> using namespace std; using II = pair<int, int>; signed main() { int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); vector<int> b; for (int i = 0; i < m; i++) { int x1, x2, y; cin >> x1 >> x2 >> y; if (x1 > 1) continue; b.push_back(x2); } sort(b.begin(), b.end()); int ans = n + m; a.push_back(1e9); m = b.size(); for (int i = 0; i <= n; i++) { int pos = lower_bound(b.begin(), b.end(), a[i]) - b.begin(); ans = min(ans, m + i - pos); } cout << ans << "\n"; }
4
#include <bits/stdc++.h> using namespace std; vector<int> va, vo, vi; bool cmp(int i, int j) { return va[i] < va[j]; } int main() { int cases, n, a, o, len; cin >> cases; while (cases-- != 0) { cin >> n; len = 2 * n - 1; if (va.size() < len) { va.reserve(len); vo.reserve(len); vi.reserve(len); } for (int i = 0; i < len; ++i) { cin >> a >> o; va[i] = a; vo[i] = o; vi[i] = i; } ::sort(vi.begin(), vi.begin() + len, cmp); cout << "YES" << endl; for (int i = 0; i < len - 1; i += 2) { if (vo[vi[i]] > vo[vi[i + 1]]) cout << (vi[i] + 1) << " "; else cout << (vi[i + 1] + 1) << " "; } cout << (vi[len - 1] + 1) << endl; } return 0; }
8
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll,ll> pll; #define F first #define S second #define PB push_back #define MP make_pair #define all(x) x.begin(),x.end() #define foru(i, a, b) for(ll i=a; i < (b) ; i++) #define fore(i, a, b) for(ll i=a ; i <= (b); i++) const ll mod = 1e9+7, N = 2e6+7, M = 2e6+7, INF = INT_MAX/10; ll power(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;} ll str_to_int(string s){stringstream asteya(s); ll x=0; asteya>>x; return x;} string int_to_str(ll n){return to_string(n);} void testcase(){ ll a,b,ans,moves,sub; cin>>a>>b; if(a==0 and b==0) cout<<0<<" "<<0<<endl; else{ ans = abs(a-b); if(ans == 0) sub=0; else sub = min(a,b)%ans; if(ans > 0 && ans !=1) moves = min(sub, (ans-(a%ans))%ans); else moves = 0; cout<<ans<<" "<<moves<<endl; } } int main(){ fast; int t=1; cin >> t; while(t--){ testcase(); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; cin.ignore(); while (t--) { string s, s1; getline(cin, s); int n = s.size(), i, j, f; for (i = 0; i < n; i++) { if (s[i] == '0') { break; } } for (j = 0; j < s.size(); j++) { if (s[j] == '1') { break; } } if (i == n || j == n) cout << s << endl; else { if (s[0] == '1') { for (int i = 0; i < n; i++) { s1 += "10"; } } else { for (int i = 0; i < n; i++) { s1 += "01"; } } cout << s1 << endl; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; int a[2013]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) { int ans = 0; for (int j = 0; j < n; j++) if (a[j] > a[i]) ans += 1; printf("%d ", ans + 1); } printf("\n"); return 0; }
0
#include <bits/stdc++.h> using namespace std; struct pos { int x, y; } huruf[26]; pos setPos(int x, int y) { return (pos){x, y}; } bool checkPos(pos a, pos b) { return a.x == b.x && a.y == b.y; } int n, m, k, len, hor[1005][1005], ver[1005][1005]; char dir; string grid[1005]; string arah = "NSWE"; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; bool check(pos asal, pos tujuan) { if (tujuan.x < 0 || tujuan.x >= n || tujuan.y < 0 || tujuan.y >= m) { return 0; } bool ok; if (dir == 'N') { ok = (ver[asal.x][asal.y] - ver[tujuan.x - 1][tujuan.y]) == 0; } else if (dir == 'S') { ok = (ver[tujuan.x][tujuan.y] - ver[asal.x - 1][asal.y]) == 0; } else if (dir == 'W') { ok = (hor[asal.x][asal.y] - hor[tujuan.x][tujuan.y - 1]) == 0; } else { ok = (hor[tujuan.x][tujuan.y] - hor[asal.x][asal.y - 1]) == 0; } return ok; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < 26; i++) { huruf[i] = setPos(-1, -1); } for (int i = 0; i < n; i++) { cin >> grid[i]; for (int j = 0; j < m; j++) { if (grid[i][j] >= 'A' && grid[i][j] <= 'Z') huruf[grid[i][j] - 'A'] = setPos(i, j); } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { hor[i][j] = (grid[i][j] == '#') + (j ? hor[i][j - 1] : 0); ver[i][j] = (grid[i][j] == '#') + (i ? ver[i - 1][j] : 0); } } cin >> k; while (k--) { cin >> dir >> len; for (int i = 0; i < 26; i++) { if (checkPos(huruf[i], setPos(-1, -1))) continue; bool ok = 1; for (int x = 0; x < 4; x++) { if (arah[x] == dir) { ok = check(huruf[i], setPos(huruf[i].x + len * dx[x], huruf[i].y + len * dy[x])); if (!ok) { huruf[i] = setPos(-1, -1); } else { huruf[i] = setPos(huruf[i].x + len * dx[x], huruf[i].y + len * dy[x]); } } } } } string ans = ""; for (int i = 0; i < 26; i++) { if (checkPos(huruf[i], setPos(-1, -1))) continue; ans += 'A' + i; } if (ans == "") cout << "no solution\n"; else cout << ans << '\n'; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int z = 0; z < t; z++) { string s; cin >> s; bool single = true; char p = s[0]; for (int i = 0; i < s.size(); i++) { if (p == s[i]) { } else { single = false; break; } } if (single) { cout << s << "\n"; } else { p = s[0]; string ans = ""; ans += s[0]; for (int i = 1; i < s.size(); i++) { if (p == s[i]) { if (p == '0') { ans += '1'; ans += p; } else { ans += '0'; ans += p; } } else { p = s[i]; ans += p; } } cout << ans << "\n"; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= ch == '-', ch = getchar(); while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar(); return f ? -x : x; } template <class T> void print(T x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) print(x / 10); putchar(x % 10 + '0'); } template <class T> void print(T x, char let) { print(x), putchar(let); } template <class T1, class T2> void ckmin(T1& x, T2 y) { if (x > y) x = y; } template <class T1, class T2> void ckmax(T1& x, T2 y) { if (x < y) x = y; } const int N = 200005; const int inf = 1e9; char s[N]; int ls[N], rs[N]; int a[N], pat[N], p[N], ans[N], c; int n, k; void dfs(int u) { if (!u) return; dfs(ls[u]); ++c, pat[c] = s[u], p[u] = c; dfs(rs[u]); } void dfs0(int u) { if (!u) return; dfs0(ls[u]); if (a[u]) printf("%c%c", s[u], s[u]); else printf("%c", s[u]); dfs0(rs[u]); } int g(int u, int d) { if (ls[u] && g(ls[u], d + 1)) a[u] = 1; if (rs[u]) { if (a[u] || (ans[p[u]] && k >= d)) { if (!a[u]) a[u] = 1, k -= d; if (g(rs[u], 1)) a[u] = 1; } else { if (g(rs[u], inf)) a[u] = 1; } } else { if (a[u] || !(ans[p[u]] && k >= d)) ; else a[u] = 1, k -= d; } return a[u]; } int main() { scanf("%d%d%s", &n, &k, s + 1); for (int i = (1); i <= (n); i++) ls[i] = read(), rs[i] = read(); dfs(1); for (int i = (1); i <= (c); i++) pat[i] -= 'a'; for (int i = (n - 1); i >= (0); i--) ans[i] = pat[i] != pat[i + 1] ? (pat[i] < pat[i + 1]) : ans[i + 1]; g(1, 1); dfs0(1); return 0; }
8
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; inline long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar(); if (_tc == '-') _tc = getchar(), _tmp = -1; while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar(); return _x * _tmp; } inline long long add(long long _x, long long _y, long long _mod = 1000000007LL) { _x += _y; return _x >= _mod ? _x - _mod : _x; } inline long long sub(long long _x, long long _y, long long _mod = 1000000007LL) { _x -= _y; return _x < 0 ? _x + _mod : _x; } inline long long mul(long long _x, long long _y, long long _mod = 1000000007LL) { _x *= _y; return _x >= _mod ? _x % _mod : _x; } long long mypow(long long _a, long long _x, long long _mod) { if (_x == 0) return 1LL; long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod); if (_x & 1) _ret = mul(_ret, _a, _mod); return _ret; } long long mymul(long long _a, long long _x, long long _mod) { if (_x == 0) return 0LL; long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod); if (_x & 1) _ret = add(_ret, _a, _mod); return _ret; } inline bool equal(double _x, double _y) { return _x > _y - 1e-9 && _x < _y + 1e-9; } int __ = 1, _cs; void build() {} long long bi, li, ri; void init() { bi = getint(); li = getint(); ri = getint(); } int bt[100], bc; long long sv[11][100][1 << 11]; bool gt[11][100][1 << 11]; long long go(int now, int msk, bool bnd, bool st) { if (st and not bnd and gt[bi][now][msk]) return sv[bi][now][msk]; if (now < 0) { if (not st) return 0; return msk == 0 ? 1 : 0; } long long ret = 0; if (not st) { if (now + 1 == bc) { ret += go(now - 1, 0, false, false); for (int i = 1; i <= bt[now]; i++) ret += go(now - 1, msk ^ (1 << i), i == bt[now], true); } else { ret += go(now - 1, 0, false, false); for (int i = 1; i < bi; i++) ret += go(now - 1, msk ^ (1 << i), false, true); } } else if (not bnd) { for (int i = 0; i < bi; i++) ret += go(now - 1, msk ^ (1 << i), false, true); } else { for (int i = 0; i <= bt[now]; i++) ret += go(now - 1, msk ^ (1 << i), i == bt[now], true); } if (st and not bnd) { gt[bi][now][msk] = true; sv[bi][now][msk] = ret; } return ret; } long long cal(long long vv) { if (vv == 0) return 0; bc = 0; while (vv) { bt[bc++] = vv % bi; vv /= bi; } return go(bc - 1, 0, false, false); } void solve() { long long ans = cal(ri) - cal(li - 1); printf("%lld\n", ans); } int main() { build(); __ = getint(); while (__--) { init(); solve(); } }
7
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n, m; cin >> n >> m; long long int a[n][m]; for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < m; j++) cin >> a[i][j]; } long long int dp[n][m]; memset(dp, 0, sizeof(dp)); long long int cnt = 0; for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < m; j++) { if (a[i][j] == 1) { for (long long int k = 0; k < n; k++) dp[k][j] = 1; for (long long int k = 0; k < m; k++) dp[i][k] = 1; } } } for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < m; j++) { if (dp[i][j] == 0) { cnt++; for (long long int k = 0; k < n; k++) dp[k][j] = 1; for (long long int k = 0; k < m; k++) dp[i][k] = 1; } } } if (cnt % 2) cout << "Ashish\n"; else cout << "Vivek\n"; } cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n"; }
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; char s[1034], L[1034], R[1034]; int n, D, d; int i, j, k, l, r; int dig, nj, nk; long long f[55][25610][8], ans = 0; namespace AcAM { int cnt = 1; int d[25610][10], v[25610], f[25610], la[25610]; int que[25610]; void insert(char *_beg, char *_end) { char *p; int t = 1, id; for (p = _beg; p != _end; ++p) { id = *p & 15; t = (d[t][id] ? d[t][id] : (d[t][id] = ++cnt)); } v[t] = 1; } void Build_Ac_AM() { int h, ta = 1, i, t, id; que[0] = 1; f[1] = 0; for (h = 0; h < ta; ++h) for (i = que[h], id = 0; id < 10; ++id) { t = (f[i] ? d[f[i]][id] : 1); int &u = d[i][id]; if (!u) { u = t; continue; } f[u] = t; que[ta++] = u; la[u] = (v[t] ? t : la[t]); } } } // namespace AcAM inline void add(long long &A, const long long B) { (A += B) >= mod ? A -= mod : 0; } int main() { scanf("%s%s%s", s, L, R); n = strlen(s); D = strlen(L); d = D >> 1; for (i = 0; i <= n - d; ++i) AcAM::insert(s + i, s + (i + d)); AcAM::Build_Ac_AM(); f[0][1][3] = 1; for (i = 0; i < D; ++i) for (j = 1; j <= AcAM::cnt; ++j) for (k = 0; k < 8; ++k) if (f[i][j][k]) { l = (k & 2 ? L[i] & 15 : 0); r = (k & 1 ? R[i] & 15 : 9); for (dig = l; dig <= r; ++dig) { nj = AcAM::d[j][dig]; nk = k & (dig == l ? -1 : -3) & (dig == r ? -1 : -2); nk |= AcAM::v[nj] << 2; add(f[i + 1][nj][nk], f[i][j][k]); } } for (j = 1; j <= AcAM::cnt; ++j) for (k = 4; k < 8; ++k) add(ans, f[D][j][k]); printf("%lld\n", ans); return 0; }
12
#include <bits/stdc++.h> using namespace std; const int N = 100 + 3; int pos[N], val[N]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < k; i++) { cin >> val[i]; pos[val[i]] = i; } int sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int a; cin >> a; sum += pos[a] + 1; for (int t = pos[a]; t; t--) { pos[val[t - 1]]++; val[t] = val[t - 1]; } pos[a] = 0; val[0] = a; } } cout << sum << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; char a[1000][1000], b[1000][1000]; char s[1000]; int main() { int count1 = 0, count2 = 0; int n; scanf("%d", &n); scanf("%s", s); int temp = 0; int f = 1, flag = 1; for (int i = 0; i < n; i++) { if (s[i] == '(') { int temp1 = 0; f = 1; i++; while (s[i] != ')') { if (s[i] == '_') { f = 1; } else if (f == 1 && s[i] != '_') { temp1 = 0; f = 0; b[++count2][temp1++] = s[i]; } else if (f == 0 && s[i] != '_') { b[count2][temp1++] = s[i]; } i++; } flag = 1; } else if (s[i] == '_') { flag = 1; } else if (s[i] != '_' && flag) { flag = 0; temp = 0; a[++count1][temp++] = s[i]; } else if (flag == 0 && s[i] != '_') { a[count1][temp++] = s[i]; } } int l = 0; for (int i = 1; i <= count1; i++) { int temp2 = strlen(a[i]); l = max(l, temp2); } printf("%d %d\n", l, count2); }
1
#include <bits/stdc++.h> using namespace std; bool a[1100]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; long long int n; cin >> n; long long int fin = 0; long long int p = 1, m = 0; while (a[m] != true) { a[m] = true; m += p; m = m % n; p++; fin++; } if (fin == n) { cout << "YES"; return 0; } cout << "NO"; }
2
#include <bits/stdc++.h> using namespace std; vector<int> a[1 << 21], dis[1 << 21], op[1 << 21]; char s[1 << 22]; int qx[1 << 22], qy[1 << 22]; int n, m; bool OK(int lim) { int hd = 1, tl = 0; for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= m + 1; j++) { if (a[i][j] && dis[i][j] > lim) { qx[++tl] = i, qy[tl] = j; op[i][j] = 0; } else op[i][j] = -1; } while (hd <= tl) { int x = qx[hd], y = qy[hd]; ++hd; for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) { int x1 = x + i, y1 = y + j; if (x1 < 0 || x1 > n + 1 || y1 < 0 || y1 > m + 1 || op[x1][y1] != -1) continue; op[x1][y1] = op[x][y] + 1; qx[++tl] = x1, qy[tl] = y1; } } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (a[i][j] && (op[i][j] == -1 || op[i][j] > lim)) return 0; return 1; } int main() { scanf("%d%d", &n, &m); int hd = 1, tl = 0; for (int i = 0; i <= n + 1; i++) { op[i].resize(m + 2); a[i].resize(m + 2); dis[i].resize(m + 2); if (i >= 1 && i <= n) scanf("%s", s + 1); for (int j = 0; j <= m + 1; j++) { if (i >= 1 && i <= n && j >= 1 && j <= m) a[i][j] = s[j] == 'X'; else s[j] = 0; if (a[i][j]) dis[i][j] = -1; else dis[i][j] = 0, qx[++tl] = i, qy[tl] = j; } } while (hd <= tl) { int x = qx[hd], y = qy[hd]; ++hd; for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) { int x1 = x + i, y1 = y + j; if (x1 < 0 || x1 > n + 1 || y1 < 0 || y1 > m + 1 || dis[x1][y1] != -1) continue; dis[x1][y1] = dis[x][y] + 1; qx[++tl] = x1, qy[tl] = y1; } } int l = 0, r = n + m; while (l <= r) { int mid = (l + r) >> 1; if (OK(mid)) l = mid + 1; else r = mid - 1; } OK(r); printf("%d\n", r); for (int i = 1; i <= n; i++, puts("")) for (int j = 1; j <= m; j++) putchar(op[i][j] == 0 ? 'X' : '.'); return 0; }
7
#include <bits/stdc++.h> int cmpfunc(const void* a, const void* b) { return (*(int*)b - *(int*)a); } int main() { int a, b, c, d, e, i, j, k, sum1 = 0, ct = 0, sum = 0; int x[100002]; scanf("%d", &a); for (i = 0; i < a; i++) { scanf("%d", &x[i]); sum1 = sum1 + x[i]; } if (sum1 % 2 != 0) { printf("0"); return 0; } sum1 = sum1 / 2; for (i = 0; i < a - 1; i++) { sum = sum + x[i]; if (sum == sum1) ct++; } printf("%d", ct); return 0; }
2
#include <bits/stdc++.h> using namespace std; const int MX = 1e6, MAXN = 2e5 + 5; const long long INF = 1e18; long long arr[MX + 1], tr[MX * 4 + 1], tag[MX * 4 + 1]; void add(int o, int k) { tr[o] += k, tag[o] += k; } void pushup(int o) { tr[o] = max(tr[(o << 1)], tr[(o << 1 | 1)]); } void pushdown(int o) { if (tag[o]) add((o << 1), tag[o]), add((o << 1 | 1), tag[o]), tag[o] = 0; } void build(int o, int l, int r) { if (l == r) tr[o] = arr[l]; else build((o << 1), l, ((l + r) >> 1)), build((o << 1 | 1), ((l + r) >> 1) + 1, r), pushup(o); } void ins(int o, int l, int r, int L, int R, int K) { if (r < L || l > R) return; if (L <= l && r <= R) return add(o, K); pushdown(o), ins((o << 1), l, ((l + r) >> 1), L, R, K), ins((o << 1 | 1), ((l + r) >> 1) + 1, r, L, R, K), pushup(o); } long long qry(int o, int l, int r, int L, int R) { if (r < l || l > R) return 0; if (L <= l && r <= R) return tr[o]; pushdown(o); return max(qry((o << 1), l, ((l + r) >> 1), L, R), qry((o << 1 | 1), ((l + r) >> 1) + 1, r, L, R)); } int N, M, P; long long ans = -INF; struct weapon { int x, c; bool operator<(const weapon& t) const { return x < t.x; } } a[MAXN]; struct monster { int x, y, c; bool operator<(const monster& t) const { return x < t.x; } } p[MAXN]; int main() { scanf("%d%d%d", &N, &M, &P); int x, c; for (int i = 1; i <= N; ++i) scanf("%d%d", &a[i].x, &a[i].c); for (int i = 1; i <= MX; ++i) arr[i] = -INF; for (int i = 1; i <= M; ++i) scanf("%d%d", &x, &c), arr[x] = max(arr[x], (long long)-c); build(1, 1, MX); for (int i = 1; i <= P; ++i) scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].c); sort(p + 1, p + P + 1), sort(a + 1, a + N + 1); for (int i = 1, j = 1; i <= N; ++i) { while (j <= P && p[j].x < a[i].x) { if (p[j].y < MX) ins(1, 1, MX, p[j].y + 1, MX, p[j].c); ++j; } ans = max(ans, -a[i].c + tr[1]); } printf("%lld", ans); return 0; }
6
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long _INF = 0xc0c0c0c0c0c0c0c0; const long long mod = (int)1e9 + 7; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long ksm(long long a, long long b, long long mod) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans; } long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); } void exgcd(long long a, long long b, long long &x, long long &y, long long &d) { if (!b) { d = a; x = 1; y = 0; } else { exgcd(b, a % b, y, x, d); y -= x * (a / b); } } const int MAX_N = 200025; int num[MAX_N], n, num_[MAX_N]; vector<int> vt[MAX_N]; vector<int> day[MAX_N]; bool check(int x, int ck) { for (int i = 1; i <= x; ++i) day[i].clear(); for (int i = 1; i <= n; ++i) num_[i] = num[i]; int sum_ = 0; for (int i = 1; i <= n; ++i) { int sz = vt[i].size(); if (!sz) continue; if (vt[i][sz - 1] <= x) { day[vt[i][sz - 1]].push_back(i); } else { int xb = upper_bound(vt[i].begin(), vt[i].end(), x) - vt[i].begin(); if (xb == 0) continue; else { day[vt[i][xb - 1]].push_back(i); } } } int sum = 0; for (int i = 1; i <= x; ++i) { sum++; if (day[i].size()) { for (int j = 0; j < day[i].size(); ++j) { if (num_[day[i][j]]) { sum_ += min(sum, num_[day[i][j]]); sum -= min(sum, num_[day[i][j]]); } } } } if (sum >= (ck - sum_) * 2) return true; return false; } int main() { int m, a, b, sum = 0; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &num[i]), sum += num[i]; while (m--) { scanf("%d%d", &a, &b); vt[b].push_back(a); } for (int i = 1; i <= n; ++i) sort(vt[i].begin(), vt[i].end()); int l = 1, r = sum * 2; while (l <= r) { int mid = (l + r) / 2; if (check(mid, sum)) r = mid - 1; else l = mid + 1; } printf("%d\n", l); return 0; }
6
#include <bits/stdc++.h> using namespace std; const double EPS = 1E-12; int n; double m[64][64]; int l[128], r[128]; int gain[128]; double dp[64]; double pwin[128][128]; double f(int id) { if (id >= (1 << n)) return 0; if (dp[id] > EPS) return dp[id]; double best = -1.; int bestp = 0; for (int p = l[id]; p < r[id]; p++) { double score = 0; int match_id = id; while (match_id < (1 << n)) { score += pwin[match_id][p] * gain[match_id]; if (p < r[2 * match_id]) { score += f(2 * match_id + 1); match_id *= 2; } else { score += f(2 * match_id); match_id = 2 * match_id + 1; } } if (score > best) { best = score; bestp = p; } } return dp[id] = best; } int main() { cin >> n; for (int i = 0; i < (1 << n); i++) for (int j = 0; j < (1 << n); j++) { int x; scanf("%d", &x); m[i][j] = (double)x / 100.; } for (int i = (1 << n); i < (1 << (n + 1)); i++) { l[i] = i; r[i] = i + 1; pwin[i][i] = 1; } for (int i = (1 << n) - 1; i >= 1; i--) { gain[i] = ((2 * i >= (1 << n)) ? 1 : (2 * gain[2 * i])); l[i] = l[2 * i]; r[i] = r[2 * i + 1]; for (int p = l[2 * i]; p < r[2 * i]; p++) for (int o = l[2 * i + 1]; o < r[2 * i + 1]; o++) { double a = pwin[2 * i][p] * pwin[2 * i + 1][o]; pwin[i][p] += a * m[p - (1 << n)][o - (1 << n)]; pwin[i][o] += a * m[o - (1 << n)][p - (1 << n)]; } } printf("%.12lf\n", f(1)); return 0; }
6
#include <bits/stdc++.h> using namespace std; int main() { int n, t, r, aux, aux2, c1, c2; string s; char obj; cin >> n; cin >> s; t = s.size(); s = s + s; r = 10000; c1 = 0; c2 = 0; for (int i = 0; i < t; i++) { if (s[i] == 'H') c1++; else c2++; } if (c1 > c2) obj = 'T'; else obj = 'H'; aux2 = min(c1, c2); for (int i = 0; i < t; i++) { aux = 0; for (int j = i; j < aux2 + i; j++) { if (s[j] != obj) aux++; } r = min(aux, r); } cout << r; return 0; }
4
#include <bits/stdc++.h> using namespace std; void solve() { long long pre[31]; for (int i = 0; i < 31; i++) pre[i] = 1 << i; int n; cin >> n; map<long long, int> mp; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i], mp[a[i]]++; int ans = 0; loop: for (int i = 0; i < n; i++) { bool f = 0; for (int j = 0; j < 31; j++) { long long dif = pre[j] - a[i]; if (dif > 0) { if (mp.find(dif) != mp.end()) { if (a[i] == pre[j] - a[i] && mp[dif] >= 2) { f = 1; } if (a[i] != pre[j] - a[i] && mp[dif] >= 1) { f = 1; } } } } if (!f) ans++; } cout << ans; } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; loop: while (t--) { solve(); } }
2
#include <bits/stdc++.h> int main() { long long n; scanf("%lld", &n); long long a[4]; scanf("%lld %lld %lld %lld", &a[0], &a[1], &a[2], &a[3]); long long b[4]; long long c[4]; b[0] = a[0] + a[1]; b[1] = a[0] + a[2]; b[2] = a[2] + a[3]; b[3] = a[1] + a[3]; std::sort(b, b + 4); long long v = b[3] - b[0]; if (v > n) printf("0"); else printf("%lld", (n - v) * n); return 0; }
3
#include <bits/stdc++.h> using namespace std; map<char, int> a; char c[100005]; int l, r, i, j, k, s; int main() { a['A'] = a['H'] = a['I'] = a['M'] = a['O'] = a['T'] = a['U'] = 1; a['U'] = a['V'] = a['W'] = a['X'] = a['Y'] = 1; scanf("%s", &c); r = strlen(c); r--; l = 0; while (l <= r) { if (c[l] != c[r]) { printf("NO"); return 0; } else if (!a[c[l]] || !a[c[r]]) { printf("NO"); return 0; } l++; r--; } printf("YES"); }
1
#include <bits/stdc++.h> using namespace std; long long t, n; long long a[200005]; long long res; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long x, y, a, t, s, n, b, i, c, d; cin >> n >> x; string s1; cin >> s1; long long dp[1000] = {}; for (i = 0; i < n; i++) { a = s1[i] - '0'; dp[a]++; } y = *max_element(dp, dp + 1000); if (y > x) cout << "NO"; else cout << "YES"; return 0; }
0
#include <bits/stdc++.h> using namespace std; void boost() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void solve() { long long n, i, j, k; cin >> n >> k; long long ans = 1; while (k % 2 == 0) { ans++; k /= 2; } cout << ans << '\n'; } int main() { boost(); solve(); return 0; }
2
#include <bits/stdc++.h> using namespace std; char str[20]; int mem[20][200][2]; int dp(int pos, int sum, bool f) { if (pos == strlen(str)) return sum; if (mem[pos][sum][f] != -1) return mem[pos][sum][f]; mem[pos][sum][f] = 0; if (f) mem[pos][sum][f] = dp(pos + 1, sum + 9, f); else { mem[pos][sum][f] = dp(pos + 1, sum + (str[pos] - '0'), f); for (int i = str[pos] - '1'; i >= 0; i--) mem[pos][sum][f] = max(mem[pos][sum][f], dp(pos + 1, sum + i, 1)); } return mem[pos][sum][f]; } queue<int> q; void print(int pos, int sum, bool f) { if (pos == strlen(str)) return; if (f) q.push(9), print(pos + 1, sum + 9, f); else { if (mem[pos][sum][f] == dp(pos + 1, sum + (str[pos] - '0'), f)) q.push(str[pos] - '0'), print(pos + 1, sum + (str[pos] - '0'), f); else { for (int i = str[pos] - '1'; i >= 0; i--) if (mem[pos][sum][f] == dp(pos + 1, sum + i, 1)) { q.push(i); print(pos + 1, sum + i, 1); return; } } } } int main() { memset(mem, -1, sizeof mem); scanf("%s", str); dp(0, 0, 0); print(0, 0, 0); if (q.front() == 0) q.pop(); while (!q.empty()) printf("%d", q.front()), q.pop(); puts(""); return 0; }
2
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-6; const unsigned long long hashp = 1e7 + 19; const long long INF = 0x3f3f3f3f3f3f3f3fll; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 2e5 + 100; struct node { int val; int id; bool operator<(const node& z) const { return val < z.val; } } a[maxn]; int c[maxn]; int dp[maxn]; int path[maxn]; int ans[maxn]; int vis[maxn]; void solve() { int n; scanf("%d", &n); for (int i = 1; (i) <= (n); i++) { scanf("%d", &a[i]); a[i].id = i; } sort(a + 1, a + n + 1); if (n < 6) { printf("%d 1\n", a[n].val - a[1].val); for (int i = 1; (i) <= (n); i++) printf("1 "); return; } for (int i = 1; (i) <= (n - 1); i++) { c[i] = a[i + 1].val - a[i].val; } dp[3] = c[3]; int mx = 0, mark = 0; for (int i = 4; i <= n - 3; i++) { dp[i] = mx + c[i]; path[i] = mark; if (i >= 5) { if (mx < dp[i - 2]) { mx = dp[i - 2]; mark = i - 2; } } } int num = -1, xb; for (int i = 3; i <= n - 3; i++) { if (num < dp[i]) { num = dp[i]; xb = i; } } while (xb) { vis[xb] = 1; xb = path[xb]; } int now = 1; for (int i = 1; (i) <= (n); i++) { ans[a[i].id] = now; if (vis[i]) now++; } printf("%d %d\n", a[n].val - a[1].val - num, now); for (int i = 1; (i) <= (n); i++) printf("%d ", ans[i]); } int main() { solve(); return 0; }
6
#include <bits/stdc++.h> using namespace std; const int N = 100010; inline int in() { int x; scanf("%d", &x); return x; } inline long long lin() { long long x; scanf("%I64d", &x); return x; } int main() { int l = in(), r = in(); if (r - l == 0) printf("%d\n", l); else { int ans = 0, mx = 0; for (int i = 2; i <= N; i++) { int tmp = r / i - (l - 1) / i; if (tmp >= mx) { mx = tmp; ans = i; } } printf("%d\n", ans); } }
1
#include <bits/stdc++.h> using namespace std; int ask(int x1, int y1, int x2, int y2) { printf("? %d %d %d %d\n", x1, y1, x2, y2); fflush(stdout); int tmp; scanf("%d", &tmp); return tmp ^ 1; } const int N = 55; int ans[N][N], n; bool vis[N][N]; inline void get(int x1, int y1, int x2, int y2) { if (x2 <= n && y2 <= n && !vis[x2][y2]) vis[x2][y2] = 1, ans[x2][y2] = ans[x1][y1] ^ ask(x1, y1, x2, y2); } int main() { ans[1][1] = 1; scanf("%d", &n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { get(i, j, i + 1, j + 1); get(i, j, i + 2, j); get(i, j, i, j + 2); } if (i == 1) ans[2][1] = ans[2][3] ^ ask(2, 1, 2, 3); } int tmp = 1; for (int i = 1; i < n - 1; i++) for (int j = 1; j < n; j++) if (((i + j) & 1) == 0 && ((ans[i + 1][j + 1] != ans[i + 2][j] || (ans[i + 1][j] == ans[i][j + 1] && !(ans[i][j] ^ ans[i + 1][j + 1] ^ ans[i + 1][j] ^ ans[i + 2][j + 1]))))) { tmp = (ans[i][j] ^ ans[i + 2][j + 1] ^ ask(i, j, i + 2, j + 1)); goto NXT; } for (int i = 1; i < n; i++) for (int j = 1; j < n - 1; j++) if (((i + j) & 1) == 0 && ((ans[i + 1][j + 1] != ans[i][j + 2] || (ans[i + 1][j] == ans[i][j + 1] && !(ans[i][j] ^ ans[i + 1][j + 1] ^ ans[i][j + 1] ^ ans[i + 1][j + 2]))))) { tmp = (ans[i][j] ^ ans[i + 1][j + 2] ^ ask(i, j, i + 1, j + 2)); goto NXT; } NXT: puts("!"); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) printf("%d", ans[i][j] ^ (((i + j) & 1) & tmp)); puts(""); } return 0; }
8
#include <bits/stdc++.h> using namespace std; const int INF = 0x7f7f7f7f; long long arr[500005], pre[500005], post[500005]; long long pre2[500005]; int main() { ios_base::sync_with_stdio(false); int n; long long sum = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; sum += arr[i]; pre2[i] = pre[i] = post[i] = 0; } if (sum % 3 != 0) { cout << 0; cout << "\n"; return 0; } sum = sum / 3; long long s = 0; for (int i = 1; i <= n; i++) { s = s + arr[i]; if (s == sum) pre[i] = 1; } s = 0; for (int i = n; i >= 1; i--) { s = s + arr[i]; if (s == sum) post[i] = 1; if (s == 2 * sum) pre2[i] = 1; } for (int i = 2; i <= n; i++) pre[i] += pre[i - 1]; for (int i = n - 1; i >= 1; i--) post[i] += post[i + 1], pre2[i] += pre2[i + 1]; long long ans = 0; for (int i = 1; i <= n; i++) { if (pre[i] > pre[i - 1]) { long long x; if (sum == 0 && pre2[i + 1] >= 1) x = post[i + 1] - 1; else if (sum != 0 && pre2[i + 1] >= 1) x = post[i + 1]; else x = 0; ans += x; } } cout << ans; cout << "\n"; return 0; }
4
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; const long long int N = 1e5 + 5; long long int mod = 998244353; void null() { string a, b; cin >> a >> b; long long int n = (long long int)a.size(), m = (long long int)b.size(); vector<vector<long long int>> dp(n + 1, vector<long long int>(m + 1, 0)); for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { dp[i][j] = dp[i][j + 1]; if (a[i] == b[j]) dp[i][j] = (dp[i][j] + (1 + dp[i + 1][j + 1]) % 1000000007) % 1000000007; } } long long int ans = 0; for (int i = 0; i < n; i++) { ans = (ans + dp[i][0]) % 1000000007; } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); cout << setprecision(4); cout << fixed; long long int t = 1; clock_t start, end; start = clock(); while (t--) { null(); } end = clock(); double time_taken = double(end - start) / double(CLOCKS_PER_SEC); }
4
#include <bits/stdc++.h> using namespace std; const int N = 10004; long long a[N], b[N], c, sa = 0, mb = 0, M; int n; bool ok1(long long x) { long long s = 0; for (int i = 1; i <= n; i++) { if (a[i] > 0 && x / b[i] > c / a[i]) return 0; s += a[i] * x / b[i] + 1; if (s >= c) return 0; } return 1; } bool ok2(long long x) { long long s = 0; for (int i = 1; i <= n; i++) { if (a[i] > 0 && x / b[i] > c / a[i]) return 1; s += a[i] * x / b[i] + 1; if (s > c) return 1; } return 0; } int main() { scanf("%d %lld", &n, &c); for (int i = 1; i <= n; i++) { scanf("%lld %lld", &a[i], &b[i]); sa += a[i]; mb = max(mb, b[i]); } long long u, v; M = c * mb; if (sa == 0) return puts(n == c ? "-1" : "0"), 0; long long l = 0, r = M; while (l < r) { long long mid = (l + r + 1) / 2; if (ok1(mid)) l = mid; else r = mid - 1; } u = l; l = 0, r = M; while (l < r) { long long mid = (l + r) / 2; if (ok2(mid)) r = mid; else l = mid + 1; } v = r; printf("%lld\n", max(v - u - 1, 0ll)); }
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<ll, ll>; using vi = vector<ll>; using vii = vector<ii>; const int MX = 2 * 100007; int n; ii weis[MX], edge[MX], par[MX]; int rr[MX], rrl[MX]; list<int> ee[MX]; ll w[MX], wl[MX], wd[MX]; int main() { scanf("%d", &n); for (int i = 0; i < n - 1; i++) { int a, b, w, s; scanf("%d%d%d%d", &a, &b, &w, &s); a--; b--; edge[i] = {a, b}; weis[i] = {w, s}; rr[a]++; rrl[a]++; par[b] = {a, i}; } queue<ll> q; for (int i = 0; i < n; i++) if (!rr[i]) q.push(i); bool ok = 1; while (q.size()) { int v = q.front(); q.pop(); if (v == 0) break; int p = par[v].first, pe = par[v].second; while (ee[v].size() && weis[pe].second < w[v]) { ll ei = ee[v].front(); ll md = min(weis[ei].first - 1, weis[ei].second - wl[edge[ei].second]); if (md <= 0) { ee[v].pop_front(); wd[edge[ei].first] += wd[edge[ei].second]; rrl[edge[ei].first]--; if (!rrl[edge[ei].first]) { wl[edge[ei].first] += wd[edge[ei].first]; } continue; } ll diff = w[v] - weis[pe].second; ll mmd = min(md, diff); weis[ei].first -= mmd; weis[ei].second -= mmd; w[v] -= mmd; wd[edge[ei].first] -= mmd; } if (weis[pe].second < w[v]) { ok = 0; break; } ee[p].splice(ee[p].end(), ee[v]); ee[p].push_back(pe); w[p] += w[v] + weis[pe].first; wl[p] += wl[v] + weis[pe].first; rr[p]--; if (!rr[p]) q.push(p); } if (!ok) printf("-1\n"); else { printf("%d\n", n); for (int i = 0; i < n - 1; i++) printf("%d %d %d %d\n", (int)edge[i].first + 1, (int)edge[i].second + 1, (int)weis[i].first, (int)weis[i].second); } return 0; }
9
#include <bits/stdc++.h> using namespace std; using ll = long long; ll n; int main() { cin.tie(0)->sync_with_stdio(0); int t; cin >> t; while (t--) { string str; cin >> str; int d = str[0] - '0' - 1, l = str.size(); cout << 10 * d + l * (l + 1) / 2 << endl; } return 0; }
0
#include <bits/stdc++.h> int main() { std::string a, b; getline(std::cin, a); getline(std::cin, b); long ftos(0), stof(0); for (int k = 0; k < a.size(); k++) { if (a[k] == '4' && b[k] == '7') { ++ftos; } else if (a[k] == '7' && b[k] == '4') { ++stof; } } printf("%ld\n", (ftos > stof) ? ftos : stof); return 0; }
2
#include <bits/stdc++.h> using namespace std; int main(void) { std::ios::sync_with_stdio(false); std::cin.tie(0); int t; cin >> t; while (t--) { int d, m; cin >> d >> m; long long res = 1; for (int i = 1; 1; ++i) { if (1 << (i - 1) > d) break; res = res * (min((1 << i) - 1, d) - (1 << (i - 1)) + 2) % m; } cout << (res - 1 + m) % m << endl; } return 0; }
4
#include <bits/stdc++.h> using namespace std; int t, n, k; int main() { cin >> t; while (t--) { scanf("%d%d", &n, &k); if (k % 3 != 0) puts(n % 3 ? "Alice" : "Bob"); else { n %= (k + 1); if (n == k) puts("Alice"); else puts(n % 3 ? "Alice" : "Bob"); } } }
4
#include <bits/stdc++.h> using namespace std; long long int p[100001], onof[100001], onfactors[100001]; void spf() { long long int n = 100001; for (long long int i = 1; i <= n; i++) { p[i] = i; } for (long long int i = 2; i <= n; i++) { if (p[i] == i) { for (long long int j = i * i; j <= n; j = j + i) { if (p[j] == j) { p[j] = i; } } } } } void solve() { int n, m; cin >> n >> m; unordered_map<int, int> mk; for (int i = 0; i < m; i++) { char x; int y; cin >> x >> y; int j = y; if (x == '+') { if (onof[y]) { cout << "Already on" << "\n"; } else { vector<int> curr; int k = 0; bool ok = false; while (y != 1) { if (onfactors[p[y]] > 0) { k = p[y]; ok = true; break; } else { curr.push_back(p[y]); y = y / p[y]; } } if (ok) { cout << "Conflict with " << mk[k] << "\n"; ; } else { cout << "Success" << "\n"; onof[j] = 1; for (int l : curr) { onfactors[l]++; mk[l] = j; } } } } else { if (onof[y] == 0) { cout << "Already off" << "\n"; } else { cout << "Success" << "\n"; onof[y] = 0; while (y != 1) { onfactors[p[y]]--; y /= p[y]; } } } } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; spf(); fill_n(onof, 100001, 0); fill_n(onfactors, 100001, 0); int t = 1; while (t--) { solve(); } return 0; }
4
#include <bits/stdc++.h> using namespace std; const int max_n = 5e5 + 5; const int mod = 998244353; int n; vector<int> v; int powmod(int a, int b) { if (b == 0) return 1; if (a == 0) return 0; int sq = powmod(a, b / 2); sq = (sq * 1LL * sq) % mod; if (b % 2 == 0) return sq; return (sq * 1LL * a) % mod; } int bit[max_n]; void add(int x) { while (x <= n) { bit[x]++; x += (x & -x); } } int ask(int x) { int ans = 0; while (x != 0) { ans += bit[x]; x -= (x & (-x)); } return ans; } int jest[max_n]; int sa_mniejsze[max_n]; int main() { scanf("%d", &(n)); ; for (int i = (0); i < ((n)); ++i) { int(a); scanf("%d", &(a)); ; (v).push_back(a); }; int k = 0; for (int i = (0); i < (n); ++i) if (v[i] == -1) k++; for (int i = (0); i < (n); ++i) jest[v[i]] = 1; sa_mniejsze[1] = 0; for (int i = (2); i < (n + 1); ++i) sa_mniejsze[i] = sa_mniejsze[i - 1] + jest[i - 1]; int ans = ((k * 1LL * (k - 1)) % mod * powmod(4, mod - 2)) % mod; for (int i = (n - 1); i >= (0); --i) { if (v[i] != -1) { ans = (ans + ask(v[i] - 1)) % mod; add(v[i]); } } if (k != 0) { int pyt = 0; for (int i = (n - 1); i >= (0); --i) { if (v[i] == -1) pyt++; else { int zle = v[i] - 1 - sa_mniejsze[v[i]]; ans += ((pyt * 1LL * zle) % mod * 1LL * powmod(k, mod - 2)) % mod; ans %= mod; ans += (((k - pyt) * 1LL * (k - zle)) % mod * 1LL * powmod(k, mod - 2)) % mod; ans %= mod; } } } printf("%d\n", ans); }
7
#include <bits/stdc++.h> using namespace std; int a[14][100010]; bitset<4096> b[100040]; int n, k; pair<int, int> pa[14]; int main() { int q; scanf("%d%d%d", &n, &k, &q); int l = k; for (int i = 0; i < k; i++) { for (int j = 0; j < n; j++) { scanf("%d", &a[i][j]); } for (int j = 0; j < 4096; j++) { b[i][j] = j >> i & 1; } } while (q--) { int t, x, y; scanf("%d%d%d", &t, &x, &y); --x; --y; --t; if (t <= 1) { if (t == 0) { b[k] = b[x] & b[y]; } else { b[k] = b[x] | b[y]; } k++; } else { for (int i = 0; i < l; i++) { pa[i] = make_pair(a[i][y], i); } sort(pa, pa + l); int z = 0; for (int i = 0; i < l; i++) { z |= 1 << pa[i].second; if (b[x][z]) { printf("%d\n", pa[i].first); break; } } } } return 0; }
10
#include<cstdio> #include<cstring> #define inf 0x7f7f7f7f const int mxc=40,mxx=500; int l,Test_num;char ch[55]; int f[55][82][1002][2]; inline int min(int a,int b) { return a<b? a:b; } inline int dp(int pos,int c,int x,int delta) { if(pos==l)return c? inf:0;if(c>mxc || c<-mxc || x>mxx || x<-mxx)return inf; if(!(~f[pos][c+mxc][x+mxx][(delta==1)]))f[pos][c+mxc][x+mxx][(delta==1)]=min(dp(pos,c,x+delta,delta)+l-pos, min(dp(pos+1,c*10+ch[pos+1]-x,x,1),dp(pos+1,c*10+ch[pos+1]-x,x,-1))); return f[pos][c+mxc][x+mxx][(delta==1)]; } int main() { scanf("%s",ch+2),l=strlen(ch+2)+1,ch[1]=0; for(int i=2;i<=l;++i)ch[i]^=48; memset(f,-1,sizeof(f)),printf("%d",dp(0,0,0,1)); return 0; }
10
#include <bits/stdc++.h> using namespace std; namespace cqz { static const int GYN = 2333333; char SZB[GYN], *S = SZB, *T = SZB; inline char gc() { if (S == T) { T = (S = SZB) + fread(SZB, 1, GYN, stdin); if (S == T) return '\n'; } return *S++; } inline long long read() { long long x = 0, g = 1; char ch = gc(); for (; !isdigit(ch); ch = gc()) if (ch == '-') g = -1; for (; isdigit(ch); ch = gc()) x = x * 10 - 48 + ch; return x * g; } inline void write(long long x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar(x % 10 + '0'); } inline char readchar() { char ch = gc(); for (; isspace(ch); ch = gc()) ; return ch; } inline long long readstr(char *s) { char ch = gc(); int cur = 0; for (; isspace(ch); ch = gc()) ; for (; !isspace(ch); ch = gc()) s[cur++] = ch; s[cur] = '\0'; return cur; } void Print(long long *a, int s, int t) { for (int i = int(s); i <= int(t); ++i) printf("%lld ", a[i]); } void Print(int *a, int s, int t) { for (int i = int(s); i <= int(t); ++i) printf("%d ", a[i]); } void Print(char *a, int s, int t) { for (int i = int(s); i <= int(t); ++i) putchar(a[i]); } void writeln(long long x) { write(x); puts(""); } } // namespace cqz using namespace cqz; long long n, m, k; int main() { n = read(), m = read(), k = read() + 1; if (k <= n) { write(k); putchar(' '); write(1); return 0; } --m; k -= n; long long Hang_Up = (k - 1) / m + 1; k -= (Hang_Up - 1) * m; write(n - Hang_Up + 1); putchar(' '); if (Hang_Up % 2 == 1) write(1 + k); else write(2 + m - k); }
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; vector<vector<int>> ans = { {1, -1}, {1}, {1, 0, 1}, {2}, {1, 1, 0, 0}, {3}, {1, 0, -1, -1, 0}, {4}, {1, -1, 0, 1, 0, 1}, {5}, {1, -1, 1, -1, 0, 0, 0}, {6}, {1, -1, 1, 0, 0, 1, 1, 1}, {7}, {1, 0, 1, 1, -1, 1, 1, 1, 0}, {8}, {1, -1, 1, 1, 0, 0, -1, -1, 1, -1}, {9}, {1, 1, 0, -1, 0, 1, 1, -1, 1, 1, 1}, {10}, {1, 1, -1, -1, 0, -1, 1, -1, 1, -1, -1, 1}, {11}, {1, -1, 1, 1, 0, 0, -1, 1, 1, 0, -1, 1, 0}, {12}, {1, 1, 0, 0, -1, -1, -1, 1, 0, 0, 1, -1, 0, 0}, {13}, {1, 1, -1, 0, 0, 0, -1, -1, 0, 1, -1, 1, 0, -1, 1}, {14}, {1, 0, -1, 1, -1, -1, 0, 1, 1, 0, 1, -1, 1, 1, 0, -1}, {15}, {1, -1, 0, 1, 1, -1, -1, 1, 0, -1, -1, -1, -1, -1, 1, 0, 1}, {16}, {1, 0, 1, 0, 0, -1, -1, 1, -1, 1, 1, 0, 1, 1, 1, 0, -1, 0}, {17}, {1, 1, -1, 0, 0, 1, -1, 1, 1, -1, -1, -1, -1, -1, 1, -1, 0, 0, -1}, {18}, {1, 0, 1, -1, -1, 1, -1, 1, 0, 1, 1, 1, -1, -1, 1, 1, -1, 1, 0, 0}, {19}, {1, 0, -1, 1, -1, 0, 0, -1, 1, 0, 1, 0, 0, -1, 0, -1, 1, -1, 1, -1, 1}, {20}, {1, -1, 0, 0, -1, 0, -1, -1, 1, -1, 1, -1, 1, 0, 1, 1, -1, -1, 1, -1, 0, 1}, {21}, {1, 1, 0, -1, -1, -1, 1, 1, 0, -1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, -1, -1, 0}, {22}, {1, 0, 1, -1, 0, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 0, 1, 0, -1, 1, -1, -1, -1, 1}, {23}, {1, 1, 0, -1, 1, -1, -1, 1, -1, 0, -1, 0, -1, 1, 1, -1, 1, 0, 0, 0, 1, -1, 0, 1, 0}, {24}, {1, -1, 0, -1, -1, 1, 1, 1, 0, 1, 0, -1, 0, 1, -1, 0, -1, 0, -1, 1, 0, 0, 1, 1, 1, 0}, {25}, {1, 1, -1, 0, -1, -1, 0, 1, 0, -1, 0, -1, -1, -1, 0, -1, 0, 1, 0, -1, 1, 1, 1, -1, 0, -1, 1}, {26}, {1, -1, 1, 1, -1, 1, 0, 1, 0, 0, -1, 0, 1, 0, 1, 0, -1, -1, 0, 1, 1, 1, 1, 0, 0, 1, 1, -1}, {27}, {1, -1, 0, 1, -1, -1, 0, -1, 1, -1, -1, 0, 0, -1, -1, -1, -1, 1, -1, -1, 0, -1, 0, 0, 1, 1, 1, -1, -1}, {28}, {1, 0, -1, 0, 0, 0, -1, 1, 0, -1, 1, -1, 0, -1, -1, 1, 1, -1, -1, 0, -1, -1, 0, 1, 1, 0, 0, 0, 1, -1}, {29}, {1, -1, 1, 0, 0, -1, 1, 0, 1, 1, -1, 0, -1, -1, -1, 1, -1, 0, 0, 1, -1, -1, 1, 0, 0, -1, 0, 1, 1, 0, 0}, {30}, {1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 1, -1, -1, 1, 0, -1, 0, 1, 0, 1, 0, 1, 0, 0, -1, 1, 0, 0, -1, 0, 1, -1}, {31}, {1, 1, 0, 0, 1, -1, -1, 1, -1, 1, -1, -1, 1, 0, 0, 1, 0, 0, 0, -1, 1, 0, 1, 1, 1, 1, 1, -1, 0, 1, 1, 0, 1}, {32}, {1, 1, 0, 0, 1, -1, 1, -1, 0, 0, 0, -1, 1, 1, 1, 0, -1, 1, 1, 1, -1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, -1}, {33}, {1, 1, -1, 1, 0, -1, 0, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 0}, {34}, {1, -1, 0, 1, -1, 1, 1, 0, 1, 1, -1, -1, 0, 0, 1, 1, 1, 1, 1, -1, 0, 1, -1, 0, -1, 1, 0, 1, 1, 1, 1, -1, 1, 0, 0, -1}, {35}, {1, -1, 1, 1, -1, 0, 1, 0, 1, 1, 1, -1, -1, -1, 0, 1, 1, 0, -1, -1, 0, 0, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 0, 1, 0}, {36}, {1, 1, 0, 1, 1, 0, -1, 1, -1, 1, -1, 0, -1, 1, 1, 1, 0, 0, -1, 0, 1, 0, 1, 0, 1, -1, 1, 0, -1, 1, 0, 1, 0, -1, 1, -1, 0, -1}, {37}, {1, -1, 1, 0, 1, 1, -1, 1, -1, 1, -1, 1, 0, -1, 1, -1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, -1, 0, 0, 0, 1, 1, 0, -1, 1, -1, 1, 0}, {38}, {1, 0, 1, 1, 0, 1, -1, -1, -1, 0, -1, -1, -1, -1, 1, 1, 1, -1, 1, 0, 1, 1, -1, 0, 0, 1, 0, -1, 1, -1, 1, -1, 1, 1, 1, -1, 1, -1, 0, 0}, {39}, {1, 1, 0, 0, -1, 0, 0, -1, 1, 0, -1, 0, -1, 1, 1, 0, -1, 0, 0, 1, -1, -1, 0, 0, -1, 0, 1, 0, 1, 1, -1, 0, 1, 1, -1, -1, -1, 1, -1, 0, -1}, {40}, {1, -1, 0, 0, -1, 1, 1, 0, 0, -1, -1, -1, -1, 1, 0, 0, -1, 0, 1, -1, -1, -1, 1, 1, 0, -1, -1, 1, 0, 0, 0, 1, 0, 1, -1, -1, 1, 1, 0, 1, -1, 0}, {41}, {1, -1, 1, -1, 0, 0, -1, 1, 0, -1, 1, -1, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, -1, -1, 1, 0, -1, 1, 0, 1, 0, 0, 1, 1, 1, -1, -1, 1, 0, -1, -1, 1}, {42}, {1, -1, 1, 0, 1, 0, -1, -1, -1, 0, 0, 0, 0, -1, 1, -1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 0, 0, -1, -1, -1}, {43}, {1, -1, 0, -1, 1, 0, -1, -1, 0, -1, -1, 1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, 1, 0, -1, -1, 1, -1, 1, 0, -1, -1, 0, 1, -1, 0, 0, 0, 1, -1, 1, -1, -1, -1, 0}, {44}, {1, 0, 1, 1, -1, 0, 1, -1, -1, 0, 1, -1, -1, 1, 1, 0, 1, 0, 1, -1, -1, 1, -1, -1, -1, -1, -1, -1, 0, -1, -1, 0, 1, -1, -1, 1, 0, -1, 0, 1, 1, 0, 1, 1, 0, 1}, {45}, {1, -1, 1, 1, -1, 0, 1, 1, 0, -1, -1, 0, 0, 0, 0, 0, 1, -1, -1, 1, 0, 0, -1, 0, -1, 0, -1, 1, 0, -1, 0, 0, -1, 0, 0, 0, -1, -1, -1, 1, 0, 0, 0, -1, -1, 1, 0}, {46}, {1, -1, 0, 1, -1, -1, 0, -1, 0, 0, 0, 0, 1, 1, -1, 1, -1, 1, -1, -1, 0, -1, 1, -1, -1, -1, 0, 1, 0, 1, -1, 0, -1, 1, 0, 0, 0, -1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1}, {47}, {1, 1, 0, 1, -1, -1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, 0, 0, 0, 0, -1, 1, 0, -1, -1, 0, 1, -1, -1, -1, 1, -1, -1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1}, {48}, {1, 1, -1, 0, 1, -1, -1, 1, 0, -1, -1, -1, 1, -1, 0, -1, 0, -1, 0, -1, 0, 0, 1, -1, -1, 1, 1, 0, -1, 1, 1, 0, 1, -1, -1, -1, 0, 0, 1, -1, 1, 1, 0, 0, -1, 1, 1, 0, 1, -1}, {49}, {1, 0, 1, 1, 0, -1, 0, 0, 0, 1, 1, 0, -1, 1, 1, 1, 1, -1, 0, -1, -1, 1, 0, -1, 0, 1, 1, -1, -1, 0, 0, 1, -1, -1, 1, 1, 0, -1, 0, 1, 1, -1, 0, -1, -1, 0, 0, 1, 1, 1, -1}, {50}, {1, 1, -1, 0, -1, 1, 1, 1, -1, 0, 0, 0, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1, 0, 0, 1, -1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, -1, -1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, -1}, {51}, {1, 0, -1, 1, 1, 0, -1, 0, 1, -1, 1, 1, 0, 0, -1, 0, 0, 1, 1, -1, 1, -1, 0, -1, 1, 0, -1, 1, -1, -1, 0, 1, 1, -1, 0, 0, 1, 1, 1, 0, -1, -1, 1, 1, 0, 1, -1, 1, 0, -1, 0, 1, 0}, {52}, {1, -1, 0, 1, 0, -1, 1, -1, 1, 1, -1, 1, -1, 0, 0, -1, 0, -1, -1, -1, -1, 0, 1, 0, 1, 1, 0, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 0, 1, -1, -1, 0, 0, 0, 1, 0, 1, -1, -1, 1}, {53}, {1, 0, 1, 1, 0, -1, 1, 0, -1, 0, 1, 0, 1, 1, 1, 0, -1, 0, 1, -1, 0, -1, 0, 0, 0, 0, 1, -1, 1, 1, -1, 0, 0, -1, 0, 1, 0, -1, 1, 0, 0, 0, 0, 0, 0, -1, -1, 1, 1, 1, -1, 0, 0, 1, 1}, {54}, {1, 0, 1, -1, -1, -1, 0, 0, 1, 1, 0, 0, -1, 1, 0, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 0, 1, 1, -1, 1, 1, -1, 0, 0, -1, 1, 1, 0, -1, 0, 0, 1, 0, 0, 0, -1, 1, -1, -1, 0, 1, 0, 1, -1, 1, 0}, {55}, {1, 0, -1, 1, 1, 0, 1, -1, 0, 1, 0, 1, 0, 1, 0, 1, 1, -1, 0, 0, 1, -1, 1, 1, 0, 0, 1, -1, -1, 0, -1, 1, -1, 0, 0, -1, -1, 1, 0, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1, 1, 0, -1, 1, 0, 0, 0, 1}, {56}, {1, 1, -1, 1, 0, 1, -1, 1, -1, 1, 0, -1, 0, -1, 1, -1, -1, 1, 1, -1, 1, -1, 0, 1, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 1, 1, -1, 1, 1, 1, -1, -1, 0, -1, 0, 0, -1, 0, 1, -1, 1, 0, -1, 1, 1, -1}, {57}, {1, 1, 0, 0, 1, -1, -1, -1, 0, -1, 0, -1, -1, 0, 0, 1, 1, 1, 1, 1, 1, -1, -1, 0, 0, 0, 1, 0, -1, 1, -1, 0, 0, 1, 1, 0, -1, -1, 1, -1, -1, 0, -1, -1, -1, 1, 0, 1, 1, -1, -1, 1, 0, -1, 0, -1, 1, 0, -1}, {58}, {1, 0, 1, 0, 0, 0, -1, -1, 1, 1, -1, 0, 1, 0, -1, 1, 0, -1, -1, -1, 0, 0, 1, 1, 1, -1, 0, 0, 1, -1, 1, -1, 1, 1, 0, 0, -1, 0, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 0, 0, 0, 1, -1, 0, 1, -1, 0, 0, 0, 0}, {59}, {1, -1, 0, 1, 1, -1, -1, 1, 1, -1, 1, 0, -1, 0, 1, 0, 0, -1, 0, -1, 1, -1, 0, 0, 0, 1, -1, 0, 1, -1, 0, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 0, 0, -1, 0, -1, 1, 1, 0, 0, 0, 1, 1, -1, -1, 1, 0, 1, -1, 0}, {60}, {1, 0, 1, 0, 0, 0, -1, 1, -1, 0, 1, -1, 1, 0, 1, 0, 0, 0, -1, 0, 0, 1, 1, -1, 0, 0, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, 0, 0, 1, 0, -1, 1, 1, -1, 0, 1, 0, 1, -1, 1, -1, 1, 0, -1, -1, -1, 1, 0, 1, -1, -1, 0}, {61}, {1, -1, 0, 0, 1, 1, 1, -1, -1, 0, -1, 1, 0, 1, -1, -1, 1, 1, -1, 1, 0, -1, 1, 1, -1, 1, 0, -1, 1, 1, 0, 1, -1, -1, 0, 1, 0, -1, 1, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1, -1, 0, -1, 0, -1, 1, 0, -1, 0, -1, -1}, {62}, {1, 1, -1, 1, 0, -1, 1, -1, 0, -1, 1, 1, 0, -1, -1, 1, 1, -1, -1, 1, 0, -1, 1, 1, 1, 0, -1, 0, -1, 1, 0, -1, 0, 0, 1, -1, 1, -1, 0, 0, 0, -1, 0, -1, 0, -1, -1, -1, 0, -1, -1, -1, 0, -1, -1, -1, 0, 0, 1, 1, 0, -1, 1, 1}, {63}, {1, -1, 0, 0, -1, 1, 1, 1, 0, 0, -1, 0, -1, 1, -1, 0, -1, 0, -1, 1, 1, 0, 1, -1, 0, -1, 1, 0, -1, 0, -1, 0, 0, -1, -1, 1, -1, -1, 0, 0, 0, 1, 0, -1, 1, 1, 0, 1, 0, 1, 0, -1, 1, 0, 0, 0, 1, 1, 1, -1, -1, 0, 1, -1, 0}, {64}, {1, -1, 1, 0, -1, -1, 0, 1, 0, 0, -1, -1, 1, -1, 0, 1, 0, -1, 1, -1, 1, 1, -1, 0, 0, 0, 0, 1, 1, 1, 1, -1, -1, 0, -1, 1, 1, 1, 0, -1, -1, 0, -1, -1, 1, -1, -1, -1, 0, -1, -1, 0, 1, 0, -1, -1, 0, 1, 0, 0, 1, -1, 0, -1, 1, 0}, {65}, {1, -1, 1, -1, -1, 1, 0, 0, -1, 1, -1, 0, -1, -1, 1, -1, -1, 0, 0, -1, 0, -1, 0, -1, 1, -1, 0, -1, -1, 0, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 0, -1, 1, 1, 1, 1, -1, 1, -1, -1, 0, -1, 1, -1, -1, 0, -1, -1, 1, -1}, {66}, {1, 0, 1, -1, 1, 0, -1, -1, 0, 0, -1, 0, 0, -1, -1, 1, -1, 0, 0, -1, -1, 1, 0, 0, -1, 1, 0, -1, 1, 0, 0, -1, 0, 0, 0, 0, -1, 0, 1, -1, -1, -1, 0, 0, 0, 1, 0, -1, 1, -1, -1, 1, 1, -1, 0, 0, 1, 0, 0, 0, -1, -1, -1, 0, 0, 0, -1, -1}, {67}, {1, 1, -1, 1, 0, -1, 1, -1, 0, -1, -1, -1, -1, 0, 1, 0, -1, 0, 1, -1, 1, -1, 0, -1, 1, -1, 0, 0, -1, 0, -1, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1, 1, 1, 1, 0, 1, 0, -1, -1, 0, -1, 1, -1, 0, 1, 0, -1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1}, {68}, {1, 1, -1, 1, 1, 1, 0, 0, 1, 1, 0, -1, -1, 0, 1, 0, -1, -1, 0, 0, -1, 1, 0, 0, -1, 0, 0, 1, 0, 0, 1, 0, -1, 1, -1, 1, 1, 0, -1, -1, -1, 1, -1, 0, -1, 1, -1, -1, 0, 1, 1, 0, 1, 0, -1, 1, 1, 1, 1, -1, -1, 1, 0, 0, 1, 1, -1, 1, 0, 0}, {69}, {1, 0, -1, 1, -1, 1, 0, 1, 0, 0, 1, 1, 0, -1, -1, 0, 0, -1, -1, 0, 0, 0, 0, 1, 0, 0, -1, 1, -1, -1, 1, -1, 0, 1, 1, -1, -1, 1, 1, 1, -1, 1, 0, 1, -1, 1, -1, 1, -1, 1, 0, 0, -1, 1, 1, 1, 0, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 0, -1, 1, -1}, {70}, {1, 1, -1, 0, 0, 0, 1, 1, 0, -1, 0, -1, 0, 0, 1, 0, 1, -1, 1, 0, -1, -1, -1, 0, -1, 0, -1, 1, -1, 1, -1, -1, 0, -1, 0, 0, 1, 0, 0, -1, 1, -1, 0, -1, 1, 0, -1, 1, 1, 1, -1, 1, 1, 1, -1, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, 0, 1, 1}, {71}, {1, 0, 1, -1, 0, 0, -1, -1, -1, 1, 0, 1, -1, -1, -1, -1, 0, -1, 1, -1, 0, -1, -1, 1, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, 1, 1, 1, 1, -1, -1, 0, 1, -1, 1, -1, 0, -1, 1, 0, 1, 1, -1, -1, -1, 1, 0, -1, 0, -1, 1, -1, 0, 0, 0, -1, -1, 0, -1, 1, 1, -1, 0, -1}, {72}, {1, 1, 0, 0, 1, -1, 0, 1, 1, -1, -1, 0, 1, -1, 1, 0, -1, -1, 0, -1, -1, -1, 0, 0, -1, 1, 1, 1, -1, -1, -1, 0, 1, 1, -1, 0, -1, 1, 0, 1, 1, 1, 0, 0, 1, -1, -1, -1, 1, 1, -1, -1, 1, 0, 0, -1, 0, 0, -1, 1, 0, -1, 0, 0, -1, 0, 1, -1, -1, 0, -1, 0, 0, 0}, {73}, {1, -1, 0, 1, 1, 0, 0, -1, 0, 1, 1, 1, 1, 0, 1, -1, 0, 0, 1, 1, 1, -1, -1, 0, 0, -1, 0, -1, 1, 1, 0, -1, 1, -1, -1, 1, 0, -1, -1, 1, 1, 1, 1, 0, 1, 1, -1, 0, 0, 1, -1, -1, -1, 0, -1, 1, -1, 1, -1, -1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, -1, 0, -1, -1, -1}, {74}, {1, 0, -1, 0, 0, 0, -1, 1, 0, 0, -1, 1, 0, 1, 1, 0, 1, 1, 0, 0, -1, 1, 1, -1, 1, -1, -1, 0, -1, -1, 0, -1, 0, 0, 0, -1, -1, 0, -1, 1, -1, 0, -1, 0, 0, -1, -1, 0, -1, 0, 1, -1, -1, 1, -1, -1, -1, 1, 0, -1, 1, 1, -1, 0, 0, 0, 1, 1, -1, -1, 1, 0, 0, 1, -1, -1}, {75}, {1, 0, -1, 0, 1, -1, 1, 0, 1, 0, 0, -1, 0, -1, 1, -1, 0, 1, 1, -1, 1, -1, 1, 1, 0, 1, 1, -1, -1, -1, -1, 1, 1, -1, 0, 0, 0, -1, -1, -1, 0, -1, 1, 1, -1, 0, -1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 1, -1, -1, -1, 0, -1, -1, 0, 0, 0, 1, 1, 1, -1, -1, -1, -1, 1, 0, 1, 0}, {76}, {1, -1, 0, 0, -1, -1, -1, -1, 1, 1, 1, 0, 1, -1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, -1, 0, -1, 1, 0, 1, 1, 1, -1, 0, -1, -1, 1, 1, -1, -1, -1, -1, 0, -1, 0, 1, -1, -1, 1, 0, -1, 1, -1, 0, 1, 0, -1, 1, -1, 0, 0, 0, -1, 0, -1, -1, -1, 1, -1, -1, 1, 0, 1, -1, 1, -1}, {77}, {1, -1, 1, 1, -1, -1, -1, 0, 0, -1, -1, 0, 0, 1, -1, 1, 1, 1, -1, -1, -1, 0, 1, 0, -1, -1, 0, 1, 1, 0, 1, 1, -1, 1, 1, 0, 0, 0, 1, -1, 0, 0, 0, 1, -1, 0, 1, 1, 0, -1, -1, 0, 1, -1, -1, -1, -1, 1, -1, 0, 1, -1, 0, 1, 1, 0, -1, -1, 1, -1, -1, 0, 0, 1, -1, 0, 0, -1, 0}, {78}, {1, -1, 0, 0, -1, -1, 1, 0, 1, -1, -1, 0, 1, 1, 0, -1, -1, -1, 1, 1, 0, 1, 1, -1, -1, 1, 0, 0, 0, 0, -1, 1, 1, 0, 1, 1, 1, 0, 0, 1, -1, 1, 0, 1, 0, -1, 1, 1, -1, -1, 1, -1, -1, 1, 0, -1, 0, 1, 0, -1, -1, 0, -1, 1, 0, -1, 1, -1, 0, 0, -1, 0, -1, 1, 0, -1, -1, 0, 1, 0}, {79}, {1, -1, 0, -1, 1, -1, 1, 0, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1, 0, -1, 1, 0, 0, -1, 0, 0, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 0, 1, -1, 1, -1, 1, 0, 1, 1, 0, 1, 1, 1, -1, 0, 0, 1, 1, -1, -1, 1, 1, 0, 1, -1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, -1, 0, 0, 1, 1, 1}, {80}, {1, 1, -1, 0, -1, 0, 0, 0, 0, 1, 0, -1, 0, -1, -1, 0, 0, 0, 1, 1, 1, -1, 1, 0, 1, -1, -1, -1, -1, 0, 0, -1, 0, 1, 1, 1, 0, -1, -1, -1, -1, 1, 0, 0, -1, 1, -1, 0, 1, 0, 1, 0, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, -1, 0, -1, 1, 0, 1, -1, 1, -1, 0, 1, 0, -1, 0, 0, 1, 1, -1, -1, 0}, {81}, {1, 1, -1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 0, -1, 0, -1, 0, -1, -1, 0, 0, -1, -1, -1, 1, -1, 0, 0, -1, -1, 1, 1, 1, 1, 0, 1, -1, 1, 0, 0, 0, 0, 1, 1, 0, -1, -1, -1, 0, 0, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 0, -1, -1, -1, 1, 1, 1, 0, 0, 1, -1, -1, -1, 1, 0, 1, 1, 1}, {82}, {1, -1, 1, -1, 0, -1, -1, 0, 1, 1, 1, 0, 0, 0, 1, -1, 1, 0, 1, -1, 1, -1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, -1, 0, -1, 1, -1, 1, 1, 1, 1, -1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 1, 1, -1, -1, 1, 0, -1, -1, -1, 0, -1, 1, 1, 0, -1, 0, 0, -1, -1, 0, 1, -1, 1, 0, 0, 1, -1, -1, -1, 0, 0, 1}, {83}, {1, -1, 0, 1, 0, 0, 0, -1, 0, 1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, 0, 1, 0, 1, -1, -1, -1, 0, -1, 1, -1, -1, 1, 0, -1, 0, 0, 0, 1, -1, 0, 1, -1, 1, -1, 0, 1, 0, 1, -1, 0, -1, -1, -1, -1, 0, -1, 0, -1, 1, -1, 0, -1, 0, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, 0, -1, 1, 0, 1}, {84}, {1, 0, -1, -1, 0, 1, -1, 1, 1, 1, 0, -1, 1, -1, 1, 0, 0, 0, -1, -1, 1, -1, -1, 0, 0, 1, 1, -1, 0, 0, 0, 1, 1, 0, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 0, 0, 0, -1, 1, 0, -1, 1, 1, -1, 0, 0, -1, -1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, -1, 0, 1, 0, 0, 1, -1, 1, 0, -1, -1, 1, 0, 1, 1, 1, -1}, {85}, {1, -1, 0, 1, 0, -1, 1, -1, -1, 1, 0, -1, -1, -1, 0, -1, -1, -1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1, 0, 1, -1, 1, 1, 1, 1, 1, 1, 0, 0, -1, 1, -1, 1, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 1, 0, 1, 0, -1, 0, 0, 1, 0, -1, 0, 1, -1, 1, 1, 0}, {86}, {1, 1, -1, 0, -1, 1, 1, 1, 1, -1, -1, 0, -1, 1, 0, 1, 0, -1, 0, 0, -1, -1, 1, 0, 0, 1, 1, -1, -1, 1, 1, 1, 1, 0, -1, 0, -1, -1, -1, 0, 0, 0, 1, 1, -1, 0, 0, 0, 1, 0, -1, -1, 1, -1, 0, -1, 1, 0, -1, -1, 0, -1, -1, 0, 1, 1, 1, -1, -1, -1, 0, 1, 0, -1, 1, 1, -1, 0, 0, 1, -1, 1, 1, -1, 1, 0, 0, -1}, {87}, {1, 0, 1, 1, -1, 1, -1, -1, -1, 0, 0, 0, 0, 0, 1, -1, 0, 1, 1, -1, -1, -1, 0, -1, 1, 0, 1, -1, -1, -1, -1, -1, 1, -1, 1, 0, 0, 1, 0, 1, 0, 1, -1, 1, 1, -1, 1, 0, -1, -1, 1, 0, -1, -1, 1, 1, 0, 1, 1, 1, 1, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, -1, -1, 1, 0, -1, -1, 1, 1}, {88}, {1, 0, 1, 1, 0, 0, 0, -1, -1, -1, 0, 1, 0, 1, 0, 1, 1, 0, 0, -1, -1, 0, -1, -1, -1, 1, 0, -1, 0, -1, -1, 1, -1, -1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, -1, 0, -1, 1, -1, 0, 1, -1, 1, 1, -1, -1, -1, 0, 0, -1, 0, 0, -1, -1, 0, 0, -1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -1, 1, 1}, {89}, {1, 1, 0, 1, -1, 0, -1, -1, 1, 1, -1, 0, 1, -1, 0, 1, 1, 0, 0, 0, 1, -1, -1, 1, 0, -1, 0, 0, -1, -1, 0, 1, -1, 1, 1, 0, 0, 0, 1, -1, -1, -1, 1, 1, 1, 0, 1, 0, 1, 0, -1, 1, 1, -1, 1, 1, 1, 0, 0, 1, 1, -1, 1, -1, -1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, -1, -1, 0, -1, 1, 0, -1, 1, -1, -1, 0, 1, 1, -1, 1}, {90}, {1, 0, -1, 0, 1, 1, -1, -1, 1, 0, 1, -1, 1, -1, 0, 1, -1, 1, 1, 0, 0, -1, 0, 1, 0, -1, 0, 1, 0, 1, 1, -1, 1, -1, 1, 0, 1, 1, 1, -1, -1, 1, 0, -1, -1, -1, -1, -1, -1, 1, 1, 0, 1, 1, -1, 0, 1, 0, 1, 0, 1, 1, 1, 0, -1, 0, -1, -1, 0, 0, -1, 1, -1, -1, 1, 0, -1, -1, 1, -1, -1, -1, 1, -1, 1, -1, 1, 0, 1, 0, -1, 1}, {91}, {1, 1, 0, 1, -1, 0, 1, -1, -1, -1, 0, -1, -1, -1, 1, 0, -1, 1, 1, -1, 1, 0, 1, -1, 1, 0, 1, 0, 0, 0, 1, -1, -1, -1, -1, 0, 0, -1, 0, 1, -1, -1, 0, 0, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, -1, -1, -1, -1, -1, 1, -1, 0, -1, 1, 1, 1, -1, 0, 1, 0, 1, 1, 0, 0, 1, 0, -1, 1, -1, 1, -1, -1, 1, 0, -1, 1}, {92}, {1, 0, 1, 1, -1, -1, -1, 0, 0, 0, -1, 0, 0, 1, 1, -1, 1, 1, -1, 1, 1, -1, -1, 0, 1, 0, 0, -1, 1, -1, 0, 1, 0, -1, 1, 1, 0, 1, -1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, -1, -1, 0, 1, -1, -1, 1, 0, 0, 0, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 0, -1, 1, -1, 0, -1, 1, -1, -1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1}, {93}, {1, -1, 1, 0, -1, -1, 1, 1, 0, -1, 0, 0, -1, 1, -1, -1, -1, 0, 0, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, -1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, -1, -1, -1, 0, 0, -1, 1, 1, -1, 0, 1, -1, 0, 1, 1, 0, 0, 1, 0, 0, -1, 0, -1, 1, -1, -1, 0, -1, -1, 1, 0, 0, -1, 1, -1, 0, -1, 1, -1, 0, -1, 0, 0, 1, 0, 0, -1, 1, -1, 1, 1, 0, 0, 1, 0}, {94}, {1, 1, 0, 1, 1, -1, -1, 1, 1, -1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0, 1, -1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, 0, -1, 1, 0, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 0, 1, 0, 1, 1, -1, -1, 0, 0, -1, 0, 0, 1, -1, -1, 0, 0, -1, 1, 0, 1, -1, 0, 0, -1, 1, 0, 1, 0, -1, -1, -1, -1, 1, -1, -1, 1}, {95}, {1, 0, -1, -1, 1, -1, 1, 1, -1, 1, -1, 0, 1, 0, 0, -1, 1, -1, 0, -1, 1, -1, 1, 1, 0, 1, 0, 1, -1, 1, 1, -1, 0, -1, -1, 0, -1, 0, -1, 1, 0, -1, -1, -1, -1, 1, 0, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 0, 1, 1, 1, -1, -1, -1, 1, 0, 0, -1, 1, 1, 1, 0, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 0, 0, 1, -1, -1, -1, 1, 1}, {96}, {1, -1, 1, 0, 0, -1, -1, 1, 0, 1, 1, -1, -1, 1, 0, -1, 0, 0, 1, 1, 0, 0, 0, -1, -1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, -1, 1, 1, -1, 0, -1, 0, 1, 0, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 0, -1, -1, 0, 0, -1, 1, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, -1, -1, 0, 1, 0, -1, -1, -1, 0, 0, -1, 0, 1, 0, -1, -1, 0, 0, 1, 1, 0, -1}, {97}, {1, 0, -1, 1, 1, 1, 0, 1, -1, -1, -1, -1, 1, 0, -1, 1, -1, -1, -1, 0, -1, 0, 1, 0, 1, -1, -1, 0, -1, 0, 0, 0, -1, 1, 0, -1, 1, 1, 1, 1, -1, 0, 0, -1, 1, 0, 1, 1, 0, -1, 0, 0, 1, -1, -1, 0, 0, 1, 1, 1, -1, 0, 0, 0, -1, 1, -1, 1, 1, 1, -1, 1, -1, 0, 0, 0, 1, -1, 0, 0, 0, -1, -1, -1, 0, -1, 1, -1, 1, 1, 1, 0, 0, 0, -1, 0, -1, -1, 1}, {98}, {1, -1, 0, 0, 1, -1, -1, 1, 1, 1, 0, -1, -1, 0, 0, 0, 1, 0, 1, -1, 0, -1, -1, 1, 1, 0, -1, 1, 1, -1, 1, 1, -1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, -1, 1, -1, 1, 1, 1, 0, 1, 1, -1, -1, 0, -1, 0, 1, 1, 1, -1, 1, 1, -1, -1, 0, -1, -1, 1, -1, 1, 0, 1, 0, 1, 0, -1, 1, -1, -1, 0, -1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, -1, -1, 0, 0, 0, -1}, {99}, {1, -1, 0, -1, -1, 1, 0, 0, -1, -1, 0, -1, -1, 0, 0, 0, 1, 1, -1, -1, 0, 1, -1, -1, 1, -1, 1, 0, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, 1, 0, 0, -1, 1, -1, -1, -1, 1, -1, -1, 0, -1, 0, 0, 1, 0, -1, 1, -1, -1, -1, 0, -1, -1, 1, -1, -1, 0, -1, 1, 0, 0, -1, 1, 0, 0, 1, 1, 0, 1, 1, 1, -1, -1, 0, -1, -1, 1, 1, 0, -1, -1, 1, -1, 0, 0, 1, -1, -1, 1}, {100}, {1, -1, 1, 1, 0, 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, 0, 1, 0, 1, 0, 0, 0, -1, 1, -1, 0, -1, -1, 0, -1, 1, 0, 1, 1, 0, -1, -1, -1, 0, -1, -1, 0, -1, -1, 0, -1, 0, -1, 1, 0, 1, 1, -1, -1, 1, 1, 1, 1, 1, 0, -1, 1, 0, -1, 0, 1, 0, 0, -1, 1, 1, -1, -1, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 1, -1, 1, 0, -1, 1, -1, 1, -1, 1, -1, 0, 0, 1, 1, 1, 1, 1}, {101}, {1, 1, 0, -1, -1, 1, -1, -1, 0, -1, 1, -1, 0, 1, 0, -1, -1, 0, 1, 1, -1, 0, 0, -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 0, 1, 0, 1, -1, 0, -1, 0, 0, 1, -1, 0, 0, -1, 0, 1, -1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, -1, 1, -1, 0, -1, 0, -1, 1, 0, 1, 0, -1, 0, -1, 1, 1, 0, 1, 0, 1, 0, 0, 0, -1, 1, 1, -1, -1, -1, 1, 1, 0, 0, 0, -1, 1, -1, 0, -1, 1, -1, 0, 0}, {102}, {1, -1, 1, -1, -1, 0, 1, -1, 0, 0, 0, 1, 0, -1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, -1, 1, 0, -1, 0, 0, 0, 1, 0, 0, -1, 1, 1, -1, 1, -1, 1, 0, -1, -1, 0, -1, -1, -1, 1, 1, -1, 0, 0, -1, -1, 0, -1, 1, 1, 0, -1, 0, 0, 1, -1, 0, 1, -1, 0, 0, 0, 0, 1, -1, 1, 1, 0, 0, -1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, -1, 0, 0, 1, 0}, {103}, {1, -1, 1, 1, -1, 0, 0, 0, -1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, -1, 1, 0, 1, -1, 0, 0, -1, -1, -1, 1, -1, -1, 0, -1, 1, -1, -1, 0, -1, 1, 0, 0, 0, 0, 1, 0, 0, -1, 1, 1, -1, 0, 1, -1, 0, -1, 0, 1, -1, 1, 0, -1, -1, -1, 0, 1, 0, 1, 0, 1, 1, 1, 0, -1, 0, -1, 0, -1, -1, 0, 1, 0, 1, 1, 0, 0, -1, 0, -1, -1, 0, 1, 1, 1, 0, -1}, {104}, {1, 0, 1, -1, 1, -1, -1, 1, -1, 0, -1, -1, 1, 0, 1, 1, 0, 1, 1, -1, -1, 1, 0, -1, 1, 0, 1, -1, 0, 0, -1, 0, -1, 1, 1, 1, -1, -1, 1, -1, 0, -1, -1, -1, 1, -1, 0, -1, -1, -1, -1, 1, -1, 1, -1, 0, -1, -1, 0, -1, 1, 1, 0, 1, 0, 0, 1, -1, 0, 1, -1, -1, -1, 1, 0, 1, -1, -1, 1, 0, 0, 1, 0, 1, 1, 0, 0, -1, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, 1, -1, 0, 0, 0, 0, -1, -1}, {105}, {1, -1, 0, -1, 1, 0, 1, 1, -1, 1, -1, 1, -1, 1, 0, -1, 0, -1, 1, 1, 1, -1, 0, -1, -1, 1, 1, 0, 0, -1, 0, -1, 0, -1, 1, -1, 0, 0, -1, -1, -1, -1, -1, 0, 0, 0, 1, -1, -1, 0, 1, 1, 0, 0, -1, 1, -1, -1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0, -1, 1, 1, 0, 0, 0, -1, 1, 0, -1, 1, -1, -1, -1, -1, 1, -1, 1, -1, 0, 0, 1, 0, 0, -1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, -1, -1, 0}, {106}, {1, 0, -1, 0, 0, 1, 1, 1, -1, -1, 0, 1, 1, -1, -1, 1, 1, 0, 0, 1, -1, -1, -1, 0, 1, 0, 1, -1, 0, 0, -1, -1, 1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, -1, -1, -1, -1, 0, 0, -1, -1, -1, 1, -1, 0, -1, 0, 1, -1, 1, 0, 1, -1, 1, 0, 1, 0, -1, 1, 0, 1, 1, 0, 0, -1, 1, 1, -1, 0, -1, 0, 1, -1, -1, 1, 1, 0, 1, 1, 1, 0, -1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0}, {107}, {1, -1, 1, 1, -1, -1, -1, -1, 1, 0, 0, -1, -1, -1, 0, 0, 0, 0, -1, -1, 1, 0, -1, -1, 1, 0, 1, 0, 0, 0, 0, -1, 0, -1, -1, 0, 1, 0, 1, 0, 1, 0, 1, -1, 0, -1, 1, -1, 0, 1, 1, 0, 0, 1, 1, -1, 0, 1, 0, -1, -1, 0, 0, 1, 1, 1, -1, 0, 0, -1, 0, 0, 0, -1, 0, -1, 1, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, -1, -1, 0, -1, 0, 1, 1, -1, 1, 0, 0, 0, 0, 1, -1, 1, 1, 0, 0, 1, -1, -1}, {108}, {1, -1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, -1, 1, -1, 0, 0, -1, -1, -1, -1, -1, -1, 1, 1, 1, 0, 0, -1, 1, -1, 1, -1, 0, -1, 1, -1, 0, -1, 0, -1, 1, 0, 0, -1, 1, 1, 0, 1, 0, -1, -1, 1, 0, 0, 0, -1, 1, -1, -1, -1, 1, -1, -1, 0, 1, -1, 0, -1, 1, -1, 0, 1, 0, 1, 1, 1, -1, 1, 1, 1, 1, -1, 0, -1, 1, -1, 0, 0, 0, 1, 0, 0, -1, 1, 1, 1, 0, -1, -1, 0, -1, 1, -1, -1, 1}, {109}, {1, -1, 0, -1, -1, 0, 0, 1, -1, 0, 0, -1, 1, 1, 0, 1, 0, 0, 1, -1, 1, 0, 0, -1, 1, -1, 1, 0, -1, -1, 0, 1, 0, 0, 0, 0, -1, -1, 0, -1, 0, -1, 0, 0, -1, 1, 0, 1, 1, -1, -1, 0, 1, 0, 0, 1, 1, 0, -1, 1, 1, -1, -1, 0, 0, 0, -1, 1, 0, 1, -1, -1, -1, 1, 1, 0, 0, 0, -1, 0, 0, -1, -1, 0, 1, 1, 0, 0, 1, -1, 1, 0, 0, 1, 1, 1, 0, -1, 1, 1, 1, 1, -1, 0, 0, -1, 1, 0, 0, -1, 1}, {110}, {1, 1, 0, 1, 1, 0, -1, 1, 1, -1, 1, 1, 0, 0, 0, -1, 1, -1, 0, 0, -1, -1, -1, -1, 1, -1, 0, -1, -1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 0, 0, -1, -1, 0, 1, 0, 1, 0, 1, -1, 0, -1, 1, -1, 0, -1, -1, 1, -1, -1, 1, 0, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, 0, 1, -1, 0, 0, 0, 1, 0, 1, 1, -1, 0, 1, 1, -1, 0, -1, 1, -1, 1, -1, 1, 1, -1, 0, 1, -1, 0}, {111}, {1, -1, 1, -1, 0, 1, 1, -1, -1, 1, -1, 0, -1, 0, 1, 0, -1, -1, 1, 1, 0, 0, 1, 0, -1, 1, -1, 0, 1, 0, 1, 1, 0, 1, -1, -1, 0, -1, -1, 0, -1, 1, 1, 0, 0, 1, -1, 0, -1, 1, 1, 1, 1, 1, -1, 1, 0, 1, 0, 0, 0, -1, 1, -1, -1, -1, 0, 0, 0, 1, -1, 1, 1, -1, 0, -1, -1, 0, 1, -1, 0, 1, -1, -1, 1, 1, -1, -1, 1, 0, 1, -1, 1, 0, 0, 1, 1, -1, 0, -1, -1, 1, 0, -1, -1, 1, -1, -1, 0, -1, 0, 1, -1}, {112}, {1, -1, 0, 1, 1, 1, 0, 0, 1, 0, 0, -1, -1, 0, 0, 0, 0, -1, 1, 0, 1, 1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 0, 0, 0, 1, -1, 1, 0, 1, 0, -1, -1, -1, 1, 0, -1, 1, 0, -1, -1, 0, -1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, -1, -1, 0, -1, 0, 0, 0, -1, -1, 1, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, 0, 0, 1, 0, -1, 1, 0, 0, -1, -1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, -1, 1}, {113}, {1, 1, -1, 1, 1, 1, 0, -1, 1, -1, 0, 0, 1, -1, 0, 1, 0, -1, -1, -1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, -1, 1, 1, 0, 0, 1, 1, 1, 0, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 0, 1, 1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, -1, 0, 1, 0, 0, 0, -1, -1, 0, 0, 1, 0, -1, 1, 0, -1, 1, 1, 1, 0, 1, -1, 1, -1, -1, 0, 0, -1, -1, 0, 0, 0, -1, -1, 1, 1, 1, 0, 0, 0, -1, -1, -1, -1, 1, 0, 0, 1, 0, -1, 0, -1}, {114}, {1, -1, 1, 0, 0, 1, 0, -1, 0, 1, 0, 0, 1, 1, -1, -1, 0, 1, 1, 0, -1, -1, -1, 0, 0, -1, -1, 1, 1, -1, -1, 1, -1, -1, 0, -1, 1, -1, -1, 0, 1, -1, 1, 0, -1, -1, 1, 0, 1, -1, -1, -1, 0, 0, 0, 1, 1, 0, 0, 0, -1, 1, 0, 0, 1, 1, 0, 1, -1, -1, 0, 1, -1, -1, 1, 0, 0, 1, -1, -1, 1, -1, 0, 0, 1, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, -1, -1, 1, -1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, -1, -1, 1, -1, 0}, {115}, {1, 1, -1, -1, 0, 1, -1, 0, 0, -1, 0, 0, -1, 1, 0, 0, 1, 0, 0, -1, 1, 0, -1, 0, 0, 1, 1, -1, -1, -1, -1, -1, 1, -1, 0, 0, -1, -1, 1, -1, -1, -1, 0, 0, -1, -1, -1, -1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, -1, 1, 1, 0, 1, -1, 0, 0, -1, -1, -1, 0, -1, -1, 1, -1, 0, 0, -1, -1, 0, 0, 0, -1, -1, -1, -1, 1, 1, 0, 0, -1, 1, 0, -1, 1, 0, 0, 0, -1, -1, 1, 1, -1, -1, -1, 0, 0, 1, 0, -1, -1, 0}, {116}, {1, 0, -1, 1, 1, 1, 0, 1, -1, -1, 1, 1, -1, 0, 0, -1, -1, 0, 0, 0, -1, 1, 1, -1, 1, 1, 1, 1, 0, -1, -1, 0, 1, 0, -1, 1, 1, -1, 0, -1, -1, 0, 1, -1, 0, 0, 1, 0, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, -1, -1, 1, 0, 0, 1, 0, 1, 0, -1, 1, -1, -1, -1, 1, 0, 0, -1, 1, 0, -1, 0, 1, 0, 1, -1, 1, 0, 0, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, -1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, -1, -1, 0, -1, 0, 0, 1, -1}, {117}, {1, 0, -1, -1, 1, 0, -1, 0, 1, 0, 0, 0, 0, 0, 1, 0, -1, 1, -1, -1, 1, 1, -1, -1, 0, 1, -1, -1, 0, 0, -1, 0, 1, -1, -1, 0, 0, 0, -1, 1, 1, 1, -1, -1, -1, 1, 1, 0, 1, 1, 0, 0, 1, -1, 1, 0, 1, 1, 1, 0, 0, 1, 0, -1, -1, 0, 1, 1, 1, 1, 0, -1, 0, 1, 0, -1, 1, 0, 1, 0, -1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, -1, 1, 1, -1, -1, 0, 1, 0, -1}, {118}, {1, 1, -1, -1, 0, -1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, -1, -1, 1, 1, -1, -1, -1, -1, 0, 1, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 1, 1, -1, 0, 0, 1, 0, -1, 0, 1, -1, 0, 0, -1, 1, 0, -1, -1, 1, 0, 1, -1, -1, 1, 1, -1, 0, -1, -1, 1, 1, 1, 1, 1, 0, -1, 1, 1, 0, -1, -1, 0, 1, 0, 1, 1, -1, -1, -1, -1, -1, 1, -1, 0, 1, 1, 0, -1, 0, 1, 1, -1, 1, 1, 0, 0, -1, -1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0}, {119}, {1, 0, -1, -1, 1, -1, -1, 1, 1, 0, -1, 0, 1, 0, 0, -1, 0, 1, 1, -1, 1, -1, 1, 1, 1, 0, -1, 0, -1, -1, -1, -1, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, -1, 1, 1, 1, 1, 1, -1, 0, -1, -1, -1, -1, 0, 0, 1, -1, 0, 1, -1, 0, -1, 0, -1, 1, 1, 0, -1, 0, 1, 0, -1, -1, -1, -1, -1, 0, 1, 0, 1, -1, 0, -1, 0, 0, 1, -1, 0, 0, 1, 1, 1, 0, -1, 0, 0, 1, 1, 1, 0, 1, 0, 1, -1, 1, -1, 0, -1, 1, 1, -1, 0, -1, 0, 1, 1, -1, -1}, {120}, {1, 1, -1, -1, 0, 0, 0, 0, -1, 0, -1, -1, 1, -1, -1, 1, 1, 0, -1, 1, 1, 1, -1, 0, 0, -1, -1, 1, -1, 0, -1, -1, -1, 1, -1, -1, -1, -1, 0, 1, 0, 1, 1, 0, -1, -1, 0, -1, 0, 0, -1, 1, 0, 0, -1, 0, 1, 0, -1, 1, 1, 0, -1, 0, -1, 0, 0, 1, 0, -1, 0, 0, -1, 0, 1, -1, 1, 0, 0, 0, -1, 1, -1, 1, 0, 0, 0, -1, 1, 0, -1, -1, 0, 0, 0, 1, 1, -1, 1, 1, 0, -1, -1, 0, 1, -1, 1, 0, 1, 0, -1, -1, -1, 0, 1, 1, -1, 0, -1, -1, -1, -1}, {121}, {1, 0, 1, -1, 1, 1, 0, 1, 1, 0, 1, 1, -1, 0, 1, 1, 1, 1, -1, 0, 0, 1, -1, -1, 0, 1, -1, -1, -1, 1, -1, -1, 0, -1, -1, 0, 1, 1, 0, 1, 0, 0, 0, 1, -1, 0, 1, -1, 0, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, -1, 0, -1, 0, 0, -1, 1, 1, -1, 1, 0, 1, 0, -1, 0, -1, 0, -1, -1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, -1, -1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 1, 0, 0, 0, -1, -1, 0, -1, 1, -1, 1, 0, 0, 0, 0, -1, 1, 0, 1, -1, 0, -1}, {122}, {1, -1, 0, 1, -1, 1, -1, 0, -1, 0, 1, 0, 0, -1, 1, 0, 0, -1, 0, 1, 0, -1, 1, -1, -1, 0, 0, -1, 1, 1, 1, -1, 0, 0, 1, 0, -1, -1, 1, 1, 0, 1, -1, -1, -1, 0, 0, 1, 1, 1, 1, -1, -1, 0, 0, -1, -1, 1, -1, -1, -1, 0, -1, 0, 1, -1, 1, 0, -1, 1, -1, 1, 1, 0, 1, -1, 1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 0, 0, 1, 1, 0, 0, -1, 1, 0, 0, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 0, -1, 1, 1, 1, -1, 0, 1, -1, 0, 0, 0}, {123}, {1, 0, -1, -1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, 1, 0, 1, -1, 1, -1, -1, 1, 0, -1, 0, -1, 0, -1, 1, 1, 1, -1, -1, -1, -1, -1, 1, 0, 1, 0, -1, -1, 1, 0, 0, 1, 0, 0, -1, -1, 0, -1, -1, -1, 0, 1, 0, -1, -1, 0, 0, 1, -1, 0, -1, -1, 1, -1, 0, 0, 1, 0, 1, -1, -1, -1, -1, 0, 1, -1, 1, 0, 0, 0, 1, -1, -1, 0, 0, 0, -1, 1, -1, -1, 0, 1, -1, 0, 1, 1, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, -1, 0, -1, 1, 1, 1, -1, -1, 0, 0, 0, 0, -1, -1}, {124}, {1, -1, 0, -1, 1, -1, 1, 0, 1, 0, 0, 1, 0, -1, 1, 0, 1, 0, -1, -1, 0, 0, 0, 0, 1, 0, 1, 1, 1, -1, 1, 1, 0, -1, -1, 0, 0, -1, 1, 0, 1, -1, -1, -1, 0, 0, 1, 0, -1, -1, 1, -1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, -1, 0, -1, 1, -1, -1, -1, 0, -1, 1, 1, -1, 0, 0, 0, 0, 0, -1, 1, -1, 1, 0, 0, 0, 0, 0, -1, -1, -1, 1, 1, -1, 1, 0, -1, 1, 0, 0, 0, 0, -1, 1, -1, 0, -1, 0, -1, 1, 0, 1, 1, 0, 0, 0, 1, 1, -1, -1, 0, 0}, {125}, {1, 0, 1, 1, -1, 0, 1, -1, -1, 0, 0, 1, 1, 1, 0, 0, 0, -1, -1, 1, -1, 1, 0, 0, 1, 0, -1, -1, 1, 1, -1, 1, -1, -1, 1, 0, 1, 0, 0, 1, 0, -1, 1, 0, 1, -1, 1, 0, 0, 0, -1, 0, -1, 1, 0, 1, -1, 0, -1, -1, -1, 0, -1, 0, 1, -1, 1, 0, 1, -1, -1, -1, 0, -1, 0, 0, -1, 1, 1, -1, -1, -1, 1, 0, -1, -1, 0, -1, 1, 0, 0, -1, -1, 1, 1, 1, -1, 0, 0, 1, -1, 0, -1, 0, -1, 1, -1, 0, 1, -1, 0, -1, 1, 0, 1, 1, 1, -1, 0, 0, -1, -1, -1, -1, 1, -1, -1}, {126}, {1, -1, 0, 1, -1, -1, -1, -1, 0, -1, 0, 0, 0, -1, 0, 0, 1, 1, 0, -1, 1, 0, 0, 1, 0, 1, 1, 1, -1, 1, 1, 0, 1, -1, 0, -1, -1, 1, 0, 1, 1, -1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, -1, 0, 0, -1, 0, 1, -1, -1, 0, 1, -1, 1, 0, 0, -1, -1, -1, -1, 1, 0, 1, -1, -1, 0, -1, 1, 1, 0, 1, 0, 1, -1, -1, -1, -1, 1, -1, -1, 1, 0, -1, -1, 0, 0, 1, 1, 0, 0, -1, 0, 1, -1, 1, -1, 1, -1, -1, 0, 1, 1, -1, 0, 1, 0, -1, -1, -1, -1, 0, -1, -1, 1, 1, 1, 0}, {127}, {1, 0, 1, -1, -1, -1, 0, -1, 0, 1, 0, 1, 1, 0, 0, -1, 0, 1, 0, -1, -1, -1, 1, -1, 0, 0, -1, -1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, -1, 0, 0, 0, 1, -1, 0, 0, 0, 0, -1, 1, -1, 0, 0, 1, -1, 0, 1, 1, -1, 0, 0, 1, -1, 0, 1, 0, 1, -1, -1, 1, 1, 1, 1, 1, 1, -1, 0, 0, 1, 1, -1, 1, 0, 0, 1, 0, -1, 0, -1, 0, 1, 1, -1, 0, 1, 1, -1, 0, 0, 0, 1, -1, 0, 0, -1, -1, 0, 1, 1, -1, 0, 1, -1, -1, 1, -1, 0, 1, 1, -1, -1, 1, -1, 0, 0, 1}, {128}, {1, 0, -1, -1, 0, 0, 0, 0, 1, 0, 1, 1, 1, -1, 0, -1, -1, 0, 1, 0, 1, -1, 1, 1, -1, -1, 0, 1, -1, 1, 0, -1, 0, 0, -1, 1, -1, 1, -1, -1, 0, 1, -1, 1, -1, -1, 1, 0, 0, 0, 1, -1, 1, 1, -1, 0, 1, 1, -1, -1, 1, 1, 0, -1, 1, 1, 1, -1, 1, 1, -1, 0, 1, 1, -1, 1, 1, 1, 1, 0, 1, 0, -1, 0, 1, -1, 1, 0, -1, -1, -1, 1, -1, 0, -1, 1, 0, 1, 1, 0, 1, 0, -1, 1, 0, -1, 1, -1, 0, 0, 1, -1, 0, 1, 0, -1, 0, 1, 1, 1, 1, 1, -1, -1, 0, -1, -1, -1, -1, -1}, {129}, {1, 0, -1, 1, 0, 0, 1, 1, -1, 1, 1, 1, 1, 0, 1, -1, -1, 1, 0, 1, -1, 1, 1, 0, 1, 1, -1, 1, 1, 0, -1, 0, -1, 0, -1, 1, -1, 1, 0, -1, 1, 1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, -1, 0, 1, -1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 1, 1, -1, 1, 1, 0, 1, -1, 1, 1, -1, 1, 0, -1, 1, -1, -1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, -1, 1, -1, -1, 1, 0, 1, -1, 1, 1, -1, 1, 0, -1, 1, 1, -1, 0, 0, 0, 0, -1, -1, -1, -1, 0, -1, 0, 0, -1}, {130}, {1, 1, 0, 1, 1, 1, -1, 0, 1, -1, 0, -1, 0, 1, -1, -1, 0, 1, 1, 0, -1, 1, 0, -1, 1, -1, -1, 1, 1, 0, -1, -1, 0, 1, 0, 0, 1, 1, 1, 1, -1, 1, 1, 0, 1, 0, 1, -1, -1, 0, 1, 0, 0, -1, 1, 1, -1, 1, 0, -1, 1, 1, 1, 0, 1, 0, 1, 1, -1, 1, 0, -1, 0, 0, -1, -1, 1, -1, 0, -1, -1, -1, 1, 0, -1, 0, 0, 0, 1, 0, 1, 0, 0, 0, -1, 0, 1, 1, -1, -1, 1, 1, 0, 0, -1, 0, 1, -1, -1, 0, 0, -1, 0, 0, 1, -1, 1, 0, 0, 1, -1, -1, -1, 0, 1, -1, 1, 1, -1, -1, 1, -1}, {131}, {1, 1, 0, 1, 1, 1, -1, -1, -1, 0, 0, 0, -1, 1, 1, 1, 0, -1, 1, -1, -1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, 0, 0, -1, 0, 1, -1, 0, -1, -1, 1, 0, 1, 1, -1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, -1, 0, 1, 1, -1, 1, 0, -1, 1, 0, 1, 0, 1, 0, -1, 0, -1, 1, 0, 1, 1, 0, 1, 0, -1, 0, 0, 1, 0, -1, 1, -1, 0, 0, 1, 1, 0, 0, -1, 0, -1, -1, 0, 1, 0, 0, 0, 1, 1, -1, 1, 0, 0, 1, -1, -1, -1, 0, 1, -1, 1, 1, -1, 0, 0, 1, 0, -1, 0, 0, 0}, {132}, {1, -1, 1, 0, 0, 1, 1, -1, 1, 0, 1, 1, 0, -1, 1, -1, 0, 0, -1, 0, 1, -1, 1, 0, 1, 0, -1, 1, -1, 0, 0, -1, 1, -1, 1, 0, -1, 1, 1, 1, -1, 0, 1, 1, 1, 1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, -1, 0, 1, 1, 1, -1, 1, 0, -1, -1, 0, -1, 1, 1, 0, 0, 0, -1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 1, -1, 1, 0, -1, 0, 0, -1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 0, 1, 0, 0, -1, 1, 1, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, -1, -1, 0, 0, 1, 0, 1, -1, 0, -1, 0, -1, 0, -1, 0}, {133}, {1, 0, -1, -1, 1, -1, -1, 1, 1, -1, -1, 0, 1, 0, 1, -1, 1, 0, -1, -1, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, -1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, 1, -1, 0, 0, 0, 1, 0, -1, 1, -1, 0, 0, -1, 1, -1, -1, 0, 0, 1, 0, 1, -1, 0, -1, -1, 1, -1, 0, 0, 0, 0, 0, 1, 0, -1, -1, 0, 0, 0, 0, 1, -1, -1, -1, -1, 0, 0, 1, 1, 0, 0, 1, 1, -1, -1, -1, 0, -1, 1, -1, 1, 0, 0, 0, -1, 0, -1, 0, 0, 1}, {134}, {1, 1, -1, -1, 1, 1, 0, 1, 1, 0, 0, 0, -1, 1, 0, -1, 1, -1, 0, 0, -1, 1, 1, 0, 0, -1, -1, 0, 1, 0, 0, 0, -1, 0, 1, 0, 1, -1, -1, 0, 0, 1, -1, 1, 1, -1, 1, 1, -1, 1, 0, 0, 0, -1, -1, -1, 1, 1, 1, 0, -1, 0, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1, 1, 0, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 1, 0, 1, 1, -1, 0, -1, 0, -1, -1, -1, 0, -1, 1, -1, 0, -1, -1, 0, 0, -1, -1, 1, 1, 0, 0, 0, -1, -1, -1, 0, 1, 1, -1, 1, 1, 0, 1, 1, 1, 0, -1, 0, 0, 1, -1, 0, -1, 0, 1}, {135}, {1, -1, 1, 0, 1, 1, 0, 0, 0, 1, -1, -1, 0, -1, -1, -1, 1, 0, -1, 0, -1, 1, -1, 0, -1, 0, 0, 0, -1, -1, 0, 1, -1, -1, 0, -1, -1, -1, 0, 1, -1, 0, 1, 1, 1, 1, -1, 0, -1, 0, 0, 1, -1, 0, -1, 0, -1, -1, -1, -1, -1, 0, 0, -1, 1, -1, -1, -1, 0, 1, -1, 1, 0, -1, 0, 0, -1, 1, -1, 1, 0, 0, 1, 0, 1, 1, -1, -1, 1, -1, 1, 1, 1, 0, -1, 1, 0, 0, 1, -1, -1, 1, 1, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, -1, 1, -1, -1, 1, 0, 0, 0, -1, 0, -1, 0, 1, -1, -1, -1, -1, -1, 1, -1, -1, 0, 0, 1}, {136}, {1, -1, 0, 1, 1, 0, 1, -1, -1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, -1, -1, -1, -1, -1, 0, -1, -1, 0, 1, -1, -1, 1, -1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 0, 1, 0, -1, -1, -1, -1, 0, 1, -1, 0, -1, 1, -1, -1, -1, -1, 0, -1, 1, 0, -1, -1, -1, 0, 0, 0, -1, -1, 1, 1, 0, 1, -1, 1, -1, 1, -1, 1, 1, -1, 0, 1, 0, 1, -1, 0, 1, 1, -1, 0, 0, -1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, -1, -1, 0, 1, 0, 0, 0, 1, -1, 0, -1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, -1, 0, 0, -1, -1, 0, 0, 0}, {137}, {1, 0, 1, -1, -1, 0, 1, 0, -1, -1, 0, 1, 0, 0, 0, -1, 0, -1, -1, 0, -1, 0, -1, 1, -1, 1, 0, 1, -1, 1, 0, -1, -1, 1, 0, 0, -1, -1, -1, 0, 0, 0, -1, -1, -1, 0, -1, 1, -1, 1, 0, 0, 0, 0, -1, 1, 0, 1, 0, 1, 1, 0, -1, 1, -1, 0, 0, 0, 1, -1, -1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, -1, -1, -1, -1, 0, 1, 0, -1, 1, 0, -1, -1, 0, -1, 0, -1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 0, -1, -1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, -1, -1, -1, -1, 0, 1, 0, -1, -1, 0, 0, -1, 0, 0, 1, -1, -1, 0, 1, 0}, {138}, {1, 0, 1, -1, 1, 0, 1, 1, -1, -1, 1, 0, 0, 1, -1, 0, -1, -1, -1, -1, 0, -1, 1, -1, 0, 1, 0, 1, -1, -1, 1, 0, 0, 0, 1, 0, -1, 0, 0, -1, 0, -1, -1, 0, -1, -1, -1, 0, 0, -1, 1, 1, -1, 1, 0, 0, 0, 1, 0, -1, -1, 0, 0, 0, -1, -1, -1, 0, 1, 0, 1, 0, -1, 1, -1, 0, 1, -1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, -1, -1, 0, -1, 1, 1, -1, -1, 0, 0, 1, -1, 0, 1, 1, 0, -1, 1, -1, 1, -1, -1, 1, 1, -1, 0, 0, 0, 0, 1, 1, 1, 0, 0, -1, -1, 0, 0, 0, -1, 1, -1, -1, -1, 0, 0, 1, 0, -1, 1, 0, 0}, {139}, {1, 0, 1, 1, 0, -1, 1, -1, 1, 0, 0, 0, 1, -1, 0, 1, -1, 0, 1, 1, -1, 1, 1, -1, 1, 1, 0, -1, -1, 1, 0, -1, 0, -1, -1, 1, 0, 1, -1, 0, 0, -1, 0, 0, -1, 1, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, -1, 0, 0, 1, 0, 0, 1, -1, 1, 1, 1, 1, 1, 0, -1, 0, 0, 0, 1, 0, 1, 0, 1, 0, -1, -1, -1, 1, 0, -1, -1, 1, 0, -1, 1, 1, 1, 0, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 0, -1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, -1, -1, -1, -1, 1, 0, -1, 0, 1, -1, 1, -1, 1, 1, -1, 1, 1, -1, -1, -1, 0, 1}, {140}, {1, 0, -1, -1, 1, -1, 0, 1, 0, 1, 0, 0, -1, 1, 1, 1, 1, 1, 1, 0, -1, -1, -1, 1, -1, 1, 0, -1, 0, 0, 1, 0, -1, -1, 1, 0, 0, -1, -1, -1, 1, 1, 0, -1, 1, 0, -1, 0, 1, -1, 1, -1, 0, 0, 1, 1, -1, 1, -1, 1, 0, 0, 0, 1, 0, 0, -1, 0, 1, 0, 0, 1, 0, 0, -1, 0, 1, 0, 1, 1, 0, -1, -1, 1, 0, -1, 1, 1, 1, -1, 1, 1, 0, 0, 0, -1, -1, 1, 0, -1, -1, 0, 1, 1, -1, 1, -1, 1, -1, -1, -1, 0, 0, -1, 1, -1, -1, 0, 1, 0, 1, 1, -1, -1, 0, 1, 1, 1, 0, 0, 1, 1, -1, 0, 1, -1, 0, 1, 0, 0, -1, 0}, {141}, {1, 1, -1, 0, 0, 1, 0, -1, 0, -1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, -1, 0, 0, 1, -1, 0, -1, 0, -1, -1, 1, 1, 0, 0, -1, 1, 1, -1, -1, 1, 1, -1, 0, -1, 1, 1, 0, 0, -1, -1, -1, -1, -1, 0, 1, -1, 1, -1, 1, -1, 0, 0, 1, -1, 1, -1, 0, 1, 0, 1, 0, 0, 1, 0, -1, 1, -1, 0, 0, -1, 0, 1, 1, 1, 0, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, 0, -1, 1, 0, -1, 1, -1, 0, 1, -1, 0, -1, 1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 1, -1, 0, 1, 0, 1, -1, -1, 1, 1, -1, -1, 0, 0, -1, 1, 1, 1, -1, 1, 1}, {142}, {1, 1, -1, -1, 0, -1, -1, -1, -1, -1, 0, 1, -1, -1, 1, 1, 0, -1, -1, 1, 1, 1, -1, 0, -1, 0, -1, -1, 0, 1, 1, 1, 0, -1, 0, -1, -1, 0, 0, -1, 1, 1, -1, -1, 1, 1, 1, 0, 0, 1, 1, -1, 1, 1, -1, 0, 0, -1, 0, -1, 1, -1, -1, 0, 0, 0, 1, 1, -1, 0, -1, -1, -1, 0, -1, -1, 0, -1, 1, 1, -1, 0, 0, -1, 0, 1, 0, -1, 1, -1, -1, 1, 0, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, -1, -1, -1, 0, -1, -1, 0, -1, 1, 0, 0, 0, 0, 0, 0, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0, -1, 1, 0, 0}, {143}, {1, 0, 1, -1, 0, -1, 0, 0, 1, -1, 1, -1, -1, 0, -1, 1, 1, 1, 0, -1, 0, 0, 0, 0, 1, -1, 1, 0, 0, 0, -1, 0, -1, 0, 1, 0, 0, -1, -1, -1, 0, -1, 0, 0, 0, 1, 1, 1, 0, -1, -1, -1, -1, 0, 0, 1, 1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 1, 0, -1, 0, 1, 1, 0, 0, 0, -1, -1, 0, 1, 1, 1, -1, -1, 1, 1, 1, 1, 0, 0, -1, -1, 1, -1, 1, -1, -1, 1, 0, 1, -1, 1, 0, 1, 0, -1, 0, 0, 0, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, 0, 0, -1, 0, -1, -1, 1, 0, 1, 1, -1, 0, 1, 1, -1, 1, -1, 0, 1, 1, -1, -1, 1, -1, -1, 1, -1}, {144}, {1, 0, 1, -1, -1, 0, 0, 1, 0, 1, 1, -1, 1, -1, 1, 1, 0, 0, -1, 1, 1, 1, -1, 0, -1, 0, 0, 0, 0, 1, 1, 1, 0, -1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, -1, -1, 1, -1, 1, -1, 1, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, 1, 0, 0, -1, 0, -1, 1, -1, -1, 1, 0, 1, -1, 0, 1, 0, -1, -1, 1, 0, 1, -1, 0, -1, 1, 0, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 0, -1, 1, -1, 1, 0, 0, 0, -1, -1, 0, 0, 1, -1, 0, -1, 1, 1, -1, 0, -1, 1, -1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, -1, 1, 1, 0, 0, -1, 1, 1, 1}, {145}, {1, 1, -1, 0, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 0, 1, -1, -1, -1, 1, 0, 0, 0, 1, 1, -1, 1, -1, 0, 1, 1, 0, 1, 0, 1, -1, -1, 1, -1, -1, 1, 0, -1, 0, 0, 1, 1, 0, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, 0, -1, 0, 1, 0, 0, 1, 1, -1, -1, -1, -1, 1, 0, -1, 0, -1, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 1, -1, 1, 0, 1, -1, -1, -1, 1, -1, 0, -1, 0, 0, 0, 0, -1, 0, -1, 0, 1, -1, 0, 0, 1, 0, -1, 0, 0, -1, 0, -1, -1, 0, 1, 1, 0, -1, 0, 1, 0, -1, 1, -1, 1, 0, 1, 1, 0, 1, -1, -1, -1, 1, 0, -1, -1, 1}, {146}, {1, 1, 0, 1, -1, -1, 1, 1, -1, 1, 1, -1, 0, -1, 0, -1, 1, 0, 0, 0, -1, 0, 1, 1, 1, 1, -1, 1, 0, 0, 1, 0, 1, -1, 0, -1, 0, -1, 1, -1, 1, 1, -1, -1, -1, 0, 0, 1, -1, -1, -1, 0, 0, -1, 0, 0, 1, 1, -1, 0, 0, 1, -1, 0, 0, 0, 0, -1, 1, 0, -1, 1, -1, 0, -1, -1, 0, 1, 1, 0, 1, -1, -1, 0, 1, 1, -1, 0, 1, -1, 0, 0, 0, 1, 1, -1, -1, 0, -1, -1, 1, 1, -1, -1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -1, 0, 0, -1, 0, 0, 1, 1, 1, 0, 0, -1, 0, 1, 0, 1, 1, 0, 1, -1, 0, 0, 1, -1, -1, -1, 0, 1, 1, -1, 1, -1, 1, 0}, {147}, {1, -1, 0, 1, -1, 0, -1, -1, 0, 1, 1, -1, 1, 0, 0, 1, 1, 1, 0, 1, -1, 1, -1, 1, 1, -1, -1, 1, 0, -1, 0, -1, -1, -1, -1, 0, 0, 0, 1, -1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, -1, -1, 0, 0, -1, -1, -1, -1, 0, 1, -1, -1, -1, 0, -1, 0, 0, 1, 1, 0, -1, 0, 0, 0, 1, 1, 1, 0, 0, 1, -1, 1, -1, -1, 1, -1, 0, 1, -1, -1, 1, 1, 0, 1, 0, 1, 0, -1, 1, 0, 0, -1, -1, 1, 1, 0, -1, 0, 1, 0, 0, 0, 0, 0, 1, -1, 0, 0, -1, -1, 1, -1, -1, 0, -1, 0, -1, 1, 1, -1, 0, -1, 0, 0, 0, 0, -1, 0, -1, -1, -1, 1, 1, 0, 0, 0, 1, 0, 1}, {148}, {1, 1, 0, -1, -1, 1, -1, 1, -1, 0, 1, -1, -1, -1, -1, 0, 1, -1, 0, -1, 0, 0, 1, -1, -1, 1, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 0, 0, -1, 1, 0, -1, -1, 0, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, 0, 1, 0, 0, 0, 1, -1, 0, -1, -1, 0, -1, 1, -1, 1, 1, 0, 1, -1, -1, 1, 0, -1, 0, -1, -1, 0, 0, 0, -1, 1, 1, -1, 0, 0, 1, -1, 1, 0, 0, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 0, 0, 0, 1, 1, -1, -1, 0, -1, -1, 1, 1, 1, 1, -1, 0, -1, 1, 0, -1, 1, 0, 0, 0, -1, 0, 0, -1, -1, -1, 0, 1, 1, 0, 0, -1, 0, 1, 1, 0, -1, 0}, {149}, {1, -1, 1, -1, 0, 1, -1, 0, -1, 1, -1, -1, 0, 0, 0, 1, 1, 0, -1, 0, 1, -1, 1, 1, -1, 0, -1, 1, 1, 0, -1, 0, 0, -1, 1, 0, 1, 0, -1, 0, 0, 0, 1, -1, -1, 0, 1, -1, -1, 1, 0, 1, -1, 0, 1, -1, 1, 1, 0, 1, 0, 1, 0, -1, 1, 0, 1, 1, -1, 1, -1, 0, -1, -1, 0, -1, 1, 0, 0, 1, -1, 1, 1, 1, -1, 0, -1, -1, 0, 0, -1, 1, -1, 1, -1, -1, 0, 1, -1, 0, 0, 0, 1, -1, 1, 1, 0, 1, -1, -1, 0, 1, -1, 0, 0, 0, -1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -1, 0, 1, 0, 1, 1, -1, 1, 1, -1, 0, -1, 1, 1, 0, -1, 0, 1, 1, 1, 0, 1, 0, -1, 0}, {150}}; void printa(int i) { cout << ans[i].size() - 1 << '\n'; reverse(ans[i].begin(), ans[i].end()); for (int j : ans[i]) cout << j << " "; cout << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; n--; printa(2 * n); cout << ans[2 * n + 1][0] - 1 << '\n'; for (int i = 0; i < ans[2 * n + 1][0]; i++) cout << 1 << " "; cout << '\n'; exit(0); }
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long x = 1, y = 1; while (n--) { string str; cin >> str; if (str == "UL" || str == "DR") x++; else if (str == "DL" || str == "UR") y++; else { x++; y++; } } cout << x * y << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; void scanint(int &x) { register int c = getchar(); x = 0; int neg = 0; for (; ((c < 48 || c > 57) && c != '-'); c = getchar()) ; if (c == '-') { neg = 1; c = getchar(); } for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; } if (neg) x = -x; } void scanlong(long long int &x) { register long long int c = getchar(); x = 0; int neg = 0; for (; ((c < 48 || c > 57) && c != '-'); c = getchar()) ; if (c == '-') { neg = 1; c = getchar(); } for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; } if (neg) x = -x; } long long int dp[100000 + 5]; long long int a[100000 + 5] = {0}; long long int func(int i) { if (dp[i] != -1) return dp[i]; return dp[i] = max(a[i] * i + func(i + 2), func(i + 1)); } int main() { int t = 1; while (t--) { memset(dp, -1, sizeof(dp)); long long int sum = 0; int n; scanint(n); int b; for (int i = 0; i < n; ++i) { scanint(b); a[b]++; } cout << func(0); } return 0; }
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n; vector<long long int> arr(N + 1, 0); vector<long long int> sum1(N + 1, 0); vector<long long int> sum2(N + 1, 0); int main() { cin >> n; long long int x = 0; for (int i = 1; i <= n; i++) { cin >> arr[i]; sum1[i] = sum1[i - 1] + arr[i]; x += arr[i]; } for (int i = 1; i <= n; i++) sum2[i] = sum2[i - 1] + arr[n - i + 1]; if (x % 2 == 1) { cout << "NO"; return 0; } int l = 1, r = n; while (l <= r) { int mid = (l + r) / 2; if (sum1[mid] == x / 2) { cout << "YES"; return 0; } else if (sum1[mid] > x / 2) r = mid - 1; else l = mid + 1; } for (int i = 1; i <= n; i++) { l = i + 1, r = n; while (l <= r) { int mid = (l + r) / 2; if (sum1[mid] - sum1[i] + sum1[i - 1] == x / 2) { cout << "YES"; return 0; } else if (sum1[mid] - sum1[i] + sum1[i - 1] > x / 2) r = mid - 1; else l = mid + 1; } } for (int i = 1; i <= n; i++) { l = i + 1, r = n; while (l <= r) { int mid = (l + r) / 2; if (sum2[mid] - sum2[i] + sum2[i - 1] == x / 2) { cout << "YES"; return 0; } else if (sum2[mid] - sum2[i] + sum2[i - 1] > x / 2) r = mid - 1; else l = mid + 1; } } cout << "NO"; return 0; }
5
#include <bits/stdc++.h> using namespace std; int dx[3] = {1, 0, 0}; int dy[3] = {0, 1, 0}; int dz[3] = {0, 0, 1}; char g[105][105][105]; bool cango(int x1, int y1, int z1, int x2, int y2, int z2) { if (x1 > x2 || y1 > y2 || z1 > z2) return false; if (g[x1][y1][z1] == '0') return false; if (x1 == x2 && y1 == y2 && z1 == z2) return true; for (int i = (0); i < (3); i++) { if (cango(x1 + dx[i], y1 + dy[i], z1 + dz[i], x2, y2, z2)) return true; } return false; } int a, b, c; int main() { scanf("%d%d%d", &a, &b, &c); for (int i = (0); i < (a); i++) { for (int j = (0); j < (b); j++) { scanf(" %s", g[i][j]); } } int res = 0; for (int i = (0); i < (a); i++) for (int j = (0); j < (b); j++) for (int k = (0); k < (c); k++) if (g[i][j][k] == '1') { int f[3][3] = {}; for (int s = (0); s < (3); s++) { int pi = i - dx[s]; int pj = j - dy[s]; int pk = k - dz[s]; for (int t = (0); t < (3); t++) { int ni = i + dx[t]; int nj = j + dy[t]; int nk = k + dz[t]; if (min({pi, pj, pk}) >= 0 && ni < a && nj < b && nk < c && g[pi][pj][pk] == '1' && g[ni][nj][nk] == '1') { f[s][t] = cango(pi, pj, pk, ni, nj, nk) ? 1 : 0; } else f[s][t] = -1; } } g[i][j][k] = '0'; int o[3][3]; for (int s = (0); s < (3); s++) { int pi = i - dx[s]; int pj = j - dy[s]; int pk = k - dz[s]; for (int t = (0); t < (3); t++) { int ni = i + dx[t]; int nj = j + dy[t]; int nk = k + dz[t]; if (min({pi, pj, pk}) >= 0 && ni < a && nj < b && nk < c && g[pi][pj][pk] == '1' && g[ni][nj][nk] == '1') { o[s][t] = cango(pi, pj, pk, ni, nj, nk) ? 1 : 0; } else o[s][t] = -1; } } g[i][j][k] = '1'; bool cut = false; for (int s = (0); s < (3); s++) for (int t = (0); t < (3); t++) { if (f[s][t] != o[s][t]) cut = true; } res += cut; } printf("%d\n", res); }
5
#include <bits/stdc++.h> using namespace std; int rev(int ans) { if (ans == 1) return 0; else return 1; } int main() { int arr[3][3], ans[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cin >> arr[i][j]; ans[i][j] = 1; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (arr[i][j] % 2 != 0) { if (i - 1 >= 0) { ans[i - 1][j] = rev(ans[i - 1][j]); } if (i + 1 < 3) { ans[i + 1][j] = rev(ans[i + 1][j]); } if (j + 1 < 3) { ans[i][j + 1] = rev(ans[i][j + 1]); } if (j - 1 >= 0) { ans[i][j - 1] = rev(ans[i][j - 1]); } ans[i][j] = rev(ans[i][j]); } } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << ans[i][j]; } cout << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, c = 0, s = 0, f = 0, a, b; cin >> n >> m; vector<pair<long long int, long long int> > arr; for (i = 0; i < m; i++) { cin >> a >> b; arr.push_back(make_pair(b, a)); } sort(arr.rbegin(), arr.rend()); for (i = 0; i < m; i++) { if (n <= 0) { break; } c = min(arr[i].second, n); n -= c; s += arr[i].first * c; } cout << s << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } const int N = 11009; int c[N], l[120], r[120], a[120]; long long d[2][N]; function<bool(long long, long long)> cmp; int n, m, k; int s[2], f; vector<pair<long long, int> > adj[N]; int seen[N]; void dij(int p) { memset(seen, 0, sizeof seen); priority_queue<pair<long long, int> > pq; pq.push(pair<long long, int>(0, s[p])); for (int i = 0; i < n; i++) d[p][i] = LLONG_MAX; while (!pq.empty()) { pair<long long, int> x = pq.top(); pq.pop(); if (seen[x.second]) continue; seen[x.second] = true; d[p][x.second] = -x.first; for (pair<long long, int> e : adj[x.second]) if (!seen[e.first]) pq.push(pair<long long, int>(x.first - c[e.second], e.first)); } } bool solve() { int i; while (true) { dij(0); dij(1); for (i = 0; i < k && (c[m + i] == l[i] || !cmp(d[0][a[i]], d[1][a[i]])); i++) ; if (i == k) return cmp(d[0][f], d[1][f]); c[m + i] = l[i]; } } void finish(const char *str) { puts(str); for (int i = 0; i < k; i++) printf("%d ", c[i + m]); putchar('\n'); exit(0); } int main() { int i, a, b; scanf("%d %d %d", &n, &m, &k); scanf("%d %d %d", &s[0], &s[1], &f); s[0]--; s[1]--; f--; for (i = 0; i < m; i++) { scanf("%d %d %d", &a, &b, &c[i]); a--; b--; adj[a].push_back(pair<long long, int>(b, i)); } for (i = 0; i < k; i++) { scanf("%d %d %d %d", &a, &b, &l[i], &r[i]); a--; b--; adj[a].push_back(pair<long long, int>(b, m + i)); c[m + i] = r[i]; ::a[i] = a; } cmp = less<long long>(); if (solve()) finish("WIN"); cmp = less_equal<long long>(); if (solve()) finish("DRAW"); puts("LOSE"); }
10
#include <bits/stdc++.h> using namespace std; int k, _a, _b, a, b, Inv_b, ans, Dp[1000 + 5][1000 + 5]; int Power(int u, int v) { int res = 1; for (; v; v >>= 1) { if (v & 1) res = 1LL * res * u % 1000000007; u = 1LL * u * u % 1000000007; } return res; } int Inc(int u, int v) { return u + v - (u + v >= 1000000007 ? 1000000007 : 0); } int main() { scanf("%d%d%d", &k, &_a, &_b); a = 1LL * _a * Power(_a + _b, 1000000007 - 2) % 1000000007; b = 1LL * _b * Power(_a + _b, 1000000007 - 2) % 1000000007; Inv_b = Power(b, 1000000007 - 2); Dp[1][0] = 1; for (int i = 1; i <= k; i++) for (int j = 0; j <= k; j++) { if (i + j < k) Dp[i][i + j] = Inc(Dp[i][i + j], 1LL * Dp[i][j] * b % 1000000007); else if (i < k) ans = Inc(ans, 1LL * Dp[i][j] * b % 1000000007 * (i + j) % 1000000007); if (i < k) Dp[i + 1][j] = Inc(Dp[i + 1][j], 1LL * Dp[i][j] * a % 1000000007); else ans = Inc(ans, 1LL * Dp[i][j] * (k + j + 1LL * a * Inv_b % 1000000007) % 1000000007); } printf("%d\n", ans); return 0; }
7
#include <bits/stdc++.h> using namespace std; namespace SHENZHEBEI { static const int GYN = 2333333; char SZB[GYN], *SS = SZB, *TT = SZB; inline char gc() { if (SS == TT) { TT = (SS = SZB) + fread(SZB, 1, GYN, stdin); if (SS == TT) return '\n'; } return *SS++; } inline long long read() { long long x = 0, g = 1; char ch = gc(); for (; !isdigit(ch); ch = gc()) if (ch == '-') g = -1; for (; isdigit(ch); ch = gc()) x = x * 10 - 48 + ch; return x * g; } inline void write(long long x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar(x % 10 + '0'); } inline char readchar() { char ch = gc(); for (; isspace(ch); ch = gc()) ; return ch; } inline long long readstr(char *s) { char ch = gc(); int cur = 0; for (; isspace(ch); ch = gc()) ; for (; !isspace(ch); ch = gc()) s[cur++] = ch; s[cur] = '\0'; return cur; } void Print(long long *a, int s, int t) { for (int i = (long long)(s); i <= (long long)(t); ++i) printf("%lld ", a[i]); } void Print(int *a, int s, int t) { for (int i = (long long)(s); i <= (long long)(t); ++i) printf("%d ", a[i]); } void Print(char *a, int s, int t) { for (int i = (long long)(s); i <= (long long)(t); ++i) putchar(a[i]); } void writeln(long long x) { write(x); puts(""); } void Min(long long &x, long long y) { x = x < y ? x : y; } void Max(long long &x, long long y) { x = x > y ? x : y; } } // namespace SHENZHEBEI using namespace SHENZHEBEI; const long long N = 200010; vector<long long> g[N], w[N]; long long visted[N], dfn[N], a[N], b[N], q[N], vis[N], n, top; void dfs(long long x) { visted[x] = 1; for (int i = (long long)(0); i < (long long)(g[x].size()); ++i) { if (vis[abs(w[x][i])]) continue; vis[abs(w[x][i])] = w[x][i] < 0 ? 1 : 2; dfs(g[x][i]); } } int main() { n = read(); for (int i = (long long)(1); i <= (long long)(n); ++i) { a[i] = read(), b[i] = read() + 1; q[++top] = a[i], q[++top] = b[i]; } sort(q + 1, q + top + 1); top = unique(q + 1, q + top + 1) - q - 1; for (int i = (long long)(1); i <= (long long)(n); ++i) { a[i] = lower_bound(q + 1, q + top + 1, a[i]) - q, b[i] = lower_bound(q + 1, q + top + 1, b[i]) - q; g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); w[a[i]].push_back(i); w[b[i]].push_back(-i); ++dfn[a[i]]; ++dfn[b[i]]; } long long cnt = n; for (int i = (long long)(1); i <= (long long)(top); ++i) { dfn[i] += dfn[i - 1]; if (dfn[i] & 1) { g[i].push_back(i + 1); g[i + 1].push_back(i); w[i].push_back(++cnt); w[i + 1].push_back(cnt); } } for (int i = (long long)(1); i <= (long long)(top); ++i) if (!visted[i]) dfs(i); for (int i = (long long)(1); i <= (long long)(n); ++i) write(vis[i] - 1), putchar(' '); }
4
#include <bits/stdc++.h> using namespace std; bool flag = 0; void dfs(int u, vector<vector<int> > &g, vector<int> &mark, string &order) { mark[u] = 1; for (auto to : g[u]) { if (mark[to] == 1) flag = 1; else if (mark[to] == 0) dfs(to, g, mark, order); } order.push_back('a' + u); mark[u] = 2; } int main() { ios::sync_with_stdio(0); int n; cin >> n; vector<string> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<vector<int> > g(26); for (int i = 0; i < n - 1; i++) { int size = min((int((a[i]).size())), (int((a[i + 1]).size()))), j; for (j = 0; j < size; j++) if (a[i][j] != a[i + 1][j]) break; if (j < size) g[a[i][j] - 'a'].push_back(a[i + 1][j] - 'a'); else if ((int((a[i]).size())) > (int((a[i + 1]).size()))) flag = 1; } vector<int> mark(26); string order; for (int i = 0; i < 26; i++) if (mark[i] == 0) dfs(i, g, mark, order); if (flag) { cout << "Impossible\n"; } else { reverse(order.begin(), order.end()); cout << order << '\n'; } return 0; }
4