akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int a,b;cin >> a >> b;
    string s; cin >> s;
    rep(i,a+b+1){
        if(i==a){
            if(s[i]!='-'){
                out("No");
                return 0;
            }
        }
        else{
            if(s[i] == '-'){
                out("No");
                return 0;
            }
        }
    }
    out("Yes");
}


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

int main() {
    int a, b, c, d, max=0, min=0, n;
    cin >> a >> b >> c >> d;
    
    max = (b > d ? b : d);
    min = (a < c ? a : c);
    
    n = (max-min)-(b-a)-(d-c);
    cout << (n > 0 ? 0 : abs(n)) << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
li = list(map(int, input().split()))

li.sort()
base = max(li) - min(li)
cost = []

for i in range(m-1):
    tmp = li[i+1] - li[i]
    cost.append(tmp)

cost.sort()
if n == 1:
    res = 0
else:
    res = sum(cost[-n+1:])

print(base - res)

Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dx={0,1,0,-1};
vector<int> dy={1,0,-1,0};
int h,w;
bool f(int y,int x,vector<vector<char>> &s){
    if(s[y][x]=='.') return true;
    rep(i,0,4){
        int ny=y+dy[i],nx=x+dx[i];
        if(ny<0 || ny>=h || nx<0 || nx>=w) continue;
        if(s[ny][nx]=='#') return true;
    }
    return false;
}

int main(){
    cin>>h>>w;
    vector<vector<char>> s(h,vector<char>(w));
    rep(i,0,h) rep(j,0,w) cin>>s[i][j];
    
    rep(i,0,h) rep(j,0,w) {
        if(!f(i,j,s)) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


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

int main(int argc, const char **argv)
{
    double a = 0, b = 0, n = 0;

    fscanf(stdin, "%lf %lf %lf", &a, &b, &n);

    if ( b > n ) fprintf( stdout, "%ld\n", (long)( a * n / b ) );
    else fprintf( stdout, "%ld\n", (long)( a * (b - 1) / b ) );

    return 0;
}

Measured memory_bytes: 2220
import sys
input=sys.stdin.readline
n=int(input())
ns=str(n)
l=len(ns)
ans=0
for i in range(1,n+1):
    s=str(i)
    x=s[0]
    y=s[-1]
    if y=='0':
        continue
    if x==y:
        ans+=1
    if l==1:
        continue
    for j in range(l-2):
        ans+=10**j
    if int(ns[0])>int(y):
        ans+=10**(l-2)
    elif int(ns[0])<int(y):
        pass
    else:
        z=n-int(ns[0])*10**(l-1)
        if z>=int(x):
            w=z-int(x)
            ans+=w//10+1
print(ans)






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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    long long x = n/(a+b);
    if (n >= (a+b)*x+a) cout << a*(x+1) << endl;
    else cout << a*x + (n - x*(a + b)) << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        a: [usize;n-1],
    };
    // let mut ans: Vec<usize> = Vec::with_capacity(n);
    let mut ans = vec![0; n].into_boxed_slice();
    for i in a.iter() {
        ans[i - 1] += 1;
    }
    for i in ans.iter() {
        println!("{}", i);
    }

}


Measured memory_bytes: 4304
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a,b;
  cin>>a>>b;
  if(a.size()>b.size()){
      cout<<"GREATER"<<endl;
      return 0;
  }
  else if(a.size()<b.size()){
      cout<<"LESS"<<endl;
      return 0;
  }
  else {
      for(int i=0;i<a.size();i++){
          if(a[i]>b[i]){
              cout<<"GREATER"<<endl;
              return 0;
          }
          if(a[i]<b[i]){
              cout<<"LESS"<<endl;
              return 0;
          }
          if(i==a.size()-1){
              cout<<"EQUAL"<<endl;
              return 0;
          }
      }
  }
  
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<utility>

using namespace std;
typedef pair<int, int> P;
const int INF = (1 << 30);
int V, E, r;
int dp[100000];
struct edge{
	int to, cost;
	edge(int to,int cost=1):to(to),cost(cost){}
};
vector<edge> G[100000];



int main()
{
	ios::ios_base::sync_with_stdio(false);
	 cin >> V >> E >> r;
	for (int i = 0; i < E; ++i) {
		int s, t, d;
		cin >> s >> t >> d;
		edge e(t,d);
		G[s].push_back(e);
	}
	fill(dp, dp + V, INF);
	dp[r] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	P start(0, r);
	que.push(start);
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (dp[p.second] < p.first)continue;

		int v = p.second;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (dp[e.to]>dp[v] + e.cost) {
				dp[e.to] = dp[v] + e.cost;
				que.push(P(dp[e.to], e.to));
			}
		}
	}
	for (int i = 0; i < V; i++) {
		if (dp[i] == INF)cout << "INF\n";
		else cout << dp[i] << "\n";
	}
	cout << flush;
	return 0;
}

Measured memory_bytes: 11288
# python template for atcoder1
from functools import reduce
from math import log2
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def floor(x, y):
    return int((-x)//y*(-1))


def floorlog(x):
    if x > 0:
        return floor(log2(x), 1)
    else:
        return 0


def XXor(X, A):
    #    print("x,a->", X, A)
    return X ^ A


N, K = map(int, input().split())
A = list(map(int, input().split()))


def xorSum(X):
    ret = 0
    for a in A:
        ret += XXor(X, a)
    return ret


def solve():

    ans = 0
    ans_x = 0
    for x in range(K+1):
        tmp = xorSum(x)
        if tmp > ans:
            ans = tmp
            ans_x = x
    # print("ans_x->", ans_x)

    return ans


def solve2():
    ans = 0
    for i in reversed(range(0, 40)):
        b = sum([(a >> i) % 2 for a in A])*2 < N
        if b and ans+(1 << i) <= K:
            ans += (1 << i)
        else:
            continue
    return xorSum(ans)


print(solve2())


Measured memory_bytes: 14696
// diverta2019_2_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 30)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
//struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    vector<int> A(N);
    REP(i, N) cin >> A[i];
    sort(ALL(A));

    int sm = accumulate(ALL(A), 0);

    int ans = -INF;
    int split_idx = -1;
    int tmp_sm = 0;
    REP(i, N-1){
        tmp_sm += A[i];
        if (sm - 2 * tmp_sm >= ans) {
            ans = sm - 2 * tmp_sm;
            split_idx = i;
        }
    }

    print(ans);

    int x = A[0];
    REPN(i, split_idx+1, N-1){
        print(x, A[i]);
        x -= A[i];
    }

    print(A[N-1], x);
    x = A[N-1] - x;

    REPN(i, 1, split_idx+1){
        print(x, A[i]);
        x -= A[i];
    }


    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using Int = int64_t;
const Int INF = 1<<30;
const Int MOD = (Int)1e9 + 7;
const Int MAX_N = (Int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    Int n; cin >> n;
    Int ans = 1LL<<50;
    for(Int A = 1; A <= sqrt(n); A++)
    {
        if(n % A) continue;
        Int B = n / A;
        ans = min(ans, A - 1 + B - 1);
    }
    cout << ans << endl;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n,x,y,z;
    scanf("%d",&n);
    x = n/100;
    y = n/10%10;
    z = n%10;
    if(x == y && z == y)
        printf("%d\n",n);
    else
    {
        for(int i = n+1; i <= 999; i++)
        {
            x = i/100;
            y = i/10%10;
            z = i%10;
            if(x == y && z == y)
            {
                printf("%d\n",i);
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 128
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#define INF 100000000000000
using namespace std;

int main() {
    long long N;
    long long temp;
    long long cnt=0;
    cin >> N;
    vector<long long> A(N);
    for(int i=0; i<N; i++){
        cin >> A.at(i);
    }
    for(int i=0; i<N-1; i++){
        for(int j=N-1; j > i; j--){
            if(A.at(j) < A.at(j-1)){
                temp = A.at(j);
                A.at(j) = A.at(j-1);
                A.at(j-1) = temp;
                cnt++;
            }
        }
    }
    for(int i=0; i<N-1; i++){
        cout << A.at(i) << " ";
    }
    cout << A.at(N-1) << endl;
    cout << cnt << endl;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
using namespace std;
const int tINF = (int)INT_MAX;
const long long lINF = (long long)LLONG_MAX;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef DEBUG
			assert(freopen("inp", "r", stdin));
			assert(freopen("out", "w",stdout));
	#else
			#define cerr if(false)cerr
	#endif
    int n, r;
    cin >> n  >> r;
    if(n <= 10)
        cout << r + (100 * (10 - n)) << '\n';
    else
        cout << r <<  '\n';
   cerr << "Time execute: " << (double)clock() / (double)CLOCKS_PER_SEC 
    << " sec" << endl;
}

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

int main() {
ll a,b;
cin >> a >>b;
ll n = b-a+1;
if(a==0||b==0||(a<0&&b>0))cout <<"Zero" << endl;
else if(n%2==0||(n%2!=0&&a>0)) cout <<"Positive" << endl;
else cout << "Negative" << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S;
    cin >> S;
    string next = "";
    REP(i,12){
        next += S[i];
        if(i == 3)next += ' ';
    }
    cout << next << "\n";
}

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

int solve(long long &A, long long &B, long long &C)
{
    long long change = 0;
    long long A0, B0, C0;
    A0 = A;
    B0 = B;
    C0 = C;
    while (A0 % 2 == 0 && B0 % 2 == 0 && C0 % 2 == 0)
    {
        A = B0 / 2 + C0 / 2;
        B = A0 / 2 + C0 / 2;
        C = A0 / 2 + B0 / 2;
        A0 = A;
        B0 = B;
        C0 = C;
        change++;
        if (change == pow(10, 5))
        {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << change << endl;
    return 0;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    solve(A, B, C);
    return 0;
}


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

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

vector<P> graph[100005];
vector<ll> dist(100005, 1e+15);
bool setted[100005];

bool dfs(int from){
    for(auto p : graph[from]){
        int to = p.first, cost = p.second;
        if(setted[to]){
            if(dist[to] != dist[from] + cost)   return false;
        }
        else{
            setted[to] = true;
            dist[to] = dist[from] + cost;
            if(!dfs(to))    return false;
        }
    }
    return true;
}

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

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        graph[l].push_back(P(r, d));
        graph[r].push_back(P(l, -d));
    }
    for(int i = 0; i < n; ++i){
        if(!setted[i]){
            setted[i] = true;
            dist[i] = 0;
            if(!dfs(i)){
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 11520
n, k = map(int,input().split())
a_l = list(map(int,input().split()))

from collections import defaultdict
a_dict = defaultdict(int)

for a in a_l:
    a_dict[a] += 1
a_count = list(a_dict.values())
a_count.sort()
variety = len(a_count)

ans = 0
i = 0
while variety > k:
    variety -= 1
    ans += a_count[i]
    i += 1
print(ans)
    

Measured memory_bytes: 33280
N = int(input())
A = list(map(int, input().split()))
memo = {}

for a in A:
    try:
        memo[a] += 1
    except:
        memo[a] = 1

import math
def combinations_count(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

sum_memo = 0

for key in memo.keys():
    sum_memo += combinations_count(memo[key], 2)

for a in A:
    print(sum_memo-(memo[a]-1))


Measured memory_bytes: 24996
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;

int N;

int input() {
  string S;
  cin >> S;
  int h, m, s;
  h = (S[0] - '0') * 10 + (S[1] - '0');
  m = (S[3] - '0') * 10 + (S[4] - '0');
  s = (S[6] - '0') * 10 + (S[7] - '0');
  return h * 3600 + m * 60 + s;
}

int main(void) {
  while(cin >> N, N) {
    pii T[20000];
    REP(i, 0, N) {
      T[i * 2] = pii(input(), 1);
      T[i * 2 + 1] = pii(input(), 0);
    }

    sort(T, T + N * 2);

    // REP(i, 0, N * 2) {
    //   cout << T[i].fi << " " << T[i].se << endl;
    // }
    // cout << endl;

    int ans = 0, cnt = 0;
    REP(i, 0, N * 2) {
      if(T[i].se == 0) cnt--;
      if(T[i].se == 1) cnt++;
      ans = max(ans, cnt);
    }
    cout << ans << endl;
  }
  return 0;
}

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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;
    cin >> c;
    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;

void insertionSort(vector<int> a, int n){
  //表示
  cout << a[0];
  for (int x = 1; x < n; x++){
    cout << " " << a[x];
  }
  cout << "\n";

  for (int i = 1; i < n; i++){
    int tmp = a[i];
    int j = i - 1;

    while(j >= 0 && a[j] > tmp){
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = tmp;

    //表示
    cout << a[0];
    for (int x = 1; x < n; x++){
      cout << " " << a[x];
    }
    cout << "\n";
  }
}

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

  cin >> n;

  a.resize(n);

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

  insertionSort(a, n);

  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int n;
int b[110];
int main()
{
  cin >> n;
  rep(i,n-1) cin >> b[i];
  
  int res = 0;
  res += b[0] + b[n-2];
  rep(i,n-2){
    res += min(b[i],b[i+1]);
  }
  
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
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 mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<double> p(n);
    rep(i,n){
        cin >> p[i];
    }
    vector<vector<double>> dp(n+1,vector<double>(n+1));
    for(ll i=1;i<=n;i++){
        if(i==1){
            dp[i][i]=p[i-1];
            dp[i][i-1]=(double)(1-p[i-1]);
            continue;
        }
        for(ll j=0;j<=n;j++){
            if(j+1<=n){
                dp[i][j+1]+=dp[i-1][j]*p[i-1];
            }
            dp[i][j]+=dp[i-1][j]*((double)(1-p[i-1]));
        }
    }
    double ans=0;
    for(ll i=0;i<=n;i++){
        if(i>=((n+1)/2)){
            ans+=dp[n][i];
        }
    }
    cout << setprecision(10) << fixed;
    cout << ans << endl;
    return 0;
} 

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


int main() {
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == b[i] && b[i] == c[i])
            continue;
        if(a[i] == b[i] || b[i] == c[i] || c[i] == a[i])
            ans++;
        else ans += 2;
    }
    cout << ans << endl;
}


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

using ll = long long;

int main()
{
    string S, T;
    int N;
    cin >> N;
    cin >> S >> T;
    string an;
    for(int i = 0; i<N; i++){
        an += S.at(i);
        an += T.at(i);
    }
    cout << an << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<ctime>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<bitset>
#define ll long long 
#define ull unsigned long long 
#define mem(a) memset(a,0,sizeof(a))
#define rint register int 
#define rll register long long 
#define rull register unsigned long long 
#define rchar register char
#define rstring register string 
#define rfloat register float
#define rdouble register double 
#define fio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define For(i,a,b) for(int i=a;i<b;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define cFor(i,a,b) for(int i=a;i>b;i--)
#define cFOR(i,a,b) for(int i=a;i>=b;i--)
#define lFor(i,a,b) for(ll i=a;i<b;i++)
#define lFOR(i,a,b) for(ll i=a;i<=b;i++)
#define lcFor(i,a,b) for(ll i=a;i>b;i--)
#define lcFOR(i,a,b) for(ll i=a;i>=b;i--)
#define watch(a) cout<<#a<<"="<<a<<endl
#define mkp(a,b) make_pair(a,b)
#define inthis cout<<"--------this\n"
#define pr(a,b) pair(a,b)
#define iset(a) set<a>::iterator 
#define imap(a,b) map<a,b>::iterator 
#define vec vector
#define fi first
#define se second
#define _vec vector<int>
#define __vec vector<vector<int>> 
#define pb push_back
#define mp map
#define _pr pair<int,int>
#define ins insert
#define era erase
#define fin find
#define EXIT exit(0)
#define all(a) a.begin(),a.end()
using namespace std;

int main(){
	fio;
	_vec p;
	int n;
	cin>>n;
	while(n--){
		int x;
		cin>>x;
		p.pb(x);
	}	
	int ans=0;
	For(i,1,p.size()-1){
		_vec tmp;
		FOR(j,-1,1)
			tmp.pb(p[i+j]);
		sort(all(tmp));
		if(tmp[1]==p[i])
			ans++;	
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    ll k; cin >> k;
    ll n = s.size();
    vector dp(n, vector(n+1, vector(k+1, 0LL)));

    auto dfs = [&](auto self, ll l, ll r, ll x){
        if(dp[l][r][x])return dp[l][r][x];
        if(r - l == 1){
            return dp[l][r][x] = 1;
        }
        if(r - l == 2){
            if(x){
                return dp[l][r][x] = 2;
            }
            else{
                return dp[l][r][x] = (s[l] == s[r-1] ? 2 : 1);
            }
        }
        ll res = 0;
        chmax(res, self(self, l, r-1, x));
        chmax(res, self(self, l+1, r, x));
        if(s[l] == s[r-1]) chmax(res, self(self, l+1, r-1, x) + 2);
        else{
            if(x)chmax(res, self(self, l+1, r-1, x-1) + 2);
        }

        return dp[l][r][x] = res;
    };

    cout << dfs(dfs, 0, n, k) << "\n";
}

Measured memory_bytes: 219096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll mod = 1e9 + 7;
const ll b1 = 9973, b2 = 100000007;

ll Pow(ll a, ll b) {
	ll res = 1; a %= mod;
	while (b) {
		if (b & 1) {
			res = (res * a) % mod;
		}
		a = (a * a) % mod;
		b >>= 1;
	}
	return res;
}

class RollingHash {
	int N;
	string s;
	vector<ll> r1, r2, h1, h2, rh1, rh2;
public:
	RollingHash(const string& s_)
		: N((int)s_.size()), s(s_), r1(N + 1), r2(N + 1), h1(N + 1), h2(N + 1), rh1(N + 1), rh2(N + 1) {
		r1[0] = r2[0] = 1;
		for (int i = 1; i <= N; i++) r1[i] = r1[i - 1] * b1 % mod;
		for (int i = 1; i <= N; i++) r2[i] = r2[i - 1] * b2 % mod;

		h1[0] = h2[0] = 1;
		for (int i = 1; i <= N; i++) h1[i] = (h1[i - 1] * b1 + s[i - 1]) % mod;
		for (int i = 1; i <= N; i++) h2[i] = (h2[i - 1] * b2 + s[i - 1]) % mod;
	}
	P get(int l, int r) {
		return P((h1[r + 1] - h1[l] * r1[r - l + 1] % mod + mod) % mod, (h2[r + 1] - h2[l] * r2[r - l + 1] % mod + mod) % mod);
	}
};

int main()
{
	cin.sync_with_stdio(false);
	int Q;
	string S;
	cin >> S >> Q;
	int N = S.size();
	RollingHash rh(S);
	vector<P> dis;
	for (int i = 0; i < N; i++) {
		for (int j = -25; j <= 25; j++) {
			dis.push_back(P(Pow(b1, i) * (mod + j) % mod, Pow(b2, i) * (mod + j) % mod));
		}
	}
	sort(dis.begin(), dis.end());
	for (int i = 0, l, r, t; i < Q; i++) {
		cin >> l >> r >> t; l--; r--;
		auto lrh = rh.get(l, r - t), rrh = rh.get(l + t, r);
		ll d1 = (lrh.first - rrh.first + mod) % mod, d2 = (lrh.second - rrh.second + mod) % mod;
		if (r - l + 1 > t * 2) {
			if (binary_search(dis.begin(), dis.end(), P(d1, d2))) {
				puts("Yes");
			}
			else {
				int w = r - l + 1 , fl = (r - l + 1) / t * t;
				if (w == fl && rh.get(l, l + t - 1) != rh.get(r - t + 1, r)) {
					puts("No");
					continue;
				}
				if (w != fl && (rh.get(l, l + w - fl - 1) != rh.get(r - (w - fl - 1), r) || rh.get(l + w - fl, l + t - 1) != rh.get(r - t + 1, r - (w - fl)))) {
					puts("No");
					continue;
				}
				ll lb = t - 1, ub = r - l + 1 - t;
				while (lb + 1 < ub) {
					ll c = (lb + ub) / 2;
					lrh = rh.get(l, l + c - 1), rrh = rh.get(l + t, l + t + c - 1);
					d1 = (lrh.first - rrh.first + mod) % mod, d2 = (lrh.second - rrh.second + mod) % mod;
					if (binary_search(dis.begin(), dis.end(), P(d1, d2))) {
						lb = c;
					}
					else {
						ub = c;
					}
				}
				ll tmp = lb;
				lb = t - 1, ub = r - l + 1 - t;
				while (lb + 1 < ub) {
					ll c = (lb + ub) / 2;
					lrh = rh.get(r - t - c + 1, r - t), rrh = rh.get(r - c + 1, r);
					d1 = (lrh.first - rrh.first + mod) % mod, d2 = (lrh.second - rrh.second + mod) % mod;
					if (binary_search(dis.begin(), dis.end(), P(d1, d2))) {
						lb = c;
					}
					else {
						ub = c;
					}
				}
				puts(tmp + lb == r - l || lb == r - l + 1 - t ? "Yes" : "No");
			}
		}
		else {
			puts(binary_search(dis.begin(), dis.end(), P(d1, d2)) ? "Yes" : "No");
		}
	}
	return 0;
}

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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main() {
  ios:: sync_with_stdio(false);
  cin.tie();
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> sum(n + 5, 0);
  for (int i = 0; i + 1 < n; i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      sum[i + 1]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    sum[i] += sum[i - 1];
  }
  while (q--) {
    int l, r;
    cin >> l >> r;
    int ans = sum[r - 1] - sum[l - 1];
    cout << ans << '\n';
  }

  return 0;
}




Measured memory_bytes: 3876
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n, k, *a = map(int, read().split())

    cur_town = 0
    transits = set()
    tran_time = defaultdict(int)
    cnt = 0
    while True:
        if k == 0:
            print(cur_town + 1)
            sys.exit()
        if cur_town in transits:
            break
        else:
            transits.add(cur_town)
            tran_time[cur_town] = cnt
            cur_town = a[cur_town] - 1
            cnt += 1
            k -= 1
    k2 = k % (cnt - tran_time[cur_town])
    while k2 > 0:
        k2 -= 1
        cur_town = a[cur_town] - 1
    print(cur_town + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 46112
N = int(input())
A = [0]
A.extend(list(map(int, input().split())))

boxes = [0 for i in range(N+1)]  # 後に最初の要素を取り除く

for i in range(N, 0, -1):
    # print("iiii = ", i)
    wa = 0
    for j in range(i, N+1, i):
        # print("j = ", j)
        wa += boxes[j]
    if wa % 2 != A[i]:
        boxes[i] = 1

ans_n = sum(boxes)
ans_list = []

for i in range(len(A)):
    if boxes[i] == 1:
        ans_list.append(i)
print(ans_n)
if ans_n != 0:
    print(" ".join(map(str, ans_list)))


Measured memory_bytes: 19892
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <math.h>
#include <numeric>
#include <algorithm>
#include <string>
#include <tuple>

typedef long long ll;

using namespace std;



int main() {
    int a,b;
    cin >> a >> b;
    int ret = max(a,b)*2 +(a==b) -1;
    cout << ret << endl;;
    return 0;
}


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

/*int n;
  cin >> n;
  vector<int> h(n);*/

int main() {

  int a,b;
  int ans=0;
  cin >> a >> b;

  ans = a - b*2;

  if(ans <= 0){
    ans=0;
  }

  cout << ans << endl;
  
  return 0;
}

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

int32_t main(){
    int n, p, odd = 0, even = 0, a;
    cin >> n >> p;
    for(int i=0; i<n; i++){
        cin >> a;
        if( a % 2 ) odd++;
        else even++;
    }
    long long ans = 1LL << even;
    if( odd == 0 && p == 1 ) ans = 0;
    else if( odd != 0 ) ans <<= ( odd-1 );
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli                      int long long
#define ull                      unsigned long long
#define ld                       long double
#define pi                       acos(-1)
#define pb                       push_back
#define pbk                      pop_back
#define mp                       make_pair
#define all(v)                   v.begin(),v.end()
#define ff                       first
#define ss                       second
#define pii                      pair<int,int>
#define gcd(a,b)                 __gcd(a,b)
#define lcm(a,b)                (a/gcd(a,b))*b
#define READ                     freopen("in.txt","r",stdin);
#define WRITE                    freopen("outer.txt","w",stdout);
#define sortv(t)                  sort(t.begin(),t.end())
#define mem(a,b)                 memset(a,b,sizeof a)
#define t_c(t)                          for(int z=1;z<=t;z++)
#define p_c                             printf("Case %d: ",z)
#define LINE_PRINT_CASE          printf("Case %d:\n",z)
#define sf                       scanf
#define pf                       printf
#define dist(ax,ay,bx,by)        sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
#define MX                       100005
#define inf                      10000000000000000+7
#define M                        1000000002
#define MINI                     -1000000003
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move

//int kx[]={+2,+2,-2,-2,+1,+1,-1,-1};     //Knights move
//int ky[]={+1,-1,+1,-1,+2,-2,+2,-2};     //Knights move


//#define for(i,a,n)    for(int i=a;i<n;i++)
//it=myset.find(20);
//int a[8]= {0,0,-1,1,-1,1,-1,1};
//int b[8]= {-1,1,0,0,-1,1,1  ,-1};


int a[105],ans=0;
vector<int>v;

void func(int l,int r)
{
    int minn=M,p=0;

    int t=l;
   for(int i=l;i<=r;i++)
   {
       if(a[i]==0)p++;
       minn=min(a[i],minn);
   }ans+=minn;
   if(p==(r-l+1)) return;
   for(int i=l;i<=r;i++)
   {
       a[i]=a[i]-minn;
       if(a[i]==0)
       {
           if((i-1)>=t)
       {
           func(t,i-1);
       }t=i+1;
       }
   }
   if(t<=r) func(t,r);

   return ;
}

int main()
{
   int n,i,j;
   cin>>n;
   map<int,int>mm;

   for(i=0;i<n;i++){cin>>a[i];
   }
   func(0,n-1);
   cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3576
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;
const int MOD=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
void solve(){
  int n;
  int ans=INT_MAX;
  cin>>n;
  vector<int> v(n);
  int cnt=0;
  for(auto& it:v)cin>>it;
   int sum=0;
  for(auto it:v)sum+=it;
  for(auto it:v){
	    cnt+=it;
	    sum-=it;
	    ans=min(ans,abs(cnt-sum));
	 }
	 cout<<ans<<endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}


Measured memory_bytes: 256
<?php
$n=trim(fgets(STDIN));
$s=trim(fgets(STDIN));
$c=array_count_values(str_split($s));
if(isset($c["."])){
  $ans=min($n-$c["."],$c["."]);
}else{
  $ans=min($n-$c["#"],$c["#"]);
}
if($ans==0){
  echo 0;
}else{
  $key=array_keys(str_split($s),".");
  $i=1;
  foreach($key as $k=>$v){
    $ans=min($ans,$v+1+count($key)-$i*2);
    ++$i;
  }
  echo $ans;
}

Measured memory_bytes: 25080
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc098/tasks/arc098_b

//ポイント：
//「xor 和と加算和とが等しい」という条件下では
//「条件を満たす区間の部分区間も条件を満たす」という構造を作れる
//基本的に「xor 和 <= 加算和」
//加算和には繰り上がりがあるため

//参考：https://drken1215.hatenablog.com/entry/2018/06/26/125054

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200000];
 
LL ans = 0;

void solve(){
	//尺取り法
	LL add_sum = A[0];
	LL xor_sum = A[0];
	//今見てる範囲を[left,right)で表す
	int right = 1;
	for(int left=0;left<N;left++){
		while(right<=N-1 && ((xor_sum^A[right]) == add_sum+A[right])){
			xor_sum ^= A[right];
			add_sum += A[right];
			right++;
		}
		ans += (right-left);
		if(left==right){
			xor_sum ^= A[right];
			add_sum += A[right];
			right++;
		}
		else{
			xor_sum ^= A[left];
			add_sum -= A[left];
		}
	}
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <utility>
#include <tuple>
#include <map>
#include <ctype.h>
#include <set>
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    vector<pair<ll,ll>> J(N);
    for(int i=0;i<N;i++){
        ll a,b; cin >> a >> b;
        J[i]=make_pair(b,a);
    }
    sort(J.begin(),J.end());
    // for (int i=0;i<N;i++) {
    //     cout << J[i].first << " " << J[i].second << endl;
    // }
    ll tmp_time = 0;
    bool flag_gtd = true;
    for(int i=0;i<N;i++){
        tmp_time += J[i].second;
        // cout << tmp_time << endl;
        if (tmp_time>J[i].first) {
            flag_gtd = false;
            break;
        }
    }
    if (flag_gtd) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

const int N = 200005;

const int MOD = 1e9+7;

vector<int> G[N];

int n;

int ans[N], sz[N], t[N];

int fac[N], inv[N];

void init(){
    fac[0]=fac[1]=inv[0]=inv[1]=1;
    for(int i=2;i<=200000;++i)fac[i]=1ll*fac[i-1]*i%MOD;
    for(int i=2;i<=200000;++i)inv[i]=1ll*(MOD-MOD/i)*inv[MOD%i]%MOD;
    for(int i=2;i<=200000;++i)inv[i]=1ll*inv[i]*inv[i-1]%MOD;
}

inline int powmod(int x, int y){
    int res=1;
    while(y){
        if(y&1)
            res=1ll*res*x%MOD;
        x=1ll*x*x%MOD;
        y>>=1;
    }
    return res;
}


inline int C(int n, int m){
    if(m>n) return 0;
    else return 1ll*fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}

void dfs1(int u, int f){
    sz[u]=1;
    for(int i=0;i<G[u].size();++i){
        int v=G[u][i];
        if(v==f)continue;
        dfs1(v,u);
        sz[u]+=sz[v];
    }
}

int calc(int u, int f, int num){
    int res=1;
    for(int i=0;i<G[u].size();++i){
        int v=G[u][i];
        if(v==f)continue;
        res=1ll*res*C(num,sz[v])%MOD*calc(v,u,sz[v]-1)%MOD;
        num-=sz[v];
    }
    return t[u]=res;
}

void dfs2(int u, int f, int num){
    int res=ans[u];
    for(int i=0;i<G[u].size();++i){
        int v=G[u][i];
        if(v==f)continue;
        int tv=1ll*res*powmod(t[v],MOD-2)%MOD*powmod(C(n-1,sz[v]),MOD-2)%MOD;
        ans[v]=1ll*t[v]*C(n-1,n-sz[v])%MOD*tv%MOD;
        dfs2(v,u,sz[v]-1);
    }
}

int main(){
    init();
    scanf("%d",&n);
    for(int i=1;i<n;++i){
        int u,v;scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }

    dfs1(1,0);
    calc(1,0,n-1);
    ans[1]=t[1];
    dfs2(1,0,n-1);

    for(int i=1;i<=n;++i){
        printf("%d\n",ans[i]);
    }

    return 0;
}



Measured memory_bytes: 18912
def MAP(): return list(map(int,input().split()))
import collections

n = int(input())
a = [MAP() for _ in range(n)]
q = list(range(n))
c = collections.defaultdict(int)
t = [0]*n
r=0

while q:
    r += 1
    nq = []
    for i in q:
        j = a[i][t[i]]-1
        k = i
        if k<j:
            j,k = k,j
        c[(j,k)] += 1
        if c[(j,k)] == 2:
            t[j] += 1
            t[k] += 1
            if t[j] < n-1:
                nq.append(j)
            if t[k] < n-1:
                nq.append(k)
    q = nq

for tt in t:
    if tt!=n-1:
        print(-1)
        exit(0)
print(r)


Measured memory_bytes: 115324
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READV(X);
    READAR(A,N);
    ll ans=inf;
    FORI(i,0,N+1)
    {
        set<pll> Z;
        ll anx=X*i;
        FORI(j,0,i)
        {
            Z.insert({A[j%N],j%N});
        }
        FORI(j,0,N)
        {
            Z.insert({A[(i+j)%N],(j+i)%N});
            anx+=(*Z.begin()).fi;
            Z.erase(Z.find({A[j],j}));
        }
        ans=min(ans,anx);
    }
    cout<<ans<<endl;

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = i64(1e9) + 7;

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

  int N;
  cin >> N;

  int L[16];
  rep(i, N) cin >> L[i];

  sort(L, L + N, greater<int>());

  int sum = 0;
  for (int i = 1; i < N; ++i) sum += L[i];

  cout << (L[0] < sum ? "Yes" : "No") << "\n";

  return 0;
}

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

int size;
vector <int> seg;

void add(int i, int x){
    i += size - 1;
    seg[i] += x;
    while(i > 0){
        i = (i - 1) / 2;
        seg[i] = seg[i * 2 + 1] + seg[i * 2 + 2];
    }
}

void init(int n){
    size = 1;
    while(size <= n) size *= 2;
    seg = vector <int> (2 * size + 1, 0);
}

int sum(int a, int b, int v, int l, int r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return seg[v];
    return sum(a, b, v * 2 + 1, l, (l + r)  / 2) + sum(a, b, v * 2 + 2, (l + r) / 2, r);
}

int main(){
    
    int n, q;
    cin >> n >> q;
    init(n);
    while(q--){
        int c, a, b; cin >> c >> a >> b;
        if(!c) add(a, b);
        else cout << sum(a, b + 1, 0, 0, size) << endl;
    }
}

Measured memory_bytes: 3116