akhauriyash/Code-Regression huggingface dataset:
a;f(H,W){for(long long i=H,x,y,z,t;i--;a=t<a?t:a)x=(H-i)*W,y=W/2*i,z=(W+1)/2*i,t=x>z?x-y:x<y?z-x:i;}main(H,W){scanf("%d%d",&H,&W);printf("%d\n",H%3&&W%3?a=H<W?H:W,f(H,W),f(W,H),a:0);}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-9)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#endif
}
//
int n;
#define nMax 200+9
int A[nMax];
//
int main()
{
    read_file();
    while(scanf("%d", &n)!=EOF)
    {
        n *= 2;
        for(int i=0; i<n; i++)
            scanf("%d", &A[i]);
        sort(A, A+n);
        
        int ans = 0;
        for(int i=0; i<n; i+=2)
            ans += A[i];
        
        printf("%d\n", ans);
    }
}


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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ll a, b;
	cin >> a >> b;
	cout << a *b;





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int A = nextInt();
  int P = nextInt();
  P += 3 * A;
  cout << P / 2 << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[200005];
int n;
int main(){
	int i,j,k;
	scanf("%s",s);
	n=strlen(s);
	int res=0;
	for(i=0;i<n;){
		for(j=i;j<n;++j){
			if(s[j]!=s[i]) break;
		}
		int len=j-i;
		while(len>=3){
			len-=3;
			res+=2;
		}
		if(len==2 && j<n-1 && s[j]==s[j+1]){
			res+=2;
			len=0;
			++j;
		}
		if(len) ++res;
		i=j;
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1020
import itertools

n,k=map(int,input().split())
d=[]
a=[]
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int,input().split())))
a_1=itertools.chain.from_iterable(a)
print(n-len(list(set(a_1))))

Measured memory_bytes: 9224
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vvll a(n, vll(n-1));
  rep(i, n)rep(j, n-1) {cin >> a[i][j];a[i][j]--;}
  vvll ans(n, vll(n, 0));
  vll p(n, 0);
  while(1){
    ll c = 0;
    rep(i, n){
      while(p[i] < n-1){
        ll j = a[i][p[i]];
        if(a[j][p[j]]==i){
          ll k = max(ans[i][p[i]], ans[j][p[j]]);
          ans[i][p[i]+1] = k+1;
          ans[j][p[j]+1] = k+1;
          p[i]++;
          p[j]++;
          c++;
        }else{
          break;
        }
      }
    }
    if(c == 0 && *min_element(ALL(p)) < n-1){
      print(-1);
      return 0;
    }
    if(c == 0) break;
  }
  dump(ans);
  ll mans = 0;
  rep(i, n){
    chmax(mans, ans[i][n-1]);
  }
  print(mans);
}


Measured memory_bytes: 19028
def f(m):
    if z[m]==-1:
        z[m]=q[m]
        s=(m-1)&m
        while s:
            z[m]=max(z[m],f(s)+f(s^m))
            s=(s-1)&m
    return z[m]
n=input()
a=[map(int,raw_input().split()) for _ in xrange(n)]
t=1<<n
q=[0]*t
for m in xrange(t):
    s=0
    for i in xrange(n):
        if (m>>i)&1:
            for j in xrange(i):
                if (m>>j)&1:
                    q[m]+=a[i][j]
z=[-1]*t
print f(t-1)

Measured memory_bytes: 85172
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<stack>
#include<vector>
#include<cstdlib>
using namespace std;
#define y printf("vowel")
#define n printf("consonant")
#define b break
char ch;
int main(){
	cin>>ch;
	switch(ch){
		case 'a':y;b;
		case 'e':y;b;
		case 'i':y;b;
		case 'o':y;b;
		case 'u':y;b;
		default:n;
	}
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int N,K,M,f[10005],n,i,j,p;
int main()
{
	for(;scanf("%d%d%d",&N,&K,&M),N;)
	{
		memset(f,0,sizeof(f));
		for(i=j=0,n=N-1;i<n;i++,j++)
		{
			if(i==M-1)
				j++;
			f[i]=j+1;
		}
		for(p=f[M-1]?M-1:0;n>1;n--)
		{
			for(i=1;i<K;i++)
				p=f[p+1]?p+1:0;
			memmove(f+p,f+p+1,4*(n-p));
			if(f[p]==0)
				p=0;
		}
		
		printf("%d\n",f[0]);
	}
	return 0;
}

Measured memory_bytes: 660
N, Ma, Mb = map(int, input().split())

A,B,C = [0]*N,[0]*N,[0]*N

for i in range(N):
  A[i],B[i],C[i] = map(int, input().split())

table = dict()
table[(0,0)] = 0

for a,b,c in zip(A,B,C):
  updates = []
  for e,v in table.items():
    ne = (e[0]+a, e[1]+b)
    if ne not in table or table[ne] > table[e] + c:
      updates.append((ne,table[e]+c))
  table.update(updates)

max_iter = min(sum(A)//Ma, sum(B)//Mb) + 1

try:
  print(min(table[(Ma*i,Mb*i)] for i in range(1,max_iter) if (Ma*i, Mb*i) in table))
except (ValueError, KeyError):
  print(-1)

Measured memory_bytes: 7896
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n;
  cin >> n;
  vector<ll> A(n);
  vector<ll> P(n+1);
  for (auto& _a : A) cin >> _a;
  for (int i = 0; i < n; ++i) {
    P[i+1] = P[i] + A[i];
    P[i+1] %= mod;
  }
  
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += (A[i]*((P[n] - P[i+1]+mod)%mod)) % mod;
    ans %= mod;
  }
  ans %= mod;
  cout << ans << endl;

}


Measured memory_bytes: 6352
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
s,t = map(str,input().split())
ans = []
#print(s,t)
for i in range(n):
    ans.append(s[i])
    ans.append(t[i])
print("".join(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
using namespace std;

#define ll long long
#define ld long double
#define pi 3.14159265359;

// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 特定コンテナの中から特定の値をカウントする
#define _count(v,value) count(v.begin(),v.end(),value)

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//                                                              member.emplace(2)とかも同じ
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }
// 最大公約数
static int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
// 最小公倍数
static int lcm(int a, int b) { return a * b / gcd(a, b); }
// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);

// UINT32_MAX
// 4294967295 ≒ 4 * 1e9 


/*

*/
// ABC 162 B
// https://atcoder.jp/contests/abc162/tasks/abc162_b
int main()
{
	uint32_t n;
	cin >> n;

	uint64_t result = 0;
	for (uint32_t i = 1; i <= n; i++) {
		if (!(i % 3)) { continue; }
		if (!(i % 5)) { continue; }
		result += i;
	}
	printf("%llu\n", result);
	return 0;
}


Measured memory_bytes: 3704
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
   char name[100];
   int t;
}P;

int head,tail,n;
P Q[LEN];

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a,int b){return a < b ? a : b;}

int main(){
  int q,elaps = 0;
  int c,i;
  P u;
  scanf("%d %d",&n,&q);

  for(int i = 1;i <= n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head = 1,tail = n + 1;
  while(head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0){
        enqueue(u);
    }else{
       printf("%s %d\n",u.name,elaps);
    }
  }
   return 0;
}


Measured memory_bytes: 12840
#include <stdio.h>
#define N 100
int main(){
	int n,key,i,j,k;
	scanf("%d", &n);
	int array[n];
	for(i=0; i<n; i++){
		scanf("%d", &array[i]);
	}
	for(k=0; k<n; k++){
		if(k == n-1){printf("%d\n", array[k]);}
		else{printf("%d ", array[k]);}
	}
	for(i=1; i<n; i++){
		key = array[i];
		j = i-1;
		while((j>=0) && (array[j]> key)){
			array[j+1] = array[j];
			j--;
		}
		array[j+1] = key;
		for(k=0; k<n; k++){
			if(k == n-1){printf("%d\n", array[k]);}
			else{printf("%d ", array[k]);}
		}
	}
	return 0;
}

Measured memory_bytes: 596
from itertools import*
s,k=open(0)
k,x=int(k),0
g=[len(list(v))for _,v in groupby(s)]
for c in g:x+=c//2
x*=k
if(s[0]==s[-2])*g[0]%2&g[-2]%2:x+=k//2if-len(s)==~g[0]else k-1
print(x)

Measured memory_bytes: 38384
#include<iostream>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

int a, b, c;

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

    bool flag = false;
    REP(i, 1000){
        if((a*(i+1))%b == c){
            flag = true;
            break;
        }
    }
    if(flag){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int add(int a, int b){
    return (a + b) % mod;
}

int sub(int a, int b){
    return (a - b + mod) % mod;
}

int mul(int a, int b){
    return ll(a) * b % mod;
}

int pow(int a, int n){
    int b = a;
    int s = 1;
    while(n){
        if(n & 1){
            s = mul(s, b);
        }
        b = mul(b, b);
        n >>= 1;
    }
    return s;
}

int inv(int a){
    return pow(a, mod - 2);
}

void comb(int a, int* p){
    p[0] = 1;
    rep(i, a){
        p[i + 1] = mul(mul(p[i], a - i), inv(i + 1));
    }
}

int n;
int a[100001];
int s[100000];
int p[100002];
int q[100001];

int main(){
    cin >> n;
    rep(i, n + 1){
        cin >> a[i];
    }

    fill_n(s, n, -1);
    int k;
    rep(i, n + 1){
        if(s[a[i] - 1] != -1){
            k = n - (i - s[a[i] - 1]);
            break;
        }
        s[a[i] - 1] = i;
    }

    comb(n + 1, p);
    comb(k, q);
    rep(i, n + 1){
        cout << sub(p[i + 1], q[i]) << endl;
    }    
    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
void solve() {
	int n;
	cin >> n;

	int start = 1000;
	while (start < n) {
		start += 1000;
	}
	cout << start - n;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	solve();
}

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

int main(){
  int N;
  cin>>N;
 double A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int i=0;i<N-1;i++){
    sort(A,A+N);
    A[0]=(A[0]+A[1])/2;
    A[1]=1001;
  }
  cout<<A[0]<<endl;
}

Measured memory_bytes: 3656
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;
ll gcd(ll a,ll b) {//a>b
	if (a < b)swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
int main() {
	ll N;
	cin >> N;
	vector<ll> num(N);
	for (int i = 0; i < N; i++) cin >> num[i];
	ll now = 0;
	ll cnt = 0;
	ll ans = 0;
	while (now < N) {
		while (now < N-1) {
			if (num[now] >= num[now + 1]) {/*5 10 4 8 7 3*/
				cnt++;
				now++;
			}
			else break;
		}
		ans = max(cnt, ans);
		cnt = 0;
		now++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<double, double> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;

//ll bit[200010];
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		t = max(bit[i], t);
		i -= i & -i;
	}
	return t;
}

void update(ll i, ll x)
{
	i += 1;
	while (i <= 200005)
	{
		bit[i] = max(bit[i], x);
		i += i & -i;
	}
}*/

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

/*ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
	//毎回オーダーlog(n)かかる
}*/

/*void kaijo() {
	kai[0] = 1;
	for (ll i = 1; i <= 3004; i++) {
		kai[i] = kai[i - 1] * i % mod;
	}
}*/

ll N, K;
ll t[100010], d[100010];
vector<ll> syurui[100010];
vector<P> vec;
vector<ll> res;
ll syu, ans;
map<ll, ll> mp;
priority_queue<ll, vector<ll>, greater<ll>> que;

void solve() {
	cin >> N >> K;
	rep(i, N) {
		cin >> t[i] >> d[i];
		syurui[t[i]].pb(d[i]);
		vec.push_back(P(d[i], t[i]));
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	rep(i, K) {
		ans += vec[i].first;
		if (mp[vec[i].s] == 0) {
			mp[vec[i].s]++;
			syu++;
		}
		else {
			que.push(vec[i].f);
		}
	}
	res.pb(ans + syu * syu);
	for (ll i = K; i < N; i++) {
		if (que.size() == 0) break;
		if (mp[vec[i].s] == 0) {
			mp[vec[i].s]++;
			syu++;
			ans -= que.top(); que.pop();
			ans += vec[i].first;
			res.pb(ans + syu * syu);
		}
	}
	for (ll a : res) {
		ans = max(ans, a);
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 12144
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
#include<cctype>
#include<cstdio>
using namespace std;

int main(){
  int cnt=0;
  string w,t,end="END_OF_TEXT";
  
  getline(cin,w);
  transform(w.begin(),w.end(),w.begin(), ::toupper);
  while(cin >> t){
    if(t==end) break;
    transform(t.begin(),t.end(),t.begin(), ::toupper);
    if(t==w){ cnt++;}
  }
  cout<<cnt<<endl;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  long long W, H, x, y;
  cin >> W >> H >> x >> y;

  double ans;
  ans = (W * H) / 2.0;
  if (x == 0 || x == W || y == 0 || y == H) {
    printf("%.10f", ans);
    cout << " " << 0 << endl;
    return 0;
  } else if (2*x == W && 2*y == H) {
    printf("%.10f", ans);
    cout << " " << 1 << endl;
    return 0;
  } else {
    printf("%.10f", ans);
    cout << " " << 0 << endl;
    return 0;
  }
    
    

   


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
vector<int> E[400000];
int flag[400000];
int N,M;
bool dfs(int x){
    if(flag[x]==1) return true;
    flag[x]=1;
    for(int &to : E[x]){
        if(flag[to]>=0&&dfs(to)) return true;
    }
    flag[x]=-1;
    return false;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>M;
    string s;
    cin>>s;
    rep(i,0,M){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        if(s[a]==s[b]){
            E[N+a].pb(b);
            E[b+N].pb(a);
        }
        else{
            E[a].pb(b+N);
            E[b].pb(a+N);
        }
    }
    rep(i,0,2*N){
        if(flag[i]==0){
            if(dfs(i)){
                cout <<"Yes"<<"\n";
                return 0;
            }
        }
    }
    cout <<"No"<<"\n";
}

Measured memory_bytes: 24912
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    int a, b, d, r;
    double f;
    
    scanf("%d %d", &a, &b);
    
    d = a / b;
    
    r = a % b;
    
    f = (double)a / (double)b;
    
    printf("%d %d %f\n", d, r, f);
    
}

Measured memory_bytes: 3204
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC target ("avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define orz ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);    
#define inp freopen("input.txt","r",stdin);freopen("out.txt","w",stdout); 
ll mod=1e9+7;
void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.tie(NULL);    
    
}
const int N=2e5+5;

ll pre[N][26];
int main() {
    io();
    ll i,j,k,n,m,prev=0,cnt=0;
    string s,t;

    cin>>s>>t;
    n=s.length();
    s+=s;
    for(i=2*n-1;i>=0;i--){
        for(j=0;j<26;j++){
            if(i!=(2*n-1))
                pre[i][j]=pre[i+1][j];
            else
                pre[i][j]=2*n;
            pre[i][s[i]-'a']=i;
        }
    }
    
    prev=0;
    ll ans=-1;
    for(i=0;i<t.length();i++){
        
        k=pre[prev][t[i]-'a'];
        //cout<<k<<' ';
        if(k==2*n){
            cout<<"-1";
            return 0;
        }
        prev =  pre[prev][t[i]-'a']  + 1;
        if(prev>=n){
            cnt++;
            prev=prev-n;
        }

        
    }
    ans=cnt*(n);
    cout<<ans+prev;
}





Measured memory_bytes: 41324
n,m=map(int,input().split())
a=[0]+[int(input()) for _ in range(m)]
dp=[0]*(n+1)
dp[0]=1
j=0

if m>0:
    j+=1

if 1!=a[j]:
    dp[1]=1
elif 1==a[j]:
    dp[1]=0
    j+=1
    if j>m:
        j-=1
for i in range(2,n+1):
    if i!=a[j]:
        dp[i]=dp[i-1]+dp[i-2]
    elif i-1==a[j-1]:
        print(0)
        exit()
    else:
        j+=1
    if j>m:
        j-=1
print(dp[n]%(10**9+7))


Measured memory_bytes: 470264
import java.util.Scanner;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.nextLine();
    String[] strAry = str.split("");
    
    int count = 0;
    if(strAry[0].equals("1")) count++;
    if(strAry[1].equals("1")) count++;
    if(strAry[2].equals("1")) count++;    
    System.out.println(count);
    
    return;
  }
}

Measured memory_bytes: 23764
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int s[10];
int main(){
	int n,num;
	scanf("%d",&n);
	memset(s,0,sizeof(s));
	int sum = 0;
	int SUM = 0;
	//int s1 = 0,s2 = 0,s3 = 0,s4 = 0,s5 = 0, s6 = 0,s7 = 0,s8 = 0,s9 = 0;
	while(n--){
		scanf("%d",&num);
		if(num>=1&&num<=399){
			s[0]++;
		}
		else if(num>=400&&num<=799){
			s[1]++;
		}
		else if(num>=800&&num<=1199){
			s[2]++;
		}
		else if(num>=1200&&num<=1599){
			s[3]++;
		}
		else if(num>=1600&&num<=1999){
			s[4]++;
		}
		else if(num>=2000&&num<=2399){
			s[5]++;
		}
		else if(num>=2400&&num<=2799){
			s[6]++;
		}
		else if(num>=2800&&num<=3199){
			s[7]++;
		}
		else if(num>=3200&&num<=4800){
			s[8]++;
		}
	}
	for(int i = 0; i <= 7;i++){
		if(s[i]!=0){
			sum++;
		}
	}
	if(sum==0){
		printf("1 %d",s[8]);
	}
	if(sum!=0){
		printf("%d %d",sum,sum+s[8]);
	}
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int T = array[0];
			int X = array[1];

			Console.WriteLine($"{(double)T / X}");
			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int ans=n;
    for(int i=1;i<n;i++){
        if(a[i-1]==a[i]){
            ans-=2;
            i++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	
	int a1,b1,c1;
	a1=a%2;
	b1=b%2;
	c1=c%2;
	int st=0;
	    if(a1==b1&&b1==c1)
	    {
	    	st+=0;
		}
		else if(a1==b1)
		{
			a++;
			b++;
			st++;
		}
		else if(b1==c1)
		{
			c++;
			b++;
			st++;
		}
		else if(c1==a1)
		{
			a++;
			c++;
			st++;
		}
	int ma=max(a,max(b,c));
	st+=(ma-a)/2;
	st+=(ma-b)/2;
	st+=(ma-c)/2;
	cout<<st<<endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

bool check(vector<pair<int, int>> v){
  int h = 0;
  for(auto p : v){
    int b = h+p.first;
    if(b < 0) return false;
    h += p.second;
  }
  return true;
}

signed main() {
  int N; 
  cin >> N;

  int total = 0;
  vector<pair<int, int>> plus, minus;
  REP(i, N){
    string s;
    cin >> s;
    int h = 0, b = 0;
    for(char c : s){
      if(c == '(') ++h; else --h;
      chmin(b, h);
    }

    if(h > 0) plus.emplace_back(b, h);
    else minus.emplace_back(b-h, -h);
    total += h;
  }

  sort(plus.rbegin(), plus.rend());
  sort(minus.rbegin(), minus.rend());

  if(check(plus) && check(minus) && total == 0){
    cout << "Yes" << "\n";
  }else{
    cout << "No" << "\n";
  }

  return 0;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//pair型のソート
bool compare_by_second(pair<ll,ll> a, pair<ll,ll> b){
  return a.second != b.second ? a.second < b.second : a.first < b.first;
}

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N, T; cin >> N >> T;
  vector<pair<ll,ll>> ab(N); FOR(i,N){ cin  >> ab[i].fi >> ab[i].se; }
  sort(all(ab));
  /*sort(all(ab),compare_by_second());
  reverse(all(ab));*/
  //FOR(i,N){ cout << ab[i].fi << ab[i].se << endl; }
  
  vector<ll> M(N);//b[i]以降の最大値。
  M[N-1] = ab[N-1].se;
  for(int i=N-2; i>=0; i--){
    M[i] = max(ab[i].se,M[i+1]);
  }
  
  //main
  ll ans = 0;
  vvll dp(N+1,vll(T+1,0));
  for(int i=1; i<=N; i++){//i種類目まで見る。
    for(int j=0; j<T; j++){//j分時点まででの満足度の最大値。
      if(j+ab[i-1].fi<T){
        dp[i][j+ab[i-1].fi] = max(dp[i][j+ab[i-1].fi],dp[i-1][j]+ab[i-1].se);
      }
      dp[i][j] = max(dp[i][j],dp[i-1][j]);
    }
  }
  for(int i=1; i<=N-1; i++){
    ans = max(ans,dp[i][T-1]+M[i]); 
  }
  ans = max(ans,dp[N][T-1]);
  
  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    string A, B, C;
    
    cin >> A >> B >> C;
    
    if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
    
}

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

using namespace std;

int main(void) {
    int64_t A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;
    int64_t dist = abs(B-A);
    int64_t vel = V - W;
    if(dist <= vel*T) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


from collections import deque

def main():
    '''
    l > A / 3
    3 > A / l
    '''
    N, K = mis()
    A = lmis()
    def f(l):
        k = 0
        for a in A:
            if a%l == 0:
                k += a//l - 1
            else:
                k += a//l
            if k > K:
                return False
        return True

    L = meg(f, 10**10, 0)
    print(L)



main()



Measured memory_bytes: 32268
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, err := strconv.Atoi(input())
	if err != nil {
		log.Fatalln(err)
	}
	m, err := strconv.Atoi(input())
	if err != nil {
		log.Fatalln(err)
	}
	
	if n == 1 {
		k, err := strconv.Atoi(input())
		if err != nil {
			log.Fatalln(err)
		}
		fmt.Println(k)
		return
	}

	list := make(map[int]int)

	for i := 1; i <= m; i++ {
		list[i] = 0
	}

	for i := 0; i < n; i++ {
		k, err := strconv.Atoi(input())
		if err != nil {
			log.Fatalln(err)
		}
		for j := 0; j < k; j++ {
			a, err := strconv.Atoi(input())
			if err != nil {
				log.Fatalln(err)
			}
			list[a] += 1
		}
	}

	count := 0
	for _, v := range list {
		if v == n {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
#include<stdio.h>

int main()
{   
    int A[100];
    int t,N,count=0;
    int i,j,flag=1;
    scanf("%d",&N);
    for(i=0;i<N;i++){
      scanf("%d",&A[i]);
    }
    while(flag){
      flag=0;
      for(j=N-1;j>=1;j--)
        {
	  if(A[j]<A[j-1])
            {
	      t=A[j];
	      A[j]=A[j-1];
	      A[j-1]=t;
	      flag=1;
	      count++;
            }
        }      
    }
    for(j=0;j<N-1;j++){
    printf("%d ",A[j]);
    }
    printf("%d",A[N-1]);
    printf("\n%d\n",count);
    return 0;
}



Measured memory_bytes: 2144
_ = gets
heights = [0] + gets.split.map(&:to_i) + [0]
events = []
heights.each_cons(2) do |h1, h2|
  events << [h1, h2 <=> h1]
  events << [h2, h1 <=> h2]
end
events.sort_by!(&:first)
best = k = 0
(heights.uniq - [0]).sort.each do |level|
  k += events.shift[1] while events[0][0] < level
  best = k / 2 if k / 2 > best
end
p best


Measured memory_bytes: 26184
#include<bits/stdc++.h>
using namespace std;
void *wmem;
template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  int i;
  pair<T1, T2> *arr=(pair<T1, T2> *) mem;
  for(i=0;i<N;i++){
    arr[i].first = a[i];
    arr[i].second = b[i];
  }
  sort(arr, arr+N);
  for(i=0;i<N;i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second;
  }
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char memarr[96000000];
int N;
int A[200000];
int B[200000];
int main(){
  int i, t;
  wmem = memarr;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
    }
  }
  sortA_L(N,B,A);
  t = 0;
  for(i=0;i<N;i++){
    t += A[i];
    if(t > B[i]){
      break;
    }
  }
  if(i==N){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190706-1

// --- original code ---
// int N, A[2d5], B[2d5];
// {
//   int i, t;
//   rd(N,(A,B)(N));
//   sortA(N,B,A);
// 
//   t = 0;
//   rep(i,N){
//     t += A[i];
//     if(t > B[i]) break;
//   }
// 
//   wt( if[i==N, "Yes", "No"] );
// }


Measured memory_bytes: 4352
import javax.print.attribute.HashAttributeSet;
import java.io.*;

import java.math.BigInteger;
import java.util.*;

import java.util.ArrayList;

import java.util.Scanner;


public class Main {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    static final int mod = 1000000007;

    public static int gcd(int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int k=sc.nextInt();
        int ans=0;
        ans+=Math.min(a,k)*1;
        k-=Math.min(k,a);
        ans+=Math.min(b,k)*0;
        k-=Math.min(k,b);
        ans+=Math.min(c,k)*(-1);
        k-=Math.min(k,c);
        System.out.println(ans);




    }
}









Measured memory_bytes: 35556
n = int(input())
data = []
x = []

if n == 0:
    print('1')
data.append(1)
if n == 1:
    print('1')
data.append(1)

if n >= 2:
    for i in range(2, n+1):
    #print(sum(data[i-2:i+1]))
    #print(data[1])
    #data.append(data[i])
        x = sum(data[i-2:i+1])
        data.append(x)
    #print(i, x)
        i = i + 1
    print(x)


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

int main(){
   ll a,b,c,i;
   cin>>a>>b>>c;
   vector<ll> v;
   ll k = max(a,b);
   for(i=1;i<=k;i++){
      if(a%i==0&&b%i==0){
         v.push_back(i);
      }
   }
   cout<<v[v.size()-c]<<endl;

   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f(int n){
  if(n%2==0){
    return n/2;
  }
  else return 3*n+1;
}
int main()
{
  int s;
  cin>>s;
  set<int> a;
  a.insert(s);
  int tmp=1;
  while(1){
    s=f(s);
    a.insert(s);
    tmp++;
    if(tmp!=a.size()){
      cout<<a.size()+1;
      return 0;
    }
  }
}

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

int main() {
    int N, K;
    cin >> N >> K;
    int p[N];
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }
    sort(p, p + N);
    int ans = 0;
    for (int i = 0; i < K; i++) {
        ans += p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3560
#define _CRT_SECURE_NO_WARNINGS

//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
#ifdef DEBUG
	
#endif
	int ans = 1;
	int N, K;
	scanf("%d %d", &N, &K);

	int i;
	for (i = 0; i < N; i++) {
		if (ans > K) {
			ans += K;
		}
		else {
			ans *= 2;
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
A = list(map(int, input().split()))
A.sort()

def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return (fact[n] * factinv[r] * factinv[n-r])%mod

mod=10**9 + 7
fact=[1,1]
factinv=[1,1]
inv=[0,1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)
ans=0
for i in range(N-K+1):
    ans+=(A[-i-1]-A[i])*cmb(N-i-1,K-1,mod)
    ans%=mod
print(ans)

Measured memory_bytes: 72868
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn consume_num(target: u64,num: u64) -> u64 {
    if target <= num {return 1};
    if target % num != 0 {
        target / num + 1
    } else {
        target / num
    }
}

fn main() {
    input!(
        n: u64,
        a: u64,
        b: u64,
        c: u64,
        d: u64,
        e: u64,
    );

    let (count,_,_) = vec![a,b,c,d,e].iter().fold((0,a,0),|(count,min,delay),current|
        if min > *current {
            let count = count + consume_num(n - (count - delay) * current,*current);
            (count, *current, delay + 1)
        } else {
            let count = count + consume_num(n - (count - delay) * min,*current);
            (count, min, delay + 1)
        }
    ); 
    println!("{:?}",count);

}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++){
        if(0==i%k){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}

Measured memory_bytes: 3624
/*
	Name:
	Author: xiaruize
	Date:
*/

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

int main()
{
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	long long a,b,k;
	cin>>a>>b>>k;
	if(a+b<=k)
	{
		cout<<"0 0"<<endl;
		return 0;
	 } 
	 else{
	 	if(k>a)
	 	{
	 		cout<<"0"<<' '<<b-(k-a)<<endl;
	 		return 0;
		 }
		 else
		 {
		 	cout<<a-k<<' '<<b<<endl;
		 	return 0;
		 }
	 }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int x, y, z;
int main(){
  cin >> x >> y >> z;
  cout << (x-z)/(y+z) <<endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb push_back
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7; ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

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

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
	a = a%mod;
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

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

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}
template <typename T>
void max_self(T &a, T b ){
	a = max(a, b);
}

bool is_palin(string s){
	string t=s;
	reverse(t.begin(),t.end());
	return t==s;
}

int main()
{
    fast;
    int t;
    //~ cin>>t;
    t=1;
    
    while(t--){
			string s;
			cin>>s;
			ll n = s.length();
			if(is_palin(s) and is_palin(s.substr(0,(n-1)/2)) and is_palin(s.substr(n/2+1)))
				cout<<"Yes";
			else cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
import heapq
 
n = int(input())
a = Counter(map(int, input().split()))
 
x = []
for k in a:
    if a[k] > 1:
        x.append(-(a[k] - 1))
 
heapq.heapify(x)
 
while len(x) > 1:
    u = abs(heapq.heappop(x))
    v = abs(heapq.heappop(x))
    n -= min(v, u) * 2
    d = abs(u - v)
    if d > 0:
        heapq.heappush(x, -d)
 
if len(x) > 0:
    p = abs(heapq.heappop(x))
    n -= p + p % 2
 
print(n)

Measured memory_bytes: 22636