akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


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

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

const long nmax=2000005;

long long fac[nmax],finv[nmax],inv[nmax];

void comint(){
 fac[0]=fac[1]=1;
 finv[0]=finv[1]=1;
 inv[1]=1;
 for(long i=2;i<nmax;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;
}
}

auto com(auto n, auto k){
 if(n<k||n<0||k<0) return 0;
 return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll r1,c1,r2,c2;
  cin >> r1 >> c1 >> r2 >> c2;
  ll res=0;
  comint();
  
  rep(y,c1,c2+1) {
    ll num=com(r2+y+1,y+1)-com(r1+y,y+1);
    num+=mod;
    num%=mod;
    res+=num;
    res%=mod;
  }
   cout << res << endl;
}


Measured memory_bytes: 47104
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}


Measured memory_bytes: 3640
from collections import deque
H,W = map(int,input().split())
S = [["#"]*(W+2)] +[list("#"+input()+"#") for _ in range(H)]+[["#"]*(W+2)]
lis = [[0]*(W+2) for _ in range(H+2)]
q = deque()
ans = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        lis = [[0]*(W+2) for _ in range(H+2)]
        q = deque()
        if S[i][j] == ".":
            q.append([i,j,0])
        else:
            continue
        se = set()
        while q:
            n = q.popleft()
            if lis[n[0]][n[1]]:
                continue
            else:
                lis[n[0]][n[1]] = 1
            #se = se | set([n[0],n[1]])
            ans = max(ans,n[2])
            if S[n[0]][n[1]-1] == ".":
                q.append([n[0],n[1]-1,n[2]+1])
            if S[n[0]][n[1]+1] == ".":
                q.append([n[0],n[1]+1,n[2]+1])
            if S[n[0]-1][n[1]] == ".":
                q.append([n[0]-1,n[1],n[2]+1])
            if S[n[0]+1][n[1]] == ".":
                q.append([n[0]+1,n[1],n[2]+1])
print(ans)

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task ""

using namespace std;
typedef long long ll;

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".in", "r")){
        freopen(Task".in", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    int n; cin >> n;
    vector<int> a(n);
    pair<int, int> mx = mp(0, 0);
    for (int i=0; i<n; ++i){
        cin >> a[i];
        mx = max(mx, mp(a[i], i));
    }
    pair<int, int> res = mp(-1e9, 0);
    for (int i=0; i<n; ++i){
        if (i != mx.se) res = max(res, mp(-max(a[i], mx.fi - a[i]), a[i]));
    }
    cout << mx.fi << ' ' << res.se << '\n';
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

ll N;

ll ans = 0;

void solve( ll s  , bool b1 , bool b2 , bool b3){

	if( s > 10e10 )
		ret;

	if( s >= 100 ){
		if(s <= N && b1 && b2 && b3 ){
			ans += 1;
			//cout << s << endl;
		}
	}

	solve(s*10+3 , 1 , b2 , b3);
	solve(s*10+5 , b1 , 1 , b3);
	solve(s*10+7 , b1 , b2 , 1);
}

int main(){
	cin >> N;
	solve(0 , 0 , 0 , 0 );
	cout << ans << endl;
	ret 0;
}

Measured memory_bytes: 256
import numpy as np

n, k = map(int, input().split())
a = list(map(int, input().split()))

a = np.array(a)
a.sort()

nega = a[a<0]
zero = a[a==0]
posi = a[a>0]

l = -10**18-1
r = 10**18+1
while r - l > 1:
   mid = (r+l)//2
   cnt = 0
   if mid >= 0:
      cnt += len(zero)*n
   cnt += a.searchsorted(mid//posi, side='right').sum()
   cnt += (n - a.searchsorted(-(-mid//nega), side='left')).sum()
   cnt -= np.count_nonzero(a*a <= mid)
   cnt //=2
   if cnt >= k:
      r = mid
   else:
      l= mid

print(r)



Measured memory_bytes: 47644
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
ll m=1000000007;
int main()
{
	fast;
	ll x;
	long long int k,d;
	cin>>x>>k>>d;
	if(x<0)
		x=x*-1;
	ll quo=x/d;
	ll ans=x%d;
	if(k>=quo)
	{
		k=k-quo;
		if(k%2!=0)
		{
			ans=ans-d;
			ans=ans*-1;
		}
	}
	else
		ans=x-(k*d);

	if(ans<0)
		ans=ans*-1;

	cout<<ans;
}

Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F         first
#define S          second
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define hell        1000000007
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 1e9
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e9+1;


using namespace std;
void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);


void solve(){

  int n;
  cin>>n;
  int a[n];
  forn(i,0,n)
  cin>>a[i];

  int ans=0;
  forn(i,0,n-1){
    forn(j,i+1,n)
    {
      ans+=a[i]*a[j];
    }
  }
  cout<<ans;
}


///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1)%hell)*k%hell)%hell;
  else
  return ((pw(k,x/2)%hell)*(pw(k,x/2)%hell))%hell;
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(auto&i:a) cin>>i;
    int l{},r{1000000000},m;
    while(r-l>1){
        m=(l+r)/2;
        ll tmp{};
        fr(i,n) tmp+=(a[i]-1)/m;
        if(tmp>k) l=m;
        else r=m;
    }
    cout<<r<<'\n';
}

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

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back

int main()
{
    int win = 0;
    string str; cin >> str;

    for(char ch : str)
    {
        if(ch == 'o') win++;
    }

    if(win + 15 - str.size() > 7) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


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

typedef long long ll;
const ll INF = (ll)1e18 + 1;

// print(x, y, z);
// print(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

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

  ll N, res;
  std::cin >> N >> res;
  std::vector< ll > va(N, 0LL);

  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  std::sort(va.begin(), va.end());
  ll ans = 0;
  for (ll i = 0; i < N-1; i++) {
    if (res < va[i]) {
      break;
    }
    res -= va[i];
    ans = i+1;
  }

  if (res == va[N-1]) {
    ans++;
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

struct Edge {
	int s;
	int t;
	int w;
	Edge() {}
	Edge(int s, int t, int w) : s(s), t(t), w(w) {}
};

bool operator<(const Edge& e, const Edge& f) { return e.w < f.w; }

int root(int* par, int x)
{
	if (x == par[x]) return x;
	else return par[x] = root(par, par[x]);
}

void unite(int* par, int x, int y)
{
	int rx = root(par, x);
	int ry = root(par, y);
	par[rx] = ry;
}

bool isSame(int* par, int x, int y)
{
	return root(par, x) == root(par, y);
}

int main ()
{
	int n, m;
	std::cin >> n >> m;
	
	Edge* edge_list = new Edge[m];
	int* parent = new int[n];
	for (int i=0; i<n; i++) parent[i] = i;
	
	for (int i=0; i<m; i++) {
		int s, t, w;
		std::cin >> s >> t >> w;
		edge_list[i] = Edge(s, t, w);
	}
	
	std::sort(edge_list, edge_list + m);
	
	int total_weight = 0;
	int edge_count = 0;
	for (int i=0; i<m; i++) {
		int s = edge_list[i].s;
		int t = edge_list[i].t;
		int w = edge_list[i].w;
		if (!isSame(parent, s, t)) {
			unite(parent, s, t);
			total_weight += w;
			edge_count++;
			//std::cout << "(" << s << "," << t << "," << w << ")" << std::endl;
			if (edge_count == n-1) break;
		}
	}
	
	std::cout << total_weight << std::endl;
	
	delete[] parent;
	delete[] edge_list;
	
	return 0;
}



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

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;

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

    int n;
    cin >> n;

    if (n == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    string ans;

    do
    {
        if (n % -2 != 0)
        {
            ans = '1' + ans;
            --n;
        }
        else
        {
            ans = '0' + ans;
        }

        n /= -2;
    } while (n != 0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
A = [-1 for i in range(M)]
B = [-1 for i in range(M)]
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

for i in range(M):
    A[i],B[i] = map(int, input().split())

uf = UnionFind(N)

for i in range(M):
    uf.union(A[i]-1,B[i]-1)

print(uf.group_count()-1)

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

int main(){
  int a,b,c,x,y,kekka = 0;
  cin >> a >> b >> c >> x >> y;
  if(b+a <= 2*c){
    kekka += (a+b)*min(x,y);
    if(x > y){
      kekka += a*(x-y);
    }
    else if(x < y){
      kekka += b*(y-x);
    }
  }
  else{
    kekka += 2*c*min(x,y);
    if(x > y){
      if(a <= 2*c){
        kekka += a*(x-y);
      }
      else{
        kekka += 2*(x-y)*c;
      }
    }
    else if(x < y){
      if(b <= 2*c){
        kekka += b*(y-x);
      }
      else{
        kekka += 2*c*(y-x);
      }
    }
  }
  cout << kekka << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
vector<int> vec;
int c[100010] = { 0 };
int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int co = 1;
	vec.emplace_back(0);
	for (int i = 0; i < n - 1; i++) {
		if (s[i] != s[i + 1]) {
			vec.emplace_back(co);
			co = 1;
		}
		else {
			co++;
			c[i + 1]++;
		}
		c[i + 1] += c[i];
	}
	c[n] += c[n - 1];
	vec.emplace_back(co);
	for (int i = 1; i < vec.size(); i++) {
		vec[i] += vec[i - 1];
	}
	if (vec.size() <= k * 2 + 1) {
		cout << vec[vec.size() - 1] - vec[0] - 1 << endl;
		return 0;
	}
	else {
		int ans = 0;
		for (int i = 2 * k + 1; i < vec.size(); i++) {
			int ans1 = vec[i] - vec[i - 2 * k - 1] + c[vec[i - 2 * k - 1]] + c[n - 1] - c[vec[i]];
			if (ans < ans1) {
				ans = ans1;
			}
		}
		cout << ans - 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF =(1LL<<63)-1; //MAX 9223372036854775807

ll ans = (1LL<<63)-1;

int main()
{
ll n , x ;
cin >> n >> x ;
vector<ll> t(n);
rep(i, n){
  cin >> t[i];
}
vector<ll> s;
s.push_back(0);
rep(i,n){
  s.push_back(t[i]+s[i]);
}
auto kei = [](ll y){if(y==1)return 5LL; else return y*2+1;};
rep(i,n){
  ll j=n;
  ll te=0;
  ll co=1;
  while(j>0){
    te+=kei(co)*(s[j]-s[(j-(i+1)<0) ? 0:j-(i+1)]);
    co++;
    j-=(i+1);
  }
  if(te+(i+1)*x>0)ans=min(te+(i+1)*x,ans);
}
cout << ans+n*x << endl;
return 0;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(T x,T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> T modinv(T x,const T mod){return modpow(x,mod-2,mod);}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getdiff(const T &a,const T &b,T &c) {
  set_difference(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> T deg2rad(T deg) {return deg*2*M_PI/360;}
template<class T> T rad2deg(T rad) {return rad*360/(2*M_PI);}

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

const ll MOD=1e9+7;
const ll MAX=5e6;


int main() {
  string s,t;cin>>s>>t;
  map<char,vector<int>> mp;
  REP(i,siz(s)) mp[s[i]].push_back(i);

  REP(i,siz(t)) {
    if (siz(mp[t[i]])==0) {
      OUT(-1);
      return 0;
    }
  }

  ll ans = 0;
  int tmp = 0;

  REP(i,siz(t)) {
    auto it = lower_bound(ALL(mp[t[i]]),tmp);
    // 一周して戻ってくる
    if (it==mp[t[i]].end()) {
      ans += (mp[t[i]].front()+1)+(siz(s)-tmp);
      tmp = (mp[t[i]].front()+1)%siz(s);
    } else {
      ans += *it-tmp+1;
      tmp = (*it+1)%siz(s);
    }
  }
  OUT(ans);


  return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<vector>
#include<numeric>
#include<set>
#include<algorithm>

using namespace std;

class UF{
  vector<int> v;
public:
  UF(int n):v(n+1){
    iota(begin(v),end(v),0);
  }
  int find(int x){
    return (x==v[x])?x:v[x]=find(v[x]);
  }
  void unite(int a,int b){
    v[find(a)]=find(b);
  }
};

struct edge{
  int a,b,c;
  bool operator<(edge e)const{
    return c<e.c;
  }
};

int main(){
  for(int N,M;cin>>N>>M,N;){
    int h[201];
    set<int> s{0};
    for(int i=1;i<=N;i++){
      cin>>h[i];
      s.insert(h[i]);
    }
    int a[40000],b[40000],c[40000];
    for(int i=0;i<M;i++){
      cin>>a[i]>>b[i]>>c[i];
    }
    int t=1<<29;
    for(auto e:s){
      UF uf(N+1);
      for(int i=0;i<M;i++){
	if(h[a[i]]>e&&h[b[i]]>e){
	  uf.unite(a[i],b[i]);
	}
      }
      set<int> ri;
      for(int i=1;i<=N;i++){
	if(h[i]>e){
	  ri.insert(uf.find(i));
	}
      }
      if(ri.size()>1){
	t=e;
	break;
      }
    }
    if(t==0){
      cout<<0<<endl;
    }else{
      vector<edge> v;
      for(int i=0;i<M;i++){
	if(h[a[i]]>=t&&h[b[i]]>=t){
	  v.push_back({a[i],b[i],c[i]});
	}
      }
      sort(begin(v),end(v));
      UF kuf(N+1);
      int w=0;
      for(auto e:v){
	if(kuf.find(e.a)!=kuf.find(e.b)){
	  kuf.unite(e.a,e.b);
	  w+=e.c;
	}
      }
      vector<int> et(begin(s),end(s));
      reverse(begin(et),end(et));
      for(auto e:et){
	vector<edge> cv;
	for(int i=0;i<M;i++){
	  if(h[a[i]]>=e&&h[b[i]]>=e){
	    cv.push_back({a[i],b[i],c[i]});
	  }
	}
	sort(begin(cv),end(cv));
	for(auto f:cv){
	  if(kuf.find(f.a)!=kuf.find(f.b)){
	    kuf.unite(f.a,f.b);
	    w+=f.c;
	  }
	}
      }
      cout<<w<<endl;
    }
  }
}

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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

bool IsPrime(int);

/***** MAIN *****/
signed main() {
  int a, b;
  cin >> a >> b;
  int ans = a+b;
  ans = max(ans, a-b);
  ans = max(ans, a*b);
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/

bool IsPrime(int a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(int i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}


signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,m,k;
    cin>>n>>m>>k;
    int x,y;
    cin>>x>>y;
    string s,t;
    cin>>s>>t;
    int xx=0;
    for(int i=0;i<k;i++)
    {
        if(s[i]=='L')
            xx++;
        if(xx>=y)
        {
            cout<<"NO";
            return 0;
        }
        if(t[i]=='R')
        {
            if(xx<=0)
            {
                if(abs(xx)+y+1>m)
                    continue;
            }
                xx--;
        }
    }
    xx=0;
    for(int i=0;i<k;i++)
    {
        if(s[i]=='R')
            xx++;
        if(xx+y>m)
        {
            cout<<"NO";
            return 0;
        }
        if(t[i]=='L')
        {
            if(xx<=0)
            {
                if(abs(xx)+1>=y)
                    continue;
            }
                xx--;
        }
    }
    xx=0;
    for(int i=0;i<k;i++)
    {
        if(s[i]=='U')
            xx++;
        if(xx>=x)
        {
            cout<<"NO";
            return 0;
        }
        if(t[i]=='D')
        {
            if(xx<=0)
            {
                if(abs(xx)+x+1>n)
                    continue;
            }
                xx--;
        }
    }
    xx=0;
    for(int i=0;i<k;i++)
    {
        if(s[i]=='D')
            xx++;
        if(xx+x>n)
        {
            cout<<"NO";
            return 0;
        }
        if(t[i]=='U')
        {
            if(xx<=0)
            {
                if(abs(xx)+1>=x)
                    continue;
            }
                xx--;
        }
    }
    cout<<"YES";

} 
    


Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int n;
    cin >> n;
    int A[n+1];
    int total = 0;
    int res = INF;
    REP(i,n){
        cin >> A[i];
        total += A[i];
    }
    int su = 0;
    res = total;
    REP(i,n){
        su += A[i];
        res = min(res, abs( (total - su) - su)); 
    }
    cout << res << endl;


}


Measured memory_bytes: 256
def main():

    D, G = map(int, input().split())
    A = []
    for i in range(D):
        p, c = map(int, input().split())
        A.append([i, p, c])
    A = A[::-1]

    cur = [[0, 0]]
    used = [set()]

    for i, p, c in A:
        temp = []
        temp_used = []
        for j in range(len(cur)):
            temp.append(cur[j])
            temp_used.append(used[j])
            temp.append([cur[j][0]+ 100*(i+1)*p+c, cur[j][1] + p])
            temp_used.append(used[j] | {i})
        cur = temp
        used = temp_used
    # 
    # print(cur)
    # print(used)

    ans = float('inf')
    for j in range(len(cur)):
        if cur[j][0] >= G:
            ans = min(ans, cur[j][1])
        else:
            for i, p, c in A:
                if i not in used[j]:
                    if cur[j][0] + 100 * (i+1) * (p-1) < G:
                        cur[j][0] += 100 * (i+1) * (p-1)
                        cur[j][1] += p-1
                    else:
                        if (G - cur[j][0]) % (100*(i+1)) == 0:
                            ans = min(ans, cur[j][1] + (G - cur[j][0]) // (100*(i+1)))
                        else:
                            ans = min(ans, cur[j][1] + (G - cur[j][0]) // (100*(i+1)) + 1)
                        break
    return ans



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

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

using namespace std;
 
#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	    unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      	    cout<<"#x "<<x<<"\n";
#define trace(x,y)  	    cout<<"#x "<<x<<" #y "<<y<<"\n";
#define cn          	    cout<<"\n";


bool SBF(const pair <int,int>&a, const pair<int,int>& b){return a.F<b.F;}
bool SBS(const pair<int,int>& a, const pair<int,int>& b){return a.S<b.S;}


const long double PI = 3.1415926535;
const int         mod= 1e9+ 7; 

ll n, k;


void solve(){
    cin >> n;
    ll a[2*n];
    for(int i=0;i<2*n;i++)cin >>a[i];
    sort(a, a+2*n);
    ll sum = 0;
    for(int i=0;i<2*n; i+=2){
	    sum += min(a[i], a[i+1]);
    }
    cout<<sum<<"\n";
	
	return ;
}








int main(){
	solve();
return 0;
}


Measured memory_bytes: 256
// AOJ 0272: The Lonely Girl's Lie
// 2017.10.14 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

#define MAX 280000

int a[40003], b[40003];
char buf[280001], *p;

int getInt()
{
	int n = 0;
	if (*p == ' ') p++;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int cmp(int *a, int *b) { return *b - *a; }

int main()
{
	int n, i, k, ans;

	while (fgets(p = buf, 20, stdin) && *p != '0') {
		n = getInt();

		fgets(p = buf, MAX, stdin);
		for (i = 0; i < n; i++) a[i] = getInt();
		fgets(p = buf, MAX, stdin);
		for (i = 0; i < n; i++) b[i] = getInt();

		qsort(a, n, sizeof(int), cmp);
		qsort(b, n, sizeof(int), cmp);

		for (ans = n, i = k = 0; k < n; i++, k += 2) {
			if (a[k] > b[i]) { ans = k + 1; break; }
		}
		if (ans == n) puts("NA");
		else printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2384
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
    VECCIN(head);
    VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
    seco[head]=IN();
    VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    CIN(n);SCIN(s);

    V ruiw(n,0);//Wにする人数
    ruiw[0]=(s[0]=='W');
    REP(i,n){
        if(!i)continue;
        ruiw[i]=ruiw[i-1]+(s[i]=='W');
    }
    V ruie(n,0);
    ruie[n-1]=(s[n-1]=='E');
    REPR(i,n-2)
        ruie[i]=ruie[i+1]+(s[i]=='E');
    int ans=INF;
    REP(i,n){
        int count = (i==0?0:ruiw[i-1]) + (i==n-1?0:ruie[i+1]);
        ans=min(ans,count);
    }
    COUT(ans);

    return 0;
}

Measured memory_bytes: 5380
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<set>
#include<fstream>
#include<map>
#include<vector>
using namespace std;
int main(){
	int h,w;
	while(cin >> h >> w && h||w){
		for(int i=0;i<h;i++){
		for(int j=0;j<w;j++) cout<<"#";
		cout<<endl;
	}
	    cout<<endl;
	}
}



Measured memory_bytes: 3092
n, h = map(int, input().split())

atk = []
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    atk.append((a, 0))
    atk.append((b, 1))

atk.sort(key=lambda x: x[0], reverse=True)

for blade in atk:
    if blade[1] == 0:
        break
    else:
        h = max(0, h - blade[0])
        ans += 1
        if h <= 0:
            break

print(ans-(-h//blade[0]))


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

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

long X,K,D;
int main(){
    int N;
    long sum=0;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A.at(i);

    for(int i=0;i<N-1;i++){
        if(A.at(i+1) < A.at(i)){
  //          cout << i << endl;
            sum += A.at(i) - A.at(i+1);
            A.at(i+1) = A.at(i);
        }
   //     cout << sum << endl;
    }

    cout << sum << endl;


}


Measured memory_bytes: 4052
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
ll ppow(ll x, ll n) {
	ll ans = 1;
	while (n > 0) {
		if ((n & 1) == 1)ans = ans * x;
		x = x * x;
		n >>= 1;
		x %= mod;
		ans %= mod;
	}
	return ans;
}
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll sz, fact[N], inv[N];
void setinv() {
	fact[0] = 1; inv[0] = 1;
	for (int i =1; i <= sz; i++) {
		fact[i] = (fact[i - 1] * i) % mod;  //階乗を求める
		inv[i] = ppow(fact[i], (ll)mod - 2) % mod; // フェルマーの小定理で逆元を求める
	}
}
ll conv(ll r) {//nCr
	return fact[sz] * inv[r] % mod * inv[sz - r] % mod;
}
int n, v[100],ans=0,now;
int main() {
	cin >> n;
	rep(i,n )cin >> v[i];
	sort(v, v + n);
	rep(i, n) {
		if (i == 0)now = v[i], ++ans;
		else {
			if (now < v[i]) { ++ans; now = v[i]; }
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int a;
    
    int b;
    
    int c;
    
    cin >> a >> b >> c;
    
    if(a < b&&b < c){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" <<endl;
    }
return 0;
}


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

int main(){
    string s;
    ll a,b,u,ans;
    cin >> s;
    a = s.length();
    rep(i,a)cout << "x";
//    cout << ans;
    return 0;
}


Measured memory_bytes: 256
S = input()
if S[0] != "A":
    print("WA")
    exit()
num_C = 0
pos_C = 0
for i in range(2, len(S) - 1):
    if S[i] == "C":
        num_C += 1
        pos_C = i
if num_C != 1:
    print("WA")
    exit()
for i in range(1, len(S)):
    if i == pos_C:
        continue
    if S[i].isupper():
        print("WA")
        exit()
print("AC")


Measured memory_bytes: 3060
Num=int(input())
Str=input()

Letters =list('A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'.split())

Ans=''
for i in range(len(Str)):
  Index = Letters.index(Str[i])
  if Index + Num < 26:
    Ans += Letters [Index + Num]
  else:
    Diff = (Index + Num) - 26
    Ans += Letters [Diff ]
  
print(Ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;
ll k,a[225816];
bool judge(ll x){
	int i;
	ll cnt=0ll;
	for(i=0; i<n; ++i){
		cnt += (a[i]-1)/x;
	}
	return (k>=cnt);
}

int main(void){
	int i;
	ll ok = MOD, ng = 0ll, med;
	std::cin >> n >> k;
	for(i=0; i<n; ++i){
		std::cin >> a[i];
	}
	while(ok-ng>1ll){
		med = (ok+ng)/2;
		if(judge(med)){
			ok = med;
		}else{
			ng = med;
		}
	}
	std::cout << ok << std::endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug1(x) cout<<#x<<" : "<<x<<endl
#define debug2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl

typedef long long ll;
typedef pair<ll,ll> pii;
const ll modd=1e9+7;

ll poww(ll a,ll b){
  ll ans=1;
  while(b>0){
    if(b%2==1) ans=(ans*a);
    a=(a*a);
    b=b/2;
  }
  return ans;
}

/*-----------------------------------------------------------------------*/

ll n,k;
ll mat[51][51];
ll ide[51][51];

void mul1(){
	ll copy[51][51]={0};

    for(ll i=1;i<=n;i++)
    	for(ll j=1;j<=n;j++)
    		for(ll k=1;k<=n;k++)
    			copy[i][j]=(copy[i][j]+ide[i][k]*mat[k][j])%modd;

    for(ll i=1;i<=n;i++)
    	for(ll j=1;j<=n;j++)
    		ide[i][j]=copy[i][j];

}

void mul2(){
	ll copy[51][51]={0};

    for(ll i=1;i<=n;i++)
    	for(ll j=1;j<=n;j++)
    		for(ll k=1;k<=n;k++)
    			copy[i][j]=(copy[i][j]+mat[i][k]*mat[k][j])%modd;

    for(ll i=1;i<=n;i++)
    	for(ll j=1;j<=n;j++)
    		mat[i][j]=copy[i][j];

}

void poww1(){
	while(k>0){
		if(k%2==1)
			mul1();
		k=k/2;
		mul2();
	}
}

int main(){
   fastt;

   cin>>n>>k;

   for(ll i=1;i<=n;i++)
   	   for(ll j=1;j<=n;j++){
   	   	   cin>>mat[i][j];
   	   	   if(i==j)
   	   	   	  ide[i][i]=1;
   	   }

   poww1();

   ll ans=0;

   for(ll i=1;i<=n;i++)
   	   for(ll j=1;j<=n;j++)
   	   	   ans=(ans+ide[i][j])%modd;

   cout<<ans<<endl;

   return 0;
}


Measured memory_bytes: 384
class BIT():
    def __init__(self,n):
        self.BIT=[0]*(n+1)
        self.num=n

    def query(self,idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def update(self,idx,x):
        while idx <= self.num:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return

def comp(L):
    S=list(set(L))
    S.sort()
    return {i:e for e,i in enumerate(S)}

import sys,random

input=sys.stdin.readline

N=int(input())
A=[0]*N;B=[0]*N;C=[0]*N
for i in range(N):
    A[i],B[i],C[i]=map(int,input().split())

line=[(A[i]/B[i],i) for i in range(N)]
line.sort()
line=[line[i][1] for i in range(N)]

line2=[(B[i]/A[i],i) for i in range(N)]
line2.sort()
line2=[line2[i][1] for i in range(N)]

def cond(n):
    tempC=[C[i]-n*A[i] for i in range(N)]
    data=[tempC[i]/B[i] for i in range(N)]
    data=comp(data)
    bit=BIT(len(data))
    res=0
    for i in range(N):
        id2=data[tempC[line[i]]/B[line[i]]]
        res+=i-bit.query(id2)
        bit.update(id2+1,1)
    num=N*(N-1)//2
    return res>=(num+1)//2

def cond2(n):
    tempC=[C[i]-n*B[i] for i in range(N)]
    data=[tempC[i]/A[i] for i in range(N)]
    data=comp(data)
    bit=BIT(len(data))
    res=0
    for i in range(N):
        id2=data[tempC[line2[i]]/A[line2[i]]]
        res+=i-bit.query(id2)
        bit.update(id2+1,1)
    num=N*(N-1)//2
    return res>=(num+1)//2

start=-2*10**8
end=2*10**8
count=0
while end-start>10**-9:
    count+=1
    test=(end+start)/2
    if cond(test):
        end=test
    else:
        start=test
    if (end-start)*10**9<min(abs(start),abs(end)):
        break

start2=-2*10**8
end2=2*10**8
while end2-start2>10**-9:
    test=(end2+start2)/2
    count+=1
    if cond2(test):
        end2=test
    else:
        start2=test
    if (end2-start2)*10**9<min(abs(start2),abs(end2)):
        break

print(end,end2)
#print(count)


Measured memory_bytes: 247088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }







int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int n;
    cin >> n;
    vector<int> v[n];
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a].eb(b);
        v[b].eb(a);
    }
    
    
    const int maxn = 100005;
    int reached[maxn];
    fill_n(reached, maxn, inf);
    
    queue<int> q;
    q.push(0);
    reached[0] = 0;
    
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        
        for (int nxt : v[now]) {
            if (reached[nxt] < reached[now] + 1) continue;
            reached[nxt] = reached[now] + 1;
            q.push(nxt);
        }
    }
    
    
    int reached2[maxn];
    fill_n(reached2, maxn, inf);
    
    q.push(n - 1);
    reached2[n - 1] = 0;
    
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        
        for (int nxt : v[now]) {
            if (reached2[nxt] < reached2[now] + 1) continue;
            reached2[nxt] = reached2[now] + 1;
            q.push(nxt);
        }
    }
    
    int f = 0, s = 0;
    rep(i, n) {
        if (reached[i] <= reached2[i]) {
            f++;
        } else {
            s++;
        }
    }
    if (f > s) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}


Measured memory_bytes: 6528
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

ans=0
for i in range(int(input())):
    b=int(input())
    ans+=(is_prime(b))
    
print(ans)


Measured memory_bytes: 5676
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
string s,t;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int ans=0;
	s="CODEFESTIVAL2016";
	cin>>t;
	for(int i=0;i<16;i++)
	if(s[i]!=t[i])ans++;
	cout<<ans<<"\n"; 
	return 0;
} 

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
const int MOD = 1e9+7;
//}}}

int H, W;
char s[51][51];
int mp[51][51];

typedef struct{
	int x;
	int y;
} Pos;
queue<Pos> qu;

void f(int x, int y, int num){
	if(x < 0 || W <= x) return;
	if(y < 0 || H <= y) return;
	if(s[y][x] == '.' && mp[y][x] == 0){
		mp[y][x] = num + 1;
		Pos p = {x, y};
		qu.push(p);
	}
}

int main(void){
	cin >> H >> W;
	rep(i, H) cin >> s[i];
	int total = 0;
	rep(i, H){
		rep(j, W){
			if(s[i][j] == '.') total++;
		}
	}

	Pos p = {0, 0};
	qu.push(p);
	mp[0][0] = 1;
	while(!qu.empty()){
		Pos pos = qu.front();
		qu.pop();
		int x = pos.x;
		int y = pos.y;
		int num = mp[y][x];
		f(x - 1, y, num);
		f(x + 1, y, num);
		f(x, y - 1, num);
		f(x, y + 1, num);
	}
	if(mp[H-1][W-1] == 0){
		puts("-1");
	}else{
		printf("%d\n", total - mp[H-1][W-1]);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  string board[H];
  for(int i=0;i<H;i++){cin >> board[i];}
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(board[i][j]=='.'){
        int temp = 0;
        for(int k=-1;k<=1;k++){for(int l=-1;l<=1;l++){
          int temp_h = i+k;
          int temp_w = j+l;
          if(temp_h>=0 && temp_h<H && temp_w>=0 && temp_w<W){
            temp += (board[temp_h][temp_w]=='#');
          }
        }}
        cout << temp;
        
      }else{
        cout << '#';
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

const int INF = 10000000;
typedef pair<int, int> P;
int ans = 0;

void dfs(const Graph &G, int v, vector<bool> &seen) {
  seen[v] = true;
  int loop_times = 0;
  for (auto next_v : G[v]) {
    if (seen[next_v]) {
      continue;
    }
    vector<bool> next_seen;
    next_seen = seen;
    dfs(G, next_v, next_seen);
    loop_times++;
  }
  if (loop_times == 0) {
    // cout << v << " "
    //      << "finish" << endl;
    ans++;
    for (int i = 1; i < seen.size(); i++) {
      // cout << seen[i] << endl;
      if (seen[i] == false) {
        ans--;
        break;
      }
    }
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  Graph G(N + 1);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<bool> seen;
  seen.assign(N + 1, false);
  dfs(G, 1, seen);
  cout << ans << endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  bool flag=0;
  if(N%2==0){
    int cnt=1;
    for(int i=0; i<N; i+=2){
      if(A.at(i)!=cnt || A.at(i+1)!=cnt) flag=1;
      cnt+=2;
    }
  }
  else{
    int cnt=2;
    if(A.at(0)!=0) flag=1;
    for(int i=1; i<N; i+=2){
      if(A.at(i)!=cnt || A.at(i+1)!=cnt) flag=1;
      cnt+=2;
    }
  }
  if(flag==1) cout << 0 << endl;
  else{
    int ans=1;
    for(int i=0; i<N/2; i++) ans=ans*2%1000000007;
    cout << ans << endl;
  }
}

Measured memory_bytes: 640
object Main extends App {
  val src = io.Source.stdin.getLines.map(_.split("").map(_.toInt).toList)

  def bottomMost(li: List[Int]): List[Int] = {
    if (li.length == 1) li
    else bottomMost(bottomList(li))
  }

  def bottomList(li: List[Int]): List[Int] = li match {
    case h1 :: h2 :: tail => (h1+h2) :: bottomList(h2 :: tail)
    case _ => Nil
  }

  for (li <- src) println(bottomMost(li).head.toString.last)
}

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

public class Hello{
    public static void Main(){
        // Your code here!
        string S = Console.ReadLine();
        string[] divide = new string[]{"dream", "dreamer", "erase", "eraser"};
        
        S = string.Join("",S.Reverse());
        
        
        
        for(int i = 0; i < divide.Length; i++)
        {
            divide[i] = string.Join("", divide[i].Reverse());
        }
        bool can = true;
        
        for(int i = 0; i < S.Length;)
        {
            
            bool can2 = false;
            for(int j = 0; j < divide.Length; j++)
            {
                string d = divide[j];
                if(S.Length - i  < d.Length)
                {
                    continue;
                }
                else if(S.Substring(i, d.Length) == d) //divide[i]で分割できたら
                {
                    can2 = true;
                    i += d.Length;
                }
                
            }
            
            if(can2 == false)
            {
                
                can = false;
                break;
            }
        }
        
        if(can) Console.WriteLine("YES");
        else Console.WriteLine("NO");
        
    }
}


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

using namespace std;

const int N = 1e5;

int n, a[N + 1], b[N + 1], c[N + 1], dp[N + 1][3];

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

	cin >> n;
	for (int i = 1; i <= n; ++i)
		scanf("%d%d%d", a + i, b + i, c + i);

	dp[1][0] = a[1];
	dp[1][1] = b[1];
	dp[1][2] = c[1];

	for (int i = 2; i <= n; ++i) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i];
	}

	cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}


Measured memory_bytes: 6008