akhauriyash/Code-Regression huggingface dataset:
#pragma region template 1.2
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a) \
    REP(i, (a).size()) { cout << (a[i]) << (i == (a).size() - 1 ? "\n" : " "); }
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template
#pragma region segt 1.0
template <typename T>
struct segt
{
    using F = function<T(T, T)>;
    ll m;
    vector<T> a;
    T e;
    F f;

    segt(ll n, T e, F f) : e(e), f(f)
    {
        m = 1;
        while (m < n)
        {
            m <<= 1;
        }
        a.assign(2 * m, e);
    }

    void update(ll i, T x)
    {
        i += m;
        a[i] = x;
        while (i >>= 1)
        {
            a[i] = f(a[2 * i], a[2 * i + 1]);
        }
    }

    T query(ll i, ll j)
    {
        T l = e;
        T r = e;
        for (i += m, j += m; i < j; i >>= 1, j >>= 1)
        {
            if (i & 1)
            {
                l = f(l, a[i]);
                ++i;
            }
            if (j & 1)
            {
                --j;
                r = f(r, a[j]);
            }
        }
        return f(l, r);
    }
};
#pragma endregion segt

int main()
{
    ll N;
    cin >> N;
    vi h(N), a(N);
    REP(i, N)
    {
        cin >> h[i];
    }
    REP(i, N)
    {
        cin >> a[i];
    }

    segt<ll> dp(N + 1, 0, [](ll x, ll y) { return max(x, y); });
    REP(i, N)
    {
        dp.update(h[i], dp.query(0, h[i]) + a[i]);
    }
    ll ans = dp.query(0, N + 1);

    OUT(ans);
}

Measured memory_bytes: 7424
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
 
using namespace std;
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
int main () {
	int N;
    cin >> N;
	vector<pii> edges(N);
	vector<vi> G(N);
	int a, b;
	rep(i,N-1) {
		cin >> a >> b;
		a--; b--;
		edges[i] = make_pair(a,b);
		G[a].push_back(b);
		G[b].push_back(a);
	}

	vi coltoparent(N);
	vi visited(N,false);
	map<pii,int> C;
	queue<int> q;
	q.push(0);
	visited[0] = true;
	int K = 0;
	while(!q.empty()) {
		int v = q.front();
		q.pop();
		int cur_color = 1;
		K = max(K,(int)G[v].size());
		for (const int& u : G[v]) {
			if (visited[u]) 
				continue;
			if (cur_color == coltoparent[v]) cur_color++;
			coltoparent[u] = C[make_pair(u,v)] = C[make_pair(v,u)] = cur_color++;
			visited[u] = true;
			q.push(u);
		}
	}
	cout << K << endl;
	rep(i,N-1) {
		cout << C[edges[i]] << endl;
	}
    return 0;
}

Measured memory_bytes: 17024
#include<stdio.h>
#include<stdlib.h>
#define RMAX 10
#define CMAX 10000
int main(void){
	int R,C;
	char *Buffer=NULL;
	int Osenbei[RMAX][CMAX];
	int RSum[RMAX],CSum[CMAX];
	int count,count2,GoodSenbei=0;
	int BE_R=0;
	int Best=0,ans;
	
	//入力
	
	while(1){
		//行列サイズ入力
		scanf("%d %d%*c",&R,&C);
		if(R==0&&C==0){return 0;}//終了判定
		for(count=0;count<R;count++){//一行ずつ入力処理
			int InC=0,Charbuff=0;
			while(Charbuff=getchar()){//一文字ずつ入力
				if(Charbuff=='\n'){break;}
				else if(Charbuff=='0'){
					Osenbei[count][InC]=0;
					InC++;
				}
				else if(Charbuff=='1'){
					Osenbei[count][InC]=1;
					InC++;
				}
			}/*
			for(InC=0;InC<C;InC++){
				RSum[count]+=Osenbei[count][InC];
				CSum[InC]+=Osenbei[count][InC];
			}*/
			//for(InC=0;InC<C;InC++){
			//	printf("%d ",Osenbei[count][InC]);
			//}
		}
		//for(count2=-1;count2<C;count2++){
		//	printf("%d ",(count2==-1)?'/':CSum[count2]);
		//}
		//for(count=0;count<R;count++){
		//	printf("\n%d|",RSum[count]);
		//	for(count2=0;count2<C;count2++){
		//		printf("%d ",Osenbei[count][count2]);
		//	}
		//}puts("");
		//ここで全探索
		ans=0;
		for(count=0;count<(1<<R);count++){//全探索 裏返すのは1そうでないのは0
			int Best=0;
			for(count2=0;count2<C;count2++){
				int count3;
				int c_sum=0;
				for(count3=0;count3<R;count3++){
					c_sum+=(count&(1<<count3))?!(Osenbei[count3][count2]):Osenbei[count3][count2];
					
				}
				//printf("%d,",c_sum);
				Best+=(c_sum>(R>>1))?c_sum:R-c_sum;
				
			}
			//printf("|%d",Best);
			//puts("");
			ans=(Best>ans)?Best:ans;
		}
		printf("%d\n",ans);
	}
	return 0;

}

//次回　6/4

Measured memory_bytes: 808
list = [int(i) for i in input().split() ]

if list[0] > list [1]:
    temp = list[0]
    list[0] = list[1]
    list[1] = temp

if list[1] > list [2]:
    temp = list[1]
    list[1] = list[2]
    list[2] = temp
    
if list[0] > list [1]:
    temp = list[0]
    list[0] = list[1]
    list[1] = temp

print(str(list[0]) + " " + str(list[1]) + " " + str(list[2]))


Measured memory_bytes: 5600
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        String s = sc.next();
        
        char[] cs = s.toCharArray();
        for(int i = 0; i < cs.length; i++){
            cs[i] += n;
            if(cs[i]>90){
                cs[i]-=26;
            }
        }
        System.out.println(new String(cs));
    }
}

Measured memory_bytes: 23124
def gcd(x, y):
   while(y):
       x, y = y, x % y

   return x

def lcm(x, y):
   lcm = (x*y)//gcd(x,y)
   return lcm

cnt = int(input())
nums = [int (i) for i in input().split(" ")]
badnumber = 1
answer = 0
for i in range(0,cnt):
	badnumber = lcm(nums[i],badnumber)
badnumber=badnumber-1
for i in range(0,cnt):
	answer=answer+badnumber%nums[i]
print(answer)

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

using namespace std;

int main(){
	string input;
	int output;

	while(1){
		cin >> input;
		if("0" == input) { break; }

		output = 0;
		while(input.length()) {
			output += input.back() - '0';
			input.pop_back();
		}
		cout << output << endl;
	}

	return 0;
}


Measured memory_bytes: 3212
#define _GLIBCXX_DEBUG    //空コンテナ操作禁止　Clang環境では#define _LIBCPP_DEBUG 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for( int i=0; i<N; i++ ) cin >> d.at(i);
  
  ll sum_d = 0, sq_sum_d = 0, taikaku = 0, ans = 0;
  for( int i=0; i<N; i++ ) sum_d += d.at(i);
  for( int i=0; i<N; i++ ) taikaku += d.at(i) * d.at(i);
  ans = ( sum_d * sum_d - taikaku ) / 2;
  
  cout << ans;
  return 0;
}

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

int main(void){
    char s[100000];
    char c;
    int i, cnt;
    int len;

    scanf("%s", s);
    len = strlen(s);
    c = s[0];

    cnt = 0;
    for(i = 1; i < len; i++){
        if(c == s[i]){
            cnt++;
            if(s[i] =='0'){
                c = '1';
            }
            else{
                c = '0';
            }
        }
        else{
            c = s[i];
        }
    }

    printf("%d", cnt);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int char_to_int(char c) {
    if (c == '0')return 0;
    else if (c == '1')return 1;
    else if (c == '2')return 2;
    else if (c == '3')return 3;
    else if (c == '4')return 4;
    else if (c == '5')return 5;
    else if (c == '6')return 6;
    else if (c == '7')return 7;
    else if (c == '8')return 8;
    else if (c == '9')return 9;
}
int p[11][11];
int main() {
	string str;
	while(cin >> str){
		int x = char_to_int(str[0]);
        int y = char_to_int(str[2]);
        int s = char_to_int(str[4]);
        if(s>=1){
        	p[x][y]++;
        	if(x-1>=0)p[x-1][y]++;
        	if(x+1<=9)p[x+1][y]++;
        	if(y-1>=0)p[x][y-1]++;
        	if(y+1<=9)p[x][y+1]++;
        	if(s>=2){
        		if(x-1>=0&&y-1>=0)p[x-1][y-1]++;
        		if(x-1>=0&&y+1<=9)p[x-1][y+1]++;
        		if(x+1<=9&&y-1>=0)p[x+1][y-1]++;
        		if(x+1<=9&&y+1<=9)p[x+1][y+1]++;
        		if(s>=3){
        		 	if(x+2>=0)p[x-2][y]++;
        			if(x+2<=9)p[x+2][y]++;
        			if(y-2>=0)p[x][y-2]++;
        			if(y+2<=9)p[x][y+2]++;
        		}
        	}
        }
	}
	int sum=0,dr=0;
	for (int i = 0; i < 10; i++){
        for (int j = 0; j < 10; j++) {
            if (p[i][j] == 0)sum++;
            dr = max(dr, p[i][j]);
        }
    }
    cout<<sum<<endl<<dr<<endl;
	return 0;
}

Measured memory_bytes: 3128
#include<iostream>
#include<vector>
#include<string>
#include<queue>

using namespace std;

vector<string> field;
vector<vector<int>> dis;

int H,W;
int INF=1e9;
int dis_max=0;

class Point{
    public:
    int x,y;
    Point(){}
    Point(int x,int y):x(x),y(y) {}
};

void bfs(vector<Point> starts){
    int x,y;
    queue<Point> Q;
    vector<int> dir_x={1,0,-1,0},dir_y={0,-1,0,1};

    for(int i=0; i<starts.size(); i++){
        Q.push(starts[i]);
        dis[starts[i].y][starts[i].x]=0;
    }

    while(!Q.empty()){
        Point p=Q.front();
        Q.pop();

        x=p.x;
        y=p.y;

        for(int i=0; i<4; i++){
            int nx=x+dir_x[i],ny=y+dir_y[i];
            if(0<=nx && nx<W && 0<=ny && ny<H && dis[ny][nx]>dis[y][x]+1 && field[ny][nx]=='.'){
                Q.push(Point(nx,ny));
                dis[ny][nx]=dis[y][x]+1;
                dis_max=max(dis_max,dis[ny][nx]);                
            }
        }
    }
}

int main(){
    vector<Point> starts;


    cin>>H>>W;

    field.resize(H);
    dis.resize(H);
    for(int h=0; h<H; h++){
        dis[h].resize(W);
    }

    for(int h=0; h<H; h++){
        cin>>field[h];
        for(int w=0; w<W; w++){
            dis[h][w]=INF;
            if(field[h][w]=='#'){
                starts.push_back(Point(w,h));
            }
        }
    }

    bfs(starts);
    
    cout<<dis_max<<endl;

    return 0;
}

Measured memory_bytes: 29032
#include <bits/stdc++.h>
using namespace std;
#define fastIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
// g++ -std=c++11 -O2 -Wall *.cpp -o *
#define eps 1e-9
#define MAX 10000001
#define MOD 1000000007
#define PI 3.14159265358979323846
#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> pr_int;



int main()
{
	//freopen("input.txt", "r", stdin);
	string s;
	cin >> s;
	map<string, int> days;
	days["SUN"] = 0;
	days["MON"] = 1;
	days["TUE"] = 2;
	days["WED"] = 3;
	days["THU"] = 4;
	days["FRI"] = 5;
	days["SAT"] = 6;

	cout << 7 - days.at(s);

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9+7;

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

  int h,w,res=0;
  cin >> h >> w;
  char memo;
  for(int i=0;i<w;i++){
    for(int j=0;j<h;j++){
      cin >> memo;
      if(memo=='#') res++;
    }
  }
  if(res==h+w-1) cout <<  "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 384
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var mod = 1e9+7;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var fac=[],finv=[],invs=[];
function fset(n){
  fac.length=n+1,fac[0]=fac[1]=1;
  for(var i=2;i<=n;)fac[i]=mul(fac[i-1],i++);
  finv.length=n+1,finv[0]=finv[1]=1,finv[n]=inv(fac[n]);
  for(i=n;2<i;)finv[i-1]=mul(finv[i],i--);
  invs.length=n+1,invs[0]=invs[1]=1;
  for(i=2;i<=n;)invs[i]=mul(fac[i-1],finv[i++]);
}
function inv(b){for(var a=mod,u=0,v=1,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}
function ncr(n,r){return mul(fac[n],finv[r],finv[n-r]);}
function npr(n,r){return mul(fac[n],finv[r]);}

console.log(main());
function main(){
  var n = o.a();
  var c = o.l().sort((a,b)=>b-a);
  var ans = 0;
  fset(n+1);
  var p2 = Array(n+1);
  p2[0] = 1;
  for(var i = 1; i <= n; i++)p2[i] = p2[i-1]*2%mod;
  var pp = mul(p2[n],p2[n-1]);
  for(var i = 0; i < n; i++){
    ans += mul(c[i],pp);
    pp += mul(p2[n-1],p2[n-1]);
    pp %= mod;
  }
  return ans%mod;
}

Measured memory_bytes: 47952
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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 MOD = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}

char A[200020];
int N;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	string S; cin >> S;
	int L = 0, R = 0;
	REP(i, 2*N) {
		if (L < 0) {
			print("0");
			return 0;
		}
		if (S[i] == 'W') {
			if (L % 2 == 0) {
				A[i] = 'R';
				R++;
				L--;
			}
			else {
				A[i] = 'L';
				L++;
			}
		}
		else {
			if (L % 2 == 1) {
				A[i] = 'R';
				R++;
				L--;
			}
			else {
				A[i] = 'L';
				L++;
			}
		}
	}
	if (L != 0) {
		print(0);
		return 0;
	}
	if (A[0] != 'L' || A[2 * N - 1] != 'R') {
		print(0);
		return 0;
	}
	int ans = 1;
	L = 0, R = 0;
	REP(i, 2 * N) {
		//cout << A[i];
		if (A[i] == 'R') {
			ans *= L;
			ans %= MOD;
			L--;
		}
		else {
			L++;
		}
	}//cout << endl;
	COMinit();
	//print(ans);
	ans = mult(ans, fac[N]);
	print(ans);
}


Measured memory_bytes: 5456
N, M = [int(x) for x in input().split(" ")]
H = [int(x) for x in input().split(" ")]
lines = [[] for i in range(N)]

for _ in range(M):
    a, b = [int(x) for x in input().split(" ")]
    lines[a-1].append(b-1)
    lines[b-1].append(a-1)

judged = []
for n in range(N):
    if len(lines[n]) == 0:
        judged.append(True)
    else:
        is_good = True
        for oh in lines[n]:
            if H[oh] >= H[n]:
                is_good = False
        judged.append(is_good)
        

print(sum(judged))

Measured memory_bytes: 30308
import collections

number = int(input())
word = [input() for i in range(number)]

for i in range(number-1):
    if word[i][-1] == word[i+1][0]:
        continue
    else:
        print("No")
        exit()

word = collections.Counter(word)

if word.most_common()[0][1] != 1:
    print("No")
else:
    print("Yes")


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

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

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

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

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

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

int main() {
    int k, s;
    cin >> k >> s;

    int cnt = 0;
    rep(x, k + 1) rep(y, k + 1) {
        int z = s - (x + y);
        if (0 <= z && z <= k) {
            cnt++;
        }
    }
    cout << cnt;
    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int A,B,C,K,sum;
    
    scanf("%d %d %d %d",&A,&B,&C,&K);
    
    if (K <= A){
        sum = K;
    }else if(K > A && K <= A + B){
        sum = A;
    }else{
        sum = A - (K - A - B);
    }
    
    printf("%d\n",sum);
    
    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

ll gcd(ll x, ll y)
{
    while (y > 0)
    {
        ll tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}

int main(int argc, char const *argv[])
{
    ll n, x;
    cin >> n >> x;
    vector<ll> v(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    v.push_back(x);
    sort(ALL(v));
    ll m = LLONG_MAX;
    for (ll i = 0; i < n; i++)
    {
        ll d = v[i + 1] - v[i];
        if (m > d)
            m = d;
    }
    for (ll i = 0; i < n; i++)
    {
        ll d = v[i + 1] - v[i];
        m = gcd(m, d);
    }
    cout << m << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(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 fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
	int n;
	cin>>n;
	vvi v(n,vi(n));
	rep(i,n)rep(j,n)cin>>v[i][j];
	ll ans=0;
	rep(i,n)rep(j,n)ans+=min(v[i][j],v[j][i]);
	cout<<ans/2<<endl;
	return 0;
}



Measured memory_bytes: 3192
N,A,B=map(int,input().split())
sum,a,b=0,0,0
for i in range(1,N+1):
  b=i
  if b<10:
    a=b
  else:
    while b>=10:
      a=a+b%10
      b=b//10
      if b<10:
        a=a+b
  if B>=a>=A:
    sum=sum+i
  a=0
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int x,y;
int dp[101][301][1201];
int a[101],b[101],c[101],d[110];

int main(void){
	scanf("%d",&n);
	scanf("%d%d",&x,&y);
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
	}
	memset(dp,-1,sizeof(dp));
	dp[0][x][y+300]=0;
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=300;j++){
			for(int k=0;k<=900;k++){
				if(dp[i][j][k]>=0){
					dp[i+1][j][k]=max(dp[i][j][k],dp[i+1][j][k]);
					if(j>=a[i]){
						dp[i+1][j-a[i]][k+b[i]]=max(dp[i][j][k],dp[i+1][j-a[i]][k+b[i]]);
						if(k+b[i]>=300)ans=max(ans,dp[i+1][j-a[i]][k+b[i]]);
					}
					if(k>=c[i]){
						dp[i+1][j][k-c[i]]=max(dp[i][j][k]+d[i],dp[i+1][j][k-c[i]]);
						if(k-c[i]>=300)ans=max(ans,dp[i+1][j][k-c[i]]);
					}
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 145840
N = int(input())
alpha = [chr(ord("a") + i) for i in range(26)]


def dfs(n, s):
    if len(s) == n:
        print(s)
        return
    cnt = len(set(s))
    cnt += 1

    for a in alpha[:cnt]:
        ns = s + a
        dfs(n, ns)


dfs(N, "")


Measured memory_bytes: 4340
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        var kx = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int k = kx[0], x = kx[1];
        if (500 * k >= x) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 11092
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;
// const int imax = 100000;

int main(){
  string s;
  cin >> s;
  int r = 0;
  int b = 0;
  rep(i,s.length()){
    if(s[i]=='0') r++;
    else b++;
  }
  if(r>=b) printf("%d\n", 2*b);
  else printf("%d\n", 2*r);
  return 0;
}


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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A, B) << " " << max(A + B - N, 0) << endl;
}


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

typedef long long ll;
typedef long double ld;

using namespace std;

void INeedIt() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);		
    cout.tie(0);
}
int main() {
	INeedIt();
	int n, l;
	cin>>n>>l;
	vector <string> v;
	while (n--) {
		string s;
		cin>>s;
		v.push_back(s);
	}
	sort(v.begin(), v.end());
	for (int i=0;i<v.size();i++) {
		cout<<v[i];
	}
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def myinput():
    return map(int,readline().split())

d,g = myinput()

pc = [ list(myinput()) for _ in range(d) ]

import copy
pc2 = copy.deepcopy(pc)

# print(d,g)
# print(pc)
# print(pc2)

ls_count = []

for i in range(2**d):
    pt = 0
    count = 0
    ls = []
    # print("\ni={}".format(i))
    for j in range(d):
        if i & (2**j):
            pt = pt + 100*(j+1)*pc[j][0] + pc[j][1]
            count += pc[j][0]
        else:
            ls.append(j)
    # print(ls)
    if pt>=g:
        ls_count.append(count)
    else:
        r = g - pt
        while r>0:
            if len(ls)!=0:
                j = max(ls)
                if pc2[j][0]>=1:
                    r -= 100*(j+1)
                    pc2[j][0] -= 1
                    count += 1
                else:
                    count += float("inf")
                    break
        ls_count.append(count)
# print(ls_count)
ans = min(ls_count)
print(ans)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a)  memset((a), 0, sizeof (a))
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back

constexpr auto inf = numeric_limits<int>().max() - 1;
constexpr auto llinf = numeric_limits<ll>().max() - 1LL;

template<typename ForwardIterator>
void dump(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << *it << " ";
	}
	cout << endl;
}

template<typename ForwardIterator>
void dump_map(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << (*it).first << ":" << (*it).second << " ";
	}
	cout << endl;
}
template<typename T>
void debug(initializer_list<T> list) {
  for (auto el : list) {
    cout << el << " ";
  }
  cout << endl;
}

constexpr ll mod = ll(1e9 + 7);

ll mult(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll power(ll a, ll b) {
	ll result = 1LL;
	while (b) {
		if (b % 2LL) result = mult(result, a);
		a = mult(a, a);
		b /= 2LL;
	}
	return result;
}

ll divide(ll a, ll b) { return mult(a, power(b, mod - 2)); }

ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }

ll subtract(ll a, ll b) { return ((a - b) % mod + mod) % mod; }

int n, m, q;
struct quad {
	int a, b, c, d;
	quad(int _a, int _b, int _c, int _d) : a{_a}, b{_b}, c{_c}, d{_d} {}
};
vector<quad> quads;

int costof(vi &nums) {
	int cost = 0;
	for (auto e : quads) {
		if (nums[e.b - 1] - nums[e.a - 1] == e.c) cost += e.d;
	}
	return cost;
}

int brute(vi &nums) {
	if (sz(nums) == n) {
		return costof(nums);
	} else {
		int mxm = -2;
		repa(i, nums[sz(nums) - 1], m) {
			nums.pb(i);
			int cost = brute(nums);
			mxm = max(cost, mxm);
			nums.pop_back();
		}
		return mxm;
	}
}

void solve() {
	cin >> n >> m >> q;
	quads.clear();
	rep(i, q) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		quads.pb({a, b, c, d});
	}
	int mxm = 0;
	for (int i = 1; i <= m; i++) {
		auto nums = vi(1, i);
		mxm = max(mxm, brute(nums));
	}
	cout << mxm;
	cout << "\n";
}

#define REPEAT 0
#define CASE 0

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#if REPEAT
		int t;
		cin >> t;
		repa(i, 1, t) {
			#if CASE
				cout << "Case #" << i << ": ";
			#endif
			solve();
		}
	#else
		solve();
	#endif
	return 0;
}


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

int main(){
	int i, j, len;
	string str1, str2;
	while(cin>>str1){
		str2.erase();
		len = str1.size();
		for(i=0;i<len;i++){
			if(str1[i] == '@'){
				for(j=0;j<str1[i+1]-'0';j++){
					str2 += str1[i+2];
				}
				i+=2;
			}else{
				str2 += str1[i];
			}
		}
		cout<<str2<<endl;
	}
	return 0;
}

Measured memory_bytes: 1176
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, m) = in.readLine().split("\\s+").map(_.toInt)
    val paths = Array.fill(m) {
      in.readLine().split("\\s+").map(_.toInt) match {
        case Array(a, b) => (a - 1, b - 1)
      }
    }

    val room2room = Array.fill(n) {
      ArrayBuffer.empty[Int]
    }
    for (path <- paths) {
      room2room(path._1) += path._2
      room2room(path._2) += path._1
    }

    val signs = Array.fill(n)(Int.MinValue)

    System.err.println("=---")

    val restRooms = mutable.Queue.empty[(Int,Int)]
    restRooms.enqueue((-1, 0))

    while (restRooms.nonEmpty) {
      val (parentRoom, currentRoom) = restRooms.dequeue()
      if (signs(currentRoom) == Int.MinValue) {
        System.err.println(s"${currentRoom} sign = ${parentRoom}")
        signs(currentRoom) = parentRoom
        for (nextRoom <- room2room(currentRoom)) {
          restRooms.enqueue((currentRoom, nextRoom))
        }
      }
    }

    if (!signs.contains(Int.MinValue)) {
      out.println("Yes")
      for (i <- 1 until signs.length) {
        out.println(signs(i) + 1)
      }
    } else {
      out.println("No")
    }

    out.flush()
  }
}


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


int main() {
    string a[26] = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };
    string n;
    cin >> n;
    int place;
    for (int i = 0; i < 26; i++) {
        if (n == a[i]) {
            place = i;
        }
    }
    cout << a[place + 1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define has(c,i) (c.find() != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)

#define DBG 0
#define TR(X) ({ if(DBG) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	ll res = 0;
	ll idx = 0;
	while(idx < sz(s)){
		// calc height
		ll up = 0;
		while(idx < sz(s) && s[idx] == '<'){
			up++;
			idx++;
		}
		ll down = 0;
		while(idx < sz(s) && s[idx] == '>'){
			down++;
			idx++;
		}

		if(up > down)
			swap(up, down);

		// down >= up
		if(up > 0){
			res += ((up - 1) * up) / 2;
		}
		if(down > 0){
			res += ((down + 1) * down) / 2;
		}

		TR(up);
		TR(down);
		TR(idx);

	}

	cout << res << endl;
}


Measured memory_bytes: 1172
import sys
N = int(input())
S = str(input())
if N <= 0 or N > 100:
    sys.exit()
x = 0
max = 0
for I in S:
    if I == "I":
        x += 1
        if max < x:
            max = x
        continue
    if I == "D":
        x -=1
        continue
print(max)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);


int n;
int v[1005];

vector<vector<int>> g;

int p[1005];
int x[1005];

int f[1005]; // dp[i] := 部分木iでiと同じ色の重みの和がx[n]になるようにしたときのもう一方の色の重みの和の最小値

bool ok = 1;
int dfs(int now){
    if(!ok)return 0;
    if(f[now]<1e9+7)return f[now];
    int ret = 1e9+7;
    int size = g[now].size();
    vector<vector<int>> dp(size+1,vector<int>(5005,1e9+7));
    // dp[i][j] := i番目まで見てnowと同じ色の重みの和がjとなったときのもう一方の重みの和の最小値
    dp[0][0] = 0;
    for(int i=0;i<size;i++){
        int next = g[now][i];
        rep(j,x[now]+1){
            // next と違う色で塗った場合
            if(j>=dfs(next))chmin(dp[i+1][j],dp[i][j-dfs(next)] + x[next]);
            // next と同じ色で塗った場合
            if(j>=x[next])chmin(dp[i+1][j],dp[i][j-x[next]] + dfs(next));
        }
    }
    rep(j,x[now]+1)ret = min(ret,dp[size][j]);
    if(ret>=1e9+7){
        ok = 0;
        return 1e9+7;
    }
    return f[now] = ret;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> n;
    g.resize(n);
    rep(i,n-1){
        int a = i+1;
        int b;cin >> b;b--;
        g[b].push_back(a);
    }
    rep(i,n)cin >> x[i];
    rep(i,1001)f[i] = 1e9+7;
    if(dfs(0)<1e9+7 && ok)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 20980
from collections import Counter as C
n=int(input())
a=list(map(int,input().split()))
b=C(a)
s=sum(i*(i-1)//2for i in b.values())
t={}
for i,j in b.items():
    t[i]=s-(j*(j-1)//2-(j-1)*(j-2)//2)
for i in a:
    print(t[i])

Measured memory_bytes: 34952
while 1:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        exit()
    for i in range(h):
        for j in range(w):
            if j == w - 1:
                if (i + j) % 2 == 0:
                    print('#')
                else:
                    print('.')
            else:
                if (i+j) % 2 == 0:
                    print('#', end='')
                else:
                    print('.', end='')
    print()



Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int  A, B, C , X ;
  cin >> A >> B >> C >> X;
  int count = 0;
  for(int i =0 ; i < A+1; i++){
    for(int j = 0; j< B+1; j++){
      for(int k = 0; k< C+1;k++){
        int p = 500* i;
        int q = 100* j;
        int r = 50* k;
        if(p + q + r == X){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

bool check(const string &l, const string &r) {
	return l.size() == r.size() ? l < r : l.size() < r.size();
}
int main() {
	while (1) {
		int W, H; cin >> W >> H;
		if (!W)break;
		vector<string>sts;
		for (int i = 0; i < H; ++i) {
			string st; cin >> st;
			sts.push_back(st);
		}
		vector<vector<string>>longs(H,vector<string>(W));
		for (int x = 0; x < W; ++x) {
			for (int y = 0; y < H; ++y) {
				if (isdigit(sts[y][x])) {
					longs[y][x] = sts[y][x];
				}
			}
		}
		for (int x = 0; x < W; ++x) {
			for (int y = 0; y < H; ++y) {
				if (isdigit(sts[y][x])) {
					if (x > 0) {
						longs[y][x] = check(longs[y][x], longs[y][x - 1] + sts[y][x]) ?  longs[y][x - 1] + sts[y][x]: longs[y][x] ;
					}
					if (y > 0) {
						longs[y][x] = check(longs[y][x], longs[y-1][x] + sts[y][x]) ? longs[y - 1][x] + sts[y][x]: longs[y][x];
					}
					if (longs[y][x][0] == '0')longs[y][x] = longs[y][x].substr(1, longs[y][x].size() - 1);
				}
			}
		}
		string ans;
		for (int x = 0; x < W; ++x) {
			for (int y = 0; y < H; ++y) {
				ans = check(ans, longs[y][x]) ? longs[y][x]: ans;
					
			}
		}

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

Measured memory_bytes: 3312
#include <iostream>
#define llint long long

using namespace std;

llint n;
llint m, e, a;

int main(void)
{
	while(1){
		cin >> n;
		if(n == 0) break;
		
		a = 0;
		for(int i = 51; i >= 0; i--){
			char c;
			cin >> c;
			a |= (llint)(c - '0') << i;
		}
		a |= 1LL<<52;
		m = a, e = 0;
		
		while(n > 0){
			llint ub = 1LL << (e+1), lb = 0, mid;
			while(ub-lb>1){
				mid = (ub+lb)/2;
				if(m + a*mid >= 1LL<<53) ub = mid;
				else lb = mid;
			}
			//cout << "ub" << ub << endl;
			if(ub <= n){
				n -= ub;
				m += a * ub;
				if(m >= 1LL<<53){
					m >>= 1;
					a >>= 1;
					e++;
				}
				//for(int i = 52; i >= 0; i--) cout << ((m>>i)&1); cout << endl;
			}
			else{
				m += a * n;
				n = 0;
			}
			//cout << n << endl;
		}
		//cout << e << endl;
		for(int i = 11; i >= 0; i--) cout << ((e>>i)&1);
		for(int i = 51; i >= 0; i--) cout << ((m>>i)&1);
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3092
#include<iostream>
    #include <bits/stdc++.h>
    using namespace std;
    int main(){
        int N,M;
        cin >> N >> M;
        vector<int> vec(2*M);
        vector<int> ans(N,0);
        for(int i=0;i<2*M;i++){
            cin >>vec.at(i);
        }
        for(int i=1;i<N+1;i++){
            for(int k=0;k<2*M;k++){
                if(vec[k]==i) ++ans[i-1];
            }
            cout << ans[i-1] << endl;
        }


    }

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

using namespace std;
typedef long long ll;

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

    int ans = 100;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0)
            ans = min(ans, max((int)log10(i) + 1, (int)log10(N / i) + 1));
    }
    cout << ans << endl;

    return 0;    
}

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

int main(){
    ll n,m; cin >> n >> m;
    if(n==1 && m==1) cout << 1 << endl;
    else if(n==1 || m==1) cout << n+m-3 << endl;
    else cout << (n-2) * (m-2) << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

int main() {
	long long a, b, c, k;
	cin >> a >> b >> c >> k;

	long long tmp = min(a, k);
	k -= tmp;
	long long ans = tmp;

	tmp = min(k, b);
	k -= tmp;

	tmp = min(k, c);
	ans -= tmp;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int N, K, P[200005]; 
double sum, avg[200005];

int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++){
        cin >> P[i];
    }
    for(int i=0; i<N; i++){
        avg[i] = P[i]*(P[i] + 1) / (double)(2*P[i]);
    }

   
    double max = 0;
    for(int i=0; i<K; i++){
        sum += avg[i];
    }
    
    max = sum;
    for(int i=K; i<N; i++){
        sum -= avg[i-K];
        sum += avg[i];
        if (sum > max){
            max = sum;
        } 
    }

    cout << fixed << setprecision(8) << max <<"\n";
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, ans = 0, pre = 0; cin >> n;
    vector<string> s(2);
    cin >> s[0] >> s[1];

    // ブロックの置き方は2通りしかないため、左から順に処理していく
    // [置き方1] 縦に1個（2*1マス）
    //　最も左なら3通り、置き方1の後なら2通り、置き方2の後なら1通り
    // [置き方2] 横に2個（2*2マス）
    //　最も左なら6通り、置き方1の後なら2通り、置き方2の後なら3通り
    for(ll i=0; i<n; i++){
        // 置き方1の場合
        if(s[0][i] == s[1][i]){
            // 最も左の場合
            if(i == 0) ans = 3;
            // 置き方1の後の場合
            else if(pre == 1) ans = (ans*2)%MODV;
            // 置き方2の後の場合
            else ans = ans*1;
            // 置き方1をしたというフラグ
            pre = 1;
        }
        // 置き方2の場合
        else{
            // 最も左の場合
            if(i == 0) ans = 6;
            // 置き方1の後の場合
            else if(pre == 1) ans = (ans*2)%MODV;
            // 置き方2の後の場合
            else ans = (ans*3)%MODV;
            // 置き方1をしたというフラグ
            pre = 2;
            // 2個分読み取るのでその分iを増やす
            i++;
        }
    }

    // 答えの出力
    cout << ans << endl; 
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    int N, K,R,S,P; cin >> N >> K>>R>>S>>P;
    string T; cin >> T;
    int ans = 0;
    rep(i, T.size()) {
        if (i >= K) {
            if (T.at(i) == T.at(i - K)) {
                T.at(i) = 'a';
                continue;
            }
        }
        if (T.at(i) == 'r')ans += P;
        if (T.at(i) == 's')ans += R;
        if (T.at(i) == 'p')ans += S;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3696
n = int(input())
g = [[-1]*n for _ in range(n)]

import fractions

for i in range(n):
  for j in range(n):
    g[i][j] = fractions.gcd(i+1, j+1)

ans = 0
for i in range(n):
  for j in range(n):
    for k in range(n):
      a, b, c = i+1, j+1, k+1
      ab_gcd = g[a-1][b-1]
      abc_gcd = g[ab_gcd-1][c-1]
      ans += abc_gcd
      
print(ans)

Measured memory_bytes: 76056
raws, columns = map(int, input().strip().split())
a = []
for i in range(raws):
    a.append(list(map(int, input().strip().split())))
for i in range(raws):
    a[i].append(sum(a[i]))
a.append([sum(i) for i in zip(*a)])
for r in a:
    print(' '.join(str(x) for x in r))

Measured memory_bytes: 7724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{	
	int k;
	string s;
	map<string,int>m;
	cin>>s>>k;
	for(int i=1;i<=5;i++)
	{
		if(s.length()<i)continue;
		for(int j=0;j<=s.length()-i;j++)
		{
			string t=s.substr(j,i);
			m[t]=1;
		}
	}
	auto itr=m.begin();
	itr=next(itr,k-1);
	cout<<itr->first<<endl;
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main(){
  int W, H;
  cin >> W >> H;
  vector<int> p(W);
  for (int i = 0; i < W; i++){
    cin >> p[i];
  }
  vector<int> q(H);
  for (int i = 0; i < H; i++){
    cin >> q[i];
  }
  vector<pair<int, char>> C;
  for (int i = 0; i < W; i++){
    C.push_back(make_pair(p[i], 'p'));
  }
  for (int i = 0; i < H; i++){
    C.push_back(make_pair(q[i], 'q'));
  }
  sort(C.begin(), C.end());
  int N = C.size();
  long long ans = 0;
  for (int i = 0; i < N; i++){
    if (C[i].second == 'p'){
      ans += (long long) C[i].first * (H + 1);
      W--;
    } else {
      ans += (long long) C[i].first * (W + 1);
      H--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;
  set<string> s;
  cin >> n;
  for(int i = 0; i < n; i++){
    string ss;
    cin >> ss;
    s.insert(ss);
  }

  

  cout << s.size() << endl;


}

Measured memory_bytes: 19228
#include <stdio.h>
int main(){

    char c1[4];
    char c2[4];
    char c3[4];

    scanf("%s",c1);
    scanf("%s",c2);
    scanf("%s",c3);

    char output[4] = {c1[0],c2[1],c3[2],'\0'};
    printf("%s\n",output);

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

ll N;
ll K;


int main(){
  cin>>N>>K;
  
  ll ab=2*N*(K+K+2*N-1)/2;
  ll c=N*(K+2*N+K+3*N-1)/2;
  if(ab>c){
      cout<<-1<<endl;
      return 0;
  }

  vector<ll> A(N),B(N),C(N);
  int ind=0;
  ll p=N+N/2;
  for(ll i=0;i<N;i++){
      if(K+i+p<K+2*N){
          A[i]=K+i;
          B[i]=K+p+i;
      }else{
          A[i]=K+i;
          B[i]=K+N+ind;
          ind++;
      }
      C[i]=A[i]+B[i];
  }

  vector<pair<ll,int>> v;
  rep(i,N) v.push_back(mkp(C[i],i));
  sort(v.begin(),v.end());
  for(int i=0;i<N;i++){
      int now=v[i].second;
      cout<<A[now]<<" "<<B[now]<<" "<<K+2*N+i<<endl;
  }

  return 0;
}


Measured memory_bytes: 6256
#include<stdio.h>
long long MIN(long long a,long long b){return a<b?a:b;}
int main(){
  long long n,a,b,s=0;
  scanf("%lld %lld %lld",&n,&a,&b);
  s+=n/(a+b)*a;
  s+=MIN(n%(a+b),a);
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 128