akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

int main() {
  int a, b, c, x;

  cin >> a >> b >> c >> x;

  int ans = 0;

  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      for (int k = 0; k <= c; ++k) {
        if (500 * i + 100 * j + 50 * k == x) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 int main(){

       int a,b,k;
       cin>>a>>b>>k;

for(int i=a;i<=min(b,a+k-1);i++)
	cout<<i<<'\n';
for(int i=max(b-k+1,a+k);i<=b;i++)
	cout<<i<<"\n";



 	return 0;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){int k=0,a,b,c;
           cin>>a>>b>>c;
           map<int,int>mp;
           mp[a]++;mp[b]++;mp[c]++;
           if(mp[a]==2||mp[b]==2||mp[c]==2){k++;}
           if(!k){cout<<"No";}
             else{cout<<"Yes";}
  return 0;}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                               \
  cerr << #v << ": ";                              \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", "; \
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()

int c[10][1005];

int main() {
  //要するにホワイトチョコレートの切り分け
  //たとえホワイト同士が離れていようと分断すれば別ブロック
  //グリッドの直線通りにしか折れない
  //状態数 2^((10-1)*(1000-1))通り
  // 全部割ったら 9*999
  int H, W, K;
  cin >> H >> W >> K;

  vector<string> S(H);
  REP(i, H) { cin >> S[i]; }
  int ans = (H - 1) * (W - 1);
  for (int div = 0; div < (1 << (H - 1)); ++div) {  // 2^h-1乗通りの切り方
    int g = 0;
    vi id(H);  //それぞれの列がどのグループに属するのか
    REP(i, H) {
      id[i] = g;
      if (div >> i & 1)
        ++g;  // shiftしてから&1をとればオーバーフローしずらいし結果が１か０になる
    }
    ++g;  //３回きればグループ数は４つ

    REP(i, g) {
      REP(j, W) c[i][j] = 0;  //初期化 0初期化はされてるけどループするので
    }
    REP(i, H) { REP(j, W) c[id[i]][j] += S[i][j] - '0'; }
    bool ok = true;
    REP(i, g)
    REP(j, W)
    if (c[i][j] > K) ok = false;  //ある1列でホワイトチョコがK個を超える
    if (!ok) continue;

    int local_ans = g - 1;
    vi now(g);  //各グループで合計何個のチョコがあるか

    auto add = [&](int j) {  // j列目のチョコを考えた時K個内で収まっているか
      REP(i, g) now[i] += c[i][j];  //その縦列でのグループごとに集計を行う
      REP(i, g) if (now[i] > K) return false;
      return true;
    };

    REP(j, W) {
      if (!add(j)) {  //失敗したらその前の位置で切る
        ++local_ans;
        now = vector<int>(g);  //初期化
        add(j);
      }
    }

    ans = min(ans, local_ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int CtoI(char str) {
  return int(str - '0');
}

int main() {
  string N; cin >> N;
  int A[4];
  rep(i, 4) A[i] = CtoI(N[i]);

  int op[4];
  int d[2] = { -1, 1 };
  int result = 0;
  rep(i, 2) {
    rep(j, 2) {
      rep(k, 2) {
        result = A[0] + A[1]*d[i] + A[2]*d[j] + A[3]*d[k];
        if (result == 7) {
          op[0] = 1, op[1] = i; op[2] = j; op[3] = k;
        };
      }
    }
  }

  int B[4]; rep(i,4) B[i] = A[i]*d[op[i]];
  rep(i,4) {
    if (0 <= B[i] & 0 < i) cout << "+" << B[i];
    else cout << B[i];
  };
  cout << "=7" << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 12 10:38:04 2019
C - Bridge
実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 
300
 点
@author: justwah
use union find
"""

import sys
read = sys.stdin.readline

n, m = map(int, input().split())    # single line use regular input() is faster

l = [list(tuple(map(int, read().split()))) for i in range(m)]   #multiple lines use sys.stdin.readline faster

def root(x): #recursively find root for a node
    if parent[x] < 0: # if at root, return self
        return x
    else:
        parent[x] = root(parent[x])  # while searching rejoint queried node to a common parent for hierarchical tree
        return parent[x]
    
def merge(a, b):
    a = root(a)
    b = root(b)
    if rank[a] < rank[b]: # joint lower rank node to a higher rank one
        parent[a] = b
    else:
        parent[b] = a
        if rank[a] == rank[b]: # rank only change if two same rank node joined
            rank[a] +=1    
    return

score = 0

for i in range(m):
    parent = [-1]*(n+1)
    rank = [0]*(n+1)
    for j, (a, b) in enumerate(l[i:]+l[:i]): #iteraete from different starting point - test different last bridge
        a = root(a)
        b = root(b)
        if a != b:
            merge(a, b)
        else:
            if j == (len(l)-1):
                score += 1 # if the last bridge is redundant, +1

print(m-score)

Measured memory_bytes: 3064
import qualified Data.ByteString.Char8 as B
import qualified Data.Array.IO as A
import Control.Monad
import Data.Maybe

main :: IO ()
main = do
    [h, w] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    cost <- A.newListArray ((0,0),(9,9)) . concat =<< replicateM 10
        (map (fst . fromJust . B.readInt) . B.words <$> B.getLine) :: IO (A.IOUArray (Int,Int) Int)

    square <- concat <$> replicateM h 
        (map (fst . fromJust . B.readInt) . B.words <$> B.getLine) :: IO [Int]

    forM_ [0..9] $ \i -> do
        A.writeArray cost (i,i) 0

    cost' <- warshallFloyd cost

    print . sum =<< forM square (\i -> if i == (-1) then return 0 else do
        c <- A.readArray cost' (i, 1)
        return c)

warshallFloyd :: A.IOUArray (Int, Int) Int
              -> IO (A.IOUArray (Int, Int) Int)
warshallFloyd arr = do
    forM_ [0..9] $ \k -> forM_ [0..9] $ \j -> forM_ [0..9] $ \i -> do
        ij <- A.readArray arr (i,j)     
        ik <- A.readArray arr (i,k)     
        kj <- A.readArray arr (k,j)     
        A.writeArray arr (i,j) $ min ij (ik+kj)
    return arr

Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
2^18=262144
価値の高いものから選んでいくか
L=20

20 20
15 11
14 9
とかで失敗する

1
23
4567
89012345
2^18=2^9^2=512*512
DP２つ用意すればいける?
512まで先に用意しとく?
2^9
5000*100000とか
限界？
256くらいなら
2000*100000くらい
しといて
１発で出せるようにするとか

0 -1 -1 2 -1 -1
0  0  0 2  2  2
mapだとTLE
普通の配列に１０００個くらいいれる場合
bit全探索？
*/
vector<ll> V(263000,0),W(263000,0);
vector<vector<ll>> DP(520,vector<ll>(100010,0));
ll N;

void dfs(ll v){
  for(ll i=0; i<=100000; i++){
    DP[v][i]=DP[v/2][i];
    if(i-W[v]>=0) DP[v][i]=max(DP[v][i],DP[v/2][i-W[v]]+V[v]);
  }
}

int main(){
  cin>>N;
  for(ll i=1; i<=N; i++)cin>>V[i]>>W[i];
  ll Q; cin>>Q;
  //DP用意(511以下
  ll n=min(511LL,N);
  for(ll i=0; i<=n; i++) DP[i][0]=0;
  for(ll i=1; i<=n; i++) dfs(i);
  for(ll i=0; i<Q; i++){
    ll v,L; cin>>v>>L;
    ll vv=v, ans=0;
    vector<pair<ll,ll>> C(0,{0,0});
    while(vv>511){
      C.emplace_back(W[vv],V[vv]);
      vv/=2;
    }
    ll csz=C.size();
    ll n=1<<csz;
    for(ll j=0; j<n; j++){
      ll sw=0,sv=0,m=j;
      for(ll k=0; k<csz; k++){
        if(m>>k&1){
          sw+=C[k].first;
          sv+=C[k].second;
        }
      }
      if(sw>L) continue;
      ans=max(ans,sv+DP[vv][L-sw]);
    }
    if(v<512) ans=DP[v][L];
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 415688
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int d1[100010], d2[100010];
vector< vector<int> > v(100010, vector<int>(0));

void dfs(int d[], int point, int depth){
  if(d[point] != 0) return;
  d[point] = depth;
  if(depth == 0) d[point] = -1;

  for(int i = 0; i < v[point].size(); i++){
    dfs(d, v[point][i], depth + 1);
  }
}

int main(){
  int n;
  cin >> n;
  
  int a, b;
  for(int i = 0; i < n - 1; i++){
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  dfs(d1, 1, 0);
  dfs(d2, n, 0);

  int feField = 0;
  for(int i = 1; i <= n; i++){
    if(d1[i] <= d2[i]) feField++;
    else feField--;
  }

  if(feField > 0) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;

  return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  for(int i = 0; i < N; i++){
    cin >> card.at(i);
  }
  sort(card.begin(), card.end());
  int x = 0;
  int y = 0;
  int a = N - 1;
  int b = N - 2;
  while(a >= 0){
    x += card.at(a);
    a -= 2;
  }
  while(b >= 0){
    y += card.at(b);
    b -= 2;
  }
  cout << x - y << endl;
}
    
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

struct UnionFind {
  vector<ll> par;

  UnionFind(ll n) : par(n, -1) { }
  void init(ll n) { par.assign(n, -1); }

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

  bool issame(ll x, ll y) {
    return root(x) == root(y);
  }

  bool merge(ll x, ll y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  ll size(ll x) {
    return -par[root(x)];
  }
};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  vector<pair<ll,ll>> X(N),Y(N);
  for(ll i=0;i<N;i++){
    ll x,y;cin>>x>>y;
    X[i]=make_pair(x,i);
    Y[i]=make_pair(y,i);
  }
  map<ll,pair<set<ll>,set<ll>>> mp;
  sort(ALL(X));sort(ALL(Y));

  UnionFind uf(N);

  for(ll i=0;i<N-1;i++){
    if(X[i].first==X[i+1].first){
      uf.merge(X[i].second,X[i+1].second);
    }
    if(Y[i].first==Y[i+1].first){
      uf.merge(Y[i].second,Y[i+1].second);
    }
  }
  for(ll i=0;i<N;i++){
    mp[uf.root(X[i].second)].first.insert(X[i].first);
    mp[uf.root(Y[i].second)].second.insert(Y[i].first);
  }
  ll ans=0ll;
  for(auto e : mp){
    ans+=1ll*e.second.first.size()*e.second.second.size();
  }
  cout<<ans-N<<endl;
}


Measured memory_bytes: 13568
i,k;main(a,b){scanf("%d%d%d",&a,&b,&k);if(k*2-1>b-a){for(i=a;i<=b;i++)printf("%d ",i);}else{for(i=0;i<k;i++)printf("%d ",a+i);for(int i=k-1;i>=0;i--)printf("%d ",b-i);}puts("");}

Measured memory_bytes: 128
#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>
#include <random>
#include <ctime>

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;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> sum(n + 1);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    sum[i + 1] = sum[i] + x;
  }
  int ret = INF;
  for (int i = 1; i < n; ++i) {
    ret = min(ret, abs(sum[i] - (sum[n] - sum[i])));
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
from sys import stdout
from collections import deque
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
dst = [ [] for i in range(n) ]
for i in range(n):
    s = input().strip()
    for j in range(n):
        if s[j]=='1':
            dst[i].append(j)
            dst[j].append(i)

ddprint(dst)

mx = 0
for i in range(n):
    d = [-1]*n
    d[i] = 0
    q = deque([i])
    while len(q)>0:
        x = q.popleft()
        for y in dst[x]:
            if d[y]>=0 and (d[y]-d[x])%2 == 0:
                ddprint("x {} y {} dx {} dy {}".format(x,y,d[x],d[y]))
                print(-1)
                exit()
            if d[y]<0:
                d[y] = d[x]+1
                mx = max(mx,d[y])
                q.append(y)
print(mx+1)


Measured memory_bytes: 42348
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;

ll a[N];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	sort(a,a+n);
	int l=0,r=n-1,w=1; 
	ll ans=1;
	if(k&1) ans=a[r--],k--,w=(ans<0?-1:1);
	while(k){
		ll x=a[l]*a[l+1],y=a[r]*a[r-1];
		if(x*w>y*w) ans=(ans*(x%mod))%mod,l+=2;
		else ans=(ans*(y%mod))%mod,r-=2;
		k-=2;
	}
	printf("%lld\n",(ans%mod+mod)%mod);
	return 0;
}


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

int main(){ 
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for(int i = 0; i < n; i++) cin >> p[i];
  
  sort(p.begin(), p.end());
  int ans = 0;
  for(int i = 0; i < k; i++) ans += p[i];
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
def LI():
    return list(map(int, input().split()))

x, n = LI()
p = LI()

d = dict()
for i in range(n):
    d[p[i]] = 1

i = 0
while True:
    if d.get(x-i, 0) == 0:
        print(x-i)
        break
    elif d.get(x+i, 0) == 0:
        print(x+i)
        break
    i += 1

Measured memory_bytes: 9200
import sys

n, m, l = list(map(int, input().split()))
lines = sys.stdin.readlines()
INF = 10 ** 18

dists = [[INF] * n for _ in range(n)]

for i in range(n):
    dists[i][i] = 0

for line in lines[:m]:
    a, b, c = map(int, line.split())
    a -= 1
    b -= 1
    if c > l:
        continue
    dists[a][b] = c
    dists[b][a] = c

for k in range(n):
    dk = dists[k]
    for i in range(n):
        di = dists[i]
        for j in range(n):
            new_dist = di[k] + dk[j]
            if new_dist > l:
                continue
            if di[j] > new_dist:
                di[j] = new_dist

refuels = [[1 if dist < INF else INF for dist in row] for row in dists]

for k in range(n):
    rk = refuels[k]
    for i in range(n):
        ri = refuels[i]
        for j in range(n):
            new_dist = ri[k] + rk[j]
            if ri[j] > new_dist:
                ri[j] = new_dist

buf = []

for line in lines[m + 1:]:
    s, t = map(int, line.split())
    refuel = refuels[s - 1][t - 1]
    buf.append(-1 if refuel == INF else refuel - 1)

print('\n'.join(map(str, buf)))


Measured memory_bytes: 76636
W,a,b=map(int,raw_input().split())
if (a <= b <= a+W) or (a <= b+W <= a) or (b <= a <= b+W) or (b <= a+W <= b+W) or (a <= b <= b+W <= a+W) or (b <= a <= a+W <= b+W):
  print 0
elif a+W < b:
  print b - (a+W)
else:
  print a - (b+W)


Measured memory_bytes: 2568
parseInt(x) = parse(Int,x)

parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    N, X = readline() |> split |> parseMap
    L = readline() |> split |> parseMap
    d = 0
    count = 1
    for i in 1:N
        d += L[i]
        if d <= X
            count += 1
        end
    end
    println(count)
end

main()

Measured memory_bytes: 111152
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int e;
        int f;
        e = A+B;
        f = C+D;
        if(e>f){
            System.out.println("Left");
        }
        else if(e==f){
            System.out.println("Balanced");
        }
        else{
            System.out.println("Right");
        }

    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

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

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n, m;
  cin >> n >> m;

  vector<std::pair<int, int>> friends_list(m);
  rep(i, m) {
    cin >> friends_list[i].first >> friends_list[i].second;
  }
  UnionFind test(n);
  rep(i, m) test.unite(friends_list[i].first-1, friends_list[i].second-1);

  int ans {};
  map<int, int> mp;
  rep(i, n) {
    ++mp[test.root(i)];
  }
  for (auto it = mp.begin(); it!= mp.end();++it) {
    maxs(ans, it->second);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 13488
# https://atcoder.jp/contests/abc049/tasks/arc065_a
# なんかこの問題知ってる気がする
# 前方向から貪欲にマッチしようとすると,dreamer なのか dream eraser なのかわかりにくい
# しかし後ろ三文字を見ると、eam,mer,ase,serと一意に決定できる。よって逆方向から貪欲にマッチングさせると即座に構成可能か判別できる

S = input()

i = len(S)
while i - 3 > 0:
    tri = S[i - 3:i]
    if tri == 'eam':
        is_ok = S[i - 5:i] == 'dream'
        i -= 5
    elif tri == 'ase':
        is_ok = S[i - 5:i] == 'erase'
        i -= 5
    elif tri == 'mer':
        is_ok = S[i - 7:i] == 'dreamer'
        i -= 7
    elif tri == 'ser':
        is_ok = S[i - 6:i] == 'eraser'
        i -= 6
    else:
        print('NO')
        exit()

    if not is_ok:
        print('NO')
        exit()


print('YES')


Measured memory_bytes: 40432
program main
	implicit none
    character*100000 s
    integer::ans=0
    integer l,r
    read *,s
    l=1
    r=len_trim(s)
    do while(l<r)
    	if(s(l:l)==s(r:r)) then
        	l=l+1
            r=r-1
        else if(s(l:l)=='x') then
        	ans=ans+1
            l=l+1
        else if(s(r:r)=='x') then
        	ans=ans+1
            r=r-1
        else
        	print '(i0)',-1
            stop
        end if
    end do
    print '(i0)',ans
end program main

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

int main()
{
    long long int X, K, D;
    cin >> X;
    cin >> K;
    cin >> D;
    if (X < 0)
    {
        X = -X;
    }
    if (X / D > K)
    {
        cout << X - K * D << endl;
    }
    else if ((K - X / D) % 2 == 0)
    {
        cout << X % D << endl;
    }
    else
    {
        cout << D - X % D << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main()
{	
	int M, K;
	scanf("%d %d", &M, &K);
	if (M == 0) {
		if (K == 0) printf("0 0\n");
		else printf("-1\n");
		fflush(stdout);
		return 0;
	} else if (M == 1) {
		if (K == 0) printf("0 0 1 1\n");
		else printf("-1\n");
		fflush(stdout);
		return 0;
	}
	
	int i, bit[20];
	for (i = 1, bit[0] = 1; i <= M + 2; i++) bit[i] = bit[i-1] << 1;
	if (K >= bit[M]) {
		printf("-1\n");
		fflush(stdout);
		return 0;
	}
	for (i = 0; i < K; i++) printf("%d ", i);
	for (i = K + 1; i < bit[M]; i++) printf("%d ", i);
	printf("%d", K);
	for (i = bit[M] - 1; i >= K + 1; i--) printf(" %d", i);
	for (i = K - 1; i >= 0; i--) printf(" %d", i);
	printf(" %d\n", K);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1940
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, x, y; cin >> n >> x >> y;
    x--; y--;

    vector<ll> g[n];
    rep(i, n - 1){
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    g[x].push_back(y);
    g[y].push_back(x);

    ll ans[n] = {};

    rep(i, n){
        bool is_arrived[n] = {};

        queue<ll> que;
        que.push(i);
        is_arrived[i] = true;

        // printf("\nstart: %d\n", i);

        ll dlist[n] = {};

        while(!que.empty()){
            ll p_now = que.front();
            // printf("p_now: %d\n", p_now);
            que.pop();
            for(auto p_next : g[p_now]){
                if(is_arrived[p_next]) continue;

                // printf("p_next: %d\n", p_next);
                dlist[p_next] = dlist[p_now] + 1;
                que.push(p_next);
                is_arrived[p_next] = true;
            }
        }

        rep(i, n){
            ans[dlist[i]]++;
        }

        // printf("\nanswers\n");
        // rep(i, n){
        //     cout << ans[i] << endl;
        // }
        // printf("\n");
    }

    rep(i, n){
        ans[i] /= 2;
    }

    reps(i, 1, n){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
    int n, d;
    ll ans=0;
    cin >> n;
    vector<int> data(n);
    REP(i, n) cin >> data.at(i);
    REP(i, n-1) {
        d =  data.at(i+1) - data.at(i);
        if(d<0) {
            data.at(i+1) -= d;
            ans -= d;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3940
#include "bits/stdc++.h"
int main()
{
	int n;
	scanf("%d",&n);
	int t=0,x=0,y=0;
	int flag=1;
	for(int i=0;i<n;i++)
	{
		int ti,xi,yi;
		scanf("%d %d %d",&ti,&xi,&yi);
		int rt=ti-t;
		int rx=fabs(xi-x);
		int ry=fabs(yi-y);
		if(rt >= rx+ry &&abs(rt-(rx+ry))%2==0)
		{
			t=ti;
			x=xi;
			y=yi;
			continue;
		}
		flag=0;
		break;
		
	}
	if(flag)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });


void solve(long long A, long long B, long long T){
	ll res = 0;
	if (T<A) {
		cout << 0 << "\n";
		return;
	}
	FOR(i, 1, T+1) {
		if (i%A==0) res += B;
	}
	cout << res << "\n";
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long T;
    scanf("%lld",&T);
    solve(A, B, T);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	vector<int> v;
for(int i=0; i<5; i++)
{
	int x;
	cin >> x;
v.push_back(x);
}
for(int i=0; i<5; i++)
{
	if(v[i]==0)
	{
		cout << i+1 << endl;
		break;
	}
}
return 0;
}

Measured memory_bytes: 3600
import collections
N = int(input())

S = "abcdefghij"
result = []
deq = collections.deque(["a"])

while deq:
    s = deq.popleft()
    if len(s) == N:
        result.append(s)
        continue
    else:
        for i in S[:len(set(s))+1]:
            deq.append(s + i)

print('\n'.join(result))

Measured memory_bytes: 16428
#include<iostream>
#include<vector>
#include<queue>
#include <string.h>
#include <algorithm>

using namespace std;
long long ans=0;

int main(){
  string S;cin>> S;
  long long S_len=S.length();
  for (long long bit=0; bit<(1<<(S_len-1)); ++bit){
    long long end=S_len;
    long long i=S_len-1;
    for (;0<=i;i--){
      if(bit&(1<<i)){
        ans+=stoll(S.substr(i+1,end-i-1));
        end=i+1;
      }
    }
   ans+=stoll(S.substr(0,end));
  }
  cout<< ans << "\n";
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<500000> uf;
ll tot;
priority_queue<pair<ll,pair<int,int>>> P;
int N,Q;
int A[202020],B[202020],C[202020];
ll E[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	FOR(i,N) E[i]=1LL<<60;
	FOR(i,Q) {
		cin>>A[i]>>B[i]>>C[i];
		P.push({-(C[i]+1),{A[i],0}});
		P.push({-(C[i]+2),{B[i],0}});
	}
	
	while(P.size()) {
		auto e=P.top();
		x = e.second.first;
		P.pop();
		if(-e.first<E[x]) {
			E[x]=-e.first;
			P.push({e.first-2,{(x+1)%N,(x+2)%N}});
		}
	}
	FOR(i,N) P.push({-E[i],{i,(i+1)%N}});
	FOR(i,Q) P.push({-C[i],{A[i],B[i]}});
	
	
	while(P.size()) {
		auto e=P.top();
		P.pop();
		if(uf[e.second.first]!=uf[e.second.second]) {
			uf(e.second.first,e.second.second);
			tot += -e.first;
		}
	}
	cout<<tot<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 17516
/*  ex5_3
    L40S38  */
#include<stdio.h>
#define LIMIT 100
int main(void){
    int high,wide,i,j,black_exist_high[LIMIT],black_exist_wide[LIMIT];
    char cells[LIMIT][LIMIT];
    scanf("%d %d",&high,&wide);
    
    for(i=0;i<LIMIT;i++){
        black_exist_high[i]=0;
    }
    for(j=0;j<LIMIT;j++){
        black_exist_wide[j]=0;
    }
    
    for(i=0;i<high;i++){
        for(j=0;j<wide;j++){
            scanf(" %c",&cells[i][j]);
            if(cells[i][j]=='#'){
                black_exist_high[i]=1;
                black_exist_wide[j]=1;
            }
        }
    }
    
    for(i=0;i<high;i++){
        if(black_exist_high[i]==1){
            for(j=0;j<wide;j++){
                if(black_exist_wide[j]==1){
                    printf("%c",cells[i][j]);
                }
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
 class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int s, m, h;
        s = sc.nextInt();

        h = s / 3600;
        m = (s%3600) / 60;
        s = s % 60;

        System.out.println(h +":" + m + ":" + s);
    }
}



Measured memory_bytes: 26332
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int main()
{
  int i,j,k,n,x,y,now;
  _int64 ans1,ans2;
  vector<int> a;
  vector<int> b;
  scanf("%d",&n);
  a.clear();
  b.clear();
  for (i=0;i<n;i++)
  {
    scanf("%d%d",&x,&y);
    a.push_back(x);
    b.push_back(y);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  sort(b.begin(),b.end());
  ans1=0;
  now=0;
  for (i=0;i<n;i++)
  {
    if (a[i]>now)
    {
      ans1+=a[i]-now;
      now=a[i];
    }
    if (b[i]<now)
    {
      ans1+=now-b[i];
      now=b[i];
    }
  }
  ans1+=abs(now);
  ans2=0;
  now=0;
  for (i=0;i<n;i++)
  {
    if (b[i]<now)
    {
      ans2+=now-b[i];
      now=b[i];
    }
    if (a[i]>now)
    {
      ans2+=a[i]-now;
      now=a[i];
    }
  }
  ans2+=abs(now);
  if (ans1>ans2) printf("%lld\n",ans1);
  else printf("%lld\n",ans2);
  return 0;
}

Measured memory_bytes: 1276
#include<iostream>

using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  int A[N];
  for(int i=0;i<N;i++)
    	cin >> A[i];
  int sum = 0;
   for(int i=0;i<N;i++)
    	sum += A[i];
  
  float limit = sum/(4.0*M);
  int cnt=0;
  for(int i=0;i<N;i++){
    if(limit <=A[i]){
      cnt++;
    }
  }
  
  if(cnt >= M){
    cout << "Yes";
  }else
    cout << "No";
  return 0;
}
      


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N;
    int ans =0;
    string S;
    cin >> N>>S;
    REP(i,N-2){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
            ans++;
        }
    }
    cout << ans << endl;
}

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


def main():
    n, p = list(map(int, input().split()))
    a = list(map(int, input().split()))
    odd_count = sum([1 for ai in a if ai % 2 == 1])

    # See:
    # https://www.youtube.com/watch?v=5usHNxVUzqk
    if odd_count == 0:
        if p == 0:
            print(2 ** n)
        else:
            print(0)
    else:
        print(2 ** (n - 1))


if __name__ == '__main__':
    main()


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

int main(){
    int N,K;
    cin >> N >> K;
    
    ll ans;
    ans=K;
    
    for(int i=2; i<=N; i++){
        ans *= K-1;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


ll dp[101010];
int main(){
    int n;
    cin>>n;
    ll h[n];
    rep(i,n)cin>>h[i];
    rep(i,n)dp[i]=longinf;
    dp[0]=0;
    rep(i,n){
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int n, m, x; cin >> n >> m >> x;
    int ct_l = 0;
    int ct_r = 0;
    rep(i,m) {
        int a; cin >> a;
        if (a < x) ct_l++;
        else ct_r++;
    }
    cout << min(ct_l,ct_r) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int x,y,H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0) break;
        for(x=1;x<=H;x++){
            for(y=1;y<=W;y++){
                if((x+y)%2==0){
                    printf("#");
                }if((x+y)%2==1){
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2048
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n;
	cin >> n;
	if (n == 1)cout << n << endl;
	else {
		for (int i = n; i > 0; i--) {
			for (int j = 2; j <= i; j++) {
				for (int p = 2; pow(j, p) <= i; p++) {
					int a = pow(j, p);
					if (i == a) {
						cout << i << endl;
						return 0;
					}
				}
			}
		}
		
	}
	return 0;
}



Measured memory_bytes: 256
#include<deque>
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=5050;

int n;
char s[N],t[N];

deque<int> A,B;

int main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    scanf("%s",t+1);
    FOR(i,1,n)s[i]-='0',t[i]-='0';

    s[0]=!s[1],t[0]=!t[1];
    s[n+1]=!s[n],t[n+1]=!t[n];

    FOR(i,1,n+1)if(s[i-1]!=s[i])A.push_back(i);
    FOR(i,1,n+1)if(t[i-1]!=t[i])B.push_back(i);
    if(s[1]!=t[1])A.push_front(1);
    for(int i=0;i<=n+1;i+=2)A.push_front(1),A.push_front(1);
    for(int i=0;i<=n+1;i+=2)A.push_back(n+1),A.push_back(n+1);
    //for(int i=0;i<A.size();i++)printf("%d ",A[i]); puts("");
    //for(int i=0;i<B.size();i++)printf("%d ",B[i]); puts("");
    int ans=1e9;
    for(int i=0;i+B.size()<=A.size();i+=2){
        int tot=0;
        for(int j=0;j<i;j++)tot+=abs(A[j]-1);//全放左边
        for(int j=0;j<B.size();j++){
            tot+=abs(A[i+j]-B[j]);
        }
        for(int j=i+B.size();j<A.size();j++)tot+=abs(A[j]-(n+1));//全放右边
        ans=min(ans,tot);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll INF = 1000000000000000000;
ll dp[301][301];

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	vector<int> b(n + 1);
	for(int i = 0; i < n; ++i){ b[i + 1] = b[i] + a[i]; }
	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= n; ++j){ dp[i][j] = INF; }
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j + i <= n; ++j){
			const int head = j, tail = i + j;
			if(i == 1){ dp[head][tail] = 0; }
			for(int k = head + 1; k < tail; ++k){
				int x = b[k] - b[head], y = b[tail] - b[k], c = 0;
				ll cost = dp[head][k] + dp[k][tail];
				while(x > 0 || y > 0){
					const int z = x % 10, w = y % 10;
					cost += (z * w) + c;
					c = (z + w + c >= 10 ? 1 : 0);
					x /= 10; y /= 10;
				}
				cost += c;
				dp[head][tail] = min(dp[head][tail], cost);
			}
		}
	}
	cout << dp[0][n] << endl;
	return 0;
}

Measured memory_bytes: 1900
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#define LEN 100005
using namespace std;

typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}
int min(int a, int b){
    return a < b ? a : b;
}
int main(){
    int elaps =0,c,i,q;
    P u;
    cin >> n;
    cin >> q;
    for(int i = 1; i <= n; i++){
        cin >> Q[i].name;
        cin >> Q[i].t;
    }
    head = 1;
    tail = n + 1;
    
    while(head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enqueue(u);
        else{
         cout << u.name << " " << elaps << endl;
         
        }
    }
    return 0;
}



Measured memory_bytes: 13244
#include<bits/stdc++.h>
#include<unistd.h>
#include<iostream>
#include<utility>

using namespace std;

#define REP(i,m) for(int i=0;i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> pp;
ll mod =1000000007;

int n;
int c[10000000];
int d[10000000];
int main()
{
    int a,b;

    cin>>a>>b;

    int lo,hi;
    lo = a*2;
    hi = a*4;

    if(b>=lo && b<=hi && b%2==0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAXN = 55;
const int MAXM = 5e5 + 5;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;


int main(){
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(c > (a - b)){
        printf("%d\n", c - (a-b));
    }else{
        printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    atgc = ["A", "T", "G", "C"]
    n, q = [int(i) for i in input().split()]
    s=input()
    lr = []
    for i in range(q):
        lr.append([int(i) for i in input().split()])

    ruisekiwa = []
    ruisekiwa.append(0)
    cnt = 0
    for i in range(n-1):
        if s[i] + s[i+1] == "AC":
            cnt += 1
        ruisekiwa.append(cnt)

    for i in range(q):
        print(ruisekiwa[lr[i][1]-1]-ruisekiwa[lr[i][0]-1])

main()



Measured memory_bytes: 24464
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b;
    while(~scanf("%d %d",&a,&b))
    {
        if(a==2||b==2||a==11||a==12)
        {
            printf("No\n");
        }
        else
        {
           if((a==1||a==3||a==5||a==7||a==8||a==10)&&(b==4||b==6||b==9||b==11))
            printf("No\n");
           else if((b==1||b==3||b==5||b==7||b==8||b==10||b==12)&&(a==4||a==6||a==9))
            printf("No\n");
            else
            printf("Yes\n");
        }
    }

}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
  string s;
  string ans;
  cin >> s;
  for(int i=0; i<s.size(); i++){
    if(s[i]=='0' || s[i]=='1'){
      ans.push_back(s[i]);
    }else{
      if(!ans.empty())ans.pop_back();
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// // 整数の入力
		// int a = sc.nextInt();
		// // スペース区切りの整数の入力
		// int b = sc.nextInt();
		// int c = sc.nextInt();
		// // 文字列の入力
		// String s = sc.next();
		// // 出力
    // System.out.println((a+b+c) + " " + s);
		char X = sc.next().toCharArray()[0];
		char Y = sc.next().toCharArray()[0];
		if (X < Y) {
			System.out.println("<");
		} else if (X == Y) {
			System.out.println("=");
		} else {
			System.out.println(">");
		}
	}
}

Measured memory_bytes: 21716
import sys
sys.setrecursionlimit(10**7)

n, m = map(int, input().split())

tree = [[] for _ in range(n)]
for _ in range(m):
    x, y, z = map(int, input().split())
    tree[x - 1].append(y - 1)
    tree[y - 1].append(x - 1)

visited = [False for _ in range(n)]


def dfs(v, p):
    for u in tree[v]:
        if u == p:
            continue
        elif visited[u]:
            continue
        else:
            visited[u] = True
            dfs(u, v)


res = 0
for i in range(n):
    if not visited[i]:
        visited[i] = True
        dfs(i, -1)
        res += 1

print(res)


Measured memory_bytes: 110372
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	if ((B - A - 1) % 2 == 1) cout << "Alice" << endl;
	if ((B - A - 1) % 2 == 0) cout << "Borys" << endl;
	return 0;
}


Measured memory_bytes: 256
input = [input() for i in range(2)]

n = int(input[0])
s = list(input[1])
answer = []
alf = [chr(ord('A') + i) for i in range(26)]


for letter in s:
  for index, al in enumerate(alf, 1):
    if(al == letter):
      if(index + n < len(alf)):
          answer.append(alf[index + n -1])
      else:
        extra = (index + n) % len(alf)
        answer.append(alf[extra -1])
		
print(''.join(answer))

Measured memory_bytes: 3188
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
double ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 char s;
 ll a=0,b=0;
 rep(i,0,3){
  sc(s);
  if(s=='A')a++;
  if(s=='B')b++;
 }
 if(a==0||b==0)pn;
 else py;
 
return 0;}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(A == B){
    cout << C << endl;
  }
  else if(B == C){
    cout << A << endl;
  }
  else{
    cout << B << endl;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3500
l = list(map(int, input().split(' ')))
a = l[0]
b = l[1]
c = l[2]
d = l[3]
count=0
s=0
if a>0:
    if d>=a:
        s+=a
        d-=a
    else:
        s+=d
        d-=d
if d>0:
    d-=b
if d>0:
    if d>=c:
        s-=c
        d-=c
    else:
        s-=d
print(s)
    
        
        


Measured memory_bytes: 8956
def generateG(n):
    if n == 1:
        return [1]
    g = []
    h = 1
    while h < n:
        g.append(h)
        h = 3*h+1
    g.reverse()
    return g 

def insertionSort(a, n, g):
    cnt = 0
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j = j - g
            cnt += 1
            
        a[j+g] = v
    return cnt

if __name__ == '__main__':
    N = (int)(input())
    A = []
    cnt = 0
    for x in range(N):
        A.append((int)(input()))

    g = generateG(N)

    count = 0

    for x in g:
        count += insertionSort(A,N,x)

    print(len(g))
    print(' '.join([(str)(x) for x in g]))
    print(count)
    print('\n'.join([(str)(x) for x in A]))
    

Measured memory_bytes: 127988
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int k = scan.nextInt();
		int n = scan.nextInt();
		int a[] = new int[n];
		int dis[] = new int[n];
		int ans =0;
		
		for(int i=0;i<n;i++) {
			a[i] = scan.nextInt();
		}
		
		for(int i=0;i<n;i++) {
			if(i!=n-1) {
				dis[i] = a[i+1]-a[i];
			}else {
				dis[i] = k+a[0]-a[i];
			}
		}
		
		Arrays.sort(dis);
		
		for(int i=0;i<n-1;i++) {
			ans += dis[i];
		}
		
		System.out.println(ans);
		
	}	
}


Measured memory_bytes: 81548