solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 20;
const long long mod = 1e9 + 7;
long long k, a[N];
long long powmod(long long x, long long n) {
long long s = 1;
while (n) {
if (n & 1) s = (s * x) % mod;
n >>= 1, x = (x * x) % mod;
}
return s;
}
int main() {
while (cin >> k) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n, a;
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
m[x].push_back(y);
m[y].push_back(x);
}
for (auto i : m)
if (i.second.siz... | 9 |
#include <bits/stdc++.h>
using namespace std;
void fst() {
ios::sync_with_stdio(0);
cin.tie(0);
}
int nxt() {
int x;
cin >> x;
return x;
}
int nex_l() {
long long x;
cin >> x;
return x;
}
int main() {
fst();
int tc;
cin >> tc;
while (tc--) {
int n = nxt(), m = nxt(), k = nxt();
if (n / k... | 2 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long int mod = 998244353;
const long long int big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U>
bool mineq(T& a, U b) {
if (a > b) {
... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10;
int vis[maxn][maxn];
string s;
map<string, int> m;
int p[maxn];
int score[maxn], got[maxn];
string name[10];
inline bool cmp(int i1, int i2) {
if (p[i1] != p[i2]) return p[i1] > p[i2];
int m1 = score[i1] - got[i1];
int m2 = score[i2] - got[i2];
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = (1e9) + 7;
const long long INF = (1e10) + 10;
struct edge {
int u, v, nxt;
long long cap, flow;
} e[2010];
struct Dic {
int head[410], en;
int q[410];
int dep[410], cur[410], sta[410];
void init() {
memset(head, -1, sizeof(head));
e... | 13 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:25600000")
using namespace std;
const double pi = acos(-1.0);
const int MAXN = 9 * 1024000;
bool pres[MAXN];
int a[MAXN];
int ans[MAXN];
int n;
int main() {
for (long long i = 0; i < MAXN; i++) ans[i] = -1;
cin >> n;
for (long long i = 0; i < n; i++) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
const int INF = 0x3f3f3f3f;
int n;
struct edge {
int ne, to;
} e[MAXN << 1];
int fir[MAXN], num = 0, d[MAXN];
inline void join(int a, int b) {
e[++num].ne = fir[a];
fir[a] = num;
e[num].to = b;
}
int f[MAXN][MAXN][2], siz[MAXN];
void pre(int u... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
double x = log(m) / log(n);
int jj = (int)(x + 1e-12);
if (abs(jj - x) < 1e-12)
cout << "YES"
<< "\n"
<< x - 1;
else
cout << "NO";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, s = 0;
int c[55], d[55][55];
int temp[2501][2] = {0}, v = 1;
int res[2501][4];
cin >> m;
for (int i = 0; i < m; ++i) {
cin >> c[i];
}
for (int i = 0; i < m; ++i) {
for (int j = 0; j < c[i]; ++j) {
cin >> d[i][j];
temp[... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
int T;
cin >> T;
while (T--) {
cin >> n >> k;
bool flag = 0;
long long p = 1, i;
if (n <= 2 && k == 3) {
puts("NO");
continue;
}
for (i = 0; i < n; i++) {
p = (1 << i);
p = p * p;
if (k... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
double iszero(double x) { return fabs(x) < 1e-4; }
double dist(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double gcd(double x, double y) {
if (iszero(y))
return x;
else
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int modP = 1e9 + 7;
const long long oo = 1000000000000000LL;
const int maxN = 999999;
long long g[maxN + 10];
int k, F[6];
void knapsack() {
fill(g, g + maxN + 10, -1);
g[0] = 0;
for (auto i = 0, d = 1; i < 6; ++i, d *= 10)
for (int p = 1, left = 3 * k; left... | 22 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000009, inf, DP[2][2][32][32][32], N, H;
int fix(int x) { return min(inf, x); }
int main() {
cin >> N >> H;
inf = H + 1;
DP[0][0][1][1][1] = 1;
for (int rem = 0; rem < N; rem++) {
for (int d1 = 0; d1 <= 1; d1++)
for (int d2 = 1; d2 <= inf; d2... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int a[N], b[N], top;
int T, n, G, v, ans[N];
map<int, int> mp;
pair<int, int> q[N];
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
void exgcd(int x, int y, int &a, int &b) {
if (!y) {
a = 1;
b = 0;
return;
}
exgcd(y, x % y, b... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 210;
pair<long long, long long> pt[MAXN];
long long a[MAXN];
long long g[MAXN][MAXN];
int main() {
int n;
cin >> n;
long long d;
cin >> d;
for (int i = 1; i < n - 1; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) cin >> pt[i].first >> pt[i].secon... | 13 |
#include <bits/stdc++.h>
using namespace std;
void myassert(bool expr) {
if (!expr) abort();
}
const int64_t posinf = 9223372036854775807LL;
const int64_t neginf = 9223372036854775808LL;
const int64_t bigprime = (1LL << 61) - 1LL;
const int64_t mult = 199;
const int64_t mult2 = 3571;
const int64_t mod = 1000000007LL;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
int n, m, i, j, k;
deque<char> a[N];
string s;
vector<pair<pair<int, int>, pair<int, int> > > ans, s1, s2;
inline void wk(vector<pair<pair<int, int>, pair<int, int> > >& v, bool fl) {
static int b[N], c[N];
memset(b, 0, sizeof b);
memset(c, 0, sizeo... | 16 |
#include <bits/stdc++.h>
using namespace std;
int tot, n, m, ll, rr, aa, w, rt[100005];
struct que {
int h, i;
} p[100005];
bool cmp(que a, que b) { return b.h < a.h; }
struct node {
int mx, l, r, ls, rs;
bool tag;
} t[3000005], ans;
void merge(node &a, node b, node c) {
a.tag = (b.tag && c.tag);
if (b.tag)
... | 17 |
#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
int n, a[MAXN];
int cnt[MAXN];
int c1[MAXN], c2, c3, k;
inline long long solve() {
long long res = 0;
int p = n >> 1;
while (a[p] == a[n - p + 1]) --p;
memset(c1, 0, sizeof(c1));
memset(c1, 0, sizeof(c1));
c2 = c3 = 0;
auto add1 = [&](int x, int d) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)3e5 + 100;
const int mod = (int)1e9 + 7;
int n, q, tot, d[maxn], ans[maxn];
vector<int> g[maxn];
void calcSz(int v) {
d[v] = 1;
for (int to : g[v]) {
calcSz(to);
d[v] += d[to];
}
}
set<pair<int, int> > second[maxn];
void dfs(int v) {
in... | 11 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
istream& operator>>(istream& in, __int128& a) {
int64_t b;
in >> b;
a = b;
return in;
}
ostream& operator<<(ostream& out, const __int128 a) {
unsigned __int128 b = a < 0 ? -a : a;
char buf[128];
char* c = end(buf);
do {
--c;
*c = "0123456789"[b % 10]... | 17 |
///****In the name of ALLAH, most Gracious, most Compassionate****//
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define ALL(a) a.begin(), a.end()
#define FastIO... | 15 |
#include <bits/stdc++.h>
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;
template <class F>
struct mat {
long long n;
vector<vector<F> > tab;
mat(long long n1) : n{n1}, tab(vector<vector<F> >(n, vector<F>(n, 0))) {
for (long long i = (long long)0; i <... | 11 |
#include <bits/stdc++.h>
long gcd(long x, long y);
int main() {
long x, y, l, p, q;
long a, b;
scanf("%ld%ld%ld%ld", &x, &y, &a, &b);
l = (x * y) / gcd(x, y);
p = a / l;
q = b / l;
if (a % l == 0) q++;
printf("%ld", q - p);
return (0);
}
long gcd(long x, long y) {
if (y > x)
return gcd(y, x);
... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
const int maxn = 200003, INF = 0x3f3f3f3f;
int n, m;
int bl[maxn];
struct Q {
int l, r, id, tim;
bool operator<(const Q& b) const {... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int a = 0, d = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'A') {
a++;
} else {
d++;
}
}
if (a > d) {
cout << "Anton" << endl;
} else if (a < d) {
cout << "Danik" << endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const long double eps = 1e-8;
struct Point {
long long x, y;
Point(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}
};
bool cmp1(const Point a, const Point b) {
return a.x == b.x ? a.y > b.y : a.x < b.x;
}
bool cmp2(const Point a, const Po... | 24 |
#include <bits/stdc++.h>
const int maxn = 210;
using namespace std;
int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = 0;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f ? x : -x;
}
struct point {
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, q, f, s;
int a[5005], l[5005], r[5005], qz[5005];
int main() {
cin >> n >> q;
int nn = 0;
for (int i = 0; i < q; ++i) {
cin >> l[i] >> r[i];
a[l[i]]++;
a[r[i] + 1]--;
}
for (int i = 1; i <= n; ++i) {
a[i] += a[i - 1];
if (a[i]) nn++;
}... | 9 |
#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 62;
constex... | 13 |
#include <bits/stdc++.h>
const int MOD = 1E9 + 7;
const long long N = 1e5 + 15;
const int maxn = 5e5 + 15;
const int letter = 130;
const int INF = 1e17;
const double pi = acos(-1.0);
const double eps = 1e-10;
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
if (a < b) a = b;
}
template <typename T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void upmax(T& a, T b) {
if (a < b) a = b;
}
template <class T>
inline void upmin(T& a, T b) {
if (a > b) a = b;
}
const int maxn = 10007;
const int maxm = 200007;
const int mod = 1000000007;
const long long inf = 1ll << 62;
const double eps = 1... | 21 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
set<string> s;
pair<string, string> p[305];
vector<int> v;
int dp[605][605];
bool cmp(int x, int y) { return x > y; }
int main() {
int n, a, b, k, f;
cin >> n >> a >> b >> k >> f;
for (int i = 1; i <= n; i++) {
cin >> p[i].first >> p[i].second;... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[100010];
int a[100010];
int main() {
int n, m;
cin >> n >> m;
long long ans = 0LL, res = 0LL;
for (int i = 1; i <= m; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; i++) {
if (i > 1 && a[i - 1] != a[i]) G[a[i]].push_back(a[i - 1]);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int arr[n + 1];
for (long long int i = 1; i < n + 1; i++) {
cin >> arr[i];
}
long long int a = arr[1];
long long int ai = 1;
long long ... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const double eps = 1e-9;
template <typename T>
typename enable_if<!is_integral<T>::value, void>::type read(T &x) {
cin >> x;
}
long long read() {
char c;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class _T>
_T GCD(const _T &a, const _T &b) {
return b ? GCD(b, a % b) : a;
}
const int N = 2e5 + 10;
int n;
int T[N];
bool vis[N];
vector<int> V, V2;
int main() {
ios_base::sync_with_stdio();
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (int i = 1; i <= ... | 7 |
#include <bits/stdc++.h>
using namespace std;
string Pangram(string input, int size_Input) {
if (size_Input >= 26) {
int Count[26] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for (int i = 0; i < size_Input; i++) {
if (isupper(input[i])) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
void fft(vector<complex<double>>& a) {
long long n = (long long)(a).size(), L = 31 - __builtin_clz(n);
static vector<complex<long double>> R(2, 1);
static vector<complex<double>> rt(2, 1);
for (static long long k = 2; k < n; k *= 2) {
R.resize(n);
rt.resize(... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
if (n == 1) {
cout << 0 << '\n';
return 0;
}
vector<int> primes;
vector<int> mark(1001);
for (int i = 2; i <= 1000; i++) {
if (mark[i] == 1) co... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, a, x, b, y;
bool solve() {
int count = 0;
while (a != x && b != y) {
count++;
if (a == n)
a = 1;
else
a++;
if (b == 1)
b = n;
else
b--;
if (a == b) return true;
}
return false;
}
int main() {
ios_base::sync_wi... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[10];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int k;
scanf("%d", &k);
int tot = 0;
for (int i = 1; i <= 7; ++i) {
scanf("%d", a + i);
tot += a[i];
}
int ans = 7 * k;
int btot = tot;
if (k <= tot) {
for ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, z, w, d, k, t, p, ans, r, l, a[1000100];
bool h[1000100];
set<long long> s[2];
int main() {
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> y;
if (a[y] >= a[x]) a[y]++;
if (y == x) {
if (a[z] < a[y]) p = 1;
} else {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> prime;
const int N = 1e6 + 5;
bool notp[2 * N];
int cnt[2 * N];
long long cnt2[2 * N];
int query(int ta[], int l, int r) {
int res = ta[r];
if (l - 1 >= 0) res -= ta[l - 1];
return res;
}
long long query(long long ta[], int l, int r) {
long long res = ta... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_L = 1e5;
char buf[MAX_L + 1], s1[MAX_L + 1], s2[MAX_L + 1], t1[MAX_L + 1], t2[MAX_L + 1];
int ds[10], ts[2][10];
void init() { scanf("%[^\n]%*c", buf); }
void prn(int key) {
const int L = strlen(buf);
for (int i = 0; i < 10; i++) {
ts[0][i] = ds[i];
... | 11 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n, i, j;
cin >> n;
long long a[n][2], b[n][2];
for (long long i = 0; i < n; i++)
for (long long j = 0; j < 2; j++) {
cin >> a[i][j];
b[i][j] = n - 1;
}
map<long long, long long> m;
for (long long i = 0; i < n; i++) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(int &a, int &b) { return a > b ? true : false; }
long long com(long long a, long long b) {
if (a % b == 0) return b;
return com(b, a % b);
}
int main() {
int n;
int a[100000 + 9];
while (1 == scanf("%d", &n)) {
long long sum = 0;
for (int i = 0; i... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, sum = 0, flag = 0, t, a[1000000], ans = 0;
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long double summ = 0.0;
cin >> n >> ans;
for (int i = 0; i < (1 << n); i++) {
cin >> a[i];
summ += a[i];... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long int ans = 0;
int n, l, dp[105][3105][5];
vector<pair<int, int> > boards;
long long int solve(int prevIndex, int currTotalLength, int isRotated);
int main() {
cin >> n >> l;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
boards.push_back(mak... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5 + 1000;
const int MAXT = MAXN * MAXN;
const long long MOD = 998244353LL;
int arr[MAXN][MAXN], N, M, sz;
pair<int, pair<int, int>> all[MAXT];
long long mul(long long a, long long b) { return (a * b) % MOD; }
void add(long long& a, long long b) {
a += b;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
int a[maxn];
int low[maxn], has[maxn];
int ans[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
low[i] = n - i;
has[i] = a[i] - low[i];
}
sort(has, has + n);
for (int i = 0; i ... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool arr[1000009] = {0};
void sieve() {
arr[0] = 1;
arr[1] = 1;
for (int i = 2; i < 1000009; i++) {
if (arr[i] == 0) {
for (int j = i * 2; j < 1000009; j += i) {
arr[j] = 1;
}
}
}
}
int main() {
int n, m, index = 1;
cin >> n >> m;
f... | 0 |
//CLOCKS_PER_SEC
using namespace std;
#include<bits/stdc++.h>
#define sqr(x) 1ll*(x)*(x)
//#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#de... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long* reverse(long long* b, int n) {
long long* b2 = new long long[n];
for (int i = 0; i < n; i++) b2[i] = b[n - 1 - i];
return b2;
}
void print(vector<char> v) {
cout << "SMALL" << endl << v.size() << endl;
char s[200000 + 1];
int n = v.size();
for (int ... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long int tt;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, k;
cin >> n >> k;
long long int l1, r1, l2, r2;
cin >> l1 >> r1 >> l2 >> r2;
if (l2 < l1... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int po(long long int n, long long int k) {
long long int ans = 1;
for (int i = 0; i < k; i++) ans *= n;
return ans;
}
int dp[1000006], prs[1000006];
int main() {
int n, k, t;
cin >> t;
while (t--) {
string s;
cin >> n >> k >> s;
int f = min... | 11 |
#include <bits/stdc++.h>
long long min(long long a, long long b) {
if (a < b) {
return (a);
} else {
return (b);
}
}
long long h[110000];
long long l[110000];
long long r[110000];
int main() {
long long a, b, c, d, M = 0, can;
scanf("%lld", &a);
for (b = 0; b < a; b++) {
scanf("%lld", &h[b]);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int MOD = 998244353;
int n, ans;
int c[N], p[N];
int dp[N][N], sm[N][N];
int dfs(int x, int y) {
int C = sm[x][y];
if (dp[x][y] != -1) return dp[x][y];
if (x == y) return dp[x][y] = 1;
if (x > y) return dp[x][y] = 0;
dp[x][y] = 0ll;
int ... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * f;
}
const int INF = 1e9;
int main() {
int T = read();
while (T--) {
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
string s;
cin >> m >> s;
n = s.size();
vector<int> vi(26, 0);
for (int i = 0; i < n; ++i) {
s[i] -= 'a';
++vi[s[i]];
}
for (int i = 0; i < 26; ++i) {
int tcnt = 0;
map<int, int> mp;
for (int j = 0; j < m; ++j) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string code;
cin >> code;
string table[10];
for (int i = 0; i < 10; i++) cin >> table[i];
for (int i = 0; i < 8; i++) {
char temp[11];
code.copy(temp, 10, i * 10);
temp[10] = 0;
for (int j = 0; j < 10; j++)
if (table[j] == (strin... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline long long add(long long a, long long b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
return a;
}
inline long long sub(long long a, long long b) {
a -= b;
if (a < 0) a += 1000000007;
return a;
}
inline long long mul(long long a, long long b) {
return ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int mx = 0;
int px, nx;
int x;
int l = 0, r = 0;
cin >> n;
cin >> x;
n--;
px = x;
r++;
while (n--) {
cin >> x;
if (x == px) {
r++;
} else {
px = x;
l = r;
r = 1;
}
if (r <= l && r > mx) mx... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
int n, ans = 0;
char c1, c2;
bool opp(char c1, char c2) {
return (c1 + c2 == 'R' + 'L' || c1 + c2 == 'D' + 'U');
}
int main() {
cin >> n >> s;
c1 = ' ', c2 = ' ';
for (int i = 0; i < n; i++) {
if (s[i] == c1 || s[i] == c2) continue;
if (c1 == ' ')
... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void Read(T &x) {
int f = 1;
char t = getchar();
while (t < '0' || t > '9') {
if (t == '-') f = -1;
t = getchar();
}
x = 0;
while (t >= '0' && t <= '9') {
x = x * 10 + t - '0';
t = getchar();
}
x *= f;
}
const int mo... | 18 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
return cout << "(" << p.first << ", " << p.second << ")";
}
template <typ... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
string ToString(T t) {
stringstream s;
s << t;
return s.str();
}
template <class T>
void ToOther(T& t, string a) {
stringstream s(a);
s >> t;
}
int d, n, m;
vector<pair<int, int> > v;
int main() {
cin >> d >> n >> m;
v.resize(m);
for (int ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long m, k;
cin >> n >> m >> k;
long long min = 999999;
for (int i = 1, y; i <= n; i++) {
scanf("%d", &y);
if (min >= y && i % 2 == 1) min = y;
}
if (n % 2 == 0)
cout << 0 << endl;
else if (m < n / 2 + 1)
cout << 0 << ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int k, lvl[100005], viss[100005], dpp[100005], dp[100005],
vis[100005], p[100005], en, st;
vector<long long int> adj[100005], vv;
void dfs(long long int n, long long int kkk) {
vis[n] = 1;
for (auto x : adj[n]) {
if (kkk == x) continue;
if (vis[x] ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long ans = 1, p, z = 0;
int n, pos[105], s = 0, i, t;
cin >> n;
for (i = 0; i < n; i++) {
cin >> t;
if (t == 1) {
pos[s] = i;
s++;
z++;
}
}
if (z == 0)
cout << "0\n";
else if (z == 1)
puts("1");
else {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int q, t, x, y;
int a[500000 + 5];
int f[710][710];
void init() {}
void Time_decreasing() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void enter() { scanf("%d\n", &q); }
void solve() {
while (q--) {
scanf("%d %d %d", &t, &x, &y);
if (t == 1) {... | 13 |
#include <bits/stdc++.h>
using namespace std;
int k;
char s[110];
bool was[30];
void init() {
scanf("%d", &k);
scanf(" %s ", s);
}
void solve() {
int len = strlen(s);
for (int i = 0; i < (len + 1) / 2; i++)
if (s[i] != '?' && s[len - i - 1] != '?' && s[i] != s[len - i - 1]) {
printf("IMPOSSIBLE");
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int arr[111];
int main() {
int n;
scanf("%d", &n);
arr[0] = 0;
for (int i = (1); i < (n + 1); ++i) scanf("%d", &arr[i]);
int ans = 0;
if (n % 2 == 0 || n == 1) {
printf("-1\n");
return 0;
}
for (int i = n; i >= 1; i -= 2) {
int tmp = max(arr[i], ... | 9 |
#include <bits/stdc++.h>
const int MAX = 1e5 + 5;
const int MAX_V = 1e3 + 5;
const long long INF = 4e18 + 5;
const double M = 4e18;
using namespace std;
const int MOD = 1e9 + 7;
const double eps = 0.000000001;
int n, m, k, q, idx;
int fa[MAX], who[MAX], in[MAX], out[MAX];
vector<int> edge[MAX];
void dfs(int x) {
in[x... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = (int)s.size();
if (n <= 3) {
cout << "YES\n" << s;
return 0;
}
int m[26] = {0};
for (int i = 0; i < n; i++) m[s[i] - 'a']++;
int u = 0;
for (int i = 1; i < 26; i++)
if (m[i] > m[u]) u = i;
bool p[1001]... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
long long sgn(double a) { return a < -eps ? -1 : a < eps ? 0 : 1; }
double dis(double x1, double x2, double y1, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
void solve(double a, double b, double c, double &x1, double ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int result = 6;
for (int i = 0; i < (1000 * 1000); ++i) {
string now;
int x = i;
int a = 0, b = 0;
for (int j = 0; j < (6); ++j) {
now += char(x % 10 + '0');
... | 8 |
#include <bits/stdc++.h>
using namespace std;
char board[55][55];
void copy(char a[55][55], int row, int col, char b[55][55]) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
a[i][j] = b[i][j];
}
}
}
void dfs(char a[55][55], int row, int col) {
if (a[row][col] != '#')
return;
... | 9 |
#include <bits/stdc++.h>
inline int in() {
int k = 0;
char ch = getchar();
bool p = 1;
while (ch < '-') ch = getchar();
if (ch == '-') ch = getchar(), p = 0;
while (ch > '-') k = k * 10 + ch - '0', ch = getchar();
return p ? k : -k;
}
const int N = 5e5 + 5;
std::vector<int> G[N << 1];
int tot, o[N];
char ... | 23 |
#include <bits/stdc++.h>
using namespace std;
char ch[4507][4507];
const int N = 4507;
bool prime[N];
int p[N], tot;
void init() {
for (int i = 2; i < N; i++) prime[i] = true;
for (int i = 2; i < N; i++) {
if (prime[i]) p[tot++] = i;
for (int j = 0; j < tot && i * p[j] < N; j++) {
prime[i * p[j]] = fa... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
void smin(long long &x, long long y) { x = min(x, y); }
void smax(long long &x, long long y) { x = max(x, y); }
const long long MAXN = 1e5 + 100;
long long n, m;
vector<long long> adj[MAXN];
vector<pair<long long, pair<long long, long long> > > r... | 15 |
#include <bits/stdc++.h>
using namespace std;
int i, i0, n, m;
char s[5005], t[5005];
bool chk(int x) {
for (int i = 1; i <= x; i++) t[n - x + i] = s[i];
for (int i = x + 1; i <= n; i++) t[i - x] = s[i];
bool f = 0;
for (int i = 1; i <= n; i++) {
if (s[i] != t[i]) f = 1;
}
if (!f) return 0;
for (int i... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long inff = 0x3f3f3f3f3f3f3f3f;
long long n, a[200008], mi = 1, x, y, z, m, ans;
struct as {
long long u, v, d;
} b[500008];
int fa[200008];
bool cmp(as a, as b) { return a.d < b.d; }
int fid(int x) {
int a = x, b;
while (fa[a] != a) a = fa[a];
while (x !... | 11 |
#include <bits/stdc++.h>
using namespace std;
int ar[100100];
int din[100100];
int ifpoeifoprfirofi[400100];
int jfdslkgjlkfdgjdl[400100];
int n;
void build_min(int v, int l, int r) {
if (l == r)
ifpoeifoprfirofi[v] = l;
else {
int m = (l + r) / 2;
build_min((v << 1), l, m);
build_min((v << 1) + 1, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
void Emsawy() {}
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
long long suf(long long x) { return (x * (x + 1)) / 2; }
vector<vector<pair<int, int> > > adj;
const long long mod = 1e9 + 7, oo = 1e9;
int n, m, v[109], dis, vs[109];
int go(int id, ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, p, x = 1, y = 2;
cin >> n >> p;
for (int i = 1; i <= 2 * n + p; i++) {
if (y == n) {
cout << x << " " << y << endl;
x++;
y = x + 1;
} else {
cout << x << " " << ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << int64_t(n - 2) * (n - 2) << "\n";
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
struct block {
int bl, br;
vector<int> a;
long long have[11][11];
bool colored;
int color;
void addLetter(char x) {
if (!a.empty()) {
have[a.back()][x - 'a']++;
}
a.push_back(x - 'a');
}
int size() { return a.size(); }
void recalc() {
... | 17 |
#define _CRT_SECURE_NO_WARNINGS
#define first ff
#define second ss
#define make_pair mp
#define push_back pb
#define pop_back pop
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <cmath>
#include <utility>
#include <iomanip>
#i... | 0 |
#include <bits/stdc++.h>
struct Move {
int car_id, x, y;
Move() {}
Move(int _car_id, int _x, int _y) : car_id(_car_id), x(_x), y(_y) {}
};
int main() {
int n, k;
std::cin >> n >> k;
int rem_cars = 0;
std::vector<std::vector<int>> lot(4, std::vector<int>(n));
for (int i = 0; i < 4; i++) {
for (int j ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
template <typename T>
inline void in(T &x) {
register char ch;
x = 0;
while (isspace(ch = getchar()))
;
do x = x * 10 + ch - '0';
while (isdigit(ch = getchar()));
}
const int PS = 300, PL = 305, N = 400000 * 4 + 5;
bool np[PL]... | 16 |
#include <bits/stdc++.h>
using namespace std;
double dist(double x, double y, double x1, double y1) {
double t = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
return t;
}
int main() {
double n, k, x, y, x1, y1;
cin >> n >> k;
cin >> x >> y;
double s = 0;
for (int i = 1; i < n; i++) {
cin >> x1 >> y... | 1 |
#include <bits/stdc++.h>
using namespace std;
int N, K;
string S;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> K >> S;
if (count(S.begin(), S.end(), 'B') == N ||
count(S.begin(), S.end(), 'W') == N) {
cout << S << '\n';
return 0;
}
bool all_different = true;
for (i... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, st, de = 0;
vector<int> ve[100005];
void dfs(int now, int fa, int dep) {
if (dep > de) {
de = dep;
st = now;
}
int len = ve[now].size();
for (int i = 0; i < len; i++) {
int to = ve[now][i];
if (to != fa) dfs(to, now, dep + 1);
}
}
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
map<char, int> counts;
vector<list<char> > palindromes;
string s;
int numberOfOdds = 0;
void print() {
for (int i = 0; i < palindromes.size(); ++i) {
for (auto& currentChar : palindromes[i]) {
cout << currentChar;
}
cout << " ";
}
}
void fit(int groups... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const double PI = acos(-1.0);
const int maxn = 1e6 + 10;
const int N = 120 + 5;
const long long inf = 0x3f3f3f3f;
const int dir[][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0},
{1, 1}, {1, -1}, {-1, 1}, {-1, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int sf(pair<char, int> a, pair<char, int> b) {
return a.second < b.second ? 1 : 0;
}
int main() {
char in[100010];
int k;
int dist = 0;
vector<pair<char, int> > alpha(30);
int i = 0;
for (int i = 0; i < 30; i++) {
alpha[i].first = 'a' + i;
alpha[i].sec... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.