#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
constexpr ll inf = 0x3f3f3f3f3f3f3f3f;
ll powq(int x, int n){ ll res = 1; while (n--) { res *= x; if (res > inf) return inf; } return res; }
intmain(){ ll n; cin >> n;
bool ok = false; for (int i = 30; i >= 1; i--) { ll res = 0; if (ok) { break; } for (int j = 1; ; j++) { res += ll(powq(j, i)); if (res > n) { break; } if (res == n) { ok = true; for (int k = 1; k <= j; k++) { cout << k << "^" << i << "+\n"[k == j]; } break; } } } if (!ok) { cout << "Impossible for " << n << "."; }
intmain(){ string s; cin >> s; while (!s.empty()) { int l = -1, r = -1; for (int i = 0; i < s.size(); i++) { auto c = s[i]; if (c == '(') { l = i; } if (c == ')' && l != -1) { r = i; cout << s.substr(l + 1, r - l - 1) << endl; s = s.substr(0, l) + s.substr(r + 1); break; } } } return0; }
int n; cin >> n; vector<int> a[3]; while (n--) { int x, y; cin >> x >> y; a[y].push_back(x); }
for (int i = 0; i < 3; i++) { sort(a[i].begin(), a[i].end()); a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end()); }
vector<array<int, 3>> res; if (a[0].size() < a[2].size() && a[1].size() < a[2].size()) { for (auto x : a[2]) { mp.set(x + N); } for (auto x : a[1]) { for (auto y : a[0]) { if (2 * x - y > N) break; if (mp.test(2 * x - y + N)) { int z = 2 * x - y; res.push_back({ x, y, z }); } } } } elseif (a[2].size() < a[0].size() && a[1].size() < a[0].size()) { for (auto x : a[0]) { mp.set(x + N); } for (auto x : a[1]) { for (auto y : a[2]) { if (2 * x - y > N) break; if (mp.test(2 * x - y + N)) { int z = 2 * x - y; res.push_back({ x, z, y }); } } } } else { for (auto x : a[1]) { mp.set(x + N); } for (auto x : a[0]) { for (auto y : a[2]) { if ((x + y) % 2 == 0 && mp.test((x + y) / 2 + N)) { int z = (x + y) / 2; res.push_back({ z, x, y }); } } } }
if (res.size()) { sort(res.begin(), res.end()); for (auto [x, y, z] : res) { cout << "[" << y << ", 0] "; cout << "[" << x << ", 1] "; cout << "[" << z << ", 2]\n"; } } else { cout << -1 << endl; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
intmain(){ int N; ll l, r; cin >> N >> l >> r;
vector<ll> pow(N + 1); pow[0] = 1; for (int i = 1; i <= N; i++) { pow[i] = pow[i - 1] * 10; }
bool out = false; auto dfs = [&](auto&& dfs, ll x, int n) -> void { if (n == -1) { cout << x << endl; out = true; return; } for (int i = 0; i <= 9; i++) { if (i == 0 && N - n == 1) continue; // first not 0 ll y = x + i * pow[n]; if (y / pow[n] % (N - n) == 0 && y / pow[n] >= l / pow[n] && y / pow[n] <= r / pow[n]) { dfs(dfs, y, n - 1); } } }; dfs(dfs, 0, N - 1);
inlineintread(){ int res = 0, fu = 1; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') { fu = -1; } c = getchar(); } while (c <= '9' && c >= '0') { res = (res << 1) + (res << 3) + c - '0'; c = getchar(); } return res; }
intmain(){ int b = read(), n = read(), m = read(), k = read();
vector dis(n, vector<node>(n, node{ inf, 0 })); for (int u = 0; u < n; u++) { dis[u][u] = {0,0}; } while (m--) { int u = read(), v = read(), w = read(), d = read(); u--; v--; dis[u][v] = dis[v][u] = node{ w, d }; } for (int k = 0; k < n; k++) { for (int u = 0; u < n; u++) { for (int v = 0; v < n; v++) { dis[u][v] = min(dis[u][v], dis[u][k] + dis[k][v]); } } }
while (k--) { int s = read(); s--;
vector<int> res; for (int i = 0; i < n; i++) { if (dis[s][i].w <= b && i != s) { res.push_back(i); } }
if (res.empty()) { cout << "T_T" << endl; } else { int maxval = 0; bool fst = true; for (auto u : res) { if (fst) { fst = false; } else { cout << " "; } cout << u + 1; maxval = max(maxval, dis[s][u].d); } cout << endl; fst = true; for (auto u : res) { if (dis[s][u].d == maxval) { if (fst) { fst = false; } else { cout << " "; } cout << u + 1; } } cout << endl; } }