akhauriyash/Code-Regression huggingface dataset:
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

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

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	priority_queue<ld, vector<ld>, greater<ld>> pq;
	int n;
	cin >> n;
	while(n--)
	{
		int v;
		cin >> v;
		pq.push(v);
	}
	while(pq.size() > 1)
	{
		auto x = pq.top();
		pq.pop();
		auto y = pq.top();
		pq.pop();
		pq.push((x + y) / 2);
	}
	cout << fixed << setprecision(5) << pq.top() << '\n';
}

Measured memory_bytes: 3788
from collections import deque

n = int(input())

l = deque()
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        l.appendleft(command[1])
    elif command[0] == "delete":
        try:
            ind = l.remove(command[1])
        except ValueError:
            pass
    elif command[0] == "deleteFirst":
        l.popleft()
    elif command[0] == "deleteLast":
        l.pop()
        
print (" ".join(l))

Measured memory_bytes: 71876
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n;
    cin>>n;
    vector<bool> dp(1e6+100,false);
    V vec(n);
    map<ll,ll> mp;
    map<ll,ll> mp2;
    rep(i,n){
        cin>>vec[i];
        mp[vec[i]]++;
    }
    sort(all(vec));
    rep(i,n){
        ll index=2;
        if(mp2[vec[i]]==1||dp[vec[i]]){
            continue;
        }
        mp2[vec[i]]++;
        while(vec[i]*index<=1e6+10){
            dp[vec[i]*index]=true;
            index++;
        }
    }
    ll res=0;
    rep(i,n){
        if(dp[vec[i]]||mp[vec[i]]>=2){
        //    cout<<vec[i]<<endl;
            res++;
        }
    }
    cout<<n-res<<endl;
}


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

main(){
	int n,a[100],k;
	bool suc;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	k = -1;
	suc = 1;
	for(int i=1;i<=n;i++){
		if(a[i] != i){
			if(k == -1)
				k = i;
			else if(k == -2){
				suc = 0;
				break;
			}
			else{
				if(a[k] == i && a[i] == k)
					k == -2;
				else{
					suc = 0;
					break;
				}
			}	
		}	
	}
	if(suc == 1)	cout<<"YES"<<endl;
	else	cout<<"NO"<<endl;
	
} 

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

vector<int> stones;
int n,k;

int mem[100005];

void dp(){
	mem[0]=0;
	for(int i=1;i<=k;i++){
		if(i<stones[0])
		{
			mem[i]=0;
		}
		else
		{
			for(int j=0;j<n;j++)
			{
				if(i-stones[j]>=0){
					if(mem[i-stones[j]]==0){
						mem[i]=mem[i]|1;
					}
					
				} 
			}
		}
	}
	return;
}


int main(){
	cin>>n>>k;
	memset(mem,0,sizeof(mem));
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		stones.push_back(x);
	}
	dp();
	if(mem[k]==1){
		cout<<"First"<<endl;
	}
	else{
		cout<<"Second"<<endl;
	}
	return 0;
}

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

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

    ll n, m;
    cin >> n >> m;

    ll res;
    if(n >= m/2) {
        cout << m/2 << endl;
        return 0;
    }
    res = n;
    m -= 2*n;

    res += m/4;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int i;
int j;
long long int N;
long long int A;
long long int B;
long long int count;
long long int C;
cin >> N >> A >> B;
count=N/(A+B);
C=N-(A+B)*count;
if(C>A)C=A;
cout << A*count+C << endl;
}


Measured memory_bytes: 256
#import<bits/stdc++.h>
using namespace std;
int h,i,j,k,m,w,a[2040][2040],b[2040][2040],c[2040][2040],d[2040][2040];
char e[2040][2040];
main()
{
scanf("%d%d",&h,&w);
for(;i<h;i++)scanf("%s",e[i]);
for(i=0;i<h;i++)for(j=0;++j<w;)a[i][j]=e[i][j-1]==35?0:a[i][j-1]+1;
for(j=0;j<w;j++)for(i=0;++i<h;)b[i][j]=e[i-1][j]==35?0:b[i-1][j]+1;
for(i=h;i--;)for(j=w-1;j--;)c[i][j]=e[i][j+1]==35?0:c[i][j+1]+1;
for(j=w;j--;)for(i=h-1;i--;)d[i][j]=e[i+1][j]==35?0:d[i+1][j]+1;
for(i=0;i<h;i++)for(j=0;j<w;j++)k=a[i][j]+b[i][j]+c[i][j]+d[i][j],m=m>k||e[i][j]==35?m:k;
printf("%d",m+1);
}

Measured memory_bytes: 68992
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int	
#define INF					1e5+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(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 T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


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

	int num_p = 0;
	int num_m = 0;
	vdef vfront(n-1);
	vdef vend(n-1);

	vdef a(n, 0);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		if (a[i] > 0)
			++num_p;
		else
			++num_m;
	}
	sort(ALL(a));

	int maxid = n - 1;
	int maxval = a[maxid];
	int minid = 0;
	int minval = a[minid];
	int newval = 0;

	--maxid;
	++minid;

	for (int i = 0; i < n-1; ++i)
	{
		if (num_m < num_p)
		{
			newval = minval - maxval;
			vfront[i] = minval;
			vend[i] = maxval;

		}
		else
		{
			newval = maxval - minval;
			vfront[i] = maxval;
			vend[i] = minval;
		}

		if (minval > 0)
			--num_p;
		else
			--num_m;
		if (maxval > 0)
			--num_p;
		else
			--num_m;
		if (newval > 0)
			++num_p;
		else
			++num_m;

		if (newval < a[maxid])
		{
			maxval = a[maxid];
			--maxid;
		}
		else
		{
			maxval = newval;
		}

		if (a[minid] < newval)
		{
			minval = a[minid];
			++minid;
		}
		else
		{
			minval = newval;
		}
	}

	int ans = newval;
	std::cout << ans << std::endl;
	for (int i = 0; i < vfront.size(); ++i)
	{
		cout << vfront[i] << " " << vend[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
from bisect import bisect_left

s = list(input())

t = list(input())

alf=[[] for _ in range(26)]

for i in range(len(s)):
    alf[ord(s[i])-97].append(i)

now_alf = -1
sets = 0
i = 0

while i < len(t):
    next_alf = ord(t[i])-97

    if len(alf[next_alf]) == 0:
        print(-1)
        exit()

    if now_alf > alf[next_alf][-1]:
        now_alf = -1
        sets += 1
    else:
        serch_next_alf = bisect_left(alf[next_alf], now_alf)
        now_alf = alf[next_alf][serch_next_alf]+1
        i += 1

print(sets*len(s)+now_alf)

Measured memory_bytes: 87456
N,M,Q = map(int,input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
    a[i] -= 1  #a,bを0オリジンにそろえる
    b[i] -= 1  

def score(A):
    score = 0
    for ai, bi, ci, di in zip(a, b, c, d):
        if A[bi] - A[ai] == ci:
            score += di
    return score

def dfs(A):
    if len(A) == N:
        return score(A)
    res = 0
    prev_last = A[-1] if len(A) > 0 else 0
    for v in range(prev_last, M):
        A.append(v)
        res = max(res, dfs(A))
        A.pop()
    return res

print(dfs([]))

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define rep0(i, n) for (int i = 1; i <= (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LO
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}



int main(){
    int n,q;
    string s;
    cin>>n>>q;
    cin>>s;
    int l[q],r[q];
    int ans[n];
    int qns[n];
    rep(i,q){
        int g,h;
        cin>>g>>h;
        l[i]=g;
        r[i]=h;
        
    }
    
    rep(i,n){
        if (i==0){
            ans[0]=0;
            qns[0]=0;
        }
        else{
            ans[i]=ans[i-1];
            qns[i]=qns[i-1];
        }
        if(s[i]=='A' && s[i+1]=='C'){
            ans[i]+=1;
        }
        if(s[i-1]=='A' && s[i]=='C'){
            qns[i]+=1;
        }
        
    }
    rep(i,n){
       // cout<<ans[i];
    }
    cout<<endl;
    rep(i,n){
       // cout<<qns[i];
    }
    cout<<endl;
    rep(i,q){
        int l_1=l[i]-1;
        int r_1=r[i]-1;
        //cout<<ans[r_1]-ans[l_1]<<endl;
        cout<<qns[r_1]-qns[l_1]<<endl;
    }
}
    


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30);
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, h, w;
    cin >> n >> h >> w;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if(a >= h && b >= w) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;
  long long ans = 1;
  const int mod = 1000000007;
  cin >> n;
  for(int i = 1; i <= n; i++){
    ans *= i;
    ans %= mod;
  }
  cout << ans << "\n";
  return 0;
}

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

const int N = 200;
const int INF = 1e9;

int n;
char s[N][N];

int dst[N][N];
bool visited[N];

void dfs(int pos, bool *bg) {
  visited[pos] = true;
  rep(to, n) {
    if (s[pos][to] == '0') continue;
    if (pos == to) continue;
    if (dst[0][pos] == dst[0][to]) *bg = false;
    if (visited[to]) continue;
    dfs(to, bg);
  }
}

int main() {
  cin >> n;
  rep(i, n) rep(j, n) cin >> s[i][j];

  rep(i, n) rep(j, n) {
    dst[i][j] = INF;
    if (i == j) dst[i][j] = 0;
    if (s[i][j] == '1') dst[i][j] = 1;
  }

  rep(k, n) rep(i, n) rep(j, n) dst[i][j] = min(dst[i][j], dst[i][k] + dst[k][j]);

  rep(i, n) visited[i] = false;
  bool bg = true;
  dfs(0, &bg);

  if (!bg) {
    cout << -1 << endl;
    return 0;
  }

  int ans = 0;
  rep(i, n) rep(j, n) ans = max(ans, dst[i][j] + 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
char tolower(char ch){
    if('A'<=ch && ch<='Z'){
        return ch-'A'+'a';
    }else{
        return ch;
    }
}

int main(){
    int count=0;
    string W;
    cin>>W;
    string str;
    while(1){
        cin>>str;
        if(str=="END_OF_TEXT")break;
        for(int i=0;i<(int)str.size();i++){
            str[i]=tolower(str[i]);
        }
        if(str==W){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3176
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>

#include <iostream>

#include <stdio.h>

using namespace std;

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

    return 0;
}




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

using namespace std;
int main()
{
	int n,d, auxentero=0, contador=0, auxinsertar;
	set<int> cuadrados;
	
	
	for (int i=0; i<=200; i++)
	{
		cuadrados.insert(i*i);
	}
	
	int aux=0;
	cin>>n>>d;
	vector< vector<int> > coordenadas(n+1);
	
	for (int i=0; i<n; i++)
	{
		for (int j=0; j<d; j++)
		{
			cin>>auxinsertar;
			coordenadas[i].push_back(auxinsertar);
		}
	}
	
	
	for (int i=0; i<n; i++)
	{
		for (int j=i+1; j<n; j++)
		{
			aux=0;
			
			for (int q=0; q<d; q++)
			{	
				aux+=(coordenadas[i][q]-coordenadas[j][q])*(coordenadas[i][q]-coordenadas[j][q]);
		 	}
			 if (cuadrados.find(aux)!=cuadrados.end())
			 {
			 	contador++;
			 }
		}
	}
	cout<<contador<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int N, T;
	scanf("%d %d", &N, &T);
	int ary[2][N];
	
	int i, j = 0;
	for(i = 0; i < N; ++i){
		scanf("%d%d", &ary[0][j], &ary[1][j]);
		// printf("ary[0][%d] = %d, ary[1][%d] = %d\n", j, ary[0][j], j, ary[1][j]);
		if(ary[1][j] <= T) ++j;
		
	}
	// printf(" j = %d\n", j);
	if(j == 0) printf("TLE\n");
	else{
		int Min = 1001;	
		for(i = 0; i < j; ++i){
			if(Min > ary[0][i]) Min = ary[0][i];
			// printf("Min=%d\n", Min);
		}
		printf("%d\n", Min);
	}
	
	return 0;
}

Measured memory_bytes: 128
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << 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; }

struct UnionFind {
    vector<int> par, w;
    
    UnionFind(int n) : par(n, -1), w(n, 0) { }
    void init(int n) { par.assign(n, -1); w.assign(n, 0); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) {
            ++w[x];
            return false;
        }
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        w[x] += w[y];
        ++w[x];
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
 
    int wei(int x) {
        return w[root(x)];
    }
};

void solve() {
	int n, m; cin >> n >> m;
    UnionFind uf(n);
    int cnt = 0;
    rep(i, m) {
        int a, b; cin >> a >> b; -- a, -- b;
        if(!uf.issame(a, b)) {
            uf.merge(a, b);
            ++ cnt;
        }
    }
    cout << n - 1 - cnt << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 4768
/// Zhupengfei 2018
/// Hereby declare: this program is in public domain.

/// Solution for problem: abc103C

#include <bits/stdc++.h>

#ifdef LOCAL
#pragma GCC poison printf // To avoid fastio problems
#pragma GCC poison scanf
#endif

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
    int N;
    cin>>N;
    int sum=0;
    int x;
    for(int i=1;i<=N;i++) {
        cin>>x;
        sum+=x-1;
    }
    cout<<sum<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int A, B; cin >> A >> B;
  cout << max(max(A+B, A-B), A*B) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

llong N, A, B, C, D;
LP pr, mi;

int main(){
    cin >> N >> A >> B >> C >>D;
    int flag = 0;
    REP(i, N -1){
        if(C*(N-1-i) - D*i <= B - A && B - A <= (N-1-i)*D - C*i){
            flag = 1;
        }
    }
    string out = flag ? "YES" : "NO";
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define bg begin()
#define en end()
#define vvl(n,m) vector<vector<ll> > a( n , vector<ll> (m))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)
    return b;
    else
    return gcd(b%a,a);
}
ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = -1000000000000000, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 
ll countPairs(ll arr[], ll n) 
{ 
    map<ll, ll> map; 
    for (ll i = 0; i < n; i++) {
        if (map.find(arr[i]-i) == map.end()) { 
            map[arr[i]-i] = 1; 
        } 
        else { 
            map[arr[i]-i]++; 
        } 
    }
    ll res = 0; 
    for (auto x : map) { 
        ll cnt = x.second; 

        res += ((cnt * (cnt - 1)) / 2); 
    } 
  
    return res; 
} 
ll findSubarraySum(ll arr[], ll n, ll sum) 
{ 
    unordered_map<ll, ll> prevSum; 
  
    int res = 0; 
  
    int currsum = 0; 
  
    for (int i = 0; i < n; i++) { 
        currsum += arr[i]; 
        if (currsum == sum)  
            res++;         
  
        if (prevSum.find(currsum - sum) !=  
                                  prevSum.end())  
            res += (prevSum[currsum - sum]);
        prevSum[currsum]++; 
    } 
  
    return res; 
} 
ll sod(ll x){
    ll r,sum=0;
    while(x>0){
        r=x%10;
        x/=10;
        sum+=r;
    }
    return sum;
}
long long modpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main()
{
    fast
    ll n,i;
    cin>>n;
    ll a[n],b[n],c[n];
    for(i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    ll dp[n][3],max1=0;
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(i=1;i<n;i++){
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
    }
    for(i=0;i<3;i++){
        if(dp[n-1][i]>max1)
        max1=dp[n-1][i];
    }
    cout<<max1;
}

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

int main(){

	ll n,w;
	cin >> n >> w;
	ll wt[n],val[n];
	for(ll i=0;i<n;i++){
		cin >> wt[i] >> val[i];
	}
	ll dp[n+1][w+1];
	for(ll i=0;i<=n;i++){
		for(ll j=0;j<=w;j++){
			if(i==0 || j==0)
				dp[i][j] = 0;
			else if(j>=wt[i-1]){
				dp[i][j] = max(dp[i-1][j],val[i-1]+dp[i-1][j-wt[i-1]]);
			}else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	cout << dp[n][w];
	return 0;
}

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

ll gcd(ll b, ll c){
  return c ? gcd(c,b%c) : b;
}
ll lcm(ll b, ll c){
  return b/gcd(b,c)*c;
}

ll f(ll a,ll b, ll c){
  
  ll ans = a;
  ans -= a/b;
  ans -= a/c;
  ans += a/lcm(b,c);
  
  return ans;
}

int main(){
  
  ll A,B,C,D;
  
  cin >> A >> B >> C >>D;
  
  ll ans = f(B,C,D)-f(A-1,C,D);
  
  cout << ans << endl;

}


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

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================



	string S;
	cin >> S;


	if (S == "hi") {
		cout << "Yes";
		return 0;
	}
	
	if (S == "hihi") {
		cout << "Yes";
		return 0;
	}
	if (S == "hihihi") {
		cout << "Yes";
		return 0;
	}
	if (S == "hihihihi") {
		cout << "Yes";
		return 0;
	}
	if (S == "hihihihihi") {
		cout << "Yes";
		return 0;
	}



	cout << "No";









}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int ans[300];
int q[1000][3],qtop;
bool vis[1000];
int main(){
	int n,s,a,b,z,c[3];
	while(true){
	cin>>s>>a>>b;
	s+=a+b;
	if(!s)break;
	cin>>n;
	rep(i,s)ans[i]=2;
	qtop=0;
	rep(i,n){
		rep(j,3){cin>>c[j];c[j]--;}
		cin>>z;
		if(z)rep(j,3)ans[c[j]]=1;
		else{
			rep(j,3)q[qtop][j]=c[j];
			vis[qtop]=false;
			qtop++;
		}
	}
	bool ok=true;
	while(ok){
		ok=false;
		rep(i,qtop){
			if(!vis[i]){
			bool f[3]={false};
			rep(j,3)if(ans[q[i][j]]==1)f[j]=true;
			if(f[0]+f[1]+f[2]==2)rep(j,3)if(!f[j]){ans[q[i][j]]=0;vis[i]=true;ok=true;}
			}
		}
	}
	rep(i,s)cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=1010,M=1000010,P=1e9+7;
const int inf=0x3f3f3f3f;
const int INF=0xcfcfcfcf;
const db eps=1e-9,pi=asin(1)*2;
inline ll read();
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
inline int ADD(int a,int b) { return a+b>=P?a+b-P:a+b; }
inline int MINUS(int a,int b) { return a-b<0?a-b+P:a-b; }
#define plus(a,b) a=ADD(a,b)
#define minus(a,b) a=MINUS(a,b)
#define mul(a,b) a=(1ll*a*(b))%P
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)

inline int quickmi(int x,int n)
{
	int res=1;
	for(;n;n>>=1)
	{
		if(n&1) mul(res,x);
		mul(x,x);
	}
	return res;
}

int n,cnt=0;
int h[N],f[N];
int dp1[N],dp2[N],dp3[N];
inline int solve(int l,int r,int hfa)
{
	if(l>r) return 0;
	int id=++cnt,minn=inf,num=0,lst=l;
//	cerr<<id<<" "<<l<<" "<<r<<"\n";
	for(int i=l;i<=r;i++)
	{
		if(h[i]==minn) num++;
		if(h[i]<minn) minn=h[i],num=1;
	}
	dp1[id]=quickmi(2,minn-hfa);
	dp2[id]=quickmi(2,num);
	dp3[id]=MINUS(dp1[id],2);
	for(int i=l;i<=r+1;i++)
	{
		if(h[i]==minn||i>r)
		{
			int son=solve(lst,i-1,minn);
			lst=i+1;
			if(!son) continue;
			mul(dp1[id],dp1[son]);
			mul(dp2[id],ADD(dp1[son],dp2[son]));
			mul(dp3[id],dp1[son]);
		}
	}
	plus(dp2[id],dp3[id]);
	return id;
}

#ifdef FILE
const int RS=1<<20;
char buf[RS],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,RS,stdin),p1==p2)?EOF:*p1++
#endif
inline ll read()
{
	ll s=0;
	bool flag=false;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') flag=true;
	for(;'0'<=ch&&ch<='9';ch=getchar()) s=(s<<3)+(s<<1)+(ch^'0');
	if(flag) return -s;
	return s;
}

int main()
{
#ifdef FILE
	freopen(FILE ".in","r",stdin);
	freopen(FILE ".out","w",stdout);
#endif
	n=read();
	for(int i=1;i<=n;i++) h[i]=read();
	dp1[0]=1;
	printf("%d\n",dp2[solve(1,n,0)]);
/*
	cerr<<"dp1: \n";
	for(int i=1;i<=cnt;i++) cerr<<dp1[i]<<" ";
	cerr<<"\n";
	cerr<<"dp2: \n";
	for(int i=1;i<=cnt;i++) cerr<<dp2[i]<<" ";
	cerr<<"\n";
	cerr<<"dp3: \n";
	for(int i=1;i<=cnt;i++) cerr<<dp3[i]<<" ";
	cerr<<"\n";
//*/
	return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto s = readln().chomp();
    long ans;

    foreach(i; iota((1 << s.length-1))) {
        long tmp;
        foreach(j; iota(s.length)) {
            tmp *= 10;
            tmp += (s[j] - '0');
            if(i & (1 << j)) {
                ans += tmp;
                tmp = 0;
            }
        }
        ans += tmp;
    }
    writeln(ans);
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int c[3]; scanf("%d %d %d", &c[0], &c[1], &c[2]);
	sort(c, c + 3);
	if(c[0] + c[1] == c[2]) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100100,P=1000000007;
int i,j,k,n,m,nm,ans;
int a[N],f[N];
int ksm(int x,int y) {
	int z=1;
	for (;y;y>>=1,x=(ll) x*x%P) if (y&1) z=(ll) z*x%P;
	return z;
}
int main() {
	scanf("%d%d",&n,&m);
	for (i=1;i*i<=n;i++) if (n%i==0) {
		a[++nm]=i;
		if (i*i<n) a[++nm]=n/i;
	}
	sort(a+1,a+nm+1);
	for (i=1;i<=nm;i++) {
		f[i]=ksm(m,(a[i]+1)/2);
		for (j=1;j<i;j++) if (a[i]%a[j]==0) f[i]=(f[i]+P-f[j])%P;
	}
	for (i=1;i<=nm;i++) {
		if (a[i]&1) ans=((ll) f[i]*a[i]+ans)%P;
		else ans=((ll) f[i]*a[i]/2+ans)%P;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
inf = float('inf')
# ベルマンフォード法 計算量(VE)
# [引数]: 隣接リスト, 始点, 終点
class Bellmanford:
    def __init__(self, to : list, start : int, goal : int):
        self.N = len(to)
        self.to = [s[:] for s in to]
        self.start = start
        self.goal = goal
        self.dist = [inf] * self.N
        self.dist[start] = 0
        self.exists_negative_cycle = False
        self.exists_negative_cycle_stog = False
        self.is_updated = [False] * self.N
    
    # self.distを更新
    def update(self) -> None:
        for _ in range(self.N - 1):
            for v, s in enumerate(self.to):
                if not s: continue
                for nv, w in s:
                    if self.dist[nv] > self.dist[v] + w:
                        self.dist[nv] = self.dist[v] + w
    
    # グラフの負閉路検出
    def detection(self) -> bool:
        for v, s in enumerate(self.to):
            if not s: continue
            for nv, w in s:
                if self.dist[nv] > self.dist[v] + w:
                    self.dist[nv] = self.dist[v] + w
                    self.exists_negative_cycle = True
        return self.exists_negative_cycle
    
    # スタートからゴールまでのパスの負閉路検出
    def detection_stog(self) -> bool:
        for _ in range(self.N):
            for v, s in enumerate(self.to):
                if not s: continue
                for nv, w in s:
                    if self.dist[nv] > self.dist[v] + w:
                        self.dist[nv] = self.dist[v] + w
                        self.is_updated[nv] = True
                    if self.is_updated[v] is True:
                        self.is_updated[nv] = True
        self.exists_negative_cycle_stog = self.is_updated[self.goal]
        return self.exists_negative_cycle_stog

N, M = map(int,input().split())
to = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int,input().split())
    a -= 1; b -= 1
    to[a].append((b, -c))

BF = Bellmanford(to, 0, N-1)
BF.update()

if BF.detection_stog():
    ans = "inf"
else:
    ans = -BF.dist[N-1]

print(ans)

Measured memory_bytes: 52440
N = int(input())
A = list(map(int, input().split()))

C = {}
C2 = 0
for a in A:
    for i in range(1, 9):
        if a < 400*i:
            if i in C.keys():
                C[i] +=  1
            else:
                C[i] = 1
            break
    if a >= 3200:
        C2 += 1
if len(C) > 0:
    print(len(C), len(C)+C2)
else:
    print(1, C2)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >>c;
    double h = b*sin(c*M_PI/180), s = a*h/2, l=a+b+sqrt(a*a+b*b-2*a*b*cos(c*M_PI/180));
    cout <<fixed << setprecision(8)<< s << endl;
    cout <<fixed << setprecision(8)<< l << endl;
    cout <<fixed << setprecision(8)<< h << endl;

    return 0;
}



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

using namespace std;
int d[10]={};
bool ch(int x){
  while(x){
    if(d[x%10])return false;
    x/=10;
  }
  return true;
}

int main(){
  int n,k,i,j;
  cin >> n >> k;
  for(i=0;i<k;i++){
    cin >> j;
    d[j]=1;
  }
  for(i=n;;i++){
    if(ch(i)){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
 
const int MAXN = 1e5+3;
const int MOD = 1e9+7;
const int INF = 1e9+1;

LL gcd(LL a, LL b) {
    return (b == 0) ? a : gcd(b, a%b);
}
int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    LL a, b;
    cin >> a >> b;
    cout << a*b/gcd(a,b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
	int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  rep(i, n){
    cin >> x[i] >> y[i];
  }
  /*
  if(n==2){
    cout << fixed << setprecision(10) << sqrt((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]))/2.0 << endl;
    return 0;
  }
  */
	double x1,x2,x3,y1,y2,y3,ox,oy,r;
  double ans=10000;
  bool ok;
	for(int i=0;i<n;i++){
    for(int j=i+1; j<n; j++){
      for(int k=j+1; k<n; k++){
        x1=(double)x[i];y1=(double)y[i];
        x2=(double)x[j];y2=(double)y[j];
        x3=(double)x[k];y3=(double)y[k];
        ox=((y2-y1)*((y3*y3-y1*y1)+(x3*x3-x1*x1))-(y3-y1)*((y2*y2-y1*y1)+(x2*x2-x1*x1)))/
    				(2*((x3-x1)*(y2-y1)-(x2-x1)*(y3-y1)));
    		if(y2 != y1){
    			oy=(2*(x1-x2)*ox+(y2*y2-y1*y1)+(x2*x2-x1*x1))/(2*(y2-y1));
    		}else{
    			oy=(2*(x1-x3)*ox+(y3*y3-y1*y1)+(x3*x3-x1*x1))/(2*(y3-y1));
    		}
        r = sqrt((ox-x1)*(ox-x1)+(oy-y1)*(oy-y1));
        ok=true;
        rep(i, n){
          double r2=sqrt((ox-x[i])*(ox-x[i])+(oy-y[i])*(oy-y[i]));
          if(r2-r>0.0000001){
            ok=false;
            break;
          }
        }
        if(ok){
          ans=min(ans, r);
        }
      }
    }
	}
  for(int i=0;i<n;i++){
    for(int j=i+1; j<n; j++){

        x1=(double)x[i];y1=(double)y[i];
        x2=(double)x[j];y2=(double)y[j];
        ox=(x1+x2)/2.0;
        oy=(y1+y2)/2.0;
        r = sqrt((ox-x1)*(ox-x1)+(oy-y1)*(oy-y1));
        ok=true;
        rep(i, n){
          double r2=sqrt((ox-x[i])*(ox-x[i])+(oy-y[i])*(oy-y[i]));
          if(r2-r>0.0000001){
            ok=false;
            break;
          }
        }
        if(ok){
          ans=min(ans, r);
        }
      }
    }
  cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    bool ans = false;

    if(s[0] == 'A'){
        if(s[1] == 'B' || s[2] == 'B') ans = true;
    }
    else{
        if(s[1] == 'A' || s[2] == 'A') ans = true;
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = [int(a) for a in input().split()]
count = Counter(A)
all_sum = 0
for key, val in count.items():
    all_sum += val * (val - 1)
all_sum //= 2

for k in range(N):
    num = count[A[k]]
    before = num * (num - 1) // 2
    after = (num - 1) * (num - 2) // 2
    print(all_sum - before + after)

Measured memory_bytes: 26028
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>

using namespace std;

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

  map<long long, int> A;
  vector<long long> B(N);
  for (int i = 0; i < N; ++i)
  {
    long long a;
    cin >> a >> B[i];
    if(A.count(a) == 0) A.insert(make_pair(a, i));
    else B[A[a]] += B[i];
  }

  long long sum = 0;
  for (auto itr = A.begin(); itr != A.end(); ++itr)
  {
    if (M < B[itr->second])
    {
      sum += itr->first * M;
      break;
    }
    else
    {
      sum += itr->first * B[itr->second];
      M -= B[itr->second];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 7296
#include <stdio.h>
#include <functional>
#include <algorithm>

using namespace std;
typedef long long llong;

#define MAX 51
#define MAX2 61
const llong mod = 1000000000 + 7;

int N, M, Q;
int x, X[MAX];
int A[MAX], B[MAX], C[MAX], D[MAX];
llong ans = 0;

void func()
{
  llong result = 0;
  for (int i = 0; i < Q; i++)
  {
    if (X[B[i] - 1] - X[A[i] - 1] != C[i])
    {
      continue;
    }
    result += D[i];
  }
  ans = max(ans, result);
}

void comb(int n, int m)
{
  // 要素数が少ない場合
  if (n < N + M - 1)
  {
    // |が少ない場合
    if (m < M - 1)
    {
      comb(n + 1, m + 1);
    }
    // oが少ないとき
    if (n - m < N)
    {
      X[n - m] = m + 1;
      comb(n + 1, m);
    }
    return;
  }

  func();
}

int main()
{

  scanf("%d%d%d", &N, &M, &Q);

  int Ans[11];
  for (int i = 0; i < N; i++)
  {
    Ans[i] = 1;
  }

  for (int i = 0; i < Q; i++)
  {
    scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
  }

  comb(0, 0);

  printf("%lld\n", ans);

  return 0;
}

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

int main(){
    string s;
    cin >>s;
    if(s.size()==2) cout << s << endl;
    else {
        char tmp=s[0];
        s[0]=s[2];
        s[2]=tmp;
        cout << s << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200005],n,k,b[200005];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
	}
	sort(a+1,a+n+1);
	int tot=0;
	for(int i=1;i<=n;++i){
		if(a[i]!=a[i-1]||i==1)++tot;
		++b[tot];
	}
	sort(b+1,b+tot+1);k=min(tot,k);
	for(int i=1;i<=k;++i){
		n-=b[tot-i+1];
	}
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 1792
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;


int N, K;
int main()
{
	scanf("%d %d", &N, &K);
	for(int i = 0; i < N; i++) {
		int temp;
		scanf("%d", &temp);
	}
	int left = N - K, ans = 1;
	ans += (left / (K - 1));
	if (left % (K - 1)) {
		ans ++;
	}
	printf("%d\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc084/tasks/abc084_d
# D - 2017-like Number
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


# 素数判定
def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(pow(n, 0.5)) + 1):
        if n % k == 0:
            return False
    return True


def resolve():
    q = int(input())
    LR = [list(map(int, input().split())) for _ in range(q)]

    # 1であれば2017に似た整数、0であれば2017に似ていない数字
    Lile_2017 = [0] * (10 ** 5 + 1)

    # 素数判定済み配列
    prime = set()
    not_prime = set()

    # 1~100000が2017に似た数かどうか判定する
    for n in range(1, 10 ** 5 + 1):
        flg1, flg2 = False, False
        if n % 2 != 0:
            if n in prime:
                flg1 = True
            elif n in not_prime:
                flg1 = False
            else:
                flg1 = is_prime(n)
                prime.add(n) if flg1 else not_prime.add(n)

            if (n + 1) // 2 in prime:
                flg2 = True
            elif (n + 1) // 2 in not_prime:
                flg2 = False
            else:
                flg2 = is_prime((n + 1) // 2)
                prime.add((n + 1) // 2) if flg1 else not_prime.add((n + 1) // 2)

        Lile_2017[n - 1] += 1 if flg1 and flg2 else 0

    # 2017に似た数の累積和配列を作る
    Ruiseki = [0]
    for i in range(1, 10 ** 5 + 1):
        Ruiseki.append(Ruiseki[-1] + Lile_2017[i - 1])

    # クエリに答える
    for l, r in LR:
        print(Ruiseki[r] - Ruiseki[l - 1])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 37256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define MOD 10000007
#define PB push_back

using namespace std;



int main(){
  
  string  s,t;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  
  string u;
  cin >> u;
  
  if(u == s){
    cout << a - 1 << " " << b <<endl;
  }else{
    cout << a << " " <<b - 1<< endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

int check(string s){
    int ans = 1;
    for(int i = 0;i < s.size();++i){
        if(s[i] != s[s.size()-1-i]){
            ans = 0;
        }
    }

    return ans;
}

int main(void){
    string s, s_first, s_last;
    cin >> s;
    s_first.assign(s, 0, (s.size()-1)/2);
    s_last.assign(s, (s.size()+2)/2, s.size()-1);

    int ans_flag = 1;
    if(check(s) == 0){
        ans_flag = 0;
    }
    if(check(s_first) == 0){
        ans_flag = 0;
    }
    if(check(s_last) == 0){
        ans_flag = 0;
    }

    if(ans_flag == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
from collections import defaultdict
root=[-1]*(N+M)
def find(i):
    global root
    if root[i]>=0:
        root[i]=find(root[i])
        return root[i]
    return i
def make(a,b):
    global root
    ra=find(a)
    rb=find(b)
    if ra==rb:
        return
    elif root[ra]<=root[rb]:
        root[ra]+=root[rb]
        root[rb]=ra
    else:
        root[rb]+=root[ra]
        root[ra]=rb
    return
for i in range(N):
    X=list(map(int,input().split()))
    for k in range(X[0]):
        make(i,N+X[k+1]-1)
r0=find(0)
flag=True
for i in range(1,N):
    if find(i)!=r0:
        flag=False
        break
if flag:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9916