akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	vector<ll> v(3);
	cin >> v[0] >> v[1] >> v[2];
	SORTL2S(ll,v);
	if (v[0]==v[1] && v[1]!=v[2]) {
		cout << "Yes";
	} else if (v[0]!=v[1] && v[1]==v[2]) {
		cout << "Yes";
	} else {
		cout << "No";
	}

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <map>
#include <algorithm>

typedef long long i64;

const int N = 200000 + 10, MOD = 1000000007;

int fact[N], ifact[N];

int n, x, y, c[N], w[N];

int anc[N];

int find(int x) { return anc[x] == x ? x : (anc[x] = find(anc[x])); }
inline void meld(int x, int y) { anc[find(x)] = find(y); }

std::map<int, int> cnt[N];

int main() {
  fact[0] = 1;
  for (int i = 1; i < N; ++i) fact[i] = (i64)fact[i - 1] * i % MOD;
  ifact[1] = 1;
  for (int i = 2;   i < N; ++i) ifact[i] = ((i64)MOD - MOD / i) * ifact[MOD % i] % MOD;
  ifact[0] = 1;
  for (int i = 1; i < N; ++i) ifact[i] = (i64)ifact[i - 1] * ifact[i] % MOD;
  scanf("%d%d%d", &n, &x, &y);
  static int min[N];
  for (int i = 1; i <= n; ++i) scanf("%d%d", &c[i], &w[i]), anc[i] = i;
  for (int i = 1; i <= n; ++i) if (!min[c[i]] || w[min[c[i]]] > w[i]) min[c[i]] = i;
  for (int i = 1; i <= n; ++i) if (w[i] + w[min[c[i]]] <= x) meld(min[c[i]], i);
  int p = std::min_element(w + 1, w + n + 1) - w, q = 0;
  for (int i = 1; i <= n; ++i) if (c[i] != c[p] && (!q || w[q] > w[i])) q = i;
  for (int i = 1; i <= n; ++i) {
    if (c[i] != c[p] && w[i] + w[p] <= y) meld(i, p);
    if (c[i] != c[q] && w[i] + w[q] <= y) meld(i, q);
  }
  int ans = 1;
  for (int i = 1; i <= n; ++i) ++cnt[find(i)][c[i]];
  for (int i = 1; i <= n; ++i) {
    int sum = 0, cur = 1;
    for (std::map<int, int>::iterator it = cnt[i].begin(); it != cnt[i].end(); ++it) sum += it->second, cur = (i64)cur * ifact[it->second] % MOD;
    cur = (i64)cur * fact[sum] % MOD;
    ans = (i64)ans * cur % MOD;
  }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

const int MAX = 100005;

char A[MAX];
int N;

int main(int argc, char* argv[]) {

    scanf("%s", A);
    N = strlen(A);

    memset(A + N, 'A', MAX - N);

    for (int i = 0; i < N; ++i) {
        if (A[i] == A[i+1]) {
            cout << i+1 << " " << i+1+1 << endl;
            return 0;
        }
        if (A[i] == A[i+2]) {
            cout << i+1 << " " << i+2+1 << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;

    return 0;
}


Measured memory_bytes: 384
#include <cstdio>

int main(void){
    int n,x;
    scanf("%d %d",&n,&x);
    int l;
    int d=0;
    int ans=1;
    int i;
    for(i=1;i<=n;i++){
        scanf("%d",&l);
        d+=l;
        if(x<d)break;
    }
    for(int j=0;j<n-i;j++){
        scanf("%d",&l);
    }
    printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long m = sc.nextLong();
		sc.close();

		long x = Math.min(n, m);
		long y = Math.max(n, m);
		if (x == 1) {
			if (y == 1) {
				System.out.println(1);
			} else if (y == 2) {
				System.out.println(0);
			} else {
				System.out.println(y - 2);
			}
		} else if (x == 2) {
			System.out.println(0);
		} else {
			System.out.println((x - 2) * (y - 2));
		}
	}
}


Measured memory_bytes: 21716
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>

#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>

#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

class Data{
    public:
        int i;
        int p;
        int y;
        int order;
};

void printV(vector<Data> list){
    cout << "[vector]" << endl;
    
    for(int i=0; i < list.size(); i++){
        cout << list[i].i << " ";
        cout << list[i].p << " ";
        cout << list[i].y << " ";
        cout << list[i].order << " ";
        cout << endl;
    }
    cout << endl;
}

bool cmp_by_i(const Data &a, const Data &b)
{
    return a.i < b.i;
}

bool cmp_by_y(const Data &a, const Data &b)
{
    return a.y < b.y;
}

int main(){
    // input
    int n, m;
    cin >> n >> m;

    vector<Data> list;

    FOR(i,0,m){
        int p, y;
        cin >> p >> y;

        Data d;
        d.i = i;
        d.p = p;
        d.y = y;

        list.push_back(d);
    }

    // sort by year
    sort(list.begin(), list.end(), cmp_by_y);

    map<int, int> mp;

    FOR(i,0,m){
        mp[list[i].p]++;
        list[i].order = mp[list[i].p];
    }
    
    // sort
    sort(list.begin(), list.end(), cmp_by_i);

    // print
    for(auto data : list){
        std::cout << std::setfill('0') << std::right << std::setw(6) << data.p;
        std::cout << std::setfill('0') << std::right << std::setw(6) << data.order << endl;
    }
    
    return 0;
}

Measured memory_bytes: 7792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  long long Y=0;
  cin>>N;
  for (long long X=1;X<=sqrt(N);X++){
    if(N%X==0){
      Y=N/X;
    }
  }
  long long X=N/Y;
  cout<<X+Y-2<<endl;
}

Measured memory_bytes: 3648
def putty():
    N,X = map(int,input().split())
    ans = 0

    for i in range(0,N+1)[::-1]:
        width = 2**(i+2)-3
        if X <= i:   return ans
        elif X >= width - i:    return ans + 2**(i+1)-1
        else:
            mid = (width + 1) // 2
            if X == mid:    return ans + 2**(i)
            elif X < mid:   X -= 1 
            else:
                X -= 2**(i+1)-3 + 2 
                ans += 2**(i)

print(putty())

Measured memory_bytes: 3064
N, K = map(int, input().split())
P = [int(i) - 1 for i in input().split()]
C = [int(i) for i in input().split()]

ret = -float('inf')
done = set()
for n in range(N) :
  if n in done : continue
    
  cur = n
  s = C[cur]
  done.add(cur)
  loop = [n]
  while not P[cur] in done :
    cur = P[cur]
    done.add(cur)
    loop.append(cur)
    s += C[cur]
  
  if s <= 0:
    for i in loop :
      cur = i
      x = 0
      for _ in range(min(len(loop), K)) :
        cur = P[cur]
        x += C[cur]
        ret = max(ret, x)
  else :
    d = 0
    k = K
    if k > len(loop) :
      d = s * (k // len(loop) - 1)
      k = k % len(loop) + len(loop)
      
    for i in loop :
      cur = i
      x = 0
      for _ in range(k) :
        cur = P[cur]
        x += C[cur]
        ret = max(ret, x + d)
      
print(ret)


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

int  main()
{
	int n, m;
	cin >> n >> m;
	set<int> reach;
	vector<pair<int, int> > p(m);
	rep(i, m)
	{
		cin >> p[i].first >> p[i].second;
		if (p[i].second == n)
			reach.insert(p[i].first);
	}
	rep(i, m)
	{
		if (p[i].first == 1)
		{
			if (reach.count(p[i].second))
			{
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE\n";
	return (0);
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, X, T;
  cin >> N >> X >> T;
  long a = 0, ans = 0;
  while(a < N){
    a += X;
    ans += T;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
n = int(input())
A = list(map(int, input().split()))

def cmb(m, n):
    if m - n < n:
        n = m - n
    if n == 0:
        return 1
    if n == 1:
        return m
    
    numerator = [m - n + k + 1 for k in range(n)]
    denominator = [k + 1 for k in range(n)]

    for p in range(2, n+1):
        pivot = denominator[p-1]
        if pivot > 1:
            offset = (m-n) % p
            for k in range(p-1, n, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    
    result = 1
    for k in range(n):
        if numerator[k] > 1:
            result *= int(numerator[k])
            
            # mod(10**9+7)
            # result = result % (10**9+7)

    return result


Dict = {x:0 for x in range(n+1)}
for a in A:
    Dict[a] += 1

Non_minus = [0 for _ in range(n+1)]
one_minus = [0 for _ in range(n+1)]

for i in range(1, n+1):
    if Dict[i] <= 1:
        Non_minus[i] = 0
        one_minus[i] = 0
    elif Dict[i] == 2:
        Non_minus[i] = 1
        one_minus[i] = 0
    else:
        Non_minus[i] = cmb(Dict[i],2)
        one_minus[i] = cmb(Dict[i]-1, 2)

total_non = sum(Non_minus)

# print(Non_minus)
# print(one_minus)

for i in range(n):
    ans = total_non - Non_minus[A[i]] + one_minus[A[i]]
    print(ans)

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b || b == c || c == a){
        if (!(a == b && b == c)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3616
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e3 + 10;
int a[N];
bitset<N> b1[N], b2[N];
vector<int> refrain(bitset<N>& b, int k, int o = 0)
{
	vector<int> ret;
	for (int i = 0; i < k; i++)
	{
		if (b[i])
			ret.push_back(i + o);
	}
	return ret;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	int sz = 0;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		if (x >= k) continue;
		a[++sz] = x;
	}
	n = sz;
	b1[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		b1[i] = b1[i - 1] | (b1[i - 1] << a[i]);
	}
	b2[n + 1][0] = 1;
	for (int i = n; i >= 1; i--)
	{
		b2[i] = b2[i + 1] | (b2[i + 1] << a[i]);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		vector<int> v1 = refrain(b1[i - 1], k, a[i]), v2 = refrain(b2[i + 1], k, 0);
		int minv = INF;
		for (auto& x : v1)
		{
			while (!v2.empty() && v2.back() + x >= k)
			{
				minv = min(minv, v2.back() + x);
				v2.pop_back();
			}
		}
		if (minv - a[i] >= k) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
  int N, A, B;
  std::vector<int> sum;
  std::cin >> N >> A >> B;
  for(int i = 1; i <= N; ++i) {
    std::vector<int> digit;
    int num = i;
    do {
      digit.push_back(num % 10);
      num /= 10;
    } while(num > 0);
    int sumi = std::accumulate(digit.begin(), digit.end(), 0);
    if(sumi >= A && sumi <= B) {
      sum.push_back(i);
    }
  }
  std::cout << std::accumulate(sum.begin(), sum.end(), 0) << std::endl;
  return 0;
}


Measured memory_bytes: 384
S = input()
ans = 0
L = ['A','T','G','C']
for i in range(len(S)):
  if S[i] in L:
    cnt = 1
    s = i+1
    while s < len(S):
      if S[s] in L:
        cnt += 1
        s += 1
      else:
        break
    if cnt >= ans:
      ans = cnt
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define dl double
using namespace std;

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
   int n,m;
   cin >>n;
   vector<int> v(n);
   //ll sum=0;
   for(int i=1;i<n;i++)
   {
       cin >> v[i];
      
   }
   vector<int> ans(n+1);
   for(int i=1;i<n;i++)
   {
       ans[v[i]]++;
   }
   for(int i=1;i<=n;i++)
   cout << ans[i] << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

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

#define INF 1120000000

int main(){
  int n;
  while(cin>>n, n){
    vector<int> x(n),y(n);
    rep(i,n) cin>>x[i]>>y[i];
    vector<int> px(4), py(4);
    rep(i,4) cin>>px[i]>>py[i];

    vector<int> sx,sy;
    rep(i,n) sx.pb(x[i]), sy.pb(y[i]);
    rep(i,4) sx.pb(px[i]),sy.pb(py[i]);
    sx.pb(-300000);
    sy.pb(-300000);
    uniq(sx); uniq(sy);
    int nx = sx.size(), ny = sy.size();

    x.pb(x[0]); y.pb(y[0]);

    auto idx = [&](vector<int> &v, int val){ return lower_bound(all(v), val) - v.begin(); };

    vector<vector<int>> vec(nx,vector<int>(ny,0));

    rep(i,n) if(y[i] == y[i+1]){
      int l = idx(sx, min(x[i], x[i+1]));
      int r = idx(sx, max(x[i], x[i+1]));
      int t = idx(sy, y[i]);
      for(; l<r; l++) vec[l][t]+=1;
    }

    rep(i,nx) repl(j,1,ny) vec[i][j] += vec[i][j-1];
    rep(i,nx) rep(j,ny) vec[i][j] %=2;

    {
      int lw = idx(sy, min(py[0], py[2]));
      int up= idx(sy, max(py[0], py[2]));
      int l = idx(sx, min(px[0], px[2]));
      int r = idx(sx, max(px[0], px[2]));
      repl(i,l,r)repl(j,lw,up) vec[i][j] = 0;
    }

    long ans = 0;
    rep(i,nx) rep(j,ny) if(vec[i][j]>0) ans += (sx[i+1]-sx[i])*(sy[j+1]-sy[j]);

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, H;
int A[100010];
int B[100010];
int C[100010];
int D[100010];

vector<int> V[420];
int M = 210;
int input[420];
int output[420];

const int UFSIZE = 420;
int union_find[UFSIZE];

vector<int> S[420];

void init() {
  for (auto i=0; i<UFSIZE; i++) {
    union_find[i] = i;
  }
}

int root(int a) {
  if (a == union_find[a]) return a;
  return (union_find[a] = root(union_find[a]));
}

bool issame(int a, int b) {
  return root(a) == root(b);
}

void unite(int a, int b) {
  union_find[root(a)] = root(b);
}

bool isroot(int a) {
  return root(a) == a;
}

void add_edge(int i) {
  int from, to;
  if (C[i] == 0) {
    from = A[i];
  } else {
    from = -C[i];
  }
  if (D[i] == 0) {
    to = -B[i];
  } else {
    to = D[i];
  }
  V[from + M].push_back(to + M);
  output[from + M]++;
  input[to + M]++;
}

int main () {
  init();
  cin >> N >> H;
  fill(input, input+420, 0);
  fill(output, output+420, 0);
  for (auto i = 0; i < N; ++i) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
    add_edge(i);
  }
  for (auto i = 1; i <= H; ++i) {
    if (input[i + M] > output[i + M]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  for (auto i = 1; i <= H; ++i) {
    if (input[-i + M] < output[-i + M]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  for (auto i = 0; i < 420; ++i) {
    for (auto x : V[i]) {
      unite(i, x);
    }
  }
  for (auto i = 0; i < 420; ++i) {
    S[root(i)].push_back(i);
  }
  for (auto i = 0; i < 420; ++i) {
    if (!(S[i].empty())) {
      bool ok = false;
      for (auto x : S[i]) {
        if (input[x] > 0 && input[x] == output[x]) {
          
        } else {
          ok = true;
          break;
        }
      }
      if (!ok) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
}


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

int main() {
    int N, K;
    string S;
    cin >> N >> S >> K;

    char c = S.at(K-1);
    for (int i=0; i<N; i++) {
        if (S.at(i)==c) {
            cout << c;
        } else {
            cout << '*';
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define   ll    long long int
#define   sz    200010

using namespace std;


int main()
{
    ll a,b;

    cin>>a>>b;

    if(a<=9 && a>=1 && b<=9 && b>=1)cout<<a*b<<endl;
    else
        cout<<-1<<endl;

    return 0;
}


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

typedef struct directedGraph{
  int *vertex;
  int *next;
  int *start;
  int v,e;
  int pointer;
} graph;

graph* newGraph(const int v,const int e){
  graph *g=(graph *)malloc(sizeof(graph));
  g->vertex=(int *)calloc(e,sizeof(int));
  g->next=(int *)calloc(e,sizeof(int));
  g->start=(int *)calloc(v,sizeof(int));
  for(int i=0;i<v;i++) g->start[i]=-1;
  g->v=v;
  g->e=e;
  g->pointer=0;
  return g;
}

void freeGraph(graph *g){
  free(g->vertex);
  free(g->next);
  free(g->start);
  free(g);
  return;
}

void addEdge(graph *g,const int from,const int to){
  const int p=g->pointer;
  g->vertex[p]=to;
  g->next[p]=g->start[from];
  g->start[from]=p;
  g->pointer++;
  return;
}

typedef long long int int64;

void run(void){
  int n,mod;
  scanf("%d%d",&n,&mod);
  graph *g=newGraph(n,2*n);
  int i;
  for(i=0;i<n-1;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;b--;
    addEdge(g,a,b);
    addEdge(g,b,a);
  }
  int *parent=(int *)calloc(n,sizeof(int));
  int *q=(int *)calloc(n,sizeof(int));
  int front=0;
  int last=0;
  q[last++]=0;
  while(last<n){
    int v=q[front++];
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(u==parent[v]) continue;
      parent[u]=v;
      q[last++]=u;
    }
  }
  int *dp1=(int *)calloc(n,sizeof(int));
  for(i=n-1;i>=0;i--){
    int v=q[i];
    int local=1;
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(u==parent[v]) continue;
      local=(int64)local*dp1[u]%mod;
    }
    dp1[v]=(local+1)%mod;
  }
  int *dp2=(int *)calloc(n,sizeof(int));
  int *child=(int *)calloc(n,sizeof(int));
  int *fr=(int *)calloc(n,sizeof(int));
  dp2[0]=1;
  for(i=0;i<n;i++){
    int v=q[i];
    int len=0;
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(u==parent[v]) continue;
      child[len++]=u;
    }
    fr[len]=dp2[v];
    for(int j=len-1;j>=0;j--){
      int u=child[j];
      fr[j]=(int64)fr[j+1]*dp1[u]%mod;
    }
    int local=1;
    for(int j=0;j<len;j++){
      int u=child[j];
      dp2[u]=((int64)local*fr[j+1]+1)%mod;
      local=(int64)local*dp1[u]%mod;
    }
  }
  for(i=0;i<n;i++) printf("%lld\n",(int64)(dp1[i]+mod-1)*dp2[i]%mod);
}

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


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


Measured memory_bytes: 2104
N, K = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
ary = [0]*N
for i, p in enumerate(P):
    ary[i] = (p+1)*p/2/p
tmp = sum(ary[:K])
ans = tmp
for i in range(N-K):
    tmp = tmp-ary[i]+ary[i+K]
    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 73480
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007, INF = 1e9;

int main()
{
    string s, t;
    cin >> s;
    t = "keyence";
    if(s == t){
        cout << "YES" << endl;
        return 0;
    }
    for(int i = 0; i < s.size(); i++){
        for(int j = i; j < s.size(); j++){
            string r = "";
            for(int k = 0; k < s.size(); k++){
                if(i <= k && k <= j) continue;
                else r.push_back(s[k]);
            }if(r == t){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

template <typename T> T gcd(T a, T b) {
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

template <typename T> T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

void solve() {
    string s;
    cin >> s;

    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 384
#include<string>
#include<iostream>

int main(){
 int D;std::cin>>D;
 if( D
==
25)std::cout <<"Christmas"<<std::endl; 
if(D
==
24)std::cout <<"Christmas Eve"<<std::endl; 
if(D
==
23)std::cout <<"Christmas Eve Eve"<<std::endl;
if(D
==
22)std::cout <<"Christmas Eve Eve Eve"<<std::endl; 
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const ll MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE;

int arr[MAXN];
int deg[MAXN];
int parent[MAXN];

int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string A, B;
    cin >> A >> B;
    cout << B + A << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    int sum = 0;
    for (int i = 0; i < k; i++)
    {
        sum += arr[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3628
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := map[string]int{}
	for i := 0; i < n; i++ {
		s := getNextString(scanner)
		m[s]++
	}
	fmt.Fprintln(writer, fmt.Sprintf("AC x %d", m["AC"]))
	fmt.Fprintln(writer, fmt.Sprintf("WA x %d", m["WA"]))
	fmt.Fprintln(writer, fmt.Sprintf("TLE x %d", m["TLE"]))
	fmt.Fprintln(writer, fmt.Sprintf("RE x %d", m["RE"]))
}


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

const ll INF = 1LL << 60;

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  vector<ll> sum(N + 1);
  REP(i, 0, N) sum[i + 1] = sum[i] + A[i];

  vector<vector<ll>> dp(N, vector<ll>(N + 1, INF));
  REP(i, 0, N) dp[i][i + 1] = 0;

  REP(w, 2, N + 1) {
    REP(i, 0, N) {
      ll j = i + w;
      if (j > N) continue;
      REP(k, i, j) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j] + (sum[j] - sum[i]));
      }
    }
  }

  cout << dp[0][N] << endl;
}

Measured memory_bytes: 1536
#include <stdio.h>
//#include <algorithm>

int main(void){
	int n, start, startpoint;
	int reference[60];
	bool head;

	while (true){
		scanf("%d", &n);
		if (n == 0){ break; }

		// テ・ツ?・テ・ツ環崚」ツつ津・ツ渉療」ツ?妥・ツ渉姪」ツつ?
		for (int i = 0; i < n; i++){ scanf("%d", &reference[i]); }
		reference[n] = reference[n - 1] + 2;

		// テ」ツつステ」ツδシテ」ツδ暗」ツ?凖」ツつ?
		//std::sort(&reference[0], &reference[n]);

		// テ・ツ?コテ・ツ環崚」ツ?凖」ツつ?
		// テ、ツセツ凝・ツ、ツ姪・ツ?ヲテァツ青?
		if (n == 1){
			printf("%d\n", reference[0]);
			continue;
		}
		// テヲツ卍ョテゥツ?堙」ツ?ョテ・ツ?エテ・ツ青?
		start = reference[0];
		startpoint = 0;
		head = true;
		for (int i = 1; i <= n; i++){
			if (reference[i] != reference[i - 1] + 1){
				if (head){ head = false; }
				else{ printf(" "); }

				if (startpoint == i - 1){ printf("%d", reference[startpoint]); }
				else{ printf("%d-%d", reference[startpoint], reference[i - 1]); }
				start = reference[i];
				startpoint = i;
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1032
import Control.Applicative
import Data.List

main :: IO ()
main = solve <$> f <*> f <*> f >>= putStrLn
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> [Int] -> [Int] -> String
solve [n, m, x, y] xs ys
  | mx < my = "No War"
  | otherwise = "War"
  where
    mx = maximum (x:xs)
    my = minimum (y:ys)


Measured memory_bytes: 1020
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
using namespace std;
//using namespace boost::multiprecision;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  int n;
  cin>>n;
  int a[n],b[n];
  REP(i,n){
    cin>>a[i];
  }
  REP(i,n){
    cin>>b[i];
  }
  priority_queue<pair<int, int>> q;
  REP(i,n){
    q.push(make_pair(b[i],i));
  }
  long long ans = 0;
  while(!q.empty()){
    int val = q.top().first;
    int i = q.top().second;
    q.pop();
    if(val == a[i]){
      continue;
    }
    if(val < a[i]){
      cout<<-1<<endl;
      return 0;
    }
    int l = i - 1, r = i + 1;
    if(l < 0){
      l = n - 1;
    }
    if(r >= n){
      r = 0;
    }
    long long cnt;
    cnt = (b[i] - a[i])/(b[l] + b[r]);
    if(cnt == 0){
      cout<<-1<<endl;
      return 0;
    }
    ans += cnt;
    b[i] -= cnt*(b[l] + b[r]);
    q.push(make_pair(b[i],i));
  }
  cout<<ans<<endl; 
  return 0; 
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n, m; cin >> n >> m;

    set<pair<int, int>> se;

    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;

        se.insert(make_pair(a, b));
    }

    for (int i = 2; i < n; ++i) {
        if (se.count(make_pair(1, i)) && se.count(make_pair(i, n))) {
            puts("POSSIBLE");
            return 0;
        }
    }

    puts("IMPOSSIBLE");
}

Measured memory_bytes: 9600
#include<iostream>
using namespace std;
//#define rep(i, a, b) for(int i=(a);i<(b);i++)

int main(){
  int N,K,result=0;
  cin >> N >> K;
  if((N-1)%(K-1)==0) result=(N-1)/(K-1);
  else result = (N-1)/(K-1)+1;
  cout<<result<<endl;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
S = set(range(1, M + 1))
for _ in range(N):
    K, *A = map(int, input().split())  # *を使ってAのリストを作成
    S &= set(A)  # 集合の演算を繰り返し行う
print(len(S))

Measured memory_bytes: 3060
#include <stdio.h>

int n, A[50];

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





Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  
  int aoki,taka;
  aoki = C-B;
    taka = A-D;
  while(aoki>0&&taka>0){
    
    aoki -= B;
    taka -= D;
  }
 	if(aoki<=0){
      cout<<"Yes"<<endl;
    }
  else {
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<int> h(N);
    REP(i, N)
    {
        cin >> h.at(i);
    }

    int active = 0;
    int ans = 0;

    REP(i, N)
    {
        if (active > h.at(i))
            active = h.at(i);
        else
        {
            ans += h.at(i) - active;
            active = h.at(i);
        }
    }

    cout << ans;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def dfs(v, p):
    for u in link[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

N, Q = map(int, input().split())
link = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

ans = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

dfs(0, -1)

print(*ans)


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

using namespace std;

#define int long long
#define forr(i,n) for(int i = 0;i < (int)n; i++)
#define forn(i,n) for(int i = (int)(n-1); ~i ;i--)
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define pb push_back
#define mpa make_pair
#define endl "\n"
#define ar array

const int INF = (int)2e9+10;
const int mxN = (int)2e5+10;
const int MOD = (int)1e9 + 7;

int power(int x, int y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
} 

void solve(){
	int a;
	cin>>a;
	cout << (int)(a + (int)power(a,2) + (int)power(a,3));		
}


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3608
#include <iostream>

using namespace std;

#define INF 100000000000;

typedef long long ll;

int main() {
    int N, H;
    cin >> H >> N;
    ll *A = new ll[N], *B = new ll[N];
    for (int i = 0; i < N; i++)
        cin >> A[i] >> B[i];
    ll **dp = new ll*[N+1];
    for (int i = 0; i <= N; i++) {
        dp[i] = new ll[H+1];
        for (int j = 0; j <= H; j++)
            dp[i][j] = INF;
    }
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= H; j++) {
            if (j >= A[i])
                dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]] + B[i]);
            else
                dp[i+1][j] = min(dp[i][j], dp[i][0] + B[i]);
            
        }
    }

    cout << dp[N][H] << endl;

    return 0;
}

Measured memory_bytes: 78464
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;

int a[33];

int main()
{
    fast;
    int b , bb; cin >> b >> bb;
    a[b] = 1; a[bb] = 1;
    for(int i = 1; i<=3; i++){
        if(a[i] == 0)cout << i << endl;
    }
    return 0;
}
/*



*/



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define vi_a vector<int>a;
#define p_b push_back
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define getfiles ifstream cin("input.txt");ofstream cout("output.txt");
#define closefiles cin.close();cout.close();
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
#define sz(x) (int)x.size()
#define endl "\n"
using namespace std;

signed main()
{
    fast_io;
    string a,b;
    cin>>a>>b;
    ll n=a.length(),m=b.length();
    unordered_map<ll,unordered_map<ll,ll>>dp;
//    cout<<"  ";
//    for(ll i=0;i<m;i ++){
////        cout<<b[i]<<" ";
////    }
//    cout<<endl;
    for(ll i=0;i<n;i++){
//        cout<<a[i]<<" ";
        for(ll j=0;j<m;j++){
            if(a[i]==b[j]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
//            cout<<dp[i][j]<<" ";
        }
//        cout<<endl;
    }
    ll i=n-1,j=m-1;
//    cout<<dp[i][j]<<endl;
    string ans;
    while(dp[i][j]){
        if(a[i]==b[j]){
            ans+=a[i];
            i--;j--;
//             cout<<i<<" "<<j<<endl;
            continue;
        }
        else{
            if(!j || (i && dp[i-1][j]>dp[i][j-1])){
                i--;
            }
            else{
                j--;
            }
        }
    }
    reverse(all(ans));
    cout<<ans;
}


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    ll l = 0;
    ll sum = 0;
    rep(i, n) sum += a[i];

    ll ans = (1LL << 50);
    for (int i = 0; i < n - 1; i++) {
        l += a[i];
        ans = min(ans, abs(sum - l * 2LL));
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int64_t ans = 0;
    for (int bit = 0; bit < (1<<n-1); bit++) {
        int lef = 0;
        int sz = 1;
        rep(i,n) {
            if ((bit & (1 << i)) || i == n-1) {
                string t = s.substr(lef, sz);
                lef = i+1;
                sz = 1;
                if (t != "") ans += stoll(t);
            }
            else sz++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(a+b>=c){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>

using namespace std;

int selectionSort(int A[], int N);

int main() {
	int N;
	int count = 0;
	cin >> N;

	int A[N];

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

	count = selectionSort(A, N);

	for (int i = 0; i < N; i++) {
		if (i < N - 1)
			cout << A[i] << " ";
		else
			cout << A[i] << endl;
	}
	cout << count << endl;
}

int selectionSort(int A[], int N) {
	int count = 0;
	int minj = 0;

	for (int i = 0; i < N; i++) {
		minj = i;
		for (int j = i; j < N; j++) {
			if (A[j] < A[minj]) {
				minj = j;
			}
		}
		if (i != minj) {
			swap(A[i], A[minj]);
			count++;
		}
	}

	return count;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int h[100001],f[100001];
int main()
{
	int n,i;
	cin>>n;
	for(i=1;i<=n;i++)
	 cin>>h[i];
	f[2]=abs(h[2]-h[1]);
	for(i=3;i<=n;i++) f[i]=min(f[i-1]+abs(h[i-1]-h[i]),f[i-2]+abs(h[i-2]-h[i]));
	 cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
/*#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
*/

/*
ID: febrian3 
LANG: C++11 
PROB: task 
*/

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr<<#x<<": "<<(x)<<'\n'
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
const ll inf = 0x3f3f3f3f;
const ll nax = 0;
ld d, s, t;

int main(){
		/*freopen("filename.in","r",stdin); 
		freopen("filename.out","w",stdout);*/ 
		IOS	
		cin >> d >> s >> t;
		if(d/s<=t){
			cout << "Yes" << '\n';
		}
		else cout << "No" << '\n';
	}


Measured memory_bytes: 3736
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


a, b = map(int, input().split())

g = gcd(a, b)
num = g

ans = 1

for i in range(2, int(g ** 0.5) + 1):

    if num % i == 0:
        ans += 1
        while num % i == 0:
            num = num // i

if num != 1:
    ans += 1

print(ans)


Measured memory_bytes: 9372
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }

  getChildrenNumber() {return Number(this.left !== null) + Number(this.right !== null);}

  isLeftChild() {
    if (this.parent === null) return null;
    return this.parent.left === this;
  }

  getLeftOrRight() {return this.isLeftChild() ? 'left' : 'right';}

  getSuccessor() {
    let n;
    if (this.right !== null) {
      n = this.right;
      while (n.left !== null) n = n.left;
    } else {
      n = this.parent;
      while (!n.isLeftChild && n.parent != null) n = n.parent;
    }
    return n;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    if (this.root === null) {
      this.root = new BinaryTree.Node(key);
      return;
    }
    let x = this.root, y;
    let newNode = new BinaryTree.Node(key);
    while (x !== null) {
      y = x;
      x = x[key < x.key ? 'left' : 'right'];
    }
    newNode.parent = y;
    y[key < y.key ? 'left' : 'right'] = newNode;
  }

  find(key) {
    const innerFunc = (n) => {
      if (n === null || n.key === key) return n;
      return innerFunc(n[key < n.key ? 'left' : 'right']);
    };
    return innerFunc(this.root);
  }

  delete(key) {
    const n = this.find(key);
    let leftOrRight = n.getLeftOrRight();
    switch (n.getChildrenNumber()) {
    case 0:
      n.parent[leftOrRight] = null;
      break;
    case 1:
      n.parent[leftOrRight] = n.left || n.right;
      n.parent[leftOrRight].parent = n.parent;
      break;
    default:
      let skey = n.getSuccessor().key;
      this.delete(skey);
      n.key = skey;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch (cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    case 'f': console.log(tree.find(Number(cmd.split(' ')[1])) ? 'yes' : 'no'); break;
    case 'd': tree.delete(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



Measured memory_bytes: 203184
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int T, D; cin >> T >> D;
  int t1, t2; cin >> t1 >> t2;
  int d1, d2; cin >> d1 >> d2;

  double ans = INF;
  for(int i = 0; i <= D; i+=d1){
    for(int j = 0; j <= D; j+=d2){
      if(i + j > D || i + j == 0) continue;
      double res = 1.0 * (t1 * i + t2 * j) / (i + j);
      if(ans > abs(T - res)){
        ans = abs(T - res);
      }
    }
  }
  printf("%.6f\n", ans);

  return 0;
}


Measured memory_bytes: 3220
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t[] = new int[n];
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			t[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int tmin[] = new int[n];
		int tmax[] = new int[n];
		int amin[] = new int[n];
		int amax[] = new int[n];
		tmin[0] = tmax[0] = t[0];
		for (int i = 1; i < n; i++) {
			if (t[i] == t[i - 1]) {
				tmin[i] = 1;
				tmax[i] = t[i];
			} else {
				tmin[i] = t[i];
				tmax[i] = t[i];
			}
		}
		amin[n - 1] = amax[n - 1] = a[n - 1];
		for (int i = 0; i < n - 1; i++) {
			if (a[i] == a[i + 1]) {
				amin[i] = 1;
				amax[i] = a[i];
			} else {
				amin[i] = a[i];
				amax[i] = a[i];
			}
		}

		long r = 1;
		for (int i = 0; i < n; i++) {
			int rr = Math.min(tmax[i], amax[i]) - Math.max(tmin[i], amin[i]) + 1;
			if (rr < 1) {
				r = 0;
				break;
			}
			r = r * rr % 1000000007;
		}

		System.out.println(r);
	}
}


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

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        int result = 0;

        String[] str = br.readLine().split(" ");

        for(int i=0; i < 3; i++){
          result = result + Integer.parseInt(str[i]);
        }

        if(result > 21){
          System.out.println("bust");
        }else{
          System.out.println("win");
        }
      }
    }
}

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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
template<class T>bool CHMAX(T &a, const T &b) {if(a<b){a=b;return true;}return false;}
template<class T>bool CHMIN(T &a, const T &b) {if(b<a){a=b;return true;}return false;}
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define LL(n) ll n;assert(0<scanf("%lld", &n))

int main(){
  ll ans = 0;
  INT(n); INT(m);
  vector<ll> v(m + 1, -(1ll << 60)); v[0] = 0;
  vector<vector<ll>> dp(8, v);
  REP(i, n){
    LL(x); LL(y); LL(z);
    REP(j, 8){
      ll s = x * (1 - 2 * (j & 1)) + y * (1 - 2 * ((j >> 1) & 1)) +  z * (1 - 2 * ((j >> 2) & 1));
      REP(k, (int) min(i + 1, m), 0){
        dp[j][k + 1] = max(dp[j][k] + s , dp[j][k + 1]);
      }
      if (0 < dp[j][m]){
        ans = max(dp[j][m], ans);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 768