akhauriyash/Code-Regression huggingface dataset:
from math import ceil
h, w = map(int, input().split())

a = ceil(w/2)
b = w - a

if h == 1 or w == 1:
    print(1)
    exit()
    
if h%2 == 0:
    ans = a*h//2 + b*h//2
    print(ans)

else:
    ans = a*(h//2) + b*(h//2) + a
    print(ans)
    


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

int main() { 
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i= 0; i < N; i++) cin >> A[i];

    int next = 1;
    for (int a : A) {
        if (a == next) next++;
    }
  
    if (next == 1) {
        cout << -1 << endl;
        return 0;
    }
    cout << N - (next -1) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

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

int main(){

  int h, w;
  cin >> h >> w;
  vector<vector<string>> vec(h+2, vector<string>(w+2));
  for (int i = 0; i < h+2; i++) {
    for (int j = 0; j < w+2; j++) {
      vec.at(i).at(j) = "#";
    }
  }

  string s;
  for (int i = 1; i < h+1; i++) {
    cin >> s;
    for (int j = 1; j < w+1; j++) {
      vec.at(i).at(j) = s[j-1];
    }
  }

  // 処理
  for (int i = 1; i < h+1; i++) {
    for (int j = 1; j < w+1; j++) {
      if(vec.at(i).at(j) == "#"){
        // if(vec.at(i-1).at(j) == "#")  break;
        // if(vec.at(i).at(j-1) == "#")  break;
        // if(vec.at(i).at(j+1) == "#")  break;
        // if(vec.at(i+1).at(j) == "#")  break;
        if(vec.at(i-1).at(j) != "#" && vec.at(i).at(j-1) != "#" && vec.at(i).at(j+1) != "#" && vec.at(i+1).at(j) != "#"){
          cout << "No" << endl;
          return 0;
        }
      }
      // cout << vec.at(i).at(j) << " ";
    }
    // cout << endl;
  }

  cout << "Yes" << endl;

  // // 【確認用】
  // // 全体
  // for (int i = 0; i < h+2; i++) {
  //   for (int j = 0; j < w+2; j++) {
  //     cout << vec.at(i).at(j) << " ";
  //   }
  //   cout << endl;
  // }

  // cout << " " << endl;

  // // 該当のみ
  // for (int i = 1; i < h+1; i++) {
  //   for (int j = 1; j < w+1; j++) {
  //     cout << vec.at(i).at(j) << "";
  //   }
  //   cout << endl;
  // }

  return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<long long> v){
  priority_queue<long double,vector<long double>,greater<long double>> q;
  REP(N)q.push((long double)v[i]);
  while(q.size()>1){
    long double s=q.top();q.pop();
    long double t=q.top();q.pop();
    q.push((s+t)/2.0l);
  }
  cout<<setprecision(10)<< q.top()<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> v(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&v[i]);
    }
    solve(N, std::move(v));
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s >> t;
    if (s + t.back() == t)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;

bool check[101];

int main(void)
{
	int x, n, temp, ans;
	scanf("%d %d", &x, &n);
	if (n == 0)
		printf("%d\n", x);
	else
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &temp);
			check[temp] = true;
		}
		temp = x;
		while (temp <= 100)
		{
			if (!check[temp])
				break;
			temp++;
		}
		ans = temp;
		temp = x;
		while (temp >= 0)
		{
			if (!check[temp])
				break;
			temp--;
		}
		if (ans - x >= x - temp)
			ans = temp;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int b,c,i,j,a,d;
    cin>>a>>b;
    c=ceil(a/0.08);
    d=ceil(b/0.1);
    if(floor(c*0.08)==a && floor(c*0.1)==b)
        cout<<c<<endl;
    else if(floor(d*0.08)==a && floor(d*0.1)==b)
        cout<<d<<endl;
    else
        cout<<"-1"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <random>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;

ll n, k;
vector<ll> ans;

void dfs(ll now, ll prev, ll d) {
  if (d == 11) {
    return;
  }
  ans.push_back(now);
  if (prev > 0) {
    dfs(now*10+prev - 1, prev - 1, d + 1);
  }
  dfs(now*10+prev,prev,d+1);
  if (prev < 9) {
    dfs(now*10+prev + 1, prev + 1, d + 1);
  }
}

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

  for(int i = 1; i < 10; ++i) {
    dfs(i, i, 0);
  }
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  cout << ans[k - 1];
  return 0;
}



Measured memory_bytes: 10604
#define _CRT_SECURE_NO_WARNINGS
#define MOD 998244353 
#define INF 100000000
//#define MOD 922337203685419LL
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>
#include <cstdio>
#include <utility>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <chrono>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n-1,-1)
#define ALL(obj) (obj).begin(), (obj).end()

inline ll madd(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a + b) % MOD;
}
inline ll msub(ll a, ll b) {
	a %= MOD;b %= MOD;
	a += MOD;
	return (a - b) % MOD;
}
inline ll mmul(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a*b) % MOD;
}
inline ll mpow(ll a, ll r) {
	long long res = 1;
	while (r > 0) {
		if (r & 1) res = res * a % MOD;
		a = a * a % MOD;
		r >>= 1;
	}
	return res;
}
inline ll minv(ll a) {
	a %= MOD;
	ll b = MOD, u = 0, v = 1;
	while (a) {
		ll t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	if (u < 0) u += MOD;
	return u;
}
inline ll mdiv(ll a, ll b) {
	a %= MOD;
	a *= minv(b);
	return a%MOD;
}


//ll fact[]
//inline ll combi(int a, int b) {
//	return mmul(fact[a], mmul(fact_inv[b], fact_inv[a - b]));
//}

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	ll n, d, a, x ,h;
	cin >> n >> d >> a;
	vector<pll> v;
	vll vv;
	REP(i, n) {
		cin >> x >> h;
		if (h%a == 0) h = h / a;
		else h = h / a + 1;
		v.push_back(pll(x, h));
		vv.push_back(x);
	}
	sort(v.begin(), v.end());
	sort(vv.begin(), vv.end());
	ll res = v[0].second;
	map<ll, ll> mp;
	mp[upper_bound(vv.begin(), vv.end(), v[0].first + d * 2)-vv.begin()] = v[0].second;
	ll now = v[0].second;
	ll nowind = 1;
	if (n == 1) {
		cout << res;
		return 0;
	}
	while (true) {
		if (mp.count(nowind)) now -= mp[nowind];
		if (v[nowind].second - now > 0) {
			res += v[nowind].second - now;
			if(!mp.count(upper_bound(vv.begin(), vv.end(), v[nowind].first + d * 2)-vv.begin())) mp[upper_bound(vv.begin(), vv.end(), v[nowind].first + d * 2)-vv.begin()] = v[nowind].second-now;
			else mp[upper_bound(vv.begin(), vv.end(), v[nowind].first + d * 2)-vv.begin()] += v[nowind].second-now;
			now += v[nowind].second - now;
		}
		nowind++;
		if (nowind == n) {
			break;
		}
	}
	cout << res;
	return 0;
}
	

Measured memory_bytes: 18412
def push(stack, item)
  stack << item
end
def pop(stack)
  item = stack[-1]
  stack.delete_at(-1)
  item
end
stack = []
input = gets.split
input.each do |item|
  case item
  when "+"
    b = pop(stack)
    a = pop(stack)
    push(stack, a+b)
  when "-"
    b = pop(stack)
    a = pop(stack)
    push(stack, a-b)
  when "*"
    b = pop(stack)
    a = pop(stack)
    push(stack, a*b)
  else
    push(stack, item.to_i)
  end
end
puts stack[0]



Measured memory_bytes: 6868
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;
//const ll INF = (ll)1e18 + 1;

int main(){
  string S; cin >> S;
  S[3] = '8';
  cout << S << endl;
}


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

int main(){
    int N;
    cin >> N;
    int ans=N%10;
    if(ans==2 or ans==4 or ans==5 or ans==7 or ans==9){
        cout<< "hon"<<endl;return 0;
    }else if(ans ==0 or ans==1 or ans==6 or ans==8){
        cout<< "pon"<<endl;return 0;
    }else if(ans==3){
        cout << "bon" <<endl;return 0;
    }
}

Measured memory_bytes: 3624
def msb(x)Math.log2(x).to_i;end
def cnt(x)x.to_s(2).count(?1);end
def p(*a)puts a.join" ";end
l=gets.to_i
n=msb(l)
m=n*2+cnt(l)-1
p n+1,m
n.times{|i|p i+1,i+2,0;p i+1,i+2,1<<i}
k=l^(1<<n)
while(k>0)
  j=msb(k)
  p j+1,n+1,l-k
  k^=1<<j
end

Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")  
#include<bits/stdc++.h>
using namespace std;

#define ll 				long long
#define eb 				emplace_back
const long long 		MOD = 1e9 + 7;
#define rep(i,n) 		for (int (i) = 0; (i) < (n); (i)++) 
#define REP(i,k,n)  	for (int (i) = (k); (i) <= (n); (i)++) 
#define REPR(i,k,n) 	for (int (i) = (k); (i) >= (n); (i)--)
#define watch(x) 		cout << (#x) << " = " << (x) << endl
#define t(x)			int x; cin >> x; while(x--)

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	
	/*---- continue Coding ;----*/

	string s;
	cin >> s;
	int len = s.length()-1;
	if(s[len] == 's'){
		s += "es";
	}else{
		s += "s";
	}
	cout << s << "\n";
	
	/*---- break ;----*/

	cerr<<"Execution time: "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
	return 0;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll inf=1e18;
const ll maxs = 201;
const ll mod = 1e9+7;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define line() cout<<endl;
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

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


int main()
{
    fastio();
    
     ll t=1;
     //cin>>t;
     while(t--)
     {
         ll x,a;
         cin>>x>>a;
         
         if(x<a)
            cout<<0;
         else
          cout<<10;
     }
    
    return 0;
}



Measured memory_bytes: 256
int main(){
  long long int n,a,b,c;
  long double d;
  scanf("%lld",&n);
  d=sqrt(n);
  a=(int)d;
  for(int i=a;i>=0;i--){
    if(n%i==0){
      b=i;
      c=n/i;
      i=0;
    }
  }
  printf("%lld\n",b+c-2);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int i;
	int len;
	int c_count = 0;
	string input;
	cin >> input;
	len = input.size();
	
	if (input[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}

	if (input[1] >= 'A' &&
		input[1] <= 'Z') {
		cout << "WA" << endl;
		return 0;
	}

	for (i = 2; i < len - 1; i++) {
		if (input[i] == 'C') {
			c_count++;
		} else if (input[i] >= 'A' &&
				   input[i] <= 'Z') {
			c_count += 2;
		}
	}
	
	if (c_count != 1) {
		cout << "WA" << endl;
		return 0;
	}

	if (input[len - 1] >= 'A' &&
		input[len - 1] <= 'Z') {
		cout << "WA" << endl;
	} else {
		cout << "AC" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc153d()
}

fun abc153d() {
    val h = readLine()!!.toLong()

    var mons = 1L
    var hp = h
    var answer = 0L
    while (true) {
        answer += mons
        if (hp == 1L) break
        mons *= 2
        hp /= 2
    }

    println(answer)
}


Measured memory_bytes: 31828
// In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
const ll mod = 1e9 + 7;
 
 
void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const ll M = 400 + 10;
const ll N = 40 * 100 + 10;


int main()
{
	faster();
	string s;
	int k;
	cin >> s >> k;
	for (int i = 0; i < s.size(); i++)
	{
		int t = s[i] - 'a';
		if(s[i] == 'a')
			continue;
		if(t + k >= 26)
		{
			s[i] = 'a';
			k -= 26;
			k += t;
		}
	}
	s.back() = ((s.back() - 'a') + (k % 26)) % 26 + 'a';
	cout << s << endl;
}

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

int main()
{

	int a,b;

	cin >> a >> b;

	if (a - b > 0) {
		cout << a - b << endl;
	}

	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>		
using namespace std;
typedef long long ll;
int a[100000];
int main()
{
	int x, n;
	scanf("%d %d", &x, &n);
	for (int i = 1; i <= x; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + x + 1);	int c=0;
	for (int i = 1; i <= n; i++) {
	
		c += a[i];
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N; cin >> N;
    vector<pair<int,int>> A(N);
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        A[i] = make_pair(a,i+1);
    }
    sort(A.begin(),A.end());
    for(int i = 0; i < N; i++){
        cout << A[i].second;
        if(i != N-1) cout << " ";
        else cout << endl;
    }
}

Measured memory_bytes: 1536
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> p_num(51, 0);
    vector<ll> t_num(51, 0);
    p_num[0] = 1;
    t_num[0] = 1;
    for (int i = 1; i <= 50; ++i) {
        p_num[i] = p_num[i-1] * 2 + 1;
        t_num[i] = t_num[i-1] * 2 + 3;
    }
    int idx = n;
    ll ans = 0;
    //cout << idx << " " << x << endl;
    while(1) {
        //if (x == 0 || idx < 0) break;
        if (x == 0) break;
        //cout << t_num[idx] << endl;
        if (x == t_num[idx]) {
            ans += p_num[idx];
            break;
        }
        if (x == t_num[idx] / 2LL + 1LL) {
            ans += p_num[idx-1] + 1LL;
            break;
        }
        else if (x > t_num[idx] / 2LL + 1LL) {
            ans += p_num[idx-1] + 1LL;
            x -= t_num[idx-1] + 2LL;
        }
        else {
            //cout << "test" << endl;
            x -= 1LL;
        }
        --idx;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int count=0; int height=h[0];
    int max_count=0;
    for(int i=1; i<n; i++){
        if(height>=h[i]){
            count++; height = h[i];
        }else{
            if(count>max_count)
                max_count = count;
            count =0 ;
            height = h[i];
        }
    }
    if(count > max_count)
        max_count = count;
    cout << max_count << endl;

    return 0;
}


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

int main(){
  int a,b,c,d,e;
  cin >> a;
  b = a/1000;
  c = (a%1000)/100;
  d = (a%100)/10;
  e = a%10;
  if ((b==c&&c==d)||(c==d&&c==e))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

list_n=[]
for i in range(1,N+1):
    list_n.append(i)
    
t=[]
for i in range(K):
    d=int(input())
    s=list(map(int,input().split()))
    t+=s
    
s=list(set(t))
s.sort()

cnt=0
for i in list_n:
    if i not in s:
        cnt+=1
        
print(cnt)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=610;
const int mod=1e9+7;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,m=0,a[N],f[N][310][310],type[N];
int main() {
    n=gi()<<1;
    for(int i=1;i<=n;i++) a[i]=gi();
    for(int i=1;i<=n;i+=2) {
        if(~a[i]&&~a[i+1]) type[a[i]]=type[a[i+1]]=2;
        else if(~a[i]) type[a[i]]=1;
        else if(~a[i+1]) type[a[i+1]]=1;
        else ++m;
    }
    f[n+1][0][0]=1;
    for(int i=n;i;i--) {
        for(int j=0;j<=min(i,n/2);j++)
            for(int k=0;k<=min(i,n/2);k++) {
                if(type[i]==0) {
                    if(j) f[i][j][k]=f[i+1][j-1][k];
                    inc(f[i][j][k],f[i+1][j+1][k]);
                    inc(f[i][j][k],1ll*f[i+1][j][k+1]*(k+1)%mod);
                }
                else if(type[i]==1) {
                    if(k) f[i][j][k]=f[i+1][j][k-1];
                    inc(f[i][j][k],f[i+1][j+1][k]);
                }
                else {
                    f[i][j][k]=f[i+1][j][k];
                }
            }
    }
    int ans=f[1][0][0];
    for(int i=1;i<=m;i++) ans=1ll*ans*i%mod;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 225536
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>

int main(int argc, char* argv[]) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  /* */
  std::string s[3];
  std::cin >> s[0] >> s[1] >> s[2];

  int i[3] = {0};
  int t = 0;
  for (;;) {
    if (s[t].length() == i[t]) {
      std::printf("%c\n", t == 0 ? 'A' : t == 1 ? 'B' : 'C');
      break;
    }

    char c = s[t][ i[t]++ ];
    t = c == 'a' ? 0 : c == 'b' ? 1 : 2;
  }
  /* */

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
N = int(input())
a = []
b = []
c = []

for i in range(N):
    x,y,z = [int(i) for i in input().split()]
    a.append(x)
    b.append(y)
    c.append(z)

dp_a = [-1] * N
dp_b = [-1] * N
dp_c = [-1] * N

dp_a[0] = a[0]
dp_b[0] = b[0]
dp_c[0] = c[0]

for i in range(1,N):
    dp_a[i] = dp_b[i-1] + a[i] if dp_b[i-1] > dp_c[i-1] else dp_c[i-1] + a[i]
    dp_b[i] = dp_a[i-1] + b[i] if dp_a[i-1] > dp_c[i-1] else dp_c[i-1] + b[i]
    dp_c[i] = dp_a[i-1] + c[i] if dp_a[i-1] > dp_b[i-1] else dp_b[i-1] + c[i]

print(max(dp_a[N-1],dp_b[N-1],dp_c[N-1]))


Measured memory_bytes: 26816
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<utility>
#include<queue>
#include <map>

using namespace std;

int main(){

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

	int max=0;
	for(auto itr = map.begin(); itr != map.end(); ++itr) {
	    if(max<itr->second)max=itr->second;
	}

	for(auto itr = map.begin(); itr != map.end(); ++itr) {
		if(max==itr->second)cout<<itr->first<<endl;
	}

	cout<<endl;

	return 0;
}


Measured memory_bytes: 26752
<?php
//error_reporting(0);
$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($A,$B) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$x = 100;
$year = 0;
while($X <= $N) {
  $x += (int)($x * 0.01);
  $year++;
  if ($x >= $N) break;
}
printf("%d\n",$year);


Measured memory_bytes: 16236
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int D;
vector<int> c(26);
vector<vector<int>> s;

int64_t calc_score(const vector<int>& t) {
  int64_t result = 0;
  vector<int> last(26, -1);
  rep(i, D) {
    int j = t[i];
    result += s[i][j];
    last[j] = i;
    rep(k, 26) { result -= c[k] * (i - last[k]); }
  }
  return result;
}

int main() {
  cin >> D;

  rep(i, 26) { cin >> c[i]; }

  s.resize(D, vector<int>(26));
  rep(i, D) rep(j, 26) { cin >> s[i][j]; }

  int64_t score = numeric_limits<int64_t>::min();
  vector<int> result(D);

  mt19937 rng(111);
  uniform_int_distribution<int> dist(0, 25);
  rep(i, 10'000) {
    vector<int> tmp(D);
    rep(i, D) { tmp[i] = dist(rng); }
    int64_t z = calc_score(tmp);
    if (score < z) {
      score = z;
      result = tmp;
    }
  }

  rep(i, D) { cout << result[i] + 1 << "\n"; }
  cerr << "score = " << score << "\n";

  return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

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

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

typedef long long ll;

int mini[1001];

int main(){
	int w, a, b;
	
	cin >> w >> a >> b;
	
	int ans = 0;
	
	if (a < b){
		while (1){
			if (b <= a+w) break;
			b--;
			ans++;
		}
	}
	else if (a > b){
		while (1){
			if (b+w >= a) break;
			b++;
			ans++;
		}
	}
	else ans = 0;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int Max_N(255);

int N, MOD, L[Max_N << 1], R[Max_N << 1], F[2][Max_N];

inline int Add(int a, int b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}

inline int Sub(int a, int b)
{
	return a - b < 0 ? a - b + MOD : a - b;
}

inline int Mult(int a, int b)
{
	return a * 1LL * b % MOD;
}

inline void upd(int &a, int b)
{
	a = Add(a, b);
}

inline void inc(int &a, int b)
{
	a = Sub(a, b);
}

int main()
{
	scanf("%d%d", &N, &MOD);
	if (MOD == 1)
	{
		printf("0");
		return 0;
	}
	for (int i = 0;i < 2 * N;++i)
	{
		L[i] = 0;
		while (i * i + L[i] * L[i] < N * N)
			++L[i];
		R[i] = 2 * N - 1;
		while (i * i + R[i] * R[i] > (2 * N) * (2 * N))
			--R[i];
	}
	int Ans = 0;
	for (int x = 0, now, lst;x <= N;++x)
	{
		now = 0, lst = 1, memset(F[now], 0, sizeof(F[now])), F[now][0] = 1;
		for (int i = N - 1, j = 2 * N - 1, cnt = 0;i >= 0;--i)
		{
			while (j >= N && R[j] <= L[i] - 1)
			{
				for (int k = 0;k <= x;++k)
					if (R[j] + 1 > cnt + k)
						F[now][k] = Mult(F[now][k], (R[j] + 1) - (cnt + k));
					else
						F[now][k] = 0;
				++cnt, --j;
			}
			now ^= 1, lst ^= 1, memset(F[now], 0, sizeof(F[now]));
			for (int k = 0;k <= x;++k)
			{
				if (R[i] + 1 > (2 * N - 1 - i) + (x - k))
					upd(F[now][k], Mult(F[lst][k], (R[i] + 1) - (2 * N - 1 - i) - (x - k)));
				if (k + 1 <= x && L[i] > cnt + k)
					inc(F[now][k + 1], Mult(F[lst][k], L[i] - (cnt + k)));
			}
			if (i == 0)
				while (j >= N)
				{
					for (int k = 0;k <= x;++k)
						if (R[j] + 1 > cnt + k)
							F[now][k] = Mult(F[now][k], (R[j] + 1) - (cnt + k));
						else
							F[now][k] = 0;
					++cnt, --j;
				}
		}
		upd(Ans, F[now][x]);
	}
	printf("%d", Ans);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
  static void Main(string[] args)
  {
    var n = Int32.Parse(Console.ReadLine());

    var shichigosanNums = new List<Int64>();
    for (var digit = 3; digit <= 10; digit++)
    {
      for (var i = 0; i < Math.Pow(3, digit); i++)
      {
        var s = "";
        for (var d = 0; d < digit; d++)
        {
          var di = 0;
          if (d == 0)
          {
            di = i % 3;
          }
          else
          {
            di = i % (int)Math.Pow(3, d + 1) / (int)Math.Pow(3, d);
          }
          if (di == 0)
          {
            s += 3;
          }
          else if (di == 1)
          {
            s += 5;
          }
          else if (di == 2)
          {
            s += 7;
          }
        }
        if (s.Contains('7') && s.Contains('5') && s.Contains('3'))
        {
          shichigosanNums.Add(Int64.Parse(string.Concat(s.Reverse())));
        }
      }
    }

    var c = 0;
    foreach (var shichigosanNum in shichigosanNums)
    {
      if (shichigosanNum <= n)
      {
        c++;
      }
      else
      {
        break;
      }
    }
    Console.WriteLine(c);
  }
}


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

using namespace std;
typedef long long int lli;

#define all(arr) arr.begin(),arr.end()
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define MOD 1000000007

template <typename T>
void input(vector<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}

template <typename T>
void output(vector<T> arr) {
  for(auto x:arr) cout<<x<<" ";
  cout<<endl;
}


template <typename T>
void input_set(set<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp);
}

lli mul(lli a, lli b) {
  return (a%MOD*b%MOD)%MOD;
}

lli power(lli num,lli base) {
  lli ans = 1;
  while(base>0) {
    if(base&1)
      ans = mul(ans, num);

    num = mul(num, num);
    base >>= 1;
  }

  return ans;
}

void solve() {
  lli n, u;
  cin >> n;
  u = n;
  lli ops = 0;
  for(lli z=2; z*z<=u; z++) {
    if(n%z!=0)
      continue;

    lli cnt = 0;
    while(n%z==0)
      n/=z, ++cnt;

    ops += (sqrt(8LL*cnt+1)-1)/2;;
  }

  if(n>2)
    ++ops;

  cout << ops << endl;
}

int main() {
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  lli testcases=1;
  while(testcases--) {
    solve();
  }
}



Measured memory_bytes: 3692
# -*- coding: utf-8 -*-

A, B = map(int, input().split())
S = input()

# 部分文字列を取得して、各条件に合致するか確認
if S[:A].isdigit() and S[A] == "-" and S[A+1:A+1+B].isdigit():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll 	long long
#define pb push_back
#define mp make_pair
using namespace std;

int main()
{

int a,b,c,k; cin>>a>>b>>c>>k;

//if(b>a && c>b)
//cout<<"Yes\n";
//else
//{
	
	int cc=b;
int cnt=0,add=0,bb=0;
while(1)
{

	if(b>a)
	break;
	else
	{
	
	b*=2;
	cnt++;
}
}
int d=cnt;
//while(cnt--)
//{
	//bb=cc*2;
//}

while(1)
{

	if(c>b)
	break;
	else
	{
	
	c*=2;
	add++;
}

}
int e=add;

if((d+e)>k)
cout<<"No\n";
else
cout<<"Yes\n";
//}

    return 0;
}

Measured memory_bytes: 3592
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools

commands = [
    '({}{}{}) {}{}{}{}',
    '{}{} ({}{}{}) {}{}',
    '{}{}{}{} ({}{}{})',

    '( ({}{}{}) {}{}) {}{}',
    '{}{} ({}{} ({}{}{}) )',
    '({}{}{}) {} ({}{}{})',
]

for s in sys.stdin:
    a, b, c, d = map(int, s.split())

    if a == b == c == d == 0:
        pass
    else:
        solved = False
        for values in itertools.permutations([a, b, c, d], 4):
            if solved:
                break

            for operators in itertools.product(['+', '-', '*'], repeat=3):
                if solved:
                    break

                for command_template in commands:
                    if solved:
                        break

                    command = command_template.format(values[0], operators[0], values[1], operators[1], values[2], operators[2], values[3])
                    result = eval(command)
                    if result == 10:
                        print(command)
                        solved = True
        if not solved:
            print(0)

Measured memory_bytes: 7700
#include<bits/stdc++.h>
#define INF 2147483647
#define  ll long long
using namespace std;
const int Max=2e5+20;
const int Maxn=1e7+20;
const int mod=1e9+7;
inline int read()
{
    int f=1,x=0;
    char ch;
    do
    {
        ch=getchar();
        if(ch=='-')f=-1;
    }
    while(ch<'0'||ch>'9');
    do
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    while(ch>='0'&&ch<='9');
    return x*f;
}
ll a[Max];
ll sum[Max];
int main()
{

   int n;
   cin>>n;
   for(int i=1;i<=n;i++)
    {a[i]=read();
    sum[i]=sum[i-1]+a[i];
    }
   ll ans=0;
   for(int i=1;i<n;i++)
   {
       ans+=(((sum[n]-sum[i])%mod)*a[i])%mod;
       ans%=mod;
   }
   cout<<ans<<endl;

}




Measured memory_bytes: 6716
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int N;
    cin >> N;
    vector<pair<ll, ll> > vpp(N);
    rep(i, 0, N) {
        cin >> vpp[i].first >> vpp[i].second;
    }
    ll ans = 0LL;
    rep(i, 0, N) {
        if (vpp[i].first != vpp[i].second) {
            break;
        }
        if (i == N - 1) {
            cout << 0 << endl;
            return 0;
        }
    }

    rep(i, 0, N) {
        if (vpp[i].first <= vpp[i].second) {
            vpp[i].second -= vpp[i].first;
            ans += vpp[i].first;
            vpp[i].first = 0;
        }
    }
    sort(all(vpp));
//    int pt = 0;
//    rep(i, 0, N) {
//        if (vpp[i].first > 0 && vpp[i].second != 0) {
//            pt = i + 1;
//            break;
//        }
//    }

    ll minb = INFl;
    rep(i,0,N){
        if(vpp[i].first > 0){
            minb = min(minb,vpp[i].second);
        }
        ans += vpp[i].second;
    }
    ans -= minb;
    cout << ans << endl;

//    if (pt == N) {
//        ans += (vpp[N - 1].first - vpp[N - 1].second);
//        cout << ans << endl;
//    } else {
//        pt--;
//        ans += (vpp[pt].first - vpp[pt].second);
//        for (int i = pt + 1; i < N; i++) {
//            ans += (vpp[i].first);
//        }
//        cout << ans << endl;
//
//    }

//        pt--;
//        ans += (vpp[pt].first - vpp[pt].second);
//        for (int i = pt + 1; i < N; i++) {
//            ans += (vpp[i].first);
//        }
//        cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

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

    cout<<max(c-(a-b),0)<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  //Bubble Sort
  int tmp;
  vector<int> sort(10);
  for(int i=0;i<10;i++)cin>>sort[i];
  for(int j=9;j>=1;j--){
    for(int i=9;i>=1;i--){
      if(sort[i]<sort[i-1]){
	tmp=sort[i];
	sort[i]=sort[i-1];
	sort[i-1]=tmp;
      }
    }
  }
    
  cout<<sort[9]<<endl;
  cout<<sort[8]<<endl;
  cout<<sort[7]<<endl;
}

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

int main(){

    string str, str2, str3;
    cin >> str;
    cin >> str2;

    str += str; //二周

    bool flag = false;

    for(int i=0; i<str.size(); i++){
        if(flag == true) break;
        for(int j=0; j<str2.size(); j++){
            if(flag==true) break;
            str3.push_back(str[i+j]);
            if(str3==str2) flag = true;
        }
        str3.clear();
    }

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

    return 0; 
}


Measured memory_bytes: 3208
// Problem : D - Replacing
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define fi first
#define se second
#define pb push_back
 
#define ll long long
#define pii pair<int, int>
//#define int ll
const int MOD = 1000000007;

map<int, ll> cnt;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll cur = 0;
    int n; cin >> n;
    rep(i, n) {
    	int k; cin >> k;
    	cnt[k]++;
    	cur += k;
    }
    int q; cin >> q;
    rep(i, q) {
    	int b, c; cin >> b >> c;
    	cur -= b*cnt[b];
    	cur += c*cnt[b];
    	cnt[c] += cnt[b];
    	cnt[b] = 0;
    	cout << cur << endl;
    }
}



Measured memory_bytes: 9388
t = [0]*5
m = [0] * 5
min = 10
min_idx = 0
for i in range(5):
    t[i] = int(input())
    m[i] = t[i] % 10
    if( min > m[i] and m[i] != 0):
        min = m[i]
        min_idx = i
for i in range(5):
    if( i != min_idx ):
        if( m[i] != 0):
            t[i] += (10 - m[i])
print(sum(t))

Measured memory_bytes: 3064
import math
a, b, x = map(int,input().split())
V = (a**2)*b
v = V*0.5
if x >= v:
    U = V - x
    c = (U*2) / (a**3)
    z = math.atan(c)
    print(math.degrees(z))
else:
    c = (a*(b**2)) / (x*2)
    z = math.atan(c)
    print(math.degrees(z))
    


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

#define rep(i, n) for(int (i) = 0; i < (n); ++(i))

using ll = long long int;
const ll MOD = 1e9 + 7;

template<long long int P>
struct _mint {
  long long int x;
  _mint(long long int x = 0): x((x % P + P) % P) {}

  _mint operator-() const {
    return _mint(-x);
  }

  _mint& operator+=(const _mint a) {
    if((x += a.x) >= P) {
      x -= P;
    }
    return *this;
  }
  _mint& operator-=(const _mint a) {
    if((x += P - a.x) >= P) {
      x -= P;
    }
    return *this;
  }
  _mint& operator*=(const _mint a) {
    (x *= a.x) %= P;
    return *this;
  }
  _mint& operator/=(const _mint a) {
    return (*this) *= a.inv();
  }

  _mint operator+(const _mint a) const {
    _mint res(*this);
    return res += a;
  }
  _mint operator-(const _mint a) const {
    _mint res(*this);
    return res -= a;
  }
  _mint operator*(const _mint a) const {
    _mint res(*this);
    return res *= a;
  }
  _mint operator/(const _mint a) {
    _mint res(*this);
    return res /= a;
  }

  _mint pow(long long int t) const {
    if(! t) return 1;
    _mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }

  // for prime P
  _mint inv() const {
    return pow(P - 2);
  }
};
using mint = _mint<MOD>;

int dfs(int pos, int prev, std::vector<std::vector<int>> &from, std::vector<int> &cnt) {
  int ret = 1;
  for(auto b : from[pos]) {
    if(b == prev) {
      continue;
    }

    ret += dfs(b, pos, from, cnt);
  }

  return cnt[pos] = ret;
}

int main() {
  int N;
  std::cin >> N;

  std::vector<int> A(N - 1), B(N - 1);
  std::vector<std::vector<int>> from(N);
  rep(i, N - 1) {
    std::cin >> A[i] >> B[i];
    --A[i];
    --B[i];
    from[A[i]].push_back(B[i]);
    from[B[i]].push_back(A[i]);
  }

  std::vector<mint> pow(N + 1), inv(N + 1);
  pow[0] = 1;
  inv[0] = 1;
  rep(i, N) {
    pow[i + 1] = pow[i] * 2;
    inv[i + 1] = pow[i + 1].inv();
  }

  std::vector<int> cnt(N);
  dfs(0, 0, from, cnt);

  mint EV = 1;
  rep(i, N - 1) {
    int na = std::min(cnt[A[i]], cnt[B[i]]);
    int nb = N - na;

    EV += (mint(1) - inv[na]) * (mint(1) - inv[nb]);
  }

  mint ans = EV - inv[1] * N - inv[N];
  std::cout << ans.x << '\n';
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

// ------------------------------------------------------------------------------------------

signed main() {
  string s;
  cin >> s;

  int n = s.size();
  for (int i = 0; i < n; i++) {
    for (int j = i; j <= n; j++) {
      string t = "";
      for (int k = 0; k < n; k++) {
        if (i <= k && k < j) {
          continue;
        } else {
          t.push_back(s[k]);
        }
      }
      if (t == "keyence") {
        cout << "YES" << endl;
        return 0;
      }
    }
  }

  cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;

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

const int inf = 1e9 + 1;
const double eps = 1e-9;
const int MAXN = 101;
const int MAXV = 1e5 + 1;

int n, c;
int w[MAXN], v[MAXN];
int dp[MAXN][MAXV];
int sol;

int main(){

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

    for (int i = 0; i <= n; i++){
        dp[i][0] = 0;
        for (int j = 1; j < MAXV; j++)
            dp[i][j] = inf;
    }

    for (int i = 1; i <= n; i++){
        for (int j = MAXV-1; j >= 0; j--){
            if (j >= v[i-1]) dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]]+w[i-1]);
            else dp[i][j] = dp[i-1][j];
            //cout << dp[i][j];
        }
    }

    for (int i = 0; i < MAXV; i++){
        if (dp[n][i] <= c) sol = max(sol, i);
    }

    cout << sol;

    return 0;

}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int) n; i++)
#define reps(i, n, m) for (int i = n; i < (int) m; i++)


int main() {
	int n, q;
	cin >> n >> q;
	vector<queue<int>> Q(n);
	while (q--) {
		int t;
		cin >> t;
		if (t == 0) {
			int a, b;
			cin >> a >> b;
			Q[a].emplace(b);
		} else if (t == 1) {
			int a;
			cin >> a;
			if (Q[a].size()) cout << Q[a].front() << endl;
		} else {
			int a;
			cin >> a;
			if (Q[a].size()) Q[a].pop();
		}
	}
}


Measured memory_bytes: 4268
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL<<62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

int main() {
	int r, d, x[11];
	cin >> r >> d >> x[0];
	FOR1(i, 11)x[i] = x[i - 1] * r - d;
	FOR1(i, 11)cout << x[i] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<map>


int main() {
	int n;
	scanf("%d", &n);
	std::map<int, int> map;
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		map[a]++;
	}
	for (auto p : map) {
		if (p.second >= p.first) {
			sum += p.second - p.first;
		}
		else {
			sum += p.second;
		}
	}
	printf("%lld", sum);

}

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

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n, t;
	scanf("%d%d", &n, &t);
	vector<LL> as(n);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &as[i]);
	}
	
	LL mina = LLONG_MAX;
	LL md = 0;
	int ans = 0;
	for(int i = 0; i < n; ++i){
		mina = min(mina, as[i]);
		LL dif = as[i] - mina;
		if(md < dif){
			md = dif;
			ans = 0;
		}
		if(md == dif){
			++ans;
		}
	}
	printf("%d\n", ans);
}



}
int main() try{
//	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main() {

	char arr[5] = {0};

	cin >> arr;

	for(int i = 0; i < 3; i++)
		if(arr[i] == arr[i+1]){
			cout << "Bad" << endl;
			return 0;
		}
	
	cout << "Good" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long 
#define PI 3.14159265358979323846
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(x,n) for(ll x=1;x<(ll)n+1;x++)
using namespace std;

int main() {
	ll N;
	string ans;
	cin >> N;
	while (N) {
		N--;
		ans += 'a' + N % 26;
		N /= 26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}

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

int main() {
	long long N, K, H, ANS = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> H;
		if (H >= K) ANS++;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

A = int(input())
B = int(input())
C = int(input())
D = int(input())

print(min(A, B)+min(C, D))

Measured memory_bytes: 38384