akhauriyash/Code-Regression huggingface dataset:
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/




#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    int n, a, b; cin >> n >> a >> b;
    int ans = 100000000;
    ans = min(n * a, b);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int h,w;
cin >> h >> w;
vector<vector<char>> s(h,vector<char>(w,0));
REP(i,h) {
  REP(j,w) {
    cin >> s[i][j];
  }
}
vector<vector<int>> count(h,vector<int>(w,-1));
count[0][0]=0;
const vector<vector<int>> data = {{0,1},{1,0}};
int x,y;
REP(i,h+w-2) {
  REP(j,i+1){
    REP(k,2) {
      x=j+data[k][0];
      y=i-j+data[k][1];
      if(x>=h||y>=w) continue;
      if(s[j][i-j]!=s[x][y]) {
        if(count[x][y]!=-1){
          count[x][y]=min(count[j][i-j]+1,count[x][y]);
        } else {
          count[x][y]=count[j][i-j]+1;
        }
      } else if(s[j][i-j]==s[x][y]) {
        if(count[x][y]!=-1){
          count[x][y]=min(count[j][i-j],count[x][y]);
        } else {
          count[x][y]=count[j][i-j];
        }
      }
    }
  }
}
int ans;
if(s[0][0]=='.') {
  if(s[h-1][w-1]=='.') {
    ans = count[h-1][w-1]/2;
  } else if(s[h-1][w-1]=='#') {
    ans = (count[h-1][w-1]+1)/2;
  }
} else if(s[0][0]=='#') {
  if(s[h-1][w-1]=='.') {
    ans = (count[h-1][w-1]+1)/2;
  } else if(s[h-1][w-1]=='#') {
    ans = count[h-1][w-1]/2+1;
  }
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll H,W,D,Q;
  cin >> H >> W >> D;
  vector<vector<ll>> B(D,vector<ll>(H*W/D+1,0));
  vector<P> A(H*W);
  rep(i,H)rep(j,W){
    ll k;
    cin >> k;
    A.at(k-1)=P(i,j);
  }
  rep(i,H*W){
    if(i<D){
      B.at(i).at(i/D)=0;
    }else{
      B.at(i%D).at(i/D)=B.at(i%D).at(i/D-1)+abs(A.at(i-D).first-A.at(i).first)+abs(A.at(i-D).second-A.at(i).second);
    }
  }
  cin >> Q;
  rep(i,Q){
    ll l,r;
    cin >> l >> r;
    cout << B.at((r-1)%D).at((r-1)/D)-B.at((l-1)%D).at((l-1)/D) << endl;
  }
}
      

Measured memory_bytes: 9556
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,q;cin>>n>>q;
	pair<ll,pii> a[n];
	For(i,0,n){
		ll s,t,x;cin>>s>>t>>x;
		a[i] = {x,{s,t}};
	}
	sort(a,a+n);
	ll d[q];
	For(i,0,q){
		cin>>d[i];
	}

	vector<pii> L[q];

	For(i,0,n){
		ll l = lower_bound(d,d+q,a[i].se.fi-a[i].fi)-d;
		if(l<q) L[l].pb({a[i].fi,1});
		ll r = lower_bound(d,d+q,a[i].se.se-a[i].fi)-d;
		if(r<q) L[r].pb({a[i].fi,-1});
	}

	ll ans[q];
	memset(ans,-1,sizeof(ans));

	multiset<ll> s;
	For(i,0,q){
		for(pii x:L[i]){
			if(x.se==1){
				s.insert(x.fi);
			}else{
				s.erase(s.find(x.fi));
			}
		}

		if(s.size()!=0){
			ans[i] = *s.begin();
		}
	}

	For(i,0,q){
		cout<<ans[i]<<endl;
	}










	
}

Measured memory_bytes: 32604
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int x,y;

int main(){
	cin>>x>>y;
	int t=0;
	if(x==1) t+=3;
	if(x==2) t+=2;
	if(x==3) t+=1;
	if(y==1) t+=3;
	if(y==2) t+=2;
	if(y==3) t+=1;
	if(x==1&&y==1) t+=4;
	cout<<t*100000<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  if(A != 1 && B != 1){
    if(A > B){
      cout << "Alice";
    }
    if(A == B){
      cout << "Draw";
    }
    if(A < B){
      cout << "Bob";
    }
  }
  else{
    if(A == 1 && B != 1){
      cout << "Alice";
    }
    else if(B == 1 && A != 1){
      cout << "Bob";
    }
    else if(A == B){
      cout << "Draw";
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <unordered_map>
#include <iomanip>

using namespace std;

int main() {
	int N;
	cin >> N;
	std::vector<int> value;
	value.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> value.at(i);
	}
	sort(value.begin(), value.end());

	double ans = 0;
	for (int i = 0; i < N; i++) {
		if (i != 0) {
			ans = (ans + value.at(i)) / 2.0f;
		}
		else {
			ans = value.at(i);
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int mod = 998244353;

// mod_power.cc
ll po(ll k, ll x) {
  if (x == 0) {
    return 1;
  }
  if (x == 1) {
    return k % mod;
  }
  ll y = po(k, x/2);
  y = y * y % mod;
  if (x % 2 == 1) {
    y = y * k % mod;
  }
  return y;
}

int main() {
  int n;
  ll a, b, k;
  cin >> n >> a >> b >> k;

  vll factorial(n+1, 1);
  vll rev_fact(n+1, 1);
  FOR (i, 2, n+1) {
    factorial[i] = factorial[i-1] * i % mod;
    rev_fact[i] = po(factorial[i], mod-2) % mod;
  }

  vll comb(n+1, 0);
  rep (i, n+1) {
    comb[i] = factorial[n];
    comb[i] = comb[i] * rev_fact[i] % mod;
    comb[i] = comb[i] * rev_fact[n-i] % mod;
  }

  ll ans = 0;
  rep (ia, n+1) {
    ll rest = k - a * ia;
    if (rest < 0) {
      break;
    }
    if (rest % b != 0 || rest / b > n) {
      continue;
    }
    int ib = rest / b;
    ll add = comb[ia] * comb[ib] % mod;
    ans = (ans + add) % mod;
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 7296
from sys import stdin
S = stdin.readline().rstrip('\n')

o = False
s = 0
i = 0
while i < len(S):
    if o and S[i-1] == S[i]:
        i += 2
        if i <= len(S):
            s += 1
        o = False
    else:
        i += 1
        s += 1
        o = True

print(s)


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> v[11];
int p[11];
//22:37
int main() {
    int n,m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int x;
            cin >> x;
            x--;
            v[i].push_back(x);
        }
    }
    for (int i = 0; i < m; i++) cin >> p[i];
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        bool f = 1;
        for (int j = 0; j < m; j++) {
            int sum = 0;
            for (int k = 0; k < v[j].size(); k++) {
                if ((i >> v[j][k]) & 1) sum++; 
            }
            if (sum % 2 != p[j]) f = 0;
        }
        if (f) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//マインスイーパ
int main(){
  ll N,M,X,res,tmp;
  cin >> N >> M >> X;

  ll cnt = 0;
  REP(i,M)
  {
    cin >> tmp;
    
    if(tmp > X)break;
    
    ++cnt;
  }

  res = min(cnt, M-cnt);

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        PriorityQueue<Po>queue=new PriorityQueue<>(new Comparator<Po>(){
            public int compare(Po a,Po b){
                return -(a.b-b.b);
            }
        });
        ArrayList<Po>po=new ArrayList<>();
        
        for(int i=0;i<n;i++){
            Po p=new Po(sc.nextInt(),sc.nextInt());
            po.add(p);
        }
        Collections.sort(po,new Comparator<Po>(){
            public int compare(Po a,Po b){
                return a.a-b.a;
            }
        });
        int index=0;
        long ans=0;
        for(int i=1;i<=m;i++){
            while(index<po.size()&&po.get(index).a<=i){
                queue.add(po.get(index));
                index++;
            }
            if(queue.size()!=0)ans+=queue.poll().b;
        }
        System.out.println(ans);
    }
    
}class Po{
        int a,b;
        public Po(int x,int y){
            a=x;
            b=y;
        }
        public String toString(){
            return a+" "+b;
        }
    }


Measured memory_bytes: 86220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define WHITE 0
#define CANDIDATE 1
#define VISITED 2

void topo(vvi &g, vi &id, vi &c, vi &o, int n) {
  queue<int> q;
  q.push(n);

  while (!q.empty()) {
    int u = q.front(); q.pop();
    
    o.push_back(u);
    c[u] = VISITED;
    
    for (auto x: g[u]) {
      id[x]--;
      if (!id[x] && c[x] == WHITE) {
        c[x] = CANDIDATE;
        q.push(x);
      }
    }
  }
}

int main() {
  int v, e, s, t;
  cin >> v >> e;
  
  vvi g(v);
  vi id(v), c(v, WHITE), o;
  rep(i, e) {
    cin >> s >> t;
    g[s].push_back(t);
    id[t]++;
  }
  
  rep(i, v) 
    if (!id[i] && c[i] == WHITE) topo(g, id, c, o, i);
  
  rep(i, v) cout << o[i] << endl;
}




Measured memory_bytes: 3852
#include<bits/stdc++.h>
#define ll long long
 
const int maxn=1e6+6;
using namespace std;
set<int>s;
int main()
{
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    int cnt=0;
    int t;
    for(int i=1; i<=n; i++)
    {
        int ans=i*m;
        t=ans;
        s.insert(ans);
        for(int j=1; j<=m; j++)
        {
            s.insert(t+n-2*i);
            t=t+n-2*i;
        }
    }
    int tag=1;
    set<int>::iterator it;
    for( it=s.begin();it!=s.end();it++)
        if(*it==k)
        {
            printf("Yes\n");
            tag=0;
            break;
        }
    if(tag)
        printf("No\n");
    return 0;
}

Measured memory_bytes: 13056
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<int,int>P;

struct edge{
	int to,cap,cost,rev; //?????????,??????,?????¨,??????
};

const int MAX_N = 1002;
const int MAX_V = MAX_N*3;

vector<int> a;
vector<int> bf1,bf2;
vector<P> b;
vector<edge> G[MAX_V];
int N;

void add_edge(int from,int to,int cap,int cost){
	G[from].push_back((edge){to,cap,cost,G[to].size()});
	G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}

int min_cost_flow(const int n,const int s,const int t,int f)
{
	int res =0;
	int dist[MAX_V];
	int prevv[MAX_V];
	int preve[MAX_V];
	while(f>0){
		fill(dist,dist+n,INF);
		dist[s] = 0;
		bool update = true;
		while(update){
			update = false;
			for(int v=0;v<n;v++){
				if(dist[v] == INF)	continue;
				for(int i=0;i<G[v].size();i++){
					edge &e = G[v][i];
					if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
						dist[e.to] = dist[v] + e.cost;
						prevv[e.to] = v;	//??????????????????????¨???¶
						preve[e.to] = i;	//????????????????¨???¶
						update = true;
					}
				}
			}
		}

		if(dist[t] == INF){
			return -1;
		}

		int d = f;
		for(int v=t;v!=s;v=prevv[v]){
			d = min(d,G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * dist[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}

	return res;
}

int main()
{
	scanf("%d",&N);
	rep(i,N){
		int p,q;
		scanf("%d%d",&p,&q);
		a.push_back(p),a.push_back(q);
		bf1.push_back(p),bf2.push_back(q);
	}
	sort(all(a)),sort(all(b));
	a.erase(unique(all(a)),a.end());
	b.erase(unique(all(b)),b.end());
	int cnt = a.size();
	rep(i,N){
		add_edge(0,i+1,1,0);
	}
	rep(i,N){
		int id1 = lower_bound(all(a),bf1[i]) - a.begin();
		int id2 = lower_bound(all(a),bf2[i]) - a.begin();
		add_edge(i+1,N+id1+1,1,-bf2[i]),add_edge(i+1,N+id2+1,1,-bf1[i]);
		add_edge(i+1,N+cnt+1,1,0);
	}
	rep(i,cnt){
		add_edge(N+i+1,N+cnt+2,1,0);
	}
	add_edge(N+cnt+1,N+cnt+2,INF,0);
	cout << -min_cost_flow(N+cnt+3,0,N+cnt+2,N) << "\n";

	return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
    string s;
    cin>>s;

    int n=s.size();
    n++;

    int lmax[n+1],rmax[n+1];
    lmax[0]=0;
    rep(i,1,n){
      if(s[i-1]=='<') lmax[i]=lmax[i-1]+1;
      else lmax[i]=0;
    }

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

    ll ans=0;
    rep(i,0,n){
      ans+=max(rmax[i],lmax[i]);
    }

    cout<<ans<<endl;
    //rep(i,0,n) cout<<lmax[i]<<endl;
    //rep(i,0,n) cout<<rmax[i]<<endl;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

vector<int> z_algorithm(const string &s) {
  vector<int> prefix(s.size());
  for(int i=1, j=0; i<s.size(); i++) {
    if(i+prefix[i-j] < j+prefix[j]) {
      prefix[i] = prefix[i-j];
    } else {
      int k = max(0, j+prefix[j]-i);
      while(i+k < s.size() && s[k] == s[i+k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}

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

    vector<int> z(n);
    // z = z_algorithm(s);
    int ans = 0;
    rep(i,0,n-1){
        z = z_algorithm(&s[i]);
        rep(j,0,sz(z)-1)if(z[j]<=j)ans = max(ans,z[j]);
    }
    // vecprint(z);
    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 
#define P 998244353
#define G 3
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
#define fuck printf("FUCK!!\n");
using namespace std;

int n, num;
char s[1005];
int main()
{
    scanf("%d%s", &n, s);
    for(rint i=0; i<n; ++i)
    {
        if(s[i]=='R') num++;
        else num--;
    }
    if(num>0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
def main():
    N = int(input())
    dp = [[0] * 3 for _ in range(N+1)]
    for i in range(1, N+1):
        # i 日目の行動による幸福度
        happiness = [int(i) for i in input().split()]
        # i-1 日目の行動
        for j in range(3):
            # i 日目の行動
            for k in range(3):
                # i日目とi-1日目の行動が同じ場合はスキップ
                if j == k:
                    continue
                # i日目に行動kを選んだときの最大値
                dp[i][k] = max(dp[i][k], dp[i-1][j] + happiness[k])
    ans = max(dp[-1])
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 57708
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

ll solve(int y,int m,int d){
    int x[]={31,28,31,30,31,30,31,31,30,31,30,31};
    int month[12]={31};
    
    for(int i=1;i<12;i++){
        month[i]=month[i-1]+x[i];
    }
    
    ll ret=0;
    ret+=(y-1)*365;
    ret+=(y-1)/4-(y-1)/100+(y-1)/400;
    
    if(m!=1)ret+=month[m-2];
    
    ret+=d-1;
    
    if( ( (y%4==0 && y%100!=0) || y%400==0 ) && m>2 )ret++;
    
    return ret;
}


int main() {
    int y1,m1,d1,y2,m2,d2;
    while(cin>>y1>>m1>>d1>>y2>>m2>>d2){
        if(y1==-1)break;
        cout<<solve(y2,m2,d2)-solve(y1,m1,d1)<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
    fastio();
   
    int n;
    cin>>n;
    ll a[n];
    cn(a,n);
    ll dp[n]={0};
    dp[0]=a[0];
    for(int i=1;i<n;i++)
        dp[i] =(dp[i-1]+a[i])%MOD1;
    ll ans=0;
    for(int i=1;i<n;i++)
    {
        ll d = a[i]*dp[i-1];
        d%=MOD1;
        ans+=d;
        ans%=MOD1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6736
/*

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

// 入力
int n,m,q;
vector<int> a,b,c,d;

// 数列 hoge に要素を付け加えて行って、最終的にできる数列のうちの
// スコアの最大値を返す
// 特に、最初の呼出しに対する返り値が答え
ll dfs(vector<int> &hoge){
  ll res=0;
  if(hoge.size()==n){
    //数列 hoge のスコアを計算
    rep(i,q){
      if(hoge[b[i]]-hoge[a[i]]==c[i])res+=d[i];
    }
    return res;
  }
  int prev_last = (hoge.empty() ? 0 : hoge.back());
  rep2(add,prev_last,m){
    hoge.push_back(add);
    // 再帰呼出しながら、スコア最大値を更新
    res=max(res, dfs(hoge));
    hoge.pop_back();
  }
  return res;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cin>>n>>m>>q;
  a.resize(q),b.resize(q),c.resize(q),d.resize(q);
  rep(i,q){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    //0-indexed 
    --a[i],--b[i];
  }
  vector<int> hoge;
  cout<<dfs(hoge)<<endl;
}

Measured memory_bytes: 3616
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	int h;
	int n;
	cin>>h>>n;
	rb(i,1,n){
		int ai;cin>>ai;
		h-=ai;
	}
	if(h<=0){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007mope
#define ll long long
using namespace std;
signed main(){
	int m,k; cin>>m>>k;
	int ma = (1<<m)-1;
	if( ma < k ){
		cout<<-1<<endl;
		return 0;
	}
	if( m == 0 ){
		cout<<"0 0"<<endl;
		return 0;
	}
	if( m == 1 ){
		if( k == 0 ){
			cout<<"1 1 0 0"<<endl;
			return 0;
		}
		else{
			cout<<-1<<endl;
			return 0;
		}
	}
	for(int i=0;i<=ma;i++){
		if( i == k )continue;
		cout<<i<<" ";
	}
	cout<<k<<" ";
	for(int i=ma;i>=0;i--){
		if( i == k)continue;
		cout<<i<<" ";
	}
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int solve(int n) {
  vector<int> v;
  for (int i=2; i*i<=n; ++i) {
    bool f = 0;
    while(n%i==0) {
      if (!f) {
        v.push_back(i);
        f = 1;
      }
      n/=i;
    }
  }
  if (n!=1) v.push_back(n);
  int sum = 0;
  REP(i, v.size()-1) sum+=v[i];
  // FOR(it, v) cout << *it << " ";
  // cout << v[v.size()-1] - sum << endl;
  return v[v.size()-1] - sum;
}

int main() {
  int a, b;
  while(cin >> a >> b, a||b) {
    cout << (solve(a)<solve(b)?"b":"a") << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 1000000007


ll n;
int a[500010];
int cum[500010];
ll det0[1<<20|100];
ll det1[1<<20|100];
ll cnt1[1<<20|100];
ll pre0[1<<20|100];
ll crr0;
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,n)cum[i+1]=cum[i]^a[i];
	
	rep(i,1,n+1){
		if(cum[i]==0){
			crr0++;
		}else{
			ll x=cum[i];
			ll zero=crr0-pre0[x];
			if(zero){
				det1[x]=(det1[x]+(det0[x]+1)*cnt1[x]%MOD)%MOD;
				det0[x]=(det0[x]+ det1[x]   *zero   %MOD)%MOD;
				cnt1[x]=1;
				pre0[x]=crr0;
			}else{
				cnt1[x]++;
			}
		}
	}
	
	ll ANS=0;
	if(cum[n]==0){
		ANS=pom(2,crr0-1,MOD);//0
		rep(x,1,1<<20){
			det1[x]=(det1[x]+(det0[x]+1)*cnt1[x]%MOD)%MOD;
			ANS=(ANS+det1[x])%MOD;
		}
	}else{
		ll x=cum[n];
		ANS=(det0[x]+1)%MOD;
	}
	printf("%lld",ANS);
}


Measured memory_bytes: 36864
#include <stdio.h>
#include <math.h>

typedef struct{
  double x;
  double y;
} Point;

void KOCK(int n, Point p1, Point p2){
  Point s,t,u;

  if(n == 0) return;

  s.x = (2*p1.x + 1*p2.x)/3;
  s.y = (2*p1.y + 1*p2.y)/3;
  
  t.x = (1*p1.x + 2*p2.x)/3;
  t.y = (1*p1.y + 2*p2.y)/3;

  u.x = (((t.x - s.x)*cos(M_PI/3)) - ((t.y - s.y)*sin(M_PI/3)) + s.x);
  u.y = (((t.x - s.x)*sin(M_PI/3)) + ((t.y - s.y)*cos(M_PI/3)) + s.y);

  KOCK(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  
  KOCK(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  
  KOCK(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  
  KOCK(n-1,t,p2); 
}

int main(){
  Point P1,P2;
  int n;

  P1.x = 0;
  P1.y = 0;
  P2.x = 100;
  P2.y = 0;

  scanf("%d",&n);
  
  printf("%.8f %.8f\n",P1.x,P1.y);
  KOCK(n,P1,P2);
  printf("%.8f %.8f\n",P2.x,P2.y);

  return 0;
}



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

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
}node;

typedef struct node *Node;

Node root;

Node treeMinimum(Node x){
  while(x -> left != NIL)
    x = x -> left;
  return x;
}

Node treeMaximum(Node x){
  while(x -> right != NIL)
    x = x -> right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u ->key)
    return u;
    
    if(k < u -> key)
    return treeSearch(u -> left, k);

  if(k > u -> key)
    return treeSearch(u -> right, k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x -> right != NIL)
    return treeMinimum(x -> right);

  y = x -> parent;

  while(y != NIL && x == y -> right){
    x = y;
    y = y -> parent;
  }

  return y;
}

void treeDelete(Node z){
  Node x;
  Node y;

  if(z -> left == NIL || z -> right == NIL)
    y = z;

  else
    y = treeSuccessor(z);
    
  if(y -> left != NIL)
    x = y -> left;

  else
    x = y -> right;

  if(x != NIL)
    x -> parent = y -> parent;

  if(y -> parent == NIL)
    root = x;

  else if(y == y -> parent -> left)
    y -> parent -> left = x;

  else
   y -> parent -> right = x;

  if(y != z)
    z -> key = y -> key;
}

void insert(int k){
  Node x = root;
  Node y = NIL;
  Node z;

  z = malloc(sizeof(node));

  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;
  
  while( x != NIL){
    y = x;
    if(z -> key < x -> key)
      x = x -> left;

    else
      x = x -> right;
  }

  z -> parent = y;

  if(y == NIL)
    root = z;

  else if(z -> key < y -> key)
    y -> left = z;

  else
    y -> right = z;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u -> left);

    printf(" %d", u -> key);

    inorder(u -> right);
  }
}

void preorder(Node u){
  if(u != NIL){
    printf(" %d", u -> key);

    preorder(u -> left);
    preorder(u -> right);
  }
}

int main(){
  Node t;
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     if ( com[0] == 'f' ){
      scanf("%d", &x);
      t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 20556
/* 
 * Project: AtCoder Beginners Contest 153 A - Serval vs Monster
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/07/01
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstring>
using namespace std;


int a, h;

void solve() {

    if (h%a > 0)
        printf("%d\n", h/a+1);
    else
        printf("%d\n", h/a);
}

int main() {

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

    solve();

}

Measured memory_bytes: 3188
input_str = gets
input_str = gets
lines = input_str.split(" ").collect{|l| l.to_i}.sort.reverse

count = 0
#p lines
while 3 <= lines.size do
  b_lines = lines[1..-1]
  a = lines.shift
  while 2 <= b_lines.size do
    c_lines = b_lines[1..-1]
    b = b_lines.shift
    next if a == b
    c_lines.each do |c|
      next if (a == c) || (b == c)
      #puts("a=#{a}, b=#{b}, c=#{c}")
      break if (b + c) <= a
      count += 1
    end
  end
end

puts count



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

int main()
{
   string S, T;
   cin >> S >> T;
   int count = 0;

   for (int i = 0; i < S.length(); i++)
   {
      if (S[i] != T[i]) count++;
   }
   cout << count << endl;
}


Measured memory_bytes: 3836
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    private long combi2(long n) {
        return n * (n - 1) / 2;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int[] cnt = new int[200005];
        for (int i = 0; i < N; i++) {
            cnt[A[i]]++;
        }

        long sum = 0;
        for (int i = 0; i < 200005; i++) {
            if (cnt[i] > 1) {
                sum+=combi2(cnt[i]);
            }
        }

        for (int k = 0; k < N; k++) {
            // k: bannded index
            int b = A[k];
            long prev = 0;
            long cur = 0;
            if (cnt[b] > 1) prev = combi2(cnt[b]);
            sum-=prev;
            cnt[b]--;
            if (cnt[b] > 1) cur = combi2(cnt[b]);
            sum+=cur;
            System.out.println(sum);
            sum-=cur;
            cnt[b]++;
            sum+=prev;
        }

        return;
    }

}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
int main(){
    fast;
    int x, y;
    cin >> x >> y ;
    for(int i = 0; i <= x; i++){
        int a = i;
        int b = x - i;
        if(a * 2 + 4 * b == y){
            return cout << "Yes", 0;
        }
    }
    cout << "No";
    return 0;
}

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

int main(){
    int a, b, x;
    cin >> a >> b >> x;
    if (x < a || x > a + b)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
nab =input().split()
n = nab[0]
a = int(nab[1])
b = int(nab[2])
x = 0
for i in range(1,int(n)+1):
  temp = 0
  for j in range(len(str(i))):
    temp += int(str(i)[j:j+1])
  if temp>=a and temp<=b:
    x +=i

print(x)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
map<long long, long long> divide(long long n){//素因数分解
    map<long long, long long> res;
    for(long long i = 2; i * i <= n; i++){
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}
long long extgcd(long long a, long long b, long long &x, long long &y){
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    else{
        x = 1;
        y = 0;
    }
    return d;
}

int main(){
    long long N;
    cin >> N;
    map<long long, long long> m = divide(N);
    m[2]++;
    int n = m.size();
    vector<long long> num(n, 1), cnt(n);
    int index = 0;
    for(auto v: m){
        for(int i = 0; i < v.second; i++){
            num[index] *= v.first;
        }
        cnt[index] = v.second;
        index++;
    }
    long long ans = 1e18;
    for(int bit = 0; bit < (1 << n); bit++){
        long long k1 = 1, k = 1;
        for(int j = 0; j < n; j++){
            if((1 << j) & bit) k1 *= num[j];
            else k *= num[j];
        }
        if(k1 - k == 1){
            ans = min(ans, k);
        }
        else{
            long long a, b;
            extgcd(k1, k, a, b);
            if(k1 * a > k * b && a != 0 && b != 0) {
                ans = min(ans, k1 * a - 1);
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(void){
	string S;
	int fd,ld;
	cin>>S;
	
	REP(i,(int)S.length()){
		if(S[i]=='A'){
			fd=i;
			break;
		}
	}

	RREP(j,(int)S.length()+1){
		if(S[j]=='Z'){
			ld=j;
			break;
		}
	}
	printf("%d\n",ld-fd+1);
	return 0;
}



Measured memory_bytes: 640
#include <stdio.h>

int main(void)


{


    int a,b;


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


    if(a<b)

    {


        printf("a < b\n");


    }


    if(a>b)


    {


        printf("a > b\n");


    }


    if(a==b)


    {


        printf("a == b\n");


    }


    return 0;


}














    

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s, t;
	cin>>s>>t;
	if(s == t){cout<<"Yes"<<endl; return 0;}
	int n = s.size();
	vector<bool> visited(n, false);
	for(char c = 'a'; c <= 'z'; c++){
		char x = c;
		bool ok = true;
		for(int i = 0; i < n; ++i){
			if(t[i] == c && s[i] != c){
				x = s[i];
				ok = false;
				break;
			}
		}
		if(!ok){
			for(int i = 0; i < n; ++i){
				if(s[i] == x && !visited[i]){
					s[i] = c;
					visited[i] = true;
				}
			}
			for(int i = 0; i < n; ++i){
				if(s[i] == c && !visited[i]){
					s[i] = x;
					//visited[i] = true;
				}
			}
		}
	}
	bool ans = true;
	for(int i = 0; i < n; ++i){
		if(s[i] != t[i])ans = false;
	}
	if(ans)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 776
#include <iostream>
int main(){
int n,x;
int pwd = 0;
int cnt = 1;
std::cin >> n >> x;

int tmp[n];

for(int i =0;i < n;i++)
    std::cin >> tmp[i];

for(int i = 0; i < n; i++){
    if((pwd += tmp[i])<=x){
        cnt ++ ;
    }else break;
}
std::cout << cnt <<std::endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[51010]={};
    cin>>n;
    rep(i,51000){
        a[i]=(ll)((double)i*1.08);
    }
    ll s=lower_bound(a,a+51000,n)-a;
    if(a[s]!=n){
        cout<<":("<<endl;
    }
    else{
        cout<<s<<endl;
    }
    return 0;
}

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)

#define BR "\n"

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

  priority_queue<int> Q[n];

  rep0(i, q) {
    int query; cin >> query;
    if (query == 0) {
      int t, x; cin >> t >> x;
      Q[t].push(x);
    } else if (query == 1) {
      int t; cin >> t;
      if (Q[t].size() > 0) cout << Q[t].top() << BR;
    } else {
      int t; cin >> t;
      if (Q[t].size() > 0) Q[t].pop();
    }
  }

  return 0;
}


Measured memory_bytes: 4004
def maximumSum(a):
    foo = 0
    n = len(a)/3
    a = sorted(a)
    for i in xrange(n):
        foo += a[n*3-(i+1)*2]
    return foo

def main():
    n = int(raw_input().strip())
    a = [int(x) for x in raw_input().strip().split()]
    print maximumSum(a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31976
#include <bits/stdc++.h>
	
using namespace std;
	
#define endl "\n"
#define ll long long
#define vi vector <int >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
#define a first
#define b second


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

	int mx, mn, n;
	cin >> mx >> mn >> n;

	if(mn > mx) swap(mn, mx);

	int ans = 0;
	forn(i, mn + 1){
		if(mx*i >= n){
			cout << i << endl;
			break;
		}
	}


	return 0;
}


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

int main(){
  int N;
  cin >> N;
  int H[N];
  rep(i, N){
    cin >> H[i];
  }
  int now = 0;
  bool flag = true;
  rep(i, N-1){
    if (H[i] - H[i+1] < 1) continue;
    if (H[i] - H[i+1] == 1){
      H[i]--;
      if (H[i] < now) flag=false;
      else now = H[i];
    }
    if (H[i] - H[i+1] > 1) flag=false;
    if (flag == false) break;
  }
  if (flag==true) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 4020
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <intrin.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
 
void solve() {
	int l, r;
	int d;
	cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i <= r; i++)
		if (i % d == 0)
			ans++;
	cout << ans;
}
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int D, G;
    cin >> D >> G;
    pair<pair<int,int>, int> P[D];
    rep(i,D){
      P[i].first.first = (i+1) * 100;
      cin >> P[i].first.second >> P[i].second;
    }
    reverse(P, P+D);
    int ans = INF;
    for(int i=0;i<(1<<D);i++){
      int sum = 0;
      int cou1 = 0;
      for(int j=0;j<D;j++){
        if((1<<j) & i){
          sum += P[j].first.first * P[j].first.second;
          sum += P[j].second;
          cou1 += P[j].first.second;
        }
      }
      if(sum >= G){
        ans = min(ans, cou1);
        continue;
      }
      for(int j=0;j<D;j++){
        if(((1<<j) & i) == 0){
          if(G <= sum + (P[j].first.first * (P[j].first.second-1))){
            cou1 += (G-sum+P[j].first.first-1)/P[j].first.first;
            ans = min(ans, cou1);
            break;
          }
        }
      }
    }
    cout << ans << endl;
}

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

using namespace std;

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

int main() {
    int X, N;
    cin >> X >> N;
    vector<int> Ps(N);
    rep(i, N) {
        cin >> Ps.at(i);
    }
    int i=0;
    bool found = false;
    while(!found){
        int tmp1 = X-i;
        int tmp2 = X+i;
        bool exist1 = false;
        bool exist2 = false;
        rep(j, N){
            if(Ps.at(j) == tmp1){
                exist1 = true;
            }
            if(Ps.at(j) == tmp2){
                exist2 = true;
            }
            if(exist1 && exist2){
                break;
            }
        }
        if(!exist1 && !exist2){
            found = true;
            cout << tmp1 << endl;
        } else if(!exist1 && exist2){
            found = true;
            cout << tmp1 << endl;
        } else if(exist1 && !exist2){
            found = true;
            cout << tmp2 << endl;
        }
        i++;
    }
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <map>
#include <queue>
#define N 200010
#define ll long long
#define mo ((ll)1e9+7)
//10000000000037ll
//21993833369ll
#define db double
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define drep(i,a,b) for(int i=a;i>=b;--i)
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
bool cmp(int a, int b) {return a > b;}
inline ll read() {
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') {if (ch == '-')f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
int n;
ll a[N];
int main() {
	n = read();
	ll ans = 0;
	a[1] = read();
	rep(i, 2, n) {
		a[i] = read();
		if (a[i] < a[i - 1])ans += a[i - 1] - a[i], a[i] = a[i - 1];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 5256
import sys,time
sys.setrecursionlimit(10**7)

start_time = time.time()
N,M = map(int,input().split())
S = input()
src = [tuple(map(lambda x:int(x)-1,sys.stdin.readline().split())) for i in range(M)]

outdeg = [set() for i in range(2*N)]
for x,y in src:
    if S[x] == S[y]:
        #A0->A1, B0->B1
        outdeg[x].add(y+N)
        outdeg[y].add(x+N)
    else:
        #A1->B0, B1->A0
        outdeg[x+N].add(y)
        outdeg[y+N].add(x)

mem = [0] * (2*N)
def visit(v):
    if time.time() - start_time > 1.8:
        # gori~~~
        print('No')
        exit()
    if mem[v] == 1:
        print('Yes')
        exit()
    if mem[v] == 0:
        mem[v] = 1
        for to in outdeg[v]:
            visit(to)
        mem[v] = 2

for i in range(2*N):
    visit(i)

print('No')

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int a, b;
  cin >> a >> b;
  if((a - b) % 2 != 0) cout << "IMPOSSIBLE\n";
  else cout << a + (b - a) / 2 << '\n';
}


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

#define ll long long

int const N = 111, W = 1e5 + 11;

int n, w;
int arr[N][2], vis[N][W];
ll dp[N][W];

ll pound(int index, int weight)
{
		if (index > n)
				return 0;
				
		if (weight > w)
				return -1e9;
				
		if (vis[index][weight])
				return dp[index][weight];
				
		vis[index][weight] = 1;
		
		return dp[index][weight] = max(arr[index][1] + pound(index + 1, weight + arr[index][0]), pound(index + 1, weight));
}

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

    cin >> n >> w;
    
    for (int i = 0; i < n; ++i)
        cin >> arr[i][0] >> arr[i][1];
        
    cout << pound(0, 0);
    
    return 0;
}


Measured memory_bytes: 119040
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int[] a = new int[n];
			int[] b = new int[n];
			int[] c = new int[n];
			int[] d = new int[n];
			for(int i=0;i<n;i++){
				a[i] = sc.nextInt();
				b[i] = sc.nextInt();
				c[i] = sc.nextInt();
				d[i] = sc.nextInt();
			}
			
			int[] s = new int[1001];
			int p;
			int count = 0;
			
			PriorityQueue<Integer> q = new PriorityQueue<Integer>();
			PriorityQueue<Integer> r = new PriorityQueue<Integer>();
			for(int i=10;i>=0;i--){
				for(int j=0;j<n;j++){
					if(c[j]==i && q.contains(d[j])==false) q.add(d[j]);
				}
				while(q.size()!=0){
					p = q.poll();
					for(int j=0;j<n;j++){
						if(c[j]==i && d[j]==p) r.add(a[j]);
					}
					while(r.size()!=0){
						p = r.poll();
						for(int j=0;j<n;j++){
							if(a[j]==p){
								if((count<10 && s[b[j]]<3) || (count<20 && s[b[j]]<2) || (count<26 && s[b[j]]==0)){
									System.out.println(p);
									count++;
									s[b[j]]++;
									break;
								}
							}
						}
					}
				}
								
			}
		}	
	}	
}

Measured memory_bytes: 21028