akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  queue<long long int> lunlun;
  for(int i = 1; i < 10; ++i) lunlun.push(i);
  int count = 0;
  long long int ans;
  while(count != k){
    ans = lunlun.front();
    if(ans % 10 != 0) lunlun.push(10 * ans + ans % 10 - 1);
    lunlun.push(10 * ans + ans % 10);
    if(ans % 10 != 9) lunlun.push(10 * ans + ans % 10 + 1); 
    count++;
    lunlun.pop();
  }
  cout << ans << endl;
}
 

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
  
#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define treap_pair pair<treap*, treap*>
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, ll> mll;
  
const int N = 1e5 + 2;
const int M = 1e5 + 2;
const int mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18 + 100;

  
void data() {
    #ifdef PC
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif	
}

template <typename T>
void scerr(T nums) {
    for (auto it : nums)
        cerr << it << " | ";
    cerr << "\n";
}

int n, a[N], b[N], c[N], dp[N][3];

int main() {
	data();
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
	dp[1][0] = a[1];
	dp[1][1] = b[1];
	dp[1][2] = c[1];
	for (int i = 2; i <= n; ++i) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i];
	}
	printf("%d", max(dp[n][0], max(dp[n][1], dp[n][2])));
}
  
/*
    Timus: 288481RF
    CodeForces: fractal
*/


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[100001];
ll ans[100001];
int main()
{   
	ll i,n,k,j,t;
	scanf("%lld%lld",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%lld",&a[i]);
    ans[n]=0;
    ans[n-1]=abs(a[n]-a[n-1]); 
    for(i=n-2;i>=1;i--)
    {   
    	t=1000000000000000;
    	for(j=1;j<=k;j++)
    	if(i+j<=n)
            t=min(t,abs(a[i+j]-a[i])+ans[i+j]);
        ans[i]=t;
    }
	printf("%lld\n",ans[1]);
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
/*        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
        int b = int.Parse(input[2]);*/
//        string temp = ReadLine();
        int a = int.Parse(ReadLine());
        int b = int.Parse(ReadLine());
        WriteLine(b*2-a);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <class T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N;
    ll C;
    cin >> N >> C;

    vector<ll> x(N), v(N);
    vector<ll> formax(N + 1), forpos(N + 1);
    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> v[i];
        formax[i + 1] = formax[i];
        forpos[i + 1] = forpos[i];
        ll tmp = (i > 0 ? x[i] - x[i - 1] : x[i]);
        sum += v[i] - tmp;
        if (sum > 0) {
            formax[i + 1] += sum;
            forpos[i + 1] = x[i];
            sum = 0;
        }
    }

    ll ans = max<ll>(0, formax[N]), revmax = 0, revpos = 0;
    sum = 0;
    for (int i = N - 1; i >= 0; --i) {
        ll tmp = (i + 1 < N ? x[i + 1] - x[i] : C - x[i]);
        sum += v[i] - tmp;
        if (sum > 0) {
            revmax += sum;
            revpos = C - x[i];
            sum = 0;
        }
        ans = max(ans, revmax + formax[i] - min(revpos, forpos[i]));
    }

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


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


int main() {
	int n;
	cin >> n;
	vector<string>A(n);
	rep(i, n) {
		cin >> A[i];
	}
	string ans = "Three";
	rep(i, n) {
		if (A[i] == "Y")ans="Four";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s,t;
  
  cin >> s >> t;
  int i;
  string u="Yes";
  for(i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i)){
      u="No";
    }
  }
  cout << u;
}

Measured memory_bytes: 3628
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.buffer.readline

    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.root = [-1] * (n + 1)
            self.rnk = [0] * (n + 1)

        def find_root(self, x):
            while self.root[x] >= 0:
                x = self.root[x]
            return x

        def unite(self, x, y):
            x = self.find_root(x)
            y = self.find_root(y)
            if x == y:
                return
            elif self.rnk[x] > self.rnk[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rnk[x] == self.rnk[y]:
                    self.rnk[y] += 1

        def isSameGroup(self, x, y):
            return self.find_root(x) == self.find_root(y)

        def size(self, x):
            return -self.root[self.find_root(x)]

    N, M, K = map(int, input().split())
    UF = UnionFind(N+1)
    fr_num = [0] * (N+1)
    for _ in range(M):
        a, b = map(int, input().split())
        UF.unite(a, b)
        fr_num[a] += 1
        fr_num[b] += 1

    ans = [0] * (N+1)
    for i in range(1, N+1):
        ans[i] = UF.size(i) - 1 - fr_num[i]

    for _ in range(K):
        c, d = map(int, input().split())
        if UF.isSameGroup(c, d):
            ans[c] -= 1
            ans[d] -= 1
    print(*ans[1:])


if __name__ == '__main__':
    main()


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

main(){

  ll n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];

  map<ll,ll> mp;
  for(auto x:a)mp[x]++;

  ll two=-1,res=0;
  for(auto x:mp){
    if(x.second>=4){
      ll t = x.first*x.first;
      if(two<x.first)two=x.first;
      else t = max(t,two*x.first);
      res = max(res,t);
    }
    if(x.second>=2){
      if(two!=-1){
        ll t = two*x.first;
        two = max(two,x.first);
        res = max(res,t);
      }else{
        two = x.first;
      }
    }
  }
  cout<<res<<endl;

}

Measured memory_bytes: 7296
e=Hash.new [];$<.each{|s|s.split.map{|v|e[v]+=[$.-2]}};n=$.;a=[0]*(n-1);(1..n).map{|w|u={};e[v=w.to_s].map{|j|u[a[j]]=1};t=1;e[v].map{|j|1>a[j]&&(t+=1until$\==u[t];a[j]=t;t+=1)}};p a.max;$><<a*$/

Measured memory_bytes: 192032
#include <stdio.h>

int main(){
    int v[10];
    int i, j, k, l;
    int num1, num2, num3;
    int max1 = 0, max2 = 0, max3 = 0;
    
    for (i = 0; i < 10; i++){
        scanf("%d", &v[i]);
    }
    
    for (j = 0; j < 10; j++){
        if (max1 < v[j]){
            max1 = v[j];
            num1 = j;
        }
    }
    
    for (k = 0; k < 10; k++){
        if (k == num1) continue;
        if (max2 < v[k]){
            max2 = v[k];
            num2 = k;
        }
    }
    
    for  (l = 0; l < 10; l++){
        if (l == num1 || l == num2) continue;
        if (max3 < v[l]) max3 = v[l];
    }
    
    printf("%d\n%d\n%d\n", max1, max2, max3);
    
    return 0;
}

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


int main()
{
	int y,m,d;  char c1,c2;
	
	cin>>y>>c1>>m>>c2>>d;
	
	if(m<=4){
		cout<<"Heisei"<<endl;
	}
	
	else  
	cout<<"TBD"<<endl;
	
}



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

using namespace std;

int main(void){
  int N, M, X;
  cin >> N >> M >> X;
  int l = 0, r = 0;
  for(int i = 0; i < M; i++){
    int A;
    cin >> A;
    if(A < X) l++;
    else r++;
  }
  cout << min(l, r) << endl;
}


Measured memory_bytes: 256
// AOJ 0189 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0189)
#include<cstdio>
#include<algorithm>
#include<numeric>
#include<limits>
#define rep(i,a) for(int i=0;i<(a);++i)

typedef std::pair<int, int> P;

const int MAX_N = 10, INF = std::numeric_limits<int>::max()>>4;

int d[MAX_N][MAX_N];

int main()
{
	int n;
	while( scanf( "%d", &n ), n )
	{
		rep( i, MAX_N ) rep( j, MAX_N )
			d[i][j] = i==j?0:INF;

		rep( i, n )
		{
			int a, b, c;
			scanf( "%d%d%d", &a, &b, &c );
			d[a][b] = d[b][a] = c;
		}

		rep( k, MAX_N ) rep( i, MAX_N ) rep( j, MAX_N )
			d[i][j] = std::min( d[i][j], d[i][k]+d[k][j] );

		P ans( INF, INF );
		rep( i, MAX_N )
		{
			int s = 0;
			rep( j, MAX_N ) if( d[i][j] != INF )
				s += d[i][j];

			if( s )
				ans = std::min( ans, P( s, i ) );
		}

		printf( "%d %d\n", ans.second, ans.first );
	}

	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int p[] = new int[n];
		for(int i=0; i<n;i++) {
			p[i] = sc.nextInt();
		}

		Arrays.sort(p);

		int x = 0;
		
		for(int i=0; i<k; i++) {
			x += p[i];
		}

		System.out.println(x);

	}
	
}


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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 59;
const int mod = 1e9 + 7;


int N, K;
int A[100000];
int dp[100001];

bool rec(int rest) {
  if(~dp[rest]) return dp[rest];
  for(int i = 0; i < N; i++) {
    if(rest - A[i] < 0) continue;
    if(!rec(rest - A[i])) return dp[rest] = true;
  }
  return dp[rest] = false;
}

int main() {
  cin >> N >> K;
  for(int i = 0; i < N; i++) cin >> A[i];
  memset(dp, -1, sizeof(dp));
  if(rec(K)) cout << "First\n";
  else cout << "Second\n";
}




Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){

	string str;
	while(1){
		getline(cin,str);
		if(str=="END OF INPUT"){
			break;
		}
		int cnt=0;
		for(int i = 0; i < str.size(); i++){
			if(i == str.size()-1)
				cout << cnt+1 << endl;
			else if(str[i]==' '){
				cout << cnt;
				cnt=0;
			}
			else{
				cnt++;
			}
		}

	}

	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
    long long A;
    long double B;
    cin >> A >> B;
    cout << (long long)(A * B + 0.001) << endl;
}

Measured memory_bytes: 3676
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int L, N;

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

	if(L+N-1<0){
		cout << (N-1)*(2*L+N-2)/2 << endl;
	} else if(L<0){
		cout << N*(2*L+N-1)/2 << endl;
	} else {
		cout << (N-1)*(2*L+N)/2 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

//-------- Union Find
struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
	    x = root(x); y = root(y);
        if(x != y) {
            if(data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
	}
	bool findSet(int x, int y) {
	    return root(x) == root(y);
    }
	int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

signed main() {
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    REP(i,m) {
        int a,b;
        cin>>a>>b;
        uf.unionSet(a,b);
    }

    int q;
    cin>>q;
    REP(i,q) {
        int a,b;
        cin>>a>>b;
        if(uf.root(a)==uf.root(b)) {
            cout<<"yes"<<endl;
        }
        else {
            cout<<"no"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3104
n = int(input())
t = [[] for _ in range(n)]

for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        x -= 1
        t[i].append([x, y])

ans = 0
for p in range(1 << n):
    cnt = 0
    is_not = False
    for i in range(n):
        if p >> i & 1:
            cnt += 1
            for ti in t[i]:
                x, y = ti
                if (p >> x & 1) != y:
                    is_not = True
                    cnt = 0
                    break
        if is_not:
            break
    ans = max(ans, cnt)
print(ans)


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;

int N, M, Q, A, B, C, X, Y, Z;
string s, t;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> X >> Y >> Z;
	cout << Z << ' ' << X << ' ' << Y << '\n';
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
using namespace std;
using namespace std::string_literals;

static void solve(const int n, const string &s, const char ch_max) {
    if (s.length() == n) {
        cout << s << "\n";
        return;
    }

    for (char ch = 'a'; ch <= ch_max; ch++) {

        solve(n, s + ch, ch_max + (ch == ch_max ? 1 : 0));
    }
}

int main() {
    int n;
    cin >> n;
    solve(n, ""s, 'a');
    return 0;
}


Measured memory_bytes: 1536
#include<cstdio>
#include<algorithm>
using namespace std;

bool chk(int x,int y,int z){
    int q=min(min(x,y),z);
    return (x==q)+(y==q)+(z==q)>=2 and abs(max(max(x,y),z)-q)<=1;
}

int main(){
    int a,b,c,p,rs=1;
    scanf("%d %d %d",&a,&b,&c);
    while(!chk(a,b,c)){
        p=min(min(a,b),c);
        if(p==a)a+=2;
        else if(p==b)b+=2;
        else c+=2;
        //printf("%d %d %d\n",a,b,c);
        rs++;
    }
    
    printf("%d\n",rs-(a==b and b==c));
    return 0;
}


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

int main(){

   ll n;
   cin>>n;
   ll a[n+5];
   for(int i=0; i<n; i++)
    cin>>a[i];
   ll mx=a[0];
   ll sum=0;
   for(int i=1; i<n; i++){
        if(a[i]<mx){
            sum+=(mx-a[i]);
        }
        else{
            mx=a[i];
        }
        //cout<<sum<<endl;
   }
   cout<<sum<<endl;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// aのb乗(MODした)を返す。
ll modpow(ll a, ll b, ll mod = 1000000007) {
  ll res = 1;
  for (a %= mod; b; a = a * a % mod, b >>= 1)
    if (b & 1) res = res * a % mod;
  return res;
}

const long long MAX = 300000;  // 最大を決めておく
// fac…階乗、inv…逆数、finv…逆数の累積積
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理、先にやっておく
void nCr_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// nCrを計算する (前処理は忘れないように)
long long nCr(int n, int r) {
  if (n < r) return 0;
  if (n < 0 || r < 0) return 0;
  return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

// mを法としたaの逆元を返します
long long modinv(long long a, long long m = 1000000007) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// ====================================================================

int main() {
  nCr_init();
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = (modpow(2, n) + MOD - 1) % MOD;

  ll ma = 1, na = 1;
  for (int i = 1; i <= a; i++) {
    ma = ma * i % MOD;
    na = na * (n - i + 1) % MOD;
  }

  ll mb = 1, nb = 1;
  for (int i = 1; i <= b; i++) {
    mb = mb * i % MOD;
    nb = nb * (n - i + 1) % MOD;
  }

  na = na * modinv(ma) % MOD;
  nb = nb * modinv(mb) % MOD;

  ans = (ans + MOD - na) % MOD;
  ans = (ans + MOD - nb) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x, ans = n, MIN = INF, sum = 0;
    cin >> n >> x;
    rep(i, 0, n){
        int in;
        cin >> in;
        sum += in;
        chmin(MIN, in);
    }
    cout << n + (x - sum) / MIN << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll N, A[200000], B[200000];

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

  vector<ll> va(N), vb(N);
  REP(i, 0, N) va[i] = A[i];
  REP(i, 0, N) vb[i] = B[i];

  sort(va.begin(), va.end());
  sort(vb.begin(), vb.end());

  ll ans1 = 0;
  REP(i, 0, N) {
    ll p = upper_bound(vb.begin(), vb.end(), A[i]) - vb.begin();
    ll q = va.end() - lower_bound(va.begin(), va.end(), B[i]);
    ans1 = max(ans1, N - p - q);
  }

  vector<ll> imos(200001, 0);
  REP(i, 0, N) {
    imos[A[i]]++;
    imos[B[i]]--;
  }
  REP(i, 0, 200000) imos[i + 1] += imos[i];
  ll ans2 = 0;
  REP(i, 0, 200000) ans2 = max(ans2, imos[i]);

  cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 10760
//"I'll live the focused life, because it's the best kind there is" - Winifred Gallagher
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl

int main(){
	cin.tie(0);	ios::sync_with_stdio(false);
	int n; cin>>n;
	if(n % 2 == 0){
		cout<<n/2;
	}
	else cout<<n/2 + 1;
}


Measured memory_bytes: 256
//By Tushar Gautam
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln "\n"
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
int main(){
	fastio;
	cin>>n>>k;
	int h[n]; 
	forn(i,n) cin>>h[i];
	int dp[n];
	dp[0]=0;
	forsn(i,1,n){
		dp[i] = dp[i-1]+ abs(h[i]-h[i-1]);
		forsn(j,2,k+1){
			if(i-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[n-1]<<ln;
	return 0;
}

Measured memory_bytes: 1024
// 17:05 - 17:14
#include <algorithm>
#include <iostream>
#include <vector>

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

using P = std::pair<int, int>;

// struct Job {
//   int a, b;
// };
//
// bool comp(const Job &j1, const Job &j2) { return j1.b < j2.b; }

int main() {
  int n;
  std::cin >> n;
  // Job jobs[n];
  std::vector<P> tasks(n);

  // rep(i, n) { std::cin >> jobs[i].a >> jobs[i].b; }
  rep(i, n) { std::cin >> tasks[i].second >> tasks[i].first; }

  // std::sort(jobs, jobs + n, comp);
  std::sort(tasks.begin(), tasks.end());

  int sum = 0;
  rep(i, n) {
    sum += tasks[i].second;
    if (sum > tasks[i].first) {
      std::cout << "No" << '\n';
      return 0;
    }
  }

  std::cout << "Yes" << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int NMAX = 505;
const int MMAX = 200005;

struct Data {
    int x, y;
    bool operator< (Data other) const {
        if(x == other.x)
            return y < other.y;
        return x < other.x;
    }
}v[MMAX];

struct Query {
    int x, y, ind;
    bool operator< (Query other) const {
        if(x == other.x)
            return y < other.y;
        return x < other.x;
    }
}t[MMAX / 2];

int aint[4 * NMAX];

void update(int toadd, int pos ,int node, int le, int ri) {
    if(le == ri)
        aint[node] += toadd;
    else {
        int mid = (le + ri) / 2;
        if(pos <= mid)
            update(toadd, pos, node * 2, le, mid);
        else
            update(toadd, pos, node * 2 + 1, mid + 1, ri);
        aint[node] = aint[node * 2] + aint[node * 2 + 1];
    }
}

int query(int from, int to, int node, int le, int ri) {
    if(from <= le && ri <= to)
        return aint[node];
    int mid = (le + ri) / 2;
    int ans = 0;
    if(from <= mid)
        ans += query(from, to, node * 2, le, mid);
    if(mid < to)
        ans += query(from, to, node * 2 + 1, mid + 1, ri);;
    return ans;
}

int sol[MMAX / 2];

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

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 1; i <= m ; i ++)
        cin >> v[i].x >> v[i].y;
    sort(v + 1, v + m + 1);
    for(int i = 1; i <= m; i ++)
        update(1, v[i].y, 1, 1, n);

    for(int i = 1; i <= q; i ++) {
        cin >> t[i].x >> t[i].y;
        t[i].ind = i;
    }
    sort(t + 1, t + q + 1);

    int i = 1;
    for(int test = 1; test <= q; test ++) {
        while(v[i].x < t[test].x && i <= m) {
            update(-1, v[i].y, 1, 1, n);
            i ++;
        }
        int ans = query(1, t[test].y, 1, 1, n);
        sol[t[test].ind] = ans;
    }
    for(int i = 1; i <= q; i ++)
        cout << sol[i] << "\n";
    return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
 
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main(void){
  string S;
  int cnt = 0;
  cin >> S;
  rep(i,3){
    if(S.at(i) == 'R'){
      cnt++;
    }
  }
  if(cnt==2){
    if(S=="RSR"){
      cnt = 1;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3592
import sys
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

def main():
    input = sys.stdin.readline
    N, M, L = map(int, input().split())
    d = [[float('inf')] * N for _ in range(N)]
    for i in range(N):
        d[i][i] = 0
    for _ in range(M):
        a, b, c = map(int, input().split())
        if c > L:
            continue
        d[a-1][b-1] = c
        d[b-1][a-1] = c
    
    G = floyd_warshall(d)

    e = [[float('inf')]*N for _ in range(N)]
    for i in range(N):
        e[i][i] = 0
    for i in range(N-1):
        for j in range(i+1, N):
            if G[i][j] <= L:
                e[i][j] = 1
                e[j][i] = 1
    
    H = floyd_warshall(e)
    
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        if H[s-1][t-1] == float('inf'):
            print(-1)
            continue
        ans = H[s-1][t-1] - 1
        print(int(ans))
    
    exit()


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 20320
#!/usr/bin/env python3
x1, y1, x2, y2 = map(int, input().split())
dy = y2 - y1
dx = x2 - x1
x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy
print(x3, y3, x4, y4)


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

int gcd(int a, int b) {
  if(a < b)  return gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  int n; int a; cin >> n >> a;
  for(int i=0;i<n-1;i++){
  	int tem;
  	cin >> tem;
    a = gcd(a,tem);
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

LL N;
int dfs(LL n, bool b3, bool b5, bool b7) {
  if (n > N) return 0;

  int cnt = 0;
  if (b3 && b5 && b7) ++cnt;
  cnt += dfs(n * 10 + 3, true, b5, b7);
  cnt += dfs(n * 10 + 5, b3, true, b7);
  cnt += dfs(n * 10 + 7, b3, b5, true);

  return cnt;
}

int main() {
  cin >> N;
  int cnt = 0;
  cnt += dfs(3, true, false, false);
  cnt += dfs(5, false, true, false);
  cnt += dfs(7, false, false, true);
  cout << cnt << endl;
}


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


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a < b && b < c) cout << "Yes" << endl;
  else cout << "No" << endl;
} 


Measured memory_bytes: 3092
N = int(input())
A = list(map(int, input().split()))

cr = []
MAxans = 0

for i in A:
    c = i // 400
    if c < 8 and not c in cr:
        cr.append(c)
    elif c >= 8:
        MAxans += 1


if len(cr)>0:
    Minans = len(cr)
    MAxans = MAxans + Minans
else:
    Minans = 1
print(str(Minans) + " " + str(MAxans))


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll N = 1e6 + 10, MOD = 1e9 + 7;
ll inv[N], fac[N], inv_fac[N];

void precalc() {
	inv[1] = 1;
	FOR(n,2,N) inv[n] = (MOD - (MOD/n)*inv[MOD%n] % MOD) % MOD;

	fac[0] = 1;
	FOR(n,1,N) fac[n] = n*fac[n-1] % MOD;

	inv_fac[0] = 1;
	FOR(n,1,N) inv_fac[n] = inv[n]*inv_fac[n-1] % MOD;
}

ll binom(ll n, ll k) {
	if (k < 0 || k > n) return 0;
	return fac[n] * inv_fac[k] % MOD * inv_fac[n-k] % MOD;
}

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

	ll n, k;
	cin >> n >> k;

	vl a(n);
	FOR(i,0,n) cin >> a[i];
	sort(all(a));
	
	ll res = 0;
	FOR(i,0,n) {
		res = (res + a[i] * binom(i,k-1)) % MOD;
		res = (res - a[i] * binom(n-i-1,k-1)) % MOD;
	}
	if (res < 0) res += MOD;
	cout << res << endl;
}



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

	int main(){
	int N;
    int A[30];
    int B[30];
    int C[30];
      cin >> N;
      for (int i = 0; i < N; ++i) {
        cin >> A[i];
        A[i]--;
      }
      for (int k = 0; k < N; ++k) cin >> B[k];
      for (int j = 0; j < (N-1); ++j) cin >> C[j];
    
    int sum = 0;
    for (int  q= 0;q < N;q++){
     if (A[q+1] - A[q] == 1){
       int p = A[q] ;
        sum += C[p];
      }
      sum += B[q];
      }
      cout << sum << endl;
    }


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

using namespace std;

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

    int col[] = {0, 0, 0, 0, 0, 0, 0, 0};
    int higher_remainder = 0;

    for (int i=0; i<n; i++) {
        int tmp;
        cin >> tmp;
        if (tmp > 3199) {
            higher_remainder++;
        } else {
            col[tmp/400] = 1;
        }
    }

    int col_used = 0;
    for (int i=0; i<8; i++) {
        if (col[i])
            col_used++;
    }

    cout << max(1, col_used) << " " << col_used+higher_remainder << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[51];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	double ans=(a[1]+a[2])/2.0;
	for(int i=3;i<=n;i++)
	{
		ans=(ans+a[i])/2.0;	
	}
	printf("%.5lf",ans);
	return 0;
}

Measured memory_bytes: 256
'use strict'

const main = (input) => {
    const A = parseInt(input.split(' ')[0])
    const B = parseInt(input.split(' ')[1])

    let count = 0
    for(let i = A; i <= B; i++){
        let str = i.toString()
        let rStr = str.split('').reverse().join('')
        if(str === rStr) count++
    }
    console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 15004
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n],sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    int pos=sum/n;
    ll ans1=0,ans2=0;
    for(int i=0;i<n;i++)
    {
        int diff=abs(pos-a[i]);
        ans1+=diff*diff;
    }
    pos++;
    for(int i=0;i<n;i++)
    {
        int diff=abs(pos-a[i]);
        ans2+=diff*diff;
    }
    ll ans=min(ans1,ans2);
    cout<<ans;
    return 0;
}







Measured memory_bytes: 256
/*
  AOJ 2612
  Title:Phutball
  @kankichi573
  2015/9/14 WA 38/93
  2015/9/15 TLE 91/93
*/
#include <stdio.h>
#include <string.h>
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define W 15
#define H 19

char ban[H+1][W+1];
char line[W+1];
int dir[3]={-1,0,1};
int dirx[8]={1,1,0,-1,-1,-1, 0, 1};
int diry[8]={0,1,1, 1, 0,-1,-1,-1};
int min_;

void white_stone(char ban[][W+1],int *yp,int *xp)
{
  int i,j;
  for(i=0;i<H;i++)
    for(j=0;j<W;j++)
      if(ban[i][j]=='O')
	{ *yp=i,*xp=j;
	  return;
	}
}

int direct_goal(char ban[][W+1],int y,int x)
{
  int i,k,l,ret;

  if(y==H-2)
    if((x>0 && ban[y+1][x-1]=='X')||ban[y+1][x]=='X'||
       (x<W-1 && ban[y+1][x+1]=='X'))
      return(1);
    else
      return(0);

  for(i=0;i<3;i++)
    {
    for(k=y+1,l=x+dir[i];;k++,l+=dir[i])
      {
	if(k >= H-1)
	  return(1);
	if((k==H-2 && (l<=0 && i==0)||(l>=W-1 && i==2)) || ban[k][l] != 'X')
	  goto NEXT;
      }
    NEXT: ;
    }
  return(0);
}

int can_jump(char ban[][W+1],int d,int y,int x)
{
  int k,l,ren;


  ren=0;
  for(k=y+diry[d],l=x+dirx[d];;k+=diry[d],l+=dirx[d])
    {

      if(l<0 || l>W-1 || k<0 || k> H-1)
	return(0);
      else if(ban[k][l]!='X')
	break;
      else
	ren++;
    }
  if(ren)
    return(1);

  return(0);
}

void jump(char ban[][W+1],int d,int *yp,int *xp)
{
  int k,l,y,x;

  y=*yp,x=*xp;
  ban[y][x]='.';
  for(k=y+diry[d],l=x+dirx[d];;k+=diry[d],l+=dirx[d])
    {
      if(ban[k][l]=='X')
	ban[k][l]='.';
      else
	{
	  ban[k][l]='O';
	  break;
	}
    }
  *yp=k,*xp=l;
}
void print_ban(char ban[][W+1])
{
  int i;
  printf("\n");
  for(i=0;i<H;i++)
    printf("%s\n",&ban[i][0]);
  printf("\n");
}

void solve(char ban[][W+1],int y,int x,int lv)
{
  int i,d,y0,x0;
  char my_ban[H+1][W+1];

  if(lv+1 >= min_)
    return;

  if(direct_goal(ban,y,x))
    min_=min(min_,lv+1);

  for(d=0;d<8;d++)
    {
      
      if(can_jump(ban,d,y,x))
      {
	memcpy(my_ban,ban,sizeof(my_ban));
	y0=y,x0=x;
	jump(my_ban,d,&y0,&x0);
	//print_ban(my_ban);
	solve(my_ban,y0,x0,lv+1);
      }
    }
}


main()
{
  int i,y,x;
  
  for(i=0;i<H;i++)
    scanf("%s",&ban[i][0]);
  white_stone(ban,&y,&x);

  min_=1000;
  solve(ban,y,x,0);
    
  if(min_==1000)
    printf("-1\n");
  else
    printf("%d\n",min_);
  return(0);
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
int main() {
	scanf("%d", &n);
	ll s = 0;
	for (int i = 1; i <= n; i++) {
		if (i%3 == 0 || i%5 == 0) continue;
		s = s+i;
	}
	printf("%lld\n", s);
	return 0;
}

Measured memory_bytes: 3828
n = int(input())
baralho = input().split()
pesos = list(map(int, baralho))
#print(pesos)
menor = min(pesos)
maior = max(pesos)
lst = []
for i in range(menor, maior, 1):
	acum_menor = acum_maior = 0
	for j in range (n):
		if (j <= i):
			acum_menor += pesos[j]
		else:
			acum_maior += pesos[j]
	lst.append(abs(acum_maior - acum_menor))
print(min(lst)) 




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

long gcd(long a,long b){
  if (a==0) return b;
  if (b==0) return a;
	if (a%b==0)	return b;
	else return gcd(b,a%b);
}

int main() {
long N;
cin>>N;
vector<long> a(N);
for(int i =0;i<N;i++) cin>>a[i];
vector<long> l(N+1);
vector<long> r(N+1);

for(int i=0;i<N;i++) l[i+1]=gcd(l[i],a[i]);
for(int i=N-1;i>=0;i--) r[i]=gcd(r[i+1],a[i]);
vector<long> c(N);

for(int i=0;i<N;i++) c[i]=gcd(l[i],r[i+1]);

long ans = 1;
for(int i=0;i<N;i++) ans=max(ans,c[i]);

//for(int i=0;i<N;i++) cout<<l[i]<<endl;
//for(int i=0;i<N;i++) cout<<r[i]<<endl;
//for(int i=0;i<N;i++) cout<<c[i]<<endl;

cout<<ans<<endl;


}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int vis[1000];
int main()
{

    reg int i,j,n;
    for(i=1;i<=9;++i)
        for(j=1;j<=9;++j)
            vis[i*j]=1;
    n=read();
    if(vis[n])cout<<"Yes\n";
    else cout<<"No\n";
	return 0;
}


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

long long MOD=1000000007LL; 

int main(){
	int N;
	long long K;
	cin >> N >> K;
	vector<long long> A(N);
	for(auto &i:A)cin >> i;
	
	long long ans=0;
	for(int i=0;i<N;i++){
		long long Lm=0,LM=0,Rm=0,RM=0;
		for(int j=0;j<i;j++){
			if(A[j]<A[i])Lm++;
			if(A[j]>A[i])LM++;
		}
		for(int j=i+1;j<N;j++){
			if(A[i]<A[j])RM++;
			if(A[i]>A[j])Rm++;
		}
		ans+=((K*(K-1)/2)%MOD)*Lm;
		ans%=MOD;
		ans+=((K*(K+1)/2)%MOD)*Rm;
		ans%=MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
#define V vector
vector<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
vector<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

const int INF = 1e9;

int main () {
    int h, n; cin >> h >> n;
    V<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    V<V<int>> dp(n+1, V<int> (h+1, INF));
    dp[0][0] = 0;
    rep(i, n) {
        for (int j = 0; j <= h; j++) {
            chmin(dp[i+1][j], dp[i][j]);
            int nj = min(h, j + a[i]);
            chmin(dp[i+1][nj], dp[i+1][j] + b[i]);
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

Measured memory_bytes: 42324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    ll X[N], sum = 0;
    rep(i, N){
        cin >> X[i];
        sum += X[i];
    }
    ll a = sum/N, b = a+1;
    ll ans1 = 0, ans2 = 0;
    rep(i, N){
        ans1 += (a-X[i])*(a-X[i]);
        ans2 += (b-X[i])*(b-X[i]);
    }
    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
public class Program {
    static void Main (string[] args) {
        var s = Console.ReadLine();
        var k = int.Parse(Console.ReadLine());
        var l = new List<string>();
        var hs = new HashSet<string>();
        for (int i = 0; i < s.Length; ++i) {
            for (int j = 0; j < k + 1; ++j) {
                if (s.Length > (i + j)) {
                    hs.Add(s.Substring(i, j));
                } else {
                    hs.Add(s.Substring(i, j - ((i + j) - s.Length)));
                }
            }
        }
        foreach (var i in hs) {
            l.Add(i);
        }
        l.Sort();
        Console.WriteLine(l[k]);
    }
}


Measured memory_bytes: 14816
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int a,b,c;
  std::cin >> a >> b >>c;
  if(a+b>=c) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

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

int ans[110][110];

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

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

  int tmp_cnt = 0;
  int tmp_color = 0;

  for(int i = 0; i < H; i++){
    if(i%2 == 0){
      for(int j = 0; j < W; j++){
        ans[i][j] = tmp_color;
        tmp_cnt++;
        if(tmp_cnt == a[tmp_color]){
          tmp_color++;
          tmp_cnt= 0;
        }
      }
    }else{
      for(int j = W-1; j >= 0; j--){
        ans[i][j] = tmp_color;
        tmp_cnt++;
        if(tmp_cnt == a[tmp_color]){
          tmp_color++;
          tmp_cnt = 0;
        }
      }
    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cout << ans[i][j]+1 << " ";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer x;
  x = nil->next;
  while(x != nil && x->key != key){
    x = x->next;
  }
  return x;
  
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  if ((t->next->prev == nil) || (t->prev->next == nil)) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  NodePointer t;
  t = nil->prev;
  if(t == nil) return;
  deleteNode(t);
}

void delete(int key){
  /* your code */

  deleteNode(listSearch(key));
 
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  /*  your code */
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
   
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 36092
'use strict';
console.log(function(args){
  const tmp = args.trim().split('\n').map( r=>r.split(' ').map(v=>v|0) );
  const N = tmp[0][0], W = tmp[0][1];
  const dp = [Array(W+1).fill(0)];
  for ( let i = 0; i < N; i++ ) {
    let w = tmp[i+1][0];
    let v = tmp[i+1][1];
    dp.push(Array(W+1).fill(0));
    for ( let j = 0; j <= W; j++ ) {
      if ( j >= w ) dp[i+1][j] = Math.max( dp[i][j], dp[i][j-w] + v );
      else dp[i+1][j] = dp[i][j];
    }
  }
  return dp[N][W].toString();
}(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 117396
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, m: usize, rr: usize,
        r: [Usize1; rr],
        abc: [(Usize1, Usize1, i64); m],
    }

    let mut graph = vec![vec![1i64<<50; n]; n];
    for (a, b, c) in abc {
        graph[a][b] = c;
        graph[b][a] = c;
        graph[a][a] = 0;
        graph[b][b] = 0;
    }

    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }

    let mut ans = 1<<50;
    for perm in r.iter().permutations(rr) {
        let mut res = 0;
        for (&from, &to) in perm.into_iter().tuple_windows() {
            res += graph[from][to];
        }
        ans = min(ans, res);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2948
/* Doctor's Memorable Code */

#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<cctype>

using namespace std;

string sbits(unsigned int x, int n){
  string ret;
  for(int i = 0; i < n; i++){
    ret += (x & 1) + '0';
    x >>= 1;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}

string DoctorTableAD(char c){
  string ret;
  if( isupper(c) ){
    ret = sbits(c - 'A', 5);
  }else{
    const char symb[] = " .,-'\?";
    for(int i = 0; i < sizeof(symb)/sizeof(*symb); i++){
      if( c == symb[i] ){
	ret = sbits(i+26, 5);
	break;
      }
    }
  }
  return ret;
}

string DoctorTableDA(string &s){
  unsigned int pos = 0;
  string ret;
  const char ctable[] = " ',-.\?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  const char table[][16] =
  {"101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
  
  while( true ){
    bool bFound = false;
    for(int i = 0; i < sizeof(table)/sizeof(*table); i++){
      if( 0 == s.compare(pos, strlen(table[i]), table[i]) ){
	ret += ctable[i];
	pos += strlen(table[i]);
	bFound = true;
	break;
      }
    }
    if( bFound == false ) break;
  }
  return ret;
}

string DoctorLovedDecode(string &raw){
  string s;
  for(unsigned int i = 0; i < raw.length(); i++){
    s += DoctorTableAD(raw[i]);
  }
  return DoctorTableDA( s );
}

int main(void){
  while(true){
    string s;
    
    getline(cin,s);
    if( cin.eof() ) break;
    
    cout << DoctorLovedDecode( s ) << "\n";
  }
  return 0;
}

Measured memory_bytes: 0
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    ret = a[0]
    i = 2
    for _a in a[1:]:
        if i == n:
            break
        ret += _a
        i += 1
        if i == n:
            break
        ret += _a
        i += 1
    print(ret)




if __name__ == "__main__":
    main()


Measured memory_bytes: 31440