akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

using int64 = long long;

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

    vector<int64> x(n);
    vector<int64> y(n);
    for (int i=0; i<n; i++) cin >> x[i] >> y[i];

    vector<int64> xv = x;
    vector<int64> yv = y;

    sort(xv.begin(), xv.end());
    sort(yv.begin(), yv.end());

    int64 ans = LONG_MAX;
    for (int xs=0; xs<n; xs++) {
        for (int xe=xs+1; xe<n; xe++) {
            for (int ys=0; ys<n; ys++) {
                for (int ye=ys+1; ye<n; ye++) {

                    int cnt = 0;
                    for (int i=0; i<n; i++) {
                        if (xv[xs] <= x[i] && x[i] <= xv[xe] && yv[ys] <= y[i] && y[i] <= yv[ye])
                            cnt++;
                    }
                    if (cnt >= k) {
                        ans = min(ans, (xv[xe] - xv[xs]) * (yv[ye] - yv[ys]));
                    }
              }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ms(a ,value) memset(a ,value,sizeof(a))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define N 20000000
class Triplet{
	public:
		int x , y , z;	
};
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int mod = 1e9+7;
vector <int> adj[N];
string str;
map <string,int> freq;
const double PI=3.1415926535897;
typedef long long int ll;

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	freq["AC"]=0;
  	freq["WA"]=0;
  	freq["TLE"]=0;
  	freq["RE"]=0;
	int t;
	cin>>t;
	while(t--){
		cin>>str;
		freq[str]++;
	}
	cout<<"AC x "<<freq["AC"]<<endl;
	cout<<"WA x "<<freq["WA"]<<endl;
	cout<<"TLE x "<<freq["TLE"]<<endl;
	cout<<"RE x "<<freq["RE"]<<endl;
	return 0;
}

Measured memory_bytes: 472388
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        String[] text = sc.next().split("", 0);
		int q = sc.nextInt();
		for(int i = 0; i < q; i++) {
			String msg = sc.next();
			int a = sc.nextInt();
			int b = sc.nextInt();

			int count = 0;
			if(msg.equals("replace")) {
				String[] str = sc.next().split("", 0);
				for(int y = a; y <= b; y++) {
					text[y] = str[count];
					count++;
				}
			}else if(msg.equals("reverse")) {
				String[] re = new String[b - a + 1];
				for(int j = b; j >= a; j--) {
					re[count] = text[j];
					count++;
				}
				count = 0;
				for(int x = a; x <= b; x++) {
					text[x] = re[count];
					count++;
				}
			}else {
				for(int y = a; y <= b; y++) {
					System.out.print(text[y]);
				}
				System.out.println();
			}
		}
	}
}



Measured memory_bytes: 33916
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <stack>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <set>
#include <functional>
#include <cstring>

using namespace std;

template<typename T> bool chmax( T &a, const T b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T b ) { if ( a > b ) { a = b; return ( true ); } else { return ( false ); } }

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair

#define F first
#define S second

#define popcnt __builtin_popcountll

#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
#define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i )
#define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }


int main()
{
	int h, w; cin >> h >> w;
	int ch, cw; cin >> ch >> cw;
	int dh, dw; cin >> dh >> dw;
	--ch; --cw; --dh; --dw;

	vector<string> s( h );
	rep( i, h ) cin >> s[i];

	const int cdh[] = { -1, 0, 1, 0 };
	const int cdw[] = { 0, -1, 0, 1 };
	constexpr int inf = 1e9;
	vector<vector<int>> cost( h, vector<int>( w, inf ) );
	cost[ch][cw] = 0;
	deque<Pint> dq;
	dq.push_front( mp( ch, cw ) );

	while ( dq.empty() == false )
	{
		auto x = dq.front(); dq.pop_front();
		rep( i, 4 )
		{
			ll nh = x.F + cdh[i];
			ll nw = x.S + cdw[i];
			if ( nh >= 0 && nw >= 0 && nh < h && nw < w )
			{
				if ( s[nh][nw] != '#' )
				{
					if ( chmin( cost[nh][nw], cost[x.F][x.S] ) )
						dq.push_front( mp( nh, nw ) );
				}
			}
		}

		// ワープ
		for ( int i = max( 0, x.F - 2 ); i < min( x.F + 3, h ); ++i )
		{
			for ( int j = max( 0, x.S - 2 ); j < min( x.S + 3, w ); ++j )
			{
				if ( s[i][j] != '#' )
				{
					if ( chmin( cost[i][j], cost[x.F][x.S] + 1 ) )
					{
						dq.push_back( mp( i, j ) );
					}
				}
			}
		}

#if 0
		static int cnt = 1;
		cout << "[ " << cnt++ << " ]" << endl;
		rep( i, h )
		{
			rep( j, w )
			{
				cout << cost[i][j] << " ";
			}
			cout << endl;
		}
#endif
	}

	if ( cost[dh][dw] < inf )
		cout << cost[dh][dw] << endl;
	else
		cout << -1 << endl;

	return ( 0 );
}


Measured memory_bytes: 8668
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return gcd( b, a % b );
}

ll lcm(ll a, ll b){//最小公倍数
    return a * b / gcd(a, b);
}


//入力

int main(){

    ll a, b, k;
    cin >> a >> b >> k;

    if(a >= k){
        cout << a - k << " " << b << endl;
    }
    else if(k <= a+b){
        cout << 0 << " " << b - (k - a) << endl;
    }
    else{
        cout << 0 << " " << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
s = input()

for i, si in enumerate(s):
    if i%2==0 and (si=="R" or si=="U" or si=="D"):
        pass
    elif i%2==1 and (si=="L" or si=="U" or si=="D"):
        pass
    else:
        print("No")
        break
else:
    print("Yes")



Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rint register int
#define rep(i,a,b) for (rint i=(a),_E=(b); i<=_E; ++i)
#define per(i,a,b) for (rint i=(a),_E=(b); i>=_E; --i)
#define REP(i,n) for (rint i=0,_E=(n); i<_E; ++i)
#define pb push_back
#define cmin(x,y) (y<x?x=y:0)
#define cmax(x,y) (y>x?x=y:0)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N = 100005;
int c[32], x, n, res, cnt, ans;

int main() {
	scanf("%d", &n);
	rep (i, 1, n) {
		scanf("%d", &x);
		res ^= x;
		cnt = 0;
		while (x && (x % 2 == 0))
			x >>= 1, ++ cnt;
		c[cnt] = 1;
	}
	per (i, 30, 0)
		if (res >> i & 1) {
			res ^= (1 << (i + 1)) - 1;
			++ ans;
			if (!c[i]) return puts("-1"), 0;
		}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
        
    return CONV()



sys.setrecursionlimit(200005)


def main():
    A,B,N = isRaw()
    
    if N<B:
        a1 = (A*N)//B
        return a1
    else:
        res = B-1
        a2 = (A*res)//B
        if A<=B:
            return max(a2,0)
        return max(a2, 0)
        
    
if __name__ == "__main__":
    print(main())


Measured memory_bytes: 67568
#include <cstdio>
#include <cstring>
#include <bitset>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
bitset<10010> dp[2010];
P vis[2][10010];
char s[2010][10010],ans[1000010];
int n,k;
int len[2010];

int main() {
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++) scanf("%s",s[i]),len[i]=strlen(s[i]);
    dp[n+1][0]=1;
    for (int i=n;i>=1;i--) 
        dp[i]=dp[i+1]|(dp[i+1]<<len[i]);
    int cnt=0;
    for (int i=1;i<=n;i++) 
        if (dp[i+1][k-len[i]]) vis[0][++cnt]=make_pair(i,0);

    int ii=0;
    for (int i=0;i<k;i++) {
        char minc='z';
        for (int j=1;j<=cnt;j++) minc=min(minc,s[vis[ii][j].first][vis[ii][j].second]);
        ans[i]=minc;
        
        int minid=n+1,ncnt=0;
        for (int j=1;j<=cnt;j++) {
            int nid=vis[ii][j].first,nlen=vis[ii][j].second;
            if (s[nid][nlen]!=minc) continue;
            if (nlen+1==len[nid]) minid=min(minid,nid);
            else vis[ii^1][++ncnt]=make_pair(nid,nlen+1);
        }
        for (int j=minid+1;j<=n;j++) {
            if (k-len[j]-i-1>=0 && dp[j+1][k-len[j]-i-1]) vis[ii^1][++ncnt]=make_pair(j,0);
        }
        ii^=1;
        cnt=ncnt;
    }
    printf("%s\n", ans);
    return 0;
}



Measured memory_bytes: 21888
N, D = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(N)]
ans = 0

for i in range(N):
    for j in range(i+1, N):
        distance = 0
        for c1,c2 in zip(points[i], points[j]):
            distance += (c1 - c2)**2

        if (distance**0.5).is_integer():
            ans += 1

print(ans)

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf=1e9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};	

int main(){
	string s,t,u;
	int a,b;
	cin>>s>>t>>a>>b>>u;

	if(s==u)a--;
	else b--;

	cout<<a<<" "<<b<<endl;


	return 0;
}



Measured memory_bytes: 256
if __name__ == '__main__':
    S = input()
    n = len(S)
    l_res = [0]
    r_res = [0]
    for i in range(n):
        if S[i] == '<':
            l_res.append(l_res[i] + 1)
        else:
            l_res.append(0)
    inv_S = S[::-1]

    for i in range(n):
        if inv_S[i] == '>':
            r_res.append(r_res[i] + 1)
        else:
            r_res.append(0)
    res = 0
    for l_cnt, r_cnt in zip(l_res, r_res[::-1]):
        res += max(l_cnt, r_cnt)
    print(res)
    

Measured memory_bytes: 37576
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      a: usize,
      b: usize,
    }
    let x = ((b-1) + (a-1) - 1) / (a-1);
    puts!("{}\n", x);
}


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

int main(){
  int p,q,r;
  cin>>p>>q>>r;
  int ans=min({p,q,r});
  if(ans==p) cout<<ans+min(q,r);
  else if(ans==q) cout<<ans+min(p,r);
  else cout<<ans+min(p,q);
}


Measured memory_bytes: 256
from collections import defaultdict

S = input()
T = input()

s_dic = defaultdict(list)
t_dic = defaultdict(list)


for i, ch in enumerate(S):
    s_dic[ch].append(i)

for i, ch in enumerate(T):
    t_dic[ch].append(i)

lis_s = list(s_dic.values())
lis_t = list(t_dic.values())

for i in range(len(lis_s)):
    if lis_s[i] != lis_t[i]:
        print("No")
        exit()
print("Yes") 

Measured memory_bytes: 80608
#include <stdio.h>

int main(){
	int n,x,count;
	while(true){
		scanf("%d %d",&n,&x);
		if(n == 0 && x == 0) break;
		count = 0;
		for(int min = 1; min < x/3 && min <= n-2;min++){
			for(int middle = min+1;middle < x - (min+middle) && middle <= n-1; middle++){
				if(x-(min+middle) <= n) count++;
			}
		}
		printf("%d\n",count);
	}

}



Measured memory_bytes: 2732
#include <cstdio>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V=max(V,T)
typedef long long ll;
typedef long double ld;
int A,B,Q;
ll As[100000];
ll Bs[100000];
ll INF=(ll)1000*1000*1000*1000;
ll min(ll a, ll b) {
  return a>b? b:a;
}
ll abs(ll a) {
  return a>0?a:-a;
}
ll* lower_bound(ll* a, ll* b, ll v){
  while(b>a+1) {
    ll* m=a+(b-a)/2;
    if(*m >= v) {
      b=m;
    } else {
      a=m;
    }
  }
  return b;
}
ll fastGet() {
  ll ret=0;
  char c=getchar_unlocked();
  // skipping
  while(c<'0' || c > '9') c=getchar_unlocked();
  do {
    ret *= 10;
    ret += (c-'0');
    c = getchar_unlocked();
  } while(c>='0' && c<='9');
  return ret;
}
void fastPut(ll v) {
  char s[256];
  int p=0;
  do {
    s[p++]=(v%10)+'0';
    v/=10;
  } while(v>0);
  while(p--)
    putchar_unlocked(s[p]);
}
int main() {
  A=fastGet();
  B=fastGet();
  Q=fastGet();
  REP(i,A)
    As[i]=fastGet();
  REP(i,B)
    Bs[i]=fastGet();
  REP(i,Q) {
    ll x=fastGet();
    ll* ita=lower_bound(As, As+A, x);
    ll* itb=lower_bound(Bs, Bs+B, x);
    ll ans=INF;
    ll alis[2],blis[2];
    alis[0]=ita!=As+A?*ita:INF;
    blis[0]=itb!=Bs+B?*itb:INF;
    alis[1]=ita!=As?ita[-1]:-INF;
    blis[1]=itb!=Bs?itb[-1]:-INF;
    REP(j,2)
      REP(k,2){
        ll a=alis[j],b=blis[k];
        ans = min(ans,abs(a-x)+abs(b-a));
        ans = min(ans,abs(b-x)+abs(b-a));
      }
    fastPut(ans);
    putchar_unlocked('\n');
  }
  return 0;
}


Measured memory_bytes: 2944
#include <cstdio>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;

typedef pair<int, int> Pair;

vector<Pair> ps;
map<int, int> rank_table;

int main() {
  while (1) {
    int a, b;
    scanf("%d,%d", &a, &b);
    if (a == 0 && b == 0) break;

    ps.push_back(Pair(b, a));
  }
  sort(ps.begin(), ps.end(), greater<Pair>());

  int cur_rank = 0;
  int prev_score = -1;
  for (int i=0; i<ps.size(); i++) {
    if (ps[i].first != prev_score) {
      ++cur_rank;
    }

    rank_table[ps[i].second] = cur_rank;
    prev_score = ps[i].first;
  }

  while (1) {
    int q;
    if (scanf("%d", &q) != 1) return 0;

    printf("%d\n", rank_table[q]);
  }
}

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

char s[200010];
int dp[200010][2];
int n;

int main(){
	scanf("%s", s), n = strlen(s);
	memset(dp, -1, sizeof(dp));
	dp[1][0] = 1, dp[2][1] = 1;
	for (int i = 0; i < n; i++) {
		for (int p = 0; p < 2; p++) {
			if (dp[i][p] == -1) continue;
			if (p == 0) {
				dp[i + 2][1] = max(dp[i + 2][1], dp[i][0] + 1);
				if (s[i] != s[i - 1]) dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + 1);
			} else {
				dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + 1);
				if (s[i] != s[i - 2] || s[i + 1] != s[i - 1]) dp[i + 2][1] = max(dp[i + 2][1], dp[i][1] + 1);
			}
		}
	}
	printf("%d\n", max(dp[n][0], dp[n][1]));
	return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>A;//きゅー
int main(void)
{
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	if (B / A >= C) {
		printf("%d", C);
		return 0;
	}
	printf("%d", B / A);
	return 0;

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "DataStructure.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
using namespace std;
typedef pair<int, int> p;
const int INF = 1000000000;
int main(){
	int n; cin >> n;
	for (int k = 0; k < n; k++) {
		char s[1000], t[1000];
		scanf("%s",&s); scanf("%s", &t);
		int i = 0, j = 0;
		int dp[1001][1001];
		fill(dp[0], dp[1001], 0);
		int res = 0;
		while (s[i] != '\0'){
			while (t[j] != '\0') 
			{
				if (s[i] == t[j])dp[i + 1][j + 1] = dp[i][j] + 1;
				else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
				res = dp[i + 1][j + 1];
				//cout << "i " << i << "j " << j << endl;
				//cout << "dp" << dp[i + 1][j + 1] << endl;
				j++;
			}
			i++;
			j = 0;
		}

		cout << res << endl;
	}
	return 0;
}

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

int gcd(int A,int B){
  if(B>A)swap(A,B);
  if(B==0)return A;
  return gcd(B,A%B);
}

int main(){
  ll N,M;
  cin >> N >> M;
  vector<pair<ll,ll>>AB(N);
  for(int i=0;i<N;i++){
    int a,b;
    cin >> a >> b;
    AB.at(i)=make_pair(a,b);
  }
  sort(AB.begin(),AB.end());
  ll ans=0;
  for(int i=0;i<N;i++){
    ll cnt=min(M,AB[i].second);
    ans+=AB[i].first*cnt;
    M-=cnt;
  }
  cout << ans << endl;
  
}
  
  

Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>

using namespace std;

void change(int *, int *);

int main(void)
{
	int x, y;
	
	while(scanf("%d %d", &x, &y) != EOF){
		if(x == 0 && y == 0)
		break;
		if(x < y)
			change(&x, &y);
		while(y){
			x %= y;
			change(&x, &y);
		}
		cout << x << endl;
	}
	return 0;
}

void change(int *a, int *b)
{
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
	
}

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

using namespace std;

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

    int ans = -1;
    double min_diff = 1000000000;
    for (int i = 0; i < N; i++) {
        double temp = T - H[i] * 0.006;
        
        double diff = temp - A;
        if (diff < 0) {
            diff *= -1;
        }

        if (diff < min_diff) {
            ans = i;
            min_diff = diff;
        }
    }

    cout << ans + 1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		String st;
		boolean first, second, third;
		int out, score;
		
		n = sc.nextInt();
		first = false;
		second = false;
		third = false;
		out = 0;
		score = 0;
		while (sc.hasNext()) {
			st = sc.next();
			if (st.equals("HIT")) {
				if (third) {
					score++;
				}
				third = second;
				second = first;
				first  =true;
			} else if (st.equals("HOMERUN")) {
				if (first) {
					score++;
					first = false;
				}
				if (second) {
					score++;
					second = false;
				}
				if (third) {
					score++;
					third = false;
				}
				score++;
			} else if (st.equals("OUT")) {
				out++;
				if (out == 3) {
					System.out.println(score);
					out = 0;
					score = 0;
					first = false;
					second = false;
					third = false;
				}
			}
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <math.h>
#define N 1000000

int n, s[N], x=0;

void merge(int, int, int);
void mergeSort(int, int);
int main()
{
  int i;
  
  scanf("%d",&n);
  
  for(i=0; i<n; i++)
    scanf("%d",&s[i]);

  mergeSort(0,n);

  for(i=0;i<n;i++){
    printf("%d", s[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n%d\n", x);
  
  return 0;
}

void merge(int left, int mid, int right)
{
  int n1, n2, i, j, k, L[N], R[N];
  n1 = mid - left;
  n2 = right - mid;
  for(i=0; i<=n1-1; i++)
    L[i] = s[left + i];
  for(i=0; i<=n2-1; i++)
    R[i] = s[mid + i];
  L[n1] = INFINITY;
  R[n2] = INFINITY;
  i = 0;
  j = 0;
  for(k=left; k<=right-1; k++)
    if(L[i] <= R[j]){
      s[k] = L[i];
      i = i + 1;
      x++;
    } else {
      s[k] = R[j];
      j = j + 1;
      x++;
    }
}
void mergeSort(int left, int right)
{
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

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

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define MAXN 100013
#define INF 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N;
pii arr[MAXN];
int val[MAXN];
vi guys[MAXN];
bitset<MAXN> vis;

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    FOR(i, 0, N)
    {
        cin >> arr[i].se; arr[i].se = -arr[i].se;
    }
    FOR(i, 0, N)
    {
        cin >> arr[i].fi; arr[i].fi = -arr[i].fi;
    }
    sort(arr, arr + N);
    //ai.se >= bi.se
    FOR(i, 0, N)
    {
        val[i] = UB(arr, arr + N, MP(arr[i].se, INF)) - arr - 1;
        if (val[i] < 0)
        {
            cout << "No\n";
            return 0;
        }
        guys[val[i]].PB(i);
    }
    int tot = 0;
    FOR(i, 0, N)
    {
        tot += SZ(guys[i]);
        if (tot > i + 1)
        {
            cout << "No\n";
            return 0;
        }
    }
    FOR(i, 0, N)
    {
        if (guys[i].empty())
        {
            cout << "Yes\n";
            return 0;
        }
    }
    int u = 0;
    FOR(i, 0, N)
    {
        vis[u] = true;
        u = guys[u][0];
    }
    FOR(i, 0, N)
    {
        if (!vis[i])
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
    //i can go to [0...val[i]].
    //if there's only one guy that can go to 0, we assign it.
    //you can permute the arr[i].se in any order that's not a cycle. can you get all ai < bi?
}


Measured memory_bytes: 6912
#include <stdio.h>

int main(void){
  int n,i,j;
  int p[n];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
 
  j=0;
  for(i=0;i<n-2;i++){
    if(p[i]<=p[i+1] && p[i+1]<p[i+2]){
      j=j+1;
    }
    else if(p[i]>p[i+1] && p[i+1]>=p[i+2]){
      j=j+1;
    }
  }
  printf("%d",j);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

int main()
{
	int n, k; cin >> n >> k;
	co(n - k + 1);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string w, beau = "Yes";
	cin >> w;
	for(char c = 'a';c <= 'z';c++){
		int cnt = 0;
		REP(i, w.size()){
			if(c == w[i]) cnt++; 
		}
		if(cnt % 2 != 0) beau = "No";
	}
	cout << beau << endl;

	rtn 0;
}

Measured memory_bytes: 256
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    from math import floor
    a,b,n=MI()
    if b>n:
        ans = floor((a*n)/b)
        print(ans)
    else:
        ans = floor((a*(b-1)/b))
        print(ans)
        # for i in range(1,n+1):
        #     ans = floor((a*i)/b)-a*floor((i)/b)
        #     print(ans,i)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9620
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
int n;
V<int> e[N];
int dfs(int a, int p){
  int ret = 0, z = 0;
  for(int b:e[a]) if(b!=p){
    int t = dfs(b, a);
    z += !t;
    ret += t;
  }
  return ret + max(0, z-1);
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n-1){
    int a, b;
    cin >> a >> b;
    e[a].pb(b);
    e[b].pb(a);
  }
  int s, c=0;
  if(n==2){
    cout << 1 << endl;
    return 0;
  }
  FOR(i, 0, n) if(sz(e[i])>c){
    s = i;
    c = sz(e[i]);
  }
  cout << dfs(s, -1) << endl;
}

Measured memory_bytes: 11904
#include <iostream>
#include <iomanip>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<map<int, int>> edges(N);
    for (int i = 0; i < N - 1; ++i)
    {
        int u, v, w;
        cin >> u >> v >> w;
        edges[u - 1][v - 1] = w;
        edges[v - 1][u - 1] = w;
    }

    // ID=0から各頂点までの距離を求める
    vector<int> distances(N);
    map<int, bool> passedMap;
    for (int i = 0; i < N; ++i)
    {
        passedMap[i] = false;
    }
    passedMap[0] = true;
    distances[0] = 0;
    deque<int> stack{ 0 };
    for (;;)
    {
        if (stack.empty())
        {
            break;
        }
        int key = stack.back();
        stack.pop_back();
        int distToKey = distances[key];
        for (const auto &neighborEdges : edges[key])
        {
            const int neighborID = neighborEdges.first;
            if (passedMap[neighborID] == false)
            {
                passedMap[neighborID] = true;
                distances[neighborID] = distToKey + neighborEdges.second;
                stack.push_back(neighborID);
            }
        }
    }

    // ID=0からの距離が偶数のもののみ，ID=0と同じ色（０）で塗る
    for (int i = 0; i < N; ++i)
    {
        if (distances[i] % 2 == 0)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << 1 << endl;
        }
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 200100;

int f[N];
map<ll, int> mp;

void add(int pos) {
    for (; pos < N; pos |= pos + 1) {
        ++f[pos];
    }
}

int get(int pos) {
    int s = 0;
    for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
        s += f[pos];
    }
    return s;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] -= k;
    }
    vector<ll> s(n + 1), t(n + 1);
    for (int i = 1; i <= n; ++i) {
        s[i] = s[i - 1] + a[i - 1];
        t[i] = s[i];
    }
    sort(t.begin(), t.end());
    int it = 0;
    for (int i = 0; i <= n; ++i) {
        if (!mp.count(t[i])) {
            mp[t[i]] = it++;
        }
    }
    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans += get(mp[s[i]]);
        add(mp[s[i]]);
    }
    cout << ans;
    return 0;
}

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


int main() {
  int N,M,a,b;
  cin >> N >> M;
  vector<vector<int>> ab(M,vector<int>(2));
  rep(i,M) {
    cin >> a >> b;
    a--;b--;
    ab[i] = {a,b};
  }
  sort(ab.begin(),ab.end());
  int cnt=0,now=-1;
  rep(i,M) {
    if (now<=ab[i][0]) {
      cnt++;
      now = ab[i][1];
    }
    else if (ab[i][1]<now) now = ab[i][1];

  }
  cout << cnt << endl;
}

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

int main(){
    string s;
    cin>>s;
    if(s[0]==s[s.size()-1]) cout<<(s.size()%2 ? "Second" : "First")<<endl;
    else cout<<(s.size()%2 ? "First":"Second")<<endl;

    return 0;
}


Measured memory_bytes: 512
from fractions import gcd
A, B = map(int, input().split())
G = gcd(A, B)

# nの[素因数, その数]のリストを返す
def prime_factoring(n):
    from math import sqrt
    factors = []
    for num in range(2, int(sqrt(n))+1):
        if n % num == 0:
            count = 0
            while(n % num == 0):
                n //= num
                count += 1
            factors.append([num, count])
    else:
        if n != 1:
            factors.append(n)
    return factors

print(len(prime_factoring(G))+1)


Measured memory_bytes: 64108
// C - Slimes
#include <stdio.h>
#include <string.h>

int main(void){
    int i, j, n, cnt=0;
    char s[100010], c;
    scanf("%d%s", &n, s);
    for(i=0; i<n; i++){
        if(s[i]!=s[i+1]){cnt++;}
    }
    printf("%d\n", cnt);
    return 0;
}

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

int main() {
	int a, b, c, d, e;
	scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
	int ans = 0;
	if(a < 0){
		ans -= c * a - d;
		a = 0;
	}
	ans += (b - a)*e;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3220
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
 
 
int main(void){
    int n;
    string s;
    cin>>n>>s;
    map<int,char>q;
    map<char,int>m;
    int index=0;
    int a=0;
    for(char i='A';i<='Z';i++)q[index++]=i;
    for(char i='A';i<='Z';i++)m[i]=a++;
    for(int i=0;i<s.length();i++){
        cout<<q[(m[s[i]]+n)%26];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	 int n;
  cin >> n;
  int ren = 0;
  for(int i=0;i<n;++i)				 {
    int a, b;
    cin >> a >> b;
    if (a == b) ++ren;
    else ren = 0;
    if (ren == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I,N) for(i8t I=0,I##_N=N;I<I##_N;I++)
#define FR(I,N) for(i8t I=N;I--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
int main() {
  R(X);
  u8t a=100;
  for(int i = 0;i<30000;i++){
    a = a+a/100;
    if (a>=X){
      P(i+1);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void arc_be_together(void) {
	int n;
	int a_cnt[210] = { 0 };
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int pos = a[i] + 100;
		a_cnt[pos]++;
	}
	
	sort(a.begin(), a.end());
	int min = a[0];
	int max = a[n - 1];

	int cost_min = 1000000;
	int cost = 0;
	for (int y = min; y <= max; y++) {
		cost = 0;
		for (int i = 0; i < n; i++) {
			int diff = a[i] - y;
			cost += (diff * diff);
		}
		if (cost < cost_min) cost_min = cost;
	}

	cout << cost_min << endl;
}

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

Measured memory_bytes: 3588
#include<bits/stdc++.h>
    #define ll long long
    #define db double
    #define mod 1000000007
    #define pb push_back
    #define pp pair<ll,ll>
    #define rep(i,a,b) for(ll i=a;i<b;i++)
    #define repe(i,a,b) for(ll i=a;i<=b;i++)
    #define repr(i,a,b) for(ll i=b;i>=a;i--)
    #define maxn 200005
    #define ss second
    #define ff first
    #define lb lower_bound
    using namespace std;
    void solve()
    {
        string str;
        cin >> str;
        if(str == "ABC")
            cout << "ARC";
        else cout << "ABC";
    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll t=1;
        //cin >> t;
        while(t--)
        solve();
        return 0;
    }

Measured memory_bytes: 3648
#include <stdio.h>

int main(void) {
int S[100][2];
int n;
int i=0;
int cnt=0;

    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d %d", &S[i][0], &S[i][1]);

    for(i=0; i<n; i++){
        if(S[i][0]==S[i][1]) cnt++; 
        else                 cnt=0;
        if(cnt==3)          break;
    }
    if(cnt==3) printf("Yes");
    else       printf("No");    
    return 0;
}

Measured memory_bytes: 2156
#include<bits/stdc++.h>
#include<utility>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>>dem(M);
  for (int i = 0; i < M; i ++) {
    int a, b;
    cin >> a >> b;
    if (a < b) swap(a, b);
    dem[i] = make_pair(a, b);
  }
  sort(dem.begin(), dem.end());
  int ans = 1;
  int j = dem[0].first - 1;
  for (int i = 0; i < M; i ++) {
    if (j < dem[i].second) {
      j = dem[i].first - 1;
      ans ++;
    }
  }
  cout << ans << endl;
}
  


Measured memory_bytes: 1024
class UnionFind:
    def __init__(self, n):
        self.depth  = [0] * n
        self.parent = list(range(n))

    def find(self, x):
        if x == self.parent[x]:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.depth[x] < self.depth[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.depth[x] == self.depth[y]:
                self.depth[x] += 1

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

    def size(self, x):
        return self.depth[self.ind(x)]


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

T = UnionFind(N)

for m in range(M):
    X, Y, Z  = map(int, input().split())
    T.unite(X-1, Y-1)

print(sum([1 for i in range(N) if T.find(i) == i]))


Measured memory_bytes: 8624
#include<stdio.h>

int main()
{
	int n[50];
	int x;
	scanf("%d",&x);
	for(int i=0;i<x;i++){
	scanf("%d",&n[i]);
	}
	int s=0;
	for(int i=0;i<x;i++){
	 for(int j=i+1;j<x;j++){
	     s+=n[i]*n[j];
	 }
	}
	printf("%d",s);
	return 0;
}

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

int fact(int n) {
  int ret = 1;
  while (n > 1) {
    ret *= n;
    n--;
  }
  return ret;
}

int main() {
  int n, a = 0, b = 0, count = 0;
  bool flag;
  cin >> n;
  vector<int> P(n), Q(n), T(n);
  vector<vector<int>> vec;
  for (int i = 0; i < n; i++) cin >> P.at(i);
  for (int i = 0; i < n; i++) cin >> Q.at(i);
  for (int i = 0; i < n; i++) T.at(i) = i+1;

  do {
    count++;
    flag = true;
    for (int i = 0; i < n; i++) {
      if (T.at(i) != P.at(i)) {
        flag = false;
        break;
      }
    }
    if (flag) a = count;
    
    flag = true;
    for (int i = 0; i < n; i++) {
      if (T.at(i) != Q.at(i)) {
        flag = false;
        break;
      }
    }
    if (flag) b = count;
  } while(next_permutation(T.begin(), T.end()));
  
  cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define re register
using namespace std;
struct ios{
	template <typename ty> inline ios& operator >> (ty &x)
	{
		register int f=1;x=0;register char c=getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
		for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
		x*=f;return *this;
	}
	template <typename ty>  inline ios& operator << (ty x)
	{
		if(x<0) x=-x,putchar('-');
		if(x>9) *this << x/10;
		putchar(x%10+48);
		return *this;
	}
	inline ios& operator << (char c){putchar(c);return *this;}
}io;
int a,b,c,n;
int main()
{
	io >> n;
	if(n<10)
	{
		io << n;return 0;
	}
	if(n>=10 && n<100)
	{
		io << 9;return 0;
	}
	if(n>=100 && n<1000)
	{
		io << 9+n-100+1;return 0;
	}
	if(n>=1000 && n<10000)
	{
		io << 909;return 0;
	}
	if(n>=10000 && n<100000)
	{
		io << 909+n-10000+1;return 0;
	}
	if(n==100000) 
	{
		io << 90909;return 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;
int main(){
    string str;
    cin >> str;
    if(str[0] != 'A'){
        cout << "WA";
        return 0;
    }
    llint x = 0;
    for(llint i = 2;i < str.size()-1;i++){
        if(str[i] == 'C')
            x++;
    }
    if(x != 1){
        cout << "WA";
        return 0;
    }
    x = 2;
    for(llint i = 0;i < str.size();i++){
        if(str[i] >= 'A' && str[i] <= 'Z')
            x--;
    }
    if(x != 0){
        cout << "WA";
        return 0;
    }
        cout << "AC";
        return 0;
}

Measured memory_bytes: 256
n=gets.to_i
w=Array.new(n)
n.times do |i|
    w[i]=gets.chomp
end

n.times do |i|
    if w.count(w[i])>1
        puts "No"
        return
    end
end

(n-1).times do |i|
    if w[i].reverse[0]!=w[i+1][0]
        puts "No"
        return
    end
end

puts "Yes"


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

typedef long long ll;
const int N = 200054;
constexpr long double phi = 0.61803398874989484820458683436564l,
	hz = 0.49723029647758477079258462177973l, lz = phi;

int n, T;
int f[N];
ll ans[N];
char s[N];

ll phi_n(ll n) {
	unsigned int hi = n >> 32, lo = n & 0xffffffff;
	return 2654435769ll * hi + floorl(hi * hz + lo * lz);
}

void solve(ll x, int coef) {
	int i, u = T, v = n - T;
	if (n % T) {
		ll p, Lu = -1, Lv = -1, Cu, Cv, estimate = x / (u * phi + v * (1 - phi));
		for (p = std::max<ll>(estimate - 100, 1); ; ++p) {
			Cu = phi_n(p), Cv = p - 1 - Cu;
			if (u * Cu + v * Cv > x) break;
			Lu = Cu, Lv = Cv;
		}
		assert(~Lu && ~Lv);
		for (i = 0; i < u; ++i) ans[s[i]] += Lu * coef;
		for (i = 0; i < v; ++i) ans[s[i]] += Lv * coef;
		p = x - (u * Lu + v * Lv);
		for (i = 0; i < p; ++i) ans[s[i]] += coef;
	} else {
		lldiv_t info = lldiv(x, T);
		for (i = 0; i < T; ++i) ans[s[i]] += info.quot * coef;
		for (i = 0; i < info.rem; ++i) ans[s[i]] += coef;
	}
}

int main() {
	int i, j = 0; ll l, r;
	scanf("%s%lld%lld", s, &l, &r), s[n = strlen(s) / 2] = 0;
	for (j = *f = -1, i = 0; i < n; f[++i] = ++j)
		for (; ~j && s[j] != s[i]; j = f[j]);
	T = n - f[n];
	solve(r, 1), solve(l - 1, -1);
	for (i = 97; i < 123; ++i) printf("%lld%c", ans[i], i == 122 ? 10 : 32);
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<math.h>
int main()
{
    long long int n,d,x,y,s=0;
    scanf("%lld %lld",&n,&d);
    double z,m;
    m=d*1.00;
    while(n--)
    {
        scanf("%lld %lld",&x,&y);
        x=x>0?x:-x;
        y=y>0?y:-y;

        z=x*x+y*y;

        z=sqrt(z);
        if(z<=m) s++;
    }
    printf("%lld",s);
    return 0;
}


Measured memory_bytes: 2116
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define sort_u(x) sort((x).begin(),(x).end())
#define sort_d(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
//#define INF ((1LL<<62)-(1LL<<31))  // 浮動小数点型
#define bit(n,m)(((n)>>(m))&1)  // nのmビット目が1
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main() {
    int h, w; cin >> h >> w;
    int si, sj; cin >> si >> sj;
    int gi, gj; cin >> gi >> gj;
    si--; sj--; gi--; gj--;
    
    string maze[h];
    rep(i, h) cin >> maze[i];
    int dist[h][w];
    const int di[4] = {-1,0,1,0}, dj[4] = {0,1,0,-1};
    const int INF = 1e9;
    rep(i,h) rep(j,w) dist[i][j] = INF;

    deque<P> q;
    q.emplace_back(si,sj);
    dist[si][sj] = 0;

    while(!q.empty()){
        int i = q.front().first;
        int j = q.front().second;
        q.pop_front();
        int d = dist[i][j];

        rep(v,4){
            int ni = i + di[v];
            int nj = j + dj[v];
            if(ni < 0 || ni >= h || nj < 0 || nj >= w || maze[ni][nj]=='#' || dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni, nj);
        }
        rep(mi,5) rep(mj,5){
            int ni = i + mi - 2;
            int nj = j + mj - 2;
            if(ni < 0 || ni >= h || nj < 0 || nj >= w || maze[ni][nj]=='#' || dist[ni][nj] <= d+1) continue;
            dist[ni][nj] = d + 1;
            q.emplace_back(ni, nj);
        }
    }

    int ans = dist[gi][gj];
    if(ans == INF) ans = -1;
    cout << ans << endl;
}
/*
g++ d.cpp
./a.out

g++ d.cpp
oj d
oj t
*/


Measured memory_bytes: 9376
package main
import(
  "fmt"
)
func main(){
   var s, t, temp string
   var i int
   fmt.Scan(&s, &t)
   for i=0;i<len(s);i++{
     temp=string(s[0])
     s=s[1:]
     s+=temp
     if s==t{
       fmt.Println("Yes")
       return
     }
   }
   fmt.Println("No")
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<int,int> P;
int main(void) {
    int n, m; cin >> n >> m;
    vector<P> pos;
    rep(i, m) {
        int L, R; cin >> L >> R;
        pos.push_back({L,0});
        pos.push_back({R,1});
    }
    sort(pos.begin(),pos.end());
    /*rep(i, 2*m) {
        printf("%d %d\n",pos[i].first,pos[i].second);
    }*/
    bool flag = true;
    rep(i, m) {
        if(pos[i].second){
            flag = false;
            break;
        }
    }
    if(!flag) cout << 0;
    else cout << pos[m].first - pos[m-1].first + 1;
}


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

int main(){

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

	int min_sum=20000;

	for(int i=0;i<=p[0];i++){
		int q[5000];
		for(int j=0;j<N;j++){
			q[j]=p[j];
		}
		int sum=i;
		q[0]-=i;
		
		for(int j=0;j<=N-2;j++){
			if(q[j]<=0)
				continue;
			sum +=q[j]*2;
			q[j+1] -=q[j];
		}
		if(q[N-1]>0){
			sum +=q[N-1];
		}

		min_sum=min(min_sum,sum);
	}

	cout<<min_sum<<endl;
	
	return 0;
}

Measured memory_bytes: 3140