akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vi p(n);
  rep(i,n){
    cin >> p[i];
  }
  vi q = p;
  sort(rng(q));
  int cnt = 0;
  rep(i,n){
    cnt+=(p[i]!=q[i]);
  }
  cout<<(cnt<=2?"YES":"NO")<<endl;
  return 0;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = new string[3];
            string str = Console.ReadLine();
            arr = str.Split(' ');
            int cnt = 0;
            int a = int.Parse(arr[0]);
            int b = int.Parse(arr[1]);
            int c = int.Parse(arr[2]);

            for (int i = a; i <= b; i++)
            {
                if(c%i == 0)
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);

        }   // end main
    }   // end class




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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll h, n; cin >> h >> n;
    ll a[n], b[n]; for (ll i=0; i<n; i++) cin >> a[i] >> b[i];

    vector<ll> dp(100100, 10000001000);
    dp[0] = 0;

    for (ll i=1; i<=h; i++)
    {
        for (ll j=0; j<n; j++)
        {
            dp[i] = min(dp[i], dp[max(i-a[j], (ll)0)] + b[j]);
        }
    }

    cout << dp[h] << "\n";

    return 0;
}

Measured memory_bytes: 1024
<?php
$nl=(int)trim(fgets(STDIN));
$prtw=explode(' ',trim(fgets(STDIN)));
$intw=explode(' ',trim(fgets(STDIN)));
 
$pstw=array($nl);
for($i=0;$i<$nl;$i++){$pstw[$i]=0;}
 
function to_pstw($pri,$ini,$psi,$nl){
    global $prtw,$intw,$pstw;
 
    $a=$prtw[$pri];
    $pstw[$psi+$nl-1]=$a;
 
    if($nl<=1){return;}
 
    $i=0;
    while($intw[$ini+$i]!=$a){++$i;}
 
    if($i>0){to_pstw($pri+1,$ini,$psi,$i);}
    if($nl-$i-1>0){to_pstw($pri+$i+1,$ini+$i+1,$psi+$i,$nl-$i-1);}
}
 
to_pstw(0,0,0,$nl);
printf($pstw[0]);
for($i=1;$i<$nl;$i++){printf(" %d",$pstw[$i]);}
?>

Measured memory_bytes: 15632
#include<iostream>
#include<string>
using namespace std;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
char dc[]={'R','D','L','U'};
bool t[7][7][4];
string str;
int flg=0;
void init();
void getnum(int,int,int);
bool ck(int y,int x,int d){
	if(t[y][x][d]==1)return true;
	int ny=y+dy[d];
	int nx=x+dx[d];
	if(t[ny][nx][(d+2)%4]==1)return true;
	return false; 
}
void rec(int y,int x,int d);
int main(){
	init();
	//cout<<"test"<<endl;
	for(int i=1;i<=4;i++){
		for(int j=1;j<=4;j++){
			//cin>>t[i][j][0];
			getnum(i,j,0);
		}
		for(int j=1;j<=5;j++){
			//cin>>t[i][j][1];
			getnum(i,j,1);
		}
	}
	for(int i=1;i<=4;i++)getnum(5,i,0);//cin>>t[5][i][0];
	//cout<<"inputend"<<endl;
	rec(1,1,0);
	return 0;
}
void init(){
	for(int i=0;i<7;i++)
		for(int j=0;j<7;j++)
			for(int k=0;k<4;k++)
				t[i][j][k]=0;
	string s;
	str="";
	for(int i=0;i<9;i++){
		cin>>s;
		str+=s;	
	}
}
void rec(int y,int x,int d){
	//cout<<y << " " <<x<<" "<<d<<endl;
	flg++;
	if(y==1&&x==1&&flg>1){
		cout<<endl;
		return;
	}
	
	int d1=(d+1)%4;
	int d2=(d+2)%4;
	int d3=(d+3)%4;
	if(ck(y,x,d3)){
		cout<<dc[d3];
		rec(y+dy[d3],x+dx[d3],d3);
	}else if(ck(y,x,d)){
		cout<<dc[d];
		rec(y+dy[d],x+dx[d],d);
	}else if(ck(y,x,d1)){
		cout<<dc[d1];
		rec(y+dy[d1],x+dx[d1],d1);
	}else{
		cout<<dc[d2];
		rec(y+dy[d2],x+dx[d2],d2);
	}
}
void getnum(int a,int b,int c){
	if(str[0]=='0')t[a][b][c]=0;
	else t[a][b][c]=1;
	if(str.size()>=2)str=str.substr(1);
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
template<class T> inline void dmin(T& x,T y){ y<x?x=y:0; }
template<class T> inline void dmax(T& x,T y){ y>x?x=y:0; }
template<class T> inline void dmin(T& x,vector<T> y){ 
	for(auto t:y) t<x?x=t:0;
}
template<class T> inline void dmax(T& x,vector<T> y){
	for(auto t:y) t>x?x=t:0;
}
struct K{ int w,v; };
inline K merge(K x,K y){ return (K){x.w+y.w,x.v+y.v}; }
bool cmp(K x,K y){ return x.w<y.w||x.w==y.w&&x.v>y.v; }
vector<int> dep;
vector<K> a;
vector<vector<K> > f;
vector<K> add(vector<K> a,K x){
	vector<K> b(a.size()),c(a.size()*2);
	for(int i=0;i<a.size();++i)
		b[i]=merge(a[i],x);
	merge(a.begin(),a.end(),b.begin(),b.end(),c.begin(),cmp);
	vector<K> d;
	for(int i=0;i<c.size();++i){
		if(c[i].w>(int)1e5) break;
		if(d.empty()||d.back().v<c[i].v) 
			d.push_back(c[i]);
	}
	return d;
}
int main(){
	int n; scanf("%d",&n); 
	dep.resize(n+1);
	a.resize(n+1);
	f.resize(n+1);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&a[i].v,&a[i].w);
	dep[1]=1;
	for(int i=2;i<=n;++i)
		dep[i]=dep[i>>1]+1;
	int t=dep[n]/2;
	f[0]=vector<K>({(K){0,0}});
	for(int i=1;i<=n;++i)
		if(dep[i]<=t){
			if(dep[i>>1]<1){
				f[i]=add(f[0],a[i]);
			}else{
				f[i]=add(f[i>>1],a[i]);
			}
		}
	for(int i=1;i<=n;++i)
		if(dep[i]>t){
			if(dep[i>>1]<=t){
				f[i]=add(f[0],a[i]);
			}else{
				f[i]=add(f[i>>1],a[i]);
			}
		}
	int q; scanf("%d",&q);
	while(q--){
		int x,l; scanf("%d%d",&x,&l);
		if(dep[x]<=t){
			int ans=0;
			for(int i=0;i<f[x].size();++i)
				if(f[x][i].w<=l)
					ans=max(ans,f[x][i].v);
			printf("%d\n",ans);
		}else{
			int y=x; while(dep[y]>t) y>>=1;
			int poi=(int)f[y].size()-1,ans=0;
			for(int i=0;i<f[x].size();++i){
				while(poi>=0&&f[y][poi].w+f[x][i].w>l)
					--poi;
				if(poi<0) break;
				ans=max(ans,f[y][poi].v+f[x][i].v);
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}
		


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

int main(){
  int D,N;
  cin>>D>>N;
  if(D==0){
    if(N<100){
      cout<<N<<endl;
      return 0;
    }
    cout<<101<<endl;
    return 0;
  }
  if(D==1){
    if(N<100){   
    cout<<100*N<<endl;
    return 0;
    }
    cout<<10100<<endl;
    return 0;   
  }
  if(N<100){
  cout<<10000*N<<endl;
    return 0;
  }
  cout<<1010000<<endl;
  return 0;
}

    
    

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

using namespace std;

const int N = 500000;
const int B = 700;

struct query {
  int l, r, i;
  bool operator<(const query &other) const {
    return make_pair(l / B, r) < make_pair(other.l / B, other.r);
  }
};

int c[N];
query qs[N];
int ans[N];
int f[N], cnt = 0;

void add(int value) {
  if(++f[value] == 1)
    cnt++;
}

void remove(int value) {
  if(--f[value] == 0)
    cnt--;
}

int main() {
  int n, q; scanf("%d %d", &n, &q);
  for(int i = 0; i < n; ++i) {
    scanf("%d", c + i);
  }
  for(int i = 0; i < q; ++i) {
    int l, r; scanf("%d %d", &l, &r);
    qs[i] = {l - 1, r - 1, i};
  }
  sort(qs, qs + q);
  int cur_l = 0, cur_r = -1;
  for(int i = 0; i < q; ++i) {
    while(cur_l > qs[i].l) {
      add(c[--cur_l]);
    }
    while(cur_r < qs[i].r) {
      add(c[++cur_r]);
    }
    while(cur_l < qs[i].l) {
      remove(c[cur_l++]);
    }
    while(cur_r > qs[i].r) {
      remove(c[cur_r--]);
    }
    ans[qs[i].i] = cnt;
  }
  for(int i = 0; i < q; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 15424
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int mt[10];
	for(int i=0;i<10;i++){
		cin >> mt[i];
	}
	for(int i=0;i<3;i++){
		int *maxmt = &mt[0];//mtと同じ。ポインタにすることでアドレスと値を同時に見れる
		for(int j=0;j<10;j++){
			if(*maxmt < mt[j]){
				maxmt = &mt[j];
			}
		}
		cout << *maxmt << endl;
		*maxmt = 0;
	}
	return 0;
}

Measured memory_bytes: 1160
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::{fastout, input};
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;

#[fastout]
fn main() {
    input! {
        N:usize
    }
    let mut f = vec![0usize; N + 1];
    let mut ans = 0;
    for i in 1..N + 1 {
        let mut j = i;
        while j <= N {
            f[j] += j;
            j += i;
        }
        ans += f[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 80156
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
const int INF=0x3f3f3f3f;
int d[8][2]={{-1,0},{0,-1},{0,1},{1,0},{1,1},{-1,-1},{-1,1},{1,-1}};
int main()
{
    int n,z,w,a[2005];
    scanf("%d%d%d",&n,&z,&w);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    if(n>1) cout<<max(abs(a[n-1]-a[n-2]),abs(a[n-1]-w))<<endl;
    else cout<<abs(a[n-1]-w)<<endl;
    return 0;
}


Measured memory_bytes: 256
e1,e2,e3,e4=map(int,input().split())
if e1==e2==e3==e4:
    print("yes")
elif e1==e2 and e3==e4:
    print("yes")
elif e1==e3 and e2==e4:
    print("yes")
elif e1==e4 and e2==e3:
    print("yes")
else:
    print("no")



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
           if(s=="SUN")
        cout<<"7"<<endl;
            if(s=="MON")
        cout<<"6"<<endl;
            if(s=="TUE")
        cout<<"5"<<endl;
            if(s=="WED")
        cout<<"4"<<endl;
            if(s=="THU")
        cout<<"3"<<endl;
            if(s=="FRI")
        cout<<"2"<<endl;
            if(s=="SAT")
        cout<<"1"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,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; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll h,w,n;
    cin>>w>>h>>n;
    ll x0=0,x1=w,y0=0,y1=h;
    rep(i,n){
        ll x,y,a;
        cin>>x>>y>>a;
        if(a==1) chmax(x0,x);
        else if(a==2) chmin(x1,x);
        else if(a==3) chmax(y0,y);
        else chmin(y1,y);
    }
    // cout<<x0<<x1<<y0<<y1<<endl;
    cout<<max(0ll,(x1-x0))*max(0ll,(y1-y0))<<endl;

}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    solve();


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)

const int mod = 1000000007;

int main(){
    ll x;
    cin >> x;
    ll a = x / 11;
    ll b = x % 11;
    if(b==0){b = 0;}else if(b <= 6){b = 1;}else{b = 2;}
    cout << a*2+b;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

int main()
{
	cout <<setprecision(10);
	int h , w;
	cin >> h >> w;
	vector<string> field(h);
	rep(i,h) cin >> field[i];
	
	int jmax = 0;
	rep(i,h){
		rep(j,w){
			if(field[i][j]=='#'){
				if(j < jmax){
					cout << "Impossible"<<endl;
					return 0;
				}
				chmax(jmax,j);
			}
		}
	}
	cout << "Possible" << endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
tizu = [list(input()) for _ in range(H)]

def check(i, j):
    ans = 0
    for k in [-1, 0, 1]:
        for l in [-1, 0, 1]:
            if k == 0 and l == 0:
                continue
            elif 0 <= i+k < H and 0 <= j+l < W:
                if tizu[i+k][j+l] == "#":
                    ans += 1
    return ans

for a in range(H):
    for b in range(W):
        if tizu[a][b] == "#":
            continue
        else:
            tizu[a][b] = check(a, b)

for i in range(H):
    for j in range(W):
        print(tizu[i][j], end="")
    print()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int ctoi(const char);
int main(){
    string a, b, c, ans = "YES";
    cin >> a >> b >> c;
    if(a.at(a.size() - 1) != b.at(0) || b.at(b.size() - 1) != c.at(0))
        ans = "NO";
    cout << ans;
}

Measured memory_bytes: 256
import sys
def chk(v):
  for i in range(1,len(v)):
    if v[i-1]>v[i]:
      return False
  return True
n=int(input())
p=list(map(int,input().split()))
if chk(p):
  print("YES")
  sys.exit()
for i in range(n):
  for j in range(i+1,n):
    #swap i,j
    v=[]
    for k in p:
      v.append(k)
    v[i],v[j]=v[j],v[i]
    if chk(v):
      print("YES")
      sys.exit()
print("NO")


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

int main() {
  int N;
  cin >> N;
  N %= 10;
  if (N==3) cout << "bon" << endl;
  else if (N==0 || N==1 || N==6 || N==8) cout << "pon" << endl;
  else cout << "hon" << endl;
}


Measured memory_bytes: 3624
N = input()
if N[-1] in ['3'] :
    yomi = 'bon'
elif N[-1] in ['0', '1', '6', '8'] :
    yomi = 'pon'
elif N[-1] in ['2', '4', '5', '7', '9'] :
    yomi = 'hon'
print(yomi)

Measured memory_bytes: 9016
fun main(array: Array<String>) {
    val s = readLine()!!
    val arr = s.map { it == 'W' }.toBooleanArray()
    val list = mutableListOf<Long>()

    for(i in arr.indices) {
        if(arr[i]) {
            list.add(i.toLong())
        }
    }
    if(list.size == 0 || list.size == s.length) {
        return print(0)
    }
    print(list.sum().toLong() - (list.size.toLong() - 1) * list.size.toLong() / 2)
}


Measured memory_bytes: 49128
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll w, a, b;
    cin >> w >> a >> b;
    if (a + w < b) {
        cout << b - (a + w) << endl;
    } else if (b + w < a) {
        cout << a - (b + w) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

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

int main(void){
  int n; cin >> n;
  int a[n];
  rep(i,n) cin >> a[i];
  rep(i,n){
    if(a[i] %2 == 0 && a[i] % 3 != 0 && a[i] %5 != 0){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if (A==B){
        printf("%d",C);
        }
    if (A==C){
        printf("%d",B);
        }
    if (C==B){
        printf("%d",A);
        }

    return 0;
}


Measured memory_bytes: 128
#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 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;


int main(){
   int n; cin>>n;
   //１番多い数字を見つけるそれが見つかればあとはかんたん
   //奇数と偶数で場合わけ
   int v[n];
   REP(i,n)cin>>v[i];
   int ans0;
   int ans1;

  //どの数字が何個あるかの記録用配列をつくる*2個
  //これはmapでやるとkeyがつかえていい

   map<int,int> mp0;
   map<int,int> mp1;

   int max01=0; //0基準列で一番多い数字
   int max02=0; 
   int max11=0; //1基準列で一番多い数字
   int max12=0;

   for(int i=0;i<n-1;i+=2){//0基準の奇数と１基準の偶数ループ
      if(mp0[v[i]]==0)mp0[v[i]]=1;
      else mp0[v[i]]++;

      if(max01<mp0[v[i]]){
         max01=mp0[v[i]]; ans0=v[i];
      }else if(max02<mp0[v[i]])max02=mp0[v[i]];

       if(mp1[v[i+1]]==0)mp1[v[i+1]]=1;
      else mp1[v[i+1]]++;

        if(max11<mp1[v[i+1]]){
           max11=mp1[v[i+1]];
           ans1=v[i+1];
        }else if(max12<mp1[v[i+1]])max12=mp1[v[i+1]];
      
   }

  int res=0;
   if(ans0==ans1){
      res=n-max(max01+max12,max02+max11);
   }else res=n-(max01+max11);
  /*  cout<<ans0<<":"<<ans1<<endl;
  cout<<"０基準"<<max01<<":"<<max02<<" 1基準"<<":"<<max11<<":"<<max12<<endl;
  */

  cout<<res<<endl;

}

Measured memory_bytes: 5376
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	int N, M;
	cin >> N >> M;

	vector<string> A(N), B(M);
	for(int i=0; i<N; i++)
		cin >> A[i];
	for(int i=0; i<M; i++)
		cin >> B[i];

	string ret = "No";
	for(int i=0; i<N-M+1; i++)
	{
		auto pos = A[i].find(B[0], 0);
		while(pos != string::npos)
		{
			bool ok = true;
			for(int j=1; j<M; j++)
			{
				if(A[i+j].substr(pos, M) != B[j])
				{
					ok = false;
					break;
				}
			}

			if(ok == true)
			{
				ret = "Yes";
				i = N;
				pos = string::npos;
				break;
			}

			pos = A[i].find(B[0], pos+1);
		}

	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
A=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
B=[int(input()) for _ in range(n)] 
for i in range(3):
    for j in range(3):
        for k in range(n):
            if A[i][j]==B[k]:
                A[i][j]=0
                
ans="No"
for i in range(3):
    if A[i][0]+A[i][1]+A[i][2]==0:
        ans="Yes"
    if A[0][i]+A[1][i]+A[2][i]==0:
        ans="Yes"
if A[0][0]+A[1][1]+A[2][2]==0:
    ans="Yes"
if A[0][2]+A[1][1]+A[2][0]==0:
    ans="Yes"
print(ans)

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

int main() {
    static const double pi = 3.141592653589793;
    double a, b, c;
    cin >> a >> b >> c;
    
    double s, l, h;
    
    s = a * b * sin(c * pi / 180.0) / 2.0;
    cout << fixed << setprecision(cout.precision()) << s << endl;
    
    l = a + b + sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(c * pi / 180.0));
    cout << fixed << setprecision(cout.precision()) << l << endl;
    
    h = b * sin(c * pi / 180.0);
    cout << fixed << setprecision(cout.precision()) << h << endl;
    
    return 0;
}


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

using namespace std;

int main(){
    string S;
    cin >> S;
    for (auto &s: S){
        if (s == '?')
            s = 'D';
    }

    cout << S << endl;

    // int ans = 0;
    // for (int i = 0; i < S.size(); i++){
    //     if (S.substr(i, 2) == "PD")
    //         ans++;
    //     if (S[i] == 'D')
    //         ans++;
    // }

    // cout << ans << endl;
}

Measured memory_bytes: 3752
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int P = scan.nextInt();
        String S = scan.next();
        char[] d = S.toCharArray();
        if (10 % P == 0) {
            long ans = 0;
            for (int i = N - 1; 0 <= i; i--) {
                if ((d[i]-'0') % P != 0) {
                    continue;
                }
                ans += (i+1);
            }
            System.out.println(ans);
            return;
        }
        long base = 1;
        int ten_mod = 10 % P;
        long[] data = new long[N];
        for (int i = N-1; 0 <= i; i--) {
            int x = (d[i] - '0') % P;
            long y = (x * base) % P;
            data[i] = y;
            base *= ten_mod;
            base %= P;
        }
        long[] dp = new long[N + 1];
        dp[N] = 0;
        for (int i = N-1; 0 <= i; i--) {
            dp[i] = dp[i+1] + data[i];
            dp[i] %= P;
        }
        HashMap<Long, Long> summary = new HashMap<>();
        for (int i = 0; i <= N; i++) {
            long count = summary.getOrDefault(dp[i], 0L);
            summary.put(dp[i], count+1);
        }
        long ans = 0;
        for (long key : summary.keySet()) {
            long count = summary.get(key);
            ans += count * (count - 1)/2;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 44408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0) : x((x%mod+mod)%mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<int> cnt(n, 0);
  rep(i,n) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  bool ok = true;
  for (int i = 1; i < n; ++i) {
    if (i % 2 != n % 2) { //nが偶数->iは奇数
      debug(i);
      if (cnt[i] != 2) { //全てペアならOK
        ok = false;
        break;
      }
    }
  }
  if (!ok) {
    cout << 0 << endl;
    return 0;
  }
  // 2^{n/2(ペア数)}
  mint ans(2);
  ans = ans.pow(n/2);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 640
n = gets.to_i
num = gets.strip.split.map(&:to_i)
ary = Array.new(n,0)
if n==1
  puts "0"
else
  i = 0
  k = 0
  while i < n-1 do
    if num[i] >= num[i+1]
      ary[k] += 1
    else
      k += 1
    end
    i += 1
  end
  puts ary.max
end

Measured memory_bytes: 22692
def allocation():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))

    # 最大積載量pを算出
    min = 0
    max = 100000000000
    while min + 1 != max:
        mid =(min + max) // 2
        if check(n, k, w, mid):
            max = mid
        else:
            min = mid
    print(max)

def check(n, k, w, p):
    t = 0
    now = 0
    for i in range(n):
        if (w[i] > p):
            return False
        if (now + w[i] > p):
            t += 1
            now = w[i]
        else:
            now += w[i]
    if now > 0:
        t += 1
    if t > k:
        return False
    else:
        return True

if __name__ == '__main__':
    allocation()


Measured memory_bytes: 9556
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

L=list(map(int,input())); n=len(L)
L.reverse();L.append(0)
for i in range(n):

  if L[i] >= 6:
    count += 10-L[i]
    L[i] = 0; L[i+1] += 1

  elif L[i] == 5 and L[i+1] >= 5:
    count += 10-L[i]
    L[i] = 0; L[i+1] += 1

print(count + sum(L))
# print(L)
    



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

using namespace std;

int main()
{
	int n,l=0,c=0;
  	cin >> n;
  	int a[81];
    for (int i=0;i<9;i++)
    {
    	for (int j=0;j<9;j++)
        {
        	a[l]=(i+1)*(j+1);
          	l++;
        }
    }
  	for (int k=0;k<81;k++)
    {
    	if (a[k] == n)
        {
          	c++;
        }
    }
  	if (c!=0)
    {
    	cout << "Yes";
    }
  	else
    {
     	cout << "No";
    }
  
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string x;
	cin >> x;
	stack<char> sc;
	int ans = x.size();
	rep(i, x.size()){
		if(x[i] == 'S') sc.push('S');
		if(x[i] == 'T' && !sc.empty()){
			sc.pop();
			ans -= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long UL; // ULLONG_MAX, %llu
typedef unsigned int UI; //UINT_MAX %u
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

const int N = 305;
LL num[N];
void print(LL x){
    printf("%lld = ",x);
    for(LL i = 1; i <= x; i<<=1){
        if(i&x) printf("1");
        else printf("0");
    }
    printf("\n");
}
int count(LL x){
    int cnt = 0;
    for(LL i = 1; i <= x; i<<=1){
        if(i&x) ++cnt;
    }
    return cnt;
}
int main(){
    int n;
    scanf("%d",&n);
    LL x = 0;
    FOR(i, 1, n) scanf("%lld",&num[i]), x ^= num[i];
    if(x == 0){
        printf("0"); return 0;
    }
    LL A = num[1], B = num[2], P = A+B;
    x ^= (A^B);
    if((P-x)%2){
        printf("-1"); return 0;
    }
    LL _ = (P-x)/2;
    if(_&x){
        printf("-1"); return 0;
    }
    LL Ap = _, Bp = _;
    int ch = 0;
    iFOR(i, 39, 0){
        LL bit = (x&(1ll<<i));
        if((Ap^bit) > A) Bp ^= bit;
        else Ap ^= bit;
    }
    if(Ap == 0 || Ap+Bp != P || Ap > A) printf("-1");
    else printf("%lld",A-Ap);
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 3832
#include"bits/stdc++.h"
#include<iostream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i, c) for(int i = 0; i < (int)c; i++)
const ll inf = 1000000007;

int main() {
	int a, b,c;
	cin >> a >> b >> c;
	if (a != b) {
		if (a==c || b==c) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	else {
		if (a != c) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int N,A,B;
char ch[100005];
int sum,num=0,numB=1;
int main(){
	cin>>N>>A>>B;
	for(int ii=0;ii<N;++ii){
		cin>>ch[ii];
	}
	sum = A+B;
	for(int i=0;i<N;++i){
		if(ch[i]=='c'){
			cout<<"No"<<endl;
		}else{
			if(ch[i]=='a'){
				if(num<sum){
					cout<<"Yes"<<endl;
					num+=1;
				}else{
					cout<<"No"<<endl;
				}
			}else{
				if(num<sum&&numB<=B){
					cout<<"Yes"<<endl;
					numB++;
					num++;
				}else{
					cout<<"No"<<endl;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	string s;
	cin >> s;
	if (s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" || s == "cba") {
		cout << "Yes" << endl;
	}
	else {
	cout << "No" << endl;
}
}

Measured memory_bytes: 256
r,c = map(int, input().split())
t = [0 for _ in range(r)]
for i in range(r):
    t[i] = list(map(int, input().split()))
    
for i in range(r):
    t[i].append(sum(t[i]))

s = [0] * (c+1)
for j in range(c+1):
    for i in range(r):
        s[j] += t[i][j]

t.append(s)

for i in range(r+1):
    print(" ".join(map(str, t[i])))


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

int main(){
    ll n;
    cin>>n;
    string ans="";
    while(1){
        if(n==0)break;
        n--;
        ans+=char('a'+n%26);
        n/=26;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

Measured memory_bytes: 3564
#include <stdio.h>

int main(){
   int N[5],flag=0;
   for(int i=0;i<4;i++){
      scanf("%d",&N[i]);
      if((N[i]!=1)&&(N[i]!=9)&&(N[i]!=7)&&(N[i]!=4)) flag++;
   }
   for(int i=0;i<3;i++){
      for(int j=i+1;j<4;j++){
         if(N[i]==N[j]) flag++;
      }
   }
   if(flag!=0){
      printf("NO\n");
   }else{
      printf("YES\n");
   }
   return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rt return
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
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;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    int n;
    cin>>n;
    int a[n+5];
    repd(i,1,n)
    {
    	cin>>a[i];
    }
    sort(a+1,a+1+n);
    int sum=0;
    repd(i,1,n-1)
    {
    	sum+=a[i];
    }
    if(sum>a[n])
    {
    	printf("Yes\n");
    }else
    {
    	printf("No\n");
    }
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define INF 0x3f3f3f3f3f3f3f3f
long long sum[MAXN];
int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%lld", &sum[i]);
        if(i > 0)
            sum[i] += sum[i - 1];
    }
    long long min = INF;
    for(int i = 0; i < n - 1; i++)
    {
        long long cha = abs(sum[n - 1] - 2 * sum[i]);
        if(cha < min)
            min = cha;
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 1792
//                             ¯\_(ツ)_/¯   
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mma,ava,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define ll long long
 
 
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
 
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;
std::vector<int> c(26);
int D;
std::vector<int>last(26);
std::vector<vector<int>>s;
std::vector<int> v;
int go(int indx,int S,int depth){
	if(indx == D || depth == 4)return S;
	
	for(int j=0;j<26;j++){
		S-=c[j]*(indx-last[j]);
	}
	int mx = 0;
	
	int lim = 26/depth;
	for(int i=0;i<lim;i++){
		int j = v[i];
		int takeback = s[indx][j] + c[j]*(indx-last[j]);
		int l = last[j];
		last[j] = indx;
		mx = max(mx,go(indx+1,S+takeback,depth+1));
		last[j] = l;
	}
	return mx;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();
	srand(time(NULL));
	scanf("%d",&D);
	for(int i=0;i<26;i++)v.pb(i);
	for(int i=0;i<100;i++)random_shuffle(all(v));
	for(int i=0;i<26;i++)scanf("%d",&c[i]);
	s = vector<vector<int>>(D,vector<int>(26));
	for(int i = 0;i<D;i++){
		for(int j=0;j<26;j++){
			scanf("%d",&s[i][j]);
		}
	}
	int S = 0;
	
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			S-=c[j]*(i-last[j]);
		}
		int who = 1;
		int mx = -1e9;
		int take = 0;
		for(int j=0;j<26;j++){
			int takeback = s[i][j] + c[j]*(i-last[j]);
			int l = last[j];
			last[j] = i;
			int wa = go(i+1,S+takeback,1);
			last[j] = l;
			if(mx < wa){
				mx = wa;
				take = takeback;
				who = j+1;
			}
		}
		last[who-1] = i;
		S+= take;
		printf("%d\n",who );
	}
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

string s;
int K, N;

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

ll com(ll n, ll r) {
  if (r < 0 && n > r) return 0;
  if (r == 1) return n;
  else if (r == 2) return n * (n-1) / 2;
  else return n * (n-1) * (n-2) / 6;
}
ll pow(ll n, ll k) {
  ll ret = 1;
  rep(i, k) ret *= n;
  return ret;
}

ll solve(int i, int k, bool smaller) {
  if (k == 0) return 1;
  if (i == N) return 0;
  if (smaller) return com(N-i, k) * pow(9, k);
  else if (s[i] == '0') return solve(i+1, k, false);
  else {
    ll zero, middle, lowwer;
    zero = solve(i+1, k, true);
    middle = solve(i+1, k-1, true) * (s[i] - '1');
    lowwer = solve(i+1, k-1, false);
    return zero + middle + lowwer;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  std::cin >> s >> K;
  N = s.size();
  ll ans = solve(0, K, false);
  std::cout << ans << "\n";
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("A.in","r",stdin);
	freopen("A.out","w",stdout);
#endif
}
int n,c,k;
int a[N];
void input()
{
	n=read<int>(),c=read<int>(),k=read<int>();
	For(i,1,n)a[i]=read<int>();
}
void work()
{
	int ans=0;
	sort(a+1,a+n+1);
	int j,lim,num;
	for(int i=1;i<=n;i=j)
	{
		lim=a[i]+k,num=1;
		ans++;
		//cerr<<lim<<endl;
		for(j=i+1;j<=n;j++)
		{
			if(num==c||a[j]>lim)break;
			num++;
		}
	//	cerr<<j<<endl;
	}
	write(ans,'\n');
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))
maxa = max(a)

d = {}
for ai in a:
  if ai in d:
    d[ai] += 1
  else:
    d[ai] = 1
d = sorted(d.items())
#print(d)

e = [True for _ in range(maxa+1)]
for ai,c in d:
  if c > 1:
    e[ai] = False
  for i in range(2,maxa//ai+1):
    e[ai*i] = False

ans = 0
for ai,_ in d:
  if e[ai]:
    ans += 1
print(ans)

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

int main(){
  int n,tmp;
  int a[10];

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<10;i++)a[i]=0;

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

    for(int i=0;i<10;i++){
      if(!a[i])cout << '-' << endl;
      else{
	for(int j=0;j<a[i];j++)cout << '*';
	cout << endl;
      }
    }
  }
}

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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    cout<<std::fixed<<std::setprecision(10);

    int T,X; cin >> T>>X;
    

    cout << double(T)/X << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = 0, sol = 0;
    for (char c : s)
    {
        if (c == 'S')
            n++;
        else
        {
            if (n)
                n--;
            else
                sol++;
        }
    }
    cout << sol + n;
}


Measured memory_bytes: 720
/*
ID: C4551DY
TASK: dualpal
LANG: C++14
*/
/*  CF_CC
        4U7H0R:_C4551DY */

#include <bits/stdc++.h>
#include <fstream>

using namespace std;

#define IC ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(a,b,c) for(ll a=b;a<c;a++)
#define lb lower_bound
#define ll long long
#define pii pair<int,int>
#define vec vector<ll>
#define fir first
#define sec second
#define pb push_back

const int mxi=1e7+7;
const int mod=1e9+7;

int n,m,ans;


int main(){
	IC
    //ofstream cout ("dualpal.out");
    //ifstream cin ("dualpal.in");
    cin >> n >> m;
    ans+=(n*(n-1))/2;
    ans+=(m*(m-1))/2;
    cout << ans;
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmin(T &a,const T b){if(a>b){a=b; return true;}return false;}
template<typename T> bool chmax(T &a,const T b){if(a<b){a=b; return true;}return false;}

const int MAX_N=1001001;
int par[MAX_N], depth[MAX_N];

void init(int n){
    for(int i=0; i<n; i++){
        par[i]=i;
        depth[i]=0;
    }
}

int find(int x){
    if(par[x] == x) return x;
    return par[x]=find(par[x]);
}

void unite(int x, int y){
    x=find(x), y=find(y);
    if(x == y) return;
    if(depth[x] < depth[y]) par[x]=y;
    else{
        par[y]=x;
        if(depth[x] == depth[y]) depth[x]++;
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

int main(){
    int N, K, L; cin >> N >> K >> L;
    init(2*N);
    vi p(K), q(K);
    for(int i=0; i<K; i++){
        cin >> p[i] >> q[i];
        p[i]--, q[i]--;
        unite(p[i], q[i]);
    }
    vi s(L), t(L);
    for(int i=0; i<L; i++){
        cin >> s[i] >> t[i];
        s[i]--, t[i]--;
        unite(s[i]+N, t[i]+N);
    }

    map<pii, int> mp;
    for(int i=0; i<N; i++){
        mp[{find(i), find(i+N)}]++;
    }
    for(int i=0; i<N; i++){
        cout << mp[{find(i), find(i+N)}] << (i==N-1?"\n":" ");
    }
    return 0;
}

Measured memory_bytes: 19028
n = int(input())
S = [input() for _ in range(n)]
a = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(a)):
    tmp = 50
    for j in range(n):
          tmp = min(tmp,S[j].count(a[i]))
    print(a[i]*tmp,end="")
print("")

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    while(1){
        int n;
        cin>>n;
        if(n==0)break;
        int sum=0,s[n];
        for(int i=0;i<n;i++){
            cin>>s[i];
            sum+=s[i];
        }
        double m,a=0.0;
        m=double(sum)/double(n);
        for(int i=0;i<n;i++)a+=(double(s[i])-m)*(double(s[i])-m);
        cout<<sqrt(a/double(n))<<endl;
    }
    return 0;
}


Measured memory_bytes: 3216
x,n = map(int,input().split())
if n ==0:
    print(x)
    exit()
li = list(map(int,input().split()))
if x not in li:
    print(x)
else:
    flag = True
    tmp = 1
    while flag:
        a = x - tmp
        b = x + tmp
        if a not in li:
            print(a)
            exit()
        if b not in li:
            print(b)
            exit()
        tmp += 1

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;

  if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
/* author   : mpily :-()
title : Competing.cpp
time :Tue Aug 27 13:18:01 2019

*/
#include<bits/stdc++.h>
using namespace std;
bool lt(vector<char>&a, vector<char>&b){
	for(int i = 0; i < a.size(); i++){
		if(a[i] < b[i])return 1;
		else if(a[i] > b[i])return 0;
		else continue;
	}
	return 0;
}
bool isEqual(vector<char>& a,vector<char>& b){
	for(int i = 0; i < a.size(); i++){
		//cout<<a[i]<<":"<<b[i]<<"\n";
		if(a[i] != b[i])return 0;
	}
	return 1;
}
void printArr(vector<char>& as){
	for(auto & a : as)cout<<a;
	cout<<"\n";
}
int main(){
	int n;
	cin>>n;
	vector<vector<char>>arr(n);
	for(int i = 0; i < n; i++ ){
		for(int j = 0; j < 10; j++){
			char temp; cin>>temp;
			arr[i].push_back(temp);
		}
		sort(arr[i].begin(),arr[i].end());
	}
	sort(arr.begin(), arr.end(),lt);
	long long totcount = 0;
	//for(auto & a : arr){ printArr(a);cout<<"\n";}
	for(int i = 0; i < n;){
		long long count = 0;
		vector<char>temp = arr[i];
		//printArr(temp);cout<<i<<"\n";
		while(i < n && isEqual(arr[i],temp)){
			//printArr(arr[i]); cout<<"is equal to ";printArr(temp);
			i++;count++;
		}
		totcount+=(count*count -count)/2;
	}
	cout<<totcount<<"\n";
	return 0;
}


Measured memory_bytes: 5760
import java.io.PrintWriter
import kotlin.math.max
import kotlin.math.min

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (n, m, k) = readLongList()
    val aList = readLongList()
    val bList = readLongList()
    val aSums = aList.fold(mutableListOf(0L)) { acc, value ->
        acc += acc.last() + value
        acc
    }
    val bSums = bList.fold(mutableListOf(0L)) { acc, value ->
        acc += acc.last() + value
        acc
    }

//    累積和で二分探索
//     nlog(n)
    var ans = 0
    for ((i, a) in aSums.withIndex()) {
        var left = -1
        var right = bSums.size
        while (right - left > 1) {
            val mid = (right + left) / 2
            if (a + bSums[mid] > k) right = mid else left = mid
        }

//        if (left in bSums.indices) {
//            println("${aSums} ${i} ${a}")
//            println("${bSums} ${left} ${bSums[left]}")
//            println()
//        }
        ans = if (left in bSums.indices) max(ans, i + left) else ans
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 93628