akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

// DAME:
int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h+2, vector<char>(w+2));
    rep(i, h+2){
        s[i][0] = '#';
        s[i][w+1] = '#';
    }
    rep(j, w+2){
        s[0][j] = '#';
        s[h+1][j] = '#';
    }
    rep(i, h)rep(j, w){
        cin >> s[i+1][j+1];
    }
    vector<vector<int>> L(h+2, vector<int>(w+2, 0));
    vector<vector<int>> R(h+2, vector<int>(w+2, 0));
    vector<vector<int>> U(h+2, vector<int>(w+2, 0));
    vector<vector<int>> D(h+2, vector<int>(w+2, 0));
    rep(i, h+1)rep(j, w+1){
        if(i==0 or j==0) continue;
        if(s[i][j] == '#'){
            L[i][j] = 0;
            R[i][j] = 0;
            U[i][j] = 0;
            D[i][j] = 0;
            continue;
        }
        L[i][j] = L[i][j-1]+1;
        U[i][j] = U[i-1][j]+1;
    }

    for(int i=h+1; i>0; i--)for(int j=w+1; j>0; j--){
        if(s[i][j] == '.'){
            R[i][j] = R[i][j+1]+1;
            D[i][j] = D[i+1][j]+1;
        }
    }
    int ans = 0;
    rep(i, h+1)rep(j, w+1){
        if(i==0 or j==0) continue;
        chmax(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 67072
import sys

n = int(sys.stdin.readline())
p = [int(sys.stdin.readline()) for i in range(n)]
a = [0] * n
for i in range(n):
    a[p[i]-1] = i
prv = -1
mx = 1
nw = 0
for i in range(n):
    if prv < a[i]:
        nw += 1
        mx = max(mx, nw)
    else:
        nw = 1
    prv = a[i]
print(n-mx)


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

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  vector<int>a(n);
  rep(i,0,n) cin >> a[i];
  sort(a.begin(),a.end());
  vector<bool>baned(a[n-1]+1,false);
  rep(i,0,n-1) if(a[i] == a[i+1]) baned[a[i]] = true;
  
  vector<bool>seen(a[n-1]+1,false);
  for(auto v : a){
    if(!seen[v]){
      if(!baned[v])ans++;
      for(int j = v;j <= a[n-1]+1;j += v){
        seen[j] = true;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4060
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {
	rapid_pleaseAC_fast;

	int a, b;
	cin >> a >> b;
	int ans = 1;
	int cnt = 0;
	while (ans < b) {
		ans += a - 1;
		cnt++;
	}
	cout << cnt << rt;

	please AC;
}
//参考：---

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    total_sum = 0
    inv_cum_sum = []
    ans = 0 
    for i in range(len(A)):
        total_sum += int(A[i] % int(1e9+7))
        total_sum = int(total_sum % int(1e9+7))
    tmp_cum_sum = 0
    for i in range(len(A)):
        tmp_cum_sum += int(A[i] % int(1e9+7))
        tmp_cum_sum = int(tmp_cum_sum % int(1e9+7))
        inv_cum_sum.append(total_sum - tmp_cum_sum)
    for i in range(len(inv_cum_sum)):
        ans += int((A[i] * inv_cum_sum[i]) % int(1e9+7))
    print(int(ans % int(1e9+7)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 102044
import sys
from collections import Counter
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    R, G, B, N = [int(n) for n in input().strip().split()]
    ans = 0
    for r in range((N//R)+1):
        for g in range((N-(R*r)//G)+1):
            if (N - (R * r) - (G * g)) % B == 0 and (N - (R * r) - (G * g)) // B >= 0:
                ans += 1
    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 9464
#include <stdio.h>
#define n 36

struct Card{
  char suit;
  char value;
};

void BubbleSort(struct Card C[],int N){
  int i,j;
  struct Card a;

  for(i=0;i<N;i++){
    for(j=N-1;j>=i+1;j--){
      if(C[j].value < C[j-1].value){
        a = C[j];
        C[j] = C[j-1];
        C[j-1] = a;
      }
    }
  }
}

void SelectionSort(struct Card C[],int N){
  int i,j,minj;
  struct Card a;

  for(i=0;i<N;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(C[j].value < C[minj].value){
        minj = j;
      }
    }
    a = C[i];
    C[i] = C[minj];
    C[minj] = a;
  }
}

int isStable(struct Card C1[],struct Card C2[],int N){
  int i,j;

  for(i=0;i<N;i++){
    if(C1[i].suit != C2[i].suit)return 0;
  }
  return 1;
}
  /*for(i=0;i<N;i++){                                                           
    for(j=i+1;j<N;j++){                                                         
      for(a=0;a<N;a++){                                                         
        for(b=a+1;b<N;b++){                                                     
        if(in[i] == in[j] && )*/
int main(){
  struct Card C1[101],C2[101];
  int i,N;
  scanf("%d\n",&N);
  for(i=0;i<N;i++){
    if(i!=N-1)scanf("%c%c ",&C1[i].suit,&C1[i].value);
    else scanf("%c%c",&C1[i].suit,&C1[i].value);
  }

  for(i=0;i<N;i++)C2[i] = C1[i];

  BubbleSort(C1,N);
  SelectionSort(C2,N);

  for(i=0;i<N;i++){
    if(i)printf(" ");
    printf("%c%c",C1[i].suit,C1[i].value);
  }
  printf("\nStable\n");
  for(i=0;i<N;i++){
    if(i)printf(" ");
    printf("%c%c",C2[i].suit,C2[i].value);
 }
  if(isStable(C1,C2,N)){
    printf("\nStable\n");
  }
  else printf("\nNot stable\n");

  return 0;
}



Measured memory_bytes: 2104
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, k;
	cin >> n >> k;
	int l[100];
	for(int i = 0; i < n; i++){
		cin >> l[i];
	}
	sort(l, l + n);
	int ans = 0;
	for(int i = 0; i < k; i++){
		ans += l[n - 1 - i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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 long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
vector<l_l> v;
ll ans = 0;
ll Last = -1e12;
ll N;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    v.resize(N);
    for(int i = 0; i < N; i++) {
        ll x, l;
        cin >> x >> l;
        v[i].first = x + l;
        v[i].second = x - l;
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < N; i++) {
        if(v[i].second < Last) continue;
        Last = v[i].first;
        ans++;
    }
    cout  << ans << endl;
    return 0;
}

Measured memory_bytes: 2428
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(x) x.begin(),x.end()
#define REPR(i,n) for(ll i=(n)-1;i>=0;i--)
#define FOR(i,m,n) for(ll i=(m);i<(n);i++)
#define int long long

int H;
int A[20][10];
void solve() {
    int H;cin>>H;
    int W = 5;
    if(H==0)exit(0);
    REP(i,H){
        REP(j,5){
            cin>>A[i][j];
        }
    }
    bool found = true;
    int ans = 0;
    while(found){
        found = false;
        REP(i,H){
            REP(l,W){
                int r = l;
                if(A[i][l]==-1)continue;
                while(A[i][r]==A[i][l]){
                    r++;
                    if(r==W)break;
                }
                if(r-l>=3){
                    found = true;
                    FOR(j,l,r){
                        ans+=A[i][j];
                        A[i][j]=-1;
                    }
                }
            }
        }
        REP(_,H+1){
            REPR(i,H-1){
                REP(j,W){
                    if(A[i+1][j]==-1){
                        A[i+1][j]=A[i][j];
                        A[i][j]=-1;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

signed main() {
	while (true)solve();
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int i,n,k,kotae=1;
  cin>>n;
  long long int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==0){
      cout<<0;
      return 0;
    }
  }
  for(i=0;i<n;i++){
    k=a[i];
    if(k<=1000000000000000000/kotae){
      kotae*=k;
    }else{
      cout<<-1;
      return 0;
    }
  }
  cout<<kotae;
}


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

int main() {
  double n,k,ans,x;
  cin >> n >> k;
  ans+=max(0.0,n-k+1.0)/n;
  rep(i,min(n,k-1)){
  	double tmp=1.0/n;
  	x=i+1;
  	while(x<k){
  		x*=2;
  		tmp*=0.5;
  	}
  	ans+=tmp;
  }
  cout << setprecision(12) << ans << endl;
}


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

//#include <unordered_map>

//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define dd(n) cout<<fixed<<setprecision(n)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define repir(i,a,b) for(int i=(a)-1, i##_first=(b); i>=i##_first; --i)
#define repr(i,n) repir(i,n,0)
#define repir_(i,a,b) for(int i=(a), i##_first=(b); i>=i##_first; --i)
#define repr_(i,n) repir_(i,n,0)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
//template<typename T> T vpop(vector<T> *v) {
//	T res = v->back();
//	v->pop_back();
//	return res;
//}
//char vpop(string *v) {
//	char res = v->back();
//	v->pop_back();
//	return res;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define pi 3.14159265358979
#define co(x) cout<<x<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<lint> lvec;
typedef vector<vector<int>> ivvec;
typedef pair<int, int> P;

const int
dx8[8] ={ 0,1,1,1,0,-1,-1,-1 },
dy8[8] ={ 1,1,0,-1,-1,-1,0,1 },
dx4[4] ={ 0,1,0,-1 },
dy4[4] ={ 1,0,-1,0 };

template<class T>inline bool maxi(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main(){
	setc;

	int a,b;char c;
	cin>>a>>c>>b;
	coc(c=='+',a+b,a-b);
	gc();
}

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

int main(int argc, char *argv[])
{
	int n;
	int ret;
	int i;
	int repdigit[9];
	cin >> n;

	for (i = 0; i < 9; i++) 
		repdigit[i] = 111 * (i + 1);

	for (i = 0; i < 9; i++) {
		if (n <= repdigit[i]) {
			ret = repdigit[i];
			break;
		}
	}

	cout << ret << endl;
			
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
   int w,h,x,y,r;
   scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
   if(w-r>=x&&r<=x&&h-r>=y&&r<=y){
   	printf("Yes\n");
   }else{
   	printf("No\n");
    }
}


Measured memory_bytes: 2108
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<iomanip>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int N;
int K, a[110];
int dp[111111];
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < K + 1; ++i) {
		int lose = 0, cnt = 0;
		for (int j = 0; j < N; ++j) {
			//操作を行えるかどうか調べる
			//操作を行えないなら負け
			if (0 <= i - a[j]) {
				cnt++;//cntが1以上なら操作を行える
				if (!dp[i-a[j]])lose++;//もし相手を負け状態にできる選択肢があるなら
				//選んで相手を負け状態にする。
			}
		}
		if (cnt == 0)dp[i] = 0;
		else if (0 < lose)dp[i] = 1;
		else dp[i] = 0;//遷移先が全て勝ち状態なら負け状態
	}
	if (dp[K])cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
  int D;
  scanf("%d",&D);
  switch(D){
    case 25:
      printf("Christmas\n");
      break;
    case 24:
      printf("Christmas Eve\n");
      break;
    case 23:
      printf("Christmas Eve Eve\n");
      break;
    case 22:
      printf("Christmas Eve Eve Eve\n");
      break;
  }
  return 0;
}

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

int main() {
	int A, B;//A 縦のピクセル B 横のピクセル
	cin >> A >> B;
	char x;
	int C = 0;
	string F;
	while (C < B + 2) {
    	cout << "#";
		C++;
    }
	cout << endl;
	C = 0;
	for (int D = 0; D < A; D++) {
    	cin >> F;
    	cout << "#";
    	for (int E = 0; E < F.size(); E++) {
        	x = F.at(E);
        	cout << x;
        }
    	cout << "#" << endl;
    }
	while (C < B + 2) {
    	cout << "#";
		C++;
    }
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let a: Vec<_> = (0..m)
        .map(|_| (read::<usize>() - 1, read::<usize>() - 1))
        .collect();

    let mut graph = [[false; 50]; 50];
    for i in 0..m {
        graph[a[i].0][a[i].1] = true;
        graph[a[i].1][a[i].0] = true;
    }
    let mut ans = 0;
    for i in 0..m {
        graph[a[i].0][a[i].1] = false;
        graph[a[i].1][a[i].0] = false;

        let mut visited = [false; 50];
        dfs(0, n, &mut graph, &mut visited);
        if visited.iter().take(n).any(|&x| !x) {
            ans += 1;
        }
        graph[a[i].0][a[i].1] = true;
        graph[a[i].1][a[i].0] = true;
    }

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn dfs(v: usize, n: usize, graph: &mut [[bool; 50]; 50], visited: &mut [bool]) {
    visited[v] = true;

    for v2 in 0..n {
        if !graph[v][v2] {
            continue;
        }
        if visited[v2] {
            continue;
        }
        dfs(v2, n, graph, visited);
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void)
{
	int N,m,h,k,g,M,box,a[200],i,j;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d %d",&h,&m);
		a[i]=h*60+m;
	}
	scanf("%d",&M);
	for(i=N;i<N+M;i++){
		scanf("%d %d",&k,&g);
		a[i]=k*60+g;
	}
	for(i=0;i<N+M-1;i++){
		for(j=i+1;j<N+M;j++){
			if(a[i]>a[j]){
				box=a[i];
				a[i]=a[j];
				a[j]=box;
			}
		}
	}
	for(i=0;i<N+M;i++){
		if(i>0){
			printf(" ");
		}
		printf("%d",a[i]/60);
		printf(":");
		if(a[i]%60<10){
			printf("0%d",a[i]%60);
		}
		else{
		printf("%d",a[i]%60);
		}
		if(a[i]==a[i+1]){
			i++;
		}
	}
	printf("\n");
	return 0;
	}


Measured memory_bytes: 2148
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long long int ans=0,a[200010],i,n,k;
  cin >> n >> k;
  for(i=0;i<n;i++){
	cin >> a[i];
  }
  sort(a,a+n,greater<int>());
  for(i=k;i<n;i++){
	ans=ans+a[i];
  }
	cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll tmp;
	int n, a[3]; cin >> n >> a[0] >> a[1] >> a[2];
	vector<string> ans(n), q(n);
	cin >> q;
	q.push_back("AC");
	bool ch = true;
	REP(i, n){
		int l = q[i][0] - 'A';
		int r = q[i][1] - 'A';
		//cout << a[0] << " " << a[1] << " " << a[2] << endl;
		if(a[l] == 0 && a[r] == 0) ch = false;
		else if(a[l] == 1 && a[r] == 1){
			int ll = q[i+1][0] - 'A';
			int rr = q[i+1][1] - 'A'; 
			if(l == ll || l == rr){
				ans[i] = 'A' + l;
				a[l]++;
				a[r]--;
			}
			else{
				ans[i] = 'A' + r;
				a[r]++;
				a[l]--;
			}
		}
		else {
			if(a[r] >= a[l]){
				ans[i] = 'A' + l;
				a[l]++;
				a[r]--;
			}
			else{
				ans[i] = 'A' + r;
				a[r]++;
				a[l]--;
			}
		}
	}
	if(ch){
		cout << "Yes" << endl;
		REP(i, n) cout << ans[i] << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 12756
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int ans = 1;
    for (int i = 0; i < N; i++) {
      ans = Math.min(ans * 2, ans + K);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21716
#include <stdio.h>
int main(void){
    int px[50],py[50],np,i,sign,cnt = 1;
    double area;
    scanf("%d", &np);
    while( np > 0 ){
        for(i = 0; i < np; i++){
            scanf( "%d %d", &px[i], &py[i] );
        }
        area = 0;
        for(i = 2; i < np; i++){
            area += (double)( (px[i] - px[0])*(py[i-1] - py[0])
                              - (px[i-1] - px[0])*(py[i] - py[0]) )/2;

        }
        printf("%d %.1lf\n",cnt++, area);
        scanf("%d", &np);
    }
    return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
typedef long long ll;
using namespace std;
ll now[8], n, m, r[8], dis[200][200], ans = 10e17, rn, flg[8];

void dfs(ll a) {
  ll i, j, k;
  if(a == rn) {
    ll tmp = 0;
    for(i = 0; i < rn - 1; ++i) tmp += dis[r[now[i]]][r[now[i + 1]]];
    if(ans > tmp) ans = tmp;
  } else {
    for(i = 0; i < rn; ++i) if(flg[i]) {
      now[a] = i; flg[i] = 0;
      dfs(a + 1);
      flg[i] = 1;
    }
  }
}

int main(void) {
  ll i, j, k, a, b, c;
  scanf("%lld%lld%lld", &n, &m, &rn);
  for(i = 0; i < rn; ++i) scanf("%lld", &r[i]), r[i]--;
  for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) {
    if(i != j) dis[i][j] = 10e17;
    else dis[i][j] = 0;
  }
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld%lld", &a, &b, &c);
    a--, b--;
    if(dis[a][b] > c) dis[a][b] = dis[b][a] = c;
  }
  for(k = 0; k < n; ++k) for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) if(dis[i][k] + dis[k][j] < dis[i][j]) dis[i][j] = dis[i][k] + dis[k][j];
  for(i = 0; i < rn; ++i) flg[i] = 1;
  dfs(0);
  printf("%lld", ans);
  return 0;
}


Measured memory_bytes: 512
A = []
while True:
    try:
        n = input()
        if n == "":
            break
    except:
        break
    nn = len(n)
    
    for i in range(nn):
        n_l = n.lower()
        A.append(n_l[i])
  
for i in range(ord("a"),ord("z")+1):
    print(chr(i),":",A.count(chr(i)))


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

pair<long long, long long> p[200010];
long long bb[200010], f[200010];

bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
	return x.first*(y.second+1) > y.first*(x.second+1);
}

int main() {
	ios::sync_with_stdio(false);
	int n,t; cin >> n >> t;
	int cnt1 = 0, cnt2 = 0;
	for (int i = 1; i <= n; i++) {
		int a,b; cin >> a >> b;
		if (a) p[cnt1++] = {a,b};
		else bb[cnt2++] = b+1;
	}
	sort(p,p+cnt1,cmp);
	sort(bb,bb+cnt2);
	for (int j = 1; j <= 30; j++) f[j] = t+1;
	for (int i = 1; i < cnt2; i++) bb[i] += bb[i-1];
	for (int i = 0; i < cnt1; i++)
		for (int j = 30; j; j--) //if (f[j-1] <= t)
			f[j] = min(f[j], (f[j-1]+1) * (p[i].first+1) + p[i].second);
	int ans = 0;
	
	for (int i = 0; i <= 30; i++) if (f[i] <= t) {
		int num0 = 0;
		if (cnt2) num0 = upper_bound(bb,bb+cnt2,t-f[i])-bb;
		ans = max(ans, i + num0);
	}
	cout << ans << "\n";
	
}


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

using namespace std;

class Dijkstra {
  using QItem = pair<int, int>;

 public:
  vector<int> minDistance(vector<array<int, 3>> &edges, int n, int src) {
    vector<int> costs(n, -1);
    costs[src] = 0;

    // 各ノードの隣接ノードとその距離を初期化
    vector<map<int, int>> distances(n);
    for (auto &edge : edges) {
      int n1 = edge[0], n2 = edge[1], d = edge[2];
      distances[n1][n2] = d;
      distances[n2][n1] = d;
    }

    vector<bool> used(n, false);
    priority_queue<QItem, vector<QItem>, greater<QItem>> q;
    q.push({0, src});

    while (!q.empty()) {
      // 未確定で，コストの一番低いノードを選択する
      auto [min_cost, min_idx] = q.top();
      q.pop();

      // 選択したノードは確定とする
      used[min_idx] = true;

      // 選択したノードの隣接ノードについて，そのコストを再計算する
      auto dist = distances[min_idx];
      for (auto p : dist) {
        int new_cost = min_cost + p.second;
        if (costs[p.first] < 0 || costs[p.first] > new_cost) {
          costs[p.first] = new_cost;
          q.push({new_cost, p.first});
        }
      }
    }

    return costs;
  }
};

int main(int argc, const char *argv[]) {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--, cw--, dh--, dw--;
  vector<string> maze(h);
  for (int i = 0; i < h; ++i) {
    cin >> maze[i];
  }

  vector<array<int, 3>> edges;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (maze[i][j] == '#') {
        continue;
      }

      int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
      int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
      for (int i2 = min_y; i2 <= max_y; ++i2) {
        for (int j2 = min_x; j2 <= max_x; ++j2) {
          if (i2 == i && j2 == j) {
            continue;
          }

          if (maze[i2][j2] == '#') {
            continue;
          }

          int dist = abs(i2 - i) + abs(j2 - j);
          int cost = dist <= 1 ? 0 : 1;
          // cout << i << ' ' << j << ' ' << i2 << ' ' << j2 << ' ' << cost
          // << '\n';
          edges.push_back({i * w + j, i2 * w + j2, cost});
          edges.push_back({i2 * w + j2, i * w + j, cost});
        }
      }
    }
  }

  Dijkstra d;
  vector<int> min_dists = d.minDistance(edges, h * w, ch * w + cw);
  int ans = min_dists[dh * w + dw];
  cout << ans << '\n';
  return 0;
}

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





int main(void){
    char S[102];
    long long K;
    int i=0;
    scanf("%s",S);
    scanf("%lld",&K);
    char val;
    while(1){
        if(S[i] != '1'){
            val = S[i];
            break;
        }
        if(i>=K-1){
            val = '1';
            break;
        }
        if(S[i] == '\0'){
            val = '1';
            break;
        }
        i++;
    }
    printf("%c\n",val);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int m;
    cin >> m;
    cout << 48 - m << endl;
}

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

const int Maxn = 18;

int n;
int A[1 << Maxn + 1];
multiset <int> S[Maxn + 1];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < 1 << n; i++)
        scanf("%d", &A[i]);
    sort(A, A + (1 << n));
    S[0].insert(A[(1 << n) - 1]);
    for (int i = (1 << n) - 2; i >= 0; i--) {
        int num = A[i];
        bool ok = false;
        for (int j = 0; j < n; j++) {
            multiset <int>::iterator it = S[j].upper_bound(num);
            if (it != S[j].end()) {
                S[j + 1].insert(*it);
                S[j].erase(it);
                S[j + 1].insert(num);
                ok = true;
                break;
            }
        }
        if (!ok) { printf("No\n"); return 0; }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 13568
import java.util.Scanner;

public class Main {

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int i;
        int n = sc.nextInt();
        int[] a = new int[n];
        for(i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        sc.close();
        a = new Main().go_to_school(n, a);
        for(i = 0; i < n; i++){
            System.out.print(a[i] + " ");
        }

    }

    public int[] go_to_school(int n, int[] a){
        int j = 0;
        int[] b = new int[n];
        for(int i = 0; i < n; i++) {
            b[a[i] - 1] = i + 1;
        }
        return b;
    }
}


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


int main(void) {
  string s;
  cin >> s;

  bool p = s[0] == 'R';
  bool q = s[1] == 'R';
  bool r = s[2] == 'R';
  if (p and q and r) {
    cout << 3 << endl;
  } else if ((p and q) or (q and r)) {
    cout << 2 << endl;
  } else if (p or q or r) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  
  return 0;
}

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

int main() {
	int N; cin >> N;
	string S; cin >> S;
	int ans = 0, now = 0;
	for(int i=0; i<N; i++) {
		if(S[i] == 'I') now++;
		else now--;
		ans = max(ans, now);
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N;

struct Edge {
  int a = 0, b = 0, c = 0;
}edges[MAX_N];

vector<II> E[MAX_N];

signed main()
{
  cin >> N;
  REP(n,N-1) {
    cin >> edges[n].a >> edges[n].b;
    edges[n].a--; edges[n].b--;
    E[edges[n].a].push_back(II(edges[n].b, n));
    E[edges[n].b].push_back(II(edges[n].a, n));
  }

  int ans = 0;
  REP(n,N) {
    ans = max(ans, (LL)E[n].size());
  }

  REP(n,N) {
    set<int> S;
    for(II next : E[n]) {
      if(edges[next.second].c != 0) {
        S.insert(edges[next.second].c);
      }
    }
    int color = 1;
    for(II next : E[n]) {
      if(edges[next.second].c != 0) continue;
      while(!S.insert(color).second) {
        color++;
      }
      edges[next.second].c = color;
    }
  }

  cout << ans << endl;
  REP(n,N-1) {
    cout << edges[n].c << endl;
  }

  return 0;
}


Measured memory_bytes: 10240
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
#include<cstdio>
 
#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i+1) % P.size()]
  
using namespace std;
  
double EPS = 1e-10;
const double PI = acos(-1);
  
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}
 
struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}
  point operator + (point p){return point(add(x,p.x), add(y,p.y));}
  point operator - (point p){return point(add(x,-p.x), add(y,-p.y));}
  point operator * (double d){return point(x*d,y*d);}
};
  
#define Line pair<point,point>
 
double dot(point a, point b){return (a.x * b.x + a.y * b.y);}
double cross(point a, point b){return (a.x * b.y - a.y * b.x);}
double norm(point a){return sqrt(a.x*a.x+a.y*a.y);}
  
int ccw(point a, point b, point c) {
  b = b-a; c = c-a;
  if (cross(b, c) > 0)   return +1;
  if (cross(b, c) < 0)   return -1;
  if (dot(b, c) < 0)     return +2;
  if (norm(b) < norm(c)) return -2; 
  return 0;
}
 
point intersection_l(point a1, point a2, point b1, point b2) {
  return a1 + (a2 - a1) * (cross(b2 - b1,b1 - a1) / cross(b2 - b1,a2 - a1));
}
 
point symmetry(point p1, point p2, point Q){
  double xa,ya,xb,yb,t1,t2;
  point R;
  xa=Q.x-p1.x,ya=Q.y-p1.y;
  xb=p2.x-p1.x,yb=p2.y-p1.y;
  
  t1=xa*xb+ya*yb,t2=xb*xb+yb*yb;
  
  R.x=2*(p1.x+xb*t1/t2)-Q.x;
  R.y=2*(p1.y+yb*t1/t2)-Q.y;
  return R;
}
 
 Line parallel_line(point a,point b,double h){
    double t = atan((a.y-b.y)/(a.x-b.x));
  
    point a_(a.x + h*cos(t+PI/2), a.y + h*sin(t+PI/2));
    point b_(b.x + h*cos(t+PI/2), b.y + h*sin(t+PI/2));
  
    if(ccw(a,b,a_)==-1)a_=symmetry(a,b,a_),b_=symmetry(a,b,b_);
    return make_pair(a_,b_);
}
 
vector<point> convex_cut(vector<point>pol,point a,point b){
  vector<point>q;
  for (int i=0; i<pol.size();i++) {
    point A=curr(pol,i),B=next(pol, i);
    if (ccw(a,b,A)!=-1)q.push_back(A);
    if (ccw(a,b,A)*ccw(a,b,B)<0)
      q.push_back(intersection_l(A,B,a,b));
  }
  return q;
}
 
bool C(vector<point>pol,double d){
  vector<Line>L;
  for(int i=0;i<pol.size();i++){
    L.push_back(Line(curr(pol,i),next(pol,i)));
  }
   
  for(int i=0;i<L.size();i++){
    Line tmp=parallel_line(L[i].first,L[i].second,d);
    pol=convex_cut(pol,tmp.first,tmp.second);
  }
  return pol.size()>0;
}
 
double Binary_search(vector<point>pol){
  double l=0,r=10000,tc=50;
  while(tc--){
    double d=(l+r)/2;
    if(C(pol,d))l=d;
    else r=d;
  }
  return l;
}
 
int main(void){
 
  int n;
  while(cin >> n,n){
    vector<point>pol(n);
    for(int i=0;i<n;i++)cin >> pol[i].x >> pol[i].y;
    printf("%.6f",Binary_search(pol));
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1368
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

mnzkB = 0
for i in range(N):
    mnzkB += B[i]

mnzkC = 0
for j in range(N - 1):
    if A[j + 1] - A[j] == 1:
        mnzkC += C[A[j] - 1]
    
print(mnzkB + mnzkC)

Measured memory_bytes: 3064
#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 a, b;
  cin >> a >> b;
  cout << a*b << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<stack>
#include<map>
#include<queue>
#include<unordered_map>
#include<cmath>
#include<utility>

#include<ctime>
#include<random>

using ULL = unsigned long long;
using LL = long long;
using String = std::string;
using Ints = std::vector<int>;
using Doubles = std::vector<double>;
using Bools = std::vector<bool>;
using Strings = std::vector<std::string>;
using ULLs = std::vector<ULL>;
using LLs = std::vector<LL>;

// pythonのdictionary相当
template <typename T1, typename T2>
using Dict = std::unordered_map<T1,T2>;



int culc(Ints &r, std::vector<Ints> &s, Ints &c){
    int res = 0;
    Ints last(26, 0);

    for(int i=0;i<(int)r.size();i++){
        last[r[i]-1] = i+1;
        for(int j=0;j<26;j++){
            if(r[i]-1==j) res+=s[i][j];
            else res-=c[i]*(i+1-last[j]);
        }
    }

    return res;
}

int main(void) {
    int t = std::clock();

    int D;
    std::cin >> D;
    Ints c;
    std::vector<Ints> s(D, Ints(26, 0));

    for(int i=0;i<26;i++){
        int _c;
        std::cin >> _c;
        c.push_back(_c);
    }

    for(int i=0;i<D;i++){
        for(int j=0;j<26;j++){
            int _s;
            std::cin >> _s;
            s[i][j] = _s;
        }
    }

    Ints res(D, 1);

    for(int i=0;i<D;i++){
        Ints::iterator iter = std::max_element(s[i].begin(), s[i].end());
        size_t index = std::distance(s[i].begin(), iter);
        res[i] = (int)index + 1;
    }

    LL nowp = culc(res, s, c);

    std::random_device rnd;
    std::mt19937 mt(rnd());
    while(std::clock() - t < 1800){
        int day = mt() % D;
        int contest = mt() % 26;
        Ints res_tmp = res;
        res_tmp[day] = contest + 1;
        LL tmpp = culc(res_tmp, s, c);
        if(nowp < tmpp){
            res = res_tmp;
            nowp = tmpp;
        }
    }

    for(auto r : res) std::cout << r << std::endl;

    return 0;
}

Measured memory_bytes: 3708
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll N;
vector<ll> E[200010];
ll cnt[200010];
ll par[200010];
ll dfs(ll now, ll from){
  ll res = 1;
  for(ll to: E[now]){
    if(to == from) continue;
    res += dfs(to, now);
    par[to] = now;
  }
  return cnt[now] = res;
}
void solve(){
  cin >> N;
  rep(i, N-1){
    ll a, b;
    cin >> a >> b;
    a--, b--;
    E[a].pb(b);
    E[b].pb(a);
  }
  par[0] = -1;
  dfs(0, -1);
  ll ans = 0;
  ll _2 = inverse(2);
  rep(i, N){
    if(E[i].size() == 1) continue;
    ll sum = 0;
    vector<ll> x;
    for(ll to: E[i]){
      if(to == par[i]) continue;
      x.pb(cnt[to]);
      sum += cnt[to];
    }
    x.pb(N-sum-1);
    ll add = _2;
    ll bad = 1;
    rep(j, x.size()){
      bad *= pow_mod(_2, x[j]);
      bad %= MOD;
    }
    ll bad_sum = bad;
    rep(j, x.size()){
      bad_sum += bad * inverse(pow_mod(_2, x[j])) % MOD * (1 - pow_mod(_2, x[j]) + MOD) % MOD;
      bad_sum %= MOD;
    }
    ans += _2 * (1 - bad_sum + MOD) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;
}

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


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    int a[n+1];
    ll pre[n+1]; pre[0] = 0;
    FOR(i,1,n) {
        cin >> a[i];
        pre[i] = pre[i-1] + a[i];
    }

    ll dp[n+1][n+1];
    RFOR(i,n,1) {
        dp[i][i] = 0;
        FOR(j,i+1,n) {
            dp[i][j] = 1e18;
            FOR(k,i,j-1) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + pre[j]-pre[i-1]);
            }
        }
    }
    cout << dp[1][n] << '\n';
}



Measured memory_bytes: 1664
#include<stdio.h>//1000 個の "Hello World" を出力するプログラム
 
int main(void){
 
	int data,i;
     
	for(i=1;;i++){
		scanf("%d",&data);
		if(data==0)
			break;
		printf("Case %d: %d\n",i,data);
 	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}

ll i,j,k,ii,jj,n,m,a,b,c,e,f,g,h,r,w,l;
ll num,ans,sum,ok,ng;
ll x[500005],y[500005],z[500005];
ll dp[500][500];
ll p[500005];
ll ran[500005];
char s[500005],t[500005],u[500005];
bool dame,flag;
tuple <ll,ll,ll> road[500005];
tuple <ll,ll,ll> table[500005];


//木の根っこを求める
ll find(ll x){
	if(p[x]==x){
		return x;
	}else{
		return p[x] = find(p[x]);
	}
}

//ｘとｙの属する集合を併合
void unite(ll x,ll y){
	x = find(x);
	y = find(y);
	if(x==y)return;
	if(ran[x]<ran[y]){
		p[x]=y;
	}else{
		p[y]=x;
		if(ran[x]==ran[y])ran[x]++;
	}
}

int main(){
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a >> b;
		c = i + 1;
		get<0>(table[i]) = a;
		get<1>(table[i]) = b;
		get<2>(table[i]) = c;
	}
	sort(table,table + n);
	for(i=0;i<n-1;i++){
		a = abs(get<0>(table[i]) - get<0>(table[i+1]));
		b = abs(get<1>(table[i]) - get<1>(table[i+1])); 
		get<0>(road[num]) = min(a,b);
		get<1>(road[num]) = get<2>(table[i]);
		get<2>(road[num]) = get<2>(table[i+1]);
		num++;
	}
	for(i=0;i<n;i++){
		swap(get<0>(table[i]),get<1>(table[i]));
	}
	sort(table,table+n);
	for(i=0;i<n-1;i++){
		a = abs(get<0>(table[i]) - get<0>(table[i+1]));
		b = abs(get<1>(table[i]) - get<1>(table[i+1])); 
		get<0>(road[num]) = min(a,b);
		get<1>(road[num]) = get<2>(table[i]);
		get<2>(road[num]) = get<2>(table[i+1]);
		num++;
	}
	sort(road,road + 2 * n - 2);
	for(i=1;i<=n;i++)p[i] = i;
	for(i=0;i<2 * n - 2;i++){
		a = get<1>(road[i]);
		b = get<2>(road[i]);
		if(find(a) != find(b)){
			ans += get<0>(road[i]);
			unite(a,b);
		}
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 41344
#include <stdio.h>

static const int MAX_BLOOD_TYPE = 100;

int main(void) {
    int i, j, n, k, blood_quantity[MAX_BLOOD_TYPE], used_blood, flag;

    while (EOF != scanf(" %d %d", &n, &k)) {
        if (k == 0 && n == 0) {
            break;
        }
        flag = 0;

        for (i = 0; i < k; i++) {
            scanf(" %d", &blood_quantity[i]);
        }

        for (i = 0; i < n; i++) {
            for (j = 0; j < k; j++) {
                scanf(" %d", &used_blood);
                blood_quantity[j] -= used_blood;

                if (blood_quantity[j] < 0) {
                    flag = 1;
                }
            }
        }

        printf("%s\n", (flag == 0)?"Yes":"No");
    }


    return 0;
}

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

// Longest Common Subsequence

class LCS {
    string S, T;
    vector <vector<int>> dp;

public:
    LCS(string &s, string &t) : S(s), T(t) {
        int sl = S.size(), tl = T.size();
        dp.assign(sl + 1, vector<int>(tl + 1, 0));

        for (int i = 0; i < sl; i++) {
            for (int j = 0; j < tl; j++) {
                if (S[i] == T[j]) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                } else {
                    dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
                }
            }
        }
    }

    int len() { return dp[S.size()][T.size()]; }

    string str() {
        string ret = "";
        int i = S.size(), j = T.size();
        while (dp[i][j]) {
            if (S[i - 1] == T[j - 1]) {
                i--, j--;
                ret = S[i] + ret;
            } else if (dp[i - 1][j] > dp[i][j - 1]) {
                i--;
            } else {
                j--;
            }
        }
        return ret;
    }
};


// verified
//   http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp
void AOJ_ALDS1_10_C() {
    int q;
    cin >> q;
    while (q--) {
        string x, y;
        cin >> x >> y;
        LCS lcs(x, y);
        cout << lcs.len() << "\n";
    }
}


// verified
//   https://atcoder.jp/contests/dp/tasks/dp_f
void AtCoder_2019_1_6_F() {
    string s, t;
    cin >> s >> t;
    LCS lcs(s, t);
    cout << lcs.str() << '\n';
}

int main() {
    AOJ_ALDS1_10_C();
    // AtCoder_2019_1_6_F();
    return 0;
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin>>N;
  while(N>0){
    vector<ll> v(N);
    FOR(i,0,N){
      cin>>v[i];
    }
    sortAl(v);
    ll res=0;
    FOR(i,1,N-1){
      res+=v[i];
    }
    cout<<res/(N-2)<<endl;
    cin>>N;
  }
}



Measured memory_bytes: 3112
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		int count = 0;
		while (sc.hasNext())
		{
			String str = sc.next();
			int n = str.length();
			loop: {
				for (int i = 0; i < n; i++)
				{
					if (str.charAt(i) != str.charAt(n - (i + 1)))
						break loop;
				}
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 12000