akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
        if (m == -1 && f == -1 && r == -1){
            break;
        }else{
            if(m == -1 || f == -1){
                System.out.printf("F\n");
            }else if(m + f >= 80){
                System.out.printf("A\n");
            }else if(m + f >= 65) {
                System.out.printf("B\n");
            }else if(m + f >= 50) {
                System.out.printf("C\n");
            }else if(m + f >= 30){
                if(r >= 50) {
                    System.out.printf("C\n");
                }else{
                    System.out.printf("D\n");
                }
            }else{
                System.out.printf("F\n");
            }
        }
        }
    }
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  long long K;
  cin >> K;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      if (K == 1) {
        cout << s[i] << endl;
        return 0;
      }
      K--;
    } else {
      cout << s[i] << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(void){
    int n,k,l; cin>>n>>k>>l;
    struct UnionFind tree(n+100);
    for(int i=0;i<k;i++){
        int p,q; cin>>p>>q; p--; q--;
        tree.unite(p,q);
    }
    map<pair<int, int>, int> mp;
    struct UnionFind tree2(n+100);
    for(int i=0;i<l;i++){
        int a,b; 
        cin>>a>>b; a--; b--;
        tree2.unite(a,b);
    }
    vector <int> r(210000);
    int a[300000],b[300000];
    for(int i=0;i<=n;i++){
        a[i] = tree.root(i);
        b[i] = tree2.root(i);
        mp[{a[i], b[i]}]++;
    }
    for(int i = 0;i < n;i++){
    cout << mp[{a[i], b[i]}] <<' ';
  }
}


Measured memory_bytes: 15872
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

const int MAX = 50;

int sp2i(string str, int p)
{
	string::iterator s, g;
	s = str.begin();
	for (int i=0; i<p; i++)
	{
		s = find(s, str.end(), ',');
		s++;
	}
	g = find(s, str.end(), ',');
	string t = string(s, g);
	int c = 0;
	for (int i=0; i<t.size(); i++)
	{
		c *= 10;
		c += t[i] - '0';
	}

	return c;
}

int main()
{
	int d[MAX][MAX];
	memset(d, 0, sizeof(d));

	vector<string> dt;
	string s;
	while (cin >> s)
	{
		dt.push_back(s);
	}

	int S = dt.size();
	int N = S / 2;

	for (int i=0; i<=N; i++)
	{
		for (int j=0; j<=i; j++)
		{
			d[i-j][j] = sp2i(dt[i], j);
		}
	}

	for (int i=N; i>=1; i--)
	{
		for (int j=0; j<i; j++)
		{
			d[N-j][N-i+j+1] = sp2i(dt[S-i], j);
		}
	}

	int dp[MAX][MAX];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = d[0][0];
	for (int i=1; i<=N; i++)
	{
		dp[i][0] = dp[i-1][0] + d[i][0];
		dp[0][i] = dp[0][i-1] + d[0][i];
	}

	for (int i=1; i<=N; i++)
	for (int j=1; j<=N; j++)
	{
		dp[i][j] = d[i][j] + max(dp[i-1][j], dp[i][j-1]);
	}

	cout << dp[N][N] << endl;

	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int n = sc.nextInt();
    int[] a = new int[n + 1];
    for (int i = 1; i <= n; i++) {
      a[i] = sc.nextInt();
    }
    int[][] matrix = new int[h][w];
    int row = 0;
    int col = 0;
    for (int i = 1; i <= n; i++) {
      int num = a[i];
      while(row < h && num != 0) {
        while(row % 2 == 0 && row < h && col < w && num != 0) {
          matrix[row][col] = i;
          col++;
          num--;
        }
        if (col == w) {
          row++;
          col--;
        }
        while(row % 2 == 1 && row < h && col >= 0 && num != 0) {
          matrix[row][col] = i;
          col--;
          num--;
        }
        if (col == -1) {
          row++;
          col++;
        }
      }
    }
    for (int r = 0; r < h; r++) {
      for (int c = 0; c < w; c++) {
        System.out.print(matrix[r][c] + " ");
      }
      System.out.println();
    }
  }
}


Measured memory_bytes: 34308
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;

int main() {
	int D, G;
	cin >> D >> G;
	cout << (D-1)*(G-1) << endl;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const ll LINF = 1e11;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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


void solve() {
    string s;
    cin >> s;

    int cnt= 0;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i] == 'o'){
            cnt ++;
        }
    }
    string ans = "NO";
    if(cnt + 15 - s.size() >= 8){
        ans = "YES";
    }

    cout << ans << "\n";
}


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

    solve();
    return 0;
}


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;

int main() {
    cin >> n;
    Vs s(2);
    cin >> s[0] >> s[1];

    Vi v; char c = s[0][0];
    int i = 1;
    if (n == 1) v.push_back(0);
    while (i < n) {
        if (c == s[0][i]) {
            v.push_back(1);
            if (i+1 >= n) break;
            c = s[0][i+1];
            i++;
        } else {
            v.push_back(0);
            c = s[0][i];
        }
        if (i+1 >= n) {
            v.push_back(0);
            break;
        }
        i++;
    }

    ll res = 1;
    if (v[0] == 0) res *= 3;
    else res *= 6;
    REP2(i, 1, v.size()) {
        if (v[i] == 0) {
            if (v[i-1] == 0) res *= 2;
        } else {
            if (v[i-1] == 0) res *= 2;
            else res *= 3;
        }
        res %= MOD;
    }
    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
bool visited[1001][1001][1001];
//------------------------------------------------------------------------------
void _main()
{
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X);
    vector<ll> B(Y);
    vector<ll> C(Z);
    rep(i, 0, X) cin >> A[i];
    rep(i, 0, Y) cin >> B[i];
    rep(i, 0, Z) cin >> C[i];
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());

    vector<ll> ans;

    priority_queue<tuple<ll, int, int, int>> q;
    q.push(make_tuple(A[0] + B[0] + C[0], 0, 0, 0));

    while (!q.empty())
    {
        ll sum;
        int x, y, z;
        tie(sum, x, y, z) = q.top();

        q.pop();

        ans.push_back(sum);

        if (ans.size() >= K) break;

        if (x + 1 < X)
        {
            if (!visited[x + 1][y][z])
            {
                q.push(make_tuple(A[x + 1] + B[y] + C[z], x + 1, y, z));
                visited[x + 1][y][z] = true;
            }
        }
        if (y + 1 < Y)
        {
            if (!visited[x][y + 1][z])
            {
                q.push(make_tuple(A[x] + B[y + 1] + C[z], x, y + 1, z));
                visited[x][y + 1][z] = true;
            }
        }
        if (z + 1 < Z)
        {
            if (!visited[x][y][z + 1])
            {
                q.push(make_tuple(A[x] + B[y] + C[z + 1], x, y, z + 1));
                visited[x][y][z + 1] = true;
            }
        }
    }

    for(const auto a : ans)
    {
        cout << a << endl;
    }
}


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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    int[] dp = new int[h + 1];
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    for (int i = 1; i < h + 1; i++) {
      int magic_point = 0;
      for(int j = 0; j < n; j++) {
        if(i - a[j] < 0) {
          magic_point = b[j];
        } else {
          magic_point = b[j] + dp[i -a[j]];
        }
        if(magic_point < dp[i] || dp[i] == 0) {
          dp[i] = magic_point;
        }
      }
    }
    System.out.println(dp[h]);
  }
}

Measured memory_bytes: 27972
import sys
input=sys.stdin.readline
import bisect

def main():
    _,T = map(int, input().split())
    P = list(map(int, input().split()))
    ans = start = end = 0
    for p in P:
        if start == 0 and end == 0:
            end = T
        else:
            if p < end:
                end = p + T
            else:
                ans += end - start
                start = p
                end = p + T
    ans += end - start
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25748
<?php
    fscanf(STDIN,"%d",$n);
    $i=1;

    while(true){
        $flag=false;
        if($i%3==0){
            $flag=true;
        }
        $a=$i;
        while($a>0){
            if($a%10==3){
                $flag=true;
            }
            $a/=10;
        }
        if($flag){
            echo " ".$i;
        }
        if($i==$n)break;
        $i++;
    }
    echo "\n";

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

//////////////////ここの値は必ず確認！！！！！////////////////////
//---------------------------------------------------------//
const int MOD = 998244353;
const int MAXR = 510000;
//---------------------------------------------------------//

template<ll mod> class modint{
public:
    ll val=0;
    //コンストラクタ
    modint(ll x=0){while(x<0)x+=mod;val=x%mod;}
    //コピーコンストラクタ
    modint(const modint &r){val=r.val;}
    //算術演算子
    modint operator -(){return modint(-val);} //単項
    modint operator +(const modint &r){return modint(*this)+=r;}
    modint operator -(const modint &r){return modint(*this)-=r;}
    modint operator *(const modint &r){return modint(*this)*=r;}
    modint operator /(const modint &r){return modint(*this)/=r;}
    //代入演算子
    modint &operator +=(const modint &r){
        val+=r.val;
        if(val>=mod)val-=mod;
        return *this;
    }
    modint &operator -=(const modint &r){
        if(val<r.val)val+=mod;
        val-=r.val;
        return *this;
    }
    modint &operator *=(const modint &r){
        val=val*r.val%mod;
        return *this;
    }
    modint &operator /=(const modint &r){
        ll a=r.val,b=mod,u=1,v=0;
        while(b){
            ll t=a/b;
            a-=t*b;swap(a,b);
            u-=t*v;swap(u,v);
        }
        val=val*u%mod;
        if(val<0)val+=mod;
        return *this;
    }
    //等価比較演算子
    bool operator ==(const modint& r){return this->val==r.val;}
    bool operator <(const modint& r){return this->val<r.val;}
    bool operator !=(const modint& r){return this->val!=r.val;}
};

using mint = modint<MOD>;

//入出力ストリーム
istream &operator >>(istream &is,mint& x){//xにconst付けない
    ll t;is >> t;
    x=t;
    return (is);
}
ostream &operator <<(ostream &os,const mint& x){
    return os<<x.val;
}

//累乗
mint modpow(const mint &a,ll n){
    if(n==0)return 1;
    mint t=modpow(a,n/2);
    t=t*t;
    if(n&1)t=t*a;
    return t;
}

//二項係数の計算
mint fac[MAXR+1],finv[MAXR+1],inv[MAXR+1];
//テーブルの作成
void com_init() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    FOR(i,2,MAXR){
        fac[i]=fac[i-1]*mint(i);
        inv[i]=-inv[MOD%i]*mint(MOD/i);
        finv[i]=finv[i-1]*inv[i];
    }
}
//演算部分
mint com(ll n,ll k){
    if(n<k)return 0;
    if(n<0)return 0;
    if(k==0) return 1;
    return fac[n]*finv[k]*finv[n-k];
}

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

    mint ans = 0;
    com_init();
    REP(k,K+1){
        ans += com(N-1, k) * M * modpow(M-1, N-1-k);
    }

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

Measured memory_bytes: 15564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N, T; cin >> N >> T;
    VI A(N);
    VI MAX_A(N);
    VI diff(N);
    REP(i,N)
    {
        cin >> A[i];
    }
    int tmpmax = 0;

    for(int i = N - 1; i >= 0; i--)
    {
        MAX_A[i] = max(tmpmax, A[i]);
        tmpmax = MAX_A[i];
        dump(MAX_A[i])
    }
    REP(i,N-1)
    {
        diff[i] = MAX_A[i+1] - A[i];
        dump(diff[i])
    }
    sort(diff.begin(), diff.end(), greater<int>());
    LL difmax = diff[0];
    int ans = 0;
    REP(i,N-1)
    {
        if(diff[i] == difmax) ans++;
        else break;
    }
    cout << ans << endl;

}


Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int M, K;

int main() {
    fastio();
    cin >> M >> K;
    if((1 << M) <= K || (M == 1 && K == 1)) {
        printf("-1");
    	return 0;
    }
    if (M == 0 && K == 0) {
        printf("0 0");
        return 0;
    }
    if (M == 1 && K == 0) {
        printf("0 1 1 0");
        return 0;
    }
    printf("%d ", K);
    FOR(i, 0, K - 1) printf("%d ", i);
    FOR(i, K + 1, (1 << M) - 1) printf("%d ", i);
    printf("%d ", K);
    DOWN(i, (1 << M) - 1, K + 1) printf("%d ", i);
    DOWN(i, K - 1, 0) printf("%d ", i);
    return 0;
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());

    int al = 0, b = 0;
    rep(i, 0, n)
    {
        if (i % 2 == 0) al += a[i];
        else b += a[i];
    }
    cout << al - b << endl;
}


Measured memory_bytes: 256
#include <iostream>
    #include <string>
    using namespace std;
     
    int N;
    int A[4];
     
    int main(void) {
    	cin >> N;
     
    	int m = 1000;
    	for (int i = 0; i < 4; ++i) {
    		A[i] = N / m;
    		N %= m;
    		m /= 10;
    	}
     
    	string sig;
    	if (A[0] + A[1] + A[2] + A[3] == 7)
    		sig = "+++";
    	else if (A[0] + A[1] + A[2] - A[3] == 7)
    		sig = "++-";
    	else if (A[0] + A[1] - A[2] + A[3] == 7)
    		sig = "+-+";
    	else if (A[0] + A[1] - A[2] - A[3] == 7)
    		sig = "+--";
    	else if (A[0] - A[1] + A[2] + A[3] == 7)
    		sig = "-++";
    	else if (A[0] - A[1] - A[2] + A[3] == 7)
    		sig = "--+";
    	else if (A[0] - A[1] + A[2] - A[3] == 7)
    		sig = "-+-";
    	else if (A[0] - A[1] - A[2] - A[3] == 7)
    		sig = "---";
     
    	for (int i = 0; i < 3; ++i)
    		cout << A[i] << sig[i];
    	cout << A[3] << "=7\n";
     
    	return 0;
    }

Measured memory_bytes: 256
N,M = map(int,input().split())
L = [0]*M
R = [0]*M
for i in  range(M):
        L[i],R[i] = map(int,input().split())
l = 1
r = N
for i in range(M):
        if l < L[i]:
                l = L[i]
        if r > R[i]:
                r = R[i]
        if l > r:
                break
print(r-l+1 if l <= r else 0)


Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 17;
ll n;
vector<ll> v;

bool so(ll x){
	bool ans=true;
	FOR(i,2,sqrt(x)+2){
		if(x%i==0)ans=false;
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	v.pb(11);
	ll k=11;
	while(v.size()<n){
		k+=10;
		if(so(k))v.pb(k);
	}
	cout<<v[0];
	FOR(i,1,v.size()){
		cout<<" "<<v[i];
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, kk;
	cin >> nn >> kk;
	vector<int64> aa(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> aa[ii];
	}
	for(int64 ii = kk;ii < nn;ii++)
	{
		if(aa[ii] > aa[ii - kk])
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4836
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll N;
	cin >> N;
	string ans;
	while (1) {
		if (N == 0)
			break;
		ll c = N % 26;
		if (c == 0)
			c = 26;
		char anstmp = 'a' + c - 1;
		ans.push_back(anstmp);
		N -= c;
		N /= 26;
	}
	reverse(ans.begin(), ans.end());

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

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    vector<int> Dim(N, 0);
    REP(i, 0, M) {
        int x, y;
        cin >> x >> y;
        G[x - 1].push_back(y - 1);
        Dim[y - 1]++;
    }

    queue<int> q;
    REP(i, 0, N) {
        if (Dim[i] == 0) {
            q.emplace(i);
        }
    }

    vector<ll> dp(N, 0);
    ll ans = 0;
    while (q.size()) {
        int edge = q.front();
        q.pop();
        REP(i, 0, G[edge].size()) {
            int nxt = G[edge][i];
            if (!(--Dim[nxt])) {
                q.emplace(nxt);
            }
            dp[nxt] = max(dp[nxt], dp[edge] + 1);
            ans = max(ans, dp[nxt]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6912
n=int(input())
a=list(map(int,input().split()))
if len(set(a))>3:
    print("No")
    exit()
if a.count(0)==n:
    print("Yes")
    exit()
if n%3!=0:
    print("No")
    exit()
if len(set(a))==3:
    a.sort()
    if a.count(a[0])==n//3 and a.count(a[-1])==n//3:
        if a[0]^a[-1] in set(a):
            print("Yes")
            exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
elif len(set(a))==2:
    if a.count(0)==n//3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
else:
    print("No")
    exit()

Measured memory_bytes: 20648
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<queue>
#include<string>
#include<unordered_set>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000000;

ll N, min_p=INF, ans;

int main(){
    cin >> N;
    for(int i=0; i<N; i++){
        ll p;
        cin >> p;
        if(p<min_p){
            ans++;
            min_p = p;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef long double ld;
const ld pi = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 1e6 + 5;

ll n;
ll freq[nax];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> n;
	for(ll i = 1; i <= n; i++){
		ll a;
		cin >> a;
		freq[a]++;
	}
	ll pair = 1, st = 1;
	for(ll i = 2; i <= 1e6; i++){
		ll cnt = 0;
		for(ll j = i; j <= 1e6; j += i){
			cnt += freq[j];
		}
		if(cnt > 1){
			pair = 0;
		}
		if(cnt >= n){
			st = 0;
		}
		if(pair == 0 && st == 0){
			break;
		}
	}
	if(pair){
		cout << "pairwise coprime\n";
	}
	else if(st){
		cout << "setwise coprime\n";
	}
	else{
		cout << "not coprime\n";
	}
}



Measured memory_bytes: 11464
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s, t = input().strip().split()
  a, b = map(int, input().strip().split())
  u    = input().strip()
  if u == s:
    print(a-1, b)
  else:
    print(a, b-1)

if __name__=='__main__':
  main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x,n,i,y=10000000,o,p;
cin>>x>>n;
int a[n];
for(i=1;i<=n;i++)
{
    cin>>a[i];
}
sort(a+1,a+1+n);
p=abs(a[1]-0)+abs(x-a[2]);
o=abs(a[n]-a[1]);
y=min(y,min(o,p));
p=abs(a[n]-x)+abs(0-a[n-1]);
y=min(y,p);
for(i=2;i<n;i++)
{
   o=abs(a[i]-x)+abs(0-a[i-1]);
   p=abs(a[i]-0)+abs(a[i+1]-x);
   y=min(y,min(o,p));


}
cout<<y;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A+B > C+D) {
    cout << "Left";
  }
  else if(A+B == C+D) {
    cout << "Balanced";
  }
  else {
    cout << "Right";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
#define INF	100000000
#define pb	push_back
#define fi first
#define sec second
#define SS stringstream
using namespace std;
typedef pair<int, int> P;
typedef long long int	ll;

ll n;

int main(){
	while(cin >> n){
		if(n == 0) break;
		int ans = 0;
		while(true){
			if(n < 5) break;
			ans += n/5;
			n = n/5;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
n,m,x,y=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
amax=max(a)
bmin=min(b)
c=a+b;flag=0
for i in range(n+m):
    if (c[i]>x and c[i]<=y) and (amax<c[i]) and (bmin>=c[i]):
        print('No War')
        flag=1
        break
if flag==0:
    print('War')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S, T;
    cin >> S >> T;
    for (int n = 0; n < S.size(); ++n)
    {
        char tmp = S[S.size() - 1];
        for (int i = S.size() - 1; i > 0; --i)
        {
            S[i] = S[i - 1];
        }
        S[0] = tmp;
        if (S == T)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main (void) {
    int n;
    scanf("%d", &n);
    if (n % 2 == 0) {
        printf("%f\n", 0.5);
    } else {
        int oddNumber = n / 2 + 1;
        printf("%f\n", (double) oddNumber / n);
    }
    return 0;
}

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

ll m(ll a) {
    return ((a%MOD)+MOD)%MOD;
}

ll dp[100005][2];
vector<vector<int>> adj;
int n;
bool vis[100005][2];

ll getcount(int u, int col, int p){
    if (vis[u][col]) return dp[u][col];
    vis[u][col] = true;
    dp[u][col] = 1ll;
    for (int v: adj[u]) {
        if (v==p) continue;
        if (col==0) {
            dp[u][col] = m(dp[u][col]*getcount(v, 1, u));
        } else {
            dp[u][col] = m(dp[u][col]*m(getcount(v, 0, u)+getcount(v, 1, u)));
        }
    }
    return dp[u][col];
}


int main() {
    scanf("%d", &n);
    memset(vis, 0, sizeof vis);
    adj.resize(n);
    for (int i=0; i<n-1; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    ll l1 = getcount(0, 1, -1);
    ll l2 = getcount(0, 0, -1);
    l1 += l2;
    if (l1>=MOD) l1 -= MOD;
    printf("%lld\n", l1);
}

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

int G[205][205],vis[205],n,ans=0,flag=0;
char s[205];
void bfs(int x){
	std::queue<int>q;q.push(x);
	while (!q.empty()){
		int u=q.front();q.pop();
		for(int i=1;i<=n;++i){
			if (!G[u][i])continue;
			if (vis[i]&&vis[u]%2==vis[i]%2){flag=1;return ;}
			if (!vis[i]){vis[i]=vis[u]+1;q.push(i);}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%s",s+1);
		for(int j=1;j<=n;++j)
			G[i][j]=s[j]-'0';
	}
	for(int i=1;i<=n;++i){
		std::memset(vis,0,sizeof(vis));
		vis[i]=1;bfs(i);
		if (flag){printf("-1");return 0;}
		for(int j=1;j<=n;++j)ans=std::max(ans,vis[j]);
	}printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    ll sum = 0;
    rep(i, n) {
        int t;
        cin >> t;
        mp[t]++;
        sum += t;
    }

    int q;
    cin >> q;
    rep(i, q) {
        int b, c;
        cin >> b >> c;
        sum += (c-b)*mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 7884
#include <vector>
#include <string>
#include <iostream>
#include <stdlib.h> // @atoi
#include <algorithm>
using namespace std;
 
 
#define NUMBEROF(Array)		( sizeof( Array ) / sizeof( Array[ 0 ] ) )
 
 
int main(void)
{
	int value[5] = { 0 };
	int distance;
	cin >> value[0] >> value[1] >> value[2] >> value[3] >> value[4] >> distance;
 
	bool isCan = true;
	for (int i = 0; i < NUMBEROF(value); ++i)
	{
		for (int j = 0; j < NUMBEROF(value); ++j)
		{
			if (abs(value[i] - value[j]) > distance)
			{
				isCan = false;
				break;
			}
		}
	}
	cout << ((isCan) ? "Yay!" : ":(") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,x,y;
signed main(){
	scanf("%lld",&n);
	for(int i=sqrt(n);i>=1;i--){
		if(n%i==0){
			x=i;
			y=n/i;
			break;
		}
	}
	cout<<x+y-2<<endl;
	return 0;
} 

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

using namespace std;

#define int long long

const int maxn = 2e5+10;

int n;

int a[maxn];
signed main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int res = 0;
	sort(a+1, a+n+1, greater<int>());
	res += a[1];
	int pos = 2;
	int cnt = 1;
	for (int i = 2; i <= n; i++) {
		if (cnt == n - 1) break;
		for (int j = 0; j < 2; j++) {
			if (cnt == n - 1) break;
			res += a[i];
			cnt++;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 5204
def factorize(a):
    factors = {}
    v = a
    if v%2==0: factors[2]=0
    while v%2==0:
        v//=2
        factors[2]+=1
    
    p = 3
    while p*p<=a:
        if v%p==0: factors[p] = 0
        while v%p==0:
            v//=p
            factors[p]+=1
        p+=2
    if v>1: factors[v] = 1
    return factors

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

# calc lcm
lcm = {}
for a in A:
    factors_a = factorize(a)
    for k, v in factors_a.items():
        if k not in lcm or lcm[k]<v: lcm[k] = v

C = 1
for k, v in lcm.items():
    C *= pow(k, v, mod)
    C %= mod

ans = 0
for a in A:
    ans += C * pow(a, mod-2, mod)
    ans %= mod

print(ans)

Measured memory_bytes: 4596
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

const EPS = 1e-7;

alias float Number;

/* 鬆伜沺譛ィ繝ゥ繧、繝悶Λ繝ェ.
 *   Node : 鬆伜沺譛ィ縺ョ蜷?ヮ繝シ繝? *   construct(Point[] ps) 
 *      : ps(x蠎ァ讓吶〒繧ス繝シ繝医＆繧後◆轤ケ髮?粋)繧偵ｂ縺ィ縺ォ鬆伜沺譛ィ繧剃ス懈?.
 *   query(Node root, long sx, long sy, long gx, long gy) 
 *      : root縺ォ蜷ォ縺セ繧後ｋ轤ケ縺ョ縺?■, (sx <= x <= gx && sy <= y <= gy)縺ェ繧九ｂ縺ョ縺ョ蛟区焚繧定ソ斐☆.
 */
struct Point {
    Number x, y;
    int id;
}
struct Pair {
    double y; int id;
    int opCmp(double py) const {
        if (abs(y - py) <= EPS) return 0;
        return cast(int)((y - py) / abs(y - py));
    }
}
class Node {
    Node parent;
    Node left, right;
    Number left_x, right_x;
    Pair[] P;
    override string toString() const {
        return format("%s -> P: %s", [left_x, right_x], P);
    }
}
Node construct(in Point[] ps) {
    auto n = new Node;
    n.left_x = ps.front.x;
    n.right_x = ps.back.x;
    if (ps.length == 1) {
        n.P = [ Pair(ps[0].y, ps[0].id) ];
        return n;
    }
    Node l = construct(ps[0 .. $ / 2]),
         r = construct(ps[$ / 2 .. $]);
    l.parent = n;
    r.parent = n;
    n.left = l;
    n.right = r;
    size_t li = 0, ri = 0;
    Pair[] P;
    while (true) {
        if (li >= l.P.length && ri >= r.P.length) break;
        if (li >= l.P.length) P ~= r.P[ri++];
        else if (ri >= r.P.length) P ~= l.P[li++];
        else {
            P ~= (l.P[li].y < r.P[ri].y ? l.P[li++] : r.P[ri++]);
        }
    }
    n.P = P;
    return n;
}

bool[] used;
/* (sx <= x <= gx && sy <= y <= gy)縺ェ繧狗せ(x, y)縺ョ蛟区焚繧定ソ斐☆ 
 * 髢牙玄髢薙↑縺ョ豕ィ諢?*/
void query(Node root, Number sx, Number gx, Number sy, Number gy) {
    //writeln("query: ", [sx, gx, sy, gy]);
    if (gx + EPS < root.left_x || root.right_x < sx - EPS) {
        return;
    } else if (sx - EPS <= root.left_x && root.right_x <= gx + EPS) {
        auto P = assumeSorted(root.P);
        auto matched = P.upperBound(sy - EPS).lowerBound(gy + EPS);
        foreach (p; matched) {
            used[p.id] = true;
        }
    } else {
        query(root.left, sx, gx, sy, gy);
        query(root.right, sx, gx, sy, gy);
    }
}

void main() {
    int N; double R; scanf("%d %lf\n", &N, &R);
    R = ceil(R);
    Point[] P = new Point[N];
    foreach (int i; 0 .. N) {
        double x, y; scanf("%lf %lf\n", &x, &y);
        P[i] = Point(x, y, i);
    }
    P.sort!"a.x < b.x";
    auto rtree = construct(P);
    used = new bool[N];
    int Ans = 0;
    foreach (int i; 0 .. N) {
        auto p = P[i];
        if (used[p.id]) continue;
        Ans++;
        rtree.query(p.x - R, p.x + R, p.y - R, p.y + R);
    }
    writeln(Ans);
}

Measured memory_bytes: 115928
#include <bits/stdc++.h>
#define ll long long int
#define db double
#define pb push_back
#define mpr make_pair
#define andl "\n"
#define f first
#define s second
#define mset(x,y) memset(x,y,sizeof(x))
#define fr(i,n) for(long long int i=0;i<n;i++)
#define trace(it,x) for(auto it = (x).begin(); it != (x).end(); it++)
#define mod 1000000007
#define fastio ios::sync_with_stdio (false); cin.tie (0); cout.tie (0);
#define runtime cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
using namespace std;
 
// convert number to string to_string(x);
// convert string to number stoi();
 
// ll mulmod(ll x,ll y)
// {
//     return ((x%mod)*(y%mod))%mod;
// }
 
// ll binpow(ll x, ll y)
// {
//     ll z = 1;
//     while(y > 0)
//     {
//         if(y % 2 == 1)
//             z = mulmod(z, x);
//         x = mulmod(x, x);
//         y /= 2;
//     }
//     return z;
// }
 
// ll ncr(ll n,ll r)
// {
//     return mulmod(fact[n],binpow(mulmod(fact[n-r],fact[r]),mod-2));
// }
 
// ll pwr(ll n,ll m)
// {
//   if(n==1 || m==0)
//     return 1;
 
//   ll x=pwr(n,m/2);
//   if(m%2==0)
//     return x*x;
//   else
//     return n*x*x;
// }
 
// ll pwr(ll n,ll m,ll b)
// {
//   if(n==1 || m==0)
//     return 1;
 
//   ll x=pwr(n,m/2,b);
//   if(m%2==0)
//     return ((x%b)*(x%b))%b;
//   else
//     return ((n%b)*(((x%b)*(x%b))%b))%b;
// }
 
void solve()
{
  return ;
}
 
int main()
{
  fastio
  
  string s;
  cin >> s;

  ll n=s.length();
  if(s[n-1]!='s' || s[n-1]=='e')
    cout << s+"s";
    else

        cout << s+"es";
 
  runtime
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> A(N),sum(N+1,0);
	FOR(i,0,N) cin >> A[i];
	sort(A.begin(),A.end());
	FOR(i,1,N+1)sum[i] = sum[i-1] + A[i-1];

	// 幸福度が ok 以上になる握手がM回以上ある
	ll ok=0,ng=300000,ans=0;
	while(ng-ok>1){
		ll mid = (ng+ok)/2;
		ll num = 0;
		ll anst = 0;
		FOR(i,0,N){
			ll ind = POSL(A,mid-A[i]);
			num += N - ind;
			anst += (sum[N]-sum[ind])+A[i]*(N-ind);
		}
		if(num >= M){
			ok = mid;
			ans = anst - (num-M) * ok;
		}else{
			ng = mid;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 510
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

LL T,n,i,j,k,x,y,z;
LL a[N],f[N];
char c[N];

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL LL Max(LL a,LL b){return (a>b)?a:b;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);
	return Res;
}

IL LL read(){
	LL p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();
	for (i=1;i<=n;i++)	a[i]=read();
	f[1]=1000;
	for (i=2;i<=n;i++){
		for (j=1;j<i;j++)	f[i]=Max(f[i],f[j]);
		for (j=1;j<i;j++){
			f[i]=Max(f[i],f[j]/a[j]*a[i]+f[j]%a[j]);
		}
	}
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main() {
  while (true) {
    int M;
    cin >> M;
    if (M == 0) {
      break;
    }
    int m = 1000 - M;

    int ans = 0;
    while (m > 0) {
      if (m >= 500) {
        m -= 500;
      } else if (m >= 100) {
        m -= 100;
      } else if (m >= 50) {
        m -= 50;
      } else if (m >= 10) {
        m -= 10;
      } else if (m >= 5) {
        m -= 5;
      } else {
        m--;
      }

      ans++;
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3084
// VU TRUONG AN
#include <bits/stdc++.h>
#define F first
#define S second
#define maxn 200005
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define pi acos(-1)
#define bit(p,x) ((x>>p) & 1)
#define Task "CF"
using namespace std;

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

const int base = 200003;
const long long MM = 1ll * MOD * MOD;

int n,m;
void Solve(){
    cin >> n >> m;
    if(n > m) swap(n,m);
    if(n == 1 && m == 1) cout << 1;
    if(n == 1 && m > 1) cout << m - 2;
    if(n >= 2 && m >= 2) cout << 1ll * (n - 2) * (m - 2);
}

void NumTime(){cerr << "Toi" << "\n";cerr << "Di" << "\n";cerr << "Chep" << "\n";cerr << "Code" << "\n";}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen(Task".inp", "r", stdin);
    freopen(Task".out", "w", stdout);
#endif
    int test = 1;
//    cin >> test;
    while(test--){
        NumTime();
        Solve();
    }
}


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

using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int N;
    cin >> N;
    vector<long> v;
    long n;
    for (int i=0; i<N ; ++i){
        cin >> n;
        v.push_back(n-i-1);
    }
    
    sort(v.begin(), v.end());
    long b = v[N/2];
    long sadness = 0;
    for (auto it = v.begin(); it != v.end(); ++it){
        sadness += abs(*it - b);
    }
    cout << sadness << endl;
    return 0;
}


Measured memory_bytes: 2420
H, W = list(map(int, input().split()))

ans = float('inf')

# first cut vertical
for x in range(1, W):
  S1 = x * H
  # cut vertical
  w2 = (W - x) // 2
  w3 = W - x - w2
  S2 = w2 * H
  S3 = w3 * H
  S_max = max(S1, S3)
  S_min = min(S1, S2)
  ans = min(ans, S_max - S_min)
  # cut horizontal
  h2 = H // 2
  h3 = H - h2
  S2 = (W - x) * h2
  S3 = (W - x) * h3
  S_max = max(S1, S3)
  S_min = min(S1, S2)
  ans = min(ans, S_max - S_min)
# first cut horizontal
for y in range(1, H):
  S1 = W * y
  # cut vertical
  w2 = W // 2
  w3 = W - w2
  S2 = w2 * (H - y)
  S3 = w3 * (H - y)
  S_max = max(S1, S3)
  S_min = min(S1, S2)
  ans = min(ans, S_max - S_min)
  # cut horizontal
  h2 = (H - y) // 2
  h3 = H - y - h2
  S2 = W * h2
  S3 = W * h3
  S_max = max(S1, S3)
  S_min = min(S1, S2)
  ans = min(ans, S_max - S_min)

print(int(ans))

Measured memory_bytes: 3064
def dfs(parent, connect, passed, N):
    cnt = 0
    passed.append(parent)
    if len(passed) == N:
        cnt = 1
    for next_ in connect[parent]:
        if next_ in passed:
            continue
        cnt += dfs(next_, connect, passed, N)
    passed.pop()
    return cnt    

N, M = map(int, input().split())
connect = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    connect[a-1].append(b-1)
    connect[b-1].append(a-1)
ans = dfs(0, connect, [], N)
print(ans)

Measured memory_bytes: 9096
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	string S;
	cin >> S;
	sort(S.begin(), S.end());
	string A = "abc";
	cout << ((S == A) ? ("Yes") : ("No")) << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,C=map(int,input().split())
    l=[]
    for i in range(N):
        l.append(list(map(int,input().split())))
    l.sort(key=lambda t:(t[2],t[1]))
    a=[0]*(10**5+1)
    ss,tt,cc=-1,-1,-1
    for s,t,c in l:
        if s==tt and c==cc:
            a[tt]+=1
            a[t]-=1
        else:
            a[s-1]+=1
            a[t]-=1
        ss,tt,cc=s,t,c
    ans=0
    tmp=0
    for x in a:
        tmp+=x
        ans=max(ans,tmp)
    print(ans)
            

if __name__ == '__main__':
    main()


Measured memory_bytes: 64476