akhauriyash/Code-Regression huggingface dataset:
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << (x) << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 2e3 + 7;
int n, a[N], s;
bitset<N*N> b;

int main() {
	rd(n), rda(a, n), b[0] = 1;
	for (int i = 1; i <= n; i++) b |= b << a[i], s += a[i];
	s = (s + 1) >> 1;
	while (!b[s]) ++s;
	print(s);
	return 0;
}

Measured memory_bytes: 5096
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
const LL M = 1000000007;
void show(VEC<VEC<int>> A) {
  REP(i, 0, A.size()) {
    REP(j, 0, A[i].size()) { cerr << A[i][j] << " "; }
    cerr << endl;
  }
  cerr << endl;
}
LL gbit(LL n, LL i) { return (n >> i) & 1; }

int in_contest() {
  LL N;
  cin >> N;
  VEC<LL> A(N);
  REP(i, 0, N) cin >> A[i];
  LL bit_lim = 61;
  // LL lim = pow(2, 60);
  VEC<LL> B(bit_lim, 0);
  VEC<VEC<LL>> bit_cs(bit_lim, VEC<LL>(N));
  REP(bit, 0, bit_lim) {
    bit_cs[bit][0] = gbit(A[0], bit);
    REP(i, 1, N) { bit_cs[bit][i] = gbit(A[i], bit) + bit_cs[bit][i - 1]; }
  }
  // show(bit_cs);
  REP(bit, 0, bit_lim) {
    REP(i, 0, N) {
      LL one_num_raw = bit_cs[bit][N - 1] - bit_cs[bit][i];
      LL one_num;
      if (gbit(A[i], bit) == 0) {
        one_num = one_num_raw;
      } else {
        one_num = N - i - 1 - one_num_raw;
      }
      B[bit] += one_num;
    }
  }
  LL sum = 0;
  REP(bit, 0, bit_lim) {
    // LL c = 0;
    // LL adding = (1LL << bit);
    // REP(i, 0, B[bit]) { c = (c + adding) % M; }
    LL c = (B[bit] * (1LL << bit)) % M;
    sum = (sum + c) % M;
  }
  cout << sum << endl;

  return 0;
}
int main() {
  ULL N;
  cin >> N;
  VEC<ULL> A(N);
  REP(i, 0, N) cin >> A[i];
  ULL bit_lim = 60;
  VEC<ULL> B(bit_lim, 0);
  REP(bit, 0, bit_lim) {
    LL zeros = 0;
    LL ones = 0;
    REP(i, 0, N) {
      if (gbit(A[i], bit)) {
        ones++;
      } else {
        zeros++;
      }
    }
    // zeros=(N-ones);
    B[bit] = (zeros * ones) % M;
  }
  ULL sum = 0;
  REP(bit, 0, bit_lim) {
    ULL c = (1ULL << bit) % M;
    c = (B[bit] * c) % M;
    sum = (sum + c) % M;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 2560
def main():
    s = input()
    s = list(reversed(s))
    s.append('0')
    dp = [[10**10 for _ in range(2)] for _ in range(len(s)+1)]
    dp[0][0] = 0
    for i in range(len(s)):
        for j in range(2):
            x = int(s[i])
            x += j
            for a in range(10):
                ni = i+1
                nj = 0
                b = a-x
                if b < 0:
                    nj = 1
                    b += 10
                dp[ni][nj] = min(dp[ni][nj], dp[i][j]+a+b)
    print(dp[len(s)][0])


main()


Measured memory_bytes: 194172
#include <stdio.h>

int cou = 1;
int oya[500010];
int kodo[2][500010];
int ata[500010];

int ks(int x,int y){
  if(y==0)printf(" %d",ata[x]);
  if(kodo[0][x])ks(kodo[0][x],y);
  if(y==1)printf(" %d",ata[x]);
  if(kodo[1][x])ks(kodo[1][x],y);
  if(y==2)printf(" %d",ata[x]);
}

void pull(int x, int xa){
  if(cou==1){
    ata[cou]=xa;
    cou++;
    return;
  }
  if(kodo[ata[x]<xa][x])pull(kodo[ata[x]<xa][x],xa);
  else{
    kodo[ata[x]<xa][x] = cou;
    oya[cou]=x;
    ata[cou]=xa;
    cou++;
  }
}

int tanch(int x,int xa){
  if(ata[x]==xa)return 1;
  if (kodo[ata[x]<xa][x])return tanch(kodo[ata[x]<xa][x],xa);
  return 0;
}

int main(){
  int p;
  scanf("%d",&p);
  while(p--){
    char s[10];
    scanf("%s",s);
    if(s[0]=='p'){
      ks(1,1);
      puts("");
      ks(1,0);
      puts("");
    }else if(s[0]=='i'){
      int t;
      scanf("%d",&t);
      pull(1,t);
    }else{
      int t;
      scanf("%d",&t);
      puts(tanch(1,t)?"yes":"no");
      
    }
  }
}



Measured memory_bytes: 7960
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int n, y, i, j, k;
int main(void)
{
  scanf("%d%d", &n, &y);
  for (i=0; i <= n; ++i) 
  {
    for (j = 0; i + j <= n; ++j)
    {
      k = n - i - j;
      if (y == 10000 * i + 5000 * j + 1000 * k)
      {
        printf("%d %d %d\n", i, j, k);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}


Measured memory_bytes: 128
//তুমি চেয়ে আছো তাই, আমি পথে হেঁটে যাই
//হেঁটে হেঁটে বহুদুর বহুদুর যেতে চাই 
//I FAILED BADLY AND VERY PUBLICLY
//THAT'S WHAT I DESERVE 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI 2 * acos(0.0) 
const long long M = 1e7 + 10, oo = 1e9 + 7;
ll n, w, ans = 0, dp[M];
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> w;
    // dp[i] - ans if we have taken total i weight
    for (int i = 0; i < n; i++) {
        ll wi, vi;
        cin >> wi >> vi;
        for (int pw = w - wi; pw >= 0; pw--) {
            dp[wi + pw] = max(dp[wi + pw], dp[pw] + vi);
            ans = max(ans, dp[wi + pw]);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
struct Graph{
  using ver_t=int32_t; using edge_t=pair<ver_t,ver_t>;
  vector<vector<ver_t>> field;
  const edge_t dr[8]={{1,1},{1,0},{1,-1},{0,1},{0,-1},{-1,1},{-1,0},{-1,-1}};
  void dfs(edge_t frm){
    // preorder
    field[frm.first][frm.second]=0;
    for(const auto& v:dr){
      auto x=frm.first+v.first; auto y=frm.second+v.second;
      if(x>=0&&x<field.size()&&y>=0&&y<field.front().size()&&field[x][y]==1){
        dfs(make_pair(x,y));
      }
    }
    // postorder
  }
  // void bfs(ver_t frm){
  //   seen[frm]=0;
  //   deque<ver_t> que(1,frm); // dfs,bfs
  //   while(!que.empty()){
  //     auto u=que.front(); que.pop_front(); // bfs
  //     for(const auto& v:edge[u]){
  //       if(seen[v]==NO){
  //         seen[v]=seen[u]+1;
  //         que.push_back(v); // dfs,bfs
  //       }
  //     }
  //   }
  // }
};
int32_t main(){
  Graph g;
  // size_t n; cin>>n;
  // for(size_t i=0; i<n; ++i){
  size_t w,h; cin>>w>>h;
  while(w!=0||h!=0){
    g.field.resize(h);
    for(auto&& x:g.field){
      x.resize(w);
      for(auto&& y:x) cin>>y;
    }
    size_t ret=0;
    for(size_t i=0; i<h; ++i){
      for(size_t j=0; j<w; ++j){
        if(g.field[i][j]==1){ ++ret; g.dfs(make_pair(i,j)); }
      }
    }
    cout<<ret<<'\n';
    cin>>w>>h;
  }
}



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

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

    if(n==m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val count = mutableMapOf<Int,Int>()
    readLine()!!.split(" ")
        .map { it.toInt() }
        .forEach { count[it] = count.getOrElse(it, {0}) + 1 }
    var ans = 0
    for (key in 0..100000) {
        ans = Math.max(ans, (count[key - 1] ?: 0) + (count[key] ?: 0) + (count[key + 1] ?: 0))
    }
    println(ans)
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()

int main() {
	ll h, n, a, sum=0;
	cin >> h >> n;
	FOR(i, 1, n) {
		cin >> a;
		sum += a;
	}
	if (sum >= h) {
		ps(Yes)
	}
	else {
		ps(No)
	}
	return(0);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    string s;
    cin>>s;
    
    if(s[0]==s[s.size()-1]){
        if(s.size()%2==0)   cout<<"First"<<endl;
        else                cout<<"Second"<<endl;
    }else{
        if(s.size()%2==1)   cout<<"First"<<endl;
        else                cout<<"Second"<<endl;
    }
}

Measured memory_bytes: 512
import Control.Monad.State.Strict
import Data.Bool
import qualified Data.ByteString.Char8 as C
import Data.Coerce
import qualified Data.IntMap as M
import Data.Tuple
import Data.Vector.Generic ((!))
import qualified Data.Vector as V
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Unboxed as U

main = sol <$> gett >>= print

gett = U.unfoldr (runStateT $ (,) <$> geti <*> geti) <$> C.getContents

geti = coerce $ C.readInt . C.dropWhile (<'0') :: StateT C.ByteString Maybe Int

sol v = pred . fst $ lowlink 0 1 M.empty
  where
  n = fst $ U.head v
  g = V.accumulate (flip (:)) (V.replicate (n+1) [])
    $ V.concatMap (V.fromList . liftM2 (:) swap return)
    $ (G.convert :: U.Vector (Int, Int) -> V.Vector (Int,Int)) $ U.tail v
  lowlink s t low = (c', low')
    where
    (c,low') = foldr f (0, M.insert t (M.size low) low) $ g!t
    c' = c + bool 0 1 (M.size low==low' M.! t)
    f i (c,low)
      | i == s          = (c,low)
      | M.member i low  = (c,M.adjust (min (low M.! i)) t low)
      | otherwise       = (c+c',M.adjust (min (low' M.! i)) t low')
      where
      (c',low') = lowlink t i low

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

const int maxN = 200020;

int n, m;
int A[maxN], B[maxN];

int main (){
	int i, j;
	scanf("%d", &n);
	for(i = 0; i < n; ++i) scanf("%d", A + i); sort(A, A + n);
	scanf("%d", &m);
	for(i = 0; i < m; ++i) scanf("%d", B + i); sort(B, B + m);
	for(i = j = 0; j < m; ++j){
		for(; i < n && A[i] < B[j]; ++i);
		if(i < n && A[i] == B[j]) ++i;
		else break;
	}
	puts(j == m ? "YES" : "NO");
	return 0;
}


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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define int ll

int32_t main(){
    FAST
    int n; cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(i%3 == 0 && i%5 == 0){
        }
        else if(i%3 == 0){
        }
        else if(i%5 == 0){
        }
        else{
            ans += i;
        }
    }
    cout << ans;
    return 0;
}


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

using namespace std;

const int max_n = 2e5 + 5;

int start_1[max_n], start_2[max_n], tab_1[max_n], tab_2[max_n], napis[3 * max_n], P[3 * max_n], n;

vector<pair<int, int> > wynik;

void wczytaj(int* tab, int* start){
    cin >> start[0];
    for (int i = 1; i < n; i++){
        cin >> start[i];
        tab[i - 1] = start[i] ^ start[i - 1];
    }
    tab[n - 1] = start[n - 1] ^ start[0];
}

void stworz_napis(){
    for (int i = 1; i <= n; i++)
        napis[i] = tab_1[i - 1];
    napis[n + 1] = -4;
    for (int i = 0; i < n; i++)
        napis[i + n + 2] = tab_2[i];
    for (int i = 0; i < n - 1; i++)
        napis[i + 2 * n + 2] = tab_2[i];
}

void kmp(){
    P[1] = 0;
    //cout << "0 ";
    for (int i = 2; i <= 3 * n; i++){
        int pom = i - 1;
        while (pom && napis[P[pom] + 1] != napis[i])
            pom = P[pom];
        P[i] = P[pom]; 
        if (napis[P[pom] + 1] == napis[i])
            P[i]++;
        if (P[i] == n){
            //cout << i << "xd\n";
            wynik.emplace_back((n - (i - 2 * n - 1)) % n, start_1[(n - (i - 2 * n - 1)) % n] ^ start_2[0]);
            //wynik.emplace_back((n - (i - 2 * n - 1)) % n, (n - (i - 2 * n - 1)) % n);
        }
        //cout << P[i] << " ";
    }
    //cout << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    wczytaj(tab_1, start_1);
    wczytaj(tab_2, start_2);
    stworz_napis();
    /*for (int i = 0; i < n; i++)
        cout << tab_1[i] << " ";
    cout << "\n";
    for (int i = 0; i < n; i++)
        cout << tab_2[i] << " ";
    cout << "\n";
    for (int i = 1; i <= 3 * n; i++)
        cout << napis[i] << " ";
    cout << "\n";
    */
    kmp();
    //return 0;
    sort(wynik.begin(), wynik.end());
    for (pair<int, int> i : wynik)
        cout << i.first << " " << i.second << "\n";
    //cout << (start_1[0] ^ start_2[0]) << " " << (start_1[1] ^ start_2[1]) << "\n";
    return 0;
}

Measured memory_bytes: 13272
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    string S; cin >> S;
    F0R(i, sz(S)) {
        cout << 'x';
    }
    cout << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

int main(void){
  int x=0;
  int n;
  string s;
  cin >> n;
  cin >> s;

  int max = 0;

  for(int i=0;i<n;i++){
    if(s[i]=='I'){
      x++;
      if(x>max){
        max = x;
      }
    } else {
      x--;

    }
  }

  cout << max <<endl;
  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REP(i, n) for(ll i = 1; i < (ll)(n); i++)
#define P pair<ll, ll>
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(int x, int y){
  if(x % y == 1) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(int x, int y){
  return x * y / gcd(x, y);
}
// n個の最大公約数
ll ngcd(vector<int> a){
  int res;
  res = a[0];
  for(int i=1; i<a.size() && res!=1; i++){
    res = gcd(res, a[i]);
  }
  return res;
}
// n個の最小公倍数
ll nlcm(vector<int> a){
  int res;
  res = a[0];
  REP(i, a.size()){
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(int x){
  int i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
int digsum(int x){
  int res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int x, y;
  cin >> x >> y;
  int ans = x + y/2;
  cout << ans << endl;
}






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

typedef long long ll;

const int mod = 1000000007;
const int Maxn = 5005;

int res;
int pw2[Maxn];
int n, a, b;
int ind[Maxn];
int delt[Maxn][Maxn];

void Add(int &res, int x) { res = (res + x) % mod; }

void Sub(int &res, int x) { res = (res - x + mod) % mod; }

int main()
{
    pw2[0] = 1;
    for (int i = 1; i < Maxn; i++)
        pw2[i] = 2ll * pw2[i - 1] % mod;
    scanf("%d %d %d", &n, &a, &b);
    if (a > b) swap(a, b);
    Add(delt[0][1], 1);
    Sub(delt[0][2], 1);
    for (int i = 0; i <= n; i++) {
        for (int j = i + 1; j <= n + 1; j++) {
            int cur = 0;
            if (j > 0) Add(delt[i][j], delt[i][j - 1]);
            Add(cur, delt[i][j]);
            if (j == i + 2) {
                if (i > 0) Add(ind[i], ind[i - 1]);
                Add(cur, ind[i]);
            }
            if (j - 1 - i >= b) { Add(res, ll(cur) * pw2[n + 1 - j] % mod); continue; }
            Add(delt[i][j + 1], cur);
            Sub(delt[i][j + 2], cur);
            int lim = min(a, n + 1 - j);
            Add(ind[j], cur);
            Sub(ind[j + lim - 1], cur);
            if (j + a <= n + 1) {
                if (j - 1 - i + a >= b) {
                    Add(delt[i][j + a], cur);
                    Sub(delt[i][j + a + 1], cur);
                } else {
                    Add(delt[i][j + a + 1], cur);
                    Add(delt[i][n + 1], cur);
                }
            }
        }
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 70704
#include<bits/stdc++.h>
using namespace std ;
void solve() {
  int s, w;
  cin >> s >> w ;
  if(w>=s) cout << "unsafe";
  else cout << "safe";
}
int main() {
  int t=1;
  //cin >> t ;
  while(t--) solve() ;
  return 0 ;
}


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

int main()
{
    int N,P[100010]={0},Li,Ri;

    cin>>N;

    for(int i=0;i<N;i++)
    {
        cin>>Li>>Ri;
        P[Li-1]=P[Li-1]+1;
        P[Ri]=P[Ri]-1;
    }

    int Count=0;

    for(int i=1;i<100000;i++)
    {
        P[i]=P[i-1]+P[i];
        if(P[i]!=0)
            Count++;
    }
    if(P[0]==0)
        cout<<Count<<endl;
    else
        cout<<Count+1<<endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
#define H 50
#define W 50
#define INF 1e+9
int h;
int w;
bool m[H][W];
void dfs(int y, int x)
{
    m[y][x] = false;
    trep(i, -1, 2)
    {
        trep(j, -1, 2)
        {
            int ny = y + i;
            int nx = x + j;
            if (0 <= ny && ny < h && 0 <= nx && nx < w && m[ny][nx] == true)
            {
                dfs(ny, nx);
            }
        }
    }
}
int main()
{
    while (scanf("%d%d%*c", &w, &h))
    {
        if (w == 0 && h == 0)
        {
            break;
        }
        rep(i, h)
        {
            rep(j, w)
            {
                cin >> m[i][j];
            }
        }
        int ans = 0;
        rep(i, h)
        {
            rep(j, w)
            {
                if (m[i][j] == true)
                {
                    dfs(i, j);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3328
process.stdin.resume();
process.stdin.setEncoding('utf8');

// Here your code !
function main (input) {
    input = input.trim().split('\n').map(Number);
    
    var rList = input.slice(1)
    var result = rList[1] - rList[0]
    var min = rList[0]
    rList.shift();
    
    rList.forEach(function (v) {
        result = Math.max(result, v - min);
        min = Math.min(min, v);
    });
    console.log(result)
}

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

Measured memory_bytes: 44396
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n;
	while(cin >> n, n){
		vector<ll> h(n+1);
		map<ll, int> ds;
		ll mx = 0, d;
		
		rep(i, n+1){
			cin >> h[i];
			if(i) ds[h[i] - h[i-1]]++;
		}
		if(n <= 10){
			rep(i, n+1){
				vector<ll> h2(h);
				h2.erase(h2.begin() + i);
				bool ok = 1;
				rep(j, h2.size() - 1) if(h2[j + 1] - h2[j] != h2[1] - h2[0]) ok = 0;
				if(ok){
					cout << h[i] << endl;
					goto END;
				}
			}
			assert(0);
		}
		
		for(auto p : ds) if(p.second > mx) mx = p.second, d = p.first;
		
		for(int i = 1; i < n; i++) if(h[i-1] + d != h[i] && h[i] != h[i+1] - d){
			cout << h[i] << endl;
			goto END;
		}
		cout << (h[0] + d != h[1] ? h[0] : h[n]) << endl;
		END:;
	}
	return 0;
}


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

const int INF = 0x3f3f3f3f, MAX_N =  2e5+10;
int N;
int P[MAX_N];
int dp[MAX_N];

void solve()
{
	int ans = 0;
	for(int i=1;i<=N;++i){
		dp[P[i-1]] = max(dp[P[i-1]], dp[P[i-1]-1]+1);
		ans =  max(ans, dp[P[i-1]]);
	}
	cout << N-ans << '\n';
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i) cin >> P[i];
	solve();
	return 0;
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
int  main(){
int a,b,c;
cin >> a >>b >> c;
for(int i=0;i<10000;i++){
  ll e = b*i+c;
  ll z = gcd(a,e);
  if(z%a==0){cout<<"YES"<<endl;return 0;}
}
cout<<"NO"<<endl;
}







Measured memory_bytes: 256
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        String s[] = sc.next().split("T", -1);
        int x = sc.nextInt();
        int y = sc.nextInt();

        List<Integer> tate = new ArrayList<>();
        List<Integer> yoko = new ArrayList<>();
        for (int i = 1; i < s.length; i++) {
            if (i % 2 == 0) {
                yoko.add(s[i].length());
            } else {
                tate.add(s[i].length());
            }
        }

        boolean dp[][] = new boolean[yoko.size() + 1][16001];
        dp[0][s[0].length() + 8000] = true;
        int i = 0;
        for (Integer dx : yoko) {
            for (int j = 0; j < 16000; j++) {
                if (dp[i][j]) {
                    if (j + dx <= 16000) {
                        dp[i + 1][j + dx] = true;
                    }
                    if (j - dx >= 0) {
                        dp[i + 1][j - dx] = true;
                    }
                }
            }
            i++;
        }
        boolean res1 = dp[yoko.size()][x + 8000];

        dp = new boolean[tate.size() + 1][16001];
        dp[0][8000] = true;
        i = 0;
        for (Integer dy : tate) {
            for (int j = 0; j < 16000; j++) {
                if (dp[i][j]) {
                    if (j + dy <= 16000) {
                        dp[i + 1][j + dy] = true;
                    }
                    if (j - dy >= 0) {
                        dp[i + 1][j - dy] = true;
                    }
                }
            }
            i++;
        }
        boolean res2 = dp[tate.size()][y + 8000];

        System.out.println(res1 & res2 ? "Yes" : "No");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 161128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	if(a>=400 && a<=599) cout<<8<<endl;
	else if(a>=600 && a<=799) cout<<7<<endl;
	else if(a>=800 && a<=999) cout<<6<<endl;
	else if(a>=1000 && a<=1199) cout<<5<<endl;
	else if(a>=1200 && a<=1399) cout<<4<<endl;
	else if(a>=1400 && a<=1599) cout<<3<<endl;
	else if(a>=1600 && a<=1799) cout<<2<<endl;
	else if(a>=1800 && a<=1999) cout<<1<<endl;
	
}

Measured memory_bytes: 3616
#include<iostream>
using std::cin;
using std::cout ;
int main()
{
	long int n,temp;
	int sum=0;
	cin>>n;
	temp=n;
	while(temp!=0)
	{
		sum+=temp%10;
		temp/=10;
	}
	if(0==n%sum)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}


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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> neg,pos,zer;
  rep(i,N) {
    ll t;
    cin>>t;
    if(t<0) neg.push_back(-t);
    if(t == 0) zer.push_back(t);
    if(t>0) pos.push_back(t);
  }
  sort(neg.begin(),neg.end());
  sort(pos.begin(),pos.end());
  ll l = -INF,r = INF;
  while(r-l>1) {
    ll mid = (l+r)/2;
    ll cnt = 0;
    //cout<<mid<<endl;
    if(mid<0){
      for(auto x:neg) {
        auto ite = lower_bound(pos.begin(),pos.end(),(-mid-1)/x+1);
        cnt += pos.end()-ite;
      }
    }
    if(mid ==0) {
      cnt += (ll) neg.size() * (ll)pos.size();
      cnt += (ll)zer.size()*(N-(ll)zer.size()) + (ll)zer.size()*(zer.size()-1)/2;
    }
    if(mid>0){
      cnt += (ll) neg.size() * (ll)pos.size();
      cnt += (ll)zer.size()*(N-(ll)zer.size()) + (ll)zer.size()*(zer.size()-1)/2;
      ll k = 0;
      for(auto x:neg){
        auto ite1 = upper_bound(neg.begin(),neg.end(),mid/x);
        k += ite1 - neg.begin();
        //cout<<"a "<<ite1-neg.begin()<<endl;
        if(x*x<=mid) k--;
      }
      for(auto x:pos){
        auto ite1 = upper_bound(pos.begin(),pos.end(),mid/x);
        k += ite1 - pos.begin();
        //cout<<"a "<<ite1 - pos.begin()<<endl;
        if(x*x<=mid) k--;
      }
      //cout<<"k"<<k<<endl;
      cnt += k/2;
    }
    //cout<<" "<<cnt<<endl;
    if(cnt < K) l = mid;
    else r = mid;
  }
  cout<<r<<endl;
}

Measured memory_bytes: 5544
#include <stdio.h>

int x[4],y[4],xx,yy,n;

int main(){


    for(n=0;n<2;n++) scanf("%d %d",&x[n],&y[n]);

    xx = x[1]-x[0];
    yy = y[1]-y[0];

    x[2] = x[1] - yy;
    y[2] = y[1] + xx;

    x[3] = x[2] - xx;
    y[3] = y[2] - yy;

    printf("%d %d %d %d\n",x[2],y[2],x[3],y[3]);






    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    ll res=0;
    ll m=n, cnt=0;
    while(m>0){
        res+=m%10;
        m/=10;
    }
    m=n;
    while(m>10){
        cnt++;
        m/=10;
    }
    chmax(res, 9*cnt+m-1);
    cout<<res<<endl;
    return 0;
}

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

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

using namespace std;
typedef long long ll;

int main(int argc, char const *argv[])
{
	int a, b; cin >> a >> b;
	if (a <= 8 && b <= 8) printf("Yay!\n");
	else printf(":(\n");
	return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

const vector<char> hands = {'r', 's', 'p'};

ll dynamic_programing(vector<char> &sequence, map<char, ll> &points) {
    if (sequence.empty()) return 0;
    vector<map<char, ll>> dp(sequence.size());

    auto get = [&](ll i, char h) {
        if (i == -1) return 0ll;
        if (dp[i].find(h) == dp[i].end()) return 0ll;
        return dp[i][h];
    };

    auto set = [&](ll i, char h, ll point) {
        if (dp[i].find(h) == dp[i].end()) {
            dp[i][h] = point;
        } else {
            cmax(dp[i][h], point);
        }
    };

    auto get_point = [&](char a, char b) {
        if (a == 'r') {
            if (b == 'p') return points['p'];
            else return 0ll;
        }
        if (a == 's') {
            if (b == 'r') return points['r'];
            else return 0ll;
        }
        if (a == 'p') {
            if (b == 's') return points['s'];
            else return 0ll;
        }
    };

    for (ll i = 0; i < sequence.size(); i++) {
        for (char b : hands) {
            for (char h : hands) {
                if (b == h) continue;
                ll point = get_point(sequence[i], h);
                set(i, h, get(i - 1, b) + point);
            }
        }
    }
    return max(max(dp.back()['r'], dp.back()['s']), dp.back()['p']);
}

int main() {
    ll n, k;
    cin >> n >> k;
    ll r, s, p;
    cin >> r >> s >> p;

    string t;
    cin >> t;

    vector<vector<char>> t_m_k(k);
    for (ll i = 0; i < t.size(); i++) {
        t_m_k[i % k].push_back(t[i]);
    }

    map<char, ll> points = {
            {'r', r},
            {'s', s},
            {'p', p},
    };
    ll ans = 0;
    for (ll i = 0; i < k; i++) {
        ans += dynamic_programing(t_m_k[i], points);
    }
    cout << ans << endl;
}


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

using namespace std;

#define pb push_back
#define ll long long
#define MX 1000009

bool marked[MX+1];

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

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

void sieve()
{
    marked[0] = true;
    marked[1] = true;
    for(int i = 4; i <= MX; i += 2)
        marked[i] = true;
    for(ll i = 3; i * i <= MX; i += 2)
    {
        for(ll j = i * i; j <= MX; j += i)
             marked[j] = true;
    }
}

int main()
{
    //cout << "Hello world!!" << endl;
 int n;
 cin >> n;
 string str;
 cin >> str;
 if( n % 2 == 1)cout << "No" << endl;
 else
 {
     string tmp = "";
     for(int i = 0; i * 2 < n; i++)
        tmp += str[i];
     tmp += tmp;
     if( str == tmp)cout << "Yes" << endl;
     else cout << "No" << endl;
 }

    return 0;
}


Measured memory_bytes: 256
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
x,y= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意

if 5<x<13:
    print(y//2)
elif x<6:
    print(0)
else:print(y)

Measured memory_bytes: 5444
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;

#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)

const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 2e5 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;

int n, m, k, x;
int a[105];

int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &k);
        while(k--) {
            scanf("%d", &x);
            a[x]++;
        }
    }
    int ans = 0;
    for(int i = 1; i <= m; i++) {
        if(a[i] == n) ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
vi va, vb;
void input() {
  cin >> N >> M;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; }
}
void solve() {
  // vaをsort
  sort(all(va));
  // vbは累積和
  vb.resize(N + 1);
  rep(i, 0, N - 1) { vb[i + 1] = vb[i] + va[i]; }

  // 二分探索
  auto findkey = [](int m) {
    int ng = INF;
    int ok = 0;

    while (abs(ok - ng) > 1) {
      int mid = (ok + ng) >> 1;
      int cnt = 0;

      rep(i, 0, N - 1) {
        int sa = mid - va[i];
        auto iter = lower_bound(all(va), sa);  // sa以上になる最小のiterator
        int okcount = va.end() - iter;
        cnt += okcount;
      }
      if (cnt >= m) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    return ok;  // 和がok以上のものであれば握手して良い
  };

  int X = findkey(M);  // M通り以上の握手ができる最小のXが求まった
  int ans = 0;

  // 和がXより大きいものを足す
  rep(i, 0, N - 1) {
    int key = X - va[i];
    auto iter = upper_bound(all(va), key);  // keyより大きい最小のもの
    int index = iter - va.begin();
    int cnt = N - index;
    ans += vb[N] - vb[index] + cnt * va[i];
    M -= cnt;
  }
  // 最後に，和がXになるものを足す
  ans += M * X;

  cout << ans << endl;
}

signed main() {
  input();
  solve();
  return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vi cnt(m+1,0);
  rep(i,n){
    int k;
    cin >> k;
    rep(j,k){
      int a;
      cin >> a;
      cnt[a]++;
    }
  }
  int ans=0;
  rep(i,m+1){
    if(cnt[i] == n) ans++;
  }
  cout << ans << endl;
}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

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

  ll x, y;
  int cnt = 0;
  for(int i=0; i<n; ++i){
    cin >> x >> y;
    if(x*x + y*y <= d*d) cnt++;
  }
  cout << cnt << endl;
}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define Maxn 607
using namespace std;
int n,d1,d2;
int flag1[Maxn][Maxn],flag2[Maxn][Maxn];
int c[Maxn*Maxn];
void dfs1(int x,int y,int now)
{
	if (flag1[x][y]!=-1) return;
	flag1[x][y]=now;
	for (int j=0;j<2*n;j++)
	{
		int del=d1-(x-j)*(x-j);
		if (del<0||c[del]==-1) continue;
		del=c[del];
		if (y-del>=0) dfs1(j,y-del,now^1);
		if (y+del<2*n) dfs1(j,y+del,now^1);
	}
}
void dfs2(int x,int y,int now)
{
	if (flag2[x][y]!=-1) return;
	flag2[x][y]=now;
	for (int j=0;j<2*n;j++)
	{
		int del=d2-(x-j)*(x-j);
		if (del<0||c[del]==-1) continue;
		del=c[del];
		if (y-del>=0) dfs2(j,y-del,now^1);
		if (y+del<2*n) dfs2(j,y+del,now^1);
	}
}
int main()
{
	scanf("%d%d%d",&n,&d1,&d2);
	memset(flag1,-1,sizeof(flag1));
	memset(flag2,-1,sizeof(flag2));
	c[0]=0;
	for (int i=1;i<=600*600;i++)
	{
		c[i]=-1;
		int t=sqrt(i);
		if (t*t==i) c[i]=t;
	}
	for (int i=0;i<2*n;i++)
		for (int j=0;j<2*n;j++)
		{
			if (flag1[i][j]==-1) dfs1(i,j,0);
			if (flag2[i][j]==-1) dfs2(i,j,0);
		}
	int res1,res2;
	int cnt1=0,cnt2=0,cnt3=0,cnt4=0;
	for (int i=0;i<2*n;i++)
		for (int j=0;j<2*n;j++)
		{
			if (flag1[i][j]) ++cnt1; else ++cnt2;
			if (flag2[i][j]) ++cnt3; else ++cnt4;
		}
	if (cnt1>=n*n&&cnt3>=n*n) res1=1,res2=1;
	if (cnt1>=n*n&&cnt4>=n*n) res1=1,res2=0;
	if (cnt2>=n*n&&cnt3>=n*n) res1=0,res2=1;
	if (cnt2>=n*n&&cnt4>=n*n) res1=0,res2=0;
	int ans=0;
	for (int i=0;i<2*n;i++)
		for (int j=0;j<2*n;j++)
			if (flag1[i][j]==res1&&flag2[i][j]==res2) 
			{
				printf("%d %d\n",i,j);
				++ans;
				if (ans==n*n) return 0;
			}
	return 0;
}

	

Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


int main(){fastio
    ll m,n;cin>>m>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=0;
    if(m==2){
        ll a1=0,a2=0;
        rep(i,0,n-1){
            if(i%2==0){
                if(a[i]==1)a1++;
                else a2++;
            }else{
                if(a[i]==2)a1++;
                else a2++;
            }
        }
        cout<<min(a1,a2)<<endl;return 0;
    }
    rep(i,0,n-1){
        ll c=1;
        while(i<=n-2&&a[i]==a[i+1]){
            c++;i++;
        }
        ans+=c/2;
    }
    cout<<ans<<endl;
    
    return 0;
}



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

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

  for (int i = 0; i < a.size(); ++i) {
    string rotation = a.substr(i, a.size() - i) + a.substr(0, i);
    if (rotation == b) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys


class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x


N, M = map(int, input().split())
info = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]

uf = UnionFind(N)
for a, b in info:
    uf.union(a, b)

ans = min(uf.parents)

print(-ans)


Measured memory_bytes: 121644
#include <bits/stdc++.h>
using namespace std; 
#define deb(x) cout << #x <<"="<< x <<endl;
#define deb2(x,y) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<endl;
#define deb3(x,y,z) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<<endl;
#define deb4(x,y,z,a) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<< ", "<<#a <<"="<<a << endl;
#define debarr(x) cout << #x<<"::"<<endl;for(int i : x){cout << i <<" ";} cout <<endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
#define vi vector<int>
#define int long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define fi first
#define se second
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)

#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;}; 



void solve(){
	int n , m , x;
	cin >> n >> m >> x;
	map <int, vi> cst;
	
	vector <vi> ans;
	ans.resize(n);
	map <int,int> mm;
	int cnt = 0;
	rep(i,n){
		int x1;
		cin >> x1;
		rep(j,m){
			int y;
			cin >> y;
			ans[cnt].pb(y);
		}
		mm[cnt] = x1;
		++cnt;
		
	}
	

	int mn = 1e18;
	
	for(int i = 0 ; i < (1 << n) ; i++){
		vi ans1(m,0);
		int cst = 0;

		
		for(int j = 0 ; j < n ;j++){
			if(i & (1 << j)){
				
				cst += mm[j];
				
				rep(k,m){
					ans1[k] += ans[j][k];
				}
				
				
				
			}
			
		}
		sort(all(ans1));
				if(ans1[0] >= x){
					
					mn = min(cst,mn);
					
				}
		
		
		
	}
	
	if(mn == 1e18){
		cout << -1 <<endl;
		return;
	}
	cout << mn<< endl;
	
	
	
	

	



}





signed main(){
    cin.tie(NULL),ios_base::sync_with_stdio(false),cout.tie(NULL);
    int t=1;

    while(t--)solve();
    return 0;
}



Measured memory_bytes: 3628
main = do
    s <- (map read . words) <$> getLine :: IO [Int]
    let a = s !! 0
    let b = s !! 1
    let k = (b - 1) `mod` (a - 1)
    print $ if k == 0 then (b-1) `div` (a-1) else (b-1)`div`(a-1) + 1

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


int main() {
    int n; cin >> n;
    if(n == 0) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<ll,ll> ms;

  string s;
  cin >> s;
  ll t=0;
  ll kake = 1;
  ms[t]++;
  for(int i=s.size()-1; i>=0; i--){
    t += kake * (s[i]-'0');
    t %= 2019;    
    ms[t]++;
    kake *= 10;
    kake %= 2019;
  }
  ll ans =0;
  for(auto i:ms){
    ans += i.second * (i.second -1 )/2;
    // cout << i.first << " " << i.second << endl;
  }

  cout << ans << endl;

  return 0;
    

}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
const int N=2e3+3;

  int n,A;
  int a[N];
void in()
{
  cin>>n;
  for (int i=0;++i<=n;)
    cin>>a[i],A+=a[i];
}

  bitset<N*N> f;
void wor()
{
  A=A+1>>1;
  f[0]=1;
  for (int i=0;++i<=n;)
    f|=f<<a[i];
  while (!f[A]) ++A;
}

void out()
{
  cout<<A;
}

int main()
{
  in();
  wor();
  out();
  exit(0);
}

Measured memory_bytes: 1792