akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;

int main(void) {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if (A + B >= K) {
        cout << min(K, A) << endl;
    } else {
        cout << A - (K - (A+B)) << endl;
    }

    return 0;
}



Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n)cin >> h[i];
    sort(h.begin(),h.end());
    int ans = 1e9+3; 
    for(int i=0;i<=n-k;i++){
        ans = min(ans,h[i+k-1]-h[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<queue>
#include<algorithm>
#include<functional>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// bit
template<typename T, int NN>
struct bit {
  typedef std::function<T(T,T)> OP;
  T data_[NN], e_; // 0-base
  OP& op_;
  bit(OP& op, T e) : e_(e), op_(op) { std::fill_n(data_, NN, e_); }
  int lb(int i){ return i&-i; }
  T query(int i) { // 1-base
    T res = e_;
    while(i > 0) { res = op_(res, data_[i-1]); i -= lb(i); }
    return res;
  }
  void add(int i, T const& v) { // 1-base
    while(i <= NN) { data_[i-1] = op_(data_[i-1], v); i += lb(i); }
  }
};

using mbit = bit<int, (1<<18)>;
mbit::OP op_mi = [](int x, int y){ return std::min(x, y); };
mbit::OP op_ma = [](int x, int y){ return std::max(x, y); };

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> a(N);
  std::vector<int64_t> num(N+1);
  for(int i = 0; i < N; ++i) std::cin >> a[i];
  // left
  mbit bma(op_ma, -1);
  for(int i = 0; i < N; ++i) {
    int v = a[i];
    num[v] = i - bma.query(v-1);
    bma.add(v, i);
  }
  // right
  mbit bmi(op_mi, N);
  for(int i = N-1; i >= 0; --i) {
    int v = a[i];
    num[v] *= bmi.query(v-1) - i;
    bmi.add(v, i);
  }
  int64_t ans = 0;
  for(int i = 1; i <= N; ++i) ans += num[i]*i;
  fin(ans);
  return 0;
}


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

int main(){
  int n;
  cin >> n;

  vector<pair<long,long>> vec;
  for (int i = 0; i < n; i++)
  {
    long long x,l;
    cin >> x >> l;
    vec.emplace_back(x,l);
  }  
  sort(vec.begin(),vec.end());

  long long minr = vec[0].first + vec[0].second;
  int ans = 0;
  for (int i = 1; i < n; i++)
  {
    long long x,l;
    x = vec[i].first;
    l = vec[i].second;
    if(x-l < minr){
      minr = min(x+l,minr);
      ans++;
    }
    else{
      minr = x+l;
    }
  }
  cout << n-ans << endl;
}

Measured memory_bytes: 2420
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            int num = cin.ReadInt;
            int[] d = cin.ReadIntArray(num);
            for(int i = 0; i < num; i++)
            {
                if(d[i] % 2 == 0)
                {
                    if(d[i] % 3 != 0 && d[i] % 5 != 0)
                    {
                        Console.WriteLine("DENIED");
                        //Console.ReadLine();
                        return;
                    }
                }
            }
            Console.WriteLine("APPROVED");
            //Console.ReadLine();
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11220
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            int Q = in.nextInt();
            int[] A = new int[N];
            Arrays.fill(A, K - Q);
            for (int i = 0; i < Q; i++) {
                int index = in.nextInt();
                A[index - 1]++;
            }
            StringBuilder sb = new StringBuilder(4 * N);
            for (int i = 0; i < N; i++) {
                sb.append(A[i] > 0 ? "Yes" : "No").append('\n');
            }
            out.println(sb.toString());
        }

    }
}



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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N,K; cin >> N >> K;
    VI A(N); REP(i,N) cin >> A[i];

    cout << (N-1+K-2)/(K-1) << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
// vector<vector< vector<double> > >  memo;
// vector<vector< vector<bool> > >  vis;
double memo[301][301][301];
bool vis[301][301][301];
double expected(int i, int j, int k, double n) {
	if( i < 0 || j < 0 || k < 0) return 0.0;
	if(i == 0 && j == 0 && k == 0) {
		return 0.0;
	}
	if(vis[i][j][k]) return memo[i][j][k];
	double pi = (double)(i+j+k) / n;
	double ans = 1.0/pi, T = double(i+j+k);
	ans += (double(i)/T) * expected(i-1, j+1, k, n);
	ans += (double(j)/T) * expected(i,j-1,k+1, n);
	ans += (double(k)/T) * expected(i, j, k-1, n);
	
 	memo[i][j][k] = ans;
 	vis[i][j][k] = true;
 	
 	return ans;
}
// void init(vector<int> &ct) {
// 	memo.resize(ct[3]+1);
// 	for(int j = 0; j < (int)memo.size(); j++)  {
// 		memo[j].resize(ct[2]+1);
// 		for(int k = 0; k < (int)memo[j].size(); k++)  {
// 			memo[j][k].resize(ct[1]+1);
// 		}
// 	}
// 	vis.resize(ct[3]+1);
// 	for(int j = 0; j < (int)vis.size(); j++)  {
// 		vis[j].resize(ct[2]+1);
// 		for(int k = 0; k < (int)vis[j].size(); k++)  {
// 			vis[j][k].resize(ct[1]+1);
// 		}
// 	}
// }
int main() {
	int n;
	cin>>n;
	vector<int> ct (4,0);
	for(int i=0;i<n;i++) {
		int  v;
		cin>>v;
		ct[v]++;
	}
	// init(ct);
	cout<<fixed<<setprecision(15)<<expected(ct[3],ct[2],ct[1], (double)n)<<endl;
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] a = new int[3 * N];
		for(int i = 0;i < 3 * N;i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		Arrays.sort(a);
		long sum = 0L;
		for(int i = N;i < 3*N;i += 2) {
			sum += (long)a[i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 65708
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define show(x) cout<<#x<<" "<<x<<" ";
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
const int MSIZE = 3e3+5;
const int MOD = 1e9+7;

double dp[MSIZE][MSIZE];
double pr[MSIZE];


int main(){
    FIO
    int n; cin>>n;
    f(i,1,n)    cin>>pr[i];

    memset(dp,0,sizeof(dp));

    dp[0][0] =  1;
    f(i,1,n)    dp[i][0]=dp[i-1][0]*(1-pr[i]);
    
    f(i,1,n) f(j,1,n) 
        dp[i][j] = pr[i]*dp[i-1][j-1] + (1-pr[i])*dp[i-1][j];
    
    double ans = 0;
    f(i,(n+1)/2,n)  ans+=dp[n][i];
    cout<<fixed<<setprecision(10)<<ans<<endl;
    
    return 0;

}
    


Measured memory_bytes: 70784
/*
abc103_a
*/
#include<algorithm>
#include<iostream>
#include<vector>
#include<fstream>
using namespace std;

int main() {
	vector<int> a;
	int t;
	while (cin >> t) {
		a.push_back(t);
	}

	sort(a.begin(), a.end());
	int ans = 0;
	for (int j = 1; j < a.size(); j++) {
		ans += abs(a[j] - a[j - 1]);
	}

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

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
static const lint MOD9 = (lint)1e9+7;
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};

// 整数の桁数を返す ( log(N) )
template <class Integer> Integer GetDigit(Integer n) {
    Integer d = 0;
    while (n) {
        n /= 10;
        d++;
    }
    return d;
}

// 素数かどうかを返す ( O(sqrt(N)) )
template <class Integer>
constexpr bool IsPrime(const Integer n) noexcept {
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
    for (Integer i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}


int main()
{
    int K; cin >> K;

    int sum = 0;
    reps (a, K)
    {
        reps (b, K)
        {
            reps (c, K)
            {
                sum += gcd(gcd(a, b), c);
            }
        }
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3524
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>

using namespace std;
using LL = long long;

constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;

int main() {
	int n;
	cin >> n;
	vector<int> A;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		A.emplace_back(a);
	}
	sort(A.begin(), A.end(), greater<int>());
	for (int i = 1; i <= n; i++) {
		if (A[i - 1] < i) {
			cout << i - 1 << endl;
			return 0;
		}
	}
	cout << n << endl;
}

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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001ll;

int N,M;
int dp[1001][3001];

int v[3000],h[3000];
int t[1000],s[1000];

int accv[3001];
signed main(){
    cin>>N>>M;
    rep(i,N)cin>>v[i]>>h[i],accv[i+1]=accv[i]+v[i];
    rep(i,M)cin>>t[i]>>s[i];

    fill_n(*dp,1001*3001,-INF);
    dp[0][0]=0;

    for(int i=0;i<M;i++){
        for(int j=0;j<=N;j++){
            if(accv[j]>t[i])break;
            if(j){
                chmax(dp[i+1][j],dp[i][j-1]+h[j-1]);
            }
            if(j>1)chmax(dp[i+1][j],dp[i+1][j-1]+h[j-1]+abs(h[j-2]-h[j-1]));
        }
        for(int j=0;j<=N;j++)chmax(dp[i+1][j],dp[i][j]);
        for(int j=0;j<=N;j++){
            if(dp[i+1][j]<s[i])dp[i+1][j]=-INF;
        }

    }

    for(int i=0;i<=N;i++){
        if(dp[M][i]!=-INF){
            cout<<t[M-1]-accv[i]<<endl;
            return 0;
        }
    }

    cout<<-1<<endl;
    return 0;
}

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

#define task "F"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 3001, mod = 998244353;
int n, a[N], s, dp[N];
int power(int x, int y)
{
    int res = 1;
    while (y)
    {
        if (y & 1) res = res * 1ll * x % mod;
        y >>= 1;
        x = x * 1ll * x % mod;
    }
    return res;
}
int main()
{
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#else
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#endif
    cin >> n >> s;
    rep(i, 1, n) cin >> a[i];
    dp[0] = power(2, n);
    rep(i, 1, n) Rep(j, s, 0) if (j - a[i] >= 0)
    {
        dp[j] = (dp[j] + dp[j - a[i]] * 1ll * power(2, mod - 2) % mod) % mod;
    }
    cout << dp[s];
    return 0;
}


Measured memory_bytes: 3536
M = 10 ** 9 + 7
H, W, A, B = gets.split.map{|i|i.to_i}
def inv(x)
    result = 1
    m = M - 2
    while m > 0
        if m & 1 == 1
            result = result * x % M
        end
        x = x * x % M
        m >>= 1
    end
    result
end

def c(a, b)
    if b > a / 2
        b = a - b
    end
    result = 1
    a.downto(a - b + 1){|r|result = result * r % M}
    fact = (1 .. b).inject(1){|r, i|r * i % M}
    result = result * inv(fact) % M
end

x = B
y = H - 1 - A
n = 0
p1 = c(x + y, x)
p2 = c(W - 1 - x + H - 1 - y, W - 1 - x)
loop{
    n += p1 * p2 % M
    x += 1
    y -= 1
    break if x >= W || y < 0
    p1 = p1 * (x + y - (x - 1)) % M
    p1 = p1 * inv(x) % M
    #warn "p1:#{p1}"
    p2 = p2 * (W - 1 - (x - 1)) % M
    p2 = p2 * inv(H - 1 - (y + 1) + 1) % M
    #warn "p2:#{p2}"
}
puts n % M


Measured memory_bytes: 3836
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

bool cal(int n) {
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		if ( (n % i) == 0 ) {
			cnt++;
		}
	}
	if (cnt == 8) {
		return true;
	}
	return false;
}

void solve() {
	string S;
	LL K;
	cin >> S >> K;
	int ans = -1;
	int len = S.size();
	for (int i = 0; i < len; ++i) {
		if (S[i] != '1') {
			ans = S[i] - '0';
			break;
		}
		else {//S[i] == "1";
			if (K == i + 1) {
				ans = S[i] - '0';
				break;
			}
		}
	}
	
	cout << ans << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    int sum = 0;
    for(int i = 0; i < N; i++) sum += a[i];
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(abs(a[i] * N - sum) < abs(a[ans] * N - sum)) ans = i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int
main()
{
	int i, j;
	for( i = 1; i < 10; ++i )
	{
		for( j = 1; j < 10; ++j )
		{
			printf( "%dx%d=%d\n", i, j, i * j );
		}
	}

	return 0;
}

Measured memory_bytes: 524
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> v(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
	}
	vector<int> states;
	vector<int> vis(n + 1);
	vis[1] = 1;
	int last = 0;
	int cur = v[1];
	while (!vis[cur]) {
		vis[cur] = 1;
		states.pb(cur);
		cur = v[cur];
	}
	last = cur;
	if (last == 1) {
		states.pb(1);
	}
	int cycle_length = states.size();
	if (k < cycle_length) {
		cout << states[k - 1] << endl;
		return;
	}
	if (last == 1) {
		cout << states[(k - 1) % cycle_length] << endl;
		return;
	}
	int start ;
	for (int i = 0; i < cycle_length; i++) {
		if (states[i] == last) {
			start = i + 1;
			break;
		}
	}
	if (k < cycle_length) {
		cout << states[k - 1] << endl;
		return;
	}
	k -= cycle_length;
	int left = cycle_length - start + 1;
	cout << states[start - 1 + (k - 1) % left] << endl;
}
int32_t main() {
	BOLT;
	solve();
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

template<typename T,typename U>
void Printarray2(T f,U n){
  for(int i=0;i<n;i++) cout<<f[i]<<endl;
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;cin>>n;
  bool flag=false;
  rep2(i,1,10){
    rep2(j,1,10){
      //cout<<i<<j<<endl;
      if(i*j==n){
        flag=true;
        goto repend;
      }
    }
  }
  repend:
  flag2func(flag);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ul>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string str;  cin>>str;
    string o ;
    o+=str[0];  o+=str[1];
    string c;
    c+=str[2];  c+= str[3];
    int x1 =  stoi(o);
    int x2 = stoi(c);
    if(x1 >=1 && x1 <= 12 && x2 >=1 && x2<=12)
        cout << "AMBIGUOUS";
    else if(x1>=1 && x1<=12)
        cout <<"MMYY";
    else if(x2 >=1 && x2<=12)
        cout << "YYMM";
    else 
        cout << "NA";


       
    return 0;
}
    


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

int main()
{
    int a[5],k;
    for(int i=0;i<5;i++)
        scanf("%d",&a[i]);
    scanf("%d",&k);
    int zj=1;
    for(int i=0;i<5;i++)
        for(int j=0;j<5;j++)
    {
        if((a[i]-a[j])>k)
        {
            zj=0;
            break;
        }
    }
    if(zj==0)
        printf(":(");
    else
        printf("Yay!");
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   // Your code here!
   int n,i,j,m,q,r;
   int a[10];
   int b[10];
   int c[10];
   cin >> n;
   for(m=0;m<n;m++){
       for(i=0;i<10;i++){
            cin >> a[i];
        }
        for(i=0;i<10;i++){
            b[i]=0; 
           }
        for(i=0;i<10;i++){
            c[i]=0; 
        }
   
        q=0;
        r=0;
        for(j=0;j<10;j++){
            if(q==0 || a[j]>b[q-1]){
                b[q]=a[j];
                q=q+1;
            }else if(r==0 || a[j]>c[r-1]){
              c[r]=a[j];  
              r=r+1;
            }else{
                cout << "NO\n";
                break;
            }
            
          }
          if(j==10){
          cout << "YES\n";
          }
        for(i=0;i<10;i++){
            a[i]=0; 
   }
   
   }
   


}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

ll dp[1010][1010];

const ll mod = 1e9+7;
int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> field(H);
	rep(i, H)cin>>field[i];
	dp[1][1] = 1;
	
	for(int i = 1; i <= H;i++){
		for(int j = 1; j <= W;j++){
			if(i == 1 && j == 1) continue;
			if(field[i-1][j-1] == '#'){
				dp[i][j] = 0;
				continue;
			}
			dp[i][j] = dp[i-1][j] + dp[i][j-1];
			dp[i][j] %= mod;
		}
	}
	cout << dp[H][W] << endl;
}


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    char X, Y;
    cin >> X >> Y;
    if (X < Y) cout << "<" << endl;
    else if (X == Y) cout << "=" << endl;
    else cout << ">" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
const int MAXN=2e5+8;
int n,t,a[MAXN]; 
long long ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	(n%2)==1?t=a[(n/2)+1]:t=a[n/2];
	for(int i=1;i<=n;i++)
		ans+=abs(a[i]-t);	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::string s;
	std::cin >> s;
	std::vector<int> p(1<<n);
	rep(i,1<<n) std::cin >> p[i];
	auto f = [&] (int a, int b) -> int {
		if(a>b) std::swap(a,b);
		if(s[b-a-1]=='0') return a;
		return b;
	};
	std::vector<std::vector<int> > dp(n+1,std::vector<int>(1<<n));
	dp[0]=p;
	rep(i,n) {
		int dx=1<<i;
		rep(j,1<<n) {
			dp[i+1][j]=f(dp[i][j],dp[i][(j+dx)%(1<<n)]);
		}
	}
	debug(dp);
	rep(i,1<<n) print(dp[n][i]);

	return 0;
}



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

int main()
{
    int N, L;
    cin >> N >> L;
    vector<int> A(N);
    for(int i = 0; i < N; i++)
        cin >> A[i];
    
    bool flag=false;
    int first = -1;
    for(int i = 0; i < N-1; i++)
    {
        int l = A[i] + A[i+1];
        if (L <= l) 
        {
            flag = true;
            first = i;
            break;
        }
    }
    
    if (flag)
        cout << "Possible" << endl;
    else
    {
        cout << "Impossible" << endl;
        return 0;
    }
    
    int ans[N-1];
    for(int i = first; i < N-1; i++)
        ans[i - first] = i;
    for (int i = 0; i < first; i++)
        ans[N - 2 - first + i + 1] = first - 1 - i;
    
    for(int i = 0; i < N-1; i++)
        cout << ans[N-2-i] + 1 << endl;    

    return 0;
}

Measured memory_bytes: 1536
#include <iostream>

int C[6];

int main(){
    for(int i=0;i<6;i++){
        std::cin >> C[i];
    }

    int all = C[0] + 5 * C[1] + 10 * C[2] + 50 * C[3] + 100 * C[4] + 500 * C[5];
    if(all >= 1000){
        std::cout << 1 << std::endl;
    }else{
        std::cout << 0 << std::endl;
    }
}

Measured memory_bytes: 1160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] a = in.nextIntArray(N);

            int count = 0;
            int cur = 1;
            for (int i = 0; i < N; i++) {
                if (a[i] == cur) {
                    cur++;
                } else {
                    count++;
                }
            }
            out.println(cur == 1 ? -1 : count);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

    }
}



Measured memory_bytes: 46144
#include <iostream>
#include <queue>
int main(){
  using namespace std;
  int N,i,sum,max,l;
  priority_queue<int> pque;
  cin>>N;
  for(i=0;i<N;i++){
    cin >> l;
    pque.push(l);
  }
  
  max=pque.top();
  pque.pop();
  
  while(!pque.empty()){
    sum+=pque.top();
    pque.pop();
  }
  
  if(sum>max)cout << "Yes" << endl;
    else cout << "No" << endl; 
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> pii;
    rep(i,n){
        int x;
        cin>>x;
        pii.push_back({x,i});
    }
    sort(pii.begin(),pii.end());
    set<int> si1;
    for(int i=0;i<=(n-2)/2;i++){
        si1.insert(pii[i].second);
    }
    int left=pii[n/2].first, right=pii[n/2-1].first;
    for(int i=0;i<n;i++){
        if(si1.find(i)!=si1.end()) cout<<left<<endl;
        else cout<<right<<endl;
    }
    return 0;
}

Measured memory_bytes: 8432
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, m;
	cin >> n >> m;
	long long int ans = 1;
	if(abs(n - m) > 1) ans = 0;
	for(int i = 2; i <= n; i++){
		ans =(ans * i) % mod;
	}
	for(int i = 2; i <= m; i++){
		ans = (ans * i) % mod;
	}
	if(n == m) ans = (2 * ans) % mod;
	cout << ans << endl;
}

Measured memory_bytes: 384
use proconio::input;

fn main() {
    input! { x: usize }
    let n_max = x / 100;
    let mut exists = false;
    'outer: for i in 0..=n_max {
        for j in 0..=n_max - i {
            for k in 0..=n_max - i - j {
                for l in 0..=n_max - i - j - k {
                    for m in 0..=n_max - i - j - k - l {
                        if (x - (i * 105 + j * 104 + k * 103 + l * 102 + m * 101)) % 100 == 0 {
                            exists = true;
                            break 'outer;
                        }
                    }
                }
            }
        }
    }
    println!("{}", if exists { 1 } else { 0 });
}


Measured memory_bytes: 2120
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n;
    cin>>n;
    vector<in> a(n+1ll);
        rep(i,n+1) cin>>a.at(i);
    vector<P> maxi(n+1,P(0ll,0ll));
    bool f=true;

    if(n==0ll){
        if(a[0]==1ll) cout<<1<<endl;
        else cout<<-1<<endl;
        return 0;
    }

    if(a[0]>=1ll) f=0;

    rep(i,n+1){
        if(i==0){
            maxi[i]=P(0ll,1ll);
            continue;
        }
        maxi[i].first=a[i];
        if(maxi[i-1].second*2ll>1e18) maxi[i].second=1e18;
        else maxi[i].second=maxi[i-1].second*2ll-maxi[i].first;
        if(i==n && maxi[i].second<0) f=0;
        if(i<n && maxi[i].second<=0) f=0;
    }
    
    if(!f){
        cout<<-1<<endl;
        return 0;
    }

    in ans=0ll;
    vector<P> make(n+1,P(0ll,0ll));
    for(in i=n;i>=0;i--){
        if(i==n){
            make[i]=P(maxi[i].first,0);
            continue;
        }
        make[i].first=a[i];
        make[i].second=min(maxi[i].second,make[i+1].first+make[i+1].second);
    }
    rep(i,n+1){
        ans +=make[i].first;
        ans +=make[i].second;
    }
    cout<<ans<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 7144
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
void solve() {
    ll k, a, b;
    cin >> k >> a >> b;
    if (b - a > 2) {
        if (a - 1 > k) {
            cout << 1 + k << "\n";
        } else {
            cout << a + (k - a + 1) / 2 * (b - a) + (k - a + 1) % 2 << "\n";
        }
    } else {
        cout << 1 + k << "\n";
    }
    return;
}



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

int main()
{
    int a,b,c;
    while(~scanf("%d %d %d",&a,&b,&c))
    {
        if(c>=a&&c<=b)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for(int i=0; i < m; i++){
        cin >> a[i];
    }
    for(int i=0; i < m; i++){
        n -= a[i];
    }
    if(n < 0) n = -1;
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3640
n = int(input())
a = [int(input()) for _ in range(n)]
pairs = 0
for i in range(n-1):
  pairs += a[i]//2
  a[i] %= 2
  if a[i]:
    syu = min(a[i],a[i+1])
    a[i+1] -= syu
    pairs += syu
pairs += a[-1]//2
print(pairs)  

Measured memory_bytes: 7072
def main():
	n  = int(input())
	arr = []
	for _ in range(n):
		arr.append(int(input()))
	arr2 = arr.copy()
	arr2.sort()
	mx = arr2[-1]
	mx2 = arr2[-2]
	for i in range(len(arr)):
		if arr[i]==mx:
			print(mx2)
		else:
			print(mx)

main()


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

int main(){
  int n,a[1000],f[1000000]={};
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i],f[a[i]]=1;
  for(int i=0;i<n-1;i++)f[a[i]*10+a[i+1]]=1;
  for(int i=0;i<n-2;i++)f[a[i]*100+a[i+1]*10+a[i+2]]=1;
   for(int i=0;i<1000;i++) if(f[i]==0){ cout<<i<<endl;break;}
      
  return 0;
}

    

Measured memory_bytes: 5080
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<=b&&b<=c){
		printf("%d %d %d\n",a,b,c);
	}else if(a<=c&&c<=b){
		printf("%d %d %d\n",a,c,b);
	}else if(b<=a&&a<=c){
		printf("%d %d %d\n",b,a,c);
	}else if(b<=c&&c<=a){
		printf("%d %d %d\n",b,c,a);
	}else if(c<=a&&a<=b){
		printf("%d %d %d\n",c,a,b);
	}else if(c<=b&&b<=a){
		printf("%d %d %d\n",c,b,a);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.0000000001;

int n;
vector<pair<pair<int, int>, int>> ab;
int *c;

void clr(int node, int from, int ecl) {
    auto l = lower_bound(ab.begin(), ab.end(), make_pair(make_pair(node, 0), 0));
    auto r = lower_bound(ab.begin(), ab.end(), make_pair(make_pair(node + 1, 0), 0));
    int s = 1;
    for (auto i = l; i != r; i++) {
        if (i->first.second == from) continue;
        if (s == ecl) s++;
        clr(i->first.second, node, s);
        c[i->second] = s;
        s++;
    }
}

int main() {
    cin >> n;
    c = new int[n-1];
    memset(c, 0, sizeof(int) * (n-1));
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        ab.emplace_back(make_pair(a, b), i);
        ab.emplace_back(make_pair(b, a), i);
    }
    sort(ab.begin(), ab.end());
    clr(1, 0, 0);
    int k = 0;
    for (int i = 0; i < n-1; i++) k = max(k, c[i]);
    cout << k << endl;
    for (int i = 0; i < n-1; i++) cout << c[i] << endl;
}

Measured memory_bytes: 7540
def splitter(n, a):
    count = 1
    mode = 'none'
    for i in range(1, n):
        if mode == 'incr':
            if a[-i-1] > a[-i]:
                # print('{} | {}'.format(a[-i-1], a[-i:]))
                count += 1
                # print('count:', count)
                mode = 'none'
            else:
                continue
        elif mode == 'decr':
            if a[-i-1] < a[-i]:
                # print('{} | {}'.format(a[-i-1], a[-i:]))
                count += 1
                # print('count:', count)
                mode = 'none'
        else:
            if a[-i-1] == a[-i]:
                # print('{} = {}'.format(a[-i-1], a[-i:]))
                continue
            elif a[-i-1] > a[-i]:
                # print('{} > {}'.format(a[-i-1], a[-i:]))
                mode = 'decr'
            elif a[-i-1] < a[-i]:
                # print('{} > {}'.format(a[-i-1], a[-i:]))
                mode = 'incr'
    return count


def main():
    n = int(input())
    a = list(map(int, input().split()))

    print(splitter(n, a))


main()


Measured memory_bytes: 14436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
bool used[100001];
int main() {
    init();
    ll N;
    cin >> N;

    ll cnt = 0;
    rep(i,N){
        ll a;
        cin >> a;
        if (used[a]) cnt++;
        else
            used[a] = true;
    }

    if (cnt & 1) cnt++;

    cout << N - cnt << endl;

}

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

#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define FOR(i,a,b) for(long long i=(a);i<=(b);i++)

int main() {
  string S;
  cin >> S;
  vector<char> s;
  int ans = 0;
  REP(i, S.size()) {
    if(s.empty()) {
      s.push_back(S[i]);
    } else {
      if(s[s.size()-1] == S[i]) {
        s.push_back(S[i]);
      } else {
        ans += 2;
        s.pop_back();
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

void readIds(bool (&is_grouped)[100], int counter);

int main()
{
    int n;
    int x;
    int y;
    int z;
    bool is_grouped_x[100] = {};
    bool is_grouped_y[100] = {};
    bool is_grouped_z[100] = {};
    int ans = 0;

    /* Read */
    cin >> n;
    
    cin >> x;
    readIds(is_grouped_x, x);

    cin >> y;
    readIds(is_grouped_y, y);

    cin >> z;
    readIds(is_grouped_z, z); 

    /* count up */
    for(int i = 0; i < n; i++)
    {
        if((!is_grouped_x[i] && is_grouped_z[i]) || (is_grouped_y[i] && is_grouped_z[i]))
        {
            ans++;    
        }
    }

    /* display */
    cout << ans << endl;

    return 0;
}

void readIds(bool (&is_grouped)[100], int counter)
{
    for(int i = 0; i < counter; i++)
    {
        int id;
        cin >> id;
        is_grouped[id - 1] = true;
    }
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

void solve() {
  int n;
  cin >> n;
  cout << (n/2) * ((n+1)/2) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


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

if ('##' in S[a:c-1]) or ('##' in S[b:d-1]): print('No')
else:
    if d < c:
        if ('...' in S[b-2:d+1]): print('Yes')
        else: print('No')
    else: print('Yes')

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  int N;
  cin >> N;
  vector<int> P(N);
  vector<int> Q(N);
  for(int i=0; i<N; i++) cin >> P.at(i);
  for(int i=0; i<N; i++) cin >> Q.at(i);
  vector<int> R(N);
  iota(R.begin(), R.end(), 1);
  int count = 0;
  int P_count, Q_count;
  do {
    count++;
    if(P==R) P_count = count;
    if(Q==R) Q_count = count;
  } while (next_permutation(R.begin(), R.end()));
  cout << abs(P_count-Q_count) << endl;
}


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

using namespace std;
void Main(){
cin.sync_with_stdio(0);
cin.tie(0);
}

int main()
{
Main();

int s , w ; cin >> s >> w ;

if(w >= s)
    cout << "unsafe" ;

    else
        cout << "safe" ;


return 0;
}


Measured memory_bytes: 3640