akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
const ll MOD = 1e9 + 7;

void mainsolve(){

	ll n,c;
	cin >> n >> c;
	vector<vector<bool>> memo(c,vector<bool>(1e5, false));

	rep(i,n){
		ll s,t,cc;
		cin >> s >> t >> cc;
		--s; --t; --cc;

		for(ll j = s; j <= t; j++) memo[cc][j] = true;
	}

	ll res = 0;
	rep(i,1e5){
		ll cnt = 0;
		rep(j,c){
			if(memo[j][i]) cnt++;
		}

		res = max(res, cnt);
	}

	cout << res << endl;

	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int n,i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		if(i%3==0) printf(" %d",i);
		else{
			for(j=i;j!=0;j/=10){
				if(j%10==3){
					printf(" %d",i);
					break;
				}
			}
		}
	}
	printf("\n");
	return 0;
}

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

using namespace std;

const int oo = 1e9;

struct SegmentTree
{
    vector<long long> IT, Lazy;
    vector<int> Low, High;
    void InitTree(int x, int Left, int Right, int type)
    {
        Low[x] = Left;
        High[x] = Right;
        Lazy[x] = 0;
        if (Left == Right)
        {
            IT[x] = type * Left;
            return;
        }
        int Mid = (Left + Right) / 2;
        InitTree(x * 2, Left, Mid, type);
        InitTree(x * 2 + 1, Mid + 1, Right, type);
        IT[x] = min(IT[x * 2], IT[x * 2 + 1]);
    }
    void doLazy(int x)
    {
        if (Lazy[x] == 0)
        {
            return;
        }
        IT[x * 2] = Lazy[x * 2] = Lazy[x];
        IT[x * 2 + 1] = Lazy[x * 2 + 1] = Lazy[x];
        Lazy[x] = 0;
    }
    void Update(int x, int Left, int Right, long long Val)
    {
        if (Low[x] > Right || High[x] < Left)
        {
            return;
        }
        if (Low[x] >= Left && High[x] <= Right)
        {
            IT[x] = Val;
            Lazy[x] = Val;
            return;
        }
        doLazy(x);
        Update(x * 2, Left, Right, Val);
        Update(x * 2 + 1, Left, Right, Val);
        IT[x] = min(IT[x * 2], IT[x * 2 + 1]);
    }
    long long Get(int x, int Left, int Right)
    {
        if (Low[x] > Right || High[x] < Left)
        {
            return oo;
        }
        if (Low[x] >= Left && High[x] <= Right)
        {
            return IT[x];
        }
        doLazy(x);
        return min(Get(x * 2, Left, Right), Get(x * 2 + 1, Left, Right));
    }
    void Init(int n, int type)
    {
        IT.resize(4 * n + 5);
        Lazy.resize(4 * n + 5);
        Low.resize(4 * n + 5);
        High.resize(4 * n + 5);
        InitTree(1, 1, n, type);
    }
};

int n, m;
SegmentTree SMT1, SMT2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    SMT1.Init(m, 0);
    SMT2.Init(m, -1);
    int u, v;
    for (int i = 1; i <= n; i++)
    {
        cin >> u >> v;
        if (v < m)
        {
            long long tmp = SMT2.Get(1, u, v);
            long long val = SMT1.Get(1, v + 1, v + 1);
            if (val > tmp + v + 1)
            {
                SMT1.Update(1, v + 1, v + 1, tmp + v + 1);
                SMT2.Update(1, v + 1, v + 1, tmp);
            }
        }
        SMT1.Update(1, u, v, oo);
        SMT2.Update(1, u, v, oo);
        long long Ans = SMT1.Get(1, 1, m);
        if (Ans == oo)
        {
            Ans = -1;
        }
        else
        {
            Ans += i;
        }
        cout << Ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 40620
#include <bits/stdc++.h>
#define ll long long
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
int main() {
  INIT;
  
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c == 17 && (a == 5 || a == 7) && (b == 5 || b == 7) && (c == 5 || c == 7) ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N,K;
    string S;
    cin>>N>>K>>S;
    int happy=0;
    int rl=0;
    rep(i,N-1){
        if(S[i]==S[i+1]) happy++;
        else rl++;
    }
    happy = min(happy+2*K,N-1);
    cout<<happy<<endl;
}

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

#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define LL long long
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;

template<typename T>
inline int getplc(T x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}

LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}

template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) {
	return max(a, Smax(args...));
}
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) {
	return min(a, Smin(args...));
}

template <typename T>
#define errorl(args...) {  \
	string _s = #args;   \
	replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    errl(_it, args);  \
}
void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}
#define error(args...) {  \
    string _s = #args;  \
    replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    err(_it, args);  \
    cerr<<endl; \
}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}

int a[N];

void Solve() {
	int n;
	cin >> n;

	int d = 0, ans = 1;

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

		if (i == 1 || a[i] == a[i - 1]) continue;

		if (d == 1 && a[i] >= a[i - 1]) continue;
		else if (d == -1 && a[i] <= a[i - 1]) continue;
		else {
			if (d == 0) d = ((a[i] > a[i - 1]) ? 1 : -1);
			else ans++, d = 0;
		}
	}

	cout << ans << endl;
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
//  freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}


Measured memory_bytes: 3996
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	int N;
	cin >> N;
    pair<pair<string, int>, int>A[110];

	for (int i = 0; i < N; i++)
	{
		string S;
		int P;
		cin >> S >> P;
		A[i] = make_pair(make_pair(S, -P), i);
	}

	sort(A, A + N);
	for (int i = 0; i < N; i++)
	{
		cout << A[i].second+1 << endl;
	}

	return 0;
}

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

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC095_B();
        }

        static void ABC095_B()
        {
            var NX = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var N = NX[0];
            var X = NX[1];

            var ans = N;
            var m = new List<int>();
            for (var n = 0; n < N; n++)
            {
                var value = int.Parse(Console.ReadLine());
                m.Add(value);
                X -= value;
            }
            Console.WriteLine(X / m.Min() + ans);
        }
    }
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int R = count(S.begin(), S.end(), 'R');
  int cnt = 0;
  for (int i = 0; i < R; i++) {
    if (S.at(i) != 'R') cnt++;
  }
  cout << cnt << "\n";
}

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


int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v.at(i);
    double ans;
    double tmp;
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++){
        if (i == 0){
            tmp = v.at(i);
        }
        else{
            tmp = (v.at(i) + tmp) / 2;
        }
    }
    
    ans = tmp;
    
    cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
t = input()

if s==t:
    print('Yes')

else:
    for i in range(len(s)-1):
        lst =[]
        lst.append(s[i+1:])
        lst.append(s[:i+1])

        if ''.join(lst)==t:
            print('Yes')
            break

    else:
        print('No')

Measured memory_bytes: 3068
#include <cstdio>
int main()
{
	int a[25];
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	int cnt = 0;
	for (int i = 1; i < n - 1; i++) {
		if ((a[i] - a[i - 1]) * (a[i] - a[i + 1]) < 0)
			cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
N,K = [int(x) for x in input().split()]
num0 = 0
num1 = 0
if(K%2 == 0):
    num1 = int(N/K)
    num0 = int(N/K*2)-num1
else:
    num1 = int(N/K)
print(num1**3+num0**3)


Measured memory_bytes: 2940
N, K = map(int, input().split())

res = 0
P = 10 ** 9 + 7
for i in range(K, N + 2):
    head = i * (i - 1) // 2#先頭i個の和
    tail = i * (2*N - i + 1) // 2#先頭i個の和
    res += tail - head + 1
    res %= P
print(res)

Measured memory_bytes: 63708
/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 02-Aug-2020 18:38:57
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void INT(T &n) {
    n = 0; int f = 1; int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void INT(T &x, W &y) {INT(x), INT(y);}
template <TN T, TN W, TN Q> inline void INT(T &x, W &y, Q &z) {INT(x, y), INT(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;


int solve() {
    int n, k; cin >> n >> k;
    int l = 1, r = 0;
    vector<int> a(n);
    for (int &x : a) {
        cin >> x;
        umax(r, x);
    }

    int res = 0;
    while (l <= r) {
        int mid = l + r >> 1;
        int cuts = 0;
        for (int i = 0; i < n; ++i) {
            cuts += ((a[i] - 1) / mid);
        }
        if (cuts <= k) {
            res = mid;
            r = mid - 1;
        } else if (cuts > k) {
            l = mid + 1;
        }
    }

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

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0;
    // INT(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}

Measured memory_bytes: 3960
import numpy as np

A, B, C = (int(i) for i in input().split())

output=[]
output.append(A+B*10+C)
output.append(A+C*10+B)
output.append(B+A*10+C)
output.append(B+C*10+A)
output.append(C+A*10+B)
output.append(C+B*10+A)

print(np.max(np.array(output)))


Measured memory_bytes: 14448
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
 
 
void solve(){
    int a,b;
    cin>>a>>b;
    if(a==b)cout<<"Draw"<<endl;
    else if(a>b && b!=1 || a==1){
        cout<<"Alice"<<endl;
    }else{
        cout<<"Bob"<<endl;
    }
}
 
signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

C = Counter(A)
ans = 1
if N % 2 == 0:
    for i in range(1, N, 2):
        if C[i] != 2:
            print(0)
            exit()
        ans *= 2
        ans %= MOD
else:
    if C[0] != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if C[i] != 2:
            print(0)
            exit()
        ans *= 2
        ans %= MOD
print(ans)


Measured memory_bytes: 14812
# coding: utf-8

import math
import re
import numpy as np
import copy

S = input().split(" ")
X = int(S[0])
Y = int(S[1])

possible = True

#鶴とかめ（切り捨て）
crane = (4*X - Y) // 2
turtle = (-2*X+Y) // 2

if crane < 0 or turtle < 0:
    possible = False

else:
    if crane + turtle != X:
        possible = False
    elif 2*crane + 4*turtle != Y:
        possible = False

if possible:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 27184
#include <stdio.h>
#include<stdlib.h>


int main()
{
  int array[1000];
  int n;
  int i, j,mini, t;
  int count=0;
  
//number of array
  scanf("%d", &n);

//selectionsort
  for (i = 0; i < n; i++)
    scanf("%d", &array[i]);

  for (i = 0; i < (n - 1); i++) // finding minimum element (n-1) times
  {
    mini = i;

    for (j = i + 1; j < n; j++)
    {
      if (array[mini] > array[j])
        mini = j;
        
    }
    if (mini !=i)
    {
      t = array[i];
      array[i] = array[mini];
      array[mini] = t;
      count++;
    }
   
  }


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

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


Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int K=3,P=1e9+7; 

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }

struct Matrix{
	int a[3][3]; 
	Matrix(){ 
		lop(i,0,K){
			a[i][i]=1; 
		}
	}
	Matrix operator*(const Matrix &r) const{
		Matrix c; mem(c.a,0); 
		lop(i,0,K)lop(j,0,K)lop(k,0,K){
			c.a[i][j]=add(c.a[i][j],mul(a[i][k],r.a[k][j])); 
		}
		return c;
	}
} res,nor,spec;

void gao(int c){
	Matrix t=nor;
	for(;c;c>>=1,t=t*t)if(c&1){
		res=res*t; 
	}
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin); 
#endif
	mem(nor.a,0),mem(spec.a,0);
	lop(i,0,K){
		for(int j=0;i+j<=2;++j){
			++nor.a[i][i+j];
			++spec.a[i][i+j];
			if(i+j==2)++nor.a[i][0];
		}
	}
	++nor.a[1][2],++nor.a[1][0],++spec.a[1][2];
	int n,m,lst=0;
	read(n),read(m); 
	while(m--){
		int x;
		read(x); 
		gao(x-lst-1); 
		res=res*spec;
		lst=x;
	}
	if(lst!=n)gao(n-lst); 
	printf("%d\n",res.a[0][2]);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int ave=0;
  rep(i, N) {
    cin >> a[i];
    ave+=a[i];
  }
  ave = round((double)ave/N);
  int ans=0;
  rep(i, N) ans += pow(a[i]-ave, 2);
  cout << ans << endl;
  return 0;
}

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


int char_to_int(char c){
  switch(c){
    case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
  }
}


int main(){
  ll N;
  cin >> N;
  vector <char> S(N);
  rep(i,N) cin >> S.at(i);
  
  ll W = 0;
  vector <ll> Wl(N);  
  //i 番目の人をリーダーにしたとき、それより左の人の中で、Wを向いている人数。
  
  Wl.at(0) = 0; 
  
  rep (i, N){
    if(S.at(i) == 'W'){
      W++;
    }
    if(i>0){
      if(S.at(i-1) == 'W'){
        Wl.at(i) = Wl.at(i-1) + 1;
      }else{
        Wl.at(i) = Wl.at(i-1);
      }
    }
  }
  
  ll E = N - W;
  
  vector<int> res(N);
  
  rep(i,N){
    int El = i - Wl.at(i);
    int Er;
    if(S.at(i) == 'E'){
      Er = E - El - 1;
    }else{
      Er = E - El;
    }
    
    res.at(i) = Wl.at(i) + Er;
  }
  
  int res_min = res.at(0);
  rep(i,N){
    if(res_min > res.at(i)){
      res_min = res.at(i);
    }
  }
  
  //rep(i,N) cout << res.at(i) << endl;
  cout << res_min;
    
  
  
  
                         
                         
}

Measured memory_bytes: 4096
#include <iostream>
using namespace std;
#include <stdio.h>
int main()
{
	char str;
	int count[26] = { 0 }, i = 0, k;
	str = getchar();
	while (str != EOF){
		if ('a' <= str && str <= 'z'){ k = str - 'a'; count[k]++; }
		if ('A' <= str && str <= 'Z'){ k = str - 'A'; count[k]++; }
		str = getchar();
	}
	for (i=0;i<26;i++){
		printf("%c : %d\n", 'a' + i, count[i]);
	}
	return 0;
}

Measured memory_bytes: 1104
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vl a(n);
    rep(i,n){
        cin >> a[i];
    }
    vl b=a;
    sort(b.begin(),b.end());
    rep(i,n){
        if(a[i]==b[n-1]){
            cout << b[n-2] << endl;
        }
        else{
            cout << b[n-1] << endl;
        }
    }
}

Measured memory_bytes: 6432
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = (int)1e9;
const int N = 2020;
char s[N];
vector<int> g[N];
int dp[N][3];
int n;
int ans = INF;

void dfs(int v, int par) {
	dp[v][0] = dp[v][1] = dp[v][2] = 0;
	if (s[v] == '1')
		dp[v][0]++;
	pii b = mp(0, 0);
	for (int u : g[v]) {
		if (u == par) continue;
		dfs(u, v);
		dp[v][0] += dp[u][0];
		pii t = mp(dp[u][2] + dp[u][0], dp[u][1] + dp[u][0]);
		dp[v][2] += t.first;
		b = max(b, t);
	}
  	assert(b.second <= b.first);
	if (b.second > dp[v][2] - b.first) {
		dp[v][1] = b.second - (dp[v][2] - b.first);
	} else {
		dp[v][1] = dp[v][2] & 1;
	}
}

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

	scanf("%d", &n);
	scanf("%s", s);
	for (int i = 1; i < n; i++) {
		int v, u;
		scanf("%d%d", &v, &u);
		v--;u--;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	for (int v = 0; v < n; v++) {
		dfs(v, -1);
		if (dp[v][1] == 0)
			ans = min(ans, dp[v][2]);
	}
	if (ans == INF)
		printf("-1\n");
	else
		printf("%d\n", ans / 2);

	return 0;
}


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

int main() {
    int n;
    cin >> n;
    double a;
    for(int i = 1; i <= n; i = i + 1) {
        if(i * 1.08 >= n && i * 1.08 < n + 1) {
            cout << i << endl;
            break;
        }
        if(i == n) cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	
	// print a + a^2 + a^3
	
	int A;
	int sum = 0;	
	scanf("%d", &A);
	int B = A*A;
	int C = A*A*A;
	sum = A + B + C;
	
	printf("%d", sum);
	
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

string ans[3] = {"Sunny","Cloudy","Rainy"};

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	string s;cin>>s;
	if(s==ans[0]){
		cout<<ans[1]<<endl;
	}else if(s==ans[1]){
		cout<<ans[2]<<endl;

	}else{
		cout<<ans[0]<<endl;
	}
	































	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM + 7
#define MAX 10100000
#define INF 1e15
#define MAP 110
#define initial_value -1
#define LINF 1LL << 60
#define Pair pair<int, int>
#define chmax(a, b) (a < b ? a = b : 0)
#define chmin(a, b) (a > b ? a = b : 0)
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
ll N,A,B,C,D;
int main(){
    cin >> N >> A >> B >> C >> D;
    ll diff = B-A;
    bool ans = false;
    for(ll i = 0; i < N; i++){
        ll ma = i*D - (N-i-1)*C;
        ll mi = i*C - (N-1-i)*D;
        if(mi <= diff && diff <= ma) ans = true;
    }
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(){
	int n, med;
	cin >> n;
	vector<ll> a(n);
	ll tmp;
	for(int i=0; i<n; i++){
		cin >> tmp;
		a[i] = tmp - i - 1;
	}
	sort(a.begin(), a.end());

	if(n%2==1){
		med = a[n/2];
	}else{
		med = (a[n/2-1]+a[n/2])/2;
	}

	ll sum = 0;

	for(int i=0; i<n; i++){
		sum += abs(a[i] - med);
	}
	cout << sum << endl;
}

Measured memory_bytes: 1792
# Aizu Problem 0047: Cup Game
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

IDX = {'A': 0, 'B': 1, 'C': 2}
cups = [1, 0, 0]
for line in sys.stdin:
    a, b = [IDX[_] for _ in line.strip().split(',')]
    cups[a], cups[b] = cups[b], cups[a]

print(chr(65 + cups.index(1)))

Measured memory_bytes: 7608
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 数字の数 */
	private static final int N = 3;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int[] a = new int[N];
			IntStream.range(0, N).forEach(i -> a[i] = scanner.nextInt());
			Arrays.sort(a);
			System.out.println(getResult(a[N - 1] - a[0], a[N - 1] - a[1]));
		}
	}

	/**
	 * aとbになるための操作回数
	 * 
	 * @param a
	 * @param b
	 * @return 操作回数
	 */
	private static int getResult(int a, int b) {
		// aとbの差分が奇数の場合
		if (1 == ((a - b) & 1)) {
			return getResult(a + 1, b) + 1;
		}
		return (a + b) / 2;
	}
}


Measured memory_bytes: 26580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;

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

    int a, b;
    cin >> a >> b;
    int res = -1;
    for(int i = 1; i <= 100000; ++i){
        int foo = 0.08 * i;
        int bar = 0.1 * i;
        if(foo == a && bar == b){
            res = i;
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, a, b, num[5007], dp[5007][5007], res = 1e18;
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
signed main()
{
	n = read();
	a = read();
	b = read();
	for (int i = 1; i <= n; i++)
		num[i] = read();
	memset(dp, 0x3f, sizeof dp);
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= n; j++)
			if (num[i] > j)
			{
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + a);
				dp[i][num[i]] = min(dp[i][num[i]], dp[i - 1][j]);
			}
			else dp[i][j] = min(dp[i][j], dp[i - 1][j] + b);
	for (int i = 0; i <= n; i++)
		res = min(res, dp[n][i]);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 196224
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

string N;

int solve(){
  string s = (N);
  int cou = 0;
  while(s != "6174"){
    sort(s.begin(),s.end());
    if(s.front() == s.back()) return -1;
    int S = atoi(s.c_str());
    reverse(s.begin(),s.end());
    int L = atoi(s.c_str());
    s = to_string(L - S);
    while(s.size() < 4) s.push_back('0');
    cou++;
  }

  return cou;
}
int main(){
  while(cin >> N,N != "0000"){
    int ans = solve();
    if(ans == -1){
      cout << "NA" << endl;
    }
    else{
      cout << ans << endl;
    }
  }
}



Measured memory_bytes: 3212
#include <iostream>

using namespace std;
long long correct[100001];
int main() {
    long long N,K,Q;
    cin >> N >> K >> Q;
    long long A[100001];
    for (int i=0; i<Q; i++) cin >> A[i];

    for (int i=0; i<Q; i++) {
        correct[A[i]-1]++;
    }
    
    for (int i=0; i<N; i++) {
        if (K + correct[i] - Q <= 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,l,r;
  cin >> n >> l >> r;
  int ans=0;
  REP(i,1,n+1) {
    int x=i,sum=0;
    while(x) {
      sum+=x%10;
      x/=10;
    }
    if(l<=sum&&sum<=r) ans+=i;
  }
  pr(ans);
}

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


Measured memory_bytes: 256
import java.util.*;
public class Main { //クラス名はMain
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.next();
        int c=0;
        for(int i=0;i<n;i++){
			char a=s.charAt(i);
            if(i==0){
              c++;
            }else{
            	char b=s.charAt(i-1);
                if(a!=b)c++;
            }
            
        }
        //int o=((int)Math.pow(sum,2)-sum2)/2;
        System.out.println(c);
    }
}

Measured memory_bytes: 24224
#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;
  vll a(n), b(n), c(n);
  REP(i, n) cin >> a.at(i) >> b.at(i) >> c.at(i);
  vll dpa(n, 0), dpb(n, 0), dpc(n, 0);
  dpa.at(0) = a.at(0); dpb.at(0) = b.at(0); dpc.at(0) = c.at(0);
  rep(i, 1, n) {
    dpa.at(i) = max(dpb.at(i-1), dpc.at(i-1)) + a.at(i);
    dpb.at(i) = max(dpc.at(i-1), dpa.at(i-1)) + b.at(i);
    dpc.at(i) = max(dpa.at(i-1), dpb.at(i-1)) + c.at(i);
  }
  cout << max(dpa.at(n-1), max(dpb.at(n-1), dpc.at(n-1))) << endl;
  return 0;
}


Measured memory_bytes: 4992
import java.util.*;
import java.io.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                PrintWriter ou = new PrintWriter(System.out);
                int n = Integer.parseInt(sc.next());
                int sum = 0;
                int[] t = new int[n];
                for(int i = 0 ; i < n ; i++){
                        t[i] = Integer.parseInt(sc.next());
                        sum += t[i];
                }
                int m = Integer.parseInt(sc.next());
                int[][] p = new int[2][m];
                for(int i = 0 ; i < m ; i++){
                        for(int j = 0 ; j < 2 ; j++){
                                p[j][i] = Integer.parseInt(sc.next());
                        }
                        ou.print(sum - t[p[0][i] - 1] + p[1][i] + "\n");
                }
                sc.close();
                ou.flush();
        }
}

Measured memory_bytes: 38480
#include<iostream>
using namespace std;
int main()
{
	char a[5],b[5];
	cin>>a>>b;
	int i,j;
	if(a[0]==b[2]&&a[2]==b[0]&&a[1]==b[1])
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define tii tuple<int,int,int>
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
int main(){
    int n=in();
    ll k=lin();
    vecll a(n),f(n);
    rep(i,n)a[i]=in();
    rep(i,n)f[i]=in();
    sort(ALL(a));
    sort(ALL(f));

    vector<pair<ll,int>>p(n);
    rep(i,n)p[i]=mp(a[i]*f[n-1-i],f[n-1-i]);
    sort(ALL(p));
    ll l=-1,r=p[n-1].first+1;
    ll ans=0;
    while(l+1<r){
        ans = (l+r)/2;
        ll tmp=0;
        auto itr=upper_bound(ALL(p),mp((ll)ans,INT_MAX));
        while(itr<p.end()){
            tmp += (((*itr).first - ans) + (*itr).second - 1)/(*itr).second;
            itr ++;
        }
        if(tmp>k) l=(l+r)/2;
        else r=(l+r)/2;
    }
    cout<<r<<endl;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) cin >> vec.at(i);
	vector<int> rank(n);
	for (int i = 0; i < n; i++) {
		rank.at(vec.at(i) - 1) = i + 1;
	}
	cout << rank.at(0);
	for (int i = 1; i < n; i++) cout << " " << rank.at(i);
}

Measured memory_bytes: 1536
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int N = Integer.valueOf(s.next());
		long[] A = new long[N];
		for(int i = 0; i < N; i++) {
			A[i] = Long.valueOf(s.next());
		}
		Arrays.sort(A);

		long ret = A[N-1];
		int index = 2;
		int cnt = 0;
		for(int i = 2; i < N; i++) {
			ret += A[N-index];
			if(i%2 == 1) {
				index++;
			}
		}
		System.out.println(ret);
	}
}

Measured memory_bytes: 61792
def isPrime(n):
    for i in range(2,int(n**.5+1)):
        if n%i==0:
            return False
    return True
while 1:
    n=int(input())
    if not n:break
    for i in range(n,1,-1):
        if isPrime(i) and isPrime(i-2):
            print(i-2,i)
            break


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

using namespace std;
template<typename T> void in(T &x) { x = 0; bool neg = false; register T c = getchar(); if (c == '-')neg = true, c = getchar(); while ((c < 48) || (c > 57))c = getchar(); for (; c < 48 || c > 57; c = getchar()); for (; c > 47 && c < 58; c = getchar())x = (x << 3) + (x << 1) + (c & 15); if (neg) x *= -1; }
template<typename T> void out(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); }
template<typename T> void outln(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); putchar('\n'); }
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define fastIO ios_base::sync_with_stdio(false); cin.tie(false);
#define ll long long
#define itr(_c) for(auto i=_c.begin();i!=_c.end();i++)
#define itrr(_c)for(auto i=_c.begin();i!=_c.end();i++)
#define f1(_x)for (int i = 0; i < _x; ++i)
#define fr(_x)for (int i = _x; i >0; i--)
#define f2(_x,_y)for (int i = _x; i < _y; ++i)
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi; typedef vector<string> vs; typedef vector<bool> vb; vector<long long>vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;

int n[101]={};
int main() {
	int a, b;
	std::cin >> a >>b;
	std::cout << (a <= 0 ? b >= 0 ? "Zero" : ((b - a) % 2 == 0 ? "Negative" : "Positive") : "Positive");


	
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++) cin>>v[i];
  sort(v.rbegin(),v.rend());
  vector<int> z,o;
  while(!v.empty()&&v.back()==0) z.push_back(0),v.pop_back();
  while(!v.empty()&&v.back()==1) o.push_back(1),v.pop_back();
  if(o.empty()&&(int)z.size()%2){
    if(v.empty()){
      for(int i:z) cout<<i<<endl;
      return 0;
    }
    o.push_back(v.back());
    v.pop_back();
  }
  sort(v.begin(),v.end());
  if(*----v.end()==2&&*--v.end()==3)
    swap(v[v.size()-2],v[v.size()-1]);
  for(int i:v) cout<<i<<endl;
  if((int)z.size()%2){
    z.pop_back();
    for(int i:z) cout<<i<<endl;
    cout<<o.back()<<endl;
    o.pop_back();
    cout<<0<<endl;
    for(int i:o) cout<<i<<endl;
  }else{
    for(int i:z) cout<<i<<endl;
    for(int i:o) cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

int main(void) {
    int q; cin >> q;
    lint s = 0;
    lint c = 0;
    
    /*
    auto show = [](multiset<lint> m) {
        for (auto e: m) {
            cout << e << " ";
        }
        cout << endl;
    };
    */
    
    multiset<lint> zen, kou;
    
    rep (q) {
        int t; cin >> t;
        if (t == 1) {
            
            lint a, b;
            cin >> a >> b;
            c += b;
            
            if (zen.empty()) {
                zen.insert(a);
                kou.insert(a);
                s = 0;
                continue;
            }
            
            lint x = *zen.rbegin();
            lint y = *kou.begin();
            if (x <= a and a <= y) { //relax
            }
            else {
                s += min(abs(x-a), abs(y-a));
            }
            
            if (a < x) {
                kou.insert(x);
                zen.erase(--zen.end());
                zen.insert(a);
                zen.insert(a);
            }
            else if (x <= a and a <= y) {
                zen.insert(a);
                kou.insert(a);
            }
            else {
                zen.insert(y);
                kou.erase(kou.begin());
                kou.insert(a);
                kou.insert(a);
            }
            //cout << "zen = "; show(zen);
            //cout << "kou = "; show(kou);
            //dump(s); dump(c); el;    
        }
        else {
            cout << *zen.rbegin() << " ";
            cout << s + c << endl;
        }
    }
    
}

Measured memory_bytes: 18944
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
mask = 1
ret = 0
for i in range(70):
    on = 0
    off = 0
    for a in A:
        if a & mask:
            on += 1
        else:
            off += 1
    ret += (on * off) * mask
    ret %= MOD
    mask *= 2

print(ret)
    


Measured memory_bytes: 122808
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;

	int x = a*b;
	if (x % 2 == 0) {
		cout << "Even" << endl;
		return 0;
	} else {
		cout << "Odd" << endl;
		return 0;
	}
}


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

int main() {
    string s;
    cin >> s;
    int a = 0, l = s.size();
    for(int i = 0; i < l/2; i++) {
        if(s[i] != s[l - 1 - i]) a++;
    }
    cout << a << endl;

    return 0;
}

Measured memory_bytes: 256
/*                    ___          |\    /|           ____   ____   ____  ____
   |     |    /\    /    \ |     | | \  / |    /\    |    \ |    \ |     |    \
   |_____|   /__\   \____  |_____| |  \/  |   /__\   |____/ |____/ |__   |____/
   |     |  /    \       \ |     | |      |  /    \  |      |      |     |   \
   |     | /      \ \____/ |     | |      | /      \ |      |      |____ |    \
*/
#include<bits/stdc++.h>
using namespace std;
#define lb lower_bound
#define ub upper_bound
#define pf push_front
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pi pair<int,int>
#define pl pair<long,long>
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define endl '\n'
#define loop(i,n) for(ll i=0;i<n;i++)
#define mod ((ll)(1e9+7))
#define in(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define vl vector<ll>
#define ml unordered_map<ll,ll> 
#define vpll vector<pair<ll,ll>>
#define INF 0x3f3f3f3f
#define mp make_pair

int main() {
    ll r;
    in(r);
    cout<<r*r<<endl;
    return 0;
}



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

int n;
vector<vector<pair<int, bool>>> g(100000);
vector<bool> d(100000);

void dfs(int v, int prev) {
	for (auto &x : g[v]) {
		if (x.first == prev)
			continue;
		d[x.first] = d[v] ^ x.second;
		dfs(x.first, v);
	}
}

int main() {
	cin >> n;
	for (int i = 0, u, v, w; i < n - 1; i++) {
		cin >> u >> v >> w;
		u--, v--, w &= 1;
		g[u].emplace_back(v, w);
		g[v].emplace_back(u, w);
	}
	d[0] = 0;
	dfs(0, -1);
	for (int i = 0; i < n; i++) {
		cout << d[i] << endl;
	}
}



Measured memory_bytes: 8832
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = nextInt(scanner);
        if (x == 0) {
            System.out.println(1);
        }else {
            System.out.println(0);
        }
    }

    private static int nextInt(Scanner scanner) {
        return Integer.parseInt(scanner.next());
    }

    private static long nextLong(Scanner scanner) {
        return Long.parseLong(scanner.next());
    }

    private static float nextFloat(Scanner scanner) {
        return Float.parseFloat(scanner.next());
    }

    private static double nextDouble(Scanner scanner) {
        return Double.parseDouble(scanner.next());
    }


}


class UnionFind {
    int[] parent;

    UnionFind(int n) {
        parent = new int[n];
        Arrays.fill(parent, -1);
    }

    int find(int x) {
        if (parent[x] < 0) {
            return x;
        } else {
            parent[x] = find(parent[x]);
            return parent[x];
        }
    }

    void unite(int x, int y) {
        int rootX = find(x);
        int rootY = find(y);
        if (rootX == rootY) {
            return;
        }

        if (parent[rootX] > parent[rootY]) {
            int temp = rootX;
            rootX = rootY;
            rootY = temp;
        }
        parent[rootX] += parent[rootY];
        parent[rootY] = rootX;
    }

}


Measured memory_bytes: 35500
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    string S;
    cin >> S;
    int n = S.size();
    if (S[0] != 'A' || S[1] < 'a' || S[n-1] < 'a') {
        cout << "WA" << endl;
        return 0;
    }
    int cnt = 0;
    for (int i = 2; i < n - 1; ++i) {
        if (S[i] == 'C') {
            ++cnt;
            if (cnt > 1) {
                cout << "WA" << endl;
                return 0;
            }
        } else if (S[i] < 'a') {
            cout << "WA" << endl;
            return 0;
        }
    }
    if (cnt == 1) {
        cout << "AC" << endl;
    } else {
        cout << "WA" << endl;
    }
    return 0;
}


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

int main()
{
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());

	if (s.compare(t) < 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


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

int main(){
    int a,b;
    char s;
    while(1){
        cin >> a >> s >>b;
        if(s=='?') break;
        switch(s){
            case '+':
                cout << a+b <<endl;
                break;
            case '-':
                cout << a-b<<endl;
                break;
            case '*':
                cout << a*b<<endl;
                break;
            case '/':
                cout << a/b<<endl;
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 3060