akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long res = N+1-2;
        for(long i = 1; i*i <= N; i++) {
            if(N%i==0) {
                res = Math.min(res, i+(N/i)-2);
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 35556
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	d := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&d[i])
	}
	sort.Ints(d)
	fmt.Println(d[N/2] - d[N/2-1])
}


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

using namespace std;

using ll = long long;

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

    int x;
    cin >> x;
    if (x < 1200) cout << "ABC\n";
    else cout << "ARC\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,Taro=0,Hanako=0;
	cin>>n;
	for(int i=0;i<n;i++){
		string t,h;
		cin>>t>>h;
		if(t<h) Hanako+=3;
		else if(t>h) Taro+=3;
		else{
			Hanako++;
			Taro++;
		}
	}
	cout<<Taro<<" "<<Hanako<<endl;
	return 0;
}



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

vector<int> dists_from(int v);
void dfs(int v, int d, int p);

int n;
vector<int> N[200000];

vector<int> dists;

int main(void) {
  int u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for(int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    N[a].push_back(b);
    N[b].push_back(a);
  }
  vector<int> dist_u = dists_from(u);
  vector<int> dist_v = dists_from(v);
  int d = 0;
  for(int i = 0; i < n; i++) {
    if(dist_u[i] < dist_v[i]) {
      d = max(d, dist_v[i]);
    }
  }
  cout << d - 1 << endl;
  return 0;
}

vector<int> dists_from(int v) {
  dists = vector<int>(n);
  dfs(v, 0, -1);
  return dists;
}

void dfs(int v, int d, int p) {
  for(const auto& u : N[v]) {
    if(u == p) {
      continue;
    }
    dfs(u, d + 1, v);
  }
  dists[v] = d;
}

Measured memory_bytes: 15608
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;

int A[100000];
set<int> s1, s2;

int main()
{
	//ifstream cin("input.txt");

	int N, T;

	cin >> N >> T;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		s1.insert(A[i]);
		s2.insert(A[i]);
	}

	int maxDiff = 0;
	for (int i = 0; i < N; ++i)
	{
		if (maxDiff < (*s1.rbegin()) - A[i])
			maxDiff = (*s1.rbegin()) - A[i];
		s1.erase(A[i]);
	}

	int result = 0;
	for (int i = 0; i < N; ++i)
	{
		if (maxDiff == (*s2.rbegin()) - A[i])
			++result;
		s2.erase(A[i]);
	}

	cout << result;
	
	return 0;
}


Measured memory_bytes: 10112
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadInt;
            var K = cin.ReadInt;

            double[] prob = new double[N];
            for (int i = 1; i <= N; i++)
            {
                prob[i - 1] = 1.0;
                int now = i;
                while(now < K)
                {
                    now *= 2;
                    prob[i - 1] /= 2;
                }

            }

            Console.WriteLine(prob.Sum() * (1.0/N));
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11872
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <climits>
#include <functional>
#include <algorithm>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

  vector<size_t> V(N);
  for(auto& it: V){
    cin >> it;
  }

  sort(V.begin(),V.end());
  V.erase(unique(V.begin(),V.end()), V.end());
  
  cout << (V.size() == N ? "YES" : "NO") << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;

int n, a[109], s;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n, greater<int>());
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) s += a[i];
		if (i % 2 == 1) s -= a[i];
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <stdio.h>
 
int main()
{
    int n;
    std::cin >> n;
    bool cards[4][13] = {};
    for (int i = 0; i < n; i++)
    {
        char mark;
        int num;
        std::cin >> mark >> num;
        switch (mark)
        {
        case 'S':
            cards[0][num-1] = true;
            break;
        case 'H':
            cards[1][num-1] = true;
            break;
        case 'C':
            cards[2][num-1] = true;
            break;
        case 'D':
            cards[3][num-1] = true;
            break;
        default:
            break;
        }
    }
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
        {
            if (cards[i][j] == false)
            {
                switch (i)
                {
                case 0:
                    printf("S %d\n", j+1);
                    break;
                case 1:
                    printf("H %d\n", j+1);
                    break;
                case 2:
                    printf("C %d\n", j+1);
                    break;
                case 3:
                    printf("D %d\n", j+1);
                    break;
                default:
                    break;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

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

    ll n;
    cin >> n;
    ll flag = 0;
    while (n)
    {
        if (n % 10 == 7)
        {
            cout << "Yes\n";
            return 0;
        }
        n /= 10;
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

void	ft_half(int *a, int N)
{
	int i = 0;
	while (i < N)
		a[i++] /= 2;
}

int main()
{
	int N;
	scanf("%d", &N);
	int a[N];
	int i;
	for (int i = 0; i < N; i++)
		scanf("%d", &a[i]);
	i = 0;
	int sign = 1;
	int count = 0;
	while (i < N)
	{
		if (a[i] % 2)
			break ;
		i++;
		if (i == N)
		{
			count++;
			ft_half(a, N);
			i = 0;
		}
	}
	printf("%d\n", count);
	return (0);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
using namespace std;

int main(){
    //freopen("in.txt", "r", stdin);

    int n, k;
    string s;
    queue<int> q;
    cin>>n>>k;
    cin>>s;

    int l = 0, r = 0, maxi = 0, last;
    while (r<n){
        if (k==0 && s[r] == '0'){
            maxi = max(maxi, r-l);
            k++;
            int last = q.front(); q.pop();
            l = last+1;
        }
        if (k>0 && s[r] == '0'){
            //cout<<"k "<<endl;
            while (r<n && s[r] == '0'){
                r++;
            }
            //cout<<"l : "<<l<<" r : "<<r<<endl;
            maxi = max(maxi, r-l);
            q.push(r-1);
            k--;
            r--;
        }
        if (s[r]=='1') maxi = max(maxi, r-l+1);
        r++;
    }
    cout<<maxi<<endl;

    return 0;
}

Measured memory_bytes: 512
/* You lost the game. */

#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cfloat>
#include <numeric>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <vector>

#define fin(i,n) for (int i = 0; i < n; i++)
#define fin2(i,a,b) for (int i = a; i < b; i++)

#define mp make_pair
#define pb push_back

#define si(n) scanf("%d", &n)
#define sii(n,m) scanf("%d %d", &n, &m)
#define siii(n,m,k) scanf("%d %d %d", &n, &m, &k)
#define sl(n) scanf("%lld", &n)
#define sll(n,m) scanf("%lld %lld", &n, &m)
#define slll(n,m,k) scanf("%lld %lld %lld", &n, &m, &k)
#define ss(s) scanf("%s", s)

#define pi(n) printf("%d\n", n)
#define pii(n,m) printf("%d %d\n", n, m)
#define pl(n) printf("%lld\n", n)
#define pll(n,m) printf("%lld %lld\n", n, m)
#define pai(t,n) fin(i,n) { printf("%d ", t[i]); } printf("\n"); 
#define pal(t,n) fin(i,n) { printf("%lld ", t[i]); } printf("\n"); 

#define L long long int
#define PII pair<int, int>
#define VPII vector<PII>
#define VL vector<L>
#define VI vector<int>
#define VVI vector<VI>

using namespace std;




int main() {
    int n, A[100000], c[100000] = {0};
    si(n);
    fin(i,n) { 
        si(A[i]); 
        c[A[i]]++; 
        if (A[i] % 2 == n % 2) { printf("0\n"); return 0; }
    }
    L res = 1;
    if (c[0] > 1) { printf("0\n"); return 0; }
    fin2(i,1,n) {
        if (c[i] == 2) { res = (res * 2) % 1000000007; }
        else if (c[i] > 2) { printf("0\n"); return 0; }
    }
    pl(res);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	
	long long N,K;
	cin>>N>>K;
	
	vector<long long> A(N);
	for(long long i=0;i<N;i++){
		cin>>A[i];
	}
	
	long long ans = 0;
	
	for(long long i=0;i<N;i++){
		long long x = 0;
		for(long long j=0;j<i;j++){
			if(A[i]<A[j])x++;
		}
				
		ans = mod(ans+mod(x*K));
		x=0;
		for(long long j=0;j<N;j++){
			if(A[i]<A[j])x++;
		}
		long long a = mod(K*(K-1)/2);
		a=mod(a*x);
		ans = mod(ans+a);
	}
	
	cout<<ans<<endl;
		
	
	return 0;
}


Measured memory_bytes: 256
n , x = map(int,input().split())

field = [int(i) for i in input().split()]

diff = list(map(lambda a:abs(a-x),field))

def gcd(x,y):
    # print(x,y)
    if x < y:
        x,y = y,x

    if x % y == 0:
        return y
    else:
        return gcd(y,x%y)

ans = diff[0]


for i in diff[1:]:
    ans = gcd(i,ans)

print(ans)

Measured memory_bytes: 14252
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define NINTH_POWER_OF_TEN 1000000000
#define LL_INF (numeric_limits<long long>::max()/2)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxN = 100;

int N;
string W[kMaxN];
string ans;

string Ans() {
  set<string> s;
  s.insert(W[0]);
  FOR(i, 1, N-1) {
    if (W[i-1].back() == W[i].front() && s.insert(W[i]).second) {
      continue;
    }
    return "No";
  }
  return "Yes";
}

signed main() {
  cin >> N;
  REP(i, N) { cin >> W[i]; }

  ans = Ans();

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


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

int N,M;
int main(){
	fast;
  
  cin>>N>>M;
  
  cout<<(N*(N-1)) / 2 + (M*(M-1)) / 2;
	
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
#include <deque>
#include <queue>
#include <tuple>
using namespace std;

#define prec(i) cout << fixed << setprecision(i)

void output_yn(bool isYes) {
	if (isYes)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

long long fact_mod(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum = (sum * i) % MOD;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}

long long modinv(long long a) {

	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;

	return u;
}

long long _gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);

	if (a % b == 0)
		return b;
	else
		return _gcd(b, a % b);
}

long long _lcm(long long a, long long b)
{
	return (((a * b) % MOD) * modinv(_gcd(a, b))) % MOD;
}

long long ncr(long long n, long long r) {
	long long sum = 1;
	for (long long i = r + 1; i <= n; i++)
		sum *= i;

	return sum;
}


int main()
{

	long long n, x, t;
	cin >> n >> x >> t;



	cout << (int)ceil(n / (float)x) * t << endl;

	return 0;
}

Measured memory_bytes: 3632
n, m = map(int, input().split())

mat = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
    mat[i] = list(map(int, input().split()))

b = []
for _ in range(m):
    b.append(int(input()))

for i in range(n):
    sum = 0
    for j in range(m):
        sum += mat[i][j] * b[j]
    print(sum)



Measured memory_bytes: 6020
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n = get_int()
    print(180 * n - 360)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 65388
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

constexpr static int MAXN = 600;
constexpr static int INF = 1e9;

int n;
char a[MAXN][MAXN];
bool col_black[MAXN];
bool can_paint[MAXN]; // there is a row with col j black

// notes:
// - need to get a fully black row (otherwise can't finish)
// - pick a "goal" row, complete it optimally (needs numWhite moves)
//   - if row i, missing spots j1, j2, ..., jk
//   - pick row i2, something with column i black
//   - if i == jl for some l? can't use or do last?

bool is_white() {
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (a[i][j] == '#')
                return false;
    return true;
}

int solve() {
    if (is_white())
        return -1;

    for (int j = 0; j < n; j++) {
        col_black[j] = true;
        for (int i = 0; i < n; i++) {
            if (a[i][j] == '.') {
                col_black[j] = false;
                break;
            }
        }
        for (int i = 0; i < n; i++)
            if (a[i][j] == '#')
                can_paint[j] = true;
    }

    int best = INF;
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        if (!can_paint[i])
            cnt++;
        for (int j = 0; j < n; j++)
            if (a[i][j] == '.')
                cnt++;

        cnt += n;
        for (int j = 0; j < n; j++)
            if (col_black[j])
                cnt--;
        best = min(best, cnt);
    }
    return best;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%s", a[i]);
    printf("%d\n", solve());
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14


ll powe(ll a, ll b){//aのb乗のmod
    ll ret = 1;
    while(0 < b){
        if((b%2) == 0){
            a = (a*a);
            b >>= 1;
        }
        else{
            ret = (ret*a);
            b--;
        }
    }
    return ret;
}


int main(){
    ll n; cin >> n;n++;
    if (n==1){
        ll x; cin >> x; 
        if (x==1) cout << 1 << endl;
        else cout << -1 << endl;
    }
    else{
        vector<ll> a(n);
        vector<ll> b(n);
        REP(i,n) cin >> a[i];
        bool jud = true;
        FORD(i,n-1,0){
            b[i]+=a[i];
            if (i!=n-1)b[i]+=(b[i+1]+1)/2;
        }
        ll x = 52;
        ll cnt = 0;
        ll maxlim = 1;
        vector<ll> c(n);
        REP(i,n){
            c[i]=maxlim;
            maxlim=min(powe(2,x),(maxlim-a[i])*2);
        }
        ll nodes = 0;
        vector<ll> minodes(n,0);
        FORD(i,n-1,0){
            nodes+=a[i];
            if (i==n-1) minodes[i]=a[i];
            else minodes[i]=(1+minodes[i+1])/2+a[i];
            if (minodes[i]>c[i]){
                jud = false;
                break;
            }
            nodes=min(nodes,c[i]);
            cnt+=nodes;
        }
        if (!jud) cout << -1 << endl;
        else cout << cnt << endl;
    }
}

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

int main(){

	int n,a,b;
	cin >> n >> a >> b;
	if(b<a) {cout << 0; return 0;}
	if(n==1 && a!=b) {cout << 0; return 0;}
	else if (n==1 && a==b) { cout << 1; return 0;}
	if(n==2) {cout << 1; return 0;}
	int changeable = n-2;
	long long count = 1;
	while(changeable){
		count+=b-a;
		changeable--;
		}
	cout << count;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"
const double PI = 3.14159265358979323846;

int main() {
	map<long long, long long> mp;
	for (long long i = -pow(10, 3); i < pow(10, 3); ++i) {
		mp[pow(i, 5)] = i;
	}

	long long X;
	cin >> X;

	for (long long i = -pow(10, 5); i < pow(10, 5); ++i) {
		if (mp[X + pow(i, 5)] != 0) {
			cout << mp[X + pow(i, 5)] << " " << i << endl;
			return 0;
		}
	}

	return 0;
}



Measured memory_bytes: 4704
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t a,b;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> a>>b;
	if (a*b % 2 == 0) {
		out << "No" << endl;
	}
	else {
		out << "Yes" << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)
 
 
 
 
 
 
int main()
{
	int n;
	cin >> n;
	int i;
	int d[100];
 
	rep(i, 0, n) scanf("%d", &d[i]);
 
	int j;
	int Ans = 0;
 
	for (j = 0; j < n - 1; j++) {
		for (i = j + 1; i < n;i++) {
			Ans += (d[j] * d[i]);
			
		}
	}
 
 
	cout << Ans << endl;
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

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

    int h,w;
    cin >> h >> w;
    string sur[h];
    for(int i = 0; i < h; i++) cin >> sur[i];

    int ald2 = 0,ald1 = 0;
    if(h%2 == 1 && w%2 == 1) ald1 = true;
    if(h%2 == 1) ald2 += w/2;
    if(w%2 == 1) ald2 += h/2;

    map<char,int> c;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            c[sur[i][j]]++;
            c[sur[i][j]] %= 4;
        }
    }

    auto rec = [&](int x){
        if(x < 0) cout << "No" << endl;
        return x < 0;
    };

    for(auto p:c){
        if(p.second != 0){
            if(p.second == 1){
                ald1--;
                if(rec(ald1)) return 0;
            } else if(p.second == 2){
                ald2--;
                if(rec(ald2)) return 0;
            } else {
                ald1--;
                ald2--;
                if(rec(ald1)) return 0;
                if(rec(ald2)) return 0;
            }
        }
    }
    if(ald1 != 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n,D,A,x,y;
priority_queue<pii,vector<pii>,greater<pii> >pq;

int32_t main()
{
    IOS
    cin>>n>>D>>A;
    for (int i=1;i<=n;i++)
    {
        cin>>x>>y;
        pq.push(mkp(x,y));
    }

    int ans=0,now_bomb=0;
    while (!pq.empty())
    {
        pii now=pq.top();
        pq.pop();
        if (now.S<0)
        {
            now_bomb+=now.S;
        }
        else
        {
            now.S-=A*now_bomb;
            if (now.S<=0) continue;
            else
            {
                now_bomb+=(now.S+A-1)/A;
                ans+=(now.S+A-1)/A;
                pq.push(mkp(now.F+2*D+1,-(now.S+A-1)/A));
            }
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 6128
#include <bits/stdc++.h>
    
using namespace std;
    
struct vw_pair {
    int v, w;
    vw_pair(int v,int w) : v(v), w(w) {};
};
    
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<int> vi;
typedef vector <string> vs;
typedef vector <vi> vvi;
typedef vector <vector<vw_pair>> adj_list;
typedef vector <bool> vb;
typedef long long ll;
typedef unsigned long long ull;
typedef priority_queue<int> max_heap_int;
typedef priority_queue<int, vi, greater<>> min_heap_int;
    
#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
    
#define modulo(S, N) ((S) & (N-1))   // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S-1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
#define turnOffLastConsecutiveBits(S) ((S) & (S+1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S-1))
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    vi a(n);
    for (int i=0;i<n;++i) cin >> a[i];
    if (is_sorted(a.begin(), a.end())) cout << "YES\n";
    else {
        bool is_good = false;
        for (int i=0;(i<n-1) && !is_good;++i)
            for (int j=i+1;(j<n) && !is_good;++j) {
                swap(a[i], a[j]);
                if (is_sorted(a.begin(), a.end())) is_good = true;
                swap(a[i], a[j]);
            }
        if (is_good) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <iomanip>
#include <numeric>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);

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

	sort(A.begin(), A.end());

	int prev = A[0];
	int cnt = 1;
	int cnt2 = 0;
	for (int i = 1; i < N; i++)
	{
		if(prev == A[i])
		{
			cnt++;
		}
		else
		{
			if (cnt % 2 != 0)
			{
				cnt2 ++;
			}

			cnt = 1;
		}

		prev = A[i];
	}

	if (cnt % 2 != 0)
	{
		cnt2 ++;
	}

	cout << cnt2 << endl;

	return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
f = 0
for i in range(N-M+1):
	for j in range(N-M+1):
		for k in range(M):
			if f:
				f = 0
				break
			for l in range(M):
				if A[i+k][j+l] != B[k][l]:
					f = 1
					break
			else:
				if k == l == M-1:
					print("Yes")
					exit()
print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    string s1,s2;
    cin>>s1>>s2;
    if(s1.length()>s2.length())cout<<"GREATER";
    else if(s2.length()>s1.length())cout<<"LESS";
    else{
        int f=0;
        for(int i=0;i<s1.length();i++){
            if(s1[i]>s2[i]){
                f=1;
                cout<<"GREATER";
                break;
            }else if(s1[i]<s2[i]){
                f=1;
                cout<<"LESS";
                break;
            }
        }
        if(f==0)cout<<"EQUAL";
    }

}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<string>
#include<vector>

#define ll long long
#define ull unsigned long long

using namespace std;
int main(void) {

	ll N = 0;
	scanf("%lld", &N);
	printf("%lld\n", N % 2 == 0 ? N : N * 2);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#define YesNo(c) ((c) ? "Yes" : "No")
#ifdef LOCAL
#define dump(x) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] " << #x " = " << (x) << endl;
#else
#define dump(x)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << ", " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.fst << ", " << p.snd << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.fst >> p.snd; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
////////////////////////////////

int32_t main() {
    int n; cin >> n;
    int a[3], b[3];
    rep (i,3) cin >> a[i];
    rep (i,3) cin >> b[i];
    {
        vector<int> dp(n+1);
        rep (i,3) rep (j,n+1) if (j+a[i] <= n) chmax(dp[j+a[i]], dp[j]+b[i]-a[i]);
        n += dp[n];
    }
    {
        vector<int> dp(n+1);
        rep (i,3) rep (j,n+1) if (j+b[i] <= n) chmax(dp[j+b[i]], dp[j]+a[i]-b[i]);
        n += dp[n];
    }
    cout << n << endl;
}


Measured memory_bytes: 195584
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	var tmp []string
	for i := range s {
		if len(tmp) >= 2 {
			if contains(tmp, string(s[i])) == false {
				fmt.Println("No")
				return
			}
		} else {
			if contains(tmp, string(s[i])) != true {
				tmp = append(tmp, string(s[i]))
			}
		}
	}
	if len(tmp) == 2 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
func contains(s []string, e string) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInts(5)

	var sum, maxRem int
	for _, e := range n {
		sum += maxTime(e)

		if maxRem < remTime(e) {
			maxRem = remTime(e)
		}
	}

	fmt.Println(sum - maxRem)
}

func maxTime(n int) int {
	return ((n + 9) / 10) * 10
}

func remTime(n int) int {
	return maxTime(n) - n
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;


namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int n = sc.intarr[0];
            int[] ps = sc.intarr;

            int[] cp = new int[n];


            ps.CopyTo(cp, 0);

            Array.Sort(cp);

            int difcount = 0;
            for(int i=0; i<n; i++)
            {
                if(ps[i] != cp[i])
                {
                    difcount++;
                }
            }
            if(difcount == 0 || difcount == 2)
            {
                wr.wri("YES");
            }
            else
            {
                wr.wri("NO");
            }
        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N,L;
  cin>>N>>L;
  vector<string> S(N);
  for(int i=0; i<N; i++) cin >>S[i];
  sort(S.begin(), S.end());
  for(int i=0; i<N; i++) cout << S[i];
  cout <<endl;  
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    ll n,m,d;
    cin >> n >> m >> d;
    if(d == 0){
        cout << fixed << setprecision(10) << (n-d)*(m-1) / (double)(n*n) << endl;
    }else{
        cout << fixed << setprecision(10) << 2*(n-d)*(m-1) / (double)(n*n) << endl;
    }
    return 0;
}

Measured memory_bytes: 3752
#include <algorithm>
#include <map>
#include <iostream>

using namespace std;

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

    map<char, int> char_appear_count;
    for (char c = 'a'; c <= 'z'; c++) {
        char_appear_count[c] = 51;
    }

    for (int i = 0; i < n; i++) {
        map<char, int> si_char_appear_count;
        for (char c = 'a'; c <= 'z'; c++) {
            si_char_appear_count[c] = 0;
        }

        string si;
        cin >> si;
        for (char si_c: si) {
            si_char_appear_count[si_c]++;
        }

        for (auto p: si_char_appear_count) {
            char_appear_count[p.first] = min(p.second, char_appear_count[p.first]);
        }
    }

    string answer;
    for (auto c_ac_pair: char_appear_count) {
        if (c_ac_pair.second == 0 || c_ac_pair.second == 51) {
            continue;
        }
        answer += string(c_ac_pair.second, c_ac_pair.first);
    }

    cout << answer << endl;
    return 0;
}


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

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

typedef pair< int, int > Pi;
typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const long long INF = 5e18;
const int di[4] = { 1,0,-1,0 };
const int dj[4] = { 0,1,0,-1 };

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

int n;
ll k,a[1010],ans;
int b[60];
vector<ll>sum,nex;

void input(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	return;
}


void solve(){
	for(int i=0;i<n;i++){
		ll s=a[i];
		sum.eb(s);
		nex.eb(s);
		for(int j=i+1;j<n;j++){
			s+=a[j];
			sum.eb(s);
			nex.eb(s);
		}
	}
	for(int i=0;i<sum.size();i++){
		for(int j=0;j<50;j++){
			if(sum[i]&((ll)1<<(ll)j))b[j]++;
		}
	}
	int now=50;
	while(now>=0){
		for(int i=now;i>=0;i--){
			if(b[i]>=k){
				now=i;
				break;
			}
			else if(i==0){
				now=-1;
			}
		}
		vector<ll>ne;
		ne.clear();
		for(int i=0;i<nex.size();i++){
			if(nex[i]&((ll)1<<(ll)now))ne.eb(nex[i]);
		}
		if(now!=-1)ans+=(ll)1<<(ll)now;
		for(int i=0;i<=50;i++){
			b[i]=0;
		}
		for(int i=0;i<ne.size();i++){
			for(int j=0;j<50;j++){
				if(ne[i]&((ll)1<<(ll)j))b[j]++;
			}
		}
		nex=ne;
		ne.clear();
		now--;
	}
	cout<<ans<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}


Measured memory_bytes: 10336
#include<iostream>

using namespace std;

int main(){
    int ans = 0;
    string s;
    cin >> s;

    string array[2];
    array[0] = s[0];

    for(int i = 0; i < s.length(); i++){
        array[1] = s[i + 1];

        if(array[0] == array[1]){
            array[0] += s[i + 2];
            i++;
        }else{
            array[0] = s[i + 1];
        }
        ans++;
    }

    cout << ans;
}


Measured memory_bytes: 640
N=int(input())
X=input()
A1=[]
A1=X.split(" ") #数値YをリストXに格納
A=[int(i) for i in A1] #リストXの要素を"文字"から"数値"に変換
Y=input()
B1=[]
B1=Y.split(" ") #数値YをリストXに格納
B=[int(i) for i in B1] #リストXの要素を"文字"から"数値"に変換
W=[]
Z=[]
for j in range(0,N):
    w=A[j]-B[j]
    W.append(w)
for n in range(0,N):
    z=A[n]-B[n]
    Z.append(z)
Z=sorted(Z,reverse=True) #リスト内の要素を大→小にソート
x2=0
x=0
if sum(B)>sum(A):
    print("-1")
else:
    x=0
    x1=0
    x2=0
    x3=0
    for i in range(0,N):#A[i]<B[i]となるリストの要素の個数を数える
        if A[i]<B[i]:
            x=x+1 #xは条件を満たすリストの個数
            x1=x1+W[i]#x1は"いくら足りないか"の積算


    for k in range(0,N): #埋め合わせにZの要素がいくつ必要か(=x3)求める
        if x1<0:
            x1=int(x1)
            p=int(Z[k])
            x1=x1+p
            x3=x3+1
        else:
            break
    x2=x3
    print(x2+x)


Measured memory_bytes: 36404
import java.util.Scanner;

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

		//入力
		int r = scanner.nextInt();
		int c = scanner.nextInt();

		//配列rc
		int[][] rc = new int[r + 1][c + 1];

		//入力
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				rc[i][j] = scanner.nextInt();
			}
		}


		//縦列の合計
		for (int i = 0; i < r; i++) {

			int sum = 0;

			for (int j = 0; j < c; j++) {
				sum += rc[i][j];
			}
			rc[i][c] = sum;
		}

		//横列の合計
		for (int i = 0; i < c + 1; i++) {
			int sum = 0;
			for (int j = 0; j < r; j++) {
				sum += rc[j][i];
			}
			rc[r][i] = sum;

		}


		//配列rcの出力
		for (int i = 0; i <= r; i++) {

			for (int j = 0; j <= c; j++) {

				if (j == 0)					//一回目
					System.out.print(rc[i][j]);
				else
					System.out.print(" " + rc[i][j]);

			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 41664
#include<iostream>
#include<stdio.h>
#include<string>
#include <math.h>
using namespace std;
# define maxn 100000

int main(){
  int n,m,l[maxn],r[maxn],cnt(0),sum(0);
  cin>>n>>m;
  for(int i(0);i<m;i++){
    cin>>l[i]>>r[i];
  }
  int sl=l[0],sr=r[0];
  for(int i(1);i<m;i++){
    sl=max(sl,l[i]);
    sr=min(sr,r[i]);
  }
  if (sr - sl>=0){
    cout<<sr-sl+1;
  }else{
    cout<<0;
  }
  return 0;
}


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

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

  if (a+b+2*sqrt(a*b) < c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
  	ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k <= a)
		cout << k;
	else{
		int sum = a;
		k -= a;
		if(b >= k){
			cout << sum;
			return 0;
		}
		k -= b;
		cout << sum - k;
	}
	return 0;
}

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

struct number {
  int s, t;
};

int asc(const void *a, const void *b){
  struct number *A = (struct number *)a;
  struct number *B = (struct number *)b;
  return A->s - B->s;
}

int
main(int argc, char *argv[])
{
  int n; struct number x[200000];
  scanf("%d", &n);
  for(int i = 0; i < n; ++i){
    scanf("%d", &x[i].s);
    x[i].t = i;
  }

  qsort(x, n, sizeof(struct number), asc);

  int b[200000];
  for(int i = 0; i < n; i++){
    if(i <= (n / 2) - 1) b[x[i].t] = x[n / 2].s;
    else b[x[i].t] = x[n / 2 - 1].s;
  }

  for(int i = 0; i < n; i++) printf("%d\n", b[i]);

  return 0;
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  while(true) {
  if (a + b == c) {
    cout << "Yes" << endl;
    break;
  }
  if (b + c == a) {
    cout << "Yes" << endl;
    break;
  }
  if (a + c == b) {
    cout << "Yes" << endl;
    break;
  }
  else {
    cout << "No" << endl;
     break;
  }
  }
  return 0;
  }


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << (N+1)/2 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, C;
    cin >> n >> C;
    vvll d(C+1, vll(C+1, 0));
    vvll c(n+1, vll(n+1, 0));
    repr(i, 1, C+1)repr(j, 1, C+1) cin >> d[i][j];
    repr(i, 1, n+1)repr(j, 1, n+1) cin >> c[i][j];
    
    // 色を揃えるコストの和
    vvll dsum(C+1, vll(3, 0));
    repr(i, 1, n+1)repr(j, 1, n+1)repr(k, 1, C+1){
        dsum[k][(i+j)%3] += d[c[i][j]][k];
    }
    ll ans = INF;
    repr(i, 1, C+1)repr(j, 1, C+1)repr(k, 1, C+1){
        if(i==j || j==k || k==i){
            continue;
        }
        chmin(ans, dsum[i][0]+dsum[j][1]+dsum[k][2]);
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf (int)(1e18)
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(p) p.begin(), p.end()
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define sz(x) (int)x.size()
#define PI 3.14159265
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int N = 1010;
vector<string> a;
int n, m;
bool check(int x, int y)
{
    return (x >= 0 and y >= 0 and x < n and y < m and a[x][y] != '#');
}
void solution()
{
    cin >> n >> m;
    a.resize(n);
    int cx, cy, dx, dy;
    cin >> cx >> cy >> dx >> dy;
    cx--, cy--, dx--, dy--;
    rep(i, 0, n)
    {
        cin >> a[i];
    }
    if (a[cx][cy] == '#' or a[dx][dy] == '#')
    {
        cout << "-1" << endl;
        return;
    }
    vector<pair<int, int>> dir = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
    vector<vector<int>> dp(n, vector<int>(m, inf));
    dp[cx][cy] = 0;
    deque<pair<int, int>> q;
    q.push_front({cx, cy});
    int mi = 0;
    while (q.size())
    {
        int x = q.front().ff;
        int y = q.front().ss;
        q.pop_front();
        mi = max(mi, dp[x][y]);
        for (auto ele : dir)
        {
            int x1 = x + ele.ff;
            int y1 = y + ele.ss;
            if (check(x1, y1) and (dp[x1][y1] > dp[x][y]))
            {
                dp[x1][y1] = dp[x][y];
                q.push_front({x1, y1});
            }
        }
        for (int i = x - 2; i <= x + 2; i++)
        {
            for (int j = y - 2; j <= y + 2; j++)
            {
                if (check(i, j) and (dp[i][j] > dp[x][y] + 1))
                {
                    dp[i][j] = dp[x][y] + 1;
                    q.push_back({i, j});
                }
            }
        }
        if (dp[dx][dy] == mi)
        {
            break;
        }
    }
    if (dp[dx][dy] != inf)
    {
        cout << dp[dx][dy] << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
    return;
}
int32_t main()
{
    run();
    solution();
    return 0;
}

Measured memory_bytes: 12688