akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n; cin >> n;
  V a(n);
  rep(i, n) {
    int x; cin >> x;
    --x;
    ++a[x];
  }
  sort(all(a));

  V s(n+1);
  rep(i, n) s[i+1] = s[i] + a[i];

  V f(n+1);
  rep2(x, 1, n+1) {
    int i = lower_bound(all(a), x) - a.begin();
    f[x] = s[i] / x + (n-i);
  }

  V ans(n);
  rep2(i, 1, n+1) chmax(ans[f[i]-1], i);
  drep(i, n-1) chmax(ans[i], ans[i+1]);

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


Measured memory_bytes: 7844
#include <stdio.h>

int main(void){
	int n,i,S[10000],q,j,T[500],C;
	scanf("%d",&n);
	for (i=0;i!=n;i++){
		scanf("%d",&S[i]);
	}
	for (j=0;j!=n;j++){
		for (i=0;i!=n;i++){
			if (S[i]==S[j]){
				if (i!=j){
					S[i]=-100;
				}
			}
		}
	}
	scanf("%d",&q);
	for (j=0;j!=q;j++){
		scanf("%d",&T[j]);
	}
	for (i=0;i!=q;i++){
		for (j=0;j!=q;j++){
			if (S[j]==S[i]){
				if (j!=i){
					S[j]=-10;
				}
			}
		}
	}
	for (C=0,j=0;j!=q;j++){
		for (i=0;i!=n;i++){
			if (S[i]==T[j]){
				C=C+1;
			}
		}
	}
	printf("%d\n",C);
	
	return 0;
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>  // ver2.2.0
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MOD 1000000007  //  10^9 + 7
using namespace std;
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ
 
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}

signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  
  string ss;
  cin >> ss;
  string s;
  VVi z(n,Vi(n));
  
  rep(QW,0,n){
    s = ss.substr(QW);

    z[QW][0] = s.size();
    int i=1,j=0;
    while (i<s.size()) {
      while(i+j<s.size() && s[j]==s[i+j]) j++;
      z[QW][i]=j;
      if(j==0){
        i++;
        continue;
      }
      int k=1;
      while(i+k<s.size() && k+z[QW][k]<j){
        z[QW][i+k] = z[QW][k];
        k++;
      }
      i += k;
      j -= k;
    }
  }
  int ans = 0;
  //VVout(z);
  int l;
  rep(i,0,n){
    rep(j,0,n){
      if(j==0) {l = z[i][j];continue;}
      if(z[i][j]-1 >= j) continue;
      else {
        ans = max(ans,z[i][j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

int n,t;
int a[3252], b[3252];

int dp[3252][3252];
int dp2[3252][3252];

int mx1[3252], mx2[3252];

int main(){
	scanf("%d%d",&n,&t);
	REP(i,n)scanf("%d%d",a+i,b+i);
	fill(dp[0], dp[0]+3252, -(1<<30));
	dp[0][0] = 0;
	REP(i,n){
		fill(dp[i+1], dp[i+1]+3252, -(1<<30));
		REP(j,t){
			CHMAX(dp[i+1][j], dp[i][j]);
			if(j+a[i]<t){
				CHMAX(dp[i+1][j+a[i]], dp[i][j]+b[i]);
			}
		}
	}
	fill(dp2[n], dp2[n]+3252, -(1<<30));
	dp2[n][0] = 0;
	FORR(i,0,n){
		fill(dp2[i], dp2[i]+3252, -(1<<30));
		REP(j,t){
			CHMAX(dp2[i][j], dp2[i+1][j]);
			if(j+a[i]<t){
				CHMAX(dp2[i][j+a[i]], dp2[i+1][j]+b[i]);
			}
		}
	}
	int ans = dp[n][t-1];
	REP(i,n){
		mx1[0] = 0;
		FOR(j,1,t)mx1[j] = max(mx1[j-1], dp[i][j]);
		mx2[0] = 0;
		FOR(j,1,t)mx2[j] = max(mx2[j-1], dp2[i+1][j]);
		REP(u,t)CHMAX(ans, mx1[u] + mx2[t-1-u] + b[i]);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
    int64_t A,B,C,K;
    cin >>A>>B>>C>>K;
    int64_t count=0;
    int64_t sum=0;
    for(int i=0; i<A; i++)
    {
        if(count==K) {break;}
        count++;
        sum++;
    }
    for(int i=0; i<B; i++)
    {
        if(count==K) {break;}
        count++;
    }
    for(int i=0; i<C; i++)
    {
        if(count==K) {break;}
        count++;
        sum--;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3632
using System.Collections.Generic;
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        var aL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        var d = new Dictionary<char, int>();
        var d2 = new Dictionary<int, char>();
        for (int i = 0; i < 26; i++)
        {
            d[aL[i]] = i;
            d2[i] = aL[i];
        }
        while (true)
        {
            var s = Console.ReadLine().Trim();
            if (s == ".") break;
            var ans = getAns(s,d,d2)  ;
            Console.WriteLine(ans);
        }
    }
    static string getAns(string s , Dictionary<char,int> d, Dictionary<int,char> d2)
    {
        var sL = s.Length;
        var st = new Stack<string>();
        var p = 0; var ws = "";
        while (p < sL)
        {
            var w = s[p];
            if (w == '[')
            {
                if (ws != "") { st.Push(ws); ws = ""; st.Push("["); }
                else st.Push("[");
            }
            else if (w == ']')
            {
                while (true)
                {
                    var w2 = st.Pop();
                    if (w2 != "[") { ws = w2 + ws;  }
                    else break;
                }
                st.Push(getRev(ws));
                ws = "";
            }
            else if (w == '?') { st.Push("?"); ws = ""; }
            else if (w == '+' | w == '-') ws += w;
            else
            {
                if (ws == "") st.Push(w.ToString());
                else
                {
                    st.Push(getChar(ws, w, d,d2));
                    ws = "";
                }
            }
            p++;
        }
        var ret = "";
        while (st.Count() > 0) ret = st.Pop() + ret;
        ret = ret.Replace("?", "A");
        return ret;
    }
    static string getChar(string ws, char w, Dictionary<char, int> d, Dictionary<int, char> d2)
    {
        var p = ws.Length - ws.Replace("+", "").Length;
        var m = ws.Length - p;
        var pm = p - m;
        var wn = d[w] + pm;
        while (true)
        {
            if (wn >= 26) wn -= 26;
            else if (wn < 0) wn += 26;
            else break;
        }
        return d2[wn].ToString();
    }
    static string getRev(string s)
    {
        var w = s.ToCharArray();
        Array.Reverse(w);
        return new string(w);
    }
}



Measured memory_bytes: 18556
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

vector<int> make_prime(int N){
  bool p[N+1];
  memset(p, true, sizeof(p));
  p[0] = p[1] = false;
  for(int i = 0 ; i*i < N ; i++){
    if(p[i]){
      for(int j = 2*i ; j < N ; j += i){
	p[j] = false;
      }
    }
  }
  vector<int> ret;
  for(int i = 0 ; i <= N ; i++){
    if(p[i]) ret.push_back(i);
  }
  return ret;
}
 
int main(){
  vector<int> prime = make_prime(100000);
  int m, a, b;
  while(cin >> m >> a >> b, m|a|b){
    double a_b = (double)a / (double)b;
    int max_p = 0;
    int ans1, ans2;
    for(int i = 0 ; i < prime.size() ; i++){
      if(prime[i]*prime[i] > m) break;
      for(int j = i ; j < prime.size() ; j++){
	int M = prime[i]*prime[j];
	if(M > m) break;
	if( (M <= m) && (a_b <= (double)prime[i] / (double)prime[j]) ){
	  if(max_p <= M){
	    max_p = M;
	    ans1 = prime[i], ans2 = prime[j];
	  }
	}
      }
    }
    cout << ans1 << ' ' << ans2 << endl;
  }

  return 0;
}

Measured memory_bytes: 1420
//============================================================================
// Name        : abc145_c.cpp
// Author      : abb
// Version     :
// Copyright   : [My copyright notice]
// Description : test program
//============================================================================

/*
C - Average Length

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 300 点

問題文
座標平面上に N 個の町があります。町 i は、座標 ( x_i , y_i ) に位置しています。町 i と町 j の間の距離は \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2} です。
これらの町を全て 1 回ずつ訪れるとき、町を訪れる経路は全部で N! 通りあります。1 番目に訪れる町から出発し、2 番目に訪れる町、3 番目に訪れる町、\ldots、を経由し、N 番目に訪れる町に到着するまでの移動距離 (町から町への移動は直線移動とします) を、その経路の長さとします。これらの N! 通りの経路の長さの平均値を計算してください。

制約

・2 ≤ N ≤ 8
・-1000 ≤ x_i ≤ 1000
・-1000 ≤ y_i ≤ 1000
・\left(x_i, y_i\right) ≠ \left(x_j, y_j\right) ( i ≠ j のとき)

 */

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

using ll = long long;
using ull = unsigned long long;

#define REP(i, m, n) for (ll i = (m); i < (ll)(n); ++(i))
#define REPM(i, m, n) for (ll i = (m); i <= (ll)(n); ++(i))
#define REPR(i, m, n) for (ll i = (m); i >= (ll)(n); --(i))
#define REPD(i, m, n, d) for (ll i = (m); i < (ll)(n); i += (d))
#define REPMD(i, m, n, d) for (ll i = (m); i <= (ll)(n); i += (d))
#define ALL(x) begin(x), end(x)

/**
 * エントリポイント．
 * @return 0.
 */
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll n;
    double x, y;
    cin >> n;
    vector<pair<double, double>> points(n);
    REP(i, 0, n)
    {
        cin >> x >> y;
        points[i] = {x, y};
    }
    double dx, dy, d, sum;
    REP(i, 0, n - 1)
    {
        pair<double, double> p1 = points[i];
        REP(j, i + 1, n)
        {
            pair<double, double> p2 = points[j];
            // i, j の距離を算出する
            dx = p1.first - p2.first;
            dy = p1.second - p2.second;
            d = sqrt(dx * dx + dy * dy);
            cerr << dx << ", " << dy << "->" << d << endl;
            sum += d;
        }
    }
    // 全経路数 n! のうち，あるエッジを通る経路が選択される確率は，その2つが隣り合う確率
    // つまり (n-1)! * 2! / n! = 2/n
    cout << std::setprecision(12) << sum * 2 / n << endl;
    return 0;
}


Measured memory_bytes: 256
n,m = list(map(int, input().split()))

h = list(map(int, input().split()))

nb = [[]for i in range(n)]
for i in range(m):
    a,b = list(map(int, input().split()))
    a-=1
    b-=1
    nb[a].append(b)
    nb[b].append(a)

ans = 0
#print(nb)
for i in range(n):
    ok = 1
    for j in nb[i]:
        if(h[i]<=h[j]):
            ok = 0
    ans += ok
        
print(ans)


Measured memory_bytes: 92584
num = int(input())
a = list(map(int,input().split()))

cnt = 0
for i in range(num):
    minj = i
    for j in range(i,num):
        if a[j] < a[minj]:
            minj = j
    a[i], a[minj] = a[minj],a[i]
    if i != minj:
        cnt += 1

print(" ".join([str(i) for i in a]))
print(cnt)



Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N;
LL X,D;
typedef pair<LL,LL> P;
vector<P>v[200111];
LL sum[200111];
LL gcd(LL a,LL b){
	if(a>b)return gcd(b,a);
	if(b%a==0)return a;
	return gcd(b%a,a);
}

int main(){
	cin>>N>>X>>D;
	if(X==0&&D==0){
		cout<<1<<endl;
		return 0;
	}
	if(X==0){
		LL ans=(N*(N-1))/2+1;
		cout<<ans<<endl;
		return 0;
	}
	if(D==0){
		cout<<N+1<<endl;
		return 0;
	}
	
	LL Y=gcd(abs(D),abs(X));
	D/=Y;
	X/=Y;
	if(D<0){
		D*=-1;
		X*=-1;
	}
	
	sum[0]=0;
	REP(i,N+1){
		sum[i+1]=(i+1)+sum[i];
	}
	v[0].push_back(P(0,0));
	REP(i,N){
		int j=(i+1)%D;
		LL k=(i+1)/D;
		LL lb=sum[min((LL)i,N-1)];
		LL ub=sum[N-1]-sum[max((LL)0,N-i-2)];
		lb+=(k*X);
		ub+=(k*X);
		v[j].push_back(P(min(lb,ub),max(lb,ub)));
	}
	LL ans=0;
	REP(i,min(D+1,N+1)){
		LL ub=-1e16;
		LL lb=-1e16;
		if(v[i].size()==0)continue;
		sort(v[i].begin(),v[i].end());
		REP(j,v[i].size()){
			P p=v[i][j];
			LL a=p.first;
			LL b=p.second;
			if(ub<a){
				ans+=(ub-lb+1);
				//cout<<i<<" "<<ub<<" "<<lb<<endl;
				lb=a;
				ub=b;
			}else{
				lb=min(lb,a);
				ub=max(ub,b);
			}
		}
		//cout<<i<<" "<<ub<<" "<<lb<<endl;
		ans+=(ub-lb+1);
		ans--;
	}
	
	cout<<ans<<endl;
}

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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,k,s,i;
	cin >> n >> k >> s;
	if(k > 0)
	{
		if(s == (ll)(1e9))
		{
			for(i=1;i<=n-k;++i)
				cout << 1 << " ";
			for(i=1;i<=k;++i)
				cout << s << " ";
		}
		else
		{
			for(i=1;i<=k;++i)
				cout << s << " ";
			for(i=1;i<=n-k;++i)
				cout << s+1 << " ";
		}
	}
	else
	{
		if(s == (ll)(1e9))
		{
			for(i=1;i<=n;++i)
				cout << 1 << " ";
		}
		else
		{
			for(i=1;i<=n;++i)
				cout << s+1 << " ";
		}
	}
	cout << "\n";
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
//bit全探索
int main(){
    string s;
    cin >> s;

    long long ans = 0;
    int n = s.length();
    FOR(i,0,1<<(n-1)){// {0, 1, ..., n-1} の部分集合の全探索
        long long sum = 0;
        long long a = s[0] - '0';
        FOR(j,0,n-1){
            if(i&(1<<j)){// j が i に入るかどうか
                sum += a;
                a = 0;
            }
            a = a * 10 + s[j + 1] - '0';
        }
        sum += a;
        ans += sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
	int main(){
        int A1, A2, A3, A;
                scanf("%d%d%d", &A1, &A2, &A3);
    A = A1 + A2 + A3;
        if(A >= 22){
            printf("bust");
            }
            else{
                printf("win");
            }
    return 0;
    }


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
	char n[9];
	int sum = 0;
	int i = 0;
	int x = 0;
	
	cin >> n;
	
	
	while (n[i] != '\0'){
		x = x * 10 + (n[i] - '0');
		sum += n[i] - '0';
		i++;
	}
	
	if (x % sum == 0){
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}
	return (0);
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void) {

	long long A = 0, B = 0, C = 0, K = 0;
	long long AB = 0, BC = 0, CA = 0;
	long long gate = 0;
	cin >> A >> B >> C >> K;
	int i = 0, ans = 0;
	gate = pow(10,18);
	long long gate2 = pow(10, 9);
	long long ea = 0, eb = 0;

	if (A == B && B == C) {
		cout << 0 << endl;
		return 0;
	}
	//for (i = 0; i < K; ++i) {
	//
	//	ea = A; 
	//	eb = B;
	//	A = B + C;
	//	B = C + ea;
	//	C = ea + eb;

	//	//if (C>gate)break;
	//	

	//}

	if(K % 2 == 0)
	ans = A - B;
	if (K % 2 == 1)
	ans = B - A;

	if (llabs(ans) < gate)
		cout << ans << endl;
	else
		cout << "Unfair" << endl;

	return 0;



}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
using namespace std;
#define N 100009
#define mod 1000000007

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    ll num[2001];
    num[0]=1;
    for (int i=1; i<=2000; i++){
        num[i]=num[i-1]*i;
        num[i]%=mod;
    }
    
    int n,k;
    cin>>n>>k;
    
    if (k<=n-k+1){
        for (int i=1; i<=k; i++){
            ll p=num[n-k-i+1]*num[i];
            p%=mod;
            p*=num[k-i];
            p%=mod;
            p*=num[i-1];
            p%=mod;
        
            ll q=num[n-k+1]*num[k-1];
            q%=mod;
        
            ll r=q*modinv(p,mod);
        
            cout<<r%mod<<endl;
        }
    }
    else{
        for (int i=1; i<=n-k+1; i++){
            ll p=num[n-k-i+1]*num[i];
            p%=mod;
            p*=num[k-i];
            p%=mod;
            p*=num[i-1];
            p%=mod;
        
            ll q=num[n-k+1]*num[k-1];
            q%=mod;
        
            ll r=q*modinv(p,mod);
        
            cout<<r%mod<<endl;
        }
        for (int i=n-k+2; i<=k; i++){
            cout<<"0"<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, a;
map<int, int>mp;

bool tourist() {
	if (mp.size() >= 4)return false;
	if (mp.size() == 3) {
		vector<pair<int, int>>v;
		for (pair<int, int>p : mp) {
			v.push_back(p);
		}
		if ((v[0].first^v[1].first) == v[2].first&&v[0].second == v[1].second&&v[1].second == v[2].second) {
			return true;
		}
		else {
			return false;
		}
	}
	if (mp.size() == 2) {
		if (mp.begin()->first == 0 && mp.begin()->second == N / 3 && N % 3 == 0) {
			return true;
		}
		else {
			return false;
		}
	}
	if (mp.size() == 1 && mp.begin()->first == 0) {
		return true;
	}
	return false;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a;
		++mp[a];
	}
	if (tourist()) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3840
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,avx2,tune=native")
//#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/rope>

using namespace __gnu_pbds; 
using namespace __gnu_cxx;
using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define precision(n) fixed<<setprecision(n)

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("output.txt","w",stderr);
    #endif
}
template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);

clock_t time_p=clock();
void printTime(){
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}


const int N = 2e5 + 5;

int main() {
    io();
    int cnt = 0;
    int d, m;
    cin >> m >> d;
    for(int i = 22; i <= d; i++) {
        int x = i % 10;
        int j = i;
        int y = (j / 10) % 10;
        if(x * y <= m and x * y > 0 and x >= 2 and y >= 2) {
            cnt++;
        }
    }
    cout << cnt;
}




Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			ArrayList<Integer> ar = new ArrayList<>();
			int n = sc.nextInt();
			for(int i = 0; i < 10; i++){
				if( (n & (1 << i)) > 0) ar.add(1<<i);
			}
			System.out.print(ar.get(0));
			for(int i = 1; i < ar.size(); i++) {
				System.out.print(" " + ar.get(i));
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26308
# pypy
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

R, C, K = map(int, readline().split())
rcv = list(map(int, read().split()))
rc2v = {}
for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]):
    rc2v[(rr, cc)] = vv

dp = [[0]*4 for c in range(C+1)]
for r in range(1, R+1):
  for c in range(1, C+1):
    v = rc2v[(r, c)] if (r, c) in rc2v else 0
    dp[c][0] = max(dp[c-1][0], max(dp[c]))
    dp[c][1] = max(dp[c-1][1], dp[c][0] + v)
    for k in range(2, 4):
      dp[c][k] = max(dp[c-1][k], dp[c-1][k-1] + v)

print(max(dp[-1]))

Measured memory_bytes: 162344
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;
int select_second(int a, int b, int c) {
	int ret;
	if (a < b && b < c || c < b && b < a) ret=b;
	else if (b < a&&a < c || c < a&&a < b) ret = a;
	else if (a < c&&c < b || b < c&&c < a)ret = c;
	return ret;
}
int main(void) {
	int n, ans = 0;
	cin >> n;
	vector<int> p(n);
	REP(i, n)cin >> p[i];
	for (int i = 1; i < n-1; i++) {
		int num[3] = { p[i - 1], p[i], p[i + 1] };
		sort(num, num + 3);
		if (num[1] == p[i])ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#define ll  long long
#define endl "\n" 
#define FOR(n) for(int i=0 ; i<n ; i++)
#define FORa(a, n) for(ll i=a ; i<=n ; i++)
ll mod=1000000007;
ll inf=1e9;

int gcd(int a , int b){
  if(a==0) return b;
  return gcd(b%a , a);
}
void solve()
{
  string s;
  cin >> s;
  int n=s.size();
  if(s[n-1]=='s') s+='e' , s+='s';
  else s+='s';
  cout << s << endl;


}

  


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1;
  //cin >> t;
  while(t--)
    solve();
    return 0 ;
}


Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve2(UL *A, UL *ans, UL N) {
		if (N == 1) {
			ans[0] = 0; ans[1] = A[0] + A[1];
			//cout << "A={" << A[0] << "," << A[1] << "},ans={" << ans[0] << " " << ans[1] << "}" << endl;
			return;
		}
		UL S = (1u << (N - 1));
		UL *A1 = A + S, *ans1 = ans + S;
		vector<UL> Abuf(S * 2); rep(i, S * 2) Abuf[i] = A[i];
		vector<UL> Ap(S); rep(i, S) { Ap[i] = A[i] + A1[i]; }
		rep(i, S) { A1[i] = max(A[i], A1[i]); }
		Solve2(A, ans, N - 1);
		Solve2(A1, ans1, N - 1);
		rep(i, S) { ans1[i] = max(ans1[i], Ap[i]); }
		rep(i, S * 2 - 1) ans[i + 1] = max(ans[i + 1], ans[i]);
		//cout << "A={"; rep(i, Abuf.size()) { if (i)cout << ","; cout << Abuf[i]; }
		//cout << "},ans={"; rep(i, S * 2) { if (i)cout << ","; cout << ans[i]; }
		//cout << "}" << endl;
	}

	void Solve() {
		UL N; cin >> N;
		UL S = 1u << N;
		vector<UL> A(S); rep(i, S) cin >> A[i];
		vector<UL> ans(S);
		Solve2(&A[0], &ans[0], N);
		for (UL i = 1; i < S; i++) cout << ans[i] << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 5736
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, a[MAXN], b[MAXN], c[MAXN];
ll t[MAXN * 2];

void update(int k) {
    while (k <= 200000) {
        t[k]++;
        k = k + (k & (-k));
    }
}

ll get(int k) {
    ll res = 0;
    while (k) {
        res += t[k];
        k = k - (k & (-k));
    }
    return res;
}

bool solve(int u) {
    // so median >= u phai >= g
    ll N = (ll) n * (n+1) / 2;
    ll g = N / 2 + N % 2;
    FOR(i,1,n)
        if (a[i] >= u) b[i] = 1;
        else b[i] = -1;
    FOR(i,1,n) c[i] = c[i-1] + b[i];
    int Min = 1000000000;
    FOR(i,0,n) Min = min(Min, c[i]);
    FOR(i,0,n) c[i] -= (Min-1);
    MS(t, 0);
    ll cnt = 0;
    FOR(i,0,n) {
        cnt += get(c[i]);
        update(c[i]);
    }
    return cnt >= g;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    int dau = 1, cuoi = 1000000000, mid;
    while (dau <= cuoi) {
        mid = (dau + cuoi) >> 1;
        if (solve(mid)) dau = mid+1;
        else cuoi = mid-1;
    }
    cout << cuoi;
    return 0;
}

Measured memory_bytes: 2944
# 高さ（h）と幅（w）を定義
h, w = gets.split.map(&:to_i)

# 空の配列を定義
squares = []
for i in 0...h
  boxs = gets.chomp.split("")
  squares << boxs
end

def count_mine(squares, h, w, i, j)
  count = 0
  # 探索する座標を時計回りに定義
  h_dir = [-1, -1, 0, 1, 1, 1, 0, -1]
  w_dir = [0, 1, 1, 1, 0, -1, -1, -1]
  dir_vector = 8
  for k in 0...dir_vector
    count += exist_mine?(squares, h, w, i, j, h_dir[k], w_dir[k])
  end
  return count
end

# 探索対象の座標にmineが存在するか確認する
def exist_mine?(squares, h, w, i, j, h_dir, w_dir)
  i += h_dir
  j += w_dir
  # 配列外の探索を排除する
  unless i < 0 || w <= j || j < 0 || h <= i
    if squares[i][j] == "#"
      return 1
    end
  end
  return 0
end

# 探索
for i in 0...h
  for j in 0...w
    if squares[i][j]!= "#"
      squares[i][j] = count_mine(squares, h, w, i, j)
    end
  end
end

# 探索の終了した配列を出力する
for i in 0...h
  for j in 0...w
    if j == w - 1
      puts squares[i][j]
    else
      print squares[i][j]
    end
  end
end

Measured memory_bytes: 2172
#include <iostream>
#include <cstdio>
#include <complex>

using namespace std;
typedef long long ll;

typedef double R;
typedef complex<R> P;

const R EPS = 1e-10;
const R PI = acos(-1);
int sgn(R a) {
    if (a < -EPS) return -1;
    if (a > EPS) return 1;
    return 0;
}


bool near(P a, P b) {
    return !sgn(abs(a-b));
}

double cross(const P &a, const P &b) { return imag(conj(a)*b); }
double dot(const P &a, const P &b) { return real(conj(a)*b); }

P p[3];
void solve() {
    p[1] -= p[0];
    p[2] -= p[0];
    R ar = arg(p[1]);
    p[2] /= polar(1.0, ar);
    p[2] = conj(p[2]);
    p[2] *= polar(1.0, ar);
    p[2] += p[0];
    printf("%.20lf %.20lf\n", p[2].real(), p[2].imag());
}


int main() {
    while (true) {
        R d[6];
        if (scanf("%lf,%lf,%lf,%lf,%lf,%lf", d, d+1, d+2, d+3, d+4, d+5) <= 0) break;
        p[0] = P(d[0], d[1]);
        p[1] = P(d[2], d[3]);
        p[2] = P(d[4], d[5]);
        solve();
    }
    return 0;
}

Measured memory_bytes: 1292
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int d[100100];
//ll rec(int num) {
//	if (num == 0) return 0;
//	return rec(num - 1) + num;
//}
ll gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll calc(ll b,ll n){
	if (n < b) return n;
	return calc(b, n / b) + n % b;
}

void Solve() {

	int n;
	cin >> n;
	int sum = 0;
	int t[10000];
	fill(t, t + 10000, 0);
	int p = 1;
	while (sum < n)
	{
		t[p] = p;
		sum += p++;
	}

	int v = sum - n;
	t[v] = 0;
	for (size_t i = 0; i < 10000; i++)
	{
		if (t[i] == 0) continue;
		cout << t[i] << endl;
	}
}


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



Measured memory_bytes: 6016
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	static int n, k;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		n = Integer.parseInt(sa[0]);
		k = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		Arrays.parallelSort(a);
		int not = -1;
		int need = n;

		while (Math.abs(need - not) > 1) {
			int mid = (need + not) / 2;
			if (isNeed(a, mid)) {
				need = mid;
			} else {
				not = mid;
			}
		}
		System.out.println(need);
	}

	static boolean isNeed(int[] a, int mid) {
		boolean[][] dp = new boolean[n + 1][k + 1];
		dp[0][0] = true;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= k; j++) {
				dp[i + 1][j] |= dp[i][j];
				if (i != mid && j <= k - a[i]) {
					dp[i + 1][j + a[i]] |= dp[i][j];
				}
			}
		}
		for (int j = Math.max(k - a[mid], 0); j < k; j++) {
			if (dp[n][j]) {
				return true;
			}
		}
		return false;
	}
}


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


int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  vector<int> cnt(4);
  rep(i, n){
    if(s[i] == "AC") cnt[0]++;
    else if(s[i] == "WA") cnt[1]++;
    else if(s[i] == "TLE") cnt[2]++;
    else if(s[i] == "RE") cnt[3]++;
  }
  cout << "AC" << " " << "x" << " " << cnt[0] << endl;
  cout << "WA" << " " << "x" << " " << cnt[1] << endl;
  cout << "TLE" << " " << "x" << " " << cnt[2] << endl;
  cout << "RE" << " " << "x" << " " << cnt[3] << endl;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;
 
int main() {
  int N, K, ans=0;
  int L[60]={0};
  cin >> N >> K;
  for(int i=1; i<=N; ++i){
  cin >> L[i];
  }
  sort(L, L+60, std::greater<>());
  for(int i=0; i<K; ++i){
    ans+=L[i];
  }
  cout << ans << endl;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n,k; cin >> n >> k;
    vector<pll> dt;
    rep(i,n){
        ll t,d; cin >> t >> d;
        dt.emplace_back(d,t);
    }
    sort(rall(dt));

    vi used(n+1, 0);
    priority_queue<ll, vector<ll>, greater<ll>> Q;
    ll y = 0, x = 0;
    rep(i,k){
        ll d = dt[i].fi;
        ll t = dt[i].se;
        if(used[t]){
            Q.push(d);
        }else{
            used[t] = 1;
            x++;
        }
        y += d;
    }

    ll ans = y + x*x;
    REP(i,k,n){
        if(Q.empty()) break;
        ll d = dt[i].fi;
        ll t = dt[i].se;
        if(used[t]){
            continue;
        }else{
            used[t] = 1;
            x++;
        }
        y -= Q.top(); Q.pop();
        y += d;
        ans = max(ans, y + x*x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5820
#include <bits/stdc++.h>
#define MAX 100008
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define forn(a,b,c) for(int a=b;a<c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
int n,k,h[MAX],ans = 0,dp[MAX];
int jump(int idx)
{
    if(idx >= n - 1)
        return 0;
    if(dp[idx] != -1)
        return dp[idx];
    dp[idx] = INT_MAX;
    for(int i = idx; i <= min(idx + k, n - 1); i++)
        dp[idx] = min(dp[idx], abs(h[i] - h[idx]) + jump(i));
    return dp[idx];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    forn(i,0,n)
        cin >> h[i];
    memset(dp, -1, sizeof(dp));
    ans = jump(0);
    cout << ans;
    return 0;
}



Measured memory_bytes: 5760
#include <stdio.h>
int main(){
  int a,b;
  scanf("%d%d", &a, &b);
  if(a > 0){
    puts("Positive");
  }else if(b >= 0){
    puts("Zero");
  }else if((b-a)%2==0){
    puts("Negative");
  }else{
    puts("Positive");
  }
  return 0;
}


Measured memory_bytes: 128
n,k = map(int,input().split())
S = input()
p = S[k-1]
if p == 'A':
  print(S[:k-1]+'a'+S[k:])
elif p == 'B':
  print(S[:k-1]+'b'+S[k:])
else:
  print(S[:k-1]+'c'+S[k:])

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

typedef struct{
	int no;
	double time;
}person;


int main(){
	person p[24];
	double a[8], b[8], c[8], loser[18], f[8];
	
	for(int i=0; i<8; ++i) {
		scanf(" %d %lf", &p[i].no, &p[i].time);
		a[i]=p[i].time;
	}
	for(int i=0; i<8; ++i) {
		scanf(" %d %lf", &p[i+8].no, &p[i+8].time);
		b[i]=p[i+8].time;
	}
	for(int i=0; i<8; ++i) {
		scanf(" %d %lf", &p[i+16].no, &p[i+16].time);
		c[i]=p[i+16].time;
	}
		
	sort(a, a+8);
	f[0]=a[0]; f[1]=a[1];
	sort(b, b+8);
	f[2]=b[0]; f[3]=b[1];
	sort(c, c+8);
	f[4]=c[0]; f[5]=c[1];
	
	//for(int i=0; i<6; ++i) printf("f[%d]=%lf\n", i, f[i]);
	
	for(int i=2; i<8; ++i) loser[i-2]=a[i];
	for(int i=2; i<8; ++i) loser[i-2+6]=b[i];
	for(int i=2; i<8; ++i) loser[i-2+12]=c[i];
	
	sort(loser, loser+16);
	f[6]=loser[0]; f[7]=loser[1];
	
	for(int i=0; i<8; ++i){
		for(int j=0; j<24; ++j){
			if(f[i]==p[j].time){
				printf("%d %.2lf\n", p[j].no, p[j].time);
			}
		}
	}
	
	return 0;
}

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

int main(){
	char x,y,now='A';
	while(scanf("%c,%c",&x,&y)>0){
		if(now==x) now=y;
		else if(now==y) now=x;
	}
	cout<<now<<endl;
	return 0;
}

Measured memory_bytes: 3176
n, m, k = map(int, input().split())

mod = 10**9+7
N = 2*10**5+50
fac = [1]*(N+1)
finv = [1]*(N+1)
for i in range(N):
    fac[i+1] = fac[i] * (i+1) % mod
finv[-1] = pow(fac[-1], mod-2, mod)
for i in reversed(range(N)):
    finv[i] = finv[i+1] * (i+1) % mod

def cmb1(n, r, mod):
    if r <0 or r > n:
        return 0
    r = min(r, n-r)
    return fac[n] * finv[r] * finv[n-r] % mod

ans = 0
for i in range(n*m):
    x, y = divmod(i, m)
    # x
    ans += x*m*cmb1(n*m-2, k-2, mod)*x
    ans -= (n-1-x)*m*cmb1(n*m-2, k-2, mod)*x
    # y
    ans += y*n*cmb1(n*m-2, k-2, mod)*y
    ans -= (m-1-y)*n*cmb1(n*m-2, k-2, mod)*y

ans %= mod
print(ans)


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

int main(){
  vector<int> lookup(26 , 0);
  char temp;
  for(int i=0;i<4;i++){
    cin>>temp;
    lookup[temp -'A']++;
  }
  for(int i=0;i<26;i++){
    if(lookup[i]!=0 && lookup[i]!=2){
      cout<<"No"<<endl;
      return 0 ;
    }
  }
  cout<<"Yes"<<endl;
  
    return 0;
}

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

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree < int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define smallk order_of_key
#define kth find_by_order
*/

#define nl '\n'
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back

typedef long long ll;

const int N = 1e5 + 123;
const int M = 1e9 + 7;
const int K = 500;

int n, W;
long long dp[111][N];
int w[111], p[111];
int main(){

    ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #ifdef LOCAL
      // freopen("A.txt", "r", stdin);
    #endif // LOCAL

    cin >> n >> W;
    for(int i = 1; i <= n; ++i){
        cin >> w[i] >> p[i];
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= W; ++j){
            dp[i][j] = dp[i - 1][j];
            if(w[i] <= j){
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + p[i]);
            }
        }
    }
    cout << dp[n][W];
    return 0;
}


Measured memory_bytes: 79488
# https://atcoder.jp/contests/abc121/tasks/abc121_c

import itertools
import collections
import bisect

def main():
    N, M = map(int, input().split())
    AB = []
    for _ in range(N):
        a, b = map(int, input().split())
        AB.append((a, b))
    AB.sort(key=lambda x:x[0])
    # print(AB)

    ans = 0
    rest = M

    for ab in AB:
        buy_count = min(rest, ab[1])
        ans += ab[0] * buy_count
        rest -= buy_count
        if rest == 0:
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18480
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int K, N, dif_sum=0, max_dif;

    cin >> K >> N;

    vector<int> a(N);

    for(int i=0; i<N; i++)
      cin >> a[i];

    max_dif = K - a[N - 1] + a[0];
    dif_sum = K - a[N - 1] + a[0];

    for(int i=0; i<N-1; i++){
      max_dif = max(max_dif, a[i + 1] - a[i]);
      dif_sum += a[i + 1] - a[i];
    }
    cout << dif_sum - max_dif << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    vector<int> T(N, 0);
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> T[i]; sum += T[i];
    }
    int M; cin >> M;
    for (int i = 0; i < M; ++i) {
        int p, x, out = sum; cin >> p >> x;
        out -= T[p - 1], out += x;
        printf("%d\n", out);
    }
}


Measured memory_bytes: 3668
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Control.Monad

main :: IO ()
main = do
    _ <- getLine
    t <- zip [1..] <$> map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    _ <- getLine
    px <- map ((\[a,b] -> (a,b)) . map (fst . fromJust . BS.readInt) . BS.words) . BS.lines <$> BS.getContents
    let f (p,x) = foldr (\(i,t) j -> if i == p then j+x else j+t)
    forM_ px $ \p -> print $ f p 0 t


Measured memory_bytes: 764
import java.util.*;
public class Main {

	public static void main(String[] args) {
		int p, q, r, quot;
		int c_st, c_ed;
		int count;
		boolean flag;
		Scanner scanner = new Scanner(System.in);
		StringBuffer decimalString = new StringBuffer();
		ArrayList<Integer> remainList = new ArrayList<Integer>();
		
		while (scanner.hasNext()) {
			p = scanner.nextInt();
			q = scanner.nextInt();
			decimalString.setLength(0);
			remainList.clear();
			flag = true;
			c_st = c_ed = 0;
			count = 0;
			r = p;
			
			remainList.add(p);
			
			while (flag && r > 0) {
				count++;
				p *= 10;
				quot = p / q;
				r = p % q;
				p = r;
				decimalString.append(quot);
				
				if (remainList.contains(r)) {
					c_st = remainList.indexOf(r);
					c_ed = count;
					flag = false;
				} else {
					remainList.add(r);
				}
			}
			
			if (flag) {
				System.out.println(decimalString.toString());
			} else {
				System.out.println(decimalString.toString());
				StringBuffer str = new StringBuffer();
				for(int i = 0; i < c_st; i++) {
					str.append(" ");
				}
				for(int i = c_st; i < c_ed; i++) {
					str.append("^");
				}
				System.out.println(str.toString());
			}
		}
	}
}

Measured memory_bytes: 29400
#要素の根を探す関数
def find_root(n,parts):
    n=n-1
    #partsをタプルで返す
    if parts[n][0]==n:
        return tuple(parts[n])
    else:
        return find_root(parts[n][0]+1,parts)

#入力を受け取る
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]

#partsの1つ目は根の番号、2つ目は深さ、3つ目は接続されている要素数
parts=[[i,1,1] for i in range(N)]
ans=[N*(N-1)//2]

#橋の数-1だけ処理を行う（橋が全部かかっているときは不便度0なので）
for i in range(M-1):
    #一番最後に壊れた橋を探す
    ab=AB.pop()
    #それぞれの要素の根を探す
    a=find_root(ab[0],parts)
    b=find_root(ab[1],parts)
    #木構造が深い方をaとする
    if a[1]>=b[1]:
        a,b=a,b
    else:
        b,a=a,b
    #根が同一ならば処理不要
    if a[0]==b[0]:
        ans.append(ans[-1])
    #根が違うのであれば、以後木をくっつける処理を行う
    else:
    #要素x個の木と要素y個の木が繋がれば不便度はxyだけ減る
        ans.append(ans[-1]-a[2]*b[2])
    #bの根にaを接続する
        parts[b[0]][0]=parts[a[0]][0]
    #接続後のaの深さは(aの深さ)と(bの深さ+1)の大きい方
        parts[a[0]][1]=max(parts[a[0]][1],parts[b[0]][1]+1)
    #aの要素数+bの要素数が接続後のaの要素数
        parts[a[0]][2]+=parts[b[0]][2]
#答えを出力
for i in reversed(ans):
    print(i)

Measured memory_bytes: 38180