akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return x*f;
}
const int N=200010;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll da[2][N],db[2][N],a[N];
int n;ll d;
inline int cmin(ll*num,int x,int y){
	if (num[x]<=num[y]) return x;
	else return y;
}
struct Data{
	int mna[2],mnb[2];
	pair<ll,int> ans;
}T[N<<2];
inline void pushup(int o){
	for (int i=0;i<2;++i){
		T[o].mna[i]=cmin(da[i],T[o<<1].mna[i],T[o<<1|1].mna[i]);
		T[o].mnb[i]=cmin(db[i],T[o<<1].mnb[i],T[o<<1|1].mnb[i]);
	}
	T[o].ans=min(T[o<<1].ans,T[o<<1|1].ans);
	ll tans=da[1][T[o<<1].mna[1]]+db[0][T[o<<1|1].mnb[0]];
	T[o].ans=min(T[o].ans,make_pair(tans,T[o<<1].mna[1]));
	tans=db[1][T[o<<1].mnb[1]]+da[0][T[o<<1|1].mna[0]];
	T[o].ans=min(T[o].ans,make_pair(tans,T[o<<1|1].mna[0]));
}
inline void build(int o,int l,int r){
	if (l==r){
		T[o].ans=make_pair(INF,l);
		T[o].mna[0]=T[o].mna[1]=T[o].mnb[0]=T[o].mnb[1]=l;
		return;
	}
	int mid=(l+r)>>1;
	build(o<<1,l,mid),build(o<<1|1,mid+1,r);
	pushup(o);
}
inline void qset(int o,int l,int r,int x){
	if (l==r){
		da[0][l]=da[1][l]=INF;
		db[0][l]=1ll*l*d+a[l],db[1][l]=-1ll*l*d+a[l];
		return;
	}
	int mid=(l+r)>>1;
	if (x<=mid) qset(o<<1,l,mid,x);
	else qset(o<<1|1,mid+1,r,x);
	pushup(o);
}
int main(){
	n=read(),d=read();
	for (int i=1;i<=n;++i) a[i]=read();
	for (int i=1;i<=n;++i){
		da[0][i]=1ll*i*d+a[i],da[1][i]=-1ll*i*d+a[i];
		db[0][i]=db[1][i]=INF;
	}
	build(1,1,n);
	ll ans=0;
	qset(1,1,n,1);
	for (int i=1;i<n;++i){
		ans+=T[1].ans.first;
		int wh=T[1].ans.second;
		qset(1,1,n,wh);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  int64_t N;
  cin>>N;
  int x=N;
  string t;
  while(x){
   int r=x%(-2);
   if(r<0){r+=2;}
   x-=r;
   x/=(-2);
   t+=(char)('0'+r);
  }
  reverse(t.begin(),t.end());
  if(t==""){t='0';}
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define lli long long int
#define vec2 vector<vector<lli>>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FRE freopen("input.txt","r",stdin);freopen("ans.txt","w",stdout)
#define mp make_pair
#define pll pair <lli,lli>
#define vll vector <lli>
#define pq2 priority_queue<pair<lli,lli>>
#define f first
#define s second
#define pb push_back
#define pf push_front
#define minii LLONG_MAX
#define all(x) x.begin(), x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define ld long double
const long double pi = 3.1415926535898;
#define dec greater<lli>()
const lli mod=1000000007;
//const lli mod=100000000;
using namespace std;
lli lcm (lli a, lli b) {return ((a*b)/__gcd(a,b));}
lli modpower (lli a,lli b)
{
    if(b==0) return 1;
    lli c=modpower(a,b/2)%mod;
    if (b%2) return (((a*c)%mod)*c)%mod;
    else return (c*c)%mod;
}
lli power (lli a,lli b)
{
    if(b==0) return 1;
    lli c=power(a,b/2);
    if (b%2) return (a*c*c);
    else return c*c;
}
bool prime (lli k)
{
    if (k==1||k==0) return 0;
    bool flag=1;
    lli a=sqrt(k);
    for (int i=2;i<=a;i++)
    {
        if (k%i==0)
        {flag=0;break;}
    }
    return flag;
}
lli sieve (int n)
{
    bool qrr[n+1];
    for (int i=0;i<=n;i++)
    qrr[i]=1;qrr[0]=0;qrr[1]=0;
    for (int i=2;i<=n;i++)
    {
        if (qrr[i]==1)
        {
            for (int j=i;j<=n;j+=i)
            {qrr[j]=0;}
        }
    }
    return 0;
}
int main()
{
    lli n;
    cin>>n;
    if (n>=30)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3648
unittest
{
	assert( [ "4 2", "1 1 3 4" ].parse.expand.solve == 11 );
	assert( [ "6 3", "10 10 10 -10 -10 -10" ].parse.expand.solve == 360 );
	assert( [ "3 1", "1 1 1" ].parse.expand.solve == 0 );
	assert( [ "10 6", "1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0" ].parse.expand.solve == 999998537 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], as );
}

auto solve( long k, long[] as )
{
	if( k == 1 ) return 0;
	
	as.sort();
	
	// マイナス値をmodの世界に合わせる
	foreach( ref a; as )
	{
		a = a.normalizeMod;
	}
	
	// 累積和表を作成
	auto ts = new long[ 1 + as.length ];
	foreach( i; 0L .. as.length.signed )
	{
		ts[ i + 1 ] = ts[ i ].addMod( as[ i ] );
	}
	
	// 任意の連続するw個の範囲からk個を選択したときの合計を計算
	auto ans = 0L;
	foreach( w; k .. as.length.signed + 1 )
	{
		auto ma = ts[ $ - 1 ].subMod( ts[ w - 1 ] );
		auto mi = ts[ $ - w ];
		auto f = ma.subMod( mi );
		auto c = ( w - 2 ).combinationMod( k - 2 );
		ans = ans.addMod( f.mulMod( c ) );
	}
	return ans;
}

// マイナス値を補正
auto normalizeMod( long MOD = 10L ^^ 9 + 7 )( long x )
{
	return ( 0 <= x ) ? ( x % MOD ) : ( MOD + x );
}

// 足し算
auto addMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + y ) % MOD;
}

// 引き算
auto subMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + MOD - y ) % MOD;
}

// 掛け算
auto mulMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y % MOD;
}

// 割り算
auto divMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y.powMod!MOD( MOD - 2 ) % MOD;
}

// べき乗
auto powMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	auto a = 1L;
	for( ; 0 < y; y >>= 1 )
	{
		if( y & 1 ) a = a * x % MOD;
		x = x ^^ 2 % MOD;
	}
	return a;
}

// 階乗
auto factorialMod( long MOD = 10L ^^ 9 + 7 )( long x )
{
	static memo = [ 1L ];
	if( memo.length <= x )
	{
		auto i = memo.length;
		memo.length = x + 1;
		for( ; i <= x; i++ ) memo[ i ] = memo[ i - 1 ] * i % MOD;
	}
	return memo[ x ];
}

// 組み合わせ数
auto combinationMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x.factorialMod!MOD.divMod!MOD( y.factorialMod!MOD.mulMod!MOD( ( x - y ).factorialMod!MOD ) );
}


Measured memory_bytes: 8312
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>

using namespace std;
int main() {
	vector<int> v(100,0);
	int n;
	while (cin >> n) {
		v[n - 1]++;
	}

	int max = 0;
	for (int i = 0; i < 100; i++) {
		if (max < v[i]) max = v[i];
	}

	for (int i = 0; i < 100; i++) {
		if (v[i] == max) cout << i + 1 << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<" L-B-W-- "<<x<<" --N-B\n"
#define pb push_back
#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
using namespace std;
typedef long long ll;
typedef double db;
const double pai = acos(-1.0);
const double eps = 1e-8;
const int mod=998244353;
//const int mod=1e9+7;
const int inf=1e9+7;
//const ll inf=0x7f7f7f7f1234abcd;
const int maxn=2e5+10;
inline ll ksm(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;x=x*x%mod;y>>=1;}return res;}
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}
inline ll lcm(ll a,ll b){return a * b / __gcd(a, b);}
int t,n,m,k;
int main() {
    int n;
    cin >> n;
    vector<tuple<bool, int, int, int>> v(n);
    for (auto &e : v) {
    string s;
    cin >> s;
    int l = 0, r = 0;
    for (auto c : s) {
      if (c == '(') {
        l++;
      } else if (l > 0) {
        l--;
      } else {
        r++;
      }
    }
    e = {l <= r, l <= r ? -l : r, l, -r};
    }
    sort(v.begin(), v.end());

    bool valid = true;
    int h = 0;
    //for (auto [a, b, l, r] : v)  cerr << a << ' ' << b << ' ' << l << ' ' << r << endl;
    for (auto [a, b, l, r] : v) {
     //cerr << a << ' ' << b << ' ' << r << ' ' << l << endl;
    if (h < -r) {
      valid = false;
      break;
    }
    h -= -r;
    h += l;
    }
    if (h != 0) valid = false;
    cout << (valid ? "Yes" : "No") << endl;
}


Measured memory_bytes: 18696
import heapq

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
ABS = sorted(AB, key=lambda x: -x[1])
ABSS = sorted(ABS, key=lambda x: x[0])
# print(ABS)
# print(ABSS)

heap = []
ans = 0
chkpos = 0

for i in range(1, M + 1):
  if chkpos < N:
    while ABSS[chkpos][0] <= i:
  #    print(chkpos, len(ABSS))
      heapq.heappush(heap, -1 * ABSS[chkpos][1])
      chkpos += 1
      if chkpos >= N:
        break
  #  print(heap)
    if len(heap) > 0:
      ans -= heapq.heappop(heap)
  else:
    ans -= heapq.heappop(heap)
print(ans)


Measured memory_bytes: 33336
N,K=map(int,input().split())
a=list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
l=[0]
t=0
for i in a:
    t+=i
    l.append(t)
for i in range(N):
    for j in range(i+1,N+1):
        d[l[j]-l[i]]+=1
s=0
for i in range(39,-1,-1):
    t=0
    for j in d.keys():
        if (j>>i)%2:
            t+=d[j]
    if t<K:
        continue
    s+=2**i
    l=[]
    for j in d.keys():
        if (j>>i)%2==0:
            l.append(j)
    for j in l:
        d.pop(j)
print(s)

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

using namespace std;
int hotel[200005];
int jump[200005][20];

int solve(int u,int v)
{
    if(u==v)
        return 0;
    int ans = 0;
    for(int i=17;i>=0;i--)
    {
        if(jump[u][i]<v)
        {
            u = jump[u][i];
            ans+=(1<<i);
        }
    }

    return ans+1;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n,k,q;
    cin>>n;

    hotel[n+1] = 2e9;
    memset(jump,-1,sizeof jump);

    for(int i=1;i<=n;i++)
    {
        cin>>hotel[i];
    }
    cin>>k;
    cin>>q;
    for(int i=1;i<=n;i++)
    {
        int p = upper_bound(hotel,hotel+n+2,hotel[i]+k) - hotel ;
        jump[i][0] = p-1;
    }

    for(int j=1;j<20;j++)
    {
        for(int i=1;i<=n;i++)
        {
            if(jump[i][j-1]!=-1)
                jump[i][j] = jump[jump[i][j-1]][j-1];
        }
    }

    while(q--)
    {
        int u,v;
        cin>>u>>v;
        if(u>v)
            swap(u,v);

        cout<<solve(u,v)<<'\n';
    }

}


Measured memory_bytes: 17280
Scanf.scanf "%d" @@ fun n ->
let l = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
let s, m = Array.fold_left (fun (s, m) x -> s + x, max m x) (0,0) l in
print_endline (if s > 2*m then "Yes" else "No")


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  string S;
  cin >> S;
  rep(i, S.size()){
    if(S[i]==',')S[i] =' ';
    cout << S[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char buf[1048576];
int bufl=sizeof(buf);
char bufr(void){
	if(bufl==sizeof(buf)){
		read(STDIN_FILENO, buf, sizeof(buf));
		bufl=0;
	}
	return buf[bufl++];
}

#define getchar bufr

void rsort_d32(void *base, const int count){
	int32_t *a=base;
	int32_t *b=malloc(count*sizeof(int32_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))+0x80]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }

#define P 1000000007

int k[100001];
int rk[100001];

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}
 
int comb(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[b]%P*rk[a-b]%P;
}

void comb_init(int n){
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	rk[n]=getk(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		rk[i]=((long)rk[i+1])*(i+1)%P;
	}
}

int a[100000];
int main(void){
	int n=nextint();
	int k=nextint();
	for(int i=0; i<n; i++){
		a[i]=nextint();
	}
	rsort_d32(a, n);
	comb_init(n);
	long ans=0;
	for(int i=0; i<=n-k; i++){
		int c = comb(n-i-1, k-1);
		ans=((long)(a[n-i-1]-a[i])*c%P+ans+P)%P;
	}
	printf("%ld\n", ans);
}


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


int main()
{
	int n,count=0;
	cin>>n;
	string s;
	cin>>s;
	for(int i=1;i<s.size();i++)
	{
		if(s[i]!=s[i-1])
			count++;
	}
	cout<<count+1;
}

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

int main(){
  char b;
  cin >> b;
  
  char ans;
  if(b=='A'){
   ans = 'T';
  }else if(b=='C'){
   ans = 'G';
  }else if(b=='G'){
   ans = 'C';
  }else if(b=='T'){
   ans = 'A';
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 256
fn input_c() -> std::io::Cursor<String> {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	std::io::Cursor::new(s.trim().to_owned())
}
 
fn input_vt<T: std::str::FromStr>() -> Vec<T> {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	s.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}
 
fn read_t<T: std::str::FromStr>(r: &mut std::io::Read) -> T {
	use std::io::Read;
	use std::iter::Iterator;
	r.bytes().map(|b| b.ok().unwrap() as char).skip_while(|c| c.is_whitespace() == true).take_while(|c| c.is_whitespace() == false).collect::<String>().parse().ok().unwrap()
}

fn main() {
	let mut c    = input_c();
    let     n    = read_t::<u32>(&mut c);
    let     m    = read_t::<u32>(&mut c);
    let     xs   = input_vt::<u64>();
    let mut heap = std::collections::BinaryHeap::with_capacity(xs.len());
    
    for x in &xs {
    	heap.push(*x);
    }
    
    for _ in 0..m {
    	let x = heap.pop().unwrap() / 2;
    	heap.push(x);
    }
    
    println!("{}", heap.iter().fold(0, |a, x| a + x));
}

Measured memory_bytes: 8444
import std.stdio;
import std.exception;
import std.conv;
import std.container;
import std.algorithm;
import std.functional;
import std.range;
import std.array;

const ulong C = 1000000007;
ulong[100001] fact;
static this() {
    fact[0] = 1;
    foreach (i; 1 .. 100001) {
        fact[i] = fact[i - 1] * i % C;
    }
}

class SegmentTree {
    SegmentTree left, right; 
    SegmentTree parent;
    int from, to;
    int diff;
    ~this() {
        delete left;
        delete right;
    }
    this(SegmentTree parent, int from, int to) {
        //writeln(parent is null);
        this.parent = parent;
        this.from = from;
        this.to = to;
        this.diff = 0;
        if (from + 1 != to) {
            int mid = (from + to + 1) / 2;
            this.left  = new SegmentTree(this, from, mid);
            this.right = new SegmentTree(this, mid, to);
        }
    }
    void add(int from, int to) {
        if (from >= to) return;
        if (this.from == from && this.to == to) {
            diff++;
        } else {
            if (from < left.to) {
                if (to <= left.to) left.add(from, to);
                else left.add(from, left.to);
            } 
            if (right.from < to) {
                if (from <= right.from) right.add(right.from, to);
                else right.add(from, to);
            }
            //left.add(max(from, left.from), min(to, left.to));
            //right.add(max(from, right.from), min(to, right.to));
        }
    }
    int opIndex(ulong index) {
        if (from == index && index + 1 == to) return diff;
        int mid = (from + to + 1) / 2;
        return (index < mid ? left : right).opIndex(index) + diff;
    }
}

void main() {
    int N, R;
    while (readf("%d\n", &N), N) {
        readf("%d\n", &R);
        int[] str = new int[N];
        foreach (int i, ref c; str) c = i;
        foreach (i; 0 .. R) {
            int s, t; readf("%d %d\n", &s, &t);
            s--; t--;
            swap(str[s], str[t]);
        }
        ulong ans = 0;
        auto segtree = new SegmentTree(null, 0, N);
        foreach (i; 0 .. N) {
            ans = (ans + (str[i] - segtree[str[i]]) * fact[N - 1 - i]) % C;
            segtree.add(str[i] + 1, N);
        }
        ans.writeln;
        delete segtree;
        delete str;
    }
}

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

#define INF (1<<25)

#define FOR(i,a,n) for (int i = a; i < n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); \
    })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

int main() {
  string s; cin >> s;
  int k; cin >> k;
  vector<string> a;
  REP(i,s.size()) REP(j,k) if (i+j<s.size()) a.push_back(s.substr(i,j+1));
  whole(sort, a);
  a.erase(whole(unique, a), a.end());
  cout << a[k-1] << endl;
  return 0;
}


Measured memory_bytes: 1660
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline ll getint() {
	ll A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	ll N = getint(), K = getint();

	int B[40] = {};
	rep(i, N) {
		ll A = getint();
		rep(j, 40) {
			B[j] += A >> j & 1;
		}
	}

	int K2[40] = {};
	rep(i, 40) {
		K2[i] = K >> i & 1ll;
	}

	int OK = 0;

	ll dp[41][2] = {};
	rep(i, 41) dp[i][1] = -1;

	for (int i = 39; i >= 0; i--) {
		int kari = N - B[i];
		ll k = (1ll << i);
		if (dp[i + 1][1] != -1) dp[i][1] = max(dp[i][1], dp[i + 1][1] + k * max(B[i], kari));

		if (K2[i]) {
			dp[i][1] = max(dp[i][1], dp[i + 1][0] + k * B[i]);
			dp[i][0] = max(dp[i][0], dp[i + 1][0] + k * kari);
		}
		else {
			dp[i][0] = max(dp[i][0], dp[i + 1][0] + k * B[i]);
		}
	}

	printf("%lld", max(dp[0][0], dp[0][1]));

	Would you please return 0;
}

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

typedef long long ll;

int sum_x(int x)
{
    int sum = 0; // 0で初期化を忘れない。
    while (x > 0)
    {
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main()
{
    int N;
    cin >> N;
    int ans = N;

    for (int i = 1; i < N; ++i)
    {
        int A = i;
        int B = N - i;
        int temp = sum_x(i) + sum_x(B);
        ans = min(temp, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
R = 101
while 1:
	n,S = map(int,raw_input().split())
	if n == 0: break
	r = [0]*R
	for i in range(n):
		r[int(raw_input())] += 1
	ans = 0
	for i in range(R):
		if 2*i > S:
			ans += r[i]*(r[i]-1)/2
		ans += r[i]*sum([r[j] for j in range(max(i+1,S-i+1),R)])
	print ans

Measured memory_bytes: 4516
import java.util.*;


class Main{
  
    
  
	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
     int x = sc.nextInt();
     int y = sc.nextInt();
     int z = sc.nextInt();
     int n = 1; 
      while(x >= n*y + (n+1)*z){
        n++;
    }
     System.out.println(n-1);
	}
}



Measured memory_bytes: 35440
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	for(int i = 0; i < m; ++i){
		cin >> a[i] >> b[i];
	}
	int num[100] = {0};
	for(int i = 0; i < m; ++i){
		num[a[i]]++;
		num[b[i]]++;
	}
	for(int i = 0; i < n; ++i){
		cout << num[i+1] << endl;
	}
	return 0;		
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力]
		int N = sc.nextInt();
		int[] number = new int[N];
		int[] times = new int[number.length];
		int sum = 0;
      
		for(int i=0; i<N; i++){
			number[i] = sc.nextInt();
			while(number[i]%2==0){
				number[i] /= 2;
				times[i]++;
			}
			sum += times[i];
        }
      	
		System.out.println(sum);
	}
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a % 3 ==0 || b % 3 == 0 || (a+b) % 3 ==0){
        cout << "Possible" << endl;
    }
    else cout << "Impossible" << endl;
    
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int n;
    std::string str;
    int max = 0;
    int x = 0;
    std::cin >> n >> str;
    for(auto it : str) {
        x = it == 'I' ? x + 1 : x - 1;
        max = max > x ? max: x;
    }
    std::cout << max;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


class UnionFind{
public:
    UnionFind(int n){
        size = n;
        parent = vector<int>(size,-1);
    }
    int getSize(){return size;}
    int getParentElement(int index){return parent[index];}
    int getGroupSize(int index){return abs(getParentElement(find(index)));}
    bool isSame(int x, int y){return find(x)==find(y);}
    void printParent(){
        for(auto v: parent) {cout << v << " ";}
        cout << endl;
    }
    int find(int x){
        int a = x;
        vector<int> children;
        while(parent[a]>=0){
            children.push_back(a);
            a = parent[a];
        }
        for(auto child: children){parent[child] = a;}
        return a;
    }
    int Union(int x, int y){
        int root_x = find(x);
        int root_y = find(y);
        if(root_x != root_y){
            if(parent[root_x]>=parent[root_y]){
                parent[root_x] += parent[root_y];
                parent[root_y] = root_x;
            }else{
                parent[root_y] += parent[root_x];
                parent[root_x] = root_y;
            }
        }
        return parent[root_x];
    }
private:
    int size;
    vector<int> parent;
};

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

    UnionFind uf(n);
    int a, b;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        a--; b--;
        uf.Union(a,b);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, uf.getGroupSize(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 4884
#include<stdio.h>
#include<stdlib.h>

void swap(int *x,int *y){
  int temp;
  temp=*x;
  *x=*y;
  *y=temp;
}

int main(void){
  int A[100];
  int i,j,N,C,mini;
  int p,q;
  C=0;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<N;i++){
    mini=i;
    for(j=i;j<N;j++){
      if(A[j]<A[mini]){
        mini=j;
      }
    }    p=A[i];
    q=A[mini];
    if (p>q)C++;
    swap(&p,&q);
    A[i]=p;
    A[mini]=q;
  }
  for(i=0;i<N;i++){
    if(i!=0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",C);
  return 0;
}

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

int M[500][500];
struct Point {
    int y;
    int x;
};
vector<Point> A;
vector<Point> B;

int main() {
    int H, W; cin >> H >> W;
    rep(i, H){
        rep(j, W){
            cin >> M[i][j];
        }
    }
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W-1; j++){
            if(M[i][j] % 2 == 1){
                M[i][j+1]++;
                int y = i+1;
                int x = j+1;
                Point p = {y, x};
                A.push_back(p);
                Point p2 = {y, x+1};
                B.push_back(p2);
            }
        }
    }

    for (int i = 0; i < H-1; i++){
        if(M[i][W-1] % 2 == 1){
            M[i+1][W-1]++;
            int y = i+1;
            int x = W;
            Point p = {y, x};
            A.push_back(p);
            Point p2 = {y+1, x};
            B.push_back(p2);
        }
    }

    int N = A.size();
    cout << N << endl;
    rep(i, N){
        cout << A[i].y << " " << A[i].x << " " << B[i].y << " " << B[i].x << endl;
    }

    return 0;
}

Measured memory_bytes: 5228
import sys
import math
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
aint = lambda: int(input())
ints = lambda: list(map(int, input().split()))
is_even = lambda x: True if x%2==0 else False
 
a,b,c,d = ints()
Yes(math.ceil(a/d)>=math.ceil(c/b))

Measured memory_bytes: 9476
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
#include <set>
#include <queue>
#include <climits>
#include <limits>
#include <map>

#define ll long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
#define mp(A, B) make_pair(A, B)
#define pb push_back
#define fu(A, B, C) for(ll (A) = (B); (A) < (C); (A)++)
#define fu0(A, B) fu((A), 0, (B))
#define fd(A, B, C) for(ll (A) = (B); (A) >= (C); (A)--)
#define mem(A, B) memset((A), (B), sizeof((A)))
#define v(A, B, C) vector<ll> (A)((B), (C));
#define v0(A, B) v((A), (B), 0);


using namespace std;

typedef pair<int, int> pi;

void perform() {
  int n, k; cin >> n >> k;
  int sum = 0;
  fu0(i, k) {
    int t; cin >> t;
    sum += t;
  }
  if (sum > n) cout << -1 << endl;
  else cout << n - sum << endl;
}

/*
int n; cin >> n;
cout << (2 * M_PI * n) << endl;
*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1; //cin >> t;
  fu0(i, t) {perform();}
}


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

int main() {
  int x,y,z;
  cin >> x >> y >> z; 
  int a=0,b=0;
  if(x == 5){
    a++;
  }
  else if(x==7){
    b++;
  }
    if(y == 5){
    a++;
  }
  else if(y==7){
    b++;
  }
    if(z== 5){
    a++;
  }
  else if(z==7){
    b++;
  }
  
  if(a == 2 && b == 1){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#素因数分解して列挙する関数、約数列挙ではない！
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

N = int(input())
print('{}:'.format(N),end=' ')
print(*factorize(N))


Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<pair<int, int>> g[100];
int N;
int dfs(int n, int from, int (*f)(int, int))
{
  int res = 0;
  for(int i = 0; i < g[n].size(); i++)
  {
    auto e = g[n][i];
    if(e.second == from || g[e.second].size() == 1)
      continue;
    res = f(res, dfs(e.second, n, f) + e.first * 2);
  }
  return res;
}

int max(int a, int b)
{
  return a > b ? a : b;
}

int add(int a, int b)
{
  return a + b; 
}

int main()
{
  while(1)
  {
    cin >> N;
    if(!N)
      break;
    for(int i = 0; i < N; i++)
      g[i].clear();
    for(int i = 0; i < N - 1; i++)
    {
      int a, b, t;
      cin >> a >> b >> t;
      a--; b--;
      g[a].push_back(make_pair(t, b));
      g[b].push_back(make_pair(t, a)); 
    }
    for(int i = 0; i < N; i++)
      sort(g[i].begin(), g[i].end());
    cout << dfs(0, -1, add) - dfs(0, -1, max) / 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include<stdio.h>
int main(){
	int g[10]={1,2,4,8,16,32,64,128,256,512};
	int a,n;
	for(;;){
		int low[10]={0},f=0;
		if(scanf("%d",&n) == EOF){break;}
		for(a=0;a<10;a++){
			if(n%2 == 1){low[a] = 1;}
			n=n/2;
		}
		for(a=0;a<10;a++){
			if(low[a] == 1){
				if(f == 0){printf("%d",g[a]);f = 1;}
				else if(f == 1){printf(" %d",g[a]);}
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    string s;
    cin >> s;
    cout << count(s.begin(), s.end(), '1') << endl;    

    return 0;
}



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

using namespace std;

int N, L, x[200009], y[200009];
long long ans = 0, sx[200009], sy[200009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &L, &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &x[i]), sx[i] = sx[i - 1] + x[i];
ans = max (x[N], L - x[N]);
for (int i=1; i<=N; i++)
    y[i] = L - x[N + 1 - i], sy[i] = sy[i - 1] + y[i];
for (int k=1,p=N-1; k<N; k++,p--)
{
    long long maxx = x[k], maxy = y[p];
    int l = min (k - 1, p - 1);
    maxx += 2LL * (sx[k - 1] - sx[k - 1 - l] + sy[p] - sy[p - l - 1]);
    l = min (k - 1, p - 1);
    maxy += 2LL * (sx[k] - sx[k - l - 1] + sy[p - 1] - sy[p - 1 - l]);
    long long curr = max (maxx, maxy);
    ans = max (ans, curr);

    maxx = x[k], maxy = y[p];
    l = min (k - 1, p);
    maxx += 2LL * (sx[k - 1] - sx[k - 1 - l] + sy[p] - sy[p - l]);
    l = min (k, p - 1);
    maxy += 2LL * (sx[k] - sx[k - l] + sy[p - 1] - sy[p - 1 - l]);
    curr = max (maxx, maxy);
    ans = max (ans, curr);
}
printf ("%lld\n", ans);
return 0;
}


Measured memory_bytes: 4992
n = int(input())
s = ["0"]*n
dict = {}
for i in range(n):
    s[i] = input()
    if s[i] in dict:
        dict[s[i]] += 1
    else:
        dict[s[i]] = 1

m = int(input())
t = ["0"]*m
for i in range(m):
    t[i] = input()
    if t[i] in dict:
         dict[t[i]] -= 1
    else:
         dict[t[i]] = -1
    if dict[t[i]] < 0 :
         dict[t[i]] = 0
print(max(dict.values()))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define R register
using namespace std;
const int N =2e6+200;
template <class Ruby_Rose> inline void read(Ruby_Rose &x)
{
 	x=0;
	char ch=getchar(), w=0;
	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
	x=w?-x:x;
}
char s[N];
int main()
{
	scanf("%s", s+1);
	if(s[3]==s[4] && s[5]==s[6])printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, Integer> factoringN = new HashMap<>();
        for (int i = 2; i <= n; i++) {
            int num = i;
            for (int j = 2; j <= 10 ; j++) {
                while (num % j == 0) {
                    num /= j;
                    add(factoringN, j);
                }
            }
            if(num != 1) {
                add(factoringN, num);
            }
        }
        long over4 = factoringN.values().stream().filter(integer -> integer >= 4).count();
        long over2 = factoringN.values().stream().filter(integer -> integer == 2 || integer == 3).count();
        long over14 = factoringN.values().stream().filter(integer -> integer >= 14).count();
        long over4_14 = factoringN.values().stream().filter(integer -> integer >= 4 && integer < 14).count();
        long over24 = factoringN.values().stream().filter(integer -> integer >= 24).count();
        long over2_24 = factoringN.values().stream().filter(integer -> integer >= 2 && integer < 24).count();
        long over74 = factoringN.values().stream().filter(integer -> integer >= 74).count();
        System.out.println(over4 * (over4 - 1) * (over2 + over4 - 2) / 2 + over14 * (over4_14 + over14 - 1) + over24 * (over2_24 + over24 -1) + over74);
    }

    private static void add(Map<Integer, Integer> m, int i) {
        if(m.containsKey(i)) m.put(i, m.get(i) + 1);
        else m.put(i, 1);
    }
}

Measured memory_bytes: 28756
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <set>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 100000 + 5;

int n, m;
char s[maxn];

int main() {
  scanf("%d%d%s", &n, &m, s);
  int p = n;
  vector<int> ans;
  while (p) {
    int len = p <= m ? p : m;
    for (; len > 0; len--) {
      if (s[p - len] == '0') break;
    }
    if (len == 0) return puts("-1"), 0;
    ans.push_back(len);
    p -= len;
  }
  reverse(begin(ans), end(ans));
  for (int x: ans) printf("%d ", x);
  return 0;
}

Measured memory_bytes: 1020
package main

import (
	"bufio"
	"fmt"
	"os"
)

const SPACE = '.'
const BLOCK = '#'

type Point struct {
	x int
	y int
	d int
}

type Queue []Point

func (q *Queue) push(x Point) {
	*q = append(*q, x)
}

func (q *Queue) pop() Point {
	x := (*q)[0]
	*q = (*q)[1:]
	return x
}

func (q *Queue) isEmpty() bool {
	return len(*q) == 0
}

var dx = []int{-1, 0, 1, 0}
var dy = []int{0, 1, 0, -1}
var sc = bufio.NewScanner(os.Stdin)

func main() {
	r := bufio.NewReader(os.Stdin)

	var h, w int
	fmt.Fscan(r, &h)
	fmt.Fscan(r, &w)

	grid := make([]string, h)

	spaceCnt := 0
	for i := 0; i < h; i++ {
		fmt.Fscan(r, &grid[i])
		for j := 0; j < w; j++ {
			if grid[i][j] == SPACE {
				spaceCnt++
			}
		}
	}
	spaceCnt-- // without start point

	seen := make([][]bool, h)
	for i := range seen {
		seen[i] = make([]bool, w)
	}

	que := Queue{}
	que.push(Point{x: 0, y: 0})
	d := 0
	for !que.isEmpty() {
		p := que.pop()
		if p.x == w-1 && p.y == h-1 {
			d = p.d
			break
		}

		for i := 0; i < 4; i++ {
			nx := p.x + dx[i]
			ny := p.y + dy[i]
			if 0 <= nx && nx < w && 0 <= ny && ny < h && grid[ny][nx] != BLOCK && !seen[ny][nx] {
				seen[ny][nx] = true
				que.push(Point{x: nx, y: ny, d: p.d + 1})
			}
		}
	}
	if d > 0 {
		fmt.Println(spaceCnt - d)
	} else {
		fmt.Println(-1)
	}
}


Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <set>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Point {
  int x;
  int y;
  int type;
  Point() {;}
  Point(double x, double y, int type) : x(x), y(y), type(type) {;}
  bool operator<(const Point &rhs) const {
    if (fabs(y - rhs.y) > EPS) { return y < rhs.y; }
    if (fabs(x - rhs.x) > EPS) { return x < rhs.x; }
    return false;
  }
};

struct Event {
  int x;
  Point p;
  int in;
  Event() {;}
  Event(int x, Point p, int in) : x(x), p(p), in(in) {;}
  bool operator<(const Event &rhs) const {
    if (x != rhs.x) { return x < rhs.x; }
    return in > rhs.in;
  }
};

inline int square(int x) { return x * x; }

inline int dist2(const Point &a, const Point &b) {
  return square(a.x - b.x) + square(a.y - b.y);
}

int an, bn, n;
int r;
Event event[500000];

int PlaneSweep() {
  int ans = 0;
  set<Point> open;
  REP(iter, n) {
    Event &e = event[iter];
    Point &p = e.p;
    if (e.in) {
      set<Point>::iterator lower = open.lower_bound(Point(0, p.y - 4.0 * r - 1, 0));
      set<Point>::iterator upper = open.upper_bound(Point(0, p.y + 4.0 * r + 1, 0));
      for (set<Point>::iterator it = lower; it != upper; it++) {
        if (dist2(*it, p) <= 16.0 * r * r) {
          ans += p.type ^ it->type;
        }
      }
      open.insert(p);
    } else {
      open.erase(open.find(p));
    }
  }
  return ans;
}

int main() {
  while (scanf("%d %d %d", &an, &bn, &r), an|bn) {
    n = (an + bn) * 2;
    REP(i, an) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * i + 0] = Event(x - 2 * r, Point(x, y, 0), 1);
      event[2 * i + 1] = Event(x + 2 * r, Point(x, y, 0), 0);
    }
    REP(i, bn) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * an + 2 * i + 0] = Event(x - 2 * r, Point(x, y, 1), 1);
      event[2 * an + 2 * i + 1] = Event(x + 2 * r, Point(x, y, 1), 0);
    }
    sort(event, event + n);
    int ans = PlaneSweep();
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 8752
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define mp make_pair
#define P pair<int,int>
#define ri register int
#define rb register bool
#define rc register char
#define t(i) edge[i].to
#define w(i) edge[i].wei
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
#define e(i,x) for(ri i=head[x];i;i=edge[i].nxt)

const int N=2e6+1000;
int n,a[N],f[N],cnt[N],as,st,S,x[N];

il int read()
{
	rc ch=gc;ri x=0;rb y=1;
	while(ch!='-' && (ch<'0' || ch>'9'))ch=gc;
	if(ch=='-')ch=gc,y=0;
	while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
	return y?x:-x;
}

int main()
{
	n=read();rp(i,1,n-1){ri t1=read()+1,t2=read()+1,z=read();a[t1]^=z;a[t2]^=z;}rp(i,1,n)++cnt[a[i]];
	rp(i,1,15)as+=cnt[i]/2,st|=(cnt[i]&1)<<(i-1);
	S=(1<<15)-1;
	rp(i,1,S)f[i]=f[i>>1]+(i&1);
	rp(i,1,S)--f[i];rp(i,1,S)rp(j,0,14)if((i>>j)&1)x[i]^=(j+1);
	rp(i,1,S)if(!x[i])for(ri j=(i-1)&i;j;j=(j-1)&i)if(!x[j])f[i]=min(f[i],f[j]+f[i^j]);
	printf("%d",as+f[st]);
	return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int tak = (c + b - 1) / b;
    int aok = (a + d - 1) / d;
    if (tak <= aok)
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,d[200001][70];
ll k;

int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,n){
		cin>>d[i][0];
		d[i][0]--;
	}
	forn(j,1,65){
		rep(i,n){
			d[i][j]=d[d[i][j-1]][j-1];
		}
	}
	int now=0;
	int b=0;
	while(k){
		if(k%2){
			now=d[now][b];
		}
		b++;
		k/=2;
	}
	cout<<now+1;
	re 0;
}


Measured memory_bytes: 58288
#define _USE_MATH_DEFINES
#include <complex>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
	double current_angle_in_degree = 0;
	complex<double> current_position = 0;

	int input_distance = 0, input_angle_in_degree = 0;
	while (scanf("%d,%d", &input_distance, &input_angle_in_degree) == 2) {
		if (input_distance == 0 && input_angle_in_degree == 0) {
			break;
		}
		double angle_in_radian = current_angle_in_degree * M_PI / 180.0;
		current_position += static_cast<double>(input_distance)
			* complex<double>(cos(angle_in_radian), sin(angle_in_radian));
		current_angle_in_degree += input_angle_in_degree;
	}

	printf("%d\n%d\n",
		 static_cast<int>(current_position.imag()),
		 static_cast<int>(current_position.real()));

	return 0;
}

Measured memory_bytes: 1032
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int MOD=31;
int main()
{
	int n;
	cin>>n;
	string s;
	char ch='#';
	bool Y=true;
	map<ull,bool> M;
	for(int i=0;i<n;i++){
		cin>>s;
		
		if(ch!='#'&&s[0]!=ch){
			Y=false;
		}
		 ull x=0;
		for(int i=0;i<s.length();i++){
			x=x*MOD+s[i]-'a';
		}
		if(M[x]) Y=false;
		M[x]=true;
		ch=s[s.length()-1];
	}
	cout<<(Y?"Yes":"No")<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    int n;
    cin >> n;
    vec<double> v(n);

    for (auto& e : v)
        cin >> e;

    sort(v.begin(), v.end());

    auto ans = accumulate(v.cbegin(), v.cend(), v.front(), [](auto init, auto x) {return (init + x) / 2.0; });

    cout << fixed << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def digit(n):
    ans=0
    for i in n:
        ans += int(i)
    return ans
    
def iszero(n):
    if n[0]!='1': return False
    for i in n[1:]:
        if i!='0': return False
    return True
    
N=input()

if iszero(N):
    ans = 10
else:
    ans = digit(N)
    
print(ans)

Measured memory_bytes: 2940
#include<stdio.h>

typedef long long int lli;


void mult(lli A[][105],lli B[][105],lli C[][105],int n,int m,int l){
	int i,j,k;
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			lli s=0;
			for(k=0;k<m;k++){
				s += A[i][k]*B[k][j];
			}
			C[i][j]=s;
		}
	}
}


lli A[105][105];
lli B[105][105];
lli C[105][105];



int main(){
	int n,m,l;
	scanf("%d%d%d",&n,&m,&l);
	int i,j,k;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%lld",&A[i][j]);
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			scanf("%lld",&B[i][j]);
		}
	}
	
	mult(A,B,C,n,m,l);
	
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			printf("%lld%c",C[i][j],j+1==l?'\n':' ');
		}
	}
	
	return 0;
}

Measured memory_bytes: 1924