akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e3;
const int M=2e3+88;
const int mod=1e9+7;
int n,a[M*100],b[M*100],f[N+99][N+99],fac[M*10+99],da;
int ksm(int x,int y){
	int base=1;
	while(y){
		if(y&1)base=(1ll*base*x)%mod;
		x=(1ll*x*x)%mod;
		y>>=1;
	}return base;
}
int C(int n,int m){
	return 1ll*fac[n]*ksm(fac[m],mod-2)%mod*ksm(fac[n-m],mod-2)%mod;
}
signed main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
	}fac[0]=1;
	for(int i=1;i<=M*5;i++){
		fac[i]=1ll*fac[i-1]*i%mod;
	}
	for(int i=1;i<=n;i++){
		f[M-a[i]][M-b[i]]++;
	}
	for(int i=1;i<=N;i++){
		for(int k=1;k<=N;k++){
			f[i][k]=(f[i][k]+f[i-1][k]+f[i][k-1])%mod;
		}
	}
	for(int i=1;i<=n;i++){
		da=(da+f[a[i]+M][b[i]+M])%mod;
		da=((da-C(2*(a[i]+b[i]),a[i]*2)%mod)%mod+mod)%mod;
	}
	da=(1ll*da*ksm(2,mod-2))%mod;
	cout<<da;
}

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

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

int main()
{
    string S, pre_S = "", after_S = "";
    long Q;
    cin >> S >> Q;
    bool b = false;
    for (long i = 0; i < Q;i++)
    {
        int T = 0;
        cin >> T;
        if(T == 1)
        {
            if(b == true)
            {
                b = false;
            }
            else if(b == false)
            {
                b = true;
            }
            continue;
        }
        else if(T == 2)
        {
            int F = 0;
            string C = "";
            cin >> F >> C;
            if(F == 1)
            {
                if(b == true)
                {
                    after_S = after_S + C;
                }
                else if(b == false)
                {
                    pre_S = C + pre_S;
                }
            }
            else if(F == 2)
            {
                if(b == true)
                {
                    pre_S = C + pre_S;
                }
                else if(b == false)
                {
                    after_S = after_S + C;
                }
            }
        }
        else
        {
            cout << "Strange" << endl;
        }
    }

    if (b == true)
    {
        for (int i = after_S.size()-1;i >= 0 ;i--)
        {
            cout << after_S[i];
        }
        for (int i = S.size()-1;i >= 0 ;i--)
        {
            cout << S[i];
        }
        for (int i = pre_S.size()-1;i >= 0 ;i--)
        {
            cout << pre_S[i];
        }
        cout << endl;
        return 0;
    }

    cout << pre_S << S << after_S << endl;
}

Measured memory_bytes: 1160
// ==============================
//  author: memset0
//  website: https://memset0.cn
//  date: 2018.08.06 14:06:24
// ==============================
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int len;
char s[110];

int main() {
	scanf("%s", s), len = strlen(s);
	for (int i = 0; i < len; i++)
		if (s[i] == 'C')
			for (int j = i + 1; j < len; j++)
				if (s[j] == 'F') {
					printf("Yes\n");
					return 0;
				}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define mpi map<int,int>
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define str stringstream
using namespace std;
ll ans,cnt=10;
int main() {
	rep(i,0,5){
		int a;
		cin>>a;
		ans+=(a+9)/10*10;
		if(cnt>a%10&&a%10!=0) cnt=a%10;
	}
	cout<<ans+cnt-10;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>

using namespace std;

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

    if (n % (2*d + 1) == 0) printf("%d\n", n / (2*d + 1));
    else                    printf("%d\n", n / (2*d + 1) + 1);
}

Measured memory_bytes: 1732
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <cstring>

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<int> adj[N];
ll dp[N][2];

ll dfs(int v, bool white, int par = -1) {
    if (dp[v][white] != -1) return dp[v][white];
    ll ans = 1;
    for (int u : adj[v]) if (u != par) {
        if (white) ans = mult(ans, add(dfs(u, white, v), dfs(u, !white, v)));
        else ans = mult(ans, dfs(u, !white, v));
    }
    return dp[v][white] = ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    rep (i, 0, n-1) {
        int u, v;
        cin >> u >> v; u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    memset(dp, -1, sizeof(dp));
    cout << add(dfs(0, 0), dfs(0, 1)) << endl;
    return 0;
}

Measured memory_bytes: 15616
#include <stdio.h>

int main(void)
{
  int a, b, c, d, p, rate, x, y;

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

  x = a * p;

  y = b;
  if(p > c)
    y += (p - c) * d;

  if(x > y)
    printf("%d\n", y);
    else
      printf("%d\n", x);

  return 0;
}

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

int main(){
  long K;
  cin >>K;
  
  long long lun[110000]={0,1,2,3,4,5,6,7,8,9};
  
  int cnt=9;
  int last = 0;
  int pos = 1;
  
  while(cnt<K){
    //cout <<"lun:" <<lun[pos]%10 <<" last" <<last <<endl;
    if(abs(lun[pos]%10 - last)<=1){
      cnt++;
      lun[cnt]=lun[pos]*10+last;
      //cout << lun[cnt] <<endl;
    }
    last++;
    if(last == 10){
      last=0;
      pos++;
    }
  }
  cout <<lun[K] <<endl;
  
}


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

int main(){
	ull n,tmp,tmp2,check1 = 0,check2 = 0,memo = 1000000;
	cin >> n;
	rep(i,1,sqrt(n)+1){
		check1 = 0;
		check2 = 0;
		tmp = i;
		if(n % tmp == 0){
			tmp2 = n / tmp;
			while(tmp){
				check1++;
				tmp /= 10;
			}
			while(tmp2){
				check2++;
				tmp2 /= 10;
			}
			
			memo = min(max(check2,check1),memo);
		}
	}
	
	cout << memo << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
 
int main(){
  ll N,K;
  cin>>N>>K;
  VL A(N);
  rep(i,N) cin>>A[i];
  if(K==0){
    ll sum=0;
    rep(i,N) sum+=A[i];
    cout<<sum<<endl;
    return 0;
  }
  VL X(40);
  rep(i,40) X[i]=(K>>i)&1;
  ll keta;
  rep(i,40){
    if(X[39-i]){
      keta=40-i;
      break;
    }
  }
  VVL Y(N,VL(40));
  rep(i,N) rep(j,40) Y[i][j]=(A[i]>>j)&1;
  int F=1;
  VL ans(40);
  rep(i,40){
    int cnt=0;
    rep(j,N) cnt+=Y[j][39-i];
    if(cnt*2>N){
      ans[39-i]=0;
      if(X[39-i]) F=0;
    }else if(cnt*2<N){
      if(F) ans[39-i]=X[39-i];
      else ans[39-i]=1;
    }else{
      if(F){
        if(X[39-i]){
          ans[39-i]=0;
          F=0;
        }else ans[39-i]=0;
      }else ans[39-i]=0;
    }
  }
  ll Z=0;
  VL Q(40);
  Q[0]=1;
  rep(i,39) Q[i+1]=Q[i]*2;
  rep(i,40) Z+=Q[i]*ans[i];
  ll B=0;
  rep(i,N) B+=Z^A[i];
  cout<<B<<endl;
}

Measured memory_bytes: 36224
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int x, y;
    int t;
 
    for (;;) {
        scanf("%d%d", &x, &y);
        if (x == 0 && y == 0) break;
        if (x > y) t = x, x = y, y = t;
        printf("%d %d\n", x, y);
    }
    return 0;
}


Measured memory_bytes: 2140
import numpy as np

N, K=map(int, input().split())
A=np.sort(list(map(int, input().split())))

p=np.sum(A>0)
q=np.sum(A<0)
Z=N-p-q
if p>0:
  AP=A[-p:]
else:
  AP=[]
if q>0:
  AN=A[:q]
else:
  AN=[]

b=(N-Z)*Z+Z*(Z-1)//2
a=p*q

if K<=a:
  x=AP[-1]*AN[0]-1
  y=AP[0]*AN[-1]
  while y-x>1:
    tmp=(y+x)//2
    counter=np.searchsorted(AN, tmp//AP, side='right').sum()
    if counter<K:
      x=tmp
    else:
      y=tmp
  print(y)
elif K<=a+b:
  print(0)
else:
  x=0
  y=10**18
  K=K-a-b
  if q<=1:
    while y-x>1:
      tmp=(y+x)//2
      counter=(np.searchsorted(AP, tmp//AP, side='right').sum()-np.searchsorted(AP, int(pow(tmp, 1/2)), side='right'))//2
      if counter<K:
        x=tmp
      else:
        y=tmp
    print(y)
    exit()
    
  AN=AN[::-1]
  AN=-AN
  
  if p<=1:
    while y-x>1:
      tmp=(y+x)//2
      counter=(np.searchsorted(AN, tmp//AN, side='right').sum()-np.searchsorted(AN, int(pow(tmp, 1/2)), side='right'))//2
      if counter<K:
        x=tmp
      else:
        y=tmp
    print(y)
    exit()
    
  while y-x>1:
    tmp=(y+x)//2
    counter1=(np.searchsorted(AP, tmp//AP, side='right').sum()-np.searchsorted(AP, int(pow(tmp, 1/2)), side='right'))//2
    counter2=(np.searchsorted(AN, tmp//AN, side='right').sum()-np.searchsorted(AN, int(pow(tmp, 1/2)), side='right'))//2
    counter=counter1+counter2
    if counter<K:
      x=tmp
    else:
      y=tmp
  print(y)

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    bool flag=true;
    ll ans=1,sum=0;

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

    while(n > k-1){
        n /= k;
        ++ans;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
read = input
def read_numbers():
    a = read().split(' ')
    a = list(map(int, a))
    return a
[x,y,z,K] = read_numbers()
memo = [[set() for i in range(y)]for i in range(x)]
X = read_numbers()
Y = read_numbers()
Z = read_numbers()
X.sort()
X.reverse()
Y.sort()
Y.reverse()
Z.sort()
Z.reverse()
import queue
def cal(px, py,pz):
    return X[px]+Y[py]+Z[pz]
memo[0][0].add(0)
cnt = 0
pq = queue.PriorityQueue()
# print(X,Y,Z)
pq.put((-cal(0,0,0) ,0,0,0))
while(cnt < K):
#     print(cnt)
    cost , px, py, pz = pq.get(timeout=1)
#     print(cost, px, py,pz)
    for i in range(px-1, px + 2):
        for j in range(py-1, py + 2):
            for k in range(pz-1, pz + 2):
                if (i >= 0 and i < x and 
                    j >= 0 and j < y and 
                    k >=0 and k < z and
                    k not in memo[i][j]
                   ):
                    memo[i][j].add(k)
                    pq.put((-cal(i,j,k),i,j,k))
    print(-cost)
    cnt = cnt + 1



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

int main() {
	long long ans=0;
	
	long long N , x;
	cin >> N >> x;
	
	long long a[N];
	long long b[N-1]={0};
	for(int i=0; i<N; i++){
		cin >> a[i];
		if(i<N-1)b[i]+=a[i];
		if(i>0)b[i-1]+=a[i];
	}
	
	for(int i=0; i<N-1; i++){
		b[i]-=x;
	}
	
	for(int i=0; i<N-1; i++){
		if(b[i]>0){
		if(b[i]>=a[i+1]){
			ans+=b[i];
			if(i<N-2)b[i+1]-=a[i+1];
		}else{
			ans+=b[i];
			if(i<N-2)b[i+1]-=b[i];
		}
		}

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

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

using namespace std;

using int64 = long long;

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

  int n;
  cin >> n;
  vector<int64> as(n), bs(n);
  for (int i = 0; i < n; i++) {
    cin >> as[i];
    cin >> bs[i];
  }

  int64 inc = 0;
  for (int i = n - 1; i >= 0; i--) {
    int64 x = as[i] + inc;
    int64 y = (x + bs[i] - 1) / bs[i] * bs[i];
    inc += y - x;
  }
  cout << inc << endl;
}

Measured memory_bytes: 1792
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
N = lines.shift() * 1
lines.pop()
c = lines.map(x => x.split(' ').map(y => y * 1))
d = []
r = 1
p = 2
for (i=0;i<N-1;i++) {
    for (j=i+1;j<N;j++) {
        d.push(Math.sqrt(Math.pow(c[i][0] - c[j][0], 2) + Math.pow(c[i][1] - c[j][1], 2)))
    }
    r *= i + 2
    p *= i + 1
}
sum = 0
for (i=0;i<d.length;i++) {
    sum += d[i] * p
}
console.log((sum / r).toFixed(10))

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl
#define COUT(x) cerr<<#x<<" = "; cout<<(x)<<endl
#define PRINT(x) cout<<(x)<<endl

struct edge { int to, cost; };

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

signed main()
{
   int H, W; cin >> H >> W;
   V<string> A(H);
   map<char,int> cnt;
   for (int i = 0; i < H; i++) {
      cin >> A[i];
      for (int j = 0; j < W; j++) {
         cnt[A[i][j]]++;
      }
   }

   if (cnt['#'] != H+W-1) {
      PRINT("Impossible");
      return 0;
   }

   for(int i = 0, j = 0; i != H-1 || j != W-1;) {
      if (i != H-1 && A[i+1][j]) {
         i++; continue;
      }
      if (j != W-1 && A[i][j+1]) {
         j++; continue;
      }
      PRINT("Impossible");
      return 0;
   }
   PRINT("Possible");

   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );}

using edge=pair<int,int>;
using P=pair<int,pair<pair<int,int>,int>>;
#define mp(i,j,k,l) make_pair((i),make_pair(make_pair((j),(k)),(l)))
#define D first
#define Y second.first.first
#define X second.first.second
#define C second.second
const int INF=1<<29;
vector<edge> G={edge(-1,0),edge(0,1),edge(1,0),edge(0,-1)};
int d[22][22][1024];
int c[22][22];
int w,h;

void dijkstra(int y,int x,int cnt){
  cnt-=1;
  priority_queue<P,vector<P>,greater<P>> que;
  Fill(d,INF);
  d[y][x][0]=0;
  que.push(mp(0,y,x,0));
  while(!que.empty()){
    P p=que.top();que.pop();
    if(p.C==cnt){
      cout<<p.D<<endl;
      return;
    }
    if(d[p.Y][p.X][p.C]<p.D)continue;
    for(edge e:G){
      if(p.Y+e.first<0||p.X+e.second<0||p.Y+e.first>=h||p.X+e.second>=w)continue;
      if(c[p.Y+e.first][p.X+e.second]==-1)continue;
      if(d[p.Y+e.first][p.X+e.second][p.C|c[p.Y+e.first][p.X+e.second]]>d[p.Y][p.X][p.C]+1){
	d[p.Y+e.first][p.X+e.second][p.C|c[p.Y+e.first][p.X+e.second]]=d[p.Y][p.X][p.C]+1;
	que.push(mp(d[p.Y+e.first][p.X+e.second][p.C|c[p.Y+e.first][p.X+e.second]],
		    p.Y+e.first,
		    p.X+e.second,
		    p.C|c[p.Y+e.first][p.X+e.second]));
      }
    }
  }
  cout<<-1<<endl;
}

int main(){ _;
  while(cin>>w>>h,(w|h)){
    int cnt=1,x,y;
    char ch;
    REP(i,h)REP(j,w){
      cin>>ch;
      if(ch=='x')c[i][j]=-1;
      else if(ch!='*')c[i][j]=0;
      else{
	c[i][j]=cnt;
	cnt<<=1;
      }
      if(ch=='o'){
	y=i;
	x=j;
      }
    }
    dijkstra(y,x,cnt);
  }
}

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

int main() {
  string s,t; cin >> s >> t;
  ll a = s.size();
  ll b = 0;
  for(ll i = 0; i<a; i++){
    if(s[i]!=t[i]) b++;
  }
  if(b==0 && t.size()==a+1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
long long int dp[200005];
long long int n;
vector<long long int > arr(200005);
void gen(long long int x)
{
    for(int i=x;i<n;i++)
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
}
int main()
{
   // int n;
    cin>>n;
   // vector<int> arr(n);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    //input part has been done

   // long long int mini=1e5;
    //initialization
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);

    gen(2);
    cout<<dp[n-1];
}


Measured memory_bytes: 5544
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main(){
	int A,B,C;
    cin >> A >> B >> C;
  	if (int(A)==int(B)){
      if (int(A)==int(C)){
        cout << "Yes" << endl;
        return 0;
      }
      }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){

  int N,M;
  cin>>N>>M;
  vector<bool>check(N,0);
  vector<int>p(M);
  vector<string>S(M);
  vector<int>pena(N,0);
  for(int i=0;i<=M-1;i++){
  
    cin>>p[i]>>S[i];
  }
  int ac=0;
  int penanum=0;
  for(int i=0;i<=M-1;i++){
  
    if(S[i]=="AC"){
    
      if(check[p[i]-1]==0){
      
        check[p[i]-1]=1;
        ac++;
      }
    }
    if(S[i]=="WA"){
    
      if(check[p[i]-1]==0){
      
        pena[p[i]-1]++;
      }
    }
  }
  for(int i=0;i<=N-1;i++){
  
    if(check[i]==1){
    
      penanum+=pena[i];
    }
  }
  cout<<ac<<" "<<penanum;
  return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string n; cin >> n;
  string ans = "ABC";
  ans+=n;

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


Measured memory_bytes: 3636
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		char[] c = new char[n];
		sc.close();
		for (int i = 0; i < n; i++) {
			c[i] = s.charAt(i);
		}
		int[] east = new int[n];
		east[0] = c[0] == 'E' ? 1 : 0;
		for (int i = 1; i < n; i++) {
			if (c[i] == 'E') {
				east[i] = east[i - 1] + 1;
			} else {
				east[i] = east[i - 1];
			}
		}

		int min = east[n - 1] - east[0];
		for (int i = 1; i < n; i++) {
			int tmp = (east[n - 1] - east[i]) + (i + 1 - east[i]);
			if (tmp < min) {
				min = tmp;
			}
		}
		System.out.println(min);
	}

	public static long modFactorial(long n, long mod) {
		long ans = 1;
		for (int i = 1; i <= n; i++) {
			ans *= i;
			ans %= mod;
		}
		return ans;
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}

class Combination {
	static final int MOD = 1000000007;
	long[] fac;
	long[] finv;
	long[] inv;

	public Combination(int size) {
		fac = new long[size];
		finv = new long[size];
		inv = new long[size];
		fac[0] = 1;
		fac[1] = 1;
		finv[0] = 1;
		finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < size; i++) {
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

	public long getComb(int n, int k) {
		if (n < k || n < 0 || k < 0) {
			return 0;
		}
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
}

Measured memory_bytes: 32504
#include <vector>
#include <iostream>

#define ff first
#define ss second
using namespace std;
#define MOD 1000000007
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

long long n;
vector<vector<long long>> gr;

long long add(long long a, long long b) {
	a += b;
	if (a >= MOD) a %= MOD;
	return a;
}

void mult(long long &a, long long b) {
	a = ((a % MOD) * (b % MOD)) % MOD;
}

pair<long long, long long> dfs(long long curr, long long par) {
	pair<long long, long long> res = {1, 1};

	for (auto child : gr[curr]) {
		if (child != par) {
			pair<long long, long long> q = dfs(child, curr);
			mult(res.ff, q.ff + q.ss);
			mult(res.ss, q.ff);
		}
	}
	return res;
}

int main() {

	cin >> n;
	gr.resize(n + 1);
	for (long long i = 1; i <= n - 1; i++) {
		long long u, v; cin >> u >> v;
		gr[u].push_back(v);
		gr[v].push_back(u);
	}

	pair<long long, long long> ans = dfs(1, 1);
	cout << add(ans.ff, ans.ss);

	return 0;
}

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

int main(){
    int N;  cin >> N;
    vector<int> h(N+1);
    for(int i=1; i<=N; i++) cin >> h[i];

    vector<int> dp(N+1);
    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    for(int i=3; i<=N; i++){
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 1024
function main(lines) {
  const input = lines.split(' ').map(function(a){return parseInt(a);})
  const a = input[0]
  const b = input[1]
  if(a<b){
      console.log('a < b')
  } else if(a>b){
      console.log('a > b')
  } else {
      console.log('a == b')
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 15112
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
int a[200010];

int main()
{
	scanf("%d", &n);
	for (int i = 0 ; i < n ; i++)
		scanf("%d", &(a[i]));
		
	int p = 0;
	int nextP = 1;
	for (int i = 0 ; i < n ; i++) {
		if (a[i] == nextP) {
			p++;
			nextP++;
		}
	}
	
	int cut = n - p;
	if (cut == n)
		cut = -1;
	printf("%d\n", cut);

	return 0;
}


Measured memory_bytes: 896
import java.util.*;
public class Main {
		
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		sc.close();
		
		int res = Math.max(C-(A-B), 0);
		
		System.out.println(res);
		
	}
	
}

Measured memory_bytes: 25300
// 23/01/20 // 11:34 AM //

#include <bits/stdc++.h>

using namespace std;

const int MAXN = (int)(3e3) + 10;
const int INF  = 0x3f3f3f3f;

int n;
double p[MAXN], memo[MAXN][MAXN];

double solve(int i, int qnt){
    if(memo[i][qnt]!=-1) return memo[i][qnt];

    if(2*(qnt+n-i+1)<n) return memo[i][qnt] = 0;
    if(i>n)             return memo[i][qnt] = 1;

    return memo[i][qnt] = p[i]*solve(i+1, qnt+1) + (1-p[i])*solve(i+1, qnt);
}

int main(){


    cin >> n;
    for(int i=1; i<=n; i++) cin >> p[i];

    for(int i=0; i<=n+1; i++)
        for(int j=0; j<=n+1; j++)
            memo[i][j] = -1;


    cout.precision(10);
    cout.setf(ios::fixed);

    cout << solve(1, 0) << endl;

    return 0;
}


Measured memory_bytes: 71040
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	size_t num_ac = 0;
	size_t num_wa = 0;
	size_t num_tle = 0;;
	size_t num_re = 0;;
	cin >> n;
	vector<string> s;
	for (int i = 0; i < n; i++) {
		string str;
		cin >> str;
		s.push_back(str);
	}
	num_ac = count(s.begin(), s.end(), "AC");
	num_wa = count(s.begin(), s.end(), "WA");
	num_tle = count(s.begin(), s.end(), "TLE");
	num_re = count(s.begin(), s.end(), "RE");
	cout << "AC x " << num_ac << "\n";
	cout << "WA x " << num_wa << "\n";
	cout << "TLE x " << num_tle << "\n";
	cout << "RE x " << num_re << "\n";
}

Measured memory_bytes: 7436
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, K] = string_to_int(inputs[0])
    count_a = 0
    count_b = 0
    for i in range(1, N+1):
        if i % K == 0:
            count_a += 1
        if i % K == K/2:
            count_b += 1

    count = count_a ** 3
    if K % 2 == 0:
        count += count_b ** 3
    return count


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


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

ostream& operator << (ostream& out, const unordered_set<int>& st) {
    for (const auto i : st) {
        out << i << " ";
    }
    return out;
}

int main() {
    int N;
    string S;
    cin >> N >> S;
    unordered_set<int> one, two, three;
    for (int i = 0; i < N; ++i) {
        int v = int(S[i] - '0');
        for (auto j : two) {
            three.insert(10 * j + v);
        }
        for (auto j : one) {
            two.insert(10 * j + v);
        }
        one.insert(v);
        // cout << "one: " << one << "\ntwo: " << two << "\nthree: " << three << "\n\n";
    }
    cout << three.size() << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    ll flag=1;
    for(ll i=0;i<s.length();i++)
    {
        if(s[i]!=s[s.length()-1-i])
            flag=0;
    }
    for(ll i=0;i<(s.length())/2;i++)
    {
        if(s[i]!=s[s.length()/2-1-i])
            flag=0;
        if(s[s.length()-1-i]!=s[s.length()/2+1+i])
            flag=0;
    }
    if(flag==1)
        cout<<"Yes";
    else
        cout<<"No";
}

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

using namespace std;
#define         MAX         1000000
#define         ll          long long
#define         input       freopen("input.txt","r",stdin)
#define         output      freopen("output.txt","w",stdout)



int main() {

    int n;

    cin>>n;
    int flag = 0;
    int tmp;
    while(n>0){
        tmp = n%10;
        n /= 10;
        if(tmp == 7) flag = 1;
    }

    (flag)?cout<<"Yes":cout<<"No";
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3632
n,y= map(int, input().split())
for i in range(n+1):
	for j in range(n-i + 1):
		if 10000 * i + 5000 * j + 1000 * (n-i-j) == y:
			print(i,j,n-i-j)
			exit()


print('-1 -1 -1')

Measured memory_bytes: 40812
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main (){
    string a;
    cin>>a;
    int ans = 0;
    for(int i=0;i<4;++i){
        if(a[i]=='+')ans++;
        else ans--;
    }
    cout <<ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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 long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string s;
    ll k;
    cin >> s >> k;
    if (k==1){
        cout << s[0] << endl;
    }else{
        for (ll i=0;i<k and i<s.size();i++){
            if (s[i]!='1'){
                cout << s[i] << endl;
                return 0;
            }
        }
        cout << 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	ll n,k;
	cin >> n >> k;
	vector <int> h(n);
	ll count =0;
	for (ll i =0;i<n;i++) {
		cin >> h[i];
		if (h[i] >= k) {
			count++;
		}
	}
	cout << count <<endl;
	return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int x;
    cin >> x;

    int ans = 0, sum = 0;
    while(1) {
        sum += ans;
        if(sum>=x) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <map>


using namespace std;

int main(void) {

	int n;
	int max = 0;
	map<int, int> m;

	cin >> n;

	for (int i = 0; i < n; ++i) {

		int num; cin >> num;

		m[num - 1]++;
		m[num]++;
		m[num + 1]++;

	}

	for (auto i : m) {

		if (max < i.second) {

			max = i.second;

		}

	}

	cout << max << endl;


	return 0;

}

Measured memory_bytes: 4736
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int q;

  while(1){
    cin>>q;
    if(q<0)break;
    double a,b;
    b=q/2.0;
    while(2){
      a=b-(b*b*b-q)/(3*b*b);
      if(abs(a*a*a-q)<0.00001*q)break;
      b=a;
    }
    printf("%.10f\n",a);
  }
}

Measured memory_bytes: 1192
let rec repcomb acc xs n ys =
  match n, ys with
  | 0, _ -> List.rev xs :: acc
  | _, [] -> acc
  | n, y :: ys' -> repcomb (repcomb acc xs n ys') (y :: xs) (n - 1) ys
(* 与えられたリストから重複を許してn要素を選ぶ組み合わせを列挙 *)
let repcomb : int -> 'a list -> 'a list list = fun n xs -> repcomb [] [] n xs

let () = Scanf.scanf "%d %d %d\n" @@ fun n m q ->
  let abcds = Array.init q @@ fun _ ->
    Scanf.scanf "%d %d %d %d\n" @@ fun a b c d -> a, b, c, d in
  Printf.printf "%d\n" @@
  List.fold_left max min_int @@
  List.map (fun as_ ->
    Array.fold_right (fun (a, b, c, d) -> ( + ) @@
      if as_.(b - 1) - as_.(a - 1) = c then d else 0) abcds 0) @@
  List.map Array.of_list @@
  repcomb n @@
  List.init m succ



Measured memory_bytes: 37376
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>
#include <string>
#include <vector>


using namespace std;


bool cmp(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    return a.first + a.second > b.first + b.second;
}



int main(void){
    int N;
    scanf("%d",&N);
    vector<pair<long long,long long> >po;
    for(int i=0;i<N;i++){
        long long a,b;
        scanf("%lld %lld",&a,&b);
        po.push_back(make_pair(a,b));
    }
    sort(po.begin(),po.end(),cmp);
    long long ans=0;
    for(int i=0;i<N;i++){
        if(i%2==0)ans+=po[i].first;
        else ans-=po[i].second;
    }
    printf("%lld",ans);
    return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x;
  x = a * 100 + b * 10 + c;
  if (x % 4 == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}  


Measured memory_bytes: 256
n,k,s = list(map(int, input().split()))

if s != 1e9:
    ret = [s for i in range(k)] + [s+1 for i in range(n-k)]
    print(*ret)
else:
    ret = [s for i in range(k)] + [1 for i in range(n-k)]
    print(*ret)

Measured memory_bytes: 50800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vpci = vector<pair<char, int>>;
using miq = unordered_map<int, queue<char>>;

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

int partition(vpci &a, int p, int r) {
  int x = a[r].second, i = p - 1;
  
  for (int j = p; j < r; j++) {
    if (a[j].second <= x) {
      i++;
      swap(a[i], a[j]);
    }
  }
  
  i++;
  swap(a[i], a[r]);

  return i;
}

void quick_sort(vpci &a, int p, int r) {
  if (p < r) {
    int q = partition(a, p, r);
    quick_sort(a, p, q - 1);
    quick_sort(a, q + 1, r);
  }
}

bool is_stable(miq m, vpci a) {
  for (auto p: a) {
    auto &q = m[p.second];
    if (q.front() != p.first) return false;
    q.pop();
  }

  return true;
}

int main() {
  int n;
  cin >> n;
  
  vpci vp;
  miq m;
  rep(i, n) {
    char c;
    int x;
    cin >> c >> x;
    vp.push_back(make_pair(c, x));

    if (!m.count(x)) m[x] = queue<char>();
    m[x].push(c);
  }

  quick_sort(vp, 0, n - 1);
  
  cout << (is_stable(m, vp) ? "Stable" : "Not stable") << endl; 

  for (auto p: vp) printf("%c %d\n", p.first, p.second);
}



Measured memory_bytes: 39916
"use strict";
let input = require("fs").readFileSync("/dev/stdin", "utf8");
let dp = [];
dp[0] = 0;
for (let n = 1; n <= 100000; n ++) {
    dp[n] = Infinity;
    let power = 1;
    while (power <= n) {
        dp[n] = Math.min(dp[n], dp[n - power] + 1);
        power *= 6;
    }
    power = 1;
    while (power <= n) {
        dp[n] = Math.min(dp[n], dp[n - power] + 1);
        power *= 9;
    }
}

console.log(dp[parseInt(input)]);

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

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

int main(){
  string S;
  cin>>S;
  ll k;
  cin>>k;
  if(k==1)
    cout<<S[0]<<endl;
  else if(S[0]!='1')
    cout<<S[0]<<endl;
  else {
    rep(i,S.size()){
      if(S[i]!='1'&&i<k){
	cout<<S[i]<<endl;
	return 0;
      }}
      cout<<1<<endl;
    

  }



  return 0;
}


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

int a[100005];
int x;
int main()
{
    int n,l;
    cin>>n>>l;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i-1]+a[i]>=l)
        {
            printf("Possible\n");
            x=i;
            break;
        }
    }
    if(x==0)
    {
         printf("Impossible\n");
         return 0;
    }
    for(int i=1;i<x;i++)
    {
        cout<<i<<endl;
    }
    for(int i=n-1;i>x;i--)
    {
        cout<<i<<endl;
    }
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
signed main(){
	int n;
	cin>>n;
	if(n%2==0){
		cout<<0.5<<endl;
	}else{
		double ans=(n+1)/2;
		ans/=n;
		cout<<ans<<endl;
	}


	return 0;
}



Measured memory_bytes: 3768
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int h = ri();
    int w = ri();
    char s[h][w+1];
    FOR(i,h) cin >> s[i];
    
    int white = 0;
    FOR(i,h) FOR(j,w) if (s[i][j] == '.') white++;
    // cout << "white:" << white << endl;
    
    queue<pi > q;
    q.push(pi(0,0));
    int data[h][w];
    FOR(i,h) FOR(j,w) data[i][j] = INF;
    data[0][0] = 0;
    
    int res = -1;
    while(q.size()) {
        auto i = q.front();q.pop();
        
        const pi dir[]={pi(1,0),pi(-1,0),pi(0,1),pi(0,-1)};
        FOR(j,4) {
            int x = i.fi+dir[j].fi;
            int y = i.se+dir[j].se;
            if (x < 0 || x >= h) continue;
            if (y < 0 || y >= w) continue;
            if (s[x][y] == '#') continue;
            if (data[x][y] > data[i.fi][i.se]+1) {
                q.push(pi(x,y));
                data[x][y] = data[i.fi][i.se]+1;
            }
        }
        if (data[h-1][w-1] != INF) {
            res = white - data[h-1][w-1] -1;
            break;
        }
    }
    cout << res << endl;
 return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 998244353
#define mkp make_pair
typedef long long ll;
using namespace std;

int N;
string S;

int main(){
  cin>>N;
  cin>>S;
  int M=S.size();

  queue<char> one;
  queue<pair<char,char>> two;
  ll ans=1;
  for(int i=0;i<M;i++){
    if(one.empty()&&two.empty()) one.push(S[i]);
    else if(one.empty()){
      char a,b;
      tie(a,b)=two.front();
      if(S[i]!=a&&S[i]!=b){
        ans=ans*two.size()%MOD;
        two.pop();
      }else one.push(S[i]);
    }else if(two.empty()){
      char a=one.front();
      if(a==S[i]) one.push(S[i]);
      else{
        ans=ans*one.size()%MOD;
        one.pop();
        two.push(mkp(a,S[i]));
      }
    }else{
      char a,b;
      char c=one.front();
      tie(a,b)=two.front();
      if(S[i]!=a&&S[i]!=b){
        ans=ans*two.size()%MOD;
        two.pop();
      }else if(c==S[i]){
        one.push(S[i]);
      }else{
        ans=ans*one.size()%MOD;
        one.pop();
        two.push(mkp(c,S[i]));
      }
    }
  }

  for(int i=1;i<=N;i++) ans=ans*i%MOD;

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <set>
using namespace std;
class sai
{
    public :
    int ue;
    int tem;
    int migi;
    int hidari;
    int oku;
    int sita;
    void roll(char c){
        int kari;
        if (c == 'S') {
        kari = ue;
        ue = oku;
        oku = sita;
        sita = tem;
        tem = kari;
    } else if (c == 'N') {
        kari = ue;
        ue = tem;
        tem = sita;
        sita = oku;
        oku = kari;
    } else if (c == 'E') {
        kari = ue;
        ue = hidari;
        hidari = sita;
        sita = migi;
        migi = kari;
    } else if (c == 'W') {
        kari = ue;
        ue = migi;
        migi = sita;
        sita = hidari;
        hidari = kari;
    }
  
    }
};
sai roll(sai b, char c) {
    if (c == 'S') {
        b = {b.oku,b.ue,b.migi,b.hidari,b.sita,b.tem};
    } else if (c == 'N') {
        b = {b.tem,b.sita,b.migi,b.hidari,b.ue,b.oku};
    } else if (c == 'E') {
        b = {b.hidari,b.tem,b.ue,b.sita,b.oku,b.migi};
    } else if (c == 'W') {
        b = {b.migi,b.tem,b.sita,b.ue,b.oku,b.hidari};
    }
    return b;
}
bool judge(sai a, sai b) {
    bool hey = true;
    string s = "EEEENEEEENEEEENEEEENENEEENNEEEE" ;
    for (int i = 0; i < s.length(); i++) {
        if (a.oku == b.oku and a.ue == b.ue and a.migi == b.migi and a.hidari == b.hidari and a.sita == b.sita and a.tem == b.tem) {
            hey = true;
            break;
        } else {
            hey = false;
        }
        b.roll(s[i]);
    }
    return hey;
}

int main(void){
    int a1,a2,a3,a4,a5,a6,n,b1,b2,b3,b4,b5,b6;
    int x ,y;
    bool ans = true;
    cin >> n;
    int l[n][6];
    for(int i = 0; i < n ; i++){
        for(int j = 0; j < 6; j++){
            cin >> l[i][j];
        }
    }
    sai a,b;
    for(int i = 0; i < n ; i++){
        for(int j = i + 1; j < n; j++){
            a = {l[i][0],l[i][1],l[i][2],l[i][3],l[i][4],l[i][5]};
            b = {l[j][0],l[j][1],l[j][2],l[j][3],l[j][4],l[j][5]};
            if(judge(a,b)){
                ans = false;
            }
        }
    }
    if(ans){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }


int N;
lint D;
vector<lint> A, B;

int main()
{
    cin >> N >> D;
    A.resize(N);
    lint as = 0;
    REP(i, N)
    {
        cin >> A[i];
        as += A[i];
    }
    B = A;
    REP(i, N - 1) Min(B[i + 1], B[i] + D);
    IREP(i, N - 1) Min(B[i], B[i + 1] + D);

    cout << as + accumulate(B.begin() + 1, B.begin() + N - 1, 0LL) + (N - 1) * D << endl;
}


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

int main()
{
    int n; cin>>n;
    vector<vector<int>> g(n);
    for(int i=0; i<n-1; ++i) {
        int a, b; cin>>a>>b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> x(n);
    queue<int> q;
    q.push(0); x[0]=1;
    q.push(n-1); x[n-1]=-1;

    while (q.size()) {
        int v=q.front(); q.pop();
        int k=x[v];
        for(int u: g[v]) if (!x[u]) {
            x[u]=k;
            q.push(u);
        }
    }
    int fennec=count(begin(x), end(x), 1);
    int snuke=n-fennec;
    cout<<(fennec>snuke ? "Fennec" : "Snuke")<<endl;
}


Measured memory_bytes: 6144
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#define ll long long
using namespace std;
int main() {
	ll a, b, c, d,x,y;
	cin >> a >> b >> c >> d;
	x = min(a, b);
	y = min(c, d);
	cout << x + y << endl;
}


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

using namespace std;

typedef long long ll;

struct knapsack:vector<vector<ll>>
{
    ll max_value;
    
    knapsack(int n, int W) 
    { 
        vector<int> weight(n), value(n); 
        
        for(int i = 0; i < n; ++i)
            cin >> weight[i] >> value[i];
      
        resize(n+1); int W1 = W+1;
         
        for(auto&dp:*this)
            dp.resize(W1,0);
            
        for (int i = 0, j = 1; i < n; i = j++) 
	        for (int w = 1; w < W1; ++w) 
	            if ((at(j).at(w) = at(i).at(w),weight[i]) <= w) 
	                if( (max_value = at(i).at(w-weight[i])+value[i]) > at(j).at(w))
	                    at(j).at(w) = max_value;
	                    
		max_value = at(n).at(W);
    }
};

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int n, W; cin >> n >> W; cout << knapsack(n,W).max_value; 
}

Measured memory_bytes: 79488
s = gets.chomp
k = gets.to_i

a = 0
prev = nil
cont = 1
for i in 0...s.size
    if prev == s[i]
        cont += 1
        a += 1 if cont % 2 == 0
    else
        cont = 1
    end
    prev = s[i]
end

ans = 0   
if cont == s.size
    # 全て同じ文字
    ans = s.size * k / 2
elsif k > 1 && s[-1] == s[0] && cont % 2 == 1
    # 1単語目と2単語目以降でカウントが異なる場合
    b = 0
    prev = s[-1]
    cont = 1
    for i in 0...s.size
        if prev == s[i]
            cont += 1
            b += 1 if cont % 2 == 0
        else
            cont = 1
        end
        prev = s[i]
    end

    ans = a + b * (k-1)
else
    # 1単語目と2単語目以降でカウントが同じ場合
    # - 末尾と先頭が異なる場合
    # - 1単語で完結している場合
    ans = a * k
end

puts ans

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int N;
  cin>>N; 
  vector<int>a(N);
  for(int j=0; j<N;j++){
    cin>>a.at(j);
  }
  sort(a.begin(),a.end());
  
 
    cout<<a.at(N-1)-a.at(0)<<endl;
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
using namespace std;

int main() {
  int N, M, score = 0, max = 0;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i<N; i++){
    cin >>s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for (int i=0; i<M; i++){
    cin >> t.at(i);
  }
  
  for (int i =0; i<N; i++){
    score = 0;
    for(int k = 0; k<N; k++){
      if(s.at(i) == s.at(k)){
        score ++;
      }
    }
    for (int k = 0; k<M; k++){
      if(s.at(i) == t.at(k)){
        score --;
      }
    }
    if(max < score){
      max = score;
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include <algorithm>
#include <functional>
#include<cmath>

using namespace std;

int main(){
	int a,b;
	
	while(cin>>a>>b)
	{
		a = a+b;
		a = (int)log10(a)+1;
		cout << a << endl;
	}

	return 0;
}

Measured memory_bytes: 1204