akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
  using namespace std;

  int main () {
    int i;
    cin >> i;
    i %= 10;
    if(i == 3) cout << "bon" << endl;
    else if(i == 0 || i == 1 || i == 6 || i == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

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

using namespace std;

namespace {

bool Search(const vector<int>& S, int t) {
  int min = 0;
  int max = S.size();
  int mid = (min + max) / 2;
  while (min <= max) {
    if (t == S[mid]) {
      return true;
    } else if (t > S[mid]) {
      min = mid + 1;
    } else {
      max = mid - 1;
    }
    mid = (min + max) / 2;
  }
  return false;
}

} // namespace

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

  vector<int> S(n);
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
  }

  int q;
  cin >> q;

  int C = 0;
  int t;
  for (int i = 0; i < q; ++i) {
    cin >> t;
    if (Search(S, t))
      ++C;
  }
  cout << C << endl;

  return 0;
}

Measured memory_bytes: 1532
/**
 * File              :  b.cpp
 * Author            : recurze
 * Date              : 22:52 18.01.2019
 * Last Modified Date: 22:59 18.01.2019
 */
#include <stdio.h>
#include <float.h>
#include <math.h>

void readInput();
void solve();
void printAns();

int main() {
    int t = 1;
    //scanf("%d", &t);

    for (int tc = 1; tc <= t; ++tc) {
        readInput();
        solve();
        printAns();
    }
}

const int N = 1010101;

int n = 0, t = 0, a = 0;
int h[N];
void readInput() {
    scanf("%d", &n);
    scanf("%d%d", &t, &a);
    for (int i = 0; i < n; ++i) {
        scanf("%d", h + i);
    }
}

double computeT(int t, int x) {
    return (double)t - x*0.006;
}

int ans = 0;
double min = DBL_MAX;
void solve() {
    for (int i = 0; i < n; ++i) {
        double x = computeT(t, h[i]) - (double)a;
        if (x < 0) x = -x;
        if (x < min) {
            min = x;
            ans = i + 1;
        }
    }
}

void printAns() {
    printf("%d\n", ans);
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int h, w, n;
    cin >> h >> w >> n;

    set<pair<int, int> > s;
    for(int i=0; i<n; ++i){
        int y, x;
        cin >> y >> x;
        s.insert(make_pair(y, x));
    }

    set<pair<int, int> > history;
    vector<long long> ans(10, 0);
    ans[0] = (h - 2LL) * (w - 2LL);
    for(const auto& p : s){
        for(int i=0; i<9; ++i){
            int y = p.first  - 2 + i / 3;
            int x = p.second - 2 + i % 3;
            if(!(1 <= y && y <= h - 2 && 1 <= x && x <= w - 2))
                continue;
            if(history.find(make_pair(y, x)) != history.end())
                continue;
            history.insert(make_pair(y, x));

            int cnt = 0;
            for(int j=0; j<9; ++j){
                int y2 = y + j / 3;
                int x2 = x + j % 3;
                if(s.find(make_pair(y2, x2)) != s.end())
                    ++ cnt;
            }
            ++ ans[cnt];
            -- ans[0];
        }
    }

    for(int i=0; i<10; ++i)
        cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

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

  vector<int> H(N);
  rep(i,0,N-1) cin >> H[i];

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

  string ans = "Yes";
  rep(i,1,N-1) {
    int diff = H.at(i) - H.at(i-1);
    if (1 < diff) ans = "No";
    else if (0 < diff) H[i] -= 1;
  }

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


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<functional>
const int P=1000000007;
int a[107],f[107][107][507];
int read(){int x;scanf("%d",&x);return x;}
void inc(int&a,int b){a+=b-P,a+=a>>31&P;}
int mul(int a,int b){return 1ll*a*b%P;}
int main()
{
    int n=read(),m=read(),ans=0;
    for(int i=1;i<=n;++i) a[i]=read();
    std::sort(a+1,a+n+1,[](int i,int j){return i>j;}),f[1][1][a[1]]=1;
    for(int i=2;i<=n;++i)
	for(int j=0;j<=i;++j)
	    for(int k=0;k<=m;++k)
		if(f[i-1][j][k])
		{
		    inc(f[i][j][k],mul(k-(a[i]-1)*j,f[i-1][j][k]));
		    if(k+a[i]<=m) inc(f[i][j+1][k+a[i]],mul(j+1,f[i-1][j][k]));
		    for(int l=1;l<a[i]&&k+l<=m;++l) inc(f[i][j][k+l],mul(j*2,f[i-1][j][k]));
		    if(j>1) for(int l=0;l<a[i]&&k+l<=m;++l) inc(f[i][j-1][k+l],mul((j-1)*(a[i]-l-1),f[i-1][j][k]));
		}
    for(int i=1;i<=n;++i) inc(ans,f[n][i][m]);
    printf("%d",ans);
}


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

int main(){
    vector<int> time(5), rem(5);
    int res = 0, min = 10, min_index = 0;

    for(int i = 0; i < 5; ++i)
    {
        cin >> time[i];
        rem[i] = time[i] % 10;

        if(rem[i] != 0 && rem[i] < min)
        {
            min = rem[i];
            min_index = i;
        }
    }

    for(int i = 0; i < 5; ++i)
    {
        if(i == min_index) res += time[i];
        else if(rem[i] == 0) res += time[i];
        else res += time[i] + 10 - rem[i];
    }
    
    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 3632
import sys
from operator import itemgetter, attrgetter
from itertools import starmap
import cmath
from math import isinf, sqrt, acos, atan2
readline = sys.stdin.readline
EPS = 1e-9
ONLINE_FRONT = -2
CLOCKWISE = -1
ON_SEGMENT = 0
COUNTER_CLOCKWISE = 1
ONLINE_BACK = 2
class Circle(object):
    __slots__ = ('c', 'r')
    def __init__(self, c, r):
        self.c = c
        self.r = r
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
Line = Segment
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
def ccw(p1, p2, p3):
    a = p2 - p1
    b = p3 - p1
    if cross(a, b) > EPS: return 1
    if cross(a, b) < -EPS: return -1
    if dot(a, b) < -EPS: return 2
    if norm(a) < norm(b): return -2
    return 0
def intersect4(p1, p2, p3, p4):
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0)
def intersect2(s1, s2):
    return intersect4(s1.fi, s1.se, s2.fi, s2.se)
def getDistance(a, b):  return abs(a - b)
def getDistanceLP(l, p):
    return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))
def getDistanceSP(s, p):
    if dot(s.se - s.fi, p - s.fi) < 0.0: return abs(p - s.fi)
    if dot(s.fi - s.se, p - s.se) < 0.0: return abs(p - s.se)
    return getDistanceLP(s, p)
def getDistances(s1, s2):
    if intersect2(s1, s2): return 0.0
    return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se),
               getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))
def getCrossPoint(s1, s2):
	base = s2.se - s2.fi
	d1 = abs(cross(base, s1.fi - s2.fi))
	d2 = abs(cross(base, s1.se - s2.fi))
	t = d1 / (d1 + d2)
	return s1.fi + (s1.se - s1.fi) * t
def getCrossPointsCL(c, l):
    pr = project(l, c.c)
    e = (l.se - l.fi) / abs(l.se - l.fi)
    base = sqrt(c.r * c.r - norm(pr - c.c))
    return Segment(*sorted((pr + e * base, pr - e * base)), key=attrgetter('real', 'imag'))
def getCrossPointsCC(c1, c2):
    d = abs(c1.c - c2.c)
    a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2.0 * c1.r * d))
    t = cmath.phase(c2.c - c1.c)
    return Segment(*sorted((c1.c + cmath.rect(c1.r, t + a), c1.c + cmath.rect(c1.r, t - a)), key=attrgetter('real', 'imag')))
def contains(g, p):
    n = len(g)
    x = False
    for i in range(n):
        a = g[i] - p
        b = g[(i + 1) % n] - p
        if abs(cross(a, b)) < EPS and dot(a, b) < EPS: return 1
        if a.imag > b.imag: a, b = b, a
        if a.imag < EPS and EPS < b.imag and cross(a, b) > EPS: x = not x
    return 2 if x else 0
n = int(readline())
pg = [complex(*map(int, readline().split())) for _ in [0] * n]
q = int(readline())
for _ in [0] * q:
    x, y = map(int, readline().split())
    print(contains(pg, complex(x, y)))

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

#define INF 1300500000

int dp[2][256];
int sample[20010];


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

  while (1) {
    int N, M, code[16];
    cin >> N >> M;
    if (N == 0 && M == 0) break;
    REP(i, M) cin >> code[i];
    REP(i, N) cin >> sample[i];

    fill(dp[0], dp[0]+256, -1);
    dp[0][128] = 0;

    REP(i, N) {
      fill(dp[(i+1)%2], dp[(i+1)%2]+256, -1);
      REP(j, 256) {
	if (dp[i%2][j] == -1) continue;
	REP(k, M) {
	  int next = max(0, min(255, j + code[k]));
	  int diff = sample[i] - next;
	  if (dp[(i+1)%2][next] == -1 || dp[i%2][j] + diff * diff < dp[(i+1)%2][next]) {
	  dp[(i+1)%2][next] = dp[i%2][j] + diff * diff;
	  }
	}
      }
    }
    int ans = -1;
    REP(i, 256) {
      if (ans == -1 || (dp[N%2][i] != -1 && dp[N%2][i] < ans))
	ans = dp[N%2][i];
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define line cout << "----------" << endl;


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
void Yay(bool condition){

    if(condition){
        p("Yay!");
    }else{
        p(":(");
    }
    return;
}

//ll fact[800005],rfact[800005];
/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,ans,a,b,c,d,e,g,h,w,i,j,k,q;
ll x[500005],y[500005],z[500005];
ll sum[500005],lsum[500005];
char s[500005],t[500005];
bool dame;


int main(){
	cin >> s;
	for(i=0;i<3;i++){
		if(s[i] == s[i+1])dame = true;
	}
	if(dame){
		p("Bad");
	}else{
		p("Good");
	}
	return 0;
}


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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    for(int i=0;i<N;++i){
        cin >> h[i];
    }
    vector<int> B(N);
    for(int i=0;i<N;++i){
        B[i] = h[i];
    }
    sort(B.begin(),B.end());
    int res_dif=B[K-1]-B[0];
    for(int i=1;i<N-K+1;++i){
        if(res_dif>B[K+i-1]-B[i]){
            res_dif=B[K+i-1]-B[i];
        }
    }
    
    cout << res_dif;
}

Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


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

int main(){
    int n;
    cin>>n;
    vector<int> a(2*n-1);
    for(int i=0;i<2*n-1;i++)  cin>>a[i];

    int lb=1,ub=2*n;
    while(ub-lb>1){
        int mid=(lb+ub)/2;
        vector<int> flag(2*n-1);
        for(int i=0;i<2*n-1;i++){
            flag[i]=(mid<=a[i]);
        }
        int l=0;
        bool bl=flag[0];
        for(int i=1;i<=n-1;i++){
            if(flag[i]==flag[i-1]) l=i,bl=flag[i];
        }
        int r=2*n-2;
        bool br=flag[2*n-2];
        for(int i=2*n-3;i>=n-1;i--){
            if(flag[i]==flag[i+1]) r=i,br=flag[i];
        }
        bool f=(n-1-l<=r-n+1 ? bl : br);
        
        if(l==0 && r==2*n-2){
            f=((n-1)%2)^flag[n-1];
        }
        if(f) lb=mid;
        else ub=mid;
    }
    cout<<lb<<endl;

    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int c,n,m,s,d;
	while(cin>>c>>n>>m>>s>>d,n){
		s--;d--;
		int cost[110][110];
		rep(i,110)rep(j,110)cost[i][j]=inf;
		while(m--){
			int a,b,e;
			cin>>a>>b>>e;
			a--;b--;
			cost[a][b]=cost[b][a]=e;
		}
		int dp[110][11];
		int used[110]={0};
		rep(i,110)rep(j,11)dp[i][j]=inf;
		rep(i,11)dp[s][i]=0;
		while(1){
			int v=-1;
			rep(i,n)if(!used[i]&&(v==-1||dp[v][0]>dp[i][0]))v=i;
			if(v==-1)break;
			used[v]=true;
			rep(i,n)for(int j=c;j>=0;j--){
				dp[i][j]=min(dp[i][j],dp[v][j]+cost[v][i]);
				dp[i][j+1]=min(dp[i][j+1],dp[v][j]+cost[v][i]/2);
			}
		//rep(i,6){rep(j,3)cout<<" "<<dp[i][j];cout<<endl;}
		//cout<<endl;
		}
		//rep(i,6){rep(j,3)cout<<" "<<dp[i][j];cout<<endl;}
		cout<<dp[d][c]<<endl;
	}
}

Measured memory_bytes: 1208
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int x[3];
        for(int i=0; i<3; ++i)
            cin >> x[i];
        if(x[0] == 0)
            return 0;
        sort(x, x+3);

        int n;
        cin >> n;

        while(--n >= 0){
            int r;
            cin >> r;
            if(4*r*r - x[0]*x[0] - x[1]*x[1] > 0)
                cout << "OK" << endl;
            else
                cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 0
N = int(input())
xy = [[] for _ in range(N)]

for i in range(N):
  A = int(input())
  for _ in range(A):
    xy[i].append(list(map(int, input().split())))
lst = [[0 for j in range(N)] for k in range(2**N)]

for l in range(2**N):
  for m in range(N):
    if (l >> m) & 1:
      lst[l][m] = 1

ans = 0
for n in lst:
  flag = True
  for f in range(N):
    if n[f] == 1:
      for g in xy[f]:
        if n[g[0]-1] != g[1]:
          flag = False
          break
    else:
      tmp = 0
      for g in xy[f]:
        if n[g[0]-1] == g[1]:
          tmp += 1
      if tmp == len(n):
        flag = False
    if not flag:
      break
  if flag:
    ans = max(ans, n.count(1))
print(ans)

Measured memory_bytes: 15680
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)
 
//int dxy[5] = {0, 1, 0, -1, 0};
// cmd
 
signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
    int2(a, b);
 
    int c = a * 2, d = b * 2;
    int cnt = 0;
    while (1) {
        if (cnt % 2 == 0) {
            // sente UKU
            d -= min(a, c);
        } else {
            c -= (d / 2) + (d % 2);
        }
        if (c > 0 && d > 0) 
            cnt++;
        else
            break;
    }
 
    int ans = 0;
    c = a * 2; d = b * 2;
    while (1) {
        if (ans % 2 == 0) {
            // sente UKU
            d -= (c / 2) + (c % 2);
        } else {
            c -= min(b, d);
        }
        if (c > 0 && d > 0) 
            ans++;
        else
            break;
    }
 
    std::cout << min(ans, cnt) << std::endl;
 
 
 
    return 0;
}


Measured memory_bytes: 3168
X,Y,Z,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

from heapq import heapify, heappop, heappush, heappushpop
hp=[]
hist=set([])
heapify(hp)
hp0=[-(A[0]+B[0]+C[0]), 1, 1, 1]
heappush(hp, hp0)
hist.add(tuple(hp0[1:]))
k=0
while k<K:
  k+=1
  sabc=heappop(hp)
  print(sabc[0]*-1)
  for i in [1,2,3]:
    sabc_next = sabc[:]
    sabc_next[i]=sabc[i]+1
    sp = sabc_next[1]*sabc_next[2]*sabc_next[3]
    if sp<=K and sabc_next[1]<=X and sabc_next[2]<=Y and sabc_next[3]<=Z:
      sabc_next[0] = - (A[sabc_next[1]-1]+B[sabc_next[2]-1]+C[sabc_next[3]-1])
      if not tuple(sabc_next[1:]) in hist: 
        heappush(hp,sabc_next)
        hist.add(tuple(sabc_next[1:]))

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    Graph G(N);
    for(int i = 0; i < N; i++) {
        int a; cin >> a; a--;
        G[i].push_back(a);
    }
    
    queue<int> que;
    vector<int> visit(N), dist(N);
    que.push(0);
    while(!que.empty()) {
        int u = que.front(); que.pop();
        for(auto v : G[u]) {
            if(visit[v] == 0) {
                visit[v] = 1;
                dist[v] = dist[u] + 1;
                que.push(v);
            }
        }
    }
    if(visit[1]) cout << dist[1] << endl;
    else cout << -1 << endl;
    return 0;
}

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

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

  std::vector<int> a(n);
  for (auto&& ai : a) std::cin >> ai;

  std::vector<int> student_id(n);
  std::iota(student_id.begin(), student_id.end(), 1);
  std::sort(student_id.begin(), student_id.end(),
            [&a](auto i, auto j) { return a[i - 1] < a[j - 1]; });

  for (auto&& i : student_id) std::cout << i << ' ';
  std::cout << std::endl;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main()
{
    long long a,b;
    cin>>a>>b;
    if(a+b>=a-b && a+b>=a*b)
        cout<<a+b;
    else if (a-b>=a+b && a-b>=a*b)
        cout<<a-b;
    else if (a*b>=a+b && a*b>=a-b)
        cout<<a*b;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[7];
int main(){
for (int i = 0; i < 6; ++i) cin >> a[i];
int N = 0;
for (int i = 0; i < 6; ++i){
	if(a[i]==1)
	N++;
}
int B = 0;
for (int i = 0; i < 6; ++i){
	if(a[i]==2)
	B++;
}
int V = 0;
for (int i = 0; i < 6; ++i){
	if(a[i]==3)
	V++;
}
int C = 0;
for (int i = 0; i < 6; ++i){
	if(a[i]==4)
	C++;
}
if(N>=3 || B>=3 || V>=3 || C>=3){
 cout << "NO" << endl;
}else{
 cout << "YES" <<endl;
}
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int n , m ;
    cin >> n >> m ;

    vi h ( n + 1 ) ;

    for ( int i = 1 ; i <= n ; i ++ )
    {
        cin >> h[i] ;
    }

    vvi g ( n + 1 ) ;

    for ( int i = 1 ; i <= m ; i ++ )
    {
        int a , b ;
        cin >> a >> b ;

        g[a].pb ( b ) ;
        g[b].pb ( a ) ;
    }

    int ans = 0 ;

    for ( int i = 1 ; i <= n ; i ++ )
    {
        bool ok = 1 ;

        for ( auto &j : g[i] )
        {
            if ( h[i] > h[j] ) C ;

            ok = false ;
            break ;
        }

        if ( ok ) ans ++ ;
    }

    cout << ans ; line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0;
}


Measured memory_bytes: 8744
fn main() {
    let (n, k) = read_tuple::<i64>();

    let x = n / k;
    let y = (n + k / 2) / k;

    if k % 2 != 0 {
        println!("{:?}", x*x*x);
    } else {
        println!("{:?}", x*x*x + y*y*y);
    }
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define NMAX 110000
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;

int main()
{
	int a,b;
	cin >> a >> b;
	
	if(b%a ==0) cout << a + b << endl;
	else cout << b-a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <cmath>
#include <complex>
#include <vector>
#include <utility>
using namespace std;

typedef complex<double> Point;
#define X real()
#define Y imag()
#define EPS 10e-8

namespace std {
  bool operator < (Point a, Point b) {
    if (a.X != b.X) return a.X < b.X;
    return a.Y < b.Y;
  }
}

double cross(Point a, Point b) {
  return (conj(a)*b).Y;
}

double dot(Point a, Point b) {
  return (conj(a)*b).X;
}

double dist2(Point a, Point b) {
  return dot(a-b, a-b);
}

struct Line : public vector<Point> {
  Line(Point a, Point b) {push_back(a); push_back(b);}
};

int n;
Point ps[3];

Line PerpendBisect(Line l) {
  Point mid = (l[0]+l[1])/2.0;
  return Line(mid, mid+(l[1]-l[0])*Point(0, 1));
}

Point GetCrossPoint(Line l, Line m) {
  double A = cross(l[1]-l[0], m[1]-m[0]);
  double B = cross(l[1]-l[0], l[1]-m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0];
  if (abs(A) < EPS) assert(false);
  return m[0] + B / A * (m[1]-m[0]);
}

double round3(double t) {
  return floor(t*1000+0.5)/1000.0;
}

int main() {
  scanf("%d", &n);
  while (n--) {
    for (int i=0; i<3; i++) {
      double x, y;
      scanf("%lf%lf", &x, &y);
      ps[i] = Point(x, y);
    }

    Line l(ps[0], ps[1]);
    Line m(ps[1], ps[2]);
    Point p = GetCrossPoint(PerpendBisect(l), PerpendBisect(m));
    double r = sqrt(dist2(p, ps[0]));
    printf("%.3f %.3f %.3f\n", round3(p.X), round3(p.Y), round3(r));
  }
}

Measured memory_bytes: 2728
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

A,B,C,K = LI()

current = min(A,K)
K -= min(A,K)
if K > 0: K -= min(B,K)
if K > 0: current -= min(C,K)

print(current)


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll k;
	string s;
	cin >> s >> k;
	bool same = true;
	char a = s[0];
	ll ss = s.size();
	REP(i, 1, ss){
		if(s[i] != a){
			same = false;
			break;
		}
	}
	if(same) cout << ss*k/2;
	else{
		ll ans = 0, i = 1;
		while(i < ss){
			if(s[i] == s[i-1]){
				++i;
				++ans;
			}
			++i;
		}
		ans *= k;
		if(a == s[ss-1]){
			ll checkA = 0;
			ll checkB = 0;
			while(checkA < ss && s[checkA] == a) ++checkA;
			while(ss-checkB > 0 && s[ss-1-checkB] == a) ++checkB;
			ans -= ((checkA/2 + checkB/2 - (checkA+checkB)/2) * (k-1));
		}
		cout << ans;
	}
	

}


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

int N, M;
vector<int> arr;
vector<int> cnt;
vector<int> seg;

int main() {
    scanf("%d %d", &N, &M);

    arr.resize(N);
    cnt = vector<int>(N + 1, 0);
    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        arr[i] = t;
        cnt[t]++;
    }

    seg = vector<int>(N, 0);

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= cnt[i]; j++) {
            if(i - j < 0) break;
            seg[i - j]++;
        }
    }

    int ans = 0;
    for(int i = 0; i < N; i++) if(!seg[i]) ans++;

    for(int i = 0; i < M; i++) {
        int x, y; scanf("%d %d", &x, &y);
        x--;
        if(arr[x] - cnt[ arr[x] ] >= 0) {
            seg[ arr[x] - cnt[ arr[x] ] ]--;
            if(!seg[ arr[x] - cnt[ arr[x] ] ]) ans++;
        }
        cnt[ arr[x] ]--;
        arr[x] = y;
        cnt[ arr[x] ]++;
        if(arr[x] - cnt[ arr[x] ] >= 0) {
            if(!seg[ arr[x] - cnt[ arr[x] ] ]) ans--;
            seg[ arr[x] - cnt[ arr[x] ] ]++;
        }
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 3840
n=int(input())
x=[]
for i in range(n):
    a,b=map(int, input().split())
    x.append([a+b,a-b])
x.sort(key=lambda x:x[0])

cur=-10**9
ans=0
for xx in x:
    if xx[1]>=cur:
        ans+=1
        cur=xx[0]
print(ans)

Measured memory_bytes: 21336
def main():
    N = int(input())
    A = [0] * N
    for i in range(N):
        A[i] = int(input())

    set_A = set(A)
    max_A = max(A)
    count_A = A.count(max_A)
    for a in A:
        if a == max_A and count_A == 1:
            print(sorted(set_A)[-2])
        else:
            print(max_A)

main()

Measured memory_bytes: 17332
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}

void solve() {
    ll n;
    std::cin >> n;

    vll f(n + 1, 0);
    for (ll i = 1; i <= n; i++) for (ll j = i; j <= n; j += i)
        f[j]++;

    ll ans = 0;
    for (ll i = 1; i <= n; i++)
        ans += i * f[i];

    std::cout << ans << '\n';
}


Measured memory_bytes: 81328
(defvar N (read))
(defvar Xi (loop :repeat N :collect (read)))
(defvar aveXi (/ (apply #'+ Xi) N))
(defvar P (floor (+ aveXi (/ 1 2))))

(princ 
 (reduce #'(lambda (x y)
	   (+ x (expt (- y P) 2)))
	 Xi :initial-value 0))

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

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


    int N; std::cin >> N;

    std::vector A(N, 0);
    for (int i = 0; i < N - 1; i++) {
        int a; std::cin >> a;
        A[a - 1]++;
    }

    for (int i = 0; i < N; i++) {
        std::cout << A[i] << '\n';
    }
}

Measured memory_bytes: 3988
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()


int main() {
	ll n;
	cin >> n;
	vll v(n);
	vector<pair<ll, ll>> n_odd, n_even;
	rep(i, 100001) {
		n_odd.push_back(pair<ll, ll>(0, i));
		n_even.push_back(pair<ll, ll>(0, i));
	}
	rep(i, n) {
		cin >> v[i];
		if ((i + 1) % 2 == 1) ++n_odd[v[i]].first;
		else ++n_even[v[i]].first;
	}
	sort(all(n_odd), greater<pair<ll, ll>>());
	sort(all(n_even), greater<pair<ll, ll>>());

	if (n_odd[0].second != n_even[0].second) {
		cout << n - n_odd[0].first - n_even[0].first << endl;
	}
	else {
		ll tmp = max(n_odd[0].first + n_even[1].first, n_odd[1].first + n_even[0].first);
		cout << n - tmp << endl;
	}
}


Measured memory_bytes: 4332
MODE = "stdiro"
#require 'matrix'
#include Math
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '6
  5 2 4 6 1 3'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end


n = line[0].to_i
a = line[1].split(" ").map(&:to_i)

puts a.join(" ")
(1..n-1).each do |i|
  v = a[i]
  j = i-1
  while (j>=0)&&(a[j]>v) do
    a[j+1] = a[j]
    j -= 1
  end
  a[j+1] = v
  puts a.join(" ")
end

Measured memory_bytes: 8748
a,b = map(int, input().split())
aList = [b]*a
bList = [a]*b
i = 0
l = min(len(bList),len(aList))
if a==b:
    pass
else:
    while aList[i]==bList[i]:
        i+=1
        if i+1==l:
            break
if aList[i]>bList[i]:
    print(*bList,sep="")
else:
    print(*aList,sep="")

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

int main(){
    long long h, w, k;
    cin >> h >> w >> k;

    char maze[h][w];
    long long ans = 0;

    for(long long i = 0; i < h; i++){
        for(long long j = 0; j < w; j++){
            cin >> maze[i][j];
        }
    }

    char maze_copy[h][w];
    for(long long bity = 0; bity < (1 << h); bity++){
        for(long long bitx = 0; bitx < (1 << w); bitx++){

            for(long long i = 0; i < h; i++){
                for(long long j = 0; j < w; j++){
                maze_copy[i][j] =  maze[i][j];
                }
            }

            for(long long y = 0; y < h; y++){
                for(long long x = 0; x < w; x++){
                    if(bitx & (1 << x) || bity & (1 << y)){
                        maze_copy[y][x] = 'R';
                    }
                }
            }

            long long count = 0;
            for(long long i = 0; i < h; i++){
                for(long long j = 0; j < w; j++){
                    if(maze_copy[i][j] == '#'){
                        count++;
                    }
                }
            }

            if(count == k){
                ans++;
            }
        }
    }

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

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <map>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> vec;
    // calculation
    vec.push_back(N);
    vec.push_back(M);
    vec.push_back(X);
    vec.push_back(Y);
    sort(vec.begin(), vec.end());
    if (vec[0] == 1 && vec[1] == 4 && vec[2] == 7 && vec[3] == 9) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }
    
    
    return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> H(n);
	for (int& h : H) {
		cin >> h;
	}
	vector<int> dp(n);
	dp[0] = dp[1] = 0;
	for (int i = 2; i <= n; i++) {
		dp[i] = INT_MAX;
		for (int j = 1; j <= k; j++) {
			if (i - 1 - j >= 0) {
				dp[i] = min(dp[i], dp[i - j] + abs(H[i - 1 - j] - H[i - 1]));
			}
		}
	}
	cout << dp[n];
	return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF 10000

int main() {
    int n, m;
    cin >> n >> m;
    int start = 0;
    REP(i, n) {
        char c;
        cin >> c;
        start <<= 1;
        start |= (c == '1' ? 1 : 0);
    }
    int goal = 0;
    int t = 0;
    REP(i, m) {
        int bits;
        cin >> bits;
        REP(j, bits) {
            goal <<= 1;
            goal |= t & 1;
        }
        t = ~t;
    }
    int goal2 = ~goal & ((1 << n)-1);
//    cout << bitset<15>(start) << endl;
//    cout << bitset<15>(goal) << endl;
//    cout << bitset<15>(~goal & ((1 << n)-1)) << endl;

    vvi dp(2, vi(1 << n, INF));
    dp[0][start] = 0;
    while (1) {
        dp[1] = dp[0];
        REP(step, 1 << n) {
            if (dp[0][step] == INF) continue;
            REP(i, n-1) {
                int has_next = (step >> i) & 3;
                if (has_next != 0 && has_next != 3) {
                    int next = step;
                    if (next & (1 << i)) {
                        next &= ~(1 << i);
                    } else {
                        next |= (1 << i);
                    }
                    if (next & (1 << (i+1))) {
                        next &= ~(1 << (i+1));
                    } else {
                        next |= (1 << (i+1));
                    }
//                    cout << bitset<15>(next) << endl;
                    dp[1][next] = min(dp[1][next], dp[0][step]+1);
                }
            }
        }
        dp[0] = dp[1];

        if (min(dp[0][goal], dp[0][goal2]) != INF) {
            cout << min(dp[0][goal], dp[0][goal2]) << endl;
            break;
        }
    }
}

Measured memory_bytes: 3352
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>

struct node {
  node *parent_;
  int value_;
  int level_;
  int num_nodes_;
  std::vector<node*> children_;

  node(node *parent, int value) : parent_(parent), value_(value), level_(0), num_nodes_(1) {
    level_ = parent ? parent->level_ + 1 : 0;
  }

  node* build_tree_and_search(int search_target,
                              const std::vector<std::list<int>> &edges) {
    node *target_node = nullptr;
    for (auto it = edges[value_].begin(); it != edges[value_].end(); ++it) {
      if (parent_ == nullptr || *it != parent_->value_) {
        auto p = new node(this, *it);
        auto target_in_child = p->build_tree_and_search(search_target, edges);
        if (target_node == nullptr) {
          target_node = (*it == search_target) ? p : target_in_child;
        }
        children_.push_back(p);
        num_nodes_ += p->num_nodes_;
      }
    }

    return target_node;
  }


  ~node() {
    for (auto it : children_) {
      delete it;
    }
  }

  void dump() {
    printf("l:%d n:%d v:%d\n", level_, num_nodes_, value_);
  }
};

int main(int argc, char **argv) {
  int N;
  scanf("%d", &N);

  std::vector<std::list<int>> edges(N + 1, std::list<int>());
  for (int i = 1; i < N; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    edges[a].push_back(b);
    edges[b].push_back(a);
  }

  node root(nullptr, 1);
  node *node_N = root.build_tree_and_search(N, edges);
  node *border = node_N;
  while (border->parent_->level_ > node_N->level_ / 2) {
     border = border->parent_;
  }

//  root.dump();
//  node_N->dump();
//  border->dump();

  int pt_f = root.num_nodes_ - border->num_nodes_;
  int pt_s = border->num_nodes_;
  printf("%s\n", pt_f > pt_s ? "Fennec" : "Snuke");

  return 0;
}

Measured memory_bytes: 21632
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#define N 100100
typedef long long ll;
using namespace std;
int main()
{
    int x,y,z;
    cin>>x>>y>>z;
   int ans=x/y;
       while (x-ans*y<(ans+1)*z)
            ans--;
            cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	int n,i;
	char a[1000];
	scanf("%d",&n);
	getchar();
	gets(a);
	int k=strlen(a);
	if(k>n){
		for(i=0;i<n;i++)printf("%c",a[i]);
		printf("...\n");
	}
	else printf("%s",a);
	
	return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int MX = 200001;
int n, m, v[100000], sum[MX];
bool dp[2][MX];
vector<vi> e;

bool rec(int c, int col, int &a, int &b){
	a++;
	v[c] = col;
	rep(i, e[c].size()){
		if(v[e[c][i]]){
			if(v[e[c][i]] == col) return 0;
		}
		else rec(e[c][i], -col, b, a);
	}
	return 1;
}

int main(){
	scanf("%d%d", &n, &m);
	e.resize(n);
	rep(i, m){
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	map<int, int> s;
	rep(i, n) if(!v[i]){
		int a = 0, b = 0;
		if(!rec(i, 1, a, b)){
			cout << -1 << endl;
			return 0;
		}
		s[abs(a - b)]++;
	}
	
	//each(i, s) cerr<<i->first<<" "<<i->second<<endl;
	const int GETA = 100000;
	dp[0][GETA] = 1;
	int cur = 0, next = 1;
	each(i, s){
		memset(dp[next], 0, sizeof(dp[next]));
		memset(sum, 0, sizeof(sum));
		
		int a = i->first, b = i->second;
		if(a == 0) continue;
		
		rep(j, MX) if(dp[cur][j]){
			int t = (MX - 1 - j) / a;
			if(t % 2 != b % 2) t--;
			t = min(t, b);
			if(t >= 0 && j + a * (t + 2) < MX) sum[j + a * (t + 2)]--;
			
			t = j / a;
			if(t % 2 != b % 2) t--;
			t = min(t, b);
			if(t >= 0) sum[j - a * t]++;
		}
		rep(j, 2 * a){
			int l = 0;
			for(int k = j; k < MX; k += 2 * a){
				l += sum[k];
				if(l) dp[next][k] = 1;
			}
		}
		swap(cur, next);
	}
	ll mx = 0;
	rep(i, MX) if(dp[cur][i]){
		mx = max(mx, (ll)((n + i - GETA) / 2) * ((n - i + GETA) / 2));
	}
	cout << mx - m << endl;
	return 0;
}

Measured memory_bytes: 8800
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#define rep(i,m,n) for(int i=m; i<(n); i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
typedef long long ll;
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int mi = 1000;
    int n = s.size();
    rep(i,0,n-2)
    {
        int sei = 0;
        sei += 100*(s[i]-'0');
        sei += 10*(s[i+1]-'0');
        sei += s[i+2]-'0';
        mi = min(mi, abs(sei - 753));
    }
    cout << mi << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int a[101],b[101];
    int suma[101],sumb[101];
    int main()
    {
        int n;
        while(cin>>n){
            for(int i=0;i<n;i++){
                cin>>a[i];
            }
            for(int i=0;i<n;i++){
                cin>>b[i];
            }
            suma[0]=a[0];sumb[0]=b[0];
            for(int i=1;i<n;i++){
                suma[i]=suma[i-1]+a[i];
                sumb[i]=sumb[i-1]+b[i];
            }
            int maxn=suma[0]+sumb[n-1];
            for(int i=1;i<n;i++){
                int sum=suma[i]+sumb[n-1]-sumb[i-1];
                maxn=max(maxn,sum);
            }
            cout<<maxn<<endl;
        }
        return 0;
    }

Measured memory_bytes: 256