solution
stringlengths 53
181k
| difficulty
int64 0
13
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int n, s1, s2;
vector<int> v(200);
vector<int> rem;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
int y;
for (int j = 0; j < x; j++) {
cin >> y;
if (x % 2 == 0) {
if (j < (x / 2))
s1 += y;
else
s2 += y;
} else {
if (j < (x / 2)) s1 += y;
if (j == (x / 2)) rem.push_back(y);
if (j > (x / 2)) s2 += y;
}
}
}
sort(rem.rbegin(), rem.rend());
for (int i = 0; i < rem.size(); i++) {
if (i % 2 == 0)
s1 += rem[i];
else
s2 += rem[i];
}
cout << s1 << ' ' << s2 << '\n';
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, a, b;
cin >> t;
while (t--) {
cin >> n >> a >> b;
vector<char> v;
for (int i = 0; i < n; i++) {
v.push_back(char(97 + (i % b)));
}
for (int i = 0; i < n; i++) cout << v[i];
cout << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 5];
long long sum = 0;
int mx = -1, smx = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] > mx) {
smx = mx;
mx = a[i];
} else if (a[i] > smx)
smx = a[i];
}
vector<int> v;
for (int i = 0; i < n; i++) {
long long nsum = sum - a[i];
if (a[i] == mx) {
if (nsum - smx == smx) {
v.push_back(i + 1);
}
} else if (nsum - mx == mx) {
v.push_back(i + 1);
}
}
cout << v.size() << "\n";
for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
return 0;
}
| 2 |
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using LL = long long;
template <typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a; swap(a, m);
u -= t * v; swap(u, v);
}
assert(m == 1);
return u;
}
template <typename T>
class Modular {
public:
using Type = typename decay<decltype(T::value)>::type;
constexpr Modular() : value() {}
template <typename U>
Modular(const U& x) {
value = normalize(x);
}
template <typename U>
static Type normalize(const U& x) {
Type v;
if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
else v = static_cast<Type>(x % mod());
if (v < 0) v += mod();
return v;
}
const Type& operator()() const { return value; }
template <typename U>
explicit operator U() const { return static_cast<U>(value); }
constexpr static Type mod() { return T::value; }
Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }
Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }
template <typename U> Modular& operator+=(const U& other) { return *this += Modular(other); }
template <typename U> Modular& operator-=(const U& other) { return *this -= Modular(other); }
Modular& operator++() { return *this += 1; }
Modular& operator--() { return *this -= 1; }
Modular operator++(int) { Modular result(*this); *this += 1; return result; }
Modular operator--(int) { Modular result(*this); *this -= 1; return result; }
Modular operator-() const { return Modular(-value); }
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {
#ifdef _WIN32
uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
asm(
"divl %4; \n\t"
: "=a" (d), "=d" (m)
: "d" (xh), "a" (xl), "r" (mod())
);
value = m;
#else
value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
return *this;
}
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, long long>::value, Modular>::type& operator*=(const Modular& rhs) {
long long q = static_cast<long long>(static_cast<long double>(value) * rhs.value / mod());
value = normalize(value * rhs.value - q * mod());
return *this;
}
template <typename U = T>
typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type& operator*=(const Modular& rhs) {
value = normalize(value * rhs.value);
return *this;
}
Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }
friend const Type& abs(const Modular& x) { return x.value; }
template <typename U>
friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);
template <typename U>
friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);
template <typename V, typename U>
friend V& operator>>(V& stream, Modular<U>& number);
private:
Type value;
};
template <typename T> bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value == rhs.value; }
template <typename T, typename U> bool operator==(const Modular<T>& lhs, U rhs) { return lhs == Modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) == rhs; }
template <typename T> bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const Modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T> bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value < rhs.value; }
template <typename T> Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T> Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T> Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T> Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template<typename T, typename U>
Modular<T> power(const Modular<T>& a, const U& b) {
assert(b >= 0);
Modular<T> x = a, res = 1;
U p = b;
while (p > 0) {
if (p & 1) res *= x;
x *= x;
p >>= 1;
}
return res;
}
template <typename T>
bool IsZero(const Modular<T>& number) {
return number() == 0;
}
template <typename T>
string to_string(const Modular<T>& number) {
return to_string(number());
}
// U == std::ostream? but done this way because of fastoutput
template <typename U, typename T>
U& operator<<(U& stream, const Modular<T>& number) {
return stream << number();
}
// U == std::istream? but done this way because of fastinput
template <typename U, typename T>
U& operator>>(U& stream, Modular<T>& number) {
typename common_type<typename Modular<T>::Type, long long>::type x;
stream >> x;
number.value = Modular<T>::normalize(x);
return stream;
}
using ModType = int;
struct VarMod { static ModType value; };
ModType VarMod::value;
ModType& md = VarMod::value;
using Mint = Modular<VarMod>;
const int MAXN = 101;
const int MAXS = 10010;
int n;
Mint f[MAXN][MAXS];
int b[MAXN], c[MAXN];
int sb[MAXN], sc[MAXN];
Mint DP(int q) {
memset(f, 0, sizeof(f));
f[0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= sc[i]; ++j) {
if (j > 0) f[i][j] += f[i][j - 1];
if (f[i][j] == 0) continue;
for (int k = 0; k <= c[i + 1]; ++k) {
if (q * (i + 1) + sb[i + 1] <= j + k) {
f[i + 1][j + k] += f[i][j];
f[i + 1][j + c[i + 1] + 1] -= f[i][j];
break;
}
}
}
}
Mint ans = 0;
for (int i = 0; i <= sc[n]; ++i) {
if (i > 0) f[n][i] += f[n][i - 1];
ans += f[n][i];
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
md = 1000000007;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> c[i];
for (int i = 1; i <= n; ++i) {
sc[i] = sc[i - 1] + c[i];
}
for (int i = 1; i <= n - 1; ++i) cin >> b[i];
for (int i = 2; i <= n; ++i) {
for (int j = 1; j < i; ++j) sb[i] += b[j] * (i - j);
}
int L = 0;
for (int i = 1; i <= n; ++i) L = min(L, -sb[i] / i);
int R = L;
map<int, Mint> h;
h[R] = DP(R);
while (true) {
Mint temp = DP(R + 1);
if (temp == 0) break;
h[R + 1] = temp;
++R;
}
while (true) {
Mint temp = DP(L - 1);
if (temp == h[L]) break;
h[L - 1] = temp;
--L;
}
int times;
cin >> times;
while (times--) {
int q;
cin >> q;
if (q < L) {
cout << h[L] << "\n";
} else
if (q > R) {
cout << 0 << "\n";
} else {
cout << h[q] << "\n";
}
}
return 0;
} | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3 + 10;
int n, a[MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cout << "? 1 2" << endl;
int x, y, z;
cin >> x;
cout << "? 1 3" << endl;
cin >> y;
cout << "? 2 3" << endl;
cin >> z;
a[0] = ((x + y + z) - z - z) / 2;
a[1] = x - a[0];
a[2] = y - a[0];
for (int i = 3; i < n; i++) {
cout << "? 1 " << i + 1 << endl;
cin >> a[i];
a[i] -= a[0];
}
cout << "! ";
for (int i = 0; i < n; i++) cout << a[i] << " ";
cout << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int main() {
int cases;
cin >> cases;
while (cases--) {
long long n;
cin >> n;
long long x;
cin >> x;
vector<long long> vec;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
vec.push_back(x);
}
long long total = 0;
vector<long long> alaa;
long long ans = 0;
for (auto v : vec) {
if (v >= x) {
total += v - x;
ans++;
} else {
alaa.push_back(x - v);
}
}
sort(alaa.begin(), alaa.end());
for (auto v : alaa) {
if (v > total) {
break;
} else {
total -= v;
ans++;
}
}
cout << ans << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct A {
long long m, p;
} a[200005];
int t, n;
multiset<int> st;
int main() {
ios::sync_with_stdio(false);
cin >> t;
while (t--) {
cin >> n;
st.clear();
for (int i = 1; i <= n; i++) cin >> a[i].m >> a[i].p;
sort(a + 1, a + 1 + n,
[](A b, A c) { return b.m < c.m || b.m == c.m && b.p < c.p; });
int now = 0;
long long ans = 0;
for (int i = n; i >= 1; i--) {
int ned = a[i].m - (i - 1);
st.insert(a[i].p);
while (!st.empty() && now < ned) {
ans += *st.begin();
st.erase(st.begin());
now++;
}
}
cout << ans << endl;
}
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int t, n, k;
string s;
int dp[N], pref[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--) {
cin >> n >> k >> s;
pref[0] = 0;
for (int i = (1); i < (n + 1); i++) {
pref[i] = pref[i - 1] + (s[i - 1] == '1');
}
int ans = pref[n];
for (int i = (1); i < (n + 1); i++) {
int L = max(0, i - k);
dp[i] =
(s[i - 1] == '0') + min(pref[i - 1], (pref[i - 1] - pref[L]) + dp[L]);
ans = min(ans, pref[n] - pref[i] + dp[i]);
}
cout << ans << '\n';
}
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int cmp(pair<int, pair<int, int> > x, pair<int, pair<int, int> > y) {
return (x.first) > (y.first);
}
vector<pair<int, pair<int, int> > > vs, vb, fs, fb;
map<int, int> mps, mpb;
int main() {
int n, s;
;
scanf("%d", &n);
scanf("%d", &s);
for (int i = 0; i < n; i++) {
string s;
int p;
int q;
cin >> s;
scanf("%d", &p);
scanf("%d", &q);
if (s == "B") {
vb.push_back({p, {q, 0}});
} else if (s == "S") {
vs.push_back({p, {q, 1}});
}
}
sort(vs.begin(), vs.end());
;
sort(vb.rbegin(), vb.rend());
int l = 0;
for (int i = 0; i < vs.size(); i++) {
mps[vs[i].first] += vs[i].second.first;
}
for (int i = 0; i < vb.size(); i++) {
mpb[vb[i].first] += vb[i].second.first;
}
map<int, int>::iterator it;
while (mps.size() > s) {
it = mps.end();
mps.erase(--it);
}
while (mpb.size() > s) {
it = mpb.begin();
mpb.erase(it);
}
map<int, int>::reverse_iterator i;
for (i = mps.rbegin(); i != mps.rend(); i++) {
cout << "S " << i->first << " " << i->second << endl;
}
for (i = mpb.rbegin(); i != mpb.rend(); i++) {
cout << "B " << i->first << " " << i->second << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long a[200005], n, m;
struct ak {
int mx, mn;
};
ak tree[4 * 200005];
void build(long long node, long long st, long long end) {
if (st == end) {
tree[node].mn = st;
tree[node].mx = st;
return;
}
long long mid = (st + end) / 2;
build(2 * node, st, mid);
build(2 * node + 1, mid + 1, end);
if (a[tree[2 * node].mx] < a[tree[2 * node + 1].mx])
tree[node].mx = tree[2 * node + 1].mx;
else
tree[node].mx = tree[2 * node].mx;
if (a[tree[2 * node].mn] > a[tree[2 * node + 1].mn])
tree[node].mn = tree[2 * node + 1].mn;
else
tree[node].mn = tree[2 * node].mn;
}
ak query(long long node, long long st, long long end, long long l,
long long r) {
if (l > end || r < st) {
ak ba;
ba.mn = INT_MAX;
ba.mx = INT_MAX;
return ba;
}
if (l <= st && r >= end) {
return tree[node];
}
long long md = (st + end) / 2;
ak lf, rt;
lf = query(2 * node, st, md, l, r);
rt = query(2 * node + 1, md + 1, end, l, r);
ak b;
if (lf.mx == INT_MAX) {
return rt;
}
if (rt.mx == INT_MAX) {
return lf;
}
if (a[lf.mx] < a[rt.mx]) {
b.mx = rt.mx;
} else
b.mx = lf.mx;
if (a[lf.mn] > a[rt.mn]) {
b.mn = rt.mn;
} else
b.mn = lf.mn;
return b;
}
int main() {
scanf("%lld %lld", &n, &m);
for (long long i = 1; i < n + 1; i++) scanf("%lld", &a[i]);
build(1, 1, n);
while (m--) {
long long xx, yy, zz;
scanf("%lld %lld", &xx, &yy);
scanf("%lld", &zz);
ak raj = query(1, 1, n, xx, yy);
if (a[raj.mx] != zz)
cout << raj.mx;
else if (a[raj.mn] != zz)
cout << raj.mn;
else
cout << "-1";
printf("\n");
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long INF = LLONG_MAX / 2;
const long long N = 2e5 + 1;
long long power(long long first, long long second, long long p) {
long long ans = 1;
first = first % p;
while (second) {
if (second & 1) ans = (ans * first) % p;
second = second >> 1;
first = (first * first) % p;
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
{
long long n, m;
cin >> n >> m;
cout << power(power(2, m, M) - 1, n, M);
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
void __print(long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
long long f = 0;
cerr << '{';
for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
void solve() {
long long n;
cin >> n;
vector<long long> p(n), q(n);
string s;
for (long long i = 0; i < (n); i++) {
cin >> p[i];
}
cin >> s;
long long tot = 0;
for (long long i = 0; i < (n); i++) {
if (s[i] == '0') tot++;
}
vector<long long> zeros, ones;
for (long long i = 0; i < n; i++) {
if (s[i] == '0' and p[i] > tot) {
zeros.push_back(i);
} else if (s[i] == '1' and p[i] <= tot) {
ones.push_back(i);
}
};
if (zeros.empty()) {
for (long long i = 0; i < (n); i++) {
cout << p[i] << " ";
}
cout << "\n";
return;
}
long long curr = 0;
for (long long i = 0; i < (n); i++) {
if (curr < ones.size() and i == zeros[curr]) {
swap(p[i], p[ones[curr]]);
curr++;
}
}
for (long long i = 0; i < (n); i++) {
cout << p[i] << " ";
}
cout << "\n";
return;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
int a[100010];
bitset<100010> bs;
bool dfs(int idx) {
if (idx >= s.size() || idx < 0) return true;
if (bs[idx] == 1) return false;
bs[idx] = 1;
bool res = false;
if (s[idx] == '<') {
res |= dfs(idx - a[idx]);
} else {
res |= dfs(idx + a[idx]);
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
cin >> s;
for (int i = 0; i < n; i++) cin >> a[i];
bs.reset();
if (dfs(0)) {
cout << "FINITE" << '\n';
} else {
cout << "INFINITE" << '\n';
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m;
vector<int> adj[N];
int vis[N];
int nxt[N];
int ise[N];
bool isEqual(int a, int b) { return a == b; }
bool isLess(int a, int b) {
if (vis[a] == vis[b]) return a < b;
if (vis[a] && !vis[b]) return 1;
return 0;
}
bool in;
bool solve() {
for (int i = int(1); i <= int(n - 1); i++) {
int f = i - 1, s = i, idx = -1;
bool eq = true;
if (ise[i] == -1) {
for (int j = 0; j < int(min(int(adj[f].size()), int(adj[s].size())));
j++) {
if (isEqual(adj[f][j], adj[s][j])) continue;
eq = false;
idx = j;
break;
}
ise[i] = eq;
nxt[i] = idx;
}
if (int(adj[f].size()) <= int(adj[s].size())) {
if (ise[i]) continue;
} else {
if (ise[i]) {
return 0;
}
}
assert(nxt[i] != -1);
if (isLess(adj[f][nxt[i]], adj[s][nxt[i]]))
continue;
else {
in = true;
vis[adj[s][nxt[i]]] = 0;
if (isLess(adj[f][nxt[i]], adj[s][nxt[i]])) {
continue;
}
return 0;
}
}
return 1;
}
int main() {
fill(vis, vis + N, 1);
memset(nxt, -1, sizeof nxt);
memset(ise, -1, sizeof ise);
scanf("%d %d", &n, &m);
for (int i = 0; i < int(n); i++) {
int l, x;
scanf("%d", &l);
for (int j = 0; j < int(l); j++) {
scanf("%d", &x);
adj[i].push_back(x);
}
}
int cnt = 0;
while (cnt < 100) {
in = false;
if (!solve()) return puts("No");
if (!in) break;
cnt++;
}
vector<int> ans;
for (int i = int(1); i <= int(m); i++)
if (vis[i]) ans.push_back(i);
puts("Yes");
printf("%d\n", int(ans.size()));
for (int i = 0; i < int(int(ans.size())); i++) printf("%d ", ans[i]);
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 2000000000;
const long long INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const long long MOD = 1000000007LL;
int main() {
int n;
std::cin >> n;
std::vector<pair<long long, long long>> a(n);
for (int i = 0; i < (int)(n); i++) {
std::cin >> a[i].first;
}
for (int i = 0; i < (int)(n); i++) {
std::cin >> a[i].second;
}
sort((a).begin(), (a).end());
long long ans = 0ll;
priority_queue<long long> p;
p.push(a[0].second);
long long accumulate = a[0].second;
for (int i = 1; i < (int)(n); i++) {
for (int j = 0; j < (int)(a[i].first - a[i - 1].first); j++) {
if (p.empty()) break;
accumulate -= p.top();
ans += accumulate;
p.pop();
}
p.push(a[i].second);
accumulate += a[i].second;
}
accumulate -= p.top();
p.pop();
while (!p.empty()) {
ans += accumulate;
accumulate -= p.top();
p.pop();
}
std::cout << ans << std::endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
const int inf_int = 1e9 + 100;
const long long inf_ll = 1e18;
const double PI = 3.1415926535898;
bool debug = 0;
int T, K;
const int MOD = 1e9 + 7;
int ans[MAXN];
void solve() {
int n;
cin >> n;
int n1 = n;
while (n > 0) {
int x = 1;
while (x <= n) {
x <<= 1;
}
x >>= 1;
int mn = inf_int;
int m = x;
if (debug) cerr << " $ " << n << " " << m << endl;
for (int i = 0; m + i <= n; ++i) {
ans[m + i] = m - i - 1;
ans[m - i - 1] = m + i;
mn = min(mn, m - i - 1);
}
n = mn - 1;
}
long long res = 0;
n = n1;
for (int i = 0; i <= n; ++i) {
res += (i ^ ans[i]);
}
cout << res << endl;
assert(res == 1ll * n * (n + 1));
for (int i = 0; i <= n; ++i) {
cout << ans[i] << " ";
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
const long long mod = 998244353;
long long n, n2, fact[MAXN], invfact[MAXN];
long long qpow(long long a, long long k) {
long long ans = 1, tmp = a;
while (k) {
if (k & 1) ans = ans * tmp % mod;
tmp = tmp * tmp % mod;
k >>= 1;
}
return ans;
}
int main() {
scanf("%I64d", &n);
fact[1] = 1;
for (int i = 2; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
invfact[n] = qpow(fact[n], mod - 2);
for (int i = n - 1; i >= 0; i--) invfact[i] = invfact[i + 1] * (i + 1) % mod;
n2 = n * n;
long long ans = qpow(3, n2);
long long sub = qpow(qpow(3, n) - 3, n);
long long xishu = -1;
for (int i = 1; i <= n; i++) {
long long tmp = fact[n] * invfact[i] % mod * invfact[n - i] % mod;
long long other = (3ll * qpow(qpow(3, n - i) - 1, n) % mod +
(qpow(3, i) - 3) * qpow(3, (n - i) * n) % mod) %
mod;
tmp = (tmp * other) % mod;
sub = ((sub + tmp * xishu) + mod) % mod;
xishu *= -1;
}
ans = ((ans - sub) % mod + mod) % mod;
printf("%I64d\n", ans);
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9;
vector<pair<int, int> > q[500010];
int n, qn, A[500010], pre[500010], lst[500010], Ans[500010];
pair<int, int> T[500010 * 4];
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void modify(const int &l, const int &r, const int &id, const int &p,
const int &x) {
if (l == r) {
T[id] = make_pair(x, A[p]);
return;
}
int mid = (l + r) >> 1, ls = id << 1, rs = id << 1 | 1;
if (p <= mid)
modify(l, mid, ls, p, x);
else
modify(mid + 1, r, rs, p, x);
if (T[ls].first < T[rs].first)
T[id] = T[ls];
else
T[id] = T[rs];
}
pair<int, int> query(const int &l, const int &r, const int &id, const int &L,
const int &R) {
if (L <= l && r <= R) return T[id];
int mid = (l + r) >> 1, ls = id << 1, rs = id << 1 | 1;
pair<int, int> res = make_pair(1e9, 1e9);
if (L <= mid) res = min(res, query(l, mid, ls, L, R));
if (R > mid) res = min(res, query(mid + 1, r, rs, L, R));
return res;
}
int main() {
n = read();
for (int i = 1; i <= n; ++i) pre[i] = lst[A[i] = read()], lst[A[i]] = i;
qn = read();
for (int i = 1; i <= qn; ++i) {
int l = read(), r = read();
q[r].push_back(make_pair(l, i));
}
for (int i = 1; i <= n; ++i) {
if (pre[i]) modify(1, n, 1, pre[i], Inf);
modify(1, n, 1, i, pre[i]);
for (pair<int, int> x : q[i]) {
pair<int, int> lest = query(1, n, 1, x.first, i);
if (lest.first < x.first) Ans[x.second] = lest.second;
}
}
for (int i = 1; i <= qn; ++i) printf("%d\n", Ans[i]);
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
void fft(vector<complex<double>>& a) {
int n = (int)(a).size(), L = 31 - __builtin_clz(n);
static vector<complex<long double>> R(2, 1);
static vector<complex<double>> rt(2, 1);
for (static int k = 2; k < n; k *= 2) {
R.resize(n);
rt.resize(n);
auto x = polar(1.0L, acos(-1.0L) / k);
for (int i = k; i < (2 * k); ++i)
rt[i] = R[i] = i & 1 ? R[i / 2] * x : R[i / 2];
}
vector<int> rev(n);
for (int i = 0; i < (n); ++i) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
for (int i = 0; i < (n); ++i)
if (i < rev[i]) swap(a[i], a[rev[i]]);
for (int k = 1; k < n; k *= 2)
for (int i = 0; i < n; i += 2 * k)
for (int j = 0; j < (k); ++j) {
auto x = (double*)&rt[j + k], y = (double*)&a[i + j + k];
complex<double> z(x[0] * y[0] - x[1] * y[1], x[0] * y[1] + x[1] * y[0]);
a[i + j + k] = a[i + j] - z;
a[i + j] += z;
}
}
vector<double> conv(const vector<double>& a, const vector<double>& b) {
if (a.empty() || b.empty()) return {};
vector<double> res((int)(a).size() + (int)(b).size() - 1);
int L = 32 - __builtin_clz((int)(res).size()), n = 1 << L;
vector<complex<double>> in(n), out(n);
copy(a.begin(), a.end(), begin(in));
for (int i = 0; i < ((int)(b).size()); ++i) in[i].imag(b[i]);
fft(in);
for (complex<double>& x : in) x *= x;
for (int i = 0; i < (n); ++i) out[i] = in[-i & (n - 1)] - conj(in[i]);
fft(out);
for (int i = 0; i < ((int)(res).size()); ++i) res[i] = imag(out[i]) / (4 * n);
return res;
}
long long rd(double x) {
if (x > 0) return (x + 0.5);
return (x - 0.5);
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int n, m, Q;
cin >> n >> m >> Q;
const int M = int(1e5) + 2;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
vector<long long> all_score(2 * M, 0);
for (int q = 0; q < 2; q++) {
vector<int> ac = a, bc = b;
ac.insert(ac.begin(), q * M);
ac.insert(ac.end(), q * M);
bc.insert(bc.begin(), q * M);
bc.insert(bc.end(), q * M);
vector<double> freq_a(M, 0), freq_b(M, 0);
for (int i = 1; i + 1 < (int)ac.size(); i++) {
if (ac[i - 1] < ac[i] && ac[i] >= ac[i + 1]) freq_a[ac[i]] += 1;
if (ac[i - 1] >= ac[i] && ac[i] < ac[i + 1]) freq_a[ac[i]] -= 1;
}
for (int i = 1; i + 1 < (int)bc.size(); i++) {
if (bc[i - 1] < bc[i] && bc[i] >= bc[i + 1]) freq_b[bc[i]] += 1;
if (bc[i - 1] >= bc[i] && bc[i] < bc[i + 1]) freq_b[bc[i]] -= 1;
}
vector<double> score = conv(freq_a, freq_b);
for (int i = 0; i < (int)score.size(); i++) all_score[i] += rd(score[i]);
}
all_score[0] -= 1;
for (int j = 1; j < 2 * M; j++) all_score[j] += all_score[j - 1];
for (int _ = 0; _ < Q; _++) {
int x;
cin >> x;
cout << -all_score[x - 1] << '\n';
}
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
bool f(int i, int j) { return (i > j); }
int a[2000007];
int main() {
int n, temp;
long long pat = 0;
cin >> n;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n, f);
while (n) {
for (int i = 0; i < n; i++) pat += a[i];
n = n / 4;
}
cout << pat << endl;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int M = 1000000007;
const int N = 2001;
const int INF = 1 << 30;
char field[N][N];
int d[N][N];
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
long long int answer = 0;
long long int prev = 0, cur = 0;
for (int i = 0; i <= n; ++i) {
if (i < n)
cin >> cur;
else
cur = 0;
long long int delta = (prev + cur) / k;
if (delta * k < prev) ++delta;
cur = max(0ll, cur + prev - delta * k);
answer += delta;
prev = cur;
}
cout << answer;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e6 + 5;
vector<long long> v1[MAXN];
vector<long long> vsum[MAXN];
long long in[MAXN];
long long getv(long long curr, long long val) {
long long l = 0;
long long r = v1[curr].size() - 1;
long long ans = -1;
while (l <= r) {
long long mid = (l + r) / 2;
if (v1[curr][mid] < val) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
ans++;
if (ans == 0) {
return 0;
}
return ans * val - vsum[curr][ans - 1];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, q;
cin >> n >> q;
for (long long i = 2; i <= n; i++) {
cin >> in[i];
}
for (long long i = n; i >= 1; i--) {
long long n1 = 2 * i;
long long n2 = 2 * i + 1;
long long p1 = 0;
long long p2 = 0;
v1[i].push_back(0);
while (p1 < v1[n1].size() || p2 < v1[n2].size()) {
if (p2 >= v1[n2].size() ||
(p1 < v1[n1].size()) && v1[n1][p1] + in[n1] <= v1[n2][p2] + in[n2]) {
v1[i].push_back(v1[n1][p1] + in[n1]);
p1++;
} else {
v1[i].push_back(v1[n2][p2] + in[n2]);
p2++;
}
}
vsum[i].push_back(v1[i][0]);
for (long long j = 1; j < v1[i].size(); j++) {
vsum[i].push_back(vsum[i].back() + v1[i][j]);
}
}
while (q--) {
long long t1, t2;
cin >> t1 >> t2;
long long prv = -1;
long long curr = t1;
long long ans = 0;
while (curr) {
if (t2 < 0) {
break;
}
ans += t2;
if (2 * curr <= n && prv != 2 * curr) {
ans += getv(2 * curr, t2 - in[2 * curr]);
}
if (2 * curr + 1 <= n && prv != 2 * curr + 1) {
ans += getv(2 * curr + 1, t2 - in[2 * curr + 1]);
}
t2 -= in[curr];
prv = curr;
curr /= 2;
}
cout << ans << "\n";
}
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
int N, M, T;
map<string, int> mp;
set<string> s;
set<string>::iterator it;
char str[22];
char ss[22][22];
int tb[20][20];
int Mc;
int num[20];
void gen(int idx) {
if (idx == N) {
int i, j, k;
for (i = 1; i <= N; i++)
for (j = i + 1; j <= N; j++)
if (num[i] && num[j] && tb[i][j]) return;
k = 0;
for (i = 1; i <= N; i++)
if (num[i]) k++;
if (k > Mc) {
Mc = k;
s.clear();
for (i = 1; i <= N; i++)
if (num[i]) s.insert(ss[i]);
}
return;
}
num[idx + 1] = 1;
gen(idx + 1);
num[idx + 1] = 0;
gen(idx + 1);
}
int main() {
int i, j, k;
scanf("%d%d", &N, &M);
for (i = 1; i <= N; i++) {
scanf("%s", ss[i]);
mp[ss[i]] = i;
}
int x, y;
for (i = 1; i <= M; i++) {
scanf("%s", str);
x = mp[str];
scanf("%s", str);
y = mp[str];
tb[x][y] = 1;
tb[y][x] = 1;
}
gen(0);
printf("%d\n", Mc);
for (it = s.begin(); it != s.end(); it++) cout << (*it) << endl;
scanf(" ");
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int getint() {
int f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return f * x;
}
const int inf = 12345678;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
int n, m;
char mp[1123][1123];
int dis[1123][1123][3];
bool vis[1123][1123];
priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >,
greater<pair<int, pair<int, int> > > >
q;
void BFS(char v) {
int k = v - '1';
while (!q.empty()) q.pop();
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) dis[i][j][k] = inf;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (mp[i][j] == v) {
dis[i][j][k] = 0;
q.push(make_pair(dis[i][j][k], make_pair(i, j)));
vis[i][j] = true;
}
while (!q.empty()) {
pair<int, int> X = q.top().second;
q.pop();
int x = X.first, y = X.second;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (!vis[nx][ny] && mp[nx][ny] != '#') {
if (mp[nx][ny] == '.')
dis[nx][ny][k] = dis[x][y][k] + 1;
else
dis[nx][ny][k] = dis[x][y][k];
vis[nx][ny] = true;
q.push(make_pair(dis[nx][ny][k], make_pair(nx, ny)));
}
}
}
return;
}
char s[1123];
int main() {
n = getint();
m = getint();
for (int i = 1; i <= n; i++) {
scanf("%s", s + 1);
for (int j = 1; j <= m; j++) mp[i][j] = s[j];
}
for (int i = 0; i <= n + 1; i++) mp[i][0] = mp[i][m + 1] = '#';
for (int j = 0; j <= m + 1; j++) mp[0][j] = mp[n + 1][j] = '#';
BFS('1');
BFS('2');
BFS('3');
int ans = inf;
int mn[3][3];
mn[0][1] = mn[1][2] = mn[2][0] = inf;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
for (int k = 0; k < 3; k++) {
int k1 = k + 1;
if (k1 == 3) k1 = 0;
mn[k][k1] =
min(mn[k][k1], dis[i][j][k] + dis[i][j][k1] - (mp[i][j] == '.'));
}
}
ans = min(ans, min(mn[0][1] + mn[1][2],
min(mn[1][2] + mn[2][0], mn[2][0] + mn[0][1])));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
ans = min(ans, dis[i][j][0] + dis[i][j][1] + dis[i][j][2] -
2 * (mp[i][j] == '.'));
}
if (ans == inf)
printf("-1\n");
else
printf("%d\n", ans);
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
long long nCr(int n, int r) {
if (n - r == 0) return 1;
return nCr(n - 1, r) * (n) / (n - r);
}
int main() {
int n, m, t;
unsigned long long sum = 0;
cin >> n >> m >> t;
for (int i = 4; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i + j == t) {
sum += ((nCr(n, i)) * nCr(m, j));
}
}
}
cout << sum;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int b, c, x, y;
cin >> b >> c >> x >> y;
x++;
y++;
cout << max((max(c - y, y - 1) * b), (max(b - x, x - 1) * c)) << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1e9, 1e9);
map<long long, long long> mp[40][40];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int m, n;
long long k;
cin >> n >> m >> k;
vector<vector<long long>> v(n, vector<long long>(m));
for (auto& i : v)
for (auto& j : i) cin >> j;
if (n == 1) {
for (auto& i : v[0]) k ^= i;
cout << (k ? 0 : 1) << '\n';
exit(0);
}
int p = (n + m - 2) / 2;
for (int mask = 0; mask < (1 << p); ++mask) {
int x = 0, y = 0;
long long s = v[0][0];
for (int i = 0; i < p; ++i) {
++(mask & (1 << i) ? x : y);
if (x >= n || y >= m) break;
s ^= v[x][y];
}
++mp[x][y][s];
}
long long res = 0;
for (int mask = 0; mask < (1 << (n + m - p - 2)); ++mask) {
int x = n - 1, y = m - 1, ok = 1;
long long s = v[x][y];
for (int i = 0; i < (n + m - p - 2); ++i) {
--(mask & (1 << i) ? x : y);
if (x < 0 || y < 0) break;
if (i + 1 == (n + m - p - 2))
res += mp[x][y][k ^ s];
else
s ^= v[x][y];
}
}
cout << res << '\n';
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int n, tp = 0, ct, ans = 0;
struct data {
int v, id, pop;
} a[100005], b[100005];
bool p1(data a, data b) { return a.v == b.v ? a.id < b.id : a.v > b.v; }
bool p2(data a, data b) { return a.id < b.id; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i].v);
a[i].id = i;
b[++tp] = a[i];
if (a[i].v == 0) {
ct = 0;
sort(b + 1, b + 1 + tp, p1);
for (int j = 1; j <= min(tp - 1, 3); j++) {
b[j].pop = 1;
ct++;
}
int cnt = 0;
sort(b + 1, b + 1 + tp, p2);
for (int j = 1; j < tp; j++) {
if (b[j].pop) {
cnt++;
if (cnt == 1)
printf("pushQueue\n");
else if (cnt == 2)
printf("pushStack\n");
else if (cnt == 3)
printf("pushFront\n");
} else
printf("pushBack\n");
}
printf("%d", ct);
if (ct >= 1) printf(" popQueue");
if (ct >= 2) printf(" popStack");
if (ct >= 3) printf(" popFront");
printf("\n");
tp = 0;
}
}
for (int i = 1; i < tp; i++) printf("pushQueue\n");
if (tp >= 1) printf("pushQueue");
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, str;
int n, i, j, cnt = 0, ans;
cin >> n >> s;
for (i = 0; i < n - 1; i++) {
ans = 0;
for (j = i; j < n - 1; j++) {
if (s[j] == s[i] && s[j + 1] == s[i + 1]) ans++;
}
if (ans > cnt) {
cnt = ans;
str.clear();
str.push_back(s[i]);
str.push_back(s[i + 1]);
}
}
cout << str << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, l, c, d, p, nl, np;
cin >> n >> k >> l >> c >> d >> p >> nl >> np;
int drink = (int)k * l / nl;
int lime = c * d;
int salt = p / np;
int ans = min(min(drink, lime), salt);
cout << ans / n << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n + 1], car;
for (int i = 0; i < n; i++) {
cin >> car;
arr[car] = i;
}
int cnt = 1, mx = 0;
for (int i = 1; i < n; i++) {
if (arr[i] < arr[i + 1]) {
cnt++;
} else {
mx = max(mx, cnt);
cnt = 1;
}
}
mx = max(cnt, mx);
cout << n - mx;
return 0;
}
| 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
inline void base() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
bool ok(int a) {
for (int i = 0; i <= 50; i += 10) {
if (a == i + 7) return true;
}
return false;
}
int main() {
base();
int x, a, b;
cin >> x >> a >> b;
int ans = 0;
while (!ok(a) && !ok(b)) {
b -= x;
if (b < 0) b += 60, a--;
if (a < 0) a += 24;
ans++;
}
cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> n >> m;
vector<long long> N(5, 0), M(5, 0);
for (int i = 0; i < n; ++i) ++N[(i + 1) % 5];
for (int i = 0; i < m; ++i) ++M[(i + 1) % 5];
long long ans = N[0] * M[0];
for (int i = 1; i < 5; ++i) ans += N[i] * M[5 - i];
cout << ans << '\n';
}
| 1 |
#include <bits/stdc++.h>
int p[65];
int main() {
int n, x, now = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
now = now ^ x;
x = now;
for (int j = 31; j >= 0; j--) {
if (x & (1 << j)) {
if (!p[j]) {
p[j] = x;
break;
} else
x = x ^ p[j];
}
}
}
if (now == 0) {
printf("-1\n");
return 0;
}
int ans = 0;
for (int i = 31; i >= 0; i--)
if (p[i]) ans++;
printf("%d\n", ans);
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
long long int spf[100010];
void seive() {
spf[1] = 1;
for (long long int i = 2; i < 100010; i += 1) {
spf[i] = i;
}
for (long long int i = 2; i < 100010; i += 2) {
spf[i] = 2;
}
for (long long int i = 3; i * i < 100010; i += 1) {
if (spf[i] == i) {
for (long long int j = i * i; j < 100010; j += i) {
if (spf[j] == j) spf[j] = i;
}
}
}
}
set<long long int> get_fact(long long int x) {
set<long long int> an;
while (x != 1) {
an.insert(spf[x]);
x /= spf[x];
}
return an;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
seive();
long long int n;
cin >> n;
long long int A[n];
for (long long int i = 0; i < n; i += 1) {
cin >> A[i];
}
if (n == 1) {
cout << "1";
return 0;
}
set<long long int> fac;
map<long long int, long long int> cnt;
for (long long int i = n - 1; i >= 0; i--) {
if (A[i] == 1) continue;
fac.clear();
long long int ans = std::numeric_limits<long long int>::min();
fac = get_fact(A[i]);
for (set<long long int>::iterator itr = fac.begin(); itr != fac.end();
itr++)
ans = max(ans, cnt[(*itr)]);
ans++;
for (set<long long int>::iterator itr = fac.begin(); itr != fac.end();
itr++)
cnt[(*itr)] = ans;
}
long long int acc = std::numeric_limits<long long int>::min();
for (map<long long int, long long int>::iterator itr = cnt.begin();
itr != cnt.end(); itr++)
acc = max(acc, itr->second);
cout << acc;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double x1, y1, r1, x2, y2, r2, dis, dis2, dis3, dis1;
cin >> x1 >> y1 >> r1;
cin >> x2 >> y2 >> r2;
dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
dis1 = sqrt(dis);
if (dis1 > r1 + r2) {
if (dis1 > r1 + r2) {
dis2 = dis1 - (r1 + r2);
dis3 = (double)dis2 / 2.0;
cout << std::setprecision(12) << dis3 << endl;
}
} else if (dis1 <= abs(r1 - r2)) {
if (dis1 == abs(r1 - r2)) {
cout << "0" << endl;
} else {
if (r1 > r2) {
dis2 = r1 - dis1 - r2;
} else {
dis2 = r2 - dis1 - r1;
}
dis3 = (double)dis2 / 2.0;
cout << std::setprecision(12) << dis3 << endl;
}
} else {
cout << "0" << endl;
}
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, s, q, d, l;
int t;
int c = 0;
cin >> t >> s >> q;
d = s;
l = 0;
n = 1;
while (l <= t) {
if (l == t) break;
d += (q - 1);
l += q;
if (l >= d && d < t) {
n++;
l = 0;
}
}
cout << n;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;
bool comp(const pair<int, int> &a, const pair<int, int> &b) {
int len = a.second - a.first + 1;
int len2 = b.second - b.first + 1;
if (len == len2) return a.first < b.first;
return (len > len2);
}
void solve() {
int n;
cin >> n;
int ar[n + 7];
set<pair<int, int>, bool (*)(const pair<int, int> &, const pair<int, int> &)>
S(&comp);
S.insert({1, n});
int cnt = 0;
while (!S.empty()) {
auto it = S.begin();
int l = it->first, r = it->second;
S.erase(it);
int len = r - l + 1;
int mid = 0;
if (len & 1) {
mid = (l + r) / 2;
} else {
mid = (l + r - 1) / 2;
}
++cnt;
ar[mid] = cnt;
if (len == 1) continue;
if (mid > l) S.insert({l, mid - 1});
if (mid < r) S.insert({mid + 1, r});
}
for (int i = 1; i <= n; i++) {
cout << ar[i] << " ";
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long nm = 0, fh = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') fh = -1;
for (; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * fh;
}
int n, N;
long long L, a[1000020], b[1000020];
inline bool check(long long x) {
int l = 1, r = 1, mx = -1000000000;
for (int i = n + 1; i <= n + n + n; i++) {
while (l <= N && b[l] < a[i] - x) l++;
while (r <= N && b[r] <= a[i] + x) r++;
mx = max(mx, l - i);
if (r - i - 1 < mx) return false;
}
return true;
}
int main() {
n = read(), L = read();
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= n; i++) b[i] = read();
sort(a + 1, a + n + 1), sort(b + 1, b + n + 1);
for (int i = 1; i <= n; i++)
a[i + n] = a[i] + L, a[i + n + n] = a[i] + L + L,
a[i + n + n + n] = a[i] + L + L + L, b[i + n] = b[i] + L,
b[i + n + n] = b[i] + L + L, b[i + n + n + n] = b[i] + L + L + L;
N = n << 2;
long long ans = L;
for (int k = 30; ~k; k--) {
long long tmp = ans - (1ll << k);
if (tmp >= 0 && check(tmp)) ans = tmp;
}
printf("%lld\n", ans);
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
int n, dfn[MAXN], dfsn, bn, bq;
int beg[MAXN], fin[MAXN];
vector<int> v[MAXN];
struct QUERY {
int type, v, time;
};
vector<QUERY> query[MAXN];
void dfs(int x, int par) {
dfn[x] = beg[x] = fin[x] = ++dfsn;
for (auto &y : v[x]) {
if (y == par) continue;
dfs(y, x);
fin[x] = max(fin[x], fin[y]);
}
}
int bit[4 * MAXN];
vector<int> mt[4 * MAXN];
void go(int x, int par) {
for (auto &t : query[x]) {
if (t.type == 2) {
mt[bn + dfn[x]].push_back(t.time);
}
}
for (auto &y : v[x]) {
if (y == par) continue;
go(y, x);
}
}
int ans[MAXN];
void upd(int x, int y) {
while (x) {
bit[x] += y;
x /= 2;
}
}
int sum(int l, int r) {
int ret = 0;
while (l <= r) {
if (l == r) {
ret += bit[l];
break;
}
if (l & 1) ret += bit[l++];
if (!(r & 1)) ret += bit[r--];
l /= 2;
r /= 2;
}
return ret;
}
int fnd(int x, int y) {
int l = 0, r = mt[x].size() - 1, mid, val, ret = -1;
while (l <= r) {
mid = (l + r) / 2;
val = mt[x][mid];
if (val < y) {
ret = max(ret, val);
l = mid + 1;
} else
r = mid - 1;
}
return ret;
}
void f(int x, int par) {
for (auto &t : query[x]) {
if (t.type == 1) {
upd(bq + t.time, 1);
}
}
for (auto &t : query[x]) {
if (t.type == 3) {
int nt = t.time, t1 = -1, t2 = -1;
{
int l = bn + beg[x], r = bn + fin[x];
while (l <= r) {
if (l == r) {
t2 = max(t2, fnd(l, nt));
break;
}
if (l & 1) {
t2 = max(t2, fnd(l, nt));
l++;
}
if (!(r & 1)) {
t2 = max(t2, fnd(r, nt));
r--;
}
l /= 2;
r /= 2;
}
}
{
int l = 1, r = nt - 1, md;
while (l <= r) {
md = (l + r) / 2;
int s = sum(bq + md, bq + nt);
if (s > 0) {
t1 = max(t1, md);
l = md + 1;
} else
r = md - 1;
}
}
if (t1 == -1 || (t1 < t2))
ans[nt] = 0;
else
ans[nt] = 1;
}
}
for (auto &y : v[x]) {
if (y == par) continue;
f(y, x);
}
for (auto &t : query[x]) {
if (t.type == 1) {
upd(bq + t.time, -1);
}
}
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n - 1; i++) {
int x, y;
scanf("%d%d", &x, &y);
v[x].push_back(y);
v[y].push_back(x);
}
dfs(1, 0);
int Q;
scanf("%d", &Q);
vector<int> ask;
for (int q = 1; q <= Q; q++) {
int a, b;
scanf("%d%d", &a, &b);
if (a == 1) query[b].push_back({1, b, q});
if (a == 2) query[b].push_back({2, b, q});
if (a == 3) query[b].push_back({3, b, q}), ask.push_back(q);
}
bn = 1;
while (bn < n) bn *= 2;
bn--;
bq = 1;
while (bq < Q) bq *= 2;
bq--;
go(1, 0);
for (int i = bn + 1; i <= bn + n; i++) sort(mt[i].begin(), mt[i].end());
for (int i = bn; i >= 1; i--) {
auto &L = mt[i * 2];
auto &R = mt[i * 2 + 1];
int lp = 0, rp = 0;
while (lp < L.size() && rp < R.size()) {
if (L[lp] < R[rp])
mt[i].push_back(L[lp++]);
else
mt[i].push_back(R[rp++]);
}
while (lp < L.size()) mt[i].push_back(L[lp++]);
while (rp < R.size()) mt[i].push_back(R[rp++]);
}
f(1, 0);
for (auto &t : ask) printf("%d\n", ans[t]);
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int arr[100005], dp[100005];
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
queue<int> q;
int d;
int cnt = 0;
std::map<int, int> h1;
for (int i = 0; i < n; ++i) {
cin >> d;
h1[d] = i;
}
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
for (int i = 0; i <= n + 1; ++i) {
dp[i] = mod;
}
for (int i = n - 1; i >= 0; i--) {
dp[i] = min(dp[i + 1], h1[arr[i]]);
}
for (int i = 0; i < n; ++i) {
if (h1[arr[i]] > dp[i + 1]) cnt++;
}
cout << endl;
cout << cnt;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int i_max(int arr[], int n) {
int MAX = arr[0];
int i1 = 0, i2 = 0;
for (int i = 0; i < n; i++) {
if (arr[i] > MAX) {
MAX = arr[i];
i1 = i;
i2 = i;
} else if (arr[i] == MAX) {
i2 = i;
}
}
return max(i1, i2);
}
int i_min(long long int arr[], int n, int& i1, int& i2) {
long long int min = arr[0];
i1 = 0;
i2 = 0;
for (int i = 0; i < n; i++) {
if (arr[i] < min) {
min = arr[i];
i1 = i;
i2 = i;
} else if (arr[i] == min) {
i2 = i;
}
}
return max(i1, i2);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
string s;
bool flag = true;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[0] != '1') {
cout << "NO\n";
flag = false;
break;
}
if (s[i] != '1' && s[i] != '4') {
cout << "NO\n";
flag = false;
break;
}
if (s.find("444") != s.npos) {
cout << "NO\n";
flag = false;
break;
}
}
if (flag) cout << "YES\n";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void read(int &a) {
a = 0;
char c = getchar();
while (c < '0' || c > '9') {
c = getchar();
}
while (c >= '0' && c <= '9') {
a = (a << 1) + (a << 3) + (c ^ 48);
c = getchar();
}
}
const int Maxn = 10000;
const long long Inf = 0x3f3f3f3f3f3f3f3fll;
int n, c;
int p[Maxn + 5], s[Maxn + 5];
long long f[2][Maxn + 5];
int main() {
read(n), read(c);
for (int i = 1; i <= n; i++) {
read(p[i]);
}
for (int i = 1; i <= n; i++) {
read(s[i]);
}
for (int i = 1; i <= n; i++) {
int now = (i & 1), pre = now ^ 1;
memset(f[now], 0x3f, sizeof f[now]);
f[now][0] = f[pre][0] + p[i];
for (int j = 1; j <= i; j++) {
f[now][j] = min(f[pre][j] + p[i] + 1ll * c * j, f[pre][j - 1] + s[i]);
}
}
long long ans = Inf;
for (int i = 0; i <= n; i++) {
ans = min(ans, f[n & 1][i]);
}
printf("%lld\n", ans);
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
int h = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
if (a[i] > a[j]) {
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
for (int i = 1; i < n; i++) {
if (a[i] > a[0]) {
cout << a[i];
h++;
break;
}
}
if (h == 0) {
cout << "NO";
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
cout << "? " << 1 << " " << n << endl;
cout.flush();
int pos;
cin >> pos;
int pp = 0;
if (pos != 1) {
cout << "? " << 1 << " " << pos << endl;
cout.flush();
cin >> pp;
}
if (pp == pos) {
int l = 1;
int r = pos - 1;
while (l < r) {
int mid = (l + r + 1) >> 1;
int k;
cout << "? " <<mid << " " << pos << endl;
cout.flush();
cin >> k;
if (k == pos) l = mid;
else r = mid - 1;
}
cout << "! " << l << endl;
cout.flush();
}
else {
int l = pos + 1;
int r = n;
while (l < r) {
int mid = (l + r) >> 1;
int k;
cout << "? " << pos << " " << mid << endl;
cout.flush();
cin >> k;
if (k == pos) r = mid;
else l = mid + 1;
}
cout << "! " << l << endl;
cout.flush();
}
return 0;
} | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec[100001];
int n, m;
int ret[100001];
void pre() {
int msort[n][m];
memset(msort, 0, sizeof msort);
for (int j = 0; j < m; ++j) {
msort[n - 1][j] = 1;
for (int i = n - 2; i >= 0; i--) {
if (vec[i][j] > vec[i + 1][j]) {
msort[i][j] = 1;
} else {
msort[i][j] = msort[i + 1][j] + 1;
}
}
}
for (int i = 0; i < n; ++i) {
ret[i] = 0;
for (int j = 0; j < m; ++j) ret[i] = max(ret[i], msort[i][j]);
}
}
int main() {
int a;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
scanf("%d", &a);
vec[i].push_back(a);
}
}
pre();
int k;
cin >> k;
int x, y;
for (int i = 0; i < k; ++i) {
scanf("%d %d", &x, &y);
x--;
y--;
if (ret[x] >= y - x + 1)
puts("Yes");
else
puts("No");
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
ifstream in;
ofstream out;
const long long INF = LLONG_MAX;
const long double EPS = 1e-9;
const long double pi = 3.141592653589793238462643383279502884;
long long n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.precision(40);
srand(time(0));
cin >> n;
vector<bool> a(n);
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
a[i] = x & 1;
}
vector<bool> stk;
stk.push_back(a[0]);
for (long long i = 1; i < n; i++) {
if (!stk.empty() && a[i] == stk.back())
stk.pop_back();
else
stk.push_back(a[i]);
}
stk.size() <= 1 ? cout << "YES" : cout << "NO";
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int fa[N];
vector<int> g[N];
int son[N];
int level[N];
int dfs(int x) {
if (g[x].empty()) {
return 0;
}
son[x] += (int)g[x].size();
for (int i = 0; i < g[x].size(); i++) {
son[x] += dfs(g[x][i]);
}
return son[x];
}
void dfs2(int x, int t) {
level[x] = t;
for (int i = 0; i < g[x].size(); i++) {
dfs2(g[x][i], t + 1);
}
}
int main() {
int n;
while (scanf("%d", &n) == 1) {
memset(fa, 0, sizeof(fa));
memset(son, 0, sizeof(son));
memset(level, 0, sizeof(level));
for (int i = 0; i < n; i++) g[i].clear();
int a;
for (int i = 2; i <= n; i++) {
scanf("%d", &a);
fa[i] = a;
g[a].push_back(i);
}
dfs(1);
dfs2(1, 1);
double ans = 0;
for (int i = 1; i < n; i++) {
ans = (level[i] + n - son[i]) * 1.0 / 2;
printf("%.1lf ", ans);
}
ans = (level[n] + n - son[n]) * 1.0 / 2;
printf("%.1lf", ans);
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
string tos(T x) {
stringstream ss;
ss << x;
return ss.str();
}
int Ivan = 0;
vector<pair<int, int> > v1, v2;
int i, h, t, r, m, n;
class Substitute {
public:
};
int vis[1000][1000];
void solve() {
queue<pair<pair<int, int>, int> > q;
memset(vis, 0, sizeof(vis));
pair<pair<int, int>, int> start(pair<int, int>(h, t), 0), cur;
q.push(start);
int cc, ch, ct;
while (!q.empty()) {
cur = q.front();
cc = cur.second;
ch = cur.first.first;
ct = cur.first.second;
q.pop();
if (vis[ch][ct]) continue;
if (!ch && !ct) {
Ivan = cc;
return;
} else {
vis[ch][ct] = 1;
int k, l;
for (k = 0; k < (n > ch ? ch : n); k++)
if (ch - (k + 1) + v1[k].first + ct + v1[k].second <= r)
q.push(pair<pair<int, int>, int>(
pair<int, int>(ch - (k + 1) + v1[k].first, ct + v1[k].second),
cc + 1));
for (l = 0; l < (m > ct ? ct : m); l++)
if (ch - (l + 1) + v2[l].first + ct + v2[l].second <= r)
q.push(pair<pair<int, int>, int>(
pair<int, int>(ch + v2[l].first, ct - (l + 1) + v2[l].second),
cc + 1));
}
}
}
void checkDraw(int ch, int ct) {
if (vis[ch][ct] == 1) {
cout << "Draw\n";
exit(0);
} else if (vis[ch][ct])
return;
vis[ch][ct] = 1;
int k;
for (k = 0; k < (n > ch ? ch : n); k++)
if (ch - (k + 1) + v1[k].first + ct + v1[k].second <= r)
checkDraw(ch - (k + 1) + v1[k].first, ct + v1[k].second);
for (k = 0; k < (m > ct ? ct : m); k++)
if (ch + v2[k].first + ct - (k + 1) + v2[k].second <= r)
checkDraw(ch + v2[k].first, ct - (k + 1) + v2[k].second);
vis[ch][ct] = 2;
}
int checkZmey(int ch, int ct) {
if (ch + ct > r) return 0;
if (vis[ch][ct] >= 0) return vis[ch][ct];
int k, res = 0;
for (k = 0; k < (n > ch ? ch : n); k++)
res = (res > checkZmey(ch - (k + 1) + v1[k].first, ct + v1[k].second) + 1
? res
: checkZmey(ch - (k + 1) + v1[k].first, ct + v1[k].second) + 1);
for (k = 0; k < (m > ct ? ct : m); k++)
res = (res > checkZmey(ch + v2[k].first, ct - (k + 1) + v2[k].second) + 1
? res
: checkZmey(ch + v2[k].first, ct - (k + 1) + v2[k].second) + 1);
return vis[ch][ct] = res;
}
int main() {
cin >> h >> t >> r >> n;
v1.resize(n);
for (i = 0; i < n; i++) cin >> v1[i].first >> v1[i].second;
cin >> m;
v2.resize(m);
for (i = 0; i < m; i++) cin >> v2[i].first >> v2[i].second;
solve();
if (Ivan) {
cout << "Ivan\n" << Ivan << endl;
return 0;
}
memset(vis, 0, sizeof(vis));
checkDraw(h, t);
memset(vis, 255, sizeof(vis));
cout << "Zmey\n" << checkZmey(h, t) << endl;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
bool isSafe(int x, int y, int n, int m) {
return x < n && x >= 0 && y < m && y >= 0;
}
int main() {
int t;
cin >> t;
while (t-- > 0) {
int n;
cin >> n;
char a[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}
bool p = true;
for (int i = n - 1; i >= 0; --i) {
for (int j = n - 1; j >= 0; --j) {
if (a[i][j] == '1') {
if ((isSafe(i, j + 1, n, n) && a[i][j + 1] == '0') &&
(isSafe(i + 1, j, n, n) && a[i + 1][j] == '0')) {
p = false;
break;
}
}
if (!p) {
break;
}
}
}
if (p) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
char ch;
x = 0;
bool fl = false;
while (!isdigit(ch = getchar())) (ch == '-') && (fl = true);
for (x = (ch ^ '0'); isdigit(ch = getchar()); x = x * 10 + (ch ^ '0'))
;
(fl == true) && (x = -x);
}
template <class T>
inline void output(T x) {
if (x / 10) output(x / 10);
putchar(x % 10 + '0');
}
template <class T>
inline void ot(T x) {
if (x < 0) putchar('-'), x = -x;
output(x);
putchar(' ');
}
template <class T>
inline void prt(T a[], int st, int nd) {
for (register int i = st; i <= nd; ++i) ot(a[i]);
putchar('\n');
}
namespace Miracle {
const int N = 55;
const int P = N * N;
const int inf = 0x3f3f3f3f;
int n, m, h;
int s, t;
struct node {
int nxt, to;
int w;
} e[2 * (P + P + N * N)];
int hd[P], cnt = 1;
void add(int x, int y, int z) {
e[++cnt].nxt = hd[x];
e[cnt].to = y;
e[cnt].w = z;
hd[x] = cnt;
e[++cnt].nxt = hd[y];
e[cnt].to = x;
e[cnt].w = 0;
hd[y] = cnt;
}
int d[P];
int q[P], l, r;
int ans;
int dfs(int x, int flow) {
int res = flow;
if (x == t) return flow;
for (register int i = hd[x]; i && res; i = e[i].nxt) {
int y = e[i].to;
if (d[y] == d[x] + 1 && e[i].w) {
int k = dfs(y, min(res, e[i].w));
if (!k) d[y] = 0;
res -= k;
e[i].w -= k;
e[i ^ 1].w += k;
}
}
return flow - res;
}
bool bfs() {
memset(d, 0, sizeof d);
l = 1, r = 0;
q[++r] = s;
d[s] = 1;
while (l <= r) {
int x = q[l++];
for (register int i = hd[x]; i; i = e[i].nxt) {
int y = e[i].to;
if (e[i].w && !d[y]) {
d[y] = d[x] + 1;
q[++r] = y;
if (y == t) return true;
}
}
}
return false;
}
int num(int x, int y) { return (x - 1) * (h + 1) + y + 1; }
int main() {
rd(n);
rd(h);
rd(m);
ans = n * h * h;
s = 0;
t = num(n, h) + 1;
int tot = t;
for (register int i = 1; i <= n; ++i) {
add(s, num(i, 0), inf);
for (register int j = 0; j < h; ++j) {
add(num(i, j), num(i, j + 1), h * h - j * j);
}
}
int l, r, x, c;
for (register int i = 1; i <= m; ++i) {
rd(l);
rd(r);
rd(x);
rd(c);
if (x < h) {
++tot;
add(tot, t, c);
for (register int j = l; j <= r; ++j) {
add(num(j, x + 1), tot, inf);
}
}
}
int flow = 0;
while (bfs()) {
while (flow = dfs(s, inf)) ans -= flow;
}
ot(ans);
return 0;
}
} // namespace Miracle
signed main() {
Miracle::main();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101;
int N;
char S[MAXN];
bool ar[MAXN];
int main() {
cin >> N >> S;
for (int i = 0; i < N; ++i) {
ar[i] = (S[i] == '*');
}
bool good = false;
for (int i = 0; i < N; ++i) {
if (ar[i]) {
for (int len = 1; len < N; ++len) {
bool found = false;
int cur = i;
for (int k = 0; k < 4; ++k) {
cur += len;
if (cur >= N || !ar[cur]) break;
if (k == 3) found = true;
}
good |= found;
}
}
}
cout << (good ? "yes\n" : "no\n");
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
string s, t, tmp;
long long k, good[100005], bad[100005];
const long long mod = 1e9 + 7;
int main() {
cin >> s >> t >> k;
long long n = s.size();
long long x = 0, y = 0, f = 0, l = 0;
if (s.size() != t.size()) {
cout << 0;
return 0;
}
for (int i = 1; i < s.size(); i++) {
tmp = s.substr(i) + s.substr(0, i);
if (tmp == t)
x++;
else
y++;
}
if (s == t) {
good[0] = 1;
good[1] = x, bad[1] = y;
for (int i = 2; i <= k; i++) {
good[i] = good[i - 1] % mod * x % mod + bad[i - 1] % mod * (x + 1) % mod;
bad[i] = good[i - 1] % mod * y % mod + bad[i - 1] % mod * (y - 1) % mod;
good[i] %= mod;
bad[i] %= mod;
}
} else {
good[0] = 0;
good[1] = x, bad[1] = y;
for (int i = 2; i <= k; i++) {
good[i] = good[i - 1] % mod * (x - 1) % mod + bad[i - 1] % mod * x % mod;
bad[i] = good[i - 1] % mod * (y + 1) % mod + bad[i - 1] % mod * y % mod;
good[i] %= mod;
bad[i] %= mod;
}
}
cout << good[k];
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
if (b == 0) return 1;
long long res = 1;
while (b) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
b >>= 1;
}
return res;
}
unsigned long long mulmod(unsigned long long a, unsigned long long b,
unsigned long long m) {
a = a % m;
unsigned long long res = 0;
while (b > 0) {
if (b & 1) res = (res + a) % m;
a = (a << 1) % m;
b >>= 1;
}
return res;
}
unsigned long long power(unsigned long long a, unsigned long long b,
unsigned long long m) {
if (b == 0) return 1;
long long res = 1;
while (b) {
if (b & 1) res = mulmod(res, a, m);
a = mulmod(a, a, m);
b >>= 1;
}
return res;
}
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
bool millerTest(unsigned long long n, unsigned long long d) {
unsigned long long a = 2 + rand() % (n - 4);
unsigned long long x = power(a, d, n);
if (x == 1 || x == n - 1) return true;
while (d != n - 1) {
x = mulmod(x, x, n);
d <<= 1;
if (x == 1) return false;
if (x == n - 1) return true;
}
return false;
}
bool isPrime(unsigned long long n, int k) {
if (n == 2 || n == 3) return true;
if ((n & 1) == 0) return false;
if (n <= 1) return false;
long long d = n - 1;
while ((d & 1) == 0) d >>= 1;
for (int i = 0; i < k; i++)
if (!millerTest(n, d)) return false;
return true;
}
bool visited[1001];
vector<vector<int>> answer;
vector<pair<int, int>> path[1001];
vector<int> leaves[1001];
int father[1001];
int root = 1;
void dfs1(int top) {
visited[top] = true;
for (auto p : path[top]) {
if (visited[p.first]) continue;
dfs1(p.first);
father[p.first] = top;
leaves[top].push_back(leaves[p.first][0]);
}
if (leaves[top].size() == 0) leaves[top].push_back(top);
}
void addPath(int top, int val) {
if (leaves[top].size() == 1) {
answer.push_back({root, top, val});
return;
}
answer.push_back({root, leaves[top][0], val / 2});
answer.push_back({root, leaves[top][1], val / 2});
answer.push_back({leaves[top][0], leaves[top][1], -val / 2});
}
void addEdge(int top, int val) {
if (father[top] == root) {
addPath(top, val);
return;
}
addPath(top, val);
addPath(father[top], -val);
}
void dfs2(int top) {
visited[top] = true;
for (auto p : path[top]) {
if (visited[p.first]) continue;
addEdge(p.first, p.second);
dfs2(p.first);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int u, v, val;
cin >> u >> v >> val;
path[u].push_back({v, val});
path[v].push_back({u, val});
}
for (int i = 1; i <= n; i++) {
if (path[i].size() == 2) {
cout << "NO";
return 0;
}
}
while (path[root].size() != 1) root++;
dfs1(root);
memset(visited, 0, sizeof(visited));
dfs2(root);
cout << "YES" << endl;
cout << answer.size() << endl;
for (auto it : answer) {
for (int j : it) cout << j << " ";
cout << endl;
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long k;
pair<long long, long long> _count(long long x) {
pair<long long, long long> res;
res.first = res.second = 0;
for (int i = 1; i <= n; i++) {
res.first += min((long long)m, (x - 1) / (long long)i);
res.second += min((long long)m, x / (long long)i);
}
res.second--;
return res;
}
void gett(long long x) {
long long res = (long long)1e15;
for (int i = 1; i <= n; i++) {
long long y = x / (long long)i;
if (x % i != 0) y++;
if (y > m) continue;
long long z = y * (long long)i;
res = min(res, z);
}
cout << res << endl;
}
int main() {
cin >> n >> m >> k;
k--;
long long lo = 1, hi = (long long)n * (long long)m, mid;
while (lo + 1 < hi) {
mid = (lo + hi) >> 1;
pair<long long, long long> x = _count(mid);
if (x.second < k)
lo = mid;
else if (x.first > k)
hi = mid;
else {
gett(mid);
return 0;
}
}
pair<long long, long long> x = _count(lo);
if (x.first <= k && x.second >= k)
gett(lo);
else
gett(hi);
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, ans;
cin >> n >> m;
cout << max(0ll, n - m * 2) << " ";
ans = 0;
while (ans * (ans - 1) / 2 < m) ans++;
cout << n - ans;
}
| 2 |
#include <bits/stdc++.h>
using std::cerr;
using std::endl;
inline int rd() {
int a = 1, b = 0;
char c = getchar();
while (!isdigit(c)) a = c == '-' ? 0 : 1, c = getchar();
while (isdigit(c)) b = b * 10 + c - '0', c = getchar();
return a ? b : -b;
}
const int N = 6e5 + 233;
int n, m, ban[N], bad;
struct Edge {
int x, y, w;
} E[N];
std::priority_queue<std::pair<int, int>> que;
int fa[N], ch[N][2], rev[N], stk[N], top;
int size1[N], size2[N];
int val[N], id[N];
inline int isroot(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }
inline void pushup(int x) {
size1[x] = size1[ch[x][0]] + size1[ch[x][1]] + size2[x] + (x <= n);
int o = val[id[ch[x][0]]] > val[id[ch[x][1]]] ? id[ch[x][0]] : id[ch[x][1]];
id[x] = val[o] > val[x] ? o : x;
}
inline void pushdown(int x) {
if (rev[x]) {
std::swap(ch[x][0], ch[x][1]);
rev[ch[x][0]] ^= 1;
rev[ch[x][1]] ^= 1;
rev[x] = 0;
}
}
inline void rotate(int x) {
int y = fa[x], z = fa[y], k = ch[y][1] == x;
if (!isroot(y)) ch[z][ch[z][1] == y] = x;
fa[x] = z, ch[y][k] = ch[x][k ^ 1];
fa[ch[y][k]] = y, ch[x][k ^ 1] = y, fa[y] = x;
pushup(y), pushup(x);
}
inline void preview(int x) {
stk[top = 1] = x;
for (; !isroot(x); x = fa[x]) stk[++top] = fa[x];
while (top) pushdown(stk[top--]);
}
inline void splay(int x) {
preview(x);
while (!isroot(x)) {
int y = fa[x], z = fa[y];
if (!isroot(y)) rotate((ch[y][1] == x) != (ch[z][1] == y) ? x : y);
rotate(x);
}
}
inline void access(int x) {
for (int y = 0; x; y = x, x = fa[x]) {
splay(x);
size2[x] += size1[ch[x][1]] - size1[y];
ch[x][1] = y, pushup(x);
}
}
inline void makeroot(int x) { access(x), splay(x), rev[x] ^= 1; }
inline int findroot(int x) {
access(x), splay(x), pushdown(x);
while (ch[x][0]) pushdown(x = ch[x][0]);
return x;
}
inline void link(int x, int y) {
makeroot(x), access(y), splay(y);
bad -= size1[x] & 1;
bad -= size1[y] & 1;
fa[x] = y, size2[y] += size1[x];
pushup(y);
bad += size1[y] & 1;
}
inline void cut(int x, int y) {
makeroot(x), access(y), splay(y);
bad -= size1[y] & 1;
ch[y][0] = fa[x] = 0;
pushup(y);
bad += size1[x] & 1;
bad += size1[y] & 1;
}
inline int solve(int ver) {
int x = E[ver].x, y = E[ver].y, w = E[ver].w, flag = 1;
if (findroot(x) == findroot(y)) {
makeroot(x), access(y), splay(y);
int o = id[y];
if (val[o] > w) {
cut(E[o - n].x, o);
cut(E[o - n].y, o);
ban[o - n] = 1;
} else
flag = 0;
}
if (flag) {
val[n + ver] = w, id[n + ver] = n + ver;
link(x, n + ver), link(y, n + ver);
que.push({w, ver});
}
if (bad) return -1;
while (!que.empty()) {
int v = que.top().second;
que.pop();
if (ban[v]) continue;
cut(E[v].x, n + v), cut(E[v].y, n + v);
if (bad) {
link(E[v].x, n + v), link(E[v].y, n + v);
que.push({E[v].w, v});
return E[v].w;
}
}
return 0;
}
int main() {
n = bad = rd(), m = rd();
for (int i = 1; i <= m; ++i) {
int x = rd(), y = rd(), c = rd();
E[i] = {x, y, c};
printf("%d\n", solve(i));
}
return 0;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 1, M = 998244353;
long long sf[N];
char a[N], b[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) cin >> b[i];
sf[m - 1] = b[0] == '1';
for (int i = m - 2; i >= 0; --i) sf[i] = sf[i + 1] + (b[m - i - 1] == '1');
long long p = 1, ans = 0;
for (int i = 0; i < n; ++i) {
if (a[n - i - 1] == '1') {
long long res = (p * sf[i]) % M;
ans = (ans + res) % M;
}
p = (p * 2LL) % M;
}
cout << ans;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long long K = 11;
const long long MX = 151;
const long long INF = 1e18;
long long sum[MX][K];
long long sumDig(long long n) {
long long ans = 0;
while (n > 0) {
ans += n % 10;
n /= 10;
}
return ans;
}
void solve() {
long long n, k;
cin >> n >> k;
if (k == 0) {
string s = "";
while (n > 0) {
long long aux = min(n, 9ll);
s = char('0' + aux) + s;
n -= aux;
}
cout << s << "\n";
} else if (k == 1) {
if (n < 40) {
cout << sum[n][k] << "\n";
} else {
string s = "";
if (n % 2 == 0) {
s = "89";
n -= 8 + 9 + 9;
} else {
s = "98";
n -= 8 + 9 + 9 + 9;
}
while (n > 0) {
if (n > 18) {
s = "9" + s;
n -= 18;
} else {
s = char('0' + n / 2) + s;
n = 0;
}
}
cout << s << "\n";
}
} else {
cout << sum[n][k] << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(10);
cout << fixed;
for (long long i = 0; i < MX; i++) {
for (long long j = 0; j < K; j++) {
sum[i][j] = INF;
}
}
for (long long i = 0; i <= 1000000; i++) {
long long ac = 0;
for (long long j = 0; j < K; j++) {
ac += sumDig(i + j);
if (ac < MX) sum[ac][j] = min(sum[ac][j], i);
}
}
for (long long i = 0; i < MX; i++) {
for (long long j = 0; j < K; j++) {
if (sum[i][j] == INF) sum[i][j] = -1;
}
}
long long t;
cin >> t;
while (t--) solve();
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, k;
cin >> n >> k;
long long int i, j;
long long int aa[n + 5];
aa[0] = 0;
for (i = 1; i <= n; i++) {
cin >> aa[i];
aa[i] = aa[i] + aa[i - 1];
}
long long int prev = 1;
long long int sum = 0;
long long int index;
long long int ans;
sort(aa + 1, aa + n);
for (i = 1; i < k; i++) {
sum = sum + aa[i];
}
cout << k * aa[n] - sum;
}
| 3 |
#include "bits/stdc++.h"
#define pb(x) push_back(x)
#define fil(x, y) memset(x, y, sizeof(x))
#define ll long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(x, y) make_pair(x,y)
#define inf INT_MAX
#define infll LLONG_MAX
#define M 1000000007
#define N 200007
#define sm 0.0000007
#define ins insert
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
bool cmp(pii a, pii b)
{
return a.ff < b.ff;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
int ara[n];
bool k[n];
fil(k, 0);
vector <pii> val;
for(int i = 0;i < n;i++)
{
cin >> ara[i];
int x = i - ara[i] + 1;
if(ara[i] > 0){
val.pb(pii(x, i));
// cout << x << " " << i << endl;
}
}
sort(val.begin(), val.end(), cmp);
int x = 0;
for(int i = 0;i < n && x < val.size();i++)
{
// cout << i << " " << val[x].ff << " " << val[x].ss << endl;
if(i >= val[x].ff && i <= val[x].ss)
{
k[i] = 1;
}
else if(i > val[x].ss)
{
x++;
i--;
}
}
for(int i = 0;i < n;i++)
cout << k[i] << " ";
cout << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
#include <utility>
using namespace std;
#define int long long
#define fi(i,n) for(int i=0;i<n;i++)
#define f(i, a, b) for(int i=a;i<b;i++)
#define vi vector<int>
#define pb push_back
#define all(x)(x).begin(), (x).end()
#define MOD 1000000007
#define mod 998244353
#define pii pair<int, int>
#define ff first
#define ss second
#define setzero(a) memset(a,0,sizeof(a))
#define prDouble(x) cout<<fixed<<setprecision(10)<<x;
#define SetBits(x) __builtin_popcount(x)
#define eps 0.000001
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define INF 1e18
#define disp(vec, n) fi(i, n) cout << vec[i] << " ";
void kick(int t) { cout << "Case #" << t << ": "; }
bool valid(int i,int j,int n,int m)
{
return i >= 0 && i < n && j >= 0 && j < m;
}
bool perfect_square(int a)
{
int num = sqrt(a);
if(num*num==a)return true;
return false;
}
int digits(int n)
{
int cnt = 0;
while(n>0)
{
cnt++;
n = n/10;
}
return cnt;
}
int modularExponentiation(int x,int n)
{
int result = 1;
while(n>0)
{
if(n % 2 ==1)
{
result = ((result%MOD)*(x%MOD))%MOD;
}
x = ((x%MOD)*(x%MOD))%MOD;
n = n/2;
}
return result%MOD;
}
void solve()
{
int n;
cin>>n;
int arr[n];
fi(i,n){cin>>arr[i];}
sort(arr,arr+n);
int p = 0;
int q = 0;
fi(i,n)
{
p += q - i*arr[i];
if(i)p += arr[i] - arr[i-1];
else p += arr[i];
q += arr[i];
}
cout<<p<<endl;
}
int32_t main()
{
IOS;
int t;
cin>>t;
while(t--)
{
solve();
}
} | 3 |
#include <bits/stdc++.h>
using namespace std;
char Alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string getCol(int Col) {
int tCol = Col;
int vCol = tCol - 1;
string C;
while (tCol != 0) {
C += Alpha[vCol % 26];
tCol = vCol / 26;
vCol = tCol - 1;
}
reverse(C.begin(), C.end());
return C;
}
int main() {
int T;
cin >> T;
while (T--) {
char S[1000];
cin >> S;
int row, col;
if (sscanf(S, "R%dC%d", &row, &col) == 2) {
cout << getCol(col) << row << endl;
} else {
char K[1000];
col = 0;
sscanf(S, "%[A-Z]%d", K, &row);
for (int i = 0; i < strlen(K); i++) {
float n = pow(26, strlen(K) - 1 - i) * (K[i] - 64);
col += n;
}
cout << "R" << row << "C" << col << endl;
}
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int N;
string S;
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> S;
N = S.size();
int L = 0, R = N - 1;
vector<int> V;
while (L < R) {
while (L < R && S[L] == ')') L++;
while (L < R && S[R] == '(') R--;
if (S[L] == '(' && S[R] == ')') {
V.push_back(L);
V.push_back(R);
L++;
R--;
} else {
break;
}
}
if (V.empty()) {
cout << 0 << endl;
} else {
cout << 1 << endl;
cout << V.size() << endl;
sort((V.begin()), (V.end()));
for (auto& v : V) cout << (v + 1) << " ";
cout << endl;
}
}
int main(int argc, char** argv) {
string s;
int i;
if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100005];
while (cin >> n) {
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
if (a[0] == a[2]) {
long long int x = 3;
for (int i = 3; i < n; i++) {
if (a[i] != a[0]) {
break;
} else {
x++;
}
}
cout << x * (x - 1) * (x - 2) / 6 << endl;
continue;
}
if (a[0] != a[1] && a[1] != a[2]) {
long long int x = 1;
for (int i = 3; i < n; i++) {
if (a[i] != a[2]) {
break;
} else {
x++;
}
}
cout << x << endl;
continue;
}
if (a[0] != a[1] && a[1] == a[2]) {
long long int x = 2;
for (int i = 3; i < n; i++) {
if (a[i] != a[1]) {
break;
} else {
x++;
}
}
cout << x * (x - 1) / 2 << endl;
continue;
}
if (a[0] == a[1] && a[0] != a[2]) {
long long int x = 1;
for (int i = 3; i < n; i++) {
if (a[i] != a[2]) {
break;
} else {
x++;
}
}
cout << x << endl;
}
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
inline long long lin() {
long long x;
scanf("%I64d", &x);
return x;
}
int n;
long long inp[N];
struct Info {
int mx, mx_pos;
int mn, mn_pos;
} t[N * 4];
void Merge(int par, int lft, int rgt) {
if (t[rgt].mx >= t[lft].mx) {
t[par].mx = t[rgt].mx;
t[par].mx_pos = t[rgt].mx_pos;
} else {
t[par].mx = t[lft].mx;
t[par].mx_pos = t[lft].mx_pos;
}
if (t[lft].mn <= t[rgt].mn) {
t[par].mn = t[lft].mn;
t[par].mn_pos = t[lft].mn_pos;
} else {
t[par].mn = t[rgt].mn;
t[par].mn_pos = t[rgt].mn_pos;
}
}
void build(int x, int b, int e) {
if (b == e) {
t[x].mx = inp[b];
t[x].mx_pos = b;
t[x].mn = inp[b];
t[x].mn_pos = b;
return;
}
int m = (b + e) >> 1;
build(x + x, b, m);
build(x + x + 1, m + 1, e);
Merge(x, x + x, x + x + 1);
}
Info get(int x, int b, int e, int l, int r) {
if (b >= l && e <= r) return t[x];
int m = (b + e) >> 1;
if (m >= r)
return get(x + x, b, m, l, r);
else if (m < l)
return get(x + x + 1, m + 1, e, l, r);
else {
Info par, lft, rgt;
lft = get(x + x, b, m, l, r);
rgt = get(x + x + 1, m + 1, e, l, r);
if (rgt.mx >= lft.mx) {
par.mx = rgt.mx;
par.mx_pos = rgt.mx_pos;
} else {
par.mx = lft.mx;
par.mx_pos = lft.mx_pos;
}
if (lft.mn <= rgt.mn) {
par.mn = lft.mn;
par.mn_pos = lft.mn_pos;
} else {
par.mn = rgt.mn;
par.mn_pos = rgt.mn_pos;
}
return par;
}
}
long long Max_find(int l, int r) {
if (l > r) return 0;
if (l == r) return inp[l];
Info found = get(1, 1, n, l, r);
int lft = found.mx_pos - l + 1;
int rgt = r - found.mx_pos + 1;
long long ret = 1ll * lft * rgt * found.mx;
ret = ret + Max_find(l, found.mx_pos - 1) + Max_find(found.mx_pos + 1, r);
return ret;
}
long long Min_find(int l, int r) {
if (l > r) return 0;
if (l == r) return inp[l];
Info found = get(1, 1, n, l, r);
int lft = found.mn_pos - l + 1;
int rgt = r - found.mn_pos + 1;
long long ret = 1ll * lft * rgt * found.mn;
ret = ret + Min_find(l, found.mn_pos - 1) + Min_find(found.mn_pos + 1, r);
return ret;
}
int main() {
n = in();
for (int i = 1; i <= n; i++) {
inp[i] = lin();
}
build(1, 1, n);
long long ans = Max_find(1, n) - Min_find(1, n);
printf("%I64d\n", ans);
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int c = 42, k = 8, c2 = (1 << 20);
int n, m, szint[c];
long long elm[c], po[c], ans[k], akt[k];
bool el[c][c], v[c], pkor;
int maskdb[c2], jodb[c2];
vector<int> sz;
void dfs(int a) {
v[a] = true;
sz.push_back(a);
for (int i = 1; i <= n; i++) {
if (el[a][i] && !v[i]) {
szint[i] = szint[a] + 1;
dfs(i);
}
if (el[a][i] && ((szint[a] % 2) == (szint[i] % 2))) {
pkor = 1;
}
}
}
int main() {
cin >> n >> m;
po[0] = 1;
for (int i = 1; i <= n; i++) {
po[i] = po[i - 1] * 2;
}
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
el[a][b] = 1, el[b][a] = 1;
elm[a] += po[b], elm[b] += po[a];
}
ans[0] = 1;
for (int cs = 1; cs <= n; cs++) {
if (v[cs]) {
continue;
}
pkor = 0;
dfs(cs);
int si = sz.size(), fel = si / 2, m1 = (1 << fel), m2 = (1 << (si - fel));
for (int i = 0; i < k; i++) {
akt[i] = 0;
}
if (si == 1) {
akt[0] = 2;
} else {
for (int i = 0; i < m2; i++) {
maskdb[i] = 0, jodb[i] = 0;
}
for (int mask = 0; mask < m1; mask++) {
long long res = 0;
bool baj = 0;
for (int i = 0; i < fel; i++) {
if (mask & (1 << i)) {
if (res & po[sz[i]]) {
baj = 1;
}
res = (res | elm[sz[i]]);
}
}
if (!baj) {
int marad = m2 - 1;
for (int i = fel; i < si; i++) {
if (res & po[sz[i]]) {
marad -= (1 << (i - fel));
}
}
maskdb[marad]++;
}
}
for (int mask = 0; mask < m2; mask++) {
long long res = 0;
bool baj = 0;
for (int i = fel; i < si; i++) {
if (mask & (1 << (i - fel))) {
if (res & po[sz[i]]) {
baj = 1;
}
res = (res | elm[sz[i]]);
}
}
if (!baj) {
jodb[mask]++;
}
}
for (int i = 0; i < si - fel; i++) {
for (int j = 0; j < m2; j++) {
if ((j & po[i]) == 0) {
jodb[j + po[i]] += jodb[j];
}
}
}
long long sum = 0;
for (int i = 0; i < m2; i++) {
sum += maskdb[i] * jodb[i];
}
sum--;
akt[1] = akt[4] = 1;
if (!pkor) {
sum -= 2;
akt[2] = 2;
}
akt[3] = akt[6] = sum;
akt[7] = po[si];
for (int i = 0; i < 7; i++) {
akt[7] -= akt[i];
}
}
for (int pos = 7; pos >= 0; pos--) {
long long ert = 0;
for (int i = 0; i < k; i++) {
for (int j = 0; j < k; j++) {
if ((i | j) == pos) {
ert += ans[i] * akt[j];
}
}
}
ans[pos] = ert;
}
sz.clear();
}
cout << ans[7] << "\n";
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10, MAXM = 1e6 + 10;
const int INF = INT_MAX, SINF = 0x3f3f3f3f;
const long long llINF = LLONG_MAX;
const int MOD = 1e9 + 7, mod = 998244353;
const int inv2 = 5e8 + 4;
int n, b, k, x;
struct Matrix {
long long a[105][105];
Matrix operator*(const Matrix &rhs) const {
Matrix res;
memset(res.a, 0, sizeof(res.a));
for (int i = 0; i < x; i++)
for (int j = 0; j < x; j++)
for (int k = 0; k < x; k++)
(res.a[i][j] += a[i][k] * rhs.a[k][j]) %= MOD;
return res;
}
};
Matrix ksm(Matrix base, int v) {
Matrix res;
memset(res.a, 0, sizeof(res.a));
res.a[0][0] = 1;
while (v) {
if (v & 1) (res = res * base);
base = base * base;
v >>= 1;
}
return res;
}
int cnt[MAXN];
int main() {
scanf("%d%d%d%d", &n, &b, &k, &x);
for (int i = 1; i <= n; i++) {
int p;
scanf("%d", &p);
cnt[p % x]++;
}
Matrix base;
memset(base.a, 0, sizeof(base.a));
for (int i = 0; i < x; i++)
for (int j = 0; j < x; j++) {
base.a[i][(i * 10 + j) % x] += cnt[j];
}
Matrix res = ksm(base, b);
cout << res.a[0][k];
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int64_t factorial(int64_t n) {
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
int64_t power(int64_t x, int64_t y) {
int64_t res = 1;
while (y > 0) {
if (y & 1) res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
int64_t powerMod(int64_t x, int64_t y, int64_t m) {
if (y == 0) return 1;
int64_t p = powerMod(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
int64_t modInverse(int64_t a, int64_t m) { return powerMod(a, m - 2, m); }
int64_t gcd(int64_t a, int64_t b) {
if (a == 0) {
return b;
} else if (b == 0) {
return a;
} else {
if (a > b) {
return gcd(a % b, b);
} else {
return gcd(b % a, a);
}
}
}
void pre() {}
void solve() {
int64_t n = 0;
cin >> n;
for (int64_t i = 0; i < n; i++) cout << 2 << " ";
cout << "\n";
}
int main() {
int64_t t = 1;
cin >> t;
pre();
while (t--) solve();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
char str[50010];
int f[3000][3000];
pair<int, int> path[3000][3000];
int c[26], n;
bool mk[3000];
void go(int a, int b) {
if (a == 0 && b == 0) return;
go(path[a][b].first, path[a][b].second);
if (path[a][b].first + 1 == a && path[a][b].second + 1 == b) {
mk[a - 1] = mk[n - b] = true;
}
}
int main() {
while (~scanf("%s", str)) {
n = strlen(str);
memset(c, 0, sizeof(c));
for (int i = 0; i < (n); i++) c[str[i] - 'a']++;
bool flag = false;
for (int i = 0; i < (26); i++)
if (c[i] >= 100) {
flag = true;
for (int j = 0; j < (100); j++) {
cout << (char)('a' + i);
}
cout << endl;
break;
}
if (flag) continue;
memset(f, 0, sizeof(f));
int a = -1, b = -1;
for (int i = 0; i < (n); i++) {
for (int j = 0; j < (n - i); j++) {
if (str[i] == str[n - 1 - j]) {
if (i == n - 1 - j) {
f[i + 1][j + 1] = f[i][j] + 1;
} else {
f[i + 1][j + 1] = f[i][j] + 2;
}
path[i + 1][j + 1] = make_pair(i, j);
} else {
if (f[i][j + 1] > f[i + 1][j]) {
f[i + 1][j + 1] = f[i][j + 1];
path[i + 1][j + 1] = make_pair(i, j + 1);
} else {
f[i + 1][j + 1] = f[i + 1][j];
path[i + 1][j + 1] = make_pair(i + 1, j);
}
}
if (a == -1 && b == -1 || f[a][b] < f[i + 1][j + 1]) {
a = i + 1;
b = j + 1;
}
}
}
memset(mk, 0, sizeof(mk));
if (f[a][b] > 100) {
for (int i = 0; i < (n); i++) {
for (int j = 0; j < (n - i); j++)
if (f[i + 1][j + 1] == 100) {
flag = true;
go(i + 1, j + 1);
break;
}
if (flag) break;
}
} else
go(a, b);
for (int i = 0; i < (n); i++)
if (mk[i]) cout << str[i];
cout << endl;
}
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
int x = 0;
char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
return x;
}
const int N = 600005;
int n, m, r[N];
long long g, mod, w[2][N], W[2][N], X[N], Y[N], a[N], b[N], c[N], da[N], rb[N],
dc[N];
inline long long mul(long long a, long long b) {
return (a * b - (long long)((long double)a * b / mod) * mod + mod) % mod;
}
inline long long pw(long long a, long long b) {
long long r = 1;
for (; b; b >>= 1, a = mul(a, a))
if (b & 1) r = mul(r, a);
return r;
}
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void gtP() {
for (m = 1; m <= 2 * n; m <<= 1)
;
long long lcm = 1ll * n * m / gcd(n, m);
mod = 1;
while (mod < 1e5) mod += lcm;
while (true) {
int ff = 1;
for (int i = 2; 1ll * i * i <= mod; i++)
if (mod % i == 0) {
ff = 0;
break;
}
if (ff)
break;
else
mod += lcm;
}
for (g = 2;; g++) {
int f = 1;
for (int i = 2; 1ll * i * i <= mod; i++)
if ((mod - 1) % i == 0)
if (pw(g, i) == 1 || pw(g, (mod - 1) / i) == 1) {
f = 0;
break;
}
if (f) break;
}
}
inline void gtW() {
long long w0 = pw(g, (mod - 1) / m);
w[0][0] = w[1][0] = 1;
for (int i = 1; i < m; i++) w[1][m - i] = w[0][i] = mul(w[0][i - 1], w0);
w0 = pw(g, (mod - 1) / n);
W[0][0] = W[1][0] = 1;
for (int i = 1; i < n; i++) W[1][n - i] = W[0][i] = mul(W[0][i - 1], w0);
}
inline void ntt(long long* a, int n, int f) {
int l = 0;
while ((1 << l) < n) l++;
for (int i = 1; i < n; i++) r[i] = r[i >> 1] >> 1 | (i & 1) << (l - 1);
for (int i = 0; i < n; i++)
if (i < r[i]) swap(a[i], a[r[i]]);
for (int i = 1; i < n; i <<= 1)
for (int j = 0, t = n / (i << 1); j < n; j += i << 1)
for (int k = l = 0; k < i; k++, l += t) {
long long x = a[j + k], y = mul(a[j + k + i], w[f][l]);
a[j + k] = x + y;
a[j + k + i] = x - y;
if (a[j + k] >= mod) a[j + k] -= mod;
if (a[j + k + i] < 0) a[j + k + i] += mod;
}
if (f) {
long long iv = pw(n, mod - 2);
for (int i = 0; i < n; i++) a[i] = mul(a[i], iv);
}
}
inline void preB(int f) {
for (int i = 0; i < 2 * n; i++)
Y[2 * n - 1 - i] = W[f][1ll * i * (i - 1) / 2 % n];
for (int i = 2 * n; i < m; i++) Y[i] = 0;
ntt(Y, m, 0);
}
inline void bluestein(long long* a, int f) {
for (int i = 0; i < n; i++)
X[i] = mul(a[i], W[f][(n - 1ll * i * (i - 1) / 2 % n) % n]);
for (int i = n; i < m; i++) X[i] = 0;
ntt(X, m, 0);
for (int i = 0; i < m; i++) X[i] = mul(X[i], Y[i]);
ntt(X, m, 1);
for (int i = 0; i < n; i++)
a[i] = mul(X[2 * n - 1 - i], W[f][(n - 1ll * i * (i - 1) / 2 % n) % n]);
if (f) {
long long iv = pw(n, mod - 2);
for (int i = 0; i < n; i++) a[i] = mul(a[i], iv);
}
}
int main() {
n = rd();
for (int i = 0; i < n; i++) b[i] = rd();
for (int i = 0; i < n; i++) c[i] = rd();
gtP();
gtW();
long long iv2 = pw(mod - 2, mod - 2), ca = 0, cb = 0, cc = -c[0], sum = 0;
for (int i = 0; i < n; i++) rb[i] = b[i];
reverse(rb + 1, rb + n);
for (int i = 0; i < n; i++)
dc[i] = mul((c[(i + 1) % n] - c[i] + mod) % mod, iv2);
preB(0);
bluestein(rb, 0);
bluestein(dc, 0);
for (int i = 0; i < n; i++) da[i] = mul(dc[i], pw(rb[i], mod - 2));
preB(1);
bluestein(da, 1);
for (int i = 0; i < n; i++) {
long long v = (da[i] < mod - da[i]) ? da[i] : da[i] - mod;
if (abs(v) > 5000000) {
puts("0");
return 0;
} else
a[i] = v;
}
for (int i = 0; i < n; i++) {
ca++;
cb += 2 * (sum - b[i]);
cc += (sum - b[i]) * (sum - b[i]);
sum += a[i];
}
if (sum != 0) {
puts("0");
return 0;
}
set<long long> ans;
if (cb * cb - 4 * ca * cc >= 0) {
long long s = (long long)(sqrt(cb * cb - 4 * ca * cc) + 0.5);
if (s * s != cb * cb - 4 * ca * cc) {
puts("0");
return 0;
}
if ((-cb + s) % (2 * ca) == 0) ans.insert((-cb + s) / (2 * ca));
if ((-cb - s) % (2 * ca) == 0) ans.insert((-cb - s) / (2 * ca));
}
printf("%d\n", (int)ans.size());
for (set<long long>::iterator it = ans.begin(); it != ans.end(); it++) {
long long x = *it;
for (int i = 0; i < n; i++) printf("%lld ", x), x += a[i];
puts("");
}
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
int a[2005][2005], visit[2005][2005], cx[2005 * 2005], cy[2005 * 2005],
can[2005 * 2005], c1, n, cnt, cntC, cntS;
double dist[2005 * 2005], Ox, Oy;
void dfs(int x, int y) {
if (visit[x][y]) return;
visit[x][y] = 1;
++cnt;
bool bo = 0;
Ox += x;
Oy += y;
for (int dx = -1; dx <= 1; ++dx)
for (int dy = -1; dy <= 1; ++dy) {
int x1 = x + dx, y1 = y + dy;
if (!a[x1][y1])
++bo;
else
dfs(x1, y1);
}
if (bo) ++c1, cx[c1] = x, cy[c1] = y;
}
int main() {
scanf("%d", &n);
memset(visit, 1, sizeof(visit));
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) scanf("%d", &a[i][j]), visit[i][j] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (!visit[i][j] && a[i][j]) {
c1 = 0;
cnt = 0;
Ox = 0;
Oy = 0;
dfs(i, j);
if (cnt < 130) continue;
double ave_d = 0;
int c1_pre = c1;
Ox /= cnt;
Oy /= cnt;
for (int k = 1; k <= c1; ++k)
dist[k] =
sqrt((Ox - cx[k]) * (Ox - cx[k]) + (Oy - cy[k]) * (Oy - cy[k]));
sort(dist + 1, dist + c1 + 1);
reverse(dist + 1, dist + c1 + 1);
c1 = min(c1, int(8.1 * sqrt(1.0 * cnt / 0.8)));
int _c1 = c1;
for (int k = 1; k <= c1; ++k) ave_d += dist[k];
ave_d /= c1;
for (int k = 1; k <= c1; ++k) can[k] = 1;
for (int k = 1; k <= c1; ++k)
if (dist[k] < ave_d * 0.87) --_c1, can[k] = 0;
ave_d = 0;
for (int k = 1; k <= c1; ++k)
if (can[k]) ave_d += dist[k];
ave_d /= _c1;
double ave = 0, sum = 0;
for (int k = 1; k <= c1; ++k)
if (can[k]) ave += dist[k];
ave /= _c1;
for (int k = 1; k <= c1; ++k)
if (can[k]) sum += fabs(dist[k] - ave);
sum /= _c1;
if (sum / ave < 0.05)
++cntC;
else
++cntS;
}
end:;
printf("%d %d\n", cntC, cntS);
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int casi;
cin >> casi;
while (casi--) {
int n;
cin >> n;
if (n == 1) {
cout << 2 << '\n';
continue;
} else if (n == 2) {
cout << 4 << " " << 6 << '\n';
continue;
}
for (int i = 1; i <= n; i++) cout << 2 * n + 2 * i << " ";
cout << '\n';
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
if (a == b)
cout << a << endl;
else
cout << 1 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int letternum = 26;
const int maxn = 5005;
bool checked[maxn];
int main() {
string s;
cin >> s;
int n = s.size();
s = s + s;
vector<vector<int> > cnt(letternum);
for (int i = 0; i < n; i++) {
cnt[s[i] - 'a'].push_back(i);
}
int ans = 0;
for (int c = 0; c < letternum; c++) {
int best = 0;
for (int i = 1; i < n; i++) {
vector<int> num(letternum, 0);
for (auto k : cnt[c]) {
num[s[i + k] - 'a']++;
}
int tmp = 0;
for (int i = 0; i < letternum; i++) tmp += num[i] == 1;
if (best < tmp) best = tmp;
}
ans += best;
}
printf("%.8lf\n", (double)ans / n);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline P smin(P &a, Q b) {
if (b < a) a = b;
return a;
}
template <class P, class Q>
inline P smax(P &a, Q b) {
if (a < b) a = b;
return a;
}
const long long N = 1e5 + 5;
long long read() {
long long x;
cin >> x;
return x;
}
long long dw[N], up[N], a[N], ondw[N], onup[N];
vector<long long> adj[N];
void dfs_down(long long v, long long p = -1) {
ondw[v] = a[v];
dw[v] = a[v];
long long max0 = 0, max1 = 0;
for (long long u : adj[v])
if (u != p) {
dfs_down(u, v);
smax(dw[v], dw[u]);
smax(ondw[v], ondw[u] + a[v]);
smax(dw[v], ondw[v]);
long long x = ondw[u];
if (max0 <= x)
max1 = max0, max0 = x;
else if (max1 <= x)
max1 = x;
}
smax(dw[v], max1 + max0 + a[v]);
}
void dfs_up(long long v, long long val = 0, long long onu = 0,
long long p = -1) {
if (p != -1) {
smax(up[v], val);
smax(onup[v], onu);
smax(up[v], onup[v]);
}
vector<long long> lmax0(adj[v].size() + 3, 0), rmax0(adj[v].size() + 3, 0),
lmax1(adj[v].size() + 3, 0), rmax1(adj[v].size() + 3, 0),
lmx(adj[v].size() + 3, 0), rmx(adj[v].size() + 3, 0);
long long cur = 1;
long long max0 = 0, max1 = 0;
for (long long u : adj[v])
if (u != p) {
long long x = ondw[u];
if (max0 <= x)
max1 = max0, max0 = x;
else if (max1 <= x)
max1 = x;
smax(lmx[cur], max(lmx[cur - 1], dw[u]));
lmax0[cur] = max0;
lmax1[cur] = max1;
cur++;
}
max0 = 0, max1 = 0;
cur--;
for (long long i = adj[v].size() - 1; i >= 0; --i)
if (adj[v][i] != p) {
long long u = adj[v][i];
long long x = ondw[u];
if (max0 <= x)
max1 = max0, max0 = x;
else if (max1 <= x)
max1 = x;
smax(rmx[cur], max(rmx[cur + 1], dw[u]));
rmax0[cur] = max0;
rmax1[cur] = max1;
cur--;
}
cur = 1;
for (long long u : adj[v])
if (u != p) {
long long z[5];
z[0] = lmax0[cur - 1], z[1] = lmax1[cur - 1];
z[2] = rmax0[cur + 1], z[3] = rmax1[cur + 1];
z[4] = onu;
sort(z, z + 5);
long long maxonu = max(onu + a[v], z[4] + a[v]);
long long go = z[3] + z[4] + a[v];
dfs_up(u, max(val, max(go, max(lmx[cur - 1], rmx[cur + 1]))), maxonu, v);
cur++;
}
}
int32_t main() {
ios_base ::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n = read();
for (long long i = 0, _n = (long long)(n); i < _n; i++) cin >> a[i];
for (long long i = 0, _n = (long long)(n - 1); i < _n; i++) {
long long u = read() - 1, v = read() - 1;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs_down(0);
dfs_up(0);
long long res = 0;
for (long long i = 0, _n = (long long)(n); i < _n; i++) {
smax(res, dw[i] + up[i]);
}
cout << res;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = ~0ull / 4;
const long long maxn = 210000;
bool can[2][30][60][60];
bool ev[30][800];
long long dp[60][60];
vector<string> v[30];
int32_t main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
string s[2];
cin >> s[0] >> s[1];
long long n;
cin >> n;
for (long long i = 0; i < n; i++) {
string t;
cin >> t;
long long ind = (t[3] - 'a') * 26 + (t[4] - 'a');
ev[t[0] - 'a'][ind] = 1;
}
for (long long t = 0; t < 2; t++) {
for (long long i = 0; i < s[t].length(); i++)
can[t][s[t][i] - 'a'][i][i] = 1;
for (long long d = 1; d < s[t].length(); d++) {
for (long long i = 0; i < s[t].length(); i++) {
long long j = i + d;
if (j >= s[t].length()) break;
for (long long g = i; g < j; g++)
for (long long b = 0; b < 26; b++)
for (long long c = 0; c < 26; c++)
if (can[t][b][i][g] and can[t][c][g + 1][j])
for (long long a = 0; a < 26; a++)
if (ev[a][b * 26 + c]) can[t][a][i][j] = 1;
}
}
}
for (long long i = 0; i < s[0].length(); i++) {
for (long long j = 0; j < s[1].length(); j++) {
long long t = maxn;
for (long long g = 0; g < i + 1; g++)
for (long long r = 0; r < j + 1; r++) {
long long I = i - g;
long long J = j - r;
for (long long a = 0; a < 26; a++) {
if (!can[0][a][I][i] or !can[1][a][J][j]) continue;
if (!I and !J)
t = min(t, 1ll);
else if (I and J)
t = min(t, 1 + dp[I - 1][J - 1]);
}
}
dp[i][j] = t;
}
}
long long ans = dp[s[0].length() - 1][s[1].length() - 1];
if (ans == maxn) ans = -1;
cout << ans << "\n";
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[405];
vector<int> R[405];
int a[405][405];
int bfs(vector<int> vec[], int n, int src) {
int val;
queue<int> q;
int taken[405] = {0}, distance[405] = {0};
q.push(src);
taken[src] = 1;
distance[src] = 0;
while (!q.empty()) {
int u = q.front();
for (int i = 0; i < vec[u].size(); i++) {
int v = vec[u][i];
if (!taken[v]) {
distance[v] = distance[u] + 1;
taken[v] = 1;
q.push(v);
}
}
q.pop();
}
return distance[n];
}
int main() {
int x, y, node, src, edge, r, rr, p, u, v, j, i, cnt;
cin >> node >> edge;
cnt = 0;
if (edge == 0) {
cout << -1;
return 0;
}
for (int i = 0; i < edge; i++) {
cin >> x >> y;
a[x][y] = 1;
a[y][x] = 1;
G[x].push_back(y);
G[y].push_back(x);
}
for (i = 1; i <= node; i++) {
for (j = 1; j <= node; j++) {
if (a[i][j] == 0) {
R[i].push_back(j);
R[j].push_back(i);
}
}
}
src = 1;
u = bfs(G, node, src);
v = bfs(R, node, src);
if (u == 0 || v == 0)
cout << -1;
else
cout << max(u, v);
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long x[2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
x[i % 2] += a / 2;
x[(i + 1) % 2] += (a + 1) / 2;
}
cout << min(x[0], x[1]) << endl;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 9;
int b, g, n;
int main() {
scanf("%d%d%d", &b, &g, &n);
int cou = 0;
for (int i = 0; i <= b; i++) {
if (n - i >= 0 && n - i <= g) {
cou++;
}
}
printf("%d", cou);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long n) {
if (n < 2) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
for (int i = 3; i * i <= n; i = i + 2) {
if (n % i == 0) return false;
}
return true;
}
long long twomutiplierwithminimumdiffrence(long long n) {
int x = sqrt(n);
int y = x;
if (isprime(n)) {
cout << 1 << " " << n;
return 0;
}
while (1) {
if (x * y == n)
break;
else if (x * y > n)
x--;
else
y++;
}
return x;
}
long long largest_power(long long N) {
N = N | (N >> 1);
N = N | (N >> 2);
N = N | (N >> 4);
N = N | (N >> 8);
N = N | (N >> 16);
return (N + 1) >> 1;
}
long long fact(long long n) {
if (n == 0) return 1;
return ((n % 998244353) * (fact(n - 1)) % 998244353) % 998244353;
}
long long calculate(long long p, long long q) {
long long expo;
expo = 998244353 - 2;
while (expo) {
if (expo & 1) {
p = (p * q) % 998244353;
}
q = (q * q) % 998244353;
expo >>= 1;
}
return p;
}
void solution() {
int n;
int k;
cin >> n;
cin >> k;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int res = 0;
int i = n - 2 * k;
int j = n - 1;
int z = 0;
map<int, int> mp;
while (i < n) {
mp[a[i]]++;
z = max(z, mp[a[i]]);
i++;
}
res = max(0, z - k);
for (int i = 0; i < n - 2 * k; i++) {
res += a[i];
}
cout << res << endl;
}
int main() {
ios::sync_with_stdio(false);
int tc = 1;
cin >> tc;
while (tc--) {
solution();
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int T;
cin >> T;
while (T--) {
string a;
string b;
cin >> a >> b;
if (a[0] != b[0]) {
cout << "NO\n";
continue;
}
a += '#';
int curr = -1;
int flag = 0;
int cnt = 0;
for (auto u : b) {
if (u == a[curr + 1]) {
curr = curr + 1;
} else if (u == a[curr]) {
} else
flag = 1;
}
if (flag == 1 || curr != a.size() - 2)
cout << "NO\n";
else
cout << "YES\n";
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c;
double x[3];
cin >> a >> b >> c;
if (a == 0 && b == 0 && c == 0) {
cout << "-1" << endl;
return 0;
}
if (a == 0 && b == 0) {
cout << "0" << endl;
return 0;
}
if (a == 0) {
cout << "1" << endl;
cout << fixed << setprecision(10) << double(-c / b) << endl;
return 0;
}
if (b * b - 4 * a * c < 0) {
cout << "0" << endl;
return 0;
}
x[0] = double(-b + sqrt(b * b - 4 * a * c)) / double(2 * a);
x[1] = double(-b - sqrt(b * b - 4 * a * c)) / double(2 * a);
if (x[0] == x[1]) {
cout << "1" << endl;
cout << fixed << setprecision(10) << x[0] << endl;
return 0;
} else {
cout << "2" << endl;
cout << fixed << setprecision(10) << min(x[0], x[1]) << endl;
cout << fixed << setprecision(10) << max(x[0], x[1]) << endl;
return 0;
}
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
pair<int, long long> findMaxBlocksAndVolumeHelper(long long volumeLimit,
int currentBlocks,
long long currentVolume) {
if (volumeLimit == 0) return make_pair(currentBlocks, currentVolume);
long long maxA = floor(cbrt(volumeLimit));
pair<int, long long> bigBlockState = findMaxBlocksAndVolumeHelper(
volumeLimit - maxA * maxA * maxA, currentBlocks + 1,
currentVolume + maxA * maxA * maxA);
if (maxA > 1) {
pair<int, long long> smallBlockState = findMaxBlocksAndVolumeHelper(
maxA * maxA * maxA - 1 - (maxA - 1) * (maxA - 1) * (maxA - 1),
currentBlocks + 1,
currentVolume + (maxA - 1) * (maxA - 1) * (maxA - 1));
if (smallBlockState.first > bigBlockState.first ||
(smallBlockState.first == bigBlockState.first &&
smallBlockState.second > bigBlockState.second))
return smallBlockState;
}
return bigBlockState;
}
pair<int, long long> findMaxBlocksAndVolume(long long volumeLimit) {
return findMaxBlocksAndVolumeHelper(volumeLimit, 0, 0);
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long M;
cin >> M;
pair<int, long long> blockVolume = findMaxBlocksAndVolume(M);
cout << blockVolume.first << ' ' << blockVolume.second << endl;
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, l, r, i, a[100005], x, m = 1000000000000, mn = 0;
int main() {
cin >> n >> l >> r;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) {
cin >> x;
a[i] += x;
m = min(m, a[i]);
mn = max(mn, a[i]);
}
if (mn - m > r - l)
cout << -1 << endl;
else {
x = m - l;
for (i = 1; i <= n; i++) cout << a[i] - x << " ";
cout << endl;
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300;
char s[N];
int n;
char ss[] = "AGCT";
int cnt[4];
int main() {
scanf("%d", &n);
scanf("%s", s);
if (n % 4) {
puts("===");
return 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++)
if (s[i] == ss[j]) cnt[j]++;
}
for (int i = 0; i < 4; i++)
if (cnt[i] > n / 4) {
puts("===");
return 0;
}
for (int i = 0; i < n; i++)
if (s[i] == '?') {
for (int j = 0; j < 4; j++)
if (cnt[j] < n / 4) {
cnt[j]++;
s[i] = ss[j];
break;
}
}
puts(s);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 401000;
const int BSIZE = 200;
const int NBUCK = 200000 / BSIZE + 20;
int N, Q;
int par[MAXN];
int ssize[MAXN];
int sloc[MAXN];
vector<int> child[MAXN];
int nord;
int ord[MAXN];
long long a[MAXN], b[MAXN];
pair<long long, long long> pp[MAXN];
int M;
long long nadd[NBUCK];
int gind[NBUCK];
vector<int> qloc[NBUCK];
vector<int> bloc[NBUCK];
inline bool cmp(int x, int y) { return b[x] < b[y]; }
void flood(int cloc) {
ord[nord] = cloc;
sloc[cloc] = nord;
nord++;
for (int x : child[cloc]) flood(x);
}
long long ginter(int i, int j) {
return (a[i] * b[i] - a[j] * b[j]) / (b[j] - b[i]);
}
void gen(int ind) {
qloc[ind].clear();
for (int i = ind * BSIZE; i < min(N, (ind + 1) * BSIZE); i++) {
a[i] += nadd[ind];
a[i + N] += nadd[ind];
}
nadd[ind] = 0;
for (int i : bloc[ind]) {
qloc[ind].push_back(i);
int q = qloc[ind].size();
if (q >= 2) {
int j = qloc[ind][q - 2];
if (b[j] == b[i]) {
if (a[j] * b[j] > a[i] * b[i])
qloc[ind].pop_back();
else {
qloc[ind][q - 2] = i;
qloc[ind].pop_back();
}
q--;
}
}
while (q >= 3) {
int x = qloc[ind][q - 3], y = qloc[ind][q - 2], z = qloc[ind][q - 1];
if (ginter(x, y) >= ginter(y, z)) {
qloc[ind][q - 2] = z;
qloc[ind].pop_back();
q--;
} else
break;
}
}
gind[ind] = 0;
}
long long csolve(int ind) {
int x = qloc[ind][gind[ind]];
long long lv = (a[x] + nadd[ind]) * b[x];
while (gind[ind] + 1 < qloc[ind].size()) {
int y = qloc[ind][gind[ind] + 1];
long long nv = (a[y] + nadd[ind]) * b[y];
if (nv >= lv) {
gind[ind]++;
lv = nv;
} else
break;
}
return lv;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> N >> Q;
for (int i = 1; i < N; i++) {
cin >> par[i];
par[i]--;
child[par[i]].push_back(i);
}
for (int i = 0; i < N; i++) ssize[i] = 1;
for (int i = N - 1; i >= 1; i--) ssize[par[i]] += ssize[i];
for (int i = 0; i < N; i++) {
cin >> a[i];
if (i) a[i] += a[par[i]];
}
for (int i = 0; i < N; i++) {
cin >> b[i];
if (i) b[i] += b[par[i]];
}
nord = 0;
flood(0);
for (int i = 0; i < N; i++) pp[i] = make_pair(a[i], b[i]);
for (int i = 0; i < N; i++) {
a[i] = pp[ord[i]].first;
b[i] = pp[ord[i]].second;
a[i + N] = a[i];
b[i + N] = -b[i];
}
M = (N - 1) / BSIZE + 1;
for (int i = 0; i < M; i++) {
for (int j = i * BSIZE; j < i * BSIZE + BSIZE; j++)
if (j < N) {
bloc[i].push_back(j);
bloc[i].push_back(j + N);
}
sort(bloc[i].begin(), bloc[i].end(), cmp);
nadd[i] = 0;
gen(i);
}
for (int q = 0; q < Q; q++) {
int c;
cin >> c;
if (c == 1) {
int v, x;
cin >> v >> x;
v--;
int sstart = sloc[v], send = sloc[v] + ssize[v];
int bstart = sstart / BSIZE, bend = send / BSIZE;
if (bstart != bend) {
for (int i = bstart + 1; i < bend; i++) nadd[i] += x;
for (int i = sstart; i < (bstart + 1) * BSIZE; i++) {
a[i] += x;
a[i + N] += x;
}
gen(bstart);
for (int i = bend * BSIZE; i < send; i++) {
a[i] += x;
a[i + N] += x;
}
gen(bend);
} else {
for (int i = sstart; i < send; i++) {
a[i] += x;
a[i + N] += x;
}
gen(bend);
}
} else {
int v;
cin >> v;
v--;
long long ans = 0;
int sstart = sloc[v], send = sloc[v] + ssize[v];
int bstart = sstart / BSIZE, bend = send / BSIZE;
if (bstart != bend) {
for (int i = bstart + 1; i < bend; i++) ans = max(ans, csolve(i));
for (int i = sstart; i < (bstart + 1) * BSIZE; i++)
ans = max(ans, abs((a[i] + nadd[bstart]) * b[i]));
for (int i = bend * BSIZE; i < send; i++)
ans = max(ans, abs((a[i] + nadd[bend]) * b[i]));
} else {
for (int i = sstart; i < send; i++)
ans = max(ans, abs((a[i] + nadd[bend]) * b[i]));
}
cout << ans << "\n";
}
}
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
long long int a[16];
long long int dp[1000000];
long long int cost[16][16];
long long int modpow(long long int base, int exp) {
if (exp == 0) return 1;
if (exp == 1) return base;
long long int pv = modpow(base, exp / 2);
pv = (pv * pv) % int(1e9 + 7);
if (exp % 2 == 0) return pv;
pv = (base * pv) % int(1e9 + 7);
return pv;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cost[i][j] =
(a[i] * modpow(a[i] + a[j], int(1e9 + 7) - 2)) % int(1e9 + 7);
}
}
for (int msk = 1; msk < (1 << n); msk++) {
if (__builtin_popcount(msk) == 1) {
dp[msk] = 1;
continue;
}
vector<int> v;
v.clear();
for (int i = 0; i < n; i++) {
int x = msk & (1 << i);
if (x > 0) v.push_back(i);
}
int sz = v.size();
dp[msk] = 1;
for (int submask = 1; submask < (1 << sz) - 1; submask++) {
long long int naive = 1;
int prev_mask = 0;
vector<int> inside_bits, outside_bits;
inside_bits.clear();
outside_bits.clear();
for (int i = 0; i < sz; i++) {
int x = submask & (1 << i);
if (x > 0) {
inside_bits.push_back(v[i]);
prev_mask += (1 << v[i]);
} else
outside_bits.push_back(v[i]);
}
assert(!inside_bits.empty());
assert(!outside_bits.empty());
for (int in : inside_bits) {
for (int out : outside_bits) {
naive = naive * cost[in][out] % int(1e9 + 7);
}
}
assert(prev_mask < (1 << n));
dp[msk] -= (dp[prev_mask] * naive) % int(1e9 + 7);
dp[msk] %= int(1e9 + 7);
}
}
long long int ret = 0;
for (int msk = 1; msk < (1 << n); msk++) {
long long int naive = 1;
for (int t = 0; t < n; t++) {
for (int q = 0; q < n; q++) {
int x = msk & (1 << t);
int y = msk & (1 << q);
if (x > 0 and y == 0) naive = (naive * cost[t][q]) % int(1e9 + 7);
}
}
ret = (ret + (((__builtin_popcount(msk) * naive) % int(1e9 + 7)) * dp[msk] %
int(1e9 + 7))) %
int(1e9 + 7);
}
if (ret < 0) ret += int(1e9 + 7);
cout << ret << endl;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
char a[15], b[15], c[15], d[15];
int main() {
scanf("%s%s", a, b);
printf("%s %s\n", a, b);
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s%s", c, d);
if (!strcmp(a, c))
strcpy(a, d);
else
strcpy(b, d);
printf("%s %s\n", a, b);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, m, l, r, c, p, ans;
vector<long long> cnt[1000005], val[1000005];
struct BIT {
long long tree[1000005];
BIT() {
memset(tree, 0, sizeof(tree));
return;
}
inline long long lowbit(long long x) { return x & (-x); }
inline void add(long long pos, long long val) {
while (pos <= 1000000) tree[pos] += val, pos += lowbit(pos);
return;
}
inline long long ask(long long pos) {
long long ans = 0;
while (pos) ans += tree[pos], pos -= lowbit(pos);
return ans;
}
} bit1, bit2;
signed main() {
cin >> n >> k >> m;
for (long long i = 1; i <= m; i++) {
scanf("%lld%lld%lld%lld", &l, &r, &c, &p);
cnt[l].push_back(c), val[l].push_back(p);
cnt[r + 1].push_back(-c), val[r + 1].push_back(p);
}
for (long long i = 1; i <= n; i++) {
for (long long j = 0, len = cnt[i].size(); j < len; j++) {
bit1.add(val[i][j], cnt[i][j]);
bit2.add(val[i][j], val[i][j] * cnt[i][j]);
}
long long l = 1, r = 1000000, now = 1000000;
while (l <= r) {
long long mid = (l + r) / 2;
if (bit1.ask(mid) >= k)
now = mid, r = mid - 1;
else
l = mid + 1;
}
if (bit1.ask(now) > k)
ans += bit2.ask(now) - (bit1.ask(now) - k) * now;
else
ans += bit2.ask(now);
}
cout << ans << endl;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int rev(int n) {
int res = 0;
for (int i = 0; i < 8; ++i) res += ((n >> i) & 1) << (8 - i - 1);
return res;
}
int main() {
string s;
while (getline(cin, s)) {
int prev = 0;
for (int i = 0; i < s.length(); ++i) {
int t = (prev - rev(s[i]) + 256) % 256;
prev = rev(s[i]);
cout << t << endl;
}
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[300005] , spare = 0;
int main(){
ll n , q , i , j;
cin >> n >> q;
set < pair < ll , ll > > cur;
for(i = 1;i<=n;i++){
cin >> a[i];
cur.insert( { i , a[i] } );
}
while(q--){
ll x , gone = 0;
cin >> x;
pair < ll , ll > ind;
for(auto i : cur){
gone++;
if (i.second == x){
ind = i;
break;
}
}
cout << gone << "\n";
cur.erase(ind);
cur.insert({ spare , ind.second }) ;
spare--;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void _DBG(const char *s, _T x) {
cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
while (*s != ',') cerr << *s++;
cerr << " = " << x << ',';
_DBG(s + 1, a...);
}
const int N = 2e5 + 7;
int n, k, T[N], pre[N][3][3];
char s[N], mp[256];
int ask(int l, int r, int v, int m3) {
return pre[r][v][m3] - pre[l - 1][v][m3];
}
int calc(int i, int a, int b, int c) {
int j = i + k - 1, ans = k;
ans -= ask(i, j, a, i % 3);
ans -= ask(i, j, b, (i + 1) % 3);
ans -= ask(i, j, c, (i + 2) % 3);
return ans;
}
void solve() {
cin >> n >> k >> (s + 1);
for (int i = 1; i <= n; i++) T[i] = mp[s[i]];
for (int i = 0; i <= n; i++)
for (int j = 0; j < 3; j++)
for (int l = 0; l < 3; l++) pre[i][j][l] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 3; j++)
for (int l = 0; l < 3; l++) pre[i][j][l] = pre[i - 1][j][l];
pre[i][T[i]][i % 3]++;
}
int mn = N;
for (int i = 1; i + k - 1 <= n; i++) {
mn = min(mn, calc(i, 0, 1, 2));
mn = min(mn, calc(i, 1, 2, 0));
mn = min(mn, calc(i, 2, 0, 1));
}
cout << mn << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
mp['R'] = 0;
mp['G'] = 1;
mp['B'] = 2;
int q;
cin >> q;
while (q--) {
solve();
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
struct num {
int num;
int mo;
} a[10];
bool cmp(num a, num b) { return a.mo < b.mo; }
int main() {
for (int i = 1; i <= 3; i++) {
cin >> a[i].num;
a[i].mo = a[i].num % 3;
}
sort(a + 1, a + 4, cmp);
long long ans;
ans = a[1].num / 3 + a[2].num / 3 + a[3].num / 3 + a[1].mo;
if (a[1].num >= 3 && a[1].mo == 0 && a[2].mo == 2 && a[3].mo == 2) {
ans++;
}
cout << ans;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n, kk;
int a[maxn];
double f[2][maxn][maxn];
int Sum(int n) { return n * (n + 1) / 2; }
int main() {
scanf("%d%d", &n, &kk);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
kk = min(kk, 900);
for (int k = 1; k <= kk; k++) {
for (int l = 1; l <= n; l++) {
for (int r = l; r <= n; r++) {
f[k & 1][l][r] = 0.0;
for (int s = 1 + r; s <= l + n; s++) {
f[k & 1][l][r] += max(0, min(n, s - 1) - max(r, s - l) + 1) *
(1.0 - f[~k & 1][s - r][s - l]);
}
for (int s = 1 + l; s <= l + r - 1; s++) {
f[k & 1][l][r] += max(0, min(r - 1, s - 1) - max(l, s - l) + 1) *
f[~k & 1][s - l][r];
}
for (int s = l + 1 + r; s <= r + n; s++) {
f[k & 1][l][r] += max(0, min(n, s - 1 - l) - max(r, s - r) + 1) *
f[~k & 1][l][s - r];
}
f[k & 1][l][r] +=
(Sum(l - 1) + Sum(n - r) + Sum(r - l - 1)) * f[~k & 1][l][r];
f[k & 1][l][r] /= ((1 + n) * n / 2);
}
}
}
double ans = 0.0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (a[i] > a[j])
ans += 1.0 - f[kk & 1][i][j];
else
ans += f[kk & 1][i][j];
}
}
printf("%.12lf\n", ans);
return 0;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
;
{
int n, k, q;
cin >> n >> k >> q;
long long t[n + 1];
for (int i = 1; i < n + 1; i++) cin >> t[i];
vector<pair<long long, long long>> v;
for (int i = 0; i < q; i++) {
int x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
set<long long> s;
set<long long>::iterator it;
for (int i = 0; i < q; i++) {
if (v[i].first == 1) {
if (s.size() < k)
s.insert(v[i].second);
else {
int mn = 1000000007, mn_idx;
for (it = s.begin(); it != s.end(); it++) {
if (t[*it] < mn) {
mn = t[*it];
mn_idx = *it;
}
}
if (mn < t[v[i].second]) {
s.erase(mn_idx);
s.insert(v[i].second);
}
}
} else if (v[i].first == 2) {
if (s.find(v[i].second) != s.end())
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
}
}
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
long long maxn = 1000000;
long long BIT[1000001];
void update(long long pos, long long val) {
for (long long i = pos; i <= maxn; i += i & (-i)) {
BIT[i] += val;
}
}
long long bitse(long long val, long long n) {
long long sum = 0;
long long pos = 0;
long long logn = log2(maxn);
for (long long i = logn; i >= 0; i--) {
if (pos + (1 << i) <= maxn && (sum + BIT[pos + (1 << i)]) < val) {
sum += BIT[pos + (1 << i)];
pos += (1 << i);
}
}
return pos + 1;
}
void solve() {
long long n, q;
cin >> n >> q;
vector<long long> cnt(n + 1, 0);
long long x;
for (int i = 0; i < n; i++) {
cin >> x;
cnt[x]++;
}
for (int i = 1; i <= n; i++) {
update(i, cnt[i]);
}
for (int i = 0; i < q; i++) {
long long ip;
cin >> ip;
if (ip > 0) {
cnt[ip]++;
update(ip, 1);
} else {
ip = abs(ip);
long long valatp = bitse(ip, n);
update(valatp, -1);
cnt[valatp]--;
}
}
for (int i = 1; i <= n; i++) {
if (cnt[i] > 0) {
cout << i << endl;
break;
}
if (i == n) {
cout << "0" << endl;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int k;
cin >> k;
vector<vector<bool> > vec(1, vector<bool>(1, 1));
while (k--) {
int n = vec.size();
for (int i = 0; i < n; i++) {
vec[i].insert(vec[i].end(), vec[i].begin(), vec[i].end());
vec.push_back(vec[i]);
for (int j = 0; j < n; j++) vec[i][n + j] = !vec[i][j];
}
}
int n = vec.size();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) cout << ((vec[i][j]) ? '+' : '*');
cout << endl;
}
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int const INF = numeric_limits<int>::max();
inline int count_ones(int a) {
int ans = 0;
while (a > 0) {
ans += a & 1;
a >>= 1;
}
return ans;
}
int const MAX = pow(2, 16);
int const N = 1e5 + 5;
int a[N];
long long m[N];
int main() {
ios::sync_with_stdio(false);
vector<int> v;
int n, k;
cin >> n >> k;
for (int i = 0; i < MAX; i++) {
if (count_ones(i) == k) {
v.push_back(i);
}
}
long long ans = 0;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
for (auto& mask : v) {
ans += m[mask ^ x];
}
m[x]++;
}
cout << ans << endl;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long maxi = LLONG_MIN;
long long mini = LLONG_MAX;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main() {
fast();
int x;
cin >> x;
if (x == 1) {
cout << "-1" << '\n';
} else if (x == 2) {
cout << "2"
<< " "
<< "2" << '\n';
} else {
cout << x - 1 << " " << x - 1 << '\n';
}
return 0;
}
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.