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

vector<i64> p;
vector<vector<i64>> G;

vector<i64> go;
vector<i64> ba;

void dfs(i64 v, i64 f) {
  i64 DIFF = 0;
  i64 SUM = 0;
  for(auto x: G[v]) {
    if(x == f) continue;
    dfs(x, v);
    if(ba[x] - 2 <= 0) {
      DIFF = max(DIFF, go[x] - 1);
    }
    else {
      SUM += ba[x] - 2;
      DIFF = max(DIFF, go[x] - 1 - (ba[x] - 2));
    }
  }
  ba[v] = SUM + p[v];
  go[v] = SUM + DIFF + p[v];

  //cout << v << " " << ba[v] << " " << go[v] << endl;
}

vector<i64> ans;

void rerooting(i64 v, i64 f, i64 fgo, i64 fba) {
  vector<pair<i64, i64>> diff;
  diff.push_back({ 0, -1 });
  i64 SUM = 0;
  i64 DIFF = 0;
  for(auto x: G[v]) {
    i64 g, b;
    if(x == f) {
      g = fgo;
      b = fba;
    }
    else {
      g = go[x];
      b = ba[x];
    }
    if(b - 2 <= 0) {
      DIFF = max(DIFF, g - 1);
      diff.push_back({ g - 1, x });
    }
    else {
      SUM += b - 2;
      DIFF = max(DIFF, g - 1 - (b - 2));
      diff.push_back({ g - 1 - (b - 2), x });
    }
  }
  ans[v] = SUM + DIFF + p[v];
  sort(begin(diff), end(diff));
  reverse(begin(diff), end(diff));
  for(auto x: G[v]) {
    if(x == f) continue;
    i64 s = SUM;
    if(ba[x] - 2 > 0) {
      s -= ba[x] - 2;
    }
    i64 g = s;
    if(diff.front().second != x) {
      g += diff.front().first;
    }
    else {
      g += diff[1].first;
    }
    rerooting(x, v, g + p[v], s + p[v]);
  }
}

int main() {
  i64 N;
  cin >> N;
  p.resize(N);
  ans.resize(N);
  for(i64 i = 0;i < N;i++) cin >> p[i];
  G.resize(N);
  for(i64 i = 0;i < N - 1;i++) {
    i64 s, t;
    cin >> s >> t;
    s--;
    t--;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  go.resize(N, -1e18);
  ba.resize(N, -1e18);
  dfs(0, -1);
  rerooting(0, -1, 0, 0);
  cout << *max_element(begin(ans), end(ans)) << endl;
}



Measured memory_bytes: 33148
#include<bits/stdc++.h>
using namespace std;
long long a,b,sum=0;
int main(){
	cin>>a>>b;
	if(a==b){
		cout<<a<<endl;
		return 0;
	}
	if(a%2==0&&b%2==1){
		if((b+1-a)/2%2==0) cout<<0<<endl;
		else cout<<1<<endl;
		return 0;
	}
	else if(a%2==0&&b%2==0){
		if((b-a)/2%2==0){
			sum=0^b;
			cout<<sum<<endl;
		}
		else{
			sum=1^b;
			cout<<sum<<endl; 
		}
		return 0;
	}
	else if(a%2==1&&b%2==0){
		if((b-a-1)/2%2==0){
			sum=0^a^b;
			cout<<sum<<endl;
		}
		else{
			sum=1^a^b;
			cout<<sum<<endl;
		}
		return 0;
	}
	else{
		if((b-a)/2%2==0){
			sum=0^a;
			cout<<sum<<endl;
		}
		else{
			sum=1^a;
			cout<<sum<<endl;
		}
		return 0;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int A[20];
int n;

int solve(int p, int t);

int main(void) {
	int i, q, M;
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	
	scanf("%d", &q);
	for (i = 0; i < q; ++i) {
		scanf("%d", &M);
		if (solve(-1, M)) {
			printf("yes\n");
		} else {
			printf("no\n");
		}
	}
	
	return 0;
}

int solve(int p, int t) {
	if ((p == n) || (t == 0)) {
		return t == 0;
	}
	if (t >= A[p + 1]) {
		if (solve(p + 1, t - A[p + 1])) {
			return 1;
		}
	}
	return solve(p + 1, t);
}

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

/*
3 5 5  p^2*q^4*r^4   有多少种不同的p,q,r 
15 5   p^14*q^4      有多少种不同的p,q
25 3   p^24*q^2      有多少种不同的p,q
75     p^74          有多少种不同的p
get(x) ::= 个数大于等于x的素数s的个数 
ans += get(74)  			 					 对应p^74. (从>=74去见选一个)
ans += get(24)*(get(2)-1)    					 对应p^24*q^2.但是>=24.也>=2.(从>=24区间选一个.>=2的区间就会少一个)
ans += get(14)*(get(4)-1)    					 对应p^14*q^4.但是大于等于14.也大于等于4.
ans += (get(2)-2)*(get(4)*(get(4)-1)/2)          对应p^2*q^4*q^4.但是大于等于4.也大于等于2.
*/

int f[110];
int n;

void div(int x){
	for(int i = 2; i <= x; ++i){
		while(!(x%i)){
			++f[i];
			x /= i;
		}
	}
}

int get(int x){
	int res = 0;
	for(int i = 1; i <= n; ++i){
		if(f[i] >= x) ++res;
	}
	return res;
}

int main(){
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0); 
	cin >> n;
	for(int i = 1; i <= n; ++i){
		div(i);
	}
	int ans = 0;
	ans += get(74);  			 					 //对应p^74. (从>=74去见选一个)
	ans += get(24)*(get(2)-1);    					 //对应p^24*q^2.但是>=24.也>=2.(从>=24区间选一个.>=2的区间就会少一个)
	ans += get(14)*(get(4)-1);    					 //对应p^14*q^4.但是大于等于14.也大于等于4.
	ans += (get(2)-2)*(get(4)*(get(4)-1)/2);          //对应p^2*q^4*q^4.但是大于等于4.也大于等于2.
	cout << ans << endl;
	return 0;
}


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

const int N = 3e3+9, M = 1e7, OO = 0x7f7f7f7f;

int n,t;
int a[N] , b[N];
vector<pair <int ,int > >v;
int mem[N][N];


int sol(int i =0 , int rem = t){
    if(i==n)return 0;
    if(rem <= 0)return 0;
    int& ret = mem[i][rem];
    if(~ret)return ret;
    ret = sol(i+1 , rem);
    ret = max(ret , sol(i+1 , rem-v[i].first )+v[i].second);
    return ret;
}




int main(){
    memset(mem , -1 , sizeof(mem));
    scanf("%d %d",&n,&t);
    for(int i=0 ; i<n ; ++i){
        scanf("%d %d",a+i , b+i);
        v.push_back(make_pair(a[i] , b[i]));
    }
    sort(v.begin() , v.end());

//    for(int i=0 ; i<n ; ++i){
//        cout << v[i].first << " " <<v[i].second<<endl;
//    }

   // v[n-1].second = 1;
    printf("%d\n",sol());
    return 0;
}


Measured memory_bytes: 35840
#include<bits/stdc++.h>
#define maxn 2000010
#define inf 1000000000
using namespace std;
template<typename T> inline void read(T &x)
{
    x=0;char c=getchar();bool flag=false;
    while(!isdigit(c)){if(c=='-')flag=true;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    if(flag)x=-x;
}
int k;
int dis[maxn];
bool vis[maxn];
struct edge
{
    int to,nxt,v;
}e[maxn];
int head[maxn],edge_cnt;
void add(int from,int to,int val)
{
    e[++edge_cnt]=(edge){to,head[from],val};
    head[from]=edge_cnt;
}
struct node
{
    int val,num;
};
bool operator <(const node &x,const node &y)
{
    return x.val>y.val;
}
void dijkstra()
{
    priority_queue<node> q;
    for(int i=0;i<=k;++i) dis[i]=inf;
    dis[1]=1,q.push((node){1,1});
    while(!q.empty())
    {
        int x=q.top().num;
        q.pop();
        if(vis[x]) continue;
        vis[x]=true;
        for(int i=head[x];i;i=e[i].nxt)
        {
            int y=e[i].to,v=e[i].v;
            if(dis[y]>dis[x]+v)
                dis[y]=dis[x]+v,q.push((node){dis[y],y});
        }
    }
}
int main()
{
    read(k);
    for(int i=1;i<k;++i) add(i,i*10%k,0),add(i,(i+1)%k,1);
    dijkstra(),printf("%d\n",dis[0]);
    return 0;
}

Measured memory_bytes: 9468
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
  char ch[1200];
  int i = 0;
  int n = 0;

  for (n = 0; n < 1200; n++) {
    ch[n]=0;
  }


  while(1){

    scanf("%c",&ch[i]);

    if(ch[i] == '\n') break;

    // ?°???????????????°,??§?????????

    if(islower(ch[i])){
      ch[i]=toupper(ch[i]);
      printf("%c",ch[i]);
    }
    //??§?????????????°??????????
    else if(isupper(ch[i])){
      ch[i]=tolower(ch[i]);
      printf("%c",ch[i]);
    }
    // ?????£?????§?????????????????????????????????
    else {
      printf("%c", ch[i]);
    }
i=i+1;
  }

 printf("\n");

return(0);
}

Measured memory_bytes: 524
{- written by MarekCerny.com -}
{-# LANGUAGE ViewPatterns, PatternSynonyms  #-}
{-# LANGUAGE TupleSections                  #-}
{-# LANGUAGE UnicodeSyntax                  #-}
{-# LANGUAGE LambdaCase, MultiWayIf         #-}
import Data.Tuple
import Data.Bits
import Data.Maybe
import Data.Function
import Data.List
import Control.Exception
import qualified Data.HashMap.Strict as M
import Data.Sequence (Seq, (|>), (<|), (><))
import qualified Data.Sequence as S

main = interact $ unlines . sol . allInt . lines

sol :: [[Int]] -> [String]
sol [[n]] = wrap $ show (48-n)

--------------------------------------------------------------------------------
groupOn :: Int -> [a] -> [[a]]
groupOn _ [] = []
groupOn n xs = let (sts, nds) = splitAt n xs in sts : groupOn n nds

fromBool :: Num a => Bool -> a
fromBool b = if b then 1 else 0

allInt :: [String] -> [[Int]]
allInt = map ((map read) . words)

swrt :: Ord a => (a, a) -> (a, a)
swrt (a, b) | compare b a == LT = (b, a) | otherwise = (a, b)

wrap :: a -> [a]
wrap x = [x]

toSnd :: a->b-> (a,b)
toSnd x y = (x,y)

toFst :: b->a-> (a,b)
toFst y x = (x,y)

addCnt :: [String] -> [String]
addCnt ls = (show $ length ls) : ls

toBitMap :: Int -> [(Int, Bool)]
toBitMap = toBitMap' 31
  where
    toBitMap' (-1) _ = []
    toBitMap' n v = (n, v .&. (1`shiftL`n) > 0) : toBitMap' (n-1) v
--------------------------------------------------------------------------------
pattern Empty   <- (S.viewl -> S.EmptyL)
pattern x :< xs <- (S.viewl -> x S.:< xs)
pattern xs :> x <- (S.viewr -> xs S.:> x)
--------------------------------------------------------------------------------


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

#define MAX(A,B) \
  ( (B) > (A) ? (B) : (A) )

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int l, a, b, c, d;

  scanf ( "%d%d%d%d%d", &l, &a, &b, &c, &d );
  a = ( a / c ) + !!( a % c );
  b = ( b / d ) + !!( b % d );

  printf ( "%d\n", l - MAX( a, b ) );

  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> primes;
void sieve() {
	int lim = 1e6+1000;
	vector<bool> mark(lim+6, true);
	for (int i=2; i*i<=lim; i++) {
		if (mark[i]) {
			for (int j=i*i; j<=lim; j+=i) {
				mark[j] = false;
			}
		}
	}
	
	for (int i=2; i<=lim; i++) {
		if (mark[i]) primes.emplace_back(i);
	}
	
}
int main() {
	sieve();
	int x;
	cin >> x;
	cout << *lower_bound(primes.begin(),primes.end(),x);
	return 0;
}


Measured memory_bytes: 3884
#include<stdio.h>

int main(void) {
	char S[4];
	int c=0;
	scanf("%s", S);
	for (int i = 0; i < 4; i++) {
		if (S[i] == S[i + 1]&&c==0) {
			printf("Bad\n");
			c = 1;
		}
	}
	if (c == 0) {
		printf("Good\n");
	}
	return 0;
}

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

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

const long long MOD = 1000000007;

int main(){
  int a,b,aa,bb,m;
  cin >> a >> b >> m;
  int ma=1e5+1,mb=1e5+1;
  vector<int> la(a),lb(b);
  rep(i,a){
    cin >> aa;
    la.at(i) = aa;
    ma = min(aa,ma);
  }
  rep(i,b){
    cin >> bb;
    lb.at(i) = bb;
    mb = min(bb,mb);
  }
  
  int ans = ma+mb;
  int x,y,c;
  rep(i,m){
    cin >> x >> y >> c;
    x--;y--;
    ans=min(la.at(x)+lb.at(y)-c,ans);
  }
  cout << ans << endl;
    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    LL a,b,c;cin >> a >> b >> c;
    LL t = 4 * a * b;
    LL tt = (c - a - b) * (c - a - b);
    if(c - a - b > 0 && t < tt) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

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

        while(true) {
            int sum = 0;
            String S = sc.next();
            if (S.equals("-")) {
                break;
            }
            int num = Integer.parseInt(sc.next());
            for (int i = 0; i < num; i++) {
                sum += Integer.parseInt(sc.next());
            }
            String ans = S + S;
            int shift = sum % S.length();
            out.printf("%s\n", ans.substring(shift, shift + S.length()));
        }
        out.flush();
    }
}


Measured memory_bytes: 26272
N = int(input())
Txy = []
for i in range(N):
   Txy.append([int(i) for i in input().split()])


time = [0]
x = [0]
y = [0]
for txy in Txy:
    time.append(txy[0])
    x.append(txy[1])
    y.append(txy[2])

def isPossible(N, time, x, y):
    for i in range(N):
        dt = (time[i + 1] - time[i]) ** 2 
        dx = (x[i + 1] - x[i]) ** 2
        dy = (y[i + 1] - y[i]) ** 2

        if dt >= (dx + dy) and (dt%2 == (dx+dy)%2):
            pass
        else:
            return False
    return True

if(isPossible(N, time, x, y)):
    print("Yes")
else :
    print("No")

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

int main()
{
  int n, m;
  int a, b, c;

  cin >> a >> b >> c;

  if( a + b >= c ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return (0);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
const double pi = acos(-1);
int main()
{
    Hello
    int n, m, sum = 0;
    cin >> n >> m;
    int arr[m + 5];
    for(int i = 0; i < m; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    if(sum > n)
        cout << -1;
    else
        cout << n - sum;
    return 0;
}

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

using namespace std;

int main(){
        int N, M;
        cin>>N>>M;
        vector <int> st;
        vector <int> go;
        for(int i=0;i<M;i++){
                int a, b;
                cin>>a>>b;
                if(a==1)
                        st.push_back(b);
                if(b==N)
                        go.push_back(a);
        }
        sort(st.begin(), st.end());
        sort(go.begin(), go.end());
        bool res=false;
        int j=0, gosize=go.size();
        for(unsigned int i=0;i<st.size()&&!res;i++){
                for(;j<gosize&&go[j]<=st[i];j++){
                        if(st[i]==go[j]){
                                res=true;
                                break;
                        }
                }
                if(j>0)j--;
        }
        if(res)
                cout<<"POSSIBLE"<<endl;
        else
                cout<<"IMPOSSIBLE"<<endl;
        return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include<climits>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> 
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define f first
#define s second
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vi vector<int>
#define vll vector<ll>
#define be begin
#define en end
#define endl '\n'
#define SIZE 1000000
#define w(t) int t;cin>>t;while(t--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define value_at_idx find_by_order
#define idx order_of_key
#define MOD 1000000007
#define reset(dp) memset(dp,0,sizeof(dp))

typedef long long ll;
using namespace std;
using namespace __gnu_pbds; 

ll  dp[101][SIZE];

 ll w[SIZE];
ll v[SIZE];
ll N,W;
ll solve(ll N,ll W)
{
	if(N==0 || W==0)
		return 0;
	

	if(dp[N][W] != 0)
		return dp[N][W];
	ll op1 = INT_MIN;
	if(w[N]<=W)
		op1=v[N] + solve(N-1,W - w[N]);
	ll op2 = solve(N-1,W);

	dp[N][W] = max(op1,op2);

	return dp[N][W];
	
} 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	reset(dp);

	cin>>N>>W;
	for(int i=1;i<=N;i++)
	{
		cin>>w[i]>>v[i];
	}
	cout<<solve(N,W);
	return 0;
		
		

	
	
}
	
	


Measured memory_bytes: 792704
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int main(void)
{
  int A, B;
  cin >> A >> B;
  cout << (A - 1) * (B - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define sc3(a,b,c)  cin>>a>>b>>c
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first 
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5],B[MAXN+5];
vi dskeblock[MAXN+5],dske[MAXN+5];
bitset<MAXN+5> bi;
ll DFS(ll x,ll cnt){
	if(bi[x])re 0;
	bi[x]=1;
	A[x]=cnt;
	B[cnt]++;
	ll ans=0;
	fuv(i,dske[x]){
		ll v=DFS(dske[x][i],cnt);
		ans+=v;
	}
	re ans+1;
}
ll Solves(){
	
	ll n,m,k,cnt=1,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	
	cin>>n>>m>>k;
	while(m--){
		sc2(x,y);
		dske[x].pb(y);
		dske[y].pb(x);
	}
	while(k--){
		sc2(x,y);
		dskeblock[x].pb(y);
		dskeblock[y].pb(x);
	}
	
	f1(i,n){		
		v=DFS(i,cnt);
		if(v)cnt++;
	}
	f1(i,n){
		cnt=0;
		fuv(j,dskeblock[i])if(A[dskeblock[i][j]]==A[i])cnt++;
		cout<<(B[A[i]]-cnt-sz(dske[i])-1)<<" ";
	}
	
	
	
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	} 		
}

Measured memory_bytes: 62080
# N: number of balls to take, A: blue, B: red
N, A, B = list(map(int, input().split()))

if N == 0:
    print(0)

if A + B < N:
    # want to know how much A + B blocks can we place such that A + B < N (i.e. solve x(A+B) < N)
    blocks = int(N/(A+B))
    # for each block, there are A blue balls, plus potentially some reamining slots to fill the remaining space of N
    remaining_slots = N % (A+B)
    if A <= remaining_slots:
        # if it can fit A, place A more balls in the row
        print(blocks*A + A) 
    else:
        print(blocks*A + remaining_slots)
else:
    if A < N:
        print(A)
    else:
        print(N)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cba"||s=="cab"){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

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

    void solve(){

        int x = sc.nextInt();

        if(x / 100 * 5 >= x % 100) System.out.println(1);
        else System.out.println(0);

    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    long pow_mod(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <= 0){
                return false;
            }
        }
        return true;
    }
    private int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c){ return 33 <= c && c <= 126;}
    public boolean hasNext(){ while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b <= '9'){
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble(){ return Double.parseDouble(next());}
}


Measured memory_bytes: 23252
H, W = map(int, input().split())
N = int(input())
a = []
for i, ai in enumerate(map(int, input().split())) :
    for _ in range(ai) :
        a.append(i+1)
a = a[::-1]

c = [[0] * W for _ in range(H)]

d = ((1, 0), (0, 1), (-1, 0), (0, -1))
di = 0
dx, dy = d[0]
x, y = 0, 0
for i in range(H * W) :
    c[y][x] = a.pop()
    if not (0 <= x + dx < W) or not (0 <= y + dy < H) or c[y+dy][x+dx] != 0 :
        di = (di + 1) % 4
        
    dx, dy = d[di]
    x += dx
    y += dy    
        
for i in range(H) :
    print(*c[i])

Measured memory_bytes: 42864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
string ans = "Yes";

int main()
{
ll n , m ;
cin >> n >> m ;
double sum=0;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
  sum+=a[i];
}
ll an=0;
rep(i,n){
  if(a[i]>=sum/(4*m))an++;
}
if(an<m)ans="No";
cout << ans << endl;
return 0;
}

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

int main()
{
    long long int N , r;
    
    cin>> N;
    
    r = (N % 1000);
    
    if(r==0)
       cout<<"0";
      else
      {
          cout<<(1000-r);
      }

    return 0;
}


Measured memory_bytes: 3540
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
  char name[100];
  int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
 
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
 
int min(int a,int b) {
  return a < b ? a : b; 
}
 
int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD 998244353


char S[2020];
ll dp[4040][4040];
ll i,j,k,l,ans,n;

int main(){
    scanf("%s", S);
    n = 2;
    dp[0][S[0]-'0'] = 1;
    /*
    fornum(j,0,n+1){
        printf("%lld ", dp[i][j]);
    }
    printf("\n");*/
    for (i = 1; S[i];i++){
        ll b = S[i] - '0';
        dp[i][b] = (dp[i][b]+dp[i-1][0])%MOD;
        fornum(j,1,n){
            dp[i][j+b] = (dp[i][j+b]+dp[i-1][j])%MOD;
            dp[i][j+b-1] = (dp[i][j+b-1]+dp[i-1][j])%MOD;
        }
        dp[i][n+b-1] = (dp[i][n+b-1]+dp[i-1][n])%MOD;
        n++;/*
        fornum(j,0,n+1){
            printf("%lld ", dp[i][j]);
        }
        printf("\n");
        */
    }
    k = i;
    for (i; i<=k*2;i++){
        dp[i][0] = (dp[i][0]+dp[i-1][0])%MOD;
        fornum(j,1,n){
            dp[i][j] = (dp[i][j]+dp[i-1][j])%MOD;
            dp[i][j-1] = (dp[i][j-1]+dp[i-1][j])%MOD;
        }
        dp[i][n-1] = (dp[i][n-1]+dp[i-1][n])%MOD;
        n--;/*
        fornum(j,0,n+1){
            printf("%lld ", dp[i][j]);
        }
        printf("\n");
        */
    }
    printf("%lld",dp[k*2][0]);

    return 0;
}

Measured memory_bytes: 125440
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			String s = in.nextString();
			int k = in.nextInt();
			int len = s.length();

			TreeSet<String> set = new TreeSet<>();

			for (int i = 0; i < len; i++) {
				if (i + k <= len) {
					set.add(s.substring(i, i+k));
				} else {
					set.add(s.substring(i, len));
				}
			}

			List<String> list = new ArrayList<>();

			int count = 1;
			for (String string : set) {
				if (count <= 5) {
					list.add(string);
					count++;
				} else {
					break;
				}
			}

			TreeSet<String> nset = new TreeSet<>();
			for (String str : list) {
				int nlen = str.length();
				for (int i = 0; i < nlen; i++) {
					for (int j = i+1; j <= nlen; j++) {
						nset.add(str.substring(i, j));
					}
				}
			}

			count = 1;
			for (String string : nset) {
				if (count == k) {
					out.println(string);
					return;
				}
				count++;
			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 23124
package main

import (
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	iv, _ := strconv.Atoi(readStr())
	return iv
}

func readStr() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	h, w := readInt(), readInt()
	s := make([]string, h)
	for i := range s {
		s[i] = readStr()
	}

	var wr = bufio.NewWriter(os.Stdout)
	mvx := []int{-1, 0, 1, -1, 1, -1, 0, 1}
	mvy := []int{1, 1, 1, 0, 0, -1, -1, -1}
	for i := range s {
		for j := range s[i] {
			if s[i][j] == '#' {
				wr.WriteString("#")
				continue
			}

			cnt := 0
			for k := 0; k < 8; k++ {
				if x, y := j+mvx[k], i+mvy[k]; x >= 0 && x < w && y >= 0 && y < h && s[y][x] == '#' {
					cnt++
				}
			}
			wr.WriteString(strconv.Itoa(cnt))
		}
		wr.WriteString("\n")
	}
	wr.Flush()
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        for(int i=1;i<=5;i++){
            if(scanner.nextInt() == 0)
                System.out.println(i);

        }
    }

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


Measured memory_bytes: 35704
#include <stdio.h>
int main(void)
{
	int n;
	int s[100];
	int sum;
	int min = 101;
	int i;
	scanf("%d", &n);
	for (i = 0, sum = 0; i < n; i++) {
		scanf("%d", &s[i]);
		sum += s[i];
		if (s[i] % 10 != 0 && min > s[i]) min = s[i];
	}
	if (min > 100) printf("%d", 0);
	else if (sum % 10 == 0) printf("%d", sum - min);
	else printf("%d", sum);
	return 0;
}

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

int main()
{
  int N, a[200000];
  cin >> N;
  for(int i = 0; i < N; i++)
  {
    cin >> a[i];
  }
  
  int block = 0;
  int number = 1;
  
  for(int i = 0; i < N; i++)
  {
    if(a[i] == number)
    {
      number++;
    }
    else
    {
      block++;
    }
  }
  
  if (number == 1){
    cout << -1 << endl;
  }
  else{
    cout << block << endl;
  }
}

Measured memory_bytes: 4416
#include<stdio.h>
#include<algorithm>
#include<vector>
#define fst first
#define snd second

using namespace std;

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

ll n;

ll f(ll a, ll b) {
    if (a > b) return f(b, a);

    if((b - a)&1) {
        auto g = [&](ll p1, ll p2) {
            return (p1 - 1) + (p2 - p1 + 1)/2;
        };

        return min(g(a, b), g(n - b + 1, n - a + 1));
    }
    else {
        return (b - a) >> 1;
    }
}

int main() {
    ll a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    printf("%lld\n", f(a, b));
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>

using namespace std;
// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }


#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;


template<typename T>
struct SqrtTree {

  vector<T> data;
  vector<T> bucket;
  T sq;

  SqrtTree( vector<T> const& v) : data(v) {
    int d_size = data.size();
    sq = sqrt( d_size );
    bucket.assign( (d_size + sq - 1) / sq, 0 );
    for(int i = 0; i < d_size; i++) {  bucket[i / sq] += data[i];  }
  }

  // [l, r]
  T query(int l, int r) {
    T res = 0;
    int i = l;
    while(i <= r) {
      if(i % sq == 0 && i + sq <= r) {
        // change here!
        res += bucket[ i / sq ];
        // res = min(res,  bucket[ i / sq ]); RMQ
        i += sq;
      } else {
        res += data[i];
        i++;
      }
    }
    return res;
  }

  void update(int i, T x) {
    // change here!
    // bucket[i / sq] -= data[i];
    data[i] += x;
    bucket[i / sq] += x;

    // RMQ
    // bucket[i / sq] = min(x, bucket[i / sq]);
    // data[i] = x;
  }

  void print() {

    for(int i = 0; i < (int)bucket.size(); i++ ) {
      cout << setw(2*sq) << bucket[i];
    }

    cout << "\n";

    for(int i = 0; i < (int)data.size(); i++ ) {
      cout << setw(2) << data[i];
    }

    cout << "\n";
  }

};



int main() {
  ios::sync_with_stdio(false);

  int N, Q;
  cin >> N >> Q;

  vector<int> data(N, 0);
  SqrtTree<int> sqtree(data);

  for(int i = 0; i < Q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    // add
    if(com == 0) {
      x--;                      // 0 index
      sqtree.update(x, y);
    }
    if(com == 1) {

      x--; y--;        // 0 index
      cout << sqtree.query(x, y) << "\n";
    }

  }

  return 0;
}

Measured memory_bytes: 3524
#coding: utf-8

while True:
    H, W = (int(i) for i in input().split())
    
    if H == W == 0:
        break

    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                print("#", end = '')
            else:
                print(".", end = '')
        print("")
    print("")
            


Measured memory_bytes: 7020
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int digitSum(int64 n){
  int sum=0;
  while(n>0){
    sum+=n%10;
    n/=10;
  }
  return sum;
}

void run(void){
  int64 n;
  scanf("%lld",&n);
  int t=digitSum(n);
  int64 d=1;
  while(10*d<n) d*=10;
  int s=digitSum((n/d-1)*d+d-1);
  printf("%d\n",MAX(s,t));
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int d[N];
vector<int> gr[N];
void dfs(int cur, int parent){
	for (int adj : gr[cur]){
		if (adj != parent){
			d[adj] = d[cur] + 1;
			dfs(adj,cur);
		}
	}
}

int main(){
	int n; 
  	cin >> n;
	for (int i = 0; i < n-1; i++){
		int u, v;
		cin >> u >> v;
		u--, v--;
		gr[u].push_back(v);
		gr[v].push_back(u);
	}
	
	dfs(0,-1);
	int edge = max_element(d,d+n) - d;
	d[edge] = 0;
	dfs(edge, -1);
	int ans = *max_element(d,d+n);
	if (ans % 3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;
	return 0;
}

Measured memory_bytes: 21376
#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
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> P;



int main(){
    int n;  cin >> n;
    vector<ll> a(n);

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

    vector<ll> s(n, 0);
    for(int j = 0; j < n; j++){
        s[j] = a[j] + j;
    }

    ll res = 0;
    vector<ll> count(n+10, 0);
    for(int i = 0; i < n; i++){
        ll obj = i - a[i];
        if(obj >= 0 && obj <= n+3){
            res += count[obj];
        }
        ll x = a[i] + i;
        if(x >= 0 && x <= n+3){
            count[x]++;
        }
    }

    cout << res << endl;





    return 0;
}


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


int main(){
  int N;
  cin >> N;
  vector<int> D(N);
  for(auto& d : D){
    cin >> d;
  }
  sort(D.begin(), D.end());
  cout << D[N/2] - D[N/2-1] << endl;
  return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define R(_x, _y) (0 <= _x && _x <= M - 1 && 0 <= _y && _y <= N - 1)
#define A(a) (!(R(x + dx[a], y + dy[a]) && b[y + dy[a]][x + dx[a]]))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int main() {
	int A, B, C, D, t = 0;
	cin >> A >> B >> C >> D;
	while (A > 0 && C > 0) {
		if (t == 0) {
			C -= B;
			t = 1;
		}
		else A -= D, t = 0;
	}
	puts(A > 0 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int ans = a - b * 2;
    if (ans < 0) {
        cout << "0" << endl;
    }
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <vector>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector <int> h(n),dp(n,INT_MAX);
	for(int i=0;i<n;i++) cin>>h[i];
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=1;j<=k;j++){
			if(i+j<n){
			dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
			}
		}
	}
	cout<<dp[n-1];
	return 0;
} 

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(a-b>=0)
    {
        cout<<"delicious"<<endl;

    }
    else if(x>=abs(b-a))
    {
        cout<<"safe"<<endl;
    }
    else
    {
        cout<<"dangerous"<<endl;
    }
}


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

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

int main(){
    int n, m, ans = 0;
    string s, t;

    cin >> n >> m;
    cin >> s >> t;

    long long lcd = s.size() * t.size() / gcd(s.size(), t.size());
    long long c = lcd / s.size() * lcd / t.size() / gcd(lcd / s.size(), lcd / t.size());

    for(int i=0; i <= lcd/c; ++i){
        if(s[c / (lcd / s.size()) * i] != t[c / (lcd / t.size()) * i]){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << lcd << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
vi alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main() {
	ll a,b,x;
  	cin>>a>>b>>x;
  	ll count=0;
  	ll aq=a/x;
  	ll ar=a%x;
  	ll bq=b/x;
  	ll br=b%x;
  	if(ar==0){
    	count = bq-aq+1;
    }
  	else{
    	count =bq-aq;
    }
  	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

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

const int MOD = 1e9+7;

int main() {
  int N, M;
  cin >> N >> M;
  if(abs(N-M) > 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<ll> fact(max(N, M)+1);
  fact[1] = 1;
  for(int i = 2; i <= max(N, M); i++)
    fact[i] = fact[i-1]*i%MOD;
  ll ans = fact[N];
  ans = ans*fact[M]%MOD;
  if(N == M)
    ans = ans*2%MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

bool ask(long n){
  cout << "? " << n << endl;
  string ans;

  // {
  //   long N = 9999;
  //   string sN = to_string(N);
  //   string sn = to_string(n);
  //   return (n<=N && sn<=sN) || (n>N && sn>sN);
  // }

  cin>>ans;
  return ans=="Y";
}

int main(){
  long dig = 1;

const long XX = 10000000000LL;
  while(dig <= XX && ask(dig)) dig *= 10L;
  dig /= 10;

  if(dig == XX){
    dig = 1;
    while(!ask(dig*10 - 1)) dig *= 10;

    cout << "! " << dig << endl;
    return 0;
  }

  long l = dig, r = dig*10;
  while(r-l>1){
    long m = (r+l)/2;
    if(ask(m*10)) r = m;
    else l = m;
  }

  cout << "! " << r << endl;

  return 0;
}


Measured memory_bytes: 648
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    long n;
    int k;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        if(n <= 2){
            sb.Append("0\n");
            return;
        }
        long m = (n-2) % 11;
        long mc = 0;
        long count = 0;
        for(int i=0;i<11;i++){
            if(m == i){
                mc = count;
            }
            for(int j=0;j<5;j++){
                if((8*i+9*j+4)%11 == k){
                    count++;
                }
            }
        }
        sb.Append((count*((n-2)/11))+mc);
        sb.Append("\n");
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        n = Int64.Parse(str[0]);
        k = int.Parse(str[1]);
    }    
}

Measured memory_bytes: 2904
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string s;
int n;
int y, x, M[9][9];
int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };

void solve(int y,int x){
	M[y][x] = 0;

	for (int i = 0; i < 4; i++){
		for (int j = 1; j <= 3; j++){
			int ny = y + dy[i] * j, nx = x + dx[i] * j;
			if (ny >= 1 && ny <= 8 && nx >= 1 && nx <= 8){
				if (M[ny][nx] == 1)solve(ny, nx);
			}
		}
	}
}

int main(){
	cin >> n;
	REP(i, n){
		FOR(j, 1, 9){
			cin >> s;
			FOR(k, 1, 9){
				M[j][k] = s[k - 1] - '0';
			}
		}
		cin >> x >> y;
		solve(y, x);
		cout << "Data " << i + 1 << ":" << endl;
		FOR(j, 1, 9){
			FOR(k, 1, 9){
				cout << M[j][k];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 1196
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int beki(int n){
	int res = 0;
	while(n%2==0){
		res++;
		n /= 2;
	}
	return res;
}
int main(){
	int N;
	cin >> N;
	int times = 0;
	int ans;
	for(int i=1;i<=N;i++){
		if(times <= beki(i)){
			ans = i;
			times = beki(i);
		}
	}
	cout << ans <<endl;
    
	return 0;
}

Measured memory_bytes: 256
//#define NDEBUG

#include <bits/stdc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define B back()
#define FR front()
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define modadd(a, b) (((a % MOD) + (b % MOD)) % MOD)
#define modtimes(a, b) (((a % MOD) * (b % MOD)) % MOD)
#define iceil(a) ((int)ceil(a))
#define ifloor(a) ((int)floor(a))

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

int main(){
    StarBurstStream

    int n;
    cin >> n;

    vector<int> a(n), b(n), c(n);
    vector<ll> dpa(n), dpb(n), dpc(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }

    dpa[0] = a[0];
    dpb[0] = b[0];
    dpc[0] = c[0];

    for(int i = 1; i < n; i++){
        dpa[i] = max(dpb[i - 1] + a[i], dpc[i - 1] + a[i]);
        dpb[i] = max(dpa[i - 1] + b[i], dpc[i - 1] + b[i]);
        dpc[i] = max(dpb[i - 1] + c[i], dpa[i - 1] + c[i]);
    }

    cout << max({dpa[n - 1], dpb[n - 1], dpc[n - 1]}) << "\n";

    return 0;
}

Measured memory_bytes: 3840
function main (input) {
	input = input.trim().split('\n');
  	const n = Number(input[0]);
  	const vs = input[1].split(' ').map(n => Number(n));
  	vs.sort(((a, b) => a  - b);
  	let result = (vs[0] + vs[1])/2;
  	for (let i = 2; i < vs.length; i++) {
      const v = vs[i];
      result = (result + v)/2;
    }
  	console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
#include<stdio.h>

int main()
{
  char  s[100001], *p;
  int  k;

  scanf("%s", s);
  scanf("%d", &k);

  p = s;
  while(*p != '\0'){
    if( ('z' - *p) < k && *p != 'a'){
       k -= 'z'+1 - *p;
       *p = 'a'; 
    }
    p++;
    if( k == 0) break;
  }
  if( k > 0 ){
     p--;
     *p += k % 26;
     k = 0;
   }

  printf("%s\n", s);

  return 0;
} 

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long ll;

int main()
{
	int N,M;
	scanf("%d", &N);
	int t[N];
	struct drink
	{
		int index[100];
		int time[100];
		int diff[100];
	} d;
	int sum = 0;
	int i = 0;
	while (i < N)
	{
		scanf("%d", &t[i]);
		sum += t[i];
		i++;
	}
	scanf("%d", &M);
	i = 0;
	int m,p;
	while (i < M)
	{
		scanf("%d", &d.index[i]);
		scanf("%d", &d.time[i]);
		d.diff[i] = d.time[i] - (t[d.index[i] - 1]);
		// printf("%d\n", sum + d.diff[i]);
		i++;
	}
	i = 0;
	while (i < M)
		printf("%d\n", sum + d.diff[i++]);
	return (0);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	long long n; cin>> n;
	vector<long long> av;
	for(int i = 0; i < n; i++){
		long long a;
		cin >> a;
		av.push_back(a);
	}

	vector<long long> av_origin = av;
	sort(av.rbegin(), av.rend());

	for(int i = 0; i < n; i++){
		int tmp_i = 0;
		if(av_origin[i] == av[tmp_i])tmp_i++;
		// while(av_origin[i] != av[tmp_i]){
		// 	tmp_i++;
		// }
		cout << av[tmp_i] << endl;
	}
}

Measured memory_bytes: 4848