akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)
bool option(pair<int, int> a, pair<int, int> b){
	return a.second < b.second;
}
int32_t main(){ fast;
	int n,k; cin>>n>>k;
	set<int> set;
	int cnt = 0;
	map<int, int> map;
	rep(i, n){
		int x; cin>>x;
		if(!set.count(x)){
			cnt++;
			set.insert(x);
		}
		map[x]++;
	}
	if(cnt <= k){
		cout<<0<<endl;
		return 0;
	}
	vector<int> a;
	for(auto it: map){
		a.push_back(it.second);
	}
	int need = cnt - k;
	sort(all(a));
	int ans = 0;
	for(int i = 0; i < need; i++){
		ans += a[i];
	}
	cout<<ans<<endl;
}


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

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
	ll n, ans = 0, s[1100];
	cin >> n;
	REP(i, n) {
		ll a;
		cin >> a;
		if (a % 2 == 0)ans++;
	}
	cout << ans << endl;
}





Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define int long long
#define M (int)1e9+7
#define I (int)10e5

int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE

    int n;
    cin>>n;
    int ans = 0;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int max_val = v[0];
    for(int i=1;i<n;i++)
    {
        if(v[i]<max_val)
        {
            ans+=abs(max_val-v[i]);
            v[i] = max_val;
        }
        else
        {
            max_val = v[i];
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);i++)
#define FORq(i, m, n) for(int i = (m);i <= (n);i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
	ll N; cin >> N;
	FORq(h,1,3500){
		FORq(n,1,3500){
			ll a,b;
			a = N * h * n;
			b = 4*h*n - N * n - N * h;
			if (a<0) continue;
			if (b<=0) continue;
			if (a % b == 0) {
				ll w; w = a / b;
				if (w <= 0) continue;
				printf("%d %d %d\n",h,n,w);
				return 0;
			}
			
		}
	}
	
	return 0;
}

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

int main() {
   int n;
   cin>>n;
   int x,y;
   cin>>x>>y;
   for (int i=x; i<=y; i++) {
   	if(i%n==0) {
   		cout << "OK";
   		return 0;
   	}
   }
   cout << "NG";
}

Measured memory_bytes: 3636
#include<stdio.h>
int main ()
{
    int a,b,c,k;
    scanf("%d%d%d",&a,&b,&c);
    if(a<b)
        k=a,a=b,b=k;
    if(a<c)
        k=a,a=c,c=k;
    if(b<c)
        k=b,b=c,c=k;
    printf("%d\n",b+c);
}


Measured memory_bytes: 128
n = gets.chomp.to_i
march = {M:0,A:0,R:0,C:0,H:0}
n.times {
  initial = gets.chomp[0].to_sym
  if march.include?(initial) then
    march[initial] += 1
  end
}

MA = march[:M] * march[:A]
MAR = MA * march[:R]
MAC = MA * march[:C]
MAH = MA * march[:H]
MR = march[:M] * march[:R]
MRC = MR * march[:C]
MRH = MR * march[:H]
CH = march[:C] * march[:H]
MCH = march[:M] * CH
AR = march[:A] * march[:R]
ARC = AR * march[:C]
ARH = AR * march[:H]
ACH = march[:A] * CH
RCH = march[:R] * CH

puts (MAR + MAC + MAH + MRC + MRH + MCH + ARC + ARH + ACH + RCH)


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

Measured memory_bytes: 592
N = int(input())
a_list = list(map(int,input().split()))

s = sum(a_list)
mae = 0
min_diff = 10**16
for a in a_list[:-1]:
    mae += a
    ato = s - mae
    diff = abs(mae-ato)
    if diff < min_diff:
        min_diff =diff
print(min_diff)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> s(H,vector<char>(W));

  REP(i,H)REP(j,W)cin >> s[i][j];

  REP(i,H){
    REP(j,W){
      if(s[i][j]=='.')continue;
      bool ok=false;
      REP(k,4){
        int ii = i + dx[k];
        int jj = j + dy[k];
        if(ii < 0 || ii >= H || jj < 0 || jj >= W)continue;
        if(s[ii][jj]=='#')ok=true;
      }
      if(!ok){
        cout << "No" << endl;
        exit(0);
      }
    }
  }
  cout << "Yes" << endl;

}



Measured memory_bytes: 256
#include <stdio.h>
#define MAX 2000000

int h[MAX+1],size = 0;

void maxHeapify(int i){
  int l,r,largest,ex;
  
  l = 2*i;
  r = 2*i+1;

  if(l <= size && h[l] > h[i])largest = l;
  else largest = i;

  if(r <= size && h[r] > h[largest])largest = r;
  
  if(largest != i){
    ex = h[i];
    h[i] = h[largest];
    h[largest] = ex;
    maxHeapify(largest);
  }
}

void IncreaseKey(int i,int k){
  int ex;
  
  h[i] = k;
  while(i > 1 && h[i/2] < h[i]){
    ex = h[i];
    h[i] = h[i/2];
    h[i/2] = ex;
    
    i /= 2;
  }

}

void Insert(int key){
  size++;
  h[size] = -1;
  IncreaseKey(size,key);
}

void extractMax(){
  if(size < 1)return;
  
  printf("%d\n",h[1]);
  h[1] = h[size];
  size--;
  
  maxHeapify(1);
}

int main(){
  int i,k;
  char a[7];
  
  for(i = 0;i < MAX; i++){
  scanf("%s",a);

  if(a[0] == 'i'){
    scanf("%d",&k);
    if(k < 0 || k > 2000000000)return 0;
    Insert(k);
  }
  else if(a[1] == 'x')extractMax();
  else return 0;

}
}



Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll dp[110][10];
ll memo_comb[8];

const ll MOD = 1e9+7;

int H, W, K;

ll calc_dp(int h, int k){

    if(h == 0 && k == 1){
        return dp[h][k] = 1;
    }else if(h == 0){
        return dp[h][k] = 0;
    }

    if(dp[h][k] >= 0) return dp[h][k];

    ll tmp_ans = 0;
    tmp_ans = (tmp_ans + calc_dp(h-1, k) *   memo_comb[max(0, k-2)]   * memo_comb[max(0, W-k-1)])%MOD;
    tmp_ans = (tmp_ans + calc_dp(h-1, k-1) * memo_comb[max(0, W-k-1)] * memo_comb[max(0, k-3)])%MOD;
    tmp_ans = (tmp_ans + calc_dp(h-1, k+1) * memo_comb[max(0, W-k-2)] * memo_comb[max(0, k-2)])%MOD;
    return dp[h][k] = tmp_ans;
}

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    for(int i = 0; i < 110; i++){
        for(int j = 0; j < 10; j++){
            dp[i][j] = -1;
        }
    }

    cin >> H >> W >> K;

    for(int i = 0; i < 110; i++){
            dp[i][0] = 0;
            dp[i][W+1] = 0;
    }
    
    ll memo_comb_sub[8][2];
    memo_comb_sub[0][0] = 1;
    memo_comb_sub[0][1] = 0;
    memo_comb_sub[1][0] = 1;
    memo_comb_sub[1][1] = 1;

    for(int i = 1; i < 7; i++){
        memo_comb_sub[i+1][0] = memo_comb_sub[i][0] + memo_comb_sub[i][1];
        memo_comb_sub[i+1][1] = memo_comb_sub[i][0];
    }

    for(int i = 0; i < 8; i++){
        memo_comb[i] = memo_comb_sub[i][0] + memo_comb_sub[i][1];
    }

    cout << calc_dp(H, K) << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
#define pb push_back
#define fi first
#define se second 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s; 
	cin>>s;
	deque<char>dq;
	for(char c:s)dq.push_back(c);
	int q; 
	cin>>q; 
	int r = 0;
	while(q--){
		int t; 
		cin>>t; 
		if(t==1){
			r = 1-r;
		}
		else{
			int f;
			char c;
			cin>>f>>c; 
			if(r){
				if(f==1){
					dq.push_back(c);
				}
				else{
					dq.push_front(c);
				}
				
				
			}
			else{
				if(f==1){
					dq.push_front(c);
				}
				else{
					dq.push_back(c);
				}
			}
		}
	}
	string ans = "";
	while(!dq.empty()){
		ans+=dq.front();
		dq.pop_front();
	}
	if(r)reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 1368
#include "bits/stdc++.h"
using namespace std;

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

// vector
template <typename T>
istream & operator>>(istream & is, vector<T> & vec) {
	for (T& x : vec) is >> x;
	return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	os << "{";
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
	}
	os << "}";
	return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
	os << "{";
	repi(itr, map_var) {
		os << *itr;
		itr++;
		if (itr != map_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
	os << "{";
	repi(itr, set_var) {
		os << *itr;
		itr++;
		if (itr != set_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}

#define DUMPOUT cerr

void dump_func() {
	DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
	DUMPOUT << head;
	if (sizeof...(Tail) > 0) {
		DUMPOUT << ", ";
	}
	dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif



signed main() {

	int N;
	cin >> N;
	int total = 0;
	vector<int> A(N), s(N+1,0);
	rep(i, N) {
		cin >> A[i];
		s[i + 1] = s[i] + A[i];
		total += A[i];
	}

	int ans = INF;
	for (int i = 0; i < N - 1; i++) {
		int left = s[i + 1];
		int right = total - s[i + 1];
		ans = min(ans, abs(left - right));
	}

	cout << ans << endl;

}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int e[n+1];
	int w[n+1];
	e[0]=0;
	w[0]=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='E')
		{
			e[i+1]=e[i]+1;
			w[i+1]=w[i];
		}
		else
		{
			e[i+1]=e[i];
			w[i+1]=w[i]+1;
		}
	}
	long long ans=9999999999;
	for(int i=1;i<=n;i++)
	{
		if((w[i-1]+e[n]-e[i])<ans)
		ans=w[i-1]+e[n]-e[i];
	}
	cout<<ans;
 } 

Measured memory_bytes: 6144
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
K = INT()
ans = 1
for _ in range(N):
    if ans * 2 < ans + K:
        ans = ans * 2
    else:
        ans = ans + K
print(ans)


Measured memory_bytes: 27056
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    string s; cin >> s;
    vector<int> sum(n + 1, 0);
    for(int i = 0; i < s.size() - 1; i++)
    {
        if(s.substr(i, 2) == "AC")
        {
            sum[i]++;
            sum[i + 1]--;
        }
    }
    for(int i = 0; i < n; i++)
    {
        if(i > 0) sum[i] += sum[i - 1];
    }
    vector<int> v(n + 1, 0);
    v[0] = sum[0];
    for(int i = 1; i < n; i++) v[i] = v[i - 1] + sum[i];
    for(int i = 0; i < n; i++) if(sum[i] == 1) v[i]--;
    for(int i = 0; i < q; i++)
    {
        int l, r; cin >> l >> r;
        l--, r--;
        cout << v[r] - v[l] << endl;
    }
    return 0;
}



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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int inf = 1e9;

class WarshallFloyd {
private:
    int n;
    VV d;
public:
    WarshallFloyd(int _n) : n(_n) {
        d.resize(n, V(n));
        rep(i, n) rep(j, n) {
            d[i][j] = (i == j ? 0 : inf);
        }
    }
    // directed
    void setDist(int i, int j, int c) {
        d[i][j] = c;
    }
    int getDist(int i, int j) {
        return d[i][j];
    }
    void calc() {
        rep(k, n) rep(i, n) rep(j, n) {
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
};

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

    int n, m, s, g1, g2;
    while (cin >> n >> m >> s >> g1 >> g2, n) {
        s--, g1--, g2--;
        WarshallFloyd wf(n);
        rep(i, m) {
            int a, b, c;
            cin >> a >> b >> c;
            a--, b--;
            wf.setDist(a, b, c);
        }

        wf.calc();

        int ans = inf;
        rep(i, n) {
            ans = min(ans, wf.getDist(s, i) + wf.getDist(i, g1) + wf.getDist(i, g2));
        }
        cout << ans << endl;
    }
}

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

using namespace std;
typedef long long ll;

int main() {
    int n, c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    for(int i = 0; i < n; i++){
        cin >> t[i];
    }
    sort(t.begin(),t.end());

    int ans = 1;
    int first = 0;
    int passenger = 0;
    for(int i = 0; i < n; i++){
        if(t[i]>t[first]+k || passenger == c){
            first = i;
            passenger = 1;
            ans += 1;
        }else{
            passenger += 1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

ll a, b;

int main() {
    cin >> a >> b;
    if( (a + b) % 2 == 0 )
        cout << (a + b) / 2 << endl;
    else
        cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int main()
{
  int a[3];
  for ( int i = 0; i < 3; i++ ) std::cin >> a[i];
  std::sort(a, a+3);

  if ( (a[2]-a[0]) % 2 == 0 && (a[2]-a[1]) % 2 == 0 ) {
    std::cout << (a[2] - a[0]) / 2 + (a[2] - a[1]) / 2 << std::endl;
  } else if ( (a[2] - a[0]) % 2 == 1 && (a[2] - a[1]) % 2 == 0 ) { 
    std::cout << 1 + (a[2] + 1 - a[0]) / 2 + (a[2] - a[1]) / 2 << std::endl;
  } else if ( (a[2] - a[0]) % 2 == 0 && (a[2] - a[1]) % 2 == 1 ) {
    std::cout << 1 + (a[2] - a[0]) / 2 + (a[2] + 1 - a[1]) / 2 << std::endl;
  } else {
    std::cout << 1 + (a[2] - a[0] - 1) / 2 + (a[2] - a[1] - 1) / 2 << std::endl;
  }
  return 0;
}


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

void solve(){
    int k; cin>>k;

    if(k%2 == 0 || k%5 == 0) printf("-1\n");
    else{
        int i = 1;
        int ans = -1;
        long long m = 7;

        m = 7%k;
        while(m!=0) {
            m = (m*10 + 7)%k;
            i++;
        }

        cout<<i<<endl;
    }
}

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


Measured memory_bytes: 3584
// header {{{
// #define NDEBUG
#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)
#define CILING(a, b)    (((a)+(b)-1LL)/(b))

template<class T>
using PIT = pair<int, T>;
template<class T>
using PTI = pair<T, int>;
using PII = pair<int, int>;
using PDI = pair<double, int>;
using LL  = long long;
using ULL = unsigned long long;
// }}}

int main() {
    int n;cin >> n;
    vector<int> p(n);
    for(auto &pp : p){
        cin >> pp;
        pp--;
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(p[i] == i){
            ans++;
        }
    }
    for(int i=0;i<n-1;){
        if(p[i] == i && p[i+1] == i+1){
            ans--;
            i+=2;
        }else{
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(100000000)
N, M = map(int, input().split())
A = [list(map(int,input().split())) for i in range(N)]
A.sort()
hon_li = [a[0] for a in A]
hon = 0
pre_hon = 0
turn = 0
for i in range(N):
    pre_hon = hon
    hon += A[i][1]
    if hon >= M:
        turn = i
        break
li = [A[k][0]*A[k][1] for k in range(turn)]
amari = A[turn][0] * (M - pre_hon)
ans = sum(li) + amari
print(ans)

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

using namespace std;
typedef long long ll;

int main(){
    ll A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    ll x = A*X+B*Y;
    ll y = max(X,Y) * 2 * C;
    if(X > Y){
        swap(X,Y);
        swap(A,B);
    }
    ll z = X*2*C + (Y-X)*B;
    cout << min(x,min(y,z)) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)

Asort = sorted(A)
maxA = Asort[-1]
nexA = Asort[-2]

for a in A:
    if a == maxA:
        print(nexA)
    else:
        print(maxA)


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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int t[n], x[n], y[n];
    for (int i = 0; i < n; i++) cin >> t[i] >> x[i] >> y[i];
    int time = 0, cx = 0, cy = 0, tmp;
    bool flag = true;
    for (int i = 0; i < n; i++) {
        tmp = abs(x[i] - cx) + abs(y[i] - cy);
        if (t[i] - time >= tmp && tmp % 2 == (t[i] - time) % 2) {
            time = t[i], cx = x[i], cy = y[i];
        } else {
            flag = false;
            break;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

bool used[MAXX];
int k;

int main()
{
    _FastIO;
    cin >> k;
    for(int i = 0; i < 100; i++){
        used[i] = false;
    }
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            used[i * j] = true;
        }
    }
    if(used[k])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll a, b;
    cin >> a >> b;
    MSG(max(a+b, max(a-b, a*b)))
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        Deque<Integer> d = new ArrayDeque<>();
        int tmp1 = sc.nextInt();
        d.push(tmp1);
        int tmp2 = 0;
        int answer = 0;
        for(int i = 1;i<n;i++){
            tmp1 = d.getFirst();
            tmp2 = sc.nextInt();
            if(tmp2 == tmp1){
                tmp2 = 0;
                answer++;
            }
            d.push(tmp2);
        }
        System.out.println(answer);
    }
}

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

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

  while(a>0||c>0){
    c-=b;
    if(c<=0){
      cout << "Yes" << endl;
      break;
    }
    a-=d;
    if(a<=0){
      cout << "No" << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cmath>

using namespace std;

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

    a[0] = 0;
    a[1] = abs(h[1] - h[0]);

    for (int i = 2; i < n; i++)
    {
        a[i] = min(a[i - 2] + abs(h[i] - h[i - 2]), a[i - 1] + abs(h[i] - h[i - 1]));
    }

    cout << a[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1408
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		long X = sc.nextLong();
		long Y = sc.nextLong();

		for (int i = 0; i <= 60; i++) {
			if (Y < X * (long)Math.pow(2, i)) {
				System.out.println(i);
				break;
			}
		}
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
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 int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

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

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int 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 nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 21204
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main(void)
{
	int M;
	cin >> M;
	cout << 24 - M + 24;
	return 0;
}


Measured memory_bytes: 764
#ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define All(v) v.begin(),v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 998'244'353;

signed main() {
    FAST;

    int k, a, b;
    cin >> k >> a >> b;
    bool can = false;
    Fr(i, a, b+1) can |= i%k == 0;
    cout << (can ? "OK" : "NG") << endl;

}


Measured memory_bytes: 3652
#include <stdio.h>
#define N 1000000000
int S[N],n,key;
int binarySearch(){
    int left = 0,right = n,mid;
    while(left < right){
        mid = (left + right) / 2;
        if(S[mid] == key) return 1;
        if(key > S[mid]) left = mid + 1;
        else if(key < S[mid]) right = mid;
    }
    return 0;
}
int main(void){
    int i;
    int q,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&S[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&key);
        if(binarySearch() == 1) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}



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

#include <vector>
using namespace std;


int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	
	for(int i = 0; (size_t)i < s.size() - 1 ; i++){
		if(s[i] == s[i + 1]){
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
			}
	}	
	
		for(int i = 0; (size_t)i < s.size() - 2 ; i++){
			if(s[i] == s[i + 2]){
				cout << i  + 1 << " " << i + 3 << endl;
				return 0;
				}
			}
	
	
	cout << -1 << " " << -1 << endl;
	
	
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
    int n, k, x, y,ans;
    scanf("%d %d %d %d", &n, &k, &x, &y);
    if(n >= k){
        ans = k * x + (n - k) * y;
    }else{
        ans = n * x;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    r = int(input())
    res = 3 * pow(r, 2)
    print(res)


if __name__ == '__main__':
    resolve()


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

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> a;
    int ans=0;
    for(int i=0;i<n;i++){
        int b;
        cin>>b;
        a.push_back(b);
    }
    sort(a.begin(),a.end());
    for(int i=0;i<k;i++){
        ans+=a[i];
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    long long H,N;
    cin>>H>>N;
    long long suma=0;
    for(int i = 0;i<N;i++)
    {
        int pom;
        cin>>pom;
        suma+=pom;
    }
    if(suma>=H)cout<<"Yes";
    else cout<<"No";
}


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

cnt = max(0, a[0] - x)
a[0] -= cnt
for i in range(1, n):
    cnt_now = max(0, a[i-1] + a[i] - x)
    a[i] -= cnt_now
    cnt += cnt_now

print(cnt)


Measured memory_bytes: 20048
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include <string>
#include <utility>
#include<array>
#include<set>
#define EPS (1e-7)
using namespace std;




int main() {

	int A, B, C, D;
	char a, b, c, d;
	cin >> a >> b >> c >> d;

	
	A = (int)a - 48;
	B = (int)b - 48;
	C = (int)c - 48;
	D = (int)d - 48;


	if (A + B + C + D == 7) { cout << A << "+" << B << "+" << C << "+" << D << "=" << "7" << endl; return 0; }
	if (A + B + C - D == 7) { cout << A << "+" << B << "+" << C << "-" << D << "=" << "7" << endl; return 0; }
	if (A + B - C + D == 7) { cout << A << "+" << B << "-" << C << "+" << D << "=" << "7" << endl; return 0; }
	if (A + B - C - D == 7) { cout << A << "+" << B << "-" << C << "-" << D << "=" << "7" << endl; return 0; }
	if (A - B + C + D == 7) { cout << A << "-" << B << "+" << C << "+" << D << "=" << "7" << endl; return 0; }
	if (A - B - C + D == 7) { cout << A << "-" << B << "-" << C << "+" << D << "=" << "7" << endl; return 0; }
	if (A - B + C - D == 7) { cout << A << "-" << B << "+" << C << "-" << D << "=" << "7" << endl; return 0; }
	if (A - B - C - D == 7) { cout << A << "-" << B << "-" << C << "-" << D << "=" << "7" << endl; return 0; }

	return 0;
}

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

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

int main(){
  priority_queue<P>que_a,que_b;
  int N;
  cin >> N;

  ll A[N],B[N];

  for(int i = 0 ; i < N ; i++){
    ll a,b;
    cin >> a >> b;
    A[i] = a;
    B[i] = b;
    que_a.push(P(a+b,i));
    que_b.push(P(b+a,i));
  }

  bool flag[N];
  for(int i = 0 ; i < N ; i++){
    flag[i] = false;
  }

  ll res_a = 0;
  ll res_b = 0;

  while(que_a.size() > 0 && que_b.size() > 0){
    while(que_a.size()){
      P t = que_a.top();
      que_a.pop();
      if(flag[t.second])continue;
      res_a += A[t.second];
      flag[t.second] = true;
      break;
    }

    while(que_b.size()){
      P t = que_b.top();
      que_b.pop();
      if(flag[t.second])continue;
      res_b += B[t.second];
      flag[t.second] = true;
      break;
    }
  }
  cout << (res_a - res_b) << endl;
  return 0;
}


Measured memory_bytes: 6632
large_p = 10**9 + 7
from itertools import accumulate
from itertools import chain
def main():
    n, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    dp = [[0] * (k+1) for _ in range(n+1)]
    dp[0][0] = 1
    for i1 in range(n):
        accum = tuple(chain([0], accumulate(dp[i1])))
        for i2 in range(k + 1):
            t = max(0, i2 - a[i1])
            dp[i1 + 1][i2] += accum[i2+1] - accum[t] + large_p
            dp[i1 + 1][i2] %= large_p

    print(dp[n][k])

if __name__ == '__main__':
    main()


Measured memory_bytes: 183304
ary = []
5.times { ary << gets.to_i }
a, b, c, d, e, f = ary
k = gets.to_i
flag = false
ary.each do |i|
  ary.each do |j|
    flag = true if i - j > k
  end
end
puts flag ? ':(' : 'Yay!'

Measured memory_bytes: 1788
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <memory.h>
using namespace std;

typedef pair<int,long long> pil;
typedef pair<long long,int> pli;

int n,q,k;
vector<pil> adj[100005];
long long dist[100005];

void dij(int s){
	priority_queue<pli,vector<pli>,greater<pli> > pq;
	dist[s]=0;
	pq.push(pli(0,s));
	while(!pq.empty()){
		pli v=pq.top();
		pq.pop();
		long long dis=v.first;
		int pos=v.second;
		for(int i=0;i<adj[pos].size();i++){
			pil u=adj[pos][i];
			int npos=u.first;
			long long len=u.second;
			if(dis+len<dist[npos]){
				dist[npos]=dis+len;
				pq.push(pli(dist[npos],npos));
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;
		long long c;
		scanf("%d %d",&x,&y);
                cin>>c;
		adj[x].push_back(pil(y,c));
		adj[y].push_back(pil(x,c));
	}
	scanf("%d %d",&q,&k);
	fill(dist,dist+100005,1e18);
	dij(k);
	for(int i=1;i<=q;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		cout<<dist[x]+dist[y]<<endl;
	}
return 0;
}

Measured memory_bytes: 11120
/*{{{*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#else
#define debug(...) {}
#endif
#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
using namespace std;
using ll = long long;
using ld = long double;
template < typename t > using V = vector< t >;
template< typename t > int size(const t& c) {return c.size();}
void print() {cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}
#define flag() __LINE__"| "__PRETTY_FUNCTION__
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
/*}}}*/

constexpr int nax = 2e5, inf = 1e9;

int n, tab[nax], bat[nax];

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

    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> tab[i], bat[i] = inf;

    reverse(tab, tab + n);

    int mi = inf;

    for (int i = n - 1; i >= 0; --i)
    {
        int q = tab[i] + i;
        if (q > mi)
        {
            return print(-1), 0;
        }
        if (q >= n)
            return print(-1), 0;
        bat[q] = min(bat[q], i);
        mi = min(mi, q);
    }
        
    ll res = 0;
    for (int i = 0; i < n; ++i)
        res += max(0, i - bat[i]);
    print(res);
}

Measured memory_bytes: 1792
def solve():
    N, A, B = [int(x) for x in input().split()]
    S = input()
    a, b = 0, 0
    Ans = ['No'] * N
    for i in range(N):
        s = S[i]
        if s == 'c':
            continue
        if s == 'a':
            if a + b < A + B:
                Ans[i] = 'Yes'
                a += 1
        if s == 'b':
            if a + b < A + B and b < B:
                Ans[i] = 'Yes'
                b += 1
    for ans in Ans:
        print(ans)


if __name__ == "__main__":
    solve()

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

using namespace std;

long a[222222];
int main()
{
	int n;
	cin >> n;
	long r = 0, b = 0;
	scanf("%ld", a);
	for (int i = 0, j = 0; i < n; i++) {
		while (j < n && !(b&a[j])) {
			b ^= a[j++];
			if (j == n) break;
			scanf("%ld", a + j);
		}
		r += j - i;
		b ^= a[i];
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 1792
// ABC067_A.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || b + c == a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for(int i=1; i<s.length(); i++) {
			if(s.charAt(i-1) == s.charAt(i)) {
				System.out.println("Bad");
				sc.close();
				return;
			}
		}
		System.out.println("Good");
		sc.close();
	}
}


Measured memory_bytes: 35784
def main():
    q = int(input())
    cnt = 0
    for _ in range(q):
        n = int(input())
        i = 2
        f = True
        while i*i <= n and f:
            if n % i == 0:
                f=False
            i += 1
        if f:
            cnt += 1
    print(cnt)

main()


Measured memory_bytes: 5608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

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


int main() {
    string a;
    cin >> a;
    if (a.size() == 3) {
        cout << a.at(2) << a.at(1) << a.at(0) << endl;
    }
    else {
        cout << a << endl;
    }
}

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

int N, K;
string S;
int ser_n = 0;  //1以上の文字連続の塊数
int ini_happi = 0;  //初期幸福人数
int res;

int main(){
    cin >> N >> K;
    cin >> S;

    int i = 0;
    while(i < S.size()){
        int j = 0;
        while(i+j < S.size() && S[i] == S[i+j]) ++j;
        ++ser_n;
        ini_happi += (j-1);
      	i += j;
    }

    if(ser_n & 1)
      res=ini_happi+2*min(ser_n/2,K);
    else
      res=ini_happi+2*min(ser_n/2-1,K)+min(1,max(K-(ser_n/2-1),0));
  
    cout << res << endl;
    return 0;
}


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

int main() {
	string S;
	int a = 1000;
	cin >> S;
	for (int i = 0; i < S.size() - 2; i++) {
		int MIN = min(a, abs(753-stoi(S.substr(i, 3))));
	
		a = abs(MIN);
	}
	cout << a << endl;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

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

ll T[105];

int main() {
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> T[i];
    }
    ll ans = T[0];
    REP(i, N) {
        ll g = gcd(ans, T[i]);
        ans = (ans / g) * T[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    string s;
    cin>>s;
    int n = s.length();
    if(n==2) cout<<s<<endl;
    else{
        for(int i =n-1;i>=0;--i) cout<<s[i];
        cout<<endl;
    }
    return 0;
}

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

int main()
{
    int n, i, c = 0;
    cin >> n;
    int N[n];
    for(i=0;i<n;i++)
    {
        cin >> N[i];
    }
    for(i=1;i<n-1;i++)
    {
        if((N[i]>N[i+1]) && (N[i]<N[i-1]))
        {
            c++;
        }
        else if((N[i]<N[i+1]) && (N[i]>N[i-1]))
        {
            c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] res = new int[N + 1];

        for (int x = 1; x < 100; x++) {
            for (int y = 1; y < 100; y++) {
                for (int z = 1; z < 100; z++) {
                    int ans = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
                    if (ans <= N) {
                        res[ans]++;
                    }
                }
            }
        }
        for (int i = 1; i <= N; i++) {
            System.out.println(res[i]);
        }
    }
}

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

#define ll long long int
#define mod 1000000007

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

const double pi = 3.141592653589793238;
int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int r;
    cin>>r;
    double ans = 2*pi*r;
    printf("%0.2f",ans);
    
}



Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define reps(i, s, n) for (int i = (s); i < (n); ++i)
#define repse(i, s, n) for (int i = (s); i <= (n); ++i)
#define all(xs) (xs).begin(), (xs).end()
const int64_t inf = (int64_t)1e18;
const int64_t mod = (int64_t)1e9 + 7;

class UnionFind {
    vector<int64_t> parent, rank, sizes;

public:
    UnionFind(int64_t size) {
        parent = rank = sizes = vector<int64_t>(size, 0);
        rep(i, size) {
          parent[i] = i;
          sizes[i] = 1;
        }
    }

    int64_t root(int64_t x) {
        return parent[x] == x ? x : parent[x] = root(parent[x]);
    }

    bool same(int64_t x, int64_t y) {
        return root(x) == root(y);
    }

    int64_t size(int64_t x) {
      return sizes[root(x)];
    }

    void unite(int64_t x, int64_t y) {
        x = root(x); y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        sizes[x] += sizes[y];
        parent[y] = x;
    }
};

int main() {
  int64_t N, M; cin >> N >> M;
  vector<int64_t> A(M), B(M);
  rep(i, M) cin >> A[i] >> B[i];
  UnionFind uf(N + 1);
  vector<int64_t> ans(M, 0);
  ans[M - 1] = N * (N - 1) / 2;
  for (int64_t i = M - 1; i >= 1; --i) {
    if (ans[i] == 0) break;
    if (uf.same(A[i], B[i])) {
      ans[i - 1] = ans[i];
      continue;
    }
    ans[i - 1] = ans[i] - uf.size(A[i]) * uf.size(B[i]);
    uf.unite(A[i], B[i]);
  }
  for (int64_t x : ans) cout << x << endl;
  return 0;
}

Measured memory_bytes: 6016
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long 
struct node{
	ll l,r;
	node(ll a,ll b){
		l=a;r=b;
	}
	friend bool operator<(const node &a,const node &b){
		return a.r>b.r;
	}
};
priority_queue<node> q;
ll n,t1,t2;
int main(){
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&t1,&t2);
		q.push(node(t1,t2));
	}
	ll sum=0;
	for(int i=0;i<n;i++){
		node e=q.top();
		q.pop();
		sum+=e.l;
		if(sum>e.r){
			printf("No");
			return 0;
		}
		//cout <<e.l<<" "<<e.r<<endl;
	}
	printf("Yes");
	return 0;
}

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

int main(){
	vector<int>v;
	int q;cin>>q;
	rep(i,q){
		int a;cin>>a;
		if(a==0){
			int x;cin>>x;
			v.push_back(x);
		}
		else if(a==1){
			int x;cin>>x;
			cout<<v[x]<<endl;
		}
		else v.pop_back();
	}	
}



Measured memory_bytes: 3848
import sys
input = sys.stdin.readline
N = int(input())
a = "No"
b = 1
for i in range(21) :
    for j in range(15) :
        if 4 * i + 7 * j == N :
            a = "Yes"
            b = 0
            break
    if b == 0 :
        break
print(a)

Measured memory_bytes: 2940
# -*- coding: utf-8 -*-


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    from collections import defaultdict
    n = input_int()
    a = input_to_int_tuple()

    syain = defaultdict(int)

    for a_i, josi_no in enumerate(a):
        syain_no = a_i + 1
        syain[josi_no] = syain[josi_no] + 1

    for syain_no in range(1, n + 1):
        print(syain[syain_no])


if __name__ == "__main__":
    main()


Measured memory_bytes: 37340
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#include<utility>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007
int a[2001][2001];
using namespace std;


int main() {
	lli n,k;
	cin>>n>>k;
	vector<lli> vec(n),ans;
	rep0(i,n)cin>>vec[i];
	
	vector<lli> devec(2*n,0);
	rep1(i,n*2-1){
		devec[i]=devec[i-1]+vec[(i-1)%n];
	}
	rep0(i,min(k,n)+1){
		rep0(j,2*n-i){
			if(!(j<=n&&n<=j+i))continue;
			vector<lli> mivec;
			for(int h=j;h<j+i;h++)if(vec[h%n]<0)mivec.push_back(vec[h%n]);
			sort(all(mivec));
			lli temp=0;
			for(int h=0;h<k-i&&h<mivec.size();h++)temp+=mivec[h];
			ans.push_back(devec[j+i]-devec[j]-temp);
			//cout << devec[j+i]-devec[j] << ' ' << temp <<endl;
		}
		//cout << endl;
	}
	sort(rall(ans));
	cout <<ans[0];
}

Measured memory_bytes: 256