akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define LL long long

const int maxn = 2e5+5;
vector<int> G[maxn];
int d[maxn];

int bfs(int st){
    int ret_val = st;
    d[st] = 0;
    queue<int> que;
    que.push(st);
    while(!que.empty()){
        int now = que.front();que.pop();
        ret_val = now;
        _for(i,0,G[now].size()){
            int nex = G[now][i];
            if(d[nex] == -1){
                d[nex] = d[now] + 1;
                que.push(nex);
            }
        }
    }
    return ret_val;
}

int main()
{
    int N;scanf("%d",&N);
    memset(d,-1,sizeof(d));
    _for(i,0,N-1){
        int v,w;
        scanf("%d %d",&v,&w);
        G[v].push_back(w);
        G[w].push_back(v);
    }
    int st = bfs(1);
    memset(d,-1,sizeof(d));
    int ed = bfs(st);
    int ans = d[ed];
    if(ans % 3 == 1){
        printf("Second\n");
    }
    else printf("First\n");
    return 0;
}

Measured memory_bytes: 13556
function Main(input) {
  input = input.trim().split("\n").map(function(x) { return x.split(" ")});
  var N = parseInt(input[0],10);
  var vec_A = input[1].map(e => (parseInt(e, 10)));
  var eachNumCount = Array.from({length: N}, () => 0);
  var pairCount = Array.from({length: N}, () => 0);
  var sumPair, tmp;
  var ans = [];
  for (var i = 0; i < N; i++){
    eachNumCount[vec_A[i]-1] ++;
    pairCount[vec_A[i]-1] = (eachNumCount[vec_A[i]-1] * (eachNumCount[vec_A[i]-1] - 1) / 2)
  }
  sumPair = sum(pairCount);
  for (var i = 0; i < N; i++){
    tmp = eachNumCount[vec_A[i]-1]
    if (tmp === 0) ans.push(sumPair)
    else ans.push(sumPair - (tmp * (tmp - 1) / 2) + ((tmp - 1) * (tmp - 2) / 2));
  }
  console.log(ans.join('\n'));
}   

var sum  = function(arr) {
  var sum = 0;
  arr.forEach(function(elm) {
      sum += elm;
  });
  return sum;
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;
typedef long long ll;
const ll INF = 1e9;
 
int main(void) {
    int A, B;
    cin >> A >> B;

    int current = 1;
    int used = 0;
    while (current < B) {
        used++;
        current += (A - 1);
    }
    cout << used << 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 = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();

		int[] B = new int[M];
		for(int j = 0; j < M; j++) {
			B[j] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0; i < N; i++) {
			int sum = 0;
			for(int j = 0; j < M; j++) {
				sum += B[j] * sc.nextInt();
			}
			if (sum > -1 * C) {
				count++;
			}
		}

		System.out.println(count);

	}

}



Measured memory_bytes: 22996
H, W = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
ans = []
for i in range(H-1):
    S = A[i]
    T = A[i+1]
    for j in range(W):
        if S[j] % 2:
            ans.append("%d %d %d %d" % (i+1, j+1, i+2, j+1))
            S[j] -= 1; T[j] += 1
S = A[-1]
for j in range(W-1):
    if S[j] % 2:
        ans.append("%d %d %d %d" % (H, j+1, H, j+2))
        S[j] -= 1; S[j+1] += 1
print(len(ans))
print(*ans, sep='\n')

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

int main() {
	string s, t;
	llong s_size;
	cin >> s >> t;
	s_size = s.size();

	vector<vector<int> > pos(26);
	for (int i = 0; s[i]; ++i)
		pos[s[i] - 'a'].push_back(i);

	llong ret = 0, before = -1;
	for (int i = 0; t[i]; ++i) {
		int id = t[i] - 'a';
		auto it = upper_bound(ALL(pos[id]), before);
		if (it == pos[id].end()) {
			if (before == -1) {
				ret = -inf;
				break;
			} else {
				ret += s_size - before - 1;
				before = -1;
				i--;
				continue;
			}
		} else {
			ret += *it - before;
			before = *it;
		}
		// cerr << t[i] << " " << ret << " " << before << endl;
	}

	cout << max(-1ll, ret) << endl;

	return 0;
}

Measured memory_bytes: 1216
a,b,c,x,y=map(int,input().split())
ans=a*x+b*y
for i in range(1,max(x,y)+1):
  ab=i*2
  abc=ab*c+a*max(0,x-i)+b*max(0,y-i)
  ans = min(ans,abc)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll H,W,ans=0;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H) cin >> S.at(i);
  vector<vector<ll>> h(H,vector<ll>(W,0)),w(H,vector<ll>(W,0));
  rep(i,H){
    ll t=0,s=0;
    while(t<W){
      while(s<W&&S.at(i).at(s)=='.'){
        s++;
      }
      for(ll j=t;j<s;j++){
        h.at(i).at(j)=s-t;
      }
      t=s+1;
      s=t;
    }
  }
  rep(j,W){
    ll t=0,s=0;
    while(t<H){
      while(s<H&&S.at(s).at(j)=='.'){
        s++;
      }
      for(ll i=t;i<s;i++){
        w.at(i).at(j)=s-t;
      }
      t=s+1;
      s=t;
    }
  }
  rep(i,H){
    rep(j,W){
      ans=max(ans,h.at(i).at(j)+w.at(i).at(j));
    }
  }
  cout << ans-1 << endl;
}
   

Measured memory_bytes: 73432
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin>>n;
    vector<long> t(n);
    for(int i = 0; i < n; i++)
        cin>>t[i];
    long m;
    cin>>m;
    for(int i = 0; i < m; i++){
        long p,x;
        cin>>p>>x;
        vector<long> cp;
        cp=t;
        cp[p-1]=x;
        long count=0;
        for(auto z:cp)
            count+=z;
        cout<<count<<endl;
    }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
	"math"
)

var INF = math.MaxInt32
var INF64 = math.MaxInt64

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func readLineNums(bf *bufio.Reader) []int {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int{}
	for _, field := range fields {
		num, _ := strconv.Atoi(field)
		nums = append(nums, num)
	}
	return nums
}

func readLineFloats(bf *bufio.Reader) []float64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []float64{}
	for _, field := range fields {
		num, _ := strconv.ParseFloat(field, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineStrs(bf *bufio.Reader) []string {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	return strings.Split(line, " ")
}

func main() {
	bf := bufio.NewReader(os.Stdin)
	nw := readLineNums(bf)
	N, W := nw[0], nw[1]
	Ws := make([]int, 0)
	Vs := make([]int, 0)
	for i:=0; i<N; i++ {
		wv := readLineNums(bf)
		Ws = append(Ws, wv[0])
		Vs = append(Vs, wv[1])
	}

	V := 0
	for _, v := range Vs {
		V += v
	}

	dp := make([]int, V+1) // dp[i]: 表示产生价值为i, 需要的最少背包容量
	for i:=1; i<=V; i++ {
		dp[i] = INF
	}

	for i:=0; i<N; i++ {
		wi := Ws[i]
		vi := Vs[i]
		for v:=V; v>=vi; v-- {
			dp[v] = min(dp[v], dp[v-vi]+wi)
		}
	}

	ans := 0
	for i:=0; i<=V; i++ {
		if dp[i] <= W {
			ans = max(ans, i)
		}
	}
	fmt.Println(ans)
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

const ll MOD = 1000000007;

int main() {
	ll N;
	cin >> N;
	string S;
	cin >> S;

	map<char, ll> m;
	for (int ii = 0; ii < N; ++ii){
		m[S[ii]] += 1;
	}

	ll ans = 1;
	for (char c = 'a'; c <= 'z'; ++c){
		ans = (ans * (m[c] + 1)) % MOD;
	}

	cout << ans - 1 << endl;

	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

void trace(int x[], int n){
	
	int i;
	
	for ( i = 0; i < n - 1; i++ ){
		if ( i >= 0 ){
			printf("%d ", x[i]);
		}
	}
	printf("%d\n",x[n - 1]);
}


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

int main(void){
	int n, i, j, x[100];
	
	scanf("%d", &n);
	for ( i = 0; i < n; i++ ){
		scanf("%d", &x[i]);
	}
		trace(x, n);
		insertionSort(x, n);
		
		return 0;
}

Measured memory_bytes: 1744
import java.util.Scanner;
 class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int GCD[] = new int[100];
		int LCM[] = new int[100];
		int i = 0;
		while(sc.hasNext()){
			int a = sc.nextInt(), b =sc.nextInt();
			GCD[i] = GCD(a,b);
			LCM[i] = (a/GCD[i])*(b/GCD[i])*GCD[i];
			i++;
		}
		for(int j = 0; j < i; j++){
			System.out.println(GCD[j]+" "+LCM[j]);
		}
		
	}
	
	public static int GCD(int a, int b){
		Scanner sc = new Scanner(System.in);
		int x ;
		if(a < b){
			x = a;
			a = b;
			b = x;
		}
		while(true){
			x = a%b;
			if(x == 0) break;
			a = b;
			b = x;
		}
		return b;
	}
}

Measured memory_bytes: 26492
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int R,C,K;
int map_item[3005][3005];
int dp[3005][3005][5];
signed main(){
    scanf("%lld %lld %lld",&R,&C,&K);
    rep(i,K){
        int r,c,v;
        scanf("%lld %lld %lld",&r,&c,&v);r--;c--;
        map_item[r][c]=v;
    }
    rep(i,R){
        rep(j,C){
            rep(k,4){
                //拾わないで横に移動
                dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
                //拾わないで下に移動
                dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
                //拾って横に移動
                dp[i][j+1][k+1]=max(dp[i][j+1][k+1],dp[i][j][k]+map_item[i][j]);
                //拾って下に移動
                if(k!=3)dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]+map_item[i][j]);
            }
        }
    }
    int ans=0;
    ans=max(ans,dp[R-1][C-1][0]+map_item[R-1][C-1]);
    ans=max(ans,dp[R-1][C-1][1]+map_item[R-1][C-1]);
    ans=max(ans,dp[R-1][C-1][2]+map_item[R-1][C-1]);
    ans=max(ans,dp[R-1][C-1][3]);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 424344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}



int main(){

  ll N,K;
  cin >> N >> K;
  vector<ll> ans(N+1,0);
  FOR(i,0,K){
    ll d;
    cin >> d;
    FOR(j,0,d){
      ll x;
      cin >> x;
      ans[x]++;
    }
  }
  ll ans_c=0;
  FOR(i,1,N+1)if(ans[i]==0)ans_c++;
  cout << ans_c << endl;
}


Measured memory_bytes: 3628
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	shops := make([][10]int, N) // 商店街のお店が開いている時間帯
	for i := 0; i < N; i++ {
		for j := 0; j < len(shops[i]); j += 2 {
			fmt.Scan(&shops[i][j], &shops[i][j+1])
		}
	}
	profits := make([][11]int, N) // 自分のお店と商店街のお店iが同時に開いている時間帯の個数で得られる利益
	for i := range profits {
		for j := range profits[i] {
			fmt.Scan(&profits[i][j])
		}
	}
	// お店を開く時間を全列挙して探索する
	const inf = int(1e10) + 1
	ans := -inf
	for bits := 0; bits < (1 << uint(10)); bits++ {
		if bits != 0 { // 少なくとも1つの時間帯以上でお店を開ける
			var p int
			for i := 0; i < N; i++ { // お店iが空いている時間帯をチェックする
				var slots int
				for j := 0; j < 10; j++ {
					if (bits & (1 << uint(j))) != 0 { // 時間帯jはお店を開く
						if shops[i][j] != 0 { // 商店街のお店iの時間帯jも空いている
							slots++
						}
					}
				}
				p += profits[i][slots]
			}
			ans = max(ans, p)
		}
	}
	fmt.Println(ans)
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 640
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#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 FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int A,B;
    R(A,B);
    W((A-1)*(B-1));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int main(){
  string s; int a;
  priority_queue<int> pq;
  cin >> s;
  while(s != "end"){
    if(s == "insert"){
      cin >> a; pq.push(a);
    }else{
      cout << pq.top() << "\n";
      pq.pop();
    }
    cin >> s;
  }
  return 0;
}


Measured memory_bytes: 7128
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A,B,C;cin>>A>>B>>C;
  int g = gcd(A,B);
  cout << (C%g==0? "YES":"NO")<<endl;
  return 0;
}


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

using namespace std;

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

    int ans = 1;
    for (int i = 1; i < N; i++) {
        if (s[i - 1] != s[i]) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	lli N, A, B; cin >> N >> A >> B;
	if (A == 0)cout << 0 << endl;
	else if (B == 0)cout << N << endl;
	else {
		lli ans = (N / (A + B))*A + less(A, (N % (A + B)));
		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<list>
#include<string>
#include<algorithm>
 
using namespace std;

int main(){
  long long n,k;
  cin >> n >> k;
  long long ans = n;
  if(abs(n-k) < n){
    long long num = n%k;
    if(num!=0){
      ans = abs(num-k);
    }else{
      ans = 0;
    }
  }

  cout << ans << endl;
}

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

int main() {
  int i, j, k, H, N; cin >> H >> N;
  string s, t;
  vector<int> a(N);
  rep (i, N) cin >> a.at(i);
  int sum = 0;
  sum = accumulate(a.begin(), a.end(), sum);
  if (sum >= H)
    puts("Yes");
  else
    puts("No");
  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  // #の入力
  vector<char> moji(W);
  for (int i = 0; i < H; i++) {
    // 上辺
    if (i == 0) {
      for (int j = -1; j < W + 1; j++) {
        cout << "#";
      }
      cout << endl;
    }
    
    // 文字の左辺右辺
    for (int j = 0; j < W; j++) {
      cin >> moji.at(j);
    }
    cout << "#";
    for (int j = 0; j < W; j++) {
      cout << moji.at(j);
    }
    cout << "#" << endl;
    
    // 下辺
    if (i == H - 1) {
      for (int j = -1; j < W + 1; j++) {
        cout << "#";
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<vector>
#include<algorithm>
#include<iostream>
#include<utility>
#include<climits>
using namespace std;





class LCA{
	int n;
	std::vector<int> _depth,idx;
	static int calcsize(int n){
		int res=1;
		while(res<n)res<<=1;
		return res;
	}
	int minimum(int a,int b,int k,int l,int r)const{
		if(r<=a||b<=l)return _depth.size()-1;
		if(a<=l&&r<=b)return idx[k];
		else{
			int vl=minimum(a,b,k*2+1,l,(l+r)/2);
			int vr=minimum(a,b,k*2+2,(l+r)/2,r);
			return _depth[vl]<_depth[vr]?vl:vr;
		}
	}
	void buildRMQ(){
		n=calcsize(_depth.size());
		idx.resize(2*n-1);
		for(int i=0;i<(int)_depth.size();i++)idx[n-1+i]=i;
		for(int i=_depth.size();i<n;i++)idx[n-1+i]=_depth.size();
		_depth.push_back(INT_MAX);
		for(int i=n-2;i>=0;i--){
			idx[i]=_depth[idx[i*2+1]]<_depth[idx[i*2+2]]?idx[i*2+1]:idx[i*2+2];
		}
	}
	
	std::vector<int> eulertour;
	std::vector<int> in;
	void dfs(const std::vector<int> edge[],int d,int u){
		in[u]=eulertour.size();	
		eulertour.push_back(u);
		_depth.push_back(d);
		for(int i=0;i<edge[u].size();i++){
			dfs(edge,d+1,edge[u][i]);
			eulertour.push_back(u);
			_depth.push_back(d);
		}
	}
public:
	LCA(const std::vector<int> edge[],int n,int root):in(n){
		dfs(edge,1,root);
		eulertour.push_back(root);
		_depth.push_back(0);
		buildRMQ();
	}
	int query(int u,int v)const{//uとvの最小共通祖先
		if(u==v)return u;
		if(in[u]>in[v])std::swap(u,v);
		return eulertour[minimum(in[u], in[v],0,0,n)];
	}
	int depth(int u)const{//rootの深さが1
		return _depth[in[u]];
	}
};


vector<int> edge[100000];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int k,v;
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>v;
			edge[i].push_back(v);
		}
	}
	LCA lca(edge,n,0);
	int q,u,v;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>u>>v;
		cout<<lca.query(u,v)<<endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int n;
  cin >> n;
  vector<int> t(n),x(n),y(n);
  REP(i,n)cin >> t[i] >> x[i] >> y[i];
  int ox = 0,oy = 0,ot = 0;
  bool flag = true;
  for(int i = 0;i < n;i++){
    int nx = abs(x[i]-ox),ny = abs(y[i]-oy),nt = abs(ot - t[i]);
    if(nx+ny > nt || abs(nx+ny-nt) & 1)flag = false;
    ox = nx,oy = ny,ot = nt;
  }
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;





  

  return 0;
}


Measured memory_bytes: 1408
n = int(input())
l = list(map(int, input().split()))
if n == 1:
    print("Yes")
else:
    l1 = l[1:]+[0]
    d = [i-j for (i,j) in zip(l1, l)][:-1]
    t = [i for i in d if i <= -2]
    if len(t) >= 1:
        print("No")
    else:
        if -1 not in d or d.count(-1)==1:
            print("Yes")
        else:
            p = d.index(-1)
            d = d[p+1:]
            s = ''.join(map(str, d))
            spl = s.split("-1") 
            if "" in spl[:-1]:
                print("No")
            else:
                if spl[-1] == "":
                    spl = [s for s in spl if s != '']
                    y = [int(i) for i in spl]
                    if 0 not in y:
                        print("Yes")
                    else:
                        print("No")
                else:
                    y = [int(i) for i in spl]
                    if 0 in y[:-1]:
                        print("No")
                    else:
                        print("Yes") 

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

int main() {
    string s; cin >> s;
    if (s[2]==s[3] and s[4]==s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

namespace ConsoleApp21 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            int length = S.Length;

            int ans = 0;
            
            for (int i = 0; i < length - 2; i++) {
                if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
                    ans++;
                }

            }


            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define eb emplace_back

int in(){int x;cin>>x;return x;}


    
#define ll long long
vector<vector<int>> g;
vector<int> nxt;
constexpr ll MOD = 1000003;

main(){
    while(1){
        int n=in(),m=in();
        if(!n)return 0;
        g=vector<vector<int>>(n);
        vector<vector<int>> v(2);
        using P = pair<int,int> ;
        vector<P> ed;
        rep(i,m){
            int a=in()-1,b=in()-1;
            if(a>b)swap(a,b);
            if((a+b)&1){
                g[a].pb(b);
                v[a&1].pb(a);
                ed.eb(P(a,b));
            }
        }
        if(n&1){
            cout<<0<<endl;continue;
        }
        #define all(c) (c).begin(),(c).end()
        vector<pair<int,ll>> dp(n);
        ed.emplace_back(0,n-1);
        sort(all(ed),[](P x,P y){return x.second-x.first<y.second-y.first;});
        rep(i,n-1) dp[i] = P(i+1,1);
        for(auto p:ed){
            int a = p.first,b=p.second;
            ll ans = 1;
            int now = a+1;
            while(now!=b){
                ans=(ans*dp[now].second)%MOD;
                now = dp[now].first+1;
            }
            dp[a+1]={b-1,ans};
            now = a,ans = 1;
            while(now!=b+1){
                ans = (ans*dp[now].second)%MOD;
                now = dp[now].first+1;
            }
            ans+=dp[a+1].second;
            if(ans>=MOD)ans-=MOD;
            dp[a] = {b,ans};
        }
        cout<<dp[0].second<<endl;
    }
}


Measured memory_bytes: 6688
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	long long X, K, D;
	cin >> X >> K >> D;
	while (1) {
		if ((abs(X) <= D && K % 2 == 0) || K == 0) {
			break;
		}
		if (X < 0) {
			if (D <= abs(X)) {
				long long buf = min(abs(X) / D, K);
				K -= buf;
				X = X + buf * D;
			}
			else {
				X += D;
				--K;
			}
		}
		else {
			if (D <= X) {
				long long buf = min(X / D, K);
				K -= buf;
				X = X - buf * D;
			}
			else {
				X -= D;
				--K;
			}
		}
	}

	cout << abs(X) << endl;

	return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  int a = count(ALL(s),'a');
  int b = count(ALL(s),'b');
  int c = count(ALL(s),'c');
  int mn = min({a,b,c});
  int mx = max({a,b,c});
  if(mx-mn <= 1){
    puts("YES");
  }else{
    puts("NO");
  }
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2002;

int dp[MAX][MAX];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int H, W;
    cin >> H >> W;
    char S[MAX][MAX];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> S[i][j];
        }
    }

    for (int i = 0; i < H; i++) {
        int tmp[MAX];
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#') {
                tmp[j] = 0;
            } else {
                if (j == 0) {
                    tmp[j] = 1;
                } else {
                    tmp[j] = tmp[j-1] + 1;
                }
            }
            dp[i][j] += tmp[j];
        }
    }
    for (int i = 0; i < W; i++) {
        int tmp[MAX];
        for (int j = 0; j < H; j++) {
            if (S[j][i] == '#') {
                tmp[j] = 0;
            } else {
                if (j == 0) {
                    tmp[j] = 1;
                } else {
                    tmp[j] = tmp[j-1] + 1;
                }
            }
            dp[j][i] += tmp[j];
        }
    }
    for (int i = 0; i < H; i++) {
        int tmp[MAX];
        for (int j = 0; j < W; j++) {
            if (S[i][W - j - 1] == '#') {
                tmp[j] = 0;
            } else {
                if (j == 0) {
                    tmp[j] = 1;
                } else {
                    tmp[j] = tmp[j-1] + 1;
                }
            }
            dp[i][W - j - 1] += tmp[j];
        }
    }
    int maxv = 0;
    for (int i = 0; i < W; i++) {
        int tmp[MAX];
        for (int j = 0; j < H; j++) {
            if (S[H - j - 1][i] == '#') {
                tmp[j] = 0;
            } else {
                if (j == 0) {
                    tmp[j] = 1;
                } else {
                    tmp[j] = tmp[j-1] + 1;
                }
            }
            dp[H - j - 1][i] += tmp[j];
            maxv = max(maxv, dp[H - j - 1][i]);
        }
    }
    cout << max(0, maxv - 3) << endl;



    return 0;
}


Measured memory_bytes: 19840
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int a, b, j=0;
      cin >> a >> b;
      
      for (int i=a; i <= b; i++){
        int x = i;
        if (x/10000 == x%10 && (x/1000)-10*(x/10000) == ((x%100)-(x%10))/10){
          j++;
        }  
      }
      
      cout << j << endl;
      
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 300 * 1000 + 10;
int dp[N], fr[N], nd[N];
int main() {
	ios_base::sync_with_stdio (false);
	cin.tie(0);
	int q = 1;
	while(q--) {
		int n;
		cin >> n;
		vector<int> v;
		for (int i = 0; i < n; i++) {
			int x;
			cin >> x;
			x--;
			nd[x] = i + 1;
			if (!fr[x]) {
				fr[x] = i + 1;
				v.push_back(x);
			}
		}
		sort(v.begin(), v.end());
		int sz = v.size();
		int ans = N;
		dp[sz - 1] = 1;
		for (int i = (int) v.size() - 2; i >= 0; i--) {
			dp[i] = 1;
			if (nd[v[i]] < fr[v[i + 1]])
				dp[i] += dp[i + 1];
//			cout << "i = " << i << " : " << dp[i] << endl;
		}
		for (int i = 0; i < sz; i++) {
			ans = min(ans, i + (sz - i - dp[i]));
		}
		cout << ans << "\n";
		for (int i = 0; i <= n; i++) 
			dp[i] = nd[i] = fr[i] = 0;
	}
	return 0;
}
	


Measured memory_bytes: 3572
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
constexpr int MX = 1e5+5;
vector<int> G[MX];
vector<bool> visited(MX, false);
vector<int> dist(MX, 0);

int dfs(int cur) {
	int res = 0;
	visited[cur] = true;
	for(int &to: G[cur]) {
		if(!visited[to]) {
			chmax(res, 1+dfs(to));
		} else chmax(res, 1+dist[to]);
	}
	dist[cur] = res;
	return res;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
	int n,m; cin >> n >>m;
	rep(i,m) {
		int x,y; cin >> x >> y; x--; y--;
		G[x].push_back(y);
		// G[y].push_back(x);
	}

	rep(i,n) {
		if(!visited[i]) dfs(i);
	}

	int ans = 0;
	rep(i,n) {
		// cout << dist[i] << " ";
		chmax(ans, dist[i]);
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  string str;
  cin >> str;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i)
  {
    string s;
    cin >> s;
    int a, b;
    cin >> a >> b;
    if (s == "print")
      cout << str.substr(a, b - a + 1) << endl;
    else if (s == "reverse")
    {
      string t = str.substr(a, b - a + 1);
      reverse(t.begin(), t.end());
      str.replace(a, b - a + 1, t);
    }
    else
    {
      string p;
      cin >> p;
      str.replace(a, b - a + 1, p);
    }
  }

  return 0;
}



Measured memory_bytes: 3212
N, M = map(int, input().split())
ship1 = set([])
ship2 = set([])
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        ship1.add(b)
    elif b == N:
        ship2.add(a)

if len(ship1 & ship2) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 19024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int k = std.nextInt();
        int[] hs = new int[n];
        long[] dp = new long[n + 1];
        for (int i = 0; i < n; i++) {
            hs[i] = std.nextInt();
        }
        Arrays.fill(dp, Long.MAX_VALUE);

        dp[0] = 0;

        long ans = rec(dp, n - 1, k, hs);
        System.out.println(ans);
    }

    static long rec(long[] dp, int i, int step, int[] hs) {
        if (dp[i] < Long.MAX_VALUE) {
            return dp[i];
        }

        if (i == 0) {
            dp[0] = 0;
            return 0;
        }

        long min = Long.MAX_VALUE;
        for (int j = 1; j <= step; j++) {
            if (j > i) {
                continue;
            }
            long cost = rec (dp,i - j, step, hs) + Math.abs(hs[i] - hs[i - j]);
            min = Math.min(cost, min);
        }

        dp[i] = min;
        return dp[i];
    }
}


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

// aを常に小さい値にする
template<class T> void chmin(T &a, T b){ if(a>b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 *  f(A, B) = f(0, B) ^ f(0, A-1) という分解ができる（累積和）
 *
 *  つまりf(0, N) を求めることができればOKとなる
 *  ただし、ループは10^12オーダーなので使えない何か別の方法を考える必要がある。
 *
 *  「任意の偶数とその次の奇数のXORは必ず1になる」という性質に着目します。
 *  これは偶数とその次の奇数を2進数で表した場合に、1bit目だけが異なることから明らかです。
 *
 *  f(0,N) = 0 ^ 1 ^ 2 ^ 3 ^ ... ^ N-1 ^ N
 *         = (0^1) ^ (2^3) ^ ... ^ N-1) ^ N  / または  (N-1^N)
 *         =   1   ^   1   ^     ^  1   ^ N  /           1
 *
 *   つまり 4 ずつ0が表れる周期的な動きになる
 *   Nを４で割った余りが
 *   　0の時: f(0,N) = N (4,8,12など)
 *     1の時: f(0,N) = 1
 *     2の時: f(0,N) = N ^ 1
 *     3の時: f(0,N) = 0
 *   となる
 * */

ll f(ll n){
    switch(n%4){
        case 0:
            return n;
        case 1:
            return 1;
        case 2:
            return n ^ 1;
        case 3:
            return 0;
    }
}

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

    ll res = f(A-1) ^ f(B);

    cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()

{
    int i,j,a,b,c,d,n,m;
    scanf("%d",&m);
    scanf("%d ",&n);
    char ar[m+2][n+2];
    for(i=0;i<m+2;i++)
    {
      for(j=0;j<n+2;j++)
      {
          ar[i][j]='#';
      }
    }
 
     for(a=1;a<=m;a++)
    {
      for(b=1;b<=n;b++)
      {
          if(b==n && a!=m)
            scanf("%c ",&ar[a][b]);
          else
            scanf("%c",&ar[a][b]);
      }
    }
     for(c=0;c<m+2;c++)
    {
      for(d=0;d<n+2;d++)
      {
          printf("%c",ar[c][d]);

      }
    printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

int main(){
  int a1,b1,c1,d1,a2,b2,c2,d2,s,t;

  scanf("%d %d %d %d",&a1,&b1,&c1,&d1);
  scanf("%d %d %d %d",&a2,&b2,&c2,&d2);

  s=a1+b1+c1+d1;
  t=a2+b2+c2+d2;

  if(s == t){
    printf("%d\n",s);
  }
  else if(s > t){
    printf("%d\n",s);
  }
  else{
    printf("%d\n",t);
  }

  return 0;
}

Measured memory_bytes: 1020
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        
        int[] array = new int[n];
        for (int i = 0; i < q; i++) {
            int player = sc.nextInt() - 1;
            array[player]++;
        }
        
        for (int i = 0; i < n; i++) {
            if (k - (q - array[i]) > 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 51164
#include<bits/stdc++.h> 
using namespace std;
int main() 
{
	int N,K,b=0;
	cin>>N>>K;
	int a[N];
	for(int i=0;i<N;i++)
	cin>>a[i];
	sort(a,a+N); 
	for(int i=0;i<K;i++)
	b=b+a[i];
	cout<<b;
	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>

int bitcount(int a){
	int count = 0;
	for(int i = 0; i < 10; i++){
		if(a & (1 << i))count++;
	}
	return count;
}

int main(void){
	int n, m;
	scanf("%d %d", &n, &m);
	unsigned int *sw = malloc(sizeof(unsigned int) * n);
	int k;
	int in;
	for(int i = 0; i < m; i++){
		scanf("%d", &k);
		sw[i] = 0;
		for(int j = 0; j < k; j++){
			scanf("%d", &in);
			sw[i] |= (1 << (in - 1));
		}
	}
	int *p = malloc(sizeof(int) * m);
	for(int i = 0; i < m; i++)
		scanf("%d", p + i);
	int count = 0;
	for(int i = 0; i < (1 << n); i++){
		for(int j = 0; j < m; j++){
			if(bitcount(sw[j] & i) % 2 != p[j])break;
			if(j == m - 1)count++;
		}
	}
	printf("%d\n", count);
	return 0;
}


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

int main() {
  int N;
  string S;
  string T;
  cin >> N;
  cin >> S >> T;
  for (int i = 0; i < N; i++) {
    cout << S.at(i);
    cout << T.at(i);
  }
}

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

struct UnionFind
{
	int N;
	vector<int> parent;
	vector<int> size_r;
	int num_of_sets;

	UnionFind(int N) : N(N), parent(N), size_r(N, 1), num_of_sets(N) {
		for (int i = 0; i < N; ++i) parent[i] = i;
	}

	int root(int x) {
		if (parent[x] == x) return x;
		return parent[x] = root(parent[x]);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (size_r[x] < size_r[y]) swap(x, y);
		parent[y] = x;
		size_r[x] += size_r[y];
		size_r[y] = 0;
		num_of_sets--;
		return true;
	}

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

	int size(int x) {
		return size_r[root(x)];
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	UnionFind uf(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		uf.merge(a, b);
	}
	int ans = uf.num_of_sets - 1;
	cout << ans << endl;
	return 0;
}

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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {
  
  int n,d,x;
  cin >> n >> d >> x;
  
  int count = 0;
  
  vector<int> a(n);
  for ( int i = 0; i < n; i++){
    cin >> a[i];
    int j = 0;
    while( j * a[i] + 1 <= d ){
      count++;
      j++;
    }
  }
  
  cout << x + count << endl;

}


Measured memory_bytes: 256
import sys

N = int(input())
items = []
for i in range(N):
  item = input()
  items.append(item)

if(len(items) != len(set(items))):
  print('No')
  sys.exit()

for i in range(len(items)):
  if(i != 0 and items[i][0] != items[i-1][-1]):
    print('No')
    sys.exit()

print('Yes')


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 100000;
const long double PI = acos(-1);

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, r;
    cin >> r >> n;

    vector<int> v(2*n);

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


    int ans = oo;

    for (int i=0; i<n; i++){
        ans = min(ans, v[i+n-1] - v[i]);
    }

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

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

using namespace std;

const int INF = 1e9;
const int N = 1e4;
const int MOD = 998244353;
const double EPS = 1e-6;

const double PI = acos(-1);




int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    long long h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1;
        return 0;
    }
    long long ans = (h / 2) * (w / 2) + (w / 2 + w % 2) * (h / 2 + h % 2);
    cout << ans;
}

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

int main()
{
  int n, count = 0;
  int ls[200];
  bool flag;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> ls[i];
    
  while (true)
  {
    flag = false;
    for (int i = 0; i < n; i++)
    {
      if (ls[i] % 2 == 1) flag = true;
      ls[i] /= 2;
    }
    if (flag) break;
    count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
/*
ID: seekho
PROG: friday
LANG: C++14                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
// const int N = 100005;

map<int,int> M;

int32_t main() {

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

    int n;
    cin >> n;

    vector<int> a(n);
    rep(i,n) cin >> a[i];

    sort(all(a));

    int mx = a[n-1];
    int sum = 0;
    repD(i,n-2,0) sum += a[i];

    if(sum > mx) {
        cout << "Yes\n";
    }
    else cout << "No\n";
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
//#pragma GCC target ("avx")
//#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1e17;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

int main(){
	INIT;
	ll n;
	cin>>n;
	vector<ll> a(n), b(n);
	rep(i, n) cin>>a[i]>>b[i];
	if(a==b){
		cout<<0<<endl;
		return 0;
	}
	ll sum = 0, mn = INF;
	rep(i, n){
		sum += b[i];
		if(a[i]>b[i]) chmin(mn, b[i]);
	}
	cout<<sum-mn<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265
int main()  
{     
    vector<ll> v(3);
    for(ll i=0;i<3;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    if(v[2]==7&&v[1]==5&&v[0]==5)
        cout<<"YES";
    else
        cout<<"NO";
    //cin>>a>>b>>c;

}   

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
ks_m = m.times.map{|_| gets.split.map(&:to_i)}
p_m = gets.split.map(&:to_i)

ans = 0
[0, 1].repeated_permutation(n).to_a.each do |c|
  lighted = 0
  ks_m.each.with_index do |ks, idx|
    on = 0
    (1..ks[0]).each do |i|
      on += 1 if c[ks[i]-1] == 1
    end
    if on % 2 == p_m[idx]
      lighted += 1
    end
  end
  if lighted == m
    ans += 1
  end
end
p ans

Measured memory_bytes: 14288
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll h, w, n;
    cin >> h >> w >> n;
    map<pair<ll, ll>, ll> count;
    REP(i, n){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        for(ll da = -1; da <= 1; ++da){
            for(ll db = -1; db <= 1; ++db){
                if(a + da >= 0 && a + da < h && b + db >= 0 && b + db < w){
                    count[make_pair(a + da, b + db)]++;
                }
            }
        }
    }

    vector<ll> ans(10, 0);
    ans.at(0) = (h - 2) * (w - 2);
    for(auto it = count.begin(); it != count.end(); ++it){
        if(it->first.first == 0 || it->first.first == h - 1 ||
           it->first.second == 0 || it->first.second == w - 1){
            continue;
        }
        ans.at(it->second)++;
        ans.at(0)--;
    }

    REP(i, 10){
        cout << ans.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 56448