akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
 
template <typename T>
void cetak(T t){cout << t << ')' << endl;}
template <typename T, typename... V>
void cetak(T t, V... v) {cout << t; if (sizeof...(v)) cout << ", "; cetak(v...);}
 
#define debug(x...) cout << '(' << #x << ") = ("; cetak(x) 
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())


const int MOD = 1e9 + 7;

int add(int x, int y){
    int ret = x + y;
    if(ret >= MOD) ret -= MOD;
    return ret;
}
int sub(int x, int y){
    int ret = x - y;
    if(ret < 0) ret += MOD;
    return ret;
}
int mul(int x, int y){
    return (long long)x * y % MOD;
}


const int mx = 1e5 + 10;

int find(vector<int> &par, int x){
    if(par[x] == x) return x;
    return par[x] = find(par, par[x]);
}

void gabung(vector<int> &par, int i, int j){
    i = find(par, i);
    j = find(par, j);
    if(i != j) par[i] = j;
}

void solve(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> d(n), w(m, 1e9), u(m), v(m), par(n * 2, 0), ve(m), c(n, -1);
    iota(ALL(ve), 0);
    iota(ALL(par), 0);
    for(int i = 0; i < n; i++) cin >> d[i];
    map<pair<int, int>, int> apa;
    for(int i = 0; i < m; i++){
        cin >> u[i] >> v[i];
        u[i] -= 1;
        v[i] -= 1;
        apa[{u[i], v[i]}] = apa[{v[i], u[i]}] = i;
        g[u[i]].pb(v[i]);
        g[v[i]].pb(u[i]);
    }
    sort(ALL(ve), [&](int i, int j){
        int x = abs(d[u[i]] - d[v[i]]);
        int y = abs(d[u[j]] - d[v[j]]);
        if(x == y) return d[u[i]] < d[u[j]];
        return x < y;
    });
    set<int> aa;
    for(int i : ve){
        if(d[u[i]] == d[v[i]]){
            // warnanya beda
            if(aa.count(u[i]) && aa.count(v[i])) continue;
            aa.insert(u[i]);
            aa.insert(v[i]);
            if(c[u[i]] == -1 && c[v[i]] == -1){
                c[u[i]] = 0;
                c[v[i]] = 1;
            }
            else if(c[u[i]] == -1) c[u[i]] = c[v[i]] ^ 1;
            else c[v[i]] = c[u[i]] ^ 1;
            w[i] = d[u[i]];
        }
    }
    queue<int> q;
    for(int i : aa) q.push(i);
    while(!q.empty()){
        int now = q.front();
        q.pop();
        for(int i : g[now]){
            if(aa.count(i)) continue;
            if(d[i] > d[now]){
                aa.insert(i);
                q.push(i);
                w[apa[{now, i}]] = d[i] - d[now];
                c[i] = c[now];
            }
        }
    }
    if(sz(aa) < n){
        cout << -1 << endl;
        return;
    }
    for(int i = 0; i < n; i++){
        int j = i + n;
        int x = find(par, i);
        int y = find(par, j);
        if(x == y){
            cout << -1 << endl;
            return;
        }
    }
    for(int i = 0; i < n; i++){
        if(c[i]) cout << 'B';
        else cout << 'W';
    }
    cout << endl;
    for(int i = 0; i < m; i++) cout << w[i] << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 43008
import sys, math
from pprint import pprint
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = []
for i in range(N):
	a = []
	for j in range(ri()):
		x, y = rl()
		a.append((x-1, y))
	A.append(a)

def check(A, b):
	for i, a in enumerate(A):
		for x, y in a:
			if b[i] == 1:
				if b[x] != y:
					return False
	return True

import itertools
ans = 0
for b in itertools.product([0,1], repeat=N):
	if check(A, b):
		ans = max(ans, sum(b))
print(ans)

Measured memory_bytes: 43740
#include<bits/stdc++.h>
    #define ll long long
    #define ull unsigned long long
    #define pii pair<int,int>
    #define pp pair<pair<ll, ll>,pair<ll, ll>>
    #define pll pair<ll,ll>
    #define ppll pair<ll,pll>
    #define pdd pair<double,double>
    #define vii vector<int>
    #define vll vector<ll>
    #define mat vector<vector<ll>>
    #define lb lower_bound
    #define ub upper_bound
    #define pb push_back
    #define eb emplace_back
    #define fi first
    #define sc second
    #define rep(i,n) for(ll i=0;i<n;i++)
    #define rep2(i,a,b) for(ll i=a;i<b;i++)
    #define repr(i,n) for(ll i=n-1;i>=0;i--)
    #define all(x) x.begin(),x.end()
    #define sz(x) (ll) (x).size()
    #define pq priority_queue<ll>
    #define pqg priority_queue<ll,vector<ll>,greater<ll>>
    #define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
    #define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
    #define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
    #define int ll
    #define FOR(i,a,b) for(ll i=a;i<=b;i++)
    // #define ll int
    #define PN 1
    using namespace std;
    const ll MAXR = 1000000;
    const ll INF = 1 << 29;
    const ll LLINF = (1LL << 60LL);
    const ll MOD = 1000000007;
    const int MAX_V = 500;
    // const ll mod = 998244353;
    const ll MAX = 2100000;
    const double pi = acos(-1);
    const double eps = 1e-10;
    ll dx[8] ={1,0,-1,0,1,-1,1,-1};
    ll dy[8] ={0,1,0,-1,1,-1,-1,1};
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



    map<ll,ll> res;
    
    bool ok1 = true, ok2 = true;
    void prime_factor(ll n){
        map<ll,ll> res2;
        for(ll i=2;i*i<=n;i++){
            while(n%i==0){
                res2[i]++;
                n/=i;
            }
        }
        if(n!=1) res2[n]++;

        for(auto i:res2){
            if(res[i.fi] > 0){
                ok1 = false;
            }
            res[i.fi]+=i.sc;
        }
        return;
    }


    void solve() {
        ll n;
        ll a[1000010];
        cin>>n;
        rep(i,n) cin>>a[i];
        repr(i,n){
            prime_factor(a[i]);
            // cout<<i<<endl;
            if(ok1 == false) break;
        }

        if(ok1 == true){
            cout<<"pairwise coprime"<<endl;
            return;
        }

        for(auto i : res){
            // cout<<i.fi<<" "<<i.sc<<endl;
            // if(i.sc < n) continue;
            ll cnt = 0;
            rep(j,n){
                if(a[j] % i.fi == 0) cnt++;
                else break;
            }
            if(cnt == n) ok2 = false;
            if(ok2 == false) break;
        }

        if(ok2){
            cout<<"setwise coprime"<<endl;
            
            return;
        }

        cout<<"not coprime"<<endl;

        



    }







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


        ll t=1;
        rep(i,t){
            solve(); 
        }


        return 0;
    }

Measured memory_bytes: 11380
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool ok = 0;
    rep(i,n/4+1){
        if ((n-i*4)%7 == 0) ok = 1;
    }
    if (ok) PRINT("Yes");
    else PRINT("No");
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

#[fastout]
fn main() {
    input! {
        n: usize,
        xyu: [(isize, isize, char); n],
    }
    let mut xyu: Vec<(isize, isize, char)> = xyu.clone();

    let mut collision_time = 99999999;
    macro_rules! collision_check {
        ($main_coord:expr, $sub_coord:expr, $plus_dir:expr, $minus_dir:expr) => {
            xyu.sort_unstable_by_key(|&tr| $main_coord(tr));
            xyu.sort_by_key(|&tr| $sub_coord(tr));
            let mut nowsub = 0;
            let mut prevmain: Option<isize> = None;
            for &tr in &xyu {
                if nowsub != $sub_coord(tr) {
                    nowsub = $sub_coord(tr);
                    prevmain = None;
                }
                if tr.2 == $plus_dir {
                    prevmain = Some($main_coord(tr));
                } else if tr.2 == $minus_dir {
                    match prevmain {
                        None => {}
                        Some(mm) => {
                            let coltime = ($main_coord(tr) - mm) * 5;
                            collision_time = collision_time.min(coltime);
                        }
                    }
                    prevmain = None;
                }
            }
        };
    }
    let xclosure = |(x, y, u)| x;
    let yclosure = |(x, y, u)| y;
    let vclosure = |(x, y, u)| x + y;
    let wclosure = |(x, y, u)| x - y;

    collision_check!(yclosure, xclosure, 'U', 'D');
    collision_check!(xclosure, yclosure, 'R', 'L');
    collision_check!(vclosure, wclosure, 'U', 'L');
    collision_check!(wclosure, vclosure, 'R', 'U');
    collision_check!(vclosure, wclosure, 'R', 'D');
    collision_check!(wclosure, vclosure, 'D', 'L');
    if collision_time < 10000000 {
        println!("{}", collision_time);
    } else {
        println!("SAFE");
    }
}


Measured memory_bytes: 16524
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

res = [[0]*N for _ in range(2)]
res[0][0] = A1[0]
res[1][N-1] = A2[N-1]

for i in range(1, N):
    res[0][i] = res[0][i-1]+A1[i]
    res[1][N-i-1] = res[1][N-i]+A2[N-i-1]

r = 0
for i in range(N):
    r = max(res[0][i]+res[1][i], r)

print(r)

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N);
    for(auto &e : A) cin >> e;
    int cnt = 0;
    int sum = accumulate(A.begin(), A.end(), 0);
    rep(i, N) cnt += (sum <= A[i] * 4 * M);
    cout << (cnt >= M ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

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

b = a[::2]
c = a[1::2]

if n%2 == 0:
  ans = list(reversed(c)) + b
  print(*ans, sep=" ")
else:
  ans = list(reversed(b)) + c
  print(*ans, sep=" ")


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

using namespace std;

int main()
{
	int i,j,k,n;
	char A,T;

	cin >> A >> T;

	cout << ((A==T) ? "H" : "D") << endl; 

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const ll MAX = 150000;
bool isPrime[MAX];
vector<ll> prime;
void makePrime(){
  for (ll i = 0; i < MAX; i++){
    isPrime[i] = true;
  }
  for (ll i = 2; i * i < MAX + 1; i++){
    if(isPrime[i]){
      for (ll j = 2 * i; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  FOR(i,2,MAX) if(isPrime[i]) prime.push_back(i);
  return;
}
int main()
{
  makePrime();
  int N, R;
  while(cin >> N >> R, N != -1) {
    int j = upper_bound(prime.begin(), prime.end(), N) - prime.begin();
    vector<int> v;
    FOR(i,j,j+200) {
      FOR(k,i,j+200) {
        v.push_back(prime[i]+prime[k]);
      }
    }
    sort(v.begin(), v.end());
    cout << v[R-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3276
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args) throws IOException
	{
		Scanner c = new Scanner(System.in);
		int N = c.nextInt();
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for(int j=0; j<N; j++)
		{
			int i = c.nextInt();
			if(!map.containsKey(-i)) map.put(-i, 1);
			else map.put(-i, 1+map.get(-i));
		}
//		System.out.println(map);
		int side1=0, side2=0;
		for(int i: map.keySet())
		{
			if(map.get(i) >= 2)
			{
				if(side1 == 0 && map.get(i)>=4)
				{
					System.out.println(((long)(i)) * (long)(i));
					return;
				}
				else if(side1 == 0)
				{
					side1 = i;
				}
				else
				{
					System.out.println(((long) (side1)) * (long) (i));
					return;
				}
			}
		}
		System.out.println(0);
	}
}


Measured memory_bytes: 62504
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
/*        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);*/
//        int b = int.Parse(input[2]);
//        string temp = ReadLine();
        int a = int.Parse(ReadLine());
        if(a%10==9 || a/10==9){
            WriteLine("Yes");
        }else{
            WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}

//小文字=大文字+32

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	int nm=0;
	int m=0;
	rep(i, n) {

		if (a[i] > m) {
			m = a[i];
		}
		else if(a[i] > nm){

			nm = a[i];
		}
	}
	rep(i, n) {
		if (m != a[i]) {
		
			cout << m<<endl;
		}
		else {
			cout << nm<<endl;
		}
	}

}
	



Measured memory_bytes: 4056
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        for (int i = 0; i < n - 1; i++) if (s.charAt(i) == s.charAt(i + 1)){
            System.out.println("Bad");
            return;
        }
        System.out.println("Good");
    }


    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
char s[1005][1005];
int dp[1005][1005];
int main(){
    int h, w, ch, cw, dh, dw;
    scanf("%d%d", &h, &w);
    scanf("%d%d", &ch, &cw);
    scanf("%d%d", &dh, &dw);
    for(int i=1;i<=h;i++) scanf("%s", s[i]+1);
        
    memset(dp, -1, sizeof(dp));
    deque<pair<int, int> > q;
    q.push_front(make_pair(ch, cw));
    dp[ch][cw] = 0;
    while(!q.empty()){
        int x = q.front().first, y = q.front().second;
        q.pop_front();
        for(int i=-1;i<=1;i++){
            for(int j=-1;j<=1;j++){
                if(i == 0 || j == 0){
                    int vx = x+i, vy = y+j;
                    if(s[vx][vy] == '#') continue;
                    if(1 <= vx && vx <= h && 1 <= vy && vy <= w){
                        if(dp[vx][vy] == -1 || dp[vx][vy] > dp[x][y]){
                            dp[vx][vy] = dp[x][y];
                            q.push_front(make_pair(vx, vy));
                        }
                    }
                }
            }
        }

        for(int i=-2;i<=2;i++){
            for(int j=-2;j<=2;j++){
                int vx = x+i, vy = y+j;
                if(1 <= vx && vx <= h && 1 <= vy && vy <= w){
                    if(s[vx][vy] == '#') continue;
                    if(dp[vx][vy] == -1 || dp[vx][vy] > dp[x][y] + 1){
                        dp[vx][vy] = dp[x][y] + 1;
                        q.push_back(make_pair(vx, vy));
                    }
                }
            }
        }
    }
    printf("%d\n", dp[dh][dw]);
}

Measured memory_bytes: 8676
#include <bits/stdc++.h>
using namespace std;
int n, m, q, a[50], b[50], c[50], d[50], ans=0, A[10];
void dfs(int p, int k){
  if(p == n){
    int sum = 0;
    for(int i = 0; i < q; i++){
      if(A[b[i]-1] - A[a[i]-1] == c[i]) sum+=d[i];
    }
    ans = max(ans,sum);
  }else{
    for(int i = k; i <= m; i++){
      A[p] = i;
      dfs(p+1,i);
    }
  }
}
int main(){
  cin >> n >> m >> q;
  A[0] = 1;
  for(int i= 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs(1,1);
  cout << ans << endl;
}

Measured memory_bytes: 3472
#include <stdio.h>

int main(void){
  int a,b,c,k;
  int i;
  int tmp;
  
  scanf("%d %d %d",&a,&b,&c);
  scanf("%d",&k);
  
  /* Maximize A */
  if( b < c ){
    if( a < c ){
      tmp = c;
      c = a;
      a = tmp;
    }
  }
  else{ // b > c
    if( a < b ){
      tmp = b;
      b = a;
      a = tmp;
    }
  }
  
  //printf("A B C --(sort)--> %d %d %d\n",a,b,c);
  
  for( i=0; i<k; i++) a *= 2;
  
  printf("%d\n",a+b+c);
  
  return 0;
}
    
    
  
  

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
#include <sstream>
using namespace std;
const constexpr int INF = 1e9;
#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
struct Less{
   bool operator()(const pair<string, int>&a, const pair<string, int>&b){
        if(a.first==b.first){
            return a.second < b.second;
        }
       return a.first < b.first;
    }
};

ll extGCD(ll a, ll b, ll& x, ll& y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}
ll GCD(ll a, ll b){
    if(a<b) swap(a, b);
    if(b==0) return a;
    return GCD(b, a%b);
}
int par[100010], rr[100010];
void init(){
    for(int i=0; i<100010; ++i){
        par[i]=i;
        rr[i]=0;
    }
}
int root(int x){
    return par[x] == x ? x:par[x] = root(par[x]);
}
bool same(int x, int y){
    return root(x)==root(y);
}
void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x==y) return ;
    
    if(rr[x]<rr[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(rr[x]==rr[y]) rr[x]++;
    }
}

ll pow_mod(ll x, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res*x%MOD;
        }
        x = x*x%MOD;
        n>>=1;
    }
    return res;
}
int alph[26];
int main() {
    string S; cin >> S;
    if(S=="zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }
    if(S.size()<26){
        for(int i=0; i<S.size(); ++i){
            alph[S[i]-'a']++;
        }
        cout << S;
        for(int i=0; i<26; ++i){
            if(alph[i]==0){
                cout << (char)(i+'a') << endl;
                break;
            }
        }
        cout << endl;
    }else{
        vector<string> v;
        for(int i=S.size()-1; i>=0; i--){
            for(int j=i-1; j>=0; j--){
                if(S[i]>S[j]){
                    string s="";
                    for(int k=0; k<j; ++k){
                        s+=S[k];
                    }
                    s+=S[i];
                    v.push_back(s);
                    break;
                }
            }
        }
        v.push_back(S);
        sort(v.begin(), v.end());
        for(int i=0; i<v.size(); ++i){
            if(v[i]==S) cout << v[i+1] << endl;
        }
        
    }
    return 0;
}

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

int main() {
  int N,M,i,x,y;
  cin >> N >> M;
  vector<int> L(M), R(M);
  for(i=0; i<M; i++)
    cin >> L.at(i) >> R.at(i);
  
  for(i=0; i<M; i++) {
    if(i==0) {
      x=L.at(i);
      y=R.at(i);
    } else {
      if(x<L.at(i))
        x = L.at(i);
      if(y>R.at(i))
        y = R.at(i); 
    }
  }
  
  if(x>N || y<x) {
    cout << 0 << endl;
  	return 0;
  } else if(y>N)
    y=N;
  
  cout << y-x+1 << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			long k = sc.nextLong();
			long n = sc.nextLong();
			long[] a = new long[(int)n];
			
			for(int i=0;i<n;i++) {
				a[i] = sc.nextLong();
			}
			long dis = 0;
			for(int i=1;i<n;i++) {
				dis = Math.max(dis, a[i]-a[i-1]);
			}
			
			dis = Math.max(dis, Math.abs(k-a[(int)n-1]+a[0]));
			
			System.out.println(k-dis);
			
	    }
		
	}
	


Measured memory_bytes: 61708
n = int(input())
lower, upper = [], []
for _ in range(n):
    a, b = map(int, input().split())
    lower.append(a)
    upper.append(b)
lower.sort()
upper.sort()
if n % 2 == 1:
    mid = n // 2
    median_min = lower[mid]
    median_max = upper[mid]
else:
    mid = n // 2 - 1
    median_min = lower[mid] + lower[mid + 1]
    median_max = upper[mid] + upper[mid + 1]
print(median_max - median_min + 1)

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

#define int long long
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
//const int MOD = 10000;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
int gcd(int x,int y){if(y==0) return x; return gcd(y, x%y);}
int lcm(int x,int y){return x/gcd(x,y)*y;}

pair<intpair, intpair> square_vertex(int x1, int y1, int x2, int y2){
    int X = x2 - x1, Y = y2 - y1;
    return {{x2-Y, y2+X}, {x1-Y, y1+X}};
}

signed main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    auto p = square_vertex(x1, y1, x2, y2);
    cout << p.first.first << " " << p.first.second << " ";
    cout << p.second.first << " " << p.second.second << endl;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define debug(x) {cout<<(#x)<<" "<<x<<endl;}
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 200005;
const LL INF = 100000000007LL;

int n,q,b;
int x[N<<2];
LL dp[3][N<<2],tag[N<<2];

inline void pushup(int x) {
	rep(i,0,2) dp[i][x]=min(dp[i][x<<1],dp[i][x<<1|1]);
}

inline void pushdown(int x) {
	if (tag[x]) {
		tag[x<<1]+=tag[x]; tag[x<<1|1]+=tag[x];
		rep(i,0,2) dp[i][x<<1]+=tag[x],dp[i][x<<1|1]+=tag[x];
		tag[x]=0;
	}
}

inline void build(int x,int l,int r) {
	if (l==r) {
		rep(i,0,2) dp[i][x]=INF; tag[x]=0;
		return;
	}
	int mid=(l+r)>>1;
	build(x<<1,l,mid); build(x<<1|1,mid+1,r);
	pushup(x);
}

inline void change(int x,int l,int r,int p,LL val) {
	if (l==r) {
		rep(i,0,2) dp[i][x]=val; dp[1][x]-=l; dp[2][x]+=l;
		return;
	}
	int mid=(l+r)>>1;
	pushdown(x);
	if (p<=mid) change(x<<1,l,mid,p,val);
	else change(x<<1|1,mid+1,r,p,val);
	pushup(x);
}

inline LL query(int x,int l,int r,int ll,int rr,int tp) {
	if (r<ll||l>rr) return INF;
	if (l>=ll&&r<=rr) return dp[tp][x];
	int mid=(l+r)>>1;
	pushdown(x);
	return min(query(x<<1,l,mid,ll,rr,tp),query(x<<1|1,mid+1,r,ll,rr,tp));
}

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(),q=read(),x[0]=read(),b=read();
	rep(i,1,q) x[i]=read();
	build(1,1,n); change(1,1,n,b,0);
	rep(i,1,q) {
		LL t1=query(1,1,n,1,x[i],1)+x[i],t2=query(1,1,n,x[i],n,2)-x[i];
		LL tmp=abs(x[i]-x[i-1]);
		rep(i,0,2) dp[i][1]+=tmp; tag[1]+=tmp;
		change(1,1,n,x[i-1],min(t1,t2));
	}
	printf("%lld\n",dp[0][1]);
	return 0;
}


Measured memory_bytes: 26880
#include <stdio.h>

int main()
{
    int A,B,C,D,i;
    scanf("%d %d %d %d", &A, &B, &C, &D);
    for(i=0; ;i++)
    {
        C=C-B;
        A=A-D;
        if(C<=0 || A<=0)break;
    }
    if(C<=0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

Measured memory_bytes: 1608
#include <iostream>

int main() {
	int a, b, c, d, e, f;
	std::cin >> a >> b >> c >> d >> e >> f;

	int bestAmount, bestSuger;
	double bestDens = -1.0;
	for (int i = 0; i * 100 <= f; i += a) {
		for (int j = 0; (i + j) * 100 <= f; j += b) {
			for (int k = 0; k <= (i + j) * e; k += c) {
				for (int l = 0; k + l <= (i + j) * e; l += d) {
					const int water = (i + j) * 100, suger = k + l;
					if (water + suger > f)
						continue;

					const double dens = suger * 1.0 / (water + suger);
					if (dens > bestDens) {
						bestDens = dens;
						bestAmount = water + suger;
						bestSuger = suger;
					}
				}
			}
		}
	}

	std::cout << bestAmount << " " << bestSuger << std::endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from itertools import product

def main():
    field_y_length,field_x_length =  map(int, input().split())
    maze = [input() for i in range(field_y_length)]

    INF = 10**8
    
    max_distance = 0

    def bfs(sy,sx):
        distance = [[INF for i in range(field_x_length)] for j in range(field_y_length)]
        queue = []

        queue.insert(0,(sy,sx))

        distance[sy][sx] = 0

        res = 0

        while len(queue):
            y,x = queue.pop()

            for i in range(0,4):
                ny,nx = y + [1, 0, -1, 0][i], x + [0, 1, 0, -1][i]

                if (0 <= nx and nx < field_x_length and 0 <= ny):
                    if (ny < field_y_length and maze[ny][nx] != '#'):
                        if (distance[ny][nx] == INF):
                            queue.insert(0, (ny, nx))
                            distance[ny][nx] = distance[y][x] + 1
                            res = max(res,distance[y][x] + 1)
        
        return res

    
    for y,x in product(range(field_y_length),range(field_x_length)):
        if maze[y][x] == '#':
            continue
        max_distance = max(max_distance,bfs(y,x))
    print(max_distance)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $s = <STDIN>);
my $t = int(sqrt($s));
if ($t * $t == $s) {
  say "0 0 $t 0 0 $t";
  exit;
}
$t++;
my $e = $t *$t - $s;
say "0 0 $t $e 1 $t";


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const int INF = 100100100;
typedef long long ll;
 
int main() {
   string s;
   cin >> s;
   int l=s.find("A");
   int r=s.rfind("Z");
   cout << r-l+1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	int a,b;
	char op;
	while(1){
		cin>>a>>op>>b;
		if ( op == '+' ){
			cout<<a+b<<endl;
		} else if ( op == '-' ){
			cout<<a-b<<endl;
		} else if ( op == '*' ){
			cout<<a*b<<endl;
		} else if ( op == '/' ){
			cout<<a/b<<endl;
		} else {
			break;
		}
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int K;
  cin>>K;

  Int ans = 0;
  for(Int i=1;i<=K;i++)
    for(Int j=1;j<=K;j++)
      for(Int k=1;k<=K;k++){
        Int gcd = __gcd(__gcd(i, j), k);
        ans += gcd;
      }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(){
    int a, b, c, x, i, j, k, cnt=0;

    scanf("%d %d %d %d", &a, &b, &c, &x);

    for(i=0; i<=a; i++){
        for(j=0; j<=b; j++){
            for(k=0; k<=c; k++){
                if(i*500 + j*100 + k*50 == x)
                    cnt++;
            }
        }
    }

    printf("%d\n", cnt);

    return 0;
}

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

	
	int main() {

		#ifndef ONLINE_JUDGE
	        freopen("input.txt","r",stdin);
	        // freopen("output.txt","w",stdout);
	    #endif
	    ios::sync_with_stdio(false);
	    cin.tie(0);
	    cout.tie(0);
	   
	  	ll a,b,c,d;
	  	cin>>a>>b>>c>>d;
	  	cout<<max(a*c,max(a*d,max(b*c,b*d)));
	    return 0;
}



	



Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
#define TYPE int
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int f[200002];
int main() {
	int N, K, A;
	int type = 0, ans = 0;
	scanf("%d%d", &N, &K);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A);
		if (f[A] == 0)//shurui
		{
			type++;
		}
		f[A]++;//kazu
	}
	//printf("%d ", type);

	qsort(f, 200000, sizeof(int), cmp_r);
	//for (int i = 0; i < 200000; i++)
	//{
	//	printf("%d ", f[i]);
	//}
	for (int i = type - 1; i > K - 1; i--)
	{
		ans += f[i];
	}
	printf("%d\n", ans);

	return 0;
}

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

struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }
	void init(int n) { par.assign(n, -1); }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>X(M); 
	vector<int>Y(M); 
	vector<int>Z(M);
	for (int n = 0;n<M; ++n) {
		cin >> X[n] >> Y[n] >> Z[n];
		--X[n];
		--Y[n];
	}
	UnionFind uf(N);
	for (int n = 0; n < M; ++n) {
		uf.merge(X[n],Y[n]);
	}	
	set<int>st;
	for (int n = 0; n < N; ++n) {
		st.insert(uf.root(n));
	}
	cout << st.size()<<endl;
	return 0;
}


Measured memory_bytes: 9512
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#define NUM 200

int main()
{
   static long i,j,k,l;
   static char s[NUM][1003];
   static int sum[NUM];


   for(i=0;;i++){
      fgets(s[i],1005,stdin);
      if(s[i][0] == '0')
         break;
      for(j=0;s[i][j] != '\n';j++)
         sum[i] += s[i][j] - '0';
   }
   for(j=0;j<i;j++)
      printf("%d\n",sum[j]);

   return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#include <queue>
#include <set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF LLONG_MAX/2e5

bool issquare(ll val){
	forn(i,val+2){
		if(i*i==val){
			return true;
		}
		if(i*i>val) return false;
	}
}

void solve(ll index){
	ll n,d;
	cin >> n >> d;
	ll a[n][d];
	forn(i,n) forn(j,d) cin >> a[i][j];
	ll ans = 0;
	forn(i,n){
		forsn(j,i+1,n){
			ll sum = 0;
			forn(k,d){
				sum += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			if(issquare(sum)) ans++;
		}
	}
	cout << ans << ln;
}

int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    // cin >> t;
    forn(i,t) solve(i+1);
    return 0;
}

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

int main() {
  string S, T, U;
  int A, B;

  cin >> S >> T;
  cin >> A >> B;
  cin >> U;

  if(S==U) cout << --A << " "  << B << endl;
  else cout << A << " " << --B << endl;
}


Measured memory_bytes: 256
#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 - 1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

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

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

const ll INF = 1e18;
const int mod = 1e9+7;
const int MAX = 1e6;

struct unionfind {
    vector<int> par; // 各要素の親(根の場合は-1)
    unionfind(int n) {
        par.resize(n, -1);
    }
    int root(int x) { // 要素xの属する集合の根のindexを返す(xが根の場合はx)
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) { // 要素xとyを同一の集合(根)に結合
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
    bool same(int x, int y) { // 要素xとyが同一の集合に属するか判定
        return root(x) == root(y);
    }
    int size(int x) { // 要素の属する集合の大きさ
        return -par[root(x)];
    }
};

struct edge {int to, cost;}; // 辺
vector<edge> graph[MAX]; // 隣接リスト
bool visited[MAX]; // 訪問の有無

void dfs(int cur, int &cnt) {
    cnt++;
    visited[cur] = true;
    for (edge e : graph[cur]) {
        if (not visited[e.to]) {
            dfs(e.to, cnt);
        }
    }
}

void solve1() { // DFSを使った解法
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a;
        cin >> b;
        graph[a].push_back({b, 0});
        graph[b].push_back({a, 0});
    }
    int ans = 0;
    rep(i, n) {
        int cnt = 0;
        if (not visited[i]) {
            dfs(i, cnt);
            chmax(ans, cnt);
        }
    }
    cout << ans << endl;
}

void solve2() { // UnionFindを使った解法
    int n, m;
    cin >> n >> m;
    unionfind f(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        f.unite(a, b);
    }
    int ans = 0;
    rep(i, n) {
        chmax(ans, f.size(i));
    }
    cout << ans << endl;
}

int main() {
    // solve1();
    solve2();
}

Measured memory_bytes: 27556
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define pb push_back

using namespace std;

ll d[101][100001];

int main(){
	ll n,w;cin>>n>>w;
	ll a[n+1],b[n+1];
	for(ll i=1;i<=n;i++)cin>>a[i]>>b[i];

	
    for(ll i=1;i<=n;i++){
    	for(ll j=1;j<=w;j++){
    		if(j-a[i]>=0){
    			d[i][j]=max(d[i-1][j-a[i]]+b[i],d[i-1][j]);
			}
			else d[i][j]=d[i-1][j];
		}
	}

	cout<<d[n][w];
}




Measured memory_bytes: 81732
#include<cstdio>
#include<algorithm>
using namespace std;
struct point{
    int a, b, c;
}w[101000];
struct AA{
    int num;
    double y;
    bool operator<(const AA &p)const{
        return y<p.y;
    }
}P[101000];
int n, BIT[101000], Ord[101000];
void Add(int a){
    while(a<=n){
        BIT[a]++;
        a += (a&-a);
    }
}
int Sum(int a){
    int s = 0;
    while(a){
        s += BIT[a];
        a -= (a&-a);
    }
    return s;
}
long long Calc(double x){
    int i;
    for(i=1;i<=n;i++){
        P[i].y = -(w[i].c+x*w[i].a)/w[i].b;
        P[i].num = i;
        BIT[i] = 0;
    }
    sort(P+1,P+n+1);
    long long r = 0;
    for(i=n;i>=1;i--){
        r += Sum(Ord[P[i].num]);
        Add(Ord[P[i].num]);
    }
    return r;
}
double Get(){
    double b = -1e9, e = 1e9, mid;
    int i;
    for(i=1;i<=n;i++){
        P[i].y = -(w[i].c+(-1e9)*w[i].a)/w[i].b;
        P[i].num = i;
    }
    sort(P+1,P+n+1);
    for(i=1;i<=n;i++)Ord[P[i].num] = i;
    for(i=0;i<62;i++){
        mid = (b+e)*0.5;
        if(Calc(mid)*2 >= 1ll*n*(n-1)/2)e = mid;
        else b = mid;
    }
    return (b+e)*0.5;
}
int main(){
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d%d%d",&w[i].a,&w[i].b,&w[i].c);
        w[i].c = -w[i].c;
    }
    double x = Get();
    for(i=1;i<=n;i++)swap(w[i].a,w[i].b);
    double y = Get();
    printf("%.10f %.10f\n",x,y);
}

Measured memory_bytes: 1920
import bisect

INF = int(10**9+1)

n, q = map(int, input().split())
tmp = [ (int(input()),i) for i in range(n) ]
tmp.sort()
s = [0]*n
f = [0]*n
i = 0
for key,val in tmp :
    s[i] = key
    f[val] = i
    i += 1

leader = []
while q > 0 :
    line = input().split()
    arg = int(line[1])
    #print(line)
    if line[0] == 'ADD':
        idx = bisect.bisect_left( leader, f[arg-1] )
        leader = leader[:idx] + [f[arg-1]] + leader[idx:]
    elif line[0] == 'REMOVE':
        leader.remove( f[arg-1] )
    else: #CHECK
        fail_r = -1
        succ_r = INF
        while succ_r - fail_r > 1 :
            mid = int((succ_r + fail_r)/2)
            count = 0
            prev = -1
            for idx in leader :
                l_idx = bisect.bisect_left( s, s[idx]-mid )
                r_idx = bisect.bisect_right( s, s[idx] ) - 1
                if l_idx <= prev : l_idx = prev + 1
                count += r_idx - l_idx + 1
                prev = r_idx

            if n - count <= arg : succ_r = mid
            else : fail_r = mid

        if succ_r == INF : print('NA')
        else : print(succ_r)

#    for idx in leader : print(idx)
    
    q -= 1



Measured memory_bytes: 188320
function main(input){
  const N = parseInt(input);
  let count = 0;
  
  const permutation = (sevenFiveThree, num, N) => {
    let Num = sevenFiveThree + 10*num;
    //console.log("Num",Num);
    let NumString = Num.toString();

    if(N>=Num) {
      //console.log("NumString",NumString);
      if(NumString.indexOf('7')!= -1 && NumString.indexOf('5')!= -1 && NumString.indexOf('3')!= -1) count++;
      permutation(7, Num, N);
      permutation(5, Num, N);
      permutation(3, Num, N);
    }
  };
  permutation(0, 0, N);
  console.log(count);    
}

main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 35944
dice_num, point = gets.chomp.split(' ').map(&:to_i)

prob = 0.0

(1..dice_num).each do |dice_roll|
  coin_roll_prob = (1.0/dice_num.to_f).to_f
  coin_roll_num = 0
  loop do
    if dice_roll >= point then
      prob = prob + coin_roll_prob
      break
    end
    dice_roll      = dice_roll * 2
    coin_roll_prob = (coin_roll_prob * (1.0/2.0).to_f).to_f
  end
end

print prob

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






#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define pii                 pair<int,int>
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define pbp(a,b)            push_back({a,b})
#define db                  double
#define ft                  float
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define N                   100007
#define inf                 100000008
#define mod                 1000000007

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/




int b[100];

int main()
{
    int x,y,i,j,a;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            a=i*j;
            b[a]=1;
        }
    }
    cin>>x;
    if(b[x]==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;

}
































Measured memory_bytes: 256
// abc085_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, H;
    cin >> N >> H;
    vector<pair<ll, int>> A(N), B(N);
    REP(i, N){
        int a, b; cin >> a >> b;
        A[i] = {a, i};
        B[i] = {b, i};
    }
    sort(ALL(A), greater<P>());
    sort(ALL(B), greater<P>());

    auto func = [&](int n){

        int cnt = 0;
        ll damage = 0;
        REP(i, N){
            if (B[i].first > A[0].first){
                damage += B[i].first;
                cnt++;
                if (cnt >= n) break;
            }
        }

        if (cnt < n){
            damage += A[0].first * (n - cnt);
        }

        return damage;
    };

    int ok = 1e9;
    int ng = 0;
    while (ok - ng > 1){
        int mid = (ok + ng) / 2;
        if (func(mid) >= H){
            ok = mid;
        } else {
            ng = mid;
        }
    }

    print(ok);



    return 0;
}


Measured memory_bytes: 3456