akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;

int ans = 0;
int N, M, Q;
int qu[50][4];
void go(vi&A, int v){
  if(A.size() == N){
    int t = 0;
    REP(i,Q){
      auto q = qu[i];
      if(A[q[1]] - A[q[0]] == q[2]) t += q[3];
    }
    MAX(ans, t);
  }else{
    FORN(i, v, M){
      A.PB(i);
      go(A, i);
      A.RB();
    }
  }
}

int main(){
  IO; cin >> N >> M >> Q;
  REP(i,Q) cin >> qu[i][0] >> qu[i][1] >> qu[i][2] >> qu[i][3], --qu[i][0], --qu[i][1];
  vi t; go(t, 1);
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>


int main() {
	std::string s;

	std::cin >> s;

	std::replace(s.begin(), s.end(), '?', 'D');

	std::cout << s << std::endl;

	return 0;
}


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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    ll n,a[2*BIG],b[2*BIG],ans;
    map <ll,ll> mp;


int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    cin >>n;
    for (int i=1; i<=n; i++) {
        cin >>a[i];
    }

    for (int i=1; i<=n; i++) {
        mp[i-a[i]]++;
    }

    for (int i=1; i<=n; i++) {
        ans += mp[i+a[i]];
    }

    cout <<ans;


    return 0;
}


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

int main(){
    int n; cin>>n;
    ll ans=0;
    vector<ll> lis(5,0);
    for (int i=0; i<n; i++){
        string s; cin >> s;
        char c=s[0];
        if(c=='M') lis[0]++;
        else if(c=='A') lis[1]++;
        else if(c=='R') lis[2]++;
        else if(c=='C') lis[3]++;
        else if(c=='H') lis[4]++;
    }
    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ans += lis[i]*lis[j]*lis[k];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll>loe,ano,ple;
set<ll>s;
ll d,n=1,o,ans;
ll iabs(ll x)
{
	return x<0?-x:x;
}
ll dfs(ll use,ll rest)
{
	ll k=ple[(rest%10+10)%10];
	if(use<=0)
	{
		if(rest)
			return 0;
		else
			return 1+(o&1)*9;
	}
	if(abs(rest)/abs(use)>9)
		return 0;
	if(k)
		return ano[k]*dfs(use/100,(rest-k*use)/10)+ano[k-10]*dfs(use/100,(rest+(10-k)*use)/10);
	else
		return ano[0]*dfs(use/100,rest/10);
}
ll logi(ll use,ll rest)
{
	ll k=ple[(rest%10+10)%10];
	if(use<=0)
	{
		if(rest)
			return 0;
		else
			return 1+(o&1)*9;
	}
	if(abs(rest)/abs(use)>9)
		return 0;
	if(k)
		return loe[k]*dfs(use/100,(rest-k*use)/10)+loe[k-10]*dfs(use/100,(rest+(10-k)*use)/10);
	else
		return loe[0]*dfs(use/100,rest/10);
}
int main(void)
{
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
	ll t;
	t=1;
	//scanf("%lld",&t);
	for(ll i=-8; i<9; i++)
		loe[i]=9-iabs(i);
	for(ll i=-9; i<10; i++)
		ano[i]=10-iabs(i);
	for(ll i=0; i<10; i++)
		ple[i*9%10]=i;
	while(t--)
	{
		o=0;
		ans=0;
		n=1;
		scanf("%lld",&d);
		for(ll i=1; i<=18; i++)
		{
			o++;
			ans+=logi(n-1,d);
			n*=10;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string N;
	cin >> N;
	bool ans = false;
	for (int i = 0; i < 3; i++) {
		if (N[i] == '7') ans = true;
	}
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;

#define INF ((1LL<<31)-1)
#define D 10

struct SegTree {
	int segSize, realSegSize, nodeSize;
	vector<int> seg;

	void init(int n) {
		realSegSize = n;

		nodeSize = 0;
		for (segSize = 1; segSize < n; segSize *= D) nodeSize += segSize;

		seg = vector<int>(nodeSize+n, INF);
	}

	int get(int n) {
		if (n < (int)seg.size()) return seg[n];
		else return INF;
	}
	void set(int n, int v) {
		if (n < (int)seg.size()) seg[n] = v;
	}

	void update(int pos, int val) {
		int n = nodeSize + pos;
		set(n, val);
		while (n) {
			n = (n-1)/D;

			int r = INF;
			for (int i = 0; i < D; ++i) {
				r = min(r, seg[n*D+i+1]);
			}
			set(n, r);
		}
	}
	int get(int n, int l, int r, int L, int R) {
//		cout << n << " " << l << " " << r << endl;
		if (L <= l && r <= R) return get(n);
		else if (R <= l || r <= L) return INF;
		else {
			int ret = INF;
			int prev = l;
			for (int i = 0; i < D; ++i) {
				int next = i == D-1 ? r : prev + (r-l)/D;
				ret = min(ret, get(n*D+i+1, prev, next, L, R));
				prev = next;
			}
			return ret;
		}
	}
	int get(int L, int R) {
		return get(0, 0, segSize, L, R);
	}

	~SegTree() {
		seg.clear();
		seg.shrink_to_fit();
	}
};

struct Query {
	int y1, x1, y2, x2;
};

int main() {
	int H, W, Q;
	while ( cin >> H >> W >> Q, H || W || Q ) {
		vector< vector<int> > m(H, vector<int>(W, 0));

		for (int y = 0; y < H; ++y) {
			for (int x = 0; x < W; ++x) {
				cin >> m[y][x];
			}
		}

		bool isSegRow = H < W;
		vector<SegTree> seg;

		if (isSegRow) {
			seg.resize(H);
			for (int y = 0; y < H; ++y) {
				seg[y].init(W);
			}
		}
		else {
			seg.resize(W);
			for (int x = 0; x < W; ++x) {
				seg[x].init(H);
			}
		}

		for (int y = 0; y < H; ++y) {
			for (int x = 0; x < W; ++x) {
				if (isSegRow) seg[y].update(x, m[y][x]);
				else seg[x].update(y, m[y][x]);
			}
		}

		for (int t = 0; t < Q; ++t) {
			int y1, x1, y2, x2; cin >> y1 >> x1 >> y2 >> x2;

			int ans = INF;
			if (isSegRow) {
				for (int y = y1; y <= y2; ++y) {
					ans = min(ans, seg[y].get(x1, x2+1));
				}
			}
			else {
				for (int x = x1; x <= x2; ++x) {
					ans = min(ans, seg[x].get(y1, y2+1));
				}
			}
			cout << ans << endl;
		}

		seg.clear();
		seg.shrink_to_fit();
	}
}

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

using namespace std;
int a[1000],dp[100009][3],n,k;
int sol(int x,int tu)
{
    if(dp[x][tu]!=-1) return dp[x][tu];
    if (tu==2) dp[x][tu]=1;
    else dp[x][tu]=0;
    for (int i=0;a[i]<=x && i<n;i++)
    {
        if (tu==1) dp[x][tu]=max(sol(x-a[i],2),dp[x][tu]);
        else dp[x][tu]=min(sol(x-a[i],1),dp[x][tu]);
    }
    return dp[x][tu];
}
int main()
{
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=sol(k,1);
    if (ans==0) cout<<"Second";
    else cout<<"First";
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int P[20];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>P[i];
	int ret=0;
	FOR(i,N-2) {
		if(P[i]<P[i+1] && P[i+1]<P[i+2]) ret++;
		if(P[i]>P[i+1] && P[i+1]>P[i+2]) ret++;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
local n = io.read("n")
local k = io.read("n")
--local n, k = 50, 4321098765432109
local g = {[0] = {1, 1}}
for i = 1, n do
	local c0 = g[i - 1][1]
	local p0 = g[i - 1][2]
	local c = c0 * 2 + 3
	local p = p0 * 2 + 1
	g[i] = {c, p}
end
local function f(_n, _k)
	if _k <= 0 then
		return 0
	end
	if _n <= 0 then
		return 1
	end
	local c = g[_n][1]
	local hc = (g[_n][1] + 1) // 2
	if _k >= c then
		return g[_n][2]
	elseif _k == hc then
		return f(_n - 1, _k - 2) + 1
	elseif _k < hc then
		return f(_n - 1, _k - 1)
	else
		return f(_n - 1, _k - 1) + 1 + f(_n - 1, _k - hc)
	end
end
print(f(n, k))

Measured memory_bytes: 256
# A
# Airplane

P_Q_R = input()

P = int(P_Q_R.split(" ")[0])
Q = int(P_Q_R.split(" ")[1])
R = int(P_Q_R.split(" ")[2])

PQR =[P, Q, R]

import numpy as np

print(np.sum(PQR) - np.max(PQR))

Measured memory_bytes: 12508
#include <bits/stdc++.h>
using namespace std;
// ==================================================
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,a,b) for(i64 i=(int64_t)(a);i<(int64_t)(b);i++)
#define repn(i,n) rep(i,0,n)
#define din(t, ...) t __VA_ARGS__;_din(__VA_ARGS__)
#define v(t,n) vector<t> n
void _din() {}
void dout() { cout << endl; }
template <typename T, typename ... Args> inline void _din(T& head, Args& ... rest) { cin >> head; _din(rest...); }
template <typename T, typename ... Args> inline void dout(T head, Args ... rest) { cout << head; if (sizeof...(rest)) cout << ' '; dout(rest...); }
template <typename T>inline void qsortv(vector<T>& v) { qsort(v.data(), v.size(), sizeof(T), [](const void*a, const void*b)->int {if ((*(T*)a) < (*(T*)b))return -1; if ((*(T*)a) == (*(T*)b))return 0; return 1; }); }
template <typename T, typename F>inline void qsortv(vector<T>& v, F func) { qsort(v.data(), v.size(), sizeof(T), func); }
template <typename T>inline void sortv(vector<T>& v) { sort(v.begin(), v.end()); }
// ==================================================

int main()
{
	din(int, n, m, x, y);
	int zmin = -101, zmax = 101;
	repn(i, n)
	{
		din(int, xi = 0);
		if (xi > zmin) zmin = xi;
	}
	repn(i, m)
	{
		din(int, yi = 0);
		if (yi < zmax) zmax = yi;
	}
	dout(zmin<y&&zmax>x&&zmin < zmax ? "No War" : "War");
}

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

int x[10000000];

void prime(int p) {
	x[2] = 1;
	for (int i = 3; i < p; i += 2) {
		for (int j = 3; j*j <= i; j += 2) {
			if (i%j == 0) { goto E; }
		}
		x[i] = 1;
	E:;
	}
}

int gold(int p) {
	int sum = 0;
	for (int i = 2; i <= p / 2; i++) {
		if (x[i] + x[p - i] == 2) { sum++; }
	}
	return sum;
}

int n;

int main() {
	prime(3000000);
	while (true) {
		cin >> n;
		if (n == 0) { break; }
		cout << gold(n) << endl;
	}
}

Measured memory_bytes: 13440
#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) (x&-x)
using namespace std;
const int N = 18;
ll f[1<<18];
int n, a[N][N];
ll slove(int s)
{
	ll res = 0;
	int t[N], tot = 0;
	for(int i = 0; i < n; i++)
	{
		if(s&(1<<i))
		{
			t[++tot] = i+1;
		}
	}
	for(int i = 1; i <= tot; i++)
	{
		for(int j = i; j <= tot; j++)
		{
			res += a[t[i]][t[j]];
		}
	}
	return res;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}
	for(int s = 1; s < (1<<n); s++)
	{
		f[s] = slove(s);
		for(int ss = s; ss; ss = (ss-1)&s)
		{
			f[s] = max(f[s], f[ss]+f[s^ss]);
		}
	}
	printf("%lld\n", f[(1<<n)-1]);
	return 0;
}

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

int *dp, *hrr, n;

int main(){
    cin>>n;
    hrr = new int[n], dp = new int[n];
    for(int i=0;i<n;i++){
        cin>>hrr[i];
    }

    dp[0] = 0;
    dp[1] = abs(hrr[1]-hrr[0]) + dp[0];
    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(hrr[i]-hrr[i-1]), dp[i-2]+abs(hrr[i]-hrr[i-2]));
    }
    cout << dp[n-1];

    return 0;
}

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

//A
/*
int main() {
    int N, odd, eve;
    double ans;
    std::cin >> N;
    eve = N/2;
    odd = N - eve;
    ans = (double) odd/N;

    std::cout << ans << std::endl;

    return 0;
}
 */

int main() {
    int N, K;
    std::cin >> N >> K;
    int h[N];
    int mem = 0;
    for(int i=0; i<N; i++){
        std::cin >> h[i];
        if(h[i]>=K){
            mem ++;
        }
    }

    std::cout << mem << std::endl;
    return 0;
}


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

int main()
{
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    int mx = f / 100;
    //    int mani1, mani2, water,smax;
    double conc = 0.0;
    double cmax = 100.0 * (double)e / (100.0 + (double)e);
    //   cout << "cmax=" << cmax << endl;
    int w = 0, s = 0;
    //   cout << mx / a << " " << mx / b << endl;
    rep(i, mx / a + 1)
    {
        int mani1 = i * 100 * a;
        rep(j, mx / b + 1)
        {
            int mani2 = j * b * 100;
            int water = mani1 + mani2;
            int smax = f - water;
            rep(k, smax / c + 1)
            {
                int mani3 = k * c;
                rep(l, smax / d + 1)
                {
                    int mani4 = l * d;
                    int sugar = mani3 + mani4;
                    if ((sugar + water) <= f)
                    {
                        double ctmp = 100.0 * (double)sugar / ((double)sugar + (double)water + 1e-10);
                        //             cout << "sugar=" << sugar << endl;
                        //           cout << "water=" << water << endl;
                        //         cout << "ctmp=" << ctmp << endl;
                        if (ctmp >= conc && ctmp <= cmax)
                        {
                            conc = ctmp;
                            w = water;
                            s = sugar;
                            //       cout << "w=" << w << ",s=" << s << endl;
                        }
                    }
                }
            }
        }
    }
    cout << w + s << " " << s << endl;
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll N,M,H,W,K,A,B;
string S;
//Write From this Line

int main()
{
	cout << setprecision(10);
	cin >> N >> K ;
	//a1をb1個挿入する。
	vector<ll> P(100100,0);
	//pair<入れる数、何個入ってるか>

	rep(i,N){
		ll a, b;
		cin >>  a >> b;
		P[a] += b;
	}
	ll count = 0 ;
	rep(i,100100){
		count += P[i];
		if(count>=K){
			cout <<i<<endl;
			return 0;
		}
	}

}


Measured memory_bytes: 1024
N,M,X = map(int,input().split())

text = []
min_money = 100000000
for i in range(N):
  ca = list(map(int,input().split()))
  text.append((ca[0],ca[1:]))
for i in range(2 ** N):
    und = [0]*M
    money = 0
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
          und = [x + y for (x, y) in zip(text[j][1], und)]
          money += text[j][0]
    if all([i >= X for i in und]) and money < min_money:
      min_money = money

if min_money == 100000000:
  min_money = -1
print(min_money)
      

Measured memory_bytes: 9220
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<random>
#include<stdio.h>
using namespace std;

typedef long long ll;
typedef double lf;


int main(){
    ll N,M;
    cin>>N>>M;
    vector<vector<ll>>    edge(N,vector<ll>(0));
    for (ll i=0;i<M;i++){
        ll s,t;
        cin>>s>>t;
        edge[s-1].push_back(t-1);
    }

    vector<lf> dp(N,0);
    vector<ll> Max(N,-1);
    for (ll i=N-2;i>-1;i--){
        lf ans=1;
        lf test=0;
        for (ll j=0;j<edge[i].size();j++){
            ans+=dp[edge[i][j]]/edge[i].size();
            if (dp[edge[i][j]]>test){
                Max[i]=edge[i][j];
                test=dp[edge[i][j]];
            }
        }
        dp[i]=ans;
    }

    lf answer=dp[0];
    for (ll i=0;i<N;i++){
        if (edge[i].size()>1){
            vector<lf> tdp(N,0);
            for (ll j=N-2;j>-1;j--){
                lf ans=1;
                if (j!=i){
                    for (ll k=0;k<edge[j].size();k++){
                        ans+=tdp[edge[j][k]]/edge[j].size();
                    }
                    tdp[j]=ans;
                }
                else{
                    for (ll k=0;k<edge[j].size();k++){
                        if (edge[j][k]!=Max[i]){
                            ans+=tdp[edge[j][k]]/(edge[j].size()-1);
                        }
                    }
                    tdp[j]=ans;
                }
                
            }
            answer=min(answer,tdp[0]);
        }
    }
    cout<<std::setprecision(12)<<answer<<endl;
}


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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    string S;
    cin >> S;
    int ans = 0;
    for (int s = 0; s < S.size(); ++s) {
        for (int e = S.size()-1; e >= s; --e) {
            bool f = true;
            for (int t = s; t <= e; ++t) {
                if (S[t] != 'A' and S[t] != 'G' and S[t] != 'C' and S[t] != 'T') {
                    f = false;
                    break;
                }
            }
            if (f) {
                ans = max(ans, e - s + 1);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3596
def abs(x):
    if x > 0:
        return x
    else:
    	return x * (-1)

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_sorted = sorted(a)
    print(abs(a_sorted[-1] - a_sorted[0]))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ers erase
#define ins insert
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) cout << #x << "= " << x << '\n';
#define kill(x) return cout << x, 0;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll LOG = 25;

vl num;
ll n, d;
ll Cnt[10];

bool isval(ll x){
	ll f = 0;
	while (x){
		f |= Cnt[x % 10];
		x /= 10;
	}
	return !f;
}

int main(){
	cin >> n >> d;
	for (int i = 0; i < d; i++){
		ll v;
		cin >> v;
		Cnt[v] = 1;
	}
	ll pnt = n;
	ll f = 1;
	while (f){
		if (!isval(pnt)) pnt++;
		else f = 0;
	}
	cout << pnt;


	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int n, m;
	auto dist = [&](int src, int dst){
		if(src <= dst) return dst - src;
		return dst + m - src;
	};
	while(cin >> n >> m){
		vector<int> a(n);
		for(int& t : a){ cin >> t; --t; }
		vector<int> dif(m, 0);
		vector<int> add(m, 0);
		for(int i=0;i<n-1;i++) dif[(a[i]+1)%m]++;
		for(int i=1;i<n;i++){
			dif[a[i]]--;
			add[a[i]] += dist(a[i-1], a[i]) - 1;
		}
		int cnt = dif[0];
		long long cur = 0;
		for(int i=0;i+1<n;i++){
			int distA = dist(a[i], a[i+1]);
			int distB = dist(0, a[i+1]) + 1;
			if(distB < distA) ++cnt;
			cur += min(distA, distB);
		}
		long long res = cur;
		for(int i=1;i<m;i++){
			cur -= cnt;
			cur += add[(i+m-1)%m];
			cnt += dif[i];
			res = min(cur, res);
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 1408
H, W = map(int, input().split())

min_p = 10 ** 6
for i in range(1, W):
    a = H * i
    b = H * ((W - i) // 2)
    c = H * W - a - b
    if max(a, b, c) - min(a, b, c) < min_p:
        min_p = max(a, b, c) - min(a, b, c)
    a = H * i
    b = (H // 2) * (W - i)
    c = H * W - a - b
    if max(a, b, c) - min(a, b, c) < min_p:
        min_p = max(a, b, c) - min(a, b, c)

for i in range(1, H):
    a = W * i
    b = W * ((H - i) // 2)
    c = W * H - a - b
    if max(a, b, c) - min(a, b, c) < min_p:
        min_p = max(a, b, c) - min(a, b, c)
    a = W * i
    b = (W // 2) * (H - i)
    c = W * H - a - b
    if max(a, b, c) - min(a, b, c) < min_p:
        min_p = max(a, b, c) - min(a, b, c)

print(min_p)


Measured memory_bytes: 3064
local n, k = io.read("*n", "*n")
local k2 = k * 2
local rows_per_col = {}
for i = 1, k2 do rows_per_col[i] = {} end
local count_per_row, count_per_row2 = {}, {}
for i = 1, k2 do
  count_per_row[i] = 0
  count_per_row2[i] = 0
end
for i = 1, n do
  local x, y, c = io.read("*n", "*n", "*l")
  if c == " W" then x = x + k end
  x, y = x % k2 + 1, y % k2 + 1
  table.insert(rows_per_col[x], y)
  if x <= k then
    count_per_row[y] = count_per_row[y] + 1
  else
    count_per_row2[y] = count_per_row2[y] + 1
  end
end
local mma = math.max
local function solve()
  local val = 0
  for i = 1, k do
    val = val + count_per_row[i] + count_per_row2[i + k]
  end
  local maxval = val
  for i = 1, k do
    val = val - count_per_row[i] + count_per_row[k + i] - count_per_row2[k + i] + count_per_row2[i]
    maxval = mma(maxval, val)
  end
  for i = 1, k do
    val = val + count_per_row[i] - count_per_row[k + i] + count_per_row2[k + i] - count_per_row2[i]
    maxval = mma(maxval, val)
  end
  return maxval
end
local ret = solve(maxval)
for i = 1, k do
  for j = 1, #rows_per_col[i] do
    count_per_row[rows_per_col[i][j]] = count_per_row[rows_per_col[i][j]] - 1
    count_per_row2[rows_per_col[i][j]] = count_per_row2[rows_per_col[i][j]] + 1
  end
  for j = 1, #rows_per_col[i + k] do
    count_per_row[rows_per_col[i + k][j]] = count_per_row[rows_per_col[i + k][j]] + 1
    count_per_row2[rows_per_col[i + k][j]] = count_per_row2[rows_per_col[i + k][j]] - 1
  end
  ret = mma(ret, solve())
end
for i = 1, k do
  for j = 1, #rows_per_col[i] do
    count_per_row[rows_per_col[i][j]] = count_per_row[rows_per_col[i][j]] + 1
    count_per_row2[rows_per_col[i][j]] = count_per_row2[rows_per_col[i][j]] - 1
  end
  for j = 1, #rows_per_col[i + k] do
    count_per_row[rows_per_col[i + k][j]] = count_per_row[rows_per_col[i + k][j]] - 1
    count_per_row2[rows_per_col[i + k][j]] = count_per_row2[rows_per_col[i + k][j]] + 1
  end
  ret = mma(ret, solve())
end
print(ret)


Measured memory_bytes: 2432
import sys
input = sys.stdin.readline
from collections import deque
from itertools import product
import heapq


def read():
    H, W = map(int, input().strip().split())
    CH, CW = map(int, input().strip().split())
    DH, DW = map(int, input().strip().split())
    S = [[0 for j in range(W)] for i in range(H)]
    for i in range(H):
        s = list(input().strip())
        for j in range(W):
            if s[j] == "#":
                S[i][j] = -2
            else:
                S[i][j] = -1
    return H, W, CH, CW, DH, DW, S


def solve(H, W, CH, CW, DH, DW, S):
    DIR0 = [(0, 1), (1, 0), (0, -1), (-1, 0)]
    DIR1 = [
        (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),
        (-1, -2), (-1, -1), (-1, 1), (-1, 2),
        (0, -2), (0, 2),
        (1, -2), (1, -1), (1, 1), (1, 2),
        (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)
    ]
    S[CH-1][CW-1] = 0
    q = deque()
    q.appendleft((CH-1, CW-1))
    while q:
        # キューの先頭から候補を取り出す
        y0, x0 = q.popleft()
        d0 = S[y0][x0]
        # 距離0で到達可能な場所をキューの先頭に入れる
        for dy, dx in DIR0:
            ny, nx = y0 + dy, x0 + dx
            if 0 <= ny < H and 0 <= nx < W and (S[ny][nx] == -1 or S[ny][nx] > d0):
                q.appendleft((ny, nx))
                S[ny][nx] = d0
        # 距離1で到達可能な場所をキューの末尾に入れる
        for dy, dx in DIR1:
            ny, nx = y0 + dy, x0 + dx
            if 0 <= ny < H and 0 <= nx < W and (S[ny][nx] == -1 or S[ny][nx] > d0+1):
                q.append((ny, nx))
                S[ny][nx] = d0+1
    return S[DH-1][DW-1]


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 90816
import java.util.*;

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

        int N = sc.nextInt();
        int[] nums = {64, 32, 16, 8, 4, 2, 1};
        
        for (int n : nums) {
            if (N >= n) {
                System.out.println(n);
                return;
            }
        }
    }
}



Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n[12];
    rep(i, 12){
        cin>>n[i];
    }
    sort(n, n + 12);
    rep(i, 3){
        if(count(n + i * 4, n + (i + 1) * 4, n[i * 4]) != 4){
            cout<<"no"<<endl;
            return 0;
        }
    }
    cout<<"yes"<<endl;
}



Measured memory_bytes: 3212
#include <stdio.h>
#include <iostream>
#include <vector>

int main(int argc, char** argv)
{
    int H,W;
    std::cin >> H;
    std::cin >> W;
    std::vector<char> A;
    std::vector<int> vIndex;

    for(int h = 0; h<H;h++)
    {
        for(int w = 0; w < W; w++)
        {
            char Aij;
            std::cin >> Aij;
            A.push_back(Aij);
            if(Aij =='#')
            {
                vIndex.push_back(h*W+w);
            }
        }
    }
    int counter=0;
    int index0,index1,index2,index3;
    int S = H*W;

    for(int i=0; i<(int)vIndex.size(); i++)
    {
        bool nochange = true;
        int iMax = (int)vIndex.size();

        for(;i < iMax; i++)
        {
            index0 = vIndex[i] -1;
            index1 = vIndex[i] +1;
            index2 = vIndex[i] +W;
            index3 = vIndex[i] -W;

            if(vIndex[i] % W !=0 && A[index0] =='.'){ vIndex.push_back(index0); A[index0] ='#';nochange = false;}
            if(vIndex[i] % W != W-1 && A[index1] =='.'){ vIndex.push_back(index1); A[index1] ='#';nochange = false;}
            if(index2 < S  && A[index2] =='.'){ vIndex.push_back(index2); A[index2] ='#';nochange = false;}
            if(index3 >= 0 && A[index3] =='.'){ vIndex.push_back(index3); A[index3] ='#';nochange = false;}
        }

        if(nochange){break;}
        counter++;
        i--;

    }


    std::cout << counter;
    
    return 0;
}

Measured memory_bytes: 7400
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))

ll gcd(ll a,ll b){
    ll p,q;
    ll aa=max(a,b);
    ll bb=min(a,b);
    //p=aa/bb;
    q=aa%bb;
    if (q<=0)return bb;
    return gcd(bb,q);
}

int main(){
    ll ans,a,b,k;

    cin >>a>>b>>k;

    ll gcdd=gcd(a,b);
    dbg cout <<gcdd<<endl;
    for(int i=gcdd;i>0;i--){
        if(gcdd%i==0){
            k--;
            dbg cout <<i<<endl;
            if (k==0){
                ans=i;
                break;
            }
        }

    }
    

    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int la,ra;
        if((a&1)==0){
            la = a*25/2;
            ra = (a+1)*25/2;
        }else{
            la = a*25/2 + 1;
            ra = (a+1)*25/2-1;
        }

        int lb = b*10;
        int rb = b*10+9;

        if(la>rb || ra<lb) System.out.println(-1);
        else System.out.println(Math.max(la,lb));
    }
}

Measured memory_bytes: 25296
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for( i=a;i<b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const ll MOD=1e9+7;


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    ll t=1,a=1;
    rep(i,n) {
        ll tt,aa;
        cin >> tt >> aa;
        t+=(tt-(t%tt))%tt;
        a+=(aa-(a%aa))%aa;
        ll r=(t/tt>a/aa)?(t/tt):(a/aa);
        t=r*tt;
        a=r*aa;
    }
    cout << t+a << endl;
    return 0;
}

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

int main () {
  int a, b;
  cin >> a >> b;
  
  if (a+b == 15) {
    cout << "+" << endl;
  }
  else if (a*b == 15) {
    cout << "*" << endl;
  }
  else {
    cout << "x" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int X[300][300],cnt=0;
  for(int i=0; i<300; i++) {
      cin >> X[i][0] >> X[i][1];
      if(X[i][0]==0&&X[i][1]==0) {
          cnt=i;
          break;
      }
  }
  for(int i=0; i<cnt; i++) {
      for(int j=0; j<X[i][0]; j++) {
          for(int k=0; k<X[i][1]; k++) {
              cout << '#';
          }
          cout << endl;
      }
      cout << endl;
  }
}


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

using namespace std;

int n, k, w[100000];

bool check(int p){
  int cnt = 1;
  long long total = 0;

  for(int i = 0;i < n;i++){
    if(w[i] > p) return false;
    if(total + w[i] <= p) total += w[i];
    else{
      cnt++;
      total = w[i];
    }
  }

  if(cnt <= k) return true;
  else return false;
}

int main(){

  cin >> n >> k;
  for(int i = 0;i < n;i++) cin >> w[i];

  long long left = 0, right = 100000 * 10000;
  while(left < right){
    int mid = (left + right) / 2;

    if(check(mid)) right = mid;
    else left = mid + 1;
  }

  cout << left << endl;

  return 0;
}



Measured memory_bytes: 3480
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };

vector<edge>tree[100010];
vector<P> connect[100005];
long long cost[100005];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int N, M;
	cin >> N >> M;

	vector<P>key;
	for (int i = 0; i < M;++i) {
		int a, b;
		cin >> a >> b;
		int s = 0;
		for (int j = 0; j < b; ++j) {
			int c;
			cin >> c; --c;
			s |= 1 << c;
		}
		key.emplace_back(s, a);
	}

	vector<int>dp(1 << N, INF);
	dp[0] = 0;
	for (int i = 0; i < (1 << N); ++i) {
		for (int j = 0; j < M; ++j) {
			int t = i | key[j].first;
			dp[t] = min(dp[t], dp[i] + key[j].second);
		}
	}

	int ans = dp.back();
	if (ans == INF)ans = - 1;
	cout << ans << endl;
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
#define el '\n'
typedef long long ll; typedef long double ld; typedef double dd;typedef vector<int> vi; typedef pair<int, int> pii;typedef pair<ll,ll> pll;
ll INFLL=(ll)4e18, MOD=1e9+7; const int INF=0x3f6f6f6f;
//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';
/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vi vis, color, level; int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

vi a;
vv<int> memo((int)1e5+1,-1);
int dp(int n){
	if(n<=0) return false;
	else if(memo[n]!=-1) return memo[n];
	int& ret=memo[n];
	ret=0;
	for(auto nums: a){
		if(nums>n) continue;
		else if(dp(n-nums)==false) {ret=1; break;}
	}
	return ret;
}
///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n,k; cin>>n>>k;
a.resize(n); for(int i=0;i<n;++i) cin>>a[i];
cout<< (dp(k)?"First":"Second") <<el;

return 0;
}


Measured memory_bytes: 5888
#include <stdio.h>
 
int main(void) {
    int m, f, r;
 
    while(1) {
        scanf("%d %d %d", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1) {
            break;
        }
 
        if (m == -1 || f == -1) {
            printf("F\n");
        } else if (m + f >= 80) {
            printf("A\n");
        } else if (m + f >= 65) {
            printf("B\n");
        } else if (m + f >= 50 || r >= 50) {
            printf("C\n");
        } else if (m + f >= 30) {
            printf("D\n");
        } else {
            printf("F\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2068
#include <stdio.h>

int main(void)          
{
	int x=1;
	int i = 1;

	while(x != 0)
	{
		scanf("%d", &x);
		if (x != 0) 
		{
			printf("Case %d: %d\n", i, x);
			i++;
		}
	}


	return 0;
}

Measured memory_bytes: 600
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
 	public static void main (String[] args) {
     	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int k = sc.nextInt(); int count = 0;
      	for (int i = 0; i<n; i++) {
         	int x = sc.nextInt();
          	if (x>=k)
              count++;
        }
      System.out.println(count);
      
    }
}


Measured memory_bytes: 57752
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];

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


  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        //printf("%d %d %d\n", a[i], a[j], a[k]);
        if (a[i] + a[j] > a[k]) ++ans;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

//Izua Dictionary
public class Main{

	long M = 1000000007;

	public void run() {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[100000];
		long[] f = new long[100001];
		f[0] = 1;
		for(int i=1;i<=100000;i++)f[i]=f[i-1]*i%M;
		for(;;){
			int n = sc.nextInt();
			if (n==0)break;
			for(int i=0;i<n;i++)a[i]=i+1;
			int r = sc.nextInt();
			while(r--!=0){
				int s = sc.nextInt()-1, t = sc.nextInt()-1;
				int x = a[s];
				a[s] = a[t];
				a[t] = x;
			}
			BIT bit = new BIT(100001);
			for(int i=2;i<=100000;i++){
				bit.add(i, 1);	
			}
			long res = 0;
			for(int i=0;i<n;i++){
				res+=bit.sum(a[i])*f[n-1-i];
				res%=M;
				bit.add(a[i], -1);
			}
			System.out.println(res);
		}
	}

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

	public static class BIT {

		public int n;
		private int[] bit;

		public BIT(int n) {
			this.n = n;
			bit = new int[n+1];
		}

		public int sum(int i){
			int s = 0;
			while(i>0){
				s += bit[i];
				i -= i&-i;
			}
			return s;
		}

		public void add(int i, int x){
			while(i<=n){
				bit[i] += x;
				i += i&-i;
			}
		}
	}
}

Measured memory_bytes: 55612
#include <iostream>
#include <string>
using namespace std;
int main() {
    int tbl[6][5] = {
        {'a', 'b', 'c', 'd', 'e'},
        {'f', 'g', 'h', 'i', 'j'},
        {'k', 'l', 'm', 'n', 'o'},
        {'p', 'q', 'r', 's', 't'},
        {'u', 'v', 'w', 'x', 'y'},
        {'z', '.', '?', '!', ' '}
    };

    string code;
    while (cin >> code) {
        string converted = "";

        if (code.size() % 2 != 0) {
            converted = "NA";
        } else {
            for (int i=0; i<(int)code.size(); i+=2) {
                int a = code[i] - '0';
                int b = code[i+1] - '0';
                if (a >= 1 && a <= 6 && b >= 1 && b <= 5) {
                    converted += tbl[a-1][b-1];
                } else {
                    converted = "NA";
                    break;
                }
            }
        }

        cout << converted << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

signed main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  int sum=0;
  r(i,n-1){
    if(s[i]==s[i+1])sum++;
  }
  while(k && sum!=n-1){
    k--;
    sum+=2;
    if(sum>=n)sum--;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

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

  sort(a.rbegin(), a.rend());
  ll sum = 0;
  rep(i, n) {
    if (i%2 == 0) sum += a[i];
  }

  vector<ll> s(n);
  s[0] = sum;
  //debug(sum);
  for(int i=1; 2*i<n; i++) {
    s[i] = s[i-1] - a[2*i] + a[i];
    //debug(i); debugln(s[i]);
  }

  vector<int> pos(n);
  pos[0] = INT_MAX;
  for(int i=1; 2*i<n; i++) {
    pos[i] = (a[i]+a[2*i])/2;
    //debug(i); debugln(pos[i]);
  }

  vector<ll> x(q);
  rep(i, q) {
    int x; cin >> x;
    int mi = 0; // always true
    int ma = n/2+1; // always false
    while(mi+1 < ma) {
      int now = (mi+ma)/2;
      if (x <= pos[now]) {
        mi = now;
      } else {
        ma = now;
      }
    }
    cout << s[mi] << '\n';
  }

  
  
  

}

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

int main() {
    int N;
    cin >> N;
    vector<int> t(N + 1, 0), x(N + 1, 0), y(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }

    for (int i = 1; i <= N; i++) {
        int dt = t[i] - t[i - 1];
        int dx = abs(x[i] - x[i - 1]);
        int dy = abs(y[i] - y[i - 1]);
        if ((dx + dy) % 2 != dt % 2 || (dx + dy) > dt) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1408
D, G = map(int, input().split())
ps = []
cs = []
for i in range(D):
    p, c = map(int, input().split())
    ps.append(p)
    cs.append(c)

ans = 1e100

for bit in range(1 << D):
    score = 0
    num = 0

    # 全問解く
    for b in range(D):
        if (bit & (1 << b)) > 0:
            score += cs[b] + ps[b] * 100 * (b + 1)
            num += ps[b]
    if score >= G:
        ans = min(ans, num)
        continue

    for b in range(D - 1, -1, -1):
        # 上で全問解いてるのでもう解けない
        if (bit & (1 << b)) > 0:
            continue

        for j in range(ps[b]):
            if score >= G:
                break
            score += 100 * (b + 1)
            num += 1
    ans = min(ans, num)

print(ans)


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            (long N, long K) = Slice2<long>();
            var ans = (long)(K * Pow((int)K - 1, (int)N - 1));
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 27692
#include <stdio.h>

int main()
{
  char str[100001];
  int ans=1;
  int i=1;
  int n;
  scanf("%d",&n);
  scanf("%s",str);
  while(str[i]){
    if(str[i]!=str[i-1]) ans++;
    i++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  long double n, t, a;
  cin >> n >> t >> a;
  vector<long double> h(n);
  rep(i, n) cin >> h[i];
  int ans = 0;
  long double dis = mod;
  rep(i, n) {
    long double cdis = t - h[i] * 0.006 - a;
    if (cdis < 0) cdis *= -1;
    if (cdis < dis) {
      dis = cdis;
      ans = i+1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: int, B: int):
    print(A*(N//(A+B))+min(N%(A+B), A))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
using System;
class p
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    string[] input = Console.ReadLine().Split(' ');
    int[] arr = new int[N];
    for (int i = 0; i < N; i++) {
      arr[i] = int.Parse(input[i]);
    }
    Array.Sort(arr);
    Array.Reverse(arr);
    
    int aPoint = 0;
    int bPoint = 0;
    for (int i = 0; i < N; i++) {
      if (i % 2 == 0) {
        aPoint += arr[i];
      } else {
        bPoint += arr[i];
      }
    }
    Console.WriteLine(aPoint - bPoint);
  }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
long long a;
int b,c;
int main()
{
	scanf("%lld",&a);
	scanf("%d.%d",&b,&c);
	b=b*100+c;
	a=a*b/100;
	printf("%lld",a);
	return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;typedef long long ll;
int main(){
  ll a, b, c, ans = 0;
  cin >> a >> b >>c;
  while ((a%2+1)*(b%2+1)*(c%2+1)==1) {
    ll A = a, B = b;
    a = B/2+c/2;
    b = A/2+c/2;
    c = A/2+B/2;
    ans++;
    if (ans > 10000000) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N,count;
    
    int i, h,h0,diff;

    h0 = 0;
    count = 0;
    cin >> N ;
    for (i=0; i<N; i++){
        cin >> h;
        diff = h - h0;
        if(diff<0)diff=0;
        count += diff;
        h0 = h;
    }
    
    cout << count << endl;
    
    
    return 0;
}

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

int main(){
    ll N;
    cin >> N;
    vector<ll> p(N), q(N+1);
    rep(i, 0, N){
        cin >> p[i];
        q[p[i]] = i;
    }
    ll mx = 1, pre = -1, tmx = 0;
    rep(i, 1, N+1){
        if(pre < q[i]){
            tmx++;
            pre = q[i];
            mx = max(tmx, mx);
        }else{
            pre = q[i];
            tmx = 1;
        }
        // cerr << "q[i] : " << q[i] << ", tmx : " << tmx << endl;
    }
    cout << N - mx << endl;
    return 0;
}

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

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

    int res = 0;
    res += 1000 * (X / 500);
    X %= 500;
    res += 5 * (X / 5);

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

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

int main()
{
	int N,ans = 0,a[200];

	cin >> N;

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

	for (int n = 0; n < N; n++) {
		if (a[n] % 2 == 0) {
			if (n == N - 1) {
				for (int i = 0; i < N; i++) {
					a[i] /= 2;
				}
				ans++;
				n = 0;
			}
		}
		else break;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256