akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

int mod = 1e9+7;

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() {
  int N, K;
  cin >> N >> K;
  vector<int> ans(K);
  int R = N - K;
  if (R == 0) {
    rep(i, 0, K) {
      if (i == 0) cout << 1 << endl;
      else cout << 0 << endl;
    }
    return 0;
  } else {
    rep(i, 0, K) {
      if (i == 0) {
        cout << (R + 1) % mod << endl;
        continue;
      }
      int I = i + 1;
      if (R < I - 1) {
        cout << 0 << endl;
        continue;
      }
      // if (R == I - 1) {
      //   ll ans = 1;
      //   rep(j, K - I + 1, K) {
      //     ans *= j;
      //     ans = (ans % mod);
      //   }
      //   rep(j, 1, I) {
      //     ans = ans * modinv(j, mod) % mod;
      //   }
      //   cout << ans << endl;
      //   continue;
      // }
      ll ans = 1;
      rep(j, K - I + 1, K) {
        ans *= j;
        ans = (ans % mod);
      }
      rep(j, 1, I) {
        ans = ans * modinv(j, mod) % mod;
      }
      rep(j, I + 1, R + 2) {
        ans *= j;
        ans = (ans % mod);
      }
      rep(j, 1, R - I + 2) {
        ans = ans * modinv(j, mod) % mod;
      }
      cout << ans << endl;
    }
  }
};


Measured memory_bytes: 256
import sys
import bisect
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()

    cor_v = -1
    inc_v = a[-1] * 2 + 1
    while - cor_v + inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        p = n
        for v in a:
            p = bisect.bisect_left(a, bin_v - v, 0, p)
            cost += n - p
            if cost > m:
                break
        #costが制約を満たすか
        if cost >= m:
            cor_v = bin_v
        else:
            inc_v = bin_v
    acm = [0] + list(itertools.accumulate(a))
    c = 0
    t = 0
    for v in a:
        p = bisect.bisect_left(a, cor_v - v)
        c += n - p
        t += acm[-1] - acm[p] + v * (n - p)
    print(t - (c - m) * cor_v)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 54384
#include<bits/stdc++.h>
#define ll             long long int
#define lb             lower_bound
#define ub             upper_bound
#define fi             first
#define mp             make_pair
#define vll            vector<ll>
#define se             second
#define sz             size()
#define mod            1000000007
#define endl           "\n"
#define fast           ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define allr(v)        v.rbegin(),v.rend()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
               const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.second >b.second);
    }
    else
        return (a.fi<b.fi);
}

int main()
{
     fast;
     int q=1;
     //cin>>q;
     while(q--)
     {
       ll n,i,j,k,l,m,sum=0,ans=0,b=0,e;
      ll a;
       cin>>a;
       cout<<a+a*a+a*a*a<<endl;



    }
   return 0;
}


Measured memory_bytes: 3624
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.NoSuchElementException;

public class Main {

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

		int n = sc.nextInt();
		int[] a = sc.nextIntArray(n);

		HashMap<Integer, Integer> hm = new HashMap<>();
		for (int i = 0; i < a.length; i++) {
			if (!hm.containsKey(a[i])) {
				hm.put(a[i], 0);
			}
			hm.put(a[i], hm.get(a[i]) + 1);
		}

		int ans = 0;
		for (Entry<Integer, Integer> e : hm.entrySet()) {
			if (e.getValue() >= e.getKey()) {
				ans += e.getValue() - e.getKey();
			} else {
				ans += e.getValue();
			}
		}

		out.println(ans);
		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) return true;
		else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) return false;
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) return buffer[ptr++];
		return -1;
	}

	private boolean isPrintableChar(byte c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		if (!hasNext()) throw new NoSuchElementException();
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}

	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}
}

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

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

const int MOD = 1e9 + 7;

void solve()
{
    string s;
    cin >> s;
    akari<int> dp(2);
    dp[0] = 1;
    for (char c : s)
    {
        akari<int> nx(2);
        if (c == '1')
        {
            nx[0] = (dp[0] * 2L) % MOD;
            nx[1] = (dp[0] + dp[1] * 3L) % MOD;
        }
        else
        {
            nx[0] = dp[0];
            nx[1] = (dp[1] * 3L) % MOD;
        }
        swap(dp, nx);
    }
    cout << (dp[0] + dp[1]) % MOD << endl;
}

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


Measured memory_bytes: 512
#include <iostream>
#include <string.h>
using namespace std;

int main() {
		long n;
		char s[100000];
		bool sb[100000];
		bool animal[4][100000];

		cin >> n >> s;
		for (int a = 0; a < n; a++) {
				if (s[a] == 'o') sb[a] = 1;
				else sb[a] = 0;
		}
		animal[0][0] = 1; animal[0][1] = 1;
		animal[1][0] = 1; animal[1][1] = 0;
		animal[2][0] = 0; animal[2][1] = 1;
		animal[3][0] = 0; animal[3][1] = 0;

		for (int i = 0; i < 4; i++) {
				if (!(animal[i][0] ^ sb[0])) animal[i][n - 1] = animal[i][1];
				else animal[i][n - 1] = !animal[i][1];
				for (int j = 1; j < n - 2; j++) {
						if (!(animal[i][j] ^ sb[j])) animal[i][j + 1] = animal[i][j - 1];
						else animal[i][j + 1] = !animal[i][j - 1];
				}

				if ((!(animal[i][n - 2] ^ sb[n - 2]) == (animal[i][n - 3] == animal[i][n - 1])) &&
					(!(animal[i][n - 1] ^ sb[n - 1]) == (animal[i][n - 2] == animal[i][0]))) {
						// 条件に当てはまる場合 S, W を出力
						for (int k = 0; k < n; k++) {
								if (animal[i][k]) cout << "S";
								else cout << "W";
						}
						cout << endl;
						return 0;
				}
				}
				//条件に当てはまるものがない場合 -1を出力
				cout << -1 << endl;
				return 0;

}

Measured memory_bytes: 896
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (N, L) = get!(i32, i32);
    let mut sum = 0;
    let mut skipped = false;
    for aji in L..(L+N) {
        if !skipped {
            if aji > 0 {
                skipped = true;
                continue;
            } else if aji == 0 {
                skipped = true;
                continue;
            } else if aji == L+N-1 {
                skipped = true;
                continue;
            }
        }
        sum += aji;
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lowbit(x) x&-x
#define pb push_back
#define MP make_pair
#define clr(a) memset(a,0,sizeof(a))
#define INF(a) memset(a,0x3f,sizeof(a))
#define FIN freopen("in.txt","r",stdin)
#define fuck(x) cout<<"["<<x<<"]"<<endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>pii;
typedef pair<ll, ll>pll;
typedef vector<int> VI;
//head
const int MX = 5e5 + 7;
const int inf = 0x3f3f3f3f;

int n, k;
char s[MX], t[MX];
int dp[MX], sum[MX];
struct Queue {
    pii a[MX];
    int s, t;
    void init() {
        s = 1; t = 0;
    }
    void update(int pos, int val) {
        while (s <= t && val < a[t].se) t--;
        a[++t] = MP(pos, val);
        while (s <= t && a[t].fi - a[s].fi >= k) s++;
    }
    int query() {
        if (s > t) return inf;
        return a[s].se;
    }
} q;

int main() {
    // FIN;
    scanf("%d%d", &n, &k);
    scanf("%s%s", s + 1, t + 1);
    t[0] = '*';
    for (int i = 1; i <= n; i++)
        sum[i] = sum[i - 1] + (t[i] != t[i - 1]);
    q.init();
    dp[0] = 0; q.update(0, 2 * dp[0] - sum[1]);
    for (int i = 1; i <= n; i++) {
        dp[i] = inf;
        if (s[i] == t[i]) {
            dp[i] = dp[i - 1];
            q.update(i, 2 * dp[i] - sum[i + 1]);
            continue;
        }
        // cout << i << " " << q.query() << " " << sum[i]  << endl;
        dp[i] = min(dp[i], (q.query() + sum[i] + 3) / 2);
        q.update(i, 2 * dp[i] - sum[i + 1]);
    }
    printf("%d\n", dp[n]);
    return 0;
}


Measured memory_bytes: 12004
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N),b(N);
    REP(i,N){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(ALL(b));

    REP(i,N){
        if(a[i]<=b[N/2-1])
            cout<<b[N/2]<<endl;
        else
            cout<<b[N/2-1]<<endl;
    }

}


Measured memory_bytes: 5376
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long llint;
typedef long double ldouble;
// int compare(const void *a, const void *b){return *(llint *)a - *(llint *)b;}
typedef struct{
    llint aa;// p
    llint bb;// y 
    llint cc;// city number
    llint id;
}frequent;
int cmp1( const void *p, const void *q ){
    return ((frequent*)p)->aa - ((frequent*)q)->aa == 0 ? ((frequent*)p)->bb - ((frequent*)q)->bb : ((frequent*)p)->aa - ((frequent*)q)->aa;
}
int cmp2( const void *p, const void *q ){
    return ((frequent*)p)->cc - ((frequent*)q)->cc;
}


int main(void){
    llint n,m,i;
    scanf("%lld%lld",&n,&m);
    frequent city[m];
    for(i=0;i<m;i++){
        scanf("%lld",&city[i].aa);
        scanf("%lld",&city[i].bb);
        city[i].cc = i;
    }
    qsort(city,m,sizeof(frequent),cmp1);
    // for(i=0;i<m;i++){
    //     printf("%lld\n",city[i].bb);
    // }
    for(i=0;i<m;i++){
        if(i==0){
            city[i].id = city[i].aa*pow(10,6)+1;
            continue;
        }
        if(city[i].aa == city[i-1].aa){
            city[i].id = city[i-1].id + 1;
        }else{
            city[i].id = city[i].aa*pow(10,6)+1;
        }
        // printf("%lld\n",city[i].id);
    }
    qsort(city,m,sizeof(frequent),cmp2);
    for(i=0;i<m;i++){
        printf("%012lld\n",city[i].id);
    }



    // printf("\n");
    return 0;
}


Measured memory_bytes: 7748
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int X;
    cin >> X;
    int ans = 0;
    for (int b = 1; b <= 100; b++) {
        for (int p = 2; p <= 10; p++) {
            if (pow(b,p) <= X) {
                if (ans < pow(b,p)) ans = pow(b,p);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
  char A,B,C,D;
  cin>>A>>B>>C>>D;
  int a = A - '0';
  int b = B - '0';
  int c = C - '0';
  int d = D - '0';
  if(a+b+c+d==7) {
    cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<'='<<7;
  }
  else if(a+b+c-d==7) {
    cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<'='<<7;
  }
  else if(a+b-c+d==7) {
    cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<'='<<7;
  }
  else if(a+b-c-d==7) {
    cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<'='<<7;
  }
  else if(a-b+c+d==7) {
    cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<'='<<7;
  }
  else if(a-b+c-d==7) {
    cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<'='<<7;
  }
  else if(a-b-c+d==7) {
    cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<'='<<7;
  }
  else if(a-b-c-d==7) {
    cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<'='<<7;
  }
}

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

int main(){
	int n, k, q;
  	cin >> n >> k >> q;
  	vector<int> a(n);
  	rep(i, q){
      	int res;
      	cin >> res;
      	res--;
 		a[res]++;
    }
  	
  	rep(i, n){
      	if(k-q+a[i] > 0) cout << "Yes" << endl;
  		else cout << "No" << endl;
   	}
}

Measured memory_bytes: 3760
#include<stdio.h>

#define N 100 
#define BLACK 1
#define GRAY  2
#define WHITE 3
 
int G[N][N],d[N],f[N],color[N];
int n,time;

 void visit(int r){
  int v;
 
  color[r]=GRAY;
  time++;
  d[r]=time;
 
  for(v=0;v<=n;v++){
    if(G[r][v] && color[v]==WHITE){
      visit(v);
    }
  }
  color[r]=BLACK;
  f[r]=++time;
 }

void dfs(int n){
  int u;
  
  for(u=0;u<n;u++){
    if(color[u]==WHITE){
      visit(u);
    }
  }
}

int main(void){
  
  int  i,j,k,m;
 
  scanf("%d",&n);
  
  for(i=0;i<100;i++){
    for(j=0;j<100;j++){
      G[i][j]=0;
    }
    color[i] = WHITE;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&j,&k);
    
    for(j=0;j<k;j++){
      scanf("%d",&m);
      G[i][m-1]=1;
    }
  }
  
  dfs(n);
 
  for(i=0;i<n;i++)
    printf("%d %d %d\n",i+1,d[i],f[i]);
  
  return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.awt.geom.*;
public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m) == 0) break;
			
			Point2D [] p1 = new Point2D[n];
			for(int i = 0 ; i < n; i++){
				int x = sc.nextInt();
				int y = sc.nextInt();
				p1[i] = new Point2D.Double(x, y);
			}
			Point2D [] p2 = new Point2D[m];
			for(int i = 0 ; i < m; i++){
				int x = sc.nextInt();
				int y = sc.nextInt();
				p2[i] = new Point2D.Double(x, y);
			}
			
			if(n == 1 && m == 1){
				System.out.println("YES");
				continue;
			}
			if(n == 1){
				p2 = convexHull(p2);
				if(iscontains(p2, p1)){
					System.out.println("NO");
				}
				else{
					System.out.println("YES");
				}
				continue;
			}
			if(m == 1){
				p1 = convexHull(p1);
				if(iscontains(p1, p2)){
					System.out.println("NO");
				}
				else{
					System.out.println("YES");
				}
				continue;
			}
			
			p1 = convexHull(p1);
			p2 = convexHull(p2);
//			
//			//debug
//			System.out.println(Arrays.toString(p1));
//			System.out.println(Arrays.toString(p2));
			
			if(isintersect(p1, p2)){
				System.out.println("NO");
				continue;
			}
			
			if(iscontains(p1, p2) || iscontains(p2, p1)){
				System.out.println("NO");
				continue;
			}
			System.out.println("YES");
		}
	}

	private boolean iscontains(Point2D[] p1, Point2D[] p2) {
		Point2D p = p2[0];
		int prev = 1 << 24;;
		for(int i = 0 ; i < p1.length; i++) {
			Line2D l = new Line2D.Double(p1[i], p1[(i+1) % p1.length]);
			
			int now = l.relativeCCW(p);
			if(prev != 1 << 24){
				if(now * prev  <= 0){
					return false;
				}
			}
			else{
				if(now == 0){
					return true;
				}
				
			}
			prev = now;
		}
		return true;
	}

	private boolean isintersect(Point2D[] p1, Point2D[] p2) {
		int n = p1.length;
		int m = p2.length;
		for(int i = 0 ; i < n; i++){
			for(int j = 0 ; j < m; j++){
				Line2D l = new Line2D.Double(p1[i], p1[(i + 1) % n]);
				Line2D l2 = new Line2D.Double(p2[j], p2[(j + 1) % m]);
				if(l.intersectsLine(l2)){
					return true;
				}
			}
		}
		return false;
	}

	private Point2D[] convexHull(Point2D[] p) {
		int n = p.length;
		Comparator<Point2D> com = new Comparator<Point2D>() {
			
			@Override
			public int compare(Point2D a, Point2D b) {
				if(a.getX() < b.getX()) return -1;
				if(a.getX() > b.getX()) return 1;
				if(a.getY() < b.getY()) return -1;
				if(a.getY() > b.getY()) return 1;
				return 0;
			}
		};
		Arrays.sort(p, com );
		int k = 0;
		Point2D [] qs = new Point2D[n * 2];
		for(int i = 0 ; i  < n; i++){
			while(k > 1 && new Line2D.Double(qs[k-2], qs[k-1]).relativeCCW(p[i]) > 0){
				k--;
			}
			qs[k++] = p[i];
		}
		
		for(int i = n - 2, t = k; i >= 0; i--){
			while(k > t && new Line2D.Double(qs[k-2], qs[k-1]).relativeCCW(p[i]) > 0){
				k--;
			}
			qs[k++] = p[i];
		}
		Point2D [] res = Arrays.copyOf(qs, k-1);
		return res;
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 13000
#include <iostream>
using namespace std;
int main(){
  int n,a,b;cin>>n>>a>>b;
  string s;cin>>s;
  int honsen = 0;
  int honsenkaigai = 0;
  for(int i = 0; n > i;i++){
    string kekka = "No";
    if(s[i] == 'a' && honsen < a+b)kekka="Yes",honsen++;
    if(s[i] == 'b' && honsen < a+b && honsenkaigai < b)kekka="Yes",honsen++,honsenkaigai++;
    cout << kekka << endl;
  }
  return 0;
}

Measured memory_bytes: 896
N = int(input())
a = list(map(int, input().split()))
color = [0]*8
strong = 0

for i in range(N):
    if a[i] >= 3200:
        strong += 1
    else:
        if a[i] < 400:
            color[0] = 1
        elif a[i] < 800:
            color[1] = 1
        elif a[i] < 1200:
            color[2] = 1
        elif a[i] < 1600:
            color[3] = 1
        elif a[i] < 2000:
            color[4] = 1
        elif a[i] < 2400:
            color[5] = 1
        elif a[i] < 2800:
            color[6] = 1
        else:
            color[7] = 1

smallest = color.count(1)
greatest = smallest + strong
if smallest == 0:
    smallest = 1

print(smallest, greatest)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
Int floorsum(Int n, Int m, Int a, Int b) {
    assert(n != 0 && m != 0);
    Int ans = 0;
    ans += b / m * n;
    b -= b / m * m;
    ans += n * (n - 1) / 2 * (a / m);
    a -= a / m * m;
    Int t = (a * (n - 1) + b) / m;
    if (a == 0 || t == 0) return ans;
    return ans + floorsum(t, a, m, n * a - (t * m - b));
}
int main() {
    int T; cin >> T;
    while (T--) {
        int N, M, A, B; cin >> N >> M >> A >> B;
        cout << floorsum(N, M, A, B) << '\n';
    }
    return 0;
}


Measured memory_bytes: 3624
n = int(input())
visited = [False] * (n + 1)
distance = [0] * (n + 1)
prev = [0] * (n + 1)

from collections import defaultdict, deque
d = defaultdict(list)

for _ in range(n-1):
    u,v,w = list(map(int, input().split()))
    d[u].append((v, w))
    d[v].append((u, w))

q = deque([1])
while q:
    node = q.popleft()
    visited[node] = True
    for next_node, next_dist in d[node]:
        if not visited[next_node]:
            q.append(next_node)
            # 距離を更新
            distance[next_node] = distance[node] + next_dist
    
# print(distance)
for dist in distance[1:]:
    print(dist%2)

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

int n;
long long ans;
struct node
{
	int x,id;
}a[100010]; 
inline int cmp(node x,node y)
{
	return x.x<y.x;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i].x);
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;++i)
	{
		if((a[i].id&1)!=(i&1))
		++ans;
	}
	printf("%lld\n",ans/2);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,m,a[200001];
ll tot;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(res i=1;i<=n;++i) cin>>a[i];
	sort(a+1,a+1+n),reverse(a+1,a+1+n);
	for(res i=m+1;i<=n;++i) tot+=a[i];
	cout<<tot<<'\n';
	cout<<flush;	 
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 1024
// atcoder/sumitrust2019/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

bool fn(string s, string t)
{
  queue<char> q;
  each (c, t) q.push(c);
  each (c, s) {
    if (q.front() == c) q.pop();
    if (q.empty()) return true;
  }
  return false;
}

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

  lli n;
  string s;
  while (cin >> n >> s) {
    lli sum = 0;
    char buff[1000];
    for (int i = 0; i < 1000; ++i) {
      sprintf(buff, "%03d", i);
      sum += fn(s, string(buff));
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <tuple>
#include<cmath>
#include<queue>
#include <climits>

using lli = long long int;
using namespace std;
int inf = 1000000007;

int N, H;
int a, b;

int main() {
	cin >> N >> H;
	priority_queue<tuple<int, bool>> pq;
	for (int i = 0; i < N; i++) {
		cin >> a >> b;
		bool f = true, g = false;
		pq.push(tie(a, g));
		pq.push(tie(b, f));
	}
	//貪欲に投げる
	int ans = 0;
	while (H > 0) {
		bool f;
		tie(a, f) = pq.top();
		if (f) { H -= a; ans++; pq.pop(); }
		else {
			ans += ceil((H + .0) / (a + .0));
			break;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MAXN=110000;
int N;
int S[MAXN];

ll get_sum_naive(int s,int d,int k) {
	ll sum=0;
	rep(i,0,k+1) sum+=S[s+i*d];
	return sum;
}

ll check_naive(int A,int d,int k) {
	if (A<=d || (A%d==0 && k>=A/d)) return 0;
	return get_sum_naive(0,d,k) + get_sum_naive(A,d,k);
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>S[i];
	
	ll res=0;
	for (int d=1; d*d<=N; ++d) {
		vector<vector<ll>> sums(d);
		rep(i,0,N) {
			ll v=S[i];
			if (!sums[i%d].empty()) v+=sums[i%d].back();
			sums[i%d].push_back(v);
		}
		
		rep(A,1,N-1) if ((N-1-A)%d==0) {
			int k=(N-1-A)/d;
			res=max(res,check_naive(A,k,d));
			
			if (A<=d || (A%d==0 && k>=A/d)) continue;
			
			ll sum=sums[0][k];
			sum+=sums[A%d][A/d+k];
			if (A/d>0) sum-=sums[A%d][A/d-1];
			res=max(res,sum);
		}
	}
		
	cout<<res<<"\n";
}


Measured memory_bytes: 2400
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		int n =sc.nextInt();
		int k =sc.nextInt();
		Integer[] balls =new Integer[n];
		for (int i=0;i<n;i++) {
			balls[i] =0;
		}
		for (int i=0;i<n;i++) {
			balls[sc.nextInt()-1] ++;
		}
		Arrays.sort(balls, Collections.reverseOrder());
		int ans =0;
		for (int j=k;j<n;j++) {
			ans += balls[j];
		}
		System.out.println(ans);
		
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
	}
}

Measured memory_bytes: 79596
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

const int MAX_V = 2001;

struct edge {
  int to, cost;
};
typedef pair<int, int> P; // firstは最短距離, secondは頂点の番号

int V;
vector<edge> G[MAX_V];
int d[MAX_V][MAX_V];

// 負辺のない単一始点全点間最短路を求めるアルゴリズム。
// 蟻本参照
//
// 計算量: O(ElogV)
void dijkstra(int s, int idx) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d[idx], d[idx] + V, INF);
  d[idx][s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[idx][v] < p.first) {
      continue;
    }

    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[idx][e.to] > d[idx][v] + e.cost) {
        d[idx][e.to] = d[idx][v] + e.cost;
        que.push(P(d[idx][e.to], e.to));
      }
    }
  }
}

int X, Y;
// vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> V >> X >> Y;
  X--;
  Y--;
  for (int i = 0; i < V - 1; i++) {
    G[i].push_back(edge{i + 1, 1});
    G[i + 1].push_back(edge{i, 1});
  }
  G[X].push_back(edge{Y, 1});
  G[Y].push_back(edge{X, 1});

  for (int i = 0; i < V; i++) {
    dijkstra(i, i);
  }

  vector<int> ans(V, 0);
  for (int i = 0; i < V; i++) {
    for (int j = i + 1; j < V; j++) {
      ans[d[i][j]]++;
    }
  }

  for (int i = 1; i < V; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 16000
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	int n; cin>>n;
  VI a(n);
  rep(i,n) cin>>a[i];
  // VI b; b.PB(a[0]); b.PB(INF);
  // reps(i,n-1){
  //   rep(j,b.size()-1){
  //     if((b[j]<a[i])&&(b[j+1]>=a[i])){
  //       b[j]=a[i];
  //       sort(ALL(b));
  //       break;
  //     }
  //     if(j==b.size()-2){
  //       b.PB(a[i]);
  //       sort(ALL(b));
  //       break;
  //     }
  //   }
  // }
  // cout << b.size()-1 << endl;
  deque<int> d;
  rep(i,n){
    int p = lower_bound(ALL(d), a[i]) - d.begin();
    if(p==0) d.push_front(a[i]);
    else d[p-1] = a[i];
  }
  cout << d.size() << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a * c <= b) {
            System.out.println(c);
        } else if (a * c > b) {
            System.out.println(b / a);
        }
    }
}


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

using namespace std;
 
int main() {
int N, K, A[200010]={0}, B[200010]={0},res=0;
cin >> N >> K;
for(int i=1; i<=N; ++i){
  cin >> A[i];
}
for(int i=1; i<=N; ++i){
  ++B[A[i]];
}
sort(B, B+200010, greater<>());
for(int i=0; i<K; ++i){
  res+=B[i];
}
cout << N-res << endl;

}


Measured memory_bytes: 1792
#include <stdio.h>
 
int main(void)
{
    int a = 0;
    int b = 0;
    int c = 0;
     
    scanf("%d %d %d", &a, &b, &c);
     
    if (a < b) {
        if (b < c) {
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }
    else{
        printf ("No\n");
    }
     
    return (0);
}

Measured memory_bytes: 580
//suhan lee,saitama university

#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <complex>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repn(i,n) for(int i=0;i<n;i++)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
#define pb push_back 
#define pf push_front
const int INF=10000000;
bool checked(int chouten,int i){
  if( ((1<<i)&chouten)){
    return true;
  }
  else return false;
}
int pluscheck(int chouten,int i){
  return (chouten|(1<<i));
}

int graph[16][16];
int dynamic[((1<<16)-1)][16];
int V,E;


int roop(int chouten,int genzai){
  //cout<<"hehe"<<chouten<<' '<<genzai<<' '<<len<<endl;;
  if(dynamic[chouten][genzai]!=-1)
    return dynamic[chouten][genzai];
  if(chouten==(1<<(V))-1){
    if(genzai==0)  
      return 0;
    else return INF;
  }
  else{
    int newlen,out;
    out=INF;
    for(int i=0;i<16;i++){
      if(checked(chouten,i)) continue;
      if(graph[genzai][i]!=INF){
	//	newlen=len+graph[genzai][i];
	out=min(out,roop(pluscheck(chouten,i),i)+graph[genzai][i]);
      }
    }
    return dynamic[chouten][genzai]=out;
  }
}
int main(){
  cin>>V>>E;
  int s,t,d;
  for(int i=0;i<16;i++){
    for(int j=0;j<16;j++){
      graph[i][j]=INF;
    }
  }
  for(int i=0;i<E;i++){
    cin>>s>>t>>d;
    graph[s][t]=d;
  }
  for(int i=0;i<((1<<16)-1);i++){
    for(int j=0;j<16;j++){
      dynamic[i][j]=-1;
    }
  }
  int rinzi=roop(0,0);
  if (rinzi<INF)
    cout<<rinzi<<endl;
  else cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 5260
#include <iostream>

using namespace std;

int N, M;
int a[50], b[50];
int adjacent[51][51];
bool visited[51];

void dfs(int v) {
	visited[v] = true;
	for (int i = 1; i <= N; i++) {
		if (adjacent[v][i] && !visited[i]) {
			dfs(i);
		}
	}
}

int main(int argc, char *argv[]) {
	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		int ai, bi;
		cin >> ai >> bi;
		adjacent[ai][bi] = adjacent[bi][ai] = 1;
		a[i] = ai; b[i] = bi;
	}

	int ans = 0;
	for (int i = 0; i < M; i++) {
		for (int j = 1; j <= N; j++) visited[j] = false;

		adjacent[a[i]][b[i]] = adjacent[b[i]][a[i]] = false;
		dfs(a[i]);
		if (!visited[b[i]]) ans++;
		adjacent[a[i]][b[i]] = adjacent[b[i]][a[i]] = true;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
int main()
{
    ll x, y ;
    string a, b ;
    cin >> a >> b ;
    x=a.size();
    y=b.size();
    ll flag=-1;
    if(x<y)
        flag=0;
    else if(x>y)
        flag=1;
    else
    {
        ll i, j ;
        for(i=0; i<x; i++)
        {
            if(a[i]>b[i])
            {
                flag=1;
                break;
            }
            else if(a[i]<b[i])
            {
                flag=0;
                break;
            }
        }
    }
    if(flag==-1)
        cout << "EQUAL";
    else if(flag==1)
        cout << "GREATER";
    else
        cout << "LESS";
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    ll n; cin >> n;
    map<string,ll> mp;
    for(int i=0;i<n;i++){
        int q; cin >> q;
        if(q==0){
            string key; cin >> key;
            ll x; cin >> x;
            mp[key] = x;
        }else if(q==1){
            string key; cin >> key;
            cout << mp[key] << endl;
        }else{
            string key; cin >> key;
            mp.erase(key);
        }
    }
}



Measured memory_bytes: 27836
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/25 16:27:18 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	int	n;
	cin >> n;
	vector<bitset<10000000>>	BS(n);
	rep(i, n)
	{
		string	s;
		cin >> s;
		rep(j, s.size())
		{
			int k = (int)s.at(j);
			while (BS.at(i).test(k))
				k += 150;
			BS.at(i).set(k);
		}
	}
	for (int i = 1; i < n; i++)
		BS.at(0) = BS.at(0) & BS.at(i);
	string	s;
	rep(i, 10000000)
	{
		if (BS.at(0).test(i))
			s += char(i % 150);
	}
	sort(s.begin(), s.end());
	cout << s << endl;
}
// END

int		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 62464
import java.util.*;

public class Main {
	

	
	public static class Sushi{
		int t;
		int d;
		
		public Sushi(int t, int d) {
			this.t = t;
			this.d = d;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		Sushi[] sushis = new Sushi[N];
		
		for (int i = 0; i < N; i++) {
			int t = sc.nextInt();
			int d = sc.nextInt();
			sushis[i] = new Sushi(t, d);
		}
		
		Arrays.sort(sushis, new Comparator<Sushi>() {
			public int compare(Sushi s1, Sushi s2) {
				return s2.d - s1.d;
			}
		});
		
		Stack<Sushi> extras = new Stack<Sushi>();
		HashMap<Integer, Boolean> types = new HashMap<Integer, Boolean>();
		
		long typeCount = 0;
		long deliciousness = 0;
		for (int i = 0; i < K; i++) {
			Sushi s = sushis[i];
			if (!types.containsKey(s.t)) {
				types.put(s.t, true);
				typeCount++;
			} else {
				extras.push(s);
			}
			deliciousness += s.d;
		}
		
		long satisfaction = typeCount*typeCount + deliciousness;
		
		for (int i = K; i < N && extras.size() > 0; i++) {
			Sushi s = sushis[i];
			if (!types.containsKey(s.t)) {
				types.put(s.t, true);
				typeCount++;
				deliciousness -= extras.pop().d;
				deliciousness += s.d;
				satisfaction = Math.max(satisfaction, typeCount*typeCount + deliciousness);
			}
		}
		
		System.out.println(satisfaction);
	}
}


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


int main() {
    int n;
    cin >> n;
    vector<ll> ans(n+1, 0);
    for(int x = 1; x <= 200; ++x) {
        for(int y = 1; y <= 200; ++y) {
            for(int z = 1; z<=200; ++z) {
                ll sum=x*x+y*y+z*z+x*y+y*z+z*x;
                if(sum <= n) ans[sum]++;
            }
        }
    }
    for(int i = 1; i <= n; ++i) {
        cout << ans[i] << endl;
    }
    
    return 0;
} 

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

int value[110];
int weight[110];
ll dp[110][1000100];

int main(){
  int n, w;
  cin >> n >> w;
  rep(i,n) cin >> weight[i] >> value[i];

  rep(i,w+1) dp[0][i] = 0;

  rep(i,n){
    rep(j,w+1){
      if(j >= weight[i]) dp[i+1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]);
      else dp[i+1][j] = dp[i][j];
    }
  }
  cout << dp[n][w] << endl;
  return 0;
}



Measured memory_bytes: 285696
#include<bits/stdc++.h>
using namespace std;
long inf = 1000000007;

int main() {
	long n, k; cin >> n >> k;
	long a = n % k;
	if (a < abs(a - k)) {
		cout << a << endl;
	}
	else {
		cout << abs(a - k) << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	long long int x;
	cin >> x;
	if (x < 7)
		cout << 1 << endl;
	else if (x < 11)
		cout << 2 << endl;
	else if (x % 11 == 0)
		cout << x / 11 * 2 << endl;
	else if (x % 11 < 7)
		cout << (x / 11 * 2) + 1 << endl;
	else
		cout << (x / 11 * 2) + 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

long long pow[12];
long long n;

int main() {
    std::cin >> n;
    pow[0] = 1;
    for (int i = 1; i <= 11; i++)
        pow[i] = pow[i - 1] * 26;
    for (int i = 1; i <= 11; i++) {
        if (n > pow[i])
            n -= pow[i];
        else {
            for (int j = i - 1; j; j--) {
                std::cout << static_cast<char>((n - 1) / pow[j] + 'a');
                n = (n - 1) % pow[j] + 1;
            }
            std::cout << static_cast<char>(n + 'a' - 1) << std::endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    ll N;
    cin >> N;
    vector<ll> Xi(N);
    rep(i,N){
        cin >> Xi[i];
    }

    vector<ll> score_list(100,99999999);
    rep(i,100){
        ll score = 0;
        rep(j,N){
            score += powl(Xi[j] - i - 1,2);
        }
        score_list[i] = score;
        // cout << score_list[i] << "\n";
    }

    ll result = 99999999;
    rep(i,100){
        result = min(score_list[i],result);
    }

    cout << result;
 }

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll a;
  cin >> a;
  cout << a + a*a + a*a*a;
  return 0;
}


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

vector<pair<int, int>> runLength(string s) {
  vector<pair<int, int>> ret;
  int n = s.length();
  map<char, int> charToNum;
  int maxAssined = 1;
  rep(i, n) {
    int cnt = 1;
    while (i < n - 1 && s[i] == s[i + 1]) {
      cnt++;
      i++;
    }
    if (charToNum.find(s[i]) == charToNum.end()) {
      charToNum[s[i]] = maxAssined;
      maxAssined++;
    }
    ret.push_back(make_pair(charToNum[s[i]], cnt));
  }

  return ret;
}

int main() {
  string s, t;
  cin >> s >> t;
  vector<pair<int, int>> sRL = runLength(s);
  vector<pair<int, int>> tRL = runLength(t);

  if (sRL.size() != tRL.size()) {
    cout << "No" << endl;
    return 0;
  }

  rep(i, sRL.size()) {
    if (sRL[i].first != tRL[i].first || sRL[i].second != tRL[i].second) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 5428