akhauriyash/Code-Regression huggingface dataset:
// agc038_b
// Sorting a Segment

#include <bits/stdc++.h>
using namespace std;

#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define jn treapdidsu

#define INF (ll)1e18
#define mod 1000000007
#define maxn 200010

ll i, i1, j, k, k1, t, n, m, res, flag[10], a[maxn], b, x, xt[maxn][2], pf[maxn];
deque<ll> q;
vector<ll> adj[maxn];
bool visited[maxn];

void add(ll x) {
    while (!q.empty() && q.front() > x) q.pop_front();
    q.push_front(x);
}

void rm(ll x) {
    while (!q.empty() && q.back() == x) q.pop_back();
}

void dfs(ll s) {
    if (visited[s]) return;
    visited[s] = true;
    for (auto u : adj[s]) dfs(u);
}

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

    #if !ONLINE_JUDGE && !EVAL
        ifstream cin("input.txt");
        ofstream cout("output.txt");
    #endif

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

    pf[0] = 0;
    for (i = 1; i < n; i++) {
        pf[i] = pf[i - 1];
        if (a[i] > a[i - 1]) pf[i]++;
    }

    x = INF;
    for (i = 0; i < n - k + 1; i++) {
        if (pf[i + k - 1] == pf[i] + k - 1) {
            x = min(x, i);
            if (x != i && x != INF) {
                adj[x].pb(i); adj[i].pb(x);
            }
        }
    }

    k++;

    for (i = 0; i < 2; i++) {
        q.clear();
        m = 1 - 2 * i;
        for (j = 0; j < k; j++) add(m * a[j]);
        xt[0][i] = m * q.back();
        for (j = k; j < n; j++) {
            rm(m * a[j - k]); add(m * a[j]);
            xt[j - k + 1][i] = m * q.back();
        }
    }

    for (i = 0; i < n - k + 1; i++) {
        if (a[i] == xt[i][0] && a[i + k - 1] == xt[i][1]) {
            adj[i].pb(i + 1); adj[i + 1].pb(i);
        }
    }

    res = 0;
    for (i = 0; i < n - k + 2; i++) {
        if (visited[i] == false) {
            dfs(i); res++;
        }
    }

    cout << res;

    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    int l=0;
    int r=0;

    for(int i = 0; i < n; i++) {
        if(s[i]=='(') l++;
        else{
            if(l!=0) l--;
            else r++;
        }
    }

    cout << string(r,'(')+s+string(l,')') << "\n";

    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int H, W, h, w; cin >> H >> W >> h >> w;
	cout << H*W - h*W - w*H + w*h << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

#define PI 3.14159265359

int main(){
  long double A, B, H, M;
  long double ans;
  
  std::cin>>A>>B>>H>>M;
  
  ans = (60*H - 11*M)*PI/360;
  ans = A*A + B*B - 2*A*B*cosl(ans);
  ans = sqrtl(ans);
  
  std::cout << std::fixed << std::setprecision(15) <<ans;
  
  return 0;
}

Measured memory_bytes: 4164
#include<iostream>
using namespace std;
int main()
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int a[7], b[7];
    int z = 1;
    int I, aa, bb, cc;
    for (int i = 0; i < K; i++){
        z *= 4;
    }
    a[0] = 1;
    a[1] = 4;
    a[2] = 4 * 4;
    a[3] = 4 * 4 * 4;
    a[4] = 4 * 4 * 4 * 4;
    a[5] = 4 * 4 * 4 * 4 * 4;
    a[6] = 4 * a[5];
    for(int i = 0; i < z; i++){
        I = i;
        for(int j = 6; j > 0; j--){
            b[j] = 0;
            if(I >= a[j]){
                b[j] = I / a[j];
                I = I % a[j];
            }
        }
        b[0] = I;
        aa = A;
        bb = B;
        cc = C;
        for(int j = 0; j < 7; j++){
            if (b[j] == 1){
                aa *= 2;
            }
            else if(b[j] == 2){
                bb *= 2;
            }
            else if(b[j] == 3){
                cc *= 2;
            }
        }
        if(aa < bb && bb < cc){
            cout << "Yes";  
            goto exit;
        }
    }
    cout << "No";
    exit: ;
}

Measured memory_bytes: 3608
n,m=map(int,input().split())
st=[]
for i in range(n):
  s_d=list(map(int,input().split()))
  st.append(s_d)
cp=[]
for i in range(m):
  c_d=list(map(int,input().split()))
  cp.append(c_d)
sc=[]
for i in range(n):
  scd=[]
  for j in range(m):
    scd_d=abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
    scd.append(scd_d)
  sc.append(scd.index(min(scd))+1)
  
for i in range(n):
  print(sc[i])

Measured memory_bytes: 39408
#include <iostream>
#include <string>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
/*bool isPrime(long long n) 
{ long long i;
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false;
  
    return true; 
}

long long factorial(long long n) 
{    if(n==0||n==1)
     return 1;
     else
     return n*factorial(n - 1);  
} 

long long binarySearch(long long arr[], long long l, long long r, long long x) 
{ 
    while (l <= r) { 
        long long  m = l + (r - l) / 2; 
  
        
        if (arr[m] == x) 
            return m; 
  
      
        if (arr[m] < x) 
            l = m + 1; 
  
       
        else
            r = m - 1; 
    } 
    return -1; 
} 
*/

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
   
    long long n,rem,q;
    cin>>n;
    rem=n%1000;
     q=n/1000;
    if(rem==0)
    { 
     cout<<rem<<endl;
    }
    else 
      cout<<((q+1)*1000-n)<<endl;
    
    
    
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(){
  int n,m,i,j,k,nt,np,a[110]={};
  double d[110][110]={1};
  while(scanf("%d %d %d %d",&n,&m,&i,&j),n){
    for(k=0;k<110*110;k++)d[k/110][k%110]=a[k/110]=0;
    while(i--){
      scanf("%d",&k);
      a[k]=1;
    }
    while(j--){
      scanf("%d",&k);
      a[k]=2;
    }
    d[0][0]=1;
    for(i=0;i<m;i++){
      for(j=0;j<n;j++){
	for(k=1;k<7;k++){
	  nt=i+1;
	  np=j+k;
	  if(np>n)np=2*n-np;
	  if(a[np]==1)nt++;
	  if(a[np]==2)np=0;//printf("%d %d\n",nt,np);
	  d[nt][np]+=d[i][j]/6.0;
	}
      }
      d[i+1][n]+=d[i][n];
    }
    //for(i=0;i<7;i++)printf("%.10lf ",d[m][i]);printf("\n");
    printf("%.10lf\n",d[m][n]);
  }
  return 0;
}



Measured memory_bytes: 2704
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

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

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n,a,b;
        cin>>n>>a>>b;
        vl x(n);
        rep(i,n)cin>>x[i];
        ll res=0;
        rep(i,n-1){
            res+=min(a*(x[i+1]-x[i]),b);
        }
        cout<<res<<endl;
    }

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

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int V, all, mini;
int used[4], ans[4], rel[4];
vector< int > p(4);

int remain(int v) {
    int ret = 0;
    ret += v / 500; v %= 500;
    ret += v / 100; v %= 100;
    ret += v / 50;  v %= 50;
    ret += v / 10;
    return ret;
}

void Update(int *used, int sum) {
    int coins = (all - (used[0] + used[1] + used[2] + used[3])) + remain(sum - V);
    if(coins < mini) {
        for(int i = 0; i < 4; i++)
            ans[i] = used[i];
        mini = coins;
    }
}

void rec(int idx, int sum) {
    //cout << idx << " " << sum << endl;
    if(sum >= V) {
        Update(used, sum);
    }
    if(idx > 3) return;
    rec(idx + 1, sum);
    for(int i = 1; i <= p[idx]; i++) {
        used[idx] += i;
        rec(idx + 1, sum + rel[idx] * i);
        used[idx] -= i;
    }
}

int main() {

    bool enter = false;
    rel[0] = 500, rel[1] = 100, rel[2] = 50, rel[3] = 10;
    while(cin >> V, V) {
        if(enter) cout << endl;
        enter = true;
        memset(used, 0, sizeof(used));
        mini = INF, all = 0;
        for(int i = 3; i >= 0; i--) {
            cin >> p[i]; all += p[i];
        }
        rec(0, 0);

        for(int i = 3; i >= 0; i--)
            if(ans[i]) cout << rel[i] << " " << ans[i] << endl;
    }
}

Measured memory_bytes: 1192
N=int(input())
a=list(map(int,input().split()))
count4=0
countodd=0
for i in range(N):
  if a[i]%2==1:
    countodd+=1
  elif a[i]%4==0:
    count4+=1
if countodd + count4 == N:
  if countodd <= count4+1:
    print("Yes")
  else:
    print("No")
else:
  if countodd <= count4:
    print("Yes")
  else:
    print("No")

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b > d+c)
    cout << "Left" << endl;
  else if(a+b < d+c)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
/**
*    author:  y_takano
*    created: 19.06.2020 16:41:51
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

using namespace std;

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

  int n, x;

  for (;;)
  {
      int cnt = 0;
      cin >> n >> x;
      if (n == 0 && x == 0)
      {
          break;
      }
      
      for (size_t i = 0; i < n; i++)
      {
          for (size_t j = i + 1; j < n; j++)
          {
              for (size_t k = j + 1; k < n; k++)
              {
                  if (i + j + k + 3 == x)
                  {
                      cnt += 1;
                  }
              }
              
          }
      }
      cout << cnt << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3164
#include <stdio.h>

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

    int t_score = 0, h_score = 0;

    int i;

    for (i = 0; i < n; i++) {
        char t_card[101], h_card[101];

        scanf("%s", t_card);
        scanf("%s", h_card);

        int j;

        for (j = 0; t_card[j] != '\0' || h_card[j] != '\0'; j++) {
            if (t_card[j] > h_card[j]) {
                t_score += 3;
                break;
            } else if (t_card[j] < h_card[j]) {
                h_score += 3;
                break;
            }
        }

        if (t_card[j] == '\0' && h_card[j] == '\0') {
            t_score++;
            h_score++;
        }
    }

    printf("%d %d\n", t_score, h_score);

    return 0;
}

Measured memory_bytes: 596
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1e9+7;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,i,ans=0,mae=-1;cin>>n;
	for(i=0;i<n;i++){
		int gen;cin>>gen;
		if(mae==gen){ans++;gen=-1;}
		mae=gen;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 764
/*
 *
 *    I am o0o0oo00.
 *
 */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define p7          1000000007
#define p9          998244353
#define pb          push_back
#define ff          first
#define ss          second
#define vll         vector<ll>
#define pll         pair<ll,ll>
#define vpll        vector<pll>
#define mll         map<ll,ll>
#define test        ll T;cin>>T;while(T--)
#define ad(a,n)     vll a;a.resize(n);for(ll i=0;i<n;i++)cin>>a[i];
#define as(a,n)     for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define all(x)      x.begin(),x.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll powm(ll x, ll y, ll m = p7) {
    x = x % m; ll res = 1; while (y)
    {if (y & 1)res = res * x; res %= m; y = y >> 1; x = x * x; x %= m;} return res;
}
ll modi(ll a, ll m = p7) {return powm(a, m - 2, m);}
void yesno(bool f) {f ? cout << "YES" << endl : cout << "NO" << endl;}


void ss99()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

string k;
ll d;
ll dp[100005][102][2];


ll f(ll index, ll sum, ll tight)
{
    if (index == k.size())
        return sum == 0;
    if (dp[index][sum][tight] != -1 && tight != 1)
        return dp[index][sum][tight];
    ll ans = 0;
    ll n = tight ? k[index] - '0' : 9;
    for (ll i = 0; i <= n; i++)
    {
        ll new_tight = (k[index] - '0' == i) ? tight : 0;
        ans += f(index + 1, (sum + i) % d, new_tight);
        ans %= p7;
    }
    dp[index][sum][tight] = ans;
    return ans;
}


int32_t main()
{
    ss99();
//    test
    {
        cin >> k >> d;
        memset(dp, -1, sizeof(dp));
        ll ans = f(0, 0, 1);
        cout << (ans - 1 + p7) % p7 << endl;
    }
    return 0;
}

Measured memory_bytes: 160384
s=int(input())
n=s//3
ans=0
mod = 10**9+7
fac=[1]
inv=[]
for i in range(n+s):
  fac.append(fac[-1]*(i+2)%mod)
for i in range(n+s):
  inv.append(pow(fac[i],mod-2,mod))
def modcom(n,k,fac,inv):
  if k>n or k<0:
    return 0
  elif k==n or k==0:
    return 1
  else:
    return((fac[n-1]*inv[k-1]*inv[n-k-1])%mod)
for i in range(n+1):
  ans+=modcom(s-3*i+(i-1),i-1,fac,inv)
print(ans%mod)

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int l,r,d;cin>>l>>r>>d;
  int result=0;
  for(int i=l;i<=r;i++){
    if(i%d==0)result++;
  }

  cout<<result;

  return 0;
}



Measured memory_bytes: 3632
#include <stdio.h>
#define MAX 500000
#define Large 2000000000
int cnt;
int L[250000+2];
int R[250000+2];
int A[MAX];

void merge1(int l,int m,int r){
  int n1,n2,i;
  n1=m-l;   
  n2=r-m;    
  for(i=0;i<n1;i++){
    L[i]=A[l+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[m+i];
  }
  L[n1]=Large;
  R[n2]=Large;
  int i1=0,i2=0,j;
  for(j=l;j<r;j++){
    if(L[i1]<=R[i2]){
      A[j]=L[i1];
      i1++;
    }else{
      A[j]=R[i2];
      i2++;
    }
    cnt++;
  }
}
 
void mergesort(int l, int r){
  int m;
  if(l+1<r){
      m=(r+l)/2;
      mergesort(l,m);
      mergesort(m,r);
      merge1(l,m,r);
  }
}
 
 
 
int main() {
  int n,i;
  scanf("%d\n",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  mergesort(0,n);
  for(i=0;i<n;i++){
    if(i==n-1)printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 4504
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999999;



int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n),d(n);
    map<int,vector<int> > red;
    map<int,vector<int> > blue;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        red[a[i]].push_back(b[i]);
    }

    for(int i=0;i<n;i++){
        cin>>c[i]>>d[i];
        blue[c[i]].push_back(d[i]);
    }

    vector<int> rys(0);;

    int ans=0;
    for(int i=0;i<2*n;i++){
        if(blue[i].size()){
            int by=blue[i][0];
            if(rys.size()==0) continue;
            sort(rys.begin(),rys.end());
            int itr=lower_bound(rys.begin(), rys.end(), by) - rys.begin();
            if(itr==0) continue;
            rys.erase(lower_bound(rys.begin(), rys.end(), by)-1);
            ans++;
        }
        if(red[i].size()){
            rys.push_back(red[i][0]);
        }
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 3656
extern crate core;

use std::io::{self, Read};
use core::cmp::Ordering;
fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input);
    println!("{}", output);
}

fn run(input: String) -> String {
    let vec: Vec<&str> = input.split_whitespace().collect();
    let s = {
        let mut v = vec[0].chars().collect::<Vec<_>>();
        v.sort();
        v
    };
    let t = {
        let mut v = vec[1].chars().collect::<Vec<_>>();
        v.sort();
        v.reverse();
        v
    };
    match s.cmp(&t) {
        Ordering::Less => "Yes",
        _ => "No",
    }.to_string()
}

Measured memory_bytes: 4352
class PriorityQueue
  MIN = -(1 << 60)

  attr_reader :size

  def initialize(&block)
    @size = 0
    @heap = Array.new
    @get_key = block || :itself.to_proc
  end

  def empty?
    size == 0
  end

  def pop
    return nil if @size <= 0
    max = @heap[1]
    @heap[1] = @heap[@size]
    @size -= 1
    max_heapify(1)
    max
  end

  def push(x)
    @size += 1
    i = @size
    @heap[i] = x
    while i > 1 && @get_key.call(@heap[i / 2]) < @get_key.call(@heap[i])
      t = @heap[i / 2]
      @heap[i / 2] = @heap[i]
      @heap[i] = t
      i = i / 2
    end
  end

  def top
    return nil if @size <= 0
    @heap[1]
  end

  def to_a
    return [] if @size == 0
    @heap[1..@size]
  end

  private

  def max_heapify(i)
    l = 2 * i
    r = 2 * i + 1
    largest =
      l <= @size && @get_key.call(@heap[l]) > @get_key.call(@heap[i]) ? l : i
    largest = r \
      if r <= @size && @get_key.call(@heap[r]) > @get_key.call(@heap[largest])
    unless largest == i
      t = @heap[i]
      @heap[i] = @heap[largest]
      @heap[largest] = t
      max_heapify(largest)
    end
  end
end

require 'set'

X, Y, Z, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
C = gets.split.map(&:to_i)

sorted_a = A.sort_by { |n| -n }
sorted_b = B.sort_by { |n| -n }
sorted_c = C.sort_by { |n| -n }

candidates = []
sorted_a.each.with_index do |a, i|
  i += 1
  sorted_b.each.with_index do |b, j|
    j += 1
    sorted_c.each.with_index do |c, k|
      k += 1
      break if i * j * k > K
      candidates.push(a + b + c)
    end
  end
end
candidates.sort_by { |n| -n }.take(K).each do |n|
  puts n
end


Measured memory_bytes: 6776
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    while(t--)
    {
        int n,m,i,x,y,z;
        cin>>n;
        n=n%10;
        if(n==2 || n==4 || n==5 || n==7 || n==9)
            cout<<"hon"<<endl;
        else if(n==0 || n==1 || n==6 || n==8)
            cout<<"pon"<<endl;
        else
        {
            cout<<"bon"<<endl;
        }
        
    }
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>
#define NIL NULL
#define TREE_VALUE INT_MAX

typedef struct Node* NodePointer;
typedef NodePointer Tree;

typedef struct Node {
  int key;
  NodePointer p, left, right;
} Node;

NodePointer makeNode(int key) {
  NodePointer node = (NodePointer)malloc(sizeof(Node));
  node->key = key;
  node->p = node->left = node->right = NIL;
  return node;
}

void treeInsert(Tree tree, NodePointer z) {
  NodePointer y = NIL;
  NodePointer x = tree->left;
  while(x != NIL) {
    y = x;
    if(z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->p = y;
  if(y == NIL) {
    tree->left = z; // if T is empty
  } else if(z->key < y->key) {
    y->left = z;
  } else {
    y->right = z;
  }
}

void printInorder(NodePointer node) {
  if(node->left  != NIL) printInorder(node->left);
  if(node->key != TREE_VALUE) printf(" %d", node->key);
  if(node->right != NIL) printInorder(node->right);
}

void printPreorder(NodePointer node) {
  if(node->key != TREE_VALUE) printf(" %d", node->key);
  if(node->left  != NIL) printPreorder(node->left);
  if(node->right != NIL) printPreorder(node->right);
}

bool find(NodePointer node, int key) {
  if(node == NIL) return false;
  if(node->key == key) return true;
  else if(key < node->key)
    return find(node->left, key);
  else
    return find(node->right, key);
}

int main() {
  int N, key;
  char str[10];
  Tree tree;

  // initialize tree
  tree = makeNode(TREE_VALUE);

  scanf("%d", &N);
  while(N--) {
    scanf("%s", str);
    if(str[0] == 'i') {
      scanf("%d", &key);
      treeInsert(tree, makeNode(key));
    } else if(str[0] == 'p') {
      printInorder(tree);
      printf("\n");
      printPreorder(tree);
      printf("\n");
    } else {
      scanf("%d", &key);
      printf(find(tree,key)?"yes\n":"no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 9840
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): 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)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

a = s()
t = s()

a = sorted(a)
y = "".join(a)
t = sorted(t,reverse = True)
x = "".join(t)
if y < x:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9988
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, K;
	in >> N >> K;

	long double ans = 0;
	for (LL i = 1; i <= N; ++i)
	{
		long double res = 1. / N;
		LL num = i;
		while (num < K)
		{
			num *= 2;
			res *= 0.5;
		}
		ans += res;
	}

	out << std::fixed << std::setprecision(15);
	out << ans << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
#endif
}
const int N=2e5+5;
int n,a[N],top;
void input()
{
	int x;
	n=read<int>();
	For(i,1,n)
	{
		x=read<int>();
		if(x!=a[top])a[++top]=x;
	}
}
const int mo=1e9+7;
int dp[N],last[N];
void work()
{
	dp[0]=1;
	For(i,1,top)
	{
		dp[i]=dp[i-1];
		if(last[a[i]])dp[i]=(dp[i]+dp[last[a[i]]])%mo;
		last[a[i]]=i;
	}
	write(dp[top],'\n');
}
int main()
{
	
	input();
	work();
	return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

signed main() {
    string S;
    cin >> S;
    bool checkA = false, checkB = false;
    for (auto temp : S) {
        if (temp == 'A') checkA = true;
        else checkB = true;
    }
    cout << (checkA && checkB ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int M, N, a;
    int ac, max_ac;
    int i, j;
    
    scanf("%d%d", &M, &N);
    
    max_ac = 0;
    for (i = 0; i < M; i++){
        ac = 0;
        for (j = 0; j < N; j++){
            scanf("%d", &a);
            ac += a;
        }
        if (max_ac < ac){
            max_ac = ac;
        }
    }
    
    printf("%d\n", max_ac);

    return (0);
}

Measured memory_bytes: 600
package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)
	var s string
	fmt.Scanln(&s)
	ans := 0
	prev := ' '
	for _, r := range s {
		if r != prev {
			ans++
			prev = r
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 1280
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n]*finv[r]*finv[n-r]%p

def perm(n,r,p):
  if (r < 0) or (n < r):
    return 0
  return fac[n]*finv[n-r]%p

N = 310000
MOD = pow(10,9)+7

fac = [-1]*(N+1); fac[0] = 1; fac[1] = 1 #階乗
finv = [-1]*(N+1); finv[0] = 1; finv[1] = 1 #階乗の逆元
inv = [-1]*(N+1); inv[0] = 0; inv[1] = 1 #逆元
for i in range(2,N+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD

M = int(input())
A = list(map(int,input().split()))
MAX = 63
L = [0]*MAX

for i in range(M):
  for j in range(MAX):
    if A[i]>>j&1:
      L[j] += 1
#print(L)
ans = 0
for i in range(MAX):
  base = pow(2,i)
  kosu = cmb(M,2,MOD)-cmb(L[i],2,MOD)-cmb(M-L[i],2,MOD)
  ans += base*kosu%MOD
print(ans%MOD)
  

Measured memory_bytes: 134496
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000

int main(){
    int A,N,ans=0;
    cin>>N>>A;
    if(N%500<=A){
        ans=1;
    }
    if(ans==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>
#include<cmath>
#include<queue>

typedef long long ll;
using namespace std;
#define mod 10007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl



int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    double sum=0;
    rep(i,n){
        double k=1.0/a[i];
        sum+=k;
    }
    double ans=1.0/sum;
    printf("%f\n",ans);
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

typedef long long ll; //64bit型
using namespace std;
const ll INF = 1LL << 20;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main()
{
        char a;
        cin >> a;
        if (a == 'A')
        {
                cout << 'T' << endl;
        }
        else if (a == 'C')
        {
                cout << 'G' << endl;
        }
        else if (a == 'G')
        {
                cout << 'C' << endl;
        }
        else if (a == 'T')
        {
                cout << 'A' << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <string>
#include <stdlib.h>
#include <algorithm>

using namespace std;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int main() {
	string s;
	cin >> s;
	s[5] = s[13] = ' ';
	cout << s <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int sum = 0;
    for(int i = 0; i<s.size(); i= i+2){
        if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
            sum++;
        }
    }
    
    for(int j = 1; j<s.size(); j= j+2){
        if(s[j]=='L'||s[j]=='U'||s[j]=='D'){
            sum++;
        }
    }
    
    if(s.size()==sum){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 768
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c = map(int, readline().split())
if (a == b and a != c) or (b == c and a != b) or (a == c and a != b):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include <iostream>
#include <stack>

using namespace std;
long long n;
string s;

string f(long long n) {
    if (n == 0) return "";
    n--;
    return f(n / 26) + string(1, 'a' + (n % 26));
}

int main() {
//    printf("%c", 'a' + 0);
    cin >> n;
    cout << f(n);
    return 0;
    
    stack<char> s;
    while (n > 0) {
        n--;
        int mod = n % 26;
        s.push('a' + mod);
        n /= 26;
    }

    while (!s.empty()) {
        char c = s.top();
        cout << c;
        s.pop();
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string K; cin >> K;
    ll D; cin >> D;
    vvvl dp(K.size()+1, vvl(2, vl(D, 0)));
    dp[0][0][0] = 1;
    const ll mod = 1e9+7;
    rep(i, K.size()){
        ll nd = K[i] - '0';
        rep(d, D){
            dp[i+1][0][(nd+d)%D] += dp[i][0][d];
        }
        rep(kk, 10) rep(d, D){
            dp[i+1][1][(kk+d)%D] += dp[i][1][d];
            if(kk < nd){
                dp[i+1][1][(kk+d)%D] += dp[i][0][d];
            }
        }
        rep(st, 2) rep(d, D){
            dp[i+1][st][d] %= mod;
        }
    }
    cout << (dp[K.size()][0][0] + dp[K.size()][1][0] -1+mod)%mod << endstr;
    return 0;
}


Measured memory_bytes: 17024
# dp[c1][c2][c3]=
# 		(1個の皿がc1枚、2個の皿がc2枚、3個の皿がc3枚あるとき、全て食べるまでの操作回数の期待値)

N = int(input())
A = list(map(int, input().split()))
cnt1 = A.count(1)
cnt2 = A.count(2)
cnt3 = A.count(3)

dp = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 0

# dp[c1][c2][c3]=1
# 	+dp[c1−1][c2][c3]∗(1個の皿が選ばれる確率)
# 	+dp[c1+1][c2−1][c3]∗(2個の皿が選ばれる確率)
# 	+dp[c1][c2+1][c3−1]∗(3個の皿が選ばれる確率)
# 	+dp[c1][c2][c3]∗(0個の皿が選ばれる確率)
# ↓式変形↓
# dp[c1][c2][c3]=1/(1−(0個の皿が選ばれる確率))
# 			+ dp[c1−1][c2][c3]*(1個の皿が選ばれる確率)/(1−(0個の皿が選ばれる確率))
# 			+ dp[c1+1][c2−1][c3]*(2個の皿が選ばれる確率)/(1−(0個の皿が選ばれる確率))
# 			+ dp[c1][c2+1][c3−1]*(3個の皿が選ばれる確率)/(1−(0個の皿が選ばれる確率))


def func(c1, c2, c3):
    if dp[c1][c2][c3] != -1:
        return dp[c1][c2][c3]

    # 繰り返し登場するので先に計算しておく
    prob0 = (N - c1 - c2 - c3) / N

    temp = 1 / (1 - prob0)
    if c1 > 0:
        temp += func(c1 - 1, c2, c3) * (c1 / N) / (1 - prob0)
    if c2 > 0:
        temp += func(c1 + 1, c2 - 1, c3) * (c2 / N) / (1 - prob0)
    if c3 > 0:
        temp += func(c1, c2 + 1, c3 - 1) * (c3 / N) / (1 - prob0)

    dp[c1][c2][c3] = temp
    return temp


print(func(cnt1, cnt2, cnt3))


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

int main() {
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> strB(M);
	vector<int> strA(M);
	int count = 0;
	int sum = 0;

	for (int i = 0; i < M; i++)
		cin >> strB.at(i);
	
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> strA.at(j);
			sum = sum + strA.at(j) * strB.at(j);
		}
		if (sum + C > 0)
			count++;
		sum = 0;
	}

	cout << count << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, k: usize,
    };

    let mut res = 0_f64;
    for a in 1..n + 1 {
        let mut c = 0;
        while a * 2.pow(c) < k {
            c += 1;
        }
        res += (1.0 / n as f64) * (1_f64 / 2.pow(c as u32) as f64);
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(true)
    {
        if(a<=0||c<=0)break;
        if(a>0)
        c-=b;
        if(c>0)
        a-=d;
    }
    if(a<=0)cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include <cstring>
#include<bits/stdc++.h>
using namespace std; 
  
#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;

int main() 
{
	int r,g,b;
	cin>>r>>g>>b;
	if ((100*r+10*g+b)%4==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
N,C,K=gets.split.map(&:to_i)
T=N.times.map{gets.to_i}
T.sort!
wait=0
last=Float::INFINITY
ans=0
T.each do |t|
	if last+K<t || wait==C
		ans+=1
		wait=0
		last=Float::INFINITY
	end
	wait+=1
	last=t if last==Float::INFINITY
end

if wait!=0
	ans+=1
end
puts ans

Measured memory_bytes: 4016
#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 INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    int N;
    cin >> N;
    vector<pair<int, int>> pairs(N);
    REP(i, N){
        int a;
        cin >> a;
        pairs.at(i) = make_pair(a, i + 1);
    }
    sort(pairs.begin(), pairs.end());
    REP(i, N) {
        cout <<  pairs.at(i).second << " ";
        if(i == N-1)
            cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
import java.io.*;

public class Main {

  public static void main(String[] args){

    try{
      String str;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
      str = br.readLine();
str=br.readLine();
      String[] ss = str.split(" ");
      //int sample = Integer.parseInt(str);
      //func(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]));
ffunc(ss);
    } catch(IOException e){
      e.printStackTrace();
    }
  }

  public static void func(int a, int b){
    if((a+b)%2 == 0){
      System.out.println(Math.abs((a+b)/2));
    } else System.out.println("IMPOSSIBLE");
  }

  public static void ffunc(String[] ss){

    int ints[] = new int[ss.length];

int count = 0;

    for(int i = 0; i < ss.length; i++){
      ints[i] = Integer.parseInt(ss[i]);
    }

    for (int i = 0; i < ss.length; i++){
      if(ints[i] != i+1)count++;
}
if(count == 2 || count == 0) System.out.println("YES");
else System.out.println("NO");

  }
}


Measured memory_bytes: 22484
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
//const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

int main()
{
	char a[10][10];
	memset(a, 'a', sizeof a);
	FORI(i, 1, 8+1)
	{
		FORI(j, 1, 8+1)
		{
			cin >> a[i][j];
		}
	}
	bool ok = true;
	while (ok)
	{
		ok = false;
		FOR(which, 2)
		{
			int n[10][10] = {};
			char obj[] = "xo";
			FORI(i, 1, 8 + 1)
			{
				FORI(j, 1, 8 + 1)
				{
					if (a[i][j] == '.')
					{
						int x[8] = { -1,0,1,-1,1,-1,0,1 };
						int y[8] = { -1,-1,-1,0,0,1,1,1 };
						FOR(k, 8)
						{
							int X = i, Y = j;
							int dx = x[k], dy = y[k];
							int c = 0;
							while (true)
							{
								X += dx; Y += dy;
								if (a[X][Y] == obj[which])
								{
									c++;
								}
								else if (a[X][Y] == '.'||a[X][Y]=='a')
								{
									c = 0;
									break;
								}
								else
								{
									break;
								}
							}
							n[i][j] += c;
						}
					}
				}
			}

			int maxi = 0,I,J;
			FORI(i, 1, 8 + 1)
			{
				FORI(j, 1, 8 + 1)
				{
					if ((!which&&maxi < n[i][j])||(which&&maxi<=n[i][j]))
					{
						maxi = n[i][j];
						I = i; J = j;
					}
				}
			}
			if (maxi != 0)
			{
				ok = true;
				int x[8] = { -1,0,1,-1,1,-1,0,1 };
				int y[8] = { -1,-1,-1,0,0,1,1,1 };
				FOR(k, 8)
				{
					int X = I, Y = J;
					int dx = x[k], dy = y[k];
					int c = 0;
					while (true)
					{
						X += dx; Y += dy;
						if (a[X][Y] == obj[which])
						{
							c++;
						}
						else if (a[X][Y] == '.' || a[X][Y] == 'a')
						{
							c = 0;
							break;
						}
						else
						{
							break;
						}
					}
					if (!c)continue;
					X = I, Y = J;
					a[X][Y] = obj[(which + 1) % 2];
					while (true)
					{
						X += dx; Y += dy;
						if (a[X][Y] == obj[which])
						{
							a[X][Y] = obj[(which + 1) % 2];
						}
						else
						{
							break;
						}
					}
				}
			}
		}
	}
	FORI(i, 1, 8 + 1)
	{
		FORI(j, 1, 8 + 1)
		{
			cout << a[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 3088
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a,b,c;
    a=sc.nextInt();
    b=sc.nextInt();
    c=sc.nextInt();
    int n=a-b;
    int m=c-n;
    if(m>0){
      System.out.println(m);
    }else{
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 21332
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int H[N];
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    int ans=1;
    for(int i=1;i<N;i++){
        int count=0;
        for(int j=0;j<i;j++){
           if(H[i]>=H[j]){count++;}
        }
        if(count==i){ans++;}
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int a, b, k; cin >> a >> b >> k;
  vector<int> yakusu;
  FOR(i, 1, 101) {
    if (a % i == 0 && b % i == 0) yakusu.emplace_back(i);
  }
  reverse(ALL(yakusu));
  cout << yakusu[k - 1] << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 2e2+5;
// check for forloop
// take input
// overflow
// intialize variable
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    string s;
    cin>>s;
    int ans=0;
    if(s[0]=='R'||s[1]=='R'||s[2]=='R')ans=1;
    if((s[0]=='R'&&s[1]=='R')||(s[2]=='R'&&s[1]=='R'))ans=2;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')ans=3;
    cout<<ans;
}



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

int main(){
  int N;
  cin>>N;
  int X[N],Y[N];
  int H[N];
  int tempH;
  for(int i=0;i<N;i++){
    cin>>X[i]>>Y[i]>>H[i];
  }
  int ix=0;
  for(int i=0;i<N;i++){
    if(H[i] != 0){
      ix=i;
      break;
    }
  }
  //cout<<ix<<endl;
      

    for(int i=0;i<=100;i++){
      for(int j=0;j<=100;j++){
        tempH=abs(i-X[ix])+abs(j-Y[ix])+H[ix];
        
        int flag=1;
        for(int k=0;k<N;k++){
          if(H[k] != max(tempH-abs(i-X[k])-abs(j-Y[k]),0)){
            //cout<<i<<" "<<j<<" "<<tempH<<" "<<max(tempH-abs(i-X[k])-abs(j-Y[k]),0)<<endl;
            flag=0;
            break;
          }
        }
        if(flag){
          cout<<i<<" "<<j<<" "<<tempH;
          return 0;
        }
      }
    }
  return 0;
}


Measured memory_bytes: 3612