akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int H, N, A[1010], B[1010];
int dp[1010][10101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> N;
	rep(i, 0, N) cin >> A[i] >> B[i];

	rep(i, 0, N + 1) rep(h, 0, H + 1) dp[i][h] = inf;
	dp[0][H] = 0;

	rep(i, 0, N) rrep(h, H, 0) {
		chmin(dp[i + 1][h], dp[i][h]);
		chmin(dp[i][max(0, h - A[i])], dp[i][h] + B[i]);
	}

	cout << dp[N][0] << endl;
}







Measured memory_bytes: 39808
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector< vector< long long > > scr, scs;
vector< vector< int > > to;
int main(void){
    int n, k;
    cin >> n >> k;
    vector<long long> c(n), p(n);
    scr.assign(n, vector<long long>(n+1, 0));
    scs.assign(n, vector<long long>(n+1, 0));
    to.assign(n, vector<int>(n+1, -1));
    for(int i=0;i<n;i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i=0;i<n;i++) cin >> c[i];

    for(int i=0;i<n;i++){
        int v = i;
        long long s = 0;
        for(int j=0;j<=n;j++){
            if(j > 0) scs[i][j] = max(scs[i][j-1], s);
            scr[i][j] = s;
            to[i][j] = v;
            v = p[v];
            s += c[v];
        }
    }
    long long ans = -1e18-1;
    for(int i=0;i<n;i++){
        for(int j=1;j<=min(n, k);j++){
            ans = max(ans, scr[i][j]);
        }
    }
    if(k <= n){
        cout << ans << endl;
        return 0;
    }

    k--;
    for(int i=0;i<n;i++){
        vector<int> w(n, -1);
        int v = p[i];
        int j = 0;
        for(j=0;w[v]==-1;j++){
            w[v] = j;
            v = p[v];
        }
        long long tmp = scr[i][w[v]];
        int x = k - w[v];
        int y = j - w[v];
        // cout << i << " " << j << " " << v << " " << w[v] << " " << x << " " << y << endl;
        if(scr[v][y] >= 0) tmp += scr[v][y] * (x / y);
        tmp += scs[v][x%y];
        tmp = max(tmp, scs[i][w[v]]);
        ans = max(ans, tmp+c[p[i]]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 491988
#include <stdio.h>

int main(void){
	unsigned long long n, a, b, ans = 0;
	scanf("%llu %llu %llu", &n, &a, &b);
	if((b - a) % 2 == 0) ans = (b - a) / 2;
	else{
		if(a - 1 <= n - b){
			ans = a;
			b -= a;
			a = 1;
		}else{
			ans = n - b + 1;
			a += n - b + 1;
			b = n;
		}
		ans += (b - a) / 2;
	}
	printf("%llu\n", ans);
	return 0;
}


Measured memory_bytes: 128
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
l = r = ""
for op in qs:
    if op[0] == '1':
        n = not n
    if op[0] == '2':
        t , f, c = op
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            l=c+l
        elif f == 2:
            r+=c
s = l+s+r
print(s[::-1] if n else s)

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);

  int N;
  cin >> N;
  vector<pll> v(N);
  for(int i = 0; i < N; i++){
    ll x,y;
    cin >> x >> y;
    v.at(i) = make_pair(x,y);
  }

  map<pll,int > m;
  for(int i = 0; i < N-1; i++){
    for(int j = i+1; j < N; j++){
      pll p1,p2;
      p1 = v[i];
      p2 = v[j];

      ll diff_x = p1.first - p2.first;
      ll diff_y = p1.second - p2.second;

      m[make_pair(diff_x, diff_y)]++;
      m[make_pair(-diff_x, -diff_y)]++;
    }
  }

  int max_val = 0;
  for(auto x: m){
    max_val = max(max_val, x.second);
  }
  cout << N - max_val << endl;
}


Measured memory_bytes: 384
void main(){
	int n = _scan();
	string s = readln().chomp();
	writeln( s[0..n/2] == s[n/2..$]? "Yes": "No" );
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2680
#[allow(unused_macros)]
macro_rules! input {
    ($x:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        $x = buf.trim().parse().unwrap();
    };

    ($x:expr, $($y:expr), +) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        input_iter!(buf.split_whitespace(), $x, $($y), +);
    };

    ($v:expr; $size:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        for v in buf.split_whitespace() {
            $v.push(v.parse().unwrap());
        }
    };

    ($v:expr; $h_size:expr, $w_size:expr) => {
        for _ in 0..$h_size {
            let mut part_vec = Vec::new();
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).ok();
            for v in buf.split_whitespace() {
                part_vec.push(v.parse().unwrap());
            }
            $v.push(part_vec);
        }
    };
}

#[allow(unused_macros)]
macro_rules! input_iter {
    ($iter:expr, $x:expr) => {
        $x = $iter.next().unwrap().parse().unwrap();
    };

    ($iter:expr, $x:expr, $($y:expr), +) => {
        let mut iter = $iter;
        $x = iter.next().unwrap().parse().unwrap();
        input_iter!(iter, $($y), *);
    };
}

use std::collections::*;

fn main() {
    let (n, m): (usize, usize);
    input!(n, m);
    let mut works = vec![vec![]; m + 1];
    for _ in 0..n {
        let (a, b): (usize, usize);
        input!(a, b);
        if a <= m {
            works[a].push(b);
        }
    }
    let mut candidates = BinaryHeap::new();
    let mut ans = 0;
    for i in 1..(m + 1) {
        for work in &works[i] {
            candidates.push(work);
        }
        ans += match candidates.pop(){
            Some(x) => *x,
            None => 0,
        };
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod=998244353;
vector<ll>ans;

ll add(ll a, ll b)  {return ( (a%mod) + (b%mod) )%mod;}

ll multiply(ll a, ll b) {return ((a%mod) * (b%mod))%mod;}

ll power(ll a, ll b)
{
    if(b==0) return 1;
    ll temp=power(a,b/2);
    if(b%2==1) return multiply(temp,multiply(temp,a));
    else return multiply(temp,temp);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   ll n;
   cin>>n;
   unordered_map<ll,ll>s;
   vector<ll>v(n);
   for(int i=0;i<n;i++)
   {
       cin>>v[i];
       s[v[i]]++;
   }
   ll c=0,ans=0;
   for(int i=0;i<n;i++)
   {
       c=0;
       for(int j=1;j<=sqrt(v[i]);j++)
       {
           if((v[i]%j) ==0 )
           {
               if(s.find(j)!=s.end())
               {
                   c+=s[j];
               }
               if( (v[i]/j)!=j && s.find(v[i]/j)!=s.end())
               {
                   c+=s[v[i]/j];
               }
           }
       }
       if(c==1){
           ans++;
       }
   }
   cout<<ans<<"\n";
}


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



int main(){
    int n, m;

    cin >> n >> m;
    int r, l;
    int r_min = n;
    int l_max = 0;
    for(int i=0; i < m; i++){
        cin >> l >> r;
        r_min = min(r_min, r);
        l_max = max(l_max, l);

    }
    cout << max(r_min - l_max + 1, 0) << endl;



}


Measured memory_bytes: 256
#include <utility>
#include <vector>
#include <iostream>
#include <cstdlib>
#include<bits/stdc++.h>
#include <limits>
#include <set>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef long long ll;
using namespace std;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<int, ll> mp;
    for(int i = 1; i <= 100000; i++){
        mp[i] = 0;
    }
    ll N, K;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        ul a, b;
        cin >> a >> b;
        mp[a] += b;
    }
    int ans;
    for(int i = 1; i <= 100000; i++){
        K -= mp[i];
        if(K <= 0){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8576
// AOJ 0564: Bug Party
// 2018.1.27 bal4u

#include <stdio.h>

#define MAX 300002

typedef struct { int a, b; } T;
T tbl[MAX], tbl2[MAX];

T que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	T qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].b < que[i].b) min = l; else min = i;
	if (r < qsize && que[r].b < que[min].b) min = r;
	if (min != i) {
		qt = que[i]; que[i] = que[min]; que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
//	if (qsize == 0) return 0;
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int a, int b)
{
	int i, min;
	T qt;

	i = qsize++;
	que[i].a = a, que[i].b = b;
	while (i > 0 && que[min = PARENT(i)].b > que[i].b) {
		qt = que[i]; que[i] = que[min]; que[min] = qt;
		i = min;
	}
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int f[100002];
void distsort(int n)
{
	int i, x;

	for (i = 0; i < n; i++) f[tbl2[i].a]++;
	for (i = 1; i <= 100000; i++) f[i] += f[i-1];
	for (i = n-1; i >= 0; i--) {
		x = tbl2[i].a, tbl[--f[x]] = tbl2[i];
	}
}

int main()
{
	int i, n, ans;
	long long s;

	n = in();
	for (i = 0; i < n; i++) tbl2[i].a = in(), tbl2[i].b = in();
	distsort(n);

	ans = 0, s = 0, qsize = 0;
	for (i = 0; i < n; i++) {
		s += tbl[i].a;
		enq(tbl[i].a, tbl[i].b);
		while (qsize && (long long)qsize*que[0].b < s) {
			s -= que[0].a, deq();
		}
		if (qsize > ans) ans = qsize;
	}
	printf("%d\n", ans);
	return 0;
}



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

int main(){
  string S;
  cin >> S;
  if (S == "Sunny"){
    cout << "Cloudy" << endl;
  }
  else if (S == "Cloudy"){
    cout << "Rainy" << endl;
  }
  else if (S == "Rainy"){
    cout << "Sunny" << endl;
  }
}


Measured memory_bytes: 256
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;
    
    auto ans = n / 2;
    if (n % 2 == 0) { ans -= 1; }
    
    ans.writeln;
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  string s;
  cin >> s;
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

struct dice {
    mt19937 mt;
    dice() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}
    ll operator()(ll x) { return this->operator()(0, x - 1); }
    ll operator()(ll x, ll y) {
        uniform_int_distribution<ll> dist(x, y);
        return dist(mt);
    }
} rnd;

class rollingHash {
private:
    static constexpr ll mod = (1LL<<61) - 1;
    const ll base;
    vector<ll> hash, p;

    ll mul(ll a, ll b) {
        ll au = a>>31, ad = a & ((1LL<<31)-1);
        ll bu = b>>31, bd = b & ((1LL<<31)-1);
        ll mid = ad*bu+au*bd, midu = mid>>30, midd = mid & ((1LL<<30)-1);
        return au*bu*2 + midu + (midd<<31) + ad*bd;
    }
    ll calcmod(ll x) {
        ll ret = (x>>61) + (x & mod);
        if(ret >= mod) ret -= mod;
        return ret;
    }

public:
    rollingHash(const string &s) : base(rnd(2, 100000)), hash(s.size()+1), p(s.size()+1,1) {
        REP(i, s.size()) {
            hash[i+1] = calcmod(mul(hash[i], base)+s[i]);
            p[i+1] = calcmod(mul(p[i], base));
        }
    }
    // [l,r)
    ll get(int l,int r) {
        return calcmod(hash[r] + 3*mod - mul(hash[l], p[r-l]));
    }
    ll concat(ll h1, ll h2, ll h2len) {
        return calcmod(mul(h1, p[h2len]) + h2);
    }
};

int main(void) {
    ll n, q;
    string s;
    cin >> n >> q >> s;

    rollingHash hash(s);

    ll l = 0, r = 0;
    set<ll> st;
    while(q--) {
        string t;
        cin >> t;
        if(t == "R++") r++;
        else if(t == "R--") r--;
        else if(t == "L++") l++;
        else if(t == "L--") l--;
        st.insert(hash.get(l, r+1));
    }
    cout << st.size() << endl;

    return 0;
}


Measured memory_bytes: 21936
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N, Q;
	cin >> N >> Q;
    
	string S;
	cin >> S;
    
    for( int ii = 0; S[ii+1] != '\0'; ++ii){
        if( S[ii] == 'A' && S[ii+1] == 'C' ){
            S[ii+1] = 'a';
        }
    }
    
    vector<int> t;
    int cnt = 0;
    for( int ii = 0; ii < N; ++ii ) {
        if(S[ii] == 'a'){
            ++cnt;
        }
        t.push_back(cnt);
        //cout << cnt << endl;
    }
    
    for( int ii = 0; ii < Q; ++ii ) {
        int li, ri;
        cin >> li >> ri;
        
        cout << t[ri-1] - t[li-1] << endl;
    }
	
	return 0;
}


Measured memory_bytes: 1528
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;



vector<ll> getdiv(int k) {
	vector<ll> res;
	for (int i = 1; i * i <= k; i++) {
		if (k % i == 0) {
			res.push_back(i);
			res.push_back(k / i);
			if (i == k / i)res.pop_back();
		}
	}
	sort(res.begin(), res.end());
	return res;
}


int main()
{
	//int n; cin >> n;
	//string s;
	//cin >> s;
	//int left = 0, right = 0;
	//bool previsright = false;
	//stack<char> st; // 8 (()))(() 6 (())() ))(()()()()( 8
	////))((())(

	//ll ans = 0;
	//ll start = -1;
	//for (int i = 0; i < n; i++) {
	//	if (s[i] == '(') {
	//		st.push('(');
	//		left++;
	//		if (right == left) {
	//			ans += i - start + 1;
	//			for (int j = 0; j < left; j++) st.pop();
	//			left = 0;
	//			right = 0;
	//			start = -1;
	//			
	//		}
	//		
	//	}
	//	else {
	//		if (!st.empty() && st.top() == '(') {
	//			left--;
	//			st.pop();
	//		}
	//		else {
	//			if (start == -1) {
	//				start = i;
	//				right++;
	//			}
	//			else {
	//				right++;
	//			}
	//		}
	//		

	//	}
	//}

	//if (left == 0 && right == 0)
	//	cout << ans;
	//else cout << -1;

	string s;
	cin >> s;
	if (s[0] != s[1] || s[1] != s[2]) cout << "Yes";
	else cout << "No";








}

Measured memory_bytes: 256
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int main(){
  int a[3];
  rep(i, 3) cin >> a[i];
  sort(a, a + 3);
  cout << (a[0] + a[1] == a[2] ? "Yes\n" : "No\n") << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define lson o<<1
#define rson o<<1|1
#define mid (l+r)/2
#define ll long long
using namespace std;
struct Tree
{
	ll addv;
	ll maxv;
}tree[800005];
ll val[200005];
void pushup(int o)
{
	tree[o].maxv=max(tree[lson].maxv,tree[rson].maxv);
}
void pushdown(int o)
{
	if(tree[o].addv)
	{
		tree[lson].addv+=tree[o].addv;
		tree[rson].addv+=tree[o].addv;
		tree[lson].maxv+=tree[o].addv;
		tree[rson].maxv+=tree[o].addv;
		tree[o].addv=0;
	}
}
void add(int o,int l,int r,int from,int to,ll v)
{
	if(from>to)return;
	if(l>=from&&r<=to)
	{
		tree[o].addv+=v;
		tree[o].maxv+=v;
		return;
	}
	pushdown(o);
	if(from<=mid)add(lson,l,mid,from,to,v);
	if(to>mid)add(rson,mid+1,r,from,to,v);
	pushup(o);
}
ll ask(int o,int l,int r)
{
	if(l==r)return l;
	pushdown(o);
	if(tree[lson].maxv>=0)return ask(lson,l,mid);
	else return ask(rson,mid+1,r);
}
void debug(int o,int l,int r)
{
	if(l==r)
	{
		printf("%lld ",tree[o].maxv);
		return;
	}
	pushdown(o);
	debug(lson,l,mid);
	debug(rson,mid+1,r);
}
struct Query
{
	int type;
	ll a,b;
}q[200005];
int n,m,sa[200005],rnk[200005];
bool cmp(int a,int b)
{
	return val[a]<val[b];
}
namespace rqytxdy
{
	ll c[200005];
	int c2[200005];
	void add(int p,int v)
	{
		while(p<=n)
		{
			c[p]+=v;
			c2[p]++;
			p+=p^(p&(p-1));
		}
	}
	ll ask(int p)
	{
		if(p<0)return 0;
		ll ans=0;
		while(p)
		{
			ans+=c[p];
			p&=p-1;
		}
		return ans;
	}
	ll ask(int l,int r)
	{
		return ask(r)-ask(l-1);
	}
	ll ask2(int p)
	{
		if(p<0)return 0;
		ll ans=0;
		while(p)
		{
			ans+=c2[p];
			p&=p-1;
		}
		return ans;
	}
	ll ask2(int l,int r)
	{
		return ask2(r)-ask2(l-1);
	}
}
using namespace rqytxdy;
int main()
{
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&q[i].type);
		if(q[i].type==1)
		{
			scanf("%lld%lld",&q[i].a,&q[i].b);
			val[++n]=q[i].a;
			sa[n]=n;
		}
	}
	sort(sa+1,sa+n+1,cmp);
	for(int i=1;i<=n;i++)rnk[sa[i]]=i;
	sort(val+1,val+n+1);
	ll sum=0;
	int num=0;
	for(int i=1;i<=m;i++)
	{
		if(q[i].type==1)
		{
			num++;
			sum+=q[i].b;
			add(1,1,n,1,rnk[num]-1,-1);
			add(1,1,n,rnk[num],n,1);
			add(rnk[num],q[i].a);
		}
		else
		{
			int x=ask(1,1,n);
			ll p=val[x];
			printf("%lld %lld\n",p,ask(x+1,n)-ask2(x+1,n)*p-ask(x-1)+ask2(x-1)*p+sum);
		}
	}
	return 0;
}

Measured memory_bytes: 18560
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    int n; cin >> n;
    vector<pii> a(n);
    for(auto &x: a) cin >> x.first >> x.second;
    vector<int> b(n);
    for(int i = 0; i < n; ++i) b[i] = i;
    double sum = 0.0;
    int num = 0;
    do {
        for(int i = 0; i < n-1; ++i) {
            sum += sqrt(sqr(a[b[i]].first-a[b[i+1]].first) + sqr(a[b[i]].second - a[b[i+1]].second));
        }
        num++;
    } while(next_permutation(b.begin(), b.end()));
    cout << sum / (double) num;
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>

using namespace std;

int main(){

	int n;
	cin>>n;

	//set<pair<int,int> > wrong;

	for(int i = 0; i < n; i++){
		bool wrong[10][10];
		memset(wrong,0,sizeof(wrong));
		int field[10][10];
		for(int j = 0; j < 9; j++){
			for(int k = 0; k < 9; k++){
				cin>>field[j][k];
			}
		}
		// row
		for(int j = 0; j < 9; j++){
			vector<pair<int,int> > p[10];
			for(int k = 0; k < 9; k++){
				p[field[k][j]].push_back(make_pair(k,j));
			}
			// 2ツ禿アツ度ツ暗按湘」ツ出ツ個サツつオツづつ「ツつスツづァツ、wrongツづ永nsert
			for(int k = 1; k < 10; k++){
				if(p[k].size()>=2){
					for(int l = 0; l < p[k].size(); l++){
						//wrong.insert(p[k][l]);
						wrong[p[k][l].first][p[k][l].second]=true;
					}
				}
			}
		}
		// cow
		for(int j = 0; j < 9; j++){
			vector<pair<int,int> > p[10];
			for(int k = 0; k < 9; k++){
				p[field[j][k]].push_back(make_pair(j,k));
			}
			// 2ツ禿アツ度ツ暗按湘」ツ出ツ個サツつオツづつ「ツつスツづァツ、wrongツづ永nsert
			for(int k = 1; k < 10; k++){
				if(p[k].size()>=2){
					for(int l = 0; l < p[k].size(); l++){
						wrong[p[k][l].first][p[k][l].second]=true;
					}
				}
			}
		}
		// mergin
		for(int j = 0; j < 7; j+=3){
			for(int k = 0; k < 7; k+=3){
				if(j==9&&k==0){
					cout<<endl;
				}
				// (k,j)ツづ個地ツ点ツつゥツづァツ探ツ催オツつキツづゥ
				vector<pair<int,int> > p[10];
				for(int l = 0; l < 3; l++){
					for(int m = 0; m < 3; m++){
						p[field[j+l][k+m]].push_back(make_pair(j+l,k+m));
					}
				}
				// 2ツ禿アツ度ツ暗按湘」ツ出ツ個サツつオツづつ「ツつスツづァツ、wrongツづ永nsert
				for(int l = 1; l < 10; l++){
					if(p[l].size()>=2){
						for(int m = 0; m < p[l].size(); m++){
							wrong[p[l][m].first][p[l][m].second]=true;
						}
					}
				}
			}
		}

		for(int j = 0; j < 9; j++){
			for(int k = 0; k < 9; k++){
				if(wrong[j][k]){
					cout<<'*';
				}
				else
					cout<<' ';
				cout<<field[j][k];
			}
			cout<<endl;
		}
		if(i!=n-1)
			cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>

using namespace std;

int main() {
  vector<string> c(3);
  copy_n(istream_iterator<string>(cin), c.size(), c.begin());
  for (size_t i = 0; i < c.size(); ++i) {
    cout << c[i][i];
  }
  cout << endl;
  return 0;
}


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

int main()
{
    int n, m, l;
    int a[100][100], b[100][100];
    long c[100][100];

    cin >> n >> m >> l;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            for (int k = 0; k < l; k++) {
                c[i][k] += a[i][j] * b[j][k];
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            if (j == l - 1) {
                cout << c[i][j];
            } else {
                cout << c[i][j] << ' ';
            }
        }

        cout << endl;
    }

    return 0;
}

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

int GCD(int former, int latter){
    if((former<=0)||(latter<=0))return -1;
    if(former%latter==0)return latter;
    if(latter%former==0)return former;
    return GCD(latter, former%latter);
}

int main(void){
    int X;
    cin >> X;
    cout << 360/GCD(360, X) << endl;
    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Linq;

namespace Main
{
	class Program
	{
		static void Main(string[] args)
		{
            int i;
            var temp = 0.0;
            var n = int.Parse(Console.ReadLine());
            var A_temp = Console.ReadLine().Split(' ');
            var a = new double[n];
            for (i = 0; i < n; i++)
            {
                a[i] = double.Parse(A_temp[i]);
            }
            for (i = 0; i < n; i++)
            {
                temp += (1 / a[i]);
            }
            Console.WriteLine(1 / temp);
		}
	}
}


Measured memory_bytes: 11092
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);

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

struct dice {
	int t, f, r;
	dice(int t, int f, int r) : t(t), f(f), r(r) {};
};

int getR(int t, int f) {
	switch(t) {
	case 1:
		switch(f) {
		case 2: return 3;
		case 3: return 5;
		case 4: return 2;
		case 5: return 4;
		}
	case 2:
		switch(f) {
		case 1: return 4;
		case 3: return 1;
		case 4: return 6;
		case 6: return 3;
		}
	case 3:
		switch(f) {
		case 1: return 2;
		case 2: return 6;
		case 5: return 1;
		case 6: return 5;
		}
	case 4:
		switch(f) {
		case 1: return 5;
		case 2: return 1;
		case 5: return 6;
		case 6: return 2;
		}
	case 5:
		switch(f) {
		case 1: return 3;
		case 3: return 6;
		case 4: return 1;
		case 6: return 4;
		}
	case 6:
		switch(f) {
		case 2: return 4;
		case 3: return 2;
		case 4: return 5;
		case 5: return 3;
		}
	}
}

dice roll(int d, dice die) {
	int nt = die.t;
	int nf = die.f;
	int nr = die.r;
	switch(d) {
	case 0:
		nt = 7-die.f;
		nf = die.t;
		break;
	case 1:
		nt = die.r;
		nr = 7-die.t;
		break;
	case 2:
		nt = die.f;
		nf = 7-die.t;
		break;
	case 3:
		nt = 7-die.r;
		nr = die.t;
		break;
	}
	return dice(nt, nf, nr);
}

int check(int d, dice die) {
	switch(d) {
	case 0:
		return die.f;
	case 1:
		return 7-die.r;
	case 2:
		return 7-die.f;
	case 3:
		return die.r;
	}
}

int main() {
	int n;
	while(cin >> n, n) {
		vvi height(31, vi(31));
		vvi num(31, vi(31));
		int t, f;
		REP(i, n) {
			cin >> t >> f;
		
			int r = getR(t, f);
			dice die(t, f, r);

			bool rolled = false;
			int px = 15, py = 15;
			int dir = -1;
			int tmp = 3;
			do {
				rolled = false;
				dir = -1;
				tmp = 3;
				REP(d, 4) {
					if(height[py][px] > height[py+dy[d]][px+dx[d]]) {
						if(check(d, die) > tmp) {
							dir = d;
							tmp = check(d, die);
						}
					}
				}

				if(dir != -1) {
					die = roll(dir, die);
					py = py+dy[dir];
					px = px+dx[dir];
					rolled = true;
				}
			} while(rolled);

			num[py][px] = die.t;
			height[py][px]++;
		}

		vi ans(7);
		REP(i, 31) {
			REP(j, 31) {
				ans[num[i][j]]++;
			}
		}

		cout << ans[1];
		FOR(i, 2, 6) {
			cout << " " << ans[i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1224
// // If you want something you've never had, you must be willing to do
// // something you've never done

// //  When the going gets tough,  the tough get going

// #pragma GCC optimize ("O3")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<pair<int,int>, null_type,less<pair<int, int> >,rb_tree_tag,tree_order_statistics_node_update > pbds;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// #define int ll
ll power(ll a, ll b, ll mod) {
    ll res = 1;
    a %= mod;
    while(b) {
        if(b % 2) {
            res *= a;
            res %= mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}
const int INF = 2e9;

// ----------------------------------------------------------
// #define int ll
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 1e9 + 7;
int n, m, q;

pair<pair<int,int>, pair<int,int > > p[55];
int mx = 0;
void solve(vector<int> &a) {
    // for(int x: a) {
    //     cout << x<<" ";
    // }
    // cout << '\n';
    int ans = 0;
    for(int i=0; i<q; ++i) {
        if(a[p[i].first.second-1] - a[p[i].first.first-1] == p[i].second.first) ans += p[i].second.second;
    }
    // cout << ans << '\n';
    mx = max(mx, ans);
}

void make(int i, vector<int> v) {
    if(i == n) {
        solve(v);
        return ;
    }
    int last = (int)v.size()?v.back():1;
    for(int j=last; j<=m; j++) {
        v.pb(j);
        make(i+1, v);
        v.pop_back();
    }
}

signed main() {
    cin >> n >> m >> q;
    int a, b, c, d;
    for(int i=0; i<q; i++) {
        cin >> a >> b >> c >> d;
        p[i] = {{a, b}, {c, d}};
    }
    vector<int> v;
    make(0, v);
    cout << mx << '\n';
    return 0;
}


Measured memory_bytes: 3636
import java.io.*;

class Researcher {
	int n;
	int c[] = {0,0,0};

	Researcher(int n) {
		this.n = n;
	}

	int Two() {
		while (this.n%2==0) {
			c[2]++;
			this.n /= 2;
		}
		return c[2];
	}

	int Five() {
		while (this.n%5==0) {
			c[1]++;
			this.n /= 5;
		}
		return c[1];
	}

	int Ten() {
		while (this.n%10==0) {
			c[0]++;
			this.n /= 10;
		}
		return c[0];
	}
}

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while ((buf = br.readLine()).equals("0")==false) {
				int c[] = {0,0,0};
				int n = Integer.parseInt(buf);
				for (int i=1;i<=n;i++) {
					Researcher r = new Researcher(i);
					c[0] += r.Ten();
					c[1] += r.Five();
					c[2] += r.Two();
				}
				System.out.println(c[0]+Math.min(c[1],c[2]));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 23144
s = raw_input()

ans = 100
for ci in range(97,123):
    c = chr(ci)
    ss = list(s)
    count = 0

    while len(ss) > 0:
      if all(c == cs for cs in ss):
        ans = min(ans, count)
        break

      ss_ = ss[:len(ss)-1:]
      for i in range(len(ss)-1):
        if ss[i+1] == c:
          ss_[i] = c
      ss = ss_
      count += 1

print ans


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

using namespace std;

const int M = 5005,N = 1005;

int dp[N][M];


vector<int> adj[N];

int X[N];

int mini[N];

void dfs(int root){


    int u,i,weight;

    int temp[M];
    for(i=0;i<=X[root];++i)
        dp[root][i] = 1e9;

    int j,w1,w2;
    dp[root][0]= 0;
    
    for(i=0;i<adj[root].size();++i){

        u = adj[root][i];

        dfs(u);
        w1= mini[u];
        w2 = X[u];
        
        for(j=0;j<=X[root];++j)
            temp[j] = 1e9;

        for(j=0;j<=X[root]-w1;++j){
            temp[j+w1]= min(temp[j+w1],dp[root][j]+ w2);
        }
        for(j=0;j<=X[root]-w2;++j){
            temp[j+w2] = min(temp[j+w2],dp[root][j]+w1);
        }
        for(j=0;j<=X[root];++j)
            dp[root][j]= temp[j];
    }

    int minx = 1e9;
    
    for(j=0;j<=X[root];++j)
        minx = min(minx,dp[root][j]);

    if(minx==1e9){
        printf("IMPOSSIBLE\n");
        exit(0);
    }
    mini[root] = minx;
}

int main(){
    int p,n,i;
    cin>>n;
    for(i=2;i<=n;++i){
        scanf("%d",&p);
        adj[p].push_back(i);
    }
    for(i=1;i<=n;++i)scanf("%d",&X[i]);

    dfs(1);
    cout<<"POSSIBLE\n";
}


Measured memory_bytes: 22784
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = []
d = []
for i in range(m):
    b, c = map(int, input().split())
    bc.append((b, c))
a.sort()
bc.sort(key=lambda x: x[1])
bc = bc[::-1]
cnt = 0
flg = False
for t in bc:
    for i in range(t[0]):
        d.append(t[1])
        cnt += 1
        if cnt == n:
            flg = True
            break
    if flg:
        break
for i, k in enumerate(d):
    if a[i] > k:
        i -= 1
        break
ans = sum(a[i + 1:] + d[:i + 1])
print(ans)

Measured memory_bytes: 23276
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxN 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e9+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
int32_t main()
{
fastio;
int n;in n;
out((n+2-1)/2)-1;
 return 0;
}


Measured memory_bytes: 256
h, w, k = map(int, input().split())
S = [list(input()) for i in range(h)]
A = []
cnt = 1
for i in range(h):
    Ai = []
    if S[i].count('#') == 0:
        A.append(Ai)
        continue
    flag = False
    for j in range(w):
        if S[i][j] == '#':
            if flag:
                cnt += 1
            flag = True
        Ai.append(cnt)
    A.append(Ai)
    cnt += 1

l = 0
for i in range(h):
    if A[i] != []:
        for j in range(l, i):
            A[j] = A[i]
        l = i + 1
for j in range(l, h):
    A[j] = A[l - 1]

for i in range(h):
    print(*A[i])


Measured memory_bytes: 8272
using System;
public class Hello{
    public static void Main(){
        var n = long.Parse(Console.ReadLine());
        var ans = n / 11 * 2;
        if(n % 11 != 0){
            ans += (n % 11 > 6) ? 2 : 1;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

// vector<int> par(0),depth(0),siz(0);
// void init(int n){
//     par.resize(n);
//     depth.resize(n,0);
//     siz.resize(n,1);
//     rep(i,n) par[i]=i;
// }
// int find(int n){
//     if(par[n]==n) return n;
//     return par[n]=find(par[n]);
// }
// void unite(int x,int y){
//     x=find(x);
//     y=find(y);
//     if(par[x]==par[y]) return;
//     siz[x]+=siz[y];
//     siz[y]=siz[x];
//     if(depth[x]<depth[y]) par[x]=par[y];
//     else{
//         par[y]=par[x];
//         if(depth[x]==depth[y]) depth[x] ++;
//     }
// }
// bool same(int x,int y){
//     return find(x)==find(y);
// }
// int size(int x){
//     return siz[find(x)];
// }

// struct union_find{
//     vector<int> par;
//     vector<int> depth;
//     vector<int> siz;

//     union_find(int n) : par(n) , depth(n,0) , siz(n,1){
//         rep(i,n) par[i]=i;
//     }

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

//     void unite(int x,int y){
//         x=find(x);
//         y=find(y);
//         if(x==y) return;
//         siz[x] +=siz[y];
//         siz[y] =siz[x];
//         if(depth[x]<depth[y]) par[x]=par[y];
//         else{
//             par[y]=par[x];
//             if(depth[x]==depth[y]) depth[x] ++;
//         }
//     }

//     bool same(int x,int y){
//         return find(x)==find(y);
//     }
//     int size(int x){
//         return siz[find(x)];
//     }
// };
struct union_find{
    vector<int> par;
    vector<int> depth;
    vector<int> siz;

    union_find(int n) : par(n) , depth(n,0) , siz(n,1){
        rep(i,n) par[i]=i;
    }

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

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        siz[x] +=siz[y];
        siz[y] =siz[x];
        if(depth[x]<depth[y]) par[x]=par[y];
        else{
            par[y]=par[x];
            if(depth[x]==depth[y]) depth[x] ++;
        }
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return siz[find(x)];
    }
};

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    int x,y,z;
    union_find uf(n);
    rep(i,m){
        cin>>x>>y>>z;
        x --,y --;
        uf.unite(x,y);
    }
    rep(i,n) uf.find(i);
    map<int,int> a;
    int cnt=0;
    rep(i,n){
        if(a[uf.par[i]]==1) continue;
        a[uf.par[i]]=1;
        cnt ++;
    }
    cout<<cnt<<endl;
}

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

int main()
{
    string s;
    cin>>s;
    if(s=="SUN")
     cout<<7<<"\n";
     else if(s=="MON")
      cout<<6<<"\n";
      else if(s=="TUE")
       cout<<5<<"\n";
       else if(s=="WED")
        cout<<4<<"\n";
        else if(s=="THU")
         cout<<3<<"\n";
         else if(s=="FRI")
          cout<<2<<"\n";
          else 
           cout<<1<<"\n";
           return 0;
}

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

using namespace std;

int rate[]={1, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200, 4900};

int main(){
        int flag[9];
        for(int i=0;i<9;i++){
                flag[i]=0;
        }
        int N;
        cin>>N;
        for(int i=0;i<N;i++){
                int rr;
                cin>>rr;
                for(int j=0;j<9;j++){
                        if(rr>=rate[j]&&rr<rate[j+1]){
                                flag[j]++;
                                break;
                        }
                }
                /*for(int j=0;j<9;j++){
                        cout<<j+1<<":"<<flag[j]<<endl;  
                }*/
        }
        int res=0;
        for(int i=0;i<8;i++){
                if(flag[i]>0)
                        res++;
        }
        if(res==0){
                cout<<1<<" "<<flag[8]<<endl;
        }
        else{
                cout<<res<<" "<<res+flag[8]<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;

int M;
int a[7];
int s, g;
int N[301];

bool isChecked[301];
vector<int> milestone[301];  //そのマスで出せばゴールにたどり着ける目を格納する

int iabs(int x){ return x >= 0 ? x : -x; }

bool search(int now){
	if (isChecked[now]){
		return false;
	}
	else if (now == g){
		return true;
	}

	isChecked[now] = true;
	for (int dice = 1; dice <= 6; dice++){
		if (now + a[dice] == g){
			milestone[now].push_back(a[dice]);
		}
		else if (now - a[dice] == g){
			milestone[now].push_back(-a[dice]);
		}
	}
	for (int dice = 1; dice <= 6; dice++){
		if (now + a[dice] <= M && search(now + a[dice] + N[now + a[dice]])){
			milestone[now].push_back(a[dice]);
		}
		if (now - a[dice] >= 1 && search(now - a[dice] + N[now - a[dice]])){
			milestone[now].push_back(-a[dice]);
		}
	}

	return milestone[now].size() > 0 ? true : false;
}

int main(){
	srand((unsigned int)time(NULL));
	cin >> M;
	for (int i = 1; i <= 6; i++){
		cin >> a[i];
	}
	cin >> s >> g;
	for (int i = 1; i <= M; i++){
		cin >> N[i];
	}
	bool canGoal = search(s);

	int now = s; //自分が今いるマスの番号
	for (;;){
		int dice;
		cin >> dice;

		bool found = false;
		for (vector<int>::iterator it = milestone[now].begin(); it != milestone[now].end(); it++){
			if (iabs(*it) == a[dice]){
				if (*it > 0){
					now = now + a[dice] + N[now + a[dice]];
					cout << 1 << endl;
				}
				else{
					now = now - a[dice] + N[now - a[dice]];
					cout << -1 << endl;
				}
				found = true;
				break;
			}
		}
		if(!found) cout << 0 << endl;
		cout.flush();

		if (now == g) return 0;
	}
	
	return 0;
}

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

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

using namespace std;

int main(void)
{
    string S;
    cin >> S;
    if(S == "AAA" || S == "BBB"){
        cout <<"No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int amd[1010][1010];

int main()
{
	while(1) {
		int n, m, a;
		cin >> n >> m >> a;
		if (!n && !m && !a) break;
		memset(amd, 0, sizeof(amd));
		int d = 0;
		rep(i,0,m) {
			int h, p, q;
			cin >> h >> p >> q;
			if (p > q) swap(p, q);
			amd[h][p] = 1;
			amd[h][q] = 2;
			d = max(d, h);
		}
		while(d) {
			//printf("n=%d a=%d amd[n][a]=%d\n",n,a,amd[n][a]);
			if (amd[d][a] == 1) a++;
			else if (amd[d][a] == 2) a--;
			d--;
		}
		cout << a << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5152
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
//*s.find_by_order(p)   returns the value of pth largest starting from 0 
//s.order_of_key(p)   returns no. of items that are strictly < p 
//string bin = bitset<64>(m).to_string();     convert decimal m to binary   
int main()
{
      fast;ll t;t=1;
      while(t--)
      {
            ll n,k,i,s=0;
            cin>>n>>k;
            ll x[n+2];
            for(i=0;i<n;i++){cin>>x[i];}
            sort(x,x+n);
            for(i=0;i<k;i++){
                  s=s+x[i];
            }
            cout<<s<<"\n";
      }
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x": " << x << endl;
inline int lowbit(int x) { return x & -x; }
typedef long long LL;
const int N = 1e4 + 10;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const int mod = 1e9 + 7;



int main() {
#ifdef purple_bro
    freopen("in.txt", "r", stdin);
#endif // purple_bro
    LL h, w;

    scanf("%lld%lld", &h, &w);

    LL ans = INF;

    for (int i = 1; i < h; i++) {
        LL t1 = w * i;
        LL t2 = (h - i) * (w / 2);
        LL t3 = (h - i) * w - t2;
        LL mi = min({t1, t2, t3});
        LL mx = max({t1, t2, t3});
        ans = min(ans, mx - mi);
        t2 = w * ((h - i) / 2);
        t3 = w * (h - i) - t2;
        mi = min({t1, t2, t3});
        mx = max({t1, t2, t3});
        ans = min(ans, mx - mi);
    }

    for (int i = 1; i < w; i++) {
        LL t1 = h * i;
        LL t2 = (w - i) * (h / 2);
        LL t3 = (w - i) * h - t2;
        LL mi = min({t1, t2, t3});
        LL mx = max({t1, t2, t3});
        ans = min(ans, mx - mi);
        t2 = h * ((w - i) / 2);
        t3 = h * (w - i) - t2;
        mi = min({t1, t2, t3});
        mx = max({t1, t2, t3});
        ans = min(ans, mx - mi);
    }

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

    return 0;
}


Measured memory_bytes: 256
l = input().split()
N = int(l[0])
K = int(l[1])
P = 0
for i in range(1,N+1):
    score = i 
    sub = K - score
    j = 0
    while sub > 0 :    
        score = score * 2
        j += 1
        sub = K - score
    p = 1/N * ((1/2)**j)
    P += p
print(P)

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

int cnt = 0;
void merge_sort(vector<int>& A, int left, int right){
    if (left >= right) return;
    int mid = (left + right) / 2;
    merge_sort(A, left   , mid  );
    merge_sort(A, mid + 1, right);
    int T[right - left + 1];
    int A1[mid - left + 2];
    int A2[right - mid + 1];
    for (int i = 0; i < mid - left + 1; i++) {
        A1[i] = A[left+i];
    }
    A1[mid - left + 1] = 1e9 + 1;
    for (int i = 0; i < right - mid; i++) {
        A2[i] = A[mid+1+i];
    }
    A2[right - mid] = 1e9 + 1;
    int i1 = 0;
    int i2 = 0;
    for (int k = 0; k < right - left + 1; k++) {
        cnt++;
        if (A1[i1] < A2[i2]) {
            T[k] = A1[i1++];
        } else {
            T[k] = A2[i2++];
        }
    }
    for (int i = 0; i < right - left + 1; i++) {
        A[left+i] = T[i];
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> S(n);
    for (auto& s : S) cin >> s;
    merge_sort(S, 0, n - 1);
    for (int i = 0; i < n; i++) {
        cout << S[i] << (i < n - 1 ? " " : "\n");
    }
    cout << cnt << endl;
    return 0;
}

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

int fun(char * day)
{
	int i,comp;
	char * s[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	for( i=0;i<7;i++)
	{
		comp=strcmp(s[i],day);
		if(comp==0) break;
	}
	return(7-i);
}
int main()
{
	int n;
    char s[4];
	cin>>s;	
	n=fun(s);
	cout<<n;
	return 0;
}

Measured memory_bytes: 256