akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 1100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int C[1100];
vector<int> V[1100];

int main(){
    int N,M;
    ll x[110000],y[110000],sumx=0,sumy=0;
    cin>>N>>M;
    for(int i=0;i<N;i++) cin>>x[i];
    for(int i=0;i<M;i++) cin>>y[i];

    for(int i=0;i<N;i++){
        sumx+=(x[i]*i-(N-1-i)*x[i]);
        sumx%=MOD;
    }
    for(int i=0;i<M;i++){
        sumy+=(y[i]*i-(M-1-i)*y[i]);
        sumy%=MOD;
    }
    sumx*=sumy;
    sumx%=MOD;
    cout<<sumx<<endl;




}


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n;
	cin>>n;
	int p2, q2;
	vector<int> p, q, v;
	rep(i, n){
		cin>>p2;
		p.push_back(p2);
		v.push_back(p2);
	}
	rep(i, n){
		cin>>q2;
		q.push_back(q2);
	}
	sort(v.begin(), v.end());
	int a=0, b=0, c=0, d=0, e=0;
	do{
		a++;
		b=0, c=0;
		rep(i, n){
			if(v[i]==p[i])
				b++;
			if(v[i]==q[i])
				c++;
		}
		if(b==n){
			d=a;
		}
		if(c==n){
			e=a;
		}
	}while(next_permutation(v.begin(), v.end()));
	cout<<abs(d-e)<<endl;
	return 0;
}

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

int n,m;

vector<int> g[100010],rg[100010];
vector< pair<int,int> > e;

int dp[100010];
int f[100010];
vector<int> depth[100010];

map< pair<int,int> , int > pos;
int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a,b;
		scanf("%d%d",&a,&b);
		g[a].push_back(b);
		rg[b].push_back(a);
		pos[make_pair(a,b)] = i;
	}
	
	for(int i = 1; i <= n; i++){
		g[0].push_back(i);
		rg[i].push_back(0);
	}
	
	for(int i = 0; i <= n; i++)
		for(int j = 0; j < g[i].size(); j++)
			dp[g[i][j]] = max(dp[g[i][j]],dp[i]+1);
	
	int maximum = *max_element(dp,dp+100010);
	
	for(int i = n; i >= 0; i--){
		if(maximum == dp[i]) f[i] = 1;
		else if(f[i] == 0) continue;
		for(int j = 0; j < rg[i].size(); j++){
			if(dp[rg[i][j]]+1 == dp[i]){
				f[rg[i][j]] |= f[i];
				e.push_back(make_pair(rg[i][j],i));
			}
		}
	}
	for(int i = 0; i < e.size(); i++){
		depth[dp[e[i].first]].push_back(pos[make_pair(e[i].first,e[i].second)]);
	}
	vector<int> ans;
	for(int i = 1 ; i < 100010 ; i++){
		if( depth[i].size() == 1 ){
			ans.push_back(depth[i][0]+1);
		}
	}
	sort(ans.begin(),ans.end());
	for(int i = 0 ; i < ans.size() ; i++)
		printf("%d\n",ans[i]);
	if( ans.size() == 0 ) cout << -1 << endl;
}

Measured memory_bytes: 27948
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////
 
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); //入出力高速化
  while (true) {
    int w,d; cin >> w >> d;
    if (w == 0 && d == 0) break;
    vector<pair<int, int>> hw(w),hd(d);
    rep(i,w) {
      int h; cin >> h;
      hw[i] = make_pair(h,i);
    }
    rep(i,d) {
      int h; cin >> h;
      hd[i] = make_pair(h,i);
    }

    sort(all(hw));
    sort(all(hd));
    reverse(all(hw));

    vector<bool> cd(d,false);
    vector<vector<int>> A(w, vector<int>(d));

    rep(i,w) {
      int wh,nw;
      tie(wh,nw) = hw[i];
      rep(j,d) {
        int dh,nd;
        tie(dh,nd) = hd[j];
        if (dh < wh) continue;
        if (dh == wh && cd[nd] && j != d-1) continue;
        A[nw][nd] = wh;
        if (wh == dh) cd[nd] = true;
        break;
      }
    }
    reverse(all(hw));
    reverse(all(hd));
    rep(i,d) {
      int dh,nd;
      tie(dh,nd) = hd[i];
      if (cd[nd]) continue;
      rep(j,w) {
        int wh,nw;
        tie(wh,nw) = hw[j];
        if (dh > wh) continue;
        A[nw][nd] = dh;
        break;
      }
    }
    int ans = 0;
    rep(i,w) {
      rep(j,d) ans += A[i][j];
    }

    cout << ans << endl;
  }


}


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

int main(){
  int n,k,q,i,x;
  cin>>n>>k>>q;
  int a[n];
  for(i=0;i<n;i++){
    a[i]=0;
  }
  for(i=0;i<q;i++){
    cin>>x;
    a[x-1]++;
  }
  for(i=0;i<n;i++){
    if(a[i]>q-k){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
}


Measured memory_bytes: 1024
# B 하나씩 shift하면서 타겟을 정함. 이제 A -> B' 만드는 게 목표
A = input()
B = input()
N = len(A)

if B.count('1') == 0 and A != B:
    print(-1)
    exit()

ans = int(2e18)

ld = [i if B[i] == '1' else -int(1e9) for i in range(N)]
rd = [i if B[i] == '1' else  int(1e9) for i in range(N)]
for i in range(1, N): ld[i] = max(ld[i-1], ld[i])
for i in reversed(range(N-1)): rd[i] = min(rd[i+1], rd[i])

for _ in range(N): # right shift _ times
    # A -> B 만드는 게 목표임
    # 연산: B 왼쪽/오른쪽 shift, B가 1인 거 flip

    tl = []
    tr = []

    for i in range(N):
        if A[i] != B[i]:
            tl.append(min(rd[i] - i, (N + rd[0]) - i))
            tr.append(min(i - ld[i], i - (ld[-1] - N)))

    if len(tl) == 0:
        cur = min(_, N - _)
    else:
        cur = int(1e9)

        posl = [[] for x in range(N)]
        for i, v in enumerate(tl): posl[v].append(i)

        y = 0
        for x in reversed(range(N)):
            cur = min(cur, x+2*y+min((_-x+N)%N,(x-_+N)%N), 2*x+y+min((y-(-_)+N)%N,((-_)-y+N+N)%N))
            for i in posl[x]:
                y = max(y, tr[i])

        posr = [[] for y in range(N)]
        for i, v in enumerate(tr): posr[v].append(i)

        x = 0
        for y in reversed(range(N)):
            cur = min(cur, x+2*y+min((_-x+N)%N,(x-_+N)%N), 2*x+y+min((y-(-_)+N)%N,((-_)-y+N+N)%N))
            for i in posr[y]:
                x = max(x, tl[i])

    cur += len(tl)
    ans = min(ans, cur)
    B = B[1:] + B[0]

print(ans)


Measured memory_bytes: 122588
import java.util.Scanner;

public class Main {

    public static void main (String [] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<s.length();i=i+2){
            sb.append(s.charAt(i));
        }
        System.out.println(sb.toString());

    }
}

Measured memory_bytes: 25384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	long long n,i,ans=1e15;
	cin>>n;
	for(i=1;i*i<=n;i++)
		if(n%i==0)
			ans=min(ans,i+n/i-2);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
    
from sys import stdin
    
n,x = [int(i) for i in stdin.readline().split()]
limit = int(x ** (1.0/n)) + 1
    
def devide_counter(x, p):
    count = 1
    x = x // p
    while x % p == 0:
        count += 1
        x = x // p
    return x, count
    
def factorize(x):
    ans = 1
    
    p = 2
    if x % p == 0:
        x, count = devide_counter(x, p)
        if count >= n:
            ans = ans * (p ** (count // n))
    
    for p in range(3, limit, 2):
        if x % p == 0:
            x, count = devide_counter(x, p)
            if count >= n:
                ans = ans * (p ** (count // n))
        if x < p * p:
            break
    return ans
    
if x == 1:
    print(1)
elif n == 1:
    print(x)
else:
    ans = factorize(x)
    print(ans)

Measured memory_bytes: 39152
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;

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

	int n, m, s, c;
	cin >> n >> m;
	string ans;
	if (n == 1) ans = "0";
	if (n == 2) ans = "10";
	if (n == 3) ans = "100";
	bool ok = true;
	set<int> st;
	for (int i = 0; i < m; ++i) {
		cin >> s >> c;
		int before = st.size();
		st.insert(s);
		int after = st.size();
		if (before == after && ans[s - 1] != c + '0') 
			ok = false;
		// Leading zero is unacceptable.
		if (n > 1 && c == 0) {
			if (s == 1) ok = false;
		}
		ans[s - 1] = c + '0';
	}
	if (ok) cout << ans;
	else cout << -1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, k, x, y; cin >> n >> k >> x >> y;
  if (n <= k) cout << x * n << endl;
  else cout << x*k + y*(n-k) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

const int Maxn = 110;
ll a[Maxn];
int n;

ll power_sum(int m){
    ll res = 0;
    REP(i,0,n) res += (m - a[i]) * (m - a[i]);
    return res;
}

int main(){
    cin >> n;
    ll sum = 0;
    REP(i,0,n){
        cin >> a[i];
        sum += a[i];
    }

    ll ans = min(power_sum(sum / n), power_sum((sum + n - 1) / n));

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

Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <typename T>
vector<vector<T>> alloc_double_vec(size_t rows, size_t cols, T init) {
    vector<vector<T>> ret;
    vector<T> ret_elem;
    ret_elem.resize(cols, init);
    ret.resize(rows, ret_elem);
    return ret;
}

int main() {
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    struct Item {
        int param;
        int cost;
    };
    vector<Item> items0;
    vector<Item> items1;
    vector<Item> items2;
    for (int i = 0; i < N; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        int param = b * Ma - a * Mb;
        if (param > 0) {
            items0.push_back(Item{param, c});
        } else if (param < 0) {
            items1.push_back(Item{-param, c});
        } else {
            items2.push_back(Item{param, c});
        }
    }
    int min_cost = numeric_limits<int>::max();
    for (auto item : items2) {
        min_cost = min(min_cost, item.cost);
    }
    vector<vector<int>> dp0 = alloc_double_vec(items0.size()+1, 40001, numeric_limits<int>::max());
    vector<vector<int>> dp1 = alloc_double_vec(items1.size()+1, 40001, numeric_limits<int>::max());
    // dpi[i][p] = インデックスi-1までの薬品を使用してパラメータの和をpにするための最小コスト
    using items_dp_t = pair<vector<Item>&, vector<vector<int>>&>;
    for (items_dp_t items_dp_pair : {items_dp_t(items0, dp0), items_dp_t(items1, dp1)}) {
        vector<Item>& items = items_dp_pair.first;
        vector<vector<int>>& dp = items_dp_pair.second;
        for (int i = 0; i < dp.size(); i++) {
            for (int p = 0; p < 40001; p++) {
                if (i == 0) {
                    if (p == 0) {
                        dp[i][p] = 0;
                    } else {
                        dp[i][p] = numeric_limits<int>::max();
                    }
                } else {
                    if (p-items[i-1].param >= 0) {
                        if (dp[i-1][p-items[i-1].param] == numeric_limits<int>::max()) {
                            dp[i][p] = dp[i-1][p];
                        } else {
                            dp[i][p] = min(dp[i-1][p], items[i-1].cost + dp[i-1][p-items[i-1].param]);
                        }
                    } else {
                        dp[i][p] = dp[i-1][p];
                    }
                }
            }
        }
    }
    for (int p = 1; p < 40001; p++) {
        if (dp0[items0.size()][p] == numeric_limits<int>::max() || dp1[items1.size()][p] == numeric_limits<int>::max()) {
            continue;
        }
        min_cost = min(min_cost, dp0[items0.size()][p] + dp1[items1.size()][p]);
    }
    if (min_cost == numeric_limits<int>::max()) {
        cout << -1 << endl;
    } else {
        cout << min_cost << endl;
    }
}


Measured memory_bytes: 7136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   int n, m;
   cin>>n>>m;
   vector<int> d(n, -1);
   bool ok=true;
   rep(_, m){
      int s, c;
      cin>>s>>c; s--;

      if(d[s]== -1 || d[s]==c) d[s]=c;
      else ok=false;
   }

   if(n>=2 && d[0]==0) ok=false;
   if(n>=2 && d[0]== -1) d[0]=1;

   int ans=0;
   if(ok){
      rep(i, n){
         ans*=10;
         if(d[i]!= -1) ans+=d[i];
      }
   }
   else ans= -1;

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


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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;}

const int INF = 100000; 

int main(){
    ll x, a, b;
    cin >> x >> a >> b;

    ll y = b - a;

    if(y <= 0){
        cout << "delicious" << endl;
    }else if(y <= x){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
S = str(input())

day = 0

if S == "SUN":
    day = 7
elif S == "MON":
    day = 6
elif S == "TUE":
    day = 5
elif S == "WED":
    day = 4
elif S == "THU":
    day = 3
elif S == "FRI":
    day = 2
else:
    day = 1
    
print(day)

Measured memory_bytes: 38480
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
lst=[list(map(int,input().split())) for i in range(N)]
lst.sort(key=lambda x: x[1])
ans=0
t=0
for i in range(N):
 t+=lst[i][0]
 if t>lst[i][1]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	if ((n - a.size()) % 2)
		cout << a.size() - 1 << endl;
	else
		cout << a.size() << endl;
	return 0;
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int A,B,C;
  int ans=3;
  cin >> A >> B >> C;
  if(A==B)
    ans--;
  if(B==C)
    ans--;
  if(C==A)
    ans--;
  if(ans==0){
    cout << 1 << endl;
  }
  else
    cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  int N,K;
  scanf("%d%d",&N,&K);

  long ans = 0;
  for(int b = K+1;b <= N;b++){
    int p = N/b;
    int r = N%b;
    ans += p*max(0,b-K)+max(0,r-K+1);
  }
  if(K == 0) ans -= N;

  printf("%ld\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
#include <complex>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)

typedef complex<double> P;
typedef pair<P, P> L;
const double EPS = 1e-8;

// see: https://github.com/infnty/acm/blob/master/lib/geometry/CircleTangents.java
vector<L> tangentLines(P a, double ar, P b, double br) {
  vector<L> ret;
  double d = abs(b-a);
  rep (i,2) {
    double sin = (ar - (1-i*2)*br) / d;
    if (sin*sin > 1 + EPS || sin != sin) break;
    double cos = sqrt(max(1 - sin*sin, 0.0));
    rep (j,2) {
      P n = (b-a) * P(sin, cos * (1-j*2)) / d;
      ret.push_back(L(a + ar*n, b + (1-i*2)*br*n));
      if (cos < EPS) break;
    }
  }
  return ret;
}

double dot(P a, P b) {
  return real(conj(a)*b);
}

P projection(L l, P p) {
  P a = l.second - l.first;
  p = p - l.first;
  double t = dot(a,p) / norm(a);
  return l.first + t*a;
}

double distanceLP(L l, P p) {
  return abs(projection(l, p) - p);
}

int n;

int getnum(vector<P> &c, vector<double>& r, vector<double>& m, L line) {
  int num = 0;
  rep(i,n) {
    double d = distanceLP(line, c[i]);
    if (r[i] < d + EPS && d < r[i] + m[i] + EPS) num++;
  }
  return num;
}

int main() {
  while (cin >> n, n) {
    vector<P> c(n);
    vector<double> r(n), m(n);
    rep (i,n) {
      int x, y;
      cin >> x >> y >> r[i] >> m[i];
      c[i] = P(x,y);
    }

    int ans = 1;
    rep(j,n) rep(i,j) rep(mi,2) rep(mj, 2) {
      vector<L> lines = tangentLines(c[i], r[i] + mi*m[i], c[j], r[j] + mj*m[j]);
      rep(k, lines.size()) ans = max(ans, getnum(c,r,m, lines[k]));
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1256
N=int(input())
a=list(map(int,input().split()))
two=0
four=0
out=0

for i in range(N):
    if a[i]%4==0:
        four=four+1
    elif a[i]%2==0:
        two=two+1
    else:
        out=out+1

if two%2!=0:
    out=out+1

if out<=four+1:
    print("Yes")
else:
    print("No")

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

int main() {
  string a, b;
  cin >> a >> b;
  int c = stoi(a + b);
  for (int i = 1; i < 317; i++) {
    if (i * i == c) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 200000
#define MD 18
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,X,Y,h1[MN+5],h2[MN+5],cnt=0,d1[MN+5],d2[MN+5],q[MN+5],top;
int nl[MN+5],nr[MN+5],dn=0,vis[MN+5],dep[MN+5],fa[MD+1][MN+5],flag,ans=0;
struct edge{int to,next;}e[MN*4+5];
inline void ins(int*H,int f,int t)
{
	e[++cnt]=(edge){t,H[f]};H[f]=cnt;
	e[++cnt]=(edge){f,H[t]};H[t]=cnt;	
}
void Bfs(int*d,int*head,int s)
{
	memset(vis,0,sizeof(vis));
	vis[q[top=1]=s]=1;
	for(int i=1;i<=top;++i)
		for(int j=head[q[i]];j;j=e[j].next)
			if(!vis[e[j].to]) vis[e[j].to]=1,d[q[++top]=e[j].to]=d[q[i]]+1;	
}
void Pre(int x,int f)
{
	fa[0][x]=f;nl[x]=++dn;
	for(int i=h2[x];i;i=e[i].next)
		if(e[i].to!=f) dep[e[i].to]=dep[x]+1,Pre(e[i].to,x);
	nr[x]=dn;
}
inline int GetUp(int x,int k)
{
	for(int j=0;k;k>>=1,++j) if(k&1) x=fa[j][x];
	return x;
}
inline int lca(int x,int y)
{
	if(dep[x]<dep[y]) swap(x,y);
	x=GetUp(x,dep[x]-dep[y]);
	if(x==y) return x;
	for(int i=MD;~i;--i) if(fa[i][x]!=fa[i][y]) x=fa[i][x],y=fa[i][y];
	return fa[0][x];
}
inline int dis(int x,int y){return dep[x]+dep[y]-2*dep[lca(x,y)];}
inline int Move(int x,int y)
{
	if(x==y) return x;
	if(nl[y]>=nl[x]&&nl[y]<=nr[x]) return GetUp(y,dep[y]-dep[x]-1);
	else return fa[0][x];
}
void dfs(int x,int fa,int oth)
{
	ans=max(ans,d1[x]+dis(x,oth));
	if(x==oth) return;
	for(int i=h1[x];i;i=e[i].next)
		if(dis(e[i].to,x)>2) flag=1;
	for(int i=h1[x];i;i=e[i].next)
		if(e[i].to!=fa&&e[i].to!=oth) dfs(e[i].to,x,Move(oth,e[i].to));
}
int main()
{
	n=read();X=read();Y=read();
	for(int i=1;i<n;++i) ins(h1,read(),read());
	for(int i=1;i<n;++i) ins(h2,read(),read());
	Bfs(d1,h1,X);Bfs(d2,h2,Y);Pre(Y,0);
	for(int i=1;i<=MD;++i) for(int j=1;j<=n;++j) fa[i][j]=fa[i-1][fa[i-1][j]];
	dfs(X,0,Y);
	if(flag) puts("-1");
	else printf("%d\n",ans*2);
	return 0;
}



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

using namespace std;

#define ALL(x) x.begin(), x.end()

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

const int maxn = 1e5 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(15);
	cout << fixed;

	int n, m;
	cin >> n >> m;

	vector<pii> vec(n);

	for (int i = 0; i < n; i++)
		cin >> vec[i].first >> vec[i].second;

	sort(ALL(vec));

	priority_queue<int> pq;
	int pos = 0, ans = 0;

	for (int i = 1; i <= m; i++) {
		for (; vec[pos].first <= i; pos++) {
			pq.push(vec[pos].second);
		}

		if (pq.empty())
			continue;

		ans += pq.top();
		pq.pop();	
	}

	cout << ans << '\n';



	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

int main() {
  int n,c,k;
  cin >> n >> c >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());

  int lim = a[0]+k; // departure time
  int cnt = 1; //bus noru hito
  int ans = 1;
  rep(i,n-1){
    if(a[i+1]>lim || cnt==c){
      ans++;
      lim = a[i+1]+k;
      cnt = 1;
    } else {
      cnt++;
    }
  }

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

Measured memory_bytes: 768
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
F=int(input())

S=[]
S.append(A)
S.append(B)
S.append(C)
S.append(D)

S.remove(min(S))

T=[]
T.append(E)
T.append(F)

T.remove(min(T))

P=S+T

U=sum(P)
print(U)


Measured memory_bytes: 5592
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
	string a, b;
	cin >> a >> b;

	if (a == b) cout << "=" << endl;
	else if (a > b) cout << ">" << endl;
	else cout << "<" << endl;
}


Measured memory_bytes: 3612
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end()))
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

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

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int popcount(ll n) {
  int ret = 0;
  while (n > 0) {
    if (n & 1) ret++;
    n >>= 1;
  }
  return ret;
}

// 要考慮
// - 最初からk色以上見えてる場合

void solve() {
  ll n, k; cin >> n >> k;
  vector<ll> a(n); rep(i, n) cin >> a[i];
  vector<ll> b(n);

  ll ans = INF;
  rep(i, 1<<n) {
    // 一番左の人を見えなくするのは無理
    if ((i & 1) == 0) continue;

    // k色見えないのでダメ
    if (popcount(i) < k) continue;

    copy(all(a), b.begin());
    ll maxh = b[0], view = 1, cost = 0;
    bool ok = true;
    for (int j = 1; j < n; j++) {
      // 今見てる建物を見えるようにすべきか
      bool b1 = ((i >> j) & 1) == 1;
      // 今見てる建物は左から見えるのか
      bool b2 = b[j] > maxh;

      if (b1 && b2) {
        // もう見えてるのでOK
        view++;
      } else if (b1 && !b2) {
        // 見えるようにする
        cost += maxh + 1 - b[j];
        b[j] = maxh + 1;
        view++;
      } else if (!b1 && b2) {
        // 見せたくないのに見えてる
        // 前の建物を高くするよりないけど無駄なのでスキップ
        ok = false;
        break;
      } else {
        // 見せたくないし、見えてないからOK
      }

      maxh = max(maxh, b[j]);
    }

    if (!ok) continue;

    // debug3(i, view, cost);

    ans = min(ans, cost);
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int N = scanner.nextInt();

        int[] count = new int[N + 1];

        for (int i = 2 ; i <= N ; i++) {
            int boss = scanner.nextInt();
            count[boss]++;
        }


        for (int i = 1; i <= N ; i++) {
            System.out.println(count[i]);
        }
    }
}


Measured memory_bytes: 69524
#include<iostream> 
using namespace std; 
int n,m,x,y,a,robot,flg; 
string moji; 
void change(){ 
  if(moji=="LEFT"){ 
    robot+=3; 
    robot%=4; 
  }else{ 
    robot++; 
    robot%=4; 
  } 
} 
void walk(int a,int z){ 
  //  int cy=y,cx=x; 
  if(robot%4==0)y+=a*z; 
  if(robot%4==1)x+=a*z; 
  if(robot%4==2)y-=a*z; 
  if(robot%4==3)x-=a*z; 
  if(y>m)y=m; 
  if(y<1)y=1; 
  if(x>n)x=n; 
  if(x<1)x=1; 
} 
int main(){ 
  while(1){ 
    cin>>n>>m; 
    if(n==0&&m==0)break; 
    x=y=1;robot=0; 
    while(1){ 
      cin>>moji; 
      if(moji=="FORWARD"){ 
    cin>>a; 
    walk(a,1); 
      }else if(moji=="BACKWARD"){ 
    cin>>a; 
    walk(a,-1); 
      }else if(moji=="STOP"){ 
    break; 
      }else{ 
    change(); 
      } 
    } 
    cout<<x<<' '<<y<<endl;  
  } 
  return 0; 
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int N; cin >> N;
    vector<Int> A(N), B(N), diff(N);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];

    Int res = 0, negSum = 0, posSum = 0;
    rep(i, 0, N) {
        diff[i] = A[i]-B[i];
        if (diff[i] < 0) { ++res; negSum += -diff[i]; }
        if (diff[i] > 0) posSum += diff[i];
    }

    if (negSum > posSum) { cout << -1 << endl; return 0; }
    if (negSum == 0) { cout << 0 << endl; return 0; }

    sort(diff.begin(), diff.end(), greater<Int>());
    rep(i, 0, N) {
        negSum -= diff[i];
        ++res;
        if (negSum <= 0) break;
    }

    cout << res << endl;
}


Measured memory_bytes: 2560
from collections import deque
import sys
input = sys.stdin.readline


n = int(input())
edges = [[] for i in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

todo = deque([(0, 1), (n-1, 2)])

colors = [0] * n
colors[0] = 1
colors[-1] = 2

while todo:
    node, color = todo.popleft()
    for to in edges[node]:
        if colors[to]:
            continue
        else:
            colors[to] = color
            todo.append((to, color))

fennec_count = colors.count(1)
if fennec_count > n // 2:
    print('Fennec ')

else:
    print('Snuke ')


Measured memory_bytes: 23444
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <tuple>
#include <limits>

using namespace std;

int main() {
    int r;
    cin >> r;

    cout << 3*r*r<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define mod 100000
#define rep(i,n)for(int i=0;i<n;i++)
int dp[17712][20][20];
int x,y;
char map[20][20];
int mask;
short check[1<<20];
int solve(int place,int bit) {
	int res;
	int nx,ny;
	if(place==x*y)return 1;
	nx=place%x;
	ny=place/x;
	res=dp[(int)check[bit]][nx][ny];
	if(res!=-1)return res;
	res=0;
	if(map[nx][ny]=='?'||map[nx][ny]=='J') {
		int nextbit=bit;
		if(nextbit&1) {
			nextbit=((nextbit-1)<<1)|1;
		}else {
			nextbit=(nextbit<<1)|1;
		}
		nextbit&=mask;
		res+=solve(place+1,nextbit);
		res%=mod;
	}
	if(map[nx][ny]=='?'||map[nx][ny]=='O') {
		int nextbit=bit;
		nextbit<<=1;
		nextbit&=mask;
		res+=solve(place+1,nextbit);
		res%=mod;
	}
	if(map[nx][ny]=='?'||map[nx][ny]=='I') {
		if(((1<<(x-1))&bit)==0||nx==x-1) {
			int nextbit=bit;
			if(nextbit&1) {
				nextbit=(nextbit-1)<<1;
			}else {
				nextbit<<=1;
			}
			nextbit&=mask;
			res+=solve(place+1,nextbit);
			res%=mod;
		}
	}
	return dp[(int)check[bit]][nx][ny]=res;
}
int main() {
	scanf("%d %d",&y,&x);
	int sum=1;
	rep(i,y) {
		getchar();
		rep(j,x) {
			map[j][i]=getchar();
			if(map[j][i]=='?')sum=(sum*3)%mod;
		}
	}
	memset(check,-1,sizeof(check));
	int idx=0;
	rep(i,1<<x) {
		int temp=i<<1;
		while(temp!=0) {
			if((temp>>1)&1&&(temp>>2)&1)break;
			temp>>=1;
		}
		if(temp==0)check[i]=idx++;
	}
	mask=(1<<x)-1;
	memset(dp,-1,sizeof(dp));
	int ans=solve(0,0);
	printf("%d\n",(sum-ans+mod)%mod);
}

Measured memory_bytes: 30784
#include<bits/stdc++.h>
#define     FAST            ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
#define ll long long
using namespace std;
int main()
{
    FAST;

    string s;
    cin>>s;

    ll sm=0;
    for(int i=0;i<s.size();i++)
    {
        sm+=(s[i]-'0');
    }

    //cout<<sm<<endl;


    if(sm%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

















    return 0;
}


Measured memory_bytes: 3700
import scala.collection.mutable._
object Main extends App {
  val N = Scanner.nextInt // |V|
  val M = Scanner.nextInt // |E|
  val G = Array.tabulate(N)(from => (from, ArrayBuffer.empty[(Int, Long)])) // [(from, [(to, weight)])]
  val V = Array.fill(N)(Long.MinValue / 2L); V(0) = 0L
  (0 until M).foreach(i => G(Scanner.nextInt - 1)._2 += ((Scanner.nextInt - 1, Scanner.nextLong)))
  for {
    _ <- 0 until N
    n <- G // (from, [(to, weight)])
    e <- n._2 // (to, weight)
  } {
    if (V(e._1) < V(n._1) + e._2) V(e._1) = V(n._1) + e._2
  }
  for {
    _ <- 0 to N
    n <- G // (from, [(to, weight)])
    e <- n._2 // (to, weight)
  } {
    if (V(e._1) < V(n._1) + e._2) {
      V(e._1) = V(n._1) + e._2
      if (e._1 == V.size - 1) {
        println("inf")
        sys.exit
      }
    }
  }
  println(V.last)
}

object Scanner {
  private val buf = new Array[Byte](1024)
  private var ptr = 0
  private var len = 0

  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte: Boolean = if (ptr >= len) {
      ptr = 0
      len = System.in.read(buf)
      len > 0
    } else {
      true
    }
  @inline private def hasNext: Boolean = {
    while (hasNextByte && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte
  }
  @inline private def readByte: Byte = {
    if (hasNextByte) {
      val res = buf(ptr)
      ptr += 1
      res
    } else {
      -1
    }
  }

  def next: String = {
    if(!hasNext) ???
    val sb = new StringBuilder
    var b = readByte
    while (isPrintableChar(b)) {
      sb.append(b.toChar)
      b = readByte
    }
    sb.toString
  }
  def nextInt: Int = {
    val n = nextLong
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong: Long = {
    if(!hasNext) ???
    var minus = false
    var b = readByte
    if (b == '-') {
      minus = true
      b = readByte
    }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') go(readByte, n * 10 + b - '0')
      else if (minus) -n
      else n
    go(b)
  }
  def nextDouble: Double = next.toDouble
}

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

using namespace std;
int main() {
  int H, N;
  cin >> H;
  cin >> N;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    sum += tmp;
  }
  if (H <= sum) {
    cout << "Yes" << std::endl;
  } else {
    cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
A = [input()[0] for i in range(n)]

A = Counter(A)
m = A['M']
a = A['A']
r = A['R']
c = A['C']
h = A['H']

print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h)

Measured memory_bytes: 4224
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

char x, y;

char solve() {
    if (x < y) return '<';
    if (x > y) return '>';
    return '=';
}

void input() {
    cin >> x >> y;
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

W,H,x,y = map(int,input().split())
area = W*H/2
if x == W/2 and y == H/2:
    cnt = 1
else:
    cnt = 0

print(area,cnt)


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

int main() {
  int H,W;
  cin >> H >> W;
  
  vector<vector<char>> a(H, vector<char>(W));
  rep(i,H){
    rep(j,W){
      cin >> a.at(i).at(j);
    }
  }
  
  vector<bool> row(H,false);
  vector<bool> column(W,false);
  
  rep(i,H){
    rep(j,W){
      if (a.at(i).at(j) == '#') row.at(i) = true;
    }
  }
  
  rep(j,W){
    rep(i,H){
      if (a.at(i).at(j) == '#') column.at(j) = true;
    }
  }
  
  rep(i,H){
    if (!row.at(i)) continue;
    rep(j,W){
      if (column.at(j)) cout << a.at(i).at(j);
    }
    cout << endl;
  }

}


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


def solve(A: int, B: int, C: int):
    print(max(C-(A-B),0))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, a;
    cin >> n >> a;

    if(n % 500 <= a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {

        new Main().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Main() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws IOException {

        int t = 1;
        while (t > 0) {
            solve();
            //out.println();
            t--;
        }

        out.flush();
        out.close();
    }

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    //ArrayList<Integer>[] g = new ArrayList[1000000];

    HashMap<Integer, Integer> map = new HashMap<>();

    void solve() throws IOException {
        
        int x = in.nextInt();
        int y = in.nextInt();
        
        if (x%y==0)
            out.println(-1);
        else
            out.println(x);
        
    }


    class Pair implements Comparable<Pair>{

        int a;
        int b;

        Pair(int a, int b) {

            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {

            if (a > p.a) return 1;
            if (a < p.a) return -1;
            if (b > p.b) return 1;
            if (b < p.b) return -1;
            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }


        String nextLine() throws IOException {
            return br.readLine();
        }

    }

}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define fast_io ios::sync_with_stdio(false);cin.tie(NULL);
#define input freopen("Test.txt","r",stdin)
#define output freopen("Output.txt","w",stdout);
#define what_is(x) cout<<#x<<" is "<<x<<endl;
#define F(i,a,b) for(int i = a; i < b; i++)
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define inf 1000000000
const double pi = 3.141592653589793238460;
#define debug false
#define MAXN 100010
#define mod 1000000007


void solve()
{
    int N; cin>>N;
    if(N%2==1)
        cout<<(N/2)+1<<"\n";
    else cout<<N/2<<"\n";
}

int main()
{
     // input; // output; // if(debug){watch_is();}
    fast_io;
    solve();   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }

const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_C = 60;
ll Com[MAX_C][MAX_C];

void calc_com() {
    memset(Com, 0, sizeof(Com));
    Com[0][0] = 1;
    for (int i = 1; i < MAX_C; ++i) {
        Com[i][0] = 1;
        for (int j = 1; j < MAX_C; ++j) {
            Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]);
        }
    }
}
 
int main() {
  calc_com();
  ll n,a,b;
  cin >> n >> a >> b;
  vl v(n);
  rep(i,n) cin >> v[i];
  sort(ALL(v));
  ll num = v[n-a];
  ll sum = 0;
  for(ll i = n-a; i<n; i++){
    sum += v[i];
  }
  double s,A;
  s = (double)sum;
  A = (double)a;
  double x = s/A;
  cout << setprecision(10) << x << endl;
  ll cnt1 = 0, cnt2 = 0;
  rep(i,n){
    if(v[i] == num) cnt1++;
    if(v[i] > num) cnt2++;
  }
  if(cnt1 == 1){
    cout << 1;
    return 0;
  }
  ll ans = 0;
  if(num == v[n-1]){
  for(ll i=a; i<=b; i++){
    ans += Com[cnt1][i];
  }
  } else {
    ans = Com[cnt1][a-cnt2];
  }
  cout << ans;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    double d;
    cin >> d;
    double t;
    cin >> t;
    double s;
    cin >> s;
    if ((d / s) > t)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
  int n;
  vector<int> l;
  cin >> n;
  int tmp;
  for(int i = 0; i < n; i++){
     cin >> tmp;
     l.push_back(tmp);
  }
  sort(l.begin(), l.end());
  int max = l[n-1];
  l.pop_back();
  int sum = accumulate(l.begin(), l.end(), 0);
  if(max < sum) cout << "Yes" <<endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
const int N = 100;
const int INFTY = (1<<21);
using namespace std;
int n,M[N][N],d[N];
void bfs(int u){
    queue<int> q;
    q.push(u);
    for(int i=0;i<n;i++) d[i] = INFTY;
    d[u] = 0;
    while(!q.empty()){
        int m = q.front();
        q.pop();
        for(int i=0;i<n;i++){
            if(M[m][i]&&d[i]==INFTY){
                d[i] = d[m] + 1;
                q.push(i);
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<i+1<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int u,k,v;
		scanf("%d%d",&u,&k);
		while(k--){
			scanf("%d",&v);
			M[u-1][v-1] = 1;
		}
	}
	bfs(0);
	return 0;
}


Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    bool flag = false;
    for(int i = 1; i < s.size(); i++)
    {
        if(s[i] == s[i - 1]) flag = true;
    }
    if(flag) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}



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

using namespace std;

int findDivisors(int k)
{
  int ans=0;
  for(int i=1; i<=sqrt(k); i++)
  {
    if(k%i==0)
      ans++;
  }
  if(sqrt(k) == floor(sqrt(k)))
    return 2*ans+1;
  return 2*ans;
}

int main()
{
 	int N, result=0;
  	cin >> N;
  	for(int i=1; i<=N; i+=2)
    {
      if(findDivisors(i) == 8)
        result++;
    }

   //cout << findDivisors(105) << endl;
  	cout << result;
  	return 0;
}


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

int dp[2][1 << 20];
char s[21][21];
int main() {
	int m, n; scanf("%d%d", &m, &n);
	int cnt = 1;
	rep(i, m)scanf("%s", s[i]);
	rep(i, m)rep(j, n) {
		if (s[i][j] == '?')cnt = (cnt * 3) % MOD;
	}
	int*now = dp[0], *nxt = dp[1];
	now[0] = 1;
	rep(i, m)rep(j, n) {
		fill(nxt, nxt + (1 << n), 0);
		rep(k, 1 << n) {
			if (now[k] == 0)continue;
			int a = k&~(1 << (j - 1));
			if (s[i][j] == 'J' || s[i][j] == '?') {
				if (j < n - 1)(nxt[a | 1 << j] += now[k]) %= MOD;
				else(nxt[a&~(1 << j)] += now[k]) %= MOD;
			}
			if (s[i][j] == 'O' || s[i][j] == '?')
				(nxt[k&~(1 << j)] += now[k]) %= MOD;
			if (s[i][j] == 'I' || s[i][j] == '?') {
				if (!(k >> j & 1))(nxt[a&~(1 << j)] += now[k]) %= MOD;
			}
		}
		swap(now, nxt);
	}
	rep(i, 1 << n)cnt = (cnt + MOD - now[i]) % MOD;
	printf("%d\n", cnt);
}

Measured memory_bytes: 11392
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  vector<bool> v(8);
  int col[] = { 1, 399, 400, 799, 800, 1199, 1200, 1599, 1600, 1999, 2000, 2399, 2400, 2799, 2800, 3199, 3200 };
  int s = 0;
  for (int i = 0; i < n; i++) {
	cin >> a[i];
	if (a[i] <= 399) {
	  v[0] = true;
	}
	else if (a[i] <= 799) {
	  v[1] = true;
	}
	else if (a[i] <= 1199) {
	  v[2] = true;
	}
	else if (a[i] <= 1599) {
	  v[3] = true;
	}
	else if (a[i] <= 1999) {
	  v[4] = true;
	}
	else if (a[i] <= 2399) {
	  v[5] = true;
	}
	else if (a[i] <= 2799) {
	  v[6] = true;
	}
	else if (a[i] <= 3199) {
	  v[7] = true;
	}
	else {
	  s++;
	}
  }

  int minim = 0, maxim = 0;
  for (int i = 0; i < 8; i++) {
	if (v[i]) {
	  minim++;
	}
  }
  if (minim != 0) {
	cout << minim << " " << minim + s << endl;

  }
  else {
	cout << 1 << " " << s << endl;
  }


	return 0;
}



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

int main(){
	int n,k;
	cin >> n >> k;
	priority_queue<int> q;
	rep(i,n){
		int l;
		cin >> l;
		q.push(l);
	}
	int ans = 0;
	rep(i,k){
		ans += q.top();
		q.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}


int main(void){
	VI S = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << S[K-1] << endl;
    return 0;
}


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

ll f(ll n, ll k){
	if(n == 0){
		return 0;
	} else {
		return 1 + f(n/k, k);
	}
}

int main(void){
	ll n, k;
	cin >> n >> k;
	cout << f(n, k) << endl;
	return 0;
}


Measured memory_bytes: 3544