solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 0;
scanf("%d", &n);
int ans = n - 2;
long long Ans = 0;
while (1) {
for (int i = 1; i <= n; i++) {
for (int j = 2; j <= n; j++) {
for (int k = 3; k <= n; k++) {
if ((i + j) == k) {
Ans = Ans + (i * ... | 4 |
#include <bits/stdc++.h>
using namespace std;
tuple<int, int, int> a[100005];
bool u[100005], v[100005];
int main() {
int n, m, s, c;
scanf("%d%d%d", &n, &m, &s);
for (int i = 0; i < n; i++) scanf("%d", &get<0>(a[i]));
for (int i = 0; i < n; i++) {
scanf("%d", &get<1>(a[i]));
get<2>(a[i]) = i;
}
sor... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool check(pair<int, int> &a, pair<int, int> &b) {
if (a.first > b.second || a.second < b.first) return false;
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q;
cin >> q;
while (q--) {
int n, t0;
cin >> n >> t0;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int inf = 1000000002;
struct node {
int l, r, id;
bool operator<(const node &c) const {
if (l != c.l)
return l < c.l;
else
return r < c.r;
}
} a[N], b[N];
int n, m, num[N], ans[N], nxt;
set<pair<int, int> > s;
int main()... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int i;
cin >> s;
long long c1 = 0, c2 = 0;
i = s.find('^');
for (int j = i - 1; j >= 0; j--) {
if (s[j] != '=') {
c1 += (s[j] - '0') * (i - j);
}
}
for (int j = i + 1; j < s.length(); j++) {
if (s[j] != '=') {
c... | 1 |
#include <bits/stdc++.h>
using namespace std;
unsigned int calc(unsigned int n, unsigned int m) {
unsigned int counter = 0;
while (n >= 1 && m >= 2 || n >= 2 && m >= 1) {
if (n > m) {
n -= 2;
m--;
counter++;
} else if (m > n) {
n--;
m -= 2;
counter++;
} else {
n... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
if (n == 1) {
return false;
}
if (n == 2 or n == 3) {
return true;
}
if (n % 2 == 0 or n % 3 == 0) {
return false;
}
for (int i = 5; i * i <= n; i += 6) {
if (n % i == 0 or n % (i + 2) == 0) {
return false;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q, w, re;
scanf("%d %d", &q, &w);
if (q == 1 && w == 1)
re = 1;
else if (q - w > w - 1)
re = w + 1;
else
re = w - 1;
printf("%d\n", re);
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n(0);
cin >> n;
vector<int> v(n);
long long sum_b(0), sum_c(0);
for (auto i = 0; i < n; i++) {
cin >> v[i];
if (v[i] >= 0)
sum_b += v[i];
else
sum_c += v[i];
}
cout << sum_b - sum_c << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, maxn;
double p[111], l, r, mid, f[333][333];
const double eps = 1e-7;
bool check(double mid) {
for (int i = 0; i <= maxn; i++) {
for (int j = 0; j <= maxn; j++) f[i][j] = -1e9;
}
for (int i = 0; i <= maxn; i++) {
for (int j = 0; j <= i && j <= n; j++) {... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long MOD = 1e9 + 7;
const long double pi = 3.14159265359;
long long n, d[N], u[N];
multiset<long long> s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (long long i = 0; i < n; i++) cin >> d[i];
for (l... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
vector<long long> ans(n, 0);
vector<pair<long long, int>> d;
for (int i... | 11 |
#include <bits/stdc++.h>
const int N = 5050;
using namespace std;
int n, m;
int a[N], g, f[N];
set<int> s[N];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
f[a[i]]++;
if (f[a[i]] > f[g]) g = a[i];
}
for (int i = 1; i <= f[g]; i++) s[i].insert... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int c[n], t[n], v[m];
map<int, int> ma;
int start = 0;
for (int i = 0; i < n; i++) {
cin >> c[i] >> t[i];
ma[i] = (start + c[i] * t[i]);
start = ma[i];
}
for (int i = 0; i < m; i++) {
cin >> v[i];
}
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const char lf = '\n';
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
return a < b ? a : b;
}
template <typename T1, typename T2>
inline T1 gmax(T1 &a, T2 b) {
retu... | 23 |
#include <bits/stdc++.h>
using namespace std;
int n, t[200000];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> t[i];
sort(t, t + n);
cout << min(t[n - 2] - t[0], t[n - 1] - t[1]);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int N;
int a[105], b[105];
int p[105];
bool dfs(int i, int k, int sum) {
if (k == N) {
if ((int)sqrt((double)sum) * (int)sqrt((double)sum) == sum) {
for (i = 0; i < N; ++i) a[i] = p[i];
return true;
}
return false;
}
for (; i <= 1000; ++i) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i <= 810; i++) {
if (i * 1234567 > n) break;
for (int j = 0; j <= 8100; j++) {
if (i * 1234567 + j * 123456 > n) break;
int k = n - i * 1234567 - j * 123456;
if (k % 1234 == 0) {
pu... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n;
int a[maxn];
int mx[maxn];
int mk[maxn];
int ans[maxn][26];
void in();
void solve();
void out();
int main() {
in();
solve();
out();
}
void in() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
cin >> n;
}
void solve() {... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long one = 1, two = 2;
int main() {
long long k, q, n;
cin >> k >> q;
while (q--) {
cin >> n;
long long i = 63;
for (; i >= 0; i--) {
if (n % (one << i) == 0) break;
}
string s;
cin >> s;
long long level = (one << i);
for (lo... | 11 |
#include <bits/stdc++.h>
constexpr auto MAX_BIT_INT = 31;
constexpr auto MOD = 1000000007;
using namespace std;
int n, k, p[5005], q, c;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> p[i];
sort(p, p + n);
cin >> q;
while (q) {
q--;
cin >> c;
int ans = 100;
for (int i = 0; i < ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> g[N];
int deep[N], cnt[N];
void dfs(int o, int u) {
deep[u] = deep[o] + 1;
for (int i = 0; i < g[u].size(); i++) {
if (g[u][i] != o) dfs(u, g[u][i]);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4;
long long a[maxn];
long long b[maxn];
long long M;
int check(int L, int R) {
int j = 1;
long long ans2;
if (a[L] > b[1])
ans2 = M - a[L] + b[1];
else if (a[L] <= b[1])
ans2 = b[1] - a[L];
for (int i = L; i <= R; i++, j++) {
if ((a... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, i, j;
cin >> n >> k;
vector<pair<long long, long long> > v;
map<long long, long long> m;
for (i = 0; i < n; i++) {
long long a;
cin >> a;
v.push_back(make_pair(a, i));
m[a] = i;
}
int a[n];
memset(a, 0, sizeof(a))... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[500005], n, id[500005], prv[500005], nxt[500005];
long long ans;
bool cmp(int x, int y) { return a[x] < a[y]; }
int main() {
int i;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", a + i);
id[i] = i;
prv[i] = i - 1;
nxt[i] = i + 1;
}
s... | 17 |
#include <bits/stdc++.h>
using namespace std;
int t, n, k, cnt[30];
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
for (int i = 0; i < t; ++i) {
cin >> n >> k;
cin >> s;
sort(s.begin(), s.end());
for (int j = 0; j < 26; ++j) {
cnt[j] = 0;
}
for (a... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int H, M;
scanf("%d:%d", &H, &M);
do {
H = (H + (++M / 60)) % 24;
M %= 60;
} while (!(H / 10 == M % 10 && H % 10 == M / 10));
printf("%02d:%02d\n", H, M);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
bool isLucky(int number) {
int ok = 1;
do {
int digit = number % 10;
if (digit != 4 && digit != 7) {
ok = 0;
break;
}
number /= 10;
} while (number);
return ok;
}
void countVertex(vector<int>& answer, const vector<vector<int> >& graph) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1 || n == 2) {
cout << "No";
return 0;
}
cout << "Yes\n";
cout << n / 2 << " ";
for (int i = 2; i <= n; i += 2) cout << i << ' ';
cout << '\n';
cout << ceil((float)n / 2) << ' ';
for (int i = 1; i <= n; i +=... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = (1e9);
const long long N = 1e5 + 5;
const long long M = 998244353;
void solve() {
long long n;
cin >> n;
vector<long long> a(n + 1, -1);
for (long long i = n; i > 1; i -= 2) {
a[i] = i - 1;
a[i - 1] = i;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int v[200005];
long long cmmdc(long long a, long long b) {
long long r;
while (b) {
r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
long long t, n, i, j, mn = 100003LL * 100003LL, k, a, b, mx = 0, pz, tot;
cin >> k >> n >> a >> b;
tot = n * 1LL... | 9 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const long long M = (1e9) + 7;
const long long N = 100005;
const long long NF = 1010;
long long n, m;
long long zyx[NF][NF];
void dfs(long long x, long long y) {
if (x < 1 |... | 7 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> a[200005];
int32_t main() {
long long t = 1;
cin >> t;
while (t--) {
long long n, w;
cin >> n >> w;
for (long long i = 1; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a + 1, a + n + 1);
long l... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << (6 * n * (n - 1)) + 1;
return 0;
}
| 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\t";
err(++it, args...);
}
template <typename T1, typenam... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
while (arr[0] != 0) {
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
if (arr[i] < n - 1)
arr[i]++;
else
arr[i] = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
void input() {
int i, n, cnt0, cnt5, x;
scanf("%d", &n);
cnt0 = cnt5 = 0;
for ((i) = 0; (i) < (n); (i)++) {
scanf("%d", &x);
if (x)
cnt5++;
else
cnt0++;
}
if (cnt5) {
while ((cnt5 * 5) % 9) cnt5--;
if (cnt5) {
if (cnt0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> s;
vector<long long> A;
vector<long long> B;
long long a, b;
long long h = 0, p = 1e18;
long long f(long long x, long long y) {
h = 0;
for (long long j = 0; j < A.size(); j++) {
if ((x >= A[j] && y >= a / A[j]) || (x >= a / A[j] && y >= A[j])) {
... | 12 |
#include <bits/stdc++.h>
const int N = 200010;
const int Y = N >> 5;
int qn;
char sa[N], sb[N];
int cnt[N];
unsigned int ca[N], cb[N], *ia, *ib;
const int mod = (1 << 16) - 1;
inline unsigned int B(int i) { return 1 << i; }
void genc(char sx[], unsigned int cx[]) {
for (int i = 0; sx[i]; i++) {
int u = i >> 5, v ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a1, a2, k1, k2, n;
cin >> a1 >> a2 >> k1 >> k2 >> n;
if (k1 > k2) {
swap(a1, a2);
swap(k1, k2);
}
cout << max(0, n - ((k1 - 1) * a1 + (k2 - 1) * a2));
cout << " " << min(n / k1, a1) + min(a2, (n - (min(n / k1, a1) * k1)) / k2);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int count = 0;
while (n--) {
string s;
cin >> s;
s[0] = tolower(s[0]);
if (s == "cube") {
count += 6;
} else if (s == "tetrahedron") {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int cnt, bn;
int a[maxn], b[maxn];
int le[maxn], ri[maxn];
long long f[maxn][2];
vector<int> v[maxn];
int solve(int i, int j, int k) {
int ans = 1e9;
int p = lower_bound(b + 1, b + bn + 1, j) - b;
if (p <= bn) {
int res = b[p] - j;
r... | 13 |
#include <bits/stdc++.h>
using namespace std;
queue<long long> q;
stack<long long> s;
deque<long long> deq;
priority_queue<long long> pq;
const long long maxn = 200005;
long long n, m, l, r, k;
long long ans = 0;
long long a[maxn];
int main() {
long long T;
cin >> T;
while (T--) {
long long ans = 0;
cin >... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 4e3 + 10;
const long long MAX_M = 65 + 10;
const long long mod = 1e9 + 7;
const int INF = 1e9;
inline long long bpow(long long t, long long n) {
long long ans = 1;
while (n > 0) {
if (n & 1) ans = (ans * t) % mod;
t = (t * t) % mod, n >>=... | 17 |
#include <bits/stdc++.h>
using namespace std;
int hoge, foo, bar, t, m, n;
string s;
int main() {
stack<char> a;
cin >> s;
while (!a.empty()) a.pop();
int ans = 0;
int l = s.size();
for (int i = 0; i < l; i++) {
if (s[i] == '(' || s[i] == '{' || s[i] == '[' || s[i] == '<')
a.push(s[i]);
else i... | 6 |
#include <bits/stdc++.h>
int main() {
int arr[1001], n, i, flag = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
if (arr[i] == 0) flag++;
}
if (n == 1 && arr[0] == 1)
flag = 1;
else if (n == 1 && arr[0] == 0)
flag = 0;
if (flag == 1)
printf("YES");
else
print... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> debts(n, 0);
int i;
for (i = 0; i < m; i++) {
int a, b, debt;
cin >> a >> b >> debt;
debts[a - 1] += debt;
debts[b - 1] -= debt;
}
int sum = 0;
for (auto debt : debts) {
if (debt > 0) sum ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt;
long long a, sum, ans[100010];
queue<long long> q[100010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a);
for (int j = 60; j >= 0; j--) {
if (a & (1LL << j)) {
q[j].push(a);
break;
}
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const double eps = 1e-9;
namespace point_output {
static char buf[8][30];
static int bufc = 0;
} // namespace point_output
struct pt {
double x, y;
pt() {}
pt(double xx, double yy) : x(xx), y(yy) {}
void read() {
double xx, yy;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long ppow(long long a, long long b, long long mod) {
long long ans = 0;
while (b) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
void ac() { ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
reverse(s.begin(), s.end());
vector<int> v;
int n = s.length();
for (int i = 0; s[i]; i++) {
if (s[i] == '1') v.push_back(i);
}
v.push_back(n);
int cnt = 0;
f... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const long long MOD = 1e9 + 7;
using namespace std;
long long n_bits(long long n) {
long long x = __builtin_popcount(n);
return x;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t = 1;
cin >> t;
while (t--) {
lo... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, out = 0, sum = 0;
cin >> n;
vector<long long> v(101, 0);
for (int i = 0; i < n; i++) {
int c;
cin >> c;
v[i] = c;
sum += c;
}
long long a, b;
cin >> a >> b;
int check = 0;
for (int i = 0; i < n; i++) {
check ... | 2 |
#include <bits/stdc++.h>
int main() {
int n, k;
std::scanf("%d%d", &n, &k);
k -= n / 2;
if (2 <= n && 0 < k) {
int h = (k + 1) * 2;
std::printf("%d %d", h / 2, h);
for (int i(2); i < n; ++i) std::printf(" %d", ++h);
std::puts("");
} else if (0 == k) {
for (int i(1); i <= n; ++i) {
if... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, q, A[N], D[N], Lz[N];
vector<int> base, B[N * 2];
inline void Xor(int i, int val) {
for (i++; i < N; i += i & -i) Lz[i] ^= val;
}
inline int GetAt(int i) {
int ret = 0;
for (i++; i; i -= i & -i) ret ^= Lz[i];
return ret;
}
inline void Me... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 998244353;
int n, m, a[200010];
long long tot;
int s, t, u;
map<pair<int, int>, int> q;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
tot += a[i];
}
scanf("%d", &m);
while... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x1, Y1, x2, Y2;
string a = "First", b = "Second";
int main() {
cin >> n >> m >> x1 >> Y1 >> x2 >> Y2;
if (abs(x1 - x2) >= 4 && abs(Y1 - Y2) >= 4)
cout << b << endl;
else if (abs(x1 - x2) > 4 || abs(Y1 - Y2) > 4)
cout << b << endl;
else if (abs(x1 -... | 12 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
const ll maxn =2e5+5;
const ll mod=998244353 ;
const ll base=317;
ll pos[maxn];
ll a[maxn];
ll gt[maxn];
ll gtv[maxn];
ll mu(ll a,l... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
static int r, sign;
static char c;
r = 0, c = getchar(), sign = 1;
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') sign = -1, c = getchar();
while (c >= '0' && c <= '9') r = r * 10 + (c - '0'), c = getchar();
return r ... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long temp = 0, r, s = 0, ans = 0, e, x, y, max1 = 0, m = 0, c = 0, t = 0,
i, n, k, c1 = 0, tot = 0, t1, b, k4 = 0, c2 = 0, j = 0, k1, k2 = 0,
k3 = 0;
char ch;
string s1, s2;
signed main() {
cin >> s1;
n = s1.length();
vector<long long> v2(1000... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
char c;
unordered_set<char> st[110];
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> c;
st[j].insert(c);
}
}
long long ans = 1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[200001];
int main() {
vector<int> v;
v.push_back(0);
double sum = 0;
int n, t, x, y;
cin >> n;
while (n--) {
cin >> t;
if (t == 1) {
cin >> x >> y;
sum += (double)x * y;
a[x - 1] += y;
}
if (t == 2) {
cin >> x;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m;
bool ok = false;
int l = 0;
cin >> m;
m = m + 1;
string n;
while (ok == false) {
n = to_string((long long)m);
for (int i = 0; i < n.length(); i++) {
for (int j = 0; j < n.length(); j++) {
if ((n[i] == n[j]) && (i != j)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e5 + 5;
int n;
long long t;
long long a[mxn], res;
vector<long long> v;
struct bit {
long long val[mxn];
inline void init() { memset(val, 0, sizeof(val)); }
inline void add(int x) {
for (int i = x + 1; i; i -= i & -i) ++val[i];
}
inline long l... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10000001;
int pri[N], p[N], sp[N], is[N], phi[N], fcs[N];
long long n, cnt0, cnt1, cnt2, cnt3, bad_p;
int main() {
int i, j, k;
scanf("%I64d", &n);
cnt1 = n * (n - 1) / 2;
for (i = 2; i <= n; i++) {
if (is[i] == 0) {
if (i * 2 > n) bad_p++;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c h, c n) {
return {h, n};
}
template <class c>
auto dud(c* r) -> decltype(cerr << *r);
template <class c>
char dud(...);
struct muu {
template <class c>
muu& opera... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1 << 10;
int n;
int bitcnt[MX * 10], mp[MX * 10];
int ass[MX * 10], acnt;
long long ret[MX];
int main() {
cin >> n;
for (int i = 1; i < (1 << 13); ++i) {
bitcnt[i] = 1 + bitcnt[i - (i & -i)];
if (bitcnt[i] == 6) ass[++acnt] = i;
}
for (int i =... | 20 |
#include <bits/stdc++.h>
int min(int a, int b) { return (a < b ? a : b); }
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
printf("%d", min(n - a, b + 1));
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int ans = n, L, R;
for (int i = 0; i < m; i++) {
scanf("%d %d", &L, &R);
L--;
ans = min(ans, R - L);
}
printf("%d\n", ans);
for (int i = 0; i < n; i++) printf("%d ", i % ans);
return 0;
}
| 9 |
#include <bits/stdc++.h>
const int nax = 1e5 + 5;
using namespace std;
vector<int> arr(10), prefix(10);
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int v;
cin >> v;
int mini = 1e5 + 10, mndx = -1;
for (int i = 1; i < 10; i++) {
cin >> arr[i];
if (mini >= arr[i]) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int odd[] = {0, 1, 0, 1, 2, 0};
int godd(int n) {
if (n <= 5) return odd[n];
if (n & 1) return 0;
return 1 + (godd(n >> 1) == 1);
}
int geven(int n) {
if (n <= 2) return n;
return (n & 1) ^ 1;
}
int main() {
scanf("%d%d", &n, &k);
int grundy = 0;
w... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<char> s;
char a[150];
cin >> a;
int len = strlen(a);
for (int i = 0; i < len; i++) {
s.insert(a[i]);
}
int length = s.size();
if (length % 2 == 0)
cout << "CHAT WITH HER!" << endl;
else
cout << "IGNORE HIM!" << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long t, sum[(200000 + 1000)], refun[(200000 + 1000)], fin, now;
int n, QAQ[(200000 + 1000)], QvQ[(200000 + 1000)];
int lowbit(int x) { return ((x) & (-(x))); }
void Update(int x) {
for (int i = x; i <= refun[0]; i += lowbit(i)) ++QvQ[i];
}
int Query(int x) {
int fi... | 10 |
#include <bits/stdc++.h>
using namespace std;
int J1[100005], J2[100005], n, d;
int findS(int t) {
int pos1 = 0, pos2 = 0, s1 = 0, s2 = 0;
while (pos1 < J1[n] || pos2 < J2[n]) {
int p1 = lower_bound(J1, J1 + n + 1, pos1 + t) - J1;
int p2 = lower_bound(J2, J2 + n + 1, pos2 + t) - J2;
if (p1 > n && p2 > n... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y, z;
};
point pt[11111], a, v, u;
int n;
double f, ans1, ans2, t1, t2;
const double inf = 1e9, eps = 1e-9;
int main() {
int i, j, s, p, q;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%lf%lf", &pt[i].x, &pt[i].y);
scanf("%lf%lf%lf%lf%l... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
const char *qr =
"111111101010101111100101001111111"
"100000100000000001010110001000001"
"101110100110110000011010001011101"
"101110101011001001111101001011101"
"101110101100011000111100101011101"
"100... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class node>
struct link_cut_tree {
bool connected(node* u, node* v) { return lca(u, v) != NULL; }
int depth(node* u) {
access(u);
return get_sz(u->ch[0]);
}
node* get_root(node* u) {
access(u);
while (u->ch[0]) u = u->ch[0], u->push();
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long m = 1e9 + 7;
long long prime[100005];
void sieve() {
prime[0] = 1;
prime[1] = 1;
for (int i = 2; i * i < 100005; i++) {
for (int j = i * 2; j < 100005; j += i) prime[j] = 1;
}
}
long long gcd(long long a, long long b) {
if (a == 0)
return b... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
int now;
bool v[3][110000];
int va[3][110000];
int x, y;
void cal(int ha, int xx, int yy) {
int tx = x == 1 ? 2 : 1;
if (v[tx][yy - 1]) va[xx][yy] += ha, va[tx][yy - 1] += ha, now += ha * 2;
if (v[tx][yy]) va[xx][yy] += ha, va[tx][yy] += ha, now += ha * 2;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
vector<long long> used;
map<long long, long long> mp;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
long long n = s.size();
long long q = 0;
for (long long i = 0; i < n; i++) {
q += (s[i] - '... | 12 |
#include <bits/stdc++.h>
using Azir = int;
namespace fastIO {
bool IOerror = 0;
inline char nc() {
static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
if (p1 == pend) {
p1 = buf;
pend = buf + fread(buf, 1, 100000, stdin);
if (pend == p1) {
IOerror = 1;
return -1;
}
}
r... | 10 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T, const T id>
class retroactive_CHT {
struct line {
T a, b;
line(T a_ = 0, T b_ = 0) : a(a_), b(b_) {}
T get(T x) const { return a * x + b; }
};
const int n;
const vector<T> pos;
vector<line> data;
vector<pai... | 17 |
#include <bits/stdc++.h>
using namespace std;
map<long long, int> exist;
map<pair<long long, int>, int> dp;
char s[100005];
long long calcHash(long long hash, int c, long long MOD) {
return ((hash << 5) % MOD + c) % MOD;
}
void Hash(char str[], long long MOD) {
long long hash = 1;
int Sz = strlen(str);
int c;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; ++i) cin >> s[i];
vector<int> use(26);
for (int i = 0; i < n; ++i) {
int cnt[26] = {};
for (char c : s[i]) {
cnt[c - 'a']++;
use[c - 'a'] = 1;
}
for (int j = 0;... | 12 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
int n;
cin >> n;
cin >> s;
int sum = 1;
char c = s[0];
for (int i = 1; i < n; i++) {
if (c != s[i]) {
sum++;
c = s[i];
}
}
cout << min(n, sum + 2) << endl;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long inf64 = 0x3f3f3f3f3f3f3f3fLL;
const long double pi = 3.14159265358979;
const long double eps = 1e-7;
struct up {
int start, end, h;
up() {}
up(int s, int e, int hh) : start(s), end(e), h(hh) {}
};
const int maxm = 100500;
up... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string s[22];
string t[22];
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < m; i++) cin >> t[i];
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int x;
cin >> x;
x--;
cout << s[x % n] << t[x... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e6 + 5;
int trie[maxn][2];
int a[maxn], n, tot;
long long l[35], r[35], cnt[maxn];
void insert(int n, int pos) {
int rt = 0;
for (int i = 30; i >= 0; i--) {
int tmp = (n >> i) & 1;
if (!trie[rt][tmp]) trie[rt][tmp] = ++tot;
if (tmp == 1)
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
struct node {
int a, b;
bool operator<(const node x) const {
if (a == x.a) return b < x.b;
return a < x.a;
}
} nd[maxn];
int n;
int main() {
scanf("%d", &... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if ((n == 1 && k != 0) || k == n)
cout << -1;
else {
if (k != n - 1 && (n - k - 1) % 2 == 0) {
cout << 1 << " ";
int i;
for (i = 2; i <= k + 1; i++) {
cout << i << " ";
}
for (int j ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, bs;
int arre[6][6];
cin >> n;
memset(arre, 0, sizeof arre);
for (int i = int(0); i < int(n); i++) {
cin >> a >> bs;
arre[a][bs] = 1;
arre[bs][a] = 1;
}
bool b = false;
for (int i = int(1); i < int(6); i++) {
for (int j ... | 5 |
#include <bits/stdc++.h>
int min(int x, int y) { return (x < y) ? x : y; }
int get_int() {
int t = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') {
t = t * 10 + ch - '0';
ch = getchar();
}
return t;
}
struct Edge {
int from, to, cap, flow;
Edg... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[200004];
int cs[200004][6];
int sz[200004];
long long int ans;
int n, k;
int to_add(int a, int b) {
int r = ((a - b) % k + k) % k;
if (r == 0)
return 0;
else
return k - r;
}
void dfs(int u, int p, int d) {
cs[u][d % k] = 1;
sz[u] = 1;
for (... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, cnt;
float ans;
int main() { cout << "INTERCAL"; }
| 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300050;
int n;
long long p, k;
long long A[maxn];
unordered_map<long long, int> mp;
int main() {
scanf("%d%lld%lld", &n, &p, &k);
for (int i = 0; i < n; i++) {
scanf("%lld", &A[i]);
long long x = A[i] * (A[i] % p * A[i] % p * A[i] % p - k + p) %... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 107;
struct node {
int val, id;
} a[maxn], b[maxn];
int ans[maxn];
struct T {
int s[6];
} tmp;
vector<T> rcd[6];
bool cmp(node& p, node& q) { return p.val > q.val; }
void Deal(int p) {
memset(tmp.s, 0, sizeof(tmp.s));
for (int i = 1; i <= p; i++) {
... | 10 |
#include <bits/stdc++.h>
int main() {
int n, c = 0, nc = 0, a;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
if (a % 2 == 0)
c++;
else
nc++;
}
if (nc < c)
printf("%d\n", nc);
else {
printf("%d\n", c + (nc - c) / 3);
}
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
string s;
cin >> s;
int count = 0;
if (s[0] == '?' || s[a - 1] == '?') {
count = 1;
}
for (int x = 0; x < a; x++) {
if (s[x] == '?') {
if (s[x + 1] == '?') {
count = 1;
} else if (s[x - 1] == s[x + 1]... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long next(long long a) {
for (int b = (0); b < (64); ++b) {
if (((a >> b) & 1LL) == 0) {
if (!b) {
a = a >> 1LL;
a |= 2LL * (a + 1LL);
break;
} else {
a |= (1LL << b);
a &= ~(1LL << (b - 1LL));
break;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
void solve() {
int n;
cin >> n;
if (n == 2)
cout << -1;
else {
cout << "14\n21\n";
for (int i = 2; i < n; i++) cout << string(i, '6') << '\n';
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
i... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.