akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stdlib.h>
using namespace std;
typedef long long int ll;
#define INF (1e9)
#define distance(x1,y1,x2,y2) sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
#define rep(i,N) for(ll i=0;i<N;i++)
using vvl=vector<vector<ll>>;
using vl=vector<ll>;
using vs=vector<string>;

bool func(vl s,vl t){
    return s[1]<t[1];
}

/*void printvl(vl v){
    rep(i,v.size()){
        cout<<i<<": "<<v[i]<<endl;}
}

void printvl2(vvl v){
    rep(i,v.size()){
        cout<<i<<": "<<v[i][0]<<" ,"<<v[i][1]<<endl;}
}*/

ll N,Y;

ll calc(){
    ll x_max=Y/10000;
    ll y_max=Y/5000;
    ll k;
    rep(i,x_max+1){
        rep(j,y_max+1){
            k=N-i-j;
            if(k>=0 && 10000*i+5000*j+1000*k==Y){
                cout<<i<<" "<<j<<" "<<k<<endl;
                return 1;
            }
         }
     }
    return 0;
}

int main(){
    cin>>N>>Y;
    ll ret=calc();
    if(!ret)
        cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;}

Measured memory_bytes: 256
K, A, B = map(int, input().split())

if B-A <= 2:
  ans = K+1
else:
  ans = A
  n = (K-A+1) // 2
  ans += (B-A) * n
  if (K-A+1) % 2 == 1:
    ans += 1
print(ans)

Measured memory_bytes: 9176
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    p=parseMap(split(readline()))
    MINs=[p[1] for i in 1:n]
    for i in 2:n
        MINs[i]=min(MINs[i-1],p[i])
    end
    ans=0
    for i in 1:n
        if p[i]<=MINs[i]
            ans+=1
        end
    end
    println(ans)
end
main()

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

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    int a = n / x;
    int b = n % x;
    if (b) {
        cout << (a + 1) * t << endl;
    } else {
        cout << a * t << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class TripleDots
{
    static void Main(string[] args)
    {
        var number  = int.Parse(Console.ReadLine());

        var word = Console.ReadLine();

        var ans = "";

        if(word.Length <= number)
        {
            ans = word;
        }
        else
        {
            for(var i = 0; i< number; i++)
            {
                ans += word[i];
            }

            ans += "...";
        }

        Console.WriteLine(ans);
        
    }
}

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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

ll M = 1e7 + 7;

ll binpow(ll a, long long b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a);
		a = (a * a);
		b >>= 1;
	}
	return res;
}

int n , m , sx , sy , ex , ey;
int dx[] = { -1 , 1 , 0 , 0};
int dy[] = { 0 , 0 , -1 , 1};
char a[1005][1005];
bool vis[1005][1005];

bool isValid(int x , int y)
{
	if (x < 0 || x >= n || y < 0 || y >= m)
		return false;
	if (vis[x][y] || a[x][y] == '#')
		return false;
	return true;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;
	cin >> sx >> sy;
	cin >> ex >> ey;
	sx-- , sy-- , ex-- , ey--;

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

	memset(vis, false, sizeof(vis));

	deque<pair<pair<int, int> , int>> q;
	q.push_back({{sx , sy} , 0});
	//vis[sx][sy] = true;
	while (!q.empty()) {

		auto p = q.front();
		int cx = p.first.first , cy = p.first.second , cost = p.second;
		//cout << cx << " " << cy << " " << cost << "\n";
		q.pop_front();

		if (vis[cx][cy]) continue;
		vis[cx][cy] = true;

		if (cx == ex and cy == ey)
		{
			cout << cost << "\n";
			return 0;
		}

		for (int i = 0 ; i < 4 ; i++)
		{
			int nx = cx + dx[i] , ny = cy + dy[i];
			if (isValid(nx , ny))
			{
				//vis[nx][ny] = true;
				q.push_front({{nx , ny} , cost});
			}

		}

		for (int i = -2 ; i <= 2 ; i++) {
			for (int j = -2 ; j <= 2 ; j++) {
				int nx = cx + i , ny = cy + j;
				if (isValid(nx , ny))
				{
					//vis[nx][ny] = true;
					q.push_back({{nx , ny} , cost + 1});
				}
			}
		}
	}

	cout << "-1\n";
	return 0;
}





Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<18;
const ll INF=1LL<<55;

int n;
pair<ll,int> dat[2*MAX-1][2];

void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<2*n-1;i++){
        dat[i][0]={INF,i-(n-1)};
        dat[i][1]={INF,i-(n-1)};
    }
}

void update(int k,ll a,int kind){
    k+=n-1;
    dat[k][kind].first=a;
    
    while(k>0){
        k=(k-1)/2;
        dat[k][kind]=min(dat[k*2+1][kind],dat[k*2+2][kind]);
    }
}

pair<ll,int> query(int a,int b,int k,int l,int r,int kind){
    
    if(r<=a||b<=l) return {INF,-1};
    if(a<=l&&r<=b) return dat[k][kind];
    else{
        pair<ll,int> vl=query(a,b,2*k+1,l,(l+r)/2,kind);
        pair<ll,int> vr=query(a,b,2*k+2,(l+r)/2,r,kind);
        return min(vl,vr);
    }
}

struct edge{
    int from;
    int to;
    ll dis;
};

bool compare(edge a,edge b){
    return a.dis<b.dis;
}

int par[MAX],size[MAX];

void initUF(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        size[i]=1;
    }
}

int root(int a){
    if(par[a]==a) return a;
    else return par[a]=root(par[a]);
}

void unite(int a,int b){
    if(root(a)!=root(b)){
        size[root(a)]+=size[root(b)];
        par[root(b)]=root(a);
    }
}

bool check(int a,int b){
    return root(a)==root(b);
}

int main(){
    
    ll N;
    ll D;cin>>N>>D;
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    
    vector<int> id(N);
    iota(all(id),0);
    sort(all(id),[&](int i,int j){
        return A[i]<A[j];
    });
    
    init(N);
    
    vector<edge> S;
    
    for(int i:id){
        auto left=query(0,i+1,0,0,n,0),right=query(i,n+1,0,0,n,1);
        if(left.first!=INF){
            S.push_back({left.second,i,A[left.second]+A[i]+D*(i-left.second)});
        }
        if(right.first!=INF){
            S.push_back({i,right.second,A[i]+A[right.second]+D*(right.second-i)});
        }
        
        update(i,D*(N-1-i)+A[i],0);
        update(i,D*i+A[i],1);
    }
    
    sort(all(S),compare);
    
    initUF(N);
    
    ll ans=0;
    
    for(edge e:S){
        int a=e.from,b=e.to;
        ll c=e.dis;
        
        if(check(a,b)) continue;
        
        ans+=c;
        unite(a,b);
    }
    
    cout<<ans<<endl;
    
}



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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long)(1e15)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');
    cerr.write(names, name-names) << " = " << arg1 << endl;
    _F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){
    in >> q.F >> q.S; return in;
}template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}

const int N = 2e3+1;
int dp[N][N], n;
vpi v;

int fun(int l, int r, int i){
    if(l == r){
        dp[l][r] = abs(r-v[i].S)*v[i].F;
        return dp[l][r];
    }
    if(dp[l][r] != -1)return dp[l][r];
    int ll = abs(r-v[i].S)*v[i].F+fun(l, r-1, i+1);
    int rr = abs(l-v[i].S)*v[i].F+fun(l+1, r, i+1);
    return dp[l][r] = max(ll, rr);
}

void solve(){
    cin >> n;
    int a;
    for(int i = 0; i < n; i++){
        cin >> a;
        v.pb({a, i});
    }
    memset(dp, -1, sizeof(dp));
    sort(rall(v));
    cout << fun(0, n-1, 0) << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(12);

    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    //freopen("error.txt", "w", stderr);
    //#endif

    //cin >> t;

    for(int i = 1; i <= t; ++i){
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

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

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n;cin>>n && n;){
		vi a(n);
		rep(i,n) cin>>a[i];

		ll res=0;
		int p=1;
		for(int i=0;i<n;){
			if(a[i]<p)
				i++;
			else if(a[i]==p){
				p++;
			}
			else{
				int c=(a[i]-1)/p;
				res+=c;
				a[i]=1;
			}
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 768
// topic8b
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    string str;
    cin>>str;
    if(str=="0"){
      break;
    }
    int sum=0;
    for(int i=0;i<(int)str.size();i++){
      sum+=str[i]-'0';
    }
    cout<<sum<<endl;
  }
  return 0;
}



Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <queue>
#include <string>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> G(n + 1, vector<int>());
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> lev(n + 1, 0);
	lev[1] = 1;
	queue<int> q;
	q.push(1);
	int l = 1;
	int cnt = 1;
	while (!q.empty()) {
		l++;
		int size = q.size();
		for (int s = 0; s < size; s++) {
			int cur = q.front();
			q.pop();
			for (auto& next : G[cur]) {
				if (lev[next] == 0) {
					lev[next] = l;
					cnt++;
					q.push(next);
				}
			}
		}
	}

	if (cnt != n) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	for (int i = 2; i <= n; i++) {
		int cur = lev[i];
		bool found = false;
		for (auto& next : G[i]) {
			if (lev[next] == lev[i] - 1) {
				cout << next << endl;
				found = true;
			}
			if (found) break;
		}
	}

	return 0;
}


Measured memory_bytes: 10276
n, a, b = (int(i) for i in input().split()) 

if (b-a)%2==0:
    print((b-a)//2)
else:
    if (n*2-b-a)%2==0:
        migi=(n*2-b-a)//2
    else:
        migi=((n*2-b-a)//2)+1
    if (b-2+a)%2==0:
        hidari=(b-2+a)//2
    else:
        hidari=((b-2+a)//2)+1
    print(min(migi,hidari))

Measured memory_bytes: 38524
// luogu-judger-enable-o2
#include<cstdio>
long long a,b,k;
main(){
    scanf("%lld%lld%lld",&k,&a,&b);
    if(k<=a)return puts("1"),0; //按思路特判
    else if(a<=b)return puts("-1"),0;   //按思路特判
    else printf("%lld\n",((k-a)/(a-b)+bool((k-a)%(a-b)))<<1|1);
    //按思路求解，此处的位运算 <<1 = *2 , |1 = +1
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll N, i;
    cin >> N >> i;

    cout << N - i + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll N; cin>>N;
    vector<ll> A(N);
    vector<ll> B(N);
    rep(i,N) cin>>B[i]>>A[i];
    ll ans=0;
    rrep(i,N){
        B[i]+=ans;
        ans+=((B[i]+A[i]-1)/A[i])*A[i]-B[i];
    }
    cout<<ans<<endl;
}


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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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 Edge = pair<int,ll>;
vector<vector<Edge>> G;

const ll INF = 1LL << 60;

int main() {
    int N,M;
    cin >> N >> M;
    G.resize(N);
    REP(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        --a; --b;
        G[a].push_back(Edge(b,-c));
    }
    
    vector<ll> dist(N,INF);
    dist[0] = 0;
    bool negative = false;
    REP(iter,2*N+1) REP(v,N) {
        if ( dist[v] >= INF/2 ) continue;
        for ( auto e: G[v] ){
            if ( chmin( dist[e.first], dist[v] + e.second )){
                if ( e.first == N-1 and iter == 2 * N ) negative = true;
            }
        }
    }
    
    if ( !negative ) cout << -dist[N-1] << endl;
    else cout << "inf" << endl;
    
    return 0;
}


Measured memory_bytes: 3700
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
	double x1, y1, x2, y2;
	cin.tie(0);
	cin >> x1 >> y1 >> x2 >> y2;

	printf("%.8f\n", sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))));
}


Measured memory_bytes: 3208
/*B - Uneven Numbers*/
#include <iostream>
using namespace std;

int main() 
{
  int n,counter=0,dig=0;
  cin >> n;

  for(int i=1; i<=n; i++)
  {
    int tmp = i;
    while( 0 < tmp )
    {
      tmp /= 10;
      dig++; 
    }
    if( dig%2 == 1 ) counter++;
    dig=0;
  }

  cout << counter << endl;
  return 0;
}


Measured memory_bytes: 256
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n; cin >> n;
    string s[n]; rep(i,n) cin >> s[i];
    map<string,int> m;
    rep(i,n){
        if(m[s[i]] != 0){
            cout << "No" << endl;
            return 0;
        }
        if(i != 0){
            if(s[i-1][s[i-1].size()-1] != s[i][0]){
                cout << "No" << endl;
                return 0;
            }
        }
        m[s[i]]++;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int a[5],b[5],i,j,hit,blow;
  while(scanf("%d",&a[0])!=EOF){
    for(i=1;i<4;i++){
      scanf("%d",&a[i]);
    }
    for(i=0;i<4;i++){
      scanf("%d",&b[i]);
    }
    hit=blow=0;
    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
	if(a[i]==b[j]){
	  if(i==j){
	    hit++;
	  }
	  else{
	    blow++;
	  }
	}
      }
    }
    printf("%d %d\n",hit,blow);
  }
  return 0;
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	const int mod = 1e9+7;

	int n;
	cin >> n;
	vector<int> c(n);
	for (auto &i : c) cin >> i;

	sort(c.begin(), c.end(), greater<int>());
	debug(c);

	vector<int> dp(n+1), p(n+1);
	p[0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		p[i] = p[i-1] * 2 % mod;
		dp[i] = ((ll)dp[i-1] * 4 + (ll)p[i-1] * p[i] % mod) % mod;
	}

	debug(dp);

	int ans = 0;
	for (int i = 0; i < n; ++i)
		ans = (ans + (ll)c[i] * 2 % mod * ((ll)p[i] * p[i] % mod + dp[i]) % mod * p[n-i-1] % mod * p[n-i-1]) % mod;
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;

const int  MAX_N = 1000000;
vector<int> prime;
bool is_prime[MAX_N + 1]; 

void eratosthenes(int n) {
    int p=0;
    for(int i=0; i<=n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<=n; i++) {
        if(is_prime[i]) {
            prime.push_back(i);
        }
        for(int j=2*i; j<=n; j+=i) is_prime[j] = false;
    }
}

int main(){
    const int n = 100000;
    eratosthenes(n);
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int l, r, count=0;
        cin >> l >> r;
        auto itr1 = lower_bound(prime.begin()+1, prime.end(), l);
        int s = distance(prime.begin(), itr1);
        auto itr2 = upper_bound(prime.begin(), prime.end(), r);
        int f = distance(prime.begin(), itr2);
        for(int j=s; j<f; j++){
            if(is_prime[(prime[j] + 1) / 2]) count++;
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 896
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))

n = ii()
d = li()

d_sort = sorted(d)
d_abc = d_sort[:n//2]
d_arc = d_sort[n//2:]

if d_abc[-1]==d_arc[0]:
    print(0)
else:
    print(d_arc[0]-d_abc[-1])

Measured memory_bytes: 14396
#include<stdio.h> 
main(){ 
    char op; 
    int a,b; 
    while(1){ 
        scanf("%d %c %d", &a, &op, &b); 
        if(op == '+') 
        printf("%d\n",a+b); 
        if(op == '-') 
        printf("%d\n",a-b); 
        if(op == '*') 
        printf("%d\n",a*b); 
        if(op == '/') 
        printf("%d\n",a/b); 
        if(op == '?') 
        break; } 
        return 0; } 






Measured memory_bytes: 2044
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;


const int N = 51;
const int W = 5001;
ll dp[N][W];
ll x[N];

int main(void){
  int n, a;
  cin >> n >> a;
  REP(i, 0, n) {
    cin >> x[i];
    x[i] -= a;
    assert (x[i] >= -50);
  }
  dp[0][2500] = 1;
  REP(i, 1, n + 1) {
    REP(j, 0, W) {
      dp[i][j] += dp[i - 1][j];
      if (j >= x[i - 1] && j - x[i - 1] < W) {
	dp[i][j] += dp[i - 1][j - x[i - 1]];
      }
    }
  }
  cout << dp[n][2500] - 1 << endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

char t[525252];
char p[525252];

int go[525252], ni[525252];
int s[525252];

int main(){
  scanf("%s%s",t,p);
  int n = strlen(t);
  int m = strlen(p);
  
  int cur = -1;
  REP(i,n){
    if(cur+1 < m && p[cur+1] == t[i]){
      cur++;
      s[cur] = i;
    }
    go[i] = cur;
  }

  if(cur != m-1){
    puts("no");
    return 0;
  }

  cur = m;
  FORR(i,0,n){
    if(cur-1 >= 0 && p[cur-1] == t[i]){
      cur--;
    }
    ni[i] = cur;
  }

  REP(i,m){
    // not use s[i]
    int pos = s[i];
    int mae = pos==0 ? -1 : go[pos-1];
    int usiro = pos==n-1 ? m : ni[pos+1];
    if(usiro-mae <= 1){
      puts("no");
      return 0;
    }
  }
  puts("yes");
  return 0;
}

Measured memory_bytes: 9964
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

result = sum(A)

for i in range(N):
    beat = min(A[i], B[i])
    A[i] -= beat 
    B[i] -= beat
    A[i + 1] -= min(A[i + 1], B[i])
    
result -= sum(A)

print(result)

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

int main(int argc, char const *argv[])
{
    int a,  b;
    cin >> a >> b;
    if(b % a == 0) {
        cout << a + b << endl;
    } else {
        cout  << b -a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  bool flag=true;
  int N,H[110000];
  cin>>N;
  for(int i=0;i<N;i++) cin>>H[i];
  H[0]--;
  for(int i=1;i<N;i++){
    if(H[i]<H[i-1]){
      flag=false;
      break;
    }else if(H[i]!=H[i-1]) H[i]--;
  }

  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 640
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <cstdint>
#include <iostream>
#include <string>

constexpr int32_t kMaxNumberOfIndex = 100;

void CallFibonacciNumber(std::istream &input_stream);

class FibonacciNumber {
 public:
  FibonacciNumber() noexcept;
  ~FibonacciNumber() noexcept;
  int32_t Calculate(const int32_t n);

 private:
  FibonacciNumber(const FibonacciNumber &obj) = delete;
  FibonacciNumber &operator=(const FibonacciNumber &obj) = delete;
  FibonacciNumber(FibonacciNumber &&obj) = delete;
  FibonacciNumber &operator=(FibonacciNumber &&obj) = delete;

 private:
  int32_t values_[kMaxNumberOfIndex];
};

void CallFibonacciNumber(std::istream &input_stream) {
  input_stream.tie(0);
  std::ios::sync_with_stdio(false);
  FibonacciNumber *fibonacci_number = new FibonacciNumber();
  try {
    int32_t n;
    input_stream >> n;
    std::cout << fibonacci_number->Calculate(n) << std::endl;
  } catch (...) {
    std::cerr << "ERROR: CallFibonacciNumber()" << std::endl;
    throw;
  }
  delete fibonacci_number;
}

// ****************************************************

FibonacciNumber::FibonacciNumber() noexcept {
  values_[0] = 1;
  values_[1] = 1;
}
FibonacciNumber::~FibonacciNumber() noexcept {}

int32_t FibonacciNumber::Calculate(const int32_t n) {
  for (int32_t index = 2; index <= n; ++index) {
    values_[index] = values_[index - 1] + values_[index - 2];
  }
  return values_[n];
}

int main(int argc, char *argv[]) {
  try {
    CallFibonacciNumber(std::cin);
  } catch (...) {
    std::cerr << "ERROR: main()" << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd>> Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod


int main(){
    ll a; cin>>a;
    ll b=a*a;
    ll c=b*a;
    cout<<a+b+c<<endl;
    
}




Measured memory_bytes: 3620
// https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_a
// +build ignore

package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	
	
	if n % 2 == 0 {
		// even
		if k <= n/2 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	} else {
		// odd
		if k <= (n+1)/2{
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}


Measured memory_bytes: 512
#include <stdio.h>
int main()
{
  char S[4];
  int i;
  
  for(i=0;i<4;i++){
    scanf("%s",&S[i]);
  }
  
  if(S[0]==S[1]&&S[1]==S[2])	printf("No");
  else	printf("Yes");
  
  return(0);
}

Measured memory_bytes: 128
# h,w = map(int,input().split())
S = input()
len_s = len(S)
ans = 'Yes'

# 奇数
for x in range(0,len_s,2):
  target = S[x]
  if target == 'L':
    ans = 'No'
  
# 偶数
for x in range(1,len_s,2):
  target = S[x]
  if target == 'R':
    ans = 'No'

print(ans)

Measured memory_bytes: 3060
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import deque, defaultdict

    h, w = map(int, readline().split())
    sr, sc = map(int, readline().split())
    gr, gc = map(int, readline().split())

    grid = [["#"] * (w + 2)]
    for _ in range(h):
        s = ["#"] + list(input()) + ["#"]
        grid.append(s)
    grid.append(["#"] * (w + 2))

    ans = 0
    que1 = deque()
    que2 = deque()
    que1.append((sr, sc))
    grid[sr][sc] = "!"

    while que1 or que2:
        while que1:
            cr, cc = que1.popleft()
            que2.append((cr, cc))

            if cr == gr and cc == gc:
                return print(ans)

            if grid[cr + 1][cc] == ".":
                que1.appendleft((cr + 1, cc))
                grid[cr + 1][cc] = "!"
            if grid[cr - 1][cc] == ".":
                que1.appendleft((cr - 1, cc))
                grid[cr - 1][cc] = "!"
            if grid[cr][cc + 1] == ".":
                que1.appendleft((cr, cc + 1))
                grid[cr][cc + 1] = "!"
            if grid[cr][cc - 1] == ".":
                que1.appendleft((cr, cc - 1))
                grid[cr][cc - 1] = "!"

        ans += 1

        while que2:
            cr, cc = que2.popleft()
            for mr in range(-2, 3):
                for mc in range(-2, 3):
                    nr = cr + mr
                    nc = cc + mc
                    if 1 <= nr <= h and 1 <= nc <= w:
                        if grid[nr][nc] == ".":
                            que1.append((nr, nc))
                            grid[nr][nc] = "!"

    return print(-1)


if __name__ == '__main__':
    main()


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll r, D, x;
    cin >> r >> D >> x;

    ll ans[10];

    ans[0] = r*x - D;
    ans[1] = r*ans[0] - D;
    ans[2] = r*ans[1] - D;
    ans[3] = r*ans[2] - D;
    ans[4] = r*ans[3] - D;
    ans[5] = r*ans[4] - D;
    ans[6] = r*ans[5] - D;
    ans[7] = r*ans[6] - D;
    ans[8] = r*ans[7] - D;
    ans[9] = r*ans[8] - D;

    rep (i, 10) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
    int getsn(long long int n)
    {
        int sum=0;
     
        while(n!=0)
        {
            sum=sum+n%10;
            n=n/10;
        }
        return sum;
    }
     
    int main()
    {
        int i, j, k, count;
        long long int x=1, n=1;
        scanf("%d", &k);
        puts("1");
        for(i=1; i<k; i++)
        {
            if((i-count)%9==0)
            {
                if(x+n>n*getsn(x+n))
                {
                    n=n*10;
                    count=0;
                }
                else
                {
                    count++;
                }
            }
            x=x+n;
            printf("%lld\n", x);
        }
        return 0;
    }

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



int main(){

  	double A,B,C,D,E,F;
  	cin >> A >> B >> C >> D >> E >>F;
	double max = 0;
  	double mmax = 0;
  	double smax = 0;
  	double a,b,c;
  	int N=100;
  	int imax = F/(A*100);
  	int jmax = F/(B*100);
  	int kmax = F/C;
  	int lmax = F/D;
  	//cout << imax<<" "<<jmax<<" "<<kmax<<" " <<lmax<<endl;
  	for(int i = 0; i <= imax ; i++){
    	for(int j = 0; j <= jmax ; j++){
        	for(int k = 0 ; k <= kmax ; k++){
            	for(int l = 0; l <= lmax ; l++){
                  	a = (A*i+B*j)*100;
                  	b = C*k+D*l;
                  	
                  	
                  	if(a!=0&&a+b<=F){
                      	c = b*100/(a+b);
                      	//cout << max << " " << c << endl;
						//cout << E/100 << " " << b/a << endl;
                    	if(max<=c&&E/100>=b/a){
                          	//cout << max << " " << c << endl;
                          	//cout << E/100 << " " << b/a << endl;
                      		max = c;
                          	mmax = a+b;
                          	smax = C*k+D*l;
                        	//cout << "Water"<<A*i*100<<":"<<B*j*100<<endl;
                      		//cout << "Suger"<<C*k<<":"<<D*l<<endl;
                    
                    	}		
             		}
                
                }
            
            }
          	
        }
    
    }

  	cout << mmax<<" "<<smax << endl;

}

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

int main(void)
{
    int a, b;
    cin >> a >> b;
    cout << a * b - (a + b - 1) << endl;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <string.h>
#pragma warning(disable:4996)

#define Max_n 51
int main()
{
	int n;
	scanf("%d", &n);

	char x[101];
	int t[Max_n];
	char s[Max_n][101];

	for (int i = 0; i != n; i++) 
	{
		scanf("%s %d", &s[i][0],&t[i]);
	}
	scanf("%s", &x[0]);
	int i = 1, j = 0;
	char tmp[101];
	while (i) 
	{
		sprintf(&tmp[0], "%s", &s[j][0]);
		i = strcmp(x, tmp);
		j++;
	}
	int a = 0;
	for (j; j != n; j++)
	{
		a = a + t[j];
	}
	printf("%d", a);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include "cmath"
#include <cstdlib>
#include <string>
#include <utility>

using namespace std;
typedef long long ll;

const ll INF = 10000000000;

struct node {
    int pointer_i;
    int pointer_j;
    int len;
};

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

    string a;
    string b;
    cin >> a;
    cin >> b;

    vector<vector<node> > dp(a.length()+1, vector<node>(b.length()+1, {0, 0, 0}));

    for (int i = 0; i < a.length()+1; i++) {
        for (int j = 0; j < b.length()+1; j++) {
            if (i == 0 || j == 0) {
                dp[i][j] = {0, 0, 0};
            } else if (a[i-1] == b[j-1]) {
                dp[i][j] = {
                        i-1,
                        j-1,
                        dp[i-1][j-1].len + 1
                };
            } else {
                if (dp[i-1][j].len > dp[i][j-1].len) {
                    dp[i][j] = {
                            i-1,
                            j,
                            dp[i-1][j].len
                    };
                } else {
                    dp[i][j] = {
                            i,
                            j-1,
                            dp[i][j-1].len
                    };
                }
            }
        }
    }

    string ans = "";
    size_t i=a.length();
    size_t j=b.length();

    while(i != 0 && j != 0) {
        if (dp[i][j].pointer_i == i-1 && dp[i][j].pointer_j == j-1) {
            ans += a[i-1];
            i -= 1;
            j -= 1;
        } else if (dp[i][j].pointer_i == i-1) {
            i -= 1;
        } else if (dp[i][j].pointer_j == j-1) {
            j -= 1;
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}

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

int main() {
    int N, W;
    cin >> N >> W;
    int w[N], v[N];
    for (int i = 0; i < N; ++i) cin >> w[i] >> v[i];

    long long dp[N + 1][W + 1];
    for (int j = 0; j <= W; ++j) dp[0][j] = 0;

    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j <= W; ++j) {
            if (j - w[i - 1] >= 0) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
            else dp[i][j] = dp[i - 1][j];
        }
    }

    cout << dp[N][W] << endl;
}


Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <utility>
#define p pair<int, int>
using namespace std;

int main(){
  int n, m, a, b;
  cin >> n >> m;
  vector<p> v;
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    v.push_back(p(a, b));
  }
  for(int i = 1; i <= n; i++){
    int cnt = 0;
    for(int j = 0; j < m; j++){
      if(v[j].first == i || v[j].second == i) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}


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

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  if ((B - A + 1) / 2 >= K){
    for (int i = A; i < A + K; i++){
      cout << i << endl;
    }
    for (int i = B - K + 1; i <= B; i++){
      cout << i << endl;
    }  
  } else {
    for (int i = A; i <= B; i++){
      cout << i << endl;
    }  
  }
}


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

int main() {
    ll N;
    cin >> N;
    ll A[300000] = {};
    rep(i,N){
        ll a;
        cin >> a;
        A[a-1]++;
    }
    vector<ll> S;
    rep(i, 300000) {
        if(A[i]!=0) S.push_back(A[i]);
    }
    sort(S.begin(), S.end());
    vector<ll> D(N+1);
    rep(i,S.size()){
        D[S[i]]++;
    }
    vector<ll> Ds(N+1, 0);
    REP(i,1, N+1){
        Ds[i] = Ds[i-1] + D[i];
    }
    vector<ll> kDs(N+1, 0);
    REP(i, 1, N+1){
        kDs[i] = kDs[i-1] + i * D[i];
    }

    vector<ll> f(N+1);
    REP(i,1,N+1){
        f[i] = (kDs[i] + i * (Ds[N] - Ds[i])) / i;
    }
    vector<ll> ans(N+1);
    ll pos = N;
    REP(i, 1, N+1){
        while(i>f[pos] && pos!=0) pos--;
        cout << pos << endl;
    }

    return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    ll N, K;
    std::cin >> N >> K;

    ll ans = 0;
    if(K == 0) {
        ans = N * N;
    }
    else {
        REP(i, N) {
            ans += (N / (i + 1)) * max(i - (K - 1), 0LL);
            ll mod = N % (i + 1);
            if(mod != 0) {
                ans += min(max(mod - (K - 1), 0LL), max(i - (K - 1), 0LL));
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void dfs(vector<vector<int>> &g, vector<bool> &used, int v, vector<int> &ans) {
    used[v] = true;
    for(int nv: g[v]) {
        if(!used[nv])  {
            dfs(g, used, nv, ans);
        }
    }
    ans.push_back(v);
}
int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<vector<int>> to(n);
    vector<vector<int>> from(n);
    rep(i,n-1+m) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        to[a].push_back(b);
        from[b].push_back(a);
    }
    vector<bool> used(n, false);
    vector<int> topo_sort(0);
    rep(v,n) {
        if(!used[v]) dfs(to, used, v, topo_sort);
    }
    vector<int> inv_topo(n);
    rep(i,n) {
        inv_topo[topo_sort[i]] = i;
    }
    rep(i,n) {
        if(from[i].size() == 0) {
            cout << 0 << endl;
            continue;
        }
        int ans = from[i][0];
        for(int v :from[i]) {
            if(inv_topo[v] < inv_topo[ans]) {
                ans = v;
            }
        }
        cout << ans+1 << endl;
    }
}


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

int main() {
    int x;
    cin >> x;
    for (int a = 1; a < 1000; ++a){
        ll a5 = 1;
        rep(i,5) a5 *=a;
        for (int b = -1000; b < 1000; ++b){
            ll b5 = 1;
            rep(i,5) b5 *= b;
            if (a5-b5 == x) {
                printf("%d %d\n", a, b);
                return 0;
            }
        }
    }
    return 0;
}

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

const int INF=1e9 + 5;
int main(){
	int n;
	cin>>n;
	int k;
	cin>>k;
	vector<int> arr(n);
	for(int i=0;i<n;i++)
		cin>>arr[i];
	vector<int> dp(n, INF);
	dp[0]=0;
	for(int i=1;i<n;i++){
		for(int j=1;j<=k;j++){
			if(i-j>=0){
				dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
			}else
				break;
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,m,x,a,i;
    cin>>n>>m>>x;
    set<int> s;
    for (i=0;i<m;i++)
    {
        cin>>a;
        s.insert(a);
    }
    int ans=n+2,tp=0;
    for (i=x-1;i>=0;i--)
    {
        if (s.find(i)!=s.end())
            tp++;
    }
    ans=min(ans,tp);
    tp=0;
    for (i=x+1;i<=n;i++)
    {
        if (s.find(i)!=s.end())
            tp++;
    }
    ans=min(ans,tp);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
				C++
				encoding: UTF-8
				Modified: <27/Jul/2019 05:48:35 PM>

				✪ H4WK3yE乡
				Mohd. Farhan Tahir
				Indian Institute Of Information Technology (IIIT), Gwalior
*/

#include <bits/stdc++.h>
#ifdef LOCAL_PROJECT
#	include <prettyprint.hpp>
#endif

using namespace std;

// clang-format off

#define         int                     long long
#define ll long long
#define         mod                    1000000007
#define         ve                     vector
#define         pb                     push_back
#define         endl                   "\n";
#define         ff                     first
#define         ss                     second
#define         pii                    pair<int, int>
#define         len(v)                 int(v.size())
#define         all(v)                 v.begin(), v.end()
#define         reset(a, b)            memset(a, b, sizeof(a));
#define         fr(i, s, n)            for (ll i = s ; i < n ; ++i)
#define         dfr(i, s, n)           for (ll i = s ; i > n ; --i)

void print (string sep = "\n") {
    cout << sep;
}

template < typename T, typename... TAIL > void print (const T& t, TAIL... tail) {
    cout << t << " ";
    print (tail...);
}

// clang-format on

signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int n;
	cin >> n;
	int a[n + 1];
	fr (i, 0, n + 1) cin >> a[i];
	int b[n];
	fr (i, 0, n) cin >> b[i];
	int ans = 0, curr = 0;

	fr (i, 0, n) {
		curr = min (a[i], b[i]);
		ans += curr;
		b[i] -= curr;
		curr = min (a[i + 1], b[i]);
		a[i + 1] -= curr;
		ans += curr;
	}
	print (ans);
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;

#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())

ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

template <class TH>
void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a)
{
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V)
{
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P)
{
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/

main()
{
  int n, i, j, w;
  cin >> n >> w;
  vector<int> a(n), b(n);
  for(i = 0; i < n; i++)
  cin >> a[i] >> b[i];

  vi dp(w + 1);
  for(i = 0; i < n; i++)
  for(j = w; j >= 0; j--)
  if(a[i] <= j)
  dp[j] = max(dp[j - a[i]] + b[i], dp[j]);
  cout << dp[w];
}

Measured memory_bytes: 1024
#include <stdio.h>

void getTotalTime( int totalTime, int* ansSec, int* ansMin );

int main( void )
{
	int totalTime;
	int moveTime;
	int i;
	int ansSec;
	int ansMin;
	
	totalTime = 0;
	for( i = 0; i < 4; i++ )
	{
		scanf( "%d", &moveTime );
		totalTime += moveTime;
	}
	getTotalTime( totalTime, &ansSec, &ansMin );
	printf( "%d\n%d\n", ansMin, ansSec );
	
	return (0);
}

void getTotalTime( int totalTime, int* ansSec, int* ansMin )
{
	*ansMin = totalTime / 60;
	*ansSec = totalTime - ( (*ansMin) * 60 );
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  int sum = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'A') {
      for(int j = s.size()-1; j > i; j--) {
        if(s[j] == 'Z') {
          sum = j+1-i;
          cout << sum << endl;
          return 0;
        }
      }
    }
  } 
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int a;
  cin>>a;
  if(a == 1){
    cout << "0" << endl;
  }
  else{
    cout << "1" << endl;
  }
  return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

struct UnionFind {
  vector<int> par;
  vector<int> sz;
  UnionFind(int n) { init(n); }

  void init(int n) {
    par.resize(n);
    sz.resize(n);
    REP(i, n) {
      par[i] = i;
      sz[i] = 1;
    }
  }

  int find(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sz[x] < sz[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
    }
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int size(int x) { return sz[find(x)]; }
};

int main() {
  int n;
  cin >> n;
  UnionFind uf(200000);
  REP(i, n) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    uf.unite(x, y + 100000);
  }
  int cnt_x[200000] = {};
  int cnt_y[200000] = {};
  REP(i, 100000) {
    cnt_x[uf.find(i)]++;
    cnt_y[uf.find(i + 100000)]++;
  }
  ll ans = 0;
  REP(i, 200000) ans += 1ll * cnt_x[i] * cnt_y[i];
  cout << ans - n << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
  	cin >> d[i];
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
  	for (int j = i + 1; j < N; j++) {
    	count += d[i] * d[j];
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int N= 1e5 + 10;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
 

int main()
{
    string a, b;
    cin >> a >> b;
    for (int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[i])
            {
                cout << "No" << endl;
                return 0;
            }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3628