akhauriyash/Code-Regression huggingface dataset:
import sys

N,K = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

P = []
M = []
Ans = []
p = 0
m = 0

for i in range(N):
    if 0 <= A[i]:
        P.append(A[i])
    else:
        M.append(A[i])

M.sort()

if K % 2 == 1 and len(P) != 0:
    Ans.append(P[p])
    p += 1
elif K % 2 == 1 and len(P) == 0:
    M.sort(reverse=True)
elif len(M) == 0:
    answer = 1
    for i in range(K):
        answer = (answer * P[i]) % 1000000007

    print(answer)
    sys.exit()

while len(Ans) < K:

    #Mのストックがもうない時
    if m+1 >= len(M) and p < len(P):
        Ans.append(P[p])
        if len(Ans) == K:
            break
        if p + 1 < len(P):
            Ans.append(P[p + 1])
            p += 2
        else:
            p += 1
        
    elif p+1 >= len(P) and m < len(M):
        Ans.append(M[m])
        if len(Ans) == K:
            break
        Ans.append(M[m + 1])
        m += 2
    elif m >= len(M) and p < len(P):
        Ans.append(P[p])
        p += 1
    elif p >= len(P) and m < len(M):
        Ans.append(M[m])
        m += 1
    else:
        if P[p]*P[p+1] < M[m]*M[m+1]:
            Ans.append(M[m])
            Ans.append(M[m+1])
            m += 2
        else:
            Ans.append(P[p])
            Ans.append(P[p + 1])
            p += 2

answer = 1
for i in range(K):
    answer = (answer * Ans[i]) % 1000000007

print(answer)


Measured memory_bytes: 118292
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#define MOD_P 1000000007
#define ll long long
using namespace std;


int main()
{
	map<string, int> dic;
	int n;
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		string test;
		cin >> test;
		dic[test]++;
	}

	printf("%d", dic.size());

	return 0;
}

Measured memory_bytes: 19268
N, M = map(int,input().split())
bulbs = [list(map(int,input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))

cnt = 0
for i in range(2**N):
    check = [False] * M
    for j, bulb in enumerate(bulbs):
        on_sum = 0
        for b in bulb:
            if i >> (b-1) & 1:
                on_sum += 1
        
        if on_sum%2 == p[j]:
            check[j] = True
        
    if all(check):
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define PB push_back
#define MP make_pair
#define vec vector

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

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
  for (int i = 0; i < len; i++) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  s << "]";
  return s;
}

bool check(int m, int A, int B, const vector<int>& h)
{
  int sum = 0;
  rep(i, 0, SZ(h)) {
    sum += (max((int)0, h[i] - B*m) + (A-B-1)) / (A-B);
  }
  return sum <= m;
}

int solve(int A, int B, const vector<int>& h)
{
  int l = -1, r = INF;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (check(m, A, B, h)) {
      r = m;
    } else {
      l = m;
    }
  }
  return r;
}


signed main()
{
  int N, A, B; cin >> N >> A >> B;
  vec<int> h(N);
  rep(i, 0, N) {
    cin >> h[i];
  }

  cout << solve(A, B, h) << endl;

  return 0;
}


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

int main(){
  int h1, h2, k1, k2;
  int a, b, c, d;
  int p1, p2;

  cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >>d;

  p1 = h1 * a + h2 * b + (h1 / 10) * c + (h2 / 20) * d;
  p2 = k1 * a + k2 * b + (k1 / 10) * c + (k2 / 20) * d;

  if(p1 > p2){
    cout << "hiroshi";
  }else if(p1 < p2){
    cout << "kenjiro";
  }else cout << "even";
  cout << endl;

  return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll unsigned long long
#define N 1000011

int main() {
        int n;
        cin >> n;
        if (n == 1) {
                cout << "Hello World";
        }else {
                int b, a;
                cin >> b>> a;
                cout << a+b;
        }
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    while(1) {
        c -= b;
        if(c <= 0) {
            printf("Yes\n");
            break;
        }
        a -= d;
        if(a <= 0) {
            printf("No\n");
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3768
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;

LLONG dp[200001];

int main()
{
	// ループするまで続ける
	LLONG N, X, M; cin >> N >> X >> M;
	vector<LLONG> as;
	set<LLONG> aSet;
	LLONG ans = 0;
	LLONG prev = X;
	for (LLONG i = 0; i < N; ++i)
	{
		as.push_back(prev);
		aSet.insert(prev);
		ans += prev;
		LLONG next = (prev * prev) % M;
		if (next == prev)
		{
			ans += next * (N - i - 1);
			break;
		}
		else if (aSet.count(next))
		{
			int pos = distance(as.begin(), find(as.begin(), as.end(), next));
			ans = accumulate(as.begin(), as.end(), 0LL);
			LLONG cycleSize = as.size() - pos;
			LLONG cycleSum = accumulate(as.begin() + pos, as.end(), 0LL);
			LLONG remNum = N - as.size();
			ans += cycleSum * (remNum / cycleSize);
			remNum %= cycleSize;
			ans += accumulate(as.begin() + pos, as.begin() + pos + remNum, 0LL);
			break;
		}
		prev = next;
	}
	cout << ans << endl;
}


Measured memory_bytes: 5812
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    int xorSum = 0;
    for (int i = 0; i < N; i++) xorSum ^= a[i];
    for (int i = 0; i < N; i++) {
        if (i) cout << ' ';
        cout << (xorSum ^ a[i]);
    }
    cout << '\n';
}


Measured memory_bytes: 3992
#include<stdio.h>
#include<string.h>
#include<math.h>
#define N 1001
int ary[N][N];
int lcs(char* X,char* Y){
  int i,j,n,m,maxlen=0;
  m=strlen(X);
  n=strlen(Y);
  for(i=1;i<=m;i++)
    {
      ary[i][0]=0;
    }
  for(j=1;j<=n;j++)
    {
      ary[0][j]=0;
    }
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(X[i-1]==Y[j-1]){
	ary[i][j]=ary[i-1][j-1]+1;
      }
      else {
	ary[i][j]=fmax(ary[i-1][j],ary[i][j-1]);	
      }
      maxlen=fmax(maxlen,ary[i][j]);
    }
  }
  return maxlen;
}

int main(){
  int i,n;
  char word1[N],word2[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%s",word1,word2);
    printf("%d\n",lcs(word1,word2));
  }
  return 0;
}



Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
const int MAXN = 200005;
ll INF = 1e18;

ll t[4 * MAXN];
ll tmx[4*MAXN];

void upd(int v, int tl, int tr, int l, int r, ll val)
{
    if (l > r) return;
    if (tl == l &&  tr == r)
    {
        t[v] += val;
        tmx[v] = tmx[v] + val;
    }
    else
    {
        int tm = (tl + tr) / 2;
        upd(v*2, tl, tm, l, min(r,tm), val);
        upd(v*2+1, tm+1, tr, max(l,tm+1), r, val);
        tmx[v] = max(tmx[2*v], tmx[2*v+1]) + t[v];
    }
}

ll mx(int v, int tl, int tr, int l, int r) {
    if (l > r) return -INF;
    if (tl == l && tr == r) return tmx[v];
	int tm = (tl + tr) / 2;
	return max(mx(v*2, tl, tm, l, min(r,tm)),
        mx(v*2+1, tm+1, tr, max(l,tm+1), r));
}


pair <int, ll> l[MAXN];
pair < int, pair <int, ll> > r[MAXN];

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> l[i].ff >> r[i].ff >> l[i].ss;
        r[i].ss.ff = l[i].ff;
        r[i].ss.ss = l[i].ss;
    }

    sort(l, l + m);
    sort(r, r + m);
    int li = 0, ri = 0;
    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        while (li < m && l[li].ff <= i) {
            upd(1, 0, n, 0, l[li].ff-1, l[li].ss);
            li++;
        }
        while (ri < m && r[ri].ff < i) {
            upd(1, 0, n, 0, r[ri].ss.ff-1, -r[ri].ss.ss);
            ri++;
        }
        ll dp = mx(1, 0, n, 0, i-1);
        upd(1, 0, n, i, i, dp);
        ans = max(ans, dp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 18688
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, M = map(int, input().split())
AB = []
for _ in range(M):
    A, B = map(int, input().split())
    AB.append((A-1, B-1))

uf = UnionFind(N)
ans = [N*(N-1)//2]
for A, B in AB[:0:-1]:
    if uf.isSameGroup(A, B):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1]-uf.Count(A)*uf.Count(B))
    uf.Unite(A, B)
print(*ans[::-1], sep='\n')


Measured memory_bytes: 112984
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N =1e5+5;
const ll mod=1e9+7;
int main()
{
    ll k,x,y;
    scanf("%lld%lld%lld",&k,&x,&y);
    if(k%2==0 && (abs(x)+abs(y))%2==1)
    {
        puts("-1");return 0;
    }
    ll sx=1,sy=1;
    if(x<0)x=-x,sx=-1;
    if(y<0)y=-y,sy=-1;

    ll n=(x+y+k-1)/k,cx=0,cy=0;
    if(n==1 && x+y!=k)n++;
    while((n*k-x-y)%2)n++;

    printf("%lld\n",n);


    for(ll w=(n*k-x-y)/2;w>0;)
    {
        int t= abs(x-cx) < abs(y-cy);
        if(t)
            cx-=min(k,w);
        else
            cy-=min(k,w);
        ll r=k-min(k,w);
        if(t)
            cy+=r;
        else
            cx+=r;
        w-=min(w,k);
        printf("%lld %lld\n",cx*sx,cy*sy);
    }
    while(cx!=x || cy!=y)
    {
        ll r=k;
        if(cx!=x)
        {
            ll d=min(k,x-cx);
            cx+=d;
            r-=d;
        }
        if(cy!=y)
        {
            ll d=min(y-cy,r);
            cy+=d;
            r-=d;
        }
        printf("%lld %lld\n",cx*sx,cy*sy);
    }
    return 0;
}


Measured memory_bytes: 2304
/*
god taekyu
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n;
int A[100005][3];
int dp[100005][3];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) {
        for(int j=0;j<3;j++) cin>>A[i][j];
    }
    for(int i=1;i<=n;i++) {
        for(int j=0;j<3;j++) {
            for(int k=0;k<3;k++) {
                if(j==k) continue;
                dp[i][j] = max(dp[i-1][k] + A[i][j], dp[i][j]);
            }
        }
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]});
    return 0;
}

/*
god taekyu
*/


Measured memory_bytes: 2560
#define _GIBCXX_DEBUG
#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()
using namespace std;
using ll = long long;
using P = pair<int, int>;


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

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }


  vector<int> L(N), R(N);
  rep(i, N - 1) {
    L[i + 1] = gcd(L[i], A[i]);
  }
  for (int i = N -1; i >= 1; --i) {
    R[i - 1] = gcd(R[i], A[i]);
  }

  int ans = 1;
  rep(i, N) {
    ans = max(ans, gcd(L[i], R[i]));
  }

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

Measured memory_bytes: 4208
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

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

num = 0

for i in range(len(h)):
    for j in range(len(h)):
        if i == j:
            num += 1
        if h[j] > h[i]:
            break

print(num)

Measured memory_bytes: 12420
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int n;
int a[1000005];
bool val[1000005];
bool check(int lim){
	int ans=-1;
	for(int i=1;i<=n;i++){
		if(a[i]>lim)val[i]=1;
		else val[i]=0;
	}
	for(int i=n/2+2,j=n/2;i<=n;j--,i++)
	{
		if(val[i]==val[i-1]){
			ans=val[i];
			break;
		}
		if(val[j]==val[j+1]){
			ans=val[j];
			break;
		}
	}
	if(ans==-1) return val[1];
	else return ans;
}
signed main(){
	scanf("%lld",&n);
	n=2*n-1;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	int l=1,r=n,mid;
	while(l<r){
		mid=(l+r)>>1;
		if(check(mid))l=mid+1;
		else r=mid;
	}
	printf("%lld",l);
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int a,b,n,c[100005],ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		for(int j=a;j<=b;j++)
			c[j]=1;
	}
	for(int i=1;i<=100000;i++)
		if(c[i]>0) ans++;
	cout<<ans;
	return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int x,y;
  x = min(min(a,b),c);
  y = max(max(a,b),c);
  cout << y-x << endl;
  return 0;
}


Measured memory_bytes: 256
/**
 *    author:   K.R.Surrya  
 *    created:  02/05/2020 17:44:06
**/
#include<bits/stdc++.h>
#define vi vector<int>
#define vii vector<vector<int> >
#define vpi vector<pair<int,int> >
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pb push_back
using namespace std; 

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)  { return ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a,Args... args)
{
    cerr << *it << " = " << a <<endl;
    err(++it,args...);   //args is going to end.
}

void solve() { 
   long long X;
   cin >> X;
   int t=0;
   long long principal=100;
   while(true) { 
       ++t;
       principal=principal*(1.01);
       if(principal>=X) {
           cout << t << '\n';
           return ;
       }
   }
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

     auto start = chrono::high_resolution_clock::now();
     solve();
     auto end = chrono::high_resolution_clock::now();

     cerr << " Execution time : " << chrono::duration_cast<chrono::milliseconds>(end-start).count()<<"ms"<<endl;

   
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

const ll mod=1000000007;

int main(void){
	          int i;

	          int N;
	          string s1,s2;
	          cin >> N >> s1 >> s2;

	          int t,c;
	          ll a;
	          if(s1[0]==s2[0]){
	        	  a=3; t=1; c=1;
	          }else{
	        	  a=6; t=2; c=2;
	          }

	        	  for(i=c;i<N;i++){
	        		  if(s1[i]==s2[i] && t==1){
	        			  t=1;
	        			  a=(2*a)%mod;
	        		  }
	        		  else if(s1[i]==s2[i] && t==2){
	        			  t=1;
	        			  continue;;
	        		  }
	        		  else if(s1[i]!=s2[i] && t==1){
	        			  t=2;
	        			  a=(2*a)%mod;
	        			  i++;
	        		  }
	        		  else if(s1[i]!=s2[i] && t==2){
	        			  t=2;
	        			  a=(3*a)%mod;
	        			  i++;
	        		  }
	        	  }
	        	  cout << a%mod << endl;

	          return 0;
}


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

#define ff first
#define ss second
#define it(a, x) for (auto &a : x)
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vs vector<string>
#define gi greater<int>
#define vc vector<char>
#define vvi vector<vi>
#define vvc vector<vc>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define deb(x) cout << #x << "=" << x << endl;
#define in(i, n) for (auto i = 0; i < n; i++)
#define all(x) begin(x), end(x)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());//random shuffler

ll fxp(ll a, ll b) {
    if (b == 0) return 1;
    if (b % 2 == 0) {
        ll c = fxp(a, b / 2);
        return (c * c) % mod;
    }
    return (a * fxp(a, b - 1)) % mod;
}

void c_p_c() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
}

vi dp;

int go(int s) {
    if (s == 0)
        return 1;
    if (s < 0)
        return 0;
    if (dp[s] != -1)
        return dp[s];
    int ans = 0;
    for (int i = 3; i <= s; i++) {
        ans = (ans % mod + go(s - i) % mod) % mod;
    }
    return dp[s] = ans % mod;
}

void solve() {
    int s;
    cin >> s;
    dp.clear();
    dp.resize(s + 1, -1);
    cout << go(s) << endl;
    //for (int x : dp) cout << x << " ";
}

int main(int argc, char const *argv[]) {
    c_p_c();
    solve();
    return 0;
}


Measured memory_bytes: 3688
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, core.bitop;

void main()
{
    auto N = readln.chomp.to!long;
    auto T = new int[][](N, N);
    foreach (i; 1..N.to!int) {
        auto ab = readln.split.to!(int[]);
        auto a = ab[0]-1;
        auto b = ab[1]-1;
        T[a][b] = i;
        T[b][a] = i;
    }
    auto M = readln.chomp.to!long;
    auto RS = new ulong[](M);
    foreach (i; 0..M) {
        auto uv = readln.split.to!(int[]);
        auto u = uv[0]-1;
        auto v = uv[1]-1;
        int[] walk(int i, int p) {
            if (i == v) return [-1];
            foreach (j; 0..N.to!int) if (j != p && T[i][j]) {
                auto s = walk(j, i);
                if (!s.empty) {
                    return s ~ T[i][j];
                }
            }
            return [];
        }
        foreach (e; walk(u, -1)[1..$]) RS[i] |= (1L<<e);
    }

    long res = 2L^^(N-1);
    foreach (x; 1..(1<<M)) {
        ulong s;
        foreach (i; 0..M) if (x & (1<<i)) s |= RS[i];
        res += 2L^^(N-1-popcnt(s)) * (-1)^^popcnt(x);
    }
    writeln(res);
}

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

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

using R=long double;
const R EPS = 1E-8; 
inline int sgn(const R& r){ return (r > EPS) - (r < -EPS);}

using P=complex<R>;
using L=struct{P s,t;};

inline R dot(P o,P a,P b){a-=o,b-=o; return real(conj(a)*b);}
inline R det(P o,P a,P b){a-=o,b-=o; return imag(conj(a)*b);}

R dsp(L s,P p){
	if(sgn(dot(s.s,s.t,p))<=0) return abs(p-s.s);
	if(sgn(dot(s.t,s.s,p))<=0) return abs(p-s.t);
	return abs(det(s.s,s.t,p))/abs(s.t-s.s);
}

R dss(L a,L b){return min({dsp(a,b.s),dsp(a,b.t),dsp(b,a.s),dsp(b,a.t)});}

const R inf=1e60;

int main(void){
	int w,m;
	cout.precision(20);
	while(cin >> w >> m,w){
		vector<L> pol[210];

		rep(i,m){
			int n,x[55],y[55];
			cin >> n;
			rep(j,n) cin >> x[j] >> y[j];
			rep(j,n) pol[i].push_back({P(x[j],y[j]),P(x[(j+1)%n],y[(j+1)%n])});
		}

		const int s=m,t=m+1,n=m+2;
		pol[s].push_back({P(0,-1e5),P(0,1e5)});
		pol[t].push_back({P(w,-1e5),P(w,1e5)});
		
		R dist[210][210];
		rep(i,n) dist[i][i]=0.0;

		rep(j,n)rep(i,j){
			R d=inf;
			for(auto &il:pol[i])
				for(auto &jl:pol[j]) 
					chmin(d,dss(il,jl));
			dist[i][j]=dist[j][i]=d;
		}
	
		rep(k,n)rep(i,n)rep(j,n) chmin(dist[i][j],dist[i][k]+dist[k][j]);
		cout << fixed << dist[s][t] << endl;
 	}
	return 0;
}

Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main(){
  int n;
  map<char,ll> mp;
  cin>>n;
  rep(i,n){
    char c;
    cin>>c;
    mp[c]++;
  }

  ll ans=1;
  for(auto m:mp){
    ans*=m.S+1;
    ans%=M;
  }

  cout<<ans-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int N; cin >> N;
    ll sum=0;
    for (int i=1; i<=N; i++){
        if (i%3==0 || i%5==0) continue;
        sum+=i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> a(h+2);
  for(int i = 1; i < h+1;i++){
    string tmp;
    cin >> tmp;
    a[i] = '#' + tmp + '#';
  }
  rep(i,w+2){
    a[0] += '#';
    a[h+1] += '#';
  }  
  for(auto b:a){
    cout << b << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
l = list(map(int,input().split()))
ans = 0
if l[0] == l[1] == l[2] and all(i % 2 == 0 for i in l):
  print(-1)
  exit()
while all(i % 2 == 0 for i in l):
  l[0], l[1], l[2] = l[1]//2 + l[2]//2, l[0]//2 + l[2]//2, l[0]//2 + l[1]//2
  ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
const int N=1e6;
int n,p[N],i,cnt,x;
pair<int,int>a[N],b[N];
main(){
	scanf("%d",&n);
	for (i=1;i<=n;++i) scanf("%d",&a[i].F),a[i].S=i;
	for (i=1;i<=n;++i) scanf("%d",&b[i].F),b[i].S=i;
	sort(a+1,a+n+1),sort(b+1,b+n+1);
	for (i=1;i<=n;p[a[i].S]=b[i].S,i++)
		if (a[i].F>b[i].F) return puts("No"),0;
	for (i=1;i<n;i++)
		if (a[i+1].F<=b[i].F) return puts("Yes"),0;
	x=1;
	do cnt++,x=p[x];while(x!=1);
	puts(cnt==n?"No":"Yes");
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    int n;
    string s;
    cin >> n >> s;
    int x =0;
    int _x = 0;
    rep(i,n) {
        if (s[i]=='I') _x++;
        if (s[i]=='D') _x--;
        x = max(_x,x);
    }
    cout << x << "\n";


}


Measured memory_bytes: 256
import java.util.*;
// warm-up
//Got it. Missed the condition around m<n
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong(), m=sc.nextLong(), t=0;
		if (m/2<n) t=m/2;
		else t=n+(m-n*2)/4;
		System.out.println(t);
		sc.close();			
	}

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

}

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

ll sum(ll t) {
  return (t*(t+1))/2;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  ll x = 1; //配点の最大値
  rep(i, 1, n+1) {
    if(sum(i-1) < n and n <= sum(i)) {
      x = i;
      break;
    }
  }
  ll y = n-sum(x-1); //x-1までの和での不足分
  rep(i, 1, x+1) {
    if(i != x-y)
      cout << i << "\n";
  }
}

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

int lucas(int l, int r) {
	return !(~l & r);
}

int main() {
	int n; cin >> n;
	int a[n];
	for(int i = 0; i < n; ++i) {
		char c; cin >> c;
		a[i] = c - '1';
	}
	{
		int cnt = 0;
		bool one = false;
		for(int i = 0; i < n; ++i) {
			if(a[i] == 1) {
				cnt += lucas(n - 1, i);
				cnt &= 1;
				one = true;
			}
		}
		if(cnt) {
			cout << 1 << '\n';
			return 0;
		}
		if(one) {
			cout << 0 << '\n';
			return 0;
		}
	}
	for(int i = 0; i < n; ++i) {
		a[i] >>= 1;
	}
	int cnt = 0;
	for(int i = 0; i < n; ++i) {
		if(a[i] == 1) {
			cnt += lucas(n - 1, i);
			cnt &= 1;
		}
	}
	if(cnt) {
		cout << 2 << '\n';
		return 0;
	}
	cout << 0 << '\n';
	return 0;
}

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

int main() {
    long x;
    cin >> x;

    if (x == 7 || x == 5 || x == 3) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}


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

int main(){
    int n,k,c;cin>>n>>k>>c;
    string s;cin>>s;
    vector<int> a(2e5,0),b(2e5,0);
    for(int i=0,cur=0;i<n,cur<=k-1;i++){
        if(s[i]=='o'){
            a[cur++]=i;
            i+=c;
        }
    }
    for(int i=n-1,cur=k-1;i>=0,cur>=0;i--){
        if(s[i]=='o'){
            b[cur--]=i;
            i-=c;
        }
        
    }
    for(int i=0;i<k;i++){
        if(a[i]==b[i])cout<<a[i]+1<<endl;
    }
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
using lint  = long long;
const lint MOD = 1e9+7;

lint modpow(lint m, lint n){
  if(n == 0) return 1;
  else if(n % 2 == 0) return modpow(m * m % MOD, n/2);
  else{
    return modpow(m, n - 1) * m % MOD;
  }
}

signed main(){
 lint n, a, b; cin >> n >> a >> b;
 lint ans = modpow(2, n) - 1;
 lint ca = 1, cb = 1;
 lint na = 1, nb = 1;
 for(lint i = n - a + 1; i <= n; i++) ca *= i, ca %= MOD;
 for(lint j = n - b + 1; j <= n; j++) cb *= j, cb %= MOD;
 for(lint i = 1; i <= a; i++) na *= i, na %= MOD;
 for(lint j = 1; j <= b; j++) nb *= j, nb %= MOD;
 na = modpow(na, MOD - 2);
 nb = modpow(nb, MOD - 2);
 ca = (na * ca) % MOD;
 cb = (nb * cb) % MOD;
 ans -= (ca + cb);
 ans %= MOD;
 if(ans < 0) ans += MOD;
 cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;


#[fastout]
fn main() {
    input!{
        A: usize,
        B: usize,
        C: usize,
    }

    println!("{} {} {}", C, A, B);
}


Measured memory_bytes: 2196
n,m=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(m)]
ab.sort()
l=-1;r=n
ans=1
for a,b in ab:
  if b<=l or r<=a:
    ans+=1
    l,r=a,b
  l=max(l,a)
  r=min(b,r)
print(ans)

Measured memory_bytes: 27872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b;
	cin>>a>>b;
	ll pl=a-1;
	ll moto=1;
	ll ans=0;
	while(moto<b){
		ans++;
		moto+=pl;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
student = [list(map(int, input().split())) for _ in range(N)]
chpoint = [list(map(int, input().split())) for _ in range(M)]
ans = []
for i in range(N):
    mdisstance_tmp = float('inf')
    ans_tmp = 0
    for j in range(M):
        mdistance = abs(student[i][0]-chpoint[j][0])+abs(student[i][1]-chpoint[j][1])
        if mdisstance_tmp > mdistance:
            mdisstance_tmp = mdistance
            ans_tmp = j+1
    ans.append(ans_tmp)

for i in ans:
    print(i)

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

string s[52];
int dx[8]={-1,0,1,1,1,0,-1,-1}, dy[8]={-1,-1,-1,0,1,1,1,0};

int main(){
    int h, w;
    cin >> h >> w;
    for(int i=0;i<h;++i)cin >> s[i];
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(s[i][j] == '.'){
                int cnt = 0;
                for(int k=0;k<8;++k){
                    if(i+dy[k] >= 0 && i+dy[k] < h && j+dx[k] >= 0 && j+dx[k] < w && s[i+dy[k]][j+dx[k]] == '#')cnt++;
                }
                cout << cnt;
            }else
                cout << '#';
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import math, itertools, operator
from math import *
from math import factorial as fact
from functools import reduce
from statistics import mean, median, median_low, median_high, mode
# Before Python 3.5
from fractions import gcd
#import numpy
#import scipy, scipy.special
#from sympy import isprime, nextprime
#from sympy.ntheory import factorint

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(inp = input, sep = ' ', conv = int):
    return map(conv, inp().split(sep = sep))

################################################################################

N = input_ints()
H = input_ints()

curmax = -inf
cnt = 0
for Hi in H:
    if curmax <= Hi:
        cnt += 1
        curmax = Hi
print(cnt)


Measured memory_bytes: 5500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[2500][2500][2];
bool done[2500][2500][2];
int n;
ll a[2500];
ll dp(int x, int y, bool turn)
{
	if (done[x][y][turn]) return memo[x][y][turn];
	done[x][y][turn] = true;
	int upto = max(x, y);
	if (upto == n-1) 
	{
		return memo[x][y][turn] = abs(a[x]-a[y]);
	}
	if (turn)
	{
		//printf("%d %d %d\n", x, y, max(dp(upto+1, y, true), dp(upto+1, y, false)));
		return memo[x][y][turn] = max(dp(upto+1, y, true), dp(upto+1, y, false));
	}
	else
	{
		return memo[x][y][turn] = min(dp(x, upto+1, true), dp(x, upto+1, false));
	}
}
int main()
{
	ll z, y;
	scanf("%d%lld%lld", &n, &a[0], &a[1]);
	n+=2;
	for (int i = 2; i < n; i++)
	{
		scanf("%lld", &a[i]);
	}
	printf("%lld\n", dp(0, 1, true));
}

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

int main() {
    double a,b;
    double c;
    int d;

    cin >> a >> b;

    c = (a+b)/2;
    d = (a+b)/2;
    if(c == d){
        cout << d << endl;
    } else
    {
        cout << d+1 << endl; 
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int N, R, G, B, tmp = 0, sum = 0;
    std::cin >> R >> G >> B >> N;
    for (int r = 0; r <= 3000; r++)
    {
        for (int g = 0; g <= 3000; g++)
        {
            sum = R * r + G * g;
            if (N >= sum && (N - sum) % B == 0) { tmp++; }
        }
    }

    std::cout << tmp << std::endl;
    return 0;
}

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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

const int  N = 2e5+5;
const int inf = INT_MAX;
const int MOD = 1e9+7;

void solve()
{
   int x[5];
   int ans = -1;
   for(int i=0;i<5;i++)
   {
      cin >> x[i];
      if(x[i] == 0)
      {
         ans = i;
      }
   }
   cout << ans+1;
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 3632
//此程序使用了qt专属名称，请勿模仿。侵权必究！！！
//我真是太菜了…… 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=110;
int n,a[N],b[N],v[N];
char s[N][N];
bool flag=1;
inline int read()
{
	int sum=0,flag=1;
	char c;
	for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=-1;
	for(;c>='0'&&c<='9';c=getchar())sum=(sum<<1)+(sum<<3)+c-'0';
	return sum*flag;
}
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	n=read();
	for(int i=1;i<=n;++i)
	{
		scanf("%s",s[i]);
		a[i]=strlen(s[i]);
	}
	memset(b,300,sizeof(b));
	for(int i=1;i<=n;++i)
	{
		memset(v,0,sizeof(v));
		for(int j=0;j<a[i];++j)
		{
			++v[s[i][j]-'a'];
		} 
		for(int j=0;j<26;++j)
		{
			b[j]=min(b[j],v[j]);
		}
	}
	for(int i=0;i<26;++i)
	{
		if(b[i])
		{
			flag=0;
			while(b[i]--)
			{
				printf("%c",i+'a');
			}
		}
	}
	if(flag)
	{
		printf("\n");
	}
	return 0;
}




Measured memory_bytes: 256
#include <cstdio>
#include <list>

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0,tmp;i<n;i++){
		list<int> a,b,c;
		for(int j=0;j<10;a.push_back(tmp),j++)
			scanf("%d",&tmp);
		while(!a.empty()){
			if(a.front()>b.back()||b.empty()){
				b.push_back(a.front());
				a.pop_front();
			}
			else if(a.front()>c.back()||c.empty()){
				c.push_back(a.front());
				a.pop_front();
			}
			else break;
		}
		puts(a.empty()?"YES":"NO");
	}
	return 0;
}

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

int main(){
    int n,i,j;
    cin >> n;
    vector<double>p(n);
    for(i=0;i<n;i++)cin >> p[i];
    vector<vector<double>> dp(n+1, vector<double>(n+1));

    dp[0][0]=1;

    //dp[i][j]:i枚のコインを投げた時の表がjであるような個数
    double res = 0;
    for(i=0;i<n;i++){
        for(j=0;j<i+1;j++){
            dp[i+1][j] += dp[i][j] * (1-p[i]);
            dp[i+1][j+1] += dp[i][j] * (p[i]);
        }
    }

    for(i=n/2 + 1; i<=n;i++){
        res += dp[n][i];
    }

    printf("%.10f\n", res);


    return 0;
}

Measured memory_bytes: 70656
def factorial(n):
    res = 1
    for i in range(n):
        res*=(i+1)
    return res

def order(n, li):
    res=0
    for i in range(n):
        j=sorted(li[n-i-1:n]).index(li[n-i-1])
        res+=factorial(i)*j
    return res

n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))

p_ord=order(n,p)
q_ord=order(n,q)

print(abs(p_ord-q_ord))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define x first
#define y second
using namespace std;
vector< vector < int > > adj(10000);
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin>>n;
    int d[n]; memset(d,0,sizeof(d));
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        cin>>u>>v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
        d[u]++;
        d[v]++;
    }
    int c[n];
    for(int i=0;i<n;i++)
        cin>>c[i];
        sort(c,c+n);

    int val[n]; memset(val,-1,sizeof(val));
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int r=10000; int in=0; int y=0;
        for(int j=0;j<n;j++)
        {
            //cout<<d[j]<<" r ";
            if(d[j]&&(d[j]<r)){
                r=d[j]; in =j;
            }
            if(val[j]==-1)y=j;
        }
       // cout<<r<<"\n";
        if(r==10000){
            val[y]=c[i];continue;
        }
         val[in]=c[i];
         ans+=(d[in])*val[in];
         d[in]=0;
         for(auto x : adj[in])
         {
             if(d[x])d[x]--;
         }
    }
    cout<<ans<<"\n";
    for(int i=0;i<n;i++)
        cout<<val[i]<<" ";
      return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <tuple>
#include <set>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> d(N);
  for (auto& di: d) scanf("%d", &di);
  std::sort(d.begin(), d.end());

  printf("%d\n", d[N/2]-d[N/2-1]);
}


Measured memory_bytes: 640
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

tmp = 0
MAX = 100000
prime = primes(MAX)
a = [0 for _ in range(MAX+1)]
for i in range(MAX+1):
    if i%2 == 0:
        continue
    elif i in prime and int((i+1)/2) in prime:
        a[i] = 1
#累積和
s = [0 for _ in range(MAX+2)]
for i in range(MAX+1):
    s[i+1] = s[i] + a[i]


Q = int(input())
for i in range(Q):
    l,r = map(int, input().split())
    print(s[r+1]-s[l])

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

using namespace std;

int main()
{
    int x, y;
    scanf("%d %d", &x, &y);

    if (y % 2 == 1)
        printf("No");
    else if (x * 2 > y)
        printf("No");
    else if (x * 4 < y)
        printf("No");
    else
        printf("Yes");

    return 0;
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}
int no=1,n1;
int recu(int n,int k,int val){


	if(n==n1){
		return min(val*2,val+k);
	}
	return min( recu(n+1,k,2*val),recu(n+1,k,val+k)              );


}

int main() {
    int i,m,n,k,c=0,sum=0;
    c_p_c();
    // cout<<"Sd"<<endl;>
    cin>>n>>m>>k;
    n=n-2*k;


    if(n-m>=0){
    	c++;
    	n=n-m;
    }
    // watch(n);
    while(1){

    	if(n-m-k>=0){
    		c++;
    		n=n-m-k;
    	}else
    		break;


    }
    cout<<c<<endl;

   }

Measured memory_bytes: 3600
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    string s;
    cin>>n>>s;
    LL ans = n;

    REP(i,n-1){
        if(s[i] == s[i+1])ans--;
    }
    PUTS(ans);
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

int main() {
	string s;
	cin >> s;
	int l, r;
	l = 0, r = s.size()-1;
	int res = 0;
	while(l < r) {
//		cout << l << "," << r << endl;
		if(s[l] == s[r]) {
			l++;
			r--;
		}
		else if(s[l] == 'x') {
			l++;
			res++;
		}
		else if(s[r] == 'x') {
			r--;
			res++;
		}
		else {
			res = -1;
			break;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 512
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val a = io.StdIn.readLine().split(" ").map(_.toInt)
    val count = bubbleSort(a, n)
    println(a.mkString(" "))
    println(count)
  }

  def bubbleSort(a: Array[Int], n: Int): Int = {
    var flag = true
    var count = 0
    while (flag) {
      val c = (n - 1 to 1 by -1).count { j =>
        if (a(j) < a(j - 1)) {
          val v = a(j)
          a(j) = a(j - 1)
          a(j - 1) = v
          true
        } else {
          false
        }
      }
      count += c
      flag =
        if (c > 0) true
        else false
    }
    count
  }
}

Measured memory_bytes: 43924