akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

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

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

#define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

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

int n,m;
vector<pair<int,int>> edges;
int res;

vector<int> uf_par(55);
vector<int> uf_rk(55);
void uf_init(int n) {
    rep(i,n) {
        uf_par[i] = i;
        uf_rk[i] = 1;
    }
}
int uf_find(int x) {
    if (x == uf_par[x]) { return x; }
    return uf_par[x] = uf_find(uf_par[x]);
}
void uf_unite(int x, int y) {
    x = uf_find(x); y = uf_find(y);
    debug(x,y);
    if (x == y) { return; }
    if (uf_rk[x] < uf_rk[y]) {
        uf_par[x] = y;
        debug("y", x,y);
    } else {
        uf_par[y] = x;
        debug("x", x,y);
        if (uf_rk[x] == uf_rk[y]) { uf_rk[x]++; }
    }
}
bool uf_same(int x, int y) {
    return uf_find(x) == uf_find(y);
}

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    cin>>n>>m;
    rep(i,m) {
        int a,b; cin>>a>>b; a--; b--;
        edges.push_back(make_pair(a,b));
        debug(edges[i].first, edges[i].second);
    }
    debug("input");
    rep(i, m)
    {
        debug(i);
        // G \ i で連結性判定
        uf_init(n);
        rep(j, m) {
            if (i == j) { continue; }
            uf_unite(edges[j].first, edges[j].second);
        }
        bool some = false;
        rep(j, n-1) {
            debug(uf_find(j));
            some = some || !uf_same(j, j+1);
        }
        res += some;
    }
    cout<<res<<'\n';

    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long N, std::vector<long long> l, std::vector<long long> r){
    int sum = 0;
    REP(i, N)
        sum += r[i] - l[i] + 1;
    cout << sum << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> l(N);
    std::vector<long long> r(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&l[i]);
        scanf("%lld",&r[i]);
    }
    solve(N, std::move(l), std::move(r));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(){
  int i,n;
  int c = 0;
  char s[1000];
  scanf("%d%s",&n,s);
  if(n%2 == 1) printf("No");
  else {
    for(i=0;i<n/2;i++){if(s[i] == s[i+n/2]) c++;}
  	if(c == n/2) printf("Yes");
  	else printf("No");
    return 0;
  }
  }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define F first
//#define S second

typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e12;
const ll mlnf = -1e12;
const double e = 1e-10;

void debug_vector(vector<int>& v)
{
    int n = v.size();
    for (int i = 0; i < n; i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}


//////////////////////
//// coding start ////
//////////////////////

// global variety

// function
void solve();

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

void solve(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> cnt(N, 0);
    rep(i, N){
        cnt[A[i]]++;
    }
    long long ans = 0;  // ans = 2 ** m   flag = true;
    int m = N / 2;
    bool flag = true;
    if (N % 2 == 0){
        rep(i, N){
            if (i % 2 == 0){
                if (cnt[i] != 0){
                    flag = false;
                    break;
                }
            }
            else{
                if (cnt[i] != 2){
                    flag = false;
                    break;
                }
            }
        }
    }
    else{
        rep(i, N){
            if (i == 0){
                if (cnt[i] != 1){
                    flag = false;
                    break;
                }
            }
            else if (i % 2 == 1){
                if (cnt[i] != 0){
                    flag = false;
                    break;
                }
            }
            else{
                if (cnt[i] != 2){
                    flag = false;
                    break;
                }
            }
        }
    }
    if (flag){
        ans = 1;
        for (int i = 1; i <= m; i++){
            ans *= 2;
            ans %= MOD;
        }
    }
    printf("%lld\n", ans);

                       
}



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

#define ar array

int main() {
	// your code goes here
	int n;
    cin >> n;
    vector<ar<int, 3>> a(n);
    for (auto &x : a)
        cin >> x[0] >> x[1] >> x[2];
    vector<ar<int, 3>> dp(n);
    for (int i = 0; i < 3; ++i) {
        dp[0][i]  = a[0][i];
    }
    for (int i = 1; i < n; ++i) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + a[i][2];
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
	return 0;
}


Measured memory_bytes: 5576
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;
#define chmax(a, b) a=(((a)<(b))?(b):(a))
#define chmin(a, b) a=(((a)>(b))?(b):(a))
#define F first
#define S second
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const P<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

void construct_map(V<int> a, map<int,int>& m) {
   REP(i, a.size()) {
      int k = 0;
      while (a[i] > 0) {
         m[k] += (a[i] & 1);
         a[i] >>= 1; k++;
      }
   }
}

signed main()
{
   int N, K; cin >> N >> K;
   V<int> a(N);
   REP(i, N) {
      cin >> a[i];
   }
   K++;

   map<int,int> m;
   construct_map(a, m);

   int ans = -INF;
   const int M = 40;
   REP(i, M) {
      // calculate the score when X[i] = 0, K[i] = 1
      if ((K >> i & 1) == 0) continue;

      int tmp = 0;
      FOR(j, 0, i) {
         tmp += (max(N - m[j], m[j]) << j);
      }
      tmp += (m[i] << i);
      FOR(j, i+1, M) {
         tmp += ((K >> j & 1 ? N - m[j] : m[j]) << j);
      }
      chmax(ans, tmp);
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<bitset>
#include<vector>
using namespace std;
bitset<4000001>s;
int n,a;
main()
{
	cin>>n;
	s[0]=1;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		s|=s<<a;
	}
	vector<int>ans;
	for(int i=0;i<=4000000;i++)if(s[i])ans.push_back(i);
	cout<<ans[ans.size()/2]<<endl;
}


Measured memory_bytes: 11244
N,M = map(int,input().split())
H = list(map(int,input().split()))
Y = [1]*N
for i in range(M):
    a,b = map(int,input().split())
    if H[a-1] <= H[b-1]:
        Y[a-1] *= 0
    if H[a-1] >= H[b-1]:
        Y[b-1] *= 0
print(Y.count(1))

Measured memory_bytes: 20108
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n, a[3005];
int dp[3005][3005][2];

int rec(int l, int r, bool dep) {
	if(l == r) {
		if(dep) return -a[l];
		return a[l];
	}
	int &ans = dp[l][r][dep];
	if(ans != -inf) return ans;
	if(dep == 0) {
		ans = max(rec(l + 1, r, 1) + a[l], rec(l, r - 1, 1) + a[r]);
	}
	else {
		ans = min(rec(l + 1, r, 0) - a[l], rec(l, r - 1, 0) - a[r]);
	}
	return ans;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    cin>>n;
    f(i, n) cin>>a[i];
    f(i, n + 2) {
    	f(j, n + 2) dp[i][j][0] = dp[i][j][1] = -inf;
    }
    cout<<rec(0, n - 1, 0);
    return 0;
}

Measured memory_bytes: 141440
#C++のコードを移植
def Expected_value(n):
    return n + 1

n,k = map(int, input().split())
a = input().split()
sm = 0
mx = 0
for i in range(n):
    if i <= k-1:
        sm += Expected_value(int(a[i]))
        mx = sm
    else:
        sm = sm + Expected_value(int(a[i])) - Expected_value(int(a[i-k]))
        mx = max(mx,sm)

print(mx/2)





Measured memory_bytes: 72048
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
#define space " "
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
vector<int>vec[100005];
int vis[100005];
void dfs(int src)
{
    if(vis[src])
        return;
    vis[src]=1;
    for(int j=0;j<vec[src].size();j++)
    {
        int v=vec[src][j];
        if(vis[v]==0)
            dfs(v);
    }
}
main()
{
    timesave;
    int n,m,i,u,v,cnt=0;
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>u>>v;
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    for(i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            dfs(i);
            cnt++;
        }
    }
    cout<<cnt-1<<endl;
}



Measured memory_bytes: 9980
#include <stdio.h>

int isRT(int a,int b,int c)
{
	int a2 = a*a;
	int b2 = b*b;
	int c2 = c*c;
	if(a2 == (b2+c2) || b2 == (c2+a2) || c2 == (a2+b2))
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main()
{
	int n;
	int i;
	scanf("%d",&n);
	for (i = 0; i < n; i += 1)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		printf("%s\n",isRT(a,b,c)?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
struct Point
{
	long long x,y;
	int num;
	Point () {}
	Point (long long x,long long y,int num):x(x),y(y),num(num) {}
}p[101010],p1[101010],p2[101010];
bool vis[101010];
bool cmpx(const Point &px,const Point &py)
{
	if(px.x!=py.x)
		return px.x<py.x;
	return px.y<py.y;
}
bool cmpy(const Point &px,const Point &py)
{
	if(px.y!=py.y)
		return px.y<py.y;
	return px.x<py.x;
}
int rt1[101010],rt2[101010];
int getr(int *rt,int x)
{
	if(x==rt[x])
		return x;
	rt[x]=getr(rt,rt[x]);
	return rt[x];
}
int n;
queue <int> q;
int findx1(long long x,long long y)
{
	int l=0,r=n+1,mid;
	while(l<r)
	{
		mid=(l+r)>>1;
		if(p1[mid].x>x||(p1[mid].x==x&&p1[mid].y>=y))
			r=mid;
		else
			l=mid+1;
	}
	return l;
}
int findx2(long long x,long long y)
{
	int l=0,r=n+1,mid;
	while(l<r)
	{
		mid=(l+r+1)>>1;
		if(p1[mid].x<x||(p1[mid].x==x&&p1[mid].y<=y))
			l=mid;
		else
			r=mid-1;
	}
	return l;
}
int findy1(long long x,long long y)
{
	int l=0,r=n+1,mid;
	while(l<r)
	{
		mid=(l+r)>>1;
		if(p2[mid].y>y||(p2[mid].y==y&&p2[mid].x>=x))
			r=mid;
		else
			l=mid+1;
	}
	return l;
}
int findy2(long long x,long long y)
{
	int l=0,r=n+1,mid;
	while(l<r)
	{
		mid=(l+r+1)>>1;
		if(p2[mid].y<y||(p2[mid].y==y&&p2[mid].x<=x))
			l=mid;
		else
			r=mid-1;
	}
	return l;
}
long long ans=0;
void work1(int l,int r)
{
	if(l>r)
		return ;
	ans+=r-l+1;
	int now=getr(rt1,l);
	while(now<=r)
	{
		if(!vis[p1[now].num])
		{
			q.push(p1[now].num);
			vis[p1[now].num]=true;
		}
		rt1[now]=getr(rt1,now+1);
		now=getr(rt1,now);
	}
}
void work2(int l,int r)
{
	if(l>r)
		return ;
	ans+=r-l+1;
	int now=getr(rt2,l);
	while(now<=r)
	{
		if(!vis[p2[now].num])
		{
			q.push(p2[now].num);
			vis[p2[now].num]=true;
		}
		rt2[now]=getr(rt2,now+1);
		now=getr(rt2,now);
	}
}
int main()
{
	int a,b,xx,yy,d,now;
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&xx,&yy);
		p[i]=Point(xx-yy,xx+yy,i);
		p1[i]=p2[i]=p[i];
	}
	d=max(abs(p[a].x-p[b].x),abs(p[a].y-p[b].y));
	sort(p1+1,p1+1+n,cmpx);
	sort(p2+1,p2+1+n,cmpy);
	memset(vis,0,sizeof(vis));
	q.push(a);
	q.push(b);
	vis[a]=true;
	vis[b]=true;
	for(int i=1;i<=n+1;i++)
		rt1[i]=rt2[i]=i;
	p1[0]=Point(-101010101010ll,-101010101010ll,0);
	p2[0]=Point(-101010101010ll,-101010101010ll,0);
	p1[n+1]=Point(101010101010ll,101010101010ll,0);
	p2[n+1]=Point(101010101010ll,101010101010ll,0);
	while(!q.empty())
	{
		now=q.front();
		q.pop();
		work1(findx1(p[now].x-d,p[now].y-d),findx2(p[now].x-d,p[now].y+d));
		work1(findx1(p[now].x+d,p[now].y-d),findx2(p[now].x+d,p[now].y+d));
		work2(findy1(p[now].x-d+1,p[now].y-d),findy2(p[now].x+d-1,p[now].y-d));
		work2(findy1(p[now].x-d+1,p[now].y+d),findy2(p[now].x+d-1,p[now].y+d));
	}
	printf("%lld",ans/2);
	return 0;
}

Measured memory_bytes: 9344
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    boolean flg = true;

    while(flg) {
      int x = sc.nextInt();
      int y = sc.nextInt();

      if (x <= 0 && y <= 0) {
        System.exit(0);
      }

      if (x > y) {
        System.out.println(y + " " + x);
      } else if (x < y) {
        System.out.println(x + " " + y);
      } else {
        System.out.println(x + " " + y);
      }
    }
    sc.close();

  }
}


Measured memory_bytes: 35948
#include<iostream>
using namespace std;
#define MAX 100000
#define NIL -1

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

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

void print(int u){
    int i,c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if(T[u].p==NIL) cout << "root, ";
    else if(T[u].l==NIL) cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    
    for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

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

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


Measured memory_bytes: 7804
package main

import (
	"fmt"
)

func solution(n int, s string) int {
	var ans int
	for i := 0; i < n-2; i++ {
		if s[i:i+3] == "ABC" {
			ans++
		}
	}
	return ans
}

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	fmt.Println(solution(n, s))
}


Measured memory_bytes: 512
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s,t;
	cin>>s>>t;
	vi used(256);
	bool h=true;
	rep(i,s.size())if(s[i]!=t[i]){
		if(used[t[i]]){h=false;break;}
		used[t[i]]=1;
		char a=s[i],b=t[i];
		rep(j,s.size())if(s[j]==a)s[j]=b;
		else if(s[j]==b)s[j]=a;
	}
	if(s==t&&h)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}







Measured memory_bytes: 776
package main

import "fmt"

func main() {
  var s string
  start := -1
  end := -1

  fmt.Scan(&s)
  for i, _ := range s {
    if s[i:i+1] == "A" && start == -1 {
      start = i
    }
    if s[i:i+1] == "Z" {
      end = i
    }
  }
  fmt.Println(end-start+1)
}

Measured memory_bytes: 1920
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

const int MAX = 100 * 11;
bool visited[MAX];
vector<vector<int> > es;
map<string, int> conv;

inline int convert(const string& s) {
	if(!conv.count(s))
		conv.insert(make_pair(s, conv.size()));

	return conv[s];
}

inline int dfs(int idx) {
	visited[idx] = true;
	if(es[idx].size() == 0)
		return 1;

	int res = 0;
	for(int i = 0; i < (int)es[idx].size(); ++i)
		if(!visited[es[idx][i]])
			res += dfs(es[idx][i]);

	return res;
}

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

	for(int n; cin >> n, n;) {
		cin.ignore();
		conv.clear();
		es.clear();
		es.resize(MAX);
		for(int i = 0; i < n; ++i) {
			string line;
			getline(cin, line);

			int pos = line.find(':');
			const int group_id = convert(line.substr(0, pos));
			line = line.substr(pos + 1);

			while((pos = line.find(',')) != string::npos) {
				const int idx = convert(line.substr(0, pos));
				es[group_id].push_back(idx);
				line = line.substr(pos + 1);
			}

			const int idx = convert(line.substr(0, (int)line.size() - 1));
			es[group_id].push_back(idx);
		}

		memset(visited, false, sizeof(visited));
		cout << dfs(0) << endl;
	}

	return EXIT_SUCCESS;
}

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

map<int, int> dp;
map<int, int>::iterator its;

int main(){
    int n, a;
    scanf("%d", &n);   
    for(int i=1;i<=n;i++){
        scanf("%d", &a);
        dp[a]++;
    }
    if(dp.size() == 1 && dp.begin()->first == 0){
        printf("Yes\n");
        return 0;
    }
    if(n%3 != 0){
        printf("No\n");
        return 0;
    }
    int mx = 0, mn = 1e9;
    vector<int> v;
    for(its = dp.begin();its != dp.end();its++){
        v.push_back(its->first);
        mx = max(mx, its->second);
        mn = min(mn, its->second);
    }
    if(v.size() == 1){
        if(v[0] == 0) printf("Yes\n");
        else printf("No\n");
    }
    else if(v.size() == 2){
        if(mn*2 != mx) printf("No\n");
        else{
            if((v[0]^v[0]) == v[1]) printf("Yes\n");
            else if((v[1]^v[1]) == v[0]) printf("Yes\n");
            else printf("No\n");
        }
    }
    else if(v.size() == 3){
        if((v[0]^v[1]) != v[2] || n/3 != mx){
            printf("No\n");
        }
        else{
            printf("Yes\n");
        }
    }
    else{
        printf("No\n");
    }
}

Measured memory_bytes: 4480
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		vi a(n);
		rep(i,n)
			cin>>a[i];
		int res=32;
		for(int i=0;res;i++){
			int n1=(res-1)%5;
			res-=n1;
			cout<<res<<endl;
			int n2=min(res,a[i%a.size()]);
			res-=n2;
			cout<<res<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    public static void main(String[] arg) {
        Scanner scan = new Scanner(System.in);
        long h = Long.parseLong(scan.next());
        long num = 1;
        long count = 0;
        while (h > 0) {
            h = h/2;
            count = count + num;
            num *= 2;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23252
//Vacation

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define fi first
#define se second
template<class T>inline bool chmin(T& a,T b,bool f){
    if(f==1){if(a>b){a=b;return true;}return false;}
    else if(f==0){if(a<b){a=b;return true;}return false;}return false;
}
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int n;cin>>n;
    int v[n][3],dp[n+1][3];
    rep(i,0,n)rep(j,0,3)cin>>v[i][j];
    dp[0][0]=dp[0][1]=dp[0][2]=0;
    rep(i,1,n+1){
        dp[i][0]=max(dp[i-1][1]+v[i-1][0],dp[i-1][2]+v[i-1][0]);
        dp[i][1]=max(dp[i-1][0]+v[i-1][1],dp[i-1][2]+v[i-1][1]);
        dp[i][2]=max(dp[i-1][0]+v[i-1][2],dp[i-1][1]+v[i-1][2]);
    }
    cout << max(dp[n][0],max(dp[n][1],dp[n][2]))<< nnn;
    return 0;
}

Measured memory_bytes: 2560
N = int(input())
s = input()

d = {'S':'W','W':'S'}

def make(s1,s2):
    a = [s1,s2]
    for i in range(N):
        s1,s2 = a[-2:]
        if s2 == 'S':
            if s[i] == 'o':
                s0 = s1
            else:
                s0 = d[s1]
        else:
            if s[i] == 'o':
                s0 = d[s1]
            else:
                s0 = s1
        a.append(s0)
    return a

for s1 in ['S','W']:
    for s2 in ['S','W']:
        a = make(s1,s2)
        possible = a[:2]==a[-2:]
        if possible:
            break
    if possible:
        break

if possible:
    print(''.join(a[1:N+1]))
else:
    print(-1)

Measured memory_bytes: 4948
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = i()
A = []
for j in range(N):
    a = i()
    A.append(a)

A.sort()
b = N // 2
if N % 2 == 0:
    ans = 2*sum(A[b:])-2*sum(A[:b])
    ans += A[b-1]-A[b]
else:
    ans = 2*sum(A[b+1:])-2*sum(A[:b])
    ans += max(A[b]-A[b+1],-A[b]+A[b-1])

print(ans)


Measured memory_bytes: 14352
N = int(input())
lis = list(map(int, input().split()))

cnt = 0
while True:
  li_yojo = [a % 2 for a in lis]
  if li_yojo.count(0) != N:
    break
  else:
    lis = [ a / 2 for a in lis ]
    cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n, k;
  cin >> n >> k;
  vector <int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = k; i < n; ++i) {
    int j = i - k;
    if (a[i] > a[j]) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  }
}



Measured memory_bytes: 3964
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      int n;
      cin >> n;
      pair<ll,ll> a[n],b[n];
      rep(i,n)cin >> a[i].first >> b[i].first;
      rep(i,n){
        a[i].second=i;
        b[i].second=i;
      }
      pair<ll,int> c[n];
      rep(i,n){
        c[i].first=a[i].first+b[i].first;
        c[i].second=i;
      }
      sort(c,c+n);
      reverse(c,c+n);
      ll ans=0;
      rep(i,n){
        if(i%2==0){
         ans+=a[c[i].second].first; 
        }
        else ans-=b[c[i].second].first;
      }
      cout << ans << endl;
      return 0;}

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

int main() {
  int n;
  cin >> n;
  int h[n];
  for ( int i = 0; i < n; i++ ) { cin >> h[i]; }
  string ans = "Yes";
  if ( n != 1 ) {
    h[0]--;
    for ( int i = 1; i < n; i++ ) {
      if ( h[i]-1 >= h[i-1] ) { h[i]--; }
      if ( h[i] < h[i-1] ) { ans = "No"; break; }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
def c_many_medians(N, X):
    # 解説どおり
    Y = sorted(X)
    ans = ['' for _ in range(N)]
    pos = N // 2
    for k, xi in enumerate(X):
        if xi < Y[pos]:
            ans[k] = str(Y[pos])
        else:
            ans[k] = str(Y[pos - 1])
    return '\n'.join(ans)

N = int(input())
X = [int(i) for i in input().split()]
print(c_many_medians(N, X))

Measured memory_bytes: 30292
h, w, k = map(int, input().split())

board = [list(input()) for _ in range(h)]

ans = 0

for point_h in range(2**h):
    for point_w in range(2**w):
        cnt=0
        for i in range(h):
            for j in range(w):
                if (point_h>>i)&1==0 and (point_w>>j)&1==0:
                    if board[i][j]=="#":
                        cnt+=1
        if k==cnt:
            ans+=1

print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<int> data(N);
    vector<int> mt(N, 0);
    REP(i, N)
    {
        cin >> data.at(i);
    }

    int mt1 = 0;
    REP(i, N)
    {
        if (i % 2 == 0)
        {
            mt1 += data.at(i);
        }
        else
        {
            mt1 -= data.at(i);
        }
    }
    mt.at(0) = mt1;
    mt.at(N - 1) = 2 * data.at(N - 1) - mt.at(0);
    for (int i = N - 2; 0 < i; i--)
    {
        mt.at(i) = 2 * data.at(i) - mt.at(i + 1);
    }

    REP(i, N)
    {
        cout << mt.at(i) << ' ';
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
bool is_integer( double x ){
  return floor(x)==x;
}
int main(){
  ll l,r; cin >> l >> r;
  
  if(r-l >= 2019){
    cout << 0 << endl;
  }else{
    ll ans = 1LL << 60;
    for(ll i = l; i < r;i++){
      for(ll j = l+1; j <= r;j++){
        chmin(ans, (i*j)%2019);
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//const ll mod=1000000007;
int GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
 ll n,m;
 cin>>n>>m;
   for(int i=0;i<m;i++){
      cout<<i+2<<" "<<n-i-(n%2==0&&(n/2+1)/2<=i+1)<<"\n";
   }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define READ freopen("in.txt", "r", stdin)
#define WRITE freopen("out.txt", "w", stdout)
#define sz size()
#define number_of_digit(n) __builtin_ffs(n);
#define ll long long
#define T int
#define ld long double
inline void print(T n)
{
  if (n == 0)
  {
    putchar('0');
    putchar('\n');
  }
  else if (n == -1)
  {
    putchar('-');
    putchar('1');
    putchar('\n');
  }
  else
  {
    char buf[11];
    buf[10] = '\n';
    int i = 9;
    while (n)
    {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n')
      putchar(buf[++i]);
  }
}
int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int ret = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          ret = ret * 10 + cc - '0';
          cc = getc(stdin);
       }
      return ret;
}
ll power(ll num,ll g)
{
  if(g==0)return 1;

  if(g%2==1)return (num*power((num*num),g/2));
  return power((num*num),g/2);
}
ll a[100005];
ll find(ll index)
{
  if(a[index]==index)return index;
  return a[index]=find(a[index]);
}
int main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n,m;
  cin>>n>>m;
  pair<ll,ll> pa[m];
  For(i,m)
  {
    cin>>pa[i].ff>>pa[i].ss;
  }
  
  For(i,n+1)a[i]=i;
  ll size[n+1];
  For(i,n+1)size[i]=1;
  ll ans=n;
  ans*=n-1;
  ans/=2;
  stack<ll> st;
  for(ll i=m-1;i>=0;i--)
  {
    st.push(ans);
    ll u=find(pa[i].ff);
    ll v=find(pa[i].ss);
    if(u==v)
    {
      //st.push(ans);
    }
    else
    {
      a[u]=a[v];
      ans-=size[v]*size[u];
      size[v]+=size[u];
      //st.push(ans);
    }
  }
  while(!st.empty())
  {
    cout<<st.top()<<endl;
    st.pop();
  }
  return 0;
}

Measured memory_bytes: 5020
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0,T a=0):n(n_),bit(n_+1,a){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
};
int N;
long X,b[1<<17],l[1<<17],u[1<<17];
long sumb,sumL;
main()
{
	cin>>N>>X;
	vector<pair<long,int> >A;
	for(int i=0;i<N;i++)
	{
		cin>>b[i]>>l[i]>>u[i];
		sumb+=b[i];
		sumL-=b[i]*l[i];
		A.push_back(make_pair((X-b[i])*u[i]+b[i]*l[i],i));
	}
	sort(A.begin(),A.end());
	reverse(A.begin(),A.end());
	BIT<long>P(N);
	for(int i=0;i<N;i++)
	{
		P.add(i+1,A[i].first);
	}
	long L=-1,R=sumb;
	while(R-L>1)
	{
		long M=(L+R)/2;
		bool flag=0;
		for(int i=0;!flag&&i<N;i++)
		{
			long tmp=P.sum(i+1)-P.sum(i);
			P.add(i+1,-tmp);
			int id=A[i].second;
			long nowsum=sumL+max(M%X*l[id],M%X*u[id]-b[id]*(u[id]-l[id]));
			nowsum+=P.sum(M/X+(M/X>i));
			flag|=nowsum>=0;
			P.add(i+1,tmp);
		}
		if(flag)R=M;
		else L=M;
	}
	cout<<R<<endl;
}


Measured memory_bytes: 4976
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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


int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b){
        swap(a, b);
    }
    if(a % 2 == b % 2){
        cout << (b - a) / 2 << endl;
    }
    else{
        ll res1 = a + (b - a - 1) / 2;
        ll res2 = (n - b + 1) + (b - a - 1) / 2;
        cout << min(res1, res2) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// AtCoder abc152-B

#include <cstdio>
#include <vector>

int main() {
  unsigned int n;

  std::scanf("%u", &n);

  unsigned int *c = new unsigned int[n];
  unsigned int *v = new unsigned int[n];

  for (unsigned int i = 0; i < n; i++) {
    unsigned int value;
    std::scanf("%u", &value);
    c[i] = value;
  }

  for (unsigned int i = 0; i < n; i++) {
    unsigned int value;
    std::scanf("%u", &value);
    v[i] = value;
  }

  unsigned int sum = 0;

  for (unsigned int i = 0; i < n; i++)
    if (c[i] > v[i])
      sum += c[i] - v[i];

  std::printf("%u\n", sum);

  return 0;
}


Measured memory_bytes: 256
from math import ceil

n = int(input())
s = [tuple(map(int, input().split())) for _ in range(n-1)]
s.append((0, 0, 0))

for i in range(n):
    sec = s[i][0] + s[i][1]
    for j in range(i+1, n-1):
        if sec < s[j][1]: sec = s[j][1]
        else: sec = s[j][2] * ceil(sec / s[j][2])
        sec += s[j][0]
    print(sec)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int A,B,N,sum ;
  cin >> A >> B ;
  sum=0;
  N=B-A+1;
  rep(i,N){
    if((A+i)/10000==(A+i)%10&&(A+i)%10000/1000==(A+i)%100/10){
      sum++;
    }
       
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int ans = (int) (a + Math.pow(a, 2) + Math.pow(a, 3));
		System.out.println(ans);
		sc.close();
	}

}

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

int main() {
  std::vector<int> a;
  int n,k,i;
  int ans = 0;
  scanf("%d %d", &n,&k);
  while ((k - 1)*ans < n-1) {
    ans++;
  }
  std::cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    string s;
    while(cin >> s, s != "."){
        string ans  = "";
        stack<int> st;
        int tmp = 0;
        rep(i,s.size()){
            if(s[i] >= 'A' && s[i] <= 'Z'){
                ans += 'A' + (s[i] - 'A' + 260 + tmp)%26;
                tmp = 0;
            }else if(s[i] == '['){
                st.push(ans.size());
            }else if(s[i] == ']'){
                string t = ans.substr(st.top());
                reverse(all(t));
                ans = ans.substr(0,st.top()) + t;
                st.pop();
            }else if(s[i] == '+'){
                tmp++;
            }else if(s[i] == '-'){
                tmp--;
            }else if(s[i] == '?'){
                ans += 'A';
                tmp = 0;
            }
            //cout << i << " " << s[i]<< " "  << ans << endl;
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3204
#include<iostream>

using namespace std;

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  if (b <= a){
    cout << "delicious" << endl;
  }
  else if(b - a <= x){
    cout << "safe" << endl;
  }
  else{
    cout << "dangerous" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
const ll MOD=998244353;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;

int main(){
    int n;cin>>n;
    vector<ll> A(n),B(n),C(n);
    for(int i=0;i<n;i++){
        cin>>A[i];
        B[i]=i+1+A[i];
        C[i]=i+1-A[i];
    }
    sort(C.begin(),C.end());
    C.push_back(INF);
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=(ll)(upper_bound(C.begin(),C.end(),B[i])-lower_bound(C.begin(),C.end(),B[i]));
    }
    cout<<ans<<endl;
    return 0;
}

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

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

struct edge {
  int i, j, w;
};

int main() {
  int n, m;

  cin >> n >> m;

  vector< vector<int> > d(n, vector<int>(n, 1001));

  vector<edge> es(m);

  rep(i, m) {
    cin >> es[i].i >> es[i].j >> es[i].w;
  }


  for (auto ee = es.begin(); ee != es.end(); ee++) {
    edge e = *ee;

    d[e.i - 1][e.j - 1] = e.w;
    d[e.j - 1][e.i - 1] = e.w;
  }

  rep(k, n) {
    rep(i, n) {
      rep(j, n) {
        int l = d[i][k] + d[k][j];
        if (d[i][j] > l) {
          d[i][j] = l;
        }
      }
    }
  }


  int c = 0;

  for (auto ee = es.begin(); ee != es.end(); ee++) {
    edge e = *ee;
    if (d[e.i - 1][e.j - 1] < e.w) {
      c++;
    }
  }

  cout << c << endl;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string s;
  cin>>s;
  int N=s.size();
  for(int i=0;i<N;i++){
    for(int j=0;j+i<N;j++){
      string ss=s;
      ss.erase(i,j);
      if(ss=="keyence"){
        cout<<"YES"<<endl;
        return 0;
      }
    }
  }
  cout<<"NO"<<endl;
  return 0;
}


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

int main() {
  int N;
  std::cin >> N;
  
  std::vector<int> A, B, C;
  
  for (int i=0, temp; i<N; ++i) {
    std::cin >> temp;
    A.push_back(temp);
  }
  for (int i=0, temp; i<N; ++i) {
    std::cin >> temp;
    B.push_back(temp);
  }
  for (int i=0, temp; i<N-1; ++i) {
    std::cin >> temp;
    C.push_back(temp);
  }
  
  int res = 0;
  for (int i=0; i<N; ++i) {
    res += B[A[i]-1];
    if (i > 0 && A[i] != 0 && A[i-1] + 1 == A[i])
      res += C[A[i-1]-1];
  }
  
  std::cout << res << std::endl;
}

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

#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define ll long long
const int MAXV = 1000;

void smin(ll &a,ll b){
	a = min(a,b);
}
void smax(ll &a,ll b){
	a = max(a,b);
}
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, W;
	cin >> n >> W;
	vector<ll> val(n),weight(n);
	for(int i=0;i<n;i++)
		cin >> weight[i] >> val[i];
	ll sum = 0;
	for(int x: val)
		sum+=x;
	vector<ll> dp (sum + 1,inf);
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int value= sum-val[i];value>=0;value--){
			smin(dp[value+val[i]],dp[value]+weight[i]);
		}
	}
	
	ll ans = 0;
	for(int i = 0;i<=sum;i++){
		if(dp[i]<=W)
			smax(ans,i);
	}
	cout << ans << '\n';
	
	
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m; cin >> n >> m;
    vector<unsigned long long> fibo(n + 1, 1);
    for (int i = 0; i < n - 1; i++) {
        fibo.at(i + 2) = fibo.at(i) + fibo.at(i + 1);
        fibo.at(i + 2) %= (int)1e+9 + 7;
    }
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (m == 0) {
        cout << fibo.at(n) << endl;
        return 0;
    }
    vector<int> a(m + 2);
    a.at(0) = -1;
    a.at(m + 1) = n + 1;
    for (int i = 1; i <= m; i++) {
        cin >> a.at(i);
    }
    
    // 2個以上連続で壊れている時
    for (int i = 1; i <= m - 1; i++) {
        if (a.at(i + 1) == a.at(i) + 1) {
            cout << 0 << endl;
            return 0;
        }
    }
    
    unsigned long long ans = 1;
    for (int i = 0; i < m + 1; i++) {
        int len = a.at(i + 1) - a.at(i) - 2;
        ans *= fibo.at(len);
        ans %= (int)1e+9 + 7;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1408