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

using namespace std;
typedef long long ll;


int main(){
	int h,w,k;
	cin >> h >> w >> k;
	char mat[h][w];
	unordered_map<int,int> m;
	
	for(int i = 0;i<h;i++){
		for(int j = 0;j < w;j++){
			char kk;
			cin >> kk;
			mat[i][j] = kk;
		}
	}
	int ans[h][w];
	int c = 1;
	for(int i = 0;i<h;i++){
		for(int j = 0;j<w;j++){
			ans[i][j] = -1;
		}
	}
	for(int j = 0;j < w;j++){
		int sum = 0;
		for(int i = 0;i<h;i++){
			if(mat[i][j] == '#'){
				sum++;
			}
		}
		m[j] = sum;
		if(sum == 0){
			continue;
		}
		bool flag = false;
		for(int i = 0;i < h;i++){
			if(flag == true && mat[i][j] == '#'){
				c++;
			}
			ans[i][j] = c;
			if(mat[i][j] == '#'){
				flag = true;
			}
		}
		c++;
	}

	for(int i = 0;i<h;i++){
		for(int j = 0;j<w;j++){
			if(ans[i][j] == -1 && j!=0){
				ans[i][j] = ans[i][j-1];
			}
		}
	}

	for(int i = h-1;i>=0;i--){
		for(int j = w-1;j>=0;j--){
			if(ans[i][j] == -1 && j!= w-1){
				ans[i][j] = ans[i][j+1];
			}
		}
	}
	for(int i = 0;i<h;i++){
		for(int j = 0;j < w;j++){
			cout << ans[i][j] << " ";
		}
		cout << "\n";
	}
	return 0;


}

Measured memory_bytes: 1152
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

const int INF=1<<30;

template <class RandomIt>
size_t msort(RandomIt first, RandomIt last) {
    if (first+1 >= last) return 0;

    using T=typename RandomIt::value_type;
    ptrdiff_t lhalf=(last-first)>>1;
    RandomIt mid=first+lhalf;

    size_t count_=0;
    count_ += msort(first, mid);
    count_ += msort(mid, last);

    ptrdiff_t rhalf=last-mid;
    vector<T> L(lhalf+1), R(rhalf+1); L[lhalf]=R[rhalf]=INF;

    for (RandomIt in=first, out=L.begin(); in<mid; (++in, ++out))
        *out = *in;

    for (RandomIt in=mid, out=R.begin(); in<last; (++in, ++out))
        *out = *in;

    RandomIt l=L.begin(), r=R.begin();
    for (RandomIt it=first; it<last; ++it) {
        if (*l <= *r) {
            *it = *l++;
        } else {
            *it = *r++;
            count_ += (mid-first)-(l-L.begin());
        }
    }

    return count_;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> a(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &a[i]);

    printf("%lld\n", msort(a.begin(), a.end()));
    return 0;
}

Measured memory_bytes: 3904
#include <stdio.h>

int main(void)
{
    int N=0;
    long int D=0;
    int count=0;
    long int x=0;
    long int y=0;

    scanf("%d%ld",&N,&D);
    for(int i=0;i<N;i++){
        scanf("%ld%ld",&x,&y);
        if(x*x+y*y<=D*D) count+=1;
    }

    printf("%d",count);
    return 0;
}


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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<string> red_list(N);
    for(int i = 0; i< N; i++){
        cin >> red_list[i];
    }

    int M;
    cin >> M;
    vector<string> blue_list(M);
    for(int i = 0; i< M; i++){
        cin >> blue_list[i];
    }

    map<string, int> mp;

    for(int i = 0; i < red_list.size(); i ++){
        mp[red_list[i]] += 1;
    }

    for(int i = 0; i < blue_list.size(); i ++){
        mp[blue_list[i]] -= 1;
    }

    int currenctMax = 0;
    for(auto it = mp.cbegin(); it != mp.cend(); ++it){
        if(it -> second > currenctMax){
            currenctMax = it -> second;
        }
    }

    cout << currenctMax << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
	int n; cin >> n;
	vector<string> a(n);
	rep(i, n) {
		cin >> a[i];
		if (i != 0 && a[i - 1].back() != a[i].front()) {
			cout << "No" << endl;
			return 0;
		}
		rep(j, i) {
			if (a[i] == a[j]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define xh(a,b,c)for(int a=b;a<=c;a++)
#define dxh(a,b,c)for(int a=b;a>=c;a--)
inline ll read()
{
	ll out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=1e5+10;
struct bnum
{
    short a[MAXN];
    int size;
    bnum()
    {
        memset(a,0,sizeof a);
        size=1;
    }
    bnum operator =(ll k)
    {
        char ch[1000];
        sprintf(ch,"%lld",k);
        size=strlen(ch);
        for(int i=0;i<size;i++)
        	a[i]=ch[size-i-1]-'0';
        return *this;
    }
    bnum operator +(bnum b)
    {
        bnum c;
        int lena=size,lenb=b.size;
        c.size=max(lena,lenb)+1;
        for(int i=0;i<c.size+1;i++)
        {
            c.a[i]+=a[i]+b.a[i];
            if(c.a[i]>=10)
            c.a[i]-=10,c.a[i+1]++;
        }
        if(!c.a[c.size-1]&&c.size>1)
        c.size--;
        return c;
    }
private:
    void clear()
    {
        memset(a,0,sizeof a);
        size=1;
    }
};
ostream& operator <<(ostream &os,bnum x)
{
    for(int i=x.size-1;i>=0;i--)
    printf("%d",x.a[i]);
    return os;
}
bnum ans;
int main()
{
	ll n=read();
	for(ll R=1; R*R<n; ++R)
	{
		if(n%R)
			continue;
		ll r=R;
		ll m1=n/r;
		ll m=m1-1;
		if(m>0 && r<m)
		{
			bnum k;
			k=m;
			ans=ans+k;
		}
		swap(m1,r);
		m=m1-1;
		if(m>0 && r<m)
		{
			bnum k;
			k=m;
			ans=ans+k;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

signed main()
{
    string s;
    cin >> s;
    int N = s.size();
    rep(i, N - 1)
    {
        if (s[i] == s[i + 1]) {
            printf("%d %d\n", i + 1, i + 2);
            return 0;
        }
    }
    rep(i, N - 2)
    {
        if (s[i] == s[i + 2]) {
            printf("%d %d", i + 1, i + 3);
            return 0;
        }
    }
    printf("%d %d\n", -1, -1);
    return 0;
}

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

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

    long long cur=1;
    long long ans=0;
    for(int i=0;i<n;++i){
        if(a[i]!=cur){
            ++ans;
            continue;
        }
        ++cur;
    }

    bool flag=false;
    for(int i=0;i<n;++i){
        if(a[i]==1){
            flag=true;
            break;
        }
    }

    if(!flag) cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 4820
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

type intHeap []int

func (h *intHeap) Len() int           { return len(*h) }
func (h *intHeap) Swap(i, j int)      { (*h)[i], (*h)[j] = (*h)[j], (*h)[i] }
func (h *intHeap) Less(i, j int) bool { return (*h)[i] > (*h)[j] }
func (h *intHeap) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func solve() {
	n, m := getInt(), getInt()
	h := intHeap(getIntSlice(n))
	heap.Init(&h)

	for i := 0; i < m; i++ {
		h[0] /= 2
		heap.Fix(&h, 0)
	}

	ans := sum(h...)
	fmt.Fprintln(wr, ans)
}

func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]) {
  int h, w;
  cin >> h >> w;
  char a[h][w];
  vector<int> col, row;
  vector<vector<char>> ans;
  for (size_t i = 0; i < h; i++) {
    for (size_t j = 0; j < w; j++) cin >> a[i][j];
  }
  for (int i = 0; i < h; i++) {
    bool tf = true;
    for (int j = 0; j < w; j++) {
      if (a[i][j]!='.') tf = false;
    }
    if (tf) row.push_back(i);
  }
  for (int i = 0; i < w; i++) {
    bool tf = true;
    for (int j = 0; j < h; j++) {
      if (a[j][i]!='.') tf = false;
    }
    if (tf) col.push_back(i);
  }
  for (int i = 0; i < h; i++) {
    if (distance(row.begin(),find(row.begin(),row.end(), i))!=row.size()) continue;
    else{
      vector<char> temp;
      for (int j = 0; j < w; j++) {
        if (distance(col.begin(),find(col.begin(),col.end(), j))!=col.size()) continue;
        else {
          temp.push_back(a[i][j]);
        }
      }
      ans.push_back(temp);
    }
  }

  for (size_t i = 0; i < ans.size(); i++) {
    for (size_t j = 0; j < ans[i].size(); j++) {
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <bitset>
using namespace std;

int main() {
    int n, m;
    cin>>n>>m;
    vector<pair<int, int>> s(n), c(m);
    for (int i=0; i<n; ++i) {
        int x, y;
        cin>>x>>y;
        s[i]=make_pair(x, y);
    }
    for (int i=0; i<m; ++i) {
        int x, y;
        cin>>x>>y;
        c[i]=make_pair(x, y);
    }
    for (int i=0; i<n; ++i) {
        int mi=INT_MAX, cp=0;
        for (int j=0; j<m; ++j) {
            int dist=abs(s[i].first-c[j].first)+abs(s[i].second-c[j].second);
            if (dist<mi) {
                mi=dist;
                cp=j;
            }
        }
        cout<<cp+1<<'\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define size_t long long
// std::sort(&a[0], &a[4], [](auto& x, auto& y){return x[0] < y[0];});
//accumulate(&arr2[n], &arr2[m-1], 0);
using namespace std;

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

  ll L,R;
  std::cin >> L >> R;
  int ans = 2020;
  for (int i = (int)L%2019; i <= (int)L%2019 + min((int)(R-L),2019) - 1; i++) {
    for (int j = i+1; j <= (int)L%2019 + min((int)(R-L),2019) ; j++) {
      ans = min(ans,(i*j)%2019);
    }
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
//***Faithless is he that says farewell when the road darkens***

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main()
{
   ll n;
   cin>>n;
   vector<string> v(n);

   for(ll i=0;i<n;i++){
      cin>>v[i];
      sort(v[i].begin(),v[i].end());
   }

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

   string s=v[0];
   ll c=0,f=0;

   for(ll i=0;i<n;i++){
      if(v[i]==s) f++;
      else{
         s=v[i];
         c+=(f*(f-1))/2;
         f=1;
      }
   }

   c+=(f*(f-1))/2;
   cout<<c;
}

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

signed main() {
  ios::sync_with_stdio(false);

  int r, g, b, n;
  cin >> r >> g >> b >> n;

  vector<int> dp(n + 1);
  for (int i = 0; i < n + 1; ++i)
    for (int j = 0; j < n + 1; ++j)
      if (i * r + j * g < n + 1)
        ++dp[i * r + j * g];

  int64_t ans = 0;
  for (int i = 0; i < n + 1; ++i) {
    int x = n - i * b;
    if (x < 0) continue;
    ans += dp[x];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

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

ll A[200010];
ll B[200010];
ll C[200010];
ll D[200010];
ll E[200010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    for (int i = 0;i < N;i++) {
        cin >> A[i];
    }
    memset(B, 0, sizeof(B));
    memset(C, 0, sizeof(C));
    ll sum = A[0];
    ll pre = 0;
    int c = 0;
    for (int i = 1;i < N;i++) {
        sum += A[i];
        while ((pre + A[c]) * 2 <= sum) {
            pre += A[c];
            c++;
        }
        B[i] = max(B[i], pre);
        B[i] = max(B[i], sum - pre - A[c]);
        D[i] = sum;
    }
    sum = A[N - 1];
    pre = 0;
    c = N - 1;
    for (int i = N - 2;i >= 0;i--) {
        sum += A[i];
        while ((pre + A[c]) * 2 <= sum) {
            pre += A[c];
            c--;
        }
        C[i] = max(C[i], pre);
        C[i] = max(C[i], sum - pre - A[c]);
        E[i] = sum;
    }
    ll sol = 1E9;
    for (int i = 1;i + 2 < N;i++) {
        ll ma = max(D[i] - B[i], E[i + 1] - C[i + 1]);
        ll mi = min(B[i], C[i + 1]);
        sol = min(sol, ma - mi);
    }
    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 8192
def bubbleSort(A, n):
    flag = True
    i = 0
    while flag:
        flag = False
        for j in range (1,n)[::-1]:
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = True
                i += 1
    L=[str(a) for a in A]
    L=" ".join(L)
    print(L)
    print(i)



n = int(input())
A = list(map(int,input().split()))
bubbleSort(A, n)


Measured memory_bytes: 5604
/* ex7_3
   kohei_suzuki */

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

int main(void){
    int row, col; //行数,列数
    int *ture_row, *ture_col; //#の有無を保存するための配列
    char **square; //入力用配列

    scanf("%d %d",&row,&col);//入力受取

    //メモリを動的確保して多次元配列を定義する
    square = (char**)calloc(row, sizeof(char*));
    if(square == NULL){
        printf("memory allocation error.\n");
        exit(1);
    }
    for(int i=0; i<row; i++){
        square[i] = (char*)calloc(col, sizeof(char));
        if(square[i] == NULL){
            printf("memory allocation error.\n");
            exit(1);
        }
    }

    //メモリを動的確保して配列を定義する
    ture_row = (int*)calloc(row, sizeof(int));
    if(ture_row == NULL){
        printf("memory allocation error.\n");
        exit(1);
    }
    
    //メモリを動的確保して配列を定義する
    ture_col = (int*)calloc(col, sizeof(int));
    if(ture_col == NULL){
        printf("memory allocation error.\n");
        exit(1);
    }

    //squareの入力受取
    for(int i=0; i<row ;i++){ 
        for(int j=0; j<col ;j++){
            scanf(" %c",&square[i][j]);
        }
    }
 
    //記録用配列の初期化
    for(int i=0; i<row; i++){ 
        ture_row[i]=0;
    }
    for(int j=0; j<col; j++){
        ture_col[j]=0;
    }

    //#があった行i,列jを記録(true_row[i]=1,true_col[j]=1とする)
    for(int i=0; i<row; i++){
        for(int j=0; j<col; j++){
            if(square[i][j]=='#'){
                ture_row[i]=1;
                ture_col[j]=1;
            }
        }
    }

    //true_row[i]=1かつtrue_col[j]=1ならばsquare[i][j]を出力
    for(int i=0; i<row; i++){
        if(ture_row[i] == 1){
            for(int j=0; j<col; j++){
                if(ture_col[j] == 1){
                    printf("%c",square[i][j]);
                }
            }
            printf("\n"); //行終わりで改行
        }
    }
    return 0;
}

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

int main() {
    long long N;
    cin >> N;
    vector <long long> A(N);
    for (long long i=0; i<N; i++) cin >> A.at(i);
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    N-=2;
    long long ans = A.at(0);
    for (long long i=1; i<=(N/2); i++) {
        ans += 2*A.at(i);
    }
    if (N%2!=0) ans += A.at((N/2)+1);
    cout << ans;
}

Measured memory_bytes: 4836
import sys

MOD = 1000000007

N = int(input())
a = list(map(int,input().split()))

if(N%2 == 0):
    a.sort()
    for i in range(N//2):
        n = 2*i + 1
        if(a[2*i] != n or a[2*i + 1] != n):
            print(0)
            sys.exit()
    print((2 ** (N//2)) % MOD)
else:
    a.sort()
    if(a.count(0) != 1):
        print(0)
        sys.exit()
    for i in range((N-1)//2):
        n = 2*i + 2
        if(a[2*i + 1] != n or a[2*i + 2] != n):
            print(0)
            sys.exit()
    print((2 ** ((N-1)//2)) % MOD)


Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vector<ll> a(n),sum(n+1,0);
	rep(i,n){
		cin>>a[i];
	}
	sort(begin(a),end(a));
	rep(i,n){
		sum[i+1]=sum[i]+a[i];
	}
	auto check=[&](ll x){
		ll cnt=0;
		rep(i,n){
			cnt+=end(a)-lower_bound(begin(a),end(a),x-a[i]);
		}
		return cnt<m;
	};
	ll ok=inf,ng=0,mid;
	while(ok-ng>1){
		mid=(ok+ng)/2;
		if(check(mid)) ok=mid;
		else ng=mid;
	}
	ll ans=0,cnt=0;
	for(int i=n-1;i>=0;i--){
		auto itr=lower_bound(begin(a),end(a),ok-a[i]);
		cnt+=end(a)-itr;
		ans+=a[i]*(end(a)-itr);
		int ind=itr-begin(a);
		ans+=sum[n]-sum[ind];
	}
	ans+=(m-cnt)*ng;
	cout<<ans<<endl;
}

Measured memory_bytes: 1920
N, M = map(int, input().split())
students = [tuple(map(int, input().split())) for _ in range(N)]
checkpoints = [tuple(map(int, input().split())) for _ in range(M)]

for a, b in students:
    min_dist = 10 ** 9
    ans = -1
    for i in range(M):
        c, d = checkpoints[i]
        distance = abs(a - c) + abs(b - d)
        if distance < min_dist:
            min_dist = distance
            ans = i + 1
    print(ans)

Measured memory_bytes: 3064
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static int[] takos=new int[101];
	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		for(int i=0;i<N;i++) {
			takos[i]=sc.nextInt();
		}
		
		long ans=0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				ans+=takos[i]*takos[j];
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
a,b=map(int,input().split())
a+=1
b+=1
s=0
for i in range(1,42):
    k=b-(b//(2**i))*(2**i)
    if k>=2**(i-1):
        x=(b//(2**i))*(2**(i-1))+(k%(2**(i-1)))
    else:
        x=(b//(2**i))*(2**(i-1))
    j=(a-1)-((a-1)//(2**i))*(2**i)
    if j>=2**(i-1):
        y=((a-1)//(2**i))*(2**(i-1))+(j%(2**(i-1)))
    else:
        y=((a-1)//(2**i))*(2**(i-1))
    if x!=0 and (x-y)%2!=0:
        s+=2**(i-1)
print(s)


Measured memory_bytes: 3064
package main

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

var a, b, c, d, answer int

func main() {
	readVariables()
	answer = a * c
	answer = MaxInt(answer, a*d)
	answer = MaxInt(answer, b*c)
	answer = MaxInt(answer, b*d)
	fmt.Println(answer)
}

func readVariables() {
	a = nextInt()
	b = nextInt()
	c = nextInt()
	d = nextInt()
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


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

static const int MAX = 1e+5;
int cnt[MAX+1];

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        cnt[a]++;
        if(a != 0) cnt[a-1]++;
        if(a != n) cnt[a+1]++;
    }
    int ans = 0;
    for(int i = 0; i < MAX; i++){
        ans = max(ans, cnt[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3840
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

#define REP(i,n) for(i=1;i*i<=n;i++)

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int dfs(int v, int n, int *visited, int table[n][n]) {
    int all_visited = 1, i;

    REP(i,n) {
        if (!visited[i]) {
            all_visited = 0;
            break;
        }
    }

    if (all_visited) {
        return 1;
    }

    int count = 0;

    REP(i,n) {
        if (!table[v][i]) continue;
        if (visited[i]) continue;

        visited[i] = 1;
        count += dfs(i, n, visited, table);
        visited[i] = 0;
    }

    return count;
}

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
    long long n = llin(), i, a, b, f, min = 11;
    REP(i,n) {
        if (n % i != 0) continue;
        a = i;
        b = n / a;
        f = max((int)(log10(a) + 1), (int)(log10(b) + 1));
        if (min > f) {
            min = f;
        }
    }
    iout(min);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  map<int, vector<int>> m;
  int n;
  cin>>n;
  vecint v(n+1);
  REP(i,n) {
    cin>>v[i];
  }
  if (v[0] != 0) {
    cout << -1 << endl;
  } else {
    bool ok = true;
    int64_t cnt = 0;
    REP(i,n) {
      if (v[i] >= v[i+1]) {
        if (v[i] > i) {
          ok = false;
          break;
        } else {
          cnt += v[i];
        }
      } else if (v[i] < v[i+1] - 1) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << cnt << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int x = ri();
	for (int i = x; ; i++) {
		bool res = true;
		for (int j = 2; j * j <= i; j++) if (i % j == 0) res = false;
		if (res) {
			std::cout << i << std::endl;
			return 0;
		}
	}
	
	return 0;
}




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

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int i=0;
        while(i<10000)
        {
            int N = cin.nextInt();
            if(N!=0){Console.WriteLine("Case "+(i+1)+": "+N);i++;}
            else if(N==0)break;
            
        }
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

using namespace std;

int main()
{
	vector<int> ant;
	for (int i=0; i<5; i++){
		int x;
		cin>>x;
		ant.push_back(x);
	}
	int k;
	cin>>k;
	if (ant[4]-ant[0]>k) cout<<":(";
	else cout<<"Yay!";
	cout<<endl;
}

Measured memory_bytes: 3440
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize,
        pp: [u32;n]
    }
    let mut m = pp[0];
    let mut cnt = 1;
    for p in pp.into_iter().skip(1) {
        if p < m {
            m = p;
            cnt += 1;
        }
    }
    println!("{}", cnt);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define ll long long
#define lf long double
#define INF 1000000000
#define MAX 200001
#define M 1000000007
using namespace std;
 
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a+b+c >= 22) cout << "bust\n";
    else cout << "win\n";
    return 0;
}

Measured memory_bytes: 256
def solve():
  N, M = map(int, input().split())
  X = [int(i) for i in input().split()]
  if N >= M: return 0
  X.sort()
  diff = [0] * (len(X) - 1)
  for i in range(len(X) - 1):
    diff[i] = X[i + 1] - X[i]
  diff.sort(reverse=True)
  return sum(diff[N - 1:])

print(solve())


Measured memory_bytes: 13200
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

const int MAX=510000;

vll fac(MAX);
vll finv(MAX);
vll inv(MAX);

void combinit(ll m){
    fac[0]=1;fac[1]=1;
    finv[0]=1;finv[1]=1;
    inv[1]=1;
    rep2(i,2,MAX){
        fac[i]=fac[i-1]*i%m;
        inv[i]=m-inv[m%i]*(m/i)%m;
        finv[i]=finv[i-1]*inv[i]%m;
    }
}

ll combi(ll n,ll k,ll m=inf){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%m)%m;
}

ll calculate(ll x,ll y,ll k){
    ll sum=(ll)0,res,tmp;
    for(ll i=1;i<x;i++){
        res=i;res*=(x-i);
        res%=inf;
        res*=y*y;
        res%=inf;
        tmp=x*y-(ll)2;
        tmp%=inf;
        res*=combi(tmp,k-(ll)2);//ペアを一組決めた状態
        res%=inf;
        sum+=res;
    }
    return sum;
}

int main(){
    ll n,m,k;cin>>n>>m>>k;
    combinit(inf);
    ll ans=calculate(n,m,k)+calculate(m,n,k);
    ans%=inf;
    cout<<ans<<endl;
}

Measured memory_bytes: 14936
# -*- coding: utf-8 -*-
from itertools import combinations

line = input().split(" ")
d = int(line[0])
g = int(line[1])

p = []
c = []
for _ in range(d):
    line = input().split(" ")
    p.append(int(line[0]))
    c.append(int(line[1]))

ret = 10000
for sel in range(0,d+1):
    for s in combinations(range(d),sel):
        score = 0
        num = 0
        for si in s:
            score += (si+1)*100*p[si] + c[si]
            num += p[si]
        if score>=g:
            if num<ret:
                ret = num
            continue

        r = set(range(d)) - set(s)
        if len(r)==0:
            continue

        si = max(r)
        for pi in range(p[si]):
            score += (si+1)*100
            num += 1
            if score>=g and num<ret:
                ret = num

print(ret)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    cout << (n / 3) << endl;
    return 0;
}

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


public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	int[] data=new int[3];
    	
    	for(int i=0;i<3;i++) {
    		data[i]=sc.nextInt();
    	}
    	
    	Arrays.sort(data);
    	
    	int result=data[0]+data[1];
    	
    	System.out.println(result);
    	
    	
    	
    }
}


Measured memory_bytes: 23764
S=raw_input()
N=len(S)
c=len(S)/2


if N%2==1:
	cnt=c+1
	for i in range(1,c+1):
		if S[c-i]==S[c+i]==S[c]:
			cnt+=1
			pass
		else:
			break
else:
	cnt=c
	if S[c]!=S[c-1]:
		print cnt
		quit()
	cnt+=1
	for i in range(1,c):
		if S[c+i]==S[c-i-1]==S[c]:
			cnt+=1
		else:
			break

print cnt


Measured memory_bytes: 4228
#include <iostream>
#include <algorithm>
#include<string>

#define CODE_MAX 150

using namespace std;
int main()
{
	string S, T;
	int Scount[CODE_MAX] = {}, Tcount[CODE_MAX] = {};
	int i,length;
	cin >> S >> T;

	length = S.length();
	for (i = 0; i < length; i++) {
		Scount[S[i]]++;
		Tcount[T[i]]++;
	}

	sort(Scount, Scount + CODE_MAX);
	sort(Tcount, Tcount + CODE_MAX);

	bool ans = true;
	for (i = 0; i < CODE_MAX; i++) {
		if (Scount[i] != Tcount[i]) {
			ans = false;
		}
	}

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

	return 0;
}


Measured memory_bytes: 776
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;


int main() {
  int N;
  cin>>N;
  long long total=0;
  long long A;
  long long maxi=-1;
  for(int i=0;i<N;i++){
    cin>>A;
    total+=A;
    if(A>maxi)
      maxi=A;
  }
  cout<<total-(maxi/2);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#define MAXN 100006
#include<cstring>
#include<algorithm>
using namespace std;
int n,a[MAXN],fa[MAXN],root;
char s[MAXN];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
		a[i]=s[i]-'0';
	if(a[1]==0)
	{
		printf("%d",-1);
		return 0;
	}
	for(int i=1;i<=n;i++)
		if(a[i]!=a[n-i])
		{
			printf("-1");
			return 0;
		}
	int m=n/2;
	for(int i=m+1;i<n;i++)
		fa[i]=n;
	root=n;
	for(int i=m;i>=1;i--)
	{
		fa[i]=root;
		if(a[i]==1) root=i;
	}
	for(int i=1;i<n;i++)
		printf("%d %d\n",i,fa[i]);
}

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

#define o(output) cout << output << endl

using namespace std;

string s;
int a,b,c,d;
char A,B;
priority_queue<int,vector<int>,greater<int> >small;

int main(){
  cin >> a >> b >>c;
  if(b>=c) o("delicious");
  else if(a>=abs(b-c)) o("safe");
  else o("dangerous");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

ll n,W;
ll w[110],v[110];
ll dp[110][110000];//iこ目、価値,,,, 重さの最小値
int main(){
  cin>>n>>W;
  rep(i,n){
   cin>>w[i+1]>>v[i+1]; 
  }
rep(i,110){
  rep(j,110000){
    dp[i][j]=inf;
  }
 }
  rep(i,110){
     dp[i][0]=0;
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<110000;j++){
        chmin(dp[i][j],dp[i-1][j]);
    
       if(j-v[i]>=0) chmin(dp[i][j],dp[i-1][j-v[i]]+w[i]);
    }
  }
  ll ans=0;
 // cout<<dp[1][30];
  
    for(ll j=0;j<110000;j++){
      if(dp[n][j]<=W) ans=j; 
    }
    
  
  
  
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 94848
#include "bits/stdc++.h"

using namespace std;

void solve()
{
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<long> acc(n + 1);
    for (int i = 0; i < n; i++)
    {
        acc[i + 1] = acc[i] + (s[i] == 'D');
    }
    while (q--)
    {
        int k;
        cin >> k;
        long ans = 0, sum = 0;
        queue<int> dq;
        for (int i = 0; i < n; i++)
        {
            if (!dq.empty() && dq.front() + k == i)
            {
                sum -= acc[dq.front()];
                dq.pop();
            }
            if (s[i] == 'M')
            {
                dq.push(i);
                sum += acc[i];
            }
            if (s[i] == 'C')
            {
                ans += sum - acc[max(0, i - k + 1)] * dq.size();
            }
        }
        cout << ans << endl;
    }
}

int main()
{
    solve();
    return 0;
}


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

//int main(int argc, char **argv)
int main()
{   
  int a, b, c, x, y, z;  
  //a = stoi(argv[1]);
  //b = stoi(argv[2]);
  //c = stoi(argv[3]);
  cin >> a >> b >> c;
  x = a;
  y = b;
  z = c;
  a = y;
  b = x;
  x = a;
  y = b;
  z = c;
  a = z;
  c = x;

  cout << a << " " << b << " " << c << endl;
  return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<queue>
using namespace std;
int main()
{
    int n,m;
    priority_queue<long long>q;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        long long x;
        cin>>x;
        q.push(x);
    }
    while(m--)
    {
        q.push(q.top()/2);
        q.pop();
    }
    long long sum=0;
    while(!q.empty())
    {
        sum+=q.top();
        q.pop();
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1400
def prepare(n, MOD):
 
    # n! の計算
    f = 1
    fn=[1]*(n+1)
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        fn[m]=f
     
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return fn, invs

def main():
    n,m=map(int,input().split())
    MOD=10**9+7
    fn,invs=prepare(m,MOD)
    ans=0
    for i in range(n+1):
        x=(fn[m-i]*invs[m-n])%MOD
        x=(x*fn[n]*invs[i]*invs[n-i])%MOD
        x*=(-1)**i
        ans+=x
    ans=(ans*fn[m]*invs[m-n])%MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 48504
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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

int main() {
	int n;
	cin >> n;
	int a[n];

	rep(i, n) {
		cin >> a[i];
	}
	sort(&a[0], &a[n]);
	int max_v = a[n - 1];
	int half = -1;
	int half_v = -1;

	rep(i, n) {
		int cur = a[i];
		if (cur > max_v / 2) {
			cur = max_v - a[i];
		}
		if (half < cur) {
			half_v = a[i];
			half = cur;
		}
	}

	cout << max_v << " " << half_v << endl;  




	return 0;
}

Measured memory_bytes: 1016
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
from numba import njit
def main():

    @njit
    def solve(a):
        count = np.zeros(10 ** 6 + 1, np.int32)
        for ae in a:
            if count[ae] <= 1:
                count[::ae] += 1
        r = 0
        for ae in a:
            r += count[ae] == 1
        return r

    a = np.array(read().split(), np.int32)[1:]
    print(solve(a))

if __name__ == '__main__':
    main()


Measured memory_bytes: 122364
#include <bits/stdc++.h>
    using namespace std;
     
    #define N (int)1e5 
    #define pb push_back
    #define ll long long
    #define all(a) a.begin(),a.end()
    #define fri(a) freopen(a,"r",stdin);
    #define fro(a) freopen(a,"w",stdout);
     
    ll dizi[N],dp[N],n;
     
     
    int main(){
    	//fri("in.txt");
    	//fro("out.txt");
    	cin >> n;
    	for(int  i = 0; i < n; i++){
    		cin >> dizi[i];
    	}
    	dp[0] = 0;
    	dp[1] = abs(dizi[1] - dizi[0]);
    	for(int i = 2; i <= n; i++){
    		dp[i] = min(dp[i-1] + abs(dizi[i] - dizi[i-1]), dp[i-2] + abs(dizi[i] - dizi[i-2]));
    	}
    	cout<<dp[n-1]<<endl;
    	return 0;
    }

Measured memory_bytes: 1792
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>

int main()
{
    int64_t N;
    std::cin >> N;

    int64_t n = N - 1;
    std::string name;
    while (n >= 0)
    {
        name.insert(name.begin(), 'a' + n % 26 );
        n = n / 26 - 1;
    }
    std::cout << name << std::endl;

    return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<long> a(N);
  vector<long> b(N);
  for(int i=0;i<N;i++) cin>>a[i]>>b[i];
  long ans=0;
  for(int i=N-1;i>=0;i--){
    if(a[i]%b[i]!=0){
      long res=a[i]%b[i];
      long push=b[i]-res;
      ans+= push;
    }
    if(i>=1) a[i-1]+=ans;
  }
  cout<<ans<<endl;

}


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

int main() {
  int N;
  cin >> N;
  double A[N];
  rep(i, N) { cin >> A[i]; }

  sort(A, A + N);

  double ans;
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      continue;
    };
    if (i == 1) {
      ans = 0.5 * (A[0] + A[1]);
      continue;
    }
    ans = 0.5 * (ans + A[i]);
  }

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

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(105);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (x[i] <= k - x[i]) {
            ans += x[i] * 2;
        }
        else {
            ans += (k - x[i]) * 2;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    string s;
    cin>>s;
    list <char> l;
    for(int i=0;i<s.length();i++)
    {
        l.push_back(s[i]);
    }
    int sig=1;
    int x;cin>>x;
    while(--x>=0)
    {
        int z;cin>>z;
        if(z==1)
        {
            if(sig==1){sig=2;}
            else if(sig==2){sig=1;}
            
        }
        
        if(z==2)
        {
            char c;
            cin>>z>>c;
            if(sig==1)
            {
                if(z==1)
                {
                    l.push_front(c);
                }
                else
                {
                    l.push_back(c);
                }
            }
            
            if(sig==2)
            {
                if(z==2)
                {
                    l.push_front(c);
                }
                else
                {
                    l.push_back(c);
                }
            }
        }
    }
    if(sig==1)
    {
        for(auto i=l.begin();i!=l.end();i++)
        {
            cout<<(*i);
        }
    }
    else if(sig==2)
    {
        for(auto i=--l.end();i!=--l.begin();i--)
        {
            cout<<(*i);
        }
    }
}

Measured memory_bytes: 9984
S = []
for _ in range(3):
	s = list(map(int, input().split()))
	S.append(s)
	
a = [None, None, None]
b = [None, None, None]

a[0] = 0
b[0] = S[0][0] - a[0]
b[1] = S[0][1] - a[0]
b[2] = S[0][2] - a[0]
a[1] = S[1][0] - b[0]
a[2] = S[2][0] - b[0]

yes = 1

for i in range(3):
	for j in range(3):
		if not S[i][j] == a[i] + b[j]:
			yes = 0
			break

if yes:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 38404
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MOD = 1000000007;
const int INF = INT_MAX;



int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;

    ll l, g;
    for (int i=1; i <= a; i++){
        if (a%i == 0 && b%i == 0){
            g = i;
        }
    }

    l = a / g * b;

    cout << l << endl;

    return 0;
}




//              g++ -std=c++1z  

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

int main() {
  int N;
  cin >> N;
  string S, T, U(N*2, ' ');
  cin >> S >> T;
  for (int i = 0; i < N; i++) {
    U[i*2] = S[i];
    U[i*2+1] = T[i];
  }
  cout << U << endl;
  return 0;
}

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

#define int long long

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int p = 1000;
	int q;
	cin >> q;
	if(q%p > 0){
		cout << p - (q % p) << "\n";
	}else{
		cout << 0 << "\n";
	}
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
using namespace std;
#define ForInt(i, n) for (int i = 0; i < (n); ++i)
#define ForIntInit(i, begin, n) for (int i = (begin); i < (n); ++i)
using int64 = long long;



int main()
{
    int l, r;
    cin >> l >> r;

    int min = 2019;
    ForIntInit(i, l, r)
    {
        ForIntInit(j, i + 1, r + 1)
        {
            int m = ((i % 2019) * (j % 2019)) % 2019;
            if (m == 0)
            {
                min = 0;
                goto ModIsZero;
            }
            else if (m < min)
            {
                min = m;
            }
        }
    }
ModIsZero:

    cout << min << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
 
namespace mp = boost::multiprecision;
 
 
 
using ll = long long;
using namespace std;

int main()
{
    mp::cpp_dec_float_100 a, b, c;
    cin >> a >> b >> c;
  	cout << (mp::sqrt(a) + mp::sqrt(b) < mp::sqrt(c) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#define MN 210000
using namespace std;

int n,m,x,y,c[MN<<1],t[MN],a[MN],mmh=0;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (a[i]-t[a[i]]>0) mmh+=(c[a[i]-t[a[i]]]++)==0;
		t[a[i]]++;
	}
	while (m--){
		scanf("%d%d",&x,&y);
		t[a[x]]--;
		if (a[x]-t[a[x]]>0)mmh-=(--c[a[x]-t[a[x]]])==0;
		a[x]=y;
		if (a[x]-t[a[x]]>0)mmh+=(c[a[x]-t[a[x]]]++)==0;
		t[a[x]]++;
		printf("%d\n",n-mmh);
	}
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
const int N=1262145;
int n,f[N],a[N],tot;
int main()
{
	memset(f,7,sizeof(f));
	cin>>n;
	f[0]=0;
	a[++tot]=1;
	for(int x=6;x<=100000;x*=6)
	  a[++tot]=x;
	for(int x=9;x<=100000;x*=9)
	  a[++tot]=x;
	for(int i=0;i<=n;i++){
		for(int j=1;j<=tot;j++)
		  f[i+a[j]]=min(f[i+a[j]],f[i]+1);
	}
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 6016