akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, d, e, f, h, k, n, w, ans = 0, count = 0;
  string s;
  cin >> n;
  vector<lli> x(n), y(n), t(n);
  rep(i, 0, n)
  {
    cin >> t[i] >> x[i] >> y[i];
    if (((x[i] + y[i]) % 2 == 1 && t[i] % 2 == 0) || (x[i] + y[i]) % 2 == 0 && t[i] % 2 == 1)
    {
      count++;
    }
    if ((x[i] + y[i]) > t[i])
    {
      count++;
    }
  }
  if (count > 0)
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	static int[] w;
	static int k;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		k = sc.nextInt();
		w = new int[n];

		for (int i=0; i<n; i++) {
			w[i] = sc.nextInt();
		}

		long left = 0;
		long right = 100000 * 10000;
		while (right-left>1) {
			long mid = (left+right)/2;
			if (can(mid)) {
				right = mid;
			} else {
				left = mid;
			}
		}

		System.out.println(right);

		sc.close();
	}

	static boolean can(long v) {
		int j=0;
		for (int i=0; i<k; i++) {
			long sum = 0;
			while (j<w.length && sum+w[j]<=v) {
				sum += w[j];
				j++;
			}
		}
		if (j==w.length) {
			return true;
		}
		return false;
	}
}

Measured memory_bytes: 71568
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main(void){
  int n,x, tmp, count=1;
  cin >> n >> x;
  vector<int> v,d;
  for(int i=0; i<n; i++){
    cin >> tmp;
    v.push_back(tmp);
  }
  d.push_back(0);
  for(int i=0; i<n; i++){
    tmp = (d[i] + v[i]);
    d.push_back(tmp);
     // cout << tmp << endl;
    if(tmp > x){
      break;
    }
    count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int min, max;
  int a;
  int N;
  int i;
  min = 1000;
  max = 0;

  scanf("%d", &N);
  for (i=0; i < N; i++) {
    scanf("%d", &a);
    if (min > a) {
      min = a;
    }
    if (max < a) {
      max = a;
    }
  }
  printf("%d\n", max-min);
  return 0;
}


Measured memory_bytes: 128
X, Y = map(int, input().split())
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod

def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)
 
    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac
if (X + Y) % 3 != 0:
    print(0)
    quit()
n = (2 * Y - X) // 3
m = (2 * X - Y) // 3
if n < 0 or m < 0:
    print(0)
    quit()
mod = 10 ** 9 + 7
fac, ifac = make_tables(mod, n + m)
print(cmb(n + m, n, mod, fac, ifac))

Measured memory_bytes: 82284
#初めは0と1で多い方だと思った
#正確にやってはないけど連続する0or1より長くないとだめ
#上限が何かを考える
s=input()
l=len(s)

ans=1000000000000
for i in range(l-1):
    if s[i]!=s[i+1]:
        ne=max(i+1,l-i-1)
        ans=min(ans,ne)
if ans==1000000000000:
    print(l)
else:
    print(ans)



Measured memory_bytes: 3188
/*   Abhijith  */
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define	endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<lld>     adj[100005];
lld dp[100005][2];
void dfs(lld s,lld par)
{
    lld sz=adj[s].size();
    if(sz==1&&s!=1)          //leaf node base condition
    {
        dp[s][0]=1;
        dp[s][1]=1;
        return;
    }
    lld ans1=1,ans2=1;
    for(lld i=0;i<sz;i++)
    {
        if(adj[s][i]==par)
            continue;
        dfs(adj[s][i],s);
        ans1=(ans1*(dp[adj[s][i]][0]+dp[adj[s][i]][1])%mod)%mod;
        ans2=(ans2*dp[adj[s][i]][0])%mod;
    }
    dp[s][0]=ans1;
    dp[s][1]=ans2;
    //cout<<s<<" "<<ans1<<" "<<ans2<<endl;
}
int main()
{
      ios;
      lld x,y,n,m;
      cin>>n;
      m=n-1;
      rep(i,0,m-1)
      {
          cin>>x>>y;
          adj[x].pb(y);
          adj[y].pb(x);  //if graph is directed delete this line
      }
      dfs(1LL,0LL);
      cout<<(dp[1][0]+dp[1][1])%mod;
    return 0;
}


Measured memory_bytes: 14208
from itertools import accumulate

n,k=map(int,input().split())
p=list(map(int,input().split()))

x=[]
for i in p:
 x.append((i+1)/2)

b=[0]+list(accumulate(x))

mm=0
inx=-1
for i in range(len(b)-k):
 if b[i+k]-b[i]>=mm:
  inx=i
  mm=b[i+k]-b[i]


ans=0
for j in range(inx,inx+k):
  ans+=((p[j]*(p[j]+1))*0.5)*(1/p[j])

print(ans)

Measured memory_bytes: 26236
import math

n = int(input())

if n==1:
  print(0)
else:
  fctr = []
  for a in range(2,math.isqrt(n)+1):
    atta = 0
    if n%a==0:
      while n%a==0:
        atta += 1
        n //= a
      fctr.append((a,atta))
  if n!=1:
    fctr.append((n,1))
#  print(fctr)

  kaisu = 0
  for pair in fctr:
    if pair[1]<3:
      kaisu += 1
    elif pair[1]<6:
      kaisu += 2
    elif pair[1]<10:
      kaisu += 3
    elif pair[1]<15:
      kaisu += 4
    elif pair[1]<21:
      kaisu += 5
    elif pair[1]<28:
      kaisu += 6
    elif pair[1]<36:
      kaisu += 7
    elif pair[1]<45:
      kaisu += 8
    elif pair[1]<55:
      kaisu += 9

  print(kaisu)
  

Measured memory_bytes: 9244
using System;
using System.Collections.Generic;

class ABC073D
{
	static int N,M,R;
	static int[] r;
	static long[,] costs;
	static bool[] used;
	static List<int> path;
	static long ans;

	static public void Main(string[] args)
	{
		string[] vals = Console.ReadLine().Split(' ');
		N = int.Parse(vals[0]);
		M = int.Parse(vals[1]);
		R = int.Parse(vals[2]);
		r = new int[R+1];
		vals = Console.ReadLine().Split(' ');
		for(int i=0; i<R; i++)
		{
			r[i+1] = int.Parse(vals[i]);
		}
		costs = new long[N+1,N+1];
		for(int i=1; i<=N; i++)
		{
			for(int j=1; j<=N; j++)
			{
				costs[i,j] = -1;
			}
		}
		int A,B,C;
		for(int i=0; i < M; i++)
		{
			vals = Console.ReadLine().Split(' ');
			A = int.Parse(vals[0]);
			B = int.Parse(vals[1]);
			C = int.Parse(vals[2]);
			costs[A,B] = C;
			costs[B,A] = C;
		}


		for(int k=1; k <= N; k++)
		{
			for(int i=1; i<=N; i++)
			{
				for(int j=1; j<=N; j++)
				{
					if(costs[i,j] == -1)
					{
						if(costs[i,k] != -1 && costs[k,j] != -1)
							costs[i,j] = costs[i,k] + costs[k,j];
					}
					else
					{
						if(costs[i,k] != -1 && costs[k,j] != -1)
							costs[i,j] = Math.Min(costs[i,j], costs[i,k] + costs[k,j]);
					}
				}
			}
		}

		used = new bool[R+1];
		path = new List<int>();
		ans = long.MaxValue;
		calc();
		Console.WriteLine(ans);
	}

	static void calc()
	{
		if(path.Count == R)
		{
			long c = 0;
			//Console.WriteLine("path:");
			for(int i=0; i<path.Count-1; i++)
			{
				c += costs[path[i], path[i+1]];
				//Console.WriteLine("{0} to {1}", path[i], path[i+1]);
			}
			if(c < ans)
				ans = c;
			return;
		}
		else
		{
			for(int i=1; i<=R; i++)
			{
				if(used[i] == false)
				{
					used[i] = true;
					path.Add(r[i]);
					calc();
					path.RemoveAt(path.Count-1);
					used[i] = false;
				}
			}
		}
	}
}


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

using ll = long long;

// 組合せを素数で割った値を求める
const int MAX = 510000;
const ll MOD = 1e9 + 7;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  if(k > n) k = n - 1;
  
  COMinit();
  
  ll ans = 0;
  for(int i = 0; i <= min<int>(k, n - 1); i++){
    int zero = i, occupied = n - i;
    if(i == 0){
      ans++;
      continue;
    }
    ans += COM(n, zero) * COM((n - occupied) + (occupied - 1), n - occupied);
    ans %= MOD;
    //cout << ans << endl;
  }
  
  cout << ans << '\n';
}

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

int n, a[1000];

int main(){
	int mi;
	while (cin >> n && n != 0) {
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		mi = a[1] - a[0];
		for (int i = 1; i < n - 1; i++) {
			if (a[i + 1] - a[i] < mi) {
				mi = a[i + 1] - a[i];
			}
		}
		cout << mi << endl;
	}

	return 0;
}

Measured memory_bytes: 3136
using System;

class ABC074D
{
	static public void Main(string[] args)
	{
		int A,B,C,D,E,F;
		string[] vals = Console.ReadLine().Split(' ');

		A = int.Parse(vals[0]);
		B = int.Parse(vals[1]);
		C = int.Parse(vals[2]);
		D = int.Parse(vals[3]);
		E = int.Parse(vals[4]);
		F = int.Parse(vals[5]);

		int i,j,k,l;
		double maxcon = 0.0;
		double con;
		int answ=100*A, anss=0;
		for(i=0; 100*A*i<=F; i++)
		{
			for(j=0; 100*A*i+100*B*j<=F; j++)
			{
				for(k=0; 100*A*i+100*B*j+C*k<=F; k++)
				{
					for(l=0; 100*A*i+100*B*j+C*k+D*l<=F; l++)
					{
						if(C*k+D*l <= E*(A*i+B*j))
						{
							con = (double)(C*k+D*l)/(100*A*i+100*B*j);
							if(con > maxcon)
							{
								maxcon = con;
								answ = 100*A*i+100*B*j+C*k+D*l;
								anss = C*k+D*l;
							}
						}
					}
				}
			}
		}

		Console.WriteLine("{0} {1}", answ, anss);
	}
}


Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <unordered_set>
using namespace std;

int main()
{
	//	input	--------------------------------------------------
//	int a, b;
//	cin >> a;
//	cin >> a >> b;

	string str;
	cin >> str;

	/*
	vector< int > vec( a );
//	unordered_set<int> set;

	for( auto &it : vec )
	{
		cin >> it;
//		set.insert( it );
	}
	*/

	string buf[4] = { "dreamer", "dream", "eraser", "erase" };

	//	--------------------------------------------------

	deque< string > tmp;


	for( int i=0 ; i<4 ; i++ )
	{
		int pos = str.find( buf[i] );
		if( pos == 0 )
		{
			string st = str;
			tmp.emplace_back( st.erase( pos, buf[i].size() ) );
		}
	}
			
	
	do
	{
		string it = tmp.front();

		if( it.size() == 0 )
		{
			cout << "YES" << endl;
			return 0;
		}


		bool add = false;

		for( int i=0 ; i<4 ; i++ )
		{
			int pos = it.find( buf[i] );
			if( pos == 0 )
			{
				string st = it;
				tmp.emplace_back( st.erase( pos, buf[i].size() ) );
				add = true;
			}
		}

		tmp.pop_front();

	}
	while( !tmp.empty() );
	

	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 820
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] a;
    int i, j, count, tmp, min;

    n = sc.nextInt();
    a = new int[n];
    for(i = 0;i < n;i++){
      a[i] = sc.nextInt();
    }

    count = 0;

    for(i = 0;i < n - 1;i++){
      min = i;
      for(j = i + 1;j < n;j++){
        if(a[min] > a[j])min = j;
      }
      if(min != i){
        tmp = a[min];
        a[min] = a[i];
        a[i] = tmp;
        count++;
      }
    }

    for(i = 0;i < n - 1;i++){
      System.out.print(a[i] + " ");
    }
    System.out.println(a[n - 1]);
    System.out.println(count);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

int main(void){
	int A,B,C,D;cin >> A >> B >> C >> D;

	while(true){
		C-=B;
		if(C <= 0){
			cout << "Yes" << endl;
			return 0;
		}
		A-=D;
		if(A <= 0){
			cout << "No" << endl;
			return 0;
		}
	}
}


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


def main():
    n = int(input())
    xs = [0 for _ in range(n)]
    ys = [0 for _ in range(n)]
    d = dict()

    # KeyInsight (◯：気がつけた，△：解説を読んでなんとなく理解，×：理解できず):
    # ◯ 任意の二点について，ベクトルを計算
    # △ 同じベクトルの頻度を計算する
    # △ 頻度の最大値が減らせるコストの最大値
    # See:
    # https://www.youtube.com/watch?v=TbobvdA6AlE
    # https://atcoder.jp/contests/diverta2019-2/submissions/5920106
    for i in range(n):
        xi, yi = map(int, input().split())
        xs[i] = xi
        ys[i] = yi

    for j in range(n):
        for k in range(n):
            if j == k:
                continue

            c = xs[j] - xs[k], ys[j] - ys[k]

            if c in d:
                d[c] += 1
            else:
                d[c] = 1

    ans = n

    for di in d.values():
        ans = min(ans, n - di)

    print(ans)


if __name__ == '__main__':
    main()


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve() {
  int i, o, j, l, _;
  cin >> i >> o >> _ >> j >> l >> _ >> _;
  i64 ans = 0;
  ans += o;
  vi64 v = {i, j, l};
  sort(all(v));
  int c = 0;
  rep(i, 3) {
    c += v[i] & 1;
  }
  if (c == 3 || c == 0) {
    ans += v[0] + v[1] + v[2];
  }
  if (c == 2) {
    if (v[0] == 0) {
      ans += v[1] / 2;
      ans += v[2] / 2;
    } else {
      ans += v[0] + v[1] + v[2] - 1;
    }
  }
  if (c == 1) {
    ans += v[0] + v[1] + v[2] - 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

x=0
for i in range(n):
    if b[i]>=a[i]:
        x+=a[i]
        b[i]-=a[i]
        a[i]=0
        if a[i+1]>=b[i]-a[i]:
            x+=b[i]-a[i]
            a[i+1]-=b[i]-a[i]
            b[i]=0
        else:
            x+=a[i+1]
            a[i+1]=0
            b[i]-=a[i+1]
    else:
        x+=b[i]
        a[i]-=b[i]
        b[i]=0 
print(x)

Measured memory_bytes: 18752
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
       ll k;
      cin>>k;
      ll sum =0;
  
       for(ll i=1;i<=k;i++)
       {
         for(ll j=1;j<=k;j++)
         {
            for(ll q=1;q<=k;q++)
                {
                  //cout<<i<<" "<<j<<" "<<q<<endl;
                  sum = sum + gcd(i, gcd(j,q));
                }
          }
       }
       cout<< sum<<endl;
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
#define LL long long
int a[100010];
char s[100010];
const int maxn = 400010;
const int logn = 19;
vector <int> vc[maxn];
set<int>st;
list<int>li;
map<string,int>m;
pair<int,int>p;
bool mark[maxn];
int n, k;

void join() {
   string s,t;
   cin>>s>>t;
   for(int i=0;i<s.size();i++){
       string k=s.substr(i,t.size());
       if(k==t)cout<<i<<"\n";
   }
}

void solve() {
    LL n;
    cin >> n;
    long long x=n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(&a[0],&a[n]);
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]) --x;
    }
    cout<<x<<"\n";
}

int main()
{
    //int tc;
	//scanf("%d", &tc);
	//while(tc-->0) {
	    //solve();
	    join();
	//}
    return 0; 
}


Measured memory_bytes: 13360
N = gets.to_i
heights = gets.split.map(&:to_i)
costs = Array.new(N) { nil }
N.times do |i|
  if i == 0
    costs[i] = 0
  elsif i == 1
    costs[i] = (heights[i] - heights[i-1]).abs
  else
    costs[i] = [(heights[i] - heights[i-1]).abs + costs[i-1],
                (heights[i] - heights[i-2]).abs + costs[i-2]].min
  end
end
puts costs.last


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 40;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(ALL(a));
  sort(ALL(b));
  ll ans;
  if(n%2 == 1) ans = b[n/2] - a[n/2] + 1;
  else ans = (b[n/2-1]+b[n/2]) - (a[n/2-1]+a[n/2]) + 1;
  cout << ans << endl;
  
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<*it.F<<' '<<*it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
ll dp[2002][2002];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,x,t,m;
	cin>>n;
	vii b(n);
	for(int i=0;i<n;i++){
		cin>>b[i].F;
		b[i].S = i;
	}
	sort(all(b),greater<ii>());
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			if(i!=j){
				dp[i][j] = max(dp[i][j], dp[i-1][j] + abs(n-i+j - b[i-1].S)*b[i-1].F);
			}   
			if(j){
				dp[i][j] = max(dp[i][j], dp[i-1][j-1]+ abs(j-1 - b[i-1].S)*b[i-1].F);
			}
		}
	}
	ll ans = -1;
	for(int j=0;j<=n;j++){
		ans = max(ans, dp[n][j]);
	}
	cout<<ans;




	return 0;
}







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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (ll i=0; i<n; i++) {
        cin >> a.at(i);
    }
    vector<ll> cnt(2e5+1, 0), sum(2e5+1, 0);
    for (int i=0; i<n; i++) {
        cnt.at(a.at(i))++;
        sum.at(a.at(i)) += a.at(i);
    }
    for (int i=2e5-1; i>=0; i--) {
        cnt.at(i) += cnt.at(i+1);
        sum.at(i) += sum.at(i+1);
    }
    ll ok = -1;
    ll ng = 2e5+1;
    while (abs(ok-ng) > 1) {
        ll mid = (ok+ng)/2;
        ll tmp = 0;
        for (int i=0; i<n; i++) {
            tmp += (mid - a.at(i) >= 0) ? cnt.at(mid-a.at(i)) : cnt.at(0);
        }
        if (tmp >= m) ok = mid;
        else ng = mid;
    }
    ll ans = 0;
    for (int i=0; i<n; i++) {
        ans += a.at(i) * ((ok - a.at(i) >= 0) ? cnt.at(ok-a.at(i)) : cnt.at(0)) + ((ok - a.at(i) >= 0) ? sum.at(ok-a.at(i)) : sum.at(0));
    }
    ll tmp = 0;
    for (int i=0; i<n; i++) {
        tmp += ((ok - a.at(i) >= 0) ? cnt.at(ok-a.at(i)) : cnt.at(0));
    }
    if (tmp > m) {
        ans -= ok * (tmp - m);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define MAXN 3010010
#define Max 25
using namespace std;

int main()
{
	string str;
	cin >> str;
	int N;
	cin >> N;
	set<string>st;
	for(int i = 0 ; i < 26 ; i++) {
		char ch = 'a' + i;
		for(int j = 0 ; j < str.size() ; j++) {
			if(ch == str[j]) {
				string s = "";
				for(int k = 0 ; k < 5 ; k++) {
					if(j + k < str.size())
            s += str[j + k] , st.insert(s);
				}
			}
		}
		if(st.size() >= N) break;
	}
	int cnt = 0;
	for(auto it : st) {cnt++ ; if(cnt == N) cout << it << endl;}
}


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

int main() {
  int n;
  cin >> n;
  vector<double> p(n);
  rep(i, n) cin >> p[i];
  
  // dp[i][j]: コインをi枚まで投げてj枚が裏になる確率
  vector<vector<double>> dp(n+1, vector<double>(n+1));
  dp[0][0] = 1;

  rep(i, n) rep(j, n+1) {
    dp[i+1][j] += dp[i][j] * p[i];
    if (j) dp[i+1][j] += dp[i][j-1] * (1 - p[i]);
  }
  double ans = 0;
  rep(j, (n+1)/2) ans += dp[n][j];
  printf("%.9f\n", ans);
  return 0;
}

Measured memory_bytes: 73756
#include <iostream>
using namespace std;
  
int main(){
    int a,b,c,x,y,n;
    n=0;
    cin >> a >> b >> c;
    for (x=a;x<=b;x++){
        y= c % x;
        if ( y == 0 ){
            n++;
        }
    }
    cout << n << "\n";
    return 0;
}

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

int ft[27][500005];
int n,q;
char s[500005];
char sb[10];

void upd( int c, int x, int v ){
	while ( x <= n ){
		ft[c][x] += v;
		x += x & (-x);
	}
}

int rsq( int c, int x) {
	int ans = 0;
	while ( x > 0 ){
		ans += ft[c][x];
		x -= x & (-x);
	}
	return ans;
}

int main(){
	
	scanf("%d%s%d",&n,&s,&q);
	for ( int i = 0; i < n; i++ ){
		int v = s[i] - 'a';
		upd(v, i + 1, 1);
	}
	for ( int i = 0; i < q; i++ ){
		int c, a,b;
		scanf("%d%d",&c,&a);
		if ( c == 1 ){
			scanf("%s",&sb);
			int v = s[a-1] -'a';
			upd(v, a  , - 1 );
			s[a-1] = sb[0];
			upd(sb[0]-'a', a , 1 );
		} else {
			scanf("%d",&b);
			int ans = 0;
			for ( int i = 0; i < 26; i++ ){
				if ( rsq(i, b) - rsq(i,a-1) > 0 ) ans++;
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 51584
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, x, y;
    cin >> n >> x >> y;
    --x;
    --y;
    vector<int> res(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int d = j - i;
            chmin(d, abs(x - i) + abs(y - j) + 1);
            chmin(d, abs(y - i) + abs(x - j) + 1);
            res[d]++;
        }
    }
    for (int i = 1; i < n; i++) {
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


//const int MAX_COMB = 510000;
const int MAX_COMB = 2100000;
long long fac[MAX_COMB], finv[MAX_COMB], inv[MAX_COMB];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_COMB; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    COMinit();
    int x, y;
    cin >> x >> y;

    ll ans = 0;
    for(int i=0; i<=max(x, y); i++){
        int j = (x + y -3*i);
        if(j < 0) continue;
        if(j%3 == 0){
            j /= 3;
            if(x != i + 2*j || y != 2*i + j) continue;
            ans += COM(i+j, i);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 49408
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int m, k, a=0, b=0, c=0, p, q;
    vector<int> v, w;
    cin>>m>>k;

    for(int i=0;i<32;i++){
        if(((k>>i)&1)==1){
            if(i>=m){
                cout<<-1<<endl;
                return 0;
            }
            int x=(1<<i);
            a^=x;
            v.push_back(x);
        }
    }
    p=v.size();
    for(int i=0;i<(1<<m);i++){
        if(c<p&&i==v[c]){
            c++;
        }else{
            if(p>0)b^=i;
            w.push_back(i);
        }
    }
    //cout<<"Debug "<<a<<" "<<b<<endl;
    if(a!=k||b!=k){
        cout<<-1<<endl;
        return 0;
    }
    q=w.size();

    for(int i=0;i<p;i++){
        cout<<v[i]<<" ";
    }
    //cout<<"Debug"<<endl;
    for(int i=0;i<q;i++){
        cout<<w[i]<<" ";
    }
    for(int i=p-1;i>=0;i--){
        cout<<v[i]<<" ";
    }
    for(int i=q-1;i>=0;i--){
        cout<<w[i]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 2424
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < n; ++i)

pair<int, bool> r[200000];

int main() {
	int w, h;
	scanf("%d%d", &w, &h);
	int s = w + h;
	f(i, 0, w)scanf("%d", &r[i].first);
	f(i, 0, h)scanf("%d", &r[i + w].first), r[i + w].second = true;
	sort(r, r + s);
	++w, ++h;
	ll an = 0;
	f(i, 0, s) {
		if (r[i].second)an += (ll)r[i].first * w, --h;
		else an += (ll)r[i].first * h, --w;
	}
	printf("%lld\n", an);
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  string s;
  cin >> s;
  vector<char> ans(10,' ');
  int pointer=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='0'){
      ans.at(pointer)='0';
      pointer++;
    }
    else if(s.at(i)=='1'){
      ans.at(pointer)='1';
      pointer++;
    }
    else if(s.at(i)=='B'){
      if(pointer>0)  pointer--;
    }
  }

  for(int i=0;i<pointer;i++){
    cout << ans.at(i);
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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;
}
const long long INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i <= n; i++) {
        if(i >= 1 && i < 10) {
            ans++;
        }else if(i >= 100 && i < 1000) {
            ans++;
        }else if(i >= 10000 && i < 100000) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}



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

using namespace std;

const int N = 2010;
const int NN = 2010;

unsigned long long one = 1;
unsigned long long g[N][NN];
unsigned long long was[NN]; 

bool alive[N]; 
bool can_put[N]; 

int a[N];
int x[N]; 

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (__gcd(a[i], a[j]) > 1) {
        g[i][j >> 6] |= (one << (j & 63));
        g[j][i >> 6] |= (one << (i & 63));
      }
    }
  }
  int nn = ((n - 1) >> 6) + 1;
  for (int i = 0; i < n; i++) {
    alive[i] = true;
    can_put[i] = true;
  }
  for (int it = 0; it < n; it++) {
    for (int i = 0; i < nn; i++) {
      was[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      if (!alive[i]) {
        was[i >> 6] |= (one << (i & 63));
      }
    }
    int best = -1;
    for (int i = 0; i < n; i++) {
      if (was[i >> 6] & (one << (i & 63))) {
        continue;
      }
      int b = 0, e = 1;
      x[0] = i;
      was[i >> 6] |= (one << (i & 63));
      while (b < e) {
        for (int j = 0; j < nn; j++) {
          if ((g[x[b]][j] & was[j]) != g[x[b]][j]) { 
            for (int u = j * 64; u < (j + 1) * 64; u++) { 
              if (g[x[b]][u >> 6] & (one << (u & 63))) {
                if (!(was[u >> 6] & (one << (u & 63)))) {
                  was[u >> 6] |= (one << (u & 63));
                  x[e++] = u;
                }
              }
            }
          }
        }
        b++;
      }
      int cur = -1;
      for (int j = 0; j < e; j++) {
        if (!can_put[x[j]]) {
          continue;
        }
        if (cur == -1 || a[x[j]] < a[cur]) {
          cur = x[j];
        }
      }
      if (best == -1 || (cur != -1 && a[cur] > a[best])) {
        best = cur;
      }
    }
    if (it > 0) putchar(' ');
    printf("%d", a[best]);
    alive[best] = false;
    for (int i = 0; i < n; i++) {
      if (!alive[i]) {
        continue;
      }
      if (g[best][i >> 6] & (one << (i & 63))) {
        can_put[i] = true;
      } else {
        if (a[best] < a[i]) {
          can_put[i] = false;
        }
      }
    }
  }
  printf("\n");
  return 0;
}


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

int main(){
  int a,b,mx;

  while( cin >> a >> b, a+b ){
    char ans = 'A';
    mx =  a + b;
      for(int i = 1 ; i < 5 ; i++ ){
	cin >> a >> b;
	if(mx < a+b){
	  mx = a+b;
	  ans = char('A'+i); 
	}
      }
      cout << ans <<' '<<mx << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
from fractions import gcd
a, b, c, d = map(int, input().split())

def calc(x, k):
    return x // k


def all_calc(x):
    return x - (calc(x, c) + calc(x, d) - calc(x, c * d // gcd(c, d)))
print(all_calc(b) - all_calc(a - 1))


Measured memory_bytes: 5728
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int main() {
	ll D; cin >> D;
	
	ll ans = 0;
	
	FOR(k, 2, 20) {
		ll t[11] = {};
		REP(i, k / 2) t[i] = (ll)powl(10, k - i - 1) - (ll)powl(10, i);
		
		ll nowcnt = 0;
		
		queue<pll> que[11];
		que[0].push(pll(D, 1));
		REP(i, k / 2) {
			while (!que[i].empty()) {
				pll now = que[i].front(); que[i].pop();
				ll n = now.fi, c = now.se;
				
				ll d = abs(n) / t[i];
				if (d >= 10) continue;
				
				int tim = 10 - d;
				if (i == 0) tim--;
				que[i + 1].push(pll(n - d * t[i] * (n >= 0 ? 1 : -1), c * tim));
				
				if (d == 9) continue;
				d++;
				tim = 10 - d;
				if (i == 0) tim--;
				que[i + 1].push(pll(n - d * t[i] * (n >= 0 ? 1 : -1), c * tim));
			}
		}
		
		while (!que[k / 2].empty()) {
			pll now = que[k / 2].front(); que[k / 2].pop();
			ll n = now.fi, c = now.se;
			if (n == 0) nowcnt += c;
		}
		
		if (k & 1) nowcnt *= 10;
		ans += nowcnt;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n){
        cin >> a[i];
    }
    map<int, int> mapping;
    REP(i, n){
        mapping.insert(make_pair(a[i], i+1));
    }
    bool isFst = true;
    for (auto e : mapping){
        if(isFst){
            cout << e.snd;
            isFst = false;
        }
        else {
            cout << " " << e.snd;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 5888
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll h[101010];
ll dp[101010];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	rep(i, n) {
		cin >> h[i];
		dp[i] = INF;
	}
	dp[0] = 0;
	rep(i, n) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
mt19937_64 mt(1);//seed
uniform_real_distribution<double> rnd(0.00,1.00);




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

	double a2tans = 2.0*a*b-2.0*x/a;
	double tans = a2tans/a/a;
	double EPS = 1e-10;
	if( (double)b-a*tans > -EPS){
		out(10) << atan(tans)*180.0/M_PI << endl;
		return 0;
	}
	double ans = double(1.0*a*b*b)/(2.0*x);
	out(10) << atan(ans)*180.0/M_PI << endl;
}


Measured memory_bytes: 256
STDIN.each_line do |line|
  x1, y1, x2, y2, x3, y3, xp, yp = line.split(" ").map(&:to_f)
  a, b, c, d, x, y = x2-x1, x3-x1, y2-y1, y3-y1, xp-x1, yp-y1
  det = a*d-b*c

  s, t = (d*x-b*y)/det, (-c*x+a*y)/det

  puts (s>0 && t>0 && s+t<1)? "YES" : "NO"
end

Measured memory_bytes: 8692
# -*- coding: utf-8 -*-
x = int(input())
y = input()

z = y

while z.find("()") != -1:
    z = z.replace("()","")

a = z.count("(")
b = z.count(")")

ans = y

for i in range(a):
    ans = ans + ")"

for i in range(b):
    ans = "(" + ans

print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll h,w;
ll v[3];

int main(void){
	scanf("%lld%lld",&h,&w);
	if(h*w%3LL==0){
		printf("0\n");
		return 0;
	}else{
		ll res=min(w,h);
		for(ll i=1;i<h;i++){
			v[0]=i*w;
			v[1]=(h-i)*(w/2LL);
			v[2]=(h-i)*((w+1LL)/2LL);
			sort(v,v+3);
			res=min(res,v[2]-v[0]);
		}
		for(ll i=1;i<w;i++){
			v[0]=i*h;
			v[1]=(w-i)*(h/2LL);
			v[2]=(w-i)*((h+1LL)/2LL);
			sort(v,v+3);
			res=min(res,v[2]-v[0]);
		}
		printf("%lld\n",res);
	}
	return 0;
}


Measured memory_bytes: 764
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
dp=[0]*(k+1)
for i in range(1,k+1):
    for j in a:
        if i>=j and dp[i-j]==0:
            dp[i]=1
            break
if dp[k]:
    print("First")
else:
    print("Second")

Measured memory_bytes: 41836
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int ac = 0;
    int wa = 0;

    vector<int> A(n + 1, 0);
    vector<int> W(n + 1, 0);
    for (int i = 0; i < m; ++i) {
        int x;
        string s;
        cin >> x >> s;
        --x;
        if (s == "AC") {
            if (A[x]++ == 0) {
                ac += 1;
                wa += W[x];
            }
        } else {
            W[x] += 1;
        }
    }
    cout << ac << " " << wa << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	long int a = 0,sum = 0, min = 1000001,max = -1000001;
	int n ,i;

	scanf("%d",&n);

	for(a = 1; a <= n; a++){
		scanf("%d",&i);
		if(i < min) min = i;
		if(i > max) max = i;
		sum += i;
	}

	printf("%ld %ld %ld\n",min,max,sum);
	
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int[] a = new int[n];
        for (int i = 1; i < n; i++) {
            a[i] = in.nextInt();
        }

        int[] boss = new int[n];
        Arrays.fill(boss, 0);
        for (int i = 1; i < n; i++) {
            boss[a[i] - 1]++;
        }

        for (int i = 0; i < boss.length; i++) {
            System.out.println(boss[i]);
        }
    }
}


Measured memory_bytes: 62436
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main{
    public static void main(String[] args)throws IOException{
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(isr);
        String string;
        int count;
         
        boolean hamming[] = new boolean[1000001]; hamming[1] = true;
        int num[] = new int[]{2, 3, 5};
        for(int i = 0; i < 3; i++){
            for(int j = 1; j * num[i] < 1000001; j++){
                if(hamming[j * num[i]]) continue;
                if(j * num[i] % num[i] == 0 && hamming[j * num[i] / num[i]])
                    hamming[j * num[i]] = true;
            }
        }
         
        while(!(string = reader.readLine()).equals("0")){
            count = 0;
            for(int i = Integer.valueOf(string.split(" ")[0]);
                    i <= Integer.valueOf(string.split(" ")[1]); i++){
                if(hamming[i]) count++;
            }
            System.out.println(count);
        }
        reader.close();
    }
}

Measured memory_bytes: 289688
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int H, W;

  std::cin >> H >> W;

  std::vector<std::string> board(H);

  for (auto& s : board)
    std::cin >> s;

  std::queue<std::pair<int, int>> queue;

  int dist[1111][1111];

  memset(dist, -1, sizeof(dist));

  for (int i = 0; i < H; i ++)
    for (int j = 0; j < W; j ++)
      if (board[i][j] == '#') {
        queue.emplace(j, i);

        dist[i][j] = 0;
      }

  int dp = 0;

  while (! queue.empty()) {
    auto pair = queue.front(); queue.pop();

    int x = pair.first, y = pair.second;

    for (int k = 0; k < 4; k ++) {
      int xx = x + dx[k], yy = y + dy[k];

      if (xx < 0 || xx >= W || yy < 0 || yy >= H)
        continue;

      if (dist[yy][xx] >= 0)
        continue;

      dp = std::max(dist[yy][xx] = dist[y][x] + 1, dp);

      queue.emplace(xx, yy);
    }
  }

  std::cout << dp << std::endl;

  return 0;
}


Measured memory_bytes: 14464
N = int(input())
X = list(map(int, input().split()))

X_sorted = sorted(X)
m = X_sorted[N // 2]

for i in range(N):
  if X[i] < m:
    res = X_sorted[N // 2]
  elif X[i] >= m:
    res = X_sorted[N // 2 - 1]

  print(res)
      

Measured memory_bytes: 25344