akhauriyash/Code-Regression huggingface dataset:
// Hovalhagh
// Ya Aziz & Hakim
// AliReza Kaboli

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 100;

ll dp[N];

int main() {
	int n, w;
	cin >> n >> w;
	for (int i = 1; i <= n; ++i) {
		int w, v;
		cin >> w >> v;
		for (int j = N; j >= 0; --j)
			if (j - w >= 0)
				dp[j] = max(dp[j], dp[j - w] + v);
	}
	cout << dp[w] << '\n';
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
bool c[5][5];
int main(void){
    // Your code here!
    for (ll i = 0; i < 3; i++){
        ll a, b;
        cin >> a >> b;
        c[a][b] = true;
        c[b][a] = true;
    }
    for (ll i = 1; i <= 4; i++){
        for (ll j = 1; j <= 4; j++){
            if (i == j) continue;
            for (ll k = 1; k <= 4; k++){
                if (i == k || j == k) continue;
                for (ll l = 1; l <= 4; l++){
                    if (i == l || j == l || k == l) continue;
                    if (c[i][j] && c[j][k] && c[k][l]){
                        cout << "YES" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		double p[] = new double[n + 1];
		double q[] = new double[n + 1];
		
		String tmpArray[] = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			p[i + 1] = Double.parseDouble(tmpArray[i]);
		}
		
		tmpArray = br.readLine().split(" ");
		for(int i = 0; i < n + 1; i++){
			q[i] = Double.parseDouble(tmpArray[i]);
		}
		
		double e[][] = new double[n + 2][n + 1];
		int root[][] =  new int[n + 1][n + 1];
		
		optimalBST(p, q, e, root);
		
		System.out.printf("%.5f\n",e[1][n]);
	}
	
	static void optimalBST(double p[], double q[], double e[][], int root[][]){
		int n = p.length - 1;
		
		double[][] w = new double[n + 2][n + 1];

		for(int i = 1; i <= n + 1; i++){
			e[i][i - 1] = q[i - 1];
			w[i][i - 1] = q[i - 1];
		}
		
		for(int l = 1; l <= n; l++){
			for(int i = 1; i <= n - l + 1; i++){
				int j = i + l - 1;
				e[i][j] = Double.MAX_VALUE;
				
				w[i][j] = w[i][j - 1] + p[j] + q[j];
				
				for(int r = i; r <= j; r++){
					double t = e[i][r - 1] + e[r + 1][j] + w[i][j];
					
					if(t < e[i][j]){
						e[i][j] = t;
						root[i][j] = r;
					}
				}
			}
		}
	}

}



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

const int MAX = 100005;
const int NIL = -1;

struct node {
	int p, l, r;
};

node T[MAX];
int n, D[MAX];

void print(int u)
{
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";
	
	if (T[u].p == NIL)cout << "root, ";
	else if (T[u].l == NIL) cout << "leaf, ";
	else cout << "internal node, ";

	cout << "[";
	
	for (int i = 0, c = T[u].l; c != NIL; ++i, c = T[c].r){
		if (i)cout << ", ";
		cout << c;
	}
	cout << "]" << endl;
}

int rec(int u, int p)
{
	D[u] = p;
	if (T[u].r != NIL)rec(T[u].r, p);
	if (T[u].l != NIL)rec(T[u].l, p + 1);
}

int main()
{
	int d, v, c, l, r;
	cin >> n;
	for (int i = 0; i < n; ++i)T[i].p = T[i].l = T[i].r = NIL;
	for (int i = 0; i < n; ++i)
	{
		cin >> v >> d;
		for (int j = 0; j < d; ++j)
		{
			cin >> c;
			if (j == 0)T[v].l = c;
			else T[l].r = c;
			l = c;
			T[c].p = v;
		}
	}
	for (int i = 0; i < n; ++i)
	{
		if (T[i].p == NIL)r = i;
	}
	rec(r, 0);
	for (int i = 0; i < n; ++i)print(i);
	return 0;
}


Measured memory_bytes: 7788
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

const i64 MOD = 1e9 + 7;

i64 modinv(i64 a, i64 m)
{
  i64 b = m, u = 1, v = 0;
  while (b)
  {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main()
{
  i64 n, k;
  cin >> n >> k;
  vector<i64> a(n);
  for (i64 i = 0; i < n; i++)
    cin >> a[i];
  vector<i64> cnt(2 * n);
  for (i64 i = 0; i < 2 * n; i++)
    for (i64 j = 0; j < i; j++)
      if (a[i % n] < a[j % n])
        cnt[i]++;
  i64 ans = 0;
  for (i64 i = 0; i < n; i++)
  {
    i64 tmp = k * (2 * cnt[i] + ((k - 1) * (cnt[i + n] - cnt[i]) % MOD)) % MOD;
    ans += tmp * modinv(2, MOD) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    
    int h,w,a,b;
    cin >> h >> w >> a >>b;

    rep(i,0,h){
	rep(j,0,w){
	    if(i < b){
		if(j < a)cout << 1;
		else cout << 0;
	    }else{
		if(j < a)cout << 0;
		else cout << 1;
	    }
	}
	cout << endl;
    }
    
    return  0;
}


Measured memory_bytes: 1280
words = {}
gets.to_i.times do
    s = gets.chomp
    !words[s] ? words[s] = 1 : words[s] += 1 
end
gets.to_i.times do
    t = gets.chomp
    !words[t] ? words[t] = -1 : words[t] -= 1 
end

ans = words.sort_by{ |_,v| -v }
p [ans[0][1], 0].max

Measured memory_bytes: 2044
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);
  int copy;
  copy = n;
  int i;
  int k=0;
  while(n!=0)
  {
    k+=n%10;
    n=n/10;
  }
  if(copy%k==0) printf("Yes");
  else printf("No");
  
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vl x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    ll l, q;
    cin >> l >> q;
    vl a(q), b(q);
    for (int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    vvl dbl(n, vl(20, n - 1));
    int nxt = 0;
    for (int i = 0; i < n; ++i) {
        while (x[nxt] - x[i] <= l && nxt < n) {
            nxt++;
        }
        nxt--;
        dbl[i][0] = nxt;
    }
    for (int i = 1; i <= 17; ++i) {
        for (int j = 0; j < n; ++j) {
            dbl[j][i] = dbl[dbl[j][i - 1]][i - 1];
        }
    }
    auto check = [&](int mid, int i) {
        int l = min(a[i], b[i]);
        int r = max(a[i], b[i]);
        for (int j = 17; j >= 0; --j) {
            if (mid & 1 << j)
                l = dbl[l][j];
        }
        return r <= l;
    };
    for (int i = 0; i < q; ++i) {
        int ok = n;
        int ng = 0;
        while (ng + 1 != ok) {
            int mid = (ok + ng) / 2;
            if (check(mid, i))
                ok = mid;
            else
                ng = mid;
        }
        cout << ok << "\n";
    }
    return 0;
}

Measured memory_bytes: 22784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int>g[100005];
 int d[100005],ans[100005]={0},vis[100005]={0};
void bfs(int u){
    queue<int>q;
    q.push(u);
    while(!q.empty()){
        int a=q.front();
        q.pop();
        for(int b:g[a]){
            if(!vis[b]) {
                if(d[b]>d[a]+1){
                    d[b]=d[a]+1;
                    ans[b]=a;
                }
                vis[b]=1;
                q.push(b);
            }
        }
    }
}

main(){
    int n,m;
    cin>>n>>m;
    fill(d,d+n+1,10000000);
    while(m--){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    d[1]={0};
    bfs(1);
    for(int i=2;i<=n;i++){
        if(ans[i]==0) {puts("No");
        exit(0);
        }
    }
    puts("Yes");
    for(int i=2;i<=n;i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 11224
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a==b && c==d){
    cout<<"yes"<<endl;
  }
  else if(a==c && b==d){
    cout<<"yes"<<endl;
  }
  else if(a==d && b==c){
    cout<<"yes"<<endl;
  }
  else {cout<<"no"<<endl;}
  return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    if((A+11)%13 > (B+11)%13) cout << "Alice" << endl;
    else if(A==B) cout << "Draw" << endl;
    else cout << "Bob" << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct edge { int to; int n; };
vector<vector<edge>> adj;
vector<bool> used;

bool dfs(int from, int to, int par = -1) {
  if (from==to) return true;
  for (auto x: adj[from]) {
    if (x.to==par||!used[x.n]) continue;
    if (dfs(x.to,to,from)) return true;
  }
  return false;
}

int main() {
  int N; cin >> N;
  int a[N]; rep(i,N) cin >> a[i];
  int b[N]; rep(i,N) cin >> b[i];



  adj.resize(51); used.resize(51,true);
  repr(i,1,51) repr(j,1,i+1) adj[i].push_back({i%j,j});

  rep(i,N) if (!dfs(a[i],b[i])) { cout << -1 << endl; return 0; }
  per(i,51) {
    bool ok = true;
    used[i+1] = false;
    rep(i,N) ok &= dfs(a[i],b[i]);
    if (!ok) used[i+1] = true;
  }
  // debug(all(used));

  ll result = 0;
  repr(i,1,52) if (used[i]) result += 1ull<<i;
  cout << result << endl;
  return 0;
}

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

int main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int c=0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
        c++;
    }
    cout<<c;
    return 0;
}

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

int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k; 
  vector<int>vec;
  vec = {a,b,c,d,e};
  sort(vec.begin(), vec.end());
  if (vec.at(4)-vec.at(0) > k){
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 1005
int n,m,tim,vis[N],f[N][N][2],u[N*N],v[N*N];
struct st{int to,id;};
vector<st>g[N];
void dfs(int x,int p,int b,int k)
{
	vis[x]=tim;f[p][x][k]=b;
	for(int i=0;i<g[x].size();i++)if(vis[g[x][i].to]!=tim)dfs(g[x][i].to,p,b,k);
}
void sol(int x)
{
	tim++;vis[x]=tim;
	for(int i=0;i<g[x].size();i++)if(vis[g[x][i].to]!=tim)dfs(g[x][i].to,x,g[x][i].id,0);
	reverse(g[x].begin(),g[x].end());
	tim++;vis[x]=tim;
	for(int i=0;i<g[x].size();i++)if(vis[g[x][i].to]!=tim)dfs(g[x][i].to,x,g[x][i].id,1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){scanf("%d%d",&u[i],&v[i]);g[u[i]].push_back((st){v[i],i});}
	for(int i=1;i<=n;i++)sol(i);
	for(int i=1;i<=m;i++)if((f[v[i]][u[i]][0]!=0)^(f[u[i]][v[i]][0]!=i||f[u[i]][v[i]][1]!=i))puts("diff");else puts("same");
	return 0;
}

Measured memory_bytes: 18688
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

template <typename T>
struct WeightedUnionFind {
	LL n;
	T d;
	vector<LL> r, p;
	vector<T> ws;
	WeightedUnionFind() {}
	WeightedUnionFind(LL sz, T d_) :
		n(sz), d(d_), r(n, 1), p(n), ws(n, d) {
		iota(p.begin(), p.end(), 0);
	}
	LL find(LL x) {
		if (x == p[x]) {
			return x;
		}
		else {
			LL t = find(p[x]);
			ws[x] += ws[p[x]];
			return p[x] = t;
		}
	}
	T weight(LL x) {
		find(x);
		return ws[x];
	}
	bool same(LL x, LL y) {
		return find(x) == find(y);
	}
	void unite(LL x, LL y, T w) {
		w += weight(x);
		w -= weight(y);
		x = find(x); y = find(y);
		if (x == y) return;
		if (r[x]<r[y]) swap(x, y), w = -w;
		r[x] += r[y];
		p[y] = x;
		ws[y] = w;
	}
	T diff(LL x, LL y) {
		return weight(y) - weight(x);
	}
};

int main() {
	LL n, m;
	cin >> n >> m;
	WeightedUnionFind<LL> wuf(n + 1, 0);
	for (LL i = 0; i<m; i++) {
		LL l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		if (wuf.same(l, r)) {
			if (wuf.diff(l, r) != d) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			wuf.unite(l, r, d);
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(i%2 == 0 && a%2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
n=int(input())
p=[0]*n
for i in range(n):
    p[i]=int(input())

a=[0]*n
cnt=1
ans=0
for i in range(n):
    a[p[i]-1]=i
#print('n,p=',n,p,a)
for i in range(n):
    if i==0:
        pre=a[0]
    else:
        if a[i]>pre:
            cnt+=1
        else:
            ans=max(ans,cnt)
            cnt=1
    ans=max(ans,cnt)
    pre=a[i]
print(n-ans)


Measured memory_bytes: 49880
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;
const ll mod=1000000007;
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
// ll a,b;cin>>a>>b;
 ll n;cin>>n;
 if(n>=30){
   py;
   return 0;
 }
 pn;
return 0;}

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

string s;
bool k0, km;

int main() {
    int n;
    cin >> n;
    getchar();
    cout << "0" << endl;
    fflush(stdout);

    getline(cin, s);
    if(s == "Vacant") return 0;
    k0 = (s == "Male" ? 1 : 0);

    int mid = (n-1) / 2;
    int l = 0, r = n;
    bool kl = k0, kr = k0;
    while(l <= r){
        cout << mid << endl;
        fflush(stdout);
        getline(cin, s);
        if(s == "Vacant") return 0;
        km = (s == "Male" ? 1 : 0);
        if((mid - l + 1 + (km == kl)) % 2 == 1){
            r = mid;
            kr = km;
        }
        else{
            l = mid;
            kl = km;
        }
        mid = (l + r) / 2;
    }
}

Measured memory_bytes: 852
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if a[i] > b[i]:
        ans += b[i]
    elif a[i] + a[i+1] < b[i]:
        ans += (a[i]+a[i+1])
        a[i+1] = 0
    else:
        ans += b[i]
        a[i+1] -= (b[i]-a[i])
print(ans)

Measured memory_bytes: 18624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

typedef long long ll;

int main(){

    int a[5];
    for (int i = 0; i < 5; i++)cin >> a[i];

    for (int i = 0; i < 5; i++) {
        if (a[i] == 0)cout << i + 1 << endl;
    }

    return 0;
}


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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 1e5 + 100;
const int maxN = 1e16;
const int oo = 1e18;
const int mod  = 998244353;

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    bool flag = 0;
    while(n > 0) {
        int x = n % 10;
        if(x == 7) flag = 1;
        n /= 10;
    }
    if(flag) cout << "Yes";
    else cout << "No";
}


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

int main()
{
	int n; cin >> n;
	
	vector<double> v(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	
	sort(v.begin(), v.end());
	
	double tmp;
	for (int i = 1; i < n; i++) {
		v[i] = (v[i - 1] + v[i]) / 2;
	}
	cout << fixed << setprecision(11) << v[n - 1] << endl;
	return 0;
}

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

bool compare(const pair<string,int> &a, const pair<string,int> &b){
  if(a.second!=b.second) return a.second < b.second;
  else return a.first < b.first;
}

int main(void){
  int n;
  while(cin>>n,n){
    vector<pair<string,int> > chr(n);
    vector<set<int> > data(31);
    for(int i=0;i<n;++i){
      cin>>chr[i].first;
      int m;cin>>m;
      for(int j=0,d;j<m;++j){
        cin>>d;data[d].insert(i);
      }
    }
    for(int i=0;i<=30;++i){
      set<int>::iterator it=data[i].begin();
      for(;it!=data[i].end();++it){
        chr[*it].second+=n-data[i].size()+1;
      }
    }
    sort(chr.begin(), chr.end(), compare);
    cout<<chr[0].second<<" "<<chr[0].first<<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
// header {{{
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    (26)
#define EPS         (1e-10)
#define INF         (1000000005LL)
#define MOD         (1000000007LL)
#define EQ(a, b)    (abs((a)-(b)) < EPS)
// ciling(x/y) = (x+y-1)/y

typedef long long ll;
typedef unsigned long long ull;
// }}}
// number {{{
#define SIZE 100005

// べき乗
// verified AOJ NTL_1_B
ll pow(ll a, ll b) {
    if(b == 0) return 1;
    ll aa = pow(a, b/2);
    return aa*aa%MOD*(b%2 == 1 ? a : 1)%MOD;
}

// 階乗と階乗の逆元
// ARC077D
ll fact[SIZE] = {1, 1};
ll finv[SIZE] = {1, 1};

void fact_init() {
    // fact
    for(ll i=2;i<SIZE;i++){
        fact[i] = fact[i-1]*i%MOD;
    }

    // finv
    finv[SIZE-1] = pow(fact[SIZE-1], MOD-2);
    for(ll i=SIZE-1;i>=3;i--){
        finv[i-1] = finv[i]*i%MOD;
    }
}

// 組み合わせの数
// ARC077D
ll comb(int n, int r) {
    if(r > n) return 0;
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD;
}

// 最小公約数
ll gcd(ll x, ll y) {
    return y ? gcd(y, x%y) : x;
}

// 素数判定 (エラトステネスのふるい)
bool isPrime[SIZE];
void initIsPrime() {
    for(int i=0;i<SIZE;i++){
        isPrime[i] = true;
    }
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i=2;i*i<=SIZE;i++){
        if(isPrime[i]){
            for(int j=i*i;j*j<=SIZE;j+=i){
                isPrime[j] = false;
            }
        }
    }
}

// 素因数分解
// verified AOJ NTL_1_A
vector<pair<int, int>> factor(int n) {
    vector<pair<int, int>> ret;
    for(int i=2;i*i<=n;i++){
        if(isPrime[i]){
            int count = 0;
            while(n%i == 0){
                count++;
                n /= i;
            }
            if(count > 0){
                ret.push_back({i, count});
            }
        }
    }
    if(n != 1){
        ret.push_back({n, 1});
    }
    return ret;
}
//}}}

int main() {
    ll n;cin >> n;
    vector<int> cnt(n+5, 0);
    for(int i=0;i<n;i++){
        int a;cin >> a;
        cnt[a]++;
    }
    for(int i=0;i<n;i++){
        if(cnt[i] == 0) continue;
        if(i == 0 && cnt[i] > 1){
            cout << 0 << endl;
            return 0;
        }
        if(i != 0 && cnt[i] != 2){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << pow(2LL, n/2LL) << endl;
    return 0;
}


Measured memory_bytes: 640
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 2e4 + 5, logx = 18;
int n;
long long a[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  return true;
}

long long p10;

vector< pair<long long, long long> > shift(const vector< pair<long long, long long> > &segs, long long sh) {
  vector< pair<long long, long long> > res;
  for (int i = 0; i < sz(segs); i++) {
    long long l = segs[i].first + sh, r = segs[i].second + sh;
    if (r <= p10) {
      res.push_back(make_pair(l, r));
    } else if (l >= p10) {
      l -= p10;
      r -= p10;
      res.push_back(make_pair(l, r));
    } else {
      res.push_back(make_pair(l, p10));
      res.push_back(make_pair(0, r - p10));
    }
  }
  sort(res.begin(), res.end());
  return res;
}

vector< pair<long long, long long> > mergeSegs(const vector< pair<long long, long long> > &a,
                                               const vector< pair<long long, long long> > &b) {
  vector< pair<long long, long long> > res;
  vector< pair<long long, int> > ev;
  for (int i = 0; i < sz(a); i++) {
    ev.push_back(make_pair(a[i].first, -1));
    ev.push_back(make_pair(a[i].second, 1));
  }
  for (int i = 0; i < sz(b); i++) {
    ev.push_back(make_pair(b[i].first, -1));
    ev.push_back(make_pair(b[i].second, 1));
  }
  sort(ev.begin(), ev.end());
  long long l = -1;
  int bal = 0;
  for (int i = 0; i < sz(ev); i++) {
    if (!bal) {
      l = ev[i].first;
    }
    bal -= ev[i].second;
    if (!bal) {
      res.push_back(make_pair(l, ev[i].first));
    }
  }
  return res;
}

void solve() {
  p10 = 1;
  for (int i = 0; i < logx; i++) {
    p10 *= 10;
  }
  int res = 0;
  for (int dig = logx; dig > 0; dig--) {
    for (int i = 0; i < n; i++) {
      a[i] %= p10;
    }
    long long len = p10 / 10;
    for (int x = 9; x >= 0; x--) {
      vector< pair<long long, long long> > segs;
      segs.push_back(make_pair(x * len, (x + 1) * len));
      for (int i = 0; i < n; i++) {
        auto segs0 = shift(segs, (p10 - a[i]) % p10);
        segs = mergeSegs(segs, segs0);
      }
      if (segs[0].first == 0) {
        res += x;
        break;
      }
    }
    p10 /= 10;
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define RG register
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define clear(x, y) memset(x, y, sizeof(x))
#define int long long

inline int read()
{
    int data = 0, w = 1; char ch = getchar();
    while(ch != '-' && (!isdigit(ch))) ch = getchar();
    if(ch == '-') w = -1, ch = getchar();
    while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
    return data * w;
}

const int maxn(2e5 + 10);
struct edge { int x, y, w; } e[maxn << 2];
inline int cmp(const edge &lhs, const edge &rhs) { return lhs.w < rhs.w; }
int dis[maxn], n, Q, e_num, fa[maxn], ans;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
template<typename T> inline void chkmin(T &x, const T &y) { if(y < x) x = y; }
inline void add_edge(int x, int y, int w) { e[++e_num] = (edge) {x, y, w}; }

signed main()
{
    n = read(), Q = read(); memset(dis, 0x3f, sizeof dis);
    for(RG int i = 1, a, b, c; i <= Q; i++)
        a = read(), b = read(), c = read(),
        add_edge(a, b, c), chkmin(dis[a], c + 1), chkmin(dis[b], c + 2);
    for(RG int i = 0; i < n; i++) chkmin(dis[i], dis[(i - 1 + n) % n] + 2);
    for(RG int i = 0; i < n; i++) chkmin(dis[i], dis[(i - 1 + n) % n] + 2);
    for(RG int i = 0; i < n; i++) add_edge(i, (i + 1) % n, dis[i]), fa[i] = i;
    std::sort(e + 1, e + e_num + 1, cmp);
    for(RG int i = 1; i <= e_num; i++)
    {
        if(find(e[i].x) == find(e[i].y)) continue;
        fa[find(e[i].x)] = find(e[i].y); ans += e[i].w;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 17664
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct in {
    int n; in() {} in(int n_) : n(n_){}
    template <class T> operator T() { T ret; cin >> ret; return ret; }
    template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jan 18 21:00:12 JST 2020
 **/

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

template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

const Int K = 50, INF = 1e18;
signed main() {
    Int n = in();
    vector<Int> a = in(n), b = in(n);
    REP(i, n) a[i]--, b[i]--;
    auto dp = make_vec<Int>(1 << n, 50, INF);
    dp[0][0] = 0;
    REP(S, 1 << n) {
        REP(i, n) {
            if (!(S >> i & 1)) continue;
            Int T = S ^ 1 << i;
            Int j = __builtin_popcount(T);
            Int nxt = (i - j) % 2 ? b[i] : a[i];
            Int acc = 0;
            REP(x, i + 1, n) acc += (T >> x & 1);
            if (S == 3) dump(i, T, acc);
            // dump(S, i, j, T, nxt);
            chmin(dp[S][nxt], dp[T][nxt] + acc);
        }
        REP(k, K) {
            if (k) chmin(dp[S][k], dp[S][k - 1]);
        }
    }
    dump(dp);
    Int all = (1 << n) - 1;
    cout << (dp[all][K - 1] == INF ? -1 : dp[all][K - 1]) << endl;
}


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

const int N=5005;
const int MOD=1e9+7;
int n,ans;
vector<int> nei[N],son[N];
int dp[N][N][2],f[N][2],sz[N],w[N];

void predfs(int x,int p){
	for(int i=0;i<nei[x].size();i++){
		int to=nei[x][i];
		if(to!=p){
			predfs(to,x);
			son[x].push_back(to);
		}
	}
}

void dfs(int x){
	for(int i=0;i<son[x].size();i++) dfs(son[x][i]);
	dp[x][1][0]=1;
	sz[x]=1;
	for(int i=0;i<son[x].size();i++){
		int to=son[x][i];
		memset(f,0,sizeof(f));
		for(int j=1;j<=sz[x];j++) for(int k=1;k<=sz[to];k++) for(int a=0;a<2;a++) for(int b=0;b<2;b++){
			f[j+k][a^b]=(f[j+k][a^b]+1ll*dp[x][j][a]*dp[to][k][b]%MOD)%MOD;
			f[j][a^b^1]=(f[j][a^b^1]+1ll*dp[x][j][a]*dp[to][k][b]%MOD*w[k]%MOD)%MOD;
		}
		sz[x]+=sz[to];
		for(int j=1;j<=sz[x];j++) for(int a=0;a<2;a++) dp[x][j][a]=f[j][a];
	}
//	printf("%d\n",x);
//	for(int i=1;i<=sz[x];i++) printf("%d %d\n",dp[x][i][0],dp[x][i][1]);
}

int main(){
	scanf("%d",&n);
	w[0]=1;
	for(int i=2;i<=n;i+=2) w[i]=1ll*(i-1)*w[i-2]%MOD;
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		nei[x].push_back(y);
		nei[y].push_back(x);
	}
	predfs(1,-1);
	dfs(1);
	for(int i=2;i<=n;i++) ans=((ans+1ll*w[i]*(dp[1][i][0]-dp[1][i][1])%MOD)%MOD+MOD)%MOD;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 93252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		long sum = 0;
		Scanner sc = new Scanner(System.in);
		int N= sc.nextInt();
		long A[] = new long[200000];
		for (int i=0;i<N;i++) {
			long temp = sc.nextLong();
			sum +=temp;
			A[(int)temp]++;
		}
		int Q= sc.nextInt();
		for (int i=0;i<Q;i++) {
			long b = sc.nextLong();
			long c = sc.nextLong();
			long count = A[(int)b];
			A[(int)c]+=A[(int)b];
			A[(int)b] = 0;
			sum = count*(c-b)+sum;
			System.out.println(sum);
		}
	}
}


Measured memory_bytes: 66036
import java.util.Scanner;

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

    private void solve() {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }
        int idx = n / 2, d;
        if (n % 2 == 0) {
            d = -1;
        } else {
                d = 1;
        }
        for (int i = 0; i < n; ++i) {
            b[idx] = a[i];
            idx += d;
            if (d < 0) {
                d = 1 - d;
            } else {
                d = -1 - d;
            }
        }
        for (int i = 0; i < n; ++i) {
            System.out.print(b[i] + " ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 97572
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    ll n; cin >> n;
    ll ans = n*(n+1)/2;
    for ( ll i = 3;i <=n;i+=3){
        ans-=i;
    }
    for(ll i = 5;i <=n;i+=5){
        ans-=i;
    }
    for(ll i = 15;i <=n;i+=15){
        ans+=i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
let input = readLine()!.split(separator: " ").map { Int($0)! }

let N = input[0]
let W = input[1]

var weights: [Int] = .init(repeating: 0, count: N)
var values: [Int] = .init(repeating: 0, count: N)

for i in 0..<N {
  let inp = readLine()!.split(separator: " ").map { Int($0)! }
  weights[i] = inp[0]
  values[i] = inp[1]
}

var dp: [[Int]] = .init(repeating: .init(repeating: 0, count: W + 1), count: N + 1)

for i in 1...N {
  for j in 1...W {
   	let prev = j - weights[i - 1]
    if prev < 0 {
      dp[i][j] = dp[i-1][j]
      continue
    }
    dp[i][j] = max(dp[i-1][prev] + values[i - 1], dp[i-1][j])
  }
}
print(dp[N][W])

Measured memory_bytes: 87116
#include <iostream>
using namespace std;
int main()
{
    int A,B,C,X;
    int res=0;
    cin>>A>>B>>C>>X;
    for(int i=0;i<=A;i++){
        for(int j=0;j<=B;j++){
            for(int k=0;k<=C;k++){
                if(i*500+j*100+k*50==X)res++;
            }
        }
    }
    cout<<res<<'\n';
    return 0;
}

Measured memory_bytes: 256
while True:
    table = list(input().split())
    if table[1] == "?":
        break
    
    a = int(table[0])
    b = int(table[2])
    op = table[1]
    
    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    else:
        print(a // b)  


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000+7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18
# define LN 20  
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 (ll)1e10
# define maxn 300005
# define offset 2000005
#define N 100005
const ld eps = 1e-10L;

/*void LPS()
{
	len = s.length();
    lps[0] = 0;
    for(ll i=1;i<len;i++){

        ll j = lps[i-1];
        while(j > 0 && s[j] != s[i])    j = lps[j-1];
        if(s[i] == s[j])    j++;
        lps[i] = j;
    }
}*/

/*************************************************
struct Coupon {
	ll l;
	ll r;
	ll id;

	Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization

	bool operator<(const Coupon& c) { // Sorting
		return l < c.l;    
	}
};

**************************************************/
int main()
{
	ll n;
	cin >> n;
	multiset<ll>s;
	map<ll,ll>m;
	ll a[n+1];
	map<ll,ll>ans1,m1;
	vector<pair<ll,ll> >v;
	vector<ll> v1;
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		cin >> a[i];
		s.insert(a[i]);
		v1.pb(a[i]);
		m[a[i]]++;
		m1[a[i]]++;
	}

	while(s.size()>0)
	{
		ll x=*(s.rbegin());
		s.erase(s.find(x));
		ll now=1;
		while(now<=x)
			now*=2;
		multiset<ll>::iterator it=s.find(now-x);
		if(it==s.end())
			continue;
		s.erase(it);
		ans++;
	}

	cout << ans;

}

Measured memory_bytes: 37744
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;


int main() {
	string s;
	cin >> s;
	int ans = 0;
	int k = 0, u = 0, p = 0, c = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'K')k++;
		if (s[i] == 'U')u++;
		if (s[i] == 'P')p++;
		if (s[i] == 'C')c++;
	}
	cout << min({ k,u,p,c }) << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;
int r = inf, c, m;

int main() {
	cin >> s;
	rep(i,26) {
		c = 0, m = 0;
		rep(j,s.length()) {
			if (s[j]!='a'+i) c++;
			else c = 0;
			chmax(m, c);
		}
		chmin(r, m);
	}
	cout << r << ln;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

#define INF (1e+9)
#define LLINF (1e+18)
#define LL long long


using namespace std;


int array[200000];

int main (void){
	//printf("%lld:::%lld",(LL)INF,(LL)LLINF);

	int n;
	int k;

	LL sum;
	LL maxNum;

	while(true){
		sum = 0;
		maxNum = -1*(LL)LLINF;
		scanf("%d",&n);
		scanf("%d",&k);
		if((n==0)||(k==0))break;
		for(int i=0;i<n;i++){
			scanf("%d",array+i);
		}
		for(int i=0;i<k;i++){
			sum += array[i];
		}
		maxNum = max(maxNum,sum);
		for(int i=0;i<n-k;i++){
			maxNum = max(maxNum,sum = (sum-array[i]+array[i+k]));
		}
		printf("%lld\n",maxNum);
	}

	return 0;
}

Measured memory_bytes: 1576
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
using namespace std;

int main(void){
    int h,w;
    cin >> h >> w;
    int grid[505][505];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> grid[i][j];
        }
    }

    int count=0;
    vector< pair<int,int> > move;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(j!=w-1 && grid[i][j]%2==1){
                move.push_back( make_pair(i+1,j+1) );
                move.push_back( make_pair(i+1,j+2) );
                grid[i][j]--;
                grid[i][j+1]++;
                count++;
            }else if(grid[i][j]%2==1 && i!=h-1){
                move.push_back( make_pair(i+1,j+1) );
                move.push_back( make_pair(i+2,j+1) );
                grid[i][j]--;
                grid[i+1][j]++;
                count++;
            }
        }
    }
    cout << count << endl;
    for(int i=0; i<move.size(); i+=2){
        cout << move[i].first << " " << move[i].second << " ";
        cout << move[i+1].first << " " << move[i+1].second << endl;
    }
    return 0;
}

Measured memory_bytes: 5232
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; i++)
#define repR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    int n, res;
    cin >> n;
    rep(i,10){
        int zoro = i*100 + i*10 + i;
        if(zoro - 111 < n && n <= zoro){
            res = zoro;
            break;
        }
    }
    cout << res << endl;
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int N,M;
vector<vector<int>> G(100010);
vector<bool> seen(100010);
vector<int> order;
void rec(int v,vector<vector<int>> &G,vector<bool> &seen,vector<int> &order){
    seen[v]=true;
    for (auto nv:G[v]){
        if (seen[nv]){
            continue;
        }
        rec(nv,G,seen,order);
    }
    order.push_back(v);
}

vector<int> TopologicalSort(int V,vector<bool> &seen,vector<int> &order){
    rep(i,V){
        if (seen[i]){
            continue;
        }
        rec(i,G,seen,order);
    }
    reverse(order.begin(),order.end());
    return order;
}

int main(){
    cin >> N >> M;
    rep(i,M){
        int x,y;
        cin >> x >> y;
        x--,y--;
        G[x].push_back(y);
    }
    TopologicalSort(N,seen,order);
    vector<int> dp(N,0);
    rep(i,N){
        for (auto nv:G[order[i]]){
            chmax(dp[nv],dp[order[i]]+1);
        }
    }
    int ans=0;
    rep(i,N){
        chmax(ans,dp[i]);
    }
    cout << ans << endl;
}

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

int main() {
  int h, w;
  cin>>h>>w;
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];

  int color[h][w];
  int a_idx = 0;
  int i = 0;
  int j = 0;
  while (a_idx < n) {
    while (a[a_idx] > 0) {
      color[i][j] = a_idx + 1;
      if (i % 2 == 0) {
        ++j;
        if (j == w) {
          ++i;
          --j;
        }
      } else {
        --j;
        if (j == -1) {
          ++i;
          ++j;
        }
      }
      --a[a_idx];
    }
    ++a_idx;
  }
  for (int i=0; i<h; i++) {
    cout<<color[i][0];
    for (int j=1; j<w; j++) {
      cout<<" "<<color[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 384