akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;

int main(){
	int n, T, L;
	int t[100], h[100];
	
	scanf("%d%d%*d%d", &n, &T, &L);
	for(int i = 0; i < n; ++i){
		scanf("%d%d", &t[i], &h[i]);
	}
	
	int x = 0;
	int p;
	for(p = 0; ; p = (p + 1) % n){
		if( t[p] ){
			--t[p];
			++T;
			++x;
			
			if( T > L ){
				break;
			}
		}
		else if( h[p] ){
			--h[p];
			x += 10;
		}
		else{	break;	}
		
		if( x >= 9 ){
			if( x - 9 > T ){	break;	}
			t[p] += x - 9;
			T -= x - 9;
			x = 0;
		}
	}
	printf("%d\n", p + 1);
}

Measured memory_bytes: 1028
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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)*}
    };
}

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

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

fn main() {
    input!{
        n: usize,
        xyh: [(i64, i64, i64); n],
    }

    for cx in 0..101 {
        for cy in 0..101 {
            // 高さが0より大きい位置を見つけ出してあたりを中心の高さにあたりをつける
            // なければ無理!
            let &(x, y, h) = xyh.iter()
                .filter(|&&(_, _, h)| h > 0)
                .nth(0)
                .unwrap()
                ;

            let ch = h + (x - cx).abs() + (y - cy).abs();

            let mut clear = true;
            for &(x, y, h) in &xyh {
                if h != std::cmp::max(ch - (x - cx).abs() - (y - cy).abs(), 0) {
                    clear = false;
                    break;
                }
            }

            if clear {
                println!("{} {} {}", cx, cy, ch);
            }
        }
    }
}


Measured memory_bytes: 4352
var x,y,ans:int64;

begin
ans:=0;
read(x,y);
if x = 1 then ans:=ans+300000;
if x = 2 then ans:=ans+200000;
if x = 3 then ans:=ans+100000;
if y = 1 then ans:=ans+300000;
if y = 2 then ans:=ans+200000;
if y = 3 then ans:=ans+100000;
if(x=1)and(y=1)then ans:=ans+400000;
write(ans)
end.

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 3000000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}

vector<ll> A, B, S, T;

int main() {
    ll N, M, K;
    cin >> N >> M >> K;

    A.assign(N, 0);
    S.assign(N+1, 0);
    B.assign(M, 0);
    T.assign(M+1, 0);
    ll thresh_A = -1, thresh_B = -1;
    for(ll i = 0; i < N; i++) {
        cin >> A[i];
        S[i+1] = S[i] + A[i];
        if(S[i+1] > K &&thresh_A == -1) thresh_A = i;
    }
    if(thresh_A == -1) thresh_A = N;
    for(ll i = 0; i < M; i++) {
        cin >> B[i];
        T[i+1] = T[i] + B[i];
        if(S[thresh_A] + T[i+1] > K &&thresh_B == -1) thresh_B = i;
    }
    if(thresh_B == -1) thresh_B = M;

    //cout << thresh_A << "," << thresh_B << endl;

    ll count = 0;
    // A取る冊数
    for(ll i = thresh_A; i >= 0; i--) {
        for(ll j = thresh_B; j <= M; j++) {
            if(S[i] + T[j] <= K) thresh_B = j;
            if(S[i] + T[j] > K) break;
            count = max(count, i + j);
        }
    }   


    cout << count << endl;
    return 0;    
}



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


int main() {
 #define int long long
  int A,B,C,N,b,x,s;
  
  cin >> N;
  vector<int>D(N);
  vector<int>a;
  
  for(int i=0;i<N;i++){
    cin >> D.at(i);
  }
  x=D.at(0);
  std::sort(D.begin(),D.end());
  
  b=1;
  for(int i=1;i<N;i++){
    if(D.at(i)==D.at(i-1)){
      b++;
    }else if(D.at(i)==(D.at(i-1)+1)){
      a.push_back(b);
      b=1;
    }else{
      x=1;
      break;
    }
  }
  a.push_back(b);
  s=a.size();
  vector<int>c(s);
  c.at(0)=1;
  for(int i=1;i<(s);i++){
    c.at(i)=1;
    for(int j=0;j<a.at(i);j++){
      c.at(i)*=a.at(i-1);
      c.at(i)=c.at(i)%(998244353);
    }
  }
  A=1;
  for(int i=0;i<s;i++){
    A=A*c.at(i);
    A=A%(998244353);
  }
  if((x!=0)||(a.at(0)!=1)){
    A=0;
  }
  B=A%(998244353);
  
cout << B << endl;

}








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

int main() {
	int H, W, h, w;
	int black, white, all;
	int output;
	cin >> H >> W;
	cin >> h >> w;
	all = H * W;
	black = H * w + h * (W - w);
	white = all - black;
	cout << white << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string>

using namespace std;

int main(void)
{
	string w;
	cin >> w;
	int i, j;
	int flag = 0;
	int count = 0;
	for (i = 0; w[i]!='\0'; i++)
	{
		count = 0;
		for (j = 0; j < w[j]!='\0'; j++)
		{
			if (w[i] == w[j])
			{
				count++;
			}
		}
		if (count % 2 != 0)
		{
			flag = 1;
		}
	}
	if (flag == 1)
	{
		cout <<"No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int c=1000000007;
signed main()
{
   int n,t=0;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   for(int i=0;i<n;i++)
   {
       for(int j=i+1;j<n;j++)
        t+=a[i]*a[j];
   }
   cout<<t;
}


Measured memory_bytes: 256
//
//  main.cpp
//  A-+-x
//
//  Created by david chong on 8/14/19.
//  Copyright © 2019 david chong. All rights reserved.
//

#include <iostream>

using namespace std;

int solve(int a, int b) {
    
    int result = max((a+b), (a-b));
    result = max((a*b), result);
    
    return result;
    
}

int main(int argc, const char * argv[]) {
    
//    freopen("input.in", "r", stdin);
    
    int a, b;
    
    cin >> a >> b;
    
    cout << solve(a, b) << endl;
    
    return 0;
}


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

int main() {
  
  int a, b, c;
  cin >> a >> b >> c;
 
  cout << (b-a == c-b ? "YES" : "NO") << endl;

}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#define N 55
using namespace std;
char Map[N][N];
int n,m,cnt;
int vis[N][N];
struct node
{
	int x, y;
}q[N*N];
bool she[N][N];
const int r[]={1,-1,0,0};
const int w[]={0,0,1,-1};
inline void bfs(int sx, int sy)
{
	int hd,tl,dx,dy,fx,fy;
	hd=tl=1;
	q[1].x=sx;
	q[1].y=sy;
	while(hd<=tl)
	{
		fx=q[hd].x;
		fy=q[hd].y;
		hd++;
		for(int i=0;i<4;++i)
		{
			dx=fx+r[i];
			dy=fy+w[i];
			if(dx<1||dy<1||dx>n||dy>m||Map[dx][dy]=='#'||she[dx][dy]==1) 
			continue;
			she[dx][dy]=1;
			tl++;
			q[tl].x=dx;
			q[tl].y=dy;
			vis[dx][dy]=vis[fx][fy]+1;
			if(dx==n&&dy==m) 
			return ;
		}
	}
}
int main()
{
	cin>>n>>m;
	memset(vis,127/3,sizeof vis );
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			cin>>Map[i][j];
			if(Map[i][j]=='#') 
			cnt++;
		}
	}
	vis[1][1]=1;
	she[1][1]=1;
	bfs(1,1);
	int ans=n*m-cnt-vis[n][m];
	if(ans<0) 
	puts("-1");
	else 
	printf("%d",ans);
}


Measured memory_bytes: 3796
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x = 0;
		double y = 0;
		double angle = 90;
		
		while(sc.hasNext()){
			String[] str = sc.nextLine().split(",");
			int step_count = Integer.parseInt(str[0]);
			int rotation = Integer.parseInt(str[1]);
			
			if(step_count == 0 && rotation == 0)
				break;
			
			x = x + step_count * Math.cos(Math.toRadians(angle));
			y = y + step_count * Math.sin(Math.toRadians(angle));
			angle = angle - rotation;
		}
		System.out.println((int)x);
		System.out.println((int)y);
	}
}

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

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


ll gcd(ll x, ll y){
    return y ? gcd(y, x%y) : x;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X;
    cin >> N >> X;
    vector<ll> x(N+1);
    x[0] = X;
    REP(i,N) cin >> x[i+1];
    sort(x.begin(), x.end());
    ll g = x[1] - x[0];
    for(int i=2;i<=N;i++) g = gcd(g, x[i] - x[i-1]);
    cout << g << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

		Task2[] tasks = new Task2[100000];

		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		}
		int time = 0;
		int head = 0;
		int tail = n;
		while (head != tail) {
			Task2 task = tasks[head];
			head++;
			if (head == 100000) {
				head = 0;
			}
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			}

		}

	}

}

class Task2 {
	String name;
	int second;

	public Task2(String name, int second) {
		this.name = name;
		this.second = second;

	}

	public String getName() {
		return name;
	}

	public int getSecond() {
		return second;
	}

	public void setSecond(int second) {
		this.second = second;
	}

}

Measured memory_bytes: 73784
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,w;
  int a[LIMIT2]={0},b[LIMIT1]={0};
  char s[LIMIT1];
  ll dp[LIMIT1]={0};
  
  scanf("%lld %lld",&n,&w);
  rep(i,n) scanf("%d %d",&a[i],&b[i]);
  rep(i,n){
    per(j,w+1){
      dp[j+a[i]] = max(dp[j+a[i]],dp[j]+b[i]);
      dp[j+1]=max(dp[j+1],dp[j]);
    }
  }
  printf("%lld",dp[w]);
  return 0;
}



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

int main() {
  int A, B;
  cin >> A >> B;

  string S;
  cin >> S;

  bool flag = true;

  rep(i, 0, A) {
    if (int('0') <= S[i] && S[i] <= int('9')) continue;
    else flag = false;
  }

  if (S[A] != '-') flag = false;

  rep(i, A+1, A+B+1) {
    if (int('0') <= S[i] && S[i] <= int('9')) continue;
    else flag = false;
  }

  cout << ( flag ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define MK make_pair
#define PB push_back
#define fi first
#define se second

typedef long long LL;
typedef pair<int, int> PII;

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	printf("%d\n", n-k+1);	
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut stack1: Vec<usize> = Vec::new();
    let mut stack2: Vec<(usize, usize)> = Vec::new();

    let mut sum = 0;

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let chars: Vec<char> = buf.trim().chars().collect();

    for i in 0..chars.len() {
        if chars[i] == '\\' {
            stack1.push(i);
        } else if chars[i] == '/' && stack1.len() > 0 {
            let j = stack1.pop().unwrap();
            let mut a = i - j;
            sum += a;
            while stack2.len() > 0 && stack2[stack2.len() - 1].0 > j {
                a += stack2.pop().unwrap().1;
            }
            stack2.push((j, a));
        }
    }

    let mut ans: Vec<usize> = Vec::new();
    for _ in 0..stack2.len() {
        ans.push(stack2.pop().unwrap().1);
    }
    ans.reverse();
    println!("{}", sum);
    print!("{}", ans.len());
    for a in ans {
        print!(" {}", a);
    }
    println!();
}



Measured memory_bytes: 5036
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    string s;cin>>s;
    ll k;cin>>k;
    ll c=1;
    vector<ll>v;
    f(i,1,s.size()){
        if(s[i]==s[i-1])c++;
        else{
            v.pb(c);
            c=1;
        }
    }
    v.pb(c);
    if(v.size()==1){
        cout<<(s.size()*k)/2;
    }
    else if(s[0]==s[s.size()-1]){
        ll ans=(k-1)*((v[v.size()-1]+v[0])/2);
        f(i,1,v.size()-1){
            ans+=(k*(v[i]/2));
        }
        if(v.size()>1)ans+=v[0]/2;
        if(v.size()>1)ans+=v[v.size()-1]/2;
        cout<<ans;
    }
    else{
        ll ans=0;
        f(i,0,v.size()){
            ans+=(k*(v[i]/2));
        }
        cout<<ans;
    }
    return 0;  
} 

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct edge_t {
  int to, w;
};

using weight_t = pair<int, int>;

const weight_t inf = {400, 1e9 + 10};

vector<int> solve(const vec<edge_t, 2>& g, int L, int s) {
  vector<weight_t> dist(g.size(), inf);
  using P = pair<weight_t, int>;
  priority_queue<P, vector<P>, greater<P>> q;
  dist[s] = {0, 0};
  q.emplace(weight_t(0, 0), s);
  while (!q.empty()) {
    const P p = q.top();
    q.pop();
    const weight_t w = p.first;
    const int v = p.second;
    if (dist[v] < w) continue;
    vector<weight_t> ws = {w, {w.fst + 1, 0}};
    for (auto w : ws) {
      for (const auto& e : g[v]) {
        if (w.snd + e.w > L) continue;
        const weight_t nw = {w.fst, w.snd + e.w};
        if (dist[e.to] <= nw) continue;
        dist[e.to] = nw;
        q.emplace(nw, e.to);
      }
    }
  }
  vector<int> res(g.size(), -1);
  for (int v = 0; v < g.size(); v++) {
    if (dist[v] != inf) res[v] = dist[v].fst;
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, M, L;
  while (cin >> N >> M >> L) {
    vec<edge_t, 2> g(N);
    for (int i = 0; i < M; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      --a;
      --b;
      if (c > L) continue;
      g[a].push_back({b, c});
      g[b].push_back({a, c});
    }
    vec<int, 2> ans(N);
    for (int i = 0; i < N; i++) ans[i] = solve(g, L, i);
    int Q;
    cin >> Q;
    for (int q = 0; q < Q; q++) {
      int s, t;
      cin >> s >> t;
      --s;
      --t;
      cout << ans[s][t] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2600
k = gets.chomp.to_i

ary = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

puts ary[k-1]

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define pb push_back


/* alias */


template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = 1000100010010010;
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alpha = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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; }




/* main */






signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);


    string s = raw_input();

    int ans = s.size();

    rep(i,0,s.size() - 1){
        if(s[i] != s[i + 1]) chmin(ans, max(i + 1, (int)s.size() - i - 1));
    }
    print(ans);
    




    
    
    

    



    






    



    





    


    

}



Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
inline int read()
{
    int x=0,t=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return x*t;
}
int a[5][500],n;
int s[5][500];
int main()
{
	n=read();
	for(int i=1;i<=2;++i)
		for(int j=1;j<=n;++j)
			a[i][j]=read();
	for(int i=1;i<=2;++i)
		for(int j=1;j<=n;++j)
			s[i][j]=s[i][j-1]+a[i][j];
	int ans=0;
	for(int i=1;i<=n;++i)
		ans=max(ans,s[1][i]+s[2][n]-s[2][i-1]);
	cout<<ans<<endl;
	return 0;
}

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

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

int n,a[105],w[105],val,all;
int dp[105][100005];


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>val;
    for(int i=1;i<=n;i++){
        cin>>w[i]>>a[i];
        all+=a[i];
    }

    for(int i=0;i<=n;i++)for(int j=0;j<=all;j++)dp[i][j]=MOD;
    dp[0][0]=0;

    for(int i=1;i<=n;i++){
        for(int j=0;j<=all;j++){
            if(j-a[i]>=0)dp[i][j]=min(dp[i][j],dp[i-1][j-a[i]]+w[i]);
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
        }
    }

    for(int j=all;j>=0;j--){
        if(dp[n][j]<=val){
            cout<<j;
            return 0;
        }
    }
    return 0;
}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  long long N, M;
  cin >> N >> M;
  vector<pair<long long, long long>> p(N);
  for (int i = 0; i < N; i++)
  {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p.begin(), p.end());
  long long ans = 0, cnt = 0;
  int i = 0;
  while (cnt < M)
  {
    ans += p[i].second * p[i].first;
    cnt += p[i].second;
    i++;
  }
  if (cnt == M)
    cout << ans << endl;
  else
  {
    int ex = cnt - M;
    ans -= ex * p[i - 1].first;
    cout << ans << endl;
  }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
inline void chmin(T &a, T b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, T b) { a = max(a, b); }
template <class T>
inline bool kbit(T &x, int k) { return ((x >> k) & 1LL); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void readv(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    V<int> h(n);
    readv(h);
    V<V<int>> G(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].eb(b);
        G[b].eb(a);
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
        if (G[i].size() == 0) {
            res++;
            continue;
        }
        int f = 1;
        for (auto &e : G[i]) {
            if (h[e] >= h[i]) f = 0;
        }
        res += f;
    }
    cout << res << '\n';
}

Measured memory_bytes: 8740
import numpy as np
h,w=map(int,input().split())
a=np.array([[0 if i!="." else 1 for i in input()]for j in range(h)])
e=np.zeros((4,h,w))
for i in range(h):
    e[0,i]=(e[0,i-1]+1)*a[i]
    e[1,-i-1]=(e[1,-i]+1)*a[-i-1]  
for i in range(w):
    e[2,:,i]=(e[2,:,i-1]+1)*a[:,i]
    e[3,:,-i-1]=(e[3,:,-i]+1)*a[:,-i-1] 
print(int(np.amax(np.sum(e, axis=0))-3))

Measured memory_bytes: 222636
n = int(input())
P = list(map(int, input().split()))
c = 0
for i in range(1, n-1):
    if P[i-1] < P[i] < P[i+1]:
        c += 1
    elif P[i+1] < P[i] < P[i-1]:
        c += 1
print(c)

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

int main() {
  int n, roads, i, a, b;
  cin>>n>>roads;
  vector<set<int> >g(n);
  vector<int>peak(n);
  for(i = 0; i < n; i++)  cin>>peak[i];
  for(i = 0; i < roads; i++) {
    cin>>a>>b;
    g[a-1].insert(b-1);
    g[b-1].insert(a-1);
  }
  
  int good = 0;
  int curr_high, j;
  for(i = 0; i < n; i++) {
    curr_high = peak[i];
    j = 0;
    for(int x : g[i]) {
      if(peak[x] < curr_high)
        j++;
      //cout<<"\n"<<i<<" "<<curr_high<<" "<<x<<" ";
    }
    if(j == g[i].size()) {
      good++;
      //cout<<(i+1)<<" ";
    }
  }
  
  cout<<good<<"\n";
  return 0;
}

Measured memory_bytes: 17752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, m;
    cin >> h >> w >> m;
    vector<pair<int, int>> a(m);
    map<int, int> x, y;
    for (int i = 0; i < m; i++) {
        cin >> a[i].first >> a[i].second;
        x[a[i].first]++;
        y[a[i].second]++;
    }
    sort(a.begin(), a.end());
    int mx = 0, my = 0;
    for (auto e : x) {
        mx = max(mx, e.second);
    }
    for (auto e : y) {
        my = max(my, e.second);
    }
    vector<int> s, t;
    int ans = mx + my;
    for (auto e : x) {
        if (mx == e.second) {
            s.emplace_back(e.first);
        }
    }
    for (auto e : y) {
        if (my == e.second) {
            t.emplace_back(e.first);
        }
    }
    for (int i : s) {
        for (int j : t) {
            if (!binary_search(a.begin(), a.end(), make_pair(i, j))) {
                cout << ans << '\n';
                return 0;
            }
        }
    }
    ans--;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 37852
# your code goes here
n=int(input())
st=input()
a=""
b=""
if(n%2==1):
	print("No")
else:
	x=n//2
	for i in range(0,x):
		a=a+st[i]
	for i in range(x,n):
		b=b+st[i]
	if(a==b):
		print("Yes")
	else:
		print("No")
	

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

// 1から番号が始まっていることに注意
class UnionFind {
    vector<int> parent;
    vector<int> rank;

public:
    int root(int x) {
        return parent[x] >= 0 ? parent[x] = root(parent[x]) : x;
    }

    void unite(int x, int y) {
        int rootX = root(x);
        int rootY = root(y);
        if (rootX == rootY)
            return;

        if (rank[rootX] > rank[rootY]) {
            parent[rootX] += parent[rootY];
            parent[rootY] = rootX;
        } else {
            if (rank[rootX] == rank[rootY])
                ++rank[rootY];

            parent[rootY] += parent[rootX];
            parent[rootX] = rootY;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int groupSize(int x) {
        return -parent[root(x)];
    }

    int numGroup() {
        int num = 0;
        for (int k : parent) {
            num += k < 0;
        }
        return num;
    }

    UnionFind(int size) : parent(size + 1, -1), rank(size + 1, 1) {
        parent[0] = rank[0] = 0;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> idx(n + 1);
    for (int i = 1; i <= n; ++i) {
        int p;
        cin >> p;
        idx[p] = i;
    }

    UnionFind uf(n);
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += uf.same(i, idx[i]);
    }

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

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

using namespace std;
using ll = long long int;
#define long ll

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

    ll n, y;
    cin >> n >> y;
    for(ll i=0; i<=n; i++)
    for(ll j=0; i+j<=n; j++)
        if(10000*i + 5000*j + 1000*(n-i-j) == y) {
            cout << i << ' ' << j << ' ' << n-i-j << endl;
            return 0;
        }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template<class _T> static void getint(_T& a) {
	if (sizeof(_T) > sizeof(int)) {
		scanf("%lld", &a);
	}
	else {
		scanf("%d", &a);
	}
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}
template <class _T> static _T tp_modpow(_T base, _T exp, _T mod = (_T)1) {
	_T ans = 1;
	while (exp > 0) {
		if (exp & 1) {
			ans = (ans * base) % mod;
		}
		base = (base * base) % mod;
		exp >>= 1;
	}
	return ans;
}
template <class _T> static _T tp_modinv(_T a, _T mod) {
	return tp_modpow<_T>(a, mod - 2, mod);
}

static void exec()
{
	int N;
	get(N);

	std::string str;
	get(str);

	std::reverse(str.begin(), str.end());

	std::vector<int> num(N);
	for (int i = 0; i < N; i++) {
		num[i] = str[i] - '0';
	}

	LLONG bitCount = std::accumulate(num.begin(), num.end(), 0LL);

	LLONG plusMod = 0;
	LLONG minusMod = 0;
	LLONG twoFactor1 = 1;
	LLONG twoFactor2 = 1;
	for (int i = 0; i < N; i++) {
		plusMod += (num[i] % (bitCount + 1)) * (twoFactor1 % (bitCount + 1LL));
		plusMod %= (bitCount + 1LL);
		twoFactor1 = twoFactor1 * 2LL % (bitCount + 1LL);
		if (bitCount > 1) {
			minusMod += (num[i] % (bitCount - 1)) * (twoFactor2 % (bitCount - 1));
			minusMod %= (bitCount - 1);
			twoFactor2 = twoFactor2 * 2LL % (bitCount - 1);
		}
		else minusMod = 0;
	}
	std::vector<int> ans(N, 0LL);
	for (int i = 0; i < N; i++) {
		int cnt = 1;
		LLONG n = 0;
		LLONG mod = 0;
		if (num[N - 1 - i]) {
			mod = bitCount - 1;
			if (mod <= 0) {
				n = cnt = 0;
			}
			else {
				n = (minusMod - tp_modpow<LLONG>(2, N - i - 1, mod)) % mod;
				if (n < 0) {
					n += mod;
				}
			}
		}
		else {
			mod = bitCount + 1;
			n = (plusMod + tp_modpow<LLONG>(2, N - i - 1, mod)) % mod;
		}
		while (n) {
			cnt++;

			mod = std::bitset<32>(n).count();
			n = n % mod;
		}
		ans[N - 1 - i] = cnt;
	}

	for (int i = N - 1; i >= 0; i--) {
		printf("%d\n", ans[i]);
	}
}


Measured memory_bytes: 5256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,mx=0;
  cin>>N;
  int key;
  vi A(N);
  rep(i,0,N){
    int X;
    cin>>X;
    A[i]=X-i-1;
    }
  sort(ALL(A));
  key=A[N/2];
  int ans=0;
  rep(i,0,N){
    ans+=abs(A[i]-key);
    }
  cout<<ans<<endl;
  }


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;


int main(){
  int a,b;
  cin>>a>>b;
  int ans=0;
  if(a!=b){
    ans+=max(a,b);
  ans*=2;
  ans--;
  cout<<ans<<endl;
  }
  
  else cout<<a*2<<endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int count = 1;
    int hub = a;
    while(a < b){
        a = a + hub - 1;
        count++;
    }
    if(b != 1)
        cout << count << endl;
    else
    {
        cout << 0 << endl;
    }
    
} 
    


Measured memory_bytes: 256
# coding:utf-8

N, M = map(int, input().split(' '))
ac_stk = [0 for _ in range(N)]
wa_stk = [[True, 0] for _ in range(N)]
pair = []
for _ in range(M):
    p, s = input().split(' ')
    pair.append((int(p), s))
ac = 0
wa = 0

for p, s in pair:
    if s == 'WA':
        wa_stk[p-1][1] += 1
    elif s == 'AC':
        ac_stk[p-1] = 1
        if wa_stk[p-1][0]:
            wa += wa_stk[p-1][1]
            wa_stk[p-1][0] = False

print('{} {}'.format(sum(ac_stk), wa))

Measured memory_bytes: 29952
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final Set<String> seen = new HashSet<>();
        char prev = '#';
        for (int i = 0; i < n; i++) {
            final String curr = fs.next();
            if (!seen.add(curr) || (prev != '#' && curr.charAt(0) != prev)) {
                System.out.println("No");
                return;
            }
            prev = curr.charAt(curr.length() - 1);
        }
        System.out.println("Yes");
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


Measured memory_bytes: 32616
L = gets.chomp.to_i
A = gets.chomp.to_i
B = gets.chomp.to_i
C = gets.chomp.to_i
D = gets.chomp.to_i
j = A/C
if A%C != 0
  j += 1
end
m = B/D
if B%D != 0
  m += 1
end

puts L-[j,m].max


Measured memory_bytes: 6864
#include<stdio.h>
int main(void) {
	int n,m;
	scanf("%d %d",&n,&m);
	int A[m];
	for(int i=0;i<m;i++){
		scanf("%d",&A[i]);
	}
	for(int i=0;i<m;i++){
		n=n-A[i];
		if(n<0) {
			printf("-1\n");
			break;
		}
		else if(n==0&&i==m-1){
			printf("0\n");
			break;
		}
		else if(i==m-1)
			printf("%d\n",n);
	}
	return 0;
}
	

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>

#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

}  // namespace atcoder


using namespace std;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n, m;
    cin >> n >> m;
    atcoder::dsu d(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        d.merge(a, b);
    }
    cout << d.groups().size() - 1 << endl;
}


Measured memory_bytes: 8836
#include<bits/stdc++.h>
using namespace std;
#define int long long

int N,D,A;
pair<int, int> m[200000];

signed main() {
  cin >> N >> D >> A;
  for(int i=0; i<N; i++) cin >> m[i].first >> m[i].second;

  sort(m, m+N);

  int ans = 0;
  int damage = 0;
  queue<pair<int, int>> q;

  for(int i=0; i<N; i++) {
    int Xi=m[i].first;
    int Hi=m[i].second;

    while (q.size() && q.front().first < Xi) {damage -= q.front().second; q.pop();}

    Hi -= damage;
    if(Hi <= 0) continue;
    int a = (Hi+A-1) / A;
    ans += a;

    damage += a*A;
    q.emplace(Xi + 2*D, a*A);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5120
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

map<int,int> n1,n2;
char str[100];
int main(){
    for(;;){
        gets(str);
        if(strlen(str)==0) break;
        int a;
        sscanf(str,"%d,%*d",&a);
        n1[a]++;
    }
    while(scanf("%s\n",str)!=-1){
        int a;
        sscanf(str,"%d,%*d",&a);
        n2[a]++;
    }
    for(map<int,int>::iterator it=n1.begin();it!=n1.end();it++){
        if(n2[it->first]>0) printf("%d %d\n",it->first,it->second+n2[it->first]);
    }
}

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

int main()
{
  long H;
  cin >> H;
  long p = 0;
  int i = 0;
  long ans = 1;
  while(H >= p){
    //cout << p << endl;
    ans += p;
    i++;
    p = pow(2, i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())

k = -1
for i in range(1, 10 ** 5 + 1):
    if i * (i - 1) == 2 * n:
        k = i
        break

if k == -1:
    print('No')
else:
    ans = [[] for _ in range(k)]
    print('Yes')
    print(k)
    tmp = 1
    for i in range(k):
        for j in range(i+1, k):
            ans[i].append(tmp)
            ans[j].append(tmp)
            tmp += 1

    for i in range(k):
        print(len(ans[i]), *ans[i])



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

/* 問題文
N 
A_1 ... A_N が与えられ、A_1 ~ A_Nの積を求めよ。
10^18をこえる時は-1とする */
int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);

    for (long long i = 0; i < N; i++){
        cin >> A.at(i);
    }

    for (int i = 0; i < N; i++) 
        if (A.at(i) == 0 ){
            cout << "0"<< endl;
            return 0;
        }

    long long product = 1;

    for (long long i = 0; i < N; i++){
        if (product <= 1000000000000000000/A.at(i))
            product *= A.at(i);
        else {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << product << endl;
}

Measured memory_bytes: 4048
def primes(x):
    if x < 2:
        return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > x**0.5:
            break

        if prime == 0:
            continue

        for non_prime in range(2 * prime, x, prime):
            primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


N = int(input())
prime_arr = primes(N + 1)
arr = [1 for i in range(N + 1)]
for i in range(2, N + 1):
    n = i

    for prime in prime_arr:
        while n % prime == 0:
            n //= prime
            arr[prime] += 1
        if n == 1:
            break

ans = 1
for v in arr:
    ans *= v

print(ans % (1000000007))


Measured memory_bytes: 3188
#include	<iostream>
#include	<cmath>

using namespace std;

int main(void) {
	while(1) {
		double v, y, t;
		cin >> v;
		if( cin.eof() )	break;
		
		t = v / 9.8;
		y = 4.9 * t * t;
		
		int f;
		
		for(int i = 1;;i++) {
			f = 5 * i - 5;
			if(y < f) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <vector>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i_, __start, __end) for(ll i_=(ll)__start; i_<(ll)__end; i_++)
#define print(_a) cout << _a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");


int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b < c+d){
      print("Right");
    }else if(a+b > c+d){
      print("Left");
    }else{
      print("Balanced");
    }
   
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

string s;
int n;

int main() {
	cin >> s; n = s.length();
	
	int i, j;
	if (s[0] == '0' || s[n - 1] == '1') { cout << -1 << endl; return 0; }
	rep(i, n - 1) if (s[i] != s[n - 2 - i]) { cout << -1 << endl; return 0; }
	
	vector<int> vec;
	rep(i, n - 1) {
		if (i > n - 2 - i) break;
		if (s[i] == '1') vec.push_back(i);	//部分木のサイズ - 1
	}
	vec.push_back(n - 1);
	
	rep(i, vec.size()) {
		if (i == 0) continue;
		for (j = vec[i - 1]; j < vec[i]; j++) cout << vec[i] + 1 << " " << j + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1916
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int A, B, C;
  cin >> A >> B >> C;
  int K;
  cin >> K;

  int cnt = 0;
  while (A >= B) {
    cnt++;
    B *= 2;
  }
  while (B >= C) {
    cnt++;
    C *= 2;
  }

  if (cnt <= K)
    cout << "Yes\n";
  else
    cout << "No\n";
}

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

#define f(i,x,y)			for(int i=x; i<y; i++)
#define mp 					make_pair
#define F 					first
#define S 					second

int main()
{
	int n;
	cin>>n;
	int a[n+1];
	f(i,1,n+1)
		cin>>a[i];

	vector <int> dp(n+1,0);
	dp[1] = 0;
	dp[2] = abs(a[2]-a[1]);
	f(i,3,n+1)
	{
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]) , dp[i-2]+abs(a[i]-a[i-2]) );
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void) {
	char a, *b;
	scanf("%c", &a);
	if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')printf("vowel\n");
	else printf("consonant\n");
	return 0;
}

Measured memory_bytes: 128