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

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

bool isAllVisit(const vector<bool>& visit) {
    for (auto&& v : visit) {
        if (!v)return false;
    }
    return true;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}


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

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int lenY = ty - sy;
    int lenX = tx - sx;

    auto print = [](int n, char c) {
        string s(n, c);
        cout << s;
    };

    print(lenY, 'U');
    print(lenX, 'R');
    print(lenY, 'D');
    print(lenX + 1, 'L');
    print(lenY + 1, 'U');
    print(lenX + 1, 'R');
    print(1, 'D');
    print(1, 'R');
    print(lenY + 1, 'D');
    print(lenX + 1, 'L');
    print(1, 'U');
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = mod * mod;

int main() {
	int n;
	cin >> n;
	int yakusu[1000] = {};
	for (int i = 1; i <= n; i++) {
		int temp = i;
		int div = 2;
		while (temp > 1) {
			if (temp%div == 0) {
				yakusu[div]++;
				temp /= div;
			}
			else {
				div++;
			}
		}
	}
	ll ans = 1LL;
	for (int i = 0; i < 1000; i++) {
		ans *= yakusu[i] + 1;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define re(i,a,n) for(int _tmp=n,i=a;i<_tmp;++i)
#define fec(i,a) for(__typeof a.begin() i=a.begin();i!=a.end();++i)
#define For(i,v,u) for(int i=H[u],v=to[i];i;i=nxt[i],v=to[i])
#define si(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define X first
#define Y second
#define inf 1000000000
using namespace std;
template<class T> inline void read(T&x){char c;bool fu=0;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x*=-1;}
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z) {read(x,y);read(z);}
template<class T> inline void MAX(T&x,T y){if(x<y)x=y;}
template<class T> inline void MIN(T&x,T y){if(x>y)x=y;}
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
//head
double ans,n,d,t;
void work(double n,double d,double t){
	if(n==0)return;
	ans+=(d+d+(2*n-1)*t)/2.;
	double dd=((2*n+2.)*d+5*t)/2./n,tt=(t*(4.+2*n)/2./n);
	work(n-1,dd,tt);
}
int main() {
	scanf("%lf%lf%lf",&n,&d,&t);
	work(n,d,t);
	printf("%.12lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int a,b,tmp;

  scanf("%d",&a);
  scanf("%d",&b);

  tmp = a + b;

  if(tmp < a - b ) tmp = a - b;
  if(tmp < a * b ) tmp = a * b;

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

  return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    char a;
    cin>>a;
    if(isupper(a)) cout<<'A';
    else cout<<'a';
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,m; cin>>n>>m;
	vector<vector<char>> vec(n,vector<char>(m));
	rep(i,0,n){
		rep(j,0,m){
			cin>>vec[i][j];
		}
	}
	//vector<bool> ok(n,vector<bool>(m));
	set<int> s;
	set<int> s2;
	rep(i,0,n){
		bool a=true;
		rep(j,0,m){
			if(vec[i][j]=='#') a=false;
		}
		if(a) s.insert(i);
	}
	rep(i,0,m){
		bool a=true;
		rep(j,0,n){
			if(vec[j][i]=='#') a=false;
		}
		if(a) s2.insert(i);
	}
	vector<vector<char>> ans(n,vector<char>(0));
	rep(i,0,n){
		rep(j,0,m){
			if(s.count(i)) continue;
			if(s2.count(j)) continue;
			ans[i].push_back(vec[i][j]);
		}
	}
	rep(i,0,n){
		if(ans[i].size()==0) continue;
		rep(j,0,ans[i].size()){
			cout<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
}

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

int main() {
	string s, t; cin >> s >> t; string test = t;
	sort(s.begin(), s.end()); sort(t.rbegin(), t.rend());
	
	if (s < t)cout << "Yes";
	else cout << "No";
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll int
#define N 100005
#define rep(i,j,k) for (ll i=j;i<=k;++i)
#define per(i,j,k) for (ll i=j;i>=k;--i)
using namespace std;
inline ll read(){
	char ch=getchar(); ll x=0,f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}
ll n,tot,head[N],f[N];
struct edge{ ll to,next; }e[N<<1];
void add(ll u,ll v){
	e[++tot]=(edge){v,head[u]}; head[u]=tot;
}
void dfs(ll u,ll last){
	vector<int> a;
	for (ll i=head[u],v=e[i].to;i;i=e[i].next,v=e[i].to){
		if (v==last) continue; dfs(v,u); a.push_back(f[v]);
	}
	sort(a.begin(),a.end());
	for (int i=0;i<a.size();++i)
		f[u]=max(f[u],a[i])+1;
}
int main(){
	n=read();
	rep(i,2,n){
		ll x=read();
		add(x,i);
	}
	dfs(1,-1);
	printf("%d",f[1]);
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
typedef long long ll;

int main(int argc, char const *argv[]) {
    ll N, M;
    std::cin >> N;
    ll T[N];

    for (size_t i = 0; i < N; i++) {
        std::cin >> T[i];
    }
    std::cin >> M;
    ll P[M];
    ll X[M];
    for (size_t i = 0; i < M; i++) {
        std::cin >> P[i] >> X[i];
    }
    ll sum = 0;
    for (size_t i = 0; i < N; i++) {
        sum += T[i];
    }
    for (size_t i = 0; i < M; i++) {
        std::cout << sum - T[P[i] - 1] + X[i] << '\n';
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

// 200, 10min

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

ll A, B, C;

int main()
{
    cin >> A >> B >> C;
    ll ans = INF;
    if(A % 2 == 0 || B % 2 == 0 || C % 2 ==0) {
        printf("0\n");
        return 0;
    }
    printf("%lld\n", min({A*B, B*C, C*A}));
    return 0;
}


Measured memory_bytes: 256
// abc150_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int K, X;
    cin >> K >> X;

    if (500 *  K >= X){
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
LL ave(LL, LL);

int main() {
	int x,a, b; cin >>x>> a >> b;
	if (a >= b) {
		cout << "delicious";
	}
	else {
		if (b - a <= x) {
			cout << "safe";
		}
		else cout << "dangerous";
	}
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}
LL ave(LL a, LL b) {
	return (a + b) / 2;
}

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

int main() {
  int L, R, d;
  cin >> L >> R >> d;
  int ans = 0;
  
  for (int i = L; i < R + 1; i++) {
    if (i % d == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
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;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K=in();
    int N=in();
    vector<int>A(N,0);
    REP(i,N){
        cin>>A[i];
    }
    vector<int>a(N,0);
    REP(i,N-1){
        a[i]=A[i+1]-A[i];
    }
    a[N-1]=K+A[0]-A[N-1];
    sort(all(a));
    cout<<K-a[N-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    int h,w,n,x=0,y=0;
    cin>>h>>w>>n;
    vector<int> a(n),c(w);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<a[i];j++){
            if(y%2==0){
                c[x]=i+1;
                x++;
            }
            else if(y%2==1){
                c[w-x-1]=i+1;
                x++;
            }
            if(x==w){
                for(int k=0;k<w;k++){
                    if(k!=w-1)cout<<c[k]<<" ";
                    x=0;
                    if(k==w-1)cout<<c[k]<<endl;
                }
                y++;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 384
N,M,L=map(int,input().split())
c=[[0]*N for i in range(N)]
for i in range(M):
    A,B,C=map(int,input().split())
    c[A-1][B-1]=c[B-1][A-1]=C
Q=int(input())
ST=[list(map(int,input().split())) for i in range(Q)]
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
g=csr_matrix(c)
d=floyd_warshall(g,directed=False)
import numpy as np
c=np.array([[1 if d[i][j]<=L else 0 for j in range(N)] for i in range(N)])
g=csr_matrix(c)
d=floyd_warshall(g,directed=False)
for s,t in ST:
    x=d[s-1][t-1]
    print(int(x)-1 if x<10**9 else -1)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
void self_min(ll &a,ll b){
	a = min(a,b);
}

int main(){
	int m1,d1; cin >> m1 >> d1;
	int m2,d2; cin >> m2 >> d2;

	if(d2 == 1 ) cout<< 1 << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdtr1c++.h>
    // typedef __int128 int128;
    // typedef __float128 float128;
     
    using namespace std;
    using namespace rel_ops;
    typedef long long ll;
    typedef long double ld;
    typedef complex<ld> pt;
    typedef vector<pt> pol;
    typedef vector<ll> vi;
    typedef vector<vi> vvi;
    typedef vector<vvi> vvvi;
    typedef vector<ld> vd;
    typedef vector<vd> vvd;
    typedef pair<ll, ll> pii;
    typedef vector<pii> vpii;
    #define pb push_back
     
     
    int main(){
     
      // freopen("A.in", "r", stdin);
     
      ll N;
      cin >> N;
     
     
      ll abc[100010][4];
     
      ll f[100010][4];
      for (ll i = 1; i <= N; ++i) {
        cin >> abc[i][1] >> abc[i][2] >> abc[i][3];
        if(i == 1) f[i][1] = abc[i][1], f[i][2] = abc[i][2], f[i][3] = abc[i][3];
        else f[i][1] = max(abc[i][1] + f[i-1][2], abc[i][1] + f[i-1][3]),
               f[i][2] = max(abc[i][2] + f[i-1][1], abc[i][2] + f[i-1][3]),
               f[i][3] = max(abc[i][3] + f[i-1][1], abc[i][3] + f[i-1][2]);
      }
     
      cout << max(max(f[N][1], f[N][2]), f[N][3]) << endl;
     
     
    }

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};

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(){
    int n; cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];

    ll odd=0, even=0;
    bool flag=false;
    ll total=0, res=0;

    REP(i,n){
    // 奇数番目が正
        total+=a[i];
        if(i%2!=0){
            if(total>=0){
                even+=total+1;
                total=-1;
            }
        }else{
            if(total<=0){
                even+=-total+1;
                total=1;
            }
        }
        //cout << "i= " << i << " total[i]= " << total[i] <<  " even= " << even << endl;
    }

    REP(i,n){
    // 偶数番目が正
        res+=a[i];
        if(i%2==0){
            if(res>=0){
                odd+=res+1;
                res=-1;
            }
        }else{
            if(res<=0){
                odd+=-res+1;
                res=1;
            }
        }
        //cout << "i= " << i << " res[i]= " << res[i] << " odd= " << odd << endl;
    }

    cout << min(odd, even) << endl;

    return 0;
}

Measured memory_bytes: 640
N=int(input())
ta=[]
t=N
while t>0:
    t,m=divmod(t,26)
    if m==0:
        t-=1
    ta.append(m)
l='abcdefghijklmnopqrstuvwxyz'
ta=ta[::-1]
ans=''
for i in ta:
    ans+=l[i-1]
print(ans)

Measured memory_bytes: 9180
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999


int main() {
	int a[10];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] + a[1] == a[2])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
input_lines = 4
coin_list = []
for i in range(input_lines):
  s = int(input())
  coin_list.append(s)
# print(coin_list)

def calc(coin_list, total = 0, count = 0):
    yen_500 = coin_list[0]
    yen_100 = coin_list[1]
    yen_50 = coin_list[2]
    total_yen = coin_list[3]

    for i in range(yen_500+1):
        for j in range(yen_100+1):
            for k in range(yen_50+1):
                if 500 * i + 100 * j + 50 * k == total_yen:
                    count += 1
    return count

calcurate = calc(coin_list)
print(calcurate)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;


int main() {

	set<char> S;
	string str;
	cin >> str;
	rep(i, str.size()) {
		S.insert(char(str.at(i)));
	}
	char first = 'a';
	rep(i, 26) {
		if (S.count(char(first + i))) {
		}
		else {
			cout << char(first + i) << endl;
			break;
		}
		if (char(first + i) == 'z') {
			cout << "None" << endl;
		}

	}
	
	return 0;
	
}



Measured memory_bytes: 512
s = input()
flag = True
if s[0] != "A":
    flag = False
elif s[2:-1].count("C") != 1:
    flag = False
else:
    s = s[1:].replace("C", "")
    if not s.islower():
        flag = False
if flag == True:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int		main(void)
{
	ll a;
	double b;
	cin >> a >> b;

	ll c = b * 100 + 0.001;
	cout << a * c / 100 << endl;
}



Measured memory_bytes: 3712
#include <iostream>

using namespace std;

int main(void)
{
 int H,A;
  cin >> H>>A;
  int ans;
  int iBuf;
 ans =H/A;
   iBuf = H%A;
  if(iBuf != 0)
  {
  cout << ans+1 << endl;
  }
  else
  {
    cout << ans << endl;
  }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 

using namespace std;

//#Rohitpratap311
//#Keep Calm And Stay Happy

typedef long long ll;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n],b[n];
        for(ll i=0;i<n;i++)
        {
            cin>>a[i]>>b[i];
        }
        for(ll i=n-1;i>=2;i--)
        {
            if(a[i]==b[i]&&a[i-1]==b[i-1]&&a[i-2]==b[i-2])
            {
                cout<<"Yes";
                return 0;
            }
        }
        cout<<"No";
    }
    return 0;
}

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

ll Q, H, S, D, N;

int main(void) {
  cin >> Q >> H >> S >> D >> N;

  H = min(H, 2 * Q);
  S = min(S, 2 * H);
  D = min(D, 2 * S);

  ll ans = 0;
  ans += (N / 2) * D;
  N %= 2;
  ans += N * S;

  cout << ans << endl;
}


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

int INF = 1e9;
 
int main(void){
    int h, w;
    cin>>h>>w;
    vector<string> v(h);
    rep(i, h) cin>>v[i];
    queue<pair<int, int> > que;
    queue<pair<int, int> > nextque;
    rep(i, h)rep(j, w)if(v[i][j] == '#') que.push(make_pair(i, j));
    int ans = 0;
    bool ok = true;
    vector<int>dx = {0, -1, 0, 1};
    vector<int>dy = {-1, 0, 1, 0};
    while(ok){
        bool change = false;
        nextque = queue<pair<int, int> >();
        while(!que.empty()){
            auto p = que.front();que.pop();
            rep(i, 4){
                if(p.first+dx[i]>=0 && p.first+dx[i]<=h-1 && p.second+dy[i]>=0 && p.second+dy[i]<=w-1 && v[p.first+dx[i]][p.second+dy[i]] == '.'){
                    change = true;
                    v[p.first+dx[i]][p.second+dy[i]] = '#';
                    nextque.push(make_pair(p.first+dx[i], p.second+dy[i]));
                }
            }
        }
        ok = !nextque.empty();
        que = nextque;
        if(change) ans++;
        else break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vvi            vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)        for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x)    ((c).find(x) != (c).end()) 
#define cpresent(c,x)    (find(all(c),x) != (c).end()) 
using namespace std;
ll mod=1e9+7;
#define N  100005
vi minprime(1e6+1,0), ffc(1e6+1);

void sieve(){
    for(ll i=2; i*i<=1e6;i++){
        if(minprime[i]==0){
            for(ll j=i; j<=1e6; j+=i) if(minprime[j]==0) minprime[j]=i;
        }
    }
    rep(i,1,1e6+1) if(minprime[i]==0) minprime[i]=i;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    //ll cs=1;
    while(TESTS--)
    {
        ll n; cin >> n; vi a(n);
        rep(i,0,n) cin >> a[i];
        sieve();
        rep(i,0,n){
            set<ll> fac;
            while(a[i]!=1){
                fac.insert(minprime[a[i]]);
                a[i]/=minprime[a[i]];
            }
            for(auto &&it:fac) {
                ffc[it]++;
            }
        }
        rep(i,0,1e6+1) if(ffc[i]==n){
            cout << "not coprime" << "\n";
            return 0;
        }
        ll fl = 0;
        rep(i,0,1e6+1){
            if(ffc[i]>1) fl=1;
        } 
        if(fl==0) cout << "pairwise coprime" << "\n";

        else cout << "setwise coprime" << "\n";
    }
    return 0;
}

Measured memory_bytes: 26644
#include <iostream>

using namespace std;

typedef long long   ll;
typedef long double ld;

#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)

#define endl '\n'
#define INF  0x7f7f7f7f7f7f7f7f
#define INFi 0x7f7f7f7f
const string YES = "Yes";
const string NO = "No";

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

bool solve(ll X) {
  if (X>=30) return true;
  else return false;
}

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

  ll X;
  cin >> X;

  auto ans = solve(X);
  cout << (ans ? YES : NO) << endl;

  return 0;
}


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

int p[200001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1,x;i<=n;i++){
		cin>>x;
		p[x]=i;
	}
	long long int ans=0;
	set<int> s;
	s.insert(0);
	s.insert(n+1);
	for(int i=1;i<=n;i++){
		int x=p[i];
		auto it=s.insert(x).first;
		ans+=1LL*i*(x-(*prev(it)))*(*next(it)-x);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    n %= 12;
    for (int i = 0; i < n; ++i) {
        if(i&1) b += a;
        else a -= b;
    }
    cout << a << " " << b << "\n";
    return 0;
}


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

#include <algorithm>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}
int power(long long x, long long y, long long p) {
    long long res = 1;  // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1) res = (res * x) % p;

        // y must be even now
        y = y >> 1;  // y = y/2
        x = (x * x) % p;
    }
    return res;
}

long long modInverse(long long n, long long p) { return power(n, p - 2, p); }

long long nCrModPFermat(long long n, long long r, long long p) {
    if (r == 0) return 1;
    long long fac[n + 1];
    fac[0] = 1;
    for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;

    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

signed main() {
    long long ans = 0;
    string s;
    cin >> s;
    char a, b;
    a = s[0];
    b = s[s.size() - 1];
    cout << a << s.size() - 2 << b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
	long long int n;
	cin>>n;
	long long int a[100001]={0};
	long long int sum=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a[x]++;
		sum+=x;
	}
	long long int q;
	cin>>q;
	vector<long long int> v;
	while(q--){
		long long int b,c;
		cin>>b>>c;
		sum+=(a[b])*(c-b);
		a[c]+=a[b];
		a[b]=0;
		v.push_back(sum);
	}
	for(auto i :v){
		cout<<i<<endl;
			}
	return 0;
}
//


Measured memory_bytes: 5028
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin>>n;
    int v[n];
    rep(i,n){
        cin>>v[i];
    }
    priority_queue<double,vector<double>,greater<double>> p;
    rep(i, n) { p.push(v[i]); }

    while (p.size() != 1) {
        double a, b;
        a = p.top();
        p.pop();
        b = p.top();
        p.pop();
        p.push((a + b) / 2);
    }

    cout << p.top() << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)
#define IINF 2e9
#define MOD 1e9+7

int main(void){

    string a;
    cin >> a;

    int ans = 0;

    for(int i = 0; a[i] != '\0';i++){
        ans += a[i]-'0';
    }

    cout << (ans % 9 == 0? "Yes": "No") << endl;

    return 0;
}

Measured memory_bytes: 3708
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static byte[][] d;
	static final byte INF = Byte.MAX_VALUE;

	public static void main(String[] args) {

		PrintWriter out = new PrintWriter(System.out);
		Scanner scan = new Scanner(System.in);
		byte n = scan.nextByte();
		d = new byte[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = i!=j ? INF : 0;
			}
		}
		for (int i = 0; i < n; i++) {
			byte id = scan.nextByte();
			byte c = scan.nextByte();
			for (int j = 0; j < c; j++) {
				d[id-1][scan.nextByte()-1]=1;
			}
		}

		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					d[i][j] = (byte)Math.min(d[i][j], d[i][k]+d[k][j]);
				}
			}
		}

		int p = scan.nextInt();
		for (int i = 0; i < p; i++) {
			byte s = scan.nextByte();
			byte g = scan.nextByte();
			short ttl = scan.nextShort();
			out.println(ttl<=d[s-1][g-1] || d[s-1][g-1]==INF ? "NA" : d[s-1][g-1]+1);
		}
		out.flush();
	}
}

Measured memory_bytes: 26356
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
import copy

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def calc_water(u, l, h):
    return ((u + l) * h) // 2


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    stack = []

    water = []
    sum = 0
    for i in range(len(S)):
        s = S[i]
        if s == '\\':
            stack.append(i)
        elif s == '/' and len(stack) > 0:
            j = stack.pop()
            sum += i - j
            area = i - j
            while len(water) > 0 and water[-1][0] > j:
                w = water.pop()
                area += w[1]
            water.append([j, area])

    ret = []
    for i, w in water:
        ret.append(w)
    print(sum)
    print(len(ret), *ret)


if __name__ == '__main__':
    main()



Measured memory_bytes: 8252
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define PI acos(-1)
typedef long long ll;
using namespace std;
//  Table is the complete reverse of dp
//  Always think of the pattern (LCM, GCD)
const int MOD = (int)1e9 + 7;
long long fast_power(long long base, long long power)
{
    long long result = 1;
    while(power > 0)
    {
        if(power & 1)
        {
            result = ((result % MOD) * (base % MOD)) % MOD;
        }
        base = ((base % MOD) * (base % MOD)) % MOD;
        power >>= 1;
    }
    return result;
}
int main()
{
    cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);
    long long n, k, ans = 0;
    cin >> n >> k;
    long long *x = new long long[k + 1];
    for(long long i = k; i >= 1; i--)
    {
        long long tmp = fast_power(k / i, n);
        x[i] = tmp;
        for(int j = 2; i * j <= k; j++)
            x[i] = ((x[i] - x[i * j]) % MOD + MOD) % MOD;
        ans += (x[i] * i) % MOD;
        ans %= MOD;
    }
    cout << ans;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m; cin >> n >> m;
	Graph g(n);
	REP(i, m)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		add_edge(g, a, b, 0);
		add_edge(g, b, a, 0);
	}
	int q; cin >> q;
	vector<tuple<int, int, int>> qs(q);
	REP(i, q)
	{
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		qs[i] = make_tuple(a, b, c);
	}
	vector<pii> ans(n, pii(0, -1));
	for (int query = q - 1; query >= 0; query--)
	{
		int v, d, c;
		tie(v, d, c) = qs[query];
		queue<pii> que;
		if (ans[v].second >= d) continue;
		if (ans[v].first == 0) ans[v].first = c;
		chmax(ans[v].second, d);
		que.emplace(v, d);
		while (!que.empty())
		{
			int t = que.front().first;
			int dist = que.front().second - 1;
			que.pop();
			for (auto e : g[t])
			{
				int u = e.to;
				if (ans[u].second >= dist) continue;
				if (ans[u].first == 0) ans[u].first = c;
				chmax(ans[u].second, dist);
				if (dist == 0) continue;
				que.emplace(u, dist);
			}
		}
	}
	REP(i, n) cout << ans[i].first << endl;
	return 0;
}

Measured memory_bytes: 10036
#include <bits/stdc++.h>
using namespace std;
const int N = 200007;
const int inf = 1e9 + 7;

std::vector<int> adj[N];
int n;

long long lt[N];

long long L[N];
long long R[N];




map<int, pair<int, int>> dp[N];
int d[N];
int nxt[N], f[N];
int num[N];
int mxDepth[N];

int st[N], top;

pair<int, int> calc(int h) {
	L[0] = 1; R[top + 1] = 1;

	for (int i = 1; i <= top; ++i) {
		L[i] = L[i - 1] * dp[nxt[st[i - 1]]][h].first % inf;
	}
	for (int i = top; i > 0; --i) {
		R[i] = R[i + 1] * dp[nxt[st[i - 1]]][h].first % inf;
	}
	long long has = 0;
	long long total = 1;
	for (int i = 1; i <= top; ++i) {
		auto it = dp[nxt[st[i - 1]]][h];
		has = (has + L[i - 1] * R[i + 1] % inf * it.second) % inf;
		total = total * (it.first + it.second) % inf;
	}

	total -= has; if (total < 0) total += inf;
	return make_pair(total, has);
}

void dfs(int u, int r) {
	f[u] = 1;
	nxt[u] = u;
	d[u] = (r == -1) ? 0 : (d[r] + 1);
	num[d[u]]++;
	mxDepth[u] = d[u];

	for (int v : adj[u]) {
		dfs(v, u);
		mxDepth[u] = max(mxDepth[u], mxDepth[v]);
		f[u] += f[v];
		if (nxt[u] == u || f[nxt[u]] < f[v])
			nxt[u] = v; 
	}
}

bool cmp(int u, int v) {
	return mxDepth[u] > mxDepth[v];
}

void build(int u) {
	if (nxt[u] == u) {
		dp[u][d[u]] = make_pair(1, 1);
		return;
	}

	for (int v : adj[u]) {
		build(v);
	}

	int t = nxt[u];
	top = 0;
	for (int v : adj[u]) if (v != t) st[top++] = v;
	sort(st, st + top, cmp);
	
	for (int h = d[u] + 1; h <= n; ++h) {
		while (top && mxDepth[st[top - 1]] < h) --top;
		if (!top) break;
		if (mxDepth[nxt[u]] >= h) st[top++] = nxt[u];

		auto res = calc(h);
		dp[nxt[t]][h] = res;


		if (mxDepth[nxt[u]] >= h) top--;
	}
	nxt[u] = nxt[t];
	dp[nxt[u]][d[u]] = make_pair(1, 1);

}

void solve() {
	cin >> n;

	lt[0] = 1;
	for (int i = 1; i <= n; ++i) {
		lt[i] = lt[i - 1] << 1;
		if (lt[i] >= inf) lt[i] -= inf;
	}

	for (int i = 1; i <= n; ++i) {
		int r; scanf("%d", &r);
		adj[r].push_back(i);
	}

	dfs(0, -1);
	build(0);


	long long res = 0;
	for (int i = 0; i <= mxDepth[0]; ++i) {
		res += dp[nxt[0]][i].second * lt[n - num[i] + 1] % inf;
		// cout << dp[nxt[0]][i].second << ' ' << num[i] << '\n';
		if (res >= inf) res -= inf;
	}
	cout << res << '\n';

}

int main() {
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin);
#endif

	solve();

#ifdef _LOCAL_
	cout << '\n' << 1.0 * clock() / CLOCKS_PER_SEC << '\n';
#endif
	return 0;
}

Measured memory_bytes: 59392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
  if(b==0){
    return a;
  }
  return gcd(b,a%b);
}
int main(){
  ll a,b;
  cin >> a >> b;
  ll g=gcd(a,b);
  ll num=g;
  ll ans=1;
  for(ll i=2;i*i<=num;i++){
    if(g==1){
      break;
    }
    if(g%i==0){
      ans++;
      while(g%i==0){
        g/=i;
      }
    }
  }
  if(g!=1){
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// KOI NI YAAR SAB SAHI HOEGA  BAS  CHORRO MAT
// ENJOR KARO YAAR
// HAAR MAT MAANO
// // APNA TIME AAYEGA
// BEILIEVE IN GOD
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define ma 1e18
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double
#define PI  3.14159265358979
#define pri  priority_queue<ll>
#define prim  priority_queue<ll,vector<ll>,greater<ll>>
#define flush  cout<<flush

vector<vector<double>> dp(3001,vector<double>(3001,-1)); 
lli n;
double a[3000];
lli ans;



double solve(lli index , lli tails)
{if(index == n+1)
{if(tails<=n/2)
{return 1.0;
}
else
{return 0.0;
}
}
if(dp[index][tails]!=-1)
{return dp[index][tails];
}
return dp[index][tails] =  ((a[index] * 1.0 * solve(index+1,tails)) + (1.0-a[index]) * 1.0 *  solve(index+1,tails+1));
}

int main()
{
cin>>n;
loop(i,1,n+1)
{cin>>a[i];
}
cout<<fixed<<setprecision(10)<<solve(1,0)<<"\n";
}


Measured memory_bytes: 74040
// B: Shift only
"use strict";

const DEBUG_MODE = false;
const rawInput = DEBUG_MODE
  ? "6\n382253568 723152896 37802240 379425024 404894720 471526144"
  : require("fs")
      .readFileSync("/dev/stdin", "utf8")
      .trim();

const allEven = intList => intList.every(item => item % 2 === 0);

const process = inputRaw => {
  const inputs = inputRaw.split("\n");
  const count = parseInt(inputs[1]);
  let blackboardNumbers = inputs[1].split(" ").map(item => parseInt(item));

  let operationCount = 0;

  // TODO: can probably use bitwise here to determine how many operations
  // in each number before becoming odd in one runthrough of array
  //
  // do this when there is time to optimise after answering everything
  // or use python->numpy to easily divide vector

  while (allEven(blackboardNumbers)) {
    blackboardNumbers = blackboardNumbers.map(item => Math.floor(item / 2));
    operationCount++;
  }

  console.log(operationCount);
};

process(rawInput);


Measured memory_bytes: 7500
h,w = gets.chomp.split.map(&:to_i)
s = h.times.map{gets.chomp.chars}
#ans = Array.new(h){Array.new(w,0)}
0.upto(h-1) do |i|
  0.upto(w-1) do |j|
    cnt = 0
    if s[i][j] == '.'
      -1.upto(1) do |k|
        -1.upto(1) do |l|
          if 0 <= i+k && i+k <= h-1 && 0 <= j+l && j+l <= w-1
            cnt += 1 if s[i+k][j+l] == '#'
          end
        end
      end
      s[i][j] = cnt
    end
  end
end
s.each{|n| puts n.join}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define llINF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,k,a[200010],f[200010];
int func(int mi){
	int cnt=0;
	rep(i,n){
		if(a[i]*f[i]>mi){
			cnt+=a[i]-(mi/f[i]);
		}
	}
	return cnt<=k;
}
signed main(){
	cin>>n>>k;
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>f[i];
	sort(a,a+n);
	sort(f,f+n,greater<int>());
	int ok=llINF,ng=-1;
	while(ok-ng>1){
		int mid=(ok+ng)/2;
		if(func(mid))ok=mid;
		else ng=mid;
	}
	cout<<ok<<endl;
	return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

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

Measured memory_bytes: 256