akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

/////////////         modの計算

#define MOD_IS_PRIME
const ll mod = 1000000007LL;

class modlong {
public:
	modlong() { x = 0; }
	modlong(ll num) { x = adjust(num); }
	inline operator ll() const { return x; }
	inline bool operator ==(ll num) { return this->x == num; }
	inline bool operator !=(ll num) { return !(*this == num); }
	inline void operator = (ll num) { x = adjust(num); }
	inline void operator += (ll num) { x = adjust(x + num); }
	inline void operator ++() { this->operator+=(1); }
	inline modlong operator + (ll num) const { modlong m(this->x); m += num; return m; }
	inline void operator -= (ll num) { x = adjust(x - num); }
	inline void operator --() { this->operator-=(1); }
	inline modlong operator - (ll num) { modlong m(this->x); m -= num; return m; }
	inline void operator *= (ll num) { x = adjust(x * num); }
	inline modlong operator * (ll num) { modlong m(this->x); m *= num; return m; }
private:
	inline ll adjust(ll a) {
		if (a >= mod) { return a % mod; }
		if (a < 0) { return mod - 1 + ((a + 1) % mod); }
		return a;
	}
	ll x;
};

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

	constexpr int K = 16;

	vector<modlong> v_e = { 869418286, 727008098, 660103155, 183023413, 471090892, 417297686, 237315285, 542573865, 444014759, 927321758, 184117322, 5655049, 347662323, 346175634, 765144583, 0};
	vector<modlong> v_o = { 869418286, 727008098, 660103155, 183023413, 471090892, 417297686, 237315285, 542573865, 444014759, 927321758, 184117322, 962779130, 404391958, 700407153, 729548371, 539588932 };

	int T, N; cin >> T;
	for (int _t = 0; _t < T; _t++) {
		cin >> N;
		modlong x = N;
		modlong ans = v_e[0];
		if (N & 1) {// odd
			for (int i = 1; i < K; i++) {
				ans *= x;
				ans += v_o[i];
			}
		}
		else {// even
			for (int i = 1; i < K; i++) {
				ans *= x;
				ans += v_e[i];
			}
		}
		cout << (ll)ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>

int main(){
	
	char date[15];
	scanf ("%s", date);
	for (int i = 0; date[i] != '/'; i++){
		if (date[3] != '8'){
			date[3] = '8';
		}
	}
	printf ("%s", date);
	return 0;
}

Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int num=n/500;
	int rem=n%500;
	int ans=1000*num;
	int rem2=rem/5;
	ans+=rem2*5;
	cout<<ans;
	return 0;
}

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

typedef long double LD;
typedef long long ll;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define mod             1000000007
#define INF             2147483647
#define endl            "\n"
#define FasterIO        ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0) ;
#define precision(a)    cout << fixed << setprecision(a)
#define bug(a,b)        cout<<a<<"\t"<<b<<"\n";
#define Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";
#define reset(a,b)      memset(a,b,sizeof(a));
#define For(x,n)        for(int i=x; i<n; i++)

const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

int strtoint(string str){
    stringstream ss(str);
    int x = 0;
    ss >> x ;
    return x ;
}
string intostr(int x){
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
void rem(string &s, const string &c) {
	auto pos = s.find(c);
	if (pos == string::npos) {
		cout << -1 << endl;
		exit(0);
	}
	s.erase(0, pos + 1);
}
void println (int n){
    cout<<n<<"\n";
}
void printvec(vector <int> &a){
    for (int i=0;i<a.size();i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printgraph(vector <int> g[],int e){
    for (int i=0;i<e;i++){
        cout<<i<<" --> ";
        for (int j=0;j<g[i].size();j++){
            cout<<g[i][j]<<" ";
        }
        cout<<"\n";
    }
}

void printmap (map <int,int> &mymap){
    for (auto itr = mymap.begin(); itr != mymap.end(); ++itr) {
        cout << '\t' << itr->first
             << '\t' << itr->second << '\n';
    }
    cout << "\n";
}


void solve(){
    int n,k;
    cin>>n>>k;
    vector <int> v;
    vector <int> mem(n+3,INT_MAX);
    for (int i=0;i<n;i++){
        int in;cin>>in;
        v.pb(in);
    }

    mem[0]=0;

    for (int i=0;i<n;i++){
        for (int x=1; x<=k && i+x<n; ++x){
            mem[i+x] = min(mem[i+x],abs(v[i]-v[i+x])+mem[i]);
        }
    }

    cout<<mem[n-1]<<endl;




}


int main(){
    FasterIO;

    solve();
    return 0;
}


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

typedef long long ll;

int a[1010];

int main() {
	int n, i, j;
	cin >> n;
	set<string> st;
	int cnt = 0;
	for(i = 1; i <= n; ++i) {
		cin >> j;
		if(j<=399)	st.insert("gray");
		else if(j<=799)	st.insert("brown");
		else if(j<=1199)	st.insert("green");
		else if(j<=1599)	st.insert("cyan");
		else if(j<=1999)	st.insert("blue");
		else if(j<=2399)	st.insert("yellow");
		else if(j<=2799)	st.insert("orange");
		else if(j<=3199)	st.insert("red");
		else	cnt++;
	}
	cout << max((int)st.size(), 1) << " " <<st.size()+cnt << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll sum[200009];
ll a[200009];
int main()
{
    int n;
    cin>>n;
    ll t=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];

    }
    ll minn=1e15;
    for(int i=1;i<=n-1;i++)
    {
        minn=min(minn,abs(sum[i]-(sum[n]-sum[i])));
    }
    cout<<minn<<endl;
}


Measured memory_bytes: 3328
N, D = map(int, input().split())

def is_square(N):
    for i in range(1000):
        if i * i == N:
            return True
    return False

def dist(X1, X2):
    ans = 0
    for i in range(len(X1)):
        ans += (X1[i] - X2[i]) ** 2
    return ans

X = [[] for j in range(N)]
for i in range(N):
    X[i] = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if is_square(dist(X[i], X[j])):
            ans += 1
            
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
	int H[100]={1},W[100]={1},s,t,a;
	//??\???
	for(a=0;H[a]!=0 && W[a]!=0 && a<100-1;a++){
		do{
			printf("");
			scanf("%d %d",&H[a+1],&W[a+1]);
		}while(!(H[a+1]>=0 && H[a+1]<=300 && W[a+1]>=0 && W[a+1]<=300));
	}
	
	//??????
	for(a=1;W[a]!=0 && H[a]!=0;a++){
		for(s=1;s<=H[a];s++){
			for(t=1;t<=W[a];t++){
				if(((s%2)+(t%2))%2==0){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(vector<T> & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(vector<T>& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(vector<T>& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(vector<T>& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>T Sum(vector<T> a, T init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template<class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define in(...) int __VA_ARGS__; CINPUT(__VA_ARGS__);
#define In(T,...) T __VA_ARGS__; CINPUT(__VA_ARGS__);
#define Vin(T,name,n) int n; cin>>n; vector<T> name(n); rep(i,n)cin>>name[i];
#define VIn(T,name,n) vector<T> name(n); rep(i,n)cin>>name[i];
#define VIn2(T,name,name2,n) vector<T> name(n),name2(n); rep(i,n)cin>>name[i]>>name2[i];

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template<class T>void out(T n) { cout << n << endl; }
template<class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void poss(bool f) { puts(f ? "possible" : "impossible"); }
void Poss(bool f) { puts(f ? "Possible" : "Impossible"); }
void POSS(bool f) { puts(f ? "POSSIBLE" : "IMPOSSIBLE"); }

int main() {
	in(x);
	YES(x == 3 || x == 5 || x == 7);
}

Measured memory_bytes: 256
class my_card:
    list_s = [i for i in range(1,14)]
    list_h = [i for i in range(1,14)]
    list_c = [i for i in range(1,14)]
    list_d = [i for i in range(1,14)]
    
    def remove_card(self, pattern, number):
        if pattern == 'S':
            self.list_s.remove(number)
        elif pattern == 'H':
            self.list_h.remove(number)
        elif pattern == 'C':
            self.list_c.remove(number)
        else:
            self.list_d.remove(number)
    
    def print_card_sep(self, list_card, name):
        for card in list_card:
            print('{} {}'.format(name, card))
    
    def print_card(self):
        self.print_card_sep(self.list_s, 'S')
        self.print_card_sep(self.list_h, 'H')
        self.print_card_sep(self.list_c, 'C')
        self.print_card_sep(self.list_d, 'D')
    
input_num = int(input())
my_card = my_card()
for i in range(input_num):
    s, n = input().split()
    n = int(n)
    my_card.remove_card(s, n)
    
my_card.print_card()


Measured memory_bytes: 5608
s = int(input())
list = [int(i)for i in input().split()]
answer=0
a = True
while a:
  count=0
  for i in range(s):
    if list[i]%2==0:
      list[i]/= 2
      count +=1
  if count ==s:
    answer += 1
  else:
    a =False
    break
    
print(answer)

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

using namespace std;
typedef long long ll;
const int maxn = 5e5 + 10;

int a[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size();
	int cnt = 0;
	for (int i = 0; i < n; i++){
		if (s[i] == '>')
			cnt = 0;
		else
			cnt ++;
		a[i + 1] = cnt;
	}
	cnt = 0;
	ll sum = a[n];
	for (int i = n - 1; i >= 0; i--){
		if (s[i] == '<')
			cnt = 0;
		else
			cnt ++;
		a[i] = max(a[i], cnt);
		sum += a[i];
	}
	cout << sum << endl;
}


Measured memory_bytes: 2844
import java.util.Scanner;

public class Main {
  
  	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int f[] = new int[N];
		int h[] = new int[N];
		
		h[0] = sc.nextInt();
		h[1] = sc.nextInt();
		
		f[1-1] = 0;
		f[2-1] = Math.abs(h[2-1] - h[1-1]);
		
		for(int i=3;i<=N;i++){
			
			f[i-1] = -1;
			h[i-1] = sc.nextInt();
			
			f[i-1] = flog1(i-1,h,f);
		}
		
		System.out.println(f[N-1]);
	}
	
	public static int flog1(int i,int[] h,int[] f){
		
		if(i == 0){
			return f[0];
		}
		else if(i == 1){
			return f[1];
		}
		
		if(f[i] != -1){
			return f[1];
		}
		else{
			int f_i1 = Math.abs(h[i]-h[i-1]) + f[i-1];
			int f_i2 = Math.abs(h[i]-h[i-2]) + f[i-2];
			
			return Math.min(f_i1, f_i2);
		}
	}
}

Measured memory_bytes: 58536
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
int N=INT_MAX;
map<int ,int>my;
//vector<PII>v[1000005];

int main(){
    int n,k;
    cin>>n>>k;
    vector<int>v;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        v.PB(x);
    }
    int f[n];
    for(int i=0;i<n;i++){
        f[i]=0;
    }
    for(int i=0;i<n;i++){
        int m=N;
        for(int j=1;j<=k;j++){
            if( (i-j)>=0 ){
                m=min(m,abs(v[i]-v[i-j])+f[i-j]);
            }
            else{break;}
        }
        if(m!=N){
            f[i]=m;
        }
    }
    cout<<f[n-1];
    return 0;
}


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

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def add(i,x,bit):
        while i < len(bit):
            bit[i] += x
            i += i&-i
    def sum(i,bit):
        res = 0
        while i :
            res += bit[i]
            i -= i&-i
        return res
    Q = I()
    q = LIR(Q)
    bit = [0]*(Q+1)
    bit2  = [0]*(Q+1)
    bit3 = [0]*(Q+1)
    bit4 = [0]*(Q+1)
    A = []
    for qi in q:
        if qi[0] == 1:
            a = qi[1]
            A.append(a)
    qa = [i for i in A]
    qa.sort()
    ia = {i:bisect.bisect_left(qa,i) for i in A}
    revqa = [-i for i in qa[::-1]]
    revia = {i:bisect.bisect_left(revqa,-i) for i in A}
    sb = 0
    n = 0
    for qi in q:
        if qi[0] == 1:
            a,b = qi[1:]
            ia[a] += 1
            revia[a] += 1
            i = ia[a]
            revi = revia[a]
            add(i,1,bit)
            add(i,a,bit2)
            add(revi,1,bit3)
            add(revi,a,bit4)
            sb += b
            n += 1
        else:
            l = 0
            r = Q
            k = (n-1)>>1
            while r-l > 1:
                m = (l+r) >> 1
                if sum(m,bit) <= k:
                    l = m
                else:
                    r = m
            fa = qa[l]
            i = ia[fa]
            revi = revia[fa]
            s1 = sum(l,bit)
            s2 = sum(l,bit2)
            s3 = sum(revi,bit3)
            s4 = sum(revi,bit4)
            s = fa*s1-s2+s4-fa*s3+sb
            print(fa,s)
    return

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


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

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

// v の長さ len の区間で最大値を求める
ll calc(const vector<ll>& v, int len) {
  int l = 0;
  int r = l + len;
  ll ans = 0;
  for (int i = 0; i < len; i++) ans += v[i];
  ll tmp = ans;
  while (r < v.size()) {
    tmp -= v[l];
    tmp += v[r];
    chmax(ans, tmp);
    l++; r++;
  }
  // dump(v);
  // cerr << "len: " << len << "  ans: " << ans << endl;
  return ans;
}

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

  ll n, k;
  cin >> n >> k;
  vector<ll> p(n), c(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  ll ans = -INF;
  rep(i, n) {
    cin >> c[i];
    chmax(ans, c[i]);
  }

  vector<vector<ll>> a;
  vector<int> used(n, -1);

  for (int i = 0; i < n; i++) {
    // i : はじめにコマを置く位置
    if (used[i] != -1) continue;
    int j = i;
    vector<ll> tmp;
    while (used[p[j]] == -1) {  // p[j]: 移動先。移動先が未踏の間ループする
      j = p[j];  // j から p[j] へ移動する
      tmp.push_back(c[j]);  // p[j] の位置の値を足す
      used[j] = 1;
    }
    a.push_back(tmp);
  }

  // dump(a);

  for (auto& v : a) {
    ll tmp = 0;
    int kk = k;
    if (kk > v.size()) {
      ll sum = SUM(v);
      if (sum > 0) {
        int n_loop = (kk / v.size()) - 1;
        if (n_loop > 0) tmp += sum * n_loop;
        kk -= v.size() * n_loop;
      } else {
        kk = v.size();
      }
      // cerr << "sum: " << sum << " tmp: " << tmp << " kk: " << kk << endl;
    }
    if (kk == 0) {
      chmax(ans, tmp);
      continue;
    }
    // v の中で 1 以上 kk 以下の区間の最大値を求める O(N^2)
    // 循環するので vv = v + v とする
    auto vv = v;
    vv.insert(vv.end(), v.begin(), v.end());
    vv.insert(vv.end(), v.begin(), v.end());
    for (int i = 1; i <= kk; i++) {
      chmax(ans, tmp + calc(vv, i));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;
int A, B;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> A >> B;

	int ans = (B-1)/(A-1);
	if ((B-1)%(A-1)!=0) {
		ans += 1;
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int x, y, z, k;
    cin >> x >> y >> z >> k;

    vector <long long> a(x), b(y), c(z);
    for (int i = 0; i < x; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<long long>());

    for (int i = 0; i < y; i++){
        cin >> b[i];
    }
    sort(b.begin(), b.end(), greater<long long>());
    
    for (int i = 0; i < z; i++){
        cin >> c[i];
    }
    sort(c.begin(), c.end(), greater<long long>());

    vector <long long> ans;

    for (int i = 0; i < a.size(); i++){
        for (int j = 0; j < b.size(); j++){
            for (int h = 0; h < c.size(); h++){
                if ((i+1) * (j+1) * (h+1) > k){
                    break;
                }else{
                    ans.push_back(a[i] + b[j] + c[h]);
                }
            }
        }
    }
    
    sort(ans.begin(), ans.end(), greater<long long>());

    for (int i = 0; i < k; i++){
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int d[100005];
    for(int i=1;i<=n;i++)
    {
        cin>>d[i];
    }
    sort(d+1,d+1+n);
    if(n%2==1)
    {
        cout<<"0";
        return 0;
    }
    else
    {
        if(d[n/2]==d[n/2+1])
        {

            cout<<"0";
            return 0;
        }
        else
        {
            cout<<d[n/2+1]-d[n/2];
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int nSum = 0;
        int mSum = 0;
        for (int i = 0; i < n; i++)
            nSum += i;
        for (int i = 0; i < m; i++)
            mSum += i;
        pw.println(nSum + mSum);
        
        pw.flush();
    }
}

Measured memory_bytes: 22612
#include <cstdio>
#include <vector>
using namespace std;
 
int main() {
  int num_vector, num_query;
  scanf("%d %d", &num_vector, &num_query);
  vector< vector<int> > nums(num_vector);
   
  while (num_query--) {
    int command, t; scanf("%d %d", &command, &t);
     
    switch (command) {
      case 0:
        int x; scanf("%d", &x);
        nums[t].push_back(x);
        break;
        
      case 1:
        if (!nums[t].empty()) {
          printf("%d", nums[t][0]);
          for (int i = 1; i < nums[t].size(); i++) printf(" %d", nums[t][i]);
        }
        printf("\n");
        break;
        
      case 2:
        if (!nums[t].empty())nums[t].clear();
        break;
    }
  }
}


Measured memory_bytes: 5384
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll


int t, n, m, k, a[300010], q, l, r;


int32_t main(){
INIT
cin>>n;
for(int i=1; i<=n; i++){cin>>a[i];} sort(a+1, a+1+n);
int sum=a[n];
int ar=2;

for(int i=n-1; i>=1; i--){
    if(ar>=n){break;}
    sum+=a[i]; ar++;
    if(ar>=n){break;}
    sum+=a[i]; ar++;
}


cout<<sum;

return 0;
}




Measured memory_bytes: 5220
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=100005;

char str[3];
int n,A[MAXN],op[MAXN];
long long sum[MAXN],sum2[MAXN];

int main()
{
	scanf("%d",&n);
	op[1]=1;
	long long ans;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&A[i]);
		sum2[i]=sum2[i-1]+A[i];
		sum[i]=sum[i-1]+A[i]*op[i];
		if(i<n)
		{
			scanf("%s",str);
			op[i+1]=(str[0]=='+')?1:-1;
		}
	}
	
	int last=-1;
	op[n+1]=-1;
	ans=sum[n];
	for(int i=1;i<=n+1;i++)
		if(op[i]==-1)
		{
			if(last!=-1)
				ans=max(ans,sum2[n]-sum2[i-1]-(sum2[i-1]-sum2[last-1])+sum[last-1]);
			last=i;
		}
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,j,len;
	char str[1001];
	char a[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
	char b[26]={'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C'};

	scanf("%s",str);
	len=strlen(str);
	for(i=0;i<len;i++){
		for(j=0;j<26;j++){
			if(str[i]==b[j]){
				str[i]=a[j];
				break;
			}
		}	
	}
	printf("%s\n",str);
	return 0;
}

Measured memory_bytes: 948
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){

    int n, i;
    cin >> n >> i;
    cout << n-i+1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll K;
  cin >> K;
  ll ans = 0;
  for(ll i = 1; i <= K; i++){
    for(ll j = i; j <= K; j++){
      for(ll k = j; k <= K; k++){
        ll x = __gcd(i, j);
        ll y = __gcd(x, k);
        if(i == j && i == k) ans += y;
        else if(i != j && j != k && k != i) ans += 6LL * y;
        else ans += 3LL * y;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.Arrays;

class Main {
  private static final int maxNum = 100000010;
  public static void main(String[] args) {
    Scanner cin = new Scanner(System.in);
    boolean[] primeTable = new boolean[maxNum];
    creatPrimeTable(primeTable);

    int n = cin.nextInt(), ct = 0;
    for (int i = 0; i < n; i++){
      int num = cin.nextInt();
      if (primeTable[num]) ct++;
    }

    System.out.println(ct);
  }

  private static void creatPrimeTable(boolean[] table) {
    Arrays.fill(table, true);
    double sqrt_max = Math.sqrt(maxNum);
    for (int i = 2; i < sqrt_max; i++){
      if (table[i]){
        for (int j = i * 2; j < maxNum; j += i){
          table[j] = false;
        }
      }
    }
  }
}

Measured memory_bytes: 140596
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;

class unionfind {
    vector<int> par, rank, size_;
public:
    unionfind(int n) :par(n), rank(n), size_(n, 1) {
        iota(all(par), 0);
    }
    int find(int x) {
        if (par[x] == x)return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])swap(x, y);
        par[y] = x;
        size_[x] += size_[y];
        if (rank[x] == rank[y])rank[x]++;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return size_[find(x)];
    }
};

int main(){
    int n;
    while(cin>>n,n){
        int ans=0;
        vector<vector<pii>>graph(n,vector<pii>(n,pii(0,0)));
        rep(i,n)rep(j,n)cin>>graph[i][j].second>>graph[i][j].first;
        vector<vector<bool>>flag(n,vector<bool>(n,true));
        rep(i,n)rep(j,n){
            if(!flag[i][j])continue;
            vector<vector<bool>>temp=flag;
            map<pii,int>mp;
            bool IsHeyro=false;
            pii now=pii(i,j);
            while(1){
                if(mp[now]!=0){ans++; IsHeyro=true;;break;}
                if(flag[now.first][now.second]==false)break;
                mp[now]++;
                now=graph[now.first][now.second];
            }
            if(IsHeyro)for(auto itr=mp.begin(); itr!=mp.end();itr++)flag[itr->first.first][itr->first.second]=false;
        
        }
        cout<<ans<<endl;
    }
}

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

int main() {
    ll n;
    cin >> n;
    ll v = sqrt(n);
    ll ans = 1;
    for (int i = 2; i <= v; i++) {
        if (n % i == 0) ans = i;
    }
    ans = ans + (n / ans) - 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<pair<int, int>>;
using VTIII = vector<tuple<int, int, int>>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int S, W;


signed main(){
    cin >> S >> W;

    if(S <= W) cout << "unsafe" << endl;
    else cout << "safe" << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N =1e6;

LL int dp[N][4], a[N], b[N], c[N];

int main(){
    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], dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2])+b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c[i];
        //cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
    }
    int ans = max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
    cout << ans << endl;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int n;
int ans = -1;

bool ask(int i){
  cout << i%n << endl;
  string s;
  cin>>s;
  if(s == "Vacant") exit(0);
  else if(s == "Male") return true;
  else return false;
}

bool b[100005];

int main(int argc, char *argv[]){
  if(argc >= 2){
    ans = atoi(argv[1]);
  }
  cin >> n;

  b[0] = ask(0);
  b[n/2] = ask(n/2);

  int l,r;
  if( ((n/2)%2==0 && b[0] == b[n/2]) || ((n/2)%2==1 && b[0] != b[n/2])){
    l = n/2;
    r = n;
  } else {
    l = 0;
    r = n/2;
  }

  while(true){
    int p = (l+r)/2;
    b[p] = ask(p);

    if( ((p-l)%2 == 0 && b[l] == b[p]) || ((p-l)%2 == 1 && b[l] != b[p])) l = p;
    else r = p;
  }

  return 0;
}


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

a, b = [1], [1]

for i in range(n):
    a.append(a[i]*2+3)
    b.append(b[i]*2+1)

def cal(n, x):
    if n == 0:
        if x <= 0:
            return 0
        else:
            return 1
    val = (a[n]+1)//2

    if x < val:
        return cal(n-1, x-1)
    elif x == val:
        return b[n-1]+1
    elif x > val:
        return b[n-1]+1+cal(n-1, x-val)

ans = cal(n, x)
print(ans)
    
    




Measured memory_bytes: 9224
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,M,X = MI()
A = LI()
a = sum(A[i] < X for i in range(M))
print(min(a,M-a))


Measured memory_bytes: 61740
s=input()
n=len(s)

c=[0]
tmp='R'
idx=0
# count for r,l
for i in s:
  if tmp==i:
    c[idx]+=1
  else:
    tmp=i
    idx+=1
    c.append(1)

    
for i in range(0,len(c),2):
  r,l=c[i],c[i+1]
  rl=r+l
  for j in range(r-1):
    print(0, end=' ')
  if not rl%2:
    print(rl//2,rl//2, end=' ')
  elif not r%2:
    print(rl//2,rl//2+1, end=' ')
  else:
    print(rl//2+1,rl//2, end=' ')
  for j in range(l-1):
    print(0, end=' ')  


Measured memory_bytes: 9772
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << " " <<  max(0, a+b-n) << endl;
    return 0;
}

Measured memory_bytes: 256
if __name__=="__main__":
    sum = 0
    x,y = map(int,input().split())
    c = [list(map(int,input().split())) for n in range(10)]
    for k in range(10):
        for i in range(10):
            for j in range(10):
                if c[i][j]>c[i][k]+c[k][j]:
                    c[i][j] = c[i][k]+c[k][j]

    m = [list(map(int,input().split())) for n in range(int(x))]
    for i in range(x):
        for j in range(y):
            if m[i][j]!=-1:
                sum+=int(c[m[i][j]][1])

    print(sum)




Measured memory_bytes: 3444
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	int K,A,B;
	cin >> K >> A >> B;
	string ans = "NG";
	for (int i = K; i <= B;i+=K){
		if(A<=i&&i<=B){
			ans = "OK";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

int main() {

    int n,k; cin >> n >> k;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];


    // 何も操作しない場合は0
    int ans = 0;
    int m = min(n, k);

    erep(l, m) {
        erep(r, m-l) {
            // 操作可能回数から取り出した操作回数を引いた数が削除可能な数
            int deleteCount = k-l-r;
            // 現在の点数
            int now = 0;
            // 取り出した数を保持するvector
            vector<int> s;
            rep(i, l) {
                now += v[i];
                s.push_back(v[i]);
            }
            FOR(i, n-r, n) {
                now += v[i];
                s.push_back(v[i]);
            }
            // 昇順ソート
            sort(s.begin(), s.end());

            // 削除可能な数だけ、削除していく
            rep(i, deleteCount) {
                if(i >= s.size()) break;
                // 削除するのはマイナスの値だけ
                if(s[i] > 0) break;
                now -= s[i];
            }
            chmax(ans, now);
        }
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
n=int(input())
s=[0]*n
for i in range(n):
  s[i]=input()
  
print("AC x "+str(s.count('AC')))
print("WA x "+str(s.count('WA')))
print("TLE x "+str(s.count('TLE')))
print("RE x "+str(s.count('RE')))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_d() {
    ull n, a, b;
    cin >> a >> b >> n;

	ull ans = 0;
	
	if (n < b) {
		ans = max(ans, a * n / b - a * (n / b));
	}
	else {
		ans = max(ans, a * (b-1) / b - a * ((b - 1) / b));
	}

	cout << ans << "\n";
}

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

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 3640
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let a: i64 = sc.cin();
    let b: i64 = sc.cin();
    let c: i64 = sc.cin();
    let k: i64 = sc.cin();
    let mut ans = min!(a, k);
    ans -= max!(k - a - b, 0);
    put!(ans);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 2160
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;




int main(){
  const int n = getInt();
  vector<int> x(n);
  REP(i,n) x[i] = getInt();
  const int l = getInt();

  const int m = 20;
  vector<vector<int> > dp(n, vector<int>(m));

  REP(i,n) {
    if (i == n - 1) dp[i][0] = n - 1;
    else {
      const int xx = x[i];
      int mn = i + 1;
      int mx = n - 1;
      while(mn <= mx) {
        const int med = (mn + mx) / 2;
        const int d = x[med] - xx;
        if(d <= l) mn = med + 1;
        else mx = med - 1;
      }
      dp[i][0] = mx;
      if(mx == i) throw 0;
    }
  }

  for(int i = 1; i < m; i++) {
    REP(j,n) {
      const int c = dp[j][i - 1];
      dp[j][i] = dp[c][i - 1];
    }
  }

  const int q = getInt();

  // REP(i,n) { printf("%d: ", i); REP(j,m) printf("%d ", dp[i][j]); puts(""); }

  REP(i,q) {
    int a = getInt() - 1;
    int b = getInt() - 1;
    if(a > b) swap(a, b);

    int p = a;
    int ans = 0;

    while(p < b) {
      for(int i = 0; i < m; i++) {
        if(dp[p][i] >= b || (dp[p][i] <= b && dp[p][i + 1] >= b)) {
          p = dp[p][i];
          ans += 1 << i;
          break;
        }
      }

      // printf("%d %d\n", p, ans);
    }

    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
#define ll long
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string a;
	string b;
	cin >> a;
	cin >> b;
	int count = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] != b[i]) {
			count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 3900
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

int main(){
  int K; cin >> K;
  if (K%2==0 || K%5==0) {
    cout << -1 << endl;
    return 0;
  }
  ll pow10 = 7;
  ll S = 0;
  for (int n=1;n<=1000000;n++){
    (pow10 *=10 ) %= K;
    (S += pow10 )%= K;
    if (S%K==0) {
      cout << n << endl;
      return 0;
    }
  }

  //cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

signed main(){
    string s; cin>>s;
    string ans;
    if(s[0]=='0') ans ="0";
    else if(s[0]=='1') ans = "1";
    FOR(i,1,s.size()){
        if(s[i]=='0') ans.push_back('0');
        else if(s[i]=='1') ans.push_back('1');
        else if(s[i]=='B'&&ans.size()>=1) ans.erase(ans.size()-1);
    }
    Out(ans);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
const LL MOD = 1000000007LL;
const int inf = 1e9;
const LL INF = 1e18;
int a[200000];
int b[200000];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	int ans = 0;
	for (int i = 0; i <= 28; i++) {
		int sum = 0;
		vector<int> zero, one;
		for (int j = 0; j < N; j++) {
			if (b[j] & (1 << i)) one.push_back(b[j] % (1 << i));
			else zero.push_back(b[j] % (1 << i));
		}
		sort(zero.begin(), zero.end());
		sort(one.begin(), one.end());
		for (int j = 0; j < N; j++) {
			int t = a[j] % (1 << i);
			if (a[j] & (1 << i)) {
				sum += one.end() - lower_bound(one.begin(), one.end(), (1 << i) - t);
				sum += zero.size() - (zero.end() - lower_bound(zero.begin(), zero.end(), (1 << i) - t));
			}
			else {
				sum += one.size() - (one.end() - lower_bound(one.begin(), one.end(), (1 << i) - t));;
				sum += zero.end() - lower_bound(zero.begin(), zero.end(), (1 << i) - t);
			}
		}
		if (sum % 2) ans += 1 << i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624