akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    char c;
    cin>>c;
    if(c=='A'){
        cout<<"T"<<endl;
    }else if(c=='T'){
        cout<<"A"<<endl;
    }else if(c=='G'){
        cout<<"C"<<endl;
    }else if(c=='C'){
        cout<<"G"<<endl;
    }





    return 0;
}


Measured memory_bytes: 888
import sys

a, b = map(int, input().split())
ans = 0

if b - a < 100:
    for i in range(a, b + 1):
        ans ^= i
    print(ans)
    sys.exit()

while a % 4 > 0:
    ans ^= a
    a += 1
while b % 4 < 3:
    ans ^= b
    b -= 1
print(ans)


Measured memory_bytes: 3060
n = int(input())
s = input()
flag = 1
if n % 2 == 1:  flag = 0
else:
    hn = n // 2
    for i in range(hn):
        if s[i] != s[i + hn]:   flag = 0

if flag == 1:   print("Yes")
else:           print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int BUF = 305;
const int BIT = 61;
const long long INF = 1LL << 62;


int nVal;
long long val[BUF];

void read() {
    cin >> nVal;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}


long long rec(int bit, int aCarry, int bCarry, long long dp[BIT][2][2], long long result) {
    if (bit == BIT - 1) {
        return aCarry == 0 && bCarry == 0 ? 0 : -1;
    }
    
    long long &ret = dp[bit][aCarry][bCarry];
    if (ret != -1) return ret;

    ret = INF;
    
    long long aBit = (val[0] - (aCarry ?  1LL << (bit) : 0)) & (1LL << bit);
    long long bBit = (val[1] + (bCarry ?  1LL << (bit) : 0)) & (1LL << bit);
    long long rBit = result & (1LL << bit);
    
    // A - (1 << bit),  B + (1 << bit)
    if ((aBit ^ bBit) == rBit) {
        int aNexCarry = (val[0] & (1LL << bit)) == 0 || aCarry;
        int bNexCarry = (val[1] & (1LL << bit)) || bCarry;
        long long v = rec(bit + 1, aNexCarry, bNexCarry, dp, result);
        if (v != -1) {
            ret = min(ret, (v << 1) + 1);
        }
    } 
    
    // A - 0,  B + 0
    if ((aBit ^ bBit) == rBit) {
        int aNexCarry = (val[0] & (1LL << bit)) == 0 && aCarry;
        int bNexCarry = (val[1] & (1LL << bit)) && bCarry;
        long long v = rec(bit + 1, aNexCarry, bNexCarry, dp, result);
        if (v != -1) {
            ret = min(ret, v << 1);
        }
    }

    if (ret == INF) ret = -1;
    
    return ret;
}


void work() {
    long long result = 0;
    for (int i = 2; i < nVal; ++i) {
        result ^= val[i];
    }
    
    long long dp[BIT][2][2];
    memset(dp, -1, sizeof(dp));

    long long v = rec(0, 0, 0, dp, result);
    cout << (v == val[0] ? -1 : v) << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 3612
N = int(input())
B = input().split(' ')
B = [int(B[i]) for i in range(N-1)]
SUM = [B[0], B[-1]]
for i in range(N-2):
  if B[i]>=B[i+1]:
    SUM.append(B[i+1])
  else:
    SUM.append(B[i])
print(sum(SUM))

Measured memory_bytes: 9144
#include <stdio.h>

int main() {
	char a[1], b[1];

	scanf("%c %c", a, b);

	if (a[0] == 'H') printf("%c\n", b[0]);
	else if (b[0] == 'D') printf("H\n");
	else printf("D\n");

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, C, D, res;
  rd(A);
  rd(B);
  rd(C);
  rd(D);
  res =min_L(A, B)+min_L(C, D);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int A, B, C, D, res;
//   rd(A, B, C, D);
//   res = min(A, B) + min(C, D);
//   wt(res);
// }


Measured memory_bytes: 256
/*
Character Drawing Adapted from FAKEUPDATE.NET
		   _    _____         _
		   \`,""   ,'7"r-..__/ \
		  ,'\ `, ,',','    _/   \
		 /   \, 7 / /     (   \ |
		J     \/ j  L______\  / |
		L   __JF"""/""\"\_,    /
		L,-"| O|  f O |  L_  _/
		F   \_ /  \__/   `-  j|
			.-'    `"""    ,' |          _..====.._
			\__/         r"_  A        ,' _..---.._`,
			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,
					  j   / / / 7"    `-<""=:'  '':. \ \
					 /   <,' /  F  . i , \   `,    :T W I
					 |    \,'  /    >X<  |     \   :| | L
					 |     `._/    ' ! ` |      I  :| |  G
					  \           \     /       |  :H T  |
					 __>-.__   __,-\   |        |  S P   |
					/     /|   | \  \  \_       | 'A R   |
				   /   __/ |   |  L  L   \      K./ /    L
				  /   |    |   4  I  I    |    E./ /   ,'
				 J    \    I    L F  I    |    // / _,'
		_________|     |   F    |J   F    |   //_/-'
		\   __   |    /   J     |/  J     |  /="
		\\  \_\  \__,' \  F     |   F     |
		\\\_____________\/      F__/      F
		 \\| 计算机编程 |_____/  (______/
		  \/从入门到入土/
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
#define MATH_PI 3.14159265358979323846
int GetDayCount(int iMonth){
	if (iMonth == 1 || iMonth == 3 || iMonth == 5 || iMonth == 7 || iMonth == 8 || iMonth == 10 || iMonth == 12)
		return 31;
	else if (iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11)
		return 30;
	else if (iMonth == 2)
		return 28;
	else
		return 0;
}
int main(){
	ios::sync_with_stdio(false);
	int M1, M2;
	cin >> M1 >> M2;
	cout << (GetDayCount(M1) == GetDayCount(M2) ? "Yes\n" : "No\n");
endapp:
//system("pause > nul");
	return 0;
}

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

#define MAX 100

int main(void) {
	int N;
	cin >> N;
	int D[MAX][2];
	int a = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 2; j++) {
			cin >> D[i][j];
		}
	}

	for (int i = 0; i < N; i++) {
		if (D[i][0] == D[i][1])	a++;
		else a = 0;

		if (a == 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3104
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		while(n-->0)
		{
			int a=sc.nextInt();
			int b=sc.nextInt();
			int c=sc.nextInt();
			System.out.println((a*a==b*b+c*c)||(b*b==a*a+c*c)||(c*c==a*a+b*b) ? "YES":"NO");
		}
	}
}

Measured memory_bytes: 23400
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int h,n;
  cin >> h >> n;
  ll a[n];
  rep(i,n)cin >> a[i];
  ll sum=0;
  rep(i,n)sum+=a[i];
  if(sum>=h)cout << "Yes" << endl;
  else cout << "No" << endl;
return 0;}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!
    val xs = f(s)

    var r = 0

    for (i in (0 until xs.size step 2)) {

        val l = if (i + 2 * k < xs.size) {
            i + 2 * k
        } else {
            xs.size - 1
        }

        val x = xs[l] - (if (i > 0) xs[i - 1] else 0)

        r = Math.max(r, x)
    }

    println(r)
}

private fun f(s: String): List<Int> {
    val xs = mutableListOf(0, 0)

    if (s[0] == '0') {
        xs.add(0)
    }

    if (s.length == 1) {
        xs.add(1)
        return xs
    }

    var x = 1
    var c = s[0]
    s.substring(1).forEach {
        if (it != c) {
            xs.add(xs.last() + x)
            x = 0
        }
        x++
        c = it
    }

    xs.add(xs.last() + x)

    if (s.last() == '0') {
        xs.add(xs.last())
    }

    return xs
}

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

#define mp make_pair
#define pb push_back
#define f first
#define s second 
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define int long long
#define forn(i, x, y) for(int i = x; i <= y; i++)
#define forev(i, y, x) for(int i = y; i >= x; i--)

using namespace std;

const int maxn = (int)3e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int)1e6 + 7;
const int inf = (int)1e9 + 7;

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

using namespace std;

int n, x,q,tin[maxn],tout[maxn],timer,ans[maxn],pref[maxn],pos[maxn];
vi g[maxn];
void dfs(int v,int p=-1){
	tin[v]=++timer;
	pos[timer]=v;
	for(auto to:g[v])
		if(to != p)
			dfs(to,v);
	tout[v]=timer;
}	
main () {
	cin>>n>>q;
	forn(i,1,n-1){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1);
	while(q--){
		int p,x;
		cin>>p>>x;
		pref[tin[p]]+=x;
		pref[tout[p]+1]-=x;
	}
	forn(i,1,n)
		pref[i]+=pref[i-1],ans[pos[i]]=pref[i];
	forn(i,1,n)cout<<ans[i]<<" ";
}

Measured memory_bytes: 36480
#!/usr/bin/env python
rank = [0 for i in range(4)]
for _ in range(3):
    a, b = map(int, input().split())
    rank[a - 1] += 1
    rank[b - 1] += 1
print('YES' if sorted(rank) == [1, 1, 2, 2] else 'NO')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    int n,m;cin>>n>>m;
    dsu d(n);
    REP(i,m){
        int a,b;cin>>a>>b;a--;b--;
        d.merge(a,b);
    }
    cout<<d.groups().size()-1<<endl;
}

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

Measured memory_bytes: 8840
import sys
input = sys.stdin.readline
from collections import Counter,defaultdict
n=int(input())
al=[float("inf")]*26
a=ord("a")
#print(a)
for i in range(n):
    s=input().strip()
    for i in range(26):
        al[i]=min(al[i],s.count(chr(i+a)))
rep=""
for i,k in enumerate(al):
    for j in range(k):
        rep+=chr(i+a)
print(rep)


Measured memory_bytes: 40688
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n,k,l,r;
    cin>>n>>k>>l>>r;
    vector<ll> a(n),b,c;
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n/2;i++) b.push_back(a[i]);
    for(ll i=n/2;i<n;i++) c.push_back(a[i]);

    ll bn = n/2,cn = n-n/2;
    vector<mp> bb,cc;//i個の数字でできる数
    for(ll i=0;i< (1<<bn);i++){
	ll cnt = 0;
	ll sum = 0;
	for(ll j=0;j<bn;j++){
	    if( (i>>j)&1 ){
		cnt++;
		sum += b[j];
	    }
	}
	bb.push_back( mp(cnt, sum ) );
    }
    for(ll i=0;i< (1<<cn);i++){
	ll cnt = 0;
	ll sum = 0;
	for(ll j=0;j<cn;j++){
	    if( (i>>j)&1 ){
		cnt++;
		sum += c[j];
	    }
	}
	cc.push_back( mp(cnt, sum) );
    }
    sort( bb.begin(), bb.end() );
    sort( cc.begin(), cc.end() );
    ll res = 0;
    for(auto it:bb){
	ll bi = it.first;
	ll bs = it.second;
	auto s = lower_bound(cc.begin(),cc.end(), mp(k-bi,l-bs) );
	auto t = upper_bound(cc.begin(),cc.end(), mp(k-bi,r-bs) );
	res += (t-s);
    }
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 43744
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define MOD2 (lli) 998244353  
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

void no(){
  cout << "No" << endl;
  exit(0);
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 
  int n;
  cin >> n;
  vector<int> vec;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    vec.push_back(a);
  }

  for(int i=0;i<sz(vec)-1;i++){
    if(vec[i] > vec[i+1]) vec[i]--;
    else if(vec[i] <= vec[i+1] and vec[i] > 1){
      if(!i){
        vec[i]--;
      } else {
        if(vec[i]-1 >= vec[i-1]) vec[i]--;
      }
    }
  }

  for(int i=0;i<sz(vec)-1;i++){
    if(vec[i] > vec[i+1]) no();
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, k, n) for (int i = k; i <= n; ++i)
#define REPR(i, k, n) for(int i = n; i >= k; --i)
using namespace std;

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

    int N, sum = 0;
    cin >> N;
    REP(i,1,N){
        sum += i;
    }
   cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let s : String = get_one();
    let ans = "ABC".to_string() + &s;
    println!("{}", ans);
}


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


int main()
{
  	int N, K;
	string S;
	cin >> N >> K >> S;
	if (S.at(K-1) == 'A'){
		S.at(K-1) = 'a';
	}
	else if (S.at(K-1) == 'B'){
		S.at(K-1) = 'b';
	}
	else{
		S.at(K-1) = 'c';
	}
	cout << S << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.stream.DoubleStream;
import java.util.stream.Stream;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String line;
      String[] lines;
      double[] s;
      while( !(line = br.readLine()).equals("0") ){

        int n = Integer.parseInt(line);
        lines = br.readLine().split(" ");

        s =
          Stream.of(lines)
            .mapToDouble(Double::parseDouble)
            .toArray();
        
        double dm =
          Arrays.stream(s)
            .average()
          .getAsDouble();

        double result =
        Arrays.stream(s)
          .map(d -> Math.pow((d-dm),2))
          .sum();
        result = Math.sqrt((result)/n);

        System.out.printf("%.8f\n" ,result);
      }
    }
  }
}


Measured memory_bytes: 32056
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 998244353;

long long int modpow(long long int b, long long int p){// modinv(x) = modpow(x, MOD-2)
    long long int num = 1, power = b;
    for(int i=0; i<=30; i++){
        if((p>>i) & 1){
            num *= power;
            num %= MOD;
        }

        power *= power;
        power %= MOD;
    }
    return num;
}

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

    int sum = 0;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }

    vector<vector<long long int>> dp1(n+1, vector<long long int>(sum+1));
    vector<vector<long long int>> dp2(n+1, vector<long long int>(sum+1));
    dp1[0][0] = 1;
    dp2[0][0] = 1;
    for(int i=0; i<n; i++){
        for(int j=0; j<=sum; j++){
            if(j - a[i] >= 0) dp1[i+1][j] += dp1[i][j-a[i]];
            dp1[i+1][j] += dp1[i][j] * 2;
            dp1[i+1][j] %= MOD;

            if(j - a[i] >= 0) dp2[i+1][j] += dp2[i][j-a[i]];
            dp2[i+1][j] += dp2[i][j];
            dp2[i+1][j] %= MOD;
        }
    }

    long long int ans = modpow(3,n);
    long long int sub1 = 0;
    for(int j=(sum+1)/2; j<=sum; j++){
        sub1 += dp1[n][j];
        sub1 %= MOD;
    }
    long long int sub2 = 0;
    if(sum % 2 == 0) sub2 = dp2[n][sum/2];

    ans = ((ans - sub1 * 3 + sub2 * 3) % MOD + MOD) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 426596
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i ++)
#define pb push_back
#define mp make_pair

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
const ll power = 49999;

ll n, k;

int main()
{

#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	forn(i, 0, 15)
	{
		forn(j, 0, 26)
			if (7 * i + j * 4 == n)
			{
				cout << "Yes";
				return 0;
			}
	}
	cout << "No";

	return 0;
}


Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]

a = [1 for i in range(n+1)]
for i in range(m):
    a[int(input())] = 0

dp = [0 for i in range(n + 1)]
dp[0] = 1
if a[1]:
    dp[1] = 1

for i in range(2, n + 1):
    dp[i] = a[i] * (dp[i-2] * a[i-2] + dp[i-1] * a[i-1])

print(dp[-1] % 1000000007)


Measured memory_bytes: 507440
#include <iostream>
using namespace std;
const int me = 1e5;
int a[me], b[me], c[me];

int main() {
	int n;
	cin>>n;
	
	for(int i=0; i<n; i++) {
	    cin>>a[i];
	    //cout<<a[i]<<endl;
	}
	
	for(int i=0; i<n; i++) {
	    cin>>b[i];
	}
	for(int i=0; i<n-1; i++) {
	    cin>>c[i];
	}
	
	int prev = -2;
	int sm = 0;
	for(int i=0; i<n; i++) {
	    //cout<<(a[i]-1)<<" "<<b[a[i]-1]<<endl;
	    sm+=b[a[i]-1];
	    if((a[i]-prev)==1) {
	        sm+=c[prev-1];
	    }
	    prev = a[i];
	}
	
	cout<<sm<<endl;
	return 0;
}

Measured memory_bytes: 256
import math

N, D = map(int, input().split())
point_list = list(list(map(int, input().split())) for i in range(N))
tmp = 0
output = 0

for k in range(N - 1):
    X = point_list[k]
    for l in range(k + 1, N):
        Y = point_list[l]
        for i in range(D):
            tmp += (X[i] - Y[i]) ** 2

        if math.sqrt(tmp).is_integer():
           output += 1

        tmp = 0

print(output)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main()
{
    unsigned short *A, *B;

    int C[VMAX + 1];
    int n, i, j;
    scanf("%d", &n);

    
    A = malloc(sizeof(short) * n + 1);
    B = malloc(sizeof(short) * n + 1);

    for (i = 0; i <= VMAX; i++)
        C[i] = 0;

    for (i = 0; i < n; i++)
    {
        scanf("%hu", &A[i + 1]);
        C[A[i + 1]]++;
    }

    for (i = 1; i <= VMAX; i++)
        C[i] = C[i] + C[i - 1];

    for (j = 1; j <= n; j++)
    {
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }

    for (i = 1; i <= n; i++)
    {
        if (i > 1)
            printf(" ");
        printf("%d", B[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 9656
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=2e5+5;
const ll INF=1e18;

int n;
ll mid;
vector<pll> f[MAXN];
int tot,h[MAXN];
struct node{
    int to,w,nxt;
}edge[MAXN];

void addedge(int u,int v,int w){
    edge[++tot]=(node){v,w,h[u]}; h[u]=tot;
}

void ins(int u,pll x){
    if(!f[u].empty()&&f[u].back()<=x) return ;
    while(!f[u].empty()&&f[u].back().second>=x.second) f[u].pop_back();
    f[u].push_back(x);
}

bool dfs(int u){
    f[u].clear();
    if(!h[u]){
        f[u].push_back(make_pair(0,0));
        return 1;
    }
    int ls=0,rs=0;
    ll disl=0,disr=0;
    for(int i=h[u];i;i=edge[i].nxt){
        int v=edge[i].to;
        if(!dfs(v)) return 0;
        if(!ls) ls=v,disl=edge[i].w;
        else rs=v,disr=edge[i].w;
    }
    ll lim=mid-disl-disr;
    if(lim<0) return 0;
    vector<pll> vl,vr;
    int pl=0,pr=0,sl=f[ls].size(),sr=f[rs].size();
    for(int i=0;i<sl;i++){
        while(pr<sr&&f[ls][i].second+f[rs][pr].first>lim) pr++;
        if(pr==sr) break;
        else vl.push_back(make_pair(f[ls][i].first+disl,f[rs][pr].second+disr));
    }
    for(int i=0;i<sr;i++){
        while(pl<sl&&f[rs][i].second+f[ls][pl].first>lim) pl++;
        if(pl==sl) break;
        else vr.push_back(make_pair(f[rs][i].first+disr,f[ls][pl].second+disl));
    }
    pl=pr=0,sl=vl.size(),sr=vr.size();
    while(pl<sl&&pr<sr){
        if(vl[pl].first>vr[pr].first) ins(u,vl[pl++]);
        else ins(u,vr[pr++]);
    }
    while(pl<sl) ins(u,vl[pl++]);
    while(pr<sr) ins(u,vr[pr++]);
    return !f[u].empty();
}

int main(){
    scanf("%d",&n);
    for(int i=2,a,v;i<=n;i++) scanf("%d%d",&a,&v),addedge(a,i,v);
    ll l=0,r=INF,ret=0;
    while(l<=r) {
        mid=(l+r)>>1;
        if(dfs(1)) ret=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%lld\n",ret);
}


Measured memory_bytes: 31408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;
map<string,int>mp;

int main(){
  string s;
  cin>>s;
  mp["SUN"]=7;
  mp["MON"]=6;
  mp["TUE"]=5;
  mp["WED"]=4;
  mp["THU"]=3;
  mp["FRI"]=2;
  mp["SAT"]=1;
  cout<<mp[s]<<endl;

  return(0);
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(400*400*1000)
from collections import Counter
def rec(union_id, i, j):
    symbol = S[i][j]
    if union_white[i][j] != 0:
        return
    if symbol == '.':
        union_white[i][j] = union_id
        next_symbol = '#'
    else:
        union_white[i][j] = -1
        next_symbol = '.'
        union_black[union_id] += 1

    if i >= 1 and S[i-1][j] == next_symbol:
        rec(union_id, i-1, j)
    if i < H-1 and S[i+1][j] == next_symbol:
        rec(union_id, i+1, j)
    if j >= 1 and S[i][j-1] == next_symbol:
        rec(union_id, i, j-1)
    if j < W-1 and S[i][j+1] == next_symbol:
        rec(union_id, i, j+1)

    return
H, W = map(int, input().split())
S = [input() for h in range(H)]
ans = 0
union_white = [[0 for w in range(W)]for h in range(H)]
union_black = Counter()
count_black = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '.' or union_white[i][j] != 0:
            continue
        count_black += 1
        rec(count_black, i, j)

counter = Counter([x for Si in union_white for x in Si])
ans = 0
# print(counter)
# print(union_black)
# print(union_white)
for i in union_black.keys():
    ans += counter[i] * union_black[i]

print(ans)


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

using namespace std;
	
	
class Hoge{
			int A,B,T,inum;
			
		
		public:
			Hoge(){
								
					}
			
			
		void input();
		
		
	int getinum() const{return inum;}

			

									
		virtual ~Hoge(){	
					
					
					//cout<<"pyama is erased."<<endl;
						}
};



void Hoge::input(){
		
					//cin>>A;
					//cin>>B;
					//cin>>T;
					cin>>A>>B>>T;
						
					//cout<<"T/A="<<T/A<<endl;
					inum=T/A*B;
					
					}
					
					


int main()
{
	int inum;
	Hoge* ph0=new Hoge();
	ph0->input();
	
	inum=ph0->getinum();
	cout<<inum<<endl;
	delete ph0;
	
}

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;

int main() {
    string a,b;cin>>a>>b;
    int a1,b1;
    if(a[0]=='H')a1=1;
    else a1=-1;

    if(b[0]=='H')b1=1;
    else b1=-1;    
    
    if(a1*b1==1)cout<<'H'<<endl;
    else cout<<'D'<<endl;

	return 0;
}

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

using namespace std;

int n,l,r,x,a[120000];
char s[10];

void ask(int x){
	printf("%d\n",x); fflush(stdout);
	scanf("%s",s+1);
	if (s[1]=='V') exit(0);
	if (s[1]=='M') a[x]=1;
	if (s[1]=='F') a[x]=2;
}

int main(){
	scanf("%d",&n);
	ask(0); ask(n-1); l=0,r=n-1;
	for (int i=1;i<=20;i++){
		int mid=(l+r)>>1;
		ask(mid);
		if ((!((l^mid)&1)&&a[l]!=a[mid])||(((l^mid)&1)&&(a[l]==a[mid]))) r=mid;
		else l=mid;
	}
	
	return 0;
}
			

Measured memory_bytes: 852
"use strict"
function main(arg) {
    arg = arg.trim().split("\n")[0]
    var N = arg.split(" ").map(Number)[0]
    var L = arg.split(" ").map(Number)[1]
    // console.log([N,L])
    const absMin = (a, b) => {
        if (Math.abs(a) < Math.abs(b)) {
            return a
        }
        return b
    }
    var min = Number.MAX_VALUE
    var sum = 0
    for (var i = 1; i <= N; i++) {
        var t = L + i -1
        sum += t
        min = absMin(t, min)
    }
    console.log(sum - min)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
    ll a,b;
    cin >> a >> b;
    if(a > 0) {
      	cout << "Positive" << endl;
      	return 0;
    }
  	else if(a <= 0 && 0 <= b){
    	cout << "Zero" << endl;
      	return 0;
    }
    int c = a - b;
    if(c%2 == 0) cout << "Negative" << endl;
    else cout << "Positive" << endl;
}

Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

A = np.array(A, dtype=int)
A.sort()
cs = A.cumsum()

ng = 0
for i in range(N - 1):
    if cs[i] * 2 < A[i + 1]:
        ng = i + 1
print(N - ng)


Measured memory_bytes: 24308
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
void Digvijay()
{
   int n,k;
   cin>>n>>k;
   int tmp=(n*(n+1))/2;
   int ans = 0;
   for(int i=k;i<=n+1;i++)
   {
       int val1 = ((n-i)*(n-i+1))/2;
       val1=tmp-val1;
       int val2=(i*(i-1))/2;
       //cout<<val1<<" "<<val2<<"\n";
       ans+=(val1-val2+1);
       ans%=mod;
   }
   cout<<ans<<"\n";
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=0;__<_;__++)
    {
        Digvijay();
    }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;
const int INF = 1000000000;

int main()
{
    int num_book, num_algo, min_level;
    cin >> num_book  >> num_algo >> min_level;

    vector<int> costs(num_book);
    vector<vector<int>> algo(num_book, vector<int>(num_algo, 0));
    rep(i, 0, num_book)
    {
        cin >> costs[i];
        rep(j, 0, num_algo)
            cin >> algo[i][j];
    }

    // full search
    int min_cost = INF;
    for (int status=0; status<(1<<12); ++status)
    {
        vector<int> levels(num_algo, 0);
        int cost = 0;
        rep(i, 0, num_book)
        {
            if ((status>>i)&1)
            {
                cost += costs[i];
                rep(j, 0, num_algo)
                    levels[j] += algo[i][j];
            }
        }
        // check level
        bool is_ok = true;
        rep(i, 0, num_algo)
            if (levels[i] < min_level)
            {
                is_ok = false;
                break;
            }
        if (is_ok)
            min_cost = min(min_cost, cost);
    }

    if (min_cost == INF)
        cout << -1 << endl;
    else
        cout << min_cost << endl;
    return 0;
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

// m > n >= 0
template <class T>
T gcd(T m, T n)
{
    if (m<n) swap(m,n);
    if (n == 0)
        return m;
    return gcd(n, m % n);
}

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

    i64 sum = 0;
    for (int i = 1; i <= k; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            for (int h = 1; h <= k; h++)
            {
                int g = gcd(i, j);
                sum += gcd(g, h);
            }
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<assert.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;//角度转弧度 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 1e6+10, M = 1e6+10;
int n;
int main() {
	cin>>n;
	ll ans = 0;
	for(int i = 1;i < n;i++) {
		int tmp = n - i;
		for(int j = 1;j * j <= tmp;j++) {
			if(tmp % j == 0) {
				if(j != tmp / j) ans += 2;
				else ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3532
def A():
    temp = input().split()
    S = temp[0]
    T = temp[1]
    temp = [int(i) for i in input().split()]
    A = temp[0]
    B = temp[1]
    U = input()
    if U == S:
        print(A-1, B)
    else:
        print(A, B-1)

def B():
    print('x'*len(input()))

def C():
    N = int(input())
    A = [int(i) for i in input().split()]
    if N > len(set(A)):
        print('NO')
    else:
        print('YES')

def D():
    temp = [int(i) for i in input().split()]
    N = temp[0]
    K = temp[1]
    p = [int(i) for i in input().split()]
    expected_val = [(i+1)/2.0 for i in p]
    cur = sum(expected_val[:K])
    ans = cur
    for i in range(N-K):
        cur -= expected_val[i]
        cur += expected_val[i+K]
        ans = max(ans, cur)
    print(ans)

def E():
    #https://www.geeksforgeeks.org/count-of-numbers-in-range-where-the-number-does-not-contain-more-than-k-non-zero-digits/
    def countInRangeUtil(pos, cnt, tight, num): 
        if pos == len(num): 
            if cnt == K: 
                return 1
            return 0
    
        if dp[pos][cnt][tight] != -1: 
            return dp[pos][cnt][tight] 
    
        ans = 0
    
        limit = 9 if tight else num[pos] 
    
        for dig in range(limit + 1): 
            currCnt = cnt 
    
            if dig != 0: 
                currCnt += 1
    
            currTight = tight 
    
            if dig < num[pos]: 
                currTight = 1
    
            ans += countInRangeUtil(pos + 1, currCnt, currTight, num) 
    
        dp[pos][cnt][tight] = ans 
        return dp[pos][cnt][tight] 

    global dp, K, M 
    N = int(input())
    K = int(input())
    M = 100
  
    num = [] 
    while N: 
        num.append(N % 10) 
        N //= 10
  
    num.reverse() 
  
    # Initialize dp 
    dp = [[[-1, -1] for i in range(M)] for j in range(M)] 
    print(countInRangeUtil(0, 0, 0, num)) 
  

E()

Measured memory_bytes: 4084
#include <iostream>
using namespace std;
int main(void){
    int H, W, X, Y, A, B;
    cin >> H >> W >> X >> Y;
    A = H * W;
    B = X + Y;
    if(A % 2 == 1 && B % 2 == 1){
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;
    return 0;
    
    
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define N 200010
using namespace std;
int n,m=0;
int a[N];
int f[N];
int main() {
	memset(f,0,sizeof(f));
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=n;i>=1;i--) {
		int tot=0;
		for(int j=i;j<=n;j+=i)
			tot+=f[j];
		if(tot%2!=a[i])
			f[i]=1;
	}
	for(int i=1;i<=n;i++)
		m+=f[i];
	printf("%d\n",m);
	for(int i=1;i<=n;i++)
		if(f[i]) printf("%d ",i);
	return 0;
}

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

int main(){
  long long N;
  cin >> N;
  int sqN = (int)ceil((int)sqrt(N));
  int ans = 10000;
  for (int i=1; i<sqN+1; i++){
    if (N%i == 0){
      string istr = to_string(i);
      string jstr = to_string((long long)N/i);
      int leng = max(istr.size(),jstr.size());
      ans = min(ans,leng);
    }
  }
  cout << ans << endl;
}


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

// 切り上げ関数
// a÷bの切り上げ
int round_up(int a, int b)
{
    return (a + b - 1) / b;
}

int main()
{
    int a, b;
    cin >> a >> b;
    // cout << (a + b + 2 - 1) / 2 << endl;
    cout << round_up(a + b, 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	iota(a.begin(), a.end(), 1);
	int errorcnt = 0;
	for( int i = 0; i < n; ++i ){
		int k; cin >> k;
		if( a[i] != k ) ++errorcnt;
	}
	if( errorcnt <= 2 ) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main() {
	int h, w; cin >> h >> w;
	vector<string> s(h); rep(i, 0, h) cin >> s[i];

	rep(i, 0, h) {
		rep(j, 0, w) {
			if (s[i][j] == '.') {
				int counter = 0;
				rep(dx, -1, 2) {
					if ((i + dx < 0) || (i + dx > h - 1)) continue;
					rep(dy, -1, 2) {
						if ((j + dy < 0) || (j + dy > w - 1)) continue;
						if (s[i + dx][j + dy] == '#') counter++;
					}
				}
				string str = to_string(counter);
				s[i][j] = str[0];
			}
		}
	}

	for (auto& x : s) cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(); 
		int B = sc.nextInt(); 
		int C = sc.nextInt(); 
		int sw = 0;
		for(int i = 0; i < 1000; i++) {
			if(A*i%B == C) {
				System.out.println("YES");
				sw = 1;
				break;
			}
		}
		if(sw == 0)System.out.println("NO");
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (a).size()
#define pb(a) push_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
using namespace std;
using 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; }
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr double EPS = 1e-10;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  cin >> s;
  if (sz(s) == 2) {
    cout << s << endl;
    return 0;
  }
  reverse(all(s));
  cout << s << endl;

  return 0;
}

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

a = tuple(map(int, input().split(" ")))

a_count = dict()
for a_i in a:
	if a_i not in a_count:
		a_count[a_i] = 0
	a_count[a_i] += 1

print(sum(sorted(a_count.values())[:len(a_count)-k]))

Measured memory_bytes: 32448
#include<stdio.h>
int main(){
 
  int a,b;
  scanf("%d%d",&a,&b);
  if(a<b){printf("a < b\n");}
  if(a>b){printf("a > b\n");}
  if(a==b){printf("a == b\n");}
 return 0;
}

Measured memory_bytes: 1008
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
	long long int n, k,q;
	int a[200000];
	int point[200000];

	cin >> n>>k>>q;
	for (int i = 1;i <= n;i++)
		point[i] = 0;
	for (int i=0;i < q;i++)
		cin >> a[i];
	
	for (int i = 0;i < q;i++)
	{
      	point[a[i]]++;
	}
	for (int i = 1;i <= n;i++)
	{
		if (k - q + point[i] > 0)
			cout << "Yes"<<endl;
		else
			cout << "No"<<endl;
	}


	return 0;
}

Measured memory_bytes: 1408
<?php
fscanf(STDIN, '%d', $H);
$ans = 0;
for ($i = 0; true; $i++) {
    if ($H == 1) {
        $ans += 2 ** $i;
        break;
    }
    $ans += 2 ** $i;
    $H = floor($H/2);
}
echo $ans;

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

int main()
{
  int a,b,c;
  int x,y;
  cin>>a>>b>>c>>x>>y;
  long long ans=0;
  int count=0;
  ans=(x*a)+(y*b);
  int d=((2*c)-(a+b));
  if(d<0)
  {
    ans+=(d*min(x,y));
    if(x<y && (2*c)<b)ans+=((2*c*(y-x))-((y-x)*b));
    else if(y>x && (2*c)<a)ans+=((2*c*(x-y))-((x-y)*b));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int data[30];
	int i;
	int in;
	for(i=0;i<30;i++){
		data[i]=0;
	}
	for(i=0;i<28;i++){
		scanf("%d",&in);
		data[in-1]=1;
	}
	for(i=0;i<30;i++){
		if(data[i]==0){
			printf("%d\n",i+1);
		}
	}
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define T int t;cin>>t;rep(i,t)

void solve() {

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = 0;
	if (d > a) {
		ans += a;
		d -= a;
	}
	else{
		ans += d;
		d = 0;
	}
	
	if (d > b)
		d -= b;
	else
		d = 0;
		
	if (d > 0)
		ans -= d;
		
	cout << ans;
		
}

int main()
{
    fastio;
//    T
    solve();
	//code
	return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

int main() {
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0) {
			break;
		}
		for (int j = 0;j < H;j++) {
			for (int i = 0; i < W; i++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3132
#include <iostream>
using namespace std;
int main(void){
    while(true){
        int num, num2;
        cin >> num >> num2;
        if ((num == 0) && (num2 == 0)){
            break;
        }
        else if (num > num2){
            int tmp;
            tmp = num;
            num = num2;
            num2 = tmp;
        }
        cout << num << " " << num2 << endl;
    }
}



Measured memory_bytes: 2984
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;

const int N=100005,mod=1e9+7;
inline void ch(int &x,int y){x+=y;if(x>=mod) x-=mod;}
int n,m,ax,ay,a[N];

int main(){
#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
		ch(ax,(ll)(a[i+1]-a[i])*i%mod*(n-i)%mod);
	for(int i=1;i<=m;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<m;i++)
		ch(ay,(ll)(a[i+1]-a[i])*i%mod*(m-i)%mod);
	printf("%lld\n",(ll)ax*ay%mod);
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = x[0];
            int M = x[1];
            var out1 = new int[N];
            var A = new int[N][];
            for (var i = 0; i < N; i++) A[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var C = new int[M][];
            for (var i = 0; i < M; i++) C[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            for (int i = 0; i < N; i++)
            {
                int l = D(A[i], C[0]);
                out1[i] = 1;
                for (int j = 0; j < M; j++)
                {
                    if (D(A[i], C[j]) < l)
                    {
                        l = D(A[i], C[j]);
                        out1[i] = j + 1;
                    }
                }
                Console.WriteLine(out1[i]);
            }
        }

        static int D(int[] a, int[] b)
        {
            return Math.Abs(a[0] - b[0]) + Math.Abs(a[1] - b[1]);
        }
    }
}

Measured memory_bytes: 13396
# frozen_string_literal: true

# induce sort (internal routine)
def sa_is_induce(s, ls, sum_l, sum_s, lms)
  n = s.size
  sa = [-1]*n

  buf = *sum_s # deep copy
  lms.each{ |lms|
    if lms != n then
      sa[buf[s[lms]]] = lms
      buf[s[lms]] += 1
    end
  }

  buf = *sum_l # deep copy
  sa[buf[s[-1]]] = n-1
  buf[s[-1]] += 1
  sa.each{ |v|
    if v>=1 && !ls[v-1] then
      sa[buf[s[v-1]]] = v-1
      buf[s[v-1]] += 1
    end
  }

  buf = *sum_l # deep copy
  sa.reverse_each{ |v|
    if v>=1 && ls[v-1] then
      buf[s[v-1]+1] -= 1
      sa[buf[s[v-1]+1]] = v-1
    end
  }

  return sa
end

# SA-IS (internal routine)
def sa_is(s, upper)
  n = s.size

  return [] if n == 0
  return [0] if n == 1

  ls = [false]*n
  (n-2).downto(0){ |i|
    ls[i] = s[i]==s[i+1] ? ls[i+1] : s[i]<s[i+1]
  }

  sum_l = [0]*(upper+1)
  sum_s = [0]*(upper+1)
  s.zip(ls){ |s, ls|
    if ls then
      sum_l[s+1] += 1
    else
      sum_s[s] += 1
    end
  }
  0.upto(upper){ |i|
    sum_s[i] += sum_l[i]
    sum_l[i+1] += sum_s[i] if i<upper
  }

  lms = (1 ... n).select{ |i| !ls[i-1] && ls[i] }
  m=lms.size
  lms_map = [-1]*(n+1)
  lms.each_with_index{ |lms, id| lms_map[lms] = id }

  sa = sa_is_induce(s, ls, sum_l, sum_s, lms)

  return sa if m == 0

  sorted_lms = sa.select{ |sa| lms_map[sa] != -1 }
  rec_s = [0]*m
  rec_upper = 0
  rec_s[lms_map[sorted_lms[0]]] = 0
  1.upto(m-1){ |i|
    l, r = sorted_lms[i-1, 2]
    end_l = lms[lms_map[l]+1]||n
    end_r = lms[lms_map[r]+1]||n
    same = true
    if end_l-l != end_r-r then
      same = false
    else
      while l < end_l do
        break if s[l] != s[r]
        l+=1
        r+=1
      end
      same = false if l==n || s[l]!=s[r]
    end
    rec_upper += 1 if not same
    rec_s[lms_map[sorted_lms[i]]] = rec_upper
  }

  sa_is(rec_s, rec_upper).each_with_index{ |rec_sa, id|
    sorted_lms[id] = lms[rec_sa]
  }

  return sa_is_induce(s, ls, sum_l, sum_s, sorted_lms)
end

# suffix array for array of integers
def suffix_array(s, upper = nil)
  if not upper then
    # compression
    n = s.size
    idx = (0 ... n).sort_by{ |l, r| s[l] < s[r] }
    t = [0]*n
    upper = 0
    t[idx[0]] = 0
    idx.each_cons(2){ |i, j|
      upper += 1 if s[i] != s[j]
      t[j] = upper
    }
    s = t
  end

  return sa_is(s, upper)
end

# suffix array for string
def suffix_array(s)
  return sa_is(s.bytes, 255)
end

# lcp array for array of integers
def lcp(s, sa)
  n = s.size
  rnk = [0]*n
  sa.each_with_index{ |sa, id|
    rnk[sa] = id
  }
  
  lcp = [0]*(n-1)
  h = 0
  n.times{ |i|
    h -= 1 if h > 0
    next if rnk[i] == 0
    j = sa[rnk[i]-1]
    h += 1 while j+h<n && i+h<n && s[j+h]==s[i+h]
    lcp[rnk[i]-1] = h
  }
  return lcp
end

# lcp array for string
def lcp_array(s, sa)
  return lcp(s.bytes, sa)
end

s = gets.chomp
lcp = lcp_array(s, suffix_array(s))
ans = s.size*(s.size+1)/2
lcp.each{ |lcp|
  ans -= lcp
}
puts ans


Measured memory_bytes: 67440
#include "bits/stdc++.h"
 
using namespace std;
 
#define pb push_back
#define mp make_pair
constexpr int INF = 1 << 29;
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
 
constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};
 
int main() {
	vector<int> A;
	A.push_back(1);
	for(int i = 1; pow(6, i) <= 100000; i++) {
		A.push_back(pow(6, i));
	}
	for(int i = 1; pow(9, i) <= 100000; i++) {
		A.push_back(pow(9, i));
	}
	int N;
	cin >> N;

	vector<int> dp(N + 1,INF);
	dp[0] = 0;

	for(int i = 0; i <= N; i++) {
		for(int j = 0; j < A.size(); j++) {
			if (i - A[j] >= 0) {
				dp[i] = min(dp[i], dp[i - A[j]] + 1);
			}
		}
	}

	cout << dp[N] << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(void){
    string T;
    cin >> T;
    ll ans=T.size();
    if(ans&1) ans=(ans+1)*(ans+1)/4;
    else ans=ans*ans/4+ans/2;
    int r=1;
    vector<ll> v{0};
    for(int i=0; i<T.size(); ++i){
        if(T[i]=='0'){
            if(i%2==r) ++v.back();
            else{
                v.emplace_back(1);
                r=1-r;
            }
        }
    }
    for(int i=0; i<v.size(); ++i) ans -= v[i]*((i+1)/2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5436