solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int i, i0, n, m, ans, p; int main() { scanf("%d %d", &n, &p); for (int i = 0; i <= 1000000; i++) { int m = n - i * p; if (m < 0) break; if (__builtin_popcount(m) <= i && m >= i && __builtin_popcount(m)) { printf("%d\n", i); return 0; } } ...
4
#include <bits/stdc++.h> using namespace std; int n, q; int Ans; string s; int Cost(char Bla1, char Bla2) { int Blaa = Bla1 - 'a'; int Blla = Bla2 - 'a'; int Cost1 = max(Blaa, Blla) - min(Blaa, Blla); int Cost2 = (min(Blaa, Blla) + 1) + (25 - max(Blaa, Blla)); return min(Cost1, Cost2); } int Get(int X) { in...
4
#include <bits/stdc++.h> using namespace std; long long pow(long long a, long long b, long long c) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % c; a = (a * a) % c; b >>= 1; } return ans; } long long modInv(long long p) { return pow(p, 1000000007 - 2, 1000000007); } long long F[10000...
6
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; unsigned long long int bigMod(unsigned long long int b, unsigned long long int p, unsigned long long int m) { b = b % m; if (p == 0) return 1; else if (p % 2 == 0) return...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int N = 100005; const double PI = 4 * atan(1); const long long MAX = 9223372036854775807; int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n + 1); for (int i = 0; i < n; i++) cin >> v[i]; v[n] = 1; int ans = 0; for (int i = 0; i <= n; i++) { int cnt = 0; for (int j = 0; j < i; j++) { cnt += v[j]; } for (int j = i; j <= n; j++) { ...
3
#include <bits/stdc++.h> int main() { int n, i, gr = 0; scanf("%d", &n); int a[n]; for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n; i++) { if (a[i] == a[i + 1]) continue; else gr = gr + 1; } printf("%d", gr); return 0; }
0
#include <bits/stdc++.h> using namespace std; inline int read() { int k = 1, re = 0; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') k = -1; ch = getchar(); } while (ch <= '9' && ch >= '0') { re = re * 10 + ch - 48; ch = getchar(); } return re * k; } inline void write(in...
8
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int q; cin >> q; while (q--) { long long l, r, d; cin >> l >> r >> d; if (d < l || d > r) cout << d << endl; else { long long t = r / d; cout << (t + 1) * d << endl; } } return ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int t = 1; while (t--) { long long int n, sum = 0, ct = 0, l, r, m, k, ans = 0; cin >> n >> m; long long int a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } long long int b[m]; for ...
3
#include <bits/stdc++.h> using namespace std; int N; int a[60][60]; set<int> S; int main() { cin >> N; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) scanf("%d", &a[i][j]); bool was = 0; for (int i = 0; i < N; i++) { S.clear(); for (int j = 0; j < N; j++) S.insert(a[i][j]); if ((int)S.s...
1
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; int dp[105][105][12]; struct DP { int col, d; } path[105][105][12]; char str[105]; int maze[105][105]; char road[105 * 2], cnt; int main() { int n, m, k; while (scanf("%d %d %d", &n, &m, &k) != EOF) { k++; for (int i = 1; i <= n; i++...
5
#include <bits/stdc++.h> using namespace std; const long long MXN = 510, Inf = 1e18; int n, m; struct Matrix { int r, c; bitset<MXN> row[MXN], col[MXN]; bool identity; Matrix() { identity = 1; } Matrix(int a, int b, bool iden = 1) { identity = iden; r = a, c = b; } void set(int i, int j, int k) { ...
8
#include <bits/stdc++.h> const long double PI = 3.141592653589793238L; const long long N = 2000005; using namespace std; long long ans[1 << 20], tmp[1 << 20]; pair<pair<long long, long long>, long long> a[101]; long long n, m, b; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long...
5
#include <bits/stdc++.h> using namespace std; long long n, dp[501][501] = {{0}}; string s; signed main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> s; for (long long l = 0; l < n; l++) { for (long long i = 0; i < n - l; i++) { long long j = i + l; if (l == 0) { ...
6
#include <bits/stdc++.h> using namespace std; const long double EPS = (long double)1e-7; const long double PI = acos(0) * 2; bool isZero(const long double& x) { return abs(x) <= EPS; } int sign(const long double& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); } long long gcd(long long a, long long b) { for (; b; a %= ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, ans; scanf("%d", &n); ans = n; int arr[n]; for (int i = (0); i < (n); ++i) scanf("%d", &arr[i]); sort(arr, arr + n); int st = 0, end = n / 2; while (st < n / 2 && end < n) { if (2 * arr[st] <= arr[end]) { ans--; end++; ...
4
#include <bits/stdc++.h> int main() { int i, j, n; scanf("%d", &n); for (i = (n / 2); i >= 0; i--) { for (j = 1; j <= n; j++) { if (j > i && j < n - i + 1) { printf("D"); } else { printf("*"); } } printf("\n"); } for (i = 1; i <= (n / 2); i++) { for (j = 1; j ...
0
#include <bits/stdc++.h> using namespace std; int a[200001], val[200001], ans = 0, T = 1; int roun[200001], c[200001]; stack<int> s; void DFS(int v, int rou) { roun[v] = rou; val[v] = T++; s.push(v); if (val[a[v]] == 0) { DFS(a[v], rou); } else if (roun[rou] == roun[a[v]]) { int x = 1e9; while (tr...
4
#include <bits/stdc++.h> std::set<std::pair<int, int> > adj; int a[100005]; int main() { srand(time(0)); int n, m; int aprox; scanf("%d %d", &n, &m); for (int i = 0; i < m; ++i) { int u, v; scanf("%d %d", &u, &v); adj.insert(std::make_pair(u, v)); adj.insert(std::make_pair(v, u)); } for (i...
8
#include <bits/stdc++.h> long long a, b = 1; bool check(int x) { if (x < 0) x = -x; while (x) { if (x % 10 == 8) return true; x /= 10; } return false; } int main() { scanf("%lld", &a); while (!check(a + b)) ++b; printf("%lld\n", b); return 0; }
1
#include <bits/stdc++.h> int main() { int k; scanf("%d", &k); char c; scanf("%c", &c); char string[1001]; gets(string); int letter[26]; int m = 0; for (int i = 0; i < 26; i++) { letter[i] = 0; } int a = strlen(string); for (int i = 0; i < a; i++) { letter[string[i] - 97]++; } for (in...
1
#include <bits/stdc++.h> using namespace std; const int inft = 1000000009; const int MAXN = 1000006; int ile[MAXN], t[MAXN], tt[MAXN]; int n; int get(int pocz, int kon) { multiset<int> S; for (int i = pocz; i <= kon; i++) S.insert(t[i]); int ans = 0, med = -1; vector<int> V; for (typeof((S).begin()) it = (S)....
8
#include <bits/stdc++.h> using namespace std; const long long NR = 210000; long long n, a[NR], b[NR], c[NR], dp[NR], p[NR], w[NR]; vector<long long> v[NR]; void dfs(long long rt, long long u, long long s) { long long l = 0, r = u, mid; while ((r - l) > 1) { mid = (l + r) >> 1; if (b[mid] >= s - a[rt]) { ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, a[N], b[N]; long long ans = 0; void dfs(int x, int w) { if (!ans) return; if (0 <= a[x + 1] + w && a[x + 1] + w <= 9) { printf("%d %d\n", x, w); a[x] += w; a[x + 1] += w; ans--; return; } dfs(x + 1, -w); if (!ans)...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k, sum = 0; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> k; if (i == j) { sum += k; } else if (j == (int)(n + 1) / 2) { sum += k; } else if (i == n - j + 1) { sum...
0
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } long long flag = 0; for (long long i = 1; i < n; i++) { if (abs(a[i] - a[i - 1]) == ...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int tdata = a * c; int down = b; int ttime = c; int extra = tdata / b; int newt = extra - c; int newt1 = tdata - newt * b; if (newt1 % b == 0) { cout << newt; } else { cout << newt + 1; } }
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 5 * 100010; set<long long int> s; set<long long int>::iterator itlow, itup; long long int data[4 * MAXN], ind[4 * MAXN], a[MAXN]; const long long int INF = 10000000000000; void build(int s = 0, int e = 5e5 + 1, int id = 1) { if (e - s < 2) { data[id] ...
8
#include <bits/stdc++.h> using namespace std; int n, p[666], f[666][666]; char c; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> c, f[i][j] = c - 48; for (int k = 1; k <...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e3; int x[MAXN + 1], y[MAXN + 1]; inline long long ccw(int i, int j) { return 1LL * x[i] * y[j] - 1LL * x[j] * y[i]; } inline long long get(int t, int i, int j, int k) { if (t == 1) { return llabs(ccw(i, j) + ccw(j, k) + ccw(k, i)); } else {...
7
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define int long long int #define rep(i, a, b) for (int i = a; i < b; i++) #define revrep(i, a, b) for (int i = a; i >= b; i--) #define pb push_back #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define min3(a, b, c) min(a, mi...
1
#include <bits/stdc++.h> using namespace std; template <class T> using vec = std::vector<T>; bool __hack = std::ios::sync_with_stdio(false); auto __hack1 = cin.tie(nullptr); namespace template_util { constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; } template <int N> struct bytetype {}; templ...
5
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; const int inf = 0x7FFFFFFF; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template <class T> inline T sqr(T x) { ...
3
#include <bits/stdc++.h> using namespace std; const int N = 3010; const int mod = 998244353; inline void add(int &a, int b) { a += b; if (a >= mod) a -= mod; } int n, m, dp[2][N][2]; char s[N], t[N]; int main() { scanf("%s", s); scanf("%s", t); n = strlen(s); m = strlen(t); reverse(s, s + n); memset(dp,...
7
#include <bits/stdc++.h> using namespace std; const int MAXA = 1000100, INF = 0x3f3f3f3f; int n, ans = INF, lvl[MAXA], p[MAXA]; vector<int> g[MAXA]; void bfs(int v) { memset(lvl, INF, sizeof lvl); queue<int> q; lvl[v] = 0; q.push(v); while (!q.empty()) { v = q.front(), q.pop(); for (const int &u : g[v...
9
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { bool b = 0; char c; while (!isdigit(c = getchar()) && c != '-') ; if (c == '-') c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - 48; if (b) x = -x; } template <typ...
5
#include <bits/stdc++.h> using namespace std; multiset<pair<long long, long long> > s; vector<pair<long long, long long> > v; int32_t main() { long long n, x, y; cin >> n >> x >> y; for (long long i = 0; i < n; i++) { long long a, b; cin >> a >> b; v.push_back({a, b}); } sort(v.begin(), v.end()); ...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e6 + 5; int mod = 998244353; const double PI = acos(-1); int n, k; int d[14]; const int MOD = 998244353; long long w[2][3000005]; inline long long qp(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % MOD; a =...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; long long a[maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long sum = 1e18; for (long long i = 1; i; i++) { long long res = 1; ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int x = n / 2 / (k + 1); cout << x << " " << k * x << " " << n - x - k * x; }
0
#include <bits/stdc++.h> using namespace std; int a[10010], b[10010] = {0}; int main() { int n, ans = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < n; i++) { if (!b[a[i]] && a[i] <= n) { b[a[i]] = 1; } else if (b[a[i]] || a[i] > n) { ans++;...
1
#include <bits/stdc++.h> int main() { int a; while (~scanf("%d", &a)) { int b[60] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = (int)5e4 + 10; const int mod = (int)1e9 + 7; const long long inf = 1e18; vector<bool> sieve(long long N) { vector<bool> prime(N + 1, 1); prime[0] = prime[1] = 0; for (int i = 2; i * i <= N; i++) { if (prime[i]) { for (int j = i * i; j <= N; ...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); } template <class num> inline void rd(num& x) { char c; ...
8
#include <bits/stdc++.h> using namespace std; using Key = int; using ll = long long; const int mxn = 100006; const int mxv = mxn; struct Val { ll l, r; ll c, S, L, R; Val operator+(Val b) { if (!c) return b; if (!b.c) return *this; return {l, b.r, c + b.c, S + b.S +...
8
#include <bits/stdc++.h> using namespace std; int rd() { char c = getchar(); int t = 0, f = 1; while (!isdigit(c)) f = (c == '-') ? -1 : 1, c = getchar(); while (isdigit(c)) t = t * 10 + c - 48, c = getchar(); return t * f; } void wt(int x) { if (x < 0) putchar('-'), wt(-x); else { if (x > 9) wt(x...
8
#include <bits/stdc++.h> using namespace std; const int MN = 5e5 + 100; int pa[MN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); list<int> lt; int n, m, p; cin >> n >> m >> p; string s; cin >> s; vector<int> v; for (int i = 0; i < n; ++i) { if (s[i] == '(') v.push_back(i); else...
4
#include <bits/stdc++.h> using namespace std; int dp[300010][2], x[300010][2]; int pa, pb, a, b; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> x[i][0]; for (int i = 1; i <= n; i++) cin >> x[i][1]; memset(dp, 0x3f, sizeof...
8
#include <bits/stdc++.h> int n, tl, a[1000005], x[1000005]; std::stack<int> stk; char opt[1000005][5]; void NO() { puts("NO"); exit(0); } int main() { scanf("%d", &n); for (int i = 1; i <= 2 * n; ++i) { scanf("%s", opt[i] + 1); if (opt[i][1] == '+') stk.push(++tl); else { scanf("%d", &x[...
4
#include <bits/stdc++.h> using namespace std; struct E { long long x; int y, z; E() {} E(long long _, int __, int ___) : x(_), y(__), z(___) {} bool operator<(const E &a) const { return x == a.x ? y < a.y : x < a.x; } E operator+(const long long &a) const { return E(x + a, y, z); } void operator+=(const l...
11
#include <bits/stdc++.h> using namespace std; const int N = 500 * 1000 + 20; int n, m, ver_3k, root, par[N], h[N], d[N], cnt; set<int> st, pap1, pap2; bool vis[N], ok, seen, no; vector<int> gr[N]; void find_3k_ver() { for (int i = 1; i <= n; i++) if (d[i] % 3 == 0) if (st.empty()) st.insert(i); } void dfs_f...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int p, n, j, i, k = 0, t = 0, l, h, mid, u = 0, v = 0, cnt[26] = {0}, T, f = 0, q, r, x, y, a, b, c, d; cin >> a >> b >> c >> d; x = max((3 * a) / 10, a - ((a / 250...
0
#include <bits/stdc++.h> using namespace std; const int oo = 1e9 + 7; const int maxn = 2e3 + 7; int n, k, a[maxn], f[maxn]; long long l, r; inline void read(int &x); void nhap() { read(n); read(k); for (int i = (1), _b = (n); i <= _b; ++i) { read(a[i]); } } bool check(long long x) { int res = n; for (in...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e6; struct mem { long long a, b, c; }; vector<mem> ans, ans1; long long a[N], b[N], p[N], p1[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n, ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } sort(a,...
5
#include <bits/stdc++.h> using namespace std; const int mo = 1000000007; int x, k, X, Y, n, m, u[100005]; long long ans[2]; int f[2], g[2][2][2], G[2][2][2], vis[100005]; vector<int> a[100005], A[100005], e[100005], w[100005]; void dfs(int x) { if (vis[x]) return; vis[x] = 1; memset(G, 0, sizeof G); int j = a[x...
10
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& out, vector<T> v) { out << v.size() << '\n'; for (auto e : v) out << e << ' '; return out; } template <class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.first << ' ' << p.se...
12
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-10; const int inf = 2000000000; const int MOD = 1000000007; int MOD1 = 1000000007; int MOD2 = 1000000009; inline bool checkBit(long long int n, long long int i) { return n & (1LL << i); } inline long long int setBit(long l...
6
#include <bits/stdc++.h> using namespace std; int pw(int a, int b, int mod) { int r = 1; while (b) { if (b & 1) { r = (long long)r * a % mod; } a = (long long)a * a % mod; b /= 2; } return r; } int dv(int a, int b, int mod) { return (long long)a * pw(b, mod - 2, mod) % mod; } const int C...
10
#include <bits/stdc++.h> using namespace std; long long n, x, m, q, k; long long mulmod(long long a, long long b) { long long ret = 0; while (b) { if (b & 1) ret = (ret + a) % 1000000009; a = (a << 1) % 1000000009; b >>= 1; } return ret; } long long fastPow(long long x, long long n) { long long re...
5
#include <bits/stdc++.h> using namespace std; set<int> st[100005]; priority_queue<pair<int, int> > q; vector<pair<int, int> > v[100005]; long long dist[100005]; int n, m; int main() { cin >> n >> m; for (int i = 0; i < 100005; i++) { dist[i] = 1e11; } dist[1] = 0; for (int i = 0; i < m; i++) { int a, ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, d; int a[N]; int main() { scanf("%d%d", &n, &d); long long sm = 0; for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); sm += a[i]; if (a[i] == 0 && sm < 0) sm = 0; if (sm > d) { cout << -1; return 0; } } ...
5
#include <bits/stdc++.h> using namespace std; int main() { int tt; cin >> tt; while (tt--) { int n; cin >> n; string s(n, '?'); auto Ask = [&](string t) { cout << "? " << t << endl; int foo; cin >> foo; for (int i = 0; i < foo; i++) { int bar; cin >> bar; ...
13
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; vector<int> readVec(int n) { vector<int> result; result.resize(static_cast<std::size_t>(n)); for (int i = 0; i < n; i++) { int a; cin >> a; result[i] = a; } return result; } void solve() { int n; cin >> n; int b = sqrt(n)...
3
#include <bits/stdc++.h> using namespace std; const int S = 2001; const int P = 1073741824; int Gcd[S][S], flag[S], prime[S], mul[S]; int ans, A, B, C, i, j, a, d, t, cnt; int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } int F(int n, int g) { int ret = 0; for (int i = 1; i <= n; i++) if (Gcd[i][g] == 1)...
9
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; } template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; } inline int nxt() { int wow; scanf("%d", &wow); return wow; } inline long long int lxt() { ...
0
#include <bits/stdc++.h> using namespace std; int a[10006]; int main() { int i, j, k, m, n, t; scanf("%d", &t); while (t--) { scanf("%d", &n); int sum = 0; for (i = 1; i <= n; i++) { scanf("%d", &a[i]); sum += a[i]; } if (sum % n != 0) { printf("-1\n"); continue; } ...
6
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e6 + 6; const long long MOD = 1e9 + 7; bool comparator(long long i, long long j) { return (i < j); } long long power(long long x, long long i) { long long ans = 1; while (i > 0) { if (i & 1) ans = (ans * x) % MOD; i >>= 1; x = (x * x)...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { string a; cin >> a; int n = a.size(), ans = 0, pos[n]; for (int i = 0; i < n - 2; i++) { if (a[i] == 't' && a[i + 1] == 'w' && a[i + 2] =...
3
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-8; static const double PI = 4.0 * atan(1.0); bool ISINT(double x) { return fabs(x - (int)round(x)) < EPS; } bool ISEQ(double x, double y) { return fabs(x - y) < EPS; } string itos(long long x) { stringstream ss; ss << x; return ss.str(); }...
4
#include<bits/stdc++.h> using namespace std; #define ll long long int #define MAX 1000001 int main() { int t; cin>>t; while(t--) { int n; cin>>n; ll ans=0; int a[n]; for(int i=0;i<n;i++) { ...
0
#include <bits/stdc++.h> using namespace std; priority_queue<long long> q1; priority_queue<long long> q2; long long x, ans1, ans2; int main() { int a; cin >> a; q1.push(0); q2.push(0); q1.push(0); q2.push(0); for (int i = 0; i < a; i++) { scanf("%lld", &x); q1.push(x); } for (int i = 0; i < a;...
2
#include <bits/stdc++.h> using namespace std; int mod = 1000000007; const int inf = 1034567891; const long long LL_INF = 1234567890123456789ll; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* na...
5
#include <bits/stdc++.h> using namespace std; int main() { int w, m; cin >> w >> m; while (m > 0) { if (m % w == 0) { m = m / w; } else { if (m % w == 1) { m = (m - 1) / w; } else { if (m % w == w - 1) { m = (m + 1) / w; } else { break; ...
5
#include <bits/stdc++.h> using namespace std; char a[2000][2001]; int q, w, t = 0, s[2000][2000], d[4000000], f[4000000]; void add(int e, int r) { if ((0 <= e) && (0 <= r)) s[e][r]++; } void del(int e, int r) { if ((0 <= e) && (0 <= r)) { s[e][r]--; if (s[e][r] == 1) { d[t] = e; f[t] = r; ...
8
#include <bits/stdc++.h> using namespace std; template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; template <typename T> using max_priority_queue = priority_queue<T, vector<T>, less<T>>; const int64_t MODVAL = 1e9 + 7; template <typename T1, typename T2> istream &operator>>(istream...
4
#include <bits/stdc++.h> using namespace std; const int MAX_M = 106; int pos[MAX_M]; int add[MAX_M]; int main() { ios::sync_with_stdio(0); cin.tie(0); int b, d; while (cin >> b >> d) { string a, c; cin >> a >> c; for (int i = 0; c.size() > i; i++) { pos[i] = 0; add[i] = 0; int p = ...
6
#include <bits/stdc++.h> int main() { int n, j, i; int a[1000]; char b[1000]; j = 97; for (i = 1; i <= 26; i++, j++) { a[i] = j; } scanf("%d", &n); char o; o = getchar(); for (i = 0; i < n; i++) { scanf("%c", &b[i]); if (b[i] < 97) b[i] += 32; a[b[i] - 96] = 0; } for (i = 1; i <=...
0
#include <bits/stdc++.h> const int MOD = 1e9 + 7; const int maxn = 1000100; int f[maxn], g[maxn], a[maxn], b[maxn]; int main() { int n, m, c, ans = 0; scanf("%d%d", &n, &m); int up = n - 2 < m - 1 ? n - 2 : m - 1; for (int i = (0); i <= (maxn - 1); ++i) { f[i] = i == 0 ? 1 : (long long)f[i - 1] * i % MOD; ...
8
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> duyet(int l, int r) { vector<int> ans1, ans2, ans; ans1.clear(); ans2.clear(); ans.clear(); if (k == 0 || r - l == 1) { for (int i = l; i < r; i++) ans.push_back(i); return ans; } int mid = (l + r + 1) / 2; if (k >= 2) { k -...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i = 1, j = n - 1, ans1 = 1, ans2 = n - 1; while (i < j) { int c = 0; for (int k = 2; k <= i; k++) { if (i % k == 0 && j % k == 0) { c++; } } if (c == 0) { ans1 = i; ans2 = j; } ...
0
#include <bits/stdc++.h> using namespace std; int n, sum[2][1005], num[1005], mn, mx; char grid[2005][2005]; void print() { for (int i = mx - 1; i >= 0; i--) { for (int j = 0; j < sum[0][n]; j++) printf("%c", grid[i][j]); printf("\n"); } } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf...
4
#include <bits/stdc++.h> int main() { int n, t; scanf("%d %d", &n, &t); int ara[n - 1]; for (int i = 0; i < n - 1; i++) { scanf("%d", &ara[i]); } int i = 0; while (i < n - 1) { i = i + ara[i]; if (i == t - 1) { printf("YES\n"); return 0; } } printf("NO\n"); return 0; }
1
#include <bits/stdc++.h> using namespace std; const int kN = 2e5 + 1; int ct[kN], bit[kN]; int n; void Update(int x) { ++x; while (x <= n) { bit[x]++; x += x & -x; } } int Query(int x) { int c = 0; while (x) { c += bit[x]; x -= x & -x; } return c; } void ReadProcess() { int x; for (int...
6
#include <bits/stdc++.h> using namespace std; const int N = 105; int a[N][N]; int r[N], c[N]; int fr[N], fc[N]; int main(void) { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { scanf("%d", &a[i][j]); r[i] += a[i][j]; c[j] += a[i][j]; } int c...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; int a, b, c, d; cin >> n; cout << "YES" << endl; while (n--) { cin >> a >> b >> c >> d; int ans = abs(a) % 2; int bns = abs(b) % 2; cout << 1 + 2 * ans + bns << endl; } return 0; }
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t > 0) { int n, x, y, d; cin >> n >> x >> y >> d; if (x == y || (abs(y - x)) % d == 0) { cout << abs(y - x) / d << endl; } else if (y == 1 || (y - 1) % d == 0) { int temp = (x - 1) / d + 1 + (y - 1) / d;...
2
#include <bits/stdc++.h> using namespace std; const int N = 100003, K = 13; const int MOD = 1e9 + 7; int f[N][K][3], w[K][3], s[N]; int n, m, mk, x; unsigned long long res; vector<int> g[N]; void dfs(int u, int fa) { s[u] = 1; f[u][0][0] = mk - 1; f[u][1][1] = 1; f[u][0][2] = m - mk; for (int i = 0; i < g[u]....
6
#include <bits/stdc++.h> using namespace std; vector<long long> v; void solve(long long x) { if (x > (long long)(1e9)) return; v.push_back(x * 10 + 7); v.push_back(x * 10 + 4); solve(x * 10 + 4); solve(x * 10 + 7); } int main() { long long n, res = 0, i = 1; cin >> n; while (n) { if (n % 10 == 4) ...
1
#include <bits/stdc++.h> using namespace std; void file(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } template <typename Tp> void read(Tp &x) { int fh = 1; char c = getchar(); x = 0; while (c > '9' || c < '0') { if (c == '-') { fh = -1; } ...
11
#include <bits/stdc++.h> using namespace std; int n; int l[1005], r[1005]; int main() { int t; scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d %d", &l[i], &r[i]); int curr = l[1]; printf("%d ", curr); curr++; for (int i = 2; i <= n; i++) { if (c...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); bool flag = false; for (int i = 0; i < n - 2; i++) { if (a[i] + a[i + 1] > a[i + 2] && a[i] + a[i + 2] > a[i + 1] && a[i + 2] + a[i + 1] > a[i]) { ...
1
#include <bits/stdc++.h> const int inf = (int)1e9; const int mod = 1e9 + 7; using namespace std; int n; int k; int a[500011]; bool check1(int v) { long long sum = 0, cnt = 0; for (int i = 1; i <= n; i++) { if (a[i] >= v) { cnt += a[i] - v; } else sum += v - a[i]; } if (sum <= k && sum <= cnt...
6
#include <bits/stdc++.h> using namespace std; long long a, b, k; int main() { cin >> k >> a >> b; long long x, y; if (a > 0 && b > 0) { cout << (b / k) - ((a - 1) / k); return 0; } if (a <= 0 && b >= 0) { cout << (b / k) + 1 + (abs(a) / k); return 0; } cout << (abs(a) / k) - ((abs(b) - 1) ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, min = 10000000, sum = 0, val; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < arr[i]; j++) { cin >> val; sum += val; } sum = (sum * 5) + (arr[i...
0
#include <bits/stdc++.h> using namespace std; template <class T> void read(T& num) { char CH; bool F = false; for (CH = getchar(); CH < '0' || CH > '9'; F = CH == '-', CH = getchar()) ; for (num = 0; CH >= '0' && CH <= '9'; num = num * 10 + CH - '0', CH = getchar()) ; F && (num = -num); } int s...
1
#include <bits/stdc++.h> using namespace std; void par(int a[], int n) { for (long long int i = 0; i < n; i++) { cout << a[i] << " "; } } void pv(vector<long long int> a) { for (long long int i = 0; i < a.size(); i++) { cout << a[i] << " "; } } long long int ceiling(long long int n, long long int m) { ...
3
#include <bits/stdc++.h> using namespace std; long long modx(long long Base, long long exponent) { long long ans = 1; if (Base == 1) return Base; while (exponent) { if (exponent & 1) ans = (ans * Base) % 1000000007LL; Base = (Base * Base) % 1000000007LL; exponent = exponent >> 1; } return ans; } l...
3
#include <bits/stdc++.h> using namespace std; int MIN(int a, int b) { return a < b ? a : b; }; int MAX(int a, int b) { return a > b ? a : b; }; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int n, m, q; int flag[110]; int main() { int i, j, k; int m, t, cnt, d; char str[11...
0
#include <bits/stdc++.h> typedef long double ld; #define int long long #define gcd __gcd #define endl "\n" #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_elemen...
6