akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

const int MAX = 510000;
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;
    }
}

// 二項係数計算
ll 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() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll h = inl(), w = inl(), a = inl(), b = inl();
        COMinit();
        ll ans = 0;
        rep(i, h - a) {
            ans += COM(b - 1 + i, i) * COM(w - b - 1 + h - i - 1, h - i - 1);
            ans %= mod;
        }
        cout << ans << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 12160
n,m=map(int,input().split())
h=[int(i) for i in input().split()]
rel=[set() for _ in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]<=h[b-1]:
    rel[a-1].add(b)
  if h[a-1]>=h[b-1]:
    rel[b-1].add(a)
ans=0
for l in rel:
  if len(l)==0:
    ans+=1
print(ans)

Measured memory_bytes: 40984
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, k, ans;

ll cb(ll x)
{
	return x*x*x;
}

int main(void)
{
	cin>>n>>k;
	ans+=cb(n/k);
	if(k%2==0) ans+=cb((n+k/2)/k);
	cout<<ans; return 0;
}

Measured memory_bytes: 256
main = do
    [x,y] <- map read . words <$> getLine
    let p a | a == 1 = 300000
            | a == 2 = 200000
            | a == 3 = 100000
            | otherwise = 0
    print . (p x +) . (p y +) $ if x == 1 && y == 1 then 400000 else 0

Measured memory_bytes: 508
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();

		if(a==b) System.out.println(c);
		else if(a==c) System.out.println(b);
		else if(b==c) System.out.println(a);
	}
} 

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

int main() {
  int N;
  int count = 0;
  string s;
  cin >> N >> s;
  for(int i = 0; i < N - 2; i++) {
    if(s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      count++;
    }
  }
  cout << count << endl;
}

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


int main(){

  int s;
  int count=0;
  int max=-1;
  int max_value;
  int buf;
  int value;
  int i;

  scanf("%d",&s);
  if(s==1){
    printf("%d\n",s);
    exit(0);
  }
  
  for(i=1;i<=s;i++){
    value=i;
    while(1){
      buf=value%2;
      if(buf!=1){
        count++;
        if(count>max){
          max=count;
          max_value=i;
        }
      }
      else if(buf==1) break;
      value=value/2;
    }
    count=0;
  }

  printf("%d\n",max_value);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()

using namespace std;

int main(int argc, char const* argv[])
{
    int price[] = { 1, 5, 10, 50, 100, 500 };
    while (1) {
        int p; cin >> p;
        int n[6]; loop (6, i) cin >> n[i];

        if (!p) break;

        int pos = 0;
        loop (6, i) pos += n[i] * price[i];

        int ans = 1<<29;

        for (int change = 0; change <= pos - p; change++) {
            int coins = 0;
            int total_pay = change + p;

            int pay_coin[6] = {};
            for (int i = 5; i >= 0; i--) {
                pay_coin[i] = min(total_pay / price[i], n[i]);
                total_pay -= price[i] * pay_coin[i];
            }

            if (total_pay) break;

            for (int v : pay_coin) coins += v;

            int _change = change;
            for (int i = 5; i >= 0; i--) {
                coins += _change / price[i];
                _change %= price[i];
            }

            ans = min(ans, coins);
        }

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

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

string s;
i64 Q;
deque<char> deq;

int main() {
    cin >> s;
    REP(i, s.length()) {
        deq.push_back(s[i]);
    }

    cin >> Q;
    i64 t, fi;
    char ci;
    bool reversed = false;
    REP(i, Q) {
        cin >> t;
        if (t == 1) {
            reversed = !reversed;
        } else {
            cin >> fi >> ci;
            fi = (fi - 1 + reversed) % 2 + 1;
            if (fi == 1) {
                deq.push_front(ci);
            } else {
                deq.push_back(ci);
            }
        }
    }

    if (reversed) {
        RREP(i, deq.size()) {
            cout << deq[i];
        }
    } else {
        REP(i, deq.size()) {
            cout << deq[i];
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 976
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  vector<int>vec;
  for(int i=0;i<10;i++){
    cin>>n;
    vec.push_back(n);
  }
  sort(vec.begin(),vec.end(),greater<int>());
  for(int i=0;i<3;i++){
    cout<<vec[i]<<'\n';
  }
  return(0);
}



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

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

    int d = 0;
    for(int i=1; i<=100000000; i*=10){
        d += (n/i)%10;
    }
    
    if(n%d == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
  
    return 0;
}


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

using namespace std;

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

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

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


int f(int a, int b){
    a++,b++;
    return a*600+b;
}
pii g(int a){
    int x = a/600;
    int y = a%600;
    x--,y--;
    return pii(x,y);
}

signed main(void) {
    int n,m;
    int num[2];
    cin >> n >> num[0] >> num[1] >> m;
    vector<map<int,int> > ma(2);
    rep(i,2)rep(j,n)rep(k,n){
        int in;
        cin >> in;
        ma[i][in] = f(j,k);
    }
    vi x(m);
    rep(i,m)cin >> x[i];

    vi ans(2,INF);
    rep(t,2){
        if(n == 1){
            rep(i,m){
                if(ma[t][x[i]] > 0 && num[t] == 1){
                    ans[t] = i;
                    break;
                }
            }
        }else{
            int a[500] = {};
            int b[500] = {};
            int c[2] = {};
            int cnt = 0;
            rep(i,m){
                if(ma[t][x[i]] == 0)continue;
                pii p = g(ma[t][x[i]]);
                int x = p.first;
                int y = p.second;
                a[x]++;
                if(a[x] == n)cnt++;
                b[y]++;
                if(b[y] == n)cnt++;
                if(x == y){
                    c[0]++;
                    if(c[0] == n)cnt++;
                }
                if(x == n-1-y){
                    c[1]++;
                    if(c[1] == n)cnt++;
                }
                if(cnt >= num[t]){
                    ans[t] = i;
                    break;
                }
            }
        }
    }
    if(ans[0] < ans[1]){
        cout << "USAGI" << endl;
    }else if(ans[0] > ans[1]){
        cout << "NEKO" << endl;
    }else{
        cout << "DRAW" << endl;
    }
}



Measured memory_bytes: 23240
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

const int N = 100100;
int a[N];
int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n,greater<int>());
	int v;
	for(v = 0; v < n; v++){
		if(v >= a[v]){
			break;
		}
	}
	v--;
	int k;
	for(k = v; k < n; k++){
		if(v > a[k]-1){
			break;
		}
	}

	//printf("%d %d\n",v,k);
	if((k-v-1)%2==0 && (a[v]-v-1)%2==0){
		puts("Second");
	}
	else puts("First");


}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		
			int n=scn.nextInt();
			long []arr =new long[n];
			for(int i=0;i<n;i++){
				arr[i]=scn.nextLong();
			}
			long max=0;
			long ans=0;
			for(int i=0;i<n;i++){
				if(arr[i]>max){
					max=arr[i];
				}else{
					ans+=(max-arr[i]);
				}
			}
		System.out.println(ans);

	}

}

Measured memory_bytes: 61000
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forN(i, n) for(int i = 0; i <n ; ++i)
#define endl "\n"
#define noob (main)
typedef long long ll;
using namespace  std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int N = 2e5 +5 ;
int n,m,s,c,num[4];

int noob(){
    cin>>n>>m;
    fastIO
    memset(num,-1,sizeof num);
    while(m--){
        cin>>s>>c;
        if(num[s]!=-1 && num[s]!=c){
            cout<<-1;
            return 0;
        }
        num[s] = c;
    }
    if(n>1 && !num[1]){
        cout<<-1;
        return 0;
    }
    if(n==1 && num[1] ==-1){
        cout<<0;
        return 0;
    }
    for(int i =1 ; i<=n;i++){
        if(i==1 &&num[i]==-1)cout<<1;
        else if (num[i]==-1)cout<<0;
        else cout<<num[i];
    }
}



Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;

class Main{



	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		int N =sc.nextInt();

		int[] X = new int[N];


		for(int i = 0;i < N;i++){
			X[i] = sc.nextInt();
		}

		Arrays.sort(X);
		int max = X[N-1];		//最大値

		int key = (max+1)/2;
		int ans = 0;
		for(int i = 0;i < N-1 ;i++){
			if(Math.abs(key-ans) > Math.abs(key-X[i])){
				ans =X[i];
			}

		}
		System.out.println(max+" "+ans);



	}

	static long comb(int n,int r){
		long ue = 1;
		for(int i = 0;i < r;i++){
			ue *= n-i;
		}
		long sita = 1;
		for(int i = 1;i <= r;i++){
			sita *= i;
		}
		return ue/sita;


	}





}




class Pair implements Comparable{
	String from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}





Measured memory_bytes: 50816
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int x, t;
    cin >> x >> t;
    cout << max(0,x-t) << endl;

    return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> s={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
  
  int K; cin>>K;
  cout<<s.at(K-1)<<endl;
}


Measured memory_bytes: 256
import time
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

def No():
    print(-1)
    exit()


N,M=input_int_list()
s_c_tuple_list=[input_int_list() for i in range(M)]
the_dict={}
for tup in s_c_tuple_list:
    s,c=tup
    if s==1 and c==0:
        if N==1:
            pass
        else:
            No()
    if s in the_dict:
        if the_dict[s]==c:
            pass
        else:
            No()
    else:
        the_dict[s]=c

if 1 not in the_dict:
    if N==1:
        the_dict[1]=0
    else:
        the_dict[1]=1
the_num=int("".join([str(the_dict[i+1]) if i+1 in the_dict else str(0) for i in range(N)]))

print(the_num)


Measured memory_bytes: 3064
import math
N,H=[int(x) for x in input().split()]
a=[]
b=[]
for i in range(N):
    A,B=[int(x) for x in input().split()]
    a.append(A)
    b.append(B)
am = max(a)
b.sort(reverse=True)

count = 0
for i in b:
    if i < am:
        break
    else:
        H -= i
        count += 1
    if H <= 0:
        break
if H > 0:
    count += math.ceil(H/am)
print(count)        


Measured memory_bytes: 11312
/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 13-Sep-2020 18:00:58
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;


int solve() {
    int x; Int(x);
    cout << (x ^ 1) << endl;

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}

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

bool search(int x, int y, vector<int> vec)
{
  auto resultX = find(vec.begin(), vec.end(), x);
  auto resultY = find(vec.begin(), vec.end(), y);
  
  if((resultX != vec.end()) && (resultY != vec.end()))
    return true;
  else 
    return false;
}

int main()
{
  int x, y;
  cin >> x >> y;
  
  vector<int> vec1 = {1, 3, 5, 7, 8, 10, 12};
  vector<int> vec2 = {4, 6, 9, 11};
  vector<int> vec3 = {2};
  
  if(search(x, y, vec1) || search(x, y, vec2) || search(x, y, vec3))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
class Tree:
    __slots__ = ['id', 'p', 'depth', 'type', 'c']
    def __init__(self):
        self.id = 0
        self.p = -1
        self.depth = -1
        self.type = "leaf"
        self.c = []
    def __str__(self):
        return f"node {self.id}: parent = {self.p}, depth = {self.depth}, {self.type}, {self.c}"
n = int(input())
li = [Tree() for _ in range(n)]
for _ in range(n):
    id, k, *c = map(int, readline().split())
    if k == 0:
        c = []
    else:
        li[id].type = "internal node"
    li[id].id = id
    li[id].c = c
    for j in c:
        li[j].p = id
root = 0
while True:
    a = li[root].p
    if a == -1:
        li[root].type = "root"
        li[root].depth = 0
        break
    root = a
dp = [(root, 0)]
while dp:
    id, d = dp.pop()
    d += 1
    for i in li[id].c:
        li[i].depth = d
        dp.append((i, d))
print(*li, sep="\n")



Measured memory_bytes: 34840
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_108
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int x1 = int.Parse(input[0]);
            int y1 = int.Parse(input[1]);
            int x2 = int.Parse(input[2]);
            int y2 = int.Parse(input[3]);

            int x3, y3, x4, y4;

            /*if (x1 == x2)
            {
                int length = Math.Abs(y2 - y1);
                if (y1 < y2)
                {
                    x3 = x1 - length;
                }
                else
                {
                    x3 = x1 + length;
                }
                x4 = x3;
                y3 = y2;
                y4 = y1;
            }
            else
            {
                int length = Math.Abs(x2 - x1);
                if (x1 < x2)
                {
                    y3 = y1 + length;
                }
                else
                {
                    y3 = y1 - length;
                }
                y4 = y3;
                x3 = x2;
                x4 = x1;
            }*/

            x3 = x2 - (y2 - y1);
            y3 = y2 + (x2 - x1);
            x4 = x3 - (x2 - x1);
            y4 = y3 - (y2 - y1);

            Console.WriteLine(x3+" "+y3+" "+ x4 + " " + y4);
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<40))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll n,X;
ll x[200010];
ll cumx[200010];
int main(){
	scanf("%lld%lld",&n,&X);
	rep(i,0,n)scanf("%lld",x+i);
	rep(i,0,n)cumx[i+1]=cumx[i]+x[i];
	
	ll ans=INF;
	//往復回数を全探索
	rep(j,1,n+1){
		//1なら19/17/15/13/11/ 9/ 7/ 5/ 5
		//2なら11/ 9, 9/ 7, 7/ 5, 5/ 5, 5
		//3なら 7, 7, 7/ 5, 5, 5/ 5, 5, 5　というかんじ
		ll temp=0,amp=3;
		for(int i=n;i>0;i-=j,amp+=2){
			temp+=(cumx[i]-cumx[max(0,i-j)])*amp;
			//j=nのときのcumx[n]*5+j*X+n*X~~1.4e15が自明な上界なのでそれ以上は打ち切り
			if(temp>2e15)break;
		}
		temp+=(cumx[n]-cumx[n-j])*2+j*X;
		ans=min(ans,temp);
	}
	printf("%lld\n",ans+n*X);
}

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

int main(){
  int n;
  cin >> n ;
  vector<ll> a(n);
  for(int i= 0; i< n; i++)cin >> a[i];
  sort(a.begin(), a.end());
  ll amax = a[n-1];
  vector<ll> p(amax+5);

 for(int i =0; i< n; i++){
   for(int j = a[i]; j < amax + 5 ; j += a[i]){
      p[j]++;
    }
 }
ll ans = 0;
 for(auto x :a){
    if(p[x]==1) ans ++;
 }
cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12556
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
from itertools import accumulate
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def floor(a, b): return -(-a // b)


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True


a, b = zz()
ans = 0
for num in range(a, b + 1):
    if is_kaibun(str(num)):
        ans += 1
print(ans)


Measured memory_bytes: 74628
code = r"""
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False
from libc.stdio cimport getchar, printf
cdef extern from "/opt/atcoder-stl/atcoder/math.hpp" namespace "atcoder":
    cdef long long floor_sum(long long n, long long m, long long a, long long b)
cdef long long cin() nogil:
    cdef long long b, c = 0
    while 1:
        b = getchar() - 48
        if b < 0: break
        c = c * 10 + b
    return c
cdef int i, t = cin()
cdef long long n, m, a, b
for i in range(t):
    n = cin()
    m = cin()
    a = cin()
    b = cin()
    printf('%lld\n', floor_sum(n, m, a, b))
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);



int main() {

    int a, b, x;
    cin >> a >> b >> x;

    if((a + b) < x ) {
        cout << "NO" << endl;
        return 0;
    }

    if(a > x) {
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;

}


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

int main(){
	int l, r, ans = 2020;
	cin >> l >> r;
	int count = 0;
	while(l < r && count < 2020){
		int tl = l % 2019;
		int tl2 = l+1;
		int c2 = 0;
		for( ; tl2 <= r && c2 < 2020; tl2++, c2++){
			int tll2 = (tl2)%2019;
			ans = min(ans, (tl*tll2)%2019);
		}
		
		count++;
		l++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
/* kadai3_2
   reo012 */

#include<stdio.h>

int main(void){
  int num, ones;
  // 何本であるか取得
  scanf("%d", &num);

  // numの一の位(ones)を求める
  ones = num%10;

  //一の位ごとにhon/pon/bonを出力
  switch(ones){
    case 2: case 4: case 5: case 7: case 9:
      printf("hon\n"); break;
    case 0: case 1: case 6: case 8:
      printf("pon\n"); break;
    case 3:
      printf("bon\n"); break;
    default:
      break;
  }
  return 0;
}


Measured memory_bytes: 1616
/* Hello darkness my old friend, I've come to visit you again! */

#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1000000005
#define INF 1000000000000000005
#define io ios_base::sync_with_stdio(0);
#define ff first
#define ss second
using namespace std;

int main()
{
    io;
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a*b,a-b));
    return 0;
}

/* This is the end, beautiful friend! */


Measured memory_bytes: 892
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int a = in.nextInt();
            char ope = in.next().charAt(0);
            int b = in.nextInt();

            if (ope == '+') {
                out.println(a + b);
            } else if (ope == '-') {
                out.println(a - b);
            }

        }

    }
}



Measured memory_bytes: 21844
N, K = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(K)]
 
# dpの高速化 => 累積和によって、O(N)で解く
dp = [0] * N
acc = [0]* (N+1)
dp[0], acc[1] = 1, 1
# acc[0] = 0
# acc[1] = dp[0]
# acc[2] = dp[0] + dp[1]
# acc[n] = dp[0] + dp[1] + dp[n-1]

# dp[0] = acc[1] - acc[0]
# dp[1] = acc[2] - acc[1]
# dp[n-1] = acc[n] - acc[n-1]
mod = 998244353
 
for i in range(1, N):
  # acc[i] = dp[0] + ... + dp[i-1] が既知
  # 貰うdp
  for j in range(K):
    r = i - X[j][0]
    l = i - X[j][1]
    if r < 0: continue
    l = max(l, 0)
      
    dp[i] += acc[r+1] - acc[l] # s = dp[L] + ... + dp[R]
    dp[i] %= mod
  acc[i+1] = acc[i] + dp[i] # acc[i+1] = dp[0] + ... + dp[i]

print(dp[N-1])

Measured memory_bytes: 27976
program main
  implicit none
  integer i
  double precision dX, dY, P, ans, A, B, H, M
  read(*, *)A, B, H, M
  !read(*, *) (L(i), i = 1,N)
  P = 3.141592653589793238462643383279d0
  P = 2*P
  P = P/12
  H = H+M/60
  M = M/5
  dX = A*cos(-P*H)-B*cos(-P*M)
  dY = A*sin(-P*H)-B*sin(-P*M)
  ans = (dX**2+dY**2)**(0.5)
  write(*, *) ans
end program main

Measured memory_bytes: 3472
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

char c[105];
int l;

int main(void){
	scanf("%s",c+1);
	int l=strlen(c+1);
	if(l%2==1){
		printf("No\n");
		return 0;
	}
	for(int i=1;i<=l;i++){
		if(i%2==1&&c[i]!='h'){
			printf("No\n");
			return 0;
		}
		else
		if(i%2==0&&c[i]!='i'){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
} 

Measured memory_bytes: 128
import java.util.*;

public class Main{

    static int mod = (int) 1e9 + 7;
    static int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
    static int INF = Integer.MAX_VALUE/2;

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);

        //Queue<int[]> q = new ArrayDeque<int[]>();
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        if(((a==b)&&(b!=c)) || ((b==c)&&(c!=a)) || ((c==a)&&(a!=b)))   
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
    }


}

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

int n,p[100][26];string S[100];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>S[i];
		for(int j=0;j<S[i].size();j++) p[i][S[i][j]-'a']++;
	}
	for(int i=0;i<26;i++){
		int minx=100000;
		for(int j=1;j<=n;j++) minx=min(minx,p[j][i]);
		for(int j=0;j<minx;j++) cout<<(char)('a'+i);
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        int n = Integer.parseInt(br.readLine().trim());
        String s[] = br.readLine().trim().split(" ");
        int cnt=0;
        for(int i=0;i<n;i++) {
            if(i%2==0){
                if(Integer.parseInt(s[i])%2==1) ++cnt;
            }
        }
        out.println(cnt);
        
        br.close();out.flush();out.close();
    }
}

Measured memory_bytes: 32944
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
using namespace std;
#define int long long
#define F first
#define S second
typedef pair<int, int> P;
vector<P>v;
signed main() {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;

	for (int i = n - 1; i > -1; i--) {
		int mn = c*i+a;
		int mx = d*i+a;
		int e = n - 1 - i;
		mn -= e*c;
		mx -= e*d;
		v.push_back(P(mn, mx));
		int ma = a - (c*i);
		int mb = a - (d*i);
		ma += e*d;
		mb += e*c;
		v.push_back(P(min(ma, mb), max(ma, mb)));
	}
	int flg = 0;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].first <= b&&b <= v[i].S)flg++;
	}
	if (flg)puts("YES");
	else puts("NO");
}

Measured memory_bytes: 18664
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;

#include <assert.h>
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    VI a(3);
    REP(i,3) cin >> a[i];
    sort(ALL(a));

    REP(i,100000){
        if (a[0] == a[1] && a[1] == a[2]){
            cout << i << endl;
            return 0;
        }

        if (a[1] < a[2]){
            a[0]++;
            a[1]++;
        }else{
            a[0] += 2;
        }

        sort(ALL(a));
    }


    return 0;
}


Measured memory_bytes: 764
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140156
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <numeric>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mod = 1000000007;

typedef long long num;

#define bs(n) (1ll<<(ll)(n))
#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define rrep(i, n) for(ll (i) = 1;(i) <= (n);(i)++)

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    auto dist = [&N, &X, &Y](int a, int b) {
        int d1 = abs(a - b);
        int d2 = abs(a - X) + abs(b - Y) + 1;
        int d3 = abs(a - Y) + abs(b - X) + 1;
        return min(d1, min(d2, d3));
    };
    int *r = new int[N];
    memset(r, 0, sizeof(int[N]));
    for (int i = 1; i <= N; i++)
        for (int j = i + 1; j <= N; j++) {
            int d = dist(i, j);
            r[d]++;
        }
    for (int i = 1; i < N; i++) cout << r[i] << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  int a = 0;
  F0R(i, s.size()) {
    a += s[i] - '0';
  }
  cout << (a % 9 == 0 ? "Yes" : "No");
}
#endif


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()


using pi = pair<int, int>;
#define INF 0x3f3f3f3f


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("o2.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n;
    cin>>n;
    while(n)
    {
        if(n%10 == 7)
        {
            cout<<"Yes";
            return 0;
        }
        n/=10;
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner (System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int s[][]=new int[n][m];
		for(int i=0;i<n;i++) {
			String c=sc.next();
			for(int j=0;j<m;j++)
				if(c.substring(j,j+1).equals("#"))s[i][j]=-1;
		}
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if(s[i][j]==-1) {
					for(int y=i-1;y<=i+1;y++) {
						for(int x=j-1;x<=j+1;x++) {
							if(y>=0&&y<n&&x>=0&&x<m) {
								if(s[y][x]>-1)s[y][x]++;
							}
						}
					}
				}
			}
		}
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				System.out.print(s[i][j]<0?"#":s[i][j]);
			}
			System.out.println();
		}
	}
}

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

int main(){
  int n,k,q;
  cin>>n >>k >>q;
  vector<int> peo(n,k-q);
  
  for(int i=0;i<q;i++){
    int a; cin>>a;
    a--;
    peo[a]++;
  }
  
  for(int i=0;i<n;i++){
    if(peo[i]>0){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define y0    lol
#define y1    lool
#define yn    loool
#define prev  looool
#define next  loooool
#define read  looooool
#define tm    loooooool
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#ifdef LOCAL
#define rall(x,a) for(x : a)
#define LL "%lld"
#else
#define rall(x,a) for(auto x : a)
#define LL "%I64d"
#endif
#define rng(a) a.begin(), a.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, t;
    cin >> a >> b >> t;
    int ans = t / a * b;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define pq priority_queue
#define MZ 1000000007

long long num[200005];
long long sum[2][200005];
int L[200005],R[200005];

int main()
{
    int n;
    long long ans=1000000000000007LL;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld",&num[i]);
    for(int i=1;i<=n;i++)
    {
        sum[0][i]=sum[0][i-1]+num[i];
        L[i]=L[i-1];
        while(sum[0][L[i]+1]*2<=sum[0][i])
            L[i]++;
    }
    R[n+1]=n+1;
    for(int i=n;i;i--)
    {
        sum[1][i]=sum[1][i+1]+num[i];
        R[i]=R[i+1];
        while(sum[1][R[i]-1]*2<=sum[1][i])
            R[i]--;
    }
    for(int i=2;i<n-1;i++)
    {
        if(L[i]>0 && R[i+1]<n+1)
           ans=min(ans,max(max(sum[0][L[i]],sum[0][i]-sum[0][L[i]]),max(sum[1][R[i+1]],sum[1][i+1]-sum[1][R[i+1]]))-min(min(sum[0][L[i]],sum[0][i]-sum[0][L[i]]),min(sum[1][R[i+1]],sum[1][i+1]-sum[1][R[i+1]])));
        if(L[i]+1<i && R[i+1]<n+1)
           ans=min(ans,max(max(sum[0][L[i]+1],sum[0][i]-sum[0][L[i]+1]),max(sum[1][R[i+1]],sum[1][i+1]-sum[1][R[i+1]]))-min(min(sum[0][L[i]+1],sum[0][i]-sum[0][L[i]+1]),min(sum[1][R[i+1]],sum[1][i+1]-sum[1][R[i+1]])));
        if(L[i]>0 && R[i+1]-1>i+1)
           ans=min(ans,max(max(sum[0][L[i]],sum[0][i]-sum[0][L[i]]),max(sum[1][R[i+1]-1],sum[1][i+1]-sum[1][R[i+1]-1]))-min(min(sum[0][L[i]],sum[0][i]-sum[0][L[i]]),min(sum[1][R[i+1]-1],sum[1][i+1]-sum[1][R[i+1]-1])));
        if(L[i]+1<i && R[i+1]-1>i+1)
           ans=min(ans,max(max(sum[0][L[i]+1],sum[0][i]-sum[0][L[i]+1]),max(sum[1][R[i+1]-1],sum[1][i+1]-sum[1][R[i+1]-1]))-min(min(sum[0][L[i]+1],sum[0][i]-sum[0][L[i]+1]),min(sum[1][R[i+1]-1],sum[1][i+1]-sum[1][R[i+1]-1])));
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include <limits>
#include <iomanip>
#include <map>

using namespace std;

int main(){
	long long int n,k;
	long long int ans=0;
	
	cin >> n >> k;
	
	vector<int> v(n);
	
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	
	sort(v.begin(),v.end());
	
	if(k >= n){
		cout << 0 << endl;
		return 0;
	}
	else{
		for(int i=0;i<k;i++){
			v.pop_back();
		}
	}
	
	for(int i=0;i<v.size();i++){
		ans += v[i];
	}
	
	cout << ans << endl;
	
	return 0;
}

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

int main(){
    string s;cin>>s;
    int j['Z']={0};

    for(int i=0;i<s.length();i++){
        if(s[i]=='N') j['N']=1;
        if(s[i]=='W') j['W']=1;
        if(s[i]=='S') j['S']=1;
        if(s[i]=='E') j['E']=1;
    }
    
    if(j['N'] ^ j['S'] || j['W'] ^ j['E']) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll sum=0;
    ll M=0;
    ll g=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        M=max(M,a[i]);
        sum+=a[i];
    }
    

    sort(a,a+n);
    set<int,greater<int>> v;
    for(int i=1;i*i<=sum;i++){
        if(sum%i==0){

            v.insert(i);
            v.insert(sum/i);
            
        }
    }

    for(auto div:v){
        int cnt[n]={};
        ll sum=0;
        for(int i=0;i<n;i++){
            cnt[i] = a[i]%div;
            sum+=(div-cnt[i])%div; 
        }
        sort(cnt,cnt+n);
        ll sum2=0;

        for(int i=0;i<n;i++){
            sum2+=cnt[i];
            sum-=(div-cnt[i])%div;
            if(sum2==sum && sum2<=k){
                cout<<div<<endl;
                return 0;
            }
        }


    }



    

}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

string S,T;

int main() {
	cin >> S;
	T = S;
	int N = S.length();
	int ans1 = 0, ans2 = 0;

	for (int i = 0; i < N-1; i++) {
		if (S[i] == S[i + 1]) {
			if (S[i + 1] == '0') {
				S[i + 1] = '1';
				ans1++;
			}
			else {
				S[i + 1] = '0';
				ans1++;
			}
		}
	}

	for (int i = N - 1; i > 0; i--) {
		if (T[i] == T[i - 1]) {
			if (T[i - 1] == '0') {
				T[i - 1] == '1';
				ans2++;
			}
			else {
				T[i - 1] == '0';
				ans2++;
			}
		}
	}

	cout << ans1 << endl;
	//cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 512
//wawando's template

#include <iostream>
#include <string>
#include <fstream>
#include <functional>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <set>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>  //clock_t , clock() , CLOCKS_PER_SEC
#include <cstring>
#include <cctype>
#include <climits> // LLONG_MAX , LLONG_MIN , INT_MAX , INT_MIN

//MACROS
#define pb              push_back
#define mp              make_pair
#define INF             1000000000     //1 billion safer for floyd warshall, avoid overflow

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

vi pset, setSize;
int numDis;

void initSet(int N) {setSize.assign(N,1);pset.assign(N,0);numDis=N; for(int i=0;i<N;i++)pset[i]=i;}
int findSet(int i) {return(pset[i]==i)?i:(pset[i]=findSet(pset[i]));}
bool isSameSet(int i, int j) {return findSet(i)==findSet(j);}
void unionSet(int i, int j) {
  if (!isSameSet(i, j)){
    numDis--;
    setSize[findSet(j)]+=setSize[findSet(i)];
    pset[findSet(i)]=findSet(j);}}
int sizeOfSet(int i){return setSize[findSet(i)];}

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	//ios::sync_with_stdio(false);
  int N, M;
  scanf("%d %d", &N, &M);
  initSet(N);
  for(int i = 0; i < M; i++) {
    int u,v,w;
    scanf("%d %d %d", &u, &v, &w);
    unionSet(u-1, v-1);
  }
  printf("%d\n", numDis);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
// ascending order
#define asort(array, N) sort(array, array + N)
// descending order
#define asort_r(array, N) sort(array, array + N, greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int A, B, C, D, E, F;

float calCon(int w, int s) {
	return 100.0 * s / (w + s);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> A >> B >> C >> D >> E >> F;

	vector<int> x;
	vector<int> y;

	for(int i = 0; 100 * A * i + 1<= F; i++) {
		for(int j = 0; 100 * B * j + 1<= F; j++) {
			x.push_back(100 * A * i + 100 * B * j);
		}
	}

	for(int i = 0; C * i <= F; i++) {
		for(int j = 0; D * j <= F; j++) {
			y.push_back(C * i + D * j);
		}
	}

	int ans1 = 0;
	int ans2 = 0;
	float maxCon = -1.0;

	for(int i = 0; i < x.size(); i++) {
		for(int j = 0; j < y.size(); j++) {
			int tmpX = x[i];
			int tmpY = y[j];
			if(tmpX + tmpY > F) continue;
			if(100 * tmpY > E * tmpX) continue;
			if(maxCon < calCon(tmpX, tmpY)) {
				maxCon = calCon(tmpX, tmpY);
				ans1 = tmpX + tmpY;
				ans2 = tmpY;
			}
		}
	}
	cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 2420
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#define int long long
using namespace std;

signed main() {
	int n, m; cin >> n >> m;
	map<int,int>S;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b; a--; b--;
		if (a > b)swap(a, b);
		S[a*n + b] = true;
	}
	for (int j = 1; j < n - 1; j++) {
		if (S[j]&&S[j*n + n - 1]) {
			puts("POSSIBLE");
			return 0;
		}
	}
	puts("IMPOSSIBLE");
}

Measured memory_bytes: 25216