akhauriyash/Code-Regression huggingface dataset:
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    char c;
    cin >> c;

    cout << (char)(c+1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
    long n, k;
    cin >> n >> k;
    vector<long> p(n), c(n);
    for (long i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    for (long i = 0; i < n; i++) {
        cin >> c[i];
    }
    long ms = c[p[0]];
    for (long i = 0; i < n; i++) {
        long score = 0;
        long tk = k;
        long x = i;
        bool loop = false;
        while (tk > 0) {
            tk--;
            x = p[x];
            score += c[x];
            ms = max(ms, score);
            if (x == i && !loop) {
                loop = true;
                long t = tk / (k - tk) - 1;
                if (t > 0) {
                    score += score * t;
                    tk -= (k - tk) * t;
                }
                ms = max(ms, score);
            }
        }
    }
    cout << ms << endl;
}



Measured memory_bytes: 3712
/*
	Author: Hamza Hasbi
	Copyrights: "h.hamza" ==> "www.hamzahasbi.me"
	Date: 10/06/2017 13:07:24
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define uld unsigned long double
#define ui unsigned int
#define ud unsigned double
#define uf unsigned float
#define pi 2*acos(0.0)
#define module cin.ignore()
#define rep(i,l,r) for(auto i=l;i<=r;i++)
#define range(x,y) for(auto x:y)
//inline lcm(int a,int b) {return a*b/__gcd(a,b);}
//inline gcd(ll a,ll b) {return 1LL*b == 0 ? a : gcd(1LL*b, a*1LL % b*1LL);}
using namespace std;

main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	scanf("%d",&n);
	int mx=-1,mn=INT_MAX;
	for(int i=0;i<n;i++) {
		int x;
		scanf("%d",&x);
		mx=max(mx,x);
		mn=min(mn,x);
	}
	cout<<mx-mn<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int n,m,q;
char s[2007][2007];
int s0[2007][2007],s1[2007][2007],s2[2007][2007];
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;++i){
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;++j){
			s0[i][j]=s[i][j]-'0';
			s1[i][j]=s0[i][j]&s0[i][j-1];
			s2[i][j]=s0[i][j]&s0[i-1][j];
		}
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			s0[i][j]+=s0[i][j-1];
			s1[i][j]+=s1[i][j-1];
			s2[i][j]+=s2[i][j-1];
		}
		for(int j=1;j<=m;++j){
			s0[i][j]+=s0[i-1][j];
			s1[i][j]+=s1[i-1][j];
			s2[i][j]+=s2[i-1][j];
			//printf("%d ",s0[i][j]);
		}//puts("");
	}
	while(q--){
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int r=0;
		r+=s0[x2][y2]+s0[x1-1][y1-1]-s0[x2][y1-1]-s0[x1-1][y2];
		r-=s1[x2][y2]+s1[x1-1][y1]-s1[x2][y1]-s1[x1-1][y2];
		r-=s2[x2][y2]+s2[x1][y1-1]-s2[x2][y1-1]-s2[x1][y2];
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 52864
#include<iostream>
#include<string>
#include <vector>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
using vll = vector<ll>;
const ll MOD = 1e9 + 7;

int solve(ll n) {
	int c = 0;
	while (n > 0) {
		n /= 10;
		c++;
	};
	return c;
}

int main() {
	ll n;
	cin >> n;
	int ans = solve(n);
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ll j = n / i;
			int k, l;
			k = solve(i);
			l = solve(j);
			k = max(k, l);
			ans = min(ans, k);
		}
	}
	cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
typedef long long lint;
typedef vector<int> vi;

const int mod = 1e9 + 7;

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

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

// ?????????????????????????????????????????????
lint extgcd(lint a, lint b, lint& x, lint& y) {
	lint d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}

bool is_prime(int n) {
	for (int i = 2; i * i <= n; ++i) {
		if (n % i == 0) return false;
	}
	return true;
}

// n????´???° ???????????????unsorted
vi divisor(lint n) {
	vi res;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.pb(i);
			if (n / i != i) res.pb(n / i);
		}
	}

	return res;
}

// 2 * 2 * 3 * 5 * 5 * 5 = {2:2, 3:1,5:3} ???????????? map ????????£????????????
map<int, int> prime_factor(lint n) {
	map<int, int> res;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			++res[i];
			n /= i;
		}
	}

	if (n != 1) res[n] = 1;
	return res;
}

const int MAX_N = 202020;
int prime[MAX_N];
bool memo[MAX_N + 1];

// ?´???°?????¨?????? n??\???????´???°????????°?????????
int sieve(int n) {
	int p = 0;
	memset(memo, true, sizeof(memo));
	memo[0] = memo[1] = false;

	for (int i = 2; i <= n; ++i) {
		if (memo[i]) {
			prime[p++] = i;
			for (int j = i * 2; j <= n; j += i) {
				memo[j] = false;
			}
		}
	}

	return p;
}

const lint MAX_LEN = 1000000;
const lint MAX_SQRT_B = 1000000;
bool memo_all[MAX_LEN];         //i means i + a
bool memo_small[MAX_SQRT_B];

// [a, b)????´???°????????°???????????????
lint count_prime(lint a, lint b) {
	for (int i = 0; (lint)i * i < b; i++) memo_small[i] = true;
	for (int i = 0; i < b - a; i++)     memo_all[i] = true;

	for (int i = 2; (lint)i * i < b; i++) {
		if (memo_small[i]) {
			for (int j = 2; (lint)j * j < b; j += i) memo_small[j] = false;
			for (lint j = max(2LL, (a + i - 1) / i) * i; j < b; j += i) memo_all[j - a] = false;
		}
	}

	lint ret = 0;
	for (lint i = a; i < b; i++) {
		if (memo_all[i]) ret++;
	}
	return ret;
}

// k???????????§????????£??????????????°??????{a_0 : 0, a_1 : 1, a_2 : 1, ... }
lint Fib[101010];
int calcFib(int k) {
	Fib[0] = 0;
	Fib[1] = Fib[2] = 1;
	for (int i = 3; i <= k; ++i) {
		Fib[i] = Fib[i - 1] + Fib[i - 2];
		// Fib[i] %= mod;
	}

	return Fib[k];
}

int main() {
	int n;
	while (cin >> n) {
		for (int i = n - 1; i >= 0; --i) {
			if (is_prime(i)) {
				cout << i << " ";
				break;
			}
		}
		for (int i = n + 1; ; ++i) {
			if (is_prime(i)) {
				cout << i << endl;
				break;
			}
		}
	}
}

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

using namespace std;


int main(int argc, char const *argv[]){
	int x1,y1,x2,y2;
	while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2)){
		printf("%d %d ",x2+(-(y2-y1)),y2+(+(x2-x1)));
		printf("%d %d\n",x1+(-(y2-y1)),y1+(+(x2-x1)));
	}
	return 0;
}

Measured memory_bytes: 256
/*** 𝕒𝕜𝕤𝕙𝕒𝕪𝕜𝕦𝕞𝕒𝕣𝟡𝟡 ***/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
template<typename T> using id_setp = tree<pair<T,T>,null_type,less<pair<T,T>>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=2e3+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
    ll a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<' '<<b<<' '<<c<<'\n';
}

int main()
{
    IOS();
   
    int tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
typedef long long ll;
int main(int argc,int *argv[])
{
	int a,b,i;
	int flag=0;
	scanf("%d%d",&a,&b);
	for(i=1; i<=(b+a)*13 ;i++)
	{
		if((int)(i*0.08)==a && (int)(i*0.1)==b)
		{
			flag = 1;
			break;
		}
			
	}
	if(flag)
		printf("%d",i);
	else
	printf("-1");
	return 0;
}


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

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

  sort(a, a + n);

  long long dp[n];
  dp[0] = a[0];
  for (int i = 1; i < n; i++) {
    dp[i] = dp[i - 1] + a[i];
  }

  int temp = 0;
  for (int i = n - 1; i > 0; i--) {
    if (dp[i - 1] * 2 < a[i]) {
      temp = i;
      break;
    }
  }

  cout << n - temp << endl;

  
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  const int coin[] = {500, 100, 50, 10, 5, 1};
  int n;

  while (cin >> n, n){
    int cnt = 0;
    for (int i = 0; i < 6; i++){
      while (n + coin[i] <= 1000){
        n += coin[i];
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}

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

int main(){
  char tmp[1111111];
  string IOI,com;
  int n,m,cou,p_cou;
  while(1){
    cou = 0;
    com = "I";
    cin >> n;
    if(n == 0)break;
    cin >> m;
    for(int i=0;i<m;i++){
      cin >> tmp[i];
    }
    IOI = tmp;
    p_cou = n + n + 1;
    for(int i=0;i<n;i++){
      com += 'O';
      com += 'I';
    }
    for(int i=0;i<m-p_cou;i++){
      string copy = IOI.substr(i,p_cou);
      if(copy == com){
	cou++;
      }
    }
    cout << cou << endl;
  }
}

Measured memory_bytes: 3120
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define DESS(X) cout <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 10007;
const ll INF = 20000000000;
typedef std::pair<int,int> P;


	ll ans=0;
	ll N,M,K;
	ll A[200010],B[200010],as,bs;
	// ll L[200010],R[200010];
	ll deff[200010];
	vector<P> Q;
	string S,T;
	ll id=0;
	ll sum;bool F=true;

int main(){
	ios_base::sync_with_stdio(false);
	cin>>N;
	REP(i,N){cin>>A[i];as+=A[i];}
	REP(i,N){cin>>B[i];bs+=B[i];deff[i]=A[i]-B[i];}
	if(bs>as){
		cout<<-1;
		return 0;
	}
	sort(deff,deff+N);
	REP(i,N){
		if(deff[i]<0){ans++;id++;sum+=deff[i];}
		else{break;}
	}
	DEB(ans)DEB(id)
	if(sum>=0){cout<<0<<endl; return 0;}
	REP(i,N-id){
		sum+=deff[N-1-i];
		ans++;
		if(sum>=0){break;}
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 3584
A,B=map(int,input().split())
R=list(range(1,A+1))
for i in range(2*B):
  L=list(map(int,input().split()))
  if i%2==1:
    for j in range(len(L)):
      if L[j] in R:
        R.pop(R.index(L[j]))
  if R==list():
    break
print(len(R))

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

public class Hello
{
    public static int A, B, C;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        A = int.Parse(line[0]);
        B = int.Parse(line[1]);
        C = int.Parse(line[2]);
        var s = Console.ReadLine().Trim();
        var ans = 0;
        for (int i = 0; i < k; i++)
        {
            var ww = getAns(n, k, s, i);
            ans += ww;
        }
        Console.WriteLine(ans);
    }
    static int getAns(int n, int k, string s, int t)
    {
        var ans = 0;
        var w = t;
        var a = new List<char>();
        while (w < n)
        {
            if (s[w] == 'r') a.Add('g');
            else if (s[w] == 's') a.Add('c');
            else a.Add('p');
            w += k;
        }
        var amax = a.Count();
        var p = 0;
        var pre = 'x';
        while (p < amax)
        {
            var my = getWin(a[p]);
            if (my != pre)
            {
                ans += getPoint(a[p]);
                pre = my;
            }
            else
            {
                if (p + 1 < amax)
                {
                    var nextmy = getWin(a[p + 1]);
                    my = getOther(my, nextmy);
                    pre = my;
                }
                else
                {
                    my = getOther2(my);
                    pre = my;
                }
            }
            p++;
        }
        return ans;
    }
    static char getOther2(char a)
    {
        if (a == 'g') return 'c';
        if (a == 'c') return 'p';
        return 'g';
    }
    static char getOther(char a, char b)
    {
        var t = new char[2];
        t[0] = a; t[1] = b;
        Array.Sort(t);
        if (t[0] == 'c' && t[1] == 'g') return 'p';
        if (t[0] == 'c' && t[1] == 'p') return 'g';
        if (t[0] == 'g' && t[1] == 'p') return 'c';
        if (t[0] == 'g' && t[1] == 'g') return 'c';
        if (t[0] == 'c' && t[1] == 'c') return 'p';
        return 'g';
    }
    static int getPoint(char a)
    {
        if (a == 'g') return C;
        if (a == 'c') return A;
        return B;
    }
    static char getWin(char a)
    {
        if (a == 'g') return 'p';
        if (a == 'c') return 'g';
        return 'c';
    }
}

Measured memory_bytes: 17300
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int n;
  int ans = 100000;
  cin >> n;
  for(int i = 0; i < n; ++i){
    ans = ceil((ans * 1.05) / 1000.0) * 1000;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll ans(ll x, ll y) {
	if ((x + y) % 3 != 0) { return 0; }

	ll a, b;
	a = (2 * y - x) / 3;
	b = (2 * x - y) / 3;

	COMinit();

	
	return COM(a + b, a);
}




int main() {
	ll X;
	ll Y;
	cin >> X >> Y;

	cout << ans(X, Y);


	system("PAUSE");

}

Measured memory_bytes: 23928
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}
ll dx[2]={1,0};
ll dy[2]={0,1};

int main(){
    IOS;
    make2(ll,n,m);
    makevec(ll,a,n);
    ll ans=a[0]/2;
    bool flag=1;
    fr(i,n){
        if(a[i]%2==1) flag=0;
        else ans=(ans*a[i]/2)/gcd(ans,a[i]/2);
    }
    ll e=0;
    while(a[0]%2==0) {e++; a[0]/=2;}
    //cout<<e<<endl;
    for(ll i=1;i<n;i++){
        ll p=0;
        while(a[i]%2==0) {p++; a[i]/=2;}
        if(p!=e) flag=0;
       // cout<<p<<endl;
    }
    if(!flag) cout<<"0 \n";
    else{
        ll x=m/ans;
        cout<<x-x/2<<endl;
    }


    return 0;
}


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

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

#define MAX 100005
#define INF INT_MAX

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

class Node
{
public:
    int id;
    int parent;
    int left;
    int right;
    Node(int id) {
        this->id = id;
        parent = -1;
    }
};

vector<Node> nodes;
vector<int> preorder;
vector<int> inorder;
vector<int> postorder;

void dfs(int v, int p)
{
    int l = nodes[v].left;
    int r = nodes[v].right;
    int h = 0;

    preorder.push_back(v);
    if (l != -1) {
        dfs(l, v);
    }
    inorder.push_back(v);
    if (r != -1) {
        dfs(r, v);
    }
    postorder.push_back(v);
}

int main(int, char**)
{
    int n;
    cin >> n;

    rep(i,n) nodes.push_back(Node(i));
    rep(i,n) {
        int id, left, right;
        cin >> id >> left >> right;
        nodes[id].left = left;
        nodes[id].right = right;
        if (left != -1) {
            nodes[left].parent = id;
        }
        if (right != -1) {
            nodes[right].parent = id;
        }
    }
    auto itr = find_if(nodes.begin(), nodes.end(), [] (Node& nd) { return nd.parent == -1; } );
    int root = distance(nodes.begin(), itr);
    dfs(root, -1);

    cout << "Preorder" << endl;
    rep(i,n) cout << " " << preorder[i];
    cout << endl;

    cout << "Inorder" << endl;
    rep(i,n) cout << " " << inorder[i];
    cout << endl;

    cout << "Postorder" << endl;
    rep(i,n) cout << " " << postorder[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  int d,e;
  int i,j;
  while(1){
    double ans=INF;
    cin>>d>>e;
    if(d==0 && e==0)break;
    rep(i,d+1){
      j=d-i;
      double rail=sqrt(i*i+j*j);
      rail=max(rail-e,e-rail);//diff
      ans=min(ans,rail);
    }
    printf("%.10f\n",ans);
  }
}

Measured memory_bytes: 3220
N = int(input())
MOD = 1e+9 + 7
shift = 70
a = [int(i) for i in input().split()]

b = [0 for _ in range(shift)]

for i in a:
  for j in range(shift):
    b[j] += (i >> j) & 1

ans = 0
for i, j in enumerate(b):
  ans += ((j * (N - j)) * 2**i) % MOD
  
print(int(ans%MOD))

Measured memory_bytes: 122808
#include<bits/stdc++.h>
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)
using namespace std;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    int maxi = (n+1)/2;
    cout << (k<=maxi?"YES":"NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clz(x) - 1;	}


//Variables Declaration
int N , W ;

vector<ll> w;
vector<ll> v ;


ll dp[(int)(2e3 * 100 ) ];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	memset(dp, 0x3f, sizeof(dp));

	cin >> N >> W;
	w.resize(N);
	v.resize(N);

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

	dp[0] = 0;
	for (int k = 0 ; k < N ; ++k ) {
		for (int x = 100000 ; x >= 0 ; x--) {
			dp[x + v[k]] = min(dp[x + v[k]] , dp[x] + w[k]);
		}
	}

	for (int i = 100000 ; i >= 0  ; --i) {
		if (dp[i] <= W) {
			cout << i   << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r,d,x;
    cin>>r>>d>>x;
    for(int i=0;i<10;i++){
        x=r*x-d;
        cout <<x<<endl;
    }


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n, k; cin >> n >> k;
	int a[n];
	rep(i,n) {
		cin >> a[i];
		a[i]--;
		a[i] %= k;
	} 
	int sum[n + 1] = {};
	rep(i,n) sum[i + 1] = (sum[i] + a[i]) % k;
	map<int, int64_t> cnt;
	int64_t ans = 0;
	if(n < k - 1) {
		for(int i = 0; i <= n; ++i) {
			ans += cnt[sum[i]]++;
		}
	} else {
		for(int i = 0; i < k - 1; ++i) {
			ans += cnt[sum[i]]++;
		}
		for(int i = k - 1; i <= n; ++i) {
			ans += cnt[sum[i]]++;
			cnt[sum[i - (k - 1)]]--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14336
s = input()

flag = True

while s != "":
    if s[-5:] == "dream":
        s = s[:-5]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-5:] == "erase":
        s = s[:-5]
    elif s[-6:] == "eraser":
        s = s[:-6]
    else:
        flag = False
        break

if flag:
    print("YES")
else:
    print("NO")

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

bool cek[102];

int main(){
	int x,n;
	cin >> x >> n;
	while(n--){
		int y;
		cin >> y;
		cek[y] = 1;
	}
	int up = x,down=x;
	if(!cek[x]){
		cout << x << '\n';
	}else{
		int ans=-1;
		down = x;
		up = x;
		while(cek[down]&&cek[up]){
			down--;
			up++;
			if(!cek[down]){
				ans = down;
			}else if(!cek[up]){
				ans = up;
			}
		}
		cout << ans << '\n';
	}
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string n;cin>>n;
    int x=0;
    for (int i=0;i<n.size();i++){
        x+=n[i]-48;
    }if (stoi(n)%x==0)cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  double R; cin >> R;
  cout << fixed << setprecision(30) << R*2*M_PI << endl;
}


Measured memory_bytes: 3760
#include <map>
#include <cmath>
#include <cfloat>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

template<class T> class Point {
public:
  T x, y;

  Point(T x, T y) {
    this->x = x;
    this->y = y;
  }

  Point<T> operator +(const Point &p) const {
    return Point<T>(this->x + p.x, this->y + p.y);
  }

  Point<T> operator -(const Point &p) const {
    return Point<T>(this->x - p.x, this->y - p.y);
  }

  bool operator <(const Point &p) const {
    if (this->x != p.x)
      return this->x < p.x;
    else
      return this->y < p.y;
  }

  bool operator >(const Point &p) const {
    return p < *this;
  }

  bool operator <=(const Point &p) const {
    return !(*this > p);
  }

  bool operator >=(const Point &p) const {
    return !(*this < p);
  }

  bool operator ==(const Point &p) const {
    return this->x == p.x && this->y == p.y;
  }
};

template<class T> double inner_product(Point<T> a, Point<T> b) {
  return a.x * b.x + a.y * b.y;
}

template<class T> double cross_product(Point<T> a, Point<T> b) {
  return a.x * b.y - a.y * b.x;
}

// return: list of points counterclockwise that compose convex hull
template<class T> vector<Point<T>> convex_hull(vector<Point<T>> &points) {
  Point<T> p0 = points[0];
  for (Point<T> p: points) {
    if (p.y < p0.y)
      p0 = p;
    else if (p.y == p0.y && p.x < p0.x)
      p0 = p;
  }

  // pair<pair<angle, distance>, point>
  typedef pair<pair<double, double>, Point<T>> Ppp;
  vector<Ppp> v;
  for (Point<T> p: points) {
    if (p == p0)
      continue;
    double angle = atan2(p.y - p0.y, p.x - p0.x);
    double dist = sqrt(pow(p.x - p0.x, 2) + pow(p.y - p0.y, 2));
    v.push_back(make_pair(make_pair(angle, dist), p));
  }

  sort(v.begin(), v.end());
  auto it = v.end(); it--;
  while (fabs(it->first.first - v.back().first.first) <= DBL_EPSILON) it--;
  it++;
  reverse(it, v.end());

  vector<Point<T>> res;
  res.push_back(p0);
  res.push_back(v[0].second);
  for (uint i = 1; i < v.size(); i++) {
    Point<T> p = v[i].second;
    while (res.size() >= 2) {
      Point<T> p2 = *(res.end() - 2), p1 = res.back();
      Point<T> v1 = p2 - p, v2 = p1 - p;
      T c = cross_product(v1, v2);
      if (c >= 0)
        break;
      res.erase(res.end() - 1);
    }
    res.push_back(p);
  }

  return res;
}

int main(void) {
  int N;
  vector<Point<int>> v;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back(Point<int>(x, y));
  }

  vector<Point<int>> res = convex_hull(v);
  cout << res.size() << endl;
  for (uint i = 0; i < res.size(); i++)
    cout << res[i].x << ' ' << res[i].y << endl;

  return 0;
}



Measured memory_bytes: 7616
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;

const int MN = 50500;

int w, n;
int x[MN];
int sum[MN];

int res[MN], dp[MN];
bool calc(int k) {
    dp[n] = 0;
    res[n-1] = 1;
    dp[n-1] = 1;
    for (int i = n-2; i >= 0; i--) {
        if (sum[n]-sum[i]+n-i-1 <= w) {
            res[i] = 1;
            dp[i] = res[i] + dp[i+1];
            continue;
        }
        int x, y;
        int l = i+1, r = n;
        while (r-l > 1) {
            int md = (l+r)/2;
            if (sum[md]-sum[i]+k*(md-i-1) < w) {
                l = md;
            } else {
                r = md;
            }
        }
        x = r;
        l = i+1, r = n;
        while (r-l > 1) {
            int md = (l+r)/2;
            if (sum[md]-sum[i]+md-i-1 <= w) {
                l = md;
            } else {
                r = md;
            }
        }
        y = r;
        if (dp[x]-dp[y] >= 1) res[i] = 1;
        else res[i] = 0;
        dp[i] = res[i] + dp[i+1];
    }
    return res[0];
}

bool solve() {
    scanf("%d %d", &w, &n);
    if (!w && !n) return false;
    sum[0] = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", x+i);
        sum[i+1] = sum[i] + x[i];
    }
    for (int i = 1; i <= w; i++) {
//        printf("calc %d %d\n", i, calc(i));
    }
    int l = 0, r = w;
    while (r-l > 1) {
        int md = (l+r)/2;
        if (calc(md)) {
            r = md;
        } else {
            l = md;
        }
    }
    printf("%d\n", r);
    return true;
}

void main2() {
    while(solve()) {}
}

ll eord, enew;
int main() {
    const int SZ = 120*1024*1024;
    void *p = malloc(SZ);
    enew = (long long)p + SZ - 1;

//    __asm__("mov %rsp, eord");
//    __asm__("mov enew, %rsp");

    main2();

//    __asm__("mov eord, %rsp");
}

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

string arr[3];
int main() {
    for (auto &el: arr) cin >> el, reverse(begin(el), end(el));


    int i = 0;
    while( true ) {
        int lst = arr[i].size() - 1;
        char ch =  arr[i][lst] ;

        if ( arr[i].size() == 0 ) {
            if ( i == 0 ) cout << 'A' << endl;
            else if ( i == 1 ) cout << 'B' << endl;
            else cout << "C" << endl ;
            break;
        }

        arr[i].pop_back();
        
        if ( ch == 'a' ) i = 0;
        else if (ch == 'b' ) i = 1;
        else i = 2;   
    }

    return 0;
}


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

int main(){
  long long k;	cin >> k;
  long long ans=0;
  for(long long i=1;i<=k;i++){
    for(long long j=1;j<=k;j++){
      for(long long l=1;l<=k;l++){
        ans+=__gcd(__gcd(i,j),l);
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,k,a[200000];
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i],a[i]--;
    map<int,int>mp;
    int i=0,cnt=0;
    for(;mp.find(i)==mp.end();i=a[i],cnt++)
        mp[i]=cnt;
    int sz=cnt-mp[i];
    vector<int>vec;
    for(int j=0;j<sz;i=a[i],j++)
        vec.push_back(i);
    if(k<cnt-sz){
        int ans=0;
        for(int j=0;j<k;j++)
            ans=a[ans];
        cout<<ans+1<<endl;
    }else
        cout<<vec[(k-cnt+sz)%sz]+1<<endl;
}

Measured memory_bytes: 18288
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,a[3];
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[j];
		}
		sort(a,a+3);
		if(a[2]*a[2]==(a[0]*a[0]+a[1]*a[1]))cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1168
def gcd(x, y):
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

def lcm(x, y):
    return x//gcd(y, x)*y

n = int(input())
a = list(map(int, input().split()))

l = 1
for x in a:
    l = lcm(x, l)

ans = 0
for x in a:
    ans += l//x

print(ans%(10**9+7))

Measured memory_bytes: 4084
n, m, x0 = list(map(int, input().split()))
c = [0] * n
a = [[0]*m for i in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    c[i] = tmp[0]
    a[i] = tmp[1:]

b = [[0]*m for i in range(2**n)]
money = [0] * (2**n)

list2n = [list(f"{i:0{n}b}") for i in range(2**n)]

for i, x in enumerate(list2n):
    for j in range(n):
        money[i] += c[j] * int(x[j])
        for k in range(m):
            b[i][k] += a[j][k] * int(x[j])
            
ans = 1e10
for i in range(2**n):
    flag = True
    for j in range(m):
        if b[i][j] < x0:
            flag = False
            break
    if flag == True:
        ans = min(ans, money[i])

print(ans) if ans != 1e10 else print(-1)

Measured memory_bytes: 11988
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    LL n;
    cin >> n;
    vector<pair<LL, LL>> v(n);
    rep(i, n) {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end(), [](auto a, auto b){
                                 return a.second < b.second;
                             });
    LL sum = 0;
    rep(i, n) {
        sum += v[i].first;
        if (sum > v[i].second) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3328
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
c = 0
for i in range(n):
    d1,d2 = map(int, input().split())
    if d1==d2:
        c += 1
    else:
        c = 0
    if c==3:
        print("Yes")
        break
else:
    print("No")

Measured memory_bytes: 61988
import java.io.*;
import java.util.StringTokenizer;
import java.util.concurrent.atomic.AtomicLong;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();

        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                if (n == i * j) {
                    out.println("Yes");
                    return;
                }
            }
        }
        out.println("No");
    }

    private static boolean contains(int[] d, int i) {
        for (int i1 : d) {
            if (i1 == i)
                return true;
        }
        return false;
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

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


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  ll n;
  cin >> n;
  int cnt = 0;
  n--;
  deque<char> q;
  while(n >= 0) {
    q.push_front((char)'a' + (n % 26));
    n /= 26;
    n--;
  }
  while(!q.empty()) {
    cout << q.front();
    q.pop_front();
  }
  cout << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


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

#define int long long
 	
const int N = 100 + 1;
vector< int > g[N];
int d[N]; // stores the depth of all nodes

void BFS(int u){
   queue<int> q;
   q.push(u);
   d[u] = 0;
   while (!q.empty()){
	   int x = q.front(); q.pop();
	   for(auto it : g[x]){
		     if (d[it] != -1) continue;
		     d[it] = d[x] + 1;
		     q.push(it);
		 }  
	 }
}

int32_t main(){
   int n, m, deg;
   cin >> n;
   for (int i = 0; i < n; i++){
	    cin >> m >> deg;
	    m--;
	    for(int i = 0; i < deg; i++){
		    int x;
		    cin >> x;
		    x--;
		    g[m].push_back(x);
	    }  
	 }
	for (int i = 0; i < n; i++) d[i] = -1;
    BFS(0);
    for (int i = 0; i < n; i++){
	   int idx = i + 1;
	   if (d[i] == -1) cout << idx << " " << -1 << endl;
	   else cout << idx << " " << d[i] << endl; 
	 }
}



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

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == t[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
//#include<unordered_map>
using namespace std;
#define int long long
#define ll long long
#define str string
#define db double
#define ac() cout<<"Yes"<<endl
#define wa()  cout<<"No"<<endl
#define ddd cout<<"---debug---"<<endl;
#define ff(a,b) for(signed long long (a)=1;(a)<=(b);(a)++)
#define fff(a,b) for(signed long long (a)=0;(a)<(b);(a)++)
#define re readdd()
#define pr(a) printtt(a)
#define pee puts("");
#define eee putchar(' ');
#define pss(a) push_back(a)
#define ps(a) push(a)
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}//
int ppow(int a,int b,int mod){a%=mod;//
int ans=1%mod;while(b){if(b&1)ans=(long long)ans*a%mod;
a=(long long)a*a%mod;b>>=1;}return ans;}
int readdd(){int x=0,f=1;char c=getchar();//
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return f*x;}
void printtt(int x){if(x<0)putchar('-'),x=-x;
if(x>=10)printtt(x/10);putchar(x%10+'0');}
bool addd(int a,int b){return a>b;};
//
const int maxm=2e5+5;
int a[maxm];
signed main(){
    int n=re,m=re;
    ff(i,n)a[i]=re;
    int sum=0;ff(i,n)sum+=a[i];
    int ans=0;
    ff(i,n)if(a[i]*4*m>=sum)ans++;
    if(ans>=m)ac();else wa();
    return 0;
}


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

#define ll long long
#define endl "\n"

ll a[100005],n,k,dp[100006];

ll solve(ll i){
    if(i==n-1)  return 0;
    if(i>=n)    return INT_MAX;
    if(dp[i]!=-1)   return dp[i];
    ll ans=INT_MAX;
    for(ll j=i+1;j<min(n,i+k+1);j++){
        ans=min(ans,abs(a[i]-a[j])+solve(j));
    }
    return dp[i]=ans;
}

int main(){
    memset(dp, -1, sizeof dp);
    cin >> n >> k;
    for(ll i=0;i<n;i++)
        cin >> a[i];
    cout << solve(0) << endl;
    return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        var h = n / 2;
        Console.WriteLine(h * (h + n % 2));
    }
}

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

using namespace std;

#define int long long
#define pii pair<int, int>
#define pb push_back
int const N = 51;
vector<int> v[N];
vector<pii> edges;
int a[N];
vector<pii> path;
int m;
int dp[51][(1<<20)];

bool dfs(int x, int y, int p = -1) {
    if(x == y) {
        return 1;
    }
    for(auto i: v[x]) {
        if(i == p) continue;
        if(dfs(i, y, x)) {
            path.pb({x, i});
            return 1;
        }
    }
    return 0;
}
int solve(int i, int mask) {
    if(mask == (1 << m) - 1) {
        return dp[i][mask] = (1LL << (edges.size() - i));
    }
    if(i == edges.size()) {
        return  dp[i][mask] = 0;
    }
    if(dp[i][mask] != -1) return dp[i][mask];
    return  dp[i][mask] = solve(i + 1, mask) + solve(i + 1, mask|a[i]);
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int N;
    cin >> N;
    for(int i = 0; i < N - 1; i++) {
        int x, y;
        cin >> x >> y;
        edges.pb({x, y});
        v[x].pb(y);
        v[y].pb(x);
    }
    memset(dp, -1, sizeof dp);
    cin >> m;
    for(int j = 0; j < m; j++) {
        int x, y;
        cin >> x >> y;
        path.clear();
        dfs(x, y);
        for(auto e: path) {
            for(int i = 0; i < edges.size(); i++) {
                if(edges[i].first == e.first && edges[i].second == e.second || edges[i].first == e.second && edges[i].second == e.first) {
                    a[i] |= (1 << j);
                }
            }
        }
    }
    cout << solve(0, 0) << endl;
    return 0;
}



Measured memory_bytes: 418176
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = []
last = [[-1] for i in range(26)]

# max index greedy search
for i in range(D):
    op = 0
    mx = 0
    for j in range(26):
        if s[i][j]*c[j] > mx:
            mx = s[i][j]*c[j]
            op = j
    t.append(op+1)
    last[op].append(i)
    # ans += s[i][op]
    # last[op]=i
    # for j in range(26):
    #     ans -= c[j]*(i-last[j])
    # for j in range(26):
    #     ans -= c[j]*(i-last[j][-1])

# update
from bisect import *
import random
m = 400000
def suminc(a,b):
    return b*(b-1)//2-a*(a-1)//2
while m:
    m-=1
    update = 0
    d = random.randint(1,D)
    q = random.randint(1,26)
    d-=1
    q-=1
    oq = t[d]-1
    update += s[d][q]-s[d][oq]
    idx = bisect_left(last[oq],d)
    if idx == len(last[oq])-1:
        cnt = D - last[oq][idx]
    else:
        cnt = last[oq][idx+1] - last[oq][idx]
    update += c[oq]*suminc(0,cnt)
    cntprv = last[oq][idx] - last[oq][idx-1]
    update -= c[oq]*suminc(cntprv,cntprv+cnt)

    idx2 = bisect_left(last[q],d)-1
    if idx2 == len(last[q])-1:
        cnt = D - d
    else:
        cnt = last[q][idx2+1] - d
    if idx2 == len(last[q])-1:
        cntprv = D - last[q][idx2] - cnt
    else:
        cntprv = last[q][idx2+1] - last[q][idx2] - cnt
    update += c[q]*suminc(cntprv,cntprv+cnt)
    update -= c[q]*suminc(0,cnt)

    if update > 0:
    # ans += update
        del last[oq][idx]
        last[q].insert(idx2+1,d)
        # print(ans)
        t[d] = q+1

# with open('ramdom.out', 'w') as f:
#     for i in range(D):
#         print(t[i],file=f)

for i in range(D):
    print(t[i])


Measured memory_bytes: 91852
#include<iostream>
#include<algorithm>
using namespace std;
int N;
long A[2<<17];
main()
{
	cin>>N;
	long s=0;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		s+=A[i];
	}
	long t=0,m=s;
	for(int i=0;i<N;i++)
	{
		t+=A[i];
		if(abs(s-2*m)>abs(s-2*t))m=t;
	}
	cout<<abs(m-(s-m))<<endl;
}


Measured memory_bytes: 1792
n = int(input())
count = 0
data = [int(s) for s in input().split()]
max = data[0]
for i in range(0,n-1):
    
    if max < data[i]:
      max = data[i]
    if data[i] <= data[i+1] and data[i+1] >= max:
        count += 1


print(count+1)

    
    

Measured memory_bytes: 3060
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// -fsanitize=undefinedでオーバーフロー検出
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    ll h,w;
    cin>>h>>w;
    string str[h];
    rep(i,h) cin>>str[i];
    ll x=0;
    ll y=0;
    while(x!=w-1||y!=h-1){
        if(y!=h-1&&str[y+1][x]=='#'){
            str[y+1][x]='.';
            y++;
        }else if(x!=w-1&&str[y][x+1]=='#'){
            str[y][x+1]='.';
            x++;
        }else{
            f=1;
            break;
        }
       // cout<<y<<" "<<x<<endl;
    }
   // cout<<str[1][4]<<endl;
  //  rep(i,h){rep(j,w) {cout<<str[i][j];}ln;}
    if(str[0][0]=='.') f=1;
    str[0][0]='.';
    str[h-1][w-1]='.';
    rep(i,h)rep(j,w) if(str[i][j]=='#') f=1;
    if(f)cout<<"Impossible"<<endl;
    else cout<<"Possible"<<endl;
    
    return 0;
}


Measured memory_bytes: 3632
a, b, h, m = gets.chomp.split(" ").map(&:to_i)

between_corner = ((30 * h + 0.5 * m)  - 6.0 * m).abs
theta = between_corner * Math::PI / 180.0
ans = a*a + b*b - 2.0 * a * b * Math.cos(theta)

puts Math.sqrt(ans)

Measured memory_bytes: 14780