criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<iostream>
#include<string>
#include<vector>

int main(){
	long long N,M;
  	cin>>N>>M;
  	vector<long long> score;
  	vector<long long> sum;
  	for(int i=0; i<N; i++){
      cin>>score[i];
    }
  	for(int i=0; i<N; i++){
      sum.push_back(score[i]*2);
      for(int j=i+1; j<N; j++){
        sum.push_back(score[i]+score[j]);
        sum.push_back(score[i]+score[j]);
      }
    }
  	sort(sum.begin(),sum.end()){
    long long ans=0;
    for(int i=0; i<M; i++){
      ans+=sum[i];
    }
    cout<<ans<<endl;
    return 0;
}
		

Compiler output:
a.cc: In function 'int main()':
a.cc:7:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    7 |         cin>>N>>M;
      |         ^~~
      |         std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:8:9: error: 'vector' was not declared in this scope
    8 |         vector<long long> score;
      |         ^~~~~~
a.cc:8:9: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:8:16: error: expected primary-expression before 'long'
    8 |         vector<long long> score;
      |                ^~~~
a.cc:9:16: error: expected primary-expression before 'long'
    9 |         vector<long long> sum;
      |                ^~~~
a.cc:11:12: error: 'score' was not declared in this scope
   11 |       cin>>score[i];
      |            ^~~~~
a.cc:14:7: error: 'sum' was not declared in this scope
   14 |       sum.push_back(score[i]*2);
      |       ^~~
a.cc:14:21: error: 'score' was not declared in this scope
   14 |       sum.push_back(score[i]*2);
      |                     ^~~~~
a.cc:20:14: error: 'sum' was not declared in this scope
   20 |         sort(sum.begin(),sum.end()){
      |              ^~~
a.cc:20:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   20 |         sort(sum.begin(),sum.end()){
      |         ^~~~
      |         short
a.cc:27:2: error: expected '}' at end of input
   27 | }
      |  ^
a.cc:5:11: note: to match this '{'
    5 | int main(){
      |           ^
Language: Java

import java.util.Arrays;
import java.util.Scanner;

public class Temp{
    static int binarySearch(long Y , long A[]){
        int N = A.length;
        if(A[N - 1] < Y){
            return N;
        }
        if(A[0] >= Y){
            return 0;
        }
        int low = 0; // false
        int high = N - 1; // true
        while(low < high - 1){
            int mid = (low + high) / 2;
            if(A[mid] >= Y){
                high = mid;
            }else{
                low =  mid;
            }
        }
        return high;
    }
    // 幸福度X以上の握手の数
    static long numberOfHandshake(long X , long A[] ){
        int N = A.length;
        long ret = 0;
        for(int i = 0 ; i < N ; ++i){
            ret += N - binarySearch(X - A[i], A);
        }
        return ret;
    }
    static long totalHappiness(long X , long A[]){
        int N = A.length;
        long S[] = new long[N + 1];
        for(int i = 0 ; i < N ; ++i){
            S[i + 1] = S[i] + A[i];
        }
        long ret = 0;
        for(int i = 0 ; i < N ; ++i){
            int idx = binarySearch(X - A[i], A);
            ret += S[N] - S[idx] + (N - idx) * A[i];
        }
        return ret;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long M = sc.nextLong();
        long A[] = new long[N];
        for(int i = 0 ; i < N ; ++i){
            A[i] = sc.nextLong();
        }
        sc.close();
        Arrays.sort(A);
        long low = 0; // ?
        long high = A[N - 1] * 2 + 1; // true
        while(low < high){
            long mid = (low + high) / 2;
            long c = numberOfHandshake(mid , A);
            if(c <= M){
                high = mid;
            }else{
                low = mid + 1;
            }
        }
        long c = numberOfHandshake(low, A);
        long h = totalHappiness(low, A);
        if(c != M){
            h += (low - 1) * (M - c);
        }
        System.out.println(h);
    }
}


Compiler output:
Main.java:4: error: class Temp is public, should be declared in a file named Temp.java
public class Temp{
       ^
1 error
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main(){
 int N;
 long long int M;
 cin >> N >> M;
 int a[N];
 long long int sum[N];
 int id[N];
 int i;
for(i=0;i<N;++i)cin >> a[i];

sort(a,a+N);
sum[0]=a[0];
for(i=1;i<N;++i)sum[i] = sum[i-1] + a[i];
 int left = 0;
 int right = 2 * a[N-1];
 int mid = (left + right)/2;
 long long int count = 0;
 while(left != right){
 mid = (left + right)/2;
 count = 0;
 for(i=0;i<N;++i){
    id[i] = lower_bound(a,a+N,mid-a[i]) - a;
    count += (N - id[i]);
    if(count>M)break;
     }
  if(count>M)left=mid;
  if(count<M)right=mid;
 }
long long int result = 0;
for(i=0;i<N;++i){
  id[i] = lower_bound(a,a+N,left-a[i]) - a;
  result += (sum[N-1]-sum[id[i]]+a[i]*(N-id[i]));
 cout << result << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:2: error: expected '}' at end of input
   38 | }
      |  ^
a.cc:4:11: note: to match this '{'
    4 | int main(){
      |           ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main()
{
 int
 cin >> n >> m;
 int a[n];
 for(i=0;i<n;i++)
 cin >> a[i];
 sort(a,a+n,greater<int>);
 for(i=0;i<n;i++)
 {
  b[i]=2*(i+1)*a[i];
  if(i>0)
  a[i]+=a[i-1];
 }

Compiler output:
a.cc: In function 'int main()':
a.cc:6:6: error: expected initializer before '>>' token
    6 |  cin >> n >> m;
      |      ^~
a.cc:7:8: error: 'n' was not declared in this scope; did you mean 'yn'?
    7 |  int a[n];
      |        ^
      |        yn
a.cc:8:6: error: 'i' was not declared in this scope
    8 |  for(i=0;i<n;i++)
      |      ^
a.cc:9:9: error: 'a' was not declared in this scope
    9 |  cin >> a[i];
      |         ^
a.cc:10:7: error: 'a' was not declared in this scope
   10 |  sort(a,a+n,greater<int>);
      |       ^
a.cc:10:25: error: expected primary-expression before ')' token
   10 |  sort(a,a+n,greater<int>);
      |                         ^
a.cc:11:6: error: 'i' was not declared in this scope
   11 |  for(i=0;i<n;i++)
      |      ^
a.cc:13:3: error: 'b' was not declared in this scope
   13 |   b[i]=2*(i+1)*a[i];
      |   ^
a.cc:16:3: error: expected '}' at end of input
   16 |  }
      |   ^
a.cc:4:1: note: to match this '{'
    4 | {
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;


int main(){
 int N;
 long long int M;
 cin >> N >> M;
 int a[N];
 long long int sum[N];
 int id[N];
 int i;
for(i=0;i<N;++i)cin >> a[i];

sort(a,a+N);
sum[0]=a[0];
for(i=1;i<N;++i)sum[i] = sum[i-1] + a[i];
 int left = 0;
 int right = 2 * a[N-1];
 int mid = (left + right)/2;
 long long int count = 0;
 while(count!= M){
 mid = (left + right)/2;
 count = 0;
 for(i=0;i<N;++i){
    auto it = lower_bound(a,a+N,mid-a[i]);
    id[i] = distance(a,it)-1;
    count += (N - id[i]);
    if(count>M)break;
     }
  if(count>M)left=mid;
  if(count<M)right=mid;
 }
long long int result = 0;
for(i=0;i<N;++i)result += (sum[N-1]-sum[id[i]-1]+a[i]*(N-id[i]));
 cout << result << endl;
  return 0;

Compiler output:
a.cc: In function 'int main()':
a.cc:37:12: error: expected '}' at end of input
   37 |   return 0;
      |            ^
a.cc:5:11: note: to match this '{'
    5 | int main(){
      |           ^
Language: C++

#include <bits/stdc++.h>
using namespace std;


int main(){
 int N;
 long long int M;
 cin >> N >> M;
 int a[N];
 long long int sum[N];
 int id[N];
 int i;
for(i=0;i<N;++i){
  cin >> a[i]; }

sort(a,a+N);
sum[0]=a[0];
for(i=1;i<N;++i)sum[i] = sum[i-1] + a[i];
 int left = 0;
 int right = 2 * a[N-1];
 int mid = (left + right)/2;
 long long int count = 0;
 while(count!=M){
 mid = (left + right)/2;
 count = 0;
 for(i=0;i<N;++i){
    id[i] = (int)(lower_bound(a,a+N,mid-a[i]));
    count += (N - id[i]);
     }
  if(count>M)left=mid;
  if(count<M)right=mid;
 }
long long int result = 0;
for(i=0;i<N;++i)result += (sum[N-1]-sum[id[i]-1]+a[i]*id[i]);
 cout << result << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:13: error: cast from 'int*' to 'int' loses precision [-fpermissive]
   27 |     id[i] = (int)(lower_bound(a,a+N,mid-a[i]));
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;


int main(){
 int N;
 long long int M;
 cin >> N >> M;
 int a[N];
 long long int sum[N];
 int id[N];
 int i;
for(i=0;i<N;++i){
  cin >> a[i]; }

sort(a,a+N);
sum[0]=a[0];
for(i=1;i<N;++i)sum[i] = sum[i-1] + a[i];
 int left = 0;
 int right = 2 * a[N-1];
 int mid = (left + right)/2;
 long long int count = 0;
 while(count!=M){
 mid = (left + right)/2;
 count = 0;
 for(i=0;i<N;++i){
    id[i] = lower_bound(a,a+N,mid-a[i]);
    count += (N - id[i]);
     }
  if(count>M)left=mid;
  if(count<M)right=mid;
 }
long long int result = 0;
for(i=0;i<N;++i)result += (sum[N-1]-sum[id[i]-1]+a[i]*id[i]);
 cout << result << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:24: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   27 |     id[i] = lower_bound(a,a+N,mid-a[i]);
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~~~
      |                        |
      |                        int*
Language: C++

#include <bits/stdc++.h>
using namespace std;


int main(){
 int N;
 long long int M;
 cin >> N >> M;
 int a[N];
 long long int sum[N];
 int id[N];
 int i;
for(i=0;i<N;++i){
  cin >> a[i]; }

sort(a,a+N);
sum[0]=a[0];
for(i=1;i<N;++i)sum[i] = sum[i-1] + a[i];
 int left = 0;
 int right = 2 * a[N-1];
 int mid = (left + right)/2;
 long long int count = 0;
 while(count!=M){
 mid = (left + right)/2;
 count = 0;
 for(i=0;i<N;++i){
    id[i] = (lower_bound(a,a+N,mid-a[i]));
    count += (N - id[i]);
     }
  if(count>M)left=mid;
  if(count<M)right=mid;
 }
long long int result = 0;
for(i=0;i<N;++i)result += (sum[N-1]-sum[id[i]-1]+a[i]*id[i]);
 cout << result << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:25: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   27 |     id[i] = (lower_bound(a,a+N,mid-a[i]));
      |             ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
      |                         |
      |                         int*
Language: C++

#include <bits/stdc++.h>
using namespace std;


int main(){
 int N;
 long long int M;
 cin >> N >> M;
 vector<int> a;
 long long int sum[N];
 int id[N];
 int i;
for(i=0;i<N;++i){
  cin >> a[i]; }

sort(a.begin(),a.end());
sum[0]=a[0];
for(i=1;i<N;++i)sum[i] = sum[i-1] + a[i];
 int left = 0;
 int right = 2 * a[N-1];
 int mid = (left + right)/2;
 long long int count = 0;
 while(count!=M){
 mid = (left + right)/2;
 count = 0;
 for(i=0;i<N;++i){
    id[i] = (lower_bound(a.begin(),a.end(),mid-a[i]));
    count += (N - id[i]);
     }
  if(count>M)left=mid;
  if(count<M)right=mid;
 }
long long int result = 0;
for(i=0;i<N;++i)result += (sum[N-1]-sum[id[i]-1]+a[i]*id[i]);
 cout << result << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:25: error: cannot convert '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'int' in assignment
   27 |     id[i] = (lower_bound(a.begin(),a.end(),mid-a[i]));
      |             ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                         |
      |                         __gnu_cxx::__normal_iterator<int*, std::vector<int> >
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int N;
 long long int M;
 cin >> N >> M;
 vector<int> a;
 long long int sum[N];
 int id[N];
 int i;
for(i=0;i<N;++i){
  cin >> a[i]; }

sort(a.begin(),a.end());
sum[0]=a[0];
for(i=1;i<N;++i)sum[i] = sum[i-1] + a[i];
 int left = 0;
 int right = 2 * a[N-1];
 int mid = (left + right)/2;
 long long int count = 0;
 while(count!=M){
 mid = (left + right)/2;
 count = 0;
 for(i=0;i<N;++i){
    id[i] = lower_bound(a.begin(),a.end(),mid-a[i]);
    count += (N - id[i]);
     }
  if(count>M)left=mid;
  if(count<M)right=mid;
 }
long long int result = 0;
for(i=0;i<N;++i)result += (sum[N-1]-sum[id[i]-1]+a[i]*id[i]);
 cout << result << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:24: error: cannot convert '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'int' in assignment
   26 |     id[i] = lower_bound(a.begin(),a.end(),mid-a[i]);
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                        |
      |                        __gnu_cxx::__normal_iterator<int*, std::vector<int> >
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int N;
 long long int M;
 cin >> N >> M;
 vector<int> a;
 long long int sum[N];
 int id[N];
 int i;
for(i=0;i<N;++i){
  cin >> a[i]; }

sort(a.begin(),a.end());
sum[0]=a[0];
for(i=1;i<N;++i)sum[i] = sum[i-1] + a[i];
 int left = 0;
 int right = 2 * a[N-1];
 int mid = (left + right)/2;
 long long int count = 0;
 while(count!=M){
 mid = (left + right)/2;
 count = 0;
 for(i=0;i<N;++i){
    id[i] = (int)lower_bound(a.begin(),a.end(),mid-a[i]);
    count += (N - id[i]);
     }
  if(count>M)left=mid;
  if(count<M)right=mid;
 }
long long int result = 0;
for(i=0;i<N;++i)result += (sum[N-1]-sum[id[i]-1]+a[i]*id[i]);
 cout << result << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:13: error: invalid cast from type '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to type 'int'
   26 |     id[i] = (int)lower_bound(a.begin(),a.end(),mid-a[i]);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int N;
 long long int M;
 cin >> N >> M;
 vector<int> a;
 long long int sum[N];
 int id[N];
 int i;
for(i=0;i<N;++i){
  cin >> a[i]; }

sort(a.begin(),a.end());
sum[0]=a[0];
for(i=1;i<N;++i)sum[i] = sum[i-1] + a[i];
 int left = 0;
 int right = 2 * a[N-1];
 int mid = (left + right)/2;
 long long int count = 0;
 while(count!=M){
 mid = (left + right)/2;
 count = 0;
 for(i=0;i<N;++i){
    id[i] = lower_bound(a.begin(),a.end(),mid-a[i];
    count += (N - id[i]);
     }
  if(count>M)left=mid;
  if(count<M)right=mid;
 }
long long int result = 0;
for(i=0;i<N;++i)result += (sum[N-1]-sum[id[i]-1]+a[i]*id[i]);
 cout << result << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:51: error: expected ')' before ';' token
   26 |     id[i] = lower_bound(a.begin(),a.end(),mid-a[i];
      |                        ~                          ^
      |                                                   )
Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define vi vector<int>
#define vvi vector<vector<int>>
#define se second

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int pair_count(vi& a, int v) {
    int n = a.size(), res = 0;
    for (int i = 0; i < n; ++i) {
        int cnt = lower_bound(a.begin(), a.end(), v - a[i]) - a.begin();
        res += n - cnt;
    }
    return res;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (auto& i : a) cin >> i;
    sort(a.begin(), a.end());

    int lef = 0, rig = 2e5, val = 0, cnt = 0;

    while (lef <= rig) {
        int mid = (lef + rig) >> 1;
        int cnt_mid = pair_count(a, mid);
        if (cnt_mid >= m) {
            lef = mid + 1;
            val = mid;
            cnt = cnt_mid;
        } else
            rig = mid - 1;
    }

    vector<ll> psum(n + 1);
    partial_sum(a.rbegin(), a.rend(), psum.rbegin() + 1);

    ll res = 1LL * val * (m - cnt);
    for (int i = 0; i < n; ++i) {
        int pos = lower_bound(a.begin(), a.end(), val - a[i]) - a.begin();
        res += 1LL * (n - pos) * a[i] + psum[pos];
        // cout << i << ' ' << a[i] << ' ' << pos << ' ' << n - pos << ' ' << psum[pos] << ' ' << (n - pos) * a[i] + psum[pos] << '\n';
    }

    cout << res << '\n';
    // cout << val << ' ' << cnt << '\n';
    // for (int i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];
    // for (int i = 0; i <= n; ++i) cout << psum[i] << " \n"[i == n];
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:39:34: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<long long int>'
   39 |         int cnt_mid = pair_count(a, mid);
      |                                  ^
a.cc:19:20: note: in passing argument 1 of 'int pair_count(std::vector<int>&, int)'
   19 | int pair_count(vi& a, int v) {
      |                    ^
Language: C++

#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)


int main() {
  ll N,M;
  cin>>N>>M;
  vector<ll> A(N);
  for(ll i=0;i<N;i++){
    cin>>A[i];
  }
  sort(ALL(A));
  reverse(ALL(A));
  queue<ll> mD;
   priority_queue<ll> q;
  for(ll i=0;i<N;i++){
    q.push((2*A[i]));
  }

  priority_queue<ll> q;
  for(ll i=0;i<N;i++){
    for(ll j=i;j<N;j++){
      if(i!=j){
        q.push(A[i]+A[j]);
      }
    }
  }
ll ss=0;
for(ll i=0;i<M;i++){
  ss+= q.top();
  q.pop();
}

  

cout<<ss<<endl;
  
  
  }


Compiler output:
a.cc: In function 'int main()':
a.cc:26:22: error: redeclaration of 'std::priority_queue<long long int> q'
   26 |   priority_queue<ll> q;
      |                      ^
a.cc:21:23: note: 'std::priority_queue<long long int> q' previously declared here
   21 |    priority_queue<ll> q;
      |                       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> v(n), rui(n + 1);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.rbegin(), v.rend());  // 大きい順に並べる！
  for (int i = 0; i < n; i++) rui[i + 1] = rui[i] + v[i];

  // 幸福度上昇がi以上のやつがM通り以上ある、という境界を探す
  ll left = -1, right = INF;
  while (right - left > 1) {
    ll mid = (left + right) / 2;

    ll count = 0;                  // 個数をO(NlogN)で数える
    for (int l = 0; l < n; l++) {  // 左手を全探索して右手はにぶたん、個数を数える
      count += v.rend() - lower_bound(v.rbegin(), v.rend(), mid - v[l]);
    }

    if (count >= m)
      left = mid;
    else
      right = mid;
  }

  // leftが条件を満たすギリギリの幸福度上昇になっている

  ll ans = 0, count = 0;
  for (int i = 0; i < n; i++) {
    int right = v.rend() - lower_bound(v.rbegin(), v.rend(), left - v[i]);
    // cout << "r = " << right << " add = " << right * v[i] + rui[m] << endl;
    ans += right * v[i] + rui[right];
    count += right;
  }

  assert(abs(count - m) == 1)
  
  ans -= (count - m) * left;

  cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:56:3: error: expected ';' before 'ans'
   56 |   ans -= (count - m) * left;
      |   ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  long long M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end(), greater<int>());
  int p1 = 0;
  int p2 = 0;
  long long count = 0;
  long long score = 0
  while(count > M){
    score += A[p1] * A[p2];
    if(p1 < p2) p1++;
    else p2++;
    count++;
  }
  cout << score;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:3: error: expected ',' or ';' before 'while'
   16 |   while(count > M){
      |   ^~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  int ar[n];
  for(int i=0;i<n;i++)
    cin>>ar[i];
  sort(ar,ar+n);
  int i=n-1;
  while(m>0)
  {
     sum += 2*(ar[i]+ar[i-1));
      i=i-1;
       m=m-2;
  }
    cout<<sum<<endl;
     return 0;
  }

Compiler output:
a.cc: In function 'int main()':
a.cc:14:6: error: 'sum' was not declared in this scope
   14 |      sum += 2*(ar[i]+ar[i-1));
      |      ^~~
a.cc:14:28: error: expected ']' before ')' token
   14 |      sum += 2*(ar[i]+ar[i-1));
      |                            ^
      |                            ]
a.cc:18:11: error: 'sum' was not declared in this scope
   18 |     cout<<sum<<endl;
      |           ^~~
Language: C++

#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define maxn 100010
ll n,a[maxn],b[maxn],m;

ll cmp(const void *x,const void *y){
	return (*(ll*)x-*(ll*)y);
}

int chk_id(ll x){
	int l=1,r=n,mid,ans=n+1;
	for(;l<=r;){
		mid=l+r>>1;
		if(x<=a[mid])r=(ans=mid)-1;
		else l=mid+1;
	}
	return ans;
}

int chk(ll mid){
	ll cnt=0;
	int i;
	for(i=1;i<=n;++i)
		cnt+=n+1-chk_id(mid-a[i]);
	if(cnt>=m)return 1;
	else return 0;
}

void solve(){
	int i;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=n;++i)
		scanf("%lld",a+i);
	qsort(a+1,n,sizeof(ll),cmp);
	
	for(i=1;i<=n;++i)
		fprintf(stderr,"%d ",a[i]);
	fprintf(stderr,"\n");
	for(i=1;i<=n;++i)
		b[i]=b[i-1]+a[i];
	ll mid,l=0,r=(ll)1e15,res=-1;
	for(;l<=r;){
		mid=l+r>>1;
		if(chk(mid))l=(res=mid)+1;
		else r=mid-1;
	}
	
	ll ans=0;
	for(i=1,r;i<=n;++i,m-=r){
		r=n+1-chk_id(res-a[i]);
		ans+=(b[n]-b[n-r])+a[i]*r;
	}
	printf("%lld\n",ans+m*res);
} 
int main(){
	solve();
	
	return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:35:32: error: invalid conversion from 'long long int (*)(const void*, const void*)' to '__compar_fn_t' {aka 'int (*)(const void*, const void*)'} [-fpermissive]
   35 |         qsort(a+1,n,sizeof(ll),cmp);
      |                                ^~~
      |                                |
      |                                long long int (*)(const void*, const void*)
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/stdlib.h:36,
                 from a.cc:2:
/usr/include/stdlib.h:971:34: note:   initializing argument 4 of 'void qsort(void*, size_t, size_t, __compar_fn_t)'
  971 |                    __compar_fn_t __compar) __nonnull ((1, 4));
      |                    ~~~~~~~~~~~~~~^~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;


long long n, m;
vector<long long> a;

//判定
bool chk(long long x) {
	long long cnt = 0;
	for(int i=0; i<n; i++) {
		long long pos = lower_bound(a.begin(), a.end(), x - a[i]) - a.begin();
		cnt += (n - pos);
	}
	return cnt < m;//X以上の和がM個未満かどうか
}

int main() {
	cin >> n >> m;
	a.resize(n);
	for(int i=0; i<n; i++)cin >> a[i];
	sort(a.begin(), a.end());
	//二分探索
	long long ng = 0, ok = LLONG_MAX;
	while (abs(ok - ng) > 1) {
		long long mid = (ok + ng) / 2;
		if (chk(mid)) ok = mid;
		else ng = mid;
	}
	//終了時にngにX-1,okにXが入っている。


	vector<long long> wa(n + 1); //Aの累積和
	for(int i=0; i<n; i++) wa[i + 1] = wa[i] + a[i];
	for(int i=0; i<n; i++) {
		long long pos = upper_bound(a.begin(), a.end() , ng - a[i]) - a.begin();
		long long cnt = n - pos;
		ans += cnt * a[i] + (wa[n] - wa[pos]);
		m -= cnt;
	}
	ans += m * ng;
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   38 |                 ans += cnt * a[i] + (wa[n] - wa[pos]);
      |                 ^~~
      |                 abs
a.cc:41:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   41 |         ans += m * ng;
      |         ^~~
      |         abs
Language: C

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  char str[1000000];
  long int N,M,A[100000];
  long int i,j,k,l,tmp,n,sum,s[100000];
  int flag=0;
  
  fgets(str,sizeof(str),stdin);
  N=atol(strtok(str," "));
  M=atol(strtok(NULL," "));
  fgets(str,sizeof(str),stdin);
  A[0]=atol(strtok(str," "));
  while(i=1;i<N;i++){
    A[i]=atol(strtok(NULL," "));
  }
  
  for(i=0;i<N;i++){
    s[i]=i;
    k=i;
    tmp=A[i];
    for(j=i+1;j<N;j++){
      if(A[j]>tmp){
        k=j;
        tmp=A[j];
      }
    }
    A[k]=A[i];
    A[i]=tmp;
  }
  
  i=0;
  n=0;
  sum=0;
  k=0;
  while(n<M){
    if(s[k]==k+1){
      k++;
    }
    tmp=A[s[0]];
    l=0;
    for(i=0;i<k;i++){
      if(A[s[j]]>tmp){
        tmp=A[s[j]];
        l=i;
      }
    }
    sum+=A[l]+A[s[l]];
    n++;
    if(n==M){
      break;
    }
    if(s[l]!=l){
      sum+=A[l]+A[s[l]];
      n++;
    }
  }
  printf("%ld\n",sum);
  return 0;
}
      

Compiler output:
main.c: In function 'main':
main.c:17:12: error: expected ')' before ';' token
   17 |   while(i=1;i<N;i++){
      |        ~   ^
      |            )
Language: C

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  char str[1000000];
  long int N,M,A[100000];
  long int i,j,k,l,tmp,n,sum,s[100000];
  int flag=0;
  
  fgets(str,sizeof(str),stdin);
  N=atol(strtok(str," "));
  M=atol(strtok(NULL," "));
  fgets(str,sizeof(str),stdin);
  A[0]=atol(strtok(str," "));
  while(i=1;i<N;i++){
    A[i]=strtok(NULL," ");
  }
  
  for(i=0;i<N;i++){
    s[i]=i;
    k=i;
    tmp=A[i];
    for(j=i+1;j<N;j++){
      if(A[j]>tmp){
        k=j;
        tmp=A[j];
      }
    }
    A[k]=A[i];
    A[i]=tmp;
  }
  
  i=0;
  n=0;
  sum=0;
  k=0;
  while(n<M){
    if(s[k]==k+1){
      k++;
    }
    tmp=A[s[0]];
    l=0;
    for(i=0;i<k;i++){
      if(A[s[j]]>tmp){
        tmp=A[s[j]];
        l=i;
      }
    }
    sum+=A[l]+A[s[l]];
    n++;
    if(n==M){
      break;
    }
    if(s[l]!=l){
      sum+=A[l]+A[s[l]];
      n++;
    }
  }
  printf("%ld\n",sum);
  return 0;
}
      

Compiler output:
main.c: In function 'main':
main.c:17:12: error: expected ')' before ';' token
   17 |   while(i=1;i<N;i++){
      |        ~   ^
      |            )
main.c:18:9: error: assignment to 'long int' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
   18 |     A[i]=strtok(NULL," ");
      |         ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,-1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fst first
#define sec second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define int long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
}

int main()
{
	//fopen();
	fastio;
	int n,m;
	cin>>n>>m;
	int a[n];
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	int i=0,j=10000000010;
	while(j-i>1)
	{
		int mid=(j+i)/2;
		int cunt=0;
		rep(i,n){ 
			int t=lower_bound(a,a+n,mid-a[i])-a;
			cunt+=n-t;
		}
		//cout<<i<<endl;
		if(cunt>=m)i=mid;
		else j=mid;
	}
	int r[n];
//	cout<<i<<endl;
	rep(j,n) r[j]=a[j]+(j?r[j-1]:0);
	//cout<<r[1]<<endl;
	int ans=0;
	int cnt=0;
	rep(j,n){
		int k=lower_bound(a,a+n,i-a[j])-a;
		ans+=r[n-1]-(k?r[k-1]:0);
		ans+=a[j]*(n-k);
		cnt+=(n-k);
	}
	//cout<<ans<<endl;
	if(cnt>=m)ans-=(cnt-m)*i;
	cout<<ans;
	return 0;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,-1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fst first
#define sec second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define int long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
}

int main()
{
	//fopen();
	fastio;
	int n,m;
	cin>>n>>m;
	int a[n];
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	int i=0,j=10000000010;
	while(j-i>1)
	{
		int mid=(j+i)/2;
		int cunt=0;
		rep(i,n){ 
			int t=lower_bound(a,a+n,mid-a[i])-a;
			cunt+=n-t;
		}
		//cout<<i<<endl;
		if(cunt>=m)i=mid;
		else j=mid;
	}
	int r[n];
//	cout<<i<<endl;
	rep(j,n) r[j]=a[j]+(j?r[j-1]:0);
	//cout<<r[1]<<endl;
	int ans=0;
	int cnt=0;
	rep(j,n){
		int k=lower_bound(a,a+n,i-a[j])-a;
		ans+=r[n-1]-(k?r[k-1]:0);
		ans+=a[j]*(n-k);
		cnt+=(n-k);
	}
	//cout<<ans<<endl;
	if(cnt>=m)ans-=(cnt-m)*i;
	cout<<ans;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e+9 + 7;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
int main(){
  ll n,m;
  cin >> n >> m;
  ll a[n+5];
  for(int i = 0;i<n;++i){
    cin >> a[i];
  }
  ll np = l*l;
  ll b[np+5] = {0};
  for(int i = 0;i<n;++i){
    for(int j = 0;j<n;++j){
      b[i*n+j] = a[i] + a[j];
    }
  }
  sort(b, b + SIZE_OF_ARRAY(b),greater<ll>());
  ll ans = 0;
  for(ll i = 0;i<m;++i) ans += b[i];
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:11: error: 'l' was not declared in this scope
   14 |   ll np = l*l;
      |           ^
Language: C++

#include <iostream>
#include <vector>

using LL = long long int;

LL get_times(LL max_val, const std::vector<int>& v) {
    LL sum = 0;
    for (int i=0; i<v.size(); ++i) {
        sum += v.end() - lower_bound(v.begin(), v.end(), max_val-v[i]);
    }

    return sum;
}

LL score(LL max_val, const std::vector<int>& v, const LL& m) {
    LL used = 0;
    std::vector<int> rui(v.size()+1,0);
    for (int i=v.size()-1; i>=0; --i) {
        rui[i] = rui[i+1] + v[i];
    }
    LL sum = 0;
    for (int i=0; i<v.size(); ++i) {
        int l = lower_bound(v.begin(), v.end(), max_val-v[i]) - v.begin();
        int num = v.end() - lower_bound(v.begin(), v.end(), max_val-v[i]);
        sum += rui[l] + v[i]*num;
        used += num;
    }

    return sum -(used - m)*max_val;
}

int main(){
    LL n,m;
    std::cin>>n>>m;
    std::vector<int> v;

    for (int i=0; i<n; ++i) {
        int tmp;
        std::cin >> tmp;
        v.emplace_back(tmp);
    }

    std::sort(v.begin(), v.end());

    LL l = 0, r = 1e16;
    while( r-l>1 ){
        LL mid = (r+l)/2;

        LL times = get_times(mid, v);
        if (times < m) {
            r = mid;
        }else{
            l = mid;
        }
    }

    std::cout << score(l, v, m) << std::endl;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:10: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
   43 |     std::sort(v.begin(), v.end());
      |          ^~~~
      |          qsort
Language: Java

import java.util.Scanner;

/**
 * Handshake
 */
public class Main2 {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int MAX = 100000;

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

            int[] C = new int[MAX + 2];
            for (int a : A) {
                C[a]++;
            }

            int[] CS = new int[MAX + 2];
            for (int i = MAX; i >= 0; i--) {
                CS[i] += CS[i + 1] + C[i];
            }

            int min = 0;
            int max = MAX * 2;

            while (max - min > 1) {
                int mid = (max + min) / 2;

                long K = 0;
                for (int a : A) {
                    K += CS[Math.max(mid - a, 0)];
                }

                if (K < M) {
                    max = mid;
                } else {
                    min = mid;
                }
            }

            long[] S = new long[MAX + 2];
            for (int i = MAX; i >= 0; i--) {
                S[i] = S[i + 1] + (long) i * C[i];
            }

            long H = 0;
            long K = 0;
            for (int a : A) {
                H += a * CS[Math.max(min + 1 - a, 0)] + S[Math.max(min + 1 - a, 0)];
                K += CS[Math.max(min + 1 - a, 0)];
            }

            if (M - K > 0) {
                H += min * (M - K);
            }

            System.out.println(H);
        }
    }

}


Compiler output:
Main.java:6: error: class Main2 is public, should be declared in a file named Main2.java
public class Main2 {
       ^
1 error
Language: Java


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main_Sort {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int A[] = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		ArrayList<Pair> pairs = new ArrayList<Pair>();
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				Pair pair = new Pair();
				pair.setX(A[i]);
				pair.setY(A[j]);
				pair.setValue(A[i] + A[j]);
				pairs.add(pair);
				Collections.sort(pairs, (p1,p2)->p1.getValue()-p2.getValue());
				if(pairs.size()>M) {
					pairs.remove(0);
				}
			}
		}
		
		
		int total = 0;
		for (int i = 0; i < M; i++) {
				total += pairs.get(i).getValue();
		}
		System.out.println(total);
	}

}
class Pair {
	private int x;
	private int y;
	private int value;
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	public int getValue() {
		return value;
	}
	public void setValue(int value) {
		this.value = value;
	}
	
}


Compiler output:
Main.java:10: error: class Main_Sort is public, should be declared in a file named Main_Sort.java
public class Main_Sort {
       ^
1 error
Language: C++

#include<iostream>


void main()
{
int n ,m ;
cin>>n>>m ;cout<<"\n";
int a[100],j=0,c,d;
for(int i=0;i<=n-1;i++)
cin>>a[i];
for(;j<n;j++)
{
for(i=j;i<n; i++)
{
if(a[j]<a[i]){
c=a[j];
a[j]=a[i];
a[i]=c;}
}

}
    c=0,d=0;
for(i=0;i<=m-1;i++)
{if(i%3==0){
c = c+ 2*(a[i]);
d=i+1;}
else{
c = c + (a[d]+a[d-1] ); }
  
}

cout<<"\n\n\n";
cout<<c;

getch();
}


Compiler output:
a.cc:4:1: error: '::main' must return 'int'
    4 | void main()
      | ^~~~
a.cc: In function 'int main()':
a.cc:7:1: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    7 | cin>>n>>m ;cout<<"\n";
      | ^~~
      | std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:7:12: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
    7 | cin>>n>>m ;cout<<"\n";
      |            ^~~~
      |            std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:13:5: error: 'i' was not declared in this scope
   13 | for(i=j;i<n; i++)
      |     ^
a.cc:23:5: error: 'i' was not declared in this scope
   23 | for(i=0;i<=m-1;i++)
      |     ^
a.cc:35:1: error: 'getch' was not declared in this scope; did you mean 'getc'?
   35 | getch();
      | ^~~~~
      | getc
Language: C++

#include<iostream>
#include<conio>

void main()
{
int n ,m ;
cin>>n>>m ;cout<<"\n";
int a[100],j=0,c,d;
for(int i=0;i<=n-1;i++)
cin>>a[i];
for(;j<n;j++)
{
for(i=j;i<n; i++)
{
if(a[j]<a[i]){
c=a[j];
a[j]=a[i];
a[i]=c;}
}

}
    c=0,d=0;
for(i=0;i<=m-1;i++)
{if(i%3==0){
c = c+ 2*(a[i]);
d=i+1;}
else{
c = c + (a[d]+a[d-1] ); }
  
}

cout<<"\n\n\n";
cout<<c;

getch();
}

Compiler output:
a.cc:2:9: fatal error: conio: No such file or directory
    2 | #include<conio>
      |         ^~~~~~~
compilation terminated.
Language: C

#include<iostream.h>
#include<conio.h>

void main()
{
int n ,m ;
cin>>n>>m ;cout<<"\n";
int a[100],j=0,c,d;
for(int i=0;i<=n-1;i++)
cin>>a[i];
for(;j<n;j++)
{
for(i=j;i<n; i++)
{
if(a[j]<a[i]){
c=a[j];
a[j]=a[i];
a[i]=c;}
}

}
    c=0,d=0;
for(i=0;i<=m-1;i++)
{if(i%3==0){
c = c+ 2*(a[i]);
d=i+1;}
else{
c = c + (a[d]+a[d-1] ); }
  
}

cout<<"\n\n\n";
cout<<c;

getch();
}

Compiler output:
main.c:1:9: fatal error: iostream.h: No such file or directory
    1 | #include<iostream.h>
      |         ^~~~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream.h>
#include<conio.h>

void main()
{
int n ,m ;
cin>>n>>m ;cout<<"\n";
int a[100],j=0,c,d;
for(int i=0;i<=n-1;i++)
cin>>a[i];
for(;j<n;j++)
{
for(i=j;i<n; i++)
{
if(a[j]<a[i]){
c=a[j];
a[j]=a[i];
a[i]=c;}
}

}
    c=0,d=0;
for(i=0;i<=m-1;i++)
{if(i%3==0){
c = c+ 2*(a[i]);
d=i+1;}
else{
c = c + (a[d]+a[d-1] ); }
  
}

cout<<"\n\n\n";
cout<<c;

getch();
}

Compiler output:
a.cc:1:9: fatal error: iostream.h: No such file or directory
    1 | #include<iostream.h>
      |         ^~~~~~~~~~~~
compilation terminated.
Language: C++

#include<fstream.h>
#include<conio.h>

void main()
{
int n ,m ;
cin>>n>>m ;cout<<"\n";
int a[100],j=0,c,d;
for(int i=0;i<=n-1;i++)
cin>>a[i];
for(;j<n;j++)
{
for(i=j;i<n; i++)
{
if(a[j]<a[i]){
c=a[j];
a[j]=a[i];
a[i]=c;}
}

}
    c=0,d=0;
for(i=0;i<=m-1;i++)
{if(i%3==0){
c = c+ 2*(a[i]);
d=i+1;}
else{
c = c + (a[d]+a[d-1] ); }
  
}

cout<<"\n\n\n";
cout<<c;

getch();
}

Compiler output:
a.cc:1:9: fatal error: fstream.h: No such file or directory
    1 | #include<fstream.h>
      |         ^~~~~~~~~~~
compilation terminated.
Language: C++

#include <memory.h>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cctype>
#include <cstring>
#include <climits>
#include <cmath>
#include <vector>
#include <string>
#include <memory>
#include <numeric>
#include <limits>
#include <functional>
#include <tuple>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>

#include <intrin.h>
#include <immintrin.h>

using namespace std;

#define PROFILE_START(i)    clock_t start##i = clock()
#define PROFILE_STOP(i)     fprintf(stderr, "elapsed time (" #i ") = %f\n", double(clock() - start##i) / CLOCKS_PER_SEC)

// https://atcoder.jp/contests/abc149/tasks/abc149_e?fbclid=IwAR0nHOgZ-UygqFHB08BPLs_o3_6r5K2TB_Rd0fV3Ijhcru1aSaIaRQQjo4Y
// E - Handshake

typedef long long           ll;
typedef unsigned long long  ull;

tuple<ll, ll, ll> calc(const vector<int>& A, const vector<ll>& prefixSum, int x) {
    int N = int(A.size());

    ll cnt = 0;
    ll sum = 0;
    ll minX = numeric_limits<ll>::max();

    int j = N - 1;
    for (int i = 0; i < N; i++) {
        while (j >= 0 && (A[i] + A[j]) >= x)
            j--;

        if (j < N - 1) {
            minX = min(minX, 0ll + A[i] + A[j + 1]);
            sum += prefixSum[N] - prefixSum[j + 1] + 1ll * A[i] * (N - 1 - j);
            cnt += N - 1 - j;
        }
    }

    return make_tuple(cnt, sum, minX);
}

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

    int N;
    ll M;
    cin >> N >> M;

    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];
    sort(A.begin(), A.end());

    vector<ll> prefixSum(N + 1);
    for (int i = 0; i < N; i++)
        prefixSum[i + 1] = prefixSum[i] + A[i];

    int lo = 1, hi = A.back() * 2ll;
    while (lo <= hi) {
        int mid = lo + (hi - lo) / 2;

        auto t = calc(A, prefixSum, mid);

        if (get<0>(t) >= M)
            lo = mid + 1;
        else
            hi = mid - 1;
    }

    auto t = calc(A, prefixSum, hi);
    ll ans = get<1>(t) - get<2>(t) * (get<0>(t) - M);
    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc:27:10: fatal error: intrin.h: No such file or directory
   27 | #include <intrin.h>
      |          ^~~~~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (auto &a: A)
		cin >> a;
	sort(A.begin(), A.end());
	int lo = 0, hi = 1e6, m = 0;
	while (hi-lo > 1) {
		m = (lo+hi) / 2;
		int cnt = 0;
		for(auto a: A) {
			auto itr = lower_bound(A.begin(), A.end(), m - a);
			int inc = A.end() - itr;
			cnt += inc;
		}
		if (cnt == M)
			break;
		(cnt > M ? lo : hi) = m;
	}
	vector<int> I(N);
	for (int i = 0; i < N; i++) {
		auto a = A[i];
		auto itr = lower_bound(A.begin(), A.end(), m - a);
		I[i] = itr - A.begin();
	}
	uint64_t score = 0;
	int small = 1e6, num = 0;
	for(int i = 0; i < N; i++) {
		for (int k = I[i]; k < N; k++) {
			score += A[i] + A[k];
			if (A[i] + A[k] < small)
				small = A[i] + A[k];
			++num;
		}
	}
	printf("%ld\n", score - (num - M) * small);
	return 0;
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

using Complex = complex<double>;
const long double M_PI = 3.1415926535;

//DFT(離散Fouriet変換)
//A:変換したい多項式(A[i]=i次の係数)直変更!!!!!,N:1の何乗根?(2の累乗数),sgn:逆変換の時-1に
void dft(vector<Complex>* A, int N, int sgn = 1) {
	if (N == 1) return;

	vector<Complex>* F = new vector<Complex>(N / 2);
	vector<Complex>* G = new vector<Complex>(N / 2);
	for (int i = 0; i < N / 2; i++) {
		F->at(i) = A->at(2 * i + 0);
		G->at(i) = A->at(2 * i + 1);
	}

	dft(F, N / 2, sgn);
	dft(G, N / 2, sgn);

	Complex zeta(cos(2.0 * M_PI / N), sin(2.0 * M_PI / N) * sgn);
	Complex pow_zeta = 1;

	for (int i = 0; i < N; i++) {
		A->at(i) = F->at(i % (N / 2)) + pow_zeta * G->at(i % (N / 2));
		pow_zeta *= zeta;
	}
	delete F, G;
	return;
}

//inverse DFT(離散Fouriet逆変換)
//A:変換したい多項式,N:要素数(2の累乗数)
void inv_dft(vector<Complex>* A, int N) {
	dft(A, N, -1);
	for (int i = 0; i < N; i++) {
		A->at(i) /= N;
	}
	return;
}

//多項式の畳み込み(FFT,inverse FFTを使う)
//A,B:多項式(書き変わります...),C:結果保存用
void multiply(vector<Complex>& A, vector<Complex>& B, vector<Complex>& C) {
	int sz = A.size() + B.size() + 1;
	int n = 1;
	while (n < sz) n *= 2;

	A.resize(n), B.resize(n);
	dft(&A, n);
	dft(&B, n);

	C.resize(n);
	for (int i = 0; i < n; i++) {
		C[i] = A[i] * B[i];
	}
	inv_dft(&C, n);
	return;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll N,M;
	cin >> N >> M;
	vector<Complex> A(1e5+1,0);
	vector<Complex> B(1e5 + 1, 0);
	for (ll n = 0; n < N;n++) {
		ll a;
		cin >> a;
		A[a] += 1;
		B[a] += 1;
	}
	vector<Complex> C;
	multiply(A, B, C);
	ll ans = 0;
	for (ll c = 2e5; c >= 0; c--) {
		ll d = min((ll)round(C[c].real()), M);
		ans += d * c;
		M -= d;
	}
	cout << ans << "\n";
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/cmath:47,
                 from /usr/include/c++/14/math.h:36,
                 from a.cc:6:
a.cc:39:19: error: expected unqualified-id before numeric constant
   39 | const long double M_PI = 3.1415926535;
      |                   ^~~~
Language: C++

#include <algorithm>
#include <array>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <stack>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define MOD ((ll)1000000007)

ll main(ll argc, char const *argv[])
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	ll N;
	ll M;
	cin >> N >> M;

	vector<ll> A(N, 0);
	for (ll i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	// 昇順でソート
	sort(A.begin(), A.end());

	// min_happiness以上の幸福度を獲得可能な握手パターンがM以上あるか
	auto isOK = [&](ll min_happiness) {
		ll count_shake = 0;
		// i番目との握手を固定
		for (ll i = 0; i < N; i++)
		{
			// 合計の幸福度がmin_happiness以上となる最小のj
			ll bound = min_happiness - A[i];
			ll j = lower_bound(A.begin(), A.end(), bound) - A.begin();
			// min_happiness以上を達成可能な握手パターン数を加算
			count_shake += N - j;
		}
		return count_shake >= M;
	};

	// isOKがtrueとなる最大のmin_happinessを二分探索
	ll left = 0;
	ll right = A.back() * 2 + 1; // 1度の握手で獲得可能な幸福度の最大値
	while (right - left > 1)
	{
		ll pivot = left + (right - left) / 2;
		if (isOK(pivot))
		{
			// OKの場合、min_happinessをもっと大きくできる
			left = pivot;
		}
		else
		{
			// NGの場合、min_happinessを緩和
			right = pivot;
		}
	}

	// 累積和を計算
	vector<ll> cumsum(N + 1, 0);
	for (ll i = 0; i < N; i++)
	{
		cumsum[i + 1] = cumsum[i] + A[i];
	}

	// 合計幸福度を計算
	ll total_happiness = 0;
	ll count = 0;
	for (ll i = 0; i < N; i++)
	{
		// 合計の幸福度がleft - A[i]以上となる最小のj
		ll j = lower_bound(A.begin(), A.end(), left - A[i]) - A.begin();
		count += N - j;
		total_happiness += cumsum[N] - cumsum[j]; // 各jの幸福度の合計
		total_happiness += A[i] * (N - j);		  // iの幸福度の合計
	}

	total_happiness -= left * (count - M);
	cout << total_happiness << endl;

	return 0;
}


Compiler output:
a.cc:28:1: error: '::main' must return 'int'
   28 | ll main(ll argc, char const *argv[])
      | ^~
a.cc:28:4: warning: first argument of 'int main(ll, const char**)' should be 'int' [-Wmain]
   28 | ll main(ll argc, char const *argv[])
      |    ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
long long a[100005],sum[100005],n,m,ans;
long long check(long long x){
    long long res=0;
    for(int i=1;i<=n;i++){
        int k=lower_bound(a+1,a+1+n,x-a[i])-a;
        res+=n-k;
    }
    return res;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
    }
    long long l=0,r=200001;
    while(r>=l){
        long long mid=(l+r)/2;
        if(check(mid)>=m) l=mid+1;
        else r=mid-1; 
    }
    for(int i=1;i<=n;i++){
        int k=lower_bound(a+1,a+1+n,l-1-a[i])-a-1;
        res+=n-k;
        ans+=sum[n]-sum[k]+(n-k)*a[i];
    }
    ans+=(m-res)*(l-1);
    cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:9: error: 'res' was not declared in this scope
   29 |         res+=n-k;
      |         ^~~
a.cc:32:13: error: 'res' was not declared in this scope
   32 |     ans+=(m-res)*(l-1);
      |             ^~~