akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 3000006
using namespace std;

int n, x, y, u[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d",&n);
	if(n == 3){
		printf("2 5 63\n");
		return 0;
	}
	if(n == 4){
		printf("2 5 20 63\n");
		return 0;
	}
	// if(n == 6){
	// 	printf("3 6 9 12 15 21\n");
	// 	return 0;
	// }
	for(int i = 15000; i >= 1; i--){
		if(i < n and i%3 != 1 and (n - i)%2 == 0){
			x = i;
			y = n - i;
			break;
		}
	}
	// cout << x << " " << y << endl;
	int say = 0;
	for(int i = 1; i <= x; i++){
		printf("%d ", i*2);
		say++;
	}
	// cout << "AMKAMksakdkac\n\n\n\n" << say << " " << x << endl;
	int son = 3;
	while(y--){
		if(son > 30000)
			assert(0);
		printf("%d ", son);
		say++;
		son += 6;
	}
	if(say != n)
		cout << "HAY aq" << say << " " << n << endl;
	return 0;
}

Measured memory_bytes: 384
from math import gcd, ceil
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [i // 2 for i in a]
l = 1
for i in a:
    l *= i // gcd(l, i)
for i in a:
    if l // i % 2 == 0:
        print(0)
        exit()
#print(ceil((m // l) / 2))
print((m//l+1)//2)


Measured memory_bytes: 20376
#include<stdio.h>
#define MAX 100000

int partition(int ,int);
int A[MAX];

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

    value=partition(0,n-1);

    for(i=0;i<n;i++)
    {
        if(i>0)printf(" ");
        if(i==value) printf("[%d]",A[i]);
        else printf("%d",A[i]);
    }
    printf("\n");
    return 0;
}

int partition(int p, int r)
{
    int x,i,j,tmp;
    x = A[r];
    i = p-1;
    for(j=p;j<=r-1;j++)
    {
        if(A[j]<=x)
        {
            i=i+1;
            tmp=A[i];
            A[i]=A[j];
            A[j]=tmp;
        }
    }
    tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp; 
    return i+1;
}



Measured memory_bytes: 2104
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        s: String,
    }
    let days = if s == "RRR" {
        3
    } else if s == "SSS" {
        0
    } else if s == "RRS" || s == "SRR" {
        2
    } else {
        1
    };
    println!("{}", days);
}


Measured memory_bytes: 2080
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;

int Sum(const vector<int>& Jwels, size_t a, size_t b, size_t suteru)
{
  int val = 0;
  
  list<int> Hands;
  while(a > 0)
  {
    const int temp = Jwels[a - 1];
    val += temp;
    if(temp < 0)
	    Hands.emplace_back(temp);    
    -- a;
  }
  
  while(b > 0)
  {
    const int temp = Jwels[Jwels.size() - b];
    val += temp;
    if(temp < 0)
	    Hands.emplace_back(temp);    
    -- b;
  }
  
  Hands.sort();
  for(auto Itr = Hands.cbegin(); suteru > 0 && Itr != Hands.cend(); -- suteru, ++ Itr)
  {
    if(*Itr > 0)
      break;
    
    val += -(*Itr);
  }
    
  return val;
}

int main()
{
  size_t n, k;
  cin >> n >> k;
  
  vector<int> Jwels;
  for(size_t i = 0; i < n; ++ i)
  {
    int temp;
    cin >> temp;
    Jwels.emplace_back(temp);
  }
  Jwels.shrink_to_fit();
  
  const int min_pop = min(n, k);
  int max_val = 0;
  for(size_t a = 0; a <= min_pop; ++ a)
  {
    for(size_t b = 0; b <= min_pop - a; ++ b)
    {
      const int val = Sum(Jwels, a, b, k - (a+b));
      if(max_val < val)
        max_val = val;
    }
  }
  cout << max_val << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(int i=s;i<n;i++)
	
bool check1(string s){
	For(i,0,s.size()-1){
		if(s[i]=='#'&&s[i+1]=='#') return false;
	}
	return true;
}

int main(){
	int N,A,B,C,D;
	string S;
	cin >> N >> A >> B >> C >> D >> S;
	//int left,right;
	
	string sa=S.substr(A-1,B-A+1);
	string sb=S.substr(C-1,D-C+1);
	
	if(C<D){
		if(check1(sa)&&check1(sb)) cout << "Yes";
		else cout << "No";
	}
	else{
		if(!check1(sa)) cout << "No";//A-C間がダメ
		else{//A-C間はok
			for(int i=B-2;i<=D-2;i++){
				if(S[i]=='.'&&S[i+1]=='.'&&S[i+2]=='.'){
					cout << "Yes";
					return 0;
				}
			}
			cout << "No";
			return 0;
		}
	}
}

Measured memory_bytes: 644
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=100+10;
struct node
{
	string s;
	int num,dis;
}a[N];
bool cmp(node p,node q)
{
	if(p.s!=q.s)return p.s<q.s;
	return p.dis>q.dis;
}
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].s>>a[i].dis;
		a[i].num=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
		printf("%d\n",a[i].num);
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!long;
    long a = 0;
    long b = 0;
    foreach (i; 0..10^^6) {
        b += 1;
        a += b;
        if (a >= N) {
            b.writeln;
            return;
        }
    }
}


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

using namespace std;

int main (){
	int N , M , C; cin >> N >> M >> C;
	
	vector<int>B(M);
	for (int i = 0;i < M ; i++) {
	cin >> B [i];
	}

  	vector<vector<int>>A(N, vector<int>(M));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> A [i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int sum = 0;
		for ( int j = 0; j < M; j++) {
			sum += A[i][j] * B[j];
		}
		if ( sum + C > 0) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n, x, p;
	int a[50000] = {0}, sum = 1;

	scanf("%d", &n);
	p = (n+1) % 2;
	for(int i=0; i < n; i++) {
		scanf("%d", &x);
		if(x%2 != p) {
			printf("0");
			return 0;
		}
		a[x/2]++;
	}

	if((!p && a[0] != 1) || (p && a[0] != 2)) {
		printf("0");
		return 0;
	}else if(p) {
		sum *= 2;
	}

	for(int i=1; i < (n+1)/2; i++) {
		if(a[i] != 2) {
			printf("0");
			return 0;
		}
		sum = (sum*2) % 1000000007;
	}
	printf("%d", sum);

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    cout<<setprecision(10);
 int n;
  cin>>n;
 double a[n];
  double p=1.0000000000;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
     p*=a[i];
  }
  double d =0.0000000000;
  for(int i=0;i<n;i++)
  {
    d = d +(double)p/(double)a[i];
  }
  double ans = (double)p/(double)d;
  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void grade(char c) {
	cout << c << endl;
}
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int m, f, r;
	while (true) {
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) break;
		if (m == -1 || f == -1 || m + f < 30) { grade('F'); continue; }
		if (m + f >= 80) { grade('A'); continue; }
		if (m + f < 80 && m + f >= 65) { grade('B'); continue; }
		if (m + f < 65 && m + f >= 50) { grade('C'); continue; }
		if (r >= 50) { grade('C'); continue; }
		grade('D');
	}
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
int main()
{
	int n,k;
	cin >> n >> k;
	ll arr[n+1];
	for(int i=1;i<=n;i++){
		cin >> arr[i];
	}
	ll dp[n+1][k+1];//dp[i][j] is number of ways to distribute j candies among first i people
	for(int i=1;i<=k;i++){
		dp[0][i] = 0;
	}
	dp[0][0] = 1;
	for(int i=1;i<=n;i++){
		ll sum[k+1];//sum[j] is number of ways to distribute atmost j candies among i-1 people
		sum[0] = dp[i-1][0];
		for(int j=1;j<=k;j++){
			sum[j] = (sum[j-1] + dp[i-1][j])%MOD;
		}
		for(int j=0;j<=k;j++){
			ll upper = sum[j];
			ll lower_index = j-arr[i]-1;
			if(lower_index >= 0){
				upper = (upper - sum[lower_index]+MOD)%MOD;
			}
			dp[i][j] = upper%MOD;
		}
	}
	cout << dp[n][k]%MOD << "\n";
	return 0;
}


Measured memory_bytes: 83252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A[10];
  for(int i=0;i<10;i++){
    cin>>A[i];
  }
  sort(A,A+10);
  cout<<A[9]<<endl;
  cout<<A[8]<<endl;
  cout<<A[7]<<endl;

  return 0;
  
}

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

typedef long long ll;
#define mod 1000000007

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void solve() {
    int n;
    cin>>n;
    int cnt = 0;
    bool ans = false;
    for(int i = 0; i < n; i++){
        int a, b;
        cin>>a>>b;
        if(a == b){
            cnt += 1;
        }
        else{
            cnt = 0;
        }
        if(cnt >= 3){
            ans = true;
        }
    }
    if(ans){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
}
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    // pre();
    while (t--)
        solve();

    return 0;
}

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

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

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc107/tasks/abc107_b
#include <bits/stdc++.h>
using namespace std;

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<char> mp(H * W);
  vector<bool> col(W, true);
  vector<bool> row(H, true);

  rep(i, H) {
    rep(j, W) {
      cin >> mp.at(i * W + j);
      if (mp.at(i * W + j) == '#') {
        row.at(i) = false;
        col.at(j) = false;
      }
    }
  }

  rep(i, H) {
    if (row.at(i)) continue;
    rep(j, W) {
      if (col.at(j)) continue;
      putchar(mp.at(i * W + j));
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool include3(int i){
    int x=i;
    while(x){
        if(x%10==3)return true;
        x/=10;
    }
    return false;
}

void call(int n){
    for(int i=1;i<=n;i++){
        if(i%3==0||include3(i)){
            cout<<" "<<i;
        }
    }
    cout<<endl;
}

int main(void){
    int n;
    cin>>n;
    call(n);
}

Measured memory_bytes: 3064
S = input()


def is_acgt(c):
    return c == 'A' or c == 'C' or c == 'G' or c == 'T'


succession = 0
max_succession = 0
for c in S:
    if is_acgt(c):
        succession += 1
    else:
        max_succession = max(succession, max_succession)
        succession = 0
print(max(succession, max_succession))


Measured memory_bytes: 2940
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>

using namespace std;
using ll = long long;

ll mod = 1000000007;

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

  map<ll, ll> mp;
  for (ll i = 2; i <= n; ++i) {
    ll tmp = i;
    for (ll j = 2; j <= sqrt(i) + 1;) {
      if (tmp / j * j == tmp) {
        tmp /= j;
        if (mp.find(j) == mp.end())
            mp[j] = 1;
        else
          mp[j] += 1;
      } else {
        ++j;
      }
    }
    if (tmp != 1) {
      if (mp.find(tmp) == mp.end())
        mp[tmp] = 1;
      else
        mp[tmp] += 1;
    }
  }

  ll ans = 1;
  for (auto &v : mp)
    ans = ans * (v.second + 1) % mod;
  cout << ans << endl;

}


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

int main() {
    int n;
    cin >> n;
    set<ll> s;
    for(int i=0; i<n; i++){
        ll a;
        cin >> a;
        s.insert(a);
    }
    if(s.size() == n){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
}

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

int main() {
	long long n=0;
	long long a[101];
	long long k=0;
	cin >> n;
	cin >> k;
	long long sum=0;
	for (int i=1; i<=n; i++) {
		cin >> a[i];
		sum+=min(2*a[i],2*k-2*a[i]);
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string n;
    cin >> n;
    cout << (n.find('9')!=-1?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int yakusu(int a, int b, int c){
    int cnt = 0;
    for(int i = a; i <= b; i++){
        if(c % i == 0)cnt++;
    }
    return cnt;
}


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << yakusu(a,b,c) << endl;
}


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

int main() {

	int l, m, n;
	long A[100][100], B[100][100], C[100][100];

	cin >> n >> m >> l;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> B[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			C[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			for (int k = 0; k < m; k++) {
				C[i][j] += A[i][k] * B[k][j];
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			cout << C[i][j];
			if (j != l - 1)cout << " ";
		}
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 1392
def pow2( n ):
    ans = 1 
    for i in range(n):
        ans = 2*ans % 1000000007
    return ans

N = int(input())
AList = list(map(int,input().split()))
AList.sort()

if N % 2 == 0:
    flag = True
    for n in range(0,N-1,2):
        if AList[n] == n+1 and AList[n+1] == n+1:
            pass
        else:
            flag = False
            break

    if flag == False:
        print(0)
    else:
        a = N//2
        print(pow2(a))
else:
    flag = True
    if AList[0] != 0:
        flag = False
    else:
        for n in range(1,N-1,2):
            if AList[n] == n+1 and AList[n+1] == n+1:
                pass
            else:
                flag = False
                break
    if flag == False:
        print(0)
    else:
        a = N//2
        print(pow2(a))

Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector< set<int> >q(30);
int main(){
    int n,i,j,t,l,r,k,f,ans;
    string s;
    char c;
    cin>>n>>s;
    for(int i=0;i<26;i++)q[i]={n};
    for(int i=0;i<n;i++)q[s[i]-'a'].insert(i);
    cin>>t;
    while(t--){
        cin>>f;
        if(f==1){
            cin>>k>>c;k--;
            if(s[k]!=c) q[s[k]-'a'].erase(k);
            s[k]=c;
            q[c-'a'].insert(k);
        }else{
            ans=0;
            cin>>l>>r;l--;r--;
            for(int j=0;j<26;j++)if(*q[j].lower_bound(l)<=r) ans++;
            cout<<ans<<endl;
        }
    }
    return 0;
}

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

int main(){
    int n;cin>>n;
    vector<int> nums(n);for (int i=0;i<n;i++){cin>>nums[i];}

    int acc = 0;
    bool consecutive = false;
    for (int i=0;i<n;i++){
        if (nums[i] == i + 1){
            if (consecutive){
                consecutive = false;
            } else {
                acc++;
                consecutive = true;
            }
        } else {
            consecutive = false;
        }
    }
    cout << acc << endl;
    return 0;

}

Measured memory_bytes: 640
<?php

fscanf(STDIN, "%s", $N);
fscanf(STDIN, "%d", $k);

$keta = strlen($N);
$ans = 0;
$map = str_split($N);
$list = [];
foreach($map as $n => $str){
    if($str != 0){
        $list[] = $keta-$n;
    }

}


if($k == 1){

    for($i=1;$i<=$keta;$i++){
        if($i != $keta){
            $ans += 9;
        }else{
            $ans += $map[0];
        }

    }
}elseif($k == 2){
    for($i=2;$i<=$keta;$i++){
        for($j = 1; $j<$i;$j++) {
            if ($i != $keta) {
                $ans += 81;
            } else {
                if (!isset($list[1])) {
//                    break;
                    $ans += ($map[0] - 1) * 9;
                } elseif ($j < $list[1]) {
                    $ans += $map[0] * 9;
                } elseif ($j == $list[1]) {
                    $ans += ($map[0] - 1) * 9 + $map[$keta - $j];
                } elseif ($j > $list[1]) {
                    $ans += ($map[0] - 1) * 9;
                }
            }
        }
    }
}elseif($k == 3){

    for($i=3;$i<=$keta;$i++){
        for($j = 2; $j<$i;$j++) {
            for($l = 1; $l < $j;$l++){
                if ($i != $keta) {
                    $ans += 729;
                } else {
                    if (!isset($list[1])) {
                        $ans += ($map[0] - 1) * 9 * 9;
                    } elseif ($j < $list[1]) {
                        $ans += $map[0] * 9 * 9;
                    } elseif ($j > $list[1]) {
                        $ans += ($map[0] - 1) * 9 * 9;
                    } elseif ($j == $list[1]) {
                        if(!isset($list[2])){
                            $ans += ($map[0] - 1) * 9 * 9 + ($map[$keta - $j] - 1) * 9;
                        }elseif($l < $list[2]){
                            $ans += ($map[0] - 1) * 9 * 9 + ($map[$keta - $j]) * 9;
                        }elseif($l > $list[2]){
                            $ans += ($map[0] - 1) * 9 * 9 + ($map[$keta - $j] - 1) * 9;
//                            break;
                        }elseif($l == $list[2]){
                            $ans += ($map[0] - 1) * 9 * 9 + ($map[$keta - $j] - 1) * 9 + $map[$keta-$l];
                        }

                    }
                }
            }
        }
    }
}

echo $ans;

Measured memory_bytes: 4984
/*
author : rahil_1407
motto : Time Management,Consistency,Patience!!
*/

#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define f first
#define s second
#define pii pair<int,int>
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define For(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define pi 3.1415926536
#define MAX 1000005
#define ll int long long

const ll N=10e8+7;
using namespace std;

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

	if(k<=a)
	 cout<<k<<endl;
	else
	{
		int ans=a;
		k-=a;
		if(k<=b)
		 cout<<ans<<endl;
		else
		{
			k-=b;
			while(k--)
			 ans--;

			cout<<ans<<endl;
		}
	}
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
  int n,k,q;
  int point[100005]={0};
  cin>>n>>k>>q;
  for(int i=0;i<q;i++){
    int num;
    cin>>num;
    point[num-1]++;
  }
  
  for(int i=0;i<n;i++){
    if(point[i]>q-k){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return(0);
}


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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){for(int i=0;i<n;i++) cin>>f[i];}

template<typename T,typename U>
void Printarray(T f,U n){for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];}
template<typename T,typename U>
void Printarray2(T f,U n){for(int i=0;i<n;i++) cout<<f[i]<<endl;}
template<typename T,typename U,typename V>
void Printarray3(T f,U a,V b){
  rep(i,a){
    rep(j,b){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}
template<typename T,typename U>
void Printarray4(T f,U n){
  rep(i,n){
    rep(j,n){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}

void flagfunc(bool flag,string A,string B){flag ? cout<<A<<endl : cout<<B<<endl;}
void flag2func(bool flag){flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;}
void flag3func(bool flag){flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string s;cin>>s;
  string::size_type pos=s.find("7");
  flag2func(pos != string::npos);
}


Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

const lld N = 200043;
const lld MOD = 1000000007;

lld add(lld x, lld y)
{
    x =((x%MOD)+(y%MOD))%MOD;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

lld mul(lld x, lld y)
{
    return ((x%MOD)*(y%MOD))% MOD;
}

lld binpow(lld x, lld y)
{
    lld z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

lld inv(lld x)
{
    return binpow(x, MOD - 2);
}

lld divide(lld x, lld y)
{
    return mul(x, inv(y));
}

// Combinations

/*
lld fact[N];

void precalc()
{
    fact[0] = 1;
    for(lld i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

lld C(lld n, lld k)
{
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t,i,j;
    //cin>>t;
    t=1;
    while(t--)
    {
        lld n;
        cin>>n;
        vector<lld>ar(n);
        for(i=0;i<n;i++)
            cin>>ar[i];
        sort(ar.begin(),ar.end());
        lld ans=0;
        for(i=0;i<n;i++)
        {
            for(j=i+1;j<n;j++)
            {
                for(lld k=j+1;k<n;k++)
                    if(ar[i]+ar[j]>ar[k] && ar[i]!=ar[j] && ar[i]!=ar[k]  && ar[k]!=ar[j])
                    ans++;
            }
        }
        cout<<ans<<endl;
    }
}





Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

const int MOD = 998244353;
ll facs[4005];
ll ifacs[4005];

ll choose(int n, int k) {
  ll ret = facs[n];
  ret *= ifacs[k];
  ret %= MOD;
  ret *= ifacs[n-k];
  ret %= MOD;
  return ret;
}

ll partition(int n, int k) {
  if(n < 0) return 0;
  return choose(n+k-1, n);
}

ll modpow(ll b, ll e, ll m) {
  ll r = 1;
  while(e) {
    if(e%2){
      r*=b;
      r%=m;
    }
    e/=2;
    if(e) {
      b*=b;
      b%=m;
    }
  }
  return r;
}

ll solve(int n, int k, int l) {
  ll ret = 0;
  for(int m = 0; m <= l; m++) {
    ll inc = choose(l, m);
    inc *= modpow(2, m, MOD);
    inc %= MOD;
    inc *= partition(n-m, k-2*l+m);
    inc %= MOD;
    ret += inc;
    ret %= MOD;
  }
  return ret;
}

void init() {
  facs[0] = 1;
  for(int i = 1; i <= 4000; i++) {
    facs[i] = facs[i-1] * i;
    facs[i] %= MOD;
  }
  ifacs[4000] = modpow(facs[4000], MOD-2, MOD);
  for(int i = 3999; i >= 0; i--) {
    ifacs[i] = ifacs[i+1] * (i+1);
    ifacs[i] %= MOD;
  }
}

void solve() {
  init();
  int n, k;
  cin >> k >> n;
  for(int s = 2; s <= 2*k; s++) {
    int numpairs = 0;
    for(int i = 1; i <= k; i++) {
      int j = s-i;
      if(j <= i) break;
      if(j <= k) numpairs++;
    }
    ll ret = 0;
    if(s%2 == 0) {
      ret += solve(n, k-1, numpairs);
      ret += solve(n-1, k-1, numpairs);
      ret %= MOD;
    }
    else {
      ret += solve(n, k, numpairs);
    }
    cout << ret << "\n";
  }
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long 
using namespace std;
signed main(){
  int n,m,p[100000],ac=0,wa=0,cun[100000]={},c[100000]={};
  string s[100000];
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>p[i]>>s[i];
  }
  for(int i=0;i<m;i++){
    if(s[i]=="AC" && cun[p[i]]==0){
      ac++;
      wa+=c[p[i]];
      cun[p[i]]++;
    }else if(cun[p[i]]==0){
      c[p[i]]++;
    }
  }
  cout<<ac<<" "<<wa<<"\n";
  return(0);
}


Measured memory_bytes: 8064
#include <iostream>

using namespace std;

int main()
{
	int n, k, ans = 1;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int x = 0, y = 0;
		x = ans * 2;
		y = ans + k;
		if (x <= y)
		{
			ans = x;
		}
		else
		{
			ans = y;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))

N = int(input())
for i in range(N):
  b = int(input())
  for j in range(3):
    if(A1[j] == b): A1[j] = 0
    if(A2[j] == b): A2[j] = 0
    if(A3[j] == b): A3[j] = 0
      
ans = 0      
if(A1[0]+A1[1]+A1[2] == 0): ans = 1
if(A2[0]+A2[1]+A2[2] == 0): ans = 1
if(A3[0]+A3[1]+A3[2] == 0): ans = 1
if(A1[0]+A2[0]+A3[0] == 0): ans = 1
if(A1[1]+A2[1]+A3[1] == 0): ans = 1
if(A1[2]+A2[2]+A3[2] == 0): ans = 1
if(A1[0]+A2[1]+A3[2] == 0): ans = 1
if(A1[2]+A2[1]+A3[0] == 0): ans = 1  
 
if(ans == 0): print('No')
else: print('Yes')

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

 
int main() {
   ll a,b,c,k;
   cin>>a>>b>>c>>k;
   if(k<=a)cout<<k<<endl;
   else if(k<=a+b)cout<<a<<endl;
   else cout<<a-(k-a-b)<<endl;
}

Measured memory_bytes: 3588
# Your code here!

def digitsum(v)
    s=0
    while v>0
        s += v%10
        v /= 10
    end
    return s
end

N=gets.to_i
minsum=1000000000
(1..N-1).each{|a|
    b = N - a
    s = digitsum(a)+digitsum(b)
        # puts "a=#{a}, b=#{b}, s=#{s}, minsum=#{minsum}"
    minsum = [minsum, s].min
}
puts minsum




Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n, k;
Int ans;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(Int i=0; i<n; ++i){
		Int h; cin >> h;
		if(h >= k) ++ans;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;

int main() {
  int N, M, w;
  while (cin >> N, N) {
    bool mp[25][25] = {};
    int sx = 10, sy = 10;
    rep(i, N) {
      int a, b;
      cin >> a >> b;
      mp[b][a] = 1;
    }
    cin >> M;
    char s;
    rep(i, M) {
      cin >> s >> w;
      if (s == 'N') {
        rep(j, w) {
          sy++;
          mp[sy][sx] = 0;
        }
      }
      if (s == 'S') {
        rep(j, w) {
          sy--;
          mp[sy][sx] = 0;
        }
      }
      if (s == 'E') {
        rep(j, w) {
          sx++;
          mp[sy][sx] = 0;
        }
      }
      if (s == 'W') {
        rep(j, w) {
          sx--;
          mp[sy][sx] = 0;
        }
      }
    }
    bool ans = 1;
    rep(i, 25) rep(j, 25) if (mp[i][j]) ans = 0;
    cout << (ans ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
int n,num=0;
double ans=0;
vector<int>v;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
    	int a;
		cin>>a;
		v.push_back(a);
	}
	for(int i=0;i<n;i++){
		ans+=1.0/v[i];
	} 
    printf("%.10lf",1.0/ans);
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    cout<<(n+1)/2<<endl;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <algorithm>
int N, K, a[500001], B[500001], T[1048576], A[1048576], O[500001];
int I()
{
	int r = 0, c;
	do c = getchar(); while (c < 48 || c > 57);
	do r = (r << 3) + r + r + (c - 48), c = getchar(); while (c > 47 && c < 58);
	return r;
}
void P(int x, int d)
{
	while (x <= N)
	{
		B[x] += d;
		x += x & -x;
	}
}
int G(int x)
{
	int r = 0;
	while (x)
	{
		r += B[x];
		x &= x - 1;
	}
	return r;
}
void build(int p, int l, int r)
{
	if (l == r)
	{
		if (l + K - 1 <= N)
			P(a[l + K - 1], 1);
		if (l > K)
			P(a[l - K], -1);
		T[p] = G(a[l] - 1);
		return;
	}
	int m = l + r >> 1;
	build(p << 1, l, m);
	build(p << 1 | 1, m + 1, r);
	T[p] = std::min(T[p << 1], T[p << 1 | 1]);
}
void D(int p, int l, int r, int L, int R, int w)
{
	if (L <= l && r <= R)
	{
		T[p] += w;
		A[p] += w;
		return;
	}
	int m = l + r >> 1;
	if (A[p])
	{
		T[p << 1] += A[p];
		T[p << 1 | 1] += A[p];
		A[p << 1] += A[p];
		A[p << 1 | 1] += A[p];
		A[p] = 0;
	}
	if (L <= m)
		D(p << 1, l, m, L, R, w);
	if (R > m)
		D(p << 1 | 1, m + 1, r, L, R, w);
	T[p] = std::min(T[p << 1], T[p << 1 | 1]);
}
void F(int w)
{
	int p = 1, l = 1, r = N;
	while (l < r)
	{
		int m = l + r >> 1;
		if (A[p])
		{
			T[p << 1] += A[p];
			T[p << 1 | 1] += A[p];
			A[p << 1] += A[p];
			A[p << 1 | 1] += A[p];
			A[p] = 0;
		}
		if (T[p << 1] == 0)
			p <<= 1, r = m;
		else
			p = p << 1 | 1, l = m + 1;
	}
	T[p] = 1000000000;
	O[l] = w;
	while (p > 1)
	{
		p >>= 1;
		T[p] = std::min(T[p << 1], T[p << 1 | 1]);
	}
	D(1, 1, N, std::max(1, l - K + 1), std::min(N, l + K - 1), -1);
}
int main()
{
	N = I();
	K = I();
	for (int i = 1; i <= N; i++)
		a[i] = I();
	for (int i = 1; i < K; i++)
		P(a[i], 1);
	build(1, 1, N);
	for (int T = 1; T <= N; T++)
		F(T);
	for (int i = 1; i <= N; i++)
		printf("%d\n", O[i]);
	return 0;
}


Measured memory_bytes: 17536
/*
 * ARC079_C.cpp
 *
 *  Created on: Jun 6, 2018
 *      Author: 13743
 */
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

vector<int> g[200000];
int d[200000];

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

	int N, M;
	cin >> N >> M;
	REP(i, M) {
		int u, v;
		cin >> u >> v;
		g[u-1].pb(v-1);
	}

	queue<int> que;
	que.push(0);
	d[0] = 1;
	while(!que.empty()) {
		int rt = que.front(); que.pop();
		for(int v : g[rt]) {
			if(d[v] != 0) continue;
			d[v] = d[rt] + 1;
			que.push(v);
		}
	}
	if(d[N-1]==0 || d[N-1] > 3) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << "POSSIBLE" << endl;
	}
}






Measured memory_bytes: 9720
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	int n,time[10000];
	long long ans=0;
	
	while(cin>>n){
		if(n==0)break;
		int wait=0;
		for(int i=0;i<n;i++)cin>>time[i];
		sort(time,time+n);
		for(int i=0;i<n;i++){
			ans+=wait;
			wait+=time[i];
		}
		cout<<ans<<endl;
		ans=0;
	}
	return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
vec B;
int search(){
    vec C;
    while(B.size()>1){
        int b=pow(2,int(log2(B.size()))),a=0;
        rep(i,b) a=a^B[i];
        rep(i,B.size()-b+1){
            C.push_back(a);
            if(i<B.size()-b) a=a^B[i]^B[i+b];
        }
        B=C;
        C.clear();
    }
    return B[0];
}
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    vec A(n);
    rep(i,n) A[i]=s[i]-'0';
    rep(i,n-1) B.push_back(abs(A[i]-A[i+1]));
    int z=1;
    rep(i,n-1) if(B[i]==1) z=0;
    if(z){
        if(search()) cout<<2;
        else cout<<0;
    }
    else{
        rep(i,n-1) if(B[i]!=1) B[i]=0;
        if(search()) cout<<1;
        else cout<<0;
    }
}

Measured memory_bytes: 13176
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  int n;
  string s;
  cin >> n >> s;

  int cntR = 0, cntB = 0;
  rep(i, s.size()) {
    if(s[i] == 'R') cntR++;
    else cntB++;
  }

  bool flag = false;
  if(cntR > cntB) flag = true;

  cout << (flag ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9')x=(x<<1)+(x<<3)+c-'0',c=getchar();
	return x*f;
}
int n,ans;
map<int,int>m;
int main()
{
	n=read();
	while(n--)
	{
		int x=read();
		m[x]++;
	}
	for(map<int,int>::iterator it=m.begin();it!=m.end();it++)
	{
		int a=(*it).first,b=(*it).second;
		if(b>a)ans+=b-a;
		if(b<a)ans+=b;
	}
	printf("%d",ans);
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define X real()
#define Y imag()
using namespace std;
using ll=long long;
using point=complex<ll>;

const int MXN=200005;

int n,qh,h[MXN];
ll dp[MXN],sqh[MXN],C;

bool cmpfrac(ll a,ll b,ll c,ll d){
  if(a/b!=c/d)return a/b>c/d;
  return a%b*d>=c%d*b;
}

bool ccw(point a,point b,point c){
  const point p=b-a;
  const point q=c-a;
  return cmpfrac(p.Y,p.X,q.Y,q.X);
}

int main(){
  scanf("%d%lld",&n,&C);
  for(int i=1;i<=n;++i)scanf("%d",h+i);
  for(int i=1;i<=n;++i)sqh[i]=(ll)h[i]*h[i];
  deque<point>hull={{-2*h[n],sqh[n]}};
  for(int i=n-1;i>=1;--i){
    auto f=[&](int x){return hull[x].X*h[i]+hull[x].Y;};
    while(hull.size()>=2&&f(hull.size()-1)>f(hull.size()-2))hull.pop_back();
    dp[i]=f(hull.size()-1)+sqh[i]+C;
    point p={-2*h[i],dp[i]+sqh[i]};
    while(hull.size()>=2&&ccw(hull[1],hull[0],p))hull.pop_front();
    hull.push_front(p);
  }
  printf("%lld\n",dp[1]);
}


Measured memory_bytes: 5760
N = int(input())

# 26進数に変換する問題
ans = ""
alphabet = "Xabcdefghijklmnopqrstuvwxyz"
while N > 0:
    mod = N % 26
    if mod == 0:
        mod = 26
    ans = alphabet[mod] + ans
    N -= mod
    N //= 26

print(ans)


Measured memory_bytes: 60980
a,b=input().split()
lis=(("1","3","5","7","8","10","12"),("4","6","9","11"),("2"))
for gn, row in enumerate(lis):
    try:
        A=(gn, row.index(a))
        break
    except ValueError:
        pass
for gn, row in enumerate(lis):
    try:
        B=(gn, row.index(b))
        break
    except ValueError:
        pass    
print("Yes" if A[0]==B[0] else "No")    

Measured memory_bytes: 38256
/*
  AOJ 2252
  Title:koukyoukoukokukikou
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

char left_[]="qwertasdfgzxcvb";
char buf[100];

int hand(char c)
{
  if(strchr(left_,c))
    return(1);
  else
    return(0);
}

main()
{
  int i,prev,cur,cnt;

  while(scanf("%s",buf) && buf[0]!='#')
    {
      prev=hand(buf[0]);
      for(i=1,cnt=0;i<strlen(buf);i++)
	{
	  cur=hand(buf[i]);
	  if(prev!=cur)
	    cnt++;
	  prev=cur;
	}
      printf("%d\n",cnt);
    }
  return(0);
}

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

int N, K;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  int digit = 1;
  while(true){
    long long divider = 1;
    for(int i = 0; i < digit; i++){
      divider *= K;
    }
    if(N / divider == 0){
      cout << digit <<endl;
      return 0;
    }
    digit++;
  }
}


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

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999

typedef long long ll;

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

	char S[8];
	sprintf(S, "%d", N);

	int cnt = 0;

	FOR(i, 0, 4){
		if(S[i] == '2')
			cnt++;
	}

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
using namespace std;
int main(void){
    long long a, b;
    double f;
  cin >> a>> b;
  f = 1.0*a/b;
  cout << fixed;
  cout << a/b << " " << a%b << " " << setprecision(5)<< f<< endl;
  return 0;
}



Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
int n,x,ans,s;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
	
	cin>>x;
	while(x%2==0)
   {s++;
   x=x/2;
	   }	
	
	}
	cout<<s;
	
	
	return 0;
	
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

//code by lynmisakura.wish to be accepted!
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

/***************************/
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

class ACircle {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int r;cin >> r;
        cout << r*r << endl;
    }
};

int main() {
	ACircle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#n = int(input())
a,b,c,d = map(int,input().split())
#a_L = list(map(int,input().split()))

while True:
    c = c - b
    if c<=0:
        print("Yes")
        exit()
    a = a-d
    if a<=0:
        print("No")
        exit()

Measured memory_bytes: 61560
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        double sum=0;

        for(int i=0;i<n;i++){
            int a=sc.nextInt();
            sum += 1.0/a;
        }

        sum = 1.0/sum;
        System.out.println(sum);

    }

}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 075_arc_b / Link: https://abc063.contest.atcoder.jp/tasks/arc075_b?lang=en  ----- */
/* ------問題------

あなたが散歩していると、突然 N 体の魔物が出現しました。それぞれの魔物は 体力 という値を持ち、i 体目の魔物の出現時の体力は hi です。体力が 0 以下となった魔物は直ちに消滅します。
幸い、あなたは熟練の魔法使いであり、爆発を引き起こして魔物を攻撃できます。一回の爆発では、以下のように魔物の体力を減らすことができます。
生存している魔物を一体選び、その魔物を中心に爆発を引き起こす。爆発の中心となる魔物の体力は A 減り、その他の魔物の体力はそれぞれ B 減る。ここで、A と B はあらかじめ定まった値であり、A>B である。
すべての魔物を消し去るためには、最小で何回の爆発を引き起こす必要があるでしょうか？

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N,A,B;

LL ans = 0LL;


bool f(LL x, VL &h) {// x回で倒せるか
	LL cnt = 0;
	FOR(i, 0, N) {
		LL lefth = h[i] - x*B;
		LL atk = (lefth+A-B-1)/(A-B);
		if(lefth>0)cnt += atk;
	}
	return cnt <= x;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N>>A>>B;
	VL h(N);
	FOR(i, 0, N) {
		cin >> h[i];
	}
	RSORT(h);

	LL L = 0; LL R = INF;
	FOR(i, 0, 50) {
		LL mid = (L + R) / 2;
		if (f(mid, h)) {
			R = mid;
		}
		else L = mid;
	}
	cout << R << endl;

	return 0;
}


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

namespace ARC84_C
{



    class Program
    {
        public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
        {
            int low = start;
            int high = end;
            int mid;
            while (low < high)
            {
                mid = ((high - low) >> 1) + low;
                if (comparer.Compare(arr[mid], value) < 0)
                    low = mid + 1;
                else
                    high = mid;
            }
            return low;
        }

        public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
        {
            int low = start;
            int high = end;
            int mid;
            while (low < high)
            {
                mid = ((high - low) >> 1) + low;
                if (comparer.Compare(arr[mid], value) <= 0)
                    low = mid + 1;
                else
                    high = mid;
            }
            return low;
        }

        //引数省略のオーバーロード
        public static int UpperBound<T>(T[] arr, T value)
        {
            return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
        }
        //引数省略のオーバーロード
        public static int LowerBound<T>(T[] arr, T value) where T : IComparable
        {
            return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
        }

        static void Main(string[] args)
        {

            var n = int.Parse(Console.ReadLine());
            var a0 = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var b0 = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var c0 = Console.ReadLine().Split().Select(long.Parse).ToArray();
            Array.Sort(a0);
            Array.Sort(b0);
            Array.Sort(c0);

            long d = 0;
            for (int i = 0; i < n; i++)
            {
                long ai = Math.Max(LowerBound<long>(a0, b0[i]), 0);
                long ci = Math.Max(n - UpperBound<long>(c0, b0[i]), 0);
                d += ai * ci;
            }

            Console.WriteLine(d);
        }
    }
}



Measured memory_bytes: 44052
slist = input()
tlist = input()
scounter = 0
slength=len(slist)
slist=slist+slist
preposition=-1
for tchar in tlist:
    preposition=slist.find(tchar, preposition+1)
    if preposition==-1:
        scounter=-1
        break
    elif preposition>=slength:
        scounter+=slength
        preposition-=slength
    # print(tchar, scounter, preposition)
if (scounter==-1):
    print(scounter)
else:
    print(scounter+preposition+1)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	vector<pair<int, int> > red(N), blue(N);
	for (int i = 0; i < N; i++)cin >> red[i].first >> red[i].second;
	for (int i = 0; i < N; i++)cin >> blue[i].second >> blue[i].first;
	sort(red.begin(), red.end(), greater<>());
	sort(blue.begin(), blue.end());
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < red.size(); j++) {
			if (red[j].second < blue[i].first && red[j].first < blue[i].second) {
				ans++;
				red.erase(red.begin() + j);
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <functional>
typedef long long ll;

int main(void) {
  ll i, j, k, h, n, m = 2 * 1e4, ans = 1e9;
  scanf("%lld%lld", &h, &n);
  ll dp[m + 1], a, b;
  for(i = 0; i <= m; ++i) dp[i] = 1e9;
  dp[0] = 0;
  for(i = 0; i < n; ++i) {
    scanf("%lld%lld", &a, &b);
    for(j = 0; j < m - a; ++j) if(dp[j + a] > dp[j] + b) dp[j + a] = dp[j] + b;
  }
  for(i = h; i <= m; ++i) if(ans > dp[i]) ans = dp[i];
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256