akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

void solve()
{

}

int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin>>n>>k;
vll a(n);
rep(i,0,n-1)cin>>a[i];

rep(i,k,n-1)
{
	if(a[i]>a[i-k])
	{
		ol("Yes\n");
	}
	else
	{
		ol("No\n");
	}
}
return 0;
}



Measured memory_bytes: 4784
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>

using namespace std;

#define ll long long
#define pb push_back

int main(){

    ll N, M;
    vector<pair<pair<ll, ll>, pair<ll, string>>> P;
    cin >> N >> M;
    for(int i = 0; i < M; i ++){
        ll p, y;
        cin >> p >> y;
        P.pb(make_pair(make_pair(p, y), make_pair(i, "")));
    }
    sort(P.begin(), P.end());
    int cnt = 0;
    for(int i = 0; i < M; i ++){
        cnt ++;
        if(cnt > 1 && P[i].first.first != P[i - 1].first.first){
            cnt = 1;
        }
        string tmp1, tmp2;

        tmp1 = to_string(P[i].first.first);
        reverse(tmp1.begin(), tmp1.end());
        while(tmp1.size() < 6){
            tmp1.pb('0');
        }
        reverse(tmp1.begin(), tmp1.end());

        tmp2 = to_string(cnt);
        reverse(tmp2.begin(), tmp2.end());
        while(tmp2.size() < 6){
            tmp2.pb('0');
        }
        reverse(tmp2.begin(), tmp2.end());

        P[i].second.second = tmp1 + tmp2;
        /*ll tmp = P[i].first.first;
        P[i].first.first = P[i].second.first;
        P[i].second.first = tmp;*/
    }
    for(int i = 0; i < M; i ++){
        ll tmp = P[i].first.first;
        P[i].first.first = P[i].second.first;
        P[i].second.first = tmp;
    }
    sort(P.begin(), P.end());
    for(int i = 0; i < M; i ++){
        cout << P[i].second.second << endl;
    }

    return 0;
}

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

const int mod = 1000000007;
//素因数分解
vector<pair<ll,ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (long long a = 2; a * a <= n; a++){
    if(n % a != 0) continue;
    ll ex = 0; //指数
    while(n % a == 0){
      ex++;
      n /= a;
    }
    res.push_back(make_pair(a, ex));
  }
  if(n != 1){
    res.push_back(make_pair(n, 1));
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> ex(n + 1, 0);
  for (ll i = 2; i <= n; i++){
    const auto &res = prime_factorize(i);
    for(auto p: res) ex[p.first] += p.second;
  }
  ll ans = 1;
  for (int p = 2; p <= n; p++){
    ans *= ex[p] + 1;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <list>
#include <deque>
#include <bitset>
#include <numeric>
#include <iomanip>

using namespace std;

inline int toInt(string s) {int d; istringstream iss(s); iss >> d; return d;}
template<class T> inline string toString(T d) {ostringstream oss; oss << d; return oss.str();}

template<class T> inline T pow2(T x) {return x*x;}

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> VI;
typedef vector<string> VS;
 
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SORT(v) sort(ALL(v))
#define PB push_back
#define MP(x,y) make_pair(x,y)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define PARSE(type, v, str) {istringstream iss(str); type val; while(iss >> val) v.push_back(val);}

const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = 1000000000;
const ll LLINF = 10000000000000000LL;

#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int N, L[201];

int main()
{
  ios::sync_with_stdio(false);

  cin >> N;
  FOR(i,0,2*N) cin >> L[i];
  sort(L, L+2*N);
  int ans = 0;
  FOR(i,0,N) {
    ans += L[2*i];
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;

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

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

// dp[i][t] : i番目までのアイテムを使って、時間 t 以内の最適値
const ll N_MAX = 3001, T_MAX = 3001;
ll dp[N_MAX][T_MAX] = {};
bool use[N_MAX] = {};
ll A[N_MAX] = {};
ll B[N_MAX] = {};

void DP(ll N, ll T){
    // create dp table;
    for(ll i = 1; i <= N; ++i){
        ll ai = A[i], bi = B[i];
        for(ll t = 1; t <= T; ++t){
            if(ai <= t){
                auto tmp = dp[i-1][t-ai] + bi;
                auto tmp2 = dp[i-1][t];
                //printf("i: %lld, t: %lld, tmp: %lld, tmp2: %lld\n", i, t, tmp, tmp2);
                dp[i][t] = max(tmp, tmp2);
            }
            else {
                dp[i][t] = dp[i - 1][t];
            }
        }
    }
}

void DP_OptimalSolution(ll N, ll T){
    for(ll i =N; i>=1; i--){
        ll Ti = A[i];
        ll Bi = B[i];
        if (T >= Ti){
            if(dp[i-1][T-Ti] + Bi > dp[i-1][T]){
                use[i]=1;
                T -= Ti;
            }
        }
    }
}

int main() {
    auto N = read<ll>(),
        T = read<ll>();
    REP(i, N){
        A[i+1] = read<ll>();
        B[i+1] = read<ll>();
    }
    
    DP(N, T-1);
    DP_OptimalSolution(N, T-1);
    
    ll ans = dp[N][T-1];
    //write("ans"); write(ans);
    ll ans2 = 0;
    REP(i, N){ if(!use[i+1]){ ans2 = max(ans2, B[i+1]); } }
    write(ans + ans2);
}



Measured memory_bytes: 70656
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

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

    cout<<min(n*a,b)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;

int main() {
//	cout << fixed << setprecision(15);
    string s;
    cin >> s;
    if(s[1] == 'B') s[1] = 'R';
    else s[1] = 'B';
    cout << s << endl;
}


Measured memory_bytes: 3620
while true do
    i = gets
    h = i.split[0].to_i
    w = i.split[1].to_i
    break if h == 0 && w == 0
    h.times do |x|
        w.times do |y|
            print "#" if (x%2 == 0 && y%2 == 0) || (x%2 == 1 && y%2 == 1)
            print "." if (x%2 == 0 && y%2 == 1) || (x%2 == 1 && y%2 == 0)
        end
        print "\n"
    end
    print "\n"
end



Measured memory_bytes: 6876
#include <cstdio>
#include <iostream>
const int max_ = 1e5 + 15;

long long int ans;
long long int A[max_], B[max_];
using namespace std;
int main() {
	
	int n;
    cin >> n;
    
    for (int i = 1; i <= n + 1; ++i) {
        scanf("%lld", &A[i]);
    }
    
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &B[i]);
        if (B[i] <= A[i])
            ans += B[i];
        else if (B[i] <= A[i] + A[i + 1]) {
            ans += B[i];
            A[i + 1] -= (B[i] - A[i]);
        }
        else {
            ans += (A[i] + A[i + 1]);
            A[i + 1] = 0;
        }
    }
    printf("%lld", ans);
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> l(N);
  vector<int> r(N);
  int ans = 0;
  for(int i=0;i<N;i++){
    cin >> l[i] >> r[i];
    ans += r[i] - l[i] + 1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

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

    vector<int> dp(s+1);
    dp[0]=1;
    for(int i = 3; i <= s; i++) {
        ll sum = 0;
        for(int j = 3; j <= i; j++) {
            int a = i-j;
            sum += dp[a];
            sum %= INF;
        }
        dp[i]=sum;
    }

    cout << dp[s] << endl;

    return 0;
}

Measured memory_bytes: 3616
import copy
n = int(input())
s = input()

l = [set({})] * n
r = [set({})] * n
for i in range(1, n):
    l[i] = copy.copy(l[i-1])
    l[i].add(s[i-1])

for i in range(1, n):
    r[n-i-1] = copy.copy(r[n-i])
    r[n-i-1].add(s[n-i])

ok = set()

for i in range(1, n-1):
    for x in l[i]:
        for y in r[i]:
            ok.add(x + s[i] + y)

print(len(ok))

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

using namespace std;

int main() {
	long long int x, y;
	cin >> x >> y;
	if (x > y) {
		swap(x, y);
	}
	if (y == 0) {
		cout << "Brown" << endl;
	}
	else if (y == 1) {
		cout << "Brown" << endl;
	}
	else {
		if (x + 2 <= y) {
			cout << "Alice" << endl;
		}
		else {
			cout << "Brown" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
int factorial(int k){
    int n=1;
    for(int i=1;i<=k;i++){
        n*=i;
    }
    return n;
}
int main(){
  int n;
  cin>>n;
  vector<P> p(n);
  
  REP(i,n){
    cin>>p[i].first>>p[i].second;
  }
  double sum=0;
  REP(i,n){
    for(int j=0;j!=i&&j<n;j++){
      int d=pow((p[i].first-p[j].first),2)+pow(p[i].second-p[j].second,2);
      sum+=pow(d,0.5);
    }
  }
  cout<<fixed<<setprecision(10)<<sum*2/n<<endl;
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (((bit >> i) & 1) > 0)

typedef long long LL;
template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a, Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}    // C++14
template<typename T,typename V> typename std::enable_if<std::is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename std::enable_if<std::is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const long double PI = acos(-1.0);
const std::vector<int> dy4 = {0, -1, 0, 1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };


using namespace std;


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

    string S;
    cin >> S;

    const int N = S.size();

    int l, r;
    int ans = N / 2;
    if (N % 2 == 0) {
        r = N / 2;
        l = r - 1;
    }
    else {
        r = N / 2;
        l = N / 2;
    }

    char c = S[l];
    while (l >= 0 and r < N and S[l] == c and S[r] == c) {
        l--;
        r++;
        ans++;
    }
    print(ans);

    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int x, y;
    cin >> x >> y;

    int res = 0;
    while(x <= y) {
        res++;
        x *= 2;
    }

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
import Data.Bits

accumulatedSum :: [Int] -> [Int]
accumulatedSum [] = []
accumulatedSum [x] = [x]
accumulatedSum (x:y:rs) = x:accumulatedSum ((y + x):rs)

solve :: Int -> Int -> [Int] -> Int
solve k 0 a = 0
solve k i a
  | k <= length b = s .|. solve k (i - 1) b
  | otherwise = solve k (i - 1) a
    where
      s = shift 1 $ i - 1
      b = [x | x <- a, (x .&. s) /= 0]

beauties :: [Int] -> [Int]
beauties [x] = []
beauties (x:rs) = [y - x | y <- rs] ++ beauties rs

main :: IO ()
main = do
  [_, k] <- (fmap (\x -> read x :: Int)) . words <$> getLine
  a <- (fmap (\x -> read x :: Int)) . words <$> getLine
  let b = accumulatedSum a in
    print $ solve k 40 $ beauties (0:b)


Measured memory_bytes: 46460
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

template<typename Monoid>
struct SegmentTree {
	using Op = function<Monoid(const Monoid& lhs, const Monoid& rhs)>;
	size_t width;
	vector<Monoid> node;
	Op op;
	Monoid unit;
 
	SegmentTree(const vector<Monoid>& elems, Op op, Monoid unit)
	: op(op)
	, unit(unit) {
		width = 1;
		while (width < elems.size()) {
			width *= 2;
		}
		node.resize(2 * width - 1, unit);
		for (size_t i = 0; i < elems.size(); i++) {
			node[i + width - 1] = elems[i];
		}
		for (size_t i = width - 2; i != numeric_limits<size_t>::max(); i--) {
			node[i] = op(node[2 * i + 1], node[2 * i + 2]);
		}
	}
	void update(size_t idx, Monoid elem) {
		idx += width - 1;
		node[idx] = elem;
		while (idx >= 1) {
			idx = (idx - 1) / 2;
			node[idx] = op(node[2 * idx + 1], node[2 * idx + 2]);
		}
	}
	Monoid query(size_t a, size_t b, size_t root) const {
		assert(0 <= a && b <= width);
		size_t left = root, right = root;
		while (left < width - 1) {
			left = 2 * left + 1;
		}
		left -= (width - 1);
		while (right < width - 1) {
			right = 2 * right + 2;
		}
		right -= (width - 1);
		right++;
		if (right <= a || b <= left) {
			return unit;
		}
		if (a <= left && right <= b) {
			return node[root];
		}
		Monoid ans_l = query(a, b, 2 * root + 1);
		Monoid ans_r = query(a, b, 2 * root + 2);
		return op(ans_l, ans_r);
	}
};

int main() {
	ll N, M;
	cin >> N >> M;
	struct Range {
		ll L;
		ll R;
		ll C;
	};
	vector<Range> ranges;
	rep(i,0,M) {
		ll l, r, c;
		cin >> l >> r >> c;
		l--;
		r--;
		ranges.push_back(Range{l, r, c});
	}
	sort(ranges.begin(), ranges.end(), 
		 [](Range lhs, Range rhs){ return lhs.R < rhs.R; });
	vector<ll> dp_init(N, numeric_limits<ll>::max());
	SegmentTree<ll> dp(dp_init, [](ll lhs, ll rhs){ return min(lhs, rhs); },
						numeric_limits<ll>::max());
	dp.update(0, 0);
	rep(i,0,M) {
		Range range = ranges[i];
		ll now = dp.query(range.R, range.R+1, 0);
		ll x = dp.query(range.L, range.R, 0);
		ll v = numeric_limits<ll>::max();
		if (x < numeric_limits<ll>::max()) {
			v = x + range.C;
		}
		dp.update(range.R, min(now, v));
	}
	ll ans = dp.query(N-1, N, 0);
	if (ans == numeric_limits<ll>::max()) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}
}


Measured memory_bytes: 6000
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

'''
pythonにsortedsetをくれlower_boundとupper_boundをくれ
'''

def main():
    a,b,q = map(int,ipt().split())
    s = [-10**11]+[int(ipt()) for i in range(a)]+[10**11]
    t = [-10**11]+[int(ipt()) for i in range(b)]+[10**11]

    for i in range(q):
        x = int(ipt())
        ns = bisect.bisect_left(s,x)
        nt = bisect.bisect_left(t,x)
        ls = s[ns-1]-x
        rs = s[ns]-x
        lt = t[nt-1]-x
        rt = t[nt]-x
        ans = []
        ans.append(2*rs-lt)
        ans.append(2*rt-ls)
        ans.append(max(rs,rt))
        ans.append(-min(ls,lt))
        ans.append(rs-2*lt)
        ans.append(rt-2*ls)
        print(min(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 85444
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
int main(){
    int a,b,t;
    cin>>a>>b>>t;
    cout<<b*(t/a)<<endl;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    d = list(map(int, input().split()))
    d.sort()
    print(d[n // 2] - d[n // 2 - 1])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

 
// Driver code to test above functions
int32_t main()
{
 
    long long n, ans = 0;
    cin >> n;
    map<long long, int> mp;
    for(int i=1;i<=n;i++)
    {
        long long x;
        cin >> x;
 
        ans += mp[i-x];
 
        mp[i+x]++;
    }
 
    cout << ans;
 
    return 0;
 
} 


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

int main(){
    int n,x,y; cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n+1,0);
    rep(i,n){
        for(int j=i+1;j<n;j++){
            int di = min(abs(x-i)+1+abs(y-j), j-i);
            ans[di]++;
        }
    }
    rep(i,n-1){
        cout << ans[i+1] << endl;
    }
}

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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int C = in.nextInt();
		int K = in.nextInt();
		int[] T = new int[N];
		for (int i = 0; i < N; i++) {
			T[i] = in.nextInt();
		}
		Arrays.sort(T);
		long max = 0;
		int ans = 0;
		int count = 0;
		for (int i = 0; i < N; i++) {
			if (T[i] > max || count >= C) {
				ans++;
				max = T[i] + K;
				count = 0;
			}
			count++;
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 50876
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;


int main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int sum=A*X+B*Y;
    int ans=sum;
    int x=X,y=Y;
    for(int i=1; i<=max(X,Y); i++){
        int res=sum;
        res += C*2;
        if(x>0){
            res -= A;
        }
        if(y>0){
            res -= B;
        }
        ans = min(ans,res);
        sum = res;
        x--;
        y--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 12;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    while (1) {
        int n, m, a[1001], ans = -1;
        cin >> n >> m;
        if (n == 0) break;
        REP(i, n) cin >> a[i];
        REP(i, n) {
            FOR(j, i + 1, n) {
                if (a[i] + a[j] <= m) ans = max(ans, a[i] + a[j]);
            }
        }
        if (ans > 0)
            cout << ans << endl;
        else
            cout << "NONE" << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define MAXN 100010

struct node
{
	int x, t;
	node (int x1, int t1)
	{
		x = x1;t = t1;
	}
};
queue<node> que;
vector<int> vec[MAXN];
int n, m, x, y, ans;
int in[MAXN];

void topo_sort()
{
	for (int i = 1; i <= n; ++ i)
		if (! in[i])
			que.push(node(i, 0));
	while (! que.empty())
	{
		int x = que.front().x;
		int t = que.front().t;
		que.pop();
		ans = max(ans, t);
		for (int i = 0; i < vec[x].size(); ++ i)
		{
			int v = vec[x][i];
			if (-- in[v] == 0)
				que.push(node(v, t + 1));
		}
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++ i)
	{
		scanf("%d%d", &x, &y);
		vec[x].push_back(y);
		++ in[y];
	}
	topo_sort();
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll N , L;
  cin >> N >> L;
  
  vector<string> str;
  rep(i,N){
    string inp; cin >> inp;
    str.pb(inp);
  }
  sort(all(str));

  rep(i,N){
    cout << str[i] ;
  }

  cout << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        A[i] -= (i + 1);
    }
    sort(A, A + N);

    long long b = A[N/2];
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        long long tmp = A[i] - b;
        ans += max(-1 * tmp, tmp);
    }
    cout << ans << endl;
}

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

#define MAX_N (1<<17)

using namespace std;

long all[2 * MAX_N - 1], part[2 * MAX_N - 1];

void init(){
    for(int i = 0; i < 2 * MAX_N - 1; i++)
        all[i] = part[i] = 0;
}

void add(int a, int b, long x, int k = 0, int l = 0, int r = MAX_N){
    if(a <= l && r <= b){
        all[k] += x;
    }
    else if(l < b && a < r){
        part[k] += (min(b, r) - max(a, l)) * x;
        add(a, b, x, k * 2 + 1, l, (l + r) / 2);
        add(a, b, x, k * 2 + 2, (l + r) / 2, r);
    }
}

long sum(int a, int b, int k = 0, int l = 0, int r = MAX_N){
    if(b <= l || r <= a) return 0;
    else if(a <= l && r <= b) return all[k] * (r - l) + part[k];
    else{
        long res;
        res = (min(b, r) - max(a, l)) * all[k];
        res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
        res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
        return res;
    }
}

int main(){
    int n, q, s, a, b;
    cin >> n >> q;
    init();
    for(int i = 0; i < q; i++){
        cin >> s >> a >> b;
        if(s == 0){
            long x;
            cin >> x;
            add(a - 1, b, x, 0, 0, MAX_N);
        }else{
            cout << sum(a - 1, b, 0, 0, MAX_N) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 7204
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
typedef long long ll;
const int mx=2e5+125;
ll pr[mx],ar[mx],br[mx];
#define PB push_back
#define endl '\n'
#define S second
#define F first
int main()
{
    int a,b;
    set<int>s;
    cin>>a>>b;
    s.insert(a);
    s.insert(b);
    for(int i=1; i<=3; i++)
    {
        if(!s.count(i))
        {
            cout<<i<<endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main()
{
int a,b,d;
scanf("%d",&a);
char c[a];
  
  for(int j=0;j<a;j++)
         {
          scanf("%d",&c[j]);
          b=b+(c[j])*(c[j]);
          d=b;
          }
  
  for(int i=1;i<101;i++)
     {
      b=0;
         for(int j=0;j<a;j++)
         {
          scanf("%d",&c[j]);
          b=b+(c[j]-i)*(c[j]-i);
          }
      if(b<d) d=b;
      }
  printf("%d",d);
return 0;
}

Measured memory_bytes: 128
d=[]

for i in range(5):
    s=int(input())
    if s%10 == 0:
        d.append((s,s,s%10))
    else:
        d.append((s,s+(10-s%10),10-s%10))

d.sort(key=lambda d:d[2])
result=0
result=sum(d[i][1] for i in range(len(d)-1)) + d[-1][0]

print(result)



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}


int main(){
    double n,k;
    cin >> n >> k;
    
    int ans = ceil((n-1)/(k-1));
    cout << ans << endl;
}







Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def topological_sort(E, D):
    D = D[:]
    n = len(E)
    Q = [i for i in range(n) if D[i] == 0]
    L = []
    while Q:
        p = Q.pop()
        L.append(p)
        for vf in E[p]:
            D[vf] -= 1
            if not D[vf]:
                Q.append(vf)
    
    if len(L) != n:
        return False
    return L

def check(E, D, N):
    D = D[:]
    Q = [i for i in range(N**2) if D[i] == 0 and i//N < i%N]
    
    cnt = 0
    res = 0
    match = N*(N-1)//2
    while match > res:
        cnt += 1
        res += len(Q)
        Q2 = []
        for q in Q:
            for vf in Edge[q]:
                D[vf] -= 1
                if not D[vf]:
                    Q2.append(vf)
        Q = Q2[:]
    return cnt
        
N = int(readline())
AA = [list(map(lambda x:int(x)-1, readline().split())) for _ in range(N)]

Edge = [[] for _ in range(N**2)]
Dim = [0]*(N**2)
for i in range(N):
    for j in range(N-2):
        noden = min(i, AA[i][j]) * N + max(i, AA[i][j])
        nodef = min(i, AA[i][j+1]) * N + max(i, AA[i][j+1])
        Dim[nodef] += 1
        Edge[noden].append(nodef)
L = topological_sort(Edge, Dim)
if L == False:
    ans = -1
else:
    ans = check(Edge, Dim, N)
print(ans)


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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

using num = modnum<int(1e9) + 7>;

const int N = 2333333;
vector<num> fact(N);
vector<num> ifact(N);

num ncr(int n, int r) {
	if (n >= r && r >= 0) {
		return fact[n] * ifact[r] * ifact[n-r];
	} else {
		return 0;
	}
}

num go(int r, int c) {
	return ncr(r+c+2, r+1) - 1;
}

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

	fact[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = fact[i-1] * i;
	}
	ifact.back() = inv(fact.back());
	for (int i = N-1; i >= 1; i--) {
		ifact[i-1] = ifact[i] * i;
	}

	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	r1--; c1--;
	cout << go(r2, c2) + go(r1, c1) - go(r2, c1) - go(r1, c2);

	return 0;
}


Measured memory_bytes: 18432
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, a, b; cin >> n >> a >> b;
  vector<int> h(n); for(int & i : h) cin >> i;
  int lo = 0, hi = 1000000000, ans = 1000000000;
  while(lo <= hi){
    int mid = (lo+hi)>>1;
    long long need = 0;
    for(int i : h){
      long long cur = i - 1ll * mid * b;
      if(cur > 0) need += (cur + a - b - 1) / (a - b);
    }
    if(need <= mid) hi = mid - 1, ans = mid;
    else lo = mid + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main()
{
  long long int n,i,sum;
    scanf("%lld",&n);
  sum=0;
  for(i=1;i<=n;i++)
  {
      if(i%3!=0&&i%5!=0)
      {
          sum+=i;
      }
      
  }
  printf("%lld\n",sum);

}


Measured memory_bytes: 1704
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
int n,m;
int p;

int main()
{

  

  while(cin >> n >> m && n){

    pair<int,int> a[10000];

    for (int i = 0; i < n; ++i)
    {
      cin >> a[i].second >> a[i].first;
    }

    sort(a,a+n);
    reverse(a,a+n);
    
    for (int i = 0; i < n; ++i)
    {

      if(m >= a[i].second)m -= a[i].second;
      else if( m == 0 ) p += a[i].second * a[i].first;
      else{
        a[i].second -= m;
        m = 0; 
        p += a[i].second * a[i].first;
      }

    }

cout << p << endl;
p=0; //????????????????????????



}
  return 0;
}

Measured memory_bytes: 1240
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

bool solve() {

	string s;
	cin >> s;
	sort(s.begin(), s.end());
	
	if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return true;
}

signed main() {
	solve();

	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N; cin >> N;
	vll A(N); cin >> A;
	sort(begin(A), end(A));
	
	ll xd = 0;
	ll prev = 0;
	for (int i = 0; i < N; i++) {
		if ((A[i] - prev) % 2 == 1) xd ^= N-i;
		prev = A[i];
	}
	if (xd == 0) cout << "second" << endl;
	else cout << "first" << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3940
import java.util.Scanner;
import java.util.HashSet;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        scanner.nextLine();
        HashSet<String> result = new HashSet<>();
        for (int i = 0; i < num; i++) {
            String gacha = scanner.nextLine();
            result.add(gacha);
        }
        System.out.println(result.size());
    }
}

Measured memory_bytes: 79532
n = int(input())
s = list(input())

l = [0]
r = [0]
l_cnt = 0
r_cnt = 0
for i in range(n-1):
    if s[i] == 'W':
        l_cnt += 1
    if s[n-i-1] == 'E':
        r_cnt += 1
    l.append(l_cnt)
    r.append(r_cnt)
print(min(l[i]+r[n-i-1] for i in range(n)))


Measured memory_bytes: 20492
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define int long long int
#define all(x) (x).begin(), (x).end()
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'

void solve(){
	int n,m;
	cin>>n>>m;
	vector<vector<int>>adj(n);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;
		v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vector<bool>vis(n);
	function<void(int)>dfs=[&](int u){
		vis[u]=true;
		for(int v:adj[u]){
			if(!vis[v]){
				dfs(v);
			}
		}
	};
	int cnt=0;
	for(int i=0;i<n;i++){
		if(!vis[i]){
			dfs(i);
			cnt++;
		}
	}
	cout<<cnt-1<<endl;
}

int32_t main(){

	//remove for interactive problems
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	solve();
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

	return 0;
}

Measured memory_bytes: 10836
#include <algorithm>
#include <cstdio>
#define LL long long
#define maxn 600010
using namespace std;
struct node{
    int v,c;
}a[maxn];
int cmp(node a,node b){
    return a.v>b.v;
}
int main(){
    int X,Y,A,B,C,i,cnt;
    LL sum=0;
    scanf("%d%d%d%d%d",&X,&Y,&A,&B,&C);
    for(i=1;i<=A;i++)scanf("%d",&a[i].v),a[i].c=1;
    for(i=A+1;i<=A+B;i++)scanf("%d",&a[i].v),a[i].c=2;
    for(i=A+B+1;i<=A+B+C;i++)scanf("%d",&a[i].v),a[i].c=0;
    sort(a+1,a+1+A+B+C,cmp);
    cnt=0;
    for(i=1;i<=A+B+C;i++)
        if(a[i].c==1){
            if(X>0)X--,sum+=a[i].v;
            if(X+Y==cnt)break;
        }else if(a[i].c==2){
            if(Y>0)Y--,sum+=a[i].v;
            if(X+Y==cnt)break;
        }else if(a[i].c==0){
            cnt++;
            sum+=a[i].v;
            if(X+Y==cnt)break;
        }
    printf("%lld\n",sum);
    return 0;
}

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

struct edge{
    ll to;
    ll cost;
};

int main(){
    int n;
    cin>>n;
    vector<vector<edge>> G(n);
    for(int i=0;i<n-1;i++){
        int u,v,w;
        cin>>u>>v>>w;
        u--;v--;
        G[u].push_back((edge){v,w});
        G[v].push_back((edge){u,w});
    }
    vector<ll> d(n,-1);
    queue<int> que;
    que.push(0);
    d[0]=0;
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(auto p:G[v]){
            int nv=p.to;
            if(d[nv]!=-1) continue;
            d[nv]=d[v]+p.cost;
            que.push(nv);
        }
    }
    for(int i=0;i<n;i++){
        if(d[i]%2==0) cout<<1<<endl;
        else cout<<0<<endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i = 0; i < N; i++){
  cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  
  int sum = 0;
  for(int i = 0; i < N - 1; i++){
    if(v.at(i + 1) == v.at(i)){
      sum += 0;    
    }
    else{
      sum += 1;
    }
  }
  cout << sum + 1 << endl;
}


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

int main(void){
	long long int N,cnt[5] = {0,0,0,0,0};
  cin>>N;
	char s[11];
  long long int ans = 0;
  for(int i=0;i<N;i++){
	cin>>s;
    if(s[0] == 'M')cnt[0]++;
    if(s[0] == 'A')cnt[1]++;
    if(s[0] == 'R')cnt[2]++;
    if(s[0] == 'C')cnt[3]++;
    if(s[0] == 'H')cnt[4]++;
  }
  ans+=cnt[0]*cnt[1]*cnt[2];
  ans+=cnt[0]*cnt[1]*cnt[3];
  ans+=cnt[0]*cnt[1]*cnt[4];
  ans+=cnt[0]*cnt[2]*cnt[3];
  ans+=cnt[0]*cnt[2]*cnt[4];
  ans+=cnt[0]*cnt[3]*cnt[4];
  ans+=cnt[1]*cnt[2]*cnt[3];
  ans+=cnt[1]*cnt[2]*cnt[4];
  ans+=cnt[1]*cnt[3]*cnt[4];
  ans+=cnt[2]*cnt[3]*cnt[4];
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = []
for _ in range(n):
    s.append(input())

import collections

a = collections.Counter(s)
b = a.most_common()
c = len(b)

ans = [b[0][0]]
for i in range(c-1):
    if b[i][1] > b[i+1][1]:
        break
    else:
        ans.append(b[i+1][0])

ans.sort()

for i in ans:
    print(i)

Measured memory_bytes: 47796
#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;
  int a[n], dp[n] = { };
  rep(i,n)
    cin >> a[i];
  for (int i = 1; i < n; i++) {
    if (i == 1) {
      dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
    } else {
      dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]),
          dp[i - 2] + abs(a[i] - a[i - 2]));
    }
  }
  cout << dp[n - 1];
}

Measured memory_bytes: 1024
n,m,x=map(int,input().split())
ca = [list(map(int,input().split())) for i in range(n)]
ans=float('inf')
#2のn乗通り
for i in range(1,2**n):
    rikaido = [0]*m
    money=0
    for j in range(n):
        #組み合わせの処理
        if i>>j&1:
            money+=ca[j][0]
            for k in range(1,m+1):
                rikaido[k-1]+=ca[j][k]
        for l in range(m):
            #全て理解度がx以上の時にかかるコストの最小値を計算する。
            if all(rikaido[l] >= x for l in range(m)):
                ans=min(money,ans)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9208
import math

N = int(input())
a_list = list(map(int, input().split(' ')))
b_list = list(map(int, input().split(' ')))

cnt = sum(b_list) - sum(a_list)

cnt_tmp = 0
for i in range(N):
    if a_list[i] < b_list[i]:
        cnt_tmp += math.ceil((b_list[i] - a_list[i]) / 2)

if cnt_tmp > cnt:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

char s[600][600];
char t[1200][1200];
int sum[1200][1200];
int sum2[1200][1200];

signed main(){
	int h,w;scanf("%d%d",&h,&w);
	int H=2*(h+w),W=2*(h+w);
	map<int,vector<int>>mp;
	map<int,vector<int>>mp2;
	rep(i,H)rep(j,W)t[i][j]='.';
	rep(i,h){
		scanf("%s",s[i]);
		rep(j,w){
			if(s[i][j]=='#'){
				mp[i-j+h+w].push_back(i+j+h+w);
				mp2[i+j+h+w].push_back(i-j+h+w);
				t[i-j+h+w][i+j+h+w]='#';
			}
		}
	}
	rep(i,H)rep(j,W){
		if(j)sum[i][j]+=sum[i][j-1];
		if(t[i][j]=='#')sum[i][j]++;
	}
	rep(i,W)rep(j,H){
		if(j)sum2[j][i]+=sum2[j-1][i];
		if(t[j][i]=='#')sum2[j][i]++;
	}
	//~ rep(i,H)cout<<t[i]<<endl;
	//~ rep(i,H){
		//~ rep(j,W)cout<<sum[i][j];
		//~ cout<<endl;
	//~ }
	//~ cout<<endl;
	//~ rep(i,H){
		//~ rep(j,W)cout<<sum2[i][j];
		//~ cout<<endl;
	//~ }
	int ans=0;
	for(auto&p:mp){
		auto&v=p.second;
		sort(v.begin(),v.end());
		rep(i,v.size())for(int j=i+1;j<v.size();j++){
			int d=v[j]-v[i];
			ans+=sum[p.first-d][v[j]]-sum[p.first-d][v[i]-1];
			ans+=sum[p.first+d][v[j]]-sum[p.first+d][v[i]-1];
		}
	}
	for(auto&p:mp2){
		auto&v=p.second;
		sort(v.begin(),v.end());
		rep(i,v.size())for(int j=i+1;j<v.size();j++){
			int d=v[j]-v[i];
			ans+=sum2[v[j]-1][p.first-d]-sum2[v[i]][p.first-d];
			ans+=sum2[v[j]-1][p.first+d]-sum2[v[i]][p.first+d];
		}
	}
	cout<<ans<<endl;
}
/*
5 11
..#...#....
...........
#...#...#..
...........
..#...#....
*/

Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int func(int a) {
    int ret = 0;
    while (a != 0) {
        ret += a % 10;
        a /= 10;
    }
    return ret;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    FOR(i, 1, N + 1) {
        if (A <= func(i) && func(i) <= B) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256