akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long


using namespace std;
vector<vector<pair<int,int> > >adj;
pair<int,int> dis[305][305];
int n,m,l;
void dikstra(int ver)
{
    priority_queue<pair<pair<int,int> ,int>,vector<pair<pair<int,int> ,int>>,greater<pair<pair<int,int> ,int>> >qu;
    qu.push({{0,-l},ver});
    dis[ver][ver]={0,-l};
    int vis[305]={0};
    while (!qu.empty())
    {
        pair<pair<int,int> ,int>p=qu.top();
        qu.pop();
        if(vis[p.second])
            continue;
        vis[p.second]=1;
        for(auto i:adj[p.second])
        {
            if(!vis[i.first])
            {
                if(-dis[ver][p.second].second<i.second)
                {
                    if(dis[ver][i.first].first>1+dis[ver][p.second].first)
                    {
                        dis[ver][i.first].first=1+dis[ver][p.second].first;
                        dis[ver][i.first].second=-(l-i.second);
                        qu.push({dis[ver][i.first],i.first});
                    }
                    else if(dis[ver][i.first].first==1+dis[ver][p.second].first)
                    {
                        if(-dis[ver][i.first].second<(l-i.second))
                        {
                            dis[ver][i.first].second=-(l-i.second);
                            qu.push({dis[ver][i.first],i.first});
                        }
                    }
                }
                else
                {
                    if(dis[ver][i.first].first>dis[ver][p.second].first)
                    {
                        dis[ver][i.first].first=dis[ver][p.second].first;
                        dis[ver][i.first].second=-(-dis[ver][p.second].second-i.second);
                        qu.push({dis[ver][i.first],i.first});
                    }
                    else if(dis[ver][i.first].first==dis[ver][p.second].first)
                    {
                        if(-dis[ver][i.first].second<(-dis[ver][p.second].second-i.second))
                        {
                            dis[ver][i.first].second=-(-dis[ver][p.second].second-i.second);
                            qu.push({dis[ver][i.first],i.first});
                        }
                    }
                }
            }
        }
    }

}

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

    cin>>n>>m>>l;

    adj.resize(n+1);
    int x,y,z;
    for (int i = 0; i < m; ++i) {
        cin>>x>>y>>z;
        if(z>l)
            continue;
        adj[x].push_back({y,z});
        adj[y].push_back({x,z});
    }

    int zz=1e17;

    fill_n(&dis[0][0],305*305,make_pair(zz,-l));

    for (int i = 1; i <=n ; ++i) {
        dikstra(i);
    }

    int q;
    cin>>q;

    while (q--)
    {
        cin>>x>>y;
        if(dis[x][y].first>=zz)
            cout<<-1<<"\n";
        else
            cout<<dis[x][y].first<<"\n";
    }

}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main(){
    int space[4][3][10];
    int i,j,k;
    int n;
    int b,f,r,v;
    
    for(i = 0;i < 4;i++){
        for(j = 0;j < 3;j++){
            for(k = 0;k < 10;k++){
                space[i][j][k] = 0;
            }
        }
    }
    
    cin >> n;
    
    for(i = 0;i < n;i++){
        cin >> b >> f >> r >> v;
        space[b - 1][f - 1][r - 1] = space[b - 1][f - 1][r - 1] + v;
    }
    
    for(i = 0;i < 4;i++){
        for(j = 0;j < 3;j++){
            for(k = 0;k < 10;k++){
                cout << ' ' << space[i][j][k];
            }
            cout << endl;
        }
        
        if(i != 3){
            for(j = 0;j < 20;j++){
                cout << '#';
            }
            cout << endl;
            
        }
    }
    
    return 0;
}


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

using namespace std;

typedef long long ll;

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

#define per(i, n) for (int i = n ; i >= 0 ; --i)

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

  double D, T, S;
  cin >> D >> T >> S;

  cout << ((D / S <= T) ? "Yes" : "No") << '\n';

  return 0;
}

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

using namespace std;

int n, chek;

int main()
{
	cin >> n;
	string s, t;
	cin >> s >> t;
	for(int i = 0; i < n; i++) {
		if(s[i] == t[0]) {
			for(int j = i + 1; j < n; j++) {
				if(s[j] != t[j - i]) {
					chek = 1;
					break;
				}
			}
			if(chek == 1) {
				chek = 0;
			}
			else{
				cout << n + i;
				return 0;
			}
		}
	}
	cout << 2 * n;
	return 0;
}


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

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

int main() {
    int h,w;cin>>h>>w;
    string s;
    rep(i,h){
        cin>>s;
        cout<<s<<endl;
        cout<<s<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
priority_queue<int>q1;
priority_queue<int,vector<int>,greater<int> >q2;
int q,opt,x,y;
ll sum1,sum2,sum;
int main()
{
    scanf("%d",&q);
    while(q--)
    {
        scanf("%d",&opt);
        if(opt==1)
        {
            scanf("%d%d",&x,&y);
            sum+=y;
            if(q1.empty()||x<q1.top())
                q1.push(x),sum1+=x;
            else q2.push(x),sum2+=x;
            if(q1.size()>q2.size()+1)
            {
                int t=q1.top();q1.pop();
                sum1-=t;sum2+=t;
                q2.push(t);
            }
            if(q2.size()>q1.size())
            {
                int t=q2.top();q2.pop();
                sum2-=t;sum1+=t;
                q1.push(t);
            }
        }
        else
            printf("%d %lld\n",q1.top(),sum-sum1+sum2+q1.top()*q1.size()-q1.top()*q2.size());
    }
}


Measured memory_bytes: 3452
import math
p=math.pi
A,B,H,M=map(int,input().split())
h=[A*math.cos(p*(H/6+M/360)),A*math.sin(p*(H/6+M/360))]
m=[B*math.cos(p*M/30),B*math.sin(p*M/30)]
L=math.sqrt(math.pow(h[0]-m[0],2)+math.pow(h[1]-m[1],2))
print(L)

Measured memory_bytes: 9504
num = 0
n,l = map(int, input().split())
if l <= 0 < l+n-1:
    for i in range(1,n+1):
        num += (l+i-1)
elif l > 0:
    for i in range(2,n+1):
        num += (l+i-1)
else:
    for i in range(1,n):
        num += (l+i-1)
print(num)

Measured memory_bytes: 9108
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int c[10];
  rep(i, 0, 9) scanf("%d", &c[i]);

  int ok = 1;
  rep(j, 1, 3) {
    rep(i, 0, 2) {
      if (c[i+j*3] - c[i] == c[i+j*3+1] - c[i+1]) continue;
      ok = 0;
    }
  }
  printf(ok ? "Yes\n" : "No\n");
  return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n;
    cin >> n;
    vector<vector<int>> graph(n);
    rep(i,0,n-1){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }


    int k;
    cin >> k;
    vector<int> p(n,-1);
    rep(i,0,k){
        int v;
        cin >> v;
        --v;
        cin >> p[v];
    }

    vector<bool> used(n);
    vector<int> lb(n,-inf),ub(n,inf);
    int r;
    function<bool(int,int)> rec=[&](int u,int d){
        used[u]=true;
        if(p[u]!=-1) lb[u]=ub[u]=p[u];
        for(int v:graph[u]){
            if(used[v]){
                if(p[u]!=-1 and abs(p[u]-p[r])%2!=d%2) return false;
                continue;
            }
            if(!rec(v,d+1)) return false;
            if(ub[v]+1<lb[u] or ub[u]<lb[v]-1) return false;
            lb[u]=max(lb[u],lb[v]-1);
            ub[u]=min(ub[u],ub[v]+1);
        }
        if(lb[u]>ub[u]) return false;
        return true;
    };
    rep(i,0,n){
        if(p[i]!=-1){
            r=i;
            if(!rec(i,0)){
                cout << "No" << endl;
                return;
            }
            break;
        }
    }

    vector<int> ans(n);
    function<void(int,int)> write=[&](int u,int parent){
        if(p[u]!=-1) ans[u]=p[u];
        else{
            if(lb[u]<=ans[parent]-1 and ans[parent]-1<=ub[u]) ans[u]=ans[parent]-1;
            if(lb[u]<=ans[parent]+1 and ans[parent]+1<=ub[u]) ans[u]=ans[parent]+1;
        }
        for(int v:graph[u]){
            if(v==parent) continue;
            write(v,u);
        }
    };
    rep(i,0,n){
        if(p[i]!=-1){
            write(i,-1);
            break;
        }
    }
    cout << "Yes" << endl;
    rep(i,0,n) cout << ans[i] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

int main()
{
    int D;
    cin >>D;
    if(D==25){
        cout<<"Christmas"<<endl;
    }
    else if(D==24){
        cout<<"Christmas Eve"<<endl;
    }
    else if(D==23){
           cout<<"Christmas Eve Eve"<<endl;
       }
    else if(D==22){
              cout<<"Christmas Eve Eve Eve"<<endl;
          }

    
    return 0;
}


Measured memory_bytes: 256
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    i64 d, t, s;
    cin >> d >> t >> s;
    cout << (t * s >= d ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
int main() {
  int x,y;
  cin >> x >> y;
  bool ans = false;
  if(y%2 == 0 && y/2-x >=0 && 2*x - y/2 >= 0) ans = true;
  puts(ans ? "Yes":"No");
  }


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


int main(void){
    // Your code here!
    int n,k;
    
    
    cin>>n>>k;
    vector<int> d(k);
    vector<int> A(n);
    int s;
    for(int i=0;i<k;i++){
      cin>>d[i];
      for(int j=0;j<d[i];j++){
        cin>>s;
        A[s-1]++;
      }
    }
    
    int ct=0;
    for(int i=0;i<n;i++){
      if(A[i]==0) ct++;
    }
    
    cout<<ct<<endl;
    
    
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll factorial[2000000]; 
ll mod = 1e9 + 7; 

ll binaryExp(ll a, ll b){
	ll result =1;
	while(b){
		if(b%2){
			result = (result*a)%mod;
		}
		a = (a*a)%mod;
		b/=2;
	}
	return result;
}

ll ncr1(ll n, ll r){
	if(n<r) return 0;
	ll result = (factorial[n]*binaryExp((factorial[n-r]*factorial[r])%mod,mod-2))%mod;
	return result;
}

int main(){
  ios_base::sync_with_stdio(false);
	factorial[0]=1;
	for(int i=1;i<1000002;++i){
		factorial[i]=(i*factorial[i-1])%mod;
	}
	ll n;
	cin>>n;
	ll result =0;
	for(int i=2;i<=n;++i){
		result = (result + (ncr1(n,i)*(binaryExp(2,i)-2+mod))%mod*binaryExp(8,n-i))%mod;
	}
	cout<<result;
}


Measured memory_bytes: 11448
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) R a[i];
  double sum=0,ans=0;
  rep(i,n) {
    if(i-m>=0) sum-=(double)(a[i-m]+1)/2;
    sum+=(double)(a[i]+1)/2;
    if(i>=m-1) ans=max(ans,sum);
  }
  pd(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = II()
    v = LI()
    d1 = defaultdict(int)
    d0 = defaultdict(int)
    for num, a in enumerate(v):
        if num % 2:
            d1[a] += 1
        else:
            d0[a] += 1
    A = list(d0.items())
    A.sort(key = lambda x: x[1], reverse = True)
    A = A[:2]
    A.append((0,0))
    B = list(d1.items())
    B.sort(key = lambda x: x[1], reverse = True)
    B = B[:2]
    B.append((0, 0))
    a = n // 2
    b = (n + 1) // 2
    if A[0][0] == B[0][0]:
        ans = min(a - A[0][1] + b - B[1][1], a - A[1][1] + b - B[0][1])
        print(ans)
    else:
        #print(A,B)
        A = A[0][1]
        B = B[0][1]
        print(a+b-A-B)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 19936
#include <map>
#include <cstdio>
using namespace std;

const int MAXN = 2e5 + 5;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
_T MAX( const _T a, const _T b )
{
	return a > b ? a : b;
}

struct edge
{
	int to, nxt;
}Graph[MAXN << 1];

map<int, int> q[MAXN];

int mx[MAXN], c[MAXN];
int head[MAXN];
int N, cnt;

void addEdge( const int from, const int to )
{
	Graph[++ cnt].to = to, Graph[cnt].nxt = head[from];
	head[from] = cnt;
}

int Q( const int u, const int fa, const int val )
{
	if( q[u][val] ) return q[u][val];
	q[u][val] = 1;
	for( int i = head[u], v ; i ; i = Graph[i].nxt )
		if( ( v = Graph[i].to ) ^ fa && v < val )
			q[u][val] += Q( v, u, val );
	return q[u][val];
}

void DFS( const int u, const int fa )
{
	mx[u] = MAX( u, mx[fa] );
	for( int i = head[u], v ; i ; i = Graph[i].nxt )
		if( ( v = Graph[i].to ) ^ fa )
		{
			if( mx[u] == u )
			{
				c[v] = c[u] + Q( v, u, mx[u] );
				if( v < mx[fa] ) c[v] -= Q( v, u, mx[fa] );
			}
			else
			{
				if( v < mx[u] ) c[v] = c[u];
				else c[v] = c[u] + Q( v, u, mx[u] );
			}
			DFS( v, u );
		}
}

int main()
{
	read( N );
	for( int i = 1, a, b ; i < N ; i ++ )
		read( a ), read( b ), addEdge( a, b ), addEdge( b, a );
	DFS( 1, 0 );
	for( int i = 2 ; i <= N ; i ++ ) write( c[i] ), putchar( i == N ? '\n' : ' ' );
	return 0;
}

Measured memory_bytes: 52108
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;

// n! を素数 p で何回割れるか
ll fact_divp(ll n, ll p) {
  if (n<p) return 0;

  return n/p + fact_divp(n/p, p);
}

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


  ll N; cin>>N;
  
  if (N%2 == 1) { 
    // f(N) = N*(N-2)*(N-4)*...5*3*1 : 2 が出ないので 10 も出ない
    cout << 0 << endl;
    return 0;
  }

  assert(N%2 == 0);
  ll ans = 0;
  ll cnt2 = fact_divp(N/2, 2) + N/2;
  ll cnt5 = fact_divp(N/2, 5);
  ans = min(cnt2, cnt5);

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}


//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  ll a[n];
  for(int i = 0; i < n; i++){
    cin>>a[i];
  }
  ll ans = a[0];
  for(int i = 1; i < n; i++){
    ans = lcm(ans,a[i]);
    
  }
  cout<<ans<<endl;
  return 0;
}




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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n),cnt(100001),cou(100001);
  for(int i=0;i<n;i++){
    cin >> vec[i];
  }
  int ans=n;
  int i=0;
  while(i<n){
    cnt[vec[i]]++;
    i=i+2;
  }
  i=1;
  while(i<n){
    cou[vec[i]]++;
    i=i+2;
  }
  int max_cnt=1,max_cou=1,s,t;
  for(int i=0;i<100001;i++){
    max_cnt=max(max_cnt,cnt[i]);
    if(max_cnt==cnt[i]){
      s=i;
    }
    max_cou=max(max_cou,cou[i]);
    if(max_cou==cou[i]){
      t=i;
    }
  }
  if(s!=t){
    cout << n-max_cnt-max_cou << endl;
  }
  else{
    int sec_cnt=0,sec_cou=0,j=0;
    i=0;
    while(i<100001){
      if(s!=i){
        sec_cnt=max(sec_cnt,cnt[i]);
        i++;
      }
      else
        i++;
    }
    while(j<100001){
      if(t!=j){
        sec_cou=max(sec_cou,cou[j]);
        j++;
      }
      else
        j++;
    }
    cout << min(n-(max_cnt+sec_cou),n-(max_cou+sec_cnt)) << endl;
  }
}

Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    int N; cin >> N;
    int cnt = 0;
    for(int i = 1; i <= N; i++){
        int x; cin >> x;
        cnt += i&1 && x&1;
    }
    cout << cnt << '\n';
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

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

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

    int sl = s.length();
    int tl = t.length();

    
    if (sl < tl) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    int i_ans = -1;

    for (int i = 0; i <= sl - tl; i++) {
        for (int j = 0; j < tl; j++) {
            if (s[i+j] == '?' || s[i+j] == t[j]) {
                if (j == tl - 1) i_ans = i;
            } else if (s[i+j] != t[j]) {
                break;
            }
        }
        // if (i_ans != -1) break;
    }
    if (i_ans == -1) {
        cout << "UNRESTORABLE" << endl;
    } else {
        for (int i = 0; i < sl; i++) {
            if (s[i] == '?') s[i] = 'a';
        }

        cout << s.substr(0, i_ans) + t + s.substr(i_ans + tl, sl - tl - i_ans) << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#### ARC097D - Equals
#https://atcoder.jp/contests/arc097/tasks/arc097_b
# 参考URL
# https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
 
N, M = map(int, input().split())
p = list(map(int, input().split()))
 
uf = UnionFind(N)
for _ in range(M):
    x, y = map(int, input().split())
    uf.union(x-1, y-1)
 
ans = 0

for i in range(N):
    if i == p[i]-1 or uf.same(i, p[i]-1):
        ans+=1
        
print(ans)

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

const int N = 15;
int states[N][N];

bool check(int n, int flg) {
  rep(i, n) {
    if(!(flg & (1<<i))) {
      // i番目の人が真偽不明の場合は無視する
      continue;
    }
    rep(j, n) {
      int y = states[i][j];
      if(y == -1 && (flg & (1<<j))) {
        // i番目の人の主張が真偽不明かつj番目の人が正直者だと矛盾
        return false;
      }
      if(y == 1 && !(flg & (1<<j))) {
        // i番目の人の主張が正直者かつj番目の人が真偽不明だと矛盾
        return false;
      }
    }
  }
  return true;
}

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

  rep(i, n) {
    int a;
    cin >> a;
    rep(j, a) {
      int x, y;
      cin >> x >> y;
      x -= 1; // 0スタートなので

      // 配列の初期化のために、正直者を1, 真偽不明を-1とする
      // 0は何も言及されていない
      int _y = 0;
      if(y == 1) {
        _y = 1;
      }
      else {
        _y = -1;
      }
      states[i][x] = _y;
    }
  }

  int max_size = 0;
  for(int bit = 0; bit < (1<<n); ++bit) {
    int current_size = 0;
    for (int i = 0; i < n; i++) {
      if(bit & (1<<i)) {
        current_size++;
      }
    }
    if(check(n, bit)) {
      max_size = max(max_size, current_size);
    }
  }

  cout << max_size << endl;
  return 0;
}


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

typedef vector<int> veci;
typedef pair<int,int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9+7)
#define fi first
#define se second
#define endl '\n'

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST    
    int tcs;
    cin >> tcs;
    while (tcs-->0)
#endif        
{
    int n;
    cin >> n;

    vector<veci> dp(3,veci(n+1,0));
    for (int i=1; i<3; ++i) {
        for (int j=1; j<n+1; ++j) {
            cin >> dp[i][j];
        }
    }

    for (int i=1; i<3; ++i) {
        for (int j=1; j<n+1; ++j) {
            dp[i][j] += max(dp[i][j-1],dp[i-1][j]);
        }
    }

    cout << dp[2][n] << endl;
}}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  while(true){
  int n;
  cin >> n;
  if(n==0){
    break;
  }
  int player[2][n];
  for(int i=0;i<n;i++){
    cin >> player[0][i];
  }

  for(int j=0;j<n+1;j++){
    for(int i=0;i<n-1;i++){
      if(player[0][i]>player[0][i+1]){
	int c;
	c=player[0][i];
	player[0][i]=player[0][i+1];
	player[0][i+1]=c;
      }
    }
  }
    int count=0;
    int hanako=0;
    for(int i=1;i<=n*2;i++){

      if(player[0][count]==i){
	
	count++;

      }
      else{
	player[1][hanako]=i;
	hanako++;
      }
    }
    int field=0;
    int fieldO=-1;
    int point[2];
    point[0]=n; 
    point[1]=n;
    while((point[0]!=0 && point[1]!=0)){
      for(int i=0;i<2;i++){
	for(int j=0;j<n;j++){
	  if(player[i][j]>field){

	    field=player[i][j];
	    player[i][j]=-1;
	    point[i]--;
	    fieldO=i;
	    break;
	  }
	 
	}
	if(fieldO==i*-1+1){
	  fieldO=i+10;
	  field=0;
	}
	if((point[0]==0 || point[1]==0)){
	  break;
	}
      

      }
    }
    cout << point[1] << endl;
    cout << point[0] << endl;
  }
}

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

typedef long long ll;
const int maxn=1e5+10;
int n,s,x[maxn];
ll p[maxn],ans;
deque<int> q;
stack<int> stk;

int main(){
	cin>>n>>s;
	for(int i=1;i<=n;++i)
		cin>>x[i]>>p[i];
	for(int i=1;i<=n;++i)
		q.push_back(i);
	while(true){
		if(x[q.front()]>s){
			while(!q.empty()){
				stk.push(q.back());
				q.pop_back();
			}
			break;
		}
		if(x[q.back()]<s){
			while(!q.empty()){
				stk.push(q.front());
				q.pop_front();
			}
			break;
		}
		if(p[q.front()]>=p[q.back()]){
			stk.push(q.back());
			p[q.front()]+=p[q.back()];
			q.pop_back();
		}
		else{
			stk.push(q.front());
			p[q.back()]+=p[q.front()];
			q.pop_front();
		}
	}
	for(int now=s;!stk.empty();now=x[stk.top()],stk.pop())
		ans+=abs(now-x[stk.top()]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	return (n + 9) / 10 * 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N,x,y,maxx=0,maxy=0;
	cin >> N;
	rep(i, N) {
		cin >> x >> y;
		if (x > maxx) {
			maxx = x;
			maxy = y;
		}
	}
	cout << maxx+maxy << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {

  ll N, K;
  std::cin >> N >> K;

  ll ans = 0;
  for(ll b = K+1; b<=N; b++) {
    ans += (N/b*std::max(0LL,b-K)+std::max(0LL,N%b-K+1));
    if ( K == 0 ) ans--;
  }

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

  return 0;
}

Measured memory_bytes: 256
while 1:
    H, W = map(int, input().split())

    if H == 0 and W == 0:
        break

    for i in range(H):
        for j in range(W):
            if i == 0 or i == H-1 or j == 0 or j == W-1:
                print("#", end = "")
            else:
                print(".", end = "")
        print("")
    print("")

Measured memory_bytes: 9096
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

int gojo(int n, int m)
{
	if (n > m) swap(n, m);
	while (true)
	{
		if (m == 0)
			return m;
		int nn = n;
		n = m % n;
		m = nn;
	}
}

vector<int> yakusu(int n)
{
	vector<int> v;
	for (int i = 1; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			v.push_back(i);
			if (i != n / i)
			{
				v.push_back(n / i);
			}
		}
	}
	sort(v.begin(), v.end());
	return v;
}

int N;
signed main()
{
	cin >> N;

	vector<int> y = yakusu(N);

	int m = LLONG_MAX;
	for (int a : y)
	{
		int b = N / a;
		m = min(m, a + b - 2);
	}

	cout << m << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;


int main(){
    int N, K; cin >> N >> K;
    string S; cin >> S;

    char current = S[0];

    vector<int> compress;
    int count = 0;
    rep(i,N){
        if (current == S[i]){
            count++;
        }
        else{
            compress.push_back(count);
            count = 1;
            current = S[i];
        }
    }
    compress.push_back(count);

    // 累積和を取得
    vector<int> cum(compress.size()+1,0);
    rep(i,compress.size()){
        cum[i+1] = cum[i] + compress[i];
    }

    int now = 0;
    if (S[0] == '1') now++;
    
    int ans = 0;
    for (int left = 0; left < cum.size(); left++){
        int tmp = 0;
        int add = 2*K;
        if (now == 1) add++;
        
        int right = min(left+add, (int)cum.size()-1);
        tmp = cum[right] - cum[left];
        ans = max(ans, tmp);
        
        // 0と1を切り替える
        now = 1 - now;
    }

    cout << ans << endl;

}

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

int k;

int gcd(int a, int b) {
    if (b == 0) 
        return a; 
    return gcd(b, a % b);
} 

int main() {
	cin >> k;
	long long ans = 0;
	for (int a=1; a<=k; a++) {
		for (int b=1; b<=k; b++) {
			for (int c=1; c<=k; c++) {
				ans += gcd(a, gcd(b, c));
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int cur=s.find("C");
	if(cur<0) cout<<"No"<<endl;
	else
	{
		s=s.substr(cur,s.length());
		cur=s.find("F");
		if(cur<0) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int x = sc.nextInt();
		
		int[] l = new int[n];
		
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		int d = 0;
		int count = 1;
		
		for (int i = 0; i < n;) {
			d = d + l[i];
			if (d <= x) {
				count++;
				i++;
			} else {
              break;
            }
		}
		System.out.println(count);
	}

}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>



using namespace std;


typedef long long ll;
typedef long double ld;

#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define forn(i, n) for (int i = 0; i < int(n); ++i)

#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()


const int N = (int) 1e6 + 10;

ll a[N];
ll b[N];

int main(){
    ios_base::sync_with_stdio(0);
    
    
    // freopen("input.txt" , "r" , stdin);
    // freopen("output.txt" , "w" , stdout);
    
    
    ll n;
    cin >> n;
    
    for (int i = 0; i < n; ++i){
        cin >> a[i];
    }
    
    sort(a, a + n);
    
    /* for (int i = 0; i < n; ++i){
     cout << a[i] << " ";
     }
     
     cout << endl;*/
    
    ll q = (n + 1) / 2 - 1;
    
    //  cout << q << endl;
    
    ll ql, qr,l,r;
    
    b[q] = a[0];
    ql = q - 1;
    qr = q + 1;
    l = 1;
    r = n - 1;
    
    while (true){
        if (qr == n && ql == -1) break;
        if (qr < n){
            b[qr] = a[r];
            qr++;
            r--;
        }
        if (ql > -1){
            b[ql] = a[r];
            ql--;
            r--;
        }
        if (qr < n){
            b[qr] = a[l];
            qr++;
            l++;
        }
        if (ql > -1){
            b[ql] = a[l];
            ql--;
            l++;
        }
    }
    
    /*   for (int i = 0; i < n; ++i){
     cout << b[i] << " ";
     }
     
     cout << endl;*/
    
    ll ans;
    ans = 0;
    
    for (int i = 0; i < n - 1; ++i){
        ans += abs(b[i] - b[i+1]);
    }
    
     q = (n + 1) / 2 - 1;
    
    //  cout << q << endl;
    
    
    b[q] = a[n - 1];
    ql = q - 1;
    qr = q + 1;
    l = 0;
    r = n - 2;
    
    while (true){
        if (qr == n && ql == -1) break;
        if (qr < n){
            b[qr] = a[l];
            qr++;
            l++;
        }
        if (ql > -1){
            b[ql] = a[l];
            ql--;
            l++;
        }
        if (qr < n){
            b[qr] = a[r];
            qr++;
            r--;
        }
        if (ql > -1){
            b[ql] = a[r];
            ql--;
            r--;
        }
    }
    
    ll temp = 0;
    
    for (int i = 0; i < n - 1; ++i){
        temp += abs(b[i] - b[i+1]);
    }
    
    cout << max(temp,ans);
    
    return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;
#define NUM 1e9+7

int main() {
    ll n,m;
    cin >> n >> m;
    ll N=1,M=1;

    for(ll i=1;i<=n;i++)    N = N*i%ll(NUM);
    for(ll i=1;i<=m;i++)    M = M*i%ll(NUM);

    if(n+1==m||n==m+1)  cout << N*M%ll(NUM);
    else if(n==m)   cout << 2*N*M%ll(NUM);   
    else cout << 0 << endl;
    
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
#include <stdio.h>
#define int long long
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
int Max(int x, int y) {
	if (x > y)return x;
	else return y;
}
int Min(int x, int y) {
	if (x < y)return x;
	else return y;
}
int kai(int x) {
	int cnt=1;
	if (x == 0)return 1;
	cnt = kai(x - 1);
	return x * cnt;
}
inline void shoki()
{
	srand((unsigned int)time(NULL));
}

/*Library End!*/

signed main() {
	string s, t;
	map<char, char>m1;
	map<char, bool>m2;
	map<char, char>m3;
	map<char, bool>m4;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		if (m1[t[i]] != s[i] && m2[t[i]]) {
			cout << "No" << endl;
			goto end;
		}
		m1[t[i]] = s[i];
		m2[t[i]] = true;
	}
	for (int i = 0; i < s.size(); i++) {
		if (m3[s[i]] != t[i] && m4[s[i]]) {
			cout << "No" << endl;
			goto end;
		}
		m3[s[i]] = t[i];
		m4[s[i]] = true;
	}
	cout << "Yes" << endl;
end:;
	system("PAUSE");
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

bool is_feasible(uint32_t n, uint32_t k, uint32_t P, vector<uint32_t> w) {
    uint32_t sum = 0, count = 0;

    for (uint32_t i = 0; i < n; i++) {
        if (w[i] > P) {
            return false;
        }

        if (sum + w[i] > P) {
            sum = w[i];
            count++;
            if (count > k) {
                return false;
            }
        } else {
            sum += w[i];
        }
    }

    return count < k;
}

int main() {
    uint32_t n, k;

    cin >> n >> k;

    vector<uint32_t> w(n);

    for (uint32_t i = 0; i < n; i++) {
        cin >> w[i];
    }

    uint32_t left = 0, right = 1000000000;
    while (right - left > 1) {
        uint32_t mid = (left + right) / 2;
        if (is_feasible(n, k, mid, w)) {
            right = mid;
        } else {
            left = mid;
        }
    }

    cout << right << endl;

    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string x;
	int k, i, j;
	cin >> x >> k;
	set<string> s;
	int n=x.size();
	for (i=0; i<n; i++)
	{
		for (j=1; j<=5; j++)
		{
			if (i+j-1>=n)
			{
				continue;
			}
			
			s.insert(x.substr(i, j));
		}
	}
	for (i=1; i<=k-1; i++)
	{
		s.erase(s.begin());
	}
	cout << *s.begin() << endl;
	return 0;
}

Measured memory_bytes: 1664
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,sum=0;
  cin>>a>>b>>c;
  if(b>=c){
    cout<<"delicious"<<'\n';
  }
  else if(c-b>a){
    cout<<"dangerous"<<'\n';
  }
  else{
    cout<<"safe"<<'\n';
  }
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
//ll mod = 1000000009;
//ll mod = 998244353;

int gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n%m);
}

int main() {
	int n, p, q;
	cin >> n;
	vector<int> a(n);
	vector<vector<int>> x(n, vector<int>());
	vector<vector<int>> y(n, vector<int>());
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		for (int j = 0; j < a[i]; j++) {
			cin >> p >> q;
			p--;
			x[i].push_back(p);
			y[i].push_back(q);
		}
	}
	int ans = 0;
	for (int i = 0; i < (1 << n); i++) {
		bool flag = true;
		for (int j = 0; j < n; j++) {
			if (i&(1 << j)) {
				for (int k = 0; k < a[j]; k++) {
					if ((i&(1 << x[j][k])) == 0 && y[j][k] != 0) flag = false;
					if ((i&(1 << x[j][k])) != 0 && y[j][k] == 0) flag = false;
				}
			}
		}
		if (flag) {
			int cnt = 0;
			for (int j = 0; j < n; j++) {
				if (i&(1 << j)) cnt++;
			}
			ans = max(ans, cnt);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size()+1;
    int a[n] = {};
    for (int i = 0; i < n-1; i++) {
        if (s[i] == '<') {
            a[i+1] = max(a[i+1], a[i]+1);
        }
    }
    for (int i = n-2; i >= 0; i--) {
        if (s[i] == '>') {
            a[i] = max(a[i], a[i+1]+1);
        }
    }
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 2844
// AOJ 2155: Infected Computer
// 2017.10.20 bal4u@uu

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

typedef struct { int t, s, d; } T;
T tbl[20002];
char f[20002];

int cmp(T *a, T *b) { return a->t - b->t; }

char buf[130], *p;
int getInt(void)
{
	int n;
	if (*p == ' ') p++;
	n = 0; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}
int main()
{
	int n, m, i, ans;
	register T *t;
	char *q;

	while (fgets(p=buf, 128, stdin) && *p != '0') {
		n = getInt(), m = getInt();
		memset(f, 0, n+1);
		for (t = tbl, i = m; i--; t++) {
			fgets(p=buf, 128, stdin);
			t->t = getInt(), t->s = getInt(), t->d = getInt();
		}
		qsort(tbl, m, sizeof(T), cmp);
		for (f[1] = 1, t = tbl, i = m; i--; t++) f[t->d] |= f[t->s];
		for (ans = 0, q = f+1, i = n; i--; ) ans += *q++;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int main()
{
    int n ,m;
    cin >> n >> m;
    vector<pair<ll,ll>> nums(m+1);
    vector<vector<pair<ll,ll>>> year(n+1);
    rep(i,m){
        ll p;
        ll y;
        cin >> p >> y;
        year[p].push_back(pair<ll,ll>(y,i+1));
        
    }
    rep(i,n){
        if(year[i+1].size()== 0)continue;
        sort(year[i+1].begin(),year[i+1].end());
        rep(j,year[i+1].size()){
            ll pref = i+1;
            ll city = year[i+1][j].second;
            nums[city].first = pref;
            nums[city].second = j+1;
            
        }
    }
    rep(i,m+1){
        if(i == 0)continue;
        printf("%06ld%06ld\n",nums[i].first,nums[i].second);
    }



    
    return 0;
}

Measured memory_bytes: 8576
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 100001;
const int maxk = 17;
#define is_anc(a, b) (in[a] < in[b] and out[a] >= out[b])
struct info{
	int v, c, w;
};
struct query{
	int id, c, w, y;
};
int n, anc[maxn][maxk], in[maxn], out[maxn], depth[maxn], m;
long long ans[maxn];
vector < info > edge[maxn];
vector < query > ask[maxn];
void dfs(int now, int last = 1){
	static int t = 0;
	static int d = 0;
	depth[now] = d++;
	in[now] = t++;
	anc[now][0] = last;
	for(int i = 1;i < maxk;++i)anc[now][i] = anc[anc[now][i - 1]][i - 1];
	for(auto &i : edge[now])
		if(last != i.v)dfs(i.v, now);
	out[now] = t;
	--d;
}
int get_lca(int a, int b){
	if(depth[a] > depth[b])swap(a, b);
	if(is_anc(a, b))return a;
	for(int i = maxk - 1;i > -1;--i)
		if(!is_anc(anc[b][i], a))b = anc[b][i];
	return anc[b][0];
}
void dfs2(int now, int last = 1){
	static int total_w = 0;
	static int q_of[maxn] = {};
	static int w_of[maxn] = {};
	for(auto &i : ask[now]){
		ans[i.id] += (total_w - w_of[i.c] + q_of[i.c] * i.y) * i.w;
	}
	for(auto &i : edge[now]){
		if(i.v != last){
			++q_of[i.c];
			w_of[i.c] += i.w;
			total_w += i.w;
			dfs2(i.v, now);
			--q_of[i.c];
			w_of[i.c] -= i.w;
			total_w -= i.w;
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for(int a, b, c, d, i = 1;i < n;++i){
		cin >> a >> b >> c >> d;
		edge[a].push_back({b, c, d});
		edge[b].push_back({a, c, d});
	}
	dfs(1);
	for(int i = 0, x, y, u, v, lca;i < m;++i){
        cin >> x >> y >> u >> v;
		lca = get_lca(u, v);
		ask[u].push_back({i, x, 1, y});
		ask[v].push_back({i, x, 1, y});
		ask[lca].push_back({i, x, -2, y});
	}
	dfs2(1);
	for(int i = 0;i < m;++i)cout << ans[i] << '\n';
}


Measured memory_bytes: 28788
#include <stdio.h>
int main(void){
	long long n,t,ans=0,i;
	scanf("%lld%lld",&n,&t);
	int time,time2;
	scanf("%d",&time);
	ans += t;
	for(i=1;i<n;i++){
		scanf("%d",&time2);
		if(time+t>time2) ans += time2 - time;
		else if(t==time) ans += t;
		else ans += t ;
		time = time2;
	}
	
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#define out(a) printf("%d",a)
#define ll long long
using namespace std;
int n;
int a[100050];
int num,b,ans; 
int read()
{
	int s=0,t=1; char ch;
	while (ch<'0'||ch>'9'){if (ch=='-') t=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){s=s*10+ch-'0'; ch=getchar();}
	return s*t;
}
int main()
{
	n=read(); 
	if (n==1) {
		out(1);
		return 0;
	}
	for (int i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	  sort(a+1,a+n+1);
	for (int i=1;i<=n-1;i++) {
	  if (a[i]==a[i+1]) num++;
	  else {
	  	if (num%2==0) ans++;
	  	num=0;
	  }
	   if (i==n-1) {
	  	if (num%2==0) ans++;
	  }
}
	  out(ans);
}

Measured memory_bytes: 640