akhauriyash/Code-Regression huggingface dataset:
L, R = map(int, input().split())
mod = 2019

l = L // mod
r = R // mod

if l != r:
    print(0)
else:
    l_ = L % mod
    r_ = R % mod
    ans = 2019
    for i in range(l_, r_):
        for j in range(i+1, r_+1):
            a = i * j % mod
            ans = min(ans, a)
            if ans == 0:
                break
        if ans == 0:
            break
    print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n,m;
const int MAX_N=1<<17;
const ll INF=(1ll<<31)-1;
class Lz_segtree{
public:
    int n;
    ll e=0;
    ll init=0;
    vector<ll> dat,lz;
    Lz_segtree(int n_):n(n_){
        n=1;
        while(n<n_) n*=2;
        dat.resize(n*2,e);
        lz.resize(n*2,init);
    }
    void update_f(ll& d,ll x){
        d+=x;
    }
    ll dat_propergate(ll l,ll r){
        return max(l,r);
    }
    void lz_propergate(ll& l,ll& r,ll x){
        l+=x,r+=x;
    }
    void eval(int len,int k){
        if(lz[k]!=init) update_f(dat[k],lz[k]);
        if(len>1){//flag check!
            if(lz[k]!=init)lz_propergate(lz[k*2+1],lz[k*2+2],lz[k]);
        }
        lz[k]=init;
    }
    //range [a,b)
    void update(int a,int b,int k,int l,int r,ll x){
        eval(r-l,k);
        if(r<=a||b<=l) return;
        if(a<=l&&r<=b){
            update_f(lz[k],x);
            eval(r-l,k);
        }
        else{
            update(a,b,k*2+1,l,(l+r)/2,x);
            update(a,b,k*2+2,(l+r)/2,r,x);
            dat[k]=dat_propergate(dat[2*k+1],dat[2*k+2]);
        }
    }
    //range [a,b)
    ll query(int a,int b,int k,int l,int r){
        eval(r-l,k);
        if(r<=a||b<=l) return e;
        if(a<=l&&r<=b) return dat[k];
        else{
            ll vl=query(a,b,k*2+1,l,(l+r)/2);
            ll vr=query(a,b,k*2+2,(l+r)/2,r);
            return dat_propergate(vl,vr);
        }
    }
    void update(int a,int b,ll x){
        return update(a,b,0,0,n,x);
    }
    ll query(int a,int b){
        return query(a,b,0,0,n);
    }
};

vector<ll> l[200001],a[200001];
int main(){
    cin>>n>>m;
    int li,ri,ai;
    rep(i,m){
        cin>>li>>ri>>ai;
        --li,--ri;
        l[ri].pb(li);
        a[ri].pb(ai);
    }
    Lz_segtree seg(n+1);
    rep(i,n){
        ll nx=seg.query(0,i);
        seg.update(i,i+1,nx);
        int sz=l[i].size();
        rep(j,sz){
            seg.update(l[i][j],i+1,a[i][j]);
        }
    }
    cout<<seg.query(0,n)<<endl;
    return 0;
}


Measured memory_bytes: 30336
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main()
	{
		long N = GetLong();
		for(long h = 1; h <= 3500; h++)
		{
			for(long n = 1; n <= 3500; n++)
			{
				long denominator = 4L * h * n - N * (h + n);
				if(denominator <= 0)
					continue;

				long numerator = N * h * n;
				if(numerator % denominator != 0)
					continue;

				long w = numerator / denominator;
				Console.WriteLine($"{h} {n} {w}");
				return;
			}
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

typedef long long llint;
typedef pair<int, int> pii;

#define mp make_pair
#define pb push_back
#define X first
#define Y second

//#define DEBUG
#ifdef DEBUG
#define TRACE(x) cout<<#x<<" = "<<x<<endl
#else
#define TRACE(x) ;
#endif // DEBUG



int main() {
    string s;
    cin >> s;
    int cnt[30] = {0};
    for (int i = 0; i < s.size(); i++) {
        cnt[s[i] - 'a']++;
    }
    bool ok = true;
    for (int i = 0; i < 30; i++) {
        if (cnt[i] & 1)
            ok = false;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int s = Integer.parseInt(br.readLine());

        int h = s / 3600;

        int m = (s - h * 3600) / 60;

        s = s - (h * 3600) - (m * 60);

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


Measured memory_bytes: 24352
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
int a[1000][1000], dp[1000][1000];
int main() {
	int h, w, n;
	while (scanf("%d%d%d", &h, &w, &n), h) {
		rep(i, h)rep(j, w) {
			getchar_unlocked(); a[i][j] = getchar_unlocked() - '0';
		}
		memset(dp, 0, sizeof(dp));
		dp[0][0] = n - 1;
		rep(i, h)rep(j, w) {
			if (i) {
				if (a[i - 1][j])dp[i][j] += dp[i - 1][j] >> 1;
				else dp[i][j] += (dp[i - 1][j] + 1) >> 1;
			}
			if (j) {
				if (a[i][j - 1])dp[i][j] += (dp[i][j - 1] + 1) >> 1;
				else dp[i][j] += dp[i][j - 1] >> 1;
			}
		}
		int x = 0, y = 0;
		while (x < h&&y < w) {
			if (dp[x][y] & 1)a[x][y] = !a[x][y];
			if (a[x][y])y++;
			else x++;
		}
		printf("%d %d\n", x + 1, y + 1);
	}
}

Measured memory_bytes: 10916
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007
 
ll n,x,y,i,a[2005][2005],b[2005],j;

int main()
{
    
    Fast;
    cin>>n>>x>>y;
    for(i=1;i<=n-1;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            a[i][j]=j-i;
        }
    }
    for(j=y;j<=n;j++)
    {
        a[x][j]=j-y+1;
    }
    for(i=x-1;i>=1;i--)
    {
        for(j=y;j<=n;j++)
        {
            a[i][j]=a[i+1][j]+1;
        }
    }
    for(i=x;i>=1;i--)
    {
        for(j=x+1;j<=y-1;j++)
        {
            a[i][j]=min(a[i][j],x-i+1+y-j);
        }
    }
    
    for(i=x+1;i<=y-1;i++)
    {
        for(j=i+1;j<=y-1;j++)
        {
            a[i][j]=min(a[i][j],i-x+1+y-j);
        }
    }
    for(i=x+1;i<=y-1;i++)
    {
        for(j=y;j<=n;j++)
        {
            a[i][j]=min(a[i][j],i-x+1+j-y);
        }
    }
    for(i=1;i<=n-1;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            //cout<<a[i][j]<<" ";
            b[a[i][j]]++;
        }
//        cout<<endl;
    }
    for(i=1;i<=n-1;i++)
        cout<<b[i]<<endl;
}

Measured memory_bytes: 31104
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n";
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;
int dp[maxn][3];
int a[maxn],b[maxn],c[maxn];
int main(){
	migmig;
	int n;
	cin>>n;
	
	for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(int i=1;i<n;i++){
		dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
		dp[i][2]=max(dp[i-1][1]+c[i],dp[i-1][0]+c[i]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int N,i;
	cin>>N;
	i=N%10;
	if((i==2)||(i==4)||(i==5)||(i==7)||(i==9))
	cout<<"hon";
	else if((i==3))
	cout<<"bon";
	else
	cout<<"pon";
	return 0;
}

Measured memory_bytes: 3592
s = input();l = [];h=[]
n=len(s)
for i in range(n):
    l += s[i] 
    
h += l 
cnt1=0;cnt2=0

if l[0]=='1':
    l[0]='0'
    cnt1 += 1
for i in range(n-1):
    if l[i]==l[i+1]:
        if l[i]=='0':
            l[i+1]='1'
        else:
            l[i+1]='0'
        cnt1 += 1

if h[0] == '0':
    h[0] = '1'
    cnt2 += 1
for j in range(n-1):
    if h[j]==h[j+1]:
        if h[j]=='0':
            h[j+1]='1'
        else:
            h[j+1]='0'
        cnt2 += 1
print(min(cnt1,cnt2))

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

int main(){
    int n, m;
    int a[100], b[100];
    while(true){
        scanf("%d%d", &n, &m);
        if(n == 0 && m == 0) break;
        int sa = 0, sb = 0;
        for(int i = 0; i < n; i++){
            scanf("%d", a + i);
            sa += a[i];
        }
        for(int i = 0; i < m; i++){
            scanf("%d", b + i);
            sb += b[i];
        }
        bool found = false;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(2 * (a[i] - b[j]) == sa - sb){
                    printf("%d %d\n", a[i], b[j]);
                    found = true;
                    break;
                }
            }
            if(found) break;
        }
        if(!found){
            puts("-1");
        }
    }
    return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
  int main()
{
  char s[4];
  cin>>s;
  int i,flag=1;
  char c=s[0];
  for(i=0;i<3;++i)
  {	if(s[i]!=c)
    {
      flag=0;
      break;
    }
}
  if(flag==1)
    cout<<"No";
  else
    cout<<"Yes";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {


    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String s = sc.nextLine();
            map.put(s, map.getOrDefault(s, 0)+1);
        }
        //AC x 3
        //WA x 1
        //TLE x 2
        //RE x 0
        System.out.println("AC x "+map.getOrDefault("AC", 0));
        System.out.println("WA x "+map.getOrDefault("WA", 0));
        System.out.println("TLE x "+map.getOrDefault("TLE", 0));
        System.out.println("RE x "+map.getOrDefault("RE", 0));

    }

    private static boolean ok(int k) {
        while (k>0) {
            int c = k%10;
            if (c!=4&&c!=7) return false;
            k/=10;
        }
        return true;
    }

    // 1 2 3 4 5 6
    // x * 2 == 10



    private static boolean preSum(int[] nums, int target) {
        int cur = 0;
        Set<Integer> set = new HashSet<>();
        set.add(0);
        for (int i = 0; i < nums.length; i++) {
            cur += nums[i];
            if (set.contains(cur-target)) {
                System.out.println(cur-target);
                return true;
            }
            set.add(cur);
        }
        return false;
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}



Measured memory_bytes: 44804
//漸化式:dp[i][j][k]=Σdp[i+1][k][0~2] (j!=k)
//                  Σdp[i+1][k][0~2のj以外]
//      dp[n-2][][]=1
#include <stdio.h>
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int a,b,plan[100],i,j,k,l,dp[100][3][3],ans=0;//dp[a][b][c]はplan[a]にb,plan[a+1]にcがきたときの,a+2番目以降の場合の数
    for (i=0; i<n; i++) {
        plan[i]=-1;
    }
    for (i=0; i<m; i++) {
        scanf("%d%d",&a,&b);
        plan[a-1]=b-1;
    }
    for (i=0; i<n; i++) {
        for (j=0; j<3; j++) {
            for (k=0; k<3; k++) {
                dp[i][j][k]=0;
                if (i==n-3&&(plan[i]==j||plan[i]==-1)&&(plan[i+1]==k||plan[i+1]==-1)) {
                    if (j==k) {
                        dp[i][j][k]=2;
                        if (plan[i+2]!=-1) {
                            if (plan[i+2]==j) {
                                dp[i][j][k]=0;
                            }else{
                                dp[i][j][k]=1;
                            }
                        }
                    }else if (plan[i+2]!=-1){
                        dp[i][j][k]=1;
                    }else{
                        dp[i][j][k]=3;
                    }
                }
            }
        }
    }
    
    for (i=n-4; i>=0; i--) {
        for (j=0; j<3; j++) {
            if (plan[i]!=j&&plan[i]!=-1) {
                continue;
            }
            for (k=0; k<3; k++) {
                if (plan[i+1]!=k&&plan[i+1]!=-1) {
                    continue;
                }
                for (l=0; l<3; l++) {
                    dp[i][j][k]+=dp[i+1][k][l];
                }
                if (j==k) {
                    dp[i][j][k]-=dp[i+1][k][j];
                }
                if (dp[i][j][k]>=10000) {
                    dp[i][j][k]%=10000;
                }
            }
        }
    }
    for (i=0; i<3; i++) {
        for (j=0; j<3; j++) {
            ans+=dp[0][i][j];
            if (ans>=10000) {
                ans%=10000;
            }
        }
    }
    printf("%d\n",ans%10000);
    return 0;
}

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

using namespace std;

int main(void)
{
  int N;
  cin >> N;
  vector<int> vi(N);
  for(int& x : vi){
    cin >> x;
  }
  int max = *max_element(vi.begin(), vi.end());
  int sum = accumulate(vi.begin(), vi.end(), 0);
  cout << sum - max / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
//D
#include<iostream>
using namespace std;
int main(){
	int h,w;
	while(true){
	cin>>h>>w;
	if(h==0&&w==0)break;
	int a=999,b=999;
	for(int i=1;i<=150;i++){
		for(int j=i+1;j<=150;j++){//(h,w)と(i,j)の比較
			if((h*h+w*w<j*j+i*i||h*h+w*w==j*j+i*i&&h<i)&&(a*a+b*b>j*j+i*i||i*i+j*j==a*a+b*b&&b>i)){
			a=j,b=i;
			}
		}
	}
	cout<<b<<" "<<a<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
atoz = [chr(i) for i in range(97,97+26)]

a,b = inpl()
print((b-a)*(b-a+1)//2-b)


Measured memory_bytes: 4212
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	int a, b; cin >> a >> b;
	cout << 6 - a - b;

	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

#define INF 1e9

void dfs(int x, vector<bool>& visited, vector<int>& from, vector<int> &to) {
    if(visited[x]) return;
    visited[x] = true;
    for(int i=0; i < from.size(); i++) {
        if(from[i] == x)
            dfs(to[i], visited, from ,to);

    }
}

int main() {
    int n, m, p;
    cin >> n >> m >> p;
    vector<int> a(m), b(m), c(m);
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        c[i] = - (c[i] - p);
    }

    map<int, vector<int>> edge;
    for(int i = 0; i < m; i++) {
        edge[a[i]].push_back(b[i]);
    }

    vector<bool> visited(n, false);
    dfs(n-1, visited, b, a);
    if(!visited[n-1]){
        cout << -1 << endl;
        return 0;
    }

    vector<ll> d(n, INF);
    d[0] = 0;

    for(int i=0; i < n-1; i++) {
        for(int j=0; j < m; j++) {
            int from = a[j];
            int to = b[j];
            int cost = c[j];
            if(d[from] != INF && d[to] > d[from] + ll(cost)) {
                d[to] = d[from] + ll(cost);
            }
        }
    }

    for(int j=0; j<m ; j++) {
        int from = a[j];
        int to = b[j];
        int cost = c[j];
        if(d[from] != INF && visited[to] && d[to] > d[from] + ll(cost)) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << max(-d[n-1], ll(0)) << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
    int m,d; cin>>m>>d;
    int cnt=0;

    rep2(i,1,m+1)rep2(j,1,d+1)
    {
        if(j<21)continue;
        int d1=j%10,d10=j/10;
        if(d1*d10==i)
        {
            if(d1>=2)cnt++;
        }
    }
    cout<<cnt<<endl;

}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class ABBQEasy {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[(n * 2)];
            for (int i = 0; i < n * 2; i++) a[i] = in.nextInt();
            Arrays.sort(a);
            long s = 0;
            for (int i = 0; i < n * 2; i++) {
                if (i % 2 == 1) continue;
                else {
                    s += Math.min(a[i], a[i + 1]);
                }
            }
            out.println(s);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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


int main(){
    int A, B, count = 0, remainder;
    cin >> A >> B;
    int dif = B-A;
    for(int i = 0; i <= dif; i++){
        int temp = A;
        int reverse = 0;
        while(temp != 0){
            remainder = temp % 10;
            reverse = (reverse * 10) + remainder;
            temp = temp / 10;
        }
        if(reverse == A){
            count++;
        }
        A++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
# test
class BIT:
  ini = 0
  def __init__(s, num):
    s.N = 1
    while s.N <= num:
      s.N *= 2
    s.T = [s.ini] * s.N
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, n): # xにnを加える
    k = x + 1
    s.T[k - 1] += n
    k += k & -k
    while k <= s.N:
      s.T[k - 1] += n
      k += k & -k
  def getV(s, x): # xまでの和(x含む)
    if x < 0: return 0
    x += 1
    ans = s.T[x - 1]
    x -= x & -x
    while x != 0:
      ans += s.T[x - 1]
      x -= x & -x
    return ans

N, Q = list(map(int, input().split()))
a = list(map(int, input().split()))
Query = [list(map(int, input().split())) for _ in range(Q)]
  
bit = BIT(N)
bit.set(a)

for q in Query:
  if q[0] == 0:
    _, p, x = q
    bit.update(p, x)
  else:
    _, l, r = q
    print(bit.getV(r - 1) - bit.getV(l - 1))


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

//オーダーやばそう、tn?

int main(){
  int n;
  cin >> n;
  int w[n];
  rep(i,n){cin>>w[i];}
  
  int ABS = 0; //s1とs2の差(絶対値)
  rep(t,n){
    int s1=0,s2=0;
    for(int i = 0; i < t; i++){ //区切りの前半
      s1 += w[i];
    }
    
    for(int j = t; j < n; j++){ //区切りの後半
      s2 += w[j];
    }
    if(t==0){
      ABS = abs(s1-s2);
    }else{
      if(ABS > abs(s1-s2)) ABS = abs(s1-s2);
    }
  }
  cout << ABS << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	int n;
	double x1,y1,x2,y2,x3,y3,xp,yp,r;
	double a,b,c,d,e,f,L,M,N;
	
	cin>>n;
	for (int i=0; i<n; i++) {
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
		
		a=x1-x2;
		b=y1-y2;
		c=-1*(x1*x1+y1*y1)+(x2*x2+y2*y2);
		d=x1-x3;
		e=y1-y3;
		f=-1*(x1*x1+y1*y1)+(x3*x3+y3*y3);
		
		if (a==0) {
			M=c/b;
			L=(f-e*M)/d;
		}
		else{
		M=(c*d-a*f)/(b*d-a*e);//
		L=(c-b*M)/a;
		}
		N=-L*x1-M*y1-x1*x1-y1*y1;
		
		xp=-1*(L/2);
		yp=-1*(M/2);
		r=sqrt(-1*N+(L*L)/4+(M*M)/4);
			
		printf("%.3f %.3f %.3f\n",xp,yp,r);
	}
	
	return 0;	
}

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

using namespace std;

const int N = 1e5 + 10;

int n, m, cnt, d[N << 3], v[N << 3], sum, ans;

map <int, int> mp[N << 3];

vector < pair <int, int> > e[N << 3];

queue <int> q;

void init ()
{
	scanf ( "%d%d" , &n, &m);
	cnt = n;
	for (int i = 1; i <= m; ++ i)
	{
		int p, q, c;
		scanf ( "%d%d%d" ,&p, &q, &c);
		if ( !mp[p].count (c) )
		{
			mp[p][c] = ++cnt;
			e[p].push_back ( make_pair (cnt, 1) );
			e[cnt].push_back ( make_pair (p, 1) );
		}
		if ( !mp[q].count (c) )
		{
			mp[q][c] = ++cnt;
			e[q].push_back ( make_pair (cnt, 1) );
			e[cnt].push_back ( make_pair (q, 1) );
		}
		e[ mp[p][c] ].push_back ( make_pair (mp[q][c], 0) );
		e[ mp[q][c] ].push_back ( make_pair (mp[p][c], 0) );
	}
}

void work ()
{
	memset ( d, 0x3f, sizeof (d) );
	d[1] = 0, v[1] = 1;
	q.push (1);
	for ( ; !q.empty (); )
	{
		int x = q.front ();
		q.pop ();
		for (int i = 0; i < e[x].size (); ++ i)
		{
			int y = e[x][i].first;
			if (d[y] > d[x] + e[x][i].second)
			{
				d[y] = d[x] + e[x][i].second;
				if (!v[y])
				{
					v[y] = 1;
					q.push (y);
				}
			}
		}
		v[x] = 0;
	}
	if (d[n] == 0x3f3f3f3f) sum = -1;
	else sum = d[n] / 2;
}

void prin ()
{
	printf ( "%d" , sum);
}

int main ()
{
	init ();
	work ();
	prin ();
	return 0;
}

Measured memory_bytes: 99968
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

n,c,k = MI()
t = sorted([I() for _ in range(n)])

cnt = 1
b = 1
bt = t[0]+k
for i in range(1, n):
    if cnt == c or t[i] > bt:
        b += 1
        bt = t[i]+k
        cnt = 1
    else:
        cnt += 1
print(b)


Measured memory_bytes: 8276
n = int(input())
a_list = [int(x) for x in input().split()]
count = 0
ans = 0
m = 10 ** 9
for i in range(n):
    if a_list[i] < 0:
        a_list[i] *= -1
        count += 1
    ans += a_list[i]
    if a_list[i] < m:
        m = a_list[i]
if count % 2 == 1:
    ans -= m * 2
print(ans)

Measured memory_bytes: 20040
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    int n;
    int max = 0;
    int min = 1000;
    int cost = 10000000;
    
    cin >> n;
    
    int array[n];
    
    for(int i=0;i<n;i++){
        cin >> array[i];
        
        if(array[i] > max){
            max = array[i];
        }
        
        if(array[i]　< min ){
            min = array[i];
        }
    }
    
    for(int i = min;i<=max;i++){
        int tmpcost=0;
        for(int j=0;j<n;j++){
            if(array[j] != i){
                tmpcost += pow((array[j] - i),2);
            }
        }
        if(tmpcost < cost){
            cost = tmpcost;
        }
    }
    
    cout << cost << endl;
    
    return 0;
    
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++)
    {
        cin >> A.at(i);
    }
    int count=0;
    int max=0;
    for(int i=0; i<N-1; i++)
    {
        if(A.at(i)>=A.at(i+1))
        {
            count++;
        }
        if(max<count)
        {
            max=count;
        }
        if(A.at(i)<A.at(i+1))
        {
            count=0;
        }

    }
    cout << max << endl;
}

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

Measured memory_bytes: 600
#include <iostream>
#include <map>
#include <algorithm>
#include <cstdint>

typedef std::uint32_t WeightType;
typedef std::uint32_t ValueType;
typedef std::map<WeightType, ValueType> DPMap;

class LessSecond {
public:
	bool operator()(DPMap::value_type lhs, DPMap::value_type rhs) const
	{ return lhs.second < rhs.second; }
};

int main()
{
	std::uint32_t count = 0;
	WeightType W;
	for (std::cin >> W; W != 0; std::cin >> W) {
		DPMap dp_map;
		dp_map.insert(DPMap::value_type(0u, 0u));

		std::uint16_t n;
		std::cin >> n;

		for (std::uint32_t i = 0; i < n; ++i) {
			ValueType value;
			WeightType weight;
			(std::cin >> value).ignore() >> weight;

			for (auto it = dp_map.rbegin(); it != dp_map.rend(); ++it) {
				WeightType const new_weight = it->first + weight;
				ValueType const new_value = it->second + value;
				if (new_weight <= W) {
					auto insert_pos = dp_map.lower_bound(new_weight);
					if (insert_pos != end(dp_map) and
							not dp_map.key_comp()(new_weight, insert_pos->first)) {
						insert_pos->second = std::max(insert_pos->second, new_value);
					}
					else {
						dp_map.insert(insert_pos, DPMap::value_type(new_weight, new_value));
					}
				}
			}
		}

		auto max_pos = std::max_element(begin(dp_map), end(dp_map), LessSecond());
		std::cout << "Case " << ++count << ":\n"
				  << max_pos->second << "\n"
				  << max_pos->first << std::endl;
	}
}

Measured memory_bytes: 1232
n, k= map(int,input().split())
x = list(map(int, input().split()))
if 0 not in x:
    k += 1
    x.append(0)
    x = sorted(x)
x = [abs(i) for i in x]

orig = x.index(0)

ans = float("inf")
for i in range(k):
    f = orig + i
    s = orig + i - k + 1
    if (s >= 0) and (f <= len(x)-1):
        temp1 = x[s]
        temp2 = x[f]
        ans = min([ans, 2*temp1+temp2, temp1+2*temp2])

print(ans)

Measured memory_bytes: 14384
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str, T: str):
    ds = {}
    dt = {}
    cs = []
    ct = []
    for s, t in zip(S, T):
        if s in ds:
            cs.append(ds[s])
        else:
            cc = len(ds) + 1
            ds[s] = cc
            cs.append(cc)
        if t in dt:
            ct.append(dt[t])
        else:
            cc = len(dt) + 1
            dt[t] = cc
            ct.append(cc)
    return YES if cs == ct else NO


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    result = solve(S, T)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9096
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y,z,k = inpl()
a = inpl()
b = inpl()
c = inpl()
ab = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)
A = min(x*y,k)
res = []
# print(ab,c)
for i in range(A):
    for j in range(z):
        res.append(ab[i]+c[j])
res.sort(reverse=True)
for i in range(k):
    print(res[i])


Measured memory_bytes: 152296
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var mod = n % 10

	if mod == 3 {
		fmt.Printf("bon")
	} else if mod == 2 || mod == 4 || mod == 5 || mod == 7 || mod == 9 {
		fmt.Printf("hon")
	} else {
		fmt.Printf("pon")
	}
}


Measured memory_bytes: 1816
n,m=map(int,input().split())
ab=[[0]*2 for i in range(n)]
for i in range(n):
    ab[i]=list(map(int,input().split()))
    
ab.sort()

mm=0
y=0
for i in range(n):
    mm+=ab[i][1]
    y+=ab[i][0]*ab[i][1]
    if mm>=m:
        break
y=y-(mm-m)*ab[i][0]
print(y)
    

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

#if DEBUG && !ONLINE_JUDGE
    #include "/home/tushar_garg/Desktop/cpp/debug.h"
#else
    #define dbg(x...)
#endif

typedef     long long                            ll; 
typedef     pair<ll, ll>                         pl; 
typedef     vector<ll>                           vl;
typedef     vector<char>                         vc;
typedef     vector<bool>                         vb; 
typedef     vector<vl>                           vvl; 
typedef     vector<pl>                           vll; 
typedef     map<ll, ll>                          dict; 
typedef     map<ll, ll, greater <ll> >           sdict; 
typedef     map<char, ll>                        mcl;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pl>                   pqii;
typedef     priority_queue<ll, vl, greater<ll>>  pqmini;

#define rep(i, a, n) for (auto i=a-(a>n); i!=n-(a>n); i+=1-2*(a>n))
#define trav(i, a) for(auto &i:a)
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back
#define eb emplace_bac
#define flash ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define QuickSilver cin.exceptions(cin.failbit),setprecision(12),cout.precision(12)
#define get(a) rep(i,0,sz(a))cin>>a[i];
#define sz(a) (ll)(a.size())
#define all(a) a.begin(), a.end()
#define mod 1000000007

// bool fun(int n, int m){
// 	int n,m; cin>>n>>m;
// 	vl a(n); rep(i,0,n) cin>>a[i], a[i]%=m;
// 	vl b(m,0); 
// 	rep(i,0,n){

// 	}
// 	if(fun(n-1, m)) cout<<"YES\n";
// 	else cout<<"NO\n";
// }

pair<char,char> find(int i){
  pair<char,char> p={'0', '0'};
  if(i<10) p={p.fi+i, p.se+i};
  else{
    p.se+=i%10;
    while(i/10>0) i/=10;
    p.fi+=i;
  }
  return p;
}

int main(){
	flash; QuickSilver;
	string n; cin>>n;
  if(sz(n)==1){cout<<1<<"\n"; return 0;}
  ll t=0; trav(i,n) t=10*t+(i-'0');
  ll ans=0;
  vl ten(15,1); rep(i,1,15) ten[i]=ten[i-1]*10;
  rep(i,1,t+1){
    if(i%10==0) continue;
    pair<char,char> p=find(i);
    
    if(i<10 || p.fi==p.se) ans++;
    for(ll len=2; len<sz(n); len++) 
      ans+=ten[len-2];
    if(p.se<n[0]) ans+=ten[sz(n)-2];
    else if(p.se==n[0]){
      rep(j,1,sz(n)-1){
        ll t=n[j]-'0';
        ans+=ten[sz(n)-j-2]*t;
      }
      if(n.back()>=p.fi) ans++;
    }
  }
  cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    
    int b = 1e8;
    rep(i, s.size() - t.size() + 1) {
        int c = 0;
        rep(j, t.size()) {
            if (s[i+j] != t[j]) {
                c++;
            }
        }
        b = min(c, b);
    }

put(b);
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
    char ch;
    int cnt[26] = {};
    while (cin >> ch)
    {
        ch = tolower(ch);
        if (isalpha(ch))
        {
            cnt[ch-'a']++;
        }
    }
    for (int i = 0; i < 26; i++)
    {
        printf("%c : %d\n",i+'a',cnt[i]);
    }
return 0;
}


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

lli n, xs;

lli gcd(lli a, lli b){
	if(b == 0) return a;
	else return gcd(b, a%b);
}

int main(void){
	cin >> n >> xs;
	lli ans = 0;
	rep(i, n){
		lli x;
		cin >> x;
		ans = gcd(ans, abs(x-xs));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3572
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
char map[12][6];
char color[5]={'R','G','B','Y','P'};
int d1[4]={0,1,0,-1};
int d2[4]={1,0,-1,0};
int flg,c,a;
void swap(char *map1,char *map2){
	char t;
	t=*map1;
	*map1=*map2;
	*map2=t;
	return;
}
void fall(){
	int i,j,fl;	
	for(j=0;j<6;j++){
		while(1){	
			fl=0;
			for(i=11;i>0;i--){
				if(map[i][j]=='.'&&map[i-1][j]!='.'){
					swap(&map[i][j],&map[i-1][j]);fl=1;
				}
			}
			if(fl==0)break;
		}
	}
	return;
}
void dfs(char cl,int y,int x){//再帰の深さ＞＝４で考えるとWA
	int ny,nx;
	for(int i=0;i<4;i++){
		ny=y+d1[i];nx=x+d2[i];
		if(0<=ny&&ny<12&&0<=nx&&nx<6&&map[ny][nx]==cl){
			if(a>=3){
				map[ny][nx]='@';a++;
			}else{
				map[ny][nx]='#';a++;
			}
			dfs(cl,ny,nx);
		}
	}
	return;
}
void dfs2(int y,int x){
	int ny,nx;
	for(int i=0;i<4;i++){
		ny=y+d1[i];nx=x+d2[i];
		if(0<=ny&&ny<12&&0<=nx&&nx<6&&map[ny][nx]=='#'){
			map[ny][nx]='*';dfs2(ny,nx);
		}
	}
	return;
}
void vanish(char cl){
	int i,j,k;
	for(i=0;i<12;i++){
		for(j=0;j<6;j++){
			a=0;
			if(map[i][j]==cl){
				dfs(cl,i,j);
			}
		}
	}
	for(i=0;i<12;i++){
		for(j=0;j<6;j++){
			if(map[i][j]=='@'){
				dfs2(i,j);
			}
		}
	}
	for(i=0;i<12;i++){
		for(j=0;j<6;j++){
			if(map[i][j]=='*'||map[i][j]=='@'){
				for(int k=0;k<4;k++){
					if(map[i+d1[k]][j+d2[k]]=='O'&&0<=i+d1[k]&&i+d1[k]<12&&0<=j+d2[k]&&j+d2[k]<6){
						map[i+d1[k]][j+d2[k]]='.';
					}
				}
				map[i][j]='.';flg=1;
			}else if(map[i][j]=='#'){
				map[i][j]=cl;
			}
		}
	}
}
int main(){
	int set;
	cin>>set;
	for(set;set>0;set--){
		c=0;
		for(int i=0;i<12;i++){
			cin>>map[i];
		}
		while(1){
			flg=0;
			for(int i=0;i<5;i++){
				vanish(color[i]);
			}
			fall();
			if(flg==0)break;
			c++;
		}
		cout<<c<<endl;
	}
    return 0;
}

Measured memory_bytes: 1164
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int dp[11000];

int main(){
  ll count=0;
  int M,D;
  cin>>M>>D;

  for(int i=1;i<=M;i++){
    for(int j=22;j<=D;j++){
      if((j%10)*(j/10)==i) count++;
  
      if(j%10==9) j+=2;
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 888
import kotlin.math.abs

fun main(args: Array<String>) = tokiomarine2020b()

fun tokiomarine2020b() {
    val (a, v) = readLine()!!.split(' ').map { it.toLong() }
    val (b, w) = readLine()!!.split(' ').map { it.toLong() }
    val t = readLine()!!.toLong()

    val distance = abs(a - b)
    val closePerSec = v - w

    val answer = if (distance <= t * closePerSec) "YES" else "NO"

    println(answer)
}


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

int main(){
  int N;
  cin >> N;
  
  vector<int> vec(N);
  
  rep(i, N){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());      //　大きい順にソート
  
  int sum = 0;
  rep(i, N){
    sum += vec.at(i); 
  }
  
  int Alice = 0;
  rep(i, N){
    Alice += vec.at(i);
    i++;
  }
  
  int Bob = sum - Alice;
  
  cout << Alice - Bob << endl;
}
  

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

using ll = long long;

int main() {
    string N;
    cin >> N;
    auto n = N;
    reverse(n.begin(), n.end());
    if(n == N) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] nm = Console.ReadLine().Split(' ');
        int n = int.Parse(nm[0]);
        int m = int.Parse(nm[1]);
        int[,] ndata = new int[n,m];
        int[] mdata = new int[m];
        for (int i = 0; i < n; i++)
        {
            string[] data = Console.ReadLine().Split(' ');
            for (int j = 0; j < m; j++)
            {
                ndata[i, j] = int.Parse(data[j]);
            }
        }

        for (int i = 0; i < m; i++)
        {
            mdata[i] = int.Parse(Console.ReadLine());
        }

        for (int i = 0; i < n; i++)
        {
            int line = 0;
            for (int j = 0; j < m; j++)
            {
                line = line + ndata[i, j] * mdata[j];
            }
            Console.WriteLine(line);
        }
    }
}

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

int main() {
  int a, b, c, k; cin >> a >> b >> c >> k;
  int ans = 0;
  if (a >= k) {
    ans = k;
  } else {
    k -= a;
    ans = a;
    if (b >= k) {

    } else {
      k -= b;
      ans -= k;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3624
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

struct UnionFind{
    vector<int> data;
    UnionFind(int size){
        data=vector<int>(size,-1);
    }
    bool union_set(int x,int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];
            data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    GI(N);
    GVI(a,N);
    int now=0,c=0;
    while(c<=N){
        c++;
        now=a[now]-1;
        if(now==1){
            print(c);
            return 0;
        }
    }
    print(-1);
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long int
using namespace std;
int32_t main()
{
    int n,w;
    cin>>n>>w;
    int profit[200]={0};
    int weight[200]={0};
    for(int i=0;i<n;i++)
    {
        cin>>weight[i]>>profit[i];
    }

  int dp[n+1][w+1];
  for(int i=0;i<=n;i++)
  {
      for(int j=0;j<=w;j++)
      {
          if(i==0||j==0)
          {
              dp[i][j]=0;
          }

         else if(j>=weight[i-1])dp[i][j]=max(dp[i-1][j],profit[i-1]+dp[i-1][j-weight[i-1]]);
          else{
            dp[i][j]=dp[i-1][j];
          }

      }}
cout<<dp[n][w];
return 0;
}


Measured memory_bytes: 79104
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }

template<class T>
class Tree {
public:
	class Node {
	public:
		int parent;
		vector<int> children;
		int depth;
		T value;
	};

	vector<Node> data;
	int root = -1;
	int _size = 1;

	Tree() {
		data.resize(1);
	}

	Node operator[](int id) {
		return data[id];
	}
	
	void resize(int size) {
		if (size > _size) {
			while (_size < size) {
				_size *= 2;
			}
			data.resize(_size);
		}
	}
	
	void addNode(int id, vector<int>& children, T value) {
		resize(id + 1);

		if (root == -1) {
			root = id;
			data[id].parent = -1;
		}

		data[id].children = children;
		for (int i = 0; i < children.size(); ++i) {
			resize(children[i] + 1);
			if (root == children[i]) {
				root = id; 
				data[id].parent = -1;
			}
			data[children[i]].parent = id;
		}
		data[id].value = value;
	}

	void calcDepth() {
		if (root == -1) {
			return;
		}

		int depth = 0;
		queue<int> que;
		que.push(root);
		while (!que.empty()) {
			for (int i = 0, n = que.size(); i < n; ++i) {
				int parent = que.front();
				que.pop();

				data[parent].depth = depth;

				for (int j = 0; j < data[parent].children.size(); ++j) {
					que.push(data[parent].children[j]);
				}
			}
			depth++;
		}
	}
};

int main() {
	Tree<int> tree;

	int n, id, k;
	vector<int> v;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> id >> k;
		v.resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> v[j];
		}
		tree.addNode(id, v, 0);
	}

	string s;
	tree.calcDepth();
	for (int i = 0; i < n; ++i) {
		if (tree[i].parent == -1) {
			s = "root";
		}
		else if (tree[i].children.size() == 0) {
			s = "leaf";
		}
		else {
			s = "internal node";
		}
		printf("node %d: parent = %d, depth = %d, %s, [", i, tree[i].parent, tree[i].depth, s.c_str());
		for (int j = 0, k = tree[i].children.size(); j < k; ++j) {
			printf("%d", tree[i].children[j]);
			if (j < k - 1)
				printf(", ");
		}
		printf("]\n");
	}

	return 0;
}

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

int main()
{
    int n,r,k=0,a[110],i;
    long long sum, min = LONG_LONG_MAX;
    cin>>n;
    r = n;
    for(i=0;i<n;i++)
    {
    //cout<<69<<endl;
        cin>>a[i];
    }
    sort(a,a+n);
    //cout<<69<<endl;
    for(i=a[0]; i<=a[n-1]; i++)
    {
        //cout<<69<<endl;
        sum = 0;
        for(int j=0; j<n; j++)
            sum += (a[j]-i)*(a[j]-i);
        if(min>sum)
            min = sum;
    }
    cout<<min<<endl;
    return 0;
}


Measured memory_bytes: 256