akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const unsigned INF = 0xFFFFFFFF;
static const ll       MOD = 1000000007LL;
static const double   EPS = 1E-10;

int r, c, q;
int _r, _c;
int g;
unsigned int _seg[11111111];
vector<unsigned int*> seg;
int sx, sy, tx, ty;

void init()
{
  _r = 1;
  _c = 1;
  while(_r < r) _r *= 2;
  while(_c < c) _c *= 2;
  seg.resize(2 * _r - 1);
  rep(i, 2 * _r - 1) seg[i] = _seg + i * (2 * _c - 1);
  rep(i, 2 * _r - 1) rep(j, 2 * _c - 1) seg[i][j] = INF;
}

void update(int a, int b, unsigned int x)
{
  a += _r - 1;
  b += _c - 1;
  seg[a][b] = x;
  while(a >= 0){
    int tmp = b;
    while(b > 0){
      b = (b - 1) / 2;
      seg[a][b] = min(seg[a][2 * b + 1], seg[a][2 * b + 2]);
    }
    b = tmp;
    if(a == 0) break;
    a = (a - 1) / 2;
    seg[a][b] = min(seg[2 * a + 1][b], seg[2 * a + 2][b]);
  }
}

unsigned int _query(int sy, int ty, int kk, int k = 0, int l = 0, int r = _c)
{
  if(r <= sy || ty <= l) return INF;
  if(sy <= l && r <= ty) return seg[kk][k];
  return min(_query(sy, ty, kk, 2 * k + 1, l, (l + r) / 2),
             _query(sy, ty, kk, 2 * k + 2, (l + r) / 2, r));
}

unsigned int query(int sx, int sy, int tx, int ty, int k = 0, int l = 0, int r = _r)
{
  if(r <= sx || tx <= l) return INF;
  if(sx <= l && r <= tx) return _query(sy, ty, k);
  return min(query(sx, sy, tx, ty, 2 * k + 1, l, (l + r) / 2),
             query(sx, sy, tx, ty, 2 * k + 2, (l + r) / 2, r));
}

int main(int argc, char *argv[])
{
  while(cin >> r >> c >> q, r){
    init();
    rep(i, r) rep(j, c){
      cin >> g;
      update(i, j, g);
    }
    rep(i, q){
      cin >> sx >> sy >> tx >> ty;
      cout << query(sx, sy, tx + 1, ty + 1) << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 35928
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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;
}

int dp[10005][2][105] = {};
signed main(void) {
    string s;
    cin >> s;
    int d;
    cin >> d;
    int n = s.size();
    dp[0][0][0]++;
    rep(i,n)rep(j,2)rep(k,d)if(dp[i][j][k]){
        int lim = s[i] - '0';
        if(j)lim = 9;
        //cout << i << " " << j << " " << k << endl;
        rep(x,lim+1){
            //cout << " " << (j || x < lim) << " " << (k + x) % d << endl;
            (dp[i+1][j || x < lim][(k + x) % d] += dp[i][j][k]) %= MOD;
        }
    }
    /*
    rep(i,n+1)rep(j,2)rep(k,d)if(dp[i][j][k]){
        cout << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
    }*/
    cout << (MOD + dp[n][0][0] + dp[n][1][0] - 1) % MOD << endl;
}


Measured memory_bytes: 16640
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int H,W;
        int fie[102][102][3][3]={0};
        cin>>H>>W;
        if(H==0&&W==0)break;
        fie[0][0][0][0]=1;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                for(int k=0;k<3;k++){
                    for(int l=0;l<3;l++){
                        for(int m=1;m<3;m++){
                            if(m==1){
                                if(!(k==1&&l==2))fie[i][j+1][l][m]+=fie[i][j][k][l];
                                fie[i][j+1][l][m]%=100000;
                            }
                            else if(m==2){
                                if(!(k==2&&l==1))fie[i+1][j][l][m]+=fie[i][j][k][l];
                                fie[i][j+1][l][m]%=100000;
                            }
                        }
                    }
                }
            }
        }
        int ans=0;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++)ans+=fie[H-1][W-1][i][j];
        }
        cout<<ans%100000<<endl;
    }
    return 0;
}

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

using namespace std;

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

#define ll long long

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	rep (i, n) {
		cin >> a[i];
		b[i] = a[i] - (i+1);
	}
	sort(all(b));
	ll ans = 0;
	rep (i, n)
		ans += abs(b[i] - b[n/2]);
	cout << ans << endl;
}


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

using namespace std;



uint64_t mul_mod(uint64_t a, uint64_t b, uint64_t m)
{
  long double x;
  uint64_t c;
  int64_t r;
  if (a >= m) a %= m;
  if (b >= m) b %= m;
  x = a;
  c = x * b / m;
  r = (int64_t)(a * b - c * m) % (int64_t)m;
  return r < 0 ? r + m : r;
}
uint64_t m =2019;

int main()
{
    int64_t l,r;
    cin>>l>>r;
    if(l==0)
    {
        cout<<"0"<<endl;
        return 0;
    }
    uint64_t L=l;
    uint64_t R=r;
    uint64_t gap= R - L + 1;

    if(gap>=2019)
    {
        cout<<"0"<<endl;
        return 0;
    }
    else
    {
        uint64_t ans=INT_MAX;
        for(uint64_t i=L;i<=R;i++)
        {
            for(uint64_t j=i+1;j<=R;j++)
            {
                uint64_t x=mul_mod(i,j,m);
                ans=min(ans,(x%m));
            }
        }
        cout<<ans<<endl;
    }
}


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

int main() {
  int N, step=1;
  cin >> N;
  vector<int> diameter(N);
  for (int i=0; i<N; i++) {
    cin >> diameter.at(i);
  }
  sort(diameter.begin(), diameter.end());
  for (int i=0; i<N-1; i++) {
    if (diameter.at(i+1)-diameter.at(i) > 0) {
      step++;
    }
  }
  cout << step << endl;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> v(H + 2, string(W + 2, '#'));
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            cin >> v[i][j];
        }
    }
    for(auto& s : v) {
        cout << s << endl;
    }
}


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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
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};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 本を読む時間も最短でないといけない
// 1) aの最大値mxがaの総和sの半分以上である場合は余ったところ(2mx-s)に感想文を入れられる
// 2) そうじゃない場合は普通にaの総和とbの総和の和が答え

int n;
pii a[1010];

signed main() {
	while (1) {
		cin >> n;
		if (n==0) break;
		int sa = 0, sb = 0;
		rep(i,n) {
			cin >> a[i].fi >> a[i].se;
			sa += a[i].fi, sb += a[i].se;
		}
		sort(a,a+n);
		int m = a[n-1].fi;
		if (m<sa-m) {
			cout << sa+sb << ln;
			continue;
		}
		int res = m*2 + sb, p = m*2 - sa;
		bitset<1010> b = 1;
		rep(i,n-1) b |= (b<<a[i].se);
		repr(i,p) if (b[i]) {
			res -= i;
			break;
		}
		cout << res << ln;
	}
}


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

#define pb push_back
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pf push_front

using namespace std;

typedef long long llong;

const int MXN = (int)1e6 + 7;
const llong INF = (llong)1e18 + 7;
const int MOD = (int)1e9 + 7;

int n, k, p[MXN];
llong pref[MXN];
double mx;

int main()
{
  cin >> n >> k ;
  for(int i = 1; i <= n; i++){
    cin >> p[i];
    pref[i] = p[i] + 1 + pref[i - 1];
  }
  for(int i = k; i <= n; i++){
    mx = max(mx, (pref[i] - pref[i - k]) * 1.0 / 2 * 1.0);
  }
  cout << fixed << setprecision(9) << mx;
  return 0;
}


Measured memory_bytes: 6016
import bisect
N=int(input())
a=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
print(sum(bisect.bisect_left(a,b)*(N-bisect.bisect_right(c,b)) for b in B))

Measured memory_bytes: 23156
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var a  = int.Parse(Console.ReadLine());
    var aho = Console.ReadLine();
    var k = 0;
    for(var i = 0;i < aho.Length-2;i++){
       var  zen = aho.Substring(i,3);
       //Console.WriteLine(zen);
      if(zen == "ABC") k += 1;
    }
    Console.WriteLine(k);
  }
}

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

static const int N = 2 * 1e5; 
vector<int> ans(N,0);
int n,q ;
vector<bool> used(N,0);

void dfs(int x, vector<vector<int>> &data){
  	used[x] = 1 ; 
    for(int i: data[x]){
        if(used[i]) continue;
        else{
            ans[i] += ans[x];
            dfs(i,data);
        }
    }
  return ; 
}

int main(){
    cin >> n >> q ;
    vector<vector<int>> data(n);
    int a,b ;
    rep(i,n-1){
        cin >> a >> b ;
        data[a-1].push_back(b-1);
        data[b-1].push_back(a-1); 
    }
    rep(i,q) {
        cin >> a >> b ; 
        ans[a-1] += b ;
    }
    //子に親の値を足していくらしい
    dfs(0,data);
    rep(i,n){
        cout << ans[i] << " ";
    }
    cout << endl ;

}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF=1001001001;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main() {
  ll a,b;
  cin>>a>>b;
  ll ans=lcm(a,b);
  cout<<ans;



}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;

}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

int N, X, ans;

int Solve(){
  ans = 0;
  for (int i = 1; i <= N; i++){
    for (int j = i + 1; j <= N; j++){
      int k = X - (i + j);
      if (j < k && k <= N) ans++;
    }
  }
  return 0;
}

int main(){
  while (true){
    cin >> N >> X;
    if (N == 0 && X == 0) return 0;
    Solve();
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3088
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>

using namespace std;

int N;
int L[200];

int main() {
  cin >> N;
  for (int i = 0; i < 2 * N; i++) {
    cin >> L[i];
  }
  sort(L, L + 2*N);

  int res = 0;
  for (int i = 0; i < N; i++) {
    res += L[2 * i];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 888
### constant

MAX_MN = 20

### main

ccache = (MAX_MN + 1).times.map{[]}

for i in (0..MAX_MN)
  ccache[i][0] = ccache[i][i] = 1
  for j in (1...i)
    ccache[i][j] = ccache[i - 1][j] + ccache[i - 1][j - 1]
  end
end

loop do
  a, m, b, n = gets.split.map(&:to_i)
  break if (a | m | b | n) == 0
  #p [a, m, b, n]

  mn = m * n
  mn2 = mn * 2
  
  mtx = []
  mn.downto(0).each do |d|
    cs = mn.times.map{Rational(0)}
    for k in (0..d)
      ck = ccache[d][k] * (a ** (k / m)) * (b ** ((d - k) / n))
      m0 = k % m
      n0 = (d - k) % n
      cs[m0 * n + n0] += ck
    end
    mtx << cs.reverse
  end

  ad = mtx.shift.map{|t| -t}
  mtx = mtx.transpose
  #p ad
  #p mtx

  for i in (0...mn)
    if mtx[i][i] == 0
      i0 = i + 1
      while mtx[i0][i] == 0
        i0 += 1
      end
      for j in (i...mn)
        t = mtx[i][j]; mtx[i][j] = mtx[i0][j]; mtx[i0][j] = t
      end
      t = ad[i]; ad[i] = ad[i0]; ad[i0] = t
    end

    mii = mtx[i][i]
    if mii == 0
      puts "error"
      p i
      p mtx
      exit
    end
    (i...mn).each{|j| mtx[i][j] /= mii}
    ad[i] /= mii

    for j in ((i + 1)...mn)
      mji = mtx[j][i]
      (i...mn).each{|k| mtx[j][k] -= mji * mtx[i][k]}
      ad[j] -= mji * ad[i]
    end
  end
  #p mtx
  #p ad

  (mn - 1).downto(0).each do |i|
    ((i + 1)...mn).each{|j| ad[i] -= mtx[i][j] * ad[j]}
  end

  puts ([1] + ad.map{|d| d.to_i}).join(' ')
end

Measured memory_bytes: 6200
from math import ceil


def main():
    d, g = [int(x) for x in input().split()]
    pcs = [[int(x) for x in input().split()] for _ in range(d)]
 
    def rec(g, i):
        nonlocal pcs
        if i <= 0:
            return float('inf')

        p, c = pcs[i-1]
        s = 100 * i
        n = min(ceil(g/s), p)
        score = s * n + c if n == p else s * n

        if score >= g:
            m = n
        else:
            m = n + rec(g-score, i-1)

        r = min(m, rec(g, i-1))
        #print(g, i, r)
        return r


    print(rec(g, d))

main()

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

typedef long long ll;
const int maxn = 1e5 + 5;

int N, X, Y, Z;
int A[maxn], B[maxn], C[maxn];
int id[maxn];
ll pre[maxn], suf[maxn], sumC[maxn];

int x[maxn];
struct IT {
	int cnt[maxn * 4];
	ll sum[maxn * 4];
	#define mid ((l + r) >> 1)
	void reset(int v, int l, int r) {
		if (l != r) {
			reset(2 * v, l, mid);
			reset(2 * v + 1, mid + 1, r);
		}
		sum[v] = cnt[v] = 0;
	}
	void up(int v, int l, int r, int pos, int val) {
		if (pos < l || pos > r)
			return;
		if (l == r) {
			++cnt[v];
			sum[v] += val;
			return;
		}
		up(2 * v, l, mid, pos, val); up(2 * v + 1, mid + 1, r, pos, val);
		cnt[v] = cnt[2 * v] + cnt[2 * v + 1];
		sum[v] = sum[2 * v] + sum[2 * v + 1];
		// cout << l << ' ' << r << " = " << cnt[v] << ' ' << sum[v] << endl;
	}
	ll get(int v, int l, int r, int &ct) {
		if (ct == 0) {
			return 0;
		}
		if (ct >= cnt[v]) {
			ct -= cnt[v];
			return sum[v];
		}
		if (l == r) {
			int k = ct;
			ct = 0;
			return x[l] * k;
		}
		ll ans = get(2 * v, l, mid, ct);
		ans += get(2 * v + 1, mid + 1, r, ct);
		return ans;
	}
	ll get(int ct) { return get(1, 1, N, ct); }
	#undef mid
} T;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> X >> Y >> Z;
	// X = 30000, Y = 30000, Z = 40000;
	N = X + Y + Z;
	for (int i = 1; i <= N; ++i) {
		cin >> A[i] >> B[i] >> C[i];
		// const int inf = 1e9;
		// A[i] = rand() % inf + 1;
		// B[i] = rand() % inf + 1;
		// C[i] = rand() % inf + 1;
		// cout << A[i] << ' ' << B[i] << ' ' << C[i] << endl;
		id[i] = i;
	}
	sort(id + 1, id + N + 1, [](int a, int b) { return B[a] - C[a] > B[b] - C[b]; });
	for (int i = 1; i <= N; ++i) {
		sumC[i] = sumC[i - 1] + C[id[i]];
	}
	T.reset(1, 1, N);
	for (int i = 1; i <= N; ++i) {
		x[i] = A[i] - B[i];
	}
	sort(x + 1, x + N + 1, greater<int>());
	ll sumB = 0;
	for (int i = 1; i <= N; ++i) {
		sumB += B[id[i]];
		T.up(1, 1, N, lower_bound(x + 1, x + N + 1, A[id[i]] - B[id[i]], greater<int>()) - x, A[id[i]] - B[id[i]]);
		if (i >= Y) {
			// cout << i << ' ' << sumB << ' ' << T.get(i - Y) << endl;
			pre[i] = sumB + T.get(i - Y);
		}
	}
	T.reset(1, 1, N);
	for (int i = 1; i <= N; ++i) {
		x[i] = A[i] - C[i];
	}
	sort(x + 1, x + N + 1, greater<int>());
	for (int i = N; i >= 1; --i) {
		T.up(1, 1, N, lower_bound(x + 1, x + N + 1, A[id[i]] - C[id[i]], greater<int>()) - x, A[id[i]] - C[id[i]]);
		if (N - i + 1 >= Z) {
			suf[i] = sumC[N] - sumC[i - 1] + T.get(N - i + 1 - Z);
		}
	}
	ll ans = 0;
	for (int i = 1; i <= N; ++i) {

		// cout << i << ' ' << id[i] << ' ' << pre[i] << ' ' << suf[i + 1] << endl;
	}
	for (int i = Y; i + Z <= N; ++i) {
		ans = max(ans, pre[i] + suf[i + 1]);
	}
	cout << ans << endl;
}

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

#define fl(k, n) for(int i = k; i < n; i++)
#define flr(k, n) for(int i = n - 1; i >= k; i--)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define ll long long 
#define llu long long unsigned int

using namespace std;

int binary_search(vector<int> nums, int target_val){
  int begin = 0;
  int end = nums.size();
  int mid;

  while(begin <= end){
    mid = begin + (end - begin) / 2;
    if(nums[mid] == target_val)
      return mid;
    else if(nums[mid] <= target_val && nums[mid + 1] > target_val)
      return mid;
    else if(nums[mid] > target_val)
      end = mid - 1;
    else
      begin = mid + 1;
  }

  if(begin == 0)
    return -1;
  else 
    return nums.size();
}

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

  int n, w;
  cin >> n >> w;

  vp wtval(n);
  fl(0, n)
    cin >> wtval[i].first >> wtval[i].second;

  sort(wtval.begin(), wtval.end());

  vector<vector<llu>> max_val(n + 1, vector<llu>(w + 1));

  fl(0, n){
    for(int j = 0; j <= w; j++){
      if(wtval[i].first > j){
        max_val[i + 1][j] = max_val[i][j];
      }
      else{
        llu take_val = wtval[i].second + max_val[i][j - wtval[i].first];
        //cout << i << " " << j << endl;
        //cout << "take_val: " << take_val << endl;
        llu no_take_val = max_val[i][j];
        max_val[i + 1][j] = max(take_val, no_take_val);
      }
    }
  }

  /*
  fl(0, n + 1){
    for(int j = 0; j <= w; j++){
      cout << max_val[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
  */
  cout << max_val[n][w] << "\n";
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010, mod = 1e9 + 7;

int n;
int a[N], b[N], c[N];
LL sum[N], cnt[N];

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", a + i);
    for(int i = 1; i <= n; i++) scanf("%d", b + i);
    for(int i = 1; i <= n; i++) scanf("%d", c + i);
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);
    sort(c + 1, c + 1 + n);

    for(int i = 1, j = 1; i <= n; i++)
    {
        while(j <= n && b[i] >= c[j]) j++;
//        if(j > n) break;
        cnt[i] = n - j + 1;
    }

    for(int i = 1; i <= n; i++) sum[i] = sum[i - 1] + cnt[i];

    LL res = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(j <= n && a[i] >= b[j]) j++;
//        if(j > n) break;
        res += sum[n] - sum[j - 1];
    }

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>

using namespace std;

int main() {
	int a,b,c;
	int x[3];
	cin >> a >> b >> c;
	x[0] = min(a, min(b, c));
	x[2] = max(a, max(b, c));
	x[1] = a + b + c - x[0] - x[2];
	cout << x[0] <<' '<< x[1] <<' '<< x[2] << endl;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;
int main() {

	string s;
	cin >> s;

	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else if (s == "Rainy") {
		cout << "Sunny" << endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int tot=1;
queue<int> q;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int tmp;
		scanf("%d",&tmp);
		q.push(tmp);
	}
	while(!q.empty())
	{
		if(q.front()==tot)
			tot++;
		q.pop();
	}
	tot--;
	if(tot==0)
		printf("-1");
	else
		printf("%d",n-tot);
	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> ok(n);
    int a;
    cin >> a;
    for (int i = 0; i < a; ++i) {
        int p;
        cin >> p;
        --p;
        ++ok[p];
    }
    int b;
    cin >> b;
    for (int i = 0; i < b; ++i) {
        int p;
        cin >> p;
        --p;
        if (ok[p]) ++ok[p];
        else ok[p] += 2;
    }
    int c;
    cin >> c;
    int ans = 0;
    for (int i = 0; i < c; ++i) {
        int p;
        cin >> p;
        --p;
        if (ok[p] == 2 || ok[p] == 0) {
            ++ans;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3216
let [|n;m|] = stdin.ReadLine().Split() |> Array.map int
let mutable a = stdin.ReadLine().Split() |> Array.map int64
let mutable bt = Array.zip a [|1..n|] |> Set.ofArray
let rec f i =
    if i=m then ()
    else
        let (x, y) as b = Set.maxElement bt
        bt <- Set.remove b bt
        bt <- Set.add (x / 2L, y) bt
        f (i+1)
f 0
bt |> Set.fold (fun s (x, y) -> s + int64 x) 0L |> stdout.WriteLine

Measured memory_bytes: 46772
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
#define ALL(v) (v).begin(), (v).end()

double Main(int N, VI &x, VI &y)
{
    double ans = 0.0;
    VI towns(N);
    REP(i, N) towns[i] = i;
    double nume = 0.0;
    double deno = 1.0;
    REP(i, N) deno *= (double)(i+1);
    do {
        REP(i, N-1) nume += sqrt(
             pow(x[towns[i]]-x[towns[i+1]], 2)
            +pow(y[towns[i]]-y[towns[i+1]], 2)
            );
    }while(next_permutation(ALL(towns)));
    ans = nume/deno;
    return ans;
}

int main(void){
    int N;
    cin >> N;
    VI x(N);
    VI y(N);
    REP(i, N) cin >> x[i] >> y[i];
    printf("%.10f\n",Main(N, x, y));
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static long count = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); //カードの枚数
        Cards[] cards = new Cards[n]; //カードの配列
        for(int i=0; i<n; i++) { //情報格納
            cards[i] = new Cards(sc.next(), sc.nextInt(), i);
        }

        quickSort(cards, 0, n-1);

        String s = "Stable";
        for(int i=0; i<n-1; i++) {
            //同じ数字の要素が並んでいる && インデックスが前にある要素の方が大きい場合
            //ソートの際に順番が逆転しているので不安定なソートとみなす
            if(cards[i].num==cards[i+1].num && cards[i].i>cards[i+1].i) {
                s = "Not stable";
                break;
            } 
        }
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<n; i++) {
            if(i==n-1) sb.append(cards[i].pic + " " + cards[i].num);
            else sb.append(cards[i].pic + " " + cards[i].num + "\n");
        }
        System.out.println(s); //出力（安定or不安定）
        System.out.println(sb); //出力（並べ替え後のカード）
    }
    /**
     * トランプカード格納クラス
     */
    static class Cards {
        String pic;
        int num;
        int i;
        Cards (String pic, int num, int i) {
            this.pic = pic;
            this.num = num;
            this.i = i;
        }
    }
    /**
     * クイックソート
     */
    static void quickSort(Cards[] c, int p, int r) {
        if(p<r) {
            int x = partition(c, p, r);
            quickSort(c, p, x-1);
            quickSort(c, x+1, r);
        }
    }
    /**
     * Partition
     */
    static int partition(Cards[] c, int p, int r) {
        int x = c[r].num;
        int i = p-1;
        Cards tmp;
        for(int j=p; j<r; j++) {
            if(c[j].num<=x) {
                i += 1;
                tmp = c[j];
                c[j] = c[i];
                c[i] = tmp;
            }
        }
        tmp = c[i+1];
        c[i+1] = c[r];
        c[r] = tmp;
        return i+1;
    }
}


Measured memory_bytes: 99260
import math
import random
m = int(input())
n = 10000
def sosuuhantei(x):
    p = x
    if p < 2:
        return false
    elif  n == 2:
        return p
    else:
        for i in range(3,math.floor(math.sqrt(x)) + 1,2):
            if x % i == 0:
                return False
        else:
             return x
sosulist = []
 
if n < 2:
    None
elif n == 2:
    sosulist.append(2)
else:
    sosulist.append(2)
    for i in range(3,n+1,2):
        sosulist.append(sosuuhantei(i))
        
while False in sosulist:
    sosulist.remove(False)

s = []
for i in range(len(sosulist)):
    if sosulist[i] % 5 == 1:
        s.append(sosulist[i])

strs = ''
for i in range(m):
    strs = strs + str(s[i]) + ' '
print(strs)

Measured memory_bytes: 3444
// Problem Code: abc176_e

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int bomber(int H, int W, int M, vector<int>& h, vector<int>& w) {
	int max_bombs, r, c;
	set<int> seen;
	vector<int> row(H), col(W);
	
	for (int i = 0; i < M; i++) {
		row[h[i]]++;
		col[w[i]]++;
	}
	
	r = distance(row.begin(), max_element(row.begin(), row.end()));
	max_bombs = row[r];
	for (int i = 0; i < M; i++)
		if (h[i] == r)
			seen.insert(w[i]);
	
	for (c = 0; c < W; c++) {
		int bombs = row[r] + col[c] - seen.count(c);
		max_bombs = max(bombs, max_bombs);
	}
	
	seen.clear();
	c = distance(col.begin(), max_element(col.begin(), col.end()));
	max_bombs = max(max_bombs, col[c]);
	for (int i = 0; i < M; i++)
		if (w[i] == c)
			seen.insert(h[i]);
	
	for (r = 0; r < H; r++) {
		int bombs = row[r] + col[c] - seen.count(r);
		max_bombs = max(bombs, max_bombs);
	}
	
	return max_bombs;
}

int main() {
	int H, W, M;
	cin >> H >> W >> M;
	vector<int> h(M), w(M);
	for (int i = 0; i < M; i++) {
		cin >> h[i] >> w[i];
		h[i]--, w[i]--;
	}
	cout << bomber(H, W, M, h, w);
	return 0;
}

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

int main(void){
  int N;
  cin >> N;

  int AC = 0;
  int WA = 0;
  int TLE = 0;
  int RE = 0;

  string X;

  for (int i = 0; i < N; i++){
    cin >> X;
    if (X == "AC"){
      AC = AC + 1;
    }
    if (X == "WA"){
      WA = WA + 1;
    }
    if (X == "TLE"){
      TLE = TLE + 1;
    }
    if (X == "RE"){
      RE = RE + 1;
    }
  }

  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;

}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    while(tt--)
    {
        string s;
        cin >> s;
        int n = s.length();
        if(s.at(n-1)=='s')
        {
            s+="es";
        }
        else
        {
            s+="s";
        }
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>
int main(void){
	char s[26];
	scanf("%s",s);
	int i,j;
	for(i=0;i<strlen(s);i++){
		char c=s[i];
		for(j=i+1;j<strlen(s);j++){
			if(c==s[j]){printf("no");return 0;}
		}
	}
	printf("yes");
}

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


void show(int A[], int N){
  for(int i=0; i<N; i++){
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  return;
}

int insertionSort(int A[], int N){
  for(int i=1; i<N; i++){
    int v = A[i];
    int j = i-1;
    while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    show(A, N);
  }
}

int main(){
  int N, A[1000];
  cin >> N;
  for(int i=0; i<N; i++) cin >> A[i];
  show(A, N);
  insertionSort(A, N);
  return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

string s;

int main()
{
    FAST_IO;

    cin >> s;
    int r = 0, b = 0;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] == '0')
            r++;
        else
            b++;
    }
    cout << 2*min(r,b) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int a[maxn], b[maxn], c[maxn], uf[maxn], act[maxn], od[maxn];
vector<int> to[maxn];
long long sum[maxn], f[maxn];
int find(int x){
	if(x == uf[x]) return x;
	return uf[x] = find(uf[x]);
}
int main(){
	iota(uf, uf + maxn, 0);
	iota(od, od + maxn, 0);
	int n, m; cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	for(int i = 0; i < m; i++){
		int u, v; cin >> u >> v; u--; v--;
		to[u].push_back(v);
		to[v].push_back(u);
	}
	for(int i = 0; i < n; i++) c[i] = max(a[i] - b[i], 0), sum[i] = b[i];
	sort(od, od + n, [&](int a, int b){
		return c[a] < c[b];
	});
	for(int i = 0; i < n; i++){
		int u = od[i];
		vector<int> comp;
		for(int v : to[u]){
			if(act[find(v)]){
				comp.push_back(find(v));
			}
		}
		sort(comp.begin(), comp.end());
		comp.erase(unique(comp.begin(), comp.end()), comp.end());
		for(int v : comp){
			sum[u] += sum[v];
		}
		if(comp.size()){
			f[u] = 1ll<<60;
			for(int v : comp){
				f[u] = min(f[u], sum[u] - sum[v] + max(1ll * c[u], f[v]));
			}
		} else {
			f[u] = c[u] + b[u];
		}
		for(int v : comp)
			uf[v] = u;
		act[u] = 1;
	}
	cout << f[od[n-1]] << endl;
	return 0;
}


Measured memory_bytes: 10236
#include <cstdio>
using namespace std;

int main(){
	unsigned q, s;
	for(scanf("%u", &q); q--; ){
		scanf("%x", &s);
		int x = (s & 0x7fffffffu) >> 7;
		int y = 0;
		for(int i = 0; i < 7; ++i){
			if(s >> i & 1){
				y += 78125 << i;
			}
		}

		int d = 7;
		while(d > 1 && y % 10 == 0){
			y /= 10;
			--d;
		}
		
		if(s >> 31) putchar('-');
		printf("%d.%0*d\n", x, d, y);
	}
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;
using ll=long long;

int main() {
  ll N;
  cin >> N;
  vector<ll> V(5);
  for (ll i=0; i<5; i++) {
    cin >> V[i];
  }
  ll S=0;
  
  ll Ve=V[0];
  for (ll i=1; i<5; i++) {
    if (V[i]<Ve) {
      Ve=V[i];
    }
  }

  cout << (N-1)/Ve+5 << endl;
  
}

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

int main(){
    int N, M;
    std::cin >> N >> M;

    int K;
    std::vector<int> a(M, 0);

    for(int i = 0; i < N; i++){
        std::cin >> K;
        for(int j = 0; j < K; j++){
            int input;
            std::cin >> input;
            a[input - 1]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < M; i++){
        if(a[i] == N)ans++;
    }

    std::cout << ans;


    return 0;
}

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

class Solution {
  int n, m;
  vector<vector<int>> g;
  vector<int> pa, indeg, vis;
  void dfs(int u, int p = -1) {
    pa[u] = p, vis[u] = true;
    for (int v: g[u]) {
      --indeg[v];
    }
    for (int v: g[u]) {
      if (indeg[v] == 0 and not vis[v]) dfs(v, u);
    }
  }
public:
  void run() {
    cin >> n >> m; 
    g.resize(n), pa.resize(n);
    indeg.resize(n), vis.resize(n);
    for (int i = 0; i < m + n - 1; ++i) {
      int u, v; cin >> u >> v; --u, --v;
      g[u].push_back(v);
      ++indeg[v];
    }
    dfs(find_if(indeg.begin(), indeg.end(), 
        [&](int a) { return a == 0; }) - indeg.begin());
    for (int i = 0; i < n; ++i) cout << pa[i] + 1 << '\n';
  }
};

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  Solution().run();
}


Measured memory_bytes: 9728
def myAnswer(K:int,S:int) -> int:
   ans = 0
   for x in range(K+1):
      for y in range(K+1):
        z = S - (x + y)
        if 0 <= z and z <= K:
           ans += 1
   return ans

def modelAnswer():
   return
def main():
   K,S = map(int,input().split())
   print(myAnswer(K,S))
if __name__ == '__main__':
   main()

Measured memory_bytes: 40940
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> a[i][j];
        }        
    }
    vector<int> raw, column;

    rep(i, h) {
        int flag = true;
        rep(j, w) {
            if (a[i][j] != '.') {
                flag = false;
                break;
            }
        }

        if (flag) raw.push_back(i);
    }

    rep(j, w) {
        int flag = true;
        rep(i, h) {
            if (a[i][j] != '.') {
                flag = false;
                break;
            }
        }

        if (flag) column.push_back(j);
    }

    rep(i, h) {
        int flagr = false;
        for (auto x : raw) {
            if (x == i) {
                flagr = true;
                break;
            }
        }

        if (flagr) continue;

        rep(j, w) {
            int flagc = false;
            for (auto y : column) {
                if (y == j) {
                    flagc = true;
                }
            }

            if (flagc) continue;

            cout << a[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	vi num(10);
	REP(i, 10) {
		cin >> num[i];
	}

	sort(RALL(num));
	REP(i, 3) {
		cout << num[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
using namespace std;
int main(){
int n, p;
cin >> n;
int mn = n;
int count = 0;  
for (int i=0; i<n; i++){
  	
	cin >> p;
	if (p <= mn){
      count++;
    }
  	mn = min(p, mn);
	}
  cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int f(const void *a,const void *b){
  return strcmp((char*)a,(char*)b);
}

int main(void){                                                                                                                                                                                int N;                                                                                                                                                                                       scanf("%d\n",&N);                                                                                                                                                                            char S[200002][12];
  for(int i=0;i<N;i++)
    scanf("%s\n",S[i]);
  qsort((void*)S,N,sizeof(S[0]),f);
  int max=1;
  int c=1;
  for(int i=0;i<N-1;i++){
    if(strcmp(S[i],S[i+1])==0) c++;
    else c=1;
    if(max<c) max=c;
  }
                                                                                                                                                                                               for(int i=0;i<N-max+1;i++){
    if(strcmp(S[i],S[i+max-1])==0)
      printf("%s\n",S[i]);
  }
  return 0;
}


Measured memory_bytes: 6268
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef pair<int,int> PII;
typedef long long int ll;
typedef pair< ll,ll> PLL;
typedef unsigned long long int ULL;
typedef pair<ULL,int> PUI;
#define S second
#define F first
typedef tree<
PLL,
null_type,
less<PLL>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;


PLL operator+(PLL a,PLL b){ return {a.first + b.first, a.second + b.second}; }
PLL operator-(PLL a,PLL b){ return {a.first - b.first, a.second - b.second}; }
PLL operator*(PLL a,PLL b){ return {a.first * b.first, a.second * b.second}; }
PLL operator/(PLL a,PLL b){ return {a.first / b.first, a.second / b.second}; }
PLL operator%(PLL a,PLL b){ return {( b.first + a.first) % b.first, (b.second + a.second) % b.second}; }
PLL operator%(PLL a,ll b){ return {a.first % b, a.second % b} ;}
PLL operator+(PLL a,ll b){ return {a.first + b, a.second + b} ;}
PLL operator-(PLL a,ll b){ return {a.first - b, a.second - b} ;}
PLL operator*(PLL a,ll b){ return {a.first * b, a.second * b} ;}

ostream& operator<<(ostream &out,PLL a)
{
    out << "( " << a.first << ", " << a.second << " )" ;
    return out;
}

ostream& operator<<(ostream &out,PUI a)
{
    out << "( " << a.first << ", " << a.second << " )" ;
    return out;
}
/*
	Order Statistics Tree ( OST )

	find_by_order()
		takes an integer k and returns an iterator to the k'th largest element counting from zero
	order_of_key()
		takes an element, here an integer and returns the number of elements strictly smaller than input
*/


int const MOD = 1e9 + 7;

int const N = 500 + 10;
bool mark[N] ;

void sieve()
{
    for(int i = 2; i < N; i++){
        if(!mark[i]){
            for(int j = 2 * i ; j < N; j += i) 
                mark[j] = 1;
        }
    }
}

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

    int a,b;
    cin >> a >> b ;
    if((a + b ) % 2 == 0){
        cout << (a+b)/2 << endl;
    }
    else{
        cout << "IMPOSSIBLE\n";
    }
    return 0;

}


Measured memory_bytes: 256
want_red, want_green, have_red, have_green, have_white = [int(n) for n in input().rstrip().split()]

red_shortage = want_red-have_red
green_shortage = want_green-have_green

red_deliciousness = sorted([int(n) for n in input().rstrip().split()], reverse=True)[:want_red]
green_deliciousness = sorted([int(n) for n in input().rstrip().split()], reverse=True)[:want_green]
white_deliciousness = sorted([int(n) for n in input().rstrip().split()], reverse=True)[:want_red+want_green]

happiness = sum(sorted(red_deliciousness+green_deliciousness+white_deliciousness,reverse=True)[:want_red+want_green])
print(happiness)

Measured memory_bytes: 22544
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>=10||b>=10){
		printf("-1\n");
	}
	if(!(a>=10||b>=10)){
		printf("%d\n",a*b);
	}
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init()  {
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, err := strconv.Atoi(input())
	if err != nil {
		log.Fatal(err)
	}

	a := make([]int, 3*n)
	for i, _ := range a {
		a[i], err = strconv.Atoi(input())
		if err != nil {
			log.Fatal(err)
		}
	}

	sort.Ints(a)
	a = a[n:]

	sum := 0
	for i := 0; i < n; i++ {
		sum += a[2*i]
	}

	fmt.Println(sum)
}


Measured memory_bytes: 6016
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int dp[1100000][2];
string sa;

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>sa;
	n=sa.size();
	for(i=0;i<=n;i++){
		for(j=0;j<2;j++){
			dp[i][j]=1e9;
		}
	}
	dp[0][0]=0,dp[0][1]=1;
	for(i=0;i<n;i++){
		a=(int)sa[i]-(int)'0';
		dp[i+1][0]=min(dp[i+1][0],dp[i][0]+a);
		dp[i+1][1]=min(dp[i+1][1],dp[i][0]+a+1);
		dp[i+1][0]=min(dp[i+1][0],dp[i][1]+10-a);
		dp[i+1][1]=min(dp[i+1][1],dp[i][1]+9-a);
	}
	cout<<dp[n][0]<<endl;
}

Measured memory_bytes: 9476
#include<bits/stdc++.h>
#include <iterator>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
#define ar array 
using namespace std;
ll dp[200005];
ll cs_dp[200005];

ar<ll,2> moves[20];
ll mod=998244353;
int main(){
  ll n,k;
  cin>>n>>k;
  dp[1]=1;
  cs_dp[1]=1;
  
  for(ll i=1;i<=k;i++)cin>>moves[i][0]>>moves[i][1];
  
  
  for(ll i=2;i<=n;i++){
  	for(ll j=1;j<=k;j++){
  		ll lo=max(i-moves[j][1],1ll);
  		ll hi=max(i-moves[j][0],0ll);
  		ll t_add=0;
		if(lo-1>=0)t_add=(cs_dp[hi]-cs_dp[lo-1]+mod)%mod;
  		dp[i]=(dp[i]+t_add)%mod;
        
  	}
    
	cs_dp[i]=(cs_dp[i-1]+dp[i])%mod;
  }
  
  cout<<dp[n]<<endl;

    
    
    
    
    
    
	
   
}
  

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    cout << N * (N - 1) / 2 << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
signed main()
{
	scanf("%d%d%d",&a,&b,&c);
	if(a<b)
	swap(a,b);
	if(a<c)
	swap(a,c);
	if(b<c)
	swap(b,c);
	if(a==b)
	{
		if(b!=c)
		printf("Yes");
		else
		printf("No");
	}
	else
	if(b==c)
	{
		if(a!=b)
		printf("Yes");
		else
		printf("No");
	}
	else
	printf("No");
	return 0;
}

Measured memory_bytes: 256
a, b, c=map(int, raw_input().split())
if a==b==c:
	print 0 if a%2 else -1
else:
	result=0
	while not a%2 and not b%2 and not c%2:
		result+=1
		a, b, c=(b+c)/2, (a+c)/2, (a+b)/2
	print result

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

int main()
{
	int x,y,sum=0; cin>>x>>y;
	int s[y];
	for (int i=0;i<y;i++)
	{
    cin>>s[i];
	sum += s[i];
	}
	if (sum>=x)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 2e5+9, INF = 0x3f3f3f3f;

int main( void ) {
    ios::sync_with_stdio( false );
    int dt[7];
    for( int i = 1; i <= 6; ++i ) cin >> dt[i];
    string q;
    cin >> q;
    int len = q.length();
    for( int i = 0; i < len; ++i ) {
        if( q[i] == 'E' ) {
            int t = dt[1];
            dt[1] = dt[4];
            dt[4] = dt[6];
            dt[6] = dt[3];
            dt[3] = t;
        }
        else if( q[i] == 'W' ) {
            int t = dt[1];
            dt[1] = dt[3];
            dt[3] = dt[6];
            dt[6] = dt[4];
            dt[4] = t;
        }
        else if( q[i] == 'N' ) {
            int t = dt[1];
            dt[1] = dt[2];
            dt[2] = dt[6];
            dt[6] = dt[5];
            dt[5] = t;
        }
        else {
            int t = dt[1];
            dt[1] = dt[5];
            dt[5] = dt[6];
            dt[6] = dt[2];
            dt[2] = t;
        }
    }
    cout << dt[1] << '\n';
    return 0;
}



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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k; string s;
    cin >> n;
    cin >> s;
    cin >> k;

    k --;
    for(auto& i : s) {
        if(i != s[k])
            i = '*';
    }

    cout << s << endl;
}


Measured memory_bytes: 256
s = input()
def ispalindrome(s):
    for i in range(len(s)//2):
        if s[i] != s[~i]:
            return False
    return True
if ispalindrome(s) and ispalindrome(s[:len(s)//2]) and ispalindrome(s[len(s)//2+1:]):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060