func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int n, x, bac[maxn], a[maxn], b[maxn]; inline int read() { char ch = getchar(); int u = 0, f = 1; while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { u = u * 10 + ch - ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; pair<int, int> pt[N], q[2][N]; vector<int> E; int main() { int n, m, i, j; scanf( %d%d , &n, &m); for (i = 0; i < m; i++) { scanf( %d%d , &pt[i].first, &pt[i].second); } sort(pt, pt + m); int w[2], pre = 0, now =...
#include <bits/stdc++.h> using namespace std; bitset<101> b; int number; vector<int> primes; void sieve() { b.set(); b[0] = 0; b[1] = 1; for (int i = 2; i <= number; i++) { if (b[i] == 1) { primes.push_back(i); for (int j = i * i; j <= number; j += i) b[j] = 0; } ...
#include <bits/stdc++.h> using namespace std; const int N = 300000 + 10; struct Node { int x, y; Node(int x, int y) : x(x), y(y) {} bool operator<(const Node& rhs) const { return x < rhs.x || (x == rhs.x && y < rhs.y); } }; int n, m, size[N], color[N], col = 1; vector<int> G[N], grp[N]...
#include <bits/stdc++.h> using namespace std; int GCD(int a, int b) { if (a == 0) return b; else return GCD(b % a, a); } int main() { int v[2], n, i = 0; cin >> v[0] >> v[1] >> n; while (n >= 0) { int k = GCD(n, v[i]); n -= k; i = !i; } cout << i << endl...
#include <bits/stdc++.h> using namespace std; const int max_n = 105; int n; int a[max_n]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); vector<int> V; sort(a, a + n); for (int nb = 1; nb <= n; nb++) { V.clear(); for (int i = 0; i < nb; i++) V.pus...
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 2, M = 1e5 + 5; int n, m, k, par[N]; vector<int> vec; struct edge { int u, v, i; long double w; } e[M]; int getPar(int u) { return ~par[u] ? par[u] = getPar(par[u]) : u; } bool check(double x) { for (int i = 0; i < m; i++) e[i...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; struct row { long long base, limit; row(long long t = 0, long long d = 0) : base(t + d), limit(t) {} long long push(long long t) const { return t <= limit ? base : base + (t - limit); } row operator*(const row &o) cons...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long mod = 1e9 + 7; template <typename T> inline T gcd(T a, T b) { return !b ? a : gcd(b, a % b); } template <typename T> inline T q_pow(T a, T x) { T ans = 1, tmp = a; while (x) { if (x & 1) (ans *= tmp) ...
#include <bits/stdc++.h> char B[1 << 15], *S = B, *T = B; using namespace std; int n, k, ans = 2147483647; bool u[1001]; int f[2][250001]; inline int read() { int x = 0; char ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long k = 0; for (int i = 1; i < n + 1; i++) { long long h = i * i; for (int j = 1; j < i; j++) { double e = pow(h - j * j, 0.5); if ((int)e == e) { k++; } } } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; char s[maxn]; char ans[maxn]; int sum[maxn]; int n; int check() { for (int i = 0; i < n / 2;) { int l = i, r = n - 1 - i; if (sum[l] == sum[r]) i++; else if (sum[l] == sum[r] + 1 || sum[l] == sum[r] + 11)...
#include <bits/stdc++.h> using namespace std; long long gcd(long long n1, long long n2) { if (!n1) return n2; if (!n2) return n1; if (n1 % n2 == 0) return n2; return gcd(n2, n1 % n2); } long long powmod(long long base, long long exponent) { base %= 1000000007; long long ans = 1; whil...
#include <bits/stdc++.h> using namespace std; const long long N = 1e3 + 5; const long long Q = 3e5 + 5; char w[N][N]; char x[Q]; long long l[Q], r[Q]; long long u[Q], d[Q]; long long f[N][N]; long long c[N][N][26]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { c...
#include <bits/stdc++.h> using namespace std; template <class T> void dbs(string str, T t) { cerr << str << : << t << n ; } template <class T, class... S> void dbs(string str, T t, S... s) { long long idx = str.find( , ); cerr << str.substr(0, idx) << : << t << , ; dbs(str.substr...
#include <bits/stdc++.h> using namespace std; const long double PI = 3.1415926535897932384626433832795; template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p) { out << ( << p.first << , << p.second << ) ; return out; } template <typename T> ostream& operator...
#include <bits/stdc++.h> using namespace std; bool flag; vector<vector<int> > g; map<int, bool> used; void dfs(int x, int last) { used[x] = true; for (auto to : g[x]) { if (!used[to]) { dfs(to, x); } else { if (last != to) { flag = false; return; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; int T[MAXN]; int ids[MAXN]; int n; int check(int a, int b) { vector<int> V(n); copy(T, T + n, V.begin()); int m = 0; for (int i = 0; i < V.size(); i++) { if (V[i] == -1) continue; if (V[i] < a || V[i] > b) contin...
#include <bits/stdc++.h> using namespace std; const int N = 138; int n, Ans, x, y, z, GG[N][N][5][5]; int main() { memset(GG, -63, sizeof(GG)); cin >> n; int i, j, k, p; for (i = 1; i <= n; ++i) { cin >> x >> y >> z; GG[i][i][z][x] = GG[i][i][x][z] = y; } for (i = n; i >= 1; ...
#include <bits/stdc++.h> using namespace std; long long n, k, ans = 34343434; vector<long long> a; vector<long long> b; int main() { cin >> n; for (int i = 0; i < n; i++) { long long x, y; cin >> x >> y; if (x == 1) a.push_back(y); else b.push_back(y); } ...
#include <bits/stdc++.h> using namespace std; const vector<int> dx = {-1, 0, 1, 0}; const vector<int> dy = {0, -1, 0, 1}; const int mod = (int)1e9 + 7; inline void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } inline void sub(int &x, int y) { x -= y; if (x < 0) x += mod; } inl...
#include <bits/stdc++.h> using namespace std; int main() { int n; set<int> h; cin >> n; for (int i = 1; i <= n; i++) h.insert(i); for (int i = 1; i <= n; i++) for (int j = 1, x; j <= n; j++) { cin >> x; x != 0 && x != -1 ? x == 1 ? h.erase(i) : h.erase(j) : 0; } c...
#include <bits/stdc++.h> using namespace std; class Debugger { public: Debugger(const std::string& _separator = , ) : first(true), separator(_separator) {} template <typename ObjectType> Debugger& operator,(const ObjectType& v) { if (!first) cerr << separator; cerr << v; f...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void ...
#include <bits/stdc++.h> using namespace std; vector<int> solve() { const int N = 3e6; vector<bool> isPrime(N, true); isPrime[0] = isPrime[1] = false; for (int i = 0; i * i < N; i++) { if (isPrime[i]) { for (int j = i * 2; j < N; j += i) { isPrime[j] = false; } ...
#include <bits/stdc++.h> using namespace std; template <class T> T Mul(T x, T y, T P) { T F1 = 0; while (y) { if (y & 1) { F1 += x; if (F1 < 0 || F1 >= P) F1 -= P; } x <<= 1; if (x < 0 || x >= P) x -= P; y >>= 1; } return F1; } template <class T> ...
#include <bits/stdc++.h> using namespace std; const int oo = 0x7fffffff; const long long OO = 1000000000000000000LL; const int base = 1000000007; const int dx[] = {1, 0, 0, -1}; const int dy[] = {0, 1, -1, 0}; int x; int main() { ios_base::sync_with_stdio(false); cin >> x; if (x == 2) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); vector<pair<unsigned long long, unsigned long long> > v; unsigned long long target; cin >> target; unsigned long long base_l = 1, base_r = target + 1; for (unsigned long long n = 1; n * (n + 1) * (2 * n ...
#include <bits/stdc++.h> using namespace std; bool f(string s1, string s2) { if (s1 == s2) return true; bool ans = false; string t1(s1.begin(), s1.begin() + s1.size() / 2); string t2(s1.begin() + s1.size() / 2, s1.end()); string t3(s2.begin(), s2.begin() + s2.size() / 2); string t4(s2.begin(...
#include <bits/stdc++.h> using namespace std; bool visit[204]; vector<int> dependency[204]; int col[203]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> col[i]; } for (int i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; int hcf(long long a, long long b) { if (b == 0) return a; return hcf(b, a % b); } void solve() { long long n; cin >> n; long long x = hcf(n + 1, 4 * n); long long lcm = ((4 * n) * (n + 1)) / x; cout << lcm / (n + 1) + 1; } int main() ...
#include <bits/stdc++.h> using namespace std; int a, n, i, k, l, r, d, kol1, kol2, ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (i = 1; i <= n; i++) { cin >> a; if (a < k) kol1++; else if (a > k) kol2++; } l = n; r = n * 3;...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 10; int to[maxn << 1], nex[maxn << 1], head[maxn << 1], e, cnt; int u[maxn << 1], v[maxn << 1]; int dep[maxn << 1], siz[maxn << 1], son[maxn << 1], top[maxn << 1], fa[maxn << 1], id[maxn << 1]; int sum[maxn << 2]; int n; vo...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, i, k; cin >> n >> k; int a[n], c = 0; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 0; i < n; i += 3) { if (a[i] <= 5 && a[i + 1] <= ...
#include <bits/stdc++.h> using namespace std; int main() { int v[6][4]; for (int i = 0; i < 6; i++) { for (int j = 0; j < 4; j++) cin >> v[i][j]; } int cnt1 = 0, cnt2 = 0, cnt3 = 0; for (int i = 0; i < 3; i++) if (v[0][i] == v[0][i + 1] && v[2][i] == v[2][i + 1]) cnt1++; for (int...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; inline bool checkBit(long long n, int i) { return n & (1LL << i); } inline long long setBit(long long n, int i) { return n | (1LL << i...
#include<bits/stdc++.h> #define pb push_back #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define SORT(v) sort(all(v)) #define int long long #define ff first #define ss second #define mod 1000000007 using namespace std; void oj() { ios::sync_with_stdio(0);cin.tie(...
#include <bits/stdc++.h> using namespace std; const int NMAX = 2020; vector<int> Gph[2][NMAX]; int N, A, B, K; int st[2][NMAX], dr[2][NMAX], edges[2][NMAX]; int val[2][NMAX][NMAX]; int dp[NMAX / 2]; void dfs(int node) { if (node != 1) edges[K][node] = 1; for (int i = 0; i < Gph[K][node].size(); ...
#include <bits/stdc++.h> struct Mock { Mock(int n, const std::string &s) : n(n), s(s) {} std::vector<std::string> ask(int l, int r) { if (l > r) { return {}; } std::vector<std::string> substrings; for (int i = l - 1; i < r; ++i) { for (int j = 1; i + j <= r; ++j) { ...
#include <bits/stdc++.h> using namespace std; const long long LIM = 1e18; long long root(long long x) { long long L = 0LL, R = 1e9 + 7; while (L < R - 1) { long long mid = (L + R) >> 1LL; if (mid * mid <= x) L = mid; else R = mid; } return L; } int main() { ...
#include <iostream> #include <bits/stdc++.h> using namespace std; int main () { int t; cin >> t; for (int k=0; k<t;k++){ int n; cin >> n; int a[n]; for (int i=0; i<n; i++){ cin >> a[i]; } for (int j=n-1; j>=0; j--){ if(a[j]+j < n){ a[j] = a[j]+a[a[j]+j]; ...
#include <bits/stdc++.h> using namespace std; long long ncr_2(long long n, long long k) { if (k > n) return 0; if (k * 2 > n) k = n - k; if (k == 0) return 1; long long result = n; for (long long i = 2; i <= k; ++i) { result = result * (n - i + 1); result /= i; } return resul...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e16; const int maxn = 1e5; pair<long long, int> tree[4 * maxn + 11]; long long ans[maxn + 11]; long long minn[4 * maxn + 11], lazy[4 * maxn + 11]; set<pair<long long, int> > t; void push_up(int rt) { tree[rt] = min(tree[rt << 1], tree[...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pi; typedef vector <ll> vi; typedef vector <pi> vpi; typedef pair<pi,ll> pii; typedef set <ll> si; typedef long double ld; #define f first #define s second #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #defi...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int black = 0, white = 1000000001; cout << 0 << << 0 << endl; cout << flush; string S; cin >> S; if (S == white ) swap(white, black); for (int i = 1; i < N; i++) { int mid = (white + black) / 2...
#include <bits/stdc++.h> int main(void) { int n, m, c1 = 0, c2 = 0, c3 = 0, c4 = 0, count = 0, i, j; scanf( %d%d n , &n, &m); char s[n + 1][m + 1]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) scanf( %c n , &s[i][j]); } for (i = 0; i < n - 1; i++) { for (j = 0; j < m - 1; j++)...
#include <bits/stdc++.h> using namespace std; long long modPow(long long a, long long b); long long modInv(long long a); void solve() { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long dp[n + 1][n + 1]; memset(dp, 0, sizeof(dp)); long lo...
#include <bits/stdc++.h> using namespace std; char grid[2010][2010]; bool vis[2010][2010]; int dx[] = {0, 0, 1, -1}; int dy[] = {-1, 1, 0, 0}; bool valid(int x, int y, int n, int m) { if (x == n || y == m || x == -1 || y == -1 || vis[x][y] || grid[x][y] == * ) { return 0; } return...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int MOD = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, i; cin >> n; while (n--) { long long int k, t; cin >> k >> t; cout << t + (k - 1) * 9 << n ; ...
#include <bits/stdc++.h> using namespace std; const int mxn = 5e5 + 123; const int inf = 1e9; const int mod = 1e9 + 7; int a[mxn], n; vector<int> v; int main() { long long s; cin >> s; for (long long i = 1; i <= s; i++) { long long n; cin >> n; long long sum = 0; while ...
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 10; long long num[maxn], dp[maxn][15]; void Solve() { int n, m, k; scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; i++) scanf( %lld , &num[i]); long long ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1;...
#include <bits/stdc++.h> using namespace std; int n; long long c; int last, l, r; int q[200010]; long long a[400010], ans[200010]; int main() { scanf( %d%lld , &n, &c); for (int i = 1; i < 2 * n; i++) scanf( %lld , &a[i]), a[i] += a[i - 1]; for (int i = 1; i <= n; i++) { while (last < i ...
#include <bits/stdc++.h> using namespace std; long long H[200005]; int a[200005]; long long c[200005 << 2]; long long s[200005 << 2]; long long lz[200005 << 2]; vector<int> v[200005]; int u; int yl, yr; void build(int o, int l, int r) { if (l == r) { lz[o] = l; c[o] = l; s[o] =...
#include <bits/stdc++.h> using namespace std; const int MM = 1e9 + 7; const double eps = 1e-8; const int MAXN = 2e6 + 10; int n, m; int a[MAXN], Q[MAXN], cnt[MAXN], ans[MAXN]; int f[MAXN]; void prework() {} void read() {} int gao(int k) { if (f[k] != -1) return f[k]; int ret = 0; int now...
#include <bits/stdc++.h> using namespace std; int n, l, m, sol; int a[10]; bool r[333][333]; bool ok; int main() { cin >> n; for (int(i) = (0); (i) < (n); ++(i)) cin >> a[i]; if (n == 1) { if (a[0] == 0) cout << BitAryo << endl; else cout << BitLGM << endl; ...
#include <bits/stdc++.h> bool map[21][21]; int i, j, k, n, m, lim, tot, l, t, c[1 << 10]; long long f[1 << 10][1 << 10], ans; int main() { scanf( %d%d%d , &n, &m, &lim); tot = 1 << n; memset(map, 0, sizeof(map)); memset(f, 0, sizeof(f)); for (i = 0; i < tot; i++) for (j = i, c[i] = 0; ...
#include <bits/stdc++.h> const long long LL_INF = (long long)2e18 + 5; using namespace std; const long long N = 2e5 + 10; void solve() { long long n, a0, a, b0, b, k; cin >> n; vector<long long> v(n), pref(n + 1); ; { for (auto &i : v) cin >> i; } sort(v.begin(), v.end()), reve...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; struct cate { long long num, t; bool operator<(const cate& other) const { return t > other.t; } } a[maxn]; int n; set<long long> has; map<long long, long long> fa; long long find(long long x) { return x == fa[x] ? x : fa[x] ...
#include <bits/stdc++.h> using namespace std; const long long LL_MIN = std::numeric_limits<long long>::min(); const long long LL_MAX = std::numeric_limits<long long>::max(); template <class T, class R> ostream& operator<<(ostream& o, const pair<T, R>& p) { o << ( << p.first << , << p.second << ) ; ...
#include <bits/stdc++.h> int main() { long long n, w = 0, i, j, k; bool y[1261] = {0}; scanf( %I64d , &n); k = 1260; for (i = 2; i <= 10; i++) for (j = 1; j <= 1260; j++) if (j % i == 0 && y[j] == 0) { y[j] = 1; k--; } w = 0; w = n / 1260 * k; ...
#include <bits/stdc++.h> using namespace std; int present(int *lib, int k, int x) { int i; for (i = 0; i < k; i++) { if (lib[i] == x) return 1; } return 0; } int findMax(int *lib, int k, queue<int> *q, int n) { int i, max = -1, maxi = 0; for (i = 0; i < k; i++) { if (q[lib[i]...
#include <bits/stdc++.h> const int maxn = 3e5 + 5; using namespace std; long long n, m; int main() { scanf( %d%d , &n, &m); if (min(n, m) == 1) { long long t = max(n, m); long long ti = t / 6, res = t % 6; printf( %lld n , ti * 6 + max(0ll, res - 3) * 2); return 0; } if (...
#include <bits/stdc++.h> using namespace std; double p[600][600], pp[600][600]; double f[600][600]; bool checkInRound(int I, int K, int Round) { int i = I - 1; int k = K - 1; if (i / (1 << Round) != k / (1 << Round)) return false; if (i / (1 << (Round - 1)) == k / (1 << (Round - 1))) return fals...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, x, p, m = 0; stack<int> s; cin >> n; p = n % 2; for (int i = 0; i < n; i++) { cin >> x; m = max(x, m); if (!s.empty() && s.top() < x) cout << NO , exit(0)...
#include <bits/stdc++.h> using namespace std; bool check(char s) { if (s == A || s == H || s == I || s == M || s == O || s == T || s == U || s == V || s == W || s == X || s == Y ) return true; else return false; } int main() { int n, i, x, p; bool ans = t...
#include <bits/stdc++.h> using namespace std; int main() { int count[26] = {0}, c = 0, i; string str; getline(cin, str); for (i = 1; i <= str.length() - 1; i++) { if (str[i] == } || str[i] == , ) count[str[i - 1] - a ]++; } for (i = 0; i <= 25; i++) if (count[i] > 0) c++; ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); long long t; cin >> t; while (t--) { vector<long long> v(7); for (auto& e : v) cin >> e; sort(v.begin(), v.end()); cout << v[0] << << v[1] << ; if (v[2] != v[...
#include <bits/stdc++.h> using namespace std; int a[1000100], n, m; int sum[1000100], now; long long ans; int idx, cnt; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &a[i]), ans += a[i]; if (ans % m) { puts( No ); return 0; } ans /= m; for (...
#include <bits/stdc++.h> using namespace std; inline int read(int f = 1, int x = 0, char ch = ) { while (!isdigit(ch = getchar())) if (ch == - ) f = -1; while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return f * x; } const int N = 2e5 + 5; int m, n, T, s[2][N], c[2], f[2], ans...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; const double eps = 1e-7; const double pi = acos(-1.0); const long long INF = (long long)2e9 + 1; const long long LINF = (long long)8e18; const long long inf = (long long)2e9 + 1; const long long linf = (long long)8e...
#include <bits/stdc++.h> using namespace std; const int maxn = 10 + 1e6; const int INF = 1e9 + 10; long long a, b; map<long long, int> f; map<long long, long long> dad; long long ans[100]; void dfs(long long x, int s) { if (x > b) return; if (f[2 * x] == 0 || f[2 * x] > s + 1) { dad[2 * x]...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; for (int i = 0; i < s.size(); i++) { if (s[i] == t[s.size() - i - 1]) { continue; } else { cout << NO ; return 0; } } cout << YES ; }
#include <bits/stdc++.h> using namespace std; int n, a, b; int main() { cin >> n >> a >> b; long long chores[n]; for (int i = 0; i < n; i++) cin >> chores[i]; sort(chores, chores + n); cout << chores[b] - chores[b - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { double n, x; cin >> n >> x; vector<double> a(n); for (__typeof(n) i = 0; i < n; i++) { cin >> a[i]; } sort(a.rbegin(), a.rend()); a.push_back(0); double...
#include <bits/stdc++.h> using namespace std; int fromStrtoInt(string s, string c) { int x = 0; for (int i = 0; i < c.size(); i++) { x *= 10; x += s[c[i] - 0 ] - 0 ; } return x; } int main() { int n, k; cin >> n >> k; string s, arr[n]; for (int i = 0; i < n; i++) ci...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, ans = 0; scanf( %d , &n); while (n--) scanf( %d%d , &x, &y), ans = max(ans, x + y); printf( %d , ans); }
#include <bits/stdc++.h> using namespace std; long long int full = 0; long long int arr[51][51]; long long int n, t; void solve(long long int i, long long int j, long long int level) { if (level > n - 1) { return; } else { if (arr[i][j] < (1ll << level)) { arr[i][j]++; if (...
#include <bits/stdc++.h> using namespace std; int V[102][102], M2[2][102]; int main() { int n, a; scanf( %d , &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { scanf( %d , &a); M2[0][i] += a; M2[1][j] += a; } int cnt = 0; for (int i = 0; i < n; ...
#include <bits/stdc++.h> unsigned long long c; int n, i, j, k, ks, ke, pd, pp, pa; char s[1000100]; bool f, ff, fff; int main() { scanf( %s , s); n = strlen(s); for (i = 0; i < n; i++) { if (s[i] >= a && s[i] <= z ) { k = 0, f = 1, ff = 0, fff = 0, ks = 1, ke = 0, pa = 0, pd = 0, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000; int n, i, j; char s[maxn]; long long F[maxn][maxn]; long long P[maxn]; int main() { scanf( %d , &n); scanf( %s , s); P[1] = 1; for (i = 2; i <= 18; ++i) P[i] = 10LL * P[i - 1]; memset(F, 0, sizeof F); for (i = 0; ...
#include <bits/stdc++.h> int n, from[300005], p[300005], dis[300005], a[300005], b[300005]; std::queue<int> que; std::set<int, std::greater<int>> l; void work(int now) { if (now != n) work(from[now]), std::cout << p[now] << ; } void print(int now) { std::cout << dis[now] + 1 << std::endl; wor...
#include <bits/stdc++.h> using namespace std; const long long MAX = -1000000000000000000; const long long MIN = 1000000000000000000; const long long inf = 1000000000; const long long KOK = 100000; const long long LOG = 30; const long long li = 500005; const long long mod = 1000000007; int n, m, b[li],...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; string s; cin >> n; cin >> s; sort(s.begin(), s.end()); cout << s; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; long long a; int g = 0; for (int i = 0; i < n; i++) { cin >> a; set<int> d; while (a) { if (a % 10 <= k) { d.insert(a % 10); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<int> st; for (int i = 2; i <= n; i++) { int a = i; for (int j = 2; j * j <= a; j++) { int num = 1; while (a % j == 0 and a > 1) { a /= j; num *= j; } if (nu...
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <algorithm> #include <string> #include <fstream> #include <set> #include <deque> #include <math.h> #include <iomanip> #define ll long long #define ld long double using namespace std; int all = 0; int price =...
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T &x, T y) { x = x > y ? x : y; } template <typename T> void chkmin(T &x, T y) { x = x > y ? y : x; } const int INF = (1ll << 30); template <typename T> void read(T &x) { x = 0; bool f = 1; char ch; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; template <class T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = 0; while (!isdigit(c)) { if (c == - ) flag = 1; c = getchar(); }...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const long long LL_INF = 1ll * INF * INF; const int MAX_N = 1000000 + 7; template <typename T> inline void addmod(T& a, const long long& b, const int& MOD = INF) { a = (a + b) % MOD; if (a < 0) a += MOD; } const int mod = INF...
#include <bits/stdc++.h> using namespace std; struct lichao { int l, r, A; long long B; lichao() : l(0), r(0), A(0), B(0x7fffffffffffffffLL) {} }; const int SZ = 1 << 17; vector<int> adj[100000]; vector<lichao> tree(2 * SZ); int node_cnt, num[100000], A[100000], B[100000]; long long ans[1000...
#include <bits/stdc++.h> using namespace std; const int inf = 1e5 + 9, lg = 30; int a[inf * 3], n, table[lg][inf << 2]; int ans[inf], nxt[inf], sml[inf << 2]; void build() { int i, j; for (i = 1; i <= n + n; i++) table[0][i] = a[i]; for (j = 1; j < lg - 1; j++) for (i = 1; i + (1 << (j - 1))...
#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; int main() { in...
#include <bits/stdc++.h> using namespace std; int p; int pm(int x, int e) { int res = 1; int tmp = x; while (e > 0) { if (e & 1) res = ((long long)res * tmp) % p; tmp = ((long long)tmp * tmp) % p; e >>= 1; } return res; } bool prim() { for (int i = 2; i * i <= p; ++i)...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } int main() { long long n; cin >> n; string s; cin >> s; vector<int> v(26); for (long long i = 0; i < n; i++) { v[...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int k, n, m; long long a[MAXN], g[MAXN], ii[MAXN], ty[MAXN]; vector<pair<long long, long long> > V[MAXN]; vector<pair<long long, pair<long long, long long> > > P; bool Compare(pair<long long, pair<long long, long long> > A, ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > g[100005]; long long n, ans, ans2; void dfs(long long u, long long p, long long cur) { ans2 = max(ans2, cur); for (auto e : g[u]) if (e.first != p) dfs(e.first, u, cur + e.second); } signed main() { ios_base:...
#include <bits/stdc++.h> using namespace std; template <class T> inline void rd(T &x) { char ch; x = 0; bool fl = false; while (!isdigit(ch = getchar())) (ch == - ) && (fl = true); for (x = (ch ^ 0 ); isdigit(ch = getchar()); x = x * 10 + (ch ^ 0 )) ; (fl == true) && (x = -x); }...
#include <bits/stdc++.h> long long f[2005][2005]; long long k[2005][2005]; long long C[4005][4005]; int main() { int n, m; scanf( %d %d , &n, &m); for (register int i = 0; i <= n; ++i) for (register int j = 0; j <= m; ++j) { if (i == 0) k[i][j] = 1; else if (j == 0) ...
#include <bits/stdc++.h> using namespace std; const int M = 2000 + 4, Inf = 1e9 + 10; int n, m, k; char f[M][M]; int main() { ios::sync_with_stdio(false); cin >> n >> m >> k; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> f[i][j]; for (int i = 0; i < m; i++) { int a...