akhauriyash/Code-Regression huggingface dataset:
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!

#include <bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;

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

const ll N_MAX = 2e5;
ll n, k;
vll a, next_dis, occurance;

void func() {
    cin >> n >> k;
    a.resize(n);
    next_dis.resize(n, -1);
    occurance.resize(N_MAX + 1, -1);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (ll i = n - 1; i >= 0; i--) {
        if (occurance[a[i]] != -1) {
            next_dis[i] = occurance[a[i]] - i + 1;
        }
        occurance[a[i]] = i;
    }
    for (ll i = n - 1; i >= 0; i--) {
        if (next_dis[i] == -1) {
            next_dis[i] = occurance[a[i]] - i;
            if (next_dis[i] <= 0) {
                next_dis[i] += n;
            }
            next_dis[i]++;
        }
    }
    ll i = 0, sum = 0;
    while (1) {
        sum += next_dis[i]; i += next_dis[i]; i %= n;
        if (i == 0) {
            break;
        }
    }
    ll elem = (n % sum) * (k % sum); elem %= sum;
    i = 0;
    while (elem > 0) {
        if (elem >= next_dis[i]) {
            elem -= next_dis[i];
            i += next_dis[i]; i %= n;
        } else {
            cout << a[i] << ' ';
            i++; i %= n;
            elem--;
        }
    }
    cout << endl;
}

int main() {
    fast_io; cout.precision(32);
    ll t = 1; // cin >> t;
    for (ll i = 1; i <= t; i++) {
        func();
    }
}


Measured memory_bytes: 6272
#include <stdio.h>

int main() {

  int b,c;
  int i,j,k;
  int a[5];
  int ave;
  int sum =0;

  for(i=0;i<5;i++) {
    scanf("%d" ,&a[i]);
    if(a[i] < 40) {
      a[i] = 40;
    }
    sum = sum + a[i];
  }

  ave = sum / 5;

  printf("%d\n",sum/5);

 return 0;

}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;

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

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

// 第一引数 == 第二引数 ? true : false
template<class T, class U>
bool check(T first, U second) {
    return (first == second);
}

// 約数列挙
vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


// 数字和
template<class T>
T digitSum(T num) {
    T dig;
    T sum = 0;
    while (num) {
        dig = num % 10;
        sum += dig;
        num /= 10;
    }
    return sum;
}

string background_black(string s) { return "\x1b[40m" + s; }
string background_red(string s) { return "\x1b[41m" + s + "\x1b[40m"; }
string background_green(string s) { return "\x1b[42m" + s + "\x1b[40m"; }
string background_yellow(string s) { return "\x1b[43m" + s + "\x1b[40m"; }
string background_bleu(string s) { return "\x1b[44m" + s + "\x1b[40m"; }
string background_white(string s) { return "\x1b[47m" + s + "\x1b[40m"; }

string black(string s) { return "\x1b[30m" + s + "\x1b[37m"; }
string red(string s) {return "\x1b[31m" + s + "\x1b[37m"; }
string green(string s) { return "\x1b[32m" + s + "\x1b[37m"; }
string yellow(string s) { return "\x1b[33m" + s + "\x1b[37m"; }
string blue(string s) { return "\x1b[34m" + s + "\x1b[37m"; }
string white(string s) { return "\x1b[37m" + s + "\x1b[37m"; }

const int ten = 10;
const int hundred = 100;
const int thousand = 1000;

typedef long long ll;
typedef unsigned long long ull;

string tolower(string s) {
  string c;
  for (int i = 0; i < s.size(); i++) {
    if ((s[i] >= 'A') && (s[i] <= 'Z')) {
        c.push_back((s[i] + 0x20));
    } else {
        c.push_back(s[i]);
    }
  }
  return c;
}
#include <cstdlib>
string solve() {
  string str = "";
// int->string: to_string, string->int: stoi
//=============================================================================


  string a;
  cin >> a;
  int n = 0, w = 0, s = 0, e = 0;

  for (int i = 0; i < a.size(); i++) {
    if (a[i] == 'N') {
      n++;
    } else if (a[i] == 'W') {
      w++;
    } else if (a[i] == 'S') {
      s++;
    } else if (a[i] == 'E') {
      e++;
    }
  }
  
  if (n >0 && s > 0 && w == e) {
    str += "Yes";
  } else {
    if (n == s && w>0 && e>0) {
      str += "Yes";
    } else {
      str += "No";
    }
  }


//=============================================================================
  return str;
}

int main() {	
  std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
  cout << solve() << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int countA = 0;
		int countB = 0;
		for (int i = 0; i < arr.length; i++) {
		    if (arr[i] == '0' ^ i % 2 == 0) {
		        countA++;
		    } else {
		        countB++;
		    }
		}
		System.out.println(Math.min(countA, countB));
	}
}


Measured memory_bytes: 27604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N,M,A;
    cin >> N >> M;
    ll total = 0;
    for(ll i = 0;i < M;i++){
        cin >> A;
        total += A;
    }
    if(total <= N){
        cout << N - total << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())

//変数
ll N, M;
vector<ll> P;
vector<ll> Y;
vector<pair<ll, pair<ll, ll>>> ID;
vector<ll> num;

bool sortfunc1(pair<ll, pair<ll, ll>>& x, pair<ll, pair<ll, ll>>& y) {
	if (x.second.first != y.second.first) {
		return x.second.first < y.second.first;
	}
	else {
		return x.second.second < y.second.second;
	}
}

bool sortfunc2(pair<ll, pair<ll, ll>>& x, pair<ll, pair<ll, ll>>& y) {
	return x.first < y.first;
}

//解法
void solve() {

	sort(ID.begin(), ID.end(), sortfunc1);

	int val = 1;
	rep(i, M) {
		if (i != 0 && ID[i - 1].second.first != ID[i].second.first) {
			val = 1;
		}
		num[ID[i].first] = val;
		val++;
	}

	sort(ID.begin(), ID.end(), sortfunc2);

	rep(i, M) {
		cout << setfill('0') << setw(6) << right << ID[i].second.first;
		cout << setfill('0') << setw(6) << right << num[i];
		cout << endl;
	}


	return;
}

int main() {
	//入力
	cin >> N >> M;
	ID.resize(M);
	num.resize(M);

	rep(i, M) {
		ID[i].first = i;
		cin >> ID[i].second.first >> ID[i].second.second;
	}

	solve();
	//cout << endl;
	return 0;
}

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



int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    
    s[k-1] = s[k-1] + 32;
    
    cout << s << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3564
#include <stdio.h>
#include <iostream>
using namespace std;

void insertionSort(int ary[], int num);
void outputArray(int ary[], int num);

int main(void)
{
	int n;
	cin >> n;
	
	int i = 0, a[100];
	while (cin >> a[i++]) {};
	
	insertionSort(a, n);
	
	return 0;
}

void insertionSort(int ary[], int num)
{
	outputArray(ary, num);
	
	int i;
	for (i = 1; i < num; i++) {
		int v = ary[i];
		int j = i - 1;
		while (j >= 0 && ary[j] > v) {
			ary[j+1] = ary[j];
			j--;
		}
		ary[j+1] = v;
		
		outputArray(ary, num);
	}
}

void outputArray(int ary[], int num)
{
	for(int i = 0; i < num - 1; i++){
		cout << ary[i] << " ";
	}
	cout << ary[num-1] << endl;
}

Measured memory_bytes: 3100
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(n)]
a1 = sorted(a, key = lambda x:x[0])
b1 = sorted(b, key = lambda x:x[0])

inum = []
for j in range(n):
    bench = []
    for i in range(n):
        if a1[i] not in inum:
            if a1[i][0]< b1[j][0] and a1[i][1]< b1[j][1]:
                bench.append(a1[i])
    if bench:
        inum.append(max(bench, key=lambda x:x[1]))
print(len(inum))


Measured memory_bytes: 3064
import java.util.Scanner;

 class Main{

  public static int selectionSort(int A[],int N){
    int i,j,temp,r=0,min;
    for(i=0;i<N-1;i++){
    	min=i;
    	for(j=i;j<N;j++){
    		if(A[j]<A[min])
    			 min=j;
    	}
      temp=A[i];
      A[i]=A[min];
      A[min]=temp;
      if(i!=min)
    	   r++;
    }
    return r;
}
   
public static void main(String[] args){
         
		 Scanner sc= new Scanner(System.in);
	         int N=sc.nextInt();
             int A[]=new int[100];
             
             int i,j;
             for(i=0;i<N;i++){
            	 A[i] = sc.nextInt();
             }
	       
        int loop = selectionSort(A,N);
        
        for(i=0;i<N;i++){
      	  if(i>0)
      	   System.out.print(" ");
         System.out.print(A[i]);
        }
        System.out.println();
        System.out.println(loop);
        sc.close();
}
}

Measured memory_bytes: 26180
N=int(input())
W=list(map(int,input().split()))
al=sum(W)
harf=al/2
c=0
S=0
compare=[]

while c<=N:
    S+=W[c]
    if S<harf:
        compare.append(S)
        c+=1
    elif S==harf:
        c=101
        break
    else:
        break
if c==101:
    print(0)
else:
    a=max(compare)
    compare.append(S)
    b=max(compare)
    A=al-2*a
    B=2*b-al
    print(min(A,B))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
ll INF = 1e12;

int main() {
  int N;
  ll K;
  cin >> N >> K;
  VI A(N);
  VI F(N);
  rep(i, N) { cin >> A.at(i); }
  rep(i, N) { cin >> F.at(i); }
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<ll>());
  ll low = -1;
  ll high = INF;
  ll mid = (low + high) / 2;
  bool pos;
  while (low + 1 < high) {
    ll usek = 0;
    pos = true;
    rep(i, N) {
      usek += max(0ll, A.at(i) - mid / F.at(i));
      if (usek > K) {
        pos = false;
        break;
      }
    }
    if (pos) {
      high = mid;
    } else {
      low = mid;
    }
    mid = (low + high) / 2;
  }
  cout << high << endl;
  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main() {

  int N;
  string S;

  cin>>N>>S;

  int x=0, ans=0;
  for(int i=0; i<N; i++){
    if(S[i] == 'I') x++;
    else x--;
    ans = max(ans, x);
  }

  cout<<ans<<endl;

  return 0;
}


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

using namespace std;

int n,q;
int par[1000001];
int rank[1000001];
bool flag[1000001];

void init(){
	for(int i=0;i<n;i++){
		par[i]=0;
		rank[i]=0;
	}
	memset(flag,false,sizeof(flag));
}

int find(int x){
	if(flag[x])return x;
	return find(par[x]);
}

int main(void){
	while(1){
		scanf("%d %d",&n,&q);
		if(n+q==0)break;
		init();
		for(int i=2;i<=n;i++){
			scanf("%d",&par[i]);
		}
		flag[1]=true;
		long long res=0;
		for(int i=0;i<q;i++){
			char s;
			int v;
			cin >> s >> v;
			if(s=='M'){
				flag[v]=true;
			}
			if(s=='Q'){
				res+=find(v);
			}
		}
		printf("%lld\n",res);

	}
	return 0;
}

Measured memory_bytes: 4656
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template <typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}
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 (a > b) { a = b; return 1;}
    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin >> A >> B;
    if(A >= 10 || B >= 10){
        cout << -1 << endl;
    }else{
        cout << A * B << endl;
    }
    return 0;
}

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


using ll = long long int;

using namespace std;




int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int i, j, n;
    
    cin >> n;
    
    string s, t;
    
    cin >> s >> t;
    
    
    string ans(2 * n, 'a');
    
    for(i = 0; i < n; ++i)
    {
        ans[2 * i] = s[i];
        ans[2 * i + 1] = t[i];
    }
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    String A=gs();
	    String B=gs();

	    
        //System.out.println((H-h)*(W-w));
        if (A.length()>B.length()) {
        	System.out.print("GREATER");
        }else if(A.length()<B.length()){
        	System.out.print("LESS");
        }else {
        	for (int i=0; i<A.length();i++) {
        		int a=Integer.parseInt(String.valueOf(A.charAt(i)));
        		int b=Integer.parseInt(String.valueOf(B.charAt(i)));
        		if (a>b) {
        			System.out.print("GREATER");
        			return;
        		}else if(a<b) {
        			System.out.print("LESS");
        			return;
        		}
        	}
        	System.out.print("EQUAL");
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35608
#include <stdio.h>
int main(void)
{
    int i,j,limit=1000000,count;
    int prime[1000000];
    for(i=0;i<limit;i++){
        prime[i]=i;
    }
    for(i=2;i*i<limit;i++){
    if(prime[i]){
        for(j=i*2;j<limit;j+=i){
        prime[j]=0;
    }}}
    int n;
    while(scanf("%d",&n)!=EOF){
        count=0;
        for(i=2;i<=n;i++){
            if(prime[i]!=0){
                count++;
            }}
    printf("%d\n", count);
    }
    return 0;
}


Measured memory_bytes: 5608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}


ll dp[101][1<<17];
ll val[1<<17];
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,M;
    while(cin >> N >> M,N){
        fill(*dp,*dp+101*(1<<17),LLONG_MAX);
        fill(val,val+(1<<17),0);
        
        vector<int> s(N),d(M);
        for(auto& in:s) cin >> in;
        for(auto& in:d) cin >> in;
        
        sort(s.begin(),s.end());
        sort(d.begin(),d.end());
        
        for(int i = 0; i < (1<<N);i++){
            ll v = 0;
            for(int j = 0; j < N;j++){
                if((i>>j)&1){
                    v += s[j];
                }
            }
            val[i] = v;
        }
        
        dp[0][0] = 0;
        for(int i = 0; i < M;i++){
            for(int j = 0; j < (1<<N);j++){
                if(dp[i][j] == LLONG_MAX) continue;
                
                dp[i+1][j] = min(dp[i+1][j],dp[i][j] + abs(val[j]-d[i]));
                
                for(int k = 0; k < N;k++){
                    if((j>>k)&1) continue;
                    dp[i+1][j|(1<<k)] = min(dp[i+1][j|(1<<k)],dp[i][j]+abs(val[j]-d[i]));
                    
                    dp[i][j|(1<<k)] = min(dp[i][j|(1<<k)],dp[i][j]);
                }
            }
        }
        cout << *min_element(dp[M], dp[M]+(1<<17)) << endl;
    }
    return 0;
}



Measured memory_bytes: 107588
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N =int(input())

div = make_divisors(N)
L = len(div)

if L % 2 == 0:
    if div[L//2] - div[L//2-1] == 1:
        print(sum(div[L//2+1:])-L//2+1)
    else:
        print(sum(div[L//2:])-L//2)
else:
    print(sum(div[L//2+1:])-L//2)


Measured memory_bytes: 3296
#include <iostream>

using namespace std;

#define A 0
#define B 1
#define C 2

#define FALSE   0
#define TRUE    1
#define UNCLEAR 2

#define ABC_MAX 101

int work[3][ABC_MAX];

void init() {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < ABC_MAX; j++) {
            work[i][j] = UNCLEAR;
        }
    }
}

int main() {
    int a, b, c;
    while (cin >> a >> b >> c) {
        if (! (a || b || c) ) break;
        init();
        int N;       cin >> N;
        int is[N], js[N], ks[N], rs[N];
        for (int p = 0; p < N; p++) {
            int i, j, k, r;
            cin >> i >> j >> k >> r;
            is[p] = i; js[p] = j - a; ks[p] = k - a - b; rs[p] = r;
        }
        for (int p = 0; p < N; p++) {
            int i, j, k, r;
            i = is[p], j = js[p], k = ks[p], r = rs[p];
            if (r) {
                work[A][i] = TRUE;
                work[B][j] = TRUE;
                work[C][k] = TRUE;
            } else {
                if (work[A][i] == TRUE && work[B][j] == TRUE) work[C][k] = FALSE;
                if (work[B][j] == TRUE && work[C][k] == TRUE) work[A][i] = FALSE;
                if (work[C][k] == TRUE && work[A][i] == TRUE) work[B][j] = FALSE;
            }
        }
        for (int p = 0; p < N; p++) {
            int i, j, k, r;
            i = is[p], j = js[p], k = ks[p], r = rs[p];
            if (r) {
                work[A][i] = TRUE;
                work[B][j] = TRUE;
                work[C][k] = TRUE;
            } else {
                if (work[A][i] == TRUE && work[B][j] == TRUE) work[C][k] = FALSE;
                if (work[B][j] == TRUE && work[C][k] == TRUE) work[A][i] = FALSE;
                if (work[C][k] == TRUE && work[A][i] == TRUE) work[B][j] = FALSE;
            }
        }


        for (int p = 1; p <= a; p++) {
            cout << work[A][p] << endl;
        }
        for (int p = 1; p <= b; p++) {
            cout << work[B][p] << endl;
        }
        for (int p = 1; p <= c; p++) {
            cout << work[C][p] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=5000000000000000000;
ll MOD=1000000007;

int par[100100];
int rrank[100100];
void init(int n){
for (int i=0;i<n;i++){
par[i]=i;
rrank[i]=0;
}}
int find(int x){
if (par[x]==x) return x;
else return par[x]=find(par[x]);
}
void unite(int x,int y){
x=find(x);
y=find(y);
if (x==y) return;
if (rrank[x]<rrank[y]) par[x]=y;
else {par[y]=x;
if (rrank[x]==rrank[y]) rrank[x]++;}}
bool same(int x,int y){
return find(x)==find(y);}

int main() {
    int n,m;
    cin >> n >> m;
    int w,a,b;
    init(n);
    rep(i,m) {cin >> a >> b >> w;unite(a,b);}
    set<int> s;
    int ans=0;
    rep(i,n){
        set<int>::iterator iti = s.find(find(i+1));
        if (iti==s.end()){
            //cout << i+1 << endl;
            ans++;
            s.insert(find(i+1));
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	int sum = 0;
	int l_max = 0;

	for (int i = 0; i < n; i++) {
		cin >> l;
		sum += l;
		l_max = max(l_max, l);
	}

	bool ans = (sum - l_max) > l_max;

	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a;
  for(int i=1;i<=9;i++){
  	if(a%i==0 && a/i<=9){
    	cout<<"Yes"<<'\n';
    	return 0;
  	}	
  }
  cout<<"No"<<'\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i]; 
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    rep(i,Q)cout<<res[i]<<endl;
}

Measured memory_bytes: 21728
/*
Owner: darkxeon
Problem: Divide a Cuboid
Date: 21/11/2019
*/
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//	freopen("ex.in", "r", stdin);
//	freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	vector<long long> a(3);
	for(auto &i : a) cin >> i;
	
	sort(a.begin(), a.end());
	
	cout << abs(((a[2] / 2) * a[1] * a[0]) - (((a[2] + 1) / 2) * a[1] * a[0]));
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a=0,b=0,t=0;
	scanf("%d %d",&a,&b);
	if(a>b)
	{
		t=a-1;
		if(t>b)
		{
			printf("%d",a+a-1);
		}
		else
		{
			printf("%d",a+b);
		}
	}
	else
	{
		t=b-1;
		if(t>a)
		{
			printf("%d",b+b-1);
		}
		else
		{
			printf("%d",a+b);
		}
	}
	return 0;
}

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

const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

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

  ll r = 0, g = 0, b = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') r++;
    if (s[i] == 'G') g++;
    if (s[i] == 'B') b++;
  }
  int rgb = int('R') + int('G') + int('B');
  ll ans = r * g * b;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      int k = j * 2 - i;
      if (k >= n) continue;
      if (int(s[i]) + int(s[j]) + int(s[k]) == rgb) {
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  set<int64_t> s;
  for(int i=0;i<N;i++){
    int64_t a;
    cin >> a;
    s.insert(a);
  }
  if(s.size()==N){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 9600
#include<cstdio>
#include<iostream>
#include<cstdlib>
using namespace std;
int a[500001],b[500002]={0};
int main(){
	int n;
	cin>>n;
	int i;
	for(i=0;i<n;i++){
		cin>>a[i];
		if(a[i]-1<0){
			b[500001]++;
		}else{
			b[a[i]-1]++;
		}
		b[a[i]]++;
		b[a[i]+1]++;
	}
	int max=0;
	for(i=0;i<=500001;i++){
		if(b[i]>max){
			max=b[i];
		}
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n; cin >> n;
    map<string,int> mp;
    rep(i,n) {
        string si; cin >> si;
        ++mp[si];
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    return 0;
}

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

typedef long long ll;
#define rep(n, i) for(int i = 0; i < n; ++i)
const double PI = acos(-1);

void solve(void) {
  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double rada = (h / 12.0 * 2 * PI) + (m / 60.0 * PI / 6.0);
  double radb = m / 60.0 * 2 * PI;
  double rad = abs(rada- radb);
  if (rad >= PI ) rad = -(rad - 2 * PI);

  cout << setprecision(16) << sqrt(a * a + b * b - 2 * a * b * cos(rad)) << endl;
  return;
}

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

Measured memory_bytes: 4256
n=gets.to_i
m=gets.split.map(&:to_i)
first=m[0]
last=m[-1]
m.unshift(first)
m.push(last)
#p m
count=0
flag=0
for i in 1..m.length-1
    if  flag=="-" && m[i]-m[i-1]>0
        flag=0
        count+=1
        
    elsif flag=="+" && m[i]-m[i-1]<0
        flag=0
        count+=1
    elsif flag==0 && m[i]-m[i-1]>0
        flag="+"
    elsif flag==0 && m[i]-m[i-1]<0
        flag="-"
    
    end

#p flag
end
p count+1

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

using namespace std;

typedef long long LL;
typedef long double LD;



int main()
{
  LL N, M;
  cin >> N >> M;

  priority_queue<LD, vector<LD>, less<LD>> A;

  for (LL i = 0; i < N; i++) {
    LD a;
    cin >> a;
    A.push(a);
  }
 
  for (LL i = 0; i < M; i++) {
    LD a = A.top();
    a /= 2.0;
    A.pop();
    A.push(a);
  }

  LL total_cost = 0;
  while (!A.empty()) {
    LD cost = A.top();
    //cerr << cost << endl;
    total_cost += (LL)cost;
    A.pop();
  }

  cout << total_cost;

  return 0;
}






Measured memory_bytes: 3444
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
using namespace std;
using boost::irange;

// 定義
typedef long long           ll;
typedef pair<ll, ll>        P;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
const ll                    INF = 2e9;
const ll                    INF_LL = 1LL<<60;
const ll                    MOD = 1e9 + 7;
namespace {
	ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
	ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
	ll FloorN(ll x, ll n)     { return (x - x % n); }
	bool IsOdd(ll x)          { return ((x & 1) == 1); }
	bool IsEven(ll x)         { return ((x & 1) == 0); }
	template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
	template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
};



// 処理
void Solve()
{
	vector<ll> A;
	vector<bool> isUsed;

	ll N, K;
	cin >> N >> K;
	A.resize(N);
	REP(i, N) {
		cin >> A[i];
		A[i]--;
	}

	ll idx = 0;
	ll depCnt = 0;
	vector<ll> depth(N, INF);
	isUsed.resize(N, false);
	while (!isUsed[idx]) {
		isUsed[idx] = true;
		depth[idx] = depCnt;
		idx = A[idx];
		depCnt++;
	}

	ll cycNum = depCnt - depth[idx];
	ll targetDepth = min(K, depth[idx]);
	K -= targetDepth;
	if (0 < K) {
		targetDepth = K % cycNum;
		targetDepth += depth[idx];
	}

	ll ans = 0;
	REP(i, N) {
		if (depth[i] == targetDepth) {
			ans = i + 1;
			break;
		}
	}
	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 6368
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define MAX_N (10010)

static map<int, int> prime_factorization(int N)
{
	map<int, int> ret;
	for (int i = 2; i <= N; i++) {
		while (N % i == 0) {
			ret[i]++;
			N /= i;
		}
	}
	return ret;
}

class Combination
{
private:
	int p;
	vector<ll> factorials, factorials_r;

public:
	// O(n)
	void init(int n, int _p)
	{
		if (n % _p == 0) {
			printf("%d should not be multiple of %d\n", n, _p);
			exit(1);
		}
		if (n >= _p) {
			printf("%d should not be greater than %d\n", n, _p);
			exit(1);
		}

		p = _p;

		// n!
		factorials.clear();
		factorials.resize(n + 1);
		factorials[0] = 1;
		for (ll i = 1; i <= n; i++)
			factorials[i] = (i * factorials[i - 1]) % p;

		// n!^(-1)
		factorials_r.clear();
		factorials_r.resize(n + 1);
		factorials_r[n] = __power(factorials[n], p - 2, p);
		for (ll i = n - 1; i >= 0; i--) {
			factorials_r[i] = factorials_r[i + 1] * (i + 1);
			factorials_r[i] %= p;
		}
	}

	// O(1)
	// nCr = n! / (r! * (n - r)!) = n! * (1 / r!) * (1 / (n - r)!)
	ll get(int n, int r)
	{
		if (n < 0 || r < 0 || n < r)
			return 0;
		if (r == 0)
			return 1;

		return (factorials[n] * factorials_r[r]) % p * factorials_r[n - r] % p;
	}

private:
	static ll __power(ll n, ll r, ll p)
	{
		ll power_of_2, power_of_2_prev, res = 1;

		// n ^ 2 ^ 0 --- n ^ 2 ^ 63
		for (ll j = 0; j < 64; j++) {
			power_of_2 = (j == 0 ? n : power_of_2_prev * power_of_2_prev) % p;
			if (r & ((ll)1 << j))
				res = res * power_of_2 % p;
			power_of_2_prev = power_of_2;
		}

		return res;
	}
};

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);

	map<int, int> primes = prime_factorization(M);

	Combination comb;
	ll ret = 1;
	for (auto iter = primes.begin(); iter != primes.end(); iter++) {
		int k = iter->second;
		comb.init(N - 1 + k, MOD);
		ret *= comb.get(N - 1 + k, k);
		ret %= MOD;
	}
	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#define mo 1000000007
int fac[4000005],inv[4000005],n,k,f[2005][2005];
int C(int n,int m){return 1ll*fac[n]*inv[m]%mo*inv[n-m]%mo;}
int ksm(int a,int p)
{int ans=1;for(;p;p>>=1,a=1ll*a*a%mo)if(p&1)ans=1ll*ans*a%mo;return ans;}
int main()
{
	scanf("%d%d",&n,&k);
	if(k==1){printf("1\n");return 0;}
	f[0][0]=1;inv[0]=fac[0]=1;
	for(int i=1;i<=n*k;i++)fac[i]=fac[i-1]*1ll*i%mo;
	inv[n*k]=ksm(fac[n*k],mo-2);
	for(int i=n*k-1;i;i--)inv[i]=inv[i+1]*1ll*(i+1)%mo;
	for(int i=1;i<=n;i++)
	{
		f[i][0]=f[i-1][0];
	 	for(int j=1;j<=i;j++)
	  	 f[i][j]=(f[i-1][j]+f[i][j-1]*1ll*C(n*k-(j-1)*(k-1)-i-1,k-2)%mo)%mo;
	}printf("%d\n",f[n][n]*1ll*fac[n]%mo);
}

Measured memory_bytes: 46208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.function.LongSupplier;
import java.util.function.ToLongFunction;

public class Main{ // Main
	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

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

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

	static LongSupplier now = new LongSupplier() {
		private long t = System.currentTimeMillis();

		@Override
		public long getAsLong() {
			long a = t;
			t = System.currentTimeMillis();
			long ans = t - a;
			return ans;
		}
	};

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static int tr(Object... objects) {
		System.out.println("tr:" + Arrays.deepToString(objects));
		return 0;
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int n = cin.nextInt();
		int m = cin.nextInt();
		int r = cin.nextInt();

		int[] s = new int[r];
		for (int i = 0; i < s.length; i++)
			s[i] = cin.nextInt() - 1;
		long[][] dist = new long[n][n];
		for (long[] d : dist)
			Arrays.fill(d, Long.MAX_VALUE / 2);
		for (int i = 0; i < n; i++)
			dist[i][i] = 0;
		for (int i = 0; i < m; i++) {
			int a = cin.nextInt() - 1;
			int b = cin.nextInt() - 1;
			int c = cin.nextInt();
			dist[a][b] = dist[b][a] = c;
		}

		now.getAsLong();

		long ans = solve(n, r, s, dist);
		cout.println(ans);

		assert 0 == tr("elapsed", now.getAsLong());
	}

	private static long solve(int n, int r, int[] s, long[][] d) {

		// Warshall–Floyd Algorithm
		for (int k = 0; k < n; k++)
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					if (d[i][j] > d[i][k] + d[k][j])
						d[i][j] = d[i][k] + d[k][j];

		// 2<=R<=min(8,N)
		ToLongFunction<Integer> minimize = new ToLongFunction<Integer>() {
			@Override
			public long applyAsLong(Integer x) {
				int k = x;
				if (k == r - 1) {
					// evaluate
					assert 0 == tr(s);
					long ans = 0;
					for (int i = 1; i < r; i++)
						ans += d[s[i - 1]][s[i]];
					return ans;
				}

				// permutate
				long ans = Long.MAX_VALUE;
				for (int i = k; i < r; i++) {
					int t = s[i];
					s[i] = s[k];
					s[k] = t;
					long subans = this.applyAsLong(k + 1);
					ans = Math.min(ans, subans);
					t = s[i];
					s[i] = s[k];
					s[k] = t;
				}
				return ans;
			}

		};
		long ans = minimize.applyAsLong(0);
		return ans;
	}

}


Measured memory_bytes: 31540
N,M = map(int,input().split())
from collections import deque
v = [deque([]) for _ in range(N)]

for i in range(M):
    a,b,c = map(int,input().split())
    a,b = a-1,b-1
    v[a].append([b,c])
    v[b].append([a,c])

s = deque([])
for i in range(N):
    ls = [[-1,M*10000]]*N
    ls[i] =  [-1,0]
    q = [deque(j for j in k) for k in v]
    l = deque([i])
    while l:
        u = l.popleft()
        x = len(q[u])
        for i in range(x):
            e = q[u].popleft()
            if ls[u][1] + e[1] < ls[e[0]][1]:
                ls[e[0]] = [u, ls[u][1] + e[1]]
                l.append(e[0])
            q[u].append(e)
    for j,e in enumerate(ls):
        if e[0] != -1:
             s.append([min(j,e[0]),max(j,e[0])])

s = list(map(list, set(map(tuple, s))))
print(M-len(s))


Measured memory_bytes: 4716
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int num = 100*r + 10*g + b;
  if (num % 4 == 0) {
    coYES;
  }
  else {
    coNO;
  }
}


Measured memory_bytes: 3636
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
  int n, m;
  cin >> n >> m;
  v a(n, 0);
  int total = 0;
  rep(i, n)
  {
    cin >> a[i];
    total += a[i];
  }
  int cnt = 0;
  rep(i, n)
  {
    if(a[i] * 4 * m >= total) cnt++;
  }
  if(cnt >= m) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

a, b, c, d = nm()
while True:
    c -= b
    if c <= 0:
        print('Yes')
        break
    a -= d
    if a <= 0:
        print('No')
        break


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

int main() {
    int x;
    cin >> x;
    bool a;

    a = (x == 3 || x == 5 || x == 7);
  
     if(a){
          cout << "YES" << endl;
        }else{
          cout << "NO" << endl;
        }
 
}
  

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

int n, k;
string s;
int main() {
	cin >> n >> s >> k;
	for(int i=0; i<n; i++) {
		putchar(s[i]==s[k-1] ? s[i] : '*');
	}
	return 0;
}

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

int main() {
	for(int E; cin >> E && E; ) {
		int best = 1 << 30;
		
		for(int z = 0; z * z * z <= E; z++) {
			for(int y = 0; y * y + z * z * z <= E; y++) {
				int x = E - y * y - z * z * z;
				
				best = min(best, x + y + z);
			}
		}
		
		cout << best << endl;
	}
}

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;
    const ll INF = LLONG_MAX / 16LL;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        auto i = vs.begin();
        os << "[" << *i;
        for (++i; i != vs.end(); ++i) os << " " << *i;
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<vector<int>> A;
    void input() {
        cin >> N;
        A = vector<vector<int>>(N, vector<int>(N, 0));
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                cin >> A[i][j];
            }
        }
    }

    struct S {
        int from, to; ll cost;
        S(int from, int to, ll cost) : from(from), to(to), cost(cost) {}
        bool operator<(const S& s) const {
            return cost > s.cost;
        }
    };

    ll calc() {
        priority_queue<S> PQ;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                PQ.push(S(i, j, A[i][j]));
            }
        }
        auto D = vector<vector<ll>>(N, vector<ll>(N, INF));
        ll ans = 0;
        while (not PQ.empty()) {
            auto cur = PQ.top(); PQ.pop();
            // cout << cur.from << " -> " << cur.to << " : " << cur.cost << endl;
            auto cur_opt = D[cur.from][cur.to];
            if (cur.cost > cur_opt) return -1;
            if (cur.cost == cur_opt) continue;
            ans += cur.cost;
            D[cur.from][cur.to] = D[cur.to][cur.from] = cur.cost;
            for (auto k : {cur.from, cur.to}) {
                for (int i = 0; i < N; i++) {
                    for (int j = 0; j < N; j++) {
                        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
                    }
                }
            }
        }
        return ans;
    }

    void solve() {
        cout << calc() << endl;
    }
}

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



Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int N, M, X;
    cin >> N >> M >> X;
    int left = 0, right = 0;
    for (int i = 0; i < M; ++i) {
        int A;
        cin >> A;
        if (A < X) {
            left++;
        } else {
            right++;
        }
    }
    cout << min(left, right) << endl;

    return 0;
}

Measured memory_bytes: 256
n,m,x=map(int,input().split())
cx=[list(map(int,input().split())) for i in range(n)]

ans=10000000000000000000000000000

for dummy in range(2**n):
  books=format(dummy, 'b')
  books='0'*(n-len(books))+books
  point=[0]*(m+1)
  cost=0
  for i in range(n):
    if books[i]=='1':
      cost+=cx[i][0]
      for j in range(1,m+1):
        point[j]+=cx[i][j]
  ok=1
  for j in range(1,m+1):
    if point[j]<x:
      ok=0
  if ok:
    ans=min(ans,cost)


if ans==10000000000000000000000000000:
  ans=-1
print(ans)

Measured memory_bytes: 9180
fun main() {
    readInt()
    val a = readInts().map { it.toLong() }

    val all = a.reduce { acc, l -> acc xor l }
    println(a.map { it xor all }.joinToString(" "))
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 78776
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;

const int INF = (int)10e9;
int N, K;
vector<int> v;
vector<int> dp;

int main() {
    cin >> N >> K;
    v.resize(N);
    dp.resize(N);
    fill(all(dp), 0);

    for(int i = 0; i < N; i++) {
        cin >> v[i];
    }

    for(int i = 1; i < N; i++) {
        dp[i] = INF;
        for(int j = 1; j <= K; j++) {
            if(i - j >= 0) {
              dp[i] = min(dp[i], abs(v[i] - v[i-j]) + dp[i-j]);
            }
        }
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
import sys
HAND=["null","one pair","two pair","three card","straight","full house","four card"]
for line in sys.stdin.readlines():
    cards=sorted(map(int,line.strip().split(",")))
    switch=len(set(cards))
    ma=max([cards.count(i) for i in cards])
    if switch==4:print HAND[1]
    elif switch==3:
        if ma==2:print HAND[2]
        else:print HAND[3]
    elif switch==2:
        if ma==4:print HAND[6]
        else:print HAND[5]
    else:
        if cards==[1,10,11,12,13] or len(set([cards[i+1]-cards[i] for i in xrange(4)]))==1:print HAND[4]
        else:print HAND[0]

Measured memory_bytes: 23000
#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable:4996)

int main() {
	int N = 0, K = 0;
	scanf("%d %d", &N, &K);
	int price[1000] = { 0 };
	for (int i = 0; i < N; i++) {
		scanf("%d", &price[i]);
	}
	for (int i = 0; i < N-1; i++) {
		for (int j = 0; j < N-1; j++) {
			if (price[j] > price[j + 1]) {
				int temp = price[j];
				price[j] = price[j + 1];
				price[j + 1] = temp;
			}
		}
	}
	int m = 0;
	for (int i = 0; i < K; i++) {
		m += price[i];
	}
	printf("%d\n", m);
		return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int H, W;
	cin >> H >> W;
	
	vector<int> A(H), B(H);
	REP(i, H) scanf("%d %d", &A[i], &B[i]), --A[i];
	
	int cur = 0;
	set<pii> dp; // pos, min-dist
	multiset<int> mind;
	REP(i, W) {
		dp.emplace(i, 0);
		mind.insert(0);
	}
	REP(i, H) {
		// B[i] を更新
		pii upd(-1, -1);
		auto it = dp.lower_bound(pii(B[i], -1));
		if (it != dp.begin()) {
			if (it == dp.end() || it->first != B[i]) {
				--it;
				int nd = it->second + (B[i] - it->first);
				upd = pii(B[i], nd);
			}
		}
		
		// [A[i], B[i]) を削除
		it = dp.lower_bound(pii(A[i], -1));
		while (it != dp.end() && it->first < B[i]) {
			mind.erase(mind.find(it->second));
			it = dp.erase(it);
		}
		
		// 更新した B[i] の変更
		if (B[i] != W && upd != pii(-1, -1)) {
			dp.insert(upd);
			mind.insert(upd.second);
		}
		
		int ans = -1;
		if (!mind.empty()) ans = *mind.begin() + i + 1;
		printf("%d\n", ans);
	}
	
	return 0;
}


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

int main(){
 int n;
 cin>>n;
 vector<ll> v(n);
 vector<ll> sum(n);
 for(ll i=0;i<n;i++){
 	cin>>v[i];
 	if(i==0)
 		sum[i]=v[i];
 	else
	 	sum[i]=v[i]+sum[i-1];	
 }
 
 vector<vector<ll>> dp(n,vector<ll>(n,0));
 for(ll j=0;j<n;j++){
 	for(ll i=j-1;i>=0;i--){
 		dp[i][j]=LLONG_MAX;
 		for(ll k=i;k<j;k++){
 			ll s=0;
 			s=sum[j];
 			if(i>0)
 				s-=sum[i-1];
 			dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+s);	
		}	
	}
 }

 cout<<dp[0][n-1]<<endl;
 return 0;
}



Measured memory_bytes: 4892
#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define pb push_back
using namespace std;

const int N = 1e6+10;
int n, k, ans, a[N], f[N];
vector<int> g[N];

void dfs(int x) { 
    f[x] = 1;
    for (int y:g[x]) dfs(y), f[x] = max(f[x], f[y]+1);
    if (f[x]==k&&a[x]!=1) ++ans,f[x]=0;
}
int main() {
    scanf("%d%d", &n, &k);
    REP(i,1,n) scanf("%d", a+i);
    ans = a[1]!=1;
    a[1] = 1;
    REP(i,2,n) g[a[i]].pb(i);
    dfs(1);
    printf("%d\n", ans);
}

Measured memory_bytes: 34688