akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
int a[200005];
int b[200005];
int aa[400005];
int bb[200005];
int ne[200005];
int ans[200005];
int n;
void Net()
{
    ne[0]=-1;
    int k=-1;
    int j=0;
    while(j<n)
    {
        if(k==-1||bb[k]==bb[j])
        {
            k++;
            j++;
            ne[j]=k;
        }
        else
            k=ne[k];
    }
}
int main()
{
    cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
    }
    for(int i=0;i<n;i++)
    {
        aa[i]=a[i]^a[(i+1)%n];
        aa[i+n]=aa[i];
        bb[i]=b[i]^b[(i+1)%n];
    }
    /*for(int i=0;i<n;i++)
    {
        cout<<bb[i]<<" ";
    }
    cout<<endl;
    for(int k=0;k<2*n;k++)
    {
        cout<<aa[k]<<" ";
    }
    cout<<endl;*/
    Net();
    for(int i=0;i<n;i++)
        ans[i]=-1;
    int i=-1;
    int j=-1;
    while(i<2*n-1)
    {
        while(i<2*n-1&&j<n)
        {
            if(j==-1||bb[j]==aa[i])
            {
                i++;
                j++;
            }
            else
                j=ne[j];
        }
        if(j>=n)
        {
            ans[i-n]=b[0]^a[i-n];
            j=ne[j];
        }
    }
    for(int k=0;k<n;k++)
    {
        if(ans[k]!=-1)
            cout<<k<<" "<<ans[k]<<endl;
    }
    return 0;
}


Measured memory_bytes: 8960
#include<iostream>

typedef long long ll;

using namespace std;

const int mod = 1e9 + 7;

int n, m, a, b;

ll fact[200005];

ll rev[200005];

ll ans;

ll binPow(ll a, ll b, ll m) {
	ll ret = 1;

	while (b > 0) {
		if (b & 1) {
			ret = (ret * a) % m;
		}

		a = (a * a) % m;
		b >>= 1;
	}

	return ret;
}

void pre() {
	fact[0] = 1;

	for (int i = 1; i <= 200000; ++i) {
		fact[i] = fact[i - 1] * i % mod;
	}

	for (int i = 0; i <= 200000; ++i) {
		rev[i] = binPow(fact[i], mod - 2, mod);
	}
}

ll C(ll n, ll k) {
	return fact[n] * rev[k] % mod * rev[n - k] % mod;
}

ll f(ll x1, ll y1, ll x2, ll y2) {
	ll p1 = (x2 - x1); 
	ll p2 = (y2 - y1); 

	return C(p1 + p2, p1);
}

int main(){
	cin >> n >> m >> a >> b;
	
	pre();

	for (int x = 1; x <= n - a; ++x) {
		ans += f(x, b + 1, n, m) * f(1, 1, x, b);
		ans %= mod;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <deque>
using namespace std;

int main() {
	deque<int> A;
	int num_query; scanf("%d", &num_query);
	int command, arg1, arg2;
	for (int loop = 0; loop < num_query; loop++) {
		scanf("%d", &command);
		switch (command) {
    		case 0:
    			scanf("%d %d", &arg1, &arg2);
    			if (arg1 == 0) {
                    A.push_front(arg2);
                } else {
                    A.push_back(arg2);
                }
    			break;
    		case 1:
    			scanf("%d", &arg1);
    			printf("%d\n", A[arg1]);
    			break;
    		case 2:
    			scanf("%d", &arg1);
    			if (arg1 == 0) {
    				A.pop_front();
    			} else {
    				A.pop_back();
    			}
    			break;
    	}
	}
	return 0;
}


Measured memory_bytes: 4248
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
int n,k,ans;
string s;
int extgcd(int a,int b,int &x,int &y){
	int g=a;
	x=1,y=0;
	if(b!=0){
		g=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}
	return g;
}
 
// 逆元
int mod_inverse(int a,int m){
	int x, y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}
 
// 階乗
std::vector<int>fact;
void mod_fact(int n, int m){//N,MOD
	fact.resize(n+1);
	fact[0]=1;
	for(int i=1;i<=n;i++){
		fact[i]=fact[i-1]*i%m;
	}
}
 
// nCk mod p
int mod_nCr(int n, int k, int m){
	if(n<k)return 0;
	return fact[n]*mod_inverse(fact[k]*fact[n-k]%m,m)%m;
}

long long modpow(long long a, long long n, long long mod) {
    long long res=1;
    while (n>0) {
        if (n&1)res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

signed main(){
	
	cin>>n>>s;
	int flagcnt=0;
	rep(i,n)if(s[i]=='1')flagcnt++;
	int high=0,low=0;
	rep(i,n){
		if(s[i]=='1'){
			high+=modpow(2,n-1-i,flagcnt+1);
			if(flagcnt!=1)low+=modpow(2,n-1-i,flagcnt-1);
		}
	}
	high%=(flagcnt+1);
	if(flagcnt!=1)low%=(flagcnt-1);
	//cout<<high<<" "<<low<<endl;
	rep(i,n){
		int flagcnt2,sum,sans=0;
		if(s[i]=='1'){
			flagcnt2=flagcnt-1;
			if(flagcnt==1){
				cout<<0<<endl;
				continue;
			}
			sum=low-modpow(2,n-1-i,flagcnt2);
			sum=(sum+flagcnt2)%flagcnt2;
		}
		else{
			flagcnt2=flagcnt+1;
			sum=high+modpow(2,n-1-i,flagcnt2);
			sum=(sum+flagcnt2)%flagcnt2;
		}
		while(sum!=0){
			int flagcnt3=0,num=sum,m=(int)log2(sum);
			while(num!=0){
				flagcnt3+=(num%2);
				num/=2;
			}
			sum=sum%flagcnt3;
			sans++;
			//cout<<flagcnt<<endl;
		}
		cout<<sans+1<<endl;
	}
	//cout<<(int)log2(100)<<endl;
	
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

int solve() {
  string X, Y;
  cin >> X >> Y;
  int N = X.size();
  int M = Y.size();
  int dp[1010][1010] = {};
  rep(i, 0, N) rep(j, 0, M) {
    if(X[i] == Y[j]) {
      chmax(dp[i + 1][j + 1], dp[i][j] + 1);
    } else {
      chmax(dp[i + 1][j + 1], dp[i + 1][j]);
      chmax(dp[i + 1][j + 1], dp[i][j + 1]);
    }
  }
  cout << dp[N][M] << "\n";
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int q; cin >> q;
  rep(i, 0, q) solve();
  return 0;
}



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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> A(n);

    for (size_t i = 1; i < n; i++) {
        int ai;
        cin >> ai;
        ++A[--ai];
    }

    for (size_t i = 0; i < n; i++) {
        cout << A[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=100005,mod=1e9+7;
ll c[N];
int q[N],a[N],b[N];
int o;
PI e[N];
bool cmp(PI a,PI b){
	return a.fi!=b.fi?a.fi<b.fi:a.se>b.se;
}
#define lowbit(i) i&-i
void change(int pos,int de){
	for(int i=pos;i<N;i+=lowbit(i))c[i]+=de;
}
ll ask(int pos){
	ll ans=0;
	for(int i=pos;i;i-=lowbit(i))ans+=c[i];
	return ans;
}
int main(){
	int n=read(),m=read();
	For(i,1,n)a[i]=read();
	For(i,1,m)b[i]=read();
	For(i,1,n)if(a[i]>b[1]&&a[i]<b[m]){
		int pos=lower_bound(b+1,b+m+1,a[i])-b;
		e[++o]=mp(a[i]-b[pos-1],b[pos]-a[i]);
	}
	sort(e+1,e+o+1,cmp);
	o=unique(e+1,e+o+1)-e-1;
	For(i,1,o)q[i]=e[i].se;
	sort(q+1,q+o+1);
	ll ans=1;
	For(i,1,o){// cout<<e[i].fi<<" "<<e[i].se<<" ";
		e[i].se=lower_bound(q+1,q+o+1,e[i].se)-q;
		ll t=(ask(e[i].se-1)+1)%mod;// cout<<e[i].se<<" "<<t<<endl;
		ans+=t; change(e[i].se,t);
	}
	cout<<ans%mod<<endl;
}

Measured memory_bytes: 2944
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools


a = stdin.readline().rstrip()
if a[2] == a[3] and a[4] == a[5]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
#include <iostream>
#include <array>
//#include <fstream>
 
int main(){
    const int max_sum = 20;
    const int min_sum = 0;
    const int max_number = 100;
    int N;
    //std::ifstream ifs("517.txt");
     
    while(std::cin >> N){
        std::array<int, max_number> numbers;
        std::array<std::array<long long int, max_sum + 1>, max_number> count;
        for(int i = 0; i < max_number; ++i){
            count[i].fill(0);
        }
        for(int i = 0; i < N; ++i){
            std::cin /*ifs*/ >> numbers[i];
        }
         
        count[0][numbers[0]] = 1;
        for(int i = 1; i < N; ++i){
            for(int j = 0; j <= max_sum; ++j){
                if(j + numbers[i] <= max_sum){
                    count[i][j + numbers[i]] += count[i - 1][j];
                }
                if(j - numbers[i] >= min_sum){
                    count[i][j - numbers[i]] += count[i - 1][j];
                }
            }
        }
        std::cout << count[N - 2][numbers[N - 1]] << std::endl;
    }
     
    //ifs.close();
    return 0;
}

Measured memory_bytes: 1172
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
  dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[n-1])



Measured memory_bytes: 13980
#include <stdio.h>
int main(void) 
{
    int m, f, r;
    while(1) {
        scanf("%d %d %d", &m, &f, &r);
        if(m == -1 && f == -1 && r == -1) {
        	break;
        }
        if(m == -1 || f == -1) {
        	printf("F\n");
        }
        else if(m + f >= 80) {
        	printf("A\n");
        }
        else if(m + f >= 65 && m + f < 80) {
        	printf("B\n");
        }
        else if(m + f >= 50 && m + f < 65) {
        	printf("C\n");
        }
        else if(m + f >= 30 && m + f < 50) {
            if(r < 50) {
            	printf("D\n");
            }
            else {
            	printf("C\n");
            }
        }
        else if(m + f < 30) {
        	printf("F\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2124
fn top(x: usize) -> usize {
    let mut top = 0;
    let mut y = x;
    while y > 0 {
        top = y;
        y /= 10;
    }
    top
}

use std::collections::HashMap;
fn main() {
    let n = read::<usize>();
    let mut hm = HashMap::new();
    for i in 1..n + 1 {
        let t = top(i);
        let b = i % 10;
        let c = hm.entry((t, b)).or_insert(0);
        *c += 1;
    }

    let mut count = 0;
    for i in 0..10 {
        for j in 0..10 {
            let cij = *hm.entry((i, j)).or_insert(0);
            let cji = *hm.entry((j, i)).or_insert(0);
            count += cij * cji;
        }
    }
    println!("{}", count);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import java.util

import scala.io.StdIn
import scala.util.Try

object Main extends App {
  val INF: Long = 1e15.toLong
  val (n, x, y) = {
    val in = StdIn.readLine().split(" ").map(_.toInt)
    (in(0), in(1), in(2))
  }
  val sweets = for (_ <- 0 until n) yield {
    val k = StdIn.readLine().toInt
    for (_ <- 0 until k) yield {
      val in = StdIn.readLine().split(" ").map(_.toInt)
      Sweet(in(0), in(1), in(2))
    }
  }

  val dist = for (_ <- 0 until n) yield StdIn.readLine().split(" ").map(_.toLong)
  for (k <- 0 until n) for (i <- 0 until n) for (j <- 0 until n) dist(i)(j) = math.min(dist(i)(j), dist(i)(k) + dist(k)(j))

  val cost = Array.fill[Long](1 << n, n)(INF)
  cost(0)(0) = 0
  for (mask <- 0 until 1 << n)
    for (cur <- 0 until n)
      for (next <- 0 until n)
        if ((mask & (1 << next)) == 0) {
          val add = dist(cur)(next)
          cost(mask | (1 << next))(next) = math.min(cost(mask | (1 << next))(next), cost(mask)(cur) + add)
        }


  def knapsack(dp: Array[Long], available: Seq[Sweet]): Unit = {
    for {
      sweet <- available
      money <- 0 until sweet.price
    } {
      val deque = new util.ArrayDeque[(Int, Long)]()
      var num = 0
      while (num * sweet.price <= (y - money)) {
        //    while (num <= (y - money) / sweet.price) { ????????????
        val next = num * sweet.price + money


        val v = dp(next) - num * sweet.value
        while (!deque.isEmpty && deque.peekLast()._2 <= v) deque.pollLast()
        deque.addLast((num, v))

        dp(next) = deque.peekFirst()._2 + num * sweet.value
        if (deque.peekFirst()._1 == num - sweet.remain) deque.pollFirst()

        num += 1
      }
    }
    for (i <- 1 until dp.length) dp(i) = math.max(dp(i), dp(i - 1))
  }


  val prefix = n / 2
  val suffix = n - prefix

  val prefixDp = Array.fill[Long](1 << prefix, y + 1)(0)
  for (prefixMask <- 0 until 1 << prefix) {
    val mask = prefixMask << suffix
    val dp = prefixDp(prefixMask)
    val available = for {
      i <- 0 until n
      if (mask & (1 << i)) != 0
      sweet <- sweets(i)
    } yield sweet
    knapsack(dp, available)
  }

  val suffixDp = Array.fill[Long](1 << suffix, y + 1)(0)
  for (mask <- 0 until 1 << suffix) {
    val dp = suffixDp(mask)
    val available = for {
      i <- 0 until n
      if (mask & (1 << i)) != 0
      sweet <- sweets(i)
    } yield sweet
    knapsack(dp, available)
  }
  var ans = 0L
  for (mask <- 0 until 1 << n) {
    val suffixMask = mask & ((1 << suffix) - 1)
    val prefixMask = mask >> suffix
    val travelingCost = (for (last <- 0 until n) yield {
      cost(mask)(last) + dist(last)(0)
    }).min
    val money = math.min(x - travelingCost, y).toInt
    for (prefixMoney <- 0 to money) {
      val suffixMoney = money - prefixMoney
      val value = prefixDp(prefixMask)(prefixMoney) + suffixDp(suffixMask)(suffixMoney)
      ans = math.max(ans, value)
    }
  }
  println(ans)

  Try {

  }.recover {
    case e: Throwable => println(e)
  }

}

case class Sweet(price: Int, value: Int, remain: Int)

Measured memory_bytes: 576160
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;
 
#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  string s;
  cin >> s;
  for(ll i =0;i<s.size();i+=2) cout << s[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 592
#include<stdio.h>

#define MAX 100000
int parent(int i){
    return i/2;
}

int left(int i){
    return 2*i;
}

int right(int i){
    return 2*i + 1;
}

int main(){
    int n,i,A[MAX+1];

    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&A[i]);
    }
    for(i=1;i<=n;i++){
        printf("node %d: key = %d,",i,A[i]);
        if(parent(i) >= 1){
            printf(" parent key = %d,",A[parent(i)]);
        }
        if(left(i) <= n){
            printf(" left key = %d,",A[left(i)]);
        }
        if(right(i) <= n){
            printf(" right key = %d,",A[right(i)]);
        }

        printf(" \n");

    }
return 0;
}


Measured memory_bytes: 2052
#include<stdio.h>

int selectionSort(int A[],int N){
  int i,j,t,sw=0, minj;
  for(i=0;i<N-1;i++){
    minj = i;
    for(j=i;j<N;j++){
      if (A[j]<A[minj])minj=j;
    }
    t=A[i];A[i]=A[minj];A[minj]=t;
    if(i != minj) sw++;
  }
  return sw;
}
int main(){
  int A[100],N,i,sw;

  scanf ("%d",&N);
  for (i = 0;i<N;i++)scanf("%d",&A[i]);

  sw = selectionSort(A,N);

  for (i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",sw);
  return 0;
}
	  



Measured memory_bytes: 2108
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,k,i=0,now=1,next,tmp=0,ans=0,na,nb;
    string s;
    cin >> n >> k >> s;
    vector<int> a,b;
    while(true){
        if(i==n){
            if(now==0) b.push_back(tmp);
            else a.push_back(tmp);
            break;
        }
        next=s.at(i)-'0';
        if(next==now){
            tmp++;
            i++;
        }else{
            if(now==0) b.push_back(tmp);
            else a.push_back(tmp);
            tmp=1;
            now=next;
            i++;
        }
    }
    na=a.size(); nb=b.size();
    if(na==nb){
        a.push_back(0);
        na++;
        }
    vector<int> sa(na+1),sb(nb+1);
    sa.at(0)=0;
    sb.at(0) = 0;
    for(i=0;i<na;i++){
        sa.at(i+1)=sa.at(i)+a.at(i);
    }
    for(i=0;i<nb;i++){
        sb.at(i+1)=sb.at(i)+b.at(i);
    }
    if(nb<=k){
        ans = n;
    }
    else{
        for(i=0;i<nb-k+1;i++){
            tmp=sb.at(i+k)-sb.at(i)+sa.at(i+k+1)-sa.at(i);
            ans=max(ans,tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1404
n,m = map(int,input().split())
a=[]
b=[]
ab=[]
for i in range(n):
  a0,b0 = map(int,input().split())
  ab.append([a0,b0])
ab.sort()
money = 0
i = 0
while m > 0:
  money+=min(m,ab[i][1])*ab[i][0]
  m-=min(m,ab[i][1])
  i+=1
print(money)

Measured memory_bytes: 20064
#include <stdio.h>
 
int count_digit(int n) {
    int count = 0;
 
    while(n != 0) {
        n /= 10;
        count++;
    }
 
    return count;
}
 
int main() {
    int a, b;
 
    while(scanf("%d %d", &a, &b) != EOF) {
        printf("%d\n", count_digit(a + b));
    }
 
    return 0;
}

Measured memory_bytes: 1664
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

map<int64_t, int> prime_factor(int64_t n)
{
  map<int64_t, int> ret;
  for (int64_t i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}

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

  auto factor = prime_factor(N);

  int64_t result = 0;
  for (auto &&i : factor) {
    result = result + (sqrt(1 + 8 * i.second) - 1) / 2.0;
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 3720
using System;
using System.Linq;

class Program
{
	static void Main(string[] args)
    {  
    	var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderBy(x => x).ToArray();
        Console.WriteLine(input[0]+input[1] == input[2] ? "Yes" : "No");
    }
}

Measured memory_bytes: 13396
while True:
    ( a, op, b) = input().split()
    a = int(a)
    b = int(b)

    if op == '?':
        break
    elif op == '+':
        print( '{0}'.format( a + b))
    elif op == '-':
        print( '{0}'.format( a - b))
    elif op == '*':
        print( '{0}'.format( a * b))
    elif op == '/':
        print( '{0}'.format( a // b))

Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
int n,k,ans=0;
int a[100];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=k;i++)
	ans+=a[i];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
// ABC155A - Poor

#include <bits/stdc++.h>
using namespace std;

int main() {
	int A, B, C;
	bool answer = false;

	cin >> A >> B >> C;

	if ((A == B)&&(A != C)) {
		answer = true;
	} else if ((B == C)&&(B != A)) {
		answer = true;
	} else if ((C == A)&&(C != B)) {
		answer = true;
	}

	if (answer) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}
// 4分30秒


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

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

using namespace std;

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;


ld a, b;
ll c, d;

int main() {


//    ifstream in("/Users/koichihasegawa/src/repository/cpp/AtCoder/ABC/abc130/input.txt");
//    cin.rdbuf(in.rdbuf());

    cin >> a >> b >> c >> d;
    a--;

    ll maxNum = max(c, d);
    ll minNum = min(c, d);

    while (minNum != 0) {
        ll x = maxNum % minNum;
        maxNum = minNum;
        minNum = x;
    }

    ld cd = c / maxNum;
    {
        cd = cd * d;
    }

    ll cdPot = cd / c + cd / d - 1;


    ll bAns;
    {
        ll cdDivAns = b / cd;
        ll minAns = (b - cdDivAns * cd) / min(c, d);
        ll maxAns = (b - cdDivAns * cd) / max(c, d);
        bAns = cdDivAns * cdPot + minAns + maxAns;
    }

    ll aAns;
    {
        ll cdDivAns = a / cd;
        ll minAns = (a - cdDivAns * cd) / min(c, d);
        ll maxAns = (a - cdDivAns * cd) / max(c, d);
        aAns = cdDivAns * cdPot + minAns + maxAns;
    }

//    cout << cd << endl;
//    cout << bAns << endl;
//    cout << aAns << endl;

    ld ans = (b - a) - (bAns - aAns);

    printf("%.0Lf", ans);

    return 0;
}


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

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    boost;
    long long int n;
    cin >> n;
    map<string,long long int> mp;
    for(long long int i=0;i<n;i++)
    {
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    map<string,long long int>::iterator it;
    long long int ans=0;
    for(it=mp.begin();it!=mp.end();it++)
    {
        long long int n=it->second;
        ans+=(n*(n-1))/2;
    }
    cout << ans << endl;
}

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

int main(){
  string S;
  cin>>S;
  long long sum=0L;
  int j;

  for(int bit=0;bit<(1<<(S.length()-1));++bit){
    long long sumi=S[0]-'0';
    for(int i=S.length()-2,j=0;i>=0;--i,++j){
      if(bit&(1<<i)){
        sum+=sumi;
        sumi=S[j+1]-'0';
      }else{
        sumi=(sumi*10)+(S[j+1]-'0');
      }
    }
    sum+=sumi;
  }
  cout<<sum<<endl;
}


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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    str ans = "No";
    if(a == b && c != a) ans = "Yes";
    if(c == b && c != a) ans = "Yes";
    if(c == a && b != a) ans = "Yes";
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n,a,b,c,w,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
		if(a<b){w=a;a=b;b=w;}
		if(a<c){w=a;a=c;c=w;}
		if(a*a==b*b+c*c){printf("YES\n");
		}else{printf("NO\n");}
	}
	
	
	return 0;
}

Measured memory_bytes: 580
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }

    public static long Median(long[] x) 
    {
	int ct = x.Count();
	var y = new long[ct];
	Array.Copy(x, y, ct);
	Array.Sort(y);
	
	if (ct % 2 == 1)
	{
	    return y[ct / 2];
	}
	else
	{
	    var y1 = y[ct/2 - 1];
	    var y2 = y[ct/2];
	    return (y1 + y2) / 2;
	}
    }
}

class Program
{
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	var a = ReadLongArray();

	// b_i = a_i -i and it will calculate the average of b_is, ave
	var b = new long[n];
	for (int i = 0; i < n; i++)
	{
	    b[i] = a[i] - (i+1); // caution a[i] = A_(i+1)
	}
	
	long ave = (long) Median(b);

	long sudness = 0;
	for (int i = 0; i < n; i++)
	{
	    sudness += Math.Abs(a[i] - (ave+i+1));
	}
	WriteLine(sudness);
    }
}


Measured memory_bytes: 35204
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

long solve(string l) {
    long[string] memo;
    BinaryHeap!(Array!(Tuple!(long, string)), "a > b") q;
    q.insert(tuple(0L, l));
    while(!q.empty()) {
        auto t = q.front();
        q.popFront();
        auto s = t[1];
        if(s in memo) {
            continue;
        }
        auto v = t[0];
        if(s.uniq.count == 1) {
            return v;
        }
        memo[s] = v;
        foreach(i; iota(s.length-1)) {
            if(s[i] != s[i+1]) {
                if(s[i] != 'r' && s[i+1] != 'r') {
                    q.insert(tuple(v+1, s[0..i] ~ "rr" ~ s[i+2..$]));
                }
                if(s[i] != 'g' && s[i+1] != 'g') {
                    q.insert(tuple(v+1, s[0..i] ~ "gg" ~ s[i+2..$]));
                }
                if(s[i] != 'b' && s[i+1] != 'b') {
                    q.insert(tuple(v+1, s[0..i] ~ "bb" ~ s[i+2..$]));
                }
            }
        }
    }
    return -1;
}

void main(){
    while(true) {
        auto l = readln.strip();
        if(l == "0") {
            return;
        }
        auto ans = solve(l);
        writeln(ans >= 0 ? ans.to!string: "NA");
    }
}

Measured memory_bytes: 12636
#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main(void){
    int N;
    cin >> N;
    int half = (int)((N+1) / 2);
    cout << (double)half / (double)N << endl;
    return 0;
}

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

typedef long long ll;

int main() {
	/* freopen("input.in", "r", stdin);
	freopen("output.o", "w", stdout); */
	ll a, b, c;
	scanf("%lld %lld %lld", &a, &b, &c);
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
		printf("0");
		return 0;
	}
	ll AB = a * b;
	ll BC = b * c;
	ll AC = a * c;
	ll m = min(AB, BC);
	m = min(m, AC);
	printf("%lld", m);
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int k;
    cin >> k;
    string s;
    cin >> s;
    if (s.length() <= k) cout << s << endl;
    else cout << s.substr(0, k) << "..." << endl;
}

Measured memory_bytes: 3624
import math
import sys

def main():
    n = int(sys.stdin.readline())

    total = 0

    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                total += math.gcd(i, math.gcd(j,k))

    print(total)

main()

Measured memory_bytes: 69368
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

bool can_do_ll(vec &a, ll len){
    ll num = 0;
    rep(i,N){
        num += (a[i] + len - 1) / len - 1;
    }
    return num <= K;
}

int main() {
    cin>>N>>K;
    vec a(N);
    rep(i,N) cin>>a[i];
    ll lb = 0, ub = ll(1e+9 + 1);
    while(ub - lb > 1){
        ll cen = (ub + lb) / 2;
        (can_do_ll(a, cen) ? ub : lb) = cen;
    }
    cout<<ub<<endl;
}


Measured memory_bytes: 4768
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  xs, ys, hs = [], [], []
  for _ in range(n):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)
    
  for i in range(n):
    if hs[i] > 0:
      xx, yy, hh = xs[i], ys[i], hs[i]
      break
    
  for cx in range(0, 101):
    for cy in range(0, 101):
      H = hh + abs(cx - xx) + abs(cy - yy)
      flag = True
      for x, y, h in zip(xs, ys, hs):
        if not max(H-abs(x - cx)-abs(y-cy), 0) == h:
          flag = False
          break
      if flag:
        print(cx, cy, H)
        return

if __name__=='__main__':
  main()



Measured memory_bytes: 3064
n, m, q = map(int, input().split())
abcd = []
A = 0
B = 1
C = 2
D = 3
for i in range(q):
    abcd.append(list(map(int, input().split())))

for i in range(q):
    abcd[i][A] -= 1
    abcd[i][B] -= 1

ans = 0

for i1 in range(1,m+1):
    for i2 in range(i1,m+1):
        for i3 in range(i2,m+1):
            for i4 in range(i3,m+1):
                for i5 in range(i4,m+1):
                    for i6 in range(i5,m+1):
                        for i7 in range(i6,m+1):
                            for i8 in range(i7,m+1):
                                for i9 in range(i8,m+1):
                                    for i10 in range(i9,m+1):
                                        a = [i1, i2, i3, i4, i5, i6, i7, i8, i9, i10]
                                        now = 0
                                        for j in range(q):
                                            if a[abcd[j][B]] - a[abcd[j][A]] == abcd[j][C]:
                                                now += abcd[j][D]
                                        ans = max(ans, now)

print(ans)

Measured memory_bytes: 9204
a = input()
a = list(a)
l = len(a)
for i in range(l):
    a[i] = int(a[i])
m = sum(a)
for i in range(l):
    n = a[i]-1 + 9*(l-i-1)
    if n > m:
        m = n
print(m)

Measured memory_bytes: 38384
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int a, b, c;
	cin>>a>>b>>c;
	bool ok = false;
	rep(i, a+1) rep(j, b+1){
		if(c == i*(b-j)+(a-i)*j) ok = true;
	}
	cout<<(ok?"Yes":"No")<<endl;
	return 0;
}


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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  vector<int> stack;
  int input;
  while (cin >> input) {
    if (input == 0) {
      cout << stack.back() << endl;
      stack.pop_back();
    } else {
      stack.push_back(input);
    }
  }
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,sum=0;string s;
	cin>>s;
	cin>>q;
	while(q--)
	{
		int t,f;char c;
		cin>>t;
		if(t==1) sum++;
		if(t==2)
		{
			cin>>f>>c; 
			if(f==1) 
			{
				if(sum%2==0)
				s.insert(s.begin(),c);
				else s.insert(s.end(),c);
			}
			if(f==2) 
			{
			if(sum%2==0)
			s.insert(s.end(),c);
			else s.insert(s.begin(),c);	
			}
		}
	}
	if(sum%2==1)
	reverse(s.begin(),s.end());
	cout<<s;
 } 

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

using namespace std;
 
int main()
{
    int n;
 
    while (cin >> n, n) {
	vector<int> v(n);
 
	for (int i = 0; i < n; i++) {
	    cin >> v[i];
	}
 
	int cnt = 0;
	while (1) {
	    vector<int> next(n);
	    for(int i = 0 ; i < n ; i++){
		next[i] = count(v.begin(),v.end(),v[i]);
	    }
 
	    if(v == next) break;
	    cnt++;
	    v = next;
	}
	cout << cnt << endl;
	for(int i = 0 ; i < n ; i++){
	    if(i) cout << " " << v[i];
	    else cout << v[i];
	}
	cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3116
import java.util.*;

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

    for(int i=0;i<4;i++){
      sum += sc.nextInt();
    }
    System.out.println(sum/60);
    System.out.println(sum%60);
  }
}

Measured memory_bytes: 12000
package main

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

var sc = bufio.NewScanner((os.Stdin))

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

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, a := nextInt(), []int{}
	for i := 0; i < N; i++ {
		a = append(a, nextInt())
	}

	fmt.Printf("%d\n", ABC085B(a))
}

// ABC085B ...
func ABC085B(a []int) int {
	return len(intSliceUnique(a))
}

func intSliceUnique(target []int) (unique []int) {
	m := map[int]bool{}

	for _, v := range target {
		if !m[v] {
			m[v] = true
			unique = append(unique, v)
		}
	}

	return unique
}


Measured memory_bytes: 1804
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int x, a, b;
    cin >> x >> a >> b;

    if (b <= a) {
        print("delicious");
    } else if (b - a > x) {
        print("dangerous");
    } else {
        print("safe");
    }
    
}


Measured memory_bytes: 3608
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  map<int, int> dp;
  for(int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    dp[t]++;
  }
  vector<int> all;
  for(auto x: dp) {
    all.push_back(x.second);
  }
  sort(all.begin(), all.end());
  reverse(all.begin(), all.end());
  int ret = 0;
  while(all.size() > k) {
    ret += all[all.size()-1];
    all.pop_back();
  }
  printf("%d\n", ret);
}


Measured memory_bytes: 10748
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli a, b, c;
    lli k;
    cin >> a >> b >> c >> k;
    while(a>=b){
        b *= 2;
        k--;
    }
    while(b>=c){
        c *= 2;
        k--;
    }
    YN(k >= 0);
}

Measured memory_bytes: 3640
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(a,b,c,k):
    res = 0
    if k < a:
        res = k
    elif a <= k < a+b:
        res = a
    elif a+b <= k:
        res = a - (k - (a + b))
    return res

a,b,c,k = mi()
print(main(a,b,c,k))

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

char toupper(char x) {
    return x-'a'+'A';
}
signed main() {
    string s[3];
    cin>>s[0]>>s[1]>>s[2];
    cout<<toupper(s[0][0])<<toupper(s[1][0])<<toupper(s[2][0])<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    public static void Main()
    {
        int num = int.Parse(Console.ReadLine());
        int[,,] rooms = new int[4,3,10];
        for(int i = 0; i < num ; i++)
        {
            int[] data = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int b = data[0]; //棟
            int f = data[1]; //階
            int r = data[2]; //部屋番
            int v = data[3]; //人数
            rooms[b-1,f-1,r-1] += v;
        }
        for(int i = 0; i < 4; i++)
        {
            for(int j = 0; j < 3; j++)
            {
                for(int k = 0; k < 10; k++)
                {
                    Console.Write(" " + rooms[i,j,k]);
                }
                Console.WriteLine();
            }
            if(i < 3)Console.WriteLine("####################");
        }
    }
}


Measured memory_bytes: 18336
#include <bits/stdc++.h>
using namespace std;
int main()
{
 int n;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++)
 cin>>a[i];
 int ans=0;
 for(int i=0;i<n;i++)
 {
if((i+1)%2&&a[i]%2)
ans++;
 }
 cout<<ans;
   return 0;
}


Measured memory_bytes: 3616
import fractions
N, M = map(int, input().split())
S = input()
T = input()
g = fractions.gcd(N, M)
n = N // g
m = M // g
out = n * m * g
for k in range(g):
  if S[k * n] != T[k * m]:
    out = -1
    break
print(out)

Measured memory_bytes: 5820
const main = input => {
  const [A, B, C] = input.trim().split(' ')
  if (A[A.length - 1] === B[0] && B[B.length - 1] === C[0]) {
    console.log('YES')
  } else {
    console.log('NO')
  }
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 29636
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    int cnt = 0;
    int cc=0;
    rep(i, n) {
        if(a[i] != cc+1) {
            cnt++;
        } else {
            cc++;
        }
    }

    if(cc == 0) cout << -1 << endl;
    else cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,k;
int x[101];
int main(){
	int i;
	cin>>n>>k;
	for(i=1;i<=n;i++) cin>>x[i];
	int ans=0;
	for(i=0;i<=n;i++){
		int tmp=min(x[i],k-x[i]);
		ans+=tmp;
	}
	cout<<ans*2;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Integer num[] = new Integer[3];
    num[0] = sc.nextInt();
    num[1] = sc.nextInt();
    num[2] = sc.nextInt();
    Arrays.sort(num, Collections.reverseOrder());
    System.out.println(Math.abs(num[0]-num[1])+Math.abs(num[2]-num[1]));
  }
}

Measured memory_bytes: 23380
import heapq

N, M = map(int, input().split())

INF = 10 ** 9 + 1
G, dist = [[] for i in range(N)], [INF for j in range(N)]
check, p = [0 for k in range(N)], [-1 for l in range(N)]


def dijkstra(s):
    dist[s], pq = 0, []
    heapq.heappush(pq, (0, s))

    while len(pq) != 0:
        u = heapq.heappop(pq)
        check[u[1]] = 2

        if dist[u[1]] < u[0]:
            continue

        for v in G[u[1]]:
            if check[v[0]] != 2:
                if dist[u[1]] + v[1] < dist[v[0]]:
                    dist[v[0]], check[v[0]] = dist[u[1]] + v[1], 1
                    heapq.heappush(pq, (dist[v[0]], v[0]))


def main():
    data = []
    for i in range(M):
        l, r, d = map(int, input().split())
        G[l-1].append((r-1, d))
        p[r-1] = l - 1
        data.append((l, r, d))

    for i in range(N):
        if p[i] == -1:
            dijkstra(i)

    for i in range(M):
        l, r, d = data[i]
        if dist[r-1] - dist[l-1] != d:
            print("No")
            break
    else:
        print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 75228
# C - Snuke Festival

import bisect

N = int(input())
A = list(int(x) for x in input().split())
B = list(int(x) for x in input().split())
C = list(int(x) for x in input().split())

B.sort()
C.sort()

BC = []
for i in range(N):
    BC.append((N - bisect.bisect_right(C, B[i])))

BC = BC[::-1]
BC2 = [0] * (N+1)
for i in range(N):
    BC2[i+1] = BC2[i] + BC[i]
BC2 = BC2[::-1]

ans = 0
for i in range(N):
    b = bisect.bisect_right(B, A[i])
    ans += BC2[b]

print(ans)

Measured memory_bytes: 24744
#include <stdio.h>

int main(viod)
{
	float a, b, c, d, e, f;
	float x, y, D;
	
	while (scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f) != EOF){
		D = a * e - b * d;
		x = ((e * c) + ((-1 * b) * f)) / D;
		y = (((-1 * d) * c) + (a * f)) / D;
		
		if (x == -0.0){
			x = 0.0;
		}
		if (y == -0.0){
			y = 0.0;
		}
		printf("%.3f %.3f\n", x, y);
	}
	
	return 0;
}

Measured memory_bytes: 648
import java.util.*;

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

		while(true){
			int n = sc.nextInt();
			if(n == 0) break;

			Dice d = new Dice(1,6,3,4,2,5);
			for(int i=0;i<n;i++){
				String s = sc.next();
				if(s.equals("north")){d.move(0);}
				if(s.equals("east")) {d.move(1);}
				if(s.equals("south")){d.move(0);d.move(0);d.move(0);}
				if(s.equals("west")) {d.move(1);d.move(1);d.move(1);}
			}

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

class Dice{
	int t,b,w,e,n,s;

	Dice(int t,int b,int w,int e,int n,int s){
		this.t = t;
		this.b = b;
		this.w = w;
		this.e = e;
		this.n = n;
		this.s = s;
	}

	void move(int dir){
		Dice d = this.copy();
		switch(dir){
		case 0:
			t = d.s;
			b = d.n;
			n = d.t;
			s = d.b;
			break;
		case 1:
			t = d.w;
			b = d.e;
			w = d.b;
			e = d.t;
			break;
		}
	}

	Dice copy(){
		return new Dice(t,b,w,e,n,s);
	}
}

Measured memory_bytes: 12000