akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int a[maxn],n,k;
bool b[maxn];
int main()
{
	scanf("%d",&n); 
	for (int i = 1; i <= (n << 1) - 1; i ++) scanf("%d",&a[i]);
	int L = 1, R = (int) 1e9;
	while (L <= R)
	{
	//	cerr<<L<<' '<<R<<endl;
		int mid = L + R >> 1; k = mid;
		for (int i = 1; i <= (n << 1) - 1; ++i) b[i] = (a[i] > k);
	//	for (int i = 1; i <= (n << 1) - 1; ++i) printf("%d",b[i]); putchar(10);
		int ok = -1;
		for (int i = 0; i < n - 1; ++i)
		{
			if ((b[n + i] && b[n + i + 1])||(b[n - i] && b[n - i - 1])){ ok = 1; break;}
			if ((!b[n + i] && !b[n + i + 1]) || (!b[n - i] && !b[n - i - 1])) {ok = 0; break;}
		}
		if (ok == -1) ok = b[1];
		if (ok) L = mid + 1; else R = mid - 1;
	}
	printf("%d\n",L);
}
//二分答案k
//<=答案k的那些数都看成0。>k的那些数看成1. 当二分到的k >= 实际答案时,顶端为0，否则为1. 

Measured memory_bytes: 1280
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/30/2019 11:03:37 PM
*************************************************************************/
//#pragma GCC optimize(3)
//#pragma GCC diagnostic error "-std=c++11"
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#define lowbit(x) x&(-x)
#define ls u<<1
#define rs u<<1|1
using namespace std;
template<typename T> inline T MIN(const T &a,const T &b) {return a<b?a:b;}
template<typename T> inline T MAX(const T &a,const T &b) {return a>b?a:b;}
template<typename T,typename ...Args> inline T MIN(const T &a,const T &b,Args ...args) {return MIN(MIN(a,b),args...);}
template<typename T,typename ...Args> inline T MAX(const T &a,const T &b,Args ...args) {return MAX(MAX(a,b),args...);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
char a[22][22];
int h,w;
bool vis[22][22];
struct node{
	int x,y,step;
};
int bfs(int x,int y){
	memset(vis,0,sizeof vis);
	int res=0;
	vis[x][y]=1;
	queue<node> q;
	q.push(node{x,y,0});
	while(!q.empty()){
		node t=q.front();q.pop();
#ifdef WindCry1
	cout<<t.x<<" "<<t.y<<" "<<t.step<<endl;
#endif
		res=max(res,t.step);
		for(int i=0;i<4;i++){
			int dx=dir[i][0]+t.x,dy=dir[i][1]+t.y;
			if(dx>=1 and dx<=h and dy>=1 and dy<=w and a[dx][dy]=='.' and !vis[dx][dy]){
				q.push(node{dx,dy,t.step+1});
				vis[dx][dy]=1;
			}
		}
	}
	return res;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef WindCry1
	freopen("C:\\Users\\LENOVO\\Desktop\\in.txt","r",stdin);
#endif
	cin>>h>>w;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++) cin>>a[i][j];
	int res=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(a[i][j]=='.') res=max(res,bfs(i,j));
		}
	}
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n, ll mod){
    ll res = 1;
    while(n){
        if(n & 1){
            (res *= a) %= mod;
        }else{
            (a *= a) %= mod;
        }
        n >>= 1;
    }
    return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n, k;
    cin>>n>>k;
    vector<ll> p(n);
    vector<ld> q(n+1);
    q[0] = 0;
    for(ll i=0;i<n;++i){
        cin>>p[i];
        q[i+1] = q[i] + ((ld)p[i] + (ld)1) / 2;
        if(i >= k){
            q[i+1] -= ((ld)p[i-k] + (ld)1) / 2;
        }
    }
    

    ld ans = 0;
    for(ll i=0;i<=n;++i){
        if(ans < q[i]){
            ans = q[i];
        }
        //cout<<q[i]<<endl;
    }
    cout<<setprecision(10)<<ans<<endl;

    return 0;
}

Measured memory_bytes: 7992
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


signed main() {
  string w;cin>>w;
  int a[26];rep(i,26)a[i] = 0;
  rep(i,w.length()){
    a[w[i]-'a']++;
  }
  rep(i,26){
    if(a[i]%2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

//1 2 3 4 5 6 7 8 9
//2 5 5 4 5 6 3 7 6


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, Z, W;
  cin >> n >> Z >> W;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  if (n == 1) {
    cout << abs(a[0] - W) << endl;
  } else {
    cout << max(abs(a.back() - W), abs(a[n - 2] - a.back())) << endl;
  }

  return 0;
}


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

int pow(int A, int P){
	int a = A, p = P;
	if(p == 0) return 1;
	if(p == 1) return a;
	int adash = a * a;
	if(p % 2) return pow(adash, p / 2) * a;
	else return pow(adash, p / 2);
}

int main(){
	int H, W, K;
	cin >> H >> W >> K;
	char c[H][W];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> c[i][j];
		}
	}
	int ans = 0;
	for(int l=0;l<pow(2,H);l++){
		for(int m=0;m<pow(2,W);m++){
			int cnt = 0;
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					if((l >> i) % 2 == 0 && (m >> j) % 2 == 0 && c[i][j] == '#') cnt++;
				}
			}
			if(cnt == K)ans++;
		}
	}
	cout << ans << endl;
}


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

int main(){

int x[10000]; 

 	for (int i=1; i<=10000; i=i+1 )
 	{
 	cin >> x[i] ;

		if( x[i] == 0 )
 		{
 		break;
 		}else{
		cout<< "Case "<< i << ": "<< x[i] << endl;
 		}

 	}

 return 0;
 }


Measured memory_bytes: 3092
n,k = map(int,input().split())
h = [0]*n
for i in range(n):
  h[i] = int(input())
h.sort()
hdf = 10**9
for i in range(n-k+1):
  hdf = min(hdf,h[k+i-1]-h[i])
print(hdf)

Measured memory_bytes: 7472
#include<stdio.h>

char S[250];

int main()
{
	int  countS=0,check=1,i,j,f=1;
	scanf("%s",S);
	for(j=0;S[j] !='\0'; j++){
			countS++;
	}
	
	for(int i=countS/2-1; i>=0; i--){
		f=1;
		
		for(int j=0; j<i; j++){
			if(S[j] != S[j+i]){
				f=-1;
				break;
			}
		}
		if(f==1){
			printf("%d\n",i*2);
			return 0;
		}
	}
}

Measured memory_bytes: 128
N = int(input())
A = []
B = list(map(int, input().split()))

sum = 0
for n in range(N):
  if n == 0:
    A.append(B[n])
  else:
    if A[n] > B[n]:
      A[n] = B[n]

  A.append(B[n])
  sum += A[n]

  if n == N-2:
    sum += A[n+1]
    break

      
print(sum)

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

// #define int long long
 
 
// signed main(){
//     map<int,int>mp;
//     vector<long long>vec;
//     vector<long long>d;
//     int n;
//     cin>>n;
//     long long arr[10000001];
//     for(int i = 0;i<n;++i){
//         {cin>>arr[i];mp[arr[i]]++;}
//         if(arr[i]&1)vec.push_back(i+1);
//     }
//     int q;
//     cin>>q;
//     while(q--)
//     {
//         d.clear();
//         long k;
//         long long f = 0;
//         cin>>k;
//         // if(!(k%2))
//         // {
//             f+=(n*(n-1));
//             f/=2;
//             for(int i = 1;i<=sqrt(k);++i)
//             {
//                 if(k%i==0)
//                 {
//                     d.push_back(i);
//                     d.push_back(k/i);
//                 }
//             }
//             for(int i = 0;i<d.size();++i)
//             {
//                 if(find(arr,arr+n,d[i])!=arr+n)f+=mp[d[i]];
//             }
//             cout<<f<<endl;
//         }
//         else
//         {
//             if(vec.size()==0)
//             cout<<0<<endl;
//             else
//             {
//                 f+=(n*(n-1));
//                 f/=2;
//                 for(int i = 1;i<=sqrt(k);++i)
//             {
//                 if(k%i==0)
//                 {
//                     d.push_back(i);
//                     if(i!=k/i)
//                     d.push_back(k/i);
//                 }
//             }
//             for(int i = 0;i<d.size();++i)
//             {
//                 if(find(arr,arr+n,d[i])!=arr+n)f+=mp[d[i]];
//             }
//                 int g=((vec[0]-1)*(vec[0]-2));
//                 g/=2;
//                 f-=g;
//                 int h= (n-vec[vec.size()-1])*(n-vec[vec.size()-1]-1);
//                 h/=2;
//                 f-=h;
//                 for(int i = 0;i<vec.size()-1;++i)
//                 {
//                     int q = vec[i+1]-vec[i]-1;
//                     int h = (q*(q-1));
//                     h/=2;
//                     f-=h;
//                 }
//                 cout<<f<<endl;
//             }
//         }
//     }
//     return 0;
// }

#include<bits/stdc++.h>

using namespace std;


int main()
{
    
    int n;
    cin>>n;
    cout<<pow(n,3);
    return 0;
}

Measured memory_bytes: 384
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll arr[300005];
ll mat[300005][70];

ll modMul(ll A, ll B) {
	return (A * B) % MOD;
}
ll modSum(ll A, ll B) {
	return (A + B) % MOD;
}

int main() {
	scanf("%lld", &N);
	for(ll i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
	}
	for(ll i = 0; i < N; i++) {
		for(ll j = 0; j < 61; j++) {
			if(arr[i] & (1ll << j)) {
				mat[i][j] = 1;
			}
		}
	}	
	ll ans = 0;
	for(ll j = 0; j < 61; j++) {
		ll cnt1 = 0;
		ll cnt0 = 0;
		ll pows = (1ll << j);
		pows %= MOD;
		for(ll i = 0; i < N; i++) {
			// cout << mat[i][j] << " ";
			if(mat[i][j] == 1) {
				cnt1++;
			}
			else {
				cnt0++;
			}
		}
		ll temp = modMul(cnt0, cnt1);
		ans = modSum(ans, modMul(temp, pows)); 
		// cout << cnt0 << " " << cnt1 << " " << pows << "\n";
		// cout << pow(2ll, j) << "hey\n";
		// cout << "\n";
	}
	printf("%lld\n", ans % MOD);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

inline int dist(int x1, int y1, int x2, int y2){
    return abs(x1-x2) + abs(y1-y2);
}

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> sx(n), sy(n), cx(m), cy(m), checkpoint(n);
    rep(i,n) cin >> sx[i] >> sy[i];
    rep(i,m) cin >> cx[i] >> cy[i];
    
    rep(i,n){
        int nearest = 0, nearest_dist = INT_MAX;
        rep(j,m){
            int now = dist(sx[i],sy[i],cx[j],cy[j]);
            if(now < nearest_dist){
                nearest_dist = now;
                nearest = j;
            }
        }
        checkpoint[i] = nearest + 1;
    }
    
    rep(i,n) cout << checkpoint[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
bool cmp(pair <lli,lli> a, pair <lli,lli> b){
    return a.second>b.second;
}
int main(){
    
    lli n,m;
    cin >> n >> m;
    vector <lli> v(n);
    for(int i =0;i<n;i++){
        cin >> v[i];
    }
    vector < pair <lli,lli> > queries;
    for(int i =0;i<m;i++){
        lli x,y;
        cin >> x >> y;
        //cout << x << " " << y <<endl;
        queries.push_back(make_pair(x,y));
    }
    sort(v.begin(),v.end());
    sort(queries.begin(),queries.end(),cmp);
    lli index =0,sum=0;
    for(int i =0;i<m;i++){
        lli x = queries[i].first;
        lli k = queries[i].second;
        while(x--){
            if(index>=v.size()){
                break;
            }
            if(index<v.size()&&v[index]<k){
                sum+=k;
                index++;
            }else{
                break;
            }
        }
    }
    for(;index<v.size();index++)sum+=v[index];
    cout << sum << endl;
 }


Measured memory_bytes: 3188
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] l = new int[n];

    for(int i=0;i<n;i++){
        l[i]=sc.nextInt();
    }

    Arrays.sort(l);

    int sum=0;

    for(int i=0;i<k;i++){
      sum += l[n-i-1];
    }
    System.out.println(sum);
    sc.close();
  }
}

Measured memory_bytes: 21716
while true
	h, w = gets.split( " " ).map { | val | val.to_i }
	break if 0 == h && 0 == w
	
	h.times { | i |
		if 0 == i || h-1 == i
			puts( "#"*w )
		else
			puts( "#"+"."*(w-2)+"#" )
		end
	}
	print( "\n" )
end

Measured memory_bytes: 6124
#include <bits/stdc++.h>
using namespace std;
int main(){
  double n,k;
  double ans=0;
  cin >>n >>k;
  for(double i=1;i<=n;i++){
    if(i<k){
      if(log2(k/i)!=floor(log2(k/i)))ans+=pow(0.5,floor(log2(k/i))+1);
      else ans+=pow(0.5,floor(log2(k/i)));
    }
    else ans+=1;
  }
  printf("%.16f",ans/n);
}

Measured memory_bytes: 384
#include<iostream>
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=(j);i<=(k);i++)
#define fs first
#define sc second
#define pb push_back

using namespace std;

#define N 1000000
int inp[N];

int main(){
	int a,d,n;
	inp[0]=inp[1]=1;
	reps(i,2,N-1){
		if(!inp[i])for(int j=i*2;j<N;j+=i)inp[j]=1;
	}
	while(cin >> a >> d >> n){
		if(!(a+d+n))break;
		while(n){
			if(!inp[a]) n--;
			a += d;
		}
		cout << a-d << endl;
	}
	return 0;
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=100100;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

ll power(ll a,ll n){
    if(n==0) return 1;
    ll res=1;
    while(n>0){
        if(n%2==1) res=res*a%MOD;
        a=a*a%MOD;
        n/=2;
    }
    return res;
}
ll comb(ll n,ll r){
    ll b=1,s=1;
    for(ll i=0;i<r;i++){
        b=b*(r-i)%MOD;
        s=s*(n-i)%MOD;
    }
    return s*power(b,MOD-2)%MOD;
}

int main(){
    ll n,a,b,ans=0;
    cin>>n>>a>>b;
    ans=power(2,n)-1;
    ans-=comb(n,a);
    ans-=comb(n,b);
    ans%=MOD;
    if(ans<0) ans+=MOD;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
int main(void){
    
    int N;
    scanf("%d",&N);
    int A[N];
    for(int i=0;i<N;i++){scanf("%d",&A[i]);A[i]-=i;}
    sort(A,A+N);
    int po=A[N/2];
    long long ans=0;
    for(int i=0;i<N;i++)ans+=abs(A[i]-po);
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	s := nextString()
	ss := strings.Split(s, " ")
	a, _ := strconv.ParseInt(ss[0], 10, 64)
	b, _ := strconv.ParseInt(ss[1], 10, 64)
	if a < b {
		fmt.Println(b*2 - 1)
		return
	}
	if b < a {
		fmt.Println(a*2 - 1)
		return
	}
	fmt.Println(a + b)
}


Measured memory_bytes: 640
from operator import itemgetter
N = int(input())
q = []
ans = 0
for i in range(N):
    x,l = map(int,input().split())
    q.append([x-l,x+l])
q = sorted(q,key = itemgetter(1))
last = -10**18
for i in range(N):
    tmp = q[i]
    if tmp[0] >= last:
        ans += 1
        last = tmp[1]
print(ans)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for( int i = 0; i < N; i++ ){
    cin >> vec.at(i);
  } 
  sort( vec.begin(), vec.end() );
  
  double goke = 0;
  cout << fixed << setprecision(10);
  for( int i = 0; i < N-1; i++ ){
    if( i == 0 ){
      goke = ( vec.at(0) + vec.at(1) ) / 2.000;
    }else{
      goke = ( goke + vec.at(i+1) ) / 2.000;
    }
  }
  cout << goke << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;

signed main(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a,b) << " ";

    if(a+b <= n)cout << 0;
    else cout << a+b-n;
    


    
    return 0;   
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://arc060.contest.atcoder.jp/tasks/arc060_a

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdexcept>
#include<cmath>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;

map<char,string> cs;
map<string,char> sc;
 
void init(){
cs[' '] = "11010";
cs['\''] = "11110";
cs[','] = "11100";
cs['-'] = "11101";
cs['.'] = "11011";
cs['?'] = "11111";
cs['A'] = "00000";
cs['B'] = "00001";
cs['C'] = "00010";
cs['D'] = "00011";
cs['E'] = "00100";
cs['F'] = "00101";
cs['G'] = "00110";
cs['H'] = "00111";
cs['I'] = "01000";
cs['J'] = "01001";
cs['K'] = "01010";
cs['L'] = "01011";
cs['M'] = "01100";
cs['N'] = "01101";
cs['O'] = "01110";
cs['P'] = "01111";
cs['Q'] = "10000";
cs['R'] = "10001";
cs['S'] = "10010";
cs['T'] = "10011";
cs['U'] = "10100";
cs['V'] = "10101";
cs['W'] = "10110";
cs['X'] = "10111";
cs['Y'] = "11000";
cs['Z'] = "11001";
 
sc["100101"] = 'A';
sc["10011010"] = 'B';
sc["0101"] = 'C';
sc["0001"] = 'D';
sc["110"] = 'E';
sc["01001"] = 'F';
sc["10011011"] = 'G';
sc["010000"] = 'H';
sc["0111"] = 'I';
sc["10011000"] = 'J';
sc["0110"] = 'K';
sc["00100"] = 'L';
sc["10011001"] = 'M';
sc["10011110"] = 'N';
sc["00101"] = 'O';
sc["111"] = 'P';
sc["10011111"] = 'Q';
sc["1000"] = 'R';
sc["00110"] = 'S';
sc["00111"] = 'T';
sc["10011100"] = 'U';
sc["10011101"] = 'V';
sc["000010"] = 'W';
sc["10010010"] = 'X';
sc["10010011"] = 'Y';
sc["10010000"] = 'Z';
sc["101"] = ' ';
sc["010001"] = '.';
sc["000011"] = ',';
sc["10010001"] = '-';
sc["000000"] = '\'';
sc["000001"] = '?';
  
} 

int main(){
  init();
  string s;

  while(getline(cin,s)){

  string bit;
  for(int i=0;i<s.length();i++){
    bit += cs[s[i]];
  }

  int st = 0;
  string ans;
  for(int i=0;i<bit.length();i++){
    if(sc[bit.substr(st,i-st+1)]){
      ans += sc[bit.substr(st,i-st+1)];
      st = i+1;
    }
  }
  cout << ans << endl;
  }

return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
#define pb push_back
#define fi first
#define se second
#define mk make_pair

typedef long long ll;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;

/***********************************************************************/

int fun(vector<int> a, int k){
	for(auto a1 : a)if(a1 > k)return 1;
	return 0 ;
}
void solve_case(){
	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<int>> sum(n + 1, vector<int>(m+1, 0));
	for(int x = 0; x<n; x++){
		for(int y = 0; y<m;y++)
		{
			char c;
			cin >> c;
			sum[x+1][y+1] = (c == '1') ;
		}
	}
	int ans = n * m;
	for(int x = 0; x<(1<<n-1); x++){
		int i = x;
		int co = 0;
		vector<int> keep(n + 2, 0);
		int h = 1;

		while(i){
			co += (i & 1);
			if(i & 1)keep[h] = 1;
			i >>= 1;
			h++;
		}
		bool done = true;
		vector<int> vec(co + 2, 0);
		int interval = 0;
		for(int y = 1; y<= m ; y++){
			vector<int> v(co + 2, 0);
			int u = 1;
			for(int z = 1; z<= n ; z++){
				v[u] += sum[z][y];
				u += keep[z];
			}
			if(fun(v, k))done = false;
			for(int g = 1; g<= co+1; g++)vec[g] += v[g];
			if(fun(vec, k))
			interval++,vec = v;
			if(!done)break;
		}
		if(fun(vec, k))ans++;
		if(done)ans = min(ans, interval + co);

	}
	cout << ans;
 }


int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
 	for(int x =1; x<= t; x++){
 		// cout << "Case #" << x << ": ";
 		solve_case();

 	}
}


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

int main()
{
  int n;

  cin >> n;

  vector<int> a(n, 0);

  int tmp = 0;
  for(int i = 0; i < n - 1; i++){
    cin >> tmp;
    a[tmp - 1] += 1;
  }

  for(int i = 0; i < n; i++){
    cout << a[i] << endl;
  }

  return 0; 
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;



int main(){
  int n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  string s;
  cin >> s;
  int o_n;
  int x_n;
  if(c == d) {cout << "No" << endl; return 0;}
    x_n = 0;
    REP(i,n){
      if((a <= i) && (i <= c)){
        if(s[i] == '.') x_n = 0;
        else x_n++;
        if(x_n >= 2) {cout << "No" << endl; return 0;}
      }
    }
      x_n = 0;
    REP(i,n){
      if((b <= i) && (i <= d)){
        if(s[i] == '.') x_n = 0;
        else x_n++;
        if(x_n >= 2) {cout << "No" << endl; return 0;}
      }
    }
    if(c < d){cout << "Yes" << endl; return 0;}
    o_n = 0;
    if(c > d){
      REP(i,n){
      if((b-1 <= i) && (i <= d+1)){
        if(s[i] == '.') o_n++;
        else o_n = 0;
        if(o_n >= 3) {cout << "Yes" << endl; return 0;}
      }
      }
    }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;


void solve()
{
	int n;
	while (cin >> n, n)
	{
		vector<int> colors(n);
		map<int, int> Map;
		for (int i = 0; i < n; ++i)
		{
			cin >> colors[i];
			Map[colors[i]]++;
		}
		map<int, int>::iterator it = Map.begin();
		while (it != Map.end())
		{
			if (it->second > n / 2)
			{
				cout << it->first << endl;
				goto END;
			}
			++it;
		}
		cout << "NO COLOR" << endl;
	END:
		;
	}
}

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

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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

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

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

int main()
{
    int a,b;
    cin>>a>>b;
    int ans=-1;
REP(i,2000){
    if(i*8/100==a&&i*10/100==b){
        ans=i;
        break;
    }
}
cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int flag = 0;
  for(int i = 0; i < S.size(); i++){
    if(flag == 0 && S.at(i) == 'C')flag++;
    if(flag == 1 && S.at(i) == 'F'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

int main() {
	int n, m;
	cin >> n >> m;
	if (n * 500 >= m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (998244353)
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long n;
        cin >> n;

        set<string> s;
        while (n--) {
            string x;
            cin >> x;
            s.insert(x);
        }
        long ans = s.size();
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 19256
t1,t2 = map(int,input().split())

a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
c1 = b1-a1
c2 = b2-a2

s = t1*c1
t = s + t2*c2
# print(c1,c2,s,t)
ans = -1
if s * t > 0:
    ans = 0
elif t == 0:
    ans=-10
else:
    if s > t:
        tt = abs(t)
        ans = -((-s / tt)//1)*2 - 1
        if s / tt - s//tt < 10**-25:
            ans += 1
    else:
        ss = abs(s)
        ans = -((-ss / t)//1)*2 - 1
        if ss / t -ss//t < 10**-25:
            ans += 1
if ans == -10:
    print("infinity")
else:
    print(int(ans))

Measured memory_bytes: 38516
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC113_C{
    struct P{
        public int city;
        public int year;
        public int id;
        public int number;
        public P(int city,int year,int id){
            this.city = city;
            this.year = year;
            this.id = id;
            this.number = 1;

        }
    }
    class Program{
        static void Main(string[] args){
            var line = Console.ReadLine().Split(' ');
            var N = int.Parse(line[0]);
            var M = int.Parse(line[1]);
            var list = new List<P>();

            for(var i = 0;i < M;i++){
                var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                list.Add(new P(input[0],input[1],i));
            }
            
            var list2 = list.OrderBy(x => x.city).ThenBy(x => x.year).ToArray();
            
            var temp = list2[0].city;
            var numTemp = 1;
            list2[0].number = numTemp;

            for(var i = 1;i < M;i++){
                if(temp == list2[i].city){
                    list2[i].number = ++numTemp;
                }else{
                    numTemp = 1;
                    list2[i].number = numTemp;
                    temp = list2[i].city;
                    
                }
            }

            foreach(var i in list2.OrderBy(x => x.id)){
                Console.WriteLine($"{i.city:D6}{i.number:D6}");
            }




        }
    }
}


Measured memory_bytes: 32648
import java.util.Scanner;
import java.util.Stack;

public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Stack<Integer> calc = new Stack<>();
        String n = scan.nextLine();
        for(int r = 0; r < n.length(); r++){
            if(n.charAt(r) == ' '){
            }
            else if(n.charAt(r) == '+' || n.charAt(r)== '-' || n.charAt(r)== '*' || n.charAt(r)== '/'){
                int y = calc.pop();
                int x = calc.pop();
                if(n.charAt(r)== '+'){
                    x = x + y;
                    calc.push(x);
                }
                else if(n.charAt(r)== '-'){
                    x = x - y;
                    calc.push(x);
                }
                else if(n.charAt(r)== '*'){
                    x = x * y;
                    calc.push(x);
                }
                else{
                    x = x/y;
                    calc.push(x);
                }
            }
            else{
                String num = "";
                for(int p = r; p < n.length(); p++) {
                    if(Character.isDigit(n.charAt(p))){
                        num = num + Character.toString(n.charAt(p));
                    }
                    else{
                        r = p;
                        p = n.length();
                    }
                }
                calc.push(Integer.parseInt(num));
            }
        }
        System.out.println(calc.pop());
    }
}


Measured memory_bytes: 26192
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,X;
    cin >> N >> X;
    vector<int> m(N);
    for(int i = 0; i < N; i++) cin >> m[i];
    for(int i = 0; i < N; i++) X -= m[i];
    int Count = N;
    sort(m.begin(),m.end());
    while(X > 0){
        X -= m[0];
        if(X < 0) break;
        Count++;
    }
    cout << Count << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main()
{
	string s;
	cin >> s;
	int cnt[26] = {0};
	for(int i = 0 ; i < s.size() ; i++)
		cnt[s[i] - 'a']++;
	for(int i = 0 ; i < 26 ; i++)
	{
		if(!cnt[i])
		{
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//using ll=long long;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//dp注意点
//問題の種類	 初期化する値	 備考
//最小化問題 	INF	
//最大化問題	    -INF	 テーブル全体で 00 以上の値しかとらないことがわかっていれば −1−1 でもいいですし、00 でもいい場合もあります
//数え上げ問題	00	
//確率問題	      00	
//Yes/No 判定問題	False
/*-------------ここまで---------------------------------------------*/

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

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

typedef struct{
	int parent,left,right;
}Node;

void prePause(int u);
void inPause(int u);
void postPause(int u);

Node *T;

int main(){
	int n; cin>>n;
	T = new Node[n];

	for(int i=0;i<n;i++) T[i].parent = T[i].left = T[i].right = -1;
	for(int i=0;i<n;i++){
		int id; cin>>id;
		cin>>T[id].left>>T[id].right;
		if(T[id].left!=-1) T[T[id].left].parent = id;
		if(T[id].right!=-1) T[T[id].right].parent = id;
	}
	int root;
	for(int i=0;i<n;i++)
		if(T[i].parent==-1) root = i;

	cout<<"Preorder"<<endl;
	prePause(root);
	cout<<endl;

	cout<<"Inorder"<<endl;
	inPause(root);
	cout<<endl;

	cout<<"Postorder"<<endl;
	postPause(root);
	cout<<endl;

	delete [] T;
}

void prePause(int u){
	if(u==-1) return;
	cout<<" "<<u;
	prePause(T[u].left);
	prePause(T[u].right);
}

void inPause(int u){
	if(u==-1) return ;
	inPause(T[u].left);
	cout<<" "<<u;
	inPause(T[u].right);
}

void postPause(int u){
	if(u==-1) return;
	postPause(T[u].left);
	postPause(T[u].right);
	cout<<" "<<u;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <cmath>

int a()
{
    int a, b;
    std::cin >> a >> b;
    
    int odd = a * (a - 1) / 2;
    int even = b * (b - 1) / 2;
    
    std::cout << odd+even;
    
    return 0;
}

int main(int argc, const char * argv[])
{
    a();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long n,dp[100001],a[100001];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    dp[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n];
}

Measured memory_bytes: 5100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 100001;
int dp[N][3];
int A[N], B[N], C[N];
int n;
int solve(int in, int lst){
  int& res = dp[in][lst];
  if(res != -1)
    return res;
  res = 0;
  if(lst != 0)
    res = max(res, solve(in + 1, 0) + A[in]);
  if(lst != 1)
    res = max(res, solve(in + 1, 1) + B[in]);
  if(lst != 2)
    res = max(res, solve(in + 1, 2) + C[in]);
  return res;
}
int main() {
//  freopen("transform.in", "r", stdin);
//  freopen("in.txt", "r", stdin);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for(int i = 0;i < n;i++)
    cin >> A[i] >> B[i] >> C[i];
  int res = solve(1, 0) + A[0];
  res = max(res, solve(1, 1) + B[0]);
  res = max(res, solve(1, 2) + C[0]);
  cout << res;
  return 0;
}


Measured memory_bytes: 8832
h,w=map(int,input().split())
a=[input() for _ in range(h)]
b=[[h*w]*w for _ in range(h)]
b[0][0]=1
d=[(0,0)]
while d:
    y,x=d.pop(0)
    for i,j in([1,0],[-1,0],[0,1],[0,-1]):
        t,u=y+i,x+j
        if h>t>=0<=u<w and a[t][u]=="." and b[t][u]>b[y][x]+1:
            d+=[(t,u)]
            b[t][u]=b[y][x]+1
print(max(-1,sum([i.count(".") for i in a])-b[-1][-1]))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		if(n == 1){
			System.out.println(0);
			return;
		}

		long all = 1;
		long no0 = 1;
		long no9 = 1;
		long no19 = 1;

		int mod = 1_000_000_007;
		long result = (long)n * (n - 1) % mod;

		for(int i = 2; i < n; i++){
			result *= 10;
			result %= mod;
		}

		for(int i = 0; i < n; i++){
			all *= 10; all %= mod;
			no0 *= 9; no0 %= mod;
			no9 *= 9; no9 %= mod;
			no19 *= 8; no19 %= mod;
		}
//		System.out.println(all + " " + no0 + " " + no9 + " " + no19);

		result = (all + no19 + (mod - no9) + (mod - no0))%mod;

		System.out.println(result);
	}
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

ll digits(ll num){
  st numst = to_string(num);
  return numst.size();
}

int main(){
  ll n;
  cin >> n;
  ll ans = mod;
  for(ll i = 1; i * i <= n; i++){
    if(n % i == 0) if(max(digits(i), digits(n / i)) < ans) ans = max(digits(i), digits(n / i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int d; cin >> d;
	// 監視員は地震のいる木とあとD本みれる
	int a = 2*d+1 ;
	if(n%a ==0){
		cout << n/a<<endl;
		}
		else {
		  cout << n/a + 1 << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define F first
#define S second
#define MP m ake_pair
#define LB lower_bound
#define UB upper_bound

using namespace std;
typedef long long ll;
typedef pair<int , int> pii;
typedef long double DB;

const int N = 200100;
int d[N] , a[N];

int main(){

	ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	
	int n , ans(0);
	cin >> n;

	for(int i = 0 ; i < n ; i++)
	   cin >> a[i];
	
	for(int i = n-1 ; i >= 0 ; i--){
	   d[a[i]] = d[a[i]+1] + 1;
	   ans = max(ans , d[a[i]]);
	}
	
	cout << n-ans << endl;

	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll x;
    cin>>x;
    for(ll a=-118;a<=119;a++){
        for(ll b=-119;b<=118;b++){
            if(pow(a,5)-pow(b,5)==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4012
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll N;
    cin >> N;
    VS S(N);
    ll cnt=0;
    ll c1=0,c2=0,c3=0;
    rep(i,0,N){
        cin >> S[i];
        rep(j,0,S[i].size()-1){
            if(j!=S[i].size()-1)if(S[i][j]=='A'&&S[i][j+1]=='B')cnt++;
        }
        if(S[i][S[i].size()-1]=='A'&&S[i][0]=='B'){
            c1++;
        }
        else if(S[i][S[i].size()-1]!='A'&&S[i][0]=='B'){
            c2++;
        }
        else if(S[i][S[i].size()-1]=='A'&&S[i][0]!='B'){
            c3++;
        }
    }
    ll ans=0;
    if(c1==0)ans=cnt+min(c2,c3);
    else if(c1!=0){
        if(c2+c3>0)ans=cnt+c1+min(c2,c3);
        else if(c2+c3==0)ans=cnt+c1-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
  stack<int> S;
  while (1){
    string s;
    cin >> s;
    if (s == ""){
      cout << S.top() << endl;
      break;
    } else if (s == "+"){
      int A = S.top();
      S.pop();
      int B = S.top();
      S.pop();
      S.push(B + A);
    } else if (s == "-"){
      int A = S.top();
      S.pop();
      int B = S.top();
      S.pop();
      S.push(B - A);
    } else if (s == "*"){
      int A = S.top();
      S.pop();
      int B = S.top();
      S.pop();
      S.push(B * A);
    } else {
      int v = 0;
      for (int i = 0; i < s.size(); i++){
        v *= 10;
        v += (s[i] - '0');
      }
      S.push(v);
    }
  }
}


Measured memory_bytes: 3156
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int A;
        cin >> A;

        if (A%2==0)
        {
                cout << A << endl;
        } else{
                cout << A * 2 << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0


int main(){
	int n,a;
	string in;
	vector<int> data;
	
	while(getline(cin,in)){
		data.clear();
		stringstream ss(in);
		ss>>n;
		while(ss>>a){
			data.push_back(a);
		}

		sort(all(data));

		int l,r,lr,rr;
		bool f = false;
		
		rep(t,2){
			double sum = 0.0;
			int sz = 1;
			int r1,r2,a;
			if( t==0 ){
				l = 0 , r = data.size()-2;
				lr = rr = data[data.size()-1];
			}else{
				l = data.size()-1, r = 1;
				lr = rr = data[0];
			}
			if( data.size()==1 ){
				if( data[0]<=n ){
					f = true;
					break;
				}
			}

#if DEB
			printf("t:%d --------------------\n",t);
			printf("(l,r)=(%d,%d)   init_r:%d\n",l,r,rr);
#endif			
			
			for(;sz<data.size();){
				r1 = data[l]+lr;
				r2 = abs(data[l]-lr);
				a = r1*r1 - r2*r2;
				sum += sqrt((double)a);
				lr = data[l];

#if DEB
				printf("sz:%d  l:%d  lr:%d  sum:%lf\n",sz+1, l, lr, sum);
#endif				

				if( t==0 )l++;
				else l--;
				sz++;
				if( sz==data.size() ) break;
				
				r1 = data[l]+rr;
				r2 = abs(data[l]-rr);
				a = r1*r1 - r2*r2;
				sum += sqrt((double)a);
				rr = data[l];

#if DEB
				printf("sz:%d  l:%d  rr:%d  sum:%lf\n",sz+1, l, rr, sum);
#endif				
				
				
				if( t==0 )l++;
				else l--;
				sz++;
				if( sz==data.size() ) break;
				
				r1 = data[r]+lr;
				r2 = abs(data[r]-lr);
				a = r1*r1 - r2*r2;
				sum += sqrt((double)a);
				lr = data[r];

#if DEB
				printf("sz:%d  r:%d  lr:%d  sum:%lf\n",sz+1,r,lr,sum);
#endif
				
				if( t==0 )r--;
				else r++;
				sz++;
				if( sz==data.size() ) break;
				
				r1 = data[r]+rr;
				r2 = abs(data[r]-rr);
				a = r1*r1 - r2*r2;
				sum += sqrt((double)a);
				rr = data[r];

#if DEB
				printf("sz:%d  r:%d  rr:%d  sum:%lf\n",sz+1,r,rr,sum);
#endif
				
				if( t==0 )r--;
				else r++;
				sz++;
				if( sz==data.size() ) break;
			}
			sum += (double)(lr+rr);
#if DEB
			printf("sum:%lf\n",sum);
#endif			
			if( sum<=(double)n ){
				f = true;
			}
		}
		puts(f?"OK":"NA");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i = 0;i < N;i++){
    cin >> P.at(i);
  }
  int count = 0,a = 0,b = 0,c = 0;
  for(int i = 1;i < N - 1;i++){
    a = P.at(i - 1);
    b = P.at(i);
    c = P.at(i + 1);
    if(a < b && b < c){
      count++;
    }else if(a > b && b > c){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3616
N = int(input())
A = list(map(int, input().split()))
s = 0
P = (A[0:N])
Q = A
for i in range(N-1):
    if Q[i] < Q[i+1]:
        Q[i+1] = Q[i]
for i in range(N):
    if P[i] == Q[i]:
        s += 1
print(s)

Measured memory_bytes: 76240