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

using namespace std;
#define ll long long
const int N = 15 + 5;
int n ,m, x;
int skill[N], a[N][N], c[N], ans = 1e9;
void solve(int idx, int cost) {
    if (idx == n) {
        bool bo = 1;
        for(int i = 0 ; i < m ; i++) if (skill[i] < x) bo = 0;
        if (bo) ans = min(ans, cost);
        return;
    }
    for(int i = 0 ; i < m ; i++) {
        skill[i] += a[idx][i];
    }
    solve(idx + 1, cost + c[idx]);
    for(int i = 0 ; i < m ; i++) {
        skill[i] -= a[idx][i];
    }
    solve(idx + 1, cost);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> x;
    for(int i = 0 ; i < n ; i++) {
        cin >> c[i];
        for(int j = 0 ; j < m ; j++) {
            cin >> a[i][j];
        }
    }
    solve(0, 0);
    if (ans == 1e9) cout << -1;
    else cout << ans;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << ":\t" << x << endl
#define _ << " " <<

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll N = 300 + 3;
const ll INF = 1e18;

ll n, a[3 + 1];
ld dp[N][N][N];

int main() {
//	mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//	freopen("in", "r", stdin)
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(14);
	
	cin >> n;
	for (ll i = 1; i <= n; ++i) {
		ll x; cin >> x;
		++a[x];
	}
	
	for (ll k = 0; k <= n; ++k) {
		for (ll j = 0; j <= n; ++j) {
			for (ll i = 0; i <= n; ++i) {
				if (i == 0 && j == 0 && k == 0) continue;
				ll sum = i + j + k;
				ld ev = n / ld(sum);
				if (i > 0) dp[i][j][k] += (dp[i-1][j][k] + ev) * i / sum;
				if (j > 0) dp[i][j][k] += (dp[i+1][j-1][k] + ev) * j / sum;
				if (k > 0) dp[i][j][k] += (dp[i][j+1][k-1] + ev) * k / sum;
			}
		}
	}
	cout << dp[a[1]][a[2]][a[3]] << "\n";
	
	return 0;
}


Measured memory_bytes: 432384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

const int MAX = 4e5;
ll fac[MAX], finv[MAX], inv[MAX];

//前処理
void COMinit (){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1]*i%mod;
        inv[i] = mod-inv[mod%i]*(mod/i)%mod;
        finv[i] = finv[i-1]*inv[i]%mod;
    }
}
//二項係数
ll COM(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(){
    int n,k;
    cin >> n >> k;
    COMinit();
    ll ans = 0;
    for(int i = 0; i <= min(n-1,k); i++){
        ans += COM(n,i)*COM(n-1,i);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        string s = ins();
        ll ans = 0;
        for (long long i = 2; i < s.size(); i += 2) {
            string tmp = s.substr(0, i);
            if (tmp.substr(0, tmp.size() / 2) == tmp.substr(tmp.size() / 2, tmp.size() / 2)) {
                ans = tmp.size();
            }
        }
        cout << ans << endl;
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

char c[]={'z','.','?','!',' '};
string s;

int main(){
	while(getline(cin,s)){
		int l=s.size();
		if(l%2){cout<<"NA"<<endl;continue;}
		int cur=0,f=0;
		string ans="";
		while(cur<l){
			int a=s[cur++]-'0',b=s[cur++]-'0';
			if(a<1||a>6||b<1||b>5){cout<<"NA"<<endl;f=1;break;}
			if(a<6)ans+=(char)('a'+(a-1)*5+b-1);
			if(a==6)ans+=c[b-1];
		}
		if(!f)cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
/*  ex4_2
    supercomputerjoi    */

#include <stdio.h>
#include <math.h>

int main(void){

    int shortHand, longHand, hour, minute;
    double theta;  // angle between long hand and short hand
    double ans;    // answer

    // input A B H M
    scanf("%d %d %d %d", &shortHand, &longHand, &hour, &minute);

    // calculate angle
    theta = 2 * M_PI * (hour / 12.0 + minute / 720.0 - minute / 60.0);

    // calculate answer by cosine formula
    ans = sqrt(pow(shortHand, 2) + pow(longHand, 2) - 2 * shortHand * longHand * cos(theta));

    // print answer
    printf("%.9f\n", ans);

    return 0;
}

Measured memory_bytes: 2520
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (1000000000000000000ll)
#define mod (1000000007)

int n;
int a[111];

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	cin>>n;
	int cnt=0;
	FOR(i,0,n){
		cin>>a[i];
		if(a[i]!=i+1){
			cnt++;
		}
	}
	if(cnt>2){
		cout<<"NO\n";
	}
	else cout<<"YES\n";
	
	
	
	return 0;
}


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

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long a, b, c, d; cin >> a >> b >> c >> d;
	cout << max({a * c, a * d, b * c, b * d}) << '\n';
    return 0;
}

Measured memory_bytes: 3648
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Collections;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ir = new Resolver(new ConsoleReader());
            Console.WriteLine(ir.Resolve());
        }
    }

    public class Resolver
    {
        IInputReader InputReader { get; }
        public List<string> Messages { get; set; } = new List<string>();

        int[] rule;
        int[] input;

        public void ParseLines()
        {
            rule = InputReader.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            input = InputReader.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public string Resolve()
        {
            var arranged = input.ToList().OrderBy(x => x).ToList();
            var diff = arranged.Select((x, i) =>
            {
                if (i == 0) return 0;
                return arranged[i] - arranged[i - 1];
            }).ToList();

          if (rule[1] <= rule[0]) return "0";
            var diff_ = diff.OrderBy(x => -x).ToList().GetRange(rule[0] - 1, rule[1] - rule[0]).ToList();
            
            return diff_.Sum().ToString();
            //return diff_.Select(x => x.ToString()).Aggregate((a, b) => a + "," + b);
        }


        public Resolver(IInputReader inputReader)
        {
            InputReader = inputReader;
            ParseLines();
        }

    }

    public interface IInputReader
    {
        string ReadLine();
    }

    class ConsoleReader : IInputReader
    {
        string IInputReader.ReadLine()
        {
            return Console.ReadLine();
        }
    }
}

Measured memory_bytes: 25952
a, e, b= map(str,input().split())
a = int(a)
b = int(b)
while e !="?":
  if e=="+":
    print(str(a + b))
  if e=="-":
    print(str(a - b))
  if e=="*":
    print(str(a * b))
  if e=="/":
    print(str(a // b))
  a , e, b = map(str,input().split())
  a= int(a)
  b= int(b)



Measured memory_bytes: 5596
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define Rep(i, s, n) for (int i = (int)s; i < (int)n; i++)

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

    int n, x;
    cin >> n >> x;
    int l[n];
    rep(i, n) cin >> l[i];

    int res = 1, len = 0;
    rep(i, n) {
        len += l[i];
        if (len <= x) res++;
    }
    cout << res << endl;
}

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

int main() {
  int N, T;
  cin >> N >> T;

  vector<int> t(N);
  rep(i, N) cin >> t[i];

  int ans = T;
  rep(i, N) {
    int d = t[i] - t[i - 1];
    if (d < T)
      ans += d;
    else
      ans += T;
  }

  cout << ans << endl;
}

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

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

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

signed main() {
		int n;
		cin >> n;
		map<string,int> cnt;
		for(int i=0;i<n;i++){
				string tmp;
				cin >> tmp;
				sort(tmp.begin(),tmp.end());
				cnt[tmp]++;
		}
		int ans = 0;
		for(auto& A : cnt){
				ans += A.second * (A.second - 1) / 2;
		}
		cout << ans;
}



Measured memory_bytes: 11264
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

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

const int N = 55;

int n, p[N], hm;

int main() {
  init_ios();
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
    if (p[i] != i)
      ++hm;
  }
  if (hm <= 2)
    cout<<"YES\n";
  else
    cout<<"NO\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <stack>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <set>
#include <functional>
#include <cstring>

using namespace std;

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

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair

#define F first
#define S second

#define popcnt __builtin_popcountll

#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
#define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i )
#define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }

int main()
{
	ll n, x, d; cin >> n >> x >> d;

	if ( d == 0 )
	{
		if ( x == 0 ) cout << 1 << endl;
		else cout << n + 1 << endl;
		return ( 0 );
	}

	if ( d < 0 )
	{
		x += ( n - 1 ) * d;
		d = -d;
	}

	map<ll, vector<Pll>> me;
	rep( k, n + 1 )
	{
		ll l = k * x + ( k * ( k - 1 ) / 2 ) * d;
		ll r = k * x + ( n * k - k * ( k + 1 ) / 2 ) * d;
		ll key = ( k * x ) % d;
		if ( key < 0 ) key += d;
		if ( l > r ) swap( l, r );
		me[key].eb( mp( l, 1 ) ); me[key].eb( mp( r, 2 ) );
	}

	ll ans = 0;
	arep( it, me )
	{
		auto &v = it.S;
		sort( ALL( v ) );

		ll cnt = 0, start;
		arep( itt, v )
		{
			auto [a, b] = itt;
//			cout << it.F << ": " << a << ", " << b << endl;
			if ( b == 1 )
			{
				if ( cnt == 0 )
				{
					start = a;
				}
				++cnt;
			}
			else
			{
				--cnt;
				if ( cnt <= 0 )
				{
					ans += ( a - start ) / d + 1;
				}
			}
		}
	}

	cout << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 28128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String S = sc.next();
		//int N = sc.nextInt();
		//System.out.println();
		int N = sc.nextInt();
		long a1 = 2;
		long a2 = 1;
		long lucas = 3;
		if(N==1){
			System.out.println(a2);
		}else{
			for(int i=1; i<N;i++){
				lucas = a1 + a2;
				a1 = a2;
				a2 = lucas;
			}
			System.out.println(lucas);
		}
			
	}
}


Measured memory_bytes: 23252
A1 = input().split()
A2 = input().split()
A3 = input().split()

A1 = [int(i) for i in A1]
A2 = [int(i) for i in A2]
A3 = [int(i) for i in A3]

A = []
A.append(A1)
A.append(A2)
A.append(A3)

B = [[0,0,0],[0,0,0],[0,0,0]]

N = int(input())
vals = []
for i in range(N):
  vals.append(int(input()))

for val in vals:
  if A[0][0] == val:
    B[0][0] = 1
  elif A[0][1] == val:
    B[0][1] = 1
  elif A[0][2] == val:
    B[0][2] = 1
  elif A[1][0] == val:
    B[1][0] = 1
  elif A[1][1] == val:
    B[1][1] = 1
  elif A[1][2] == val:
    B[1][2] = 1
  elif A[2][0] == val:
    B[2][0] = 1
  elif A[2][1] == val:
    B[2][1] = 1
  elif A[2][2] == val:
    B[2][2] = 1

isGood = False
for i in range(3):
  if B[i][0] + B[i][1] + B[i][2] == 3:
    isGood = True

for i in range(3):
  if B[0][i] + B[1][i] + B[2][i] == 3:
    isGood = True
    
if B[0][0] + B[1][1] + B[2][2] == 3:
  isGood = True

if B[2][0] + B[1][1] + B[0][2] == 3:
  isGood = True
  
if isGood == True:
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 3192
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

long long mod = 1000000007;
int N, M, K;
int ans = 1;

int answer() {
  if(N == 1) return M;

  for(int i = 1;i <= sqrt(M);i++) {
    if(M % i == 0) {
      if(i-N+1 > 0) ans = max(ans, M/i);
      int adiv = M/i; // another divisor
      if(adiv-N+1 > 0) ans = max(ans, M/adiv);
    }
  }

  return ans;
}

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N >> M;
  cout << answer() << 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 rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

bool solve(int c[3][3]){
    int b[3]={c[0][0],c[0][1],c[0][2]};
    int a[3]={0,c[1][0]-b[0],c[2][0]-b[0]};
    REP(i,3) REP(j,3){
        if(c[i][j]!=a[i]+b[j]) return false;
    }
    return true;
}

bool lie(int c[3][3]){
    return c[0][0]+c[1][1]+c[2][2]==c[0][1]+c[1][2]+c[2][0]&&
           c[0][1]+c[1][2]+c[2][0]==c[0][2]+c[1][0]+c[2][1];
}

int main(){
    int c[3][3];
    REP(i,3) REP(j,3) cin>>c[i][j];
    if(solve(c)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int k,s,ans=0;
   cin>>k>>s;
   
   for(int i=0;i<=k;i++){
       for(int j=0;j<=k;j++){
           if(0<=s-i-j&&s-i-j<=k)ans++;
       }
   }
   cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long K){
	ll res = 0;
	while(N != 0) {
		N /= K;
		res++;
	}
	cout << res << endl;
}

int main(){	
	long long K;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&K);
	solve(N, K);
	return 0;
}



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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define A first
#define B second
#define MOD 1000000007

typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;
}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

const int N = 1e5 + 5;

int arr[N];

/**
    Check out for boundary cases, (n = 1 or n = 0)
    check for integer overflow

**/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c;
    cin >> a >> b >> c;
    int rem = (a - b);
    cout << max(0, c - rem);

}



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

typedef long long ll;

using namespace std;

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

    int now = 1;

    for (int i = 1; i < n; i++) {
        if (i * i > n) {
            break;
        }

        now = i * i;
    }

    cout << now << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int
main(int argc, char* argv[]) {
    char input[20000];
    int n = 0;
    scanf("%d", &n);
    scanf("%s", input);
    int i=0;
    while(1){
        if(input[i++]=='\0') break;
    }
    int j;
    for(j=0;j<i-1;j++){
        if(input[j]+n > 'Z'){
            input[j]=input[j]-26+n;
        }
        else input[j]=input[j]+n;
    }
    printf("%s",input);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <string>

using namespace std;

int main()
{
    int p,q,r;
    cin >> p >> q >> r;
    cout << min(p+q, min(q+r, r+p)) << '\n';
    return 0;
}


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

using namespace std;

using ll =  long long;

constexpr ll LINF = 1LL << 60;

bool is_zero(ll k, ll n_pos, ll n_neg, ll n_zero) {
    return n_pos * n_neg < k && k <= n_pos * n_neg + n_zero * (n_pos+n_neg) + n_zero * (n_zero-1) / 2;
}

bool is_ok(ll mid, ll k, ll n_pos, ll n_neg, ll n_zero, vector<ll> &pos, vector<ll> &neg) {
    ll kk = 0;  // mid より小さい積をもつ組数
    if(k <= n_pos * n_neg) {
        for(int i=0;i<n_pos;++i) {
            ll d = n_neg - ll(lower_bound(neg.begin(), neg.end(), (-mid+pos[i]-1)/pos[i]) - neg.begin());
            kk += d;
        }
    } else {
        kk = n_pos * n_neg + n_zero * (n_pos+n_neg) + n_zero * (n_zero-1) / 2;
        for(int i=0;i<n_pos;++i) {
            ll d = ll(upper_bound(pos.begin()+i+1, pos.end(), mid/pos[i]) - pos.begin()) - (i+1);
            kk += d;
        }
        for(int i=0;i<n_neg;++i) {
            ll d = ll(upper_bound(neg.begin()+i+1, neg.end(), mid/neg[i]) - neg.begin()) - (i+1);
            kk += d;
        }
    }

    return kk >= k;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll n, k, a;
    cin >> n >> k;
    vector<ll> pos, neg;
    for(int i=0;i<n;++i) {
        cin >> a;
        if(a > 0) pos.push_back(a);
        else if(a < 0) neg.push_back(-a);
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    ll n_pos = pos.size(), n_neg = neg.size(), n_zero = n - n_pos - n_neg;

    if(is_zero(k, n_pos, n_neg, n_zero)) {
        cout << 0 << endl;
        return 0;
    }

    ll ng = -LINF, ok = LINF;
    while(ok-ng > 1LL) {
        ll mid = (ok + ng) / 2;
        if(is_ok(mid, k, n_pos, n_neg, n_zero, pos, neg)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok << endl;

    return 0;
}


Measured memory_bytes: 2420
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int query(const string s[2]) {
	puts(s[0].c_str());
	puts(s[1].c_str());
	fflush(stdout);
	char q[4];
	scanf("%s", q);
	if(*q == 'e') exit(0);
	return *q == 'T' ? 1 : 0;
}

int main() {
	int N;
	while(~scanf("%d", &N)) {
		string s[2];
		while(1) {
			rep(k, 2) s[k] += '?';
			bool ok = false;
			rep(p, 1 << 2) {
				rep(k, 2) s[k].back() = ".#"[p >> k & 1];
				if(query(s) == 1) {
					ok = true;
					break;
				}
			}
			if(!ok) {
				rep(k, 2)
					s[k].pop_back();
				break;
			}
		}
		while(1) {
			rep(k, 2) s[k] = '?' + s[k];
			bool ok = false;
			rep(p, 1 << 2) {
				rep(k, 2) s[k][0] = ".#"[p >> k & 1];
				if(query(s) == 1) {
					ok = true;
					break;
				}
			}
			assert(ok);
		}
	}
	return 0;
}


Measured memory_bytes: 724
x = input()
if x == "SUN":
    print(7)
elif x == "MON":
    print(6)
elif x == "TUE":
    print(5)
elif x == "WED":
    print(4)
elif x == "THU":
    print(3)
elif x == "FRI":
    print(2)
elif x == "SAT":
    print(1)

Measured memory_bytes: 2940
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    ans = 0
    n = ii()
    for _ in range(n):
        x, u = input().split()
        x = float(x)
        if u == 'JPY':
            ans += x
        else:
            ans += 380000 * x
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
//vector<vector<int>> data(3, vector<int>(4));

int main() {
	ll A, B, C, D;cin >> A >> B >> C >> D;
	ll time = 0;
	for (ll i = C;i <= D;i++) {
		if (A <= i && B >= i)time++;
	}
	if (time > 0)time--;
	cout << time << endl;
}

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

int main(void){
  int N, K, R;
  vector< vector<int> > bad(51);
  vector< vector<int> > boart(50);
  cin >> N >> K;
  for(int i=0; i < K; i++){
    int m; cin >> m;
    for(int j=0; j < m; j++){
      int tmp; cin >> tmp;
      boart[i].push_back(tmp);
    }
  }
  cin >> R;
  for(int i=0; i < R; i++){
    int p, q; cin >> p >> q;
    bad[p].push_back(q); bad[q].push_back(p);
  }

  int ans = 0;

  for(int i=0; i < K; i++){
    for(int j=0; j < boart[i].size(); j++){
      bool flg = false;
      for(int b=0; b < bad[boart[i][j]].size(); b++){
        for(int k = 0; k < boart[i].size(); k++){
          if(boart[i][k] == bad[boart[i][j]][b]){
            ans++;
            flg = true;
            break;
          }
        }
        if(flg) break;
      }
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
string s,t;
cin>>s>>t;
vector<char> a;
int dp[s.size()+1][t.size()+1];
for(int i = 0;i<=s.size();i++)
{
	for(int j = 0;j<=t.size();j++)
	{  
	  if(i==0 || j==0)
	  {
	  	dp[i][j]=0;
	  }
		else if(s[i-1] == t[j-1])
		{
			dp[i][j]=1+dp[i-1][j-1];
			
		}
		else {
		dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
		
	}
}
}
int index = dp[s.size()][t.size()];
//cout<<dp[s.size()][t.size()]<<endl;
int i =s.size(),j=t.size();
while(i>0 && j>0)
{
	    if (s[i-1] == t[j-1]) 
      { 
          a.push_back(s[i-1]); // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
}
reverse(a.begin(),a.end());	
	for(auto x : a) cout<<x;
	return 0;
}

Measured memory_bytes: 38792
#include <bits/stdc++.h>
#define ll long long
using namespace std;
main(){
	int n;
	double k;
	cin>>n;
	if(n%2==0)k=n/2*1.0;
	else k=(n+1)/2*1.0;
	printf("%.10f",k/n*1.0);
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vs32 A, B;

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

    int N;
    cin >> N;

    A.resize(N); B.resize(N);
    rep (i, N) cin >> A[i];
    rep (i, N) cin >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    vu64 acc(N + 1, 0);
    rep (i, N)
    {
        auto it = upper_bound(A.begin(), A.end(), B[i] - 1);
        acc[i + 1] = acc[i] + it - A.begin();
    }

    u64 ans = 0;
    int C;
    rep (i, N)
    {
        cin >> C;
        auto itb = upper_bound(B.begin(), B.end(), C - 1);
        if (itb == B.begin())
        {
            continue;
        }
        ans += acc[itb - B.begin()];
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1792
n, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

nega = []
posi = []
zeros = 0

a.each do |ai|
  if ai < 0
    nega << ai
  elsif ai > 0
    posi << ai
  else
    zeros += 1
  end
end

posi.sort!
nega.sort!.reverse!

ng = - (10 ** 18) - 1
ok = 10 ** 18 + 1

while ok - ng > 1
  mid = (ok + ng) / 2
  cnt = 0

  if mid >= 0
    cnt += zeros * (zeros - 1) / 2 + zeros * (n - zeros)
  end

  if mid > 0
    cnt += nega.size * posi.size
    [posi, nega].each do |a|
      l = 0
      r = a.size - 1
      while l < r
        while l < r and a[l] * a[r] > mid
          r -= 1
        end
        cnt += r - l
        l += 1
      end
    end
  else
    r = nega.size - 1
    0.upto(posi.size - 1) do |l|
      while r >= 0 and posi[l] * nega[r] <= mid
        r -= 1
      end
      cnt += nega.size - r - 1
    end
  end

  if cnt >= k
    ok = mid
  else
    ng = mid
  end
end
puts ok

Measured memory_bytes: 20472
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> h(n);
    cin >> h;
    bool ok = true;
    int now = h[n-1];
    for(int i = n-1;i>0;i--){
        if(now>=h[i-1]-1){
            now = min(now,h[i-1]);
        }
        else{
            ok = false;
        }
        
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3688
import java.util.Scanner;
public class Main {

  /*
  public static boolean find(String w, String t, int i) {
    int j = 0;
    while (j < w.length()) {
      if (i >= t.length())
        return false;
      if (w.charAt(j) != t.charAt(i))
        return false;
      i++;
      j++;
    }
    return true;
  }

  public static int count(String w, String t) {
    t = t.toLowerCase();
    int i = 0;
    int count = 0;
    boolean found = false;
    while (i < t.length()) {
      if (t.charAt(i) == w.charAt(0)) {
        found = find(w, t, i);
        if (find(w, t, i))
          count++;
      }
      i++;
    }
    return count;
  }
  */

  public static int count(String w, String t) {
    t = t.toLowerCase();
    t = t.replaceAll("[^a-z]", " ");
    String[] tAry = t.split(" ");
    int count = 0;
    for (String word : tAry) {
      if (word.equals(w))
        count++;
    }
    return count;
  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    String w = s.next();
    String line = s.nextLine();
    int count = 0;
    while (!line.equals("END_OF_TEXT")) {
      count += count(w, line);
      line = s.nextLine();
    }
    System.out.println(count);
    s.close();
  }

}



Measured memory_bytes: 26416
using System;
using System.Collections.Generic;
using System.Linq;

    class Program3
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            Sort.MergeSort(input);
            Console.WriteLine(input[input.Length / 2] - input[input.Length / 2 - 1]);
        }
    }

    static class Sort
    {
      const int THREASHOLD = 64;
      
              public static void Swap<T>(ref T a, ref T b)
        {
            T c = a; a = b; b = c;
        }
      
        static void InsertSort<T>(T[] a, int first, int last)
          where T : IComparable<T>
        {
            for (int i = first + 1; i <= last; i++)
                for (int j = i; j > first && a[j - 1].CompareTo(a[j]) > 0; --j)
                    Swap(ref a[j], ref a[j - 1]);
        }
      
      public static void MergeSort<T>(T[] a)
          where T : IComparable<T>
        {
            T[] work = new T[a.Length / 2];
            MergeSort(a, 0, a.Length, work);
        }

        static void MergeSort<T>(T[] a, int begin, int end, T[] work)
          where T : IComparable<T>
        {
            if (end - begin < THREASHOLD)
            {
                InsertSort(a, begin, end - 1);
                return;
            }

            int mid = (begin + end) / 2;
            MergeSort(a, begin, mid, work);
            MergeSort(a, mid, end, work);
            Merge(a, begin, mid, end, work);
        }

        static void Merge<T>(T[] a, int begin, int mid, int end, T[] work)
          where T : IComparable<T>
        {
            int i, j, k;

            for (i = begin, j = 0; i != mid; ++i, ++j) work[j] = a[i];

            mid -= begin;
            for (j = 0, k = begin; i != end && j != mid; ++k)
            {
                if (a[i].CompareTo(work[j]) < 0)
                {
                    a[k] = a[i];
                    ++i;
                }
                else
                {
                    a[k] = work[j];
                    ++j;
                }
            }

            for (; i < end; ++i, ++k) a[k] = a[i];
            for (; j < mid; ++j, ++k) a[k] = work[j];
        }
    }

Measured memory_bytes: 20320
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int INF = 1000000;
struct segment_tree{
	int N;
	vector<int> M, m;
	segment_tree(vector<int> &A){
		int n = A.size();
		N = 1;
		while (N < n){
			N *= 2;
		}
		M = vector<int>(N * 2 - 1, -INF);
		for (int i = 0; i < n; i++){
			M[N - 1 + i] = A[i];
		}
		for (int i = N - 2; i >= 0; i--){
			M[i] = max(M[i * 2 + 1], M[i * 2 + 2]);
		}
		m = vector<int>(N * 2 - 1, INF);
		for (int i = 0; i < n; i++){
			m[N - 1 + i] = A[i];
		}
		for (int i = N - 2; i >= 0; i--){
			m[i] = min(m[i * 2 + 1], m[i * 2 + 2]);
		}
	}
	pair<int, int> query(int L, int R, int i, int l, int r){
		if (r <= L || R <= l){
			return make_pair(INF, -INF);
		} else if (L <= l && r <= R){
			return make_pair(m[i], M[i]);
		} else {
			int mid = (l + r) / 2;
			pair<int, int> A = query(L, R, i * 2 + 1, l, mid);
			pair<int, int> B = query(L, R, i * 2 + 2, mid, r);
			return make_pair(min(A.first, B.first), max(A.second, B.second));
		}
	}
	pair<int, int> query(int L, int R){
		return query(L, R, 0, 0, N);
	}
};
int main(){
	int N, K;
	cin >> N >> K;
	vector<int> P(N);
	for (int i = 0; i < N; i++){
		cin >> P[i];
	}
	segment_tree ST(P);
	int ans = N - K + 1;
	for (int i = 0; i < N - K; i++){
		pair<int, int> tmp = ST.query(i + 1, i + K);
		if (P[i] < tmp.first && tmp.second < P[i + K]){
			ans--;
		}
	}
	int cons = 1;
	int sc = 0;
	for (int i = 1; i < N; i++){
		if (P[i - 1] < P[i]){
			cons++;
			if (cons == K){
				sc++;
			}
		} else {
			cons = 1;
		}
	}
	if (sc > 0){
		ans -= sc - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

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

    sort(a.begin(),a.end());
    ll mx = 0;
    rep(i,n-1){
        ll l=abs(a[i+1]-a[i]);
        mx=max(mx,l);
    }

    ll l=k - abs(a[n-1]-a[0]);
    mx=max(l,mx);

    cout<<k - mx<<endl;
}

Measured memory_bytes: 4748
/*
        i Apologize 3la el Habda
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;
long double EPS = 1e-6;


int ans[N];
int h[N];
int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n,k;
    cin >> n;
    for(int i = 0; i < n; ++i){
            cin >> h[i];
            ans[i] = 2e9;
    }
    ans[0] = 0;
    ans[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; ++i){
         ans[i] = min(abs(h[i - 2] - h[i])+ans[i - 2], abs(h[i - 1]-h[i])+ans[i - 1]);
    }
    cout << ans[n-1] << "\n";
 return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long

using namespace std;

int a,b;

il int gi(){
  RG int x=0,q=1; RG char ch=getchar();
  while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
  if (ch=='-') q=-1,ch=getchar();
  while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
  return q*x;
}

int main(){
  gi(),a=gi(),b=gi();
  puts((b-a-1)&1?"Alice":"Borys");
  return 0;
}


Measured memory_bytes: 256
class Node
    attr_accessor :parent, :rank

    def initialize(n)
      @parent = n
      @rank = 0
    end
end

class UnionFindTree
  def initialize(n)
    @n = n
    @nodes = (0..n).to_a.map { |i| Node.new(i) }
  end

  def find(x)
    return x if @nodes[x].parent == x

    return @nodes[x].parent = find(@nodes[x].parent)
  end

  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b

    if @nodes[a].rank < @nodes[b].rank
      @nodes[a].parent = b
    else
      @nodes[b].parent = a
      @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
    end
  end

  def same?(a, b)
    find(a) == find(b)
  end

  def parents
    @nodes.map(&:parent)
  end

  def roots
    (1..@n).map {|i| find(i)}
  end
end

n,k,l = gets.chomp.split.map(&:to_i)
tree1 = UnionFindTree.new(n)
k.times do
    p,q = gets.chomp.split.map(&:to_i)
    tree1.unite(p,q)
end

tree2 = UnionFindTree.new(n)
l.times do
    r,s = gets.chomp.split.map(&:to_i)
    tree2.unite(r,s)
end

p =  (1..n).to_a.zip(tree1.roots, tree2.roots)
g = p.group_by {|i| [i[1], i[2]]}

ans = []
p.each do |v|
    ans << g[[v[1],v[2]]].size
end
puts ans.join(" ")





Measured memory_bytes: 81660