akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

ll n, q;
string s;
V<char> t, d;

// Antsbook p.132
// minimum x (C(x) == true)
bool C(ll mid){
    rep(i, q){
        if(s[mid] == t[i]){
            mid += (d[i] == 'L' ? -1 : 1);
        }
        if(mid == n+1){
            return true;
        }
    }
    return false;
}

ll BinarySearchMin(ll lb, ll ub){
    // 返り値の範囲：(lb, ub]
    // 条件：
    //   (lb, ub]で検証できること
    //   C(lb)==false, C(ub)==true
    while(ub - lb > 1){
        ll mid = ((lb + ub) >> 1);
        if(C(mid)){
            // (lb, mid]
            ub = mid;
        }else{
            // (mid, ub]
            lb = mid;
        }
    }
    return ub;
}

// Antsbook p.132
// maximum x (C(x) == true)
bool D(ll mid){
    rep(i, q){
        if(s[mid] == t[i]){
            mid += (d[i] == 'L' ? -1 : 1);
        }
        if(mid == 0){
            return true;
        }
    }
    return false;
}

ll BinarySearchMax(ll lb, ll ub){
    // 返り値の範囲：[lb, ub)
    // 条件：
    //   [lb, ub)で検証できること
    //   C(lb)==true, C(ub)==false
    while(ub - lb > 1){
        ll mid = ((lb + ub) >> 1);
        if(D(mid)){
            // [mid, ub)
            lb = mid;
        }else{
            // [lb, mid)
            ub = mid;
        }
    }
    return lb;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cin >> n >> q;
    cin >> s;
    s = "n" + s + "n";
    t.resize(q);
    d.resize(q);
    rep(i, q){
        cin >> t[i] >> d[i];
    }
    // n+1に行く最小
    ll minr = BinarySearchMin(0, n+1);
    // 0に行く最大
    ll maxl = BinarySearchMax(0, n+1);
    cout << minr-maxl-1 << endl;
    return 0;
}

Measured memory_bytes: 952
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  constexpr int mod = 1e9 + 7;
  int n; cin >> n;
  vector<int> c(n);
  REP(i, n) cin >> c[i];

  map<int, ll> memo;
  map<int, int> cnt;

  ll ans = 1LL;
  REP(i, n){
    if(i > 0 && c[i-1] == c[i]) continue;

    ll tmp = ans;
    if(cnt[c[i]] > 0){
      (ans += memo[c[i]]) %= mod;
    }    
    (memo[c[i]] += tmp) %= mod;
    cnt[c[i]]++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 22912
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;

int main() {
    int n, m; cin >> n >> m;
    vector<int> cnt(n+1, 0);
    rep(i, m) {
        int l, r; cin >> l >> r;
        l--; r--;
        cnt[l]++;
        cnt[r+1]--;
    }
    rep(i, n) {
        cnt[i+1] += cnt[i];
    }
    int ans = 0;
    rep(i, n) {
        if (cnt[i] == m) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

const int NMAX = 100;
bool flag;


int main(){
    CIN(N);
    int ans=1;
    flag=false;
    while(1){
        if(2*ans>N)flag=true;
        if(flag) break;
        ans*=2;        
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if (n >= k)
    {
        cout << x * k + y * (n - k) << endl;
    }
    else
    {
        cout << x * n << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }

vector<ll> fact;
vector<ll> fact_inv;

void init_fact(int n) {
  fact.resize(n + 1);
  fact_inv.resize(n + 1);
  fact[0] = fact_inv[0] = 1;
  REP(i, n) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
    fact_inv[i + 1] = fact_inv[i] * mod_inv(i + 1) % MOD;
  }
}

ll nCr(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

ll nPr(ll n, ll r) { return nCr(n, r) * fact[r] % MOD; }

int n, k;
vector<int> g[100000];
ll ans = 1;

void dfs(int v, int p, int d) {
  int cnt = 0;
  for (int i = 0; i < g[v].size(); ++i) {
    if (g[v][i] == p) continue;
    dfs(g[v][i], v, d + 1);
    cnt++;
  }
  if (d == 0) {
    ans *= k;
    ans %= MOD;
    ans *= nPr(k - 1, cnt);
    ans %= MOD;
  } else {
    ans *= nPr(k - 2, cnt);
    ans %= MOD;
  }
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  init_fact(200000);
  dfs(0, -1, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14720
# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn = (int) 1e5 + 1;

int n;
string s;
int main(){
	cin >> n >> s;
	if(n % 2){
		cout << "No";
		return 0;
	}
	for(int i = 0; i < n / 2; i++){
		if(s[i] != s[n / 2 + i]){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long P = 1000000007;
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long dp[n + 1][k + 1], sdp[n + 1][k + 2];
  for (int i = 0; i <= k; i++)
    dp[0][i] = sdp[0][i] = 0;
  sdp[0][k + 1] = 0;
  sdp[0][0] = 0;
  sdp[0][1] = dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    sdp[i][0] = 0;
    for (int j = 1; j <= k + 1; j++) {
      sdp[i][j] = (sdp[i][j - 1] + dp[i][j - 1]) % P;
    }
    for (int j = 0; j <= k; j++) {
      dp[i + 1][j] = (sdp[i][j + 1] - sdp[i][max(0, j - a[i])] + P) % P;
    }
  }
  cout << dp[n][k] << endl;
  return 0;
}


Measured memory_bytes: 158080
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int h, w, a, b; cin >> h >> w >> a >> b;
    
    rep(i,h) {
        rep(j,w) {
            if ((i<b&&j<a) || (i>=b&&j>=a)) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<cstdio>
using namespace std ;

/*認識番号
  市iが県P[i]に属する市の中でx番目に誕生したなら、上6桁はP[i],下6桁はx*/
int main()
{
  int N,M ;
  cin>>N>>M ;
  /*所属する県P[i],誕生した年月Y[i],市の番号*/
  vector<tuple<int,int,int>>C ;
  for(int i=0;i<M;i++){
    int first,second ;
    cin>>first>>second ;
    C.push_back(make_tuple(first,second,i+1)) ;
  }
  sort(C.begin(),C.end()) ;
  
  vector<pair<int,string>>number ;
  int pre_P=get<0>(C.at(0)) ;
  int x=0 ;
  for(int i=0;i<M;i++){
    if(pre_P!=get<0>(C.at(i))){
      pre_P=get<0>(C.at(i)) ;
      x=0 ;
    }x++ ;
    string S,T ;
    S=to_string(pre_P) ;
    T=to_string(x) ;
    if(S.size()<6) while(S.size()!=6) S='0'+S ;
    if(T.size()<6) while(T.size()!=6) T='0'+T ;
    number.push_back(make_pair(get<2>(C.at(i)),S+T)) ;
  }
  sort(number.begin(),number.end()) ;
  for(int i=0;i<M;i++) cout<<number.at(i).second<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 8944
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, K;
    cin >> N >> K;

    vll A(N);
    REP(i, N) cin >> A[i];

    ll s = accumulate(ALL(A), 0LL);

    vector<ll> div;
    for(int i = 1; i * i <= s; ++i) {
        if (s % i == 0) {
            div.pb(i);

            if (i * i != s) div.pb(s / i);
        }
    }

    debug(div);

    ll ans = 1;
    for (auto &e: div) {
        vector<ll> R(N);
        REP(i, N) R[i] = A[i] % e;

        ll rs = accumulate(ALL(R), 0LL);
        if (rs % e != 0) continue;

        sort(ALL(R));
        reverse(ALL(R));

        debug(R)

        ll cnt = 0, p = rs / e;
        int i = 0;
        while(p > 0) {
            --p;
            cnt += e - R[i++];
        }

        if (cnt <= K) ans = max(e, ans);
    }

    print(ans);
    
}


Measured memory_bytes: 3652
#include<stdio.h>
int main(void)
{
 int n,a,b,i,k=0;
 scanf("%d %d %d",&n,&a,&b);
 for(i=a;i<=b;i++){
  if(n%i==0) k++;
 }
 printf("%d\n",k);
 return 0;
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;


template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    double N; cin >> N;
    double a=N/3.0;
    cout << a*a*a << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <cmath>

const long long INF = 1LL << 60;

int main() {
  int n, k;
  std::cin >> n >> k;
  long long h[n];
  long long dp[110000];
  for (int i = 0; i < 110000; i++)
    dp[i] = INF;
  
  for (int i = 0; i < n; i++)
    std::cin >> h[i];
  
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      if (dp[i + j] > dp[i] + abs(h[i] - h[i + j])) {
        dp[i + j] = dp[i] + abs(h[i] - h[i + j]);
      }
    }
  }
  std::cout << dp[n - 1] << "\n";
}

Measured memory_bytes: 5232
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

struct Range { int left; int right; };

int main() {
    int H, W; cin >> H >> W;
    vector<Range> walls(H);
    REP(y, H) {
        int A, B; cin >> A >> B; --A; --B;
        walls[y] = { A, B };
    }

    set<pair<int, int>> end_and_starts;
    multiset<int> x_dists;

    REP(x, W) {
        end_and_starts.insert({x, x});
        x_dists.insert(0);
    }

    REP(y, H) {
        auto wall = walls[y];
        auto lo = end_and_starts.lower_bound({ wall.left, 0 });
        auto hi = end_and_starts.lower_bound({ wall.right+1, 0 });
        if (lo != hi) {
            int max_start = -1;
            for (auto it = lo; it != hi; ) {
                max_start = max(max_start, it->second);
                int x_dist = it->first - it->second;
                it = end_and_starts.erase(it);
                x_dists.erase(x_dists.find(x_dist));
            }
            if (wall.right != W-1) {
                int new_end = wall.right + 1;
                end_and_starts.insert({ new_end, max_start });
                x_dists.insert(new_end - max_start);
            }
        }
        if (x_dists.empty()) {
            cout << "-1\n";
        } else {
            int min_x_dist = *x_dists.begin();
            cout << min_x_dist + y + 1 << '\n';
        }
    }
}


Measured memory_bytes: 23096
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int a[3],k; cin >> a[0] >> a[1] >> a[2] >> k;
    sort(a,a+3);
    REP(i,k) a[2] *= 2;
    cout << a[0] + a[1] + a[2] << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    ans = 0

    for i in range(n):
        xi, ui = input().split()

        if ui == 'JPY':
            ans += float(xi)
        else:
            ans += float(xi) * 380000

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;

int main ()
{

    int N; cin >> N;
    vector < ll > A(N);
    REP(i,N) cin >> A[i];

    sort(A.begin(), A.end());
    deque < ll > que;
    int l = 1, r = N - 1;
    int cnt = 0;
    que.push_back(A[0]);
    while (true) {
        if (cnt % 2 == 0) {
            que.push_front(A[r]);
            r--;
            if (que.size() < N) {
                que.push_back(A[r]);
                r--;
            }
        } else {
            que.push_front(A[l]);
            l++;
            if (que.size() < N) {
                que.push_back(A[l]);
                l++;
            }
        }
        if (que.size() == N) break;
        cnt++;
    }

    vector < ll > B;
    while (que.size() > 0) {
        B.push_back(que.front());
        que.pop_front();
    }

    l = 0, r = N - 1;
    cnt = 0;
    que.push_back(A[r]);
    r--;
    while (true) {
        if (cnt % 2 == 1) {
            que.push_front(A[r]);
            r--;
            if (que.size() < N) {
                que.push_back(A[r]);
                r--;
            }
        } else {
            que.push_front(A[l]);
            l++;
            if (que.size() < N) {
                que.push_back(A[l]);
                l++;
            }
        }
        if (que.size() == N) break;
        cnt++;
    }

    vector < ll > C;
    while (que.size() > 0) {
        C.push_back(que.front());
        que.pop_front();
    }

    REP(i,C.size()) {
        cerr << C[i] << " ";
    }
    cerr << endl;


    ll ans1 = 0;
    REP(i,B.size() - 1) {
        ans1 += abs(B[i] - B[i + 1]);
    }

    ll ans2 = 0;
    REP(i,C.size() - 1) {
        ans2 += abs(C[i] - C[i + 1]);
    }

    cout << max(ans1,ans2) << endl;

    return 0;
}


Measured memory_bytes: 4216
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define DIVCEIL(A,B) ((A+(B-1))/B)
using namespace std;


void solve(long long N, std::vector<long long> arr){
    map<long long, long long> cnts;
    for(auto a: arr)cnts[a]++;
    auto ans=0l;
    for(auto &kv: cnts){
        auto tmp = kv.second-kv.first;
        ans += (tmp < 0 ? kv.second : min(kv.second, tmp));
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 7040
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
constexpr auto oorret = 0;
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

int func(int a, int k) {
	int res = 0;
	while (a < k) {
		a *= 2;
		res++;
	}
	return res;
}



int main() {
	int n,k;
	cin >> n >> k;
	double res = 0;
	FOR(i, 1, n+1) {
		res += pow<double>(0.5, func(i, k)) / n;
	}
	cout << setprecision(20) << res << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define float long double
#define ss second
#define ff first
typedef vector<int> vi;
#define pb push_back

float dp[3001][3001];

float solve(int i,int j,int n,float *arr){
    if(dp[i][j]>=0) return dp[i][j];
    if(i == n){
        if(2*j > n) return dp[i][j] = 1;
        else return dp[i][j] = 0;
    }
    return dp[i][j] = arr[i]*solve(i+1,j+1,n,arr) +(1.0-arr[i])*solve(i+1,j,n,arr);
}


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n ;
	cin >> n;
	float *arr = new float[n];
	for(int i = 0; i < n ; i++) cin >> arr[i];
	for(int i =0 ; i < 3001; i++){
        for(int j  = 0 ;j < 3001 ; j++) dp[i][j] = -1;
	}

	float answer = 0 ;
	cout << fixed << setprecision(10);
	solve(0,0,n,arr);
	answer+= dp[0][0] ;
	cout << answer << endl;


}


Measured memory_bytes: 141312
#include <iostream>
#include <vector>

using namespace std;

const int N = 1e5;

int n;
int s[N];
bool kt[N];

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> s[i];

    long long res = 0;
    for (int i = 1; i < n - 1; ++i) {
        long long sum = 0;
        vector<int> modified;
        for (int l = i, r = n - 1 - i; l + i < n - 1; l += i, r -= i) {
            if (!kt[l]) {
                kt[l] = true;
                sum += s[l];
                modified.push_back(l);
            }
            else break;
            if (!kt[r]) {
                kt[r] = true;
                sum += s[r];
                modified.push_back(r);
            }
            else break;
            res = max(res, sum);
        }
        for (int x : modified) kt[x] = false;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int n,k;
    string s;
    cin >> n >> k;
    cin >> s;
    vector<int> vt;
    char now='1';
    int cnt=0;
    for(int i=0; i<s.size(); i++){
        if(now==s[i]){
            cnt++;
        }else{
            vt.push_back(cnt);
            now=s[i];
            cnt=1;
        }
    }
    if(cnt!=0) vt.push_back(cnt);
    if(vt.size()%2==0) vt.push_back(0);

    int add = 2*k+1;
    int ans=0;
    vector<int> sums(vt.size()+1);
    for(int i=0; i<vt.size(); i++){
        sums[i+1] = sums[i] + vt[i];
    }

    for(int i=0; i<vt.size(); i+=2){
        int left=i;
        int right=min(i+add, (int)vt.size());
        int tmp=sums[right]-sums[left];
        ans=max(ans, tmp);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1336
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

typedef long long ll;

using namespace std;
int main () {
int a, count = 0;
cin >> a;
for(;;){
if(a > count) {
    count +=1000;
}
else
{
    break;
}

}
cout << abs(count-a);

return 0 ;
}

Measured memory_bytes: 3192
using System;
using System.Linq;

namespace ABC071_C
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();

            Array.Sort(A);
            Array.Reverse(A);

            long l = 0;
            long w = 0;
            for (int i = 0; i < N-1; i++)
            {
                if (A[i] == A[i+1])
                {
                    if (l != 0)
                    {
                        w = A[i];
                        break;
                    }

                    l = A[i];
                    i++;
                }
            }
            Console.WriteLine(l * w == 0 ? 0 : l * w);
        }
    }
}


Measured memory_bytes: 23264
#include<bits/stdc++.h>
using namespace std;

int main(){
	int k,t,a[100];
	cin>>k>>t;
	int ma=0;
	for (int i = 0; i < t; i++){
		cin>>a[i];
		if(ma<a[i])
			ma=a[i];
	}

	cout<<max(ma-1-(k-ma),0)<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int count=0;
 vector<int> res;
  for(int i=0;i<k;i++){
    int temp;
    cin>>temp;
    for(int j=0;j<temp;j++){
      int x;
      cin>>x;
      res.push_back(x);
    }
  }
  for(int i=1;i<=n;i++){
    if(find(res.begin(),res.end(),i)==res.end())
      count++;
  }
  cout<<count;
}
      

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int H, W;
    int h, w;
    cin >> H >> W;
    cin >> h >> w;

    int X;

    X = (H * W) - (h * W) - (w * H) + (h * w);

    cout << X << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int MOD = 998244353;


//---------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& os, const ModInt<MOD>& mi) { return os << mi.get(); }
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
template<typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac;
    Comb() { fac.resize(FAC_MAX + 1, 1); ifac.resize(FAC_MAX + 1, 1);
        for (int i = 1; i <= FAC_MAX; i++) fac[i] = fac[i - 1] * i;
        for (int i = 1; i <= FAC_MAX; i++) ifac[i] = T(1) / fac[i]; }
    T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; }
    T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; }
    T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0;
        return aCb(n + k - 1, k); }
    T fact(int n) { if (n < 0) return T(0); return fac[n]; }
};
typedef ModInt<MOD> mint;
//---------------------------------------------------------------


int main() {
    Comb<mint, 300000> com;
    int N;
    ll A, B, K;
    cin >> N >> A >> B >> K;

    mint ans = 0;
    for (ll a = 0; a <= K / A; a++) {
        // A*a + B*b = K
        if ((K - A * a) % B) continue;
        ll b = (K - A * a) / B;
        ans += com.aCb(N, a) * com.aCb(N, b);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n,cx=0,cy=0,ct=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int t,x,y,v,tt;
		cin>>t>>x>>y;
		v=abs(cx-x)+abs(cy-y);
		tt=abs(ct-t);
		if(tt<v||(tt-v)%2==1){
			cout<<"No";
			return 0;
		}
		cx=x;
		cy=y;
		ct=t;
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 256
N, W = map(int, input().split())

IN = list(list(map(int, input().split())) for _ in range(N))
sumw = 0
sumv = 0
for w, v in IN:
    sumw += w
    sumv += v

DP = dict()
DP[sumv] = sumw

def minv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v < DP[i]:
            DP[i] = v

for w, v in IN:
    DPpre = DP.copy()
    for i in DPpre:
        minv(i-v, DPpre[i]-w)

for v in sorted(DP, reverse=True):
    if DP[v] <= W:
        print(v)
        break


Measured memory_bytes: 20848
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main()
{
  map<int, pair<int, int>> bingo;

  for (int i = 0; i < 3; ++i)
  {
    for (int k = 0; k < 3; ++k)
    {
      int tmp;
      cin >> tmp;
      bingo[tmp] = {i, k};
    }
  }

  vector<vector<int>> sheet(3, vector<int>(3));
  int N;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    int tmp;
    cin >> tmp;
    if (bingo.find(tmp) != bingo.end())
    {
      sheet[bingo.find(tmp)->second.first][bingo.find(tmp)->second.second]++;
    }
  }

  if (sheet[0][0] && sheet[1][0] && sheet[2][0])
  {
    cout << "Yes" << endl;
  }
  else if (sheet[0][1] && sheet[1][1] && sheet[2][1])
  {
    cout << "Yes" << endl;
  }
  else if (sheet[0][2] && sheet[1][2] && sheet[2][2])
  {
    cout << "Yes" << endl;
  }
  else if (sheet[0][0] && sheet[0][1] && sheet[0][2])
  {
    cout << "Yes" << endl;
  }
  else if (sheet[1][0] && sheet[1][1] && sheet[1][2])
  {
    cout << "Yes" << endl;
  }
  else if (sheet[2][0] && sheet[2][1] && sheet[2][2])
  {
    cout << "Yes" << endl;
  }
  else if (sheet[0][0] && sheet[1][1] && sheet[2][2])
  {
    cout << "Yes" << endl;
  }
  else if (sheet[0][2] && sheet[1][1] && sheet[2][0])
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
x = int(input())
base = 100
year = 0
while True:
    year = year + 1
    base = int(base * 1.01)
    if(x <= base):
        print(year)
        break

#結果：
#コード長:206 Byte 	
#処理速度：21 ms	
#メモリ： 9096 KB

Measured memory_bytes: 9116
#include <iostream>
#include <string>s

int main()
{
    uint8_t i = 0;
    std::string S;
    std::cin >> S;
    while(S[i] != 0x00){
        if((((i+1) % 2) == 0) && !((S[i] == 0x4C) || (S[i] == 0x55) || (S[i] == 0x44))){
            std::cout << "No" << std::endl; 
            return 0;
        }else if ((((i+1) % 2) == 1) && !((S[i] == 0x52) || (S[i] == 0x55) || (S[i] == 0x44))){
            std::cout << "No" << std::endl; 
            return 0;
        }

        i++;
    }
    std::cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] # solution for each key in A
res_list = {} # solution for each value in A

# counter ver
A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return int(j * (j-1) / 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  res_list[m] = s - combs[m] + ncr(A_c[m] - 1)

for k in range(N):
  res.append(res_list[A[k]])
print('\n'.join([str(s) for s in res]))

Measured memory_bytes: 52000
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N;
int X[1111];

int calc(int p) {
	int sum = 0;
	rep (i, N) {
		int t = X[i] - p;
		sum += t *t;
	}
	return sum;
}

signed main() {
	cin >> N;
	rep (i, N) {
		cin >> X[i];
	}

	int ans = 1e9;
	for (int i = -100000; i <= 100000; i++) {
		int t = calc(i+1);
		// dbg(t)
		chmin(ans, t);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main() {
        char str1[20000],str2[20000],str3[20000];
        int len1,len2,len3;
        scanf("%s",str1);
        scanf("%s",str2);
        scanf("%s",str3);
        len1=strlen(str1);
        len2=strlen(str2);
        len3=strlen(str3);
        if(str1[len1-1]==str2[0] && str2[len2-1]==str3[0]) printf("YES");
        else printf("NO");
    	return 0;
    }


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
signed main(){
	int a,b,c;
	cin>>a>>b;
	f(i,b){
		cin>>c;
		a-=c;
	}
	if(a<=0)puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
#include <stdio.h>
#define D_SIZE_BUFF 200000

int main()
{
    long N;
    int a,bucket[D_SIZE_BUFF];

    scanf("%ld",&N);

    for( int i=0; i<N; i++)
    {
        scanf("%d",&a);
        bucket[a-1] = i+1;
    }

    for( int i=0;i<N; i++)
    {
        printf("%d",bucket[i]);
        if( i < N-1) printf(" ");
    }

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e5 + 5;
int i, n, x, y;
vector<int> v[Nmax];

int solve(int node, int dad = -1)
{
    int ans = 0, cnt = 0;
    for(auto it : v[node])
        if(it != dad)
        {
            int nr = solve(it, node);
            if(!nr) ++cnt;
            ans += nr;
        }
    return ans + max(cnt-1, 0);
}

int main()
{
   // freopen("input", "r", stdin);
  //  freopen("output", "w", stdout);

    cin >> n;
    for(i=1; i<n; ++i)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    for(i=0; i<n; ++i)
        if(v[i].size() >= 3)
        {
            cout << solve(i, -1) << '\n';
            return 0;
        }
    cout << 1 << '\n';
    return 0;
}


Measured memory_bytes: 9088
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    T=int(input())         
    for _ in range(T):
        N,A,B,C,D=map(int,input().split())
        memo={}
        def saiki(m):
            if m in memo:
                return memo[m]
            if m==0:
                tmp=0
            elif m==1:
                tmp=D
            else:
                tmp=INF
                for k,P in [(2,A),(3,B),(5,C)]:
                    tmp=min(tmp,saiki(m//k)+(m-m//k*k)*D+min((m//k*k-m//k)*D,P))
                    tmp=min(tmp,saiki(-(-m//k))+(-(-m//k)*k-m)*D+min(((-(-m//k))*k+(-m//k))*D,P))
            memo[m]=tmp
            return tmp
        print(saiki(N))

if __name__ == '__main__':
    main()


Measured memory_bytes: 90228
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, lamp = 1, count = 0;
  cin >> N;
  vector<int> a(N);
  
    for (int i = 0; i < N; i++){
      cin >> a.at(i);
    }
  
  while(lamp != 2){
    lamp = a.at(lamp - 1);
    count++;
    if (count > N)
      break;
  }
      
  if (count <= N)
    cout << count << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 640
n,m = map(int,input().split())
s = [list(map(int,input().split())) for i in range(m)]
l = s[0][0]
r = s[0][1]
for i,j in s:
  if i>l:l=i
  if j<r:r=j
print(max(0,r-l+1))

Measured memory_bytes: 27336
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int main(){
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N);
    rep(i, N){
        cin >> a[i] >> b[i] >> c[i];
    }

    vector<int> adp(N), bdp(N), cdp(N);
    adp[0] = a[0];
    bdp[0] = b[0];
    cdp[0] = c[0];
    FOR(i, 1, N){
        adp[i] = a[i] + max(bdp[i-1], cdp[i-1]);
        bdp[i] = b[i] + max(adp[i-1], cdp[i-1]);
        cdp[i] = c[i] + max(adp[i-1], bdp[i-1]);
    }

    cout << max({adp[N-1], bdp[N-1], cdp[N-1]}) << endl;

    return 0;
}

Measured memory_bytes: 2688
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int[] integar=new int[3];
for(int i=0; i<integar.length; i++){
integar[i]=scan.nextInt();
}
for(int j=0; j<integar.length; j++){
for(int k=integar.length-1; k>j; k--){
if(integar[k]<integar[k-1]){
int temp=integar[k];
integar[k]=integar[k-1];
integar[k-1]=temp;
}
}
}
System.out.println(integar[0]+" "+integar[1]+" "+integar[2]);
}
}   

Measured memory_bytes: 26104
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
 

 
int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
 
    int m = 2019;
    vector<int> count(m);
 
    int t = 0, x = 1;
    long long ans = 0;
 
    for (int i = 0; i < s.size(); i++) {
        count[t]++;
        t += (s[i] - '0') * x;
        t %= m;
        ans += count[t];
        x = x * 10 % m;
    }
 
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3724
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>

#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define ld long double

using namespace std;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
ll ans = 0, mx = 0, mn = 1e9, sum = 0, cnt = 0, avr = 0, index = 0;

//map<int, int>freq;
vector<int>vec;
vector<int>res;
vector<int>freq(10000+5,0);
vector<int>cFreq(150, -1);

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		vec.push_back(x);
		mx = max(mx, x);
		sum += vec[i];
	}
	ll sub = sum - mx;
	if (sub > mx) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main(){
  long n,k;
  cin >> n >> k;

  while(n > 0){
    if(n % k < n) n = n % k;
    else if((-n + k) % k < n) n = (-n + k) % k;
    else break;
  }
  cout << n << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)

int main(){
    long int n, k;
    cin >> n >> k;
    long int a[n];
    rep(i, n){
        long int num = i + 1;
        long int bin = 0;
        while(num < k){
            num *= 2;
            bin++;
        }
        a[i] = bin;    
    }
    // rep(i,n) cout << a[i] << " ";
    // cout << endl;
    long int sm = 0;
    long int sq[a[0]+1];
    sq[0] = 1;
    for(int i = 1; i <= a[0]; i++){
        sq[i] = sq[i-1] * 2;
    }
    // rep(i,a[0]+1) cout << sq[i] << " ";
    // cout << endl;
    rep(i, n){
        sm += sq[a[0]-a[i]];
    }
    // cout << sm << endl;
    double ans = (double)sm / (double)(sq[a[0]] * n);
    printf("%.16f\n", ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n; sc(n)
    ll time;
    vector<int> c(n), s(n), f(n);
    for (int i = 0; i < n - 1; i++){
        sc(c[i]) sc(s[i]) sc(f[i])
    }
    for (int i = 0; i < n; i++){
        if (i < n - 1) time = s[i] + c[i];
        else time = 0;
        for (int j = i + 1; j < n - 1; j++){
            if (s[j] >= time){
                time += s[j] - time + c[j];
            }else {
                if (time % f[j] == 0) time += c[j];
                else time += f[j] - (time % f[j]) + c[j];
            }
        }
        cout << time << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from math import sqrt

n, m = map(int, input().split())
isqrtm = int(sqrt(m))
for revdiv in range(1, 1+isqrtm):
	if m % revdiv == 0:
		div = m // revdiv
		if div <= m//n:
			print(div)
			sys.exit()
for div in range(isqrtm, 0, -1):
	if m % div == 0:
		if div <= m//n:
			print(div)
			sys.exit()


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication27
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (a[0] == 0 && a[1] == 0) break;
                Array.Sort(a);
                Console.WriteLine("{0} {1}",a[0],a[1]);
            }
        }
    }
}

Measured memory_bytes: 9888
//============================================================================
// Name        : a.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
using namespace std;

int main() {
	int n;cin>>n;
	vector<int> a(n);
	int odd,even;
	odd=even=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2){
			odd++;
		}else{
			even++;
		}
	}
	if(odd%2){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();

        if (((a.charAt(0) == a.charAt(1)) && (a.charAt(1) == a.charAt(2))) || ((a.charAt(1) == a.charAt(2)) && (a.charAt(2) == a.charAt(3))))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 35420
//Source : https://www.geeksforgeeks.org/convert-number-negative-base-representation/
#include <bits/stdc++.h>
using namespace std;

//  Utility method to convert integer into string
string toString(int n)
{
    string str;
    stringstream ss;
    ss << n;
    ss >> str;
    return str;
}

// Method to convert n to base negBase
string toNegativeBase(int n, int negBase)
{
    //  If n is zero then in any base it will be 0 only
    if (n == 0)
        return "0";

    string converted = "";
    while (n != 0)
    {
        // Get remainder by negative base, it can be
        // negative also
        int remainder = n % negBase;
        n /= negBase;

        // if remainder is negative, add abs(base) to
        // it and add 1 to n
        if (remainder < 0)
        {
            remainder += (-negBase);
            n += 1;
        }

        // convert remainder to string add into the result
        converted = toString(remainder) + converted;
    }

    return converted;
}

//  Driver code to test above methods
int main()
{
    long long n;
    scanf("%lld", &n);
    cout<<toNegativeBase(n, -2);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n,t;
	cin>>n>>t;
	int bef=0;
	int ans=0;
	rep(i,n){
		int ti;
		cin>>ti;
		if(bef+t<ti){
			ans+=t;
		}else{
			ans+=ti-bef;
		}
		bef=ti;
		
	}
	ans+=t;
	cout<<ans<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 256
import numpy as np
n,k = map(int,input().split())
item_count = {}
for i in range(n):
    a,b = map(int,input().split())
    if a not in item_count:
        item_count[a] = 0
    item_count[a] += b
sorted_ls = sorted(item_count.items(), key = lambda x:x[0])
nums_ls = list(item_count.keys())
nums_ls.sort()
count_ls = [item[1] for item in sorted_ls]
csum_count = list(np.cumsum(count_ls))

def isOK(index, key, l):
    if l[index] >= key:
        return True
    else:
        return False
def meguru_search(l, key):
    left = -1
    right = len(l)
    while (right - left) > 1:
        mid = left + (right - left) // 2
        # 直感的に記憶　
            # 「含まれている」んだったら「含むを許容（等号付き）する右側」はmidまで動かして問題ない
                # 新しいrightの位置がkeyの位置だとしても、「含む」は許容されてる
            # 「含まれていない」んだったら「含まない(<)左の壁」をそこまで動かしてもkeyを通り過ぎることはない
        if isOK(mid, key, l):
            right = mid
        else:
            left = mid
    # whileを抜ける時、rightとleftは一個差で、かつkeyがrightの位置にある
    return right

ind = meguru_search(csum_count, k)
ans = nums_ls[ind]
print(ans)


    


Measured memory_bytes: 27528