akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

string s, t;

int main() {
    cin >> s >> t;

    sort(begin(s), end(s));
    sort(begin(t), end(t), greater<>());

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<long long> A(X);
  for (int i = 0; i < X; i++){
    cin >> A[i];
  }
  vector<long long> B(Y);
  for (int i = 0; i < Y; i++){
    cin >> B[i];
  }
  vector<long long> C(Z);
  for (int i = 0; i < Z; i++){
    cin >> C[i];
  }
  vector<long long> S1;
  for (int i = 0; i < X; i++){
    for (int j = 0; j < Y; j++){
      S1.push_back(A[i] + B[j]);
    }
  }
  sort(S1.begin(), S1.end());
  reverse(S1.begin(), S1.end());
  vector<long long> S2;
  for (int i = 0; i < min((int) S1.size(), K); i++){
    for (int j = 0; j < Z; j++){
      S2.push_back(S1[i] + C[j]);
    }
  }
  sort(S2.begin(), S2.end());
  reverse(S2.begin(), S2.end());
  for (int i = 0; i < K; i++){
    cout << S2[i] << endl;
  }
}

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

using namespace std;
using Int = long long;

const int MAX = 2000;
const int MOD = 1000000007;

Int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
Int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
    Int n, k;
    cin >> n >> k;

    COMinit();

    for(Int i = 1; i <= k; i++){
        cout << (COM(n - k + 1, i) * COM(k-1, i-1)) % MOD << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
p=[]
s=[]
for c in range(m):
    k=input().split()
    p.append(int(k[0])-1)
    s.append(k[1])
a=[0]*n
w=[0]*n
for c in range(m):
    if a[p[c]]==1:
        continue
    if s[c]=="AC":
        a[p[c]]=1
    else:
        w[p[c]]+=1
u=0
for c in range(n):
    if a[c]==1:
        u+=w[c]
print(sum(a),u)

Measured memory_bytes: 14920
n,k=map(int,input().split())
a=list(map(int,input().split()))

#n=10000
#k=n//2
#a=[100000000*(-1)**i for i in range(n)]

mod=pow(10,9)+7
a.sort()
if a[-1]<=0:
  if k%2==0:
    ans=1
    for i in range(k):
      ans*=a[i]
      ans%=mod
    print(ans%mod)
  else:
    ans=1
    for i in range(k):
      ans*=a[-1-i]
      ans%=mod
    print(ans%mod)
elif a[0]>=0:
  ans=1
  for i in range(k):
    ans*=a[-1-i]
    ans%=mod
  print(ans%mod)
else:
  from collections import deque
  a=deque(a)
  ans=1
  while k:
    if k==1:
      ans*=a.pop()
      ans%=mod
      k-=1
    else:
      if a[0]*a[1]>=a[-1]*a[-2]:
        ans*=a.popleft()
        ans*=a.popleft()
        ans%=mod
        k-=2
      else:
        ans*=a.pop()
        ans*=a.pop()
        ans%=mod
        k-=2
  print(ans)
        

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

int Hp,Hpmax;
int R,C;
int T;
char fie[111][111];
int D[256];
int S;
int M[1001];
int P;
int p[13];

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

int dp[1001][(1<<12)];

int main(){
  string s = "UDLR";
  for(int i=0;i<4;i++) dm[(int)s[i]] = i;
  while( cin >> Hp >> Hpmax && (Hp||Hpmax) ){
    cin >> R >> C;
    for(int i=0;i<R;i++)
      for(int j=0;j<C;j++)
	cin >> fie[j][i];

    memset(D,0,sizeof(D));
    memset(dp,0,sizeof(dp));

    cin >> T;
    for(int i=0;i<T;i++){
      char c;
      int d;
      cin >> c >> d;
      D[(int)c] = d;
    }
    cin >> S;
    int cnt = 0;
    int x = 0, y = 0;
    for(int i=0;i<S;i++){
      char c;int n;
      cin >> c >> n;
      for(int j=cnt;j<cnt+n;j++){
	x += dx[dm[(int)c]]; y += dy[dm[(int)c]];
	M[j] = D[(int)fie[x][y]];	
	//	cout << x << " "<< y << " "<< M[j] << endl;
      }
      cnt += n;
    }
    cin >> P;
    for(int i=0;i<P;i++) cin >> p[i];
   

    dp[0][0] = Hp;
    for(int i=0;i<cnt;i++){
      for(int j=0;j<(1<<P);j++){
	if( dp[i][j] == 0 ) continue;
	//	cout << i << " "<< bitset<12>(j) << " "<< dp[i][j] << endl;
	int hp = dp[i][j];
	for(int k=0;k<P;k++){
	  if( ( j & (1<<k) ) ) continue;
	  int nhp = min( hp + p[k] , Hpmax ) - M[i];
	  dp[i+1][j|(1<<k)] = max( dp[i+1][j|(1<<k)], nhp );
	}
	dp[i+1][j] = max( dp[i+1][j], hp - M[i] );      
      }
    }

    bool f = false;
    for(int i=0;i<(1<<P);i++) if( dp[cnt][i] ) f = true;
    cout << (f?"YES":"NO") << endl;

  }

}

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

public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);

                int K = scan.nextInt();
                int A = scan.nextInt();
                int B = scan.nextInt();

                int syou = A/K;
                int hantei = K * syou;

                while (true) {
                        if (hantei > B) {
                                System.out.println("NG");
                                break;
                        }
                        if (hantei >= A) {
                                System.out.println("OK");
                                break;
                        }
                        hantei += K;
                }
        }
}

Measured memory_bytes: 35804
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
int a,b,c,d;
int main()
{
	cin>>a;
	a++;
	while(a--)
	{
		c=a;
		d=0;
		while(c)
		{
			c/=10;
			d++;
		}
		if(d%2==1)
		{
			b++;
		}
	}
	cout<<b<<endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  int h,w,n;
  cin>>h>>w>>n;
  vector<int> vec(h*w);
  rep(i,h)rep(j,w){
    int a,b;
    scanf("%d %d", &a, &b);
    vec[i*w+j] = a*w+b;
  }
  vector<int> p(n);
  rep(i,n){
    int a,b;
    scanf("%d %d", &a, &b);
    p[i] = a*w+b;
  }

  vector<vector<int>> mat(20, vector<int>(h*w));
  rep(i,h*w) mat[0][i] = vec[i];
  repl(i,1,20) rep(j,h*w){
    mat[i][j] = mat[i-1][mat[i-1][j]];
  }

  int l=0, r=2*h*w;
  while(r-l>1){
    int m = (l+r)/2;
    auto exe = [&](int x){
      vector<bool> vis(h*w,false);
      vector<int> v(p);
      int q=0;
      while(x>0){
        if(x%2){
          rep(i,n) v[i] = mat[q][v[i]];
        }
        x /= 2;
        q++;
      }
      rep(i,n){
        if(vis[v[i]]) return true;
        vis[v[i]]=true;
      }
      return false;
    };

    if(exe(m)) r = m;
    else l = m;
  }

  if(r==2*h*w) r=-1;
  cout << r << endl;

  return 0;
}

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

using namespace std;

#define pb push_back
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i <= (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+7; 

const double PI =  3.141592653589793;

int main(){
	IO;
	string s;
	cin>>s;
	(s=="ABC")?cout<<"ARC\n": cout<<"ABC\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 3600
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

ll dp[1010][1010];

void solve() {
  ll H, W;
  cin >> H >> W;
  vector<string> input(H);
  rep (i, H) cin >> input[i];

  rep (i, 1010) rep (j, 1010) dp[i][j] = 0;
  dp[0][0] = 1;
  rep (i, H) rep (j, W) {
    if (input[i][j] != '.') continue;
    if(i == 0 and  j == 0) continue;
    ll tmp = 0;
    if (i > 0 and input[i-1][j] == '.') tmp += dp[i-1][j];
    if (j > 0 and input[i][j-1] == '.') tmp += dp[i][j-1];
    dp[i][j] = tmp % MOD;
  }
  cout << dp[H-1][W-1] << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 9344
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>
 
#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;
 
int main()
{
	string str;cin >> str;
	
	if((str[0] == str[1] && str[1] == str[2])  ||
		(str[1] == str[2] && str[2] == str[3] ))
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
			
		
	
	return 0;
}	

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import Control.Arrow
import Control.Monad
import Control.Monad.ST
import Control.Monad.State.Strict
import Data.Char
import Data.Function
import Data.List
import Data.Maybe
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import qualified Data.ByteString.Unsafe as B

type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
 
parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
 
parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

avg :: Double -> Double -> Double
avg x y = (x+y)/2

main :: IO ()
main = do
 !n <- readLn :: IO Int
 !vs <- U.unfoldrN n parseInt <$> C.getContents :: IO (U.Vector Int)
 let (x1:x2:sorted) = sort $ U.toList $ U.map fromIntegral vs
 print $ foldl avg (avg x1 x2) sorted


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
int main (){
    long long int t1,t2,a1,a2,b1,b2,e1,e2,ans=0;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    
    e1=(a1-b1)*t1;
    e2=(a2-b2)*t2;

    if(e1+e2==0){
        cout << "infinity" << endl;
        return 0;
    }
    if(e1>0 && e2>0){
        cout << 0 << endl;
        return 0;
    }
    if(e1 < 0 && e2 < 0){
        cout << 0 << endl;
        return 0;
    }
    if(e1 > 0 && e2 < 0 && e1+e2>0){
        cout << 0 << endl;
        return 0;
    }    
    if(e1 < 0 && e2 > 0 && e1+e2<0){
        cout << 0 << endl;
        return 0;
    }

    if(e1 > 0 && e2 < 0 && e1+e2<0){
        long long int d=(-1)*(e1+e2);
        if(e1%d==0){
            cout << 2*(e1/d) << endl;
        }else{
            cout << 2*(e1/d)+1 << endl;
        }
        return 0;
    }
    if(e1 < 0 && e2 > 0 && e1+e2>0){
        long long int d=e1+e2,s=(-1)*e1;
        if(s%d==0){
            cout << 2*(s/d) << endl;
        }else{
            cout << 2*(s/d)+1 << endl;
        }
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t x;
    cin >> x;

    cout << (x / 500) * 1000 + (x % 500) / 5 * 5 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define int long long
priority_queue<pair<int,int> >q;
int n,m,b[200100],a[200100],pre[200100],nxt[200100];
signed main(){
    int i,j,k,ans=0;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(i=1;i<=n;i++){
      scanf("%lld",&b[i]);
      q.push(mp(b[i],i));
    }
    for(i=1;i<=n;i++){
      nxt[i]=i+1;
      pre[i]=i-1;
    }
    pre[1]=n;
    nxt[n]=1;
    while(!q.empty()){
      int x=q.top().se;
      q.pop();
      if(b[x]==a[x])continue;
      int y=pre[x],z=nxt[x];
      if(b[x]-b[y]-b[z]<a[x]){
          puts("-1");
          return 0;
      }
      k=b[x]-a[x];
      ans+=k/(b[y]+b[z]);
      b[x]=(k%(b[y]+b[z]))+a[x];
      if(a[x]!=b[x])q.push(mp(b[x],x));
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 10480
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int res = 0;
	for (int i = 1; i < n; i++) {
		int c = 0;
		for (int j = 0; j + i < n; j++) {
			if (s[j] == s[j + i]) {
				c++;
				res = max(res, min(c, i));
			} else {
				c = 0;
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 3648
function main(input) {
  const formatted_input = input.split('\n').map( x => x.split(' ').map( x => parseInt(x, 10) ) );


  const first = formatted_input[0];
  const N = first[0];
  const M =first[1]; 
  const X = first[2];
  const Y = first[3];

  const Xs = formatted_input[1];
  const Ys = formatted_input[2];

  var max_x = -101;
  for(var x of Xs){ max_x = Math.max(x, max_x);}
  max_x = Math.max(X, max_x);

  var min_y = 101;
  for(var y of Ys){ min_y = Math.min(y, min_y);}
  min_y = Math.min(Y, min_y);

  if(max_x < min_y){
    console.log('No War');
  }else{
    console.log('War');
  }




}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 9420
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll h;
    ll x=1,y=0;
    cin>>h;
    while(h>1)
    {
       h/=2;
       y++;
       x+=(pow(2,y));
    }
    cout<<x;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args){

		try {
			InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(isr);
			String buf = br.readLine();
			StringTokenizer st=new StringTokenizer(buf," ");
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());


			if(a < b && b < c)
				System.out.println("Yes");
			else
				System.out.println("No");

		} catch(IOException e) {
			System.err.println(e);
		}
	}
}

Measured memory_bytes: 17000
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    string s; cin>>s;

    int ans=0;
    for(int i=1;i<=N-1;i++){
        int cnt=0;
        for(char c='a';c<='z';c++){
            if(count(s.begin(),s.begin()+i,c) and count(s.begin()+i,s.begin()+N,c)){
                cnt++;
            }
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  sort(a,a+n);
  ll mi=a[n/2-1],ma=a[n/2];
  pr(ma-mi);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1024
#include <stdio.h>
void selectionSort(int *A,int N){
	int i,j,minj,t,count=0;
	for(i=0;i<N;i++){
		minj=i;
		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;
			count++;
		}
	}
    for(i=0;i<N-1;i++) printf("%d ",A[i]);
    printf("%d\n",A[N-1]);
    printf("%d\n",count);
}
int main(void){
	int N,a,i;
	int A[100];
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&a);
		A[i]=a;
	}
	selectionSort(A,N);
	return 0;
}



Measured memory_bytes: 1928
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

int main() {
	vector<int> vec; int n; int set = 0;
	cin >> n; vec.resize(n);
	iota(vec.begin(), vec.end(), 1);
	do {
		for (int i : vec) cout << (set++ ? " " : "") << i;
		cout << endl; set = 0;
	} while (next_permutation(vec.begin(), vec.end()));
	return 0;
}


Measured memory_bytes: 3120
N = input()
count = 0
MM = [i+1 for i in range(12)]
if int(N[:2]) in MM:
    count += 1
if int(N[2:]) in MM:
    count += 2
if count == 1:
    print('MMYY')
elif count == 2:
    print('YYMM')
elif count == 3:
    print('AMBIGUOUS')
else:
    print('NA')

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
typedef long long LL;
typedef pair<int, int> Pair;
const int N = 1000010, INF = 1e9;

int n, m, sz;
int las[N], din[N], dis[N], vis[N];

struct Edge{ int to, pre, w; }e[N];
inline void Add(int a, int b, int c){
	e[++sz]=(Edge){b, las[a], c}; las[a]=sz;
	++din[b];
}

queue<int> Q;
int Topsort(){
	for (int i=1; i<=n; ++i)
		if (!din[i]) Q.push(i);
	while (!Q.empty()){
		int x=Q.front(); Q.pop();
		for (int i=las[x]; i; i=e[i].pre){
			int v=e[i].to;
			if (vis[v] && dis[v]!=dis[x]+e[i].w) return 0;
			vis[v]=1; dis[v]=dis[x]+e[i].w;
			--din[v];
			if (!din[v]) Q.push(v);
		}
	}
	for (int i=1; i<=n; ++i)
		if (din[i]) return 0;
	return 1;
}

int main(){
	scanf("%d%d", &n, &m);
	for (int i=1, l, r, d; i<=m; ++i)
		scanf("%d%d%d", &l, &r, &d), Add(l, r, d);
	if (Topsort()) puts("Yes");
		else puts("No");
	
	return 0;
}

Measured memory_bytes: 12672
#include<bits/stdc++.h>
using namespace std;
#define N 2005
#define ll long long
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<endl;
#define trace(a) cout<<#a<<": "<<a<< endl;

pair<int,int> a[2*N];
string t[2*N];
int dp[N][N],psb[2*N][N],psw[2*N][N],pos[3][N];
int n;
int rec(int b,int w) {
	if(b == 0 && w == 0) {
		return 0;
	}
	if(dp[b][w] != -1) return dp[b][w];
	// vector<pair<int,int> > v;
	// for(int i = 0;i < 2*n;i++) {
	// 	if(a[i].second == 1) {
	// 		if(a[i].first > n-b) {
	// 			v.push_back(a[i]);
	// 		}
	// 	}
	// 	else {
	// 		if(a[i].first > n-w) {
	// 			v.push_back(a[i]);
	// 		}
	// 	}
	// }
	// trace(v.size());
	int ans = 1e9;
	if(b > 0) {
		int index = pos[1][n-b+1];
		int cnt = psw[index][n-w] + psb[index][n-b+1];
		// for(auto it : v) {
			
		// 	if(it.second == 1 && it.first == n-b+1) {
		// 		break;
		// 	}
		// 	cnt++;
		// }
		ans = min(ans,rec(b-1,w) + cnt);
	}
	if(w > 0) {
		int index = pos[2][n-w+1];
		int cnt = psb[index][n-b] + psw[index][n-w+1];
		// for(auto it : v) {
		// 	if(it.second == 2 && it.first == n-w+1) {
		// 		break;
		// 	}
		// 	cnt++;
		// }
		ans = min(ans,rec(b,w-1) + cnt);
	}
	// cout << b << " " << w << " " << ans << endl;
	return dp[b][w] = ans;
}
// int solve(int n) {
// 	int i,j,k,l,m;
// 	int ans = 0;
// 	for(i = 0;i < 2*n;i++) {
// 		for(j = i - 1;j >= 0;j--) {
// 			if(mark[j]) continue;
// 			if(t[i] == t[j]) {
// 				if(a[j] > a[i]) {

// 				}
// 			}

// 		}
// 	}
// 	return ans;
// }
int main() {
	ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
	int i,j,k,l,m;
	cin >> n;
	for(i = 0;i < 2*n;i++) {
		cin >> t[i] >> a[i].first;
		if(t[i] == "B") {
			a[i].second = 1;
		}
		else {
			a[i].second = 2;
		}
		pos[a[i].second][a[i].first] = i;
	}
	for(int w = 0;w <= n;w++) {
		for(i = 0;i < 2*n;i++) {
			if(i > 0)
				psw[i][w] = psw[i-1][w];
			if(a[i].second == 2 && a[i].first > w) {
				psw[i][w]++;
			}
		}
	}
	for(int b = 0;b <= n;b++) {
		for(i = 0;i < 2*n;i++) {
			if(i > 0)
				psb[i][b] = psb[i-1][b];
			if(a[i].second == 1 && a[i].first > b) {
				psb[i][b]++;
			}
		}
	}
	memset(dp,-1,sizeof(dp));
	cout << rec(n,n) << endl;
	// int an = min(rec(n,n,0),rec(n,n,1));
	// cout << an << endl;
}

Measured memory_bytes: 79232
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
    static long[] dp;
    public static void main(String[] args)throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] s=br.readLine().split(" ");
        int n=Integer.parseInt(s[0].trim());
        int m=Integer.parseInt(s[1].trim());
        ArrayList<ArrayList<Integer>> al=new ArrayList<>();
        for(int i=0;i<n;i++){
            al.add(new ArrayList<>());
        }
        int[] dist=new int[n];
        dp=new long[n];
        Arrays.fill(dp,-1);

        while(m-->0){
            s=br.readLine().split(" ");
            int u=Integer.parseInt(s[0].trim())-1;
            int v=Integer.parseInt(s[1].trim())-1;
            al.get(u).add(v);
        }
//        System.out.println(algo(al););
        boolean[] vis=new boolean[n];
        long res=0;
          for(int i=0;i<n;i++){
//            Arrays.fill(vis,false);
            res=Math.max(dfs(al,i),res);

          }
          System.out.println(res);

    }


    public static long dfs(ArrayList<ArrayList<Integer>> al,int u){

        if(dp[u]!=-1){
            return dp[u];
        }
        long res=0;
        for(int v:al.get(u)){
                res=Math.max(res,1+dfs(al,v));
        }
        dp[u]=res;
        return res;
    }




    public static void algo(ArrayList<ArrayList<Integer>> al,int[] dist,int u,boolean[] vis){
        dist[u]=0;
        vis[u]=true;
        Queue<Integer> q=new LinkedList<>();
        q.add(u);
        while(!q.isEmpty()){
        int u1=q.poll();
        for(int v:al.get(u1)){
            if(dist[v]==0)
            {
                vis[v]=true;
                dist[v]=Math.max(dist[v],1+dist[u1]);
                q.add(v);
            }
        }

        }

    }







}





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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define mp(i,j) make_pair(i,j)
#define debug_v(v,N) for(int i=0;i<N;i++) { cout << v[i] << " "; } cout << endl;
#define debug_vv(v,H,W) for(int i=0;i<H;i++) { for(int j=0;j<W;j++) { cout << v[i][j] << " "; } cout << endl; }

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

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

void Main()
{
	int N; cin >> N;
	int _min = 1e9 + 10;
	int _max = -1e9 - 10;
	rep(i,N) {
		int a; cin >> a;
		chmin(_min, a);
		chmax(_max, a);
	}
	cout << (_max - _min) << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	vi a(3); cin >> a;
	sort(ALL(a));
	cout << a[2] - a[1] + a[1] - a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
from functools import reduce
import sys
from operator import xor


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _ = _i()
    a = list(_ia())
    s = reduce(xor, a, 0)
    return " ".join(map(str, map(lambda x: s ^ x, a)))


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


Measured memory_bytes: 112136
from collections import defaultdict
N, K, L = map(int, input().split())


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF_road = UnionFind(N)
for k in range(K):
    p, q = map(int, input().split())
    p, q = p - 1, q - 1
    UF_road.union(p, q)
UF_road.all_find()

UF_train = UnionFind(N)
for l in range(L):
    r, s = map(int, input().split())
    r, s = r - 1, s - 1
    UF_train.union(r, s)
UF_train.all_find()

D = defaultdict(int)
for r, t in zip(UF_road.par, UF_train.par):
    D[(r, t)] += 1

ans = [D[(r, t)] for r, t in zip(UF_road.par, UF_train.par)]
print(*ans, sep=' ')


Measured memory_bytes: 53748
package main

import "fmt"

const Mod = 1000000007

var empty = byte('.')

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	grid := make([][]byte, h)
	for i := 0; i < h; i++ {
		var b []byte
		fmt.Scan(&b)
		grid[i] = b
	}

	var dp [1001][1001]int
	dp[0][0] = 1

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if grid[i][j] != empty {
				continue
			}
			if i == 0 && j == 0 {
				dp[i][j] = 1
				continue
			}
			if i == 0 {
				dp[i][j] = dp[i][j-1]
				continue
			}
			if j == 0 {
				dp[i][j] = dp[i-1][j]
				continue
			}

			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % Mod
		}
	}

	fmt.Println(dp[h-1][w-1])
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll max_N = 55, MOD = 1e9 + 7;
ll N, K;
vector<vector<ll>> adj;

vector<vector<ll>> matrix_multiply(vector<vector<ll>> A, vector<vector<ll>> B)
{
    vector<vector<ll>> res(N, vector<ll>(N, 0));
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            for (int k = 0; k < N; ++k)
            {
                res[i][j] += (A[i][k] * B[k][j]) % MOD;
                res[i][j] %= MOD;
            }
    return res;
}

vector<vector<ll>> matrix_expo(vector<vector<ll>> mat, ll y)
{
    vector<vector<ll>> res(N, vector<ll>(N, 0));
    for (int i = 0; i < N; ++i)
        res[i][i] = 1;
    vector<vector<ll>> base = mat;
    while (y)
    {
        if (y & 1)
            res = matrix_multiply(res, base);
        base = matrix_multiply(base, base);
        y >>= 1;
    }
    return res;
}

int main()
{
    cin >> N >> K;
    vector<ll> temp;
    ll x;
    for (int i = 0; i < N; ++i)
    {
        temp.clear();
        for (int j = 0; j < N; ++j)
            cin >> x, temp.push_back(x);
        adj.push_back(temp);
    }
    adj = matrix_expo(adj, K);
    ll ans = 0;
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
        {
            ans += adj[i][j];
            ans %= MOD;
        }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int H, W;
  cin >> H >> W;
  vector<string> C(H + 1);
  for (int i = 1; i < H + 1; i++) {
    cin >> C[i];
  }

  for (int i = 1; i < 2 * H + 1; i++) {
    cout << C[(i + 1) / 2] << "\n";
  }
  return 0;
}


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

cnt = 1
ans = float("inf")

while cnt ** 2 <= N:

    now = 0

    if N % cnt == 0:

        now = N // cnt

        keta = 1
        while True:

            if 10 ** keta > now:
                break
            keta += 1

        ans = min (keta,ans)

    cnt += 1

print (ans)


Measured memory_bytes: 39152
def calc(n)
  result = 0
  (1..n).each do |i|
    if i < 10
      result += 1
    else
      str = i.to_s
      digits = str.length - 2
      next if str[-1] == "0"
      if str[0] < str[-1]
        result += [0, 1, 11, 111, 1111][digits] * 2
      elsif str[0] > str[-1]
        result += [1, 11, 111, 1111, 11111][digits] * 2
      else
        result += [1, 2, 12, 112, 1112][digits] * 2
        result += (str[1..-2].to_i + 1) * 2 - 1
      end
    end
  end
  result
end

puts calc(gets.to_i)

Measured memory_bytes: 1788
class Inv:
  def __init__(s, mod):
    s.MOD = mod
  def modpow(s, a, n):
    res = 1
    while n > 0:
      if n & 1:
        res = res * a % s.MOD
      a = a * a % s.MOD
      n >>= 1
    return res
  def invx(s, a):
    return s.modpow(a, s.MOD - 2)
  def invpowL(s, a, n): # a^-x (0 <= x <= n)リスト
    ia = s.invx(a)
    L = [1] * (n + 1)
    for i in range(1, n + 1):
      L[i] = L[i - 1] * ia % s.MOD
    return L
  def invL(s, n): # 0 <= x <= n 逆元リスト
    I = [0, 1]
    for i in range(2, n + 1):
      I.append(s.MOD - I[s.MOD % i] * (s.MOD // i) % s.MOD)
    return I


N, S = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 998244353

DP = [[0] * (S + 1) for _ in range(N + 1)]

inv = Inv(MOD)
v = inv.invx(2)

p = inv.modpow(2, N - 1)
for i in range(1, N + 1):
  a = A[i - 1]
  if a > S: 
    for j in range(S + 1):
      DP[i][j] = DP[i - 1][j]
    continue
  for j in range(a):
    DP[i][j] = DP[i - 1][j]
  DP[i][a] = (DP[i - 1][a] + p) % MOD
  for j in range(a + 1, S + 1):
    DP[i][j] = (DP[i - 1][j] + DP[i - 1][j - a] * v) % MOD

print(DP[-1][S])


Measured memory_bytes: 132256
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << min({a*b,c}) << endl;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    
    string s;
    cin>>s;

    if(s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;

}
/*


*/


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c; cin >> a >> b >> c;
    cout << (a + b >= c ? "Yes" : "No") << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int a[3];
  for(int i = 0; i < 3; i++){
  cin >> a[i];
  }
  sort(a,a+3);
  int ans = 0;
  for(int i = 1; i < 3; i++){
  ans += (a[i]-a[i-1]);
  }
  
  cout << ans << endl;
  
  
}

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

int main() {

  int N;
  cin >> N;
  vector<double> x(N),y(N);
  for(int i = 0;i < N;i++) {
    cin >> x.at(i) >> y.at(i);
  }

  double sum = 0;
  for(int i = 0;i < N-1;i++) {
    for(int j = i+1;j < N;j++) {
      double dx = x.at(i)-x.at(j),dy = y.at(i)-y.at(j);
      sum += sqrt(dx*dx+dy*dy);
    }
  }

  cout << fixed << setprecision(10);
  cout << sum*2 / N << endl;


}



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

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N;
    cin >> N;
    cout << N*N*N << endl;

    return 0;
}


Measured memory_bytes: 256
n,p = map(int,input().split())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

lst = factorization(p)
lst = sorted(lst,reverse=True,key=lambda x:x[1])
ans = 1
for i in lst:
  tmp=i[1]
  while tmp>=n:
      if tmp>=n:
        ans *= i[0]
        tmp -= n
      
print(ans) 

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

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

  int count = 0;
  for (int i = 1; i <= N; ++i){
    cin >> a;
    if ((i % 2 == 1) && (a % 2 == 1)){
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 3556
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		int K = in.nextInt();
		for (int i = 0; i < K; ++i) {
			if (i % 2 == 0) {
				if (A % 2 == 1) {
					A = A - 1;
				}
				A /= 2;
				B += A;
			} else {
				if (B % 2 == 1) {
					B -= 1;
				}
				B /= 2;
				A += B;
			}
		}
		System.out.println(A + " " + B);
		in.close();
	}
}

Measured memory_bytes: 23636
fn main() {
    let v = read_vec::<u64>();
    let a = v[0];
    let b = v[1];
    let x = v[2];
    let extra = if a % x == 0 { 1 } else { 0 };
    println!("{}", b / x - a / x + extra);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

const int MAX = 510000;
const int MOD = 1000000007;
const int MAX_N = 200000;

int ctoi(const char c){
 switch(c){
   case '0': return 0;
   case '1': return 1;
   case '2': return 2;
   case '3': return 3;
   case '4': return 4;
   case '5': return 5;
   case '6': return 6;
   case '7': return 7;
   case '8': return 8;
   case '9': return 9;
   default : return -1;
 }
}

ll N,M;
vector<ll> A;
ll check(ll X){
    ll sum = 0;
  for(ll i=0;i<N;i++){
    // A[j]=X-A[i]以上の個数をカウント：O(logN)
    sum  +=  N - (lower_bound(A.begin(),A.end(),X-A[i]) - A.begin());
  }
  return sum;
}

int main(int argc, const char * argv[]) {
  cin >> N >> M;
  A = vector<ll>(N);
  for(ll i=0;i<N;i++) cin >> A[i];
  sort(A.begin(),A.end());
  // ll left = 0, right = A[N-1]*2;
  ll left = 0, right = 1000000000;
  while(right-left>1){
    ll mid = (left+right)/2;
    if(check(mid)<M) right = mid;
    else{ left = mid; }
  }

  vector<ll> S(N+1);
  for(ll i=0;i<N;i++) S[i+1]=S[i]+A[i];

  ll left_M=0,right_M=0;
  for(ll i=0;i<N;i++)  left_M += A.end() - lower_bound(A.begin(),A.end(),left-A[i]);
  for(ll i=0;i<N;i++)  right_M += A.end() - lower_bound(A.begin(),A.end(),right-A[i]);

  // printf("left:%ld Msize:%ld   right:%ld Msize:%ld \n",left,left_M,right,right_M);

  ll ans=0;
  ll cnt=0;
  for(ll i=0;i<N;i++){
    // X - A[i] 以下の個数を求める
    ll pos = upper_bound(A.begin(),A.end(),left-A[i]) - A.begin();
    // X - A[i] を超える値の個数を求める
    cnt = N - pos;
    // cout << "cnt :" << cnt << "  " << cnt*A[i]<< endl;
    // 数をカウント
    ans += cnt*A[i] + S[N]-S[pos];
    M -= cnt;
  }

  // cout << "M*left : " <<M << " * " <<left<< " == " << M*left << endl;
  ans += M * left;

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


Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
import random
import time
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() 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)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def scorei(ti, i, last, minus):
        k = [i for i in last]
        mi = minus-(i+1-last[ti])*c[ti]
        v = s[i][ti]-mi
        mi += sum_
        k[ti] = i+1
        return v, k, mi

    def score(t):
        n = 26
        v = 0
        minus = sum_ = sum(c)
        last = [0]*n
        for i in range(d):
            ti = t[i]-1
            minus -= (i+1-last[ti])*c[ti]
            v += s[i][ti]-minus
            minus += sum_
            last[ti] = i+1
        return v
    start = time.time()
    d = I()
    c = LI()
    s = LIR(d)
    n = 26
    m = 20
    sum_ = sum(c)
    q = [(0, [], [0]*n, sum_)]
    argmax = 0
    for i in range(d):
        nq = []
        for _ in range(m):
            if not q:
                break
            v, t, last, minus = heappop(q)
            for ti in range(n):
                nt = [i for i in t]
                vi,nl,nm = scorei(ti,i,last,minus)
                nv = v-vi
                nt.append(ti)
                heappush(nq,(nv,nt,nl,nm))
        q = [i for i in nq]
    t = [i+1 for i in heappop(q)[1]]
    v = score(t)
    i = 0
    while time.time() < 1.8+start:
        nt = [i for i in t]
        r = random.randrange(1,n+1)
        nt[i] = r
        nv = score(nt)
        if v < nv:
            t = [i for i in nt]
            v = nv
        i += 1
        i %= d
    for i in t:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A.at(i);
  sort (A.begin(), A.end());
  bool flag = true;
  for (int i=1; i<N; i++) {
    if (A.at(i-1) == A.at(i)) {
      flag = false;
      break;
    }
  }
  if (flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int rem1[200005], rem2[200005];

int find(int n)
{
    if(n == 0)
        return 0;
    return 1 + find(n%(__builtin_popcount(n)));
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    int n;
    cin >> n;
    cin >> s;
    int rem = 0;
    for(int i=0; i<n; i++)
    {
        rem += (s[i] == '1');
    }
    if(rem == 0)
    {
        for(int i=0; i<n; i++)
        {
            cout << 1 << "\n";
        }
        return 0;
    }

    if(rem == 1)
    {
        for(int i=0; i<n; i++)
        {
            if(s[i] == '1')
            {
                cout << 0 << "\n";
            }
            else
            {
                if(i==n-1 || s[n-1] == '1')
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
        }
        return 0;
    }
    int prev1 = -1, prev2 = -1;
    int ind1=0, ind2=0;
    rem1[0] = rem2[0] = 1;
    for(int i=1; i<n; i++)
    {
        rem1[i] = (rem1[i-1] * 2) % (rem-1);
        rem2[i] = (rem2[i-1] * 2) % (rem+1);
    }
    //what_is(rem);
    for(int i=0; i<n; i++)
    {
        if(s[i] == '1')
        {
            if(prev1 == -1)
            {
                prev1 = 0;
                //compute for first time
                for(int j=n-1; j>=0; j--)
                {
                    if(s[j] == '1' && j != i)
                        prev1 = (prev1 + rem1[n-1-j])%(rem-1);
                }
            }
            else
            {
                prev1 = (prev1 + rem1[n-1-ind1]) % (rem-1);
                prev1 = (prev1 + rem - 1 - rem1[n-1-i]) % (rem-1);
            }
            //what_is(ind1);
            ind1 = i;
            //what_is(prev1);
            cout << 1 + find(prev1) << "\n";
        }
        else
        {
            if(prev2 == -1)
            {
                prev2 = 0;
                //compute for first time
                for(int j=n-1; j>=0; j--)
                {
                    if(s[j] == '1' || j == i)
                        prev2 = (prev2 + rem2[n-1-j])%(rem+1);
                }
            }
            else
            {
                prev2 = (prev2 + rem + 1 - rem2[n-1-ind2]) % (rem+1);
                prev2 = (prev2 + rem2[n-1-i]) % (rem+1);
            }
            ind2 = i;
            cout << 1 + find(prev2) << "\n";
        }
    }

    return 0;
}


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

using namespace std;

int main() {
	int A, B, C; cin >> A >> B >> C;

	auto count = array<int, 11>{};
	count[A]++; count[B]++; count[C]++;

	cout << (count[5] == 2 && count[7] == 1 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
MAP = [[0] * N for i in range(N)]
for i in range(M):
  L, R = map(int, input().split())
  MAP[L-1][R-1] += 1

for r in range(N):
  for l in range(N-1, 0, -1):
    MAP[l-1][r] += MAP[l][r]

for r in range(N-1):
  for l in range(N):
    MAP[l][r+1] += MAP[l][r]

for i in range(Q):
  p, q = map(int, input().split())
  print(MAP[p-1][q-1])

Measured memory_bytes: 11120
from heapq import heappop,heappush
def dijkstra(s,n,edge):
  inf=10**20
  ans=[inf]*n
  ans[s]=0
  h=[[0,s]]
  while h:
    c,v=heappop(h)
    if ans[v]<c:continue
    for u,t in edge[v]:
      if c+t<ans[u]:
        ans[u]=c+t
        heappush(h,[c+t,u])
  return ans
n=int(input())
edge=[[]for _ in range(n)]
for i in range(n-1):
  a,b,c=map(int,input().split())
  a-=1;b-=1
  edge[a].append([b,c])
  edge[b].append([a,c])
q,k=map(int,input().split())
k-=1
xy=[list(map(int,input().split()))for _ in range(q)]
for i in range(q):xy[i][0]-=1;xy[i][1]-=1
edge=dijkstra(k,n,edge)
for x,y in xy:print(edge[x]+edge[y])

Measured memory_bytes: 81788
N, K = map(int,input().split())
x = list(map(int,input().split()))
y = []

for i in range(N-K+1):
    l1 = abs(x[i])
    l2 = abs(x[i+K-1])
    if x[i]* x[i+K-1] > 0:
        y.append(max(l1,l2))
    else:
        
        y.append(2*min(l1,l2) + max(l1,l2))

print(min(y))

Measured memory_bytes: 14384
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[0]*M
B=[0]*M
for i in range(M):
  A[i],B[i]=map(int,input().split())
C=[]
for j in range(M):
  if H[A[j]-1]>H[B[j]-1]:
               C.append(B[j])
  elif H[A[j]-1]==H[B[j]-1]:
               C.append(A[j])
               C.append(B[j])
  else:
               C.append(A[j])
c=set(C)
d=list(c)               
print(N-len(d))  

Measured memory_bytes: 24496
N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
deg = [0] * (N+1)
for i in range(M):
    x, y = map(int, input().split())
    G[x].append(y)
    deg[y] += 1
G[0] = list(range(1, N+1))
for i in range(1,N+1):
    deg[i] += 1

from collections import deque
topo = [0]
deq = deque(topo)

while deq:
    v = deq.popleft()
    for t in G[v]:
        deg[t] -= 1
        if deg[t] == 0:
            topo.append(t)
            deq.append(t)

dp = [-1] * (N+1)
for v in topo:
    for t in G[v]:
        dp[t] = max(dp[t], dp[v] + 1)

print(max(dp))

Measured memory_bytes: 94132