akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>  

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define TMP 1000000007

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

int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	int ans = k;
	for(int i = n - 1; i > 0; --i) {
		ans *= k - 1;
	}
	printf("%d\n", ans);
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int A,B;
	int add,sub,mul,max;
	scanf("%d",&A);
	scanf("%d",&B);
	add=A+B;
	sub=A-B;
	mul=A*B;

	max=add;
	if(max<sub)max=sub;
	if(max<mul)max=mul;
	printf("%d\n",max);
	return 0;

}

Measured memory_bytes: 128
#include <stdio.h>
#define N 100000
#define F 0
#define T 1
 
typedef struct {
  char c;
  int value;
  int id;
} cards;
 
cards A[N];
 
int partition(int , int );
 
void qSort(int , int );
 
int isStable(int ); 
 
int main() {
  int n, i;
 
  scanf("%d", &n);
  
  for(i = 0;i < n;i ++)
    {
      scanf("%s %d", &A[i].c, &A[i].value);

      A[i].id = i;
    }
 
  qSort(0, n-1);
 
  if(isStable(n) == F)printf("Not stable\n");

  else printf("Stable\n");

  for (i = 0;i < n; i ++ )
    {
      printf("%c %d\n", A[i].c, A[i].value);
    }
  return 0;
 
}

int partition(int p, int r) {

  int i, j, x;
  cards tmp;
 
  x = A[r].value;

  i = p-1;

  for (j = p;j < r;j ++)
    {
      if(A[j].value <= x)
	{
	  i++;
	  tmp = A[i];
	  A[i] = A[j];
	  A[j] = tmp;
	}
    }
  
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  
  return i+1;
}
 
void qSort(int p, int r) {
  int q;
  
  if (p < r)
    {
      q = partition(p, r);
      qSort(p, q-1);
      qSort(q+1, r);
    }
}
 
int isStable(int n) {
  int i;

  for(i = 0;i < n-1;i ++)
    {
      if(A[i].value == A[i+1].value && A[i].id > A[i+1].id)return F;
    }
  return T;
}

Measured memory_bytes: 1784
#include<stdio.h>
int main(void)
{
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a<b&&b<c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	
	return 0;
}

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

using namespace std;

const int MAXN = 311;
int n, m;
int a[MAXN][MAXN];

int b[MAXN];
int cnt[MAXN];
vector<int> per[MAXN];
bool in[MAXN];

bool check(int mx)
{
    //cout << "MX " << mx << endl;
    for (int i=1; i<=m; i++) per[i].clear();
    for (int i=1; i<=n; i++) per[a[i][1]].push_back(i);
    for (int i=1; i<=m; i++) in[i] = true;
    for (int i=1; i<=n; i++) b[i] = 1;
    for (int t=1; t<=m; t++)
    {
        bool bo = false;
        int id;
        for (int i=1; i<=m; i++)
        {
            //cout << in[i] << "&" << per[i].size() << " ";
            if (in[i] == true && per[i].size() > mx)
            {
                bo = true;
                id = i;
                break;
            }
            
        }
        //cout << endl;
        //cout << "BOOL " << bo << endl;
        if (bo == false)
        {
            return true;
        }
        if (t == m) break;
        in[id] = false;
        for (int i=0; i<per[id].size(); i++)
        {
            int tt = per[id][i];
            while (in[a[tt][b[tt]]] == false) b[tt] ++;
            per[a[tt][b[tt]]].push_back(tt);
        }
    }
   //cout << "?\n";
    return false;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=m; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }

    int L, R, mid;
    L = 0; R = n;
    
    while (L + 1 < R)
    {
        mid = (L+R)/2;
        //cout << L << " " << R << " " << mid << " " << check(mid) << endl;
        if (check(mid) == true) R = mid;
        else L = mid;
    }
    //cout << L << " " << R << endl;
    
    /*cout << "?\n";
    cout << check(2) << endl;
    cout << "fk\n";*/
    printf("%d", R);
}

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

using namespace std;

const int mod = 1000000007;

int mod_mult(const vector<long long> &terms) {
  int ans = 1;
  for (auto &term : terms) {
    ans = (term % mod * ans) % mod;
  }

  return ans;
}

int main(int argc, const char *argv[])
{
  int n, ans = 0;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int j = 0; j < 61; j++) {
    int cnt0 = 0, cnt1 = 0;
    long long mask = 1LL << j;
    for (auto num : a) {
      if (num & mask) {
        cnt1++;
      } else {
        cnt0++;
      }  
    }

    ans += mod_mult({cnt0, cnt1, mask});
    ans = ans % mod;
  }

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

Measured memory_bytes: 2560
def main():
    n = int(input())
    a = list(int(input()) for _ in range(n))
    s = sorted(a)
    MAX1, MAX2 = s[-1], s[-2]
    for i in range(n):
        ans = MAX2 if a[i] == MAX1 else MAX1
        print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14120
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
const int MAX = 2001;
const int MOD = 1000000007;
 
 



 
signed main(){
    int n,a,c=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a!=i+1)c++;
    }
    if(c==2||c==0)cout<<"YES";
    else cout<<"NO";
    

    return 0;
}

Measured memory_bytes: 256
//Binaty Tree
#include <iostream>

using namespace std;

static const int NIL = -1;

struct Node {
    int parent = NIL, left = NIL, right = NIL, sibling = NIL, degree = 0, depth = 0, height = 0;
};

void setDepth(Node N[], int u, int d) {
    N[u].depth = d;
    if(N[u].right != NIL) setDepth(N, N[u].right, d + 1);
    if(N[u].left != NIL) setDepth(N, N[u].left, d + 1);
}

void setHeight(Node N[], int u, int h) {
    if(N[u].height < h) N[u].height = h;
    if(N[u].parent != NIL) setHeight(N, N[u].parent, h + 1);
}

int main() {
    int n, id, left, right;
    cin >> n;
    Node N[n];
    for(int i = 0; i < n; i++) {
        cin >> id >> left >> right;
        N[id].degree = (left != NIL) + (right != NIL);
        if(left != NIL) {
            N[id].left = left;
            N[left].parent = id;
        }
        if(right != NIL) {
            N[id].right = right;
            N[right].parent = id;
        }
        if(left != NIL && right != NIL) {
            N[left].sibling = right;
            N[right].sibling = left;
        }
    }

    for(int i = 0; i < n; i++) {
        if(N[i].parent == NIL) setDepth(N, i, 0);
        if(N[i].degree == 0) setHeight(N, i, 0);
    }

    for(int i = 0; i < n; i++) {
        cout << "node " << i
             << ": parent = " << N[i].parent
             << ", sibling = " << N[i].sibling
             << ", degree = " << N[i].degree
             << ", depth = " << N[i].depth
             << ", height = " << N[i].height;
        if(N[i].parent == NIL) cout <<", root" << endl;
        else if(N[i].left == NIL && N[i].right == NIL) cout << ", leaf" << endl;
        else cout << ", internal node" << endl;
    }
}


Measured memory_bytes: 3112
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n, m) for (int i = (n), i < (m); i++)

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int
main(int argc, char *argv[])
{
  int n, k, v[100];
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &v[i]);

  int ans = 0;
  for (int i = 0; i <= k; i++) {
    if (k - i <= n) {
      for (int l = 0; l <= k - i; l++) {
	int minus = 0, ma[100];
	int sum = 0;
	for (int j = 0; j < l; j++) {
	  if (v[j] >= 0) sum += v[j];
	  else ma[minus++] = v[j];
	}
	for (int j = 0; j < k - i - l; j++) {
	  if (v[n - 1 - j] >= 0) sum += v[n - 1 - j];
	  else ma[minus++] = v[n - 1 - j];
	}
	qsort(ma, minus, sizeof(int), asc);
	for (int j = 0; j < minus; j++) {
	  if (j >= i) sum += ma[j];
	}
	ans = Max(ans, sum);
      }
    }
  }

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

  return 0;
}
	


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

int main() {
    long long a;
    cin >> a;
    long long b = a/5;
    long long c = a/3;
    long long d = a/15;
    b = 5*b*(b+1)/2;
    c = 3*c*(c+1)/2;
    d = 15*d*(d+1)/2;
    long long e = (a+1)*a/2;
    cout << e-b-c+d << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
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; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////

template<class T> T getDigits(const T N) { return static_cast<T>(std::floor(std::log10(N) + 1.0)); }

void Main() {
	const int N = inputVal<int>();

	int cnt = 0;
	for (int i = 1; i <= N; ++i) {
		if (getDigits(i) % 2 != 0) ++cnt;
	}

	cout << cnt << endl;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	double tmp;
	cin >> tmp;

	return 0;
}


Measured memory_bytes: 512
import itertools

N = input()
P = input()
Q = input()
string1 = tuple(map(int, list(P.split(" "))))
string2 = tuple(map(int, list(Q.split(" "))))

num =list(itertools.permutations(list(range(1, int(N)+1))))
count = 1

for i in num:
    if i == string1:
        a = count
    if i == string2:
        b = count
    count += 1

print(abs(a-b))

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

bool is_prime(int x) {
    For(i, 2, (int)(sqrt(x) + 1)) if (x % i == 0 and i != x) return false;

    return true;
}

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int x;
    cin >> x;
    while (true) {
        if (is_prime(x)) {
            print(x);
            return 0;
        }
        x++;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int X, A, B; cin >> X >> A >> B;

    string ans;
    if (B <= A) {
        ans = "delicious";
    } else if (B-A <= X) {
        ans = "safe";
    } else {
        ans = "dangerous";
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }
int main() {
ll N;
  ll A;
  ll B;
  cin >>N>>A>>B;
  
 if(((A%2==0)&&(B%2==0)) ||((A%2==1) &&(B%2==1))) {
   cout<<(B-A)/2<<endl;
   return 0;
 }

  else {
    cout<<min(A-1,N-B)+(B-A)/2+1<<endl;
  }
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < 2; i++) {
			if (A > B) {
				ans += A;
				A--;
			} else {
				ans += B;
				B--;
			}
		}

		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 21844
#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;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<vector<int>> v,vz;
    REP(i,n) {
        vector<int> p(3);
        cin >> p[0] >> p[1] >> p[2];
        if (p[2] != 0) {
            v.push_back(p);
        } else {
            vz.push_back(p);
        }
    }

    REP(i,101) REP(j,101) {
        int htmp = 0;
        bool b = true;
        for(auto p:v) {
            if (htmp == 0) {
                htmp = p[2] + abs(i-p[0]) + abs(j-p[1]);
            } else {
                if (htmp != p[2] + abs(i-p[0]) + abs(j-p[1])) {
                    b = false;
                    break;
                }
            }
        }

        int hztmp = 1e9 + 1000;
        for(auto p:vz) {
            int x = abs(i-p[0]) + abs(j-p[1]);
            hztmp = min(hztmp,x);
        }
        if (htmp > hztmp) b = false;

        if (b) {
            cout << i << " " << j <<" " << htmp << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	
	int n,S[100000],q,T[50000],i,j,C=0,mid,left,right;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d", &S[i]);	
	}
	
	scanf("%d",&q);
	for(j=0;j<q;j++){
		scanf("%d",&T[j]);
	}
	
	for(j=0;j<q;j++){
	left = 0;
	right = n;
	while(left<right){
		mid = (left+right)/2;
		if(S[mid] == T[j]){C++;break;}
		else if(S[mid]>T[j])right = mid;
		else left = mid+1;
	}
	}
	
	printf("%d\n",C);
	
	return 0;}
	
	
	

Measured memory_bytes: 1184
def cmb(n, r, p):
    # nume/deno === nume * pow(deno, p - 2, p) (mod p)
    nume, deno = 1, 1
    for i in range(r):
        nume = nume * (n - i) % p
        deno = deno * (i + 1) % p
    return nume * pow(deno, p - 2, p) % p


if __name__ == "__main__":
    n, a, b = map(int, input().split())
    p = 10 ** 9 + 7

    print((pow(2, n, p) - cmb(n, a, p) - cmb(n, b, p) - 1) % p)


Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct AREA
{
	int x1, y1, z1, x2, y2, z2;
};
int main(void)
{
	long long N, K,i,j,x[101],y[101],z[101],xx,yy,zz,m,h,cnt=0;
	AREA barea[51];
	long long sum = 0;
	scanf("%lld%lld", &N, &K);
	for (i = 0; i <2*N; i++)
	{
		scanf("%lld %lld %lld", &x[i], &y[i], &z[i]);
		if (i % 2 == 0)
		{
			barea[i / 2].x1 = x[i];
			barea[i / 2].y1 = y[i];
			barea[i / 2].z1 = z[i];
		}
		else
		{
			barea[i / 2].x2 = x[i];
			barea[i / 2].y2 = y[i];
			barea[i / 2].z2 = z[i];
		}
	}

	for (i = 0; i < 2*N-1; i++)
	{
		for (j = i + 1; j < 2*N; j++)
		{
			if (x[i] > x[j])
			{
				xx = x[i];
				x[i] = x[j];
				x[j] = xx;
			}
			if (y[i] > y[j])
			{
				yy = y[i];
				y[i] = y[j];
				y[j] = yy;
			}
			if (z[i] > z[j])
			{
				zz = z[i];
				z[i] = z[j];
				z[j] = zz;
			}
		}
	}

	for (i = 0; i < 2 * N-1; i++)
	{
		for (j = 0; j < 2 * N-1; j++)
		{
			for (m = 0; m < 2 * N-1; m++)
			{
				for (h = 0; h < N; h++)
				{
					if(barea[h].x1<=x[i]&&x[i+1]<=barea[h].x2&&barea[h].y1 <= y[j] && y[j + 1] <= barea[h].y2&&barea[h].z1 <= z[m] && z[m + 1] <= barea[h].z2)
					cnt++;
				}
				if (K <= cnt)
				{
			
					sum = sum + (x[i + 1] - x[i])*(y[j + 1] - y[j])*(z[m + 1] - z[m]);
				}
				//printf("%d*%d*%d=%lld\n", x[i + 1] - x[i], y[j + 1] - y[j], z[m + 1] - z[m], sum);
				cnt = 0;
			}
		}
	}
	printf("%lld\n", sum);
	return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mx = 1e5+1;
vector<int> adj[mx];
vector<ll> treenum(mx);
vector<ll> pref[mx];
vector<ll> suff[mx];
ll m;
vector<ll> ans(mx);

void dfs(int v, int p)
{
	ll num = 1;
	for (int a : adj[v])
	{
		if (a != p)
		{
			dfs(a, v);
			num = (num * (treenum[a]+1)) % m;
		}
	}
	treenum[v] = num;
}

void dp(int v, int p, int index)
{
	for (int a : adj[v])
	{
		if (a != p)
		{
			pref[v].push_back((treenum[a]+1)%m);
			suff[v].push_back((treenum[a]+1)%m);
		}
		else
		{
			ll temp = 1;
			if (index > 0)
			{
				temp = (temp * pref[p][index-1])%m;
			}
			if (index < suff[p].size()-1)
			{
				temp = (temp * suff[p][index+1])%m;
			}
			pref[v].push_back((temp+1)%m);
			suff[v].push_back((temp+1)%m);
		}
	}	
	int sz = pref[v].size();
	for (int q = 1; q < sz; q++)
	{
		pref[v][q] = (pref[v][q] * pref[v][q-1]) % m;
		suff[v][sz-q-1] = (suff[v][sz-q-1] * suff[v][sz-q]) % m;
	}
	ll num = treenum[v];
	if (p != 0)
	{
		ll prod = 1;
		if (index > 0)
		{
			prod = (prod * pref[p][index-1]) % m; 
		}
		if (index < suff[p].size()-1)
		{
			prod = (prod * suff[p][index+1]) % m;
		}
		num = (num * (prod+1)) % m;
	}
	ans[v] = num;
	int counter = 0;
	for (int a : adj[v])
	{
		if (a != p)
		{
			dp(a, v, counter);
		}
		counter++;
	}
}

int main()
{
	ll n;
	cin >> n >> m;
	for (int q = 0; q < n-1; q++)
	{
		int a,b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(1,0);
	dp(1,0,0);
	for (int q = 1; q <= n; q++)
	{
		cout << ans[q] << "\n";
	}
	return 0;
}


Measured memory_bytes: 29568
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;

    cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;
string s[222];
int d[222][2],n;
void dfs(int x,int t) {
  d[x][t]=1;
  rep(y,n) {
    if(s[x][y]=='1'&&!d[y][t^1]) dfs(y,t^1);
  }
}

void Main() {
  R n;
  rep(i,n) R s[i];
  dfs(0,0);
  rep(i,n) {
    if(d[i][0]&&d[i][1]) {
      pr(-1);
      return;
    }
  }
  ll d[n][n];
  rep(i,n) {
    rep(j,n) {
      if(s[i][j]=='1') d[i][j]=1;
      else d[i][j]=MAX;
    }
    d[i][i]=0;
  }
  rep(k,n) {
    rep(i,n) {
      rep(j,n) {
        if(d[i][k]!=MAX&&d[k][j]!=MAX) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  ll ans=0;
  rep(i,n) {
    rep(j,n) {
      if(d[i][j]!=MAX) ans=max(ans,d[i][j]);
    }
  }
  pr(ans+1);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using namespace std;

#define INF 2100000000
#define int long long

template<typename T>
void remove(vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

signed main(){
    int n;
    cin >> n;
    vector<float> a;
    for(int i=0;i<n;i++){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(),a.end());
    while(a.size() != 1){
        a[1] = (a[0] + a[1]) / 2;
        remove(a,0);
        sort(a.begin(),a.end());
    }
    cout << a[0] << endl;
}


Measured memory_bytes: 256
from heapq import heapify,heappush,heappop
n,m = map(int,input().split())
a = [-1*int(i) for i in input().split()]
heapify(a)
while m:
    s = abs(heappop(a))
    s //= 2
    heappush(a,-1*s)
    m -= 1
print(abs(sum(a)))

Measured memory_bytes: 14184
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  if(a == b){
    cout << a*2 << endl;
  }else if(a > b){
    cout << a + (a - 1) << endl;
  }else if(a < b){
    cout << b + (b -1) << endl;
  }
}

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

namespace program
{
    class Program
    {
        static void Main()
        {
          string w = Input.ScanStr();
          
          Console.WriteLine(w.Substring(0,4) + " " + w.Substring(4));
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();

		String[] s = sc.next().split("");
		s[k - 1] = s[k -1].toLowerCase();

		System.out.println(String.join("", s));
	}
}

Measured memory_bytes: 35980
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n, k;
  char s[51];
  scanf("%d %d", &n, &k);
  scanf("%s", s);

  if(s[k - 1] == 'A') s[k - 1] = 'a';
  else if(s[k - 1] == 'B') s[k - 1] = 'b';
  else s[k - 1] = 'c';

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

  return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    N = len(S)
    a = S[0:int((N-1)/2)]
    b = S[int((N+3)/2)-1:N]
    print(YES) if S == S[::-1] and a == a[::-1] and b == b[::-1] else print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n;
    cin>>n;
    cout<<n/3<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var n int
	fmt.Scan(&n)

	v := make([]int, n)
	me, mo := map[int]int{}, map[int]int{}
	for i := range v {
		fmt.Scan(&v[i])
		if i%2 == 0 {
			mo[v[i]]++
		} else {
			me[v[i]]++
		}
	}

	// Case1: even max key == odd max key
	e_key1, e_cnt1 := max(me)
	o_key1, o_cnt1 := max(mo)
	if o_key1 != e_key1 {
		fmt.Println(n - e_cnt1 - o_cnt1)
		return
	}

	// Case2: even max key != odd max key
	me[e_key1] = 0
	mo[o_key1] = 0
	_, e_cnt2 := max(me)
	_, o_cnt2 := max(mo)
	a1 := n - e_cnt2 - o_cnt1
	a2 := n - e_cnt1 - o_cnt2
	if a1 < a2 {
		fmt.Println(a1)
	} else {
		fmt.Println(a2)
	}
}

func max(m map[int]int) (int, int) {
	maxKey := 0
	maxCnt := 0
	for k, v := range m {
		if maxCnt < v {
			maxKey = k
			maxCnt = v
		}
	}
	return maxKey, maxCnt
}

Measured memory_bytes: 8320
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
a = list(set(s+t))
ans = {'min': 0}
for i in a:
    ans[i] = 0
for i in s:
    ans[i] += 1
for i in t:
    ans[i] -= 1

print(max(ans.values()))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;





signed main() {
    string s;
    cin >> s;
    ll len = (ll)s.size();
    
    ll i = 0;
    ll bk = 0;
    int erf = 1;
    string res = "YES";
    while (i < len) {
        bk = i;
        if (s[i] == 'd') {
            if(i+4 <= len && s[i+1] == 'r' && s[i+2] == 'e' && s[i+3] == 'a' && s[i+4] == 'm') {
                i += 5;
                erf = 0;
                continue;
            }
            
        }
        
        if (s[i] == 'e') {
            if(i+5 <= len && s[i+1] == 'r' && s[i+2] == 'a' && s[i+3] == 's' && s[i+4] == 'e' && s[i+5] == 'r') {
                i += 6;
                erf = 0;
                continue;
            }
            if(i+4 <= len && s[i+1] == 'r' && s[i+2] == 'a' && s[i+3] == 's' && s[i+4] == 'e') {
                i += 5;
                erf = 0;
                continue;
            }
        }
        
        if (s[i] == 'e' && erf != 1) {
            if(i+1 <= len && s[i+1] == 'r') {
                i += 2;
                erf = 1;
                continue;
            }
        }
        
        if (i == bk) {
            res = "NO";
            break;
        }
            
    }
    
    mes(res);
    
    
    
    
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
using namespace std;

vector<int> suffix_array(string const & s) { // O(N (\log N)^2), sa[i] is the index of i-th smallest substring of s
    int n = s.length();
    vector<int> sa(n+1);
    vector<int> rank(n+1);
    repeat (i,n+1) {
        sa[i] = i;
        rank[i] = i < n ? s[i] : -1;
    }
    auto rankf = [&](int i) { return i <= n ? rank[i] : -1; };
    vector<int> nxt(n+1);
    for (int k = 1; k <= n; k <<= 1) {
        auto cmp = [&](int i, int j) { return make_pair(rank[i], rankf(i + k)) < make_pair(rank[j], rankf(j + k)); };
        sort(sa.begin(), sa.end(), cmp);
        nxt[sa[0]] = 0;
        repeat_from (i,1,n+1) {
            nxt[sa[i]] = nxt[sa[i-1]] + (cmp(sa[i-1], sa[i]) ? 1 : 0);
        }
        rank.swap(nxt);
    }
    return sa;
}

int main() {
    int k; string s; cin >> k >> s;
    vector<int> sa = suffix_array(s);
    vector<int> rank(sa.size()); repeat (i,sa.size()) rank[sa[i]] = i;
    int l = (s.length()+k) / (k+1);
    function<bool (int)> pred = [&](int a) {
        int used = 0;
        for (int i = 0; i < s.length(); ++ used) {
            int delta = rank[i] < a ? l : l-1;
            if (delta == 0) return false;
            i += delta;
        }
        return used <= k+1;
    };
    int low = 0, high = rank.size();
    while (low + 1 < high) {
        int mid = (low + high) / 2;
        (pred(mid) ? high : low) = mid;
    }
    int a = low;
    cout << s.substr(sa[a], l) << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
 
using namespace std;
 
#define BUF_SIZE 1024

class Stack{
public:
  Stack(int stack_size):
  m_index(0){
    m_array=new int[stack_size];
  };
  ~Stack(){
    delete[] m_array;
  };
  void push(int var){
    m_array[m_index++]=var;
  }
  int pop(){return m_array[--m_index];
  };
  bool isEmpty(){
    return m_index==0;
  };

private:
  int* m_array;
  int m_index;
};

int main(){
  char buf[BUF_SIZE];

  for(int i=0;i<BUF_SIZE;i++)
  {
    buf[i]='e';
  }
  fgets(buf,BUF_SIZE,stdin);

  Stack stack(BUF_SIZE);

  bool numFLG=false;
  int S=0,op1=0,op2=0;

  for(int i=0;buf[i]!='e';i++){
    if(buf[i]>='0'&&buf[i]<='9'){
      numFLG=true;
      S=10*S+(buf[i]-'0');
    }else{
      if(numFLG){
        stack.push(S);
        S=0;
        numFLG=false;
      }

      if(buf[i]=='+'){
        op2=stack.pop();
        op1=stack.pop();
        stack.push(op1+op2);
      }else if(buf[i] == '-'){
                op2 = stack.pop();
                op1 = stack.pop();
                stack.push(op1-op2);
            }else if(buf[i] == '*'){
                op2 = stack.pop();
                op1 = stack.pop();
                stack.push(op1*op2);
            }
    }
  }
  op1=stack.pop();
  printf("%d\n",op1);
}


Measured memory_bytes: 3224
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.Map;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ballot = sc.nextInt();  //投票用紙の枚数
		TreeMap<String, Integer> voteMap = new TreeMap<>();
      int voteMax = 0;
 
		for(int i=1 ; i<=ballot ; i++) {
			int count;
			String voteName = sc.next();
 
			if(! voteMap.containsKey(voteName)) {
				count = 1;
				voteMap.put(voteName, count);
			}
			else {
				count = voteMap.get(voteName) + 1;
				voteMap.put(voteName, count);
			}
          
          voteMax = Math.max(voteMax, count);
		}
      
      for (Map.Entry<String, Integer> e : voteMap.entrySet()) {
        if (e.getValue() == voteMax) {
          System.out.println(e.getKey());
        }
      }
	}
}

Measured memory_bytes: 71188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N, A, B;
	cin >> N >> A >> B;

	map<ll, int> MAP;
	rep(i, N) {
		ll V;
		cin >> V;
		MAP[V]++;
	}

	int kaisuu = MAP.size();

	int kosuu = 0;
	ll goukei = 0;
	rep(i, kaisuu) {
		auto T = *(--MAP.end());

		kosuu += T.second;
		if (kosuu >= A) {
			int X = kosuu - A;

			goukei += T.first * (T.second - X);
			double kotae = 1.0 * goukei / A;
			cout << fixed << kotae << endl;

			ll comb = 1;
			rep1(ii, X) {
				comb *= T.second + 1 - ii;
				comb /= ii;
			}
			if (i == 0) {
				int nanko = min(B, T.second);
				for (int ii = A + 1; ii <= nanko; ii++) {
					ll comb2 = 1;
					rep1(iii, ii) {
						comb2 *= T.second + 1 - iii;
						comb2 /= iii;
					}
					comb += comb2;
				}
			}
			co(comb);
			break;
		}

		goukei += T.first * T.second;

		MAP.erase(T.first);
	}
	Would you please return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
#define mp(x,y) make_pair((x),(y))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

const int mod=998244353;
int n,pw[300005];
inline void inc(int& x,int y){x=x+y<mod?x+y:x+y-mod;}

struct Graph{
	int m,sg[100005],vis[100005],val[100005];
	vector<int> E[100005];
	void dfs(int u){
		for(int v:E[u])if(!~sg[v])dfs(v);
		for(int v:E[u])vis[sg[v]]=1;
		sg[u]=0;
		while(vis[sg[u]])++sg[u];
		for(int v:E[u])vis[sg[v]]=0;
	}
	void calSG(){
		memset(sg,-1,sizeof sg);
		REP(i,1,n)if(!~sg[i])dfs(i);
		REP(i,1,n)inc(val[sg[i]],pw[i]);
	}
} G[3];

int main(){
	// freopen("in.in","r",stdin);
	int b=((ll)1e18)%mod;
	REP(i,pw[0]=1,300001)pw[i]=1ll*pw[i-1]*b%mod;
	n=read();
	REP(t,0,2){
		G[t].m=read();
		REP(i,1,G[t].m){
			int u=read(),v=read();
			if(u>v)swap(u,v);
			G[t].E[u].pb(v);
		}
		G[t].calSG();
	}
	int ans=0;
	REP(a,0,sqrt(G[0].m)*2)REP(b,0,sqrt(G[1].m)*2){
		int c=a^b;
		inc(ans,1ll*G[0].val[a]*G[1].val[b]%mod*G[2].val[c]%mod);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 16512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class CGoodSequence {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            Map<Integer, Integer> m = new HashMap<>();
            int n = in.ints();
            int[] a = in.ints(n);
            int ans = 0;
            for (int x : a) {
                m.merge(x, 1, (p, q) -> p + q);
            }
            for (Map.Entry<Integer, Integer> e : m.entrySet()) {
                if (e.getValue() >= e.getKey()) {
                    ans += e.getValue() - e.getKey();
                } else {
                    ans += e.getValue();
                }
            }
            out.println(ans);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

        public int[] ints(int length) {
            return IntStream.range(0, length).map(x -> ints()).toArray();
        }

    }
}



Measured memory_bytes: 44796
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<int>>;
//using P =pair<int,int>;
//int dy[4] = {-1,0,1,0};
//int dx[4] = {0,-1,0,1};

int main()
{
    int N,M;
    cin >> N>>M;
    
    for(int i=0;i<M;i++)
    {
        int a;
        cin >> a;
        N -= a;
    }
    
    if(N<0) N=-1;
    
    cout<<N<<endl;
    
    return 0;
    
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

const int MOD = 998244353;

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

	int n; cin >> n;
	vi v(n); FOR(i, n) cin >> v[i];

	sort(all(v));

	int ans = 0;
	if(n >= 3){
		FOR(i, n-2){
			for(int j = i+1; j < n-1; j++){
				if(v[j] == v[i]) continue;
				for(int k = j+1; k < n; k++){
					if(v[k] == v[j]) continue;

					if(v[k] < v[i] + v[j]){
						ans ++;
					}

					//cout << v[i] << ' ' << v[j] << ' ' << v[k] << '\n';
				}
			}
		}
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int n,len;
int a[233];
int main()
{

	scanf("%d",&n);
	int x;
	for (int i=1;i<=n;++i) scanf("%d",&x),++a[x];
	for (int i=n;i>=1;--i) if (a[i])
	{
		len=(i+1)/2+1;

		for (int j=0;j<(i+1)/2;++j)
		{
			if (a[i-j]<2) 
			{
				printf("Impossible\n");
				return 0;
			}
			a[i-j]-=2;
		}
		if (i%2==0)
		{
			if (a[i-i/2]) --a[i-i/2];
			else
			{
				printf("Impossible\n");
				return 0;
			}
		}
		break;
	}
//	for (int i=1;i<=n;++i) printf("%d ",a[i]);
//	printf("\n");
//	printf("len : %d\n",len);
	for (int i=1;i<len;++i)
	if (a[i])
	{
		printf("Impossible\n");
		return 0;
	}
	printf("Possible\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;



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

	int N, Q;
	int st, ed;
	int counter = 0;
	int tmp = 0;
	string S;

	cin >> N >> Q;
	cin >> S;

	vector<int> ar(S.length(), 0);

	REP(i, S.length()) {
		if (S[i] == 'A' && S[i + 1] == 'C') {
			counter++;
			REP(j,S.length()-i-1) {
				ar[i+j+1] = counter;
			}
			tmp = i;
			i++;
		}
	}

	REP(i, Q) {
		cin >> st >> ed;
		cout << ar[ed-1]-ar[st-1] << endl;
	}

	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int t; cin >> t; for(int cs = 1; cs <= t; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";

//input space ---> scanf("%[^\n]%*c",s);
ll n,dp[405][405];
vll a(405),pre(405);

ll f(ll l, ll r) {
//	debug(l)debug(r)testing
	if(dp[l][r] != -1)
		return dp[l][r];
	if(l == r)
		return 0;
	ll ret = LLONG_MAX;
	fori(i,l,r-1,1) {
		ll tmp = f(l,i)+f(i+1,r)+pre[r]-pre[l-1];
		ret = min(ret,tmp);
	}
	return dp[l][r] = ret;
}

int main() {
	IOS
	reset(dp,-1);
	cin >> n;
	fori(i,1,n,1) {
		cin >> a[i];
		pre[i]=pre[i-1]+a[i];
	}
	cout << f(1,n) << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	vector<vector<int>> c(10, vector<int>(10));
	rep(i, 10){
		rep(j, 10){
			int in;
			cin >> in;
			c.at(i).at(j) = in;
		}
	}
	rep(k, 10){
		rep(i, 10){
			rep(j, 10){
				c.at(i).at(j) = min(c.at(i).at(j), c.at(i).at(k) + c.at(k).at(j));
			}
		}
	}
	map<int, int> m;
	rep(i, h)rep(j, w){
		int in;
		cin >> in;
		if(in == -1) continue;
		m[in]++;
	}
	ll ans = 0;
	for(auto p : m){
		ans += c.at(p.first).at(1) * p.second;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <unordered_set>
#include <functional>
 
using namespace std;
 
int main() {
    string s;
    cin>>s;
    bool a=s[0]=='A'||s[1]=='A'||s[2]=='A';
    bool b=s[0]=='B'||s[1]=='B'||s[2]=='B';
    if (a && b){
    cout<<"Yes";
    }else{
    cout<<"No";
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

int n, m, r, dist[220][220], x, y, w, d, ans=inf;
vector<int> p;



int main(){
cin >> n >> m >> r;
rep(i, 1, n){
rep(j, 1, n){
if(i==j)dist[i][j]=0;
else dist[i][j]=inf;
}
}
rep(i, 0, r-1){
cin  >> x;
p.pb(x);
}
rep(i, 0, m-1){
cin >> x >> y >> w;
dist[x][y]=w;
dist[y][x]=w;
}
rep(k, 1, n){
rep(i, 1, n){
rep(j, 1, n){
dist[i][j]= min(dist[i][j], dist[i][k]+dist[k][j]);
}
}
}
sort(p.begin(), p.end());
do{
        d=0;
    rep(i, 0, r-2){
    d+= dist[p[i]][p[i+1]];
    }
    ans = min(d, ans);
}
while(next_permutation(p.begin(), p.end()));

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


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

void answer1() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  vector<bool> alice_on(101, false);
  for (int i = a; i < b; i++) {
    alice_on.at(i) = true;
  }

  int count = 0;
  for (int i = c; i < d; i++) {
    if (alice_on.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}

int main() {
  answer1();
}


Measured memory_bytes: 256