akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;


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


int main(){
    int n;
    ll a[101000];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    ll bef = 0;
    for(int i = 0; i < n-1; i++){
        bef = (a[i] - bef / 2) * 2;
    }

    bef = (a[n-1] - bef / 2);

    cout << bef << " ";
    for(int i = 0; i < n-1; i++){
        bef = (a[i] - bef / 2) * 2;
        cout << bef << " ";
    }
    cout << endl;




    return 0;
}


Measured memory_bytes: 2048
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") 
///#pragma GCC target("avx2")
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>
#include <numeric>

using namespace std;
#define open_streams ifstream fin("olympiad.in");ofstream fout("olympiad.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define UNIQ(a) a.resize(unique(all(a)) - a.begin())
#define eps 1e-6
//const double PI = M_PI;
const int INF = INT_MAX;
const ll limit = 1LL * 4e18;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
//---------------------------------------------------------------------------
const int mod = 1e9 + 7;
const int maxn = 1e6 + 100;






signed main() {
	speed;
	string s;
	cin >> s;
	if (s != "AAA" && s != "BBB") {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 10000003
#define mod 1000000007
#define F first
#define S second
ll prime[MAX]; 
unordered_map<ll, ll> max_map; 
  
// Function to return a^n 
ll power(ll a, ll n) 
{ 
    if (n == 0) 
        return 1; 
    ll p = power(a, n / 2) % mod; 
    p = (p * p) % mod; 
    if (n & 1) 
        p = (p * a) % mod; 
    return p; 
} 
  
// Function to find the smallest prime factors 
// of numbers upto MAX 
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (ll i = 2; i < MAX; i++) { 
        if (prime[i] == 0) { 
            for (ll j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
} 
  
// Function to return the LCM modulo M 
ll lcmModuloM(const ll* ar, ll n) 
{ 
  
    for (ll i = 0; i < n; i++) { 
        ll num = ar[i]; 
        unordered_map<ll, ll> temp; 
  
        // Temp stores mapping of prime factor to 
        // its power for the current element 
        while (num > 1) { 
  
            // Factor is the smallest prime factor of num 
            ll factor = prime[num]; 
            //cout<<factor<<" ";
            // Increase count of factor in temp 
            temp[factor]++; 
  
            // Reduce num by its prime factor 
            if(factor==0)
            num=0;
            num /= factor; 
        } 
  
        for (auto it : temp) { 
  
            // Store the highest power of every prime 
            // found till now in a new map max_map 
            max_map[it.first] = max(max_map[it.first], it.second); 
        } 
    } 
  
    ll ans = 1; 
  
    for (auto it : max_map) { 
  
        // LCM is product of primes to their highest powers modulo M 
        ans = (ans * power(it.F, it.S)) % mod; 
    } 
  
    return ans; 
}
int main()
{
    sieve();
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    cin>>arr[i];
    ll lcm=lcmModuloM(arr,n);
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        sum=(sum+lcm*power(arr[i],mod-2))%mod;
    }
    cout<<(sum+mod)%mod<<"\n";
    return 0;
}

Measured memory_bytes: 78848
#include<iostream>
using namespace std;
int main() {
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int max = 0;
    bool flag = true;
    for(int i = 0; i < N; i++) {
        if(max - a[i] > 1) {
            flag = false;
            break;
        }
        if(max < a[i]) {
            max = a[i];
        }
    }
    if(flag) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
const int M = 100000;

int gcd(int x, int y) {
	if (x < y)gcd(y, x);
	int r;
	if(y==0)return x;
	while (r = x % y) {
		x = y;
		y = r;
	}
	return y;
}


int main() {
	int n, a[M],l[M],r[M],c[M], ans = 0;

	cin >> n;
	rep(i, n)cin >> a[i];

	l[0]=0,r[n+1]=0;
	rep(i,n)
		l[i+1]=gcd(l[i],a[i]);
	for(int i=n;i>=0;i--)
		r[i]=gcd(r[i+1],a[i]);
	rep(i,n)c[i]=gcd(l[i],r[i+1]);
	sort(c,c+n);
	ans=c[n-1];
		
	
	cout << ans << endl;
}

Measured memory_bytes: 1792
n=int(input())
a_list=list(map(int,input().split()))
import heapq
pre=a_list[0:n]
heapq.heapify(pre)
pre_list=[sum(a_list[0:n])]
for i in range(n):
    heapq.heappush(pre,a_list[i+n])
    pre_list.append(pre_list[-1]+a_list[i+n]-heapq.heappop(pre))
b_list=[]
for i in range(2*n,3*n):
    b_list.append(-a_list[i])
post=b_list
heapq.heapify(post)
post_list=[sum(b_list)]
for i in range(n):
    heapq.heappush(post,-a_list[2*n-1-i])
    post_list.append(post_list[-1]-a_list[2*n-1-i]-heapq.heappop(post))
ans=-10**16
for i in range(n+1):
    Max=pre_list[i]+post_list[n-i]
    ans=max(ans,Max)
print(ans)



Measured memory_bytes: 122512
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <array>

#define ll long long

using namespace std;

vector<ll> A;
vector<array<long long, 4>> Q;

ll calc(ll v) {
	for (const auto& q : Q) {
		ll p, x, s, t;
		p = q[0];
		x = q[1];
		s = q[2];
		t = q[3];

		if (p == 1 and v >= x) {
			v = t * (v + s);
		}
		else if (p == 2 and v <= x) {
			v = (v - s) / t;
		}

	}

	return v;
}

signed main() {
	int n, q;
	ll L, R;
	cin >> n >> q >> L >> R;

	A.resize(n);
	for (auto& a : A) cin >> a;
	sort(A.begin(), A.end());

	for (int i = 0; i < q; i++) {
		ll p, x, s, t;
		cin >> p >> x >> s >> t;
		Q.push_back({ p, x, s, t });
	}

	int ng = -1, ok = n;

	while (ok - ng > 1) {
		int mid = (ok + ng) / 2;
		if (calc(A[mid]) >= L) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}

	int l = ok;

	ng = n, ok = -1;

	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		if (calc(A[mid]) <= R) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}

	int r = ok;
	
	cout << max(0, r - l + 1) << endl;

}


Measured memory_bytes: 12756
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
//vector
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pp pop_back
//pair
#define pi pair<int ,int >
#define mk make_pair
#define ff first
#define ss second
//set
#define si set<int>
#define sit set<int>::iterator 
using namespace std;
int main()
{
fast;
int n;cin>>n;
ll a[n],zero=0;
fr(i,0,n)
{
	cin>>a[i];
	if(a[i]==0)
	{
		zero=1;
	}
}
if(zero==1)
{
	cout<<0<<"\n";
}
else
{
	ll ans=1,f=1,N=1000000000000000000,check;
	fr(i,0,n)
	{
		check=N/ans;
		if(a[i]<=check)
		{
			ans*=a[i];
		}
		else
		{
			f=0;
			break;
		}
	}
	if(f)
	{
		cout<<ans;
	}
	else
	{
		cout<<-1;
	}
}
return 0;
}

Measured memory_bytes: 4436
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n;
	cin >> n;
	if (n == 1){
		cout << "Hello World" << endl;
	}
	else{
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<string>

typedef long long ll;
typedef unsigned short int unsi;
typedef unsigned int uni;
typedef unsigned long int unli;

using namespace std;

unsi gojoho(unsi A, unsi B) {
	unsi R = 1;
	if (A > B) {
		while (R!=0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}

uni gojoho(uni A, uni B) {
	uni R = 1;
	if (A > B) {
		while (R != 0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}

unli gojoho(unli A, unli B) {
	unli R = 1;
	if (A > B) {
		while (R != 0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}

int gojoho(int A, int B) {
	int R = 1;
	if (A > B) {
		while (R != 0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}



int main(){
	string S;
	int Win = 0;
	int day = 0;
	
	cin >> S;
	
	day = S.size();

	for (int i = 0; i <= day - 1; i++) {
		char o = 'o';
		if (S[i]==o) {
			Win++;
		}
	}

	if (15 - day + Win>=8) {
		printf("YES");
	}else {
		printf("NO");
	}
}


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

#define oldone


bool osyar(int w, int h, int x, int y, int r){
  if (x - r <  0 || x + r > w){
    return false;
  }
  if (y - r < 0 || y + r > h) {
    return false;
  }
  return true;
}


int main () {
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  bool flag = osyar(w, h, x, y, r);
  #ifndef oldone
    if (x + r > w)  flag = false;
    if (x - r < 0)  flag = false;
    if (y + r > h)  flag = false;
    if (y - r < 0)  flag = false;
  #endif
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}





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

int main() {
  int n;
  cin>>n;
  int vec[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  int vecb[n];
  for(int i=0;i<n;i++){
    if(i%2==0){
      vecb[n/2+i/2]=vec[i];
    }
    else{
      vecb[n/2-i/2-1]=vec[i];
    }
  }
  if(n%2==1){
    reverse(vecb,vecb+n);
  }
  for(int i=0;i<n;i++){
    cout<<vecb[i]<<" ";
  }
  return 0;
}

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


/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/
typedef struct  llnode
{
	int x;
	struct llnode *next;
}
slnode;


using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}
int findSingle(int ar[], int ar_size)
    {
        int res = ar[0];
        for (int i = 1; i < ar_size; i++)
            res = res ^ ar[i];
        return res;
    }
const int con = 2e5;
int freq[con + 9];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n , temp;
    cin >> n;
    while(cin >> temp)
    {
    	freq[temp]++;
    }
    lpe(i , 1 ,n)
    {
    	cout << freq[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4436
#include<iostream>
#include<map>
#include<cassert>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
const int N = 500;
char m[N][N+1];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

bool cango(int r,int c,int y,int x,int ty,int tx){
  rep(i,4){
    int ddx=x+dx[i],ddy=y+dy[i];
    while(ddy != -1 && ddx != -1 && ddy != r && ddx != c){
      if (m[ddy][ddx] != '.')break;
      if (ddy == ty && ddx == tx)return true;
      ddx+=dx[i];
      ddy+=dy[i];
    }
  }
  return false;
}

bool erase(int r,int c,int y1,int x1,int y2,int x2){
  vector<int> tx,ty;
  if (y1 == y2){
    tx.push_back(x1 < x2?x1+1:x2+1);
    ty.push_back(y1);
  }else if (x1 == x2){
    tx.push_back(x1);
    ty.push_back(y1 < y2?y1+1:y2+1);
  }else {
    tx.push_back(x1);
    ty.push_back(y2);
    tx.push_back(x2);
    ty.push_back(y1);
  }
  bool isok=false;
  rep(i,(int)tx.size()){
    if (cango(r,c,y1,x1,ty[i],tx[i]) && 
	cango(r,c,y2,x2,ty[i],tx[i])){isok=true;break;}
  }
  if (isok)m[y1][x1]=m[y2][x2]='.';
  return isok;
}

main(){
  int r,c;
  while(cin>>r>>c){
    rep(i,r)cin>>m[i];
    vector<pii> in[26];
    rep(i,r){
      rep(j,c){
	if (!isalpha(m[i][j]))continue;
	in[m[i][j]-'A'].push_back(make_pair(i,j));
      }
    }
    rep(i,26){
      if (in[i].size() == 0)continue;
      if (abs(in[i][0].first-in[i][1].first)+abs(in[i][0].second-in[i][1].second) == 1)in[i].clear();
    }
    int ans=0;
    while(true){
      bool iserased=false;
      rep(i,26){
	if (in[i].size() == 0)continue;
	if (erase(r,c,in[i][0].first,in[i][0].second,in[i][1].first,in[i][1].second))ans+=2,iserased=true,in[i].clear();
      }
      if (!iserased)break;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int N; std::cin >> N;

  int cnt = 0;
  int height = 0;
  for (int i = 0; i < N; ++i) {
    int h; std::cin >> h;
    if (height <= h) {
      ++cnt;
      height = h;
    }
  }

  std::cout << cnt << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  cout << 180 * (n-2) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	// your code goes here
	string s,t;
	cin>>s>>t;
	ll u=0;
	for(ll i=0;i<s.size();i++)
	{
	    if(s[i]!=t[i])
	    {
	        u++;
	    }
	}
	cout<<u;
	return 0;
}


Measured memory_bytes: 3916
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int num;
    cin >> num;
    
    string str;
    cin >> str;
    
    int counter = 0;
    int loop = num - 2;
    for(int i = 0; i < loop; ++i){
        if(str[i] == 'A' && str[i+1] == 'B' && str[i+2] == 'C') ++counter;
        else continue;
    }
    
    cout << counter << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <cstdio>
#include <string.h>
#include <cstring>

using namespace std;

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

typedef long long ll;
//各地点の行と列をPairで持たせる
typedef pair<int,int> P;
int y,x,n,nx,ny,nextx,nexty;
int ans = 0;
int counter = 0;
int d[1100][1100];
char c[1100][1100];
int d1[] = {0,0,-1,1};
int d2[] = {1,-1,0,0};
int dc = 0;
char key[] = "S123456789";
P st[10];

int bfs(P,P);

int main(){
    cin >> y >> x >> n;
    REP(i,y){
        cin >> c[i];
    }
    REP(i,y){
        REP(j,x){
            REP(k,n+1) {
                if(c[i][j] == key[k]) st[k] = P(i,j); 
            }
        }
    }
   
    REP(i,n){
        memset(d,-1,sizeof(d));
      
        ans += bfs(st[i],st[i+1]);
      
    }
    cout << ans << endl;
    return 0;
}

int bfs(P s, P g){
    queue<P> que;
    que.push(s);
    d[s.first][s.second] = 0;
    while(que.size()){
        P p = que.front(); que.pop();
        ny = p.first;
        nx = p.second;
        dc = d[ny][nx];
       
        if(p == g) break;
 
        
        REP(i,4){
            nextx = nx + d1[i];
            nexty = ny + d2[i];

            if(nexty < 0 || nexty >= y || nextx < 0 || nextx >= x) continue;
           
            if(c[nexty][nextx] == 'X' || d[nexty][nextx] != -1) continue;
	
            que.push(P(nexty,nextx));
     
            d[nexty][nextx] = dc + 1;
        }
        
    }
    return d[g.first][g.second];

}



Measured memory_bytes: 8984
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define RELEASE

#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define REPR(i, n) for(ll i = n; i >= 1; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define INF 1e9+123
#define ALL(v) v.begiあn(), v.end()

int main(){
    char t;
    cin>>t;
    t=t+1;
    cout<<t;
    
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int flr[1000010], flm[1000010];

int main() {
	int N;
	cin >> N;
	vector<string> s(N);
	vector<pair<int, int>> pl, mn; 
	int sum=0;
	for(int i=0; i<N; ++i){
		cin >> s[i];
		flr[i]=flm[i]=0;
		for(int j=0; j<s[i].size(); ++j){
			if(s[i][j]=='(') ++flr[i];
			else --flr[i];
			flm[i]=min(flm[i], flr[i]);
		}
		sum += flr[i];
		if(flr[i]>=0){
			pl.emplace_back(make_pair(-flm[i], flr[i]));
		}
		else{
			mn.emplace_back(make_pair(flr[i]-flm[i], -flr[i]));
		}
	}
	if(sum!=0){
		cout << "No" << endl;
		return 0;
	}
	sort(pl.begin(), pl.end());
	sort(mn.begin(), mn.end());
	priority_queue<int> pq, mq;
	int now=0, id=0;
	for(int i=0; i<pl.size(); ++i){
		while(id<pl.size()){
			if(pl[id].first>now) break;
			pq.emplace(pl[id].second);
			++id;
		}
		if(pq.empty()){
			cout << "No" << endl;
			return 0;
		}
		now += pq.top();
		pq.pop();
	}
	now=0, id=0;
	for(int i=0; i<mn.size(); ++i){
		while(id<mn.size()){
			if(mn[id].first>now) break;
			mq.emplace(mn[id].second);
			++id;
		}
		if(mq.empty()){
			cout << "No" << endl;
			return 0;
		}
		now += mq.top();
		mq.pop();
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 56080
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define INF 1LL << 55
#define MAX (1LL << 31) -1
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,ll> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};
//#define F function<T(T,T)>

int f(string s){
    return stoi(s.substr(0,2))*3600+stoi(s.substr(3,2))*60+stoi(s.substr(6,2));
}

signed main(){
    while(true){
        int n;
        cin>>n;
        if(n==0) return 0;
        vector<P> V;
        for(int i=0;i<n;i++){
            string s,t;
            cin>>s>>t;
            V.emplace_back(f(s),f(t));
        }
        sort(V.begin(),V.end());
        multiset<int> S;
        S.insert(MAX);
        S.insert(-1);
        int count=0;
        for(int i=0;i<n;i++){
            int x=V[i].first;
            auto it=S.upper_bound(x);
            it--;
            if(*it==-1) count++;
            else S.erase(it);
            S.insert(V[i].second);
        }
        cout<<count<<endl;
    }
}


Measured memory_bytes: 3308
#include<stdio.h>
int main(void){
	int n;
	int s[100];
	int i;
	int min,max,sum;


	while(1){
		scanf("%d",&n);
		
		if(n==0){
			break;
		}

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

		min=s[0];
		max=s[0];
		sum=0;
		i=0;

		while(i<n){
			if(min>s[i]){
				min=s[i];
			}

			if(max<s[i]){
				max=s[i];
			}
			i++;
		}
		
		i=0;
		while(i<n){
			sum=sum+s[i];
			i++;
		}

		printf("%d\n",(sum-min-max)/(n-2));
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int n, m;
int deg[100010];
vector <pii> E[100010];
t3 edge[100010];
int chk[100010];

void dfs(int x, int st) {
	chk[x] = 1;
	t3 e = edge[x];
	int a, b, idx; tie(a, b, idx) = e;
	if(st == b) swap(a, b);
	int f = -1;
	for(int i=0;i<szz(E[b]);i++) if(E[b][i].Fi == a) f = i;
	f ^= 1;
	if(chk[E[b][f].Se] == 0) dfs(E[b][f].Se, b);
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i=1;i<=m;i++) {
		int x, y; scanf("%d%d", &x, &y);
		deg[x]++; deg[y]++;
		E[x].pb(pii(y, i));
		E[y].pb(pii(x, i));
		edge[i] = t3(x, y, i);
	}
	for(int i=1;i<=n;i++) if(deg[i] & 1) {
		puts("No");
		return 0;
	}
	for(int i=1;i<=n;i++) if(deg[i] >= 6) {
		puts("Yes");
		return 0;
	}
	int ans = 0;
	for(int i=1;i<=n;i++) if(deg[i] == 4) ++ans;
	if(ans >= 3) puts("Yes");
	else if(ans <= 1) puts("No");
	else {
		int fa = -1, fb = -1;
		for(int i=1;i<=n;i++) if(deg[i] == 4) {
			if(fa == -1) fa = i;
			else fb = i;
		}
		int ok = 0;
		rep(a, 3) {
			rep(b, 3) {
				int cc = 0;
				memset(chk, 0, sizeof chk);
				for(int i=1;i<=m;i++) if(chk[i] == 0) {
					++cc;
					dfs(i, get<0>(edge[i]));
				}
				if(cc >= 3) ok = 1;
				rotate(E[fa].begin()+1, E[fa].begin()+2, E[fa].begin()+4);
			}
			rotate(E[fb].begin()+1, E[fb].begin()+2, E[fb].begin()+4);
		}
		printf("%s\n", ok ? "Yes" : "No");
	}
	return 0;
}

Measured memory_bytes: 7680
n,a,b,c,d = map(int,input().split())
s = input()
if '##' in s[a:c] or '##' in s[b:d]:
  print('No')
else:
  if c < d:
    print('Yes')
  else:
    if '...' in s[b - 2:d + 1]:
      print('Yes')
    else:
      print('No')

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793238462
typedef long long ll;
typedef double db;
ll a[100005];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    if(a[1]==0){
        cout<<0<<endl;
        return 0;
    }
    ll now=1,p=1e18;
    for(int i=1;i<=n;i++){
        ll x=p/now;
        if(x>=a[i]){
            now*=a[i];
        }
        else{
            cout<<-1<<endl;
            return 0;
        }
    }
    if(now>1e18) cout<<-1<<endl;
    else cout<<now<<endl;
} 


Measured memory_bytes: 4424
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
using namespace std;
typedef long long ll;
void inputVector(vector<int> * p, int a){ REP(i, a){ int input; cin >> input; p -> push_back(input); }}

int main(int argc, const char * argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, s = 0; cin >> n;
  vector<int> h;
  inputVector(&h, n);
  int maxv = *max_element(h.begin(), h.end());
  REP(j, maxv) {
    bool is_zero = true;
    int cnt_mnt = 0;
    REP(i, n) {
      if (is_zero == true && h[i] > 0) {
        cnt_mnt ++;
        is_zero = false;
      }
      if (h[i] <= 0) {
        is_zero = true;
      }
    }
    REP(i, n) h[i] --;
    s += cnt_mnt;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    string s;
    cin >> s;
    cout << s.substr(0, 4) << " " << s.substr(4, 8) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int c1,c5,c10,c50,c100,c500;
    cin>>c1>>c5>>c10>>c50>>c100>>c500;
    
    if(c1*1+c5*5+c10*10+c50*50+c100*100+c500*500>=1000)
    {
        cout<<"1"<<endl;
    }
    else{
        cout<<"0"<<endl;
    }
}



Measured memory_bytes: 3104
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
    int N,K;
    
    cin >> N >> K;

    int L[N];

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

    sort(L, L+N);
    int ans=0;
    for(int i=0;i<K;i++){
        ans = ans + L[N-i-1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template <class T> bool chmax(T &a, const T &b) {
  if(a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if(b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int a[500][500];

int main() {
  int h, w, sum;
  cin >> h >> w;
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
      sum += a[i][j];
    }
  }

  vector<string> ans;
  rep(i, h) {
    rep(j, w - 1) {
      if(a[i][j] % 2 == 1) {
        a[i][j + 1]++;
        ans.push_back(to_string(i + 1) + ' ' + to_string(j + 1) + ' ' +
                      to_string(i + 1) + ' ' + to_string(j + 2));
      }
    }
  }
  rep(i, h - 1) {
    if(a[i][w - 1] % 2 == 1) {
      a[i + 1][w - 1]++;
      ans.push_back(to_string(i + 1) + ' ' + to_string(w) + ' ' +
                    to_string(i + 2) + ' ' + to_string(w));
    }
  }

  cout << ans.size() << endl;
  rep(i, ans.size()) {
    cout << ans[i] << endl;
  }

  return 0;
}


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

using namespace std;

int N, A, B;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d", &N, &A, &B);
if ((B - A) & 1) printf ("Borys\n");
else printf ("Alice\n");

return 0;
}


Measured memory_bytes: 764
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
const int M=1<<9,N=1<<18,inf=1e5;
int f[M+10][100010];
int w[N+10],v[N+10];
int top,sta[20];
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read();
	for(int i=1;i<=n;i++)v[i]=read(),w[i]=read();
	for(int i=1;i<min(n+1,M);i++)
	{
		int fa=i/2;
		for(int j=0;j<=inf;j++)
		{
			f[i][j]=f[fa][j];
			if(j>=w[i])f[i][j]=max(f[i][j],f[fa][j-w[i]]+v[i]);
		}
	}
	for(int i=1;i<min(n+1,M);i++)
	{
		for(int j=1;j<=inf;j++)f[i][j]=max(f[i][j],f[i][j-1]);
	}
	int Q=read();
	while(Q--)
	{
		int d=read(),l=read();
		int now=d;top=0;
		while(now>=M)sta[++top]=now,now=now/2;
		int ans=0;
		for(int i=0;i<(1<<top);i++)
		{
			int tot=0,val=0;
			for(int j=0;j<top;j++)
			{
				if(!(i>>j&1))continue;
				int uf=sta[j+1];
				tot+=w[uf],val+=v[uf];
			}if(tot<=l)ans=max(ans,val+f[now][l-tot]);
		}pr2(ans);
	}
	return 0;
}

Measured memory_bytes: 203216
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
			int a=scan.nextInt();
			for(int i=0;i<a;i++){
				int b=scan.nextInt();
				if(b==0){
					int c=scan.nextInt();
					kadai.pushBack(c);
				}else if(b==1){
					int c=scan.nextInt();
					int ab=kadai.randomAccess(c);
					System.out.println(ab);
				}else if(b==2){
					kadai.popBack();
				}
			}
		scan.close();
	}
}

class kadai{
	static ArrayList<Integer> retu=new ArrayList<>();
	
	static void pushBack(int a){
	retu.add(a);
	}
	static int randomAccess(int a){
		int d=0;
		d=retu.get(a);
		return d;
	}
	static void popBack(){
		int d=0;
		d=retu.size();
		retu.remove(d-1);
	}
}


Measured memory_bytes: 139448
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
ans = 0
for _ in range(N):
    l, r = M()
    ans += (r-l)+1
print(ans)

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

int N, X;
int m[127];

int main(){
    scanf("%d%d", &N, &X);
    int minm=1e5;
    int sum=0;
    for(int i =0; i<N; i++){
        scanf("%d", &m[i]);
        sum+=m[i];
        if(m[i] < minm){
            minm = m[i];
        }
    }
    X-=sum;
    N+= X/minm;
    printf("%d", N);

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
using namespace std;

string s;
long long ans;

long long getnum(string ss){
	if(ss.size()==1) return ss[0]-'0';
	return getnum(ss.substr(0,ss.size()-1))*10+ss[ss.size()-1]-'0';
}

int main(){
	cin>>s;
	int n=s.size();
	for(int i=0;i<(1<<(n-1));i++){
		int last=0;
		for(int j=0;j<n-1;j++) if(i&(1<<j)){
			ans+=getnum(s.substr(last,j-last+1));
			last=j+1;
		}
		if(last!=n){
			ans+=getnum(s.substr(last,n-last));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;cin>>h>>w;
  vector<vector<char>>grid(h+2,vector<char>(w+2));
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>grid[i][j];
    }
  }
  vector<vector<vector<int>>>rlud(h+2,vector<vector<int>>(w+2,vector<int>(4)));
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(grid[i][j]=='.')rlud.at(i).at(j).at(2)=rlud.at(i).at(j-1).at(2)+1;
      if(grid[i][j]=='#')rlud.at(i).at(j).at(2)=0;
    }
    for(int j=w;j>0;j--){
      if(grid[i][j]=='.')rlud.at(i).at(j).at(3)=rlud.at(i).at(j+1).at(3)+1;
      if(grid[i][j]=='#')rlud.at(i).at(j).at(3)=0;
    }
  }
  for(int j=1;j<=w;j++){
    for(int i=1;i<=h;i++){
      if(grid[i][j]=='.')rlud.at(i).at(j).at(0)=rlud.at(i-1).at(j).at(0)+1;
      if(grid[i][j]=='#')rlud.at(i).at(j).at(0)=0;
    }
    for(int i=h;i>0;i--){
      if(grid[i][j]=='.')rlud.at(i).at(j).at(1)=rlud.at(i+1).at(j).at(1)+1;
      if(grid[i][j]=='#')rlud.at(i).at(j).at(1)=0;
    }
  }
  int ma=0;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      ma=max(ma,rlud.at(i).at(j).at(0)+rlud.at(i).at(j).at(1)
             +rlud.at(i).at(j).at(2)+rlud.at(i).at(j).at(3));
    }
  }
  cout<<ma-3<<endl;
}

Measured memory_bytes: 223616
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    long y=sc.nextLong();
    for(int i=0;i<=n;i++) {
    	for(int j=0;j<=n-i;j++) {
    		if(i*10000+j*5000+(n-i-j)*1000==y) {
    			System.out.println(i+" "+j+" "+(n-(i+j)));
    			System.exit(0);
    		}
    	}
    }
    System.out.println("-1 -1 -1");
  }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int fa[100010];
int get(int x)
{
	if(x!=fa[x])
		return fa[x]=get(fa[x]);
	return x;
}
int main()
{
	int n,m,i,x,y;
	cin>>n>>m;
	for(i=1;i<=n;i++)
		fa[i]=i;
	for(i=1;i<=m;i++)
	{
		cin>>x>>y;
		int fx=get(x),fy=get(y);
		fa[fx]=fy;
	}
	set<int>st;
	for(i=1;i<=n;i++)
		st.insert(get(i));
	cout<<st.size()-1;
	return 0;
}

Measured memory_bytes: 7816
//C - Vacation

#include <iostream>
using namespace std;

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

  //iにおける幸福度a, b, cを受け取る配列
  int a[3][n];

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

  //その日に受け取りうる幸福度
  int dp[3][n];
  dp[0][0] = max(a[1][0], a[2][0]);
  dp[1][0] = max(a[0][0], a[2][0]);
  dp[2][0] = max(a[0][0], a[1][0]);

  for (int i = 1; i < n; i++) {
    dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + a[0][i];
    dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + a[1][i];
    dp[2][i] = max(dp[0][i-1], dp[1][i-1]) + a[2][i];
  }

  cout << max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1])) << endl;
}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

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

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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;
}
//

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

  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  int cnt = 0;
  rep(i, n) {
    if (i + 1 != p[i]) cnt++;
  }

  if (cnt == 0 || cnt == 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#define N 100
using namespace std;
int main(void) {
	int n;
	char a[N];
	char b[N];
	char c[N];

	int x=0;
	int y;

	int i=0;
	cin >> n;

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

	for (i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			b[i] = a[i];
		}
		//else
			//x++;

		else if (a[i] == c[i]) {
			//x++;
			c[i] = a[i];
		}
		else
			x++;

		if (b[i] == c[i]) {
			//x++;
			c[i] = b[i];
		}
		else
			x++;
	}
	cout << x;
	return 0;
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N; cin >> M;
  vector<string> a(N), b(M);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> b[i];
  }
  bool matched = false;
  for (int i = 0; i < N-M+1; i++) {
    for (int j = 0; j <N-M+1; j++) {
      for (int k = 0; k < M; k++) {
        for (int l = 0; l < M; l++) {
          //cout << i << ' ' << j << ' ' << b[k][l] << ' ' << a[k+i][l+j];
          if (b[k][l] != a[k+i][l+j]) goto out;
        }
      }
      matched = true;
      goto end;
out:
      matched = false;
    }
  }
  cout << "No" << endl;
  return 0;
end:
  cout << "Yes" << endl;
  return 0;
}

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

int main() {
    int W, H, x, y, r;
    
    cin >> W >> H >> x >> y >> r;
    if ((x-r) >= 0 && (x+r) <= W && (y-r) >= 0 && (y+r) <= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>

int main(){

  int N,A[100],a,b,i,j,n,v;
  
  scanf("%d",&N);
  for (a = 0;a < N;a++) scanf("%d",&A[a]);
  
  for (i = 1;i < N;i++){
    for (b = 0;b < N-1;b++)  printf("%d ",A[b]);
    printf("%d\n",A[N-1]);
    v = A[i];
    j = i - 1;
    while (j >= 0 && A[j]  > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  }

  for (b = 0;b < N-1;b++)  printf("%d ",A[b]);
  printf("%d\n",A[N-1]);

  return 0;
}



Measured memory_bytes: 2144
#!/usr/bin/env python:
# -*- coding: utf-8 -*-

import sys

def make_prime_list(lim):
    lst = [True for i in xrange(lim + 1)]

    num = 2
    while num ** 2 <= lim:
        for i in xrange(num * 2, lim + 1, num):
            lst[i] = False
        num += 1
        while not lst[num]:
            num += 1
    return [i for i in xrange(2, lim + 1) if lst[i]]

def binary_search(n, prime_list):
    rLim = len(prime_list) - 1
    lLim = 0
    while lLim < rLim:
        middle = (rLim + lLim) / 2
        if prime_list[middle] == n:
            return middle
        elif prime_list[middle] < n:
            lLim = middle + 1
        else:
            rLim = middle - 1
    while prime_list[rLim] < n and rLim < len(prime_list) - 1:
        rLim += 1
    return rLim    

def solve():
    prime_list = make_prime_list(50000)
    while True:
        n = input()
        if n > 0:
            if n % 2 == 0:
                count = 0
                index = 0
                rev_index = binary_search(n, prime_list)
                while index <= rev_index:
                    while prime_list[index] + prime_list[rev_index] > n:
                        rev_index -= 1
                    if index <= rev_index and prime_list[index] + prime_list[rev_index] == n:
                        count += 1
                    index += 1
                print count
            else:
                if n - 2 in prime_list:
                    print 1
                else:
                    print 0
        else:
            sys.exit()

if __name__ == "__main__":
    solve()    

Measured memory_bytes: 4820
import java.io.*;
import java.util.*;
public class Main{
  	/*public int minRec(int a[],int dp[],int i,int j)
    {
      if(i==n && j==n)
        	return dp[n][n];
      if(
        return Math.min( Math.abs(a[]
    }*/
	public static void main(String args[]) throws IOException{
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int arr[]=new int[n];
      for(int i=0;i<n;i++)
        arr[i]=sc.nextInt();
      
      int dp[] =  new int[n];
      Arrays.fill(dp, Integer.MAX_VALUE);
      
      System.out.println(minCost(arr, 0, dp, k));
      
    }
  
  public static int minCost(int arr[], int pos, int dp[], int k){
  	if(pos >= arr.length)
      return Integer.MAX_VALUE;
    
     if(pos == arr.length -1)
      return 0;
    
    if(dp[pos] != Integer.MAX_VALUE)
      	return dp[pos];
    
    for(int i = pos+1; i<=pos+k; i++){
    if(i < arr.length)
      dp[pos] = Math.min(dp[pos], Math.abs(arr[pos] - arr[i]) + minCost(arr, i,dp, k));
    }
   
      return dp[pos];
    
  }
}


Measured memory_bytes: 64384
/******************************************
*    AUTHOR:         julianferres         *
******************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define show(v,n) cerr << #v << " = "; forn(i,n) cerr << v[i] << " "; cerr << endl;
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
const int inf = 1<<30; // const ll inf = 1LL<<62;
const int mod = 1e9+7; // 998244353
const int N  = 1e3+5;

struct S{
    ll w, s, v;
    void read(){
        cin >> w >> s >> v;
    }
    bool operator<(const S &other) const
    {
        return w + s < other.w + other.s;
    }
    void print(){
        cout << w << " " << s << " " << v << endl;
    }
};
vector<S> in(N);
const ll max_s = 20200;

int
main()
{
    FIN;
    int n; cin >> n;
    forn(i, n) in[i].read();

    sort(all(in));

    vi dp(max_s+1, 0);

    for(auto block: in){
        for (ll w = min(block.s, max_s - block.w); w >= 0; --w){
            dp[w + block.w] = max(dp[w + block.w], dp[w] + block.v);
        }
    }
    ll answer = 0;
    forn(i,max_s+1){
        answer = max(answer, dp[i]);
    }
    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 512
from collections import defaultdict
from collections import Counter

MOD = 10 ** 9 + 7
def main():
    N = int(input())
    c = Counter(list(map(int, input().split())))

    if N % 2 == 0 and c[0] != 0:
        print(0)
        return
    if N % 2 != 0 and c[0] != 1:
        print(0)
        return
    for i in range(N - 1, 0, -2):
        if c[i] != 2:
            print(0)
            return

    print(pow(2, (N // 2), MOD))

if __name__ == '__main__':
    main()


Measured memory_bytes: 14812
#include <bits/stdc++.h>
using namespace std;
int main() {
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  int X=tx-sx;
  int Y=ty-sy;
  for(int i=0;i<X;i++)	cout << "R";
  for(int i=0;i<Y;i++)	cout << "U";
  for(int i=0;i<X;i++)	cout << "L";
  for(int i=0;i<Y+1;i++)	cout << "D";
  for(int i=0;i<X+1;i++)	cout << "R";
  for(int i=0;i<Y+1;i++)	cout << "U";
  cout << "L" << "U";
  for(int i=0;i<X+1;i++)	cout << "L";
  for(int i=0;i<Y+1;i++)	cout << "D";
  cout << "R" << endl;
}


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

#define rep(i, N) for(int i = 0; i < N; i++)
using namespace std;

int main(void){
  int N; cin >> N;
  int A[N], B[N], C[N-1];
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  rep(i, N-1) cin >> C[i];
  int ans = 0;
  for(int i = 0; i < N; i++){
    ans += B[A[i]-1];
    if(i < N-1 && A[i]+1 == A[i+1]) ans += C[A[i]-1];
  }
  cout << ans << endl;
}


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

int main() {
  int n, i, tmp; cin >> n;
  vector<pair<int, int>> a(n);
  for (i = 0; i < n; i++) {
    cin >> tmp;
    a[i].first = tmp; a[i].second = i+1;
  }
  sort(a.begin(), a.end());
  cout << a[0].second;
  for (i = 1; i < n; i++)
    cout << " " << a[i].second;
  cout << endl;
}

Measured memory_bytes: 1664
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

def ktw(x):
    return sum(list(map(int,list(str(x)))))
n,a,b=MI()
ans=0
for i in range(1,n+1):
    if a<=ktw(i)<=b:
        ans+=i
print(ans)



Measured memory_bytes: 3440
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    fact();
    cin >> N >> M;
    if (abs(N - M ) > 1) {
        cout << 0 << endl;
        return 0;
    } else if(abs(N - M) == 1) {
        cout << Mul(F[N], F[M]) << endl;
    } else{
        cout << Mul(2, Mul(F[N], F[M])) << endl;
    }

    return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define ll long long
using namespace std;
const int N=400005;
int a[N],las[N],q[N],n;
ll b[N][60],k;
int main(){
	scanf("%d%lld",&n,&k);
	For(i,1,n) scanf("%d",&a[i]),a[i+n]=a[i];
	Rep(i,n+n,n+1) las[a[i]]=i;
	Rep(i,n,1){
		b[i][0]=las[a[i]];
		las[a[i]]=i;
	}
	For(i,1,58) For(j,1,n)
		if (b[j][i-1]==(1ll<<60)) b[j][i]=1ll<<60;
		else{
			ll S=b[j][i-1]/n,id=b[j][i-1]+1-S*n;
			b[j][i]=min(1ll<<60,b[id][i-1]+S*n);
		}
	ll now=0;
	Rep(i,58,0){
		ll S=now/n,id=now+1-S*n;
		if (b[id][i]+S*n<=k*n)
			now=b[id][i]+S*n;
	}
	For(i,1,N-1) las[i]=0;
	for (now++;now<=k*n;now++){
		ll S=(now-1)/n,id=now-S*n;
		if (!las[a[id]]) q[++*q]=a[id],las[a[id]]=1;
		else{
			for (;q[*q]!=a[id];--*q) las[q[*q]]=0;
			--*q; las[a[id]]=0;
		}
	}
	For(i,1,*q) printf("%d ",q[i]);
	puts("");
}

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

int main(){
    int n, d;
    cin >> n >> d;
    if(n % (d * 2 + 1) == 0){
        cout << n / (d * 2 + 1) << endl;
    }
    else{
        cout << n / (d * 2 + 1) + 1 << endl;
    }
}

Measured memory_bytes: 256