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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		
		int input = in.nextInt();
		long[] a = new long[input];
		long max = (long)Math.pow(10, 18);
		long ans = 1;
		for(int i = 0;i<input;i++) {
			a[i] = in.nextLong();
		}
		for(int i = 0;i<input;i++) {
		if(a[i] == 0) {
			ans = 0;
			break;
		}
		else if(a[i]>(max/ans)) {
			ans = -1;
		}
		else {
			ans = ans * a[i];
		}
		
		
	}
		System.out.println(ans);

 
 }
}


Measured memory_bytes: 51068
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;

int main() {
    cout << fixed << setprecision(6);

    long double x, h;
    while (true) {
        cin >> x >> h;
        if (x == 0 && h == 0) break;
        cout << x * x + 2 * x * sqrt(h * h + x * x / 4) << endl;
    }
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
    #define rep(i, n) for (int i = 0; i < (n); ++i)
    using namespace std;
    typedef long long ll;
     
    int main()
    {
        int n;
        cin >> n;
        vector<int> d(n);
        rep(i, n) cin >> d[i];
        int ans = 0;
        rep(i, n) for (int j = i + 1; j < n; j++)
        {
            ans += d[i] * d[j];
        }
        cout << ans << endl;
     
        return 0;
    }

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n;
    cin >> n;
    vector<ll> ans(10000000,0);
    
    for(ll x=1;x<=100;x++){
        for(ll y=1;y<=100;y++){
            for(ll z=1;z<=100;z++){
                ll now=x*x+y*y+z*z+x*y+y*z+z*x;
                ans[now]++;
            }
        }
    }
    
    for(ll i=1;i<=n;i++){
        cout << ans[i] << endl;
    }
    
    return 0;
}











Measured memory_bytes: 81312
#include<bits/stdc++.h>
using namespace std;
long long dp[100001]={-1};
void ini()
{
for(int i=0;i<100001;i++)
dp[i]=-1;
}

long long ans(int n,int a[])
{

if(dp[n]!=-1)
return dp[n];
else if(n==1)
dp[n]=abs(a[n]-a[n-1]);
else if(n==0)
dp[n]=0;
else
dp[n]=min(ans(n-1,a)+abs(a[n]-a[n-1]),ans(n-2,a)+abs(a[n]-a[n-2]));
return dp[n];
}
int main()
{
ini();
//cout<<dp[0]<<" "<<dp[1]<<endl;
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
long long k=ans(n-1,a);
cout<<k<<endl;
return 0;
}



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

typedef long long int ll;

int main()
{
    ll n;
    cin >> n;
    vector<char> s(n);
    for(ll i = 0;i < n;i++){
        cin >> s[i];
    }

    bool pwgy[4];
    pwgy[0] = pwgy[1] = pwgy[2] = pwgy[3] = false;
    for(ll i = 0;i < n;i++){
        if(s[i] == 'P'){
            pwgy[0] = true;
        }
        else if(s[i] == 'W'){
            pwgy[1] = true;
        }
        else if(s[i] == 'G'){
            pwgy[2] = true;
        }
        else{
            pwgy[3] = true;
        }
    }

    ll cnt = 0;
    for(ll i = 0;i < 4;i++){
        if(pwgy[i]){
            cnt++;
        }
    }

    if(cnt == 3){
        cout << "Three";
    }
    else{
        cout << "Four";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N, T, check,minC=1001;
    cin >> N >> T;
    check =0;
    int c[N],t[N];
    
    for(int i=0;i<N;i++)
    {
        cin >> c[i] >> t[i];
    }
    
    for(int i=0;i<N;i++)
    {
        if(t[i]<=T && c[i]<=minC)
        {
            minC=c[i];
            check++;
        }
    }
    
    if(check==0)
    {
        cout << "TLE" << endl;
    }else{
    cout << minC << endl;
    }
}
            

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val line = readLine()!!.trim()
    val n: Int = line[0].toInt()
    val a: Int = 'A'.toInt()
    val z: Int = 'Z'.toInt()

    if (a <= n && n <= z) {
        println("A")
    } else {
        println("a")
    }
}

Measured memory_bytes: 35732
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 10000000;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };

int gcd(int a, int b) {
	if (!b)return a; return gcd(b, a%b);
}
int cnt[1000];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, n) {
		int k; cin >> k;
		rep(j, k) {
			int a; cin >> a; cnt[a]++;
		}
	}
	int ans = 0;
	rep(i, 100)if (cnt[i] == n)ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main()
{
	int N;
	cin >> N;
	vector<int> D1(N),D2(N);
	for(int i = 0;i<N;i++)
	{
		cin >> D1.at(i) >> D2.at(i);
	}
	
	for(int i = 0;i<N-2;i++)
	{
		if(D1.at(i)==D2.at(i))
		{
			if(D1.at(i+1)==D2.at(i+1))
			{
				if(D1.at(i+2)==D2.at(i+2))
				{
					cout << "Yes" << endl;
					goto end;
				}
				else i=i+2;
			}
			else i=i+1;
		}
	}
	
	cout << "No" << endl;
	end: return 0;
}

Measured memory_bytes: 3608
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

fun solve() {
    val n = inf.readLine()!!.toInt()
    var ans = 0
    var prev = -2
    inf.readLine()!!.split(' ').map(String::toInt).withIndex().forEach {
        if (it.value == it.index + 1) {
            if (it.index != prev + 1) {
                ans++
                prev = it.index
            }
        }
    }
    println(ans)
}

fun main(args: Array<String>) {
    solve()
    ouf.close()
}

val inf = BufferedReader(InputStreamReader(System.`in`))
val ouf = PrintWriter(System.out)

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

using namespace std;

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

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
//void __print(vector<bool> x) {int f = 0; cerr << '{'; for (auto i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
//void _print() {cerr << "]\n";}

#ifndef ONLINE_JUDGE
#define ANTHRO(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define ANTHRO(x...)
#endif

template<typename... T>
void read(T&... args) {
	((cin >> args), ...);
}

template<typename... T>
void writ(T&&... args) {
	((cout << args << " "), ...);
}
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define EPS 1e-9
/*
	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    No, nothing good starts in a getaway car
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll s,w; cin>>s>>w;
    if(w>=s) cout<<"unsafe";
    else cout<<"safe";
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


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

    int n;
    cin >> n;
    vector<int> cnt(26,50);
    rep(i,n) {
        string s;
        cin >> s;
        int m=s.size();
        vector<int> c(26);
        rep(j,m) ++c[s[j]-'a'];
        rep(j,26) cnt[j]=min(cnt[j],c[j]);
    }
    rep(i,26) {
        char c=i+'a';
        rep(j,cnt[i]) {
            cout << c;
        }
    }
    cout << endl;
    return 0;   
}

Measured memory_bytes: 3636
N,K = map(int,input().split())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    if A[i] not in C:
        C[A[i]] = 0
    C[A[i]] += 1
C = sorted(list(C.items()),key=lambda x:x[1],reverse=True)
n = len(C)
if n<=K:
    cnt = 0
else:
    cnt = 0
    for i in range(K,n):
        cnt += C[i][1]
print(cnt)

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

namespace ATCode2a
{
    class Program
    {
        static void Main(string[] args)
        {
            int num =0;
            string S = Console.ReadLine();
            string foo = "";
            string hoge = "";
            string piyo = "";

            for (int i = 0; i < S.Length; ++i)
            {
                foo = S[i].ToString();
                if (System.Text.RegularExpressions.Regex.IsMatch(foo, "(A|C|G|T)"))
                {
                    hoge += "1";
                }
                else
                {
                    hoge += "0";
                }
            }

            for (int i = 1; i <= S.Length; ++i)
            {
                piyo += "1";
                if (System.Text.RegularExpressions.Regex.IsMatch(hoge, piyo))
                {
                    num = i;
                }
                else
                {
                }
            }
            Console.WriteLine(num);
            Console.ReadLine();


        }
    }
}


Measured memory_bytes: 16196
/*fabs=doubleの絶対値:abs=intの絶対値:sqrt=√:pow=べき乗*/
#include <stdio.h>
#include <math.h>
int main(void)
{
	int i, n, y, p1 = 0, pi = 0;
	int x[100];
	double p2 = 0, p3 = 0;
	scanf("%d", &n);
	for (i = 0; i<n; i++) 
	{
		scanf("%d", &x[i]);
	}
	for (i = 0; i<n; i++)
	{
		scanf("%d", &y);
		y = abs(y - x[i]);
		p1 = p1 +y;
		p2 = p2 + y * y;
		p3 = p3 + y * y * y;
		if (pi<y) pi = y;
	}
	printf("%d\n%f\n%f\n%d\n", p1, sqrt(p2), pow(p3, 1.0 / 3.0), pi);
	return 0;
}


Measured memory_bytes: 2112
#include <stdio.h>

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  char com[21], buf[20];
  buf[19]='\n';
  char *p;
  do {
    fgets(com, 20, stdin);
    if (*com == 'i') {
      A[++H] = 0;
      p = com+7;
      do {
        A[H] = A[H]*10+*p-'0';
        p++;
      } while (*p!='\n');

      for (i=H; i>1 && A[i>>1]<A[i];i>>=1) {
        tmp = A[i>>1];
        A[i>>1] = A[i];
        A[i] = tmp;
      }

    } else if (com[1]=='x') { // extract
      n = A[1];
      i=18;
      do buf[i--]=(n%10)+'0'; while (n/=10);
      fputs(buf+i+1, stdout);
      A[1] = A[H];
      i = 1;
      do {
        l = i<<1;
        if (l < H && A[l] > A[i])        largest = l;
        else         largest = i;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      } while (1);
      H--;
    }
  } while (com[2]!='d');
  return 0;
}


Measured memory_bytes: 5500
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

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

    vector<lint> X;
    vector<lint> Y;

    REP(_, N) {
      lint x; cin >> x; X.push_back(x);Y.push_back(x);
    }
    SORT(Y);

    REP(i, N) {
      lint med = N/2;
      if(X[i] >= Y[med]) {
        cout << Y[med-1] << "\n";
      } else {
        cout << Y[med] << "\n";
      }
    }

    


    return 0;
}


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

int main() {
vector<int> ame(3);
cin >> ame.at(0) >> ame.at(1) >> ame.at(2);
sort(ame.begin(),ame.end());
int A = ame.at(0) + ame.at(1);
if(A == ame.at(2)){
    cout << "Yes" <<endl;
}
else{
    cout << "No" <<endl;
}
}

Measured memory_bytes: 256
#include<iostream>
    #include<map>
    #include<deque>
    #include<algorithm>
    #include<string>
    #include<cctype>
    using namespace std;
    #define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
    #define Rep(i,n) REP(i,0,n)
    typedef long long ll;
     
     
    string s[3];
    int pow(int a,int b){
        if(b==0) return 1;
        else return pow(a,b-1)*a;
    }
     
    int main(){
        int N,K;
        cin>>N>>K;
        cout<<K*pow(K-1,N-1)<<endl;


        return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
char c[99999];
int main()
{
	string a,b;
	cin>>a>>b;
	int cd1=a.length();
	int cd2=b.length();
	if(cd1>=cd2)
	{
		for(int i=0;i<cd2;i++)
		{
			cout<<a[i];
			cout<<b[i];
		}
		for(int i=cd2;i<cd1;i++)
		{
			cout<<a[i];
		}
	}
	else
	{
		for(int i=0;i<cd1;i++)
		{
			cout<<a[i]<<b[i];
		}
		for(int i=cd1;i<cd2;i++)
		{
			cout<<b[i];
		}
	}
	return 0;
}

Measured memory_bytes: 256
i=1
a = int(input())
ans = 0
while i <= a:
  if i % 3 == 0 and i % 5 == 0:
    pass
  elif i % 3 == 0:
    pass
  elif i % 5 == 0:
    pass
  else:
    ans += i
  i += 1
print(ans)

Measured memory_bytes: 9076
#include <atcoder/dsu>
#include <cstdio>

int main() {
  int n, q, t, u, v;
  scanf("%d%d", &n, &q);

  atcoder::dsu ds(n);
  while (q--) {
    scanf("%d%d%d", &t, &u, &v);
    if (t)
      printf("%d\n", ds.same(u, v));
    else
      ds.merge(u, v);
  }
  return 0;
}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for (int i = 1; i < (int)s.size(); ++i) {
        if (i != 1 && s[i] == s[i - 2]) {
            cout << i - 1 << " " << i + 1 << "\n";
            return 0;
        } else if (s[i] == s[i - 1]) {
            cout << i << " " << i + 1 << "\n";
            return 0;
        }
    }
    cout << -1 << " " << -1 << "\n";
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int counts = 0;
	rep(i,n){
		while(a[i]%2 == 0){
			a[i] /= 2;
			counts++;
		}
	}
	cout << counts << endl;
}

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

int main(){ 
  vector<int> a(3);
  rep(i,3) cin >> a[i];
  sort(a.begin(), a.end());
  int res = 0;
  for (int i = 0; i < 2; i++) {
    res += abs(a[i] - a[i+1]);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
use proconio::*;

fn run() {
    input! {
        mut n: u64,
    }
    let mut ans = 0;
    for i in 2.. {
        if i * i > n {
            break;
        }
        if n % i == 0 {
            let mut cnt = 0;
            while n % i == 0 {
                n /= i;
                cnt += 1;
            }
            let mut k = 1;
            while cnt >= k {
                ans += 1;
                cnt -= k;
                k += 1;
            }
        }
    }
    if n > 1 {
        ans += 1;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
  int n,d;
  cin >> n >> d;
  cout << (n + 2 * d) / (1 + 2 * d) << endl;
}

int main(int argc, char *argv[]){

  /* Regular */
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }
  
  // /* AOJ */
  // solve();
  return 0;
}

Measured memory_bytes: 256
/*input
abcdefghijklmnopqrstuvwzyx
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main(){
	IOS;
	string s;
	cin>>s;
	if(SZ(s)!=26){
		bool vis[26]={0};
		REP(i,SZ(s)) vis[s[i]-'a']=1;
		int i=0;
		while(vis[i]) i++;
		s.pb(char('a'+i));
		cout<<s<<'\n';
		return 0;
	}
	int idx=-1;
	for(int i=SZ(s)-2;i>=0;i--){
		if(s[i]<s[i+1]){
			idx=i;
			break;
		}
	}
	if(idx==-1){
		cout<<-1<<'\n';
		return 0;
	}
	char c;
	for(int i=SZ(s)-1;i>=0;i--){
		if(s[i]>s[idx]){
			c=s[i];
			break;
		}
	}
	REP(i,idx) cout<<s[i];
	cout<<c<<'\n';

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] array = new int[20];
    
    for(int i = 0 ; i < N ; i ++){
      array[i] = sc.nextInt();
    }
    
    boolean flag = false;
    int cnt = 0;
    
    for(int i = 1 ; i < N-1; i++){
      int a = array[i-1];
      int b = array[i];
      int c = array[i+1];
      if(a<b && b<c){
        cnt++;
      }else if(a>b && b>c){
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 21972
// 6/17 振り返り（再チャレンジ）
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    int N, M, K;
    cin >> N >> M >> K;

    Graph g(N), ng(N);  // NGグラフ
    UnionFind uf(N);

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
        uf.unite(a, b);
    }

    rep(i, K) {
        int c, d;
        cin >> c >> d;
        c--; d--;
        ng[c].push_back(d);
        ng[d].push_back(c);
    }

    rep(i, N) {
        int res = uf.size(i) - 1;
        res -= g[i].size();
        for (auto ni : ng[i]) {
            if (uf.same(i, ni)) res--;
        }
        cout << res << endl;
    }    
}

Measured memory_bytes: 12152
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int N, M, indeg[100050], come[100050];
vector<int> to[100050];

int main() {
  N = in();
  M = in();
  for (int i = 0; i < N - 1 + M; ++i) {
    int a = in() - 1;
    int b = in() - 1;
    to[a].push_back(b);
    ++indeg[b];
  }

  vector<int> par(N);
  int root = -1;
  for (int i = 0; i < N; ++i) {
    if (indeg[i] == 0) {
      root = i;
    }
  }
  par[root] = -1;

  queue<int> Q;
  Q.push(root);
  while (!Q.empty()) {
    const int u = Q.front(); Q.pop();
    for (const int v : to[u]) {
      ++come[v];
      if (come[v] == indeg[v]) {
        par[v] = u;
        Q.push(v);
      }
    }
  }

  for (int i = 0; i < N; ++i) {
    printf("%d\n", par[i] + 1);
  }

  return 0;
}


Measured memory_bytes: 7424
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

string replace(string &a,string &b,string &c){
	string ret;
	int p=0,q;
	for(;(q=a.find(b,p))!=a.npos;){
		ret+=a.substr(p,q-p)+c;
		p=q+b.size();
	}
	return ret+a.substr(p);
}
int main()
{
	int n;
	string a[10],b[10];
	string g,d;
	while(cin>>n,n){
		rep(i,n)cin>>a[i]>>b[i];
		cin>>g>>d;
		set<string> v;
		queue<pair<int,string> > q;
		q.push(mp(0,g));
		while(!q.empty()){
			string c=q.front().second; int cc=q.front().first; q.pop();
			if(v.count(c))continue;
			v.insert(c);
			if(c==d){
				cout<<cc<<endl;
				goto END;
			}
			rep(i,n){
				string nx=replace(c,a[i],b[i]);
				if(nx.size()<=d.size())q.push(mp(cc+1,nx));
			}
		}
		cout<<-1<<endl; END:;
	}
	return 0;
}

Measured memory_bytes: 1140
#include <iostream>

using namespace std;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  int a[3], b[3];
  int c[3][3];
  for (int i=0; i<3; ++i) cin >> c[i][0] >> c[i][1] >> c[i][2];

  for (int a1=0; a1<=100; ++a1) {
    for (int a2=0; a2<=100; ++a2) {
      for (int a3=0; a3<=100; ++a3) {
        a[0] = a1;
        a[1] = a2;
        a[2] = a3;
        b[0] = c[0][0]-a1;
        b[1] = c[0][1]-a1;
        b[2] = c[0][2]-a1;
        bool is_ok = true;
        for (int i=0; i<3; ++i) {
          for (int j=0; j<3; ++j) {
            if (c[i][j] != a[i]+b[j]) is_ok = false;
          }
        }
        if (true == is_ok) {
          cout << "Yes\n";
          return 0;
        }
      }
    }
  }
  cout << "No\n";
  return 0;
}

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

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

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<int> v(n);
		rep(i,n) cin >> v[i];

		bool flag = false;
		rep(i,n)
		{
			if(v[i] >= 2)
			{
				flag = true;
				break;
			}
		}

		if(flag)
		{
			int cnt=0;
			rep(i,n)
			{
				if(v[i] == 0) continue;
				cnt++;
			}

			cout << cnt+1 << endl;
		}
		else cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 1232
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

char s[maxn],t[maxn];

int main()
{
	scanf("%s",s+1); ll k=read(),a1=0,a2=0,ans=0,n=strlen(s+1);
	rep(i,1,n) s[i+n]=s[i],t[i]=s[i];
	rep(i,2,n) if(s[i]==s[i-1]) s[i]='#',a1++;
	if(s[1]!=s[n]) return cout<<a1*k<<endl,0;
	per(i,n-1,1) if(t[i]==t[i+1]) t[i]='#',a2++;
	if(t[1]!=t[n]) return cout<<a2*k<<endl,0;
	rep(i,n+1,2*n) if(s[i]==s[i-1]) s[i]='#',a2++;
	ans=a1*k;
	if(s[2*n]=='#') ans+=k/2; else ans+=k-1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int tr[N<<2],tag[N<<2],n,m,cnt=1;
void pushdown(int k)
{
	tr[k<<1]+=tag[k];
	tag[k<<1]+=tag[k];
	tr[k<<1|1]+=tag[k];
	tag[k<<1|1]+=tag[k];
	tag[k]=0;
}
void update(int k,int l,int r,int a,int b,int v)
{
	if(l==a&&r==b)
	{
		tr[k]+=v;
		tag[k]+=v;
		return;
	}
	pushdown(k);
	int mid=l+r>>1;
	if(b<=mid) update(k<<1,l,mid,a,b,v);
	else if(a>mid) update(k<<1|1,mid+1,r,a,b,v);
	else update(k<<1,l,mid,a,mid,v),update(k<<1|1,mid+1,r,mid+1,b,v);
	tr[k]=max(tr[k<<1],tr[k<<1|1]);
}
int query(int k,int l,int r,int a,int b)
{
	if(l==a&&r==b)
		return tr[k];
	pushdown(k);
	int mid=l+r>>1;
	if(b<=mid) return query(k<<1,l,mid,a,b);
	else if(a>mid) return query(k<<1|1,mid+1,r,a,b);
	else return max(query(k<<1,l,mid,a,mid),query(k<<1|1,mid+1,r,mid+1,b));
}
struct query
{
	int l,r,x;
	bool operator<(const query k)const
	{
		return r<k.r;
	}
}a[N];
main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
		cin>>a[i].l>>a[i].r>>a[i].x;
	sort(a+1,a+m+1);
	for(int i=1;i<=n;i++)
	{
		update(1,1,n,i,i,query(1,1,n,1,i));
		while(a[cnt].r==i)
		{
			update(1,1,n,a[cnt].l,a[cnt].r,a[cnt].x);
			cnt++;
		}
	}
	cout<<max(tr[1],0LL)<<endl;
	return 0;
}

Measured memory_bytes: 16640
#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(){

    long long int n;
    cin>>n;
    if(n==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    vector<long long int> v(n+1);
    
    REP(i,n){
        cin>>v[i];
    }

    adjacent_difference(v.begin(),v.end(),v.begin());

    FOR(i,1,n){
        if(v[i]>0){
            v[i]--;
            v[i+1]++;
        }else if(v[i]<0){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    

    return 0;
}


Measured memory_bytes: 1152
def resolve():
    '''
    code here
    '''

    S = input()
    T = input()

    if T in S:
        print(0)
    else:
        res = 0
        for i in range(len(S) - len(T) +1):
            temp = S[i:]
            max_num = 0
            for j in range(len(T)):
                if temp[j] == T[j]:
                    max_num += 1
            res = max(res, max_num)

        print(len(T) - res)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 8992
c = [list(map(int,input().split())) for _ in range(3)]

for i in range(2):
    for j in range(1,3):
        if c[i][j] - c[i][j-1] != c[i+1][j] - c[i+1][j-1]:
            print('No')
            quit()
for i in range(1,3):
    for j in range(2):
        #print(c[i][j] , c[i-1][j])
        #print(c[i][j+1] , c[i-1][j+1])
        if c[i][j] - c[i-1][j] != c[i][j+1] - c[i-1][j+1]:
            print('No')
            quit()
print('Yes')

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

#define NMAX 1005
#define min(a, b) (a < b ? a : b)
#define abs(a) (a < 0 : (-a) : (a))

using namespace std;

int n, k;
int x, y;
int a[2005];
int b[2005];

int dist(int a, int b) {
    if (b < a)
        swap(a, b);
    int d = (b - a);
    return d;
}

int main() {
    int st, dr;
    int d1, d2;
    cin >> n;
    cin >> x >> y;
    // k = 1
    for (int k = 1; k < n; ++k) {
        int nr = 0;
        for (int i = 1; i < n; ++i) {
            st = i;
            dr = i + k;
            if (dr > n)
                break;
            int d = dist(st, dr);
            if (d == k) {
                d1 = dist(x, st) + 1 + dist(y, dr);
                if (d1 < k) {
                    ++a[d1];
                } else ++a[k];
            }
        }
    }
    for (int i = 1; i < n; ++i) {
        cout << a[i] << "\n";
    }
}


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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int H1, H2, M1, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;

  int a = H1 * 60 + M1;
  int b = H2 * 60 + M2;
  int diff = b - a;
  cout << diff - K << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
#define swap(x, y , type) do{type t = x; x = y; y = t;}while(0)
main()
{
	char command[8], str[1001], temp[1001];
	int n, i, a, b;
	scanf("%s", str);
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%s %d %d", command, &a, &b);
		if(!strcmp(command, "print")){
			for(; a <= b; a++){
				putchar(str[a]);
			}
			putchar('\n');
		}else if(!strcmp(command, "reverse")){
			for(; a < b; a++, b--){
				swap(str[a], str[b], int);
			}
		}else if(!strcmp(command, "replace")){
			scanf(" %s", temp);
			for(; b >= a; b--){
				str[b] = temp[b - a];
			}
		}
	}
}

Measured memory_bytes: 1820
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
s = input()
for i in range(len(s)):
  if i % 2 == 0:
    if not s[i] in odd:
      print('No')
      break
  else:
    if not s[i] in even:
      print('No')
      break
else:
  print('Yes')

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MOD = 1e9 + 7;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vector<ll> a(n), t(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> t[i];
	if(a[n - 1] != t[0]){
		cout << 0 << endl;
		return 0;
	}
	repn(i, 1, n) if(a[i] > a[i - 1] && t[i] < a[i]){
		cout << 0 << endl;
		return 0;
	}
	rep(i, n - 1) if(t[i] > t[i + 1] && a[i] < t[i]){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1LL;
	repn(i, 1, n - 1){
		if(a[i] > a[i - 1] || t[i] > t[i + 1]) ans *= 1LL;
		else (ans *= 1LL * (min(a[i], t[i]))) %= MOD;
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
 
 
int main() {
    int N;
    cin >> N;
    int a;
    int count = 0;
    for (int i = 0; i < N; i++) {
        cin >> a;
        while ((a & 1) == 0) {
            a = a >> 1;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second

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<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	char c;
	cin>>c;
	char ans=c+1;
	cout<<ans<<endl;
}

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

vector<pair<int,int> > p;
bool cmp(pair<int,int> p1,pair<int,int> p2){
    return min(p1.second,p1.first+p2.second)>min(p2.second,p2.first+p1.second);
}
int main(){
    int n,sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        string s;
        int cnt=0,mn=0;
        cin>>s;
        for(int j=0;j<s.length();j++){
            char c=s[j];
            if(c=='(') cnt++;
            else cnt--;
            mn=min(mn,cnt);
        }
        p.push_back({cnt,mn});
        sum+=cnt;
    }
    if(sum!=0) {
        printf("No");
        return 0;
    }
    sort(p.begin(),p.end(),cmp);
    int res=0;
    for(int i=0;i<p.size();i++){
        if(res< -p[i].second){
            printf("No");
            return 0;
        }
        res+=p[i].first;
    }
    printf("Yes");
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N;
    cin >> N;
    vector<double> a(N);
    rep(i, N) cin >> a[i];
    sort(a.rbegin(), a.rend());

    double ans = -1e10;
    rep(i, N) rep(j, N) {
        if (i == j) continue;
        double tmp = a[i]-a[j];
        int cur = 0;
        double tmp2 = 0;
        rep(k, N) {
            if (k == i or k == j) continue;
            tmp2 += a[k];
            cur++;
            if (cur == 2) break;
        }
        ans = max(ans, tmp2/tmp);
    }

    printf("%.10f\n", ans);

    return 0;
}



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

using ll = long long;

string f(string s) {
	int n = int(s.size()) / 2;
	vector<int> fail(n+1);
	fail[0] = -1;
	for (int i = 1; i <= n; i++) {
		int cnd = fail[i-1];
		while (cnd != -1 && s[cnd] != s[i-1]) {
			cnd = fail[cnd];
		}
		assert(cnd == -1 || s[cnd] == s[i-1]);
		fail[i] = cnd+1;
	}
	int repLen = fail[n];
	return s.substr(0, 2 * n - repLen) + s.substr(0, 2 * n - repLen);
}

map<ll, vector<ll>> mem;
set<ll> reflections;
vector<ll> prefCnt(ll a) {
	if (mem.count(a)) {
		return mem[a];
	}
	auto it = reflections.lower_bound(a);
	assert(it != reflections.begin());
	--it;
	ll md = *it;
	vector<ll> v1 = prefCnt(md);
	vector<ll> v2 = prefCnt(a - md);
	for (int i = 0; i < 26; i++) {
		v1[i] += v2[i];
	}
	return mem[a] = v1;
}

vector<ll> go() {
	string S; cin >> S;
	ll L, R; cin >> L >> R; L--;
	string f0 = S;
	string f1 = f(f0);
	string f2 = f(f1);
	ll a = int(f0.size()) / 2;
	ll b = int(f1.size()) / 2;
	ll c = int(f2.size()) / 2;
	if (a + c == b + b) {
		//cerr << "periodic" << '\n';
		ll period = b - a;
		vector<ll> ans(26);
		for (int i = 0; i < period; i++) {
			ans[S[i] - 'a'] += (R - i + period - 1) / period - (L - i + period - 1) / period;
		}
		return ans;
	}

	//cerr << "fibo" << '\n';
	mem[0] = vector<ll>(26, 0);
	for (int i = 0; i < int(S.size()); i++) {
		mem[i+1] = mem[i];
		mem[i+1][S[i]-'a']++;
	}
	for (ll x = a, y = b; x <= R; y += x, x = y - x) {
		reflections.insert(x);
	}
	vector<ll> rans = prefCnt(R);
	vector<ll> lans = prefCnt(L);
	vector<ll> ans(26);
	for (int i = 0; i < 26; i++) {
		ans[i] = rans[i] - lans[i];
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	auto ans = go();
	for (int i = 0; i < 26; i++) {
		cout << ans[i] << " \n"[i+1==26];
	}

	return 0;
}


Measured memory_bytes: 61104
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<algorithm>
int read(){int x=0,c=getchar();while(!isdigit(c))c=getchar();while(isdigit(c))x=x*10+c-48,c=getchar();return x;}
void over(){puts("-1"),std::exit(0);}
const int N=500007;
std::vector<int>e[N];
int n,m,ans,eu,ev,a[N],fa[N],dep[N],f[N];
void dfs(int u)
{
    dep[u]=dep[fa[u]]+1,f[u]=dep[u]&1? 1:-1;
    for(int v:e[u]) if(v^fa[u]) dep[v]? (eu=u,ev=v):(fa[v]=u,dfs(v),f[u]+=f[v]);
}
void work1()
{
    if(f[1]) over();
    for(int i=1;i<=n;++i) ans+=abs(f[i]);
    printf("%d",ans);
}
void work2()
{
    if(f[1]&1) over();
    int x=-f[1]/2;
    for(;eu;eu=fa[eu]) f[eu]+=x;
    for(;ev;ev=fa[ev]) f[ev]+=x;
    for(int i=1;i<=n;++i) ans+=abs(f[i]);
    printf("%d",ans+abs(x));
}
void work3()
{
    if(f[1]) over();
    int c=0,x;
    for(;ev^eu;ev=fa[ev]) a[++c]=f[ev],dep[ev]=0;
    std::sort(a+1,a+c+1),x=a[(c+1)/2];
    for(int i=1;i<=n;++i) if(dep[i]) ans+=abs(f[i]);
    for(int i=1;i<=c;++i) ans+=abs(a[i]-x);
    printf("%d",ans+abs(x));
}
int main()
{
    n=read(),m=read();
    for(int i=1,u,v;i<=m;++i) u=read(),v=read(),e[u].push_back(v),e[v].push_back(u);
    dfs(1);
    m==n-1? work1():(abs(dep[eu]-dep[ev])&1? work3():work2());
}


Measured memory_bytes: 25984
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
void iput(int input) {put(input);}
void lput(long long input) {put(input);}

int main(){
  while(true){
    int n, in, prev, min, sa;
    vector<int> input;
    cin >> n;
    if(n != 0){
      for(int i=0; i<n; i++){
        cin >> in;
        input.push_back(in);
      }
      sort(input.begin(), input.end());
      for(int i=1; i<n; i++){
        sa = abs(input[i-1] - input[i]);
        if(i==1){
          min = sa;
        }else{
          min = min > sa ? sa : min;
        }
      }
      iput(min);
    }else{
      break;
    }
  }
}

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

int a,b,c,d,e,f;

int search(int w){
  int u = min(w * e,f - 100*w);
  int res = 0;
  for(int i = 0;i <= u;i += c){
    int j = ((u - i) / d) * d;
    res = max(res,i+j);
  }
  return res;
}

int main(void){
  cin >> a >> b >> c
      >> d >> e >> f;
  int res1 = a*100,res2 = 0;
  double tmp = 0.0;
  for(int i = 0;i * 100 <= f;i += a){
    for(int j = 0;(i + j)*100 <= f;j += b){
      if(i+j == 0)continue;
      int calc = search(i+j);
      int tot = (i+j)*100+calc;
      if((double)calc/tot > tmp){
        res1 = (i+j)*100+calc;
        res2 = calc;
        tmp = (double)calc/tot;
      }
    }
  }
  cout << res1 << " " << res2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

struct Fish
{
    ll beauty;
    ll taste;
};

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

int main()
{
    ll N, T, A;
    cin >> N >> T >> A;

    ll ans = 0;
    ll mn = INT_MAX;
    for (ll i = 0; i < N; i++)
    {
        ll h;
        cin >> h;
        ll t = 1000 * T - h * 6;
        if (mn > abs(A * 1000 - t)) {
            mn = abs(A * 1000 - t);
            ans = i + 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
      int y,m,d;
     scanf("%d/%d/%d",&y,&m,&d);
     printf("%d/",y+1);
     printf("0%d/",m);
     if(d>9)
        printf("%d",d);
     else
        printf("0%d",d);
     return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

bool dp[101][10001];

int main(){
	int n, sum = 0; cin >> n;
	int s[n];
	Rep(i, n){
		cin >> s[i]; sum += s[i];
	}
	if(sum % 10 != 0){
		cout << sum << endl; return 0;
	}
	dp[0][0] = true;
	Rep(i, n) Rep(j, sum + 1){
		if(dp[i][j]) dp[i + 1][j] = dp[i][j];
		if(j + s[i] <= sum){
			dp[i + 1][j + s[i]] = dp[i][j];
			if(i == n - 1 && (j + s[i]) % 10 == 0){
				dp[i + 1][j + s[i]] = false;
			}
		}
		if(i == n - 1 && j % 10 == 0) dp[i + 1][j] = false;
	}
	bool flag = true;
	Rrep(i, sum){
		if(dp[n][i]){
			cout << i << endl;
			flag = false;
			break;
		}
	}
	if(flag) cout << 0 << endl;
	return 0;
}

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

int arr[2001];

void set(){
    for(int i = 0; i <= 2000; i++){
        arr[i] = 1001 - (int)abs(i - 1000);
    }
}

int main(){
    set();
    int n;
    while( cin >> n ){
        long long int ans = 0;
        for(int i = (n-2000 > 0 ? n-2000 : 0);
            i <= (n-2000 > 0 ? 2000 : n); i++){
            ans += arr[i] * arr[n-i];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
import java.util.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().split(" ");
        int N = getInt(s[0]);
        String[] X = sc.nextLine().split(" ");
        int[] x = toIntArray(X.clone());
        Arrays.sort(x);

        // 中央値の境界を取る
        int floor = (int)Math.floor(N / 2) - 1;
        int border = x[floor];

        int a = x[floor + 1];
        int b = x[floor];
        for(int i = 0;i < N;i++){
            if(getInt(X[i]) <= border){
                println(a);
            }else{
                println(b);
            }
        }

        return;
    }
    static long getLong(String val) {return Long.parseLong(val);}
    static int getInt(String val) {return Integer.parseInt(val);}
    static String[] split(String val) {return val.split(" ");}
    static List<String> toSortedList(String[] s){ return sortList(Arrays.asList(s));}
    static List<String> sortList(List<String> list){
        Collections.sort(list, Comparator.comparingInt(val -> Integer.parseInt(String.valueOf(val))));
        return list;
    }

    static int[] toIntArray(String[] array) {
        return Stream.of(array.clone()).mapToInt(Integer::parseInt).toArray();
    }

    static void println(String val){System.out.println(val);}
    static void println(int val){System.out.println(val);}
    static void println(long val){System.out.println(val);}
    static void println(boolean val){System.out.println(val);}
}


Measured memory_bytes: 70180
n = gets.to_i
 
a = gets.chomp.split(" ").map(&:to_i)
 
a.each do |number|
  if number.even?
  	unless number % 3 == 0 || number % 5 == 0
  	  puts 'DENIED'
  	  exit
  	end
  end
end
 
puts 'APPROVED'

Measured memory_bytes: 1788
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastReader in = new FastReader();
        test a=new test();
        a.solve(in,out);
        out.close();
    }
}
class test{
    public void solve(FastReader in, PrintWriter out) {
        //int t =in.nextInt();
       // while(t-->0){

        //}
        int a=in.nextInt();
        int b=in.nextInt();
        int c=in.nextInt();
        int k=in.nextInt();
        int cnt =0;
       if(a>k){
           out.println(k);
       }else if(a<=k){
           cnt+=a;
           k=k-a;
           if(b>=k){
               out.println(cnt);
           }else{
               k=k-b;
               cnt-=k;
               out.println(cnt);
           }
       }
    }


}

class FastReader{
    BufferedReader br;
    StringTokenizer st;

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

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

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

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

    double nextDouble(){
        return Double.parseDouble(next());
    }
    String nextLine(){
        String str="";
        try{
            str=br.readLine();
        }
        catch(IOException e){
            e.printStackTrace();
        }
        return str;
    }
}



Measured memory_bytes: 32708