akhauriyash/Code-Regression huggingface dataset:
// Written By NewbieChd
#include <iostream>
#include <iomanip>
#include <cmath>
// #define double long double
using namespace std;

const int maxN = 100003;
const double eps = 1e-8;
inline double absolute(double x) { return x >= 0 ? x : -x; }
inline double square(double x) { return x * x; }

struct Vector {
    double x, y;
    Vector() {}
    Vector(double x, double y) : x(x), y(y) {}
    friend Vector operator+(const Vector& a, const Vector& b) { return Vector(a.x + b.x, a.y + b.y); }
    friend Vector operator-(const Vector& a, const Vector& b) { return Vector(a.x - b.x, a.y - b.y); }
    friend Vector operator*(const Vector& a, const double& b) { return Vector(a.x * b, a.y * b); }
    friend Vector operator/(const Vector& a, const double& b) { return Vector(a.x / b, a.y / b); }
    inline double length() { return sqrt(square(x) + square(y)); }
    inline void read() { cin >> x >> y; }
    inline void write() { cout << fixed << setprecision(10) << x << ' ' << y << '\n'; }
};
inline double distance(Vector a, Vector b) { return sqrt(square(b.x - a.x) + square(b.y - a.y)); }
inline double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
inline double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }

inline Vector project(Vector a, Vector b, Vector c) {
    b = a - b;
    return b * (dot(b, c - a) / square(b.length())) + a;
}
inline Vector reflect(Vector a, Vector b, Vector c) {
    a = project(a, b, c);
    return a * 2 - c;
}

inline bool intersect(Vector a, Vector b, Vector c, Vector d) {
    if (max(min(a.x, b.x), min(c.x, d.x)) > min(max(a.x, b.x), max(c.x, d.x)) + eps || 
        max(min(a.y, b.y), min(c.y, d.y)) > min(max(a.y, b.y), max(c.y, d.y)) + eps || 
        cross(a - c, d - c) * cross(d - c, b - c) + eps < 0 || 
        cross(c - a, b - a) * cross(b - a, d - a) + eps < 0)
        return 0;
    return 1;
}

struct Line {
    double A, B, C;
    Line() {}
    Line(double A, double B, double C) : A(A), B(B), C(C) {}
};
inline Line getLine(Vector a, Vector b) { return Line(b.y - a.y, a.x - b.x, a.y * (b.x - a.x) - a.x * (b.y - a.y)); }
inline Vector crossPoint(Line a, Line b) {
    double tmp = a.A * b.B - a.B * b.A;
    return Vector((a.B * b.C - b.B * a.C) / tmp, (b.A * a.C - a.A * b.C) / tmp);
}

int main() {
    ios::sync_with_stdio(false);
    int Q;
    Vector a, b, c, d;
    for (cin >> Q; Q; --Q)
        a.read(), b.read(), c.read(), d.read(), crossPoint(getLine(a, b), getLine(c, d)).write();
    return 0;
}



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

int main()
{
	string s;
	int n;

	cin >> n >> s;

	for (int i = 1; i < n; ++i){
		string latte;
		cin >> latte;

		string ans = "";
		for (int j = 0; j < s.size(); ++j) {
			for (int k = 0; k < latte.size(); ++k) {
				if (s[j] == latte[k]) {
					ans += s[j];
					latte[k] = '0';
					break;
				}
			}
		}

		s = ans;
	}

	sort(s.begin(), s.end());

	cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N),y(M);
    for(int i = 0; i < N; i++) cin >> x[i];
    for(int j = 0; j < M; j++) cin >> y[j];
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    if(x[N-1] < y[0] && x[N-1] < Y && X < y[0]) cout << "No War" << endl;
    else cout << "War" << endl;
}

Measured memory_bytes: 256
main(){float a,b,c,d,e,f;for(;~scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f);printf("%.3f %.3f\n",(e*c-b*f)/(a*e-b*d)+0.0,(a*f-d*c)/(a*e-b*d)+0.0));exit(0);}

Measured memory_bytes: 648
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int N;
  string S;
  cin >>  N >> S;

  rep(i,S.size()){
      int index = S.at(i) - 'A';  //S[i]がアルファベット何番目か（0-indexed)
      index = (index + N) % 26;
      cout << char(index + 'A');
  }
  cout << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

const int N_MAX = 1e5;

int num[N_MAX+5];

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 0, a; i < n; i++) {
        cin >> a;
        if (a > n) ans++;
        else num[a]++;
    }
    for (int i = 1; i < N_MAX+5; i++) {
        if (num[i]) {
            if (i < num[i]) {
                ans += num[i] - i;
            } else if (i > num[i]) ans += num[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n , y = map(int , input().split())

c = 0

for i in range(n+1):
    for j in range(n-i+1):
        if (10000*i) + (5000*j) + (1000*(n-i-j)) == y:
            print(i , j , n-i-j)
            c = 1
            break
    if c == 1:
        break
        
if c != 1:
    print(-1 , -1 , -1)

Measured memory_bytes: 40684
n = int(input())
#a, b = map(int,input().split())
#l = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
count=0
mx=0
for i in range(n):
    d1,d2=map(int,input().split())
    if d1==d2:
        count+=1
    else:
        count=0
    mx=max(count,mx)
if mx>=3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9100
'use strict';
const main = input => {
  const n = parseInt(input[0], 10);
  input.shift();
  const p = input.map(val => parseInt(val, 10));
  p.pop();
  // console.log(n, p);
  p[p.indexOf(Math.max.apply(null, p))] /= 2;
  console.log(p.reduce((prev, current)  => prev + current));
  
  
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

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

  int v;
  // int v[N];
  vector<int> vec;
  REP(i, 0, N) {
    // cin >> v[i];
    cin >> v;
    vec.push_back(v);
  }
  sort(vec.begin(), vec.end(), greater<int>()); // 5,4,3,2,1 ...
  float sum = 0;
  REP(i, 0, N) {
    if(i == N-1){
      sum += (vec[i]) / (float)(pow(2.0, i));
    }
    else{
      sum += (vec[i]) / (float)(pow(2.0, i+1));
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

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

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

    vector<int> v;
    vector<int> w;
    REP(1, i, N + 1) {
        if (K % 2 == 0) {
            if (i % K == K / 2) {
                v.push_back(i);
            }
            if (i % K == 0) {
                w.push_back(i);
            }
        } else {
            if (i % K == 0) {
                v.push_back(i);
            }
        }
    }

    // for (vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
    //     cout << *it << endl;
    // }

    long len1 = v.size();
    long len2 = w.size();
    cout << len1 * len1 * len1 + len2 * len2 * len2 << endl;

    return 0;
}


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

N,K = list(map(int, input().rstrip().split()))
#-----

check_set = set()

x = N % K
x_min = x
check_set.add(x)


while True:
  x = abs(x - K)
  x_min = min(x_min, x)
  
  if x in check_set:
    break
  else:
    check_set.add(x)


print(x_min)


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

using namespace std;

void  bubleSort(int N, vector<pair<char,int> > &A) {
	int flag = 1;
	while (flag) {
		flag = 0;
		for (int i = N - 1; i > 0; i--) {
			if (A[i].second < A[i - 1].second) {
				swap(A[i], A[i - 1]);
				flag = 1;
			}
		}
	}
}

void selectionSort(int N, vector<pair<char, int> >& A) {
	for (int i = 0; i < N; i++) {
		int minj = i;
		for (int j = i + 1; j < N; j++) {
			if (A[j].second < A[minj].second) minj = j;
		}
		if (i != minj) {
			swap(A[i], A[minj]);
		}
	}
}

string is_stabele(int N, vector<pair<char, int> >A, vector<pair<char, int> >B) {
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			for (int a = 0; a < N; a++) {
				for (int b = a + 1; b < N; b++) {
					if (A[i].second == A[j].second && A[i] == B[b] && A[j] == B[a]) return "Not stable";
				}
			}
		}
	}
	return "Stable";
}

int main() {
	int N; cin >> N;
	vector<pair<char, int> > A(N),B(N),C(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
	B = A;	C = A;
	bubleSort(N, B);
	selectionSort(N, C);

	for (int i = 0; i < N-1; i++) {
		cout << B[i].first << B[i].second << " ";
	}
	cout << B[N - 1].first << B[N - 1].second << endl;
	cout << is_stabele(N, A, B) << endl;

	for (int i = 0; i < N - 1; i++) {
		cout << C[i].first << C[i].second << " ";
	}
	cout << C[N - 1].first << C[N - 1].second << endl;
	cout << is_stabele(N, A, C) << endl;






}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var v = int.Parse(Console.ReadLine());
            var perm = new Permutation();
            var array = Enumerable.Range(1, v).ToArray();
            var a = new int[v][];
            for (var i = 0; i < v; i++)
                a[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ans = 0D;
            var count = 0;
            foreach (var n in perm.Enumerate(array))
            {
                for (var i = 1; i < n.Length; i++)
                    ans += Math.Sqrt(Math.Pow(a[n[i]-1][0] - a[n[i - 1]-1][0], 2) + Math.Pow(a[n[i]-1][1] - a[n[i - 1]-1][1], 2));
                count++;
            }

            Console.WriteLine(ans / count);
        }

    }

    public class Permutation
    {
        public IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items)
        {
            return _GetPermutations<T>(new List<T>(), items.ToList());
        }

        private IEnumerable<T[]> _GetPermutations<T>(IEnumerable<T> perm, IEnumerable<T> items)
        {
            if (items.Count() == 0)
            {
                yield return perm.ToArray();
            }
            else
            {
                foreach (var item in items)
                {
                    var result = _GetPermutations<T>(perm.Concat(new T[] { item }),
                                                        items.Where(x => x.Equals(item) == false)
                                    );
                    foreach (var xs in result)
                        yield return xs.ToArray();
                }
            }
        }
    }
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 500030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
ll n;
ll arr[N];
ll b[N];
int main()
{
	ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
  cin>>n;
  rep(i,0,n)
  {
  	ll x;
  	cin>>x;
  	b[i+1] =x;
  	arr[x]++;
  }
  ll ans=0;
  for(ll i=1;i<=n;i++)
  {
  	ans+=(arr[i]*(arr[i]-1))/2;
  }
 // cout<<ans<<endl;
  for(ll i=1;i<=n;i++)
  {
  	cout<<ans-(arr[b[i]]*(arr[b[i]]-1))/2+((arr[b[i]]-1)*(arr[b[i]]-2))/2<<endl;
  }




}


Measured memory_bytes: 8320
import java.util.*;

public class Main{
	
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);
		
		int X =sc.nextInt();
		int min = 0;
		while(true) {
			
			boolean ans = Prime(X);
			
			if(ans == true) break;
			
			X++;
		}
		
		System.out.print(X);
		
		
		
	}
	static boolean Prime(int X) {
		int flag = 0;
		if(X == 2) {
			return true;
		}else {
			for(int i = 2; i < X; i++) {
				if(X % i == 0) {
					flag = 1;
					break;
				}
				
			}
			if(flag == 1) return false;
			
			return true;
		}
		
	}
	

}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

int main(){
  //type
  int N,M,C;
  cin >> N >> M >> C;

  vt<int> B(M);
  rep(i,M)
    cin >> B[i];

  vvi A(N,vt<int>(M));
  rep(i,N)
    rep(j,M)
      cin >> A[i][j];

  //solve
  int cnt = 0;
    rep(i,N){
      int total = 0;
      rep(j,M)
        total += A[i][j]*B[j];
      if(total + C > 0)
        cnt++;
    }

  cout << cnt << endl;

  return 0;
}


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

int main()
{
    int s;
    cin >> s;
    vector<int> a(100000);
    a[0] = s;
    bool finish = false;
    repl(i, 1, 100000) {
        if(a[i - 1] % 2 == 0) a[i] = a[i - 1] / 2;
        else a[i] = a[i - 1] * 3 + 1;
        rep(j, i) {
            if(a[i] == a[j]) {
                cout << i + 1 << endl;
                finish = true;
                break;
            }
        }
        if(finish) break;
    }
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N;
	scanf("%d",&N);

	int L[N];
	for(int i = 0; i < N; i++){
		scanf("%d",&L[i]);
		if(i > 0){
			L[i] += L[i-1];
		}
	}

	int length[N+1][N+1];

	for(int left = 0; left <= N-1; left++){
		for(int right = 1; right <= N; right++){
			if(left == 0){
				length[left][right] = L[right-1];
			}else{
				length[left][right] = L[right-1]-L[left-1];
			}
		}
	}

	int dp[N+1],ans = BIG_NUM;

	int min_length,value_1,value_2;

	for(int min_range_left = 0; min_range_left <= N-1; min_range_left++){
		for(int min_range_right = min_range_left+1; min_range_right <= N; min_range_right++){

			min_length = length[min_range_left][min_range_right];

			if((min_range_left > 0 && min_length > length[0][min_range_left]) ||
					(min_range_right <= N-1 && min_length > length[min_range_right][N]))continue;

				value_1 = value_2 = 0;

			if(min_range_left > 0){

				for(int right = 1; right <= min_range_left; right++)dp[right] = BIG_NUM;

				for(int right = 1; right <= min_range_left; right++){
					dp[right] = length[0][right];

					if(length[0][right] < min_length)continue;

					for(int mid = 1; mid <= right-1; mid++){
						if(length[0][mid] < min_length || length[mid][right] < min_length)continue;
						dp[right] = min(dp[right],max(dp[mid],length[mid][right]));
					}
				}

				value_1 = dp[min_range_left]-min_length;
			}

			if(min_range_right <= N-1){

				for(int right = min_range_right+1; right <= N; right++)dp[right] = BIG_NUM;


				for(int right = 1; right <= N; right++){
					dp[right] = length[min_range_right][right];

					if(length[min_range_right][right] < min_length)continue;

					for(int mid = 1; mid <= right-1; mid++){
						if(length[min_range_right][mid] < min_length || length[mid][right] < min_length)continue;
						dp[right] = min(dp[right],max(dp[mid],length[mid][right]));
					}
				}

				value_2 = dp[N]-min_length;
			}
			if(min_range_left != 0 || min_range_right != N){
				ans = min(ans,max(value_1,value_2));
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 3232
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		sc.close();
		
		if(s.length() >= 4 && s.substring(0, 4).contentEquals("YAKI")){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int MAXN = 100010;
long long fac[MAXN];
int main(){
    int n, m;
    cin >> n >> m;
    fac[0] = 1;
    for(int i =1; i <= max(n, m); i++){
        fac[i] = (fac[i - 1] * i) % mod;
    }
    if(abs(n - m) == 1){
        cout << (fac[n] * fac[m]) % mod;
    } else if(n == m){
        cout << (2 * fac[n] * fac[m]) % mod;
    }
    else cout << 0 << endl;
    return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if (s == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (s == "Cloudy") {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(i=1;i<=n;i++)
#define   FOR(i,a,b)      for(i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
LL n,i,j,ans = 0;
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL a,b ; 
    cin>>a>>b ; 
    if(b%a==0) cout<<a+b ; 
    else cout<<b-a ; 
}
//Check for 0,1 and other corner cases.

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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
std::string s;
int main()
{
	std::cin >> n >> s;

	std::string s1[] = { "S","W" };
	std::string s2[] = { "S","W" };

	std::string ans = "-1";
	for (int i = 0; i < 2; ++i)
		for (int j = 0; j < 2; ++j) {
			std::string res;

			res = s1[i] + s2[j];
			for (int k = 1, end = n - 1; k < end; ++k)
				if (res[k] == 'S' ? s[k] == 'o' : s[k] == 'x')
					res += res[k - 1];
				else
					res += (res[k - 1] == 'S' ? 'W' : 'S');
			int r1 = (res[1] == res[n - 1] ? 1 : -1);
			int r2 = (res[0] == res[n - 2] ? 1 : -1);
			int r3 = (res[0] == 'S' ? 1 : -1);
			int r4 = (res[n - 1] == 'S' ? 1 : -1);
			int r5 = (s[0] == 'o' ? 1 : -1);
			int r6 = (s[n - 1] == 'o' ? 1 : -1);
			if (r1*r3*r5 == 1 && r2*r4*r6 == 1) {
				ans = res;
				break;
			}
		}

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


Measured memory_bytes: 736
class Facts

  def initialize(mod=10**9+7, n_max=1)
    @mod = mod
    @n_max = n_max
    @fact = [1, 1]
    @inv = [0,1]
    @factinv = [1, 1]
    setup_table(n_max) if 1 < @n_max
  end

  def cmb(n,r)
    return 0 if r < 0 || n < r
    setup_table(n) if @n_max < n
    @fact[n] * (@factinv[r] * @factinv[n-r] % @mod) % @mod
  end

  def factorial(n)
    setup_table(n) if @n_max < n
    @fact[n]
  end

  def prm(n,k)
    setup_table(n) if @n_max < n
    @fact[n] * @factinv[n-k] % @mod
  end
  
  def hom(n,k)
    cmb(n+k-1, k)
  end

  private
    # O(t)
    def setup_table(t)
      (@n_max+1).upto(t) do |i|
        @fact.push( @fact[-1] * i % @mod )
        @inv.push( -@inv[@mod % i] * (@mod / i) % @mod )
        @factinv.push( @factinv[-1] * @inv[-1] % @mod )
      end
      @n_max = t
    end
end

mod = 10 ** 9 + 7

n, k = gets.to_s.split.map{|t|t.to_i}

ans = 0
f = Facts.new

if n <= k
  puts f.hom(n, n)
  exit
end

0.upto([n-1, k].min) do |i|
  ans += f.cmb(n, i) * f.hom(n-i, i)
  ans %= mod if ans >= mod
end

puts ans

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N, K;
	cin >> N >> K;
	
	vector< int > A(N);
	for_(i,0,N) cin >> A[i];
	sort(A.begin(), A.end());
	
	int g = A[0];
	for_(i,1,N) g = __gcd(g, A[i]);
	
	puts(K <= A[N-1] && K % g == 0 ? "POSSIBLE" : "IMPOSSIBLE");
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,m,cnt[101],b[101],i,j,temp,a;
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)break;
		for(i=1;i<=m;i++) cnt[i]=0,b[i]=i;
		for(i=0;i<n;i++){
			for(j=1;j<=m;j++){
				cin>>a;
				if(a==1) cnt[j]++;
			}
		}
		for(i=1;i<m;i++){
			for(j=i+1;j<=m;j++){
				if(cnt[i]<cnt[j]||cnt[i]==cnt[j]&&b[i]>b[j]){
					temp=cnt[i]; cnt[i]=cnt[j]; cnt[j]=temp;
					temp=b[i]; b[i]=b[j]; b[j]=temp;
				}
			}
		}
		for(i=1;i<m;i++) cout<<b[i]<<' ';
		cout<<b[m]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
//#include <ext/rope>

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define last(s) (s)[(int)((s).size())-1]
#define prelast(s) (s)[(int)((s).size())-2]
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define elif else if
#define left asdasd
#define next zaza
#define prev azaz
#define cclear cout<<flush;
#define x0 kerker
//#define time chas
#define y0 lolik
#define x1 ashkjl
#define y1 fakakaka
#define y2 ololol
#define x2 jejejejej
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("a.in", "r", stdin);freopen("a.out", "w", stdout);
#define ref svyazi
#define int long long
#define ii pair<int, int>
#define llong long long
#define ld long double
#define list spisok

const ld eps = 1e-12;
const ld Pi = acos(-1);
const int md = 1e9 + 7;

using namespace std;
//using namespace __gnu_cxx;


/*
*/


int n;
ld a[200];
ld sum;

int32_t main() {
    //kchay;

    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    sum /= (ld)n;
    int ans = 0;
    ld d = 1e18;
    for(int i = 0; i < n; i++) {
        if(d > fabs(sum - a[i])) {
            d = fabs(sum - a[i]);
            ans = i;
        }
    }

    cout << ans << endl;


    return 0;
}


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

int main()
{
   int n;
   cin >> n;
   vector<ll> a(n,0);
   rep(i,n) cin >> a[i];
   vvl dp(n+1,vector<ll>(n+1,0));

   for(int k = 1; k <= n; k++)
   {
      for(int i = 0; i+k <= n; i++)
      {
         int j = i+k;
         // 先手番
         if ((n - k) % 2 == 0)
               dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);

         // 後手番
         else
               dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
      }
   }

   // rep(i,n+1)
   // {
   //    rep(j,n+1) cout << dp[i][j] << " ";
   //    cout << endl;
   // }
   // 答え
   cout << dp[0][n] << endl;
}


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

using namespace std;

struct pay{
	int c[4], sum, num;
	bool operator<( const pay& right ) const {
        return sum == right.sum ? c[0] < right.c[0] : sum < right.sum;
    }
};

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	int cnt = 0;
	while(1) {
		vector<pay> p;
		int P, c[4];
		int coin[] = {10, 50, 100, 500};
		cin >> P;
		if( P == 0 ) break;

		if( cnt > 0 ) cout << endl;

		cin >> c[0] >> c[1] >> c[2] >> c[3];

		//支払い可能なパターンを全探索
		for(int i = 0; i <= c[0]; i++) {
			for(int j = 0; j <= c[1]; j++) {
				for(int k = 0; k<= c[2]; k++) {
					for(int l = 0; l <= c[3]; l++) {
						if( P <= i * 10 + j * 50 + k * 100 + l * 500 ) {
							pay np;
							np.c[0] = i;
							np.c[1] = j;
							np.c[2] = k;
							np.c[3] = l;
							np.num = i + j + k + l;
							np.sum = i * 10 + j * 50 + k * 100 + l * 500;
							p.push_back( np );
						}
					}
				}
			}
		}

		//つり銭の数
		vector<int> chg;
		for(int i = 0; i < p.size(); i++) {
			int num, tmp = 0;
			num = p.at(i).sum - P;
			
			for(int j = 3; j >= 0; j--) {
				tmp += num / coin[j];
				num %= coin[j];
			}

			chg.push_back(tmp);
		}

		//硬貨合計
		vector<int> coins;
		for(int i = 0; i < p.size(); i++) {
			int tmp = c[0] + c[1] + c[2] + c[3] - p.at(i).num + chg.at(i);
			coins.push_back( tmp );
		}

		int indx = 0, min = 1 << 10;
		for(int i = 0; i < p.size(); i++) {
			if( coins.at(i) < min ) {
				min = coins.at(i);
				indx = i;
			}
		}

		for(int i = 0; i < 4; i++) {
			if(  p.at(indx).c[i] == 0 ) continue;
			cout << coin[i] << " " << p.at(indx).c[i] << endl;
		}
		cnt ++;
	}

	//while(1){}

	return 0;
}

Measured memory_bytes: 7320
#include <iostream>
#include<vector>
#include<string>
using namespace std;
int gcd(int x,int y){
    if(x<y)swap(x,y);
    if(y==0) return x;
    return gcd(x%y,y);
}
int main()
{
    long long a,b,c,d;
    cin >>a>>b>>c>>d;
    long long sc=(a+c-1)/c;
    long long gc=b/c;
    long long sd=(a+d-1)/d;
    long long gd=b/d;
    long long e=(c*d)/gcd(c,d);
    long long se=(a+e-1)/e;
    long long ge=b/e;
    long long ac=gc-sc+1;
    long long ad=gd-sd+1;
    long long ae=ge-se+1;
    long long ans=(b-a+1)-(ac+ad-ae);
    cout << ans<< endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef signed long long int ll;
#define ALL(a)  (a).begin(),(a).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
    int n,m;
    cin>>n>>m;
    //ll a[110000],b[110000];
    vector<pair<ll, ll>> c(n);
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        c[i]=make_pair(a, b);
    }
    ll yen=0;
    ll have=0;
    sort(ALL(c));
    rep(i,n){
        if(have<m){
            if(m-have>c[i].second){
                yen+=c[i].second*c[i].first;
                have+=c[i].second;
            }else{
                yen+=c[i].first*(m-have);
                have=m;
                
                //cout<<yen<<" "<<have<<endl;
            }
            //cout<<yen<<" "<<have<<endl;
        }
    }
    cout<<yen;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] sArray = s.split("");
        String result = "";

        for (int i = 0; i < sArray.length; i++) {
            if ("0".equals(sArray[i])) {
                result += "0";
            } else if ("1".equals(sArray[i])) {
                result += "1";
            } else if ("B".equals(sArray[i])) {
                if ("".equals(result)) {
                    continue;
                }
                result = result.substring(0, result.length() - 1);
            }
        }
        System.out.println(result);
    }

}


Measured memory_bytes: 21844
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Mon Feb  4 13:14:12 2019
//
package main

import "fmt"

type pair struct {
	x, y int
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func (p pair) dist(q pair) int {
	return abs(p.x-q.x) + abs(p.y-q.y)
}

func main() {
	var H, W, D int
	fmt.Scan(&H, &W, &D)

	nums := make([]pair, H*W)
	for i := 1; i <= H; i++ {
		for j := 1; j <= W; j++ {
			var n int
			fmt.Scan(&n)
			nums[n-1].x = i
			nums[n-1].y = j
		}
	}

	dists := make([]int, H*W)
	for i := 0; i < D; i++ {
		for j := i + D; j < len(dists); j += D {
			dists[j] = dists[j-D] + nums[j].dist(nums[j-D])
		}
	}

	var Q int
	fmt.Scan(&Q)
	for i := 0; i < Q; i++ {
		var l, r int
		fmt.Scan(&l, &r)
		fmt.Println(dists[r-1] - dists[l-1])
	}
}


Measured memory_bytes: 7556
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int inf=1e18;
int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("in","r", stdin);
		freopen("out","w",stdout);
	#endif

	int n,d,a;
	cin>>n>>d>>a;
	vector<pair<int,int>> p(n);
	for(int i=0;i<n;i++)
	{
		cin>>p[i].first>>p[i].second;
	}
	sort(p.begin(),p.end());
	int sum=0,res=0;
	queue<pair<int,int>> q;
	for(int i=0;i<n;i++)
	{
		while(!q.empty() and q.front().first<p[i].first)
		{
			sum-=q.front().second;
			q.pop();
		}

		p[i].second-=a*sum;
		if(p[i].second<=0)continue;
		int tmp=(p[i].second+a-1)/a;
		res+=tmp;
		q.push({p[i].first+2*d,tmp});
		sum+=tmp;
	}
	cout<<res<<'\n';


}

Measured memory_bytes: 7908
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>
#define fr first
#define se second

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=200000;
const long double PI = acos(-1);

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


ll A[N + 5];
ll n;
ll cum[N + 5];
ll calc(ll b)
{
  // A[i] <= b
  auto xx = upper_bound(A+1,A+n+1,b);
  ll pos = (xx - A) - 1;
  ll ret = b*pos - cum[pos];
 
  ret+= cum[n] - cum[pos] - b*(n - pos);
  return ret;

}
int main()
{
  finp;
 
  cin>>n;
  afor(i,1,n)
  {
    cin>>A[i];
    A[i]-= i;
  }
  sort(A+1,A+n+1);
  afor(i,1,n)
  {
    cum[i] = cum[i-1] + A[i];
  }
  ll ans= inf;

  afor(i,1,n)
  {
    ans = min(ans,calc(A[i]));
  }
  cout<<ans;
return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>

int main()
{


    char date[5];
    int f1,f2;
    scanf("%s",date);
    f1 = ((int)date[0] - '0')*10 + (int)date[1] - '0';
    f2 = ((int)date[2] - '0')*10 + (int)date[3] - '0';

    if(f1>0 && f1<13 && f2>0 && f2<=12){
        printf("AMBIGUOUS\n");
    }
    else if(f2>0 && f2<=12){
        printf("YYMM\n");
    }
    else if(f1>0 && f1<=12){
        printf("MMYY\n");
    }
    else{
        printf("NA\n");
    }


}


Measured memory_bytes: 128
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

ll a[10]={0};
ll f[10]={0};
ll s,c;
void solve(){
	ll n,m;
	cin>>n>>m;
	rep(i,0,m){
		cin>>s>>c;
		s--;
		if(f[s]==0){
			a[s] = c;
			f[s] = 1;
		}else{
			if(a[s]!=c){
				cout<<-1;
				return ;
			}
		}
	}
	if(f[0]==0&&n>1)a[0] = 1;
	if(a[0]==0&&n>1){
		cout<<-1;
	}else{
		
		rep(i,0,n)cout<<a[i];
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	int a,b,c;
	a=n/60/60;
	b=n/60%60;
	c=n%60;
	printf("%d:%d:%d\n",a,b,c);
	return 0;
}


Measured memory_bytes: 3212
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define SIZE 200010

using namespace std;

int n;
int dis[SIZE];
bool vis[SIZE];
vector<int> rec[SIZE];

struct d
{
    int id,dist;
};
int bfs(int from)
{
    int i;
    d tmp;
    queue<d> que;
  //  dis[from]=0;
    que.push({from,1});
    vis[from]=true;
    while(!que.empty())
    {
        tmp=que.front();
    //    printf("id=%d\n",tmp.id);
        que.pop();
        dis[tmp.id]=tmp.dist;
        for(i=rec[tmp.id].size()-1;i>=0;i--)
        {
            if(!vis[rec[tmp.id][i]])
            {
                vis[rec[tmp.id][i]]=true;
                que.push({rec[tmp.id][i],tmp.dist+1});
            }
        }
    }
    return tmp.id;
}

int main()
{
    int i;
    int a,b;
    scanf("%d",&n);
    for(i=1;i<n;i++)
    {
        scanf("%d%d",&a,&b);
        rec[a].push_back(b);
        rec[b].push_back(a);
    }
    int pos=bfs(1);
    memset(vis,false,sizeof(vis));
    pos=bfs(pos);
    if((dis[pos]+1)%3==0)
        puts("Second");
    else
        puts("First");
    return 0;
}


Measured memory_bytes: 14604
while true do
	n = STDIN.gets.chomp.to_i
	break if n == 0
    s = STDIN.gets.chomp.split(" ")
    
    sum = 0

	0.upto(n - 1) { |i|
		s[i] = s[i].to_f
		sum += s[i]
	}
	
	ave = sum / n
	
	sum2 = 0
	0.upto(n - 1) { |i|
		sum2 += (s[i] - ave) ** 2 / n
	}
	
	print Math.sqrt(sum2), "\n"

end



Measured memory_bytes: 6932
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  int in(n);
  int list_input(a, n);
  int list_input(b, n);
  int list_input(c, n);
  sort(a, a + n);
  sort(b, b + n);
  sort(c, c + n);

  long long result = 0;
  forin(b_target, b) {
    int a_target = distance(a, lower_bound(a, a + n, b_target));
    if(a_target == -1) continue;
    int c_target = n - distance(c, lower_bound(c, c + n, b_target + 1));
    if(c_target == -1) continue;
    result += (long long)a_target * (long long)c_target;
  }
  out(result);
}


Measured memory_bytes: 1536
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public static int N;
	public static Set<Integer> availablenum;
	void run() {
		Scanner sc = new Scanner(System.in);

		N = sc.nextInt();
		int K = sc.nextInt();

		availablenum=new HashSet<Integer>();


		for (int i = 0; i < K; i++) {
			availablenum.add(sc.nextInt());
		}

		while(!isValid(N++)) {
		}

		N--;

		System.out.println(N);

	}

	public static boolean isValid(int N) {


		while(N>0) {

			int lastdigit=N%10;

			if(availablenum.contains(lastdigit)) {
				return false;
			}

			N/=10;

		}

		return true;

	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

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

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


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

using namespace std;

const int mod = 1e+9 + 7;
#define debug(x) cout << #x << "==" << x << endl;
typedef long long ll;

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

  int N;
  cin >> N;

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

  bool up = true;
  int li = 0, ri = 0;
  int cnt  = 0;

  while(ri < N) {

    cnt++;

    while( ri < N and a[li]  == a[ri] ) { ri++; }

    if( ri >= N ) break;

    if( a[li] <= a[ri] ){
      up = true;
    } else {
      up = false;
    }

    if( up ) {
      while( ri < N and a[ri-1] <= a[ri] ) { ri++;  }
    } else {
      while( ri < N and a[ri-1] >= a[ri] ) { ri++; }
    }

    li = ri;
  }

  cout << cnt << "\n";

  return 0;

}



Measured memory_bytes: 640
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    s = input().rstrip()
    len_s = int(len(s))
    children = [0] * len_s
    s += "E"
    start = 0
    now = 0
    while now < len_s-1:
        r = 0
        l = 0
        while s[now] == "R":
            r += 1
            now += 1
        er = now - 1
        sl = now
        while s[now] == "L":
            l += 1
            now += 1
        count = now - start
        if count % 2 == 0:
            children[er] = count // 2
            children[sl] = count // 2
        else:
            if r % 2 == 1:
                children[er] = count // 2 + 1
                children[sl] = count // 2
            else:
                children[er] = count // 2
                children[sl] = count // 2 + 1
        start = now

    print(*children)

    return

main()


Measured memory_bytes: 10844
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int dp[1007][1007][2], c[1000], n, m; vector<int>x[1000]; bool used[1000];
int solve(int s, int t, int u) {
	if (s + t == 1)return 1;
	if (dp[s][t][u] >= 0)return dp[s][t][u];
	int minx = 1;
	if (s >= 2)minx = min(minx, solve(s - 2, t + 1, u));
	if (s >= 1 && t >= 1)minx = min(minx, solve(s, t - 1, (u + 1) % 2));
	if (t >= 2)minx = min(minx, solve(s, t - 1, (u + 1) % 2));
	if (u == 1)minx = min(minx, solve(s, t, u - 1));
	dp[s][t][u] = 1 - minx;
	return 1 - minx;
}
int main() {
	cin >> n; n++; for (int i = 0; i < n*n; i++) { dp[i / n][i%n][0] = -1; dp[i / n][i%n][1] = -1; }n--;
	for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { char c; cin >> c; if (c == 'Y') { x[i].push_back(j); m++; } } }
	queue<int>Q; int cnt = 0, r = 0; m /= 2;
	for (int i = 0; i < n; i++) {
		if (used[i] == true)continue; Q.push(i); used[i] = true;
		while(!Q.empty()) {
			int a1 = Q.front(); Q.pop(); c[cnt]++;
			for (int j : x[a1]) { if (used[j] == false) { Q.push(j); used[j] = true; } }
		}
		r += (c[cnt] - 1)*c[cnt] / 2; cnt++;
	}
	int B1 = 0, B2 = 0; for (int i = 0; i < cnt; i++) { if (c[i] % 2 == 1)B1++; else B2++; }
	int ret = solve(B1, B2, (r - m) % 2);
	if (ret == 1)cout << "Taro" << endl;
	else cout << "Hanako" << endl;
	return 0;
}

Measured memory_bytes: 11040
def insertionSort(A, N):
    for i in range(1, N):
        print(*A, sep=" ")
        
        v = A[i]
        j = i - 1

        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1

        A[j+1] = v

    print(*A, sep=" ")

    return A



N = int(input())

list_num = list(map(int, input().split()))

insertionSort(list_num, N)



Measured memory_bytes: 5980
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto n = lread();
    auto tmp = new long[](10 ^^ 5);
    foreach (i; 1 .. 101)
    {
        foreach (j; 1 .. 101)
        {
            foreach (k; 1 .. 101)
            {
                long tmptmp;
                tmptmp = i ^^ 2 + j ^^ 2 + k ^^ 2 + i * j + i * k + j * k;
                if (tmptmp <= 10 ^^ 4)
                {
                    tmp[tmptmp] += 1;
                }
            }
        }
    }
    foreach (i; 1 .. n + 1)
    {
        writeln(tmp[i]);
    }
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 4208
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

constexpr ll mod = 1000000007LL;

// aのb乗を求める.
ll modpow(ll a, ll b) {
	if (a > mod) a %= mod;
	if (b == 0LL) return 1LL;
	ll tmp = modpow(a, b / 2);
	if (b & 1LL)
		return tmp * tmp % mod * a % mod;
	return tmp * tmp % mod;
}

// aの逆元を求める.
ll inverse(ll a) {
	return modpow(a, mod - 2);
}

// kの階乗を計算する.(sgnを0以外に設定すると逆元を返す)
ll fact(ll k, int sgn = 0) {
	static vector<ll> fac(2, 1LL);
	static vector<ll> inv(2, 1LL);
	static vector<ll> finv(2, 1LL);
	static ll nx = 2LL;
	while (nx <= k) {
		fac.push_back(fac[nx - 1] * nx % mod);
		inv.push_back(mod - inv[mod % nx] * (mod / nx) % mod);
		finv.push_back(finv[nx - 1] * inv[nx] % mod);
		++nx;
	}
	if (sgn == 0)
		return fac[k];
	return finv[k];
}

// aCbを計算する.
ll comb(ll a, ll b) {
	if (b < 0 || b > a) return 0;
	return fact(a) * fact(b, 1) % mod * fact(a - b, 1) % mod;
}


int main(void){
    int K; cin >> K;
    string S; cin >> S;
    int s_sz = S.length();
    ll res = 1;
    for (int i = 1; i <= K; ++i)
        res = (res * 26 % mod + comb(s_sz + i - 1, s_sz - 1) * modpow(25, i) % mod) % mod;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 51288
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, x: usize, y: usize);
    if y % 2 == 1 || y / 2 < x || 2 * x < y / 2 {
        println!("{}", "No");
    } else {
        println!("{}", "Yes");
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2156
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n,a,b;
cin>>n>>a>>b;

ol(min(n*a,b));
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    string s1, s2;
    cin >> s1 >> s2;
    vector<vector<int>> dp(s1.size() + 1, vector<int>(s2.size() + 1, -1));
    rep(i, s1.size() + 1)dp[i][0] = 0;
    rep(i, s2.size() + 1)dp[0][i] = 0;
    for(int i = 1; i <= s1.size(); i++){
        for(int j = 1; j <= s2.size(); j++){
            if(s1[i - 1] == s2[j - 1])dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    // rep(i, s1.size() + 1){
    //     rep(j, s2.size() + 1)cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    int s1now = s1.size();
    int s2now = s2.size();
    vector<char> ans(dp[s1.size()][s2.size()]);
    int index = ans.size() - 1;
    while(dp[s1now][s2now] != 0){
        if(dp[s1now][s2now] != dp[s1now - 1][s2now] && dp[s1now][s2now] != dp[s1now][s2now - 1]){
            ans[index] = s1[s1now - 1];
            s1now--;
            s2now--;
            index--;
        }else if(dp[s1now][s2now] == dp[s1now - 1][s2now]){
            s1now--;
        }else s2now--;
    }
    rep(i, ans.size())cout << ans[i];
    cout << endl;
}

Measured memory_bytes: 38628