func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using D = double; using uint = unsigned int; const int maxn = 100005; ll t[maxn], others[maxn], me[maxn]; int f[maxn]; vector<int> from[maxn]; int kv[maxn]; ll ans[maxn]; int n, m; multiset<ll> global; ...
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f3f3f3f3fLL; const int MOD = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; vector<vector<int>> e(n + 1); for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; long long h[100000], p[100000], l, r; int i, j, n, m; long long getleft(long long x) { int l = 0, r = m - 1; while (r - l > 1) { int mid = (l + r) / 2; if (p[mid] > x) r = mid; else l = mid; } if (p[l] > x) ret...
#include <bits/stdc++.h> const int MAXN = 100; char cake[MAXN][MAXN + 1]; int main() { int n; scanf( %d , &n); for (int row = 0; row < n; ++row) { scanf( %s , cake[row]); } int pairs = 0; for (int i = 0; i < n; ++i) { int inRow = 0, inCol = 0; for (int j = 0; j < n; ++j) ...
#include <bits/stdc++.h> using namespace std; const int INF = 10000000; int main() { int n; cin >> n; string a; cin >> a; for (int j = 1; j <= 25; j++) for (int i = 0; i + 4 * j < a.size(); i++) { if (a[i] == * && a[i + j] == * && a[i + 2 * j] == * && a[i + 3 * ...
#include <bits/stdc++.h> using namespace std; struct Pair { int x, position; } valiue[543211], b[543211]; int n, k, len, N, Partition, L, R; int QWER[543211], REWQ[543211], otvet[543211], kol, i; int Lowofbound[543211], Behind[543211], sled[543211], l, r, mn; vector<pair<pair<int, int>, int> > a[800];...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int minval = 100000000, currsum = 0; for (int i = 0; i < n; i++) { if (s[i] == ( ) { currsum++; minval = min(minval, currsum); } else { currsum--; minv...
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; cin >> s; s += b ; n = s.size(); for (int i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) cout << 1 << ; else cout << 0 << ; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, d, steps = 0; string s; cin >> n >> d >> s; for (int x = 0; x < n; steps++) { if (x == n - 1) { cout << steps; break; } for (int a = d; a + 1; a--) { if (!a) { cout << -1; ...
#include <bits/stdc++.h> using namespace std; const int MX = 100005; template <typename T> void cmin(T &x, const T &y) { if (y < x) x = y; } template <typename T> void cmax(T &x, const T &y) { if (y > x) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int d[maxn], n; struct node { int a, b; } data[maxn]; int main() { cin >> n; d[0] = -1; for (int i = 1; i <= n; i++) cin >> d[i]; sort(d + 1, d + 1 + n); int cnt = 0; for (int i = 1; i <= n; i++) { if (d...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using D = double; using uint = unsigned int; template <typename T> using pair2 = pair<T, T>; const long double pi = acos((ld)-1.0); const int maxn = 1 << 16; complex<double> oddc[maxn], evenc[maxn], tmp[maxn]...
#include <bits/stdc++.h> using namespace std; char s[100][100]; int di[4][2] = {0, 1, 1, 0, 0, -1, -1, 0}; int v[100][100]; int fst[4] = {1, 0, 1, 0}; int xi[4][2] = {1, 0, 0, 1, 2, 3, 3, 2}; int m, r; struct zb { int z[2]; } po[100][100][4][2]; void gx(int x, int y, int &a, int &b, int xi) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long int s, x, y, a, b = 0; cin >> s >> x; int f = 1; if (s < x) f = 0; if (s == x) b = 2; y = s - x; if (y % 2 == 1) f = 0; if (f) { y /= 2, a = 1; while (x > 0 || y > 0) { if (x % 2 == 1) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 1 << 18; struct node { int mx; node() { mx = -1e9; } node(int val) { mx = val; } }; node temp; node merge(node l, node r) { temp.mx = min(l.mx, r.mx); return temp; } struct segment_tree { int n...
#include <bits/stdc++.h> using namespace std; struct edge { edge(int to, int back, int orient = 0) : to(to), back(back), orient(orient) {} int to; int back; int orient; }; class Tarjan { public: vector<vector<int> > adj; vector<int> comp; int nb_cfc; private: vector<int>...
#include <bits/stdc++.h> using namespace std; inline long long add(long long a, long long b) { a = (a + b); if (a >= 1000000007) a -= 1000000007; return a; } inline long long sub(long long a, long long b) { a = a - b; if (a < 0) a += 1000000007; return a; } inline long long mul(long ...
#include <bits/stdc++.h> using namespace std; const long long lcm = 840; long long w, cnt[10]; long long dp[10][lcm * 8 + 5]; int main() { ios::sync_with_stdio(false); cin >> w; for (int i = 1; i <= 8; i++) { cin >> cnt[i]; } memset(dp, -1, sizeof(dp)); dp[0][0] = 0; for (int...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); vector<int> v(n + 1); for (int i = 1; i <= n; ++i) cin >> v[i]; int x, y; scanf( %d %d , &x, &y); for (int i = 1; i <= n; ++i) { int a = 0, b = 0; for (int j = 1; j <= n; ++j) { if (j <...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m; cin >> n >> m; long long int a[n], k = 0, sum = 0; for (int x = 0; x < n; x++) { cin >> a[x]; } sort(a, a + n); for (int x = 0; x < m; x++) { if (a[x] < 0) { sum += a[x]; } } ...
#include <bits/stdc++.h> using namespace std; long long n, m, k, d[1010][101][2], ans, nf, p[1010]; int main() { cin >> n >> k >> m; p[0] = 1; for (int i = 1; i <= n; i++) p[i] = p[i - 1] * 10 % k; d[0][0][0] = 1; for (int i = 1; i <= n; i++) { for (int x = (i == n); x < 10; x++) ...
#include <bits/stdc++.h> using namespace std; bool check(long n, long k) { long dem = 0; while (n > 0) { long x = n % 10; n /= 10; (x == 4 || x == 7) ? dem++ : dem = dem; } if (dem <= k) return 1; return 0; } int main() { long n, k, dem = 0; cin >> n >> k; long ...
#include <bits/stdc++.h> using namespace std; int main() { int m, n, i, j, k; scanf( %d%d , &n, &m); vector<int> A; for (i = 0; i < n; i++) A.push_back(i + 1); int M = 0; do { int s = 0; for (i = 0; i < n; i++) { for (j = i + 1; j < n + 1; j++) { int s1 = 1000; ...
#include <bits/stdc++.h> using namespace std; int n, num, k; pair<int, int> a[200005]; bool comp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { ios::sync_with_stdio(0); cin.tie(NULL); int t = 1; cin >> t; while (t--) { cin >> n >> k; unordered_...
#include <bits/stdc++.h> using namespace std; int a[1001]; int main() { int n, t, i, j, k, m; cin >> t; while (t--) { cin >> n >> m; for (i = 0; i < n; i++) cin >> a[i]; int ans = a[0]; for (i = 1; i < n; i++) { if (ans + a[i] <= m) ans += a[i]; else {...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, k; cin >> n >> k; vector<long long> v(n); for (long long &i : v) cin >> i; sort(v.begin(), v.end(), [](long long a, long long b) { return a > b; }); vector<long long>...
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); struct C { double x, y, r; } base[3050]; double Ans; int i, j, k; long long dp[3050][2][2]; int N, mark[3050], fa[3050]; inline double dist(C A, C B) { return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y))...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = 3.1415926535897932384626433832795; template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { ...
#include <bits/stdc++.h> using namespace std; const int N = 100 + 2; const int MOD = 1 << 30; const double pi = acos(-1); struct line { double a, b, c; }; struct point { double x, y; }; void pointsToLine(point p1, point p2, line &l) { if (fabs(p1.x - p2.x) < 1e-2) { l.a = 1.0; ...
#include <bits/stdc++.h> using namespace std; const int MIN = 1e3 + 2; const int MXN = 1e6 + 3; const int INF = 1e9 + 7; const long long LINF = 1e18 + 15; const double EPS = 1e-9; int s, x1, x2; int t1, t2; int p, d; int main() { cin >> s >> x1 >> x2; cin >> t1 >> t2; cin >> p >> d; ...
#include <bits/stdc++.h> using namespace std; struct vec { long long x, y; }; bool operator==(const vec& a, const vec& b) { return a.x == b.x and a.y == b.y; } bool operator!=(const vec& a, const vec& b) { return not(a == b); } bool operator<(const vec& a, const vec& b) { return make_pair(a.x,...
#include <bits/stdc++.h> const double pi = acos(-1.0), eps = 1e-9; const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1}; const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1}; const int MO = (int)(1e9 + 7); using namespace std; struct Tcmp { bool operator()(const pair<int, int>& A, const pair<int, int>& B) { int...
#include <bits/stdc++.h> using namespace std; struct segtree { vector<long long> t; segtree(long long _n) { t.resize(4 * _n); } void update(long long id, long long l, long long r, long long pos, long long val) { if (l == r) { t[id] = val; return; } long ...
#include <bits/stdc++.h> using namespace std; long long N, P; long long L[100001]; long long R[100001]; long long getAc(long long l, long long r, long long p) { if ((l + p - 1) / p * p > r) return 0; return (r - (l + p - 1) / p * p) / p + 1; } int main() { scanf( %lld%lld , &N, &P); for (i...
#include <bits/stdc++.h> using namespace std; int n, m, a[200010], w[200010], f[3010][3010], g[3010][3010], inv[3010 * 2], sum[3]; const int mod = 998244353; int getInverse(int x, int y) { int ret = 1; while (y) { if (y & 1) ret = (long long)ret * x % mod; x = (long long)x * x % mod; ...
#include <bits/stdc++.h> using namespace std; string a; int main() { cin >> a; if (a == string(a.size(), a )) { cout << string(a.size() - 1, a ) << z << endl; } else { for (int i = 0; i < a.size(); i++) { if (a[i] != a ) { int x = i; while (x < a.size() && ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int n, m; long long minb[100010]; long long maxg[100010]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { scanf( %lld , minb + i); } sort(minb, minb + n); for (int i = 0; i < m; i++) { scanf...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return !b ? a : gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a * (b / gcd(a, b)); } template <typename T> T sqr(T a) { return a * a; } template <typename T> T cube(T a) { retu...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 550; struct DDF { int n; int v[maxn]; int dp[maxn][maxn]; int dfs(int l, int r) { if (l >= r) return dp[l][r] = 1; if (~dp[l][r]) return dp[l][r]; long long ans = dfs(l + 1, r); for (i...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int ac = 1e6 + 5; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; cout << n << n ; string s; cin >> s; int p = 0; ...
#include <bits/stdc++.h> const int N = 50; int i, j, tot, n; bool left[N][N], down[N][N]; int main() { long long T; scanf( %I64d , &T); for (i = 0; T; T /= 3, i++) { int x = T % 3; if (i) { tot += 2; down[i][i + 3] = left[i + 3][i] = 1; if (T >= 3) tot += 2, left[...
#include <bits/stdc++.h> using namespace std; const int N = 110; pair<int, int> a[N]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) scanf( %d , &a[i].first), a[i].second = i + 1; sort(a + 1, a + n); int Sum1 = a[0].first; int Sum2 = 0; for (int i = 1; i < n; i++) Sum2 += ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, /STACK:336777216 ) using namespace std; int IT_MAX = 1 << 18; const long long MOD = 1000000007; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1); const double ERR = 1e-1...
#include <bits/stdc++.h> using namespace std; int arr[50100]; int tmp[50100]; int ans[50100]; map<int, bool> vis; int n; bool Check(int mid) { vis.clear(); for (int i = 1; i <= n; ++i) { tmp[i] = arr[i]; while (tmp[i] > mid) tmp[i] >>= 1; if (tmp[i] == 0) return false; whil...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, x, y, i, j, l, pos1, pos2, A; long long m, tmp1, tmp2, tmp3, ans; struct node { int x, y; } a[N]; int cmp1(const node& a, const node& b) { return a.x > b.x; } int cmp2(const node& a, const node& b) { return a.y < b.y; } int...
#include <bits/stdc++.h> using namespace std; long long dp[100001]; string s; long long dp2[100001]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> s; dp2[1] = 1; dp2[2] = 2; dp2[3] = 3; dp2[4] = 5; for (int i = 5; i <= 100000; i++) { dp2[i] = dp2[i - 1] + dp2[i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000100; struct seg { seg *fe, *fd; int meio, l, r, xo; seg(int x, int y) { l = x, r = y; meio = (x + y) / 2; xo = 0; if (l == r) return; fe = new seg(x, meio); fd = new seg(meio + 1, y); } void ...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; const double eps = 1e-8; int n, T, cnt1, cnt2; long double sum1; double sum2; struct water { int a, t; } A[N], B[N], Tmp[N]; bool cmp1(const water &a, const water &b) { return a.t < b.t; } bool cmp2(const water &a, const water ...
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c *x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c...
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; const int SIGMA_SIZE = 26; int SZ = 0; struct Node { int sz, ch[SIGMA_SIZE]; Node() { memset(ch, 0, sizeof(ch)); } } nd[maxn << 1]; int newNode() { ++SZ; memset(nd[SZ].ch, 0, sizeof(nd[SZ].ch)); return SZ; } voi...
#include <bits/stdc++.h> using namespace std; const int p = 998244353, inv2 = 499122177; inline void XOR(int *a, int lim, int type) { for (register int mid = 1; mid < lim; mid <<= 1) { for (register int i = mid << 1, j = 0; j < lim; j += i) { for (register int k = 0; k < mid; k++) { a[...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int ans = (n / 2) + (n & 1); for (int i = ans; i <= n; ++i) { if (i % m == 0) { cout << i << n ; return 0; } } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int w = 1, c = 0; for (; !isdigit(ch); ch = getchar()) if (ch == - ) w = -1; for (; isdigit(ch); ch = getchar()) c = (c << 1) + (c << 3) + (ch ^ 48); return w * c; } const int mod = 1e9 + 7, M = 1e6...
#include <bits/stdc++.h> using namespace std; const int m = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; string s; cin >> s; for (int i = 0; i <= 25; i++) { for (int j = 0; j < n and k > 0; j++) { if (s[j] == a + i) ...
#include <bits/stdc++.h> using namespace std; void solve() { string s, s1; cin >> s; int count = 0; sort(s.begin(), s.end()); for (int i = 0; i < s.length(); ++i) { if (s[i] == + ) count++; } std::vector<string> v(s.length()); for (int i = count; i < s.length(); ++i) { v...
#include <bits/stdc++.h> using namespace std; int ans0[1000001]; int tail = 1; int a[1001]; int n, m; int ans = 0; int main() { int i, j, k; int id; int xx, yy; int temp; scanf( %d , &n); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf( %d , &temp); ...
#include <bits/stdc++.h> using namespace std; bool b[1000050]; vector<int> v; vector<int> v1; int main() { int n; cin >> n; int u = sqrt(n); if (n == 1) { cout << 1; return 0; } for (int i = 2; i <= u; i++) { if (!b[i]) { for (int j = i * i; j <= n; j += i) b[...
#include <bits/stdc++.h> using namespace std; vector<int> lk; void make(int num, int len) { if (len == 10) return; if (num != 0) lk.push_back(num); make(num * 10 + 4, len + 1); make(num * 10 + 7, len + 1); } double gao(int l1, int l2, int r1, int r2) { double l = max(l1, r1), r = min(l2, r...
#include <bits/stdc++.h> using namespace std; struct pnt { int x, y; pnt(int x = 0, int y = 0) : x(x), y(y) {} bool operator<(const pnt &p) const { return x == p.x ? y < p.y : x < p.x; } bool operator==(const pnt &p) const { return x == p.x && y == p.y; } }; const int inf = 1e9; int ans; pnt...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ...
#include <bits/stdc++.h> const int N = 2e5 + 10; const int MOD = 1e9 + 7; const int INF = 2e9; using namespace std; vector<int> a; int f[N], d[N]; int c, n; int main() { ios::sync_with_stdio(false); cin >> c >> n; for (int i = 0; i < n; i++) { int x; cin >> x; a.push_back(x...
#include <bits/stdc++.h> using namespace std; const int N = 100005; char A[N]; char B[N]; int buck[128]; int ans[128]; bool ok() { for (int i = a ; i <= z ; ++i) if (buck[i] > ans[i]) return false; return true; } int main() { scanf( %s , A); scanf( %s , B); int aa = strlen(...
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, left, line; cin >> line; bool first = true; for (int i = 0; i < line.size(); i++) { if (line[i] == | ) first = false; else if (first) s1 += line[i]; else s2 += line[i]; } cin ...
#include <bits/stdc++.h> using namespace std; int main() { int n; char tmp[11]; deque<string> dq; set<string> st; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %s , &tmp); dq.push_front(tmp); } for (deque<string>::iterator i = dq.begin(); i != dq.end(); i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 4010; int n, a, b; vector<pair<int, int>> ans; deque<int> s[3]; inline void print() { if (n == 1248) for (pair<int, int> p : ans) printf( %d %d n , p.first, p.second); } inline void move(int tp, int c) { if (!c) return; if (tp...
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b, c, d, k; cin >> t; while (t--) { cin >> a >> b >> c >> d >> k; int pen = (a + c - 1) / c; int penc = (b + d - 1) / d; if (pen + penc <= k) cout << pen << << penc << endl; else cout <...
#include <bits/stdc++.h> using namespace std; const int maxn = 105; int n, a[maxn], vis[maxn]; int gcd(int a, int b) { while (b) { int c = a % b; a = b; b = c; } return a; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); int flag = 0;...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); const double EPS = 1e-9; inline int sgn(double a) { return a < -EPS ? -1 : a > EPS; } struct node { long long v; int id; int date; node(long long a = 0, int b = ...
#include <bits/stdc++.h> using namespace std; long long Fac[1000010], Inv[1000010], inv[1000010]; void ini() { Fac[0] = Inv[0] = Fac[1] = Inv[1] = inv[1] = 1; for (int i = 2; i < 1000010; i++) { Fac[i] = Fac[i - 1] * i % 1000000007; inv[i] = inv[1000000007 % i] * (1000000007 - 1000000007 / i) ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10, M = (1 << 18); int n, a[N], fa[N], cnt; long long ans; pair<int, int> mx[M][2], cur[M]; int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); } bool merge(int x, int y) { x = getfa(x), y = getfa(y); if (x == y) return...
#include <bits/stdc++.h> const int LG = 21; const int N = 1000005; const long long MOD = 1e9 + 7; const long long INF = 1e9; const long long INFLL = 1e18; using namespace std; int cx[4] = {-1, 0, 1, 0}; int cy[4] = {0, -1, 0, 1}; string Yes[2] = { No , Yes }; string YES[2] = { NO , YES }; long l...
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(T x) { return x * x; } const double EPS = 1e-6; const int INF = 0x3fffffff; const long long LINF = INF * 1ll * INF; const double PI = acos(-1.0); using namespace std; bool vis[205][205]; int main(void) { int a, b...
#include <bits/stdc++.h> using namespace std; int main() { long long n, d, m, l, i, j, x; cin >> n >> d >> m >> l; for (i = 0; i < n - 1; i++) { if ((i * m + l) / d * d + d < (i + 1) * m) break; } cout << (i * m + l) / d * d + d; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> m >> k; vector<vector<int> > dp(1 << n, vector<int>(1 << n, 0)); vector<int> G[n]; int all = (1 << n) - 1; for (int i = 1; i <= m; ++i) { int u,...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> cnt(n + 1, false), idx(n + 1), ans(m + 1), b(m + 1); for (int i = 1; i <= n; i++) { int x; cin >> x; cnt[x]++; idx[x] = i; } for (int ...
#include <bits/stdc++.h> using namespace std; int a[10] = {4, 8, 15, 16, 23, 42}; int q[5]; int main() { for (int i = 1; i <= 4; i++) { printf( ? %d %d n , i, i + 1); fflush(stdout); cin >> q[i]; } do { if (a[1] * a[0] == q[1] && a[2] * a[1] == q[2] && a[3] * a[2] == q[3] && ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int first[maxn]; int n; int main() { int num, i; while (scanf( %d , &n) != EOF) { memset(first, 0, sizeof(first)); for (i = 1; i <= n; i++) { scanf( %d , &num); if (i <= n / 2) { if (num - (i -...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = 1000000000009; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long l{}, r{}, x{}, y{}, k{}, f{}; cin >> l >> r >> x >> y >> k; for (int i = x, sz = (int)y + 1; i < ...
#include <bits/stdc++.h> using namespace std; int a[1000000 * 2][2], g[1000000], v[1000000], d[20], f[1000000], e[20]; int n; void ins(int x, int y) { static int sum = 1; a[++sum][0] = y, a[sum][1] = g[x], g[x] = sum; } int gcd(int x, int y) { return !y ? x : gcd(y, x % y); } void dfs(int x, int G...
#include <bits/stdc++.h> using namespace std; string a; int main() { int t; cin >> t; while (t--) { int n; cin >> n; cin >> a; for (int i = 0; i < a.length(); i += 2) cout << a[i]; cout << endl; } return 0; }
/* python3 ../../CompetitionHelpers/run_codeforces.py --problem A --test 0 g++ -ggdb -fsanitize=address -std=c++17 A.cpp && ./a.out <<< 1 4 0 3 5 6 */ #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); i++) #define trav(a, x) for (auto& a : x) #define...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 500; char s[MAX_N + 2][MAX_N + 2]; int D[2][MAX_N + 1][MAX_N + 1]; int main() { int N, M; scanf( %d%d n , &N, &M); for (int i = 0; i <= M; ++i) s[0][i] = # ; for (int i = 1; i <= N; ++i) { s[i][0] = # ; gets(s[i] + 1...
#include <bits/stdc++.h> using namespace std; void ECHO(string _s) { cout << endl; (void)_s; } template <typename T, typename... Args> void ECHO(string _s, T x, Args... args) { unsigned _i; string _s2 = ; for (_i = 0; _i < _s.length(); ++_i) { if (_s[_i] == , ) break; if (_s...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read(T& x) { x = 0; int f = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) f |= (ch == - ), ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x = f ? -x : x; } ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double pi = acos(-1); const int M = 3e5 + 10; const int inf = 2e9 + 10; const int mod = 1e9 + 7; int n, stk[M], le[M], ri[M], f[M], cnt[M]; char s[M], s1[M]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 2e5 + 6; const long long inf = 1e15; long long ex, ey, ez, bx, by, bz, a[7]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); if (fopen( inp.txt , r )) { freopen( inp.txt , r , stdin)...
#include <bits/stdc++.h> using namespace std; const int N = 2055, mod = (int)1e9 + 7; template <class o> void qr(o &x) { char c = getchar(); x = 0; while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = x * 10 + c - 0 , c = getchar(); } int n, m, L, last[N], ys[N], tot, vis[N], col[N]; ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; int arr[MAX]; int n; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; set<array<int, 4> > vis; pair<int, int> p; for (int tc = 1; tc <= t; ++tc) { vis.clear(); cin...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a1, b1, c1, ma = 0, maa = 0, x1, y1; cin >> a1 >> b1 >> c1; for (int i = 0; i < b1; i++) { cin >> x1; ma = max(x1, ma); } for (int i = 0; i < c1; i++) { cin...
#include <bits/stdc++.h> using namespace std; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1}; int t; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> t; while (t--) { int n; ...
#include <bits/stdc++.h> using namespace std; void processTest(int n, int64_t m, int64_t k) { vector<int64_t> path(n); int64_t bag = m; for (auto &v : path) { cin >> v; } for (int i = 1; i < path.size(); ++i) { auto toEq = max(path[i] - k, int64_t(0)); bag += path[i - 1] - toEq...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); retur...
#include <bits/stdc++.h> using namespace std; char str[25]; char times[6] = {4, 5, 6, 3, 2, 1}; int main() { scanf( %s , str); int len = strlen(str); char seat = str[len - 1]; long long rows = 0; for (int i = 0; i < len - 1; i++) { rows = rows * 10; rows += str[i] - 0 ; } ...
#include <bits/stdc++.h> using namespace std; void solve(int n, int m, vector<int> a) { for (int i = int(0); i < int(m); i++) a[i] = min(a[i], n / 2); int sum = accumulate((a).begin(), (a).end(), 0); if (sum < n) { cout << -1 << endl; return; } vector<pair<int, int> > b(m); for (...
#include <bits/stdc++.h> using namespace std; string decToBin(int n) { string toret; while (n) { toret += char((n % 2) + 0 ); n /= 2; } while (toret.size() != 8) toret += 0 ; return toret; } int binToDec(string res) { int t = 0; int pow = 1; for (int i = res.size() ...
#include <bits/stdc++.h> using namespace std; void BFS(map<int, int> &m1, int t) { queue<pair<int, int>> q1; set<int> set_help; set<int>::iterator p; q1.push(make_pair(t, 0)); m1[t] = 0; set_help.insert(t); int Value, step; while (q1.empty() == 0) { Value = q1.front().first; ...
#include <bits/stdc++.h> using namespace std; int func(int a) { int cnt = 0; while (a) { cnt++; a /= 10; } return cnt; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, k; cin >> n >> k; vector<long long> v(n); map<int, int> m[11]; long...
#include <bits/stdc++.h> using namespace std; int n; int p[300]; int main() { int i, k, j, l; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (i = 0; i < 2 * n; i++) { cin >> p[i]; } n *= 2; int result = 200000000; for (i = 0; i < n; i++) { ...
#include <bits/stdc++.h> int main() { int x, y, z; scanf( %d %d %d , &x, &y, &z); if (x > y + z) { printf( + n ); } else if (y > x + z) { printf( - n ); } else if (x == y && z == 0) { printf( 0 n ); } else { printf( ? n ); } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, k, cnt; int main() { scanf( %d%d%d , &n, &m, &k); if (4 * n * m - 2 * n - 2 * m < k) { puts( NO ); return 0; } puts( YES ); if (m == 1) { if (k <= n - 1) { puts( 1 ); printf( %d D n , k); } else { ...