akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = int64_t;

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

int n;
ll a[100010];

ll hoge(){
    ll ans=0;
    ll temp = 0;
    rep(i, n){
        if(temp > 0 && temp + a[i] > 0){
            ans += abs(-1-temp-a[i]);
            temp = -1;
        }else if(temp < 0 && temp + a[i] < 0){
            ans += abs(1-temp-a[i]);
            temp = 1;
        }else if(temp + a[i] == 0){
            if(temp > 0){
                temp = -1;
            }else{
                temp = 1;
            }
            ans += 1;
        }else{
            temp += a[i];
        }
    }
    return ans;
}

void solve(){
    cin >> n;
    rep(i, n) cin >> a[i];

    ll ans1 = hoge();
    ll temp = 0;
    if(a[0] > 0){
        temp += abs(a[0]*(-1)-1);
        a[0] = -1;
    }else if(a[0] < 0){
        temp = abs(a[0]*(-1)+1);
        a[0] = 1;
    }else{
        temp = 1;
        a[0] = -1;
    }
    ll ans2 = hoge()+temp;

    cout << min(ans1, ans2) << endl;
}

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


Measured memory_bytes: 1024
n = int(input())
mod = 10 ** 9 + 7
start,zero,nine,ans = 1,0,0,0
for i in range(n):
  ans = (ans * 10 + zero + nine) % mod
  zero = (zero * 9 + start) % mod
  nine = (nine * 9 + start) % mod
  start = (start * 8) % mod
print(ans)

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

//#define ll unsigned long long
#define ll long long
#define null NULL
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define first ff 
#define second ss 
#define endl '\n' 

int main (){
	IOS
	int n ,d;
	cin>> n  >> d ;
	int x ; 
	ll sum = 0 ;
	//vector <int> v(n) ;
	for(int i = 0;i<d;i++){
		cin >> x ;
		sum += x ;
	} 
	if(sum > n)cout << -1 ;
	else cout << n - sum ; 
	return 0 ;
}
		

Measured memory_bytes: 3652
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 3e5 + 5;

int i,H,W,m,h[N],w[N];
set<int> which[N];

void solve()
{
    cin>>H>>W>>m;
    map<int,int> col,row;
    map<pii,int> bomb;
    for(i=1;i<=m;i++)
    {
        cin>>h[i]>>w[i];
        bomb[{h[i],w[i]}]=1;
        col[w[i]]++;
        row[h[i]]++;
        which[h[i]].insert(w[i]);
    }
    int mx=0;
    for(auto it:col)
    {
        mx=max(mx,it.s);
    }
    set<int> s;
    for(auto it:col)
    {
        if(it.s==mx)
            s.insert(it.f);
    }
    int ans=0;
    for(i=1;i<=H;i++)
    {
        int here=row[i]+mx;
        if(row[i]==W)
            here--;
        else
        {
            int num=0;
            for(int j:which[i])
            {
                if(s.find(j)!=s.end())
                    num++;
            }
            if(num==sz(s))
                here--;
        }
        ans=max(ans,here);
    }
    cout<<ans;
}

signed main()
{
    fastio;
    int tt;
    //cin>>tt;
    tt=1;
    while(tt--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 106720
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=1e6+5,MOD=1e9+7;

using namespace std;

ll n,ans=0;
map<ll,bool>vis;
bool occ[10];
bool gg(ll a){
    memset(occ,0,sizeof(occ));
     while(a){
         occ[a%10]=1;
         a/=10;
     }

     return (occ[3]&&occ[5]&&occ[7]);
}
std::vector<int> v={3,5,7};
void go(ll a){
        vis[a]=1;
        if(gg(a))ans++;
       for(auto x : v){

          if(!vis.count(a*10+x) && a*10+x <= n)
             go(a*10+x);
       }
}

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


        cin>>n;

        go(0);

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

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define N 2005
#define INF 0x3f3f3f3f
#define umx(i,j) ((i)=max(i,j))
int n,a[N*3],dp2,dp1[N],dp[N][N],add=0;
inline void upd(int i,int j,int v){
	umx(dp[i][j],v);umx(dp[j][i],v);
	umx(dp1[i],v);umx(dp1[j],v);
	umx(dp2,v);
}
struct Node{
	int i,j,v;
	inline Node(int ii,int jj,int vv){i=ii;j=jj;v=vv;}
};
vector<Node> gx;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=3*n;++i) scanf("%d",a+i);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j) dp[i][j]=-INF;
		dp1[i]=-INF;
	}
	dp2=0;
	dp1[a[1]]=0;dp1[a[2]]=0;
	dp[a[1]][a[2]]=0;dp[a[2]][a[1]]=0;
	for(int i=1;i<n;++i){
		sort(a+3*i,a+3*i+3);
		if(a[3*i]==a[3*i+2]){++add;continue;}
		gx.push_back(Node(a[3*i+1],a[3*i+2],max(dp2,dp[a[3*i]][a[3*i]]+1)));
		gx.push_back(Node(a[3*i],a[3*i+2],max(dp2,dp[a[3*i+1]][a[3*i+1]]+1)));
		gx.push_back(Node(a[3*i],a[3*i+1],max(dp2,dp[a[3*i+2]][a[3*i+2]]+1)));
		for(int j=1;j<=n;++j){
			gx.push_back(Node(j,a[3*i],max(dp1[j],dp[j][a[3*i+1]]+(a[3*i+1]==a[3*i+2]))));
			gx.push_back(Node(j,a[3*i+1],dp1[j]));
			gx.push_back(Node(j,a[3*i+2],max(dp1[j],dp[j][a[3*i+1]]+(a[3*i+1]==a[3*i]))));
		}
		for(int j=0;j<gx.size();++j) upd(gx[j].i,gx[j].j,gx[j].v);
		gx.clear();
	}
	++dp[a[3*n]][a[3*n]];
	umx(dp1[a[3*n]],dp[a[3*n]][a[3*n]]);
	umx(dp2,dp1[a[3*n]]);
	printf("%d\n",dp2+add);
	return 0;
}

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

int n, A[200005];
struct BIT {
	struct node {
		int var, var2, lazy;//홀수, 짝수 자리중 최소
		node() { var = var2 = 1e9; lazy = 0; }
	};
	vector<node> tree;
	BIT(int V):tree(4*V){}
	node merge(node p, node q) {
		node ret;
		ret.var = min(p.var, q.var);
		ret.var2 = min(p.var2, q.var2);
		return ret;
	}
	void build(int x, int L, int R) {
		if (L == R) {
			if (L & 1) {
				tree[x].var = A[L];
			}
			else {
				tree[x].var2 = A[L];
			}
			return;
		}
		int mid = (L + R) >> 1;
		build(x + x, L, mid);
		build(x + x + 1, mid + 1, R);
		tree[x] = merge(tree[x + x], tree[x + x + 1]);
	}
	void push(int x, int L, int R) {
		if (tree[x].lazy) {
			int mid = (L + R) >> 1;
			tree[x + x].lazy ^= 1;
			tree[x + x + 1].lazy ^= 1;
			swap(tree[x + x].var, tree[x + x].var2);
			swap(tree[x + x + 1].var, tree[x + x + 1].var2);
			tree[x].lazy = 0;
		}
	}
	void flip(int x, int L, int R, int le, int ri) {
		if (ri < L || R < le)return;
		if (le <= L && R <= ri) {
			swap(tree[x].var, tree[x].var2);
			tree[x].lazy ^= 1;
			return;
		}
		push(x, L, R);
		int mid = (L + R) >> 1;
		flip(x + x, L, mid, le, ri);
		flip(x + x + 1, mid + 1, R, le, ri);
		tree[x] = merge(tree[x + x], tree[x + x + 1]);
	}
	void erase(int x, int L, int R, int idx) {
		if (idx< L || R < idx)return;
		if (L==idx && idx==R) {
			tree[x].var = tree[x].var2 = 1e9;
			return;
		}
		push(x, L, R);
		int mid = (L + R) >> 1;
		if (idx <= mid)erase(x + x, L, mid, idx);
		else erase(x + x + 1, mid + 1, R, idx);
		tree[x] = merge(tree[x + x], tree[x + x + 1]);
	}
	int query(int x, int L, int R, int le, int ri) {
		if (ri < L || R < le)return 1e9;
		if (le <= L && R <= ri) {
			return tree[x].var2;
		}
		push(x, L, R);
		int mid = (L + R) >> 1;
		int ret = query(x + x, L, mid, le, ri);
		ret = min(ret, query(x + x + 1, mid + 1, R, le, ri));
		return ret;
	}
};
int pos[200005];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
		pos[A[i]] = i;
	}
	BIT bit(n);
	bit.build(1, 1, n);
	vector<int> ans;
	set<int> sp;
	//6			2 4 1 6 5 3

	for (int ite = 1; ite <= n / 2; ite++) {
		int mn = bit.tree[1].var;
		int idx = pos[mn];
		
		auto it = sp.lower_bound(idx);
		int ed = n;
		if (it != sp.end())ed = (*it) - 1;

		int mn2 = bit.query(1, 1, n, idx + 1, ed);
		ans.push_back(mn); ans.push_back(mn2);
		int idx2 = pos[mn2];

		bit.erase(1, 1, n, idx);
		bit.erase(1, 1, n, idx2);

		sp.insert(idx); sp.insert(idx2);

		bit.flip(1, 1, n, idx + 1, idx2 - 1);
	}
	for (int i = 0; i < ans.size(); i++)printf("%d ", ans[i]);
}

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,s;
    cin>>n>>m;
    s=(n*2+m)/4;
    if(n>((n*2)+m)/4) s=m/2;
    //cout<<n<<" "<<m<<endl;
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
ans = 1
cnt = [0] * 3
mod = 10**9+7
for i in range(N):
	opt = 0
	cond = 1
	for j in range(3):
		if cnt[j] == P[i]:
			opt += 1
			if cond:
				cnt[j] += 1
				cond = 0

	ans *= opt
	ans %= mod

ans %= mod
print(ans)

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

int main(){
  
  int N,v;
  cin >> N;
  
  vector<int> ans(10050);
  
  rep1(x,105){
    rep1(y,105){
      rep1(z,105){
        v = x*x+y*y+z*z+x*y+y*z+z*x;
        if(v < 10050) ans[v]++;
      }
    }
  }
  
  rep1(i,N+1){
    cout << ans[i] << endl;
  }
}
  
  
  
  
  


Measured memory_bytes: 3664
#include <stdio.h>

int main()
{
	int a, b;

	scanf("%d %d", &a,&b);

	if (a < b)
		printf("a < b\n");
	else if (a > b)
		printf("a > b\n");
	else
		printf("a == b\n");

	return 0;
}

Measured memory_bytes: 580
#include<stdio.h>
int n, A[50];
int solve(int i, int m) {
	if (m == 0)return 1;
	if (i >= n)return 0;
	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}
int main() {
	int q, M, i;
	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);
		if (solve(0, M))printf("yes\n");
		else printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2696
#include<iostream>

int main(){

    int a, b, c, n;
    std::cin >> a >> b >> c;
    
    if (b < a){
        n = b;
        b = a;
        a = n;
    }
    
    if (c < b){
        n = c;
        c = b;
        b = n;
    }
    
    if (b < a){
        n = b;
        b = a;
        a = n;
    }
    
    std::cout << a << " " << b << " " << c << std::endl;
    
    return 0;
    
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>

int main() {
    std::string S, T;
    int ans = 10000, tmp;

    std::cin >> S >> T;

    for(int i = 0; i <= S.size() - T.size(); i++) {
        tmp = 0;
        for(int j = 0; j < T.size(); j++) {
            if(S.at(j + i) != T.at(j)) {
                tmp++;
            }
        }

        if(ans > tmp) {
            ans = tmp;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3544
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

namespace string_helper
{
	bool check_divide(const string& word)
	{
		int half = word.size() / 2;
		for (int i = 0; i < half; i++)
		{
			if (word[i] != word[i + half])
			{
				return false;
			}
		}

		return true;
	}
};

//bool ret1 = string_helper::check_palindrome(s1);

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

	string S;
	cin >> S;

	while (S.size() > 2)
	{
		S.pop_back();
		if (S.size() % 2 == 0)
		{
			if (string_helper::check_divide(S))
			{
				cout << S.size();
				break;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : AOJ0110.cpp
// Author      : mizo0203
// Version     :
// Copyright   : Your copyright free
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <stdio.h>
#include <string.h>
#ifndef NULL
#define NULL   ((void *) 0)
#endif
using namespace std;

char str[127], a[127], b[127], c[127];
int zero, sum;

bool input() {

  if (gets(str) == NULL)
    return false;

  return true;
}

int main() {
  int i, j;
  int s, g;

  while (input()) {
    zero = 0;
    s = 0;
    g = strchr(str, '+') - str;
    memset(a, 0, sizeof(a));
    for (i = s; i < g; i++) {
      if (str[g - i - 1] != 'X')
        a[i] = str[g - i - 1] - '0';
      else
        a[i] = -1;
    }
    if (i > 1 && a[i - 1] == -1) {
      zero = 1;
    }
    s = g + 1;
    g = strchr(str, '=') - str;
    memset(b, 0, sizeof(b));
    for (i = 0; i < g - s; i++) {
      if (str[g - i - 1] != 'X')
        b[i] = str[g - i - 1] - '0';
      else
        b[i] = -1;
    }
    if (i > 1 && b[i - 1] == -1) {
      zero = 1;
    }
    s = g + 1;
    g = strlen(str);
    memset(c, 0, sizeof(c));
    for (i = 0; i < g - s; i++) {
      if (str[g - i - 1] != 'X')
        c[i] = str[g - i - 1] - '0';
      else
        c[i] = -1;
    }
    if (i > 1 && c[i - 1] == -1) {
      zero = 1;
    }
    for (i = zero; i < 10; i++) {
      sum = 0;
      for (j = 0; j < 127; j++) {
        if (a[j] != -1)
          sum += a[j];
        else
          sum += i;
        if (b[j] != -1)
          sum += b[j];
        else
          sum += i;
        //printf("%d", sum % 10);
        if (c[j] != -1) {
          if (sum % 10 != c[j]) break;
        } else {
          if (sum % 10 != i) break;
        }
        sum /= 10;
      }
      //printf("\n");
      if (j == 127) {
        printf("%d\n", i);
        break;
      }
    }
    if (i == 10) {
      printf("NA\n");
    }

  }

  return 0;
}

Measured memory_bytes: 952
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);
    
    int N;
    cin >> N;
    int ans = 1;
    while(ans <= N) ans *= 2;
    cout << ans/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
int main(){
    ll N;
    cin >> N;
    vector<ll> H(N);
    for(ll &h : H) cin >> h;
    vector<ll> now(N, 0);
    ll ans = 0;
    while(1){
        vector<ll> tmp;
        for(ll i = 0; i < N; i++) if(now[i] < H[i]){ tmp.push_back(i); now[i]++; }
        if(tmp.size() == 0) break;
        ans++;
        for(ll i = 0; i < tmp.size() - 1; i++) if(tmp[i + 1] - tmp[i] > 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0);cin.tie(0)
using ll = long long;
using ull = unsigned long long;

int main() {
  fastio;
  int h1, a1, h2, a2;
  cin >> h1 >> a1 >> h2 >> a2;

  bool turn = true;
  while(h1 > 0 && h2 > 0) {
    if (turn) {
      h2 -= a1;
      turn = false;
    }
    else { h1 -= a2;
    turn = true;
    }
  }
  if (h1 <= 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  
  #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}


Measured memory_bytes: 3640
// AOJ 1267: How I Mathematician Wonder What You Are!
// 2017.12.18 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <math.h>

#define EPS 1e-8

typedef struct { double x, y; } PP;
typedef struct { PP s, e; } LINE;
PP p[51];

PP a[5] = {{0,0},{10000,0},{10000,10000},{0,10000},{0,0}};

int dcmp(double x)
{
	if (fabs(x) < EPS) return 0;
	return x < 0 ? -1 : 1;
}

double cross(double ax, double ay, double bx, double by) { return ax*by - ay*bx; }

void lineIntersection(PP *p, LINE *a, PP *vs, PP *ve)
{
    double a1, a2;

	a1 = cross(ve->x  - vs->x, ve->y  - vs->y,
			   a->s.x - vs->x, a->s.y - vs->y);
	a2 = cross(ve->x  - vs->x, ve->y  - vs->y,
			   a->e.x - vs->x, a->e.y - vs->y);
	p->x = (a->s.x*a2 - a->e.x*a1) / (a2-a1);
	p->y = (a->s.y*a2 - a->e.y*a1) / (a2-a1);
}

int convex_cut(LINE *u, int n, PP *p, PP *po)
{
	int i, d1, d2, top = 0;

    for (i = 0; i < n; i++) {
        d1 = dcmp(cross(u->e.x - u->s.x, u->e.y - u->s.y,
						p[i].x - u->s.x, p[i].y - u->s.y));
        d2 = dcmp(cross(u->e.x - u->s.x, u->e.y - u->s.y,
				      p[i+1].x - u->s.x, p[i+1].y - u->s.y));
        if (d1 >= 0) po[top++] = p[i];
        if (d1*d2 < 0) lineIntersection(po + top++, u, p+i, p+i+1);
    }
	po[top].x = po[0].x, po[top].y = po[0].y;
    return top;
}

int main()
{
	int n, i, x, y, k, k1, k2;
	PP pol[2][100];
	LINE u;

	while(scanf("%d", &n) && n > 0) {
		for (i = 0; i < n; i++) {
			scanf("%d%d", &x, &y);
			p[i].x = x, p[i].y = y;
		}
		p[n] = p[0];

		k = 4, memcpy(pol[0], a, sizeof(a));

		for (k1 = 0, k2 = 1, i = 0; i < n; i++, k1 = k2, k2 = !k2) {
			u.s = p[i], u.e = p[i+1];
			k = convex_cut(&u, k, pol[k1], pol[k2]);
			if (k == 0) break;
		}
		puts(k > 0 ? "1" : "0");
	}
	return 0;
}

Measured memory_bytes: 1748
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long x, y;
  cin >> x >> y;
  long long ans = 1;
  while(x*2 <= y){
    x *= 2;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

using namespace std;

typedef long long ll;

ifstream fin ("spioni.in");
ofstream fout ("spioni.out");

#define f first
#define s second

ll dl[4] = {0, 0, -1, 1};
const ll mod = 1e9 + 7;
ll n, fact[100002], v[100002], k;

ll logpow (ll a, ll b) {
  ll p = 1;
  while (b) {
    if (b & 1)
      p = 1ll * p * a % mod;
    a = 1ll * a * a % mod;
    (b >>= 1);
  }
  return p;
}

ll comb (ll n, ll k) {
  return fact[n] * logpow(fact[k], mod - 2) % mod * logpow(fact[n - k], mod - 2) % mod;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n >> k;
  fact[0] = 1;
  for (ll i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % mod;
  for (ll i = 1; i <= n; i++)
    cin >> v[i];
  sort(v + 1, v + n + 1);
  ll ans = 0;
  for (ll i = k; i <= n; i++) {
    ans += comb(i - 1, k - 1) * v[i] % mod;
    ans % mod;
  }
  for (ll i = 1; i <= n - k + 1; i++) {
    ans = (ans - comb(n - i, k - 1) * v[i] % mod) % mod;
    if (ans < 0)
      ans += mod;
    ans %= mod;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <locale.h>
#define N 1000
int dizi[N];
int main(){
	int a;scanf("%d",&a);
	a%=10;
	if(a == 3)printf("bon");
	else if(a <= 0 || a == 1 ||a == 6 || a ==8)printf("pon");
	else printf("hon");
}

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

int main() {
	int n,m;
	int in;
	vector<int> a,b,sum;
	
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>in;
		a.push_back(in);
		sum.push_back(0);
	}
	
	for(int i=0;i<m;i++){
		cin>>in;
		b.push_back(in);
	}
	
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(a[j]<=b[i]){
				sum[j]++;break;
			}	
		}
	}
	
	int max=0,num;
	
	for(int i=0;i<n;i++){
		if(max<sum[i]){
			max=sum[i];
			num=i;
		}
	}
	
	cout<<num+1<<endl;
	return 0;
}

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

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

int main(){
    string s = " ";
    string t;
    cin >> t;
    s += t;
    int N = (int)t.size();
    bool is = true;
    int a = N/2;
    rep(i, a){
        if(s[1+i] != s[N-i]) is = false;
    }
    int b = a/2;
    rep(i, b){
        if(s[1+i] != s[(N-1)/2-i]) is = false;
    }
    rep(i, b){
        if(s[(N+3)/2+i] != s[N-i]) is = false;
    }
    if(is) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i, n) {
    cin >> vec.at(i);
  }
  auto vec2 = vec;
  sort(vec2.begin(), vec2.end());
  string ans = "NO";
  if (vec == vec2) ans = "YES";
  else {
    for(int i = 0; i < n-1; i++) {
      for(int j = i + 1; j < n; j++) {
        swap(vec.at(i), vec.at(j));
        if (vec == vec2) ans = "YES";
        else swap(vec.at(i), vec.at(j));
      }
    }
  }
  cout << ans << endl;
}

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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int main() {
    uint64_t H, W;
    cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        cout << (H / 2) * (W / 2) + (H / 2 + H % 2) * (W / 2 + W % 2) << endl;
    }
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var c = int.Parse(line[2]);
        var ans = getAns(a, b, c);
        Console.WriteLine(ans);
    }
    static int getAns (int a , int b, int c)
    {
        var p = 0;
        var ab = a + b;
        while (p <= 60)
        {
            var tmin = p * ab / 60;
            var tmax = p * (ab + a) / 60;
            for (int i = tmin   ; i <= tmax; i++)
            {
                var w = c + 60 * i;
                if (w >= p * ab && w <= p * ab + a) return w;
            }
            p++;
        }
        return -1;
    }
}


Measured memory_bytes: 17952
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
const int MOD = 1e9+7;
vi primos, tablita;
bitset <1010> bs;
void sieve(ll up) {
	bs.set();
	bs[0] = bs[1] = 0;
	ll ss = up+1;
	for(ll i=2;i<=ss;++i) {
		if(bs[i]) {
			for(ll j=i*i;j<=ss;j+=i) bs[j] = false;
			primos.push_back(int(i));
		}
	}
}
void descomponer(int n) {
	int in = 0, prim = primos[in], ans = 0;
	while(prim*prim<=n) {
		while(n%prim==0)
		{
			++ans;
			tablita[prim]++;
			n /= prim;
		}
		prim = primos[++in];
	}
	tablita[n]++;
}
void tablitaear(int n) {
	tablita.resize(n+1);
	for(int i=2;i<=n;++i) descomponer(i);
}
int getans(int n) {
	ll ans = 1;
	for(int i=0;primos[i]<=n;++i)
		ans = ll(ans*(tablita[primos[i]]+1))%MOD;
	return ans;
}
int main() {
	sieve(1000);
	int n;
	scanf("%d", &n);
	tablitaear(n);
	printf("%lld\n", getans(n));
}

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


int main() {
    int n;
    cin >> n;
    int count = 0;
    if (n < 16) {
        cout << 0 << endl;
        return 0;
    }
    
    for (int i = 17; i <= n; i+=2) {
        int _count = 2;
        for (int j = 2; j < sqrt(i) + 1; j++) {
            if (i % j == 0) _count+=2;
        }

        if (_count == 8) {
            count++;
        }    
    }
    cout << count << endl;
    return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> P(N), Q(N);
  rep(i, N) cin >> P[i];
  rep(i, N) cin >> Q[i];

  vector<int> vec(N);
  rep(i, N) vec[i] = i + 1;
  int a, b, cnt = 0;
  do {
    bool ca = true, cb = true;
    rep(i, N) {
      if (vec[i] != P[i]) ca = false;
      if (vec[i] != Q[i]) cb = false;
    }
    if (ca) a = cnt;
    if (cb) b = cnt;
    cnt++;
  } while (next_permutation(vec.begin(), vec.end()));

  cout << abs(a - b) << endl;
}

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

int main() {
  
  int a,b,c;
  cin>>a>>b;
  if(a+b==3)
  cout<<"3"<<endl;
  if(a+b==5)
  cout<<"1"<<endl;
   if(a+b==4)
  cout<<"2"<<endl;
	return 0;
}

Measured memory_bytes: 256
encryptionStr = input()
excludeStr = "{}_"
result = ""
SHIFT_COUNT = 1
for c in encryptionStr :
    if excludeStr.find(c) != -1 :
        result = result + c
        continue
    if ord('a') <= ord(c) <= ord('z') :
        result = result + chr(abs(((ord(c) + SHIFT_COUNT - ord('a')) % 26)) + ord('a'))
    else :
        result = result + chr(abs(((ord(c) + SHIFT_COUNT - ord('A')) % 26)) + ord('A'))
print (result)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define type 26

int constant(int day)//1~26 順番
{
  return day%type+1;
}
int get_random()//1~26 ランダム
{
  return rand()%type+1;
}
int max(int s[][type+1],int day)//その日の最大の満足度選ぶ
{
  int m,max_score=0,i;
  for(i=1;i<=type;i++)
  {
    if(s[day][i]>max_score){
      max_score=s[day][i];
      m=i;
    }
  }
  return m;
}
void cal(int select,int c[type+1],int last[type+1],int s[][type+1],int day,int sum[])
{
  int i;
  sum[day]=sum[day-1]+s[day][select];
  for(i=1;i<=type;i++){
    sum[day]-=c[i]*(day-last[i]);
  }
}
void change(int c[type+1],int last[type+1],int s[][type+1],int sum[],int schedul[],int D)
//ランダムに変更
{
  int d,t,old,total=0,i,j;
  d=rand()%D+1;
  t=rand()%type+1;
  old=schedul[d];
  schedul[d]=t;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  if(total>sum[D]){
  //  printf("change\n");
    sum[D]=total;
  }
  else{
    schedul[d]=old;
  }
}
void cross(int c[type+1],int last[type+1],int s[][type+1],int sum[],int schedul[],int D)
{
  int a,b,old_a,old_b,flag=0,i,j,total=0;
  flag=rand()%2;
  a=rand()%D+1;
  if(flag==0){
    b=a+rand()%16+1;
    if(b>D) b=a-(rand()%16+1);
  }
  else{
    b=a-(rand()%16+1);
    if(b<1)   b=a+rand()%16+1;
  }
  old_a=schedul[a];
  old_b=schedul[b];
  schedul[a]=old_b;
  schedul[b]=old_a;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  if(total>sum[D]){
    sum[D]=total;
  }
  else
  {
    schedul[a]=old_a;
    schedul[b]=old_b;
  }
}
int main(void)
{
  int D,c[type+1],i,j;
  clock_t start,stop;
  srand((unsigned int)time(NULL));
  scanf("%d",&D);//D=365
  int s[D+1][type+1],last[type+1],sum[D+1],schedul[D+1];
  for(i=0;i<=D;i++) sum[i]=0;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=type;i++) scanf("%d",&c[i]);
  for(i=1;i<D+1;i++){
    for(j=1;j<=type;j++) scanf("%d",&s[i][j]);
  }
  start=clock();
  for(i=1;i<D+1;i++){
    int select;
    select=constant(i);
    last[select]=i;
    schedul[i]=select;
    cal(select,c,last,s,i,sum);
    //printf("%d\n",sum[i]);
  }
  int count=0;
  stop=start;
  while((double)(stop - start) / CLOCKS_PER_SEC<1.98){
    cross(c,last,s,sum,schedul,D);
    count++;
    stop=clock();
  }
/*
  printf("count:%d\n",count);
  printf("time:%f\n",(double)(stop - start) / CLOCKS_PER_SEC);
  printf("%d\n",sum[D]);
  printf("確認\n");
  int total=0;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  printf("%d\n",total);
*/
  for(i=1;i<=D;i++) printf("%d\n",schedul[i]);
  return 0;
}


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

int n;

int main(){
  cin >> n;
  double res;
  if(n % 2 == 0){
    res = 0.5;
  }else{
    int tmp = n / 2 + 1;
    res = (double)tmp / (double)n;
  }
  cout << setprecision(10) << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000007
#define endl "\n"
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define SIZ(x) ((int)(x).size())
typedef long long int lli;
using namespace std;

int main()
{
  int k;
  vector<int> a(5);

  REP(i,5)
    {
      scanf("%d",&a[i]);
      
    }
  
  scanf("%d",&k);

  int flag_ng = 0;
  
  REP(i,5)
    {
      REP(j,5)
	{
	  if( abs(a[i]-a[j]) > k )
	    {
	      flag_ng = 1;
	      
	    }
	}
    }

  if(flag_ng)
    {
      printf(":(\n");
      
    }
  else
    {
      printf("Yay!\n");
      
    }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n,a,b;
	cin>>n>>a>>b;

	k=0;
	for(i=1;i<=n;i++){
		j=i; l=0;
		while(j>0){
			l+=(j%10);
			j=j/10;
		}
		if(l>=a&&l<=b){
			k+=i;
		}
	}
	cout<<k;
	return 0;
}


Measured memory_bytes: 256
from collections import OrderedDict
s = input()
n = len(s)
k = int(input())
# print(s, n, k)
st = set()
for j in range(min(k, n)):
    for i in range(0, n - j):
        st.add(s[i: i + j + 1])
ans = sorted(list(st))
# print(ans)
print(ans[k - 1])

Measured memory_bytes: 4976
#include<bits/stdc++.h>
#define PI 3.1415926535
#define N 10010
using namespace std;
int n, m;
int a, b, c;
int d[N];
int x ,y, w, h, r;
int p = 1;
int cnt = 0;
int main(){
    while (scanf("%d %d", &n, &m), n||m){
        for(int i = 0 ; i < n; i++){
            for(int j = 0; j < m; j++){
                if(i == 0 || j ==0 || i == n-1 || j == m-1) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3112
a, b = gets.chomp.split.map(&:to_i)

def xor_sum(x)
  if x.odd?
    if ((x + 1)/2).odd?
      1
    else
      0
    end
  else
    if ((x + 1)/2).odd?
      1 ^ x
    else
      x
    end
  end
end

puts xor_sum(a-1) ^ xor_sum(b)

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline int msbp(int x) {return 31-__builtin_clz(x);}
inline int msb(int x) {return 1 << msbp(x);}
typedef long long ll;
typedef pair<int, int> pii;
// const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x3f3f3f3f;
// const int INF = INT_MAX;
// const int nINF = INT_MIN;
// const ll INF = LLONG_MAX;
// const ll nINF = LLONG_MIN;

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

const int N = 2e5+10;

int n, x, p[N][2], sum[2], m[2];
string s;

int solve(int x) {
	int res = 0;
	while(x) {
		x %= __builtin_popcount(x);
		++res;
	}
	return res;
}

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n >> s;
    reverse(s.begin(), s.end());
    int cnt = 0;
    REP(i, n) if(s[i] == '1') ++cnt;
    p[0][0] = p[0][1] = 1;
    m[0] = cnt+1, m[1] = cnt == 1 ? 1 : cnt-1;
    FOR(i, 1, n-1) REP(j, 2) p[i][j] = (p[i-1][j]*2) % m[j];
    REP(i, n) REP(j, 2) if(s[i] == '1') sum[j] = (sum[j] + p[i][j]) % m[j];
    FORD(i, n-1, 0) {
    	int b = s[i]-'0';
    	int cur = (sum[b] + (b == 0 ? p[i][b] : m[b]-p[i][b])) % m[b];
    	cout << (b && cnt == 1 ? 0 : solve(cur)+1) << endl;
    }

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE) CHECK IF IT SHOULD BE 2*N!!!!
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - negative arithmetic, ceiling division, modulo (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)
// - forgetting to rename recursive call when copy/pasting recursive function (WA)
// - not clearing DS between test cases EVEN FOR INPUT (WA, RTE, TLE, MLE)


Measured memory_bytes: 5300
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
class unionfind {
    vector<int> par, rank, size_;//速度ではなくメモリ効率を考えるならrankのかわりにsizeを使う
public:
    unionfind(int n) :par(n), rank(n), size_(n, 1) {
        iota(all(par), 0);
    }
    int find(int x) {
        if (par[x] == x)return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])swap(x, y);
        par[y] = x;
        size_[x] += size_[y];
        if (rank[x] == rank[y])rank[x]++;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return size_[find(x)];
    }
};
signed main(){
    int n,p; cin>>n>>p;
    map<int,int>Mp;
    vector<vector<int>>v(n,vector<int>());
    unionfind uni(p+1);
    rep(i,n){
        int k; cin>>k;
        rep(j,k){
            int temp; cin>>temp;
            v[i].push_back(temp);
            Mp[temp]++;
        }
    }
    rep(i,n){
        int key=v[i][0];
        rep(j,v[i].size()){
            uni.unite(key,v[i][j]);
        }
    }
    bool ans=false;
    for(int i=1;i<=p;i++)
        if(uni.size(i)==Mp.size())ans=true;
    //cout<<uni.size(1)<<endl;
    cout<<(ans?"YES":"NO")<<endl;
}


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

int judge(int a) {
  if(a == 2) a = -1;
  else if(a == 4 || a == 6 || a == 9 || a == 11) a = -2;
  else a = -3;
  return a;
}

int main() {
  int x, y; cin >> x >> y;
  cout << (judge(x) == judge(y) ? "Yes" : "No") << endl;
}


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

int D;
double V[16];
double interpolate(int n, int E){
	double sum = 0.0;
	for(int k=0;k<D+3; ++k){
		if(k == n || k == E) continue;
		double p = V[k];
		for(int i=0;i<D+3;++i){
			if(!(i == k || i == n || i == E))
				p *= (n-i)/(double)(k-i);
		}
		sum += p;
	}
	return sum;
}

bool outliner(int E){
	for(int i=0;i<D+3;++i){
		if(i==E) continue;
		double p = interpolate(i,E);
		if(abs(p-V[i]) > 0.1) return false;
	}
	return true;
}

int main(){
	while(cin >> D && D){
		for(int i=0;i<D+3;i++) cin >> V[i];
		for(int i=0;i<D+3;i++){
			if(outliner(i)){
				cout << i << endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 3180
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

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

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int a, b, c; cin >> a >> b >> c;

  if (c <= b) {
    outl(b + c);
    return;
  }

  int ans = b * 2;
  c -= b;
  if (a >= c) ans += c;
  else if (a + 1 == c) ans += c;
  else ans += a + 1;

  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



#include <vector>
std::vector<int> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<int> P;
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}
int main()
{
    ll N,cnt1=0,cnt2=0;
    cin >> N;
    rep2(i,N){
        cnt1 = 0;
        rep2(x,N){
            if(i%x == 0){
                cnt1++;
            }
        }
        //cout<<cnt1<<endl;
        if(cnt1 == 8 && i%2 == 1){
            cnt2++;
        }
    }
    cout << cnt2<<endl;
    return 0;
}

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

int main(){
  int n; cin >> n;
  int x[n], y[n];
  cin >> x[0] >> y[0];
  int mod = abs(x[0]+y[0])%2;
  bool flag = false;
  for(int i=1; i<n; i++){
    cin >> x[i] >> y[i];
    if(abs(x[i]+y[i])%2 != mod){
      flag = true;
      break;
    }
  }
  if(flag) cout << -1 << endl;
  else{
    cout << 32-mod << endl;
    rep(i, 31) cout << (int)pow(2, i) << " ";
    if(mod == 0) cout << 1;
    cout << "" << endl;
    bool u[31], v[31];
    rep(i, n){
      if(mod == 0) y[i]--;
      rep(j, 31) u[j] = v[j] = false;
      rep(j, 31){
        if((((x[i]+y[i]-1)/2+(int)pow(2, 30))>>j)&1) u[j] = true;
        if((((x[i]-y[i]-1)/2+(int)pow(2, 30))>>j)&1) v[j] = true;
      }
      rep(j, 31){
        if(u[j] && v[j]) cout << "R";
        if(u[j] && !v[j]) cout << "U";
        if(!u[j] && v[j]) cout << "D";
        if(!u[j] && !v[j]) cout << "L";
      }
      if(mod == 0) cout << "U";
      cout << "" << endl;
    }
  }
}

Measured memory_bytes: 256
''' Hey stalker :) '''
INF = 10**10
def main():
    print = out.append
    ''' Cook your dish here! '''
    n, k = get_list()
    li = get_list()
    li.sort(reverse=True)
    #res = min(n, k)
    res = sum(li[k:])
    print(res)



''' Pythonista fLite 1.1 '''
import sys
#from collections import defaultdict, Counter
#from bisect import bisect_left, bisect_right
#from functools import reduce
#import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')


Measured memory_bytes: 99720
N,K = map(int, input().split())
V = list(map(int, input().split()))

ops = min(N,K)

ans = 0
for A in range(0,ops+1):
    l = V[:A]
    l.sort()
    for B in range(0,ops+1-A):
        ll = l[:]
        if B > 0:
            ll = l + V[-B:]
            ll.sort()
        for i in range(0,min(K-(A+B),A+B)):
            if ll[i] < 0:
                ll[i] = 0
            else:
                break
        ans = max(sum(ll),ans)

print(ans)


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		int[] d = Arrays.stream(sc.nextLine().split(" ")).mapToInt(s -> Integer.parseInt(s)).toArray();

		Arrays.sort(d);

		if (d[N / 2 - 1] == d[N / 2]) {
			System.out.println(0);
		}
		else {
			System.out.println(d[N / 2] - d[N / 2 - 1]);
		}
	}
}

Measured memory_bytes: 49724
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
void read(long long &x)
{
    char ch;bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=110;
long long a,b,x,y,l,r,ans,ll,rr;
int aa[maxn],bb[maxn],lena,lenb,len,k;
int main(){
    read(a),read(b);x=a,y=b;
    while(a)aa[++lena]=a&1,a>>=1;
    while(b)bb[++lenb]=b&1,b>>=1;
    for(rg int i=max(lena,lenb);i;i--)
    {
        if(aa[i]!=bb[i])
        {
            len=i;break;
        }
        x-=1ll*aa[i]<<(i-1);
        y-=1ll*bb[i]<<(i-1);
    }
    for(rg int i=len-1;i;i--)if(bb[i]){k=i;break;}
    l=x,r=(1ll<<(len-1))+(1ll<<k)-1;
    ll=(1ll<<(len-1))+x,rr=(1ll<<len)-1;
    if(ll>r)ans=r-l+1+rr-ll+1;
    else ans=rr-l+1;
    printf("%lld\n",ans);
}

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

int main() {
	int n, max_w;
	vector< int > w, v;
	vector< vector< int > > dp;
	
	cin >> n >> max_w;
	
	w.resize(n);
	v.resize(n);
	dp.resize(n+1);
	for(int i=0;i<=n;++i){
		dp[i].resize(max_w+1);
	}
	
	for(int i=0;i<n;++i){
		cin >> v[i] >> w[i];
	}
	
	for(int i=0;i<=max_w;++i)dp[0][i] = 0;
	
	for(int i=1;i<=n;++i){
		for(int j=0;j<=max_w;++j){
			if(j < w[i-1]){
				dp[i][j] = dp[i-1][j];
			}else{
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1]);
			}
		}
	}
	cout << dp[n][max_w] << endl;
	
	return 0;
}

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

using namespace std;
int n,m;
vector<int> g[8];
int fun(int now,int bit){
    cerr<<" "<<now<<" "<<bitset<10>(bit)<<endl;
    int res=0;
    if(bit==(1<<n)-1)return 1;
    for(int i=0;i<g[now].size();i++){
        if(!(bit&(1<<g[now][i]))){
            res+=fun(g[now][i],bit|(1<<g[now][i]));
        }
    }
    return res;
}
int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cout<<fun(0,1)<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():

    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))

    # print(A)
    pairs = 0
    for i in range(N-1):
        pairs += A[i] // 2
        A[i] = A[i] % 2
        pairs += min(A[i], A[i+1])
        A[i], A[i+1] = A[i]-min(A[i], A[i+1]), A[i+1]-min(A[i], A[i+1])
    pairs += A[N-1] // 2

    return pairs

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 7072
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main()
{
    long long int h,ans,t;
    while(cin>>h)
    {

        ans=0;
        t=1;
        while(h)
        {
            if(h==1)
            {
                ans+=t;
                h--;
            }
            else
            {
                ans+=t;
                h/=2;
                t*=2;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int;
using namespace std;
#define ll long long int
#define F first
#define S second
//#define endl "\n"
//#define nl cout<<endl;
#define pb push_back
#define ull unsigned long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 
bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
    return false;
}
bool cmp(int n, pair<int, int> const& p)
{
    return (p.first < n);
}
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 1e18;
ll const maxn = 1e2+1;
ll degree[maxn];
void solve()
{    

     ll n,m; cin >> n >> m;
     while(m--){
          ll u,v; cin >> u >> v;
          degree[u]++;
          degree[v]++;
     }

     //ll cnt = 0;
     for(ll i=1; i<=n; i++){
          //cout << find(i) << endl;
          cout << degree[i]<< endl;
     }
          
     //cout << cnt << endl;
       
}

int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
          
          ll t;
          /**/t=1;
          /*/cin>>t;/**/
          f(testcases,0,t){
               //cout << "Case #" <<testcases+1<<": ";
               solve();
          }
 
 
    return 0;
}

Measured memory_bytes: 3644