func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long dev[5000005]; long long S[5000005]; long long pri[5000005]; void sieve() { memset(dev, -1, sizeof dev); int p = 0; for (int i = 2; i <= 5000005; i++) { if (dev[i] != -1) continue; pri[p++] = i; for (long long j = 1; j < 5000...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 5; ll f[N]; int n, ans, c; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %lld , &f[i]); for (int i = 2; i < n; i++) { if (f[i] == f[i - 1] + f[i - 2]) { c++; ans = max...
#include <bits/stdc++.h> using namespace std; int p[100001], w[100001]; vector<pair<int, int>> e[100001]; long long ans[100001], sum; int root(int x) { while (x != p[x]) x = p[x] = p[p[x]]; return x; } void pre(int x, int from) { sum += w[x]; for (auto c : e[x]) if (c.first != from) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; char c[maxn]; long long mod = 1e9 + 7; long long ex(long long a, long long b) { a = a % mod; long long ans = 1; while (b) { if (b % 2 == 1) { ans = (ans * a) % mod; } a = (a * a) % mod; b = b /...
#include <bits/stdc++.h> using namespace std; template <typename T> istream &operator>>(istream &is, vector<T> &arr); template <typename T> ostream &operator<<(ostream &os, vector<T> &arr); int INF = 1e9 + 5; long long C(int n, int m) { long long ans = 1; for (int i = 1; i <= m; i++) { ans *...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long n; cin >> n; cout << n / 2 << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0, max = 0; char line; cin >> n; n++; while (n--) { char temp; scanf( %c , &temp); if (temp == ) { if (count > max) max = count; count = 0; } else if (temp >= A && temp <= Z ) ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (y1 == y2) cout << abs(x2 - x1) << n ; else if (x1 == x2) cout << abs(y2 - y1) << n ; else { int x, y; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; vector<int> graph[maxn]; vector<int> g[maxn]; bool mark[maxn]; int n, m; int par[maxn]; int cm[maxn]; bool comp[maxn]; int mk[maxn]; int moalefe[maxn]; void dfs(int x, int y) { mark[x] = 1; cm[x] = y; moalefe[y]...
#include <bits/stdc++.h> const unsigned int M = 1000000007; long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = x * res; y = y >> 1; x = x * x; } return res; } long long power(long long x, long long y, long long mod) { long long r...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> gru; for (int i = 0; i < n; i++) { gru.push_back(i + 1); } long long lead = 1; for (int i = 0; i < k; i++) { long long a; cin >> a; lead += a; lead = lead % gru.s...
#include <bits/stdc++.h> #define debug(a) cout << #a << : << a << n #define debugLine() cout << ============== n #define tick() cout << Tick n ; #define testCases() int t; cin >> t; while(t--) #define all(a) a.begin(), a.end() #define fillWith(a, b) memset(a, b, sizeof(a)) #define INF_32 1e9 #d...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 50; const int INF = 0x3f3f3f3f; struct node { int to, next; } edge[maxn * 3]; struct Node { int id; long long val; bool operator<(const Node& a) const { return val < a.val; } }; int head[maxn], cnt, d[maxn], depth[maxn]...
#include <bits/stdc++.h> using namespace std; template <class T> void in(T &x) { x = 0; bool f = 0; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = 1; c = getchar(); } while ( 0 <= c && c <= 9 ) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve() { int n, k, d; cin >> n >> k >> d; vector<int> dist(n, -1); vector<vector<pair<int, int>>> za(n); vector<int> keep(n - 1), par(n); queue<int> q; for (int i = ...
#include <bits/stdc++.h> using namespace std; int qq, n, m, k, l, r; string s, s1, s2, s3; int INF = (int)2e9 + 7; struct st { int x, y; }; bool operator<(st& a, st& b) { if (a.x != b.x) return a.x < b.x; return a.y < b.y; } vector<vector<char>> v; int x[4] = {0, 0, -1, 1}, y[4] = {-1, 1...
#include <bits/stdc++.h> int i, j, m, n, s, t, x, y; int a[1000][1000], b[1000][1000], c[1000], d[1000]; int main() { while (~scanf( %d%d%d , &n, &x, &y)) { for (i = 0; i < 1000; i++) for (j = 0; j < 1000; j++) { a[i][j] = 0; b[i][j] = 0; } for (i = 1; i <= n; i...
#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) ...
#include <bits/stdc++.h> using namespace std; int n; vector<int> adj[100001]; vector<int> cost[3]; long long matrix[3][3] = {0}; int tree[100000]; int output[100000] = {0}; void makeTree(int a, int pos) { tree[pos] = a; for (auto &i : adj[a]) { if (pos == 0 || tree[pos - 1] != i) makeTree(...
#include <bits/stdc++.h> using namespace std; int n, m, k, x[1010], y[1010], i, j, l, r[1010], w[1010], dad[1010], ss, flag, use[1010], ke, t; int rr[1010], ww[1010], use1[1010]; char s1[1010][20], s[20]; int fi(int x) { return dad[x] == x ? x : dad[x] = fi(dad[x]); } int main() { scanf( %d%d%d , ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, sum = 1, sum2 = 2, t = 0, k = 0; cin >> n; int a[n], b[n]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { if (a[i] == 1) t++; if (a[i + 1] == 1 || i == n - 1) { b[k] = a[i]; ...
#include <bits/stdc++.h> using namespace std; int N; long long shu[200010]; int main() { while (scanf( %d , &N) != EOF) { for (int i = 1; i <= N * 2; i++) { scanf( %I64d , &shu[i]); } sort(shu + 1, shu + 1 + 2 * N); long long ans = (shu[N] - shu[1]) * (shu[2 * N] - shu[N + 1]...
#include <bits/stdc++.h> using namespace std; int main() { int w, h; cin >> w >> h; char char1[100][100], char2[100][100]; string char3[200]; for (int i(0); i < h; ++i) cin >> char1[i]; for (int i(0); i < w; ++i) { for (int j(0); j < h; ++j) { char2[i][j] = char1[abs(j - h + 1)...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; bool val = false; cin >> n; char array[n][5]; for (int i = 0; i < n; i++) { cin >> array[i]; } for (int i = 0; i < n; i++) { if (array[i][0] == O & array[i][1] == O ) { val = true; array[...
#include <bits/stdc++.h> using namespace std; int n, a[110]; long long ans; int main() { ans = 0LL; scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); for (int i = 1; i <= n; ++i) { ans += (long long)a[i]; ans += (long long)(i - 1) * (long long)(a[i] - 1); } co...
#include <bits/stdc++.h> using namespace std; long long niz[200005]; int main() { ios_base::sync_with_stdio(false); cout.precision(10); cout << fixed; int n; cin >> n; long long k, m; cin >> m >> k; for (int i = 1; i <= n; i++) cin >> niz[i]; sort(niz + 1, niz + 1 + n); lon...
#include <bits/stdc++.h> using namespace std; void solve(){ int n;cin>>n; if(n <= 45){ int point = 9; string ans = ; int x = n; while(x > point){ ans += to_string(point); x -= point; point--; } if(x) ans += to_string(x); reverse(ans.begin(),ans.e...
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1}; int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; int n, m; bool dfs(pair<int, int> start, vector<string>& G, vector<vector<bool> >& odw, set<pair<int, int> >& jed) { stack<pair<int, int> > S; S.push(start); odw...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, r, avg, m, k, t, x, y, i, j, b, d, MOD = 1073741824, count = 0, ans = 0; string s; cin >> s; long long int a[36] = {0}; for (i = 0; i < s.size(); i++) { if (s...
#include <bits/stdc++.h> using namespace std; #define ll long long int const int N=1000005; //vector<int>prime; bool prime[N]; void sieve() { int k=sqrt(N-2); for(int i=1;i<=N-2;++i) prime[i]=true; for(int i=2;i<=k;++i) { if(prime[i]) { f...
#include <bits/stdc++.h> using namespace std; int main() { int tt; cin >> tt; while (tt--) { int n, l; cin >> n >> l; vector<double> flags(n); for (auto& i : flags) cin >> i; double a_s = 0, b_s = l; double a_v = 1, b_v = 1; int a_i = 0, b_i = n - 1; doubl...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5.2e3 + 5; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } char s[MAXN]; bool a[MAXN][MAXN]; int main(void) { int n; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %s , s + 1); for (int j = 1; s[j]; ++j) {...
#include <bits/stdc++.h> using namespace std; double sum[2][30][200010]; char A[2][200010]; int main() { int N; cin >> N; cin >> A[0] >> A[1]; for (int i = 0; i < (N); i++) for (int k = 0; k < (2); k++) A[k][i] -= A ; double cont = 0; double val = 0; for (int i = (1); i <= (N)...
#include <bits/stdc++.h> bool u[1000001]; int pr[500001]; int l; int n; long long a[8]; int f[7000]; int thr[10]; int b[8]; int inf = 10000; int g[8]; int cal(long long x) { int i; int ret = 0; for (i = 1; i <= l && pr[i] <= x / pr[i]; i++) { while (x % pr[i] == 0) { x = ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; priority_queue<pair<int, int> > neg; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pos; cin >> n; int x, a; ...
#include <bits/stdc++.h> using namespace std; struct edge { int v, nxt; } e[200005 << 1]; int top = 1; int head[200005]; void Add_Edge(int u, int v) { e[++top] = edge{v, head[u]}; head[u] = top; } int n; int a[200005], par[200005][21], dep[200005], size[200005]; void dfs(int u, int fa) {...
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int n; std::cin >> n; std::vector<bool> col(6 * n); for (int i = 0; i < 3 * n; ++i) { int x; std::cin >> x; --x; col[x] = true; } std::vector<int> sta; std::vector<...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const int maxn = 300 + 10, maxm = 4e4 + 10; const int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0}; const int INF = 0x3f3f3f3f; struct Graph { int ndn, edn, last[maxn]; int u[maxm], v[maxm], flw[maxm], cap[...
#include <bits/stdc++.h> using namespace std; int a[52][52] = {0}; int b[52]; bool c[52] = {0}; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { scanf( %d , &a[i][j]); if (c[a[i][j]] == 0) c[a[i][j]] = 1; els...
#include <bits/stdc++.h> using namespace std; vector<long long> ok; vector<long long> nok; void doit() { long long n, d, m; cin >> n >> d >> m; vector<long long> v; long long x; while (n--) { cin >> x; v.push_back(x); } sort(v.begin(), v.end()); long long mleg = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 2005, M = N * N; int n, m; string s[N]; bool isvalid(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m && s[x][y] == . ; } int id(int x, int y) { return x * N + y; } int par[M]; void init() { for (int i = 0; i < M; i++) par[i...
#include <bits/stdc++.h> using namespace std; int solve(int n, int a[]) { int count = 0; for (int i = 0; i < n; ++i) { if (a[i] == i) { ++count; } } for (int i = 0; i < n; ++i) { if (a[i] != i && a[a[i]] == i) { return count + 2; } } return min(count +...
#include <bits/stdc++.h> using namespace std; const int N = 52; const int MAX = 1e9 + 5; int n, a[N]; long double dp[N][N][N][N]; int p; long double all, P[N]; long double f(int wh, int ret, int left, int whd) { if (left == 0 && ret) return 0; if (left == 0 && ret == 0) return 1; if (ret < 0...
#include <bits/stdc++.h> using namespace std; void solve() { unsigned long long int t; cin >> t; while (t--) { unsigned long long int n; cin >> n; unsigned long long int x; cin >> x; vector<unsigned long long int> ind; vector<pair<unsigned long long int, unsigned long...
#include <bits/stdc++.h> using namespace std; template <typename T, typename T2> T2 fac(T n) { return n < 2 ? 1 : fac<T, T2>(n - 1) * n; } template <typename T, typename T2, typename T3> T2 fac(T n, T3 mod) { return n < 2 ? 1 : (fac<T, T2, T3>(n - 1, mod) * n) % mod; } template <typename T> T ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; long long int a, b, c, r; while (t--) { long long int ans = 0, mx = 0, mn = 0; cin >> a >> b >> c >> r; if (a >= b) { mx = a; ...
#include <bits/stdc++.h> using namespace std; long long t[45]; int n, i, k, m, kol, ans, ans2, j, l, ans3, ans1, sum; void summ(int x) { for (j = 0; j < k; j++) { l = n - x; while (ans2 <= m - t[j] and l > 0) { l--; ans2 += t[j]; kol++; } } } int main() { ...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { long long int temp; while (b > 0) { temp = b; b = a % b; a = temp; } return a; } int main() { long long int N, m; cin >> N >> m; long long int a[N], B[m]; for (lo...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5; vector<int> G[maxn + 5]; int dp[maxn + 5], d[maxn + 5]; int main() { int n, x, ans = 0; scanf( %d , &n); for (int i = 2; i <= maxn; i++) for (int j = i; j <= maxn; j += i) G[j].push_back(i); for (int i = 0; i < n; i++) {...
#include <bits/stdc++.h> using namespace std; const int N = 1111; int n; string a[N], b[N]; int t[N]; int d; std::set<pair<string, string> > res; int main() { cin >> n >> d; for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> t[i]; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 500; long long dp[N]; long long n; void init() { dp[0] = 1ll; dp[1] = 2ll; for (int i = 2; i < N; i++) { dp[i] = dp[i - 2] + dp[i - 1]; } } int main() { init(); while (cin >> n) { int cur = 0; while...
#include <bits/stdc++.h> using namespace std; int main() { char str[100005]; cin >> str; int flag = 0, i; char checkString[100005]; for (i = 0; str[i] != 0 ; i++) { checkString[i] = a ; } checkString[i] = 0 ; if (strcmp(str, checkString) == 0) { checkString[strlen(ch...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e7 + 50; const double eps = 1e-7; const int inf = 0x3f3f3f3f; const long long lnf = 0x3f3f3f3f3f3f3f3f; const long long mod = 1e9 + 7; const double pi = 3.141592653589; int vis[maxn], cnt = 0, h[maxn]; int sum1[maxn], sum2[maxn]; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; ll MOD = 1000000007; ll INF = 1LL << 60; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; vector<int> tree[n + 1]; int u, v; for (int i = 0; i < n - 1; i++) { cin >> u >> v; t...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } int main() { long long int n, a, b, t, ans, g; cin >> t >> a >> b; if (a > b) swap(a, b); n = (b / gcd(a, b)); if (n > LLONG_MAX / a) { ...
#include <bits/stdc++.h> using namespace std; const int N = 500500; bool Ans[N]; int Weight[N]; pair<int, int> Edges1[N]; vector<int> Edges2[N]; vector<pair<int, vector<int> > > Query[N]; int P[N]; stack<pair<int, int> > Was; void Clear() { while (!Was.empty()) Was.pop(); } void Restore() { ...
#include <bits/stdc++.h> using namespace std; using INT = long long; using pii = pair<int, int>; using pi3 = pair<int, pii>; int n, m; int nxt[100010]; int a[100010], b[100010]; set<pii> A, B; set<pi3> ans; int calc_max(int u, set<pair<int, int> > &st) { auto it = st.upper_bound({m - 1 - u, n + ...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return (a * b) / gcd(a, b); } long long int dp[200001][18]; void solve() { long long int n...
#include <bits/stdc++.h> using namespace std; int n, a[2005]; long long sum[10005], D[5005]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) D[abs(a[i] - a[j])]++; sum[5000] = 0; double ans = 0...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, x, y; cin >> n >> x >> y; long long l = y - (n - 1); if ((n - 1) + l * l >= x && l > 0) { for (long long i = 0; i < n - 1; i++) cout << 1 ; cout << l << endl; } else { cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; template <typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << ; cout << endl; } template <typename T> void chmin(T &t, const T &f) { if (t > f) t = f; } template <typename T> void chmax(T &t, const T &f) { if (t < f)...
#include <iostream> #include<cmath>> #include<algorithm> #include <string> using namespace std; int arr[101]; int arrstr[200]; bool prime(int n) { if(n<=1) return false; if(n<=3) return true; for(int i=2;i<=sqrt(n);i++) { if(n%i==0) ret...
#include <bits/stdc++.h> int n; struct mjj { int x, y; } a[500001], b[500001]; int fa[500001]; int head[500001], end[1000001], len[1000001], next[1000001], tp; int head2[500001], end2[1000001], len2[1000001], next2[1000001], tp2; int dad[500001], db[500001], dad2[500001], db2[500001], wz[500001], gs; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 12; int rows, cols, k, n; char mat[MAXN][MAXN]; int sol = 0; int Calc(int a, int b, int c, int d) { int ret = 0; for (int i = a; i <= c; i++) { for (int j = b; j <= d; j++) ret += (mat[i][j] == # ); } return ret; } int...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; using v...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10; const int INF = 1e9 + 9; const int B = 1e9 + 7; int n, p[N]; set<pair<int, int> > s[N]; int d[N]; int main() { scanf( %d , &n); ++n; for (int i = int(2); i <= int(n); ++i) { scanf( %d , &p[i]); d[i] = -1; ...
#include <bits/stdc++.h> using namespace std; char s[100000]; int main() { int m, n, j, k, l, t, ll; bool is = false; cin >> t; cin >> s; if (t < 5) { cout << no << endl; return 0; } l = t / 5; ll = t % 5; for (j = 0; j < t && !is; j++) for (k = 1; k < t && ...
#include <bits/stdc++.h> using namespace std; long long n, m, k, g[2010], a[100003], f[2010], ansn, sum1, sum2; bool make[200]; int main() { cin >> n >> m; bool see = false; for (int i = m; i > n; i--) { for (int j = 2; j <= min((long long)100000, n) and !see; j++) if (i % j == 0) { ...
#include <bits/stdc++.h> using namespace std; using INT = long long; const int NN = 202020; int a[NN], b[NN]; map<int, int> mp; int main() { int n, y; cin >> n >> y; for (int i = 1; i <= n; i++) cin >> a[i]; int m, yy; cin >> m >> yy; for (int i = 1; i <= m; i++) cin >> b[i]; int...
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1); const long long MOD = 1e9 + 7; const long long INF = LLONG_MAX; const long long SIZE = 100000; void solve() { long long n, s; cin >> n >> s; long long sum = 0, dig = 0, fir; long long k = n; vector<long long> ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 5; int n, a[N]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %d , a + i); sort(a, a + n); for (int i = 0, eq = 0; i < n - 1; ++i) { if (a[i] == a[i + 1]) { if ((++eq) > 1 |...
#include <bits/stdc++.h> using namespace std; int main() { int M, N, s, x, l, c; vector<pair<int, int>> val; vector<int> seq; cin >> M; for (int i = 0; i < M; i++) { cin >> s; if (s == 1) { cin >> x; val.push_back(make_pair(0, x)); if (seq.size() < 1e6) { ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void solve() { int n; cin >> n; string s; cin >> s; vector<vector<int> > v(26); for (int i = 0; i < n; i++) { char a = s[i]; char k = a; k++; for (char j = k; j <= z ; j++) { int x = j -...
#include <bits/stdc++.h> using namespace std; long long int arr[200005]; pair<long long int, long long int> even[200005]; pair<long long int, long long int> odd[200005]; int main() { long long int n; cin >> n; for (long long int i = 1; i <= n; i++) cin >> arr[i]; even[2] = make_pair(0, 2); ...
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); inline int sj(int n) { unsigned long long x = rnd(); x = x << 32 | rnd(); return x % n + 1; } const int p = 998244353; inline void inc(int &x, const int y) { if ((x += y) >...
#include <bits/stdc++.h> using namespace std; int n; vector<int> g[100005]; vector<pair<pair<int, int>, int> > coord; int visited[100005]; long long ans = 1; const long long pmod = 1000000007; long long expsize; set<int> x, y; bool cycle; int mapback[100005]; long long qpmod(long long b, long lo...
#include <bits/stdc++.h> using namespace std; int incoming[110]; int outgoing[110]; int main(int argc, const char* argv[]) { int n, m; cin >> n >> m; int a, b, c; for (int i = 0; i < m; i++) { cin >> a >> b >> c; incoming[b] += c; outgoing[a] += c; } int ans = 0; fo...
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, n, m, z, c; string s; cin >> s; c = 0, z = 0; for (i = 0; i < s.size(); i++) { if (s[i] == 4 ) c++; else if (s[i] == 7 ) z++; } if (c == z && z == 0) cout << -1 << endl; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, INF = 1e9; vector<int> g[N], r[N], out; int cnt[N], ans = INF, sum = 0; int dfs(int v, int par) { for (int i = 0; i < g[v].size(); i++) if (g[v][i] != par) cnt[v] += dfs(g[v][i], v); for (int i = 0; i < r[v].size(); i++) ...
#include <bits/stdc++.h> using namespace std; vector<int> E[1010000]; int n, m, T[1010000]; bool v[1010000]; void DFS(int a) { v[a] = true; int i; for (i = 0; i < E[a].size(); i++) { if (!v[E[a][i]]) DFS(E[a][i]); } } long long Res; int main() { int i, a, b, ck = 0, cc = 0; ...
#include<bits/stdc++.h> using namespace std; #define ll long long const int maxn = 3e3+5; const int mod = 0x3f3f3f3f; int n,d,q; void solve(int n){ if(n>=10*d){ cout<< YES <<endl; return; } for(int i=1;i<=9;i++){ if(n>=d*i&&(n-i*d)%10==0){ cout<< YES <<endl; return; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 110, mod = 1e9 + 7; const long long inf = 1e18; long long a[maxn]; int b[maxn]; long long ans1, ans2, ans3; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; using lint = long long; const int N = 200005; const int MAX = 250; int cnt[N * (MAX + 5)]; int pref[N]; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); string s; cin >> s; int n = s.size(); lint ans = 0; for (int i = ...
#include <bits/stdc++.h> using namespace std; int a[100007]; int main() { int n, kq; cin >> n; if (n == 1) { cout << 1; return 0; } kq = 2; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n - 2; ++i) { int j = 0; for (j = i + 2; j <= n; ++j) ...
// // Created by Abhishek Bansal on 3/18/2021 // //#pragma GCC optimize ( O3 ) //#pragma GCC optimize( Ofast,no-stack-protector ) //#pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native ) #include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; clock_t ...
#include <bits/stdc++.h> const long long maxn = 1e3 + 5; const long long w = 1e8; using namespace std; int m, n, p, kq; char a[maxn][maxn]; string s; char dir[4] = { D , L , U , R }; int tdx, tdy; int x, y; inline void init() { cin >> n >> m; cin.ignore(); for (int i = 1; i <= n; i++)...
#include <bits/stdc++.h> using namespace std; int main() { int n, a; int N[2005], A[2005]; cin >> n; for (int i = 0; i < n; i++) { cin >> a; N[i] = a; } for (int i = 0; i < n; i++) { int cont = 0; for (int j = 0; j < n; j++) { if (i != j && N[i] < N[j]) cont++...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, a, P, len, rev[N]; int Lim; int f[2][N], g[2][N]; const long double PI = acos(-1.0); struct Complex { long double x, y; Complex() {} Complex(long double _x, long double _y) { x = _x; y = _y; } Compl...
#include <bits/stdc++.h> using namespace std; const int N = 2000 + 1, inf = 2e8 + 1; int a, m, n; bool d[N]; int p[N]; int dp[N]; int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> a >> n >> m; for (int i = 0; i < n; ++i) { int l, r; cin >> l >> ...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ppi = pair<pii, int>; char s[200100]; int rk[200100], sa[200100], ht[200100]; int mn[200100][22]; namespace SA { int head[200100 * 2]; ppi pos[200100 * 2], buf[200100 << 1], tbuf[200100 << 1]; int nxt[200100 * 2]; void...
#include <bits/stdc++.h> using namespace std; const int BSZ1 = 1010; const int BSZ2 = 200; int N; char A[202020]; int B[40404040]; int C[202020]; long long ans; int R[202020]; void calc(int i, int r, int zero) { int t = (zero + R[r]) / i; int u = zero / i; if (zero % i != 0) u++; if ...
#include <bits/stdc++.h> using namespace std; int main() { string num1, num2, num3; int i, j, k, l, m, n, last, flag = 0; cin >> num1; num2 = num1; num3 = num1; l = num1.length(); last = num1.at(l - 1) - 48; for (i = 0; i < l - 1; i++) { m = num2.at(i) - 48; if (m % 2 == ...
#include <bits/stdc++.h> using namespace std; const double ep = 1e-6; const double eps = 4e-5; const double pi = acos(-1); int tmpx, tmpy; struct pnt { double x, y; pnt(double x = 0, double y = 0) : x(x), y(y) {} pnt operator+(const pnt &b) const { return pnt(x + b.x, y + b.y); } pnt operato...
#include <bits/stdc++.h> using namespace std; bool solve(long long a, long long b) { if (a > b) { return solve(b, a); } if (a == 0) { return false; } bool next = solve(b % a, a); if (!next) { return true; } long long c = (b / a); if ((a % 2 == 1)) { return...
#include <bits/stdc++.h> using namespace std; bool visited[2000]; vector<int> G[2000]; vector<int> parent; int dfs(int u) { if (visited[u]) { return 0; } visited[u] = true; int ans = 0; for (int i = 0; i < G[u].size(); i++) { ans = max(ans, dfs(G[u][i])); } return ans +...
#include <bits/stdc++.h> using namespace std; long long arr[101], N, T; void Input() { cin >> N; memset(arr, 0, sizeof arr); for (int i = 0; i < N; i++) { long long tmp; cin >> tmp; arr[tmp]++; } } void Solve() { int one = 0, two = 0; for (int i = 0; i <= 100; i++) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; int N; char S[2 * MAXN]; int ord[2 * MAXN]; pair<pair<int, int>, int> E[2 * MAXN]; int step = 1; int pre[MAXN]; int minp[MAXN]; int mins[MAXN]; char ans[MAXN]; void build() { for (int i = 0; i < N; i++) ord[i] = (S[i] ==...
#include <bits/stdc++.h> using namespace std; string findSum(string str1, string str2) { if (str1.length() > str2.length()) swap(str1, str2); string str = ; int n1 = str1.length(), n2 = str2.length(); reverse(str1.begin(), str1.end()); reverse(str2.begin(), str2.end()); int carry = 0; ...
#include <bits/stdc++.h> using std::cin; using std::cout; using std::string; int main() { bool newline = true; bool found; for (string s; getline(cin, s);) { found = false; for (string::size_type index = 0; index < s.size(); ++index) if (s[index] != ) if (s[index] ==...
#include <bits/stdc++.h> using namespace std; int n, d, c[55]; int dp[500010]; int main() { memset(dp, -1, sizeof(dp)); cin >> n >> d; for (int i = 0; i < n; i++) cin >> c[i]; sort(c, c + n); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = 500000 - c[i]; j >= 0; j--) ...