akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <vector>
#include <string>
using namespace std;

void Output(vector<string>& C)
{
    for (int i = 0; i < C.size(); ++i) {
        cout << C[i];
        if (i != C.size() - 1) {
            cout << " ";
        }
    }
    cout << endl;
}

vector<string> BubbleSort(vector<string> C)
{
    for (int i = 0; i < C.size() - 1; ++i) {
        for (int j = C.size() - 1; j > i; --j) {
            if (C[j-1][1] > C[j][1]) {
                swap(C[j-1], C[j]);
            }
        }
    }
    return C;
}

vector<string> SelectionSort(vector<string> C)
{
    for (int i = 0; i < C.size() - 1; ++i) {
        string minC = C[i];
        int idx = i;
        for (int j = i + 1; j < C.size(); ++j) {
            if (C[j][1] < minC[1]) {
                minC = C[j];
                idx = j;
            }
        }
        if (idx != i) {
            swap(C[i], C[idx]);
        }
    }
    return C;
}

bool IsStableSort(vector<string>& C1, vector<string>& C2)
{
    for (int i = 0; i < C1.size() - 1; ++i) {
        for (int j = i + 1; j < C1.size(); ++j) {
            if (C1[i][1] == C1[j][1]) {
                for (int k = 0; k < C2.size() - 1; ++k) {
                    for (int l = k + 1; l < C2.size(); ++l) {
                        if (C1[i] == C2[l] && C1[j] == C2[k]) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}

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

    vector<string> C;
    for (int i = 0; i < n; ++i) {
        string c;
        cin >> c;
        C.push_back(c);
    }

    vector<string> Cb = BubbleSort(C);
    Output(Cb);
    if (IsStableSort(C, Cb)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    vector<string> Ci = SelectionSort(C);
    Output(Ci);
    if (IsStableSort(C, Ci)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }

    return 0;
}


Measured memory_bytes: 3208
#include <iostream>

typedef long long ll;

ll gcd(ll a, ll b){ 
   if(a<b) return gcd(b,a);
   ll r;
   while(r=a%b){
      a = b;
      b = r;
   }   
   return b;
}

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

int main(){
   int N, M;
   std::cin >> N >> M;
   ll A[N];
   for(int i=0; i<N; ++i){
      std::cin >> A[i];
      A[i] /= 2;
   }
   ll x = 0;
   ll tmp = A[0];
   while(tmp%2==0) tmp /= 2, ++x;
   ll t = A[0];
   for(int i=1; i<N; ++i){
      t = lcm(t, A[i]);
      ll y = 0;
      tmp = A[i];
      while(tmp%2==0) tmp /= 2, ++y;
      if(x!=y) {
	 std::cout << 0 << std::endl;
	 return 0;
      }
   }
   int ans = M/t;
   ans = (ans%2==0 ? ans/2 : ans/2+1);
   std::cout << ans << std::endl;
   return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};


vector<pair<long long,long long>> prime_factorization(ll N) {
    vector<pair<long long, long long>> res;
    for(ll p=2; p*p <= N; p++) {
	if(N % p != 0) continue;
	int ex = 0;          //exponetial part
	while(N%p == 0) {
	    ex++;
	    N/=p;
	}
	res.push_back({p,ex});
    }
    if(N!=1) {
	res.push_back({N,1});
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    ll ans = 0;
    vector<pair<long long, long long>> pf;
    for(int c=1; c <= N-1; c++) {
	int nc = N-c;
	for(int a = 1; a*a <= nc; a++) {
	    if(nc % a == 0) {
		if(a * a == nc) ans++;
		else ans += 2;
	    }
	}
    }
    cout << ans << endl;

    

    return 0;
}



Measured memory_bytes: 3628
n = int(input())
count = -1
ans = []
a = list(map(int,input().split()))
for i in range(n-1):
    if(a[i] >= a[i+1]):
        count += 1
        ans.append(count+1)
    else:
        count = -1
        ans.append(count+1)
if(len(a) == 1):
    print(0)
else:
    print(max(ans))

Measured memory_bytes: 14252
import std.stdio : readln, writeln, chomp, stdin;
import std.conv : to;
import std.algorithm : min, max;

void solve()
{
	double V=0;
	double M=cast(double)(1<<28);
	while(true){
		string str = readln.chomp;
		
		if(stdin.eof())	break;
		
		double d = str.to!double;
		V = max(d, V);
		M = min(d, M);
	}
	writeln = V-M;
}

void main()
{
	solve();
}

Measured memory_bytes: 1068
unittest
{
	assert( [ "2", "12 5", "1000 2000" ].parse.expand.solve == 1 );
	assert( [ "3", "21 -11", "81234 94124 52141" ].parse.expand.solve == 3 );
}



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

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

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

auto solve( long t, long a, long[] hs )
{
	auto m = real.max;
	auto r = -1L;
	auto i = 1L;
	
	foreach( h; hs.map!( ( x ) => t - x * 0.006f ) )
	{
		auto d = ( h - a ).abs;
		if( d < m )
		{
			m = d;
			r = i;
		}
		i++;
	}
	
	return r;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int cnt = 0;

  rep(i,n) if(i % 2 == 0 && a[i] % 2 != 0) cnt++;
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
	int n;
	scanf("%d", &n);
	char* input = (char*)malloc((n + 1) * sizeof(char));
	scanf("%s", input);
	int tick = 0;
	n -= 2;
	for (int i = 0; i < n;)
	{
		if (*(input + i) == 'A' && *(input + i + 1) == 'B' && *(input + i + 2) == 'C') tick++, i += 3;
		else i++;
	}
	printf("%d", tick);
}

Measured memory_bytes: 128
N = int(input())
S = input()

#条件1を満たす(i,j,k)の組→R,G,Bの選び方
r,g,b = S.count('R'),S.count('G'),S.count('B')

ans = r*g*b

for i in range(N):
    for j in range(i+1,N):
        k = 2*j - i
        if k >= N:
            break
        else:
            if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
                ans -= 1

print(ans)


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;

signed main(){
    int n, l, q;
    cin >> n;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;

    cin >> l >> q;

    // dp[i][j]: iから2^j回移動した時にたどり着ける最大値
    vector<vector<int>> dp(n, vector<int>(32, 0));
    for(int i = 0; i < n; ++i)
        dp[i][0] = distance(a.begin(), prev(upper_bound(a.begin(), a.end(), a[i] + l)));
    for(int j = 1; j < 32; ++j)
        for(int i = 0; i < n; ++i)
            dp[i][j] = dp[dp[i][j - 1]][j - 1];

    // xからy回移動した時
    auto f = [&](int x, int y){
        int j = 0;
        int i = y & 1 ? dp[x][0] : x;
        while(++j, y >>= 1)
            if(y & 1)
                i = dp[i][j];

        return i;
    };

    for(int i = 0; i < q; ++i){
        int l, r;
        cin >> l >> r;
        --l, --r;
        if(l > r)
            swap(l, r);

        int st = 0, en = (1 << 30);
        while(en - st > 1){
            int mid = (st + en) >> 1;
            (f(l, mid) >= r ? en : st) = mid;
        }
        cout << en << endl;
    }

}


Measured memory_bytes: 17664
/* 162-A.cpp
 *     Created on : Apr 12, 2020 
 *     Time       : 5:59:46 PM
 *     Author     : null_ptr
 */

#include<bits/stdc++.h>
using namespace std;

int main()
{
	string str;
	cin>>str;
	bool chk=false;
	for(int i=0;i<(int)str.size();++i)
		if(str[i]=='7')chk=true;

	if(chk)cout<<"Yes\n";
	else cout<<"No\n";
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		int x = n % 10;
		if (x == 2) {
			ans++;
		}
		n = n / 10;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
ll in(){ ll x; cin >> x; return x; }
vector<ll> in(size_t n){ vector<ll> v(n); each(x, v) cin >> x; return v; }
/* ]]] */

ll fc[200010];

ll pwr(ll x, ll y){
  ll s = 1;
  while (y){
    if (y & 1) s = s * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return s;
}

ll inv(ll x){
  return pwr(x, mod - 2);
}

ll cmb(ll x, ll y){
  return fc[x] * inv(fc[y]) % mod * inv(fc[x - y]) % mod;
}

int main(){
  fc[0] = 1;
  rep(i, 1, 200010) fc[i] = fc[i - 1] * i % mod;

  ll h, w, a, b;
  cin >> h >> w >> a >> b;
  ll s = 0;
  rep(i, b, w){
    ll t = cmb(i + (h - a - 1), i);
    ll u = cmb((w - i - 1) + (a - 1), w - i - 1);
    s = (s + t * u % mod) % mod;
  }

  cout << s << endl;
}


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

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

typedef long long ll;

int main() {
    int a,b;cin>>a>>b;
  if((a*b)%2==0)cout<<"Even"<<endl;
  else cout<<"Odd"<<endl;
//    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 2e5;
ll a[maxn];

int main () {
    int n, k;
    cin >> n >> k;
    for (int i=1; i<=n; i++) {
       cin >> a[i];
    }
    sort(a+1, a+1+n);
    ll ans = 0;
    for (int i=1; i<=n-k; i++) {
      ans += a[i];
    } 

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


Measured memory_bytes: 5216
#include<bits/stdc++.h>
using namespace std ;
const long long N = 1e6 + 5 ; 
char tql[N] ; 
long long QAQ[N][2] ;
signed main()
{
	scanf("%s", tql + 1 ) ;
	long long n = strlen( tql + 1 ), Ans = 0 ; tql[0] = '0' ;
	QAQ[n + 1][0] = 0, QAQ[n + 1][1] = 100 ;
	for( register long long qwq = n; qwq >= 0; -- qwq ) {
		long long orz = tql[qwq] - '0' ; 
		QAQ[qwq][1] = min( QAQ[qwq + 1][1] - orz - 1, QAQ[qwq + 1][0] - orz ) + 10 ;
		QAQ[qwq][0] = min( QAQ[qwq + 1][1] + orz + 1, QAQ[qwq + 1][0] + orz ) ;
	}
	cout << QAQ[0][0] << endl ;
	return 0 ;
}

Measured memory_bytes: 16896
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        _n: usize,
        m: usize,
        lr: [(i32, i32); m],
    }
    let mut l_list = Vec::new();
    let mut r_list = Vec::new();
    for elem in lr {
        l_list.push(elem.0);
        r_list.push(elem.1);
    }

    let ans = r_list.iter().min().unwrap() - l_list.iter().max().unwrap() + 1;
    if ans > 0 {
        println!("{}", ans);
    } else {
        println!("0");
    }
}

Measured memory_bytes: 4968
package main

import (
	"fmt"
	"math"
)

func normalize(a float64) float64 {
	if a >= 360 {
		return normalize(a - 360)
	}
	return a
}

func calcDiff(a float64, b float64) float64 {
	var deg = math.Abs(a - b)
	return deg
}

func main() {
	var a, b, h, m int
	fmt.Scanf("%d %d %d %d %d", &a, &b, &h, &m)

	var min float64 = (float64) (h * 60 + m)
	var degA float64 = min / 60 / 12 * 360
	degA = normalize(degA)
	var degB float64 = min / 60 * 360
	degB = normalize(degB)
	var deg = calcDiff(degA, degB)
	// fmt.Printf("min=%g, degA= %g, degB = %g, deg=%g", min, degA, degB, deg)

	// 余弦定理
	// c^2 = a^2 + b^2 - 2ab cosAB
	var cos float64 = math.Cos(deg * float64(math.Pi / 180))
	var c2 float64 = float64(a * a + b * b) - float64(2 * a * b) * cos
	var c = math.Sqrt(c2)
	fmt.Print(c)
}


Measured memory_bytes: 1852
import bisect

a=[]
s=[]
def asff(a,b,s,n):
    m=bisect.bisect(a,b)
    if m<=0:
        asf=-n*b+s[n-1]
    elif m<n:
        asf=(2*m-n)*b+s[n-1]-2*s[m-1]
    elif n<=m:
        asf=n*b-s[n-1]
    return asf

n=int(input())
a=list(map(int,input().split()))

#n=5
#stra="2 2 3 5 5"
#ans=2

#n=9
#stra="1 2 3 4 5 6 7 8 9"
#ans=0

#n=6
#stra="6 5 4 3 2 1"
#ans=18

#n=7
#stra="1 1 1 1 2 3 4"
#ans=6

#a=list(map(int,stra.split()))

for i in range(n):
    a[i]=a[i]-i-1
#print(a)
a.sort()

s=[a[0]]
for i in range(1,n):
    s.append(s[i-1]+a[i])
    
bmin=min(a)-n
bmax=max(a)+n

b1=bmin
b5=bmax+1
b2=b1+int((b5-b1)/4)
b3=b1+int((b5-b1)/2)
b4=b1+int((b5-b1)/4*3)
#b2=b1+(b5-b1)//4
#b3=b1+(b5-b1)//4*2
#b4=b1+(b5-b1)//4*3
#print("b1",b1,"b5",b5)
    
asmin=bmax*n
#m0=0
m1=bisect.bisect(a,bmin)


while b1+1<b5:
    c=[]
    c.append([asff(a,b1,s,n),b1])
    c.append([asff(a,b2,s,n),b2])
    c.append([asff(a,b3,s,n),b3])
    c.append([asff(a,b4,s,n),b4])
    c.append([asff(a,b5,s,n),b5])
    c.sort()
    asf=c[0][0]
    d=[]
    d.append(c[0][1])
    d.append(c[1][1])
    d.append(c[2][1])
    d.sort()
    b1=d[0]
    b5=d[2]
    b2=b1+int((b5-b1)/4)
    b3=b1+int((b5-b1)/2)
    b4=b1+int((b5-b1)/4*3)
    
#    print("b1",b1,"b5",b5,"d0",d[0],"asf",asf)
    if asf<asmin:
        asmin=asf

print(asmin)

Measured memory_bytes: 25424
#include<bits/stdc++.h>
//#define N 500000
using namespace std;
struct Node{
	int key;
	Node *right,*left,*par;
};
int n;
Node *root,*Nil;

void insert(int k){
	Node *y = Nil;
	Node *x = root;
	Node *z;

	z = (Node*)malloc(sizeof(Node));
	z->key = k;
	z->left = Nil;
	z->right = Nil;
	while(x != Nil){
		y = x;
		if(z->key < x->key) x = x->left; //左の子へ移動
		else x = x->right; //右の子へ移動
	}
	z->par = y;
	
	if(y == Nil) root = z; //Tが空の場合
	else{
	  if(z->key < y->key) y->left = z; //zを左の子にする
	  else y->right = z; //zをyの右の子にする
	 }
	}
Node *find(Node *u,int k){
  while(u != Nil && u->key != k){
    if(k < u->key){
      u = u->left;
    }else{
      u = u->right;
    }
  }
  return u;
}

void inorder(Node *u){
  if(u == Nil) return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}

void preorder(Node *u){
  if(u == Nil) return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}

int main(){
	int val=0;
	string str;
	
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> str;
		if(str == "find"){
		  cin >> val;
		  Node *jud = find(root,val);
		  if(jud != Nil) cout << "yes" << endl;
		  else cout << "no" << endl;
		}else if(str == "insert"){
		  cin >> val;
		  insert(val);
		}else if(str == "print"){
		  inorder(root);
		  cout << endl;
		  preorder(root);
		  cout << endl;
		} 
	}
}



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

#define int long long

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

int N;
int a[50], b[50];
bool as[50][51], as_kari[50][51];

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        as[i][a[i]] = true;
        as_kari[i][a[i]] = true;
    }
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }
    int ok_kari[50] = {};
    for (int i = 50; i >= 1; i--) {
        for (int j = 0; j < N; j++) {
            for (int l = 50; l >= 0; l--) {
                if (as_kari[j][l]) {
                    as_kari[j][l % i] = true;
                }
            }
            if (as_kari[j][b[j]]) {
                ok_kari[j] = true;
            }
        }
    }
    for (int i = 0; i < N; i++) {
        if (!ok_kari[i]) {
            cout << -1 << endl;
            return 0;
        }
    }

    int ans = 0;
    bool ok[50] = {};
    for (int i = 50; i >= 1; i--) {
        bool ok_cpy[50] = {};
        bool as_cpy[50][51] = {};
        for (int j = 0; j < 50; j++) {
            for (int k = 0; k <= 50; k++) {
                as_cpy[j][k] = as[j][k];
            }
        }
        for (int j = i - 1; j >= 1; j--) {
            for (int k = 0; k < N; k++) {
                for (int l = 50; l >= 0; l--) {
                    if (as_cpy[k][l]) {
                        as_cpy[k][l % j] = true;
                    }
                }
            }
        }
        for (int k = 0; k < N; k++) {
            if (as_cpy[k][b[k]]) {
                ok_cpy[k] = true;
            }
        }
        for (int k = 0; k < N; k++) {
            if (!(ok[k] || ok_cpy[k])) {
                for (int l = 0; l < N; l++) {
                    for (int m = 50; m >= 0; m--) {
                        if (as[l][m]) {
                            as[l][m % i] = true;
                        }
                    }
                    if (as[l][b[l]]) {
                        ok[l] = true;
                    }
                }
                ans += 1LL << i;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void dfs(vector<vector<vector<int>>> &g,vector<int> &p,bool &f,vector<bool> &c,int x){
  if(!f)
    return;
  c.at(x)=1;
  for(auto v:g.at(x)){
    int y=v.at(0);
    int d=v.at(1);
    if(c.at(y)){
      if(p.at(y)!=p.at(x)+d)
        f=0;
      continue;
    }
    p.at(y)=p.at(x)+d;
    dfs(g,p,f,c,y);
  }
  return;
}
int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<vector<int>>> g(n);
  for(int i=0;i<m;i++){
    int l,r,d;
    cin>>l>>r>>d;
    l--;
    r--;
    g.at(l).push_back({r,d});
    g.at(r).push_back({l,-d});
  }
  vector<int> p(n,0);
  bool f=1;
  vector<bool> c(n,0);
  for(int i=0;i<n;i++){
    if(c.at(i))
      continue;
    dfs(g,p,f,c,i);
  }
  cout<<(f?"Yes":"No")<<endl;
}

Measured memory_bytes: 39292
#include<stdio.h>
int a[1111],b[1111],c[1111],d[1111],p[1111],i,j,x,y,z;
main(){
  for(;scanf("%d%d%d",a,b,c)&&(*a+=*b+*c);){
    for(i=0,scanf("%d",p);i++<*p;scanf("%d%d%d%d",a+i,b+i,c+i,d+i),p[i]=2);
    for(;--i;)
      for(j=0;j++<*p;d[j]?p[a[j]]=p[b[j]]=p[c[j]]=1:(x=p[a[j]]&1)&(y=p[b[j]]&1)?p[c[j]]=0:x&(z=p[c[j]])?p[b[j]]=0:y&z?p[a[j]]=0:0);
    for(i=0;i<*a;printf("%d\n",p[++i]));
  }return 0;
}

Measured memory_bytes: 620
#include <iostream>

int main()
{
    int n;

    std::cin >> n;

    int card[4][13] = {};

    char suit;
    int rank;
    for (int i = 0; i < n; i++)
    {
        std::cin >> suit >> rank;

        if (suit == 'S') card[0][rank-1]++;
        else if (suit == 'H') card[1][rank-1]++;
        else if (suit == 'C') card[2][rank-1]++;
        else if (suit == 'D') card[3][rank-1]++;
    }

    for (int i = 0; i < 4; i++)
    {
        if (i == 0) suit = 'S';
        else if (i == 1) suit = 'H';
        else if (i == 2) suit = 'C';
        else if (i == 3) suit = 'D';

        for (int j = 0; j < 13; j++)
        {
            if (card[i][j] == 0) std::cout << suit << " " << j + 1 << std::endl;
        }
    }
}


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

using namespace std;

int dfs(int pos, const int a, const int b, vector<vector<int> > &graph, vector<bool> &memo) {
  memo[pos] = true;
  int res = 1;
  for (auto next: graph[pos]) {
    if ((pos == a && next == b) ||
        (pos == b && next == a)) {
      continue;
    }
    if (memo[next]) {
      continue;
    }
    res += dfs(next, a, b, graph, memo);
  }
  return res;
}

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

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      vector<bool> memo(N, false);
      if (dfs(0, i, j, graph, memo) != N) {
        ans += 1;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,W,cnt = 0;
    cin >> H >> W;
    int a[502][502];
    vector<int> ans(0);
    for(int i = 1;i <= H;i ++){
        for(int j = 1;j <= W;j ++){
            cin >> a[i][j];
        }
    }
    for(int i = 1;i <= H;i ++){
        if(i%2)for(int j = 1;j <= W;j ++){
            if(j==W && a[i][j]%2 && i!=H){
                cnt++;
                a[i+1][j] ++;
                ans.push_back(i);
                ans.push_back(j);
                ans.push_back(i+1);
                ans.push_back(j);
            }else if(a[i][j]%2 && j!= W){
                cnt++;
                a[i][j+1] ++;
                ans.push_back(i);
                ans.push_back(j);
                ans.push_back(i);
                ans.push_back(j+1);
            }
        }else for(int j = W;j >= 1;j --){
            if(j==1 && a[i][j]%2 && i!=H){
                cnt++;
                a[i+1][j] ++;
                ans.push_back(i);
                ans.push_back(j);
                ans.push_back(i+1);
                ans.push_back(j);
            }else if(a[i][j]%2 && j!= 1){
                cnt++;
                a[i][j-1] ++;
                ans.push_back(i);
                ans.push_back(j);
                ans.push_back(i);
                ans.push_back(j-1);
            }
        }
    }
    cout << cnt << endl;
    for(int i = 0;i < cnt;i ++){
        cout << ans[4*i] << " "
             << ans[4*i+1] << " "
             << ans[4*i+2] << " "
             << ans[4*i+3] << endl;
    }
    return 0;
}



Measured memory_bytes: 5232
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<n;++i)

typedef long long ll;
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<pair<ll, ll>> p(n);
    REP(i, n){
        cin >> a[i] >> b[i];
        p[i] = make_pair(a[i], b[i]);
    }
    sort(p.begin(), p.end());

    ll cnt = 0, ans = 0;
    REP(i, n){
        if(cnt+p[i].second<m){
            cnt += p[i].second;
            ans += p[i].first*p[i].second;
        } else {
            REP(j, p[i].second){
                ++cnt;
                ans += p[i].first;
                if(cnt==m){
                    i=n;
                    break;
                }
            }
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main()
{int w,a,b;cin>>w>>a>>b;int x=abs(a-b);


if(x>w)
{
if(a==b)
{cout<<"0";}
if(a>b)
{cout<<a-b-w;}
if(b>a)
{cout<<b-a-w;}
}
if(x<=w)
{cout<<"0";}


return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;

using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n, m, K;
	char tmp;
	ll memo[1003][1003] = { {} };
	ll memox[1003] = {};
	ll memoy[1003] = {};
	ll x[1000006] = {};
	ll y[100005] = {};
	ll z[100005] = {};
	string s;

	//IntStack yStack;
	//charStack Stack;

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


	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;
	
	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 8064
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll x = a.front();
    ll s = 0;
    rep(i,n) {
        s^=a[i];
    }
    s^=x;
    if (s==x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int l = sc.nextInt();
    int r = sc.nextInt();
    int d = sc.nextInt();

    int count = 0;

    for (int i = l; i <= r; i++) {
      if (i%d == 0) {
        count++;
      }
    }

    System.out.println(count);

  }

}


Measured memory_bytes: 35708
import java.util.Scanner;

public class Main {

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

		for (int i = 0; i < n; i++) {
			if (sc.nextInt() >= k) {
				result++;
			}
		}
		System.out.println(result);
		sc.close();
	}

}


Measured memory_bytes: 46688
num = list(map(int, input().split()))

if (num[0] == num[1]):
    if (num[1] == num[2]):
        print("No")
    else:
        print("Yes")
else:
    if (num[1] == num[2]):
        print("Yes")
    else:
        if (num[0] == num[2]):
            print("Yes")
        else:
            print("No")


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

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

    vector<int> left(Q);
    vector<int> right(Q);
    vector<int> sum(N+1,0);

    for(int i=0; i<Q; i++){
        cin>>left[i]>>right[i];
    }

    for(int i=1; i<=N; i++){
        sum[i] = sum[i-1];
        if(S[i-1] == 'A' && S[i] == 'C'){
            sum[i]++;
        }
    }

    for(int i=0; i<Q; i++){
        cout<<(sum[right[i]-1]-sum[left[i]-1])<<endl;
    }    

    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   int n,m;
   cin>>n>>m;
   int ar[n]; memset(ar,0,sizeof(ar));
   for(int i=0;i<m;i++)
   {
       int l,r;
       cin>>l>>r;
       l--; ar[l]++;
       if(r<n)ar[r]--;
   }
   int ans=0;
   for(int i=0;i<n;i++)
   {
       if(i)ar[i]+=ar[i-1];
       if(ar[i]==m)ans++;
   }
   cout<<ans;
      return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll X;

template <typename T>
T expt(T a, std::int64_t n){
    T power {1};
    while(n > 0){
        if(n & 1){power *= a;}
        a *= a;
        n >>= 1;
    }
    return power;
}

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

  std::cin >> X;

  for(ll a=-1000;a<=1000;++a){
      for(ll b=-1000;b<=1000;++b){
          if(expt<ll>(a, 5) - expt<ll>(b, 5) == X){
              std::cout << a << " " << b << std::endl;
              return 0;
          }
      }
  }
}


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

int main() {
	int a,b,c;
	vector <int> vec;
	cin >> a >> b >> c;
	vec.push_back(a);
	vec.push_back(b);
	vec.push_back(c);
	sort(vec.begin(),vec.end());
	cout << (vec[2]*10 + vec[1] + vec[0]) << endl;;
	return 0;
}

Measured memory_bytes: 256
//verma_ankit484

#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef AV
	freopen("int.txt", "r", stdin);
	#endif
	string str1, str2;
	cin >> str1 >> str2;
	ll n1, n2;
	n1 = str1.length();
	n2 = str2.length();
	ll arr[n1+1][n2+1];
	for(ll i = 0; i <= n1; i++) {
		for(ll j = 0 ; j <= n2; j++) {
			arr[i][j] = 0;
		}
	}
	str2.insert(str2.begin(), '?');
	str1.insert(str1.begin(), '$');
	for(ll i = 1; i <= n1; i++) {
		for(ll j = 1; j <= n2; j++) {
			if(str1[i] == str2[j]) {
				arr[i][j] = arr[i-1][j-1]+1;
			}
			else {
				arr[i][j] = max(arr[i-1][j], arr[i][j-1]);
			}
		}
	}
	string s;
	ll k1, k2;
	k1 = n1, k2 = n2;
/*	for(ll i = 1; i <= n1; i++) {
		for(ll j = 1; j <= n2; j++) {
			cout << arr[i][j] <<' ';
		}
		cout << endl;
	}*/
	while(1) {
		if(arr[k1][k2] == 0) break;
		if(arr[k1][k2] == arr[k1][k2-1]) {
			k2--;
		}
		else if(arr[k1][k2] == arr[k1-1][k2]) {
			k1--;
		}
		else {
			s.push_back(str1[k1]);
			k1--;
			k2--;
		}
	}
	reverse(s.begin(), s.end());
	cout << s << '\n';
	return 0;
}

Measured memory_bytes: 70656
program prob6
    implicit none
    integer(8) :: n, i, minsum,t,s
    integer(8), allocatable :: a(:), b(:), x(:),y(:)
    read(*,*) n
    
    
    allocate(x(n))
    allocate(y(n))
    read(*,*) x
    
    y=x
   
    call msort(x)
    t=x(n/2)
    s=x((n/2+1))
    do i=1,n
        if (y(i)<=t)then
            write(*,*)s
        else
            write(*,*)t
        end if
    end do
    
    deallocate(y)
    deallocate(x)
    stop
contains
 
 
  !
  ! swap two arguments
  !
subroutine swap(a, b)
    implicit none
    integer(8), intent(inout) :: a, b
 
    integer(8) :: c
 
    c = a
    a = b
    b = c
 
  end subroutine swap
 
  !
  ! merge sort
  !
  recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x
 
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
 
end program prob6

Measured memory_bytes: 8968
#include <iostream>
#include <string>
#include <vector>

using namespace std;


int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    // string s(200000, 'a');
    int count = 0;
    int head_prev, tail_prev;
    for (int i = 1; i <= s.length(); i++) {
        if (i == 1) {
            count++;
            head_prev = 0;
            tail_prev = 1;
        } else {
            string s_prev = s.substr(head_prev, tail_prev - head_prev);
            if (s_prev == s.substr(tail_prev, i - tail_prev)) {
                continue;
            } else {
                count++;
                head_prev = tail_prev;
                tail_prev = i;
            }
        }
        // the rest is added to the final substr.
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1<<27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> void sortTwoVecter(vector<T1> &f, vector<T2> &s, bool isReverse = false){
    vector<pair<T1, T2>> p;
    rep(i, f.size()) p.emplace_back(make_pair(f[i], s[i]));
    if (!isReverse) sort(p.begin(), p.end());
    else sort(p.rbegin(), p.rend());
    rep(i, f.size()) tie(f[i], s[i]) = p[i];
    return;
}

int main(){
    ll N, A, B; cin >> N >> A >> B;
    if (A * B < N || N < A + B - 1){
        pt(-1);
        return 0;
    }
    vector<ll> ans;
    rep(i, B) ans.emplace_back(B - i);
    ll cum = 0;
    // debug(ans);
    rep(i, A - 1){
        ll tm = (N - B) / (A - 1) + (i < (N - B) % (A - 1) ? 1 : 0);
        rep(j, tm) ans.emplace_back((i + 2) * B - j - (B - tm) - cum);
        cum += B - tm;
    }
    debug(ans);
}

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


void solve(long long N, long long A, long long B, long long C, long long D, long long E){
    vector<ll> v = {A, B, C, D, E};
    ll idx = min_element(v.begin(), v.end()) - v.begin();
    ll m = *min_element(v.begin(), v.end());

    cout<<N / m +( N % m == 0 ? 0 : 1)+ 4<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    long long E;
    scanf("%lld",&E);
    solve(N, A, B, C, D, E);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
	int n;
	int x[20];
	int count = 0;
	cin >> n;
	
	for (int i = 0; i < n; i++) cin >> x[i];

	
	for (int i = 0; i < n - 2; i++){
		if (x[i + 1] > x[i] && x[i + 1] < x[i + 2])	count++;
		else if (x[i + 1] < x[i] && x[i + 1] > x[i + 2]) count++;
	}

	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int m, t, p, r;

int main() {
	while (cin >> m >> t >> p >> r, m) {
		int wa[55][11];
		bool ac[55][11];
		vector<pair<int,pair<int,int>>> vp(t);
		for (int i = 0; i < t; i++) {
			vp[i].first = 0;
			vp[i].second.first = 0;
			vp[i].second.second = i+1;
		}
		for (int i = 0; i < 55; i++) {
			for (int j = 0; j < 11; j++) {
				ac[i][j] = 0;
				wa[i][j] = 0;
			}
		}
		for (int i = 0; i < r; i++) {
			int m1, t1, p1, j;
			cin >> m1 >> t1 >> p1 >> j;
			if (j == 0) {
					ac[t1][p1] = 1;
					vp[t1-1].first++;
					vp[t1-1].second.first -= (m1 + 20 * wa[t1][p1]);
			}
			else {
				wa[t1][p1]++;
			}
		}
		sort(vp.rbegin(), vp.rend());
		int preac = -1;
		int pret = inf;
		for (int i = 0; i < t; i++) {
			if (preac != vp[i].first) {
				if (i != 0)cout << ",";
				cout << vp[i].second.second;
				pret = vp[i].second.first;
				preac = vp[i].first;
			}
			else if (pret != vp[i].second.first) {
				if (i != 0)cout << ",";
				cout << vp[i].second.second;
				preac = vp[i].fi;
				pret = vp[i].second.first;
			}else {
					cout << "=" << vp[i].second.second;
				}
			}
		cout << endl;
		}
	return 0;
	}

Measured memory_bytes: 2944
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int arr[10];
    int i,j;
    for(i=0;i<10;i++)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+10);
    for(i=9;i>=7;i--)
    {

        printf("%d\n",arr[i]);
    }

    return 0;
}

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

#define ld long double
#define ll long long
#define ull unsigned long long

#define f first
#define s second

#define endl '\n'
#define pii pair <ll, ll>

#define ios ios_base::sync_with_stdio(0), cin.tie()
#define pb push_back
#define mp make_pair

#define pi 3.14159265358979323846264
#define y1 abacaba

using namespace std;

const int MXN = 3e5 + 30;
const int MAXN = 1e3 + 2;
const ll INF = 1e9 + 7;
const ll BINF = 1e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-15;   
const ll dx[] = {0, 0, 1, -1};      
const ll dy[] = {1, -1, 0, 0};
           
int n;
int k;

int res[MXN];

int main(){
    //freopen("input.txt", "r", stdin); 
    cin >> k >> n;
    if(k % 2 == 0){
        cout << k / 2 << ' ';
        for(int i = 2; i <= n; i++){
            cout << k << ' ';
        }
    } else{
        for(int i = 1; i <= n; i++){
            res[i] = ((k + 1) / 2);
        }
        int sz = n;
        for(int i = 1; i <= n / 2; i++){
            if(res[sz] == 1) sz --;
            else{
                res[sz] --;
                for(int i = sz + 1; i <= n; i++) res[i] = k;
                sz = n;
            }
        } 
        for(int i = 1; i <= sz; i++) cout << res[i] << ' ';
    }
    return 0;
}

Measured memory_bytes: 3456
#include <cstdio>
#include <iostream>

#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>

using namespace std;

#define MAX_N 100000
int a[MAX_N];
int b[MAX_N];

typedef pair<int, int> P;

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int H, W, N;
  cin >> H;
  cin >> W;
  cin >> N;
  
  if (N != 0) {
    for (int i = 0; i < N; i++) {
      cin >> a[i] >> b[i];
    }
  }

  map<P, int> mp;

  for (int i = 0; i < N; i++) {
    int x = a[i];
    int y = b[i];

    for (int j = 0; j <= 2; j++) {
      for (int k = 0; k <= 2; k++) {

	if ( x - j >= 1 && y - k >= 1) {
	  P p = P(x - j, y - k);
	  if ( mp.find(p) != mp.end() ) mp[p]++;
	  else mp[p] = 1;
	}
	
      }
    }
  }
  
  long long hist[10] = {0};  
  long long n_total = (long long) (H-2) * (W-2);
  
  auto itr = mp.begin();
  while (itr != mp.end()) {
    if (itr->first.first <= H-2 && itr->first.second <= W-2) {
      hist[itr->second]++;
      n_total--;
    }
    itr++;
  }

  hist[0] = n_total;
  
  for (int i = 0; i < 10; i++) {
    cout << hist[i] << endl;
  }
  
}


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

ll solve() {
    string S;
    cin >> S;
    int n = S.size();
    int bs = 0;
    map<int,int> mn;
    mn[0] = 0;
    int f;
    for ( int i = 0; i < n; i++ ) {
        int b = 1 << (S[i]-'a');
        bs ^= b;
        f = 1e6;
        for ( int j = -1; j < 26; j++ ) {
            int bb = j < 0 ? 0 : (1 << j);
            if ( mn.count(bs ^ bb) > 0 ) {
                f = min(f, mn[bs^bb] + 1);
            }
        }
        if ( mn.count(bs) > 0 ) {
            mn[bs] = min(mn[bs], f);
        } else {
            mn[bs] = f;
        }
    }
    ll ans = f;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9860
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string S;
  cin >> S;
  bool ans = S[2] == S[3] && S[4] == S[5];
  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++ i)
#define per(i,a,b) for(int i = (a); i >= (b); -- i)
#define pb push_back
#define VI vector<int>
#define VVI vector<VI>
#define Pii pair<int,int>
#define Pll pair<ll,ll>
#define Pli pair<ll,int>
#define fi first
#define se second
#define Ppi pair<Pii,int>
#define VII vector<Pii>

using namespace std;

typedef long long ll;
typedef int (*funI_I) (int);
typedef int (*funI_II) (int, int);

constexpr int N = 4000100;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n, flag = 0;
    cin >> n;
    VI A(n+1, 0);
    rep(i, 1, n) {
        cin >> A[i];
        if(A[i] % 2 == 0) {
            if(A[i] % 3 == 0 || A[i] % 5 == 0) {}
            else flag = 1;
        }
    }
    if(flag) cout << "DENIED\n";
    else cout << "APPROVED\n";

}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#include <sstream>
#include <iterator>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

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

    int four = 0, zero = 0;

    for (int i = 0; i < n; i++)
    {
        int k;
        scanf("%d", &k);

        if (k % 4 == 0)
            four++;

        if (k % 2 != 0)
            zero++;
    }

    if (four >= zero || (four + zero == n && zero - four == 1))
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>

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

int main()
{
	int n, m, q;
	cin>>n>>m>>q;
	P p[200000];
	for(int i=0; i<m; i++){
		int l, r;
		cin>>l>>r;
		p[i]=P(r, l);
	}
	sort(p, p+m);
	int d=500;
	vector<int> vl[401];
	for(int i=0; i<m; i++){
		vl[i/d].push_back(p[i].second);
	}
	for(int i=0; i<=(m-1)/d; i++){
		sort(vl[i].begin(), vl[i].end());
	}
	for(int k=0; k<q; k++){
		int x, y;
		cin>>x>>y;
		int i0=upper_bound(p, p+m, P(y, n+1))-p;
		if(i0==0){
			cout<<0<<endl;
			continue;
		}
		int ans=0;
		for(int i=0; i<(i0-1)/d; i++){
			ans+=(vl[i].end()-lower_bound(vl[i].begin(), vl[i].end(), x));
		}
		for(int i=(i0-1)/d*d; i<i0; i++){
			if(p[i].second>=x) ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3328
n,*a=`dd`.split.map &:to_i;p (1..2*n).bsearch(&->x{b=a.map{|e|e<x};n.times{|i|[-1,1].map{|f|z=n-~i*f-1;return b[z]if b[z]==b[z-f]}};b[0]})-1

Measured memory_bytes: 41940
code = r"""
# distutils: language=c++
# cython: wraparound=False
from libcpp.set cimport set
from libcpp.vector cimport vector
from libc.stdio cimport getchar, printf
from cython.operator cimport dereference as deref
from cython.operator cimport preincrement as preinc, predecrement as predec
from cython.operator cimport postincrement as postinc, postdecrement as postdec
cdef int cin() nogil:
    cdef int b, c = 0
    while 1:
        b = getchar() - 48
        if b < 0: break
        c = c * 10 + b
    return c
cdef int n = cin(), i
cdef long c
cdef vector[long] a = vector[long](n)
for i in range(n): a[cin() - 1] = i
cdef set[long] s = set[long]([-1, n])
cdef set[long].iterator it
for i in range(n):
    it = s.lower_bound(a[i])
    c += (deref(postdec(it)) - a[i]) * (a[i] - deref(it)) * (i + 1)
    s.insert(a[i])
printf('%ld\n', c)
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 22320
N = int(input())
B = list(map(int, input().split()))

A = [B[0]]

for i in range(N-2):
    if B[i] < B[i+1]:
        A.append(B[i])
    else:
        A.append(B[i+1])

A.append(B[N-2])

print(sum(A))


Measured memory_bytes: 3060
a = input()
b = input()
c = len(a)-len(b)
if c==0:
    for i in range(len(a)):
        print(a[i], end ="")
        print(b[i], end ="")
else:
    for i in range(len(a)-1):
        print(a[i], end ="")
        print(b[i], end ="")
    print(a[i+1], end="")

Measured memory_bytes: 3064
N, K = list(map(int,input().split()))

A = [0]+ list(map(int,input().split()))

n = 1
visited = [1]
visitedbit = [0] * (N+1) 
visitedbit[1] = 1
k = 0
flag = True
while True:
    
    k += 1
    #A[n]はテレポート先
    if k == K:
        print(A[n])
        flag = False
        break
    if visitedbit[A[n]]  == 0:
        visited.append(A[n])
        visitedbit[A[n]] = 1
        n = A[n]
    else:
        hazime = visited.index(A[n])
        break

if flag == True:
    # print(visited)
    loop = visited[hazime:]
    # print(loop)
    # print(hazime)
    print(loop[ (K-hazime)%(len(loop)) ])

Measured memory_bytes: 32356
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define ll long long
#define me(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e5+5;
int a[maxn];

int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
        scanf("%d", &a[i]);
    sort(a, a+n);
    int cnt=1, cnt_num = a[0], del_cnt=0;
    for(int i=1; i<n; i++)
    {
        if(a[i] == cnt_num)
            cnt ++;
        else
        {
            if(cnt < cnt_num)
                del_cnt += cnt;
            else
                del_cnt += cnt - cnt_num;
            cnt = 1;
            cnt_num = a[i];
        }
    }
    if(cnt < cnt_num)
        del_cnt += cnt;
    else
        del_cnt += cnt - cnt_num;
    cout<<del_cnt<<endl;
    return 0;
}

/**
1 2 2 4 4
**/


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.IOException;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) throws IOException {
         
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] s = new int[n];
        for(int i = 0; i < n; ++i) s[i] = sc.nextInt();
        
        int q = sc.nextInt();
        int[] t = new int[q];
        for(int i = 0; i < q; ++i) t[i] = sc.nextInt();

        System.out.println(Arrays.stream(t).filter(p -> Arrays.binarySearch(s, p) >= 0).count());
    }
}


Measured memory_bytes: 70716
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<map>

using namespace std;
const int INF = 1<<30;
typedef long long int ll;

int main(){
	string s;cin>>s;
	int n=(int)s.size();
	bool ans=false;
	for(int i=0;i+n-8<=n-1;i++){
		string a=s.substr(0, i), b=s.substr(i+n-7, n-(i+n-8));
		if(a+b=="keyence"){ans=true;break;}
	}
	cout << (ans?"YES":"NO") << endl;
}

Measured memory_bytes: 256