func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; char s[100100], sir[100100]; int viz[100100], mi, ma, t, n, freq[100100], fre[100100]; int prim(int x) { for (int i = 2; i <= x; ++i) { if (i * i > x) return 1; if (x % i == 0) return 0; } return 1; } int main() { cin >> (s + 1); ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; long long int a[n]; long long int q = 0, p = 0, z = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; if (a[i] < 0) q++; else if (a[i] > 0) p++; else z++; } ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 10, inf = 1e9; int r[N], c[N], dist[N]; bool seen[N] = {0}; int main() { int row, col, k; cin >> row >> col >> k; for (int i = 1; i <= k; i++) { cin >> r[i] >> c[i]; dist[i] = inf; if (r[i] == 1 and c[i] == 1) dist... |
#include <bits/stdc++.h> using namespace std; long long int _sieve_size; bitset<10000010> bs; vector<int> primes; void sieve(long long int upperbound) { _sieve_size = upperbound + 1; bs.set(); bs[0] = bs[1] = 0; for (long long int i = 2; i <= _sieve_size; i++) if (bs[i]) { for (l... |
#include <bits/stdc++.h> #pragma warning(disable : 4786) #pragma comment(linker, /STACK:16777216 ) using namespace std; char str[1000005]; int Z[1000005], n; void Zfunction() { int L, R, r, i, j, k; L = 0; R = 0; Z[0] = 0; for (i = 1; i < n; i++) { if (i > R) { L = i; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 1, M = 100; int n, q; bitset<N> sq[M]; vector<int> on[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; for (int x = 0, qwerty = M; x < qwerty; x++) sq[x][0] = 1; for (int x = 0, qw... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<string> v; string a; while (n--) { cin >> a; v.push_back(a); } int cot = 0; bool p = 1; int ans = 1000000; string c; for (int j = 0; j < v.size(); j++) { c = v[j]; c... |
#include <bits/stdc++.h> using namespace std; inline bool equal(double _x, double _y) { return _x > _y - 1e-9 && _x < _y + 1e-9; } char s[300]; int mx, cnt, sum, ans; bool OK(char c) { if (c >= a && c <= z || c >= A && c <= Z ) return 1; return 0; } int main() { int n; scanf( ... |
#include <bits/stdc++.h> int ss[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; int n, a[200], f[120][(1 << 16) + 10], b[100], g[120][(1 << 16) + 10]; void outit(int x, int y) { if (y == 0) return; outit(x & ~b[g[y][x]], y - 1); printf( %d , g[y][x]); if (y == n) printf( n... |
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 0) return power(a * a % 1000000007, b / 2); return a * power(a, b - 1) % 1000000007; } long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a... |
#include <bits/stdc++.h> using namespace std; const int N = 101; short dp[N][N][N * N], a[N], ans; int n; short calc(int u, int k, int sum) { if (u == N) return !sum && !k; short &ref = dp[u][k][sum]; if (ref != -1) return ref; ref = 0; for (short i = 0; i <= a[u] && sum - u * i >= 0 && i ... |
#include <bits/stdc++.h> using namespace std; const int N = 300 * 1000 + 5, SQ = 373; int a[N]; long long dp[2 * N]; pair<pair<int, int>, int> t[N]; long long finans[N]; int main() { ios ::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; inline int add(int a, int b) { if ((a += b) >= mod) a -= mod; return a; } inline int dec(int a, int b) { if ((a -= b) < 0) a += mod; return a; } inline void _add(int& a, int b) { if ((a += b) >= mod) a -= mod; ... |
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)(1e9 + 7); const long long inv = (long long)(5e8 + 4); int main() { long long n, m; cin >> n >> m; long long ans = (n % mod) * (m % mod) % mod; long long l = 1, r = 1; while (l <= min(n, m)) { long long a = ... |
#include <bits/stdc++.h> using namespace std; const long long Mx = 512; long long D[Mx][Mx]; int32_t main() { long long n, m, mod, a = 0, b = 0; cin >> n >> m >> mod; vector<long long> C(n); for (long long i = 0; i < m; i++) for (long long j = 0; j < n; j++) { char c; cin >... |
#include <bits/stdc++.h> int n, a[200005]; bool check1(int x) { for (int i = x + 1; i <= n; i++) if (a[i] >= a[i - 1]) return 0; return 1; } bool check2(int x) { for (int i = x + 1; i <= n; i++) if (a[i] <= a[i - 1]) return 0; return 1; } int main() { scanf( %d , &n); for... |
#include <bits/stdc++.h> using namespace std; int n, a[105], p[105]; long long g[105]; long long d[105][105][105]; bool ok[105][105]; char c[105]; void read(int& x) { char c = getchar(); x = 0; while (!isdigit(c)) c = getchar(); while (isdigit(c)) { x = x * 10 + c - 0 ; c = ge... |
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const long long INF = LLONG_MAX / 2; const long long N = 2e5 + 1; struct event { long long sa; long long ea; long long sb; long long eb; }; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.... |
#include <bits/stdc++.h> using namespace std; long long n, arr[300010], lft[300010], rgt[300010], mx = 0, cnt = 0; stack<long long> s1, s2; set<long long> st; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) lft[i] = -1, rgt[i] = n; for (int i = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int l, r; scanf( %d%d , &l, &r); if (l == r && l % 2) printf( %d , l); else printf( %d , 2); } |
#include <bits/stdc++.h> using namespace std; const long long C = 1000000007; long long pow1(long long x, long long y, long long z) { if (y == 0) { return 1; } if (y % 2 == 0) { return pow1(x * x % z, y / 2, z); } return pow1(x, y - 1, z) * x % z; } signed main() { ios::syn... |
#include <bits/stdc++.h> using namespace std; void init_code() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { init_code(); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> arr(n + 1, 0); map<int, int> mp; for (int i = 1; i <= n;... |
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; void __print(long long int x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << << x << ; } void ... |
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T a) { return (a) * (a); } template <class T> T abs(T a) { return (a < 0) ? -(a) : (a); } const double Pi = acos(-1.0); const double eps = 1e-10; const int INF = 1000 * 1000 * 1000; const double phi = 0.5 + sqrt(1.25); ... |
#include <bits/stdc++.h> const long long mod = 1e9 + 7; const long long LL_MAX = 9223372036854775807; using namespace std; int a[100005]; int main() { int n; scanf( %d , &n); for (int i = 0; i < 2 * n; i++) scanf( %d , &a[i]); int ans = 0; for (int i = 0; i < 2 * n; i++) { if (a[i] =... |
#include <bits/stdc++.h> using namespace std; int record[300000]; int main() { map<pair<int, int>, int> m; memset(record, 0, sizeof(record)); int n, p; scanf( %d%d , &n, &p); map<pair<int, int>, int>::iterator iter; for (int i = 0; i < n; i++) { int a, b; scanf( %d%d , &a, &b);... |
#include <bits/stdc++.h> using namespace std; long long fastpow(int a, int b, int MOD) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y) % MOD; } y = (y * y) % MOD; b /= 2; } return x; } long long InverseEuler(int n, int MOD) { return fastpow... |
#include <bits/stdc++.h> using namespace std; using namespace chrono; const int maxn = 1e6; void solve() { int n, a[21][21], val; vector<int> data; map<int, int> m; cin >> n; for (int i = 0; i < n * n; i++) { cin >> val; data.push_back(val); m[val]++; } if (n == 1) ... |
#include <bits/stdc++.h> using namespace std; const int maxn = (int)(2e6 + 123); const int R = (int)(2e6); const long long inf = (long long)(1e12 + 7); long long pn, p[maxn], lp[maxn], b[maxn]; bool u[maxn]; void resheto(long long n) { for (long long i = 3; i * i <= n; i += 2) if (!u[i]) ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e6 + 3; const int INFI = 1e9 * 2; const long long LINFI = 1e17; const double pi = acos(-1.0); const int N = 111; const int M = 11; const int move[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1}; double mabs(double x) { retur... |
#include <bits/stdc++.h> using namespace std; int main() { int n, h; cin >> n >> h; vector<int> a(n, 0); copy(istream_iterator<int>(cin), istream_iterator<int>(), a.begin()); vector<int> a_orig = a; sort(a.begin(), a.end()); int max1 = a[n - 1] + a[n - 2]; int min1 = a[0] + a[1]; ... |
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1e18; const long long mod = (long long)1e9 + 7; const double eps = (double)1e-9; const double pi = acos(-1.0); const int dx[] = {0, 0, 1, 0, -1}; const int dy[] = {0, 1, 0, -1, 0}; const int N = 100500; void solve() { i... |
#include <bits/stdc++.h> using namespace std; const int p = 1000000007; int n, x, y, g[100005], vg[100005], C, P = 1, a1, a2, a3, b, ans; vector<int> l[100005], r[100005]; inline int ksm(int a, int b) { int res = 1; while (b) { if (b & 1) res = (long long)res * a % p; a = (long long)a * a ... |
#include <bits/stdc++.h> using namespace std; void bringToTen(int &k, int &rating, vector<int> &bucket) { for (int i = 9; i > 0; i--) { int x = 0; while (x < 100) { int h = min(k / (10 - i), bucket[x + i]); k -= h * (10 - i); bucket[x + 10] += h; rating += h; ... |
#include <bits/stdc++.h> using namespace std; int arr[200000], arr2[200000]; int main() { int n, i; long long sum = 0; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &arr[i]); arr2[i] = arr[i] + arr2[i - 1]; } for (i = 0; i < n; i++) { if (arr[i] == 0) { s... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6, M = 3, nBits = 2e8 + 5, MM = (1 << 16), MAX = 1111, OO = 0x3f3f3f3f, MOD = 1000000007, inf = 1 << 30; const double PI = acos(-1); const long long INF = (long long)1e18, MOOD = 1000000007; long long GCD(long long a, long long b) {... |
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > P; int n; bool compare_y(const pair<long long int, long long int>& p1, const pair<long long int, long long int>& p2) { if (p1.second != p2.second) return p1.second < p2.second; return p1.first < p2... |
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t = 1; cin >> t; while (t--) { long long n, x; cin >> n >> x; long long deg[1005] = {}; for (long long i = 1; i < n; i++) { long long u, v... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int n, g[21][21], a, t[maxn]; bool ans = true; int find(int times) { int i = 1; bool finded = false; for (; i <= 1000; ++i) if (t[i] >= times) { finded = true; break; } if (!finded) ans = false; ... |
#include <bits/stdc++.h> using namespace std; int n, d; int a[200]; int x[200], y[200]; int dis[200]; vector<pair<int, int> > edge[200]; int bellman_ford() { for (int i = 0; i < n; ++i) dis[i] = 1000000000; dis[0] = 0; for (int i = 1; i < n; ++i) { for (int j = 0; j < n; ++j) { f... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 50; const long long Mod = 1e9 + 7; struct node { long long to, next, w; } edge[maxn * 2]; struct Edge { long long u, v; } t[maxn]; long long k = 0, head[maxn]; void add(long long u, long long v) { edge[++k].to = v; ... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> L[1000005]; long long fac[1000005]; const long long MOD = 1000000007; int main() { int N, M; scanf( %d%d , &N, &M); for (int i = 0; i < N; ++i) { int g; scanf( %d , &g); map<int, int> cnt; for (int j = 0; ... |
#include <bits/stdc++.h> using namespace std; long long get_sum(vector<long long> &prefix, int left, int right) { if (left != 0) return prefix[right] - prefix[left - 1]; else return prefix[right]; } void To_Add_or_Not_To_Add(vector<long long> &a, long long k) { int n = a.size(); sort... |
/* */ #include <bits/stdc++.h> using namespace std; #define rng(x) x.begin(), x.end() #define pb push_back #define ff first #define ss second typedef double db; typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; ty... |
#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) { f... |
#include <bits/stdc++.h> using namespace std; const int inf(1010101010); int le_res, aa; char naam[1000]; int le_naam; char naam_and_res[1000]; char occ[1000]; int zvals[1000]; void z_functie(char* s, int n, int* z) { int a(0), b(0); for (int i(0); i < (n); i++) z[i] = n; for (int i = 1; i... |
#include <bits/stdc++.h> #pragma GCC optimize 03 using namespace std; const long long int N = 2e5 + 5; const long long int mod = 1e9 + 7; const long long int inf = 1e9 + 9; long long int a[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n; cin ... |
#include <bits/stdc++.h> using namespace std; char c[2001][2001]; int sum1[2001][2001], sum2[2001][2001]; int f[2001][2001][2]; int mod = 1000000007; int main() { int n, m; scanf( %d %d , &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf( %c , &c[i][j]);... |
#include <bits/stdc++.h> #pragma GCC optimize( -O2 ) 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...); } const int LIM = 1e5 + 5, MO... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; ll x[1 << 18]; int main() { ios::sync_with_stdio(false), cin.tie(0); ll n, r; cin >> n >> r; ll m = 1 << n; ll sum = 0; for (int i = 0; i < m; i++) cin >> x[i], sum += x[i]; cout << fixed <<... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long n, k; cin >> n >> k; if (k >= n / 2) cout << n * (n - 1) / 2; else cout << n * (n - 1) / 2 - (n - 2 * k) * (n - 2 * k - 1) / 2; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long T; cin >> T; while (T--) { int N; string S; cin >> N >> S; int Who = -1; string Ans1 = , Ans2 = ; for (int i = 0; i < N; i++) { if... |
#include <bits/stdc++.h> using namespace std; int const N = 1000000; int n, m; vector<vector<pair<int, int> > > adj; bool valid; int ans[N]; int cnt; int st[N * 3]; void readin() { int u, v; char b[10]; scanf( %d%d , &n, &m); valid = true; adj.clear(); adj.resize(n + 1); fo... |
#include <bits/stdc++.h> using namespace std; int main() { int n, f = 0; cin >> n; string a[] = { Sheldon , Leonard , Penny , Rajesh , Howard }; while (n > 5) { n = n / 2 - 2; } cout << a[n - 1] << endl; } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; string s, st = ; cin >> s; vector<int> m(28); vector<int> l(28); for (int i = 0; i < n; i++) { m[((int)s[i]) - 97]++; } if (n == k) { cout << n ; ... |
#include <bits/stdc++.h> using namespace std; const int N = 80, Inf = 0x3f3f3f3f; int n, f[N][N][N][2]; int pos[3][N], num[3][N]; char s[N]; inline int getid(char ch) { if (ch == V ) return 0; if (ch == K ) return 1; return 2; } inline int move(int i, int j, int k, int id) { return max... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; long long fn(string a, string b) { long long n = a.size(), m = b.size(), j = 0; for (long long i = 0; i < m; i++) { if (b[i] == a[j]) { j++; if (j >= n) { return m - n; } } } if ... |
#include <bits/stdc++.h> using namespace std; #define lln long long int #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); void solve(){ int n, k; cin>>n>>k; vector<int> a(n+1); for(int i = 1;i<=k;i++) a[i] = i; int x = k - 1; for(int i = ... |
#include <bits/stdc++.h> using namespace std; int n, m, sz1, sz2, val; int d1[200005], d2[200005], d[200005]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &val); if (val != 0) d1[sz1++] = val; } for (int i = 0; i < n; i++) { scanf( %d , &val); i... |
#include <bits/stdc++.h> using namespace std; int main() { char arr[4][4], a; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cin >> a; arr[i][j] = a; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (arr[i][j] == # && arr[i][... |
#include <bits/stdc++.h> const int N = 1e6 + 5, P = 1e9 + 9; inline int ksm(int a, int b) { int r = 1; for (; b; b >>= 1, a = (long long)a * a % P) if (b & 1) r = (long long)r * a % P; return r; } int n, q, a[N], t[N], f[N], F[N]; struct mat { int s[2][2]; inline friend mat operator+... |
#include <bits/stdc++.h> using namespace std; void low(int n) { switch (n) { default: cout << zero ; break; case 1: cout << one ; break; case 2: cout << two ; break; case 3: cout << three ; break; case 4: c... |
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf( %d , A + i); } char s[222222], r[222222]; int N, A, B; int main(void) { scanf( %s%s , s, r), N = strlen(s); for (int i(0); i < N; i++) if (s[i] ^ r[i]) A += s[i] == 52, B += s[i] != 52;... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5, mod = 1e9 + 7; int add(int x, int y) { x += y; return x >= mod ? x - mod : x; } int c[maxn << 1], dp[maxn]; struct node { int x, y, op; } e[maxn]; bool cmp(node a, node b) { if (a.x == b.x) return a.y < b.y; retu... |
#include <bits/stdc++.h> using namespace std; inline bool ig(char c) { return c >= 0 && c <= 9 ; } inline void read(int &oi) { char c; int f = 1, res = 0; while (c = getchar(), (!ig(c)) && c != - ) ; c == - ? f = -1 : res = (c ^ 48); while (c = getchar(), ig(c)) res = res * 10 + (c... |
#include <bits/stdc++.h> using namespace std; long long a[200005]; unordered_map<long long, long long> f, done; vector<long long> v; int main() { std::ios_base::sync_with_stdio(0); cin.tie(0); long long n; long long ans = 0; cin >> n; for (long long i = 1; i <= n; i++) { cin >> a... |
#include <bits/stdc++.h> using namespace std; int N, M, T, tb[100005]; long long a, b, c, co, x; map<int, int> mp; map<int, int>::iterator it; int chk[100005]; int main() { int i, j, k; scanf( %d%I64d , &N, &co); for (i = 1; i <= N; i++) { scanf( %d , &tb[i]); mp[tb[i]]++; x ... |
#include <bits/stdc++.h> using namespace std; int mida; void update(vector<int>& T, int p, int x) { T[mida + p] = x; for (int i = (mida + p) / 2; i > 0; i /= 2) T[i] = T[2 * i] + T[2 * i + 1]; } int suma(vector<int>& T, int a, int b, int c = 0, int d = mida - 1, int p = 1) { if (a <= c and d <= b)... |
#include <bits/stdc++.h> using namespace std; int r, c, s, e; vector<int> adj[1000 * 1000 + 10]; int d[1000 * 1000 + 10]; char grid[1000][1000]; char access(int n) { int x = n % c; int y = n / c; return grid[y][x]; } void bfs(int n) { queue<int> frontier; frontier.push(n); d[n] =... |
#include <bits/stdc++.h> using namespace std; int n, m; int in[100000 + 5]; bool doit() { if (scanf( %d%d , &n, &m) != 2) return false; for (int i = 0; i < n; ++i) in[i] = 0; int x, y; for (int i = 0; i < m; ++i) { scanf( %d%d , &x, &y); ++in[--x], ++in[--y]; } sort(in, in + ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = (1 << 19) + 5; template <typename T> inline void read(T &WOW) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - ... |
#include <bits/stdc++.h> using namespace std; constexpr long long MOD = (long long)1e9 + 7; long long fexp(long long a, long long n) { a %= MOD; if (n == 0) return 1; long long ret = fexp(a * a % MOD, n / 2); if (n % 2 == 1) ret = ret * a % MOD; return ret; } long long blub(long long pa, l... |
#include <bits/stdc++.h> using namespace std; vector<int> kmp(string &str) { int n = str.size(); vector<int> res(n + 1); res[0] = -1; int ind = -1; for (int i = 0; i < n; i++) { while (ind >= 0 && str[i] != str[ind]) ind = res[ind]; ind++; res[i + 1] = ind; } return res... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n, greater<int>()); for (int i = 0; i < n; i++) cout << a[i] << ; cout ... |
#include <bits/stdc++.h> int main() { int n, d, t, x, y, z, m; scanf( %d %d %d , &n, &d, &m); z = n - d; while (m--) { scanf( %d %d , &x, &y); if (x > n || y > n) { printf( NO n ); } else { if (y >= abs(x - d) && y <= n - (abs(z - x))) { printf( YES n ); ... |
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 10, mod = 1e9 + 7; int fact[N], invfact[N]; inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; } inline int mul(int x, i... |
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const lo... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; map<long long int, long long int> mp; vector<long long int> v(n); vector<long long int> cSum(n, 0); for (long long int i = 0; i < n; i++) { cin... |
#include <bits/stdc++.h> using namespace std; long long n; pair<string, long long> s[1000005]; long long m; bool cmp(pair<string, long long> a, pair<string, long long> b) { string s = a.first, t = b.first; for (long long i = 0; i < (m); i++) if (s[i] != t[i]) { if (i & 1) retur... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) const long long int maxn = 5e5 + 16, md = 1e9 + 7, inf = 2e18; long long int tav(long long int n, long long int k) { long long int res = 1; while (k > 0) { if (k & 1) { res *= n; res %= md; } n ... |
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } char s[1000009], t[1000009]; int cnt... |
#include <bits/stdc++.h> long long t, a, b, h, f[110]; using namespace std; long long mi(long long n, long long m) { long long res = 1; for (int i = 1; i <= m; i++) res *= n; return res; } void solve(long long a, long long b) { for (int i = h; i; i--) { long long t = mi(a, i); f[i]... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; vector<pair<long long, long long>> arr(n); for (long long i = 0; i < n; i++) { long long a; cin >> a; if (a >= 0) a = (-1) * a - 1; arr[i... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n]; for (int i = 0; i < n; i++) { int x; cin >> x; a[i] = x; } sort(a, a + n); int count = 0; for (int i = (n - 1); i >= 0; i--) { if (m > 0) { m = m - a[i]; ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (a > b) { if (a == 9 && b == 1) cout << 9 << << 10; else cout << -1; return 0; } if ((b - a) > 1) { cout << -1; return 0; } if (b == a) { cout <<... |
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize( inline ) using namespace std; const int N = 100050, INF = 0x3f3f3f3f; int n, col, sum, n1, n2; struct node { int color, val, id; friend bool operator<(node x, node y) { return x.val < y.val; } } white[N], black[N]; int min(in... |
#include <bits/stdc++.h> using namespace std; const long long N = 5e3 + 5; long long read() { long long s = 0; char c = getchar(), lc = + ; while (c < 0 || 9 < c) lc = c, c = getchar(); while ( 0 <= c && c <= 9 ) s = s * 10 + c - 0 , c = getchar(); return lc == - ? -s : s; } void... |
/****************************************** By Lord Sanskar Bhargava******************************/ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd;... |
#include <bits/stdc++.h> using namespace std; int dp[1003][1003][12][3]; string s, t; int solve(int i, int j, int k, int cont) { if (i < 0 || j < 0) return 0; if (dp[i][j][k][cont] != -1) return dp[i][j][k][cont]; int ret = -9; if (s[i] == t[j]) { if (cont) { ret = max(ret, 1 + sol... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 510; int m; long long n, ans; int cnt, head[N]; struct edge { int to, next; } e[1010]; void ade(int u, int v) { e[++cnt] = (edge){v, head[u]}; head[u] = cnt; } long long getsize(long long num) { ... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 105, MAX_R = 60005; int n, r, a, b; vector<pair<int, int> > inc, d; int dp[MAX_R][MAX_N]; int main() { ios::sync_with_stdio(false); cin >> n >> r; for (int i = 0; i < n; i++) { cin >> a >> b; if (b >= 0) { inc.pu... |
#include <bits/stdc++.h> using namespace std; long long n, b, x, q, t, ans, l, r, m, p, now, sum; bool ok; string s; map<int, int> a, pos; map<char, int> c; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> q; while (q--) { cin >> n >> m; cin >> s; ... |
#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++) cin >> a[i]; b[n - 1] = a[n - 1]; for (int j = 0; j < n - 1; j++) b[j] = a[j] + a[j + 1]; for (int k = 0; k < n; k++) cout << b[k] << ; return 0; } |
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read(T& x) { x = 0; int f = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) f |= (ch == - ), ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x = f ? -x : x; } ... |
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 10; const int N = (int)1e6 + 10; const long double eps = 1e-7; mt19937 rnd(228); int main() { int n, q; cin >> n >> q; deque<int> d; int mn = INF; int mx = -INF; for (int i = 0; i < n; ++i) { int x; ... |
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, k; pair<int, int> a[N]; vector<pair<int, int> > Center; bool inf; bool Check(pair<int, int> center) { int cnt = 0, l = 1, r = n; pair<int, int> t; while (l <= r && cnt <= k) { t = make_pair(center.first - a[l].fir... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) int on_bit(int N, int pos) { return N = N | (1 << pos); } int off_bit(int N, int pos) { return N =... |
#include <bits/stdc++.h> using namespace std; long long nt[105]; string s; vector<long long> V; void ts() { nt[0] = 0; nt[1] = 0; for (long long i = 2; i <= 100; i++) { nt[i] = 1; } for (long long i = 2; i <= 100; i++) { if (nt[i] == 1) { for (long long j = i * i; j <= ... |
#include <bits/stdc++.h> using namespace std; template <typename T> void maxE(T& a, const T& b) { a = max(a, b); } template <typename T> void minE(T& a, const T& b) { a = min(a, b); } template <typename T> ostream& operator<<(ostream& out, const vector<T>& t_) { out << [ ; for (auto i... |
#include <bits/stdc++.h> using namespace std; string get(int n, int m) { string str; for (int i = 1; i <= n; i++) str.push_back( 4 ); for (int i = 1; i <= m; i++) str.push_back( 7 ); return str; } int32_t main() { ios_base ::sync_with_stdio(0); cin.tie(0); string str; cin >> str;... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.