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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 5007;

int n,mo;
lint f[_]={0},coef[_]={0};

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty(),mo=ty();
	for(int i=3,j=n;i<=j;i++,j--)coef[i]=coef[j]=i-2;
	for(int i=2;i<=n;i++)coef[i]++;
	f[0]=1;
	for(int i=2;i<=n;i++)for(int j=coef[i];j<=n;j++)f[j]=(f[j]+f[j-coef[i]])%mo;
	lint ans=0;
	for(int i=0;i<n;i++)ans=(ans+f[i]*(n-i)%mo)%mo;
	cout<<ans<<lf;

	return 0;
}


Measured memory_bytes: 384
// C - Energy Drink Collector
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

	map<int,ll> AB;
	for(int i=0; i<N; ++i){
		int a,b; cin>>a>>b;
		AB[a] += b;
	}

	ll yen = 0;
	for(auto e:AB){
		ll c = min((ll)M, e.second);
		yen += c * e.first;
		if((M-=c)<=0) break;
	}
	cout<< yen <<endl;
}

Measured memory_bytes: 6528
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int n;
    cin >> n;
    if(n==1){
    cout << "Hello World" << endl;
    }else if(n==2){
    // スペース区切りの整数の入力
      int a,b;
      cin >> a;
      cin >> b;
      cout << a+b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef long long ll;

int main(void){
  int i,j;
  //  dic_t dic[200000];
  int ii[9];
  int ilen[100];
  int ia,ib,ic;
  scanf("%d %d %d\n",&ii[0],&ii[1],&ii[2]);
  scanf("%d %d %d\n",&ii[3],&ii[4],&ii[5]);
  scanf("%d %d %d\n",&ii[6],&ii[7],&ii[8]);
  int len,flg;
  scanf("%d\n",&len);
  for(i=0;i<len;i++){
    scanf("%d\n",&flg);
    //    printf("%d\n",flg);
    for(j=0;j<9;j++){
      //    printf("j%d %d %d\n",j,ii[j],flg);
      if(ii[j]==flg){
        ii[j]=0;
      }
    }
  }
  for(i=0;i<9;i+=3){
//    printf("%d %d %d \n",ii[i],ii[i+1],ii[i+2]);
    if((ii[i]+ii[i+1]+ii[i+2]) == 0){
      printf("Yes\n");
      return 0;
    }
  }
  for(i=0;i<3;i++){
//    printf("%d %d %d \n",ii[i],ii[i+3],ii[i+6]);
    if((ii[i]+ii[i+3]+ii[i+6]) == 0){
      printf("Yes\n");
      return 0;
    }
  }
//    printf("%d %d %d \n",ii[0],ii[4],ii[8]);
    if((ii[0]+ii[4]+ii[8]) == 0){
      printf("Yes\n");
      return 0;
    }
//    printf("%d %d %d \n",ii[2],ii[4],ii[6]);
    if((ii[2]+ii[4]+ii[6]) == 0){
  printf("Yes\n");
      return 0;
    }
      printf("No\n");
  return 0;


  for(i=0;i<9;i+=3){
    printf("%d %d %d \n",ii[i],ii[i+1],ii[i+2]);
  }
  return 0;

  if (ia == 1){
    printf("1\n");
    return 0;
  }
  printf("%d\n",ia/2);
  return 0;

}


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

s = {}
for i in range(n):
      text ="".join(sorted(input()))
      if text in s:
            s[text] += 1
      else:
            s[text] = 1

accum = 0
for v in s.values():
      accum += (v * (v-1))//2
print(accum)

Measured memory_bytes: 17852
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int h, w, n;
    scanf("%d%d%d", &h, &w, &n);
    vector<int> v[w];
    rep(i, n){
        int x, y;
        scanf("%d%d", &x, &y);
        v[y-1].push_back(x-1);
    }
    rep(y, w) sort(v[y].begin(), v[y].end());
    int l = -1, r = h-1;
    int ans = h;
    rep(y, w){
        ++l;
        chmax(l, y);
        for(auto x: v[y])if(l <= x && x <= r){
            if(x == l) ++l;
            else chmin(r, x-1);
        }
        if(r < l) break;
        chmin(ans, r+1);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 8704
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C;
    cin >> A >> B >> C;
    if(C>A && C < B)
    {
        printf("Yes");
    }
    else if(C<A && C > B)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

ll n, m;
 
int main(int argc, char **argv) {
	cin >> n >> m;
	ll res = min(n, m / 2);
	n -= res; m -= res * 2;
	res += m / 4;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
s=input()
lists=[int(integer)for integer in s] 
nums=int(input())

numbers=0 
strong=0 
#sに位置が初め何個ついているのかをnumbers変数に代入する
#もしｓが1で始まらなかった場合、その初めの文字を出力して終了する
for j in lists:
    if lists[0]!=1:
        break
    else:
        if j==1:
            numbers+=1
        else:
            break
#startで場合分け            
if lists[0]==1:
    if numbers>=nums:
        print(1)
        
    elif numbers<nums:
        print(lists[numbers])
else:
    print(lists[0])

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define D double
#include<bits/stdc++.h>
int main(){
  D a,b,sum=0;
  string s;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    cin>>s;
    if(s=="BTC")
      sum=sum+(a/0.1)*38000;
    else
      sum=sum+a;
  }
  cout<<fixed<<setprecision(8)<<sum;
  return 0;
}

Measured memory_bytes: 256
x1,x2,x3 = map(int,input().split())
y1,y2,y3 = map(int,input().split())
z1,z2,z3 = map(int,input().split())
ans="No"
if((x1-y1)==(x2-y2)==(x3-y3) and (y1-z1)==(y2-z2)==(y3-z3) and (x1-x2)==(y1-y2)==(z1-z2) and (x2-x3)==(y2-y3)==(z2-z3)):
    ans = "Yes"
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vector<P> a(n);
	REP(i,n) cin>>a[i].first>>a[i].second;
	ll ret=0;
	vector<int> u1(30,0);
	vector<vector<int>> u(n,vector<int>(30,0));
	ll buf=k;
	REP(i,30) {
		if(buf%2==1) u1[29-i]=1;
		buf/=2;
	}
	REP(i,n) {
		ll buf=a[i].first;
		REP(j,30) {
			if(buf%2==1) u[i][29-j]=1;
			buf/=2;
		}
	}
	REP(i,31) {
		if(i!=30&&u1[i]==0) continue;
		ll sum=0;
		REP(j,n) {
			bool d=true;
			REP(k,30) {
				if(k>i) continue;
				if(k==i) {
					if(u[j][k]) d=false;
				}
				if(k<i) {
					if(!u1[k]&&u[j][k]) d=false;
				}
			}
			if(d) sum+=a[j].second;
		}
		ret=max(ret,sum);
	}
	cout<<ret<<endl;
}

Measured memory_bytes: 16640
#include<stdio.h>
 int main(){
   int num,i,j,z;
   int key;
   scanf("%d",&num);
   int num2[num];
   
   for(i=0;i<num;i++){
     scanf("%d",&num2[i]);
   }
   
   for(z=0;z<num;z++){
     if(z == num-1){
       printf("%d\n",num2[z]);
     }
     else  {printf("%d ",num2[z]);}
   }
   for(i=1;i<num;i++){
     key = num2[i];
     j = i-1;
     while(j>=0 && num2[j] > key){
       num2[j+1] = num2[j];
       j--;
       num2[j+1] = key;
     }
     for(z=0;z<num;z++){
       if(z == num-1){
	 printf("%d\n",num2[z]);
       }
	 else {printf("%d ",num2[z]);}
       }
     }
   return 0;
 }


   
     



Measured memory_bytes: 2140
//***Little by little one travels far***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[2002];
ll bs(ll n,ll b){
  ll f=1,l=n;
  while(f<l){
    ll m=(f+l+1)/2;
    if(a[m]<b) f=m;
    else l=m-1;
  }
 // cout<<f;
  if(a[f]>=b) return(0);
  else return(f);
}

int main()
{
  ll n,s=0;
  cin>>n;
  for1(i,n) cin>>a[i];
  sort(a+1,a+n+1);
 // cout<<bs(n,219)<<" ";
  for1(i,n){
    for(ll j=i+1;j<=n;j++){
      s+=(bs(n,a[i]+a[j])-bs(n,abs(a[i]-a[j])+1));
      if((a[i]>(abs(a[i]-a[j])))) 
      s--;
      if(a[j]>(abs(a[i]-a[j])))
      s--;
      //cout<<s<<" ";
    }
  }
  //cout<<s<<" ";
  cout<<s/3;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

 Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

if (a<=b && b<=c){
System.out.println(a+" "+b+" "+c);
}else if (a<=c && c<=b){
System.out.println(a+" "+c+" "+b);
}else if (b<=a && a<=c){
System.out.println(b+" "+a+" "+c);
}else if (b<=c && c<=a){
System.out.println(b+" "+c+" "+a);
}else if (c<=a && a<=b){
System.out.println(c+" "+a+" "+b);
}else if (c<=b && b<=a){
System.out.println(c+" "+b+" "+a);
}

}
}



Measured memory_bytes: 26132
x=int(input())
a=x
i=0
j=0
if 500<= x:
  while i*500<x:
    i+=1
  i-=1
  x-=500*i
if 5<=x:
  while j*5<x:
    j+=1
  j-=1
if i==0 and j==0:
  print(0)
elif a%500==0:
  print(a//500 * 1000)
else:
  print(1000*i+5*j)


Measured memory_bytes: 9148
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int D,N,T[201],fuku[201][3],sa,dp[201][201],ans;
bool wear[201][201];
int main(){
    cin>>D>>N;
    for(int i=0;i<D;i++){
        cin>>T[i];
    }
    for(int i=0;i<N;i++){
        cin>>fuku[i][0]>>fuku[i][1]>>fuku[i][2];
    }
    for(int i=0;i<D;i++){
        for(int j=0;j<N;j++){
            if(fuku[j][0]<=T[i]&&T[i]<=fuku[j][1])wear[i][j]=true;
        }
    }
    for(int i=1;i<D;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                if(wear[i][j]&&wear[i-1][k]){
                    sa=fuku[j][2]-fuku[k][2];
                    if(sa<0)sa=sa*-1;
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+sa);
                }
            }
        }
    }
    for(int i=0;i<N;i++){
        ans=max(ans,dp[D-1][i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    vector<vector<char>> s;
    for(int i=0;i<h+2;i++){
        s.push_back(vector<char>());
        for(int j=0;j<w+2;j++){
            if(i>=1&&j>=1&&i<=h&&j<=w){
                char c;
                cin>>c;
                s[i].push_back(c);
            }else{
                s[i].push_back('.');
            }
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(s[i][j]=='#'&&s[i-1][j]!='#'&&s[i][j-1]!='#'&&s[i+1][j]!='#'&&s[i][j+1]!='#'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

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

const int N = 2e5 +1, K = 501;
int n , m , k;
int a[N] , t[2][N << 2];
void upd(bool tt ,int v , int tl , int tr , int pos){
	if(a[t[tt][v]] > a[pos])
		t[tt][v] = pos;
	if(tl == tr)
		return;
	int tm = (tl + tr) >> 1;
	if((pos + 1)/2 <= tm)
		upd(tt , v << 1 , tl , tm , pos);
	else upd(tt , v << 1 |1 , tm + 1 , tr , pos);
}
int comb(int p1 , int p2){
	if(a[p1] > a[p2])
		return p2;
	else return p1;
}
int get(bool tt , int v , int tl , int tr , int l , int r){
	if(l > r or l > tr or tl > r)
		return 0;
	if(l <= tl and tr <= r){
		return t[tt][v];
	}
	int tm = (tl + tr) >> 1;
	return comb(get(tt , v << 1 , tl , tm , l , r) , get(tt , v << 1|1 , tm + 1 , tr , l , r));
}
pii val[N];
int id = 0 , par[N];
vector < int > gr[N];
void solve(){

	vector < pair < pii , int > > seg , seg2;
	seg.pb({{1 , n} , 0});	
	id = 0;
	while(id != n / 2){
		for(auto x : seg){
			int l = x.fi.fi , r = x.fi.se , P = x.se;
			int p1 , p2; 
			if(l + 1 == r){
				val[++id] = {a[l] , a[r]};
				par[id] = x.se;
				continue;
			}
			if(l % 2 == 1)
				p1 = get(l&1 , 1 , 1, n / 2 , (l+1)/2 , (r+1)/2),
				p2 = get(r&1 , 1 ,1 , n / 2 , (p1 + 1)/2 , (r + 1)/2);
			else 
			 	p1 = get(l&1 , 1 , 1, n / 2 , (l+1)/2 , (r)/2),
			 	p2 = get(r&1 , 1 , 1 , n / 2 , (p1 + 1)/2 + 1, (r + 1)/2);
			val[++id] = {a[p1] , a[p2]};
			par[id] = P;
			if(l < p1 - 1)
				seg2.pb({{l , p1 - 1}, id });
			if(p1 + 1 < p2 - 1)
				seg2.pb({{p1 + 1 , p2 - 1}, id });
			if(p2 + 1 < r)
				seg2.pb({{p2 + 1, r} , id});
    	}
    	seg.clear();
    	seg.swap(seg2);
    }


}
main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	cin >> n;
	a[0] = 1e9;
	for(int i = 1; i <= n ; i++){
		cin >> a[i];
		upd(i&1 , 1 , 1 , n / 2, i);
    }
    solve();
    for(int i = 2 ; i <= id; i++){
    	gr[par[i]].pb(i);
    }
    set < pair<pii,int> > st;
    st.insert(mp(val[1] , 1));
    while(!st.empty()){
    	auto x = *st.begin();
    	st.erase(st.begin());
    	cout << x.fi.fi << ' ' << x.fi.se << ' ';
		for(auto to : gr[x.se])
			st.insert(mp(val[to],to));		
    }
    return 0;
}

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

int sumh[601][601], sumw[601][601];

int main(){
    int H, W;
    cin >> H >> W;
    string S[300];
    for(int i=0; i<H; i++) cin >> S[i];

    bitset<601> S2[601];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') S2[i+j+1][i-j+W+1] = 1;
        }
    }

    for(int i=1; i<=600; i++){
        for(int j=1; j<=600; j++){
            sumh[i][j] = sumh[i-1][j] + S2[i][j];
            sumw[i][j] = sumw[i][j-1] + S2[i][j];
        }
    }

    int64_t ans = 0;
    for(int k=1; k<=600; k++){
        for(int i=1; i<=600; i++){
            for(int j=1; j<=600; j++){
                if(S2[i][j] == 0) continue;
                if(i+k <= 600 && S2[i+k][j]){
                    if(j-k >= 1)   ans += sumh[i+k-1][j-k] - sumh[i][j-k];
                    if(j+k <= 600) ans += sumh[i+k-1][j+k] - sumh[i][j+k];
                }
                if(j+k <= 600 && S2[i][j+k]){
                    if(i-k >= 1)   ans += sumw[i-k][j+k] - sumw[i-k][j-1];
                    if(i+k <= 600) ans += sumw[i+k][j+k] - sumw[i+k][j-1];
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let k: usize = s.next().unwrap().parse().unwrap();
	let mut s: Vec<_> = s.next().unwrap().chars().collect();
	s.dedup();
	println!("{}", n - std::cmp::max(1, s.len().saturating_sub(2 * k)));
}


Measured memory_bytes: 2532
def main():
    #モンスター数
    n = int(input())

    #モンスターiの体力:mon[i]
    mon = list(map(int, input().split()))

    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a%b)

    ans = mon[0]
    for i in range(1,n):
        ans = gcd(ans,mon[i])

    print(ans)

main()

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

const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    
    long long N,A,B,K;
    cin >> N >> A >> B >> K;

    long long res = 0;
    for(long long x=0; x<=N; ++x) {
        if(K - A * x < 0 || (K - A * x) % B != 0) continue;
        long long y = (K - A * x) / B;
        res += COM(N, x) * COM(N, y) % MOD;
        res %= MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 12160
n = int(input())
s = []
for i in range(n):
  s.append(input())
m = int(input())
t = []
for i in range(m):
  t.append(input())
  
out = 0

s_uniq = set(s)
for i in s_uniq:
  c = len([x for x in s if x == i]) - len([x for x in t if x == i])
  if out < c:
    out = c

print(out)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
int a[N]; 
void solve(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];

    }
    for(int i = 1; i <= n; ++i) {
        if(a[i] % 2 == 0 && (a[i] % 3 != 0 && a[i] % 5 != 0)) {
            cout << "DENIED";
            return;
        } 
    }
    cout << "APPROVED";
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

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

using namespace std;

const int INF = 1e9;
const int N = 1e5;
const int MOD = 1e9 + 7;

const double PI = acos(-1);


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    map<int, int> cnt;
    int ans = 0, pen = 0;
    for (int i = 0; i < m; i++) {
        int num;
        string s;
        cin >> num >> s;
        if (s[0] == 'W' && !mp[num]) {
            cnt[num]++;
        }
        if (s[0] == 'A' && !mp[num]) {
            mp[num] = 1;
            pen += cnt[num];
            ans++;
        }
    }
    cout << ans << ' ' << pen;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
//#include<stdio.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fr(i, a, b) for(int i=a; i>=b; i--)
#define l long int
#define endl '\n'
#define pb push_back
#define pf pop.front()

using namespace std;
ll MOD=1000000000000007;
int main()
{
FAST
string s,t;
int i,mxn=0,j=0;
cin>>s>>t;
int loop=s.length()-t.length()+1;
int tsize=t.length();

int cnt=tsize;

for(i=0;i<loop;i++)
{
	    int now = t.size();
	for(j=0;j<tsize;j++)
	{
	if(s[i+j] == t[j])
	now--;	
	}
	cnt=min(cnt , now);
}


cout<<cnt;
}








Measured memory_bytes: 3608
#include <stdio.h>
int main()
{
	int n,k;
	int a;
	a=1;
	scanf("%d%d",&n,&k);
	while(n>=1)
	{
		if ((a*2)<=(a+k))
		{
			a=a*2;
		}
		else
		{
			a=a+k;
		}
		n--;
	}
	printf("%d\n",a );
	return 0;
}

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

int main() {
  int n,m;
  bool jubge = true,ans = false;
  cin >> n >> m;
  vector<string> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  vector<string> b(m);
  for(int i = 0; i < m; i++){
    cin >> b.at(i);
  }
  for(int ni = 0; ni <= n - m; ni++){
    for(int nj = 0; nj <= n - m; nj++){
      jubge = true;
      for(int mi = 0; mi < m; mi++){
        for(int mj = 0; mj < m; mj++){
          if(!(a.at(ni + mi).at(nj + mj) == b.at(mi).at(mj))){
            jubge = false;
          }
        }
        if(!(jubge)){
          break;
        }
      }
      if(jubge){
        ans = true;
        break;
      }
    }
    if(ans){
      break;
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
L = [list(map(int,input().split())) for _ in range(M)]

ans = 0
ans = min(a) + min(b)


for i in range(M):
    x = a[L[i][0]-1] + b[L[i][1]-1] - L[i][2]
    ans = min(ans, x)

print(ans)

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

int main(){
    int N, count =0;
    cin >> N;
    vector<int> a(N);

    for(int i=0; i<N; i++){
	cin >> a[i];
	if(a[i] != i+1)
	    count++;
    }    
    cout << (count<=2? "YES": "NO") << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << endl;
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << endl;
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

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

  // X >= b^p
  // log X >= p log b
  // log X / log b >= p
  
  if(X == 1){
    cout << 1 << endl;
    return 0;
  }

  ll max = 1;

  for(int b=2; b<X; ++b){
    ll p = (int)(log((double)X) / log((double)b) + EPS);
    if(p < 2){
      continue;
    }
    ll ans = 1;
    rep(i, 0, p){
      ans *= b;
    }
    if(max < ans){
      max = ans;
    }
  }

  cout << max << endl;

  return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
# s,tをリストにする
s = list(s)
t = list(t)

# 変数count,judgementに0を代入
count = 0
judgment = 0

# sの長さだけ順番入れ替えを繰り返し
while count <= len(s):
    item = s.pop()
    s.insert(0,item)
    if s == t:
        # s==tになったらjudgmentでカウントアップ
        judgment += 1
    # 回数をカウントアップ
    count +=1

# 一回もs==tになってなければNo
if judgment == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9128
#include<stdio.h>
int main(void)
{
	int n,i,w=100000;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		w=w*1.05;
		if(w%1000>0){
			w=w-(w%1000)+1000;
		}
	}
	printf("%d\n",w);
	return 0;
}	

Measured memory_bytes: 1020
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn dfs(graph: &Vec<Vec<usize>>, ver: usize, prev: usize, cnt: &mut Vec<usize>) {
    for node in &graph[ver] {
        if *node == prev {
            continue;
        }
        cnt[*node] += cnt[ver];
        dfs(&graph, *node, ver, cnt)
    }
}

fn main() {
    input! {
        n: usize, q: usize,
        ab: [(usize1, usize1); n-1],
        px: [(usize1, usize); q],
    }
    let mut graph = vec![vec![]; n];
    for (a, b) in ab {
        graph[a].push(b);
        graph[b].push(a);
    }

    let mut cnt = vec![0; n];

    for (p, x) in px {
        cnt[p] += x;
    }

    dfs(&graph, 0, 0, &mut cnt);

    for i in 0..n {
        print!("{}{}", cnt[i], if i == n - 1 { "\n" } else { " " })
    }
}


Measured memory_bytes: 33276
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,x;
    cin>>a>>b>>c;
    if(a>b){
        x=a;
        a=b;
        b=x;
    }if(b>c){
        x=b;
        b=c;
        c=x;
    }if(a>b){
        x=a;
        a=b;
        b=x;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 3104
#include<cstdio>
#include<set>
#include<cstring>
#include<queue>
#include<string>
using namespace std;
int dp[202222][3][3][2],n;
#define mod 998244353
void addto(int&x,int y){
	x+=y;
	if(x>=mod)x-=mod;
}
char s[202222];
int brute(){
	set<string> Set;
	queue<string> q;
	string S = s;
	q.push(S);
	Set.insert(S);
	while(!q.empty()){
		S = q.front();
		q.pop();
		for(int i=0; i<n-1; i++)if(S[i] != S[i+1]){
			char f = (int)('a') + 'b' + 'c' - S[i] - S[i+1];
			string S2 = S.substr(0,i);
			S2 += f;
			S2 += f;
			S2 += S.substr(i+2, n-(i+2));
			if(!Set.count(S2)){
				Set.insert(S2);
				q.push(S2);
			}
		}
	}
	return Set.size();
}
int main(){
	scanf("%s",s);
	n = strlen(s);
	if(n <= 4){
		printf("%d\n",brute());
		return 0;
	}
	int w = 0;
	bool flag = false, allsame = true;
	for(int i=0; i<n; i++){
		w += (s[i]-'a') % 3;
		if(i > 0 && s[i] == s[i-1])
			flag = true;
		if(i > 0 && s[i] != s[i-1])
			allsame = false;
	}
	if(allsame){
		printf("1\n");
		return 0;
	}
	w %= 3;

	for(int i=0; i<3; i++)dp[1][i][i][0] = 1;
	for(int i=1; i<n; i++){
		for(int sum=0; sum<3; sum++)
		for(int lst=0; lst<3; lst++)
		for(int t=0; t<2; t++)if(dp[i][sum][lst][t])
			for(int j=0; j<3; j++)
				addto(dp[i+1][(sum+j)%3][j][t|(j==lst)], dp[i][sum][lst][t]);
	}
	int res=0;
	for(int lst=0; lst<3; lst++)addto(res, dp[n][w][lst][1]);
	if(!flag)addto(res,1);
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 14592
import java.util.*;
import java.lang.*;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int [n+1];
		int b=0;
		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();
		}
		for(int i=1;i<=n;i++)
		{
			if(((a[i]%2)!=0) && ((i%2)!=0))
				b++;
		}
		System.out.println(b);
	}
}

Measured memory_bytes: 35664
/*input
6
40 1 30 2 7 20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 1e5+1;
int a[N];
int n;

bool check(int ind){
	int suma = 0;
	RE(i,ind)suma += a[i];
	for(int i= ind+1;i <= n;i++){
		if(2*suma >= a[i]){
			suma += a[i];
		}
		else return 0;
	}
	return 1;
}

void solve(){
  	cin >> n;
  	RE(i,n){
  		cin >> a[i];
  	}
  	sort(a+1,a+n+1);
  	int lo = 1;
  	int hi = n;
  	while(lo < hi){
  		int mid = (lo+hi)/2;
  		if(check(mid))hi = mid;
  		else lo = mid+1;
  	}
  	cout << n-lo+1;
}


signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 4392
def Dive(tree, nodei, ans0, ans1, ans2)
   
  ans0 << nodei
  if tree[nodei][1] != -1
    Dive(tree, tree[nodei][1], ans0, ans1, ans2)
  end
  ans1 << nodei
  if tree[nodei][2] != -1
    Dive(tree, tree[nodei][2], ans0, ans1, ans2)
  end
  ans2 << nodei
end
 
tree, ans0, ans1, ans2 = [], [], [], []
 
n = gets.to_i
pretop = Array.new(n, 0) << 1
 
n.times do
  x = gets.split.map(&:to_i)
  tree << x
  pretop[x[1]] += 1
  pretop[x[2]] += 1
end
 
tree = tree.sort_by{|n| n[0]}
 
Dive(tree, pretop.index(0), ans0, ans1, ans2)
puts "Preorder\n #{ans0.join(" ")}\n",
     "Inorder\n #{ans1.join(" ")}\n",
     "Postorder\n #{ans2.join(" ")}"


Measured memory_bytes: 6872
import java.util.*;

class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int arr[] = new int[n];
    for(int i=0;i<n;i++){
      arr[i] = sc.nextInt();
    }
    Arrays.sort(arr);    
    int x = 0;
    for(int i=0;i<n-1;i++){
      x += arr[i];
    }
    if(arr[n-1]<x){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<vector<int>> G(H + 2, vector<int>(W + 2, 0));
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            G[i][j] = -1;
        }
    }
    int color = 0;
    for (int i = 1; i <= H; i++) {
        if (i % 2 == 1) {
            for (int j = 1; j <= W; j++) {
                if (A[color]) {
                    G[i][j] = color + 1;
                    A[color]--;
                } else {
                    color++;
                    G[i][j] = color + 1;
                    A[color]--;
                }
            }
        } else {
            for (int j = W; 1 <= j; j--) {
                if (A[color]) {
                    G[i][j] = color + 1;
                    A[color]--;
                } else {
                    color++;
                    G[i][j] = color + 1;
                    A[color]--;
                }
            }
        }
    }
    rep(i, H) {
        rep(j, W) { cout << G[i + 1][j + 1] << " "; }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int euler(int num){

	 int ret = num;

	 for(int i = 2; i*i <= num;  i++){
			if(num%i == 0) {
				  ret  = ret/i*(i-1);
				  while(num%i == 0)num /= i;
			}
	  }
	  if(num != 1) ret = ret/num*(num-1);
	  return ret;
}

int main(){

	int N;
	scanf("%d",&N);

	printf("%d\n",euler(N));

	return 0;
}



Measured memory_bytes: 3212
import time

p0 = time.time()
S = input()
n = len(S)
Y = {0:1}
# print(Y)
Y[0] = 1
A = [0]
pk = 0
for i in range(1,n+1):
    # print(S[-i])
    k = (int(S[-i])*pow(10,i-1,2019)+pk)%2019
    A.append(k)
    if k not in Y:
        Y[k] = 1
    else:
        Y[k] += 1
    pk = k

# print(A)
# print(Y)
# print(time.time()-p0)
c = 0
for y in Y:
    d = Y[y]
    c += d*(d-1)//2
print(c)

Measured memory_bytes: 16492
def is_collect(fixed_number):
  score = 0
  for i in range(1, 7):
    score += int(fixed_number[i]) * (i + 1)
  for i in range(7, 12):
    score += int(fixed_number[i]) * (i - 5)
  last = 11 - score % 11
  if str(last) == fixed_number[0] or (last >= 10 and fixed_number[0] == "0"):
    return True
  else:
    return False

def check(s):
  index = s.index("?")
  cnt = 0
  for i in range(10):
    c = str(i)
    fixed_number = s[:index] + c + s[index + 1:]
    if is_collect(fixed_number):
      cnt += 1
      ret = i
  if cnt == 1:return ret
  else:return None

ans = check(input()[::-1])
print(ans if ans != None else "MULTIPLE")



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    bool flag = false;
    for (int i = 0; i < t.size(); i++) {
        if (i == t.size() - 1) {
            flag = true;
            break;
        }
        if (s[i] == t[i]) {
            continue;
        } else {
            break;
        }
    }
    if (flag) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line[] = br.readLine().split(" ");
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);
        int c = Integer.parseInt(line[2]);
        int k = Integer.parseInt(br.readLine());
        
        for (int i = 0; i < k; i++) {
            if (a >= b && a >= c) a = a * 2;
            else if (b >= a && b >= c) b = b * 2;
            else if (c >= a && c >= b) c = c * 2;
        }
        System.out.println(a + b + c);
    }
}


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

using namespace std;

#define endl            "\n"
#define sz(x)          (int) (x.size())
#define all(v)          v.begin(), v.end()
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))


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

const int N = 1e5 + 2, M = 3e5 + 5;

int ne, head[N], nxt[M], to[M], vis[N];

void initGraph(int n){ // reset graph
    memset(head, -1, n * sizeof(head[0]));
    ne = 0;
}
void addEdge(int f, int t){
    to[ne] = t;
    nxt[ne] = head[f];
    head[f] = ne++;
}

void addBidirectedEdge(int u, int v){
    addEdge(u, v);
    addEdge(v, u);
}

void dfs(int u){
    vis[u] = 1;
    for(int k = head[u]; ~k; k = nxt[k]){
        int v = to[k];
        if(!vis[v]) dfs(v);
    }
}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int n, m; cin >> n >> m;

    initGraph(n);

    while(m--){
        int u, v; cin >> u >> v;
        v--, u--;
        addBidirectedEdge(u, v);
    }
    int comp = 0;
    for(int i = 0; i < n; i++){
        if(!vis[i]){
            dfs(i);
            comp++;
        }
    }

    cout << comp - 1;
    return 0;
}


Measured memory_bytes: 7160
import math
a,b=map(int,input().split())
amin=math.ceil(a/0.08)
amax=(a+1)/0.08
if amax==float(int(amax)):
  amax=int(amax-1)
else:
  amax=math.floor(amax)
bmin=math.ceil(b/0.1)
bmax=(b+1)/0.1
if bmax==float(int(bmax)):
  bmax=int(bmax-1)
else:
  bmax=math.floor(bmax)
  
if bmax<amin or amax<bmin:
  print(-1)
else:
  if amin<bmin:
    print(bmin)
  else:
    print(amin)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 200050;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
ll dp[N];
ll a[N];
ll sum[N];
int n;

void solve()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%lld", &a[i]);
    sum[1] = a[1];
    for (int i = 3; i <= n; i += 2)
        sum[i] = sum[i - 2] + a[i];
    for (int i = 2; i <= n; ++i)
    {
        if (i & 1)
            dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
        else
            dp[i] = max(sum[i - 1], dp[i - 2] + a[i]);
    }
    printf("%lld\n", dp[n]);
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 8488
//write：Sakura
//id：
//problem：
//note：

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long ll;

ll a,b,c;
ll k;

ll ans1=0,ans2=0;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%lld %lld %lld",&a,&b,&c);
	scanf("%lld",&k);
	ans1=a-b;
	ans2=-(a-b);
	if(k%2==0){
		printf("%lld\n",ans1);
		exit(0);
	} 
	else{
		printf("%lld\n",ans2);
		exit(0);
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        int e = sc.nextInt();
        int s = sc.nextInt();
        if((e <= 8) && (s <= 8)){
        	System.out.println("Yay!");
        }else{
        	System.out.println(":(");
        }
    }
}

Measured memory_bytes: 35836
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def inv(x):
    return pow(x, mod - 2, mod)

def main():
    r1,c1,r2,c2 = LI()

    r = 0
    t1 = 1
    u1 = c2 + 1
    t2 = 1
    u2 = c1
    for i in range(1, r2+2):
        t1 *= u1
        t1 %= mod
        u1 += 1
        t1 *= inv(i)
        t1 %= mod
        t2 *= u2
        t2 %= mod
        u2 += 1
        t2 *= inv(i)
        t2 %= mod
        if i > r1:
            r += t1 - t2
            r %= mod

    return r

print(main())





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

int main(void){
  int n;
  cin >> n;
  int vec[n];
  for(int i=1;i<=n;i++) cin >> vec[i];
  int now=1;
  int count=0;
  bool judge=false;
  for(int j=0;j<n;j++){
    now=vec[now];
    count++;
    if(now==2){
      judge=true;
      break;
    }
  }
  if(judge) cout << count << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
using namespace std;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res % mod * a % mod;
        a = a % mod * a % mod;
        n >>= 1;
    }
    return res;
}

int main(void){
  long long N;
  cin >> N;
  long long MOD=1000000007;
  long long result;
  result = modpow(10,N,MOD) - 2*modpow(9,N,MOD)  + modpow(8,N,MOD);
  while(result < 0){
    result = result + MOD;
  }
  cout << result % MOD << endl;
}

Measured memory_bytes: 3504
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int a,b,h;
  cin>>a>>b>>h;
  cout<<(a+b)*h/2<<endl;
  return 0;
}


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

int main(){
    int q,a,b;
    std::string str,fo,p;

    std::cin>>str>>q;
    
    for(int i=0; i<q; i++){
        std::cin>>fo>>a>>b;
        
        if(fo=="print"){
            std::cout<<str.substr(a,b-a+1)<<std::endl;
            
        }else if(fo=="reverse"){
            std::reverse(str.begin()+a, str.begin()+b+1);
            
        }else if(fo=="replace"){
            std::cin>>p;
            str.replace(a, b-a+1, p);
        }
    }
    return 0;
}


Measured memory_bytes: 3228
#include <stdio.h>

int main(void){
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);

    if(a == 1 && b == 2 || a == 2 && b == 1){
        printf("3");
    }else if(a == 2 && b == 3 || a == 3 && b == 2){
        printf("1");
    }else if(a == 3 && b == 1 || a == 1 && b == 3){
        printf("2");
    }
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int n;
    cin>>n;
    vi v(n);
    int mini = 1<<20;
    rep(i,n){
        cin >> v[i];
        mini = min(mini, v[i]);
    }
    repi(i,1,mini+1){
        bool flag = true;
        rep(j, n)
        {
            if(v[j]%i!=0){
                flag = false;
            }
        }
        if(flag){
            cout << i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  int t = 0;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  for (int i = 0; i < K; i++) {
    t += a[i];
  }
  cout << t << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>

int main()
{
  std::string str;
  std::cin >> str;

  std::sort(str.begin(), str.end());
  char c=0;
  int count = 0;
  for(const auto& e : str)
  {
    if( e == c )
    {
      count += 1;
    }
    else
    {
      if(count %2 != 0 ) { std::cout << "No"; return 0; }
      count = 1;
      c = e;
    }
  }
  if(count %2 != 0 ) { std::cout << "No"; return 0; }
  std::cout << "Yes";
}


Measured memory_bytes: 256