akhauriyash/Code-Regression huggingface dataset:
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

int c[30];
ll dp[52][2510];
void Sequence() {
	int n,a;
	cin >> n >> a;

	dp[0][0] = 1;
	for (size_t i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		for (int j = 50; j >= 0; j--)
		{
			for (size_t k = 0; k < 2501; k++)
			{
				dp[j + 1][k + x] += dp[j][k];
			}
		}
	}

	ll res = 0;
	for (size_t i = 1; i < 51; i++)
	{
		for (size_t j = 1; j < 2501; j++)
		{
			if (j == a * i) {
				res += dp[i][j];
			}
		}
	}
	cout << res << endl;
}
int main() {
	Sequence();
	return 0;
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define endl '\n'
#define maxn 1000000000000000000
using namespace std;

int N, zero = 0;
long long A[100010], prod = 1;

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) zero++; // A[i] contains 0
    }

    if (zero > 0) {cout << 0 << endl; return 0;}

    for (int i = 0; i < N; i++) {
        if (A[i] <= maxn / prod) {
            // This condition is equivalent to prod*A[i] <= 10^18
            prod *= A[i];
        }else {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << prod << endl;

    return 0;
}


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

int main() {
	int n, l;
	cin >> n >> l;
	
	int mn = 1001001001, ans = 0;
	int tot = 0;
	rep(i, n) {
		tot += l + i;
	}
	rep(i, n) {
		int now = 0;
		rep(j, n) {
			if(j == i) continue;
			now += l + j;
		}
		int dif = abs(tot - now);
		if(mn > dif) {
			mn = dif;
			ans = now;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;
    Vec p(n);
    cin>>p;

    ll ans=0;
    ll min =p[0];
    rep(i,n){
        if(min<p[i]){
            //
        }else{
            ans++;
        }
        chmin(min,p[i]);
    }
    cout<<ans<<endl;
    return  0;
}


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

#define MAXN 100010

using namespace std;

vector<int> g[MAXN];
int vis[MAXN], d[MAXN];

void DFS(int u) {
    vis[u] = 1;
    for (auto v : g[u]) {
        if (!vis[v]) DFS(v);
        d[u] = max(d[u], d[v] + 1);
    }
}

int main(void) {
    int n, m;

    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }

    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            DFS(i);
        }
    }

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

    return 0;
}

Measured memory_bytes: 8576
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    var n = sc.nextInt()
    val k = sc.nextInt()

    var count = 0
    while (n > 0) {
        count += 1
        n /= k
    }
    println(count)
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 31272
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long mod = 1e9 + 7;


const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}




int main() {

  long n;

  cin >> n;

  vector<long> h(n);
  cin >> h;

  long ans = 0;

  long tmp = 0;
  long underline = 0;
  bool iscrime = true;
  for (int i = 0; i < n; ++i){
    cerr <<  i<< "id: "<< underline << "  :  " << ans << "  :  " << endl;

    if (tmp < h[i]){//より高い
      if (iscrime == false){
        iscrime = true;
        underline = tmp;
      }

    }else if(tmp > h[i]){
      if (iscrime == true){
        iscrime = false;
        ans += tmp - underline;
      }
    }
    tmp = h[i];
  }

  if (iscrime == true)ans += tmp - underline;




  cout << ans;


}




















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a, b, c, d;
  cin >> N;
  
  a = N / 1000;
  b = (N - a * 1000) / 100;
  c = (N - a * 1000 - b * 100) / 10;
  d = (N - a * 1000 - b * 100 - c * 10);
    
  if(a == b && b == c){
    cout << "Yes" << endl;
  }else if(b == c && c == d){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

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

  sort(a.begin(),a.end());

  ll ans = 1;
  rep(i,n){
    if(a[i]==0){
      ans = 0;
      break;
    }
    else if(a[i]<=1000000000000000000/ans){
      ans *= a[i];
    }
    else{
      ans = -1;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4052
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

string s;
llint sum[100005], pos[100005];
set<llint> S[3], T;
llint dp[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	llint n = s.size();
	s = "#" + s;
	
	S[0].insert(0);
	for(int i = 1; i <= n; i++){
		sum[i] = (sum[i-1] + s[i]-'a'+1) % 3;
		S[sum[i]].insert(i);
	}
	for(int i = 2; i <= n; i++){
		if(s[i-1] == s[i]) T.insert(i);
	}
	if(T.size() == 0){
		cout << 1 << endl;
		return 0;
	}
	
	for(int i = 0; i < 3; i++) S[i].insert(inf);
	T.insert(inf);
	
	dp[0] = 1;
	for(int i = 0; i < n; i++){
		dp[i+1] += dp[i], dp[i+1] %= mod;
		llint lb = *T.lower_bound(i+2), c = 3 - (s[i+1]-'a'+1);
		if(lb > n) continue;
		llint p = *S[(sum[i]+c)%3].lower_bound(lb);
		if(p <= n) dp[p] += dp[i], dp[p] %= mod;
	}
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		if(sum[i] == sum[n]) ans += dp[i], ans %= mod;
	}
	cout << ans << endl;
	
	/*for(int i = 0; i <= n; i++){
		for(int j = 0; j < 2; j++){
			cout << dp[i][j] << " ";
		}cout << endl;
	}*/
	
	return 0;
}

Measured memory_bytes: 14704
// E - Coprime
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rpd(i,s,e,d) for(int i=(s);i<(int)(e);i+=(d))

vi gen_d_prim(int n){
	vi D(n+1, 0);
	rpd(i, 2, n+1, 1)
		if(!D[i]) rpd(j, i, n+1, i) D[j] = i;
	return D;
}

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

	int N; cin>>N;
	int g = 0;
	bool is_pairwise = true;
	vi D = gen_d_prim(1000000);
	set<int> past;
	rpd(i, 0, N, 1){
		int a; cin>>a;
		g = gcd(g, a);
		if(is_pairwise){
			set<int> now;
			while(a != 1){
				// 素数 D[a]: 今回は未済 & 過去は済
				if(!( is_pairwise = now.count(D[a]) || !past.count(D[a]) )) break;
				now.insert(D[a]);
				past.insert(D[a]);
				a /= D[a];
			}
		}
	}
	int t = 0;
	if(g > 1) t = 2;
	else t = !is_pairwise;
	cout<< vector<string>{"pairwise","setwise","not"}[t] <<" coprime\n";
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int n, m, k, a, b, c;
string s, t, r;
char c1, c2, c3;

int A[200005];
int B[200005];
int C[200005];

int main() {
	cin >> n >> k;
	while (n) {
		a++;
		n/=k;
	}
	cout <<a<<endl;
	return 0;
}

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

int main() {
  long long int N, A, B;
  cin >> N >> A >> B;
  if (A == 0) cout << 0 << endl;
  else if (N % (A + B) >= A) {
    cout << (N / (A + B) + 1) * A << endl;
  }
  else {
    cout << (N / (A + B)) * A + (N % (A + B)) << endl;
  }
}

Measured memory_bytes: 256
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;


int n;
map<int, bool> used;
map<int, int> cnt;
vector<int> v;

int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
    //freopen("/Users/danya.smelskiy/Documents/Danya/Danya/output.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        if (!used.count(x)) {
            used[x] = true;
            v.push_back(x);
        }
        cnt[x] ^= 1;
    }
    int res = 0;
    for (int i = 0; i < v.size(); ++i)
        if (cnt[v[i]]) ++res;
    cout << res << '\n';
    return 0;
}



Measured memory_bytes: 9976
A, B, K = map(int, input().split())
ans = set()
for i in range(A, min(B + 1, A + K)):
    ans.add(i)
for i in range(B, max(A - 1, B - K), -1):
    ans.add(i)
ans_list = sorted(list(ans))
for a in ans_list:
    print(a)


Measured memory_bytes: 9124
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    if(a > b) dunk(a+a-1);
    if(a == b) dunk(a+b);
    if(a < b) dunk(b+b-1);
}

Measured memory_bytes: 256
S=input()
T=input()
LS=len(S)
LT=len(T)
ans=0

for i in range(LS-LT+1):
    cnt=0
    kari=S[i:i+LT]
    for j in range(LT):
        if kari[j]==T[j]:
            cnt+=1
    #print(kari,cnt,ans)
    ans=max(cnt,ans)        

print(LT-ans)

Measured memory_bytes: 8952
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    A_ = sorted(A)
    cnt = 0
    for i in range(len(A)):
        a = A[i]
        a_ = A_[i]
        if a != a_:
            cnt += 1

    if cnt <= 2:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>

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

int tank1[55];
int tank2[55];
int solve(int n){
  int ret =0;
  rep(i,54){
    rep(j,96){
      int tmp = i*i*i+j*(j+1)*(j+2)/6;
      if ( tmp > n)continue;
      ret=max(ret,tmp);
    }
  }
  return ret;
}

main(){
  int n;
  while(cin>>n && n){
    cout << solve(n)<<endl;
  }
}

Measured memory_bytes: 868
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL V<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define MAX 1e18
#define MIN -1e18
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
map<LL,LL>u;
void Y()
{
    cout<<"Yes"<<endl;
}
void N()
{
    cout<<"No"<<endl;
}
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z=0,r;
    string a,b,c;
    DL x,y;
   cin>>x;
   cout<<fixed<<setprecision(2)<<2*PI*x<<endl;

    return 0;
}


Measured memory_bytes: 3832
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iomanip>
#include<iterator>
#include<map>
//#include<chrono>
//cout<<setprecision(12)
//fixed
//#include<random>
using namespace std;
typedef long long int llint;
typedef long double lldo;
const int big=1e8+100000;
const int mod=1e9+7;
const lldo eps=1e-9;
const long double pai=3.141592653589793238462643;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
#define dme(in) cout<<in<<endl;return 0
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int main(void){
	int i,j,k,n,m,r,ans=big;cin>>n>>m>>r;
	vector<int>to(r);
	for(i=0;i<r;i++){cin>>to[i];to[i]--;}
	sort(to.begin(),to.end());
	static int dp[200][200];
	for(i=0;i<200;i++){
		for(j=0;j<200;j++){
			dp[i][j]=big;
		}
	}
	for(i=0;i<m;i++){
		int a,b,c;cin>>a>>b>>c;a--;b--;
		dp[a][b]=c;
		dp[b][a]=c;
	}
	for(k=0;k<n;k++){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				mineq(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
	do{
		int gen=0;
		for(i=0;i<r-1;i++){gen+=dp[to[i]][to[i+1]];}
		mineq(ans,gen);
	}while(next_permutation(to.begin(),to.end()));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
n = int(input())
h = list(map(int, input().split()))

tmp = 0
ans = 0
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 0
ans = max(ans, tmp)

print(ans)

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

int main()
{
	int a,b,c,d,sum=0;
	string s;

	cin>>a>>b>>c;
    if(a==b && b==c)
        cout<<"Yes";
    else
    {
        cout<<"No";
    }
    
	
	return 0;
}
	

Measured memory_bytes: 256
MOD = 10**9 + 7

N, K = map(int, input().split())

inv2 = pow(2, MOD-2, MOD)
nums = []
for i in range(N+3):
    num = i*(i+1)%MOD*inv2%MOD
    nums.append(num)
nums.append(0)
#print('nums:', nums)

ans = 0
for i in range(K, N+2):
    mn = nums[i-1]
    mx = nums[N] - nums[N-i]
    ans += mx-mn+1
    ans %= MOD

print(ans)


Measured memory_bytes: 16924
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int sosu[10010];

int main() {
	sosu[0]=1;
	sosu[1]=1;
	int i,j;
	for(i=0;i<=10000;i++){
		if(sosu[i]==0){
			for(j=i*2;j<=10000;j+=i){
				sosu[j]=1;
			}
		}
	}
	int n;
	while(n=in()){
		while(sosu[n]+sosu[n-2]!=0){
			n--;
		}
		cout<<n-2<<" "<<n<<endl;
	}
	return 0;
}

Measured memory_bytes: 924
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());

        double[] p = new double[n];

        for (int i = 0; i < n; i++) {
            p[i] = Double.parseDouble(sc.next());
        }

        double[][] dp = new double[n + 1][n + 1];
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                dp[i][j] = 0;
            }
        }

        dp[0][0] = 1;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i + 1; j++) {
                dp[i + 1][j] += dp[i][j] * (1 - p[i]);
                dp[i + 1][j + 1] += dp[i][j] * p[i];
            }
        }

        double result = 0;
        for (int i = (n / 2) + 1; i <= n; i++) {
            result += dp[n][i];
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 134116
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

for line in stdin:
    date = tuple(int(s) for s in line.split())
    if date < (1868, 9, 8):
        print('pre-meiji')
    elif date < (1912, 7, 30):
        print('meiji', date[0] - 1867, date[1], date[2])
    elif date < (1926, 12, 25):
        print('taisho', date[0] - 1911, date[1], date[2])
    elif date < (1989, 1, 8):
        print('showa', date[0] - 1925, date[1], date[2])
    else:
        print('heisei', date[0] - 1988, date[1], date[2])

Measured memory_bytes: 4264
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 2000001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,
q,q1,q2,q3,q4,r,s,t,u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,cnt,lim;
L mark[Mx];
vector<L>prim;
void sieve(){
    prim.push_back(2);
    lim=sqrt(Mx);
    for(L i=3;i<Mx;i+=2){
        if(!mark[i]){
            prim.push_back(i);
            if(i<lim){
                for(L j=i*i;j<Mx;j+=(i*2)){
                    mark[j]=1;
                }
            }
        }
    }

    // for(L i=0;i<100;i++)printf("%lld ",prim[i]);printf("\n");
}
void operation(int idx){
    L loc=0;
    for(L i=1;;i++){
        loc+=i;
        if(loc<=idx)cnt++;
        else break;
    }
}
void primFact(){
    for(L i=0;prim[i]*prim[i]<n;i++){
        c=0;
        while(n%prim[i]==0){
            c++;
            n/=prim[i];
        }
        if(c){
            operation(c);
        }
    }
    if(n>=2)cnt++;
}
void solve(){
    cnt=0;
    primFact();
    printf("%lld\n",cnt );
}
int main()
{
    sieve();
    scanf("%lld",&n);
    solve();
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 20872
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long r, d, x;
    scan(r, d, x);
    foreach (_; 0 .. 10)
    {
        x = r * x - d;
        writeln(x);
    }
}


Measured memory_bytes: 256
b=list(map(int,input().split()))
LL=[]
for i in range(b[0]):
    LL.append(list(map(int,input().split())))
LL.sort()
x=0
z=0
y=b[1]
i=-1
while y>=0 and not LL==[]:
    i+=1
    if y<=LL[i][1]:
        print(x+LL[i][0]*y)
        break
    else:
        y-=LL[i][1]
        x+=LL[i][1]*LL[i][0]

Measured memory_bytes: 27760
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define xx first
#define yy second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(int i=k;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> iv;
typedef pair<int,int> iip;
typedef map<int,int> mii;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}
int main(){	
	ll a,b;
	cin>>a>>b;
	cout<<max((ll)0,a-b);
	return 0;
}

Measured memory_bytes: 256
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=2002;
bitset<maxn*maxn+10>s;
int main()
{
    int N,x,sum=0;
	scanf("%d",&N);
	s[0]=1;
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&x);
		s |= (s <<x );//背包记录所有出现情况
		sum += x;
	}
	for(int i=(sum+1)/2; ;i++)
	{
		if(s[i])//如果有这种情况 即可输出答案
		{
			printf("%d\n",i);
			break;
		}
	}
    return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>

long long ans;

int main(){
	int n;
	int i;
	ans = 1;
	scanf("%d",&n);
	for(i = 1; i <= n; i++){
		ans = ans * i;
		if(ans > 1000000007) ans = ans % 1000000007;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <iterator>
#include <limits>
#include <numeric>
#include <type_traits>
#include <cmath>
#include <cstdlib>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

#define ALL(v) (v).begin(), (v).end()
#define endl "\n"
typedef long long int ll;

template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (int i = 0; i<vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

int SumDigitValues(int x)
{
	int sum = 0;
	while (x)
	{
		sum += x % 10;
		x = x / 10;
	}

	return sum;
}

int Factorial(int n)
{
	if (n < 0) return 0;
	if (n == 0) return 1;
	return n * Factorial(n - 1);
}

int factorial(int n)
{
	if (n > 1)
	{
		return n * factorial(n - 1);
	}
	else
	{
		return 1;
	}
}

int gcd(int x, int y)
{
	if (y == 0)
		return x;
	else 
		return gcd(y, x % y);
}

vector<int> Divisors(int x)
{
	vector<int> divisors;
	divisors.push_back(1);
	for (int a = 2; a <= x; a++)
	{
		if (x % a == 0) divisors.push_back(a);
	}
	return divisors;
}

vector<int> CommonDivisors(int a, int b)
{
	vector<int> divisorsA = Divisors(a);
	vector<int> divisorsB = Divisors(b);
	vector<int> commonDivisors;
	set_intersection(divisorsA.begin(), divisorsA.end(), divisorsB.begin(), divisorsB.end(), std::back_inserter(commonDivisors));
	return commonDivisors;
}

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

	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i, n) cin >> h[i];

	int cnt = 0;
	rep(i, n) {
		if (h[i] >= k) cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int caseNo = 1;
        String msg = "";

        while (true) {
            int num = scanner.nextInt();
            
            if (num == 0) { break; }
            
            System.out.println( String.format("Case %1$s: %2$s", caseNo, num) );
            caseNo++;
        }

    }
}


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

long long attack(long long resthp) {
    if(resthp==1) {
      return 1;
    } else {
      return 2*attack(resthp/2)+1;
    }
}

int main() {
    long long hp;
    cin >> hp;
    cout << attack(hp) << endl;
    return 0;
}

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

int main(){
  char c;
  cin >> c;
  c++;
  cout << c << endl;
  return 0;
}

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

int main() {
    string s;
    cin >> s;
    string a = "abcdefghijklmnopqrstuvwxyz";
    int cnt[26];
    for (int i = 0; i < 26; i++) cnt[i] = 0; 

    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < s.size(); j++) {
            if (a[i] == s[j]) {
                cnt[i]++;
                break;
            }
        }
    }
    for (int i = 0; i < 26; i++) {
        if (cnt[i] == 0) {
            cout << a[i] << endl;
            return 0;
        }
    }
    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
<?php
  fscanf(STDIN, "%d %d", $n, $k);
  $a = explode(" ", trim(fgets(STDIN)));
  
  $visited = [];
  $history = [];
  $now = 1;
  $i = 0;
  for (; $i<$k; $i++) {
    if (isset($visited[$now])) break;
    $visited[$now] = $i;
    $history[] = $now;
    $now = $a[$now-1];
  }

  if (!isset($visited[$now])) {
    echo $now;
  } else {
    $index = ($k - $visited[$now]) % ($i - $visited[$now]);
    $index += $visited[$now];
	echo $history[$index];
  }
?>

Measured memory_bytes: 44160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

typedef long double ld;
const ld eps = 1.0e-14; // 許容される誤差

int main() {
  ld a,b,c;
  cin >> a >> b >> c;
  if (sqrt(a) + sqrt(b) + eps < sqrt(c)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=2e5+4;

int main()
{
	int n,x,y;

	scn(n); scn(x); scn(y);

	vector<int> fa(n+1,0);

	rep(i,1,n+1)
	{
		rep(j,i+1,n+1)
		{
			int dis=j-i;

			int other=abs(i-x)+abs(j-y)+1;

			fa[min(dis,other)]++;
		}
	}

	rep(i,1,n)
	priln(fa[i]);

    return 0;
}

Measured memory_bytes: 256
m, d = map(int, input().split())
count = 0
for i in range(1, m+1):
  for j in range(22, d+1):
    j = str(j)
    if i == (int(j[0]) * int(j[1])) and (int(j[1]) >= 2):
      count += 1
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

//constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/


int main() {
	int n, k; cin >> n >> k;
	ll sum1 = 0, sum2 = 0;

	for (int i = 1; i <= n; i++) {
		if (i % k == 0) {
			sum1++;
		}
		if (!(k & 1) && i % k == k / 2) {
			sum2++;
		}
	}

	cout << sum1 * sum1 * sum1 + sum2 * sum2 * sum2 << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int w;
  cin >> w;
  char pattern[3] = {'-', '0', '+'};
  vector<char> result;
  while (w > 0) {
    w += 1;
    result.push_back(pattern[w % 3]);
    w /= 3;
  }
  int i;
  for (i = result.size() - 1; i >= 0; i--) {
    cout << result[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3112
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
#define min(a, b, c) min(a, min(b, c))
#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll ans=0;
    map<pll,ll> mp;
    vector<pll> e;
int parent[2*100000];
    vll v[2*100000+3];
void bfs(int u)
{
    queue<ll> q;
    q.push(1);
    while(!q.empty())
    {
        int f=q.front();
        q.pop();
        int count=1;
        for(auto x:v[f])
        {
            parent[x]=f;
            if(x==parent[f])
            continue;
            if(count==mp[{parent[f],f}])
            count++;
            mp[{x,f}]=mp[{f,x}]=count++;
            if(x!=parent[f])
            q.push(x);
        }
    }
}
ll n,m,a,b,temp;
string str;
set<ll> s;
//vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	parent[1]=-1;
	mp[{1,-1}]=mp[{-1,1}]=0;
	cin>>n;
    //deb(n);
    n--;
    while(n--)
    {
        cin>>a>>b;
        e.pb({a,b});
        v[a].pb(b);
        v[b].pb(a);
        ans=max((long unsigned int )ans,v[b].size(),v[a].size());
    }
    bfs(1);
    cout<<ans;
    nl;
    for(int i=0;i<e.size();i++)
    {
        cout<<mp[e[i]];
        nl;
    }
}

Measured memory_bytes: 23408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
   
   int K,X;
   
   scanf("%d%d",&K,&X);
  
   int i;
   int start;
   int end;
   
   if (X - K + 1 < -1000000) {
      start = -1000000;
   }
   else {
      start = X - K + 1;
   }
   
   if (K + X - 1 > 1000000) {
      end = 1000000;
   }
   else {
      end = K + X - 1;
   }
   
   for (i = start; i <= end; i++) {
      printf("%d ",i);
   }
   printf("\n");
   
   return 0;
}


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

int main() {
    string s;
    cin >> s;
    if ( s[0] == 'S' ) {
        cout << "Cloudy";
    } else if ( s[0] == 'C' ) {
        cout << "Rainy";
    } else {
        cout << "Sunny";
    }
    cout << endl;
    return 0;
}

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

int N;
int arr[20];


int main(){
  //inputs
  cin >> N;
  for (int i=0;i<N;i++){
    cin >> arr[i];
  }
  
  int count=0;
  for (int i=1;i<N-1;i++){
    int temp[3] = {arr[i-1],arr[i],arr[i+1]};
    sort(temp,temp+3);
    if (temp[1] == arr[i]){
      count += 1;
    }
  }
  cout << count;
  return 0;
}
  

Measured memory_bytes: 256
//
//  main.c
//  Yamanotesen
//
//  Created by x15071xx on 2016/06/18.
//  Copyright ?? 2016??´ AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    
    int time = 0,count=0,b=0,a,c,out_time=0,i,j;
    scanf("%d %d %d",&a,&b,&c);
    
    int first_ab = -1;
    int first_num = -1;
    while(1){

        if(time >= 60){
            time -= 60;
            
            
            if (count == 0) {
                first_ab = 1; //b
                first_num = time;
            }
            
            count++;
            
            if (first_ab == 1 && first_num == time && count >= 2) {
                printf("-1\n");
                return 0;
            }
        }
        
        for(i=0;i<a;i++){
            time++;
            if(time == c){
                //????????????
                out_time = time + (count * 60);
                printf("%d\n",out_time);
                return 0;
            }
        }
        //printf("%d\n",time);
        if(time >= 60){
            
            
            
            time -= 60;
            if (count == 0) {
                first_ab = 0;//a
                first_num = time;
            }
            count++;
            
            if (first_ab == 2 && first_num == time && count >= 2) {
                printf("-1\n");
                return 0;
            }
        }
        
            //????????????
        for(i=0;i<b;i++){
            time++;
        }
        //printf("%d\n",time);
    }
    
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll X, A;
    cin >> X >> A;
    if (X < A) cout << 0 << "\n";
    else cout << 10 << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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; }
const int INF = 1<<30;
const int mod = 1000000007;

int main(){
	string s;
	int w;
	cin >> s >> w;
	for (int i = 0; i < (s.size()-1)/w + 1; i++) {
		cout << s[i*w];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    using snack = tuple<int, int, int, int>;
    vector<snack> v;
    rep(i, n) {
      int s, p, q, r;
      cin >> s >> p >> q >> r;
      v.emplace_back(s, p, q, r);
    }
    int P, Q, R, C;
    cin >> P >> Q >> R >> C;
    vi g;
    for (auto &x : v) {
      int s, p, q, r;
      tie(s, p, q, r) = x;
      if (p <= P && q <= Q && r <= R && p * 4 + q * 9 + r * 4 <= C) g.pb(s);
    }
    if (g.size()) {
      for (auto &x : g) cout << x << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 100016

int id[N], rnk[N];

int fin(int x) { return id[x] == x ? x : id[x] = fin(id[x]); }

int uni(int x, int y)
{
    x = fin(x);
    y = fin(y);
    retif(x == y) 0;
    if (rnk[x] < rnk[y]) swap(x, y);
    id[y] = x;
    rnk[x] = max(rnk[x], rnk[y]+1);
    return 1;
}

int main()
{
    canhazfast();

    int n, m, ans;

    cin >> n >> m;
    ans = n;
    iota(id+1, id+1+n, 1);
    for (int i = 0; i < m; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        ans -= uni(x, y);
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
const long long inf = 1000000000001;
int m,n;
long long vt=0,f[100101],v[1001],w[1001];

long long min(long long a , long long b){
	return a>b?b:a;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&w[i],&v[i]);
		vt+=v[i];
	}
	for(int i=1;i<=vt;i++) f[i]=inf;
	for(int i=1;i<=n;i++)
		for(int j=vt;j>=1;j--){
		if(j<=v[i]) {
			f[j]=min(f[j],w[i]);
		}
		else f[j]=min(f[j],f[j-v[i]]+w[i]);
	}
	//for(int i=1;i<=vt;i++) printf("%d ",f[i]);
	//printf("\n");
	for(int i=vt;i>=0;i--)
	{
		if(f[i]<=m) {
		printf("%d",i);	
		return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

//#define DEBUG


int main(void)
{
  string S;
  cin >> S;
  if( S[0]==S[1] && S[1]==S[2])
  {
    cout << "No";
  }
  else
  {
    cout << "Yes";
  }
  
  return 0;
} 

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    s=SI()
    n=len(s)
    n2=n//2
    ans=n2*(n2+1)+n%2*(n2+1)
    #print(ans)
    rem=0
    for i,c in enumerate(s):
        if c=="1":continue
        ans-=(rem+1)//2
        if rem%2==0 and i%2==0:ans-=1
        if (i-rem)%2==0:rem+=1
    print(ans)

main()

Measured memory_bytes: 9408
#include <iostream>

using namespace std;

const int MAX_N = 20;

int main () {
    int n;
    int A[MAX_N], B[MAX_N], C[MAX_N];

    cin >> n;

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

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

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

    int ans = 0;
    int index;
    int before = -100;

    for (int i = 0; i < n; i++) {
        index = A[i] - 1;
        ans += B[index];
        if (index == before + 1) {
            ans += C[before];
        }
        before = index;
    }

    cout << ans << endl;
}


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

// calculate |gcd|.
// if  ether num is 0, return 0
long long GCD(long long left, long long right) {
  if(left == 0 || right == 0) return 0;
  if(left < 0) left *= -1;
  if(right < 0) right *= -1;
  if(left < right) swap(left, right);
  long long nextnum, ansgcd = -1;
  while(ansgcd == -1) {
    nextnum = left % right;
    if(nextnum == 0) ansgcd = right;
    left = right;
    right = nextnum;
  }
  return ansgcd;
}

long long LCM(long long left, long long right) {
  return left / GCD(left, right) * right;
}

long long a, b, c, d, t;

bool solve();

int main() {
  cin >> t;
  for(int i = 0; i < t; ++i) {
    cin >> a >> b >> c >> d;
    if(solve())
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

bool solve() {
  if(a < b) return 0;
  if(d < b) return 0;
  if(c < b) {
    a %= b;
    long long g = GCD(b, d);
    if(b - g + a % g > c) return 0;
  }
  return 1;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
const int N = 20;

// next_combination version
// given an integer cur, next_combination returns an integer nxt s.t.
//   nxt has the same number of 1s as cur
//   nxt is bigger than cur
//   no integer between cur and nxt has the same number of 1s as cur (and nxt)
int next_combination(int cur)
{
  int r1 = cur & -cur;   // extracts the rightmost 1
  int moved1 = cur + r1; // cancel the rightmost run of 1s and put 1 on its left
  int rm1s = cur & ~moved1; // extracts the rightmost run of 1s
  int reset = (rm1s / r1) >> 1; // the run of 1s moved to LSD and made its length decreased by 1
  int nxt = moved1 | reset; // new combination
  return nxt;
}
int main(int argc, char *argv[])
{
  for(;;) {
    int n, k, s;
    cin >> n >> k >> s;
    if(n == 0 && k == 0 && s == 0) break;
    int cnt = 0;
    if(k <= n) {
      const int fin = ((1<<k) - 1) << (n-k);
      for(int i = (1<<k) - 1; i <= fin; i = next_combination(i)) {
        int ss = 0;
        for(int j = 1, x = 1; j <= i; j<<=1, x++) {
          if(i & j) { ss+=x; }
        }
        if(s == ss) cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}



Measured memory_bytes: 3100