akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define SIZE 25
#define NIL -1
using namespace std;

typedef struct
{
    int parent, left, right;
    int depth, height;
} Tree;

Tree T[SIZE];
int parent = NIL;

void CheckDepth(int n)
{
    for (int i = 0; i < n; i++)
    {
        T[i].depth = 0;
        int id = i;
        while (T[id].parent != NIL)
        {
            T[i].depth++;
            id = T[id].parent;
        }
    }
}

int max(int x, int y)
{
    if (x >= y)
    {
        return x;
    }
    return y;
}

int GetHeight(int id = parent)
{
    int h1 = 0;
    int h2 = 0;
    if (T[id].right != NIL)
    {
        h1 = GetHeight(T[id].right) + 1;
    }
    if (T[id].left != NIL)
    {
        h2 = GetHeight(T[id].left) + 1;
    }

    T[id].height = max(h1, h2);
    return T[id].height;
}

void GetParent(int n)
{
    for (int i = 0; i < n; i++)
    {
        if (T[i].right != NIL)
        {
            T[T[i].right].parent = i;
        }
        if (T[i].left != NIL)
        {
            T[T[i].left].parent = i;
        }
    }
}

int GetSibling(int id)
{
    int pid = T[id].parent;
    if (pid == NIL)
    {
        return NIL;
    }

    if (T[pid].right != id)
    {
        return T[pid].right;
    }
    else if (T[pid].left != id)
    {
        return T[pid].left;
    }

    return NIL;
}

int GetDegree(int id)
{
    int count = 0;

    if (T[id].right != NIL)
    {
        count++;
    }
    if (T[id].left != NIL)
    {
        count++;
    }

    return count;
}

void CheckStatus(int id)
{
    if (T[id].parent == NIL)
    {
        cout << "root";
        return;
    }

    if (T[id].left == NIL && T[id].right == NIL)
    {
        cout << "leaf";
        return;
    }

    cout << "internal node";
}

void Print(int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << "node " << i << ": ";
        cout << "parent = " << T[i].parent << ", ";
        cout << "sibling = " << GetSibling(i) << ", ";
        cout << "degree = " << GetDegree(i) << ", ";
        cout << "depth = " << T[i].depth << ", ";
        cout << "height = " << T[i].height << ", ";
        CheckStatus(i);
        cout << endl;
    }
}

int main()
{
    int n, id;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> id;
        cin >> T[id].left >> T[id].right;
        T[id].parent = NIL; //parentメンバの初期化
    }

    GetParent(n);
    for (int i = 0; i < n && parent == NIL; i++)
    {
        if (T[i].parent == NIL)
        {
            parent = i;
        }
    }
    CheckDepth(n);
    GetHeight();
    Print(n);

    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    int a,b;
    cin >> a >> b;
    string s;
    cin >> s;
    int count =0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='-'){
            count++;
        }
    }
    bool before = false;
    bool after = false;
    if(count>1){
        cout<<"No"<<endl;
    }else{
        if(s[a]=='-' && s.size()-(a+1)==b){
            for(int i=0; i<a; i++){
                if(s[i]>='0' && s[i]<='9'){
                    before = true;
                }else{
                    before = false;
                    break;
                }
            }for(int i=a+1; i<s.size(); i++){
                if(s[i]>='0' && s[i]<='9'){
                    after = true;
                }else{
                    after = false;
                    break;
                }
            }
            if(before==true && after==true){
                cout<<"Yes"<<endl;
            }else{
                cout <<"No"<<endl;
            }
        }else{
            cout<<"No"<<endl;
        }
    }
}

Measured memory_bytes: 3628
def solve():
    N,T = map(int,input().split())
    t = list(map(int, input().split()))
    dup = 0
    for i in range(N-1): #enumerateはendが選択できない
        if t[i+1] < t[i] + T:
            dup += T-(t[i+1] - t[i])

    print(N*T - dup)




if __name__ == '__main__':
    solve()


Measured memory_bytes: 25196
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	int n = s.size(), m = t.size();
	vector<pii> sum_s(n + 1), sum_t(m + 1);
	sum_s[0] = sum_t[0] = pii(0, 0);
	int i0;
	for (i0 = 0; i0 < n; i0++) {
		sum_s[i0 + 1] = sum_s[i0];
		if (s[i0] == 'A') {
			sum_s[i0 + 1].first++;
		}
		else {
			sum_s[i0 + 1].second++;
		}
	}
	for (i0 = 0; i0 < m; i0++) {
		sum_t[i0 + 1] = sum_t[i0];
		if (t[i0] == 'A') {
			sum_t[i0 + 1].first++;
		}
		else {
			sum_t[i0 + 1].second++;
		}
	}
	int q;
	cin >> q;
	for (i0 = 0; i0 < q; i0++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int x, y;
		x = (sum_s[b].first - sum_s[a - 1].first) - (sum_s[b].second - sum_s[a - 1].second);
		y = (sum_t[d].first - sum_t[c - 1].first) - (sum_t[d].second - sum_t[c - 1].second);
		if ((x - y) % 3 == 0) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

}

Measured memory_bytes: 2432
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        for(int i=0;i<a;i++){String s = sc.next();
                             if(s.equals("AC")){ac++;}
                             if(s.equals("WA")){wa++;}
                             if(s.equals("TLE")){tle++;}
                             if(s.equals("RE")){re++;}
                            }
       
		System.out.println("AC"+" "+"x"+" "+ac);
      System.out.println("WA"+" "+"x"+" "+wa);
      System.out.println("TLE"+" "+"x"+" "+tle);
      System.out.println("RE"+" "+"x"+" "+re);
	}
}

Measured memory_bytes: 58324
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
  }

  ll cnt = 1;
  for_each(all(a), [&cnt](ll x){ if(x%2==0) cnt *= 2; });
  ll ans = pow(3, n) - cnt;
  cout << ans << endl;
}


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

using namespace std;

int main() {
  string s;cin>>s;
  int n=s.size();
  int ans=1e9;
  rep(i,n-2){
    int a=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    ans=min(ans,abs(753-a));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3604
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{
	public static void main(String[] arg) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String s;
		while((s=br.readLine())!=null){
			double x1 = Double.parseDouble(s.split(" ")[0]);
			double y1 = Double.parseDouble(s.split(" ")[1]);
			double x2 = Double.parseDouble(s.split(" ")[2]);
			double y2 = Double.parseDouble(s.split(" ")[3]);
			double x3 = Double.parseDouble(s.split(" ")[4]);
			double y3 = Double.parseDouble(s.split(" ")[5]);
			double xp = Double.parseDouble(s.split(" ")[6]);
			double yp = Double.parseDouble(s.split(" ")[7]);
			if(inTriangle(x1,y1,x2,y2,x3,y3,xp,yp))
				System.out.println("YES");
			else 	
				System.out.println("NO");
		}
	}
	private static boolean inTriangle(double x1, double y1, double x2, double y2, double x3, double y3, double xp, double yp)
	{
		// equation -> y = [0]x + [1]
		double[] eq12 = new double[2];
		double[] eq13 = new double[2];
		double[] eq23 = new double[2];
		
		if((x2-x1)==0) eq12[0]=(y2-y1);
		else eq12[0] = (y2-y1) / (x2-x1);
		eq12[1] = y1 - x1 * eq12[0];
		if((x3-x1)==0) eq13[0]=(y3-y1);
		else eq13[0] = (y3-y1) / (x3-x1);
		eq13[1] = y1 - x1 * eq13[0];
		if((x3-x2)==0) eq23[0]=(y3-y2);		
		else eq23[0] = (y3-y2) / (x3-x2);
		eq23[1] = y2 - x2 * eq23[0];
		
		if(yp > (eq12[0] * xp + eq12[1])) {
			if(y3 < (eq12[0] * x3 + eq12[1])) return false;
		} else if(y3 > (eq12[0] * x3 + eq12[1])) return false;
		if(yp > (eq13[0] * xp + eq13[1])) {
			if(y2 < (eq13[0] * x2 + eq13[1])) return false;
		} else if(y2 > (eq13[0] * x2 + eq13[1])) return false;
		if(yp > (eq23[0] * xp + eq23[1])) {
			if(y1 < (eq23[0] * x1 + eq23[1])) return false;
		} else if(y1 > (eq23[0] * x1 + eq23[1])) return false;
		return true;
	}
}

Measured memory_bytes: 10000
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#define mod 1000000007
#define pie 3.141592653589793238
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  while(a>0 || c>0){
    c-=b;
    if(c<=0) break;
    a-=d;
    if(a<=0) break;
  }
  
  if(a>0)cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

int HourtoMin(string s);

int main()
{
    int n;
    while(1){
        cin >> n;
        if(n == 0) break;
        int time_s;
        string h_m_s;
        vector<pair<int, int> > trains(20001);
        for(int i = 0; i < 2 * n; i++){
            cin >> h_m_s;
            time_s = HourtoMin(h_m_s);
            if(i % 2 == 0) trains[i] = make_pair(time_s, 1);
            else trains[i] = make_pair(time_s, 0);
            // 到着したときは0、出発したときは1
        }
        sort(trains.begin(), trains.begin() + 2 * n);
        int osaki_now_train = 0, need_train = 0;
        for(int i = 0; i < 2 * n; i++){
            if(trains[i].second == 1){
                if(osaki_now_train == 0) need_train++;
                else osaki_now_train--;
            } else if(trains[i].second == 0) osaki_now_train++;
        }
        cout << need_train << endl;
    }
    return 0;
}

int HourtoMin(string s)
{
    int ans = 0;
    for(int i = 0; i <= 6; i = i + 3){
        ans += ((s[i] - '0') * 10 + s[i + 1] - '0') * (int)pow(60, ((6 - i) / 3));
    }
    return ans;
}

Measured memory_bytes: 1388
using System;

class main
{
    public static int n = 1000001;
    static void Main()
    {
        string s;
        int c, q;
        int[] p = new int[n];
        for (int i = 2; i < n; ++i)
                for (int j = i * 2; j < n; j += i)
                    p[j] = 1;
        while ((s = Console.ReadLine()) != null){
                c = int.Parse(s);
                q = 0;
                for (int i = 2; i <= c; ++i)
                    if (p[i] != 1) ++q;
                Console.WriteLine("{0}", q);
        }    
    }
}

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

int main(){
    int N, x;
    cin >> N >> x;
    int a[110];
    int ans = 0;
    for (int i=1; i<N+1; i++) cin >> a[i];
    sort(a+1, a+N+1);
    if (x < a[1]) {
        cout << ans << endl;
    }
    else {
        for (int i=1; i<N+1; i++) {
            x -= a[i];
            if (x < 0) break;
            else ans += 1;
        }
        if (x > 0) ans -= 1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    char word_W[10000];
    char text_T[10000];
    int i;
    int ans = 0;

    scanf("%s", word_W);
    for(i=0; word_W[i]!='\0'; i++)
        word_W[i] = tolower(word_W[i]);
    
    while(1){
        scanf("%s", text_T);
        if(!strcmp(text_T, "END_OF_TEXT")) break;
        for(i=0; text_T[i]!='\0'; i++)
            text_T[i] = tolower(text_T[i]);
        if(strcmp(text_T, word_W) == 0){
            ans++;
           // printf("%d\n", ans);
        }
    }
    printf("%d\n", ans);
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


































Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> x(n, 0);
    rep(i, n) {
        if (i&1) {
            x[0] -= a[i];
        } else {
            x[0] += a[i];
        }
    }
    rep(i, n) {
        if (i == 0) continue;
        x[i] = 2*a[i-1] - x[i-1];
    }

    rep(i, n) printf("%d%c", x[i], i==n-1?'\n':' ');
}

Measured memory_bytes: 2176
#include <stdio.h>

void bsort(int a[], int n)
{
    int i, j;

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

int main(void)
{
    int n, k;
    scanf("%d %d", &n, &k);
    int i;
    int l[n];
    for(i=0;i<n;i++)
        scanf("%d", &l[i]);

    bsort(l, n);
    int sum = 0;
    for(i=1;i<=k;i++){
        sum +=l[n-i];
    }
    
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <stdio.h>
using namespace std;
int main(void){
    int n,s[1000];
    double m=0,a=0,q[1000];
    
    while(1){
        scanf("%d",&n);
        if(n==0)break;
        for(int c=n;c>0;c=c-1){
            scanf("%d",&s[c-1]);
            m=m+s[c-1];
        }
        m=m/n;
        for(int c=n;c>0;c=c-1){
            q[c-1]=s[c-1]-m;
            q[c-1]=q[c-1]*q[c-1];
            a=a+q[c-1];
            s[c-1]=0;q[c-1]=0;
        }
        a=a/n;
        printf("%.6lf\n",sqrt(a));
        a=0;m=0;
   
    }

}



Measured memory_bytes: 2736
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,n;
    cin>>m>>n;
    for(int i=0;i<=m;i++)
     	for(int j=0;j<=m;j++)
      		for(int k=0;k<=m,i+j+k<=m;k++)
	       {
	            if(i+j+k==m&&i*1000+j*5000+k*10000==n)
	            {
	                cout<<k<<" "<<j<<" "<<i<<endl;
	                return 0;   
	            }
	       }
    cout<<"-1 -1 -1"<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))
zero = a_list.count(0)
D = 1000000000 + 7
a_set = set(a_list)
if zero == 1 and n - 1 == 2 * (len(a_set)-1):
    print(2 ** ((n-1)//2) % D)
elif zero == 0 and n == 2 * len(a_set):
    print(2 ** (n//2) % D)
else:
    print(0)

Measured memory_bytes: 13880
// HTTF.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define int LL
#define pb emplace_back
#define eb pb

using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e6 + 1000;
const int SIZE2 = 3010;
const int SIZE3 = 330;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;

#define endl "\n" //インタラクティブでは消す
ut N, M, K, L, Q, D, H, W;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], maps2[SIZE2][SIZE2], answer = zero;
LL maps[SIZE2][SIZE2];
LL DP[SIZE];
bool finished[SIZE];
LL A[SIZE2][SIZE2];
LL solve2(LL n, LL bit) {
	if (n==-1) return 1;
	if (finished[bit]) return DP[bit];
	finished[bit] = true;
	DP[bit] =0;
	REP(i, N) {
		if ((bit&(1 << i))>0) {
			DP[bit] += solve2(n-1, bit - (1 << i))*A[n][i];
			DP[bit] %= p;
		}
	}
	return DP[bit]%p;
}
LL solve() {
	cin >> N;
	REP(i, N) REP(j, N) cin >> A[i][j];
	cout << solve2(N-1,(1<<N)-1) << endl;
	return 0;
}




//!!!!!!!!!!!!!!!!!!!実装を詰める!!!!!!!!!!!!!!!!!!!!!!!!!
signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(0);
	solve();
	cin >> N;
	return 0;

}

Measured memory_bytes: 140544
//e4-e5-f4
//#include <boost/multiprecision/cpp_int.hpp> 
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
// __int128 s128;
// __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define PI 3.14159265359
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define tc(x) ll x; cin>>x; while(x--)
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define print(a)  for (auto x : a) cout << x << " "; cout << endl
#define sl set<ll>
#define usl unordered_set<ll>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define vl vector<ll>
#define vpl vector<pll>
#define vvl vector<vector<ll>>
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define setbits(a) __builtin_popcountll(a)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define P 1000000007
#define Q 1000000006
#define inf 1e18
#define N 405
#define K 105
//using namespace boost::multiprecision; 
//using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //shuffle(all(v), rng);
ll a[N], dp[N][N], pre[N];
void solve(){
    ll n;
    cin>>n;
    f(i,1,n+1) cin>>a[i], pre[i] = pre[i-1] + a[i];
    f(d,1,n){
        f(i,1,n+1){
            ll j = i+d;
            if(j>n) continue;
            dp[i][j] = inf;
            f(k,i,j){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j]);
            }
            dp[i][j] += pre[j]-pre[i-1];
        }
    }
    cout<<dp[1][n];
}

signed main() {
    teevra_gati
        
    solve();

    return 0;
}

Measured memory_bytes: 4892
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string s;
  cin>>s;
  for(int i=0;i<(int)s.size();i++){
    s[i]=(s[i]-'A'+26-3)%26+'A';
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve() {
    cout << fixed << setprecision(10);
    
    string s; cin >> s;
    int ss = s.length();

    // int a_count = 0;
    // int bc_count = 0;
    ll ans = 0;
    ll cnt = 0;
    /*
    int i = 0;
    while (i < ss-1) {
        if (s[i] == 'A') {
            a_count += 1;
            i += 1;
        } else if (s[i] == 'B' && s[i+1] == 'C') {
            ans += a_count;
            i += 2;
            // bc_count = 0;
        } else {
            a_count = 0;
            i += 1;
        }
    }*/
    rep(i, ss){
        if(i + 1 < ss && s[i] == 'B' && s[i + 1] == 'C'){
            ans += cnt;
            i += 1;
        }
        else if (s[i] == 'A') ++cnt;
        else{
            cnt = 0;
        }
    }
    cout << ans << endl;

}
int main() {
ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t =1; 
//	cin>>t; 
	while(t--)solve();
  return 0;
}


Measured memory_bytes: 720
#include<cstdio>
#include<algorithm>
#define N 100003
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int n,m,f[N],ok[N],ok_id[N],id[N],a[N];
bool b[N];
ll ans=0;

int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}

bool cmp(int x,int y){
	return a[x]<a[y];
}
int main(){
	scanf("%d%d",&n,&m);
	int res=0;
	res=(n-1-m)*2;
	if(res>n){
		puts("Impossible");
		exit(0);
	}
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		f[i]=id[i]=i;
		ok[i]=inf;
	}
	for(int i=1;i<=m;++i){
		int l,r;
		scanf("%d%d",&l,&r);
		++l,++r;
		f[find(l)]=find(r);
	}
	for(int i=1;i<=n;++i){
		int now=find(i);
		if(a[i]<ok[now]){
			ok[now]=a[i],ok_id[now]=i;
		}
	}
	int c=0; 
	for(int i=1;i<=n;++i){
		if(find(i)==i){
			++c;
			ans+=ok[i];
			b[ok_id[i]]=1;
			--res;
		}
	}
	if(c==1){
		puts("0");
		exit(0);
	}
	sort(id+1,id+n+1,cmp);
	for(int i=1,j=1;i<=res;++i){
		for(;b[id[j]];++j);
		ans+=a[id[j++]];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2176
fun main(args: Array<String>) {
    val (a, b, c) = readInputLine().split(" ").map { it.toInt() }
    
    if (a <= c && c <= b) {
        println("Yes")
    } else {
        println("No")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37824
h, w = [int(x) for x in input().split()]
A = []
rm_pos = []

for i in range(h):
    a = input()
    if a != '.' * w:
        A += [list(a)]

flg = True

# 白マスのみの列 検索
for j in range(w):
    for i in range(len(A)):
        if A[i][j] != '.':
            flg = False
            break
    if flg == True:
        rm_pos += [j]
    flg = True
rm_pos = reversed(rm_pos)

# 列の削除
for j in rm_pos:
    for i in range(len(A)):
        del A[i][j]


# 回答出力
for i in range(len(A)):
    print(''.join(A[i]))

Measured memory_bytes: 3188
import sys
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
from collections import deque 

input = sys.stdin.readline

def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
def dbg(o):
    print(o, file=sys.stderr)

# ---------------------------------------

n = inp()
print(1 if n == 0 else 0)

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

using namespace std;


#define int long long
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)


using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

#define SIZE 19

int N;
int POW[SIZE];

signed main() {
    POW[0] = 1;
    for (int i = 1; i < SIZE; i++) {

        POW[i] = POW[i - 1] * 2;
    }

    scanf("%d", &N);

    printf("0:\n");
    int index = 1;

    for (int state = 1; state < POW[N]; state++) {
        printf("%d:", index++);
        for (int loop = 0; loop < N; loop++) {
            if (state & (1 << loop)) {
                printf(" %d", loop);
            }
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 3220
def main():
    x = int(input())
    z = 0
    for i in range(x):
        d1,d2 = map(int,input().split())
        if d1==d2:
            z += 1
        else:
            z = 0
        if z==3:
            print('Yes')
            return
    print('No')

if __name__ == "__main__":
    main()

Measured memory_bytes: 9172
// Thanks for: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

use std::cmp;

fn main() {
  input!{
    S: String,
    T: String,
  }
  let ns = S.chars().count();
  let nt = T.chars().count();
  let ss: Vec<char> = S.chars().collect();
  let ts: Vec<char> = T.chars().collect();
  
  
  let mut dp: Vec<Vec<usize>> = Vec::with_capacity(ns+1);
  let mut sp: Vec<Vec<i32>> = Vec::with_capacity(ns+1);
  for i in 0..(ns+1) {
    dp.push(Vec::with_capacity(nt+1));
    sp.push(Vec::with_capacity(nt+1));
    for j in 0..(nt+1) {
      dp[i].push(0);
      sp[i].push(-100);
    }
  }

  for i in 0..(ns+1) {
    for j in 0..(nt+1) {
      if i < ns && j < nt {
        if ss[i] == ts[j] && dp[i+1][j+1] < dp[i][j]+1 {
          dp[i+1][j+1] = dp[i][j]+1;
          sp[i+1][j+1] = 0;
        }
      }
      if i < ns {
        if dp[i+1][j] < dp[i][j] {
          dp[i+1][j] = dp[i][j];
          sp[i+1][j] = 1;
        }
      }
      if j < nt {
        if dp[i][j+1] < dp[i][j] {
          dp[i][j+1] = dp[i][j];
          sp[i][j+1] = -1;
        }
      }
    }
    //println!("{}", format!("{:?}", sp[i]) )
  }
  let mut ans = String::new();
  let mut ki = ns;
  let mut kj = nt;
  while 0 < ki && 0 < kj {
    match sp[ki][kj] {
      1 => ki -= 1,
      -1 => kj -= 1,
      0 => {
        kj -= 1;
        ki -= 1;
        ans.push(ss[ki]);
      },
      _ => {
        break
      }
    }
  }
  println!("{}", ans.chars().rev().collect::<String>())
}

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

int main(){
	int k,c,a;
	
	while( cin >> k , k ){
		a = 0;
		for(int i=0 ; i < k*(k-1)/2 ; i++ ){
			cin >> c;
			a += c;
		}
		cout << ( a / (k-1) ) << endl;
	}
}

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

int main() {
  int N, K; cin >> N >> K;
  if (N % K == 0) cout << 0 << endl;
  else            cout << 1 << endl;
}


Measured memory_bytes: 3628
/*
  AOJ 0610
  Title:Weather Forecaster
  @kankichi573
*/
#include <stdio.h>

int H,W;
char result[100][101];
char tenki[101];

main()
{
  int i,j,flag;
  char weather;
  

  scanf("%d %d",&H,&W);
  for(i=0;i<H;i++)
    {
      scanf("%s",tenki);
      for(j=0,flag=-1;j<=W;j++)
	{
	  weather=tenki[j];
	  if(weather=='.')
	    {
	      if(flag>=0)
		flag++;
	    }
	  else if (weather=='c')
	    flag=0;
	  result[i][j]=flag;
	}
    }
  for(i=0;i<H;i++)
    {
      for(j=0;j<W;j++)
	{
	  printf("%d",result[i][j]);
	  if(j<W-1)
	    printf(" ");
	  else
	    printf("\n");
	}
    }
  return(0);
}

Measured memory_bytes: 612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static int inf = 1000001;

	public static int dijkstra(int a, int b, int n, int[][] cost){
		int[] d = new int [n];
		Arrays.fill(d, inf);
		d[a] = 0;
		int[] prev = new int [n];
		Arrays.fill(prev, -1);
		boolean[] q = new boolean [n];
		Arrays.fill(q, true);

		for(int i=0; i<n; i++){
			int pmin = inf;
			int u = inf;
			for (int ki=0; ki<n; ki++){
				if(pmin>=d[ki] && q[ki]){
					pmin = d[ki];
					u = ki;
				}
			}

			q[u] = false;
			for (int v=0; v<n; v++){
				if (cost[u][v] != inf){
					if(d[v] > d[u] + cost[u][v]){
						d[v] = d[u] + cost[u][v];
						prev[v] = u;
					}
				}
			}
		}
		return d[b];
	}

	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String line[] = br.readLine().split(" ");
			int n = Integer.parseInt(line[0]);
			int k = Integer.parseInt(line[1]);
			if(n==0){break;}

			int[][] cost = new int[n][n];
			for(int i=0; i<n; i++){
				for(int j=0; j<n; j++){
					cost[i][j] = inf;
				}
			}

			for(int i=0; i<k; i++){
				String query[] = br.readLine().split(" ");
				int dep = Integer.parseInt(query[1]) - 1;
				int arr = Integer.parseInt(query[2]) - 1;
				if(query[0].equals("1")){
					int price = Integer.parseInt(query[3]);
					if (cost[dep][arr] >= price){
						cost[dep][arr] = cost[arr][dep] = price;
					}
				}else{
					int mon = dijkstra(dep, arr, n, cost);
					if(mon != inf){
						System.out.println(mon);
					}else{
						System.out.println(-1);
					}
				}
			}
		}
	}
}

Measured memory_bytes: 40812
import fractions
a, b, c, d = map(int, input().split())
a -= 1
B = b - (b//c + b//d)+b//(c*d//fractions.gcd(c, d))
A = a - (a//c + a//d)+a//(c*d//fractions.gcd(c, d))

print(B - A)


Measured memory_bytes: 5304
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <sstream>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
void printhoge(set<int> v) {
	ALL(it, v) {
		cout << *it << " ";
	}
	cout << endl;

}



int main() {
	int n, m;
	cin >> n >> m;
	set<pair<int, int>> sp;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		sp.insert(make_pair(b, a));
	}
	auto it = sp.begin();
	ll res = 0;
	while (it != sp.end()) {
		int first = (*it).first;
		int second = (*it).second;
		int piv = first;
		res++;
		while (it != sp.end()) {
			if ((*it).second >= piv) {
				break;
			}
			it++;
		}
	}
	cout << res << endl;
	return 0;

}



Measured memory_bytes: 4992
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;

const int MAX = 10;
int ball[MAX];
int can;
int n;

void dfs(int left, int right, int num){
	if(num == 10) can = 1;
	if(can != 0) return;
	if(ball[num] > left) dfs(ball[num], right, num+1);
	if(ball[num] > right) dfs(left, ball[num], num+1);
	return;
}

int main(){
	cin >> n;
	while(n--){
		for(int i = 0; i < 10; i++)
			cin >> ball[i];
		can = 0;
		dfs(0,0,0); 
		if(can == 0) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
} 


Measured memory_bytes: 3012
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(auto i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define pb push_back
#define clr clear()
#define inf (1<<30)
#define ins insert
#define xx first
#define yy second
#define eps 1e-9
typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
typedef map<int, int> mii;
typedef map<st, int> msi;
typedef set<int> si;
typedef set<st> ss;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define maxn 200000
int z[maxn];
bool can(int t, int n, int k, string& s) {
	for (int i = 0; i + t <= n; ++i) {
		int zc = i == 0 ? z[i + t - 1] : (z[i + t - 1] - z[i - 1] + (s[i] == '0'));
		if (zc <= k)
			return true;
	}
	return false;
}
int main() {
	//freopen("in.txt", "r", stdin);
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	z[0] = s[0] == '0';
	for (int i = 1; i < n; ++i) {
		z[i] = z[i - 1] + (s[i] == '0' && s[i - 1] == '1');
	}
	int ans = 0;
	int lo = 1, hi = s.size();
	while (lo <= hi) {
		int mid = (lo + hi) / 2;
		bool valid = can(mid, n, k, s);
		if (!valid)
			hi = mid - 1;
		else {
			ans = mid;
			lo = mid + 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

void kai(P &p){
    int x = p.first;
    int y = p.second;
    p = P(-y,x);
}

int main() {
    int h, w; cin >> h >> w;
    vector<vector<char>> ar(h,vector<char>(w));
    rep(i,h) rep(j,w) cin >> ar[i][j];
    vector<int> tate;
    vector<int> yoko;
    rep(i,h){
        bool t = false;
        rep(j,w) if (ar[i][j] == '#') t = true;
        if (t) tate.emplace_back(i);
    }
    rep(i,w){
        bool t = false;
        rep(j,h) if (ar[j][i] == '#') t = true;
        if (t) yoko.emplace_back(i);
    }
    rep(i,tate.size()){
        rep(j,yoko.size()){
            cout << ar[tate[i]][yoko[j]];
        }
        cout << endl;
    }
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	switch(n)
	{
		case 1: 
			cout<<"Hello World"<<endl;
			break;
		case 2:
			int a,b;
			cin>>a>>b;
			cout<<a+b<<endl;
			break;
		default: break;

	}
	return 0;
}

Measured memory_bytes: 256
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n; cin>>n;
    
    vector<int> a;

    for(int i =0 ; i < n; i++){
        int k; cin>>k;
        a.push_back(k);
    }
  	sort(all(a));
    vector<int> present(a.back()+1);
    int cnt = 0;
    for(int i : a){
        for(int j = i; j <=a.back(); j+=i){
            present[j]++;
        }
    }
    for(int i : a){
        cnt += (present[i]==1);
    }

    cout<<cnt<<endl;
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_multiset;


void _main() {
        int n; cin >> n;
        vector<int> a(n); cin >> a;
        indexed_multiset s(all(a));
        for (int i = 0; i < n; i++) {
                s.erase(prev(s.lower_bound(a[i])));
                cout << *s.find_by_order((n - 1) / 2) << '\n';
                s.insert(a[i]);
        }
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 13440
#include <iostream>
using namespace std;
void swap(int *a,int *b) {
    int tmp=*a;
    *a = *b;
    *b = tmp;
}
int main(void){
    const int N = 100;
    int lp;
    int val[N]={0};
    int min;
    int count =0;
    cin >> lp;
    for(int i=0;i<lp;i++) {
        cin >> val[i];
    }
    for(int i=0;i<lp;i++) {
        min=i;
        for(int j=i+1;j<lp;j++) {
            if(val[min] > val[j]) {
                min = j;
            }
        }
        if(min!=i) {
            swap(val[i],val[min]);
            count++;
        }
    }
    for(int i=0;i<lp;i++) {
        if(i!=lp-1)
            cout << val[i] << " ";
        else
            cout << val[i] << endl;
    }
    cout << count << endl;
}

Measured memory_bytes: 1160
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

public class Main 
{
	static HashMap<String, String> groupdef;
	static String firstgroup;
	static TreeSet<String> members;
	static TreeSet<String> checked;
	
	static void get(String g)
	{
		String con = groupdef.get(g);
//		System.out.println("Getting " + g + "...");
		if(checked.contains(g))return;
		
		int start = 0;
		int mem = 0;
		for(int i = 0; i < con.length(); i++)
		{
			if(con.charAt(i) == ',' || con.charAt(i) == '.')
			{
				String word = con.substring(start, i);
				start = i+1;
				
				if(groupdef.containsKey(word))
				{
					get(word);
				}
				else
				{
					members.add(word);
				}
			}
		}
		checked.add(g);
//		cache.put(g, mem);
	}

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		while(true)
		{
			int n = sc.nextInt();
			if(n == 0)break;
			groupdef = new HashMap<String, String>();
//			cache = new HashMap<String, Integer>();
			members = new TreeSet<String>();
			checked = new TreeSet<String>();
			
			for(int i = 0; i < n; i++)
			{
				String s = sc.next();
				int lim = s.indexOf(':');
				String groupname = s.substring(0, lim);
				String groupcon = s.substring(lim+1);
				if(i == 0)firstgroup = groupname;
				groupdef.put(groupname, groupcon);
			}
			
			get(firstgroup);
			System.out.println(members.size());
//			System.out.println(members);
		}
		

	}

}



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

bool p[1000010];
void init(){
    int MAX = 1000010;
    for(int i=0;i<MAX;i++) p[i]=1;
    p[0]=0, p[1] = 1;
    for(int i=2;i<=MAX/2;i++){
        if(p[i]){
            for(int j=i+i;j<MAX;j+=i) p[j]=0;
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    int a[n];
    init();
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    if(p[a[0]]==false){
        cout << 0 << endl;
        return 0;
    }
    ll mod = 1e9+7;
    ll dp[n+1][2]={};
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        if(i) dp[i+1][1] += dp[i][0];
        dp[i+1][1] %= mod;
        if(i-2>=0 && a[i]>a[i-2] && p[a[i]]){
            dp[i+1][0] += dp[i][1];
        }
        if(i && a[i]>a[i-1] && p[a[i]]){
            dp[i+1][0] += dp[i][0];
        }
        if(i==0){
            dp[i+1][0] += dp[i][0];
        }
        dp[i+1][0] %= mod;
    }
    ll ans = dp[n][0] + dp[n][1];
    ans %= mod;
    cout << ans << endl;
}


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

using namespace std;
using llint = long long;
using pint = pair<int,int>;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

const int INF = 1<<28;
const llint LLINF = 1LL<<60;
const llint MOD = powl(10, 9) + 7;

int n, m;
vector<int> a;

int main() {
    // Input
    cin >> n >> m;
    a.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> a.at(i);
    }

    vector<llint> dp(n+1, -1);

    dp.at(0) = 1;
    dp.at(1) = 1;

    for (int i = 0; i < m; ++i) {
        dp.at(a.at(i)) = 0;
    }

    // Solve

    for (int i = 2; i <= n; ++i) {
        if(dp.at(i) == 0) continue; 

        dp.at(i) = (dp.at(i-1)  + dp.at(i-2))%MOD;
    }

    // Output
    cout << dp.at(n) << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A.at(i);
    vector<int> B(N);
    for (int i = 0; i < N; i++) {
        B.at(A.at(i) - 1) = i + 1;
    }
    for (int i = 0; i < N; i++) {
        cout << B.at(i) << endl;
    }
}

Measured memory_bytes: 1664
N, Q = map(int, input().split())
S = input()
memo = [0]*N
tmp = 0
for i in range(1, len(S)):
    if S[i-1] == "A" and S[i] == "C":
        tmp += 1
        memo[i] = tmp
    else:
        memo[i] = tmp

for _ in range(Q):
    li, ri = map(int, input().split())
    ans = memo[ri-1] - memo[li-1]
    print(ans)


Measured memory_bytes: 6084
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> c(h, vector<char>(w));
  rep(i, h) {
    rep(j, w) {
      cin >> c[i][j];
    }
  }

  int cnt = 0;
  rep(i, h) {
    rep(j, w) {
      if (c[i][j] == '#') cnt++;
    }
  }
  int ans = 0;
  rep(S, (1 << h)) {
    rep(T, (1 << w)) {
      vector<vector<char>> res = c;
      int pos = cnt;
      rep(i, h) {
        if (S >> i & 1) {
          rep(j, w) {
            if (res[i][j] == '#') pos--;
            res[i][j] = '?';
          }
        }
      }
      rep(j, w) {
        if (T >> j & 1) {
          rep(i, h) {
            if (res[i][j] == '#') pos--;
            res[i][j] = '?';
          }
        }
      }
      if (pos == k) ans++;
    }
  }
  cout << ans << '\n';

  




  
  return 0;
}

Measured memory_bytes: 3652
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { //WOOOOOOO AtCoder is HELPING!!!!!!!!!!
		//Arraylist cheese for the win
		Scanner input = new Scanner(System.in);
		PriorityQueue<Long> subs = new PriorityQueue<Long>();
		int N = input.nextInt();
		int M = input.nextInt();
		long ans = 0;
		ArrayList<Long> deductions = new ArrayList<Long>();
		for (int i = 0; i < N; i++) {
			long x = input.nextLong();
			ans+=x;
			while (x>0) {
				long sub = x-x/2;
				deductions.add(sub);
				x/=2;
			}
		}
		Collections.sort(deductions);
		int index = deductions.size()-1;
		int cnt = 0;
		while (cnt < M) {
			ans-=deductions.get(index);
			cnt++;
			index--;
			if (index==-1) break;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 170384