akhauriyash/Code-Regression huggingface dataset:
from copy import copy
N=int(input())
G=[[] for _ in range(N)]
di=[-1]*N
for i in range(N-1):
    u,v,w=map(int,input().split())
    G[u-1].append([v-1,w])
    G[v-1].append([u-1,w])

di[0]=0
for g,w in G[0]:
    di[g]=w

for i in range(1,N):
    if di[i]!=-1:continue
    seen=[0]*N
    stack=copy(G[0])
    seen[0]=1
    dis=0
    while stack:
        y,d=stack.pop()
        if seen[y]==1:continue
        seen[y]=1
        if y==i:
            di[i]=dis+d
            break
        else:
            for z,dist in G[y]:
                if seen[z]==0:
                    di[z]=dis+d+dist
                    stack.append([z,dis+d+dist])

for i in range(N):
    if di[i]%2==0:
        print(0)
    else:
        print(1)

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

#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
#define N	    1000001
ll w[N], v[N];
//optimal substructure recursive solution
/*ll knapsack(ll w[], ll v[], ll n, ll c){
	if(n == 0 || c == 0)
		return 0;
	if(w[n-1] > c)
		return knapsack(w, v, n, c- w[n-1]);
	else return max(knapsack(w, v, n-1, c-w[n-1]) + v[n-1], knapsack(w, v, n-1, c));
}*/
ll max(int a, int b) { return (a > b)? a : b; }

//overlapping subproblems solved using dp
ll knapsack(ll c, ll wt[], ll v[], ll n){
	ll i, j;
	ll K[n+1][c+1];
	for(i = 0; i <= n; i++){
		for(j = 0; j <= c; j++){
			if(i==0 || j==0)
				K[i][j] = 0;
			else if(w[i-1] <= j)
				K[i][j] = max(K[i-1][j-w[i-1]] + v[i-1], K[i-1][j]);
			else
				K[i][j] = K[i-1][j];
		}
	}
	return K[n][c];
}
void solve(){	
	ll n, c;
	cin >> n >> c;
	rep(i, 0, n)
		cin >> w[i] >> v[i];
	cout << knapsack(c, w, v, n) << endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
     t =1;
   //  cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 81152
N = int(input())
A = list(map(int,input().split()))
flag = 1
for num in A:
    if num % 2== 0:
        if num % 3 ==0 or num % 5 ==0:
            continue
        else:
            flag =0

if flag == 1:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 2940
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, X = map(int, input().split())
    L = list(map(int, input().split()))
    lsum = [0 for _ in range(N + 1)]
    for i in range(N):
        lsum[i + 1] = L[i] + lsum[i]

    for i in range(N + 1):
        if lsum[i] <= X:
            ans = i + 1
        else:
            break
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
#define pair pair<int,int>
typedef long long ll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int mod = (int)1e9 + 7;
const ll MOD = 92709568269121;

class UnionFind{
    vector<ll> par; vector<ll> r_size;
    public:
        UnionFind(ll N) : par(N),r_size(N){
            for(int i=0; i<N; ++i){ par[i] = i; r_size[i] = 1;}
        }

        //Nの大きさで初期化
        void init(ll N){
            par.resize(N); r_size.resize(N);
            for(int i=0; i<N; ++i){ par[i] = i; r_size[i] = 1;}
        }

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

        //xとyとが所属する集合を併呑する
        void unite(ll x,ll y){
            ll rx = find(x); ll ry = find(y);
            if(rx == ry) return;
            if(r_size[rx]<r_size[ry]) swap(rx,ry);
            r_size[rx] += r_size[ry];
            par[ry] = rx;
        }

        bool same(ll x, ll y){
            ll ry = find(x); ll rx = find(y);
            return rx == ry;
        }

        //素集合の大きさを返す
        ll el_size(ll x){
            return r_size[find(x)];
        }
};

int main(){
    ll n,m,a,b; cin>>n>>m;
    vector<pair> input(m);
    rep(i,m){ cin>>a>>b; input[i].first = --a; input[i].second = --b;}

    UnionFind island(n);
    vector<ll> ans(m);

    ans[0] = (n*(n-1))/2;
    reverse(input.begin(),input.end());

    ll x,y; ll con;
    rep(i,m-1){
        x = input[i].first; y = input[i].second;
        if(island.same(x,y)){
            ans[i+1] = ans[i];
        }else{
            con = island.el_size(x)*island.el_size(y);
            ans[i+1] = max(ans[i]-con, 0LL);
            island.unite(x,y);
        }
    }
    reverse(ans.begin(),ans.end());
    for(auto x:ans)cout<<x<<endl; return 0;
}


Measured memory_bytes: 4480
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		String A[]=new String[n];
		for(int i=0;i<n;i++)A[i]=in.next();
		if(n%2==1) {
			System.out.println("NO");
			return;
		}
		Stack<Character> s=new Stack<>();
		boolean j=true;
		for(int i=0;i<n;i++) {
			if(A[i].equals("A"))s.push('A');
			else {
				if(s.isEmpty()) {
					j=false;
					break;
				}
				else s.pop();
			}
		}
		if(j && s.isEmpty())System.out.println("YES");
		else System.out.println("NO");
	}

}



Measured memory_bytes: 26416
import java.util.Scanner;

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

		int r = Integer.parseInt(sc.next());
		int g = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		System.out.println((10*g+b)%4==0 ? "YES" : "NO");
	}
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	n=n%1000;
	n=1000-n;
	n%=1000;
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	string s,t;
	cin >> s;
	for(int i = 0;i < s.length();i++){
		if(s[i] == '1') t += "1";
		else if(s[i] == '0') t += "0";
		else if(t != "") t = t.substr(0,t.length() - 1);
	}
	cout << t << endl;
	return 0;
}

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

#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define pii pair<int,int>
#define vi vector<int>
#define vit vector<int>::iterator it
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)(v.size())
#define si set<int>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int inf=0x7f7f7f7f;
const int N=1e5+10;

int main() {
    string st;
    cin>>st;
    string a,b,c,d,e;
    a=st;
    reverse(all(a));
    b=st.substr(0,(sz(st)-1)/2);
    c=b;
    reverse(all(b));
    d=st.substr((sz(st)+3)/2-1,sz(st)-(sz(st)+3)/2+1);
    e=d;
    reverse(all(d));
    // cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;
    if(a!=st || b!=c || e!=d) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){

    vector<int> v(10);
    rep(i,10){
        int x;
        cin>>x;
        v[i]=x;
    }
    sort(v.begin(),v.end(),greater<int>());
    cout<<v[0]<<endl<<v[1]<<endl<<v[2]<<endl;





return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  int N;
  cin >> N;
  ll s,q;
  cin >> s >> q;
  ll j=0;
  ll T[1000], A[1000];
  for(int i=1;i<N;i++){
    cin >> T[i] >> A[i];
    j=max((s+T[i]-1)/T[i],(q+A[i]-1)/A[i]);
    s=j*T[i];
    q=j*A[i];
  }
  cout << s+q << endl;
  return 0;
}


Measured memory_bytes: 256
# include<iostream>
# include<vector>
# include<algorithm>
# include<cstdio>
# include<string>
using namespace std;
int main() {
    int n,ans,anso;
    cin >> n;
    if (n < 105){
        cout << 0 << endl;
    }else{
        for (int i = 105;i <= n;i += 2){
            ans = 0;
            for (int j = 1;j <= i;j ++){
                if (i % j == 0){
                    ans ++;
                }
            }
            if (ans == 8){
                anso ++;
            }
        }
        cout << anso << endl;
    }
}

Measured memory_bytes: 256
S = list(input())
N = len(S)

#Rのカウント
R = [0] * N
R[0] = 1
flag = True
for i in range(1, N):
    if S[i] == 'R':
        if flag: #直前がRのとき
            R[i] = R[i - 1] + 1
        else: #直前がRではないとき
            R[i] = 1
        flag = True
    else:
        flag = False
L = [0] * N
L[N - 1] = 1
flag = True
for i in range(N - 2, -1, -1):
    if S[i] == 'L':
        if flag:
            L[i] = L[i + 1] + 1
        else:
            L[i] = 1
        flag = True
    else:
        flag = False

ans = [0] * N
for i in range(N - 1):
    if S[i] == 'R' and S[i + 1] == 'L': #区切りとなるところ
        ans[i] = (R[i] + 1)//2 + L[i + 1]//2
        ans[i + 1] = R[i]//2 + (L[i + 1] + 1)//2
# print ('R', R)
# print ('L', L)
print (*ans)

Measured memory_bytes: 53624
#include <stdio.h>
 
int main(void) {
 
	// ??°????????\???????????°?????????
	int num;
	scanf("%d", &num);
	int sequence[num];
	
	for(int cnt = 0; cnt < num; cnt++) {
		
		scanf("%d", &sequence[cnt]);
	}
	
	// ???????????°????????????????????????????????????
	for(int cnt = num-1; cnt > 0; cnt--) {
		
		printf("%d ", sequence[cnt]);
	}
		
	printf("%d\n", sequence[0]);
	return 0;
}

Measured memory_bytes: 1764
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ptrn = 1
a.each do |k|
  if k % 2 == 0
    ptrn *= 2
  else
    ptrn *= 1
  end
end
ptrn = 3**n - ptrn
p ptrn


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main()
{
    int n,k,a[105];
    bool dp[100005]; ///dp[i] det daca jucatorul care face mutarea cand mai sunt i pietre mai poate castiga
    cin >> n >> k;
    for (int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    dp[0]=false;
    for (int i=1;i<=k;i++)
    {
        dp[i]=false;
        for (int j=0;j<n;j++)
        {
            if (a[j]<=i)
            {
                if (!dp[i-a[j]])
                {
                    dp[i]=true;
                    break;
                }
            }
        }
    }
    if (dp[k]==1) cout << "First";
    else cout << "Second";
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<ll,ll>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

int main() {
  ll k,t; cin>>k>>t;
  ll mx=0;
  ll a[t]; for(int i=0;i<t;i++) cin>>a[i];
  for(int i=0;i<t;i++) mx=max(mx,a[i]);
  if (mx <= k/2+k%2) cout<<0<<endl;
  else {
    if (k%2==1) {
      cout<<(mx-(k/2+k%2))*2<<endl;
    } else {
      cout<<(mx-(k/2+k%2))*2-1<<endl;
    }
  }
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    unsigned long n, p; cin >> n >> p;
    if(n==1) {
        cout << p << endl;
        return 0;
    }
    unsigned long c, d=2L, z=1L;
    unsigned long x=sqrt(p);
    c=0L;
    for(;p>1L;) {
        if(!(p&1L)) {
            ++c; p>>=1;
            if(c==n) {
                c=0L; z<<=1;
            }
        } else {
            break;
        }
    }

    c=0L;
    for(;p>1L;) {
        if(p%3L==0) {
            ++c; p/=3L;
            if(c==n) {
                c=0L; z*=3L;
            }
        } else {
            break;
        }
    }
    
    bool flg=true;
    d=5L; c=0L;
    for(;p>1L;) {
        if(p%d==0) {
            ++c; p/=d;
            if(c==n) {
                c=0L; z*=d;
            }
        } else {
            d+=flg?2L: 4L;
            flg=!flg;
            c=0L;
            if(d>=x) break;
        }
    }
    cout << z << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int div;
    int n_count;
    while (true)
    {
        div = *min_element(A.begin(), A.end());
        rep(i, N)
        {
            if (A[i] != div)
            {
                A[i] = A[i] % div;
            }
        }
        A.erase(remove(A.begin(), A.end(), 0), A.end());
        n_count = count(A.begin(), A.end(), div);
        if (n_count == A.size())
        {
            break;
        }
    }
    cout << div << endl;
 //   system("pause");
    return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {
    Scanner sc;

    void run() {
        sc = new Scanner(System.in);
        int t = sc.nextInt();
        double[] exp_value = new double[t];

        for (int i = 0; i < t; i++) {
            // 使えるダイス
            int n = sc.nextInt();
            int m = sc.nextInt();
            double zero_pos = 1.0;
            for (int j = 0; j < m; j++) {
                int v = sc.nextInt();
                double r = sc.nextDouble();
                exp_value[i] += v * r;
                zero_pos -= r;
            }
            exp_value[i] *= 1.0 / (1.0 - zero_pos);
        }

        // 班長のダイス
        int p = sc.nextInt();
        int q = sc.nextInt();
        double leader_exp_value = 0.0;
        double leader_zero_pos = 1.0;
        for (int j = 0; j < q; j++) {
            int v = sc.nextInt();
            double r = sc.nextDouble();
            leader_exp_value += v * r;
            leader_zero_pos -= r;
        }
        leader_exp_value *= 1.0 / (1.0 - leader_zero_pos);

        boolean exist = false;
        for (int i = 0; i < t; i++) {
            if (exp_value[i] > leader_exp_value + 0.0000001) {
                exist = true;
                break;
            }
        }
        if (exist) System.out.println("YES");
        else System.out.println("NO");
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

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

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main(){
  int n, d;
  cin >> n >> d;

  int t = 2*d+1;
  int ans = (n+t-1) / t;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1e+7
int main()
{
    ll n;
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin>>n;
    int count1=0;
    int ans[n];
    n--;
    memset(ans,0,sizeof ans);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j*i<=n;j++)
        {
            ans[i*j]++;
        }
    }
    for(int i=1;i<=n;i++)
    {
        count1+=ans[i];
    }
    cout<<count1<<endl;
}


Measured memory_bytes: 7480
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val s = sc.next()

  val mod = 1_000_000_000 + 7L

  val map = mutableMapOf<Char, Int>()
  for (si in s) {
    val tmp = map.getOrElse(si) { 0 }
    map.put(si, tmp+1)
  }

  // val max = map.keys.size
  // println(max)

  var ans = 1L
  for (mi in map.values) {
    ans = ans * (mi + 1) % mod
  }

  println(ans - 1)

}


Measured memory_bytes: 41792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const int n_max=1e5+5;
vector<pair<int, int> > g[n_max];//どこに、used
vector<int > rg[n_max];
bool used[n_max];
int tp;
int ans[n_max];
int dep[n_max];

void dfs_leaf(int v){
  if(!used[v]){
    used[v]=true;
    for(auto i:g[v]){
      if(!used[i.first]) dfs_leaf(i.first);
    }
  }
}

void dfs_par(int v){
  if(!used[v]){
    tp=v;
    used[v]=true;
    for(auto i:g[v]){
      if(!used[i.first]) dfs_leaf(i.first);
    }
  }
}

/*void dfs_ans(int v, int d){
  int j=0;
  dep[v]=d+1;
  for(auto i:g[v]){    
    if(i.second==0){
      g[v][j]=mp(i.first, 1);
      if(dep[i.first] < d+1){
	ans[i.first]=v+1;
      }
      cout << "from" << v << " to " <<i.first << endl;
      dfs_ans(i.first, d+1);
    }
    j++;
  }
  }*/

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

  int n,m;
  cin >> n >> m;
  int a,b;
  rep(i,n+m-1){
    cin >> a >> b;
    a--;b--;
    g[a].pb(mp(b,0));
    rg[b].pb(a);
  }
  rep(i,n) used[i]=false;
  rep(i,n){
    dfs_par(i);
  }
  rep(i,n) dep[i]=0;
  //  cout << "par " << tp << endl;
  ans[tp]=0;
  int cou[n];
  rep(i,n) cou[i]=0;
  cou[tp]=-1;
  queue<int> qu;
  qu.push(tp);
  while(!qu.empty()){
    int v=qu.front();qu.pop();
    cou[v]++;
    if(rg[v].size()!=cou[v]) continue;
    for(auto i:g[v]){      
      qu.push(i.first);
      ans[i.first]=v+1;
    }
  }
  rep(i,n) cout << ans[i] << endl;



  
  return 0;
    

}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int al = a.length() - 1;
  int bl = b.length() - 1;
  int cl = c.length() - 1;

  cout << (a[al] == b[0] && b[bl] == c[0] ? "YES" : "NO") << endl;
  return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int a, b;
    cin >> a >> b;

    rep(i,1,1500){
        if(int(floor(i*.08)) == a && int((floor(i*.1))) == b){
            cout << i << "\n";
            return;
        }
    }

    cout << "-1\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 256
from math import sqrt

def is_prime(n):
  if n == 2:
    return True
  for i in range(2, int(sqrt(n)+1)):
    if n % i == 0:
      return False
  return True

N = int(input())
res = 0
for i in range(N):
  if is_prime(int(input())):
    res += 1

print(res)



Measured memory_bytes: 5676
#include "bits/stdc++.h"

#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vpii        vector< pii >
#define vi          vector<ll>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			1'010'000'000'000'000'017LL
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define sz(x)       (ll)x.size()
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )

using namespace std;

template<class T>
bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>
bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
ll DivisorCount(ll x) {
	ll ans = 1;
	for (int i = 2; i <= sqrt(x); i++) {
		int cnt = 0;
		while (x % i == 0) {
			cnt++;
			x /= i;
		}
		ans *= (cnt + 1);
		if (x == 1) break;
	}
	if (x != 1) ans *= 2;
	return ans;
}

void Main() {
	ll N, K;
	cin >> N >> K;
	vi P(N, 0);
	rep(i, 0, N) cin >> P[i];

	sort(P.begin(), P.end());
	ll sum = 0;
	rep(i, 0, K) sum += P[i];
	cout << sum << endl;
}


int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	Main();
	return 0;
}


Measured memory_bytes: 3688
H, W = map(int, input().split())
S = [0]*(H+1)
S[0] = '*'*(W+1)
for h in range(1,H+1):
    S[h] = '*' + input()

dps = [[0]*(W+1) for _ in range(H+1)]
mod = 10**9+7

def dp(h,w):
    if h==1 and w==1:
        return 1
    if S[h][w]=='.':
        return (dps[h-1][w]+dps[h][w-1])%mod
    return 0


def solve():
    for h in range(1,H+1):
        for w in range(1,W+1):
            dps[h][w] = dp(h,w)
    ans = dps[-1][-1]
    return ans
print(solve()) 

Measured memory_bytes: 43740
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

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

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int main() {
    ll n, l;
    cin >> n >> l;
    vll a(n);
    rep (i, n) { cin >> a[i]; }
    int last = 0;
    FOR (i, 1, n) {
        if ( a[i-1] + a[i] >= l ) {
            last = i;
            break;
        }
    }
    if ( last == 0 ) {
        printf("Impossible\n");
        return 0;
    }
    printf("Possible\n");
    FOR (i, 1, last) {
        printf("%d\n", i);
    }
    for (int i = n - 1; i > last; --i) {
        printf("%d\n", i);
    }
    printf("%d\n", last);

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

int e;
int o;

int main(){
    int k;cin>>k;
    for(int i=1;i<=k;i++){
        if(i%2==0)e++;
        else o++;
    }
    cout<<e*o<<endl;
    return 0;
}

Measured memory_bytes: 256
while(1):
	n = int(input())
	if n == 0: break
	ap = 0
	bp = 0
	for i in range(n):
		a,b = map(int,input().split())
		if a > b: ap = a + b + ap
		elif a < b: bp = a + b + bp
		elif a == b: ap = a + ap; bp = b + bp
	print(ap,bp)


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int n;
string str;
int isEdge[222222];
int cou[3];
int pointer[222222];
int ans[222222];
bool used[222222];

bool check(){
	vector<vector<int>> v(222222);
	vector<int> wapu(222222);
	REP(i,2*n){
		v[ans[i]].PB(i);
		if(ans[i] < 1 || ans[i] > n)exit(1);
	}
	for(int i = 1;i <= n;i++){
		wapu[v[i][0]] = v[i][1];
		wapu[v[i][1]] = v[i][0];
	}
	int now = wapu[0];
	while(1){
		used[now] = true;
		now++;
		if(now == 2*n)break;
		now = wapu[now];
	}
	//SHOW1d(used,2*n);
	REP(i,2*n-1){
		if(used[i]){
			if(str[i+1] != '1')return false;
		}
		else{
			if(str[i+1] != '0')return false;
		}
	}
	return true;
}

int main(){

	REP(i,222222)pointer[i] = i;

	cin >> n;

	cin >> str;
	str = '1' + str + '1';

	REP(i,2*n){
		int tmp = 0;
		isEdge[i] = ((str[i] == '1') + (str[i+1] == '1'));
		cou[isEdge[i]]++;
	}

	//SHOW1d(isEdge,2*n);
	//SHOW1d(cou,3);

	if(cou[2] % 2){
		cout << "No" << endl;
		return 0;
	}

	int nowNum = 1;

	if(cou[2] % 4 == 2){
		vector<vector<int>> paths;
		vector<int> path;
		int pla = 0;
		REP(i,2*n){
			if(isEdge[2*n-1-i] == 1){
				pla = 2*n-1-i;
				break;
			}
		}
		for(int i = 0;i < 2*n;i++){
			int place = (i + pla) % (2*n);
	//		cout << "place is " << place << endl;
			if(isEdge[place] == 0){

			}
			else if(isEdge[place] == 1){
				path.PB(place);
				if(path.size() > 1){
					if(path.size() > 2){
						paths.PB(path);
					}
					path.clear();
				}
			}
			else{
				path.PB(place);
			}
		}
		if(paths.size() <= 1){
			cout << "No" << endl;
			return 0;
		}
/*
		REP(i,paths.size()){
			REP(j,paths[i].size()){
				cout << paths[i][j] << " ";
			}
			cout << endl;
		}
*/
		ans[paths[0][1]] = 1;
		ans[paths[1][1]] = 1;
		nowNum++;
		isEdge[paths[0][1]] = -1;
		isEdge[paths[1][1]] = -1;
		swap(pointer[paths[0][0]],pointer[paths[1][0]]);
	}

	vector<int> seica;
	REP(i,2*n){
		if(isEdge[i] == 1)seica.PB(i);
		if(seica.size() == 2){
			ans[pointer[seica[0]]] = nowNum;
			ans[pointer[seica[1]]] = nowNum;
			nowNum++;
			seica.clear();
		}
	}

	REP(i,2*n){
		if(isEdge[pointer[i]] == 2)seica.PB(i);
		if(seica.size() == 4){
			ans[seica[0]] = nowNum;
			ans[seica[1]] = nowNum + 1;
			ans[seica[2]] = nowNum;
			ans[seica[3]] = nowNum + 1;
			nowNum+=2;
			seica.clear();
		}
	}

	REP(i,2*n){
		if(isEdge[i] == 0)seica.PB(i);
		if(seica.size() == 2){
			ans[seica[0]] = nowNum;
			ans[seica[1]] = nowNum;
			nowNum++;
			seica.clear();
		}
	}

	cout << "Yes" << endl;
	REP(i,2*n)cout << ans[i] << ' ';cout << endl;

	return 0;
}


Measured memory_bytes: 4856
import math
x = int(input())

expotential_set = set()
for i in range(1, 1000):
    for j in range(2, 10):
        expotential_set.add(pow(i, j))

expotential_list = sorted(list(expotential_set))

distance = 10000000000000
for num in expotential_list:
    if num <= x and abs(num - x) < distance:
        distance = abs(num - x)
        ans = num

print(ans)


Measured memory_bytes: 3944
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

string replace(string s, int i, int j, string str_replace){
    int idx=0;
    for(int h=i; h<=j; h++){
        s[h] = str_replace[idx];
        idx += 1;
    }
    return s;
}

string reverse(string s, int i, int j){
    vector<char> tmp_char(j-i+1);
    for(int h=i; h<=j; h++){
        tmp_char[h-i] = s[h];
    }
    for(int h=i; h<=j; h++){
        s[i+j-h] = tmp_char[h-i];
    }
    return s;
}

void printStr(string s, int i, int j){
    for(int h=0; h<j-i+1; h++){
        if(h==j-i){
            cout << s[i+h] << endl;
            break;
        }else{
            cout << s[i+h];
        }
    }
}

int main(){

    string s;
    cin >> s;

    int q;
    cin >> q;

    vector<string> cmds(q);
    vector<string> cmd_str(q);
    vector<vector<int>> cmd_int;
    cmd_int = vector<vector<int>>(q,vector<int>(2));

    for(int i=0; i<q; i++){
        cin >> cmds[i];
        if(cmds[i]=="replace"){
            cin >> cmd_int[i][0] >> cmd_int[i][1] >> cmd_str[i];
        }else{
            cin >> cmd_int[i][0] >> cmd_int[i][1];
            cmd_str[i] = " ";
        }
    }

    for(int i=0; i<q; i++){
        if(cmds[i]=="replace"){
            s = replace(s, cmd_int[i][0], cmd_int[i][1], cmd_str[i]);
            continue;
        }else if(cmds[i]=="reverse"){
            s = reverse(s, cmd_int[i][0], cmd_int[i][1]);
            continue;
        }else if(cmds[i]=="print"){
            printStr(s, cmd_int[i][0], cmd_int[i][1]);
            continue;
        }
    }



    return 0;
}



Measured memory_bytes: 3216
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt();
		char[][] cs = new char[a][b];
		int sx = -1, sy = -1;
		for(int i=0; i<a; i++) {
			String s = sc.next();
			if(s.indexOf('S') != -1) {
				sx = i;
				sy = s.indexOf('S');
			}
			cs[i] = s.toCharArray();
		}
		
		int[] dx = new int[]{0,0,1,-1};
		int[] dy = new int[]{1,-1,0,0};
		Queue<int[]> q = new LinkedList<int[]>();
		Queue<int[]> qq = new LinkedList<int[]>();
		q.add(new int[]{sx, sy});
		int min = get(cs, sx, sy);
		boolean[][] marked = new boolean[a][b];
		marked[sx][sy] = true;
		
		for(int j=0; j<k; j++) {
			for(int[] p : q) {
				for(int i=0; i<4; i++) {
					int newi=p[0]+dx[i];
					int newj=p[1]+dy[i];
					if(ok(cs, newi, newj) && !marked[newi][newj]) {
						marked[newi][newj] = true;
						qq.add(new int[]{newi, newj});
						int t = get(cs, newi, newj);
						if(t < min)	
							min = t;
					}
				}
			}
			q = qq;
			qq = new LinkedList<int[]>();
		}
		
		System.out.println(1 + (int)Math.ceil((0.0+min)/k));
	}

	private static int get(char[][] cs, int newi, int newj) {
		int row  = Math.min(newi, cs.length-1-newi);
		int col  = Math.min(newj, cs[0].length-1-newj);
		return Math.min(row, col);
	}

	private static boolean ok(char[][] cs, int newi, int newj) {
		if(newi<0 || newj<0 || newi>=cs.length || newj>=cs[0].length)	return false;
		if(cs[newi][newj] == '#')	return false;
		return true;
	}
}


Measured memory_bytes: 48864
#include<cstdio>
#include<map>
#define LL long long
#define mod 1000000007
using namespace std;
map<LL,LL> mp;
LL p(LL x)
{
	if(mp.count(x)) return mp[x];
	if(x==1) return 1;
	if(x%2ll) return mp[x]=(p((x-1)/2ll)+p((x+1)/2ll))%mod;
	return mp[x]=p(x/2ll);
}
LL calc(LL x)
{
	if(x==1) return 1;
	if(x%2ll) return (calc(x/2ll)*3ll+p(x/2ll+1))%mod;
	return (calc(x/2ll)*3ll-p(x/2ll)+mod)%mod;
}
int main()
{
	LL n;
	scanf("%lld",&n);
	printf("%lld\n",calc(n+1));
}


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

struct Idxtree{
    static const int o = 262144;
    ll a[o + o];
    void init(){
        memset(a,0x3f3f3f3f,sizeof(a));
    }
    ll rmq(int s, int e){
        s += o; e += o;
        ll ret = min(a[s], a[e]);
        while(s <= e){
            ret = min({ret, a[s], a[e]});
            ++s >>= 1;
            --e >>= 1;
        }
        return ret;
    }
    void addv(int i, ll v){
        i += o;
        a[i] += v;
        for(;i > 1; i >>= 1){
            a[i >> 1] = min(a[i], a[i^1]);
        }
    }
    void setv(int i, ll v){
        i += o;
        a[i] = v;
        for(; i > 1; i >>= 1){
            a[i >> 1] = min(a[i], a[i^1]);
        }
    }
} Im, Ip;

ll offset;
int n, q, a, b;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    Im.init(); Ip.init();
    cin >> n >> q >> a >> b;
    Im.setv(a, 0ll - a);
    Ip.setv(a, 0ll + a);
    for(int x; q--;){
        cin >> x;
        ll dlt = abs(x - b);
        ll tam = min(x + Im.rmq(1,x), - x + Ip.rmq(x,n)) - dlt;
        Im.setv(b, tam - b);
        Ip.setv(b, tam + b);
        offset += dlt;
        b = x;
    }
    ll ans = LLONG_MAX;
    for(int i = 1; i <= n; i++){
        ans = min(ans, offset + (Im.a[Idxtree::o + i] + Ip.a[Idxtree::o + i])/2);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 8448
import java.util.Scanner;

public class Main {
	public	static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] dice = new int[6];
		for (int i = 0; i < 6; i++) {
			dice[i] = sc.nextInt();
		}
		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if((a==dice[1]&&b==dice[2])||(a==dice[3]&&b==dice[1])||(a==dice[4]&&b==dice[3])||(a==dice[2]&&b==dice[4])) {
				System.out.println(dice[0]);
			}else if((a==dice[0]&&b==dice[3])||(a==dice[2]&&b==dice[0])||(a==dice[5]&&b==dice[2])||(a==dice[3]&&b==dice[5])) {
				System.out.println(dice[1]);
			}else if((a==dice[0]&&b==dice[1])||(a==dice[4]&&b==dice[0])||(a==dice[5]&&b==dice[4])||(a==dice[1]&&b==dice[5])) {
				System.out.println(dice[2]);
			}else if((a==dice[0]&&b==dice[4])||(a==dice[1]&&b==dice[0])||(a==dice[5]&&b==dice[1])||(a==dice[4]&&b==dice[5])) {
				System.out.println(dice[3]);
			}else if((a==dice[0]&&b==dice[2])||(a==dice[3]&&b==dice[0])||(a==dice[5]&&b==dice[3])||(a==dice[2]&&b==dice[5])) {
				System.out.println(dice[4]);
			}else {
				System.out.println(dice[5]);
			}
		}
	}
}



Measured memory_bytes: 26132
N = int(input())
mod = 10 ** 9 + 7

A = [int(x) for x in input().split()]
ans = 0
for i in range(60):
    cnt = 0
    for a in A:
        cnt += a >> i & 1
    ans += cnt * (N - cnt) * (1 << i)
print(ans % mod)


Measured memory_bytes: 122936
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int cnt = 0;
		for (int i = 0; i < s.length(); i++)
			if (s.charAt(i) != t.charAt(i))
				cnt++;
		System.out.println(cnt);
	}
}


Measured memory_bytes: 40932
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using ll = long long;

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

class FenwickTree {
public:
  FenwickTree(int _n) : n(_n) { v.resize(_n + 1, 0); }

  void add(int pos, long long val) {
    pos++;
    for (int i = pos; i <= n; i += i & (-i))
      v[i] += val;
  }

  // sum [l, r]
  long long sum(int l, int r) { return sum(r) - sum(l - 1); }

  // sum [0,pos]
  long long sum(int pos) {
    pos++;
    long long ret = 0;
    for (int i = pos; i > 0; i -= i & (-i))
      ret += v[i];
    return ret;
  }

private:
  int n;
  std::vector<long long> v;
};

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> cnt(26);
  REP(i, n) cnt[s[i] - 'a']++;
  REP(i, 26) {
    if (cnt[i] % 2 == 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> l, r;
  vector<int> cnt2(26, 0);
  REP(i, n) {
    if (cnt2[s[i] - 'a'] < cnt[s[i] - 'a'] / 2) {
      l.push_back(i);
    } else {
      r.push_back(i);
    }
    cnt2[s[i] - 'a']++;
  }

  ll ans = 0;
  REP(i, n / 2) { ans += l[i] - i; }
  vector<vector<int>> pos(26);
  REP(i, n / 2) { pos[s[l[i]] - 'a'].push_back(i); }
  FenwickTree bit(n / 2);
  vector<int> ind(26);
  REP(i, n / 2) {
    char c = s[r[n / 2 - 1 - i]];
    int p = pos[c - 'a'][ind[c - 'a']];
    ind[c - 'a']++;
    ans += -bit.sum(p) + p;
    bit.add(p, 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 7636
using System;
class Program {
    static void Main (string[] args) {
        string input = Console.ReadLine ();
        int N = input.Length;
        if (input.Substring (0, (N - 1) / 2) == input.Substring ((N + 3) / 2 - 1, (N - 1) / 2)) {
            Console.WriteLine ("Yes");
        } else {
            Console.WriteLine ("No");
        }
    }
}

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

int main() {
	int n; cin >> n;
	vector<int> y(n + 1);
	vector<int> u(n);
	int64_t ans = 0;
	rep(i, n + 1) cin >> y.at(i);
	rep(i, n) cin >> u.at(i);
	rep(i, n) {
		if (y.at(i) + y.at(i + 1) < u.at(i)) {
			ans += y.at(i) + y.at(i + 1);
			y.at(i) = 0; y.at(i + 1) = 0;
		}
		else if (y.at(i) < u.at(i)) {
			y.at(i + 1) = y.at(i + 1) - u.at(i) + y.at(i); y.at(i) = 0;
			ans += u.at(i);
		}
		else {
			ans += u.at(i);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
/**
 *		author:  zvm
 *		created: 26.09.2020 17:42:43
**/

#include <bits/stdc++.h>

using namespace std ;

class disjoint_set {

	public :
		disjoint_set( int _n ) {
			n = _n ;
			links = 0 ;
			max_comp = 1 ;
			sz.resize(n+1);
			par.resize(n+1);
			rank.resize(n+1);
			for( int i = 1 ; i <= n ; ++i ) {
				sz[i] = 1 ;
				par[i] = i ;
				rank[i] = 0 ; 
			}			
		}

		bool is_connected() {
			return links == n-1 ;
		}

		int find( int x ) {
			return par[x] = ( x == par[x] ? x : find(par[x]) ) ;
		}
		
		int components() {
			return n-links ;
		}

		int max_component() {
			return max_comp ;
		}

		bool unite( int x, int y ) {
			
			if( (x=find(x)) == (y=find(y)) ) { 
				return false ;
			}

			++links ;

			if( rank[x] < rank[y] ) {
				swap(x,y);
			}

			sz[x] += sz[y] ;
			max_comp = max( max_comp, sz[x] );
			par[y] = x ;
			rank[x] += ( rank[x]==rank[y] ) ;
			
			return true ;
		}

	private :
		int n ;
		int links ;
		int max_comp ;
		vector<int> sz ;
		vector<int> par ;
		vector<int> rank ;
};

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

	int n, m ;
	cin >> n >> m ;

	disjoint_set dsu(n);
	int u, v ;
	for( int i = 0 ; i < m ; ++i ) {
		cin >> u >> v ;
		dsu.unite(u,v);
	}

	cout << dsu.components()-1 << endl ;
}


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

int ans[500];//0で初期化したかった

int main() {

    int n;

    cin >> n;

    int c[n],s[n],f[n];

    for(int i=0; i<n-1; i++){
        cin >> c[i] >> s[i] >> f[i];
    }

    for(int i=0; i<n-1; i++){
        int time = 0;
        for(int j=i; j<n-1; j++){
            if(time <= s[j]){
                time = s[j];
                time += c[j];
            }
            else{
                if(time % f[j] != 0){
                    time += f[j] - time % f[j];
                }
                time += c[j];
            }
        }
        ans[i] = time;
    }

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

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define PI 3.14159265358979
	#define EPS 1e-8
	#define mod  1000000007
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
 
	const ll INF=1e18;	
	const int N=1e5+50;
 
	vector<vector<ll> > a;
	vector<vector<ll> > dp;
	
	ll count(ll idx,ll mask,ll n)
	{
		if(mask==((1<<n)-1))
		{
			return 1;
		}
		if(idx<0)
			return	0;
		if(dp[idx][mask]!=-1)
			return dp[idx][mask];
		ll ans=0;
		for(ll i=0;i<n;i++)
		{
			if(a[idx][i]==1 && ((mask & (1LL<<i))==0))
			{
				ans+=count(idx-1,mask | (1LL<<i),n);
				ans%=mod;
			}
		}
		return dp[idx][mask]=ans;
	}
	
	int main()
	{
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);cout.tie(0);
		
		ll n;
		cin>>n;
		a=vector<vector<ll>>(n+1,vector<ll> (n+1));
		dp=vector<vector<ll>>(n+1,vector<ll>(1<<n,-1));
		for(ll i=0;i<n;i++)
		{
			for(ll j=0;j<n;j++)
			{
				cin>>a[i][j];
			}
		}
		cout<<count(n-1,0,n);
		
		
	}


Measured memory_bytes: 380164
from collections import defaultdict, deque

n,m = map(int,input().split())
edge = [[] for i in range(n)]
for i in range(m):
    l,r,d = map(int, input().split())
    edge[l-1].append((r-1,d))
    edge[r-1].append((l-1,-d))

dist = [0]*n
visited = [False]*n

for i in range(n):
    if visited[i]:
        continue
    q = deque()
    q.append((i,0))
    while q:
        to, d = q.popleft()
        if visited[to]:
            if dist[to] != d:
                print("No")
                exit()
        else:
            visited[to] = True
            dist[to] = d
            for ind, j in edge[to]:
                q.append((ind,d+j))

print("Yes")

Measured memory_bytes: 93748
let ans board w h =
  let valid_pos (x, y) =
    0 <= x && x <= h + 1 && 0 <= y && y <= w + 1
  in
  let q = Queue.create () in
  let visited = Array.make_matrix (h+2) (w+2) false in
  visited.(0).(0) <- true;
  Queue.push (0,0) q;
  let rec aux num =
    if Queue.is_empty q then
      num
    else
      let (x,y) = Queue.pop q in
      let num' =
        List.fold_left (fun pre (x', y') ->
          if valid_pos (x', y') then
            if board.(x').(y') = 1 then  
              pre + 1
            else
              (if not visited.(x').(y') then
                (visited.(x').(y') <- true;
                Queue.push (x', y') q);
              pre)
          else
            pre 
        ) num (if x mod 2 = 0 then
                [(x-1,y-1); (x-1,y); (x+1,y-1); (x,y+1); (x+1,y); (x,y-1)]
               else
                [(x-1,y); (x,y-1); (x,y+1); (x+1,y+1); (x+1,y); (x-1,y+1)]
            )
      in
      aux num'
  in
  aux 0
;;

let (w,h) = Scanf.sscanf (read_line ()) "%d %d" (fun w h -> (w, h))
;;
let board = Array.make_matrix (h+2) (w+2) 0
;;

let rec parse i () =
  if i <= h then
    let inp = read_line () in
    let j = ref 1 in
    String.iter (fun c ->
       if c <> ' ' then
         (board.(i).(!j) <- int_of_char c - 48;
         j := !j + 1)
    ) inp;
    parse (i+1) ()
;;

parse 1 ();;

print_string (string_of_int (ans board w h) ^ "\n");;



Measured memory_bytes: 4660
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int A, B;
int VA[11000], VB[11000];

int main() {
    while (cin >> A >> B) {
        for (int i = 0; i < A; ++i) cin >> VA[i];
        for (int i = 0; i < B; ++i) cin >> VB[i];
        
        int res = 0;
        for (int a = 0; a < B; ++a) {
            int tmp = 0;
            int i = 0, j = a;
            for (i = 0, j = a; i < A && j < B;) {
                if (VA[i] == VB[j]) {
                    ++i; ++j; ++tmp;
                }
                else ++i;
            }
            chmax(res, tmp);
        }
        
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1204
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);;

    public static void main(String[] args) {
        int N = sc.nextInt();
        int X = sc.nextInt() - 1;
        int Y = sc.nextInt() - 1;
        int[] ans = new int[N];
        for (int i = 0 ; i < N; i++) for (int j = i + 1; j < N; j++) {
            ++ans[Integer.min(j-i, Integer.min(Math.abs(i-X) + Math.abs(j-Y), Math.abs(i-Y) + Math.abs(j-X)) + 1)];
        }
        for (int i = 1; i < N; i++) {
            System.out.println(ans[i]);
        }
    }
}


Measured memory_bytes: 23124
a, b, c = map(int, input().split())
a = [int(i) for i in input().split()]

small = 0
large = 0

for i in range(len(a)):
	if c > a[i]:
		small += 1
	if c < a[i]:
		large += 1

if small >= large:
	print(large)
else:
	print(small)

Measured memory_bytes: 3060
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

X, Y, Z = map(int, input().split())
X, Y = Y, X
X, Z = Z, X
print(X, Y, Z)



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

int main()
{
	ll a,b;
	cin >> a >> b;
	if(a%b==0)
	{
		cout<<-1<<endl;
		return 0;
	}
	else
	{
		cout<<a<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                ans += gcd(gcd(i,j),k);
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int h,w,t,mx,my,mt=10000000;
  while(1){
    mt=100000000;
    cin >> h >> w;
    if(h==0&&w==0)break;
    t=h*h+w*w;
    for(int i=1;i*i<=t;i++){
      for(int j=i+1;j<t;j++){
	if(i*i+j*j>=t){
	  if(i*i+j*j==t&&i<h)continue;
	  if(i*i+j*j==mt)continue;
	  if(i==h&&j==w)continue;
	  mt=min(i*i+j*j,mt);
	  // cout <<i<<" "<<j<<" "<< mt << endl;
	  if(i*i+j*j==mt){
	    mx=j;
	    my=i;
	  }
	  break;
	}
      }
      if(i*i>t)break;
    }
    cout << my << " "<<mx<<endl;
  }
  return 0;
}

Measured memory_bytes: 3096