akhauriyash/Code-Regression huggingface dataset:
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 998244353;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int powrr[3001];

int power(int base, int exp) {
    int res=1;
    while (exp > 0) {
       if (exp % 2 == 1) res = (res * base) % mod;
       base = (base * base) % mod;
       exp /= 2;
    }
    return res % mod;
}

void calc() {
  int s = 0;
  powrr[0] = 1;
  s = 0;
  for (int i = 1; i <= 3000; i++) {
    s = power(2, i);
    s %= mod;
    powrr[i] = s;
  }
}

int dp[3002][3002];
vector<int> vc;
int n, s;

int rec(int idx, int sum) {
  if (sum > s) return 0;
  if (sum == s) {
    return powrr[n - idx];
  }  
  if (idx == n) return 0;
  int &ans = dp[idx][sum];
  if (ans != -1) return ans;
  ans = rec(idx + 1, sum + vc[idx]);
  ans += (2 * rec(idx + 1, sum));
  ans %= mod;
  return ans;
}

int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  calc();
  memset(dp, -1, sizeof dp);
  cin >> n >> s;
  vc.resize(n);
  for (auto &i: vc) cin >> i;
  cout << rec(0, 0) << endl;
  return 0;
}


Measured memory_bytes: 74212
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
constexpr i64 INF = 1LL << 60;

struct edge {
	int from, to;
	i64 cost;
	edge(int f, int t, i64 c): from(f), to(t), cost(c) {}
};

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

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

	vector<edge> edges;
	rep(i, 0, m) {
		int a, b;
		i64 c;
		cin >> a >> b >> c;
		--a, --b;
		edges.emplace_back(a, b, -c);
	}

	vector<i64> dist(n, INF);
	dist[0] = 0;
	rep(i, 0, n) {
		bool updated = false;
		for (edge e : edges) {
			if (dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost) {
				dist[e.to] = dist[e.from] + e.cost;
				if (i == n - 1 && e.to == n - 1) {
					cout << "inf" << '\n';
					return 0;
				}
			}
		}
	}

	cout << -dist[n - 1] << '\n';
	return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

struct Graph {
  vector<vector<int>> edge;
  Graph(int n = 0) { resize(n); }
  void resize(int n) { edge.resize(n, vector<int>()); }
  void addEdge(int from, int to) {
    edge[from].push_back(to); edge[to].push_back(from);
  }
  vector<int>& operator[](int from) { return edge[from]; }
};
int N, M;
vector<ll> dp, ans;
vector<vector<ll>> mul, mul2;

ll dfs(Graph& G, int cur, int prev) {
  if (dp[cur] != -1) return dp[cur];
  dp[cur] = 1;
  for (int to : G[cur]) {
    if (to == prev) continue;
    (dp[cur] *= (dfs(G, to, cur) + 1) % M) %= M;
  }
  return dp[cur];
}
void dfs2(Graph& G, int cur, int prev) {
  vector<ll> v;
  for (int to : G[cur]) {
    if (to != prev) {
      v.push_back((dp[to] + 1) % M);
      continue;
    }
    int i = all(lower_bound, G[to], cur) - G[to].begin();
    v.push_back((mul[to][i] * mul2[to][i+1] + 1) % M);
  }
  ll m1 = 1, m2 = 1;
  int n = v.size();
  rep(i, n) {
    mul[cur].push_back((m1 *= v[i]) %= M);
    mul2[cur].push_back((m2 *= v[n-1-i]) %= M);
  }
  all(reverse, mul2[cur]);
  ans[cur] = (mul[cur][0] * mul2[cur][0]) % M;
  for (int to : G[cur]) {
    if (to == prev) continue;
    dfs2(G, to, cur);
  }
}

int main() {
  cin >> N >> M;

  Graph G(N);
  mul.resize(N, vector<ll>{1});
  mul2.resize(N, vector<ll>{1});
  dp.resize(N, -1);
  ans.resize(N, 1);
  rep(i, N-1) {
    int x, y; cin >> x >> y;
    --x, --y;
    G.addEdge(x, y);
  }
  rep(i, N) {
    all(sort, G[i]);
  }
  dfs(G, 0, -1);
  dfs2(G, 0, -1);
  rep(i, N) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 37488
#coding:utf-8
n = int(input())
d = []
for i in range(n):
    d.append(int(input()))
d.sort()

dm = 0
count = 1
for i in range(1, n):
    dm = d[i]-d[i-1]
    if dm > 0:
        count += 1
print(count)

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */
int main(){
    string s; cin >> s;
    int q; cin >> q;
    int flip = 0;
    string head = "", foot = "";
    rep(i, q){
        int j; cin >> j;
        if(j == 1) flip++;
        else{
            int f; string c; cin >> f >> c;
            if((f+flip) % 2 == 0){
                foot += c;
            }else{
                head += c;
            }
        }
    }

    string ans;
    if(flip % 2 == 1){
        reverse(s.begin(), s.end());
        reverse(foot.begin(), foot.end());
        ans = foot + s + head;
    }
    else{
        reverse(head.begin(), head.end());
        ans = head + s + foot;
    }
    out(ans);
}

Measured memory_bytes: 1348
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        if (s.contains("RRR")) System.out.println(3);
        else if (s.contains("RR")) System.out.println(2);
        else if (s.contains("R")) System.out.println(1);
        else System.out.println(0);
    }
}


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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))



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

int gcd(int a,int b);

int main(void)
{
  int n,k;
  scanf("%d%d",&n,&k);
  int i;
  REP(i,10000000)
  {
    if(i*(k-1)+1>=n&&(i-1)*(k-1)+1<n)
    {
      printf("%d",i);
      break;
    }
  }
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}



    

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

int main() {
  int n ;
  int sa,sb =0;
  cin >> n;
  vector<int> con(n);
  for(int i=0;i<n;i++ )
    cin >> con[i];
  
  sort(con.begin(), con.end(), greater<int>());

  
  for( int i= 0;i< n;i++){

    if( i % 2 ==0)
    sa += con[i];
    else
    sb += con[i];
  }

  cout << sa - sb << endl;
}

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

int main() {
	int a, b, c;
	int count = 0;
	list<int> numberlist;

	cin >> a >> b >> c;

	for (int k = a; k <= b; k++) {
		if (c % k == 0) {
			count++;
		}
	}

	cout << count << endl;
}

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

#define ll long long int

using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n);
    for (auto & a : A) {
        cin >> a;
    }

    ll cur = 0;
    ll sum = 0;
    for (auto a : A) {
        if (cur >= a) {
            sum += (cur - a);
        } else if (cur < a) {
            cur = a;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> Plp;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

vector<vector<ll>> d(305, vector<ll>(305,1e18));

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}
int main(){
    ll N;
    cin >> N;
    vector<vector<ll>> A(N,vector<ll>(N)), G(N);
    rep(i,N){
        rep(j,N){
            cin >> A[i][j];
            d[i][j] = A[i][j];
        }
    }
    warshall_floyd(N);
    ll ans = 0;
    rep(i,N){
        REP(j,i+1,N){
            if(d[i][j] < A[i][j]){
                cout << -1 << endl;
                return 0;
            }
            //if(d[i][j] > A[i][j]){
                //d[i][j] = 1e18;
                //d[j][i] = 1e18;
                //continue;
            //}
            bool flag =false;
            rep(k,N){
                if(k==j||k==i)continue;
                if(d[i][j] == d[i][k] + d[k][j]){
                    flag = true;
                    break;
                }
            }
            if(flag)continue;
            ans += A[i][j];
        }
    }
    cout << ans << endl;
    /*
    UnionFind<ll> uf(N);
    rep(i,N){
        REP(j,i+1,N){
            //if(0 == j)continue;
            uf.merge(i,j,A[i][j]);
        }
    }
    ll ans = 0;
    rep(i,1)REP(j,i+1,N){
        ans += uf.diff(i,j);
    }
    rep(i,N)REP(j,i+1,N){
        //if(i == j) continue;
        if(A[i][j] != uf.diff(i,j)){
            if(A[i][j] < uf.diff(i,j)){
                ans += A[i][j];
            }else{
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    /*
    map<Pll,ll> mp;
    rep(i,N){
        ll mi = 1e18;
        ll id = -1;
        rep(j,N){
            if(i==j)continue;
            if(mi > A[i][j]){
                mi = A[i][j];
                id = j;
            }
        }
        G[i].push_back(id);
        G[id].push_back(i);
        mp[Pll(i,id)]++;
        mp[Pll(id,i)]++;
    }
    cout << N << endl;*/
}

Measured memory_bytes: 5056
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const double pi = acos(-1);
const int mod = 998244353;
const double eps = 1e-8;
map<ll,ll> mp;
ll a[maxn];

int main(){     	
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%lld",&a[i]);
		mp[a[i]]++;
	}
	map<ll,ll>::iterator it;
	ll sum = 0;
	for(it = mp.begin();it != mp.end();it++){
		if(it->second >= 2){
			sum += it->second*(it->second-1)/2;
		}
	}
	for(int i = 1;i <= n;i++){
		ll k = mp[a[i]];
		if(k >= 2) printf("%lld\n",sum-k*(k-1)/2+(k-1)*(k-2)/2);
		else printf("%lld\n",sum);
	}
    return 0;
}


Measured memory_bytes: 11008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<int> h(n),t(n,0);
    rep(j,0,n) cin >> h[j];
    rep(i,0,m) {
        int a, b;
        cin >> a >> b;
        --a,--b;
        if (h[a]<h[b]) t[a]++; 
        if (h[a]>h[b]) t[b]++;
        if (h[a]==h[b]) {
            t[a]++; 
            t[b]++; 
        }
    }
    int cnt=0;
    rep(i,0,n) if (t[i]!=0) cnt++;
    cout << n-cnt << endl;
    return 0;
}

Measured memory_bytes: 3672
//#include"cpp_kyopro.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include<stdio.h>

using namespace std;
int main() {
	int n, m; cin >> n >> m;
	vector<int> a(m), b(m), ans(n);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < n; i++)cout << (count(a.begin(), a.end(), i+1)+count(b.begin(),b.end(),i+1) )<< endl;
	return 0;
 }




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

char a;
string s;

main(){
    a = getchar();
    cin >> s;
    for(auto i : s)if(i != 57)return 0 & printf("%lld", s.size() * 9 + a - 49);
    cout << s.size() * 9 + a - 48 << endl;
    return 0;
}

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

int main() {
	int64_t N;
	cin >> N;
	int64_t i, j, k;
	bool frag = false;
	
	for (i = 1; i <= 3500; i++) {
		for (j = 1; j <= 3500; j++) {
			int64_t L = 4*i*j - N*i - N*j;
			int64_t R = N*i*j;
			if ( L > 0 ) {
				if ( R % L == 0 ) {
					//cout << L << " " << R << endl;
					k = R / L;
					frag = true;
					break;
				}
			}
		}
		if (frag) {
			break;
		}
	}
	//int64_t L = 4*i*j*k;
	//int64_t R = N*(i*j + j*k + k*i);
	//cout << L << " " << R << endl;
	cout << i << " " << j << " " << k << endl;				

}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<string>
#include<sstream>
#include<vector>
const int n=1000;
char arr[n][n];
using namespace std;
int main()
{
    int h,w;
    cin>>h>>w;
    vector<string>vec;

    for(int i=0 ;i<h;i++)
    {
         string val;  cin>>val;vec.push_back(val);
    }
     for(int i=0 ;i<h;i++)
    {
        cout<<vec[i]<<endl<<vec[i]<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
using namespace std;
int main() {
	int a, b,c=0;
	cin >> a >> b;
	if (a > b) { c = a + a - 1; }
	else if (a < b) { c = b + b - 1; }
	else { c = a + a; }
	cout << c;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())
#define UNIQUE(v) \
    SORT(v);      \
    v.resize(distance(v.begin(), unique(v.begin(), v.end())))

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

const ll md = 1e9 + 7;
ll MOD(ll x) {
    ll r = x % md;
    if (r < 0) {
        r += md;
    }
    return r;
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF DBL_MAX
// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 1e18
#define MINF -INF

void solve() {
    ll n;
    cin >> n;
    vll a(n);
    vll b(n);
    REP(i, n) {
        cin >> a[i];
    }
    REP(i, n) {
        cin >> b[i];
    }
    REVERSE(b);
    ll meet = -1;
    REP(i, n) {
        if (a[i] != b[i])
            continue;
        meet = a[i];
        break;
    }

    if (meet == -1) {
        cout << "Yes" << endl;
        join(b, " ");
        return;
    }

    ll l = -1;
    ll r = n;
    REP(i, n) {
        if (a[i] == meet)
            continue;
        if (b[i] > meet) {
            l = i;
        } else if (b[i] < meet) {
            r = i;
            break;
        }
    }

    REP(i, n) {
        if (a[i] != b[i])
            continue;
        if (l > -1) {
            swap(b[i], b[l--]);
        } else if (r < n) {
            swap(b[i], b[r++]);
        } else {
            cout << "No" << endl;
            return;
        }
    }

    cout << "Yes" << endl;
    join(b, " ");
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
    //cin.rdbuf()->in_avail()
    return 0;
}

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

typedef vector<int> vec;
typedef vector<vec> mat;

mat mul(mat A, mat B, int M){
  if(A[0].size() != B.size())return mat();
  int n = A.size(), m = B[0].size();
  mat C(n,vec(m));

  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      for(int k=0;k<A[0].size();k++)
	C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
  return C;
}

mat pow(mat A,int n,int M){
  mat res(A.size(),vec(A[0].size()));
  for(int i=0;i<A.size();i++)res[i][i] = 1;
  while(n>0){
    if(n&1)res = mul(res,A,M);
    A = mul(A,A,M);
    n >>= 1;
  }
  return res;
}

int main(){
  int n,m,a,b,c,t;

  while(cin >> n >> m >> a >> b >> c >> t,n||m||a||b||c||t){
    mat s(n,vec(1)),r;
    for(int i=0;i<n;i++)cin >> s[i][0];
    
    mat A(n,vec(n));
    for(int i=0;i<n;i++){
      if(i)A[i][i-1] = a;
      A[i][i] = b;
      if(i!=n-1)A[i][i+1] = c;
    }

    r = mul(pow(A,t,m),s,m);
    for(int i=0;i<n;i++)cout << r[i][0] << ((i==n-1)?"\n":" ");
  }
}

Measured memory_bytes: 1356
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

#define bil ((ll)1e9)
#define mod ((ll)1e9+7)

int main(int argc,char* argv[]){
    ll n,k,x,y;

    cin >> n >> k >> x >> y;

    if(n>k)
        cout << k*x+(n-k)*y << endl;
    else
        cout << n*x << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int M = sc.nextInt();
   
   int[] Ai = new int[M];
   int K =0;
   int tmp = 0;
   for(int i=0;i<N;i++)
   {
     K = sc.nextInt();
     for(int l = 0;l<K;l++)
     {
       tmp = sc.nextInt();
       Ai[tmp-1]++;
     }
   }
   
   int count = 0;
   for(int i = 0;i<M;i++)
   {
     if(Ai[i]==N) count++;
   }
   System.out.println(count);
 }
}

Measured memory_bytes: 23508
#include<iostream>
#include<queue>
using namespace std;
static const int N=100;
static const int INFTY=(1<<21);

int n,M[N][N];
int d[N];

void bfs(int s){
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++)d[i]=INFTY;
    d[s]=0;
    int u;
    while(!q.empty()){
        u=q.front();q.pop();
        for(int v=0;v<n;v++){
            if(M[u][v]==0)continue;
            if(d[v]!=INFTY)continue;
            d[v]=d[u]+1;
            q.push(v);
        }
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<((d[i]==INFTY)?(-1):d[i])<<endl;
    }
}

int main(){
    int u,k,v;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)M[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    bfs(0);
    return 0;
}


Measured memory_bytes: 3132
using System;
using System.Collections.Generic;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {


            //テンプレート
            //// 整数の入力
            //int a = int.Parse(Console.ReadLine());
            //// スペース区切りの整数の入力
            //string[] input = Console.ReadLine().Split(' ');
            //int b = int.Parse(input[0]);
            //int c = int.Parse(input[1]);
            //// 文字列の入力
            //string s = Console.ReadLine();
            ////出力
            //Console.WriteLine(a + b + c + " " + s);

            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            if ((a < c && c < b) || (b < c && c < a))
            {
                Console.WriteLine("Yes");

            }
            else
                Console.WriteLine("No");



        }
    }
}

Measured memory_bytes: 11092
import java.io.*;

class Main
{
   public static void main(String[] args) throws IOException
   {
   
      BufferedReader br =
       new BufferedReader(new InputStreamReader(System.in));
       
       String str1 = br.readLine();
       String str2[] = str1.split(" ");
       int a = Integer.parseInt(str2[0]);
       int b = Integer.parseInt(str2[1]);
       int c = a*b;
       int d = 2*(a+b);
       System.out.println( c + " " + d );
   }
}

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


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    ss = input().strip().split()
    A = int(ss[0])
    B = float(ss[1])
    print(A * int(B * 1000) // 1000)


solve()


Measured memory_bytes: 9188
n = int(input())
v = [int(x) for x in input().split()]

v = sorted(v)

def r(s):
  rp = s[2:]
  rp.extend([(s[0] + s[1])/2])
  return rp

for _ in range(n-1):
  v = sorted(r(v))
  
print(v[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

//--global--//



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

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    int N, K;
    cin >> N >> K;
    vector<ll> x(N);
    rep(i, N) cin >> x[i];
 
    ll ans = 1e14;
    rep(l, N - K + 1) {
        ll tmp_ans = 0;
        int r      = l + K - 1;
        tmp_ans    = min(abs(x[l]) + abs(x[l] - x[r]),
                      abs(x[r]) + abs(x[r] - x[l]));
        ans        = min(ans, tmp_ans);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

// ref: Cuiaoxiang submission

struct node{
   node() {}
   string name;
   int val;
   int  idx;
   bool operator < (node const& other){
	    if (name != other.name) return name < other.name;
	    else return val > other.val;
	  }	
};

void solve(){
	int n;
	cin >> n;
    vector<node> v(n);
    for (int i = 0; i < n; i++){
	    string s; int p;
	    cin >> s >> p;
        v[i].name = s;
        v[i].val = p;
        v[i].idx = i + 1;	
	}	
  sort(all(v));
  for (int i = 0; i < n; i++){
	   cout << v[i].idx << endl; 
	 }
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
H,N=map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
a = [elem[0] for elem in ab]
h = max(a)
dp = [[10**9]*(H+1+h) for _ in range(N+1)]
dp[0][0]=0
for i in range(N):
    for j in range(H+1+h):
        bb = ab[i][0]
        if j < bb:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-bb] + ab[i][1])
print(min(dp[N][H:]))


Measured memory_bytes: 127600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f3f3f3f3f;
typedef long long LL;
const int maxn=100005;
LL p1[maxn], p2[maxn];
LL n,res[maxn*3];
LL c1, c2, ans;
 
priority_queue<int, vector<int>, greater<int> > Q1;
priority_queue<int>Q2;
 
int main()
{
cin.sync_with_stdio(false);
    cin>>n;
    c1=c2=0;
    for(int i=1;i<=3*n;i++){
        cin>>res[i];
        if(i<=n){
            Q1.push(res[i]);
            c1+=res[i];
        }
        else if(i>2*n){
            Q2.push(res[i]);
            c2+=res[i];
        }
    }
    p1[0]=c1;
    p2[0]=c2;
    for(int i=1;i<=n;i++){
        c1+=res[n+i];
        Q1.push(res[n+i]);
        c1-=Q1.top();
        Q1.pop();
        p1[i]=c1;
        c2+=res[2*n+1-i];
        Q2.push(res[2*n+1-i]);
        c2-=Q2.top();
        Q2.pop();
        p2[i]=c2;
    }
    ans=-INF;
    for(int i=0;i<=n;i++){
        ans=max(ans, p1[i]-p2[n-i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000



int main(){

	int N;
	cin>>N;
	
	vector<vector<int>> E(N,vector<int>());
	
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	vector<int> dis(N,Inf);
	dis[0]=0;
	queue<int> Q;
	Q.push(0);
	
	while(Q.size()!=0){
		int from = Q.front();
		Q.pop();
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i];
			if(dis[to]!=Inf)continue;
			dis[to] = dis[from]+1;
			Q.push(to);
		}
	}
	
	deque<int> L(0);
	int now = N-1;
	while(true){
		for(int i=0;i<E[now].size();i++){
			int to = E[now][i];
			if(dis[to]==dis[now]-1){
				now=to;
				break;
			}
		}
		if(dis[now]==0)break;
		L.push_back(now);
	}
	
	vector<string> color(N,"");
	color[0]="black";
	color[N-1]="white";

	reverse(L.begin(),L.end());
	
	for(int i=0;i<N;i++){
		if(L.size()==0)break;
		if(i%2==0){
			color[L.front()]="black";
			L.pop_front();
		}
		else{
			color[L.back()]="white";
			L.pop_back();
		}
	}
	
	for(int i=0;i<N;i++){
		string s = color[i];
		if(s=="")continue;
		Q.push(i);
		while(Q.size()!=0){
			int from = Q.front();
			Q.pop();
			for(int j=0;j<E[from].size();j++){
				int to = E[from][j];
				if(color[to]!="")continue;
				color[to]=s;
				Q.push(to);
			}
		}
	}
	
	int b=0,w=0;
	
	for(int i=0;i<N;i++){
		assert(color[i]!="");
		if(color[i]=="black")b++;
		else w++;
	}
	
	if(b>w){
		cout<<"Fennec"<<endl;
	}
	else{
		cout<<"Snuke"<<endl;
	}
	
    return 0;
}



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

public class Main {

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

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int R = fs.nextInt();
        out.println(Math.PI*2*R);

        out.close();

    }

    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}


Measured memory_bytes: 33396
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
    string s;

    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
$N=<>;
($a,$b,$c)=glob(<>),$$a{$b}=$$b{$a}=$c for 2..$N;
@s=<>=~$"*$';
map{$d[$_]or$d[$_]=$d[$u]+$$u{$_},push@s,$_}keys%$u while$u=pop@s;
/ /,print$d[$`]+$d[$'],$/for<>

Measured memory_bytes: 123136
#include <bits/stdc++.h>
//#include <map>
//#include <set>
//#include <list>
//#include <cmath>
//#include <ctime>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <string>
//#include <bitset>
//#include <cstdio>
//#include <limits>
//#include <vector>
//#include <climits>
//#include <cstring>
//#include <cstdlib>
//#include <fstream>
//#include <numeric>
//#include <sstream>
//#include <iomanip>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>

using namespace std;

#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.141592653589793238462643383279502884
#define MAX 1000100
#define mod 1000000007
#define EPS 1E-9
#define int long long
#define endl "\n"

int fix(int cur, int m)
{
    return ((cur%m) + m) % m;
}

int fast_power(int x, int y,int m)
{
    if (y == 0)
        return 1;
    int temp = fast_power(x, y / 2, m) ;
    temp = (temp*temp)% m;
    if (y % 2 != 0)
        temp = (temp*x)% m;
    return temp;

}


int32_t main()
{
    //freopen("D:/Important Files/Cocktail/SOLVE/TestLib/testcases/input/input11.txt", "r", stdin);
   // freopen("D:/Important Files/Cocktail/SOLVE/TestLib/testcases/output/output11.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.tie(0);

    set<int>st;
    int a,b,c;
    cin >> a >> b >> c;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    if(st.size()==2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
class UnionFind:
    """
    sizeによる実装
    """

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        """
        x: child
        ret-> node
        xのグループの代表を見つける
        """
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        """
        union (x ,y)
        x,y: node
        ret->None
        """
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        """
        return true if x and y are in same group
        """
        return self.find(x) == self.find(y)

    def connectedNum(self, x):
        """
        return size of the group x belong to
        """
        return self.size[self.find(x)]

    def is_connected(self):
        """
        return true is all node is in one group
        """
        return self.connectedNum(0) == len(self.parent)

    def conpomentNum(self):
        """
        return num of component
        """
        par_set=set()
        for p in self.parent:
            par_set.add(self.find(p))
        return len(par_set())


N,Q=map(int,input().split())

Un=UnionFind(N+1)
for _ in range(Q):
    t,u,v = map(int,input().split())
    if t==0:
        Un.union(u,v)
    else:
        print(int(Un.same(u,v)))


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n, k, q;
int a[maxn];
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n>>k>>q;
  for (int i=0; i<q; i++) {
    int x; cin>>x;
    a[x]++;
  }

  for (int i=1; i<=n; i++) {
    int s = k +a[i] - q;
    if (s > 0) {
      cout<<"Yes\n";
    } else {
      cout<<"No\n";
    }
  }
  

  return 0;
}


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

using namespace std;

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

    string s,t,t1;
    cin>>s>>t;

    t1=t.substr(0,t.length()-1);

    if(s.length()+1==t.length() && t1.find(s)!=string::npos){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }


    return 0;
}


Measured memory_bytes: 3636
from math import cos, radians, sqrt

def resolve():
    a, b, h, m = map(int, input().split())

    # H時M分になったときの、分針の向き
    minute_deg = 6 * m

    # H時M分になったときの、時針の向き
    hour_deg = 30 * (h + m / 60)

    # H時M分になったときの、分針と時針のなす角
    deg_diff = abs(minute_deg - hour_deg)

    # 余弦定理を用いて、固定されていない方の端点同士の距離を求める
    ans_squared = a ** 2 + b ** 2 - 2 * a * b * cos(radians(deg_diff))
    print(sqrt(ans_squared))
    
resolve()

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    string s;cin>>s;
    int n=s.size();
    vin leftr(n),rightl(n);
    int tmpr,tmpl;
    rep(i,n){
        if(s[i]=='R'){
            leftr[i]=i;
            tmpr=i;
        }
        else leftr[i]=tmpr;
        if(s[n-1-i]=='L'){
            rightl[n-1-i]=n-1-i;
            tmpl=n-1-i;
        }
        else rightl[n-1-i]=tmpl;
    }
    vin ans(n);
    rep(i,n){
        if(s[i]=='R'){
            if((rightl[i]-i)%2)ans[rightl[i]-1]++;
            else ans[rightl[i]]++;
        }
        else{
            if((i-leftr[i])%2)ans[leftr[i]+1]++;
            else ans[leftr[i]]++;
        }
    }
    rep(i,n-1)cout<<ans[i]<<" ";
    cout<<ans[n-1]<<endl;
}

Measured memory_bytes: 1792
let N = stdin.ReadLine() |> int
let P = stdin.ReadLine().Split() |> Array.map int

let rec resolver m (r : int) n =
    if n = N + 1 || m = 1 then r
    elif P.[n] < m then resolver P.[n] (r + 1) (n + 1)
    else resolver m r (n + 1)

resolver (N + 1) 0 0 |> stdout.WriteLine


Measured memory_bytes: 34268
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL h, w;
    cin >> h >> w;
    vector<string> mat(h);
    for(LL y = 0; y < h; ++y){
        cin >> mat[y];
    }
    vector<vector<LL>> dp(h, vector<LL>(w, h+w));
    dp[0][0] = 0;
    if(mat[0][0] == '#') dp[0][0] = 1;
    for(LL y = 0; y < h; ++y){
        for(LL x = 0; x < w; ++x){
            if(y > 0){
                if(mat[y][x] != mat[y-1][x]){
                    dp[y][x] = min(dp[y][x], dp[y-1][x]+1);
                }else{
                    dp[y][x] = min(dp[y][x], dp[y-1][x]+0);
                }
            }
            if(x > 0){
                if(mat[y][x] != mat[y][x-1]){
                    dp[y][x] = min(dp[y][x], dp[y][x-1]+1);
                }else{
                    dp[y][x] = min(dp[y][x], dp[y][x-1]+0);
                }
            }
        }
    }
    LL ans = (dp[h-1][w-1] +1) / 2;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
#[allow(dead_code)]
fn main() {
    let s = i::s();
    let b = s.iter().filter(|c| *c.clone() == '0').count() as i64;
    let a = s.len() as i64 - b;
    println!("{}", s.len() as i64 - (a - b).abs());
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


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

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef vector<point> polygon;

const double oo = 1e18;
const double eps = 1e-9;

namespace std
{
	bool operator<(point a, point b)
	{
		if (a.real() != b.real())
			return a.real() < b.real();
		return a.imag() < b.imag();
	}
}

double closestPairPoints(vector<point> &p){
	auto cmp = [](point a, point b)
	{
		return make_pair(a.imag(), a.real()) < make_pair(b.imag(), b.real());
	};

	int n = (int)p.size();
	sort(p.begin(), p.end());

	set<point, decltype(cmp)> S(cmp);
	double ans = oo;
	int ptr = 0;

	for (int i = 0; i < n; ++i)
	{
		while (ptr < i && abs(p[i].real() - p[ptr].real()) >= ans)
			S.erase(p[ptr++]);

		auto lo = S.lower_bound(point(-oo, p[i].imag() - ans - eps));
		auto hi = S.upper_bound(point(-oo, p[i].imag() + ans + eps));

		for (decltype(lo) it = lo; it != hi; ++it)
			ans = min(ans, abs(p[i] - *it));

		S.insert(p[i]);
	}

	return ans;
}

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

	int n; cin >> n;
	vector<point> p(n);
	
	for (int i = 0; i < n; ++i){
		double x, y; cin >> x >> y;
		p[i] = point(x, y);
	}

	cout.precision(10);
	cout << fixed << closestPairPoints(p) << endl;

	return 0;
}

Measured memory_bytes: 7596
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
struct multi {
  ll first;
  ll second;
  ll third;
};
bool multicomp(const multi &a, const multi &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  if (S[K - 1] == 'A')
    S[K - 1] = 'a';
  if (S[K - 1] == 'B')
    S[K - 1] = 'b';
  if (S[K - 1] == 'C')
    S[K - 1] = 'c';
  cout << S << endl;

  return 0;
}


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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int main() {
    int S, W;
    cin >> S >> W;
    if (S <= W) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
//      freopen("q.in","r",stdin);
//      freopen("q.out","w",stdout);
      int n,a,b;
      cin>>n>>a>>b;
      if(a>b)swap(a,b);
      if((b-a)%2==0){
            cout<<(b-a)/2;
            return 0;
      }
      int A=a-1;
      int B=n-b;
      cout<<min((b-A-2)/2+A+1,(n-(a+B+1))/2+B+1);
}


Measured memory_bytes: 256
n = gets.chomp.to_i

a = [0]
n.times do
  a << gets.chomp.to_i
end

curr = 1
ans = 0
n.times do
  ans += 1
  nex = a[curr]
  if nex == 2 then
    puts ans
    exit
  elsif nex == 0 then
    break
  end
  a[curr] = 0
  curr = nex
end
puts -1

Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

template<typename T> struct BIT {
	vector<T> bit;
	int n;
	
	BIT() {}
	BIT(int n) : bit(vector<T>(n + 2, 0)), n(n) {}
	
	T sum(int i) {
		i++;
		T s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	
	void add(int i, T x) {
		i++;
		while (i <= n) {
			bit[i] += x;
			i += i & -i;
		}
	}
	
	T pquery(int i) {
		return sum(i) - sum(i - 1);
	}
	
	int lower_bound(T x) {
		int l = -1, r = bit.size();
		while (r - l > 1) {
			int m = (l + r) / 2;
			
			if (sum(m) >= x) r = m;
			else l = m;
		}
		if (r == bit.size()) r = -1;
		
		return r;
	}
};

string s;
int K;
set<int> pos[26];

int main() {
	cin >> s >> K;
	
	int n = s.size();
	REP(i, n) pos[s[i]-'a'].insert(i);
	
	BIT<int> bit(n);
	REP(i, n) bit.add(i, 1);
	
	string ans = "";
	while (true) {
		bool f = false;
		
		REP(i, 26) {
			set<int>::iterator it = pos[i].begin();
			if (it == pos[i].end()) continue;
			
			int cnt = bit.sum(*it) - 1;
			if (cnt <= K) {
				K -= cnt;
				bit.add(*it, -1);
				pos[i].erase(it);
				f = true;
				ans += i + 'a';
				break;
			}
		}
		
		if (!f) break;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 13232