akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,x,a[500000];
int main(){
	scanf("%d",&n);
	int l=233333,r=233332;
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		if (i&1) a[++r]=x;
		else a[--l]=x;
	}
	if (n&1)
		for (int i=r;i>=l;i--)
			printf("%d ",a[i]);
	else
		for (int i=l;i<=r;i++)
			printf("%d ",a[i]);
}

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

int main(){
  int N;
  cin >> N;
  if (((N / 1000 == N / 100 % 10) || (N / 10 % 10 == N % 10)) 
    && (N / 100 % 10 == N / 10 % 10)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  } 
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<sstream>
#include<map>
#include<algorithm>
using namespace std;

string change(string,int);

int main(){
   int n,i;
   int pl;
   string str,z;
   string::size_type ind;
   
   cin>>n;
   getline(cin,z);
   for(i=0;i<n;i++){
      getline(cin,str);
      
      ind=str.find("Hoshino");
      while(ind!=string::npos){
         pl = (int)str.find("Hoshino");
         str = change(str,pl);
         ind = str.find("Hoshino");
      }
      cout<<str<<endl;
   }
   return 0;
}

string change(string str,int pl){
   int i,l=0;
   string name = "Hoshina";
   
   for(i=pl;i<pl+7;i++){
      str[i]=name[l];
      l++;
   }
   return str;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define sqr(x) (x)*(x)
using namespace std;

int main(){
#ifdef LOCAL
    freopen("inp.txt", "r", stdin );
    freopen("ans.txt", "w", stdout);
#endif
    ll k, x; cin >> k >> x;
    if(500*k>=x) cout << "Yes\n";
    else cout << "No\n";
}


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

using namespace std;

// {1, 2, 3} => {3, 1, 2} => 3
// {1, 2, 3 4 } => {4, 1, 2, 3} => 6
int main()
{
    long long n;
    cin >> n;
    cout << n * (n - 1) / 2 << endl;
    return 0;
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
const int N = 1e5;
ll dp[N][3];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	cin>>n;
    	ll ar[n][3];
    	for(int i = 0; i < n; i++)
    	{
    		for(int j = 0; j < 3; j++)
    		{
    			cin>>ar[i][j];
    			if(i==0)
    			{
    				dp[i][j] = ar[i][j];
    			}
    		}
    	}
    	for(int i=1;i<n;i++)
    	{
    		for(int j=0;j<3;j++)
    		{
    			dp[i][j] = max(dp[i-1][(j+1)%3]+ar[i][j],dp[i-1][(j+2)%3]+ar[i][j]);
    		}
    	}
    	ll m = max(dp[n-1][0],dp[n-1][1]);
    	m = max(dp[n-1][2],m);
    	cout<<m<<endl;
    }
    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int count = 0;
		int min = Integer.MAX_VALUE;
		for(int i=0; i<n; i++) {
			int p = in.nextInt();
			if(p<=min) {
				min=p;
				count++;
				//System.out.println(p);
			}
			
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 64548
#include <bits/stdc++.h>
using namespace std;
int main(){
    int ab[2001];
    ab[0]=1;
    for(int i=1;i<=1000;i++)ab[i]=ab[i-1]+1;
    for(int i=0;i<1000;i++)ab[2000-i]=ab[i];
 
    int n;
    while(cin>>n){
        long long int ans=0;
        for(int i=0;i<=2000;i++){
            int cd=n-i;
            if(cd>2000)continue;
            if(cd<0)break;
            ans+=(long long int)ab[i]*ab[cd];
        }
        cout<<ans<<endl;
    }
    return 0;
}

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



// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    ll A;
    long double B;
    cin >> A >>B;
    ll ans = A*B + (1e-3);
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pii pair<int, int>
#define vii vector<pii>
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vd vector<double>
#define vvi vector< vector<int> >
#define vvii vector< vector< pii > >
#define ld long double
#define mapii map<int, int>
#define mapsi map<string, int>
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pie  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-8)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'
#define output freopen("output.txt", "w", stdout)
#define mp(x, y, z) {x, {y, z}}

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

	int n, k;
	cin >> n >> k;
	vii vec(n);
	mapii mp;
	int cnt = 0;
	rep(i, 0, n)
	{
		cin >> vec[i].second;
		mp[vec[i].second]++;
	}

	set<pii> st;
	rep(i, 0, n)
	{
		vec[i].first = mp[vec[i].second];
		st.insert(vec[i]);
	}


	while(!st.empty() && k--)
	{
		auto it = st.end();
		it--;
		st.erase(it);
	}

	for(auto i : st)
		cnt += i.first;

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 20608
#include<stdio.h>
#include<stdlib.h>
#define SIZE 105
#define LENGTH 10050

int main ()
{
    int i,j,t,k=0;
    int c[SIZE][SIZE],d[LENGTH];
	int h,w;
	while(scanf("%d %d",&h,&w)!=EOF)
	{
		scanf("%d",&t);
		for(i=0;i<t;i++)
			scanf("%d",&d[i]);
		for(i=0;i<h;i++)
		{
			if(i%2==0)
				for(j=0;j<w;j++)
				{
					c[i][j]=k+1;
					d[k]--;
					if(d[k]==0)
						k++;
				}
			if(i%2==1)
				for(j=w-1;j>=0;j--)
				{
					c[i][j]=k+1;
					d[k]--;
					if(d[k]==0)
						k++;
				}
		}
		for(i=0;i<h;i++)
		{
			for(j=0;j<w-1;j++)
				printf("%d ",c[i][j]);
			printf("%d\n",c[i][w-1]);
		}
	}
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
 
 int i;
 char moji;

  scanf("%c", &moji);
 
  if((moji>= 'a') && (moji<='z')){
    printf("a");
  }
  else if((moji>= 'A') && (moji<='Z')){
    printf("A");
  }
  return 0;
}

Measured memory_bytes: 1584
def kruskal(n: int, edges: list) -> int:
    tree = [-1]*n

    def get_root(x):
        if tree[x] < 0:
            return x
        tree[x] = get_root(tree[x])
        return tree[x]

    def unite(x, y):
        x, y = get_root(x), get_root(y)
        if x != y:
            big, small = (x, y) if tree[x] < tree[y] else (y, x)
            tree[big] += tree[small]
            tree[small] = big
        return x != y

    return sum(w for (w, _, _), _ in zip(filter(lambda p: unite(p[1], p[2]), sorted(edges)), range(n)))

while True:
    n = int(input())
    if not n:
        break
    m = int(input())
    inf = float("inf")

    edges = []
    for _ in [None]*m:
        s, t, d = map(int, input().split(","))
        edges.append((d//100-1, s, t))

    print(kruskal(n, edges))


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

using namespace std;

int main() {
	string str;
	cin >> str;
	for (int i = 0; i < 19; i++) {
		if (i == 5 || i == 13) {
			cout << " ";
		}
		else {
			cout << str[i];
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define MAXN 2000
#define INF 1000000000
vector<int> G[MAXN+5];
int u,v,n,k,ex,ans;
int dfs(int x,int fa,int deep)
{
	int sum=0;
	for(int i=0;i<G[x].size();i++)
	{
		int to=G[x][i];
		if(to==fa)continue;
		sum+=dfs(to,x,deep-1);
	}
	if(deep<=0)sum++;
	return sum;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	ans=INF;
	for(int rt=1;rt<=n;rt++)
	{
		ex=0;
		int sum=0;
		for(int i=0;i<G[rt].size();i++)
		{
			int to=G[rt][i];
			int val=dfs(to,rt,k/2);
			//printf("%d %d %d\n",rt,to,val);
			sum+=val;
			if(k%2)ex=max(ex,val-dfs(to,rt,k/2+1));
		}
		sum-=ex;
		ans=min(sum,ans);
	}
	printf("%d",ans);
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;



int main() {
    int n;
    cin >> n;
    vs s(n);
    rep(i, n) {
        cin >> s[i];
    }

    int ans = 0;
    rep(i_, n) {
        bool x = true;
        rep(i, n) {
            rep(j, i) {
                if(s[(i + i_)%n][j] != s[(j + i_)%n][i]) {
                    x = false;
                    break;
                }
            }
            if(!x) break;
        }
        if(x) ++ans;
    }

    cout << ans*n << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    std::cout << std::fixed << std::setprecision(10);
    int N, K;
    cin >> N >> K;

    double ans = 0;
    double rate = 1.0 / N;
    int cnt;
    int temp;
    for (int i = 1; i <= N; i++)
    {
        rate = 1.0 / N;
        cnt = 0;
        temp = i;
        while (temp < K)
        {
            temp *= 2;
            cnt++;
        }
        rate *= pow(0.50, cnt);
        ans += rate;
    }
    cout << ans << "\n";
    return (0);
}

Measured memory_bytes: 256
import itertools

def main():
    H,W,K=map(int,input().split())
    c=[input() for _ in range(H)]
    h=[x for x in range(H)]
    w=[x for x in range(W)]
    ans=0
    for i in range(H):
        for j in range(W):
            for ph in itertools.combinations(h, i):
                for pw in itertools.combinations(w, j):
                    cnt=0
                    for k in range(H):
                        if k in ph: continue
                        for l in range(W):
                            if l in pw: continue
                            if c[k][l]=='#': cnt+=1
                    if cnt==K: ans+=1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9216
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;}
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    vector<long long> vec(n);
    for(long long i = 0; i < n; i ++){
        cin >> vec[i];
    }
    sort(all(vec));
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        for(ll j = i+1; j < n; j++){
            for(ll k = j+1; k < n; k++){
                if(vec[i] + vec[j] > vec[k] && vec[j] + vec[k] > vec[i] && vec[k] + vec[i] > vec[j]){
                    if(vec[i] != vec[j] && vec[j] != vec[k] && vec[k] != vec[i]){
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 3624
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

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

const int N = 1e5 + 10; 
const int mod = 1e9 + 7; 

int n, m, fact[N]; 

int main(int argc, char const *argv[]) {
    fact[0] = 1; 
    for(int i = 1; i < N; ++i) 
        fact[i] = (ll) fact[i - 1] * i % mod; 

    scanf("%d %d", &n, &m); 

    if(abs(n - m) > 1) puts("0"); 
    else {
        ll ans = (ll) fact[n] * fact[m] % mod;
        if(n == m) ans = 2ll * ans % mod; 
        printf("%lld\n", ans); 
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef vector<vi> vii;
const int mxN=2e5+5,M=1e9+7;
//did u check when n=1?
//is mxN correct?
struct t{
    int l,r,val;
} v[mxN];
struct EV{
    int type,x,id;
    bool operator<(const EV &o) const{
        return x<o.x;
    }
};
vector<EV>ev;
int n,m,dp[mxN];
int seg[4*mxN],lazy[4*mxN];
void down(int i,int j,int no){
    if(!lazy[no])return;
    seg[no]+=lazy[no];
    if(i!=j){
        lazy[2*no]+=lazy[no];
        lazy[2*no+1]+=lazy[no];
    }
    lazy[no]=0;
}
int query(int A,int B,int i=0,int j=n,int no=1){
    if(j<A || i>B||i>j)return -1e18;
    down(i,j,no);
    if(A<=i && j<=B)return seg[no];
    int m=(i+j)/2;
    return max(query(A,B,i,m,2*no),query(A,B,m+1,j,2*no+1));
}
void upd(int k,int A,int B,int i=0,int j=n,int no=1){
    //cout<<k<<" "<<A<<" "<<B<<" "<<i<<" "<<j<<" "<<no<<"\n";
    down(i,j,no);
    if(j<A || i>B || i>j)return;    
    if(A<=i && j<=B){
        seg[no]+=k;
        if(i!=j){
            lazy[2*no]+=k;
            lazy[2*no+1]+=k;
        }
        return;
    }
    int m=(i+j)/2;
    upd(k,A,B,i,m,2*no);
    upd(k,A,B,m+1,j,2*no+1);
    seg[no]=max(seg[2*no],seg[2*no+1]);
}   

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>v[i].l>>v[i].r>>v[i].val;
        v[i].r++;
        ev.pb({0,v[i].l,i});
        ev.pb({1,v[i].r,i});
    }
    sort(ev.begin(),ev.end());
    int cur=0;
    for(int i=1;i<=n;i++){
        while(cur<2*m && ev[cur].x==i){
            if(ev[cur].type==0){
                upd(v[ev[cur].id].val,0,i-1);
            }
            else{
                upd(-v[ev[cur].id].val,0,v[ev[cur].id].l-1);
            }
            cur++;
        }
        //cout<<query(0,0)<<"\n";
        dp[i]=query(0,i-1);
        upd(dp[i],i,i);
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans=max(ans,dp[i]);
    cout<<ans;
    
}

Measured memory_bytes: 27120
def solve()
  k, n = gets.split().map!(&:to_i)
  a = gets.split.map!(&:to_i).sort
  x = []
  n.times do |i|
    if i == (n-1)
      x.push(a[0]+k - a[i])
    else
      x.push(a[i+1] - a[i])
    end
  end
  print(x.inject(:+) - x.max)
end
solve()

Measured memory_bytes: 20464
# ABC065 C - Reconciled?
N,M = map(int,input().split())
mod = 10**9+7
ans = 0
dog = 1
monkey = 1
if abs(N-M) > 1:
    print(ans)
    exit()
elif N == M:
    for i in range(1,N+1):
        dog = (dog*i)%mod

    for i in range(1,M+1):
        monkey = (monkey*i)%mod
    ans = (2*dog*monkey)%mod

elif abs(N-M) <= 1:
    for i in range(1,N+1):
        dog = (dog*i)%mod

    for i in range(1,M+1):
        monkey = (monkey*i)%mod
    ans = (dog*monkey)%mod

print(ans)


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

int main(){

    int a, b, c;
    char x;

    while(1){
        cin >> a >> x >> b;
        if(x=='?'){
            break;
        }
        if(x=='+'){
            c = a + b;
            cout << c << "\n";
        }
        if(x=='-'){
            c = a - b;
            cout << c << "\n";
        }
        if(x=='*'){
            c = a * b;
            cout << c << "\n";
        }
        if(x=='/'){
            c = a / b;
            cout << c << "\n";
        } 
        
    }
    

    return 0;  
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i=0; i < n; i++)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
const ll INF = 1LL << 60;
//cout << fixed << setprecision(10);
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
    ll h, w; cin>>h>>w;
    vector<string>grid(h);
    set<ll> ver, hor;
    rep(i,h){
        string s;
        cin>>s;
        grid[i] = s;
    }
    rep(i,h){
        ll cnt=0;
        rep(j,w){
            if(grid[i][j]=='#') cnt++;
        }
        if(cnt==0) hor.insert(i);
    }
    rep(i,w){
        ll cnt=0;
        rep(j,h){
            if(grid[j][i]=='#') cnt++;
        }
        if(cnt==0) ver.insert(i);
    }
    rep(i,h){
        if(hor.count(i)) continue;
        rep(j,w){
            if(ver.count(j)) continue;
            cout<<grid[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
n, k = map(int, input().split())
min_num = new_min = n % k
while True:
  new_min = new_min - k
  if new_min < 0:
    new_min *= -1
  if min_num > new_min:
    min_num = new_min
  else:
    break
print(min_num)

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

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	int h;
	h = r * 100 + g * 10 + b;
	if (h % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	while (true) {
		LL n = -1;
		cin >> n;
		if (n <= 0) break;
		LL ans = n - 1;
		for (LL a = 2; a <= 1000000; ++a) {
			if ((n % a) == 0) {
				LL b = n / a;
				ans = min(ans, a - 1 + b - 1);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
            var sequenceA = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            for (int i = 0; i < sequenceA.Length; i++)
            {
                var key = sequenceA[i];
                var j = i - 1;
                while ((j >= 0) && (sequenceA[j] > key))
                {
                    sequenceA[j + 1] = sequenceA[j];
                    j--;
                }
                sequenceA[j + 1] = key;
                Console.WriteLine(string.Join(" ", Array.ConvertAll(sequenceA, x => x.ToString())));
            }
        }
    }
}

Measured memory_bytes: 5840
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll N, M;
  cin >> N >> M;
  if(2*N > M){ //c不足
    cout << M/2 << endl;
  }
  else {
    ll x = M - 2 * N; //余りのc
    cout << N + x / 4 << endl;
  }
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)


function isOk(A, x)
    for a in A
        if a < x
            return false
        end
    end
    return true
end

function main()
N, M, X = parseMap(split(readline()))

C = zeros(Int, N)
A = fill([], N)
for i in 1:N
    line =  parseMap(split(readline()))
    C[i] = line[1]
    A[i] = line[2:end]
end

min_money = 10^7

for i in 0:2^N - 1
    R = zeros(Int, M)
    m = 0
    P = digits(i, base=2, pad=N)
    for j in 1:N
        p = P[j]
        if p == 0
            m += C[j]
            for k in 1:M
                R[k] += A[j][k]
            end
        end
    end
    if isOk(R, X)
        if m < min_money
            min_money = m
        end
    end
end

println(min_money == 10^7 ? -1 : min_money)
end

main()



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

string s;
ll sum=0;

void search(ll now,ll to,ll from)
{
    if(now==s.size())
    {
        sum+=to+from;
        return;
    }
    search(now+1,to+from,s[now]-'0');
    search(now+1,to,from*10+s[now]-'0');

}


int main()
{
    cin>>s;
    search(1,0,s[0]-'0');   
    cout<<sum<<endl;
}


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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
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 main():
    n = I()
    k = I()
    a = LI()
    r = 0
    for c in a:
        r += min(abs(k-c),c) * 2

    return r


print(main())






Measured memory_bytes: 64364
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	string x;
	cin >> x;
	int n = x.size();

	stack<char> s;
	int cnt = 0;
	rep(i,n) {
		if (x[i] == 'S') s.push(x[i]);
		if (x[i] == 'T' && s.empty()) s.push(x[i]);
		if (x[i] == 'T' && s.top() == 'S') {
			s.pop();
			cnt += 2;
		}
	} 
	cout << n-cnt << endl;
	return 0;
}

Measured memory_bytes: 3724
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()  
i=0
cost=0
while m>0:
  if a[i][1]<m:
    cost+=a[i][0]*a[i][1]
    m-=a[i][1]
    i+=1
  else:
    cost+=a[i][0]*m
    break
print(cost)
    

Measured memory_bytes: 27756
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int i,j,r,c;
    int a[1000][1000];
    int sum[1000][1000];
    
    scanf("%d %d",&r,&c);
    
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&a[i][j]); //?????\???
        }
    }
    
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            a[i][c]+=a[i][j]; //c?????§??????????¨?
        }
    }
    
    for(j=0;j<c;j++){
        for(i=0;i<r;i++){
            a[r][j]+=a[i][j]; //r?????§??????????¨?
        }
    }
    
    for(i=0;i<r;i++){
        a[r][c]+=a[i][c]; //??¨???????¨?
    }
    
    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++){
            if(j==c){
                printf("%d\n",a[i][j]);
            }else{
                printf("%d ",a[i][j]);
            }
        }
    }
    
    return 0;
}

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

ll groupingRec(vector<vector<ll>> &arr, int n, int mask, vector<ll> &dp,
               vector<ll> &scores){

    if(dp[mask] != -1)
        return dp[mask];
    // Pick a non-empty subset of not chosen rabbits among 2^n possible subsets
    // and take that as one group
    ll ans = 0;
    for(int group = 1; group<(1<<n); group++){
        if(!(group&mask)){ // If these rabbits are not yet taken
            ll currGroupScore = scores[group];
            ll currRecAns = groupingRec(arr, n, mask|group, dp, scores) +
                            currGroupScore;
            if(currRecAns > ans)
                ans = currRecAns;
        }
    }
    dp[mask] = ans;
    return ans;
}

void precalculateScores(vector<vector<ll>> &arr, int n, vector<ll> &scores){

    // Store the score for each group combinations

    for(int group=0; group<(1<<n); group++){
        ll score = 0;
        for(int i=0; i<n; i++)
            if((group&(1<<i)))
                for(int j=i+1; j<n; j++)
                    if((group&(1<<j)))
                        score += arr[i][j];
        scores[group] = score;
    }
}

ll grouping(vector<vector<ll>> &arr, int n){

    vector<ll> dp(1<<n, -1);
    vector<ll> scores(1<<n);
    precalculateScores(arr, n, scores);
    ll ans = groupingRec(arr, n, 0, dp, scores);
    return ans;
}

int main()
{
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
 int n;
 cin>>n;
 vector<vector<ll>> arr(n, vector<ll>(n));
 for(int i=0; i<n; i++)
    for(int j=0; j<n; j++)
        cin>>arr[i][j];
 ll ans = grouping(arr, n);
 cout<<ans;
 return 0;
}



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

bool isPrime(int x) {

	if (x == 2) {
		return false;
	}
	if (x % 2 == 0) {
		return true;
	}
	for (int i = 3; i <= sqrt(x); i++) {
		if (x % i == 0) {
			//cout << " "<<x<<endl;
			return true;
		}
			
	}
	return false;

}


int main() {
	int n,ans=0;
	int* num;
	cin >> n;
	num=new int[n];

	for (int i = 0; i < n; i++) {
		cin >> num[i];
	}
	for (int i = 0; i < n; i++) {
		if (isPrime(num[i]) == false) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3096
n=int(input())
a=tuple(map(int,input().split()))
c1 = a.count(1)
c2 = a.count(2)
c3 = a.count(3)

dp = [[[0.0]*(n+1) for i in range(n+1)] for j in range(n+1)] 
dp[0][0][0] = 0
for i in range(c3+1):
    for j in range(c2+c3-i+1):
        for k in range(n-i-j+1):
            if i == j == k == 0:
                continue
            tmp = n
            if k != 0:
                tmp += k*dp[k-1][j][i]
            if j != 0:
                tmp += j*dp[k+1][j-1][i]
            if i != 0:
                tmp += i*dp[k][j+1][i-1]
            dp[k][j][i] = tmp/(i+j+k)

print(dp[c1][c2][c3])

Measured memory_bytes: 254216
#include<bits/stdc++.h>
using namespace std;
namespace whatever{
	int readu(){
		char ch=getchar();
		while(!isdigit(ch))
			ch=getchar();
		int value=ch-'0';
		ch=getchar();
		while(isdigit(ch)){
			value=value*10+ch-'0';
			ch=getchar();
		}
		return value;
	}
	void writeu(int n){
		if(n<10)
			putchar(n+'0');
		else{
			writeu(n/10);
			putchar(n%10+'0');
		}
	}
	typedef bitset<4000001> set_type;
	void run(){
		int n=readu();
		int sum=0;
		set_type cur;
		cur.set(0);
		for(int i=0; i<n; ++i){
			int a=readu();
			sum+=a;
			cur=((cur<<a)|cur);
		}
		for(int i=(sum+1)/2; true; ++i)
			if(cur.test(i)){
				writeu(i);
				putchar('\n');
				return;
			}
	}
}
int main(){
	whatever::run();
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff(i, c, n) for (ll i = c; i < n; i++)
#define fr(i, c, n) for (ll i = c; i >= n; --i)
#define INF 1e9 + 7

const int nax=1e5 +1 ;
bool visited[nax]={false};
vector<ll> edges[nax];
ll indegree[nax];
ll d[nax];


void dfs(ll a){
    visited[a]=true;
    for(auto i:edges[a]){
        d[i]=max(d[i],d[a]+1);
        indegree[i]--;
        if(!indegree[i]) dfs(i);
    }
}

int main(){
    ll n,m;
    cin>>n>>m;
    ff(i,0,m){
        ll a,b;
        cin>>a>>b;
        edges[a].push_back(b);
        ++indegree[b];
    }
    ff(i,1,n+1){
        if(!visited[i]&&indegree[i]==0)
        dfs(i);
    }
    ll ans=0;
    ff(i,1,n+1){
        ans=max(ans,d[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  string a;
  cin >> n;
  cin >> a;
  int ans = 0;
  int red = 0;
  int white = 0;
  for(int i = 0;i< n;i++)
  {
    if(a[i] == 'R')
    {
      red++;
    }
    else 
    {
      white++;
    }
  }
  string t;
  for(int i = 0;i< red;i++)
  {
    t+= 'R';
  }
  for(int i = 0;i < white;i++)
  {
    t+='W';
  }
  for(int i = 0;i< n;i++)
  {
    if(t[i] != a[i])
    {
      ans++;
    }
  }
  
  cout << ans/2 << endl;
}


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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)

int main()
{
    ll n,m;
    cin>>n>>m;
    vector <pair<ll,ll>> v;
    ffor(i,0,n)
    {
        int x,y;
        cin>>x>>y;
        v.push_back(make_pair(x,y));
    }
    sort(v.begin(),v.end());
    ll ans=0,i=0;
    while(m>0)
    {
        ans+=v[i].first*min(v[i].second,m);
        m-=min(v[i].second,m);
        //m=m-c;
        i++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2420
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    rep(i, N) cin >> H[i];

    const int Hmax = 1e9;

    vv<map<int, ll>> dp = vvec(N + 1, K + 2, map<int, ll>());
    dp[0][0][0] = 0;

    rep(i, N) rep(k, K + 1) {
        for (auto&& p : dp[i][k]) {
            if (p.first < H[i]) {
                if (dp[i + 1][k][H[i]] == 0) dp[i + 1][k][H[i]] = p.second + H[i] - p.first;
                else dp[i + 1][k][H[i]] = min(dp[i + 1][k][H[i]], p.second + H[i] - p.first);
                if (dp[i + 1][k + 1][p.first] == 0) dp[i + 1][k + 1][p.first] = p.second;
                else dp[i + 1][k + 1][p.first] = min(dp[i + 1][k + 1][p.first], p.second);
            }
            else {
                if (dp[i + 1][k][H[i]] == 0) dp[i + 1][k][H[i]] = p.second;
                else dp[i + 1][k][H[i]] = min(dp[i + 1][k][H[i]], p.second);
                if (dp[i + 1][k + 1][p.first] == 0) dp[i + 1][k + 1][p.first] = p.second;
                else dp[i + 1][k + 1][p.first] = min(dp[i + 1][k + 1][p.first], p.second);
            }
            //if (p.first < H[i]) {
            //    if (dp[i + 1][k].find(H[i]) == dp[i + 1][k].end()) dp[i + 1][k][H[i]] = p.second + H[i] - p.first;
            //    else dp[i + 1][k][H[i]] = min(dp[i + 1][k][H[i]], p.second + H[i] - p.first);
            //    if (dp[i + 1][k + 1].find(p.first) == dp[i + 1][k + 1].end()) dp[i + 1][k + 1][p.first] = p.second;
            //    else dp[i + 1][k + 1][p.first] = min(dp[i + 1][k + 1][p.first], p.second);
            //}
            //else {
            //    if (dp[i + 1][k].find(H[i]) == dp[i + 1][k].end()) dp[i + 1][k][H[i]] = p.second;
            //    else dp[i + 1][k + 1][p.first] = min(dp[i + 1][k + 1][p.first], p.second);
            //}
        }
    }

    ll ans = LINF;
    rep(k, K + 1) {
        for (auto&& p : dp[N][k]) {
            ans = min(ans, p.second);
        }
    }
    write(ans);
}

Measured memory_bytes: 288640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramD
    {
        static void Main()
        {
            long a = NextLong, b = NextLong;
            long gcd = MyMath.Gcd(a, b);
            var array = Enumerable.Repeat(false, 1000001).ToArray();

            for (int i = 2; i <= 1000000; )
            {
                if (gcd % i == 0)
                {
                    array[i] = true;
                    gcd /= i;
                }
                else
                {
                    i++;
                }
            }

            if (gcd > 1) array[0] = true;
            array[1] = true;

            System.Console.WriteLine(array.Count(x => x));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}
namespace Library
{
    class MyMath
    {
        public static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static long Sqrt(long n)
        {
            if (n < 0) return 0;
            long a = 0, tmp = 0, b = 0;
            for (int i = 62; i >= 0; i -= 2)
            {
                tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
                a = a << 1 | tmp;
                n -= (((b << 1) + 1) * tmp) << i;
                b = (b << 1) + tmp + tmp;
            }
            return a;
        }

        public static long Nck(int n, int k)
        {
            if (k == 0) return 1;
            if (n == 0) return 0;
            return n * Nck(n - 1, k - 1) / k;
        }
    }
}


Measured memory_bytes: 14560
$cnt = 0
def merge(left, mid, right)
    leftArr = $arr[left..mid]
    rightArr = $arr[mid+1..right]
    leftArr << 1000000001
    rightArr << 1000000001
    l = r = 0
    (left..right).each {|i|
        if leftArr[l] < rightArr[r]
            $arr[i] = leftArr[l]
            l += 1
        else
            $arr[i] = rightArr[r]
            r += 1
        end
        $cnt += 1
    }
end

def mergeSort(left, right)
    mid = (left + right)/2
    if left + 1 < right
        mergeSort(left, mid)
        mergeSort(mid+1, right)
        merge(left, mid, right)
    elsif left + 1 == right
        merge(left, mid, right)
    end
end

N = gets.to_i
$arr = gets.split.map &:to_i
mergeSort(0,N-1)
puts $arr * ' ', $cnt

Measured memory_bytes: 222332
import sys
readline = sys.stdin.buffer.readline

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    now=1
    flg = 0
    path = [1]
    pathcheck ={1}
    for i in range(min(k,n)):
        now = a[now-1]
        if now in pathcheck:
            flg = -1
            path.append(now)
            break
        path.append(now)
        pathcheck.add(now)


    if flg == 0:
        print(now)
        exit()

    x1 = path.index(now)
    x2 = len(path)-1
    x3 = (k-x1)%(x2-x1)
    print(path[x1+x3])

if __name__ == '__main__':
    main()

Measured memory_bytes: 113844
s = gets.chomp
q = gets.to_i
first = []
last = []
flg = nil

q.times do
  query = gets.chomp

  if query[0] == '1'
    flg = !flg
  else
    t, f, c = query.split
    if f == '1'
      flg ? last.push(c) : first.push(c)
    else
      flg ? first.push(c) : last.push(c)
    end
  end
end

if flg
  puts last.reverse.join + s.reverse + first.join
else
  puts first.reverse.join + s + last.join
end

Measured memory_bytes: 18556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    vector<ll> v(n, 0);
    ll ans = 0;
    rep(i, n) {
        while(h[i] > v[i]) {
            reps(j, i, n) {
                if (h[j] > v[j]) {
                    v[j]++;
                }
                else {
                    break;
                }
            }
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<string> s(n), r(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    
    for(int i = 0; i < n; i++){
        if(s[i] == "AB"){
            if (a == b && a == 1 && i != n - 1 && s[i] != s[i+1]){
				if (s[i+1][0] == 'A' || s[i+1][1] == 'A'){
					a++;
					b--;
					r[i] = "A";
				}
                else{
					a--;
					b++;
					r[i] = "B";
				}
			}
            else if (a > b){
				a--;
				b++;
				r[i] = "B";
			}
            else{
				a++;
                b--;
				r[i] = "A";
			}
        }
        else if(s[i] == "BC"){
            if (b == c && b == 1 && i != n - 1 && s[i] != s[i+1]){
				if (s[i+1][0] == 'B' || s[i+1][1] == 'B'){
					b++;
					c--;
					r[i] = "B";
				}
                else{
					b--;
					c++;
					r[i] = "C";
				}
			}
            else if (b > c){
				b--;
				c++;
				r[i] = "C";
			}
            else{
				b++;
                c--;
				r[i] = "B";
			}
        }
        else{
            if (c == a && c == 1 && i != n - 1 && s[i] != s[i+1]){
				if (s[i+1][0] == 'C' || s[i+1][1] == 'C'){
					c++;
					a--;
					r[i] = "C";
				}
                else{
					c--;
					a++;
					r[i] = "A";
				}
			}
            else if (c > a){
				c--;
				a++;
				r[i] = "A";
			}
            else{
				c++;
                a--;
				r[i] = "C";
			}
        }
        if(a < 0 || b < 0 || c < 0){
            cout << "No" << endl;
            exit(0);
        }
    }

    cout << "Yes" << endl;
    for(int i = 0; i < n; i++) cout << r[i] << endl;
    
    return 0;
}

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

int N,ans;
int val[100005];
int S;
int A[100005],siz[100005],F[100005];

int main(){
	scanf("%d",&N);
	for(int i=1;i<N;i++){
		int u,v,c;scanf("%d%d%d",&u,&v,&c);
		val[u]^=c;val[v]^=c;
	}
	for(int i=0;i<N;i++)if(val[i]){S^=(1<<val[i]);if(!((S>>val[i])&1)) ans++;}
	for(int i=1;i<(1<<16);i++){
		int j=0;
		for(;;j++) if((i>>j)&1) break;
		A[i]=A[i^(1<<j)]^j; 
		siz[i]=siz[i>>1]+(i&1);
	}
	for(int i=1;i<(1<<16);i++)if(A[i]==0){
		F[i]=siz[i]-1;
		for(int j=(i-1)&i;j;j=(j-1)&i) if(A[j]==0)
			F[i]=min(F[i],F[j]+F[i^j]);
	}
	printf("%d\n",ans+F[S]);
}

Measured memory_bytes: 4944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x; cin>>x;
    if(x==3||x==5||x==7){
        cout<<"YES"<<endl;
    }else {
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int, int> P;

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

template<typename T>
T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

int main()
{
    string n; cin >> n;
    string s = "ABC";
    cout << s + n << endl;
}

Measured memory_bytes: 256
module Main (main) where

import Control.Monad
import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main =
  replicateM 6 readInts >>= print . showAnswer . solve . concat

type Input  = [Int]
type Output = Bool

solve :: Input -> Output
solve [a,b,c,d,e,k] = all ((<=k).abs) $ ((-) <$> xs <*> xs)
  where
    xs = [a,b,c,d,e]

showAnswer :: Output -> Answer
showAnswer = String . bool ":(" "Yay!"

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes"  b
  show (YESNO b)    = bool "NO" "YES"  b
  show (AB b)       = bool "B"  "A"    b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

Measured memory_bytes: 380
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

bool isnum(char t) {
	if ('0' <= t && t <= '9')return true;
	else return false;
}
bool isalf(char t) {
	if ('A' <= t && t <= 'Z')return true;
	else return false;
}

string s; int c;

void solve() {
	c++;
	stack<int> num;

	stack<string> st;

	int n = s.length();
	string cur;
	rep(i, n) {
		//cout << i << " ";
		//cout << cur << endl;
		if (isnum(s[i])) {
			int le = i;
			while (isnum(s[i + 1]))i++;
			int len = i - le + 1;
			int z = stoi(s.substr(le, len));
			i++;
			if (isalf(s[i])) {
				//add
				rep(j, z)cur.push_back(s[i]);
				if (cur.size() >= c) {
					cout << cur[c - 1] << endl; return;
				}
			}
			else {
				num.push(z); st.push(cur);
				c -= cur.size();
				cur.clear();
			}
		}
		else if (isalf(s[i])) {
			cur.push_back(s[i]);
			if (cur.size() >= c) {
				cout << cur[c - 1] << endl; return;
			}
		}
		else if(s[i]==')'){
			if (st.empty()) {
				cout << 0 << endl; return;
			}
			int u = num.top(); num.pop();
			string ori = cur;
			rep(j, u - 1) {
				cur += ori;
				if (cur.size() >= c) {
					cout << cur[c - 1] << endl; return;
				}
			}
			string past = st.top(); st.pop();
			c += past.size();
			cur = past + cur;
		}
	}
	cout << 0 << endl; return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	while (cin >> s >> c) {
		if (s == "0")break;
		solve();
	}
	//stop
	return 0;
}


Measured memory_bytes: 6436
#include<stdio.h>

int main (void){
	int D;
  scanf("%d",&D);
  if(D==22){
  	printf("Christmas Eve Eve Eve");
  }else if(D==23){
  	printf("Christmas Eve Eve");
  }else if(D==24){
  	printf("Christmas Eve");
  }else if(D==25){
  	printf("Christmas");
  }
	return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
	static long mod=1000000007;
	static long power(long x,long y) 
    { 
        long res = 1; 
        x = x % mod; 
        while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } 
        return res%mod; 
    } 
    static long modInverse(long n) 
    { 
        return power(n, mod-2); 
    } 
    static int digits(int n)
    {
    	int ans=0;
    	while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	}
    	return ans;
    }
    static int[] dp;
    static int min(int[]h,int ind,int k)
    {
    	if(ind==h.length-1)
    		return 0;
    	if(ind>=h.length)
    		return 1000000000;
    	if(dp[ind]!=-1)
    		return dp[ind];
    	int res=1000000000;
    	for(int i=1;i<=k;i++)
    	{
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	}
    	dp[ind]=res;
    	return res;
    }
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int[]ar=split();
        int n=ar[0];
        int k=ar[1];
        int[]h=split();
        dp=new int[n+1];
        Arrays.fill(dp, -1);
        System.out.println(min(h,0,k));
    }
}

Measured memory_bytes: 58588
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 1e9;

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

    cout << (10000 - n) % 1000 << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
typedef long long ll;
using namespace std;

int main() {
    string s, a = "CODEFESTIVAL2016";
    cin >> s;
    int c = 0;
    rep(i, 0, s.size()) {
        if (s[i] != a[i]) {
            c++;
        }
    }
    cout << c << endl;
}

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

int main() {
  int H , W;
  cin >> H >> W;
  vector<vector<int>> jin(10,vector<int>(10));
  for (int i = 0; i < 10; i++){
    for (int k = 0; k < 10; k++){
      cin >> jin.at(i).at(k);
    }
  }
  vector<vector<int>> hw(H,vector<int>(W));
  for (int j = 0; j < H; j++){
    for (int k = 0; k < W; k++){
      cin >> hw.at(j).at(k);
    }
  }
  for (int k = 0; k < 10; k++){
    for (int i = 0; i < 10; i++){
      for (int j = 0; j < 10; j++){
        jin.at(i).at(j)=min(jin.at(i).at(j), jin.at(i).at(k) + jin.at(k).at(j));
      }
    }
  }
  int sum = 0;
  for (int m = 0; m < H; m++){
    for (int n = 0; n < W; n++){
      int l = hw.at(m).at(n);
      if (l==-1){
          continue;
      }
      sum += jin.at(l).at(1);
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 384