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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

#define INF (ll)(1e9+7)

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll n; ll k;
    cin >> n >> k;
    vll nums(n);
    FOR(i, n) cin >> nums[i];
    vll dp(n, INF);
    dp[0] = 0;
    FORN(i, 1, n)
    {
        dp[i] = abs(nums[i] - nums[i - 1]) + dp[i - 1];
        for (ll j = 1; j <= k && i - j >= 0; j++) dp[i] = min(dp[i], abs(nums[i] - nums[i - j]) + dp[i - j]);
    }
    cout << dp[n - 1] << '\n';
}



Measured memory_bytes: 1792
from functools import reduce 
def solve():
    mod = 10 ** 9 + 7
    n, a, b = map(int, input().split())
    all_comb = pow(2, n, mod) - 1

    X = reduce(lambda x,y:x*y%mod, list(range(n-a+1, n+1))) 
    Y = reduce(lambda x,y:x*y%mod, list(range(1,a+1)))
    Y = pow(Y, mod-2, mod)
    a_comb = X * Y % mod

    X = reduce(lambda x,y:x*y%mod, list(range(n-b+1, n+1))) 
    Y = reduce(lambda x,y:x*y%mod, list(range(1,b+1)))
    Y = pow(Y, mod-2, mod)
    b_comb = X * Y % mod

    ans = all_comb - a_comb
    ans %= mod
    ans -= b_comb
    ans %= mod
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 45552
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

vector<pint> list;










void floyd(int N, ll** d) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}


ll vis[100005];
ll d[100005];
vector<ll> M[100005];
vector<ll> anslist;


stack<int> to_1;

ll col[100005];

void dfs(ll K, ll dist) {

	
	d[K] = dist;
	vis[K] = 1;

		
	for (int i = 0; i < M[K].size(); i++) {
		if (vis[M[K][i]] == 0) {
			
			dfs(M[K][i], dist + 1);
			
		}
	}

}




string S;
ll D[2 * 100005];
int main() {

	cin >> S;

	for (int i = S.size() - 1; i >= 0; i--) {
	  
		if (S[i] == 'W')
			D[i] = D[i + 1] + 1;
		else
			D[i] = D[i + 1];

	}
	ll ans = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'B') {
			ans += D[i];
		}
	}

	cout << ans << endl;
}

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

int main(){
  int a, b, c, k, ans = 0;

  cin >> a >> b >> c >> k;

  if(k <= a){
    ans = k;
  }else if(k > a && k <= b){
    ans = a;
  }else{
    ans = a - (k - a - b);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
struct Node
{
    int x,y;
    friend bool operator <(Node a,Node b)
    {
        return a.y>b.y;
    }
}e[maxn];
bool vis[maxn];
int n,k,tot;
ll x;
ll ans,sum;
stack<int>s;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d%d",&e[i].x,&e[i].y);

    sort(e+1,e+1+n);
    for(int i=1;i<=n;i++)
    {
        if(tot<k)
        {
            if(!vis[e[i].x])
            {
                x++;
            }
            else
            {
                s.push(e[i].y);
            }
            sum+=e[i].y;
            ans=max(ans,x*x+sum);
            vis[e[i].x]=true;
            tot++;
        }
        else
        {
            if(s.empty()) break;
            if(vis[e[i].x]) continue;
            vis[e[i].x]=true;
            x++;
            sum+=e[i].y;
            int l=s.top();
            s.pop();
            sum-=l;
            ans=max(ans,sum+x*x);
        }
    }
    printf("%lld\n",ans);
}


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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int main() {
    string N;
    cin >> N;
    bool ok = false;
    for (const auto& c : N) {
        if (c == '7') {
            ok = true;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

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

int main() {
    int n, m, a, b, x;
    cin >> n >> m;
    set<int> s;
    vector<int> t;
    bool flag=false;
    for(int i=0; i<m; i++) {
        cin >> a >> b;
        if(a==1) s.insert(b);
        if(b==n) t.push_back(a);
    }
    for(int i=0; i<t.size(); i++) {
        x=t[i];
        if(s.count(x)) {
            flag=true;
            break;
        }
    }
    if(flag) cout <<"POSSIBLE";
    else cout << "IMPOSSIBLE";
}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
int uf[maxn], zero[maxn], one[maxn];
int find(int x){
	return x == uf[x] ? x : uf[x] = find(uf[x]);
}
long long ans = 0;
int join(int x, int y){
	x = find(x);
	y = find(y);
	assert(x ^ y);
	ans += 1ll * one[x] * zero[y];
	zero[x] += zero[y];
	one[x] += one[y];
	uf[y] = x;
	return x;
}
int par[maxn];
int main(){
	iota(uf, uf + maxn, 0);
	int n; cin >> n;
	for(int i = 2; i <= n; i++) cin >> par[i];
	for(int i = 1; i <= n; i++){
		int x; cin >> x;
		if(x) one[i] = 1;
		else zero[i] = 1;
	}
	struct cmp {
		bool operator ()(int a, int b){
			long long vala = 1ll * one[a] * zero[b];
		        long long valb = 1ll * one[b] * zero[a];
			if(vala != valb)
				return vala < valb;
			return a < b;
		}
	};
	set<int, cmp> pq;
	for(int i = 2; i <= n; i++) pq.insert(i);
	for(int i = 2; i <= n; i++){
		int top = *pq.begin(); pq.erase(pq.begin());
		int ptop = find(par[top]);
		if(ptop != 1) pq.erase(ptop);
		join(ptop, top);
		if(ptop != 1) pq.insert(ptop);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 12800
//LinearSearch

#include<iostream>
#include<stdio.h>


using namespace std;

#define MAX_N 10100
#define MAX_Q 510


bool Search(int A[],int n,int key)
{
    /*
        A[] : 探索する配列
        n : Aの要素数
        key : 探索対象の値
    */
   A[n]=key;
   int i=0;

   while(A[i]!=key)
   {
       i++;
   }
   return i!=n;

}


int main(){
    int i,n,q,key,sum=0;
    int S[MAX_N];

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&S[i]);
    }

    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&key);
        if(Search(S,n,key)) sum++;
    }

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

    return 0;

}



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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){for(int i=0;i<n;i++) cin>>f[i];}

template<typename T,typename U>
void Printarray(T f,U n){for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];}
template<typename T,typename U>
void Printarray2(T f,U n){for(int i=0;i<n;i++) cout<<f[i]<<endl;}
template<typename T,typename U,typename V>
void Printarray3(T f,U a,V b){
  rep(i,a){
    rep(j,b){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}
template<typename T,typename U>
void Printarray4(T f,U n){
  rep(i,n){
    rep(j,n){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}

void flagfunc(bool flag,string A,string B){flag ? cout<<A<<endl : cout<<B<<endl;}
void flag2func(bool flag){flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;}
void flag3func(bool flag){flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n;cin>>n;
  vector<int> a(n,0);
  int b;
  rep(i,n-1){cin>>b;a[b-1]++;}
  Printarray2(a,n);
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;
ll INF = 1000000009;



void solve(){
    string s,t;
    cin >> s >> t;
    int sizes = s.size();
    int sizet = t.size();
    int repeat = sizes-sizet+1;
    //例えば|S|=5,|T|=2なら、i=0~3.
    //i=0~sizes-sizetまで繰り返したものを格納
    vector<string> a;
    rep(i,repeat){
        bool b=true;
        rep(j,sizet){
            if(s[i+j]!='?'&&s[i+j]!=t[j]){
                b=false;
            }
        }
        string tmp=s;
        if(b) {
            rep(j,sizes){
                if(j<i){
                    if(s[j]=='?') tmp[j]='a';
                }
                else if(i+sizet<=j) {
                    if(s[j]=='?') tmp[j]='a';
                }
                else{
                    tmp[j]=t[j-i];
                }
            }
            a.emplace_back(tmp);
        }
    }
    sort(a.begin(), a.end());
    if(a.size()==0) cout << "UNRESTORABLE" << endl;
    else cout << a[0] << endl;
}

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


Measured memory_bytes: 256
N, A, B, C=map(int, input().split())
l=[int(input()) for i in range(N)]

def ten2four(x, n):
  output=str()
  for i in range(n-1, 0, -1):
    output+=str(x//(4**i))
    x=x%(4**i)
    
  output+=str(x)
  return output

p=4**N
minmp=abs(A-l[0])+abs(B-l[1])+abs(C-l[2])
for i in range(p):
  tempa=0
  tempb=0
  tempc=0
  tempmp=0
  
  pat=ten2four(i, N)
  
  x=sum([pat[j]=='1' for j in range(N)])
  y=sum([pat[j]=='2' for j in range(N)])
  z=sum([pat[j]=='3' for j in range(N)])
  
  if x>0 and y>0 and z>0:
    for j in range(N):
      if pat[j]=='1':
        tempa+=l[j]
      elif pat[j]=='2':
        tempb+=l[j]
      elif pat[j]=='3':
        tempc+=l[j]
      else:
        pass
      
    tempmp=10*(x+y+z-3)+abs(A-tempa)+abs(B-tempb)+abs(C-tempc)

    if minmp>tempmp:
      minmp=tempmp
            
print(minmp)

Measured memory_bytes: 71384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define LL long long;

int a[3];

int main(){

	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);

	cout << a[0] + a[1] << endl;

	return 0;
}

Measured memory_bytes: 256
s = input()
small = 'abcdefghijklmnopqrstuvwxyz'
large = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = ''
for i in s:
    q = 0
    while q < 26:
        if i == small[q]:
            ans += large[q]
            break
        elif i == large[q]:
            ans += small[q]
            break
        q += 1
    if q == 26:
        ans += i
print(ans)


Measured memory_bytes: 5556
#include <iostream>
#include <vector>
#include <set>

using namespace std;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		if(root_i > root_j) root_i ^= root_j, root_j ^= root_i, root_i ^= root_j;
		parent[root_i] = root_j;
	}
};

int N, V;
int x[200005];
int v[20], vnum;
UnionFind uf[20];
int dp[1<<18];

int main(void)
{
	cin >> N >> V;
	for(int i = 1; i <= N; i++) cin >> x[i];
	
	int tmp = V;
	for(int i = 0; ; i++){
		v[i] = tmp;
		if(tmp == 0){
			vnum = i+1;
			break;
		}
		tmp /= 2;
	}
	
	for(int i = 0; i < vnum; i++) uf[i] = UnionFind(N);
	for(int i = 0; i < vnum; i++){
		for(int j = 1; j < N; j++){
			if(x[j+1] - x[j] <= v[i]) uf[i].unite(j, j+1);
		}
	}
	
	set<int> S;
	for(int i = 1; i <= N; i++) S.insert(uf[0].root(i));
	if(S.size() > vnum){
		for(int i = 1; i <= N; i++) cout << "Impossible" << endl;
		return 0;
	}
	
	for(int p = 1; p <= N; p++){
		int l = p, r = uf[0].root(p), n = 1<<(vnum-1);
		for(int i = 0; i < n; i++) dp[i] = 0;
		for(int i = 0; i < n; i++){
			if(dp[i] == l-1) dp[i] = r;
			if(dp[i] >= N) continue;
			for(int j = 0; j < vnum-1; j++){
				if(i & (1<<j)) continue;
				dp[i|(1<<j)] = max(dp[i|(1<<j)], uf[j+1].root(dp[i]+1));
			}
		}
		bool ans = false;
		for(int i = 0; i < n; i++){
			if(dp[i] >= N){
				ans = true;
				break;
			}
		}
		for(int i = l; i <= r; i++){
			if(ans) cout << "Possible" << endl;
			else cout << "Impossible" << endl;
		}
		p = r;
	}
	
	return 0;
}

Measured memory_bytes: 20736
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define np(str) next_permutation(str.begin(),str.end())
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for( i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll M = 1e9 + 7 ;
ll inf = 2 * 1e18;
ll n, m;

int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, k, t, x, y, z,  N;
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll mx = -inf;
	v<ll> vec = {a * c, a * d, b * c, b * d};
	for (auto u : vec) {
		mx = max(mx, u);
	}
	cout << mx;

	return 0;

}


























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


int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(k),r(k);
    rep(i,k) cin >> l[i] >> r[i] ;

    vector<ll> dp(n+1);
    vector<ll> dpsum(n+1); // 累積和

    dp[1] =1;
    dpsum[1] = 1;
    for(int i=2; i<= n; i++){
        rep(j,k){
            //[l[i],r[i]]
            int li = i-r[j]; //left index
            int ri = i-l[j]; //right index
            if(ri < 0)continue;
            li = max(li,1);
            dp[i] = (dp[i]+(dpsum[ri] - dpsum[li-1]) + mod)%mod;
        }
        dpsum[i] = (dpsum[i-1]+dp[i] )% mod;
    }
    cout << dp[n] << endl;

    return 0;
}

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

using namespace std;

int n;
int a;
long long sum;
int main(int argc, char* argv[]) {
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
      cin >> a;
      sum += a-1;
  }
  cout << sum << endl;
  return 0;
}


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

#define ll long long
#define ld long double
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define infl 1e18L+9
#define inf 1e9L+9
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()

const int mod=1e9L+7; 

struct S{
  ld x,y; 
};

long double dist(S a){
  return sqrt(a.x*a.x + a.y*a.y); 
}


void solve(){
  int n; cin>>n; 
  vector<S> e; 
  for(int i=0;i<n;i++){
    ld x,y; cin>>x>>y; 
    e.push_back({x,y}); 
  }
  sort(all(e),[](S a, S b) { return atan2(a.y,a.x) < atan2(b.y,b.x);} ); 
  for(int i=0;i<n;i++){
    e.push_back(e[i]);  
  }
  long double ans=0; 
  for(int i=0;i<n;i++){
    ld x=0, y=0; 
    for(int j=0;j<n;j++){
      x+=e[i+j].x, y+=e[i+j].y; 
      ans=max(ans,dist({x,y})); 
    }
  }
  cout<<fixed<<setprecision(20); 
  cout<<ans<<endl; 
}

int main()
{
	fast_io;
	clock_t beg=clock(); 
	solve(); 
	clock_t end=clock(); 
	fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC); 
	return 0;
}

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

int main() {
	int A, B;
	cin >> A >> B;

	int max_times = 2;
	int result = 0;
	for (int time = 0; time < max_times; time++) {
		if (A >= B) {
			result += A;
			A--;
		}
		else {
			result += B;
			B--;
		}
	}

	cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
   string s,t;
   cin >> s >> t;  
   if(s[0]==t[2] && t[0]==s[2] && s[1]==t[1]) 
   cout << "YES" << endl;
   else
   cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int h, w;

int main(void) {
    int row, col;
    
    while (1) {
        scanf("%d%d", &h, &w);
        if (h == 0 && w == 0) break;
        
        for (row = 1; row <= h; ++row) {
            for (col = 1; col <= w; ++col) {
                if (row % 2 == 0 && col % 2 == 0 || row % 2 == 1 && col % 2 == 1) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            
            printf("\n");
        }
        
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n, m;
  cin>>m;
  n = m % 10;
  if(n == 2|| n == 4|| n == 5|| n == 7|| n == 9)
  {
    cout<<"hon";
  }
  else if(n == 0|| n == 1|| n == 6|| n == 8)
  {
	cout<<"pon";
  }
  else cout<<"bon";
}

Measured memory_bytes: 3580
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> ans(n);
    rep(i,n) {
        int a;
        cin >> a;
        --a;
        ans[a] = i+1;
    }
    rep(i,n) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  int gcnt = 0;
  int pcnt = 0;
  int ans = 0;
  rep(i, s.size()) {
    if (s[i] == 'g') {
      if (gcnt > pcnt) {
        ans++;
        pcnt++;
      } else {
        gcnt++;
      }
    } else {
      if (gcnt > pcnt) {
        pcnt++;
      } else {
        gcnt++;
        ans--;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
using namespace std;
int main()
{
    int H, W, h, w, ans;
    cin >> H >> W >> h >> w;
    ans = H * W - (H * w + W * h - h * w);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*

        শুভ নববর্ষ ।
        ঘরে থাকুন , সুস্থ থাকুন ।
    wan-_-s
*/

#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define stay_home_stay_safe return 0
#define pb push_back
const ll N = 200007 ;
void scan(ll &n) { scanf("%lld",&n) ; }
void scan(ll &n, ll &m) { scanf("%lld%lld",&n,&m) ; }
void scan(vector<ll> &v) { ll n = v.size() ; for(ll i=0 ;i<n;i++) scanf("%lld",&v[i]) ; }
vector<ll> adj[N] ;
ll vis[N] , lvl[N] ,lvl1[N],vis1[N] ;
void edge (ll u , ll v) {
    adj[u].pb(v) ;
    adj[v].pb(u) ;
}


int main() {

   double a = 6.28318530717958623200 , r ;
   cin >> r ;
   cout << fixed<< setprecision(9) ;
   cout << r*a << endl ;

    stay_home_stay_safe ;
}






Measured memory_bytes: 8476
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    reverse(h.begin(),h.end());
    int ans = 0;
    int val = 0;
    for(int i=1;i<n;i++){
        if(h[i-1] <= h[i]){
            val++;
        }else{
            val = 0;
        }
        ans = max(ans,val);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
 
int main(){
  int n;
  int i,j;
  cin>>n;
  if(n<=9 && n>=1){
  	cout<<"Yes";
  }
  else if(n>9 && n<=81){
  	for(i=9;i>=2;i--){
  		if(n%i==0){
  			n=n/i;
  			for(j=2;j<=9;j++){
  				if(n==j)
  				{
  					cout<<"Yes";
  					return 0;
  				}
  			}
  			cout<<"No";
  			return 0;
  		}
  	}
  	cout<<"No";
  }
  else 
  	cout<<"No";

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main{
 
  
  public static void main(String agr[]){
  
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    if((a+b+c) == 17){
    System.out.println("YES");
    }
    else {
    System.out.println("NO");
    }
  }
}

Measured memory_bytes: 35508
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int a,b,c,d,e,f,i;
    char op;
   
    for (i=1; i<=i; i++){
         cin >> a >> op >> b;
    if(op=='+'){
        c=a+b;
        cout<<c;
    }
   else if(op=='-'){
       d=a-b;
       cout<<d;
   }
   else if(op=='*'){
       e=a*b;
       cout<<e;
   }
   else if(op=='/'){
       f=a/b;
       cout<<f;
      
   }
   else if(op=='?') {
       break;
   }
   cout<<endl;
    }
    return 0;
    
}





Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=1e6+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int n,a,b,D,vis[N],f[N],pre[N];
struct data{int x,y,id;}p[N];
bool operator<(data a,data b){if(a.x!=b.x)return a.x<b.x;return a.y<b.y;}
vector<int>e[N];
void gao(int dx,int dy){
	sort(p+1,p+1+n);
	rep(i,0,n)pre[i]=0;
	rep(i,1,n){
		int l=lower_bound(p+1,p+1+n,(data){p[i].x-dx,p[i].y-dy})-p;
		int r=upper_bound(p+1,p+1+n,(data){p[i].x-dx,p[i].y+dy})-p;
		f[p[i].id]+=r-l;
		if(l<=n&&l<r){
			e[p[i].id].pb(p[l].id);e[p[l].id].pb(p[i].id);
			pre[l]++;pre[r-1]--;
		}
	}
	re(i,1,n){
		pre[i]+=pre[i-1];
		if(pre[i]){
			e[p[i].id].pb(p[i+1].id);
			e[p[i+1].id].pb(p[i].id);
		}
	}
}
void dfs(int x){
	vis[x]=1;
	re(i,0,e[x].size())if(!vis[e[x][i]])dfs(e[x][i]);
}
int main(){
	read(n,a,b);
	rep(i,1,n){int x,y;read(x,y);
		p[i].x=x+y;p[i].y=x-y;p[i].id=i;
	}
	D=max(abs(p[a].x-p[b].x),abs(p[a].y-p[b].y));
	gao(D,D);
	rep(i,1,n)swap(p[i].x,p[i].y);
	gao(D,D-1);
	ll ans=0;
	dfs(a);
	rep(i,1,n)if(vis[i])ans+=f[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 44032
N = int(input())
l = [list(map(int,input().split())) for i in range(N)]
dp = [[0,0,0] for i in range(N + 1)]
dp[1][0] = l[0][0]
dp[1][1] = l[0][1]
dp[1][2] = l[0][2]
for i in range (N -1):
    dp[i + 2][0] = max(dp[i + 1][1] + l[i + 1][0],dp[i + 1][2] + l[i + 1][0])
    dp[i + 2][1] = max(dp[i + 1][0] + l[i + 1][1],dp[i + 1][2] + l[i + 1][1])
    dp[i + 2][2] = max(dp[i + 1][0] + l[i + 1][2],dp[i + 1][1] + l[i + 1][2])
print(max(dp[N]))

Measured memory_bytes: 47340
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////



int main() {
ll x;
cin>>x;

for(ll i=0;i<=1000;i++){
	for(ll j=0;j<=1000;j++){
		if(i*i*i*i*i-j*j*j*j*j==x){cout<<i<<" "<<j<<endl;
		return 0;}
	
	if(i*i*i*i*i+j*j*j*j*j==x){cout<<i<<" "<<-j<<endl;
	return 0;}
	}
}

return 0;
}









Measured memory_bytes: 3628
#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 ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);
	
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto &x : a) cin >> x;
	sort(all(a));
	int sz = unique(all(a)) - a.begin();
	puts(sz == n ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 1024
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    int N; cin >> N;
    string S; cin>>S;
    int x=0;
    int xmax=0;
    for (auto c : S)
    {
        if (c=='I') 
        {
            x++;
            chmax(xmax, x); 
        }
        else x--;
    }
    cout << xmax << endl;
    return 0;
}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n,m; cin>>n>>m;
 priority_queue<int> pq;
    rep(i,n){
        ll a; cin>>a;
        pq.push(a);
    }
    for(ll i=0;i<m;i++){
        ll b=pq.top();
        pq.pop();
        pq.push(b/2);
    }
    ll ans=0;
    while(!pq.empty()){
        ans+=pq.top();
        pq.pop();
    }
    cout<<ans<<endl;

}



















































Measured memory_bytes: 892
#include <iostream>
#include <vector>
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
using namespace std;

int main(void){
	int T,H;
	while(cin>>T>>H,T+H){
		vector<int> taro(T),hanako(H);
		int tsum,hsum;
		tsum=hsum=0;
		rep(i,T){
			cin>>taro[i];
			tsum+=taro[i];
		}
		rep(i,H){
			cin>>hanako[i];
			hsum+=hanako[i];
		}
		
		int ttrade=-1,htrade=-1;
		rep(t1,T){
			rep(h1,H){
				if(tsum - taro[t1] + hanako[h1] == hsum - hanako[h1] + taro[t1]){
					ttrade = t1;
					htrade = h1;
					t1 = T;h1 = H; 
				}
			}
		}
		
		if(ttrade != -1)
			cout<< taro[ttrade]<<" "<<hanako[htrade]<<endl;
		else{
			cout<<-1<<endl;
		}
		
	}
}

Measured memory_bytes: 1196
#include <iostream>

int main() {
    while (true) {
        int h, w;
        std::cin >> h >> w;
        if (h == 0 && w == 0) { break; }

        for (int i = 0; i < w; i++) {std::cout << '#';}
        std::cout << '\n';

        for (int i = 1; i < h-1; i++) {
            std::cout << '#';
            for (int j = 1; j < w-1; j++) {std::cout << '.';}
            std::cout << '#'<< '\n';
        }
        for (int i = 0; i < w; i++) {std::cout << '#';}
        std::cout << '\n';

        std::cout << '\n';
    }
}



Measured memory_bytes: 3024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int cnt = 0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i] != t[i])
            cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3840
n = int(input())
X = [list(map(int, input().split())) for i in range(n)]

start = 0
while X[start][2] == 0:
    start += 1


def c():
    for i in range(101):
        for j in range(101):
            ng = 0
            h = X[start][2] + abs(i - X[start][0]) + abs(j - X[start][1])
            for k in range(n):
                if X[k][2] != max(0, h - abs(i - X[k][0]) - abs(j - X[k][1])):
                    ng = 1
                    break
            if ng == 0:
                return i, j, h

ans = c()
print(ans[0], ans[1], ans[2])

Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int c[3][3],a[3],b[3];
int main(){
    rep(i,3)rep(j,3) cin>>c[i][j];
    rep(i,101)rep(j,101)rep(k,101){
        bool flag=true;
        a[0]=i,a[1]=j,a[2]=k;
        int b1=c[0][0]-i,b2=c[0][1]-i,b3=c[0][2]-i;
        if(b1<0||b2<0||b3<0) continue;
        b[0]=b1,b[1]=b2,b[2]=b3;
        FOR(p,1,3)rep(q,3){
            if(c[p][q]!=a[p]+b[q]) flag=false;
        }
        if(flag){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#ABC054 C - One-stroke Path

# v：現在の頂点 seen:訪問済みの頂点
def dfs(v,seen):
    if all(seen):
        return 1
    res = 0
    # 頂点ｖに隣接しているnvを探索していく
    for nv in G[v]:
        if seen[nv]:
            continue
        seen[nv]=True
        res += dfs(nv,seen)
        # 次の隣接頂点nvを探索した時の探索経路で、
        # 今回探索した隣接頂点nv通る可能性があるので
        # 元に戻しておく
        seen[nv]=False
    return res

n,m = map(int, input().split())
G = [[] for _ in range(n)]
seen = [False]*n
res = 0

for i in range(m):
    a,b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

# 頂点1を訪問済みとして探索を開始する
seen[0]=True
print(dfs(0,seen))



Measured memory_bytes: 3064
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <array>

using namespace std;

int main ()
{
	array<int , 8>A,P,Q,ANS;
	A[0] = 4;
	A[1] = 1;
	A[2] = 4;
	A[3] = 1;
	A[4] = 2;
	A[5] = 1;
	A[6] = 2;
	A[7] = 1;
	while( cin >> P[0] )
	{
		for( size_t i = 1; i < 8; i++ )
		{
			cin >> P[i];
		}
		int memo = INT_MAX;
		for( size_t i = 0; i < 8; i++ )
		{
			Q = P;
			int memo2=0,memo3=0;
			for( size_t j = 0; j < 8; j++ )
			{
				Q[j] -= min(A[j],Q[j]);
				memo2 += Q[j];
			}
				//cout << memo2 << endl;
			if( memo >= memo2 )
			{
				if( memo > memo2 )
				{
				memo = memo2;
					ANS = A;
				} else
				{
					for( size_t j = 0; j < 8; j++ )
					{
						if( ANS[j]>A[j] )
						{
							ANS = A;
							break;
						} else if( ANS[j]<A[j] )
						{
							break;
						}
					}
				}
			}
			rotate ( A.begin () , A.begin () + 1 , A.end () );
		}
		for( size_t i = 0; i < 7; i++ )
		{
			cout << ANS[i] << " ";
		}
		cout << ANS[7] << endl;
	}
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<long> data(1000001), sub(N);
  for(int i = 0; i < N; i++){
    cin >> sub.at(i);
    data.at(sub.at(i))++;
  }
  long ans = 0, flag;
  for(int i = 0; i < N; i++){
    flag = 1;
    data.at(sub.at(i))--;
    for(int j = 1; j <= sqrt(sub.at(i)); j++){
      if(sub.at(i) % j == 0){
        if(data.at(j) != 0 || data.at(sub.at(i) / j) != 0){
          flag = 0;
          break;
        }
      } else continue;
    }
    data.at(sub.at(i))++;
    if(flag == 1)ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12764
def inc(y,x):
    f = True
    for i in range(m):
        for j in range(m):
            if B[i][j] != A[y+i][x+j]:
                f = False
                break
        if not f:break
    return f
n,m = map(int,input().split())
A =[]
for i in range(n):
    A.append(input())
B = []
for i in range(m):
    B.append(input())

for y in range(n-m+1):
    for x in range(n-m+1):
        if inc(y,x):
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    ll K;
    cin >> S >> K;
    int k = min(100LL, K);
    char c;
    int maxOne = 0;
    for (int i = 0; i < min(k, (int)S.size()); i++) {
        if (S[i] == '1') maxOne++;
        else {
            c = S[i];
            break;
        }
    }
    if (K <= maxOne) {
        cout << 1 << '\n';
    }
    else {
        cout << c << '\n';
    }
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
    int a, b;
  	string s,t,u;
    cin >> s >> t;
  	cin >> a>>b;
 	cin >>u;
    if (s==u) a-=1;
    if (t==u) b-=1;
   cout<<a<<endl;
  cout<<b<<endl;
}

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

int main() {
    string s;
    cin >> s;
    int p = s.size() - 1;
    while (p >= 0) {
        if (p - 6 >= 0 && s.substr(p - 6, 7) == "dreamer") {
            p -= 7;
        } else if (p - 5 >= 0 && s.substr(p - 5, 6) == "eraser") {
            p -= 6;
        } else if (p - 4 >= 0 && s.substr(p - 4, 5) == "erase") {
            p -= 5;
        } else if (p - 4 >= 0 && s.substr(p - 4, 5) == "dream") {
            p -= 5;
        } else {
            break;
        }
    }
    if (p == -1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
//    cout << p << endl;
    return 0;
}


Measured memory_bytes: 512
n,m = (int(i) for i in input().split())
ab = []
for i in range(n) :
  a,b = input().split()
  ab.append((int(a),int(b)))
  
ab = sorted(ab,key=lambda i:i[0])



cost = 0
for i in range(n) :
  a,b = ab[i]
  c = m - b
  if 0 <= c :
    cost += a*b
    m -= b    

  else :
    cost += a*m
    m = 0    

  if m == 0 :
    print(cost)
    break


Measured memory_bytes: 18860
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	int N, X;
	std::cin >> N >> X;
	int D = 0;
	int count = 1;
	for (int i : boost::irange(0, N))
	{
		int L;
		std::cin >> L;
		D += L;
		if (D <= X)
		{
			++count;
		}
	}
	std::cout << count << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		String S = sc.next();
		int result = 0;
		
		for (int i = 48; i <= 57; ++i) {
			// もっとも左に登場する数字の位置を確認
			int index = S.indexOf(i);
			if (index == -1 || index >= N - 2) continue;
			
			for (int j = 48; j <= 57; ++j) {
				int nextIndex = S.indexOf(j, index + 1);
				if (nextIndex == -1 || nextIndex == N - 1) continue;
				
				for (int k = 48; k <= 57; ++k) {
					if (S.indexOf(k, nextIndex + 1) != -1) result++;
				}
			}
		}
		
		System.out.println(result);
		
	}
	
	
	
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ld w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << w*h/2 << " " << ((x==w/2 && y==h/2) ? 1 : 0) << newl;
  return 0;
}

Measured memory_bytes: 256