akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define erep(i,n) for (int i = 0; i <= (n); ++i)
#define brep(i,n) for (int i = n; i >= 0; i--)
#define PI 3.14159265359
using namespace std;
using P = pair<int,int>;
using ll = long long;
using Graph = vector<vector<int> > ;
const int INF = 100005;
const int MAX_K = 55;
const int MAX_W = 200005; 
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// ユークリッド互除法
unsigned gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}
*/

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
  int n;
  ll ans = 0;
  cin >> n;
  for(int i=1;i<=n;i++){
    if(i%3 == 0 || i%5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;

}

Measured memory_bytes: 3560
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 H,W;
    cin>>H>>W;

    int64 blankH[H][W];
    int64 blankW[H][W];

    for(int64 i=0;i<H;i++){
        for(int64 j=0;j<W;j++){
            blankW[i][j]=0;
            blankH[i][j]=0;
        }
    }

    int64 ans=0;

    string S[H];

    for(int64 i=0;i<H;i++){
        cin>>S[i];
    }

    int64 tmp=0,tmpl=0;

    for(int64 i=0;i<H;i++){
        tmp=0;
        tmpl=-1;
        for(int64 j=0;j<W;j++){
            if(S[i][j]=='#'){
                for(int64 k=tmpl+1;k<j;k++){
                    blankW[i][k]=tmp;
                }
                tmp=0;
                tmpl=j;
            }else{
                tmp++;
            }
        }
        for(int64 k=tmpl+1;k<W;k++){
            blankW[i][k]=tmp;
        }
    }
    for(int64 i=0;i<W;i++){
        tmp=0;
        tmpl=-1;
        for(int64 j=0;j<H;j++){
            if(S[j][i]=='#'){
                for(int64 k=tmpl+1;k<j;k++){
                    blankH[k][i]=tmp;
                }
                tmp=0;
                tmpl=j;
            }else{
                tmp++;
            }
        }
        for(int64 k=tmpl+1;k<H;k++){
            blankH[k][i]=tmp;
        }
    }

    // for(int64 i=0;i<H;i++){
    //     for(int64 j=0;j<W;j++){
    //         cout<<blankH[i][j]<<"\t";
    //     }
    //     cout<<endl;
    // }

    for(int64 i=0;i<H;i++){
        for(int64 j=0;j<W;j++){
            ans=max(ans,blankH[i][j]+blankW[i][j]-1);
        }
    }

    cout<<ans<<endl;

    
    return 0;
}


Measured memory_bytes: 66816
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define ull unsigned long long
#define ff first
#define ss second
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test int t;cin>>t;while(t--)
#define mp make_pair
#define modInv(n) po(n,mod-2)%mod
#define ncr(n,r) (((fact[n]*modInv(fact[r]))%mod)*modInv(fact[n-r]))%mod
#define setbits(y) __builtin_popcountll(y)
#define mod 1000000007

ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%mod;
        ans=(ans%mod * ans%mod)%mod;
    }
    else{
        ans = po(a,(b-1)/2)%mod;
        ans = (ans%mod * ans%mod * a)%mod;
    }
    return ans%mod;
}


void solve(){
   ll n,k,i,j;
   cin>>n>>k;
   ll arr[n+1];
   for(i=1;i<=n;i++) cin>>arr[i];
   ll dp[n+1]={};
   for(i=2;i<=n;i++){
       ll val = 1000000007;
       for(j=1;j<=k;j++){
           if(i-j>=1){
                val = min(val , dp[i-j]+abs(arr[i]-arr[i-j]));
           }
       }
    //   cout<<val<<" ";
      dp[i]=val;
   }
  cout<<dp[n];
}


int main(){
    IOS
    // test{
    //     solve(); cout<<"\n";
    // }
    solve();
}

Measured memory_bytes: 5136
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define MAX 100100
#define pi pair<int,int>
#define mp make_pair
#define fr first
#define sd second
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,f[MAX];
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
queue<pi> Q;
map<pi,int> M;
set<int> E[MAX];
pi get(int x,int y){if(x>y)swap(x,y);return mp(x,y);}
void Link(int x,int y)
{
	E[x].insert(y);E[y].insert(x);
	pi u=get(x,y);
	if(++M[u]==2)Q.push(u);
}
int main()
{
	n=read();
	for(int i=1;i<=n;++i)f[i]=i;
	for(int i=1;i<=n+n-2;++i)Link(read(),read());
	for(int i=1,x,y;i<n;++i)
	{
		do
		{
			if(Q.empty()){puts("NO");return 0;}
			x=Q.front().fr,y=Q.front().sd;Q.pop();
			x=getf(x);y=getf(y);
		}while(x==y);
		if(E[x].size()>E[y].size())swap(x,y);
		f[x]=y;M.erase(get(x,y));E[y].erase(x);
		for(auto v:E[x])
		{
			int fv=getf(v);
			if(fv==y)continue;
			M.erase(get(x,fv));
			E[fv].erase(x);//E[x].erase(fv);
			Link(fv,y);
		}
	}
	puts("YES");
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 0; i < N; ++i)
  {
  	int l, r;
  	cin >> l >> r;
  	ans += r - l + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n;
  cin>>n;
  vector<long long int> a(n);
  long long int ans=0;
  for(long long int i=0; i<n; i++){
    cin>>a.at(i);
    if((i+1)%2!=0&&a.at(i)%2!=0){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(I,n) for (int I = 0; I < (n); ++I)
using namespace std;
typedef long long ll;
 
int main() {
    
    int A;
    int B;
    
    cin>>A>>B; 
    
    if(A>=2*B){
       
       cout<<A-2*B<<endl;
    }
    
    else if(A<2*B){
       
       cout<< 0 <<endl;
    }
    
    
    
    
    
  
  return 0;
}

Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))

S = []
for _ in range(D):
  S.append(list(map(int, input().split())))

T = []
for _ in range(D):
  T.append(int(input())-1)
  
LastD = [0] * 26

sc = 0
for i in range(D):
  t = T[i]
  sc += S[i][t]
  LastD[t] = i+1
  for j in range(26):
    sc -= C[j] * (i+1 - LastD[j])
  print(sc)
    

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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int A, B;
    cin >> A >> B;
    vector<vector<int> > vv(100, vector<int>(100));
    int big = max(A, B);
    int small = min(A, B);
    [&] {

        for (int i = 0; i < 25; i++) {
            for (int j = 0; j < 25; j++) {
                int x = i * 4;
                int y = j * 4;
                for (int dx = 0; dx < 3; dx++) {
                    for (int dy = 0; dy < 3; dy++) {
                        vv[x + dx][y + dy] = 1;

                    }
                }
                if (small > 1) {
                    small--;
                    vv[x + 1][y + 1] = 0;
                }
                big--;
                if (big == 0) return;
            }
        }
    }();

    cout << 100 << " " << 100 << endl;
    if (A < B) {
        rep(i, 0, 100) {
            rep(j, 0, 100) {
                if (vv[i][j] == 0) cout << ".";
                else cout << "#";
            }
            cout << endl;
        }
    } else {
        rep(i, 0, 100) {
            rep(j, 0, 100) {
                if (vv[i][j] == 0) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 888
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int64_t i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define acc(v) accumulate(v.begin(), v.end(),0);
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

int64_t digit(int64_t a) {
  int64_t len = to_string(a).size();
  return len;
}

int64_t func(int64_t a, int64_t b) {
  return max(digit(a), digit(b));
}

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

  int64_t n, res = inf;
  cin >> n;
  reps(a,1,sqrt(n)+1) {
    if(n % a != 0) continue;
    int64_t b = n / a;
    res = min(res, func(a,b));
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"

int main() {

	using namespace std;

	long long N;
	cin >> N;

	vector<long long> A(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	long long sum_diff = 0;

	for (int i = 1; i < N; i++) {
		
		if (A[i - 1] > A[i]) {
			long long diff = A[i - 1] - A[i];
			sum_diff += diff;
			A[i] += diff;
		}

	}

	cout << sum_diff << endl;

	return 0;

}

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

#define SYNC ios::sync_with_stdio(0);
#define F first
#define S second
#define endl '\n'


using namespace std;

using ll = long long int;
using ii = pair<int, int>;
using vii = vector<ii>;
using vi = vector<int>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const int MAXN = 209877;
const ll mod = 1000000007;

vector<vii> g;

vi seen;
vi cor;

void dfs (int idx) {
    seen[idx] = 1;
    for (auto i : g[idx]) {
        if (!seen[i.first]) {
            if (i.second%2 == 0) {
                cor[i.first] = cor[idx];
            } else {
                cor[i.first] = !cor[idx];
            }
            dfs(i.first);
        }
    }
}

int main() {
    SYNC
    int n, v, u, w;
    cin >> n;
    g.assign(n+1, vector<ii>());
    for (int i = 1; i < n; ++i) {
        cin >> v >> u >> w;
        g[v].push_back(make_pair(u, w));
        g[u].push_back(make_pair(v, w));
    }
    seen.assign(n+1, 0);
    cor.assign(n+1, 0);
    dfs(1);
    for (int i  = 1; i <= n; ++i) {
        cout << cor[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 7808
n,m  = map(int,input().split())
lmax = 0
rmin = 10**10
for i in range(m):
         l,r = map(int,input().split())
         if l > lmax:
                  lmax = l
         if r < rmin:
                  rmin = r
if lmax > rmin:
         print(0)
else:
         print(rmin - lmax +1)


Measured memory_bytes: 3060
n,m = gets.split.map(&:to_i)
a = Array.new(n).map{Array.new()}
ans = Array.new(n-1,0)
dist = Array.new(n, -1)
dist[0] = 0
q = Array.new()
q.push(1); 
for i in 1..m
    x,y = gets.split.map(&:to_i)
    a[x-1].push(y)
    a[y-1].push(x)
end
ena = false
while q.length != 0
    v = q[0]
    q.shift()
    a[v-1].each { |p|
        if dist[p-1] == -1
            dist[p-1] = dist[v-1] + 1
            ans[p-2] = v
            q.push(p)
        else
            if dist[v-1] > dist[p-1] + 1
                ena = true
                break
            end
        end
    }
    if ena == true
        break
    end
end
if ena == true
    puts 'No'
else
    puts 'Yes'
    ans.each{|a| puts a}
end

Measured memory_bytes: 33556
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s.front() == 'x'&&s.back() == 'x')
		cout << 'x' << endl;
	else cout << 'o' << endl;
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m;
    cin>>n>>m;
//   cout<<min(abs(m-n),min(abs(-1*n-m)+1,min(abs(-1*n+m)+1,min(abs(-1*n+m)+2,abs(-1*n-m)+2))))<<endl;
   // if(n==m) continue;
   // cout<<n<<" "<<m<<" ";
      if(n<m)
            {
                ll pos=n*(-1);
                if(n>=0&&m>=0)
                {
                    //3 5
                    cout<<m-n<<endl;
                }
                else if(n<=0&&m>=0)
                {
                    //-3 5
                    //3 5
                    //-3 2
                    //-3+1=-2 2
                    if(pos<=m)
                    {
                        if(n!=0)
                        {
                            cout<<m-pos+1<<endl;
                        }
                        else
                        {
                            cout<<m-pos<<endl;
                        }
                    }
                    else
                    {
                        // cout<<"A"<<endl;
                        //ll ans=pos-m;
                        if(m==0)
                        {
                            cout<<pos<<endl;
                        }
                        else
                            cout<<pos-m+1<<endl;
                    }
                }
                else if(n<=0&&m<=0)
                {
                    //-3 -2
                    cout<<pos+m<<endl;
                }
            }
            else
            {
                if(n>=0&&m>=0)
                {
                    //4 2
                    if(m!=0)
                    {
                        cout<<n-m+2<<endl;
                    }
                    else
                    {
                        cout<<n+m+1<<endl;
                    }
                }
                else if(n>=0&&m<=0)
                {
                    ll pos=-1*m;
                    if(n==0)
                    {
                        cout<<-1*m+1<<endl;
                    }
                    else
                    {
                        if(n<=pos)
                        {
                            cout<<pos-n+1<<endl;
                        }
                        else
                        {
                            cout<<n+m+1<<endl;
                        }
                    }
                }
                else
                {
                    if(n==0)
                    {
                        cout<<(-1)*m+1<<endl;
                    }
                    else
                    {
                        cout<<(-1)*m-(-1)*n+2<<endl;
                    }
                }
            }
    return 0;
}

Measured memory_bytes: 256
import sys
import collections
import bisect
s = raw_input()
t = raw_input()
p, e, n = 0, 1, len(s)
ss = set(s)
idx = collections.defaultdict(list)
for i in xrange(n):
    idx[s[i]].append(i)
# print(idx)
for tt in t:
    q = p % n
    if not tt in idx:
        e = 0
        break
    indexs = idx[tt]
    # print(bisect.bisect(indexs, q), indexs)
    res = bisect.bisect_left(indexs, q)
    p += indexs[res] - q + 1 if res < len(indexs) else -q + n + indexs[0] + 1
print((p+1)*e-1)

Measured memory_bytes: 6772
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
A, B = zip(*AB)

ans = 0
for i, a in enumerate(reversed(A)):
    a += ans
    if a % B[N-1-i] != 0:
        ans += B[N-1-i]-a % B[N-1-i]

print(ans)


Measured memory_bytes: 36084
n,x=map(int,input().split())

cnt=1
p=1
C=[0]*(n+1)
C[0]=1
for i in range(1,n+1):
    cnt=cnt*2+3
    C[i]=cnt

def mid(n):
    return (C[n]-1)//2


def f(n,l):
    if n==0:
        return 1
        
    if l==mid(n):
        return f(n-1,mid(n-1)*2)+1
    elif l==mid(n)*2:
        return f(n-1,mid(n-1)*2)*2+1
    elif l==0:
        return 0
    elif 0<l and l<mid(n):
        return f(n-1,l-1)
    else:
        return f(n-1,2*mid(n-1))+1+f(n-1,l-mid(n)-1)
print(f(n,x-1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;
    //cin>>testcase;
    for(int p=0;p<testcase;p++){
    ll n=0,m=0,c=0;
    cin>>n>>m>>c;
    ll counter=0;
    int array1[m]={0};
    for(int i=0;i<m;i++)
        cin>>array1[i];
    int array[20][20]={0};
    for(int i=0;i<n;i++){

        for(int j=0;j<m;j++){
            cin>>array[i][j];

        }
    }
    for(int i=0;i<n;i++){
        ll sum=0;
        for(int j=0;j<m;j++){
            sum+=array[i][j]*array1[j];
        }
        if(sum+c>0)
            counter++;
    }
    cout<<counter;


    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())

arr = []

for i in range(n):
	arr.append(int(input()))

l = 0
r = 0


ans = 0
while l < n:
	while  r+1 < n and arr[r+1] > 0:
		r += 1

	ans += sum(arr[l:r+1])/2
	l = r+1
	r = l

print ans



Measured memory_bytes: 8964
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int n;
int h[100010];
int dp[100010];

void chmin(int a, int *b)
{
	if (*b > a)
		*b = a;
}

int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		dp[i] = INT_MAX;
		scanf("%d", h+i);
	}
	dp[0] = 0;

	for (int i = 0; i < n; i++)
	{
		if(i+1 < n) chmin(dp[i] + abs(h[i + 1] - h[i]), &dp[i + 1]);
		if(i+2 < n) chmin(dp[i] + abs(h[i + 2] - h[i]), &dp[i + 2]);
	}

	printf("%d", dp[n - 1]);
	return 0;
}


Measured memory_bytes: 896
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    N = SI()
    
    if N == 0:
        print(0)
    else:
        ret = ''
        cursor = 1
        devide = 2
        while N != 0:
            if N % devide == 0:
                ret = '0' + ret
            else:
                ret = '1' + ret
                N -= cursor
            cursor *= -2
            devide *= 2
        
        print(ret)

if __name__ == "__main__":
    main()

Measured memory_bytes: 4336
import sys
from operator import itemgetter
readline = sys.stdin.buffer.readline
MOD = 10**9+7
INF = float('inf')

def main():
    N = int(readline())
    AB = []
    for _ in range(N):
        a, b = map(int, readline().split())
        AB.append((a,b))
    AB.sort(key=itemgetter(1))
    total = 0
    ans = 'Yes'
    for i in range(N):
        a = AB[i][0]
        b = AB[i][1]
        total += a
        if total>b:
            ans = 'No'
            break
    print(ans)
if __name__ == '__main__':
    main()

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

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=18,L=(1<<N);
int a[L];
int mx[L],smx[L],ans[L];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  rep(i,0,(1<<n)) cin>>a[i];
  rep(i,0,(1<<n)) mx[i]=a[i];
  rep(i,0,n)
    rep(mask,0,(1<<n))
    {
      if(mask&(1<<i))
	{
	  vi tmp;
	  tmp.pb(mx[mask]); tmp.pb(smx[mask]);
	  tmp.pb(mx[mask^(1<<i)]); tmp.pb(smx[mask^(1<<i)]);
	  sort(all(tmp)); reverse(all(tmp));
	  mx[mask]=tmp[0],smx[mask]=tmp[1];
	  ans[mask]=mx[mask]+smx[mask];
	}
    }
  rep(i,2,(1<<n)) ans[i]=max(ans[i],ans[i-1]);
  rep(i,1,(1<<n)) cout<<ans[i]<<endl;
  return 0 ;
}


Measured memory_bytes: 7168
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int a, b, c, d, n; cin >> a >> b >> c >> d >> n;
	b = min(b, 2 * a);
	c = min(c, 2 * b);
	d = min(d, 2 * c);
	
	ll ans = (ll)c * n;
	ans = min(ans, n / 2ll * d + n % 2ll * c);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
int main() {
	int a = 0, n, b = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I')
			a++;
		else
			a--;
		b = max(a, b);
	}
	cout << b << endl;
}

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

using namespace std;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll L;
	cin >> n >> L;
	ld sum = 0;
	deque<P> dq;
	for (int i = 0; i < n; i++) {
		ld t;
		ll v;
		cin >> t >> v;
		ll over = v;
		while (!dq.empty()) {
			ll tmp = min(over, dq.front().second);
			sum -= dq.front().first * (ld)tmp;
			dq.front().second -= tmp;
			over -= tmp;
			if (dq.front().second == 0) dq.pop_front();
			if (over == 0) break;
		}
		sum += t * (ld)v;

		while (!dq.empty()) {
			if (dq.back().first < t) break;
			t = (dq.back().first * (ld)dq.back().second + t * (ld)v) / (ld)(dq.back().second + v);
			v += dq.back().second;
			dq.pop_back();
		}
		dq.push_back(P(t, v));

		cout << fixed << setprecision(12) << sum / (ld)L << endl;
	}
	return 0;
}

Measured memory_bytes: 27828
using System;
class Program
 {
        static void Main(string[] args)
        {
    　　var n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            var sa = s.Split(' ');
            int[] ia = new int[n];
            for(int i = 0;i < ia.Length; i++)
            {
                ia[i] = int.Parse(sa[i]);
            }
 
            int total = 0;
            for(int i = 0;i < ia.Length; i++)
            {
                total += ia[i];
            }
            int ave = (int)Math.Round((double)total / ia.Length);
 
            int diff_total = 0;
 
            for (int i = 0; i < ia.Length; i++)
            {
                diff_total += (int)Math.Pow((ia[i] - ave), 2);
            }
 
            Console.WriteLine(diff_total);
        }
 }

Measured memory_bytes: 11092
a     = list(input())
a_re  = list(reversed(a))

if a == a_re:
  if len(a) % 2 == 0:
    b = a[0:len(a)/2]
    b_re = a[0:len(a)/2]
    b_re = list(reversed(b_re))
    if b == b_re:
      print('Yes')
    else:
      print('No')
  else:
    b = a[0:int(len(a)/2)]
    b_re = a[0:int(len(a)/2)]
    b_re = list(reversed(b_re))
    if b == b_re:
      print('Yes')
    else:
      print('No')
else:
  print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  vector<vector<bool>> B(H, vector<bool>(W, false));
  vector<int> S0, S1, SS0, SS1;
  int filled = 0;
  
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> A.at(i).at(j);
      if (A.at(i).at(j) == '#') 
      {
        B.at(i).at(j) = true;
        filled++;
        S0.push_back(i);
        S1.push_back(j);
      }
    }
    
  }
  
  int ans;
  for (ans = 0; filled < H * W; ans++)
  {
    for (int i = 0; i < S0.size(); i++)
    {
      int s0 = S0.at(i), s1 = S1.at(i);
      vector<int> T0 = {-1, 1, 0, 0};
      vector<int> T1 = {0, 0, -1, 1};
      for (int j = 0; j < 4; j++)
      {
        int t0 = T0.at(j), t1 = T1.at(j);
        if ( (0 <= s0 + t0 && s0 + t0 < H)
            && (0 <= s1 + t1 && s1 + t1 < W)
            && !B.at(s0 + t0).at(s1 + t1) )
        {
          B.at(s0 + t0).at(s1 + t1) = true;
          filled++;
          SS0.push_back(s0 + t0);
          SS1.push_back(s1 + t1);
        }
      }
      
    }
    S0.clear();
    S1.clear();
    for (int i = 0; i < SS0.size(); i++)
    {
      S0.push_back(SS0.at(i));
      S1.push_back(SS1.at(i));
    }
    SS0.clear();
    SS1.clear();
  }

  cout << ans << endl;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

struct UnionFind{
    vector<int> data;
    //data[i] = -x ... iが根であり、サイズがx
    //data[i] = x ... iの親がx

    //最初は全員根
    UnionFind(int size): data(size,-1){}

    bool union_set(int x, int y){//サイズがx>yになるようにしてから、xにyをつなげる
        x=root(x);
        y=root(y);
        if(x != y){
            if(data[y] < data[x]) swap(x,y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find_set(int x, int y){//ルートが一致するかどうかを返す
        return root(x) == root(y);
    }
    int root(int x){//根を見つける。ついでに深さ2にしちゃう
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

struct Edge{
    int s,t,cost;
    bool operator<(const Edge &o) const{
        return cost < o.cost;
    }
};

struct Graph{
    int n;
    vector<Edge> es;

    int kruskal(){
        sort(ALL(es));

        UnionFind uf(n);
        int min_cost = 0;
        REP(i,es.size()){
            Edge& e = es[i];
            if(!uf.find_set(e.s, e.t)){//辺を追加しても閉路ができなければ採用
                min_cost += e.cost;
                uf.union_set(e.s, e.t);
            }
        }

        return min_cost;
    }
};

int main() {
    int N; cin >> N;
    vector<pair<int,int>> X(N);
    vector<pair<int,int>> Y(N);
    REP(i,N){
        int x,y; cin >> x >> y;
        X[i] = {x,i};
        Y[i] = {y,i};
    }
    sort(ALL(X));
    sort(ALL(Y));

    Graph G;
    G.n = N;

    REP(i,N-1){
        G.es.push_back({X[i].second, X[i+1].second, X[i+1].first-X[i].first});
    }


    REP(i,N-1){
        G.es.push_back({Y[i].second, Y[i+1].second, Y[i+1].first-Y[i].first});
    }

    cout << G.kruskal() << endl;
    return 0;
}

Measured memory_bytes: 7988
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

template <typename T>
using V = std::vector<T>;
template <typename T>
vector<T> make_vec(size_t n, T a) {
  return vector<T>(n, a);
}
template <typename... Ts>
auto make_vec(size_t n, Ts... ts) {
  return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '[';
  for (auto &&e : v) os << e << ' ';
  return os << ']';
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << '[';
  for (auto &&e : v) os << e << ' ';
  return os << ']';
}

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  cin >> H >> W;
  auto A = make_vec(H, W, 0);
  auto B = make_vec(H, W, 0);
  REP(i, H) REP(j, W) cin >> A[i][j];
  REP(i, H) REP(j, W) cin >> B[i][j];

  const int M = 30000;
  auto dp = make_vec(H + 1, W + 1, M, false);
  dp[1][0][0] = dp[0][1][0] = true;
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      const int delta = A[i - 1][j - 1] - B[i - 1][j - 1];
      REP(k, M) {
        int k1 = abs(k + delta);
        int k2 = abs(k - delta);
        if (dp[i - 1][j][k]) {
          assert(k1 < M && k2 < M);
          dp[i][j][k1] = true;
          dp[i][j][k2] = true;
        }
        if (dp[i][j - 1][k]) {
          assert(k1 < M && k2 < M);
          dp[i][j][k1] = true;
          dp[i][j][k2] = true;
        }
      }
    }
  }

  REP(k, M) {
    if (dp[H][W][k]) {
      cout << k << endl;
      return 0;
    }
  }
  assert(false);
}


Measured memory_bytes: 28008
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <numeric>
using namespace std;

int main(){
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum = 0;
    for(int i=0; cin >> ch; i++){
        if(ch == '\\') S1.push(i);
        else if(ch == '/' && S1.size()>0){
            int j=S1.top(); S1.pop();
            sum+=i-j;
            int a=i-j;
            while(S2.size()>0 && S2.top().first>j){
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }
    
    vector<int> ans;
    while(S2.size()>0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i=0; i<ans.size(); i++){
        cout << " " << ans[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3152
/*
STring
by.YXH_XianYu
   2018.6.20
 */
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define rep(i,j,k) for(int i=j,lim=k;i<=lim;i++)
#define MXN 200003

int len;
char s[MXN];

int n,
	a[MXN];

int main(){
	//freopen("STring.in","r",stdin);
	//freopen("STring.out","w",stdout);

	scanf("%s",s+1);
	len=strlen(s+1);
	for(int i=1;i<=len;i++)
		a[++n]=(s[i]=='S')?(1):(2),
		(a[n-1]==1 && a[n]==2)?(n-=2):n;
	printf("%d\n",n);

	return 0;
}


Measured memory_bytes: 1280
import java.util.*;
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int num = 0;
		int foo[] = new int[N];
		for (int i = 0; i < N; i++) {
			foo[i] = sc.nextInt();
			X -= foo[i];
			num++;
		}
		int min = foo[0];
		for (int j = 1; j < foo.length; j++) {
			min = Math.min(min, foo[j]);
		}
		while (X >= 0) {
			X -= min;
			num++;
		}
		if (X < 0) {
			num -= 1;
		}
		System.out.println(num);
	}
}

Measured memory_bytes: 21844
s = int(input())

a = [s]
used = [0] * (10**6+1)
used[s] = 1
for i in range(2, 10**6+2):
    if a[-1] % 2 == 0:
        a.append(val := a[-1]//2)
    else:
        a.append(val := 3*a[-1]+1)

    if used[val]:
        print(i)
        break
    else:
        used[val] = 1


Measured memory_bytes: 16772
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define sort(ss) sort(ss.begin(), ss.end())
#define rsort(ss) sort(ss.rbegin(), ss.rend())
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	string ss;
	while(cin>>ss){
		if(ss[0]==ss[1]&&ss[1]==ss[2]&&ss[0]!='s') cout<<ss[0]<<endl;
		else if(ss[0]==ss[1]&&ss[1]==ss[2]&&ss[0]!='s') cout<<ss[0]<<endl;
		else if(ss[3]==ss[4]&&ss[4]==ss[5]&&ss[3]!='s') cout<<ss[3]<<endl;
		else if(ss[6]==ss[7]&&ss[7]==ss[8]&&ss[6]!='s') cout<<ss[6]<<endl;
		else if(ss[0]==ss[3]&&ss[3]==ss[6]&&ss[0]!='s') cout<<ss[0]<<endl;
		else if(ss[1]==ss[4]&&ss[4]==ss[7]&&ss[1]!='s') cout<<ss[1]<<endl;
		else if(ss[2]==ss[5]&&ss[5]==ss[8]&&ss[2]!='s') cout<<ss[2]<<endl;
		else if(ss[0]==ss[4]&&ss[4]==ss[8]&&ss[0]!='s') cout<<ss[0]<<endl;
		else if(ss[2]==ss[4]&&ss[4]==ss[6]&&ss[2]!='s') cout<<ss[2]<<endl;
		else cout<<"d"<<endl;
	}
}

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

int n;

struct Node {
    Node *p, *l, *r;
    int v;
};

Node *root;

void preorder(Node *nd) {
    if (nd == nullptr) return ;
    cout << " "  << nd->v ;
    preorder(nd->l);
    preorder(nd->r);
}

void inorder(Node *nd) {
    if (nd == nullptr) return ;
    inorder(nd->l);
    cout << " "  << nd->v ;
    inorder(nd->r);
}

void print() {
    inorder(root);
    cout << endl;
    preorder(root);
    cout << endl;
}

void insert(int k) {
    Node *z = root;
    Node *y = nullptr;

    while (z != nullptr) {
        if (k <= z->v) {
            y = z;
            z = z->l;
        } else {
            y = z;
            z = z->r;
        }
    }
    if (y == nullptr) {
        root = new Node;
        root->p = root->l = root->r = nullptr;
        root->v = k;
        return;
    }
    z = new Node;
    if (k <= y->v) {
        y->l = z;
    } else{
        y->r = z;
    }
    z->p = y;
    z->l = z->r = nullptr;
    z->v = k;
    return;
}

bool find(int k) {
    Node *x;
    x = root;
    bool flag = false;
    while (x != nullptr) {
        if (x->v < k) {
            x  = x->r;
        } else if (k < x->v) {
            x = x->l;
        } else {
            flag = true;
            break;
        }
    }
    return flag;
}


int main() {
    cin >> n;
    int k; string cmd;
    for (int i = 0; i < n; ++i) {
        cin >> cmd ;
        if (cmd == "insert") {
            cin >> k;
            insert(k); }
        else if (cmd == "print"){
            print();
        } else {
            cin >> k;
            if(find(k)) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 21884
#include <bits/stdc++.h>
#define inf 1000000000
#define maxs(x,y) (x = max(x , y))
#define mins(x,y) (x = min(x , y))
using namespace std;
typedef long long int ll;

int main(){
    int n,i;
    double ans=0.0;
    cin >> n;
    double x[n];
    string u[n];

    for(i=0 ; i<n ; i++){
        cin >> x[i] >> u[i];
        if(u[i] == "BTC"){
            x[i] *= 380000.0;
        }
    }

    for(i=0 ; i<n ; i++){
        ans += x[i];
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = 1;
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            long X = Math.abs(in.nextLong());
            long K = in.nextLong();
            long D = in.nextLong();

            double needed = Math.ceil(((double) X) / D);

            if (K <= needed)
            {
                out.println(Math.abs(X - (K * D)));
            } else
            {
                K -= needed;
                if (K % 2 == 0)
                {
                    out.println((long) Math.abs(X - (needed * D)));
                } else
                {
                    out.println((long) (X - ((needed - 1) * D)));
                }
            }
        }

    }
}



Measured memory_bytes: 27144
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
#include <algorithm>
typedef long long int ll;
const int MAX=1e6+10;
using namespace std;
ll cnt;
int l;
int a[MAX];
int n;
vector<int> G;

void insort(int a[],int n,int g)
{
    for (int i=g; i<n; i++) {
        int v=a[i];
        int j=i-g;
        while (j>=0 && a[j]>v) {
            a[j+g]=a[j];
            j-=g;
            cnt++;
        }
        a[j+g]=v;
    }
}
void shellsort(int a[],int n)
{
    for (int h=1; ; ) {
        if (h>n) {
            break;
        }
        G.push_back(h);
        h=3*h+1;
    }
    for (int i=(int)G.size()-1; i>=0; i--) {
        insort(a, n, G[i]);
    }
}

int main(){
    //freopen("/Users/mac/Desktop/C++?¨????/test/test.txt", "r", stdin);
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    cnt=0;
    shellsort(a, n);
    printf("%d\n",(int)G.size());
    for (int i=(int)G.size()-1; i>=0; i--) {
        printf("%d",G[i]);
        if (i) {
            printf(" ");
        }
    }
    printf("\n");
    printf("%lld\n",cnt);
    for (int i=0; i<n; i++) {
        printf("%d\n",a[i]);
    }
    return 0;
}

Measured memory_bytes: 7160
#include <iostream>
#include <complex>
#include <utility>
using namespace std;

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;

#define X real()
#define Y imag()

#define eps (1e-10)
#define equals(a, b) (fabs((a) - (b)) < eps)

double dot(Vector a, Vector b){
    return a.X * b.X + a.Y * b.Y;
}

double cross(Vector a, Vector b){
    return a.X * b.Y - a.Y * b.X;
}

bool isOrthogonal(Vector a, Vector b){
    return equals(dot(a, b), 0);
}

bool isParallel(Vector a, Vector b){
    return equals(cross(a, b), 0);
}

int main(){
    int q; cin>>q;
    while(q--){
        double x0, y0, x1, y1, x2, y2, x3, y3;
        cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;

        Vector V0 = Point(x0, y0) - Point(x1, y1);
        Vector V1 = Point(x2, y2) - Point(x3, y3);

        int ans = 0;
        if(isParallel(V0, V1)){
            ans = 2;
        }
        else if(isOrthogonal(V0, V1)){
            ans = 1;
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3220
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int INF = (int)1e9;

        while(true){

            int n = sc.nextInt();
            if(n==0) break;

            int[] p = new int[n];
            int[] t = new int[n];
            for(int i=0; i<n; i++){
                p[i] = sc.nextInt();
                t[i] = sc.nextInt();
            }

            int[][] dp = new int[n][4];
            for(int i=0; i<n; i++) Arrays.fill(dp[i], INF);

            int NG = -1;
            if(p[0]<=t[0]) dp[0][1] = p[0];
            else NG = 1;

            for(int i=1; i<n; i++){
                if(NG!=-1) break;
                int time = t[i] - t[i-1];
                if(dp[i-1][3]!=INF && p[i-1]*4+p[i]<=time){
                    dp[i][1] = dp[i-1][3] + p[i-1] + p[i];
                }
                if(dp[i-1][2]!=INF && p[i-1]*3+p[i]<=time){
                    dp[i][1] = Math.min(dp[i][1], dp[i-1][2] + p[i-1] + p[i]);
                }
                if(dp[i-1][1]!=INF && p[i-1]*2+p[i]<=time){
                    dp[i][1] = Math.min(dp[i][1], dp[i-1][1] + p[i-1] + p[i]);
                }                
                if(dp[i-1][1]!=INF && Math.abs(p[i-1]-p[i])*2<=time){
                    dp[i][2] = dp[i-1][1] + Math.abs(p[i-1]-p[i]);
                }
                if(dp[i-1][2]!=INF && Math.abs(p[i-1]-p[i])*3<=time){
                    dp[i][3] = dp[i-1][2] + Math.abs(p[i-1]-p[i]);
                }
                dp[i][0] = Math.min(dp[i][1] ,Math.min(dp[i][2], dp[i][3])) + p[i];
                if(dp[i][1]==INF && dp[i][2]==INF && dp[i][3]==INF){
                    NG = i+1;
                    break;
                }
            }


            if(NG!=-1) System.out.println("NG " + NG);
            else {
                int d1 = INF, d2 = INF, d3 = INF;
                if(dp[n-1][1]!=INF) d1 = dp[n-1][1] + p[n-1];
                if(dp[n-1][2]!=INF) d2 = dp[n-1][2] + p[n-1];
                if(dp[n-1][3]!=INF) d3 = dp[n-1][3] + p[n-1];
                System.out.println("OK " + Math.min(d1 ,Math.min(d2, d3)));
            }
            //System.out.println("OK " + dp[n-1][0]);
        }
    }

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

Measured memory_bytes: 25332
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

bool comp(pair<int, int> a, pair<int, int> b) { return (a.second < b.second); }

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> arr;
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    arr.emplace_back(A, B);
  }

  sort(arr.begin(), arr.end(), comp);

  long current = 0;
  bool yesFlag = true;
  for (auto a = arr.begin(); a != arr.end(); a++) {
    current += a->first;
    if (current > a->second) {
      yesFlag = false;
      break;
    }
  }

  cout << (yesFlag ? "Yes" : "No") << endl;
  return 0;
}

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

int main(){
	int a,b,c;
	cin >> a >> b >>c;
	
	if(a==b && a!=c){
		cout << "Yes" << endl;
	} else if (a == c && a!=b){
		cout << "Yes" << endl;
	} else if (b==c&&b!=a){
		cout << "Yes" << endl;
	} else{
		cout <<"No" << endl;
	}
	
    return 0;
}



Measured memory_bytes: 256