akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
long N,M,mod=998244353;
long F[1<<25],I[1<<25];
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long C(long a,long b)
{
	return a<b||a<0||b<0?0:F[a]*I[b]%mod*I[a-b]%mod;
}
long H(long a,long b){return a<0?0:C(a+b-1,b-1);}
long calc(long n,long m,long s)
{
	long ret=0;
	for(int i=0;i<=n&&i<=m;i++)
	{
		if(s-i&1)continue;
		(ret+=C(n,i)*H((s-i)/2,n)%mod)%=mod;
	}
	return ret;
}
main()
{
	cin>>N>>M;
	long T=2*M+N;
	F[0]=1;
	for(long i=1;i<T;i++)F[i]=F[i-1]*i%mod;
	I[T-1]=power(F[T-1],mod-2);
	for(long i=T-1;i--;)I[i]=I[i+1]*(i+1)%mod;
	long ans=0;
	for(int i=0;i<=N&&i<=M;i++)
	{
		if((3*M-i)%2==1)continue;
		(ans+=C(N,i)*H((3*M-i)/2,N)%mod)%=mod;
	}
	long ret=0;
	for(int i=0;i<=N&&i<=M;i++)
	{
		if((M-i)%2==1)continue;
		(ret+=C(N,i)*H((M-i)/2,N)%mod)%=mod;
	}
	for(int i=0;i<=N-1&&i<=M;i++)
	{
		if((M-i)%2==1)continue;
		(ret+=mod-C(N-1,i)*H((M-i)/2,N-1)%mod)%=mod;
	}
	cout<<(calc(N,M,3*M)-calc(N,M,M)*N%mod+calc(N-1,M,M)*N%mod+mod)%mod<<endl;
}


Measured memory_bytes: 33024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll l = 0, r = n;
  while (r-l > 1) {
    ll mid = (l+r)/2;
    if (mid < p) {
      l = mid;
      continue;
    }
    if (a[mid]+m < a[p-1]) {
      r = mid;
      continue;
    }
    ll rem = m*(v-(p-1+n-mid));
    for (int i = mid-1; i >= p-1; i--)
      rem -= max(min(a[mid]+m-a[i], m), 0LL);
    if (rem <= 0)
      l = mid;
    else
      r = mid;
  }
  cout << l+1 << endl;
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

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

  vector<vector<int>> edge(n+1, vector<int>());

  REP(i,m){
    int a,b;
    cin >> a >> b;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
  }

  vector<bool> visited(n+1, false);
  vector<int> ans(n+1,-1);

  queue<int> q;
  q.push(1);
  visited[1]=true;

  while(!q.empty()){
    int v = q.front();
    q.pop();

    for(int nv: edge[v]){
      if(visited[nv])continue;
      ans[nv] = v;
      visited[nv] = true;
      q.push(nv);
    }
  }

  cout << "Yes" << endl;
  FOR(i,2,n+1){
    cout << ans[i] << endl;
  }

}



Measured memory_bytes: 10128
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FIO;
    long long n,a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0)
        cout<<(b-a)/2<<endl;
    else
        cout<<min(a+(b-a)/2,n-b+1+(b-a)/2)<<endl;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main()
{
    int a, b;
    cin >> a >> b;
  cout << 2*b-a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pp pair<int,int> 
#define v(T) vector<T>
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10);
//int gcd(int x, int y){
  //if(y==0) return x;
  //return gcd(y, x%y);
//}
//sort小さい順(昇順)
 
int main(){
  int n;
  cin >> n;
  v(double) a(n);
  double ans=0;
  rep(i,n) {
    cin >> a[i];
    ans += 1/a[i];
  }
  cout << 1/ans << endl;
}    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, end) for (long long int i=0; i<end; i++)
#define repp(i, begin, end) for (long long int i=begin; i<end; i++)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<__LINE__<<")"<<endl;}
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long int>;
using vllvll = vector<vll>;
using vs = vector<string>;
ll sm(vll x) {ll sum=0; rep(i, x.size()) sum+=x[i]; return sum;}
//=======================================================================================================

int main()
{
    int a;
    string s;
    cin >> a >> s;
    if(a>=3200) cout << s << endl;
    else cout << "red" << endl;
}

Measured memory_bytes: 256
'use strict'

const main = arg => {
  arg = arg.trim().split('\n');
  const H = arg[0].split(' ')[0];
  let W   = arg[0].split(' ')[1];
  const a = arg.slice(1);
  let ans = [];
  
  for (let i = 0; i < H; i++) {
    if (a[i].indexOf('#') != -1) {
      ans.push(a[i]);
    }
  }

  for (let i = 0; i < W; i++) {
    let cnt = 0;
    
    for (let j = 0; j < ans.length; j++) {
      if (ans[j][i] == '#') {
        cnt++;
      }
    }

    if (cnt == 0) {
      for (let j = 0; j < ans.length; j++) {
        let tmp = ans[j].split('');
        tmp.splice(i, 1);
        ans[j] = tmp.join('');
      }
      
      i--;
      W--;
    }
  }
  
  for (let i = 0; i < ans.length; i++) {
    console.log(ans[i]);
  }
}

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


Measured memory_bytes: 9276
q = int(input())
for i in range(q):
  a,b = map(int,input().split())
  if a == b:
    print(2*a-2)
  else:
    n= (a*b)**0.5
    d = int(n)
    if n.is_integer():
        d -= 1
    ans = d*2-1
    if d*(d+1) >= a*b:
      ans -= 1
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
// const ll MOD = 1000000009;

#define M 1000000007

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> P(n);
    for (auto& p : P) { 
        cin >> p;
    }
    vector<double> D(n);
    for (ll i = 0; i < n; ++i) {
        D[i] = (double)(P[i]+1)/(double)(2);
    }
    ll left = 0; ll right = k - 1;
    double cur = 0;
    for (ll i = left; i <= right; ++i) {
        cur += D[i];
    }
    double res = cur;
    while(right < n-1) {
        //cerr << cur << endl;
        cur -= D[left];
        ++left;
        ++right;
        cur += D[right];
        res = max(res, cur);
    }
    cout << setprecision(17) << res << endl;
}


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

int main(){
  int n,k; cin>>n>>k;
  int num[n];
  int si,re;
  k--;
  for(int i=0;i<n;i++){
    cin>>num[i];
    if(num[i]==1) si=i;
  }
  long long count=0;
  re=si;
  while(re>0){
    re-=k;
    count++;
  }while(si-re<n-1){
    si+=k;
    count++;
  }
  cout<<count<<endl;
}


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

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

    int M1, D1, M2, D2;
    cin >> M1 >> D1;
    cin >> M2 >> D2;
    if (D2 == 1) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import itertools
S=[int(s) for s in list(input())]
op=['+','-']
for (op1, op2, op3) in itertools.product([0,1],[0,1],[0,1]):
  x=S[0]+(1-2*op1)*S[1]+(1-2*op2)*S[2]+(1-2*op3)*S[3]
  if x==7:
    ls=[S[0],op[op1],S[1],op[op2],S[2],op[op3],S[3],'=7']
    print(*ls,sep="")
    break


Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, k;
double dp[100010];
int main() {
	scanf("%d %d", &n, &k);

	for (int i = 1e5; 1 <= i; i--) {
		if (k <= i)
			dp[i] = 1.0;
		else if (k <= i * 2)
			dp[i] = 0.5;
		else
			dp[i] = 0.5 * dp[i * 2];
	}
	if (k == 1)
		printf("1\n");
	else {
		double total = 0;
		for (int i = 1; i <= n; i++)
			total += (1.0 / n) * dp[i];
		printf("%.18lf\n", total);
	}
}

Measured memory_bytes: 896
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int n,k;
    cin >> n >> k;
    int h[n];
    ll c[n] = {};
    inrep(n,h);

    rep(i,1,n){
	if( i-2 < 0){
	    c[i] = c[i-1] + abs(h[i] - h[i-1]);
	}else{
	    ll t = linf,j = 1;
	    rep(l,0,k){
		t = min(t, c[i-j] + abs(h[i] - h[i-j]));
		j++;
		if(i-j < 0)break;
	    }
	    c[i] = t;
	}
    }
    P(c[n-1]);
    return  0;
}


Measured memory_bytes: 1408
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long K, string S) {
    auto runlength = S.group.array;
    if (runlength[0][0] == dchar('0'))
        runlength = tuple(dchar('1'), 0u) ~ runlength;
    if (runlength[$ - 1][0] == '0')
        runlength = runlength ~ tuple(dchar('1'), 0u);
    
    long store;
    long ans;
    twoPointers(
        runlength.length,
        (i, j) {return j - i <= K * 2;},
        (i) {store += runlength[i][1];},
        (i) {store -= runlength[i][1];},
        () {ans = ans.max(store);}
    );

    return ans;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long K;
    K = input.front.to!long;
    input.popFront;

    string S;
    S = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N, K, S);
    else
        solve(N, K, S).writeln;
}


void twoPointers(
    size_t arrayLength,
    bool delegate(size_t, size_t) isValidRange,
    void delegate(size_t) pushFront,
    void delegate(size_t) popBack,
    void delegate() processRange,
) {
    pushFront(0);
    size_t first = 0;
    size_t last = 0;

    bool empty() { return first > last; }
    bool existsNext() { return last + 1 < arrayLength; }

    do {
        while (empty() || (existsNext() && isValidRange(first, last + 1))) {
            pushFront(++last);
        }
        processRange();
        popBack(first++);
        if (first < arrayLength)
            popBack(first++);
    } while (first < arrayLength && existsNext());
}


Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;

struct LowestCommonAncestor {
    size_t n;
    size_t size() const { return n; }
    vector<int> color, parent, depth, topDepth, goUp, visited;
    vector<vector<int>> g;
    LowestCommonAncestor(size_t n_) : n(n_), g(n) {}
    void addEdge(int u, int v){
        g[u].push_back(v); g[v].push_back(u);
    }
    void decomp(int root = 0, int B = 600){
        parent.assign(n, -1); depth.assign(n, 0);
        topDepth.assign(n, 0); goUp.assign(n, -1); visited.assign(n, false);
        vector<int> tord;
        vector<int> q(n+1); int l = 0, r = 0;
        q[r++] = root;
        while(l != r){
            int v = q[l++]; visited[v] = true;
            tord.push_back(v);
            for(int c : g[v]){
                if(!visited[c]){ parent[c] = v; depth[c] = depth[v] + 1; q[r++] = c; }
            }
        }
        swap(color, visited); // ?????¢????????±??????
        color.assign(n, 0);
        int c = 0;
        for(int u : tord){
            if(color[u]) continue;
            c++;
            l = 0, r = 0;
            q[r++] = u;
            for(int i = 0; i < B && l != r; i++){
                int v = q[l++];
                color[v] = c; goUp[v] = parent[u]; topDepth[v] = depth[u];
                for(int c : g[v]) if(!color[c]) q[r++] = c;
            }
        }
    }
    int solve(int u, int v){
        while(color[u] != color[v]){
            if(topDepth[u] > topDepth[v]) u = goUp[u];
            else v = goUp[v];
        }
        while(u != v){
            if(depth[u] > depth[v]) u = parent[u];
            else v = parent[v];
        }
        return u;
    }
};

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

int main(){
    int n;
    cin >> n;
    LowestCommonAncestor g(n);
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int c;
            cin >> c;
            g.addEdge(i,c);
        }
    }
    g.decomp(0);
    int q;
    cin >> q;
    rep(i,q){
        int u,v;
        cin >> u >> v;
        cout << g.solve(u,v) << endl;
    }
}

Measured memory_bytes: 10028
#include<bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    int size = S.size();
    long long up = 0, down = 0, ans = 0;
    for (int i = 0; i < size; ++i) {
        if (S[i] == '<') {
            if (down != 0) {
                ans += up*(up-1)/2 + down*(down-1)/2 + max(up, down);
                up = 0;
                down = 0;
            }
            ++up;
        } else {
            ++down;
        }
    }
    ans += up*(up-1)/2 + down*(down-1)/2 + max(up, down);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 900
/**
 * @file B-DigitalGifts.cpp
 * @author murnana
 * @brief B - Digital Gifts
 * @date 2019-02-24
 * 
 * @copyright Copyright (c) 2019
 * 
 */

#include <iostream>
#include <array>
#include <string>
#include <stdio.h>
using namespace std;

/**
 * @brief Entry point
 * 
 * @return int 
 */
int main()
{
    // 親戚の人数Nを取得
    int N;
    cin >> N;

    double sun = 0.0; // 小遣いの合計
    for (int i = 0; i < N; ++i)
    {
        // 小遣いの値xを取得
        double x;
        cin >> x;

        // 小遣いの種類uを取得
        string u;
        cin >> u;

        // 種類から小遣いの合計を入れる
        if (u == "BTC")
        {
            sun += x * 380000.0;
        }
        else    // JPY
        {
            sun += x;
        }
    }

    cout << sun << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

int solve(int x,int y,int w,int h,int n,int *inx,int *iny){
  int cnt=0;
  rep(i,n){
    int curx=inx[i],cury=iny[i];
    if ( x<=curx && curx<=x+w && y<=cury && cury<=y+h)cnt++;
  }
  return cnt;
}

main(){
  int x,y,w,h;
  int n;
  int te;
  cin>>te;
  while(te--){
    cin>>x>>y>>w>>h;
    cin>>n;
    int inx[n],iny[n];
    rep(i,n)cin>>inx[i]>>iny[i];
    cout << solve(x,y,w,h,n,inx,iny) << endl;
}
}

Measured memory_bytes: 0
from itertools import combinations


def main():
    s, k = open(0).read().split()
    k, l = int(k), len(s)
    tmp = s[:k]
    for i in range(l - k + 1):
        tmp = min(tmp, s[i:i + k])
    res = set()
    for i, j in combinations(range(min(k + 1, l + 1)), 2):
        res.add(tmp[i:j])
    ans = sorted(res)
    print(ans[k - 1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;


int main(void)
{
	int N, x; cin >> N >> x;
	vector<int> a(N); rep(i, 0, N)cin >> a[i];
	lli ans = 0;
	if (a[0] + a[1] > x) {
		int tmp = a[1];
		a[1] = max(0, x - a[0]);
		ans += (tmp - a[1]);
	}
	if (a[0] > x)ans += (a[0] - x);
	rep(i, 2, N) {
		if (a[i - 1] + a[i] > x) {
			int tmp = a[i];
			a[i] = x - a[i - 1];
			ans += (tmp - a[i]);
		}
	}
	cout << ans << endl;

	return 0;
}


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

#define PRIME 1000000007

using namespace std;

char grid[1005][1005];
long int dp[1005][1005];
int main()
{
	int h,w;
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;++i)
	scanf("%s",grid[i]);
	for(int i=h;i>=0;i--)
	{
		for(int j=w;j>=0;j--)
		{
			if(i == h-1 && j == w-1)
			dp[i][j] = 1;
			else if(i == h || j == w)
			dp[i][j] = 0;
			else if(grid[i][j] == '#')
			dp[i][j] = 0;
			else
			dp[i][j] = (dp[i+1][j] + dp[i][j+1]) % PRIME;
		}
	}
	printf("%ld\n",dp[0][0]);
	return 0;
}


Measured memory_bytes: 9088
def insertionSort arr, n, g
    for i in g ... n
        v = arr[i]
        j = i - g
        while j >= 0 && arr[j] > v
            arr[j + g] = arr[j]
            j -= g
            @count += 1
        end
        arr[j + g] = v
    end
end
  
def shellSort arr, n
    @count = 0
  
    g = []
    interval = 1
    begin
        g << interval
        interval = g.last * 2 + 1
    end while interval < n
    g.reverse!
    m = g.length
  
    for i in 0 ... m
        insertionSort(arr, n, g[i])
    end
  
    puts m
    puts g.join(" ")
    puts @count
end
  
n = gets.to_i
arr = Array.new(n)
n.times{|i| arr[i] = gets.to_i}
shellSort(arr, n)
puts arr

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    string a, b, c;
    cin >> a >> b >> c;
    if(a.back() == b.front()){
        if(b.back() == c.front()) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<vector<int>> a(2,vector<int>(n));
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    
    int max=0;
    int sum=0;
    for(int i=0;i<n;i++){
        sum=0;
        bool flag=false;
        for(int j=0;j<n;j++){
            if(j<i){
                sum+=a[0][j];
            }else{
                if(!flag) sum+=a[0][j];
                sum+=a[1][j];
                flag=true;
            }
        }
        if(max<sum){
            max=sum;
        }
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,tmp;

    scanf("%d%d%d",&a,&b,&c);

    if(a>b)
    {
        tmp=a;
        a=b;
        b=tmp;

    }

if(b>c)
{
    tmp=b;
    b=c;
    c=tmp;
}
if(a>b)
{
    tmp=a;
    a=b;
    b=tmp;
}
printf("%d %d %d\n",a,b,c);

    return 0;
}


Measured memory_bytes: 2052
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
#include<numeric>
#include<limits>
#include<type_traits>
using namespace std;

int main(void){
  string S;
  cin >> S;
  string key = "keyence";
  bool is_keyence = true;
  int size_S = S.size();
  int for_conc_num = 0;
  for(int i = 0; i < S.size(); i++){
    if(key[i] != S[i]) break;
    for_conc_num++;//前方が何個一致しているか？
  }
  //前方が合ってない個数だけ後方が合うか？
  for(int i = 0; i < key.size() - for_conc_num; i++){
    if(key[6 - i] != S[size_S - i - 1]){
      is_keyence = false;
      break;
    }
  }
  if(is_keyence){cout << "YES" << endl;}
  else{cout << "NO" << endl;}
  return 0;
}


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

function bsearch(a,x)
	l,r = 1, length(a)
	while l <= r
		m = l+div(r-l,2)
		if a[m] < x
			l = m+1
		else
			r = m-1
		end
	end
	return(l-1)
end

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	a = sort(a)
	m = a[n]
	k = bsearch(a,m/2)
	if k <= 1
		println(m, " ", a[1])
	elseif k >= n-1
		println(m, " ", a[n-1])
	else
		if m/2-a[k] > a[k+1]-m/2
			println(m, " ", a[k+1])
		else
			println(m, " ", a[k])
		end
	end
end

main()


Measured memory_bytes: 122404
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int count = 0;
        for(int i=0; i<s.length()/2; i++) {
            char a = s.charAt(i);
            char b = s.charAt(s.length()-i-1);
            if(a != b) count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 35580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[6100][6100];
const ll M = 998244353;
ll ch(int a,int b) {
	if(b < 0 || b > a) return 0;
	if(b == 0 || b == a) return 1;
	if(dp[a][b] != -1) return dp[a][b];
	ll val = ch(a-1,b-1)+ch(a-1,b);
	if(val >= M) val -= M;
	return dp[a][b] = val;
}
int main() {
	int n,x;
	cin >> n >> x;
	memset(dp,-1,sizeof(dp));
	ll tot = 0;
	for(int i=0;i<x;i++) {
		for(int j=0;j<=x-1-i;j++) {
			tot += ch(i,j)*ch(n,i);
			tot %= M;
		}
	}
	//cout << tot << '\n';
	if(x%2) {
		int st = max(x-1,(x+1)/2);
		for(int i=st;i<=n;i++) {
			tot += ch(n,i);
			tot %= M;
		}
		//cout << tot << '\n';
	}
	for(int i=1;2*i<x-1;i++) {
		for(int j=0;x-1-2*i-j>=0;j++) {
			tot += ch(x-1-2*i-j,j)*ch(n,x-1-j);
			tot %= M;
			//cout << ch(x-1-2*i-j,j) << " * " << ch(n,x-1-j) << "ad\n";
		}
		//cout << tot << '\n';
	}
	tot %= M;
	cout << tot << '\n';
}


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

using namespace std;

const int MAX_N = 100000;

int n, k, a[MAX_N + 1];
int ans;

bool isUsed[MAX_N + 1];

list<int> edge[MAX_N + 1];

int DFS(int v) {
    isUsed[v] = true;

    int d = 1;

    for (list<int>::iterator i = edge[v].begin(); i != edge[v].end(); i++) {
        if (!isUsed[*i]) {
            d = max(d, DFS(*i) + 1);
        }
    }

//    printf("%d %d %d\n", v, a[v], d);

    if (d == k && a[v] != 1) {
        d = 0;

        a[v] = 1;

        ans++;
    }

    return d;
}

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

    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);

        if (i != 1) {
            edge[a[i]].push_back(i);
        }
    }

    ans = -1;

    if (a[1] != 1) {
        a[1] = 1;

        ans++;
    }

    for (int i = 1; i <= n; i++) {
        isUsed[i] = false;
    }

    for (int i = 1; i <= n; i++) {
        if (!isUsed[i]) {
            DFS(i);

            ans++;
        }
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 10112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int  x,p,i,flag=0,j;
    cin>>x;
    for(i=x; 1 ; i++)
    {   bool flag=0;
        p=sqrt(i);
        for(j=2; j<=p; j++)
        {
            if(i%j==0)
            {
                flag=1;
                break;
            }
            if(flag)
                break;
        }
        if(flag)
            continue;
        else
        {
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int x, y;
cin >> x >> y;
if(x==2){
x = 1;
}
else if(x == 4 || x == 6 || x == 9 || x == 11){
x = 2;
}
else{
x = 3;
}

if(y==2){
y = 1;
}
else if(y == 4 || y == 6 || y == 9 || y == 11){
y = 2;
}
else{
y = 3;
}
if(x == y){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define range(i) (i).begin(),(i).end()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
inline constexpr int modpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll LINF=0x1fffffffffffffff;

int main(){
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    if(s[k-1]=='A') s[k-1]='a';
    else if(s[k-1]=='B') s[k-1]='b';
    else s[k-1]='c';
    cout<<s;
}

Measured memory_bytes: 256
using System;
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            int N, K, Q;
            N = int.Parse(str[0]);
            K = int.Parse(str[1]);
            Q = int.Parse(str[2]);

            int[] points = new int[N];
            for (int i = 0; i < N; ++i)
                points[i] = 0;

            int rightN;
            for (int i = 0; i < Q; ++i)
            {
                rightN = int.Parse(Console.ReadLine()); //標準入力
                points[rightN - 1] = points[rightN - 1] + 1;
            }

            for (int i = 0; i < N; ++i)
            {
                if ((Q - points[i]) < K)
                    Console.WriteLine("Yes");//改行付き出力
                else
                    Console.WriteLine("No");//改行付き出力
            }

        }
    }
}

Measured memory_bytes: 15708
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;

int h, w, sx, sy, gx, gy;
vector<string> graph;

int solve() {
  deque<P> deq;
  vector<vector<int>> dis(h, vector<int>(w, -1));
  vector<vector<bool>> visited(h, vector<bool>(w, false));
  deq.push_front(make_pair(sx, sy));
  dis[sx][sy] = 0;
  
  while (!deq.empty()) {
    int cx = deq.front().first;
    int cy = deq.front().second;
    deq.pop_front();
    if (visited[cx][cy]) continue;
    visited[cx][cy] = true;
    vector<P> magic;
    magic.push_back(make_pair(cx, cy));
    
    rep (i, 4) {
      int nx, ny;
      nx = cx + dx[i];
      ny = cy + dy[i];
      if (-1 < nx && -1 < ny && nx < h && ny < w) {
	if (!visited[nx][ny] && graph[nx][ny] == '.') {
	  dis[nx][ny] = dis[cx][cy];
	  deq.push_front(make_pair(nx, ny));
	  magic.push_back(make_pair(nx, ny));
	}
      }
    }

    for (auto v : magic) {
      for (int y = v.second - 2; y <= v.second + 2; y++) {
	for (int x = v.first - 2; x <= v.first + 2; x++) {
	  if (-1 < x && -1 < y && y < w && x < h) {
	    if (!visited[x][y] && graph[x][y] == '.' && dis[x][y] == -1) {
	      dis[x][y] = dis[v.first][v.second] + 1;
	      deq.push_back(make_pair(x, y));
	    }
	  }
	}
      }
    }
  }

  //for (auto v : dis) {
  //  for (auto vv : v) {
  //    cout << vv;
  //  }
  //  cout << endl;
  //}

  return dis[gx][gy];
}

int main() {
  while (cin >> h >> w >> sx >> sy >> gx >> gy) {
    --sx, --sy, --gx, --gy;
    graph.resize(h);
    rep (i, h) cin >> graph[i];
    cout << solve() << endl;
  }
  return 0;
}


Measured memory_bytes: 9644
n,k,q = map(int,input().split())
a = [int(input()) for i in range(q)]
p = [k for i in range(n)]
c = [0 for i in range(n)]

for i in range(q):
    c[a[i]-1] += 1
    
for j in range(n):
    s = p[j] - q + c[j]
    if s > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 9416
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
const val MOD = 1000000007L
const val INF = 2147483647
const val LINF = 9223372036854775807L

fun main(args: Array<String>) {
    solve()
    pw.flush()
}

fun solve() {
    val n = nextInt()
    val d = nextIntList()
    d.sort()

    val one = d[n / 2 - 1]
    val two = d[n / 2]
    println(max(0, two - one))



}


fun println(v: String) {
    pw.println(v)
}

fun print(v: String) {
    pw.print(v)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ").toMutableList()
fun nextIntList(index: Int = 0) = next().split(" ").map { it.toInt() + index }.toMutableList()
fun nextLongList(index: Long = 0L) = next().split(" ").map { it.toLong() + index }.toMutableList()
fun nextDoubleList() = next().split(" ").map { it.toDouble() }.toMutableList()

fun ary(n: Int, init: String = "") = Array(n) { init }
fun intAry(n: Int, init: Int = 0) = IntArray(n) { init }
fun longAry(n: Int, init: Long = 0L) = LongArray(n) { init }
fun doubleAry(n: Int, init: Double = 0.0) = DoubleArray(n) { init }
fun ary2(n: Int, m: Int, init: String = "") = Array(n) { Array(m) { init } }
fun intAry2(n: Int, m: Int, init: Int = 0) = Array(n) { IntArray(m) { init } }
fun longAry2(n: Int, m: Int, init: Long = 0) = Array(n) { LongArray(m) { init } }
fun doubleAry2(n: Int, m: Int, init: Double = 0.0) = Array(n) { DoubleArray(m) { init } }
fun ary3(n: Int, m: Int, k: Int, init: String = "") = Array(n) { Array(m) { Array(k) { init } } }
fun intAry3(n: Int, m: Int, k: Int, init: Int = 0) = Array(n) { Array(m) { IntArray(k) { init } } }
fun longAry3(n: Int, m: Int, k: Int, init: Long = 0L) = Array(n) { Array(m) { LongArray(k) { init } } }
fun doubleAry3(n: Int, m: Int, k: Int, init: Double = 0.0) = Array(n) { Array(m) { DoubleArray(k) { init } } }

fun abs(n: Int): Int = Math.abs(n)
fun abs(n: Long): Long = Math.abs(n)
fun abs(n: Double): Double = Math.abs(n)
fun max(a: Int = -INF, b: Int = -INF, c: Int = -INF, d: Int = -INF, e: Int = -INF): Int = listOf(a, b, c, d, e).max()!!
fun max(a: Long = -LINF, b: Long = -LINF, c: Long = -LINF, d: Long = -LINF, e: Long = -LINF): Long =
    listOf(a, b, c, d, e).max()!!.toLong()

fun min(a: Int = INF, b: Int = INF, c: Int = INF, d: Int = INF, e: Int = INF): Int = listOf(a, b, c, d, e).min()!!
fun min(a: Long = LINF, b: Long = LINF, c: Long = LINF, d: Long = LINF, e: Long = LINF): Long =
    listOf(a, b, c, d, e).min()!!.toLong()


Measured memory_bytes: 53744
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
 
#define INF ((1ll<<60)-233)
#define sqr(x) ((x)*(x))
#define debug puts("wzpkking")
using namespace std;

const int N=5005,mo=1000000007;
vector<int> e[N];
int f[N][N],fac[N];
int tmp[N],sz[N],n;
void dfs(int x,int fa){
	f[x][sz[x]=1]=1;
	for (auto y:e[x]) if (y!=fa){
		dfs(y,x);
		For(i,1,sz[x]) For(j,0,sz[y])
			UPD(tmp[i+j],1ll*f[x][i]*f[y][j]%mo);
		For(i,1,sz[x]+sz[y]) f[x][i]=tmp[i],tmp[i]=0;
		sz[x]+=sz[y];
	}
	for (int i=2;i<=sz[x];i+=2)
		UPD(f[x][0],mo-1ll*f[x][i]*fac[i]%mo);
}
int main(){
	scanf("%d",&n); fac[0]=1;
	for (int i=2;i<=n;i+=2)
		fac[i]=1ll*fac[i-2]*(i-1)%mo;
	For(i,1,n-1){
		int x,y; scanf("%d%d",&x,&y);
		e[x].PB(y); e[y].PB(x);
	}
	dfs(1,0);
	printf("%d\n",(mo-f[1][0])%mo);
}

Measured memory_bytes: 97408
def main():
    N = input()
    cnt = 9
    len_n = len(N)
    if len_n == 1:
        cnt = int(N)
    elif len_n % 2 == 0:
        len_n -= 1
    else:
        cnt += int(N[1:]) + 1
        if int(N[0]) > 1:
            cnt += (int(N[0])-1) * 10 ** (len_n-1)
        len_n -= 2
    while len_n > 1:
        cnt += 10 ** (len_n - 1) * 9
        len_n -= 2
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
 
int main(){
    int countTable[256] = {0};
    char ch;
 
    while((ch = getchar()) != EOF){
                countTable[ch]++;
    }
    for(int i = 97; i <=122;i++)printf("%c : %d\n",i,countTable[i]+countTable[i-32]);
}


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

using namespace std;
const int MAXN=1100;
int H, W;
const long long int MOD = 1e9+7;
char mat[MAXN][MAXN];
int sol[MAXN][MAXN];
long long int dp(){
	if(mat[0][0]!='.')
		return 0;
	sol[0][0]=1;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++){
			if(sol[i][j]!=0){
				if(i<H && mat[i+1][j]=='.')
					sol[i+1][j]+=(sol[i][j]+sol[i+1][j])%MOD;
				if(j<W && mat[i][j+1]=='.')
					sol[i][j+1]=(sol[i][j]+sol[i][j+1])%MOD;
			}
		}
	return sol[H-1][W-1];
}

int main(){
	cin>>H>>W;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			cin>>mat[i][j];
	cout<<dp();
}

Measured memory_bytes: 5632
#include<stdio.h>
int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a == b && a != c)printf("Yes\n");
	else if (a == c && a != b)printf("Yes\n");
	else if (b == c && a != b)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
def main():
    mod = 10**9+7
    fact = [1]*200001
    for i in range(1, 200001):
        fact[i] = fact[i-1]*i % mod

    def inv_n(n, mod=10**9+7): return pow(n, mod-2, mod)
    def nCr(n, r, mod=10**9 +
            7): return inv_n(fact[n-r]*fact[r] % mod, mod)*fact[n] % mod

    n, a, b, c = map(int, input().split())
    ans = 0
    for i in range(n, 2*n):
        j = i*100*inv_n(a+b) % mod
        ans = (ans + j*nCr(i-1, n-1)*(pow(a, n, mod)*pow(b, i-n, mod) +
                                      pow(a, i-n, mod)*pow(b, n, mod))*inv_n(pow(a+b, i, mod))) % mod
    print(ans)


main()


Measured memory_bytes: 42728
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

void Init() {
	std::cin.tie(0); std::ios::sync_with_stdio(false);
	struct Init_caller { Init_caller() { Init(); } }caller;
}

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INT_INF 1<<29
#define LL_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using ppi = pair<pi, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;
using vppi = vector<ppi>;

#pragma endregion

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

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL vmax(vi v, LL n) {
	int MAX = 0;
	f(i, 0, n) {
		MAX = max(MAX, v[i]);
	}
	return MAX;
}

LL vmin(vi v, LL n) {
	int MIN = LL_INF;
	f(i, 0, n) {
		MIN = min(MIN, v[i]);
	}
	return MIN;
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//エラトステネスの篩
void sieve(LL n) {
	vb s(n + 1, true);
	f(i, 2, n + 1) {
		for (int j = 2; i*j <= n; j++) {
			s[i*j] = false;
		}
	}
	cout << "2から" << n << "までの素数" << endl;
	f(i, 2, n + 1) {
		if (s[i]) {
			cout << i << " ";
		}
	}
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}


#pragma endregion 


/*****************************************************************************/
signed main(void) {
	while (1) {
		int n;
		cin >> n;
		if (n == 0)break;
		vi a(n);
		f(i, 0, n) {
			a[i] = i + 1;
		}
		int ans = 0;
		int l = 0, r = 0, sum = 0;
		while (1) {
			while (r < n && sum < n) {
				sum += a[r++];
				if (abs(r-l)!=1&&sum == n) {
					ans++;
				}
			}
			if (sum < n)break;
			sum -= a[l++];
			if (abs(r-l)!=1&&sum == n) {
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>

int size(char *s);

int main() {
	int i, count = 0;
	char S[16];
	char *sp;

	scanf("%s", S);

	sp = &S[0];

	for (i = 0; i < size(sp); i++) {
		if (S[i] == 'o')count++;
	}

	printf(size(sp) - count <= 7 ? "YES\n" : "NO\n");

	return 0;
}

int size(char *s) {
	int n = 0;

	while (*s != '\0') {
		n++;
		s++;
	}

	return n;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n + 1), b(n);
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll ans = 0;
    for (int i = n; i >= 0; i--) {
        if (i == n) {
            if (a[i] < b[i - 1]) {
                ans += a[i];
                b[i - 1] -= a[i];
            } else {
                ans += b[i - 1];
                b[i - 1] = 0;
            }
        } else {
            if (a[i] < b[i]) {
                ans += a[i];
                b[i] -= a[i];
            } else {
                ans += b[i];
                a[i] -= b[i];
                b[i] = 0;
                if (i > 0) {
                    if (a[i] < b[i - 1]) {
                        ans += a[i];
                        b[i - 1] -= a[i];
                    } else {
                        ans += b[i - 1];
                        b[i - 1] = 0;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920
import java.io.*;
import java.util.*;
class Main{
    public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	long n = scan.nextInt();
	long ans = sub(n);
	System.out.println(ans);
    }
    
    public static long sub(long n){
	if(n > 0){
	    return n * sub(n-1);
	}
	else{
	    return 1;
	}
    }
}

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


int main(){             
    int N,K;
    cin >> N >> K;
    string s;
    cin >> s;
    int res = 0;
    int cnt = 0;
    int l = 0;
    for(int r = 0; r < s.length(); r++){
        if(s[r] == '0'){
           if(r == 0 || s[r-1] == '1')cnt++;
        }
        if(cnt > K){
            while(l < s.length() && s[l] == '1') l++;
            while(l < s.length() && s[l] == '0') l++;
            cnt--;
        }
        res = max(res,r-l+1);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
using namespace std;
char* strpick(char *str, int start)
{
	char *result = new char[4];
	for (int i = 0; i < 3; i++)
	{
		result[i] = str[start+i];
	}
	result[3] = '\0';
	return result;
}
int main()
{
	char str[10001];
	char *tmp = new char[4];
	int ioi, joi, i;
	while (cin >> str)
	{
		if (cin.eof()) break;
		ioi = joi = 0;
		for (i = 0; i < signed(strlen(str))-2;)
		{
			if (str[i] == 'I' || str[i] == 'J')
			{
				tmp = strpick(str, i);
				if (strcmp(tmp, "IOI") == 0)
					ioi++, i+=2;
				else if (strcmp(tmp, "JOI") == 0)
					joi++, i+=2;
				else
					i++;
			}
			else
				i++;
		}
		cout << joi << endl << ioi << endl;
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <functional>
typedef long long ll;
using namespace std;

template<class T>
class SegTree{
public:
    int N;
    vector<T> dat;
    T def;
    function<T(T, T)> ope;
    function<T(T, T)> upd;

    SegTree(int _N, T _def, function<T(T, T)> _ope, function<T(T, T)> _upd){
        N = 1;
        while(N < _N) N *= 2;

        def = _def;
        ope = _ope;
        upd = _upd;
        dat.resize(2 * N - 1, def);
    }

    T Query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return def;
        if(a <= l && r <= b) return dat[k];
        else {
            T c1 = Query(a, b, 2 * k + 1, l, (l + r) / 2);
            T c2 = Query(a, b, 2 * k + 2, (l + r) / 2, r);
            return ope(c1, c2);
        }
    }

    T query(int a, int b){
        return Query(a, b, 0, 0, N);
    }

    void update(int k, T x){
        k += N - 1;
        dat[k] = upd(dat[k], x);
        while(k > 0){
            k = (k - 1) / 2;
            dat[k] = ope(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
};

//---------------------------------------------------------------------

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

    SegTree<ll> sg = SegTree<ll>(N, (1LL << 50),
                            [](ll a, ll b){return min(a, b);},
                            [](ll a, ll b){return b;});

    for(int i = 0; i < N; i++){
        sg.update(i, (1LL << 31) - 1);
    }
    vector<ll> ans;

    for(int i = 0; i < Q; i++){
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0){
            sg.update(x, y);
        } else {
            ans.push_back(sg.query(x, y + 1));
        }
    }

    for(ll x : ans){
        cout << x << endl;
    }
    return 0;
}


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

using namespace std;

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

    vector<int> nums(n);
    for(int i = 0; i < n; i++) cin >> nums[i];

    cout << *max_element(nums.begin(), nums.end()) - *min_element(nums.begin(), nums.end()) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  string a;
  cin>>a;
  int b=0,c=0;
  rep(i,a.size()){
    if(a.at(i)=='0')
      c++;
  else
    b++;
    }
  cout<<min(c,b)*2;
}



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

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

    ll ans = 0;
    if (a >= b - 1 || a >= k)
        ans = k + 1;
    else {
        k -= a - 1;
        ans = a + k / 2 * (b - a) + k % 2;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256