solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> int main() { int x, y, z; x = y = z = 0; int many; scanf("%d", &many); getchar(); for (int i = 0; i < many; i++) { int tx, ty, tz; scanf("%d %d %d", &tx, &ty, &tz); x += tx; y += ty; z += tz; } if (x == 0 && y == 0 && z == 0) { printf("YES\n"); } else {...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, p; cin >> n >> p; string str; cin >> str; char a; int i = str.size() - 1; int fl; int len = str.size(); char val[4]; while (i >= 0) { a = str[i]; a++; while (a - 'a' < p) { fl = 0; if (i - 1 >= 0) { if ...
9
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long long dp[102][5002]; char ch[102]; int main() { int t; dp[0][0] = 1; for (int i = 1; i <= 100; ++i) { for (int j = i; j <= 26 * i; ++j) { long long ss = 0; for (int k = 1; k <= 26 && k <= j; ++k) ss += dp[i - 1][j - k]; ...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long n; cin >> n; cout << 0 << ' ' << 1 << endl; fflush(stdout); char s[2]; string c; cin >> c; if (c[0] == 'w') { s[0] = 'w'; s[1] = 'b'; } else { s[0] = 'b'; s[1] = 'w'; } if (n ==...
11
#include <bits/stdc++.h> using namespace std; const int N = 2511; const int mod = 1e9 + 7; vector<pair<int, pair<int, int> > > all; int n, a[N][N]; bitset<N> r[N], c[N]; int main() { clock_t start = clock(); scanf("%d\n", &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); bo...
16
#include <bits/stdc++.h> int main() { int n, t; std::cin >> n >> t; int dp[22][22][22][12]; for (int i = 0; i < 21; ++i) { for (int j = 0; j < 21; ++j) { for (int k = 0; k < 21; ++k) { for (int l = 0; l < 12; ++l) { dp[i][j][k][l] = 0; } } } } for (int l = 0; l ...
11
#include <bits/stdc++.h> using namespace std; int main() { vector<int> p(4); int a, b; while (scanf("%d %d %d %d %d %d", &p[0], &p[1], &p[2], &p[3], &a, &b) == 6) { int ans = 0; sort(p.begin(), p.end()); for (int i = a; i <= b; i++) { int count = 0; do { if ((((i % p[0]) % p[1]) % ...
3
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:36777216") template <class T> inline void RD(T &); template <class T> inline void OT(const T &); template <class T> inline T &_RD(T &x) { RD(x); return x; } inline int RD() { int x; return _RD(x); } inline void RF(double &x) { scanf("...
20
#include <bits/stdc++.h> using namespace std; const int N = 2010; const long long Mod = 998244353; long long n, m; long long dp[N][N * 2]; int h[N]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> h[i]; dp[0][n + 1] = 1; for (int i = 1; i <= n; i++) { if (h[i] == h[i % n + 1]) for (int...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; long long ai[100000], bi[100000]; map<long long, int> topAchievers; cin >> n; for (int i = 0; i < n; ++i) { cin >> ai[i] >> bi[i]; if (i < (n / 2)) { topAchievers.insert(pair<long long, int>(ai[i], 1)); topAchievers.insert(p...
5
#include <bits/stdc++.h> using namespace std; vector<int> g[13][13]; int n, m, xt, yt, zt, ans; bool u[111]; void dfs(int x, int y, int z) { if ((x >= 1) + (x <= xt) + (y >= 1) + (y <= yt) + (z >= 1) + (z <= zt) == 6) { if (g[z][x][y - 1] == 1) { g[z][x][y - 1] = 2; dfs(x + 1, y, z); dfs(x, y + ...
6
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; static inline int Rint() { struct X { int dig[256]; X() { for (int i = '0'; i <= '9'; ++i) dig[i] = 1; dig['-'] = 1; } }; static X fuck; int s = 1, v = 0, c; for (; !fuck.dig[c = getchar()];) ; if (c == '-'...
8
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7, MAX = 2e5 + 2; int n; long long sum, res; vector<pair<long long, long long>> v; int b_s(long long beg, long long end) { if (beg > end) return 0; long long mid = (beg + end) / 2, total = sum; int cnt = 0; vector<pair<long long, long lon...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; string a; cin >> n; cin >> a; vector<int> v; int s = 0; for (int i = 0; i < a.size(); i++) { v.push_back((int)a[i] - 48); s += (int)a[i] - 48; } int s2 = 0; if (s == 0...
5
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; const long long int inf = 1e9; const long long int MOD = 1e9 + 7; const long long int nax = 1000000 + 51; const long long int N = nax - 1; long long int n, fact[nax], po[nax], invfact[nax], lpf[nax]; long long int powe(long long int a, long l...
12
#include <bits/stdc++.h> using namespace std; int indx, cur; int main() { int nm, cnt = 0; scanf("%d", &nm); string ss; cin >> ss; vector<int> vec; for (int i = 1; i <= nm; ++i) { int x; scanf("%d", &x); vec.push_back(x); } while (indx >= 0 && indx < nm) { if (ss[indx] == '>') indx...
2
#include <bits/stdc++.h> using namespace std; const long long N = 1e4 + 0.000001; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0); long long n, m; cin >> n >> m; deque<pair<long long, string> > v[m]; for (long long i = 0; i < n; i++) { string name; long long team, score; ...
5
#include <bits/stdc++.h> using namespace std; int go[100100]; int p[100100]; int n; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; p[x] = i; } go[n] = 1; for (int i = n - 1; i >= 1; i--) if (p[i] < p[i + 1]) go[i] = go[i + 1] + 1; ...
8
#include <bits/stdc++.h> using namespace std; template <class P, class Q> inline void smin(P &a, Q b) { if (b < a) a = b; } template <class P, class Q> inline void smax(P &a, Q b) { if (a < b) a = b; } const int maxn = 100000 + 100; int n, l, x, y; int a[maxn]; set<int> s; int main() { ios_base::sync_with_stdio(f...
9
#include <bits/stdc++.h> using namespace std; long long all[100005]; bool can[100005] = {0}; char temp[20]; int main() { long long N, t, i, j, ok, how = 0; scanf("%lld", &N); for (i = 0; i < N; i++) { scanf("%s", temp); if (temp[0] == '-') ok = 1; else ok = 0; t = 0; for (j = ok; t...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; int n, m, k, cnt[MAXN], myCnt[MAXN], ansx, ansy, st, ed, p; int maxDis; void getAns(int n, int m, int x, int y) { memset(myCnt, 0, sizeof(myCnt)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { myCnt[abs(i - x) + abs(j...
15
#include <bits/stdc++.h> using namespace std; int n, b, c[5015], d[5015]; vector<int> g[5015]; int l = 0; int cnt = 0; struct node { int cnt = 0; vector<long long> f; vector<long long> g; vector<int> v; void resize(int len) { len++; f.resize(len, 1LL * 1e9 * 5005); g.resize(len, 1LL * 1e9 * 5005);...
16
#include <bits/stdc++.h> using namespace std; const int Mod = 1e6 + 3; const int N = 103; char s[N]; int getVal(char c) { switch (c) { case '>': return 8; case '<': return 9; case '+': return 10; case '-': return 11; case '.': return 12; case ',': return 13;...
4
#include <bits/stdc++.h> using namespace std; int adj[425][425]; bool vis[425]; int n, m; int bfs(int x) { queue<pair<int, int> > q; q.push(make_pair(1, 0)); while (!q.empty()) { auto temp = q.front(); q.pop(); int node = temp.first; int time = temp.second; if (node == n) { return time; ...
8
#include <bits/stdc++.h> using namespace std; int main() { pair<int, int> place[][4] = {{{1, 1}, {1, 2}, {1, 3}, {1, 4}}, {{3, 1}, {3, 3}, {4, 1}, {4, 3}}}; string s; cin >> s; int ind[2] = {0}; for (auto &c : s) { int v = (c - '0'); auto out = place[v][ind[v]]; ind[...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { string s; cin >> s; long long int c1 = count(s.begin(), s.end(), 'S'), c2 = count(s.begin(), s.end(), 'R'), c3 = count(s.begin(), s.end(), 'P'); string ans = ""; ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; int x; int y; vector<int> v; if (k > n) { cout << "NO" << "\n"; return 0; } for (int i = 0; i < n; i++) { if (s[i] == 'G') x = i; if (s[i] == 'T') y = i; if (s[i] == '...
0
#include <bits/stdc++.h> using namespace std; const double EPS = (1e-7); int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; } const int OO = (int)1e6; pair<long long, pair<long long, long long> > extendedEuclid(long long a, long lon...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = ...
8
#include <bits/stdc++.h> const long long INF = 1e18; const int32_t M = 1e9 + 7; const int32_t MM = 998244353; using namespace std; void solve() { long long int i, j, k; cin >> i >> j >> k; long long int mod = abs(i - j); long long int answer = ((mod - 1) * 2) + 2; if (max(i, j) > answer || k > answer) { c...
0
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1}; bool a[2010][2010]; int n; int kp; short x[4000010], y[4000010]; bool u[2010][2010]; int s[2010][2010]; void dfs(int cx, int cy) { x[kp] = cx; y[kp] = cy; u[cx][cy] = true; k...
12
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int bs(int l, int r, int a, double num) { int ans = INF; while (l <= r) { int mid = (l + r) >> 1; double x = num / (mid + 1); if (a >= (2 * mid + 1) * x && a <= (2 * mid + 2) * x) { ans = mid; l = mid + 1; } else { ...
9
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, ans = 0; cin >> a >> b; while (1) { if (!a) break; if (a < b) swap(a, b); ans += a / b; a %= b; } cout << ans << endl; }
3
#include <bits/stdc++.h> using namespace std; long long num[1100], c[10], x[10], n, a; int main() { cin >> n; num[1] = 15; num[2] = 10; num[3] = 6; c[1] = 3; c[2] = 2; c[3] = 2; for (int i = 1; i <= 3; i++) x[i] = c[i]; if (n == 2) { cout << -1; return 0; } for (long long i = 4; i <= n; i+...
9
#include <bits/stdc++.h> using namespace std; int dirx[4] = {0, 0, 1, -1}; int diry[4] = {1, -1, 0, 0}; int sum[300][300] = {0}; char data[300][300]; int base, r, c, level; inline bool isok(int x, int y) { if (x >= 1 && x <= r && y >= 1 && y <= c) return true; return false; } void BFS(int x, int y, int value) { q...
11
#include <bits/stdc++.h> long long C[65][65] = {{0}}; long long CheckTotal(long long n) { long long total = 0; while (n) { if (n & 1) total++; n = n >> 1; } return total; } long long Find(long long num, int k) { long long ans = 0; if (CheckTotal(num) == k) ans++; for (int i = 63; i >= 0 && k >= 0;...
13
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 1e6 + 7; long long n, f = 1, ans; long long a[N]; map<long long, long long, greater<long long> > M; long long fpow(long long a, long long b) { long long res = 1; for (long long i = 0; i < 30; ++i) { if (b & (1 << i)...
15
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, l, r, input; cin >> n >> m; vector<int> preprocess(n + 1), arr(n + 1); for (int i = 1; i <= n; ++i) cin >> arr[i]; preprocess[1] = 0; for (int i = 2; i <= n; ++i) { if (arr[i] == arr[i - 1])...
9
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; int dp[255][255][255]; char str[maxn]; int go[maxn][26]; int len[5]; char s[5][255]; int main() { int n, q; cin >> n >> q; cin >> str + 1; for (int j = n; j <= n + 1; j++) for (int i = 0; i < 26; i++) go[j][i] = n + 1; for (int i = n...
14
#include <bits/stdc++.h> using namespace std; int base(int base, int n) { int digit = 0; for (; n != 0;) { digit += n % base; n /= base; } return digit; } int gcd(int a, int b) { if (b == 0) return a; else gcd(b, a % b); } int main() { int n, digit = 0, d; cin >> n; for (int i = 2; i <...
2
#include <bits/stdc++.h> using namespace std; char str[500005], ch; int main() { int l, i, j, k, r; while (scanf("%d%d", &l, &k) != EOF) { scanf("%s", str); l = strlen(str); if (k == 2) { int ans1 = 0, ans2 = 0; for (i = 0; i < l; i++) if ((i % 2 == 0 && str[i] == 'A') || (i % 2 == 1...
8
#include <bits/stdc++.h> using namespace std; char d[2510][2510]; int n, m; char ch; int ans; int ret = 0x7fffffff; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) for (int o = 1; o <= m; o++) { cin >> d[i][o]; d[i][o] -= '0'; } for (int k = 2; k <= 10; ...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; constexpr auto MOD = 1000000007LL; constexpr auto LINF = (1LL << 60); constexpr auto INF = 2147483647LL; constexpr auto PI = 3.1415926535897932384626433; constexpr auto EPS = 1...
14
#include <bits/stdc++.h> const int inf = 1e9; using namespace std; const int N = 1e5 + 100; int a[N], sz = 1; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 2; i <= n; i++) { if (a[i] == 0) { a[i] = sz; sz++; for (int j = 2 * i; j <= n; j += i) { ...
5
#include <bits/stdc++.h> #define vi vector<int> #define vvi vector<vi> #define ll long long #define vll vector<ll> #define vvll vector<vll> #define ii pair<int, int> #define vii vector<ii> #define vvii vector<vii> #define fi first #define se second #define all(v) v.begin(), v.end() #define uni(v) v.erase(unique(v.begi...
19
#include <bits/stdc++.h> using namespace std; long long sumU[1000005], sumD[1000005]; vector<long long> up, down, dd; string S; int N; int main() { cin >> N >> S; for (int i = 0; i < N; i++) if (S[i] == 'U') up.push_back(i); else dd.push_back(i); for (int i = N - 1; i >= 0; i--) if (S[i] =...
16
#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; string s; cin >> s; int l = 0, r = 0; for (auto i : s) { if (i == '(') l++; else r++; } if (r != l) cout << "-1\n"; else { r = ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int i, j, k = 0, n, m, r = -1, c = -1, s = 0; cin >> n >> m; char a[n][m]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> a[i][j]; if (a[i][j] == 'B' && s ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; struct edge { int to, nxt, weight; } e[maxn * 2]; int n, sz[maxn], sum[maxn]; int dep[maxn], cnt; int head[maxn], tot; int parent[maxn], hson[maxn]; void init() { tot = 0; memset(head, -1, ...
15
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int i = 0; i < q; i++) { string s, t, p; cin >> s >> t >> p; int k = 0, j = 0; string ss = s; while (ss.length() != 0 && j < t.length()) { if (ss[k] == t[j]) ss.erase(k, 1); j++; } if (ss.lengt...
5
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1); struct Complex { double real, image; Complex(double _real = 0, double _image = 0) : real(_real), image(_image) {} Complex operator-() const { return Complex(-real, -image); } friend Complex operator+(const Complex &A, const Complex &B) { ...
24
#include <bits/stdc++.h> using namespace std; int n, a[100005], b[100005], c[100005]; bool cmp(int x, int y) { return x > y; } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); if (n <= 2) { puts("-1"); return 0; } for (int i = 1; i <= n; ++i) b[i] = c[i] = a[i]; sort(b ...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 50000; int a[maxn]; int main() { int n, t; cin >> n >> t; n--; t--; for (int i = 0; i < n; i++) cin >> a[i]; int k = 0; while (k < t) k = k + a[k]; if (k == t) cout << "YES" << endl; else cout << "NO" << endl; }
2
#include <bits/stdc++.h> using namespace std; int nxt[105], cnt[105]; int main() { int t1, t2; string s1, s2; cin >> t1 >> t2 >> s1 >> s2; for (int i = 0; i < s2.size(); i++) { int idx = i; for (int j = 0; j < s1.size(); j++) { if (s2[idx] == s1[j]) { idx++; if (idx == s2.size()) {...
12
#include <bits/stdc++.h> using namespace std; const int INF = (1LL << 30) - 1; const long long int LINF = (1LL << 62) - 1; const int NMAX = (int)1e5; const int MMAX = (int)1e5; struct Edge { int x, y, w, apm, i; bool operator<(const Edge &that) const { if (w == that.w) return apm > that.apm; return w < that...
9
#include <bits/stdc++.h> using namespace std; int n, i, ans; int a[200020]; int main() { cin >> n; for (i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); int fi = (n - 2) / 2; int se = (n - 2) - fi; if (se > fi) swap(fi, se); ans = 2000000000; for (int i = 1; i + se + 1 <= n; i++) ans = mi...
15
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int ans(int x) { if (x % 2) return -(x - (x / 2)); return (x / 2); } int q, l, r; int main() { scanf("%d", &q); for (int i = 1; i <= q; i++) { scanf("%d%d", &l, &r); printf("%d\n", ans(r) - ans(l - 1)); } }
1
#include <bits/stdc++.h> using namespace std; const int MAXV = 1e6 + 10; const int INF = 1e9; vector<int> adj[MAXV]; int V, E; int s, e, i, j; vector<int> v; bool vis[MAXV], inc[MAXV]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> V >> E; for (i = 0; i < E; i++) { cin >> s...
22
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i, a[n]; int p; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int s = 1, S = 0; p = a[0]; for (i = 1; i < n; i++) { if (a[i] == p) s++; else { p = a[i]; if (S < s) S = s; s = 1; }...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using iii = tuple<int, int, int>; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N, M, p; cin >> p >> N; vector<bool> A; for (int i = 0; i < N; i...
8
#include <bits/stdc++.h> using namespace std; int main() { int n{0}, k{0}; cin >> n >> k; vector<pair<int, int>> vec(n); for (int i = 0; i < n; i++) { cin >> vec[i].first; vec[i].second = i + 1; } int count = 0, j = 0, i; sort(vec.begin(), vec.end()); for (i = 0; i < n; i++) { if (k - vec[i]...
2
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; char arr[100005]; char mnArr[100005]; int len; int arrCount[100005]; long long h1[100005], h2[100005]; int ptr = -1; long long b1 = 39; long long acS[100005]; long long res1 = 0, res2 = 0; long long power(long long x, long long y) { if (!y) ret...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b; long long int sum_c = 0, sum_uc = 0; cin >> n >> m; int diff[n]; for (int i = 0; i < n; i++) { cin >> a >> b; diff[i] = a - b; sum_c += b; sum_uc += a; } if (sum_c > m) cout << "-1" << endl; else { sort(di...
3
#include <bits/stdc++.h> using namespace std; vector<int> edge[100010], redge[100010]; int f[100010], ans[100010], r[100010]; bool vis[100010]; int main() { int n, m; cin >> n >> m; for (__typeof(n) i = 0; i < (n); i++) scanf("%d", &f[i]); for (__typeof(m) i = 0; i < (m); i++) { int u, v; scanf("%d%d", ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t = 1; long long int n, m, k, i, j; string s; long long int count = 1, count1 = 1; vector<long long int> a, b; while (t--) { cin >> n; cin >> s; for (i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int* nums = new int[1000005]; int l = 0, r = n - 1; int i = 1; while (l < r) { nums[l] = nums[r] = i; i += 2; ++l; --r; } if (l == r) nums[l] = n; l = n, r = 2 * n - 2; i = 2; while (l < r) { nums[l] = ...
11
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, W, WL; long long t; cin >> t; while (t--) { cin >> n >> W; WL = (W & 1) ? (W / 2 + 1) : (W / 2); long long a; vector<pair<long long, long long>> v; for (long lo...
5
#include <bits/stdc++.h> using namespace std; const int oo = 1e9; const int MAXN = 1e5 + 100; int N; int A[MAXN]; int cont = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for (int i = 0; i <= N; i++) { cin >> A[i]; } bool ok = true; int pos = -1; for (int i = 0; ...
7
#include <bits/stdc++.h> using namespace std; int n; int arr[105]; int dp[105]; int pp[105]; int res = 0; int ri = -1; void gob(int p) { if (pp[p] >= 0) gob(pp[p]); printf("%d ", 2001 + p); } int main() { scanf("%d", &n); for (int i = 0; i < (int)(n); i++) { scanf("%d", &arr[i]); pp[i] = -1; } for (...
5
#include <bits/stdc++.h> using namespace std; string s; int n; const int maxn = 150; long long dp[maxn][2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; cin >> n; cin >> s; dp[0][0] = 1; dp[0][1] = 1; for (int i = 1; i < s.size(); i++) { if (i % 2 == 0) { d...
6
#include <bits/stdc++.h> using namespace std; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { c_p_c(); string s; cin >> s; int z = s.length(); for (long long i = 0; i < z; i++) { if (s[i] == 'H' or s[i] == 'Q' or s[i] == '9') { cout << "YES"; return 0...
1
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } void print(long long t) { cerr << t; } void print(int t) { cerr << t; } v...
3
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '{'; for (int i = (0), __i = (((int)(vec).size())); i < __i; i++) { os << vec[i]; if (i + 1 != ((int)(vec).size())) os << ','; } os << '}'; return os; } template <class T1, c...
21
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int can[128]; int main() { ios::sync_with_stdio(false); int n, ans = 0; cin >> n; for (char ch = 'a'; ch <= 'z'; ch++) can[ch] = 1; for (int k = 0; k < (n); k++) { char c; string str; cin >> c >> str; if (k == n - 1) break;...
8
#include <bits/stdc++.h> using namespace std; int n, t, k, d, ans; int main() { scanf("%d %d %d %d", &n, &t, &k, &d); ans = ((n + (k - 1)) / k) * t; if (ans > t + d) printf("YES"); else printf("NO"); return 0; }
3
#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; ...
19
#include <bits/stdc++.h> using namespace std; int main() { cout.flush(); int n, ar[10005] = {0}, i; map<int, int> mp; cin >> n; int j = 1, fst, scnd; for (i = 2; i <= n; i++) { cout << "?" << " " << j << " " << i << endl; cin >> fst; cout << "?" << " " << i << " " << j << endl;...
8
#include <bits/stdc++.h> constexpr int P = 998244353; int power(int a, int b) { int res = 1; for (; b > 0; b /= 2, a = 1ll * a * a % P) if (b % 2 == 1) res = 1ll * res * a % P; return res; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, k, c; std::cin >> n >> k >> c; s...
24
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; int sum = 0, add = 0; cin >> n; int i; sum = (n * (n + 1) / 2); int k = n / 2; if (n % 2 != 0) k++; if (n <= 2) cout << "No" << endl; else { cout << "Yes" << endl; ...
3
#include <bits/stdc++.h> const int maxn = 311111; using namespace std; pair<long long, long long> w[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t, i, j; cin >> t; while (t--) { long long n, cap; cin >> n >> cap; for (i = 0; i < n; i++) { long long wt; ...
5
#include<bits/stdc++.h> using namespace std; #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); #define ll long long #define ull unsigned long long #define pb push_back #define All(x) (x).begin(),(x).end() #define mp make_pair #define nl "\n" typedef pair<int,int>ii; typedef vector<int>vi; typedef vector<ii>v...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9+7; int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; } int mul(int a, int b) { return int(1LL * a * b % mod); } const int N = 1000006; int b[N]; void rprefix_function(const string &s, int n){ b[0] = -1; int i =...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; cin.get(); getline(cin, s); int z = 0, e = 0; for (size_t i = 0; i < n; i++) { if (s[i] == '0') z++; else e++; } if (z != e) { cout << 1 << endl; cout << s; } else { cout << 2 << end...
0
#include <bits/stdc++.h> using namespace std; const int N = 1010; long long read() { long long 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; ...
2
#include <bits/stdc++.h> using namespace std; long long ans, f[100005], tmp; int a[100005], n, m; struct cmp { bool operator()(int x, int y) { return a[x] > a[y]; } }; priority_queue<int, vector<int>, cmp> g; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), ans += a[i]; if (n...
12
#include <bits/stdc++.h> using namespace std; char str[211111]; int num[211111], dp[211111], ans[211111]; char f[] = "aeiouAEIOU"; struct st { int l, r, minr; } tree[211111 << 2]; int check(char c) { int i; for (i = 0; i <= 9; i++) if (c == f[i]) return 0; return 1; } void build(int l, int r, int index) { ...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); long long qwe = 1; cin >> qwe; while (qwe--) { long long n, f = 0; string s; cin >> n >> s; if (n % 2 == 0) { for (int i = 1; i < s.size(); i += 2) ...
1
#include <bits/stdc++.h> using namespace std; long long n, k, m, d; bool func(long long x) { if (m >= x) return true; long long a = n / k; if (n % k) ++a; for (long long i = min(a, d); i >= 1; i--) { long long t = i; long long y = n / (k * i - k + 1); y = min(y, m); if (y * i >= x) return true; ...
12
#include <bits/stdc++.h> using namespace std; const double EPS = (double)1e-7; const double PI = acos(0) * 2; bool isZero(const double& x) { return abs(x) <= EPS; } int sign(const double& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); } long long gcd(long long a, long long b) { for (; b; a %= b, swap(a, b)) { } re...
16
#include <bits/stdc++.h> using namespace std; int n, a, b, k, f; map<pair<string, string>, int> travel; bool cmp(pair<pair<string, string>, int> a, pair<pair<string, string>, int> b) { return a.second > b.second; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> a >> b >> k >> ...
10
#include <bits/stdc++.h> using namespace std; const int Maxn = 100 + 19; int A[Maxn * 2], n, _n, sum; int main() { scanf("%d", &_n); n = _n * 2 - 1; for (int i = 0; i < n; i++) scanf("%d", &A[i]); sort(A, A + n); if (_n % 2 == 0) { int x = 0; while (x + 1 < n) { if (-A[x] - A[x + 1] > 0) ...
10
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535897932384626433832795; const int inf = 1e9; const long long inf2 = 1e18; const int mod = 1e9 + 7; void boost() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const int maxn = 102; long long ncr[maxn][maxn]; int cnt[11]; vector<vector<...
11
#include <bits/stdc++.h> using namespace std; long long f[1000010]; long long n, tot1, tot2, i, j, ans; int main() { cin >> n; ans = 1; for (i = 1; i <= n; i++) { cin >> j; if (j == 1) tot1++; else tot2++; } for (i = 0; i < tot2; i++) ans = (ans * (n - i)) % 1000000007; f[0] = 1; f...
15
#include <bits/stdc++.h> using namespace std; char x[1000][1000]; int main() { int a, b = 2; x[1][1] = '+'; x[1][2] = '+'; x[2][1] = '+'; x[2][2] = '*'; cin >> a; if (a == 0) { cout << "+"; return 0; } while (a != 1) { for (int i = 1; i <= b; i++) for (int j = 1; j <= b; j++) { ...
10
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e4 + 5; const long long mod = 1e9; inline long long read() { long long 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 -...
15
#include <bits/stdc++.h> using namespace std; long long const N = 1e9 * 2; long long b, c, d, a[10001], k, q, m, n, p[1000000]; string second, s1, s2, t; char ch, ch1; bool us[100001]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } while (1) { k++; if (k >= N) break; } sort...
11
#include <bits/stdc++.h> using namespace std; void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); } template <class T1, class T2> inline void gmax(T1 &a, T2 b) { if (b > a) a = b; } template <class T1, class T2> inline void gmin(T1 &a, T2 b) { if (b < a) a = b; ...
15
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, N = 105; int n, m, k, cnt, fl[N], num[N], dp[N], dp2[N], s[N], t[N], f[N][N]; bool vis[N][N]; inline int dfs(int x, int k) { if (fl[x] == cnt) return dp2[x]; int res = -1; fl[x] = cnt; for (int y = 1; y <= n; ++y) if (f[x][y] == 1 && ...
18
#include <bits/stdc++.h> using namespace std; using u64 = uint64_t; void solve() { long long n, m; cin >> n >> m; vector<vector<int>> v(n, vector<int>(m)); vector<string> str(n); for (auto &x : str) cin >> x; vector<pair<int, int>> ans; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) v[i][j] =...
7