akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#include "boost/multiprecision/cpp_int.hpp"
typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

//////////////////////////



int main(){fastio
    
    ll n,X;cin>>n>>X;
    LL a[n];rep(i,0,n-1)cin>>a[i];
    LL ans=(LL)1E18;
    LL sum[n+1];
           sum[n]=0;
    for(ll i=n-1;i>=0;i--)sum[i]=sum[i+1]+a[i];
    rep(k,1,n){
        LL s=(n+k)*X;
        ll pos=n;
        LL kei=5;
        s+=kei*(sum[max(0,pos-2*k)]-sum[pos]);
        pos-=2*k;
        while(pos>0){
            kei+=2;
            s+=kei*(sum[max(0,pos-k)]-sum[pos]);
            pos-=k;
        }
        //chmin(ans,s);
        if(ans>s){
            ans=s;
        }
        //cout<<k<<" "<<s<<endl;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < A.length; i++) {
            A[i] = sc.nextInt();
        }
        int l = 0;
        int r = (int)Math.pow(10, 9);
        while (r - l > 1) {
            int x = (l + r) / 2;
            long now = 0;
            for (int i = 0; i < A.length; i++) {
                now += (A[i] - 1) / x;
            }
            if (now <= K) {
                r = x;
            } else {
                l = x;
            }
        }
        System.out.println(r);
        sc.close();
    }
}

Measured memory_bytes: 59828
// AOJ 2282: Problem B
// 2017.11.10 bal4u@uu

#include <stdio.h>

int a[1002];

int main()
{
	int n, m, i, d, t, f;
	int min, ans;

	while (scanf("%d%d", &n, &m) && n > 0) {
		for (i = 1; i <= n; i++) scanf("%d", a+i);
		ans = 1, d = a[1], min = (m/d)*d, f = 0;
		for (i = 2; i <= n; i++) {
			t = (m/a[i])*a[i];
			if (t < min || (t == min && a[i] < d)) ans = i, d = a[i], min = t, f = 0;
			else if (t == min && a[i] == d) f = 1;
		}
		if (f) ans = n; 
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1812
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		sc.close();
		if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
			System.out.println(0);
		} else if (a >= b && a >= c) {
			System.out.println(b * c);
		} else if (b >= a && b >= c) {
			System.out.println(a * c);
		} else if (c >= a && c >= b) {
			System.out.println(a * b);
		}
	}
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  vector<pi> points(n);
  rep(i, n) {
    std::cin >> points[i].fi >> points[i].se;
    int l = points[i].fi - points[i].se, r = points[i].fi + points[i].se;
    points[i].se = l, points[i].fi = r;
  }
  sort(rng(points));
  int r = -inf, ans = 0;
  rep(i, n) if (r <= points[i].se) {
    r = points[i].fi;
    ans++;
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 1024
N,X = map(int,input().split())
if N == 1:
    print('Yes')
    print(1)
    exit()

if X == 1 or X == 2*N-1:
    print('No')
    exit()
print('Yes')

if N == X:
    ans = list(range(1,2*N))
elif N > X:
    k = N-X
    ans = list(range(2*N-k,2*N)) + list(range(1,2*N-k))
else:
    k = X-N
    ans = list(range(k+1,2*N)) + list(range(1,k+1))

print(*ans, sep='\n')

Measured memory_bytes: 15588
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    ll n, q; cin >> n >> q;
    string s; cin >> s;
    // 1文字目からi文字目までに出現するACの個数を数える
    ll cnt[110000];
    cnt[0] = 0;
    rep(i, 1, n){
        cnt[i] = cnt[i-1];
        if(s[i] == 'C' && s[i-1] == 'A') cnt[i]++;
    }
    // rep(i, 0, n) cout << cnt[i];
    // cout << endl;
    rep(i, 0, q){
        ll l, r; cin >> l >> r;
        l--; r--;
        cout << cnt[r] - cnt[l] << endl;
    }
}

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

    solve();
    return 0;
}

Measured memory_bytes: 1872
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long int ll;
const int N=1e5+5,MAX=1e9+2;
int n,a[3][N],dp[4][N];
int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[0][i]>>a[1][i]>>a[2][i];
    }
    dp[0][0]=a[0][0];
    dp[1][0]=a[1][0];
    dp[2][0]=a[2][0];
    for(int i=1;i<n;i++){
        dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[0][i];
        dp[1][i]=max(dp[0][i-1],dp[2][i-1])+a[1][i];
        dp[2][i]=max(dp[0][i-1],dp[1][i-1])+a[2][i];
    }
    cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<'\n';
    return 0;
}


Measured memory_bytes: 2560
// Problem : D - Semi Common Multiple
// Contest : AtCoder - AtCoder Beginner Contest 150
// URL : https://atcoder.jp/contests/abc150/tasks/abc150_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n,m;
    cin>>n>>m;
    vi a(n);
    int cnt;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2){
            cout<<0<<endl;
            return;
        }
        a[i] /= 2;
        int cur = 0, tmp = a[i];
        while(tmp%2 == 0) tmp /= 2, cur++;
        if(!i) cnt = cur;
        else if(cur != cnt){
            cout<<0<<endl;
            return;
        } 
    }
    int ans = a[0];
    for(int i=1;i<n;i++){
        ans = (ans*a[i])/__gcd(ans,a[i]);
        if(ans > m){
            cout<<0<<endl;
            return;
        }
    }
    int res = m/ans;
    res = (res+1)/2;
    cout<<res;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3968
#pragma GCC optimize("Ofast")
#include  "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define printclock  cerr <<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<" sec\n";
#define mp(a , b)   make_pair(a , b)
#define eb(a)       emplace_back(a)
#define SZ(n)       ((int)(n).size())
#define all(n)      (n).begin(), (n).end()
#define anal           '\n'
#define mod         1000000007
#define fst         first
#define sec         second
#define pr(n)       cerr << n  << " ";
#define pfor(a)       for(auto (w) : (a)) pr(w)
//const double PI = acos(-1.0);
typedef long long ll;
typedef unsigned long long ull;

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-


//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
int main(){
I_AM_SPEED;
#ifndef ONLINE_JUDGE  
        freopen("input.in", "r", stdin);
        freopen("output.in", "w", stdout);
#endif 
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
      
     ll n, d;
     cin >> n >> d;
     ll dist = d*d;
     int ans = 0;
     while(n--){
         ll x, y;
         cin >> x >> y;
         if(dist >= (x*x + y*y)) ans++;

     }
     cout << ans << anal;

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
//printclock; 
return  0 ;      
}        



      

Measured memory_bytes: 3652
n,q=map(int,input().split())
s=input()
t=[0]*(n)
for i in range(n-1):
  t[i+1]=t[i]+(1 if s[i:i+2]=='AC' else 0)
for j in range(q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])
  
    

    


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n); for(auto&&i:a)cin>>i;
	vector<pair<int,int>>v;
	int b=0,s=1;
	for(int i=1;i<n;++i){
		if(a.at(i)>a.at(b))s=i;
		if(b<s&&a.at(b)<a.at(s)){
			v.push_back({a.at(b),a.at(s)});
			b=i;
		}
		if(a.at(i)<a.at(b))b=i;
	}
	int64_t money=1000;
	for(auto&&i:v){
		int64_t stock=money/i.first;
		money-=1L*stock*i.first;
		money+=1L*stock*i.second;
	}
	cout<<money<<"\n"s;
}


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

using namespace std;

int MAX_N = 100;

int main()
{
    int N;
    int a[200005]={0};
    int tmp;

    cin >> N;

    for (int i = 2; i <= N; i++)
    {
        cin >> tmp;
        a[tmp] += 1;
    }
    
    for (int i = 1; i <= N; i++)
    {
        cout << a[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4408
from collections import deque

n, m = map(int, input().split())
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)

ans = [None] * n
ans[0] = -1
visited = set()
vs = deque([0])
while vs:
    v = vs.popleft()
    for other_side in e[v]:
        if other_side in visited:
            continue
        visited.add(other_side)
        vs.append(other_side)
        if ans[other_side] is None:
            ans[other_side] = v

print("Yes")
for i in ans[1:]:
    print(i+1)


Measured memory_bytes: 39904
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_R = 20;
const int MAX_C = 20;
const int MAX_M = 16;

const int dxs[] = {1, 0, -1, 0};
const int dys[] = {0, -1, 0, 1};

/* typedef */

enum { D_R, D_U, D_L, D_D };

struct Stat {
  int x, y, d, m;
  Stat() {}
  Stat(int _x, int _y, int _d, int _m): x(_x), y(_y), d(_d), m(_m) {}
  void print() { printf("(%d,%d)(%d):%d\n", x, y, d, m); }
};

/* global variables */

string prgs[MAX_R];
bool used[MAX_R][MAX_C][4][MAX_M];

/* subroutines */

/* main */

int main() {
  int r, c;
  cin >> r >> c;

  memset(used, false, sizeof(used));

  for (int y = 0; y < r; y++) cin >> prgs[y];

  queue<Stat> q;
  q.push(Stat(0, 0, D_R, 0));
  used[0][0][D_R][0] = true;

  bool ok = false;
  
  while (! q.empty()) {
    Stat u = q.front(); q.pop();
    char op = prgs[u.y][u.x];
    //cout << op; u.print();
    
    if (op == '@') {
      ok = true;
      break;
    }

    if (op == '?') {
      for (int di = 0; di < 4; di++) {
	int vx = (u.x + c + dxs[di]) % c;
	int vy = (u.y + r + dys[di]) % r;
	if (! used[vy][vx][di][u.m]) {
	  used[vy][vx][di][u.m] = true;
	  q.push(Stat(vx, vy, di, u.m));
	}
      }
    }
    else {
      switch (op) {
      case '<': u.d = D_L; break;
      case '>': u.d = D_R; break;
      case '^': u.d = D_U; break;
      case 'v': u.d = D_D; break;
      case '_': u.d = (u.m == 0) ? D_R : D_L; break;
      case '|': u.d = (u.m == 0) ? D_D : D_U; break;
      case '.': break;
      case '+': u.m = (u.m + 1) % MAX_M; break;
      case '-': u.m = (u.m + MAX_M - 1) % MAX_M; break;
      default: if (op >= '0' && op <= '9') u.m = op - '0';
      }

      u.x = (u.x + c + dxs[u.d]) % c;
      u.y = (u.y + r + dys[u.d]) % r;
      if (! used[u.y][u.x][u.d][u.m]) {
	used[u.y][u.x][u.d][u.m] = true;
	q.push(u);
      }
    }
  }

  cout << (ok ? "YES" : "NO") << endl;
  
  return 0;
}

Measured memory_bytes: 1276
n=int(input())
L=["a"]
for i in range(n-1):
    tmp=[]
    for j in range(len(L)):
        for k in range(len(set(L[j]))+1):
            tmp.append(L[j]+chr(ord("a")+k))
    L=tmp
for j in range(len(L)):
    print(L[j])

Measured memory_bytes: 12936
# coding:utf-8
h1, m1, h2, m2, k = map(int, input().split())

if k >= 60:
    k_h = k // 60
    k_m = k % 60
else:
    k_h = 0
    k_m = k

h3 = h2 - k_h
m3 = m2 - k_m

start = 60 * h1 + m1
end = 60 * h3 + m3

print(end - start)


Measured memory_bytes: 9176
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;

ll bit[200010];
//ll kai[3010];
ll Cnt[1000010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }



/*ll sum(ll i)
{
	//i += 1;
	ll t = 0;
	while (i > 0)
	{
		t += bit[i];
		i -= i & -i;
	}
	return t;
}

void add(ll i, ll x)
{
	//i += 1;
	while (i <= 200005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/



void test() {
	cout << "888888888888888888888888" << endl;
}

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

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

void makePrimeList(ll x) {
	ll X = x;
	for (ll j = 2; j * j <= x; j++) {
		ll cnt = 0;
		while (X % j == 0) {
			cnt++;
			X /= j;
		}
		if (cnt) {
			Cnt[j] = max(Cnt[j], cnt);
		}
	}
	if (X != 1) Cnt[X] = max(Cnt[X], 1LL);
}

ll N;
ll ans;

void solve() {
	ans = INF;
	cin >> N;
	for (ll i = 1; i * i <= N; i++) {
		if (N % i != 0) continue;
		ans = min(ans, N / i - 2 + i);
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define fail(s) assert(!s)
#define ULL unsigned long long
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
int n, W;
const int MAXN = 100000;
int dp[MAXN + 10];
int main()
{
	cin >> n >> W;
	memset(dp, INF, sizeof(dp));
    dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		int v, w;
		cin >> w >> v;
		for (int j = MAXN; j >= v; j--)dp[j] = min(dp[j], dp[j - v] + w); 
	}
	int ans = INF;
	for (int i = 0; i <= MAXN; i++)if (dp[i] <= W)ans = i;
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;

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

ll n, a, x[50] = {}, dp[51][51][2501] = {};

int main() {
  cin >> n >> a;
  rep(i, 0, n) cin >> x[i];
  dp[0][0][0] = 1;

  // rep(i, 0, n) rep(j, 0, i + 1) rep(k, 0, 2051) {
  //
  // }
  for(int i = 0;i < n;i++){
      for(int j = 0;j < n;j++){
          for(int k = 0;k <= 2500;k++){
              dp[i+1][j][k] += dp[i][j][k];
              if(k-x[i] >= 0)dp[i+1][j+1][k] += dp[i][j][k-x[i]];
          }
      }
  }
  ll ans = 0;
  for(int i = 1;i <= n && i*a <= 2500;i++){
      ans += dp[n][i][i*a];
  }
  cout << ans << endl;
}


Measured memory_bytes: 50048
N, M = map(int, input().split())

from collections import defaultdict

# union find
class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n
 
    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1

uf = UnionFind(N)

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a > b:
        c = b
        b = a
        a = c

    uf.union(a, b)

# member = defaultdict(int)
r = min(uf.table)
if r != -1:
    mm = abs(r)
    # ic = 0
    # for n in uf.table:
    #     if n == -1:
    #         ic += 1

    # if ic%mm != 0:
    #     mm += 1
else:
    mm = 1

print(mm)

Measured memory_bytes: 72312
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/
#include <bits/stdc++.h>
#define newline ("\n")
#define deb(x) cerr << (#x) << " = " << (x) << '\n'
#define FOR(x, n) for (int x = 0; x < n; x++)
#define PI (3.141592653589)

#define MOD 1000000007
using namespace std;

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

    // Highly sophisticated code starts here
    // preprocessing
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    s.insert(d);
    bool fail = false;
    if(s.find(1) == s.end())
    {
        fail = true;
    }
    if(s.find(9) == s.end())
    {
        fail = true;
    }
    if(s.find(7) == s.end())
    {
        fail = true;
    }
    if(s.find(4) == s.end())
    {
        fail = true;
    }
    if(fail)
    {
        cout << "NO";
    }
    else
    {
        cout << "YES";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

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

    map<string, int> m;

    long long count = 0;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if (m[s] >= 1)
        {
            count += m[s];
            m[s]++;
        }
        else
        {
            m[s]++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 11136
//40
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int bt[1000]={};
    bool in[1000]={};
    int lt=0;
    while(n--){
      cin.ignore(6);
      int h,m,d;
      char c;
      (cin>>h).ignore()>>m>>c>>d;
      int t=h*60+m;
      if(in[0]){
	for(int i=1;i<1000;i++){
	  if(in[i]){
	    bt[i]+=t-lt;
	  }
	}
      }
      lt=t;
      in[d]=c=='I';
    }
    cout<<*max_element(bt+1,bt+1000)<<endl;
  }
  return 0;
}
	

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c)              c.begin(), c.end()
#define CC(x) cout << (x) << endl
#define rep(i,n) for(int i=0;i<n;i++)
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define EPS 1e-9
typedef unsigned long long ull;
using namespace std;

int main()
{

    ll x,y;
    cin >> x;
    ll ans=0;
    ll n=1;
    while(x!=1)
    {
        x/=2;
        ans+=n;
        //cout << ans <<endl;
        n*=2;
    }
    cout <<n+ans <<endl;
}


Measured memory_bytes: 256
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())

diff1 = c21 - c11
diff2 = c31 - c21
if diff1 == (c22-c12) and diff2 == (c32-c22) and diff1 == (c23-c13) and diff2 == (c33-c23):
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int antenna[5];
  int distance;
  for(int i=0; i<5; ++i){
    cin >> antenna[i];
  }
  cin >> distance;
  sort(antenna, antenna+5);
  if ((antenna[4]-antenna[0]) > distance){
    cout << ":(";
    exit(0);
  }
  else{
    cout << "Yay!";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll NUM = pow(10,9) + 7;

int main(){
	ll N,K;
	cin >> N >> K;
	vector<int> A(N);
	for(int i(0);i<N;++i){
		cin >> A[i];
	}
	vector<int> left(N,0), right(N,0);
	for(int i(0);i<N;++i){
		if(i>=1){
			for(int j(0);j<i;++j){
				if(A[j] < A[i]) left[i]++;
			}
		}
		if(i<=N-2){
			for(int j(i+1);j<N;++j){
				if(A[j] < A[i]) right[i]++;
			}
		}
	}
	ll ans(0);
	ll sum1,sum2;
	sum1 = (K*(K-1)/2)%NUM;
	sum2 = (sum1 + K)%NUM;
	for(int i(0);i<N;++i){
		ans += ((sum1*left[i])%NUM + (sum2 * right[i])%NUM)%NUM;
		ans %= NUM;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
ShopList = [tuple(map(int, input().split())) for i in range(N)]
ShopList.sort()
Purchased = 0
Payment = 0

while Purchased < M:
    for shop in ShopList:
        if Purchased + shop[1] <= M:
            Payment += shop[0] * shop[1]
            Purchased += shop[1]
        elif Purchased + shop[1] > M:
            Payment += shop[0] * (M - Purchased)
            Purchased = M

print(Payment)

Measured memory_bytes: 16988
fn main() {
    let ha = read_vec::<usize>();
    let h = ha[0];
    let a = ha[1];

    if h % a == 0 {
        println!("{}", h / a);
    } else {
        println!("{}", h / a + 1)
    }
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    int N;
    cin >> N;
    vector<int> A(N);
    vvec<int> x(N),y(N);
    rep(i,N){
        cin >> A[i];
        x[i].resize(A[i]);
        y[i].resize(A[i]);
        rep(j,A[i]){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    // 人の正直者、真偽不明の不親切な人をbit全探索
    // 矛盾が生じなかったらchmax
    auto check = [&](ll flag) -> bool{
        bool res = true;
        vector<int> v(N,0); // 
        rep(i,N)if(bit(i)&flag)v[i] = 1;
        rep(i,N){
            if(v[i])rep(j,A[i]){
                if(v[x[i][j]] != y[i][j]){
                    res = false; // 矛盾
                }
            }
        }
        return res;
    };
    ll ans = 0;
    for(ll i = 0; i < bit(N); i++){
        ll cnt = __builtin_popcount(i);
        if(check(i))chmax(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{
    int a,b;
    do
    {
        scanf("%d %d",&a,&b);
        if (a==0 && b==0)
        {
            break;
        }
        int i,j;
        for (i=a;i>0;i--)
        {
            for(j=b;j>0;j--)
            {
                if (i==a||i==1||j==b||j==1)
                {
                    printf("#");
                }
                else
                {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }while (1);
    return 0;
}


Measured memory_bytes: 2052
n = input()
ma = map(int, input().split())
ls = []
for m in ma:
  ls.append(m)
ls.sort()
jdg = 0
Alice = 0
Bob = 0

for l in reversed(ls):
  if jdg == 0:
    Alice = Alice + l
  else:
    Bob = Bob + l
  jdg = 1 - jdg

print(Alice - Bob)

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

const int maxn = 2e5 + 10;
typedef long long int ll;
void solved(){
	string s;cin>>s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '?'){
			s[i] = 'D';
		}
	}
	cout<<s<<endl;
}
int main(){
	solved();
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main() {
  const long long mod = 1000000007;
  long long n;
  cin >> n;
  long long a = ((modpow(10, n, mod) + modpow(8, n, mod))%mod - ((modpow(9, n, mod)*2) % mod)) % 1000000007 ;
  if (a < 0) a += 1000000007;
  cout << a << endl;
}


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

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  cin >> n;
  
  vector<double> v(n);
  REP(i,n){
    cin >> v[i];
  }

  SORTV(v);

  double ans = (v[0] + v[1]) / 2;
  for(int i = 2; i < n; ++i){
    ans = (ans + v[i]) / 2;
  }

  cout << setprecision(15) <<  ans << endl;


  return 0;
}



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


void solve() {
  int N;
  scanf("%d", &N);
  int A[N];
  int B[N];
  int C[N];
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &B[i]);
  }
  for (size_t i = 0; i < N-1; i++) {
    scanf("%d", &C[i]);
  }
  int sum = 0;
  for (size_t i = 0; i < N; i++) {
    sum += B[i];
  }
  
  int tmp = -1;
  for (size_t i = 0; i < N; i++) {
    if (tmp == A[i]-1) {
      sum += C[tmp-1];
    }
    tmp = A[i];
  }

  cout << sum << "\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

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

	int ans = 0;

	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n-1);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n-1; i++) {
		cin >> c[i];
	}

	int pre = -10;
	for (int i = 0; i < n; i++) {
		int now = a[i]-1;
		ans += b[now];
		if (now == pre + 1) {
			ans += c[pre];
		}
		pre = now;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
C=list(map(int,input().split()))

import bisect

x=bisect.bisect_right(C,0)
#最初左に行く場合
if x>=K:
    ANS=-(C[x-K])
else:
    ANS=10**10


for i in range(1,min(x+1,K+1)):
    if x-i+K-1>=N:
        continue

    
    
    elif ANS>=C[x-i+K-1]-2*C[x-i]:
        ANS=C[x-i+K-1]-2*C[x-i]


#print(ANS)


CC=[None]*N
for i in range(N):
    CC[i]=-C[i]

CC.reverse()


x=bisect.bisect_right(CC,0)

if x>=K:
    if ANS>-(CC[x-K]):
        ANS=-(CC[x-K])



#print(ANS)

for i in range(1,min(x+1,K)):
    if x-i+K-1>=N:
        continue

    
    
    elif ANS>=CC[x-i+K-1]-2*CC[x-i]:
        ANS=CC[x-i+K-1]-2*CC[x-i]







    #print(x,i,CC[x-i+K-1],CC[x-i])

print(ANS)
    


Measured memory_bytes: 62576
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
  ll k,n;
  cin>>n>>k;
  ll wt[n],val[n];
  ll s=0;
  for(ll i=0;i<n;i++)
  {
    cin>>wt[i]>>val[i];
    s+=val[i];
  }
  ll dp[s+1];
  fill(dp,dp+s+1,1e12);
  for(ll i=0;i<n;i++)
  {
    for(ll j=s;j>=val[i];j--)
      dp[j]=min(dp[j],wt[i]+dp[j-val[i]]);
    for(ll j=0;j<=val[i];j++)
      dp[j]=min(dp[j],wt[i]);
  }
  ll ans=0;
  for(ll i=0;i<=s;i++)
  {
    if(dp[i]<=k)
    ans=i;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
const int MOD = 1000000007; // 10^9 + 7
const double PI = 3.14159265358979323846;
const int N = 100000; // 10^5
using namespace std;

int a[N+1];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int64_t sum = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        a[x]++;
        sum += x;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int b, c;
        cin >> b >> c;
        sum += (c-b)*a[b];
        a[c] += a[b];
        a[b] = 0;
        cout << sum << "\n";
    }
    return 0;
}

Measured memory_bytes: 4020
N = int(input())

d = dict()
d['AC'] = 0
d['WA'] = 0
d['TLE'] = 0
d['RE'] = 0

for _ in range(N):
    s = input()
    d[s] += 1

print('AC', 'x', d['AC'])
print('WA', 'x', d['WA'])
print('TLE', 'x', d['TLE'])
print('RE', 'x', d['RE'])


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

int main() {
    int n, m; cin >> n >> m;

    string s; cin >> s;
    
    vector<char> qColor(m, 0), qType(m, 0);

    for(int i = 0; i < m; i += 1) {
        cin >> qColor[i] >> qType[i];
    }
        
    auto get = [&] (int who) {
        for(int i = 0; i < m; i += 1) {
            if(qColor[i] == s[who]) {
                if(qType[i] == 'L') {
                    who--;
                    if(who < 0)
                        return -1;
                } else {
                    who++;
                    if(who >= n)
                        return 1;
                }
            } 
        }
        
        return 0;
    };

    int st = -1, dr = -1;

    for(int lf = 0, rt = n - 1; lf <= rt;) {
        int mid = (lf + rt) / 2;
        int value = get(mid);

        if(value == 0) {
            st = mid;
            rt = mid - 1;
        } else if(value == 1) {
            rt = mid - 1;
        } else {
            lf = mid + 1;
        }
    }

    if(st == -1) {
        cout << "0\n";
        return 0;
    }

    for(int lf = 0, rt = n - 1; lf <= rt;) {
        int mid = (lf + rt) / 2;
        int value = get(mid);

        if(value == 0) {
            dr = mid;
            lf = mid + 1;
        } else if(value == -1) {
            lf = mid + 1;
        } else {
            rt = mid - 1;
        }
    }
    
    cout << (dr - st + 1) << "\n";
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define MAXN  100005
#define endl "\n"
using namespace std;
ll n,a,b,c;
vector<int>v[3];
ll dp[MAXN][4];
ll rec(int i, int p){
    if(i==n)
        return 0;
    if(dp[i][p]!=-1)
        return dp[i][p];
    ll ans=0;
    for(int h=0;h<3;h++){
        if(h!=p){
            ans=max(ans,rec(i+1,h)+v[h][i]);
        }
    }
    //cout<<i<<" "<<p<<" "<<ans<<endl;
    return dp[i][p]=ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>a>>b>>c;
        v[0].pb(a);
        v[1].pb(b);
        v[2].pb(c);
    }
    memset(dp,-1,sizeof(dp));
    ll ans=max(rec(0,0),rec(0,1));
    cout<<ans;


    return 0;
}



Measured memory_bytes: 12652
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in(),K=in();
	vector<ll> A=vecin(N);
	
	int L=1<<N;
	ll minC=1LL<<60;
	REP(i,L){
		int V=i,index=0;
		vector<int> F(N,0);
		while(V){
			if(V&1){
				F[index]=1;
			}
			index++;
			V/=2;
		}
		ll C=0,OK=1,H=A[0];
		REP(j,N-1){
			if(OK>=K) break;
			if(A[j+1]<=H && F[j+1]){
				C += H+1LL-A[j+1];
				H++;
				OK++;
			}
			else if(A[j+1]>H){
				OK++;
				H = A[j+1];
			}
		}
		if(OK>=K){
			minC = min(minC,C);
		}
	}
	
	out(minC);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;

int main()
{ 
    LL D;
    cin>>D;
    LL c[26];
    LL mem[26];
    for(int i=0;i<26;i++){
        mem[i]=0;
    }
    for(int i=0;i<26;i++){
        cin>>c[i];
    }
    LL ans[D];
    for(int i=0;i<D;i++){
        LL rem=D-i;
        vector<P> v;
        for(int j=0;j<26;j++){
            LL x;
            cin>>x;
            P p;
            p.first=x+(i-mem[j]+1)*rem*c[j];
            p.second=j;
            v.push_back(p);
        }
        sort(v.begin(),v.end());
        P p=v.back();
        v.pop_back();
        P q=v.back();
        if(mem[q.second]<mem[p.second]-10){p=q;}
        ans[i]=p.second;
        mem[p.second]=i+1;


        /*for(int j=0;j<v.size();j++){
            cout<<v[j].first<<' '<<v[j].second<<endl;
        }
        cout<<endl;*/

    }

    for(int i=0;i<D;i++){
        cout<<ans[i]+1<<endl;
    }
    return 0;
}

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

const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[300000];
int main(){
	int n;cin>>n;
	rep(i,n)scanf("%d",&a[i]);
	priority_queue<ll>que;
	sort(a,a+n,greater<>());
	ll ans=a[0];
	que.push(a[1]);que.push(a[1]);
	for(int i=2;i<n;i++){
		ans+=que.top();que.pop();
		que.push(a[i]);que.push(a[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6192
#include <string>
#include <iostream>
#include <vector>

using namespace std;

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

int main() {
	int n, d;
	string s;
	cin >> n >> s >> d;
	vector<bool> f(n, false);
	if (d == 0) {
		cout << s << endl; return 0;
	}

	rep(i, n) {
		if (s[i] == '0') {
			s[i] = '1';
			f[i] = true;
			d--;
			if (d == 0) {
				cout << s << endl; return 0;
			}
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		if (f[i] == false && s[i] == '1') {
			s[i] = '0';
			f[i] = true;
			d--;
			if (d == 0) {
				cout << s << endl; return 0;
			}
		}
	}
	cout << s << endl; return 0;
}

Measured memory_bytes: 3200
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
ll a[200009];
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    cin>>n;
    x =0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        x = x^a[i];
    }
    for(i=0;i<n;i++)
    {
        y = x^a[i];
        cout<<y<<" ";
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 5180
import sys
from operator import itemgetter

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


class BinaryIndexedTree:
    # 1-indexed
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
    
    def add(self, _i, x):
        i = _i
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    def sum(self, _i):
        i = _i
        res = 0
        while i:
            res += self.data[i]
            i -= i & -i
        return res
    
    def bisect_left(self, _w):
        w = _w
        if w <= 0:
            return 0
        i = 0
        k = 1 << (self.n.bit_length() - 1)
        while 0 < k:
            if i + k <= self.n and self.data[i + k] < w:
                w -= self.data[i + k]
                i += k
            k = k >> 1
        return i + 1


def solve():
    MOD = 998244353
    N = int(rl())
    xy = [[0, 0] for _ in range(N)]
    for i in range(N):
        xy[i][0], xy[i][1] = map(int, rl().split())
    
    compress = sorted(xy, key=itemgetter(1))
    for i in range(N):
        compress[i][1] = i
    compress.sort(key=itemgetter(0), reverse=True)
    
    bit = BinaryIndexedTree(N)
    ups = [0] * N
    downs = [0] * N
    for i in range(N):
        com = compress[i][1] + 1
        downs[N - 1 - i] = bit.sum(com)
        ups[N - 1 - i] = i - downs[N - 1 - i]
        bit.add(com, 1)
    
    bit = BinaryIndexedTree(N)
    compress = compress[::-1]
    
    pow_of_2 = [1]
    for _ in range(N):
        pow_of_2.append(pow_of_2[-1] * 2 % MOD)
    
    ans = 0
    for i in range(N):
        com = compress[i][1] + 1
        d = bit.sum(com)
        u = i - d
        ans = (ans + (pow_of_2[d] - 1) * (pow_of_2[ups[i]] - 1) * pow_of_2[u + downs[i]]) % MOD
        ans = (ans + (pow_of_2[u] - 1) * (pow_of_2[downs[i]] - 1) * pow_of_2[d + ups[i]]) % MOD
        ans = (ans - (pow_of_2[d] - 1) * (pow_of_2[ups[i]] - 1) * (pow_of_2[downs[i]] - 1) * (pow_of_2[u] - 1)) % MOD
        ans = (ans + pow_of_2[N - 1]) % MOD
        bit.add(com, 1)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 102004
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main(){
	fast_io;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int ans =1, cp=1;
	while(a>0 && c>0){
		// trace3(cp,a,c)
		if(cp==1){
			
			c-=b;cp=2;
			if(c<=0)
			{ans=1;break;}
		}
		else{
			a-=d;cp=1;
			if(a<=0){
				trace(a)
				ans=2;
				break;
			}
		}
	}
	if(ans==1)cout<<"Yes";
	else cout<<"No";

	
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define ll long long int
#define lf long double

#define MOD 1000000007


ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}

ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}

int main(){
ios::sync_with_stdio(false);cin.tie(0);
ll a;
lf b;
cin>>a>>b;
lf mul=(lf)a*b;
ll res = floor(mul);
cout<<res;
}


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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int MOD = (int)1e9 + 7;
const int N = (int)1e5 + 5;

int n,k;
ll mins[N];

ll fastExp(ll base, int p) {
	ll ret = 1;
	while (p) {
		if (p & 1) {
			ret = (ret*base) % MOD;
		}
		base = (base * base) % MOD;
		p >>= 1;
	}
	return ret;
}

void process(int x, ll res) {
	int squared = (int)sqrt(x);
	for (int i = 1; i <= squared; i++) {
		if (x % i) continue;
		mins[i] = (mins[i]+res) % MOD;
		int divs = x/i;
		if (i != divs) mins[divs] = (mins[divs]+res) % MOD;
	}
}

int main() {
	scanf("%d %d", &n, &k);
	ll ans = 0;
	for (int i = k; i >= 1; i--) {
		// for (int j=1; j<=k; j++) printf("mins[%d] = %lld\n", j, mins[j]);
		ll res = (fastExp(k/i, n) - mins[i]) % MOD;
		// printf("i=%d, res=%lld\n", i, res);
		if (res < 0) res += MOD;
		process(i, res);
		ll add = (1ll*i*res) % MOD;
		ans = (ans + add) % MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

#define reg register
#define ge getchar()
#define Re read()
#define FI "a.in"
#define FO "a.out"
#define MAXN 1000

inline int read() {
	int x = 0, t = 0, ch;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = ge;
	return t ? -x : x;
}

int main() {
	int n, a, b, t, x = 0, y = 0, z = 0;
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++) {
		cin >> t;
		if(t <= a) x++;
		if(a < t && t <= b) y++;
		if(t > b) z++;
	}
	cout << min(min(x, y), z) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  ll ans = 0;
  if(n * 2 > m) {
    ans = m / 2;
  } else {
    ans = n;
    ans += (m - (n * 2)) / 4;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256