akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int V1, V2;
int size[1002];
int to[1002][1002];
int dist[1002];
int match[1002];
const int NIL = 1001;
bool BFS(){
  queue<int> que;
  REP(v, V1){
    if(match[v] == NIL){
      dist[v] = 0;
      que.push(v);
    }else{
      dist[v] = INF;
    }
  }
  dist[NIL] = INF;
  while(!que.empty()){
    int v = que.front(); que.pop();
    if(dist[v] < dist[NIL]){
      for(int i = 0; i < size[v]; i++){
        int u = to[v][i];
        if(dist[match[u]] == INF){
          dist[match[u]] = dist[v] + 1;
          que.push(match[u]);
        }
      }
    }
  }
  return dist[NIL] != INF;
}

bool DFS(int v){
  if(v != NIL){
    for(int i = 0; i < size[v]; i++){
      int u = to[v][i];
      if(dist[match[u]] == dist[v] + 1 && DFS(match[u])){
        match[u] = v;
        match[v] = u;
        return true;
      }
    }
    dist[v] = INF;
    return false;
  }
  return true;
}

int Hopcroft_Karp(){
  REP(v, V1 + V2) match[v] = NIL;
  int matching = 0;
  while(BFS()){
    REP(v, V1){
      if(match[v] == NIL && DFS(v)){
        matching ++;
      }
    }
  }
  return matching;
}
int main(){
  while(scanf("%d %d", &V1, &V2) && (V1 != 0 || V2 != 0)){
    REP(i, V1) size[i] = 0;
    static int blue[500];
    static int red[500];
    REP(i, V1) scanf("%d", blue + i);
    REP(i, V2) scanf("%d", red + i);
    REP(u, V1) REP(v, V2){
      if(__gcd(blue[u], red[v]) != 1) {
        to[u][size[u]++] = V1 + v;
        //G[u].push_back(V1 + v);
        //G[V1 + v].push_back(u);
      }
    }
    printf("%d\n", Hopcroft_Karp());
  }
  return 0;
}

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

int main(){
	vector<long long> p;
	for(int i = 2 ; i <= 100000 ; i++){
		int f = true;
		for(int j = 2 ; j * j <= i ; j++)
			if( i % j == 0 ){f = 0; break; }
		if( f ){
			p.push_back(i);
		}
	}
	long long m,a,b;
	while(cin >> m >> a >> b && m ){
		long long ans = 0;
		long long A = 0;

		for(int i = 0 ; i < p.size() ; i++){
			for(int j = i ; j < p.size() ; j++){
				if( p[i] * p[j] <= m && a*p[j] <= p[i]*b){
					if( p[i]*p[j] > ans ){
						ans = p[i]*p[j];
						A = p[i];
					}
				}else if( p[i] * p[j] > m ){
					break;
				}
			}
		}
		cout << A << " " << ans / A << endl;
	}
	
}

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

int main()
{
 int N;
  cin>>N;
  vector<int> A(N);
  bool check=0;//0 means ok
  for(int i=0;i<N;i++)
  {
   cin>>A[i];
    if(A[i]%2==0)
    {
      //cout<<2<<endl;
     if((A[i]%3!=0)&&(A[i]%5!=0))
     {
      check =1;
     }
    }
  }
  if(check==0){cout<<"APPROVED"<<endl;}
  else{cout<<"DENIED"<<endl;}
}


Measured memory_bytes: 256
#include<stdio.h>
#define BUFSIZE 100

int main(void){
    int N;
    char S[BUFSIZE], T[BUFSIZE];

    scanf("%d", &N);
    scanf("%s %s", S, T);

    for(int i = 0; i < N; i++){
        printf("%c%c", S[i], T[i]);
    }
    putchar('\n');

    return 0;
}

Measured memory_bytes: 128
import java.io.*;

public class Main{
	/*
	public static long findGcd(long f1, long f2){
		long gcd = 1;
		long max, min;
		if(f1 > f2){max = f1; min = f2;}
		else{max = f2; min = f1;}
		for(long i=1; i<=(long)(Math.sqrt(min)+1); i++){
			if(min % i == 0){
				long tmp = min / i;
				if((max % tmp) == 0){
					gcd = tmp;
					break;
				}
			}
		}
		return gcd;
	}
	*/
	
	public static long findlcm(long f1, long f2){
		long lcm = 0;
		long max, min;
		if(f1 > f2){max = f1; min = f2;}
		else{max = f2; min = f1;}
		long i=1;
		while(lcm == 0){
			if((max * i)%min == 0){
				lcm = max * i;
			}
			i++;
		}
		return lcm;
	}
	
	
	//最大公約数を求めるメソッド
    static long findGcd(long x, long y){
        if(x%y==0){
            return y;
        }else{
            long m = 1;
            while(m!=0){
                m = y%x;
                y = x;
                x = m;
            }
            return y;
        }
    }
    /*
    //最小公倍数を求めるメソッド
    static long findlcm(long x, long y){
        for(long i=1; i<=x; i++){
            if(y*i%x==0){
                return y*i;
            }
        }
        return 0;
    }
    */
	
	public static void main(String[] argv) throws NumberFormatException, IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while((line = br.readLine()) != null){
			String[] lineArray = line.split(" ");
			long[] factor = {Long.parseLong(lineArray[0]), Long.parseLong(lineArray[1])};
			long gcd = findGcd(factor[0], factor[1]);
			long lcm = findlcm(factor[0], factor[1]);
			System.out.println(gcd + " " + lcm);
		}
	}
}

Measured memory_bytes: 16948
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

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

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn prime_fact(m: usize) -> BTreeMap<usize, usize> {
    let mut m = m;
    let mx = (m as f64).sqrt() as usize;
    let mut map = BTreeMap::new();
    for i in 2..mx+1 {
        while m % i == 0 {
            m /= i;
            *map.entry(i).or_insert(0) += 1;
        }
    }
    if m > 1 {
        map.insert(m, 1);
    }
    map
}

fn solve() {
    let (n,p) = get!(usize, usize);
    let map = prime_fact(p);
    let mut g = 1;
    for (key, val) in map {
        g *= key.pow((val/n) as u32);
    }
    println!("{}", g);
}


Measured memory_bytes: 8572
#include<iostream>

using namespace std;

int main(){
  int n;
  int m;
  cin>>n;//読み込み
  cin>>m;
  //cout<<n<<endl;//System.out.println
  if((m*n)%2==0){
    cout<<"Even"<<endl;
  }else{
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> store;
#define price first
#define amount second

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

    int n, m;
    cin >> n >> m;
    vector<store> stores(n);
    for (store &st : stores) {
        cin >> st.price >> st.amount;
    }
    ll ans = 0;
    sort(stores.begin(), stores.end());
    for (int i = 0; i < stores.size() && m > 0; ++i) {
        ans += min(stores[i].amount, m)*stores[i].price;
        m -= stores[i].amount;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> v(2*N);
  for(int i=0;i<N;i++){
    int a,b;
    cin >> a >> b;
    v[2*i]=make_pair(a,0);
    v[2*i+1]=make_pair(b,1);
  }

  sort(v.begin(),v.end());
  //for(auto vi:v) cout << vi.first << " " << vi.second << endl;

  int ans=0;
  int n0=0,n1=0;
  int a0=-1,a1=-1;
  int b0=-1,b1=-1;
  for(int i=0;i<2*N;i++){
    if(v[i].second==0){
      n1++;
    }else{
      n0++;
    }
    if(n0<(N+1)/2 && (N+1)/2<=n1){
      if(a0==-1) a0=v[i].first;
    }else if(a0!=-1 && a1 == -1){
      a1=v[i].first;
    }
    if(n0<N/2+1 && N/2+1<=n1){
      if(b0==-1) b0=v[i].first;
    }else if(b0!=-1 && b1 == -1){
      b1=v[i].first;
    }
  }

  //cout << a0 << " " << a1 << endl;
  //cout << b0 << " " << b1 << endl;


  if(N%2==1){
    cout << a1-a0+1 << endl;
  }else{
    cout << a1+b1-a0-b0+1 << endl; 
  }

  return 0;
}


Measured memory_bytes: 6428
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  ll ans=(n+1)/2;
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 500;
int v[5 + nmax];
int sol[5 + nmax * nmax];

int main() {
  int n;
  std::cin >> n;
  for(int i = 1;i <= n; i++)
    std::cin >> v[i];
  std::vector<std::pair<int,int>> cond(1 + n);
  for(int i = 1;i <= n; i++)
    cond[i] = {v[i], i};
  std::sort(cond.begin() + 1, cond.end());
  for(int i = 1;i <= n; i++)
    sol[v[i]] = i;

  int ptr = 1, step = 0;
  for(int i = 1;i <= n; i++) {
    int val = cond[i].second;
    int pos = cond[i].first;
    for(int j = 1; j < val; j++) {
      while(0 < sol[ptr] && ptr < pos)
        ptr++;
      if(ptr == pos) {
        std::cout << "No";
        return 0;
      }
      sol[ptr] = val;
    }
  }
  ptr = n * n;
  for(int i = n; 1 <= i; i--) {
    int val = cond[i].second;
    int pos = cond[i].first;
    for(int j = n; val < j; j--) {
      while(0 < sol[ptr] && pos < ptr)
        ptr--;
      if(ptr == pos) {
        std::cout << "No";
        return 0;
      }
      sol[ptr] = val;
    }
  }
  std::cout << "Yes\n";
  for(int i = 1;i <= n * n; i++)
    std::cout << sol[i] << " ";
}


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll h,w,a,b;cin >> h >> w >> a >> b;
    string s;
    rep(i,a)s+='1';
    rep(i,w-a)s+='0';
    rep(i,b){
        cout << s << endl;
    }
    rep(i,w)s[i]^='0'^'1';
    rep(i,h-b){
        cout << s <<endl;
    }
}


Measured memory_bytes: 3580
#include <iostream>
#include<vector>
#include<queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    int n;
    cin >> n;
    vector<vector<int>>a(n,vector<int>(n-1));
    vector<queue<int>>b(n);
    rep(i,n) {
        rep(j,n-1) {
            cin >> a[i][j];
            a[i][j]--;
            b[i].push(a[i][j]);
        }
    }
    int ans = 0;
    int all = n*(n-1)/2;
    bool match;
    while(1) {
        vector<int>p(n);
        if(all==0) break;
        match = false;

        rep(i,n) {
            if(b[i].empty()) continue;
            if(p[i]>0 || p[b[i].front()]>0) continue;
            if(b[b[i].front()].front()==i) {
                p[i]++; p[b[i].front()]++;
                b[b[i].front()].pop(); b[i].pop();
                match = true;
                all--;
            }
        }
        if(!match) {
            cout << -1 << endl;
            return 0;
        }
        ans++;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 11792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll Nagaemon1;
void swap(ll i,ll j){
  Nagaemon1=i;
  i=j;
  j=Nagaemon1;
}
int main(){
  int n,m,y;
  cin >> n >> m >> y;
  int c[n],a[n][m];
  rep(i,n){
    cin >> c[i];
    rep(j,m){
      cin >> a[i][j];
    }
  }
  int x[12];
  int w[m];
  int t=0;
  int q,u=99999999;
  for(x[0]=0;x[0]<2;x[0]++){
    for(x[1]=0;x[1]<2;x[1]++){
      for(x[2]=0;x[2]<2;x[2]++){
        for(x[3]=0;x[3]<2;x[3]++){
          for(x[4]=0;x[4]<2;x[4]++){
            for(x[5]=0;x[5]<2;x[5]++){
              for(x[6]=0;x[6]<2;x[6]++){
                for(x[7]=0;x[7]<2;x[7]++){
                  for(x[8]=0;x[8]<2;x[8]++){
                    for(x[9]=0;x[9]<2;x[9]++){
                      for(x[10]=0;x[10]<2;x[10]++){
                        for(x[11]=0;x[11]<2;x[11]++){
                          rep(i,m){
                            w[i]=0;
                          }
                          q=0;
                          rep(i,n){
                            if(x[i]==1){
                              q+=c[i];
                              rep(j,m){
                                w[j]+=a[i][j];
                              }
                            }
                          }
                          rep(i,m){
                            if(w[i]<y){
                              t=1;
                              break;
                            }
                          }
                          if(t==1){
                            t=0;
                            continue;
                          }
                          if(u>q)u=q;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  if(u==99999999)cout << -1;
  else cout << u;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> vec(h);
  for (int i=0;i<h;i++){
    cin >> vec.at(i);
  }
  for (int i=0;i<h;i++){
    for (int j=0;j<w;j++){
      char s = vec.at(i).at(j);
      int t = 0;
      if (s == '.'){
        if (i>0 && j>0 && vec.at(i-1).at(j-1) == '#'){
          t++;
        }
        if (i>0 && vec.at(i-1).at(j) == '#'){
          t++;
        }
        if (i>0 && j<w-1 && vec.at(i-1).at(j+1) == '#'){
          t++;
        }
        if (j>0 && vec.at(i).at(j-1) == '#'){
          t++;
        }
        if (j<w-1 && vec.at(i).at(j+1) == '#'){
          t++;
        }
        if (j>0 && i < h-1 && vec.at(i+1).at(j-1) == '#'){
          t++;
        }
        if (i<h-1 && vec.at(i+1).at(j) == '#'){
          t++;
        }
        if (i<h-1 && j<w-1 && vec.at(i+1).at(j+1) == '#'){
          t++;
        }
        vec.at(i).at(j) = '0' + t;
      }
    }
  }
  for (int i=0;i<h;i++){
    cout << vec.at(i) << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans=1,k,n;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		if(ans<k) ans+=ans;
		else ans+=k;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <math.h>
int main(){
    int ban,i=0,bmi,cnt=0,kiroku[1000];
    double tai[1000],sin[1000];
    while(scanf("%d,%lf,%lf",&ban,&tai[i],&sin[i])!=EOF){
        bmi=tai[i]/(sin[i]*sin[i]);
        if(bmi>=25){
            kiroku[cnt]=ban;
            cnt++;
        }
        i++;
    }
    for(i=0;i<cnt;i++){
        printf("%d\n",kiroku[i]);
    }
    return 0;
}

Measured memory_bytes: 1064
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
			String str = in.nextLine();
			int total = 700;
			if(str.charAt(0) == 'o')
				total += 100;
			if(str.charAt(1) == 'o')
				total += 100;
			if(str.charAt(2) == 'o')
				total += 100;
		    System.out.println(total);
	}
    
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;
#define INF 1e9

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



int main(){
  ll x;
  cin >> x;

  ll ans = 0;
  ans = x / 11 * 2;
  if(x % 11 > 6){
    ans += 2;
  }
  else if(x % 11 > 0){
    ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[] dx = {1,0,-1,0};
		int[] dy = {0,1,0,-1};
		int max = 0;

		String[][] maze = new String[h][w];
		for(int i = 0; i < h; i++) {
			maze[i] = sc.next().split("");
		}

		for (int sx = 0; sx < h; sx++) {
			for (int sy = 0; sy < w; sy++) {
				int[][] d = new int[h][w];
				if(maze[sx][sy].equals("#")) continue;
				for(int i = 0; i < h; i++) {
					for(int j = 0; j < w; j++ ) {
						d[i][j] = 1000;
					}
				}
				d[sx][sy] = 0;
				point point = new point(sx, sy);
				Queue<point> que = new ArrayDeque<point>();
				que.add(point);
				while(0 != que.size()) {
					point p = que.poll();
					for(int i = 0; i < 4; i++) {
						int cx = p.x + dx[i];
						int cy = p.y + dy[i];
						if(cx >= 0 && cx <= h-1 && cy >= 0 && cy <= w-1 && !maze[cx][cy].equals("#")  && d[cx][cy] == 1000) {
							d[cx][cy] = d[p.x][p.y] + 1;
							que.add(new point(cx, cy));
						}
					}
				}
				for (int i = 0; i < h; i++) {
					for (int j = 0; j < w; j++) {
						if(d[i][j] < 1000) max = Math.max(max, d[i][j]);
					}
				}
			}
		}
		System.out.println(max);
	}
	public static class point{
		int x; int y;
		point(int x,int y){
			this.x = x; this.y =y;
		}
	}
}


Measured memory_bytes: 27732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		Map<Integer,Integer> map = new HashMap<>();
		for(int i = 0; i < n-1; i++) {
			int a = sc.nextInt();
			if(map.containsKey(a)) {
				map.put(a, map.get(a)+1);
			}else {
				map.put(a, 1);
			}
		}
		
		for(int i = 1; i <= n; i++) {
			if(map.containsKey(i)) {
				System.out.println(map.get(i));
			}else {
				System.out.println(0);
			}
		}
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

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

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

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


#define ll long long
#define ld long double
#define ull unsigned long long
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long ,long long>
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007


 
//     long long power(long long x, long long y, long long p) 
// { 
//     long long res = 1;      
  
//     x = x % p;  
  
//     while (y > 0) 
//     { 
      
//         if (y & 1) 
//             res = (res*x) % p; 

//         y = y>>1; 
//         x = (x*x) % p; 
//     } 
//     return res; 
// } 
  

// long long modInverse(long long n, long long p) 
// { 
//     return power(n, p-2, p); 
// }  

// long long ncrp(long long n, long long r, long long p) 
// { 
   
//    if (r==0) 
//       return 1; 
  
    
//     long long fac[n+1]; 
//     fac[0] = 1; 
//     // for (long long i=1 ; i<=n; i++) 
//     //     fac[i] = fac[i-1]*i%p; 
  
//     return (fac[n]* modInverse(fac[r], p) % p * 
//             modInverse(fac[n-r], p) % p) % p; 
// }




int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);


   if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
   

   ll n,x,y,z;
   cin>>n;

   ll i;
   ll a[n][3];
   ll dp[n][3];
    
for(i=0;i<n;i++)
{
    // cin>>x>>y>>z;
    cin>>a[i][0]>>a[i][1]>>a[i][2];


}

dp[0][0]=a[0][0];
dp[0][1]=a[0][1];
dp[0][2]=a[0][2];


  for(i=1;i<n;i++)
  {
      dp[i][0]=max(dp[i-1][1]+a[i][0],dp[i-1][2]+a[i][0]);
       dp[i][1]=max(dp[i-1][0]+a[i][1],dp[i-1][2]+a[i][1]);
        dp[i][2]=max(dp[i-1][1]+a[i][2],dp[i-1][0]+a[i][2]);

  }


  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;



 



  

    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  int x,y;cin>>x>>y;
  string ans="No";
  rep(i,x+1){
    if(y==i*2+(x-i)*4)ans="Yes";
  }
  cout<<ans;
}

Measured memory_bytes: 3624
N,M=map(int, input().split())

if abs(N-M)>1:
    print(0)
    exit()

p = 10 ** 9 + 7
n = 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p) 階乗のmod
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

if N==M:
    ans=2*fact[N]*fact[M] % p
else:
    big = max(N, M)
    small = min(N, M)
    ans = fact[N]*fact[M] % p

print(ans)


Measured memory_bytes: 86844
'''
Created on Mar 1, 2020

@author: dell
'''
arr=[]
for i in range(3):
    a=list(map(int,input().split()))
    arr.append(a)
n=int(input())
f=0
lst=[]
for i in range(n):
    a=int(input())
    lst.append(a)
if(arr[0][0] in lst and arr[1][1] in lst and arr[2][2] in lst):
    print("Yes")
elif(arr[0][2] in lst and arr[1][1] in lst and arr[2][0] in lst):
    print("Yes")
else:
    for i in range(3):
        f=0
        for j in range(3):
            if(arr[i][j] not in lst):
                f=1
        if(f==0):
            print("Yes")
            break
if(f==1):
    for i in range(3):
        f=0
        for j in range(3):
            if(arr[j][i] not in lst):
                f=1
        if(f==0):
            print("Yes")
            break
if(f==1):
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int a, b, c, x, y, min;
  cin >> a >> b >> c >> x >> y;
  if(a+b < 2*c){
    cout << a*x + b*y << endl;
  }
  else {
    if(x>=y){
      if(a>2*c) cout << 2*c*x << endl;
      else cout << 2*c*y+a*(x-y) <<endl;
    }
    else{
      if(b>2*c) cout << 2*c*y << endl;
      else cout << 2*c*x+b*(y-x) <<endl;
    }
  }
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
# dbg = lambda *a, **kw: print(*a, **kw, file=sys.stderr)

N = ini()
P = list(map(int, sys.stdin.readlines()))
INF = 1 << 40


def solve():
    if N == 1:
        return 0

    inds = [None] * (N + 1)
    for i, x in enumerate(P):
        inds[x] = i

    streak = [1] * (N + 1)
    for k in range(2, N + 1):
        if inds[k - 1] < inds[k]:
            streak[k] = streak[k - 1] + 1
    ans = INF
    for k in range(2, N + 1):
        r = 0 if k == P[-1] else 1
        r += N - k
        l = (k - 1) - streak[k - 1]
        if ans > l + r:
            ans = l + r
        # dbg(f"{ans=} {l=} {r=}")
    return ans


print(solve())


Measured memory_bytes: 26676
s = input()
n = len(s) - 1
a = 0
for i in range(2 ** n):
    f = s[0]
    for j in range(n):
        if ((i >> j) & 1):
            f += "+"
        f += s[j + 1]
    a += sum(map(int, f.split("+")))

print(a)

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

using namespace std;

const int N = 405;
const long long INF = 9e18 + 5;

int n; long long a[N], sum[N], f[N][N];

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i]; sum[i] = a[i] + sum[i - 1];
  }
  for (int l = n; l > 0; --l) {
    for (int r = l + 1; r <= n; ++r) {
      f[l][r] = INF;
      for (int mid = l; mid < r; ++mid) {
        f[l][r] = min(f[l][r], sum[r] - sum[l - 1] + f[l][mid] + f[mid + 1][r]);
      }
    }
  }
  cout << f[1][n] << endl;
  return 0;
}



Measured memory_bytes: 1536
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

const int N = 2e5+10;
vector<int> edge[N],dist(N,0);
int id = 0, mx = 0;

void dfs(int no, int par){
  if(par != -1) dist[no] = dist[par]+1;
  if(mx < dist[no]) mx = dist[no], id = no;
  for(int to: edge[no]){
    if(to==par) continue;
    dfs(to,no);
  }
}

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

  int n;
  cin >> n;

  REP(_,n-1){
    int x,y;
    cin >> x >> y;
    x--; y--;
    edge[x].emplace_back(y);
    edge[y].emplace_back(x);
  }

  dfs(0,-1);

  mx = 0; dist.assign(n,0);

  dfs(id,-1);

  //debug(mx);

  if(mx%3 != 1) cout << "First" << endl;
  else cout << "Second" << endl;

  return 0;
}

Measured memory_bytes: 22144
#include <iostream>
using namespace std;
int main(void){
    int n, a[50], b[50], c[50];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    
    int manzok = 0, last = -1;
    for (int i = 0; i < n; i++) {
        manzok += b[a[i]-1];
        if (a[i] == last + 1) {
            manzok += c[last-1];
        }
        last = a[i];
    }
    
    cout << manzok << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N,A;
    cin >> N >> A;
    int ans=0;
    int res=10000;
    int L=A;
    int R=A+N-1;
    int num;
    if(R<=0) num=R;
    else if(L>=0) num=L;
    else num=0;
    ans=(R+L)*(R-L+1)/2-num;
    cout << ans;
    }

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        h: [u64;n],
        ab: [(usize1, usize1); m],
    }
    let mut g = vec![Vec::new();n];
    for (a,b) in ab {
        g[a].push(b);
        g[b].push(a);
    }
    let mut cnt = 0;
    for i in 0..n {
        let mut good = true;
        let v = &g[i];
        for b in v {
            if h[i] <= h[*b] {
                good = false;
                break;
            }
        }
        if good { cnt += 1};
    }
    println!("{}", cnt);
}


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

int main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<char> > table(H, vector<char>(W));

  for (int h = 0; h < H; ++h)
  {
    for (int w = 0; w < W; ++w)
    {
      cin >> table.at(h).at(w);
    }
  }

  vector<bool> row(H, false);
  vector<bool> col(W, false);

  for (int h = 0; h < H; ++h)
  {
    for (int w = 0; w < W; ++w)
    {
      if (table.at(h).at(w) == '#')
      {
        row.at(h) = true;
        col.at(w) = true;
      }
    }
  }
  for (int h = 0; h < H; ++h)
  {
    if (row.at(h))
    {
      for (int w = 0; w < W; ++w)
      {
        if (col.at(w))
        {
          cout << table.at(h).at(w);
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include <cstring>
#include <cstdio>
#include<cstdint>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
const int MOD = 1e9+7;
#define NIL -1
const int INF = 1 << 29;
int main(){
    string n;
    cin>>n;
    int a=n[0]-'0',b=n[1]-'0',c=n[2]-'0',d=n[3]-'0';
    if(a+b+c+d==7)printf("%d+%d+%d+%d=7\n",a,b,c,d);
    else if(a+b+c-d==7)printf("%d+%d+%d-%d=7\n",a,b,c,d);
    else if(a+b-c+d==7)printf("%d+%d-%d+%d=7\n",a,b,c,d);
    else if(a+b-c-d==7)printf("%d+%d-%d-%d=7\n",a,b,c,d);
    else if(a-b+c+d==7)printf("%d-%d+%d+%d=7\n",a,b,c,d);
    else if(a-b+c-d==7)printf("%d-%d+%d-%d=7\n",a,b,c,d);
    else if(a-b-c+d==7)printf("%d-%d-%d+%d=7\n",a,b,c,d);
    else if(a-b-c-d==7)printf("%d-%d-%d-%d=7\n",a,b,c,d);


    
}

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

typedef long long ll;
ll n, k, mx, a[N], b[N];

ll f(ll p) {
	ll i, j, re = 0;
	for (i = 0; i < n; i++) {
		for (j = 0; j <= 30; j++) if (!(p & (1 << j)) && (a[i] & (1 << j))) break;
		if (j > 30) re += b[i];
	}
	return re;
}

int main()
{
	ll i, j, t;
	cin >> n >> k;
	for (i = 0; i < n; i++) scanf("%lld %lld", &a[i], &b[i]);
	mx = f(k);
	for (i = 0; i <= 30; i++) {
		if (!(k & (1 << i))) continue;
		t = k;
		for (j = 0; j < i; j++) t |= 1<<j;
		t ^= 1<<i;
		mx = max(mx, f(t));
	}
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
v pa,szz;
int Find(int u)
{
    if(u==pa[u])
        return u;
    return pa[u]=Find(pa[u]);
}
void Union(int a,int b)
{
    a=Find(a);
    b=Find(b);
    if(a==b)
        return ;
    if(szz[a] > szz[b])
        swap(a,b);
    pa[a]=b;
    szz[b]+=szz[a];
}
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int  n,m;cin>>n>>m;
    pa.resize(n+1);
    szz.resize(n+1);
    for(int i=0;i<=n;i++)
    {
    	pa[i]=i;
    	szz[i]=1;
    }
    f(i,m)
    {
    	int a,b;cin>>a>>b;
    	Union(a,b);
    }
   	int ans=-1;
    for(int i=1;i<=n;i++)
    {
    	if(Find(i)==i)
    		ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4764
# class Node:
#     def __init__(self, data): #コンストラクタ
#         self.data = data #ノードがもつ数値
#         self.left = None #左エッジ
#         self.right = None #右エッジ
#
# class BST:
#     def __init__(self, number_list): #コンストラクタ
#         self.root = None #ルート初期化
#         for node in number_list: #数値を持つ配列から二分木を生成
#             self.insert(node) #挿入メソッドを使ってノードを挿入する
#
#     #挿入
#     def insert(self, data):
#         n = self.root #nにルートを代入
#         if n == None: #ルートに何も入っていない場合
#             self.root = Node(data) #ルートにノードを代入(二分探索木の一番上の部分が出来る)
#             return #呼び出し部分に戻る
#         else: #ルートノードに既に数値が入ってる場合
#             while True: #return等が入るまでずっと実行
#                 entry = n.data #entryにnが持つデータ(数値)を入れる
#                 if data < entry: #entryとdata(代入するデータ)を比較してentryの方が大きい場合
#                     if n.left is None: #nの左エッジに何も入っていない場合
#                         n.left = Node(data) #nの左エッジにdata(代入するデータ)を代入
#                         return ##呼び出し部分に戻る
#                     n = n.left #nの左に何か入っている場合nにnのleftを代入
#                 elif data > entry: #entryとdata(代入するデータ)を比較してentryの方が小さい場合
#                     if n.right is None: #nの右エッジに何も入っていない場合
#                         n.right = Node(data) #nの右エッジにdata(代入するデータ)を代入
#                         return #呼び出し部分に戻る
#                     n = n.right #nの右エッジに何か入っている場合nにnのrightを代入
#                 else: #上2つの条件分岐以外の場合
#                     n.data = data #nのdataにdata(代入するデータ)を代入
#                     return #呼び出し部分に戻る

a, b = map(int, input().split())
s = list(input())
no = 0
if s[a] != "-":
    print("No")
    no = 1
else:
    for i in s[:a] + s[a + 1::]:
        if not ("0" <= i <= "9"):
            print("No")
            no = 1
            break
if not no:
    print("Yes")

Measured memory_bytes: 38256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        String str=s.next();
        if((str.charAt(2)==str.charAt(3))&&(str.charAt(4)==str.charAt(5)))
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

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

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

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

#define FASTIO1 ios_base::sync_with_stdio(false)
#define FASTIO2 cin.tie(NULL),cout.tie(NULL)
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll power(ll x,ll y,ll p);
const ll inf=999999999;
const ll mod=1e9+7;
bool tc=false;

void solve()
{
	ll n; cin>>n;
	cout<<!n;
}

int main() 
{
    FASTIO1;
    FASTIO2;
    clock_t start=clock();
    ll t=1; 
    if(tc) cin>>t;
    while(t--)
        solve();
    cerr<<fixed<<setprecision(6);
    cerr<<(double)(clock()-start)/CLOCKS_PER_SEC<<endl;
    return 0;
}

ll power(ll x,ll y,ll p)  
{  
    ll res=1; x=x%p;
    if(x==0) return 0;
    while(y>0)  
    {
        if(y&1) res=(res*x)%p;
        y=y>>1; x=(x*x)%p;  
    }
    return res;  
}  


Measured memory_bytes: 3796
n,k = map(int,input().split())
A = list(map(int,input().split()))
dp=[0]*n
for i in range(n):
    if i < k:
        dp[i] += dp[i-1] + A[i]
    else:
        dp[i] = dp[i-1] + A[i] - A[i-k]
for i in range(k,n):
    if dp[i-1] < dp[i]:
        print('Yes')
    else:
        print('No')

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

int main() {
  int N;
  cin >> N;
  vector<long long int> A(N);
  for(int i=0;i<N;i++) {
    long long int k;
    cin >> k;
    A[i] = 2 * k;
  }

  long long int total = 0;

  for(int i=0;i<N;i++) {
    total += A[i] * pow(-1, i);
  }

  vector<long long int> ans(N);
  ans[0] = total / 2;

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

  for(int i=0;i<N;i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

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

int main() {

  int s1s2s3, a, b, c;

  cin >> s1s2s3;
  a = s1s2s3 % 10;
  b = (s1s2s3/10) % 10;
  c = (s1s2s3/100) % 10;
  cout << a + b + c  << endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
s=input()
ok=0
x=0
ans=[]
for i in range(n):
    ss=s[i]
    if ss=="a" and ok<a+b:
        ok+=1
        ans.append("Yes")
    elif ss=="b" and ok<a+b and x<b:
        ok+=1
        x+=1
        ans.append("Yes")
    else:
        ans.append("No")

print(*ans, sep="\n")


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


int main (){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  
  rep(i, n-k){
    if(a[i] < a[k+i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;
}

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

int main() {
  int n;
  int cnt = 0;
  int i = 0;
  cin >> n;
  
  for (i = 0; i < 3; i++) {
    if (n % 10 == 1) {
      cnt++;
    }
    n = (n / 10);
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int ans;
int n;
string s[303];
int main() {
  cin >> n;
  for(int i = 0; i < n; i++) cin >> s[i];

  for(int k = 0; k < n; k++) {
    bool exist = true;
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
	if(s[i][(j+k)%n] != s[j][(i+k)%n]) {
	  exist = false;
	  break;
	}
      }
    }
    if(exist) ans++;
  }

  cout << ans * n << endl;
}


Measured memory_bytes: 512