akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n;
    cin >> n;
    map<ll, ll> mp;
    while (n--)
    {
        ll a;
        cin >> a;
        mp[a]++;
    }
    ll W = 0, H = 0;
    for (auto it = rbegin(mp); it != rend(mp); it++)
    {
        ll a = it->first;
        ll ca = it->second;
        if (ca >= 4 && W == 0)
        {
            W = a;
            H = a;
            break;
        }
        if (ca >= 2 && W == 0)
        {
            W = a;
            continue;
        }
        if (ca >= 2 && W != 0)
        {
            H = a;
            break;
        }
    }
    cout << H * W;
    return 0;
}

Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}

const ll mod = 1e9 + 7;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> s(m);
    vector<int> p(m);

    for (int i = 0;i < m;i++){
        int k;
        cin >> k;
        for (int j = 0;j < k;j++){
            int a;
            cin >> a;
            a--;
            s[i].push_back(a);
        }
    }

    for (int i = 0;i < m;i++) cin >> p[i];

    ll rep = 0;

    for (int bit = 0;bit < (1 << n);bit++){
        bool ok = true;
        for (int i = 0;i < m;i++){
           int cnt = 0;
            for (auto v : s[i]){
                if (bit & (1 << v)){
                    cnt++;
                }
            }
            if (cnt % 2 != p[i]) ok = false;
        }
        if (ok) rep++;
    }

    cout << rep << endl;
}

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

int main(){
    int n, m; cin >> n >> m;
    priority_queue<int64_t, vector<int64_t>, greater<>> q;
    vector<pair<int64_t, int>> b(m); int64_t ans = 0;
    for (auto i = 0; i < n; i++) { int a; cin >> a; q.push(a); ans += a; }
    for (auto i = 0; i < m; i++) cin >> b[i].second >> b[i].first;
    sort(b.begin(), b.end(), greater<>());
    for (auto & elm : b) {
        for (auto i = 0; i < elm.second; i++) {
            if(q.empty()) break;
            auto p = q.top(); q.pop();
            if (p < elm.first) ans = ans - p + elm.first;
            else break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5808
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define ll long long
const int N = 1e6 + 10;
using namespace std;

int n,m;
int main() {
  ios::sync_with_stdio(false);
   cin>>n>>m;
   if(m>=n)
       cout<<"Yes";
   else
       cout<<"No";
    return 0;
}

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

int main() {
  int x,y,z;
  char op;
  while (cin >> x >> op >> y,op!='?') {
    switch (op) {
      case '+':
        z=x+y;
        break;
      case '-':
        z=x-y;
        break;
      case '*':
        z=x*y;
        break;
      case '/':
        z=x/y;
        break;
    }
    cout << z << endl;
  }
  return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 5e3+23;
const long long inf = N*2e9;

int p[N], c[N];

void solve() {
  int n, k; scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", p+i), --p[i];
  for (int i = 0; i < n; ++i) scanf("%d", c+i);
  long long ans = -inf;
  for (int i = 0; i < n; ++i) {
    int len = 1;
    long long e = c[i];
    for (int j = p[i]; j != i; j = p[j]) {
      e += c[j];
      ++len;
    }
    long long cur = 0;
    for (int j = i, cnt = 0; cnt < min(k+1, len); j = p[j], ++cnt) {
      cur += c[j];
      if (e > 0) {
	if (cnt < k%len)
	  ans = max(ans, k/len*e+cur);
	else
	  ans = max(ans, (k/len-1)*e+cur);
      } else {
	ans = max(ans, cur);
      }
    }
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

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

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
  i64 A, B, C;
  cin >> A >> B >> C;
  C = max(C - (A - B), (i64)0);
  cout << C << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
	fscanf(STDIN, "%d", $X);

	for ($i = $X; $i < $X*2; $i++) {
      
      $isPrime = true;
      for ($j = 2; $j < $i; $j++) {
        if ($i % $j === 0) {
          $isPrime = false;
          break;
        }
      }
      if ($isPrime) {
        echo ($i);
       	break;
      }
    }
?>

Measured memory_bytes: 3956
N, A = gets.chomp.split.map(&:to_i)
XS = gets.chomp.split.map { |v| v.to_i - A }
M = 3_000
dp = Array.new(N) { Array.new(M * 2, 0) }
dp[0][M] += 1
dp[0][M + XS[0]] += 1
(N - 1).times do |i|
  (M * 2).times do |j|
    dp[i + 1][j] += dp[i][j]
    k = j + XS[i + 1]
    dp[i + 1][k] += dp[i][j] if k >= 0 && k < M * 2
  end
end
puts dp[N - 1][M] - 1


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

int n;
int gcd(int a,int b)
{
  return b==0?a:gcd(b,a%b);
}
int main()
{
    scanf("%d",&n);
    int ans = 0;
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j<=n;j++)
        {
            int temp = gcd(i,j);
            for(int k = 1;k<=n;k++)
            {

                ans+=gcd(k,temp);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int x, n, temp, j, maxi, hasil;
int arr[100001];
int frek[100001];
int main(){
	cin >> n;

	for (int i = 1 ; i<= n; i++){
		cin >> arr[i];
        frek[arr[i]]++;
		if (arr[i] > maxi){
			maxi = arr[i];
		}
	}
	sort(arr+1, arr+1+n);
	for (int i = 0; i <= maxi;i++){
		temp = frek[i] + frek[i-1] + frek[i+1];
		if (temp > hasil){
			hasil = temp;
		}
	} 
	
	cout <<  hasil << endl;	

	return 0;
}


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

const ll MOD = 1000000007;

ll mod_add(ll a, ll b){
    return ((a % MOD) + (b % MOD)) % MOD;
}

ll mod_sub(ll a, ll b){
    return ((a + MOD) - b) % MOD;
}
 
ll mod_mul(ll a, ll b){
    return ((a % MOD) * (b % MOD)) % MOD;
}

ll mod_pow(ll x, ll r){
    if (r == 0) return 1;

    else if (r == 1) return x % MOD;

    else if (r % 2 == 0){
        ll t = mod_pow(x, r/2) % MOD;
        return mod_mul(t, t);
    }

    else{
        ll t = mod_pow(x, r/2) % MOD;
        ll k = mod_mul(t, t);
        return ((k % MOD) * (x % MOD)) % MOD;
    }
}

ll mod_div(ll a, ll b){
    return mod_mul(a, mod_pow(b, MOD - 2));
}

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

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<ll>> bit(n, vector<ll>(66, 0));
    rep(i, n){
        ll num = a[i];
        int base = 0;
        while(num){
            bit[i][base] = num%2;
            num /= 2;
            ++base;
        }
    }

    // rep(i, n){
    //     rep(j, 66) cout << bit[i][j] << " ";
    //     cout << endl;
    // }

    ll res = 0;
    ll base = 0;
    rep(i, 66){
        ll sm = 0;
        rep(j, n){
            sm += bit[j][i];
        }
        ll m = sm*(n-sm) % MOD;
        res = (res+mod_mul(m, mod_pow(2, base))) % MOD;
        ++base;
    }

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 171852
import heapq
n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1), input().split()))
heapq.heapify(a)
for i in range(m):
  d=heapq.heappop(a)*(-1)
  heapq.heappush(a,(-1)*(d//2))
print(-sum(a))

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

int main(){
    string w;
    cin >> w;
    int len = w.size();
    short memo[512]={};
    for(int i = 0; i < len; ++i){
        memo[w[i]] = 1 - memo[w[i]];
    }
    for(int i = 0 ; i < len; ++i){
        if(memo[w[i]]){
            puts("No");
            exit(0);
        }
    }
    puts("Yes");


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<ll,ll> P;
//ll const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

int N;
string s[10000];

int main(){
    cin>>N;
    rep(i,N) cin>>s[i];

    int ans=0;
    int ra=0, lb=0, ba=0;
    rep(i,N){
        if(s[i][0]=='B' && s[i][s[i].size()-1]=='A') ba++;
        else if(s[i][s[i].size()-1]=='A') ra++;
        else if(s[i][0]=='B') lb++;
        rep(j,s[i].size()-1){
            if(s[i][j]=='A' && s[i][j+1]=='B') ans++;
        }
    }

    if(ba>0){
        ans+=ba-1;
        if(ra>0){ans++;ra--;}
        if(lb>0){ans++;lb--;}
    }
    ans+=min(ra,lb);

    cout<<ans<<endl;
}

Measured memory_bytes: 3940
from itertools import product

N = int(input())
F = [[int(i) for i in input().split()] for _ in range(N)]
P = [[int(i) for i in input().split()] for _ in range(N)]

M = -float('inf')
for open in product([0, 1], repeat=10) :
    if sum(open) == 0 :
        continue
        
    ret = 0
    for i in range(N) :
        ret += P[i][sum([F[i][j] & open[j] for j in range(10)])]
    M = max(M, ret)
print(M)

Measured memory_bytes: 42604
#include <stdio.h>

int main(void)
{
	int ap[4];
	int bp[4];
	int as;
	int bs;
	int i;
	
	as = 0;
	bs = 0;
	
	for (i = 0; i < 4; i++){
		scanf("%d", &ap[i]);
		as += ap[i];
	}
	
	for (i = 0; i < 4; i++){
		scanf("%d\n", &bp[i]);
		bs += bp[i];
	}
	
	if (as <= bs){
		printf("%d\n", bs);
	}
	else {
		printf("%d\n", as);
	}
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {

  ll N, K, R, S, P;
  string T;

  cin >> N;
  cin >> K;
  cin >> R;
  cin >> S;
  cin >> P;
  cin >> T;

  vector<ll> v;

  REP(i, 0, N) {
    if (T.substr(i, 1) == "r"){
      v.push_back(P);
    }
    if (T.substr(i, 1) == "s"){
      v.push_back(R);
    }
    if (T.substr(i, 1) == "p"){
      v.push_back(S);
    }
  }

  // i, i+K, i+2K, ...
  ll ans = 0;
  REP(i, 0, K) {
    ll ans_i = 0;
    vector<ll> temp_vec;
    ll j = 0;
    while( i + (j*K) < N  ) {
      temp_vec.push_back(v[i + (j*K)]);
      j++;
    }
    // calc temp_vec
    ll renzoku = 1;
    ans_i += temp_vec[0];
    for (ll k=1; k<(ll)temp_vec.size(); k++) {
      // if (temp_vec[k-1] == temp_vec[k]) {
      if (T.substr(i + (k-1)*K, 1) == T.substr(i + k*K, 1)) {
        renzoku++;
        if (renzoku % 2 == 0) {
          ans_i += 0;
        }
        else {
          ans_i += temp_vec[k];
        }
      }
      else {
        ans_i += temp_vec[k];
        renzoku = 1;
      }
    }
    ans += ans_i;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[21][1<<21];
bool a[21][21];
int N;
int mod=int(1e9)+7;
int target=(1<<21)-1;
ll fun(int idx, int bitmask){
    if(idx==N-1){
        for(int i=0;i<21;i++){
            if(bitmask&(1<<i)){
                if(a[idx][i]) return 1;
            }
        }
        return 0;
    }
    if(dp[idx][bitmask]!=-1) return dp[idx][bitmask];
    ll ans=0;
    for(int i=0;i<21;i++){
        if(bitmask&(1<<i) and a[idx][i]){
            ans+=fun(idx+1,bitmask^(bitmask&(1<<i)))%mod;
        }
    }
    return dp[idx][bitmask]=ans%mod;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(dp,-1,sizeof(dp));
  
    cin>>N;
    int temp;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++)
        {cin>>temp;
        a[i][j]=temp;}
    }
    cout<<fun(0,target)<<"\n";
}


Measured memory_bytes: 344320
# include <bits/stdc++.h>
using namespace std;
int main ()
{
	 int a,b,d;
	 cin>>a>>b;
	 d=a*b;
	 int i;
	 for (i=1;i<=3;++i)
	    if (d*i%2!=0)
		break;
	if (i>3)
	  printf ("No\n");
	else 
	  printf ("Yes\n");
} 

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string s = Console.ReadLine();
		int n = s.Length;
    int answer = 0;

    for(int i = 0; i < n/2; i++)
    {
      if(s[i] != s[n-1-i]) answer++;
    }

		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

int r(){int x;cin>>x;return x;}

void solve() 
{   
    string s,t;cin>>s>>t;
    cout<<t<<s;
}

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


Measured memory_bytes: 256
S = input()
from collections import defaultdict
r_child=defaultdict(int)
l_child=defaultdict(int)
sum_even=0
sum_odd=0
for i in range(len(S)):
    if S[i]=="R":
        if i%2==0:
            sum_even+=1
        else:
            sum_odd+=1
    if S[i]=="L":
        if sum_even!=0 or sum_odd!=0:
            if i%2==0:
                r_child[i]   = sum_even
                r_child[i-1] = sum_odd
            else:
                r_child[i]   = sum_odd
                r_child[i-1] = sum_even
        sum_even=0
        sum_odd=0

sum_even=0
sum_odd=0
for i in reversed(range(len(S))):
    if S[i]=="L":
        if i%2==0:
            sum_even+=1
        else:
            sum_odd+=1
    if S[i]=="R":
        if sum_even!=0 or sum_odd!=0:
            if i%2==0:
                l_child[i]   = sum_even
                l_child[i+1] = sum_odd
            else:
                l_child[i]   = sum_odd
                l_child[i+1] = sum_even
        sum_even=0
        sum_odd=0

for i in range(len(S)):
    print(r_child[i] + l_child[i],end="")
    print(" ",end="")       

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll INF = (1LL<<60);

int main(){

    ll n; cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0;
    ll j = 1;
    rep(i, n){
        if(a[i]!=j) ans++;
        else j++;
    }

    if(ans == n) ans = -1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
    int a,count;
    double buf[50] = {0};

    scanf("%d",&count); //具材を何個入れるか

    //入力を行う
    for(int i = 0; i  < count; i ++){
        scanf("%lf",&buf[i]);
    }
    //小さい順に並び替える
     double tmp = 0;
    for (int i=0; i<count; ++i) {
    for (int j=i+1; j<count; ++j) {
      if (buf[i] > buf[j]) {
        tmp =  buf[i];
        buf[i] = buf[j];
        buf[j] = tmp;
      }
    }
  }
  
    for(int i = 0; i < count-1; i ++){
        buf[i+1] = (double)(buf[i]+buf[i+1])/2;
    }

    printf("%lf\n",buf[count-1]);
    
    
    return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    if (s[2] == s[3] && s[4] == s[5]) {
        Yes;
    } else {
        No;
    }

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

use std::time::Instant;
fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: BTreeSet<_> = (0..n + 1).collect();
    let mut r2: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    let mut cnt = 1;
    while !rems.is_empty() {
        if !r2.is_empty() {
            cnt += 1;
        }
        while let Some(s_idx) = q.pop_front() {
            r2.remove(&s_idx);
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            if let Some(destv) = dests.remove(&s_num) {
                for dest in destv {
                    q.push_back(dest);
                }
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
        if let Some(&r) = r2.iter().next() {
            // q.push_back(r);
            cnt += r;
        }
    }
    if cnt > 1e18 as usize{
        println!("{}", "hoge");
    }
    println!("{}", ans);
}


Measured memory_bytes: 27576
#include <stdio.h>

int exists[100];
int ans;

int main(void){
    int n, d;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &d);
        exists[d-1] = 1;
    }
    for(int i=0; i<100; i++)
        ans += exists[i];
    printf("%d\n", ans);
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in();
    string foo=string(n,'a');
    do{
        cout<<foo<<endl;
        for(int i=foo.length()-1;i>=0;--i){
            bool kuriage=true;
            for(int j=0;j<i;++j)kuriage&=foo[j]<foo[i];
            if(kuriage){
                foo[i]='a';
            }else{
                ++foo[i];
                break;
            }
        }
    }while(foo!=string(n,'a'));
}

Measured memory_bytes: 1536
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var N, ans int
	fmt.Scan(&N)
	d := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&d[i])
	}
	sort.Ints(d)
	ans = d[N/2] - d[N/2-1]
	fmt.Fprintln(wtr, ans)
	_ = wtr.Flush()
}


Measured memory_bytes: 5504
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Fri Dec 28 15:33:41 2018
//
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)

	var hasA, hasB, hasC bool
	for i, _ := range S {
		if S[i] == 'a' {
			hasA = true
		} else if S[i] == 'b' {
			hasB = true
		} else if S[i] == 'c' {
			hasC = true
		}
	}
	if hasA && hasB && hasC {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

typedef long long ll;
const int MAX_N = 200;

int main() {
  int N, L, minAbs = 200, dif = 0;
  std::cin >> N >> L;
  
  int Ls[MAX_N + 1];
  int ans = 0;
  for(int i = 1; i <= N; ++i) {
    Ls[i] = L + i - 1;
    ans += Ls[i];
    if(std::abs(Ls[i]) < minAbs) {
      minAbs = std::abs(Ls[i]);
      dif = Ls[i];
    }
  }
  ans -= dif;

  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] X = new int[N];
        int ans = 1_000_000_000;
        for(int i = 0; i < N; i++){
            X[i] = sc.nextInt();
            int t = 1_000_000_000;
            if(i + 1 >= K){
                if(X[i] <= 0){
                    t = -X[i-K+1];
                }else if(X[i-K+1] < 0 && X[i] > 0){
                    if(-X[i-K+1] < X[i]) t = X[i] - (2*X[i-K+1]);
                    else t = -X[i-K+1] + (2*X[i]);
                }else if(X[i-K+1] >= 0){
                    t = X[i];
                }
            }
            if(t < ans) ans = t;
        }
        sc.close();
        System.out.println(ans);

    }

}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int [n];
        for (int i = 0 ; i < n ; i++) {
            d[i] = sc.nextInt();
        }

        Arrays.sort(d);

        System.out.println(d[n/2] - d[n/2 - 1]);
    }

}


Measured memory_bytes: 49804
use proconio::{fastout, input};
use std::collections::BTreeSet;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let a: BTreeSet<_> = a.iter().collect();
    let ans = if n == a.len() { "YES" } else { "NO" };

    println!("{}", ans);
}


Measured memory_bytes: 8880
package main

import (
	"fmt"
	"math"
)

func logAB(a float64, b float64) float64 {
	return math.Log10(b) / math.Log10(a)
}
func main() {
	// K 進数
	var N, K int
	fmt.Scan(&N, &K)

	d := logAB(float64(K), float64(N)) + 1.
	fmt.Println(int(d))

}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int T = s.nextInt();
        if(T%10==3)
            System.out.println("bon");
        else if(T%10==0||T%10==1||T%10==6||T%10==8)
            System.out.println("pon");
        else
            System.out.println("hon");
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 25344
#include <iostream>
#include <stdio.h>

using namespace std;
int l[200005],r[200005],ans[505][505];
int n,m,Q,p,q;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> Q;
	for(int i = 1;i <= m;++i){
		cin >> l[i] >> r[i];
		ans[1][r[i]]++;ans[l[i] + 1][r[i]]--;
	}
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= n;++j)
			ans[i][j] += ans[i - 1][j] + ans[i][j - 1] - ans[i - 1][j - 1];
	for(int i=1;i<=Q;i++){
		cin >> p >> q;
		cout << ans[p][q] << endl;
	}
	return 0;
}


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

int main() {
  long long int N,n;
  cin >> N;
  //cout << N;
  n=N;

  string s;
  s="zabcdefghijklmnopqrstuvwxyz";

  vector <int> A(100,-1);
  long long int i=0;
  if(N==1){
    cout << 'a' <<endl;
    return 0;
  }
  while(n>0){
    A.at(i)=n%26;
    if(A.at(i)==0){
      n-=26;
    }
    n-=A.at(i);
    n=n/26;
    //cout << A.at(i);

    i++;



  }
  //cout << i << endl;



  for (long long int j=i-1; j>-1; j-- ){

    cout  << s.at(A.at(j));
  }
    cout << endl;

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}
 


 
int main(){
	//in_o();
	int n;
	cin>>n;
	int a[n];
	FOR(i,0,n){
		cin>>a[i];
	}
	int min_so_far=0,min_t=0;
	FOR(i,0,n-1){
		if(a[i]>=a[i+1]){
			min_so_far++;
		}else{
			min_so_far=0;
		}
		min_t=max(min_so_far,min_t);
	}
	cout<<min_t;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>

int main(){
	int a,b;
	scanf("%d %d", &a, &b);
	if(a<b){printf("a < b\n");}
	else if(a==b){printf("a == b\n");}
	else{printf("a > b\n");}
	return 0;
}

Measured memory_bytes: 576
/*
     ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् |
     उर्वारुकमिव बन्धनान्मृत्योर्मुक्षीय माऽमृतात् ||
*/

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

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 1000005;
int a[N], n, m, k;

void solve()
{
     cin >> k >> n;
     int s = 0;
     for (int i = 0; i < n; i++)
          cin >> a[i], s += a[i];

     if (s > k)
          cout << -1;
     else
          cout << k - s;

}

int32_t main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

Measured memory_bytes: 3884
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

N, A, B = map(int, read().split())

def solve(N, A, B):
    if A > B:
        A, B = B, A
    if A == 1:
        return pow(2, N, MOD)
    dp1 = np.zeros((N, B), dtype=np.int64)  # その時点で確定している長さ集計
    dp2 = np.zeros((N, B), dtype=np.int64)  # もし右に十分な 0 があったとしたときの、長さ集計
    dp1_sum = np.zeros(N, dtype=np.int64)
    ans = 0
    for n in range(N):
        # そこで初めての 1 がたつ場合
        if n < A:
            dp1[n, 1] += 1
        else:
            if n + 1 < B:
                dp1[n, n + 1] += 1
        # ひとつ手前から 1 を立てて遷移した場合
        if n > 0:
            dp1[n, 1:] += dp1[n - 1, :-1]
        # 使えない個数の 0 をはさんで遷移した場合
        dp1[n, 1] += dp1_sum[max(0, n - A):n - 1].sum() % MOD
        # たくさんの個数の 0 をはさんで遷移した場合
        if n >= A + 1 < B:
            dp1[n, A + 1:B] += dp2[n - A - 1, 0:B - (A + 1)]
        dp1[n] %= MOD
        # 右を 0 埋めして足せるなら答に足す
        dp1_sum[n] = dp1[n].sum() % MOD
        if (N - n - 1) < A:
            ans += dp1_sum[n]
        else:
            # あと N - n - 1 のびても B にならないような範囲
            M = B - (N - n - 1)
            if M > 0:
                ans += dp1[n, :M].sum() % MOD
        dp2[n] += dp1[n]
        dp2[n, 1:] += dp2[n - 1, :-1]
        dp2[n] %= MOD
    x = pow(2, N, MOD) - ans
    return x % MOD

print(solve(N, A, B))


Measured memory_bytes: 417348
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<"-----------------------------------"<<endl
#define LL long long
#define M 100020
using namespace std;
namespace IO{
	const int BS=(1<<23)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout),OS=OT;}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush();}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}using namespace IO;
int n,m,p[M]; LL s[M],t[2][M];
inline int fd(int num){
	int l=1,r=n,res=n+1,mid;
	while(l<=r){
		mid=((l+r)>>1);
		if(p[mid]>=num) res=mid,r=mid-1;
		else l=mid+1;
	} return res;
}
LL Q(int l,int r,int kd){return r<l?0:(t[kd][r]-t[kd][l-1]);}
LL solve(int num){
	if(num>=p[n-1]) return t[(n&1)^1][n];
	LL l=1,r=num+p[n],t1,t2,mid,dt=0;
	while(l<=r){
		mid=((l+r)>>1);
		t1=fd(num-mid),t2=fd(num+mid+1);
		if(n-(t2-t1)+1>=t2) dt=mid,l=mid+1;
		else r=mid-1;
	}
	int k1=fd(num-dt),k2=fd(num+dt+1),len;
	len=k2-k1; LL now=s[k2-1]-s[k1-1];
	if(k1>1&&k2<=n&&p[k1-1]+p[k2]==num+num&&n-len==k2+1) now-=p[k2],now+=p[k1-1];
	now+=Q(k2,n-len,((n-len)&1)^1);
	
	return now+t[(k1&1)^(max(n-len-k2+1,0)&1)][k1-1];
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),m=read();
	for(int i=1;i<=n;i++){
		s[i]=s[i-1]+(p[i]=read());
		t[0][i]=t[0][i-1],t[1][i]=t[1][i-1];
		t[i&1][i]+=p[i];
	}
	while(m--){
		int x=read();
		printf("%lld\n",s[n]-solve(x));
	}
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int N;
int cnt;
void dfs(vector<int> _A, vector<int> _ans, int i) {
  if(i > N) {
    int tmp = 1;
    REP(j, N) {
      tmp = tmp * _ans[j];
    }
    if(tmp % 2 == 0) cnt++;
    // cout << cnt << endl;
    return;
  }

  for(int k = -1; k <= 1; ++k) {
    _ans.push_back(_A[i] + k);
    dfs(_A, _ans, i + 1);
    _ans.pop_back();
  }
}

int main() {
  cin >> N;
  vector<int> A(N); REP(i, N) cin >> A[i];
  vector<int> ans;
  cnt = 0;
  dfs(A, ans, 0);
  cout << cnt / 3 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
  #define int long long int
    #define endl "\n"
    #define MOD 1000000007
    #define mod 1000000007
    #define M 1000000007
    
    #define pb push_back
    #define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
  //  #define mp make_pair
  #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);  
  #define mx 400005
  #define fiint(a,b) memset(a,b,sizeof(a))  
  #define bitcount __builtin_popcount
  #define fori(i,a,b) for(int i=a;i<b;i++)
  #define ford(i,a,b) for(int i=a;i>=b;i--)
  #define debug(x) cout<<x<<endl;
  #define cases(t) int t; cin>>t; while(t--)
  #define inf1 INT_MAX
  #define all(a) a.begin(),a.end()
  #define vec vector<int>
  #define pii pair<int,int>
  #define plii pair<int,int>
  #define pint pair<int,int>
  #define ff first
  #define ss second
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define sz(x) (int)x.size()
#define PI                    3.14159265359

bool prime[10000001];

void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}

signed  main() 
{ 
	int n;cin>>n;
	vec  dp(n);
	vec a(n);
	fori(i,0,n)
	cin>>a[i];
	dp[ 1 ]= abs(a[1] - a[0]) ;
	fori(i,2,n)
	dp[i] =   min(  dp[i-1] + abs(a[i]-a[i-1]) ,dp[i-2] + abs(a[i]-a[i-2])  ); 
	cout<<dp[n-1]<<endl;
}




 


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
const int mod=1e9+7;
int main(){
    int n;
    cin>>n;
    int power=1;
    long long int finpower=1;
    for(int i=0;i<n;i++){
        finpower*=power;
        finpower=finpower%mod;
        power++;
    }
    cout<<finpower;
}

Measured memory_bytes: 3616
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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

	int N = getint(), K = getint();
	int saidai[100000] = {};
	int shurui = 0;
	int sonota[100001];
	int k = 0;
	rep(i, N) {
		int t = getint() - 1;
		int d = getint();
		if (!saidai[t]) {
			shurui++;
			saidai[t] = d;
		}
		else {
			if (saidai[t] < d) {
				swap(saidai[t], d);
			}
			sonota[k++] = d;
		}
	}

	pakuri_sort(100000, saidai);
	pakuri_sort(k, sonota);

	ll sonota2[100000];
	sonota2[k - 1] = sonota[k - 1];
	for (int i = k - 1; i >= 1; i--) {
		sonota2[i - 1] = sonota2[i] + sonota[i - 1];
	}

	ll kari = 0;
	ll kotae = 0;
	for (int i = 1; i <= min(K, shurui); i++) {
		kari += saidai[100000 - i];
		ll kari2 = kari;
		if (K - i > 0 && 0 <= k - K + i) kari2 += sonota2[k - K + i];
		kari2 += 1ll * i * i;
		kotae = max(kotae, kari2);
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;
class Main{
     public static void main(String[] av){
        Scanner sc=new Scanner(System.in);
        double r=sc.nextDouble();
        double s=r*r*Math.PI;
        double l=r*2*Math.PI;
        System.out.println(String.format("%.6f",s)+" "+String.format("%.6f",l));
    }
}


Measured memory_bytes: 28152
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

template<typename T>void chmax(T &a,T b){a=max(a,b);}
template<typename T>void chmin(T &a,T b){a=min(a,b);}
using namespace std;

void solve(){
	int n;
	cin>>n;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	//ジグザグ
	sort(begin(a),end(a));
	ll sum=0;
	if(n%2==0){
		rep(i,(n-1)/2){
			sum+=2*a[n-1-i];
			sum-=2*a[i];
		}
		sum+=a[n/2];sum-=a[n/2-1];
	}
	else {//nが奇数のときは注意
		rep(i,(n-3)/2)sum+=2*a[n-1-i];
		rep(i,(n-1)/2)sum-=2*a[i];
		sum+=a[n/2+1];sum+=a[n/2];
		ll cmp=0;
		rep(i,(n-1)/2)cmp+=2*a[n-1-i];
		rep(i,(n-3)/2)cmp-=2*a[i];
		cmp-=a[n/2];cmp-=a[n/2-1];
		sum=max(sum,cmp);
	}
	//a1<=a2>=a3...とa1>=a2<=a3...となるものを考える
	cout<<sum<<"\n";
}

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


Measured memory_bytes: 1024
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (310)
#define INF (1LL << 62)

ll mem[MAXN][MAXN][MAXN];
vector<ll> a;
vector<ll> s;
int n, k;
map<int, int> posmap;

ll diff(ll ph, ll h) {
	return max(0LL, h - ph);
}

ll solve(int pos, int used, int phind) {
	if (pos >= n) {
		return 0;
	}
	ll & ret = mem[pos][used][phind];
	if (ret >= 0) {
		return ret;
	}
	ll ph = s[phind];
	ret = diff(ph, a[pos]) + solve(pos + 1, used, posmap[a[pos]]);
	if (used < k) {
		ret = min(ret, solve(pos + 1, used + 1, posmap[ph]));
	//	for (int i = 0; i < s.size(); i++) {
	//		ll cur = diff(ph, s[i]) + solve(pos + 1, used + 1, i); 
	//		ret = min(ret, cur);
	//	}
	}
	return ret;
}

int main() {
//	freopen("input.txt", "r", stdin);
	memset(mem, -1, sizeof(mem));
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a.push_back(t);
	}
	s = a;
	s.push_back(0);
	sort(s.begin(), s.end());
	for (int i = 0; i < s.size(); i++) {
		posmap[s[i]] = i;
	}
	cout << solve(0, 0, 0);
	return 0;
}


Measured memory_bytes: 236404
from collections import Counter
n = int(input())
s = input()
c = Counter(s)
ans = c['R'] * c['G'] * c['B']
for i in range(n):
    for j in range(i, n):
        k = j + (j - i)
        if k < n:
            if s[i] == s[j]: continue
            if s[i] == s[k]: continue
            if s[k] == s[j]: continue
            ans -= 1
print(ans)


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

int main() {
  int a, b;
  cin >> a >> b;

  if(a > b){
    for(int i = 0; i < a; i++){
      cout << b;
    }
  }
  else if(b >= a){
    for(int i = 0; i < b; i++){
      cout << a;
    }
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX 1000005
 typedef struct  d{
  char name[11];
  int time;
  char sname[11];
  int stime;
  char Ansname[11];
  int Anstime;
}date;
 date tn[MAX];
 
int main(){
  int n,q,i,str,tmp,tmp2,j,k=0;
  scanf("%d%d",&n,&q);

  for(i=1;i<n+1;i++){
    scanf("%s ",tn[i].name);
     scanf("%d",&tn[i].time);
  }
  tmp2=n+1;
  i=1;
  while(1){
   
    tn[i].stime=(tn[i].time-q);
    if(tn[i].stime>0){
       
     
      tn[tmp2].time=tn[i].stime;
      strcpy(tn[i].sname,tn[i].name);
      strcpy(tn[tmp2].name,tn[i].sname);
      str+=q;
      if(tmp2==n+1){
	tmp2=1;
      }
      else{
	tmp2++;
      }
      if(i==n+1){
	i=1;
      }
      else{
	i++;
      }
      
    }
    else{
     
      str+=tn[i].time;
      tn[k].Anstime=str;
      tn[i].time=0;
      strcpy(tn[k].Ansname,tn[i].name);
      k++;
      strcpy ( tn[i].name," ");
      if(i==n+1){
	i=1;
      }
      else{
	i++;
      }
    }
    if(k==n){
      break;
    }

  }
  for(j=0;j<n;j++){
    printf("%s %d\n",tn[j].Ansname,tn[j].Anstime);
  }
  return 0;
}



Measured memory_bytes: 4092
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
    	//System.out.println("数字を入力してください");
    	Scanner sc = new Scanner(System.in);
    	int i = Integer.parseInt(sc.next());

    	int h=i/3600;
    	int a=i%3600;
    	int m=a/60;
    	int s=a%60;
    	System.out.println(h+":"+m+":"+s);
    }
}



Measured memory_bytes: 26112
def search_min_route(d,n_list,m_list):
	result = 0
	n_list.sort()
	n_list.append(d)
	for m in m_list:
		result += bs_min(n_list,m)

	return result

def bs_min(n_list,m):
	left = 0
	right = len(n_list)-1
	count = 0
	while abs(right - left) != 1:
		mid = int((right - left)/2 + left)
		if n_list[mid] == m:
			return 0
		elif n_list[mid] > m:
			right = mid
		else:
			left = mid
		count += 1

	return min(abs(n_list[left]-m),abs(n_list[right]-m))


def main():
	#データの入力
	data_list = []
	d = int(input())
	while d != 0:
		n = int(input())
		m = int(input())
		n_list = []
		m_list = []
		n_list.append(0)
		for i in range(n-1):
			n_list.append(int(input()))

		for i in range(m):
			m_list.append(int(input()))

		new_list = [d,n,m,n_list,m_list]
		data_list.append(new_list)
		d = int(input())

	for data in data_list:
		print(search_min_route(data[0],data[3],data[4]))
		
		
if __name__ == '__main__':
	main()


Measured memory_bytes: 11088
n = int (input())

xy = []

def dist(a, b):
    return abs(a[0]-b[0]) + abs(a[1]-b[1])
    
for i in range(n):
    x, y = map(int,input().split())
    xy.append([x+y, x-y])

xy.sort(key = lambda x: x[0])

min_z = xy[0][0]
max_z = xy[-1][0]

xy.sort(key = lambda x: x[1])

min_w = xy[0][1]
max_w = xy[-1][1]

print(max(abs(min_z - max_z), abs(min_w - max_w)))


Measured memory_bytes: 42324
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll ans[6010]= {0};
    int x,y,z,n,fir,i,j,k;
    ll a[1010],b[1010],c[1010];

    scanf("%d%d%d%d",&x,&y,&z,&n);
    for(i=0; i<x; i++)
        scanf("%lld",&a[i]);
    for(i=0; i<y; i++)
        scanf("%lld",&b[i]);
    for(i=0; i<z; i++)
        scanf("%lld",&c[i]);
    sort(a,a+x);
    sort(b,b+y);
    sort(c,c+z);
    fir=0;
    for(i=x-1; i>=0; i--)
    {
        for(j=y-1; j>=0; j--)
        {

            for(k=z-1; k>=0; k--)
            {
                ans[fir]=a[i]+b[j]+c[k];
                if(ans[fir]<=ans[n])
                    break;
                else fir++;
                if(fir==n)
                {
                    sort(ans,ans+2*n);
                    fir=0;
                }
            }

        }
    }
    sort(ans,ans+2*n);
    for(i=2*n-1; i>=n; i--)
        printf("%lld\n",ans[i]);
    return 0;
}



Measured memory_bytes: 384