akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;*/

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    //freopen("connect_the_dots.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n,d;
    cin >> n >> d;
    d = d * 2 + 1;
    cout << (n+(d-1))/d << endl;
}



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

int main(){
  int N;
  vector<int64_t> A(200010);

  cin >> N;
  for(int i=1; i<=N; i++){
    cin >> A[i-1];
    A[i-1] -= i;
  }
  sort(A.begin(), A.begin()+N);

  int64_t median;
  if(N % 2 != 0){
    median = A[(N-1)/2];
  } else {
    median = (A[N/2] + A[N/2-1])/2;
  }

  int64_t ans = 0;
  for(int i=0; i<N; i++) ans += abs(A[i]-median);
  cout << ans <<endl;
}

Measured memory_bytes: 1792
N , M = map(int , input().split())
A = list(map(int, input().split()))
count = 0
A_sorted = sorted(A , reverse = True)
for i in range(M):
    if A_sorted[i] >= (sum(A) / (4*M)):
        count += 1
if count == M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
def f(prev):

    if prev % 2 == 0 :
        return int(prev//2)
    else:
        return int(3*prev + 1)




def collatz(s):
    nset = set()
    a_n = s
    for n in range(1,1000000):
        if a_n in nset:
            return n
        else:
            nset.add( a_n )

        a_n = f(a_n)



s = int( input())

n = collatz(s)

print(n)





Measured memory_bytes: 3060
n = gets.to_i
w = []
d = Hash.new {0}
n.times do |i|
	w[i] = gets.chomp
	d[w[i]] += 1
end

l = ""
n.times do |i|


	if d[w[i]] != 1
		puts "No"
		exit
	end

	ww=w[i]

	if i != 0
		if l != ww[0]
			puts "No"
			exit
		end
	end

	l = ww[ww.length-1]
end

puts "Yes"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-conversion"

#define NDEBUG
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
using uint = unsigned int;
using usize = std::size_t;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<typename T> constexpr T popcount(const T u) { return u ? static_cast<T>(__builtin_popcountll(static_cast<u64>(u))) : static_cast<T>(0); }
template<typename T> constexpr T log2p1(const T u) { return u ? static_cast<T>(64 - __builtin_clzll(static_cast<u64>(u))) : static_cast<T>(0); }
template<typename T> constexpr T msbp1(const T u) { return log2p1(u); }
template<typename T> constexpr T lsbp1(const T u) { return __builtin_ffsll(u); }
template<typename T> constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast<T>(u); }
template<typename T> constexpr bool ispow2(const T u) { return u and (static_cast<u64>(u) & static_cast<u64>(u - 1)) == 0; }
template<typename T> constexpr T ceil2(const T u) { return static_cast<T>(1) << clog(u); }
template<typename T> constexpr T floor2(const T u) { return u == 0 ? static_cast<T>(0) : static_cast<T>(1) << (log2p1(u) - 1); }
template<typename T> constexpr bool btest(const T mask, const usize ind) { return ((static_cast<u64>(mask) >> ind) & static_cast<u64>(1)); }
template<typename T> constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast<T>(0) : static_cast<T>((static_cast<u64>(mask) << (64 - ind)) >> (64 - ind)); }
template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); }
template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); }
constexpr unsigned int mod                  = 1000000007;
template<typename T> constexpr T inf_v      = std::numeric_limits<T>::max() / 4;
template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884};
template<typename T>
T read()
{
    T v;
    return std::cin >> v, v;
}
template<typename T>
std::vector<T> read_vec(const std::size_t size)
{
    std::vector<T> v(size);
    for (auto& e : v) { std::cin >> e; }
    return v;
}
template<typename... Types>
auto read_vals() { return std::tuple<std::decay_t<Types>...>{read<Types>()...}; }
#define SHOW(...) static_cast<void>(0)
template<typename T>
std::vector<T> make_v(const std::size_t size, T v) { return std::vector<T>(size, v); }
template<class... Args>
auto make_v(const std::size_t size, Args... args) { return std::vector<decltype(make_v(args...))>(size, make_v(args...)); }
int main()
{
    const auto n        = read<usize>();
    const auto a        = read_vec<usize>(n);
    const usize s       = std::accumulate(a.begin(), a.end(), 0);
    constexpr usize MAX = 2000 * 2000 + 1;
    std::bitset<MAX> dp;
    dp[0] = 1;
    for (usize i = 0; i < n; i++) { dp |= dp << a[i]; }

    for (int i = s / 2; i >= 0; i--) {
        if (dp[i]) { return std::cout << s - i << std::endl, 0; }
    }
    return 0;
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, AB):
    g = defaultdict(set)
    for a, b in AB:
        g[a].add(b)
        g[b].add(a)

    def f(a, b):
        ab = set([a, b])
        stack = [a]
        done = set()
        while stack:
            u = stack.pop()
            for v in g[u]:
                if u in ab and v in ab:
                    continue
                if v not in done:
                    done.add(v)
                    stack.append(v)
        return b not in done

    c = 0
    for a, b in AB:
        if f(a, b):
            c += 1

    return c


def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(M)]
    print(slv(N, M, AB))


if __name__ == '__main__':
    main()


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

int a[400000];
ll sum[400000];

int C(int l,int r){//(l,r]
	int lb=l,rb=r;
	while(rb-lb>1){
		int mb=(rb+lb)/2;//(l,mb],(mb,r]
		if(sum[mb]-(l>=0?sum[l]:0)<sum[r]-sum[mb])lb=mb;
		else rb=mb;
	}
	return lb;
}
int main(){
	int n;cin>>n;
	rep(i,n)scanf("%d",&a[i]);
	rep(i,n)sum[i]=a[i];
	for(int i=1;i<n;i++)sum[i]+=sum[i-1];
	ll ans=LLONG_MAX;
	for(int i=1;i<n-2;i++){
		int b=C(-1,i),c=C(i,n-1);
		rep(t,2)rep(l,2){
			int j=b+t,k=c+l;//(-1,j](j,i](i,k](k,n-1]
			if(j==-1||j==i||k==i||k==n-1)continue;
			ll Min=min({sum[j],sum[i]-sum[j],sum[k]-sum[i],sum[n-1]-sum[k]});
			ll Max=max({sum[j],sum[i]-sum[j],sum[k]-sum[i],sum[n-1]-sum[k]});
			ans=min(ans,Max-Min);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3840
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <stack>
//#include <atcoder/all>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
//using namespace atcoder;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
}

lli gcd2(lli x, lli y)
{
    lli t;
    while (y != 0)
        t = x % y, x = y, y = t;
    return (x);
}

lli lcm2(lli x, lli y)
{
    lli xy = x * y;
    if (xy < 0)
        xy = -xy;
    return (xy / gcd2(x, y));
}
lli m = 1e9 + 7;
int main(void)
{
    lli N;
    cin >> N;
    if (N % 2 == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    else
    {
        lli div = 10;
        lli ans = 0;
        while (div <= N)
        {
            ans += (lli)(N / div);
            div *= 5;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>

using namespace std;

int N, Q;
int A[100005], B[100005], C[100005];
int O[100005];

void solve() {
  long long S = 0;
  for (int i = 0; i < N; i++) {
    S += A[i];
    O[A[i]]++;
  }

  for (int i = 0; i < Q; i++) {
    S += (C[i] - B[i]) * O[B[i]];
    O[C[i]] += O[B[i]];
    O[B[i]] = 0;
    printf("%lld\n", S);
  }
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A+i);
  }

  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d %d", B+i, C+i);
  }

  solve();
}


Measured memory_bytes: 5364
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  int n = s.size();
  for(int i = 0; i < n; i++){
    if(i < n-1 && s[i] == s[i+1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }else if(i < n-2 && s[i] == s[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << "-1 -1" << endl;
  return 0;
}

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

void dfs(int d, long long val, vector<long long> & all) {
	all.push_back(val);
	if (d == 10) return;

	for (int i = -1; i <= 1; i++) {
		int add = (val % 10) + i;
		if (add >= 0 & add <= 9) {
			dfs(d + 1, val * 10 + add, all);
		}
	}
}

int main(void) {
	int K; cin >> K;
	vector<long long> all;
	for (int i = 1; i < 10; i++) {
		dfs(1, i, all);
	}

	sort(all.begin(), all.end());
	cout << all[K - 1] << endl;

	return 0;
}

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

int main(void) {
	int n, k, i;
	int A[100001];
	scanf("%d %d", &n, &k);
	int min = 99999;
	int mini = -1;
	for (i = 0; i < n; i++) {
		scanf("%d", &A[i]);
		if (min > A[i]) {
			mini = i;
			min = A[i];
		}
	}
	if (k >= n) {
		printf("1\n");
		return 0;
	}

	//left
	int left = mini;
	//int count = 0;
	int count = (n - 1) / (k - 1);
	if ((n - 1) % (k - 1) != 0)count++;
	//if ((n - 1) % (k - 1) == 0)count--;
	//count += left / (k - 1);
	//if (left % (k - 1) != 0)count++;
	

	//right
	int right = n - mini - 1;
	//count += right / (k - 1);
	//if (right % (k - 1) != 0)count++;
	

	//count -= ((left % (k - 1)) + (right % (k - 1)) / (k - 1));
	/*if (((left % (k - 1)) + (right % (k - 1))) == (k - 1)) {
		count--;
	}*/
	

	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 512
n = int(input())

s = input()

white = list([0]*n)
black = list([0]*n)

for i in range(n):
    if s[i] == ".":
        white[i] = (white[i - 1] + 1)
        black[i] = (black[i - 1])
    else:
        white[i] = (white[i - 1])
        black[i] = (black[i - 1] + 1)

res = white[-1]

for i in range(n):
    res = min(white[-1] - white[i] + black[i], res)

print(res)


Measured memory_bytes: 46576
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define POPCNTI(a) __builtin_popcount(a)
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace  __gnu_pbds;

#include <bits/stdc++.h>
 
using namespace std;

 
// #ifndef _LOCAL_DEFINE
// inline int getchar_unlocked(){return _getchar_nolock();}
// inline void putchar_unlocked(char c) {_putchar_nolock(c);}
// #endif
 
typedef long long ll;  
typedef pair<int,int> pr; 
 
const ll MOD = 1e9 + 7,OOl=LLONG_MAX;
const int N = 1e6+1, M = 1e6+1, OO = INT_MAX,OOmem = 0x4f4f4f4f;
 
inline void WRITE_CHAR(char c)  {putchar_unlocked(c);}
 
template<typename T> 
inline bool READn (T &result) {
  int minus = 1;
  char ch;
  result=0;
  ch = (char) getchar_unlocked();
  if(ch!='-') while (!isdigit(ch) && ch!=EOF) ch= (char) getchar_unlocked(), minus = (ch == '-'? -1 : minus);
 
  if(ch==EOF) return false;
  while (isdigit(ch))  result = result*10 + (int) (ch - '0'),ch = (char) getchar_unlocked();
  
  result *= minus;
  return ch != '\n';
}
template<typename T>
inline void WRITEn(T x) {
  if (x < 0) {putchar_unlocked('-'); x = -x; }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = (char)('0' + x % 10);
    x /= 10;
  }
  while (x);
  do  { putchar_unlocked(*--writePtr); }
  while (writePtr > writeBuffer);
}
inline bool Read_CHAR(char &c)
{
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  c = READ_CHARACTER;
  return true;
} 
inline bool READ_CHAR_ARRAY(char (&x)[N]) {
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  char *ptr = &x[0];
  while ((READ_CHARACTER != '\n' && READ_CHARACTER != '\t' && READ_CHARACTER != ' ' && READ_CHARACTER != EOF)) *ptr++ = READ_CHARACTER, READ_CHARACTER = (char)getchar_unlocked();
  *ptr = '\0';
  return true;
}
inline void WRITE_CHAR_ARRAY(const char *x) {
  while(*x != '\0')
    putchar_unlocked(*x++);
}
ll dp[2][N],w[N];
int cst[N];
int n,W,C=0;
int main()
{
  
  READn(n),READn(W);
  for(int i=0;i<n;++i) READn(w[i]),READn(cst[i]),C+=cst[i];
  for(int cost = 1 ; cost<=C ; ++cost) dp[0][cost]=OO,dp[1][cost]=OO;
  dp[0][0]=0;
  dp[1][0]=0;
  for(int i=1;i<=n;++i)
  {
    int k = i&1;
    for(int cost = 1 ; cost<=C ; ++cost)
    {
      dp[k][cost] = dp[!k][cost];
      if(cost>=cst[i-1]) dp[k][cost] = min(dp[k][cost],dp[!k][cost-cst[i-1]]+w[i-1]);
    }
  }
  ll ans = -OO;
  for(int cost = 1 ; cost<=C ; ++cost) if(dp[0][cost]<=W || dp[1][cost]<=W) ans=max(ans,(ll)cost);
  
  
  WRITEn(ans);
  return 0;
}


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

int main() {
  int n,k;
  cin >> n >> k;
  double p[n];
  double e[n];
  double ma =0;
  rep(i,n) {
      cin >> p[i];
      e[i] = (p[i]+1)/2;
  }

  double s[n+1];
  s[0] = 0;
  for(int i=1;i<=n;i++){
      s[i] = s[i-1] + e[i-1];
  }

  for(int i=0;i<=n-k;i++){
      ma = max(ma,s[i+k]-s[i]);
  }

  cout << fixed << setprecision(10) << ma << endl;


}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
using namespace std;
static const int maxv = 50000;
static const int EPS = (1 << 29);

int main()
{
	int n, m;
	int C[21];
	int T[maxv + 1];

	cin >> n >> m;
	for (int i = 1; i <= m; i++)
		cin >> C[i];

	for (int i = 0; i <= maxv; i++)T[i] = EPS;
	T[0] = 0;

	for (int i = 1; i <= m; i++)
		for (int j = 0; j + C[i] <= n; j++)
			T[j + C[i]] = min(T[j + C[i]], T[j] + 1);

	cout << T[n] << endl;
	return 0;
}


Measured memory_bytes: 3308
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);i <= (e);(i)++)

int N;
vector<int> a;

int main(){
  cin >> N;
  a.resize(N + 1);
  for(int i = 1;i <= N;i++) cin >> a[i];
  int now = 1;
  vector<bool> vis(N + 1,0);
  vis[1] = 1;
  int cou = 0;
  while(true){
    now = a[now];
    cou++;
    if(vis[now]){
      cout << -1 << endl;
      return 0;
    }
    if(now == 2){
      cout << cou << endl;
      return 0;
    }
    vis[now] = 1;
  }
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
string s, p;
signed main() {
	while (cin >> s && s != "-") {
		int m, a;
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> a;
			string h = "";
			for (int j = a; j < s.size(); j++) {
				h += s[j];
			}
			for (int j = 0; j < a; j++) {
				h += s[j];
			}
			s = h;
		}
		cout << s << endl;
	}
}


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

int prizeMoney[230];

int main(){
    prizeMoney[1] = 300000;
    prizeMoney[2] = 200000;
    prizeMoney[3] = 100000;

    int X, Y;
    scanf("%d%d", &X, &Y);

    if(X == 1 && Y == 1){
        printf("%d", 1000000);
    }else{
        printf("%d", prizeMoney[X]+prizeMoney[Y]);
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ld INF = 1e18;
typedef pair< ld, int > P;
const ll mod = 1e9+7;

int main() {
  int h, w, a, b; cin >> h >> w >> a >> b;
  string x, y;
  x = y = "";
  for (int i = 0; i < a; i++) {
    x += "0";
    y += "1";
  }
  for (int i = 0; i < w-a; i++) {
    x += "1";
    y += "0";
  }
  for (int i = 0; i < b; i++) {
    cout << x << endl;
  }
  for (int i = 0; i < h-b; i++) {
    cout << y << endl;
  }
}


Measured memory_bytes: 1280
<?php
list($n) = ints();
$sum = 0;
for ($i = 0; $i < $n; ++$i) {
    list($s, $t) = strs();
    $sum += (int) $t;
    $past[$s] = $sum;
}
list($x) = strs();
echo $sum - $past[$x];
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<ll> sa(n+1,0),sb(m+1,0);
    rep(i,n){
        ll a;
        cin>>a;
        sa[i+1]=sa[i]+a;
    }
    rep(i,m){
        ll b;
        cin>>b;
        sb[i+1]=sb[i]+b;
    }
 
    int ans=0;
    int j=m;
    rep(i,n+1){
        while(j>=0 && sa[i]+sb[j]>k) j--;
        if(j>=0){
            //cout<<i<<" "<<j<<endl;
            ans=max(ans,i+j);
        }
        else break;
    }
 
    cout<<ans<<endl;
}



Measured memory_bytes: 6392
#include <bits/stdc++.h>
#define lld long long int
#define max 100
using namespace std;



int n, d, pontos[100][100];

int ehint(int a, int b, int c){
    int soma = 0;
    for(int i = 0; i < c; i++){
        soma+=pow(abs(pontos[a][i]-pontos[b][i]),2);
    }
    double aa = sqrt(double(soma));
    aa-=int(aa);
    if(aa==0)return 1;
    return 0;
}

int main(){

    scanf("%d %d", &n, &d);
    for(int i =0 ;i<n; i++){
        for(int j = 0; j< d; j++){
            scanf("%d", &pontos[i][j]);
        }
    }
    int cont = 0;
    for(int i = 0; i< n; i++){
        for(int j = i+1; j<n; j++){
            cont+=ehint(i, j, d);
        }
    }
    printf("%d\n", cont);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int X,N;
  cin >> X >> N;
  int p[N];
  for (int i=0;i<=N-1;i++){
    cin >> p[i];
  }
  int z1[100] = {0};
  int z2[100] = {0};
  for (int i=0;i<=N-1;i++){
    if (-1<X-p[i]) z1[X-p[i]]=1;
    if (X-p[i]<1) z2[-1*(X-p[i])]=1;
  }
  for (int i=0;i<=99;i++){
    if (z1[i]==0) {
      cout << X-i;
      break;
    }else if (z2[i]==0) {
      cout << X+i;
      break;
    }
  }

  return 0;
}


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

int n, p[300233];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int l = 1, r = 1; l <= n; l = ++r) {
    while (r + 1 <= n && ((p[r] == r) ^ (p[r + 1] == r + 1))) ++r;
    int ml = 0, mr = 0;
    for (int i = l; i <= r; i++) if (p[i] != i) {
      if (p[i] < l || p[i] > r) return puts("No"), 0;
      else if ((p[i] < i ? ml : mr) < p[i]) (p[i] < i ? ml : mr) = p[i];
      else return puts("No"), 0;
    }
  }
  puts("Yes");
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

void bubbleSort(int* A, int n, int& num) {
  bool flag = true;
  while (flag) {
    flag = false;
    for (int j = n - 1; j >= 1; j--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        flag = true;
        num++;
      }
    }
  }
}

void selectionSort(int* A, int n, int& num) {
  for (int i = 0; i < n; i++) {
    int minj = i;
    for (int j = i; j < n; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    swap(A[i], A[minj]);
    if (i != minj) {
      num++;
    }
  }
}

int main () {
  int n;
  cin >> n;
  int A[101];
  int num = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  selectionSort(A, n, num);
  for (int i = 0; i < n; i++) {
    cout << A[i];
    if (i != n - 1) {
      cout << ' ';
    }
  }
  cout << endl;
  cout << num << endl;
}

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

#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  ll ans = 1012345678912;
  cin >> n;
  for (ll x = 1; x <= (ll)ceil(sqrt(n)); x++)
    if (n % x == 0) ans = min(ans, x+n/x-2);
  cout << ans << ende;
  return 0;
}


Measured memory_bytes: 256
/*input
6
7 6 8 6 1 1
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int pre[1000],mem[1000][1000];
int dp(int l, int r){
	if(mem[l][r]!=-1)
		return mem[l][r];
	if(l==r){
		return 0;
	}
	int ans =LLONG_MAX;
	for(int i=l;i<r;++i){
		ans= min(ans, dp(l,i)+dp(i+1,r)+(pre[r])-(l==0?0:pre[l-1]));
	}
	return mem[l][r] = ans;
}
void solve(){
	int n;cin>>n;
	int a[n];
	memset(mem,-1,sizeof(mem));
	for(int i=0;i<n;++i){
		cin>>a[i];
		if(i)
			pre[i]=pre[i-1]+a[i];
		else
			pre[i]=a[i];
	}
	cout<<dp(0,n-1);
}

signed main(){
	IOS
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 8064
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

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

int main() {
  fast();
  cin >> n;
  FOR(i, 0, n) { cin >> a[i]; }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int p, x;
    cin >> p >> x;
    int ans = 0;
    FOR(i, 0, n) {
      if (i == p - 1)
        ans += x;
      else
        ans += a[i];
    }
    cout << ans << "\n";
  }
  return 0;
}



Measured memory_bytes: 3656
g={""=>1}
gets.to_i.times{h={}
g.map{|k,v|"ACGT".chars{|a|h[s=(k+a)[/.{,4}$/]]||=0
h[s]+=s=~/A.?G.?C|GAC|ACG/?0:v}}
g=h}
p g.values.reduce(:+)%(10**9+7)

Measured memory_bytes: 2556
# coding: utf-8
# Your code here!
import fractions

n,m=[int(i) for i in input().split()]
s=input()
t=input()

g = fractions.gcd(n,m)
l = n * m // g

ok=1
for i in range(g):
#    print(i)
#    print(s[i*n//g],t[i*m//g])
    if s[i*n//g] != t[i*m//g]:
        ok=0


if ok:
    print(l)
else:
    print(-1)







Measured memory_bytes: 5560
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
using namespace std;


signed main() {
    int N; cin >> N;
    vector<int> vec(N);
    rep(i, N) cin >> vec[i];

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += vec[i] / 2;
        vec[i] -= 2 * (vec[i] / 2);
        if (vec[i] > 0) {
            if (i < N - 1) {
                if (vec[i + 1] > 0) {
                    vec[i] -= 1;
                    vec[i + 1] -= 1;
                    ans += 1;
                }
            }
            
        }
    }

    cout << ans << endl;
    sysp;
}

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

int main(){
	int A , B , C; cin >> A >> B >> C;
	for(int i = 0 ; i <= 1e6 ; ++i){
		if((A | B | C) & 1){cout << i; return 0;}
		int p = A / 2 , q = B / 2 , r = C / 2;
		A = q + r; B = p + r; C = p + q;
	}
	cout << -1;
	return 0;
}


Measured memory_bytes: 256
import collections
n=int(input())
v=list(map(int,input().split()))
c1=collections.Counter(v[::2])
c2=collections.Counter(v[1::2])
c1_v1=c1.most_common()[0][0]
c2_v1=c2.most_common()[0][0]
c1_n1=c1.most_common()[0][1]
c2_n1=c2.most_common()[0][1]

if c1_v1!=c2_v1:
    print(n-c1_n1-c2_n1)
else:
    if c1_n1==n//2:
        if c2_n1==n//2:
            print(n//2)
        else:
            c2_n2=c2.most_common(2)[1][1]
            print(n-c1_n1-c2_n2)
    else:
        c1_n2=c1.most_common(2)[1][1]
        if c2_n1==n//2:
            print(n-c1_n2-c2_n1)
        else:
            c2_n2=c2.most_common(2)[1][1]
            print(min(n-c1_n2-c2_n1,n-c1_n1-c2_n2))


Measured memory_bytes: 18656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 約数の列挙O(√n)
vector<ll> enum_divisors(ll n){
    vector<ll> res;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            // 重複しないならばiの相方であるN/iもpush
            if(i!=n/i) res.push_back(n/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

int main() {
    ll n;
    cin>>n;
    auto ed=enum_divisors(n);
    ll ans=0;
    for(auto e : ed){
        if(e<=2) continue;
        ll x=e-1;
        if(n/x==n%x) ans+=x;
    }

    cout<<ans<<endl;
}




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

int main()
{
    int n,m; cin>>n>>m;
    int left=0;
    int right=1000000;
    for(int i=0;i<m;i++){
        int l,r; cin>>l>>r;
        if(left<=l) left=l;
        if(right>=r) right=r;
    }
    if(right<left) cout<<0<<endl;
    else if(left>n) cout<<0<<endl;
    else if(left<=n&&right<=n) cout<<right-left+1<<endl;
    else if(left<=n&&right>n) cout<<n-left+1<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
    public static void main(String args[]) {
 
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = 0; i < n; i++) {
            pq.add(Integer.parseInt(sc.next()));
        }
 
        while (m > 0) {
            pq.add(pq.poll() / 2);
            m--;
        }
 
        long result = 0;
        for (int a : pq) {
            result += a;
        }
 
        System.out.println(result);
    }
}

Measured memory_bytes: 48676
import heapq

N, M = map(int, input().split())
X = list(map(int, input().split()))

X.sort()
dist = [0]*(M-1)

for i in range(M-1):
    dist[i] = -(X[i+1] - X[i])
#print(dist)

heapq.heapify(dist)
for i in range(N-1):
    if len(dist) == 0:
        break
    heapq.heappop(dist)

ans = 0
if len(dist) != 0:
    ans = -sum(dist)
print(ans)


Measured memory_bytes: 13960
/* Binary tree 1 */
#include <stdio.h>
#include <stdlib.h>

struct node{
  
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
  
};

typedef struct node * Node;

#define NIL NULL
#define TRUE 1
#define FALSE 0

Node root;


/* 二分探索木Tに対してkeyがkのノードを挿入する関数 */
void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;

  /* 挿入するノードzを作成 */
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  /* zを挿入する場所を求める */
  while( x != NIL )
    {
      y = x;     /* 親を設定 */

      if( z->key < x->key )
	x = x->left;       /* 左の子に移動 */
      else
	x = x->right;      /* 右の子に移動 */
    }

  z->parent = y;           /* zの親を設定 */

  if( y == NIL )
    root = z;              /* Tが空の場合 */
  else if( z->key < y->key )
    y->left = z;           /* 左の子として挿入する場合 */
  else
    y->right = z;          /* 右の子として挿入する場合 */
}


/* 二分探索木Tを中間順巡回によって出力する関数 */
void inorder(Node u)
{
  if( u == NIL )
    return;

  inorder(u->left);       /* 左の子に進む */
  printf(" %d", u->key);
  inorder(u->right);      /* 右の子に進む */
}


/* 二分探索木Tを先行順巡回によって出力する関数 */
void preorder(Node u)
{
  if( u == NIL )
    return;
  
  printf(" %d", u->key);
  preorder(u->left);       /* 左の子に進む */
  preorder(u->right);      /* 右の子に進む */
}


/* 二分探索木T中にkeyがkという値のノードが含まれるかどうか調べる関数
   戻り値  存在 TRUE  存在しない FALSE  */
int find(int k)
{
  Node x = root;

  /* Tが空の場合 */
  if( root == NIL )
    return FALSE;

  while( x != NIL )
    {
      /* keyの値がkのノードが存在した場合 */
      if( x->key == k )
	return TRUE;

      if( k < x->key )
	x = x->left;      /* 左の子に移動 */
      else
	x = x->right;     /* 右の子に移動 */
      
    }

  return FALSE;   /* 存在しなかった場合 */
}

int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if( com[0] == 'f' )
      {
	scanf("%d", &x);

	if( find(x) == TRUE )
	  printf("yes\n");
	else
	  printf("no\n");
      }
    else if ( com[0] == 'i' )
      {
	scanf("%d", &x);
	insert(x);
      }
    else if ( com[0] == 'p' )
      {
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
      }
    
  }

  return 0;
}



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

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }
#define fi first
#define se second
#define mkp std::make_pair
#define V std::vector
#define H std::priority_queue
typedef long long ll;
typedef double ff;
typedef std::pair <int, int> pii;
const int kN = 4e5 + 5, kInf = 0x3f3f3f3f;
const ll kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL;

ll QPow(ll a, ll b) {
	ll ans = 1, bas = a;
	for(; b; b >>= 1, bas = bas * bas % kMod) if(b & 1) ans = ans * bas % kMod;
	return ans;
}

int n, m, k, q, a[kN], bl[kN], cnt = 0;
int main() { 
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	int T = 1; //rd(T);
	while(T--) {
		rd(n);
		for(int i = 1; i <= n; ++i) rd(a[i]);
		n = std::unique(a + 1, a + n + 1) - a - 1;
		bl[1] = bl[2] = ++cnt;
		for(int i = 3; i <= n; ++i) {
			if(bl[i - 1] != bl[i - 2]) bl[i] = cnt;
			else if((a[i - 1] > a[i - 2]) != (a[i] > a[i - 1])) bl[i] = ++cnt;
			else bl[i] = cnt;
		}
		printf("%d\n", cnt);
	} return 0;
}

Measured memory_bytes: 4452
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int cul(int n){
    vector<int> ar(5,0);
    int re = 0;
    rep(i,5){
        ar[i] = n % 10;
        n /= 10;
        re += ar[i];
    }
    return re;
}

int main() {
    int n, a, b; cin >> n >> a >> b;
    cout << min(n*a,b) << endl;
}

Measured memory_bytes: 3580
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[500000];
int b[500000];
int main(){
	int n,l,sign,i,m;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	scanf("%d",&m);
	for (i=1;i<=m;i++) scanf("%d",&b[i]);
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	l=1;sign=0;
	for (i=1;i<=m;i++) {
		if (a[l]==b[i]){
			l++;continue;
		}
		while (a[l]<b[i]&&l<=n) l++;
		if (a[l]==b[i]){
			l++;continue;
		}
		if (a[l]>b[i]) sign=1;
	} 
	if (sign==0) printf("YES\n");
	else printf("NO\n");
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);i++)
#define FORE(x,arr) for(auto &x:arr)
#define FOR(i,a,n) for(int i=a;i<(int)(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> l(n*2);
    REP(i,n*2) {cin >> l[i];}
    sort(ALL(l));
    int ans = 0;
    REP(i,n) {
        ans += l[i*2];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector <int> h(n);
	for (int i=0; i<n; i++) cin >> h[i];
	int ans=1;
	for (int i=1; i<n; i++){
		bool b=true;
		for (int j=0; j<i; j++){
			if (h[j]>h[i]) b=false;
		}
		if (b) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
from math import *

def main():
    N, M = map(int, input().split())
    special_value = M//N
    divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
    divisor_set = divisor_set.union(M//j for j in divisor_set)
    print(int(max(divisor_set, key=lambda x: x if special_value >= x else -1)))

    return

main()

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

#define INF -1

struct Node{
  int parent,left,right;
};

int H[30];
Node T[30];
int D[30];

void setdeep(int u,int d);
int setHeight(int u);

int main(){
  int n,id,l,r,root;
  cin>>n;
  
  //初期化
  for(int i=0;i<n;i++){
    T[i].parent=INF;
  }
 
  //入力
  for(int i=0;i<n;i++){
    cin>>id>>l>>r;
    T[id].left=l;
    T[id].right=r;
    if(l!=INF)T[l].parent=id;
    if(r!=INF)T[r].parent=id;
  }
  for(int i=0;i<n;i++){
    if(T[i].parent==INF)root=i;
  }

  //高さ求める
  setHeight(root);
  
  //深さを求める
  setdeep(root,0);
  
  //出力
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": ";
    cout<<"parent = "<<T[i].parent<<", ";
    cout<<"sibling = ";
    if(i==root)cout<<"-1";
    else if(T[T[i].parent].left==i)cout<<T[T[i].parent].right;
    else if(T[T[i].parent].right==i)cout<<T[T[i].parent].left;
    cout<<", ";
    int cnt=0;
    if(T[i].left!=INF)cnt++;
    if(T[i].right!=INF)cnt++;
    cout<<"degree = "<<cnt<<", ";
    cout<<"depth = "<<D[i]<<", ";
    cout<<"height = "<<H[i]<<", ";
    if(i==root)cout<<"root"<<endl;
    else if(T[i].left==INF && T[i].right==INF)cout<<"leaf"<<endl;
    else cout<<"internal node"<<endl;
  }
}

  


int setHeight(int u){
  int hl=0,hr=0;
  if(T[u].left!=INF){
    hl=setHeight(T[u].left)+1;
  }
  if(T[u].right!=INF){
    hr=setHeight(T[u].right)+1;
  }
  return H[u]=max(hl,hr);
}
  
void setdeep(int u,int d){
  D[u]=d;
  if(T[u].left!=INF){
    setdeep(T[u].left,d+1);
  }
  if(T[u].right!=INF){
    setdeep(T[u].right,d+1);
  }
  return;
}

Measured memory_bytes: 1160
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));


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

	int N,P;
	cin >> N >> P;
	VI A(N);
	int one = 0, zero = 0;
	REP(i, N) {
		cin >> A[i];
		A[i] =A[i]%2;
		if (A[i] == 1)one++;
		else zero++;
	}
	ll ans=1;
	REP(i, N)ans *= 2;
	if (one == 0) {
		if (P == 0)
			cout << ans << endl;
		else
			cout << 0 << endl;
	}
	
	else {
		ans /= 2;
		cout << ans << endl;
	}
	return 0;
}





Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  int N=0,K=0;
  int i=0,j=0;
  int c=0;
  int count=0;
  scanf("%d",&N);
  int b[N];
  for(i=0;i<N;i++){
    b[i]=1;
  }
  scanf("%d",&K);
  
  for(i=0;i<K;i++){
    int d=0;
    scanf("%d",&d);
    
    for(j=0;j<d;j++){
      scanf("%d",&c);
      b[c-1]=0;
    }
    
  }
  
  for(i=0;i<N;i++){
    
    if(b[i]==1)
      count+=1;
  }
  printf("%d",count);
  return 0;
}
  
      

Measured memory_bytes: 1732
#include <stdio.h>
#define MAX 105
#define INF 2e8

int G[MAX][MAX], d[MAX], n, head = 0, tail = 0, Q[MAX];

int isEmpty(){
	return head == tail;	
}

int isFull(){
	return head == (tail +1) % MAX;
}

void enqueue(int x){
	if (isFull())
		printf("overflow");
	Q[tail] = x;
	if ((tail+1)==MAX)
		tail = 0;
	else
		tail++;
}
int dequeue(){
	int x;
	if (isEmpty())
		printf("underflow");
	x = Q[head];
	Q[head] = -1;
	if ((head+1) == MAX)
		head = 0;
	else
		head++;
	return x;
}


int main(void) {
  int u,k,v,i,j,id;
 
  scanf("%d",&n);
  for(i=0; i<n; i++){
  	d[i]=INF;
  	Q[i]=-1;
	for(j=0; j<n ;j++)
  		G[i][j] = 0;
  }

  for(i=0; i<n; i++){
	scanf("%d%d",&u,&k);
	for(j=0; j<k; j++){
  		scanf("%d",&v);
  		G[u-1][v-1] = 1;
	}
  }
   
  d[0]=0;
  enqueue(0);
  while(!isEmpty()){
  	id = dequeue();
  	for(i=0; i<n; i++){
  		if(G[id][i] == 0)
  			continue;
  		if(d[id] + 1 < d[i]){
  			d[i] = d[id] + 1;
  			enqueue(i);
  		}
  	}
  }
  for(i=0;i<n;i++){
	if(d[i]==-1 || d[i]==200000000)
		printf("%d -1\n", i+1);
	else printf("%d %d\n", i+1, d[i]);
  }
  

  return 0;
}


Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  vector<int>v[n];
  int *h=new int[n];
  int *a=new int[n];
  for(int i=0;i<n;i++)
  {
    cin>>h[i];
    a[i]=0;
  }
  while(m--)
  {
    int x,y;
    cin>>x>>y;
    v[x-1].push_back(y-1);
    v[y-1].push_back(x-1);
  }
  for(int i=0;i<n;i++)
  {
    if(a[i]==0)
    {
      int count=0;
      for(int j=0;j<v[i].size();j++)
      {
        if(h[i]>h[v[i][j]])
        {
          a[v[i][j]]=-1;
          //cout<<v[i][j]<<"*";
        }
        else
        {
          count++;
        }
      }
      if(count==0)
        a[i]=1;
      else
        a[i]=-1;
    }
  }
  int good=0;
  for(int i=0;i<n;i++)
  {
    //cout<<a[i]<<" ";
    if(a[i]==1)
      good++;
  }
  cout<<good<<"\n";
}
        

Measured memory_bytes: 9508
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <iterator>
#include <math.h>
#include <cstdlib>
#include <cmath>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  int K;
  cin >> K;
  int m = max(max(A,B),C);
  int ans = 0;
  if(A == m){
    ans += B;
    ans += C;
  }else if(B == m){
    ans += A;
    ans += C;
  }else {
    ans += A;
    ans += B;
  }
  ans += m * pow(2,K);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
	int n;
	std::cin >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		std::cin >> a[i];
	}
	for(int i = n-1; i >= 0; i--){
		std::cout << a[i];
		if(i)
			std::cout << ' ';
	}
	std::cout << std::endl;
	return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size()-2;i++)
	{
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
			ans++;	
	}
	cout<<ans;	
}

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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

  if (a[0] + a[1] > a[2] + a[3]) cout << "Left" << endl;
  if (a[0] + a[1] < a[2] + a[3]) cout << "Right" << endl;
  if (a[0] + a[1] == a[2] + a[3]) cout << "Balanced" << endl;
}


Measured memory_bytes: 504
// Problem : A - Sheep and Wolves
// Contest : AtCoder - AtCoder Beginner Contest 164
// URL : https://atcoder.jp/contests/abc164/tasks/abc164_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){

	int a,b;cin>>a>>b;
	if(b<a) cout<<"safe";
	else cout<<"unsafe";


    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long

#define INF 999999999

using namespace std;

// input
int n;

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

    int l,r;
    int ans = 0;

    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> l >> r;

        ans += r+1-l;
    }


    cout << ans << "\n";
}

Measured memory_bytes: 256