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

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 2e5 + 7;
int n, a[N], p[N], ans;

int main() {
	rd(n), rda(a, n);
	for (int i = 1; i <= n; i++) p[a[i]] = i;
	for (int i = 1, c = 0; i <= n; i++)
		if (i == n || p[i+1] < p[i]) ans = max(ans, ++c), c = 0;
		else ++c;
	print(n - ans);
	return 0;
}

Measured memory_bytes: 6432
#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 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 debug(x) cerr << #x << " = " << x << endl;

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

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;}

//-------------------< start here >-------------------------// 
const int N = 2e5 + 1;
bool isprime[N];
int dp[N];
void prime_gen(){
  fill(isprime + 2,isprime + N,true);
  for(int i = 2; i < N; i++){
	  if (isprime[i]){
		  for(int j = 2 * i; j < N; j+=i){
			 isprime[j] = false;  
		   }  
		}
	}	
}

void precompute(){
  	prime_gen();
  	for(int i = 1; i <= N; i++){
	   dp[i] = dp[i-1] + (isprime[i] && isprime[(i+1)/2]);	
     }
}

void solve(){
   precompute();
   int q;
   cin >> q;
   while (q--){
	   int l, r;
	   cin >> l >> r;
	   int ret = dp[r] - dp[l-1];
	   cout << ret << 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: 2432
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int> > data;
vector<bool> used;
vector<int> p;
void dfs(int vertex){
    used[vertex] = true;
    p.push_back(vertex);
    for (int i=0; i < data[vertex].size(); i++){
        int to = data[vertex][i];
        if (used[to]) continue;
        dfs(to);
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for (int i=0; i < n; i++) cin >> v[i];
    for (int i=0; i < n; i++){
        vector<int> help;
        data.push_back(help);
        used.push_back(false);
    }
    for (int i=0; i < m; i++){
        int a, b;
        cin >> a >> b;
        data[a-1].push_back(b-1);
        data[b-1].push_back(a-1);
    }
    int ans = 0;
    for (int i=0; i < n; i++){
        p.clear();
        if (used[i]) continue;
        dfs(i);
        set<int> ya;
        for (int j=0; j < p.size(); j++) ya.insert(v[p[j]] - 1);
        for (int j=0; j < p.size(); j++) if (ya.count(p[j])) ans++;
    }
    cout << ans;
}


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

int main(){
    int N, M;
    cin >> N;
    vector<string> vecN(N+10), vecM(M+10);
    for(int i=0; i<N; i++){
        cin >> vecN[i];
    }
    cin >> M;
    for(int i=0; i<M; i++){
        cin >> vecM[i];
    }

    int result = 0;

    for(int i=0; i<N; i++){
        int count = 0;
        for(int j=0; j<N; j++){
            if(vecN[i] == vecN[j]) count++;
        }
        for(int j=0; j<M; j++){
            if(vecN[i] == vecM[j]) count--;
        }

        result = max(result, count);
    }

    cout << result << endl;


}

Measured memory_bytes: 512
n, a, b = map(int, input().split())
m = 10**9 + 7


def choose(x, y):
    v = 1
    for i in range(0, y):
        v = (v * (x - i) * pow(i + 1, m - 2, m)) % m
    return v


print((pow(2, n, m) - 1 - choose(n, a) - choose(n, b)) % m)


Measured memory_bytes: 3060
word = input()

n = len(word)

a = (n-1)//2
b = (n+3)//2

word2 = word[:a]
word3 = word[b-1:]

def kai1():
    for i in range(a):
        if(word[i] != word[-1*(i+1)]):
            return False
    return True
def kai2():
    wl = len(word2)
    if(wl % 2 == 0):
        wl = wl//2
    else:
        wl = (wl-1)//2
    for i in range(wl):
        if(word2[i] != word2[-1*(i+1)]):
            return False
    return True
def kai3():

    wl = len(word3)
    if(wl % 2 == 0):
        wl = wl//2
    else:
        wl = (wl-1)//2
    for i in range(wl):
        if(word3[i] != word3[(-1*(i+1))]):
            return False
    return True

if(kai1() and kai2() and kai3()):
    print("Yes")
else:
    print("No")


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

int main() {
    int k; cin >> k;
    string s; cin >> s;
    if (s.size() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
#include <cstdint>
#include <cstring>

using namespace std;

//2019-08-18　A
int main()
{
	long long int a;
	cin >> a;

	string s;
	cin >> s;

	if (a >= 3200){
		cout << s << endl;
	}
	else{
		cout << "red" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	void run() {
		MyScanner sc = new MyScanner();

		int MAX = 1300000;
		boolean[] prime = new boolean[MAX];
		Arrays.fill(prime, true);
		prime[0] = prime[1] = false;
		for (int i = 0; i * i <= MAX; i++) {
			if (!prime[i]) continue;
			for (int j = i * i; j < MAX; j += i) {
				prime[j] = false;
			}
		}

		int[] len = new int[MAX];
		for (int i = 1; i < MAX; i++) {
			if (prime[i]) {
				len[i] = 0;
			} else {
				len[i] = len[i - 1] + 1;
			}
		}
		for (int i = MAX - 2; 0 <= i; i--) {
			if (len[i] != 0 && len[i + 1] != 0) {
				len[i] = len[i + 1];
			}
		}

		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}

			if (prime[n]) {
				System.out.println(0);
			} else {
				System.out.println(len[n] + 1);
			}
		}
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

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

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

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

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}

}

Measured memory_bytes: 25628
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;	cin >> n;
  vector<int>	a(n);
  for(int i=0;i<n;i++)	cin >> a[i];
  
  priority_queue<int,vector<int>,less<int>>	data;
  for(int i:a)	data.push(i);
  for(int i=0;i<n;i++){
    int x=data.top();
    if(a[i]!=x)	cout << x << endl;
    else{
      data.pop();
      cout << data.top() << endl;
      data.push(x);
    }
  }
}

Measured memory_bytes: 5000
#include <bits/stdc++.h>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-9;
const long long INF = OO;
const int MAXN = 5003, MAXM = 102, Mod = 998244353, MAXLog = 20;

int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout
			<< fixed;

	int n;
	cin >> n;
	int p = (1 << n);
	vector<int> arr(p);
	multiset<int> mst;
	for (int i = 0; i < p; ++i) {
		cin >> arr[i];
		mst.insert(arr[i]);
	}

	vector<int> cur;
	cur.push_back(*mst.rbegin());
	mst.erase(mst.find(*mst.rbegin()));
	while (mst.size()) {
		int sz = cur.size();
		for (int i = 0; i < sz; ++i) {
			auto it = mst.lower_bound(cur[i]);
			if (it == mst.begin()) {
				cout << "No\n";
				return 0;
			}
			--it;
			cur.push_back(*it);
			mst.erase(it);
		}
	}

	cout << "Yes\n";

	return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    int a = 0, b = 0, c = 0;
    REP(i, N)
    {
        int p;
        cin >> p;
        if (p <= A)
            a++;
        else if (p <= B)
            b++;
        else
            c++;
    }
    cout << std::min(a, std::min(b, c)) << endl;
    return 0;
}

Measured memory_bytes: 256
mod = 10**9+7
s = input()
N = len(s)

dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(13):
        if s[i] == '?':
            for x in range(10):
                dp[i+1][(10*j+x)%13] += dp[i][j]
                dp[i+1][(10*j+x)%13] %= mod
        else:
            x = int(s[i])
            dp[i+1][(10*j+x)%13] += dp[i][j]
            dp[i+1][(10*j+x)%13] %= mod

print(dp[N][5])

Measured memory_bytes: 88540
n, k = map(int, input().split())
a = list(map(int, input().split()))


li = []
for i in range(n):
    num = 0
    for j in range(i, n):
        num += a[j]
        li.append(num)

ans = 0
for i in range(40)[::-1]:
    bit = 2 ** i
    new_li = [num for num in li if num&bit != 0]
    if len(new_li) >= k:
        li = new_li[0:]
        ans += bit
print(ans)

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	map<int, int> num;
  ll n, k, a, result = 0;
  cin >> n >> k;
  rep(i, n) {
    cin >> a;
    num[a]++;
  }
  if (num.size() <= k) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> ch;
  for (auto i : num) {
    ch.pb(i.second);
  }
  sort(ch.begin(), ch.end());
  ll count = num.size() - k;
  rep(i, count) {
    result += ch[i];
  }
  cout << result << endl;
}

Measured memory_bytes: 14964
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.Maybe

readString = map BS.unpack . BS.words

getString = readString <$> BS.getLine

split :: String -> Int -> Int -> (Int, Int)
split [] o e = (o, e)
split [x] o e = split [] o' e
  where
      o' = if x == '1' then o + 1 else o
split (x : y : ss) o e = split ss o' e'
  where
    o' = if x == '1' then o + 1 else o
    e' = if y == '1' then e + 1 else e
    
main = do
  [s] <- getString
  let k = if odd (length s) then 1 else 0
  let hl = length s `div` 2
  let (ol, el) = split s 0 0
  if ol > el
        then print $ hl + k - ol + el
        else print $ ol + hl - el
          

Measured memory_bytes: 11644
// 2017/09/21 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int X;
	cin >> X;

	switch(X%7){
	case 0:
		cout << "thu" << endl;
		break;
	case 1:
		cout << "fri" << endl;
		break;
	case 2:
		cout << "sat" << endl;
		break;
	case 3:
		cout << "sun" << endl;
		break;
	case 4:
		cout << "mon" << endl;
		break;
	case 5:
		cout << "tue" << endl;
		break;
	case 6:
		cout << "wed" << endl;
		break;
	}

	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define mod 1000000007
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e5*2+5, maxn1=202;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };

int main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n,i,j,k,temp,sum=0,m;
cin>>n>>m;
rep(i,0,m)
{
    cin>>temp;
    sum+=temp;
}
sum=n-sum;
if(sum<0)
    cout<<"-1";
else
{
    cout<<sum;
}
return 0;
}



Measured memory_bytes: 3632
#include<iostream>

using namespace std;

int main(){
    int n,i,ans=1;
    cin>>n;
    for(i=0;i<n;i++){
		ans*=2;
		if(ans>n){
			ans/=2;
			break;
		}
    }
    cout<<ans<<endl;
    return 0;
} 

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

int main(void)
{
  int n;
  int k;
  std::cin >> n >> k;
  auto ds = std::vector<int>(k);
  for (int i = 0; i < k; i++) {
    std::cin >> ds[i];
  }
  while (true) {
    auto s = std::to_string(n);
    for (auto &&c : s) {
      for (auto &&d : ds) {
        if (d == c - '0') {
          goto next;
        }
      }
    }
    std::cout << n << '\n';
    return 0;
  next:
    n++;
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define MOD (1000000007LL)
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}

ll ppow(ll a,ll b){
	a %= MOD;
	ll res = 1;
	while(b){
		if(b & 1) res = (res * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll comb(ll n, ll r){
    ll si = 1; ll bo = 1;
    for(ll i=0; i<r; i++){
        bo = (bo * (i+1)) % MOD;
        si = (si * (n-i)) % MOD;
    }
    return (si * ppow(bo, MOD - 2)) % MOD;
}

int main(void){
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = ppow(2,n) - 1;
    ans = (((ans - comb(n,a) + MOD) % MOD - comb(n,b) + MOD) % MOD);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n, k = MAP()
l = LIST()
l.sort(reverse=True)
print(sum(l[:k]))

Measured memory_bytes: 60652
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

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

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({a * c, a * d, b * c, b * d});
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

int main(){
  string s;

  cin >> s;
  int cnt =0;

  string h = s;
  reverse(h.begin(), h.end());

  for(int i=0; i<s.size(); ++i){
    if(s[i] != h[i]) cnt++;
  }

  cout << cnt / 2;
 return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int>d(N);
    
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    
    sort(d.begin(), d.end());
    int tmp = N / 2 - 1;
    int tmp1 = N / 2;
    
    
    cout << d[tmp1] - d[tmp] << endl;
}


Measured memory_bytes: 640
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, A, B = MAP()

if A - B >= 0:
    print("delicious")
elif X >= (B - A):
    print("safe")
else:
    print("dangerous")


Measured memory_bytes: 26932
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    int n, T;
    cin >> n >> T;
    vector<int> c(n), t(n);
    for (int i = 0; i < n; i++){
        cin >> c[i] >> t[i];
    }

    int res = 1010;
    for (int i = 0; i < n; ++i){
        if (t[i] <= T){
            chmin(res, c[i]);
        }
    }
    if (res != 1010) cout << res << endl;
    else cout << "TLE" << endl;

    return 0;
}



Measured memory_bytes: 256
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest068-B
#  https://beta.atcoder.jp/contests/abc068/tasks/abc068_b


def breakNumber(pint):

	numArray = [i for i in range(1,pint+1)]
	i = 0

	while i < pint :
		devCount=0
		while numArray[i] % 2 == 0:
			devCount = devCount+1
			numArray[i] = numArray[i] // 2
		numArray[i] = devCount
		i=i+1

	maxDevLabel = -1
	maxDevNumber = -1
	i = 0
	while i < pint :
		if maxDevNumber < numArray[i] :
			maxDevNumber = numArray[i]
			maxDevLabel = i
		i = i + 1

	answer = maxDevLabel+1
	return answer


if __name__ == '__main__':
	inputNum = int(input())
	ans=breakNumber(inputNum)
	print(ans)



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, T;
    cin >> n >> T;
    int ans = 10000;
    for(int i=0; i<n; i++){
        int c, t;
        cin >> c >> t;
        if(t<=T){
            ans = min(ans, c);
        }
    }
    if(ans==10000){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 384
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = getDivisorList(N);
  myerr(list);
  if(list.length % 2 == 1){
     myout(list[Math.floor(list.length / 2)] * 2 - 2);
  }else{
     myout(list[list.length / 2 - 1] + list[list.length / 2] - 2);
  }
  
}

function getDivisorList(val){
        var list = [];
        for(var i = 1; i * i <= val; i++){
                if(val % i == 0){
                        list.push(i);
                        if(i * i != val){
                                list.push(val / i);
                        }
                }
        }
        list.sort(function(a,b){ return a - b; });
        return list;
}

Measured memory_bytes: 11680
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string data[9] = {"\',.!?", "abcABC", "defDEF", "ghiGHI", "jklJKL", "mnoMNO", "pqrsPQRS", "tuvTUV", "wxyzWXYZ"};

char conv(char n, int cnt){
  return data[n-'1'][(cnt-1)%(int)data[n-'1'].size()];
}

main(){
  string in;
  while(getline(cin, in)){
    string out;
    bool f = true;
    char num;
    int cnt = 0;
    for(int i=0;i<in.size();i++){
      if(f){
        num = in[i];
        cnt++;
        f = false;
      }else{
        if(in[i] == '0'){
          if(num == '0'){
            cnt++;
          }else{
            out += conv(num, cnt);
            num = in[i];
            cnt = 0;
          }
        }else if(num != in[i]){
          if(num == '0') while(cnt--) out += ' ';
          else out += conv(num, cnt);
          num = in[i];
          cnt = 1;
        }else{
          cnt++;
        }
      }
    }
    if(num == '0') while(cnt--) out += ' ';
    else out += conv(num, cnt);
    cout << out << endl;
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 100005;
int N, A, B, h[maxn];

bool check(int g) {
    int cnt = 0;
    for(int i=1; i<=N; ++i) {
	if(1LL*g*B>=h[i]) continue;
	cnt += ceil(1.0*(h[i]-g*B)/A);
	if(cnt>g) return false;
    }
    return true;
}
int main() {
    scanf("%d%d%d", &N, &A, &B);
    A -= B;
    int H = 0;
    for(int i=1; i<=N; ++i) {
	scanf("%d", h+i);
	H = max(H, h[i]);
    }
    int l = 1, r = H/B+1, mid, ans = 1e9;
    while(l<=r) {
	mid = (l+r)>>1;
	if(check(mid)) ans = mid, r = mid-1;
	else l = mid+1;
    }
    printf("%d\n", ans);
    return 0;
}


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

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const ll MOD = 1000000007;
using mint = Fp<MOD>;

int main(){
    ll n,k; cin >> n >> k;
    mint ans=1;
    vector<mint> s(n+10,0);
    for(ll i=1;i<=n;i++){
        s[i]=s[i-1]+i;
    }
    for(ll i=k;i<n+1;i++){
        mint ma = (s[n]-s[n-i]);
        mint mi = (s[i-1]);
        ans += (ma-mi+1);
    }
    cout << ans << endl;
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct A {
  int c;
  int s;
};

A g(int x, int y) {
  int count = 0;
  while(y > 0) {
    count++;
    x %= y;
    swap(x, y);
  }

  A a;
  a.c = count;
  a.s = x;
  return a;
}

int main() {
  int x, y;
  while(cin >> x >> y) {
    if(!x && !y) return 0;
    A a = g(max(x, y), min(x, y));
    cout << a.s << " " << a.c << endl;
  }
}

Measured memory_bytes: 3164
using System;
using System.Linq;

class Program
{
    public static void Main(string[] args)
    {
        int sum = 0;
        while(true)
        {
            string s = Console.ReadLine();
            if(s == null) break;
            string[] ss = s.Split();
            int a = int.Parse(ss[0]);
            int b = int.Parse(ss[1]);
            sum = a + b;
            
            if(sum / 1000000 >= 1)
            {
                Console.WriteLine(7);
            }else if(sum / 100000 >= 1)
            {
                Console.WriteLine(6);
            }else if(sum / 10000 >= 1)
            {
                Console.WriteLine(5);
            }else if(sum / 1000 >= 1)
            {
                Console.WriteLine(4);
            }else if(sum/ 100 >= 1)
            {
                Console.WriteLine(3);
            }else if(sum / 10 >= 1)
            {
                Console.WriteLine(2);
            }else
            {
                Console.WriteLine(1);
            }
        }
    }
}


Measured memory_bytes: 13848
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int solve(int n, int a, int b)
{
  return std::min(n * a, b);
}

int main()
{
  int n, a, b;
  std::cin >> n >> a >> b;

  std::cout << solve(n, a, b) << std::endl;
}


Measured memory_bytes: 256
//author : 'Amit Singh Sansoya @amit3200'
//it was all meant to happen as i was all talk!
#include<bits/stdc++.h>
using namespace std;
long long int n,w,ele,ans=0;
vector<pair<long long int,long long int>> arr;
vector<vector<long long>> dp;
long long dfs(long row,long long int W){
	if(W<0){
		return INT_MIN;
	}
	if(row>n || W==0)
		return 0;
	if(dp[row][W]!=-1){
		return dp[row][W];
	}
	long long int x=0,y=0;
	x=arr[row].second+dfs(row+1,W-arr[row].first);
	y=dfs(row+1,W);
	dp[row][W]=max(x,y);
	return dp[row][W];
}

int main(){
	cin>>n>>w;
	for(int i=0;i<n;i++){
		long long we,v;
		cin>>we>>v;
		arr.push_back({we,v});
	}
	dp.resize(n+1,vector<long long int>(w+1,-1));
	dfs(0,w);
	long long int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=w;j++){
//			cout<<dp[i][j]<<" ";
			ans=max(ans,dp[i][j]);
		}
//		cout<<"\n";
	}
	cout<<ans<<"\n";	
}

Measured memory_bytes: 80256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MON 1000000007
#define INF (1<<29)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

class Edge{
public:
  int from, to, rev;
  Int cost, lim;
  Edge(int from, int to, Int cost, int lim = -1, Int rev = -1):
    from(from),to(to),cost(cost),lim(lim),rev(rev){}
};


class Graph{
public:
  int n;
  int m;
  vector<vector<Edge>> edge;
  Graph(int n = 0):n(n),m(0){
    edge = vector<vector<Edge>>(n);
  }
  void add_edge(int from, int to, int cost = 1, int lim = -1)
  {
    if(lim == -1){
      edge[from].push_back(Edge(from, to, cost));
      return;
    }
    edge[from].push_back(Edge(from, to, cost, lim, edge[to].size()));
    edge[to].push_back(Edge(to, from, -cost, 0, edge[from].size() - 1));
  }
};
void ok(){
  cout << "1" << endl;
  exit(0);
}

void ng(){
  cout <<  "0" << endl;
  exit(0);
}

Graph g;
vector<int> loop(108000), come(108000);
int n, m, u, v;
bool dfs(int x){
  if(loop[x])return true;
  if(come[x])return false;
  come[x] = true;
  loop[x] = true;
  for(auto e:g.edge[x]){
    if(dfs(e.to)){
      return true;
    }
  }
  loop[x] = false;
  return false;
}

int main(){
  cin >> n >> m;
  g = Graph(n);
  for(int i = 0;i < m;i++){
    cin >> u >> v;
    g.add_edge(u, v, 1);
  }

  for(int i = 0;i < n;i++){
    if(come[i])continue;
    if(dfs(i))ok();
  }
  ng();
  return 0;
}


Measured memory_bytes: 3464
n,inc,dec=int(input()),[],[]
for _ in range(n):
  s,d,r=input(),0,0
  for c in s:
    d=d+(1 if c=='(' else -1)
    r=max(r,-d)
  (dec if d<0 else inc).append((d,r))
inc.sort(key=lambda x:x[1])
dec.sort(key=lambda x:x[0]+x[1])
p1,p2,ok=0,0,True
for s in inc:
  ok&=s[1]<=p1
  p1+=s[0]
for s in dec:
  ok&=p2>=s[0]+s[1]
  p2-=s[0]
ok&=p1==p2
print('Yes'if ok else'No')
    

Measured memory_bytes: 84228
a,b,k=map(int,input().split())
for i in range(k):
    if i%2==0:
      if a%2==1:
          a-=1
      b+=a//2
      a=a//2
    else:
      if b%2==1:
          b-=1
      a+=b//2
      b=b//2
print(a,b)


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

int main(){
 string S; cin>>S;
 int N=S.size();

 string ans;

 if(S.front()==S.back()){
  ans = (N%2==1) ? "Second" : "First";
 }
 else{
  ans = (N%2==1) ? "First" : "Second";
 }

 cout<<ans<<endl;

 return 0;
}




Measured memory_bytes: 3708
#include<stdio.h>
 
int main(){
  int n,m,i;
  int a[100];
  double sum=0;
  int OK=0;
  
  scanf("%d",&n); scanf("%d",&m);
  
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum=sum+a[i];
  }
  
  for(i=0;i<n;i++){
    if(a[i]>=sum/(4*m))
      OK++;
  }
  
  if(OK>=m)
    printf("Yes");
  else
    printf("No");
  
  return 0;
}

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

int main(){
    int n,i=0;
    string k;
    cin >> n;
    cin >> k;

if (k.size() > n) {
 k = k.substr(0, n) + "...";
 }

 cout << k << '\n';

    return 0;
}

Measured memory_bytes: 3556
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  int num[101] = {};
  
  for(int i = a; i < b; i++){
    num[i]++;
  }
  for(int i = c; i < d; i++){
    num[i]++;
  }
  
  int ans = 0;
  REP(i,101){
    if(num[i] == 2) ans++;
  }
  
  cout << ans << endl;
  
  


 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b="CODEFESTIVAL2016";
int c=16;
int main(){
    cin>>a;
    for(int i=0;i<16;i++){
        c-=(a[i]==b[i])? 1:0;
    }
    cout<<c<<endl;
    return 0;
}


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

int main(){
  int x, y, r, w, h;
  int i;
  int edge[4];
  int flag = 0;

  cin>>w>>h>>x>>y>>r;
  edge[0] = x-r;
  edge[1] = w-(x+r);
  edge[2] = y-r;
  edge[3] = h-(y+r);

  for(i = 0; i < 4; i++){
    if(edge[i] < 0){
      flag = 1;
      break;
    }
  }

  if(flag == 0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

}

Measured memory_bytes: 1156
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var a,b,c,k int
	Fscan(in, &a, &b, &c, &k)
	ans := 0
	if k<=a {
		ans = k
		k=0
	} else {
		ans = a
		k-=a
	}

	if k<=b {

		k=0
	} else {

		k-=b
	}

	if k <= c {
		ans-=k
	} else {
		ans-=c
	}
	Fprintln(out, ans)
}

func main() { run(os.Stdin, os.Stdout) }


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

using namespace std;

int main(){
  double a,ans=0;
  int n;
  string s;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    cin >> s;
    if(s=="JPY"){
      ans+=a;
    }
    else if(s=="BTC"){
      ans+=a*380000;
    }
  }
  cout << fixed;
  cout << setprecision(6) << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
P = [int(e)-1 for e in input().split()]
cnt = 0
for i in range(N-1):
    if P[i] == i:
        P[i],P[i+1] = P[i+1],P[i]
        cnt += 1
if P[N-1] == N-1:
    P[N-2],P[N-1] = P[N-1],P[N-2]
    cnt += 1
print(cnt)

Measured memory_bytes: 13880
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int n,k;
  scanf("%d %d\n", &n ,&k);
  char s[50];
  scanf("%s",s);
  char c = *(s+k-1);
  *(s+k-1) = c - ('A'-'a');
  printf("%s", s);
}


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

int gcd (int x, int y){
    if(x==0 || y==0) return max(x,y);
    if(x<y) return gcd(x,y%x);
    return gcd(y,x%y);
}

int main(){
    int N; long long X;
    long long x[100100];
    cin >> N >> X;
    for(int i=0; i<N; i++){
        cin >> x[i];
        x[i] = abs(X-x[i]);
    }
//    for(int i=0; i<N; i++){
//        cout << x[i] << endl;
//    }
    long long ans =x[0];
    for(int i=0; i<N-1; i++){
        ans = gcd(ans, x[i+1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]  # 親
        self.rank = [1] * n  # 木の高さ
        self.size = [1] * n  # size[i] は i を根とするグループのサイズ

    def find(self, x):  # x の根を返す
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  # 経路圧縮
            return self.parent[x]

    def unite(self, x, y):  # x, y の属する集合を併合する
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def is_same(self, x, y):  # x, y が同じ集合に属するか判定する
        return self.find(x) == self.find(y)

    def group_size(self, x):  # x が属する集合の大きさを返す
        return self.size[self.find(x)]

    def __str__(self):  # print 表示用
        return '\n'.join('{}: {}'.format(r, self.group_members(r)) for r in self.roots())


N, M = map(int, input().split())
bridge = [list(map(int, input().split())) for _ in range(M)]
ans = [0]*M
uf = UnionFind(N)

# うしろからつないでいく
ans[M-1] = N*(N-1)//2
for i in range(M-2, -1, -1):
    A, B = bridge[i+1]
    if uf.is_same(A-1, B-1):
        ans[i] = ans[i+1]
    else:
        ans[i] = ans[i+1] - uf.group_size(A-1) * uf.group_size(B-1)
    uf.unite(A-1, B-1)

for a in ans:
    print(a)


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    int tmp = 0;
    while (N > 1)
        N /= 2, tmp++;
    cout << pow(2, tmp);
}

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

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define xmax(x,y) ((x) = max((x),(y)))
#define xmin(x,y) ((x) = min((x),(y)))
#define all(x) (x).begin(),(x).end()
#define mem(x) memset(x , 0 , sizeof(x))
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define FP(a , b , c)  for(ll (a) = (b) ; (a) < (c) ; (a++));
#define FM(a , b , c)  for(ll (a) = (b) ; (a) >= (c) ; (a--));
#define connect(a , b , c) a[b].pb(c) , a[c].pb(b)

typedef long long int ll;
typedef unsigned long long int ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <string> vs;

const ll Maxn3 = 1e3 + 10;
const ll Maxn4 = 1e4 + 10;
const ll Maxn5 = 1e5 + 10;
const ll Maxn6 = 1e6 + 10;
const ll Maxn7 = 1e7 + 10;
const ll Maxn8 = 1e8 + 10;
const ll Maxn9 = 1e9 + 10;
const ll Maxn18 = 1e18 + 10;
const ll Mod1 = 1e7 + 7;
const ll Mod2 = 1e9 + 7;
const ll LLMax = LLONG_MAX;
const ll LLMin  = LLONG_MIN;
const ll INTMax = INT_MAX;
const ll INTMin  = INT_MIN;

ll mn = LLMax , mx = LLMin;
bool mark[5];
int main()
{_
    ll n; cin >> n;char c;
    for(ll i = 0 ; i < n ; i++)
    {
        cin >> c;
        if(c == 'P') mark[0] = 1;
        if(c == 'W') mark[1] = 1;
        if(c == 'G') mark[2] = 1;
        if(c == 'Y') mark[3] = 1;
    }
	return cout << (mark[3] ? "Four" : "Three") , 0;
}
///SAliB


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static int[] parent,depth,size;
	
	static int getParent(int u)
	{
		if(u==parent[u])	
			return u;
		int val=getParent(parent[u]);parent[u]=val;return parent[u];
	}
	
	static void merge(int u,int v)
	{
		if(depth[u]>depth[v])
		{
			size[u]+=size[v];parent[v]=u;
		}
		else if(depth[v]>depth[u])
		{
			size[v]+=size[u];parent[u]=v;
		}
		else
		{
			depth[u]++;size[u]+=size[v];parent[v]=u;
		}
	}
	
	public static void main(String args[]) throws Exception
	{
		int n=sc.nextInt();Pair[] a=new Pair[n];TreeSet<Integer> ts=new TreeSet<Integer>();parent=new int[n];depth=new int[n];size=new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=new Pair(i,sc.nextLong());parent[i]=i;depth[i]=1;size[i]=1;
		}
		Arrays.sort(a);long res=0;
		for(int i=n-1;i>=0;i--)
		{
			long l=1,r=1;Integer val1=ts.lower(a[i].idx),val2=ts.higher(a[i].idx);
			if(val1!=null && val1==a[i].idx-1)
			{
				int x=getParent(a[i].idx-1);l+=size[x];merge(x,a[i].idx);
			}
			if(val2!=null && val2==a[i].idx+1)
			{
				int x=getParent(a[i].idx+1);r+=size[x];merge(x,getParent(a[i].idx));
			}
			res=res+(a[i].val*l*r);ts.add(a[i].idx);
		}
		out.println(res);out.close();
	}
}
class Pair implements Comparable<Pair>
{
	int idx;long val;
	public Pair(int idx,long val)
	{
		this.idx=idx;this.val=val;
	}
	public int compareTo(Pair x)
	{
		return Long.compare(this.val,x.val);
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}

Measured memory_bytes: 43748
#include <cstdio>

using namespace std;

int ans[200043];

int main(int argc, char const *argv[]) {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    ++ans[x];
  }
  for (int i = 1; i <= n; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}

Measured memory_bytes: 2456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f(ll x) {
  ll temp=(x+1)/2%2;
  if(x%2) {
    return temp;
  }
  return temp^x;
}

int main() {
  ll a, b;
  cin >> a >> b;
  if(a==b) {
    cout << a << endl;
    return 0;
  }
  ll ans=f(a-1)^f(b);
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  string A;
  set<string> R;
  rep(i, N) {
    cin >> A;
    R.insert(A);
  }
  
  int Ans;
  Ans = R.size();
  cout << Ans << endl;
}

Measured memory_bytes: 19120
#include<bits/stdc++.h>
using namespace std;
#define MAX 55
inline int read()
{
    int x=0;
	bool t=false;
	char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
		ch=getchar();
    if(ch=='-')
		t=true,ch=getchar();
    while(ch<='9'&&ch>='0')
		x=x*10+ch-48,ch=getchar();
    return t?-x:x;
}
int n;
struct Node{int x,y;}p[MAX];
bool operator<(Node a,Node b){if(a.x!=b.x)return a.x<b.x;return a.y<b.y;}
set<Node> M;
int ans=1e9;
int main()
{
    n=read();
    for(int i=1;i<=n;++i)p[i].x=read(),p[i].y=read();
    if(n==1){puts("1");return 0;}
    sort(&p[1],&p[n+1]);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
        {
            int P=p[j].x-p[i].x,Q=p[j].y-p[i].y;
            if(P<0)P=-P,Q=-Q;
            M.clear();int ret=0;
            for(int k=1;k<=n;++k)
            {
                if(!M.count((Node){p[k].x-P,p[k].y-Q}))
					++ret;
                M.insert(p[k]);
            }
                ans=min(ans,ret);
        }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
a,b = ma()
cnt=1
ans=0
while cnt<b:
    cnt=cnt-1 +a
    ans+=1
print(ans)


Measured memory_bytes: 9428
N = int(input())
jobs = []
for i in range(N):
    jobs.append(list(map(int, input().split())))
           
time = 0
result = "Yes"
jobs.sort(key=lambda x:x[1])

for job in jobs:
    time += job[0]
    if(time > job[1]):
        result = "No"
        break

print(result)

    


Measured memory_bytes: 53720