akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        System.out.println( (int)Math.pow(n,3) );
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) {
                return buffer[ptr++];
            } else {
                return -1;
            }
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
                throw new NumberFormatException();
            }
            return (int) nl;
        }

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


Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define per(a, b, c) for(int a = (b); a >= (c); -- a)
using namespace std;
template <class T> void rd(T &x){
  x = 0; int f = 1; char ch = getchar();
  while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}

int ans;
char s[16];

int main(){
  scanf("%s", s);
  int len = strlen(s);
  rep(i, 0, len - 1) ans += s[i] == 'x';
  if(15 - ans >= 8) puts("YES");
  else puts("NO");
  return 0;
}



Measured memory_bytes: 256
a,b = list(map(int,input().split()))
s =input()
for i in range(a+b+1):
    if i == a:
        if s[i] !='-':
            print('No')
            break
    else:
        if s[i]=='-':
            print("No")
            break
            
        else:
            if int(s[i])<0 or 9<int(s[i]):
                print("No")
                break
else:
    print('Yes')

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

int main(){
  int n,tmp,cnt=1;
  cin >> n;
  vector<int> mochis(n);
  for(int i=0;i<n;i++){
    cin >> mochis.at(i);
  }
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(mochis.at(j)<mochis.at(j-1)){
        tmp=mochis.at(j);
        mochis.at(j)=mochis.at(j-1);
        mochis.at(j-1)=tmp;
      }
    }
  }
  for(int i=0;i<n-1;i++){
    if(mochis.at(i)<mochis.at(i+1))cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3592
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(input()) for i in range(N)]

    dp = [0] * (N+1)
    
    for i in range(N):
        dp[A[i]] = dp[A[i]-1] + 1

    print(N - max(dp))


if __name__ == "__main__":
    main()

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;

  double radH = h * 30 + m * 0.5;
  double radM = m * 6;
  double rad = M_PI / 180.0 * (radH - radM);

  double squareC = a * a + b * b - 2 * a * b * cos(rad);

  printf("%.10f\n", sqrt(squareC));
  return 0;
}

Measured memory_bytes: 4244
#include <bits/stdc++.h>
     
    using namespace std;
    const long long INF = 1LL <<60;  
     
    long long gcn(long long x,long long y){
      if(x%y==0){
        return y;
      }
      else{
        return gcn(y,x%y);
      }
    }
     
    int main(void){
      long long res=0;
      long long n,q;
      long tmp,tmp2;
      long n_max=100000;
      long long i,j,k;
      long a[100010]={};
      
      cin>>n;
      for(i=0;i<n;i++){
        cin>>tmp;
        a[tmp]++;
        res+=tmp;
      }
      cin>>q;
      for(i=0;i<q;i++){
        cin>>tmp>>tmp2;
        res+=a[tmp]*(tmp2-tmp);
        a[tmp2]+=a[tmp];
        a[tmp]=0;
        cout<<res<<endl;
      }
//      cout<<res<<endl;
      return 0;
    }

Measured memory_bytes: 4424
sum = 0
n = gets.chomp.to_i
w = gets.chomp.split.map(&:to_i)
sumw = []
for a in 0..n - 1
  sum = sum + w[a]
  sumw[a] = sum
end
d = []
for b in 0..n - 1
  d << (sum - 2 * sumw[b]).abs
end
puts d.min


Measured memory_bytes: 3836
#include<iostream>
#include<algorithm>

int const MAXN = 100;
int X[MAXN];

int main() {
  int N;
  std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> X[i];
  int m = 100*100*100;
  for(int P = 1; P <= 100; ++P) {
    int s = 0;
    for(int i = 0; i < N; ++i) s += (X[i]-P)*(X[i]-P);
    m = std::min(m, s);
  }
  std::cout << m << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  char s[n];
  // Aがゴールのパターン、Bがゴールのパターン
  bool flag = true;

  for (int i = 1; i <= n; i++) {
    cin >> s[i];

    //岩が二連続のパターン
    if (i >= a && i <= max(c, d)) {
      if (s[i] == '#' && s[i] == s[i - 1]) flag = false;
    }
  }

  // c>dならb動かしてa動かして終わり
  if (d < c) {
    // d前後に岩があるとき
    if (s[d + 1] == '#' || s[d - 1] == '#') flag = false;

    for (int i = b; i <= d; i++) {
      // 途中の道で.が3連続であるとき
      if (s[i] == s[i + 1] && s[i] == s[i - 1] && s[i] == '.') {
        flag = true;
        break;
      }
    }

    if (b - 1 == a && b + 1 == '.') flag = true;
  }

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(void){
    int n,m,i,count=0;
    float sum=0;
    cin >> n >> m;
    int *a = new int[n];
    for(i=0;i<n;i++){
        cin >> a[i];
        sum+=a[i];
    }
    sum/=4.0*(float)m;
    for(i=0;i<n;i++){
        if(a[i]>=sum)
            count++;
        if(count==m)
            break;
    }
    if(count==m)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
from decimal import Decimal

cnt, m = map(int, raw_input().split())
targets = map(int, raw_input().split())

limit = Decimal(str(sum(targets))) / Decimal(str(4 * m))

n = 0
for target in targets:
    if target >= limit:
        n += 1

print 'Yes' if n >= m else 'No'


Measured memory_bytes: 4268
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()



// Graph
struct Graph
{
	struct Edge
	{
		int a,b,c;
		Edge(int a, int b, int c) : a(a), b(b), c(c) {}
	};
	int size;
	std::vector<Edge> edges;
	Graph(int n) : size(n) {}
};

struct BellmanFord
{
	const int INF = 1e18+7;
	std::vector<int> dist;
	std::vector<int> prev;
	bool closed_negative_loop = false;
	std::vector<int> negative;
	BellmanFord(Graph graph, int s, int t) :
		dist(graph.size, INF),
		prev(graph.size, -1),
		negative(graph.size, false)
	{
		dist[s] = 0;
		for(int i=1; i<=graph.size; i++) {
			for(auto e: graph.edges) {
				if(dist[e.a] + e.c < dist[e.b]) {
					if(i==graph.size) {
						closed_negative_loop = true;
					}
					dist[e.b] = dist[e.a] + e.c;
					prev[e.b] = e.a;
				}
			}
		}
		if(closed_negative_loop) {
			for(int i=1; i<=graph.size; i++) {
				for(auto e: graph.edges) {
					if(dist[e.a] + e.c < dist[e.b]) {
						negative[e.b] = true;
						dist[e.b] = dist[e.a] + e.c;
						prev[e.b] = e.a;
					}
					if(negative[e.a]) negative[e.b] = true;
				}
			}
		}
	}
};



signed main() {
    std::ios_base::sync_with_stdio(0); 
    std::cin.tie(0);
	int n,m;
	std::cin >> n >> m;
	Graph g(n+1);
	rep(i,m) {
		int a,b,c;
		std::cin >> a >> b >> c;
		g.edges.emplace_back(a,b,-c);
	}
	BellmanFord BF(g,1,n);
	if(BF.negative[n]) {
		print("inf");
		return 0;
	}
	print(-BF.dist[n]);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
using namespace std;

int main(){
    int x;
    cin >> x;
    for(int i=0; i < x; i++){
        int value;
        cout << "Case " << i+1 << ":" << endl;
        cin >> value;
        for(int j=0; j < 10; j++){
            value = pow(value, 2);
            value = value/100%10000;
            cout << value << endl;
        }
    }
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
int main(){
	int n; cin>>n;
	while(n--){
		int c = 0,hit = 0,p = 0;
		while(c != 3){
			string s; cin>>s;
			if(s == "HIT"){
				if(hit == 3) p++;
				else hit++;
			} else if(s == "OUT"){
				c++;
			} else {
				p += hit + 1;
				hit = 0;
			}
		}
		cout << p << endl;
	}
    return 0;
}

Measured memory_bytes: 0
s = input()
t = input()
c = 0
c_list = []
for i in range(len(s)-len(t)+1):
    #print(s[i:len(t)+i])
    tmp_s = s[i:len(t)+i]
    for j in range(len(t)):
        if(tmp_s[j] == t[j]):
            c += 1
    c_list.append(c)
    c = 0

print(len(t)-max(c_list))

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

int main()
{
  /*int a, s, d;
  cin >> a >> s >> d ;
   if(a+s==d || a+d==s || s+d==a)
     cout << "Yes" << endl;
     else
       cout << "No" << endl;*/
  string s;
  cin >> s;
  s[5] = ' ';
  s[13] = ' ';
  cout << s << endl;
}  


Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(N-1):
    if(i+1 == p[i]):
        if(p[i+1] != i+1 or i == 0):
            p[i], p[i+1] = p[i+1], p[i]
        else:
            p[i], p[i-1] = p[i-1], p[i]
        cnt += 1
        
if(p[-1] == N):
    p[i], p[i-1] = p[i-1], p[i]
    cnt += 1
    
print(cnt)

Measured memory_bytes: 20536
#include <stdio.h>

int main() {
	int A[1000], n, j,v;
	for (int i = 0; i < 101; i++) {
		A[i] = 0;
	}
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
			scanf("%d", &A[i]);
	}

	for (int k = 0; k < n; k++) {
		if (k < n - 1) {
			printf("%d ", A[k]);
		}
		else {
			printf("%d\n", A[k]);
		}
	}

	for (int i = 1; i < n; i++) {
		v = A[i];
		j = i - 1;
		while (j>=0 && A[j] >v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		for (int k = 0; k < n; k++) {
			if (k < n - 1) {
				printf("%d ", A[k]);
			}
			else {
				printf("%d\n", A[k]);
			}
		}
	}
}


Measured memory_bytes: 2056
#include<iostream>
#include<bitset>

using namespace std;

int main()
{
    bitset<64> bit;
    int q;
    cin>>q;
    while(q--)
    {
        int op,i;
        cin>>op;
        switch(op)
        {
        case 0:
            {
                cin>>i;
                cout<<bit.test(i)<<endl;
            }
            break;
        case 1:
            {
                cin>>i;
                bit.set(i);
            }
            break;
        case 2:
            {
                cin>>i;
                bit.reset(i);
            }
            break;
        case 3:
            {
                cin>>i;
                bit.flip(i);
            }
            break;
        case 4:
            {
                cout<<bit.all()<<endl;
            }
            break;
        case 5:
            {
                cout<<bit.any()<<endl;
            }
            break;
        case 6:
            {
                cout<<bit.none()<<endl;
            }
            break;
        case 7:
            {
                cout<<bit.count()<<endl;
            }
            break;
        case 8:
            {
                cout<<bit.to_ullong()<<endl;
            }
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;
int main(){
	int a,b;
	std::cin >> a>>b;
	std::cout << max(max(a+b,a-b),a*b) << std::endl;
}

Measured memory_bytes: 384
#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)

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<int> b(n);
  vector<int> ans;
  REP(i, n) {
    cin >> b[i];
    b[i]--;
  }
  while (b.size()) {
    bool ok = false;
    RREP(i, b.size()) {
      if (i == b[i]) {
        b.erase(b.begin() + i);
        ans.push_back(i);
        ok = true;
        break;
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return;
    }
  }
  RREP(i, n) {
    cout << ans[i] + 1 << endl;
  }
}

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


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

void Main() {
  int n,m;
  while(cin >> n >> m && n) {
    ll d[n][2];
    mem(d);
    rep(j,m) {
      int s,k;
      cin >> s >> k;
      int a[k];
      rep(i,k) {
        R a[i];
        a[i]--;
      }
      if(k==1) d[a[0]][0]+=s;
      rep(i,k) d[a[i]][1]+=s;
    }
    vector<P> a(n),b(n);
    rep(i,n) {
      a[i]=P(d[i][1],i);
      b[i]=P(d[i][0],i);
    }
    sort(all(a),greater<P>());
    sort(all(b));
    ll ans=0;
    rep(i,2) {
      ll x=a[i].F;
      ll y=b[0].F;
      if(b[0].S==a[i].S) y=b[1].F;
      ans=max(ans,x-y+1);
    }
    pr(ans);
  }
}

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


Measured memory_bytes: 3468
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();

		int[] alpha = new int[26];
		for(int i=0;i<26;i++) {
			alpha[i] = Integer.MAX_VALUE;
		}

		for(int i=0;i<n;i++) {
			String S = sc.nextLine();

			int[] alpha_i = new int[26];
			for(int j = 0;j<S.length();j++) {
				alpha_i[S.charAt(j) - 97]++;
			}

			for(int j=0;j<26;j++) {
				if(alpha_i[j] < alpha[j]) {
					alpha[j] = alpha_i[j];
				}
			}
		}

		String ans ="";
		for(int i=0;i<26;i++) {
			String ansi = "";
			for(int j=0;j<alpha[i];j++) {
				char c = (char) (i + 97);
				ansi = ansi + String.valueOf(c);
			}
			ans = ans + ansi;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
//long long -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define all(aaa) (aaa).begin(),(aaa).end()
#define REP(i,sss,eee) for(long long i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<long long,long long>
#define vi vector<long long>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
long long,
null_type,
less<long long>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
long long solve()
{
	long long n;cin>>n;
	string str;cin>>str;
	std::vector<std::vector<long long>> dp(n,std::vector<long long>(n,0)),pre;
	pre=dp;
	dp[0][0]=1;
	REP(i,0,n-1){pre[0][i]=1;}
	for(long long i=1;i<n;++i)
	{
		char sgn=str[i-1];
		if(sgn=='<')
		{
			REP(j,0,i)
			{
				dp[i][j]=((pre[i-1][n-1]-((j==0)?0:pre[i-1][j-1]))%N);
				dp[i][j]+=N;dp[i][j]%=N;
			}
		}
		else
		{
			REP(j,1,i)
			{
				dp[i][j]=pre[i-1][j-1];
			}
		}
		pre[i][0]=dp[i][0];
		REP(j,1,n-1){pre[i][j]=(dp[i][j]+pre[i][j-1])%N;}
	}
	cout<<pre[n-1][n-1]<<"\n";
}
signed main(){
	speed
	long long tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 141184
#include <iostream>
#include <queue>

using namespace std;
#define MAX 100
int I[MAX];

class TreeNode
{
public:
	int data;
	TreeNode* pLeftChild;
	TreeNode* pRightChild;
};

class BinaryTree
{
public:
	BinaryTree(TreeNode* pRoot, int n) : m_pRoot(pRoot), m_n(n) {}
	void PostOrder()
	{
		m_count = 0;
		PostOrder(m_pRoot);
	}

private:
	void PostOrder(TreeNode* currentNode)
	{
		if (!currentNode) return;

		PostOrder(currentNode->pLeftChild);
		PostOrder(currentNode->pRightChild);
		++m_count;
		cout << currentNode->data << (m_count != m_n ? " ": "\n");
	}

private:
	TreeNode* m_pRoot;
	int m_n;
	int m_count;
};

TreeNode* RebuildTree(queue<int> &P, int *i, int l, int r)
{
	if (l == r) return 0;

	int v = P.front();
	P.pop();
	TreeNode* node = new TreeNode();
	node->data = v;
	int f = -1;
	for (int j = l; j < r; ++j)
	{
		if (v == i[j])
		{
			f = j;
			break;
		}
	}
	node->pLeftChild = RebuildTree(P, i, l, f);
	node->pRightChild = RebuildTree(P, i, f + 1, r);

	return node;
}

int main()
{
	int n; cin >> n;
	queue<int> P;
	int v;
	for (int i = 0; i < n; ++i)
	{
		cin >> v;
		P.push(v);
	}
	for (int i = 0; i < n; ++i) cin >> I[i];
	TreeNode* pRoot = RebuildTree(P, I, 0, n);
	BinaryTree tree(pRoot, n);
	tree.PostOrder();

	return 0;
}


Measured memory_bytes: 3092
# -*- coding: utf-8 -*-
import numpy as np

w, h, n = map(int, input().split())

NN = [[1] * h for _ in range(w)]

def g(a, x1, x2, y1, y2):
    for i in range(x1,x2):
        for j in range(y1,y2):
            a[i][j] = 0
    return a
            
        
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        NN = g(NN,0,x,0,h)
    elif a == 2:
        NN = g(NN,x,w,0,h)
    elif a == 3:
        NN = g(NN,0,w,0,y)
    elif a == 4:
         NN = g(NN,0,w,y,h)

np.array(NN)
print(np.sum(NN))

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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    vector<int> ans(N, 0);

    int r = 0;
    rep(i, N) {
        if (S[i] == 'R') {
            r += 1;
        }
        else if (S[i] == 'L' && r >= 1) {
            ans[i] += r / 2;
            ans[i - 1] += r / 2;
            if (r % 2 == 1) {
                ans[i - 1]++;
            }
            r = 0;
        }
    }

    int l = 0;
    for (int i = N - 1; i >= 0; i--) {
        if (S[i] == 'L') {
            l += 1;
        }
        else if (S[i] == 'R' && l >= 1) {
            ans[i] += l / 2;
            ans[i + 1] += l / 2;
            if (l % 2 == 1) {
                ans[i + 1]++;
            }
            l = 0;
        }
    }
    rep(i, N) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <set>

using namespace std;

int main(){
    int n;
    cin>>n;
    set<char> st;
    for(int i=0;i<n;++i){
        char c;
        cin>>c;

        st.insert(c);
    }
    if(st.size()==3)cout<<"Three"<<endl;
    else cout<<"Four"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>

using namespace std;
#define EPS 1e-9
#define MAX 505
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define pi acos(-1.0)
#define mod 100000007
#define inf 2147483647
#define ll long long int
#define sss stringstream
#define oss ostringstream
#define iss istringstream
#define llu long long unsigned

#define _sq(a) (a)*(a)
#define sz(a) ((int)a.size())
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define _max3(a,b,c) max(a, max(b,c))
#define _min3(a,b,c) min(a, min(b,c))
#define FOR(i, n) for(i=0; i<(int)n; i++)
#define FOR1(i, n) for(i=1; i<=(int)n; i++)
#define mem(a) memset(a, 0, sizeof(a))
#define _set(a) memset(a,-1,sizeof(a))
#define FORI(i, a, b) for(i=a; i>=(int)b; i--)
#define FORab(i, a, b) for(i=a; i<=(int)b; i++)
#define popcount(n) __builtin_popcount(n)
#define popcountl(n) __builtin_popcountll(n)
#define sort_rev(a) sort(a.rbegin(), a.rend())
#define sort_all(a) sort(a.begin(), a.end())
#define dis_twopoints(x1,y1,x2,y2) sqrt(_sq(x1-x2) + _sq(y1-y2))
#define foreach(i,n) for(__typeof((n).begin())i =(n).begin();i!=(n).end();i++)

//If Long Long (mask & (1LL << k))
#define check(mask, k) (mask & (1 << k))
#define set1(mask, k) (mask | (1 << k))
#define set0(mask ,k) (mask & (~(1<<k)))

#define SD(a) scanf("%d",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)
#define SLLD(a) scanf("%lld", &a)
#define Si64(a) scanf("%I64d", &a)

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
int f[60];
int main()
{
    int i,hi[11];
    for(i=0;i<10;i++)
    {
        cin>>hi[i];
    }
    sort(hi,hi+10);
    cout<<hi[9]<<endl<<hi[8]<<endl<<hi[7]<<endl;

    return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = (ll)1e9 + 7;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}

const int N = (int)1e6 + 7;
ll S;
int n, m, d;
ll dp[N];
ll pref[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d%d", &m, &n, &d);
	ll F = 1;
	for (int i = 1; i <= m; i++) {
		F = mult(F, i);
		S = add(S, F);
	}
	//cerr << S << endl;
	dp[0] = F;
	pref[1] = F;
	for (int i = 1; i <= n; i++) {
		dp[i] = sub(pref[i], pref[max(0, i - d)]);
		//cerr << dp[i] << " ";
		pref[i + 1] = add(pref[i], mult(S, dp[i]));
	}
	printf("%lld\n", dp[n]);

	return 0;
}


Measured memory_bytes: 15872
fun main (args : Array<String>) {
	val (t, n, l) = readLine()!!.split(" ").map(String::toInt)
	var time : Int = t.toInt()
	var num : Int = n.toInt()
	var limit : Int = l.toInt()
	val timeLimit : Double = (limit + 0.5) / time
	var count : Int = 0
	for (i in 0..timeLimit.toInt()) {
		count++
	}
	println("${num * (count - 1)}")
}

Measured memory_bytes: 38116
import itertools
import math
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

# 順列のリスト
pmt = list(itertools.permutations(range(1, N + 1), N))

a = 0
b = 0

for i in range(len(pmt)):
    if pmt[i] == P:
        a = i + 1
    if pmt[i] == Q:
        b = i + 1
print(abs(a - b))


Measured memory_bytes: 13788
# input
N, K = map(int, input().split())
a = list(map(int, input().split()))

# dp
dp = ["W"] * (K + 1)

for i in range(K):
  if dp[K - i] == "W":
    for j in range(N):
      if K - i - a[j] < 0:
        continue
      dp[K - i - a[j]] = "L"

if dp[0] == "W":
  print("Second")
else:
  print("First")



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


#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

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

template <class T> inline T biton(T n, T pos)
{
    return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
    return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
    return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
    while (b)
    {
        a = a%b;
        swap(a, b);
    }
    return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
};

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif


void solve()
{
    int n;
    cin>>n;

    vector<int> a(n+1),b(n+1),c(n);

    a[0]=100;

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

    for(int i=1; i<=n; i++)
    {
        cin>>b[i];
    }


    for(int i=1; i<n; i++)
    {
        cin>>c[i];
    }

    long long sum=0;

    for(int i=1;i<=n;i++){

        sum=sum+b[a[i]];

        if(a[i-1]+1==a[i]){
            sum+=c[a[i-1]];
        }


    }

    cout<<sum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;
    while (t--)
    {
        solve();
    }


    return 0;
}


Measured memory_bytes: 256
N=int(input())
L=[int(i) for i in input().split()]

count=0
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if (L[i]!=L[j])&(L[i]!=L[k])&(L[j]!=L[k]):
                if (L[i]+L[j]>L[k])&(L[i]+L[k]>L[j])&(L[j]+L[k]>L[i]):
                    count+=1
print(count)

Measured memory_bytes: 9204
#include<stdio.h>
#include<string.h>

int main(void) {
  char S[200001];
  scanf("%s", S);
  
  int lp = 0;
  for(lp = 0; S[lp] != '\0'; lp++) {
    if(S[lp] == 'A') break;
  }

  int rp = strlen(S);
  for(; rp > lp; rp--) {
    if(S[rp] == 'Z') break;
  }
  printf("%d\n", rp-lp+1);
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int t = 1;
	// cin >> t;

	while (t--) {
		int ans = 0;
		char p;
		while (cin >> p) {
			ans += p - 48;
		}
		cout << (ans % 9 == 0 ? "Yes" : "No") << endl;
	}
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    cout << N*800 - 200*(N/15) << endl;
    return 0;
}

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

if n == 0:
    print(x)
    quit()
    
min_ = float('Inf')
ans = 0
for i in range(-1, 110):
    if i in p:
        continue
    #print(i)
    diff = abs(x - i)
    if diff < min_:
        min_ = diff
        ans = i
print(ans)

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

int main(void){
int N;
scanf("%d",&N);
int i=0;
int s[100];
int max=0;
for(i=0;i<N;i++){
 scanf("%d",&s[i]);
 max+=s[i];
}

if(max%10){
printf("%d\n",max);
return 0;
}
else{
 int j,judge=0;
 for(i=0;i<N;i++){
 judge=0;
  if(s[i]%10){
 for(j=0;j<N;j++)
  if(s[j]%10!=0&&s[j]<s[i])
   judge=1;
  if(judge==0){
  max-=s[i];
  printf("%d\n",max);
  return 0;
  }
  }
 }
 }
 printf("0\n");
 return 0;
}

Measured memory_bytes: 128
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 10000 + 10;

ll cnt[N];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, p;
    string s;
    cin >> n >> p >> s;
    ll ans = 0;
    if (p == 2 || p == 5){
        for (ll i = 0; i < n; i ++)
            if ((s[i] - '0') % p == 0)
                ans += i + 1;
        return cout << ans, 0;
    }
    cnt[0] = 1;
    ll cur = 0, pw = 1;
    for (ll i = n - 1; i >= 0; i --){
        cur = (cur + (s[i] - '0') * pw) % p;
        ans += cnt[cur];
        cnt[cur] ++;
        pw = pw * 10 % p;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3732
N = int(input())
UVW = [list(map(int, input().split())) for _ in range(N - 1)]

rel = {x:{} for x in range(1, N + 1)}
for u, v, w in UVW:
	rel[u][v] = w
	rel[v][u] = w

visited = [-1] * (N + 1)
visited[1] = 0

#print(rel)

route = [x for x in range(N, 0, -1)]
while route:
	#print(route)
	current = route.pop()
	for k, v in rel[current].items():
		if -1 == visited[k]:
			route += [k]
		if not v % 2:
			visited[k] = visited[current]
		else:
			visited[k] = (visited[current] + 1) % 2
	#print(visited)

for node in visited[1:]:
	print(node)


Measured memory_bytes: 74620
#include <stdio.h>
#include <math.h> /*  コンパイル時にオプション -lm  */
int isPrime(int);

int main(){

  int i,n,x[10000],count=0;
  scanf("%d",&n);

  for(i=0;i<n;i++){
      scanf("%d",&x[i]);

  }
  for(i=0;i<n;i++){
    if(isPrime(x[i])==1){
      count++;
    }
  }
  

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

  
}


int isPrime(int x){
  int i;

  if(x==2){
    return 1;
}
  if(x<2 || x%2==0){
    return 0;
    }
  i=3;
  while( i<=sqrt(x)){
    if(x%i==0){
      return 0;
	}
    i=i+2;


  }
  return 1;
}



Measured memory_bytes: 2724
#include "bits/stdc++.h"
using namespace std;
 
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
 
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
 
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
 
#define pb(a) push_back(a)
 
int n,m;
vector<int> ki(100000);
vector<int> kz(100000,1);
vector<int> kidmy(100000);
 
int root(int w){
  int ww=w;
  int lfg=0;
  REP(ii,100000){ 
    if (ki[ww]==ww){
      break;
    }else{
     kidmy[lfg]=ww;
     lfg++;
     ww=ki[ww];
    }
  }
  
  REP(ii,lfg){
    ki[kidmy[ii]]=ww;
  }
  
  //if (kz[ww]<lfg)kz[ww]=lfg;
  
  return ww;
}
  
 
int main(){
  int ans=0;
  cin >> n >> m;
 
  vector<int> x(m),y(m),z(m);
  REP(i,m) cin>>x[i]>>y[i]>>z[i];
  REP(i,100000)ki[i]=i;
  REP(i,m){//結合させていく
    int pidx=root(x[i]-1);
    int pidy=root(y[i]-1);
    if (pidx!=pidy){
      if (kz[pidy]>kz[pidx]){
        ki[pidx]=pidy;
        kz[pidy]+=kz[pidx];
      }else{
        ki[pidy]=pidx;
        kz[pidx]+=kz[pidy];
      }
    }
  }
  
  
  REP(i,n){
   if (ki[i]==i)ans++;
  }
 
 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2560
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

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

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

    int n, a, b;
    cin >> n >> a >> b;

    cout << min(n * a, b) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 int main(){
   int n;
   cin>>n;
   vector<int>a(n);
   for(int i=0;i<n;i++){
     cin>>a[i];
   }
   vector<int>b(n);
   for(int i=0;i<n;i++){
     b[a[i]-1]=i+1;
   }

   for(int i=0;i<n-1;i++){
     cout<<b[i]<<" ";
   }
   cout<<b[n-1]<<endl;
 }

Measured memory_bytes: 1664
#include <stdio.h>
#include <algorithm>
int n;
long long a, b;
long long x[200000];
long long y[200000];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &a, &b);
		x[i] = a + b;
		y[i] = a - b;
	}
	std::sort(x, x + n);
	std::sort(y, y + n);
	a = x[n - 1] - x[0];
	b = y[n - 1] - y[0];
	if (a < b)a = b;
	printf("%lld\n", a);
}

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

int main(){
  char c;
  cin >> c;
  if( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
  cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
int dp[1111111],su[1111111];

signed main(){
  int n;
  cin>>n;
  dp[0]=1;dp[1]=n;
  su[0]=1;su[1]=n+1;
  for(int i=2;i<=n;i++){
    dp[i]=(dp[i-1]+(i>=3?su[i-3]:0LL)+(n-1)*(n-1)+(n-i+1))%MOD;
    su[i]=(su[i-1]+dp[i])%MOD;
    //cout<<dp[i]<<endl;
  }
  cout<<dp[n]<<endl;
  return 0;
}


Measured memory_bytes: 16768
#include <bits/stdc++.h>
#define ll long long
#define ii pair < ll , ll >
#define fi first
#define se second

using namespace std;
const int N=1e5+55;
vector < ll > vec[N];
vector < ii > down[N];
vector < ll > pre[N];
vector < ll > suf[N];
vector < ll > suf2[N];
ll up[N];
ll ans[N];
ll m;


void dfs(ll u , ll p)
{
    ans[u]=1;
    for(auto v:vec[u])
    {
        if(v==p)
            continue ;
        dfs(v,u);
        ans[u]*=1+ans[v];
        down[u].push_back({ans[v],v});
        ans[u]%=m;
    }
    ans[u]%=m;
    ll n=down[u].size();
    if(!n)
        return ;
    ll x=1;
    x*=1+down[u][0].fi;
    pre[u].push_back(x);
    for(ll i=1;i<n;i++)
    {
        x*=down[u][i].fi+1;
        x%=m;
        pre[u].push_back(x);
    }
    x=1;
    ll y=1;
    x*=down[u][n-1].fi+1;
    x%=m;
    suf[u].push_back(x);
    suf2[u].push_back(1);
    for(ll i=n-2;i>=0;i--)
    {
        x*=1+down[u][i].fi;
        y*=1+down[u][i].fi;
        y%=m;
        x%=m;
        suf[u].push_back(x);
        suf2[u].push_back(y);
    }
    reverse(suf[u].begin(),suf[u].end());
    reverse(suf2[u].begin(),suf2[u].end());

}


void dfs1(ll u , ll parent)
{
    ll n=down[u].size();
    for(ll i=0;i<n;i++)
    {
        ll v=down[u][i].se;
        ll x=1;
        if(i!=0)
            x*=pre[u][i-1];
//        cout<<v<<' '<<x<<endl;
        x%=m;
        if(i!=n-1)
        {
//            if(v==3)
//            {
//                cout<<"   "<<x<<' '<<suf2[u][i+1]<<' '<<down[u][n-1].fi<<endl;
//                for(auto K:suf2[u])
//                    cout<<K<<' ';
//                cout<<endl;
//            }
            if(x>1)
                x*=(suf2[u][i+1]%m)*(down[u][n-1].fi+1%m)%m;
            else
                x*=suf[u][i+1];
        }
//        cout<<v<<' '<<x<<endl;
        x%=m;
        if(u!=1)
            x*=up[u]+1;
//        cout<<v<<' '<<x<<endl;
        x%=m;
        up[v]=x;
        ans[v]*=x+1;
        ans[v]%=m;
    }
    for(auto v:vec[u])
    {
        if(v!=parent)
            dfs1(v,u);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    ll n;
    cin>>n>>m;
    ll u,v;
    for(ll i=0;i<n-1;i++)
    {
        cin>>u>>v;
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    dfs(1,0);
    dfs1(1,0);
    for(ll i=0;i<n;i++)
        cout<<ans[i+1]%m<<endl;
    return 0;
}
/*
5 1000
1 2
2 3
2 4
3 5
*/
/*
6 1000
1 2
1 3
1 4
1 5
1 6
*/
/*
10
1000
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
5 10
*/


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

int main() {
  int N;
  cin>>N;
  string s;
  cin>>s;
  int ans =1;
  char  c=s[0];
  for(int i=0;i<N;i++){
    if(s[i]!=c){
      ans++;
      c=s[i];
    }
  }
cout<<ans<<endl;
  }


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{
    int L, R, d;
    cin >> L >> R >> d;
    int res = 0;
    for(int i = L; i <= R; ++i)
    {
        if(i % d == 0)
        {
            res++;
        }
    }
    cout << res << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  n %= 10;
  if(n==2 || n==4 || n==5 || n==7 || n==9) cout << "hon" << newl;
  else if(n==0 || n==1 || n==6 || n==8) cout << "pon" << newl;
  else if(n==3) cout << "bon" << newl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
const int maxn = 60, mod = 1'000'000'007;
int mul(long long a, long long b){
	return a * b % mod;
}
int cnt[maxn];
int main(){
	int n; cin >> n;
	int ans = 0;
	for(int j = 0; j < n; j++){
		long long x; cin >> x;
		for(int i = 0; i < maxn; i++){
			if((x>>i)&1){
				ans += mul((1ll<<i)%mod, j - cnt[i]);			
			} else {
				ans += mul((1ll<<i)%mod, cnt[i]);
			}
			if(ans >= mod) ans -= mod;
		}
		for(int i = 0; i < maxn; i++){
			cnt[i] += ((x>>i)&1);
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for(int x = 0; x <= k; x++) {
    for(int y = 0; y <= k; y++) {
      if(s - x - y >= 0 && s - x - y <= k) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first 
#define S second
int const M=1e5+10,M2=1e6+10,M3=1e3+10,inf=1e9+10,mod=1e9+7;
int a[M];
map<int,int>cnt;
main()
{	
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],cnt[a[i]]++;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(cnt[a[i]]>=a[i])ans+=cnt[a[i]]-a[i];
		else ans+=cnt[a[i]];
		cnt[a[i]]=0;
	}
	cout<<ans;
}

Measured memory_bytes: 7040
#include <iostream>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>

using namespace std;
void tbd(){

    string s; cin >> s;
    int month = stoi( s.substr(5,2) );
    int day = stoi( s.substr(8,2) );
    if (month >= 5){
        cout << "TBD" << endl;
    }else{
        cout << "Heisei" << endl;
    }

}

void gift(){
    int N; cin >> N;
    double bit_sum = 0.0;
    int jpy_sum = 0;

    for(int i= 0; i < N; i++){
        string x_i,u_i; cin >> x_i >> u_i;

        if( u_i == "JPY"){
            jpy_sum += stoi(x_i);
        }else if( u_i == "BTC"){
            bit_sum += stod(x_i);
        }
    }

    double ans;
    ans = 380000.0 * bit_sum + static_cast<double>(jpy_sum);

    cout << ans;



}

template<typename T>
pair<T, T> find(T x, const vector<T>& vec, int st, int ed){

    if(x < vec[st])
        return {-1,0};
    if( vec[ed] < x)
        return {ed, -1};

    while(ed - st > 1){

        int mid = (ed + st)/2;
        if(vec[mid] > x ){
            ed = mid;
        }else{
            st = mid;
        }
    }

    return {st, ed};

}


long long find_min(long long x, const vector<long long>& s_vec, const vector<long long>& t_vec, int A, int B){
    auto s_pair = find(x, s_vec, 0, A-1);
    auto t_pair = find(x, t_vec, 0, B-1);

    long long ss[2] = {s_pair.first, s_pair.second};
    long long tt[2] = {t_pair.first, t_pair.second};

    long long ans = numeric_limits<long long>::max();

    for(int i = 0; i<2; i++) {
        if (ss[i] == -1 )
            continue;
        for (int j = 0; j < 2; j++) {
            if (tt[j] == -1)
                continue;
            long long to_s = abs(x - s_vec[ss[i]]);
            long long to_t = abs(x - t_vec[tt[j]]);

            if (i == j) {//同じ方角
                long long dist = max(to_s, to_t);
                ans = (ans < dist) ? ans : dist;
            } else {
                long long dist;
                if (to_s > to_t){
                    dist = 2 * to_t + to_s;
                } else {
                    dist = 2 * to_s + to_t;
                }
                ans = (ans < dist) ? ans : dist;
            }


        }
    }

    return ans;

}

void lazy(){

    int A,B,Q; cin >> A >> B >> Q;
    vector<long long> s_vec(A);
    vector<long long> t_vec(B);
    vector<long long> x_vec(Q);
    for(int i = 0; i < A; i++){
        cin >> s_vec[i];
    }
    for(int i = 0; i < B; i++){
        cin >> t_vec[i];
    }
    for(int i = 0; i < Q; i++){
        cin >> x_vec[i];
    }

    sort(s_vec.begin(), s_vec.end() );
    sort(t_vec.begin(), t_vec.end() );
    for(int i = 0; i < Q; i++){
        cout << find_min(x_vec[i], s_vec, t_vec, A, B) << endl;
    }
}

int main(){

    lazy();
    return 0;
}

Measured memory_bytes: 3712
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int x= 0;
    int N = scan.nextInt();
    int M = scan.nextInt();
    int souhyou = 0;
    int syouhin[] = new int[N];
    for(int i = 0;i<N;i++){
      syouhin[i] = scan.nextInt();
      souhyou += syouhin[i];
    }
    double zyouken = 0;
    zyouken = (double)souhyou/(4*M);
//System.out.println(zyouken);
    for(int i = 0;i < N;i++){
      if(syouhin[i] >= zyouken){
        x++;
      }
    }
    if(x >= M){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23764