akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

struct UnionFind{

    vector<ll> par;
    UnionFind(ll n) : par(n, -1){}
    

    int root(int x){
        if(par[x]<0) return x;
        return par[x] = root(par[x]);
    }

    bool same(int a, int b){
        return root(a)==root(b);
    }
    void unite(int a, int b){
        int x=root(a), y=root(b);
        if(same(x, y)) return;
        if(y<x) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
    int size(int x){
        return -par[root(x)];
    }

};

int main(){
    ll n, m;   cin >> n >> m;
    UnionFind tree = UnionFind(n);
    vector<ll> z(m);
    rep(i, m){
        ll a, b;    cin >> a >> b >> z[i];
        a--, b--;
        tree.unite(a, b);
    }
    set<ll> st;
    rep(i, n){
        st.insert(tree.root(i));
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 9448
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;


enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
template <class T>
class dice {
public:
  int id[6];
  dice() {}
  dice(T *v) {
    id[TOP] = 2; id[FRONT] = 0; id[LEFT] = 4;
    id[RIGHT] = 1; id[BACK] = 5; id[BOTTOM] = 3;
    REP(i,6)
      var[i] = v[i];
  }
  T& operator[] (int f) { return var[id[f]]; }
  const T& operator[] (int f) const { return var[id[f]]; }
  void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
  void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
  void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }
  vector<dice> all_rolls() {
    vector<dice> ret;
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        ret.push_back(*this);
    return ret;
  }
private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    int tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  T var[6];
};

int n;
vector<dice<int> > vd[4];
dice<int> nowd[4];

int solve(int now) {
  if (now == n) {
    int res = 0;
    REP(i, 6) {
      int table[24] = {};
      REP(j, n) {
        table[nowd[j][i]]++;
      }
      res += n - *max_element(table, table+24);
    }
    // REP(i, n) {
    //   REP(j, 6)
    //     cout << nowd[i].var[j] << " ";
    //   cout << endl;
    // }
    // cout << res << endl;
    return res;
  }
  int res = INF;
  FOR(it, vd[now]) {
    nowd[now] = *it;
    res = min(res, solve(now+1));
  }
  return res;
}


int main() {
  while(cin>>n,n) {
    dice<int> di[n];
    map<string, int> mp;
    int num = 0;
    REP(i, n) {
      int a[6];
      REP(j, 6) {
        string s;
        cin >> s;
        int id;
        if (mp.count(s))
          id = mp[s];
        else
          id = mp[s] = num++;
        a[j] = id;
      }
      di[i] = dice<int>(a);
    }
    REP(i, n)
      vd[i] = di[i].all_rolls();

    if (n == 1) {
      cout << 0 << endl;
      continue;
    }
    cout << solve(0) << endl;
      
  }
}

Measured memory_bytes: 940
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    long double ans = 0;
    for (int i = 0; i < n; ++i) {
        long double k;
        cin >> k;
        string s;
        cin >> s;
        if(s == "BTC") k *= 380000;
        ans += k;
    }
    cout << setprecision(15) << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        int n = scan.nextInt();
        double count = 0.0;
        for(int i = 0; i < n; i++){
            int tmp = Integer.parseInt(scan.next());
            if(tmp % 4 == 0){
                count += 1.0;
            } else if (tmp % 2 == 0){
                count += 0.5;
            }
        }

        // output
        if((int)count >= n / 2){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

#define pb push_back
#define mp make_pair

#define fi first
#define se second

typedef long long ll;

using namespace std;

  int tt;

int main(){

  cin >> tt;
  while(tt--) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if(b > a) {
      cout << "No\n";
      continue;
    }
    if(b > d) {
      cout << "No\n";
      continue;
    }
    if(c >= b){
      cout << "Yes\n";
      continue;
    }
    ll g = __gcd(b, d);
    if(b - g + a % g > c) {
      cout << "No\n";
    }
    else{
      cout << "Yes\n";
    }
  }

return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
s = []
n.times do
  s.push gets.chomp.split('')
end
haz = ('a'..'z').to_a.map { |e| [e,50] }.to_h
def comhash(a, b)
  h = {}
  a.each do |k, v|
    h[k] = [v, b[k]].min if b[k]
  end
  h
end
n.times do |i|
  h = Hash.new(0)
  s[i].each do |c|
    h[c] += 1
  end
  #a[i] = s[i].reduce(Hash.new(0)) { |h, c| h[c] += 1 }
  haz = comhash(h, haz)
end
puts haz.sort_by { |e| e.first }.map { |e| e.first * e.last }.join


Measured memory_bytes: 2044
#129c
import sys
sys.setrecursionlimit(1000000)

N,M = map(int, input().split())

now_step = 0
ans = 1
calculated_jump = {}
mod_number = 1000000007 

#開いている段数の移動パターンを算出する関数
def jump(now_step):
    
    if now_step in calculated_jump:
        return calculated_jump[now_step]
    else:
        if now_step == 2:
            return 2
        elif now_step == 1:
            return 1
        else:
            if now_step not in calculated_jump:
                calculated_jump[now_step] = jump(now_step-1) + jump(now_step-2)
                return jump(now_step-1) + jump(now_step-2)

for _ in range(M):
    a = int(input())
    
    if a == now_step:
        print("0")
        break
    elif a - 1 - now_step != 0: #左記成立時は1通りしかない。
        target_step_count = a - 1 - now_step #aは踏んではいけない段なので、その前がターゲット
        ans = ans * jump(target_step_count) % mod_number
            
    now_step = a + 1

else:
    if now_step != N:
        target_step_count = N - now_step
        ans = ans * jump(target_step_count) % mod_number
    
    print(ans)

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

int main() {
    
    // 1. 入力情報取得.
    int M, D;
    scanf("%d %d", &M, &D);
    
    // 2. 高橋暦を探索.
    int ans = 0;
    for(int m = 1; m <= M; m++){
        for(int d = 10; d <= D; d++){
            // d1, d10, m を 評価.
            int d1  = d % 10;
            int d10 = d / 10;
            if(d1 >= 2 && d10 >= 2 && d1 * d10 == m) ans++;
        }
    }
    
    // 3. 出力 ～ 後処理.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
int main(void){
	int N;
	const long long int Div=1000000007;
	long long int T[100000],A[100000];
	bool Ansflag=true;
	long long int ans=1;
	bool Tflag[100000],Aflag[100000];//trueなら値確定,flaseなら不等式
	long long int min=0;


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


	for(int i=0;i<N;i++){
		if(i==0){
			Tflag[i]=true;
		}else {
			if(T[i-1]==T[i]){
				Tflag[i]=false;
			}else {
				Tflag[i]=true;
			}
		}
	}
	for(int i=N-1;i>=0;i--){
		if(i==N-1){
			Aflag[i]=true;
		}else {
			if(A[i+1]==A[i]){
				Aflag[i]=false;
			}else {
				Aflag[i]=true;
			}
		}
	}
	for(int i=0;i<N;i++){
		if(Tflag[i] && Aflag[i]){
			if(T[i]!=A[i]){
				Ansflag=false;
			}
		}else if(Tflag[i] && !Aflag[i]){
			if(T[i]>A[i]){
				Ansflag=false;
			}
		}else if(!Tflag[i] && Aflag[i]){
			if(T[i]<A[i]){
				Ansflag=false;
			}
		}else {
			ans*=std::min(A[i],T[i]);
			ans%=Div;
		}
	}
	if(Ansflag){
		std::cout<<ans<<std::endl;
	}else {
		std::cout<<'0'<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 2048
from collections import deque
def main():
    h, w = map(int, input().split())
    A = [list(input()) for _ in range(h)]
    B = [(i, j) for i, a in enumerate(A) for j, b in enumerate(a) if b == '#']
    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    stack = deque(B)
    colored = len(B)
    tot = h * w
    count = 0
    while colored < tot:
        next = deque([])
        while stack:
            y, x = stack.popleft()
            for dx, dy in dxy:
                X = x + dx
                Y = y + dy
                if X < 0 or X >= w or Y < 0 or Y >= h:
                    continue
                if A[Y][X] == '.':
                    next.append((Y, X))
                    A[Y][X] = '#'
        stack = next
        count += 1
        colored += len(next)
    print(count)

if __name__ == '__main__':
    main()


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

int main() {
  int N, count = 0;
  cin >> N;
  
  int org[N];
  for (int i=0; i < N; i++) {
    int a;
    cin >> a;
    
    org[i] = a;
  }

  for (;;) {
    int c = 0;
    for (int i=0; i < N; i++) {
      if (org[i] % 2 == 0) {
        c += 1;
        org[i] = org[i]/2;
      }
    }
    if (c != N) {
      break;
    } else {
      count += 1;
    }
  }
  cout << count;
}


Measured memory_bytes: 3588
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    bool dp[110];
    int mab = max(a, b);
    rep1(i, mab) {
        if (a % i == 0 && b % i == 0) {
            dp[i] = true;
        } else {
            dp[i] = false;
        }
    }
    int cnt = 0;
    rrep1(i, mab) {
        if (dp[i]) {
            cnt++;
            if (cnt == k) {
                cout << i << endl;
                return 0;
            }
        }
    }

    /* ====================================== */
    cout << endl;
    return 0;
}

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


int main(){
  int N , M ; 
  cin >> N >> M ; 
  vector<int> d1(N+1) , d2(N+1);
  for(int i = 0 ; i < M ; i++){
    int a , b ; 
    cin >> a >> b ; 
    if(a == 1) d1.at(b)++ ; 
    if(b == N) d2.at(a)++ ; 
  }
  int cnt = 0 ; 
  for( int i = 0 ; i <= N ; i++){
        cnt++ ; 
    if(d1.at(i) == 0 ) continue ; 

    //cout << cnt << endl ; 
      if( d2.at(i) == 1 ){
        cout << "POSSIBLE" << endl ; 
        return 0 ; 
      } 
    }
  
  
  cout << "IMPOSSIBLE" << endl ; 
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);

static const int N = 100;
static const int INF = (1<<21);

int d[N]; //距離で訪問状態を管理する
int n, M[N][N];

void bfs(int s){
  queue<int> q;
  q.push(s);

  REP(i,n) d[i] = INF;

  d[s] = 0;
  int u;
  while(!q.empty()){
    u = q.front(); q.pop();
    REP(v,n){
      //つながっていなかったら，飛ばす
      if(M[u][v] == 0) continue;
      //既に訪れていたら，飛ばす
      if(d[v] != INF) continue;

      d[v] = d[u] + 1;
      q.push(v);
    }
  }

  REP(i,n){
    cout << i + 1 << " " << ((d[i] == INF) ? (-1) : d[i] ) << endl;
  }




}
int main(){
  int u, k, v;
  cin >> n;
  REP(i,n){
    REP(j,n) M[i][j] = 0;
  }

  REP(i,n){
    cin >> u >> k;
    --u;
    REP(i,k){
      cin >> v;
      --v;
      M[u][v] = 1;
    }
  }

  bfs(0);
  return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n, r;
	cin >> n >> r;
	if(n >= 10) cout << r << endl;
	else cout << r + (10 - n) * 100 << endl;
	
}





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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector <int> a(n);
  for (int i = 0;i < n; ++i){
	cin >> a[i];
  }
  sort(a.begin(),a.end());
  bool b = true;
  for (int i = 1; i < n; ++i){
	if(a[i] == a[i-1]){
		b = false;
		break;
	}	
  }
  (b) ? cout << "YES\n" : cout << "NO\n";
return 0;
}


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

int main() {

    string s;
  	cin >> s;
    int cnt = 0; 
 
	for (int i = 0; i < s.size(); i++){
      if(s[i] == '1'){
      	cnt++;  
      }
    }
  	cout << cnt << endl;
  	return 0;

}


Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}


signed main() {
  ios::sync_with_stdio(false);
  string t;
  cin >> t;
  ll n = t.size();
  vector<vector<ll>> dp(n+1, vector<ll>(4));
  ll ans = 0;
  dp[0][0] = 1;
  REP(i, n) {
    if(t[i] == '?') {
      REP(j, 4) {
        dp[i+1][j] = 3 * dp[i][j];
      }
      REP(j, 3) {
        dp[i+1][j+1] += dp[i][j];
      }
    }
    else {
      REP(j, 4) {
        dp[i+1][j] = dp[i][j];
      }
      int j = t[i] - 'A';
      dp[i+1][j+1] += dp[i][j];
    }
    REP(j, 4) dp[i+1][j] %= mod;
  }
  cout << dp[n][3] << endl;
  return 0;
}


Measured memory_bytes: 7376
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      a: [usize; n],
      q: usize,
      bc: [(Usize1, Usize1); q]
   }

   let mut sum = 0;
   let mut m = vec![0usize; 100000];
   for &a in a.iter() {
      sum += a;
      m[a - 1] += 1;
   }

   for &(b, c) in bc.iter() {
      let num = m[b];
      if b > c {
         sum -= (b-c) * num;
      } else {
         sum += (c-b) * num;
      }
      m[b] = 0;
      m[c] += num;
      println!("{}", sum);
   }
}


Measured memory_bytes: 6828
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct air{int X,Y;air() {};air (int a, int b) {X=a,Y=b;}};bool operator <(air a, air b) {if (a.X!=b.X) return a.X<b.X; return a.Y<b.Y;}
air RB[405];int N;bool used[405];int Mahou[405];bool degree(int a, int b, int c) {int S=RB[a].X*RB[b].Y+RB[b].X*RB[c].Y+RB[c].X*RB[a].Y-RB[a].Y*RB[b].X-RB[b].Y*RB[c].X-RB[c].Y*RB[a].X;return (S>0);}
int main() {
    int i,j,k;while (1) {scanf("%d",&N);if (!N) return 0;for (i=0;i<N;i++) {scanf("%d %d",&j,&k);RB[i]=air(j,k);used[i]=1;}N++;RB[i]=air(0,0);sort(RB,RB+N);Mahou[0]=0,Mahou[1]=1,used[N-1]=1,used[0]=0,used[1]=0;
        for (i=2,j=1,k=2;k<N;i+=j) {if (i==N) i=N-1,j=-1; else if (!i) j=1;if (!used[i]) continue;while (degree(Mahou[k-2],Mahou[k-1],i)) used[Mahou[--k]]=1;Mahou[k++]=i,used[i]=0;}
		double ans=0.00;for (i=1;i<N;i++) ans+=sqrt((RB[Mahou[i]].X-RB[Mahou[i-1]].X)*(RB[Mahou[i]].X-RB[Mahou[i-1]].X)+(RB[Mahou[i]].Y-RB[Mahou[i-1]].Y)*(RB[Mahou[i]].Y-RB[Mahou[i-1]].Y));printf("%.1lf\n",ans);}}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int X, T;
	cin >> X >> T;
	cout << max(0, X - T) << endl;
}

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 205;

int N;
vector<int> graph[MX];
ll ans = -INF;

bool valid;
ll groups;
int sets[MX];

void color(int start) {
	valid = true;
	groups = 1;
	for (int j = 0; j < N; j++) sets[j] = -1;
	
	queue<int> q;
	q.push(start);
	sets[start] = 1;
	
	while (!q.empty() && valid) {
		int v = q.front();
		q.pop();
		
		for (auto u : graph[v]) {
			// cout << v << " " << u << "\n";
			if (sets[u] == -1) {
				sets[u] = sets[v] + 1;
				chmax(groups, (ll)sets[u]);
				q.push(u);
			} else {
				if (sets[v] - sets[u] > 1 || sets[u] == sets[v]) {
					valid = false;
					break;
				}
			}
		}
	}
}

void solve() {
    cin >> N;
    for (int i = 0; i < N; i++) {
		string S;
		cin >> S;
		for (int j = 0; j < N; j++) {
			if (S[j] == '1') graph[i].push_back(j);
		}
	}
	
	for (int i = 0; i < N; i++) {
		color(i);
		
		if (valid) {
			chmax(ans, groups);
		}
	}
	
	ans == -INF ? cout << -1 : cout << ans;
	
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 512
#include<stdio.h>

int main(void){
    int A,B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    while(1){
        C=C-B;
        if(C<=0){
            printf("Yes\n");
            break;
        }
        A=A-D;
        if(A<=0){
            printf("No\n");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1648
n = int(input())
s = [input() for _ in range(n)]

ac = s.count('AC')
wa = s.count('WA')
tle = s.count('TLE')
re = s.count('RE')

print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re)

Measured memory_bytes: 16272
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    int p,q,r;
    cin>>p>>q>>r;
    int k=p+q;
    int l=q+r;
    int m=p+r;
    cout<<min(k,min(l,m))<<endl;

}












































Measured memory_bytes: 3544
#include <iostream>
#include <string>

int main()
{
    int N;
    std::string S;

    std::cin >> N;
    std::cin >> S;

    // 奇数ならNo
    if (S.size() % 2 == 1)
    {
        std::cout << "No" << std::endl;
        return 0;
    }

    // 偶数なら判定
    bool flag = true;
    for (int i = 0; i < S.size() / 2; i++)
    {
        if (S[i] != S[i+S.size()/2])
        {
            flag = false;
        }
    }

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


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    int m, n=0;
    for(int i=0;i<A.length;i++){
      A[i] = sc.nextInt();
    }
    for(int i=N;i>=2;i--){
      for(int j=0;j<i-1;j++){
        if(A[j]>A[j+1]){
          m = A[j];
          A[j] = A[j+1];
          A[j+1] = m;
          n++;
        }
      }
    }
    for(int i=0;i<N;i++){
      if(i<N-1){
        System.out.print(A[i] + " ");
      }else{
        System.out.print(A[i]);
      }
    }
    System.out.println();
    System.out.println(n);
  }
}


Measured memory_bytes: 26436
import java.util.*;
import java.lang.Integer;

class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int X = sc.nextInt();
      int A = sc.nextInt();
     
      if(X < A){
        System.out.println(0);
      }
      else {
        System.out.println(10);
      }
    }
}


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


int main()
{
    int N, W;
    cin >> N >> W;
    vector<long> w(N+1), v(N+1);
    for( int i = 1; i <= N; ++i ) cin >> w[i] >> v[i];
    
    // dp[i][j]: i 番目までの品物から重さの和が j 以下になるように
    //           選んだときの価値の最大値
    long dp[101][100001];
    for( int j = 0; j <= W; ++j ) dp[0][j] = 0;
    for( int i = 1; i <= N; ++i ){
        for( int j = 0; j <= W; ++j ){
            if( j >= w[i] ) dp[i][j] = max( dp[i-1][j], dp[i-1][j-w[i]] + v[i] );
            else            dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 79232
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, x;
    cin >> n >> x;
    int sum = 0;
    int ans = 0;
    rep(i, n) {
        int a;
        cin >> a;
        sum += a;
        if (sum <= x) {
            ++ans;
        }
    }
    cout << ans+1 << endl;
    return 0;
}


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

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

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

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

  int occupied_seat = 0;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;

    occupied_seat += r - l + 1;
  }

  cout << occupied_seat << endl;
}

Measured memory_bytes: 256
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const gcd = (m,n) => n!=0 ? gcd(n, m%n) : m
const Main = () => {
    const [N, X] = nextIntArray()
    let x = nextIntArray()
    for(let i = 0; i<x.length; i++){
        x[i] = x[i] - X
    }
    let ans = x[0]
    for(let el of x){
        ans = gcd(ans, el)
    }
    console.log(Math.abs(ans))
}
Main()



Measured memory_bytes: 42868
import sys
sys.setrecursionlimit(10**6)

s=input()
t=input()

for i in range(len(s)):
    u=""
    for j in range(len(s)):
        u+=s[j-i]
#    print(u)
    if(u==t):
        print("Yes")
        exit()
    
print("No")

#print(s[0])
#print(t[0])




Measured memory_bytes: 2940
#include<cmath>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#define INF 1e16
#define N (1000000000+7)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
 


bool overflow(ll a, ll b) {

	ll prod = a * b;
	
	return (prod / b != a);
}

int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    if(a[0]==0){
        cout<<0<<endl;
        return 0;
    }
    if(n>=2 && a[0]>1000000000){
        cout<<-1<<endl;
        return 0;
    }
    ll ans = 1;
    for(ll i=0;i<n;i++){
        if(overflow(ans,a[i])){
            cout<<-1<<endl;
            return 0;
        }
        ans = ans*a[i];
    }
    if(ans > 1000000000000000000)cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4060
N = int(input())
A = list(map(int, input().split()))

l = []
flag = False
for i in range(N-1):
  if flag:
    if A[i] > A[i+1]:
      l.append(A[i])
      flag = False
  else:
    if A[i] < A[i+1]:
      l.append(A[i])
      flag = True
if flag:
  l.append(A[-1])

flag = False
ans = 1000
stock = 0
for n in l:
  if flag:
    ans += stock * n
    stock = 0
    flag = False
  else:
    stock = ans // n
    ans -= stock * n
    flag = True
print(ans)

Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n)cin >> p[i];
    int left=0;
    int res = 0;
    for(left=0;left<n-2;left++){
        if(p[left]<p[left+1]&&p[left+1]<p[left+2])res++;
        else if(p[left]>p[left+1]&&p[left+1]>p[left+2])res++;
    }
    cout << res << endl;
    return 0;
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int ggcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n;
  cin>>n;
  vector<int> v(n),w(n);
  rep(i,n) cin>>v[i];
  w[0]=0;
  w[1]=abs(v[1]-v[0]);
  for(int i=1;i<n;i++){
    w[i+1]=min(w[i]+abs(v[i+1]-v[i]),w[i-1]+abs(v[i+1]-v[i-1]));
  }
  cout<<w[n-1]<<endl;

}
///////////////////////////

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

// ABCテンプレート

#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  string ans="No";
  for(int i=0; i<K; i++) {
    if(A<B && B<C) {
      ans="Yes";
      break;
    }
    else if(C<=A) C = C*2;
    else if(C<=B) C = C*2;
    else if(B<=A) B = B*2;
  }
  if(A<B && B<C) ans="Yes";
  cout << ans << endl;
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << 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...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
char s[N];

int main() {
  int n, A, B;
  scanf("%d%d%d", &n, &A, &B);
  scanf("%s", s);
  int cntAB = 0, cntB = 0;
  for (int i = 0; i < n; ++i) {
    // trace(i, cntAB, cntB);
    if (s[i] == 'a') {
      if (cntAB < A + B) {
        puts("Yes");
        ++cntAB;
      } else {
        puts("No");
      }
    } else if (s[i] == 'b') {
      if (cntAB < A + B && cntB < B) {
        puts("Yes");
        ++cntB;
        ++cntAB;
      } else {
        puts("No");
      }
    } else {
      puts("No");
    }
  }
  return 0;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  int s, w; cin >> s >> w;
  cout << (s <= w ? "unsafe" : "safe");
  return 0;
}

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

using i64 = int64_t;

void solve(i64 n, map<i64, i64> &mp){
    i64 m = n;
    for(i64 i=2;i*i<=n;++i){
        if(n % i == 0)mp[i] += m;
        while(n % i == 0){
            n /= i;
        }
    }
    if(n != 1)mp[n] += m;
}

int main(){
    i64 n;
    cin >> n;
    vector<i64> v;
    for(i64 i=0;i<n;++i){
        i64 a;
        cin >> a;
        if(a == 1)continue;
        v.push_back(a);
    }

    map<i64, i64> mp;
    for(auto e: v){
        solve(e, mp);
    }
    i64 ans = 0;
    for(auto e: mp){
        ans = max(ans, e.second);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll a[n],b[n];
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    for(int i = n - 1; i >= 0; i--){
        a[i] += ans;
        if(a[i] % b[i] != 0){
            ans += b[i] * (a[i] / b[i] + 1) - a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys
from math import ceil

def solve(N: int):
    if N == 0:
        print(0)
        return 

    answer = ""
    while N != 0:
        syou = ceil(N/-2) 
        amari = N-syou*-2

        answer+= str(amari)
        N = syou
    
    print(answer[::-1])

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    for _ in range(M):
        B, C = map(int, input().split())
        d[C] += B

    ans = 0
    total_freq = 0
    for v, freq in sorted(d.items(), reverse=True):
        if total_freq + freq <= N:
            ans += v * freq
            total_freq += freq
        else:
            ans += v * (N - total_freq)
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 105872
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    string S;
    cin >> S;

    for (int bits = 0; bits < (0x1 << 3); bits++) {
        int sum = S[0] - '0';
        for (int i = 0; i < 3; i++) {
            int n = S[i + 1] - '0';
            if (bits & (0x1 << i)) {
                sum += n;
            } else {
                sum -= n;
            }
        }

        if (sum == 7) {
            cout << S[0];
            for (int i = 0; i < 3; i++) {
                if (bits & (0x1 << i)) {
                    cout << '+';
                } else {
                    cout << '-';
                }
                cout << S[i + 1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 888
import java.util.*;
import java.io.*;
class Main {
    static long mod = (long) Math.pow(10, 9) + 7;
    static Scanner S = new Scanner(System.in);
    public static long solve(int h[] , int n) {
        long dp[] = new long[n];
        for(int i = 0; i < n; i++) {
            if(i == 0)
                dp[i] = 0;
            else if(i == 1)
                dp[i] = Math.abs(h[i] - h[i - 1]);
            else
                dp[i] = Math.min(dp[i - 1] + Math.abs(h[i] - h[i - 1]) , dp[i - 2] + Math.abs(h[i] - h[i - 2]));
        }
        return dp[n - 1];
    }
    public static void main(String[] args) {
        //FastScanner f = new FastScanner(System.in);
        int n = S.nextInt();
        int h[] = new int[n];
        for(int i = 0; i < n; i++) {
            h[i] = S.nextInt();
        }
        pn(solve(h , n));
        
    }
/******************************END OF MAIN PROGRAM*******************************************/
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        FastScanner(InputStream stream) {
            try {
                br = new BufferedReader(new
                    InputStreamReader(stream));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
        	return Long.parseLong(next());
        }
        double nextDouble() {
        	return Double.parseDouble(next());
        }
    }


    // Print in console
    static void pn(Object o){System.out.println(o);}
    static void p(Object o){System.out.print(o);}
    static void pni(Object o){System.out.println(o);System.out.flush();}
    
    
    //GCD of two integers
    int gcd(int a, int b) {
        if(b == 0) return a;
        else {
            return gcd(b, a % b);
        }
    }

    // GCD of a array of integers
    int gcdarray(int a[]) {
        int res = a[0];
        for(int i = 1; i < a.length; i++) {
            res = gcd(a[i] , res);
        }
        return res;
    }

    // Is Prime no.?
    boolean isPrime(int n) {
        if(n == 1) return false;
        int i = 2;
        while((i * i) <= n) {
            if(n % i == 0) return false;
            i += 1;
        }
        return true;
    }   
}

Measured memory_bytes: 50972
// Create your own template by modifying this file!
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <deque>
#include <stack>
#include <functional>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x;  }
void _R(int &x) { scanf("%d", &x);  }
void _R(int64_t &x) { scanf("%lld", &x);  }
void _R(double &x) { scanf("%lf", &x);  }
void _R(char &x) { scanf(" %c", &x);  }
void _R(char *x) { scanf("%s", x);  }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...);  }
template<class T> void _W(const T &x) { cout << x;  }
void _W(const int &x) { printf("%d", x);  }
void _W(const int64_t &x) { printf("%lld", x);  }
void _W(const double &x) { printf("%.16f", x);  }
void _W(const char &x) { putchar(x);  }
void _W(const char *x) { printf("%s", x);  }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' ');  }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);  }
#ifdef DEBUG
 #define debug(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define debug(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;

void solve() {
    LL X, K, D;
    R(X, K, D);

    LL ans = min(abs(X + K * D), abs(X - K * D));
    auto check = [X, K, D, &ans](LL x) {
        assert((x - X) % D == 0);
        LL k = abs(X - x) / D;
        if (k <= K && (k - K) % 2 == 0) {
            ans = min(ans, abs(x));
        }
    };

    check(X % D);
    check(X % D - D);
    check(X % D + D);

    W(ans);
}

int main() {
#define MULTITEST 0
#if MULTITEST    
    CASET{
        solve();
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 3180
#include<iostream>

using namespace std;
int board[128][128];
bool memo[128][128];
int w, h;

void judge(int x, int y, int c){
  if(x<0 || y<0 || x>=w || y>=h)return;
  if(board[y][x]!=c)return;
  if(memo[y][x])return;
  memo[y][x] = 1;
  judge(x-1, y, c);
  judge(x+1, y, c);
  judge(x, y-1, c);
  judge(x, y+1, c);
  return;
}

int main(){
  int xs, ys, xg, yg, n, i, j, k, c, d, x, y;
  while(cin>> w >> h, w+h){
    for(i=0; i<128; i++){
      for(j=0; j<128; j++){
        board[i][j] = 0;
        memo[i][j] = 0;
      }
    }
    cin >> xs >> ys;
    cin >> xg >> yg;
    cin >> n;
    for(i=0; i<n; i++){
      cin >> c >> d >> x >> y;
      if(d==0){
        for(j=y-1; j<y+1; j++){
          for(k=x-1; k<x+3; k++){
            board[j][k] = c;
          }
        }
      }else{
        for(j=y-1; j<y+3; j++){
          for(k=x-1; k<x+1; k++){
            board[j][k] = c;
          }
        }
      }
    }
    judge(xs-1, ys-1, board[ys-1][xs-1]);
    if(memo[yg-1][xg-1]==1){
      cout << "OK" << endl;
    }else{
      cout << "NG" << endl;
    }
  }
}

Measured memory_bytes: 3076
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

X = ii()

tmp = X // 100
step = 0

for i in range(4, 20, 2):
    if i <= tmp < i+2:
        print(8-step)
        exit()
    step += 1

Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c0=0,c1=0;
  vector<int> a;
  cin>>n;
  for(int i=0,b;i<n;i++){
    cin>>b;
    if(b==0)c0++;
    else if(b==1)c1++;
    else a.push_back(b);
  }
  sort(a.begin(),a.end());
  int f=0;
  if(c0%2==1&&c1==0&&a.size()){
    a.push_back(a[0]);
    a.erase(a.begin());
    f=1;
    c0--;
  }
  if(a.size()-f>=2&&a[a.size()-f-1]==3&&a[a.size()-f-2]==2)swap(a[a.size()-f-1],a[a.size()-f-2]);
  for(int i=0;i<(int)a.size()-f;i++){
    cout<<a[i]<<endl;
  }
  if(c0%2==1&&c1){
    f=2;
    c0--,c1--;
  }


 
  for(int i=0;i<c0;i++)cout<<0<<endl;
  if(f==1)cout<<a[a.size()-1]<<endl<<0<<endl;
  if(f==2)cout<<1<<endl<<0<<endl;
  for(int i=0;i<c1;i++)cout<<1<<endl;
  return 0;
}

Measured memory_bytes: 3164
#include <stdio.h>
#include <string.h>

int main() {
    char S[1005];
    scanf("%s",S);
    int len, i ;
    i=0;
    len = strlen(S);
    char T[len+1];
    while(1){
        if(i == len-1){
            if(S[i] == 's'){
                T[i] = S[i];
                T[i+1] = 'e';
                T[i+2] = 's';
                T[i+3] = '\0';
                break;
            } else {
                T[i] = S[i];
                T[i+1] = 's';
                T[i+2] = '\0';
                break;
            }
        }
        T[i] = S[i];
        i++;
    }

    printf("%s",T);
    return 0;
}

Measured memory_bytes: 1700
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> A(N), B(N);
  for(int i=0;i<N;++i) cin>>A[i]>>B[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if(N%2==0) {
    cout<<(B[N/2-1]+B[N/2])-(A[N/2-1]+A[N/2])+1<<endl;
  }
  else {
    cout<<B[N/2]-A[N/2]+1<<endl;
  }
}



Measured memory_bytes: 6396