func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long mod = 1000000007; const long long INF18 = 1000000000000000000; long long n; long long a[1010]; bool ok = false; void rec(long long depth, long long cnt, long long sum) { ...
#include <bits/stdc++.h> using namespace std; int FuN(long long n) { string s; while (n != 0) { int ch = (n % 2); s += ch + 0 ; n /= 2; } int x = -1; for (int i = 0; i < s.size(); i++) { if (s[i] == 1 ) x = i + 1; } return x; } int main() { int t, n, i, ...
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } const double EPS = 1e-9; const double PI = acos(-1.); const int INF = 1e9; const int MAXN = 2e5 + 5; const long long MOD = 1e9 + 7; void output_path(int n, int a, int b, int c, int ...
#include <bits/stdc++.h> using ll = long long; using namespace std; bool is_valid_streak(map<ll, ll>& unique_counts) { if (unique_counts.size() == 2 && unique_counts.begin()->first == 1 && unique_counts.begin()->second == 1) { return true; } else if (unique_counts.size() == 2 && ...
#include <bits/stdc++.h> using namespace std; inline int read() { int num = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == - ; ch = getchar(); } while (isdigit(ch)) { num = (num << 3) + (num << 1) + (ch ^ 48); ch = getchar(); } return w ? -num : num; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, max = 0, count1 = 0; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; ...
#include <bits/stdc++.h> using namespace std; namespace jumpmelon { long long divfloor(long long a, long long b) { long long k = a / b; if (k * b > a) k--; return k; } long long divceil(long long a, long long b) { long long k = a / b; if (k * b < a) k++; return k; } void work() { ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int N = 1e5 + 10; multiset<int> ms; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; ms.insert(x); } int cur = 1; ...
#include <bits/stdc++.h> using namespace std; int dp[100][100]; struct point { public: int f, t; point() {} point(int a, int b) { f = a, t = b; } }; int main() { int X, k; cin >> X >> k; int val, sum = 0; vector<pair<int, int>> a, b; for (int i = 0; i < (X); i++) { cin...
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; const int maxm = 5005; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int n; scanf( %d , &n); int a[maxn]; bool exist[maxm]; for (int i = 0; i < maxm; ++i) exist[i] = true; ...
#include <bits/stdc++.h> using namespace std; int a[300010]; int main() { int t, n; cin >> t; while (t--) { cin >> n; int prvi = -1, br_jednakih = 1, maxi = -1; for (int i = 0; i < n; i++) { cin >> a[i]; maxi = max(maxi, a[i]); if (i == 0) { prvi = a...
#include <bits/stdc++.h> void parse(int size, std::string& input, int& pos, int depth, int& max_depth, std::vector<std::vector<std::string> >& comments) { if (size <= pos) { return; } if (depth > max_depth) { max_depth = depth; comments.push_back(std::vector<std::string>());...
#include <bits/stdc++.h> using namespace std; int n, CA, CB; struct point { int x, y; bool operator<(const point &p) const { return x != p.x ? x < p.x : y < p.y; } } st[201000]; int BX[201000], EX[201000], BY[201000], EY[201000]; long long res; void Pro(vector<point> &w, int *B, int *E) { int ...
#include <bits/stdc++.h> using namespace std; long long n, h; long long r(long long l, long long s, long long e, long long d) { if (s + 1 == e) return 0; long long m = 1 + (s + e) >> 1; long long k = (n < m ? (d ? (1ll << (h - l)) : 1) : (d ? 1 : (1ll << (h - l)))); if (n < m) return r(l +...
#include <bits/stdc++.h> using namespace std; int ar[200010]; vector<int> ans; void solve() { int n, a, b, k, cnt = 0; cin >> n >> a >> b >> k; string s; cin >> s; int nxt = n + 1; for (int i = n; i > 0; i--) { if (s[i - 1] == 1 ) { cnt += (nxt - i - 1) / b; nxt = ...
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int n, d, h; cin >> n >> d >> h; if (d > 2 * h || (d == 1 && (n - 1 > d))) { cout << -1 << endl; } else { for (int i = 1; i <= h; i++) { cout << i << << i + 1 << endl; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[105]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int c = 0; for (int i = 0; i < n;) { if (a[i] == 1) { while (a[i] == 1 || a[i + 1] == 1) { c++; i++; if (i == n) break;...
#include <bits/stdc++.h> int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1}; using namespace std; template <class T> T sq(T n) { return n * n; } template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } template <class T> T lcm(T a, T b)...
#include <bits/stdc++.h> using namespace std; double m1 = 200.0, m2 = 0.0, DV; int card, n, k, Q, getcard; int a[110], vs[110], b[110], len = 0; int sum = 0, tmp; int main() { memset(vs, 0, sizeof(vs)); scanf( %d%d , &n, &k); card = (int)(n / k); for (int i = 1; i <= n; ++i) scanf( %d , &a[i...
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; if (a == 1) { cout << 1 << << 1 << endl << 1 << endl; } else { cout << 2 * (a - 1) << << 2 << endl << 1 << << 2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a = 0, b = 0, r = 0; while (true) { a = (int)n / 36; r = n % 36; b = (int)r / 3; if (r % 3 == 2) b += 1; if (b >= 12) n = b *...
#include <bits/stdc++.h> using namespace std; enum Type { Normal, HBox, VBox }; struct Widget { char name[11]; long long width, height; int border, spacing; vector<int> sons; Type type; }; int wCnt; Widget widgets[101]; map<string, int> name2id; int str2int(char* start, char* end) { ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int inf = (int)1e9; const double inf1 = 1e-9; const int ss = (int)1e6 + 3; int main() { string s; getline(cin, s); int sz = s.find( . ); int z1 = 0; if (sz == -1) { sz = s.size(); z1 = -1; }...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long ans1, ans2; long long n, m; cin >> n >> m; ans1 = n * m / 2; ans2 = ans1; if (n * m % 2) ans1++; long long x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; ...
#include <bits/stdc++.h> using namespace std; constexpr int inf = numeric_limits<int>::max() >> 1; constexpr int N = 100001; constexpr int mod = 1000000007; int h[N], tin[N], tout[N], ap[N], n, root, a[N], T; int mx[N * 4], mn[N * 4], ml[N * 4]; vector<int> g[N]; void dfs(int u, int p) { tin[u] = ++...
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 1; int vis[M], vis2[M]; int main() { string t, s; cin >> s >> t; int a = 0, b = 0; for (char c : t) vis[c]++; int i = 0; for (char c : s) { if (vis[c]) { vis[c]--; a++; vis2[i] = 1; } ...
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7; int add(int a, int b) { if ((a += b) >= P) a -= P; return a; } int sub(int a, int b) { if ((a -= b) < 0) a += P; return a; } int mul(int a, int b) { return 1ll * a * b % P; } int kpow(int a, int b) { int r = 1; ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const long long MOD = 998244353; vector<vector<pair<long long, long long> > > adj; int c[2]; int colour[700005]; bool ok; int n; void dfs(int idx) { c[colour[idx]] += (idx <= n); for (auto x : adj[idx]) { if (co...
#include <bits/stdc++.h> int a[1005]; void Init() { int i; a[0] = 1; a[1] = 1; for (i = 2; i <= 1000; i++) { a[i] = a[i - 1] * 3 % 1000003; } } int main() { int i, n; Init(); scanf( %d , &n); printf( %d n , a[n]); return 0; }
#include <bits/stdc++.h> int m, n, a[10][10] = {{0, 1, 2}, {1, 0, 2}, {1, 2, 0}, {2, 1, 0}, {2, 0, 1}, {0, 2, 1}, {0, 1, 2}}; int main() { scanf( %d %d , &n, &m); n %= 6; printf( %d , a[n][m]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b[100], c, xd = 0, lol; cin >> a; for (int i = 0; i < a; i++) { cin >> b[i]; } sort(b, b + a); for (int i = 0; i < a; i++) { if (i == a - 1) { c = b[i]; } } for (int i = 0; i < a; i++) { ...
#include <bits/stdc++.h> using namespace std; template <class T> T inline sqr(T x) { return x * x; } const long double pi = 3.1415926535897932384626433832795; const long double eps = 1e-8; const int MAXN = 1000500; string s; int n; int fin[3]; struct node { int l, r, par, link; map<cha...
#include <bits/stdc++.h> using namespace std; using UL = unsigned long int; using UI = unsigned int; using ULL = unsigned long long int; using LI = long int; using LL = long long; using LF = double; using LLF = long double; const int mod1 = 1000000007; const int mod2 = 998244353; const double PI =...
#include <bits/stdc++.h> using namespace std; const int N = 1004; int n, p, q, f[N][54][54], vc = 1000000000, ns[N][30], nt[N][30]; char c[N], s[N], t[N]; bool check1(int i, char x, int j) { if (i + 1 < j) return false; for (int k = 1; k < j; k++) { if (s[i + k - j + 1] != s[k]) return false; ...
#include <bits/stdc++.h> using namespace std; string S; set<string> answer; void izomorphism1(string &s) { swap(s[0], s[3]); swap(s[1], s[3]); swap(s[2], s[3]); } void izomorphism2(string &s) { swap(s[1], s[4]); swap(s[3], s[5]); swap(s[4], s[5]); } void izomorphism3(string &s) {...
#include <bits/stdc++.h> const unsigned long long maxn = 70; unsigned long long n, flg, KKK, ans; unsigned long long f[maxn], mul10[maxn], cycle[maxn], a[maxn]; struct matrix { unsigned long long len, wid; unsigned long long mt[3][3]; } pre[14][45]; inline unsigned long long min(unsigned long long a...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int main() { int n, m; cin >> n >> m; int now1 = 0; for (int i = 0; i < n; i++) { int c, t; cin >> c >> t; now1 += c * t; mp[now1] = 1; } map<int, int>::iterator it = mp.begin(); int now = 0; fo...
#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; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c =...
#include <bits/stdc++.h> struct node { int x, y; int dir, len; } arr[1100 * 1100], st[1100]; int n, m, tot, vis[1100][1100], cnt; int srow[1100][1100], scol[1100][1100]; int dir[4] = {1, -1, -1, 1}; char mmap[1100][1100]; void Initial() { int i, j, k; for (i = 1; i <= n; ++i) for (j ...
#include <bits/stdc++.h> using namespace std; const int N = 2000 + 5; int a[N], b[N]; bool mark[N]; vector<int> ch; int main() { int n, m, mn, ans = 0; cin >> n >> m; mn = n / m; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] <= m && !mark[a[i]]) { b[a[i]]++; ...
#include <bits/stdc++.h> const unsigned long long inf = 1LL << 61; const double eps = 1e-5; using namespace std; bool cmp(int a, int b) { return a > b; } string itoa(long long a) { string t = ; while (a > 0) { t += (char)(a % 10 + 0 ); a /= 10; } string s = ; for (int i = ...
#include <bits/stdc++.h> using namespace std; int a[100005]; int ans[100005]; string s[100005]; map<string, int> h; vector<pair<int, int> > v; string res[6] = { S , M , L , XL , XXL , XXXL }; int main() { memset(ans, -1, sizeof(ans)); ios_base::sync_with_stdio(false); cin.tie(NULL); ...
#include <bits/stdc++.h> using namespace std; int a[103], n, x, y, m, ans; int main() { cin >> x >> y >> n; m = x * y; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) { int x, j; cin >> x; for (j = 0; j < n; j++) { if (a[j] == x) break; } ...
#include <bits/stdc++.h> using namespace std; void runcase() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int changes = 0; k--; for (int i = 1; i < n; i++) if (a[i] != a[i - 1]) changes++; int ans = 0; if (k == 0) { if (changes...
#include <bits/stdc++.h> using namespace std; long long f[10]; void ge() { f[0] = 1; for (int i = 1; i <= 9; i++) { f[i] = f[i - 1] * 10; } } long long a[100005], b[100005]; int main() { ge(); int n, k; long long ans = 1; int i, j; scanf( %d%d , &n, &k); for (i = 0;...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<long long int> a(n); vector<long long int> mp(n + 1, 0); for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } vector<long long int> ans(n + 1); priority_queue<pair<long long, long lon...
#include <bits/stdc++.h> using namespace std; vector<int> in[101000]; int n, m, k, curt; int up[101000], t[101000], tout[101000], ans[101000]; int jmp[101000][20]; char used[101000]; void dfs(int v, int p) { if (used[v]) return; used[v] = 1; t[v] = curt++; up[v] = t[v]; for (unsigned i...
#include <bits/stdc++.h> using namespace std; int main() { double x, y, r, x1, y1; cin >> r >> x >> y >> x1 >> y1; double diam = 2 * r; double dist = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)); int q = 0; if (dist == 0) { cout << 0 << endl; } else { while (dist >= diam) ...
#include <bits/stdc++.h> const int mod = 1e9 + 7; const int MAX = 1e5 + 7; using namespace std; string st = fedabc ; void solve(unsigned long long n, char c) { n--; unsigned long long res = 16LL * (n / 4LL); if (n % 2) res += 7; res += st.find(c) + 1; cout << res; } void mysolve(unsig...
#include <bits/stdc++.h> using namespace std; int ar[1002][1002]; char buf[20]; int main() { int n, m, k, w; int res = 0; vector<pair<int, int> > r; scanf( %d %d %d %d n , &n, &m, &k, &w); vector<vector<string> > f(k); for (int i = 0; i < k; i++) { for (int j = 0; j < n; j++) { ...
#include <bits/stdc++.h> using namespace std; size_t ham_dist(const string &a, const string &b) { size_t ct = 0; for (size_t i = 0; i < a.size(); ++i) if (a[i] != b[i]) ++ct; return ct; } string opp(const string &a) { string r = ; for (size_t i = 0; i < a.size(); ++i) r += (a[i] == ...
#include <bits/stdc++.h> using namespace std; int main() { int n, num; cin >> n; if (n % 2 == 0) { num = n / 2; cout << num << endl; for (int i = 0; i < num; i++) { cout << 2 ; } } else { num = ((n - 3) / 2) + 1; cout << num << endl; for (int i = 0...
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> data(n + 1); for (int i = 1; i <= n; i++) cin >> data[i]; int i = 1, j = n; while (j > i && data[j] == data[1]) j--; while (i < j && data[i + 1] == data[1])...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n = ...
// “Alhamdulillah for Everything” #include<bits/stdc++.h> using namespace std; #define pai acos(-1) #define ff first #define ss second #define ll long long #define pb push_back #define mp ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T POW(T B, T P) { if (P == 0) return 1; if (P & 1) return B * POW(B, P - 1); else return SQR(POW(B, P / 2)); } template <typename T> inline T ModInv(T b, T m) { return BigMod(b, m - 2, m); } template <...
#include <bits/stdc++.h> const int maxn = 1025; const int maxm = 10; using namespace std; int main() { int n; string s; cin >> n; cin >> s; int ans1 = 0, ans2 = 0; int cnt1 = 0; int f = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == ( ) { f = 1; ans1...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (abs(n - k) == 1 || ((n - k) == 0 && n > 0 && k > 0)) { cout << YES ; } else cout << NO ; }
#include <bits/stdc++.h> int main() { long long n, k; std::cin >> n >> k; long long c = std::max(n - 2 * k, 0LL); std::cout << n * (n - 1) / 2 - c * (c - 1) / 2 << n ; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, q; int arr[110][110], r[10010], c[10010], v[10010], t[10010]; int main() { scanf( %d , &n), scanf( %d , &m), scanf( %d , &q); for (int z = 0; z < q; ++z) { scanf( %d , &t[z]); if (t[z] == 1) scanf( %d , &r[z]); if (t[z] == 2) scan...
#include <bits/stdc++.h> using namespace std; const int p = 1000000007; int K; struct Ma { int g[31][31]; Ma() { memset(g, 0, sizeof(g)); } int* operator[](int x) { return g[x]; } Ma operator*(const Ma& b) const { Ma res; for (int i = 0; i <= K; i++) for (int k = 0; k <= K; k...
#include <bits/stdc++.h> using namespace std; int n; int l[6][6], h[6][6], a[6][6]; int in[6]; int cost; int rec(int inNode, int outNode) { if (inNode == n - 1) return 0; int bestCost = -1; for (int f = l[inNode][outNode]; f <= h[inNode][outNode]; f++) { if (in[inNode] >= f && (outNode != ...
#include <bits/stdc++.h> using namespace std; long long n, m; long long side[300001]; vector<long long> edges[300001]; bool vis[300001]; bool res = 1; map<long long, long long> mp; long long dfs(long long u, long long s) { vis[u] = 1; side[u] = s; ++mp[s]; long long ret = 1; for (lon...
#include <bits/stdc++.h> using namespace std; const int MAXN = 112345; long long l[MAXN], r[MAXN]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) scanf( %lld %lld , l + i, r + i); sort(l, l + n); sort(r, r + n); long long ans = n; for (int i = 0; i < n; ++i) ans += max(l[i...
#include <bits/stdc++.h> using namespace std; const int NMax = 5e3 + 5; const int MMax = 1e3 + 5; int N, M; char input[NMax][MMax + 101]; short bit[NMax][MMax][2]; char solMin[MMax], solMax[MMax]; map<string, int> ID; struct elem { bool known; int op1, op2; char tor; } v[NMax]; int com...
#include <iostream> #include <bits/stdc++.h> #include<algorithm> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define ll long long #define MOD 1000000007 #define f first #define s second #define pb push_back #define nl n #define mem(arr, value) memset(arr, value,...
#include <bits/stdc++.h> using namespace std; int n, a[100005] = {0}, b[100005] = {0}, t, j, i, rn = 0, r[100005] = {0}, dis[100005] = {0}; vector<int> v; vector<int> ht; int main() { scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d , &a[i]); if (a[i] == 1) ht.push_back(i); ...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int *mas = new int[n], m = 0; for (int i = 0; i < n; i++) { scanf( %d , &mas[m++]); while (m > 1 && mas[m - 1] == mas[m - 2]) { mas[m - 2]++; m--; } } printf( %d n , m); for (int i = 0; i < m; i...
#include <bits/stdc++.h> using namespace std; const int N = 101000; const double eps = 1e-9, g = 9.8; double V, angle, ca, sa, Y, K, x, y; int i, j, k, l, m, n, o, p; inline int sn(double x) { return x < -eps ? -1 : x > eps ? 1 : 0; } inline double Sqr(double x) { return x * x; } struct Point { doub...
#include <bits/stdc++.h> using namespace std; int n; string s[500001]; char line[10]; int dp[30][30]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) { memset(line, 0, sizeof(line)); scanf( %s , line); s[i] = line; } memset(dp, 0, sizeof(dp)); for (int k = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; long long int a[n], b[n]; long long int sum = 0, suma = 0; for (int i = 0; i < n; i++) { cin >> a...
#include <bits/stdc++.h> using namespace std; int q[200010]; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int t; cin >> t; while (t--) { string s; cin >> s; int l = s.length(); if (l == 1) { if (s[0] == L ) { cout << 2 << endl; ...
#include <bits/stdc++.h> using namespace std; long long n, j, i, l, t, k, x, y; string s, a[10000001]; int main() { cin >> n >> s; for (i = 1; i < n; i++) for (j = 0; j < n - i; j++) { t++; for (l = 0; l <= i; l++) { a[t] += s[j + l]; } } for (i = 1; i <...
#include <bits/stdc++.h> using namespace std; const int N = 5005; int gcd[N]; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } vector<int> primes; void Calc() { for (int i = 2; i * i <= 1000000000; i++) { bool is_prime = true; for (int p : primes) { if (p * p > i) { ...
#include <bits/stdc++.h> using namespace std; void expand(int); int main() { int num; cin >> num; expand(num); cout << n ; } void expand(int value) { const char* const ones[20] = { zero , one , two , three , four , five , six ...
#include <bits/stdc++.h> #ifdef LOCAL #include debuger.hpp #else #define DUMP(...) 1145141919810 #define CHECK(...) (__VA_ARGS__) #endif const int kN = 200000 + 5; const int INF = 0x3f3f3f3f; std::vector<int> edges[kN]; int n, q; int header[kN],dfn[kN],tim,parent[kN],sz[kN]; int depth[kN]; ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, a[N], ans[N], cnt, x, y; bool Ok = 0; int main() { cin >> n; for (int i = 0; i <= n; i++) { cin >> a[i]; if (i) Ok |= (a[i] > 1 && a[i - 1] > 1); } if (!Ok) { cout << perfect ; } else { cout...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int counter = 0; for (int i = 0; i < n; i++) { int j = 0; for (j = i + 1; j < n; j++) { if (s[j] == s[i]) counter++; else { break; } }...
#include <bits/stdc++.h> using namespace std; int a[250]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { int N = 250; for (int j = 0; j < N; j++) scanf( %d , a + j); double M = 0; for (int j = 0; j < N; j++) M += a[j]; M /= N; double v = 0; ...
#include <bits/stdc++.h> using namespace std; int bv[7][9] = {{}, {4}, {2, 6}, {2, 4, 6}, {0, 2, 6, 8}, {0, 2, 4, 6, 8}, {0, 2, 3, 5, 6, 8}}; int bh[7][9] = {{}, {4}, {0,...
#include <bits/stdc++.h> #define lo long long #define KKH 1546C #define fi first #define se second #define BIT(x,k) (((x)>>(k-1))&1) #define rs(x,a) memset(x,(a),sizeof x) #define off(x,k) ((x)^(1<<(k-1))) using namespace std; void START() { #ifdef toilagun2004 freopen(KKH .inp , r ,st...
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000000000000LL; long long ff(long long a, long long b, long long c) { if ((a + b) % 2 != 0) return INF; long long x = (a + b) / 2; if (a < b) swap(a, b); long long y = 0, z = (a - b) / 2; return x + y + z; } int mai...
#include<bits/stdc++.h> using namespace std; typedef long long int ll; void solve() { ll n; cin>>n; vector<ll> v; for(int i=0;i<n;i++) { ll x; cin>>x; v.push_back(x); } sort(v.begin(),v.end()); ll cost=0; for(ll i=2; i<n; ++i) { ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long poww(long long num, long long p) { long long ret = 1; while (p != 0) { if (p & 1) { ret = (ret * num) % mod; } num = (num * num) % mod; p = p >> 1; } return ret; } int main() { ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; long long a[1010000]; long long s[1010000]; memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) { scanf( %lld , a + i); } vector<pair<long long, long long>> pll; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a1, t1, a2, t2, n1 = 0, n2 = 0; cin >> n >> a1 >> a2 >> t1 >> t2; n1 += t1 * 2; n2 += t2 * 2; n1 += a1 * n; n2 += a2 * n; if (n1 > n2) cout << Second ; if (n2 > n1) cout << First ; if (n1 == n2) cout << Friendsh...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; long long DP[N]; int n; int a[N]; int freq[N]; long long solve(int num) { if (num < 1) return 0; if (DP[num] != -1) return DP[num]; return DP[num] = max((long long)num * freq[num] + solve(num - 2), solve(num - ...
#include <bits/stdc++.h> using namespace std; int n, m; bool reachable(vector<set<int>> g, int u, int v) { if (g[u].find(v) == g[u].end()) { for (auto x : g[u]) { if (g[x].find(v) != g[x].end()) return true; } } else { return true; } return false; } int main() { i...
#include <bits/stdc++.h> using namespace std; long long parent[200001], Size[200001]; long long find_set(long long x) { if (x == parent[x]) return parent[x]; return parent[x] = find_set(parent[x]); } void Union(long long x, long long y) { x = find_set(x); y = find_set(y); if (Size[x] > Siz...
#include <bits/stdc++.h> const int MNN = 2e3 + 1; using namespace std; int n, b[MNN][MNN], mx; bool used[MNN]; int main() { cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> b[i][j]; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= ...
#include <bits/stdc++.h> using namespace std; template <typename G> struct triple { G first, second, T; }; struct BIT { vector<int> v; BIT(int n) : v(n + 10) {} void upd(int p) { for (; p < v.size(); p += (p & (-p))) ++v[p]; } int query(int p) { int x = 0; for (; p > ...
#include <bits/stdc++.h> using namespace std; const int N = 200010; vector<int> t[N], f[2], f0[2]; int n, c0[N * 2], lim[N]; void add(int x) { for (; x <= n * 2; x += (x & (-x))) c0[x]++; } int query(int x) { int ret = 0; for (; x; x -= (x & (-x))) ret += c0[x]; return ret; } void up(i...
#include <bits/stdc++.h> using namespace std; const int N = 100005; bool prime[N + 5]; int vis[11111]; int main() { int tc = 1; cin >> tc; while (tc--) { int n; int m; cin >> n >> m; int ara[n + 1]; for (int i = 0; i < n; i++) { cin >> ara[i]; } if...
#include <bits/stdc++.h> using namespace std; template <typename flow_t = int, typename cost_t = int> struct mcSFlow { struct Edge { cost_t c; flow_t f; int to, rev; Edge(int _to, cost_t _c, flow_t _f, int _rev) : c(_c), f(_f), to(_to), rev(_rev) {} }; const cost_t IN...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; int n, a, b, cur, h[maxn], nxt[maxn * 2], p[maxn * 2]; void add_edge(int x, int y) { cur++; nxt[cur] = h[x]; h[x] = cur; p[cur] = y; } int tid, dfn[maxn], dep[maxn], lg[maxn], fa[maxn][25]; void dfs(int x, int f) { ...
#include <bits/stdc++.h> using namespace std; long long int N, M, Max = 0, Maxj = 0, A[1000][1000], arr[1000][1] = {}; int main() { cin >> N >> M; for (int i = 0; i < M; i++) { Max = -1; for (int j = 0; j < N; j++) { cin >> A[i][j]; if (Max < A[i][j]) { Max = A[i][j];...
#include <bits/stdc++.h> using namespace std; const long long N = 2 * 1e5 + 100; long long n, k, s, t, c[N], v[N], g[N], d[N], sum[N]; inline long long read() { long long f = 1, x = 0; char s = getchar(); while (s < 0 || s > 9 ) { if (s == - ) f = -1; s = getchar(); } while (...
#include bits/stdc++.h using namespace std; int main() { ios::sync_with_stdio (0) ; cin.tie (0) ; int T ; cin >> T ; while ( T-- ) { long x, y; cin >> x >> y ; cout << x - 1 << << y << endl ; } }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n >> m; long long vmax = n - (m - 1); long long kmax = vmax * (vmax - 1) / 2; long long vmin = n / m; long long vmi...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d, maxi1, maxi2; cin >> a >> b >> c >> d; maxi1 = max(((3 * a) / 10), (a - ((a / 250) * c))); maxi2 = max(((3 * b) / 10), (b - ((b / 250) * d))); if (maxi1 == maxi2) { cout << Tie n ; } else if (maxi2 > maxi...