func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; struct BIT { long long T[1000100]; long long ALL; BIT() { ALL = 0; } void add(int pos, long long w) { ++pos; ALL += w; for (; pos < 1000100; pos += (pos & (-pos))) T[pos] += w; } long long all_from(int pos) { long long ret...
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; char a[2000010], b[2000010]; int main() { int n; int i; int x, y, z; int p, q; while (~scanf( %d %s %s , &n, a, b)) { x = y = z = 0; for (i = 0; i < 2 * n; i++) { if (a[i] == 1 && b[i] == 1 ) {...
#include <bits/stdc++.h> using namespace std; int T; string hxt[16]; int main() { cin >> T; while (T--) { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> hxt[i]; bool iif = false; for (int i = 0; i < m; i++) { char x = hxt[1][i]; for (char j = ...
#include <bits/stdc++.h> using namespace std; int main() { vector<string> v; for (int i = 0; i < 3; i++) { string s; cin >> s; v.push_back(s); } vector<string> so; vector<string> po; vector<string> mo; for (int i = 0; i < v.size(); i++) { if (v[i][1] == s ) ...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 2; int n; int a[N]; map<int, int> m; map<pair<int, int>, bool> checked; int main() { cin >> n; int zero = 0; for (int i = 0; i < n; ++i) { scanf( %d , a + i); if (!a[i]) zero++; ; m[a[i]]++; } sor...
#include <bits/stdc++.h> using namespace std; const int maxn = 4005; vector<int> v[maxn]; int vis[maxn][maxn]; int main(void) { int n, m, ans = maxn; memset(vis, 0, sizeof(vis)); scanf( %d%d , &n, &m); for (int i = 0; i < m; i++) { int x, y; scanf( %d%d , &x, &y); v[x].push_b...
#include <bits/stdc++.h> using namespace std; int T, N; int arr[500005]; stack<int> stk; vector<pair<int, int>> v; int main() { cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> T; while (T--) { cin >> N; bool pos = 1; while (stk.size()) { stk.pop(); ...
#include <bits/stdc++.h> using namespace std; namespace io { const int __SIZE = (1 << 21) + 1; char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof; inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), ...
#include <bits/stdc++.h> using namespace std; string s; int yekdast(char c, int l, int r) { int ans = 0; for (int i = l; i <= r; i++) { if (s[i] != c) ans++; } return ans; } int check(char c, int l, int r) { if ((r - l) > 1) { int mid1 = (floor((l * 1.0 + r * 1.0) / 2.0)), ...
#include <bits/stdc++.h> const int N = 1e5 + 2, p = 1e9 + 7; int siz[N], f[N]; int n, m, x, y, z, i, c; inline void read(int &x) { c = getchar(); while ((c < 48) || (c > 57)) c = getchar(); x = c ^ 48; c = getchar(); while ((c >= 48) && (c <= 57)) { x = x * 10 + (c ^ 48); c = get...
#include <bits/stdc++.h> using namespace std; int n, m; char name[2000], part[2000000]; int work() { int p = 0; for (int i = 0; i < m; i++) { if (part[i] == name[p]) p++; if (p == n) return i; } return m; } int main() { scanf( %s , name); scanf( %s , part); n = strlen...
#include <bits/stdc++.h> using namespace std; long long int power(int b, int pw) { long long int res = 1; for (int i = 1; i <= pw; i++) { res = res * b; } return res; } long long int typ[1000000]; int main() { ios_base::sync_with_stdio(false); long long int n; cin >> n; f...
#include <bits/stdc++.h> using namespace std; const int N = 5010; int n, m; int pnt[N * 4], last; char tab[N][N], a[N][N]; int find(int x) { if (x != pnt[x]) pnt[x] = find(pnt[x]); return pnt[x]; } int id(int x, int y, int d) { return (x * m + y) * 4 + d; } void add(int x, int y) { pnt[id(...
#include <bits/stdc++.h> using namespace std; vector<long long> adj[100005]; long long a[100005]; long long col; bool ok; bool dfs(long long v, long long par) { ok &= (col == a[v]); for (auto i : adj[v]) { if (i != par) dfs(i, v); } } bool fn(long long v) { bool res = 1; for (a...
#include <bits/stdc++.h> using namespace std; int R, r, k; int main() { int T; scanf( %d , &T); while (T--) { scanf( %d%d%d , &R, &r, &k); double a = R, b = r; printf( %lf n , 1 / (1 / (a - b) + k * k * (a - b) / a / b)); } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool checkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool checkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int MAXN = 2600 / 2; const int MAXM = 51; const int ...
#include <bits/stdc++.h> using namespace std; const int N = 300005; priority_queue<pair<long long, int> > Q; int h[N], a[N]; int n, m, k, p; bool check(long long lim) { static long long now[N]; for (int i = 1; i <= n; i++) now[i] = lim; while (!Q.empty()) Q.pop(); for (int i = 1; i <= n; i++...
#include <bits/stdc++.h> using namespace std; const int N = (int)3e5 + 5; const int K = (int)3e5 + 5; vector<pair<int, int>> adj[N]; queue<pair<int, int>> q; bool visited[N]; int res[300005]; int n; int k; int d; int main() { scanf( %d%d%d , &n, &k, &d); for (int i = 0; i < k; i++) { ...
#include <bits/stdc++.h> using namespace std; int cnt, n; string ss; int main() { cin >> n >> ss; for (int i = 0; i < n; i++) { if (i < n - 1 && ((ss[i] == R && ss[i + 1] == U ) || (ss[i] == U && ss[i + 1] == R ))) { i++; cnt++; } else cn...
#include <bits/stdc++.h> using namespace std; int main() { int n, s, i, x, y; cin >> n >> s; int sol = 100; int f = 1; for (i = 0; i < n; i++) { cin >> x >> y; if (x < s) { if (y) { sol = min(sol, y); } } if (x < s || (x == s && y == 0)) { ...
#include <bits/stdc++.h> using namespace std; long long l, r, ans = 0; int main() { cin >> l >> r; for (long long i = 1; i <= r; i *= 2) { for (long long j = 1; j <= r; j *= 3) { if (i * j >= l && i * j <= r) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using vll = vector<long long>; template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>; template <class T> ...
#include <bits/stdc++.h> using namespace std; typedef pair<long long, long long> ll; typedef vector<long long> vl; typedef vector<ll> vll; typedef vector<vl> vvl; template <typename T> ostream &operator<<(ostream &o, vector<T> v) { if (v.size() > 0) o << v[0]; for (unsigned i = 1; i < v.size(); i+...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int maxn = 100010; const int maxbit = 18; const int sz = 1500; inline int read() { int x = 0, f = 1; char ch = 0; for (; !isdigit(ch); ch = getchar()) if (ch == - ) f = -1; for (; isdigit(ch); ch = getchar()...
#include <bits/stdc++.h> using namespace std; vector<int> myvec[100001]; set<int> myset[2]; set<int>::iterator it; int mark[100001]; bool isbipartite(int src) { int color[100001]; memset(color, -1, sizeof(color)); queue<int> q; q.push(src); mark[src] = 1; color[src] = 1; myset[co...
#include <bits/stdc++.h> using namespace std; int timeTook[50010][10]; int timeSpent[50010]; int main() { int numOfPictures, numOfPainters; scanf( %d %d , &numOfPictures, &numOfPainters); for (int i = 0; i < numOfPictures; i++) { for (int j = 0; j < numOfPainters; j++) { scanf( %d , &t...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; string s; int a[maxn], tot, n; int main() { while (cin >> n) { memset(a, 0, sizeof a); tot = 0; cin >> s; string temp = s; if (n == 1) { puts( 0 ); continue; } for (int i = n -...
#include <bits/stdc++.h> using namespace std; int main() { int a = 0, b = 0, c = 0, d = 0, n, temp, dl; cin >> n; for (int i = 0; i <= n; i++) { if (i < n) { cin >> temp; } else { temp = max(a, d) + 1; } dl = temp - a; if (dl != 1 && dl != -1) { if (...
#include <bits/stdc++.h> using namespace std; long long a, b, T, q, w, e, d[100001], v[100001], t[100001], B = 130; int main() { scanf( %lld%lld , &a, &b); for (int i = 1; i <= a; i++) scanf( %lld , &d[i]), v[d[i]] = i, t[i] = i; for (int i = 1; i <= a; i++) for (int j = 1; j <= B; j++) t[i] = d...
#include <bits/stdc++.h> using namespace std; int n, k, t, s; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k; if (n < 3 * k) return cout << -1, 0; for (int i = 0; i < n; i++) if (i / k % 2 == 1) cout << (1 + i) % k + 1 << ; else ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out << a.first << << a.second;...
#include <bits/stdc++.h> #define For(i, a, b) for (int i = (a), _##i = (b); i < _##i; ++i) #define FOR(i, a, b) for (int i = (a), _##i = (b); i <= _##i; ++i) #define Forr(i, a, b) for (int i = (a), _##i = (b); i > _##i; --i) #define FORR(i, a, b) for (int i = (a), _##i = (b); i >= _##i; --i) #define all(a) a....
#include <bits/stdc++.h> using namespace std; int ag[9][2], cg[9][2]; int main() { int n, m, k, s, t, t2, ans = 0; scanf( %d %d %d %d , &n, &m, &k, &s); memset(cg, 0x3f3f3f3f, sizeof(cg)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { scanf( %d , &t); ag[t - 1][0]...
#include<iostream> #include<vector> #include<queue> #include<cstring> #include<cmath> #include<map> #include<set> #include<cstdio> #include<algorithm> #define debug(a) cout<<#a<< = <<a<<endl; using namespace std; const int maxn=1e3+100; typedef long long LL; LL a[maxn]; int main(void) { ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { long long int n; cin >> n; if (n == 1 || n == 2) { cout << n << endl; return 0; } if (n % 2 == 1) { cout << (n * (n - 1) * (n - 2)) << endl; return 0; } if (n == 4 || n == 6) { ...
#include <bits/stdc++.h> using namespace std; long long a, b, t, z; bool dfs(long long x, long long y) { if (x < y) swap(x, y); if (!y) return 0; if (!dfs(y, x % y)) return 1; z = x / y; if (y & 1) return (z & 1) ^ 1; return z % (y + 1) & 1 ^ 1; } signed main() { scanf( %lld , &t);...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); cout.tie(0); string s, t, b; int n; vector<pair<char, char>> v; set<char> z; bool fine = false; char a[26]; for (int i = 0; i < 26; i++) a[i] = @ ; cin >> s >> t; for (int ...
#include <bits/stdc++.h> #pragma GCC diagnostic ignored -Wunused-result #pragma GCC diagnostic ignored -Wsign-compare using namespace std; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int test_case = 1; cin >> test_case; while (test_case--) { solve(...
#include <bits/stdc++.h> using namespace std; const int N = 200002; int n, x1, x2, p[N]; pair<int, int> a[N]; int i1, i2; bool solve() { i1 = i2 = -1; for (int i = n; i >= 1; --i) { if (a[i].first * (n - i + 1) >= x1) { i1 = i; break; } } for (int i = i1 - 1; i >=...
#include <bits/stdc++.h> using namespace std; const int N = 1E5 + 9; vector<int> g[N]; int tin[N]; int tout[N]; int sz[N]; int tt; int toys[N]; bool root[N]; void dfs(int v) { tin[v] = tt++; sz[v] = 1; for (auto i : g[v]) { dfs(i); sz[v] += sz[i]; } tout[v] = tt++; ...
#include <bits/stdc++.h> using namespace std; int main() { int sum, a, b, c, ans = 0; cin >> sum >> a >> b >> c; for (int i = 0; i <= a; i += 2) for (int j = 0; j <= c; ++j) if (sum - i / 2 - 2 * j <= b && sum - i / 2 - 2 * j >= 0) ans++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int z = 1000000007; int main() { int n; cin >> n; if (n % 3 == 0) cout << 1 << 1 << (n - 2); else if (n % 3 == 1) cout << 1 << 1 << (n - 2); else cout << 1 << 2 << (n - 3); re...
#include <bits/stdc++.h> using namespace std; const int N = 128; struct Matrix { double a[N][N]; Matrix() { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) a[i][j] = (i == j ? 1 : 0); } Matrix operator*(const Matrix &A) const { Matrix R = Matrix(); for (int i = 0;...
#include <bits/stdc++.h> using namespace std; int main() { int t, b, p, f, h, c; cin >> t; vector<int> arr(t); for (int i = 0; i < t; ++i) { cin >> b >> p >> f; cin >> h >> c; if (h > c) { while (b >= 2 && p > 0) { arr[i] = arr[i] + h; b = b - 2; ...
#include <bits/stdc++.h> using namespace std; int A[2222][2]; int main() { int n, k, x, a, c, s, i; bool j; scanf( %d%d%d , &n, &k, &x); for (i = 0; i < n; i++) { scanf( %d , &a); A[a][0]++; } for (j = 0; k--; j = !j) { for (i = s = 0; i <= 2047; i++) { c = (s + A...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; void solve() { long long int n, k; cin >> n >> k; if (n / 2 > k or n == 1) { if (k == 0 and n == 1) { cout << 1 << n ; return; } cout << -1 << n ; return; } else { vec...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const long long MOD = 1000000007; const int inf = 1 << 30; const long long linf = 1LL << 60; const double PI = 3.14159265358979323846; int n, k; char s[100000]; vector<int> v[2]; int main() { scanf( %d%d , &n, &k); for (i...
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void...
#include <bits/stdc++.h> using namespace std; void inputOutput() {} signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; inputOutput(); string yelo = AHIMOTUVWXY ; string s; cin >> s; long long int n = s.length(); for (long long int i = 0; i <...
#include <bits/stdc++.h> using namespace std; const int N = 100, V = 100; struct bottle { int a, b; bool operator<(const bottle &bt) const { return b > bt.b; } } bot[N + 1]; int dp[N + 1][N * V + 1]; int main() { int n, shui = 0; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scan...
#include <bits/stdc++.h> using namespace std; vector<int> g[300001]; bool mark[300001]; bool vis[300001]; int road_count = 0; int main(void) { int n, m; cin >> n >> m; int a, b; for (int i = 0; i < m; i++) { cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; struct node { int id, next; node() {} node(int a, int b) { id = a; next = b; } }; struct Brige { int x, y; } brige[maxn]; vector<int> v[maxn], g[maxn]; vector<node> q[maxn]; int dfn[maxn], low[maxn];...
#include <bits/stdc++.h> using namespace std; using INT = long long; int a[200100], b[200100]; map<int, int> mp[2]; int arr[200100]; map<int, int> vst; int main() { int n, st; cin >> n >> st; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } int m, ed; cin >> m >> ed; ...
#include <bits/stdc++.h> using namespace std; int main() { long long int x; cin >> x; cout << x / 2520; }
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T a) { return a < 0 ? -a : a; } template <typename T> T sqr(T a) { return a * a; } const int INF = (int)1e9; const long double EPS = 1e-9; const long double PI = 3.1415926535897932384626433832795; const int N = 1000;...
#include <bits/stdc++.h> using namespace std; int main() { set<char> deputi; vector<vector<char> > off; int m, n; char boss; cin >> n >> m >> boss; off.resize(n); for (int i = 0; i < n; i++) off[i].resize(m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) do { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int num : a) { m -= num; } if (m != 0) cout << NO << en...
#include <bits/stdc++.h> using namespace std; long long int n, t; int main() { cin >> n >> t; long long int a = (n - t) / 2; for (int i = 1; i <= n; i++) { cout << !((i) % (a + 1)); } }
#include <bits/stdc++.h> using namespace std; int main() { long long n, res = 0, cp = 0, cn = 0, cz = 0; cin >> n; vector<long long> arr(n); for (long long i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] > 0) cp++; else if (arr[i] < 0) cn++; else cz++; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; for (int i = 0; i < t; ++i) { int n; cin >> n; cout ...
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; const int N_ = (int)1e6 + 2; long long Hash_a[N_]; long long Hash_b[N_]; long long pow26[N_]; string a, b; long long n; long long get_hash_a(long long x, long long y) { return (Hash_a[y] - Hash_a[x - 1] * pow26[y - x + 1] ...
#include <bits/stdc++.h> using namespace std; inline void chkmax(long long &a, long long b) { if (a < b) a = b; } inline void chkmin(long long &a, long long b) { if (a > b) a = b; } inline long long read() { long long a = 0, fh = 1; char c = getchar(); while (c > 9 || c < 0 ) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, p, ans(0); cin >> n; map<string, int> mp; string s; while (n--) { cin >> s; mp[s]++; } for (auto x : mp) { if (x.first == Tetrahedron ) p = 4; else if (x.first == Cube ) p = 6; ...
#include <bits/stdc++.h> using namespace std; struct ele { long long a, b; }; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { long long n; cin >> n; struct ele arr[n]; bool issorted =...
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define Test int T;cin>>T;while(T--) #define PI acos(-1) #define endl n #define fx(x) fixed<<setprecision(x) #define sz(s) (int)s.size() #define all(v) (v).begin(),(v).end() #define allr(v) (v).rbegin(),(v).r...
#include <bits/stdc++.h> using namespace std; int main() { int qnt, time, felicity, time_to_eat, best = -999999999; cin >> qnt >> time; for (int i = 0; i < qnt; i++) { cin >> felicity >> time_to_eat; if (time_to_eat <= time && felicity > best) { best = felicity; } else if (time...
#include <bits/stdc++.h> int va[100000], vb[100000]; int main() { int na, nb, k, m, i, j; scanf( %d%d%d%d , &na, &nb, &k, &m); for (i = 0; i < na; i++) scanf( %d , &va[i]); for (i = 0; i < nb; i++) scanf( %d , &vb[i]); if (va[k - 1] < vb[nb - m]) printf( YES ); else printf( NO );...
#include <bits/stdc++.h> using namespace std; vector<long long> erat; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long nd(long long a) { map<long long, long long> m; while (a != 1) { ++m[erat[a]]; a /= erat[a]; } long long co...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; long long x[maxn], y[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long n; cin >> n; long long s = 0, sx = 0, sy = 0; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; long long max(long long a, long long b) { return a > b ? a : b; } struct SegmentTree { public: SegmentTree() { null_value = -INF; null_modifier = 0; } void insert_data(vector<long long> values) { size = 1;...
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define ll unsigned int #define endl n #define mp make_pair #define hcf __gcd #define test cout<< hello ;...
#include <bits/stdc++.h> using uint = unsigned int; using cat = long long; using dbl = long double; constexpr dbl pi = 3.14159265358979323846; using namespace std; template <typename T> T abs(T x) { return (x < 0) ? (-x) : x; } cat pw(cat a, cat e, cat mod) { if (e <= 0) return 1; cat x = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; struct edg { int u, v, l, r; edg(int u = 0, int v = 0, int l = 0, int r = 0) : u(u), v(v), l(l), r(r) {} bool operator<(const edg &n1) const { return l > n1.l; } }; priority_queue<edg> q; vector<edg> adj[maxn][2]; int n, m...
#include<iostream> #include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define INF 100000007 #define MAX 1000000 #define nl n #define F first #define S second #define pb(a) push_back(a) typedef vector<ll> vi; typedef priority_queue<ll , vector<ll> , great...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; namespace Xrocks {} using namespace Xrocks; namespace Xrocks { class in { } user_input; class out { } output; in& operator>>(in& X, int& Y) { scanf( %d , &Y); return X; } in& operator>>(in& X, char* Y) { sc...
#include <bits/stdc++.h> 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...); } template <class T, class R> ostream& operator<<(ostream...
#include <bits/stdc++.h> using ul = std::uint32_t; using li = std::int32_t; using ull = std::uint64_t; using ll = std::int64_t; using vul = std::vector<ul>; using vvul = std::vector<vul>; using vb = std::vector<bool>; using vvb = std::vector<vb>; using vvvb = std::vector<vvb>; using vull = std::vect...
#include <bits/stdc++.h> using namespace std; const int MaxN = 1000; int n, m; int cnt[MaxN + 5][MaxN + 5]; bool Check(int x, int y) { if (x < 0) return false; if (y < 0) return false; if (x > n) return false; if (y > n) return false; return true; } int main() { while (~scanf( %d%d...
#include <bits/stdc++.h> using namespace std; const int www = 9; const int Size = 10000; char buffer[Size]; int dr[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; const int inf = 0x0fffffff; const int size = 1000; int d[size]; int solution(int nTest) { int k, a, b; scanf( %d%d%d , &k, &a, &b); ...
#include <bits/stdc++.h> using namespace std; const int radix_len = 1e7 + 5; long long cnt[radix_len]; int main() { int n, k, a; ios_base::sync_with_stdio(false); cin >> n >> k; long long tot = 0; for (int i = (0), i_end_ = (n); i < i_end_; ++i) { cin >> a; cnt[a]++; tot +=...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; if (k < n / 2) { cout << -1; return 0; } if (n == 1) { if (k) cout << -1; else cout << 1; return 0; } int x = k - (n - 2) / 2; cout << x << << 2...
#include <bits/stdc++.h> using namespace std; int n, m, u, v, i, j, c[505], ca = 0, cb = 0, cc = 0, cnt, nt; int main() { cin >> n >> m; vector<int> g[505]; for (i = 0; i < 505; i++) c[i] = 0; for (i = 0; i < m; i++) { cin >> u >> v; g[u].push_back(v); g[v].push_back(u); if...
#include <bits/stdc++.h> using namespace std; map<string, int> Map; string s[181], sn; int n, i; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> sn; cin >> n; s[1] = January ; s[2] = February ; s[3] = March ; s[4] = April ; s[5] = May ; s[6] = June ; ...
#include <bits/stdc++.h> using namespace std; int n, k, h; struct Node { int m, v; int id; bool operator<(const Node &x) const { if (m != x.m) return m < x.m; return v < x.v; } } q[100005]; bool ok(double times) { int i, j; for (j = 1, i = 0; i < n; i++) { if (q[i].v ...
#include <bits/stdc++.h> int n, a[1000][1000]; int main() { for (int i = 1; i <= 100; i++) for (int j = 1; j <= 100; j++) a[i][j] = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) { int t, v; scanf( %d , &t); for (int j = 1; j <= t; j++) { scanf( %d , &v); a[i][v...
#include <bits/stdc++.h> using namespace std; int N[10]; string shirt[5] = { S , M , L , XL , XXL }; map<string, int> mp; int main() { int K, i, d; for ((i) = 0; (i) < (int)(5); (i)++) cin >> N[i]; cin >> K; for ((i) = 0; (i) < (int)(5); (i)++) mp[shirt[i]] = i; for ((i) = 0; (i) < (in...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T Abs(T a) { return a > 0 ? a : -a; } template <typename T> inline T sqr(T a) { return a * a; } template <typename T> inline void relaxMin(T &a, T b) { if (b < a) a = b; } template <typename T> inline void rel...
#include <bits/stdc++.h> using namespace std; int n, m; void update(int *c, int x, int v) { while (x <= m) { c[x] += v; x += x & -x; } } long long sum(int *c, int x) { long long ret = 0; while (x > 0) { ret += c[x]; x -= x & -x; } return ret; } long long cal...
#include <bits/stdc++.h> int main() { int t; scanf( %d , &t); int A[t]; for (int i = 0; i < t; i++) { scanf( %d , &A[i]); } int count = 1, max = 1; for (int i = 0; i < t - 1; i++) { if (A[i] <= A[i + 1]) { count++; if (max <= count) max = count; } else { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *thi...
#include <bits/stdc++.h> using namespace std; long long pow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) { res = (res * a) % 1000000007; } b >>= 1; a = (a * a) % 1000000007; } return res; } int main() { long long n, k; cin >> n >> ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1]; int b[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; b[a[i]] = i; } for (int i = 1; i <= n; i++) { cout << b[i] << ; } return 0; }
#include <bits/stdc++.h> using namespace std; void Yahia74() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); } const int N = 3e5 + 74, OO = 0x3f3f3f3f, MOD = (int)1e9 + 7; int main() { Yahia74(); long long n, d; cin >> n >> d; long long ans = n, c = 9, t = 10; while...
#include <bits/stdc++.h> int main() { long long n, p; scanf( %I64d , &n); if (n % 2 == 0 && n != 0) p = n + 1; else p = (n + 1) / 2; printf( %I64d , p); return 0; }
#include <bits/stdc++.h> using namespace std; bool isopen(char ch) { if (ch == < || ch == { || ch == ( || ch == [ ) return true; return false; } int main() { int k, sum = 0, ans = 0; string s; cin >> k >> s; int c[10] = {0}; for (long long int i = 0; i < s.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; void scan(int &x) { bool neg = false; register int c; x = 0; c = getchar(); if (c == - ) { neg = true; c = getchar(); } for (; (c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48; if (neg) x *= -1; } int m...
#include <bits/stdc++.h> using namespace std; int dy[] = {-1, 1, 0, 0}; int dx[] = {0, 0, -1, 1}; int n, m; char mp[1005][1005]; int k; pair<int, int> p[30]; int row[1005][1005]; int col[1005][1005]; pair<int, int> d[100005]; int return_dir(char dir) { if (dir == N ) return 0; else ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, b; cin >> n >> b; long long a[n + 1]; for (int i = 0; i < n; ++i) { cin >> a[i]; } a[n] = b; sort(a, a + n + 1); if (a[0] == b) { cout << a[n - 1] - a[0]; } else { if (a[n] == b) { c...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; long long int n, a[100005], dis[100005] = {0}, vis[100050] = {0}, cnt = 0; vector<pair<long long int, long long int> > v[100005]; void dfs(long long int s, long long int f) { vis[s] = 1; long long int i; for (i = 0; i...
#include <bits/stdc++.h> using namespace std; const int N = 100000; int p[N], u[N]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= k; i++) { int x; cin >> x; if (p[x] == 0) p[x] = i; u[x] = i; } long long rez = 0; for (int i = 1; i <= n; i++) { i...