akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MXN 200005
bool cmp(const pll &p,const pll &q){
    if((LL)q.x*p.y+q.y==(LL)p.x*q.y+p.y){
        return p.y<q.y;
    }
    return (LL)q.x*p.y+q.x<(LL)p.x*q.y+p.x;
}
int main(){
    int n,t;
    scanf("%d %d",&n,&t);
    vector<pll> p;
    vector<int> v;
    for(int i= 0;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        if(x==0)v.pb(y);
        else p.pb(mp(x,y));
    //    p[i]=mp(x,y);
    }
    
    sort(v.begin(),v.end());
    sort(p.begin(),p.end(),cmp);
    LL dp[105];
    fill(dp,dp+105,1e9+7);
    dp[0]=0;
    for(auto it:p){
        for(int j=100;j>0;j--){
            dp[j]=min(dp[j],dp[j-1]+1+(dp[j-1]+1)*it.x+it.y);
        }
    }
    
    int ans=0;
    for(int i = 0;i<=100;i++){
        if(dp[i]<=t){
            int sum=i;
            for(int j=0;j<v.size();j++){
               // printf("%d %d\n",j,dp[i]+v[j]+1);
                if(dp[i]+v[j]+1>t){
                    sum+=j;
                    break;
                }
                else{
                    dp[i]+=v[j]+1;
                }
                if(j==v.size()-1){
                    sum+=j+1;
                    break;
                }
            }
            ans=max(ans,sum);
        }
    }
    printf("%d\n",ans);
}
/*
[1,2,4,3,5,6]
concat(sorted([4,2,1]),sorted([5,3,6]))
concat(shuffle([2,1]),shuffle([2,3]))
concat(shuffle([2,1,3]),shuffle([3]))
*/

Measured memory_bytes: 6384
X,Y,A,B,C=map(int,input().split())
p=sorted(list(map(int,input().split())))[::-1][:X]
q=sorted(list(map(int,input().split())))[::-1][:Y]
r=list(map(int,input().split()))
ans=sorted(p+q+r)[::-1][:X+Y]
print(sum(ans))

Measured memory_bytes: 22548
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();

int main(){
 int n,a,b,res=0; cin>>n>>a>>b;
 res=min(n*a,b);

 cout<<res<<endl;

}

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

int main() {
  string s;
  cin >> s;
  int bit = 0;
  int end = pow(2, s.size()-1);
  ll int ans = 0;
  while(!(bit & end)) {
    ll int thisans = 0;
    ll int num = 0;
    rep(i, s.size()-1) {
      num += (int)(s[i]-48);
      if(bit & (1<<i)) {
//        cout << "true " << thisans << " + " << num << endl; 
        thisans += num;
        num = 0;
      } else {
        num *= 10;
//        cout << "false " << num << endl;
      }
    }
    thisans += num + s[s.size()-1]-48;
    ans += thisans;
    ++bit;
//    cout << thisans << endl;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4104
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
  int p, n, m;
  std::vector<int> vec;
  std::cin >> n >> m;

  for(int i = 0; i<n; i++){
    std::cin >> p;
    vec.push_back(p);
  }

  int sum = std::accumulate(vec.begin(), vec.end(), 0);
  std::sort(vec.rbegin(), vec.rend());
  int count = 0;

  for(int i = 0; i<m; i++){
    if(vec[i] * (4 * m) >= sum){
      count += 1;
    }
  }
  if(count >= m){
    std::cout << "Yes" <<std::endl;
  }else{
    std::cout << "No" <<std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> p;

#define MOD 1000000007

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

    int H, W, K;
    cin >> H >> W >> K;

    vector<vector<char> > c(H, vector<char>(W));

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> c[i][j];
        }
    }

    int ans = 0;

    for(int bit = 0; bit < (1 << H); bit++) {
        vector<int> S;
        for(int i = 0; i < H; ++i) {
            if (bit & (1 << i)) {
                S.push_back(i);
            }
        }
        for(int cit = 0; cit < (1 << W); cit++) {
            vector<int> T;
            for(int j = 0; j < W; j++) {
                if(cit & (1 << j)) {
                    T.push_back(j);
                }
            }
            vector<vector<bool> > b(H, vector<bool>(W));

            for(int j = 0; j < S.size(); j++) {
                for(int k = 0; k < W; k++) {
                    b[S[j]][k] = true;
                }
            }
            for(int j = 0; j < T.size(); j++) {
                for(int k = 0; k < H; k++) {
                    b[k][T[j]] = true;
                }
            }

            int count = 0;

            for(int j = 0; j < H; j++) {
                for(int k = 0; k < W; k++) {
                    if(b[j][k]) continue;
                    if(c[j][k] == '#') count++;
                }
            }

            if(count == K) ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
import math
import sys
n, m = map(int, input().split())

def combinations_count(n, r):
    C = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    return C

if n <= 1 and m >= 2:
    print(combinations_count(m, 2))
    sys.exit()
elif n >= 2 and m <= 1:
    print(combinations_count(n, 2))
    sys.exit()
elif n == m == 1:
    print(0)
    sys.exit()
elif n == m == 0:
    print(0)
    sys.exit()
else:
    print(combinations_count(n, 2) + combinations_count(m, 2))

Measured memory_bytes: 3064
n=int(input())

h=list(map(int,input().split()))

inf=float('inf')
np=[inf]*n

np[0]=0

for i in range(n-1):
    if np[i+1]>abs(h[i]-h[i+1])+np[i] :
        np[i+1]=abs(h[i]-h[i+1])+np[i]
    if i < n-2:
        if np[i+2]>abs(h[i]-h[i+2])+np[i] :
            np[i+2]=abs(h[i]-h[i+2])+np[i]

print(int(np[n-1]))


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

int main() {
	string s;
  	cin>>s;
  	long long i,co=0;
  	for(auto a:s)
    {
      co+=a-48;
    }
  	if(co%9==0)
    {
      cout<<"Yes";
    }
  else
  {
    cout<<"No";
  }
	return 0;
}


Measured memory_bytes: 3684
#include<stdio.h>
 
int main(){
	int n, a, b, i, max = 0, num;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d %d", &a, &b);
		if(max <= b){
			if(max < b){
				num = a;
				max = b;
			}else if(num > a) num = a; 
		}
	}
	printf("%d %d\n", num, max);
	return 0;
}

Measured memory_bytes: 600
while 1:
    n=input()
    if n==0:break
    table={}
    for i in xrange(n):
        a,b=raw_input().split()
        table[a]=b
    m=input()
    ans=""
    for i in xrange(m):
        s=raw_input()[0]
        if s in table:
            ans+=table[s]
        else:
            ans+=s
    print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll ans = 0;
  int t = n-1;
  rep(i,n) {
    int lim = 2;
    if (i == 0) lim = 1;
    rep(j,lim) {
      if (t > 0) {
        ans += a[i];
        t--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	string s;
	cin>>s;
	if(s=="SSS")	cout<<0;
	else if(s=="RRR")	cout<<3;
	else if(s=="RRS" || s=="SRR")	cout<<2;
	else	cout<<1;
	return 0;
 } 

Measured memory_bytes: 3628
#include <stdio.h>

int N, A[100], temp, count;

void bubbleSort(){
  int i=0, j;
  while(i!=N){
    for(j=N-1; j>=i+1; j--){
      if(A[j]<A[j-1]){
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
	count++;
      }
    }
    i++;
  }
}

int main(){
  int i;
    scanf("%d", &N);
  for(i=0; i<N; i++)scanf("%d", &A[i]);
  bubbleSort();
  for(i=0; i<N-1; i++){
    printf("%d ", A[i]);
  }
  printf("%d\n%d\n", A[i], count);
  return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    int n; cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    map<int, int> m;
    int ans = 0;
    for(int i : a) m[i]++;
    for(auto i : m){
        if(i.first == i.second) continue;
        if(i.first > i.second) ans += i.second;
        else ans += i.second - i.first;
    }

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

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

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

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 110;
const int MAXK = 510;

ll n, a[6];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,5) cin >> a[i];
    ll Min = 1e18;
    FOR(i,1,5) Min = min(Min, a[i]);
    ll k = n / Min + (n % Min > 0);
    cout << k + 4;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

class UnionFind
{
    std::vector<int> data;

  public:
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                std::swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    ll size(int x)
    {
        return -data[root(x)];
    }
};

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

    ll n, m;
    cin >> n >> m;
    vector<P> es(m);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        es[i] = P(a, b);
    }
    reverse(es.begin(), es.end());
    ll cnt = n * (n - 1) / 2;
    vector<ll> ans;
    ans.push_back(cnt);
    UnionFind uf(n);
    for (int i = 0; i < m; i++)
    {
        int a = es[i].first, b = es[i].second;
        if (!uf.find(a, b))
        {
            ll tmp = uf.size(a) * uf.size(b);
            uf.unite(a, b);
            cnt -= tmp;
        }
        ans.push_back(cnt);
    }
    reverse(ans.begin(), ans.end());
    for (int i = 1; i <= m; i++)
        cout << ans[i] << endl;
}


Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ

signed main(){
    constexpr ll MOD = 998244353;
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    ll dp[c+1][d+1];
    rep(i,c+1){
        rep(j,d+1){
            dp[i][j]=0;
        }
    }
    dp[a][b]=1;
    for(ll i=a;i<=c;i++){
        for(ll j=b;j<=d;j++){
            if(i==a&&j==b) continue;
            if(i==a){
                dp[i][j]=dp[i][j-1]*i;
                dp[i][j]%=MOD;
            }
            else if(j==b){
                dp[i][j]=dp[i-1][j]*j;
                dp[i][j]%=MOD;
            }
            else{
                dp[i][j]=(dp[i-1][j]*j+dp[i][j-1]*i)%MOD;
                dp[i][j]-=(dp[i-1][j-1]*(i-1LL)*(j-1LL))%MOD;
                dp[i][j]=(dp[i][j]+MOD)%MOD;
            }
        }
    }

    cout << dp[c][d] << endl;
}


Measured memory_bytes: 73928
#include<stdio.h>
int main()
{
	char a[3],num=0;
	scanf("%s",a);
	for(int i=0;i<3;i++)
	{
		if(a[i]=='R')
		num++;
	}
	switch(num){
	case(0):printf("0\n");break;
	case(2):
		if(a[1]=='S')
		printf("1\n");
		else printf("2\n");break;
	case(1):printf("1\n");break;
	case(3):printf("3\n");break;}
	return 0;
 } 

Measured memory_bytes: 1624
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#define maxSize 100000

struct process_ {
	char name[10];
	int time;
};

struct process_ my_queue[maxSize];
int rear=0, front=0;

void enqueue(struct process_ x) {
    my_queue[rear] = x;
	rear=(rear + 1) % maxSize;
}

struct process_ dequeue() {
	struct process_ value = my_queue[front];
	front = (front + 1) % maxSize;
	return value;
}
bool isEmpty(struct process_ my_queue[]) {
	if (front == rear)
		return true;
	else
		return false;
}

int main() {
	int n, q,countTime=0;
	scanf("%d%d", &n, &q);
	struct process_ p;
	for (int i = 0; i < n; i++) {
		scanf("%s%d", &p.name, &p.time);
		//printf("%s %d", p.name, p.time);
		enqueue(p);
	}
	while (!isEmpty(my_queue)) {
		struct process_ my_p = dequeue();
		if (my_p.time > q) {
			my_p.time -= q;
			countTime += q;
			enqueue(my_p);
		}
		else {
			countTime += my_p.time;
			printf("%s %d\n", my_p.name, countTime);
		}
	}
	return 0;
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
int n,y,ans,ic,uc,hc;
int main(){
    cin>>n>>y;


    for(int i=0;i<n+1;i++){
        if(1000*i>y||i>n)break;
        for(int u=0;u<n+1;u++){
            if(1000*i+5000*u>y||i+u>n)break;
            for(int h=0;h<n+1;h++){
                if(1000*i+5000*u+10000*h>y||i+u+h>n)break;
                if(1000*i+5000*u+10000*h==y&&i+u+h==n){
                    ic=h;
                    uc=u;
                    hc=i;
                    ans=1;
                    break;
                }
            }if(ans)break;
        }if(ans)break;
    }

    for(int i=0;i<1000000000*100000;i++){
        int aho;
      aho++;
    }








    if(ans==1){
        cout<<ic<<" "<<uc<<" "<<hc<<endl;
    }else{
        cout<<"-1 -1 -1"<<endl;
    }
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	string str;
	cin>>str;
	int n=str.size();
	int lo=0,hi=n-1;
	int flag=0;
	while(lo<=hi)
	{
	    if(str[lo]==str[hi])
	    {
	        lo++;
	        hi--;
	        
	    }
	    else
	    {
	        flag=1;
	        break;
	    }
	}
	lo=0,hi=(n-1)/2;
	hi--;
	while(lo<=hi)
	{
	    if(str[lo]==str[hi])
	    {
	        lo++;
	        hi--;
	        
	    }
	    else
	    {
	        flag=1;
	        break;
	    }
	}
	lo=(n+3)/2;
	lo--;
	hi=n-1;
	while(lo<=hi)
	{
	    if(str[lo]==str[hi])
	    {
	        lo++;
	        hi--;
	        
	    }
	    else
	    {
	        flag=1;
	        break;
	    }
	}
	if(flag==1)
	{
	    cout<<"No"<<endl;
	}
	else
	{
	    cout<<"Yes"<<endl;
	}
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int MOD=1e9+7;
ll a[N];
ll sum[N];
//ll ans[N];
 
ll gao(int l,int r){  //求区间l,r的和
    return sum[r]-sum[l-1];
}
 
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 
    int n ;
    cin >>n;
    for(int i=1;i<=n;i++)   cin >> a[i];
    for(int i=1;i<=n;i++)   sum[i]=sum[i-1]+a[i]; //求前缀和
    ll l=1,r=3;
    ll ans=1e18+8;
    for(int i=2;i<=n-2;i++){
         while(l+1<i&&abs(gao(1,l)-gao(l+1,i))>=abs(gao(1,l+1)-gao(l+2,i)))//若[1,l+1]和[l+1,i]的距离比[1,l+1]和[l+2,i]的距离小，那么我们就继续加，使得两边尽可能平衡
            l++;
         while(r+1<n&&abs(gao(i+1,r)-gao(r+1,n))>=abs(gao(i+1,r+1)-gao(r+2,n)))
            r++;
         set<ll>st;///利用set的log排序
         st.insert(gao(1,l));
         st.insert(gao(l+1,i));
         st.insert(gao(i+1,r));
         st.insert(gao(r+1,n));
         ans=min(ans,abs(*st.begin()-*prev(st.end())));
    }
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  string n;
  cin >> n;
  cout << "ABC" << n << endl; 
  return 0;
}


Measured memory_bytes: 3616
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  double a,b;
  cin>>a>>b;
  cout<<2*b-a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);


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

ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}

ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}



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

    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */

    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll n;
        cin>>n;
        ll h[n];
        REP(i,0,n)
        {
            ll t;
            cin>>t;
            h[i]=t;
        }
        ll a[n];
        REP(i,0,n)
        {
            ll t;
            cin>>t;
            a[i]=t;
        }
        static ll st[600000];
        ll x=262144;
        REP(i,0,n)
        {
            ll r=x+h[i];
            ll l=x;
            ll t=0;
            while(l<=r)
            {
                if(l%2==1)t=max(t,st[l++]);
                if(r%2==0)t=max(t,st[r--]);
                l/=2;
                r/=2;
            }
            t+=a[i];
            l=x+h[i];
            st[l]=t;
            l/=2;
            while(l>=1)
            {
                st[l]=max(st[2*l],st[2*l+1]);
                l/=2;
            }
        }
        cout<<st[1];
    }

    return 0;
}


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

int main(){
    int x,y;cin>>x>>y;
    int a=x,b=y;
    int ans=2000000001;
    if(a<=b)ans=min(ans,b-a);
    a=-x;
    if(a<=b)ans=min(ans,b-a+1);
    b=-y;
    if(a<=b)ans=min(ans,b-a+2);
    a=x;
    if(a<=b)ans=min(ans,b-a+1);
    cout<<ans<<endl;
    return 0;
}

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

int main(void)
{
	int a, b, c;

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

	if (a < b && b < c) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 2612
#include<iostream>
#include<vector>
#include<cmath>
const int INF = 999999999;
using namespace std;
void chmin(int &a,int b) {if(a>b) a=b;}
int N,A,B,C;
vector<int> l;

int rec(int i,int a,int b,int c){
  if(i==N){
    if(!a || !b || !c) return INF;
    return abs(a-A)+abs(b-B)+abs(c-C);
  }
  int res = rec(i+1,a,b,c);

  chmin(res,rec(i+1,a+l[i],b,c)+(a?10:0));
  chmin(res,rec(i+1,a,b+l[i],c)+(b?10:0));
  chmin(res,rec(i+1,a,b,c+l[i])+(c?10:0));

  return res;
}

int main(){
  cin >> N >> A >> B >> C;
  l.resize(N);
  for(int i=0;i<N;i++) cin >> l[i];
  cout << rec(0,0,0,0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
typedef pair<int, int> P;

signed main(){
    int x, k,d;
    cin >> x >> k >> d;
    if(k<=abs(x)/d) {
        cout << abs(x)-k*d << endl;
        return 0;
    }
    int m = k-abs(x)/d;
    //cout << m << endl;
    if(x>=0) {
        x = x%d;
        if(m%2==0) cout << x << endl;
        else cout << (-x+d) << endl;
    }else {
        //cout << x << endl;
        x = abs(x)%d;
        //cout << x << endl;
        if(m%2==0) cout << x << endl;
        else cout << (-x+d) << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

#define BASE 20000
bool dp[80][80][2*BASE] = {}; //(i,j)まででk-20000がつくれるか

int main(){
    ll h,w;
    cin >> h >> w;
    ll a[h][w],b[h][w];
    ll d[h][w];
    rep(i,0,h) rep(j,0,w) cin >> a[i][j];
    rep(i,0,h) rep(j,0,w){
        cin >> b[i][j];
        d[i][j] = a[i][j] - b[i][j];
    }

    dp[0][0][d[0][0]+BASE] = true;
    dp[0][0][-d[0][0]+BASE] = true;
    

    rep(i,0,h){
        rep(j,0,w){
            rep(k,0,2*BASE){
                if(i == 0 && j == 0) break;
                bool flag = false;
                if(i > 0 && k-d[i][j] < 2*BASE && k-d[i][j] >= 0) flag = flag || dp[i-1][j][k-d[i][j]];
                if(i > 0 && k+d[i][j] < 2*BASE && k+d[i][j] >= 0) flag = flag || dp[i-1][j][k+d[i][j]]; 
                if(j > 0 && k-d[i][j] < 2*BASE && k-d[i][j] >= 0) flag = flag || dp[i][j-1][k-d[i][j]];
                if(j > 0 && k+d[i][j] < 2*BASE && k+d[i][j] >= 0) flag = flag || dp[i][j-1][k+d[i][j]];
                dp[i][j][k] = flag;
            }
        }
    }

    ll ans = LINF;
    rep(i,0,2*BASE){
        if(dp[h-1][w-1][i]) ans = min(ans,abs(i-BASE));
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 253800
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

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

  if (M < N * 2) {
    cout << M / 2 << endl;
  } else {
    ll ans = N;
    M -= N * 2;

    ans += M / 4;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;

int main(){
  int n,d;
  cin >> n >> d;
  if(n%(2*d+1)==0) cout << n/(2*d+1);
  else cout << n/(2*d+1)+1;
}



Measured memory_bytes: 256
loop do
    word = gets.chomp.split("").map do |s| s.to_s end
    if word[0] == "-"
        break
    end
    time =  gets.chomp.to_i
    time.times do |n|
        shift = gets.chomp.to_i
        word.rotate!(shift)
    end
    puts word.join("")
end

Measured memory_bytes: 8712
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
int main()
{
	fast;


	ll n,a,b;
	cin >> n >> a >> b;
	if(a > b)
		swap(a,b);
	if((b-a)%2==0)
		cout <<(b-a)/2 << endl;
	else
	{
		cout << min(a+(b-a-1)/2,n-b+1+(b-a-1)/2) << endl;  
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;



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

    vvi jobs(M);
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        if (a > M) continue;
        jobs[M-a].emplace_back(b);
    }

    priority_queue<int> pq;
    ll ans = 0;
    for (int i = M-1; i >= 0; i--) {
        for (int b : jobs[i]) {
            pq.push(b);
        }
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5632
def resolve():
    N=int(input())
    A=list(map(int,input().split()))

    l=0
    r=0
    summury=0
    sv=0
    while r<=N-1:
        if sv+A[r] == sv ^ A[r]:
            #print(l,r,"#")
            sv+=A[r]
            r+=1

        else:

            cc=r-l
            summury+=cc
            #print(l,r,summury)
            if l==r:
                r+=1
            else:
                sv-=A[l]
                l+=1


    cc=r-l+1
    summury+=(cc-1)*cc//2
    print(summury)



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 77644
def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    warp_idx = [-1] * (len(A) + 1)
    ans_list = []

    c = 1
    i = 0
    while warp_idx[c] == -1:
        warp_idx[c] = i
        ans_list.append(c)
        c = A[c - 1]
        i += 1
    start = warp_idx[c]
    loop = i - start
    if K <= start:
        print(ans_list[K])
    else:
        step = K - start
        step %= loop
        print(ans_list[start+step])


if __name__ == '__main__':
    main()


Measured memory_bytes: 32360
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var firstflag = 1;
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            if (firstflag == 1) firstflag = 0;
            else Console.WriteLine();
            var dict = new Dictionary<string, string>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                dict[line[0]] = line[1];
            }
            var p = int.Parse(Console.ReadLine().Trim());
            for (int i = 0; i < p; i++)
            {
                var s = Console.ReadLine().Trim();
                if (dict.ContainsKey(s)) Console.Write(dict[s]);
                else Console.Write(s);
            }
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 9264
#! /usr/bin/env ruby
y, m, d = gets.chomp.split("/").map(&:to_i)
if y < 2019
  puts "Heisei"
elsif y > 2019
  puts "TBD"
else
  if m < 4
    puts "Heisei"
  elsif m > 4
    puts "TBD"
  else
    if d <= 30
      puts "Heisei"
    else
      puts "TBD"
    end
  end
end


Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

int main()
{
	char a[53];
	for (int i = 0; i < 26; ++i)
	{
		a[i] = (char)('A' + i);
	}
	for (int i = 0; i < 26; ++i)
	{
		a[26 + i] = (char)('a' + i);
	}
	int n;
	int k[100];
	char s[101];
	while(cin >> n && n != 0){
		int c = 0;
		for (int i = 0; i < n; ++i)
		{
			cin >> k[i];
		}
		k[n] = '\0';
		cin >> s;
		for (int i = 0; s[i] != '\0'; ++i)
		{
			for (int j = 0; j < 52; ++j)
			{
				if(s[i] == a[j]){
					if(j - k[c] >= 0){
						cout << a[j - k[c]];
					}else{
						cout << a[52 - k[c] + j];
					}
				}
			}
		c++;
		if(c == n){
			c = 0;
			}
		}
		c++;
		if(c == n){
			c = 0;
		}
		cout << endl;
	}
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, q;
	cin >> n >> q;
	string str;
	cin >> str;

	vector<int> s(n + 1, 0);
	rep(i, n) {
		if (i + 1 < n && str[i] == 'A' && str[i + 1] == 'C') {
			s[i + 1] = s[i] + 1;
		}
		else {
			s[i + 1] = s[i];
		}
	}

	rep(i, q) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		cout << s[r] - s[l] << endl;
	}

	return 0;
}

Measured memory_bytes: 1488
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
//-0.4620981203755741
int main(){
    ll n,a,b;
    std::cin >> n>>a>>b;
    ll ans=n/(a+b)*a;
    ans+=min(a,n%(a+b));
    std::cout << ans << std::endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=2e5+1e2;
int n;
ll Ans;
int a[maxn];

inline void file() {
	freopen("AGC024C.in","r",stdin);
	freopen("AGC024C.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read();
	For (i,1,n) {
		a[i]=read();
		if (i==1 && a[i]) {
			puts("-1"); return 0;
		}
		if (a[i-1]<a[i]-1) {
			puts("-1"); return 0;
		}
	}
	For (i,1,n-1)
		if (a[i]!=a[i+1]-1) Ans+=1ll*a[i];
	Ans+=1ll*a[n];
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import itertools

def greedy(a):
    while len(a) >= 3:
        if a[-3] + a[-2] > a[-1]:
            return a.pop() + a.pop() + a.pop()
        else:
            a.pop()

def bruteforce(a):
    while len(a) >= 3 and a[-3] + a[-2] <= a[-1]:
        a.pop()
    result = 0
    for b in itertools.combinations(a[- 10 :], 6):
        for partition in itertools.combinations(range(6), 3):
            c, d = [], []
            for i in range(6):
                if i in partition:
                    c += [ b[i] ]
                else:
                    d += [ b[i] ]
            if c[0] + c[1] > c[2] and d[0] + d[1] > d[2]:
                result = max(result, sum(b))
    return result

def solve(preserved_a):
    result = 0

    # greedy
    a = list(preserved_a)
    x = greedy(a)
    y = greedy(a)
    if x is not None and y is not None:
        result = max(result, x + y)

    # bruteforce
    a = list(preserved_a)
    x = bruteforce(a)
    result = max(result, x)

    return result

n = int(input())
a = sorted([ int(input()) for _ in range(n) ])
result = solve(a)
print(result)

Measured memory_bytes: 11028
#include <bits/stdc++.h>
using namespace std;
using ll=long long;using ull=unsigned ll;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPARR(i,v) for(int i=0;i<v.size();++i)
#define all(v) (v).begin(),(v).end()
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
#define cut(n, Min, Max) max(min(n,Max),Min)
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"":"im")<<"possible"<<endl
#define Poss(n) cout<<((n)?"P":"Imp")<<"ossible"<<endl
template<typename T>ostream&operator<<(ostream&o,const vector<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<typename T>ostream&operator<<(ostream&o,const set<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T,typename U>ostream&operator<<(ostream&o,const pair<T,U>&v){o<<v.first<<' '<<v.second;return o;}

inline ll square(ll a){return (a*a)%MOD;}
ll powmod(ll a,ll b){
    if(b==0)return 1;
    if(b==1)return a;
    if(b%2){
        return (square(powmod(a,b/2))*a);
    }else{
        return square(powmod(a,b/2));
    }
}


template<typename T>
T gcd(T a,T b){ // log N
    while((a%=b)&&(b%=a));
    return a+b;
}
template<typename T>
T lcm(T a,T b){
    return a/gcdl(a,b)*b;
}


int main(){
    ll k,a,b;
    cin>>k>>a>>b;
    ll bsc=1;


    if(b-a<=1){
        bsc+=k;
    }else{
        if(bsc<a){
            if(k<=a-bsc){
                cout<<bsc+k<<endl;
                return 0;
            }
            k-=a-bsc;
            bsc=a;
        }
        cerr<<bsc<<endl;
        cerr<<k<<endl;
        if(k%2){
            k--;
            bsc++;
        }
        k/=2;
        bsc+=(b-a)*k;
    }
    cout<<bsc<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
char str[101],answer[101];
int main()
{
    
    gets(str);
    int lens=strlen(str),i,lena=0;
    for(i=0;i<lens;i++)
        switch(str[i])
        {
            case '0':answer[lena]='0';lena++;break;
            case '1':answer[lena]='1';lena++;break;
            case 'B':if(lena!=0) lena--;break;
            } 
    for(i=0;i<lena;i++)
        printf("%c",answer[i]);
    printf("\n");
}

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

int main(){
    int n;
    while(1){
        cin >> n;
        if(!n) break;
        int x1, y1, z1, w1, x2, y2, z2, w2;
        int a, b, c, d;
        for(int i = 0;i < n;i++){
            cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
            a = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2;
            b = x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2;
            c = x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2;
            d = x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2;
            cout << a << ' ' << b << ' ' << c << ' ' << d << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int H,heap[2000001];
void maxHeapify(int i){
  int l,r,largest;
  l=i*2;
  r=i*2+1;
  //左の子、自分、右の子で値が最大のノードを選ぶ
  if(l<=H&&heap[l]>heap[i]) largest=l;
  else largest=i;
  if(r<=H&&heap[r]>heap[largest]) largest=r;
  if(largest!=i){
    swap(heap[i],heap[largest]);
    maxHeapify(largest);
  }
}
int main(){
  scanf("%d",&H);
  for(int i=1;i<=H;i++) scanf("%d",&heap[i]);
  for(int i=H/2;i>=1;i--) maxHeapify(i);
  for(int i=1;i<=H;i++) printf(" %d",heap[i]);
  printf("\n");
  return(0);
}



Measured memory_bytes: 5156
import java.util.*;

public class Main {
    static long MOD = 998244353;
    
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int s = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        // ans: f(T)の全パターンの和
        // f(T): 集合Tの部分集合であって、和がsになるパターン数
        long ans = 0;
        
        // ans: [x^s] (f{1}+f{2}+f{3}+f{1,2}+f{1,3}+f{2,3}+f{1,2,3})
        // ex. f{1,2,3}: f1f2f3 - 1
        // ex. f{1,2}: f1f2 - 1
        
        // ex. n = 3, s = 4, array[] = {2, 2, 4}
        // -> f{3}に1個、f{1,2}に1個、f{1,3}に1個、f{2,3}に1個、f{1,2,3}に2個 -> ans = 6
        // F1: f1 - 1
        // F2: (F1+1)(f2+1) - 1 = f1 + f1f2 + f2
        // F3: (F2+1)(f3+1) - 1 = f1+f1f2+f2 + f1f3+f1f2f3+f2f3 + f3
        // Fn: (Fn-1+1)(fn+1) - 1 = (f1+1)(f2+1)(...)(fn+1)
        // -> ans: [x^s] (Fn) = [x^s] (f1+1)(f2+1)(...)(fn+1)
        
        // dp[i][s]: [x^s] (Fi)
        long[][] dp = new long[n+1][s+1];
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            int offset = array[i];
            
            // Fi = (Fi-1)(fi + 1)
            
            // Fi-1fi (選ぶ)
            for (int j = s; j - offset >= 0; j--) {
                dp[i+1][j] += dp[i][j-offset];
                dp[i+1][j] %= MOD;
            }
            // Fi-1fi (選ばない)
            for (int j = 0; j <= s; j++) {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
            // Fi-1 (選ばない)
            for (int j = 0; j <= s; j++) {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
        }
        // for (int i = 0; i <= n; i++) {
        //     System.out.println(Arrays.toString(dp[i]));
        // }
        
        System.out.println(dp[n][s]);
    }
}

Measured memory_bytes: 137220
N = int(input())
T = list(map(int, input().split()))
M = int(input())



for i in range(M):
    SUM = 0
    P,X= map(int, input().split())
    for i in range(N):
        Z = T[P-1]
        T[P-1] = X
        SUM = SUM + T[i]
        T[P-1] = Z
    print(SUM)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<numeric>
#include<vector>
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  int x[m];
  for (int i=0;i<m;i++) cin >> x[i];
  sort(x,x+m);
  int l[m-1];
  for (int i=0;i<m-1;i++) l[i] = x[i+1] - x[i];
  sort(l,l+m-1);
  int count = x[m-1] - x[0];
  for (int i=0;i<n-1;i++) count -= l[m-2-i];
  if (n >= m) cout << 0 << endl;
  else cout << count << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#define ll long long

using namespace std;

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


ll lcd(ll a, ll b) {
	return a*b/gcd(a, b);
}



int main() {
	int x;
	cin >> x;
	cout << lcd(x, 360)/x<< endl;	
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

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

    std::priority_queue<int> products;
    for (int i = 0; i < N; ++i)
    {
        int price;
        cin >> price;
        products.push(price);
    }

    for (int i = 0; i < M; ++i)
    {
        int price = products.top();
        products.pop();
        price /= 2;
        products.push(price);
    }

    long total = 0;
    while (!products.empty())
    {
        total += products.top();
        products.pop();
    }

    cout << total << endl;

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D, N;
  cin >> D >> N;

  if (N!=100){
    if(D==0) cout << N << endl;
    else if(D == 1) cout << N *100 << endl;
    else cout << N * 10000 << endl;
  }

  else{
    if(D==0) cout << 101 << endl;
    else if(D==1) cout << 10100 << endl;
    else cout << 1010000 << endl;
  }

}

Measured memory_bytes: 256
import sys
for s in sys.stdin:
    x1,y1,x2,y2,xq,yq = map(float,s.split(","))
    dx,dy = x2-x1,y2-y1
    det = dx*dx+dy*dy
    y0 = dx*(y1*dx-x1*dy) + dy*(yq*dy+xq*dx)
    x0 = -dy*(y1*dx-x1*dy) + dx*(yq*dy+xq*dx)
    x0 /= det
    y0 /= det
    xp = x0+(x0-xq)
    yp = y0+(y0-yq)
    print xp,yp

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 200010, M = 1010;

int n;
int a[N], f[N];
LL m;

bool check(LL x)
{
	LL cnt = 0;
	for (int i = 1; i <= n; i ++ )
		if ((LL)a[i] * f[i] > x)
			cnt += max(0LL, (LL)a[i] - x / (LL)f[i]);
	return cnt <= m;
}

int main()
{
	scanf("%d%lld", &n, &m);
	for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i ++ ) scanf("%d", &f[i]);
	sort(a + 1, a + 1 + n);
	sort(f + 1, f + 1 + n, greater<int>());
	
	LL l = 0, r = 1e12 + 10;
	while (l < r)
	{
		LL mid = l + r >> 1;
		if (check(mid)) r = mid;
		else l = mid + 1LL;
	}
	
	printf("%lld\n", r);
	return 0;
}

Measured memory_bytes: 1792
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 = sc.nextInt();
		int a[] = new int[N];
		int b[] = new int[N];
		for (int i=0;i<N;i++) {
			a[i] = sc.nextInt();
			b[i] = a[i];
		}
		Arrays.sort(a);
		for (int i=0;i<N;i++) {
			if (b[i]<a[N/2]) {
				System.out.println(a[N/2]);
			} else {
				System.out.println(a[N/2-1]);
			}
		}
	}
}

Measured memory_bytes: 94592
import collections
#aa = collections.Counter(a) # list to list

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,k = readInts()
    A = readInts()
    A_qu = collections.Counter(A)
    ALL = []
    for i in A_qu:
        ALL.append(A_qu[i])
    ALL = sorted(ALL)
    ans = 0
    for i in range(len(ALL) - k):
        ans += ALL[i]
    print(ans)
if __name__ == '__main__':
  main()


Measured memory_bytes: 32564
let
  input() = readline()
  N, M = map(x -> parse(Int, x), input() |> split)
  A = map(x -> parse(Int, x), input() |> split)
  sumA = sum(A)
  choice = 0
  for i in 1:N
    A[i] >= sumA/4M && (choice += 1)
  end
  if choice >= M
    println("Yes")
  else
    println("No")
  end
end



Measured memory_bytes: 165900
#include<stdio.h>

int main(void){

	int n,m;
	int k[30];
	int a[30][30];
	int like[30]={};
	int count = 0;

	int buff;
	int i,j;

	scanf("%d %d",&n,&m);

	for(i=0;i<n;i++){
		scanf("%d",&k[i]);
		for(j=0;j<k[i];j++){
			
			scanf("%d",&buff);
			buff--;
			a[i][j] = buff;
			like[buff]++;
		}
	}
	
	for(i=0;i<30;i++){
		if(like[i] == n){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 128