akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

struct st {
	int a, b, c;
};
bool operator<(st a, st b) { return a.c < b.c; }
int par[1000];
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		vector<st>v;
		rep(i, m) {
			int s, t, c; scanf("%d%d%d", &s, &t, &c); s--; t--;
			v.push_back({ s,t,c });
		}
		iota(par, par + n, 0);
		sort(v.begin(), v.end());
		int t = 0;
		for (st&s : v) {
			int x = find(s.a), y = find(s.b);
			if (x == y)continue;
			par[x] = y;
			if (++t == n / 2) {
				printf("%d\n", s.c); break;
			}
		}
	}
}

Measured memory_bytes: 3360
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define int long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

template <typename F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) noexcept : F(std::forward<F>(f)) {}
    template <typename... Args>
    constexpr decltype(auto)
    operator()(Args &&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

template <typename F>
static inline constexpr decltype(auto)
make_func(F &&f) noexcept {
    return FixPoint<F>{std::forward<F>(f)};
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    vector<vector<int>> g(n);
    rep(i, m) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    int ans = 0;
    rep(i, n) {
        bool ok = true;
        each(nv, g[i]) {
            if (h[i] <= h[nv]) ok = false;
        }
        if (ok) ans += 1;
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}


Measured memory_bytes: 9800
from bisect import bisect_left


def solve(string):
    a, b, q, *stx = map(int, string.split())
    s = [-10**10] + stx[:a] + [2 * 10**10]
    t = [-10**10] + stx[a:a + b] + [2 * 10**10]
    # x = dict([])
    ans = []
    i_s = 0
    i_t = 0
    for _x in stx[-q:]:
        """
        while s[i_s] < _x:
            i_s += 1
        while t[i_t] < _x:
            i_t += 1
        """
        i_s, i_t = bisect_left(s, _x), bisect_left(t, _x)
        ls, rs = s[i_s - 1], s[i_s]
        lt, rt = t[i_t - 1], t[i_t]
        r_max = max(rs, rt)
        l_min = min(ls, lt)
        """
        x[_x] = min([
            r_max - _x, _x - l_min, rt - ls + min(rt - _x, _x - ls),
            rs - lt + min(rs - _x, _x - lt)
        ])
        """
        ans.append(
            str(
                min([
                    r_max - _x, _x - l_min, rt - ls + min(rt - _x, _x - ls),
                    rs - lt + min(rs - _x, _x - lt)
                ])))
    # return "\n".join([str(x[_x]) for _x in stx[-q:]])
    return "\n".join(ans)


if __name__ == '__main__':
    n, m, l = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, l) + '\n'.join([input() for _ in range(n + m + l)])))


Measured memory_bytes: 39524
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
#include <string.h>
#include <set>
#include <bitset>
using namespace std;

#define N 81
#define M 2*N*N*2

bitset<M> dp[N][N];

int x[N][N];
void solve() {
  int h,w;scanf("%d %d ",&h,&w);
  int ZERO = N*N*2;
  for(int i=1;i<=h;++i) {
    for(int j=1;j<=w;++j) {
      scanf("%d ", &x[i][j]);
    }
  }
  for(int i=1;i<=h;++i) {
    for(int j=1;j<=w;++j) {
      int u;
      scanf("%d ", &u);
      x[i][j] -= u;
      x[i][j] = abs(x[i][j]);
    }
  }
  dp[1][1][ZERO] = 1;

  for(int i=1;i<=h;++i) {
    for(int j=1;j<=w;++j) {
      dp[i][j] = (dp[i][j]<<x[i][j]) | (dp[i][j]>>x[i][j]);
      if(i+1<=h) {
        dp[i+1][j] |= dp[i][j];
      }
      if(j+1<=w) {
        dp[i][j+1] |= dp[i][j];
      }
    }
  }
  for(int i=0;;++i) {
    if(dp[h][w][ZERO-i] || dp[h][w][ZERO+i]) {
      printf("%d\n", i);
      return;
    }
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 21120
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


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


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };
int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/
typedef tuple<int,int,int> tpl;

int main() {

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

    int a,b,c;
    cin >> a >> b >> c;
    swap(a,b);
    swap(a,c);
    cout << a << " " << b << " " << c << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("02")
#define ll long long
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
struct ios{
    inline char gc(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> _inline ios & operator >> (_Tp &x){
        static char ch,sgn; ch=gc(),sgn=0;
        for(;!isdigit(ch);ch=gc()){if(ch==-1)return *this;sgn|=ch=='-';}
        for(x=0;isdigit(ch);ch=gc())x=x*10+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}inc;
int fa[100005];
int findset(int x){
	return fa[x]=(fa[x]==x)?x:findset(fa[x]);
}
void Union(int x,int y){
	fa[findset(x)]=findset(y);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) fa[i]=i;
	int x,y,z;
	for(int i=1;i<=m;i++) cin>>x>>y>>z,Union(x,y);
	int cnt=0;
	for(int i=1;i<=n;i++) if(fa[i]==i) cnt++;
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
using namespace std;
long long max(long long x,long long y,long long z)
{
    if(z>y&&z>x)
    {
        return z;
    }
    else if(y>=z&&y>x)
    {
        return y;
    }
    else return x;
}
int main()
{
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    cout<<a+b+c+max(a,b,c)*(pow(2,k)-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, P;
    cin >> N >> P;
    int ans = 1;
    if(N == 1) {cout << P << endl; return 0;}
    REP(i, 2, 1000000) {
        int num = P;
        int cnt = 0;
        while(num % i == 0) {
            num /= i;
            cnt++;
        }
        if(cnt >= N) ans = i;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3588
// C++ 14
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>

#define ll int
#define loop(x, start, end) for(ll x = start; x < end; x++)

using namespace std;


inline bool search(vector<ll> v, ll target) {
    if (target < v[0] || v[v.size()-1] < target) return false;
    
    ll left = 0, right = v.size(), mid;
    while (left < right) {
        mid = (left + right) / 2;
        if (v[mid] == target) return true;
        else if (v[mid] < target) left = mid+1;
        else right = mid;
    }
    
    return false;
}
 
int main(void) {
    ll n, q, x;
    vector<ll> vs, vt;
    
    cin >> n;
    ll i = 0;
    loop(i, 0, n) {
        cin >> x;
        vs.push_back(x);
    }
    
    cin >> q;
    
    ll count = 0;
    loop(i, 0, q) {
        cin >> x;
        if (search(vs, x)) count++;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define PB push_back
#define LL long long
using namespace std;
vector<int> permut;
int brute(vector<int> values)
{
    int n = values.size();
    vector<int> permut;
    for(int i = 0; i < n; i++)
        permut.PB(i);
    int ans = 0;
    do
    {
        int curAns = 0;
        for(int i = 0; i < permut.size() - 1; i++)
        {
            curAns += abs(values[permut[i]]  - values[permut[i + 1]]);
        }
        if(curAns > ans)
        {
            ans = curAns;
        }
    }
    while(next_permutation(permut.begin() , permut.end()));
    return ans;
}
LL solve(vector<int> values)
{
    int n = values.size();
    sort(values.begin() , values.end());
    vector<int> fin(values.size());
    int idx = (n - 1) / 2;
    int cnt = (n + 1) / 2;
    int from = 0;
    while(cnt--)
    {
        fin[from] = values[idx];
        idx--;
        from += 2;
    }
    cnt = n / 2;
    idx = n - 1;
    from = 1;
    while(cnt--)
    {
        fin[from] = values[idx];
        idx--;
        from += 2;
    }
    if(n > 1 && n % 2)
    {
        swap(fin[2] , fin[n - 1]);
    }
    LL ans = 0;
    for(int i = 0; i < fin.size() - 1; i++)
        ans += abs(fin[i] - fin[i + 1]);
    return ans;
}
vector<int> gen()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto &x : v)
    {
        cin >> x;
    }
    return v;
}

int main() 
{
    
        vector<int> v = gen();
        vector<int> minusV;
        for(auto x : v)
            minusV.PB(-x);
        cout << max(solve(v) , solve(minusV));
       
       // cout << "OK" << endl;
    
    return 0;
}

Measured memory_bytes: 2160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s, t, ans;
		s = sc.next();
		t = sc.next();
		sc.close();
		int n = t.length();
		int n2 = s.length();
		int bm[] = new int[27];
		for (int i = 0; i < 27; ++i) {
			bm[i] = n;
		}

		for (int i = 0; i < n; ++i) {
			int tmp = (int) (t.charAt(i) - 'a');
			bm[tmp] = n - i - 1;
		}

		ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
		int i = n - 1, j = i;
		int count = 0;
		//System.out.println(n2);
		while (i < n2) {
			while (i < n2 && j >= 0) {
				if (s.charAt(i) != t.charAt(j) && s.charAt(i) != '?') {
					int tmp = (int) (s.charAt(i) - 'a');
					if (bm[tmp] <= n - j) {
						i += n - j;
						j = n - 1;
					} else {
						i += bm[tmp];
						j = n - 1;
					}
				} else {
					i--;
					j--;
				}
			}
			if (j < 0) {
				StringBuffer tmp = new StringBuffer();
				//System.out.println(tmp + ">>" + i);
				for (int k = 0; k < i + 1; ++k)
					tmp.append(s.charAt(k));
				for (int k = 0; k < n; ++k)
					tmp.append(t.charAt(k));
				for (int k = n + i + 1; k < n2; ++k)
					tmp.append(s.charAt(k));
				String tmp2 = tmp.toString();
				tmp2 = tmp2.replace('?', 'a');
				//System.out.println(tmp2);
				if (ans.compareTo(tmp2) > 0)
					ans = tmp2;
				j = n - 1;
				i += n + 1;
				//System.out.println(i);
				++count;
			}
			else {
				++j;
				++i;
			}
		}
		if (count <= 0)
			System.out.println("UNRESTORABLE");

		else
			System.out.println(ans);
	}

}


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

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        if(dist[i][j]!=-1 && dist[i][k]!=-1 && dist[k][j]!=-1){
          dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
        }
      }
    }
  }
  return;
}

int main(){
  int H, W;
  char S[20][20];
  cin >> H >> W;
  int n = H*W;
  vector<vector<int> > dist(n, vector<int>(n,10000));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> S[i][j];
    }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      int idx = i*W+j;
      if(S[i][j]=='#'){
        for(int k=0; k<n; k++){
            dist[idx][k]=-1;
            dist[k][idx]=-1;
        }
      }else{
        dist[idx][idx]=0;
        if(j+1<W && S[i][j+1]=='.'){
          dist[idx][idx+1]=1;
          dist[idx+1][idx]=1;
        }
        if(i+1<H && S[i+1][j]=='.'){
        dist[idx][idx+W]=1;
        dist[idx+W][idx]=1;
        }
      }
    }
  }
  warfl(dist, n);
  int ans =0;
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
        ans = max(ans, dist[i][j]);
    }
  }
  if(ans==10000) ans=0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 896
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))

maximum=0

for i in range(n)[::-1]:
    for j in range(2)[::-1]:
        alpha=min(a[i+j],b[i])
        a[i+j]-=alpha
        b[i]-=alpha
        maximum+=alpha
print(maximum)



Measured memory_bytes: 18624
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#include <cassert>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;
#define int ll

signed main() {
	int ans = 0;
	int N, X, M; cin >> N >> X >> M;
	if (X == 0 && M == 1) {
		cout << 0 << endl; return 0;
	}
	vector<int> ordVisit(M, -1);
	int val = X;
	int Lcycle = -1;
	int Sumcycle = 0;
	int Startcycle = -1;
	//Aの値で既出があればおしまい
	// ordvistのvaluesは1-indexed
	for (int i = 1; i < M+1; i++) {
		//とりあえずループ探し
		if (ordVisit[val] > 0) {
			Startcycle = val;
			Lcycle = i - ordVisit[val];
			break;
		}
		ordVisit[val] = i;
		val *= val; val %= M;
	}
	int ind = Startcycle;
	for (int p = 0; p < Lcycle;p++) {
		Sumcycle += ind;
		ind *= ind; ind %= M;
	}
		
	// [X,loopind)の数を数える
	int Dfirst= 0;
	int tmp = X;
	while (tmp != Startcycle) {
		Dfirst++;
		ans += tmp;
		tmp *= tmp; tmp %= M;
	}

	int rem = N - Dfirst;
	int Tloop = rem / Lcycle;
	int Dsecond = rem % Lcycle;

	ans += Tloop * Sumcycle;

	int tmpp = Startcycle;

	for (int i = 0; i < Dsecond; i++) {
		ans += tmpp;
		tmpp *= tmpp; tmpp %= M;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3996
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;



int main(){
    ll x, y;
    cin >> x >> y;
    ll Count=0;
    if(x == 1) Count+= 300000;
    else if(x == 2) Count+= 200000;
    else if(x==3) Count+=100000;
    if(y == 1) Count+= 300000;
    else if(y == 2) Count+= 200000;
    else if(y==3) Count+=100000;
    if(x==1 && y == 1) Count+=400000;
    cout << Count;
}

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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
    ifstream t("/proc/self/status");
    cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum = 0, fg = 1;
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MOD = (int) 1e9 + 7;
const int MAXN = (int) 2e5;

int n;

vector<int> adj[MAXN + 5];

int fa[MAXN + 5];

inline void input()
{
	n = read<int>() + 1;
	for(int i = 2; i <= n; ++i)
	{
		fa[i] = read<int>() + 1;
		adj[fa[i]].push_back(i);
	}
}

int dep[MAXN + 5], max_dep[MAXN + 5], son[MAXN + 5], cnt[MAXN + 5];

inline void dfs(int u)
{
	++cnt[dep[u]];
	son[u] = 0;
	max_dep[u] = dep[u];
	for(auto v : adj[u])
	{
		dep[v] = dep[u] + 1;
		dfs(v);
//		printf("& %d %d | %d %d\n", u, v, dep[u], dep[v]);
		if(max_dep[v] >= max_dep[son[u]]) son[u] = v;
		chkmax(max_dep[u], max_dep[v]);
	}
}

int root[MAXN + 5];
vector<int> f[MAXN + 5][3];

inline void DP(int u)
{
	if(!son[u])
	{
		f[u][0].push_back(1);
		f[u][1].push_back(1);
		f[u][2].push_back(0);
		root[u] = u;
		return;
	}

	for(auto v : adj[u]) DP(v);

	root[u] = root[son[u]];
	f[root[u]][0].push_back(1);
	f[root[u]][1].push_back(1);
	f[root[u]][2].push_back(0);
	for(auto v : adj[u]) if(v != son[u])
		for(int j = 1; j <= dep[v]; ++j)
		{
			static int res[3];
			res[0] = res[1] = res[2] = 0;

			for(int p0 = 0; p0 < 3; ++p0) for(int p1 = 0; p1 < 2; ++p1)
				(res[p0 + p1 >= 2 ? 2 : p0 + p1] += (LL) f[root[u]][p0][dep[u] - j - 1] * f[root[v]][p1][dep[v] - j] % MOD) %= MOD;
			f[root[u]][0][dep[u] - j - 1] = res[0];
			f[root[u]][1][dep[u] - j - 1] = res[1];
			f[root[u]][2][dep[u] - j - 1] = res[2];
		}

	int snd_dep = 0;
	for(auto v : adj[u]) if(v != son[u]) chkmax(snd_dep, dep[v]);
	for(int i = 1; i <= snd_dep; ++i)
	{
		(f[root[u]][0][dep[u] - i - 1] += f[root[u]][2][dep[u] - i - 1]) %= MOD;
		f[root[u]][2][dep[u] - i - 1] = 0;
	}
}

inline int fpm(int x, int y)
{
	int res = 1;
	for(; y; y >>= 1, x = (LL) x * x % MOD) if(y & 1) res = (LL) res * x % MOD;
	return res;
}

inline void solve()
{
	dep[1] = 1, dfs(1);
	for(int i = 1; i <= n; ++i) dep[i] = max_dep[i] - dep[i] + 1;

	DP(1);

	int ans = 0;
	for(int i = 1; i <= dep[1]; ++i) (ans += (LL) f[root[1]][1][dep[1] - i] * fpm(2, n - cnt[i]) % MOD) %= MOD;
	printf("%d\n", ans);
}

int main()
{


	input();
	solve();

	return 0;
}



Measured memory_bytes: 46948
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	static int[][] map;
	static long ans;
	static boolean[] used;
	static int[] r;
	static int R;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		R = sc.nextInt();
		map=new int[n][n];
		used=new boolean[n];
		ans=Long.MAX_VALUE;
		r=new int[R];
		for(int i = 0; i<R; i++){
			r[i]= sc.nextInt()-1;
		}
		for(int i = 0; i<n; i++){
			Arrays.fill(map[i],Integer.MAX_VALUE/2);
		}
		for(int i = 0; i<m; i++){
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			int c = sc.nextInt();
			map[a][b]=c;
			map[b][a]=c;
		}
		for(int i = 0; i<n; i++){
			for(int j = 0; j<n; j++){
				for(int k = 0; k<n; k++){
					if(i!=j && j!=k && k!=i){
						map[j][k]=Math.min(map[j][k],map[j][i]+map[i][k]);
					}
				}
			}
		}
		for(int i :r){
			used[i]=true;
			dfs(i,0,1);
			used[i]=false;
		}
		System.out.println(ans);
	}
	static void dfs(int now,long cost,int count){
		if(count==R){
			ans=Math.min(ans,cost);
		}
		for(int i:r){
			if(!used[i]){
				used[i]=true;
				dfs(i,cost+map[now][i],count+1);
				used[i]=false;
			}
		}
	}
}


Measured memory_bytes: 46172
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
string s;
ll ans=0;
void dfs(int a,ll now) {
  if(a==s.size()) {
    ans+=now;
    return ;
  }
  ll x=0;
  for(int i=a; i<s.size(); i++) {
    x=x*10+s[i]-'0';
    dfs(i+1,now+x);
  }
}
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  dfs(0,0);
  cout << ans << endl;
}

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

int main()
{
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    vector<int> t(1000010, 0);
    for(int x : v){
        if(t[x] != 0){
            t[x] = 2;
            continue;
        }
        for(int i = x; i < 1000010; i += x){
            t[i]++;
        }
    }
    int ans = 0;
    for(int x : v){
        if(t[x] == 1)ans++;
    }
    cout << ans << endl;
    system("pause");
}


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

int main()

{
    string n;
    cin>>n;
    for(int i=0; i<n.size(); i++){
        if(n[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

}




Measured memory_bytes: 3568
# selection sort
N = int(input())
A = [int(i) for i in input().split()]

cnt = 0

for i in range(0, N):
    min_i = i
    for j in range(i+1, N):
        if A[j] < A[min_i]:
            min_i = j
    if i != min_i:
        A[i], A[min_i] = A[min_i], A[i]
        cnt = cnt + 1

print(' '.join([str(i) for i in A]))
print(cnt)

Measured memory_bytes: 7744
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;



int main ()
{
  prep();
  char c;
  cin >> c;
  cout << (char)(((int)c)+1);
  return 0; 
}

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

int main()
{
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	vector<int> av(n);
	for (auto& i : av) {
		cin >> i;
	}

	vector<vector<int>> ret(h, vector<int>(w));
	int colorNum = 1;
	int currentH = 0;
	int currentW = 0;
	int move = 1;
	for (auto& i : av) {
		for (int j = 0; j < i; ++j) {
			ret[currentH][currentW] = colorNum;
			currentW += move;
			if (move == 1 && currentW == w) {
				++currentH;
				currentW = w - 1;
				move = -1;
			}
			else if (move == -1 && currentW == -1) {
				++currentH;
				currentW = 0;
				move = 1;
			}
		}
		++colorNum;
	}

	for (auto& i : ret) {
		for (auto& j : i) {
			cout << j << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,k; cin>>n>>k;
	vector<int> v(n);
	for(auto &i:v) cin>>i;
	vector<bool> dp(k+1,false);
	For(i,0,k){
		For(j,0,n-1)
			if(i>=v[j]) dp[i]=dp[i] || !dp[i-v[j]];
	}
	if(dp[k]) cout<<"First\n";
	else cout<<"Second\n";
	return 0;
}


























Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;

long long comb(int n, int r) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v[n][r];
}


int main(){
    long long n, p;
    cin >> n >> p;

    long long a[n];
    long long cnt_odd = 0, cnt_even = 0;

    for(long long i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2 == 0) cnt_even++;
        else cnt_odd++;
    }

    long long ans;
    if(p == 0){
        long long sum = 0;
        for(long long i = 0; i <= cnt_odd; i++){
            if(i % 2 == 0){
                sum += comb(cnt_odd, i);
            }
        }
        ans = pow(2, cnt_even) * sum;
    }
    else{
        long long sum = 0;
        for(long long i = 0; i <= cnt_odd; i++){
            if(i % 2 != 0){
                sum += comb(cnt_odd, i);
            }
        }
        ans = pow(2, cnt_even) * sum;
    }

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

Measured memory_bytes: 4056
//* AuThOr GaRyMr *//
//Codeforces ID: GaryMr
//Atcoder ID: Gary
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
vector<int> each[100000+10];
int Size[100000+10];int n;
int color[100000+10],all;
int dfs(int now,int p){
	if(each[now].size()==1&&p!=-1) {
	return Size[now]=1;
	}
	int tmps;
	tmps=1;
	for(auto it: each[now]){
		if(it!=p){
			tmps+=dfs(it,now);
		} 
	}
	return Size[now]=tmps;
}
void dfs2(int now,int p,int dis){
	if(now==n) {
		all=dis;
//		cout<<all<<endl;
		color[now]=1;
		return ;
	}
	for(auto it:each[now]){
		if(it!=p){
			dfs2(it,now,dis+1);
			color[now]|=color[it]; 
		}
	}
}
int diV;
int belong;
void dfs3(int now,int p,int is){
	if(is==belong) diV=now;
	else
	for(auto it: each[now]){
		if(it!=p&&color[it]){
			dfs3(it,now,is+1);
			return;
		}
	}
}
int main(){
	
	cin>>n;
	rep(i,n-1){
		int xi,yi;
		cin>>xi>>yi;
		each[xi].PB(yi),each[yi].PB(xi);
	}
	dfs(1,-1);
	dfs2(1,-1,1);
	belong=all/2+all%2;
	belong++;
	dfs3(1,-1,1); 
	int one,two;
	two=Size[diV],one=n-two;
	if(one>two) cout<<"Fennec";
	else cout<<"Snuke"; 
	return 0;
}


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

int main() {
  long long N, K;
  cin >> N >> K;
  long long cnt[100001];
  for (int i=1; i<=100000; i++)
    cnt[i] = 0;

  for (int i=0; i<N; i++) {
    long long a, b;
    cin >> a >> b;
    cnt[a] += b;
  }

  for (int i=1; i<=100000; i++) {
    if (K <= cnt[i]) {
      cout << i << endl;
      return 0;
    }
    K -= cnt[i];
  }

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

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

	return 0;
}

Measured memory_bytes: 888
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product


def solve():
    n = II()
    A = LI()

    memo = {}
    ans = 0
    for i in range(n):
        mae = (i+1) + A[i]
        ima = (i+1) - A[i]
        ans += memo.get(ima, 0)
        memo[mae] = memo.get(mae, 0) + 1
    # print(memo)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 40548
/**	epsileer 12 January 2020  17:38:25  **/	
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1; while(t--) solve()

void solve(){
	int n,m; cin>>n>>m;
	map<int,int> mp, mp2;
	for(int i=0;i<m;i++){
		int q; cin>>q; string s; cin>>s;
		if(mp[q] == 0){
			if(s == "AC")
				mp[q] = 1;
			else
				mp2[q]++;
		}
	}
	int ans = 0, pen = 0;
	for(auto i: mp){
		if(i.second){
			ans++;
			pen += mp2[i.first];
		}
	}
	cout<<ans<<" "<<pen;
}

signed main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); TEST; return 0;
}

Measured memory_bytes: 12800
//
// Created by cerussite on 6/14/20.
//
#include <iostream>

int main() {
  int x, y;

  std::cin >> x >> y;

  const int k2 = y - 2 * x;
  if (k2 % 2 != 0 || k2 < 0) {
    std::cout << "No" << std::endl;
    return 0;
  }

  const int k = k2 / 2;

  const int t2 = 4 * x - y;
  if (t2 % 2 != 0 || t2 < 0) {
    std::cout << "No" << std::endl;
    return 0;
  }

  std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 3620
// https://atcoder.jp/contests/abc173/tasks/abc173_a
#include<bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
	int n;
	cin >> n;
	int ac = 0, wa = 0, tle = 0, re = 0;
	while (n--) {
		string s;
		cin >> s;
		if (s == "AC") {
			++ac;
		} else if (s == "WA") {
			++wa;
		} else if (s == "TLE") {
			++tle;
		} else if (s == "RE") {
			++re;
		}
	}
	cout << "AC x " << ac << endl; 
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
	
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0);
	int n,a,b,passed,b_rank;
	string s;

	cin>>n>>a>>b;
	cin>>s;

	
	b_rank=0;
	passed=0;
	for(auto& letter:s){
		if(passed < a+b){
			if(letter=='a'){
				passed++;
				cout<<"Yes\n";
				}	
			else if(letter=='b'){
				b_rank++;
				if(b_rank <= b){
					passed++;
					cout<<"Yes\n";
				}
				else
					cout<<"No\n";
			}
			else
				cout<<"No\n";
		}
		else
			cout<<"No\n";
	}

	return 0;

}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,L;
  cin>>N>>L;
  vector<string>ch (N);
  for(int i=0;i<ch.size();i++)
    cin>>ch.at(i);
  sort(ch.begin(),ch.end());
  for(int i=0;i<ch.size();i++)
    cout<<ch.at(i);
  cout<<endl;
  
  
  
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,T,A;
  cin >> N >> T >> A;
  vector<pair<double,int>> H(N);
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    H[i].first=abs(A-T+a*0.006);
    H[i].second=i;
  }
  sort(H.begin(),H.end());
  cout << H[0].second+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
int main(){
    long long n;
    cin >> n;
    long long cnt = 0, total = 0;
    long long minAbs = 100000;
    
    vector<long long> a(n);

    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(a[i] < 0){
            cnt++;
            total -= a[i];
            
        }else{
            total += a[i];
        }

        if(minAbs > abs(a[i])){
            minAbs = abs(a[i]);
        }
    }



    if(cnt % 2 != 0){
        total -= minAbs*2;
    }

    cout << total << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long a[200007];
int n;
int main(){
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%lld",a+i);
	}
	long long l=0,r=1;
	long long ans=0;
	long long hh=a[0];
//	cout<<(2 & 5)<<endl;
	while (l!=n){
		while (r!=n){
			if ((hh ^ a[r])!=hh+a[r]){
				break;
			}
			hh+=a[r];
			r++;
		}
		ans+=r-l;
		//cout<<l<<' '<<ans<<endl;
		hh-=a[l];
		l++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int dp[20][100010];
int main(){
    int n;cin>>n;
    int x[100010];
    for(int i=0;i<n;i++)cin>>x[i];
    int l;cin>>l;
    for(int i=0;i<n;i++){
        int ok=i,ng=n;
        while(ng-ok>1){
            int mid=(ng+ok)/2;
            if(x[mid]-x[i]<=l){
                ok=mid;
            }else{
                ng=mid;
            }
        }
        dp[0][i]=ok;
    }
    for(int i=0;i<17;i++){
        for(int j=0;j<n;j++){
            dp[i+1][j]=dp[i][dp[i][j]];
        }
    }
    int q;cin>>q;
    while(q--){
        int a,b;cin>>a>>b;a--;b--;
        if(a>b)swap(a,b);
        int res=0;
        for(int i=17;i>=0;i--){
            if(dp[i][a]<b){
                a=dp[i][a];
                res+=(1<<i);
            }
        }
        cout<<res+1<<endl;
    }
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, p, q, r);
  out(p + q + r - max({p, q, r}));
}


Measured memory_bytes: 3600
#include <stdio.h>
//#include <math.h>
//#include <string.h>
#include <ctype.h>
#include <stdlib.h>

int main(){
	long long *p;
	p = (long long *) malloc(sizeof(long long) * 10010);
	long long i, n, MAX = -1000000, MIN = 1000000, sum = 0;
	scanf("%lld",&n);
	for(i = 0; i < n; i++){
		scanf("%lld",p + i);
		sum += *(p + i);
		if(MAX < *(p + i)) MAX = *(p + i);
		if(MIN > *(p + i)) MIN = *(p + i);
	}
	printf("%lld %lld %lld\n",MIN,MAX,sum );
	return 0;
}

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

#define endl '\n'
#define int ll
using namespace std;
typedef long long ll;

int n, k;

void init();
void process();

int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n >> k;
}

void process()
{
    double res = 0;
    if(n >= k)
    {
        res += (n-k+1)/(double)n;
    }
    int pw = 1;
    while(pw < k) pw *= 2;
    for(int i = 1; i <= n && i < k; i++)
    {
        while(pw * i / 2 >= k) pw /= 2;
        res += 1.0/pw/n;
    }
    cout << fixed << setprecision(10) << res << endl;

}



Measured memory_bytes: 256
n = gets.to_i
as = gets.split(' ').map { |e| e.to_i }.sort

exp =
 if n.even?
  (0...n).to_a.map { |i| i/2 * 2 + 1  }
 else
  (0...n).to_a.map { |i| (i + 1)/2 * 2 }
 end

ans = 
if as == exp
  (2 ** (n / 2)) % (10 ** 9 + 7)
else
  0
end

p ans

Measured memory_bytes: 10608
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] l = new int[n + 1];
		for(int i = 1; i <= n; i++) l[i] = sc.nextInt();
		int[] cnt = new int[51];
		for(int i = 1; i <= n; i++) cnt[l[i]]++;
		int sum = 0;
		int cntIdx = 0;
		out : for(int i = 50; i > 0; i--) {
			for(int j = 0; j < cnt[i]; j++) {
				sum += i;
				cntIdx++;
				if(cntIdx == k)break out;
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21844
n,x=[int(k) for k in raw_input().split(" ")]

a=[int(k) for k in raw_input().split(" ")]

a=sorted(a)

nbh=0

for i in a:
    if i<=x:
        x-=i
        nbh+=1
    else:
        break
if x and nbh==n:
    nbh-=1

print nbh


Measured memory_bytes: 27756
n = int(input())
t, a = map(int, input().split())
h_list = list(map(int, input().split()))

t_list = [t - h * 0.006 for h in h_list]
diff = 10000
point = 0

for i, temp in enumerate(t_list):
    d = abs(a-temp)
    if d < diff:
        diff = d
        point = i+1

print(point)


Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val ans = if (s.slice(0 until n / 2) == s.slice(n / 2 until n)) {
        "Yes"
    } else {
        "No"
    }
    println(ans)
}


Measured memory_bytes: 31872
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    double d; cin >> d;
    printf("%.9f\n",max((double)((int)d+1),sqrt(2)*d) );
}



Measured memory_bytes: 3304
//https://onlinejudge.u-aizu.ac.jp/problems/2444
#include <string>
#include <vector>
#include <tuple>
#include <iostream>
#include <set>
#include <cassert>

struct HashString{
public:
    using hashtype=long long;
    using hashcomptype=std::tuple<hashtype,hashtype,hashtype>;

    std::vector<hashtype> table1;
    std::vector<hashtype> table2;
    std::vector<hashtype> table3;
    std::vector<hashtype> powtable1;
    std::vector<hashtype> powtable2;
    std::vector<hashtype> powtable3;

    hashtype mod=1000000007ll;
    hashtype base1=1919ll;
    hashtype base2=114514ll;
    hashtype base3=334334ll;

    HashString(){}
    HashString(std::string s){
        table1.resize(s.size()+1);
        table2.resize(s.size()+1);
        table3.resize(s.size()+1);
        powtable1.resize(s.size()+1);
        powtable2.resize(s.size()+1);
        powtable3.resize(s.size()+1);

        table1[0]=0ll;
        table2[0]=0ll;
        table3[0]=0ll;
        powtable1[0]=1ll;
        powtable2[0]=1ll;
        powtable3[0]=1ll;

        for(int i=0;i < s.size(); ++i){
            table1[i+1]=table1[i]*base1+s[i];
            table2[i+1]=table2[i]*base2+s[i];
            table3[i+1]=table3[i]*base3+s[i];
            powtable1[i+1]=powtable1[i]*base1;
            powtable2[i+1]=powtable2[i]*base2;
            powtable3[i+1]=powtable3[i]*base3;

            table1[i+1]=table1[i+1]%mod;
            table2[i+1]=table2[i+1]%mod;
            table3[i+1]=table3[i+1]%mod;
            powtable1[i+1]=powtable1[i+1]%mod;
            powtable2[i+1]=powtable2[i+1]%mod;
            powtable3[i+1]=powtable3[i+1]%mod;
        }
    }

    bool operator == (HashString s){
        if(this->table1.size()!=s.table1.size())return false;
        if(this->table1.back()!=s.table1.back())return false;
        if(this->table2.back()!=s.table2.back())return false;
        if(this->table3.back()!=s.table3.back())return false;
        return true;//maybe :)
    }

    hashcomptype get_hash(int l,int r){//[l,r)でのhash
        assert(r-l>0);

        hashtype hash1=table1[r]-(powtable1[r-l]*table1[l]%mod);
        while(hash1<0)hash1+=mod;
        hash1=hash1%mod;

        hashtype hash2=table2[r]-(powtable2[r-l]*table2[l]%mod);
        while(hash2<0)hash2+=mod;
        hash2=hash2%mod;

        hashtype hash3=table3[r]-(powtable3[r-l]*table3[l]%mod);
        while(hash3<0)hash3+=mod;
        hash3=hash3%mod;

        //std::cout<<hash1<<" "<<hash2<<" "<<hash3<<std::endl;
        return std::make_tuple(hash1,hash2,hash3);
    }
};

int main(){
    int n,m;
    std::cin>>n>>m;
    std::string s;
    std::cin>>s;
    HashString hs(s);
    int l=0,r=1;
    std::set<std::tuple<long long,long long,long long>> st;
    for(int i=0;i < m; ++i){
        char op,p;
        std::cin>>op>>p>>p;
        if(op=='R'){
            if(p=='+')++r;
            else --r;
        }
        else{
            if(p=='+')++l;
            else --l;
        }
        st.insert(hs.get_hash(l,r));
    }
    std::cout<<st.size()<<std::endl;
    return 0;
}



Measured memory_bytes: 35916
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	string s;
	cin>>s;
	rep(i,s.size())
		if(s[i]=='P')cout<<"P";
		else cout<<"D";
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3800
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;

    if(a+b>=a-b && a+b>=a*b){
        cout<<a+b<<endl;
    }
    else if(a*b>=a+b && a*b>=a-b)
    {
        cout<<a*b<<endl;

    }
    else if(a-b>=a+b && a-b>=a*b)
        {
           cout<<a-b<<endl;

        }
        return 0;


    }




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> T;
typedef pair<int, int> P;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    vector<T> v(N);
    for (int i = 0; i < N; i++) {
        int s, t, x;
        cin >> s >> t >> x;
        v[i] = T(x, s - x, t - x);
    }
    sort(v.begin(), v.end());
    set<P> se;
    for (int i = 0; i < Q; i++) {
        int D;
        cin >> D;
        se.insert(P(D, i));
    }

    vector<int> S(N), T(N), X(N);
    for (int i = 0; i < N; i++) {
        X[i] = get<0>(v[i]), S[i] = get<1>(v[i]), T[i] = get<2>(v[i]);
    }

    vector<int> ans(Q, 0);
    for (int i = 0; i < N; i++) {
        int x = X[i], l = S[i], r = T[i];
        auto itr1 = se.lower_bound(P(l, 0));
        auto itr2 = se.lower_bound(P(r, 0));
        if (itr1 == se.end()) continue;
        if (itr2 == se.begin()) continue;
        auto it = itr1;
        while ((it != se.end()) && ((itr2 == se.end()) || (*it < *itr2))) {
            ans[it->second] = x;
            it++;
        }
        se.erase(itr1, itr2);
    }
    for (int i = 0; i < Q; i++) {
        cout << (ans[i] ? ans[i] : -1) << endl;
    }
}


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

int a, b, c;

int main()
{
    while(cin >> a >> b)
    {
        for(int i = 1; i <= 3; i++)
        {
            if((a * b * i) % 2 == 1)
            {
                cout << "Yes" << endl;
                break;
            }
            if(i == 3)
                cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256