akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <chrono>
#include <iostream>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef int Int;

#define KIND 26
//#define KIND 2
Int D;
Int c[KIND];
Int s[400][KIND];
Int last[KIND];

std::chrono::time_point<std::chrono::steady_clock> start;

random_device rd;
mt19937 generator(rd());
uniform_real_distribution<> dist_real(0.0, 1.0);
uniform_int_distribution<> dist_int(0, RAND_MAX);

Int range(Int l, Int r) {
	Int len = r - l - 1;
	return -len * (len + 1) / 2;
}

void tic() {
	start = std::chrono::steady_clock::now();
}

double toc() {
	auto now = std::chrono::steady_clock::now();
	std::chrono::duration<double> duration = now - start;
	return duration.count();
}

struct ContestInfo {
	set<Int> held[KIND];
	vector<Int> t;
	int D;
	Int score = 0;
	ContestInfo(int D) : D(D) {
		t.resize(D, -1);
		for (int i = 0; i < KIND; i++) {
			held[i].insert(-1);
			held[i].insert(D);
			score += c[i] * range(-1, D);
		}
	}

	void add(int d, int q) {
		if (t[d] != -1) {
			cout << "Add failed" << endl;
			exit(1);
		}
		t[d] = q;
		score += s[d][q];
		held[q].insert(d);
		auto it = held[q].find(d);
		auto rit = next(it);
		auto lit = prev(it);
		score -= c[q] * range(*lit, *rit);
		score += c[q] * range(*it, *rit);
		score += c[q] * range(*lit, *it);
	}

	void erase(int d) {
		if (t[d] == -1) {
			cout << "erase failed" << endl;
			exit(1);
		}
		int q = t[d];
		t[d] = -1;
		score -= s[d][q];
		auto it = held[q].find(d);
		auto rit = next(it);
		auto lit = prev(it);
		score += c[q] * range(*lit, *rit);
		score -= c[q] * range(*it, *rit);
		score -= c[q] * range(*lit, *it);
		held[q].erase(it);
	}

	void change(int d, int q) {
		erase(d);
		add(d, q);
	}

	void output() {
		for (int i = 0; i < D; i++) {
			cout << t[i] + 1 << endl;
		}
	}
};

int main() {
	tic();
	cin >> D;
	for (Int i = 0; i < KIND; i++) {
		cin >> c[i];
	}
	for (Int d = 0; d < D; d++) {
		for (Int i = 0; i < KIND; i++) {
			cin >> s[d][i];
		}
	}

	ContestInfo ci(D);

	for (int d = 0; d < D; d++) {
		Int t;
		t = dist_int(generator) % KIND;
		ci.add(d, t);
	}
	Int current_score = ci.score;

	while (toc() < 1.9) {
		Int d, q;
		d = dist_int(generator) % D;
		q = dist_int(generator) % KIND;
		int old = ci.t[d];
		ci.change(d, q);
		Int new_score = ci.score;
		if (new_score < current_score) {
			ci.change(d, old);
		} else {
			current_score = new_score;
		}
	}
	ci.output();
	return 0;
}


Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(40) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,n,a) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e9)
#pragma endregion


int main() {
	int road[51];
	rep(i, 51) road[i] = 0;
	int n, m;
	put n >> m;
	rep(i, m) {
		int a, b;
		put a >> b;
		road[a - 1]++;
		road[b - 1]++;
	}
	rep(i, n) {
		putans(road[i]);
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 2019;
int main()
{
  ll l,r;
  ll ans=2019;

  cin>>l>>r; 
  for(ll i=l;i<=r;i++){
    for(ll j=i+1;j<=r;j++){
      ans=min(ans,i*j%MOD);
      if(ans==0) break;
    }
    if(ans==0) break;
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e16
using namespace std;
typedef long long ll;
int main() {
    int N, M;
    cin >> N >> M;

    int a[2000], b[2000];
    ll c[2000];

    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        c[i] = -c[i];
    }

    ll dist[1000];
    fill(dist, dist + 1000, INF);

    dist[0] = 0;

    for (int loop = 0; loop < N - 1; loop++) {
        for (int i = 0; i < M; i++) {
            if (dist[a[i]] == INF) continue;
            dist[b[i]] = min(dist[b[i]], dist[a[i]]+ c[i]);
        }
    }

    ll ans = dist[N - 1];

    bool negative[1000] = {false};

    for (int loop = 0; loop < N; loop++) {
        for (int i = 0; i < M; i++) {
            if (dist[a[i]] == INF) continue;
            if (dist[b[i]] > dist[a[i]] + c[i]) {
                dist[b[i]] = dist[a[i]] + c[i];
                negative[b[i]] = true;
            }

            if (negative[a[i]] == true) {
                negative[b[i]] = true;
            }
        }
    }

    if (negative[N - 1]) {
        cout << "inf" << endl;
    } else {
        cout << -ans << endl;
    }
}

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

int main() {
    string s;
    cin >> s;
    while(true){
        s.pop_back();
        if(s.size()%2 == 0){
        if(s.substr(0, s.size()/2) == s.substr(s.size()/2, s.size()/2)){
            cout << s.size() << endl;
            return 0;
        }
        }
    }
}

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

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

ll N,L;
ll A[100000];

int main(){
    cin >> N >> L;
    for(int i=0;i<N;i++) cin >> A[i];
    ll ind = -1;
    for(int i=0;i<N-1;i++){
        if(A[i] + A[i+1] >= L) ind = i+1;
    }
    if(ind < 0){
        cout << "Impossible" << endl;
    }else{
        cout << "Possible" << endl;
        for(int i=1;i<ind;i++){
            cout << i << endl;
        }
        for(int i=N-1;i>=ind;i--){
            cout << i << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int MOD=1e9+7;

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

    ll n,d,x;
    cin >>n>>d>>x;
    ll ans=x;
    for(int i=1;i<=n;i++){
        ll a;
        cin >> a;
        ans+=(d-1)/a+1;
    }
    cout << ans <<endl;

    return 0;
}


Measured memory_bytes: 256
L, R = map(int, input().split())
MOD = 2019

if R - L >= 2019:
    print(0)
    exit()
ans = (L * (L + 1)) % MOD
for i in range(L, R):
    for j in range(i + 1, R + 1):
        ans = min(ans, (i * j) % MOD)

print(ans)


Measured memory_bytes: 44652
num = int(input())
nums = [int(i) for i in input().split()]
if num < 3:
    print(0)
    exit()
ans = 0
for i in range(0, num-2):
    for j in range(i+1, num-1):
        for k in range(j+1, num):
            t = [nums[i], nums[j], nums[k]]
            temp = sum(t)
            if (temp - max(t)) > max(t) and len(set(t)) == 3:
                # print(t)
                ans += 1
print(ans)

Measured memory_bytes: 9212
INF = 100000

loop{
	
	n,m,p,a,b = gets.split.map(&:to_i)
	if n == 0 and m == 0 and p == 0 and a == 0 and b == 0 then
		break
	end
	mat = Array.new(m).map{Array.new(m,INF)}
	carr = Array.new(m,INF)
	arr = gets.split.map(&:to_f)
	arr.sort!
	arr.reverse!
	p.times{|i|
		x,y,z = gets.split.map(&:to_f)
		mat[y-1][x-1] = z
		mat[x-1][y-1] = z
	}
	
	now = a - 1
	stack = [[now,0,[]]]
	
	while (!stack.empty?) do
		pos,cost,root = stack.pop()
		mat[pos].each_with_index{|toc,i|
			if toc == INF then
				next
			end
			nroot = root +[toc]
			if nroot.size() > n then
				next
			end 
			ncost = 0
			nroot.sort!
			nroot.reverse!
			nroot.each_with_index{|r,ind|
				ncost += (r / arr[ind])
			}
			
			if (ncost < carr[i]) then
				carr [i] = ncost
				stack.push([i,ncost,nroot])
			end
			
		}
	end
	if carr[b-1] >=INF then
		print "Impossible\n"
	else 
		p carr[b-1]
	end
}

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

int main()
{
    int n;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++) cin >> h[i];
    int total=1,o=h[0];
    for(int i=1;i<n;i++)
    {
        if(h[i]>=o)
        {
            o=h[i];
            total++;
        }
    }
    cout << total;
    return 0;
}

Measured memory_bytes: 256
def valid?(i)
  quotient_100 = i / 100
  remainder_100 = i % 100
  return 0 if quotient_100 < 1
  return 1 if remainder_100.zero?
  quotient_5 = remainder_100 / 5
  remainder_5 = remainder_100 % 5
  return 0 if quotient_5 > quotient_100
  return 1 if remainder_5.zero?
  quotient_4 = remainder_5 / 4
  remainder_4 = remainder_5 % 4
  return 0 if quotient_5 + quotient_4 > quotient_100
  return 1 if remainder_4.zero?
  quotient_3 = remainder_4 / 3
  remainder_3 = remainder_4 % 3
  return 0 if quotient_5 + quotient_4 + quotient_3 > quotient_100
  return 1 if remainder_3.zero?
  quotient_2 = remainder_3 / 2
  remainder_2 = remainder_3 % 2
  return 0 if quotient_5 + quotient_4 + quotient_3 + quotient_2 > quotient_100
  return 1 if remainder_2.zero?
  quotient_1 = remainder_2 / 1
  remainder_1 = remainder_2 % 1
  return 0 if quotient_5 + quotient_4 + quotient_3 + quotient_2 + quotient_1 > quotient_100
  return 1 if remainder_1.zero?
  0
end
p valid?(gets.to_i)

Measured memory_bytes: 14348
#include<cstdio>
const int N=105;
int h,w,n,a[N*N],pos,now,ans[N][N];
int main(){
//	freopen("ex.in","r",stdin);
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	pos=1;now=0;
	for(int i=1;i<=h;++i){
		if(now==0) for(int j=1;j<=w;++j){
			while(a[pos]==0) pos++;
			a[pos]--;
			ans[i][j]=pos;
		}
		else for(int j=w;j;--j){
			while(a[pos]==0) pos++;
			a[pos]--;
			ans[i][j]=pos;
		}
		now^=1;
	}
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j) printf("%d ",ans[i][j]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
from collections import deque
from itertools import accumulate
import sys
sys.setrecursionlimit(10**6)

mo=10**9+7
#n=int(input())
l,r=map(int,input().split())
r=min(l+2019+10,r)

ans=2018
for i in range(l,r):
    for j in range(l+1,r+1):
        ans=min(ans,(i*j)%2019)
        #print(i,j,(i*j)%2019,ans)


print(ans)



Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

#define SIZE 2000
#define MAX_P 1000010

int n, m;
int cave[SIZE][SIZE];
P dp[SIZE][SIZE];
bool is_prime[MAX_P], vis[SIZE][SIZE];

void sieve()
{
    for (int i = 2; i < MAX_P; i++)
        is_prime[i] = true;
    for (int i = 2; i < MAX_P; i++)
    {
        if (!is_prime[i])
            continue;
        for (int j = 2 * i; j < MAX_P; j += i)
            is_prime[j] = false;
    }
}
void make_cave()
{
    int y = 1000, x = 1000, num = 1;
    cave[y][x] = num;
    for (int b = 1; num <= MAX_P; b++)
    {
        if (b % 2)
        {
            rep(i, b) cave[y][++x] = ++num;
            rep(i, b) cave[--y][x] = ++num;
        }
        else
        {
            rep(i, b) cave[y][--x] = ++num;
            rep(i, b) cave[++y][x] = ++num;
        }
    }
}
P solve(int y, int x)
{
    if (vis[y][x])
        return dp[y][x];
    vis[y][x] = true;
    if (cave[y][x] == 0 || cave[y][x] > n)
        return dp[y][x] = P(0, 0);
    P res = max(solve(y + 1, x - 1), max(solve(y + 1, x), solve(y + 1, x + 1)));
    if (is_prime[cave[y][x]])
    {
        res.first++;
        if (res.second == 0)
            res.second = cave[y][x];
    }
    return dp[y][x] = res;
}

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

    sieve();
    make_cave();
    while (cin >> n >> m, n)
    {
        rep(i, SIZE) rep(j, SIZE) vis[i][j] = false;
        int x, y;
        rep(i, SIZE) rep(j, SIZE) if (cave[i][j] == m) y = i, x = j;
        P ans = solve(y, x);
        cout << ans.first << " " << ans.second << endl;
    }
}


Measured memory_bytes: 33552
#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<int> a(n);
  rep(i, n) cin >> a.at(i);

  // 各iについての最大値を(i+1)、2つめの添え字は反転している場合は0、選んでたら1
  ll dp[(n + 1)][2];
  dp[0][0] = 0;
  dp[0][1] = INT_MIN;
  for (int i = 0; i < n; i++) {
    dp[i + 1][0] = max({dp[i][0] + a.at(i), dp[i][1] - a.at(i)});
    dp[i + 1][1] = max({dp[i][0] - a.at(i), dp[i][1] + a.at(i)});
  }
  cout << dp[n][0] << endl;
  return 0;
}


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

static const ll mod = 1e9+7;


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    string S[2];
    rep(i, 2) cin >> S[i];

    ll res = 1;
    int x = 0;
    int pre = -1;

    while(x < n) {
        if (S[0][x] == S[1][x]) {
            if (pre < 0) res = 3;
            else if (pre == 0) res *= 2;
            else res *= 1;
            ++x;
            pre = 0;
        }
        else {
            if (pre < 0) res = 6;
            else if (pre == 0) res *= 2;
            else res *= 3;
            x += 2;
            pre = 1;
        }
        res %= mod;
    }

    cout << res << endl;

    return 0;
}

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

typedef long long ll;

ll n, cnt = 0;

ll dfs(ll now, ll sev, ll fiv, ll thr) {
	if (now > n)return 0;

	if (sev >= 1 && fiv >= 1 && thr >= 1)cnt++;

	dfs(now * 10 + 7, sev + 1, fiv, thr);
	dfs(now * 10 + 5, sev, fiv + 1, thr);
	dfs(now * 10 + 3, sev, fiv, thr + 1);
}

int main() {
	cin >> n;
	dfs(0, 0, 0, 0);
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    int n;
    cin >> n;
    n--;
    if(n == 1){
        int k;
        cin >> k;
        cout << 2*k << endl;
        return 0;
    }
    int ans = 0;
    int b[n];
    rep(i,n){
        cin >> b[i];
    }
    rep(i,n-1){
        ans += min(b[i], b[i+1]);
    }
    ans += b[0] + b[n-1];
    cout << ans << endl;
}
/*

本質：頭と尾の和と、隣り合う二項のminの総和の和が答えっぽい

*/

Measured memory_bytes: 3612
from collections import deque
import sys

h, w = map(int, input().split())
grid = [list(map(str, input().rstrip())) for _ in range(h)]

kuro = 0
for g in grid:
    kuro += g.count("#")

q = deque([[0, 0]])
grid[0][0] = 1
moves = [[1, 0], [-1, 0], [0, 1], [0, -1]]

while q:
    cx, cy = q.popleft()
    for m in moves:
        nx, ny = cx + m[0], cy + m[1]
        if nx < 0 or nx > h - 1 or ny < 0 or ny > w - 1:
            continue
        elif grid[nx][ny] == "#":
            continue
        elif grid[nx][ny] == ".":
            grid[nx][ny] = grid[cx][cy] + 1
            q.append([nx, ny])
            if nx == h - 1 and ny == w - 1:
                print(h * w - grid[nx][ny] - kuro)
                sys.exit()
else:
    print(-1)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N; cin>>N;
    char S[N];
    int ans;ans=0;
    for(int i=0;i<N;i++){
        cin>>S[i];
        if(S[i]=='Y'){
            cout<<"Four";
            return 0;
        }
    }
    cout<<"Three";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using lint=int64_t;
using namespace std;

int main()
{
	int N,M;
	map<int,int> m;
	
	cin >> N >> M;
	for(int i=0;i<N;i++)
	{
		int K;
		cin >> K;
		for(int j=0;j<K;j++)
		{
			int A;
			cin >> A;
			m[A]++;
		}
	}
	
	int ans=0;
	for(auto&& i:m)
	{
		if(i.second==N)
			ans++;
	}
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int X,Y,Z;cin >> X >> Y >> Z;
  X-=Z;
  Y+=Z;
  cout << X/Y << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int A[202020],n,x;
int main(){
	scanf("%d %d",&n,&x);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	sort(A+1,A+n+1);
	int ans=n;
	for (int i=1;i<=n;i++){
		if (A[i]>x){
			ans=i-1; break;
		}
		x-=A[i];
	}
	if (x&&ans==n) ans--;
	cout<<ans;
}

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

#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)

int Q, A, B, C, D;

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

    cin >> Q;
    FOR(i,1,Q) {
        cin >> A >> B >> C >> D;

        int K = (max(A,B)+min(A,B))/(min(A,B)+1);
        int lo = 0, hi = A+B+1;
        while (hi-lo > 1) {
            int mid = (lo+hi)/2;

            int nb = (mid-1)/(K+1);
            int na = (mid-1) - nb;
            if (1LL*K*(A-na) >= B-nb) lo = mid;
            else hi = mid;
        }

        //cout << "q " << i << " :: " << K << " partition at " << lo << " " << hi << endl;
        FOR(i,C,D){
            if (i <= lo) {
                cout << (i%(K+1) == 0 ? 'B' : 'A');
            } else {
                cout << ((A+B-i+1)%(K+1) == 0 ? 'A' : 'B');
            }
        }
        cout << '\n';
    }
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll a = 0, b = 0;
    cin >> a >> b;
    ll ans = 0;
    if(b <= a) {
        if(b == 1) {
            ans = 0;
        }
        else {
            ans = 1;
        }
    } 
    else {
            b -= a;
            ans++;
            ans += ((a - 1) + b - 1)/(a - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

maxval = a[0]
cc = {maxval: 1}

ans = 0
idx = 0

for i in range(1, n):
    if a[i] in cc:
        cc[a[i]] += 2
    else:
        cc[a[i]] = 2
    cc[maxval] -= 1
    ans += maxval
    if cc[maxval] == 0:
        while 1:
            idx += 1
            if maxval > a[idx]:
                maxval = a[idx]
                break

print(ans)


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

int main()
{
    // 入力
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++) cin >> L[i];
    // ソート
    sort(L.begin(), L.end());
    // 組み合わせをカウント
    int cnt = 0;
    // 二つの棒をfor文二重で回す
    for(int a = 0; a < N; a++)
    {
        for(int b = 0; b < a; b++)
        {
            // 二つの棒の長さの和
            int ab = L[a] + L[b];
            // 二分探索で条件を満たす三本目のグループの右端を見つける
            int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
            // 左端
            int l = a+1;
            // カウント
            cnt += max(0, r-l);
        }
    }
    // 解を出力
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int min(int n1,int n2)
{
	if(n1>n2)
		return n2;
	else
		return n1;
}
long int reach(int i,int a[],int memo[],int k)
{
	if(i<2)
		return 1000000000;
	if(i==2)
		return 0;
	if(memo[i]!=-1)
		return memo[i];
	else
	{
		long int q=1000000000,j,m;
		if(k+2<=i)
			m=k;
		else
			m=i-2;
		for(j=1;j<=m;j++)
		q=min(q,fabs(a[i]-a[i-j])+reach(i-j,a,memo,k));
		memo[i]=q;
		return memo[i];
	}
}
int main()
{
      int a[1000009],memo[1000009],n,k;
      scanf("%d %d",&n,&k);
      for(int i=2;i<=n+1;i++)
      {
      scanf("%d",&a[i]);
      memo[i]=-1;
      }
      printf("%ld\n",reach(n+1,a,memo,k));
		      return 0;
		      }


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

const long long BIGINF = 2e18 + 7;
const int INF = 2e9 + 7;


int main () {
	/*#ifndef ONLINE_JUDGE
		freopen("inputf.txt", "r", stdin);
		freopen("outputf.txt", "w", stdout);
	#endif*/
	int n, k;
	SCD(n);
	SCD(k);
	int x;
	vector<int> a;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		SCD(x);
		a.push_back(x);
		ans += x;
	}
	sort(a.rbegin(), a.rend());
	int i = 0;
	while (i < k && i < n) {
		ans -= a[i++];
	}
	
	printf("%lld", ans);


    return 0;
}



Measured memory_bytes: 1400
import bisect
n = int(input())
a = [int(input()) for i in range(n)]
ans = 0
color = [a[n-1]]
for i in range(n-2,-1,-1):
    if a[i]>=color[-1]:
        color.append(a[i])
    else:
        x = bisect.bisect_right(color,a[i])
        color[x] = a[i]
print(len(color))

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll ds(ll x) {
	ll res = 0;
	while (x) res += x%10, x /= 10;
	return res;
}

struct seq {
	ll root = 0, cnt = -1;

	seq operator*(seq s) {
		seq res;
		res.cnt = 1 + cnt + s.cnt;
		ll x = root + s.root;
		while (x >= 10) x = ds(x), res.cnt++;
		res.root = x;
		return res;
	}
};

seq power(seq a, ll n) {
	seq res;
	while (n) {
		if (n&1) res = res*a;
		a = a*a;
		n /= 2;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	
	seq res; 

	while (n--) {
		ll d, k;
		cin >> d >> k;
		res = res * power({d,0},k);
	}
	cout << res.cnt << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define N 1000005

using namespace std;

void solve()
{
	ll n;
	cin >> n;
	ll a[n];
	ll pre[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	for (ll i = n - 1; i >= 0; --i)
	{
		if (i == n - 1)pre[i] = a[i];
		else pre[i] = (a[i] + pre[i + 1]) % M;
	}
	ll ans = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		ans = (ans + (a[i] * pre[i + 1]) % M) % M;
	}
	cout << ans << endl;
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin >> T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

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

int main() { 
  int N, M;
  cin >> N >> M;
  vector<int64_t> a(0);
  for (int i = 0; i < N; i++) {
    int64_t A;
    cin >> A;
    a.push_back(A);
  }
  vector<pair<int64_t, int64_t>> b(M);
  for (int i = 0; i < M; i++) {
    cin >> b.at(i).second >> b.at(i).first;
  }
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < b.at(i).second; j++) {
      a.push_back(b.at(i).first);
      if (a.size() >= 2*N) {
        break;
      }
    }
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int64_t ans = 0;
  for (int i = 0; i < N; i++) {
    ans += a.at(i);
  }
  cout << ans << endl;
}

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

int main()
{
    double sum = 0;
    int n, k;
    cin >> n >> k;
    double ara[n];

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

        sum += (int) ara[i];
    }

    double val = (double) sum/(4*k);

    for(int i = 0; i < n; i++)
    {
        if(ara[i] >= val)
            k--;

        if(!k)
            break;
    }

    if(k)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
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;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	cout<<0<<endl;
	string l,r;
	cin>>l;
	if(l=="Vacant"){
		return 0;
	}
	cout<<n/2<<endl;
	cin>>r;
	if(r=="Vacant"){
		return 0;
	}
//	if(n==3){
//		cout<<2<<endl;
//		return 0;
//	}
	int L,R;
	if(l==r&&(n/2-1)%2||l!=r&&(n/2-1)%2==0){
		L=n/2,R=n;
		swap(l,r);
	}else{
		L=0,R=n/2;
	}
	while(1){
		string s;
		int h=(L+R)/2;
		cout<<h<<endl;
		cin>>s;
		if(s=="Vacant"){
			return 0;
		}
		if(s==l&&(h-L-1)%2||s!=l&&(h-L-1)%2==0){
			l=s;
			L=h;
		}else{
			r=s;
			R=h;
		}
	}
}










Measured memory_bytes: 852
import java.io.*;
import java.util.*;

public class Main {

	static long m = (long) (1e9 + 7);

	public static void main(String[] args) throws IOException {
		Scanner scn = new Scanner(System.in);
//		StringBuilder sb = new StringBuilder();
//		int T = scn.nextInt(), tcs = 0;
//		A: while (tcs++ < T) {
//			int n = scn.nextInt();
//
//		}
//		System.out.println(sb);
		int a = scn.nextInt(), b = scn.nextInt(), c = scn.nextInt(), k = scn.nextInt();
		int s = 0;
		if (k > 0) {
			s += Math.min(a, k);
			k -= Math.min(a, k);
		}
		if (k > 0) {
			k -= Math.min(b, k);
		}
		if (k > 0) {
			s -= Math.min(c, k);
			k -= Math.min(c, k);
		}
		System.out.println(s);
	}

	static class Scanner {

		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 32648
#include<iostream>
using namespace std;
int main () {
  int n;
  int a[1001];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    if(a[i] % 2 == 0){
     if(a[i] % 3 != 0 && a[i] % 5 != 0){
       cout << "DENIED" << endl;
       return 0;
     }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

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

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

	int h, w, a, b;
	cin >> h >> w >> a >> b;

	vector<vector<int>> v(h, vector<int>(w));
	
	for(int i = 0; i < b; i++) {
		for(int j = 0; j < a; j++) {
			v[i][j] = 1;
		}
	}

	for(int i = b; i < h; i++) {
		for(int j = a; j < w; j++) {
			v[i][j] = 1;
		}
	}

	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cout << v[i][j];
		}
		cout << '\n';
	}

	return 0;
}

Measured memory_bytes: 5248
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<time.h>
using namespace std;
#define int long long
#define inf 1e9+7
typedef pair<int, int> P;

int a[114514], b[114514];

signed main() {
	int n, y;
	cin >> n >> y;

	for (int i = 0; i <= n; i++) {//10k
		for (int j = 0; j <= n; j++) {//5k
			if (i + j > n)continue;
			int k = n - i - j;
			if (i * 10000 + j * 5000 + k * 1000 == y) {
				cout << i << ' ' << j << ' ' << k << endl;
				return 0;
			}
		}
	}
	puts("-1 -1 -1");
}

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


#if 1

typedef long long ll;

//vに素因数分解した要素突っ込む
void Prime_factorize(vector<int>& v,int n){
  if(n<=1) return;
  int l=int(sqrt(n));
  for(int i=2;i<l+1;i++){
    if(n%i==0){
      Prime_factorize(v,i);Prime_factorize(v,int(n/i));return;
    }
  }
  v.push_back(n);return;
}

void erase_same(vector<int>& v){
  sort(v.begin(),v.end());
  //隣接している重複した要素を除いた要素を先頭に集めるのが、unique関数
  //集めた後の返り値は重複を除いた範囲の末尾の次のイテレータになる(つまり、このイテレータ以降の要素はゴミ)
  v.erase(unique(v.begin(),v.end()),v.end());
}

int euler_phifunc(int n){
  vector<int> v;
  Prime_factorize(v,n);
  erase_same(v);
  int l=v.size();
  ll ans=n;
  for(int i=0;i<l;i++){
    ans=ans-int(ans/v[i]);
  }
  return ans;
}


#endif



int main(){
  int n;cin >> n;
  cout << euler_phifunc(n) << endl;
}



Measured memory_bytes: 3160
#include <iostream>
#include <cmath>
#define int long long
signed main(){
  int towns,routes,fuel,Q,ans;
  int a,b,length;
  std::cin>>towns>>routes>>fuel;
  int way[towns][towns],fueldist[towns][towns];
  for (int i=0;i<towns;i++){//∀配列の初期化
    for (int j=0;j<towns;j++){
      way[i][j]=std::pow(10,17);
      fueldist[i][j]=std::pow(10,17);
    }
  }
  for (int i=0;i<routes;i++){//k-1番目の街とl-1番目の街が繋がれている距離情報の確保。
    std::cin>>a>>b>>length;
    way[a-1][b-1]=length;
    way[b-1][a-1]=length;
  }
  std::cin>>Q;
  int s[Q],t[Q];
  for (int i=0;i<Q;i++){
    std::cin>>s[i]>>t[i];//cinで問題文を回収。
  }

  for (int i=0;i<towns;i++){//まず道について考える.
    for (int j=0;j<towns;j++){
      for (int k=0;k<towns;k++){
          way[j][k]=std::min(way[j][k],way[j][i]+way[i][k]);
      }
    }
  }
  for (int i=0;i<towns;i++){
    for (int j=0;j<towns;j++){
      if(way[i][j]<=fuel){
        fueldist[i][j]=1;
        fueldist[j][i]=1;
      }else{
        fueldist[i][j]=std::pow(10,17);
        fueldist[j][i]=std::pow(10,17);
      }
    }
  }
  for (int i=0;i<towns;i++){
    for (int j=0;j<towns;j++){
      for (int k=0;k<towns;k++){
          fueldist[j][k]=std::min(fueldist[j][k],fueldist[j][i]+fueldist[i][k]);
      }
    }
  }
  for(int i=0;i<Q;i++){
    if(fueldist[s[i]-1][t[i]-1]>=std::pow(10,17)){
      std::cout<<-1<<std::endl;
    }else{
      ans=fueldist[s[i]-1][t[i]-1]-1;
    std::cout<<ans<<std::endl;
    }
  }
}


Measured memory_bytes: 3328
def main():
    N, M= map(int, input().split())
    H = [int(x) for x in input().split()]

    Res = [ True for i in range(N)]

    for i in range(M):
        v1, v2 = map(int, input().split())
        if H[v1-1] > H[v2-1]:
            Res[v2-1] = False
        elif H[v2-1] > H[v1-1]:
            Res[v1-1] = False
        else:
            Res[v1-1] = False
            Res[v2-1] = False

    count = 0

    for i in range(N):
        if Res[i]:
            count += 1
    
    print(count)


if __name__ == "__main__":
    main()
    pass

Measured memory_bytes: 20032
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

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

    double ans = 0;
    for(int i=1; i<=n; i++){
        double sum = (1. / n);
        ll num = i;
        double cnt = 0;
        for(int i=1; ; i++){
            if(k <= num) break;
            cnt++;
            num *= 2;
        }

        for(int i=0; i<cnt; i++){
            sum *= 1. * 0.5;
        }

        ans += sum;
    }

    cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    if(n == 1) cout << 1 << endl;
    if(i * i > n) {
      cout << (i - 1) * (i - 1) << endl;
      break;
    }
  }
  return 0;
}


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

int main(void){
  int n;cin >> n;
  int p[n];rep(i,n)cin >> p[i];
  int ans = 0;
  for(int i=1;i<n-1;i++){
    if(p[i-1] < p[i] && p[i] < p[i+1])ans += 1;
    else if(p[i-1] > p[i] && p[i] > p[i+1])ans += 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << p.first << " " << p.second;
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;

  std::map< std::pair<std::string, ll>, ll> ms;
  std::vector< std::pair<std::string, ll> > vp(N);

  for (ll i = 0; i < N; i++) {
    std::cin >> vp[i].first >> vp[i].second;
    vp[i].second *= -1;
    ms[vp[i]] = i;
  }

  std::sort(vp.begin(), vp.end());
  //print(vp);
  for (ll i = 0; i < N; i++) {
    print(ms[vp[i]]+1);
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
	int n;
	while(cin >> n, n) {
		int m[1010], p[1010], q[1010], r[1010], P, Q, R, C;
		rep(i,n) {
			cin >> m[i] >> p[i]>> q[i] >> r[i];
		}
		cin >> P >> Q >> R >> C;
		bool f = 1;
		rep(i,n) {
			if(p[i]>P || q[i]>Q || r[i]>R || (p[i]*4+q[i]*9+r[i]*4)>C) continue;
			f = 0;
			cout << m[i] << endl;
		}
		if(f) cout << "NA" << endl;
	}
}

Measured memory_bytes: 1176
#include <stdio.h>
#include <string.h>

int N;
char s[112], t[112];
bool same_flag;
int ans;

int main(void)
{
	scanf("%d%s%s", &N, s, t);

	for (int i = 0; i <= N; ++i)
	{
		same_flag = true;
		for (int j = 0; j < N; ++j)
		{
			if (i + j < N)
			{
				if (s[i + j] != t[j])
				{
					same_flag = false;
					break;
				}
			}
		}
		if (same_flag == true)
		{
			ans = i + N;
			break;
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    
    
    double r, are, circ;
    scanf("%lf", &r);
    
    are     = 3.141592653589*r*r;
    circ    =2*r*3.141592653589;
    printf("%.5f %.5f\n", are, circ);
    
    return 0;
}
    


Measured memory_bytes: 2048
//#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
struct ss{
	int node,nxt;
}e[500005];
int tot,head[200005],a[200005],b[200005],l,f[200005],g[200005];
void add(int u,int v)
{
	e[++tot].nxt=head[u];
	e[tot].node=v;
	head[u]=tot;
}
void dfs(int x,int fa)
{
	int q=a[x],now=0;
	if(g[l]<a[x])g[++l]=a[x];
	else
	{
		now=lower_bound(g+1,g+l+1,q)-g;
		swap(g[now],q);
	}
	f[x]=l;
	for(int i=head[x];i;i=e[i].nxt)
	{
		if(e[i].node!=fa)dfs(e[i].node,x);
	}
	if(now)
	{
		swap(g[now],q);
	}
	else l--;
	
}
signed main()
{
	cin>>n;
	int u,v;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<n;i++)
	{	
		cin>>u>>v;
		add(u,v);add(v,u);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		cout<<f[i]<<endl;
}

Measured memory_bytes: 28948
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define vi vector < ll  int >
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007
    using namespace std;
 ll mod=998244353;
void solve()
{
 ll i,j=1,k,n,m=0,f,s1=0,x,c=1,t,y=0;
 string s;
 cin>>s;
 if(s[2]==s[3] and s[4]==s[5]) cout<<"Yes";
 else cout<<"No";
}


 //}

    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
         //cin>>t;
        while(t--)
        solve();
    }


Measured memory_bytes: 256
#include <stdio.h>
#define BAN 21

int board[BAN][BAN], gem;

int main(void)
{
    int i, j, tx, ty, tn, px, py, fl, com;
    char tc[2];
    scanf("%d",&gem);
    while (gem) {
        for (i = 0; i < BAN; i++) {
            for (j = 0; j < BAN; j++) {
                board[i][j] = 0;
            }
        }
        px = 10; py = 10;
        fl = 0;

        for (i = 0; i < gem; i++) {
            scanf("%d %d",&tx, &ty);
            board[tx][ty] = 7;
        }
        scanf("%d",&com);
        for (i = 0; i < com; i++) {
            scanf("%s %d",tc, &tn);
            if (tc[0] == 'N') {
                for (j = 0; j < tn; j++) {
                    py++;
                    if (board[px][py] == 7) {
                        board[px][py] = 0;
                    }
                }
            } else if (tc[0] == 'E') {
                for (j = 0; j < tn; j++) {
                    px++;
                    if (board[px][py] == 7) {
                        board[px][py] = 0;
                    }
                }
            } else if (tc[0] == 'S') {
                 for (j = 0; j < tn; j++) {
                    py--;
                    if (board[px][py] == 7) {
                        board[px][py] = 0;
                    }
                }
            } else if (tc[0] == 'W') {
                 for (j = 0; j < tn; j++) {
                    px--;
                    if (board[px][py] == 7) {
                        board[px][py] = 0;
                    }
                }
            }
        }
        for (i = 0; i < BAN; i++) {
            for (j = 0; j < BAN; j++) {
                if (board[i][j] == 7) {
                    fl = 1;
                }
            }
        }
        if (fl) {
            puts("No");
        } else {
            puts("Yes");
        }
        scanf("%d",&gem);
    }
    return 0;
}

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

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

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

    int _n = n - 1;
    for (int j = _n; 0 <= j; --j) {
        if (j == 0)
            cout << ary[j] << endl;
        else
            cout << ary[j] << " ";
    }

    delete[] ary;
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000001
#define mod 998244353
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 500001;
const ll M = 21;
struct point {
    ll x, y;
    bool operator == (point b)
    {
        if(this -> x == b.x && this -> y == b.y) return 1;
        return 0;
    }
    bool operator != (point b)
    {
        return !(*this == b);
    }
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cout << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x,ll n)
{
    if(n == 0) return 1;
    ll ans;
    if(n % 2 == 0)
    {
         ans = fast_exp(x, n / 2);
         ans = ans * ans % mod;
    }
    else ans = fast_exp(x, n - 1) * x % mod;
    return ans;
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m = 0, x = 0, y = 0, ans = 0, k;
        string s;
        cin >> s;
        n = s.size();
        s = '0' + s;
        ll dp[n + 1][2];
        dp[0][0] = dp[0][1] = 0;
        string sol(n, '0');
        for(int i = 1; i <= n; i++)
        {
            if(s[i] == '?')
            {
                dp[i][0] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 2);
                dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]);
            }
            else
            {
                if(s[i] == 'D')
                    dp[i][0] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 2), dp[i][1] = 0;
                else dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]), dp[i][0] = 0;
            }
            if(dp[i][0] > dp[i][1])
            {
                sol[i - 1] = 'D';
            }
            else sol[i - 1] = 'P';
        }
        cout << sol << "\n";
     }
    return 0;
}


Measured memory_bytes: 6952
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Contest.D
{
	static class Program
	{
		public static void Solve(Scanner cin)
		{
			int n = cin.ReadInt();
			long a = cin.ReadInt();
			long b = cin.ReadInt();
			var x = cin.ReadIntArray(n);
			long ans = 0;
			for (int i = 0; i < n-1; i++)
			{
				ans += Math.Min(a * (x[i + 1] - x[i]), b);
			}

			Console.WriteLine(ans);
		}

		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);
			var cin = new Scanner();
			Solve(cin);
			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Read() => ReadString();

		public string ReadString()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return ReadString();
			i = 0;
			return s[i++];
		}

		public string[] ReadStringArray(int N)
		{
			string[] Array = new string[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = ReadString();
			}
			return Array;
		}

		public int ReadInt()
		{
			return int.Parse(ReadString());
		}

		public int[] ReadIntArray(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = ReadInt() + add;
			}
			return Array;
		}

		public long ReadLong()
		{
			return long.Parse(ReadString());
		}

		public long[] ReadLongArray(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = ReadLong() + add;
			}
			return Array;
		}

		public double ReadDouble()
		{
			return double.Parse(ReadString());
		}

		public double[] ReadDoubleArray(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = ReadDouble() + add;
			}
			return Array;
		}

		public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1));


	}
}

Measured memory_bytes: 18528