akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll N; cin >> N;
    ll A[10000];

    bool f = true;

    for (int i = 0;i < N;i++){
        cin >> A[i];
        if(A[i]%2 == 0){
            if(A[i]%3 == 0 || A[i]%5 == 0) continue;
            f = false;
        }
    }

    if(f) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;

    return 0;

}

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

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

    std::vector<int> t(n+2);
    std::vector<int> x(n+2);
    std::vector<int> y(n+2);
    for (int i = 1; i < n+1; i++)
    {
        std::cin >> t[i] >> x[i] >> y[i];
    }

    x[0] = 0;
    y[0] = 0;
    x[n + 1] = 0;
    y[n + 1] = 0;

    bool f = true;
    std::string ans;
    int dx;
    int dy;
    int dt;
    for (int i = 0; i < n; i++)
    {
        dx = std::abs(x[i + 1] - x[i]);
        dy = std::abs(y[i + 1] - y[i]);
        dt = t[i + 1] - t[i];

        if(!(dt >= dx + dy && dt%2 == (dx+dy)%2 )) {
            f = false;
        }
    }

    ans = f ? "Yes" : "No";

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

Measured memory_bytes: 4472
#include <iostream>
#include <algorithm>
using namespace std;
 
int main () {
 
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
 
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
        a[2] *= 2;
    }
 
    cout << a[0] + a[1] + a[2] << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int main() {
    int N,M; cin>>N>>M;
    int sum=N+M;
    int total=sum*(sum-1)/2;
    cout<<total-N*M<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <numeric>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <map>
#include <utility>
#include <functional>
#include <iomanip>
#include <unordered_map>
#include <set>
using namespace std;
using ull = unsigned long long;
using  ll =long long ;
using  prll =pair<ll, ll>;
static const ll MOD = 1000000007;           //10億　= 10^9になってる
static const ll mINF = -922337200085470000; //llのmax-1桁の小さい方
static const ll pINF = 1LL << 60;
static const ull uINF=  1844674407399900000; //ullのmax-1桁してる
static const double  pi = 3.1415926535897932384;
static const ll juu = 100000;             //10万 10e5
static const ll hyaku = 1000000;         //100万　10e6
static const ll dx[4] = {0,0,1,-1}; //上下左右のベクトル
static const ll dy[4] = {1,-1,0,0}; //上下左右のベクトル
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)



/*intで収まる範囲であってくれ*/
ll nCr(ll n, ll r)
{
    ll val = 1;
    ll i;
    if (r == 0)
        return 1;
    for (i = 0; i < n - r; i++)
    {
        val *= (n - i);
        val /= (i + 1);
    }
    return val;
}
/*intで収まる範囲であってくれ*/
ll nPr(ll n, ll r)
{
    ll val = 1;
    ll i;
    for (i = 0; i < r; i++)
    {
        val *= (n - i);
    }
    return val;
}
template <typename T>
bool chmin(T &a, const T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &a, const T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

/*ソートして被りを無くす*/
template <typename T>
void eraseSame(T &a)
{
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

/*aとbで大きい方を後ろにする。変更なしならtrue、ありならfalse */
template <typename T>
bool swapmax(T &a, T &b)
{
    T temp;
    temp = a;
    if (a > b)
    {
        a = b;
        b = temp;
        return false;
    }
    return true;
}
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

/*一行に入力が何個あるかを1,ぶち込むvectorを2*/
template <typename T>
void splitIn(ll N, vector<T> &array)
{
    T temp;
    int i = 0;
    if (N == 0)
    {
        return;
    }
    array.resize(N);
    while (cin >> temp)
    {
        array[i] = temp;
        i++;
        if (i >= N)
        {
            break;
        }
    }
    return;
}
vector<long double> v;
int main()
{

    ll n, k, m;
    long double ans = 0;
    long double tem;
    string s;
    cin >> n >> k;
    v.resize(n+1);
    v[0] = 0;
    for(long i=1;i<=n;++i){
        cin >> tem;
       // cout << "in";
        v[i] = v[i-1] + ((long double)1+tem)/(long double)2;
      //  cout << v[i] << endl;
    }
    for(long i = 0;i <= n -k;++i){
        chmax(ans,   v[i+k] -v[i]   );
       // cout <<v[i+k] -v[i] <<"sum\n";
    }

    cout << setprecision(12) <<ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

void shortestPath(const vector<vector<Edge> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }
}

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        string s, p, g;
        cin >> s >> p >> g;

        map<string, int> name;
        name[s] = 0;
        name[p] = 1;
        name[g] = 2;

        vector<vector<Edge> > edges(n);
        n = 3;
        for(int i=0; i<m; ++i){
            string a, b;
            int d, t;
            cin >> a >> b >> d >> t;

            int j, k;
            if(name.find(a) == name.end()){
                name[a] = j = n;
                ++ n;
            }else{
                j = name[a];
            }
            if(name.find(b) == name.end()){
                name[b] = k = n;
                ++ n;
            }else{
                k = name[b];
            }

            edges[j].push_back(Edge(k, d/40+t));
            edges[k].push_back(Edge(j, d/40+t));
        }

        int ret = 0;
        vector<int> dist;
        shortestPath(edges, 0, dist);
        ret += dist[1];
        shortestPath(edges, 1, dist);
        ret += dist[2];

        cout << ret << endl;
    }
}

Measured memory_bytes: 1120
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define soja(i,a,n) for(ll i=a;i<=n;i++)
int main()
{
    ll n,m,k,sum=0;
    cin>>n;
    soja(i,1,10000)
    {
        sum=i*1000;
        if(sum>=n)
            break;
    }
    cout<<sum-n<<endl;
return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << (#x) << " = " << (x) << endl;
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<double, double> dd;
typedef pair<float, float> ff;
const int Smax = 3001;
int f[Smax][Smax];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	s = ' ' + s;
	t = ' ' + t;
	REP1(i, n) {
		REP1(j, m) {
			if (s[i] == t[j]) f[i][j] = f[i - 1][j - 1] + 1;
			else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
		}
	}
	string res;
	int i = n, j = m;
	while (i && j) {
		if (s[i] == t[j]) {
			res.pb(s[i]);
			--i; --j;
		}
		else if (f[i][j] == f[i - 1][j]) --i;
		else --j;
	}
	reverse(res.begin(), res.end());
	cout << res;
	return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int N, A, B; cin >> N >> A >> B;
    if (N*A < B) {
        cout << N*A << endl;
    } else {
        cout << B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int n;
  	cin>>n;
  	bool fin=0;
	for(int i=1;i<=9;i++){
    	for(int j=1;j<=9;j++){
    		if(i*j==n){
        		cout<<"Yes"<<endl;
         		fin=1;
        		break;
        	}
        	else if(i*j==81){
        		cout<<"No"<<endl;
              	fin=1;
              	break;
            	
        	}
   		}
     if(fin){
     	break;
     } 
    }
}

Measured memory_bytes: 256
# A
N, P = map(int, input().split())
A_list = list(map(int, input().split()))

odd_n = 0
even_n = 0

for A in A_list:
    if A % 2 == 0:
        even_n += 1
    else:
        odd_n += 1

ncr = 1
odd_odd_cnt = 0
even_odd_cnt = 1

for i in range(1, odd_n+1):
    ncr *= odd_n-(i-1)
    ncr /= i
    if i % 2 == 0:
        even_odd_cnt += ncr
    else:
        odd_odd_cnt += ncr


if P == 0:
    print(int(even_odd_cnt * pow(2, even_n)))
else:
    print(int(odd_odd_cnt * pow(2, even_n)))

Measured memory_bytes: 3316
import collections
s = str(input())
k = int(input())

ans = 0
#if s[0] == s[-1]:
#    ans += k

tmp = ''
tmp_num = 0

check = ''
check_num = 0

if len(collections.Counter(s).keys()) == 1:
    ans = len(s)*k//2

else:
    for i, w in enumerate(s):
        if i == 0:
            tmp += w
            tmp_num += 1
            continue
        
        if tmp[-1] == w:
            tmp += w
            tmp_num += 1
        
        elif tmp[-1] != w:
            if check_num == 0:
                check = tmp
                check_num = 1

            ans += (tmp_num // 2) * k
            #print('ans', ans)
            tmp = w
            tmp_num = 1
        
        if i == len(s)-1:
            if len(tmp) == 1:
                if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1
            else:
                #print(check, tmp)
                if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1

            ans += (tmp_num // 2) * k
            #print('last', ans)

print(ans)



Measured memory_bytes: 3316
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}
import scala.util.Random
import java.util.Date

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val D = in.next().toInt
  val c = new Array[Long](26+1)
  val s = Array.ofDim[Long](D+1, 26+1)

  for (i <- 1 to 26) {
    c(i) = in.next().toInt
  }
  for (d <- 1 to D) {
    for (i <- 1 to 26) {
      s(d)(i) = in.next().toInt
    }
  }

  // optional
  val t = new Array[Int](D+1)
  for (i <- 1 to D) {
    t(i) = in.next().toInt
  }

  class Board(val t: Array[Int]) {

    // 各コンテストの開催日をセットで保持する
    private val eventDays = Array.fill(26+1)(Set[Int]())

    var score: Long = {
      var res = 0L

      val last = new Array[Int](26+1)
      for (day <- 1 to D) {
        val now = t(day)
        last(now) = day

        res += s(day)(now)
        for (contest <- 1 to 26) {
          res -= c(contest) * (day - last(contest))
        }
        pw.println(res)
      }

      res
    }

    // ${day}日の開催コンテストを, ${contest}に変更する
    def update(day: Int, contest: Int): Unit = ???
  }



  // val M = in.next().toInt
  // for (_ <- 1 to M) {
  //   val d, q = in.next().toInt
  //   t(d) = q
  //   val ans = calcScore(t)
  //   pw.println(ans)
  // }

  new Board(t)


  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 55148
#include <iostream>
#include <stdio.h>

using namespace std;

char str[10][10];

int main() {
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0; i<n; i++) {
        scanf("%s",str[i]);
    }
    int mins,maxs;
    int foo;
    for(int i=0; i<n; i++) {
        mins=10000;
        maxs=-10;
        for(int j=0; j<n; j++) {
            if(str[i][j]=='#') {
                mins=min(mins,j);
                maxs=max(j,maxs);
                /*cout<<"ns=="<<mins<<endl;
                cout<<"xs=="<<maxs<<endl;*/
            }
            /*cout<<"mins=="<<mins<<endl;
            cout<<"maxs=="<<maxs<<endl;*/
        }
        if(i!=0) {
            if(foo!=mins) {
                puts("Impossible");
                return 0;
            } else {
                foo=maxs;
            }
        } else {
            foo=maxs;
        }
    }
    puts("Possible");
    return 0;
}


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


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;

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

	int len = max(n, m);
	vector<ll> facto(len + 1);
	facto[0] = 1;
	for (int i = 1; i <= len; i++) {
		facto[i] = (facto[i - 1] * i) % MOD_CONST;
	}

	int ans = 0;
	if (n - m == 0) {
		ans = (((facto[m] * facto[n]) % MOD_CONST) * 2) % MOD_CONST;
	}
	else if (abs(n - m) == 1) {
		ans = ((facto[m] * facto[n]) % MOD_CONST);
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
a, b, m = map(int, input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
xyc = [tuple(map(int, input().split())) for _ in range(m)]

amin = min(a)
bmin = min(b)
ans = amin + bmin
for x, y, c in xyc:
    ans = min(a[x-1] + b[y-1] - c, ans)
print(ans)

Measured memory_bytes: 29244
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
const int maxn = 50050*2;
const int maxm = 50050*2;
struct Edge
{
	int from,to,dist,id;
};
vector<int> G[maxn];
vector<Edge> edges;
Edge tt[maxm];
bool cmp(Edge a,Edge b)
{
	return a.dist<b.dist;
}
void add_edge(int a,int b,int c)
{
	edges.push_back((Edge){a,b,c});
	edges.push_back((Edge){b,a,c});
	int m=edges.size();
	G[a].push_back(m-2);
	G[b].push_back(m-1);
}
int n,m;
bool flag[maxn];
int f[maxn];
int find(int x)
{
	return x==f[x]?x:find(f[x]);
}
void add(int a,int b)
{
	int ta=find(a);
	int tb=find(b);
	f[ta]=tb;
}
bool vis[maxn],is[maxm];
void dfs1(int u)
{
	vis[u]=1;
	for(int i=0;i<G[u].size();i++)
	{
		int t=G[u][i];
		Edge e=edges[t];
		if(!vis[e.to]&&flag[t])
			dfs1(e.to);
	}
}
bool vis1[maxn];
bool dfs2(int u,int key)
{
	vis1[u]=1;bool ret= false;
	for(int i=0;i<G[u].size();i++)
	{
		int t=G[u][i];
		Edge e=edges[t];
		if(!vis[e.to]&&!flag[t]&&key==e.dist)
			return true;
		if(!vis1[e.to]&&vis[e.to])
			ret|=dfs2(e.to,key);
	}
	return ret;
}
int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		for(int i=1;i<=n;i++)
			f[i]=i;
		edges.clear();
		for(int i=1;i<=n;i++)
			G[i].clear();
		memset(flag,0,sizeof(flag));
		int a,b,c,ID=0;
		for(int i=0;i<m;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			add_edge(b,a,c);
			tt[ID]=(Edge){a,b,c,ID++};
			tt[ID]=(Edge){b,a,c,ID++};
		}
		sort(tt,tt+ID,cmp);
		for(int i=0;i<ID;i++)
		{
			int u=find(tt[i].from),v=find(tt[i].to);
			if(u!=v)
			{
				add(u,v);
				flag[tt[i].id]=flag[tt[i].id^1]=1;
			}
		}
		memset(is,0,sizeof(is));
		for(int i=0;i<edges.size();i++)
			if(flag[i]&&!is[i]&&!is[i^1])
		    {
		    	memset(vis,0,sizeof(vis));
		    	flag[i]=flag[i^1]=0;
		    	dfs1(edges[i].from);
		    	flag[i]=flag[i^1]=1;
		    	memset(vis1,0,sizeof(vis1));
		    	if(dfs2(edges[i].from,edges[i].dist)) is[i]=is[i^1]=1;
		    }
		int ans=0,answ=0;
		for(int i=0;i<edges.size();i++)
			if(!is[i]&&flag[i])
			{
				is[i]=is[i^1]=1;
			    ans++;
			    answ+=edges[i].dist;
			}
		printf("%d %d\n",ans,answ);
	}
	return 0;
}

Measured memory_bytes: 7644
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define li long
#define pb push_back
#define mem(arr,x) memset(arr,x,sizeof(arr))

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j,k;
    cin>>n>>k;
    ll h[n+1];
    for(i=0;i<n;i++)
    cin>>h[i];
    vector<ll>dp(n+1,INT_MAX);
    dp[0]=0;
    for(i=1;i<n;i++)
    {
      for(j=1;j<=k;j++)
      {
        if(i>=j)
        dp[i]=min(dp[i], abs(h[i]-h[i-j])+dp[i-j]);
      }
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 4788
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    ll N;
    cin >> N;
    N *= 2;
    vector<ll> r(2);
    vector<ll> m(2);
    r[0] = 0; r[1] = -1;
    ll ans = INF;
    for(ll i = 1; i*i <= N; i++){
        if(N % i == 0){
            ll j = N / i;
            m[0] = i; m[1] = j;
            LP ans1 = crt(r, m);
            swap(m[0], m[1]);
            LP ans2 = crt(r, m);
            if(ans1.first != 0)ans = min(ans, ans1.first);
            if(ans2.first != 0)ans = min(ans, ans2.first);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  int key;
  struct node *right,*left,*parent;
};
typedef struct node * Node;
Node root = NIL;
void prerder(Node);
void insert(int);
int search(int v,Node u)
{
    if(u==NIL){
        return 0;
    }
    if( u->key == v ){
    return 1;
    }else if( u->key < v ){
    return search(v,u->right);
    }else{
    return search(v,u->left);
    }
}



void insert(int k){
struct node *y=NIL;
struct node *x=root;
struct node *z;

z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL;
z->right = NIL;

  while( x != NIL ){
    y = x;
    if( z->key < x->key ) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if( y == NIL ){
    root = z;
  }
  else if( z->key < y->key ){
    y->left = z;
  }
  else y->right = z;
}

void inorder(Node z){
 if(z==NIL)return;
  inorder(z->left);
  printf(" %d",z->key);
  inorder(z->right);
}

void preorder(struct node *z){
  printf(" %d",z->key);
  if( z->left != NIL ){
    preorder(z->left);
  }
  if( z->right != NIL ){
    preorder(z->right);
  }
}

int main(void){
  int m;
  int i;
  int f;
  int q;
  char kb[84];
  char cf[82];
  scanf("%d", &m);
  i = 0;
  while(i < m ){
  	
    scanf("%s", cf);
    if ( cf[0] == 'i' ){
      scanf("%d", &f);
      insert(f);
    }

    else if( cf[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else {
	scanf("%d", &f);
        if(search(f,root)){
        printf("yes\n");
	
	}else{
                printf("no\n");
    
  }
}

 i++;
}

  return 0;
}


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

vector<int> a;
int N;

int main() {
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    long double sum = 0;
    for (int i = 0; i < N; i++) {
        sum += (long double)1/a[i];
    }
    cout << (long double)1/sum << endl;
    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  rep(i,n) cin >> h[i];
  rep(i,m){
    int a, b;
    cin >> a >> b;
    --a; --b;
    if(h[a] <= h[b]) ok[a] = false;
    if(h[b] <= h[a]) ok[b] = false;
  }
  int ans = 0;
  rep(i,n) if(ok[i]) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3692
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e+5;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

void solve() {
    int n;
    int c[N], s[N], f[N];
    cin >> n;
    rep(i, n-1) {
        cin >> c[i] >> s[i] >> f[i];
    }

    int t;
    rep(i, n-1) {
        t = 0;
        REP(j, i, n-1) {
            if (t >= s[j] && t % f[j] == 0) {
                t += c[j];
//                 MSG(i);
//                 MSG(j);
//                 MSG(t);
            }
            else if (t < s[j]) {
                t += (s[j] - t) + c[j];
//                 MSG(i);
//                 MSG(j);
//                 MSG(t);
            }
            else {
                t += (f[j] - t % f[j]) + c[j];
//                 MSG(i);
//                 MSG(j);
//                 MSG(t);
            }
        }
        cout << t << endl;
    }
    cout << 0 << endl;
}

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


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

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

	int S;
	if (N % 2 == 1) S = N;
	else S = N + 1;

	//int cnt = 0;
	cout << N * (N - 1) / 2 - N / 2 << endl;
	for (int i = 1; i <= N; i++) {
		for (int j = i+1; j <= N; j++) {
			if (j == S - i) continue;
			//cnt++;
			//cout << cnt << " ";
			cout << i << " " << j << endl;
		}
	}
}


Measured memory_bytes: 256
import itertools

N,M,X = map(int,input().split())
COST = [0]*N
POWER = [0]*N
for i in range(N):
    AAA = list(map(int,input().split()))
    COST[i] = AAA[0]
    POWER[i] = AAA[1:]

INF = 10**10
ans = INF

for Q in itertools.product((0,1),repeat=N):
    c = 0
    p = [0]*M
    for k,v in enumerate(Q):
        if v == 0:
            continue
        c += COST[k]
        for kk,vv in enumerate(POWER[k]):
            p[kk] += vv
        b = True
        for i in range(M):
            if p[i] < X:
                b = False
                break
        if b:
            ans = min(ans,c)

if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68400
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 


long long int N,Ma,M,a[100],b[100],c[100],res=1;
long long int cost[405][405]={};
string S;
int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    for(long long int i = 1; i <= N; i++){
        res*=i;
        res%=mod;
    }
    cout<<res<<endl;
}    


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

ll cal_gcd(ll m, ll n) {
	while (m%n != 0) {
		ll c = m % n;
		m = n;
		n = c;
	}
	return n;
}

struct Sieve {
	int n_;
	vector<int>f_, primes_;
	Sieve(int n = 1):n_(n), f_(n + 1){
		f_[0] = -1; f_[1] = -1;
		for (ll i = 0; i <= n; i++) {
			if (f_[i])continue;
			primes_.push_back(i);
			f_[i] = i;
			for (ll j = i * i; j <= n; j += i) {
				if(!f_[j])f_[j] = i;//最小の素数の約数
			}
		}
	}
	bool is_prime(int i) {
		return f_[i] == i;
	}
	vector<int>factor_list(int x) {
		vector<int>res;
		while (x != 1) {
			res.push_back(f_[x]);
			x /= f_[x];
		}
		return res;
	}
	vector<pair<int, int>>factors(int x) {
		vector<int> fl = factor_list(x);
		if (fl.empty())return {};
		vector<pair<int, int>>res(1, pair<int, int>(fl[0], 0));
		for (int p : fl) {
			if (res.back().first == p) {
				res.back().second++;
			}
			else {
				res.emplace_back(pair<int, int>(p, 1));
			}
		}
		return res;
	}
};

int main() {
	Sieve sieve(1e6);
	int n;
	cin >> n;
	vector<int>a(n);
	map<int, int>mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		auto tmp = sieve.factors(a[i]);
		for (auto p : tmp) {
			mp[p.first] = max(p.second, mp[p.first]);
		}
	}
	ll ans = 0;
	ll lcm = 1;
	for (auto p : mp) {
		for (int i = 0; i < p.second; i++) {
			lcm *= p.first;
			lcm %= mod;
		}
	}
	for (int i = 0; i < n; i++) {
		ll inv = n_pow(a[i], mod - 2);
		ans += (lcm * inv) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        Dice d = new Dice(lines);
        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            String[] order = br.readLine().split(" ");
            System.out.println(d.getRight(order));
        }
    }
}
class Dice {
    String[] s = new String[6];
    int[] d = { 0, 1, 2 };

    Dice(String[] s) {
        this.s = s;
    }

    String getNumber() {
        return s[d[0]];
    }

    void roll(char n) {
        int a = 0;
        int b = 0;
        switch (n) {
        case 'N':
            a = 0;
            b = 1;
            break;
        case 'E':
            a = 2;
            b = 0;
            break;
        case 'S':
            a = 1;
            b = 0;
            break;
        case 'W':
            a = 0;
            b = 2;
            break;
        }
        int temp = d[a];
        d[a] = d[b];
        d[b] = 5 - temp;
    }

    String getRight(String[] list) {
        for (int i = 0; i < 3; i++) {
            if (getNumber().equals(list[0])) {
                break;
            }
            roll('N');
        }
        for (int i = 0; i < 3; i++) {
            if (getNumber().equals(list[0])) {
                break;
            }
            roll('W');
        }
        for (int i = 0; i < 3; i++) {
            if (s[d[1]].equals(list[1])) {
                break;
            }
            horizontalRoll();
        }
        return s[d[2]];
    }
    void horizontalRoll() {
        int temp = d[1];
        d[1] = d[2];
        d[2] = 5 - temp;
    }
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll N;
  scanf("%lld",&N);
  ll A;
  scanf("%lld",&A);
  ll B;
  scanf("%lld",&B);
  cout << min(N*A, B) << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    string s;
    cin>>s;
    int ans;
    if(s=="SSS"){
        ans=0;
    }else if(s=="RSR" || s=="RSS" || s=="SSR" || s=="SRS"){
        ans=1;
    }else if(s=="RRS" || s=="SRR"){
        ans=2;
    }else{
        ans=3;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] H = new int[N];
		for(int i = 0; i < N; i++) H[i] = sc.nextInt();
		int ans = 1;
		for(int i = 1; i < N; i++) {
			boolean canSee = true;
			for(int j = 0; j < i; j++) {
				if(H[i] < H[j]) canSee = false;
			}
			if(canSee) ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23252
n = int(input())

card = [[], [], [], []]
for x in range(n):
    mark, num = map(str, input().split())
    num = int(num) - 1
    if mark == "S":
        mark = 0
    elif mark == "H":
        mark = 1
    elif mark == "C":
        mark = 2
    else:
        mark = 3

    card[mark].append(num)

for x in range(4):
    if x == 0:
        mark= "S"
    elif x == 1:
        mark = "H"
    elif x == 2:
        mark = "C"
    else:
        mark = "D"
    for y in range(13):
        if y not in card[x]:
            print(mark, y + 1)


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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

int main()
{
  int N, A[2][100];

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

  int dp[2][100];
  fill_n(*dp, 2 * 100, -INF);
  dp[0][0] = A[0][0];
  for(int i = 0; i < 2; i++) {
    for(int j = 0; j < N; j++) {
      if(j - 1 >= 0) dp[i][j] = max(dp[i][j], dp[i][j - 1] + A[i][j]);
      if(i - 1 >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j] + A[i][j]);
    }
  }

  cout << dp[1][N - 1] << endl;
}


Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl;
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 
int main(){
    ll N, M, K;
    cin >> N >> M >> K;

    vector<ll> A(N), B(M);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<M; i++) cin >> B[i];

    vector<ll> wa_a(N+1), wa_b(M+1);
    wa_a[0] = 0; wa_b[0] = 0;
    for(int i=1; i<=N; i++) wa_a[i] = wa_a[i-1] + A[i-1];
    for(int i=1; i<=M; i++) wa_b[i] = wa_b[i-1] + B[i-1];
    wa_a.push_back(3e16);
    wa_b.push_back(3e16);
    // cout << "  wa_a:  "; print_vec(wa_a);
    // cout << "  wa_b:  "; print_vec(wa_b);



    //O(NlogN)解法  累積和 + 2分探索
    ll ans = 0;
    for(int num_a=0; num_a<=N; num_a++){
      ll time = K - wa_a[num_a];
      auto iter = upper_bound(wa_b.begin(), wa_b.end(), time);
      auto index = iter - wa_b.begin();
      //cout << "  num_a: " << num_a << " num_b: " << index-1 << endl;
      if(index-1<0) continue;
      ans = max(ans, num_a + (ll)index-1);
    }
    cout << ans << endl;

    // O(N+M)解法  累積和 + 尺取り法 (2pointers)
    // ll ans = 0;
    // ll num_a = N;// Aから読む冊数
    // for(int num_b=0; num_b<=M; num_b++){
    //   if(wa_b[num_b] > K) break;
    //   while(wa_a[num_a] + wa_b[num_b] > K){
    //     num_a--;
    //   }

    //   ans = max(ans, num_a + num_b);
    // }

    // cout << ans << endl;


}


Measured memory_bytes: 11176
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

int gcd(int a, int b) {
    return !b ? a : gcd(b, a % b);
}

int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int lc = lcm(c, d);
    a--;
    int one = !a ? 0 : a / c + a / d - a / lc;
    int two = b / c + b / d - b / lc;
    two -= one;
    cout << b - a - two;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //int t;
    //cin >> t;
    int t = 1;
    //srand(time(0));
    while (t--) solve();
}

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

using namespace std;

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

    vector<int> a(N, 0);
    vector<int> b(N, 0);

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

    for (int i = N-1; -1 < i; i--) {
        int b_sum = 0;
        for (int j = 1; i + (i + 1) * j < N; j++) {
            b_sum += b[i + (i + 1) * j];
        }
        if ((b_sum % 2) != (a[i] % 2)) {
            b[i] = 1;
        }
    }

    int M = 0;
    for (int i = 0; i < N; i++) {
        M += b[i];
    }
    cout << M << '\n';
    for (int i = 0; i < N; i++) {
        if (b[i] == 1) {
            cout << (i+1) << ' ';
        }
    }
    return 0;
}

Measured memory_bytes: 2432
#include <stdio.h>

int Count(int n){
  int cnt=0;
  while(n%2==0){
    cnt++; n/=2;
  }
  return cnt;
}

int main(){
  int n,a[209];
  scanf("%d",&n);
  for(int i=0; i<n; i++)scanf("%d",&a[i]);
  
  int ans=100;
  for(int i=0; i<n; i++)
    if(ans>Count(a[i]))ans=Count(a[i]);
  printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 300
#define LL long long
#define INF 1000000000000000000
int n,m;LL l;
LL dist[MAXN+5][MAXN+5],T[MAXN+5][MAXN+5];
LL read(){
	LL x=0,F=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*F;
}
int main()
{
	n=read(),m=read(),l=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		if(i!=j)dist[i][j]=INF,T[i][j]=INF;
	for(int i=1;i<=m;i++){
		int u=read(),v=read(),w=read();
		dist[u][v]=dist[v][u]=w;
		T[u][v]=T[v][u]=(w<=l)?0:INF;
	}
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
			if(dist[i][k]+dist[k][j]<dist[i][j])
			dist[i][j]=dist[i][k]+dist[k][j],T[i][j]=(dist[i][j]<=l)?0:INF;
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
			if(T[i][k]+T[k][j]+1<T[i][j])
			T[i][j]=T[i][k]+T[k][j]+1;
	int Q=read(); 
	while(Q--){
		int a=read(),b=read();
		if(T[a][b]==INF)printf("-1\n");
		else printf("%lld\n",T[a][b]);
	}
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

int n,m;

string s[10];

bool vis[10][10];

void dfs(int x,int y){
    if(s[x][y] != '#')
        return;
    if(vis[x][y])
        return;
    vis[x][y] = 1;
    if(x < n)
        dfs(x+1,y);
    if(y < m)
        dfs(x,y+1);
}

int main(){
    ios::sync_with_stdio(0);
    cin>>n>>m;
    for(int i=0 ; i<n ;i ++){
        cin>>s[i];
    }

    dfs(0,0);

    for(int i=0 ; i<n ; i++){
        for(int j=0 ; j<m ; j++){
            if(!vis[i][j] &&s[i][j] == '#'){
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
    for(int i=0 ; i<n ; i++){
        for(int j=0 ; j<m ; j++){
            if(s[i][j] == '#'){
                if(i+1 < n && s[i+1][j] == '#' && j+1 < m && s[i][j+1] == '#'){
                cout<<"Impossible"<<endl;
                return 0;
                }
            }
        }
    }
    cout<<"Possible"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#include <time.h>
using namespace std;

int main()
{
	int L, R, d;
	int cnt = 0;
	cin >> L >> R >> d;
	for (int i = L; i <= R; i++) {
		if (i%d == 0)
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<stack>
#include<list>
#include<deque>
#define int long long
#define mod 1000000007
using namespace std;

signed main() {
	int a, b, c; cin >> a >> b >> c;
	if (a == b&&b == c)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int K = scan.nextInt();
		int ans = 0;

		if (A <= K){
			ans += A * 1;
		}
		if (K < A){
			ans += K * 1;
		}
		if ((K - A - B) > 0){
			ans -= (K - A - B) * 1;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35768
package main

import(
	"fmt"
	//"bufio"
	//"os"
	"strings"
)

func main() {

	//line := bufio.NewScanner(os.Stdin)
	alplist := make(map[string]int)
	for i:=int(rune('a')); i<=int(rune('z')); i++ {
		alplist[string(rune(i))] = 0
	}

	var str string
	for {
		//str := line.Text()
		_, err := fmt.Scan(&str)
		if err != nil {
			break
		}
		str = strings.ToLower(str)
		rstr := []rune(str)

		for _, char := range rstr {
			//fmt.Println(string(char))
			alplist[string(char)] += 1
		}
	}
	
	for i:=int(rune('a')); i<=int(rune('z')); i++ {
		fmt.Println(string(rune(i)),":",alplist[string(rune(i))])
	}
}


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

const ll N = 200005;
struct Line{
    ll a , b;
    /// a * x + b
    ll value(ll x)
    {
        return a * x + b;
    }
    /// a*x + b = a2*x + b2
    /// x = (b2 - b) / (a - a2)
    pair < ll , ll > intersect(Line &he)
    {
        ll up = he.b - b;
        ll down = a - he.a;
        return {up , down};
    }
};
int n;
ll C , h[N];
int main()
{
    scanf("%d%lld",&n,&C);
    for(int i = 0 ; i < n; i++)
        scanf("%lld",&h[i]);
    ll ans = 0;

    vector < Line > v;
    int start = 0;

    for(int i = 0 ; i < n ; i++)
    {

        ll res = 0;
        while(start <= (int) v.size() - 2)
        {
            if(v[start].value(h[i]) > v[start+1].value(h[i]))
                start++;
            else
                break;
        }
        if(i > 0)
            res = v[start].value(h[i]) + h[i]*h[i] + C;
        if( i == n-1 )
            ans = res;
        Line line;
        line.a = -2*h[i];
        line.b = h[i]*h[i] + res;

        while(start <= (int) v.size() - 2)
        {
            Line A = v.end()[-2];
            Line B = v.back();
            pair < ll , ll > one = A.intersect(B) , tow = B.intersect(line);
            if(one.first*tow.second >= tow.first*one.second)
                v.pop_back();
            else
                break;
        }
        v.push_back(line);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7792
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

ll d[105][105];

vector<P> G[21000];
const ll Start=20001, Goal=20002;

ll memory[21000];
int main(){
    rep(i,21000) memory[i]=INF;
    ll H,W; cin>>H>>W;
    rep(i,H){
        string S; cin>>S;
        rep(j,W) if(S.at(j)=='.') d[i][j]=1;
    }

    rep(i,H) rep(j,W){
        if(i<H-1) G[i*150+j].pb(mp((i+1)*150+j,(d[i][j]+d[i+1][j])%2));
        if(j<W-1) G[i*150+j].pb(mp(i*150+j+1,(d[i][j]+d[i][j+1])%2));
    }

    G[Start].pb(mp(0,1-d[0][0]));
    G[(H-1)*150+W-1].pb(mp(Goal,1-d[H-1][W-1]));
    
    P_queue Q;
    Q.push(mp(0,Start));
    while(!Q.empty()){
        P x=Q.top(); Q.pop();
        ll A=x.first, B=x.second;
        rep(i,G[B].size()){
            ll y=G[B].at(i).first, z=G[B].at(i).second;
            if(memory[y]>A+z){
                memory[y]=A+z;
                Q.push(mp(A+z,y));
            }
            
        }
    }
    /*rep(i,H) {
        rep(j,W) cout<<memory[i*150+j]<<' ';
        cout<<endl;
    }*/
    cout<<memory[Goal]/2<<endl;

    

}

Measured memory_bytes: 1408
//agc032_b.cpp
//Sun Oct 27 17:09:11 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	vector<P> groups;
	if (n%2==0){
		for (int i=1;i<=n/2;i++){
			groups.push_back(P(i,n-i+1));
		}
	}else {
		groups.push_back(P(n,-1));
		for (int i=1;i<=(n-1)/2;i++){
			groups.push_back(P(i,n-i));
		}
	}

	vector<P> ans;
	for (int i=0;i<groups.size()-1;i++){
		for (int j=i+1;j<groups.size();j++){
			if (groups[i].second == -1){
				ans.push_back(P(groups[i].first,groups[j].first));
				ans.push_back(P(groups[i].first,groups[j].second));
			}else if (groups[j].second == -1){
				ans.push_back(P(groups[i].first,groups[j].first));
				ans.push_back(P(groups[i].second,groups[j].first));
			}else{
				ans.push_back(P(groups[i].first,groups[j].first));
				ans.push_back(P(groups[i].first,groups[j].second));
				ans.push_back(P(groups[i].second,groups[j].first));
				ans.push_back(P(groups[i].second,groups[j].second));
			}
		}
	}

	cout << ans.size() << endl;
	for (int i=0;i<ans.size();i++){
		cout << ans[i].first << " " << ans[i].second << endl;
	}


}

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

using namespace std;

void Main() {
    int N, X, T;
    cin >> N >> X >> T;

    int ans = (N / X) * T;
    if (N % X != 0) {
        ans += T;
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = List.fill(n)(sc.nextInt())
    println(a.map(m => f(m)).min)

    def f(n: Int): Int = {
      n % 2 match {
        case 0 => 1 + f(n / 2)
        case 1 => 0
      }
    }
  }
}


Measured memory_bytes: 25544
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}

ll test[1234][1234];
signed main() {
	vector<vector<ll>> abc(26, vector<ll>(2));
	ll D, c, s; cin >> D;
	for (int h = 0; h < 26; h++) {
		cin >> abc[h][0]; abc[h][1] = h + 1;
	}
	sort(abc.begin(), abc.end());
	for (int i = 0; i < D; i++) {
		for (int h = 0; h < 26; h++) {
			cin >> test[i][h];
		}
	}
	cout << abc[25][1] << endl;
	for (int h = 0; h < 26 * 14; h++) {
		cout << abc[h % 26][1] << endl;
	}
	return 0;
}

Measured memory_bytes: 5164