akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
struct edge{
	int v,u,f,d;
	inline edge(){}
	inline edge(int v,int u,int f,int d):v(v),u(u),f(f),d(d){}
}E[N*N];
int dd[N*N];
vector<int>e[N];
int dg[N],d[N],fa[N],de[N],vi[N],cnt[N],ans,nn;
void dfs(int v,int f){
	int s=e[v].size(),i=0,u,d=de[v]+1;
	for(;i!=s;++i){
		if((u=e[v][i])!=f){
			de[u]=d;
			dfs(u,fa[u]=v);
		}
	}
}
int dfs2(int v,int f){
	int s=e[v].size(),i=0,u,dd=d[v];
	for(;i!=s;++i){
		if((u=e[v][i])!=f){
			dd+=dfs2(u,v);
		}
	}
	if(dd){if(dd==1)++ans;else ans+=2;}
	return dd;
}
inline int lca(int v,int u){
	if(de[v]<de[u])swap(v,u);
	while(de[v]!=de[u])v=fa[v];
	while(v!=u){
		v=fa[v];
		u=fa[u];
	}
	return v;
}
inline void work(int a,int b,int v,int u){
//	printf("work %d %d %d %d\n",a,b,v,u);
	int i;
	for(i=2;i<=nn;++i)cnt[i]=0;
	if(de[a]<de[b])swap(a,b);
	while(de[a]!=de[b]){
		cnt[a] =1;a=fa[a];
	}
	while(a!=b){
		cnt[a] =1;a=fa[a];
		cnt[b] =1;b=fa[b];
	}
	if(de[v]<de[u])swap(v,u);
	while(de[v]!=de[u]){
		cnt[v]|=2;v=fa[v];
	}
	while(v!=u){
		cnt[v]|=2;v=fa[v];
		cnt[u]|=2;u=fa[u];
	}
//	for(i=2;i<=nn;++i)if(cnt[i]==3)printf("VI %d\n",i);
	for(i=2;i<=nn;++i)if(cnt[i]==3)vi[i]=1;
}
int main(){
	int n,m,t,td,p,l,v,u,i;
	scanf("%d%d",&n,&m);t=td=m;nn=n;
	for(i=1;i!=n;++i){
		scanf("%d%d",&v,&u);
		++dg[v];++dg[u];
		e[v].push_back(u);
		e[u].push_back(v);
	}
	dfs(1,0);
	for(i=1;i<=m;++i){
		scanf("%d%d",&v,&u);
		E[i].v=v;
		E[i].u=u;
		E[i].d=i;
		l=lca(v,u);
		++d[v];
		++d[u];
		d[l]-=2;
	}
	dfs2(1,0);
	printf("%d",ans);
	l=n;
	while(--l){
		for(v=1;v<=n;++v){
			if(dg[v]==1){
				break;
			}
		}
		p=e[v].size();
		for(i=0;i!=p;++i)if(dg[u=e[v][i]])break;
//		printf("\n===\nv=%d u=%d son=%d\n",v,u,(fa[v]==u)?v:u);
		--dg[v];
		--dg[u];
		p=0;
		for(i=1;i<=m;++i){
			if(E[i].v){
				if(E[i].u==v){E[i].u=E[i].v;E[i].v=v;}
				if(E[i].v==v)d[++p]=i;
			}
		}
//		printf("edge vi=%d\np=%d\n",vi[(fa[v]==u)?v:u],p);
		i=1;
		if(!vi[(fa[v]==u)?v:u]&&p>=2){
			i=3;
			work(v,E[d[1]].u,v,E[d[2]].u);
			if(E[d[1]].u==E[d[2]].u){
//				puts("qwq");
				E[d[1]].v=E[d[1]].u;
				E[d[1]].u=v;
				E[++t]=E[d[1]];E[t].f=0;
				E[++t]=E[d[2]];E[t].f=0;
				E[d[1]].v=E[d[2]].v=0;
			}else{
				E[++t]=E[d[1]];E[t].f=++td;
				E[++t]=E[d[2]];E[t].f=  td;
				E[d[1]]=edge(E[t-1].u,E[t].u,0,td);
				E[d[2]].v=0;
			}
		}
		for(;i<=p;++i){
//			printf("add %d\n",i);
			E[++t]=E[d[i]];
			if(u==E[t].u){
				E[t].f=0;
				E[d[i]].v=0;
			}else{
				E[t].f=++td;
				E[d[i]]=edge(u,E[t].u,0,td);
			}
		}
/*		for(i=1;i<=m;++i){
			printf("%d %d %d %d\n",E[i].v,E[i].u,E[i].f,E[i].d);
		}*/
	}
	for(i=1;i<=t;++i){
		if(E[i].v){
			dd[E[i].d]=i;
		}
	}
	for(i=1;i<=t;++i){
		E[i].f=dd[E[i].f];
	}/*
	for(i=1;i<=t;++i){
		printf("%d %d %d %d\n",E[i].v,E[i].u,E[i].f,E[i].d);
	}
	for(i=1;i<=m;++i){
		printf("%d ",dd[i]);
	}
	printf("\n");*/
	for(l=1;l<=m;++l){
		p=0;
		for(i=dd[l];i;i=E[i].f)d[++p]=i;
//		for(i=1;i<=p;++i)printf("(%d,%d) ",E[d[i]].v,E[d[i]].u);
		while(p--){
			if(E[d[p]].u==E[d[p+1]].v){
				swap(E[d[p]].v,E[d[p]].u);
			}
		}
		printf("\n%d %d",E[d[1]].v,E[d[1]].u);
	}
	return 0;
}

Measured memory_bytes: 27008
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int lli;
#define optimize ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define forab(i,a,b) for(int i = a; i<b; i++)
#define forll(i,a,b) for(lli i = a; i<b; i++)
#define mp make_pair
#define pb push_back
#define sortv(v) sort(v.begin(), v.end())
#define mod1 1000000007
#define mod2 998244353
#define debug(x) cout<<#x<<" : "<<x<<endl

int n,m,x;
int ans = 1e9;


void solve(vector<vector<int>>a, vector<int>M, int tcost, int ind, int taken, vector<int>cost)
{
	if(ind >=n)
		return;
	int ch =1;
	if(taken)
	{
		forab(i,0,m)
			M[i] += a[ind][i];
		tcost+=cost[ind];
	}
	forab(i,0,m)
	{
		if(M[i]<x)
		{
			ch = 0;
			break;
		}
	}
	if(ch && tcost<ans)
		ans = tcost;

	vector<int>M2(m);
	forab(i,0,m)
		M2[i] = M[i];

	int ind2 = ind;
	int tcost2 = tcost;
	
	solve(a, M, tcost, ++ind, 0, cost);
	solve(a, M2, tcost2, ++ind2, 1, cost);

}

int main()
{
	optimize

	cin>>n>>m>>x;

	vector<vector<int>>a(n, vector<int>(m));
	vector<int>cost(n);
	forab(i,0,n)
	{
		cin>>cost[i];
		forab(j,0,m)
			cin>>a[i][j];
	}

	vector<int>M1(m,0);
	vector<int>M2(m,0);
	solve(a,M1, 0, 0, 0, cost);
	solve(a,M2, 0, 0, 1, cost);

	if(ans == 1e9)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i=0;i<n;i++) cin >> x[i];
    sort(x.begin(),x.end());
    int ans = 1e9;
    for (int i=x[0];i<=x[n-1];i++) {
        int tans = 0;
        for (int j=0;j<n;j++) tans+=(x[j]-i) * (x[j]-i);
        ans = min(ans,tans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int w,h,n;cin >> w >> h >> n;
	int xr=w,xl=0,yu=h,yl=0;
	rep(i,n){
		int x,y,a;
		cin >> x >> y >> a;
		if(a==1) xl=max(xl,x);
		if(a==2) xr=min(xr,x);
		if(a==3) yl=max(yl,y);
		if(a==4) yu=min(yu,y);
	}
	if(xr<=xl || yu<=yl) cout << 0 << endl;
	else cout << (xr-xl)*(yu-yl) << endl;
}

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

int main(){
  while(1){
    int sum = 0;
    for(int i = 0; i < 5; i++){
      int x;
      if(!(cin >> x)) return 0;
      sum += (x >= 40 ? x : 40);
    }
    cout << sum / 5 << endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
typedef long long ll;
int ceil(int a,int b){// a以上でｂの倍数の最小値を出力//
    return (a+b-1)/b*b;
}
int stoii(string s){ //stoi関数の代用//
    return atoi(s.c_str());
}
int main(void){
   int n;
   string s;
   cin>>n>>s;
   int ci=0,cd=0;
   int sum=0;
   int max=0;
   rep(i,n){
       if(s[i]=='I') {
           sum++;
           if(max<=sum) max=sum;
       }    
       else sum--;
   }
   cout<<max<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
int main()
{
	int N, a=0, b=0;
	cin>>N;
	vector<int>v(N);
	for(int i=0;i<N;++i)cin>>v[i];
	sort(v.begin(),v.end());
	if(N % 2 == 0){
		for(int i=0;i<N/2;++i){
			a+=v[2*i+1];
		}
		for(int i=0;i<N/2;++i){
			b+=v[2*i];
		}
	}
	else {
		for(int i=0;i<N/2+1;++i){
			a+=v[2*i];
		}
		for(int i=0;i<N/2;++i){
			b+=v[2*i+1];
		}
	}
	cout<<a-b<<endl;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

L = [0] * (N+1)
R = [0] * (N+1)
for i in range(1, N+1):
    L[i] = gcd(L[i-1], A[i-1])
    R[-i-1] = gcd(R[-i], A[-i])
M = [gcd(L[i], R[i+1]) for i in range(N)] 

print(max(M))

Measured memory_bytes: 16144
def main():
    S = input()
    first = S[:2]
    second = S[2:]
    YYMM = False
    MMYY = False

    if "00" <= first <= "99" and "01" <= second <= "12":
        YYMM = True
    if "01" <= first <= "12" and "00" <= second <= "99":
        MMYY = True

    if YYMM and MMYY:
        ans = "AMBIGUOUS"
    elif YYMM:
        ans = "YYMM"
    elif MMYY:
        ans = "MMYY"
    else:
        ans = "NA"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61496
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  string S;
  ll K;
  while (cin >> S >> K) {
    --K;
    int p = -1;
    for (int i = 0; i < S.size(); i++) {
      if (S[i] != '1') {
        p = i;
        break;
      }
    }
    if (p == -1) {
      cout << 1 << endl;
      continue;
    }
    if (K < p) {
      cout << 1 << endl;
    } else {
      cout << S[p] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N;

  std::cin >> N;

  std::vector<long long> x(N), y(N);

  for (int i = 0; i < N; i ++)
    std::cin >> x[i] >> y[i];

  std::vector<std::vector<std::pair<int, int>>> G(N);

  std::vector<int> indices(N);

  std::iota(ALL(indices), 0);

  std::sort(ALL(indices), [&x](int a, int b) {
      return x[a] < x[b];
    });

  for (int i = 0; i < N; i ++) {
    int index = indices[i];
    
    if (i > 0) {
      int index2 = indices[i - 1];
      
      G[index].emplace_back(index2, x[index] - x[index2]);
    }
    
    if (i < N - 1) {
      int index2 = indices[i + 1];
      
      G[index].emplace_back(index2, x[index2] - x[index]);
    }
  }

  std::sort(ALL(indices), [&y](int a, int b) {
      return y[a] < y[b];
    });

  for (int i = 0; i < N; i ++) {
    int index = indices[i];
    
    if (i > 0) {
      int index2 = indices[i - 1];
      
      G[index].emplace_back(index2, y[index] - y[index2]);
    }
    
    if (i < N - 1) {
      int index2 = indices[i + 1];
      
      G[index].emplace_back(index2, y[index2] - y[index]);
    }
  }

  std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<std::pair<int, int>>> pq;

  std::vector<bool> visit(N);

  pq.emplace(-1, 0);

  long long l = 0;

  while (! pq.empty()) {
    int d, i, k;

    std::tie(d, i) = pq.top(); pq.pop();

    if (visit[i])
      continue;

    visit[i] = true;

    l += std::max(d, 0);

    std::cerr << "i=" << i << " d=" << d << " l=" << l << std::endl;

    for (const auto& e : G[i]) {
      std::tie(k, d) = e;

      if (! visit[k])
        pq.emplace(d, k);
    }
  }

  std::cout << l << std::endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    ll n;
    cin >> n;
    vector<ll> v(5);
    rep(i, 5) cin >> v[i];

    sort(all(v));

    cout << 5 + (n + v[0] - 1) / v[0] - 1 << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int x, y;
  cin >> x >> y;
  P(x + y / 2);

  return 0;
}



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

int main() {
  int N, K;
  cin >> N >> K;
  int number = 1;
  for (int i=0; i<N; i++) {
    if (number*2 < number+K){
      number *= 2;
    }
    else {
      number += K;
    }
  }
  cout << number << endl;
  
}

Measured memory_bytes: 3564
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-27 10:53:56
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

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

  string s; cin >> s;
  reverse(all(s));

  int n = s.size();
  vector<int> dp(n);

  int ten = 1;
  int sum = 0;

  

  for (int i = 0; i < n; ++i) {
    int cur = s[i] - '0';
    (sum += (ten * cur)) %= 2019;
    dp[i] = sum;
    (ten *= 10) %= 2019;
  }

  debug(dp);

  map<int, int> mp;
  mp[0] = 1;
  int ans = 0;

  for (int e : dp) {
    ans += mp[e];
    ++mp[e];
  }

  cout << ans << endl;

  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;


vector<int> calc(const vector<int>& v)
{
	vector<int> res;
	forn(i, v.size() - 1)
	{
		res.push_back(abs(v[i] - v[i + 1]));
	}
	return res;
}

vector<int> hst(const vector<int>& a)
{
	vector<int> v(3);
	forn(i, a.size())
		v[a[i]]++;
	return v;
}


int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N, M;
	cin >> N >> M;
	cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;

	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
op=[LI() for i in range(n)]
pro=[LI() for i in range(n)]
vals=[]
for j in range(1,2**10):
    ans=0
    common=[0 for i in range(n)]
    for k in range(n):
        for i in range(10):
            x=(j>>i) %2
            common[k]+=x*op[k][i]
        ans+=pro[k][common[k]]
    vals.append(ans)
print(max(vals))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  ll N; cin >> N;
  multiset<int> a;
  rep(i, N) {
    int x; cin >> x;
    a.insert(x);
  }

  int ans = 0;
  while (!a.empty()) {
    auto it = a.end();
    it--;
    int x = *it;
    int k = 0;
    while (x) {
      k++;
      x /= 2;
    }
    int y = (1<<k) - *it;
    a.erase(it);

    it = a.find(y);
    if (it != a.end()) {
      a.erase(it);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9600
/***** author :  C0d1ngPhenomena *****/

    #include <bits/stdc++.h>
    #define endl "\n"
    #define ll long long int
    #define TestCases int T; cin>>T; while(T--)
    #define rep(i,n) for(ll i = 0; i < n; i++)
    #define revrep(i,n) for(ll i = n-1; i >= 0; i--)
    #define vll vector<ll>
    #define vvll vector < vll >
    #define pll pair<ll, ll>
    #define vpll vector <pll>
    #define mp(x,y) make_pair(x,y)
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define alld(c) c.begin(),c.end(),greater<int>()
    #define mem(a,val) memset(a,val,sizeof(a))
    #define f first
    #define s second
    #define pb push_back
    using namespace std;
    
    bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
    {
        return (a.second < b.second);
    }




    
    int main()
    {
        std::ios::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
       
      	vll arr;
      	ll n;
      	cin >> n;
      	rep(i,n)
      	{
      		ll a;
      		cin >> a;
      		arr.pb(a);
      	}
      	ll counta = 0;
      	rep(i,n)
      	{
      		if((i+1) & 1 and (arr[i] & 1))
      		{
      			counta++;
      		}
      	}
      	cout << counta;
        return 0;
    }







Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define N 200005
using namespace std;
inline ll read(){
	ll x=0; bool f=1; char c=getchar();
	for(;!isdigit(c); c=getchar()) if(c=='-') f=0;
	for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
	if(f) return x;
	return 0-x;
}
int n,a[N<<1],nxt[N],to[N];
ll k;
int check(int x){return x=(x-1)%n+1;}
int main(){
	n=read(), k=read(); int nn=n<<1;
	for(int i=1; i<=n; ++i) a[i]=read();
	for(int i=n+1; i<=nn; ++i) a[i]=a[i-n];
	for(int i=nn; i>n; --i) nxt[a[i]]=i;
	for(int i=n; i>=1; --i){
		if(nxt[a[i]]) to[i]=nxt[a[i]]+1-i;
		nxt[a[i]]=i;
	}
	int round = 1+to[1]>n ? 1 : 0, i=check(1+to[1]);
	for(; i!=1; i=check(i+to[i])) if(i+to[i]>n) round+=(i+to[i]-1)/n;
	(--k)%=round, ++k;
	round = 1+to[1]>n ? 1 : 0;
	if(round!=k){
		i=check(1+to[1]);
		for(; ; i=check(i+to[i])){
			if(i+to[i]>n) ++round;
			if(round==k) break;
		}
	}
	int inside=0;
	for(; i<=n; ++i){
		if(i+to[i]<=n+1 && inside<=i) inside=i+to[i];
		if(i>=inside) printf("%d ",a[i]);
	}
	return 0;
}
/*
4 2
1 3 1 2
*/

Measured memory_bytes: 4608
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
    vector<int>x(n);
    vector<int>y(n);
    vector<int>h(n);
    bool f = true;
    rep(i,n){
        cin>>x[i]>>y[i]>>h[i];
        if(i!=0 && h[0]==0 && h[i]!=0 && f){
            swap(x[0],x[i]);
            swap(y[0],y[i]);
            swap(h[0],h[i]);
            f = false;
        }
    }

    rep(cx,101){
        rep(cy,101){
            int ch = h[0]+abs(y[0]-cy)+abs(x[0]-cx);
            bool g = true;
            rep(i,n){
                if(h[i] != max(ch-abs(x[i]-cx)-abs(y[i]-cy),0))g = false;
            }
            if(g){
                cout<<cx<<" "<<cy<<" "<<ch<<endl;
                return 0;
            }
        }
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<cstdlib>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i,k) for(int i=0;i<k;i++)
ll n, m[22][22] = {}, i, j, k,h, o, l=0, z, sam = 0, p, q;
ll a[100005] = {} , inf = 1000000000000;
ll b[100005] = {};

string s[22];
ll t[100005], xx[100005];
char ss,st;
const int MAX =100005;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	cin >> h >> n;
	rep(i, n) {
		cin >> z;
		sam += z;

	}

	if (h <= sam)cout << "Yes";
	else cout << "No";

	

	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  map<ll,int> p;
  int ans=0;
  rep(i,n){
    ll x;
    cin>>x;
    if(p.count(x)){
      if(p.at(x)==1) {
        ans--;
        p.at(x)=0;
      }
      else{
        ans++;
        p.at(x)=1;
      }
    }
    else {
      ans++;
      p[x]=1;
    }
  }

  cout << ans << endl;
}

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 105;

int a[MAXN];
bool ok[MAXN];
int n, x;

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

    cin >> n >> x;
    REP(i, n)
        cin >> a[i];

    sort(a, a + n);

    int sol = 0;

    REP(i, n)
        if(a[i] <= x){
            x -= a[i];
            ok[i] = true;
            sol ++;
        }

    if(ok[n - 1] && x != 0)
        sol --;

    cout << sol;
}


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

struct point_t {
    long x, y;
};

int main() {
    int N;
    std::cin >> N;
    std::vector<point_t> ps(N);
    for (auto&& p : ps) {
        std::cin >> p.x >> p.y;
    }
    std::sort(ps.begin(), ps.end(), [](point_t const& lhs, point_t const& rhs) {
        return lhs.x+lhs.y < rhs.x+rhs.y;
    });
    auto p1 = ps[0];
    auto p2 = ps[ps.size()-1];
    auto d1 = std::abs(p1.x - p2.x) + std::abs(p1.y - p2.y);

    std::sort(ps.begin(), ps.end(), [](point_t const& lhs, point_t const& rhs) {
        return lhs.x-lhs.y < rhs.x-rhs.y;
    });
    p1 = ps[0];
    p2 = ps[ps.size()-1];
    auto d2 = std::abs(p1.x - p2.x) + std::abs(p1.y - p2.y);
    std::cout << std::max(d1, d2) << std::endl;
}


Measured memory_bytes: 6416
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 200005;
int par[MAXN], fat[MAXN], val[MAXN], f[MAXN], g[MAXN], n;
struct Node {
	int f, g, id;
	bool operator<(const Node &a) const
		{ LL x = (LL)f * a.g, y = (LL)g * a.f; return x == y ? id < a.id : x < y; }
	bool operator==(const Node &a) const { return id == a.id && (LL)f * a.g == (LL)g * a.f; }
};
struct Set {
	priority_queue<Node> ins, del;
	void upd() { while (!del.empty() && ins.top() == del.top()) ins.pop(), del.pop(); }
	void push(const Node &d) { ins.emplace(d); }
	void pop() { upd(); ins.pop(); }
	Node top() { upd(); return ins.top(); }
	bool empty() { upd(); return ins.empty(); }
	void erase(const Node &d) { del.emplace(d); }
} pq;
int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) par[i] = i;
	for (int i = 2; i <= n; i++) scanf("%d", fat + i);
	for (int i = 1; i <= n; i++) {
		scanf("%d", val + i);
		(val[i] ? g[i] : f[i]) = 1;
		if (i > 1) {
			if (val[i]) pq.push(Node { 0, 1, i });
			else pq.push(Node { 1, 0, i });
		}
	}
	LL ans = 0; int cnt = 0;
	while (!pq.empty()) {
		assert(++cnt <= n - 1);
		Node d = pq.top(); pq.pop();
		int v = find(d.id), u = find(fat[v]);
		assert(v == d.id);
		ans += (LL)g[u] * f[v];
		if (u > 1) pq.erase(Node { f[u], g[u], u });
		f[u] += f[v], g[u] += g[v];
		if (u > 1) pq.push(Node { f[u], g[u], u });
		par[v] = u;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 12528
S = gets.chomp
gets
HT,h = ['',''],0
$<.each{|ln| ln.chomp!
	if ln == '1'
		h = 1-h
	elsif ln[0,3] == '2 1'
		HT[h] << ln[-1]
	elsif ln[0,3] == '2 2'
		HT[1-h] << ln[-1]
	else end
}
print HT[h].reverse, (h==0 ? S : S.reverse), HT[1-h], "\n"


Measured memory_bytes: 2684
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var TX = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => double.Parse(number));

		Console.WriteLine(TX[0] / TX[1]);

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

//節点uからでる枝の構造体の定義
typedef struct slobj_{
    struct slobj_ *next;
    int v; //uから枝が伸びている節点v
    long d; //枝(u,v)の重み
}* slobj;

//slobj型のリストの定義
typedef struct{
    slobj head;
    slobj tail;
}* slist;

//グラフの構造体の定義
typedef struct{
    int n; //節点数
    slist* E; //枝リストの配列E[0]~E[n-1],未ソート単方向
}* graph;

//vにn,dにxを持つslobj型のリスト要素のメモリ確保+作成する関数
slobj slobj_new(int n,long x){
    slobj p;
    NEW(p,1);
    p->v=n;
    p->d=x;
    p->next=NULL;
    return p;
}

//slist型のメモリを1個確保し、空リスト1つを作る関数
slist slist_new(void){
    slist L;
    NEW(L,1);
    L->head=NULL;
    L->tail=NULL;
    return L;
}

//各slistを空リストにした,節点nのgraph型のメモリを確保する関数(Eは0カウント)
graph graph_new(int n){
    graph G;
    NEW(G,1);
    
    G->n=n;
    
    NEW(G->E,G->n);
    int i;
    for(i=0;i<G->n;i++){
        G->E[i]=slist_new();
    }
    
    return G;
}

//リストLの末尾に要素rを追加する関数
void slist_append_tail(slist L,slobj r){
    if(L->head==NULL){
        L->head=r;
        L->tail=r;
    }
    else{
        L->tail->next=r;
        L->tail=r;
    }
    
    return;
}

//節点i(0~n-1)から節点j(0~n-1)に、重さxの枝を追加する関数
void add_edge(graph G, int i, int j, int x){
    //枝データを追加
    slobj p=slobj_new(j,x);
    slist_append_tail(G->E[i],p);

    return;
}

//根(節点i)からの長さをdfs
void dfs(graph G, int i, long* d){
	slobj p=G->E[i]->head;
	while(p!=NULL){
		if(d[p->v]==-1){ //未探索なら
			d[p->v]=d[i]+p->d;
			dfs(G,p->v,d);
		}
		p=p->next;
	}
	return;
}

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

	graph G = graph_new(N);

	int u,v,w;
	for(int i=1;i<=N-1;i++){
		scanf("%d%d%d",&u,&v,&w);
		add_edge(G,u-1,v-1,w);
		add_edge(G,v-1,u-1,w);
	}

	//節点iの根(0)からの深さを格納(初期値-1)
	long d[N];
	for(int i=0;i<N;i++) d[i]=-1;
	d[0]=0;

	dfs(G,0,d);

	for(int i=0;i<N;i++){
		printf("%ld\n",d[i]%2);
	}

	return 0;
}

Measured memory_bytes: 12800
read N
read K
x=()
v=""
for i in `seq 1 $N`; do
  v="$v x[$(($i-1))] "
done
eval read $v

ans=0
for ((i=0;$i<$N;i++)); do
  if [ ${x[$i]} -lt $(($K-${x[$i]})) ]; then
    ans=$(($ans+${x[$i]}))
  else
    ans=$(($ans+$K-${x[$i]}))
  fi
done
echo $(($ans*2))


Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define fo(i,n) for(int i=0;i<n;++i)
#define Fo(i,k,n) for(int i=k;i<n;++i)
typedef long long int lli;
int main(){
    FIO
    int k,x; cin>>k>>x;
    int m=k*500;
    if(m>=x) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3648
use std::io::*;
use std::str::FromStr;

#[test]
fn test() {
    // apend to test here
//    assert_eq!();
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
    token.parse().ok().expect("failed to parse token")
}

fn func(n: usize, a: Vec<u32>, b: Vec<u32>, c: Vec<u32>) -> u32 {
    let mut ans = 0;
    let mut tmp: u32 = (n + 1) as u32;
    for i in a {
        ans = ans + b[(i - 1) as usize];
        if i == (tmp + 1) {
            ans = ans + c[(tmp - 1) as usize];
        }
        tmp = i;
    }
    ans
}
fn main() {
    // Add variable
    let n: usize = read();
    let mut a = Vec::new();
    for _i in 0..n {
        a.push(read::<u32>());
    }
    let mut b = Vec::new();
    for _i in 0..n {
        b.push(read::<u32>());
    }
    let mut c = Vec::new();
    for _i in 0..(n-1) {
        c.push(read::<u32>());
    }
    let ans;

    ans = func(n, a, b, c);
    println!("{}", ans);
}



Measured memory_bytes: 4352
from itertools import accumulate
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
acc = list(accumulate(a))

def maxsum(ls,k):
  l = len(ls)
  if l==0:
    return 0
  dp = [0 for i in range(l+1)]
  dp[0] = 1
  for i in range(1,l+1):
    dp[i] = (dp[i-1]|(dp[i-1]<<ls[i-1]))&((1<<k)-1)
  for b in range(k-1,-1,-1):
    if dp[l] & 1<<b:
      return b

for i in range(n):
  if a[i]>=k:
    a = a[:i]
    break
n = len(a)
if acc[n-1] < k:
  print(n)
  exit()
sepa=[]
for i in range(n-1):
  if acc[i]<a[i+1]:
    sepa.append(i)
m=len(sepa)
if m==0:
  print(0)
  exit()
lf = 0
r = m-1
while lf<r:
  mid = (lf+r)//2
  x=sepa[mid]
  sumx = acc[x]
  if maxsum(a[x+1:],k)+sumx >= k:
    r = mid
  else:
    lf = mid+1
if r==0:
  t=sepa[0]
  if maxsum(a[t+1:],k)+acc[t]>=k:
    print(0)
  else:
    print(sepa[r]+1)
else:
  print(sepa[r]+1)


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

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

using namespace std;

using ll = long long int;

const int MOD_NUM = 1e9 + 7;

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

    // Process
    int ans = (10000 - N) % 1000;

    // Output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3616
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static ArrayList<Integer>[] e = null;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int q = sc.nextInt();
		int[] a = new int[q];
		int[] b = new int[q];
		int[] c = new int[q];
		int[] d = new int[q];
		for (int i = 0; i < q; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}
		StringBuffer buf = new StringBuffer();

		String[] ss = new String[] { S, T };
		int[][][] p = new int[ss.length][5][];
		for (int i = 0; i < ss.length; i++) {
			p[i][0] = new int[100010];
			p[i][1] = new int[10010];
			p[i][2] = new int[1010];
			p[i][3] = new int[110];
			p[i][4] = new int[20];
			for (int j = 0; j < ss[i].length(); j++) {
				int x = (ss[i].charAt(j) == 'A') ? 1 : 2;
				p[i][0][j] = p[i][0][j] + x;
				p[i][1][j / 10] = p[i][1][j / 10] + x;
				p[i][2][j / 100] = p[i][2][j / 100] + x;
				p[i][3][j / 1000] = p[i][3][j / 1000] + x;
				p[i][4][j / 10000] = p[i][4][j / 10000] + x;
			}
		}
		for (int i = 0; i < q; i++) {
			int[][] r = new int[][] { { a[i], b[i] }, { c[i], d[i] } };
			int[] chk = new int[2];
			for (int j = 0; j <= 1; j++) {
				for (int k = r[j][0] - 1; k < r[j][1];) {
					if ((k % 10000) == 0 && (k + 9999) < r[j][1]) {
						chk[j] += p[j][4][k / 10000];
						k += 10000;
					} else if ((k % 1000) == 0 && (k + 999) < r[j][1]) {
						chk[j] += p[j][3][k / 1000];
						k += 1000;
					} else if ((k % 100) == 0 && (k + 99) < r[j][1]) {
						chk[j] += p[j][2][k / 100];
						k += 100;
					} else if ((k % 10) == 0 && (k + 9) < r[j][1]) {
						chk[j] += p[j][1][k / 10];
						k += 10;
					} else {
						chk[j] += p[j][0][k];
						k += 1;
					}
				}
			}
			if (chk[0] % 3 == chk[1] % 3) {
				buf.append("YES\n");
			} else {
				buf.append("NO\n");
			}
		}

		System.out.println(buf.toString());
	}
}


Measured memory_bytes: 103568
#include <stdio.h>
#include <ctype.h>

int sub(char str[]){
	int i, ret, mul[4] = {1000,100,10,1}, count;
	char unit[5] = {"mcxi"};
	count = ret = 0;
	for(i = 0;i < str[i] != '\0';i++){
		if(isdigit(str[i])){
			while(str[i + 1] != unit[count])
				count++;
			ret += (str[i++] - '0') * mul[count++];
		}
		else{
			while(str[i] != unit[count])
				count++;
			ret += mul[count++];
		}
	}
	return ret;
}


int main(void){
	int n, i, j, res , count;
	char str1[9], str2[9], c, unit[5] = {"mcxi"};
	scanf("%d%*c",&n);
	for(i = 0;i < n;i++){
		j = 0;
		while((c = getchar()) != ' ')
			str1[j++] = c;
		str1[j] = '\0';
		j = 0;
		while((c = getchar()) != '\n')
			str2[j++] = c;
		str2[j] = '\0';
		res = sub(str1) + sub(str2);
		count = 0;
		for(j = 1000;j > 0;j /= 10){
			if(res / j == 1){
				printf("%c",unit[count++]);
				res -= j;
			}
			else if(res / j){
				printf("%d%c",res / j,unit[count++]);
				res %= j;
			}
			else
				count++;
		}
		printf("\n");
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;++i){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  
  int al,bo;
  al = 0;
  bo = 0;
  for(int i=0;i<N;++i){
    if(i%2==0) al += a[N-1-i];
    else bo += a[N-1-i];
  }
  cout<<al-bo<<endl;
}



Measured memory_bytes: 256
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace Rextester
{
    public class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);

        public static void Main(string[] args) {
            int n = Next();
            int a = Next();
            int b = Next();
            long ret = 0;
            if(a>b||(n==1&&a!=b)) {
                Console.WriteLine(ret);
            }
            else if(n==1&&a==b){
                ret++;
                Console.WriteLine(ret);
            }
            else {
                ret = 1;
                ret += (long)(n-2)*(b-a);
                Console.WriteLine(ret);
            }
        }
    
        private static int Next() {
            int c;
            int m = 1;
            do {
                c = reader.Read();
                if (c == '-')
                    m = -1;
            } while (c < '0' || c > '9');
            int res = c - '0';
            while (true) {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return m*res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>

using namespace std;

void print(int *p,int n){
    for(int i=0;i<n;i++){
        cout << p[i];
        if(i<n-1) cout << " ";
    }
    cout << endl;
}

int main(){
  int n,i,j,v;
  cin >> n;
  int a[n];
  for(i=0;i<n;i++){
      cin >> a[i];
  }
  for(i=0;i<n;i++){
    v=a[i];
    j=i-1;
    while(j>=0 && a[j]>v){
        a[j+1]=a[j];
        j--;
    }
    a[j+1]=v;
    print(a,n);
  }
  return 0;
}

Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t,p,q,x,c1,c2,c3,d,e,f;
    ll n,m,z;
    vector<ll>v;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
      cin>>t;
      v.push_back(t);
    }
    sort(v.begin(),v.end());
    ll mn;
    mn=42346875687;
    d=v[0]; e=v[n-1];
    for(ll i=d; i<=e; i++)
    {
        p=i;
        x=0;
        for(ll j=0; j<v.size(); j++)
        {
            q=v[j];
            x+=(q-p)*(q-p);
        }
        mn=min(mn,x);
    }

    cout<<mn<<endl;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
const int N = 2e5 + 5;
const ll mod = 1000000007;
using namespace std;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);


	ll tc = 1;
//	cin >> tc;

	while (tc--) {
		ll n, m, i, j, fl;
		ll k;

		string s;
		cin >> s;
		if (s == "ABC")
			cout << "ARC" << endl;
		else
			cout << "ABC" << endl;

	}
}

Measured memory_bytes: 3600
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=(1<<17)+5; 
int k[maxn],ne[maxn],c[maxn],g[maxn],num;
int i,j,n,v,x;
ll m,l,r,inf=2e10;
struct ar{ll a,b;}o;
vector<ar>p1[maxn],p2[maxn],p;
void add(int x,int y,int z){
	ne[++num]=k[x],k[x]=num,g[num]=y,c[num]=z;
}
bool cmp1(ar x,ar y){
	return x.a==y.a?x.b<y.b:x.a<y.a;
}
bool cmp2(ar x,ar y){
	return x.b==y.b?x.a<y.a:x.b<y.b;
}
void dfs(int x){
	p1[x].clear(),p2[x].clear();
	int i,cnt=0,son[2];ll dis[2],sum;
	for(i=k[x];i;i=ne[i]) dfs(g[i]),son[cnt]=g[i],dis[cnt]=c[i],cnt++;
	if (!cnt){
		p1[x].push_back(o),p2[x].push_back(o);
		return;
	}
	if (p1[son[0]].size()>p1[son[1]].size()) swap(son[0],son[1]),swap(dis[0],dis[1]);
	sum=m-dis[0]-dis[1];
	int j=0,n0=p1[son[0]].size(),n1=p1[son[1]].size();
	p.clear();
	ll b=inf,a=inf;
	for(i=n0-1;i>=0;i--){
		for(;j<n1&&p1[son[1]][j].a+p2[son[0]][i].b<=sum;j++) b=min(b,p1[son[1]][j].b);
		if (b!=inf)p.push_back((ar){p2[son[0]][i].a+dis[0],b+dis[1]});
	}
	j=0;
	for(i=n0-1;i>=0;i--){
		for(;j<n1&&p2[son[1]][j].b+p1[son[0]][i].a<=sum;j++) a=min(a,p2[son[1]][j].a);
		if (a!=inf)p.push_back((ar){a+dis[1],p1[son[0]][i].b+dis[0]});
	}
	sort(p.begin(),p.end(),cmp1);
	for(i=0;i<p.size();i++) p1[x].push_back(p[i]);
	sort(p.begin(),p.end(),cmp2);
	for(i=0;i<p.size();i++) p2[x].push_back(p[i]);
}
int main(){
	n=read();
	fo(i,2,n){
		x=read(),v=read();
		add(x,i,v);
	}
	l=0,r=inf;
	for(;l<r;){
		m=(l+r)>>1;
		dfs(1);
		if (p1[1].size()) r=m;else l=m+1;
	}
	printf("%lld\n",l);
}

Measured memory_bytes: 51572
//Problem Y

#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define endl "\n"
 
int main ()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #define int ll
  
  int n;
  cin >> n;
  vector <int> numbers(n);
  map <int, int> mp;
  int summation = 0;
  for(auto& i:numbers){
    cin >> i;
    mp[i]++;
    summation += i;
  }
  
  //cout << summation << endl;

  int q;
  cin >> q;

  while (q--){
    int b, c;
    cin >> b >> c;
    if (mp.count(b) == 0){
        cout << summation << endl;
        continue;
    }
    summation -= b*mp[b];
    summation += c*mp[b];
    if (mp.count(c))
    mp[c] += mp[b];
    else mp[c] = mp[b];
    mp[b] = 0;
    cout << summation << endl;
  }
  
  return 0;
  
}


Measured memory_bytes: 9292
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int ans = 0,j=0;
	int n;
	cin>>n;
	for(int i = 1;i<=n; i*=2)
	{
		j=i;
	}
	cout<<j<<endl;
	return 0;
}

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

int main(){
    int K,S;
    cin>>K>>S;
    int num=0;
    int Z;
    for (int X=0; X<=K; X++) {
        for (int Y=0; Y<=K; Y++) {
            Z=S-X-Y;
            if (Z<=K) {
                if (0<=Z) {
                    num++;
                }
            }
        }
    }
    
    cout<<num;
    return 0;
    
}

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

int main()
{
	int a, b, c, M, sum;
	int answer = 0;
	
	cin >> a >> b >> c;

	M = max(max(a, b), c);
	sum = a + b + c;

	if (3 * M % 2 == sum % 2 ) {
		answer = (3 * M - sum) / 2;
	}
	else {
		answer = (3 * (M + 1) - sum) / 2;
	}
	
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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


int main()
{
  int N;
  cin >> N;
  vector<int> b(N);
  REP(i, N) {
    cin >> b[i];
    b[i]--;
  }

  vector<bool> used(N, false);
  vector<pair<int, int>> ans;
  for (int i = N - 1; i >= 0; i--) {
    vector<pair<int, int>> v;
    REP(j, N) {
      if (!used[j]) v.PB(MP(b[j], j));
    }
    int ma = -1, mai = -1;
    REP(j, v.size()) {
      if (v[j].FI == j) {
        ma = v[j].FI;
        mai = v[j].SE;
      }
    }
    if (ma == -1) {
      cout << -1 << endl;
      return 0;
    }
    ans.PB(MP(i, ma));
    used[mai] = true;
  }
  sort(ALL(ans));
  REP(i, N) {
    cout << (ans[i].SE + 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back 
#define mp make_pair
#define sp " "
#define cs "Case "
#define fi first
#define sn second 
#define po(x) x*x
/* STL */
#define vi vector<int>v
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n)i=1;i<=(n);i++)
#define fa(i,a,n) for(__typeof(a)i=(a);i<=(b);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define db(something)   cerr<<#something<<" - "<<something<<"\n";         
int main()
{
  
   Ezio
   /*Variables*/
   /*Code*/
     ll a,b,c,d(0);
   cin>>a>>b>>c;
   cout<<c<<sp<<a<<sp<<b<<endl;
   return 0;
}
    

Measured memory_bytes: 3612