akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
constexpr int INF = 100100100;

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T, typename FnT>
class SegmentTree {
  public:
    explicit SegmentTree(FnT const &app, T const &un, size_t size):
      SegmentTree(app, un, std::vector<T>(size, un)) {
    }
    explicit SegmentTree(FnT const &app, T const &un, std::vector<T> const &v):
      append(app), unit(un), N(1 << log2(v.size())), dat(2*N-1) {
      std::copy(begin(v), end(v), begin(dat)+N-1);
      for (size_t k = N - 1; k > 0; --k) {
        dat[k-1] = append(dat[2*k-1], dat[2*k]);
      }
    }
    void update(size_t k, T x) {
      k += N - 1;
      dat[k] = x;
      while (k > 0) {
        k = (k - 1) / 2;
        dat[k] = append(dat[2*k+1], dat[2*k+2]);
      }
    }
    T at(size_t k) const {
      return dat[k+N-1];
    }
    T query(size_t a, size_t b, size_t k, size_t l, size_t r) const {
      if (r <= a || b <= l) { return unit; }
      if (a <= l && r <= b) { return dat[k]; }
      const auto mid = (l + r) / 2;
      const auto vl = query(a, b, 2*k+1, l, mid);
      const auto vr = query(a, b, 2*k+2, mid, r);
      return append(vl, vr);
    }
    T query(size_t a, size_t b) const {
      return query(a, std::min(b, N), 0, 0, N);
    }
    T query() const {
      return query(0, N, 0, 0, N);
    }
  private:
    FnT const append;
    T const unit;
    size_t const N;
    std::vector<T> dat;

    static size_t log2(size_t n) {
      size_t p = 1;
      while ((1 << p) < n) { ++p; }
      return p;
    }
};

int constexpr unit = -1;

int gcd(int a, int b) {
  if (a == unit) return b;
  if (b == unit) return a;
  return b == 0 ? a : gcd(b, a%b);
}

using Segt = SegmentTree<int, int(*)(int, int)>;

using namespace std;

int main() {
  // cout << fixed << setprecision(10);
  int N; cin >> N;
  Segt tree(gcd, unit, N);
  REP(i, N) {
    int A;
    cin >> A;
    tree.update(i, A);
  }
  int ans = -1;
  REP(i, N) {
    int g = gcd(tree.query(0, i), tree.query(i+1, N));
    chmax(ans, g);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }

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

const int MOD = 1000000007;
void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }
}

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    ll C[N], A[N][M];
    rep(i, N) {
        cin >> C[i];
        rep(j, M) {
            cin >> A[i][j];
        }
    }


    ll ans = 100000000000000000;
    rep(i, 1<<N) {
//        cout << i << endl;
        ll tmp[M];
        rep(j, M) {
            tmp[j] = 0;
        }
        ll tmpa = 0;
        rep(j, N) {
            if (i & (1 << j)) {
                tmpa += C[j];
                rep(k, M) {
                    tmp[k] += A[j][k];
                }
            }
        }

        bool flag = true;
        rep(j, M) {
            if (tmp[j] < X ) {
                flag = false;
                break;
            }
        }
        if (flag) {
            chmin(ans, tmpa);
        }
    }
    if (ans == 100000000000000000) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

}

Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <queue> //C++
using namespace std; //C++



int main(void) {
	
	int x, y;
	cin >> x >> y;
	int i;
	for (i = 0; i <= x; i++) {
		if (y == (4*x - 2*i)) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";

}


Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main(){
  int A[3], ans=0;
  for(int i=0; i<3; i++) cin >> A[i];
  for(int i=0; i<3; i++) ans += A[i];
  if(ans >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

void solve()
{
   string s;
   cin>>s;
   int n = s.length();
   if(s[n-1]=='s')
   {
       s=s+"es";
   } 
   else
   {
       s=s+"s";
   }
   cout<<s;
   
}

int main()
{
    ll S=1;
    //cin >> S;
    while(S--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a, b, sum = 0;
  cin >> a >> b;
  
  for (; a <= b; a++){
  int c = a%10, d = a/10000;
  int e = (a%100-c)/10, f = a/1000 - d*10;
  if ( c==d && e==f ){
    sum++;
  }
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> list(N);
  int sum = 0;
  rep(i, N) {
    cin >> list[i];
    sum += list[i];
  }
  int ans = 9999999;
  int nf = sum;
  int dl = 0;
  rep(i, N) { 
    nf -= list[i];
    dl =sum-nf;
    ans = min(ans,abs(dl-nf));
  }

  cout << ans;
  
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
#include <cassert>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int N;
string S;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>S;
    int r=0,g=0,b=0;
    rep(i,S.size()){
        if(S[i]=='R')r++;
        else if(S[i]=='G')g++;
        else b++;
    }
    int ans = r*g*b;
    rep(i,S.size()){
        for(int j = i;j<S.size();j++){
            int k = 2*j -i;
            if(k>=S.size())continue;
            if(S[i]!=S[j] && S[i]!=S[k]&&S[j]!=S[k]){
               // cout << i<<" "<<j<<" "<<k << endl;
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3660
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int h[maxn],go[maxn*2],nxt[maxn*2];
int i,j,k,l,t,n,m,tot;
void add(int x,int y){
    go[++tot]=y;
    nxt[tot]=h[x];
    h[x]=tot;
}
int dfs(int x,int y){
    int l=0,t=h[x];
    while (t){
        if (go[t]!=y) l^=dfs(go[t],x)+1;
        t=nxt[t];
    }
    return l;
}
int main(){
    scanf("%d",&n);
    fo(i,1,n-1){
        scanf("%d%d",&j,&k);
        add(j,k);add(k,j);
    }
    if (dfs(1,0)) printf("Alice\n");else printf("Bob\n");
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

signed main(){
   IOS;
   string s; cin >> s;
   int ans = 110;
   rep(k,0,26){
      int res = 0,n = s.size();
      char c = 'a'+k;
      string t = s;
      while(1){
         vector<int> pos;
         rep(i,0,n){
            if(t[i] == c) pos.pb(i);
         }
         if(pos.size() == n) break;
         for(auto x : pos){
            if(x-1>=0) t[x-1]=c;
         }
         n--;
         res++;
      }
      // cout << t << "\n";
      ans = min(ans,res);
   }
   cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
 
//足したり引いたりすると勝手にmodをとってくれる
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
 
//コンビネーションのライブラリ
struct combination {
    //factのなかに階乗を求めている
    //ifactのなかに階乗逆元を求めている
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
 
int main(){
    int x, y;
    cin >> x >> y;
    
    //移動回数を求める
    //３の倍数でなかったらアウト
    if ((x+y) % 3) {
        cout << 0 << endl;
        return 0;
    }
    
    //高校数学でおなじみの矢印並べ問題へ帰着させる
    
    int n = (x+y) / 3;
    
    x -= n, y -= n;
    
    //x or y は負になることがあるので注意せよ
    //ex. x = 1, y = 5のとき不適である
    if (x < 0 || y < 0){
        cout << 0 << endl;
        return 0;
    }
    
    //二項係数を求める
    //初期化する
    combination c(x+y);
    mint ans = c(x+y, x);
    
    cout << ans.x << endl;
}

Measured memory_bytes: 10624
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n, K;
  cin>>n>>K;
  LL x[n], y[n];
  REP(i, n){
    cin>>x[i]>>y[i];
  }
  LL ans=LINF;
  int count;
  LL ix, iy, jx, jy;
  for(int i=0; i<n; ++i){
    ix = x[i];
    for(int j=i; j<n; ++j){
      jx = x[j];
      for(int k=0; k<n; ++k){
        iy = y[k];
        for(int l=k; l<n; ++l){
          jy = y[l];
          count=0;
          REP(p, n){
            if(min(ix, jx)<=x[p] && max(ix, jx) >= x[p] && min(iy, jy) <= y[p] && max(iy, jy) >= y[p]) ++count;
          }
          if(count>=K){
            LL sq = abs(ix-jx)*abs(iy-jy);
            ans=min(ans, sq);
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

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


int main()
{
    int N;
    cin >> N;
    vector<long long> a(N+1);
    REP(i, N) cin >> a[i];

    vector<long long> s(N+1);
    REP(i, N) s[i+1] += s[i]+a[i];  // 1-index

    // dp[i][j]: 1-index で [i,j) のスライムを一つにするのに必要な最小のコスト
    vector<vector<long long>> dp(N+1, vector<long long>(N+1));

    for(int i = N-2; i >= 0; --i){
        FOR(j, i+2, N+1){
            dp[i][j] = 1e+18;
            FOR(k, i, j){
                dp[i][j] = min(dp[i][k]+dp[k][j]+s[j]-s[i], dp[i][j]);
            }
        }
    }
    cout << dp[0][N] << endl;

    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+ 5;
long long a[N], len;
long long s[N];
int vis[N];
int main() {
	long long n;
	long long x, m;
	cin >> n >> x >> m;
	a[1] = x;
	vis[x] = true;
	long long ans = 0;
	len = 1;
	while(!vis[a[len] * a[len] % m]) {
		len ++;
		a[len] = a[len - 1] * a[len - 1] % m;
		vis[a[len]] = len;
	}
	long long pos = 0;
	for (int i = vis[a[len] * a[len] % m]; i <= len; i ++) {
		pos ++;
		s[pos] = s[pos - 1] + a[i];
	}
	if (n < vis[a[len] * a[len] % m]) {
		for (int i = 1; i <= n; i ++) ans += a[i];
		cout << ans << endl;
		return 0;
	}
	n -= vis[a[len] * a[len] % m] - 1;
	for (int i = 1; i <= vis[a[len] * a[len] % m] - 1; i ++) ans += a[i];
	ans += s[pos] * (n / pos) + s[n % pos];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n;i++)

int main(){
    std::vector<int>next(3);
    std::vector<int>v(3);
    int ans=0;
    rep(i,3)std::cin>>v[i];
    bool inf=true;
    rep(i,3){
        int now=v[i];
        while(now!=1)if(now%2){inf=false; break;}else now/=2;
    }
    if(v[0]%2+v[1]%2+v[2]%2)return puts("0")*0;
    
    if((v[0]-v[1]==0&&v[1]-v[2]==0))return puts("-1")*0;
    bool check=true;
    while(check){
        next[0]=v[1]/2+v[2]/2;
        next[1]=v[0]/2+v[2]/2;
        next[2]=v[0]/2+v[1]/2;
        rep(i,3)if((next[i])%2){check=false; ans++;goto E;;}
        v=next;
        ans++;
    }
E: std::cout<<ans<<std::endl;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,s,t;
	cin>>n>>s>>t;
	vi in(n);
	rep(i,n)cin>>in[i];
	int out=abs(in[n-1]-t);
	if(n>=2)out=max(out,abs(in[n-1]-in[n-2]));
	cout<<out<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b, c, d;
  std::cin >> a >> b >> c >> d;
  if(abs(a-c)<=d||(abs(c-b)<=d&&abs(a-b)<=d)) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

int main(){
    ll ans = 0;
    ll N ,M;
    cin >> N;
    N %= 1000;
    if(N != 0){
        cout << 1000 - N << endl;
    }else{
        cout << 0 << endl;
    }
    

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int t_at = c / b + !!(c % b), a_at = a / d + !!(a % d);
    cout << ((t_at <= a_at) ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
using namespace std;
int cmp(int x,int y)
{
	return x>y;
}
int main()
{
	int a[1000],n,k,sum=0;
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	  cin>>a[i];
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=k;++i)
	  sum=sum+a[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
const int MOD=1000000000+7;

int d,n;
int ans;

int main(){
	cin>>d>>n;
	int f=0;
	if(n==100)f++;
	if(d==0)ans=n+f;
	if(d==1)ans=(n+f)*100;
	if(d==2)ans=(n+f)*10000;
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    
    int n, m; cin >> n >> m;
    vector<int> dp(m, 0), ndp(dp);
    dp[0] = 1;
 
    for (int i = 0; i < n; ++i) {
        string now; cin >> now;
        for (int j = 0; j < m; ++j) {
            if (now[j] == '#') ndp[j] = 0;
            else {
                ndp[j] = dp[j];
                if (j > 0) ndp[j] += ndp[j - 1];
                ndp[j] %= 1000000007;
            }
        }
        swap(dp, ndp);
    }
    cout << dp[m - 1] << endl;
 
 
     
    return 0;
}

Measured memory_bytes: 256
// C - Exam and Wizard
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
template<class T> T in(){T x;cin>>x;return x;}

int main(){
	int ans =0, N = in<int>();
	ll minus = 0, impossible = 0;// <0: impossible
	vi C(N);

	rp(i, 0, N) impossible += C[i] = in<int>();

	rp(i, 0, N){
		int b = in<int>();
		impossible -= b;
		if(impossible < 0){ puts("-1"); return 0; }
		C[i] -= b;
		if(C[i] < 0){
			ans++;//変更が必要
			minus += C[i];
		}
	}

	sort(allr(C));

	for(int c:C){
		if(minus >= 0) break;
		if(c <= 0) break;
		ans++;//変更が必要
		minus += c;
	}

	cout<< ans <<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[105];
	int cnt=0;
	scanf("%s",a);
	for(int i=0;i<strlen(a)/2;i++){
		if(a[i]!=a[strlen(a)-1-i]){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int A,B,C; cin >> A >> B >> C;
  if (A == 5 && B == 5 && C == 7) cout << "YES" << endl;
  else if (A == 5 && B == 7 && C == 5) cout << "YES" << endl;
  else if (A == 7 && B == 5 && C == 5) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3596
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int l = scan.nextInt();

        String ss[] = new String[n];
        for (int i = 0; i < n; i++) {
            ss[i] = scan.next();
        }

        Arrays.sort(ss);
        for (int i = 0; i < n; i++) {
            System.out.print(ss[i]);
        }
    }
}


Measured memory_bytes: 22868
n = int(input())
a = list(map(int, input().split()))

num = [0]*(10**6+1)

for x in a:
    num[x] += 1

f = 1
for i in range(2, 10**6+1):
    s = sum(num[i::i])
    if s == n:
        print("not coprime")
        exit()
    if s > 1 :
        f = 0
if f == 0:
    print("setwise coprime")
else:
    print("pairwise coprime")

Measured memory_bytes: 127548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=505,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;cin>>S;
    
    while(S!="ABC"){
        string T,sub;
        char X='X';
        for(int i=0;i<S.size();){
            if(i+2<S.size()&&S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
                if(X=='X'){
                    if(T.size()==0){
                        X='A';
                    }else if(T.back()=='A'){
                        X='B';
                    }else if(T.back()=='B'){
                        X='C';
                    }else if(T.back()=='C'){
                        X='A';
                    }
                    
                    T+=X;
                    i+=3;
                }else{
                    T+=X;
                    i+=3;
                }
            }else{
                T+=S[i];
                i++;
            }
        }
        
        if(X=='X') break;
        
        for(int i=0;i<T.size();i++){
            if(T[i]==X){
                sub+="ABC";
            }else{
                sub+=T[i];
            }
        }
        
        if(S==sub) S=T;
        else{
            S="FFF";
            break;
        }
    }
    
    if(S=="ABC") cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}






Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
int n,ans,a[1000000];
bool flag;
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int k=1,kk=0;if (c=='-')k=-1;else kk=c-'0';c=getchar();
	while (c>='0'&&c<='9')kk=kk*10+c-'0',c=getchar();return kk*k;
}
int main(){
	n=read();for (int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+1+n);for (int i=1;i<=n;i++){
			flag=true;while (a[i]==a[i+1])i++,flag=!flag;
			ans+=flag;
		}
	cout<<ans<<endl;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

mt19937 rng( (int)chrono::steady_clock::now().time_since_epoch().count() );

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  #ifdef FourLeafClover
  freopen("input", "r", stdin);
  #endif // FourLeafClover

  int n, m; cin >> n >> m;
  vector<vector<int> > gr(n);
  vector<int> deg(n);
  for (int i = 0; i < n + m - 1; ++i) {
    int u, v; cin >> u >> v; --u; --v;
    gr[u].emplace_back(v);
    ++deg[v];
  }

  queue<int> q;
  for (int u = 0; u < n; ++u) if (!deg[u]) q.emplace(u);
  vector<int> par(n, -1);
  while (sz(q) ) {
    int u = q.front(); q.pop();
    for (int v : gr[u]) {
      --deg[v];
      if (!deg[v]) {
        par[v] = u;
        q.emplace(v);
      }
    }
  }

  for (auto &i : par) cout << i + 1 << '\n';

  return 0;
}


Measured memory_bytes: 7040
a, b, x = list(map(int, input().split()))
import math
# a = 3
# b = 1
# x = 8

vol = a * a * b

if x > vol / 2 :
    # print("水が台形")
    c = (2 * b) - (2 * x) / a ** 2 # 水でない三角形の底辺
    print(math.degrees(math.atan( c / a )))
else:
    # print("水が三角形")
    c = 2 * x / ( a * b ) # 水の三角形の底辺
    print(math.degrees(math.atan( b / c )))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
int main(void){
   int N; cin >> N;
   long a[10009];
   int count = 0;
   for(int i=0; i < N; i++) cin >> a[i];
   
   for(int i=0; i < N; i++) {
       while(1) {
           if(a[i] % 2 == 0) {
               a[i] /= 2;
               count++;
           }
           else break;
       }
   }
   cout << count << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <limits.h>

int main(void){
	int N,i,j,k,c=0;
	long ans = LONG_MIN,sum=0;
	scanf("%d",&N);
	int F[N][10],schedule[1024][10];
	long P[N][11];
	for(i=0;i<N;i++){
		for(j=0;j<10;j++){
			scanf("%d",&F[i][j]);
		}
	}
	for(i=0;i<N;i++){
		for(j=0;j<=10;j++){
			scanf("%ld",&P[i][j]);
		}
	}
	for(i=0;i<1024;i++){
		int x = 2;
		for(j=0;j<10;j++){
			k = i%x;
			if(k>=(x/2)) schedule[i][j] = 1;
			else		 schedule[i][j] = 0;
			x *= 2;
		}
	}
	
	for(j=1;j<1024;j++){ //j番目のスケジュール
		sum=0;
		for(i=0;i<N;i++){//店i
			c=0;
			for(k=0;k<10;k++){//時間帯
				if(F[i][k]==1 && schedule[j][k]==1) c++;
			}
			sum+=P[i][c];
		}
		if(ans<sum) ans = sum;
	}
	
	printf("%ld",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,y,i,j,k;
  scanf("%d%d",&n,&y);
  for(i = 0;i <= n;i++)for(j=0;j<=n-i;j++){
      k =n-i-j;
      if(i*1000+j*5000+k*10000==y){
	printf("%d %d %d\n",k,j,i);
        return 0;
      }
    }
  puts("-1 -1 -1");
}


Measured memory_bytes: 128
#include <stdio.h>
 
int main(void){

	int n, i;
	int S[100];

	scanf("%d", &n);
		for(i=0; i<n; i++) {
			scanf("%d", &S[i]);
		}

	for(i=n-1; i>=0; i--) {
		if(i==0){
			printf("%d", S[i]);
	}
	else{
		printf("%d ", S[i]);
		}
	}
	printf("\n");

	return 0;
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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


int main(void) {
	int h, w;
	bool flag = true;
	char s[60][60];

	cin >> h >> w;
	FOR(i, 0, h - 1) {
		cin >> s[i];
	}
	FOR(i, 0, h - 1) {
		FOR(t, 0, w - 1) {
			if (s[i][t] == '.') {
				continue;
			}

			if (i - 1 >= 0) {
				if (s[i - 1][t] == '#') {
					continue;
				}
			}
			if (t - 1 >= 0) {
				if (s[i][t - 1] == '#') {
					continue;
				}

			}
			if (i + 1 <= h - 1) {
				if (s[i + 1][t] == '#') {
					continue;
				}
			}
			if (t + 1 <= w - 1) {
				if (s[i][t + 1] == '#') {
					continue;
				}
			}
			flag = false;
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef pair<int,int> pii;

int main(){
	int n,a,b,ap,bp;
	cin>>n;
	int t[n];
	rep(i,n)t[i]=0;
	rep(i,n*(n-1)/2){
		cin>>a>>b>>ap>>bp;
		if(ap>bp)t[a-1]+=3;
		else if(ap<bp)t[b-1]+=3;
		else{
			t[a-1]++;t[b-1]++;
		}
	}
	pair<int,int> r[n],j[n];
	rep(i,n)r[i]=pair<int,int>(t[i],i+1);
	sort(r,r+n);
	for(int i=n-1,s=1,t=1;i>=0;i--){
		j[i]=pii(r[i].second,s);
		if(i==0)s++;
		t++;
		if(r[i].first!=r[i-1].first)s=t;
	}
	sort(j,j+n);
	rep(i,n)cout<<j[i].second<<endl;
	return 0;
}

Measured memory_bytes: 1164
# -*- coding: utf-8 -*-
A, B, C = map(int, input().split(' '))

import math
ans1 = A * B * math.ceil(C/2) - A * B * math.floor(C/2)
ans2 = B * C * math.ceil(A/2) - B * C * math.floor(A/2)
ans3 = A * C * math.ceil(B/2) - A * C * math.floor(B/2)

ans = int(min([ans1, ans2, ans3]))
print(ans)



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

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
string S;
int main() {
	cin>>S;

	S[3]='8';
	cout<<S<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int n = 100002;

int LP[n], RP[n];
set<PII> SR;
set<PII, greater<PII>> SL;
int N;

long long solve1(set<PII> SR, set<PII, greater<PII>> SL){
	long long C = 0;
	int x =  0;
	while(SR.size() > 0){
		int l = SR.begin() -> first;
		int i = SR.begin() -> second;
		//cout << "chose left: (" << LP[i] << ", "<< RP[i] << ")" << endl;
		if(l < x){
			C += abs(x-l);
			x = l;
		}
		SR.erase(SR.begin());
		SL.erase({LP[i], i});

		if(SL.size() > 0){
			int r = SL.begin() -> first;
			int j = SL.begin() -> second;
			//cout << "chose right: (" << LP[j] << ", "<< RP[j] << ")" << endl;
			if(r > x){
				C += abs(x-r);
				x = r;
			}
			SL.erase(SL.begin());
			SR.erase({RP[j], j});
		}
	}
	C += abs(x);
	return C;
}
long long solve2(set<PII> SR, set<PII, greater<PII>> SL){
	long long C = 0;
	int x =  0;
	while(SL.size() > 0){
		int r = SL.begin() -> first;
		int i = SL.begin() -> second;
		//cout << "chose right: (" << LP[i] << ", "<< RP[i] << ")" << endl;
		if(r > x){
			C += abs(x-r);
			x = r;
		}
		SL.erase(SL.begin());
		SR.erase({RP[i], i});

		if(SR.size() > 0){
			int l = SR.begin() -> first;
			int j = SR.begin() -> second;
			//cout << "chose left: (" << LP[j] << ", "<< RP[j] << ")" << endl;
			if(l < x){
				C += abs(x-l);
				x = l;
			}
			SR.erase(SR.begin());
			SL.erase({LP[j], j});
		}
	}
	C += abs(x);
	return C;
}

int main(){
	cin >> N;
	for(int i = 0; i < N; ++i){
		int l, r;
		cin >> l >> r;
		LP[i] = l;
		RP[i] = r;
		SR.insert({r, i});
		SL.insert({l, i});
	}
	
	long long s1 = solve1(SR, SL);
	//cout << "\n s1: "<< s1 << endl;
	long long s2 = solve2(SR, SL);
	//cout << "\n s2: "<< s2 << endl;
	cout << max(s1, s2) << endl;
	return 0;
}

Measured memory_bytes: 21760
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var s = ToInt32(ReadLine());
        var set = new HashSet<int>();
        var isEnd = false;
        var val = s;
        var index = 1;
        while (!isEnd)
        {
            if (set.Contains(val)) break;

            set.Add(val);
            if (val % 2 == 0) val /= 2;
            else val = 3 * val + 1;
            index++;
        }
        WriteLine(index);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 13396
package main

import "fmt"

func max(a ...int) int {
	m := a[0]
	for i, v := range a {
		if i == 0 {
			continue
		}
		if m < v {
			m = v
		}
	}
	return m
}

func main() {
	// Code for A - ><
	var S string
	fmt.Scan(&S)

	a := make([]int, len(S))
	b := make([]int, len(S))
	var countA, countB int
	for i := 0; i < len(S); i++ {
		if S[i] == '<' {
			countA++
		} else {
			countA = 0
		}
		a[i] = countA
	}

	for i := len(S) - 1; 0 <= i; i-- {
		if S[i] == '>' {
			countB++
		} else {
			countB = 0
		}
		b[i] = countB
	}

	var ans int
	ans += max(b[0], 0)

	for i := 0; i < len(S)-1; i++ {
		ans += max(a[i], b[i+1])
	}
	ans += max(a[len(S)-1], 0)

	fmt.Println(ans)
}


Measured memory_bytes: 13520
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <array>
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;

int gcd(int a, int b) {
    int aa = (a > b ? a : b);
    int bb = (a > b ? b : a);

    if (aa % bb == 0) {
        return bb;
    }
    else {
        return gcd(bb, aa % bb);
    }
}

int gcd3(int a, int b, int c) {
    return gcd(gcd(a, b), c);
}


int main()
{
    int K;
    cin >> K;
    int tmp;
    long result;
    result = 0;
        
    vector<vector<vector<int>>> res(K+1, vector<vector<int>>(K + 1, vector<int>(K + 1)));
    rep(i, K) { 
        rep(j, K) {
            rep(k, K) {
                if (res[i][j][k] == 0) {
                    tmp = gcd3(i, j, k);
                    res[i][j][k] = tmp;
                    res[i][k][j] = tmp;
                    res[j][i][k] = tmp;
                    res[j][k][i] = tmp;
                    res[k][i][j] = tmp;
                    res[k][j][i] = tmp;
                }
                result = result + res[i][j][k];
            }
        }
    }
    cout << result;
}

Measured memory_bytes: 36328
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ll extgcd(ll a, ll b, ll &x, ll &y){
    ll d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x=1;
        y=0;
    }
    return d;
}
int main() {
    ll C,D;
    cin>>A>>B>>C>>D;
    if(C<D) swap(C,D);
    ll x,y;
    ll gc = extgcd(C,D,x,y);
    ll lcm = C*D/gc;
    ll ans = 0;
    --A;
    ans += B/C;
    ans += B/D;
    ans -= B/lcm;
    //cout<<ans<<endl;
    ans -= A/C;
    ans -= A/D;
    ans += A/lcm;
    ans = B-A-ans;
    cout<<ans<<endl;
    //cout<<gc<<lcm<<endl;
}

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

int main() {
    string s; cin >> s;
    int zero = 0, ichi = 0;
    for (auto c : s) {
        if (c == '0') ++zero;
        else ++ichi;
    }
    cout << min(zero, ichi) * 2 << endl;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
  int a,b,n,s,f,i=0;
  cin >> a >> b >> n;
  while(1){
    cin >> s >> f;
    if((a >= s && b <= f) || (s > a && s < b) || (f > a && f < b)){
      cout << '1' << endl;
      break;
    }
    if(++i >= n){
      cout << '0' << endl;
      break;
    }
  }
}


Measured memory_bytes: 3096
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int a, b;
    cin >> a >> b;
    int n;
    cin >> n;
    cout << (n + max(a,b) - 1) / max(a, b) << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    double w, h, x, y;
    int ways = 1;
    cin >> w >> h >> x >> y;
    double area = (w * h) / 2.0;

    if (x * 2 == w && y * 2 == h)
    {
        ways = 1;
    }
    else
    {
        ways = 0;
    }
    printf("%.6lf %d", area, ways);
}

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

typedef long long ll;

int n, a[45][45];
ll dp[45][45][45];

ll F(int l, int i, int r) {
	if (l == r) return 1;
	ll &ans = dp[l][i][r];
	if (~ans) return ans;
	ans = 0;
	for (int j = l; j < i; ++j)
		for (int k = i + 1; k <= r; ++k)
			if (a[j][k]) for (int p = j; p < i; ++p)
				for (int q = i + 1; q <= k; ++q) {
					ll a = F(l, j, p);
					ll b = !a ? 0 : F(q, k, r);
					ll c = !b ? 0 : F(p + 1, i, q - 1);
					ans += a * b * c;
				}
	return ans;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= 2 * n; ++i)
		for (int j = 1; j <= 2 * n; ++j)
			scanf("%1d", a[i] + j);
	memset(dp, -1, sizeof dp);
	ll ans = 0;
	for (int i = 2; i <= 2 * n; ++i) if (a[1][i]) ans += F(2, i, 2 * n);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>

int l[200];

int main()
{
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 2 * n; ++i)
  {
    scanf("%d", l + i);
  }
  std::sort(l, l + 2 * n);
  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
    ans += l[2 * i];
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct node {
    int cnt0, cnt1;
    friend inline int operator < (const node &a, const node &b) {
        return 1ll * a.cnt1 * b.cnt0 > 1ll * a.cnt0 * b.cnt1;
    }
} a[200010];
priority_queue < pair < node, int > > q;
int p[200010];
int fa[200010];
inline int gf(int a) {return fa[a] == a ? a : fa[a] = gf(fa[a]);}
long long ans;
int n;
int main() {
    scanf("%d", &n);
    for (int i = 2; i <= n; i++) scanf("%d", p + i);
    for (int i = 1; i <= n; i++) {
        int v;
        scanf("%d", &v);
        v ? a[i] = {0, 1} : a[i] = {1, 0};
        if (i > 1) q.push({a[i], i});
        fa[i] = i;
    }
    while (q.size()) {
        pair < node, int > now = q.top();
        q.pop();
        if (a[now.second].cnt0 != now.first.cnt0 || a[now.second].cnt1 != now.first.cnt1) continue;
        int x = now.second, y = gf(p[x]);
        ans += 1ll * a[x].cnt0 * a[y].cnt1;
        a[y].cnt0 += a[x].cnt0;
        a[y].cnt1 += a[x].cnt1;
        fa[x] = y;
        if (y != 1) q.push({a[y], y});
    }
    return cout << ans << endl, 0;
}

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

int main(){
    constexpr long MOD = 1000000007;
    long N;
    cin >> N;
    long dp{N};
    vector<long> sum(4, (N - 1) * N % MOD);
    sum[0] = 0;
    for(long i = 3, j = 2; i != N + 3; ++i, ++j)sum[i & 3] = (sum[j & 3] - 1 + (dp += sum[(j ^ 2) & 3])) % MOD;
    cout << dp % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
n,t = map(int,input().split())
tm = list(map(int,input().split()))

ans = 0
now = 0
for i in range(n):
    if now > tm[i]:
        ans += (tm[i]+t)-now
        now = tm[i]+t

    else:
        ans += t
        now = tm[i]+t
        pass
    #print(ans)

print(ans)

Measured memory_bytes: 26836
#include <iostream>
#include <algorithm>
#include <cstring>

#define MAX 1000000000

using namespace std;

typedef long long ll;

ll n, w;
ll p[100+1], v[100+1];

ll memo[100+1][100000+1];

ll mochila(ll i, ll k)
{
    if (k == 0) return 0;
    else if ( i == n ) return MAX;

    if ( memo[i][k] != -1) return memo[i][k];

    if ( v[i] <= k ) {
        memo[i][k] = min( p[i] + mochila(i+1, k - v[i] ), mochila(i+1,k));
    } else {
        memo[i][k] = mochila(i+1,k);
    }
    return memo[i][k];
}

int main()
{
    cin >> n >> w;
    int max_v = 0;
    for(int i=0; i<n; ++i) {
        cin >> p[i] >> v[i];
        max_v += v[i];
    }

    for(int i=0; i<=100; ++i){
        for(int j=0; j<=100000; ++j) {
            memo[i][j] = -1;
        }
    }

    int ans = -1, peso;

    for(ll i=1; i<=max_v;++i) {
        peso = mochila(0,i);
        if (peso <= w) ans = i;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 79104
import std.stdio;
import std.algorithm;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto N = to!ulong(tokens[0]);
	auto H = to!ulong(tokens[1]);
	auto W = to!ulong(tokens[2]);

	ulong ans;

	foreach (i; 0..N)
	{
		auto tokens2 = split(my_readln());
		auto A = to!ulong(tokens2[0]);
		auto B = to!ulong(tokens2[1]);
		if (A >= H && B >= W) ++ans;
	}

	writeln(ans);
	stdout.flush();
/*}catch (Throwable e)
	{
		writeln(e.toString());
	}
readln();*/
}

Measured memory_bytes: 380
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int n;
  std::cin >> n;
  int l[2000],r[2000],ans=0;

  for(int i=0; i<n; i++) std::cin >> l[i] >> r[i];

  for(int i=0; i<n; i++){
    ans=ans+(r[i]-l[i]+1);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n, c;
    int[] ss, ts, cs;
    int END = 100000;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        c = sc.nextInt();
        ss = new int[n];
        ts = new int[n];
        cs = new int[n];
        for (int i = 0; i < n; i++) {
            ss[i] = sc.nextInt() - 1;
            ts[i] = sc.nextInt();
            cs[i] = sc.nextInt() - 1;
        }
        solve();
    }

    void solve() {
        int[][] css = new int[c][END + 1];
        for (int i = 0; i < n; i++) {
            css[cs[i]][ss[i]]++;
            css[cs[i]][ts[i]]--;
        }
        for (int i = 0; i < c; i++) {
            for (int j = 1; j < css[i].length; j++) {
                css[i][j] = css[i][j - 1] + css[i][j];
            }
        }
        int[] sum = new int[END + 1];
        int max = 0;
        for (int i = 0; i < sum.length; i++) {
            for (int j = 0; j < c; j++) {
                if (css[j][i] > 0) {
                    sum[i]++;
                }
            }
            if (max < sum[i]) {
                max = sum[i];
            }
        }
        System.out.println(max);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 47204
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int W, H, a[11][11], rt[10][10], dn[10][10], dp[2][1 << 20], y, z;
vector<int> b;

void f(int x, int p) {
    int rx = rt[y][x];
    int mn = min({ 2, a[y][x], a[y][rx] });
    mn = p >> x * 2 + 2 & ~(-1 << (rx - x - 1) * 2) ? 0 : mn;
    for (int i = a[y][x] - min({ 2, a[y][x], a[dn[y][x]][x] }); i <= mn; ++i) {
        int q = p & ~(3 << x * 2) | a[y][x] - i << x * 2;
        if (rx == W) {
            dp[y & 1][q] = (dp[y & 1][q] + z) % 100000007;
        } else {
            a[y][rx] -= i;
            f(rx, q);
            a[y][rx] += i;
        }
    }
}

void g(int x, int p) {
    if (x) {
        for (int i = 0; i < 3; ++i)
            g(x - 1, p << 2 | i);
    } else {
        b.emplace_back(p);
    }
}

int main() {
    cin >> H >> W;
    int A[11][11]{};
    for (int y = 0; y < H; ++y) {
        char s[11];
        cin >> s;
        bool none = true;
        for (int x = 0; x < W; ++x) {
            if (s[x] != '.') {
                A[y][x] = s[x] - '0';
                none = false;
            }
        }
        if (none) {
            --H;
            --y;
        }
    }
    for (int y = 0; y < H; ++y) {
        for (int x = 0; x < W; ++x) {
            if (A[y][x]) {
                int i = x + 1;
                for (; i < W && !A[y][i]; ++i);
                rt[y][x] = i;
                for (i = y + 1; i < H && !A[i][x]; ++i);
                dn[y][x] = i;
            }
        }
    }
    memcpy(a, A, sizeof a);
    g(W, 0);
    dp[1][0] = 1;
    for (y = 0; y < H; ++y) {
        memset(dp[y & 1], 0, sizeof dp[y & 1]);
        int x = 0;
        for (; !a[y][x]; ++x);
        for (int p : b) {
            z = dp[y + 1 & 1][p];
            if (z) {
                for (int i = x; i < W; i = rt[y][i])
                    a[y][i] -= p >> i * 2 & 3;
                f(x, p);
                memcpy(a[y], A[y], sizeof a[y]);
            }
        }
    }
    cout << dp[H + 1 & 1][0] << endl;
    return 0;
}

Measured memory_bytes: 11508
#!/usr/bin/env ruby

def main
    a,b,c,d = gets.chomp.split(" ").map(&:to_i)
    if (a+b) > (c+d)
        puts "Left"
    elsif (a+b) == (c+d)
        puts "Balanced"
    else
        puts "Right"
    end
end

main

Measured memory_bytes: 1788