akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

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

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}

int main() {
  int k, a, b; cin >> k >> a >> b;
  bool flag = false;
  for (int i = a; i <= b; i++) if (i % k == 0) flag = true;
  if (flag) cout << "OK";
  else cout << "NG";
}

Measured memory_bytes: 3596
#include <stdio.h>

#define MAX 2000

int solve(int *,int,int,int);

int main(void){

  int n,q,i;
  int A[MAX],M[MAX],S[MAX];

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&M[i]);
  }

  for(i = 0;i < q;i++){
    S[i] = solve(A,n,0,M[i]);
    if(S[i] >= 1){
      printf("yes\n");
    }else if(S[i] == 0){
      printf("no\n");
    }
  }
  return 0;
}



int solve(int *A,int n,int i,int M){
  int res = 0;
  if(M == 0) return 1;
  if(i >= n) return 0;

  res = solve(A,n,i + 1,M) + solve(A,n,i + 1,M - A[i]);
  return res;
}
  



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  void solve() {
    i64 n, m, k;
    cin >> n >> m >> k;
    deg[0] = 1;
    for (int i = 1; i < maxn; ++i) deg[i] = deg[i - 1] * i % MOD;
    invdeg[maxn - 1] = pw(deg[maxn - 1], MOD - 2);
    for (int i = maxn - 2; i >= 0; --i) invdeg[i] = invdeg[i + 1] * (i + 1) % MOD;
    i64 ans = 0;
    for (int i = 0; i <= k; ++i) {
      i64 cur = m * pw(m - 1, n - i - 1) % MOD * C(n - 1, i) % MOD;
      ans = (ans + cur) % MOD;
    }
    cout << ans;
  }
  i64 C(int a, int b) {
    return deg[a] * invdeg[b] % MOD * invdeg[a - b] % MOD;
  }
  i64 deg[maxn];
  i64 invdeg[maxn];
  i64 pw(i64 a, i64 b) {
    i64 c = 1;
    while (b) {
      if (b & 1ll) c = c * a % MOD;
      a = a * a % MOD;
      b >>= 1;
    }
    return c;
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

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

using namespace __gnu_pbds;
using namespace std;
 
#define F               first
#define S               second
#define ll              long long int
#define PB              push_back
#define MP              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pqb             priority_queue<ll>
#define pqs             priority_queue<ll,vi,greater<int> >
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define W(x)            ll x; cin>>x; while(x--)
#define REP(i,n)          for(ll i=0; i<n; ++i) 
#define FOR(i,a,b)      for(ll i=a; i<=b; i++)
#define FORD(i,a,b)     for(ll i=a; i>=b; --i)
#define deb(x)          cout<< #x << " " << x << endl; 
#define MEM(a,b)        memset(a, b, sizeof(a));
#define PI              3.1415926535897932384626433832795
typedef tree<int,null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update> indexed_set;

ll powll(ll b, ll p, ll md)
{
    ll ans = 1;
    REP(i,p) ans = ans * b % md;
    return ans;
}

int main() 
{
    // clock_t start, end; 
    ios::sync_with_stdio(0);
    cin.tie(0);
    // start = clock();
    // write code here!
    ll a,b;
    cin>>a>>b;
    cout<<a*b;
    // end = clock();
    // double time_taken = double(end - start) / double(CLOCKS_PER_SEC); 
    // cout << "\nTime taken by program is : " <<ps(time_taken,10)<< " sec " << endl; 
    return 0;
}

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


using namespace std;

int main(){
  int n,p,pp,flag;
  while(1){
    cin >> n >> p;
    pp=p;
    flag=0;
    if (n==0) return 0;
    vector<int> hv(n,0);
    for(int turn=0;turn<1000000;turn++){
      if (flag==1) break;
      if (p>0){
        p--;
        hv[turn%n]++;
        if (p==0 && hv[turn%n]==pp){
          cout << turn % n << endl;
          flag=1;
        }
      } else {
        p = hv[turn%n];
        hv[turn%n]=0;
      }
    }
  }
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define REP(I,N) for(int I=0;I<N;++I)
#define REPP(I,A,B) for(int I=A;I<B;++I)
#define RI(X) scanf("%d",&X)
#define RII(X,Y) scanf("%d%d",&X,&Y)
#define RIII(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define DRI(X) int X;scanf("%d",&X)
#define DRII(X,Y) int X,Y;scanf("%d%d",&X,&Y)
#define DRIII(X,Y,Z) int X,Y,Z;scanf("%d%d%d",&X,&Y,&Z)
#define MS0(X) memset(X,0,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define RS(X) scanf("%s",X);
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;

int r,c,n;

int side(int x,int y){
	if(x==0)return y;
	if(y==c)return c+x;
	if(x==r)return c+r+(c-y);
	if(y==0)return c+r+c+(r-x);
	return -1;
}

int mn[200009][18];
int mx[200009][18];

int qry(int x,int y,bool b){
	int l=y-x+1;
	int p2=31-__builtin_clz(l);
	//printf("Q%d %d\n",l,p2);
	if(b)return max(mx[x][p2],mx[y-(1<<p2)+1][p2]);
	return min(mn[x][p2],mn[y-(1<<p2)+1][p2]);
}

vector<PII> pairs;
vector<int> points;

int main(){
	RIII(r,c,n);
	REP(i,n){
		DRII(x1,y1);DRII(x2,y2);
		int s1=side(x1,y1),s2=side(x2,y2);
		if(s1!=-1&&s2!=-1){
			points.PB(s1);points.PB(s2);
			if(s1>s2)swap(s1,s2);
			pairs.PB(MP(s1,s2));
		}
	}
	sort(ALL(points));
	REP(i,SZ(pairs)){
		pairs[i].F=lower_bound(ALL(points),pairs[i].F)-points.begin();
		pairs[i].S=lower_bound(ALL(points),pairs[i].S)-points.begin();
		//printf("%d %d\n",pairs[i].F,pairs[i].S);
	}
	n=SZ(pairs);
	REP(i,n){
		mn[pairs[i].F][0]=mx[pairs[i].F][0]=pairs[i].S;
		mn[pairs[i].S][0]=mx[pairs[i].S][0]=pairs[i].F;
	}
	//puts("ST");
	REPP(j,1,18){
		for(int i=0;i+(1<<j)-1<2*n;i++){
			mn[i][j]=min(mn[i][j-1],mn[i+(1<<(j-1))][j-1]);
			mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
			//printf("%d ",mx[i][j]);
		}//puts("");
	}
	bool legit=1;
	REP(i,n){
		if(pairs[i].F+1==pairs[i].S)continue;
		int mx=qry(pairs[i].F+1,pairs[i].S-1,1);
		int mn=qry(pairs[i].F+1,pairs[i].S-1,0);
		//printf("%d %d\n",mn,mx);
		if(mn<pairs[i].F||mx>pairs[i].S){
			legit=0;
		}
	}
	if(legit)puts("YES");
	else puts("NO");
}


Measured memory_bytes: 30188
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define debug1(a) cout<<#a<<" "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<" "#c<<" "<<(c)<<endl;
typedef long double ld;
ll mod1 = 1e9 + 7;
long long mod(long long x) {
	return ((x % mod1 + mod1) % mod1);
}
long long add(long long a, long long b) {
	return mod(mod(a) + mod(b));
}
long long mul(long long a, long long b) {
	return mod(mod(a) * mod(b));
}
long long minu(long long a, long long b) {
	return mod(mod(a) - mod(b));
}
ll power(ll x, ll y, ll p)
{
	ll res = 1;     // Initialize result

	x = x % p; // Update x if it is more than or
	// equal to p

	if (x == 0) return 0; // In case x is divisible by p;

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res * x) % p;

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x * x) % p;
	}
	return res;
}
void solve()
{
	ll n;
	cin >> n;
	if (n == 1)
	{
		cout << 0 << endl;
		return;
	}
	else if (n == 2)
	{
		cout << 2 << endl;
		return;
	}
	ll ans = minu(add(power(10, n, mod1), power(8, n, mod1)), mul(2, power(9, n, mod1)));
	cout << ans << endl;


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

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

using namespace std;


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

    vector<int> V(N), C(N);

    for(int i = 0; i < N; i++){
	cin >> V.at(i);
    }
    for(int i = 0; i < N; i++){
	cin >> C.at(i);
    }

    int v = 0;
    for(int i = 0; i < N; i++){
	if(V.at(i) > C.at(i)){
	    v += V.at(i) - C.at(i);
	}
    }

    cout << v << endl;
}


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

const int INF = INT_MAX;
const int MAXN = 5000;
const int B = 500;
const int BNUM = MAXN / B;

int n, m;
pair<int, int> ps[MAXN];
int x[MAXN], y[MAXN];
vector<int> bucket[BNUM];

int main() {
  while(scanf("%d%d", &n, &m) != EOF) {
    for(int i = 0; i < n; ++i) {
      scanf("%d%d", &ps[i].first, &ps[i].second);
    }
    sort(ps, ps+n);
    fill(bucket, bucket + BNUM, vector<int>());
    for(int i = 0; i < n; ++i) {
      x[i] = ps[i].first;
      y[i] = ps[i].second;
      bucket[i/B].push_back(y[i]);
    }
    for(int b = 0; b < BNUM; ++b) {
      sort(bucket[b].begin(), bucket[b].end());
    }
    while(m--) {
      int s, t, u, v; 
      scanf("%d%d%d%d", &s, &t, &u, &v);
      int l = lower_bound(x, x+n, s) - x;
      int r = upper_bound(x, x+n, u) - x;
      int res = 0;
      while(l < r && l % B != 0) {
        res += (t <= y[l] && y[l] <= v);
        ++l;
      }
      while(l < r && r % B != 0) {
        --r;
        res += (t <= y[r] && y[r] <= v);
      }
      while(l < r) {
        int b = l / B;
        res += upper_bound(bucket[b].begin(), bucket[b].end(), v)
          - lower_bound(bucket[b].begin(), bucket[b].end(), t);
        l += B;
      }
      printf("%d\n", res);
    }
  }
  return 0;
}

Measured memory_bytes: 1308
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,X,Y;
  cin>>n>>m>>X>>Y;
  vector<int> x(n+1);
  vector<int> y(m+1);
  for(int i=0;i<n;i++)cin>>x[i];
  for(int i=0;i<m;i++)cin>>y[i];
  x[n]=X; y[m]=Y;
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  if(x[n]<y[0]){ 
    cout<<"No War"<<endl;
  }
  else{
    cout<<"War"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define LLI long long int
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename T> T gcd(T a, T b){a = abs(a); b = abs(b); if(a<b) swap(a,b); while(b>0){a %= b; swap(a,b);} return a;}
template <typename T> T lcm(T a, T b){return (1LL * a * b) / gcd(a,b);}
template <typename T, typename U> P<T,U> operator+(const P<T,U> &a, const P<T,U> &b){return {a.first + b.first, a.second + b.second};}
template <typename T, typename U> P<T,U> operator-(const P<T,U> &a, const P<T,U> &b){return {a.first - b.first, a.second - b.second};}

// n以上の最小の2の冪
template <typename T = int>
T minimum_power_2(T n){
  T i = 1;
  while(i<n) i = i<<1;
  return i;
}

template <typename T>
class SegmentTree{
private:
  int size;
  vector<T> vec;
  T e;
  function<T(T,T)> f, upd;
  
  int aux(int x, int y, int i, int l, int r){
    if(r<=x || y<=l) return e;
    else if(x<=l && r<=y) return vec[i];
    else return f(aux(x,y,i*2+1,l,(l+r)/2), aux(x,y,i*2+2,(l+r)/2,r));
  };

public:
  SegmentTree(int n, T e, function<T(T,T)> f, function<T(T,T)> upd):
    size(minimum_power_2(n)*2-1), vec(size, e), f(f), e(e), upd(upd){}
  void update(int i, T x){
    int j = i+(size+1)/2-1;
    vec[j] = upd(vec[j], x);
    --j;
    while(j>=0){
      vec[j/2] = f(vec[(j/2)*2+1], vec[(j/2)*2+2]);
      (j /= 2) -= 1;
    }
  }

  int find(int x, int y){return aux(x,y,0,0,(size+1)/2);}
};

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

  int n,q; cin >> n >> q;
  SegmentTree<int> rsq(n, 0, [](int a, int b){return a+b;}, [](int a, int b){return a+b;});

  REP(i,q){
    int com,x,y; cin >> com >> x >> y;
    if(com){
      cout << rsq.find(x-1,y) << endl;
    }else{
      rsq.update(x-1,y);
    }
  }
  
  return 0;
}



Measured memory_bytes: 3920
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    ll n, K;
    scanf("%lld%lld", &n, &K);
    n = n % K;
    printf("%lld\n", MIN(n, K - n));


    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mx = 1e6 + 9;
vector<ll>adj[mx];
bitset<mx>mark;
ll dist[mx];

int main() {
    ll n, m; cin >> n >> m;
    for(ll i = 0; i < m; i++) {
        ll u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    bool nafisa = false;
    ll source = 1;
    mark[source] = 1;
    queue<ll>q;
    q.push(source);
    while(!q.empty()) {
        auto u = q.front();
        q.pop();
        if(u == n && dist[u] == 2) {
            nafisa = true;
            break;
        }
        for(auto v : adj[u]) {
            if(!mark[v]) {
            mark[v] = 1;
            dist[v] = dist[u] + 1;
            q.push(v);
            }
        }
    }
    if(nafisa) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;

}

Measured memory_bytes: 36816
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a!=b && a!=c && b!=c)
        printf("3\n");
    else if(a==b && a!=c && b!=c)
        printf("2\n");
    else if(a!=b && b==c)
        printf("2\n");
    else if(a!=b && a==c)
        printf("2\n");
    else if(a==b && b==c)
        printf("1\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<math.h>
#include<queue>
#include<algorithm>
#define ll long long
using namespace std;
int tb[10005];
void gettb() {
	for (int x = 1; x <= 100; x++) {
		for (int y = 1; y <= 100; y++) {
			for (int z = 1; z <= 100; z++) {
				int a = x * x + y * y + z * z + x * y + x * z + z * y;
				if (a <= 10000)tb[a]++;
			}
		}
	}
}
int main() {
	int n;
	cin >> n;
	gettb();
	for (int i = 1; i <= n; i++)cout << tb[i] << '\n';
	return 0;
}

Measured memory_bytes: 3232
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
typedef pair<int ,int> P;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,b,a[101010]={},tn;
	P p[101010]={};
	priority_queue<P> pq;
	cin>>n;
	tn=n;
	FOR(i,0,n){
		cin>>a[i];
		//pq.push(make_pair());
	}
	sort(a,a+n);
	//FOR(i,0,n)cout<<a[i]<<" ";
	FOR(i,0,n){
		int t=upper_bound(a,a+n,a[i])-lower_bound(a,a+n,a[i]);
		pq.push(make_pair(t,a[i]));
		i=upper_bound(a,a+n,a[i])-a-1;

	}
	while(1){
		P pp=pq.top(),pp2;
		pq.pop();
		if(pp.ST>=3){
			tn-=2;
			pp.ST-=2;
		}else if(pp.ST==2){
			pp2=pq.top();
			pq.pop();
			if(pp2.ST==2){
				tn-=2;
				pp.ST--;
			}else{
				tn-=2;
				break;
			}

		}else{
			break;
		}
		if(pp.ST!=0)pq.push(pp);
	}
	cout<<tn<<endl;

    return 0;
}


Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/
 
const int mx=200010;
const ll mod=1e9+7;

vector<ll> p(60,0);
vector<ll> h(60,0);

ll rec(ll n, ll x){
  if(n==0) return 1;
  if(x<=1){ return 0; }
  if(1<x && x<=1+h[n-1]){ return rec(n-1,x-1); }
  if(x==1+h[n-1]+1){ return p[n-1]+1; }
  if(1+h[n-1]+1<x && x<=1+h[n-1]+1+h[n-1]){ return p[n-1]+1+rec(n-1,x-2-h[n-1]); }
  return 1+p[n-1]*2;
}

int main() {
  ll n,x;
  cin >> n >> x;
  p[0] = h[0] = 1;
  rep(i,n){
    p[i+1] = p[i]*2+1;
    h[i+1] = h[i]*2+3;
  }
  ll ans = rec(n,x);
  cout << ans << endl;
  return 0;
}

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    string ans;
    for (int i = 0; i < n; i++) {
        if (i + m - 1 >= n) break;
        bool pass = false;
        string tmp = s;
        for (int j = 0; j < m; j++) {
            if (s[i + j] != '?' && s[i + j] != t[j]) {
                pass = true;
                break;
            } else {
                if (s[i + j] == '?') {
                    tmp[i + j] = t[j];
                }
            }
        }
        if (pass) continue;
        for (int i = 0; i < n; i++) {
            if (tmp[i] == '?') tmp[i] = 'a';
        }
        if (ans.empty()) ans = tmp;
        ans = min(ans, tmp);
    }
    if (ans.empty()) cout << "UNRESTORABLE" << '\n', exit(0);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
using namespace std;
const int MOD = (int)1e9+7;
void solve()
{
   double B;
   ll A;
   cin>>A>>B;
   ll b=round(B*100);
   long long int Result=(A*b)/100;
   cout<<Result<<endl;
}
int  main()
{
    IOS
        solve();
    return 0;
}



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

int main()
{
  char c[1000];
  int d=0;
  cin>>c;
  char a=c[0],b=c[strlen(c)-1];
  d=strlen(c)-2;
  cout<<a<<d<<b<<endl;
  return 0;
}


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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) {
  for (; a; swap(b %= a, a));
  return b;
}
inline ll lcm(ll a, ll b) {
  return a * (b / gcd(a, b));
}

signed main() {
    ll N, X;
    cin >> N >> X;
    ll a = X, b = N-X;
    if (a < b) swap(a, b);
    ll ans = N;
    while (b) {
        ans += 2*b*(a/b);
        ll c = a%b;
        a = b;
        b = c;
    }
    ans -= a;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np

N,M,X = map(int,input().split())
C = [0] * N
A = [None] * N
for i in range(N):
  c,*a = map(int,input().split())
  C[i] = c
  A[i] = a

INF = 10 ** 9
ans = INF
import itertools
for i in range(1,N + 1):
  for comb in itertools.combinations(range(N),i):
    cost = 0
    skills = [0] * M
    for c in comb:
      cost += C[c]
      for j in range(M):
        skills[j] += A[c][j]
    if cost >= ans:
      continue
    for s in skills:
      if s < X:
        break
    else:
      ans = cost

if ans == INF:
  print(-1)
else:
  print(ans)        


Measured memory_bytes: 27152
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, a, b = na()
m = n//(a+b)
r = n%(a+b)
print(a*m+min(r, a))


Measured memory_bytes: 38384
#include <iostream>
using namespace std;
struct node{
	int parent;
	bool marked;
};
node V[100000];
int query(int v){
	if(V[v].marked) return v+1;
	else return query(V[v].parent);
}
int main(){
	int n,q;
	while(cin >> n >> q,n){
		V[0].marked = true;
		for(int i = 1; i < n; ++i){
			int p;
			cin >> p;
			V[i].parent = --p;
			V[i].marked = false;
		}
		long long sum = 0;
		for(int i = 0; i < q; ++i){
			char q;int v;
			cin >> q >> v;
			--v;
			if(q == 'M') V[v].marked = true;
			else{
				sum += query(v);
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1932
#include <iostream>

using namespace std;

int main()
{
	int a,b,c,x,y;
	long long t=0;
	cin>>a>>b>>c>>x>>y;

	if (a + b > 2 * c)
	{
		if (x < y)
		{
			t += 2 * x * c;
			if ((y-x) * b > (y-x)*2*c)
			{
				t += 2 * (y-x) * c;
			}
			else t += (y-x)*b;
		}	
		else
		{
			t += 2 * y * c;	
			if ((x-y) * a > (x-y)*2*c)
			{
				t += 2 * (x-y) * c;
			}
			else t += (x-y)*a;
		} 
	}
	else
	{
		t += a*x + b*y;
	}
	cout << t << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("%s = %d\n", #x, x)
#define debug2(x, y) printf("%s = %d, %s = %d\n", #x, x, #y, y)
#define debug3(x, y, z) printf("%s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z)
#define debug4(x, y, z, t) printf("%s = %d, %s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z, #t, t)
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 100005;

int n, L[MAXN], R[MAXN], A[MAXN];
char s[MAXN];

int main() {
    scanf(" %s", s);
    n = strlen(s);

    for (int i = n - 2; i >= 0; i--) {
        if (s[i + 1] == 'R') {
            R[i] = 1 + R[i + 1];
        }
    }

    for (int i = 1; i < n; i++) {
        if (s[i - 1] == 'L') {
            L[i] = 1 + L[i - 1];
        }
    }

    for (int i = 0; i < n; i++) {
        if (s[i] == 'L') {
            if (L[i] % 2 == 1) {
                A[i - L[i] - 1]++;
            } else {
                A[i - L[i]]++;
            }
        } else {
            if (R[i] % 2 == 1) {
                A[i + R[i] + 1]++;
            } else {
                A[i + R[i]]++;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        printf("%d ", A[i]);
    }

    printf("\n");

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, M, ans;
    int minVal, maxVal;
    cin >> N >> M;
    minVal = INT_MAX;
    maxVal = 0;
    REP(int,i,0,M){
        int L, R;
        cin >> L >> R;
        minVal = min(minVal,R);
        maxVal = max(maxVal,L);
        //cout << maxVal << endl;
        //cout << minVal << endl;
    }
    ans = minVal - maxVal + 1;
    if ( ans < 0 ) ans = 0;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 105
#define __TRUE "YES"
#define __FALSE "NO"
#define cout(x) cout << (x) << endl
#define reps(i,s,n) for(i=s;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
char S[MAX][MAX];
int main() {
  int H,W;
  cin >> H >> W;
  for(int h=0;h<H;h++) {
    for(int w=0;w<W;w++) {
      cin >> S[h][w];
    }
  }
  for(int h=0;h<H;h++) {
    for(int w=0;w<W;w++) {
      cout << S[h][w];
    }
    cout << endl;
    for(int w=0;w<W;w++) {
      cout << S[h][w];
    }
    cout << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))

int main() {
     ll x, n;
     cin >> x >> n;
     if(n == 0) {
        cout << x << endl;
        return 0;
     }
     vector<ll>v;
     set<ll>s;
     ll d = 0, p = INT_MAX;
     for (ll i = 0; i < n; i++) {
        ll xx;
        cin >> xx;
        v.push_back(xx);
        s.insert(xx);
        if(abs(x- xx) < p) {
            p = abs(x - xx);
            d = xx;
        }
     }

     ll k = d;
    for (int i = 0; i < 100; i++) {
        if(s.count(d) == 1) {
            d++;
        }
        else {
            break;
        }
    }
    for (int i = 0; i < 100; i++) {
        if(s.count(k) == 1) {
            k--;
        }
        else {
            break;
        }
    }
    if(abs(k - x) == abs(d - x)) {
        cout << min(d, k) << endl;
    }
    else if(abs(k - x) < abs(d - x)) {
        cout << k << endl;
    }
    else {
        cout << d << endl;
    }

    return 0;
}



Measured memory_bytes: 3636
import math
while True:
    n=int(input())
    if n==0:
        break
        
    s=list(map(int,input().split()))
    m=sum(s)/n
    
    X=sum([(float(s[i])-m)**2 for i in range(n)])
    alphaalpha=X/n
    print("{0:.8f}".format(math.sqrt(alphaalpha)))
    


Measured memory_bytes: 5708
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
struct node
{
	int num,size;
}now;
bool cmp(node a,node b)
{
	return a.size>b.size;
}
int main()
{
	int i,n,k,gti;
	long long ans;
	int num[200005];
	vector<node>que;
	while(~scanf("%d %d",&n,&k))
	{
		memset(num,0,sizeof(num));
		ans=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&gti);
			num[gti]++;
		}
		for(i=1;i<=n;i++)
		{
			if(num[i]>0)
			{
				now.num=i;
				now.size=num[i];
				que.push_back(now);
			}
		}
		sort(que.begin(),que.end(),cmp);
		if(k>=que.size())
		{
			printf("0\n");
		}
		else 
		{
			for(i=k;i<que.size();i++)
			{
				ans+=que[i].size;
			}
			printf("%lld\n",ans);
		}
		que.clear();
	}
	return 0;
}

Measured memory_bytes: 3188
def min(a,b); a < b ? a : b ; end
  
N = gets.to_i
z = N.to_s.size
ans = (1 .. z).inject(0) do |s, d|
  if d.even?
    s
  else
    s + min(N, 10 ** d - 1) - (10 ** (d-1) - 1)
  end
end
puts ans

Measured memory_bytes: 1788
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] arr = in.next().toCharArray();
            StringBuilder sb = new StringBuilder();
            for (char c : arr) {
                if (c == 'B') {
                    if (sb.length() != 0) {
                        sb.deleteCharAt(sb.length() - 1);
                    }
                } else {
                    sb.append(c);
                }
            }
            out.println(sb.toString());
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

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

    }

}

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

int main(){
    string s; cin >> s;
    int len = s.length();
    int c = 0;
    for(int i = 0; i < len; i++){
        if(s[i] == 'o') c++;
    }
    if(c+(15-len) >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector< vector<int> > vec(4,vector<int>(13,0));
    for(int i=0;i<n;i++){
        char k;
        int g;
        cin>>k>>g;
        int h;
        if(k=='S'){
            h=0;
        }
        if(k=='H'){
            h=1;
        }
        if(k=='C'){ 
            h=2;
        }
        if(k=='D'){
            h=3;
        }
        vec[h][g-1]++;
    }
    for(int i=0;i<4;i++){
        char k;
        if(i==0){
            k='S';
        }
        if(i==1){
            k='H';
        }
        if(i==2){
            k='C';
        }
        if(i==3){
            k='D';
        }
        for(int j=0;j<13;j++){
            if(vec[i][j]==0){
                printf("%c %d\n",k,j+1);
            }
        }
    }
}


Measured memory_bytes: 3256
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[][] s = new int[5][110];
		int n = scan.nextInt();
		for(int i = 1; i <= n; ++i) {
			s[1][i] = scan.nextInt();
		}
		for(int i = 1; i <= n; ++i) {
			s[2][i] = scan.nextInt();
		}
		int sum = 0,sum2,sum3 = 0;
		for(int i = 1; i <= n; ++i) {
			sum += s[1][i];
			sum2 = sum;
			for(int j = i;j <= n ; ++j) {
				sum += s[2][j];
			}
			if(sum > sum3) {
				sum3 = sum;
			}
			sum = sum2;
			
		}
		System.out.println(sum3);
				
		
	}
}


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

int main(){
  int n,k;
  cin >> n >> k;

  int res=1;
  rep(i,n){
    res=min(res*2,res+k);
  }
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N,D;
  scanf("%d%d",&N,&D);
  int x[D][N];
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      scanf("%d",&x[j][i]);
    }
  }
  int a;
  int b;
  int c=0;
  for(int i=0;i<N-1;i++){
    for(int k=i+1;k<N;k++){
        a=0;
      for(int j=0;j<D;j++){
        a=a+x[j][k]*x[j][k]-2*x[j][k]*x[j][i]+x[j][i]*x[j][i];
      }
        for(int l=1;l*l<=a;l++){
          if(l*l==a)
            c++;
        }
      }
    }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n ; i++)
#define For(i, a, b) for(int i = (a) ; i < (b); i++)

const int MAX_M = 100000;

int main(void){
    int N, M;
    int L[MAX_M], R[MAX_M];

    scanf("%d %d", &N, &M);

    rep(i, M){
        scanf("%d %d", &L[i], &R[i]);
    }

    int L_max = 0;
    int R_min = N;
    
    rep(i, M){
        L_max = max(L[i], L_max);
        R_min = min(R[i], R_min);
    }

    cout << max(0, R_min - L_max + 1) << endl;

    return 0;

    }

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include<ctype.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define s(a) scanf("%d",&a)
//#define p(a) printf("%d",a)

#define nl printf("\n")
#define s_p printf(" ")

#include<time.h>

int main()
{
char c[29];
scanf(" %[^\n]s",c);
int t=strlen(c);
for(int i=0;i<t;i++)
{if(c[i]==',') printf(" ");
        else printf("%c",c[i]);}



}

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

int main(){
    ll Q;
    cin >> Q;

    set<ll> se;

    while(Q--){
        ll a, x;
        cin >> a >> x;

        if(a==0){
            // insert
            se.insert(x);
            p(se.size());
        }
        else if(a==1){
            // find
            p(se.count(x));
        }
        else{
            // delete
            se.erase(x);
        }
    }

    return 0;
}


Measured memory_bytes: 12356
from fractions import gcd

A,B,C,D = list(map(int,input().split()))

lcm = C*D/gcd(C,D)

a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//int(lcm))
b = (B) - ((B)//C + (B)//D - (B)//int(lcm))
print(int(b-a))

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

int main() {
	char c;
	cin >> c;
	if ((c-'a'==0)or(c-'e'==0)or(c-'i'==0)or(c-'o'==0)or(c-'u'==0)) cout << "vowel" << endl;
	else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;


int main() {
  int N,M;
  cin >> N >> M;

  cout << pow(2,M)*(1900*M+100*(N-M));
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	short a,b;
	scanf("%d%d",&a,&b);

	if(a%3!=0&&b%3!=0&&(a+b)%3!=0){
		printf("Impossible");
	}
	else 
	{	printf("Possible");
	}
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

class Combination_Mod{
    public:
        Combination_Mod(long long MAX, long long MOD) : fact(MAX + 1), inv(MAX + 1), finv(MAX + 1), MAX(MAX + 1), MOD(MOD){
            init();
        }

        void init(){
            fact[0] = fact[1] = 1;
            finv[0] = finv[1] = 1;
            inv[1] = 1;
            for(long long i = 2; i < MAX; ++i){
                fact[i] = fact[i - 1] * i % MOD;
                inv[i] = MOD - inv[MOD % i] *  (MOD / i) % MOD;
                finv[i] = finv[i - 1] * inv[i] % MOD;
            }
        }

        long long bin(long long n, long long r){
            if(n < r || n < 0 || r < 0) return 0;
            return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD;
        }

        long long perm(long long n, long long r){
            return (bin(n, r) * fact[r]) % MOD;
        }

        long long factorial(long long n){
            return fact[n];
        }

        long long modinv(long long n){
            return inv[n];
        }

        long long modfinv(long long n){
            return finv[n];
        }

    private:
        vector<long long> fact;
        vector<long long> inv;
        vector<long long> finv;
        const long long MAX;
        const long long MOD;
};

ll N, K;
ll A[100010];
Combination_Mod cm(100010, MOD);

signed main(){
    cin >> N >> K;
    REP(i, N) cin >> A[i];
    sort(A, A + N);
    ll ans = 0;
    REP(i, N){
        ans = (ans + A[i] * cm.bin(i, K - 1) % MOD) % MOD;
    }
    REP(i, N){
        ans = (ans + MOD - A[i] * cm.bin(N - i - 1, K - 1)  % MOD) % MOD;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 6428
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll N, K;
	cin >> N >> K;
	ll l[N + 1];
	for (ll i = 0; i < N; i++) {
		cin >> l[i];
	}
	sort(l, l + N);
	reverse(l, l + N);
	ll sum = 0;
	for (ll i = 0; i < K; i++) {
		sum += l[i];
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
def d_various_sushi(N, K, Param):
    import heapq

    # 寿司をおいしさの値が大きなものからK個取る
    sushi_parameter = sorted(Param, key=lambda x: x[1], reverse=True)
    sushi_invariably_chosen = []  # ネタが被っていない場合、貪欲に取っていい
    candidate_reject = []  # ネタの種類数を増やす時に取り除く候補(priority queueで管理)
    chosen_topping = set()  # 取った寿司ネタの種類
    for i in range(K):
        t, d = sushi_parameter[i]
        if t not in chosen_topping:
            sushi_invariably_chosen.append(d)
            chosen_topping.add(t)
        else:
            heapq.heappush(candidate_reject, d)

    # 暫定的な最大値を計算しておく
    delicious_sum1 = sum(sushi_invariably_chosen)
    delicious_sum2 = sum(candidate_reject)
    topping_variety = len(chosen_topping)
    ans = delicious_sum1 + delicious_sum2 + topping_variety**2

    for i in range(K, N):
        if len(candidate_reject) == 0:
            break  # 除く寿司の候補がないので、満足度を大きくしようがない

        t, d = sushi_parameter[i]
        if t in chosen_topping:
            # ネタが被った上、おいしさがこれまで取った寿司より小さな寿司と交換する理由はない
            continue

        # 取り除いてもネタの種類数が減らない寿司の中で最もおいしさの小さいものを取り除く
        delicious_sum2 -= heapq.heappop(candidate_reject)
        # これまでに取っている寿司にないネタを持ち、最もおいしさの大きい寿司を取る
        chosen_topping.add(t)
        delicious_sum1 += d
        topping_variety += 1

        ans = max(ans, delicious_sum1 + delicious_sum2 + topping_variety**2)
    return ans

N, K = [int(i) for i in input().split()]
Param = [[int(i) for i in input().split()] for j in range(N)]
print(d_various_sushi(N, K, Param))

Measured memory_bytes: 25296
#include <cstdio>
#include <cstring>

#define MAX_N 101


/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;	
char S[MAX_N];


int main () {

	// 個数と長さの読込み
	scanf("%d %s", &N, &S);

	if(N % 2 == 1) printf("No\n");
	else if(strncmp(S, S + N / 2, N / 2) == 0)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using ul = unsigned long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
source:
    ll n;
    cin >> n;
    vector<vector<ll>> g(n);
    rep(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    vector<ll> d(n, -1);
    vector<ll> ans(n);
    vector<ll> num = {3, 1, 2};
    queue<ll> q;
    q.push(0);
    d[0] = 0;
    while (!q.empty()) {
        ll now = q.front();
        q.pop();
        rep(i, g[now].size()) {
            ll next = g[now][i];
            if (d[next] != -1) {
                continue;
            }
            d[next] = d[now] + 1;
            q.push(next);
        }
    }

    ll even = 0, odd = 0;
    rep(i, n) {
        if (d[i] % 2) {
            odd++;
        } else {
            even++;
        }
    }
    if (even > n / 3 && odd > n / 3) {
        rep(i, n) {
            if (d[i] % 2) {
                if (num[1] <= n) {
                    ans[i] = num[1];
                    num[1] += 3;
                } else {
                    ans[i] = num[0];
                    num[0] += 3;
                }
            } else {
                if (num[2] <= n) {
                    ans[i] = num[2];
                    num[2] += 3;
                } else {
                    ans[i] = num[0];
                    num[0] += 3;
                }
            }
        }
    } else if (even <= n / 3) {
        rep(i, n) {
            if (d[i] % 2 == 0) {
                ans[i] = num[0];
                num[0] += 3;
            }
        }
        rep(i, n) {
            if (d[i] % 2 == 1) {
                if (num[0] <= n) {
                    ans[i] = num[0];
                    num[0] += 3;
                } else if (num[1] <= n) {
                    ans[i] = num[1];
                    num[1] += 3;
                } else if (num[2] <= n) {
                    ans[i] = num[2];
                    num[2] += 3;
                }
            }
        }
    } else if (odd <= n / 3) {
        rep(i, n) {
            if (d[i] % 2 == 1) {
                ans[i] = num[0];
                num[0] += 3;
            }
        }
        rep(i, n) {
            if (d[i] % 2 == 0) {
                if (num[0] <= n) {
                    ans[i] = num[0];
                    num[0] += 3;
                } else if (num[1] <= n) {
                    ans[i] = num[1];
                    num[1] += 3;
                } else if (num[2] <= n) {
                    ans[i] = num[2];
                    num[2] += 3;
                }
            }
        }
    }
    rep(i, n) { cout << ans[i] << " "; }
    cout << endl;

    return 0;
}



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

int main() {
  long long n;
  cin>>n;
  vector<long long>a(n);
  for(long long i=0;i<n;i++){
    cin>>a[i];
  }
  for(long long i=n-1;i>=1;--i){
    if(a[i]>=a[i-1])continue;
    else a[i-1]-=1;
    if(a[i]<a[i-1]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

bool ch(ll n){
  string s=to_string(n);
  int k=s.size();
  bool flag3=false;
  bool flag5=false;
  bool flag7=false;
  rep(i,k){
    if(s[i]=='3'){flag3=true;continue;}
    if(s[i]=='5'){flag5=true;continue;}
    if(s[i]=='7'){flag7=true;continue;}
  }
  return flag3&&flag5&&flag7;  
}
int main() {
  int n; cin>>n;
  vector<ll> s;
  priority_queue<ll> q;
  q.push(3);
  q.push(5);
  q.push(7);
  ll cnt=0;
  while(cnt<inf){
    priority_queue<ll> p;
    swap(p,q);
    while(!p.empty()){
      ll a=p.top(); p.pop();
      s.emplace_back(a*10+3);
      s.emplace_back(a*10+5);
      s.emplace_back(a*10+7);
      q.push(a*10+3);
      q.push(a*10+5);
      q.push(a*10+7);
    }
    cnt=q.top();
  }
  sort(s.begin(),s.end());
  
  int ans=0;
  for(auto t:s){
    if(!ch(t)){continue;}
    if(t<=n){ans++;}else{break;}
  }

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


Measured memory_bytes: 1812
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
dif = abs(t-a - 0.006*h[0])
ans = 1
for i in range(1, n):
  if abs(t-a-0.006*h[i]) < dif:
    ans = i+1
    dif = abs(t-a-0.006*h[i])
print(ans)

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

#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define reset(x, y) memset(x, y, sizeof(x))
#define BUG(x) cerr << #x << " = " << (x) << endl
#define BUGP(x) cout << #x << " = " << (x)._1 << ", " << (x)._2 << endl
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};
// Head

LL a, b, n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> a >> b;

    cout << n / (a + b) * a + min(n % (a + b), a) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
   
/* brownsands :Arpit */			

void solve()
{   int n,a,b,x;
    cin >> n >> a >> b;
    x=n/(a+b);x=x*a;
    x+=min(n%(a+b),a);
    cout<<x<<endl;
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




Measured memory_bytes: 256