malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long t, d, ct, q, ans, l, m, r, n, mx, mn, i, j, k, x, y, z, s;   char ch;   string ss =   , str =   ;   long long a[200003], b[200003];   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     s = k = d = l = mx = m = mn = r = q = i = j = z = x = y = ct = ans = 0;     stack<long long> st;     cin >> ss;     n = ss.length();     long long dp[n + 2];     memset(dp, 0, sizeof(dp));     for (i = 0; i < n; i++) {       if (ss[i] ==  ( ) {         st.push(i);         continue;       }       if (st.empty()) continue;       long long lft = st.top();       st.pop();       if (lft)         dp[i] = dp[lft - 1] + i - lft + 1;       else         dp[i] = i - lft + 1;       mx = max(mx, dp[i]);     }     for (i = 0; i < n; i++)       if (dp[i] == mx) ct++;     if (!mx) return cout <<  0 1 , 0;     cout << mx <<     << ct;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200100];   deque<int> Q;   bool cnt[10001000];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]] = true;     sort(a, a + n);     int Min = a[0], Max = a[n - 1], Ans = 0;     for (int i = Min; i <= 1e7; i++) {       if (Q.size() && Q.front() < i - m) Q.pop_front();       if (i >= Min + m - 1)         while (Q.size() >= k) Q.pop_back(), Ans++;       if (cnt[i]) Q.push_back(i);     }     cout << Ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1003];   const int mod = 1000000007;   int comb[1005][1005], i, j;   int main() {     int lim = 1002;     for (i = 1; i <= lim; i++) comb[i][i] = comb[i][0] = 1;     for (i = 2; i <= lim; i++)       for (j = 1; j < i; j++) {         long long aux = comb[i - 1][j] + comb[i - 1][j - 1];         aux %= mod;         comb[i][j] = aux;       }     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     long long ans = 1;     long long nr = a[1];     for (i = 2; i <= n; i++) {       int en = a[i] - 1;       ans = (1LL * ans * comb[en + nr][en]) % mod;       nr += a[i];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char buf[5000010], ch;   int a[5000010];   int dc[] = {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};   int sd = 24 * 60 * 60;   int main() {     int n, m, top = 1;     int YY, MM, DD, hh, mm, ss;     scanf( %d%d , &n, &m);     getchar();     a[0] = 0xc0c0c0c0;     while (gets(buf)) {       sscanf(buf,  %d%c%d%c%d%c%d%c%d%c%d , &YY, &ch, &MM, &ch, &DD, &ch, &hh,              &ch, &mm, &ch, &ss);       int t = (dc[MM] + DD - 1) * sd + hh * 60 * 60 + mm * 60 + ss;       a[top++] = t;       t -= n - 1;       int l = 0, r = top - 1;       while (l < r - 1) {         int mid = l + r >> 1;         if (a[mid] < t)           l = mid;         else           r = mid;       }       if (top - r >= m) {         buf[19] = 0;         printf( %s n , buf);         return 0;       }     }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     for (long long y = 2; y <= 10005; y++) {       for (long long z = y + 1; z <= 10005; z++) {         if (2 * y * z - n * y - n * z <= 0) continue;         long long x = (n * y * z) / (2 * y * z - n * y - n * z);         if ((n * y * z) % (2 * y * z - n * y - n * z) == 0 && x <= 1000000000 &&             x != y && x != z && y != z) {           cout << x <<     << y <<     << z <<   n ;           return 0;         }       }     }     cout << -1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y, ans;   string s;   int main() {     cin >> n;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  U ) y++;       if (s[i] ==  D ) y--;       if (s[i] ==  L ) x--;       if (s[i] ==  R ) x++;     }     if (y < 0) y *= (-1);     if (x < 0) x *= (-1);     ans = n - x - y;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, ans = 0;   int MUL(int u, int v) { return (int)((1LL * u * v) % (int)(1e9 + 7)); }   int main() {     scanf( %d%d%d , &n, &m, &x);     if (n > m) {       cout << 0 << endl;       return 0;     }     int dp[m + 10][n + 10][n + 10][2];     dp[m + 1][n][0][1] = 1;     for (int i = m; i >= 1; i--) {       for (int k = 0; k <= n; k++) {         for (int ng = 0; ng <= n; ng++) {           for (int pre = 0; pre <= 1; pre++) {             int ans = 0;             ans = (ans + dp[i + 1][k][ng + 1][pre || (i == x)]) % (int)(1e9 + 7);             ans = (ans + dp[i + 1][k][ng][pre]) % (int)(1e9 + 7);             ans = (ans + dp[i + 1][k + 1][ng - 1][pre]) % (int)(1e9 + 7);             ans = (ans + dp[i + 1][k + 1][ng][pre || (i == x)]) % (int)(1e9 + 7);             dp[i][k][ng][pre] = ans;           }         }       }     }     int ans = dp[1][0][0][0];     for (int i = 1; i <= n; i++) ans = MUL(ans, i);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int v, id;     node(int _id) {       id = _id;       cin >> v;     }     bool operator<(const node& from) const { return v > from.v; }   };   vector<node> Q;   bool IN[200005];   int l[200005];   int r[200005];   int pt = 1, mx = 1;   void update(int x) {     IN[x] = 1;     if (IN[x - 1]) l[x] = l[x - 1];     if (IN[x + 1]) r[x] = r[x + 1];     r[l[x]] = r[x];     l[r[x]] = l[x];     mx = max(mx, r[x] - l[x] + 1);   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) Q.push_back(node(i));     for (int i = 1; i <= n; i++) l[i] = r[i] = i;     sort(Q.begin(), Q.end());     int pt = 1;     for (int i = 0; i < n; i++) {       while (i < n and Q[i + 1].v == Q[i].v) update(Q[i++].id);       update(Q[i].id);       for (; pt <= mx; pt++) cout << Q[i].v <<    ;     }     return 0;   }
#include <bits/stdc++.h>   int n;   int main() {     int i;     long long ans, sumx, sumy, x, y;     scanf( %d , &n);     ans = sumx = sumy = 0;     for (i = 0; i < n; i++) {       scanf( %I64d%I64d , &x, &y);       ans += (long long)x * x * n + y * y * n;       sumx += x;       sumy += y;     }     printf( %I64d , ans - sumx * sumx - sumy * sumy);   }
#include <bits/stdc++.h>   using namespace std;   int dp[1000000], arr[1000000];   int main() {     int fi = 1, se = 1;     int n;     cin >> n;     int last = 20;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       arr[i] = x;       if (i == 1) {         cout << 20 <<   n ;         dp[i] = 20;         continue;       }       while (arr[fi] + 90 <= arr[i]) fi++;       while (arr[se] + 1440 <= arr[i]) se++;       dp[i] = 20 + dp[i - 1];       dp[i] = min(dp[i], dp[fi - 1] + 50);       dp[i] = min(dp[i], dp[se - 1] + 120);       cout << dp[i] - last <<   n ;       last = dp[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fr[300005], v[300005];   int main() {     int n, i, x, sol = 0, pos1, pos2, cate = 0;     cin >> n;     for (i = 1; i <= n; ++i) {       cin >> v[i];       x = v[i];       ++fr[x];       if (fr[x] == 1) ++cate;       if (cate == 1 && fr[x] == 1) pos1 = i;       if (cate == 2 && fr[x] == 1) sol = max(sol, i - pos1), pos2 = i;       if (cate >= 2) {         if (v[pos1] == v[i])           sol = max(sol, i - pos2);         else           sol = max(sol, i - pos1);       }     }     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int t[4] = {1, 1, 2, 1};     getline(cin, s);     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  h  && t[0]) {         t[0]--;       } else if (s[i] ==  e  && t[1] && !t[0]) {         t[1]--;       } else if (s[i] ==  l  && !t[1] && t[2]) {         t[2]--;       } else if (s[i] ==  o  && !t[2] && t[3]) {         t[3]--;       }     }     if (!(t[0] + t[1] + t[2] + t[3])) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, k;       scanf( %d %d , &n, &k);       int div = n / k;       int mod = n % k;       for (int i = 0; i < k; i++) {         for (int j = 1; j <= div; j++) {           printf( %c , ( a  + i));         }         if (mod) {           printf( %c , ( a  + i));           mod--;         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   void err() { std::cout << std::endl; }   template <typename T, typename... Args>   void err(T a, Args... args) {     std::cout << a <<    ;     err(args...);   }   using namespace std;   const int mod = 998244353;   const int inf = 1 << 30;   const int maxn = 200000 + 5;   const int maxq = 3000 + 5;   long long qpow(long long x, long long n) {     long long r = 1;     while (n > 0) {       if (n & 1) r = r * x % mod;       n >>= 1;       x = x * x % mod;     }     return r;   }   long long inv(int x) { return qpow(x, mod - 2); }   void add(long long& x, long long y) {     x += y;     if (x >= mod) x -= mod;   }   int n, m, a[maxn], w[maxn];   long long f[maxq][maxq];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     int sa = 0, sb = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , w + i);       if (a[i])         sa += w[i];       else         sb += w[i];     }     f[0][0] = 1;     for (int i = 0; i < m; i++) {       for (int j = 0; j <= i; j++) {         int a = sa + j, b = sb - (i - j);         long long fm = inv(a + b);         add(f[i + 1][j + 1], f[i][j] * a % mod * fm % mod);         add(f[i + 1][j], f[i][j] * b % mod * fm % mod);       }     }     long long ea = 0, eb = 0;     for (int i = 0; i <= m; i++) {       ;       add(ea, f[m][i] * (sa + i) % mod);       add(eb, f[m][i] * (sb - (m - i)) % mod);     };     long long iva = inv(sa), ivb = inv(sb);     for (int i = 1; i <= n; i++) {       if (a[i]) {         printf( %lld n , 1ll * w[i] * iva % mod * ea % mod);       } else {         printf( %lld n , 1ll * w[i] * ivb % mod * eb % mod);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double a[(1000000)], x[(1000000)];   long double b[(1000000)], y[(1000000)];   int n, A, B;   long double ans;   const long double inf = 3e9;   bool check(double t) {     int k = B;     long double cnt = inf * inf;     for (int i = A; i > 0; i--) {       while (k && y[k] >= x[i]) {         cnt = min(cnt, y[k] + t * b[k]);         k--;       }       if (x[i] + t * a[i] >= cnt) return true;     }     return false;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       double P, V;       scanf( %lf%lf , &P, &V);       if (V < 0.) {         B++;         y[B] = P;         b[B] = V;       } else {         A++;         x[A] = P;         a[A] = V;       }     }     double l = 0., r = inf;     ans = -1;     for (int T = 0; T < 100; T++) {       double mid = (l + r) / 2.;       if (check(mid)) {         ans = mid;         r = mid;       } else         l = mid;     }     if (ans < 0.)       puts( -1 );     else {       cout.precision(10);       cout << fixed;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   int n, a[maxn];   long long k;   long long f[maxn];   int main() {     scanf( %d %I64d , &n, &k);     f[0] = f[1] = 1;     for (int i = 2; i <= n; i++) f[i] = f[i - 1] + f[i - 2];     for (int i = 1; i <= n;) {       if (f[n - i] >= k) {         a[i] = i;         i++;       } else {         k -= f[n - i];         a[i] = i + 1;         a[i + 1] = i;         i += 2;       }     }     for (int i = 1; i <= n; i++) printf( %d  , a[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       if (k >= n)         cout << abs(n - k) << endl;       else {         if (n % 2 == 0) {           if (k % 2 == 1)             cout << 1 << endl;           else             cout << 0 << endl;         } else if (n % 2 == 1) {           if (k % 2 == 0)             cout << 1 << endl;           else             cout << 0 << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool marked[100000 + 2];   vector<int> prime;   int ase[100000 + 2], num[100000 + 2];   bool isPrime(int n) {     if (n < 2) return false;     if (n == 2) return true;     if (n % 2 == 0) return false;     return marked[n] == false;   }   void sieve(int n) {     for (int i = 3; i * i <= n; i += 2) {       if (marked[i] == false) {         for (int j = i * i; j <= n; j += i + i) {           marked[j] = true;         }       }     }     prime.push_back(2);     for (int i = 3; i <= n; i += 2) {       if (!marked[i]) {         prime.push_back(i);       }     }   }   vector<pair<int, int> > ans;   void correct(int x) {     if (num[x] == x) {       return;     }     int j = ase[x];     int k = j - *(upper_bound(prime.begin(), prime.end(), j - x + 1) - 1) + 1;     int a;     a = num[j], num[j] = num[k], num[k] = a;     ase[num[k]] = k, ase[num[j]] = j;     ans.push_back(pair<int, int>(k, j));     correct(x);   }   int main(int argc, char** argv) {     sieve(100000);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &num[i]);       ase[num[i]] = i;     }     getchar();     for (int i = 1; i <= n; i++) {       correct(i);     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i].first <<     << ans[i].second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int calc(long long a, long long n) {     long long res = 1;     while (n > 0) {       if (n & 1) res = (res * a) % MOD;       a = (a * a) % MOD;       n /= 2;     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     long long n;     cin >> n;     long long x = calc(2, n);     cout << x * (x + 1) / 2 % MOD;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2 * 1e9;   const double EPS = 1e-9;   const int MaxN = 100000 + 5;   const int MaxM = 2 * 100000 + 5;   int N, M, S, L, Dist[MaxN];   typedef struct Node {     int idx;     Node(void) {}     Node(int _idx) { idx = _idx; }     inline bool operator<(const Node &NewNode) const {       return Dist[idx] > Dist[NewNode.idx];     }   };   typedef struct Edge {     int idx, Weight;     Edge(void) {}     Edge(int _idx, int _Weight) {       idx = _idx;       Weight = _Weight;     }   };   vector<Edge> E[MaxM];   inline void Dijkstra(int Start) {     for (int i = 0; i < N; i++) Dist[i] = INF;     priority_queue<Node> PQ;     PQ.push(Node(Start));     Dist[Start] = 0;     while (!PQ.empty()) {       Node CurrNode = PQ.top();       PQ.pop();       for (vector<Edge>::iterator it = E[CurrNode.idx].begin();            it != E[CurrNode.idx].end(); it++) {         Node NextNode = Node((*it).idx);         int Weight = (*it).Weight;         if (Dist[CurrNode.idx] + Weight < Dist[NextNode.idx]) {           Dist[NextNode.idx] = Dist[CurrNode.idx] + Weight;           PQ.push(NextNode);         }       }     }   }   vector<pair<pair<int, int>, int> > Edges;   int main(void) {     scanf( %d %d %d , &N, &M, &S);     S--;     for (int i = 0; i < M; i++) {       int idx, idy, Weight;       scanf( %d %d %d , &idx, &idy, &Weight);       idx--;       idy--;       E[idx].push_back(Edge(idy, Weight));       E[idy].push_back(Edge(idx, Weight));       Edges.push_back(make_pair(make_pair(idx, idy), Weight));     }     scanf( %d , &L);     Dijkstra(S);     int Sol = 0;     for (int i = 0; i < N; i++)       if (Dist[i] == L) Sol++;     for (int i = 0; i < M; i++) {       int idx = Edges[i].first.first, idy = Edges[i].first.second,           Weight = Edges[i].second;       int Pos1 = -1, Pos2 = -1;       if ((Dist[idx] < L) && (L < Dist[idx] + Weight) &&           (L <= Dist[idy] + Dist[idx] + Weight - L))         Pos1 = L - Dist[idx];       if ((Dist[idy] < L) && (L < Dist[idy] + Weight) &&           (L <= Dist[idx] + Dist[idy] + Weight - L))         Pos2 = Dist[idy] + Weight - L;       if (Pos1 >= 0) Sol++;       if ((Pos2 >= 0) && (Pos2 != Pos1)) Sol++;     }     printf( %d n , Sol);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     set<char> s;     char a[100005];     s.insert( A );     s.insert( H );     s.insert( I );     s.insert( M );     s.insert( O );     s.insert( T );     s.insert( U );     s.insert( V );     s.insert( W );     s.insert( X );     s.insert( Y );     scanf( %s , &a);     int n = strlen(a);     for (int i = 0; i < n; i++) {       if (s.find(a[i]) == s.end() || a[i] != a[n - 1 - i]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t = 1, T;   void print2d(vector<vector<long long>> &v) {     for (long long i = 0; i < v.size(); i++) {       for (long long x : v[i]) {         cout << x <<    ;       }       cout <<   n ;     }   }   void print(vector<long long> &a) {     for (long long x : a) {       cout << x <<    ;     }     cout <<   n ;     return;   }   long long fun(long long x, long long y) { return x * x + y * y; }   void solve() {     long long n;     cin >> n;     vector<long long> a(n, 0);     vector<long long> freq(n + 1, 0);     long long x;     for (long long i = 0; i < n; i++) {       cin >> a[i];       freq[a[i]]++;     }     set<long long> v;     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j < n; j++) {         v.insert(a[i] + a[j]);       }     }     long long ans = 0;     for (long long sum : v) {       long long i, j;       if (sum & 1) {         i = sum / 2;         j = i + 1;       } else         i = j = sum / 2;       long long rep = 0;       while (i >= 1 && j <= n) {         if (i == j) {           rep += freq[i] / 2;           i--;           j++;         } else {           rep += min(freq[i], freq[j]);           i--;           j++;         }       }       ans = max(ans, rep);     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> t;     T = t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   int battle(std::string player1, std::string player2) {     if (player1 == player2) {       return 0;     }     if (player1 ==  rock ) {       if (player2 ==  scissors ) {         return 1;       } else {         return -1;       }     }     if (player1 ==  paper ) {       if (player2 ==  rock ) {         return 1;       } else {         return -1;       }     }     if (player1 ==  scissors ) {       if (player2 ==  paper ) {         return 1;       } else {         return -1;       }     }   }   int main(int argc, char const *argv[]) {     std::string fyodor, matroskin, sharic;     std::cin >> fyodor >> matroskin >> sharic;     std::string winner =  ? ;     if (battle(fyodor, matroskin) == 1) {       if (battle(fyodor, sharic) == 1) {         winner =  F ;       }     } else if (battle(fyodor, matroskin) == -1) {       if (battle(matroskin, sharic) == 1) {         winner =  M ;       }     } else {       if (battle(sharic, fyodor) == 1) {         winner =  S ;       }     }     std::cout << winner <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   void io() {}   long long fast_exp(long long base, int exp, int m) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1) {         res = (res * base) % m;       }       base = (base * base) % m;       exp /= 2;     }     return res % m;   }   long long arr[200005];   long long val[200005];   long long siz[200005];   map<long long, long long> mp;   long long ans, cnt, tmp;   long long vis[200005];   vector<long long> adj[200005];   long long dp[2001][2001];   long long n, m, k;   int main() {     io();     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 0;     cin >> arr[0] >> arr[1] >> arr[2];     sort(arr, arr + 3);     if (arr[2] - arr[1] - arr[0] < 0) {       cout << 0 <<   n ;       return 0;     }     cout << arr[2] - arr[1] - arr[0] + 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a, b;   vector<int> undiradj[100001];   vector<int> diradj[100001];   vector<int> dirjda[100001];   stack<int> s;   bool vis[100001];   vector<int> scc[100001];   bool isinscc[100001];   bool hascycle;   void dfs(int node) {     if (!vis[node]) {       vis[node] = true;       for (int i = 0; i < diradj[node].size(); i++) {         dfs(diradj[node][i]);       }       s.push(node);     }   }   void sfd(int node, int con) {     if (!vis[node]) {       vis[node] = true;       scc[con].push_back(node);       for (int i = 0; i < dirjda[node].size(); i++) {         sfd(dirjda[node][i], con);       }     }   }   int undirdfs(int node) {     if (!vis[node]) {       if (isinscc[node]) hascycle = true;       int cnt = 0;       vis[node] = true;       for (int i = 0; i < undiradj[node].size(); i++) {         cnt += undirdfs(undiradj[node][i]);       }       cnt++;       return cnt;     }     return 0;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b;       undiradj[a].push_back(b);       undiradj[b].push_back(a);       diradj[a].push_back(b);       dirjda[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       vis[i] = false;     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         dfs(i);       }     }     for (int i = 1; i <= n; i++) {       vis[i] = false;     }     int cc = 0;     while (!s.empty()) {       int curnode = s.top();       s.pop();       if (!vis[curnode]) {         sfd(curnode, cc);         if (scc[cc].size() > 1) {           for (int i = 0; i < scc[cc].size(); i++) {             isinscc[scc[cc][i]] = true;           }         }         cc++;       }     }     for (int i = 1; i <= n; i++) {       vis[i] = false;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         hascycle = false;         int v = undirdfs(i);         if (hascycle)           ans += v;         else           ans += (v - 1);       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s =   ;     int r = 1;     while (s.size() < 1050) {       int k = r;       string t =   ;       while (k > 0) {         t = char((k % 10) +  0 ) + t;         k = k / 10;       }       s = s + t, r++;     }     cout << s[n - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n;     long int a = 0, b = 0, c = 0;     for (int i = 0; i < n; i++) {       cin >> k;       a = a + k;     }     for (int i = 0; i < n - 1; i++) {       cin >> k;       b = b + k;     }     for (int i = 0; i < n - 2; i++) {       cin >> k;       c = c + k;     }     cout << a - b << endl << b - c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     if (n == 1 || m == 1)       cout << max(n, m);     else if (m == 2 && n % 4)       cout << n + 2 - (n & 1);     else if (n == 2 && m % 4)       cout << m + 2 - (m & 1);     else       cout << (n * m) - ((n * m) / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long dsum(unsigned long long n) {     unsigned long long res = 0;     while (n) {       res += n % 10;       n /= 10;     }     return res;   }   int main() {     unsigned long long n, s;     cin >> n >> s;     unsigned long long dif = n - dsum(n);     if (dif < s)       cout << 0 << endl;     else {       unsigned long long l = 1, h = n;       while (h - l > 0) {         unsigned long long mid = l + (h - l) / 2;         unsigned long long x = dsum(mid);         dif = mid - x;         if (dif < s) {           l = mid + 1;         } else           h = mid;       }       if (n - dsum(l) >= s) l--;       cout << n - l << endl;     }   }