akhauriyash/Code-Regression huggingface dataset:
a,b,c=gets.split.map(&:to_i).sort
m=1/0.0
a.upto(c) do |i|
  cnt=0
  [a,b,c].each do |k|
    if k>i
      cnt+=k-i
    else
      cnt+=(i-k)/2
      if (i-k).odd?
        cnt+=2
      end
    end
  end
  m=cnt if m>cnt
end
p m


Measured memory_bytes: 1788
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using lli = long long;

int N, A[200'010];
map<int, int> m;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		m[A[i]]++;
	}
	lli ans = 0;
	for (auto& pii : m)
	{
		auto& v = pii.second;
		ans += 1LL * v * (v - 1) / 2;
	}
	for (int i = 0; i < N; ++i)
	{
		int v = m[A[i]];
		ans -= 1LL * v * (v - 1) / 2;
		ans += 1LL * (v - 1) * (v - 2) / 2;
		cout << ans << "\n";
		ans -= 1LL * (v - 1) * (v - 2) / 2;
		ans += 1LL * v * (v - 1) / 2;
	}

}

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

struct TCoordinate
{
	double x;
	double y;
};

double GetCrossProduct(const TCoordinate& V1, const TCoordinate& V2)
{
	return V1.x * V2.y - V1.y * V2.x;
}

bool IsSameSide(const TCoordinate& T1, const TCoordinate& T2, const TCoordinate& L1, const TCoordinate& L2)
{
	TCoordinate VectorL1T1 = {T1.x - L1.x, T1.y - L1.y};
	TCoordinate VectorL1T2 = {T2.x - L1.x, T2.y - L1.y};
	TCoordinate VectorL1L2 = {L2.x - L1.x, L2.y - L1.y};
	double CrossProductT1 = GetCrossProduct(VectorL1T1, VectorL1L2);
	double CrossProductT2 = GetCrossProduct(VectorL1T2, VectorL1L2);
	if(CrossProductT1 * CrossProductT2 > 0){
		return true;
	}else{
		return false;
	}
}

int main()
{
	while(true){
		TCoordinate A1, A2, A3, Ap;
		cin >> A1.x >> A1.y >> A2.x >> A2.y >> A3.x >> A3.y >> Ap.x >> Ap.y;
		if(cin.eof() == true) break;
		if(IsSameSide(A3, Ap, A1, A2) && IsSameSide(A1, Ap, A2, A3) && IsSameSide(A2, Ap, A3, A1)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3116
#include <stdio.h>
int main(void)
{
	int A[100],minj,t,i,j,c,N;
	
	scanf("%d",&N);
	
	for(i=0; i<N; i++)
	{
		scanf("%d",&A[i]);
	}
	
	c=0;
	
	for(i=0; i<N; i++)
	{
		minj=i; //最小値が入っているものをA[minj]とする
		
		for(j=i; j<N; j++)
		{
			if(A[j]<A[minj])
			{
				minj=j;
			}
		}
		
		
		
		if(i!=minj)
		{
			t=A[i];
			A[i]=A[minj];
			A[minj]=t;
			c++;
		}
	}
	
	
	for(i=0; i<N; i++)
	{
		printf("%d",A[i]);
		if(i!=N-1)
		{
			printf(" ");
		}
		
	}
	
	printf("\n");
	printf("%d\n",c);
	
	return 0;
}




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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int a = int.Parse(str[0]);
            a += int.Parse(str[1]) + int.Parse(str[2]);

            if (a > 21)
            {
                Console.WriteLine("bust");
            }
            else
            {
                Console.WriteLine("win");
            }
            


            //ここまで
        }
    }
}


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

int main()
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double k1 = 360.0 * h / 12 + 360.0 * m / (12 * 60);
    double k2 = 360.0 * m / 60;
    if (k1 > k2) swap(k1, k2);
    double t = k2 - k1;
    double xx = a * a + b * b - 2 * a * b * cos(M_PI * t / 180);
    double ans = sqrt(xx);
    std::cout << std::fixed;
    cout << setprecision(9) << ans << endl;
    return 0;
}


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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    ll N,K,Q,t;
    cin >>N>>K>>Q;

    vector<ll> A(N,K-Q);
    rep(i,Q){
        cin >> t;
        A[t-1]++;
    }
    rep(i,N){
        cout << ((A[i]>0) ? "Yes": "No")<<endl;
    }
    return (0);
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    vector<ll> a(n),ai(n);
    map<ll,ll> mp;
    For(i,0,n) {
        cin>>a[i];
        ai[i]=a[i]+i;
    }
    For(i,0,n){
        ans+=mp[i-a[i]];
        mp[ai[i]]++;
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 29040
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second	

#define sz(a) ((int)(a.size()))
using namespace std;
const int mod = 998244353;
int mult(int a, int b)
{
	return a * (ll) b % mod;
}
int add(int a, int b)
{
	return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a,  int b)
{
	return a - b < 0 ? a - b + mod : a - b;
}
void Add(int &a, int b)
{
	a = add(a , b);
}
vector<ll> b;
void add(ll x)
{
	for(int i = 0; i < b.size(); i++)
	{
		ll t= b[i];
		if((x ^ t) < x)
		{
			x ^= t;
		}
	}
	if(x == 0)
		return;
	for(int i = 0; i < b.size(); i++)
	{

		if((x ^ b[i]) < b[i])
			b[i] ^= x;
	}
	b.pb(x);
	sort(b.begin() , b.end() , greater<ll>());
}
ll check(ll x)
{
	for(int i = 0; i < b.size(); i++)
	{
		ll t = b[i];
		if((x ^ t) < x)
		{
			x ^= t;
		}
	}
	return x;
}
int main() 
{
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		b.clear();
		vector<ll> a(n);
		for(auto & x : a)
			cin >> x;
		string s;
		cin >> s;
		reverse(a.begin() , a.end());
		reverse(s.begin() , s.end());
		bool pzdc = false;
		for(int i = 0; i < n; i++)
			if(s[i] == '0')
			{
				add(a[i]);
			}
			else 
			{
				pzdc |= check(a[i]) != 0;
			}
		cout << pzdc << endl;
	}
	
}












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

int main(){
    int a, b, ans;
    cin >> a >> b;

    if((a + b) % 2 == 0) {
        ans = (a + b) / 2;
        cout << ans << endl;
    }
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define index_max 250

int main(){
  int i;
  int n,a[index_max];
  int left_search,right_search;

  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d" , &a[i]);
  }

  for(i = 0 ; i < n ; i++){
    printf("node %d: key = %d, " ,i+1 ,a[i]);

    if(i){
      printf("parent key = %d, " ,a[(i+1)/2-1]);
    }
    left_search=2*i+1;
    if(left_search < n){
      printf("left key = %d, " ,a[2*i+1]);
    }
    right_search=2*i+2;
    if(right_search < n){
      printf("right key = %d, " ,a[2*i+2]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	if (N % 1000 == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1000 - N % 1000 << endl;
	}
}


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

int main(){
  int N,i,j;
  string S;
  cin >> N >> S;

  for(i=0;i<S.size();i++){
    for(j=0;j<N;j++){
      if(S.at(i)=='Z')
      S.at(i) = 'A';
      else
      S.at(i)++;
    }
  }
  cout << S << endl;
}

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

#define long long int ll

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

    vector<int> x(N);
    vector<int> y(N);
    for(int i=0; i<N; i++){
        cin >> x.at(i) >> y.at(i);
    }
    vector<vector<double>> dist(N, vector<double>(N));
    for(int i=0; i<N;i++){
        for(int j=0; j<N; j++){
            dist.at(i).at(j) = sqrt(pow(x.at(i) - x.at(j),2) + pow(y.at(i) - y.at(j),2));
        }
    }

    vector<int> order(N);
    for(int i=0; i<N; i++) order.at(i) = i;

    double ans = 0.0;
    do{
        for(int i=0; i<N-1; i++){
            ans += dist.at(order.at(i)).at(order.at(i+1));
        }
    }while(next_permutation(order.begin(), order.end()));

    int pat_num = 1;
    for(int i = 2; i <= N; i++) pat_num *= i;
    cout << fixed << setprecision(10) << ans / pat_num << endl;

    return 0;

} 


Measured memory_bytes: 3804
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int N=0;
int W=0;
int w[100];
long long v[100];
long long dp[110][1000010]={0};
int main(void){
	cin>>N>>W;
	for(int i=0;i<N;i++){
		cin>>w[i]>>v[i];
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<=W;j++){
			if(w[i]<=j){dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);}
			else dp[i+1][j]=dp[i][j];
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;
}

Measured memory_bytes: 286976
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int card[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>card[i][j];
    }
  }
  int n;
  cin>>n;
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin>>b[i];
    for(int r=0;r<3;r++){
      for(int c=0;c<3;c++){
        if(card[r][c]==b[i]){
          card[r][c]=-1;
        }
      }
    }
  }

  for(int r=0;r<3;r++){
    bool ok=true;
    for(int c=0;c<3;c++){
      if(card[r][c]!=-1){
        ok=false;
      }
    }
    if(ok){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  for(int c=0;c<3;c++){
    bool ok=true;
    for(int r=0;r<3;r++){
      if(card[r][c]!=-1){
        ok=false;
      }
    }
    if(ok){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  bool ok=true;
  for(int i=0;i<3;i++){

    if(card[i][i]!=-1){
      ok=false;
    }
  }
  if(ok){
    cout<<"Yes"<<endl;
    return 0;
  }

  ok=true;
  for(int i=0;i<3;i++){

    if(card[i][2-i]!=-1){
      ok=false;
    }
  }
  if(ok){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);  cin.tie(0) ; cout.tie(0);
#define debug(x) cout << #x << " : " << x << endl;
#define pi 3.14159265359
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
using ll = long long int;
using db = double;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
const int MOD = 1e9+9;

void solve()
{
    int n , ans = 0;
    string str;
    cin >> n ;
    cin >> str;
    int st = 0 , end = n-1;
    while(st < end)
    {
        if(str[end] == 'W')
            end--;
        else if (str[st] == 'R')
            st++;
        else
        {
            ans++;
            end--;
            st++;
        }
    }
    cout << ans << endl;
}

int main()
{
//  #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin); 
//     freopen("output.txt", "w", stdout);
//  #endif
    fastio;

    ll t = 1;
    // cin >> t;
    while(t--)
       solve();
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>

using namespace std;
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){
    os << "{ ";
    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
        os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", ");
    os << " }";
    return os;
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define vv(type,w,h,init) vector<vector<type>>(h,vector<type>(w,init))
typedef vector<string> vs;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair

string const resstr[] = {"Impossible","Possible","No","Yes"};

int const rs[]={60,80,100,120,140,160,int(1e8)}; 
int const rw[]={2,5,10,15,20,25,int(1e8)}; 
int const p[]={600,800,1000,1200,1400,1600,int(1e8)};

int main(){
    int n;
    while(cin>>n,n){
        int ans = 0;
        rep(i,n){
            int x,y,h,w; cin>>x>>y>>h>>w;
            int s=x+y+h;
            int j=0;
            for (j=0;;++j){
                if(s>rs[j]||w>rw[j]) continue;
                else break;
            }
            if(j==6) continue;
            ans += p[j];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1204
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul             1000000007
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define lul2            998244353 
#define pll             pair<ll,ll>
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}
void solve()
{
    ll a,b,c; cin>>a>>b>>c;
    if(c<(a+b)) {cout<<"No"; return;}
    ll fact1 = (c-(a+b))*(c-(a+b));
    fact1 = ceil((ld)fact1/4.0);
    ll fact2 = a*b;
    if(fact2<fact1) cout<<"Yes";
    else cout<<"No";
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; /*cin>>t;*/ t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //日付を入力する
            int h = int.Parse(Console.ReadLine());
            int w = int.Parse(Console.ReadLine());
            int n = int.Parse(Console.ReadLine());


            if(h > w)
            {
                if(n % h == 0)
                    Console.WriteLine(n / h);
                else
                    Console.WriteLine(n / h + 1);
            }
            else
            {
                if(n % w == 0)
                    Console.WriteLine(n / w);
                else
                    Console.WriteLine(n / w + 1);
            }
            
        }
    }

Measured memory_bytes: 11092
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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 INF = 10000000;
//ll mod = 1000000007;//10^9+7
int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1};
//using Graph = vector<vector<int>>;
using P = pair<int, int>;


//番号ズレ注意！！
int main() {
    int H, W;
    cin >> H >> W;
    string A[H];
    REP(i, H) {
        cin >> A[i];
    }
    queue<P> que;
    int ans = 0;
    int dist[H][W];
    REP(i, H) {
        REP(j, W) {
            dist[i][j] = -1;
            if (A[i][j] == '#') {
                que.push(make_pair(i, j));
                dist[i][j] = 0;
            }
        }
    }

    while (!que.empty()) {
        P v = que.front();
        que.pop();
        int x = v.first, y = v.second;
        REP(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W)continue;
            if (A[nx][ny] == '#') { continue; }
            que.push(make_pair(nx, ny));
            dist[nx][ny] = dist[x][y] + 1;
            ans = dist[nx][ny];
            A[nx][ny] = '#';
        }
    }
    print(ans);


}


Measured memory_bytes: 13456
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t N,A,B;
  cin>>N>>A>>B;
  if(N==1){if(A==B)
          cout<<1<<endl;
          else
          cout<<0<<endl;}
 else if(A<=B){ int64_t ans=(N-2)*(B-A)+1;
  cout<<ans<<endl;}
  else
    cout<<0<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	float temp;
	cin>>x>>y;
	temp=(4*x-y)/2.0;
	if(temp<0)
	cout<<"No"<<endl;
	else if(y<=x)
	cout<<"No"<<endl;
	else if(2*temp>y)
	cout<<"No"<<endl;
	else if((int)temp==temp)
	cout<<"Yes"<<endl;
	else 
	cout<<"No"<<endl;
}

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

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(all(A));
    vector<ll> Aa(N + 1);
    Aa[0]               = 0;
    rep(i, N) Aa[i + 1] = A[i] + Aa[i];//累積和を計算

    ll l = 0, r = 1e10;
    ll ans = 0;
//二分探索スタート
    while (r - l > 1) {
        ll c = (l + r) / 2;
        ll m = 0;
        ans  = 0;
        rep(i, N) {
            int index = lower_bound(all(A), c - A[i]) - A.begin();//c-A[i]以上のイテレータを得る
            ans += (Aa[N] - Aa[index] + A[i] * (N - index));
            m += (N - index);
        }
        M > m ? (r = c) : (l = c);

        ans -= l * (m - M);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920
#!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007

#A
"""
t,x = LI()
print(t/x)
"""

#B
"""
n= II()
a = LI()
m = max(a)
if m >= sum(a)-m:
    print("No")
else:
    print("Yes")
"""

#C
n,m = LI()
x = LI()
x.sort()
l = [x[i+1]-x[i] for i in range(m-1)]
l.sort()
l = l[::-1]
ans = sum(l[max(n-1,0):])
print(ans)
#D
"""
n,k = LI()
a = LI()
l = 0
b = [0 for i in range(n)]
for i in range(n):
    b[i] = list(bin(a[i]))[2:]
    l = max(l,len(b[i]))
s = [0 for i in range(l)]
for i in range(n):
    for j in range(l-len(b[i])):
        b[i].insert(0,"0")
for i in range(n):
    for j in range(l):
        s[j] += 1-int(b[i][j])
ke = 1
for i in range(l)[::-1]:
    if s[i] <= n//2:
        s[i] = [(n-s[i])*ke,0,float("inf")]
    else:
        s[i] = [(n-s[i])*ke,s[i]*ke,ke]
    ke *= 2
s.sort(key = lambda x:x[0])
d = 0
ans = 0
key = len(list(bin(k)))-2
key -= l
ke = 2**l
print(s)
for i in range(key):
    d += ke
    ans += n*ke
    ke *= 2
for i in range(l):
    r,q,p = s[i]
    if d+p <= k:
        d += p
        ans += q
    else:
        ans += r
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 57384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
int main(){
    int h,w;
    cin >> h >> w;
    char a[h+2][w+2];
    vector<vector<int>> bl;
    vector<vector<int>> wh;
    vector<int> tem;
    vector<vector<int>> bll;
    rep(i,h+2){
        rep(j,w+2){
            a[i][j] = 'p';
        }
    }
    rep(i,h){
        rep(j,w){
            cin >> a[i+1][j+1];
            tem = {i+1,j+1};
            if(a[i+1][j+1] == '#'){
                bl.push_back(tem);
                bll.push_back(tem);
            }
            else{
                wh.push_back(tem);
            }
        }
    }
    bool fl = true;
    vector<vector<int>> blt;
    int ans = 0;
    while(bll.size() != h*w){
        rep(i,bl.size()){
            if(a[bl[i][0]+1][bl[i][1]] == '.'){
                a[bl[i][0]+1][bl[i][1]] = '#';
                tem = {bl[i][0]+1,bl[i][1]};
                blt.push_back(tem);
                bll.push_back(tem);
            }
            if(a[bl[i][0]-1][bl[i][1]] == '.'){
                a[bl[i][0]-1][bl[i][1]] = '#';
                tem = {bl[i][0]-1,bl[i][1]};
                blt.push_back(tem);
                bll.push_back(tem);
            }
            if(a[bl[i][0]][bl[i][1]+1] == '.'){
                a[bl[i][0]][bl[i][1]+1] = '#';
                tem = {bl[i][0],bl[i][1]+1};
                blt.push_back(tem);
                bll.push_back(tem);
            }
            if(a[bl[i][0]][bl[i][1]-1] == '.'){
                a[bl[i][0]][bl[i][1]-1] = '#';
                tem = {bl[i][0],bl[i][1]-1};
                blt.push_back(tem);
                bll.push_back(tem);
            }
        }
        bl = {};
        rep(j,blt.size()){
            bl.push_back(blt[j]);
        }
        blt = {};
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 142756
#include "bits/stdc++.h"

using namespace std;

int main() {
	int N, M;
	cin >> N >> M; 
	int sum = 0;
	vector<int>A(N);
	for (int n = 0;n<N;++n) {
		cin >> A[n];
		sum += A[n];
	}
	int count = 0;
	for (int n = 0;n<N;++n) {
		if (A[n]*4*M >=sum) {
			count++;
		}
	}
	if (count >=M) {
		cout << "Yes" << endl;
	}
	else {
		cout <<"No"<<endl;
	}
	return 0;
}

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

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

  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
  }

  if (k >= n) {
    cout << 1 << endl;
  } else {
    cout << 1 + ceil((double)(n - k) / (k - 1)) << endl;
  }

  return 0;
}

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "YES" : "NO")

typedef pair <int, int> ii;
typedef pair <ii, int> iii;

const int siz = 2e5 + 10;
const int SIZ = 2e3 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e12;
const string file = "2";

int f[SIZ];

int dp(int rem) {
    if (rem == 0) {
        return 1;
    }

    int &res = f[rem];
    if (res != -1) {
        return res;
    }

    res = 0;
    for (int i = 3; i <= rem; i++) {
        (res += dp(rem - i)) %= mod;
    }

    return res;
}

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

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int s;
    cin >> s;

    memset(f, -1, sizeof(f));

    cout << dp(s) << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 3664
import java.io.*;

class AffineCipher {
	String s,c;
	String alph = "abcdefghijklmnopqrstuvwxyz";
	int a[] = {1,3,5,7,9,11,15,17,19,21,23,25};

	AffineCipher(String s) {
		this.s = s;
		this.c = s;
	}

	boolean Found(String t) {
		if (t.indexOf("that")!=-1||
			t.indexOf("this")!=-1) return true;
		else return false;
	}

	int Reciprocal(int A) {
		for (int i=1;i<=25;i++) {
			if ((A*i)%26==1) {
				for (int j=0;j<12;j++) {
					if (a[j]==i) return i;
				}
			}
		}
		return 0;
	}

	String FindString() {
		for (int i=0;i<12;i++) {
			for (int j=0;j<=25;j++) {
				String t = "";
				for (int k=0;k<this.s.length();k++) {
					if (alph.indexOf(this.s.charAt(k))!=-1)
						t = t+alph.charAt((a[i]*alph.indexOf(this.s.charAt(k))+j)%26);
					else t = t+this.s.charAt(k);
				}
				this.s = this.c;
				if (Found(t)) return t;
			}	
			this.s = this.c;
		}
		return "NotFound";
	}
}

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			int n = Integer.parseInt(br.readLine());
			for (int i=0;i<n;i++) {
				AffineCipher ac = new AffineCipher(br.readLine());
				System.out.println(ac.FindString());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	string S; cin >> S;
	int n(0), s(0),w(0),e(0);
	rep(i, 0, S.length()) {
		if (S[i] == 'N')n++;
		else if (S[i] == 'S')s++;
		else if (S[i] == 'W')w++;
		else if (S[i] == 'E')e++;
	}
	bool x(false), y(false);
	if ((n == 0 && s == 0) || (n > 0 && s > 0)) {
		x = true;
	}
	if ((e == 0 && w == 0) || (e > 0 && w > 0)) {
		y = true;
	}
	if (x&&y)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

const int MOD = 998244353;

LL a[3005];
LL r_fix[3005][3005];

// 依次求得
// (1, 1)
// (1, 2), (2, 2)
// (1, 3), (2, 3), (3, 3)
// (1, 4), (2, 4), (3, 4), (4, 4)
// .....

// r_fix[i][j] 也可由動態規劃得到


int main() {
    int n, s;
    scanf("%d%d", &n, &s);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    // r_fix[0][0] = 1;
    LL ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= s; j++) {
            if (j < a[i]) {
                r_fix[i][j] = r_fix[i - 1][j];
            } else if (j == a[i]) {
                r_fix[i][j] = (r_fix[i - 1][j] + i) % MOD;
            } else {
                r_fix[i][j] = (r_fix[i - 1][j] + r_fix[i - 1][j - a[i]]) % MOD;
            }
        }
        ans += r_fix[i][s];
        ans %= MOD;
    }
    printf("%lld\n", ans);
}


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

using namespace std;

const int MaxN = 100005;

struct TrieNode
{
    int stop, cnt;
    int Child[26];
};

struct TrieTree
{
    TrieNode Trie[4 * MaxN];
    int Sum[MaxN][26][26], Prefix[MaxN];
    int Root, nT;
    string tt;
    int NewNode()
    {
        nT++;
        Trie[nT].stop = Trie[nT].cnt = 0;
        for (int i = 0; i < 26; i++)
        {
            Trie[nT].Child[i] = 0;
        }
        return nT;
    }
    void Init()
    {
        nT = -1;
        Root = NewNode();
    }
    void Add(string &s)
    {
        int r = Root, sz = s.size();
        for (int i = 0; i < sz; i++)
        {
            int t = s[i] - 'a';
            if (Trie[r].Child[t] == 0)
            {
                Trie[r].Child[t] = NewNode();
            }
            Trie[r].cnt++;
            r = Trie[r].Child[t];
        }
        Trie[r].cnt++;
        Trie[r].stop++;
    }
    void Set(int x, string &s)
    {
        int r = Root, sz = s.size();
        Prefix[x] = 0;
        for (int i = 0; i < sz; i++)
        {
            int t = s[i] - 'a';
            for (int j = 0; j < 26; j++)
            {
                if (j != t && Trie[r].Child[j] != 0)
                {
                    Sum[x][t][j] += Trie[Trie[r].Child[j]].cnt;
                }
            }
            Prefix[x] += Trie[r].stop;
            r = Trie[r].Child[t];
        }
    }
    int Query(int x)
    {
        cin >> tt;
        int Ans = Prefix[x];
        for (int i = 0; i < 26; i++)
        {
            for (int j = 0; j < i; j++)
            {
                Ans += Sum[x][tt[i] - 'a'][tt[j] - 'a'];
            }
        }
        return Ans + 1;
    }
};

int n, q;
string a[MaxN];
TrieTree Trie;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    Trie.Init();
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        Trie.Add(a[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        Trie.Set(i, a[i]);
    }
    cin >> q;
    int x;
    while (q--)
    {
        cin >> x;
        cout << Trie.Query(x) << '\n';
    }
    return 0;
}


Measured memory_bytes: 285824
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 2e5 + 20 ;
int n , X , x[N] ;

inline int get (int k) {
	int ans = k * X + n * X ;

	for (int i = n - 1 ; i >= n - k ; i --) ans += 2 * x[i] ;
	
	int d = n / k , r = n % k ;

	int p = n - 1 ;
	for (int i = d + 1 ; i > 0 ; i --) {
		int cnt = (i == d + 1 ? r : k) ;

		for (; cnt > 0 ; p --) {
			ans += x[p] * (2 * ((n - p - 1) / k + 1) + 1) ;
			cnt -- ;
		}
	}

	return ans ;
}

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

	cin >> n >> X ;

	for (int i = 0 ; i < n ; i ++) cin >> x[i] ;

	sort(x , x + n) ;

	int low = 1 , high = n + 1 ;
	while (high - low > 1) {
		int mid = (low + high) >> 1 ;
		if (get(mid) < get(mid - 1)) low = mid ;
		else high = mid ;
	}

	cout << get(low) << '\n' ;
}


Measured memory_bytes: 1792
n, t = map(int, raw_input().split())
prices = list(map(int, raw_input().split()))
lows = n * [ 0 ]
low = prices[0] + 1
for i, x in enumerate(prices):
    if x < low:
        low = x
    lows[i] = x
best_gap = 0
best_gap_count = 0
high = prices[-1] - 1
low = lows[-2] + 1
for i in range(len(prices) - 1, 0, -1):
    update = False
    x = prices[i]
    if x > high:
        high = x
        update = True
    if lows[i - 1] != low:
        low = lows[i - 1]
        update = True
    if update:
        gap = high - low
        if gap == best_gap:
            best_gap_count += 1
        elif gap > best_gap:
            best_gap = gap
            best_gap_count = 1
print(best_gap_count)


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

int main(){
	int n, m, i, x[3] = { 10,10,10 }, c, s;
	cin >> n >> m;
	if (n == 1) {
		rep(i,m) {
			cin >> s >> c;
			if (x[0] != 10 && x[0] != c) {
				cout << "-1";
				return 0;
			}
			else x[0] = c;
		}
		if (x[0] == 10)x[0] = 0;
		cout << x[0];
		return 0;
	}
	if (n == 2) {
		rep(i,m){
			cin >> s >> c;
			if (x[s-1] != 10 && x[s-1] != c) {
				cout << "-1";
				return 0;
			}
			if (s==1&&c==0) {
				cout << "-1";
				return 0;
			}
			else x[s-1] = c;
		}
		if (x[0] == 10)x[0] = 1;
		if (x[1] == 10)x[1] = 0;
		cout << x[0] << x[1];
	}
	if (n == 3) {
		rep(i,m) {
			cin >> s >> c;
			if (x[s - 1] != 10 && x[s - 1] != c) {
				cout << "-1";
				return 0;
			}
			if (s == 1 && c == 0) {
				cout << "-1";
				return 0;
			}
			else x[s - 1] = c;
		}
		if (x[0] == 10)x[0] = 1;
		if (x[1] == 10)x[1] = 0;
		if (x[2] == 10)x[2] = 0;
		cout << x[0] << x[1]<<x[2];
	}
}



Measured memory_bytes: 764
#include <iostream>
using namespace std;
static const int SIZE = 100;
static const int INF = 1e9+7;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NIL = -1;

int n;
int G[SIZE][SIZE],d[SIZE];

void dijkstra(){
    int u,mincost;
    int color[SIZE];

    for(int i=0; i<n; i++){
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;

    while(1){
        mincost = INF;
        u = NIL;

        for(int i=0; i<n; i++){
            if(color[i] != BLACK && d[i] < mincost){
                mincost = d[i];
                u = i;
            }
        }

        if(u == NIL) break;

        color[u] = BLACK;

        for(int v=0; v<n; v++){
            if(color[v] != BLACK && G[u][v] != INF){
                if(G[u][v] + d[u] < d[v]){
                    d[v] = G[u][v] + d[u];
                    color[v] = GRAY;
                }
            }
        }
    }
}

int main(){
    cin>>n;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            G[i][j] = INF;
        }
    }

    for(int i=0; i<n; i++){
        int u,k;
        cin>>u>>k;
        for(int j=0; j<k; j++){
            int v,c;
            cin>>v>>c;
            G[u][v] = c;
        }
    }

    dijkstra();

    for(int i=0; i<n; i++){
        cout<<i<<" ";
        if(d[i] != INF) cout<<d[i]<<endl;
        else cout<<-1<<endl;
    }

    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int n, m;
vector<int> G[110];

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
	int a, b;
	cin >> a >> b;
	--a, --b;
	G[a].push_back(b);
	G[b].push_back(a);
  }
  for (int i = 0; i < n; ++i) {
	cout << G[i].size() << endl;
  }
}


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

int main()
{
    int x,y;
    while(cin>>x>>y,x||y){
        string map[x];
        for(int i=0;i<x;i++){
            cin>>map[i];
        }
        int X=0,Y=0;
        bool end=false;
        int loopCount=1;
        while(true){
            switch(map[Y][X]){
                case '^' :
                    Y--;
                    break;
                case '>' :
                    X++;
                    break;
                case 'v' :
                    Y++;
                    break;
                case '<' :
                    X--;
                    break;
                case '.' :
                    end=true;
                    break;
            }
            if(end){
                cout<<X<<' '<<Y<<endl;
                break;
            }
            if(loopCount>x*y){
                cout<<"LOOP"<<endl;
                break;
            }
            loopCount++;
        }
    }
}

Measured memory_bytes: 1232
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()


int main() {
    char i;
    cin>>i;
    dunk((char)(i+1));
}




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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    int sum = accumulate(a.begin(), a.end(), 0);
    sort(a.rbegin(), a.rend());
    for (int i = 0; i < m; i++) {
        if (a.at(i)*4*m < sum) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
//**KEEP IT SHORT AND SIMPLE**
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a)* (b)).imag()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
typedef tuple<ll, ll, ll> line;
typedef complex<double> point;
const double pi = 2 * acos(0.0);
const int OO = 0x3f3f3f3f;
int main()
{
    IO
    ll n, l, sum = 0, a = LONG_MAX, b = LONG_MAX;
    cin >> n >> l;
    vll v;
    REP(i, 1, n + 1)
    {
        v.push_back(l + i - 1);
        sum += l + i - 1;
    }
    auto it = lower_bound(v.begin(), v.end(), 0);
    if(it != v.end())   a = *it;
    if(it != v.begin()) b = *(--it);
    cout << (abs(a) <= abs(b) ? sum - a : sum - b);
    return 0;
}


Measured memory_bytes: 256
class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.range = [(-1,n)] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
            self.range[self.num + i] = (i,i)
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
            self.range[i] = (self.range[2 * i][0],self.range[2 * i + 1][1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

    def bisect_l(self,l,r,x):
        l += self.num
        r += self.num
        Lmin = -1
        Rmin = -1
        while l<r:
            if l & 1:
                if self.tree[l] <= x and Lmin==-1:
                    Lmin = l
                l += 1
            if r & 1:
                if self.tree[r-1] <=x:
                    Rmin = r-1
            l >>= 1
            r >>= 1

        if Lmin != -1:
            pos = Lmin
            while pos<self.num:
                if self.tree[2 * pos] <=x:
                    pos = 2 * pos
                else:
                    pos = 2 * pos +1
            return pos-self.num
        elif Rmin != -1:
            pos = Rmin
            while pos<self.num:
                if self.tree[2 * pos] <=x:
                    pos = 2 * pos
                else:
                    pos = 2 * pos +1
            return pos-self.num
        else:
            return -1


N,K = map(int,input().split())
seg = SegmentTree([0]*(3*10**5+1),max,0)

for i in range(N):
    a = int(input())
    L = max(0,a-K)
    R = min(a+K+1,3*10**5+1)
    tmp = seg.query(L,R)
    seg.update(a,tmp+1)

print(seg.tree[1])

Measured memory_bytes: 140784
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto ds = readln.split.to!(int[]);
    sort(ds);
    writeln(ds[N/2] - ds[N/2-1]);
}

Measured memory_bytes: 4316
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<iostream>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0) return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p; }
#define flush fflush(stdout)
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

int main()
{
    IOS;//ifstream fin("input.txt");ofstream fout("output.txt");
    int n;
    cin>>n;
    ldb p[n];
    for(int i=0;i<n;i++)
        cin>>p[i];
    int x=(n-1)/2;
    ldb dp[n][x+1];
    for(int i=0;i<n;i++)
        for(int j=0;j<=x;j++)
            dp[i][j]=0;
    dp[0][0]=p[0];
    dp[0][1]=1-p[0];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=p[i]*dp[i-1][0];
        for(int j=1;j<=min(i+1,x);j++)
        {
            dp[i][j]=dp[i-1][j]*p[i];
            dp[i][j]+=dp[i-1][j-1]*(1-p[i]);
        }
    }
    ldb ans=0;
    for(int i=0;i<=x;i++)
        ans=ans+dp[n-1][i];
    cout<<setprecision(20);
    cout<<ans<<endl;
    return 0;
}


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

#define ll long long
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ii pair < int, int >
#define vi vector < int > 
#define all(a) (a).begin(), (a).end()

using namespace std;

const int MAXN = 2e5 + 10;

void solve() {
	int n;
	cin >> n;
	map < string, int > m;
	for( int i = 0;i < n;i++ ) {
		string s;cin >> s;
		m[ s ]++;
	}
	
	vector < pair < int, string > > v;
	for( pair < string, int > i : m ) {
		v.pb( mp( i.y, i.x ) );
	}
	sort( all( v ) );
	vector < string > v1;
	for( int i = 0;i < ( int )v.size();i++ ) {
		if ( v[ i ].x == v.back().x ) v1.pb( v[ i ].y );
	}
	sort( all( v1 ) );
	for( int i = 0;i < ( int )v1.size();i++ ) cout << v1[ i ] << "\n";
}

int main() {
	int t = 1;
	//cin >> t;
	while ( t-- ) solve();
	return 0;
}


Measured memory_bytes: 32368
L = int(input())
s = input()
t = input()
if not s+t <= t+s:
    s, t = t, s
ls = len(s); lt = len(t)
for i in range(L // ls, -1, -1):
    if (L - ls*i) % lt == 0:
        ans = s * i + t * ((L - ls*i) // lt)
        break
print(ans)

Measured memory_bytes: 46832
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n,m;
    cin>>n>>m;
    int a[n],cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    SRT(a,n);
    REV(a,n);
    for(int i=0;i<m;i++)
    {
        cnt+=a[i];
    }
    cout<<cnt<<NL;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>
#include<iomanip>

#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    ll K,N;
    cin>>N>>K;
    vector<ll> p(N);
    vector<double> p_sum(N,0);
    rep(i,0,N)cin>>p[i];
    double p_sum_max=p[0]+1;
    p_sum[0]=p[0]+1;
    rep(i,1,K){
        p_sum[i]+=(p_sum[i-1]+p[i]+1);
        if(p_sum_max<p_sum[i]){
            p_sum_max=p_sum[i];
        }
    }
    rep(i,K,N){
        p_sum[i]+=p_sum[i-1]+p[i];
        p_sum[i]-=p[i-K];
        if(p_sum_max<p_sum[i]){
            p_sum_max=p_sum[i];
        }
    }
    cout<<fixed << setprecision(15) <<p_sum_max/2;
    return 0;
}

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

inline long long mpow(long long b, long long ex){
    if (b==1)return 1;
    long long r = 1;
    while (ex ){
        if (ex&1)r=(r * b)%mod;
        ex = ex >> 1;
        b = (b * b)%mod;}
    return r;
}

ll modinv(ll a) {
    return mpow(a, mod-2);
}

ll fact(ll a, ll n) {
    ll num = 1, den = 1;
    for (int i = n; i >= n-a+1; i--) num = (num * i) % mod;
    for (int i = a; i >= 1; i--) den = (den * i) % mod;

    return (num * modinv(den)) % mod;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = ((mpow(2, n)-1 - (fact(a, n) + fact(b, n)) % mod) + mod) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 3596
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt().sortedDescending().toIntArray()
    val max = A[0]
    val half = max / 2
    var b1 = 0; var b2 = 0
    for (n in 1 until N) {
        if (half <= A[n]) {
            b1 = A[n]
            b2 = A[n + 1]
        }
    }
    val ans = if (Math.abs(half - b1) <= Math.abs(half - b2)) b1 else b2
    println("${max} ${ans}")
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { it.toInt() + d }


Measured memory_bytes: 56188