akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;


ull gcd(ull a,ull b){
	if(!b) return a;
	return gcd(b,a%b);
}


int main(){
	int n,cnt = 0;
	cin >> n;
	ll a[n];
	
	rep(i,0,n){
		cin >> a[i];
		if(a[i] % 2){
			cnt++;
		}
	}
	
	if(cnt % 2 == 0){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
  int n;cin>>n;
  vector<int> a1(n),a2(n);
  rep(i,n){
    cin>>a1[i];
  }
  rep(i,n){
    cin>>a2[i];
  }
  vector<int> b1(n),b2(n);
  b1[0]=a1[0];
  b2[n-1]=a2[n-1];
  rep(i,n-1){
    b1[i+1]=b1[i]+a1[i+1];
    b2[n-2-i]=b2[n-1-i]+a2[n-2-i];
  }
  ll ans=0;
  rep(i,n){
    ans=max(ans,ll(b1[i]+b2[i]));
  }
  cout<<ans<<endl;

  return 0;
}

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

using namespace std;

int main(){
    string S, T;
    cin >> S >> T;
    set<int> replace;
    for (char c = 'a'; c <= 'z' ; ++c) {
        replace.clear();
        for (int i = 0; i < S.size(); ++i) {
            if(c == S.at(i)){
                replace.emplace(T.at(i));
            }
        }
        if(1 < replace.size()){
            cout << "No" << endl;
            return 0;
        }
        replace.clear();
        for (int i = 0; i < T.size(); ++i) {
            if(c == T.at(i)){
                replace.emplace(S.at(i));
            }
        }
        if(1 < replace.size()){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 904
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = (int)1e5 + 10;

int n, w, dp[N];
bool git[N];

signed main() {
  init_ios();
  cin >> n >> w;
  git[0] = true;
  for (int _ = 1; _ <= n; ++_) {
    int x, y;
    cin >> x >> y;
    for (int i = w; i >= x; --i) {
      if (git[i-x]) {
        git[i] = true;
        dp[i] = max(dp[i], y+dp[i-x]);
      }
    }
  }
  int res = dp[1];
  for (int i = 1; i <= w; ++i)
    res = max(res, dp[i]);
  cout<<res<<"\n";
}

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

int main()
{
	int p1[2], p2[2];
	cin >> p1[0] >> p1[1] >> p2[0] >> p2[1];

	int xDiff = p2[0] - p1[0];
	int yDiff = p2[1] - p1[1];

	cout << p2[0] - yDiff << " " << p2[1] + xDiff << " " << p1[0] - yDiff << " " << p1[1] + xDiff << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<complex>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int n,m,out;
vi test,co;
int in[10][10]={0};
void f(int a){
  //rep(i,10){rep(j,10)cout<<" "<<in[i][j];cout<<endl;}cout<<endl;
  if(a==0){
    vi tes(n);
    rep(i,n)tes[i]=i;
    rep(i,8){
      rep(j,n)if(in[i][j]){
	swap(tes[j],tes[j+1]);
      }
    }
    //    rep(i,10){rep(j,10)cout<<" "<<in[i][j];cout<<endl;}cout<<endl;
    bool h=true;
    rep(i,n)if(tes[i]!=test[i])h=false;
    if(h){
      int ma=0;
      rep(i,8)rep(j,n)if(in[i][j])ma=max(ma,i);
      out=min(out,ma);
    }    
  }else{
    rep(i,n-1)if(co[i]){
      co[i]--;
      rep(j,8){
	if(in[j][i])continue;
	if(i&&in[j][i-1])continue;
	in[j][i]=true;
	f(a-1);
	in[j][i]=false;
      }
      co[i]++;
      break;
    }    
  }  
}
int main(){
  out=inf;
  cin>>n>>m;
  test=co=vi(n,0);
  rep(i,n)test[i]=i;
  rep(i,m){
    int a;cin>>a;a--;
    swap(test[a],test[a+1]);
    co[a]++;
  }
  f(m);
  cout<<out+1<<endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong N;
  vector<llong> a;

  cin >> N;
  a.resize(N);
  for (auto &in: a) {
    cin >> in;
  }

  llong ans = 0;
  for (int i = 0; i < N; i += 2) {
    ans += a[i] % 2 == 1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

long long int nCk(int n, int k){
    long long int bunbo = 1, bunsi = 1;
    while(k>0){
        bunbo *= k;
        bunsi *= n;
        k -= 1;
        n -= 1; 
    }
    return bunsi/bunbo;
}

int main() {

    int i,j;
    int n,k;
    int d,ai,cnt=0;
    int* snuke;

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

    snuke = (int*)calloc(n, sizeof(int));
    for(i=0;i<k;i++){
        scanf("%d", &d);
        for(j=0;j<d;j++){
            scanf("%d", &ai);
            snuke[ai-1]++;
        }
    }

    for(i=0;i<n;i++){
        if(snuke[i] == 0) cnt++;
    }
    printf("%d", cnt);
    return 0;
}

Measured memory_bytes: 1732
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

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

void d_err() {
    cerr << endl;
}

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

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

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

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

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, X;
    cin >> N >> X;

    vi x(N);
    REP(i, N) cin >> x[i];

    x.pb(X);
    sort(ALL(x));

    ll ans = x[1] - x[0];
    FOR(i, 1, N) {
        ans = gcd(ans, x[i+1] - x[i]);
    }

    cout << ans << endl;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	for (char &c : s) {
		cout << char((c - 'A' + n) % 26 + 'A');
	}
	cout << '\n';
	return 0;
}


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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

/**
 *  最長増加部分列(LIS)を取得する
 *  @origin:     元の数列
 *  @continuous: 真の場合、以下の式を満たす最長増加部分列を取る
 *               LIS_{i} = LIS_{i + 1} - 1, where 1 <= i < n(LIS)
 *  @Return:     最長増加部分列
 *
 *  計算量: O(N) if continuous else O(NlogN)
 */
template<typename T>
std::vector<T> pick_up_LIS(const std::vector<T>& origin,
                           const bool&           continuous) {
    if(origin.size() == 0) return std::vector<T>();
    std::vector<T> lis;
    if(continuous) {
        auto max_val = *std::max_element(origin.begin(), origin.end());
        auto min_val = *std::min_element(origin.begin(), origin.end());
        auto range   = max_val - min_val + 1;
        auto offset  = min_val - 1;
        std::vector<T> dp(range + 1, 0);
        for(const auto& v : origin) {
            T p   = v - offset;
            dp[p] = dp[p - 1] + 1;
        }
        auto itr = std::max_element(dp.begin(), dp.end());
        auto r   = std::distance(dp.begin(), itr) + offset;
        lis.reserve(*itr);
        for(T i = *itr - 1; i >= 0; i--) {
            lis.push_back(r - i);
        }
    }
    else {
        std::vector<T> dp(origin.size() + 1, std::numeric_limits<T>::max());
        dp[0] = std::numeric_limits<T>::min();
        for(const auto& v : origin) {
            auto itr   = std::lower_bound(dp.begin(), dp.end(), v);
            auto index = std::distance(dp.begin(), itr);
            dp[index]  = (v < dp[index]) ? v : dp[index];
        }
        auto itr = std::lower_bound(dp.begin(), dp.end(), std::numeric_limits<T>::max());
        lis.reserve(std::distance(dp.begin() + 1, itr));
        std::copy(dp.begin() + 1, itr, std::back_inserter(lis));
    }
    return lis;
}

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

    int N;
    std::cin >> N;

    vector<int> P(N);
    REP(i, N) {
        std::cin >> P[i];
    }

    auto lis = pick_up_LIS(P, true);
    std::cout << N - lis.size() << std::endl;

    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include<string.h>
int main(void){
    
    char str[1000];
    char str1[1000];
    int count = 0;
    scanf("%s",str);

    for(int i=0;i<strlen(str);i++){
        
        if(str[i] == '0'){
            str1[count] = '0';
            count++;
            str1[count] = 'a';
        }else if(str[i] == '1'){
            str1[count] = '1';
            count++;
            str1[count] = 'a';
        }else if(str[i] == 'B'){
            count--;
            if(count>=0){
                    str1[count] = 'a';
            }else{
                count++;
                str1[count] = 'a';
            }
            
            
        }
    }

    for(int i=0;;i++){
      if(str1[i]!= 'a'){
        printf("%c",str1[i]);
      } else{
          break;
      }
    }
    printf("\n");

    


    return 0;
}

Measured memory_bytes: 1612
#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++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

bool lis[1000001];
vector<ll> p;
map<ll, int> mp;

int main(){
  ll n;
  cin >> n;
  rep(i, 1000001) lis[i] = false;
  for(int i = 2; i < 1000000; i++){
    if(lis[i]) continue;
    for(int j = 2; i * j < 1000000; j++){
      lis[i * j] = true;
    }
  }
  ll ans = 0;
  for(int i = 2; i < 1000000; i++){
    if(lis[i]) continue;
    while(1){
      if(n % i != 0) break;
      mp[i]++;
      n = n / i;
    }
  }
  if(n != 1) mp[n]++;
  for(pair<ll, int> x : mp){
    for(int i = 1; x.second - i >= 0; i++){
      ans++;
      x.second -= i;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 4584
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

 
int N;
int X[1011], Y[1011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d%d", X+i, Y+i);

    int odd = 0;
    REP (i, N) {
	if ((abs(X[i]) + abs(Y[i])) & 1) odd++;
    }

    if (0 < odd && odd < N) {
	puts("-1");
	return;
    } else {
	VI D;
	if (odd == 0) D.push_back(1);
	for (int t=30; t>=0; t--) D.push_back(1<<t);
	printf("%d\n", (int)D.size());
	rprintf("%d", D.begin(), D.end());

	REP (i, N) {
	    int x = X[i], y = Y[i];
	    string s;
	    if (odd == 0) {
		s.push_back('R');
		x--;
	    }
	    for (int t=30; t>=0; t--) {
		if (x <= y) {
		    if (x <= -y) {
			x += 1<<t;
			s.push_back('L');
		    } else {
			y -= 1<<t;
			s.push_back('U');
		    }
		} else {
		    if (x <= -y) {
			y += 1<<t;
			s.push_back('D');
		    } else {
			x -= 1<<t;
			s.push_back('R');
		    }
		}
	    }
	    eprintf("%d %d\n", x, y);
	    puts(s.c_str());
	}
    }


}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vvint a(n,vint(n,0));
    vvint d(n,vint(n,0));
    REP(i,n) {
        REP(j,n){
             cin >> a[i][j];
             d[i][j] = a[i][j];
        }
    }
    REP(k,n){
        REP(i,n){
            REP(j,n){
                if(a[i][j]>a[i][k]+a[k][j]){
                    puts("-1");
                    return 0;
                }
                if(k!=i&&k!=j&&a[i][j]==a[i][k]+a[k][j]){
                    d[i][j]=0;
                }
            }
        }
    }
    ll ans = 0;
    REP(i,n){
        REP(j,n){
            ans+=(ll)d[i][j];
        }
    }
    ans/=2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef pair<bool, int> pii;
void solve();

int H,W,N;
int dx[] = {0,1},dy[] = {1,0};
pii field[1010][1010];

int main()
{
    while(scanf("%d%d%d",&H,&W,&N),H + W + N)
    {
        for(int i = 0; i < H; i++)
        {
            for(int j = 0; j < W; j++)
            {
                scanf("%d",&field[i][j].first);
                field[i][j].second = 0;
            }
        }
        solve();
    }
    return 0;
}

void solve()
{
    field[0][0].second = N - 1;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            field[i + 1][j].second += field[i][j].second / 2 + (!field[i][j].first && field[i][j].second % 2 == 1);
            field[i][j + 1].second += field[i][j].second / 2 + (field[i][j].first && field[i][j].second % 2 == 1);
            if(field[i][j].second % 2 == 1)field[i][j].first = !field[i][j].first;
        }
    }
    int x = 0,y = 0;
    while(x < W && y < H)
    {
        if(field[y][x].first == 1)x++;
        else y++;
    }
    printf("%d %d\n",y + 1,x + 1);
}

Measured memory_bytes: 11156
# yahoo-procon2019-qualB - Path
from collections import Counter
from itertools import chain


def main():
    P = [list(map(int, input().rstrip().split())) for _ in range(3)]
    C = Counter(chain.from_iterable(P)).most_common()
    c = [i[1] for i in C]
    print("YES" if c == [2, 2, 1, 1] else "NO")


if __name__ == "__main__":
    main()

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

int dx[] = {1,0,0,-1};
int dy[] = {0,1,-1,0};
int n;
vector<vector<bool>> is(550,vector<bool>(550,1));
void cha(int y,int x,vector<vector<ll>> &v,int k,ll &c){
  rep(j,4){
    int ny = y+dy[j];
    int nx = x+dx[j];
    if(ny < 0 || ny >= n || nx < 0 || nx >= n)continue;
    if(v[ny][nx] > c+k){
      v[ny][nx] = c+k;
      cha(ny,nx,v,k+is[ny][nx],c);
    }
  }
}

int main(){

  cin >> n;
  //vector<string> v(n,string(n,'0'));
  vector<vector<ll>> v(n,vector<ll>(n,0));
  rep(i,n)rep(j,n)v[i][j] += min({i,j,n-i-1,n-j-1});
  int suu = n*n;
  ll res = 0;
  rep(i,suu){
    int p;scanf("%d",&p);
    int y = p/n,x = p%n-1;
    if((p%n) == 0)y--,x += n;
    res += v[y][x];
    is[y][x] = false;
    cha(y,x,v,0,v[y][x]);
  }
  cout << res << endl;
  




  return 0;
}

Measured memory_bytes: 28952
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX=200000;
int main(int argc, const char * argv[]) {
    int n;
    int R[MAX];
    cin >>n;
    for (int i=0; i<n; i++) {
        cin >> R[i];
    }
    int maxv= -2000000000;
    int minv=R[0];
    for (int i=1; i<n; i++) {
        maxv = max(maxv, R[i]-minv);
        minv = min(minv, R[i]);
    }
    cout<<maxv<<endl;
    
    return 0;
}



Measured memory_bytes: 3868
package main

import (
	"fmt"
	"sort"
	"strconv"
	"strings"
)

type dpFact struct {
	digit, from, num int
}

func main() {
	match := [...]int{0, 2, 5, 5, 4, 5, 6, 3, 7, 6}
	var N, M int
	fmt.Scan(&N, &M)

	A := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&A[i])
	}
	sort.Ints(A)

	DP := make([]dpFact, N+1)
	for i := 1; i <= N; i++ {
		DP[i].digit, DP[i].from, DP[i].num = -1, -1, -1
	}

	for i := 0; i <= N; i++ {
		for _, a := range A {
			if index := i - match[a]; index >= 0 && DP[index].digit >= 0 {
				if DP[index].digit+1 >= DP[i].digit {
					DP[i].digit = DP[index].digit + 1
					DP[i].from = index
					DP[i].num = a
				}
			}
		}
	}

	ansList := [10]int{}
	t := N
	for t > 0 {
		ansList[DP[t].num]++
		t = DP[t].from
	}

	ans := ""
	for i := 9; i > 0; i-- {
		if ansList[i] > 0 {
			ans = ans + strings.Repeat(strconv.Itoa(i), ansList[i])
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2088
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	k, _ := strconv.Atoi(Scanner())
	d := 1000000007
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(Scanner())
	}
	fact := make([]int, n+1)
	inv := make([]int, n+1)
	fact[0], inv[0] = 1, modinv(1, d)
	for i := 1; i <= n; i++ {
		fact[i] = fact[i-1] * i % d
		inv[i] = modinv(fact[i], d)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	ans := 0
	for i := 0; i < n; i++ {
		ans += a[i] * combination(n-i-1, k-1, d, fact, inv) % d
		ans -= a[i] * combination(i, k-1, d, fact, inv) % d
		ans %= d
	}
	fmt.Println(ans)
}
func combination(x int, y int, d int, fact []int, inv []int) int {
	if x < y {
		return 0
	} else {
		return fact[x] * inv[x-y] % d * inv[y] % d
	}
}

func modinv(a, m int) int {
	b, u, v := m, 1, 0
	for {
		t := a / b
		a -= t * b
		u -= t * v
		a, b, u, v = b, a, v, u
		if b == 0 {
			break
		}
	}
	u %= m
	if u < 0 {
		u += m
	}
	return u
}


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

#define mp(x, y) make_pair((x), (y))

typedef long long ll;

int n, m;
int a[333][333];
int cur[333];
int cnt[333];
int curmaxcnt, curmaxid;
int del[333];

int comp() {
	for(int i=0; i<m; i++) cnt[i]=0;
	for(int i=0; i<n; i++) cnt[a[i][cur[i]]]++;
	curmaxcnt=0;
	for(int i=0; i<m; i++) {
		if(cnt[i]>curmaxcnt) {
			curmaxcnt=cnt[i];
			curmaxid=i;
		}
	}

}

int ok(int x) {
	for(int i=0; i<n; i++) cur[i]=0;
	for(int i=0; i<m; i++) del[i]=0;
	comp();
	while(curmaxcnt>x) {
		del[curmaxid]=1;
		for(int i=0; i<n; i++) {
			while(cur[i]<m && del[a[i][cur[i]]]) cur[i]++;
			if(cur[i]>=m) return 0;
		}
		comp();
	}
	return 1;
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i=0; i<n; i++) {
		for(int j=0; j<m; j++) {
			scanf("%d", &a[i][j]);
			a[i][j]--;
		}
	}
	int l=1, r=n;
	while(l<r) {
		int mi=(l+r)/2;
		if(ok(mi)) r=mi;
		else l=mi+1;
	}
	printf("%d\n", l);

	return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(H: int):
    ans = 2 ** f(H) - 1
    print(ans if H > 1 else 1)
    return


def f(H, dep=1):
    half_h = H // 2
    dep += 1
    return f(half_h, dep) if half_h > 1 else dep


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    solve(H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;


int main(){

    int N; cin >> N;
    vector<int> L(N);
    rep(i,N) {
        cin >> L[i];
        /*
        int l; cin >> l;
        bool isOK = true;
        rep(j,L.size()){
            if (l == L[j]){
                isOK = false;
            }
        }
        if(isOK) L.push_back(l);
        */
    }
    
    int ans = 0;
    //N = L.size();
    /*
    rep(i,N){
        cout << L[i] << endl;
    }
    */
    
    for(int i = 0; i < N; i++){
        for (int j = i+1; j < N; j++){
            if (L[i] == L[j]) continue;
            for (int k = j+1; k < N; k++){
                if (L[i] == L[k] || L[j] == L[k]) continue;
                //cout <<  i+1 << " " << j+1 << " " << k+1 << endl;
                if (L[i]+L[j] > L[k] && L[j]+L[k]>L[i]&&L[k]+L[i]>L[j]) ans++;
                //cout << L[i] << " " << L[j] << " " << L[k] << endl;
            }
        }
    }

    cout << ans << endl;

}

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

const ll p = 1e9+7;

ll n, a[605], dp[305][305][305], used[605], junk[605], big[605], iv[605], dp2[305][305];

ll exp(ll x, ll k) {
	if (k == 0)
		return 1;
	if (k%2 == 1)
		return x*exp(x, k-1)%p;
	ll y = exp(x, k/2);
	return y*y%p;
}

ll inv(ll x) {
	return exp(x, p-2);
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= 2*n; ++i)
		iv[i] = inv(i);
	for (int i = 0; i < 2*n; ++i)
		cin >> a[i];
	int e1 = 0, e2 = 0;
	for (int i = 0; i < 2*n; i += 2) {
		if (a[i] != -1 && a[i+1] != -1)
			junk[a[i]] = junk[a[i+1]] = 1;
		else if (a[i] != -1 || a[i+1] != -1) {
			e1++;
			used[a[i]+a[i+1]+1] = 1;
		} else
			e2++;
	}
	dp[e1][e2][0] = 1;
	for (int i = 2*n; i >= 1; --i)
		big[i] = big[i+1]+used[i];
	int s = e1+2*e2;
	for (int i = 1; i <= 2*n; ++i) {
		if (junk[i])
			continue;
		if (used[i]) {
			memset(dp2, 0, sizeof(dp2));
			for (int j = 0; j <= big[i]; ++j)
				for (int k = 0; 2*k+j <= s; ++k) {
					int l = s-2*k-j;
					if (j > 0)
						dp2[j-1][k] = (dp2[j-1][k] + j*iv[big[i]]%p*dp[j][k][l])%p;
					dp2[j][k] = (dp2[j][k]+(big[i]-j)*iv[big[i]]%p*dp[j][k][l])%p;
				}
			for (int j = 0; j <= n; ++j)
				for (int k = 0; 2*k+j <= s; ++k)
					dp[j][k][s-2*k-j] = dp2[j][k];				
		} else {
			for (int j = 0; j <= big[i]; ++j)
				for (int k = 0; 2*k+j <= s; ++k) {
					int l = s-2*k-j;
					if (j > 0)
						dp[j-1][k][l] = (dp[j-1][k][l] + j*dp[j][k][l])%p;
					if (k > 0)
						dp[j][k-1][l+1] = (dp[j][k-1][l+1] + k*dp[j][k][l])%p;
					if (l > 0)
						dp[j][k][l-1] = (dp[j][k][l-1] + dp[j][k][l])%p;
				}
			s--;		
		}
	}
	cout << dp[0][0][0] << endl;
}

Measured memory_bytes: 219392
#include<stdio.h>
int main(void){
int i,j,h,w;
while(1){
scanf("%d %d",&h,&w);
if(h==0&&w==0) break;
for(i=1;i<=h;i++){
	for(j=1;j<=w;j++){
		putchar('#');
	}
		putchar('\n');
}
putchar('\n');
}
return(0);
}



Measured memory_bytes: 2140
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
void solve(){
    int n;
    cin >> n;
    cout << (n - 1) / 2 + 1; 
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int Q;

int main(){
    cin >> Q;
    priority_queue<ll, vector<ll>, greater<ll> > large;
    priority_queue<ll> small;
    ll constant = 0, lsum=0, ssum=0;
    for(int i=0; i<Q; i++){
        int t;
        ll a, b;
        cin >> t;
        if(t==1){
            cin >> a >> b;
            constant += b;
            if(large.size() >= small.size()){
                small.push(a);
                ssum += a;
            } else {
                large.push(a);
                lsum += a;
            }

            if(large.size()==0) continue;
            ll l = large.top();
            ll s = small.top();
            if(l < s){
                large.pop();
                small.pop();
                large.push(s);
                small.push(l);
                lsum += s-l;
                ssum += l-s;
            }
        } else {
            ll s = small.top();
            // cout << s*small.size() << " " << ssum << " " << s*large.size() << " " << lsum << " " << constant << endl;
            cout << s << " " << (s*(ll)small.size()-ssum) + (lsum-s*(ll)large.size()) + constant << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3828
from queue import PriorityQueue
from collections import defaultdict
from heapq import heappush, heappop

n, m, s = map(int, input().split())
graph = defaultdict(dict)
for i in range(m):
    u, v, a, b = map(int, input().split())
    graph[u][v] = (a, b)
    graph[v][u] = (a, b)

town = [None]*(n+1)
for i in range(n):
    c, d = map(int, input().split())
    town[i+1] = (c, d)

if s >= 2501:
    s = 2501
x = (1, s)
cost = 0
visit = set()
heap = []
heappush(heap, (cost, x))
ans = [None]*(n+1)
check = 0
while len(heap) > 0:
    cost, x = heappop(heap)
    if x in visit:
        continue
    visit.add(x)
    p, m = x
    if ans[p] is None:
        ans[p] = cost
        check += 1
        if check >= n:
            break
    c, d = town[p]
    if m <= 2501:
        heappush(heap, (cost+d, (p, m+c)))
    for q, edge in graph[p].items():
        a, b = edge
        if m-a >= 0:
            heappush(heap, (cost+b, (q, m-a)))
for i in range(2, n+1):
    print(ans[i])

Measured memory_bytes: 149152
#include <stdio.h>

int main(void){

  int jou(int a, int b){
    int i,count=1;
    for(i=0;i<b;i++){
      count*=a;
    }
    return count;
  }
  int N, K;
  scanf("%d %d",&N,&K);
  int j, count1=0;
  for(j=0;N/jou(K,j)!=0;j++){
}
printf("%d",j);
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int C[1010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		C[x-1]++;
		C[y-1]++;
	}
	FOR(i,N) cout<<C[i]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        int m = in.ni();
        long[] height = in.nl(n);
        int[] good = new int[n];
        for (int i = 0; i < m; i++) {
            int a = in.ni()-1 ,b = in.ni()-1;
            if(height[a]<height[b]){
                good[a]= -1;
            }else if(height[a]>height[b]){
                good[b] = -1;
            }else{
                good[a]=-1;
                good[b]=-1;
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if(good[i]>=0) ans++;
        }
        out.println(ans);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 54048
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
}
char s[N];
int n;
void input()
{
	scanf("%s",s+1);
	n=strlen(s+1);
}
int ans;
void work()
{
	ans=n;
	For(i,2,n)if(s[i]!=s[i-1])
	{
		cmin(ans,max(i-1,n-i+1));
	}
	write(ans,'\n');
}
int main()
{
//	file();
	input();
	work();
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x,long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long C(long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  string x;cin>>x;
  ll N=x.size();
  
  ll s=0;
  ll res=0;
  
  rep(i,N){
    if(x[i]=='S')
      s++;
    else if(s>0){
      s--;
      res+=2;
    }
  }
  
  cout<<N-res;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};


int main() {
    ll D;
    cin >> D;
    vl c(26);
    rep(i,26){
        cin >> c[i];
    }
    ll s[D][26];
    rep(i,D){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    vl latest_t(26,0);
    ll k=0;
    FOR(i,1,D+1){
        vl nt=latest_t;
        ll nk=k;
        ll MX=-INF;
        ll ans;
        rep(j,26){
            nk+=s[-1+i][j];
            nt[j]=i;
            rep(l,26){
                nk-=c[l]*(i-latest_t[l]);
            }
            if(nk>MX){
                nk=MX;
                ans=j;
            }
            if(j==25){
                k=MX;
            }
        }
        cout << ans+1 << endl;
        latest_t[ans]=i;
        k+=s[-1+i][ans];
    }
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  string s, t;
  cin>>s>>t;
  int n = s.size();
  if(s == t.substr(0, n)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3724
#include<iostream>

using namespace std;

char flip_char(char c){
	if(c == 'L') return 'R';
	return 'L';
}

int happy_num(int n, char* s){
	int out = 0;
	for(int i = 0; i < n; i++){
		if(i == 0 && s[0] == 'L'){}
		else if(i == n - 1 && s[i] == 'R'){}
		else if(s[i] == 'L' && s[i-1] == 'L'){out++;}
		else if(s[i] == 'R' && s[i+1] == 'R'){out++;}
	}
	return out;
}

int main(void){
	int n, k;
	char s[100000];

	cin >> n >> k >> s;

	int flip = k;
	int cur = 1;
	while(cur < n && flip){
		if(s[cur] != s[cur-1]){
			char last = s[cur-1];
			while(cur < n && s[cur] != last){
				s[cur] = flip_char(s[cur]);
				cur++;
			}
			flip--;
			cerr << "Flipped:" << s << '\n';
		}else{
			cur++;
		}
	}

	cout << happy_num(n, s) << '\n';

	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	int n,m,a,b;
	int k[55];
	for(int i=0;i<55;i++)k[i]=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&a,&b);
		k[a]++;k[b]++;
	}
	for(int i=1;i<=n;i++)printf("%d\n",k[i]);
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    long long N, A, B;
    cin >> N >> A >> B;
    vector<int> X(N);
    for(int i=0; i<N; i++){
        cin >> X[i];
    }
    long long ans=0;
    for(int i=0; i<N-1; i++){
        if((X[i+1]-X[i])*A<B){
            ans+=(X[i+1]-X[i])*A;
        }else{
            ans+=B;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
long long n, a[20], b[20], ans=999999999LL, sol;
vector<int> x; int v[20];
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n; 
for (int i=0; i<n; i++) cin >> a[i]; 
for (int i=0; i<n; i++) cin >> b[i];

for (int i=0; i<(1<<n); i++){
	if (__builtin_popcount(i)&1) continue;
	x.clear(); for (int j=0; j<n; j++) v[j]=0;
	for (int j=0; j<n; j++) 
		if ((1<<j) & i) x.push_back(b[j]);
		else x.push_back(a[j]);
	sort(x.begin(), x.end());
	bool ok=1; sol=0;
	for (int j=0; j<n and ok; j++){
		bool kk=0;
		if ((1<<j)&i){ 
			for (int l=(j+1)%2; l<n; l+=2){
				if (x[l]==b[j] and !v[l]){
				//	cout << l << endl;
					v[l]=j+1; kk=1; break;
				}
			}
		}
		else {
			for (int l=j%2; l<n; l+=2){
				if (x[l]==a[j] and !v[l]){
				//	cout << l << endl;
					v[l]=j+1; kk=1; break;
				}
			}
		}
//	cout << i << " "; for (int i=0; i<n; i++) cout << x[i] << " "; cout << "  " << kk << "   " << sol<< endl;
		ok=ok and kk; 
	}
	if (ok){
		for (int j=0; j<n; j++) 
			for (int l=0; l<j; l++) 
			if (v[j]<v[l]) sol++;
		ans=min(ans, sol);
	}
}
if (ans==999999999LL) cout << "-1";
else cout << ans;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const int Max=1e5+5;
const int Mod=1e9+7;

ll g(int n)
{
	ll res=1;
	for(int i=1;i<=n;i++)
	{
		res*=i;
		res%=Mod;
	}
	return res;
}

int main()
{
	int n,m;
	cin>>n>>m;
	if(abs(m-n)>=2)
	 cout<<0;
	else
	{
		if(n==m)cout<<2*g(n)*g(m)%Mod;
		else cout<<g(n)*g(m)%Mod;
	} 
}

Measured memory_bytes: 3120
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    int p[22];
    for(int i=0; i<n; i++) cin>>p[i];
    int ans=0;
    for(int i=1; i<n-1; i++){
        if(p[i-1]>p[i] && p[i]>p[i+1]){
            ans++;
        }else if(p[i-1]<p[i] && p[i]<p[i+1]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;

int main() {
    // input
    int n, m; cin >> n >> m;
    vector<ll> a(n), b(n);
    REP (i, n) {
        cin >> a[i] >> b[i];
    }

    // solve
    ll acc = 0;
    set<int> available;
    REP (i, m) {
        available.insert(i);
    }
    available.insert(INT_MIN);
    available.insert(INT_MAX);
    vector<int> order(n);
    iota(ALL(order), 0);
    sort(ALL(order), [&](int i, int j) { return b[i] > b[j]; });
    for (int i : order) {
        auto it = prev(available.upper_bound(m - a[i]));
        if (*it != INT_MIN) {
            available.erase(it);
            acc += b[i];
        }
    }

    // output
    cout << acc << endl;
    return 0;
}


Measured memory_bytes: 6912
import sys
d={"Vacant":0, "Male":1, "Female":-1}

N=int(input())
M=[2 for _ in range(N+1)]
print(0, flush=True)
M[0]=d[input()]
M[N]=M[0]

def search(l,r):
    if r - l == 2:
        print(l+1)
        sys.exit()
    print((l+r)//2, flush=True)
    return d[input()]
l=0
r=N
while True:
    m=(r+l)//2
    M[m] = search(l,r)
    if M[m] == 0:
        print(m)
        sys.exit()
    if (m-l) % 2 == 0:
        if M[m] == M[l]:
            l=m
        else:
            r=m
    else:
        if M[m] == M[l]:
            r=m
        else:
            l=m

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

int main(){
  int a,b,ab,x,y;
  cin >> a >> b >> ab >> x >> y;
  int c = 2*ab;
  long long ans = 5000 * 100000 * 2;
  for(int i = 0; i <= max(x,y); ++i){
    int cur_x = max(0, x - i);
    int cur_y = max(0, y - i);
    long long cur_ans = c * i + a * cur_x + b * cur_y;
    if(cur_ans < ans){
      ans = cur_ans;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main2():
    import heapq
    n,k = map(int,input().split(" "))
    q = []
    for i in range(n):
        a,b = map(int,input().split(" "))
        heapq.heappush(q,(a,b))
    
    while k>0:
        a,b = heapq.heappop(q)
        k-=b
    
    print(a)
main2()

Measured memory_bytes: 16692
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
h, a = i2()
print(h//a if h%a == 0 else h//a+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = 10000007;
const int MOD = 998244353;

template <typename T> inline void read(T &AKNOI) {
    T x = 0, flag = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') flag = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    AKNOI = flag * x;
}

namespace ModCalculator {
	inline void Inc(int &x, int y) {
		x += y; if (x >= MOD) x -= MOD;
	}
	inline void Dec(int &x, int y) {
		x -= y; if (x < 0) x += MOD;
	}
	inline int Add(int x, int y) {
		Inc(x, y); return x;
	}
	inline int Sub(int x, int y) {
		Dec(x, y); return x;
	}
	inline int Mul(int x, int y) {
		return 1LL * x * y % MOD;
	}
}
using namespace ModCalculator;

inline int ksm(int x, int k) {
	int ret = 1;
	while (k) {
		if (k & 1) ret = Mul(ret, x);
		x = Mul(x, x);
		k >>= 1;
	}
	return ret;
}

int n, a, b;
int fac[MAXN], finv[MAXN];

inline int C(int x, int y) {
	return Mul(fac[x], Mul(finv[y], finv[x - y]));
}

inline int H(int x, int y) {
	return Sub(C(x + y, y), C(x + y, y - 1));
}

void init() {
	read(n); read(a); read(b);
	if (b == 0) {
		printf("1\n");
		exit(0);
	}
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i] = Mul(fac[i - 1], i);
	}
	finv[n] = ksm(fac[n], MOD - 2);
	for (int i = n - 1; i >= 0; --i) {
		finv[i] = Mul(finv[i + 1], i + 1);
	}
}

void solve() {
	int ans = 0;
	int kmx = min(min(a, b - 1), n - b);
	for (int k = 0; k <= kmx; ++k) {
		int h = H(b - 1, k);
		if (k + b == n) {
			if (a == k) Inc(ans, h);
		} else {
			int x = n - b - k - 1;
			int y = a - k + 1;
			Inc(ans, Mul(h, C(x + y - 1, x)));
		}
	}
	printf("%d\n", ans);
}

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


Measured memory_bytes: 78336
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int H = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        
        String[][] map = new String[H][W];        
        for(int y=0; y<H; y++){
            String[] s = sc.next().split(""); 
            for(int x=0; x<W; x++){
                map[y][x] = s[x];
            }
        }
        
        int[] direction_x = {-1, 0, 1,-1, 1,-1, 0, 1};
        int[] direction_y = {-1,-1,-1, 0, 0, 1, 1, 1};
        
        for(int y=0; y<H; y++){
            for(int x=0; x<W; x++){
                if(map[y][x].equals("#")){
                    System.out.print("#");
                    continue;
                }
                int ans = 0;
                for(int z=0; z<8; z++){
                    if(0 <= y+direction_y[z] && y+direction_y[z] < H && 0 <= x+direction_x[z] && x+direction_x[z] < W){
                        if(map[y+direction_y[z]][x+direction_x[z]].equals("#")){
                            ans++;
                        }
                    }
                }
                System.out.print(ans);
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    
    string s, ans ="";

    cin >> s;

    for(int i=0;i<s.size();i++)
        if(i%2 == 0)
            ans += s[i];
    
    cout << ans << endl;
    return 0;

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;

using namespace std;
int main() {
	int d;
	cin >> d;
	string s = "Christmas";
	string eve = "Eve";
	d -= 22;
	rep(i,3) {
		s += " " + eve;
	}
	rep(i, d) {
		rep(j, 4)s.pop_back();
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256