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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


int main(){
  int n;
  cin >> n;
  vector<int> a(n, 0);
  rep(i, n) {
    cin >> a[i];
  }
  bool flag = true;
  int swapCount = 0;
  while (flag) {
    flag = false;
    for(int j = n-1; j >= 1; --j) {
      if (a[j] < a[j-1]) {
        swap(a[j], a[j-1]);
        ++swapCount;
        flag = true;
      }
    }
  }
  rep(i,n) {
    if (i > 0) cout << " ";
    cout << a[i];
  }
  cout << endl << swapCount << endl;
  return 0;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000

int main(){

	string S,T;
	cin>>S>>T;
	
	int A,B;
	cin>>A>>B;
	
	string U;
	cin>>U;
	
	if(S==U)A--;
	else B--;
	
	cout<<A<<' '<<B<<endl;
	
	return 0;
}

Measured memory_bytes: 256
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]


sort_ab = sorted(ab, key=lambda x:(x[1], x[0]))
#print(sort_ab)
count=0
for i in range(n):
    count+=sort_ab[i][0]
    if sort_ab[i][1]<count:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 67808
#include <stdio.h>
#include <math.h>
#include <algorithm>
 
using namespace std;
 
 
int main(){
 
    int n,d,array[1005],count;
 
    while(scanf("%d %d",&n,&d)!=EOF){
 
        array[0] = 2;
        array[1] = 3;
 
        for(int i=2; i < n; i++){
            array[i] = (array[i-1] + array[i-2])%1001;
        }
 
        std::sort(array,array+n);
 
        count = 1;
 
        for(int i=1; i < n; i++){
            if(abs(array[i]-array[i-1]) >= d)count++;
        }
        printf("%d\n",count);
 
    }
 
    return 0;
}


Measured memory_bytes: 2576
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
constexpr uint64_t L1 = 1ull;
constexpr ull bit(int n){ return 1ull << n;}

constexpr ll INF       = 1000000000;/* 1e+9a */

void solve(istream& cin) {
    ll N ;
    while(cin >> N ){
        array<int, 9> cl{};
        for (int i = 0; i < N; ++i) {
            int a;
            cin >> a;
            int band = a / 400;
            if(band > 7) band = 8;
            cl[band]++;
        }
        int mini, maxi; mini = maxi = 0;
        for (int i = 0; i < cl.size()-1; ++i) {
            if(cl[i]) mini++, maxi++;
        }
       mini = max(mini, 1);
        maxi += cl[8];
        cout << mini << ' '<< maxi << endl;
    }
}

int main(int argc, char *argv[]) {
    string FileName("C"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    if(sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size()-ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        solve(cin);
    }
    else {    
	    cerr << sub << endl;
        string inFile = "sample.txt";
        auto fs = fstream(inFile, fstream::in);
        solve(fs);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 400100;
const ll INF = 1e15;
const ll MOD =  998244353;
ll N,M,W,a,b,c,d,e,K;
ll A[MAXN];

vpi V;
string S;
string cur;
priority_queue<pi>pq;

void fail(){
    cout<<"No";
    exit(0);
}

int main(){
    cin>>N;
    for(int i=0;i<N;++i){
        cin>>S;
        cur="";
        for(auto i:S){
            if(SZ(cur)&&cur.back()=='('&&i==')'){
                cur.pop_back();
                continue;
            }
            cur+=i;
        }
        if(SZ(cur)==0)continue;
        a=b=0;
        for(auto i:cur){
            if(i=='(')++a;
            else ++b;
        }
        int req=b;
        V.pb(req,a-b);
    }
    N=SZ(V);
    sort(ALL(V));reverse(ALL(V));
    int x=0;
    int cur=0;
    while(x<N){
        while(SZ(V)&&V.back().f<=cur){
            pi t=V.back();V.pop_back();
            pq.emplace(t.f+t.s,t.s);
        }
        if(!SZ(pq))fail();
        pi t=pq.top();pq.pop();
        int req=t.f-t.s;
        int dif=t.s;
        if(req>cur)fail();
        cur+=dif;
        ++x;
    }
    if(cur!=0)fail();
    cout<<"Yes";
}

Measured memory_bytes: 43392
#include <stdio.h>

int main(void)
{
	int l1, l2, l3;
	int i;
	int count1, count2;
	int n;
	
	count1 = count2 = 0;
	
	while (scanf("%d,%d,%d", &l1, &l2, &l3) != EOF){
		if (l1 == l2){
			count2++;
		}
		
		if (l3 * l3 == l1 * l1 + l2 * l2){
			count1++;
		}
	}
	
	printf("%d\n%d\n", count1, count2);
	
	return (0);
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N, W := sc.nextInt(), sc.nextInt()
	weight := make([]int, N)
	value := make([]int, N)
	for i := 0; i < N; i++ {
		weight[i] = sc.nextInt()
		value[i] = sc.nextInt()
	}
	// dp := make([][]int, N+1)
	// for i, _ := range dp {
	// 	dp[i] = make([]int, W+1)
	// }
	var dp [101][100001]int
	for i := 0; i < N; i++ {
		for w := 0; w <= W; w++ {
			if w >= weight[i] {
				dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
			} else {
				dp[i+1][w] = dp[i][w]
			}
		}
	}
	fmt.Println(dp[N][W])
}


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

using namespace std;

/*const int mod = ;

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

int power (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

int fac[2000009], inv[2000009];
void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = power (fac[lim], mod - 2);for (int i=lim - 1; i>=0; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){if (K > N || N < 0 || K < 0) return 0; int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}*/

long long cost (long long x, long long y)
{
    return (y - x) / 2;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

long long N, A, B;
scanf ("%lld %lld %lld", &N, &A, &B);
if (A % 2 == B % 2) printf ("%lld\n", cost (A, B));
else
{
    long long c1, c2;
    ///after A rounds, the first one is at 1 whereas the second one is at B - A
    c1 = A + cost (1, B - A);
    c2 = N - B + 1 + cost (A + (N - B + 1), N);
    printf ("%lld\n", min (c1, c2));
}
return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int a,b,c,x;
	x=0;
	scanf("%d",&a);
	c=a/100;
	a%=100;
	b=a/10;
	a%=10;
	if(a==7) x++;
	if(b==7) x++;
	if(c==7) x++;
	if(0<x) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 1660
a,b=map(int, input().split())
s=[input().split() for i in range(a)]
al='abcdefghijklmnopqrstuvwxyz'
for j,i in enumerate(s):
    if 'snuke' in i:
        print(al[i.index('snuke')].upper()+str(j+1))
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int n,a[N],L[N],R[N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	a[0]=a[n+1]=0;
	for (int i=1;i<=n;i++)
		L[i]=L[i-1]+abs(a[i]-a[i-1]);
	for (int i=n;i>=1;i--)
		R[i]=R[i+1]+abs(a[i]-a[i+1]);
	for (int i=1;i<=n;i++)
		printf("%d\n",L[i-1]+R[i+1]+abs(a[i+1]-a[i-1]));
	return 0;
}

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

long long int gcd(long long int a, long long int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main()
{
  int N;
  cin >> N;
  vector<long long int> a(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a[i];
  }
  long long int ans;
  ans = gcd(a[0], a[1]);
  for (int i = 2; i < N; i++)
  {
    ans = gcd(ans, a[i]);
  }
  cout << ans << endl;
}


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

int sumDigits2(int x, int n){
  int s = 0;
  int x2 = n - x;
  
  while(x>0){
    s += x % 10;
    x /= 10;
  }
  while(x2>0){
    s += x2 % 10;
    x2 /= 10;
  }

  return s;
}

int main(){
  int N; cin >> N;
  
  int ans = 100;

  for (int i=1; i<=N/2; i++){
    ans = min(ans, sumDigits2(i, N));
  }

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

Measured memory_bytes: 256
package main
import "fmt"
import "sort"

func main(){

        var N int
        fmt.Scan( &N )
	var l []int
        for i := 0; i < N; i ++ {
                var v int;
                fmt.Scan( &v )
		l = append( l, v )
        }
        sort.Ints( l )

        ret := float32( l[ 0 ] )
        for i := 1; i < len( l ); i ++{
                ret = float32(ret + float32(l[ i ]))/2.0
        }
        fmt.Println( ret )
}

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

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<ll> p(N);
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
  }
  vector<ll> q=p;
  sort(q.begin(),q.end());
  ll cnt=0;
  for (int i = 0; i < N; ++i) {
    if(p[i]!=q[i])
      cnt++;
  }
  if(cnt==2 || cnt==0)
    cout << "YES";
  else
    cout << "NO";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 999721/* your task*/
#define NIL '\0'
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}


int h1(int key){ return key%M; }
int h2(int key){ return key%(M-1); }


//search
int find(char str[]){


  int i;
  i=0;
  long long j;
  int key;

  key=getKey(str);


  //repeat j<-h(k,i)
  while(1){
    j=(h1(key)+i*h2(key))%M;
    if(strcmp(str,H[j])==0) return j;
    i++;
    if(H[j][0]==NIL || i==M) return NIL;
  }
 

}

//insert
int insert(char str[]){

  int i;
  long long j;
  i=0;
  int key;
  key=getKey(str);
  //repeatj <-h(k,i)
  while(1){
    j=(h1(key)+i*h2(key))%M;
    if(H[j][0]==NIL){
      strcpy(H[j],str);
      return j;
    }
    else i++;
    if(i==M) break;
  }

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 13000
//想的时间太长了，打表不能一下找到规律的话，还是手推吧，不要浪费时间 
//用long long！！ 
#include <cstdio>
#include <cstring>
long long k, ans, x, y, n, m;

int main(){
	//freopen("atcoderarc091b.out", "w", stdout);
	scanf("%lld%lld", &n, &k);
	if (k == 0){
		printf("%lld", n * n);
		return 0;
	}
	ans = 0;
	ans += (n - k) * (n - k + 1) / 2;
	//printf("%d\n", ans);
	for (int i=k+1; i<=n-1; i++){
		x = n / i;
		y = n % i;
		ans += (x - 1) * (i - k);
		if (y >= k) ans += y - k + 1;
	} 
	printf("%lld", ans);
	
	//以下为打表找规律（其实最后也没找到，还是手推的） 
	/*n = 100;
	for (int i=1; i<=n; i++){
		for (int j=0; j<=i-1; j++){
			ans = 0;
			for (int a=1; a<=i; a++){
				for (int b=1; b<=i; b++) 
					if (a % b >= j) ans++;
			}
			printf("%d %d %d\n", i, j, ans); 
			//ans = 0;
		}
	}*/
	
	return 0;
} 

Measured memory_bytes: 128
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
a1 = [0] * N
a2 = [0] * N

temp = 0
for i in range(N):
    temp += A1[i]
    a1[i] = temp

temp = 0
for i in reversed(range(N)):
    temp += A2[i]
    a2[i] = temp

ans = [0] * N
for i in range(N):
    ans[i] = a1[i] + a2[i]

print(max(ans))

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


int main() {

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

    sort(a, a+n);

    int value = a[0], ans = 1;

    for (int i = 1; i < n; i++) {
        if (value != a[i])
            ans++;
        value = a[i];
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){
    int n;
    vector<int> v;
    double ave;
    int result;
    while(cin>>n,n){
        v.resize(n);
        result = 0;
        ave = 0;
        REP(i,n){
            scanf("%d", &v[i]);
            ave += v[i];
        }

        ave /= n;
        REP(i,n){
            if(v[i]<=ave+0.0001){
                result++;
            }
        }

        cout << result << endl;
        
    }

    return 0;
}



Measured memory_bytes: 3252
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef tuple<int, int, int, int> t4;
typedef pair<ll, ll> PL;
typedef long double ldouble;

int A[100010];
int color[1400070];
int ca[100010];
int p[1400070];
int Find(int x){return p[x] == x ? x : p[x] = Find(p[x]); }

void solve(){
	ll n;int m, q; cin >> n >> m >>q;
	for(int i=1;i<=q;i++)scanf("%d", A+i), ca[A[i]] = 1;
	int t = (m % 7 == 0 ? m / 7 : m);
	rep(i, 7*t)p[i] = i;
	rep(i, t)rep(j, 7){
		int v = i * 7 + j;
		if(ca[v % m])color[v] = 1;
		if(i && color[v] == 0 && color[v-7] == 0)p[Find(v)] = Find(v-7);
		if(j && color[v] == 0 && color[v-1] == 0)p[Find(v)] = Find(v-1);
	}
	ll ans = 0;
	rep(i, 7*t)if(color[i] == 0 && p[i] == i)ans++;
	if(t == n){
		printf("%lld\n", ans);
		return;
	}
	ll ans2 = 0;
	t = t * 2;
	rep(i, 7*t)p[i] = i;
	rep(i, t)rep(j, 7){
		int v = i * 7 + j;
		if(ca[v % m])color[v] = 1;
		if(i && color[v] == 0 && color[v-7] == 0)p[Find(v)] = Find(v-7);
		if(j && color[v] == 0 && color[v-1] == 0)p[Find(v)] = Find(v-1);
	}
	rep(i, 7*t)if(color[i] == 0 && p[i] == i)ans2++;
	ans2 -= ans;
	printf("%lld\n", ans + ans2 * (n / (t / 2) - 1));
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		//printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}

Measured memory_bytes: 11648
n,d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        dis = 0
        for k in range(d):
            dis += (x[i][k]-x[j][k])**2
        dis_r = int(dis**0.5)
        if dis == dis_r**2:
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_set>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<climits>
using namespace std;

int main() {
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    vector<vector<int>> dp(n, vector<int> (3,0));
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(int i=1;i<n;i++) {
        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}


Measured memory_bytes: 9852
import math

inputLine = input()
tempStr = inputLine.split(' ')

a = int(tempStr[0])
b = int(tempStr[1])
h = int(tempStr[2])
m = int(tempStr[3])

minDeg = 360 * (m / 60)
hourDeg = h * 30 + (30 * (m / 60))

finalValue = hourDeg - minDeg if hourDeg >= minDeg else minDeg - hourDeg
finalValue = 360 - finalValue if finalValue >= 180 else finalValue

if finalValue == 90 :
	print(math.sqrt((a * a) + (b * b)))
elif finalValue == 0 or finalValue == 180 :
	if b >= a :
		print(b - a if finalValue == 0 else b + a)
	else :
		print(a - b if finalValue == 0 else a + b)
else :
	print(math.sqrt((a * a) + (b * b) - (2 * a * b * math.cos(math.pi * (finalValue / 180)))))



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

int main()
{
    long long N, M, A=0, a;
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> a;
        A += a;
    }
    
    if (A > N)
        cout << "-1" << endl;
    else
        cout << N - A << endl;

}

Measured memory_bytes: 3636
#include<cstdio>
using namespace std;
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    if(n*(n-1)/2-(n-1)<k){
        printf("-1\n");
    }
    else{
        printf("%d\n",n*(n-1)/2-k);
        for(int i=1;i<n;i++){
            for(int j=i+1;j<=n;j++){
                if(i==1||!k){
                    printf("%d %d\n",i,j);
                }
                else{
                    k--;
                }
            }
        }
    }
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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

int seica(ll a, ll b){
	ll tmp = a ^ b;
	int ret = 0;
	REP(i, 20){
		if(tmp & (1 << i))ret++;
	}
	return ret;
}

void out(vector<int> v){
	cout << "YES" << endl;
	REP(i, v.size()){
		cout << v[i];
		if(i != v.size() - 1)cout << " ";
	}
	cout << endl;
}

vector<int> dfs(int s, int g, int mask, int n){
	if(n == 1){
		return {s, g};
	}
	
	REP(i, 20){
		if(!(mask & (1<<i)))continue;
		if((s & (1<<i)) == (g & (1<<i)))continue;
		int nmask = mask ^ (1<<i);
		REP(j, 20){
			if(!(nmask & (1<<j)))continue;
			int tmp = (s & nmask) ^ (1<<j);
			auto l = dfs(s & nmask, tmp, nmask, n - 1); 
			auto r = dfs(tmp, g & nmask, nmask, n - 1); 
			vector<int> ret;
			REP(k, l.size())ret.PB(l[k] | (s & (1<<i)));
			REP(k, r.size())ret.PB(r[k] | (g & (1<<i)));
			return ret;
		}
	}	
}

int main(){
	
	ll n, a, b;cin >> n >> a >> b;
		
	if(seica(a, b) % 2 == 0){
		cout << "NO" << endl;
		return 0;
	}
	
	out(dfs(a, b, (1<<n)-1, n));
	
	return 0;
}


Measured memory_bytes: 1628
def BellmanFord(edges,num_v,source):
    #グラフの初期化
    inf=float("inf")
    dist=[inf for i in range(num_v)]
    dist[source-1]=0

    #辺の緩和
    for i in range(num_v):
        for edge in edges:
            if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
                dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
                if i==num_v-1:
                    before_dist = dist[num_v-1]
                    for i in range(num_v):
                        for edge in edges:
                            if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
                                dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
                    if before_dist != dist[num_v-1]:
                        return -1
    return dist

N, M, P = map(int, input().split())
edges = []
for m in range(M):
    A, B, C = map(int, input().split())
    edges.append([A, B, -(C-P)])
dist = BellmanFord(edges, N, 1)
if dist == -1:
    print(-1)
else:
    print(max(-dist[N-1], 0))

Measured memory_bytes: 48664
let a = stdin.ReadLine() |> int
stdin.ReadLine() |> int
stdin.ReadLine() |> int
stdin.ReadLine() |> int
let e = stdin.ReadLine() |> int

stdin.ReadLine()
|> int
|> fun k ->
    if e - a <= k then "Yay!" else ":("
    |> printfn "%s"

Measured memory_bytes: 29652
import numpy as np

n = int(input())

a1 = np.array(list(map(int, input().split())))
a2 = np.array(list(map(int, input().split())))

a1_cumsum = np.cumsum(a1)
a2_cumsum = np.cumsum(a2)

#print(a1)
#print(a1_cumsum)
#print(a2)
#print(a2_cumsum)

ans = 0
for i in range(n) :
    sum = a1_cumsum[i] + a2_cumsum[n-1]
    if i != 0 :
        sum = sum - a2_cumsum[i-1]

    if sum > ans :
        ans = sum

print(ans)

Measured memory_bytes: 12428
#include<stdio.h>
int main (){
  int N,i,x;
  int a[100000];
  scanf("%d",&N);
  for(i=1;i<=N;i++){
    scanf("%d",&x);
    a[x]=i;
   }
  for(i=1;i<=N;i++){
    printf("%d ",a[i]);
   }
   return 0;
 }

Measured memory_bytes: 1152
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <bitset>

using namespace std;

const int N=2005;

bitset<N*N> f;
int n,ans;
int a[N];

int main()
{
	//freopen("will.in","r",stdin),freopen("will.out","w",stdout);
	scanf("%d",&n);
	f[0]=1;
	for (int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]),ans+=a[i];
		f=f|(f<<a[i]);
	}
	ans=ans+1>>1;
	for (;!f[ans];++ans);
	printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using li = unsigned long long int;
using namespace std;

class Point {
  public:
    long long x_, y_;
    Point(long long x, long long y) : x_{x}, y_{y} {}
    long long operator*(Point o) { return abs(x_ - o.x_) + abs(y_ - o.y_); }
};

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

    vector<Point> students;
    rep(i, n) {
        li a, b;
        cin >> a >> b;
        students.push_back(Point(a, b));
    }

    vector<Point> checkpoints;
    rep(i, m) {
        li c, d;
        cin >> c >> d;
        checkpoints.push_back(Point(c, d));
    }

    rep(i, n) {
        li min_dist = 100000001 * 2;
        int coord = 1;
        rep(j, m) {
            li cur_dist = students.at(i) * checkpoints.at(j);
            if (min_dist > cur_dist) {
                min_dist = cur_dist;
                coord = j + 1;
            }
        }
        cout << coord << endl;
    }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
int a,b,c;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>a>>b>>c;
    if(b-a == c-b) cout<<"YES\n";
    else cout<<"NO\n";
}


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

bool Solve(int n) {
  for (; n >= 0; n -= 7) {
    if (n % 4 == 0)
      return true;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  cout << (Solve(n) ? "Yes\n" : "No\n");
  return 0;
}


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

struct Edge{int to,capa,flow,next;} e[10500];
int h[210],sum=-1,s,t;
bool vis[210];
int d[210],cur[210];

void AddEdge(int u,int v,int w)
{
	e[++sum].to=v;
	e[sum].flow=0;
	e[sum].capa=w;
	e[sum].next=h[u];
	h[u]=sum;
}

void add_edge(int u,int v,int w)
{
	AddEdge(u,v,w);
	AddEdge(v,u,0);
}

bool BFS()
{
	memset(vis,0,sizeof(vis));
	queue<int> q;
	q.push(s);
	d[s]=0;vis[s]=1;
	while(!q.empty())
	{
		int u=q.front();
		for(int tmp=h[u];~tmp;tmp=e[tmp].next)
			if(e[tmp].capa>e[tmp].flow&&!vis[e[tmp].to])
			{
				vis[e[tmp].to]=1;
				d[e[tmp].to]=d[u]+1;
				q.push(e[tmp].to);
			}
		q.pop();
	}
	return vis[t];
}

int DFS(int u,int a)
{
	if(u==t||a==0) return a;
	int f,flow=0;
	for(int& tmp=cur[u];~tmp;tmp=e[tmp].next)
		if(d[e[tmp].to]==d[u]+1)
		{
			f=DFS(e[tmp].to,min(a,e[tmp].capa-e[tmp].flow));
			if(f>0)
			{
				flow+=f;a-=f;
				e[tmp].flow+=f;
				e[tmp^1].flow-=f;
				if(a==0) break;
			}
		}
	return flow;
}

int Maxflow()
{
	int flow=0;
	while(BFS())
	{
		for(int i=s;i<=t;i++) cur[i]=h[i];
		flow+=DFS(s,INF);
	}
	return flow;
}

const int N=10000000;
int lft[110],rht[110],num=0;
bool up[N+10];

int Pow(int a,int b,int p)
{
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%p)
		if(b&1) ans=1ll*ans*a%p;
	return ans;
}

bool isprime(int n)
{
	if(n==2) return true;
	if(n<2||!(n&1)) return false;
	int t=0;
	int a,x,y,u=n-1;
	while(!(u&1)) t++,u>>=1;
	for(int i=0;i<10;i++)
	{
		a=rand()%(n-1)+1;
		x=Pow(a,u,n);
		for(int j=0;j<t;j++,x=y)
		{
			y=1ll*x*x%n;
			if(y==1&&x!=1&&x!=n-1) return false;
		}
		if (x!=1) return false;
	}
	return true;
}

int main()
{
	int n,x;
	scanf("%d",&n);
	memset(h,-1,sizeof(h));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		up[x]=1;
	}
	int l=0,r=0;
	for(int i=1;i<=N+1;i++)
		if(up[i]!=up[i-1])
		{
			if(i&1) lft[++l]=i;
			else rht[++r]=i;
		}
	s=0;t=l+r+1;
	for(int i=1;i<=l;i++) add_edge(s,i,1);
	for(int i=1;i<=r;i++) add_edge(l+i,t,1);
	for(int i=1;i<=l;i++)
		for(int j=1;j<=r;j++)
			if(isprime(abs(lft[i]-rht[j])))
				add_edge(i,j+l,1);
	int falun=Maxflow(),dafa=falun;
	if(l>falun) dafa+=(l-falun)/2*2;
	if(r>falun) dafa+=(r-falun)/2*2;
	if((l-falun)&1) dafa+=3;
	printf("%d\n",dafa);
	return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    string s[3];
    rep(i, 3) cin >> s[i];
    rep(i, 3) {
        cout << s[i][i];
    }
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {

  i64 v[101] = {0};

  i64 n, m;
  cin >> n >> m;

  i64 sum = 0;
  rep(i, n) {
    i64 ai;
    cin >> ai;
    v[i] = ai;
    sum += ai;
  }

  i64 ans = 0;
  rep(i, n) {
    if (v[i] >= 1.0 * sum / (4.0 * m)) {
      ans++;
    }
  }

  if (ans >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main(void)
{
	int s,ss,sss;
	while(1){
		scanf("%d",&s);
		if(s==0) break;
		ss=1000-s;
		sss=ss/500;
//		printf("500sss=%d\n",sss);
		ss=ss%500;
		sss+=ss/100;
//				printf("100sss=%d\n",sss);
		ss=ss%100;
		sss+=ss/50;
//				printf("50sss=%d\n",sss);
		ss=ss%50;
		sss+=ss/10;
//				printf("10sss=%d\n",sss);
		ss=ss%10;
		sss+=ss/5;
//				printf("5sss=%d\n",sss);
		ss=ss%5;
		sss+=ss/1;
//				printf("1sss=%d\n",sss);
//		sss++;
	printf("%d\n",sss);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
typedef P<int, int> pii;
int n;
V<int> a, b, sa, sb;
priority_queue<pii> qa, qb;
void Yn(bool z){
  cout << (z ? "Yes" : "No") << endl;
  exit(0);
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  a = V<int>(n);
  FOR(i, 0, n){
    cin >> a[i];
    qa.push(mp(a[i], i));
  }
  b = V<int>(n);
  FOR(i, 0, n){
    cin >> b[i];
    qb.push(mp(b[i], i));
  }
  sa = a;
  sb = b;
  sort(all(sa));
  sort(all(sb));
  FOR(i, 0, n) if(sa[i]>sb[i]) Yn(false);
  FOR(i, 1, n) if(sa[i]<=sb[i-1]) Yn(true);
  FOR(i, 0, n-1){
    pii ta, tb;
    while(true){
      ta = qa.top();
      if(a[ta.se] == ta.fi) break;
      qa.pop();
    }
    qa.pop();
    tb = qb.top();
    qb.pop();
    if(ta.fi<=b[ta.se]) Yn(true);
    qa.push(mp(a[tb.se], ta.se));
    swap(a[ta.se], a[tb.se]);
  }
  Yn(false);
}

Measured memory_bytes: 3444
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

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

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

	ll N, K;
	cin >> N >> K;
	vector<ll>A(N);
	ll g = A[0];
	ll ma = -1;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] == K) {
			puts("POSSIBLE");
			return 0;
		}
		if (i > 0)g = gcd(A[i],g);
		ma = max(A[i], ma);
	}
	sort(all(A));
	if (ma < K) {
		puts("IMPOSSIBLE");
		return 0;
	}

	if (K%g == 0)puts("POSSIBLE");
	else puts("IMPOSSIBLE");


	return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, k; cin >> n >> k;
  vll h(n);
  for(int i=0;i<n;++i) {
    cin >> h[i];
  }

  sort(h.rbegin(), h.rend());
  for(int i=0;i<min(n, k);++i) {
    h[i] = 0;
  }

  ll su = 0;
  for(int i=0;i<n;++i) {
    su += h[i];
  }
  cout << su << endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int x;
  cin >> x;
  if (x == 0) {
    cout << 1;
  } else if (x == 1) {
    cout << 0;
  }
  return 0;
}

Measured memory_bytes: 3524
# tenka1-2017C - 4/N
# exhaustive search
def main():
    N = int(input())
    for h in range(N // 4 + 1, 3501):
        for n in range(N * h // (4 * h - N) + 1, 3501):
            numerator = N * h * n
            denominator = 4 * h * n - N * n - N * h
            if denominator > 0 and numerator % denominator == 0:
                w = numerator // denominator
                print(h, n, w)
                return


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    ll n,m; cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    //s[i]: n番目(index=n-1)までのa[i]の累積和
    vector<ll> s(n+1);
    rep(i,n+1) s[i]=0;
    rep(i,n) s[i+1] = s[i] + a[i];


    int l=0, r = 200001; //2つの合計の最大値、最小値

    //calc(x): 2つの合計がx以上のペアがいくつ作れるか。これがm個の場合が答え。
    auto calc = [&](int x){
        ll tot = 0, num = 0; //tot:x以上のペアの合計値 num:x以上のペアの個数
        rep(i,n){
            int j = lower_bound(a.begin(), a.end(), x-a[i]) - a.begin(); //j: x-a[i]以上の値をもつ最初のindex
            num += n-j;
            tot += s[n] - s[j];
            tot += a[i] * (n-j);
        }
        return make_pair(tot,num);
    };

    while(l+1<r){
        int x = (l+r) / 2;
        if(calc(x).second>=m) l=x; else r=x;
    }
    //l,rは1しか違わないが、calc(l).second,calc(r).secondは1以上違う場合がある。
    //その場合は上からm個をきっちりとる必要がある。
    auto ans = calc(l);
    while (ans.second > m){
        ans.first -= l;
        ans.second--;
    }
    cout << ans.first << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

long long black, white;

// 二部グラフ判定
vector<int> color;
bool dfs(const Graph &G, int v, int cur = 0) {
    color[v] = cur;
    if(cur) black++;
    else white++;
    for (auto next_v : G[v]) {
        // 隣接頂点がすでに色確定していた場合
        if (color[next_v] != -1) {
            if (color[next_v] == cur) return false; // 同じ色が隣接したらダメ
            continue;
        }

        // 隣接頂点の色を変えて、再帰的に探索 (一回でも false が返ってきたら false)
        if (!dfs(G, next_v , 1 - cur)) return false;
    }
    return true;
}

int main() {
    // 頂点数と辺数
    long long N, M; cin >> N >> M;
    black = 0; white = 0;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // 探索
    color.assign(N, -1);
    bool is_bipartite = true;
    for (int v = 0; v < N; ++v) {
        if (color[v] != -1) continue; // v が探索済みだったらスルー
        if (!dfs(G, v)) is_bipartite = false;
    }

    long long ans;
    if(!is_bipartite) ans = N*(N-1)/2 - M;
    else ans = black*white - M;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
//26

int a[] = {6000, 4000, 3000, 2000};
signed main(){
	int n = 4;
	rep(i,n){
		int x, y;
		scanf("%lld%lld", &x, &y);x--;
		printf("%lld\n", a[x]*y);
	}
	return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    cout << N/3 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    static int ans;
     static int n;
    static int dfs(int depth, int sum, int before) {
    	int result = 0;
    	if(depth==0){
    		if(sum==ans)return 1;
    		else return 0;
    	}
    	if(sum>ans)return 0;
    	if(before>9)return 0;
    	for(int i=before;i<=9;i++){
    		result+=dfs(depth-1,sum+i,i+1);
    	}
    	return result;
    }
     
    public static void main(String[] args) {
    	Scanner in = new Scanner(System.in);
    	while(true){
    		n = in.nextInt();
    		ans = in.nextInt();
    		if(n+ans==0)break;
    		System.out.println(dfs(n,0,0));
    	}
    }
}

Measured memory_bytes: 18040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;
        public string S;

        public void Run()
        {
            S = Console.ReadLine();
            N = S.Length;
            long r = 0;
            long b = 0;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'W')
                {
                    if (b > 0)
                    {
                        r += b;
                    }
                }
                else
                {
                    b++;
                }
            }

            Console.WriteLine(r);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 11616
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll d ; cin >> d ;
	vll c(26) ;
	for(auto &i:c) cin >> i ;
	vvll di(d,vll(26)) ;
	for(auto &i:di) for(auto &j:i) cin >> j ;
	vll last(26,-1) ;
	ll sum = 0 ;
	for(int i=0;i<d;i++){
		ll t ; cin >> t ;
		t-- ;
		last.at(t) = i ;
		sum += di.at(i).at(t) ;
		for(int j=0;j<26;j++){
			sum -= c.at(j)*(i-last.at(j)) ;
		}
		cout << sum << endl ;
	}
}

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

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

    for (int bit = 0; bit < (1 << 3); bit++) {
        int sum = s[0] - '0';
        char op[3];
        rep(i, 3) {
            if (bit & (1 << i)) {
                sum += s[i + 1] - '0';
                op[i] = '+';
            } else {
                sum -= s[i + 1] - '0';
                op[i] = '-';
            }
        }
        if (sum == 7) {
            rep(i, 3) cout << s[i] << op[i];
            cout << s[3] << "=7" << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var n = int.Parse(line.Trim());
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            var a = Array.ConvertAll(line2, int.Parse);
            Array.Sort(a);
            var b = new int[n+1];
            for (int i = 0; i < n; i++) b[i + 1] = b[i] + a[i];
            Console.WriteLine(b.Sum());
        }
    }
}

Measured memory_bytes: 9832
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
    if(n == 1) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    for(int i=5; i*i<=n; i+=6){
        if((n%i == 0)||(n%(i+2) == 0)) return false;
    }
    return true;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
int main()
{
    fio;
    ll n;
    cin>>n;
    ll ans = 1;
    loop(i,2,n+1)
    {
       ans *=i;
       ans %= mod;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3580