akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var d = ReadArrayInt();
            Array.Sort(d);
            var ans = d[N / 2] - d[N / 2 - 1];            

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 20064
#include <iostream>
#include <cstring>
using namespace std;
int r,c;
int max_on;
int row_on[11];
int col_on[10005];
bool grid[11][10005];
bool flip_pattern[11];
int cur_on = 0;
//
void setFlipStatus(unsigned int p){
    for (int i = 0; i<r; ++i) {
        if (p & (1<<i)) {
            flip_pattern[i] = true;
        }
        else
            flip_pattern[i] = false;
    }
}
void flip_rows(){
    for (int i = 0; i<r; ++i){
        if (flip_pattern[i]) {
            for (int j = 0; j<c; ++j) {
                grid[i][j] = !grid[i][j];
                if(grid[i][j])
                    col_on[j]++;
                else
                    col_on[j]--;
            }
            row_on[i] = c - row_on[i];
            cur_on += 2*row_on[i] - c;
        }
    }
}
void find_cur_max(){
    int ori_on = cur_on;
    for (int j = 0; j<c; ++j) {
        if(r-col_on[j]>col_on[j]){
            cur_on += r - 2*col_on[j];
        }
    }
    if (cur_on>max_on)
        max_on = cur_on;
    
    cur_on = ori_on;
}
int main(){
    while (cin>>r>>c && r &&c) {
        max_on = 0;
        cur_on = 0;
        memset(flip_pattern, 0, sizeof(flip_pattern));
        memset(row_on, 0, sizeof(row_on));
        memset(col_on, 0, sizeof(col_on));
        //
        for (int i = 0; i < r; ++i)
            for (int j = 0; j<c ; ++j) {
                cin>>grid[i][j];
                if (grid[i][j]) {
                    cur_on++;
                    row_on[i]++;
                    col_on[j]++;
                }
            }
        max_on = cur_on;
        //
        unsigned int status_size = 1<<r;
        for (unsigned int i=0; i<status_size;++i ) {
            //??¨??????????????¬?????????
            setFlipStatus(i);
            flip_rows();
            find_cur_max();
            flip_rows();
        }
        cout<<max_on<<endl;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 1304
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;

	ll ar[n+1],an[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}

	k=0;
	for(i=1;i<=n;i++){
		if(i%2){
			k+=ar[i];
		}
		else {
			k-=ar[i];
		}
	}
	an[1]=k;
	for(i=2;i<=n;i++){
		an[i]=2*ar[i-1]-an[i-1];
	}

	for(i=1;i<=n;i++){
		cout<<an[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  double l;
  cin >> l;
  double x = l/3.0;
  double ans = x*x*x;
  printf("%.10lf\n", ans);

  return 0;
}

Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  ll H[n];
  rep(i,n) cin >> H[i];

  ll memo = H[n-1];
  for(int i = n-2; i >= 0; i--){
    if(memo + 1 == H[i]){
      H[i]--;
    }else if(memo + 1 < H[i]){
      printf("No\n");
      return 0;
    }
    memo = H[i];
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    ll diff = abs(b-a);
    // if(n%2==0){
    //     diff = abs(diff-c);
    //     n--;
    // }
    n--;
    bool flg= diff <= d*n && diff >= c*n;
    ll init = n%2; 
    DEBUG{cout << init << endl;}
    for(ll i=init;i<=n;i+=2){
        if(flg){break;}
        flg = diff <= d*i && diff >= c*i ||
        abs(diff-d*i)<=(d-c)*(n-i)/2 ||
        abs(diff-c*i) <= (d-c)*(n-i)/2;
    }
    cout << (flg ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
#define MAX 500001
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node x){
while(x->left!=NIL){
  x=x->left;
}
return x;
}

Node treeMaximum(Node x){
while(x->right!=NIL){
  x=x->right;
}
return x;
}

Node treeSearch(Node x, int k){
while ( x!=NIL && k!=x->key){
  if(k<x->key) x=x->left;
  else x=x->right;
}
return x;
}

Node treeSuccessor(Node x){
Node y;
if(x->right !=NIL) return treeMinimum(x->right);

y=x->parent;
while ( y !=NIL && x == y->right) {
  x=y;
  y=y->parent;
}
return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
if(z->left == NIL || z->right ==NIL){
  y=z;
}
else y= treeSuccessor(z);

if(y->left != NIL) x=y->left;
else x=y->right;

if(x !=NIL) x->parent=y->parent;
if(y->parent==NIL) root=x;
else if(y==y->parent->left) y->parent->left=x;
else y->parent->right=x;

if(y!=z) z->key=y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

while( x!=NIL){
  y=x;
  if(z->key<x->key) x=x->left;
  else x=x->right;
}
z->parent=y;
if(y==NIL)root=z;
else{
  if(z->key<y->key) y->left=z;
  else y->right=z;
}
}

void inorder(Node u){
if(u==NIL) return;
inorder(u->left);
printf(" %d",u->key);
inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25296
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m;
	cin>>n>>m;
	vvi in(n,vi(3));
	rep(i,n)rep(j,m){
		char c;
		cin>>c;
		if(c=='W')in[i][0]++;
		else if(c=='B')in[i][1]++;
		else in[i][2]++;
	}
	vvi dp(3,vi(n+1,inf));
	dp[0][0]=0;
	rep(i,n)dp[0][i+1]=dp[0][i]+m-in[i][0];
	loop(i,1,n)dp[1][i+1]=min(dp[0][i],dp[1][i])+m-in[i][1];
	loop(i,2,n)dp[2][i+1]=min(dp[1][i],dp[2][i])+m-in[i][2];
	cout<<dp[2][n]<<endl;
}

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

using namespace std;
#define INF (1<<30)

int solve(const int h, const int w, const vector<vector<int>> &C, const vector<vector<int>> &A) {
    vector<int> p(10); for (int i = 0; i < 10; ++i) p[i] = i;
    vector<int> dp(10); for (int i = 0; i < 10; ++i) dp[i] = INF;
    do {
        int cost = 0;
        for (int i = 0; i < 10; ++i) {
            if (p[i] == 1) break;
            cost += C[p[i]][p[i+1]];
        }
        dp[p[0]] = min(dp[p[0]], cost);
    } while (next_permutation(p.begin(), p.end()));
    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int x = A[i][j];
            if (x != -1) {
                ans += dp[x];
            }
        }
    }
    return ans;
}

int main() {
    int h, w; cin >> h >> w;
    vector<vector<int>> C(10, vector<int>(10));
    for (int i = 0; i < C.size(); ++i) for (int j = 0; j < C[i].size(); ++j) cin >> C[i][j];
    vector<vector<int>> A(h, vector<int>(w));
    for (int i = 0; i < A.size(); ++i) for (int j = 0; j < A[i].size(); ++j) cin >> A[i][j];
    cout << solve(h, w, C, A) << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main()
{
  
  int i,j,x,count=0,N,flag;
  int A[100];

  scanf("%d",&N);
  
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  
  flag = 1;

  while(flag){
    flag = 0;
    for(j=N-1;j>=1;j--){
      if(A[j]<A[j-1]){
	x = A[j];
	A[j] = A[j-1];
	A[j-1] = x;
	flag = 1;
	count++;
      }
    }
  }
  
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i != N-1) printf(" ");   
  }
  
  printf("\n");
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 604
N = int(input())

AB = [list(map(int, input().split())) for i in range(N)]

AB.sort(key=lambda x: x[1])
time = 0

for i in range(N):
  time += AB[i][0]
  if time > AB[i][1]:
    print("No")
    exit()

print("Yes")

Measured memory_bytes: 88024
n = int(input())
c = [int(input()) for _i in range(n)]
c.append(-1)
dic = [-1 for _i in range(10**5 *2 +1)]
dp = [0 for _i in range(n+1)]
dp[n] = 1
mod = 10**9 +7
for i in range(n):
    if c[i-1] != c[i]:
        if dic[c[i]] > 0:
            dp[i] = (dp[i-1] + dic[c[i]])%mod
        else:
            dp[i] = dp[i-1]
        dic[c[i]] = dp[i]
    else:
        dp[i] = dp[i-1]
    
print(dp[n-1]%mod)

Measured memory_bytes: 73124
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

string rank( double weight )
{
	if ( weight <= 48 )
	{
		return "light fly";
	}
	else if ( weight <= 51 )
	{
		return "fly";
	}
	else if ( weight <= 54 )
	{
		return "bantam";
	}
	else if ( weight <= 57 )
	{
		return "feather";
	}
	else if ( weight <= 60 )
	{
		return "light";
	}
	else if ( weight <= 64 )
	{
		return "light welter";
	}
	else if ( weight <= 69 )
	{
		return "welter";
	}
	else if ( weight <= 75 )
	{
		return "light middle";
	}
	else if ( weight <= 81 )
	{
		return "middle";
	}
	else if ( weight <= 91 )
	{
		return "light heavy";
	}
	else
	{
		return "heavy";
	}
}

int main()
{
	double input;

	while ( cin >> input )
	{
		cout << rank( input ) << endl;
	}

	return 0;
}

Measured memory_bytes: 0
//-----------------------
// author : xyqkoala
// time : 2020-08-29
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

int find(vector<int> &t,int x){
	if(x!= t[x]) t[x] = find(t,t[x]);
	return t[x];
}
void solve(){
	int n,m;
	cin>>n>>m;
	vector<int> t(n);
	for(int i=0;i<n;i++) t[i] = i;
	vector<int> dp(n,0);
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		t[find(t,x)] = t[find(t,y)];
	}
	for(int i=0;i<n;i++){
		dp[find(t,i)]++;
	}
	int mx = -1;
	for(auto item:dp) mx = max(mx,item);
	cout<<mx<<endl;
}


Measured memory_bytes: 11048
n = int(input())
v = list(map(int,input().split()))
z = 0
for i in range(n):
    if len(v) == 1:
        print(z)
    else:
        z = min(v)
        v.remove(z)
        z = (z + min(v))/2
        v.remove(min(v))
        v.append(z)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll h, n;
	cin >> h >> n;
	vll a(n), b(n);
	for (ll i = 0; i < n; i++) cin >> a[i] >> b[i];

	vll dp(h + 1, inf);
	dp[0] = 0;
	for (ll i = 1; i <= h; i++) {
		for (ll j = 0; j < n; j++) {
			dp[i] = min(dp[i], dp[max(0ll, i - a[j])] + b[j]);
		}
	}
	cout << dp[h] << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
	while(1)
	{
		double n;
		scanf("%lf",&n);
		if(n < 0.0) return 0;
		bool xx[15]={}; int c = 0;
		for(double x=128.0;x>=1.0/16.0;x/=2.0)
		{
			if(n >= x)
			{
				n -= x;
				xx[c] = true;
			}
			c++;
		}
		if(n != 0.0) puts("NA");
		else
		{
			for(int i=0;i<12;i++)
			{
				if(i == 8) printf(".");
				printf(xx[i]?"1":"0");
			}
			puts("");
		}
	}
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int N,K,A[200000];
    cin >> N >> K;
    for (int i=0; i<N; ++i) cin >> A[i];

    int num[200000] = {0};
    for (int i=0; i < N; ++i) {
        num[A[i]-1]++;
    }
    sort (num,num+N,greater<int>());
    int sum;
    for (int i=N; i>=K; --i){
        sum += num[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
char A[60][60];

void search(int a,int b)
{
	int i,j;
	for(i=a-1;i<=a+1;++i)
		for(j=b-1;j<=b+1;++j)
		{
			if(A[i][j]!='#')
				A[i][j]++;
		}
}

int main()
{
	int W,H,i,j;
	scanf("%d%d",&H,&W);
	getchar();
	for(i=0;i<H;++i)
	{
		gets(A[i]);
		for(j=0;j<W;++j)
			if(A[i][j]=='.')
				A[i][j]='0';
	}
	for(i=0;i<H;++i)
		for(j=0;j<W;++j)
		{
			if(A[i][j]=='#')
				search(i,j);
		}
	for(i=0;i<H;++i)
	{
		for(j=0;j<W;++j)
		{
			printf("%c",A[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;
    for(int i = 0; i < 1000; i++) {
        int t[3] = {i/100, (i/10)%10, i%10};
        int f = 0;
        for(int j = 0; j < n; j++) {
            if (s[j] == '0'+t[f]) f++;
            if (f == 3) break;
        }
        if (f == 3) ans++;
    }

    cout << ans << endl;
    
    return 0;

}

Measured memory_bytes: 256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    int n;
    cin>>n;
    string str;
    cin>>str;
    set<string> s;
    s.insert(str);
    --n;
    while(n--){
        string temp;
        cin>>temp;
        int len = str.length();
        --len;
        if(s.count(temp) || temp[0] != str[len]){
            cout<<"No";
            return ;
        }
        s.insert(temp);

        str = temp;
    }
    cout<<"Yes";
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

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


int main(void){
   int N;
   cin>>N;
   vector<int> v(N);
   map<int,int>b;
   for(int i=1;i<N;i++){
   cin>>v[i];
   }
   for(int i=1;i<N;i++){
     b[v[i]]++;
   }
   for(int i=1;i<=N;i++){
     cout<<b[i]<<endl;
   }
    return 0;
}




Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define mp make_pair
// GCD inbuilt func: __gcd(a,b)
// LCM formula: (a*b)/__gcd(a,b)

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	// CODE goes here
    string s,t;
    cin >> s >> t;
    int maxi=0;
    for(unsigned int i=0;i<s.size()-t.size()+1;i++){
    	int matched=0;
    	unsigned int j=i;
    	unsigned int k=j;
    	for(j=i;j<i+t.size();j++){
    		if(s[j]==t[j-k]) matched++;
    	}
    	maxi=max(maxi,matched);
    }
    cout << t.size()-maxi;
	return 0;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAX 25
#define NIL -1
using namespace std;

typedef struct{
	int parent, left, right, sibling, degree;
} Node;

Node T[MAX];
int D[MAX];
int H[MAX];

int findRoot(void){
	int u = 0;
	while(T[u].parent != NIL)
		u = T[u].parent;
	return u;
}

void setDepth(int u, int p){
	D[u] = p;
	if(T[u].right != NIL)
		setDepth(T[u].right, p + 1);
	if(T[u].left != NIL)
		setDepth(T[u].left, p + 1);
}
int setHeight(int u){
	int h1 = 0, h2 = 0;
	if(T[u].right != NIL)
		h1 = setHeight(T[u].right) + 1;
	if(T[u].left != NIL)
		h2 = setHeight(T[u].left) + 1;
	return H[u] = max(h1, h2);
}

int main(void){
	int n, i, id, left, right, root;
	scanf("%d", &n);
	for(i=0;i<n;i++)
		T[i].parent = NIL;
		T[i].degree = 0;
	for(i = 0;i < n;i++){
		scanf("%d %d %d", &id, &left, &right);
		T[id].left = left;
		T[id].right = right;
		if(left != NIL){
			T[id].degree ++;
			T[left].parent = id;
			T[left].sibling = right;
		}
		if(right != NIL){
			T[id].degree ++;
			T[right].parent = id;
			T[right].sibling = left;
		}
	}
	root = findRoot();
	T[root].sibling = NIL;
	setDepth(root, 0);
	setHeight(root);
	for(i = 0;i < n;i++){
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, T[i].parent, T[i].sibling, T[i].degree, D[i], H[i]);
		if(T[i].parent == NIL)
			printf("root\n");
		else if(T[i].left == NIL && T[i].right == NIL)
			printf("leaf\n");
		else
			printf("internal node\n");
	}
	return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e9

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll n, a, ans;
ll used[9], level[9];

int main()
{
    cin >> n;
    level[0]=399;
    level[1]=799;
    level[2]=1199;
    level[3]=1599;
    level[4]=1999;
    level[5]=2399;
    level[6]=2799;
    level[7]=3199;
    level[8]=INF;
    for(int i =0; i < n; i++){
		cin >> a;
		for(int j = 0; j <= 8; j++){
			if(a<=level[j]){
				used[j]++;
				j=9;
			}
		}
	}
	for(int i = 0; i <= 7; i++){
		if(used[i]){
			ans++;
		}
	}
	if(ans){
		cout << ans << " " << ans+used[8] << endl;
	}
	else{
		cout << 1 << " " << used[8] << endl;
	}
}


Measured memory_bytes: 256
N,K = map(int,input().split())
S = input()
S = list(S)

if S[K-1] == "A":
    S[K-1] = "a"

if S[K-1] == "B":
    S[K-1] = "b"

if S[K-1] == "C":
    S[K-1] = "c"
    
print("".join(S))

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val v = (1..n).map{readLine()!!.toInt()}
    println(calcAns(n, v))
}

fun calcAns(n: Int, v: List<Int>): Int {
    var now = 0
    for (i in 0..n - 1) {
        if (now == 1) {return i}
        now = v[now] - 1
    }
    return -1
}

Measured memory_bytes: 40988
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan= new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int d=scan.nextInt();
		if((a*b)>(c*d)) System.out.println(a*b);
		else System.out.println(c*d);
	}

}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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;
}

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    ll x = n;
    ll k = 1;
    while(x % 360) {
        x += n;
        k++;
    }
    cout << k << en;
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


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

int main() {
  int n, x, m = 0;
  cin >> n >> x;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  rep(i, n){
    x -= v[i];
    if(x < 0) break;
    ++m;
  }
  if(m == n && x != 0) --m;
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
typedef unsigned long long ull;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define testcases ll t;cin>>t;while(t--)
#define dec(x) greater<x>()

/*** Define Values ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 100005
const char nl = '\n';

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a, pll b) { if (a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "

/*** Functions
ll BigMod(ll base, ll pow, ll modvalue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modvalue);ll total = ((ans % modvalue) * (ans % modvalue)) % modvalue;  if(pow % 2 == 0) return total; else{ return (total * (base % modvalue) ) % modvalue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }
ll sumofdigit(long ll n){ll sum=0;while(n){sum=sum+n%10;n=n/10;}return sum;}
ll countDigit(ll n) { if (n == 0) return 0; return 1 + countDigit(n / 10); }
ll countDigit(ll n) { return floor(log10(n) + 1); } //only positive
 ***/

template <class T> inline T gcd(T a, T b) {if (b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b, T p) {ll ans = 1; while (p--) ans *= b; return ans;}

void solve()
{	
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	vll v;
	ll z=a*c;
	v.pb(z);
	 z=a*d;
	v.pb(z);
	z=b*c;
	v.pb(z);
	z=b*d;
	v.pb(z);

	cout<<*max_element(v.begin(), v.end());
}


int main()
{

#ifndef ONLINE_JUDGE
	freopen("C:/Users/91731/Documents/input.txt", "r", stdin);
	freopen("C:/Users/91731/Documents/output.txt", "w", stdout);
	freopen("C:/Users/91731/Documents/error.txt", "w", stderr);
#endif

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	solve();
}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	
	int N;
	LL A,B;
	cin>>N>>A>>B;
	if (A>B){
		cout<<0<<endl;
		return 0;
	}

	if (N==1){
		if (A!=B){
			cout<<0<<endl;
		}else{
			cout<<1<<endl;
		}
		return 0;
	}

	cout<<A+(N-1)*B - (A*(N-1)+B)+1<<endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n, X, Y, Z, a[MAXN], b[MAXN], c[MAXN], num[MAXN];
long long ans, rn;
set<pair<int, int> > s, t[3];
void makeFindT() {
	while (t[0].size() < Y) {
		auto p = *t[1].begin();
		p.first = -p.first, rn = rn - c[p.second] + b[p.second];
		t[0].insert(p);
		t[1].erase(t[1].begin());
	}
}
void makeFindS() {
	auto fr = *s.begin();
	s.erase(s.begin());
	rn = 1ll * rn - fr.first;
	return;
}
int main() {
	cin >> X >> Y >> Z;
	n = X + Y + Z;
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i] >> c[i];
	iota(num, num + n, 0);
	sort(num, num + n, [] (int x, int y) { return (a[x] - b[x] > a[y] - b[y]); });
	for (int i = 0; i < X; i++) {
		s.insert({a[num[i]] - c[num[i]], num[i]});
		rn += a[num[i]];
	}
	for (int i = X; i < n; i++) {
		t[1].insert({-1 * (b[num[i]] - c[num[i]]), num[i]});
		rn += c[num[i]];
	}
	makeFindT();
	ans = max(ans, rn);
	for (int i = X; i < n - Y; i++) {
		pair<int, int> fr = {a[num[i]] - c[num[i]], num[i]}, sd = {b[num[i]] - c[num[i]], num[i]};
		s.insert(fr);
		rn += a[fr.second];
		makeFindS();
		auto p = *t[0].begin();
		if (sd >= p) {
			t[0].erase(sd);
			rn -= b[sd.second];
		}
		else {
			sd.first = -sd.first;
			t[1].erase(sd);
			rn -= c[sd.second];
		}
		makeFindT();
		ans = max(ans, rn);
	}
	cout << ans;
	return 0;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif // LOCAL

    int k, n;
    cin >> k >> n;

    int a[n];

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

    int max_dist = 0;

    for (int i = 1; i < n; i++) {
        max_dist = max(max_dist, a[i] - a[i - 1]);
    }

    max_dist = max(max_dist, k - a[n - 1] + a[0]);

    cout << (k - max_dist) << '\n';

    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)

        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            if (A > 8 || B > 8)
            {
                Console.WriteLine(":(");
            }
            else { Console.WriteLine("Yay!");}
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define lint long long int
using namespace std;

int main()
{
	int k=0;
	string s,ans;
	cin>>k>>s;
	if(s.size()<=k)
	{
		cout<<s<<endl;
	}
	else
	{
		ans=s.substr(0,k);
		ans.push_back('.');
		ans.push_back('.');
		ans.push_back('.');
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3628
import sys
X, N = map(int, input().split())
Mylist = input().split()
Mylist = [int(s) for s in Mylist]

for i in range(100):
    if not (X - i) in Mylist:
        print(X-i)
        sys.exit()
    elif not (X + i) in Mylist:
        print(X+i) 
        sys.exit()

Measured memory_bytes: 9184
N, K = map(int, input().split())
S = input()
arr = []
prev = '1'
length = 0
for c in S:
  if prev != c:
    arr.append(length)
    length = 0
  length += 1
  prev = c
arr.append(length)
if S[-1] == '0':
  arr.append(0)

sarr = [0]
for a in arr:
  sarr.append(sarr[-1] + a)

L = K * 2 + 1
if L >= len(sarr):
  print(N)
  exit()
ans = 0
for i in range(0, len(sarr)-L, 2):
  t = sarr[i+L] - sarr[i]
  ans = ans if ans > t else t
print(ans)

Measured memory_bytes: 7932
sx, sy, tx, ty = gets.split.map(&:to_i)

ans = ''

dy = ty - sy
dx = tx - sx

ans += 'U' * dy
ans += 'R' * dx
ans += 'D' * dy
ans += 'L' * dx
ans += 'L' + 'U' * (dy + 1)
ans += 'R' * (dx + 1) + 'D'
ans += 'R' + 'D' * (dy + 1)
ans += 'L' * (dx + 1) + 'U'

puts ans


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

int main(){
	int n;
	cin>>n;
	string s;
	map<string,int>m;
	for(int i=0;i<n;i++){
		cin>>s;
		m[s]++;
	}
	cout<<m.size();
	return 0;
}

Measured memory_bytes: 19172
require 'set'

class Peaks
  def initialize(n, ah, aab)
    @n = n
    @ah = ah
    @aab = aab
  end

  def solve
    st = Set.new

    @aab.each do |ab|
      if @ah[ab[0] - 1] < @ah[ab[1] - 1]
        st << ab[0]
      elsif @ah[ab[0] - 1] > @ah[ab[1] - 1]
        st << ab[1]
      else
        st << ab[0]
        st << ab[1]
      end
    end
    
    @n - st.size
  end
end

def run
  n, m = gets.scan(/\d+/).map(&:to_i)
  ah = gets.scan(/\d+/).map(&:to_i)
  aab = Array.new(m){gets.scan(/\d+/).map(&:to_i)}
  
  puts Peaks.new(n, ah, aab).solve
end

run



Measured memory_bytes: 26232
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<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 ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    ll d = abs(a - b), c = t * (v - w);
    if (c >= d) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int a[100+1];
int main(){
	int n,s=0;
	cin>>n;
	for(int i=1; i<=n; i++){
		int x;
		cin>>x;
		a[x]=1;
	}
	for(int i=1; i<=100; i++){
		if(a[i]==1){
			s++;
		}
	}
	cout<<s<<endl;
	
	return 0;
}

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

typedef long long LL;

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

    int N;
    cin >> N;
    int balls[N];
    multiset<int> ms;

    for (int i = 0; i < N ;i++) {
        cin >> balls[i];
        ms.insert(balls[i]);

    }

    sort(balls + 1, balls + 1 + N);
    int pairs = 0;
    int balls_aux[N];
    for (int j = N; j > 0;j--)
    {
        int val = balls[j];
        if (ms.find(val) != ms.end()){
            ms.erase(ms.find(val));
            for (int i = 0; i <= 30; i++)
            {
                if (val < 1 << i) {
                    int need = (1 << i) - val;
                    if (ms.find(need) != ms.end())
                    {
                        ms.erase(ms.find(need));
                        pairs++;
                    }
                    break;
                }
            }
        }
    }

    cout << pairs;

    return 0;
}

Measured memory_bytes: 12416
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    int a[n], m = INF, ans = 0;
    for(int i=0;i<n;++i) {
        cin >> a[i];
        if(m > a[i]) ++ans;
        m = min(m, a[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
        
		Long[] nums = new Long[6];
		for(int i=0; i<6; i++) {
			nums[i] = sc.nextLong();
		}
		
		for(int i=0; i<6; i++) {
			long tmp = nums[i];
			int count = 0;
			for(int j=0; j<6; j++) {
				if(tmp == nums[j]) {
					count++;
				}
			}
			if(count>=3) {
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
		
    }

}


Measured memory_bytes: 21844
import copy
S_dash = input()
T = input()

len_S = len(S_dash)
len_T = len(T)

candidate0 = list(S_dash)


ans = "z"*51

if len_S >= len_T:
  for s in range(len_S):
    cha_S = S_dash[s]
    if cha_S != "?" and cha_S in list(T):
      for t in range(len_T):
        cha_T = T[t]
        if cha_S == cha_T and 0<= s-t < len_S and  0< s-t+len_T <= len_S:
          S_cut = S_dash[s-t:s-t+len_T]
          candidate1 = copy.deepcopy(candidate0)
          for x in range(len_T):
            if S_cut[x] == "?":
              candidate1[s-t+x] = T[x]
            elif  S_cut[x] != T[x]:
              break
          else:
            if "".join(candidate1[s-t:s-t+len_T]) == T:
              if ans > "".join(candidate1).replace('?', 'a'):
                ans = "".join(candidate1).replace('?', 'a')
  
  
  
  for u in range(len_S-len_T+1):
    cut_S = S_dash[u:u+len_T]
    if cut_S.count("?") == len_T:
      candidate1 = copy.deepcopy(candidate0)
      for t in range(len_T):
        candidate1[u+t] = T[t]
      if ans > "".join(candidate1).replace('?', 'a'):
        ans = "".join(candidate1).replace('?', 'a')
                
if ans == "z"*51:
  ans = "UNRESTORABLE"
print(ans)

Measured memory_bytes: 9132
import java.io.*;
import java.util.*;

public class Main {
  private static long[] solve(long r, long d, long x2000) {
    long[] x = new long[10];
    x[0] = r * x2000 - d;
    for (int i = 1; i < 10; i++) {
      x[i] = r * x[i - 1] - d;
    }
    return x;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    long r = reader.nextLong();
    long d = reader.nextLong();
    long x2000 = reader.nextLong();
    long[] x = solve(r, d, x2000);
    for(long xi : x) {
      out.println(xi);
    }
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Algorithm {
  private static void swap(Object[] list, int a, int b) {
    Object tmp = list[a];
    list[a] = list[b];
    list[b] = tmp;
  }
  
  public static <T extends Comparable<? super T>> boolean nextPermutation(T[] ts) {
    int rightMostAscendingOrderIndex = ts.length - 2;
    while (rightMostAscendingOrderIndex >= 0 &&
        ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostAscendingOrderIndex + 1]) >= 0) {
      rightMostAscendingOrderIndex--;
    }
    if (rightMostAscendingOrderIndex < 0) {
      return false;
    }
    
    int rightMostGreatorIndex = ts.length - 1;
    while (ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostGreatorIndex]) >= 0) {
      rightMostGreatorIndex--;
    }
    
    swap(ts, rightMostAscendingOrderIndex, rightMostGreatorIndex);
    for (int i = 0; i < (ts.length - rightMostAscendingOrderIndex - 1) / 2; i++) {
      swap(ts, rightMostAscendingOrderIndex + 1 + i, ts.length - 1 - i);
    }
    return true;
  }
}



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

int main(){
	string SA,SB,SC,S;
    cin>>SA>>SB>>SC;
    S=SA;
    char C='a';
    for(int i=0;i<1000;i++){
    	if(C=='a'){
    		if(SA.size()>0){
              C=SA.at(0);
              SA.erase(SA.begin());
              S=SA;
              continue;
              
    		}
    		if(SA.size()==0){
    			cout<<'A'<<endl;
    			break;
    		}
    	}
    	if(C=='b'){
    		if(SB.size()>0){
              C=SB.at(0);
              SB.erase(SB.begin()+0);
              S=SB;
              continue;
              
    		}
    		if(SB.size()==0){
    			cout<<'B'<<endl;
    			break;
    		}
    	}
    	if(C=='c'){
    		if(SC.size()>0){
              C=SC.at(0);
              SC.erase(SC.begin()+0);
              S=SC;
              continue;
              
    		}
    		if(SC.size()==0){
    			cout<<'C'<<endl;
    			break;
    		}
    	}
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;
#include <deque>

int main(void){
    Cin(int, n, m);
    vc<vc<int>> al(n);
    Rep(m){
        Cin(int, a, b);
        al[a-1].push_back(b-1);
    }
    
    vc<int> ans;
    For(i, n){
        deque<int> q;
        q.push_back(i);
        vc<int> v(n, -1);
        while(!q.empty()){
            int j = q.front();
            q.pop_front();
            for(int k : al[j]){
                if(k == i){
                    vc<int> p;
                    while(j != i) p.push_back(j+1), j = v[j];
                    p.push_back(i+1);
                    if(ans.empty() || p.size() < ans.size()) ans = p;
                    goto next;
                }
                if(v[k] == -1){
                    v[k] = j;
                    q.push_back(k);
                }
            }
        }
        next:;
    }
    
    if(ans.empty()){
        Cout(-1);
        return 0;
    }
    Cout(ans.size());
    for(int i : ans) Cout(i);
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0; i < N; i++){
        cin >> vec.at(i);
    }
    std::sort(vec.begin(),vec.end());
    int ans = 0;
    vec.push_back(1000);
    for(int i = 0; i < N; i++){
        if(vec.at(i) != vec.at(i+1)){
            ans++;
        }
    }
    cout << ans << endl;
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

ll de[100005];
ll d0[100005];

ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

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

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

    d0[2] = 1;
    de[2] = 1;
    d0[3] = 2;
    de[3] = 3;
    
    for (ll i = 4; i <= n; i++) {
        d0[i] = d0[i-1] * (i-1);
        d0[i] %= MOD;
        de[i] = d0[i-1] + de[i-1] * (i-1);
        de[i] %= MOD;
    }
    // rep(i, 10){
    //     cout << d0[i] << " " << de[i] << endl;
    // }


    ll ans = 0;
    rep(i, n-1){
        ll tmp = d0[n];
        tmp *= de[i+2];
        tmp %= MOD;
        tmp *= modpow(d0[i+2], MOD-2);
        tmp %= MOD;
        tmp *= (x[i+1]-x[i]);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }

    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 2560
def main():
    n = int(input())
    A = list(map(int, input().split()))
    round = lambda x: int((x * 2 + 1) // 2)
    m = round(sum(A) / len(A))
    ans = [(a - m) ** 2 for a in A]
    print(sum(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const long long inf = (long long)(2e18) + 322;
const int mod = (int)(1e9) + 7; // check modulo

int f[N];

void add(int i, int val) {
    for(;i < N; i += (i & -i)) f[i] += val;
}
int get(int i) {
    int re = 0;
    for(;i > 0; i -= (i & -i)) re += f[i];
    return re;
}

int a[N], ans[N];
vector <pair <int, int>> R[N];
list <int> pos[N];

void solve() {
    int n, q; cin >> n >> q;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        pos[a[i]].pb(i);
    }
    for(int i = 1; i <= q; ++i) {
        int l, r; cin >> l >> r;
        R[r].pb({l, i});
    }
    for(int i = 1; i <= n; ++i) {
        add(i, 1);
        if (pos[a[i]].front() != i) {
            add(pos[a[i]].front(), -1);
            pos[a[i]].pop_front();
        }
        for(auto it : R[i]) {
            ans[it.second] = (get(i) - get(it.first - 1));
        }
    }
    for(int i = 1; i <= q; ++i) cout << ans[i] << endl;

}

signed main () {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    int test = 1;//  cin >> test;
    for(int t = 1; t <= test; ++t) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 91184