akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e5 + 5;
ii x[maxn];
int n;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 0 ; i < n ; ++i)cin >> x[i].first >> x[i].second;
    vector<int> id(n , 0);
    for(int i = 0 ; i < n ; ++i)id[i] = i;
    ld res = 0;
    do{
        for(int j = 1 ; j < n ; ++j){
            res += sqrt((x[id[j]].first - x[id[j - 1]].first) * (x[id[j]].first - x[id[j - 1]].first) +
                        (x[id[j]].second - x[id[j - 1]].second) * (x[id[j]].second - x[id[j - 1]].second));
        }
    }while(next_permutation(id.begin(),id.end()));
    for(int i = 1 ; i <= n ; ++i)res /= 1.0 * i;
    cout << fixed << setprecision(6) << res;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const ll MAX = 510000;
const ll MOD = 1000000007;

ll ret[MAX];

void prime_factor(ll N){
  ll i;
  for(i=2;i*i<=N;i++){
    while(N%i==0){
      ret[i]++;
      N/=i;
    }
  }
  if(N!=1) ret[1] = 1;
}

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

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


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

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

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

  prime_factor(M);
  COMinit();

  ll ans = 1;
  rep(i,MAX){
    if(ret[i] == 0) continue;
    else{
      ans *= COM(ret[i]+N-1,N-1);
      ans %= MOD;
    }
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 12544
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Text;
using System.Threading.Tasks;

namespace B_Shift_only
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(ReadLine());
            string b = ReadLine();
            string[] array = b.Split(' ');
            int[] n = new int[a];
            for (int i = 0; i < a; i++) {
                n[i] = int.Parse(array[i]);
                    }
            int[] m = new int[a];
           
            int c = 0;
            int count = 0;
            for (int j = 0; j < a; j++) {
                c = n[j];
                for (int k = 0; k < n[j]; k++) {
                  
                    if (( c% 2) == 0)
                    {
                        c = c / 2;
                        count++;
                    } else {
                        m[j] = count;
                        count = 0;
                        break;
                    }
                }
               
            }
            int Max = m[0];
            for (int l = 0; l < a; l++)
            {
                if (Max > m[l]){
                    Max = m[l];
                }
            }
            WriteLine("{0}", Max);
            ReadKey();
        }
    }
}


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

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

  for(i=0; i<N; i++){
    b = a.at(b-1);
    if(b == 2){
      break;
    }
  }
  
  if(b == 2){
    cout << i+1 << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}






int main()
{

	int n;
	cin >> n;

	vector<long long int> a(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	bool plusmode = true;
	long long int ans = LLONG_MAX;
	long long int wk_ans = 0;
	long long int sum = 0;

	for (int i = 0; i < n; i++) {
		plusmode = !plusmode;

		sum += a[i];

		if (plusmode) {
			if (sum <= 0) {
				wk_ans += abs(sum) + 1;
				sum = 1;
			}
		}
		else {
			if (sum >= 0) {
				wk_ans += abs(sum) + 1;
				sum = -1;
			}
		}
	}
	if (wk_ans < ans)ans = wk_ans;


	plusmode = false;
	wk_ans = 0;
	sum = 0;
	for (int i = 0; i < n; i++) {
		plusmode = !plusmode;

		sum += a[i];

		if (plusmode) {
			if (sum <= 0) {
				wk_ans += abs(sum) + 1;
				sum = 1;
			}
		}
		else {
			if (sum >= 0) {
				wk_ans += abs(sum) + 1;
				sum = -1;
			}
		}
	}
	if (wk_ans < ans)ans = wk_ans;


	cout << ans << endl;


	return 0;

}



Measured memory_bytes: 1024
from math import floor
A,B = list(map(int, input().split()))

for i in range(1,10001):
  a = i * 0.08
  b = i * 0.1
  if A <= a and a < A+1 and B <= b and b < B+1:
    print(i)
    exit(0)
    
print(-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
	vector<vector<int>>g;
	vector<bool> visited;
	int n,m;

void add_edge(int a,int b){
	g[a].push_back(b);
	g[b].push_back(a);
}

int dfs(int i,int dpt){
//    cout<<dpt<<" "<<i+1<<endl;
	int ret=0;
	if(dpt==n)return 1;
	for(auto&& w:g[i]){
    if(!visited[w]){
      visited[i]=true;
      ret+=dfs(w,dpt+1);
      visited[i]=false;
	}
    }
  	return ret;
}


int main(){
	cin>>n>>m;
	g.resize(n);
	visited.assign(n,false);
	for(int i=0;i<m;i++){
	int a,b;cin>>a>>b;
	add_edge(--a,--b);	
	}
	cout<<dfs(0,1)<<endl;
}

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

class Main {

  public static void main(String args[]) throws IOException{

	  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt( br.readLine() );

      List Doublelink = new List();


      for(int i = 0; i < n; i++ ){

    	  String[] string =  br.readLine().split(" ");

    	  if( string[0].equals("insert") ){
    		  //System.out.println("check1 " + i);
    		  Doublelink.insert( Integer.parseInt( string[1] ) );
    		  //Doublelink.printlist();
    	  }
    	  else if( string[0].equals("delete") ){
    		  //System.out.println("check2 "+ i);
    		  Doublelink.delete( Integer.parseInt( string[1] ) );
    		 //Doublelink.printlist();
    	  }
    	  else if( string[0].equals("deleteFirst") ){
    		 //System.out.println("check3 " + i);
    		  Doublelink.deleteFirst();
    		  //Doublelink.printlist();

    	  }
    	  else if( string[0].equals("deleteLast") ){
    		 //System.out.println("check4 " + i);
    		  Doublelink.deleteLast();
    		 //Doublelink.printlist();

    	  }

    	 // System.out.println(n);
      }

      Doublelink.printlist();

 }
}


class Cell{

	Cell prev;
	Cell next;
	long data;

	Cell(long d) {
	   data = d;
	}

	void setNext(Cell next) {
        this.next = next;
    }

}

class List{

    Cell dummy;

    Cell tail;

	List() {
        // ??????????????????????????????next??¨prev????????????????????????????¨??????????
        dummy = new Cell(0);
        dummy.next = dummy;
        dummy.prev = dummy;
        tail = dummy;
    }


	void insert(long data) {//?????????????´?????????\
        // ???????????????

        Cell c = new Cell(data);
        c.next = dummy.next;
        c.prev = dummy;
        dummy.next.prev = c;
        dummy.next = c;
        tail = dummy.prev;

    }

	void deleteFirst() {//?????????????´??????????
        Cell c = dummy.next;
        c.next.prev=(c.prev);
        c.prev.next = c.next;
        tail = dummy.prev;
    }

	void deleteLast() {//????°????????´??????????


        tail.next.prev =  tail.prev ;
        tail.prev.next =  tail.next;
        tail = dummy.prev;
    }

	void delete(long data ) {//???????????????????´??????????




        for(Cell deletecell = dummy.next;  deletecell != dummy  ;  deletecell = deletecell.next){

        	if( deletecell.data == data ){

        		deletecell.prev.next =  deletecell.next;
        		deletecell.next.prev = deletecell.prev;

                break;
        	}


        }

        tail = dummy.prev;
	}

	void printlist() {//??????????????¨???



		for(Cell end = dummy.next; end!=dummy; end = end.next ){

			System.out.print( end.data );

        	if(end.next != dummy){
            	System.out.print( " " );
            }
		}




        System.out.println();

	}

}

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

int main() {
  int N;
  cin >> N;
  int M = N;
  int sum = 0;
  while (M != 0) {
    sum += M % 10;
    M /= 10;
  }
  if (N%sum == 0) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

struct Item {
  int v;
  ll w, m;
};

ll solveNVSmallKnapsack(ll W, vector<Item> items) {
  int N = items.size();
  int threshold = 0;
  for (auto& item : items) threshold = max(threshold, item.v);
  sort(items.begin(), items.end(),
       [&](auto& a, auto& b) { return a.v * b.w > b.v * a.w; });
  int V = threshold * threshold * N;
  vector<ll> dp(V + 1, W + 1);
  dp[0] = 0;
  for (auto& item : items) {
    int num = min((ll)threshold, item.m);
    for (int k = 1; num > 0; k <<= 1) {
      int mul = min(k, num);
      for (int j = V; j >= item.v * mul; j--) {
        dp[j] = min(dp[j], dp[j - item.v * mul] + item.w * mul);
      }
      num -= mul;
    }
  }
  ll res = 0;
  for (int i = 0; i <= V; i++) {
    ll vtot = i;
    ll wrem = W - dp[i];
    if (wrem < 0) continue;
    for (auto& item : items) {
      ll num = item.m - min((ll)threshold, item.m);
      ll mul = min(num, wrem / item.w);
      vtot += mul * item.v;
      wrem -= mul * item.w;
    }
    res = max(res, vtot);
  }
  return res;
}

int main() {
  int N;
  ll X, D;
  while (cin >> N >> X >> D) {
    vector<ll> m(N);
    cin >> m[0];
    vec<int, 2> G(N);
    for (int i = 1; i < N; i++) {
      int p;
      cin >> m[i] >> p;
      --p;
      G[p].push_back(i);
    }
    vector<int> sz(N);
    vector<ll> msum(N);
    function<void(int)> dfs = [&](int v) {
      sz[v] = 1;
      msum[v] = m[v];
      for (int u : G[v]) {
        dfs(u);
        sz[v] += sz[u];
        msum[v] += msum[u];
      }
    };
    dfs(0);
    vector<Item> items;
    for (int i = 0; i < N; i++) {
      ll lim = D;
      if (i == 0) lim = X / msum[0];
      items.push_back({sz[i], msum[i], lim});
    }
    cout << solveNVSmallKnapsack(X, items) << endl;
  }
  return 0;
}


Measured memory_bytes: 1280
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

struct edge{int to; int cost;};
vector<vector<P>> graph(0);
vector<int> d(0);
const int MAX_dist=1e9;

void init(int n){
    graph.resize(n);
    d.resize(n,MAX_dist);
}

void dijkstra(int s){
if(d.size()==0){cout<<"You Should init"<<endl;return;}
    priority_queue<P, vector<P>, greater<P>> que;
    d[s]=0;
    que.emplace(0,s);
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,graph[v].size()){
            auto e=graph[v][i];
            if(d[e.first]>d[v]+e.second){
            d[e.first]=d[v]+e.second;
            que.emplace(d[e.first],e.first);
            }
        }
    }
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,x,y;
    cin>>n>>x>>y;
    x --,y --;
    init(n);
    rep(i,n-1){
        graph[i].emplace_back(i+1,1);
        graph[i+1].emplace_back(i,1);
    }
    graph[x].emplace_back(y,1);
    graph[y].emplace_back(x,1);
    map<int,int> a;
    rep(i,n-1){
        dijkstra(i);
        REP(j,i+1,n) a[d[j]] ++;
        rep(j,n) d[j]=MAX_dist;
    }
    REP(i,1,n) cout<<a[i]<<'\n';
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b;
cin>>a>>b;
long long ans=-1;
for(long long i=b;i<((double)(100*b)+1);i++){
  if((double)(i*8)/100>=a&&(double)(i*8)/100<a+1&&(double)(i*10)/100>=b&&(double)(i*10)/100<b+1){
    ans=i;
    break;
  }
}
cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  int ans=0;
  int outlet=1;
  while(outlet<b){
    --outlet;
    outlet+=a;
    ++ans;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;

    vector<array<int, 4>> ops;

    int carry_h = 0;

    for (int i = 0; i < H; ++i) {
        int carry_w = 0;
        int tmp;

        for (int j = 0; j < W-1; ++j) {
            cin >> tmp;
            tmp += carry_w;

            if (tmp % 2 == 1) {
                ops.push_back({i, j, i, j+1});
                carry_w = 1;
            } else {
                carry_w = 0;
            }
        }

        cin >> tmp;
        tmp += carry_w + carry_h;
        if (tmp % 2 == 1 && i < H-1) {
            ops.push_back({i, W-1, i+1, W-1});
            carry_h = 1;
        } else {
            carry_h = 0;
        }
    }

    cout << ops.size() << endl;
    for (auto e: ops) {
        cout << e[0]+1 << " " << e[1]+1 << " " << e[2]+1 << " " << e[3]+1 << endl;
    }

    return 0;
}



Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
long long a[4];
int k;
int main()
{
    while(cin>>a[0]>>a[1]>>a[2])
    {
        cin>>k;
        sort(a,a+3);
        while(k)
        {
           a[2]*=2;
           k--;
        }
        long long ans=a[0]+a[1]+a[2];
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n, k, q = rm()
li = [1] * n
if q >= k:
    li = [k-q] * n
    for _ in range(q):
        li[ri()-1] += 1
for i in li:
    if i <= 0:
        print('No')
    else:
        print('Yes')







Measured memory_bytes: 15480
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
ll n,m;
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
} 
int main()
{
	n=read(),m=read();
	printf("%d\n",n*(n-1)/2+m*(m-1)/2);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

int N;

ll dp[200000 + 5][2];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	scanf("%d", &N);

	int temp;

	scanf("%d", &temp);
	
	dp[0][0] = 0;
	dp[0][1] = temp;

	scanf("%d", &temp);
	
	dp[1][0] = max(dp[0][1], 1LL * temp);
	dp[1][1] = 0;

	for (int i = 2; i < N; ++i)
	{
		scanf("%d", &temp);
		if (i % 2 == 0)
		{
			dp[i][0] = max(dp[i - 2][0] + temp, dp[i - 1][0]);
			dp[i][1] = dp[i - 2][1] + temp;
		}
		else
		{
			dp[i][0] = max(dp[i - 2][0] + temp, dp[i - 1][1]);
			dp[i][1] = 0;
		}
	}

	printf("%lld\n", dp[N - 1][0]);

	return 0;
}

Measured memory_bytes: 6960
n = int(input())
h = list(map(int, input().split()))

can = True

for i in range(n):
    if i == 0:
        h[i] -= 1
        continue
    if h[i] > h[i - 1]:
        h[i] -= 1
    elif h[i] < h[i - 1]:
        can = False
        break

print("Yes" if can else "No")


Measured memory_bytes: 14396
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort() ; B.sort() ; C.sort()
import bisect as bi

ans=0

for i in B:
    ans+= bi.bisect_left(A,i) * (n-bi.bisect_right(C,i))
print(ans)


Measured memory_bytes: 23328
#include <iostream>
using namespace std;
int main()
{
	long long a,b;
	while(cin >> a >> b)
	{		
		if(a<b)
		{
			a=a+b;
			b=a-b;
			a=a-b;
		}
		long long a1=a,b1=b;
		while (a%b != 0)
		{
			long long c=a%b;
			a=b;
			b=c;
		}
		cout << b << ' '<<a1*b1/b << endl;	
	}
}

Measured memory_bytes: 3104
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    //ここから4行配列として数列を受け取る
    Integer a[] = new Integer[N];
    for(int i = 0; i < N; i++){
      a[i] = sc.nextInt();      
    }
    //配列を降順に並び替える
    Arrays.sort(a, Comparator.reverseOrder());
    
    int count = 0;
    //隣あう配列が同じならcountを＋１する
    for(int i = 1; i < N; i++){
      if(a[i-1].equals(a[i])){
        count++;
      }
    }
    
    //countが0以外ならNOを返す
    if(count == 0){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }

}
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 079 C / Link: http://abc079.contest.atcoder.jp/tasks/abc079_c  ----- */


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

	string s; cin >> s;
	VI a(4);
	FOR(i, 0, 4) {
		a[i] = s[i] - '0';
	}
	FOR(state, 0, 1 << 3) {
		int ret = a.front();
		FOR(i, 0, 3) {
			if (state & 1 << i) {
				ret -= a[i + 1];
			}
			else {
				ret += a[i + 1];
			}
		}


		if (ret == 7) {
			FOR(i, 0, 4) {
				cout << a[i];
				if (i < 3) {
					cout << "+-"[state >> i & 1];
				}
			}
			cout << "=7" << endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int dp[105][105][2], n, m;

int main(){
    int l;
    int a, b, c, d;
    int st, en, de;

    while(cin >> n >> m, n||m){
        rep(i, 105){
            rep(j, 105){
                rep(k, 2){
                    dp[i][j][k] = 2 << 24;
                }
            }
        }

        rep(i, n){
            cin >> a >> b >> c >> d;
            dp[a][b][0] = dp[b][a][0] = c;
            dp[a][b][1] = dp[b][a][1] = d;
        }

        rep(k, m+1){
            rep(i, m+1){
                rep(j, m+1){
                    dp[i][j][0] = min(dp[i][k][0] + dp[k][j][0], dp[i][j][0]);
                    dp[i][j][1] = min(dp[i][k][1] + dp[k][j][1], dp[i][j][1]);
                }
            }
        }

        cin >> l;
        rep(i, l){
            cin >> st >> en >> de;
            cout << dp[st][en][de] << endl;
        }
    }
}

Measured memory_bytes: 1244
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#define ll long long
using namespace std;

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

int main()
{
    ll a,b;
    scanf("%lld%lld",&a,&b);
    printf("%lld",a*b/gcd(a,b));
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  IN(N,M);
  ll s = 1, e = N;
  vb flag(N+1, false);
  REP(i,M){
    if(e-s == (N+s)-e) e--;
    if(flag[e-s] || flag[(N+s)-e]) e--;
    printf("%lld %lld\n", s, e);
    flag[e-s] = true;
    flag[(N+s)-e] = true;
    s++;
    e--;
  }
  return 0;
}

Measured memory_bytes: 3764
N,M=map(int,input().split())
if M!=0:
    a=[list(map(int,input().split())) for i in range(M)]
    ans=0
    for i in range(M):
        if ans==-1:
            break
        for j in range(M):
            if a[i][0]==a[j][0] and a[i][1]!=a[j][1]:
                ans=-1
                break
#print(ans)####      
    answer=[0]*N
    answer[0]=1
    for i in range(M):
        answer[a[i][0]-1]=a[i][1]
    
    if answer[0]==0 and N>=2:
        ans=-1
#print(answer)######
    if ans==-1:
        print(ans)
    elif answer[0]==0 and N==1:
        print("0")
    else:
        ans=0
        for i in range(N):
            ans+=answer[i]*(10**(N-i-1))
        print(ans)
else:
    if N!=1:
        print(10**(N-1))
    else:
        print("0")

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

/**
 * Change a Little Bit
 * 
 * https://atcoder.jp/contests/abc150/tasks/abc150_e
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            long MOD = 1000000007;

            int N = sc.nextInt();
            long[] C = new long[N];
            for (int i = 0; i < N; i++) {
                C[i] = sc.nextLong();
            }

            Arrays.sort(C);

            long P = pow(2, N - 1, MOD);

            long ans = 0;
            for (int i = 0; i < N; i++) {
                long p = P * (N - i + 1) % MOD;
                ans = (ans + C[i] * p) % MOD;
            }

            ans = (ans * P) % MOD;

            System.out.println(ans);
        }
    }

    static long pow(long A, long B, long MOD) {
        if (B == 0) {
            return 1;
        } else if (B % 2 == 0) {
            long C = pow(A, B / 2, MOD);
            return C * C % MOD;
        } else {
            long C = pow(A, B - 1, MOD);
            return A * C % MOD;
        }
    }

}


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

using namespace std;

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

    unsigned long long x, y;
    cin >> x >> y;
    int cnt = 0;
    for(unsigned long long tar = x; tar <= y; tar *=2) ++cnt;
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long gcd(long a,long b)
{
        if(a==b)
         return a;
        else if(a%b==0)
        {
                return b;
        }
        else if(b%a==0)
        {
                return a;
        }
        else if(a>b)
        {
                return gcd(b,a%b);
        }
        else{
                return gcd(a,b%a);
        }
        
}
int main()
{
   int n;cin>>n;
   long sum=0;
   for(int i=1;i<=n;i++)
   {
           for(int j=1;j<=n;j++)
           {
                   for(int k=1;k<=n;k++)
                   {
                           sum=sum+gcd(gcd(i,j),k);
                   }
           }
   }
   cout<<sum<<endl;
  // cout<<gcd(9,3)<<endl;
}


Measured memory_bytes: 3192
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

bool check(int N, int D, VEC(Pii)& sat)
{
    ostringstream out;
    out << N;
    string s = out.str();
    if (s.size() != D)
        return false;

    for (Pii st: sat) {
        int i = st.first, d = st.second;
        if (s[i - 1] - '0' != d)
            return false;
    }

    return true;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    //
    int D, M;
    cin >> D >> M;
    VEC(Pii) sat(M);
    READVEC(sat);
    FOR(i, 0, 1000)
        if (check(i, D, sat)) {
            cout << i << endl;
            return 0;
        }

    cout << -1 << endl;
    return 0;
};

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
int N,T,A; cin >> N >> T >> A;
vector<int> H(N);
rep(i,N){
  cin >> H[i];
}
int ans = 1000000;
rep(i,N){
  ans = min(abs(1000*T-(H[i]*6)-1000*A),ans);
}
rep(i,N){
if(ans == abs(1000*T-(H[i]*6)-1000*A)){
  cout << i +1<< endl;
}
}
}

Measured memory_bytes: 256
'use strict'

function main(input) {
  input = input.trim().split('\n')
  const img = input.slice(1)

  let tmp = []
  for (let i = 0; i < img.length; i++) {
    tmp.push(img[i])
    tmp.push(img[i])
  }

  console.log(tmp.join('\n'))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7496
#include <stdio.h>

int main(void)
{
        int n,i;
        long s;

        scanf("%d",&n);

        s=0;

        for(i=1;i<=n;i++){
                if(i%3==0) ;
                else if(i%5==0) ;
                else if(i%15==0) ;
                else s=s+i;
        }

        printf("%ld\n",s);
        return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> v(n),c(n),diff;
  for(int i=0; i<n; i++) cin>>v[i];
  for(int i=0; i<n; i++) cin>>c[i];
  for(int i=0; i<n; i++) {
    int x = v[i]-c[i];
    diff.push_back(x);
  }
  int sum=0;
  for(int i=0; i<n; i++){
    if(diff[i]>0) sum += diff[i];
  }
  cout<<sum;
}

Measured memory_bytes: 256
#include <stdio.h>
int a, b, c, m, ans, x, y;
int d[100000];
int e[100000];
int main() {
	x = 100000;
	y = 100000;
	scanf("%d%d%d", &a, &b, &m);
	for (int i = 0; i < a; i++) {
		scanf("%d", d + i);
		if (d[i] < x)x = d[i];
	}
	for (int i = 0; i < b; i++) {
		scanf("%d", e + i);
		if (e[i] < y)y = e[i];
	}
	ans = x + y;
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &x, &y, &c);
		x--; y--;
		if (d[x] + e[y] - c < ans)ans = d[x] + e[y] - c;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 896
// Vivek Rai
// Blazer_007

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define fastio      ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define ppi         pair<int,pii>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define bit(x, y)   (((x)>>(y))&1)
#define bpt(x)      (__builtin_popcount(x))
#define bptl(x)     (__builtin_popcountll(x))
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)

using namespace std;
using namespace __gnu_pbds;

typedef priority_queue<int> maxHeap;
typedef priority_queue<int, vector<int>, greater<int> > minHeap;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(index) -> value at given index or Kth smaintest element in set
// order_of_key(X) -> number of elements strictly less than X
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> OST;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cout << name << " : " << arg1 << endl;
    //use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
istream &operator>>(istream &in, vector<T> &arr)
{
    for(int i = 0 ; i < arr.size() ; i++)
        cin >> arr[i];
    return in;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> arr)
{
    for(int i = 0 ; i < arr.size() ; i++)
        cout << arr[i] << " ";
    cout << endl;
    return os;
}


void solution()
{
    int n;
    cin >> n;
    cout << 1-n << endl;
}

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

    int t = 1;
    // cin >> t;
    loop(i, 1, t + 1)
    {
        //cout<<"Case #"<<i<<": ";
        solution();
    }
}

Measured memory_bytes: 3636
import sys

n, x, m = map(int, input().split())

if x == 0:
    print(0)
    sys.exit()

l = [x]
s = {x}
prev = x

for i in range(1, m):
    next = prev ** 2
    next = next % m
    if next in s:
        break
    s.add(next)
    l.append(next)
    prev = next
start = l.index(next)
length = i - start

ans = 0
if n < start + length:
    ans += sum(l[:n])
else:
    ans += sum(l[:start])
    ans += sum(l[start:]) * ((n - start) // length)
    ans += sum(l[start:(start + ((n - start) % length))])

print(ans)


Measured memory_bytes: 76748
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  string s;
  cin >> s;
  bool ok = true;
  string sr = s;
  reverse(ALL(s));
  int n = s.size();
  string subS = s.substr(0, (n - 1) / 2);
  string subSR = subS;
  reverse(ALL(subSR));
  string s3 = s.substr((n + 3 - 1) / 2, n - 1);
  string s3r = s3;
  reverse(ALL(s3r));
  if (s != sr || subS != subSR || s3 != s3r) {
    ok = false;
  }

  print(ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long int
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;

int n, d;

signed main()
{
  cin >> n >> d;

  if(d == 1){
    cout << 1 + 2 * (n - 2) + (n - 2) * (n - 3) / 2 << endl;
  }
  else{
    cout << d + 3 * (n - d - 1) + (n - d - 1) * (n - d - 2) / 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;

vector<int> num;

long long sequence(int s) {
  long long sum = s;
  long long res = 0;
  
  for (int i = 1; i < num.size(); i++) {
    if (sum > 0) {
      if (sum + num[i] >= 0) {
        res += 1 + num[i] + sum;
        sum = -1;
      } else {
        sum += num[i];
      }
    } else {
      if (sum + num[i] <= 0) {
        res += 1 - num[i] - sum;
        sum = 1;
      } else {
        sum += num[i];
      }
    }
  }
  
  return res;
}

int main() {
  int n; scanf("%d", &n);
  
  num.resize(n);
  for (int i = 0; i < n; i++) scanf("%d", &num[i]);
  
  long long ans1;
  long long ans2;
  
  if (num[0] == 0) {
    ans1 = sequence(1) + 1;
    ans2 = sequence(-1) + 1;
  } else if (num[0] > 0) {
    ans1 = sequence(num[0]);
    ans2 = sequence(-1) + num[0] + 1;
  } else {
    ans1 = sequence(1) + abs(num[0]) + 1;
    ans2 = sequence(num[0]);
  }
  
  printf("%lld", min(ans1, ans2));
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<string> w(n);
    for(int i=0;i<n;i++){
        cin>>w[i];
    }
    bool flag=true;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(w[i]==w[j])flag=false;
        }
    }
    for(int i=1;i<n;i++){
        if(w[i-1][w[i-1].size()-1]!=w[i][0])flag=false;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  int k;
  cin>>s>>k;
  for(int i=0;i<k;i++){
    if(s.at(i)!='1'){
      cout<<s.at(i)<<endl;
      return 0;
    }
    else if(i+1==k){
      cout<<1<<endl;
    }
  }
}

Measured memory_bytes: 256
n = gets.to_i
ans = 0
((n+1)/2).times do |i|
  t = 1 + 2 * i
  cnt = 0
  (i+1).times do |j|
    q = 1 + 2 * j
    cnt += 1 if t % q == 0
  end
  ans += 1 if cnt == 8
end
puts ans


Measured memory_bytes: 1788
import Data.Maybe

main :: IO ()
main =do
  [n,y] <- map read . words <$> getLine :: IO [Int]
  let list = [if (a*10+b*5+c)*1000==y then Just [a,b,c] else Nothing
           | a <- [0..n], b <- [0..n-a], let c = n-a-b ] :: [Maybe [Int]]
  putStr . unwords . map show . fromJust . head $ filter isJust list ++ [Just [-1,-1,-1]]

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

int main()
{
    int n;
    cin >> n;
    int a[n][n];
    bool b[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
            b[i][j] = true;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if (i == k || k == j) continue;

                if (a[i][j] == a[i][k] + a[k][j]) b[i][j] = b[j][i] = false;
                else if (a[i][j] > a[i][k] + a[k][j]) { cout << -1 << endl; return 0; }
            }
        }
    }
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (b[i][j]) sum += a[i][j];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long 
#define N 100005

using namespace std;

int X[N],P[N],n,S,ret,s,t;

signed main()
{
	scanf("%lld%lld",&n,&S);
	for(int i=0;i<n;i++) scanf("%lld %lld",&X[i],&P[i]);
	ret=0; s=0,t=n-1;
	while(s<=t)
	{
		if(S<=X[s])
		{
			ret+=X[t]-S;
			break;
		}
		if(X[t]<=S)
		{
			ret+=S-X[s];
			break;
		}
		if(P[s]>=P[t])
		{
			ret+=X[t]-X[s];
			while(s<t&&P[s]>=P[t])
			{
				P[s]+=P[t];
				t--;
			}
		}
		else
		{
			ret+=X[t]-X[s];
			while(s<t&&P[s]<P[t])
			{
				P[t]+=P[s];
				s++;
			}
		}
	}
	cout << ret << endl;
	return 0;
}


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

int N,A[100001];
long long sum[100001],M;

int main(){
	scanf("%d%lld",&N,&M);
	for(int i=1;i<=N;i++) scanf("%d",&A[i]);
	sort(A+1,A+N+1);
	for(int i=1;i<=N;i++)sum[i]=sum[i-1]+A[i];
	int l=0,r=3e5,mid,ans;
	long long res,cnt;
	while(l<=r){
		mid=(l+r)>>1;
		cnt=res=0ll;
		for(int i=1;i<=N;i++){
			int x=lower_bound(A+1,A+N+1,mid-A[i])-A;
			cnt+=N-x+1;
			res+=sum[N]-sum[x-1]+(long long)(A[i])*(N-x+1);
		}
		if(cnt>=M){
			ans=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	printf("%lld\n",res-(cnt-M)*(long long)(ans));
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];

		for(int i=0;i<n;i++){
			a[i]=scan.nextInt();
		}

		for(int i=0;i<a.length;i++){
			b[a.length-(i+1)] = a[i];
		}
		
		for(int i=0; i<n-1;i++){
			System.out.print(b[i]+" ");
		}

		System.out.println(b[n-1]);
	}

}

Measured memory_bytes: 26392
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  ll x;
  cin >> x;
  ll tmp=0;
  ll ans=-1;
  rep(i,100000){
    tmp+=i;
    if(tmp>=x) {
      ans=i;
      break;
    }
  }

  prt(ans);
}


Measured memory_bytes: 3636
N,K,S,T=gets.split.map &:to_i
A=gets.split.map(&:to_i).select{1>~_1&S|_1&~T}
c=[1]*-~N
P=[]
c.map{P<<c[K]-1
t=0
c.map!{t+t=_1}}
p (0..262143).sum{|u|~u&S|u&~T<1?A.map{_1&u}.tally.sum{P[_2]}*(1-('%b'%(u-S)).count(?1)%2*2):0}

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


class Program
{
    public void Slove()
    {    
        var inputs = Console.ReadLine().Split();
        int n = int.Parse(inputs[0]);
        long k = long.Parse(inputs[1]);
        int[] hist = new int[63];
        long[] xs =
            Console.ReadLine().Split()
            .Select(long.Parse)
            .ToArray();

        foreach(long num in xs)
        {
            foreach(int i in Enumerable.Range(0, 63))
            {
                if((num >> i & 1) == 1)
                {
                    hist[i]++;
                }
            }
        }
        long result = 0;

        long[] sum = hist
            .Reverse()
            .SkipWhile(x => x == 0)
            .Reverse()
            .Select((x, i) => (long)Math.Max(x, n - x) << i).ToArray();
        long[] dp = new long[2];
        foreach(var data in hist.Select((Value, Index) => new { Value, Index}))
        {
            if(data.Value > n - data.Value)
            {
                dp[0] += (long)data.Value << data.Index;
                if((k >> data.Index & 1) == 1)
                    dp[1] = dp[0];
                else
                    dp[1] += (long)data.Value << data.Index;
            }
            else
            {
                dp[0] += (long)(n - data.Value) << data.Index;
                if((k >> data.Index & 1) == 1)
                    dp[1] += (long)(n - data.Value) << data.Index;
                else
                    dp[1] += (long)data.Value << data.Index;
            }
        }
        //Console.WriteLine(string.Join(",",hist));
        Console.WriteLine(dp[1]);

    }
    static void Main(string[] args)
    {
        var p = new Program();
        p.Slove();
    }
}


Measured memory_bytes: 33244
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;
vector<int>B,NB;

int main()
{
	int N,K;
	double res=0;
	cin>>N>>K;
	for(int i=1;i<=N;i++)
	{
		double cp=1;
		for(int j=i;j<K;j*=2)
			cp/=2;
		res+=cp*(1.0/N);
	}
	cout<<std::setprecision(10)<<res<<endl;
}

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


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}

int main(){
    ll X;
    cin>>X;
    X = 1999-X;
    cout<<X/200+1;
    return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int H, A;
    cin >> H >> A;
    cout << H / A + !!(H % A) << endl;
    return 0;
}

Measured memory_bytes: 3532