akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 200005

struct Info{
	Info(ll arg_row1,ll arg_col1,ll arg_row2,ll arg_col2){
		row1 = arg_row1;
		col1 = arg_col1;
		row2 = arg_row2;
		col2 = arg_col2;
	}
	bool operator<(const struct Info &arg) const{

		if(row1 != arg.row1){

			return row1 < arg.row1;
		}else{

			return col1 < arg.col1;
		}
	}

	ll row1,col1,row2,col2;
};

ll H,W,K;
ll dp[1005];
ll fact[SIZE];


ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}


ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll mod_fact(ll n,ll p,ll &e){
	e = 0;
	if(n == 0)return 1;

	int res = mod_fact(n/p,p,e);
	e += n/p;

	if(n/p%2 != 0)return res*(p-fact[n%p])%p;
	return res*fact[n%p]%p;
}


ll nCm(ll n,ll m,ll p){
   if(n < m) return 0;
   ll e1,e2,e3;
   ll a1 = mod_fact(n,p,e1),a2 = mod_fact(m,p,e2),a3 = mod_fact(n-m,p,e3);
   if(e1 > e2+e3)return 0;
   return a1 * mod_inverse(a2*a3%p,p)%p;
}

void func(){

	vector<Info> V;

	ll col1,row1,col2,row2;

	for(int loop = 0; loop < K; loop++){

		scanf("%lld %lld %lld %lld",&col1,&row1,&col2,&row2);

		V.push_back(Info(row1,col1,row2,col2));
	}

	sort(V.begin(),V.end());

	ll minus,A,B;

	for(int i = 0; i < V.size(); i++){

		dp[i] = nCm(V[i].row1+V[i].col1-2,V[i].row1-1,MOD);

		for(int k = 0; k <= i-1; k++){
			if(V[k].col1 > V[i].col1)continue;

			A = nCm((V[i].row1-V[k].row1+V[i].col1-V[k].col1),V[i].row1-V[k].row1,MOD);
			if(V[k].col2 > V[i].col1 || V[k].row2 > V[i].row1){

				B = 0;

			}else{

				B = nCm((V[i].row1-V[k].row2+V[i].col1-V[k].col2),V[i].row1-V[k].row2,MOD);
			}

			minus = (A-B+MOD)%MOD;
			minus *= dp[k];
			minus %= MOD;

			dp[i] = (dp[i]-minus+MOD)%MOD;
		}
	}

	ll ans = nCm(H+W-2,H-1,MOD);

	for(int i = 0; i < V.size(); i++){

		A = nCm(H-V[i].row1+W-V[i].col1,H-V[i].row1,MOD);
		B = nCm(H-V[i].row2+W-V[i].col2,H-V[i].row2,MOD);

		minus = (A-B+MOD)%MOD;
		minus *= dp[i];
		minus %= MOD;

		ans = (ans-minus+MOD)%MOD;
	}

	printf("%lld\n",ans);
}


int main(){

	fact[0] = 1;
	for(ll i = 1; i < SIZE; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}

	while(true){

		scanf("%lld %lld %lld",&W,&H,&K);
		if(H == 0 && W == 0 && K == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 4724
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void) {
	int a,b,k;
	cin >> a >> b >> k;
	vector<int> c;
	for(int i=0; i<k; i++){
		if(a+i<=b)c.push_back(a+i);
		if(a<=b-i)c.push_back(b-i);
	}
	sort(c.begin(),c.end());
	cout << c[0] << endl;
	for(int i=1; i<c.size(); i++){
		if(c[i]!=c[i-1])cout << c[i] << endl;
	}
	return 0;
}

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

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

int main(){
  int N, M;
  map<string, int> ans{};

  cin >> N;
  vector <string> blue(N);
  rep(i, N){
    cin >> blue.at(i);

    ans[blue.at(i)]++;
    //cout << blue.at(i) << ans[blue.at(i)] << endl;
  }
  //sort(blue.begin(), blue.end());
  
  cin >> M;
  vector <string> red(M);
  rep(i, M){
    cin >> red.at(i);
    ans[red.at(i)]--;
  }
  
  int max = 0;

  for (auto i=ans.begin(); i!=ans.end(); i++){
    if (max < i->second) max = i->second;
  }
  cout << max << endl;


}

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

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

int main()
{
	int n,a,b,ans;
	n=read(),a=read(),b=read();
	ans=a+b-n;
	if (ans<0) ans=0;
	printf("%d %d\n",min(a,b),ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    int[][] a = new int[H][W];
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) a[i][j] = scanner.nextInt();

    final StringBuilder sb = new StringBuilder();
    int size = 0;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (a[i][j] % 2 == 1 && j + 1 < W) {
          size++;
          sb.append(String.format("%d %d %d %d\n", i + 1, j + 1, i + 1, j + 2));
          a[i][j]--;
          a[i][j + 1]++;
        }
      }
    }
    for (int i = 0; i < H - 1; i++) {
      int j = W - 1;
      if (a[i][j] % 2 == 1) {
        size++;
        sb.append(String.format("%d %d %d %d\n", i + 1, j + 1, i + 2, j + 1));
        a[i][j]--;
        a[i + 1][j]++;
      }
    }

    System.out.println(size);
    System.out.print(sb.toString());
  }
}


Measured memory_bytes: 169984
def main():
    n, a, b, c = map(int, input().split())
    l = [int(input()) for _ in range(n)]

    print(solve(a, b, c, l))

def solve(a, b, c, l):
    m = float('inf')
    for x in range(1, 4 ** len(l)):
        m = min(m, eval_cost(x, a, b, c, l))
    return m

def eval_cost(x, a, b, c, l):
    cnt = [0, 0, 0]
    y = [0, 0, 0]

    for i in range(len(l)):
        n = (x >> (i * 2)) & 0x03
        if n < 3:
            cnt[n] += 1
            y[n] += l[i]

    if cnt.count(0) != 0:
        return float('inf')
    
    return (sum(cnt) - 3) * 10 + abs(y[0] - a) + abs(y[1] - b) + abs(y[2] - c)

main()


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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)



using namespace std;
typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

using namespace std;


int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }

    int a, b, c;
    cin >> a >> b >> c;


    cout << (a<=c && c<=b ? "Yes":"No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int cur = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;

    if (x == i) {
      cur++;
    } else {
      ans += (cur + 1) / 2;
      cur = 0;
    }
  }

  ans += (cur + 1) / 2;

  cout << ans << endl;
}


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

#define int long long
#define pii pair<int,int> 

int K;
int dist[100010];
bool inh[100010];

main()
{
	ios::sync_with_stdio(false);
	
	cin>>K;
	
	int ans=1000000010;
	
	memset(dist,-1,sizeof(dist));
	priority_queue<pii> H;
	dist[1]=1;
	H.push({-1,1});
	inh[1]=true;
	
	while(!H.empty())
	{
		int u=H.top().second; H.pop();
		if(!inh[u]) continue;
		inh[u]=false; // cout<<u<<endl;
		if(u%K==0) ans=min(ans,dist[u]);
		int v=u*10%K;
		if(dist[v]==-1 || dist[v]>dist[u])
		{
			dist[v]=dist[u];
			H.push({-dist[v],v});
			inh[v]=true;
		}
		v=(u+1)%K;
		if(dist[v]==-1 || dist[v]>dist[u]+1)
		{
			dist[v]=dist[u]+1;
			H.push({-dist[v],v});
			inh[v]=true;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}












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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> v;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int m;
    cin >> m;
    if (m == 2) {
      v.pop_back();
      continue;
    }
    int n;
    cin >> n;
    if (m == 1) {
      cout << v[n] << endl;
    } else {
      v.push_back(n);
    }
  }
  return 0;
}


Measured memory_bytes: 3884
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

const int BIT_MAX = 300010;

template <class T> class BIT{
	T x[BIT_MAX + 1];
	
public:
	
	BIT(){
		fill(x,x+BIT_MAX+1,0);
	}
	
	void add(int a , T b){
		for(; a <= BIT_MAX ; a += a & -a) x[a] += b;
	}
	
	T get(int a){
		T b = 0;
		for(; a > 0 ; a -= a & -a) b += x[a];
		return b;
	}
};

BIT<int> bit;
int N,M;
int ans[3333];

int main(){
	scanf("%d%d" , &N , &M);
	repp(i,0,N){
		int l,r,x,y,s,t;
		scanf("%d%d" , &l , &r);
		x = l;
		y = r;
		repp(j,2,351){
			int s = (l-1)/j + 1;
			int t = r/j;
			if(s>t) continue;
			if(x<=t){
				x = s;
			} else {
				bit.add(x,1);
				bit.add(y+1,-1);
				x = s;
				y = t;
			}
			if(x<351) break;
		}
		bit.add(x,1);
		bit.add(y+1,-1);
		repp(j,1,351){
			if(r-l+1>=j || l % j > r % j || l % j == 0) ++ans[j];
		}
	}
	int z = min(351,M+1);
	repp(i,1,z){
		printf("%d\n" , ans[i]);
	}
	repp(i,351,M+1){
		printf("%d\n" , bit.get(i));
	}
	return 0;
}


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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

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

const int N = (int) 1e6;
const int INF = (int) 1e9 + 7;

int cnt[N + 7];

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int n;
	sf("%d", &n);
	int a[n];
	for (int i = 0; i < n; ++i) {
		sf("%d", &a[i]);
		++cnt[a[i]];
	}

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (cnt[a[i]] > 1) continue;
		bool ok = true;
		for (int j = 2; j * j <= a[i]; ++j) {
			if (a[i] % j == 0) {
				if (cnt[j] > 0 || cnt[a[i] / j] > 0) {
					ok = false;
					break;
				}
			}
		}
		if (ok) ++ans;
	}
	if (cnt[1] == 1) ans = 1;
	if (cnt[1] > 1) ans = 0;
	printf("%d\n", ans);

	return 0;
}


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

int main(){
    int n ;
    cin >> n ;
    vector<int> a (n+1) ;
    vector<int> b (n) ;
    for (int i = 0; i < n+1; i++)
    {
        cin >> a.at(i) ;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b.at(i) ;
    }
    int64_t ans = 0 ;
    for (size_t i = 0; i < n; i++)
    {
        if (a.at(i) >= b.at(i))
        {
            ans += b.at(i) ;
        }else
        {
            ans += a.at(i) ;
            b.at(i) -= a.at(i) ;
            if (b.at(i) >= a.at (i+1))
            {
                ans += a.at(i+1) ;
                a.at(i+1) = 0 ;
            }else
            {
                ans += b.at(i) ;
                a.at(i+1) -= b.at(i) ;
            }
            
            
        }
        
        
    }
    cout << ans << endl ;
    
}

Measured memory_bytes: 1024
#include <stddef.h>
#include <stdio.h>
#include <inttypes.h>

#define MAX_PEOPLE 100000
#define NAME_LEN 12

char initial[MAX_PEOPLE];

uint64_t count_char(char* array, size_t size, char ch)
{
  uint64_t cnt = 0;
  for(size_t i = 0; i < size; i++) {
    if(array[i] == ch) {
      cnt++;
    }
  }
  return cnt;
}

int main()
{
  int num;
  char lf;
  scanf("%d%c", &num, &lf);
  for(int i = 0; i < num; i++) {
    char buf[NAME_LEN];
    fgets(buf, sizeof(buf), stdin);
    initial[i] = buf[0];
  }
  uint64_t a = count_char(initial, num, 'A');
  uint64_t c = count_char(initial, num, 'C');
  uint64_t h = count_char(initial, num, 'H');
  uint64_t m = count_char(initial, num, 'M');
  uint64_t r = count_char(initial, num, 'R');

  uint64_t result = 0;
  result += a * c * h;
  result += a * c * m;
  result += a * c * r;
  result += a * h * m;
  result += a * h * r;
  result += a * m * r;
  result += c * h * m;
  result += c * h * r;
  result += c * m * r;
  result += h * m * r;
  printf("%" PRIu64 "\n", result);
  return 0;
}


Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;

class in {
  int n;
public:
  in() {}
  in(int n_) : n(n_){};
  template <class T> operator T() { T ret; cin >> ret; return ret; }
  template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};

template <std::uint_fast64_t Mod> class modint {
  using u64 = std::uint_fast64_t;
  u64 a;
  friend ostream& operator<<(ostream& os, const modint<Mod>& m);
public:
  constexpr modint(const u64 x = 0) noexcept : a(x % Mod) {}
  constexpr u64 val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
  constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
  constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
  constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
  constexpr bool operator==(const modint rhs) const noexcept { return modint(*this).val() == rhs.val(); }
  modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; }
  modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; }
  modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Mod; return *this; }
  modint &operator/=(modint rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; }
};
template <std::uint_fast64_t Mod>
ostream& operator<<(ostream& os, const modint<Mod>& m){ return os << m.a; }
const ll mod=(ll)1e9+7;
using mint = modint<mod>;
ostream& operator<<(ostream& os, const mint& m){ return os << m.a; }
//}}}

const int kMaxBit = 64;
int bit0[kMaxBit];
int bit1[kMaxBit];

int main(){
  int N = in();
  vector<ll> A = in(N);

  mint ans = 0;
  rep(i, N){
    rep(b, kMaxBit){
      bit1[b] += ((A[i] >> b) & 1);
    }
  }
  rep(b, kMaxBit){
    bit0[b] = N - bit1[b];
  }

  rep(b, kMaxBit){
    ans += (1LL << b) % mod * bit0[b] % mod * bit1[b];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#ososou
n,k=map(int,input().split())
d=list(map(str,input().split()))
flg=True
while flg:
    sn=str(n)
    # print([sni not in d for sni in sn])
    if all([sni not in d for sni in sn]):
        flg=False
    n+=1
        
print(n-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,a,b;
    cin>>x>>a>>b;
    int m=x-a;
    if(m<0){m*=-1;}
    int n=x-b;
    if(n<0){n*=-1;}
    if(m<n){cout<<"A"<<endl;}
    else{cout<<"B"<<endl;}
    return 0;}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var p, q, r int
	fmt.Scan(&p, &q, &r)

	min := q + r
	if min > p+q {
		min = p + q
	}
	if min > p+r {
		min = p + r
	}
	fmt.Println(min)
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int h,w,i,j;
    char star,hash,save;

    while(1)
    {
        star='.';
        hash='#';
        scanf("%d %d",&h,&w);
        for(i=1; i<=h; i++)
        {
            for(j=1; j<=w; j++)
            {
                if(j%2==0)
                {
                    printf("%c",star);
                }
                else
                {
                    printf("%c",hash);
                }
            }
            printf("\n");
            save=star;
            star=hash;
            hash=save;
        }
        if(h==0 && w==0)
        {
            break;
        }
        printf("\n");
    }

}



Measured memory_bytes: 2036
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)
type City struct {
	Prefecture int64
	Year int64
	OriginalPos int64
}

func main()  {
	var N, M int64
	fmt.Scan(&N)
	fmt.Scan(&M)
	prefectures := make(map[int64]Cities, N)

	for i := 0; int64(i) < M; i++ {
		var prefecture, year int64
		fmt.Scan(&prefecture)
		fmt.Scan(&year)
		thisCity := City{Prefecture:prefecture, Year:year, OriginalPos:int64(i)}
		prefectures[prefecture] = append(prefectures[prefecture], thisCity)
	}

	result := make(map[int64]string)

	for _, p := range prefectures{
		sort.Sort(p)
	}
	for _, p := range prefectures{
		for i, r := range p {
			result[r.OriginalPos] = fmt.Sprintf("%06d%06d", r.Prefecture, i+1)
		}
	}
	for i := 0; int64(i) < M; i++ {
		fmt.Println(result[int64(i)])
	}
}

type Cities []City
func (cities Cities) Len() int {
	return len(cities)
}
func (cities Cities) Less(i, j int) bool {
	return cities[i].Year < cities[j].Year
}
func (cities Cities) Swap(i, j int)  {
	cities[i], cities[j] = cities[j], cities[i]
}


Measured memory_bytes: 23936
#include<iostream>
#include<utility>
#include<queue>
#include<vector>
using namespace std;
enum COLOR{BLACK, WHITE};

void dikstra(vector<vector<pair<int, int> > >& G, int s, vector<int>& d){
    vector<COLOR> color(G.size(), WHITE);
    priority_queue<pair<int, int> > Q;
    d[s] = 0;
    color[s] = BLACK;
    int u = s;
while (1) {
        for (int j = 0, s_j = G[u].size(); j < s_j; j++) {
            int v = G[u][j].first;
            int w = G[u][j].second;
            if (color[v] == BLACK) continue;
            if (d[v] > d[u] + w) {
                d[v] = d[u] + w;
                Q.push(make_pair(d[v] * -1, v));
            }
        }
        if (Q.empty()) break;
        u = Q.top().second;
        color[u] = BLACK;
        Q.pop();
    }
}

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int, int> > > G(n);
    for (int i = 0; i < n - 1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        G[s].push_back(make_pair(t, w));
        G[t].push_back(make_pair(s, w));
    }

    vector<int> distance(n, 1e9);
    dikstra(G, 0, distance);
    int y = 0;
    for (int i = 0; i < n; i++) {
        if (distance[y] < distance[i]) y = i;
    }
    vector<int> distance2(n, 1e9);
    dikstra(G, y, distance2);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (ans < distance2[i]) ans = distance2[i];
    }
    cout << ans << endl;

    // int max = 0;
    // for (int i = 0; i < n; i++) {
    // }
    // cout << max << endl;




    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < G[i].size(); j++) {
    //         cout << G[i][j].first << ":" << G[i][j].second << " ";
    //     }
    //     cout << endl;
    // }


    return 0;
}



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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
int main(int argc, char const *argv[])
{
	char str[NMAX];
	int len;
	scanf("%s",str+1);
	len = strlen(str+1);
	str[0] = 'D';
	str[len + 1] = 'P';
	for(register int i = 1;i <= len;i++)
		if(str[i] == '?')
		{
			if(str[i-1] == 'P')
				str[i] = 'D';
			else if(str[i+1] == 'D')
				str[i] = 'P';
			else
				str[i] = 'D';
		}
	str[len+1] = '\0';
	puts(str+1);
	return 0;
}

Measured memory_bytes: 3960
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

const int MAXN = 200000 + 100;
const int INF = 100000000;

int n;
int sx, sy, tx, ty;
pair<int, int> s[MAXN];
int f[MAXN], k = 0;

double calc_ans(int line, int qua, int hal)
{
	return 100.0 * line + (5.0 * M_PI - 20.0) * qua + (10.0 * M_PI - 20.0) * hal;
}

void solve()
{
	sort(s + 1, s + n + 1);
	for(int i = 1; i <= n; i++)
	{
		int v = s[i].second;
		if(!k || f[k] < v)
			f[++k] = v;
		else
		{
			int p = lower_bound(f + 1, f + k + 1, v) - f;
			f[p] = v;
		}
	}
	bool half = (k == min(tx - sx, ty - sy) + 1);
	double ans = calc_ans(tx - sx + ty - sy, k - half, half);
	cout << fixed << setprecision(15) << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> sx >> sy >> tx >> ty;
	if(sx > tx)
		swap(sx, tx), swap(sy, ty);

	bool rev = false;
	if(sy > ty)
		rev = true, sy = INF - sy, ty = INF - ty;

	int n0 = 0;
	cin >> n0;
	for(int i = 1; i <= n0; i++)
	{
		int x, y;
		cin >> x >> y;
		if(rev)
			y = INF - y;
		if(sx <= x && x <= tx && sy <= y && y <= ty)
			s[++n] = make_pair(x, y);
	}

	solve();

	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
 
int main(void){
  char str_s[128],str_p[128];
  int i,j,snum,pnum;
 
  scanf("%s",str_s);  scanf("%s",str_p);
  snum=strlen(str_s);  pnum=strlen(str_p);
  for(i=0;i<snum;i++){
    for(j=0;j<pnum;j++){
      if(i+j<=snum-1){
        if(str_s[i+j]!=str_p[j])  break;
      } else {
        if(str_s[i+j-snum]!=str_p[j])  break;
      }
    }
    if(j==pnum)  break;
  }
 
  if(i==snum)  printf("No\n");
  else printf("Yes\n");
 
  return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    rep(i, m) cin >> a[i];
    ll suma = accumulate(all(a), 0LL);
    if (suma > n) cout << -1 << endl;
    else cout << (n - suma) << endl;
    return 0;
}


Measured memory_bytes: 3700
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int h, w, n;
    cin >> h >> w >> n;

    int a = max(h, w);

    cout << (n + a - 1) / a << endl;

    return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define db double
#define zero(a) memset(a,0,sizeof(a))
#define inff(a,n) fill(a,a+n+1,inf)
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define write(x) printf("%d\n",x)


const ll inf = 1e9;

int n, m, cnt, ans, flag = 1, a[100001];
vector<int>v[100001];

void dfs(int u, int fa)
{
	for (auto i : v[u])
	{
		if (i == fa)continue;
		if (a[i] == -1)
		{
			a[i] = (a[u] ^ 1);
			dfs(i, u);
		}
		else
		{
			if (a[i] == a[u])flag = 0;
		}
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i<m; i++)
	{
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	memset(a, -1, sizeof(a));
	a[1] = 0;
	dfs(1, 0);
	if (flag)
	{
		for (int i = 1; i <= n; i++)if (a[i])cnt++;
		cout << 1ll * cnt*(n - cnt) - m;
	}
	else
	{
		cout << 1ll * n*(n - 1) / 2 - m;
	}
	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,tmp;
    cin>>a>>b>>c;
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    if(a>c){
        tmp=a;
        a=c;
        c=tmp;
    }
    if(b>c){
        tmp=b;
        b=c;
        c=tmp;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}



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

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

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

  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  int sum = 0;

  if (b - a <= k) {
    sum++;
  }
  if (c - a <= k) {
    sum++;
  }
  if (d - a <= k) {
    sum++;
  }
  if (e - a <= k) {
    sum++;
  }

  if (c - b <= k) {
    sum++;
  }
  if (d - b <= k) {
    sum++;
  }
  if (e - b <= k) {
    sum++;
  }

  if (d - c <= k) {
    sum++;
  }
  if (e - c <= k) {
    sum++;
  }

  if (e - d <= k) {
    sum++;
  }

  if (sum == 10) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<algorithm>
#include<numeric>
#include<string>
#include<map>

using namespace std;
using int_greater_PQ = priority_queue<int,vector<int>,greater<int>>;

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

    multimap<pair<string,int>,int> SP;//first:string second:int
    for (int i = 0; i < N; i++)
    {
        string S;
        int P;
        cin>>S>>P;
        SP.emplace(make_pair(S,(-P)),i+1);
    }

    for(const auto&sp:SP)
    {  
        cout<<sp.second<<endl;
    }
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define UB upper_bound
#define LB lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n+1),b(n+1);

  int tmp=1;
  REP(i,n){
    int a=tmp*2;
    int b=tmp+k;
    tmp=min(a,b);
  }
  cout<<tmp<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
)

type sugarWarter struct {
        sugar, warter int
}

var (
        a, b, c, d, e, f int
        ans              = sugarWarter{-1, 0}
        checked          = map[sugarWarter]struct{}{}
)

func main() {
        fmt.Scan(&a, &b, &c, &d, &e, &f)
        dfs(0, 100*a)
        dfs(0, 100*b)
        fmt.Printf("%d %d\n", ans.sugar+ans.warter, ans.sugar)
}

func dfs(sugar, warter int) {
        if sugar+warter > f || sugar*100 > warter*e {
                return
        }
        if _, c := checked[sugarWarter{sugar, warter}]; c {
                return
        }
        checked[sugarWarter{sugar, warter}] = struct{}{}
        if sugar*(ans.warter+ans.sugar) > ans.sugar*(sugar+warter) {
                ans = sugarWarter{sugar, warter}
        }
        dfs(sugar, warter+100*a)
        dfs(sugar, warter+100*b)
        dfs(sugar+c, warter)
        dfs(sugar+d, warter)
        return
}

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

int use_number[5];
int number[5];
int minv = (130 * 5);

int multipleOf10(int x)
{
    float unit = 10.0f;
    return ceil((float)x / unit) * unit;
}

void search(int n, int a[])
{
    if (n == 5) {
        int tmp = 0;
        for (int i = 0; i < 5; i++) {
            if (i != 4) {
                tmp += multipleOf10(a[number[i]]);
            } else {
                tmp += a[number[i]];
            }
        }
        minv = min(tmp, minv);
    } else {
        for (int i = 0; i < 5; i++) {
            if (use_number[i] == 0) {
                use_number[i] = 1;
                number[n] = i;
                search(n + 1, a);
                use_number[i] = 0;
            }
        }
    }
}

int main(int argc, const char * argv[]) {
    int a[5];
    
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    
    search(0, a);
    
    cout << minv << endl;
    
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, dead_code)]
use proconio::fastout;
use proconio::input;
use rand::Rng;

#[fastout]
fn main() {
    input! {
        D:usize,
        C:[i32;26],
        S:[[i32;26];D]
    }
    let start = std::time::Instant::now();
    let mut rng = rand::thread_rng();
    let mut T = vec![0; D];
    let mut Tmax = vec![0; D];
    //let mut cnt = 0;
    for i in 0..D {
        let mut saidai = 0;
        for j in 1..26 {
            if S[i][saidai] < S[i][j] {
                saidai = j;
            }
        }
        T[i] = saidai;
        Tmax[i] = saidai;
    }
    let mut ans = score(D, &C, &S, &T);
    loop {
        let r_day = rng.gen::<usize>() % D;
        let r_con = rng.gen::<usize>() % 26;
        T[r_day] = r_con;
        //cnt += 1;
        let x = score(D, &C, &S, &T);

        // 最大値を更新できたら値を更新するが、そうでなければ元に戻す。
        if ans < x {
            ans = x;
            Tmax[r_day] = T[r_day];
        } else {
            T[r_day] = Tmax[r_day];
        }
        let duration = start.elapsed();
        if duration > std::time::Duration::from_millis(1900) {
            break;
        }
    }
    for i in 0..D {
        println!("{}", Tmax[i] + 1);
    }
    //println!("cnt:{}, point:{}", cnt, ans);
}
fn score(D: usize, C: &Vec<i32>, S: &Vec<Vec<i32>>, T: &Vec<usize>) -> i32 {
    let mut last = vec![vec![0i32; 26]; D];
    for d in 0..D {
        let i = T[d];
        last[d][i] = d as i32 + 1;
        for e in d + 1..D {
            if T[e] != i {
                last[e][i] = d as i32 + 1;
            } else {
                break;
            }
        }
    }
    let mut x = 0;
    for d in 0..D {
        let i = T[d];
        x += S[d][i];
        //println!("ss{}", x);
        for j in 0..26 {
            x -= C[j] * (d as i32 + 1 - last[d][j]);
            //println!("C[{}]={} -> {}", j, C[j], x);
        }
    }
    x
}


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

const int NIL = -1, INF = 1e5;

bool ok(auto& d, auto& p, auto x) {
  int h = 0;
  for(auto i: d) if(x <= i) ++h;
  for(auto i: p) if(i != NIL) if(x <= i) --h;

  queue<int> q;
  for(int i = 0; i < p.size(); ++i) {
    if(p[i] == NIL) q.push(1);
    else            q.push(p[i] < x ? INF : 0);
  }
  while(q.size() != 1) {
    auto a = q.front(); q.pop();
    auto b = q.front(); q.pop();
    auto c = q.front(); q.pop();
    q.push(a + b + c - max({a, b, c}));
  }

  return q.front() <= h;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> D(N), P(M), p(N, NIL);
  for(int i = 0; i < N; ++i) {
    cin >> D[i];
    if(i < M) cin >> P[i];
    if(i < M) p[P[i] - 1] = D[i];
  }

  auto d = D;
  sort(begin(d), end(d));

  int l = 0, h = N;
  while(l != h - 1) {
    auto m = (l + h) / 2;
    if(ok(d, p, d[m])) l = m;
    else               h = m;
  }
  cout << d[l] << endl;
}

Measured memory_bytes: 4808
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if (n == 2) {
        cout << a[1] << " " << a[0] << endl;
        return 0;
    }

    int M = a[n - 1];
    a.pop_back();
    if (M & 1) {
        vector<int>::iterator it
            = lower_bound(a.begin(), a.end(), (M + 1) / 2);
        int m1 = *it;
        while (*it > (M - 1) / 2 && it != a.begin()) {
            it--;
        }
        int m2 = *it;
        if (m1 - (M + 1) / 2 <= (M - 1) / 2 - m2) {
            cout << M << " " << m1 << endl;
        } else {
            cout << M << " " << m2 << endl;
        }
    } else {
        vector<int>::iterator it
            = lower_bound(a.begin(),a.end(), M / 2);
        int m1 = *it;
        while (*it >  M / 2 && it != a.begin()) {
            it--;
        }
        int m2 = *it;
        if (m1 - M / 2 <= M /2 - m2) {
            cout << M << " " << m1 << endl;
        } else {
            cout << M << " " << m2 << endl;
        }
    }

    return 0;
}


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

using namespace std;

#define int long long
#define fi  first
#define se  second

typedef pair<int,int>   ii;

priority_queue<int> q;
vector<ii>  v;
int n, sum = 0;

signed main()  {
    ios_base::sync_with_stdio(false);   cin.tie(0);
    cin >> n;
    for(int i = 0 ; i < n ; ++i)    {
        int D, L;   cin >> D >> L;
        v.push_back(ii(D + L,L));
    }
    sort(v.begin(),v.end());
    for(int i = 0 ; i < n ; ++i)    {
        q.push(v[i].se);
        sum += v[i].se;
        if(sum > v[i].fi)   {
            sum -= q.top();
            q.pop();
        }
    }

    cout << q.size() << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int int64_t
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define F first
#define S second
#define T  third
#define vecsort(x) sort(x.begin(), x.end())
#define vecrsort(x) sort(x.rbegin(), x.rend())
#define massort(x, n) sort(x, x + n)
using namespace std;
int max(int32_t a, int b){
   return max((int)a, b);
}
int max(vector<int> x){
    return *max_element(x.begin(), x.end());
}

const int N = 2e5 + 228;
vector<int> g[N];
int cnt[N];
int ans[N];
bool used[N];

void dfs(int v, int cur){
    used[v] = true;
    cur += cnt[v];
    ans[v] = cur;
    for(int x: g[v]){
        if(!used[x]){
            dfs(x, cur);
        }
    }
}

int32_t main(){
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n-1; i ++){
        int a, b;
        cin >> a >> b;
        a --; b --;
        g[a].pb(b);
        g[b].pb(a);
    }
    for(int i = 0; i < q;  i++){
        int p, x; cin >>p >> x;
        cnt[p-1] += x;
    }
    dfs(0 , 0);
    for(int i = 0; i < n; i ++)
        cout << ans[i] << " ";
}




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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for (int i = 0; i <= min(a, x/500); i++) {
    for (int j = 0; j <= min(b, (x-i * 500)/100); j++) {
      if (x - i * 500 - j * 100 <= 50 * c) {ans++;}
    }
  }
  cout << ans << endl;
}
        

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii; 
int n;
int a,b,c,d;
string s;
bool st[200010]; 
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>a>>b>>c>>d>>s;
	a--;b--;c--;d--;
	for(int i=0;i<n;i++){
		if(s[i]=='#')st[i]=1;
	}
	bool no=0;
	for(int i=b;i<=d;i++){
		if(no==1 && st[i]==1){
			cout<<"No"<<endl;
			return 0;
		}
		if(st[i]==1)no=1;
		if(st[i]==0)no=0;
	}
	no=0;
	for(int i=a;i<=c;i++){
		if(no==1 && st[i]==1){
			cout<<"No"<<endl;
			return 0;
		}
		if(st[i]==1)no=1;
		if(st[i]==0)no=0;
	}
	if(c>d){
		bool ok=0;
		for(int i=b;i<=d;i++){
			if(!st[i-1] && !st[i+1] && !st[i]){
				ok=1;
			}
		}
		if(!ok)cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	else cout<<"Yes"<<endl;
    return 0; 
}

Measured memory_bytes: 772
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=200005;
int f[N],fa[N],v[N];
int cnt[N][2],n;
ll ans;
struct node{
	int x,v0,v1;
	bool operator <(const node &a)const{
		ll val0=1ll*v0*a.v1;
		ll val1=1ll*v1*a.v0;
		if (val0==val1)
			return x<a.x;
		return val0>val1;
	}
};
set<node> S;
int get(int x){
	return f[x]==x?x:f[x]=get(f[x]);
}
int main(){
	scanf("%d",&n);
	For(i,2,n) scanf("%d",&fa[i]);
	For(i,1,n) scanf("%d",&v[i]),f[i]=i;
	For(i,1,n) cnt[i][v[i]]=1;
	For(i,2,n) S.insert((node){i,cnt[i][0],cnt[i][1]});
	For(i,1,n-1){
		int x=get(S.begin()->x);
		int y=get(fa[x]);
		S.erase(S.begin());
		if (y!=1) S.erase((node){y,cnt[y][0],cnt[y][1]});
		ans+=1ll*cnt[y][1]*cnt[x][0];
		cnt[y][0]+=cnt[x][0];
		cnt[y][1]+=cnt[x][1];
		f[x]=y;
		if (y!=1) S.insert((node){y,cnt[y][0],cnt[y][1]});
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 16640
/**************************
  * Author : Leo101
  * Problem :
  * Tags :
**************************/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define gi get_int()
#define _FILE(s) freopen(#s".in", "r", stdin); freopen(#s".out", "w", stdout)
#define int long long
const int MAXN = 2e6;
int get_int()
{
	int x = 0, y = 1; char ch = getchar();
	while (!isdigit(ch) && ch != '-')
		ch = getchar();
	if (ch == '-') y = -1, ch = getchar();
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * y;
}

class Edge
{
public:
	int from, to, value;
} edges[MAXN];
bool operator< (const Edge& a, const Edge& b) 
{
	return a.value < b.value;
}
int eNum;

int f[MAXN], v[MAXN];
int find(int u)
{
	return f[u] == u ? u : f[u] = find(f[u]);
}

signed main()
{
	memset(v, 0x3f, sizeof(v));
	int n = gi, q = gi;
	while (q--) {
		int from = gi, to = gi, val = gi;
		edges[eNum++] = (Edge) {from, to, val};
		v[from] = std::min(v[from], val + 1);
		v[to] = std::min(v[to], val + 2);
	}
	for (int i = 0; i < n; i++) {
		v[(i + 1) % n] = std::min(v[(i + 1) % n], v[i] + 2);
	}
	for (int i = 0; i < n; i++) {
		v[(i + 1) % n] = std::min(v[(i + 1) % n], v[i] + 2);
	}
	for (int i = 0; i < n; i++) f[i] = i;
	for (int i = 0; i < n; i++)
		edges[eNum++] = (Edge) {i, (i + 1) % n, v[i]};
	std::sort(edges, edges + eNum);
	int answer = 0;
	for (int i = 0; i < eNum; i++) {
		int from = edges[i].from, to = edges[i].to, value = edges[i].value;
		if (find(from) == find(to)) continue;
		f[find(from)] = find(to);
		answer += value;
	}
	std::cout << answer;

	return 0;
}


Measured memory_bytes: 32000
#include <iostream>
#include<string>
#include<string.h>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<climits>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    int upper;
    int lower;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(i==0){
            lower=x;
            upper=y;
        }else{
            if(x>lower){
                lower=x;
            }
            if(y<upper){
                upper=y;
            }
        }
    }
    int ans = 0;
    for(int i=lower;i<=upper;i++){
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


int main(){
    ll n,x,m;cin >> n >> x >> m;
    if(n<=300000){
        ll ans=0;
        while(n--){
            ans+=x;
            x=x*x%m;
        }
        cout << ans <<endl;return 0;
    }
    vector<ll> memo(m+1,0);
    ll sum=0;
    ll loop=-1;
    ll now=0;
    rep(i,n){
        now++;
        if(memo[x]){
            loop=now-memo[x];
            break;
        }
        memo[x]=now;
        sum+=x;
        x=x*x%m;
    }
    //vl dp(loop);
    ll loopsum=0;
    rep(i,loop){
        loopsum+=x;
        x=x*x%m;
        //dp[0]=
    }
    now--;
    //cout << loop <<" " << loopsum << "  " << now <<" " << sum <<endl;
    sum+=(n-now)/loop*loopsum;
    ll need=(n-now)%loop;
    rep(i,need){
        sum+=x;
        x=x*x%m;
    }
    cout << sum <<endl;
}

Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int N, A;
vector<int> head, tail;

int main(void) {
  cin >> N;
  REP(i, 0, N) {
    cin >> A;
    head.push_back(A);
    swap(head, tail);
  }
  reverse(tail.begin(), tail.end());
  REP(i, 0, tail.size()) cout << tail[i] << " ";
  REP(i, 0, head.size()) cout << head[i] << " ";

  return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, i;
  cin >> N;
  string s[N];
  i = 0;
  while ( i < N ) {
    cin >> s[i];
    i++;
  }
  for ( int i = 0; i < N; i++ ) {
    if ( s[i] == "Y" ) {
      cout << "Four";
      break;
    }
    if ( i == N-1 ) {
      cout << "Three";
    }
  }
}

Measured memory_bytes: 256
#coding=UTF-8

#メモリ大富豪プレイ
mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])

a=[]
b=[]
for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    a.append(int(hyo[0])-1)
    b.append(int(hyo[1])-1)

# collect x s.t. exists (1,x)
myon_tbl=[False]*N
# and collct y s.t. exists (y,N)
meguru_tbl=[False]*N
for idx in range(0,M,1):
    if a[idx]==0:
        myon_tbl[b[idx]]=True

    if b[idx]==N-1:
        meguru_tbl[a[idx]]=True

ans=False
for idx in range(0,N,1):
    if myon_tbl[idx] and meguru_tbl[idx]:
        ans=True
        break

prefix='' if ans else 'IM'
print(prefix+'POSSIBLE')


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef vector<unsigned long long> vecull;

int main(void)
{
    int N;
    cin >> N;
    N %= 10;

    if (N == 3) cout << "bon" << endl;
    else if (N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
    else cout << "hon" << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define MAX 100
using namespace std;
int a[MAX + 1][MAX + 1];
int b[MAX + 1][MAX + 1];

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      long long c = 0;
      for (int k = 0; k < m; k++) {
        c += (long long)a[i][k] * b[k][j];
      }
      cout << c;
      if (j != l - 1) cout << " ";
      else cout << "\n";
    }
  }
}


Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 1000000000000;

int main(){
    ll A,B,C;
    cin >>A>>B>>C;
    if(A+B>=C){
        cout <<B+C<<endl;
    }
    else {
        cout <<A+2*B+1<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i;scanf("%lld",&n);
  ll a[n];
  for(i=0;i<n;i++) scanf("%lld",&a[i]);
  for(i=1;i<n;i++){
    if(a[i-1]>a[i]){
      printf("No\n");return 0;
    } else if(a[i-1]<a[i]) a[i]--;
  }
  printf("Yes\n");return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

ll vv[100005];

int main()
{
	int n;
	cin >> n;
	rep(i, n)
	{
		ll tmp;
		cin >> tmp;
		vv[tmp]++;
	}

	ll sum = 0;
	for (size_t i = 0; i < 100002; i++)
	{
		sum += vv[i] * i;
	}
	int q;
	cin >> q;
	rep(i, q)
	{
		ll b, c;
		cin >> b >> c;
		sum -= vv[b] * b;
		sum -= vv[c] * c;
		vv[c] += vv[b];
		vv[b] = 0;
		sum = sum + vv[c] * c;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 4368
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

int MOD = 998244353;

signed main(){

    ll n;
    cin >> n;

    double a = 0;
    rep(i,n){
        double x;
        cin >> x;
        a += 1/x;
    }
    printf("%0.9lf\n",1/a);

    

    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc138.contest.atcoder.jp/tasks/abc138_b

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

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

## Logic

for x in range(0,N+1):
    for y in range(0,N-x+1):
        z = N - x - y
        if 10000*x+5000*y+1000*z == Y:
            print(x,y,z)
            sys.exit()
print("-1 -1 -1")




Measured memory_bytes: 66280