akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

const int MAX_N = 8;
const int MAX_V = 10000;
const int MAX_CITY = 31;
const double INF = 1e+8;
typedef pair<int,int> P;
typedef pair<double,P> State;

struct edge{
	int to, d;
	edge(int to_, int d_){ to = to_; d = d_; };
};

// 馬車券の数
int n;
// t[i] := i 番目の馬車券の馬の数
int t[MAX_N];
// グラフ
vector<edge> G[MAX_V];
// 町の数
int V;

// 初期化
void init(){
	for(int i=0 ; i < MAX_V ; i++ ){
		G[i].clear();
	}
}

void add_edge(int u, int v, int d){
	edge e(v,d);
	G[u].push_back( e );
	e.to = u;
	G[v].push_back( e );
}

// 辿りつけるかどうか
bool search(int s, int g){
	map<int,bool> memo;
	for(int i=0 ; i < MAX_CITY ; i++ ){
		memo[i] = false;
	}
	queue<P> q;
	q.push( P(s,0) );
	
	while( !q.empty() ){
		int v = q.front().first;
		int cnt = q.front().second;
		q.pop();
		
		memo[v] = true;
		if( v == g ){
			return true;
		}
		if( cnt > n ) continue;
		
		for(int i=0 ; i < G[v].size() ; i++ ){
			int to = G[v][i].to;
			P next( to , cnt+1 );
			if( !memo[to] ){
				q.push( next );
			}
		}
	}
	return false;
}

// s : スタート, g : ゴール
double bfs(int s, int g){
	
	// d[v][bits] := 頂点 (v,bits) までの最小コスト
	double d[MAX_CITY][1 << MAX_N];
	// 訪れたかどうか
	bool visited[MAX_CITY][1 << MAX_N];
	
	// 初期化
	for(int i=0 ; i < MAX_CITY ; i++ ){
		for(int bits = 0 ; bits < (1<<MAX_N) ; bits++ ){
			d[i][bits] = INF;
			visited[i][bits] = false;
		}
	}
	
	// 頂点 : (今いる町の番号,馬車券の持っている状態)
	// 馬車券の持っている状態は bit列で表現
	// ((1<<n)-1) == 2^n -1 
	P start( s , ((1<<n)-1) );
	
	// 優先度付きキュー
	// state : ( コスト , (町番号,馬車券の状態) )
	priority_queue< State , vector<State> , greater<State> > q;
	q.push( State( 0.0 , start ) );
	d[s][(1<<n) - 1] = 0.0;
	
	// 答え
	double ans = INF;
	while( !q.empty() ){
		// 取り出す
		double now_cost = q.top().first;
		int v = q.top().second.first;
		int bits = q.top().second.second;
		P now( v , bits );
		q.pop();
		
		if( visited[v][bits] ) continue;
		visited[v][bits] = true;
		
		if( v == g ){
			ans = min( ans , now_cost );
			break;
		}
		
		for(int i=0 ; i < G[v].size() ; i++ ){
			int to = G[v][i].to;
			int dist = G[v][i].d;
			
			for(int i=0 ; i < n ; i++ ){
				// i 番目の馬車券があるとき
				if( (bits & (1 << i)) ){
					int next_bits = bits - (1 << i);
					P next( to , next_bits );
					double cost = (double) dist / t[i];
					
					if( now_cost + cost < d[to][next_bits] ){
						d[to][next_bits] = now_cost + cost;
						q.push( State( now_cost + cost , next ) );
					}
				}
			}
		}
	}
	return ans;
}

int main(){
	int m, p, s, g;
	while( cin >> n >> m >> p >> s >> g, n ){
		s--; g--;
		V = m;
		init();
		
		for(int i=0 ; i < n ; i++ ){
			cin >> t[i];
		}
		for(int i=0 ; i < p ; i++ ){
			int x, y, d;
			cin >> x >> y >> d;
			add_edge( x-1 , y-1 , d );
		}
		// ゴールに到達できるかどうか
		bool is_goal = search( s , g );
		
		if( is_goal ){
			double ans = bfs( s , g );
			if( ans == INF )
				cout << "Impossible" << endl;
			else
				cout << ans << endl;
		}else{
			cout << "Impossible" << endl;
		}
	}
}

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

typedef long long ll;
int N;
int a[23][23];
int A[23];
const ll MOD = 1e9 + 7;
ll dp[23][1<<22];
ll mmax;
ll rec(int n, int m)
{   
    
    if(dp[n][m] != -1) return dp[n][m];
    if(n == 0)
    {
        if(m == mmax) return 1;
        else return 0;
    }
    ll res = 0;
    for(int i = 0; i < N; i++)
    {   
        if(A[n - 1] >> i & 1)
        if(!(m >> i & 1)) res += rec(n - 1, m + (1 << i)) % MOD;
    }
    return dp[n][m] = res % MOD;
}


int main()
{
    cin >> N;
    for(int i = 0; i < N; i++)
    for(int j = 0; j < N; j++)
    cin >> a[i][j];
    memset(dp, -1, sizeof(dp));
    memset(A, 0, sizeof(A));

    mmax = (1 << N) - 1;

    for(int i = N; 0 < i ; i--)
    {   

        for(int j = 0; j < N; j++) A[j] += (1 << N - i) * a[i - 1][j];
    }

    cout << rec(N, 0) << endl;

}

Measured memory_bytes: 753920
#include <vector>
#include <cstdio>
#include <stack>
#include <string>
using namespace std;
const int S = (1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=(x<<3)+(x<<1)+c-'0',c=Get();
    return x;
}
int main(){
    long long marxism = -10000000000000;
    vector<stack<int> > ms;
    vector<int> dis;
    vector<long long> cf;
    vector< vector<int> > tickets;
    int shop = read(),tic = read();
    cf.assign(shop-1,0);
    tickets.assign(tic,vector<int>());
    ms.assign(tic,stack<int>());
    dis.reserve(shop);
    for (register int i = 1;i<shop;++i){
        int temp = read();
        dis.push_back(-temp);
    }
    for (register int i = 0;i<shop;++i){
        for (register int j = 0;j<tic;++j){
            int temp=read();
            tickets[j].push_back(temp);
        }
    }
    for (register int i = shop-1;i>=0;--i){
	long long result = 0;
        for (register int j = 0;j<ms.size();++j){
            int cur = tickets[j][i],prev = 0;
            while (!ms[j].empty()){
                if (cur>tickets[j][ms[j].top()]){
                    cf[ms[j].top()-1] -=(tickets[j][ms[j].top()]-prev);
                    prev = tickets[j][ms[j].top()];
                    ms[j].pop();
                }
                else{
                    cf[ms[j].top()-1] -=(cur-prev);
                    break;
                }
            }
	    result += cur;
	    if (i) cf[i-1] +=cur;
            ms[j].push(i);
        }
        marxism = max(marxism,result);
        for (register int j = i;j<shop-1;++j){
            result +=  dis[j];
            result +=  cf[j];
            marxism = max(marxism,result);
        }
    }
    printf("%lld",marxism);
}


Measured memory_bytes: 7040
#include<iostream>
#include<string>

using namespace std;

int main ()
{
    string s;
    cin>>s;
    if(s=="SUN")
        cout<<7;
    else if(s=="MON")
        cout<<6;
    else if(s=="TUE")
    cout<<5;
    else if(s=="WED")
        cout<<4;
    else if(s=="THU")
        cout<<3;
    else if(s=="FRI")
        cout<<2;
    else
        cout<<1;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
typedef long long ll;

int main()
{
    ll ans = 2020;
    ll l, r;

    scanf("%lld %lld", &l, &r);

    for (ll i = l; i <= min(l + 2019, r); i++) {
        for (ll j = i + 1; j <= min(l + 2019, r); j++) {
            ans = min(ans, (i * j) % 2019);
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 128
//********************************************************************//
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fi first 
#define se second 
#define RANGE(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DFOR(i, a, b) for(int i = a; i > b; --i)
#define DEB(x) cout << #x << ": " << x << endl
#define ALL(v) v.begin(), v.end() 
#define SORT(v) sort(ALL(v))
#define DISPV(v) { for(auto x___: v) cout << x___ << " "; cout << endl; }
#define DISPM(m) { for(auto x____: m){ cout << x____.first << ": " << x____.second << endl; } };
#define DISPMV(m) { for(auto x_____: m){ cout << x_____.first << ": " ;DISPV(x_____.second);} };
using LL = long long;
using VI = vector <int>;
using VC = vector <char>;
using VS = vector <string>;
using VL = vector <long long>;
using VVI = vector<VI>;
using VVL = vector <VL>;
using MII = map<int, int>;
using MIVI = map<int, VI>;
using MSS = map<string, string>;
using MLL = map<LL, LL>;
int READ_INT(){int temp;cin>>temp;return temp;}      // read an int
LL READ_LONG(){LL temp;cin>>temp;return temp;}      // read a long long
void mcs(VI &series, int &max_sum){                    // maximum contigous sub sum(kadane)
    int s=0;
    for(auto x: series){
        s += x;
        max_sum = max(max_sum, s);
        if(s < 0)s = 0;
    }
}
template<typename T>
T MAX(T t){ return t;}
template <typename T, typename... Args>
T MAX(T t, Args... args){ return max(t, MAX(args...)); }
const int MOD = int(1e9) + 7;
const int INF = 1e9 + 5;
const double PI = acos(-1.0); //M_PI;
const double EPS = 1e-9;
//********************************************************************//

int n, m;
MIVI adj_list, parents;
VI dp, indegree;

int distance_ending_at(int node){
    if(indegree[node] == 0)return 0;
    if(dp[node] != -1)return dp[node];
    for(auto v: parents[node])
        dp[node] = max(dp[node], 1 + distance_ending_at(v));
    return dp[node];
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> m;
    RANGE(i, m){
        int u = READ_INT(), v = READ_INT();
        adj_list[u].push_back(v);
        parents[v].push_back(u);
    }
    indegree.assign(n+1, 0);
    for(auto p: parents)indegree[p.first] = p.second.size();
    // DISPMV(parents);
    // DISPV(indegree);

    dp.assign(n+1, -1);
    for(int i = 1; i <= n; ++i)
        if(dp[i] == -1)
            dp[i] = distance_ending_at(i);

    int ans = 0;
    for(auto v: dp)ans = max(ans, v);
    cout << ans << endl;

    return 0;
}



/* complie flags
-Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector
*/

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

int main(){
  int N;
  cin >>N;
  int S=N;
  vector<int> a(N);
  int b[N+1]={0};
  bool flag=0;
  for (int i=0;i<N;i++) cin>>a[i];
  do{
    
    for (int i=N-1;i>=0;i--){
      if(a[i]==i+1){
        b[N]=i+1;
        //cout<<b[N]<<"#"<<N<<endl;
        a.erase(a.begin()+i);
        flag=0;
        N--;
        if(N==0){
          for(int k=1;k<=S;k++){
            cout<<b[k]<<endl;
          }
            return 0;
        }
        break;
      }
    }
    if(flag){
      cout<<"-1"<<endl;
      return 0;
    }
    flag=1;
      
  }
  while (N>-1);
  return 0;
}

  
      
        

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

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

    vector<int> cnt(M, 0);
    rep(person, N){
        int K;
        cin >> K;

        rep(food, K) {
            int A;
            cin >> A;
            cnt.at(A - 1)++;
        }
    }

    int ans = 0;
    rep(i, M){
        if(cnt.at(i) == N){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	string a,b;cin >> a >> b;
	int i=0;
	if(a.size()>b.size()){
		cout << "GREATER" << endl;
		return 0;
	}
	else if(a.size()<b.size()){
		cout << "LESS" << endl;
		return 0;
	}
	while(true){
		if(i==a.size() || i==b.size()){
			cout << "EQUAL" << endl;
			return 0;
		}
		if(a.at(i)==b.at(i)){
			i++;
			continue;
		}
		else if(a.at(i)-'0'<b.at(i)-'0'){
			cout << "LESS" << endl;
			return 0;
		}
		else{
			cout << "GREATER" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
# import numpy as np
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

# print(len(np.intersect1d(S, T)))
count = 0
for i in range(q):
    key = T[i]
    for j in range(n):
        if S[j] == key:
            count += 1
            break
print(count)



Measured memory_bytes: 6544
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#include <iostream>
#include <cmath>
//#define e 2.718

#define ll long long

using namespace std;

map<string,int> q;

int main()
{
    int n,m;
    cin>>n;
    string temp;
    for(int i=0;i<n;i++){
        cin>>temp;
            ++q[temp];

    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>temp;
        if(q[temp]>0){
            --q[temp];
        }

    }

    int res=0;
    map<string,int>::iterator it;
    it = q.begin();

    while(it != q.end())
    {
        //it->first;
        //it->second;
        //int max = it->second;
        res = max(res,it->second);
        it ++;
    }
    cout<<res<<endl;
    return 0;

}

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

int main() {
  string s;
  cin >> s;
  vector<int> v(4);
  rep(i,4){
    v.at(i) = s.at(i) - '0';
  }
  
  for (int bit = 0; bit < (1<<3);bit++){
    int tmp = v.at(0);
    for(int k = 0; k < 3; k++){
      if(bit & (1 << k)){
        tmp += v[k+1];
      }
      else {
        tmp -= v[k+1];
      }
    }
    if(tmp == 7){
      cout << v[0];
      for(int k = 0; k < 3; k++){
        if(bit & (1 << k)){
          cout << '+';
        }
        else {
          cout << '-';
        }
        cout << v[k+1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;


int main(){
  int N;
  cin >> N;
  int ans=N;
  for(int i=0; i<=N; i++){
    int count=0;
    int t=i;
    while(t>0){
      count += t%6;
      t /= 6;
    }
    t = N-i;
    while(t>0){
      count += t%9;
      t /= 9;
    }
    ans = min(ans,count);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

long long count(int n, vector<long long>& vct, int s) {
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
        if (vct[i] * 2 >= s) {
            int l = i;
            int r = n - 1;
            while (l < r) {
                int mid = (l + r) / 2 + 1;
                if (vct[i] + vct[mid] >= s) {
                    l = mid;
                } else {
                    r = mid - 1;
                }
            }
            cnt += 1 + 2 * (l - i);
        }
    }
    return cnt;
}

long long calculate(int n, long long m, vector<long long>& vct, vector<long long>& svct, int s) {
    long long cnt = 0;
    long long val = 0;
    for (int i = 0; i < n; i++) {
        if (vct[i] * 2 >= s) {
            int l = i;
            int r = n - 1;
            while (l < r) {
                int mid = (l + r) / 2 + 1;
                if (vct[i] + vct[mid] >= s) {
                    l = mid;
                } else {
                    r = mid - 1;
                }
            }
            val += vct[i] * 2 + 2 * (svct[l + 1] - svct[i + 1] + vct[i] * (l - i));
            cnt += 1 + 2 * (l - i);
        }
    }
    val -= s * (cnt - m);
    return val;
}

int main() {
    int n;
    long long m;
    scanf("%d %lld", &n, &m);

    vector<long long> vct = vector<long long>(n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &vct[i]);
    }
    sort(vct.rbegin(), vct.rend());

    vector<long long> svct = vector<long long>(n + 1);
    for (int i = 0; i < n; i++) {
        svct[i + 1] = svct[i] + vct[i];
    }

    long long l = 1;
    long long r = 200000;
    while (l < r) {
        int mid = (l + r) / 2 + 1;
        long long cnt = count(n, vct, mid);
        if (cnt >= m) {
            l = mid;
        } else {
            r = mid - 1;
        }
    }

    long long res = calculate(n, m, vct, svct, l);
    printf("%lld\n", res);
}

Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;
int A[200],vis[200];
int main()
{
    int i,cnt=0,n,k;
    memset(vis,0,sizeof(vis));
    scanf("%d %d",&n,&k);
    while(k--)
    {
        int d;
        scanf("%d",&d);
        for(i=1;i<=d;i++)
        {
            scanf("%d",&A[i]);
            vis[A[i]]=1;
        }
        
    }
    for(i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            cnt++;
        }
    }
    printf("%d\n",cnt);
    //system("pause");
    return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int32_t N, Y;
	cin >> N >> Y;

	for (int32_t cnt_man = 0; ; cnt_man++) {
		if (cnt_man > N || cnt_man * 10000 > Y)
			break;

		for (int32_t cnt_gosen = 0; ; cnt_gosen++) {
			if (cnt_man + cnt_gosen > N || cnt_man * 10000 + cnt_gosen * 5000 > Y)
				break;

			for (int32_t cnt_sen = 0; ; cnt_sen++) {
				int32_t total_maisu = cnt_man + cnt_gosen + cnt_sen;
				int32_t total_money =  cnt_man * 10000 + cnt_gosen * 5000 + cnt_sen * 1000;

				if (total_maisu > N || total_money > Y)
					break;

				if (total_maisu == N && total_money  == Y) {
					cout << cnt_man << " " << cnt_gosen << " " << cnt_sen << endl;
					return 0;
				}
			}
		}
	}

	cout << "-1 -1 -1" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define tam 4000
#define offset 8010
using namespace std;
typedef long long  ll;
typedef pair<int,int> ii;
typedef pair<ll,ii> iii;
typedef pair<map<ll,ll> ,ll> mi;
typedef pair<ii,ii> iiii;
typedef vector<ll> vi;
const ll MOD=1e9+7;
double val[4200];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    double tot=1.0;
    forr(i,0,n)
    {
        cin>>val[i];
        tot*=val[i];
    }
    double tot2=0;
    forr(i,0,n)
    {
        tot2+=tot/val[i];
    }
    printf("%.6lf",tot/tot2);
}


Measured memory_bytes: 256
function Main(input){
	input = input.split("\n")[0];
  var len = input.length;
  var pointer = 0;
  var counter = 0;
  var lastBlack = len;
  for(var i = len - 1; i >= 0 ; i--){  
  	if(input[i] == "B"){
      counter += (lastBlack - i - 1);
      lastBlack = lastBlack - 1;
    }
  }
  return counter;
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
BWBBW
`);

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(1000001, 0);
    ll sum = 0;
    rep(i, n)
    {
        int t;
        cin >> t;
        ++a[t];
        sum += t;
    }
    int q;
    cin >> q;
    while (q--)
    {
        int b, c;
        cin >> b >> c;
        a[c] += a[b];
        sum += (c - b) * a[b];
        a[b] = 0;
        cout << sum << endl;
    }
}

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

using namespace std;

int main()
{
  int ans = 0;
  string W, T;

  cin >> W;

  for (int i = 0; i < W.size(); i++)
  {
    if (isupper(W[i]))
      W[i] = tolower(W[i]);
  }

  while (true)
  {
    cin >> T;

    if (T == "END_OF_TEXT")
    {
      break;
    }

    for (int i = 0; i < W.size(); i++)
    {
      if (isupper(T[i]))
        T[i] = tolower(T[i]);
    }

    if (W == T)
      ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3172
#include <stdio.h>

#define N 100

int main(void){

  int i,j,n,mini,temp,c=0;
  int arr[N];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&arr[i]);
  }

  for(i=0;i<n-1;i++){
    mini = i;
    for(j=i+1;j<n;j++){
      if(arr[j] < arr[mini]){
	mini = j;
      }
    }
    if(i !=mini){
      temp = arr[i];
      arr[i] = arr[mini];
      arr[mini] = temp;
      c++;
    }
  }

  for(i=0;i<n;i++){
    printf("%d",arr[i]);
    if(i != n-1) printf(" ");
  }

  printf("\n%d\n",c);

  return 0;

}



Measured memory_bytes: 2140
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N; 
    cin >> N;
    int ans = 0;
    REP(x, 1, N) {
        int y = N - x;
        if (y > 0 && x > 0 && x < y) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vi cnt(N + 1);
    rep(i, M) {
        int u, v;
        cin >> u >> v;
        cnt[u]++;
        cnt[v]++;
    }

    rep(i, N + 1)if (cnt[i] & 1) {
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;
}


Measured memory_bytes: 640
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

const ll INF=1e15;

int main(){
    string s;
    cin >> s;
    ll n=s.length();
    if(s[n-1]=='s') s+="es";
    else s+='s';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	vi v;
	while(n > 0) {
		v.pb(n % 10);
		n /= 10;
	}
	for(auto it : v) {
		if(it == 7) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";

	return 0;
}

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

using namespace std;

#define f first
#define s second
#define pub push_back
#define pob pop_back
	
typedef vector<int> vi;
typedef vector<vi> graf;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> wgraf;

typedef vector<double> vd;
typedef pair<double,double> dd;
typedef vector<dd> vdd;

typedef uint64_t ui64;

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

	int n;
	string s;

	cin >> n >> s;

	if(n%2){
		cout << "No" << endl;
		return 0;
	}

	for(int i = 0; i < n/2; i++){

		if(s[i] != s[i + (n/2)]){
			cout << "No" << endl;
			return 0;
		}

	}
	
	cout << "Yes" << endl;

	return 0;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    cout << setprecision(20);
    ll n;
    cin >> n;
    string s;
    cin >> s;

    rep(i, s.length()){
        s[i] = 'A' + (s[i]-'A'+n)%26;
    }
    cout << s << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
if n == 1:
    ans = max(0, v[0])
else:
    ans = 0 if k < n else sum(v)
    for i in range(min(k + 1, n)):
        for j in range(i + 1):
            t = v[:j]
            if j != i:
                t += v[j - i:]
            t.sort()
            for p in range(k - i):
                if len(t) > 0 and t[0] < 0:
                    t.pop(0)
                else:
                    break
            if len(t) == 0:
                t = [0]
            ans = max(ans, sum(t))
print(ans)


Measured memory_bytes: 3192
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}


int main() {
	ll N, K, Q;
	cin >> N >> K >> Q;

	vi A(N, 0);
	rep(i, Q) {
		ll a;
		cin >> a;
		a--;
		A[a]++;
	}

	rep(i, N) {
		if (K - (Q - A[i]) > 0) {
			Yes();
		}
		else {
			No();
		}
	}
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int p_MAX = 1100000;
vector<int> prime;
int calc_prime()
{
  bool notPrime[p_MAX];
  int n = sqrt(p_MAX)+1;
  notPrime[0]=1;
  notPrime[1]=1;
  for(int i=0;i<=n;i++){
    if(notPrime[i])
      continue;
    int m = p_MAX/i;
    for(int j=2;j<=m;j++)
      notPrime[j*i]=1;
  }
  prime.clear();
  for(int i=0;i<p_MAX;i++)
    if(!notPrime[i])
      prime.push_back(i);
  return 0;
}
int main()
{
  long long n,m,i,t,s,res=0;
  cin >> n;
  calc_prime();
  m=prime.size();
  for(i=0;i<m;i++){
    if(n<prime[i])
      break;
    t=0;
    while(n%prime[i]==0){
      n/=prime[i];
      t++;
    }
    if(t==0)
      continue;
    s=sqrt(2*t);
    if(s*(s+1)<=2*t)
      res+=s;
    else
      res+=s-1;
  }
  if(n>1)
    res++;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4592
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int X,Y;
	cin>>X>>Y;
	double A=(Y-2.0*X)/2.0;
	double C=(4*X-Y)/2.0;
	if (A<0 || C<0){
		cout<<"No"<<endl;
		return 0;
	}
	if ((int)A==A && (int)C==C){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3124
def main():
    import numpy as np

    N, K = map(int, input().split())
    H = np.array(list(map(int, input().split())) + [0] * (K + 2), dtype = np.int64) 

    INF = 10 ** 9
    cost = np.array([INF] * (N + K + 2), dtype = np.int64)
    cost[0] = 0

    n_minimum = np.minimum
    n_abs = np.abs

    for i in range(N):
        cost[i + 1: i + K + 1] = n_minimum(cost[i + 1: i + K + 1], cost[i] + n_abs(H[i + 1: i + K + 1] - H[i]))


    # print (cost)
    print (cost[N - 1])
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 22852
#include <iostream>
#include <string>

using namespace std;

int main(void){
  string S;
  cin >> S;

  int ans = 0;
  for(int i =0;i<4;i++){
    if(S[i] == '+'){
      ans++;
    }else {
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string> //これがないと、cinでstring型が使えないという謎発見

using namespace std;


//わざわざクラス作るの大変なので構造体(別のファイルにできないし)
//using namespace std; よりも前に書いちゃうと、stringとかにstd::string とかわざわざ指定しないと使えないので注意
typedef  struct Process_temp {
	int time_slot;
	string quantum;
} Process;

int main() {
    int i;
    int n,q;
	int time_count;
    /*
    大した大きさでないので、ポインタ配列でなくそのまま
    qu.push(buf)の代入時に毎回丸ごとコピーされるので、元の変数は使いまわせる
    */
    queue<Process> qu;
    
    cin >> n;
    cin >> q;
    for(i=0;i<n;i++){
        Process buf;
		cin >> buf.quantum;
        cin >> buf.time_slot;
        qu.push(buf); //bufのコピーが格納される　（自動で新領域確保）
    }

	time_count=0;
	while(!qu.empty()){
		if( qu.front().time_slot - q <= 0 ){
			time_count += qu.front().time_slot;
			cout << qu.front().quantum << ' ' << time_count << endl;
			qu.pop();
		}
		else {
			time_count+=q;

			Process buf;
			buf.quantum = qu.front().quantum;
			buf.time_slot = qu.front().time_slot - q;
			qu.push(buf);
			qu.pop();
		}

	}

	return 0;
}

Measured memory_bytes: 4404
##### https://atcoder.jp/contests/abc174/submissions/15644075 を1次元化

import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.buffer.readline().rstrip()
 
class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit
 
    def __getitem__(self, i):
        return self._tree[i + self._n]
 
    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])
 
    def add(self, i, v):
        self.update(i, self[i] + v)
 
    def sum(self, l, r):
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

from operator import add
def resolve():
    n, q = map(int, input().split())
    C = list(map(lambda x : int(x) - 1, input().split()))
 
    A = [0] * n
    used = [0] * n
    for i, c in enumerate(C):
        if used[c]:
            continue
        used[c] = 1
        A[i] = 1
    tree = SegmentTree(A, add, 0)
 
    next = [-1] * n
    used = [-1] * n
    for i in range(n - 1, -1, -1):
        c = C[i]
        if used[c] != -1:
            next[i] = used[c]
        used[c] = i
 
    queries = [None] * q
    for i in range(q):
        l, r = map(int, input().split())
        queries[i] = (l - 1 << 40) + (r << 20) + i
    queries.sort(reverse = 1)
    
    m = (1 << 20) - 1
    ans = [0] * q
    for l in range(n):
        while queries and queries[-1] >> 40 == l:
            lri = queries.pop()
            l = lri >> 40
            r = (lri >> 20) & m
            i = lri & m
            ans[i] = tree.sum(l, r)
        if next[l] != -1:
            tree.add(next[l], 1)
 
    print(*ans, sep = '\n')
resolve()

Measured memory_bytes: 175860
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll mod = 1e9+7;
struct edge{
    int to;
    int cost;
    edge(int a = 0, int b = 0):to(a),cost(b){}
};
vector<ll> dijkstra(const int s,const vector<vector<edge>>&g){
    int n = (int)g.size();
    vector<ll> dist(n+1,1L<<60);
    using ll_i = pair<ll,int>;
    priority_queue<ll_i,vector<ll_i>,greater<ll_i>>pq;
    dist[s] = 0;
    pq.push({dist[s], s});
    while(!pq.empty()){
        auto a = pq.top();
        pq.pop();
        int v = a.second;
        if(a.first > dist[v])continue;
        for(auto &x:g[v]){
            if(dist[x.to] > dist[v] + x.cost){
                dist[x.to] = dist[v] + x.cost;
                pq.push({dist[x.to], x.to});
            }
        }
    }
    return dist;
}
void dfs(int s, vector<bool>&used, vector<vector<edge>>&g,vector<ll>&dp){
    used[s] = true;
    for(auto &x:g[s]){
        if(!used[x.to]){
            dfs(x.to,used,g,dp);
        }
        dp[s] = (dp[s] + dp[x.to]) % mod;
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    int s, t;
    cin >> n >> m >> s >> t;
    vector<vector<edge>>g(n+1);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        int c;
        cin >> c;
        g[a].emplace_back(b,c);
        g[b].emplace_back(a,c);
    }
    auto dist = dijkstra(s, g);
    auto dist2 = dijkstra(t, g);
    vector<vector<edge>>graph(n+1), rgraph(n+1);
    rep(i,n){
        for(auto &x:g[i+1]){
            if(dist[i+1] + x.cost + dist2[x.to] == dist[t]){
                graph[i+1].emplace_back(x.to,x.cost);
                rgraph[x.to].emplace_back(i+1,x.cost);
            }
        }
    }
    vector<ll>dp(n+1),dp2(n+1);
    dp[s] = 1;
    dp2[t] = 1;
    vector<bool>used(n+1,false);
    dfs(t,used,rgraph,dp);
    fill(used.begin(),used.end(),false);
    dfs(s,used,graph,dp2);
    ll ans = 0;
    assert(dp[t] == dp2[s]);
    ans += dp[t] * dp2[s] % mod;
    ans %= mod;
    rep(i,n){
        if(dist[i+1] * 2 == dist[t]){
            ans -= dp[i+1] * dp2[i+1] % mod * dp[i+1] % mod * dp2[i+1] % mod;
            ans = (ans + mod) % mod;
        }
    }
    rep(i,n){
        for(auto &x:graph[i+1]){
            int from = i + 1;
            int to = x.to;
            int cost = x.cost;
            if(dist[from] * 2 < dist[t] and dist2[to] * 2 < dist[t] and (dist[from] + cost) * 2 > dist[t] and (dist2[to] + cost) * 2 > dist[t]){
                ans -= dp[from] * dp2[to] % mod * dp[from] % mod * dp2[to] % mod;
                ans = (ans + mod) % mod;
            }
        }
    }
    assert(ans>=0);
    cout << ans << endl;
}

Measured memory_bytes: 28704
#include <iostream>

int main(){
	int A,B,C;
	std::cin >> A >> B >> C;
	if(A>=B && A>=C){
		std::cout << A*10+B+C << std::endl;
	}else if(B>=C && B>=A){
		std::cout << B*10+A+C << std::endl;
	}else{
		std::cout << A+B+C*10 << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <bitset>
#include <regex>
#include <cassert>
#include <set>
#include <map>
using namespace std;
#define inf 2000000000
#define mod 1000000007

long long ans,r,g,b;
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	string s;
	cin >> s;
	for(int i=0;i<n;i++){
		if(s[i] == 'R') r++;
		else if(s[i] == 'G') g++;
		else b++;
	}
	ans = r*b*g;
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			long long k = j+j-i;
			if(k>=n) continue;
			if((s[i] != s[j]) && (s[j] != s[k]) && (s[i] != s[k])) ans--;
		}
	}
	cout << ans;
}

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

int main()
{
    int N;
    int T[1000] = {0};
    int A[1000] = {0};

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

    long long a = 1LL;
    long long b = 1LL;
    for (int i = 0; i < N; i++)
    {
        long long tmp_a, tmp_b;
        if (a % T[i] == 0)
        {
            tmp_a = a / T[i];
        }
        else
        {
            tmp_a = a / T[i] + 1;
        }
        if (b % A[i] == 0)
        {
            tmp_b = b / A[i];
        }
        else
        {
            tmp_b = b / A[i] + 1;
        }
        long long n = max(tmp_a, tmp_b);
        a = n * T[i];
        b = n * A[i];
    }

    cout << a + b << endl;

    return 0;
}

Measured memory_bytes: 256
def kaibun(s):
  l=len(s)
  if(l%2==0):
    for i in range(l//2):
      if(s[i]!=s[l-1-i]):
        return 0
    return 1
  else:
    for i in range((l-1)//2):
      if(s[i]!=s[l-1-i]):
        return 0
    return 1

s=input()
l=len(s)
if(l%2==0):
  print("No")
else:
  if(kaibun(s[:((l-1)//2)])*kaibun(s)):
    print("Yes")
  else:
    print("No")

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

// Preparing for IOI 2018

using namespace std;

const int inf = (int) 1e9 + 7;
const int N = (int) 1e5 + 7;
const double PI = 3.141592653589793238462643;
const double eps = 0.000000001;

#define ok puts("OK");
#define ll long long
#define fr first
#define sc second
#define eb emplace_back
#define sz(s) ((int)s.size())
#define all(s) s.begin(), s.end()

inline void solve () {
	int x, a, b; scanf ("%d %d %d", &x, &a, &b);
	int dis = abs(x - a);
	int diss = abs(x - b);
	if (dis < diss) {
		puts("A");
	} else if (dis > diss) {
		puts("B");
	}
}

int test = 1;

main () {
        // freopen("example.in", "r", stdin); freopen("example.out", "w', stdout);
        // scanf ("%d", &test);
        while (test--) {
                solve();
        }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,k;
  string s;
  cin >>n;
  cin >>s;
  cin >>k;
  for(ll i=0;i<n;i++){
    if(s[i]!=s[k-1]) cout <<"*";
    else cout <<s[i];
  }
  cout <<endl;
}


Measured memory_bytes: 256
// Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int w;
		cin >> w;

		if(w==-1)
			break;

		int bil;
		if(w<=10){
			bil = 1150;
		}
		else if(w<=20){
			bil = 1150+(w-10)*125;
		}
		else if(w<=30){
			bil = 1150+10*125+(w-20)*140;
		}
		else{
			bil = 1150+10*125+10*140+(w-30)*160;
		}

		cout << 4280-bil << '\n';
	}

	return 0;
}

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

int main() {
  long long x,k,d;
  cin>>x>>k>>d;
  long long need=abs(x)/d;
  if(abs(x)%d>(d/2))
    need++;
  if(need>=k)
    cout<<abs(abs(x)-k*d)<<endl;
  else
    if((k-need)%2LL==0LL)
      cout<<abs(abs(x)-need*d)<<endl;
    else
      cout<<abs(abs(abs(x)-need*d)-d)<<endl;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n,k;cin>>n>>k;
    string s;cin>>s;
    vi v,ans;v.pb(0);
    rep(i,n)if(s[n-i-1]=='0')v.pb(i+1);
    n=v.size();
    ll w=0;
    while(w<n-1){
        ll u=ub(v,v[w]+k)-1;
        if(u>w)ans.pb(v[u]-v[w]);
        else{
            cout<<-1<<endl;
            return 0;
        }
        w=u;
    }
    reverse(all(ans));
    outvi(ans);
}

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

int main() {
	int a, b;
	cin >> a >> b;
	string r;
	if (0 < a) {
		r = "Positive";
	} else if (0 <= b) {
		r = "Zero";
	} else {
		r = ((b - a + 1) % 2 ? "Negative" : "Positive");
	}
	cout << r << endl;
	return 0;
}


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

using ll = long long;

ll N;
ll a[1111], b[1111];

int main() {
   cin >> N;
   for (int i = 0; i < N; i++) cin >> a[i] >> b[i];

   ll n = 1;
   ll x = 1, y = 1;
   for (int i = 0; i < N; i++) {
      if (i == 0) {
         n = 1;
      } else {
         n = max((a[i-1]*n + a[i]-1) / a[i], (b[i-1]*n + b[i]-1) / b[i]);
      }
      x = a[i] * n;
      y = b[i] * n;
   }
   cout << x + y << endl;

   return 0;
}

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

#define ll long long int

using namespace std;

void find_all_primes(ll	n, vector <ll> &primes) {
	for (ll i = 2; i <= n; i++) {
		bool tf = true;
		for (ll j = 0; j < primes.size(); j++) {
			if (primes[j] * primes[j] > i)
				break;
			if (i % primes[j] == 0) {
				tf = false;
				break;
			}
		}
		if (tf)
			primes.push_back(i);
	}
}

int main() {
	ll n;
	cin >> n;
	vector <ll> primes;
	find_all_primes(120000, primes);
	for (int i = 0; i < primes.size(); i++)
		if (primes[i] >= n) {
			cout << primes[i];
			return 0;
		}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

/*50 以下の正の整数 n を入力し、0 〜 9 の範囲の整数 a,b,c,d の組で
a+b+c+d=n
を満たすものの組み合わせ数を出力するプログラムを作成して下さい。
例えば、n が 35 のとき、(a,b,c,d) の組み合わせは (8,9,9,9)、(9,8,9,9)、(9,9,8,9)、(9,9,9,8) の 4 通りとなります。*/

/*input*/
/*複数のデータセットが与えられます。
各データセットに n (1 ≤ n ≤ 50) が１行に与えられます。
入力の最後まで処理して下さい。データセットの数は 50 を超えません。*/

/*output*/
/*各データセットごとに、a,b,c,d の組み合わせ個数を１行に出力して下さい。*/


int combinationCount(int, int);
bool inputAndJadgeEOF(int& n);

int main(){

	int n;  //入力される正の整数
	int life = 4;  //組み合わせる数字の数

	while (inputAndJadgeEOF(n)){
		std::cout << combinationCount(n, life) << std::endl;
	}
}

//組み合わせの個数を返す関数
//入力:n 数字の組み合わせで表現する数
//入力:life 組み合わせに使える数字の個数
//出力:組み合わせの数
int combinationCount(int n, int life){

	if (static_cast<double>(n) / life > 9){
		return 0;
	}

	if (n < 0){  //nが0以下なら表現不可
		return 0;
	}
	if (life == 1){  //残りの数字が一つなら
		if (n < 10 && n > -1){  //0~9の範囲内なら、組み合わせが一つできる
			return 1;
		}
		else{  //0~9の範囲外なら表現不可
			return 0;
		}
	}

	int count = 0; //組み合わせの総数 
	for (int i = 0; i <= 9; i++){  //1~9までの数字で調査
		count += combinationCount(n - i, life - 1);  //一つの数字を固定した場合の、組み合わせの総数
	}
	return count;
}

bool inputAndJadgeEOF(int& n){
	if (std::cin >> n){
		return true;
	}
	else{
		return false;
	}
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,k;
  cin>>N>>k;
  int bo=0,l=1;
  for(int i=1;i<N;i++){
    int j;
    cin>>j;
    if((j<k && bo==1)||(j>k && bo==-1)){
      l++;
      bo=0;
    }
    else{
      if(j<k)
        bo=-1;
      if(j>k)
        bo=1;
    }
    k=j;
  }
  cout<<l<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<59)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed); cerr.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed); cerr.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int n;
	cin>>n;
	if((n%10) == 3)
	cout<<"bon\n";
	else if(((n%10) == 0) || ((n%10) == 1) || ((n%10) == 6) || ((n%10) == 8))
	cout<<"pon\n";
	else cout<<"hon\n";
	return;	
}

int main(void)
{
	FLASH();
	//freopen("cowjog.in", "r", stdin);
	//freopen("cowjog.out", "w", stdout);
	int T;
	T = 1;

#ifndef ONLINE_JUDGE
	time_t time_t1, time_t2;
	time_t1 = clock();
#endif

	//cin>>T;
	while(T--)
	solve(T);

#ifndef ONLINE_JUDGE
	time_t2 = clock();
	SETF();
	cerr<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
	UNSETF();
#endif

	return 0;
}

Measured memory_bytes: 3612
N,K=map(int,input().split())
S=input()
First=S[0]
Now=First
cnt=0
A=[0]
for s in S:
    if Now=='1' and s=='0':
        A+=[cnt]
        Now='0'
    elif Now=='0' and s=='1':
        A+=[cnt]
        Now='1'
    cnt+=1
A+=[N]
dp=2*K+1
ans=[]

if First=="0":
    p=1
    ans.append(A[min(dp-1,len(A)-1)])
else:
    p=0
    ans.append(A[min(dp,len(A)-1)])

while p+dp<len(A):
	ans.append(A[p+dp]-A[p])
	p+=2
ans.append(N-A[p])
#print(A)
print(max(ans))

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

int main () {

    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll sum= 0;

    if(k > a) {
        sum+=a;
        k-=a;
    } else {
        sum+=k;
        k=0;
    }

    k -= b;

    if (k>0) {
        sum-=k;
    }
    
    cout << sum;
    return 0;
}

Measured memory_bytes: 3596