func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int arr[(int)1e5 + 1]; int q[(int)1e5 + 1]; int sol[(int)1e5 + 1]; int main() { int n, m; cin >> n; cin >> arr[0]; for (int i = 1; i < n; i++) { int x; cin >> x; arr[i] = arr[i - 1] + x; } cin >> m; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; int m, n, j, k, l, i, o, p, __t; int V[200][2000], tim[200][2000], T[200], cop[200][2000]; char ch; void read(int &a) { for (ch = getchar(); (ch < 0 || ch > 9 ) && (ch != - ); ch = getchar()) ; if (ch == - ) a = 0, __t = -1; else ...
#include <bits/stdc++.h> using namespace std; int n, k, t, cur; void solve() { scanf( %d %d , &n, &k); t = n - k; for (int i = 1; i <= t; i++) printf( %d , i); for (int i = k, j = 1; i >= 1; i--, j *= -1) { t += i * j; printf( %d , t); } } int main(void) { solve(); re...
#include <bits/stdc++.h> using namespace std; int ans, n; vector<pair<int, int> > vec; string s, t; int lcp1[5005][5005]; int lcp2[5005][5005]; void LCP(string &s, string &t, int lcp[5005][5005]) { for (int i = (int)s.size() - 1; i >= 0; i--) { for (int j = (int)t.size() - 1; j >= 0; j--) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; string s1, s2; cin >> n >> s1 >> s2; long long count = 0; for (long long i = 0; i < n / 2; i++) { char a[4] = {s1[i], s1[n - i - 1], s2[i], s2[n - i - ...
#include <bits/stdc++.h> void doubleIntSort(double d[], int m[], int s) { int i, j, r; double k1, k2, t; if (s <= 1) return; k1 = (d[0] + d[s - 1]) / 2.0; k2 = k1 + 1e-10; k1 -= 1e-10; i = -1; j = s; for (;;) { while (d[++i] < k1) ; while (d[--j] > k2) ;...
#include <bits/stdc++.h> struct data { int val; data(int val) : val(val) {} }; bool operator<(const data lhs, const data rhs) { std::cout << ? << lhs.val << << rhs.val << std::endl; char c; std::cin >> c; return c == < ; } int t, n; std::set<data> a, b; int main() { std...
#include <bits/stdc++.h> using namespace std; long long int n; long long int f(long long int x) { long long int sq = sqrt(x); for (long long int i = 2; i <= sq; i++) if (x % i == 0) return 0; return 1; } int main() { cin >> n; if (f(n)) { cout << 1 << endl << n << endl; r...
#include <bits/stdc++.h> using namespace std; int n, q; const int N = 2e5 + 10; const int inf = 1e9; char s[N]; struct Node { Node() { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { dp[i][j] = (i == j) ? 0 : inf; } } } int dp[5][5]; }; Node ...
#include <bits/stdc++.h> using namespace std; struct Point { int x; int y; Point(int x_, int y_) : x(x_), y(y_) {} }; template <class T> T sqr(const T& t) { return t * t; } template <class T> T abs(const T& t) { return ((t > 0) ? (t) : (-t)); } void initialize() { freopen( _....
#include <bits/stdc++.h> using namespace std; int res[100005], sz; bool prime[100005], used[100005]; int main() { int n; cin >> n; for (int p = 2; p <= n / 2; ++p) { if (prime[p]) continue; for (int j = p; j <= n; j += p) prime[j] = 1; if (p == 2) continue; int len = 0; ...
#include <bits/stdc++.h> using namespace std; long long mul(long long a, long long b) { return (a * b) % 1000000007; } long long add(long long a, long long b) { a += b; if (a >= 1000000007) a -= 1000000007; return a; } long long binary_expo(long long base, long long expo) { long long res = 1; ...
#include <bits/stdc++.h> using namespace std; long long n, a[3][333333], x, y, sum[4][333333], r[4][333333]; set<pair<long long, long long> > s[333333]; map<pair<long long, long long>, long long> d; map<long long, long long> last[4]; void read(long long &x) { scanf( %lld , &x); } int main() { cin >> n...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(b % a, a); } int log2(int x, int max) { return max - __builtin_clz(x) - 1; } long long powerMod(long long x, long long y) { long long res = 1; x %...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9; const long long base = 1e9 + 7; const int N = 5e3 + 2; int n, m, k; int a[N][N]; pair<int, int> h[N], c[N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> k; long long x, y, z; for (in...
#include <bits/stdc++.h> using namespace std; int S[1000007], X[1000007], Y[1000007], W[1000007], C[1000007]; char s[10]; void dfs(int x) { if (!S[x]) { W[x] = X[x]; return; } dfs(X[x]); if (S[x] > 1) dfs(Y[x]); if (S[x] == 1) W[x] = W[X[x]] ^ 1; if (S[x] == 2) W[x] = W[X[x]]...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 5, INF = (int)1e9; const long double EPS = 1e-9; int t[N], h[N], m[N]; bool used[N]; int main() { int n, cur, ans = 0, ans1 = 0, tp, v = -1, first; cin >> n >> first; cur = first; for (int i = 0; i < n; i++) cin >> t[i] >...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; long long arr[maxn]; string s; int main() { std::ios::sync_with_stdio(false); int n; cin >> n; long long tot = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; arr[i] *= 2; tot += arr[i]; } cin...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s, A( a ); cin >> s; vector<vector<int> > a(26); for (int i = 0; i < k; i++) a[s[i] - A[0]].push_back(i); for (int i = 0; i < n; i++) { cin >> s; long long ans = 0; for (int j = 0...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); void print_time() {} template <typename T> void update_max(T& x, T y) { x = max(x, y); } template <typename T> void update_min(T& x, T y) { x = min(x, y); } template <c...
#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--) { long long n; cin >> n; string a[n]; for(long long i=0;i<n;i++) { cin >> a[i]; } for(long long i=0;i<10;i++) { ...
#include <bits/stdc++.h> using namespace std; string t; vector<string> query(3); void ask(string &q) { cout << ? << q << n ; fflush(stdout); cin >> q; } int main() { ios_base::sync_with_stdio(false); ; cin >> t; for (int i = 0; i < t.length(); i++) { query[0] += (char)...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500010, INF = MAXN + 1; struct Query { int pos, l, r; }; struct AddEvent { int pos, value, start_valid; }; int n, m; int as[MAXN]; int close[MAXN]; Query queries[MAXN]; AddEvent add_events[MAXN]; int results[MAXN]; int st[4...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 11; int a[N], b[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i]; } vector<int> v; for (int p = 1; p <= 2...
#include <bits/stdc++.h> using namespace std; vector<int> sieve(int n) { vector<bool> prime(n + 1, true); prime[0] = false; prime[1] = false; int m = sqrt(n); vector<int> ans; for (int p = 2; p <= m; p++) { if (prime[p]) { for (int i = p * 2; i <= n; i += p) prime[i] = false; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; const int MOD = 1e9 + 7; int n; long long int a[MAXN], minn; bool have[MAXN], flag; int main() { while (scanf( %d , &n) != EOF) { a[1] = 0; minn = 0; memset(have, false, sizeof(have)); flag = true; f...
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << ( ; os << v.first << , << v.second << ) ; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << [ ; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 7; int A[N], B[N], n, ans, pos[N], s1[N], s2[N], cnt; int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> A[i], pos[A[i]] = i; for (int i = 1; i <= n; ++i) cin >> B[i], A[pos[B[i]]] = i; for (int i = 1; i <= n; ++i) pos[A[i...
#include <bits/stdc++.h> using namespace std; int main() { long long n, res = 0, a, b; cin >> n; vector<pair<long long, long long>> nums; for (int i = 0; i < n; i++) { cin >> a >> b; nums.push_back({a, b}); } for (int i = 0; i < n; i++) { bool l = false, r = false, u = fals...
#include <bits/stdc++.h> int main() { int a, b, c, d; while (scanf( %d%d%d%d , &a, &b, &c, &d) == 4) { if (c >= b - 1 && c <= 2 * (b + 1)) { printf( YES n ); continue; } if (d >= a - 1 && d <= 2 * (a + 1)) { printf( YES n ); continue; } printf( NO ...
#include <bits/stdc++.h> using namespace std; int A[1000001]; int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> A[i]; } map<int, int> change_v; int above = 0, below = 0; long long sum = 0; long long best_i = 0; for (int i ...
#include <bits/stdc++.h> using namespace std; template <class T> T power(T a, T b) { T x; if (b == 0) x = 1; else x = a; for (size_t i = 1; i < b; i++) x *= a; return x; } long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } long lo...
#include <bits/stdc++.h> using namespace std; const int nm = 2e5 + 3; const long long mod = 1e9 + 7; int n; int pos[nm]; int main() { ios::sync_with_stdio(0), cin.tie(0); while (cin >> n) { for (int i = 0; i < n; i++) cin >> pos[i]; sort(pos, pos + n); int step = n / 2 - 1; i...
#include <bits/stdc++.h> using namespace std; const int N = 150; int n, dp[N][N * N], sum, cnt[N], x, u[N][N * N], res; int main() { cin >> n; for (int i = 1; i <= n; i++) scanf( %d , &x), sum += x, cnt[x]++; dp[0][0] = 1; for (int i = 1; i <= 100; i++) { res += (cnt[i] > 0); for (in...
#include <bits/stdc++.h> using namespace std; long long t, xiaoyud, dayu, n, x, pos, ans1, mo = 1e9 + 7, ans2, ans; int main() { cin >> n >> x >> pos; long long l = 0, r = n; while (l < r) { long long mid = (l + r) / 2; if (mid <= pos) { l = mid + 1; if (mid != pos) xiaoyud...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, od = 0, ev = 0, ans = 0; cin >> n; vector<int> vec; vector<int>::iterator it; while (n--) { cin >> a; vec.push_back(a); if (a % 2 == 0) ev++; else od++; } for (it = vec.begin(); i...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; string s, t; int cnt[10], n, Num, tmp[10], cntT[10], m, tmpCnt[10]; string lmao1 = , lmao2 = , lmao3 = ; int main() { cin.tie(0), ios_base::sync_with_stdio(0); cin >> s; cin >> t; m = (int)(t.length()); n = (int)(...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) using namespace std; int a[510][510]; int mi[510][510]; int main() { ios_base::sync_with_stdio(0); int n, m, k, q; cin >> n >> m >> k >> q; for (int i = 1; i <= n; i++) ...
#include <bits/stdc++.h> using namespace std; struct node { node* child[26]; priority_queue<int> pq; bool leaf; node() { memset(child, 0, sizeof child); leaf = false; } }; void insert(node* curr, const string& x) { for (auto c : x) { if (!curr->child[c - a ]) curr->chi...
#include <bits/stdc++.h> using namespace std; inline int Get() { int res = 0, q = 1; char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) q = -1, ch = getchar(); while (ch >= 0 && ch <= 9 ) res = res * 10 + ch - 0 , ch = getchar(); return res * ...
#include <bits/stdc++.h> using namespace std; const int maxN = 100010; int n, m, res, l[3][maxN], r[3][maxN], g[16 * maxN], t[16 * maxN], ans[maxN], con[maxN]; bool avail[maxN]; stack<int> s[4 * maxN]; struct ioi { int v, p, t, k; }; ioi c[4 * maxN]; bool cmp(ioi i, ioi j) { if (i.v < j....
#include <bits/stdc++.h> using namespace std; using INT = long long; using pii = pair<INT, INT>; using pi3 = pair<pii, INT>; INT a[5010]; bool dp[5010][5010]; INT val[5010]; vector<pi3> ans; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); INT n, k, v; cin >> n >> k >> v; fo...
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<vector<int> > g; vector<vector<int> > revg; int active[1000005]; int del; int limx, limy, limz; unordered_set<int> visited; void add(int a, int b) { if (active[a] && active[b]) { g[a].push_back(b); revg[b].push_back(a); ...
#include <bits/stdc++.h> using namespace std; inline int d_compare(double x, double y) { return (fabs(x - y) <= 1e-8) ? 0 : (x > y) ? 1 : -1; } inline int mod(long long x, int y) { if (y == 0) return x; if (x < 0) x = -x; if (x >= y) x %= y; return x; } inline int cmod(int x, int y) { ...
#include <bits/stdc++.h> using namespace std; void solve() {} const int maxn = (int)1e6 + 420; const int MOD = (int)1e9 + 7; int n; int dp[maxn][4][4]; void contr() { cout << 0 << n ; exit(0); } int madd(int a, int b) { long long sum = a + b; sum %= MOD; return sum; } signed ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n], e = 0, s = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) e++; else s++; } int ans = 0; for (int b = 0; b < k; b++) { int c = b, ee = e, sec...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (a == 0) return b; else return gcd(b % a, a); } long long int power(long long int a, long long int b, long long int m) { long long int ans = 1; while (b) { if (b & 1) ans = (a...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, d, s = 0; cin >> n; while (n--) { cin >> a >> b >> c >> d; s = s + (c - a + 1) * (d - b + 1); } printf( %d , s); return 0; }
#include <bits/stdc++.h> using namespace std; int T, t[200010], n; int dp[2000][2000]; int main() { scanf( %d , &T); while (T--) { scanf( %d , &n); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n + n; ++j) dp[i][j] = (1 << 30); for (int i = 1; i <= n; ++i) scanf( %d , &t[i]...
#include <bits/stdc++.h> using namespace std; template <class T> void input(T &x) { char c = getchar(); x = 0; for (; (c < 48 || c > 57); c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; } } inline long long bigmod(long long p, long l...
#include <bits/stdc++.h> using namespace std; int N, M, dp[109][109][26]; vector<pair<int, char> > v[109]; void solve(int i, int j, int k) { if (dp[i][j][k] != -1) return; dp[i][j][k] = 0; for (auto e : v[i]) if (e.second >= k) { solve(j, e.first, e.second); if (dp[j][e.first][...
#include <bits/stdc++.h> using namespace std; int main() { char str[999]; cin >> str; str[0] = toupper(str[0]); cout << str << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000009; const int MAXN = 128; const int MAXK = 4; struct TrieNode { int next[MAXK], fail; int danger; void init() { fail = -1; danger = 0; for (int i = 0; i < MAXK; ++i) next[i] = -1; } } T[MAXN]; int root,...
#include <bits/stdc++.h> using namespace std; int digit(int n) { int counter = 0; while (n != 0) { counter++; n /= 10; } return counter; } int main() { int T; cin >> T; for (int i = 0; i < T; i++) { int n; cin >> n; if (n == 1) { cout << -1 << ...
#include <bits/stdc++.h> using namespace std; void base() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int32_t main() { base(); int n, num; cin >> n >> num; int turn = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (turn == j) ...
#include <bits/stdc++.h> using namespace std; struct edge { int v, id; edge *next; } * h[233333], pool[555555]; int top; inline void addedge(int u, int v, int id) { edge *tmp = &pool[top++]; tmp->v = v; tmp->id = id; tmp->next = h[u]; h[u] = tmp; edge *pmt = &pool[top++]; p...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m, count = 0; cin >> n >> m; long long a[m]; for (long long i = 0; i < m; i++) { cin >> a[i]; for (long long j = 0; j < i; j++) { if (a[j] < a[i]) count++; } } cout << count << n ; } int...
#include <bits/stdc++.h> const int N = 100001; using namespace std; long long a[N], sum[N]; int main() { int n; while (scanf( %d , &n) == 1) { for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); for (int i = 1, j; i < n; i++) { for (j = 0; (1 << j) + i <= n; j++) ; ...
#include <bits/stdc++.h> using namespace std; int n, m; int main() { scanf( %d%d , &n, &m); if (n == 1 && m == 2) { printf( 0 n1 1 n1 2 n1 1 n ); return 0; } if (n == 2 && m == 1) { printf( 0 n1 1 n2 1 n1 1 n ); return 0; } if (n * m % 2 == 1 || n == 1 || m == 1) { ...
#include <bits/stdc++.h> using namespace std; bool b[123][123]; int arr[123][123]; int k[123]; int z[123]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); bool valid = 0, flag = 0; pair<int, int> ans1, ans2; int n; cin >> n; string s, t; cin >> s >> t; for (int i =...
#include <bits/stdc++.h> using namespace std; long long n, m; long long a[100]; long long ans = 1e18; long long po[100]; map<long long, long long> ma; long long fun(long long left1) { long long ans1 = 1e18; if (left1 <= 0) { return 0; } for (long long i = 0; i < n; i++) { long ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long l, r; cin >> l >> r; long long temp = r; long long num = 1, ans = 1; while (temp) { temp /= 10; num *= 10; } num--; long long left_lim = (num)...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j; cin >> n; cin >> m; int A[n], B[m]; for (i = 0; i < n; i++) cin >> A[i]; for (j = 0; j < m; j++) cin >> B[j]; for (j = 0; j < n; j++) { for (i = 0; i < m; i++) { if (A[j] == B[i]) cout << A[j] << ...
#include <bits/stdc++.h> using namespace std; long long n, m, k, x, s, a[200005], b[200005], c[200005], d[200005], ans; int bfind(int t) { int lo = 0, hi = k - 1, mid; while (lo < hi) { mid = lo + (hi - lo + 1) / 2; if (d[mid] > t) hi = mid - 1; else lo = mid; } r...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int maxn = 100 + 10; int n, m; int a[maxn], b[maxn]; bitset<65> tt1[50000], tt2[50000]; vector<int> v; map<int, int> mp; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m;...
#include <bits/stdc++.h> using namespace std; int a[2001000]; int Partition(int l, int r) { int temp = l + rand() % (r - l); swap(a[l], a[temp]); int x = a[l], i = l - 1, j = r + 1; while (1) { do i++; while (a[i] < x); do j--; while (a[j] > x); if (i < j) swa...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T sqr(const T &a) { return a * a; } template <typename T> inline int nread(vector<T> &a) { int n; cin >> n; a.clear(); a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; return n; } template <typena...
#include <bits/stdc++.h> using namespace std; int a[210000]; long long dp[210000][2]; const long long INF = 1LL << 60; int N; void init() { for (int i = 0; i < 210000; i++) for (int j = 0; j < 2; j++) dp[i][j] = INF; } long long solve(int x, bool t) { if (x <= 0 || x > N) return 0; if ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; using ii = pair<int, int>; using ll = long long; const int N = 1e5 + 5; const int mod = 1e9 + 7; char str1[50005], str2[50005]; int n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(0);...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &n, &m); if (n == 1) printf( 1 n ); else { if (m * 2 <= n) printf( %d n , m + 1); else printf( %d n , m - 1); } return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535897; int main() { double d, h, v, e; cin >> d >> h >> v >> e; double s = (-1 * h) / (e - ((4 * v) / (pi * d * d))); if (s >= 0) cout << YES << endl << s; else cout << NO ; }
#include <bits/stdc++.h> using namespace std; void per() { cerr << endl; } template <typename Head, typename... Tail> void per(Head H, Tail... T) { cerr << H << ; per(T...); } template <class T> bool uin(T& a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(...
#include <bits/stdc++.h> int main() { int i, j, k, n, t, c1, c2, c3, c4, c5; scanf( %d%d%d%d%d , &c1, &c2, &c3, &c4, &c5); t = c1 + c2 + c3 + c4 + c5; if (t == 0) printf( -1 n ); else if (t % 5 == 0) printf( %d n , t / 5); else printf( -1 n ); }
#include <bits/stdc++.h> using namespace std; const int BIG = 1000200; char buf[BIG]; int skip0[BIG], skip1[BIG]; int vpre[BIG]; struct E { int to; char sign; int pw; }; vector<E> vg[BIG]; int main() { while (scanf( %s , buf) != EOF) { string s(buf); s = 00 + s; in...
#include <bits/stdc++.h> using namespace std; const int NMAX = 5e3; const double eps = 1e-14; double dp[NMAX + 5][NMAX + 5]; int n, k; double p[NMAX + 5]; double np[NMAX + 5]; int t[NMAX + 5]; int main() { scanf( %d %d , &n, &k); for (int i = 1; i <= n; i++) { int x; scanf( %d %d ,...
#include <bits/stdc++.h> using namespace std; bool cmp(long long a, long long b) { if (a > b) return true; return false; } long long n, dp[100010], res; pair<long long, long long> a[100010]; map<long long, long long> m; map<long long, long long>::iterator it; int main() { int t = 1; whil...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, sum1 = 0, sum2 = 0, a[200]; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] < 0) { sum2 += a[i]; } else sum1 += a[i]; } cout << sum1 - sum2; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } int ans[200200], vst[200200], pos[200200], neg[200200]; set<int> s[200200]; pr...
#include <bits/stdc++.h> using namespace std; char s[200005]; bool b[200005]; int n, ans = 0; void solve(int u) { if (u == 1) { if (u == n) { ans = 1; return; } if (s[u] == < ) { b[u] = true; ans++; } solve(u + 1); if (s[u] == > ) ...
#include <bits/stdc++.h> using namespace std; int x[10][10]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; x[a][b] = x[b][a] = 1; } if (n < 7) cout << m << n ; else { int sum = 30; for (int i = 1; i <= 7; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; for (long long i = 0; i < n; ++i) { if (i % 4 < 2) putchar( a ); else putchar( b ); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int l = s.length(); int fc = 0; int sc = 0; for (int i = 0; i < l; i++) { if (s[i] == 4 ) fc++; if (s[i] == 7 ) sc++; } if (!fc && !sc) cout << -1 << endl; else if (sc > fc) ...
#include <bits/stdc++.h> using namespace std; int main() { long int T; vector<long int> sweet(3); cin >> T; while (T--) { long int sum = 0; cin >> sweet[0] >> sweet[1] >> sweet[2]; sort(sweet.begin(), sweet.end()); sum = min((sweet[2] + sweet[1] + sweet[0]) / 2, ...
#include <bits/stdc++.h> using namespace std; inline bool is_palindrome(const string& s) { return std::equal(s.begin(), s.end(), s.rbegin()); } const long long MOD = 1000000007; const long long INF = 1e9 + 5; const double eps = 1e-7; const double PI = acos(-1.0); inline void debug_vi(vector<int> a) ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; struct node { int a; int b; int sum; }; int n, q; int nblock; node nums[300315]; int acum = 0; ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; int mod = MOD; struct ModInt { unsigned val; ModInt() : val(0) {} M...
#include <bits/stdc++.h> using namespace std; int main() { int s, v1, v2, t1, t2; cin >> s >> v1 >> v2 >> t1 >> t2; int res1 = (s * v1) + (t1 * 2); int res2 = (s * v2) + (t2 * 2); if (res1 < res2) { cout << First ; } if (res1 > res2) { cout << Second ; } if (res1 ==...
#include <bits/stdc++.h> using namespace std; const int M = 1200000; const int inf = 0x3f3f3f3f; int n, m, k; vector<int> g[M]; int ans; int dfs(int u, int f) { vector<int> v = {0, 0}; for (int to : g[u]) { if (to == f) continue; v.push_back(dfs(to, u)); } sort(v.begin(), v.end...
#include <bits/stdc++.h> using namespace std; class BIT { public: int size; vector<long long> arr; BIT(int n) { size = n + 5; arr.resize(size); } void add(int i, long long v) { for (int x = i + 1; x < size; x += (x & (-x))) arr[x] += v; } long long sum(int i) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 50; ; const int M = 255; const int mod = 998244353; const int mo = 123; const double pi = acos(-1.0); int n, m; int ans = 0; int vis[N]; vector<int> vec; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; int n, br; int p[MAXN], niz[MAXN], num[MAXN], bio[MAXN]; inline void ne() { printf( NO n ); exit(0); } void dfs1(int x) { if (bio[x]) return; bio[x] = br; num[br]++; dfs1(niz[x]); } void dfs2(int x) { if...
#include <bits/stdc++.h> using namespace std; vector<int> primes; void sieve() { vector<bool> isComposite(100000000, false); for (int i = 2; i * i <= 100000000; i++) { if (isComposite[i] == false) for (int j = i * 2; j <= 100000000; j += i) isComposite[j] = true; } for (int i = 2; i ...
#include<bits/stdc++.h> using namespace std; #define sfd(x) scanf( %d ,&x) #define sfd2(x,y) scanf( %d%d ,&x,&y) #define sfd3(x,y,z) scanf( %d%d%d ,&x,&y,&z) #define sfs(x) scanf( %s ,x) #define sfll(x) scanf( %lld ,&x) #define sfll2(x,y) scanf( %lld%lld ,&x,&y) #define pfd(x) printf( %d ,x) #define p...
#include <bits/stdc++.h> using namespace std; int fen1[200002]; void upd1(int pos, int val) { for (; pos <= 200000; pos |= (pos + 1)) fen1[pos] += val; } int fnd1(int pos) { int ret = 0; for (; pos >= 0; pos = (pos & (pos + 1)) - 1) ret += fen1[pos]; return ret; } int fen2[200002]; void ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; k = n * m / 2 - k; if (n % 2 == 1) { swap(n, m); k = n * m / 2 - k; } if...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; struct node { long long num; int p; } nd[maxn]; long long sum[maxn], f[maxn]; bool cp1(node a, node b) { return a.num < b.num; } int main() { int n, k; ios::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n;...
#include<bits/stdc++.h> #define ll int #define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; ll n, m, i, j, k = 0, t, w, flag, x, y, z, sum; string s1, s2, s; int main() { FAST_IO; cin >> n >> m >> k; ll h[n + 1][m], l[n][m + 1]; vector<vector<ll>...
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; #define rep(i,n) for (int i = 0; i < (n); ++i) #define STRING(str) #str #define ll long long #define ld long double template <typename T> void print(T x, string name) { cout << name+ : << x <...
#include <bits/stdc++.h> using namespace std; const int INFint = 2147483647; const long long INF = 9223372036854775807ll; const long long MOD = 1000000007ll; long long cnt[100000]; int main() { ios_base::sync_with_stdio(0); long long a; cin >> a; string s; cin >> s; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; template <class T> void debug(T a, T b) { ; } template <class T> void chmin(T& a, const T& b) { if (a > b) a = b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } namespace std { template <class S, class T> ostrea...