akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint MOD = 1e9+7;

signed main(){
  lint N, K; cin >> N >> K;
  lint inv = 0;
  vector<lint> a(N);
  for(lint i = 0; i < N; i++) cin >> a[i];
  for(lint i = 0; i < N - 1; i++){
    for(lint j = i + 1; j < N; j++){
      if(a[i] > a[j]) inv++;
    }
  }
  lint ans = 0;
  ans += inv * K;
  ans %= MOD;
  lint inv1 = 0;
  for(lint i = 0; i < N; i++){
    for(lint j = 0; j < N; j++){
      if(a[i] > a[j]) inv1++;
    }
  }
  ans += ((K * (K - 1) / 2) % MOD * inv1) % MOD;
  ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 256
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

x = 1
for i in range(N):
  x = (x*A[i]) // gcd(x, A[i])

ans = 0
for a in A:
  ans += x//a
  #ans %= mod
print(ans%mod)


Measured memory_bytes: 6112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, total;
  cin >> N;
  total = 0;
  
  for(int i = 0;i <= N;i++){
    if(i % 3 != 0 && i % 5 != 0){
    total = total + i;
    } 
  }
  cout << total << endl;
}

Measured memory_bytes: 3636
import math
N = int(input())

div = []
for i in range(1, int(math.sqrt(N))+1):
    if N % i == 0:
        div.append((i, N//i))
ans = 30
for elem in div:
    _, a = elem
    res = len(str(a))
    ans = min(ans, res)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////


int main() {
	ll N;
	cin >> N;
	vll a(N);
	rep(i, N) cin >> a[i];

	vvll dp(N + 1, vll(N + 1, 0));

	repn(x, N) {
		rep(i, N) {
			if (i + x > N) { break; }

			if ((N - x) % 2 == 0) {
				dp[i][i + x] = max(dp[i + 1][i + x] + a[i], dp[i][i + x - 1] + a[i + x - 1]);
			}

			else {
				dp[i][i + x] = min(dp[i + 1][i + x] - a[i], dp[i][i + x - 1] - a[i + x - 1]);
			}
		}
	}

	cout << dp[0][N] << endl;
}

Measured memory_bytes: 73648
s=input()

ym = False
my = False
for i in range(12):
    if int(s[:2]) == (i + 1):
        my = True
    if int(s[2:]) == (i + 1):
        ym = True

if my and ym:
    print('AMBIGUOUS')
elif my:
    print('MMYY')
elif ym:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}

ll fun(ll n)
{
	ll odd_sum=0,even_sum=0;
	while(n)
	{
		ll temp=n%10;
		n/=10;
		if(temp%2)
			odd_sum+=temp;
		else
			even_sum+=temp;
	}
	return abs(odd_sum-even_sum);
}
int main()
{
	fast();
	ll a,b;
	cin>>a>>b;
	cout<<max(0LL,a-2*b);
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
struct unionf{
	vector <int> data;
	unionf(int size):data(size,-1){}
	bool unions(int x,int y){
		x=root(x);y=root(y);
		if(x!=y){
			if(data[y]<data[x]){int d=x;x=y;y=d;}
			data[x]+=data[y];data[y]=x;
		}
		return x!=y;
	}
	bool finds(int x,int y){
		return root(x)==root(y);
	}
	int root(int x){
		return data[x]<0?x:data[x]=root(data[x]);
	}
	int find(int x){
		return -data[x];
	}
};
int main()
{
	vector<pint> v;
	lint n;int m,a,b;
	cin>>n>>m;
	rep(i,m){
		cin>>a>>b;v.pb(mp(a,b));
	}
	reverse(All(v));
	unionf uni(n+10);
	lint out=n*(n-1)/2;
	vector<lint> ret;
	rep(i,m){
		ret.pb(out);
		a=v[i].fi;b=v[i].se;
		if(uni.finds(a,b)) continue;
		out-=(lint)uni.find(uni.root(a))*uni.find(uni.root(b));
		uni.unions(a,b);
	}
	reverse(All(ret));
	rep(i,m) cout<<ret[i]<<endl;
}


Measured memory_bytes: 3444
#include<stdio.h>

int main(){
  int A[100];
  int a,i,j,minj=0,t;
  int N,count=0;

  scanf("%d",&N);
  for(a=0;a<N;a++){
    scanf("%d",&A[a]);
  }
  for(i=0;i<N;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj]) minj = j;     
    }
    if(minj!=i){
    t=A[i];
    A[i]=A[minj];
    A[minj]=t;
    count++;
    }
  }
  for(a=0;a<N-1;a++){
    printf("%d ",A[a]);
  }
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=32e4;

string s[N];
int a[N],r[N];

bool cmp(int x,int y){
	if(s[x]==s[y])return a[x]>a[y];
	return s[x]<s[y];
}
int main(){
	ios::sync_with_stdio(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i]>>a[i];
		r[i]=i;
	}
	sort(r,r+n,cmp);
	for(int i=0;i<n;i++){
		cout<<r[i]+1<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3200
K,S = map(int, input().split())
cnt = 0

for i in range(K+1):
    if i > S:
        break
    if S-i<= K:
        cnt += S-i+1
    else:
        for j in range(K+1):
            if S-i-j<=K:
                cnt += 1
print(cnt)

Measured memory_bytes: 2940
def main(a, b, c, k):
    l = [a, b, c]
    for _ in range(k):
        l[l.index(max(l))] = max(l)*2

    print(sum(l))


if __name__ == "__main__":
    a, b, c = map(int, input().split(' '))
    k = int(input())

    main(a, b, c, k)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {

    int A, B;
    cin >> A >> B;

    if (A >= 13) 
        cout << B << '\n';
    else if (A >= 6)
        cout << B / 2 << '\n';
    else
        cout << 0 << '\n';

}


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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  
  vector<int> A(q);
  for (int i = 0; i < q; i++) {
    cin >> A.at(i);
  }
  
  vector<int> hito(n, k);
  for (int i = 0; i < q; i++) {
    hito.at(A.at(i) - 1)++;
  }
  
  for (int i = 0; i < n; i++) {
    if (hito.at(i) > q) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    int N;
    string mas3[3] = {"a..", "a..", ".aa"};
    string mas4[4] = {"abcc", "abaa", "ccbc", "aabc"};
    string mas5[5] = {"bccbb", "ba..c", "ca..c", "c.aab", "bbccb"};
    string mas7[7] = {"aabbcc.", "dd.dd.a", "..d..da", "..d..db", "dd.dd.b", "..d..dc", "..d..dc"};
    cin >> N;
    vector<string> output(N, string(N, '.'));
    
    if (N == 2) {
        cout << -1 << endl;
        return (0);
    }
    int n = N;
    if (N == 7 || N == 11) {
        for (int i = 0; i < 7; i++) {
            for (int j = 0; j < 7; j++) {
                output[i + N - 7][j + N - 7] = mas7[i][j];
            }
        }
        n = N - 7;
    }
    if (N % 3 == 0) {
        for (int p = 0; p < N; p += 3) {
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    output[p + i][p + j] = mas3[i][j];
                }
            }
        }
        for (int i = 0; i < N; i++) cout << output[i] << endl;
        return (0);
    }

    while (n > 0 && (n & 3)) {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                output[i + n - 5][j + n - 5] = mas5[i][j];
            }
        }
        n -= 5;
    }
    for (int p = 0; p < n; p += 4) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                output[p + i][p + j] = mas4[i][j];
            }
        }
    }
    for (int i = 0; i < N; i++) cout << output[i] << endl;
    return (0);
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int r, g, b;cin >> r >> g >> b;
    cout << ((r*100+g*10+b)%4 == 0 ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
 
int main() {
   char Char[100];
   cin >> Char;
   
   if(strlen(Char)==2){
      cout << Char<<endl;
   }else {
      char RevChar[100];
      RevChar[0]=Char[2];
      RevChar[1]=Char[1];
      RevChar[2]=Char[0];
 
      cout << RevChar << endl;
   }
 
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int N;
  scanf("%d",&N);
  char s[N];
  scanf("%s",s);
  int a,sum=0;
  for(a=0;a<N;a++){
    if(s[a]=='R'){
      sum++;
    }else if(s[a]=='B'){
      sum--;
    }
  }
  if(sum>0){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N, M;
int A[1010], B[1010];
int C[1010101];

int belongs_a(int n)
{
    auto lb = lower_bound(A, A + N, n);
    int i = lb - begin(A);
    if (A[i] == n)
    {
        return i;
    }
    else
    {
        return -1;
    }
}

int greater_num_a(int n)
{
    auto lb = upper_bound(A, A + N, n);
    int i = lb - begin(A);
    return N - i;
}

int belongs_b(int m)
{
    auto lb = lower_bound(B, B + M, m);
    int i = lb - begin(B);
    if (B[i] == m)
    {
        return i;
    }
    else
    {
        return -1;
    }
}

int greater_num_b(int m)
{
    auto lb = upper_bound(B, B + M, m);
    int i = lb - begin(B);
    return M - i;
}

int main()
{
    cin >> N >> M;
    rep(i, 0, N)
    {
        cin >> A[i];
    }
    rep(i, 0, M)
    {
        cin >> B[i];
    }
    sort(A, A + N);
    sort(B, B + M);
    rep(i, 1, N)
    {
        if (A[i - 1] == A[i])
        {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, 1, M)
    {
        if (B[i - 1] == B[i])
        {
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 1;
    for (int i = N * M; i >= 1; i--)
    {
        int ba = belongs_a(i);
        int bb = belongs_b(i);
        if (ba >= 0 && bb >= 0)
        {
            continue;
        }
        else if (ba >= 0)
        {
            ans *= greater_num_b(i);
            ans %= MOD;
        }
        else if (bb >= 0)
        {
            ans *= greater_num_a(i);
            ans %= MOD;
        }
        else
        {
            ll p = greater_num_a(i) * greater_num_b(i) % MOD;
            p = (p - (M * N - i) + MOD) % MOD;
            ans *= p;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

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

signed main(void)
{
	double a, b, t, cnt, time;
	cin >> a >> b >> t;
	cnt = 0;
	time = a;
	while (time < t + 0.5)
	{
		time += a;
		cnt += b;
	}
	cout << cnt << endl;
	return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 998244353;

struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 x) : x(x) {
    if (x > P || x < 0) { cerr << "Invalied FiniteField!" << endl; exit(1); }
  }
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

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

  int n;
  cin >> n;

  vector<FiniteField> factorials(n + 1);
  vector<FiniteField> inverse_factorials(n + 1);

  factorials[0] = inverse_factorials[0] = 1;
  for (int i = 1; i <= n; i++) {
    factorials[i] = factorials[i - 1] * i;
  }
  inverse_factorials[n] = FiniteField(1) / factorials[n];
  for (int i = n; i >= 1; i--) {
    inverse_factorials[i - 1] = inverse_factorials[i] * i;
  }

  vector<FiniteField> two_powers(n + 1);
  two_powers[0] = 1;
  for (int i = 1; i <= n; i++) {
    two_powers[i] = two_powers[i - 1] * 2;
  }

  FiniteField z = 0;
  for (int k = n / 2 + 1; k <= n; k++) {
    z += factorials[n] * inverse_factorials[k] * inverse_factorials[n - k]
        * two_powers[n - k];
  }
  
  FiniteField ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= 3;
  }
  ans -= z * 2;
  cout << ans.Value() << endl;
}

Measured memory_bytes: 234624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
//import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();

		ArrayList<Integer> priceList = new ArrayList<Integer>();

		for (int i= 0; i < N; i++) {
			int p = sc.nextInt();
			priceList.add(p);
		}


		Collections.sort(priceList);

		int anser = 0;
		for (int n = 0; n < K; n++) {
			anser += priceList.get(n);
		}

		System.out.println(anser);
	}

	private static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

	}
}

Measured memory_bytes: 33256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

a = min(X//500, A)
b = min(X//100, B)
c = min(X//50, C)

ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k == X:
                ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 100000000
const int MOD = 1000000007;


int main(){
    /*
    int x;
    cin>>x;
    if(x>=30)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    */
    int n,d;
    cin>>n>>d;
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        double x,y;
        cin>>x>>y;
        double dist = sqrt(x*x+y*y);
        if(dist<=d)
        {
            ans++;
        }
    }

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

Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++)
    cin >> d.at(i);
  sort(d.begin(), d.end());
  int a,b;
  if(n % 2 == 0){
    a = n/2 - 1;
    b = n/2;
  }else{
    a = n/2;
    b = n/2;
  }
  int min = d.at(a);
  int max = d.at(b);
  cout << max - min << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<tuple>
#include<algorithm>
#include<cmath>

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

int main() {
	int A, B;
	cin >> A >> B;
	if (A % 2 != B % 2) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << (A + B) / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
	int K;
	cin>>K;
	printf("%d\n",A[K-1]);
	return 0;
}

Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

S = input()
K = INT()

N = len(S)
numlist = []
count = 1
if N == 1:
    print(K // 2)
else:
    for i in range(1, N):
        if S[i] == S[i - 1]:
            count += 1
        else:
            numlist.append(count)
            count = 1
    numlist.append(count)
    if len(numlist) == 1:
        ans = (N * K) // 2
    elif S[0] == S[-1]:
        center = numlist[0] + numlist[-1]
        ans = (center // 2) * (K - 1)
        ans += numlist[0] // 2
        ans += numlist[-1] // 2
        for i in range(1, len(numlist)-1):
            ans += (numlist[i] // 2) * K
    else:
        ans = 0
        for i in range(len(numlist)):
            ans += (numlist[i] // 2) * K
    print(ans)


Measured memory_bytes: 38384
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  string s;
  string res;
  cin >> s;

  REP(i, s.size()){
    if(s[i] == '0') res.push_back('0');
    if(s[i] == '1') res.push_back('1');
    if(s[i] == 'B' and !res.empty()) res.pop_back();
  }
  cout << res << endl;
  

  return 0;
}



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


int N;


void input() {
    cin >> N;
}


int main() {
    input();
    int ans = N / 2;
    if (N % 2 == 1) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.System.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    List<Integer> list = new ArrayList<Integer>();
    //for(int i=0; i<list.size(); i++)
    //{
    //  System.out.println(list.get(i));
    //}

    while(true)
    {
      int in = sc.nextInt();
      if(in == 0)break;
      list.add(in);
    }
    for(int i=0; i<list.size(); i++)
    {
      out.printf("Case %d: %d\n", i+1, list.get(i));
    }
  }
}


Measured memory_bytes: 61524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  ll a;
  long double b;
  cin >> a >> b;
  cout << (ll)(a * b) << endl;
  return 0;
}


Measured memory_bytes: 3752
INPUT = STDIN.read.split("\n").map{|l| l.split(" ").map{|a| a.to_i}}


def check
    dic = {}
    INPUT.each {|r|
        r.each {|c|
            if dic.key?(c)
                dic[c] = dic[c] + 1
            else
                dic[c] = 1
            end
            if dic[c] >= 3 
                return "NO"
            end
        }
    }
    return "YES"

    check
end

puts check()

Measured memory_bytes: 1788
N = int(input())
H = list(map(int, input().split()))

ans = 0

while any(h>0 for h in H):
  it = 1
  for i in range(N-1):
    if H[i]>0 and H[i+1] <= 0:
      it += 1
  if H[-1]<=0:
    it -= 1
    
  ans += it
  H = [h-1 for h in H]
  
print(ans)

Measured memory_bytes: 3060
N = int(input())
A = [int(input()) for _ in range(N)]

ok = True
pre = -1
for i, a in enumerate(A):
    if a > pre + 1:
        ok = False
        break
    pre = a

if not ok:
    print(-1)
else:
    c = 0
    for i in range(N-1):
        if A[i+1] != A[i] + 1:
            c += A[i+1]
        else:
            c += 1
    print(c)

Measured memory_bytes: 11048
#include <iostream>
using namespace std;
int main()
{
	long long a,b;
	cin>>a>>b;
	long long a1[3];
	a1[1]=a+(a-1);
	a1[2]=a+b;
	a1[3]=b+(b-1);
	if (a1[1]<a1[2])  swap(a1[1],a1[2]);
	if (a1[1]<a1[3])  swap(a1[1],a1[3]);
	cout<<a1[1]<<endl;
	return 0;
 } 

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, z, w;
  cin >> n >> z >> w;
  vector<int> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  if (va.size() == 1) {
    cout << abs(va.front() - w) << '\n';
  } else {
    cout << max(abs(va.back() - w), abs(va[va.size() - 2] - va.back())) << '\n';
  }
}

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

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int n;
 cin>>n;
 int a[n+1];
 int dp[n+1]={0};
 for(int i=1;i<=n;i++)
 {
      cin>>a[i];
 }
 dp[1]=0;
 dp[0]=INT_MAX;
 for(int i=2;i<=n;i++)
 {
      dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
 }
 cout<<dp[n];
 
} 

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

int main() {
pair<string,int> p;
vector<pair<string,int> > v;
while(cin>>p.first>>p.second){
v.push_back(make_pair(p.first,p.second));
}
sort(v.begin(),v.end());

cout<<v[0].first<<endl;
cout<<v[0].second;
string bef=v[0].first;
for (int i = 1; i < v.size(); ++i) {
    if(bef!=v[i].first){
    	cout<<endl;
    	cout<<v[i].first<<endl;
    	cout<<v[i].second;
    	bef=v[i].first;
    }else{
    	cout<<" "<<v[i].second;
    }
}
cout<<endl;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
const ll MAX=1100000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    repl(i,2,MAX){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k)return 0;
    if(n<0 or k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
int main(){
    COMinit();
    ll N,K;cin>>N>>K;
    ll ans=0;
    repl(i,max(1LL,N-K),N+1){
        ans+=COM(N,i)*COM(N-i+i-1,i-1);
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vector<int>> F(N, vector<int>(10)), P(N, vector<int>(11));
  for (int i = 0; i < N; i++) for (int j = 9; j >= 0; j--) cin >> F.at(i).at(j);
  for (int i = 0; i < N; i++) for (int j = 0; j < 11; j++) cin >> P.at(i).at(j);

  int ans = -1e9;

  for (int bit = 1; bit < 1 << 10; bit++) {
    int sum = 0;
    for (int i = 0; i < N; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if (bit >> j & 1 && F.at(i).at(j)) cnt++;
      }
      sum += P.at(i).at(cnt);
    }
    ans = max(ans, sum);
  }

  cout << ans << "\n";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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 T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;


lint D, M, d, q;
lint decrease[26];
lint decrease_sum[26];
lint positive_sum = 0;
lint satis[365][26];
lint last[26];
lint t[365];
lint prv_score = 0;

lint downscore(lint passed) {
	lint sum = 0;
	REP(i, 26) {
		sum += decrease[i] * (passed - last[i]);
	}
	return -sum;
}

lint query(set<lint> app[26], lint d, lint q) {
	lint score = prv_score;
	score += satis[d][q] - satis[d][t[d]];
	score += decrease[q] * decrease_sum[q];
	score += decrease[t[d]] * decrease_sum[t[d]];
	app[t[d]].erase(d);
	app[q].insert(d);

	{
		decrease_sum[t[d]] = 0;
		vector<lint> vec;
		vec.push_back(-1);
		for (auto itr : app[t[d]]) {
			vec.push_back(itr);
		}
		vec.push_back(D);
		REP(j, SZ(vec) - 1) {
			lint k = vec[j + 1] - vec[j] - 1;
			decrease_sum[t[d]] += k * (k + 1) / 2;
		}
	}

	{
		decrease_sum[q] = 0;
		vector<lint> vec;
		vec.push_back(-1);
		for (auto itr : app[q]) {
			vec.push_back(itr);
		}
		vec.push_back(D);
		REP(j, SZ(vec) - 1) {
			lint k = vec[j + 1] - vec[j] - 1;
			decrease_sum[q] += k * (k + 1) / 2;
		}
	}
	score -= decrease[q] * decrease_sum[q];
	score -= decrease[t[d]] * decrease_sum[t[d]];

	app[q].erase(d);
	app[t[d]].insert(d);
	return score;
}


int main() {
	cin >> D;
	REP(i, 26) {
		cin >> decrease[i];
	}
	REP(i, D) {
		REP(j, 26) {
			cin >> satis[i][j];
		}
	}
	set<lint> app[26];
	REP(i, D) {
		cin >> t[i]; t[i]--;
		app[t[i]].insert(i);
	}
	REP(i, D) {
		positive_sum += satis[i][t[i]];
	}
	REP(i, 26) {
		vector<lint> vec;
		vec.push_back(-1);
		for (auto itr : app[i]) {
			vec.push_back(itr);
		}
		vec.push_back(D);
		REP(j, SZ(vec) - 1) {
			lint k = vec[j + 1] - vec[j] - 1;
			decrease_sum[i] += k * (k + 1) / 2;
		}
	}
	prv_score = positive_sum;
	REP(i, 26) prv_score -= decrease[i] * decrease_sum[i];

	cin >> M;
	REP(i, M) {
		cin >> d >> q; d--; q--;
		lint ans = query(app, d, q);
		cout << ans << endl;
		prv_score = ans;
		app[t[d]].erase(d);
		app[q].insert(d);
		t[d] = q;
	}
}


Measured memory_bytes: 3628
A=str(input())
P=[]
for i in range(26):
    p=chr(ord("a")+i)
    P.append(p)

ANS=[]
for i in P:
    if i not in A:
        ANS.append(i)
if len(ANS)==0:
    print("None")
else:
    print(ANS[0])

Measured memory_bytes: 3188
N, T = map(int, input().split())
TL = list(map(int, input().split()))

ans = T

for i in range(1, N):
    if TL[i] - TL[i - 1] > T:
        ans += T
    else:
        ans += TL[i] - TL[i - 1]

print(ans)

Measured memory_bytes: 30728
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
all_selection = 0
count_number = Counter(A)

for k, v in count_number.items():
    all_selection += (v)*(v-1)//2

for i in range(N):
    # A[i]の箇所だけ減ることを考える
    print(all_selection-(count_number[A[i]]-1))


Measured memory_bytes: 26780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n, max;
    cin >> n;
    vector<int> a(n);

    for (int i=0; i<n; i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    max = a.at(n-1) - a.at(0);

    cout << max << endl;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "next", long, "cost");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, m, k;
    scan(n, m, k);
    auto a = aryread();
    auto b = aryread();
    iota(n - 1).each!(x => a[x + 1] += a[x]);
    iota(m - 1).each!(x => b[x + 1] += b[x]);
    a = only(0).array.chain(a).array();
  
    long bseach(long rest)
    {
        long ok = -1, ng = m;
        while (abs(ok - ng) > 1)
        {
            auto mid = (ok + ng) / 2;
            if (b[mid] <= rest)
                ok = mid;
            else
                ng = mid;
        }
        return ok + 1;
    }

    long num;
    (n + 1).iota.each!(x => num = max(num, (a[x] <= k ? x + bseach(k - a[x]) : 0)));
    num.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

inline ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch&15);ch=getchar();}
	return x*f;
}

ll a[4];

int main()
{
	for(ll i=1;i<=3;i++) a[i]=read();
	std::sort(a+1,a+4);
	ll V=a[1]*a[2];
	ll l1=a[3]/2;
	ll l2=a[3]-l1;
	cout<<V*abs(l1-l2)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

ll gcd(ll a,ll b){return b ? gcd(b,a%b) :a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}




    vector<pair<ll,ll>>p;

ll n,m,q;
vector<ll>a,b,c,d;
ll ans=0;
void dfs(vector<ll> v){
    if(v.size()==n){
      ll sum=0;
      rep(i,q)if(v[b[i]]-v[a[i]]==c[i])sum+=d[i];
      ans=max(ans,sum);
      return;
    }
    if(v.size()==0)v.push_back(1);
    v.push_back(v.back());
    dfs(v);
    while(v.back()<m){
        v.back()++;
        dfs(v);
    }
    return;
}


int main()
{
 ll n;
 cin>>n;
 ll cnt=0;
 rep(i,n){
     ll a,b;
     cin>>a>>b;
     if(a==b){
         cnt++;
     }else{
         cnt=0;
     }
     if(cnt==3){
         cout<<"Yes"<<endl;
         return 0;
     }
 }
 cout<<"No"<<endl;
}



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

public class AtCoder
{

    public static int[] ReadArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m));
    }

    public static int ReadInt()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    public static string ReadStr()
    {
        return Console.ReadLine();
    }

    public static long ReadLong()
    {
        return Convert.ToInt64(Console.ReadLine());
    }

    public static long[] ReadLongArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m));

    }


    public static void Main()
    {

        int[] B = ReadArray();

        int n = B[0], maxWeight = B[1];

        long[] dp = new long[maxWeight + 1];

        long ans = int.MinValue;

        for (int i = 0; i < n; i++)
        {
            long[] A = ReadLongArray();

            long w = A[0], v = A[1];

            if (w > maxWeight) continue;

            for (int j = maxWeight; j >= w; j--)
            {
                if (j == w)
                    dp[j] = Math.Max(dp[j], v);
                else if (dp[j - w] > 0)
                    dp[j] = Math.Max(dp[j - w] + v, dp[j]);

                ans = Math.Max(ans, dp[j]);

            }           
        }


        Console.WriteLine(ans);

        
       









    }


}


Measured memory_bytes: 13256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rt return
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n,k;
struct info
{
    int x,v;
}a[maxn];
bool cmp(info one,info two)
{
    return one.v>two.v;
}
int vis[maxn];
stack<int> s;
int main()
{
    scanf("%d %d",&n,&k);
    repd(i,1,n)
    {
        scanf("%d %d",&a[i].x,&a[i].v);
    }
    sort(a+1,a+1+n,cmp);
    ll cnt=0;
    ll tp=0;
    ll res=0;
    ll ans=0ll;
    repd(i,1,n)
    {
        if(cnt<k)
        {
                if(vis[a[i].x]==0)
                {
                    vis[a[i].x]=1;
                    tp++;
                }else
                {
                    s.push(a[i].v);
                }
                res+=a[i].v;
                cnt++;
                ans=max(ans,res+1ll*tp*tp);
        }
        else{
            if(s.empty())
                break;
            if(vis[a[i].x])
                continue;
            vis[a[i].x]=1;
            tp++;
            res-=s.top();
            res+=a[i].v;
            s.pop();
            ans=max(ans,res+tp*tp);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#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--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    int result = (H - h) * (W - w);
    cout << result << endl;
    


    return 0;
}



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

const int maxn = 1e5 + 10;
char s[maxn];

int main() {
    scanf("%s", s);
    int len = strlen(s);
    int cnt0 = 0, cnt1 = 0;
    for (int i = 0; i < len; i++) {
        if (s[i] == '0') cnt0++;
        else cnt1++;
    }
    int ans = cnt0 < cnt1 ? cnt0 : cnt1;
    printf("%d\n", 2 * ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int,int> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=mpowe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}

int main()
{
    fastio();
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    ll n,m;
    cin>>n>>m;
    ll b= max(n,m);
    ll a= min(n,m);
    for(int i=0;i<b;i++)
        cout<<a;
    nl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    while(1){
        string s;
        cin >> s;
        if (s == "-") break;

        ll m;
        cin >> m;
        rep(i,m){
            ll d;
            cin >> d;
            s = s.substr(d) + s.substr(0, d);
        }
        cout << s << endl;
    }
}


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

using namespace __gnu_pbds;
using namespace std;

#define mem(a, b)   memset(a, (b), sizeof(a))

int main(){
    int n,b;
	int a[3][3];
	bool c[3][3]={false};
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	cin>>n;
	for(int k=0;k<n;k++){
		cin>>b;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(a[i][j]==b){
					c[i][j]=true;
				}
			}
		}
	}
	bool ch=false;
	for(int i=0;i<3;i++){
		if(c[0][i]&&c[1][i]&&c[2][i]){
			ch=true;
		}
		if(c[i][0]&&c[i][1]&&c[i][2]){
			ch=true;
		}
	}
	if(c[0][0]&&c[1][1]&&c[2][2]){
		ch=true;
	}
	if(c[2][0]&&c[1][1]&&c[0][2]){
		ch=true;
	}
	if(ch){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
// constexpr ll mod = 1e9 + 7;

int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll ans=0;

    if(A+B>2*C){
        ans+=2*C*min(X,Y);
        int tmp=min(X,Y);
        X=X-tmp;
        Y=Y-tmp;
    }
    ans += X*min(A,2*C);
    ans += Y*min(B,2*C);

    cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  string s;
  cin>>s;
  int ans = 100000;
  int n = s.length();
  for(int i = 0; i <= n-3; i++){
    int a = 100*(s[i]-'0');
    int b = 10*(s[i+1]-'0');
    int c = (s[i+2]-'0');
    int x = a+b+c-753;
    ans = min(ans, abs(x));
  }
  cout<<ans<<endl;
}


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

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    if ( t >= (double)d / s) {
	cout << "Yes" << endl;
    } else {
	cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  int n,count=0;
  string s;
  cin>>n>>s;
  for (int i = 0; i < n-2; i++) {
    if(s[i]=='A'){
      if(s[i+1]=='B'&&s[i+2]=='C'){
        count++;
      }
    }
  }
  cout<<count;
}

Measured memory_bytes: 256