akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
template<typename Monoid>
struct SegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	int sz;
	vector<Monoid> seg;
	const F f;
	const Monoid e;

	SegmentTree(int n, const F f, const Monoid &e): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
	}

	SegmentTree(int n, const F f, const Monoid &e, vector<Monoid> v): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
		for(int i=0; i<n; i++) seg[i+sz]=v[i];
		for(int i=sz-1; i>=1; i--){
			seg[i]=f(seg[2*i], seg[2*i+1]);
		}
	}

	void update(int k, const Monoid &x){
		k+=sz;
		seg[k]=x;
		while(k>1){
			k>>=1;
			seg[k]=f(seg[2*k], seg[2*k+1]);
		}
	}

	Monoid query(int a, int b){
		a+=sz, b+=sz;
		Monoid ret=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) ret=f(ret, seg[--b]);
			if(a&1) ret=f(ret, seg[a++]);
		}
		return ret;
	}
	
	template<typename C>
	int binarysearch(int st, C &check){//[st,ret):false, [st, ret+1):true (check(e):false)
		Monoid s=e;
        int k=st+sz;
        while(1){
            if(!check(f(s, seg[k]))){
                if(((k+1)&-(k+1))==k+1) return -1;
                s=f(s, seg[k++]);
                if(~k&1) k>>=1;
            }else{
                if(k>=sz) return k-sz;
                k<<=1;
            }
        }
		assert(0);
        return -1;
	}

	Monoid operator[](const int &k) const{
		return seg[k+sz];
	}
};
int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    vector<int> a(n);
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    SegmentTree<int> seg(n, [](int x, int y){ return max(x, y);}, -1, a);
    while(q--){
        int t;
        scanf("%d", &t);
        if(t==1){
            int x, v;
            scanf("%d %d", &x, &v);
            x--;
            seg.update(x, v);
        }else if(t==2){
            int l, r;
            scanf("%d %d", &l, &r);
            l--;
            printf("%d\n", seg.query(l, r));
        }else{
            int x, v;
            scanf("%d %d", &x, &v);
            x--;
            auto check=[&](int a){ return a>=v;};
            int r=seg.binarysearch(x, check);
            if(r!=-1) printf("%d\n", r+1);
            else printf("%d\n", n+1);
        }
    }
    return 0;
}


Measured memory_bytes: 7024
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    k = I()
    n = len(s)
    for i in range(n):
        if s[i] != s[0]:
            break
    else:
        print((k*n)>>1)
        return
    s += s
    t = s[i-1]
    for j in range(n)[::-1]:
        if s[j] != t:
            break
    s = s[i:j+1]
    ans = (i>>1)+((n-1-j)>>1)+((n-1-j+i)>>1)*(k-1)
    i = 0
    n = len(s)
    while i < n:
        t = s[i]
        l = 0
        while i < n and t == s[i]:
            i += 1
            l += 1
        ans += (l >> 1)*k
    print(ans)
    return

#B
def B():
    n = I()
    s = [list(map(int, input())) for i in range(n)]
    v = [[] for i in range(n)]
    for i in range(n):
        for j  in range(i+1,n):
            if s[i][j]:
                v[i].append(j)
                v[j].append(i)
    bfs = [-1]*n
    q = deque([0])
    q[0] = 0
    f = 1
    while f and q:
        x = q.popleft()
        nb = 1-bfs[x]
        for y in v[x]:
            if bfs[y] >= 0:
                if bfs[y] != nb:
                    f = 0
                    break
            else:
                bfs[y] = nb
                q.append(y)
    if not f:
        print(-1)
        return
    ans = -1
    for i in range(n):
        bfs = [0]*n
        bfs[i] = 1
        q.append(i)
        while q:
            x = q.popleft()
            nb = bfs[x]+1
            for y in v[x]:
                if not bfs[y]:
                    bfs[y] = nb
                    q.append(y)
        m = max(bfs)
        if m > ans:
            ans = m
    print(ans)
    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    B()


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

using namespace std;

int main() {

	int n; scanf("%d", &n);

	vector<int> arr(n);

	for (int i = 0; i < n; i++)
		scanf("%d", &arr[i]);

	int m = 1e9;

	for (int i = -100; i <= 100; i++) {

		int cost = 0;

		for (int w : arr)
			cost += (w - i) * (w - i);

		m = min(m, cost);

	}

	printf("%d", m);

	return 0;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static int[][] field;
	static int center = 100;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int t = sc.nextInt();
			int n = sc.nextInt();
			if (t == 0 && n == 0)
				break;
			field = new int[201][201];
			for (int i = 0; i < 201; i++)
				for (int j = 0; j < 201; j++)
					field[i][j] = 0;
			int[] x = new int[n];
			int[] y = new int[n];
			for (int i = 0; i < n; i++) {
				x[i] = sc.nextInt() + center;
				y[i] = sc.nextInt() + center;
				field[x[i]][y[i]] = -1;
			}
			int sx = sc.nextInt() + center;
			int sy = sc.nextInt() + center;
			field[sx][sy] = 1;
			move(sx, sy, t);
			int result = count(201);
			System.out.println(result);
		}
		sc.close();
	}

	static void move(int x, int y, int t) {
		int[] dx = { 0, 1, 1, 0, -1, -1 };
		int[] dy = { 1, 1, 0, -1, -1, 0 };
		if (field[x][y] <= t)
			for (int i = 0; i < dx.length; i++) {
				if (field[x + dx[i]][y + dy[i]] == 0) {
					field[x + dx[i]][y + dy[i]] = field[x][y] + 1;
					move(x + dx[i], y + dy[i], t);
				}
				if (field[x + dx[i]][y + dy[i]] > 0
						&& field[x + dx[i]][y + dy[i]] > field[x][y] + 1) {
					field[x + dx[i]][y + dy[i]] = field[x][y] + 1;
					move(x + dx[i], y + dy[i], t);
				}
			}
	}

	static int count(int w) {
		int result = 0;
		for (int i = 0; i < w; i++)
			for (int j = 0; j < w; j++)
				if (field[i][j] > 0)
					result++;
		return result;
	}
}

Measured memory_bytes: 100044
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int width = sc.nextInt();
        int height = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        int  count = 0;
        if (x *2 == width && y * 2 == height){
            count = 1;
        }

        double area = (double)width * (double)height / 2.0;

        System.out.println(String.valueOf(area) + " " + String.valueOf(count));

    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second

using namespace std;

/*int gcd(int a,int b){
	if(b == 0)
		return a;
	return gcd(b,a%b);
}*/

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

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

    int n,k;
	cin>>n>>k;

    int upper = ((n -2) * (n-1) )/ 2;

    if(k > upper)
    {
    	cout<<"-1";
    	return 0;
    }

    vector<pii> v;
    for(int i =2;i<=n;i++){
    	v.push_back({1,i});
    }

    for(int i =2;i<=n-1;i++){
    	if(k == upper)
    			break;
    	for(int j = i+1;j<=n;j++){
    		if(k == upper)
    			break;
    		v.push_back({i,j});
    		upper--;
    		if(k == upper)
    			break;
    	}
    	if(k == upper)
    		break;
    }

    cout<<v.size()<<endl;
    for(int i =0;i<v.size();i++)
    	cout<<v[i].f<<" "<<v[i].s<<endl;


	return 0;
}

Measured memory_bytes: 384
// https://atcoder.jp/contests/abc159/tasks/abc159_e

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

using namespace std;

int H, W, K;
vector<vector<int>> G;

vector<vector<int>> DP;
void dp() {
    DP.assign(H, vector<int>(W, 0));
    DP[0][0] = G[0][0];
    for (int x = 1; x < W; ++x) {
        DP[0][x] = DP[0][x-1] + G[0][x];
    }
    for (int y = 1; y < H; ++y) {
        DP[y][0] = DP[y-1][0] + G[y][0];
    }
    for (int y = 1; y < H; ++y) {
        for (int x = 1; x < W; ++x) {
            DP[y][x] = DP[y-1][x] + DP[y][x-1] - DP[y-1][x-1] + G[y][x];
        }
    }
}
// [xl,xr), [yl,yr)
int query(int xl, int xr, int yl, int yr) {
    if (yr - yl == 0 || xr - xl == 0) return 0;
    int ans =  DP[yr-1][xr-1];
    if (yl > 0) {
        ans -= DP[yl-1][xr-1];
    }
    if (xl > 0) {
        ans -= DP[yr-1][xl-1];
    }
    if (yl > 0 && xl > 0) {
        ans += DP[yl-1][xl-1];
    }
    return ans;
}

const int inf = 1e8;
int divx(vector<pair<int,int>>& ys) {
    int ans = 0;
    int xl = 0;
    for (int xr = 1; xr <= W;) {
        bool succ = true;
        for (int i = 0; i < ys.size(); ++i) {
            int yl = ys[i].first, yr = ys[i].second;
            int d = query(xl, xr, yl, yr);
            succ &= d <= K;
        }
        if (succ) {
            xr++;
            continue;
        }
        if (xr - xl <= 1) {
            return inf;
        }
        ans++;
        xl = xr-1;
    }
    return ys.size() - 1 + ans;
}

int divy() {
    int ans = inf;
    for (int b = 0; b < (1 << H); b++) {
        vector<pair<int,int>> ys;
        int l = 0;
        for (int r = 0; r < H; ++r) {
            if (b & (1 << r)) {
                ys.push_back({l,r+1});
                l = r+1;
            }
        }
        if (l < H) {
            ys.push_back({l,H});
        }
        ans = min(ans, divx(ys));
    }
    return ans;
}

int solve() {
    dp();
    return divy();
}

int main() {
    cin >> H >> W >> K;
    G.assign(H, vector<int>(W, 0));
    for (int y = 0; y < H; ++y) {
        string line;
        cin >> line;
        for (int x = 0; x < W; ++x) {
            G[y][x] = line[x] - '0';
        }
    }
    cout << solve() << endl;
    return 0;
}

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

#define PI 3.14159265359
#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;
const ll INF = 1e9 + 7;

int main(void)
{
    string s,t;
    cin>>s>>t;
    
    int ans=0;
    rep(i,0,s.size()){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3916
#include <cstdio>
#include <stdint.h>
#include <vector>
#include <map>

char str[40];

const int base1=26,base2=27;
const int64_t MOD=1e9+7;

struct Thing{
  int64_t red1,blue1;
  int64_t red2,blue2;
  int64_t red1_scale;
  int64_t red2_scale;
  Thing():red1(0),red2(0),blue1(0),blue2(0),red1_scale(1),red2_scale(1){
  }
  struct Thing add_red(int v){
    struct Thing other;
    other.red1=(red1+v*red1_scale)%MOD;
    other.red2=(red2+v*red2_scale)%MOD;
    other.blue1=blue1;
    other.blue2=blue2;
    other.red1_scale=red1_scale*base1%MOD;
    other.red2_scale=red2_scale*base2%MOD;
    return other;
  }
  struct Thing add_blue(int v){
    struct Thing other;
    other.red1=red1;
    other.red2=red2;
    other.blue1=(blue1*base1+v)%MOD;
    other.blue2=(blue2*base2+v)%MOD;
    other.red1_scale=red1_scale;
    other.red2_scale=red2_scale;
    return other;
  }
  bool operator<(struct Thing other)const{
    if(red1!=other.red1) return red1<other.red1;
    if(red2!=other.red2) return red2<other.red2;
    if(blue1!=other.blue1) return blue1<other.blue1;
    if(blue2!=other.blue2) return blue2<other.blue2;
    if(red1_scale!=other.red1_scale) return red1_scale<other.red1_scale;
    if(red2_scale!=other.red2_scale) return red2_scale<other.red2_scale;
    return false;
  }
};

int main(){
  int N;
  scanf("%d",&N);
  scanf("%s",str);
  std::vector<struct Thing> layer1(1);
  for(int i=0;i<N;i++){
    std::vector<struct Thing> next;
    for(struct Thing thing:layer1){
      next.push_back(thing.add_red(str[i]));
      next.push_back(thing.add_blue(str[i]));
    }
    std::swap(layer1,next);
  }
  std::vector<struct Thing> layer2(1);
  for(int i=0;i<N;i++){
    std::vector<struct Thing> next;
    for(struct Thing thing:layer2){
      next.push_back(thing.add_red(str[N*2-1-i]));
      next.push_back(thing.add_blue(str[N*2-1-i]));
    }
    std::swap(layer2,next);
  }
  std::map<struct Thing,int> counts;
  for(struct Thing thing:layer1){
    counts[thing]++;
  }
  int64_t ans=0;
  for(struct Thing thing:layer2){
    if(counts.count(thing)){
      ans+=counts[thing];
    }
  }
  printf("%ld\n",ans);
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MX_N = 2e5+5;
const int MOD = 1e9+7;

int N, X, Y;
int C[MX_N], W[MX_N];
int mn[MX_N], cnt[MX_N], f[MX_N];

int expo(int b, int p) {
    if (p == 0) return 1;
    if (p == 1) return b;
    int x = expo(b,p/2);
    x = (ll)x*x % MOD;
    if (p&1) x = (ll)x*b % MOD;
    return x;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> X >> Y;
    W[0] = 1e9+5;
    FOR(i,1,N) mn[i] = 0;
    FOR(i,1,N){
        cin >> C[i] >> W[i];
        if (W[i] < W[mn[C[i]]]) mn[C[i]] = i;
    }

    int a = 0, b = 0;
    FOR(i,1,N){
        if (W[mn[i]] < W[a]) b = a, a = mn[i];
        else if (W[mn[i]] < W[b]) b = mn[i];
    }

    f[0] = f[1] = 1;
    FOR(i,2,N){ f[i] = (ll)f[i-1]*i % MOD; }
    int tot = 0;
    FOR(i,1,N){
        if (W[i]+W[C[i]==C[a]?b:a] <= Y || (W[mn[C[i]]]+W[C[i]==C[a]?b:a] <= Y && W[mn[C[i]]]+W[i] <= X))
            ++tot, ++cnt[C[i]];
    }
    int ans = f[tot];
    FOR(i,1,N){
        ans = (ll)ans*expo(f[cnt[i]],MOD-2) % MOD;
    }
    cout << ans << '\n';
}



Measured memory_bytes: 4224
H,W=map(int,input().split())
S=[list(map(int, input().split())) for i in range(10)]
l=[None]*10
for i in range(10):
    l[i]=S[i][1]
for i in range(5):
    for j in range(10):
        for k in range(10):
            if l[j]>l[k]+S[j][k]:
                l[j]=l[k]+S[j][k]
l.append(0)
a=0
for i in range(H):
    L=list(map(int,input().split()))
    for j in L:
        a+=l[j]
print(a)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n;
	ll t;
	cin>>n>>t;
	ll a,b;
	a=0;
	ll s=0;
	cin>>a;
	n=n-1;
	while(n--){
		cin>>b;
		if(b-a>t) s+=t;
		else s+=b-a;
		a=b;
	}
	cout<<s+t<<endl;

return 0;
}


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

int main()
{
	int x;
	deque<int> d;
	while(cin >> x){
		if(x == 0){
			cout << d.back() << endl;
			d.pop_back();
		}else{
			d.push_back(x);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const ll INF = 1001001001001;
bool visit[303][303];
int main(){
    int n; cin >> n;
    ll cost[n][n];
    ll d[n][n];
    rep(i,n)rep(j,n) d[i][j] = INF;
    rep(i,n){
        rep(j,n){
            cin >> cost[i][j];
            d[i][j] = cost[i][j];
        }
    }
    ll res = 0;
    rep(k,n){
        rep(i,n){
            rep(j,n){
                if(d[i][j] == d[i][k]+d[k][j] && i<j && k!=i && k!=j && visit[i][j]==0 ){
                    res += d[i][j];
                    visit[i][j]=1;
                }
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    bool ok = 1;
    ll ans = 0;
    rep(i,n){
        rep(j,n){
            if(i<j) ans += d[i][j];
            if(d[i][j] != cost[i][j]){
                ok = 0;
                break;
            }
        }
    }
    if(!ok) cout << -1 << endl;
    else cout << ans-res << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int a[n];
	int i,j;
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int j=0;j<k;j++){
		sum+=a[j];
	}
	cout<<sum;
} 

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int gcd(int a,int b) {
    if(a < b) swap(a,b);
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> l(n),r(n);
    l[0] = a[0];
    r[n-1] = a[n-1];
    rep(i,n-1) {
        l[i+1] = gcd(l[i],a[i+1]);
    }
    rrep(i,n-1) {
        r[i] = gcd(r[i+1],a[i]);
    }
    int ans = max(l[n-2],r[1]);
    rep2(i,1,n-1) {
        chmax(ans,gcd(l[i-1],r[i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;



int main()
{
	string S;
	cin >> S;
	if (S == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}
}

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

template<class T> struct rge { T b, e; };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
    ~debug(){cerr<<endl;}
    template<class T> debug& operator<<(T x){cerr<<boolalpha<<x; return *this;}
    template<class B, class C> debug& operator<<(pair<B, C> x){return *this<<"("<<x.first<<", "<<x.second<<")";}
    template<class T> debug& operator<<(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}return *this<<"]";}
    template<class T> debug& operator<<(vector<T> x){ return *this<<range(x.begin(),x.end());}
#else
    template<class T> debug& operator <<(const T&){return *this;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}


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

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    int ta = min(a, k);
    ans += ta;
    k -= ta;
    int tb = min(b, k);
    k -= tb;
    int tc = min(c, k);
    ans -= tc;
    k -= tc;
    cout << ans << endl;
}













// Those who say they can, and those who say they can't - are both usually right.

// Read statement carefully
// Solve on paper first!
// Overflows (long long)

// Author: blondie


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> o_tree;

void solve()
{
    ll x, k, d;
    cin >> x >> k >> d;
    x = llabs(x);
    ll moves = min(k, x / d);
    ll no = x - moves * d;
    ll rem = k - moves;
    if (rem == 0)
    {
        cout << no << "\n";
        return;
    }
    else
    {
        if(rem%2==1){
        ll no1 = no + d;
        ll no2 = llabs(no - d);
        cout << min(no1, no2) << "\n";
        return;
        }
        else{
            cout<<no<<"\n";
            return;
        }
    }
}

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

    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    cout << setprecision(20);

    ll t = 1;

    // cin >> t;

    while (t--)
    {
        solve();
    }

    return 0;
}

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

int main() {
   int K,T;
   cin >> K >> T;
   int a[T];
   for (int i=0; i<T; i++) {
       cin >> a[i];
   }
   sort(a,a+T);
   int m=a[T-1];
   if (K%2==0) {
       if (m<=K/2) cout << 0 << endl;
       else {
           int n=m-K/2;
           cout << 2*n-1 << endl;
       }
   }
   else {
       if (m<=K/2+1) cout << 0 << endl;
       else {
           int n=m-K/2-1;
           cout << 2*n << endl;
       }
   }
}

Measured memory_bytes: 3640
var ans:int64;
    i,n:longint;
    a:array[0..15]of longint;
procedure dfs(dep,bool:longint);
var i:longint;
begin
  if dep=n+1 then
  begin
    if bool=1 then inc(ans);
    exit;
  end;
  for i:=a[dep]-1 to a[dep]+1 do
  if i mod 2=0 then dfs(dep+1,bool or 1) else
  dfs(dep+1,bool);
end;
begin
  read(n);
  for i:=1 to n do
  read(a[i]);
  dfs(1,0);
  writeln(ans);
end.

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

#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define VS(v,n) vector<string> v(n); REP(i,n){cin>>v[i];}

int main(){
  INT(h); INT(w); INT(ch); INT(cw); INT(dh); INT(dw); ch--; cw--; dh--; dw--;
  VS(mz, h);
  vector<int> dra = {0, -1, 1, 0}, dca = {-1, 0, 0, 1}, drb, dcb, v(w, -1);
  vector<vector<int>> ans(h, v);
  REP(i, -2, 3){
    REP(j, -2, 3){
      if ((i == 0 && abs(j) <= 1) || (j == 0 && abs(i) <= 1)) {continue;}
      drb.PB(i); dcb.PB(j);
    }
  }
  queue<pair<int, int>> qa, qb;
  ans[ch][cw] = 0;
  qa.push(MP(ch, cw));
  while (!qa.empty() || !qb.empty()){
    while (!qa.empty()){
      auto p = qa.front(); qa.pop();
      qb.push(p);
      int r = p.first, c = p.second;
      REP(i, SZ(dra)){
        if (0 <= r + dra[i] && r + dra[i] < h && 0 <= c + dca[i] && c + dca[i] < w && mz[r + dra[i]][c + dca[i]] == '.' && ans[r + dra[i]][c + dca[i]] < 0){
          ans[r + dra[i]][c + dca[i]] = ans[r][c];
          qa.push(MP(r +  dra[i], c + dca[i]));
        }
      }
    }
    while (!qb.empty()){
      auto p = qb.front(); qb.pop();
      int r = p.first, c = p.second;
      REP(i, SZ(drb)){
        if (0 <= r + drb[i] && r + drb[i] < h && 0 <= c + dcb[i] && c + dcb[i] < w && mz[r + drb[i]][c + dcb[i]] == '.' && ans[r + drb[i]][c + dcb[i]] < 0){
          ans[r + drb[i]][c + dcb[i]] = ans[r][c] + 1;
          qa.push(MP(r +  drb[i], c + dcb[i]));
        }
      }
    }
  }
  printf("%d\n", ans[dh][dw]);
  return 0;
}

Measured memory_bytes: 9620
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long inved(long long x){
  long long p = mod - 2;
  long long y = 1;
  long long base = x;
  while (p != 0){
    if (p % 2 == 1){
      y *= base;
      y %= mod;
    }
    base *= base;
    base %= mod;
    p /= 2;
  }
  return y;
}

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i=0;i<N;i++){
    cin >> A.at(i);
  }
  map<long long, long long> D;
  D[0] = 1;
  for (int i=0;i<N;i++){
    vector<vector<long long>> L(0, vector<long long>(2));
    for (pair<long long, long long> p : D){
      L.push_back({p.first, p.second});
    }
    for (int j=0;j<L.size();j++){
      int f = L.at(j).at(0);
      long long s = L.at(j).at(1);
      if (f + A.at(i) + 1 <= K){
        if (D.count(f + A.at(i) + 1)){
          D[f + A.at(i) + 1] += mod - s;
          D[f + A.at(i) + 1] %= mod;
        }
        else{
          D[f + A.at(i) + 1] = mod - s;
        }
      }
    }
  }
  vector<long long> fact(K+N, 1);
  vector<long long> invf(K+N, 1);
  for (int i=0;i<K+N-1;i++){
    fact.at(i+1) = (fact.at(i) * (i+1)) % mod;
  }
  invf.at(K+N-1) = inved(fact.at(K+N-1));
  for (int i=K+N-1;i>0;i--){
    invf.at(i-1) = (invf.at(i) * i) % mod;
  }
  long long P = 0, prod = 1;
  for (pair<int, long long> p : D){
    prod = p.second * fact.at(K-p.first+N-1);
    prod %= mod;
    prod *= invf.at(K-p.first);
    prod %= mod;
    P += prod;
    P %= mod;
  }
  cout << (P * invf.at(N-1)) % mod << endl;
  return 0;
}

Measured memory_bytes: 12280
#include<stdio.h>
int main(){
    long long int n;
    scanf("%lld",&n);
    long long int x=n;
    long long int sum=0;
    for( ;x>0;){
        sum+=x%10;
        x=x/10;
    }
    if(n%sum==0)
        printf("Yes\n");
    else 
        printf("No\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
#define pint pair<int,int>
#define pdouble pair<double,double>
using namespace std;
typedef long long ll;

int main(){
    int n, m;
    cin >> n >> m;
    int ans = 0;
    int a = -1,b = 100000;
    rep(i,m){
        int l, r;
        cin >> l >> r;
        a = max(a,l);
        b = min(b,r);
    } 
    cout << max(b-a+1,0) << endl;
    return 0;
}

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

int SumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int answer = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = SumOfDigits(i);
    if (sum >= A && sum <= B) {
      answer += i;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
def flog(N, M, a):
  dp = [10**4] * (N + 1)
  dp[0] = 1
  dp[1] = 1
  
  if 1 in a:
    dp[1] = 0

  for j in a:
    dp[int(j)] = 0
    
  for i in range(2, N+1):
    if dp[i] != 0:
      dp[i] = dp[i - 1] + dp[i - 2]
  return dp[N] % INF
      
if __name__ == "__main__":
  N, M = map(int, input().split())
  a = [input() for i in range(M)]
  INF = 1000000007
  print(flog(N, M, a))

Measured memory_bytes: 460020
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();
		scan.close();
		int temp = (int)Math.sqrt(X);
		temp = temp * temp;
		int s = temp;
		int a = 2;
		int cnt = 2;
		boolean flag = true;
		if(temp == 1) {
			System.out.println(1);
			System.exit(0);
		}
		while(flag) {
			int k = (int)Math.pow(a, cnt);
			if(k <= X) {
				if(temp < k) {
					temp = k;
				}
			}else {
				a ++;
				cnt = 1;
			}
			cnt ++;
			if(k == s) {
				break;
			}
		}
		System.out.println(temp);
	}
}


Measured memory_bytes: 22996
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000009
using namespace std;

int main() {
	int ar[5], k;
	for (int i = 0; i < 5; ++i)
		cin >> ar[i];
	cin >> k;
	if (ar[4] - ar[0] > k)
		return cout << ":(\n", 0;
	cout << "Yay!\n";
	return 0;
}

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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;


void solve()
{
  ll n,k;
  cin >> n >> k;
  ll a[n+1];
  for(ll i=1;i<=n;i++)  cin >> a[i];
  vector<ll> w;
  vector<bool> vis(n+5,0);
  w.Pb(1);
  vis[1]=1;
  ll i = 1;
  while(vis[a[i]] == 0)
  {
    vis[a[i]] = 1;
    w.Pb(a[i]);
    i = a[i];
  }
  ll cnt = 0;
  for(int cn = 0;cn < w.size() ;cn++)
  {
    if(w[cn] == a[i])
    {
        break;
    }
    cnt++;
  }
  ll nn = (ll)w.size() - cnt;
  if(k<=(cnt))  cout << w[k];
  else
  {
    k-=(cnt);
    ll idx = k%nn;
    cout << w[cnt + idx];
  }
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 6924
#include <iostream>

using namespace std;

int main()
{
    int x,AC = 0, WA= 0, TLE= 0, RE= 0;
    cin>>x;
    string ans;
    for(int i = 0 ; i < x ; i++)
    {
        cin>>ans;
        if(ans == "AC")
            AC++;
        else if(ans == "WA")
            WA++;
        else if(ans == "TLE")
            TLE++;
        else if(ans == "RE")
            RE++;
    }
    cout<<"AC x "<<AC<<endl;
    cout<<"WA x "<<WA<<endl;
    cout<<"TLE x "<<TLE<<endl;
    cout<<"RE x "<<RE<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()

const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    double x;
    cin>>x;
    cout<<setprecision(20)<<x*x*x/27.0<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
""" outputの時間比較 """
from sys import stdin, stdout
import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()
def print_list(s):
    stdout.write(' '.join(list(map(str, s))) + '\n')
    # stdout.flush()
def print_single(s):
    stdout.write(str(s) + '\n')
    # stdout.flush()


# N = _i()
# D_list = np.array([_i() for _ in range(N)])
N = d_in()
D_list = np.array([d_in() for _ in range(N)])


idx = np.argsort(D_list)
sorted_D = D_list[idx]
mapping = []
for j in idx:
    mapping.append(j+1)

# 解説を参考に実装
# Dのスコアが大きい方から小さい方へ伸びる有向エッジとみなす
# valueはノードから出ている有向エッジを切った場合の部分木の大きさ
nodes = [1] * N
ans = []
cost = [[0, 1] for _ in range(N)]
# 葉っぱから見て，[エッジにたどり着くまでのコスト, 自分も含めた子ノードの数]
for i in range(N-1, 0, -1):
    d = sorted_D[i]
    sub = nodes[i]
    target = d + 2*sub - N
    cand = np.searchsorted(sorted_D[:i], target)
    if (sorted_D[cand] != target) or (cand == i):
        print(-1)
        exit()
    else:
        ans.append((mapping[i], mapping[cand]))
        nodes[cand] += nodes[i]
        cost[cand][0] += (cost[i][0] + cost[i][1])
        cost[cand][1] += cost[i][1]

# 1番目のノードについてチェック
if cost[0][0] != sorted_D[0]:
    print(-1)
    exit()
else:
    for a in ans:
        # print(a[0], a[1])
        print_list(a)


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

using namespace std;

map<int,int> mp;

int main() {
    
    mp[1] = 300000;
    mp[2] = 200000;
    mp[3] = 100000;


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

    int ans = (a == 1 and b == 1) ? 400000 : 0;

    ans += mp[a] + mp[b];
    
    cout << ans  << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vbool vector<bool>
#define vvbool vector<vector<bool>>
#define INF 1000000009
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; }

int main(){
    ll N,W;
    cin >> N >> W;
    const ll MAX_N = 110;
    const ll MAX_W = 100100;
    vvll knap(MAX_N,vll(MAX_W,INF));
    knap[0][0] = 0;
    rep1(i,N+1){
        ll w,v;
        cin >> w >> v;
        rep(sum_value,MAX_W){
            if(sum_value < v)
                knap[i][sum_value] = min(w,knap[i-1][sum_value]);
            else if(knap[i-1][sum_value-v] != INF)
                knap[i][sum_value] = min(knap[i-1][sum_value],knap[i-1][sum_value-v]+w);
        }
    }
    /*rep(i,N){
        rep(j,10){
		    if(knap[i][j] == INF)
                cout << "INF ";
      	    else
                cout << knap[i][j] << " ";
        }
        cout << endl;
    }*/
    ll ans = 0;
    for(ll i = 0;i<MAX_N;i++){
        for(ll j = 0;j<MAX_W;j++){
            if(knap[i][j] <= W)
                ans = max(ans,j);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 87296
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 200050
int V;
vector<int> G[MAX_V],rG[MAX_V],vs;
bool used[MAX_V];
int cmp[MAX_V];
void add_edge(int from,int to){
  G[from].push_back(to);
  rG[to].push_back(from);
}
void dfs(int v){
  used[v]=1;
  for(int i=0;i<G[v].size();i++){
    if(!used[G[v][i]]) dfs(G[v][i]);
  }
  vs.push_back(v);
}
void rdfs(int v,int k){
  used[v]=1;
  cmp[v]=k;
  for(int i=0;i<rG[v].size();i++){
    if(!used[rG[v][i]]) rdfs(rG[v][i],k);
  }
}
int scc(){
  memset(used,0,sizeof(used));
  vs.clear();
  for(int v=0;v<V;v++){
    if(!used[v]) dfs(v);
  }
  memset(used,0,sizeof(used));
  int k=0;
  for(int i=vs.size()-1;i>=0;i--){
    if(!used[vs[i]]) rdfs(vs[i],k++);
  }
  return k;
}
int main(){
  int e,i,j,k,q;
  cin>>V>>e;
  for(i=0;i<e;i++) cin>>j>>k,add_edge(j,k);
  scc();
  cin>>q;
  for(i=0;i<q;i++) cin>>j>>k,cout<<(cmp[j]==cmp[k])<<endl;
  return 0;
}

Measured memory_bytes: 13776
#include<iostream>
using namespace std;
int main(){
  char a,b;
  cin>>a>>b;
  if(a=='H'){
    if(b=='H')cout<<'H'<<endl;
    else cout<<'D'<<endl;
  }
  else{
    if(b=='H')cout<<'D'<<endl;
    else cout<<'H'<<endl;
  }
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
inline void write(int x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
char s[105];
int main()
{
    int n;
    cin>>n;
    int a=0,b=0,c=0;
    for(int i=0;i<n;i++)
    {
        ll x;
        x=read();
        if(x%4==0)
            a++;
        else if(x%2==0)
            b++;
        else c++;
    }
    if(b>0)
        c++;
    if(a+1>=c)
        cout<<"Yes"<<endl;
    else 
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) 
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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 int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  char c;
  cin >> c;

  if (c == 'A') puts("T");
  else if (c == 'C') puts("G");
  else if (c == 'G') puts("C");
  else if (c == 'T') puts("A");

  return 0;
}


Measured memory_bytes: 256
function main(input){
  let [N, ...sList] = input.split('\n')
  N = parseInt(N, 10)
  const ls = {AC: 0, WA: 0, TLE: 0, RE: 0}
  for (let i = 0; i < N; i++) {
    const str = sList[i]
    switch (str) {
      case 'AC':
      case 'WA':
      case 'TLE':
      case 'RE':
        ls[str]++
      	break
      default:
      	break
    }
  }
  console.log(`AC x ${ls.AC}
WA x ${ls.WA}
TLE x ${ls.TLE}
RE x ${ls.RE}
`) 
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 43376
#include <stdio.h>
#include <math.h>

typedef struct{
  double x;
  double y;
}pos;

void kock(int, pos, pos);

int main(){
  int n;
  pos p1, p2;

  p1.x = 0;
  p1.y = 0;

  p2.x = 100;
  p2.y = 0;

  scanf("%d", &n);

  printf("%f %f\n", p1.x, p1.y);

  kock(n, p1, p2);

  printf("%f %f\n", p2.x, p2.y);

  return 0;
}

void kock(int n, pos p1, pos p2){

  pos s, t, u;

  if(n == 0) return;

  s.x = ( 2 * p1.x + 1 * p2.x) / 3;
  s.y = ( 2 * p1.y + 1 * p2.y) / 3;

  t.x = ( 1 * p1.x + 2 * p2.x) / 3; 
  t.y = ( 1 * p1.y + 2 * p2.y) / 3;

  u.x = (t.x - s.x) * cos(M_PI/3) - (t.y - s.y) * sin(M_PI/3) + s.x;
  u.y = (t.x - s.x) * sin(M_PI/3) + (t.y - s.y) * cos(M_PI/3) + s.y;

  kock(n-1, p1, s);
  printf("%f %f\n", s.x, s.y);

  kock(n-1, s, u);
  printf("%f %f\n", u.x, u.y);

  kock(n-1, u, t);
  printf("%f %f\n", t.x, t.y);

  kock(n-1, t, p2);

}

Measured memory_bytes: 636
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;

int N, u, v;
Graph G;
vector<int> res;
const long long INF = 1LL << 60;

void dfs(int s, int p, vector<int> &d) {

    for(auto e : G[s]) {
        if(e == p) {
            continue;
        } else {
            // cout << s << "," << e << endl;
            d[e] = d[s] + 1;
            dfs(e, s, d);
        }
    }
}

int main() {
    cin >> N >> u >> v;
    u--;
    v--;
    G.assign(N, vector<int>());
    rep(i, 0, N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> uu(N);
    vector<int> vv(N);
    uu[u] = 0;
    vv[v] = 0;
    dfs(u, -1, uu);
    dfs(v, -1, vv);
    int max = 0;
    rep(i, 0, N) {
        if(uu[i] < vv[i]) {
            if(max < vv[i]) {
                max = vv[i];
            }
        }
    }
    cout << max - 1 << endl;
}

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

int main() 
{
    int n,k;
    double sum=0;
    cin >> n >> k;
    for (int i=1; i<=n; i++)
    {
        int p=i, j=0;
        while (p<k)
        {
            p*=2;
            j++;
        }
        double x = (double)(pow(0.5,j)/n);
        sum += x;
    }
    printf("%.9f", sum); 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();
        int c = W / w;
        int d = H / h;
        int resX = W % w;
        sc.close();
        int resY = H % h;
        if (resX == 0 && resY == 0) {
            System.out.println("No");
            return;
        }
        // 余りの数
        int edge = resX * H + resY * W - resX * resY;
        int a = 0;
        int anum = h * w - 1;
        while (a * edge <= c * d) {
            a++;
            if (a > 1000000000) {
                System.out.println("No");
                return;
            }
            if (a * anum + 1 > 1000000000) {
                System.out.println("No");
                return;
            }
        }
        int b = a * anum + 1;
        b *= -1;
        System.out.println("Yes");
        for (int j = 1; j < H + 1; j++) {
            if (j % h != 0) {
                for (int i = 1; i < W + 1; i++) {
                    System.out.print(a);
                    if (i != W) {
                        System.out.print(" ");
                    }
                }
                System.out.println("");
                continue;
            }
            for (int i = 1; i < W + 1; i++) {
                if (i % w == 0) {
                    System.out.print(b);
                } else {
                    System.out.print(a);
                }
                if (i != W) {
                    System.out.print(" ");
                }
            }
            System.out.println("");
        }
    }
}


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

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

typedef pair<int, int>pi;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int n, a, ans;
int till[35], cnt[35];

int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a;
		bool fl = 0;
		for (int j = 0;j < 32;j++) {
			if (a&(1 << j)) {
				if (!fl)till[j]++, fl = 1;
				cnt[j] ^= 1;
			}
		}
	}
	for (int i = 32;i >= 0;i--) {
		if (!cnt[i])continue;
		if (till[i] == 0) {
			cout << -1 << endl;
			return 0;
		}
		else {
			ans++;
			for (int j = i - 1;j >= 0;j--) {
				cnt[j]^=1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long
const ll MAX = 1e9;

int main() {
    ll s;
    cin >> s;
    if (s <= MAX) {
        printf("0 0 0 1 %d 0", s);
    } else if (s == 1e18) {
        printf("0 0 %d 0 0 %d", MAX, MAX);
    } else {
        int a = s / MAX + 1;
        int b = MAX - s % MAX;
        printf("0 0 %d 1 %d %d", a, b, MAX);
    }
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+23;
char s[maxn];

int main(){
	int n;
	scanf("%d%s",&n,s);
	int cnt=0;
	for(int i=0,j=n-1;i<j;){
		if(s[i]=='W'&&s[j]=='R') cnt++,i++,j--;
		else if(s[i]=='W') j--;
		else if(s[i]=='R') i++;
		else i++,j--;
	}
	cout<<cnt;
}

Measured memory_bytes: 3880
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N];
    priority_queue<int> q;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        q.push(a);
    }
    int alice = 0;
    int bob = 0;
    int cnt = 0;
    while(!q.empty()){
        int c = q.top(); q.pop();
        if(cnt % 2 == 0) alice += c;
        else bob += c;
        cnt ++;
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using vpli = vector<pair<ll, int>>;
using mpi = unordered_map<ll, int>;

mpi bunkai(ll n) {
  mpi res;
  for (ll i = 2; i * i <= n; i++) {
    int count = 0;
    while (n % i == 0) {
      n /= i;
      count++;
    }
    if (count != 0) {
      res.emplace(i, count);
    }
  }
  if (n != 1) {
    res.emplace(n, 1);
  }
  return res;
}

ll modpow(ll a, ll p, ll m) {
  if (p == 0)
    return 1;
  if (p % 2 == 0) {
    ll d = modpow(a, p / 2, m);
    return d * d % m;
  } else {
    return a * modpow(a, p - 1, m) % m;
  }
}

ll modinv(ll a, ll m) { return modpow(a, m - 2, m); }
ll mpitoint(mpi n, ll mod) {
  ll res = 1;
  for (auto i : n) {
    res *= modpow(i.first, i.second, mod);
    res %= mod;
  }
  return res;
}

const ll MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  mpi l;
  for (auto i : a) {
    mpi tmp = bunkai(i);
    for (auto j : tmp) {
      l[j.first] = max(l[j.first], j.second);
    }
  }
  ll allinv = 0;
  for (auto i : a) {
    allinv += modinv(i, MOD);
    allinv %= MOD;
  }
  ll al = mpitoint(l, MOD);
  cout << (allinv * al) % MOD << endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define test ll t ; cin>>t; while(t--)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	ll n , m ;
	cin>> n>> m ;

	ll ans = min(n%m,abs(m-n%m));
	cout<<ans<<endl;	

	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Numeric

main :: IO ()
main = do
  xs <- fmap (map (read :: String -> Int) . words) getLine
  putStrLn $ unwords $ (map show $ [div, rem] <*> [xs!!0] <*> [xs!!1]) ++ [showFFloat (Just 8) ((fromIntegral $ xs!!0) / (fromIntegral $ xs!!1)) ""]



Measured memory_bytes: 3816