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

using namespace std;

const int MOD=1000000007;

long N = 2000, K = 2000;
long DP_SIZE_N = N + 1;
long DP_SIZE_K = K + 1;

// 全体計算
// nCk
vector<vector<long> > DP;

void init(){
    DP.resize(DP_SIZE_N);
    for(int i=0; i<DP_SIZE_N; ++i){
        DP[i].resize(DP_SIZE_K);
    }
}

void calc_Combination(){
    DP[0][0] = 1;
    for(int i=1; i<=N; ++i){
        DP[i][0] = 1;
        for(int j=1; j<=min(long(i), K); ++j){
            DP[i][j] = (DP[i-1][j-1] + DP[i-1][j]) % MOD;
        }
        for(int j=min(long(i), K)+1; j<=K; ++j){
            DP[i][j] = 0;
        }
    }
}

int main(){
    cin>>N>>K;
    DP_SIZE_N = N + 1;
    DP_SIZE_K = K + 1;
    init();
    calc_Combination();
    // cout<<DP[N][K]<<endl;

    if(N==K){
        cout<<1<<endl;
        for(int i=2; i<=K; ++i){
            cout<<0<<endl;
        }
        return 0;
    }

    for(int i=1; i<=K; ++i){
        long ans_l = DP[N-K-1][i-1+1-1];
        long ans_r = DP[N-K-1][i-1+1-1];
        long ans_lr = DP[N-K-1][i-1+2-1];
        long ans;
        if(i==1){
            ans = 0;
        }else{
            ans = DP[N-K-1][i-1+0-1];
        }
        long ans_sum = (ans_l + ans_r + ans_lr + ans) % MOD;
        // cout<<ans_l<<" "<<ans_r<<" "<<ans_lr<<" "<<ans<<endl;
        // cout<<DP[K-1][i-1]<<endl;
        cout<<(DP[K-1][i-1] * ans_sum) % MOD<<endl;
    }

    return 0;
}


Measured memory_bytes: 31616
<?php
$rooms = array_fill_keys(range(1,10),0);
$floors = array_fill_keys(range(1,3),$rooms);
$buildings = array_fill_keys(range(1,4),$floors);
$n = trim(fgets(STDIN));
for($i = 0; $i < $n; $i++){
	fscanf(STDIN,"%d %d %d %d",$b,$f,$r,$v);
	$buildings[$b][$f][$r] += $v;
}
foreach($buildings as $floors){
	$floor = array();
	foreach($floors as $rooms){
		$floor[] = sprintf(' %s%s',implode(" ", $rooms),PHP_EOL);
	}
	$tenant[] = implode("", $floor);
}
echo implode(str_repeat("#",20).PHP_EOL,$tenant);

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

int main() {
  ll N,M;
  cin >> N >> M;
  vector<ll> ans1(N,0),ans2temp(N,0),ans2(N,0),p(M);
  vector<bool>flag(N,0);
  vector<string> S(M);
  rep(i,M) {
    cin >> p[i] >> S[i];
    if(flag[p[i]-1]==0){
      if(S[i]=="WA") ans2temp[p[i]-1]++;
      else {
        ans1[p[i]-1]=1;
        ans2[p[i]-1]=ans2temp[p[i]-1];
        flag[p[i]-1]=1;
     }
    }
  }
  
  cout << accumulate(ans1.begin(), ans1.end(), 0) << " " << accumulate(ans2.begin(), ans2.end(), 0) << endl;
  return 0;
}

Measured memory_bytes: 9592
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
using namespace std;

void solve(){
  int k, x; cin >> k >> x;
  for(int i = x - k + 1; i < x + k; i++) cout << i << endl;
  return;
}

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


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint factorial(int n){ return fact[n]; }
} C(1000010);


void solve()
{
  int n;
  cin >> n;

  mint m8 = 8;
  mint m2 = 2;
  mint ans = 0;

  // 0,9が2こ, n = 3
  // ans += m8.pow(1) * C(3, 1) * 2;

  // 0,9が3こ, n = 3
  // ans += m8.pow(0) * C(3, 0) * 3*2;

  // 0,9がkこ
  for(int k = 2; k <= n; ++k)
  {
    mint mk = k;
    ans += m8.pow(n - k) * C(n, n - k) * (m2.pow(k) - 2);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 18648
n,m = map(int,input().split())
cnt = 0
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append([a,b])
L.sort()

cnt = 0
sum1 = 0
for i in range(n):
    price  = L[i][0]*L[i][1]
    num = L[i][1]
    if cnt + num <= m:
        cnt +=num
        sum1 +=price
    elif cnt + num > m:
        num = m - cnt
        sum1 += num*L[i][0]
        break
print(sum1)

Measured memory_bytes: 20072
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <string>
#include <cctype>
#include <cassert>
#include <map>
#include <memory>
#include <memory.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<ll, string> chara;

chara cs[100010];
map<string, bool> id;
vector<chara> fav;
vector<chara> other;

int main(){
  ll N, M, L, K;
  while(cin >> N >> M >> K >> L && (N || M || L || K)){
    fav.clear();
    other.clear();
    id.clear();
    rep(i, N){
      cin >> cs[i].second >> cs[i].first;
      cs[i].first *= -1;
    }
    rep(i, M){
      string name;
      cin >> name;
      id[name] = true;
    }
    sort(cs, cs + N);
    rep(i, N){
      cs[i].first *= -1;
      if(id[cs[i].second]) fav.push_back(cs[i]);
      else other.push_back(cs[i]);
    }
    int a = other.size();
    int ub = min(M, K) + 1;
    int lb = 0;
    
    while(ub - lb > 1){
      int mb = (ub + lb) / 2;
      int rest = K - mb;
    
      if(rest >= a){
	lb = mb;
      }else{
	chara last = other[rest];
	
	ll need = 0;
	rep(i, mb){
	  if(last.second < fav[i].second){
	    need += max(last.first + 1 - fav[i].first, 0LL);
	  }else{
	    need += max(last.first - fav[i].first, 0LL);
	  }
	}
	if(need > L) ub = mb;
	else lb = mb;
      }
    }
    cout << lb << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include<math.h>


int main() {
  long long N;
  std::cin >> N;
  long long power = 1;
  for(long long i = 1; i <= N; i++){
    power = (power * i) % 1000000007;
  }

  std::cout << power;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;

int val[4];

int main() {
	memset(val, -1, sizeof val);
	int n, m;
	cin>>n>>m;
	int ada = 1;
	for(int i = 0;i < m;i++) {
		int u, v;
		cin>>u>>v;
		if(val[u] != -1 && val[u] != v) ada = 0;
		else val[u] = v;
	}
	if(val[1] == 0 && n > 1) ada = 0;
	if(ada == 0) {
		cout<<-1<<endl;
		return 0;
	}
	for(int i = 1;i <= n;i++) {
		if(val[i] == -1) {
			if(i == 1 && n != 1) cout<<1;
			else cout<<0;
		} else cout<<val[i];
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    string N; cin >> N;
    reverse(all(N));
    int ans=0;
    int pos=0;
    rep(i,SZ(N)){
        if((N[i]-'0')+pos==5 && i!=SZ(N)-1){
            if(N[i+1]-'0'+1>5) {
                ans+=5;
                pos=1;
            } else {
                ans+=5;
                pos=0;
            }
        }
        else if((N[i]-'0')+pos>5){
            ans+=10-((N[i]-'0')+pos);
            pos=1;
        } else {
            ans+=(N[i]-'0')+pos;
            pos=0;
        }
    }
    if(pos==1) ans++;
    cout << ans << endl;

}


Measured memory_bytes: 1948
#include <iostream>
#include <cstring>
#define rep(i,beg,end) for(int i=(beg);((beg<end)&& i<(end)) || ((beg>end)&& i>(end));((beg)<(end)&&((i++,1)) || (beg)>(end)&&((i--,1))))
using namespace std;

int w[102],v[102];
int dp[102][100002];
int main(){
	int n,W;
	cin>>n>>W;
	rep(i,0,n)
		cin>>w[i]>>v[i];
	memset(dp,0x3f,sizeof dp);
	dp[0][0]=0;
	dp[0][v[0]]=w[0];
	rep(i,1,n){
		dp[i][0]=0;
		dp[i][v[i]]=w[i]; 
		rep(j,0,100001){
			if(j-v[i]>=0)
				dp[i][j]=min(dp[i][j],min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]));
			else dp[i][j]=min(dp[i-1][j],dp[i][j]);
		}
	}
	rep(i,100001,-1){
		if(dp[n-1][i]!=0x3f3f3f3f && dp[n-1][i]<=W){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 40192
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

    ll x, amt=100, cnt=0;
    cin >> x;

    while(amt<x){
        ll i=amt/(ll)100;
        amt+=i;
        cnt++;
    }

    cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define i64 long long
int main()
{
  i64 n;
  vector <i64> v;
  cin >>n;
  for(i64 i=1;i<=n;i++){
    i64 sq = i*i;
    if(sq<=n){
      //cout <<sq<<endl;
      v.push_back(sq);
    }
  }
 cout <<v.back()<<endl;
 return 0;
}


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

int main() {
	int n;
	cin >> n;
	long long int a[n];
	int i;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long int neg = 0, min = abs(a[0]), sum = 0, zero = 0;
	for (i = 0; i < n; i++) {
		if (a[i] < 0)
			neg++;
		if (a[i] == 0)
			zero = 1;
		if (abs(a[i]) < min)
			min = abs(a[i]);
		sum += abs(a[i]);
	}
	if (neg % 2 == 1 && zero == 0)
		sum -= min * 2;
	cout << sum;
	return 0;
}

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

int main(){
    string s;
    cin>>s;

    int n=s.size();
    int t=0;
    for(int i=0;i<n;i++) t+=(s[i]-'0');

    if(t%9==0) cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
int main() {
  char s[10004];
  int n;
  int y;
  cin>>n;
  cin>>s;
  y=strlen(s);
  for(int i=0;i<y;i++){
    if(s[i]+n>90){
      cout<<(char)(s[i]+n-26);
    }else{
      cout<<(char)(s[i]+n);
    }
  }
  cout<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e18;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin >> a[i];
        b[i]=a[i];
    }
    ll ans=INF;
    {
        //正、負、正、、、
        ll cst1=0,sum1=0;
        rep(i,n){
            if(i%2==0){
                if(sum1+a[i]>0){
                    sum1+=a[i];
                    continue;
                }
                cst1+=1-(sum1+a[i]);
                sum1=1;
            }
            else{
                if(sum1+a[i]<0){
                    sum1+=a[i];
                    continue;
                }
                cst1+=abs(-1-(sum1+a[i]));
                sum1=-1;
            }
        }
        ans=min(ans,cst1);
    }
    {
        //負、正、負、、、
        ll cst2=0,sum2=0;
        rep(i,n){
            if(i%2==1){
                if(sum2+a[i]>0){
                    sum2+=a[i];
                    continue;
                }
                cst2+=1-(sum2+a[i]);
                sum2=1;
            }
            else{
                if(sum2+a[i]<0){
                    sum2+=a[i];
                    continue;
                }
                cst2+=abs(-1-(sum2+a[i]));
                sum2=-1;
            }
        }
        ans=min(ans,cst2);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4832
#include<stdio.h>
typedef struct{
  int value;
  char symbol;
}trump;


int main(){
  int N,i,j,min,judge=0;
  trump before[36],sorted[36],temp;
  char s[2];

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",s);
    before[i].symbol=s[0];
    before[i].value=s[1]-'0';
  }
  for(i=0;i<N;i++){
    sorted[i]=before[i];
  }  

  for(i=0;i<N;i++){
    for(j=N-1;j>=i+1;j--){
      if(before[j].value<before[j-1].value){
	temp=before[j];
	before[j]=before[j-1];
	before[j-1]=temp;
      }
    }
  }
  for(i=0;i<N-1;i++){
    printf("%c%d ",before[i].symbol,before[i].value);
  }
  printf("%c%d\n",before[i].symbol,before[i].value);
  printf("Stable\n");
  
  for(i=0;i<N;i++){
    min=i;
    for(j=i;j<N;j++){
      if(sorted[j].value<sorted[min].value){
	min=j;
     }
    }
    temp=sorted[i];
    sorted[i]=sorted[min];
    sorted[min]=temp;
  }
  
  for(i=0;i<N-1;i++){
    printf("%c%d ",sorted[i].symbol,sorted[i].value);
  }
  printf("%c%d\n",sorted[i].symbol,sorted[i].value);
  for(i=0;i<N;i++){
    if(before[i].symbol!=sorted[i].symbol){
      judge=1;
      break;
    }
    if(before[i].value!=sorted[i].value){
      judge=1;
      break;
    }
  }
  if(judge==0)printf("Stable\n");
    else printf("Not stable\n");

  return 0;
}
    
  
  



Measured memory_bytes: 2140
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

int main(){
    string s,t; cin >> s >> t;
    vector<string> ans;
    int nt=t.length();
    int n;
    if(nt>s.length()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for(int i=0;i<s.length();i++){
        n=0;
        for(int j=0;j<t.length();j++){
            //cerr << s[i+j] << " " << t[j] << endl;
            if(s[i+j]==t[j] || (s[i+j]=='?')) n++;
            else break;
        }
        if(n>=nt){
            string tmp="";
            for(int j=0;j<s.length();j++){
                if(j==i){
                    tmp += t;
                    j+=t.length()-1;
                }else if(s[j]=='?'){
                    tmp += "a";
                }else{
                    tmp += s[j];
                }
            }
            ans.push_back(tmp);
        }
        //cout << n << endl;
    }
    if(ans.size()==0){
        cout << "UNRESTORABLE" << endl;
    }else{
        sort(ans.begin(),ans.end());
        cout << ans[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def check(X):
    for i in range(len(X)):
        if X[i] % 2 != 0:
            return False
        X[i] /= 2
    return True

N = int(input())
A = list(map(int, input().split()))
ans = 0
while check(A):
    ans += 1
print(ans)

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007
colors = [0,0,0]
ans = 1
for i in range(N):
    ans = (ans * colors.count(A[i])) % mod
    for j in range(3):
        if colors[j] == A[i]:
            colors[j] += 1
            break
print(ans)

Measured memory_bytes: 52908
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

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

	int n;
	cin >> n;
	int yak = 0;
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i % 2 == 1)
		{
			for (int j = 1; j <= sqrt(i); j++)
			{
				if (i % j == 0)
					yak += 2;
			}
			if (yak == 8)
				ans++;
			yak = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// AUTHOR:: MOHAMAMD FAISAL

"use strict";

const main = (input) =>{
  
  const arr = input.trim().split("");
  const firstplace = arr[arr.length -1];
  
  if(firstplace == 3){
    console.log("bon");
  }
  else if(firstplace == 0 || firstplace == 1  || firstplace == 6 || firstplace == 8){
    console.log("pon");
  }
  else{
    console.log("hon");
  }
};
  
main(require("fs").readFileSync("/dev/stdin","utf8"));


Measured memory_bytes: 29540
#include"bits/stdc++.h"
using namespace std;
int f(int a)
{
	if(a/10000!=a%10)
		return 0;
	if(a/1000%10!=a%100/10)
		return 0;
	return 1;
}
int main()
{
	int a,b;
	int i,j;
	int s=0;
	scanf("%d %d",&a,&b);
	for(i=a;i<=b;i++)
		s+=f(i);
	printf("%d",s);
} 

Measured memory_bytes: 256
//@trueno
//The purpose of computation is insight, not numbers...
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll V[105],W[105],dp[105][100005];
int main()
{
	int N,weight;
	cin>>N>>weight;
	for(int i=1;i<=N;i++)
		cin>>W[i]>>V[i];
	for(int i=0;i<=N;i++)
		dp[i][0]=0;
	for(int i=0;i<=weight;i++)
		dp[0][i]=0;
	for(int i=1;i<=N;i++)
	{
		for(int w=0;w<=weight;w++)
		{
			if(W[i]>w) 
				dp[i][w]=dp[i-1][w];
			else dp[i][w]=(ll)max(dp[i-1][w],V[i]+dp[i-1][w-W[i]]);
		}
	}
	cout<<dp[N][weight];
	return 0;
}

Measured memory_bytes: 80128
#include <iostream>
using namespace std;
int main() {
  char x, y, commma;
  bool a[3] = {1, 0, 0};
  while(cin >> x >> commma >> y) {
	swap(a[x - 'A'], a[y - 'A']);
  }
  for(int i = 0; i < 3; ++i) {
	if(a[i]) {
	  cout << char((int)i + (char)'A') << endl;
	}
  }
  return 0;
}

Measured memory_bytes: 3004
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *A = map(int, read().split())

    K = list(map(int, f'{K:>040b}'))
    A2 = [list(map(int, f'{a:>040b}')) for a in A]
    B = [0] * 40
    for a in A2:
        for i, bit in enumerate(a):
            B[i] += bit
    for i in range(40):
        if B[i] == N - B[i]:
            B[i] = 2
        elif B[i] < N - B[i]:
            B[i] = 1
        else:
            B[i] = 0

    @lru_cache(maxsize=None)
    def rec(i, x, smaller):
        if i == 40:
            ans = 0
            for a in A:
                ans += x ^ a
            return ans
        elif smaller:
            if B[i] == 2:
                return rec(i + 1, (x << 1), True)
            else:
                return rec(i + 1, (x << 1) + B[i], True)
        else:
            if B[i] == 2:
                if K[i] == 0:
                    return rec(i + 1, (x << 1), False)
                else:
                    return rec(i + 1, (x << 1), True)
            elif K[i] == B[i]:
                return rec(i + 1, (x << 1) + K[i], False)
            elif K[i] < B[i]:
                return rec(i + 1, (x << 1) + K[i], False)
            else:
                return rec(i + 1, (x << 1) + B[i], True)

    print(rec(0, 0, False))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 64960
#include <bits/stdc++.h>
//#include <unordered_map>
#define M ((ll)1e12)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi acos(-1)
typedef long long ll;
using namespace std;

void solve()
{
    string s;
    cin>>s;int va;
    if(s=="SUN")
    va=7;
    else if(s=="MON")
    va=6;
    else if(s=="TUE")
    va=5;
    else if(s=="WED")
    va=4;
    else if(s=="THU")
    va=3;
    else if(s=="FRI")
    va=2;
    else if(s=="SAT")
    va=1;
    cout<<va<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*ll t;
    cin>>t;
    while(t--)*/
    solve();
    return 0;}

Measured memory_bytes: 256
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    S = [True if i == 'o' else False for i in input()]
    # debug(S, locals())

    for i, j in [(False, False), (False, True), (True, False), (True, True)]:
        pat = [i, j]
        for k in range(2, N):
            if pat[k - 1]:
                if S[k - 1]:
                    pat.append(pat[k - 2])
                else:
                    pat.append(not pat[k - 2])
            else:
                if S[k - 1]:
                    pat.append(not pat[k - 2])
                else:
                    pat.append(pat[k - 2])

        # debug(pat, locals())

        for k in range(N):
            if pat[k]:
                if S[k] != is_same(pat, k, N):
                    break
            else:
                if S[k] == is_same(pat, k, N):
                    break
        else:
            ans = ['S' if pat[k] else 'W' for k in range(N)]
            print(''.join(ans))
            return None

    print(-1)

def is_same(pat, i, N):
    return pat[(i - 1) % N] == pat[(i + 1) % N]

if __name__ == '__main__':
    solve()

Measured memory_bytes: 5772
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <tuple>
#include <set>
#include <map>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> a(N);
  for (auto& ai: a) scanf("%d", &ai);

  std::vector<int> b = a;
  std::sort(b.rbegin(), b.rend());

  for (auto ai: a) {
    if (b[0] == ai) {
      printf("%d\n", b[1]);
    } else {
      printf("%d\n", b[0]);
    }
  }
}


Measured memory_bytes: 3200
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

string s,rev;
int n,z1[500010],z2[500010];

inline void Z(int z[],string &x){
	int l=0,r=0;
    for(int i=1;i<n;i++)
    {
        if(i<=r) z[i]=min(z[i-l],r-i);
        while(i+z[i]<n&&x[z[i]]==x[i+z[i]]) z[i]++;
        if(i+z[i]>r)
        {
            l=i;
            r=i+z[i];
        }
    }
}

inline bool ok(int l,int r)
{
	int len=r-l+1;
	if(len==1) return true;
	if(l==0&&z1[1]>=len-1) return false;
	if(r==n-1&&z2[1]>=len-1) return false;
	for(int i=2;i*i<=len;i++){
		if(len%i==0){
			if(l==0&&z1[i]>=len-i) return false;
			if(r==n-1&&z2[i]>=len-i) return false;
			if(l==0&&z1[len/i]>=len-len/i) return false;
			if(r==n-1&&z2[len/i]>=len-len/i) return false;
		}
	}
	return true;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>s;n=s.size();
	for(int i=s.size()-1;i>=0;i--) rev+=s[i];
	Z(z1,s);
	Z(z2,rev);
	int cnt=0;
	for(int i=0;i<n;i++){
		if(s[i]!=s[0]) cnt++;
	}
	if(cnt==0){
		cout<<n<<endl<<1<<endl;
		return 0;
	}
	if(ok(0,n-1)){
		cout<<1<<endl<<1<<endl;
		return 0;
	}
	int tot=0;
	for(int i=0;i<n-1;i++){
		if(ok(0,i)&&ok(i+1,n-1)) tot++;
	}
	cout<<2<<endl<<tot<<endl;
	return 0;
}

Measured memory_bytes: 5660
import functools

nums = list(map(int, input().split()))
N = nums[0]
A = nums[1]
B = nums[2]
sums = 0
i = 1

while i <= N:
    sum = functools.reduce(lambda x, y: x + y, list(map(int, list(str(i)))))
    if A <= sum and sum <= B:
        sums += i
    i += 1
print(sums)

Measured memory_bytes: 3684
#include <cstdio>

using namespace std;

int main() {
  long long h;
  scanf("%lld", &h);
  long long ans = 0;
  for (int i = 0; h > 0; ++i) {
    ans += 1LL << i;
    h /= 2;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N,M;
  cin >> N >> M;
  if(N == 1 && M == 1){
    cout << 1 << endl;
  }else if(N == 1){
    cout << M-2 << endl;
  }else if(M == 1){
    cout << N-2 << endl;
  }else if(N == 2 || M == 2){
    cout << 0 << endl;
  }else{
    cout << (N-2)*(M-2) << endl;
  }
  
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll dp[105][100010]; //dp[N][V]
int w[105],v[105];

int main(){
  int N,W; cin >> N >> W;
  
  rep(i,N){
    cin >> w[i] >> v[i];
  }
  fill(dp[0],dp[105],INF);
  
  dp[0][0] = 0;
  
  rep(i,N){
    rep(j,100010){
      //w[i]を選べる時
      if(j - v[i] >= 0){
        chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);
      }
      //w[i]を選ばない時
      chmin(dp[i+1][j],dp[i][j]);
    }
  }
  
  int ans = 0;
  rep(j,100010){
    if(dp[N][j] <= W) ans = j;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 82304
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val n = readLong()

    val getNumDigits: (Long) -> Int = { num -> num.toString().length }
    var numDigits = getNumDigits(n) 
    var a = 1L
    while(a * a <= n) {
        if(n % a == 0L) {
            val b = n / a
            val tmp = listOf(getNumDigits(a), getNumDigits(b)).max()!!
            if(numDigits > tmp) {
                numDigits = tmp
            }
        }
        a++
    }
    println(numDigits)

    pw.flush()
}

/****** Decrared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j] % MOD)
        }
    }
    val rtn = v.map { it.toList() }.toList()
    return rtn 
}

fun gcd(a: Long, b: Long): Long = 
if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
if(b==0L) a else gcd(b, a % b)

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 35952
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
const int maxn = 4000;
char s[maxn], t[maxn], res[maxn];
int slen, tlen, rlen;
int dp[maxn][maxn];
int last[maxn][maxn];
int sel[maxn][maxn];
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> (s+1) >> (t+1);
	slen = strlen(s+1);
	tlen = strlen(t+1);
	for(int i = 1;i <= slen;++i){
		for(int j = 1, source = 0;j <= tlen;++j){
			if(s[i] == t[j]){
				sel[i][j] = true;
				last[i][j] = source;
				dp[i][j] = dp[i-1][source] + 1;
				if(dp[i-1][j] > dp[i-1][source])source = j;
			}
			else{
				if(dp[i-1][j] > dp[i-1][source])source = j; 
				dp[i][j] = dp[i-1][source], last[i][j] = source;
			}
		}
	}
	int l = tlen;
	for(int i = 1;i < tlen;++i)if(dp[slen][i] > dp[slen][l])l = i;
	for(int i = slen;i > 0 and l;--i){
		if(sel[i][l])res[rlen++] = t[l];
		l = last[i][l];
	}
	for(int i = rlen-1;i > -1;--i)cout << res[i];
	cout << '\n';
}

Measured memory_bytes: 143616
#include <stdio.h>

int main()
{
	int a, b;
	char op;
	while(1)
	{
		scanf("%d %c %d", &a, &op, &b);

		if(op == '?')
		{
			break;
		}

		switch(op)
		{
			case '+': printf("%d\n", a+b); break;
			case '-': printf("%d\n", a-b); break;
			case '*': printf("%d\n", a*b); break;
			case '/': printf("%d\n", a/b); break;
		}
	}
	return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
#include <math.h>


int main(void)
{
    float a;
    int b;
    scanf("%f %d", &a, &b);
    int j = ( a - 1 + ceil(17 - 2 * a / 2) );

    if(a >= 9 || b >= 9){
        printf(":(");
    }else if( (1 <= a && a <= 8) && (1 <= b && b <= 8) ){
        if(b <= j){
            printf("Yay!");
        }else{
            printf(":(");
        }
    }

    return 0;
}


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

int main()
{
    int k;
    cin >> k;
    if(k % 2 == 0 || k % 5 == 0){
        cout << -1 << endl;
        return 0;
    }
    if(k == 7 || k == 1){
        cout << 1 << endl;
        return 0;
    }
    int ans = 1;
    int x = 7;
    while(x){
        x = (x * 10 + 7) % k;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> a, s;
int main() {
  cin >> n;
  read_n(a, n);
  s.resize(n + 1);
  for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + a[i - 1];
  i64 t = s[n];
  i64 ans = 1ll << 60;
  for (int i = 0; i <= n; ++i) {
    ans = min(ans, abs(s[i] - (t - s[i])));
  }
  cout << ans << endl;
  return 0;
}

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

long long N, M, l, r, d, a[100101], i, j, c[100101];
vector<pair<long long, long long>> D[100101]; 

int main(){
    scanf("%lld%lld", &N, &M);
    fill(a, a + N, -1);
    for(i = 0; i < M; ++i){
        scanf("%lld%lld%lld", &l, &r, &d);
        D[l - 1].push_back({r - 1, d});
        D[r - 1].push_back({l - 1, -d});
    }
    for(i = 0; i < N; ++i){
        if(a[i] >= 0)continue;
        a[i] = 1000000000000LL;
        stack<long long> s;
        s.push(i);
        while(!s.empty()){
            j = s.top();
            s.pop();
            for(auto k : D[j]){
            	if(a[k.first] >= 0){
                    if(a[k.first] != a[j] + k.second)return 0 & puts("No");
                    else continue;
                }else{
                    a[k.first] = a[j] + k.second;
                    s.push(k.first);
                }
            }
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 13952
#include <atcoder/maxflow>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> G(N);
  for (int i = 0; i != N; ++i) {
    cin >> G[i];
  }

  int s = N * M, t = s + 1;
  atcoder::mf_graph<int> f(N * M + 2);
  for (int i = 0; i != N; ++i) {
    for (int j = 0; j != M; ++j) {
      if (G[i][j] == '#') continue;
      if ((i+j)%2)
        f.add_edge(i * M + j, t, 1);
      else
        f.add_edge(s, i * M + j, 1);
    }
  }

  for (int i = 0; i != N; ++i) {
    for (int j = 0; j != M; ++j) {
      if ((i+j)%2 || G[i][j] == '#') continue;
      int k = i * M + j;
      if (j && G[i][j-1] != '#') f.add_edge(k, k - 1, 1);
      if (j < M - 1 && G[i][j+1] != '#') f.add_edge(k, k + 1, 1);
      if (i && G[i-1][j] != '#') f.add_edge(k, k - M, 1);
      if (i < N - 1 && G[i+1][j] != '#') f.add_edge(k, k + M, 1);
    }
  }

  cout << f.flow(s,t) << endl;

  for (auto edge : f.edges()) {
    if (edge.from == s || edge.to == t || !edge.flow) continue;
    if (edge.to - edge.from == M) {
      G[edge.from/M][edge.from%M] = 'v';
      G[edge.to/M][edge.to%M] = '^';
    } else if (edge.to - edge.from == -M) {
      G[edge.to/M][edge.to%M] = 'v';
      G[edge.from/M][edge.from%M] = '^';
    } else if (edge.to - edge.from == 1) {
      G[edge.from/M][edge.from%M] = '>';
      G[edge.to/M][edge.to%M] = '<';
    } else {
      G[edge.to/M][edge.to%M] = '>';
      G[edge.from/M][edge.from%M] = '<';
    }
  }

  for (int i = 0; i != N; ++i) {
    cout << G[i] << endl;
  }
}


Measured memory_bytes: 5484
#include<bits/stdc++.h>
using namespace std;
int main()
{
      long long int h,w=0,i,j,n,l=0;
      cin>>n;
      int a[n];
      for(i=0;i<n;i++)
      {
          cin>>a[i];
      }
      h = -1;

          for(j=0;j<n-1;j++)
          {
            if(a[j]>=a[j+1])
            {
               w++;
            }
            else
            {
              if(h<w)
              {
                  h = w;
              }
              w = 0;
            }
          }
          if(h<w)
          {
              h = w;
          }
       cout<<h<<endl;


      return 0;
      }


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  int64 k;
  scanf("%d%lld",&n,&k);
  int64 *cnt=(int64 *)calloc(100000+1,sizeof(int64));
  int i;
  for(i=0;i<n;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    cnt[a]+=b;
  }
  int64 c=0;
  for(i=0;c<k;i++){
    c+=cnt[i];
  }
  printf("%d\n",i-1);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 896
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}




signed main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)
        cin >> s[i];


    int ans = MOD;
    for(int i = 0; i < (1 << (h - 1)); ++i){
        int cnt = 0;
        vector<int> group(h);
        for(int j = 0; j < h; ++j){
            group[j] = cnt;
            if(i & (1 << j)){
                // 切る
                ++cnt;
            }
        }
        vector<vector<int>> v(cnt + 1, vector<int>(w, 0));
        for(int j = 0; j < h; ++j)
            for(int p = 0; p < w; ++p)
                if(s[j][p] == '1')
                    ++v[group[j]][p];

        int val = cnt;
        vector<int> g(cnt + 1, 0);
        bool ret = false;
        for(int p = 0; p < w; ++p){
            bool cut = false;
            for(int j = 0; j <= cnt; ++j){
                if(g[j] + v[j][p] > k)
                    cut = true;
            }
            if(cut){
                ++val;
                g.assign(cnt + 1, 0);
            }
            for(int j = 0; j <= cnt; ++j)
                g[j] += v[j][p];
            for(int j = 0; j <= cnt; ++j){
                if(v[j][p] > k){
                    ret = true;
                    break;
                }
            }
            if(ret)
                break;
        }
        if(!ret)
            chmin(ans, val);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
   vector<int> dp(n, INT_MAX);
   dp[0] = 0;
 dp[1] = abs(h[1] - h[0]);
       for(int i = 2; i < n; i++)
     {
      for(int j = i - 1, jump = 0; j  >= 0 && jump < k; j--, jump++)
      {
        dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
      }
    }
   cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int k;
    int n;
    cin >> k;
    if(k==1){
        cout << 1 << endl;
        cout << 1 << endl;
        return 0;
    }
    n = (k/4+1)*2;
    if(n>500){
        n=500;
    }
    vector<vector<int> > v(n,vector<int>(n));
    int p=1;
    rep(i,n){
        int t = i;
        rep(j,n){
            if(n-i+p-1!=k){
                if(j%2==0)v[j][t] = p;
                else v[j][t] = p+1;
            }else{
                v[j][t]= p;
            }
            t = (t+n-1)%n;
        }
        if(n-i+p-1==k){
            p+=1;
        }else{
            p+=2;
        }
    }
    cout << n << endl;
        rep(i,n){
            rep(j,n){
               cout << v[i][j] << " "; 
            }
            cout << endl;
        }
    return 0;
}

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

const int INF = 2e9;
const int NMAX = 100, P = 2, DAYS = 5;

int n;
int f[NMAX + 2][DAYS + 2][P + 2];
int p[NMAX + 2][P * DAYS + 2];

int ans;
int sh[DAYS + 2][P + 2], profit[NMAX + 2];


void backt(int d, int per)
{
    if(d > DAYS)
    {
        memset(profit, 0, sizeof profit);

        bool open = false;
        for(int i = 1; i <= DAYS; i++)
        for(int c = 1; c <= n; c++)
        {
            if(sh[i][1])
            {
                open = true;
                if(f[c][i][1])
                    profit[c]++;
            }

            if(sh[i][2])
            {
                open = true;
                if(f[c][i][2])
                    profit[c]++;
            }
        }

        int pr = 0;
        for(int c = 1; c <= n; c++)
            pr += p[c][profit[c]];

        if(open)
            ans = max(pr, ans);

        return;
    }

    sh[d][per] = 0;
    if(per == 2) backt(d + 1, 1);
    else backt(d, 2);

    sh[d][per] = 1;
    if(per == 2) backt(d + 1, 1);
    else backt(d, 2);
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    for(int j = 1; j <= DAYS; j++)
    for(int k = 1; k <= P; k++)
        cin >> f[i][j][k];

    for(int i = 1; i <= n; i++)
    for(int j = 0; j <= P * DAYS; j++)
        cin >> p[i][j];

    ans = -INF;
    backt(1,1);

    cout << ans << '\n';

    return 0;
}

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

int main(){
  int N,K;
  cin>>N>>K;
  int P[N];
  for(int i=0;i<N;i++){
    cin>>P[i];
  }
  sort(P,P+N);
  int ans=0;
  for(int i=0;i<K;i++){
    ans=ans+P[i];
  }
  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <set>
using namespace std;
int mixInt(int number, int number2){
  string s;
  stringstream s1, s2;
  s1 << number; 
  s2 << number2; 
  s = s1.str() + s2.str();
  return atoi(s.c_str());
} 

int main() { 
  int i, n, x, k=0, b[4], c[12];
  set<int> a;  
  set<int>::iterator p;  
  cin >> n; 
  for(i=0; i<n; i++) {  
    cin >> x; 
    a.insert(x); 
  } 
  p=a.begin();
  if(n<4) for(i=0; i<n; i++) p++; 
  else for(i=0; i<4; i++) p++; 
  i=0; 
  for(set<int>::iterator it=a.begin(); it!=p; it++) { 
    b[i] = *it; 
    i++; 
  }  
  if(n<4){  
    sort(b, b+n); 
    for(int i=0; i<n; i++){  
      for(int j=0; j<n; j++) { 
	if(i!=j) {  
	  c[k]=mixInt(b[i],b[j]);  
	  k++; 
	}   
      }  
    } 
  } else { 
    sort(b, b+4); 
    for(int i=0; i<4; i++){   
      for(int j=0; j<4; j++) {  
	if(i!=j) {   
	  c[k]=mixInt(b[i],b[j]); 
	  k++;
	} 
      } 
    } 
  }  
  if(n<4) sort(c, c+3); 
  else sort(c, c+12); 
  cout << c[2] << endl; 
  return 0;
}


Measured memory_bytes: 1604
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var D = int.Parse(Console.ReadLine());
		if (D == 25) {
			Console.WriteLine("Christmas");
		} else if (D == 24) {
			Console.WriteLine("Christmas Eve");
		} else if (D == 23) {
			Console.WriteLine("Christmas Eve Eve");
		} else {
			Console.WriteLine("Christmas Eve Eve Eve");
		}
	}
}


Measured memory_bytes: 11092
first = 1
second = 1
n=int(input())
x = []
for i in range(0,n):
    s = int(input())
    if first <= s:
        second = first
        first = s
    elif second <= s:
        second = s
    x.append(s)

for i in range(0,n):
    if x[i] == first:
        print(second)
    else:
        print(first)
    
    


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

using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin >> n ;
    ll arr[n];
    ll x=0 , y , y2;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> arr[i];
        if(i)
        {
            if(arr[i]<arr[i-1])
            {
                x+=arr[i-1]-arr[i];
                arr[i]=arr[i-1];
            }
        }
    }
    cout << x ;
    return 0;
}


Measured memory_bytes: 5084
{-# LANGUAGE FlexibleContexts #-}

module Main where

import Debug.Trace
import Data.List
import qualified Data.Set as Set
import qualified Data.Sequence as Seq
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
-- import Data.Array.IO
import Data.Maybe
import qualified Data.Map as M
-- import Control.Monad.ST
-- import Data.STRef
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf

queen = 'Q'
space = '.'

solve :: Int -> [[Int]] -> Array (Int, Int) Char
solve n lst = toArray $ if n >= 8 then queens else concat $ map (search queens squares) squares where
    search qs ss s
        | length qs >= 7 = (s:qs)
        | otherwise = concat $ map (search (s:qs) next) next where
                    next = filter (acceptable s) ss

    queens = toTupple lst
    squares = iter [(x, y) | x <- [0..7], y <- [0..7]] queens where
        iter ac [] = ac
        iter ac (q:qs) = iter (filter (acceptable q) ac) qs  
    toArray qs = accumArray (\x y-> y) space ((0,0),(7,7)) [(location, queen)| location <- qs]   
    acceptable (r, c) (rq, cq)
        | rq == r || cq == c = False
        | rq + c == cq + r   = False
        | rq + cq == r + c   = False
        | otherwise = True
    toTupple [] = []
    toTupple ([r, c]:xs) = (r, c):toTupple xs

readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

readIntList:: IO [Int]
readIntList = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

print' :: Array (Int, Int) Char -> IO ()
print' ar = mapM_ printRow [0..7] where
    printRow r = do
        mapM_ printSquare [0..7]
        putStrLn "" where
            printSquare c = putStr $ [ar!(r,c)]

main :: IO() 
main = do
    n  <- readIntLn
    l <- replicateM n readIntList
    print' $ solve n l



Measured memory_bytes: 4896
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N,M = LMIIS()
    S = list()
    P = list()
    counts = [-1]*N
    for i in range(M):
        p,s = input().split()
        p = int(p)-1

        if s == 'AC' and counts[p] < 0:
            counts[p] *= -1
        else:
            if counts[p] < 0:
                counts[p] -= 1
    numac = 0
    nump = 0
    for c in counts:
        if c >= 0:
            numac += 1
            nump += c-1
    print(numac,nump)





if __name__ == '__main__':
    main()

Measured memory_bytes: 41836
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

int main(){
  int n,m;
  cin >> n >> m;
  int a[m],b[m];
  int ans=0;
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--,b[i]--;
  }
  UnionFind uf[m](n);
  rep(i,m){
    rep(j,m){
      if(j!=i)uf[i].unite(a[j],b[j]);
    }
    if(uf[i].size(0)!=n)ans++;
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256