akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = [int(input()) for i in range(N)]

def maxscore(S):
 Score = sum(S)
 if Score % 10 > 0:
  return Score
 else:
  min = 100
  for i in S:
   if i % 10 > 0 and i < min:
    min = i
  Score -= min
  return Score

jud = 0
for i in S:
 if i % 10 == 0:
  jud += 1
if jud == N:
 print(0)
else:
 print(str(maxscore(S)))

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

using namespace std;
struct node {
    int id, point;
} node[1<<18];
int n, a[131075];

void add(int id, int x)
{
    id=n-1+id;
    node[id].point+=x;

    while (id>0) {
        id=(id-1)/2;
        int c1=2*id+1, c2=2*id+2;
        if (node[c1].point>=node[c2].point)
            node[id]=node[c1];
        else
            node[id]=node[c2];
    }
}

void print()
{
#ifdef DEBUG
    int k=1;
    int x=0;
    while (true) {
        for(int i=0;i<k;++i) printf("(%d %d)", node[x+i].id, node[x+i].point);
        puts("");
        x+=k;
        k<<=1;
        if (x>=n) break;
    }
    puts("");
#endif
}

int main()
{
    int m, r, l;
    scanf("%d%d%d", &m, &r, &l);
    n=1;
    while (n<m) n<<=1;
    for(int i=0;i<m;++i) node[n-1+i].id=i;

    int pt=0;
    for(int i=0;i<r;++i) {
        int d, t, x;
        scanf("%d%d%d", &d, &t, &x);

        if (pt<t) {
            int id=node[0].id;
            a[id]+=t-pt;
        }
        add(d-1, x);
        print();
        pt=t;
    }
    print();
    a[node[0].id]+=l-pt;
#ifdef DEBUG
    for(int i=0;i<n;++i) printf("%d ", a[i]); puts("");
#endif
    printf("%d\n", 1+(max_element(a, a+n)-a));
}

Measured memory_bytes: 3172
#include <stdio.h>

int ave(int a, int b )
{
   int ave;
   ave = (a + b) / 2;
   if((a + b) % 2 == 1)
   {
   ave++;
   }
   return ave;
}
int main(void)
{
   int A, B;
   scanf("%d",&A);
   scanf("%d",&B);
   printf("%d",ave(A, B));
   return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int N = sc.nextInt();
 
   boolean flg = false;
   int ans = 0;
   for(int i=1;i<46300;i++)
   {
     if(i*108/100==N)
     {
       ans=i;
       flg=true;
       break;
     }
   }
   if(flg) System.out.println(ans);
   else System.out.println(":(");
 }
}

Measured memory_bytes: 23892
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	class K {
		Set<Integer> set;
		K() {
			set = new HashSet<Integer>();
		}
	}
	
	void run() {
		int n;
		while (true) {
			n = sc.nextInt();
			if (n == 0) break;
			K[] member = new K[n];
			for (int i = 0; i < n; i++) {
				member[i] = new K();
				int k = sc.nextInt();
				for (int j = 0; j < k; j++) {
					member[i].set.add(sc.nextInt());
				}
			}
			
			Set<Integer> leak = new HashSet<Integer>();
			int k = sc.nextInt();
			for (int i = 0; i < k; i++)
				leak.add(sc.nextInt());
			
			int count = 0;
			int id = 0;
			for (int i = 0; i < n; i++) {
				if (member[i].set.containsAll(leak)) {
					count++;
					id = i+1;
				}
			}
			
			if (count == 1)
				out.println(id);
			else
				out.println(-1);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 67060
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <functional>
#include <sstream>
using namespace std;

template <typename T>
string join(vector<T> &v, const string &delimiter)
{
    stringstream buffer;
    for(typename vector<T>::iterator it = v.begin(); it != v.end(); it++) {
        if (it != v.begin())
            buffer << delimiter;
        buffer << *it;
    }
    return buffer.str();
}

int main()
{
    vector<int> v;
    int x;

    while (cin >> x)
        v.push_back(x);

    sort(v.begin(), v.end(), [](int a, int b) {return a < b;});

    cout << join(v, " ") << endl;

    return 0;
}

Measured memory_bytes: 1240
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
#include <iterator>     // std::back_inserter
const double PI = acos(-1);
using namespace std;
using ll =long long;
#define rep(i,n)for(ll i=0;i<(n);i++)
const int mod = 1000000007;
const ll inf = 1e18 + 1;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
//ll f[101010], rf[101010];
//ll inv(ll x) {
//	ll res = 1;
//	ll k = mod - 2;
//	ll y = x;
//	while (k) {
//		if (k & 1) res = (res * y) % mod;
//		y = (y * y) % mod;
//		k /= 2;
//	}
//	return res;
//}
//void init() {
//	f[0] = 1;
//	for (ll i = 1; i < 101010;i++) f[i] = (f[i - 1] * i) % mod;
//	for(ll i = 0; i < 101010; i++) rf[i] = inv(f[i]);
//}
////---------------------------------------------------------------------------------------------------
//ll C(int n, int k) {
//	ll a = f[n]; // = n!
//	ll b = rf[n - k]; // = (n-k)!
//	ll c = rf[k]; // = k!
//
//	ll bc = (b * c) % mod;
//
//	return (a * bc) % mod;
//}

//小文字=大文字+32
int main() {
	ll N, M;
	cin >> N >> M;
	map <ll, ll >cnt;
	for (ll i = 2; i <= pow(M, 0.5); i++) {
		while (M % i == 0) {
			M /= i;
			cnt[i]++;
		}
	}
	if (M!=1) {
		cnt[M]++;
	}
	ll ans=1;
	for (auto J : cnt) {
	vector<vector<ll>>dp(N+1, vector<ll>(J.second + 1, 0));
	rep(i, N+1) {
		dp[i][0] = 1;
	}
		rep(i, N) {
			for (ll j = 1; j <= J.second; j++) {
				if (j - 1 - J.second >= 0) {
					dp[i + 1][j] = (dp[i + 1][j - 1] + dp[i][j] - dp[i][j - 1 - J.second] + mod) % mod;

				}
				else {
					dp[i + 1][j] = (dp[i + 1][j - 1] + dp[i][j]) % mod;

				}
			}
		}
	ans=ans*dp[N][J.second]%mod;
	}
	cout << ans;
}

Measured memory_bytes: 30880
a = input().split()

pura = int(a[0])     #1
zero = int(a[1])     #0
mai  = int(a[2])     #-1
num  = int(a[3])     #枚数
total = 0
k = num-pura-zero

if pura >= num:
    total = num
else:
    total = pura
    if zero >= num - pura:
        total = pura
    else:
        total = pura-(k)
print(total)

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



int main() {
  int N;
  cin>>N;
  vector<tuple<string, int, int>> vec;
  for(int i=0;i<N;i++){
    string s;
    int a;
    cin>>s>>a;
    vec.push_back(make_tuple(s,-a,i+1));
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<N;i++){
    cout << get<2>(vec.at(i)) << endl;
  }
  
    
}

Measured memory_bytes: 3584
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}
 
 

int n, k, arr[100005], depth[100005], par[100005];
vector<int> adj[100005];
bool done[100005];


void dfs0(int v, int p){
	par[v] = p;
	if(p == -1)	depth[v] = 0;
	else	depth[v] = depth[p]+1;
	for(auto vv : adj[v])
		if(vv != p)
			dfs0(vv, v);
}


void dfs(int v){
	done[v] = true;
	for(auto vv : adj[v])
		if(!done[vv])
			dfs(vv);
}


int main(){
 
    ios_base::sync_with_stdio(0);

    cin>>n>>k;
    for(int i=1;i<=n;i++){
    	cin>>arr[i];
    	if(i == 1)	continue;
    	adj[arr[i]].pb(i);
    }

    if(k == 1){
    	int ans = 0;
    	for(int i=1;i<=n;i++)
    		ans += (arr[i] != 1);
    	cout<<ans;
    	return 0;
    }

    int ans = (arr[1] != 1);
    arr[1] = 1;
    dfs0(1, -1);

    priority_queue<ii> pq;
    for(int i=2;i<=n;i++)
    	pq.push({depth[i], i});

    while(!pq.empty()){

    	int v = pq.top().ss;
    	pq.pop();
    	if(done[v] || depth[v] <= k)	continue;

    	int iter = k-1;
    	while(iter--){
    		v = par[v];
    	}
    	dfs(v);
    	ans++;
    }

    cout<<ans;
    return 0;
}




Measured memory_bytes: 12792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    string rs = s;
    reverse(all(rs));
    int n = s.size();
    string x = s.substr(0, n / 2);
    string rx = x;
    reverse(all(rx));
    string y = s.substr(n / 2 + 1, n / 2);
    string ry = y;
    reverse(all(ry));
    if (s != rs || x != rx || y != ry) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

ll n,x,y;


int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  cin >> n >> x >> y;
  
  vvll d(n,vll(n,1e9));
  x--;
  y--;
  
   d[x][y]=1;
   d[n-1][n-1]=0;
  rep(i,0,n-1){
    d[i][i]=0;
   rep(j,i+1,n){
    if(i<=x) {
      if(j<=x) d[i][j]=j-i;
      else if(x<j&&j<=y) d[i][j]=min(j-i,x-i+1+y-j);
      else d[i][j]=min(j-i,x-i+1+j-y);
    }
    else if(x<i&&i<=y) {
      if(x<j&&j<=y) d[i][j]=min(j-i,i-x+1+y-j);
      else d[i][j]=min(j-i,i-x+1+j-y);
    } 
    else {
      d[i][j]=j-i; 
    }
    }
  }
   
  map<ll,ll> mp;
 rep(i,0,n-1){
     rep(j,i+1,n){
       mp[d[i][j]]++;
     }
  }
  
  rep(i,0,n-1) cout << mp[i+1] << endl;
  
 
}

Measured memory_bytes: 31744
#include <iostream>
#include <algorithm>
#define INF 1000000007
using namespace std;

long long dp[100005];
bool use[100005];
int n;
int m;
int tmp;
int main()
{
    cin>>n>>m;
    for(int i = 0;i<=n;i++)use[i]=true;
    for(int i = 0;i<=n;i++)dp[i] = 0;
    for(int i = 0;i<m;i++){
        cin>>tmp;
        use[tmp] = false;
    }
    dp[0] = 1;
    for(int i = 1;i<=n;i++){
        if(i-1>=0 && use[i-1]){
            dp[i] += dp[i-1];
            
        }
        if(i-2>=0 && use[i-2]){
            dp[i] += dp[i-2];
        }
        dp[i] = dp[i]%INF;
    }
    cout<<dp[n]<<endl; 
    return 0;
}


Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
int N;
vector<int> G[102];
int f[102];
int f2[102];
int search(int id){
  int ret=0;
  for(int i=0;i<(int)G[id].size();i++){
    if(!f2[G[id][i]]){
      f[G[id][i]]=1;
      f2[G[id][i]]=1;
      ret = max(ret,search(G[id][i])+1);
      f2[G[id][i]]=0;
    }
  }
  return ret;
}
int search2(int id){
  int ret=0;
  for(int i=0;i<(int)G[id].size();i++){
    if(!f2[G[id][i]] && !f[G[id][i]]){
      f2[G[id][i]]=1;
      ret = max(ret,search(G[id][i])+1);
      f2[G[id][i]]=0;
    }
  }
  return ret;
}
int solve(int id){
  int ret=0;
  if((int)G[id].size()==1){
    if(!f[G[id][0]]){
      f[G[id][0]]=1;
      f2[G[id][0]]=1;
      ret = search(G[id][0])+1;
      f2[G[id][0]]=0;
    }
    return ret;
  }
  for(int i=0;i<(int)G[id].size();i++){
    for(int j=i+1;j<(int)G[id].size();j++){
      int tmpi=0,tmpj=0;
      bool fi=false,fj=false;
      if(!f[G[id][i]]){
	fi=true;
	f[G[id][i]]=1;
	f2[G[id][i]]=1;
	tmpi = search(G[id][i])+1;
	f2[G[id][i]]=0;
      }
      if(!f[G[id][j]]){
	fj=true;
	f[G[id][j]]=1;
	f2[G[id][j]]=1;
	tmpj = search2(G[id][j])+1;
	f2[G[id][j]]=0;
      }
      ret = max(ret,tmpi+tmpj);
    }
  }
  return ret;
}
int main(){
  while(1){
    scanf("%d",&N);
    if(!N) break;
    for(int i=0;i<N;i++){
      int a,b;
      scanf("%d %d",&a,&b);
      G[a].push_back(b);
      G[b].push_back(a);
    }
    int res=0;
    for(int i=0;i<102;i++){
      if(!G[i].empty()){
	memset(f,0,sizeof(f));
	f[i]=1;
	f2[i]=1;
	//      printf("wa:%d size %d\n",i,(int)G[i].size());
	int st = solve(i)+1;
	f2[i]=0;
	res = max(res,st);
	//     printf("wa ... %d %d\n",i,st);
      }
    }
    printf("%d\n",res);
    for(int i=0;i<102;i++) G[i].clear();
  }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define lli long long int
#define MAX 1000000000
using namespace std;

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

    lli a, b, c, k, sum=0;
    cin>>a>>b>>c>>k;
    if(k>a){
        sum += a;
        k = k-a;
    }
    else{
        sum += k;
        k = 0;
    }
    k = k-b;
    if(k>0){
        if(k>c)
            sum -= c;
        else
            sum -= k;
    }
    cout<<sum;

    return 0;
}


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

int main(){
    int N,M;
    int ans=0;
    int even=0,odd=0;
    cin>>N>>M;

    if(N>=2 &&M >=2){
        for(int a=1;a<N;a++){
            even +=(N-a);
        }

        for(int a=1;a<M;a++){
            odd +=(M-a);
    }

    cout<<even+odd<<endl;

return 0;
}

if(N<2 && M>=2){
    for(int a=1;a<M;a++){
            odd +=(M-a);
    }
     cout<<odd<<endl;
     return 0;
}else if(N>=2 && M<2){
     for(int a=1;a<N;a++){
            even +=(N-a);
        }
        cout<<even<<endl;
        return 0;
}else{
    cout<<"0"<<endl;
    return 0;
}
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

/////////////////////////////////////////////////////
//[1,n]
#define max_n 300000//調節！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
int bit[max_n+1],n;
int sum(int i){//a[1]~a[i]の和を求める
    int s=0;
    while(i>0){
        s+=bit[i];
        i-=i&-i;
    }
    return s;
}
void add(int i,int x){//a[i]にxを加える
    while(i<=n){
        bit[i]+=x;
        i+=i&-i;
    }
}
////////////////////////////////////////
int main(){
    cin>>n;
    int a[n];rep(i,0,n-1)cin>>a[i];
    vector<int>v;rep(i,0,n-1)v.pb(a[i]);
    sort(v.begin(),v.end());
   // v.erase(unique(v.begin(),v.end()),v.end());
    rep(i,0,n-1){
        a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
    }
   // rep(i,0,n-1)cout<<a[i]<<" ";
    ll ans=0;
    rep(i,0,n-1){
        ans+=i-sum(a[i]);
        add(a[i],1);
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 5448
import java.util.Scanner;
 
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = 700;
		for(int i = 0;i < 3;i++){
			if(s.charAt(i)=="o".toCharArray()[0]){
				n += 100;
			}
		}
		System.out.println(n);
	}
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll A[200000];
ll dp[200000];
ll Asum[200010];
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if(x < y) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

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

UnionFind uni;

void solve(ll X) {
    //cerr << "solve: " << X << endl;
    ll factor = A[0] - A[1];
    if(X >= Asum[N-1]) {
        cout << X - Asum[N-1] + factor << endl;
        return;
    }
    X = uni.root(X);
    X -= Asum[N-1] - Asum[3];
    X = max(X - A[2], A[2] - X);
    cout << X + factor << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N - 1; i++) cin >> A[i];
    Asum[0] = 0;
    for(int i = 2; i < N-1; i++) {
        Asum[i+1] = Asum[i] + A[i];
        //cerr << i + 1 << " " << Asum[i+1] << endl;
    }
    uni.init(2 * Asum[N-1] + 2);
    //cerr << Asum[N-1] << endl;
    for(int i = N - 2; i >= 2; i--) {
        for(int val = Asum[N-1] - Asum[i+1]; val <= Asum[N-1] - Asum[i]; val++) {
           // cerr << i << " " << val << endl;
           ll rest = val - (Asum[N-1] - Asum[i+1]);
           ll delta = A[i] - rest;
           ll to = Asum[N-1] - Asum[i] + delta;
           //cerr << "connect: " << val << " " << to << endl;
           uni.merge(val, to);
        }
    }
    ll M;
    cin >> M;
    while(M--) {
        ll X;
        cin >> X;
        solve(X);
    }
    return 0;
}


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

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

    int count = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
           count++;
        }
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
int n;
vector<vector<int> > t;
ll num_ways(bool black,int node,int par,vector<vector<ll> >&mem)
{
    if(t[node].size() == 1 && node!=1)
    {
        if(black)
            return 1;
        return 2;
    }
    if(mem[black][node] != -1)
        return mem[black][node];
    ll ans1=1,ans2=1;
    if(black)
    for(int i=0;i<t[node].size();i++)
    {
        if(t[node][i] != par)
            ans1  = (ans1*num_ways(false,t[node][i],node,mem))%mod;
    }
    else
    for(int i=0;i<t[node].size();i++)
    {
        if(t[node][i] != par){
            ans1  = (ans1*num_ways(false,t[node][i],node,mem) )%mod;
            ans2  = (ans2*num_ways(true,t[node][i],node,mem) )%mod;
        }
            
    }
    if(black)
        return mem[black][node] = ans1;
    return mem[black][node] = (ans1+ans2)%mod;
}
int main() {
    int x,y;
	cin>>n;
	t.resize(n+1);
	vector<vector<ll> >mem(2,vector<ll>(n+1,-1));
	for(int i=1;i<n;i++)
	{
	    cin>>x>>y;
	    t[x].push_back(y);
	    t[y].push_back(x);
	}
	
	cout<<num_ways(false,1,-1,mem);
	return 0;
}

Measured memory_bytes: 15600
#include<iostream>
#include<string>
using namespace std;
int main(){
  string S,ans="";
  cin>>S;
  int sum = 0;
  for(int i=0;i<8;i++){
    sum=S[0]-'0';
    ans=S[0];
    for(int k=0;k<3;k++){
      if(i & (1<<k)){
        sum=sum+(S[k+1]-'0');
        ans=ans+"+"+S[k+1];
      }else{
        sum=sum-(S[k+1]-'0');
        ans=ans+"-"+S[k+1];
      }
    }
    if(sum==7){
      break;
    }
  }
  cout<<ans+"=7"<<endl;
  return 0;
}


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

int main() {
  long int N, a = 0;
  cin >> N;
  for(int i = 0;i < N+1;i++){
    if (i % 3 != 0 && i % 5 != 0){
      a += i;
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 3632
# include <bits/stdc++.h>
# define ll long long
using namespace std;
const int N = 17, INF = 1e16;
ll dp[1 << N], group[1 << N], a[N][N], n;
int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }
    for(int mask = 0; mask < (1 << n); mask++){
        for(int j = 0; j < n; j++){
            if((mask >> j) & 1){
                for(int k = j + 1; k < n; k++){
                    if((mask >> k) & 1){
                        group[mask] += a[k][j]; 
                    }
                }
            }
        }
        dp[mask] = -INF;
    }
    dp[0] = 0; 
    for(int mask = 0; mask < (1 << n); mask++){
        vector < int > m;
        for(int j = 0; j < n; j++){
            if((mask >> j) & 1)continue;
            m.push_back(j); 
        }
        for(int new_mask = 0; new_mask < (1 << m.size()); new_mask++){
            int next_mask = mask;
            for(int j = 0; j < m.size(); j++){
                if((new_mask >> j) & 1){
                    next_mask |= (1 << m[j]);
                }
            }
            dp[next_mask] = max(dp[next_mask], dp[mask] + group[next_mask ^ mask]);
        }
    }
    cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>

const int MAXN = 3000;
const int MOD = 1e9 + 7;

int n, m, ans;
int dp[MAXN | 1][MAXN | 1][2];

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i <= n; ++i) dp[0][i][i == 0] = 1;
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j <= n; ++j) {
			for (int k = 0; k <= 1; ++k) {
				if (k == 0 && j == 0) continue;
				if (j > 0) {
					int kk = k | (j == 1);
					dp[i + 1][j - 1][kk] = (dp[i + 1][j - 1][kk] + dp[i][j][k]) % MOD;
					dp[i + 1][j][k | (j == 1)] = (dp[i + 1][j][k | (j == 1)] + dp[i][j][k]) % MOD;
				}
				if (j < n) {
					dp[i + 1][j + 1][k] = (dp[i + 1][j + 1][k] + dp[i][j][k]) % MOD;
					dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % MOD;
				}
			}
		}
	}
	for (int i = 0; i <= n; ++i) ans = (ans + dp[m][i][1]) % MOD;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 70656
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;

  std::vector<int> l(n);
  for (auto&& li : l) std::cin >> li;
  std::sort(l.begin(), l.end());

  int count = 0;
  for (int i = 0; i < n; ++i) {
    const auto a = l[i];
    for (int j = i + 1; j < n; ++j) {
      const auto b = l[j];
      for (int k = j + 1; k < n; ++k) {
        const auto c = l[k];
        if (c < a + b) {
          ++count;
        } else {
          break;
        }
      }
    }
  }

  std::cout << count << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];

    sort(all(d));
    put(d[n/2] - d[n/2-1])

    return 0;
}

Measured memory_bytes: 3772
package main
 
import (
	"fmt"
)
 
func main() {
 
	var n uint64 = 0
	var k uint64 = 0
	fmt.Scan(&n)
	fmt.Scan(&k)
 
	exec(n, k)
 
}
 
func exec(n uint64, k uint64) {
	if n == 0 {
		fmt.Println(0)
		return
	}
	cnt := 1
	for cur := uint64(k); cur <= n; cur *= k {
		cnt++
	}
	fmt.Println(cnt)
}

Measured memory_bytes: 512
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    from collections import defaultdict
    dd = defaultdict(int)
    
    for _ in range(N):
        s=list(input())
        s.sort()
        s=''.join(map(str, s))
        dd[s]+=1
        
    ans=0
    
    for k,v in dd.items():
        ans+=(v*(v-1))//2
        
    print(ans)

main()


Measured memory_bytes: 102084
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a, b, c, m;
    bool b1 = true;
    cin>> a >> b;
    c = (a - b)/ 2;
    if ( (a - b)% 2!= 0 ){
        b1 = false;
    }
    if (c< 0){
        c*=-1;
    }
    if (a<=b){
        m =a+c;
    }

    else {
        m =b+ c;
    }
    if (b1 == true){
        cout << m;
    }
    else {
        cout << "IMPOSSIBLE";
    }
//    cout << b+ c;
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int m;
  cin >> m;
  long long dsum = 0, s = 0;
  while (m--) {
    int d;
    long long c;
    cin >> d >> c;
    dsum += d * c;
    s += c;
  }
  long long res = (dsum - 1) / 9 + (s - 1);
  cout << res << '\n';
}


Measured memory_bytes: 256
/*input
1000000000000000 1000000000000000 1000000000000000
*/
 
 
#include <bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define INTMAX  2147483647
#define INTMIN  -2147483648
#define LLMAX 9223372036854775807
#define LLMIN -9223372036854775808
#define MOD 1000000007
typedef map<long long int, long long int> mpi;
typedef set<long long int> seti;
typedef multiset<long long int> mseti;
typedef priority_queue<long long int> pq;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PI 3.1415926535
#define dbg(x) cerr << "\n" << (#x) << " = " << (x) << endl ;
//#define cerr if(false)cerr

// cout<<fixed<<setprecision(10)<<(v1+v2+v3)<<endl;
  
struct node{
    ll val;
};
struct Interval {int start, end;};
bool compare(struct node n1, struct node n2) {
    return (n1.val < n2.val);
}






int main(){
	long long int x,k,d; cin>>x>>k>>d;
	x = abs(x);
	ll fr = x/d;
	if(fr >= k){
		cout<<abs(x - (d*k))<<endl;
		return 0;
	}
	k = k - (x/d);
	x = x%d;
	if(k%2==1){cout<<abs(x-d)<<endl;}
	else cout<<abs(x)<<endl;
	return 0;	
}















 

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

int main() {
  	int N, M, Q;
  	cin >> N >> M >> Q;
  
  	int a[Q], b[Q], c[Q], d[Q];
  	for (int i = 0; i < Q; i++){
      	cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
  
  	int i[10];
  	int max_ = 0;
  
  	for (i[0] = 1; i[0] <= M; i[0]++){
      	for (i[1] = i[0]; i[1] <= M; i[1]++){
			for (i[2] = i[1]; i[2] <= M; i[2]++){
      			for (i[3] = i[2]; i[3] <= M; i[3]++){
      				for (i[4] = i[3]; i[4] <= M; i[4]++){
      					for (i[5] = i[4]; i[5] <= M; i[5]++){
      						for (i[6] = i[5]; i[6] <= M; i[6]++){
      							for (i[7] = i[6]; i[7] <= M; i[7]++){
      								for (i[8] = i[7]; i[8] <= M; i[8]++){
      									for (i[9] = i[8]; i[9] <= M; i[9]++){
                                          	int res = 0;
                                          	for (int k = 0; k < Q; k++){
                                              	if (i[b[k] - 1] - i[a[k] - 1] == c[k]) res += d[k];
                                            }
                                          	max_ = max(res, max_);
        								}
        							}
        						}
        					}
        				}
        			}
        		}
    		}
        }
    }
  
  	cout << max_ << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll h;
	cin>>h;
	ll n=0;
	while(h>0){
		n++;
		h/=2;
	}
	cout<<ll(pow(2,n)*1ll-1);
	return 0;
}


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

int main(){
    int n, mizu=0;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    for(int i=1;i<=100;i++){
        int go = 0;
        for(int j=0;j<n;j++){
            if(h[j] >= 1){
                h[j]--;
                go = 1;
            }else{
                if(go){
                    mizu++;
                }
                go = 0;
            }
        }
        if(go)mizu++;
    }
    cout << mizu << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)

typedef pair<int, int> P;

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

int main() {
    int n,p; cin >> n >> p;
    string s; cin >> s;

    reverse(s.begin(), s.end());


    // 10と素でない素数
    ll ans = 0;
    if(p == 2 || p == 5) {
        rep(i, n) {
            int now = s[i]-'0';
            if(now%p == 0) ans += n-i;
        }
        cout << ans << endl;
        return 0;
    }

    vector<int> sum(n+1, 0);
    int ten = 1;
    rep(i, n) {
        int now = (s[i]-'0') * ten % p;
        sum[i+1] = (sum[i] + now) % p;
        ten *= 10; ten %= p;
    }

    vector<int> cnt(p);
    ans = 0;
    rep(i, n+1) {
        ans += cnt[sum[i]];
        cnt[sum[i]]++;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1412
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}


//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let H:u32 = read();
    let W:u32 = read();
    let h:u32 = read();
    let w:u32 = read();

    println!("{}", H*W - (h*W+w*H-(h*w)));


}


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

int main(){
	string s;
	cin >> s;
	lint sum = 0;
	string pre_s = s;
	rep(bit,1 << (s.size()-1)){
		lint tmp = 0;
		rep(j,s.size()+7){
			if(bit>>j & 1){
				string s_t = s.substr(pre_s.size()-1-j);
				tmp += stol(s_t);
				s = s.substr(0,s.size()-s_t.size());
			}
		}
		tmp += stol(s);
		sum += tmp;
		s = pre_s;
	}
	cout << sum << endl;
	return 0;
}

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

int main()
{
    string str;
    vector<string> vec;
    int h, m;

    while (1) {
        cin >> str;
        if (str[0] == '-') break;
        cin >> m;
        for (int i = 0; i < m; i++) {
            cin >> h;
            str += str.substr(0, h);
            str.erase(str.begin(), str.begin() + h);
        }
        vec.push_back(str);
        vec.push_back(" ");
    }
    for (int i = 0; i < vec.size(); i++) {
        if (vec[i] == " ")
            cout << endl;
        else
            cout << vec[i];
    }
}


Measured memory_bytes: 3172
class Node(object):
    def __init__(self, num, prv = None, nxt = None):
        self.num = num
        self.prv = prv
        self.nxt = nxt
  
  
class DoublyLinkedList(object):
    def __init__(self):
        self.start = self.last = None
  
    def insert(self, num):
        new_elem = Node(num)
  
        if self.start is None:
            self.start = self.last = new_elem
        else:
            new_elem.nxt = self.start
            self.start.prv = new_elem
            self.start = new_elem
  
    def delete_num(self, target):
        it = self.start
        while it is not None:
            if it.num == target:
                if it.prv is None and it.nxt is None:
                    self.start = self.last = None
                else:
                    if it.prv is not None:
                        it.prv.nxt = it.nxt
                    else:
                        self.start = self.start.nxt
  
                    if it.nxt is not None:
                        it.nxt.prv = it.prv
                    else:
                        self.last = self.last.prv
                break
            it = it.nxt
  
    def delete_start(self):
        if self.start is self.last:
            self.start = self.last = None
        else:
            self.start.nxt.prv = None
            self.start = self.start.nxt
  
    def delete_last(self):
        if self.start is self.last:
            self.start = self.last = None
        else:
            self.last.prv.nxt = None
            self.last = self.last.prv
  
    def get_content(self):
        ret = []
        it = self.start
  
        while it is not None:
            ret.append(it.num)
            it = it.nxt
  
        return ' '.join(ret)
  
  
def _main():
    from sys import stdin
  
    n = int(input())
  
    lst = DoublyLinkedList()
      
    for _ in range(n):
        cmd = stdin.readline().strip().split()
        if cmd[0] == 'insert':
            lst.insert(cmd[1])
        elif cmd[0] == 'delete':
            lst.delete_num(cmd[1])
        elif cmd[0] == 'deleteFirst':
            lst.delete_start()
        elif cmd[0] == 'deleteLast':
            lst.delete_last()
  
    print(lst.get_content())
  
  
if __name__ == '__main__':
    _main()


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

int main() {
  int A,B; 
  cin >> A >> B;
  vector<int>data(A);
  for(int i=0; i<data.size(); i++) {
    cin >> data.at(i);
  }
  sort(data.begin(),data.end());
  int sum=0;
  for(int i=0; i<B; i++) {
    sum = sum + data.at(i);
  }
  cout << sum << endl;
}

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

int main()
{
    int k, ans = 0;
    string s;
    cin >> k >> s;
    for (int i = 0; i < s.length() - 2; i++)
    {
        if (s.substr(i, 3) == "ABC")
        {
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}


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

int main() {
  int N, n1, n2, n3, n4;
  cin >> N;
  n4 = N/1000;
  n3 = (N - n4 * 1000) / 100;
  n2 = (N - n4 * 1000 - n3 * 100) / 10;
  n1 = (N - n4 * 1000 - n3 * 100 -n2 * 10);
  if (n1 == n2 && n2 == n3) {
    cout << "Yes" << endl;
  }
  else if (n2 == n3 && n3 == n4) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  // ここにプログラムを追記
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int t=0;
string s,ch="CODEFESTIVAL2016";
int main()
{
	cin>>s;
	for(int i=0;i<16;i++)
	{
		if(s[i]!=ch[i]) t++;
	}
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 256
/* 
   AOJ 1167
   Pollock's conjecture
   
*/

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int *a, min;

void dfs_odd(int x, int i, int c)
{
  if(min < c)
    {
      return ;
    }
  for(; i > 0; i--)
    {
      if(a[i] % 2 == 0)
	continue;
      if(x - a[i] == 0)
	{
	  if(min > c)
	    {
	      min = c;
	      return ;
	    }
	}
      else if(x - a[i] > 0)
	dfs_odd(x - a[i], i, c + 1);
    }
  return ;
}

void dfs(int x, int i, int c)
{
  if(min < c)
    {
      return ;
    }
  for(; i > 0; i--)
    {
      if(x - a[i] == 0)
	{
	  if(min > c)
	    {
	      min = c;
	      return ;
	    }
	}
	
      else if(x - a[i] > 0)
	dfs(x - a[i], i, c + 1);
    }
  return ;
}



int main(void)
{
  int x, i, max_a;
  for(i = 1; i * (i + 1) * (i + 2) / 6 < 1000000; i++);
  max_a = i;
  a = malloc(sizeof(int) * max_a);

  for(i = 1; i < max_a; i++)
    {
      a[i] = i * (i + 1) * (i + 2) / 6;
    }
  int m;
  while(scanf("%d", &x), x)
    {
      min = INT_MAX;
      for(i = 1; x >= a[i]; i++);
      m = i - 1;
      dfs(x, m, 1);
      printf("%d ", min);
      min = INT_MAX;
      dfs_odd(x, m, 1);
      printf("%d\n", min);
    }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  cout << "Christmas";
  if(n==25){
    cout << endl;
    return 0;
  }
  cout << " Eve";
  if(n==24){
    cout << endl;
    return 0;
  }
  cout << " Eve";
  if(n==23){
    cout << endl;
    return 0;
  }
  cout << " Eve" << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n, x, sum=0;
  cin >> n >> x;

  int min=x;
  for (int i=0; i<n; i++) {
    int m;
    cin >> m;
    sum+=m;
    if (m<min) min=m;
  }

  printf("%d\n", (x-sum)/min+n);
  return 0;
}

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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)
#define LL           long long
#define cnd tree[idx]
#define lnd (idx<<1)
#define rnd ((idx<<1)+1)
#define MAX 400005
#define Val first
#define lazy second
#define F first
#define S second

typedef pair<LL,LL> pii;

const LL INF = (LL)10000000000000000;
pii tree[4*MAX];

void update_node(int idx, int b, int e,LL v)
{
    cnd.Val += v;
    cnd.lazy += v;
}

void lazy_update(int idx, int b, int e)
{
    int m = (b+e)>>1;

    update_node(lnd, b, m, cnd.lazy);
    update_node(rnd, m + 1, e, cnd.lazy);

    cnd.lazy = 0;
}

LL query(int idx, int b, int e, int st, int en)
{
    if(st > e || en < b ) return INF;
    if(st <= b && en >= e) return tree[idx].Val;

    lazy_update(idx, b, e);

    int m = (b+e)>>1;

    LL lf = query(lnd, b, m, st, en);
    LL rg = query(rnd, m + 1, e, st, en);

    cnd.Val = min(tree[lnd].Val, tree[rnd].Val);
    return min(lf, rg);
}

void update(int idx, int b, int e, int st, int en,LL v)
{
    if(st > e || en < b ) return;
    if(st <= b && en >= e)
    {
        update_node(idx, b, e, v);
        return;
    }

    lazy_update(idx, b, e);

    int m = (b+e)>>1;
    update(lnd, b, m, st, en, v); update(rnd, m + 1, e, st, en, v);
    cnd.Val = min(tree[lnd].Val, tree[rnd].Val);
}

LL dp[MAX], prin, lolo;
vector<pii> mat[MAX];

int main()
{
    ios::sync_with_stdio(false);
    //inf;
    int n, m, l, r, c;

    cin >> n >> m;
    FOR(i,0,m-1)
    {
        cin >> l >> r >> c; prin += c;
        mat[r].push_back( {l, c} );
    }

    int base = 1;
    while(base <= n) {base *= 2;}

    FOR(i,1,n + 1)
    {
        dp[i] = query(1, 0, base, 0, i - 1);

        for(auto x : mat[i])
             update(1, 0, base, 0, x.F - 1, x.S);

        update(1, 0, base, i, i, dp[i]);
    }

    cout << prin - dp[n + 1] << endl;

    return 0;
}


Measured memory_bytes: 29056
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

int main() {
    ll n, m; cin >> n >> m;
    ll ans = 0;
    if (2 * n >= m) ans += m / 2;
    else {
        ans += n;
        m -= 2 * n;
        ans += m / 4;
    }
    cout << ans << endl;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n = in(), t = in();
    vll a = in(n);
    vll cur_min(n, LINF);
    vll score(n, 0);
    ll max_score = 0;
    cur_min[0] = a[0];
    int cnt = 0;
    rep(i, n - 1)
    {
        cur_min[i + 1] = min(cur_min[i], a[i + 1]);
        score[i + 1] = max(a[i + 1] - cur_min[i + 1], (ll)0);
        if (max_score == score[i + 1])
        {
            ++cnt;
        }
        else if (max_score < score[i + 1])
        {
            cnt = 0;
            ++cnt;
            max_score = score[i + 1];
        }
    }
    cout << cnt << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 1234567;
char s[MAXN];
int dig[MAXN];

int main() {
    scanf("%s", s + 1);
    int N = strlen(s + 1);
    for (int i = 1; i <= N; i++)
        dig[i] = s[i] - '0';
    int sum = 0;
    for (int i = N; i >= 1; i--) {
        if (dig[i] < 5) {
            sum += dig[i];
        } else if (dig[i] == 5) {
            sum += 5;
            if (dig[i - 1] >= 5) dig[i - 1]++;
        } else {
            dig[i - 1]++;
            sum += (10 - dig[i]);
        }
    }
    sum += dig[0];
    printf("%d\n", sum);
    return 0;
}


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

int main(){
	int n; cin>>n;
	vector<int>h(n); for(auto&i:h)cin>>i;
	int mx=h.front(),ans=0;
	for(auto&i:h){
		mx=max(mx,i);
		if(i>=mx)++ans;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        try(Scanner scn = new Scanner(System.in)) {
            while(scn.hasNextInt()) {
                int num = scn.nextInt();
                if(num > 0) {
                    list.push(num);
                } else {
                    System.out.println(list.pop());
                }
            }
        }
    }
}

Measured memory_bytes: 26052
/*  Isn't it lovely, all alone?             */
/*  Heart made of glass, my mind of stone   */
/*  Tear me to pieces, skin to bone         */
/*  Hello, welcome home                     */

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 998244353
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

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


ll t=1;
//cin>>t;
while(t--)
{

ll n;
cin>>n;

if(n>=400 && n<=599)
cout<<8<<endl;
if(n>=600 && n<=799)
cout<<7<<endl;
if(n>=800 && n<=999)
cout<<6<<endl;
if(n>=1000 && n<=1199)
cout<<5<<endl;
if(n>=1200 && n<=1399)
cout<<4<<endl;
if(n>=1400 && n<=1599)
cout<<3<<endl;
if(n>=1600 && n<=1799)
cout<<2<<endl;
if(n>=1800 && n<=1999)
cout<<1<<endl;

}
return 0;
}














Measured memory_bytes: 3648
#include <iostream>
#include <bits/stdc++.h>
#define lli  long long int
using namespace std;
#define S second
#define F first
#define pb push_back
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
#define PI 3.14159265358979323846
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define mini(x,y) (y + ((x - y) & ((x - y) >>(sizeof(int) * CHAR_BIT - 1))))
#define maxi(x,y) (x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))))
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)
{   int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {   if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

int main()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x, n, i;
    cin >> x >> n;
    int a[n];
    map<lli, lli> mp;
    for (i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]] = 1;
    }
    if (mp[x] != 1) {
        cout << x;
        return 0;
    }
    int l = 1;
    for (i = x;;) {

        if (mp[i - l] != 1) {
            cout << i - l;
            return 0;
        }
        if (mp[i + l] != 1) {
            cout << i + l;
            return 0;
        }
        l++;
    }
}

Measured memory_bytes: 3636