solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int n; int a[200000]; char stra[200000][20]; int lena[200000]; char tmp[20]; int t; int commonlen; int ansa; int dista; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < n; i++) { memset(tmp, 0, sizeof(...
11
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a; vector<int> b; int n, m; cin >> n; cin >> m; a.resize(n); b.resize(m); for (int i = 0; i < n; i++) { int x; cin >> x; a[i] = x; } for (int i = 0; i < m; i++) { int x; cin >> x; b[i] = x; } sort(a.be...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, ls = 1; cin >> n >> m; long long a[n][2]; for (long long i = 0; i < n; i++) for (long long j = 0; j < 2; j++) cin >> a[i][j]; long long total = 0; for (long long i = 0; i < n; i++) { if (a[i][0] == 1) { total += a[i][1]...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) { int d; cin >> d; a[d - 1] = i + 1; } for (int i = 0; i < n; i++) { int d; cin >> d; b[d - 1] = i + 1; } unordered_map<int, int> m; for (int i = 0; i < n; i+...
6
#include <bits/stdc++.h> using namespace std; int n; long long res, k; long long ar[100005]; int main() { int i, j, t, tc = 1, a, b; cin >> n >> k; long long res; for (i = 0; i < n; i++) cin >> ar[i]; res = 0; for (i = 1; i <= n; i++) { res += i; if (res >= k) break; } res = (i * (i - 1) / 2) + ...
2
#include <bits/stdc++.h> using namespace std; bool a[1000000]; int main() { for (int i = 0; i <= 500 && (i * (i + 1) / 2 < 1000000); ++i) a[i * (i + 1) / 2] = 1; int n; scanf("%d", &n); if (a[n]) printf("YES\n"); else printf("NO\n"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, t; long long DP[32][5][5][11][10]; int main() { cin >> n >> t; for (int i = 1; i < 5; i++) for (int j = 1; j < 5; j++) if (i != j) DP[2][i][j][0][0]++; for (int i = 2; i < n; i++) for (int j = 1; j < 5; j++) for (int k = 1; k < 5; k++) ...
11
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; char s[100010]; int n, m, len; long long fac[100010], inv[100010], f[100010], b[100010], ans[100010]; struct que { int l, ql, id; bool operator<(const que &t) const { if (l != t.l) return l < t.l; return ql < t.ql; } } a[100010];...
17
#include <bits/stdc++.h> const int INF = 1e9 + 7; int as[200005]; std::pair<int, int> query(int l, int r) { printf("? %d %d\n", l + 1, r); fflush(stdout); int X, F; scanf("%d", &X); static std::map<int, int> times; times[X]++; assert(times[X] <= 2); if (X == -1) exit(0); scanf("%d", &F); return {X, ...
19
#define Fast std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pr(x) cout<<#x<<": "<<x<<endl #include<bits/stdc++.h> using namespace std; typedef long long ll; inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; } const int maxn=2e5+5; const ll infl=1e18; int n; ll a[maxn],b[maxn],c; int main() { int t;...
11
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 200005; int n, k; long long b, c; long long t[N], s[N]; long long a[5][N], pre[5], pr[5]; int vis[5][5], num[5]; int main() { int i, j, ii, q; long long ans; long long now; while (scanf("%d%d%I64d%I64d", &n, &k, &b, &c) != EOF)...
16
#include <bits/stdc++.h> using namespace std; int dp[510][510], a[510]; vector<int> v[510]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; v[a[i]].push_back(i); dp[i][i] = 1; } for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) dp[i][i + 1] = 1;...
11
#include <bits/stdc++.h> using namespace std; const int N = 200500; int n, m; int a[32][N]; int esp[32][32]; int x[32][32]; int dp[1 << 16][16]; int f(int mask, int last, int init) { if (mask == (1 << n) - 1) { return esp[last][init]; } int &r = dp[mask][last]; if (r != -1) return r; r = 0; for (int j =...
12
#include <bits/stdc++.h> using namespace std; int d, tank, n; long long int sol = 0; const int limite = 1000000; int i1 = 0; int i2 = 0; long long int precio[limite]; long long int cuanto[limite]; int main() { ios::sync_with_stdio(false); cin >> d >> tank >> n; vector<pair<long long int, long long int> > v(n); ...
14
#include <bits/stdc++.h> using namespace std; int main() { double n; cin >> n; if ((int)sqrt(1 + (8 * n)) == sqrt(1 + (8 * n))) cout << "YES\n"; else cout << "NO\n"; return 0; }
0
#include <bits/stdc++.h> using namespace std; inline int _abs(int x) { return x > 0 ? x : -x; } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int n, m, q; struct Edge { int slp, ID, dx, dy; } edge[300001]; int st[100001], ed[100000]; bool comp_edge1(Edge a, Edge b) { if (a.dx == b.dx) return a.dy...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; int n, m; long long K; bool boss[maxn][maxn]; long long v[maxn][maxn]; long long A[maxn][maxn]; int S[maxn * maxn]; bool exs[maxn][maxn]; int sz[maxn * maxn]; int ans[maxn][maxn]; long long color[maxn][maxn]; pair<long long, long long> V[maxn * ma...
12
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const long long LINF = INF * (long long)INF; const int MAX = 1000 + 47; vector<int> A[MAX]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = (0...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, i, j, tmp = 1, lim = 1; cin >> n; vector<long long> v; vector<bool> vis; vector<long long>::iterator it; for (i = 0; i < 18; i++) lim *= 10; while (tmp < lim) { v.push_back(tmp)...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a, b; for (int i = 0; i < n - 1; ++i) { int x; cin >> x; a.push_back(x); } for (int j = 0; j < n - 1; ++j) { int x; cin >> x; b.push_back(x); } vector<int> t; for (int t0 = 0; t0 < 4; ++t0) ...
7
#include <bits/stdc++.h> using namespace std; long long x, y, z; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> x >> y >> z; long long ans = (x / z) + (y / z), mn = 0; if (x >= z - (y % z)) { long long t = (x - (z - (y % z))), tp = y + (z - (y % z)); long long gt = (t / z...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:65777216") using namespace std; long long qp(long long c, long long st, int mod) { long long r = 1; while (st) { if (st & 1) r = (r * c) % mod; c = (c * c) % mod; st >>= 1; } return r; } long long gcd(long long a, long long b) { if (a < 0) a...
18
#include <bits/stdc++.h> using namespace std; long long int diff[1004]; long long int n; bool yes(int x) { for (int i = 0; i + x < n; ++i) if (diff[i + x] != diff[i]) return false; return true; } int main() { cin >> n; long long int arr[n + 1]; for (int i = 0; i < n; i++) cin >> arr[i]; diff[0] = arr[0]...
4
#include <bits/stdc++.h> using namespace std; const int mod = 1000 * 1000 * 1000 + 7; const int N = 1000 * 1000 + 10; long long c[N], d[N], ps[N], ps2[N]; pair<long long, long long> p[N]; vector<int> adj[N]; bool cmp(pair<long long, long long> p, pair<long long, long long> q) { return p.first - p.second < q.first - q...
11
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; const long long maxn = 1e6 + 5; const double eps = 1e-7; const double PI = acos(-1); void std_quick_io() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline int read() { int x = 0, f = 1; ch...
15
#include <bits/stdc++.h> using namespace std; string s, j, vec; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> s >> n; for (int i = 1; i <= n; i++) { cin >> j; bool e = false; if (j.size() < s.size()) continue; for (int k = 0; k < s.size(); k++) { if (s[k...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const int MAXN = 200005; const int MAXA = 1000005; int A[MAXN]; int use[MAXA], phi[MAXA], cnt[MAXA]; vector<int> divisors[MAXA]; long long cnk[MAXN]; long long inv(long long a, long long p) { if (a == 1) return 1; return (p - p / a) * i...
17
#include <bits/stdc++.h> using namespace std; struct St { int h, nom, type; }; bool operator<(St a, St b) { return a.h > b.h; } St st[200001]; long long m, Z, mid1, mid2, x1, x2; int n, n2, S; long long s[100001], a[100001], b[100001], cnt[100001]; long long F(long long X) { long long M = S * X; long long MM = m ...
11
#include <bits/stdc++.h> using namespace std; queue<int> q; bool mrk[100010]; int main() { int n, a; int ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a; q.push(a); } for (int i = 0; i < n; i++) { cin >> a; if (q.empty() == true) continue; if (a == q.front()) { q.pop(); ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000; const int MAXLEN = 1000000; const int INF = 0x3f3f3f3f; template <class T> void Read(T &x) { x = 0; char c = getchar(); bool flag = 0; while (c < '0' || '9' < c) { if (c == '-') flag = 1; c = getchar(); } while ('0' <= c && c <= '9...
17
#include <bits/stdc++.h> int main() { int a; scanf("%d", &a); if (a == 1) { printf("1 2\n1 5\n"); return 0; } printf("%d 2\n", 5 * (a - 1)); printf("1 5\n"); return 0; }
6
#include <bits/stdc++.h> using namespace std; long long s[110000], t[110000], ans, n, m; int main() { long long i, j, k; while (cin >> n) { ans = 0; memset(s, 0, sizeof(s)); memset(t, 0, sizeof(t)); for (i = 1; i <= n; i++) cin >> s[i]; j = 0; for (i = 1; i < n; i++) if (s[i] == s[i + ...
5
#include <bits/stdc++.h> using namespace std; struct Vector { double x, y, z; Vector(){}; Vector(double a, double b, double c) { x = a; y = b; z = c; } double distsq(Vector b) { return (this->x - b.x) * (this->x - b.x) + (this->y - b.y) * (this->y - b.y) + (this->z - b.z)...
13
#include<bits/stdc++.h> using namespace std; int ask(int t,int i,int j,int x){ printf("? %d %d %d %d\n",t,i,j,x); fflush(stdout); int q; scanf("%d",&q); return q; } const int maxn=1e5+86; int a[maxn]; int main(){ int t; scanf("%d",&t); while(t--){ int n;scanf("%d",&n); int pos=0;...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { long x; cin >> x; cout << 1 << ' ' << x - 1 << endl; } }
0
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 50; int n, k; int a[N], dp[N], vis[N]; vector<int> G[N]; int getval(int comp, int im0) { if (im0 != -1) return 1 + comp + im0; else return -(1 + comp); } void dfs(int v, int mn) { int comp = 0, imcomp = -1; vis[v] = 1; for (int nxt...
18
#include <bits/stdc++.h> using namespace std; int main() { long n, i; cin >> n; long a[n], b[n], ind[n + 1]; for (i = 0; i <= n; i++) ind[i] = 0; for (i = 0; i < n; i++) { cin >> a[i]; } stack<long> st; for (i = n - 1; i >= 0; i--) st.push(a[i]); for (i = 0; i < n; i++) cin >> b[i]; long count =...
2
#include <bits/stdc++.h> using namespace std; long long INF = 1 << 28; const double pi = acos(-1.0); int fx[] = {1, -1, 0, 0}; int fy[] = {0, 0, 1, -1}; int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1}; int knight[8][2] = {1, 2, 1, -2, 2, 1, 2, -1, -1, 2, -1, -2, -2, 1, -2, -1}; const long double EPS = 1e-7; long long gcd(lo...
14
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast", "-funroll-loops", "-fdelete-null-pointer-checks") #pragma GCC target("ssse3", "sse3", "sse2", "sse", "avx2", "avx") using std::lower_bound; using std::max; using std::min; using std::vector; const int MAXN = 6e3 + 50; vector<int> E[MAXN];...
14
#include <bits/stdc++.h> using namespace std; int digit(int n) { int x = n % 10; if (x == 0) { return 1; } return 0; } int main() { int n; cin >> n; if (n % 10 > 5) { for (int i = 0; i < 11; i++) { if (digit(n + i)) { cout << n + i << endl; break; } } } else { ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n, m, par[N][20], h[N]; vector<int> g[N]; void dfs1(int u, int p) { h[u] = h[p] + 1; par[u][0] = p; for (int v : g[u]) if (v != p) dfs1(v, u); } void dp() { for (int j = 1; j <= 19; j++) for (int i = 1; i <= n; i++) par[i][j] = par...
16
#include <bits/stdc++.h> using namespace std; const int N = 5e2 + 3; int n, m; inline long long max(long long x, long long y) { return x > y ? x : y; } inline int rin() { int s = 0; bool bj = false; char c = getchar(); for (; (c > '9' || c < '0') && c != '-'; c = getchar()) ; if (c == '-') bj = true, c = ...
16
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7, inf = 0x7fffffff, dxy[] = {-1, 0, 1, 0, -1}; const long long INF = 1ll << 60; const double pi = acos(-1), eps = 1e-6; template <class T> void rd(T &x) { x = 0; char c; while (c = getchar(), c < 48) ; do x = (x << 3) + (x << 1) + (c ...
11
#include <bits/stdc++.h> using namespace std; bool cheak[1003]; vector<int> vec; void soe(int n) { cheak[0] = 1; cheak[1] = 1; for (int i = 2; i <= n; i++) { if (cheak[i] != 1) { vec.push_back(i); long long k = 2; while (pow(i, k) <= n) { vec.push_back(pow(i, k)); k++; ...
7
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define endl "\n" #define pb push_back #define PI 3.14159265358979323846...
1
#include <bits/stdc++.h> using namespace std; bool swp(int x, int y) { return x > y; } int main() { int n; scanf("%d", &n); int lar = 0; int prev = 0; int out[400]; int b[400]; memset(out, 0, sizeof(out)); for (int i = 1; i <= n; i++) { scanf("%d", &b[i]); lar = max(lar, ((b[i] - 1) / 9 + 1)); ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, root = 340; struct Q { int l, r, b, id; bool operator<(const Q& o) const { if (b != o.b) return b < o.b; else { if (b & 1) return r < o.r; else return r > o.r; } } } query[maxn]; int n, m, ans[ma...
10
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; } template <typename ...
17
#include <bits/stdc++.h> using namespace std; double fgcd(double a, double b) { if ((fabs((a) - (0)) < 1E-2)) return b; if ((fabs((b) - (0)) < 1E-2)) return a; return fgcd(b, fmod(a, b)); } int main() { double x[3], y[3], z[3], angle[3]; for (int i = 0; i < 3; i++) cin >> x[i] >> y[i]; for (int i = 0; i < 3...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 85, MAXM = 1e5 + 10, inf = 1e6; int a[MAXN], b[MAXN]; int n, m; int dp[MAXM]; int solve(int idx) { if (idx > m) return 0; int &ret = dp[idx]; if (ret != -1) return ret; ret = inf; for (int i = 0; i < n; ++i) { int l = a[i] - b[i]; int r = ...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; const int M = 1e9; const int inf = 1e9 + 7; const int base = 1e9 + 9; const double pi = acos(-1); const double ep = 1e-9; vector<int> gt[102]; int n, t; int main() { cin >> n >> t; for (int i = (int)0; i < (int)n; i++) { int u, v; scanf("%...
13
/* yaswanth phani kommineni */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define mpa make_pair #define endl '\n' void solve(){ ll n,m; cin >> n >> m; vector <ll> v(n); for(ll i=0;i<n;i++){ cin >> v[i]; } vector <pair<ll,char>> o,e; for(ll ...
12
#include <bits/stdc++.h> using namespace std; struct node { int di; long xia, shang; }; node aa[101]; int main() { int t; cin >> t; while (t > 0) { int n; long m, mm; cin >> n >> m; mm = m; for (int i = 0; i < n; i++) { cin >> aa[i].di >> aa[i].xia >> aa[i].shang; } long shij...
7
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; const int inf = (int)1e9; const int base = 10; int main() { int n, w; cin >> n >> w; vector<int> a(2 * n); for (int i = 0; i < 2 * n; i++) cin >> a[i]; sort(a.begin(), a.end()); int max = a.front(); int ma2x = a[n]; long double ...
7
#include <bits/stdc++.h> using namespace std; long long getBit(long long num, long long idx) { return (((num >> idx) & 1LL) == 1); } long long setBit(long long num, long long idx) { return (num | (1LL << idx)); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; int n, s; struct Node { int x, v, dir; } node[maxn + 10]; int lef[maxn + 10], rigt[maxn + 10]; bool judge(double t) { memset(lef, 0, sizeof(lef)); memset(rigt, 0, sizeof(rigt)); for (int i = 1; i <= n; ++i) { if (node[i].dir == 1) { i...
17
#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]; sort(arr, arr + n); vector<int> v1; v1.push_back(1); for (int i = 1; i < n; i++) { if (arr[i] < v1[0]) v1.push_back(1); else { for (int j = 0; j < v1.siz...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; vector<long long> a(k), ans(k); for (int i = 0, ThxDem = k; i < ThxDem; ++i) cin >> a[i]; for (int i = 0, ThxDem = k; i < ThxDem; ++i) { ans[i] = i + 1; ...
10
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 1000; const long long INF64 = 1e18 + 1000; const int N = 6 * 100 * 1000 + 100; const int MOD = 1e9 + 9; long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); } void spr(int x) { cout << setprecision(x) << fixed; } int main() { ...
9
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const double eps = 1e-6; const int N = 100010; int cas = 1; int n; int cnt[30]; char s[N * 2]; inline int get(char c) { if (c >= 'a' && c <= 'z') return c - 'a'; return c - 'A'; } void run() { cin >> s; memset(cnt, 0, sizeof(cnt)); int i, ans ...
3
#include <bits/stdc++.h> using namespace std; bool primes(int x) { for (int j = 2; j * j <= x; ++j) if (x % j == 0) return false; return true; } int main() { int n; cin >> n; if (primes(n)) cout << 1; else if (n % 2 == 0) cout << 2; else if (primes(n - 2)) cout << 2; else cout << 3; ...
8
#include <bits/stdc++.h> using namespace std; int mat[301][301], dir, x, y, t[31], n; int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; bool uz[31][301][301][8]; void rec(int dir, int k, int x, int y) { if (k > n) return; else if (!uz[k][x][y][dir]) { uz[k][x][y][dir] = 1; ...
11
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); } int main() { fast(); int test; cin >> test; while (test--) { int n; cin >> n; vector<int> vec(n); int mx = 0; for (auto &i : vec) { cin >> i; mx = max...
1
#include <bits/stdc++.h> using namespace std; void exgcd(int a, int b, int& x, int& y) { if (!b) { x = 1, y = 0; } else { exgcd(b, a % b, y, x); y -= (a / b) * x; } } int inv(int a, int n) { int x, y; exgcd(a, n, x, y); return (x < 0) ? (x + n) : (x); } const int Mod = 998244353; template <const...
25
#include <bits/stdc++.h> using namespace std; int n; string s1, s2, s3, s4; int main() { cin >> s1 >> s2 >> n; cout << s1 << ' ' << s2 << endl; for (int i = 1; i <= n; ++i) { cin >> s3 >> s4; if (s1 == s3) s1 = s4; if (s2 == s3) s2 = s4; cout << s1 << ' ' << s2 << endl; } }
1
#include <bits/stdc++.h> using namespace std; int ns[100002]; int sm1[100002], dp1[100002]; int sm2[100002], dp2[100002]; int main() { int n, res = -2000000000; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &ns[i]); } sm1[0] = dp1[0] = 0; for (int i = 1; i <= n; ++i) { sm1[i] = sm1[i -...
10
#include <bits/stdc++.h> using namespace std; vector<bitset<2000>> inv(vector<bitset<2000>> &M) { const int N = M.size(); vector<bitset<2000>> ans(N); for (int i = 0; i < N; i++) ans[i].set(i); for (int i = 0; i < N; i++) { int j = i; while (!M[j].test(i)) j++; swap(M[i], M[j]); swap(ans[i], ans...
20
#include <bits/stdc++.h> using namespace std; int DEBUG = 0; int Min(int a, int b) { return (a < b ? a : b); } int Max(int a, int b) { return (a > b ? a : b); } int Abs(int a) { return (a >= 0 ? a : -a); } void print1d(int *vec, int M, const char *str = NULL) { if (str != NULL) printf("%s ", str); for (int i = 0; i...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n >> x >> y; int tab[n]; for (int i = 0; i < n; i++) cin >> tab[i]; sort(tab, tab + n); int ans = 0; if (x > y) { cout << n << "\n"; return 0; } for (int i = 0; i < n; i++) if (tab[i] <= x) ans++; cout << (ans...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const double eps = 1e-8; int cas = 1; long long c[8][3]; long long d[8][8]; inline long long dist(long long a[3], long long b[3]) { long long res = 0; for (int i = 0; i < 3; i++) res += (a[i] - b[i]) * (a[i] - b[i]); return res; } long long a; boo...
12
#include <bits/stdc++.h> using namespace std; int main() { int x, y; int turn; cin >> x >> y; turn = 0; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (i % 2 != 0) { if (j != turn) cout << '.'; else { cout << '#'; } } else cou...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<pair<long long int, int> > arr(n); map<long long int, long long int> count, freq; for (int i = 0; i < n; i++) { cin >> arr[i].first; freq[arr[i].first]...
9
#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #define owo(i,a, b) for(auto i=(a);i<(b); ++i) #define uwu(i,a, b) for(auto i=(a)-1; i>=(b); --i) #define senpai push_back #define ttgl pair<int, int> #define ayaya cout<<"ayaya~"<<endl using n...
10
#include <bits/stdc++.h> using namespace std; long long const MOD = 998244353; void yes() { cout << "YES" << '\n'; } void no() { cout << "NO" << '\n'; } long long fact(int n) { long long ans = 1; for (int i = 2; i <= n; i++) { ans = (ans * i) % MOD; } return ans; } long long powM(int n, int x) { if (x == ...
11
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100010; const int MAX_X = 5 * MAX_N; int n, m; int a[MAX_N]; int h[MAX_N]; int l[MAX_N]; int r[MAX_N]; int x[MAX_N]; int z[MAX_N]; vector<int> xs; int getNewX(int x) { return lower_bound(xs.begin(), xs.end(), x) - xs.begin(); } int add[MAX_X][101]; void ad...
14
#include <bits/stdc++.h> using namespace std; int a[100005], n, m, kk; long long now, ans; int main() { scanf("%d%d", &n, &m); for (int i = (1); i <= (n); i++) scanf("%d", &a[i]); scanf("%d", &kk); for (int sgn = (0); sgn <= (1); sgn++) { for (int i = (1); i <= (n); i++) a[i] = -a[i]; now = 0; multi...
12
#include <bits/stdc++.h> using namespace std; int n, m, k1; string s[60]; bool used[60][60]; void clear() { for (int i = 0; i < int(n); ++i) { for (int j = 0; j < int(m); ++j) { used[i][j] = false; } } } void dfs(int x, int y) { if (x < 0 || y < 0 || x >= n || y >= m || s[x][y] == '.' || used[x][y])...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 40030; int cnt[2]; long long X[maxn], Y[maxn]; vector<int> a[2], pos; int main() { for (int i = 0; i < 2; i++) scanf("%d", &cnt[i]); for (int i = 0; i < 2; i++) { for (int j = 0, x; j < cnt[i]; j++) scanf("%d", &x), a[i].push_back((x + 10000) ...
13
#include <bits/stdc++.h> using namespace std; const int N = 100005; bool b[N]; int n, m, inn[N]; int cnt = 0, head[N], to[N], ne[N]; int ans = 0; queue<int> q0; queue<int> q1; inline long long in() { long long f = 1, x = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar();...
11
#include <bits/stdc++.h> using namespace std; int x[100100]; int y[100100]; int main() { long long int n, i, j, ans = 0, sumx = 0, sumy = 0; cin >> n; for (i = 0; i < n; i++) cin >> x[i] >> y[i]; for (i = 0; i < n; i++) { sumx += x[i]; sumy += y[i]; } for (i = 0; i < n; i++) { ans += ((n - 1) * ...
9
#include <bits/stdc++.h> using namespace std; int prime1 = 2473; int prime2 = 7919; long long MOD = 1000000007; long long hash1[1000005], hash2[1000006], fac[1000006]; int main() { fac[0] = 1; for (int i = 1; i < 1000001; i++) { fac[i] = (fac[i - 1] * i) % MOD; } int n; cin >> n; int m; cin >> m; lo...
11
#include <bits/stdc++.h> using namespace std; const int N = 5005; int dist[N][N]; int c[N], k[N], p[N]; int n, m, w, q; vector<int> adj[N]; void BFS() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) dist[i][j] = N; queue<int> q; dist[i][i] = 0; q.push(i); while (!q.empty()) { i...
13
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, const T &b) { return b > a ? a = b, true : false; } template <class T> inline bool chmin(T &a, const T &b) { return b < a ? a = b, true : false; } const int N = 1001; int n, m; bool used[N]; int parent[N]; vector<int> G[N]; pai...
12
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265358979323; const long long mod1 = 1e9 + 7; const long long mod2 = 1e18; const long long mod3 = 9e18; long long power(long long x, long long n) { if (n == 0) return 1; long long temp = power(x, n / 2); if (n % 2 == 0) return temp * ...
4
#include <bits/stdc++.h> using namespace std; int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 1000002; int ...
20
#include <bits/stdc++.h> using namespace std; int n, m, dp[5001][5001], ans; string a, b; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> a >> b; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i - 1] == b[j - 1]) { dp[i][j] = dp[i - 1][j - 1]...
10
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 1; const int INF = 1e9 + 9; const int B = 1e9 + 7; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); int q; cin >> q; for (int i = int(1); i <= int(q); ++i) { int n; cin >> n; long long l = 2, r = n; if (n <= 5) { co...
13
#include <bits/stdc++.h> namespace IO { const int SIZE = (1 << 20) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = obuf + SIZE - 1; char _st[55]; int _qr = 0; inline char gc() { return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++); } inline void ...
11
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); long long n, m, cnt = 0; cin >> n >> m; long long a = ceil(sqrt(n)); long long b = ceil(sqrt(m)); for (long long i = 0; i <= a; i++) { for (long long j = 0; j <= b; j++) { if (((i * i + j) ...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long long MIN = -1e18, MAX = 1e18; pair<long long, long long> b[100005]; void sol() { long long m, ans = 0, s = 0; cin >> m; for (long long i = 1; i <= m; i++) { cin >> b[i].second; b[i].first = 0; for (long long j = 1; j <...
5
#include <bits/stdc++.h> using namespace std; int main() { long long q; cin >> q; while (q--) { long long l1, r1, l2, r2; cin >> l1 >> r1 >> l2 >> r2; long long d = r1 - l1; long long p = r2 - l2; if (l1 == l2) { cout << l1 << " " << l2 + 1 << endl; } else cout << l1 << " " << ...
0
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f3f3f3f3fLL; string str[100050][2]; long long c[100050]; long long dp[100050][2]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; memset(dp, 0x3f, sizeof(dp)); str[0][0] = str[0][1] = ""; dp[0][0] = 0; ...
8
#include <bits/stdc++.h> using namespace std; using ld = long double; using ull = unsigned long long; int main() { int n; cin >> n; vector<int> arr(n), zeros(n, 0); for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = n - 2; i >= 0; i--) { zeros[i] = zeros[i + 1]; if (arr[i + 1] == 0) zeros[i]++; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; if (min(x, y) % 2 == 0) cout << "Malvika"; else cout << "Akshat"; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int ans = 0; while (n) { ans += n; n /= 2; } cout << ans << "\n"; } return 0; }
6
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, k, x, y, t; cin >> t; for (int i = 0; i < t; i++) { cin >> a >> b >> c >> d >> k; x = (a / c) + 1; if (a % c == 0) { x--; } y = (b / d) + 1; if (b % d == 0) { y--; } if (x + y > k) { cout <...
0
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline int read() { int x = 0, f = 1, c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f ^= 1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x; } inline void write(int x) { if (!x) { putchar(...
14
#include <bits/stdc++.h> using namespace std; priority_queue<pair<int, int> > pq[5]; queue<pair<int, int> > q[5]; int n, m, k, Max, re[5], a[100001][5]; void solve() { scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) scanf("%d", &a[i][j]); } for (int i = 0; i < n; i++...
12
#include <bits/stdc++.h> using namespace std; template <typename T> inline void checkmin(T &a, T b) { if (a > b) a = b; } void solve() { int n; cin >> n; vector<string> forbiddens(n); for (int i = 0; i < (n); i++) { cin >> forbiddens[i]; for (int j = 0; j < (((int)forbiddens[i].length())); j++) ...
8
#include<bits/stdc++.h> using namespace std; #define f(i,b) for(int i=1;i<=b;++i) #define pb push_back #define pa pair<int,int> #define F first #define S second #define mp make_pair #define ve vector<int> #define v1 vector<string> #define ma map<int,int> #define se set<int> #define ll long long #define B begin() #defi...
7