akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N;

int dp[2][101][100050];

const int INF=1e9;

void chmin(int &a,int b){
    if(a>b) a=b;
}

void solve(){
    vector<int> P(N);
    for(int i=0;i<N;i++) cin>>P[i];

    for(int i=0;i<2;i++){
        for(int j=0;j<=N;j++){
            for(int k=0;k<=1000*N;k++){
                dp[i][j][k]=INF;
            }
        }
    }

    dp[0][0][0]=0;
    int t=0;
    int rest=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=i;j++){
            for(int k=0;k<=rest;k++){
                if(dp[t][j][k]==INF) continue;

                chmin(dp[1-t][j][k],dp[t][j][k]);

                int thousand=(1000-P[i]%1000)%1000;
                rest=max(rest,k+thousand);
                if(thousand>=500) chmin(dp[1-t][j+1][k+thousand-500],dp[t][j][k]+P[i]);
                else chmin(dp[1-t][j][k+thousand],dp[t][j][k]+P[i]);

                int z=0;
                if(thousand==0) z=500;
                else if(thousand<500) z=500-thousand;
                if(z==0) continue;
                if(z>k) continue;

                chmin(dp[1-t][j+1][k-z],dp[t][j][k]+P[i]);
            }
        }

        for(int j=0;j<=i;j++){
            for(int k=0;k<=rest;k++){
                dp[t][j][k]=INF;
            }
        }
        t=1-t;
    }

    int ma=0,mi=INF;
    for(int j=N;j>=0;j--){
        for(int k=0;k<=1000*N;k++){
            if(dp[t][j][k]==INF) continue;
            ma=j;
            mi=min(mi,dp[t][j][k]);
        }
        if(ma>0) break;
    }
    cout<<ma<<" "<<mi<<endl;
}

int main(){
  while(1){
      cin>>N;
      if(N==0) break;
      solve();
  }

  return 0;
}



Measured memory_bytes: 82028
import java.util.Scanner


object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n, m = sc.nextInt()

    val as = List.fill(m)(sc.nextInt)

    val ans = if (n < as.sum) -1 else n - as.sum

    println(ans)

  }
}

Measured memory_bytes: 57640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n , x) for (int i = (int)(x); i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 1; --i)
#define repBX(i, n , x) for (int i = (int)(n); i >= int(X); --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int K,N;
    cin >> K >> N;
    vector<int> A(N);
    vector<int> dist(N);
    cin >> A[0];
    int MaxDist = 0;
    int MaxI = 0;
    repX(i,N,1){
        cin >> A[i];
        dist[i] = A[i]-A[i-1];
        if(MaxDist<dist[i]){
            MaxDist = dist[i];
            MaxI = i;
        }
    }
    dist[0] = A[0] + (K - A[N - 1]);
    if (MaxDist < dist[0])
    {
        MaxDist = dist[0];
        MaxI = 0;
    }
    int ans = 0;
    rep(i,N){
        if(i==MaxI)continue;
        ans += dist[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4836
#include<stdio.h>

int main(void){
    int N,M,i,A[10000];

    scanf("%d%d",&N ,&M);
    for(i=0; i<M; i++)
        scanf("%d",&A[i]);
    
    for(i=0; i<M; i++){
        N = N - A[i];
    }
    if(N < 0){
        printf("-1");
    }
    else 
        printf("%d",N);
        
    return 0;
}

Measured memory_bytes: 1768
#include <bits/stdc++.h>
const int N=6e5+5;

int n,m=1,k,p,o[N]; char s[N];

int main()
{
	scanf("%d%d%s",&n,&k,s+1); int i;
	for (i=1; i<=n; i++) o[i]=s[i]=='A';
	
	for (i=1; i<=k&&i<=n+n; i++)
		if (o[m]^p) o[m]^=1;
		else p^=1,o[++m+n-1]=p^1;
	if (k<=n+n){for (i=m; i<=n+m-1; i++) putchar((o[i]^p)?'A':'B');}
	else
	{
		if ((n&1)&&(k-n-n&1)) putchar((o[m]^p^1)?'A':'B');
		else putchar((o[m]^p)?'A':'B');
		for (i=m+1; i<=n+m-1; i++) putchar((o[i]^p)?'A':'B');
	} 
	
	return 0;
}

Measured memory_bytes: 5840
#include <bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define ALL(C) (C).begin(),(C).end()
#define INPUT(P) std::cin>>(P)
#define INPUT2(P1,P2) std::cin>>(P1)>>(P2)
#define INPUT3(P1,P2,P3) std::cin>>(P1)>>(P2)>>(P3)
// #define INPUTS(I,A,B,V) FOR(I,A,B)cin>>V[I]
#define INPUTS(I,N,V) REP(I,N) std::cin>>V[I]
#define OUTPUT(P) std::cout<<P<<std::endl
#define OUTPUT2(P1,P2) std::cout<<P1<<P2<<std::endl
#define OUTPUT3(P1,P2,P3) std::cout<<P1<<P2<<P3<<std::endl
// #define OUTPUTS(I,A,B,V) FOR(I,A,B)cout<<V[i]<<endl
#define OUTPUTS(I,N,V) REP(I,N) std::cout<<V[i]<<std::endl
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ul;
const int MOD = 1000000007;
const ll INF = 1e18;
using namespace std;
int i,j,k;
int N,X;
int x[100000];
int z;
int gcd(int a, int b){
  if(b==0)return a;
  else return gcd(b,a%b);
}

inline void solve(){
  INPUT2(N,X);
  INPUTS(i,N,x);
  z = abs(X-x[0]);
  FOR(i,1,N){
    z = gcd(abs(X-x[i]),z);
  }
  cout<<z<<endl;
  return;
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int n;//人数
  int k;//初期ポイント
  int q;//正解回数
  int a[100000];//正解者
  int p[100000]={0};//ポイント失う
  int b;
  scanf("%d %d %d",&n,&k,&q);
  for(int i=0;i<q;i++){
    scanf("%d",&a[i]);
    b=a[i]-1;
    p[b]=p[b]+1;
  }
  for(int i=0;i<n;i++){
    if(k-q+p[i]<=0){
        printf("No\n");
    }
    else printf("Yes\n");
  }

  return 0;
}

Measured memory_bytes: 1280
b = []
(a = gets.chomp.to_i).times do
  b.push(gets.chomp.to_s)
end
unless b.size != b.uniq.size
  for inc in 0...a-1
    unless b[inc].slice(-1) == b[inc+1].slice(0)
      puts "No"
      exit
    end
  end
else
  puts "No"
  exit
end
puts "Yes"

Measured memory_bytes: 1788
var
  max,i,j,n,k:longint;
  s:char;
begin
  readln(n);
  for i:=1 to n do
  begin
    read(s);
    if s='I' then k:=k+1 else k:=k-1;
    if max<k then max:=k;
  end;
  writeln(max);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,k,a[200005],b[200005]={};
	int now=1,j=1;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
  int c=0;
	for(long long i=k;i>0;i--){
		b[now]=j;
		if(b[a[now]]!=0 && c==0){
			i%=(b[now]-b[a[now]]+1);
          	c=1;
		}
      	if(i!=0)
		now=a[now];
		j++;
	}
	cout<<now<<endl;
  return(0);
}

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

using ll = long long;

int main() {
  // 入力
  int N, K;
  cin >> N >> K;
  int x[N], y[N];
  for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

  ll ans = 1LL << 62;
  for (int i = 0; i < N; i++) { // x座標の左端
    for (int j = 0; j < N; j++) { // x座標の右端
      for (int k = 0; k < N; k++) { // y座標の下端
        for (int l = 0; l < N; l++) { // y座標の上端
          if (x[i] > x[j]) continue;
          if (y[k] > y[l]) continue;
          // 4点で作られる長方形に囲まれる点の数を数える
          int cnt = 0;
          for (int m = 0; m < N; m++) {
            if (x[i] <= x[m] && x[m] <= x[j] && y[k] <= y[m] && y[m] <= y[l]) cnt++;
          }

          if (cnt >= K) ans = min(ans, 1LL * (x[j] - x[i]) * (y[l] - y[k]));
        }
      }
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
/*
AOJ - ITP1_5_D
Date: 20180923
Author: Mikoron
 */

#include<stdio.h>

#define N 100

int main(void) {
        int n, i;
        int a[N];

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

        for(i = n-1 ; i >= 0; i--) {
                printf("%d", a[i]);
                if(i != 0) printf(" ");
        }
        printf("\n");

        return 0;
}



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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;

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

int main()
{
    string s;
    cin>>s;
    for(int i=0;i<sz(s);++i){
        if(s[i]==',')
            cout<<" ";
        else
        {
            cout<<s[i];
        }
        
    }
    p();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

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

int main() {
	int W,H,N;
	cin >> W >> H >> N;
	VI x(N), y(N), a(N);
	REP(i, N) cin >> x[i] >> y[i] >> a[i];
	int left = 0, right = W, bottom = 0, top = H;
	
	REP(i, N){
		if (a[i] == 1) left = max(left, x[i]);
		if (a[i] == 2) right = min(right, x[i]);
		if (a[i] == 3) bottom = max(bottom, y[i]);
		if (a[i] == 4) top = min(top, y[i]);	
	}

	cout << (((right - left) > 0 && (top - bottom) > 0) ? (right - left)*(top - bottom):0) << endl;
	return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A_i={}
ans=0
for i in range(N):
    if i-A[i] in A_i:
        ans+=A_i[i-A[i]]
    if i+A[i] in A_i:
        A_i[i+A[i]]+=1
    else:
        A_i[i+A[i]]=1
print(ans)


Measured memory_bytes: 40520
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int a,b;
    cin >>a>>b;
    if(1<=a&&a<=9&&1<=b&&b<=9){
        cout<<a*b<<endl;
    }
    else{
        cout<<-1<<endl;
    }
}
    



Measured memory_bytes: 256
#include <bits/stdc++.h> // imports every library in c++
using namespace std; // ; is essential | says that you are USING the libraries

//  COMMAND TO USE WHEN RUNNING CODE: g++ day6.cpp -o day6 -std=c++11 -O2  | to run: ./(name of file)  //

int N;

int main() {
    cin >> N;
    cout << (N*N*N);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const ll MOD=1e9+7;
const int N=1e5+5;
vector<int> g[N];
ll dp[N][2];
int n;

ll f(int u, int p, int b){
	ll &r=dp[u][b];
	if(r!=-1)return r;
	r=1;
	for(int v:g[u])if(v!=p){
		ll rd=f(v,u,0);
		if(b!=1){
			rd+=f(v,u,1);
			if(r>=MOD)r-=MOD;
		}
		r=(r*rd)%MOD;
	}
	return r;
}

int main(){FIN;mset(dp,-1);
	cin >> n;
	fore(x,1,n){
		int u,v;cin>>u>>v;u--;v--;
		g[u].pb(v);g[v].pb(u);
	}
	cout << (f(0,-1,0)+f(0,-1,1))%MOD << "\n";
}

Measured memory_bytes: 15616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s,t;cin>>s>>t;
    if(s.size()==t.size()-1){
        for(int i=0;i<s.size();i++)if(s[i]!=t[i]){cout<<"No";return 0;}
        cout<<"Yes";return 0;
    }
    cout<<"No";return 0;
    
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, n) for (size_t i = 0; i < (n); i++)
#define REP(n) FOR(i, n)
#define cinv(v, n) REP(n) {cin>>(v)[i];}
#define nvec(T, v, n) vector<T> v(n); cinv(v, n)
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
 
#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))
 
#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )
 
#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}
 
#define acm accumulate
#define pub push_back
#define pof pop_front
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))
 
#define GCD(v) gcd(ALL(v), 0l)
 
template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}
 
 
 
int main(){
  int n;
  cin>>n;
  long q = 0;
  for (long i = 1; i <= n; i++) {
    for (long j = 1; j <= n; j++) {
      long m = gcd(i,j);
      for (long k = 1; k <= n; k++) {
        q += gcd(m,k);
      }
    }
  }
  cout<<q;
}
 
 
 
 
 
 
/* きょむ〜 */

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl;
#define all(v) v.begin(), v.end()


int main() {
  int M;
  ll K;
  cin >> M >> K;
  if (K == 0) {
    rep(i,(1LL<<M)) {
      cout << i << " " << i << " ";
    }
    cout << endl;
    return 0;
  } else if (M == 1) {
    print(-1);
  } else if (K<(1LL<<M)) {
    rep(i,(1LL<<M)) {
      if (i == K)
        continue;
      cout << i << " ";
    }
    cout << K << " ";
    repr(i,(1LL<<M), 0) {
      if (i == K)
        continue;
      cout << i << " ";
    }
    cout << K << endl;
  } else {
    print(-1);
  }
  return 0;
}

Measured memory_bytes: 3592
n = int(input())
mn = 10**6
for m9 in range(n+1):
    cnt = 0
    m6 = n-m9
    while m9>0:
        i = 0
        while m9>=9**i:
            if 9**(i+1)<=m9:
                i+=1
            else:
                r = m9//(9**i)
                m9 -= r*(9**i)
                cnt += r
                i = 0
    while m6>0:
        i = 0
        while m6>=6**i:
            if 6**(i+1)<=m6:
                i+=1
            else:
                r = m6//6**i
                m6 -= r*6**i
                cnt += r
                i = 0
    if cnt < mn:
        mn = cnt

print(mn)


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

using namespace std;

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int min_price = a * x + b * y;
    int num_max = max(x, y);
    for (int i = 2; i <= num_max * 2; i += 2) {
        int tmp = c * i;    // AB pizza
        tmp += a * max((x - i / 2), 0);
        tmp += b * max((y - i / 2), 0);

        if (tmp < min_price)
            min_price = tmp;
    }

    cout << min_price << '\n';
}


Measured memory_bytes: 256
class priorityQueue {
  constructor() {
    this.keys = [];
    Number.prototype.parentIdx = function() { return (this- 1) >> 1; };
    Number.prototype.leftIdx = function() { return (this << 1) + 1; };
    Number.prototype.rightIdx = function() { return (this << 1) + 2; };
  }

  insert(key) { this.heapIncrease(this.keys.push(key) - 1); }

  heapIncrease(idx) {
    const keys = this.keys;
    for (let i=idx, p=idx.parentIdx(); i > 0 && keys[i] > keys[p]; i=p, p=i.parentIdx())
      keys[p] = [keys[i], keys[i] = keys[p]][0];
  }

  extract() {
    const res = this.keys[0];
    this.keys[0] = this.keys.pop();
    this.maxHeapify(0);
    return res;
  }

  maxHeapify(idx) {
    const keys = this.keys, n = keys.length;
    const innerMaxHeapify = (i) => {
      let left = i.leftIdx(), right = i.rightIdx(), largest = i;
      if (left < n && keys[left] > keys[largest]) largest = left;
      if (right < n && keys[right] > keys[largest]) largest = right;
      if (largest != i) {
        keys[largest] = [keys[i], keys[i] = keys[largest]][0];
        innerMaxHeapify(largest);
      }
    };
    innerMaxHeapify(idx);
  }
}

(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n').slice(0, -1);
  const queue = new priorityQueue();
  let str = '';
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
      case 'i': queue.insert(Number(cmd.split(' ')[1])); break;
      case 'e': str += `${queue.extract()}\n`; break;
    }
  });
  process.stdout.write(str);
})();




Measured memory_bytes: 204000
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 1
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()


n = k()
S = list(v())

for i in range(len(S)):
    a = AL.index(S[i])
    ans = a+n
    if ans >= 26:
        ans = (a+n)-26
    S[i] = AL[ans]

print("".join(S))

Measured memory_bytes: 10576
N = int(input())
A = list(map(int, input().split()))
A = [A[i] for i in range(N) if A[i] % 2 == 0]
for j in range(len(A)):
    if A[j] % 3 == 0 or A[j] % 5 == 0:
        A[j] = True
    else:
        A[j] = False

if all(A):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38384
a,b,k = map(int,input().split())
if a == b:
    print(a)
    exit()
lis = []
x = min(b-a,k)
for i in range(a,a+x):
    lis.append(i)
for j in range(b,b-x,-1):
    lis.append(j)
ans = sorted(set(lis))
for k in ans:
    print(k)

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

struct point {double x,y,f;};

point cross(point p1,point p2,point p3,point p4) {
	double s,t;
	p3.f=0;
	t=(p2.y-p1.y)*(p4.x-p3.x)-(p2.x-p1.x)*(p4.y-p3.y);
	if (t==0) { p3.f=1; return p3;}
	s=((p3.y-p1.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p3.x-p1.x))/t;
	p3.x+=s*(p4.x-p3.x);
	p3.y+=s*(p4.y-p3.y);
	if (s<0 || s>1) p3.f=1; 
	return p3;
} 

double lpdist(point p1,point p2,point p3) {
	double d,dx,dy;
	dx=p2.x-p1.x; dy=p2.y-p1.y;
	d=(p3.x*dy-p3.y*dx+p1.y*dx-p1.x*dy)/sqrt(dx*dx+dy*dy);
	if (d<0) d=-d;
	return d;
	}
	
void polys(int n,point *p,double (*d)[100]) {
	int i,j,a,b;
	for (i=0;i<n;i++) {
		d[i][(i+1) % n]=d[i][i]=0;
		for (j=2;j<n;j++) { a=(i+j) % n; b=(i+j+n-1) % n;
		d[i][a]=d[i][b]+((p[b].x-p[i].x)*(p[a].y-p[i].y)-(p[b].y-p[i].y)*(p[a].x-p[i].x))/2;
	    }
     }
 }
 
int main() {
   int i,j,k,n,a,b;
   double ans,hi,v,d,s,g;
   point p[100],ph,pl,pm,p1,p2,p3 ;
   double ps[100][100];
   while(cin >> n >> d >> v && n+d+v!=0) {
   for (i=0;i<n;i++) cin >> p[i].x >> p[i].y;
   polys(n,p,ps);
   ans=0;  
   for (i=0;i<n;i++) {
	   hi=0;
	   for (j=2;j<n;j++) {g=lpdist(p[i],p[(i+1) % n],p[(i+j) % n]);
	                      if (g>hi) { hi=g; ph=p[(i+j) % n];}
	      }
      pl=p[i]; 
      for (j=0;j<64;j++) {
		  pm.x=(ph.x+pl.x)/2; pm.y=(ph.y+pl.y)/2;  
		  p3.x=pm.x+(p[(i+1) % n].x-p[i].x); p3.y=pm.y+(p[(i+1) % n].y-p[i].y);
		  for (k=0;k<n-1;k++) {
			p1=cross(pm,p3,p[(i+k+1) % n],p[(i+k+2) % n]);
			if (p1.f==0) { a=(i+k+1) % n; break;}
	     	}
	     for (k=0;k<n-1;k++) {
			p2=cross(pm,p3,p[(n+i-k) % n],p[(n+i-k-1) % n]);
			if (p2.f==0) { b=(n+i-k) % n; break;}
		    }
		 s=0;
		 s+=ps[i][a]+((p[a].x-p[i].x)*(p1.y-p[i].y)-(p[a].y-p[i].y)*(p1.x-p[i].x))/2;
		 s+=((p1.x-p[i].x)*(p2.y-p[i].y)-(p1.y-p[i].y)*(p2.x-p[i].x))/2;
		 s+=((p2.x-p[i].x)*(p[b].y-p[i].y)-(p2.y-p[i].y)*(p[b].x-p[i].x))/2+ps[b][i];
		 if (s*d<v) pl=pm;
		 if (s*d>v) ph=pm;
		 if (s*d==v) break;
		 }
		g=lpdist(p[i],p[(i+1) % n],pm);
		if (g>ans) ans=g;
		}
	  printf("%.6f\n",ans);
  }  
   return 0;
} 

Measured memory_bytes: 1272
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s = sc.next();
		int ans =0;
		int k=0;
		for(int i = 0; i<s.length(); i++){
			if(s.charAt(i)=='A'){
				k++;
			}else if(s.charAt(i)=='T'){
				k++;
			}else if(s.charAt(i)=='C'){
				k++;
			}else if(s.charAt(i)=='G'){
				k++;
			}else{
				ans=Math.max(ans,k);
				k=0;
			}
			
		}
		ans=Math.max(ans,k);
		System.out.println(ans);
	}
}


Measured memory_bytes: 23760
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
int main(){
    double a,b;cin>>a>>b;
    cout<<a/b<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  char a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  if(a==f&&b==e&&c==d) cout<< "YES" << endl;
  else cout<< "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
line = input().rstrip().split(" ")
a = int(line[0])
b = int(line[1])
c = int(line[2])
d = int(line[3])

if b>= 0 and d >= 0:
    print(max(b * d, a * c))
elif b <= 0 and d >= 0:
    print(max(b * c, a * c))
elif b >= 0 and d <= 0:
    print(max(a * d, a * c))
else:
    print(a * c)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#include <fstream>
#include<string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


typedef  long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;


#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=3e5+5;
ll mod=1e9+7;
ll mul (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll add (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a+b+mod)%mod;
}
ll fastpow(ll b, ll p)
{
    if(p==0)
        return 1;
    ll ans=fastpow(b,p/2);
    ans=mul(ans,ans);
    if(p%2)ans=mul(ans,b);
    return ans;
}

ll g1[N],g2[N],arr[N];
int main()
{
    FIO
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=1;i<n;i++)
    {
        g1[i]=__gcd(g1[i-1],arr[i-1]);
    }
     for(int i=n-2;i>=0;i--)
    {
        g2[i]=__gcd(g2[i+1],arr[i+1]);
    }
    ll ans=0;
    for(int i=0;i<n;i++)
        ans=max(ans,__gcd(g1[i],g2[i]));
    cout<<ans;



    return 0;
}

Measured memory_bytes: 5884
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;

int main(){
	int x;
	bool isprime[200001];
	isprime[1] = false;
	for(int i=2;i<=200000;i++) isprime[i] = true;
	for(int i=2;i<=200000;i++){
		if(isprime[i]){
			for(int j=i*2;j<=200000;j+=i){
				isprime[j] = false;
			}
		}
	}
	cin >> x;
	for(int i=x;;i++){
		if(isprime[i]){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
  string S;
  cin >> S;
  int N=S.length(), K=N;
  for (int i=1; i<N; i++) {
    if (S[i-1]!=S[i]) {
      K=min(K,max(i,N-i));
    }
  }
  printf("%d\n",K);
  return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	int n,k,l[50],t,i,j,sum;
	cin>>n>>k;
	for(i=0;i<n;i++) cin>>l[i];
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(l[i]<l[j]){
				t=l[i];
				l[i]=l[j];
				l[j]=t;
			}
		}
	}
	sum=0;
	for(i=0;i<k;i++)sum+=l[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
class Tree:
    def __init__(self, orders):
        self.root = None
        for order in orders:
            if len(order) == 1:
                self.inorder_print()
                self.preorder_print()
            else:
                self.insert(int(order[1]))

    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y

        if not y:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def inorder_print(self):
        self.root.inorder_print()
        print()

    def preorder_print(self):
        self.root.preorder_print()
        print()


class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

    def inorder_print(self):
        if self.left:
            self.left.inorder_print()
        print(' {}'.format(self.key), end='')
        if self.right:
            self.right.inorder_print()

    def preorder_print(self):
        print(' {}'.format(self.key), end='')
        if self.left:
            self.left.preorder_print()
        if self.right:
            self.right.preorder_print()


if __name__ == '__main__':
    import sys
    m = int(input())
    orders = [line.strip().split() for line in sys.stdin]
    # orders = [input().split() for i in range(m)]
    Tree(orders)



Measured memory_bytes: 243920
object Main extends App {
  import scala.io.StdIn.readLine
  
  def exchange(x:Int,y:Int,z:Int):Int={
  if((x % 2 == 0) && (y % 2 == 0) && (z % 2 == 0)){1+exchange((x+y)/2,(y+z)/2,(z+x)/2)}
    else return 0
  }

  	val cookies =readLine.split(" ").map(_.toInt);
  val a = cookies(0)
  val b = cookies(1)
  val c = cookies(2)
  if(a == b && b == c){if(a % 2 == 0){println("-1")}else println("0")}
  else {
  println(exchange(a,b,c))
  }
}


Measured memory_bytes: 54680
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
      String k = in.nextLine();  
      String S = in.nextLine();
      int K = Integer.parseInt(k);
     
      if (S.length()<=K){
          System.out.println(S);
         }
         else {
           System.out.println(S.substring(0,K)+ "...");
                }
        }
    }


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

typedef long long ll;
typedef pair<ll, ll> P;
const int mod = 1e9 + 7;

ll N, M;
vector<ll> A, B;

int main() {
    cin >> N >> M;
    A.resize(N);
    B.resize(N);

    rep(i, N) cin >> A[i] >> B[i];

    vector<vector<ll>> jobs(M);
    rep(i, N) {
        if (M - A[i] < 0) continue;
        jobs[M - A[i]].push_back(B[i]);
    }

    priority_queue<ll> q;
    ll ans = 0;
    for (ll i = M - 1; i >= 0; i--) {
        for (auto b : jobs[i]) {
            q.push(b);
        }

        if (!q.empty()) {
            ll value = q.top();
            ans += value;
            q.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7168
N,M=map(int,input().split())
H=list(map(int,input().split()))
G=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
ans=0
for i in range(0,N):
    tmp=H[i]
    Highest=True
    for h in G[i]:
        if H[h]>=tmp:
            Highest=False
            break
    if Highest:
        ans+=1
print(ans)

Measured memory_bytes: 29492
/* 
    HARSHAD VAGHASIYA

        @DAIICT
    
          H_M_Vaghasiya
    
  */

#include <iostream>
#include <vector>

using namespace std;

vector<int> G[200000];
long add[200000];
bool used[200000];





void dfs(int v){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]){
            add[G[v][i]] += add[v];
            dfs(G[v][i]);
        }
    }
}

int main(){
    int N, Q;
    cin >> N >> Q;
    for(int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 0; i < Q; i++){
        int p, x;
        cin >> p >> x;
        p--;
        add[p] += x;
    }
    dfs(0);
    for(int i = 0; i < N-1; i++){
        cout << add[i] << ' ';
    }
    cout << add[N-1] << endl;
}


Measured memory_bytes: 24448
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

struct UFTree(T)
{
    struct Node
    {
        T parent;
        T rank = 1;
    }

    ///
    T min_size, max_size;

    ///
    this(T n)
    {
        nodes.length = n;
        sizes.length = n;
        foreach (i, ref node; nodes) {
            node = Node(i.to!T);
            sizes[i] = 1;
        }

        min_sizes.length = n + 1;
        min_sizes[1] = n;
        min_size = 1;
        max_size = 1;
    }

    ///
    bool unite(T a, T b)
    {
        a = root(a);
        b = root(b);

        if (a == b) return false;

        auto a_size = sizes[a];
        auto b_size = sizes[b];
        --min_sizes[a_size];
        --min_sizes[b_size];
        ++min_sizes[a_size + b_size];
        foreach (nxt_size; min(a_size, b_size)..min_sizes.length) if (min_sizes[nxt_size] != 0) {
            min_size = nxt_size.to!T;
            break;
        }
        max_size = max(max_size, a_size + b_size);

        if (nodes[a].rank < nodes[b].rank) {
            sizes[a] += sizes[b];
            nodes[b].parent = a;
        } else {
            sizes[b] += sizes[a];
            nodes[a].parent = b;
            if (nodes[a].rank == nodes[b].rank) ++nodes[b].rank;
        }

        return true;
    }

    ///
    bool is_same(T a, T b)
    {
        return root(a) == root(b);
    }

    ///
    T size(T i)
    {
        return sizes[root(i)];
    }

private:
    Node[] nodes;
    T[] sizes;
    T[] min_sizes;

    T root(T i)
    {
        if (nodes[i].parent == i) return i;

        return nodes[i].parent = root(nodes[i].parent);
    }
}

///
UFTree!T uftree(T)(T n)
{
    return UFTree!T(n);
}

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    int[] as, bs;
    foreach (_; 0..M) {
        auto ab = readln.split.to!(int[]);
        as ~= ab[0]-1;
        bs ~= ab[1]-1;
    }
    int r;
    foreach (i; 0..M) {
        auto uft = uftree(N);
        foreach (j; 0..M) if (i != j) {
            uft.unite(as[j], bs[j]);
        }
        if (!uft.is_same(as[i], bs[i])) ++r;
    }
    writeln(r);
}

Measured memory_bytes: 380
// God be praised
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
vector<int> S[N], E[N];

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

	for (int i = 0, a, b; i < m; i++) {
		scanf("%d %d", &a, &b);

		if (a > b) swap(a, b);
		if (a == b) assert(false);

		S[a].push_back(i);
		E[b].push_back(i);
	}

	int ans = 0;
	unordered_set<int> cur;

	for (int i = 1; i < N; i++) {
		bool should = false;
		for (int e : E[i]) {
			if (cur.count(e)) {
				should = true;
				break;
			}
		}

		if (should) {
			cur.clear();
			ans++;
		}

		for (int s : S[i]) {
			cur.insert(s);
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 11900
#pragma GCC optimize("O3")

#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;

typedef long long ll;
typedef pair<int, int> pi;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

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

    int n,k;
    cin >> n >> k;
    vector<ll> arr(n);
    F0R(i,n)
        cin >> arr[i];
    sort(arr.begin(),arr.end());
    ll tot=0;
    F0R(i,n-k)
        tot+=arr[i];
    cout << tot;

    return 0;
}


Measured memory_bytes: 1792
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <stdio.h>

int A[100];
int main(void) {
 
    long double w,h,x,y;
    long double a;
    scanf("%llf %llf %llf %llf",&w,&h,&x,&y);
    a = w*h/2;
    int b = 0;
    if(w/2==x&&h/2==y)b=1;
    else b=0;
    printf("%.9llf %d",a,b);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t,n,m,i,tong=0,a[100000];
    cin >> n >> m;
    for(i=1;i<=m;i++)
    {
        cin >> t;
        tong+=t;
    }
    if(n >= tong) cout << n-tong;
    else cout << -1;
}


Measured memory_bytes: 3628
#include<stdio.h>

#define MAX 1001

int main(void)
{
	while(1)
	{	
	    int i,j,H,W,N,p[MAX][MAX],dp[MAX][MAX];
	    scanf("%d%d%d",&H,&W,&N);
		if(H==0 && W==0 && N==0) break;
	    for(i=0;i<=H-1;i++)
	    {
		    for(j=0;j<=W-1;j++)
		    {
			    scanf("%d",&p[i][j]);
		    }
	    }
	    for(i=0;i<=H;i++)
	    {
		    for(j=0;j<=W;j++)
		    {
			    dp[i][j]=0;
		    }
	    }
	    dp[0][0]=N-1;
	    for(i=0;i<=H-1;i++)
	    {
		    for(j=0;j<=W-1;j++)
		    {
			    if(dp[i][j]%2==0)
			    {
				    dp[i+1][j]+=dp[i][j]/2;
				    dp[i][j+1]+=dp[i][j]/2;
			    }
			    else
			    {
				    if(p[i][j]==0)
				    {
					    dp[i+1][j]+=dp[i][j]/2+1;
				        dp[i][j+1]+=dp[i][j]/2;
				    }
				    else
				    {
					    dp[i+1][j]+=dp[i][j]/2;
				        dp[i][j+1]+=dp[i][j]/2+1;
				    }
				    p[i][j]=1-p[i][j];
			    }
		    }
	    }
	    i=0;
	    j=0;
	    while(i!=H && j!=W)
	    {
		    if(p[i][j]==0)
		    {
			    i++;
		    }
		    else
		    {
			    j++;
		    }
	    }
	    printf("%d %d\n",i+1,j+1);
	}
	return 0;
}

Measured memory_bytes: 8428
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using ll = long long;
using ull = unsigned long long;
ull mod = 1e9 + 7;
using namespace std;

constexpr double toAngle(double rad){
  constexpr double pi = 3.141592;
  return rad * 180 / pi;
}

int main(){

  double a, b, x; cin >> a >> b >> x;
  double S = x / a;
  double ans = 0;
  if(S >= a * b / 2){
    double h = (a * b - S) * 2 / a;
    ans = toAngle(atan2(h, a));
  }else{
    double w = S * 2 / b;
    ans = toAngle(atan2(b, w));
  }

  cout << setprecision(10) << ans;

}

Measured memory_bytes: 256
using System;

class project{
static void Main(){

  string [] inp = Console.ReadLine().Split(' ');
  int a = Convert.ToInt32(inp[0]);
  int b = Convert.ToInt32(inp[1]);
  int c = Convert.ToInt32(inp[2]);
  
  int result = (a-b < c) ? c-a+b :0;
  Console.WriteLine(result);
}
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(b-a == c-b) cout <<"YES"<<endl;
  else cout << "NO" <<endl;
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    prev=0


    for i in numbers:
        if i==0:
            prev=i
        else:
            if prev<=i:
                prev=i
            elif prev <=i+1:
                prev=i+1
            else:
                print("No")
                exit()
    print("Yes")

if __name__=="__main__":
    main()

Measured memory_bytes: 20500
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int n;
  cin>>n;
  int a[n];
  REP(i,n){
    cin>>a[i];
    a[i]--;
  }
  vector<bool> visited(n,false);
  int cur=0;
  int ans=0;
  while(1){
    if(cur==1){
      cout<<ans<<endl;
      break;
    }
    if(!visited[cur]){
      visited[cur]=true;
      ans++;
      cur = a[cur];
    }else{
      cout<<-1<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.math.*;
import java.io.*;
 
class Main {
	static final int INF = 2 << 29;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] list = new int[] {1,5,10,50,100,500};
		int sum = 0;
		for(int i = 0; i < list.length; i++) {
			sum += list[i] * sc.nextInt();
		}
		System.out.println((sum >= 1000)?1:0);

	}
}
             
        

Measured memory_bytes: 17344
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
 string a, b,c,d;
	//string s="error";
	cin >> a;// cin >> b; cin >> c; cin >> d;
	a[5] = ' ';
	a[13] = ' ';

	cout<<a<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
bool flag[250000];
int a[250000];
int main()
{
	memset(flag,1,sizeof(flag));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d",&a[i]);
	for(int i=m;i>=1;i--)
		if(flag[a[i]])
		printf("%d\n",a[i]),flag[a[i]]=0;
	for(int i=1;i<=n;i++)
		if(flag[i])
			printf("%d\n",i);
		return 0;
}

Measured memory_bytes: 3348
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

int main(){
    int n;
    cin >> n;
    vector<int> c, s, f;
    rep(i, n-1){
        int x, y, z;
        cin >> x >> y >> z;
        c.push_back(x);
        s.push_back(y);
        f.push_back(z);
    }
    rep(i, n-1){
        int res=s[i];
        rep2(j, i, n-1){
            if(res<s[j]){
                res = s[j];
            }
            if(res%f[j]){
                res += f[j] - res%f[j];
            }
            res += c[j];
        }
        cout << res << endl;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int a[3];
bool flag[3];
void solve(){
  int ans = 10000;
  ans = min(ans, abs(a[0] - a[1]) + abs(a[1] - a[2])) ;
  ans = min(ans, abs(a[0] - a[2]) + abs(a[2] - a[1])) ;
  ans = min(ans, abs(a[1] - a[0]) + abs(a[0] - a[2])) ;
  ans = min(ans, abs(a[1] - a[2]) + abs(a[2] - a[0])) ;
  ans = min(ans, abs(a[2] - a[0]) + abs(a[0] - a[1])) ;
  ans = min(ans, abs(a[2] - a[1]) + abs(a[1] - a[0])) ;
  cout << ans << endl;
  
  return ;
}
int main(){
  cin >> a[0] >> a[1] >> a[2];
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)


int main(void){
    int n,k;
    cin >> n >> k;

    string buf;
    cin >> buf;

    if(buf.at(k-1) == 'A'){
        buf.at(k-1) = 'a';
    }else if(buf.at(k-1) == 'B'){
        buf.at(k-1) = 'b';
    }else{
        buf.at(k-1) = 'c';
    }

    cout << buf << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, M, i, A[100001], max, ans=0;
    priority_queue<ll> pq;

    cin >> N >> M;

    for(i=1; i<=N; i++){
        cin >> A[i];
        pq.push(A[i]);
    }

    for(i=1; i<=M; i++){
        max = pq.top();
        pq.pop();
        max /= 2;
        pq.push(max);
    }

    while(!pq.empty()){
        ans += pq.top();
        pq.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2036
#include <cstdio>
#include <algorithm>
using namespace std;

int n,k,d[100005],a[100005],ss=0,sum[100005];
bool tmp;

int main(void){
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++)
	scanf("%1d",&d[i]);
	for(int i=1;i<=n;i++){
		a[i]=(d[i]^d[i-1]);
	}
	for(int i=1;i<=n;i++)
	sum[i]=sum[i-1]+a[i];
	int b=0,ans=0;
	for(int i=1;i<=n;i++){
		b^=a[i];
		int x=upper_bound(sum,sum+1+n,k*2-(!b)+sum[i])-sum;
		ans=max(ans,x-i);
	}
	printf("%d\n",ans);
} 

Measured memory_bytes: 1280
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int limit = sc.nextInt();
    int cost;
    int time;
    int ans = -1;
    boolean con = true;
    
   	for(int i = 0; i < n;i++){
      cost = sc.nextInt();
      time = sc.nextInt();
      if(time <= limit){
        if(ans == -1) ans = cost;
        else if(cost < ans) ans = cost;
      	}
    }
    
    if(ans == -1) System.out.println("TLE");
    else System.out.println(ans);
  }
}


Measured memory_bytes: 36152
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x=2019;
    int y= 04;
    int z=30;
    int a,b , c;
    char p;
    cin>>a>>p>>b>>p>>c;
    if (a<=x and b<=y and c<=z){
        cout<<"Heisei"<<endl;
    }
    else cout<<"TBD"<<endl;
       return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    REP(i, N) {
        cin >> P.at(i);
    }
    int cnt = 0;
    int min_v = INF;
    REP(i, N) {
        if(min_v > P.at(i)) {
            cnt++;
        }
        min_v = min(min_v, P.at(i));
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<string>
#include<vector>
#include<fstream>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<cwctype>
#include<algorithm>
#include<math.h>

using namespace std;

int data[101];

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>data[i];
	}

	for(int i=1;i<=n;i++){
		if(i==1)cout<<data[i];
		else cout<<" "<<data[i];
	}

	cout<<endl;

	for(int j=2;j<=n;j++){
		int key=data[j],i=j-1;

		while(i>0 && data[i]>key){
			data[i+1]=data[i];
			i--;
		}

		data[i+1]=key;
		for(int i=1;i<=n;i++){
			if(i==1)cout<<data[i];
			else cout<<" "<<data[i];
		}
		cout<<endl;
	}
	
		return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<math.h>

int main(void) {
	int X,i,j,flag=0;
	scanf("%d", &X);
	for (i = 1; i <=330; i++) {
		for (j = -330; j <= i; j++) {
			if (powl(i,5) - powl(j,5) == X) {
				printf("%d %d\n", i, j);
                flag=1;
				break;
			}
		}
        if(flag==1) break;
	}

	return 0;
}

Measured memory_bytes: 2112