akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
template<typename T>
T argument(const pair<T, T> &a, const pair<T, T> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/

int const MAX = 2000000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

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

    COMinit();
    int n, k; std::cin >> n >> k;
    if (n<k) { std::cout << 0 << std::endl; return 0; }

    ll ans = 0;
    repr(i, 1, k+1) {
        ll add = COM(k, i) * modpow(k-i, n);
        chmod(add);
        ans += add * (i%2==1? 1:-1);
        chmod(ans);
    }
    ans = modpow(k, n) - ans;
    chmod(ans);
    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 50088
#include<iostream>
#include<vector>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
using ulong = unsigned long;
using ll = long long;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> boxes(n, 1);
	vector<bool> prob(n, false);
	prob[0] = true;
	for(int i=0;i<m;i++){
		int x, y;
		cin >> x >> y;
		x--; y--;
		if(prob[x]){
			prob[y] = true;
		}
		if(boxes[x] == 1){
			prob[x] = false;
		}
		boxes[x]--;
		boxes[y]++;
	}

	int ret = accumulate(prob.begin(), prob.end(), 0);
	cout << ret << endl;
	return 0;
}


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

int main() {
    string S,T;
    cin>>S>>T;
    int ans=0;
    for (int i = 0; i < S.size(); i++){
        if(S[i]!=T[i])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n,k;
int a[100000];
bool dp[10000][10000];

bool C(int m) {
	REP(i,k) {
		dp[0][i] = false;
	}

	dp[0][0] = true;


	FOR(i,1,n + 1) {
		REP(j,k) {
			if(i - 1 != m) {
				bool c = false;
				if(j - a[i - 1] >= 0) {
					c = dp[i - 1][j - a[i - 1]];
				}
				dp[i][j] = (c || dp[i - 1][j]);
			} else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}

	bool ret = false;
	if(k - a[m] < 0) {
		ret = true;
	}else {
		FOR(i,max(k - a[m],0),k) {
			ret |= dp[n][i];
		}
	}
	return ret;
}

ll binsearch_i_min(){
	ll lb = -1,ub = n;//(lb,ub]が探索範囲

	while(ub - lb > 1){
		ll mid = (lb + ub) / 2;
		if(C(mid))ub = mid;
		else lb = mid;
	}

	return ub;
}

int main(){
	cin >> n >> k;
	REP(i,n) {
		cin >> a[i];
	}
	sort(a,a+n);
	cout << binsearch_i_min() << endl;
	return 0;
}


Measured memory_bytes: 49280
#include<iostream>
#include<cstdio>
using namespace std;
string s,x="CODEFESTIVAL2016";
int ans;
int main()
{
	cin>>s;
	for(int i=0; i<16; i++)
	{
		if(s[i]!=x[i]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

template<typename T1,typename T2> inline void cmax(T1 &a,T2 b) {
  if (a < b) a = b;
}

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector V(H, vector(W, 0));
  for (int h, w, v; cin >> h >> w >> v;) V.at(--h).at(--w) = v;
  vector DP(H, vector(W, vector(5, 0L)));
  DP.at(0).at(0).at(1) = V.at(0).at(0);
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      for (int i = 0; i < 4; i++) {
        long now = DP.at(h).at(w).at(i);
        if (h + 1 < H) cmax(DP.at(h + 1).at(w).at(0), now);
        if (h + 1 < H) cmax(DP.at(h + 1).at(w).at(1), now + V.at(h + 1).at(w));
        if (w + 1 < W) cmax(DP.at(h).at(w + 1).at(i), now);
        if (w + 1 < W) cmax(DP.at(h).at(w + 1).at(i + 1), now + V.at(h).at(w + 1));
      }
    }
  }
  cout << *max_element(DP.at(H - 1).at(W - 1).begin(), DP.at(H - 1).at(W - 1).begin() + 4) << "\n";
}


Measured memory_bytes: 671644
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
//typedef complex<double> P;
typedef pair<double, double> P;
#define X first
#define Y second
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
#define prev(P, i) P[(i+P.size()-1) % P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
const double EPS = 1e-8;
const double INF = 1e12;
//namespace std {
//  bool operator < (const P& a, const P& b) {
//    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
//  }
//}

typedef vector<P> G;

double compare_x(const P &a, const P &b){
  return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}

double compare_y(const P &a, const P &b){
  return a.Y != b.Y ? a.Y < b.Y : a.X < b.X;
}

double length_of_the_nearest_point_to(pair<double, double> a[100000], int n){
    if(n<=1)return 999999999.9;
    int m=n/2;
    double x=a[m].first;
    double d=min(length_of_the_nearest_point_to(a, m), length_of_the_nearest_point_to(a+m, n-m));
    sort(a, a+n, compare_y);
    vector<pair<double, double> >b;
    for(int i=0; i<n; i++){
        if(fabs(a[i].first-x)>=d)continue;
        for(int j=0; j<b.size(); j++){
            double dx=a[i].first-b[b.size()-j-1].first;
            double dy=a[i].second-b[b.size()-j-1].second;
            if(dy>=d)break;
            d=min(d,sqrt(dx*dx+dy*dy));
             
        }
        b.push_back(a[i]);
    }
    return d;
}

int main() {
  int N; cin >>N;
  G g(N);
  REP(i, N){
    double x, y; cin >>x >>y;
    g[i] = P(x, y);
  }
  sort(g.begin(), g.end(), compare_x);
  printf("%.10lf\n", length_of_the_nearest_point_to(&g[0], N));
  return 0;
}

Measured memory_bytes: 5616
//ABC109A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int n, i;
	cin >> n >> i;
	int ans = n-i+1;
	cout << ans << endl;
	return 0;
}

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

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

    int ans = 0;
    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= k; j++) {
            if ((i%2 == 0) && (j%2 ==1)) ans++;
            else if ((i%2 == 1) && (j%2 == 0)) ans++;
        }   
    }
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 3596
fun main(args: Array<String>) {
    val (N, L) = readLine()!!.split(" ").map { Integer.parseInt(it) }
    val tasteList = mutableListOf<Int>()
    for (i in 1 until N + 1) {
        tasteList.add(L + i - 1)
    }
    val tasteListAbs = tasteList.map { Math.abs(it) }
    tasteList.removeAt(tasteListAbs.indexOf(tasteListAbs.min()!!))
    print(tasteList.sum())

}


Measured memory_bytes: 37932
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;

/* -- template -- */

int gcd(int x, int y){
    if(y == 0)return x;
    return gcd(y, x % y);
}

int main(){
    int N;cin >> N;
    int A[N];
    rep(i, N){
        cin >> A[i];
    }
    int ans = 0;
    int ggg1[N];
    ggg1[0] = A[0];
    for(int i = 1;i < N;++i){
        ggg1[i] = ((ggg1[i - 1] < A[i]) ? gcd(A[i], ggg1[i - 1]) : gcd(ggg1[i - 1], A[i]));
    }
    int ggg2[N];
    ggg2[N - 1] = A[N - 1];
    for(int i = N - 2;i >= 0;--i){
        ggg2[i] = ((ggg2[i + 1] < A[i]) ? gcd(A[i], ggg2[i + 1]) : gcd(ggg2[i + 1], A[i]));
    }
    for(int i = 0;i < N;++i){
        //i = 0 ggg2[1] i = 1 gcd(ggg1[0], ggg2[2]), i = 2 ggg1[1]
        ans = max(gcd(((i - 1 >= 0) ? ggg1[i - 1] : ggg2[i + 1]), ((i + 1 < N) ? ggg2[i + 1] : ggg1[i - 1])), ans);
    }

    cout << ans;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
using ll = long long;

void max_self(ll& a, ll b) {
	a = max(a, b);
}

int main() {
	int n;
	scanf("%d", &n);

	int base = 1;
	while(base <= n) {
		base *= 2;
	}
	// base is the smallest power of 2 that is not smaller than n
	vector<ll> tree(2 * base);

	vector<int> h(n), a(n);
	for(int i = 0; i < n; ++i) {
		scanf("%d", &h[i]);
	}
	for(int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	vector<ll> dp(n + 1);
	// dp[i] - the max total beauty so far if the last taken flower has height i
	for(int flower = 0; flower < n; ++flower) {

		// max dp[i] for i in [0, h[flower]-1]
		int x = h[flower] + base;
		ll best = 0;
		while(x > 1) {
			if(x % 2 == 1) {
				max_self(best, tree[x-1]);
			}
			x /= 2;
		}
		dp[h[flower]] = best + a[flower];

		for(int i = base + h[flower]; i >= 1; i /= 2) {
			max_self(tree[i], dp[h[flower]]);
		}

		//~ for(int i = 0; i < h[flower]; ++i) {
		//~ max_self(dp[h[flower]], dp[i] + a[flower]);
		//~ }
	}
	ll answer = 0;
	for(int i = 0; i <= n; ++i) {
		max_self(answer, dp[i]);
	}
	printf("%lld\n", answer);
	return 0;
}

Measured memory_bytes: 10764
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());

using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MOD = 1000000007; // 10^9 + 7

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

  int N, M; cin >> N >> M;
  string ans = "";
  REP(i, N) ans += "*";
  int S[M];
  char C[M];

  REP(i, M) {
    int s; cin >> S[i];
    char c; cin >> C[i];
  }

  REP(i, M) {
    if (ans[S[i] - 1] == '*') {
      ans[S[i] - 1] = C[i];
    } else if (ans[S[i] - 1] != C[i]) {
      cout << "-1" << endl;
      return 0;
    }
  }

  REP(i, N) {
    if (ans[i] == '*') {
      if (i == 0 && N != 1) ans[i] = '1';
      else ans[i] = '0';
    }
  }

  if (ans[0] == '0' && N != 1) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> B(N);
  REP(i, N) cin >> B[i];

  int step = 0;
  REP(i, N) step += B[i]-A[i];


  int cnt = 0;
  REP(i, N){
    int gap = B[i]-A[i];
    if(gap > 0){
      int now = (gap+1)/2;
      A[i] += 2*now;
      cnt += now;
    }
  }

  if(cnt <= step) Yes;
  else No;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	string s;
	cin >> s;
	int ans = 0;
	if(s[0] == '1') ans++;
	if(s[1] == '1') ans++;
	if(s[2] == '1') ans++;
	cout << ans << endl;
}

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


using namespace std;

typedef long long ll;




int main(void)
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);


    int n;
    cin>>n;
   if(n>=400 && n<=599)
   {
       cout<<8<<endl;
   }
   if(n>=600 && n<=799)
   {
       cout<<7<<endl;
   }
    if(n>=800 && n<=999)
   {
       cout<<6<<endl;
   }
    if(n>=1000 && n<=1199)
   {
       cout<<5<<endl;
   }
    if(n>=1200 && n<=1399)
   {
       cout<<4<<endl;
   }
    if(n>=1400 && n<=1599)
   {
       cout<<3<<endl;
   }
    if(n>=1600 && n<=1799)
   {
       cout<<2<<endl;
   }
    if(n>=1800 && n<=1999)
   {
       cout<<1<<endl;
   }

}


Measured memory_bytes: 3620
#include <stdio.h>
int main(){
    int i,j;
    int A[100],N,num=0,v;
    
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

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


Measured memory_bytes: 2052
#include<stdio.h>

#define N 100000

int doPartition(int,int);

int n;
int A[N];

int main(){

  int i,c;
  
  scanf("%d",&n);

  for(i = 0;i < n;i ++)
    {
      scanf("%d",&A[i]);
    }
   
  c = doPartition(0,n - 1);
   
  for(i = 0;i<n - 1;i ++)
    {
      if(i == c)
	{
	  printf("[%d] ",A[i]);
	}
      else{
	printf("%d ",A[i]);
      }
    }
  
  printf("%d",A[n - 1]);

  printf("\n");

  return 0;
}

int doPartition(int p,int r){

  int i,j,x,y;

  x = A[r];
  i = p - 1;

 for(j = p;j < r;j ++)
   {
     if(A[j] <= x)
       {
	 i = i + 1;
	 y = A[i];
	 A[i] = A[j];
	 A[j] = y;
       }
   }
 
 y = A[i + 1];
 A[i + 1] = A[r];
 A[r] = y;
 return i + 1;
 
}

Measured memory_bytes: 992
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

eats = sorted(p, reverse=True)[:x] + sorted(q, reverse=True)[:y] + r
eats.sort(reverse=True)
print(sum(eats[:x+y]))

Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int INF = 1<<29;

void chmin(int &a, int b){if(a > b) a = b;}

int n, A, B, C;
vector<int> l;

//4^Nの全探索
int rec(int i, int a, int b, int c){
    if(i == n){
        if(!a || !b || !c) return INF;
        return abs(a - A) + abs(b - B) + abs(c - C);
    }
    int res = rec(i+1, a, b, c);
    chmin(res, rec(i+1, a+l[i], b, c) + (a ? 10 : 0));
    chmin(res, rec(i+1, a, b+l[i], c) + (b ? 10 : 0));
    chmin(res, rec(i+1, a, b, c+l[i]) + (c ? 10 : 0));

    return res;
}

int main(){
    cin >> n >> A >> B >> C;
    l.resize(n);
    rep(i,n) cin >> l[i];
    cout << rec(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
import * as fs from 'fs';

//in
//
//out
//
const main = (inp: string) => {
    const [a, b]: number[] = inp.split(' ').map(Number);

    if (a > 9 || b > 9) {
        console.log(-1);
    } else {
        console.log(a * b);
    }

};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 7372
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

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

  for (ll i = 0; i <= 300; i++){
    for (ll j = -300; j <= 300; j++){
      ll now = pow(i, 5) - pow(j, 5);
      if (now == X){
        printf("%lld %lld\n", i, j);
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 4172
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<int,P> PP;
struct edge { int to, cor; };

int a[3005];
int dp[3005][3005];
int n; 
int memo(int l, int r) {//[l,r]
	if (dp[l][r])return dp[l][r];
	int res;
	if ((((r - l + 1 )) & 1)==(n&1)) {//先手
		if (r == l) {
			res = a[l];
		}
		else {
			res = max(a[l] + memo(l + 1, r), a[r] + memo(l, r - 1));
		}
	}
	else {
		if (r == l) {
			res = 0;
		}
		else res = min(memo(l + 1, r) , memo(l, r - 1));
	}
	return dp[l][r] = res;
}

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

	int sum=memo(0, n - 1);
	int asum = 0;
	rep(i, n)asum += a[i];
	
	cout << sum *2- asum << endl;
}

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

ll f (ll x, ll a, ll b) {
    ll A = a*x / b;
    ll B = (x/b) * a;
    return A - B;
}

int main() 
{
    ll a, b, n;
    cin >> a >> b >> n;

    if (n>=b-1) {
        cout << f(b-1, a, b) << endl;
        return 0;
    }
    cout << f(n, a, b) << endl;
    
    return 0;
}


Measured memory_bytes: 3672
<?php
  
 fscanf(STDIN,"%d",$N);
 $p_list = array();

	$p_list = explode(" ",trim(fgets(STDIN)));



$max = $p_list[0];
$count = 1;
for($i=1;$i<$N;$i++){
  if($max>=$p_list[$i]){
    $count++;
    $max = $p_list[$i];
  }
}

echo $count."\n";
  



                  
                  
                  



Measured memory_bytes: 18932
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#define FOR(x, z, y) for(int x = (z); y; x++)
#define rep(x, y) for(int x = 0; x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; FOR(cnt, 0, getline(stream,res,sp_word))
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
typedef long long ll;
using namespace std;

int main(){
  long N,K,a,b;
  scanf("%ld%ld",&N,&K);

  vector<pair<int,int>> ab;

  for(long i = 0; i < N; i++){
    scanf("%ld%ld",&a,&b);
    ab.push_back(make_pair(a,b));
  }
  
  sort(all(ab));
  long long sum = 0;
  for(long i = 0; i < ab.size(); i++){
    sum += ab[i].second;
    if(sum >= K){
      printf("%d\n",ab[i].first);
      return 0;
    }
  }
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF INT_MAX
#define LLINF LLONG_MAX
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

struct edge {ll from, to, cost; };

edge es[3000];
ll d[3000];
ll V,E,r;

bool find_negative_loop(){
    memset(d, 0, sizeof(d));
    rep(i,V){
        rep(j,E){
            edge e=es[j];
            if(d[e.to]> d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i==V-1) return true;
            }
        }
    }
    return false;
}

bool bellmanford(ll s){
    rep(i,V) d[i]=INF;
    d[s]=0;
    rep(cnt,100010){
        bool update = false;
        rep(i,E){
            edge e=es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(cnt==V) return true; 
        if(!update) break;
    }
    return false;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cin>>V>>E>>r;
    rep(i,E){
        ll a,b,c;
        cin>>a>>b>>c;
        es[i]={a,b,c};
    }
    if(bellmanford(r)){
        cout<<"NEGATIVE CYCLE"<<endl;
        return 0;
    }
    bellmanford(r);
    rep(i,V){
        if(d[i]==INF) cout<<"INF"<<endl;
        else cout<<d[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3204
import math
a,b,h,m = map(int,input().split())
h_x = a * math.sin(math.radians(30*h+0.5*m))
h_y = a * math.cos(math.radians(30*h+0.5*m))
m_x = b * math.sin(math.radians(6*m))
m_y = b * math.cos(math.radians(6*m))
ans = math.sqrt(((h_x-m_x)**2) + ((h_y - m_y)**2))
print(ans)

Measured memory_bytes: 9520
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    while(cin>>s)
    {
        int sum=0;
        for(int i=0; i<s.size(); i++)
            if(s[i]=='-')
                sum--;
            else
                sum++;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll INF = 1e9+7;
int main()
{
    int n;
    cin >> n;
    vector<P> x(n);
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        x[i] = P(a, i+1);
    }
    sort(x.begin(), x.end());

    set<int> s;
    for(int i = 1; i <= n*n; i++)
    {
        s.insert(i);
    }

    vector<int> ans(n*n+1);
    vector<P> v(n);
    for(int i = 0; i < n; i++)
    {
        P p = x[i];
        int now = p.first;
        int num = p.second;
        int l = num-1;
        int r = n-num;
        while(l--)
        {
            int tmp = *s.begin();
            if(tmp >= now)
            {
                cout << "No" << endl;
                return 0;
            }
            ans[tmp] = num;
            s.erase(tmp);
        }
        if(s.find(now) == s.end())
        {
          cout << "No" << endl;
          return 0;
        }
        ans[now] = num;
        s.erase(now);
        v[i] = P(r, num);
    }
    for(int i = 0; i < n; i++)
    {
        P p = v[i];
        int now = x[i].first;
        for(int j = 0; j < p.first; j++)
        {
            int tmp = *s.begin();
            if(tmp < x[i].first)
            {
                cout << "No" << endl;
                return 0;
            }
            ans[tmp] = p.second;
            s.erase(tmp);
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i <= n*n; i++)
    {
        cout << ans[i] << " ";
    }
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        cout << (n + n * n + n * n * n) << '\n';
    }
}

Measured memory_bytes: 34240
#include<stdio.h>
int main(void){
  int n,i;
  char s[10000];
  for(i=0;i<10000;i++){
    s[i]=0;
  }
  scanf("%d",&n);
  scanf("%s",s);
  i=0;
  while(s[i]!=0){
    s[i]-='A';
    s[i]+=n;
    s[i]%=26;
    s[i]+='A';
    printf("%c",s[i++]);
  }
  printf("\n");
  return 0;
}


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

using namespace std;

int main() {
    int N;
    string S;
    int x = 0;
    int max = 0;

    cin >> N;
    cin >> S;

    for (int i = 0; i < N; i++) {
        if (S[i] == 'I') ++x;
        else --x;

        if (max < x) {
            max = x;
        }
    }
    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000


int main(){
	
	int N;
	cin>>N;
	vector<int> a(N);
	bool f = false;
	
	vector<int> cnt_0(30,0);
	vector<int> cnt_1(30,0);
	set<int> S;
	
	for(int i=0;i<N;i++){
		cin>>a[i];
		S.insert(a[i]);
		if(a[i]!=0){
			f=true;
		}
		for(int j=0;j<30;j++){
			if(a[i]%2==0){
				cnt_0[j]++;
			}
			else cnt_1[j]++;
			a[i]/=2;
		}
	}
	if(f==false){
		cout<<"Yes"<<endl;
		return 0;
	}
	
	if(N%3!=0){
		cout<<"No"<<endl;
		return 0;
	}
	
	bool ff = false;
	
	for(int i=0;i<30;i++){
		if(cnt_0[i]!=N&&cnt_0[i]*3!=N){
			ff=true;
			break;
		}
	}
	
	
	if(ff){
		cout<<"No"<<endl;
		return 0;
	}

	
	cout<<"Yes"<<endl;

	
	return 0;
}


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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18
int n,K;
vvi g(55,vi(55));
vvi ans(55,vi(55,1));
void matrix_mul(vvi &a,vvi &b){
  vvi p(55,vi(55));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      for(int k=0;k<n;k++)
        p[i][j]=(p[i][j]+a[i][k]*b[k][j])%mod;
  a=p;
}
void b_exp(int k){
  if(k==1){
    ans=g;
    return;
  }
  b_exp(k/2);
  matrix_mul(ans,ans);
  if(k&1)matrix_mul(ans,g);
}
void solve(){
  cin>>n>>K;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>g[i][j];
  b_exp(K);
  int res=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      res=(res+ans[i][j])%mod;
  
  cout<<res;
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}

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

using namespace std;

using ull = unsigned long long;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n, k;
  cin >> n >> k;
  if (n < k) {
    ll res1 = k - n;
    ll res2 = k - res1;
    cout << (res1 <= res2 ? res1 : res2) << '\n';
  }
  else {
    if (n % k == 0) {
      cout << 0 << '\n';
    }
    else {
      ll mod = n % k;
      if (mod == 1) {
        cout << 1 << '\n';
      }
      else {
        ll tmp = mod - k;
        if (tmp < 0) {
          tmp = -tmp;
        }
        if (tmp <= mod) {
          cout << tmp << '\n';
        }
        else {
          cout << mod << '\n';
        }
      }
    }
  }
 
  
  return 0;
}


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

typedef long long ll;

int main() {
    int N, a, ans = 0;
    cin >> N;
    rep(i, N) {
        cin >> a;
        ans += a - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int A[1000000]={0}, n, i, j, k, v, cnt=0, m, G[100]={0};
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    i = 0;
    G[0] = 1;
    while(1){
        if(G[i] > n){
            m = i;
            break;
        } else {
            G[i+1] = (3 * G[i]) + 1;
            i++;
        }
    }
    for(i = 0; i < m; i++){
        for(j = G[m-1-i]; j < n; j++){
            v = A[j];
            k = j -G[m-1-i];
            while(k >= 0 && A[k] > v){
                A[k + G[m-1-i]] = A[k];
                k = k - G[m-1-i];
                cnt++;
            }
            A[k + G[m-1-i]] = v;
        }
    }
    printf("%d\n", m);
    for(i =0; i < m; i++){
        if(i == m-1){
            printf("%d\n", G[m-1-i]);
        } else {
            printf("%d ", G[m-1-i]);
        }
    }
    printf("%d\n", cnt);
    for(i = 0; i < n; i++){
        printf("%d\n", A[i]);
    } 
    return 0;
}



Measured memory_bytes: 5768
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val d = readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    var difficult = mutableSetOf<Int>()
    var testNum = mutableMapOf<Int, Int>()
    for (i in 0 until d.lastIndex) {
        difficult.add(d[i])
        if (testNum.containsKey(d[i])) {
            testNum[d[i]]!!.inc()
        } else {
            testNum[d[i]] = 1
        }
    }
    val testLevel = d.sorted()
    if (testLevel[(d.size.div(2) - 1)] == testLevel[(d.size.div(2))]) {
        println(0)
    } else {
        println(testLevel[(d.size.div(2))] - testLevel[(d.size.div(2) - 1)])
    }
}


Measured memory_bytes: 56952
void main()
{
    long[] abc = readln.split.to!(long[]);
    if (abc.all!"a % 2 == 0")
    {
        if (abc.all!(x => x == abc[0]))
        {
            writeln(-1);
        }
        else
        {
            long cnt;
            while (abc.all!"a % 2 == 0")
            {
                long[] tmp = new long[3];
                foreach (i; 0 .. 3)
                {
                    tmp[i] = (abc[(i+1)%3] + abc[(i+2)%3]) / 2;
                }
                abc = tmp;
                ++cnt;
            }
            cnt.writeln;
        }
    }
    else
    {
        0.writeln;
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

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

using namespace std;

const int IINF = INT_MAX;
int h,w,K;
char c[51][51];
int memo[50][50][1<<12][4];
int dx[] = {0,1,0,-1}; // ????????????
int dy[] = {1,0,-1,0};

inline bool isValid(int x,int y) { return 0 <= x && x < w && 0 <= y && y < h; }

int dfs(int x,int y,int remain,int bit){

  if( memo[y][x][bit][remain] != -1 ) return memo[y][x][bit][remain];
  
  if( x == w-1 && y == h-1 && remain == 0 ) return 0;
  
  int px = x,py = y;
  bool already_visited = false;
  rep(i,(2*K)){
    px -= dx[(bit>>(i*2))&3];
    py -= dy[(bit>>(i*2))&3];
    if( !isValid(px,py) ) break;
    if( px == x && py == y ) {
      already_visited = true;
      break;
    }
  }

  int ret = 0;
  if( !already_visited && '0' <= c[y][x] && c[y][x] <= '9' ) ret = c[y][x] - '0';
  
  int maxi = -2;
  rep(i,4){
    int nx = x + dx[i], ny = y + dy[i];
    if( !isValid(nx,ny)  ) continue;
    if( c[ny][nx] == '#' ) continue;
    if( i >= 2 && remain == 0 ) continue;
    maxi = max(maxi,dfs(nx,ny,remain-(i>=2),((bit<<2)|i)&((1<<(4*K))-1)));
  }

  if( maxi == -2 ) return memo[y][x][bit][remain] = -2;
  return memo[y][x][bit][remain] = ret + maxi;
  
}

int main(){
  scanf("%d %d %d",&h,&w,&K);
  rep(i,h) scanf(" %s",&c[i][0]);
  memset(memo,-1,sizeof(memo));
  int tmp = dfs(0,0,K,2);
  if( tmp == -2 ) puts("0");
  else            printf("%d\n",dfs(0,0,K,0));
  return 0;
}

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

int main(){
 LL N,K; cin>>N>>K;
 LL X=1;

 while(N--){
  if(X<K) X*=2;
  else X+=K;
 }
 cout<<X<<endl;

 return 0;
}




Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A,B,C,D,E,F,G,H,K,L,M,N,P,Q,R,W,X,Y,Z;
string  S,T;

int main(){
  cin >> H >> W >>  N;
  cout << (N-1)/max(H,W)+1 << endl;
}

Measured memory_bytes: 256
use proconio::input;

#[allow(unused_imports)]
use std::collections::HashSet;

use std::cmp;


fn main() {
    input! {
        n: usize,
        k: usize,
    }
    solve(n, k);
}

fn prepare(m: usize, k: usize, p :u64) -> Vec<Vec<u64>> {
    let mut v : Vec<Vec<u64>> = Vec::<Vec<u64>>::with_capacity(m + 1);
    let v0 : Vec<u64> = vec![1; 1];
    v.push(v0);
    for i in 1..m+1 {
        let mut vi : Vec<u64>;
        if i <= k {
            vi = vec![0; i+1];
            vi[0] = 1;
            vi[i] = 1;
            for j in 1..i/2+1 {
                vi[j] = (v[i-1][j-1] + v[i-1][j]) % p;
                vi[i-j] = vi[j];
            }
        }
        else {
            vi = vec![0; k+1];
            vi[0] = 1;
            if i < 2 * k {
                for j in 1..i/2+1 {
                    vi[j] = (v[i-1][j-1] + v[i-1][j]) % p;
                    let jx = i - j;
                    if jx <= k {
                        vi[jx] = vi[j];
                    }
                }
            } else {
                for j in 1..k+1 {
                    vi[j] = (v[i-1][j-1] + v[i-1][j]) % p;
                }
            } 
        }
        v.push(vi);
    }
    return v;
}

fn solve(n: usize, k: usize) {
    let p : u64 = (10u32.pow(9u32) + 7) as u64;

    // 1. Calculate values of combinations
    let m = cmp::max(k-1, n-k+1);
    let c = prepare(m, k, p);

    // 2. Calculate possible ways
    for i in 1..k+1 {
        if i > n-k+1 { 
            println!("0");
        } else {
            let t =  c[n-k+1][i] * c[k-1][i-1] % p;
            println!("{}", t);
        }
    }
}


Measured memory_bytes: 17816
void main() {
	auto N = ri;
	auto A = readAs!(int[]);
	auto tmp = A.sort().uniq.count;
	if(tmp % 2 == 0) (tmp-1).writeln;
	else tmp.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 4152
#include<cstdio>
#include<iostream>
#include<deque>
#include<vector>
#include<list>
#include<stack>
using namespace std;
int main()
{
	int r, T;
	cin >> r >> T;
	stack<int> p[1000];
	while (T--)
	{
		int choose;
		int a, b;
		cin >> choose;
		switch (choose)
		{
		case 0:
			cin >> a >> b;
			p[a].push(b);
			break;
		case 1:
			cin >> a;
			if (!p[a].empty())cout << p[a].top() << endl;
			break;


		case 2:
			cin >> a;
			if(!p[a].empty())
			p[a].pop();
			break;
		}
	}
}



Measured memory_bytes: 4424
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// to container
template <class C>
void input(C &c)
{
    for_each(c.begin(), c.end(), [](auto &i) { cin >> i; });
}

// to number, string
template <class T>
T input()
{
    T data;
    cin >> data;
    return data;
}

int main()
{
    ll N = input<ll>(), M = input<ll>();

    priority_queue<ll> q;
    for (ll i = 0; i < N; i++)
    {
        q.push(input<ll>());
    }

    for (ll i = 0; i < M; i++)
    {
        ll a = q.top() / 2;
        q.pop();
        q.push(a);
    }

    ll res = 0;
    while (!q.empty())
    {
        res += q.top();
        q.pop();
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
float odd(int n)
{
    float prob;
    if(n%2 == 0)
    {
        prob = (float)(n/2)/n;
    }
    else
    {
        prob = (float)(n/2 + 1)/n;
    }
    return prob;
}
int main()
{
    int n;
    float res;
    cin>>n;
    res = odd(n);
    cout<<res;
    return 0;
}

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

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

ll a[2123456];

int main(){
    int n;
    cin>>n;
    ll total=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        total^=a[i];
    }
    for(int i=0;i<n;i++){
        cout<<(total^a[i])<<" ";
    }
    
    return 0;
}


Measured memory_bytes: 5180
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);


int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

ll a, b;

int main() {
	cin >> a >> b;
	ll res = a;
	ll ans = 0;
	while (res <= b) {
		ans++;
		res *= 2;
	}
	cout << ans << endl;
	return 0;
}


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

class Main {
    public static void main (String args[]) {
		try {
			int[] mountain = new int[10];
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			for (int i = 0; i < 10; i++) {
				mountain[i] = Integer.parseInt(br.readLine());
			}
			Arrays.sort(mountain);
			for (int i = 9; i > 6; i--) {
				System.out.println(mountain[i]);
			}
		}
		catch (IOException e) {
			e.printStackTrace();
			System.exit(0);
		}
		catch (NumberFormatException e) {
			e.printStackTrace();
			System.exit(0);
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		finally {
			System.exit(0);
		}
    }
}

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

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

    long long int ans = k;

    for(int i = 1; i <= n-1; i++) {
        ans *= (k-1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const deque<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> inline void chmax(T& a, const T b){a=max(a,b);}
template <class T> inline void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	string S; cin >> S;
	corner(S=="AAA","No");
	corner(S=="BBB","No");
	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=998244353;
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
/*
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
//
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
*/
int main(){
  int N;
  cin>>N;
  int S=0;
  int now=0;
  while(S<N){
    now++;
    S+=now;
  }
  FOR(i,1,now+1){
    if(i==S-N){
      continue;
    }else{
      cout<<i<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
sum = 0
stack = [] 
res = []
gets.split("").each_with_index { |v, i|
  if v == "\\"
    stack << i
  elsif v == "/"
    j = stack.pop
    if !j.nil? 
      a = i - j 
      sum += a

      loop do
        k, b = res.pop
        if !k.nil?
          if j < k
            a += b
          else
            res << [k, b] 
            break
          end
        else
          break
        end
      end
      res << [j, a]
    end
  end
}
puts sum
if res.size() == 0
  puts "0"
else
  puts "#{res.size()} #{res.map{|n| n[1]}.join(" ")}"
end


Measured memory_bytes: 8164