akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
using namespace std;

int main(){
  int n, m;

  cin >> n >> m;
  int a[n],b[m],c[n];

  memset(c,0,sizeof(c));

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

  for(int i = 0 ; i < m ; i++){
    for(int j = 0 ; j < n ; j++){
      if(a[j] <= b[i]){
	c[j]++;
	break;
      }
    }
  }

  int ans,maxi = 0;
  for(int i = 0 ; i < n ; i++){
    if(maxi < c[i]){
      maxi = c[i];
      ans = i + 1;
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

using ll = long long;

vector< int > v[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }

    priority_queue<int> pq;
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        for (int x : v[i]) pq.push(x);
        if (pq.empty()) continue;
        ans += pq.top();
        pq.pop();
    }

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

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e5)+10;
int n,a[maxn],b[maxn],pos[maxn],c[maxn],C[maxn],cnt;
struct node { int x,y; } d[maxn],e[maxn];
bool cmp(node a,node b) { return a.y<b.y; }
void WA() { printf("No\n"); exit(0); }
void Swap(int x,int y) {
	//printf("%d %d\n",x,y);
	swap(c[x],c[y]); swap(C[x],C[y]);
	pos[c[x]]=x; pos[c[y]]=y;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(d[i].x);
	for (int i=1;i<=n;i++) read(d[i].y);
	sort(d+1,d+n+1,cmp);
	for (int i=1;i<=n;i++) {
		a[i]=d[i].x,b[i]=d[i].y;
		e[i]=(node){i,d[i].x};
		C[i]=a[i];
	}
	sort(e+1,e+n+1,cmp);
	for (int i=1;i<=n;i++) {
		c[e[i].x]=i,pos[i]=e[i].x;
		if (e[i].y>b[i]) WA();
	}
	//for (int i=1;i<=n;i++) printf("%d ",c[i]); printf("\n");
	//for (int i=1;i<=n;i++) printf("%d ",a[i]); printf("\n");
	for (int i=1;i<n;i++) {
		if (C[i]==e[i].y) continue;
		Swap(pos[i],i); cnt++;
	}
	if (cnt==n-1) {
		for (int i=1;i<n;i++)
			if (e[i+1].y<=b[i]&&e[i].y<=b[i+1]) { printf("Yes\n"); return 0; }
		WA();
	}
	printf("Yes\n");
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 3712
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

using namespace std;

long long int cost[200][200];

int main(){
	
	while(true){
		int N, M, L, K, A, H;
		cin >> N >> M >> L >> K >> A >> H;
		if(N == 0){
			break;
		}
		
		bool flag[200] = {};
		for(int i = 0; i < L; i++){
			int num;
			cin >> num;
			flag[num] = true;
		}
		flag[A] = true;
		flag[H] = true;
		
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				cost[i][j] = INF;
			}
			cost[i][i] = 0;
		}
		for(int i = 0; i < K; i++){
			long long int u, v, T;
			cin >> u >> v >> T;
			cost[u][v] = T;
			cost[v][u] = T;
		}
		for(int k = 0; k < N; k++){
			for(int i = 0; i < N; i++){
				for(int j = 0; j < N; j++){
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				if(!flag[i] || !flag[j] || cost[i][j] > M){
					cost[i][j] = INF;
				}
			}
		}
		for(int k = 0; k < N; k++){
			for(int i = 0; i < N; i++){
				for(int j = 0; j < N; j++){
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		
		if(cost[A][H] == INF){
			cout << "Help!" << endl;
		}else{
			cout << cost[A][H] + max(0LL, cost[A][H] - M) << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3240
#include<stdio.h>
int main(void){
	int a[20][20]={};
	int cnt[20]={};
	int max=0;
	int m,n;
	scanf("%d%d",&m,&n);
	int i,j;
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			scanf("%d",&a[i][j]);
			if(a[i][j]==1)cnt[i]++;
		}
		if(max<cnt[i])max=cnt[i];
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

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

  set<int> s;
  s.insert(A);
  s.insert(B);
  s.insert(C);
  if (len(s) == 2)
    cout << "Yes\n";
  else
    cout << "No\n";
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) break;
			int sum = 0;
			for (int i = 0; i < n / 4; i++) {
				sum += sc.nextInt();
			}
			out.println(sum);
		}
		out.flush();
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) { return false; }
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public int nextInt() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) { throw new NumberFormatException(); }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
}

Measured memory_bytes: 24048
#include <iostream>
#include <string>

using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    for (int k = i + 1; k < s.length(); k++) {
      if (s[i] == s[k]) {
        cout << "no" << endl;
        return 0;
      }
    }
  }
  cout << "yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<pii, lint> ppl;
typedef complex<double> xy_t;
typedef pair<xy_t, int> pci;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

lint r, s, p;

inline int idx(char c){
    return c=='p' ? 2 : c=='s';
}

inline lint score(int i){
    if(i==0) return r;
    else if(i==1) return s;
    else return p;
}

int main(){
    int n, K;
    scanf("%d%d", &n, &K);
    scanf("%lld%lld%lld", &r, &s, &p);
    string t;
    cin>>t;
    vector<string> u(K, "");
    rep(i, n) u[i%K]+=t[i];

    lint ans=0;
    rep(i, K){
        int m=u[i].size();
        vector<vector<lint>> dp=vector<vector<lint>>(m+1, vector<lint>(3, 0));
        rep(j, m)rep(k, 3){
            if(k==(idx(u[i][j])+2)%3){
                lint tmp=0;
                rep(l, 3)if(k!=l) chmax(tmp, dp[j][l]+score(k));
                dp[j+1][k]=tmp;
            }
            else{
                dp[j+1][k]=j ? dp[j][(idx(u[i][j-1])+2)%3] : 0;
            }
        }
        lint tmp=0;
        rep(j, 3) chmax(tmp, dp[m][j]);
        ans+=tmp;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 5888
program balanced_piles
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer :: n, h, d, i
  integer(8) :: dp(1000000) = 0_8, f = 1_8, k = 0_8, s = 0_8
  read(*,*) n, h, d
  do i = 1, n
    f = mod(int(i,8)*f,md)
    k = mod(k+f,md)
  end do
  do i = 1, d
    dp(i) = mod(s*k+f,md)
    s = mod(s+dp(i),md)
  end do
  do i = d+1, h
    dp(i) = mod(s*k,md)
    s = mod(s+md-dp(i-d)+dp(i),md)
  end do
  write(*,'(i0)') dp(h)
end program balanced_piles

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int maxn = 50;
int n, A;
long long dp[maxn + 3][2500 + 3][maxn + 3];
long long arr[maxn + 3];

long long solve(long long index, long long sum, long long numberOfChosen)
{
    if(index == n)
    {
        return (numberOfChosen != 0 && sum % A == 0 && A * numberOfChosen == sum);
    }
    if(dp[index][sum][numberOfChosen] != -1)
        return dp[index][sum][numberOfChosen];
    long long ans = 0;
    ans += solve(index + 1, sum, numberOfChosen);
    ans += solve(index + 1, sum + arr[index], numberOfChosen + 1);
    return dp[index][sum][numberOfChosen] = ans;
}

int main()
{
    cin >> n >> A;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0, 0);
    return 0;
}

Measured memory_bytes: 55168
n,k = map(int, input().split())
a=[int(input()) for i in range(n)]

ide_ele = 0

def segfunc(x, y):
    return max(x,y)

class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

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

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

maxa=max(a)
al = [0]*(maxa+1)
seg = SegTree(al, segfunc, ide_ele)

for num in a:
    l=max(0,num-k)
    r=min(maxa,num+k)
    mx = seg.query(l,r+1)
    seg.update(num,mx+1)

print(seg.query(0,maxa+1))

Measured memory_bytes: 143548
from collections import Counter

n=int(input())
l = list(map(int, input().split()))

l0 = l[::2]
l1 = l[1::2]
c0 = Counter(l0)
c1 = Counter(l1)
ll0 = len(l0)
ll1 = len(l1)

c0m = c0.most_common()[:2] + [(0, 0)]
c1m = c1.most_common()[:2] + [(0, 0)]

if c0m[0][0] != c1m[0][0]:
  print(ll0 - c0m[0][1] + ll1 - c1m[0][1])
else:
  print(min(ll0 - c0m[1][1] + ll1 - c1m[0][1], ll0 - c0m[0][1] + ll1 - c1m[1][1]))

Measured memory_bytes: 19040
#include <stdio.h>

int main() {
	
	int N=0, T=0;
	scanf("%d %d",&N, &T );
	int result=1001;
	int c=0, t=0;
	
	for(int i=0; i<N; i++)
	{
		scanf("%d %d",&c,&t);
		if( t <= T )
		{
			if( result > c )
			{
				result = c;
			}
		}
	}
	
	if ( result != 1001 )
	{
		printf("%d",result);
	}
	else
	{
		printf("TLE");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
ll mod = 1000000007;
int main(){
  ll n; cin >> n;
  vector<vector<ll>> v(n,vector<ll>(3,0));
  rep(i,n){
    cin >> v[i][0] >> v[i][1] >> v[i][2];
  }
  rep(x,101)rep(y,101){
    set<ll> s;
    vector<ll> yobi(3);
    ll cnt=0;
    for(auto t:v){
      if(t[2]==0) continue;
      cnt++;
      s.insert(abs(t[0]-x)+abs(t[1]-y)+t[2]);
      yobi[0]=t[0];yobi[1]=t[1];yobi[2]=t[2];
    }
    if(cnt==1){
      printf("%lld %lld %lld",yobi[0],yobi[1],yobi[2]);
      return 0;
    }
    if(s.size()==1){
      for(auto t:v){
        if(t[2]==0) continue;
        ll h = abs(t[0]-x)+abs(t[1]-y)+t[2];
        printf("%lld %lld %lld",x,y,h);
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    vector<int>a;
    cin >> n >> m;
    int sum = 0;
    for(int i = 0; i < n; i++){
        int p;
        cin >> p;
        a.push_back(p);
        sum = sum + p;
    }
    sort(a.begin(), a.end());
    if(a[n-m] < ((sum+0.0)/(4*m))) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans_list = [0] * n
for i in range(n):
    ans_list[a[i] - 1] = (i + 1)
ans = ""
for i in range(n):
    ans += str(ans_list[i])
    ans += " "
print(ans)

Measured memory_bytes: 20640
/*******************************************c#
* 20.04.16 AtCoder Beginner Contest 159. C - Maximum Volume
*
*
*********************************************/
/*********************************************

::test input::

*********************************************/
using System; //Console, IComparable
using System.IO; //StreamWriter 
using System.Linq; //Select(), Where(), OrderBy(), Count()
using System.Collections.Generic; //List<T>
using System.Reflection; //PropertyInfo[], GetProperties[]
using static System.Console; using static IOmacro.CInput;

namespace tempName {
    public class CRun{
        private static class gv{
            public static int N;
            public static int[] A;
            
            public static int[] pin;
            public static int[] pout;
            public static List<int>[] gph;
            
            public static int[] cnt;
        }
    
        public void build(){            
            gv.N = _int;
            gv.A = _inta;
        }
        
        int order = 0;
        public void dfs(int p) {
            gv.pin[p] = ++order;
            foreach (var x in gv.gph[p]) dfs(x);
            gv.pout[p] = order;
            WriteLine($"{p}, {gv.pin[p]}, {gv.pout[p]}");
        }
        
        public void solve(){
            
            /*
            gv.pin = new int[gv.N +2]; Array.Clear(gv.pin, 0, gv.pin.Length);
            gv.pout = new int[gv.N +2]; Array.Clear(gv.pout, 0, gv.pout.Length);
            gv.gph = new List<int>[gv.N +5];
            for (int i=0; i<gv.gph.Length; i++) gv.gph[i] = new List<int>();
            
            for (int i=0; i<gv.A.Length; i++) {
                gv.gph[gv.A[i]].Add(i+2);
            }
            
            dfs(1);
            */
            
            gv.cnt = new int[gv.N+2];
            
            foreach (var x in gv.A) {
                gv.cnt[x]++;
            }
            
            for (int i=1; i<=gv.N; i++) {
                WriteLine(gv.cnt[i]);
            }
        }
    }

    class Program { 
        static void Main() { 
            var run = new CRun();
            run.build();
            run.solve();
        } 
    }
}

namespace IOmacro {
    public static class CInput {
        public static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput());
        public static string _string{get{return Console.ReadLine();}}
        public static string[] _stringa{get{return (Console.ReadLine().Split());}}
        public static int _int{get{return int.Parse(Console.ReadLine());}}
        public static int[] _inta{get{return Console.ReadLine().Split().Select(x=>int.Parse(x)).ToArray();}}
        public static long _long{get{return long.Parse(Console.ReadLine());}}
        public static long[] _longa{get{return Console.ReadLine().Split().Select(x=>long.Parse(x)).ToArray();}}    
    }
}


Measured memory_bytes: 43724
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		float T, X, ans;
		
		T = scanner.nextInt();
		X = scanner.nextInt();
		
		ans = T/X;
		
		System.out.print(ans);
	}
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
struct edge{long long to,cost;};
typedef pair<int,int>P;
#define inf 1000000007
string alph("abcdefghijklmnopqrstuvwxyz");
vector<int> es[114514];
 P fi[1145140];
signed main(){
    int h,w,n;cin>>h>>w>>n;
    int d=0;
    rep(i,0,n){
        int a,b;cin>>a>>b;
        rep(i,0,3){
            rep(j,0,3){
                if(a>i&&b>j&&a-i<=h-2&&b-j<=w-2)fi[d].first=a-i,fi[d++].second=b-j;
            }
        }
    }
    sort(fi,fi+d);
    int ans[10]={};
    int key=1;
    rep(i,0,d-1){
        if(fi[i].first==fi[i+1].first&&fi[i].second==fi[i+1].second)key++;
        else if(i!=d-1){
            ans[key]++;
            key=1;
        }else key=1;
    }
    if(n)ans[key]++;
    int bans=0;
    rep(i,1,10){
        bans+=ans[i];
    }
    cout<<(h-2)*(w-2)-bans<<endl;
    rep(i,1,10)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 18816
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer a = Integer.parseInt(scan.next());
        Integer b = Integer.parseInt(scan.next());

        int c = (a+b)/2;
        if(Math.abs(a-c)==Math.abs(b-c))
            System.out.println(c);
        else
            System.out.println("IMPOSSIBLE");
    }
}

Measured memory_bytes: 23892
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
int n, m;
pair<int, int> x[10000];
int a, b, c, d, e, f, g, h, sum, l, r, mi;
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &x[i].first, &x[i].second);
	}
	sort(x, x + n);
	for (int i = 0; i < m; i++) {
		scanf("%d %d %d %d", &a, &b, &c, &d);
		sum = 0;
		l = 0; r = n; mi = n / 2;
		for (int j = 0; j < 30; j++) {
			mi = (l + r) / 2;
			if (x[mi].first < a) {
				l = mi;
			}
			if (x[mi].first > a) {
				r = mi;
			}
		}
		e = mi;
		l = 0; r = n;
		for (int j = 0; j < 30; j++) {
			mi = (l + r) / 2;
			if (x[mi].first < c) {
				l = mi;
			}
			if (x[mi].first > c) {
				r = mi;
			}
		}
		f = mi;
		g = max(0, e - 5);
		h = min(n - 1, f + 5);
		for (int j = g; j <= h; j++) {
			if (a <= x[j].first) {
				if (x[j].first <= c) {
					if (b <= x[j].second) {
						if (x[j].second <= d) {
							sum++;
						}
					}
				}
			}

		}
		printf("%d\n", sum);
	}
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
struct elem
{
	int i,val;
	string c;
};
bool compare(elem a,elem b){
	if(a.c == b.c)
		return a.val > b.val;
	return a.c < b.c;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,x;
	string s;
	cin >> n;
	vector<elem> a(n);
	for(int i=0; i < n; i++){
		cin >> s >> x;
		elem aux;
		aux.i =i+1;
		aux.val=x;
		aux.c=s;
		a[i] = aux;
	}
	sort(a.begin(), a.end(),compare);
	for(int i=0; i < a.size(); i++){
		cout << a[i].i << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
//#define MOD (ll)(998244353)
#define MOD (ll)(1e9+7)
#define INF (1e15)
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
#ifdef LOCAL_TEST
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\input.in","r",stdin);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\output.out","w",stdout);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	//code...
	string s; cin>>s;
	set<char> st;
	for(auto &i:s){
		if(st.count(i)){
			cout<<"no\n";
			return 0;
		}
		st.insert(i);
	}
	cout<<"yes\n";
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader; 
import java.io.*;
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
import java.math.*;
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader()
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next()
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine();
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
   public static void main(String args[])
    {
        FastReader sc=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);
        int t=1;//sc.nextInt();
        while(t-->0)
        {
           int n=sc.nextInt();long a[]=new long[n];
           for(int i=0;i<n;i++) a[i]=sc.nextLong();
           Arrays.sort(a);int c=0;
           for(int i=0;i<n;i++)
           {
               for(int j=i+1;j<n;j++)
               {
                   if(a[j]!=a[i])
                   {
                   for(int k=j+1;k<n;k++)
                   {
                    if(a[k]!=a[j] && a[i]+a[j]>a[k]) c++; 
                   }
               }
           }
           }
           pw.println(c);
        }
           pw.close();
    }
}
  

Measured memory_bytes: 34000
# ABC 147 D

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

bits=[0]*71
for a in A:
    j=0
    while a>>j:
        if (a>>j)&1:
            bits[j]+=1
        j+=1

t=0
n=70
while n>=0:
    if bits[n]!=0:
        break
    n-=1

for a in A:
    j=0
    while j<=n:
        if (a>>j)&1:
            res+=((2**j)*(N-bits[j]))%p
        else:
            res+=((2**j)*bits[j])%p
        j+=1
    t=res
print((res*500000004)%p)

Measured memory_bytes: 124752
TB = [63, 6, 91, 79, 102, 109, 125, 39, 127, 111]

def to_radix(k, v)
  def rec(k, v)
    return [] if v == 0
    [v % k] + rec(k, v / k)
  end
  rec(k, v).reverse
end

def solve(from, to)
  val = (from == -1 ? TB[to] : (TB[from] ^ TB[to])) + 128
  to_radix(2, val).map(&:to_s)[1..-1].join
end

loop do
  from = -1
  n = gets.to_i
  break if n == -1
  n.times do
    to = gets.to_i
    puts solve(from, to)
    from = to
  end  
end

Measured memory_bytes: 8764
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    vector<int>s(n+1);
    rep(i,n) s[i+1] = a[i]+s[i];
    
    vector<int>ans;
    rep(i,n+1) rep(j,i) {
        int tmp = s[i] - s[j];
        ans.push_back(tmp);
    }
    for(int i = 1;i<=n;i++) {
        rep(j,n) {
            int tmp = s[i]-a[j];
            ans.push_back(tmp);
        }
    }
    sort(ans.rbegin(),ans.rend());
    
    int score = 0;
    rep(i,ans.size()) {
        if(ans[i]%10 != 0) {
            score = ans[i];
            break;
        }
    }
    cout << score << endl;

}

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

int main(){
  long A,B,K;
  cin >> A >> B >> K;
  for(int i=0 ; i<K ; i++){
    if(i%2==0){
      if(A%2==1)
        A--;
      A/=2;
      B+=A;
    }
    else{
      if(B%2==1)
        B--;
      B/=2;
      A+=B;
    }
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
wk = []
for i in range(6):
  wk.append(int(input()))

aryCapa = wk[1:6]
wkTime = int(wk[0] / min(aryCapa)) + 4
if wk[0] % min(aryCapa) == 0:
  pass
else:
  wkTime += 1

print(wkTime)

Measured memory_bytes: 2940
from functools import reduce 
import math
import itertools

def gcd(numbers):
    return reduce(lambda x,y: math.gcd(x,y),numbers)

def comb(K):
    return itertools.combinations_with_replacement(range(1,K+1),3)

def main():
    k = int(input())
    if k == 1:
        print(1)
        return
    elif k == 2:
        print(9)
        return

    final = 0
    comb_list = list(comb(k))

    for i in comb_list:
        if len(set(i)) == 1:
            final += 1*gcd(i)
        elif len(set(i)) == 2:
            final += 3*gcd(i)
        else:
            final += math.factorial(3)*gcd(i)

    #print(comb_list)
    print(final)
main()


Measured memory_bytes: 105892
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int r, c;
		
		r = sc.nextInt();
		c = sc.nextInt();
		while (r + c != 0) {
			if (r % 2 == 1 && c % 2 == 1) {
				System.out.println("no");
			} else {
				System.out.println("yes");
			}
			r = sc.nextInt();
			c = sc.nextInt();
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int dp[(1 << 12)][1010];
int a[1005], b[1005];
vector<vector<int>> c(1005);
int main()
{
    int N, M; cin >> N >> M;

    int cc;
    rep(i,M)
    {
        cin >> a[i] >> b[i];
        rep(j, b[i])
        {
            cin >> cc;
            c[i].push_back(cc - 1);
        }
    } 
    
    for (int i = 0; i < (1 << 12); i++)
    {
        for (int j = 0; j <= M; j++) dp[i][j] = 500000000;
    }
    dp[0][0] = 0;
    
    int S;
    for (int i = 0; i < (1 << N); i++)
    {
        for (int j = 0; j < M; j++)
        {
            S = 0;
            for (auto x: c[j]) S |= (1 << x);
            
            dp[(i | S)][j + 1] = min(dp[i][j] + a[j], dp[(i | S)][j + 1]);
            dp[i][j + 1] = min(dp[i][j], dp[i][j + 1]);
        }
    }

    if (dp[(1 << N) - 1][M] == 500000000) cout << -1 << endl;
    else cout << dp[(1 << N) - 1][M] << endl;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
const ll inf=10000000000;
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k,i,j;
    cin>>n;
    ll arr[n+5];
    for(i=0;i<n;i++)
        cin>>arr[i];
    k=2;
    vector <ll> dp(n+5,inf);
    
    // for(i=0;i<n;i++)
    //     cout<<dp[i]<<" ";
    ll zero=0;
    dp[0]=0;
    for(i=1;i<n;i++)
    {
        for(j=i-1;j>=max(zero,i-k);j--)
        {
            dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
        }
    }
    cout<<dp[n-1];
    return 0;
}
    

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	char a[3],b[3];
	gets(a);
	gets(b);
	int len=3;
	char ch=a[2];
	a[2]=a[0];
	a[0]=ch;
	for(int i=0;i<3;i++)
	{
		if(a[i]!=b[i])
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

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

using namespace std;

int main() {
    string s;
    cin>>s;
    int len = s.length();
    vector<char> m;
    for(int i = 0; i < len; i++) {
        if(s[i] == '0' || s[i] == '1') {
            m.push_back(s[i]);
        } else {
            if(m.size() > 0)
                m.pop_back();
        }
    }
    for(auto itr = m.begin(); itr!= m.end(); itr++) {
        cout<<*itr;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

string s;
string win[2] = {"First", "Second"};
VI dis;

int main(void) {
    cin >> s;
    cout << win[s.length() % 2 == 0  ^ s.front() == s.back()] << endl;
}


Measured memory_bytes: 512
'use strict';

function Main(input) {
    let tmp = input.trim().split('\n');
    const XN = tmp[0].split(' ');
    const X = Number(XN[0]);
    const N = Number(XN[1]);
    // console.log(X, N)

    // N === 0 の場合
    if (N === 0) {
        console.log(String(X));
        return;
    }

    let P = tmp[1].split(' ').map(v => Number(v)).sort((a, b) => a - b);

    
    // Xが配列に含まれない場合
    if (!P.includes(X)) {
        console.log(String(X));
        return;
    }

    const xIndex = P.indexOf(X);
    if (xIndex === 0) {
        console.log(String(X - 1));
        return;
    }

    // 小さい方
    let min = X - 1;
    while (1) {
        if (!P.includes(min)) {
            break;
        }
        min--;
    }
    // 大きい方
    let max = X + 1;
    while(1) {
        if (!P.includes(max)) {
            break;
        }
        max++;
    }
    
    if (max - X >= X - min) {
        console.log(String(min))
    } else {
        console.log(String(max))
    }
    return;

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

// Main(`6 5
// 4 7 10 6 5`);
// Main(`10 5
// 4 7 10 6 5`);
// Main(`100 0
// `);


Measured memory_bytes: 29476
#include <bits/stdc++.h>
using namespace std;
int n;
int a[10000];int b[10000];
int c[10000];
int ans;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
		ans+=b[i];
	}
	for(int i=1;i<=n-1;i++){
		cin>>c[i];
	}
	for(int i=1;i<=n-1;i++){
		if(a[i]+1==a[i+1]){
			ans+=c[a[i]];
		}
	}
	cout<<ans;
    return 0;
    
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

using T = tuple<int32, int32, int32>;

vector<T> G;
int64 N=20, M;
int64 idx;

void answer(){
	cout << N << " " << G.size() << endl;
	REP(i, G.size()){
		int32 a, b, c;
		tie(a, b, c) = G[i];
		cout << a+1 << " " << b+1 << " " << c << endl;
	}
}

void init(int64 X){
	REP(i, N-1){
		G.push_back(T(i, i+1, 0));
	}
	int64 a = 0;
	idx = 0;
	while((1<<a)-1 <= X-1){
		a++;
	}
	a--;
	while(1<<idx <= X){
		idx++;
	}
	idx--;

	REP(i, a){
		G.push_back(T(i, i+1, 1<<i));
	}
	if((1 << a)-1 == X){
		answer();
		exit(0);
	}
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 L;
	cin >> L;
	init(L);

	while(idx >= 0){
		if(L >> idx & 1){
			int32 k = idx-1;
			while(k >= 0 && !(L >> k & 1)){k--;}
			if(k >= 0){
				G.push_back(T(k, N-1, L & ~((1<<(k+1))-1)));
				cerr << (L & ~((1 << (k+1))-1)) << endl;
			}
		}
		idx--;
	}

	answer();
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,d,e,k,max,min,x;
	cin >> a >> b >> c >> d >> e >> k;
	if(a>b){max = a;}else{max = b;}
	if(max<c){max = c;}
	if(max<d){max = d;}
	if(max<e){max = e;}
	
	if(a<b){min = a;}else{min = b;}
	if(min>c){min = c;}
	if(min>d){min = d;}
	if(min>e){min = e;}
	
	x = max - min;
	if(x<=k){cout << "Yay!";}else{cout << ":(";}
	return 0;
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(it,st,en) for(int it=(st);it<(int)(en);++it)
#define all(c) (c).begin(), (c).end()
#define debug(x) cerr << #x << " = " << x << endl
#define eb emplace_back
#define X first
#define Y second
typedef long long int ll; 
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int h,w,n;
  cin>>w>>h>>n;
  int ans = w;
  vector<pii> p(n);
  set<pii> blocked;
  rep(i,0,n) {
    cin>>p[i].X>>p[i].Y;
    blocked.insert(p[i]);
  }
  vi reach(w+1);
  reach[1] = 1;
  rep(i,2,w+1) {
    reach[i] = reach[i-1]+1;
    if(blocked.count({i, reach[i]})) --reach[i];
  }
  for(auto q:p) {
    if(reach[q.X] >= q.Y) {
      ans = min(ans, q.X-1);
    }
  }
  cout << ans << endl;
  return 0;
}
/*
 * T must ++x, otherwise A will pass to and end the game.
 * A has two choices:
 *  pass: y += 0
 *  move: ++y
 *
 * Wich block can we reach?
 *
 *  1234 x
 * 1....
 * 2 .X.
 * 3  ..
 * 4   .
 *
 * ...
 * ..X
 * ...
 *
 *
 *
 *
 */


Measured memory_bytes: 12032
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define G() Cr=getchar()
int Xr;char Cr;
inline int  rd(){
	Xr=0;G();
	while(Cr<'0'||Cr>'9')G();
	while(Cr>='0'&&Cr<='9')Xr=(Xr<<1)+(Xr<<3)+Cr-'0',G();
	return Xr;
}

int n;
int pos[250005];
struct node{
	int num,p;
}e[5005];

bool comp(node x,node y){
	return x.p<y.p;
}
int main(){
	n=rd();
	for(int i=1;i<=n;i++)
		e[i].num=i,e[i].p=rd(),pos[e[i].p]=i;
		
	sort(e+1,e+1+n,comp);	
		
	int l=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<e[i].num;j++){
			while(pos[l])l++;
			if(l>=e[i].p){
				puts("No");
				return 0;
			}
			pos[l++]=e[i].num;
		}	
	}
	
	int r=n*n;
	for(int i=n;i>=1;i--){
		for(int j=n;j>e[i].num;j--){
			while(pos[r])r--;
			if(r<=e[i].p){
				puts("No");
				return 0;
			}
			pos[r--]=e[i].num;
		}
	}
	
	puts("Yes");
	for(int i=1;i<=n*n;i++)printf("%d ",pos[i]);
	puts("");
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define Vi vector<int>
#define Vl vector<long long>
#define pb(a) push_back(a)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<int,ll>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000001;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
ll a[1001],b[1001],c[1001];
ll e[1000001]={};
ll f[3000001]={};

int main() {

	int x,y,z,k;
	cin>>x>>y>>z>>k;
	rep(i,x)cin>>a[i];

	ll s=0;
	rep(j,y){
		cin>>b[j];
		rep(i,x){
			e[j*x+i]=a[i]+b[j];
			s++;
		}
	}
	sort(e,e+s,greater<ll>());
	s=0;
	rep(i,z){
		cin>>c[i];
		rep(j,k){
			f[i*k+j]=e[j]+c[i];
			s++;
		}
	}
	sort(f,f+s,greater<ll>());
	rep(i,k)cout<<f[i]<<endl;

	return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
 
std::vector<long long> A;
long long N, M, result = 0;
 
// check if there are less than M pairs less than {target}
bool check(long long target) {
  long long cnt = 0;
  for (const auto & e : A) {
    long long pos = std::lower_bound(A.begin(), A.end(), target - e) - A.begin();
    cnt += (N - pos);
  }
  return cnt < M;
}
 
int main() {
  std::cin >> N >> M;
  A.resize(N);
  for (auto i=0; i<N; ++i) std::cin >> A[i];
  
  std::sort(A.begin(), A.end());
  
  long long ok = std::numeric_limits<long long>::max();
  long long ng = 0;
  while (std::abs(ok - ng) > 1) {
    long long mid = (ok + ng) / 2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }
  
  std::vector<long long> accsum(N+1, 0);
  
  for (auto i=0; i<N; ++i)  accsum[i+1] = A[i] + accsum[i];
  
  for (const auto & e : A) {
    long long pos = std::lower_bound(A.begin(), A.end(), ok - e) - A.begin();
    long long cnt = N - pos;
    result += cnt * e + (accsum[N] - accsum[pos]);
    M -= cnt;
  }
  result += M * ng;
  std::cout << result << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <stack> 
#include <map>
#include <queue>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;

#define pb 					push_back

template<typename T,typename S>
ostream& operator <<(ostream& os, pair<T, S> input) {
	os<<"("<<input.first<<", "<<input.second<<")";
	return os;
}

template<typename T>
ostream& operator <<(ostream& os, vector<T> input) {
	for(auto t: input)
		os << t <<" ";

	return os;
}

long long n, m;

long long MOD = 1e9 + 7;


long long powMod(long long a, long long b) {
	if(b==0)
		return 1;
	long long c = powMod(a, b/2);
	c*=c;
	c%=MOD;
	if(b%2==1)
		c*=a;
	return c%MOD;
}

long long inv(long long a){
	return powMod(a, MOD-2);
}

long long ncr(long long n, long long r){
	if(r<0 || r>n)
		return 0;
	if(r==0)
		return 1;
	r = min(r, n-r);
	long long ans = 1;
	for(int i= 1; i<=r;i++){
		ans*=(n-i+ 1);
		ans%=MOD;
		ans*=inv(i);
		ans%=MOD;
	}
	return ans;
}

long long solve(long long x, long long y){
	int sum = x + y;
	if(sum%3!=0)
		return 0;
	int n= sum/3;
	int terms = n +1;
	int firstTermR = n;
	int r= y - firstTermR;
	// cout << n<<" "<<r<<"\n";
	return ncr(n, r);

}
int main() {
    //ios_base::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0);
	cin >> n >> m;
	long long ans = solve(n, m);
	cout << ans<<"\n";



	return 0;
}

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

ll f(ll x)
{
    ll s = 0, u = 2;
    while (2 * x >= u)
    {
        ll t = 0;
        ll p = (ll)((x + 1) / u);
        t += p * u / 2;
        ll q = x - p * u + 1;
        t += max(0LL, q - u / 2);
        if (t % 2)
            s += u / 2;
        u *= 2;
    }
    return s;
}

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

    ll a, b;
    cin >> a >> b;
    a = f(a - 1);
    b = f(b);
    b ^= a;
    cout << b << endl;

    return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
		int a, b;
		cin>>a>>b;
		cout<<a*b<<endl;
	
	return 0;
}

Measured memory_bytes: 3648
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
//const int mod=998244353 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	int n,m,mod,i,j,k;cin>>n>>mod;//m の意味が違う
	static int dp[5005][5005]={};//最大ー最小,和
	m=(n-1)/2;
	dp[0][0]=1;
	if(n%2==0){
		for(j=0;j<n;j++){
			for(k=j*m;k<=n;k++){
				if(dp[j][k]==0){continue;}
				if(k+m>=n){continue;}
				dp[j+1][k+m]+=dp[j][k];
				dp[j+1][k+m]%=mod;
			}
		}
	}
	
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			if(n<(j+1)*(m-i)){break;}
			for(k=j*(m-i);k+(m-i)<=n;k++){
				if(dp[j][k]==0){continue;}
				dp[j+1][k+(m-i)]+=dp[j][k];
				dp[j+1][k+(m-i)]%=mod;
			}
		}
		
		for(j=0;j<n;j++){
			if(n<(j+1)*(m-i-1)){break;}
			for(k=j*(m-i-1);k+(m-i-1)<=n;k++){
				if(dp[j][k]==0){continue;}
				dp[j+1][k+(m-i-1)]+=dp[j][k];
				dp[j+1][k+(m-i-1)]%=mod;
			}
		}
	}
	llint ans=0;
	for(j=0;j<n;j++){
		for(k=0;j+k<n;k++){
			ans+=max(0,n-j-k)*((llint)dp[j][k]);
			ans%=mod;
		}
		
	}
	cout<<ans<<endl;
}




Measured memory_bytes: 98048
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	string s;
	cin >> s;
	for (auto i : s)if (i == '2')N++;
	cout << N << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include <iostream>
using namespace std;
long long C;
int A[200001];
int main() {
    int N,K; cin >> N >> K;
	//scanf("%d%d",&N,&K);
	for(int i=0;++i<=N;) scanf("%d",A+i);
	sort(A+1,A+N+1);
	for(int i=1;i<=N-K;++i)C+=A[i];
	//printf("%lld\n",C);
    cout << C << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
using namespace std;

#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) {
    for(T &a : v) is >> a; return is;
}

bool solve() {
    int n; cin >> n;
    if(n == 0) return 0;
    vector<string> s(n); cin >> s;

    rep(i, n) {
        vector<int> haiku = {5, 7, 5, 7, 7};
        reverse(all(haiku));
        repeat(j, i, n) {
            haiku.back() -= s[j].size();
            if(haiku.back() < 0) break;
            else if(haiku.back() == 0) {
                haiku.pop_back();
                if(haiku.size() == 0) {
                    cout << i + 1 << endl;
                    return 1;
                }
            }
        }
    }
    assert(0);
    return 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SONI ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int maxn=5e5+15;
const int maxm=5000+15;
const int mod=1e9+9;
const int inf=0x3f3f3f3f;
const int MOD=1000000007;

int main()
{
    SONI;
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    int dp[n];
    for(int i=0;i<n;i++)
    dp[i]=inf;
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=(i+2);j++)
        {
            if(j<n)
            dp[j]=min(dp[j],dp[i]+abs(arr[j]-arr[i]));
        }
    }
    cout<<dp[n-1];
    return 0; 
}

Measured memory_bytes: 1024