akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int N = 200003, M = N << 1;

int n, m;
int a[N], b[N];
char s[N], t[N];

int main()
{
    int a = gi(), b = gi(), c = gi(), d = gi();
    int ans = 0;
    if (d > 0) ans += min(d, a), d -= a;
    if (d > 0) d -= b;
    if (d > 0) ans -= d;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ff first
#define ss second
#define maxn 1000000007
#define PI 3.14159265358979323846
#define MAX 1000007 
using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    //cout<<fixed<<setprecision(20);
    ll n;
    cin>>n;
    pair<string,pair< ll,ll > > s[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>s[i].ff;
        cin>>s[i].ss.ff;
        s[i].ss.ss=i;
    }
    sort(s,s+n);
    std::map<string, set< pair<ll,ll> > > m;
    set< pair<ll,ll> >::iterator it;
    for (int i = 0; i < n; ++i)
    {
        m[s[i].ff].insert(mp(s[i].ss.ff,s[i].ss.ss));
    }
    std::map<string, ll> m2;
    for (int i = 0; i < n; ++i)
    {
        if(m2[s[i].ff]>0)
        {
            continue;
        }
        //cout<<s[i].ff<<endl;
        m2[s[i].ff]++;
        it=m[s[i].ff].end();
        it--;
        while(it!=m[s[i].ff].begin())
        {
            cout<<(*it).ss+1<<endl;   
            it--;
        }
        cout<<(*it).ss+1<<endl;
    }
    return 0;
}

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

int main() {
  int N,K,result;
  cin >> N >> K;
  result = 1;
  for (int i=0;i<N;i++){
    result += (result<=K)*result+(result>K)*K;
  }
  cout << result << endl;
  return 0;
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 200007;

int n;
int d1, dx;
LD H[MAXN];
LL da[MAXN], db[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
	
	H[0] = 0;
	lp ( i, 1, MAXN ) H[i] = H[i-1] + SC ( LD, 1 ) / i;
}

void input ()
{
	// input method
	
	scanf ( "%d%d%d", &n, &d1, &dx );
}

void work ()
{
	// main work
	
	int nd = d1;
	db[0] = 0;
	lpi ( i, 1, n ){
		da[i] = db[i-1] + nd;
		nd += dx;
		db[i] = da[i] + nd;
		nd += dx;
	}
	
	LD ans = 0;
	lpi ( i, 1, n ){
		ans += 0.5 * ( db[i] - db[i-1] );
		if ( i > 1 ) ans += 0.25 * ( ( i - 1 ) * 2 * ( -dx ) + ( H[i] - H[1] ) * ( ( db[i-1] - db[i-2] ) + 4 * dx ) );
		ans += 0.25 * ( ( n - i ) * 2 * dx + ( H[n-i+1] - H[1] ) * ( ( db[i+1] - db[i] ) - 4 * dx ) );
	}
	
	cout << setprecision ( 13 ) << fixed << ans << endl;
}

Measured memory_bytes: 6528
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

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

	char convert[255];
	for(int i = 0; i < 26; ++i)
		convert['A' + i] = 'A' + (i + 23) % 26;

	string s;
	cin >> s;

	for(int i = 0; i < s.size(); ++i)
		s[i] = convert[s[i]];

	cout << s << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1180
#include <iostream>
using namespace std;
int main(){
	int n,m,p;
	while(cin>>n>>m>>p){
		if(n==0&&m==0&&p==0) break;
		int x[n];
		for(int i=0;i<n;i++){
			cin>>x[i];
		}
		if(x[m-1]==0){
			cout<<0<<endl;
		}
		else{
			int t=0;
			for(int i=0;i<n;i++){
				t=t+x[i];
			}
			cout<<(t*(100-p))/x[m-1]<<endl;
		}
	}
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1000000000+7)

int main() {
    ull A, B;
    ull C, D;
    cin >> A >> B >> C >> D;
    
    ull CD = C * D / gcd(C, D);
    
    ull x = B/C + B/D - B/CD;
    ull y = (A-1)/C + (A-1)/D - (A-1)/CD;
    
    cout << B-A+1-(x-y) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
struct node {
  struct node *ri;
  int key;
  struct node *le;
};
typedef struct node * NodePointer;
 
NodePointer head, tail;
void init(void);
NodePointer makenode(int);
void insert(int,NodePointer);
void preorder(NodePointer);
void inorder(NodePointer);
int find(int,NodePointer);

void init(void){
  head=makenode(-1);
  tail=makenode(-1);
  head->ri=tail;
  head->le=tail;
}
 
NodePointer makenode(int k){
  NodePointer x;
 
  x=malloc(sizeof(struct node));
  x->key = k;
  x->le = x->ri = tail;
 
  return x;
}
 
void insert(int k, NodePointer p){
  if(k < p->key){
    if(p->le == tail){
      p->le = makenode(k);
    }else{
      insert(k , p->le);
    }
  }else{
    if(p->ri == tail){
      p->ri = makenode(k);
    }else{
      insert(k , p->ri);
    }
  }
}
 
void preorder(NodePointer node){
  if(node != tail){
    printf(" %d", node->key);
    preorder(node->le);
    preorder(node->ri);
  }
}
 
void inorder(NodePointer node){
  if(node != tail){
    inorder(node->le);
    printf(" %d", node->key);
    inorder(node->ri);
  }
}
  
int find(int k,NodePointer node){
  if(node == tail){
    return 0;
  }
 
  if(node->key == k){
    return 1;
  }else if(node->key < k){
    return find(k , node->ri);
  }else{
    return find(k , node->le);
  }
}
int main(){
  char str[10];
  int n,k;
 
  init();
  scanf("%d" ,&n);
  while(n--){
    scanf("%s" ,str);
 
    if(str[0] == 'i'){
      scanf("%d" ,&k);
      insert(k, head);
    }else if(str[0] == 'p'){
      inorder(head->ri);
      printf("\n");
      preorder(head->ri);
      printf("\n");
    }else{
      scanf("%d" ,&k);
      if(find(k,head->ri)){
    printf("yes\n");
      }else{
    printf("no\n");
      }
    }
  }
 
  return 0;
}

Measured memory_bytes: 13116
#include<stdio.h>

int main(void){
  int a[4],i;
  for(i=0;i<4;i++){
    a[i] = getchar()-'0';
  }
  if(a[1]!=a[2]){
  }else{
    if((a[0]==a[1]) || (a[2]==a[3])){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
 
using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
  
const int maxl = 1e3 + 10; 
  
void solve() {
	int n;
	cin >> n;
	
	vi l(n);
	for(int i = 0; i < n; i++) cin >> l[i];
	
	sort(all(l));
	
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			ans += int(upper_bound(all(l), l[i] + l[j] - 1) - l.begin()) - j - 1;
		}
	}
	
	cout << ans << endl;
}
 
int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else
 
    solve();
    
#endif
 
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    string A, B;
    cin >> A >> B;

    if (A.size() != B.size()) {
        cout << (A.size() > B.size()? "GREATER" : "LESS") << endl;
        return 0;
    }

    int ans = 0;
    rep(i, A.size()) {
        if (A[i] != B[i]) {
            ans = A[i] > B[i]? 1 : -1;
            break;
        }
    }

    if (ans > 0) {
        puts("GREATER");
    } else if (ans < 0) {
        puts("LESS");
    } else {
        puts("EQUAL");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define CHKR
#define ll long long
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define ARRS int(2e5+500)
#define BARRS int(6e4+600)
#define MAX ((int)(2e9+15))
#define EP ((double)(1e-12))
#define MMAX ((long long)(1e9+10))
#define HS1 ((long long)(1000001329))
#define HS2 ((long long)(1000001531))
#define MOD ((long long)1000000000ll)
#define SQ 31622780
#define PI 3.14159265358979323846264338327950288419716939937510
#define BG 4294967232ll
#define MH 200008
ll a[ARRS];

#ifndef CHKR
int main(){
#else
int doit(fstream &in,fstream &out){
    cin.rdbuf(in.rdbuf());
    //cout.rdbuf(out.rdbuf());
#endif
    #ifdef KHOKHO
        #ifndef CHKR
        freopen("in.in","r",stdin);
        freopen("out.out","w+",stdout);
        #endif //CHKR
    #endif //KHOKHO
    ll n,m,k,d=MAX,l,r;
    string s;
    cin>>n>>m>>l>>r;
    if(n%l||m%r){
   // else if((n/l)*(m/r)<(n%l)*m+(m%r)*n-(n%l)*(m%r)){
		cout<<"Yes"<<endl;
		ll t=0;
		for(int i=1; i<=n; i++){
			for(int j=1; j<=m; j++){
				if(i%l==0&&j%r==0){
					cout<<-(l*r-1)*1000-1<<" ";
					t+=-(l*r-1)*1000-1;
				}
				else t+=1000,cout<<1000<<" ";
			}
			cout<<endl;
		}
		//cout<<t<<endl;
    }
    else cout<<"No";

    return 0;
}


Measured memory_bytes: 1536
import math

N,H = map(int,input().split())
alis=[];blis=[]
for c in range(N):
    a,b = map(int,input().split())
    alis.append(a);blis.append(b)
a = max(alis)
blis.sort();blis.reverse()
count = 0
num = 0
for i in blis:
    if num >= H:
        print(count)
        exit()
    if i < a:
        break
    num += i
    count += 1
count += math.ceil((H-num)/a)
print(count)


Measured memory_bytes: 11332
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
//const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
int main(){
    int n,m;
    std::cin >> n>>m;
    std::vector<int> k(m),p(m);
    std::vector<std::vector<int> >s(m) ;
    rep(i,m){
        std::cin >> k[i];
        rep(j,k[i]){
            int d;
            std::cin >> d;
            d--;
            s[i].pb(d);
        }
    }
    rep(i,m)std::cin >> p[i];
    int ans=0;
    brep(n){
        std::vector<int> c(m);
        rep(i,m){
            erep(j,s[i]){
                if(bit&(1<<j))c[i]++;
            }
        }
        int dd=0;
        rep(i,m){
            if(c[i]%2==p[i])dd++;
        }
        if(dd==m)ans++;
    }
    std::cout << ans << std::endl;
}

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

int main() {
  string S; cin >> S;
  int ans = 0;
  for(char c : S) {
    if(c=='+') ans++;
    else ans--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "5 1", "00010" ].parse.expand.solve == 4 );
	assert( [ "14 2", "11101010110011" ].parse.expand.solve == 8 );
	assert( [ "1 1", "1" ].parse.expand.solve == 1 );
}



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

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

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

auto solve( long k, string s )
{
	// 連続した同じ体制の人をグループにする
	auto gs = s.group.array;
	
	// 後続の処理を楽にするために入力の形を整える
	if( gs[ 0     ][ 0 ] == '0' ) gs = [ Tuple!( dchar, uint )( '1', 0 ) ] ~ gs;
	if( gs[ $ - 1 ][ 0 ] == '0' ) gs = gs ~ [ Tuple!( dchar, uint )( '1', 0 ) ];
	
	// 人数の累積和を計算
	auto ss = new long[ 1 + gs.length ];
	for( auto i = 1L; i < ss.length; i++ )
	{
		ss[ i ] = ss[ i - 1 ] + gs[ i - 1 ][ 1 ];
	}
	
	// 連続で逆立ちする人を並ばせられる最大数を検索
	auto ans = 0L;
	for( auto li = 1L; li < ss.length; li += 2 )
	{
		auto e = min( li + 1 + ( 2 * k ), ss.length );
		for( auto ri = li; ri < e; ri += 2 )
		{
			ans = max( ans, ss[ ri ] - ss[ li - 1 ] );
		}
	}
	return ans;
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
#define PI 3.14159
using namespace std;


int main() {
	int n;
	scanf("%d", &n);
	
	int a[n] = {0};
	int tmp;
	for(int i=1; i<n; ++i) {
		cin>>tmp;
		
		a[--tmp]++;
	}
	
	for(int i=0; i<n; ++i)
		printf("%d\n", a[i]);
	
	return 0;
}


Measured memory_bytes: 4616
#include <iostream>
using namespace std;
// エラトステネスのふるい
int main() {
  int num = 1000000;
  int n, prime[num];
  while (cin >> n) {
    for (int i = 0; i < num; i++) {
      prime[i] = 0;
    }
    prime[0] = 1;
    prime[1] = 1;
    
    int count = 0;
    for (int i = 0; i <= n; i++) {
      if (prime[i] == 0) {
	count++;
	for (int j = i; j <= n; j += i) {
	  prime[j] = 1;
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}


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

#define ll long long 
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

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

	int x[5];
	for(int i = 0; i < 5; ++i) {
		cin >> x[i];
	}
	for(int i = 0; i < 5; ++i) {
		if(x[i] == 0) {
			cout << i + 1;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 3632
using System;

namespace ABC118_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int c;
            int d;
            int e;
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);
            c = b % a;
            d = a + b;
            e = b - a;
            if (c == 0)
            {
                Console.WriteLine(d);
            }else
            {
                Console.WriteLine(e);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  ll n;
  cin >> n;
  int num = 0;
  REP(i,a+1){
    REP(j,b+1){
      REP(k,c+1){
	ll sum = 500*i+100*j+50*k;
	if(sum == n)
	  num++;
      }
    }
  }
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

#include <map>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 };

ll fact[MAX], inv[MAX];

ll fast_exp(ll a, ll n)
{
    ll res = 1, base = a;

    while (n)
    {
        if (n & 1)
        {
            res *= base;
            res %= MOD;
        }

        base *= base;
        base %= MOD;

        n >>= 1;
    }

    return res;
}

ll binom(int n, int m)
{
    ll res = (fact[n] * inv[m]) % MOD;
    res = (res * inv[n - m]) % MOD;

    return res;
}

void precomp()
{
    fact[0] = inv[0] = 1;

    for (int n = 1; n < MAX; ++n)
        fact[n] = (n * fact[n - 1]) % MOD;

    for (int n = 1; n < MAX; ++n)
        inv[n] = fast_exp(fact[n], MOD - 2);
}

ll ways(int h, int w)
{
    return binom(h + w - 2, h - 1);
}

int main()
{
    ios::sync_with_stdio(false);
    precomp();

    int H, W, A, B;
    cin >> H >> W >> A >> B;

    ll total = 0;

    for (int h = 1; h <= H - A; ++h)
    {
        total += (ways(h, B) * ways(H - h + 1, W - B)) % MOD;
        total %= MOD;
    }

    cout << total << endl;

    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
string s;
ll k;
int main(void) {
    cin >> s >> k;
    ll cnt=0;
    char res;
    rep(i,s.size()){
        if(s[i]=='1')cnt++;
        else{
            res=s[i];
            break;
        }
    }
    if(k<=cnt){
        cout << 1 << endl;
    }else{
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
      Scanner sc=new Scanner(System.in);
      int[] a=new int[5];
      int res=0;
      for(int i=0;i<5;i++){
      a[i]=sc.nextInt();
        if(a[i]==0)
          res=i+1;
      }
      System.out.println(res);
    }
}


Measured memory_bytes: 35708
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 4*1001001001001001001;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int n,k; cin >>n>>k;
    vector<int> x(n); REP(i,n) cin >> x[i];

    int res = 0;
    for (int i = 0; i < n; i++) {
        res += min(2*x[i], 2*(k - x[i]));
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long q = sc.nextLong();
        long h = sc.nextLong();
        long s = sc.nextLong();
        long d = sc.nextLong();
        long n = sc.nextLong();
        long rem = n % 2;
        long min = n / 2 * d + Math.min(Math.min(rem * s, rem * 2 * h), rem * 4 * q);
        min = Math.min(min, n * s);
        min = Math.min(min, n * 2 * h);
        System.out.println(Math.min(min, n * 4 * q));
    }

}


Measured memory_bytes: 22484
#include <stdio.h>
void showA(int A[], int N) {
  int i;
  for (i = 0; i < N; ++i) {
    printf("%d ", A[i]);
  }
  printf("\n");
}

int bubbleSort(int A[], int N) {
  int flag = 1;
  int i, j, cnt, tmp;

  cnt = 0;
    for (i = 0; i < N - 1; ++i){
      for (j = N - 1; j - i > 0 ; --j) {
	if (A[j - 1] > A[j]) {
	  tmp = A[j];
	  A[j] = A[j - 1];
	  A[j - 1] = tmp;
	  ++cnt;
	  //	  showA(A, N);
	}
      }
  }

  return cnt;
}

int main(void) {
  int n, i;
  int cnt;
  int A[100] = {0};
  n = 0;
  scanf("%d", &n);

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

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

Measured memory_bytes: 600
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const int MAX_N=2e5+3;


const unsigned long long B=1e12+7;


int main(){
    LL A,B,C,K;
    cin>>A>>B>>C>>K;
    cout<<min(K,A)-max(K-A-B,(LL)0)<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

typedef struct node{
  struct node *right, *left, *parent;
  int key;
} * Node;

Node root;

Node treeSearch(Node x, int t){
  if(x == NIL || t == x ->key) return x;
  if(t < x->key) return treeSearch(x->left,t);
  else return treeSearch(x->right,t);

  while(x != NIL && t != x->key){
    if(t < x->key) x = x->left;
    else if(t > x->key) x = x->right;
  }
  return x;
}


void insert(int t){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = t;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key)  x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL)   root = z;
  else if(z->key < y->key) y->left = z;
  else y ->right = z;
}

void inorder(Node x){
  if(x != NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}

void preorder(Node x){
  printf(" %d",x->key);
  if(x->left != NIL) preorder(x->left);
  if(x->right != NIL) preorder(x->right);
}

int main(){
  int n, i, x;
  char com[10];
  Node t;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      t = treeSearch(root,x);
      if( t != NIL) printf("yes\n");
      else printf("no\n");
    }
    if( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }

  }

  return 0;
}


Measured memory_bytes: 20520
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	StringBuilder output = new StringBuilder();
	
	PriorityQueue<Object> Que = new PriorityQueue<>(Collections.reverseOrder());
	
	String text;
	int number;
	
	public void solve() {
		while(true) {
			text = sc.next();
			if(text.equals("end")) {
				break;
			}else if(text.equals("insert")) {
				number = sc.nextInt();
				Que.add(number);
			}else {
				output.append( Que.poll()+"\n" );
			}
		}
		System.out.print(output);
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.solve();
	}
}



Measured memory_bytes: 587324
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  string s;
  cin >> s;
  int ret = 0;
  for(char c: s) {
    if(c == '1') ret++;
  }
  cout << ret << endl;

  return 0;
}


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

long long choose2(long long n){
  return n * (n - 1) / 2;
}

int main(){
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a.at(i);
    a.at(i)--;
  }
  
  vector<int> cnt(n);
  for (int i = 0; i < n; i++){
    cnt.at(a.at(i))++;
  }
  
  long long tot = 0;
  for (int i = 0; i < n; i++){
    tot += choose2(cnt.at(i));
  }
  
  for (int i = 0; i < n; i++){
    long long ans = tot;
    ans -= choose2(cnt.at(a.at(i)));
    ans += choose2(cnt.at(a.at(i)) - 1);
    cout << ans << endl;
    //int diff = cnt.at(a.at(i)) - 1;
    //cout << tot - diff << endl;
  }

}

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

constexpr int MAX_N = 100;

int main(){
    int array[2 * MAX_N], n;
    std::cin >> n;
    
    for(int i = 0; i < 2 * n; ++i){
        std::cin >> array[i];
    }

    std::sort(array, array + 2 * n);

    int ans = 0;

    for(int i = 0; i < 2 * n; i += 2){
        ans += array[i];
    }
    
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque

move = [(0, 1), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1), (1, 0), (-1, 0)]

def count(chizu, start):
    stack = deque([start])
    while stack:
        y, x = stack.pop()
        for dxi, dyi in move:
            if not (0<=x+dxi<w and 0<=y+dyi<h) or chizu[y+dyi][x+dxi] == "0":
                continue
            else:
                stack.append((y+dyi, x+dxi))
        chizu[y][x] = "0"


while True:
    w, h = map(int,input().split())
    if w == 0:
        break
    
    island = [0]*h
    ans = 0
    for i in range(h):
        island[i] = list(input().split())
    
    for r in range(h):
        for c in range(w):
            if island[r][c] == "1":
                count(island, (r, c))
                ans += 1
    print(ans)


Measured memory_bytes: 6304
def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1

n = int(input())
A = list(map(int, input().split(' ')))
pi = partition(A, 0, len(A)-1)

A = ['[' + str(A[i]) + ']' if i == pi else str(A[i]) for i in range(len(A))]
print(' '.join(A))


Measured memory_bytes: 16388
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  ll n,k,sum=0; cin>>n>>k;
  ll a[n];
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  ll l=0,r=1000000000;
  ll x,func,ans;
  while(r-l>1){
    x=(l+r)/2;
    func=0;
    rep(i,n){
      func+=ceil((double)a[i]/x);
    }
    if(func>k+n){
      l=x;
    }else{
      r=x;
    }
  }
  func=0;
  rep(i,n){
    func+=ceil((double)a[i]/x);
  }
  if(func>k+n){
    cout<<x+1;
  }else{
    cout<<x;
  }
}


Measured memory_bytes: 5192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main() {
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    int mi=INT_MAX;
    for(int i=1;i<=100;i++){
        int temp=0;
        for(int j=0;j<n;j++){
            temp+=abs(arr[j]-i)*abs(arr[j]-i);
        }
        mi=min(temp,mi);
    }
    cout<<mi;
}



Measured memory_bytes: 3580
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define pos position<int>
#define at_(p) at(p.x).at(p.y)

#define GCD(v) gcd(ALL(v), 0l)

template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}

template <typename T>
using vec =vector<T>;

template <typename T>
using vvec =vector<vector<T>>;


int main(){
  int n,m;
  cin>>n>>m;
  nvec(int,h,n);
  vec<int> v(n,0);
  int a,b;
  for (size_t i = 0; i < m; i++) {
    cin>>a>>b;
    a--;b--;
    if(h[a]<=h[b])v[a]++;
    if(h[a]>=h[b])v[b]++;
  }
  cout<<count(ALL(v),0);
}



/* きょむ〜 */


Measured memory_bytes: 4048
N = int(input())
txy = [ list(map(int, input().split())) for _ in range(N) ]

d_t = 0
d_x = 0
d_y = 0
    
can = False
for ti in range(len(txy)):
    dist = abs(d_x - txy[ti][1]) + abs(d_y - txy[ti][2])
    dt = abs(d_t - txy[ti][0])
    if dt >= dist and (dt % 2 == 0 and dist % 2 == 0 or dt % 2 != 0 and dist % 2 != 0):
        d_t = txy[ti][0]
        d_x = txy[ti][1]
        d_y = txy[ti][2]
        if ti == len(txy) - 1:
            can = True
    else:
        break
print("Yes" if can else "No")

Measured memory_bytes: 60632
// https://atcoder.jp/contests/abc096/tasks/abc096_b
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> v(3);
    REP(i, 3) cin >> v[i];
    int k;
    cin >> k;
    sort(ALL(v));
    cout << v[0] + v[1] + (v[2] << k) << endl;

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> mat(H, vector<int>(W));
    char c;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> c;
            mat[i][j] = (c == '.');
        }
    }
    vector<vector<bool>> used(H, vector<bool>(W, false));
    queue<P> que;
    ll res = 0;
    ll black = 0;
    ll white = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (used[i][j]) continue;
            black = 0;
            white = 0;
            used[i][j] = true;
            que.push(P(i, j));
            while (!que.empty()) {
                P curr = que.front();
                que.pop();
                int x = curr.first;
                int y = curr.second;
                if (mat[x][y]) ++black;
                else ++white;
                for (int d = 0; d < 4; ++d) {
                    int nx = x + dx[d];
                    int ny = y + dy[d];
                    if ((nx >= 0) && (nx < H) && (ny >= 0) && (ny < W) && !used[nx][ny] && mat[nx][ny] != mat[x][y]) {
                        used[nx][ny] = true;
                        que.push(P(nx, ny));
                    }
                }
            }
            res += black * white;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 896
loop do
    e = gets.to_i
    break if e == 0
    z, ans = 0, e

    while z**3 <= e
        y = Math.sqrt((e-z**3)).floor
        x = e - y**2 - z**3
        ans = [ans, x+y+z].min
        z += 1
    end
    puts ans
end


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 30

enum Turn {
    A, B, C
};

int get_next(string s) {
    switch(s[0]) {
        case 'a':
            return A;
        case 'b':
            return B;
        case 'c':
            return C;
    }
    assert(false);
    return -1;
}

signed main()
{
    string Sa, Sb, Sc;
    cin >> Sa >> Sb >> Sc;
    int next = A;
    REP(i, 10000) {
        if(next == A) {
            if(Sa.length() <= 0) {
                printf("A\n");
                return 0;
            }
            next = get_next(Sa);
            Sa = Sa.substr(1, Sa.length()-1);
        }
        else if(next == B) {
            if(Sb.length() <= 0) {
                printf("B\n");
                return 0;
            }
            next = get_next(Sb);
            Sb = Sb.substr(1, Sb.length()-1);
        }
        else if(next == C) {
            if(Sc.length() <= 0) {
                printf("C\n");
                return 0;
            }
            next = get_next(Sc);
            Sc = Sc.substr(1, Sc.length()-1);
        }
    }
    assert(false);
    return 0;
}


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

int main() {
  vector<int> vec(3);
  
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
  
  sort(vec.begin(), vec.end());
  
  cout << (vec.at(1) - vec.at(0)) + (vec.at(2) - vec.at(1)) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PriorityQueue<Path> queue = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
		    for (int j = 0; j < n; j++) {
		        int x = sc.nextInt();
		        if (i >= j || x < 0) {
		            continue;
		        }
		        queue.add(new Path(i, j, x));
		    }
		}
		UnionFindTree uft = new UnionFindTree(n);
		long total = 0;
		while (queue.size() > 0) {
		    Path p = queue.poll();
		    if (uft.same(p)) {
		        continue;
		    }
		    uft.unite(p);
		    total += p.value;
		}
		System.out.println(total);
	}
	
	static class UnionFindTree {
	    int[] parents;
	    
	    public UnionFindTree(int size) {
	        parents = new int[size];
	        for (int i = 0; i < size; i++) {
	            parents[i] = i;
	        }
	    }
	    
	    public int find(int x) {
	        if (parents[x] == x) {
	            return x;
	        } else {
	            return parents[x] = find(parents[x]);
	        }
	    }
	    
	    public boolean same(int x, int y) {
	        return find(x) == find(y);
	    }
	    
	    public boolean same(Path p) {
	        return same(p.left, p.right);
	    }
	    
	    public void unite(int x, int y) {
	        if (same(x, y)) {
	            return;
	        }
	        parents[find(x)] = find(y);
	    }
	    
	    public void unite(Path p) {
	        unite(p.left, p.right);
	    }
	}
	
	static class Path implements Comparable<Path> {
	    int left;
	    int right;
	    int value;
	    
	    public Path(int left, int right, int value) {
	        this.left = left;
	        this.right = right;
	        this.value = value;
	    }
	    
	    public int compareTo(Path another) {
	        return value - another.value;
	    }
	}
}



Measured memory_bytes: 40876
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<set<int>> vec(26);
    for(int i=0; i<N; i++)
	{
      int x = S.at(i) - 'a';
      vec.at(x).insert(i);
    }
    int Q;
    cin >> Q;
    for(int i=0; i<Q; i++)
    {
	    int a;
	    cin >> a;
	    if(a == 1)
		{
	      int b;
	      cin >> b;
	      b--;
	      char c;
	      cin >> c;
	      int x = S.at(b) - 'a';
	      int y = c - 'a';
	      S.at(b) = c;
	      vec.at(x).erase(b);
	      vec.at(y).insert(b);
	    }
	    else
		{
	        int cnt = 0;
	    	int b,c;
	        cin >> b >> c;
	        b--; c--;
	        for(int j=0; j<26; j++)
		    {
                if(vec.at(j).set::lower_bound(b) != vec.at(j).set::lower_bound(c+1))
				{
                    cnt++;
                }
            }
            cout << cnt << endl;
        }
    }
    return 0; 
} 

Measured memory_bytes: 24324
// ABC114_C
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
typedef long long ll;

ll N, res = 0;

ll dfs(ll x, bool f3, bool f5, bool f7) {
    if (N < x) return 0;
    // check
    if (f3 && f5 && f7) res++;
    dfs(10*x + 3, true, f5, f7);
    dfs(10*x + 5, f3, true, f7);
    dfs(10*x + 7, f3, f5, true);
}

int main() {
    // input
    cin >> N;
    
    // calculation
    dfs(0, false, false, false);
    cout << res << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;


int main(int argc, char const *argv[]) {
  ll N, M;
  std::cin >> N >> M;
  std::vector<int> possible(N+1, 0);
  std::vector<int> num(N+1, 1);
  possible[1] = 1;
  ll x, y, count=1;
  for(int i=0;i<M;i++){
    std::cin >> x >> y;
    num[x]--, num[y]++;
    if(possible[x]==1){
      if(num[x]!=0&&possible[y]==0) {
        count++;
        possible[y] = 1;
      }else if(num[x]==0){
        if(possible[y] == 1) count--;
        possible[y] = 1, possible[x]=0;
      }
    }
  }
  std::cout << count << '\n';
  return 0;
}


Measured memory_bytes: 1024
// C - Traveling
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	bool ans=true;
	for(int i=0; i<N; ++i){
		int t,x,y; cin>>t>>x>>y;
		if(t%2 != (x+y)%2){ ans = false; break; }
		else if(t < x+y){ ans = false; break; }
	}
	cout<< (ans?"Yes":"No") <<endl;
}

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

int p[maxn], T[maxn];
int n;
int now;
int ans;
int c, k;

bool cmp(int a, int b) {
	return (T[a] < T[b]);
}

int main() {
	scanf("%d %d %d",&n,&c,&k);
	for (int i = 1; i <= n; i++) {
		scanf("%d",&T[i]);		
	}
	for (int i = 1; i <= n; i++) p[i] = i;
	sort(p + 1, p + n + 1, cmp);
	int pas = p[1];
	ans = 0; now = 1;
	for (int i = 2; i <= n; i++) {
		if (now == c || T[p[i]] - T[pas] > k) {
			pas = p[i];
			ans++;
			now = max(1, now - c + 1);
		}
		else now++;
	}
	if (now > 0) ans++;
	printf("%d\n",ans);	
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
typedef long long ll;
const int N=100005;
int a[N];
ll ans;
int main(){
	int n,i,m,x;
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	ans=0;
	for (int i=1;i<=n;i++) if (a[i]>=2) {
		x=(a[i]-1)/2;
		ans+=x;
		a[i]-=x*2;
	}
	i=1;
	while (i<=n){
		while (i<=n&&a[i]==0) i++;
		if (i<n-1) if (a[i]==1&&a[i+1]==2&&a[i+2]>=1){
			a[i]=0;
			a[i+1]=0;
			a[i+2]--;
			ans+=2;
		}
				   else if (a[i]==1&&a[i+1]==1){
			a[i]=0;
			a[i+1]=0;
			ans++;
		}
						else{}
		else if (i==n-1) if (a[i]==1&&a[i+1]==1){
			a[i]=0;
			a[i+1]=0;
			ans++;
		}
		i++;
	}
	for (int i=1;i<=n;i++) if (a[i]>=2) ans++;
	printf("%lld\n",ans);
	return 0;
}

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

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

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

ll modpow(ll a,ll n){
    ll res = 1;
    while(n>0){
        // &１つはビット積
        if(n&1) res = res * a%MOD;
        a = a*a%MOD;
        n>>=1;
    }
    return res;
}


int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	COMinit();
	ll N;
	cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin>>A[i];
    }
    ll ans = 0;

    rep(i,N){
        ans += inv[A[i]];
        ans %=MOD;
    }
    
    ll maxn = 10e3+1;
    map<ll,ll> gcm;

    rep(i,N){
        map<ll,ll> gcm_mp;
        for(ll j=2;j<=pow(A[i],0.5);j++){
            while(A[i]%j==0){
                gcm_mp[j]++;
                A[i]/=j;
            }
        }
        if(A[i]!=1){
            gcm_mp[A[i]]++;
        }
        for(auto it:gcm_mp){
            gcm[it.first]= max(gcm[it.first],it.second);
        }
    }
    ll lcm = 1;
    for(auto it:gcm){
        lcm *= modpow(it.first,it.second)%MOD;
        // cout<<it.first << " "<< it.second<<"\n";
        lcm %=MOD;
    }
    ans *=lcm;
    ans %=MOD;
    // cout<<lcm<<"\n";
    cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 24448
/*  ex5_3
    Rikuta  */

#include <stdio.h>

int main(void){
    int height,width,flag;
    //与えられる行列の高さと幅の入力
    scanf("%d %d\n",&height,&width);
    char matrix_given[height][width+1];
    int on_off_matrix[height][width+1];
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width+1; j++)
        {   
            //幅が与えられる行列より1多く，高さはそのままである，要素がすべてが0の行列をつくる．
            on_off_matrix[i][j]=0;
        }
        
    }
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width+1; j++)
        {   
            //改行込みで与えられた行列を受け取る
            scanf("%c",&matrix_given[i][j]);
        }
        
    }
    for (int i = 0; i < height; i++)
    {   
        //フラグを立てる
        flag=1;
        for (int j = 0; j < width; j++)
        {
            if (matrix_given[i][j]=='#')
            {   
                //i行について着目したときに#が一個でもあればフラグを0とする
                flag=0;
            }
            
        }
        //もしi行について#がいっこもなければ
        if (flag)
        {
            for (int j = 0; j < width+1; j++)
            {   
                //on_off_matrixのi行目を1にする
                on_off_matrix[i][j]=1;
            }
            
        }
    }
    for (int i = 0; i < width; i++)
    {   
        //フラグを立てる
        flag=1;
        for (int j = 0; j < height; j++)
        {   
            if (matrix_given[j][i]=='#')
            {   
                //i列について着目したときに#が一個でもあればフラグを0にする
                flag=0;
            }
            
        }
        //i列について，#がなければ
        if (flag)
        {
            for (int j = 0; j < height; j++)
            {   
                //on_off_matrixのi列目を1にする
                on_off_matrix[j][i]=1;
            }
            
        }
    }
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width+1; j++)
        {   
            if (!on_off_matrix[i][j])
            {   
                //与えられた行列の要素に対応するon_off_matrixが0ならばそれを出力する．
                printf("%c",matrix_given[i][j]);
            }
            
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 256