akhauriyash/Code-Regression huggingface dataset:
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion

signed main() {
    string s;cin >> s;
    rep(i, s.size()) {
        if(i&1) {
            if(!(s[i]=='L'||s[i]=='U'||s[i]=='D')) {
                printf("No\n");
                return 0;
            }
        }
        else {
            if(!(s[i]=='R'||s[i]=='U'||s[i]=='D')) {
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> X(m), A(m);
    rep(i, m) {
        cin >> X[i];
    }
    sort(ALL(X));
    rep(i, m - 1) {
        A[i] = X[i + 1] - X[i];
    }
    sort(ALL(A), greater<ll>());
    ll ans = 0;
    rep(i, m - 1) {
        if(i < n - 1) continue;
        else ans += A[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
import sys
X,N = map(int, input().split()) 
if N==0:
    print(X)
    sys.exit()

P = list(map(int, input().split()))
if N==1:
    if X!=P[0]:
        print(X)
        sys.exit()
    if X==P[0]:
        print(X-1)
        sys.exit()
PP=sorted(P, reverse=True)
sab=abs(X-P[0])
#print(PP[0])
for i in range(N):
    if PP.count(X-i)==0 :
        print(X-i)
        sys.exit()
    if PP.count(X+i)==0:
        
        print(X+i)
        sys.exit()

Measured memory_bytes: 9172
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=1;i<=n;i++){
        bool ok=1;
        for(int j=0;j+n-i<n;j++){
            if(t[j]!=s[j+n-i]) ok=0;
        }
        if(ok) chmax(cnt,i);
    }
    cout<<2*n-cnt<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算の際にオーバーフローに注意せよ！(適切にmodをとれ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
*/

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main() {
	int a = 0;
	int b = 0;
	int c = 0;
	int d = 0;
	int e = 0;
	cin >> a >> b >> c >> d >> e;
	if (a>=(c + e) && 0<=(c - e)) {
		if (b>=(d + e) && 0<=(d - e)) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }



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

  ll n, k;
  cin >> n >> k;
  vector<ll> p(n);
  rep(i, 0, n) cin >> p[i];
  sort(all(p));

  ll ans = 0;
  rep(i, 0, k) ans += p[i];

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <vector>
#define ll long long
#define pb push_back
#define f first
#define s second
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
const int N = 7;
char a[N][N];
int h, w, k, ans = 0;
set<int> rows, clmns;


void check(){
    //cout << "=========================" << endl;
    //cout << "rows" << endl;
    //for(auto e : rows)cout << e << ' ';
    //cout << endl << "columns" << endl;
    //for(auto e : clmns)cout << e << ' ';
    //cout << endl;
    int cnt = 0;
    for(int i = 0; i < h; i++){
        if(rows.count(i))continue;
        for(int j = 0; j < w; j++){
            if(clmns.count(j))continue;
            if(a[i][j] == '#')cnt++;
        }
    }
    if(cnt == k)ans++;
}


void brutec(int last){
    if(last >= w){
        check();
        return;
    }
    clmns.insert(last);
    brutec(last + 1);
    clmns.erase(last);
    brutec(last + 1);
}


void brute(int last){
    if(last >= h)
    {
        brutec(0);
        return;
    }
    rows.insert(last);
    brute(last + 1);
    rows.erase(last);
    brute(last + 1);
}


int main() {
    fast;
    cin >> h >> w >> k;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    brute(0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3660
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	static boolean[][] u = new boolean[16][16];
	static int a;
	static int b;
	static int[][] r = new int[16][16];

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new File("c:\\0515-input.txt"));
		while (true) {
			a = scan.nextInt();
			b = scan.nextInt();
			if (a == 0 && b == 0)
				break;
			a--;
			b--;

			for (int x = 0; x < 16; x++)
				for (int y = 0; y < 16; y++) {
					u[x][y] = false;
					r[x][y] = -1;
				}

			int n = scan.nextInt();
			for (int i = 0; i < n; i++) {
				u[scan.nextInt() - 1][scan.nextInt() - 1] = true;
			}

			System.out.println(run(0, 0));
		}

		scan.close();
		System.exit(0);
	}

	private static int run(int x, int y) {
		if (x > a || y > b)
			return 0;
		if (x == a && y == b)
			return 1;
		if (u[x][y])
			return 0;

		if (r[x][y] != -1)
			return r[x][y];

		int ret = run(x + 1, y) + run(x, y + 1);
		r[x][y] = ret;
		return ret;
	}

}

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

int main() {
    ll H, W; cin >> H >> W;
    if (H%3 == 0 || W%3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll a, b, c;
    ll ans = min(H, W);
    for (ll i = 1; i < H; i++) {
        a = i*W;
        b = (H-i)*(W/2);
        c = (H-i)*W - b;
        ans = min(ans, max({a, b, c}) - min({a, b, c}));
    }
    for (ll i = 1; i < W; i++) {
        a = i*H;
        b = (W-i)*(H/2);
        c = (W-i)*H - b;
        ans = min(ans, max({a, b, c}) - min({a, b, c}));
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(ll i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;


int main() {
	//23日目 
	ll a[3] = {}, b = 0, c = 0, n = 0;

	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << (a[2] * 10 + a[1]) + a[0] << endl;


	
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import random
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化
def choice_contest(c, data_day, last, day, contest):
    contest -= 1
    #print(last)
    last = [i + 1 for i in last]
    # 今回開催するコンテストのlastを0にする
    last[contest] = 0
    #print(len(last))
    #print(last)
    # 不満度の計算
    d_satis = sum([last[i] * c[i] for i in range(26)])
    # i日目にcontestを選んだ場合の
    return [int(data_day[contest]) - d_satis, last]

def main():
    d = int(input())
    c = list(map(int,input().split()))
    data = [input().split() for _ in range(d)]
    last = [0] * 26
    ans = 0

    hold_consets = [random.randrange(1, 26) for _ in range(d)]
    for i in range(d):
        s, last = choice_contest(c, data[i], last, i, contest = hold_consets[i])
        ans += s
    ans_hold_contest = hold_consets
    #print(ans)

    for _ in range(3):
        last_t = [0] * 26
        ans_t = 0
        hold_contest = [random.randrange(1, 26) for _ in range(d)]
        for i in range(d):
            s_t, last_t = choice_contest(c, data[i], last_t, i, contest = hold_contest[i])
            ans_t += s_t
        #print(ans_t)
        if ans < ans_t:
            ans = ans_t
            ans_hold_contest = hold_contest

   
    for i in range(d):
        print(ans_hold_contest[i])
    #print(ans)

    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 10616
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){
    
    int N;
    string S;
    cin >> N >> S;
    int x = 0, minx = 0, ssize = S.size();
    for(int i = 0; i < ssize; i++){
        if(S[i] == '(')x++;
        else x--;
        minx = min(minx, x);
    }
    for(int i = 0; i < -minx; i++){
        cout << "(";
    }
    cout << S;
    for(int i = 0; i < x - minx; i++){
        cout << ")";
    }
    cout << endl;

    return 0;
}

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

int main(){
    using namespace std;
    size_t n;
    cin >> n;
    vector<size_t> S(n);
    for(auto& i : S)cin >> i;
    size_t q;
    cin >> q;
    vector<size_t> T(q);
    for(auto& i : T)cin >> i;
    sort(T.begin(), T.end());
    vector<size_t> ans;
    set_intersection(S.begin(), S.end(), T.begin(), T.end(), back_inserter(ans));
    cout << ans.size() << endl;
}


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

int main() {

  string S,T;
  cin>>S;
  cin>>T;
  
  bool flag=false;
  for(int i=0;i<T.size();i++){
    char wk=S.back();
    S.pop_back();
    S.insert(S.begin(),1,wk);
    
    if(S==T)
      flag=true;
  }

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


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {a: usize, b: usize, c: usize, k: usize};

    let mut b = b;
    let mut c = c;
    let mut count = 0;

    while a >= b {
        b *= 2;
        count += 1;
    }

    while b >= c {
        c *= 2;
        count += 1;
    }

    // println!("{},{},{}", a, b, c);
    // println!("{}", count);
    if k >= count {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 2152
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

// -----------------------------------------------------------------------------------------------------

// -----------------------------------------------------------------------------------------------------

let main() =
    let n = read int
    let xs = reada int

    let calc a = xs |> Array.sumBy (fun x -> pown (x - a) 2)

    [ 1 .. 100 ]
    |> List.map calc
    |> List.min
    |> puts
    ()

// -----------------------------------------------------------------------------------------------------
main()
writer.Dispose()


Measured memory_bytes: 11348
class UnionFind:

    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {root: self.members(root) for root in self.roots()}

    def __str__(self):
        return '\n'.join(f'{root}: {self.members(root)}' for root in self.roots())


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

uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a - 1, b - 1)

print(max(uf.size(i) for i in range(N)))


Measured memory_bytes: 79164
#include<bits/stdc++.h>
using namespace std;
 long fun (int t,int n, vector<int> &w, vector<int>&val, vector<vector<long>>&dp)
{
    
    if(t==0 or n==0)
        return 0;
    if(dp[n][t]!=-1)
        return dp[n][t];
    long m=0;
    if(w[n]>t)
        m= fun(t,n-1,w,val,dp);
    else
       m=max(fun(t,n-1,w,val,dp), fun(t-w[n],n-1,w,val,dp)+val[n]);
   return dp[n][t]=m;



}

int main()
{
    #ifndef ONLINE_JUDGE 
    freopen ("input1.txt", "r", stdin); 
   freopen ("output1.txt", "w", stdout); 
    #endif
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n,t;
    cin>>n>>t;
    vector<int> val(n+1),w(n+1);
    for(int i=1;i<=n;i++)
        cin>>w[i]>>val[i];
    //int e=*min_element(w.begin(),w.end());
    vector<vector<long>>dp(n+1,vector<long>(t+1,-1));
    //for(int i=0;i<e;i++)
     //   dp[i]=0;
    cout<<fun(t,n,w,val,dp)<<"\n";
    return 0; 

} 

  
        
    

    

    

        

    

  
        
    

    

    

        

    

Measured memory_bytes: 82972
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head

int main(){
    int x,t;
    cin >> x >> t;
    cout << max(x-t,0);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main()
{
	int32_t N, K, Q;
	scanf("%d %d %d", &N, &K, &Q);

	vector<int32_t> cnt_ans(N, -Q);
	for (int32_t i = 0; i < Q; i++) {
		int32_t ans_index;
		scanf("%d", &ans_index);
		ans_index--;
		cnt_ans[ans_index]++;
	}
	for (int32_t i = 0; i < N; i++) {
		printf("%s\n", (K + cnt_ans[i] > 0) ? "Yes" : "No");
	}

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
	int n, x;
	while (true) {
	    int count = 0;
		cin >> n >> x;
		if (n == 0 && x == 0)
			break;
		for (int i = 1; i <= n - 2; i++) {
			for (int j = i + 1; j <= n - 1; j++) {
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x)
						count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
 
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
    int K, N, i, j, tmp;
    int A[200010];
    long int breakpoint = 0;

    scanf("%d %d", &N, &K);
  if(N<=K){printf("0");
          return 0;}
    for (int a = 0; a < N; a++)
    {
        scanf("%d", &A[a]);
    }
  
   qsort(A, N, sizeof(int), compare_int);
   
    for (int b = 0; b < N - K;b++){
        breakpoint += A[b];
    }
    printf("%Ld", breakpoint);

    return 0;
}


Measured memory_bytes: 1788
Q = int(input())

prime = [True] * 100001
prime[0] = False
prime[1] = False

for i in range(2, 50001):
  if not prime[i]:
    continue
  now = i
  while now+i <= 100000:
    now += i
    prime[now] = False
    
ans = [0] * (100001)
for i in range(1, 100001):
  if i%2 == 0:
    ans[i] = ans[i-1]
  else:
    if prime[i] and prime[(i+1)//2]:
      ans[i] = ans[i-1] + 1
    else:
      ans[i] = ans[i-1]
      
for i in range(Q):
  l, r = map(int, input().split())
  print(ans[r]-ans[l-1])


Measured memory_bytes: 4980
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<vector<int>> edge(n), redge(n);
    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge[min(a, b)].push_back(max(a, b));
        edge[max(a, b)].push_back(min(a, b));
    }
    for(auto&& i : edge){
        sort(begin(i), end(i));
    }
    vector<int> c(n);
    for(auto&& i : c){
        cin >> i;
    }
    sort(rbegin(c), rend(c));
    vector<int> cost(n);
    int p = 0;
    long long ans = 0;
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int now = q.front();
        q.pop();
        cost[now] = c[p];
        p++;
        for(auto&& i : edge[now]){
            if(cost[i]) continue;
            q.push(i);
        }
    }
    vector<int> cost2 = cost;
    q.push(0);
    while(!q.empty()){
        int now = q.front();
        cost2[now] = 0;
        q.pop();
        p++;
        for(auto&& i : edge[now]){
            if(!cost2[i]) continue;
            ans += cost2[i];
            q.push(i);
        }
    }  
    q.push(0);

    cout << ans << "\n";
    for(int i = 0; i < n - 1; i++){
        cout << cost[i] << " ";
    }
    cout << cost[n - 1] << "\n";
}

Measured memory_bytes: 1280
import itertools
n = int(input())
xy = [0 for _ in range(n)]
for i in range(n):
    ai = int(input())
    xy[i] = [list(map(int , input().split())) for _ in range(ai)]

#print(xy)
#print(xy[0])
#print(xy[0][0])
ans = 0
for i in itertools.product([0, 1], repeat=n):
    ok = True
    cnt = sum(i)
    for j in range(n):
        xyj = xy[j]
        if i[j] == 1:
            for xyk in xyj:
                if xyk[1] == 1:
                    if i[xyk[0]-1] == 0:
                        ok = False
                elif xyk[1] == 0:
                    if i[xyk[0]-1] == 1:
                        ok = False
    #print(ok, i)
    if ok:
        ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 44252
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;
int ans = 1;
const int mod = 1000 * 1000 * 1000 + 7;
void mult(int &a , int b)
{
	a = (a * (LL) b) % mod;
}

int main()
{
	int a , b;
	cin >> a >> b;
	if(abs(a - b) > 1)
	{
		cout << 0;
		return 0;
	}
	for(int i = 1; i <= a; i++)
	{
		mult(ans , i);
	}
	for(int i = 1; i <= b; i++)
	{
		mult(ans , i);
	}
	if(a == b)
		mult(ans , 2);
	cout << ans;
}


Measured memory_bytes: 256
import sys

n,m=map(int,input().split())

g=[-1]*n

for i in range(m):

  s,c=map(int,input().split())

  if g[s-1]!=-1 and g[s-1]!=c:
    print("-1")
    sys.exit()

  elif n>=2 and s==1 and c==0:
    print("-1")
    sys.exit()

  else:
    g[s-1]=c

ans=0
h=1

for i in range(n-1,-1,-1):

  if g[i]==-1:

    if n>=2 and i==0:
      g[i]=1

    else:
      g[i]=0


  ans+=int(g[i])*h
  h=h*10

#print(g)

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
const int MOD = 1e9 + 7;
int n, m;
int li[N], ri[N];
int C[N][N], f[N][N];
string st;
void ADD(int &t, int d) {t += d; if (t >= MOD) t -= MOD;}
int main()
{
    cin >> n >> m;
    cin >> st;
    for (int i = 0; i <= n; ++ i)
    {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < i; ++ j)
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
    }
    for (int i = 1; i <= m; ++ i)
    {
        cin >> li[i] >> ri[i];
        if (ri[i] < ri[i - 1]) i --, m --;
    }
    li[m + 1] = ri[m + 1] = n + 1;
    f[0][0] = 1;
    for (int i = 1; i <= m; ++ i)
    {
        int c = 0;
        for (int j = max(ri[i - 1] + 1, li[i]); j <= ri[i]; ++ j)
            if (st[j - 1] == '1') c ++;
        for (int j = 0; j <= max(ri[i - 1] - li[i] + 1, 0); ++ j)
            for (int k = 0; k <= min(j + c, min(li[i + 1] - 1, ri[i]) - li[i] + 1); ++ k)
                if (j + c - k <= max(ri[i] - li[i + 1] + 1, 0))
                    ADD(f[i][j + c - k], 1ll * f[i - 1][j] * C[min(li[i + 1] - 1, ri[i]) - li[i] + 1][k] % MOD);
    }
    cout << f[m][0] << endl;
}


Measured memory_bytes: 59392
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		/*人数　種類　　　　　　　　３人　２種類
		 * お菓子１を持ってるやつ　　2人
		 * すぬけ　　　　　　　　　　１　　３
		 * おかし２をもってるやつ　　１人
		 * すぬけ　　　　　　　　　　３
		 *
		 *       す１　す２　す３
		 * A[0]  A[1]  A[2]  A[3]
		 */

		int N = sc.nextInt();
		int K = sc.nextInt();
		//int d[] = new int[K];
		int A[] = new int[N+1];
		//int no_snack = 0;

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

			int d = sc.nextInt();

			for(int j = 0;j<d;j++) {
				int sunuke = sc.nextInt();
				A[sunuke] = 1;
			}
		}

		int no_snack = N;
		for(int i = 1;i<=N;i++) {
			if(A[i] == 1)
				no_snack--;
		}
		System.out.println(no_snack);

    }
}


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

/* define const */

/* finish defineing const */

int w, a, b;

int main()
{
    cin >> w >> a >> b;

    if (a + w < b)
    {
        cout << b - (a + w) << endl;
    }
    else if (b + w < a)
    {
        cout << a - (b + w) << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
# coding: utf-8
from itertools import product
import numpy as np

def main():
	h,w,k = map(int, input().split())
	c = np.array([[ 1 if j=='#' else 0 for j in input()] for i in range(h) ])
	ans = 0
	for row in product(range(2), repeat=h):
		for col in product(range(2), repeat=w):
			#print(row,col)
			e = np.array([[i*j for j in col] for i in row])
			if np.sum(c*e) == k:
				ans += 1
	print(ans)	

if __name__ == '__main__':
	main()


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string N;
  cin >> N;
  bool flag = false;
  for(int i = 0; i < 2; i++) {
    if(N[i] == '9') flag = true;
  }
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,w,d; cin >> h >> w >> d ;
  int N = h * w;
  vi x(N),y(N);
  rep(i,h) rep(j,w){
    int a; cin >> a ; a--;
    x[a] = i; y[a] = j;
  }
  vl dist(N),sdist(N);
  rep(i,N-d) dist[i] = abs(x[i+d]-x[i])+abs(y[i+d]-y[i]);
  sdist = dist;
  for(int i = N-1; i-d >= 0; i--){
    sdist[i-d] = sdist[i] + dist[i-d];
  } 
  dump(sdist);
  int Q; cin >> Q ;
  rep(i,Q){
    int l,r; cin >> l >> r ;
    cout << sdist[l-1]-sdist[r-1] << endl;
  }
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i =0; i < N; i++){
  cin >> a.at(i);
  }
  
  double answer;
  
  for (int i =0; i < N; i++){
    answer += (1.0 / a.at(i));
  }

  answer = 1.0 / answer;

  cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a, b;

int main() {
    int res = 0;
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        if (x < a || x >= b) res++;
    }
    cout << res << endl;
}


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

int main() {
    //
    int k;
    int n = 7;
    int cnt = 1;
    cin >> k;

    if (k == 1 || k == 7) {
        cout << 1;
        return 0;
    }

    for (long long i = 0; i < 100000000; i++) {
        if (n == 0) break;
        cnt++;
        n = (n * 10 + 7) % k;
    }

    if (n == 0)
        cout << cnt;
    else
        cout << -1;
    //
}


Measured memory_bytes: 3636
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 100004
#define INF 1e9+7

using namespace std;

ll n,m;
string s,t;
map < ll,char > fin;

ll gcd(ll a,ll b)
{
    if(b == 0)
        return a;

    return gcd(b,a%b);
}

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

    cin >> n >> m;

    cin >> s >> t;

    if(n  > m)
    {
        string tmp = s;
        s = t;
        t = tmp;

        swap(n,m);
    }

    if(m%n == 0)
    {
        ll k = m/n;

        bool found = true;

        rep(p,0,m)
        {
            if(t[k*p+1] != s[p])
            {
                found = false;
            }
        }

        if(!found)
        {
            cout << -1 << endl;
        }
        else
        {
            cout << m << endl;
        }
    }
    else
    {
        ll lcp = n*m/gcd(n,m);
        ll k1 = m/gcd(n,m);
        ll k2 = n/gcd(n,m);


        rep(i,0,n)
        {
            fin[k1*i+1] = s[i];
        }

        bool found = false;

        rep(i,0,m)
        {
            if(fin[k2*i+1] != NULL && fin[k2*i+1] != t[i])
            {
                found =  true;
            }
        }

        if(found)
        {
            cout << -1 << endl;
        }
        else
        {
            cout << lcp << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 10880
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [s,t] <- lines <$> getContents
  print $ minimum $ map (length . filter (==False)) $ checkMatch s t

checkMatch [] _ = []
checkMatch s@(x:xs) t = do
  if length s >= length t
    then do
      zipWith (==) s t : checkMatch xs t
    else []

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

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




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


  ll N ; cin >> N ;
  ll T; cin >> T;
  vector<ll> t;
  rep(i,N){
    ll inp; cin >> inp;
    t.pb(inp);
  }

  ll ans = 0;
  ll till = 0;
  
  rep(i,N){
    if(till < t[i]){
      ans += T;
      till = (t[i]+T);
    }
    else{
      ans += (T+t[i]-till);
      till = (t[i]+T);
    }
  }
  cout << ans << endl;

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


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

int main() {
    // input
    string s; cin >> s;
    // solve
    int n = s.length();
    vector<int> acc(n + 1);
    REP (i, n) acc[i + 1] = acc[i] + (s[i] - '0');
    int k = n;
    while (acc[n - k] - acc[k] != 0 and
           acc[n - k] - acc[k] != n - 2 * k) {
        -- k;
    }
    // output
    printf("%d\n", k);
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

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

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/

int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
       int n,x,t;
       cin>>n>>x>>t;
       int y=n/x;
       if(n%x==0)cout<<y*t<<endl;
       else cout<<(y+1)*t<<endl;
    }
}











Measured memory_bytes: 3648
import java.awt.geom.Point2D;
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJCGL_1().doIt();
	}

	class AOJCGL_1{
		void doIt(){
			Point2D p0 = new Point2D.Double(in.nextDouble(), in.nextDouble());
			Point2D p1 = new Point2D.Double(in.nextDouble(), in.nextDouble());
			int q = in.nextInt();
			for(int i=0;i<q;i++){
				Point2D result = getVerticalPoint(p0, p1, new Point2D.Double(in.nextDouble(),in.nextDouble()));
				System.out.printf("%.9f %.9f\n",result.getX(),result.getY());
			}
		}
		
		//p0-p1の直線があるときに直線p2から直線らしたときp0-p1上の垂直な点を求める。
		private Point2D getVerticalPoint(Point2D p0,Point2D p1,Point2D p2){
			double kyori = p0.distance(p1);
			double angle = angle(p0, p1, p2);
			double t = p0.distance(p2) * Math.cos(angle);
			Point2D result = new Point2D.Double(p0.getX()+(p1.getX()-p0.getX())*t/kyori,
					p0.getY()+(p1.getY()-p0.getY())*t/kyori);
			return result;
		}

		private double angle(Point2D p0, Point2D p1, Point2D p2){
			return Math.atan2(p2.getY()-p0.getY(),p2.getX()-p0.getX())-
					Math.atan2(p1.getY()-p0.getY(),p1.getX()-p0.getX());
		}

	}
}

Measured memory_bytes: 39124
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);

  rep(i,n){
    cin>>a[i];
  }
  ll x=0;
  while(k>0){
    ll k_tmp=k;
    ll k_o=0;
    while(k_tmp>0){
      k_tmp/=2;
      k_o++;
    }
    ll bi=0;
    rep(j,n){
      if( a[j] & bit(k_o-1) ){
        bi++;
      }
    }
    //cout << bi << endl;
    if(bi <= n/2){
      x+=bit(k_o-1);
      k-=bit(k_o-1);
    }
    else{
      k=bit(k_o-1)-1;
    }
  //  cout << x << endl;

    //cout << k << endl;
  }
  //cout << x << endl;
  ll ans=0;
  rep(i,n){
    ans += (a[i] ^ x);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	int H, W, A, B;
	cin >> H >> W >> A >> B;
	rep(i, H){
		rep(j, W){
			if((j < A && i < B) || (j >= A && i >= B)){
				cout << 0;
			}else{
				cout << 1;
			}
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1280
//#pragma warning(disable:4996)
//#include <Windows.h>
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;
template<class T>
using pqueue = priority_queue<T, vector<T>, function<bool(T, T)>>;

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

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

void input();
void solve();

void daminput();
void naive();

void outputinput();

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	input();
	//daminput();
	solve();
	//naive();
	//outputinput();
	return 0;
}

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

int N, Q;
VI T, U, V;

void input() {
	cin >> N >> Q;
	T.resize(Q);
	U.resize(Q);
	V.resize(Q);
	for (int n = 0; n < Q; n++) {
		cin >> T[n] >> U[n] >> V[n];
	}
}

void daminput() {
}

//unionFind
class unionFind {
private:
	int* p;   //親配列のポインタ
	int* rank;
	int N;   //要素数
	int* check;   //同値な要素の数
public:
	unionFind(int);   //コンストラクタ
	int parent(int);   //親要素を返す
	void unit(int, int);   //2要素をつなぐ
	int operator[](int);   //parentの省略形
	~unionFind();
	int size(int n);   //頂点nと同値な要素数を返す
};

unionFind::unionFind(int n) {
	N = n;
	p = new int[N];
	rank = new int[N];
	for (int i = 0; i < N; i++) {
		p[i] = i;
		rank[i] = 0;
	}
	check = new int[N];
	for (int n = 0; n < N; n++)check[n] = 1;
	return;
}

int unionFind::parent(int n) {
	if (n < 0 || n >= N)return -1;
	if (p[n] == n)return n;   //自分が一番上の親
	return p[n] = parent(p[n]);   //つなぎ直しと上にたどる操作
}

int unionFind::operator[](int n) {
	return parent(n);
}

void unionFind::unit(int x, int y) {
	x = parent(x), y = parent(y);
	if (x == y)return;   //根が同じだから何もせずに帰る
	int sum = check[x] + check[y];
	if (rank[x] < rank[y])p[x] = y;
	else {
		p[y] = x;
		if (rank[x] == rank[y])rank[x]++;
	}
	check[x] = sum;
	check[y] = sum;
	return;
}

unionFind::~unionFind() {
	delete(p);
	delete(rank);
	delete(check);
	return;
}

int unionFind::size(int n) {
	return check[parent(n)];
}

void solve() {
	unionFind UF(N);
	for (int n = 0; n < Q; n++) {
		if (T[n] == 0) {
			UF.unit(U[n], V[n]);
		}
		else {
			if (UF[U[n]] == UF[V[n]]) {
				cout << 1 << "\n";
			}
			else cout << 0 << "\n";
		}
	}
}

void naive() {
}

void outputinput() {
}

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

const int N=100010;
struct edge{int s,t,p,n;}e[4*N];
int n,tot=1,a[N],b[N],h[N],d[N],ans[N];

void link(int u,int v)
{
	e[++tot]=(edge){u,v,0,h[u]},h[u]=tot,d[u]++;
	e[++tot]=(edge){v,u,0,h[v]},h[v]=tot,d[v]++;
}

void dfs(int x)
{
	for (int i=h[x],y; y=e[i].t,h[x]=e[h[x]].n,i; i=h[x])
		if (!e[i].p)
			{
				e[i].p=e[i^1].p=1,dfs(y);
				if (i&2)  ans[a[x]==e[i].t?x:e[i].t]=(i&1?-1:1);
			}
}

void calc(int x)
{
	for (int i=h[x]; i; i=e[i].n)
		ans[x]-=ans[i],calc(i);
}

void work()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)  scanf("%d",&a[i]),a[i]=(a[i]==-1?n+1:a[i]);
	for (int i=1; i<=n; i++)  scanf("%d",&b[i]),b[i]=(b[i]==-1?n+1:b[i]);
	for (int i=1; i<=n; i++)  link(a[i],i),link(b[i],i);
	for (int i=1; i<=n; i++)  if (d[i]&1)  puts("IMPOSSIBLE"),exit(0);
	puts("POSSIBLE");
	dfs(1);
	for (int i=1; i<=n+1; i++)  h[i]=0;
	for (int i=1; i<=n; i++)  e[i]=(edge){a[i],i,0,h[a[i]]},h[a[i]]=i;
	calc(n+1);
	for (int i=1; i<=n; i++)  printf("%d ",ans[i]);
}

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


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

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

int comp(string& a, string& b) {
  if (a == b) return 0;

  int la = a.length(), lb = b.length();
  for(int i = 0; i < la && i < lb; ++i) {
    if (a[i] != b[i]) {
      return (a[i] > b[i]) ? 1 : -1; 
    }
  }
  
  return (la > lb) ? 1 : -1;
}

string s;
int K;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin >> s >> K;
  vector<string> v;

  int L = s.length();
  FOR(l,1,K+1) {
    REP(i,L-l+1) {
      string ss = s.substr(i,l);

      if (v.empty()) v.push_back(ss);
      else {
        int idx;
        for(idx = v.size() - 1; idx >= 0; --idx) {
          int res = comp(ss, v[idx]);
          if (res == 0) break; // ss == v[idx]
          else if (res == 1) { // ss > v[idx]
            v.insert(v.begin()+idx+1, ss);
            break;
          }
        }
        
        if (idx == -1) v.insert(v.begin(), ss);
        if (v.size() > K) v.pop_back();
      }
    }
  }

  cout << v[K-1] << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ARC067D
{
    class Program
    {
        static void Main(string[] args)
        {
            Solver sol = new Solver();
            sol.Solve();
#if DEBUG
            Console.ReadLine();
#endif
        }
    }
    class Solver
    {
        long N;
        long A;
        long B;
        long[] X;

        public void Solve()
        {
            long ans=0;
            for(int i=0;i< N-1; i++)
            {
                ans += Math.Min((X[i+1]-X[i])*A,B);
            }
            Console.WriteLine(ans);
        }

        public Solver()
        {
            long[] NAB = rla();
            N = NAB[0];
            A = NAB[1];
            B = NAB[2];
            X = rla();
        }

        static String rs() { return Console.ReadLine(); }
        static int ri() { return int.Parse(Console.ReadLine()); }
        static long rl() { return long.Parse(Console.ReadLine()); }
        static double rd() { return double.Parse(Console.ReadLine()); }
        static String[] rsa() { return Console.ReadLine().Split(' '); }
        static int[] ria() { return Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray(); }
        static long[] rla() { return Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray(); }
        static double[] rda() { return Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray(); }
    }
}


Measured memory_bytes: 20832
#include<iostream>
#include <string>

int main(){
    std::string s;
    std::cin>>s;
    if(s.size() == 2){
        if(s[0] == s[1])std::cout<<1 << " "<<2<<std::endl;
        else std::cout<<-1 <<" "<<-1<<std::endl;
    }else{
        for(int i=0;i<s.size()-2;++i){
            if(s[i] == s[i+1]){
                std::cout<<i+1<<" "<<i+2<<std::endl;
                return 0;
            }
        }
        for(int i=0;i<s.size()-3;++i){
            if(s[i] == s[i+2]){
                std::cout<<i+1<<" "<<i+3<<std::endl;
                return 0;
            }
        }
        std::cout<<-1<<" "<<-1<<std::endl;
    }
    return 0;
}

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

#define F first
#define S second

using namespace std;

/*long long int wop(long long int x, long long int y) {
    if(y===0)return 1;
    long long int ret=wop(x,y/2);
    ret=(ret*ret)%mod;
    if(y&1)ret*=x;
    return ret%mod;
}*/

/*long long int chos(long long int r, long long int n) {
    return fac[n]*rev[r]*rev[n-r]
}*/

const int N = 1e5+100;
pair<long long int, long long int> p[N];
map<long long int, long long int> mp;
vector<long long int> v;

bool cmp(pair<long long int, long long int> p1, pair<long long int, long long int> p2) {
    return p1.S<p2.S;
}

int main () {
    long long int n;
    cin >> n;
    for(int i = 0 ; i <n ; i++ ) {
        long long int x, b;
        cin >> x >> b;
        p[i].F=x-b;
        p[i].S=x+b;
        v.push_back(x-b);
        v.push_back(x+b);
    }
    int o=0;
    sort(v.begin(),v.end());
    for(int u: v) {
        mp[u]=o;
        o++;
    }
    for(int i = 0 ; i < n ; i++ ) {
        p[i].F=mp[p[i].F];
        p[i].S=mp[p[i].S];
    }
    sort(p,p+n,cmp);
    long long int ans = 0, mxr = 0;
    for(int i = 0 ; i < n ; i++ ) {
        if(i==0) {
            ans++;
            mxr=p[i].S;
        }
        else {
            if(p[i].F<mxr)continue;
            mxr=p[i].S;
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 15856