akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int X[110000];
int Y[110000];
pair<int,int>p[110000];
pair<int,int>q[110000];
map<pair<int,int>,int>M;
int bfs[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d%d",X+i,Y+i);
		p[i]=make_pair(X[i],Y[i]);
		q[i]=make_pair(Y[i],X[i]);
		M[make_pair(X[i],Y[i])]=i;
	}
	std::sort(p,p+a);
	std::sort(q,q+a);
	long long ret=0;
	for(int i=0;i<a;i++){
		if(bfs[i]==0){
			bfs[i]=1;
			queue<int>Q;
			set<int>R;
			set<int>C;
			R.insert(X[i]);
			C.insert(Y[i]);
			Q.push(i);
			int cnt=0;
			while(Q.size()){
				int at=Q.front();Q.pop();
				cnt++;
				int ad1=lower_bound(p,p+a,make_pair(X[at],Y[at]))-p;
				if(ad1&&p[ad1-1].first==p[ad1].first){
					int to=M[p[ad1-1]];
					if(!bfs[to]){
						bfs[to]=1;
						Q.push(to);
						R.insert(X[to]);
						C.insert(Y[to]);
					}
				}
				if(ad1<a-1&&p[ad1+1].first==p[ad1].first){
					int to=M[p[ad1+1]];
					if(!bfs[to]){
						bfs[to]=1;
						Q.push(to);
						R.insert(X[to]);
						C.insert(Y[to]);
					}
				}
				int ad2=lower_bound(q,q+a,make_pair(Y[at],X[at]))-q;
				if(ad2&&q[ad2-1].first==q[ad2].first){
					int to=M[make_pair(q[ad2-1].second,q[ad2-1].first)];
					if(!bfs[to]){
						bfs[to]=1;
						Q.push(to);
						R.insert(X[to]);
						C.insert(Y[to]);
					}
				}
				if(ad2<a-1&&q[ad2+1].first==q[ad2].first){
					int to=M[make_pair(q[ad2+1].second,q[ad2+1].first)];
					if(!bfs[to]){
						bfs[to]=1;
						Q.push(to);
						R.insert(X[to]);
						C.insert(Y[to]);
					}
				}				
			}
			if(R.size()>=2&&C.size()>=2)ret+=(long long)R.size()*C.size()-cnt;
		}
	}
	printf("%lld\n",ret);
}

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

int main(void){
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if(u == s) a--;
  if(u == t) b--;
  printf("%d %d", a, b);
  return 0;
}

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

int main()
{
	string str;
	cin >> str;
	int l = str.length();
	int cnt = 0;
	for (int i = 0; i < l / 2; i++) {
		if (str[i] != str[l - i - 1]) {
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import sys

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


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    res = f_inf
    for y in range(-100, 101):
        cost = 0
        for i in range(n):
            cost += pow(abs(A[i] - y), 2)
        res = min(res, cost)
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	ll n,m,x,y,z,tmp[8][1000],ans[8]={};
	cin>>n>>m;
	rep(i,n){
		cin>>x>>y>>z;
		tmp[0][i]=x+y+z;	//+++
		tmp[1][i]=x+y-z;	//++-
		tmp[2][i]=x-y+z;	//+-+
		tmp[3][i]=-x+y+z;	//-++
		tmp[4][i]=x-y-z;	//+--
		tmp[5][i]=-x+y-z;	//-+-
		tmp[6][i]=-x-y+z;	//--+
		tmp[7][i]=-x-y-z;	//---
	}
	rep(j,8)sort(tmp[j],tmp[j]+n,greater<>());
	rep(i,m)rep(j,8)ans[j]+=tmp[j][i];
	ll final_ans=0;
	rep(i,8)if(final_ans<ans[i])final_ans=ans[i];
	print(final_ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


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


const int MAX_N = 100010;
bool isbroken[100010];
int dp[100010];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int m; cin >> m;
	VE a(m);
	rep(i, m)cin >> a[i];
	rep(i, m)isbroken[a[i]] = true;
	dp[0] = 1;
	rep(i, n) {
		if (!isbroken[i + 1]) {
			dp[i + 1] += dp[i]; dp[i + 1] %= MOD;
		}
		if (!isbroken[i + 2]) {
			dp[i + 2] += dp[i]; dp[i + 2] %= MOD;
		}
	}
	cout << dp[n] << endl;
	return 0;
}


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

int main()
{
    ll n, m;
    cin >> n;
    vecll a(n), b, result;
    for (auto &x : a)
        cin >> x;

    cin >> m;
    b.resize(m);
    for (auto &y : b)
        cin >> y;

    set_difference(all(a), all(b), inserter(result, end(result)));

    for (auto &z : result)
        cout << z << endl;
}


Measured memory_bytes: 8032
#include <iostream>

using namespace std;

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

    long long int R = N % (A+B);
    long long int Q = N / (A+B);
    
    if(R <= A){
        cout << Q * A + R; 
    }else{
        cout << Q * A + A; 
    }

    return 0;

 }

Measured memory_bytes: 256
#include<iostream>

struct Node{
	int left;
	int right;
	int id;
	int parent;
};

void Preorder(Node A);
void Inorder(Node A);
void Postorder(Node A);

using namespace std;

Node Array[30];

int main(void)
{
	int n,root;
	
	cin>>n;
	for(int i=0;i<n;i++) Array[i].parent=-1;
	for(int i=0;i<n;i++)
	{
		int id;
		
		cin>>id;
		Array[id].id=id;
		cin>>Array[id].left>>Array[id].right;
		Array[Array[id].left].parent=id;
		Array[Array[id].right].parent=id;
	}
	for(int i=0;i<n;i++)
		if(Array[i].parent==-1)
		{
			root=i;
			break;
		}
	cout<<"Preorder"<<endl;
	Preorder(Array[root]);
	cout<<endl;
	cout<<"Inorder"<<endl;
	Inorder(Array[root]);
	cout<<endl;
	cout<<"Postorder"<<endl;
	Postorder(Array[root]);	
	cout<<endl;
	
	return 0;
}

void Preorder(Node A)
{
	cout<<" "<<A.id;
	if(A.left!=-1)
	{
		Preorder(Array[A.left]);
	}
	if(A.right!=-1)
	{
		Preorder(Array[A.right]);
	}
}

void Inorder(Node A)
{
	if(A.left!=-1)
		Inorder(Array[A.left]);
	cout<<" "<<A.id;
	if(A.right!=-1)
		Inorder(Array[A.right]);
}

void Postorder(Node A)
{
	if(A.left!=-1)
	{
		Postorder(Array[A.left]);
	}
	if(A.right!=-1)
	{
		Postorder(Array[A.right]);
	}
	cout<<" "<<A.id;
}

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

int main() {
int N;
  cin>>N;
 float S=0;
  vector<float> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
    S+=1/vec.at(i);
  }
  cout<<1/S<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i, j, tmp;
 
  /* 数値を格納する配列 */
    int l[200];
 
  /* 数値の総数を入力 */
    int n;
    scanf("%d", &n);
 
  /* 配列に格納する数値を入力 */
    for (i=0; i<2*n; ++i)
        scanf("%d", &l[i]);
 
  /* 数値を昇順にソート */
    for (i=0; i<2*n; ++i) {
        for (j=i+1; j<2*n; ++j) {
            if (l[i] > l[j]) {
                tmp =  l[i];
                l[i] = l[j];
                l[j] = tmp;
            }
        }
    }
    int sum=0;
    for(int i=0;i<2*n;i=i+2){
        sum+=l[i];
    }
    printf("%d\n",sum);
    return 0;
}
     

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	ll k;
	cin>>s>>k;
	for (int i=0;i<(int)s.size();i++){
		if (i+1==(int)s.size()){
			k=k%26;
			for (int j=0;j<k;j++){
				if (s[i]=='z') s[i]='a';
				else s[i]++;
			}
		}
		else{
			if (s[i]=='a') continue;
			ll t=(ll)('z'-s[i]+1);
			if (k>=t){
				s[i]='a';
				k-=t;
			}
		}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

int comb2(int n) {
	return n * (n - 1) / 2;
}

int main() {
	int N;
	std::cin >> N;

	int groupSum;
	int numGroup;
	int numEdge;
	if(N % 2 == 0) {
		groupSum = N + 1;
		numGroup = N / 2;
		numEdge = (2 * 2) * comb2(numGroup);
	} else {
		groupSum = N;
		numGroup = (N + 1) / 2;
		numEdge = (2 * 2) * comb2(numGroup - 1) + (N - 1);
	}

	std::cout << numEdge << std::endl;
	for(int i = 1; i <= N; i++) {
		const int pairNum = groupSum - i;
		for(int j = i + 1; j <= N; j++) {
			if(j == i || j == pairNum) {
				continue;
			}

			std::cout << i << " " << j << std::endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*(b/gcd(a,b));}
int f(int *d,int r){
  int n=r,i;
  for(i=0;i<r;i++){
    if(d[i])break;
  }
  if(i==r)return 1;
  if(d[0]==0)return r;
  for(i=1;i<r;i++){
    if(d[i])n=gcd(n,i);
  }
  for(i=0;i<r;i++){
    if(i%n==0)d[i/n]=d[i];
  }
  return r/n;
}
  int ans[150000]={0};
  int a,b,i,j,n,m,l,d[10][1500000],r[10]={0};
int main(){
  char s[2500],c[]={"0123456789ABCDEF"};
  scanf("%d",&m);
  while(m--){
    for(i=0;i<100000;i++)ans[i]=0;
    l=1;
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%s",s);//printf("%d\n",s[2]);
      if(l>10000)continue;
      for(j=r[i]=0;s[j];j+=2){
	for(a=0;s[j  ]-c[a];a++);//printf("a%d\n",a);
	for(b=0;s[j+1]-c[b];b++);//printf("b%d\n",b);
	d[i][r[i]++]=a*16+b;//printf("%d\n",d[i][r[i]-1]);
      }//printf("\n");
      l=lcm(l,r[i]=f(d[i],r[i]));//printf("%d ",l);
    }//printf("\n");
    for(i=0;i<n;i++){
      for(j=0;j<r[i];j++)ans[l/r[i]*j]|=d[i][j];
    }//for(i=0;i<l;i++)printf("%x",ans[i]);printf("\n");
    l=f(ans,l);//printf("c\n");
    if(l>1024)printf("Too complex.\n");
    else {
      for(i=0;i<l;i++)printf("%02X",ans[i]);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 19060
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int ar[5], i;
    for(i=0; i<5; i++){
        scanf("%d",&ar[i]);
    }
    for(int j=0;j<5; j++){
        if(ar[j]==0){
            printf("%d\n",j+1);
        }
    }
    return 0;
}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
const double PI  = acos(-1.0);

//-------------------------------------------


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

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

    bool dp[110][110 * 100];
    memset( dp, 0 ,sizeof(dp));
    dp[0][0] = true;

    for(int i = 0;i < n; i++){
        for(int j=0; j <= 100 * n;j++){
            if(j<s[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = dp[i][j]|| dp[i][j-s[i]];
        }
    }
    int j;
    for(j=10004;j>=1;j--){
        if(dp[n][j]==true&&j%10!=0)break;
    }
    cout<<j<<endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
const double EPS=1e-6;
 
double cross(P a, P b){ return imag(conj(a)*b); }
P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}
 
int main(){
  int n;
  cin>>n;
  vector<P> G(n);
  for(int i=0;i<n;i++){
    double x,y;
    cin>>x>>y;
    G[i]=P(x,y);
  }
  if(n%2){cout<<"NA"<<endl;return 0;}  
  double len=abs(G[0]-G[1]);
  for(int i=0;i<n/2;i++){
    double a=abs(G[i]-G[(i+1)]);
    double b=abs(G[i+n/2]-G[(i+n/2+1)%n]);
    if(abs(a-b)>EPS){cout<<"NA"<<endl;return 0;}
  }
  P ans=crossPoint(L(G[0],G[n/2]),L(G[1],G[n/2+1]));
  printf("%lf %lf\n",real(ans),imag(ans));
  return 0;
}

Measured memory_bytes: 3348
s = input()
N = int(input())

printList = []

for i in range(N):
    c = list(map(str, input().split()))
    start = int(c[1])
    end = int(c[2])+1
    
    if c[0] == "print":
        printList.append(s[start:end])
    elif c[0] == "replace":
        r = c[3]
        s = s[:start] + r + s[end:]
    elif c[0] == "reverse":
        r = s[start:end]
        sr = r[::-1]
        s = s[:start] + sr + s[end:]
    
for p in printList:
    print(p)


Measured memory_bytes: 5612
N = int(input())
S = input()

ret = sum(s == 'E' for s in S[1:]) # 最初は一番左の人をリーダーに
variation = ret
for i in range(N-1):
    if S[i] == 'W':
        variation += 1
    if S[i+1] == 'E':
        variation -= 1
    if ret > variation:
        ret = variation
        
print(ret)

Measured memory_bytes: 3700
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(H, W, Si):
    Si = ['#' * (W + 2)] + ['#' + S + '#' for S in Si] + ['#' * (W + 2)]
    lamp_map = [[[-1, -1] for _ in range(W + 2)] for _ in range(H + 2)]
    ans = 0
    for h in range(1, H + 2):
        for w in range(1, W + 2):
            # block
            if Si[h][w] == '#':
                lamp_map[h][w][0] = 0
                lamp_map[h][w][1] = 0
                continue
            # vertical
            if lamp_map[h - 1][w][0] > 0:
                lamp_map[h][w][0] = lamp_map[h - 1][w][0]
            else:
                tmp = 0
                while Si[h + tmp][w] == '.':
                    tmp += 1
                lamp_map[h][w][0] = tmp
            # horizon
            if lamp_map[h][w - 1][1] > 0:
                lamp_map[h][w][1] = lamp_map[h][w - 1][1]
            else:
                tmp = 0
                while Si[h][w + tmp] == '.':
                    tmp += 1
                lamp_map[h][w][1] = tmp
            ans = max(ans, sum(lamp_map[h][w]) - 1)
    print(ans)


if __name__ == '__main__':
    H, W = map(int, input().split())
    Si = [input() for _ in range(H)]

    # # test
    # import func
    # H, W = 2000, 2000
    # Si = [''.join([func.random_str(W, '.')]) for _ in range(H)]
    # for s in Si:
    #     print(s)
    solve(H, W, Si)


Measured memory_bytes: 433844
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{

  string w;
  cin>>w;
  int cnt[26]={0};
  rep(i,w.length()){
    cnt['z'-w[i]]++;
  }
  rep(i,26){
    // cout<<cnt[i]<<endl;
    if(cnt[i]%2!=0){
      cout<<"No"<<endl;
      return 0;
    }
  }


  cout<<"Yes"<<endl;
  return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

int main(){
    
    int N,x;cin>>N>>x;
    if(x==1||x==2*N-1) cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        if(x>=N){
            for(int i=0;i<2*N-1;i++){
                int a=(x+i-(N-1)-1)%(2*N-1)+1;
                printf("%d\n",a);
            }
        }else{
            for(int i=0;i<2*N-1;i++){
                int a=(x+i+N-1)%(2*N-1)+1;
                printf("%d\n",a);
            }
        }
    }
}


Measured memory_bytes: 1536
using System;


namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            if(a < b && b < c){
                Console.WriteLine("Yes");
            }
            else 
            {
                Console.WriteLine("No");
                            }
           
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 9012
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N, M;
    cin >> N >> M;
    vector<ll>L(M), R(M);
    for(int i = 0; i < M; i++)cin >> L[i] >> R[i];
    ll l = L[0], r = R[0];
    for(ll i = 1; i < M; i++){
        if(r < L[i] || R[i] < l){
            cout << 0 << endl;
            return 0;
        }
        l = max(l, L[i]);
        r = min(r, R[i]);
    }
    cout << r - l + 1 << endl;

    return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b; cin >> a >> b;

  if(a%3==0 || b%3==0 || (a+b)%3==0){
    cout << "Possible" << endl;
    return 0;
  }

  cout << "Impossible" << endl;
  
  return 0;
}


Measured memory_bytes: 3576
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Scanner;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		int one = Integer.parseInt(s.split(" ")[0]),
		 		two = Integer.parseInt(s.split(" ")[1]),
				three = Integer.parseInt(s.split(" ")[2]),
				four = Integer.parseInt(s.split(" ")[3]),
				five = Integer.parseInt(s.split(" ")[4]),
				six = Integer.parseInt(s.split(" ")[5]);
				s	= scan.nextLine();
		for (int i = 0; i < s.length(); i++) {
			int tmp;
			if (s.charAt(i) == 'E') {
				tmp = one;
				one = four;
				four = six;
				six = three;
				three = tmp;
			} else if (s.charAt(i) == 'N') {
				tmp = one;
				one = two;
				two = six;
				six = five;
				five = tmp;
			} else if (s.charAt(i) == 'S') {
				tmp = one;
				one = five;
				five = six;
				six = two;
				two = tmp;
			} else if (s.charAt(i) == 'W') {
				tmp = one;
				one = three;
				three = six;
				six = four;
				four = tmp;
			}

		}
		System.out.println(one);
	}
}



Measured memory_bytes: 26208
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        int d = sc.nextInt();
        sc.close();

        int cnt = 0;
        for(int i=l; i<=r; i++) {
            if(i % d == 0) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 35572
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

signed main(){
    int n,q; cin >> n >> q;
    string s; cin >> s;
    char t[q], d[q];
    REP(i,q)  cin >> t[i] >> d[i];
    int ok = n;
    int ng = -1;
    int mid;
    while(ok - ng > 1){
        mid = (ok+ng)/2;
        int loc = mid;
        bool flg = false;
        REP(i,q){
            if(loc == -1) break;
            if(loc == n){
                flg = true;
                break;
            }
            if(t[i] == s[loc]){
                if(d[i] == 'R') loc++;
                else loc--;
                if(loc == n){
                    flg = true;
                    break;
                }
                if(loc == -1) break;
            }
        }
        if(flg) ok = mid;
        else ng = mid;
    }
    int ok2 = -1;
    int ng2 = n;
    int mid2;
    while(ng2 - ok2 > 1){
        mid2 = (ok2+ng2)/2;
        int loc = mid2;
        bool flg = false;
        REP(i,q){
            if(loc == n) break;
            if(loc == -1){
                flg = true;
                break;
            }
            if(t[i] == s[loc]){
                if(d[i] == 'R') loc++;
                else loc--;
                if(loc == n) break;
                if(loc == -1){
                    flg = true;
                    break;
                }
            }
        }
        if(flg) ok2 = mid2;
        else ng2 = mid2;
    }
    cout << max(n - (n-ok) - (ok2+1),0ll) << endl; 
}

Measured memory_bytes: 900
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;

using namespace std;

int check(int, int*, int);


int lb[1000001];
int main(){
    while(1){
        int N,M;
        cin >> N >> M;
        
        if(N==0 && M==0){
            break;
        }
        
        int s[100000];
        for(int i=0; i<N; i++){
            cin >> s[i];
        }
        
        for(int i=0; i<1000001; i++){
            lb[i] = lower_bound(s,s+N,i) - s;
        }
        
        int left=1;
        int right=1000001;
        while(right-left>1){
            int temp=(left+right)/2;
            
            if(check(temp,s,N)>=M){
                left = temp;
            }else{
                right = temp;
            }
        }
        if(check(left,s,N)!=10000000 && check(left,s,N)>=M){
            cout<<left<<endl;
        }else{
            cout<<-1<<endl;
        }
    }
}

int check(int X, int* s, int N){
    int num=0;
    int lv=1;
    if(s[0]>=1+X){
        return 10000000; // cannot clear
    }
    
    while(lv+X<=s[N-1]){
        int enemy1 = lb[lv];
        int enemy2 = enemy1-1;
        
        
        int lvup=1;
        if(enemy1>=0 && enemy1<=N-1 && s[enemy1]<lv+X){
            lvup = max(lvup, X-abs(lv-s[enemy1]));
        }
        if(enemy2>=0 && enemy2<=N-1 && s[enemy2]<lv+X){
            lvup = max(lvup, X-abs(lv-s[enemy2]));
        }
        num++;
        lv+=lvup;
    }
    num++;
    return num;
}



Measured memory_bytes: 7368
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll L;
  cin >> L;
  vector<ll> ones;
  ll i = 0;
  while ((L>>i) > 0) {
    if ((L>>i) & 1) {
      ones.push_back(i);
    }
    ++i;
  }
  reverse(all(ones)); // decreasing order

  // For Debug
  // for (auto x : ones) {
  //   cout << x << endl;
  // }

  ll N = ones[0]; // The length of vertices without root(0).
  vector<triple> edges;
  rep(i, N) {
    // i+1 is the target number.
    edges.emplace_back(i, i+1, 0);
    edges.emplace_back(i, i+1, 1LL << i);
  }
  // Now, N is the last indice.

  ll summed = 1<<N;
  rep(i, ones.size()) {
    if (i == 0) { continue; }
    ll M = ones[i]; // The offset. e.g. 2 for 1 of 100
    edges.emplace_back(M, N, summed); // there are 2**M paths in [0, M]
    // Do somethinbg
    summed += 1<<M;
  }

  cout << N+1 << " " << edges.size() << endl;
  for (auto x : edges) {
    int i, j, c;
    tie(i, j, c) = x;
    cout << i+1 << " " << j+1 << " " << c << endl; // 1-indexed
  }
}


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

#define MAX_N 500001

int main() {
  int N, Q;
  string S;
  cin >> N >> S >> Q;

  vector<set<int>> sets(26, set<int>({MAX_N}));

  //初期化
  for (int i = 0; i < N; i++) {
    sets[(int)(((char)S[i]) - 'a')].insert(i);
  }
  for (int q = 0; q < Q; q++) {
    int t;
    cin >> t;
    //(t == 1) ? query1(S, sets) : query2(sets);
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;
      i--;
      sets[(int)(((char)S[i]) - 'a')].erase(i);
      S[i] = c;
      sets[(int)(c-'a')].insert(i);
    }
    else {
      int l, r;
      cin >> l >> r;
      l--; r--;
      int cnt = 0;
      for (int i = 0; i < 26; i++) {
        //set<int> s = sets[i];
        //auto it = lower_bound(sets[i].begin(), sets[i].end(), l);
        auto it = sets[i].lower_bound(l);
        //cout << *it << endl;
        if((it != sets[i].end()) && (*it <= r)) cnt++;
      }
      cout << cnt << endl;
    }
  }
}

Measured memory_bytes: 24196
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
using namespace std;

int main(){
    int n,x;
    cin >> n >> x;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n-1;i++){
        if(x < a[i]) break;
        ans++;
        x -= a[i];
    }
    if(x == a[n-1]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
def c_management_tree():
    N = int(input())
    A = [int(i) for i in input().split()]

    tree = [[] for _ in range(N + 1)]
    for k, a in enumerate(A, 2):
        tree[a].append(k)

    ans = [len(t) for t in tree]
    return ' '.join(map(str, ans[1:]))

print(c_management_tree())

Measured memory_bytes: 61008
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<int(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=100005;
ll f[N],g[N],n,ans,r,p;

int main(){
	read(n);
	f[0]=1;
	rep(i,0,n){
		read(r);
		while(p<=i&&r){
			if(f[p]>r){
				f[p]-=r;
				g[p+1]+=r;
				g[i+1]-=r;
				ans+=r*(i-p+1);
				r=0;
			}
			else{
				r-=f[p];
				g[p+1]+=f[p];
				g[i+1]-=f[p];
				ans+=f[p]*(i-p+1);
				f[p]=0;
				p++;
				g[p]+=g[p-1];
				f[p]=g[p];
			}
		}
		if(r){
			puts("-1");
			return 0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5084
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.EducationalDP
{
    class P
    {
        static long mask = 1000000000 + 7;

        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            List<int>[] graph = new List<int>[n];
            for (int i = 0; i < n; i++) graph[i] = new List<int>();
            for(int i = 0; i < n - 1; i++)
            {
                int[] xy = ReadInts();
                int x = xy[0] - 1;
                int y = xy[1] - 1;
                graph[x].Add(y);
                graph[y].Add(x);
            }
            long[,] dp = new long[n, 2];//j=0:white,j=1:black
            bool[] visit = new bool[n];
            DFS(ref dp,ref visit, graph, 0);
            Console.WriteLine((dp[0, 0] + dp[0, 1]) % mask);
        }

        static void DFS(ref long[,] dp,ref bool[] visit,
            List<int>[] graph, int now)
        {
            visit[now] = true;
            
            dp[now, 0] = 1;
            dp[now, 1] = 1;
            for (int i = 0; i < graph[now].Count; i++)
            {
                int to = graph[now][i];
                if (visit[to]) continue;

                DFS(ref dp,ref visit, graph, to);
                dp[now, 0] *= (dp[to, 0] + dp[to, 1]) % mask;
                dp[now, 0] %= mask;
                dp[now, 1] *= dp[to, 0];
                dp[now, 1] %= mask;
            }
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 33164
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var a = o.a();
  var b = o.a();
  return Math.max(0,a-2*b);
}

Measured memory_bytes: 7372
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int sum = 0;

		for(int i = 0; i < m; i++) sum += sc.nextInt();

		System.out.println(sum > n ? -1 : n - sum);
	}
}

Measured memory_bytes: 46188
#include <stdio.h>

int N,M; char S[10][10];
long long D[10][10];

int main()
{
	scanf ("%d %d",&N,&M);
	for (int i=0;i<N;i++) scanf ("%s",S[i]);

	D[0][0] = 1;
	int c = 0;
	for (int i=0;i<N;i++){
		for (int j=0;j<M;j++) if (S[i][j] == '#'){
			if (i) D[i][j] += D[i-1][j];
			if (j) D[i][j] += D[i][j-1];
			c++;
		}
	}

	if (c != N + M - 1){
		puts("Impossible");
		return 0;
	}
	for (int i=0;i<N;i++){
		for (int j=0;j<M;j++){
			if ((S[i][j] == '#') ^ (D[i][j] == 1)){
				puts("Impossible");
				return 0;
			}
		}
	}

	puts("Possible");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template<class S,class T>
string to_string(pair<S,T> p){
	return "{"+to_string(p.first)+","+to_string(p.second)+"}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
	int N;
	cin>>N;
	vector<vector<int>> qs(N);
	vector<int> pt(N);
	FOR(i,N){
		FOR(j,N-1){
			int A;
			cin>>A;
			qs[i].push_back(A-1);
		}
	}
	int ans=0;
	
	queue<Pi> q;
	{
	vector<int> g(N,-1);
	FOR(i,N){
		g[i]=qs[i][pt[i]];
		if(g[g[i]]==i){
			q.push(Pi(i,g[i]));
		}
	}
	}
	while(!q.empty()){
		ans++;
		while(!q.empty()){
			Pi p=q.front();
			q.pop();
			pt[p.first]++;
			pt[p.second]++;
		} 
		vector<int> g(N,-1);
		FOR(i,N){
			if(!qs[i].empty())g[i]=qs[i][pt[i]];
			if(g[i]>=0&&g[g[i]]==i&&i!=g[i])q.push(Pi(i,g[i]));
		}
	}
	FOR(i,N)if(pt[i]<N-2)ans=-1;
	print(ans);
  return 0;
}


Measured memory_bytes: 6400
#include<iostream>
using namespace std;
int main (){
	int n=0,x[101],y;
	cin>>n;
	for(y=1;y<=n;y++){
		cin>>x[y];
	}
	for( y=n;y>0;y--){
		if(y!=n){
			cout<<" ";
		}
		cout<<x[y];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>//万能头文件 
using namespace std;
bool w=0,n=0,e=0,s=0;
string str;
inline bool check()//判断是否符合条件 
{
    if(w==1&&e==1&&n==1&&s==1)return 1;
    if(w==1&&e==1&&n==0&&s==0)return 1;
    if(w==0&&e==0&&n==1&&s==1)return 1;
    if(w==0&&e==0&&n==0&&s==0)return 1;
    return 0;
}
int main()
{
	getline(cin,str);
	for(int i=0;str[i]!='\0';i++)
	{
		if(str[i]=='W')w++;
	    else if(str[i]=='N')n++;
	    else if(str[i]=='E')e++;//累加 
	    else if(str[i]=='S')s++;//if_else是连续结构，不用加大括号 
	}
	puts(check()?"Yes":"No");//如果check的返回值为1输出Yes,否则输出No 
    return 0;//圆满的结束 
}

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

string S;

int main(){
    cin >> S;

    int A = (S[0] - '0') * 10 + (S[1] - '0');
    int B = (S[2] - '0') * 10 + (S[3] - '0');

    if( ( 1 <= A && A <= 12 ) && ( 1 <= B && B <= 12 ) ) cout << "AMBIGUOUS" << endl;
    else if( 1 <= A && A <= 12 )    cout << "MMYY" << endl;
    else if( 1 <= B && B <= 12 )    cout << "YYMM" << endl;
    else    cout << "NA" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007
//#define MOD 7

using namespace std;

int main(void){
    // Your code here!
    long long a, b;
    
    cin >> a >> b;
    if(a <= 8 && b <= 8)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;
        
    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N,A,B,C = map(int,readline().split())

val = [A,B,C]
# 0,0を作ってはいけない
# 基本的には小さいほうに1を足す
# 両方とも1の場合は、次の操作で選ばれるほうに1を足す
# 両方とも次の操作で選ばれるときはどちらに足してもよい

S = [readline().rstrip() for i in range(N)]
ans = []

def get_ind(s):
  res = []
  for c in s:
    if c == "A":
      res.append(0)
    elif c == "B":
      res.append(1)
    elif c == "C":
      res.append(2)
  return res

def get_alpha(x):
  return "ABC"[x]

for i in range(N):
  ind_x,ind_y = get_ind(S[i])
  if val[ind_x] == 0 and val[ind_y] == 0:
    print("No")
    exit(0)
  if val[ind_x] < val[ind_y]:
    ans += [get_alpha(ind_x)]
    val[ind_x] += 1
    val[ind_y] -= 1
  elif val[ind_x] > val[ind_y]:
    ans += [get_alpha(ind_y)]
    val[ind_y] += 1
    val[ind_x] -= 1
  else:
    if i + 1 < N and get_alpha(ind_x) in S[i + 1]:
      ans += [get_alpha(ind_x)]
      val[ind_x] += 1
      val[ind_y] -= 1
    else:
      ans += [get_alpha(ind_y)]
      val[ind_y] += 1
      val[ind_x] -= 1
      
print("Yes")
for a in ans:
  print(a)


Measured memory_bytes: 17104
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#include <atcoder/all>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    dsu d(N);
    REP(i, 0, M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        d.merge(a, b);
    }
    ll p = 0;
    REP(i, 0, N) {
        if (d.leader(i) == i) {
            p++;
        }
    }
    cout << p - 1 << endl;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define sz(x) (int((x).size()))
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
template<typename T> bool domax(T &a, T b) { return (b > a ? (a = b, true) : false); }
template<typename T> bool domin(T &a, T b) { return (b < a ? (a = b, true) : false); }
typedef long long ll;

const int maxn = 100*1000+5;

int n, x[maxn], y[maxn], ans;
std::map<int,int> m;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", x+i);
        y[i] = x[i];
    }
    std::sort(y, y+n);
    for (int i = 0; i < n; i++) m[y[i]] = i;
    for (int i = 0; i < n; i++) {
        if ((i%2) != m[x[i]]%2) ans++;
    }
    assert(ans%2 == 0);
    printf("%d\n", ans/2);
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> l(n);
  for(int i=0; i<n;i++) cin >> l.at(i);
  sort(l.begin(),l.end());
  int ans =0;
  for(int i =0; i<n-2;i++){
    for(int j =1; j<n-i;j++){
      for(int k =i+j+1; k<n;k++){
        if(l.at(k) < (l.at(i) + l.at(i+j))) ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<set>
using namespace std;
int main(){
	int w,h,n,a,x,y,left=0,down=0;
	cin >> w >> h >> n;
	for(int i = 1;i <= n;i++){
		cin >> x >> y >> a;
		if(a==1&&x > left){
			left = x;
			}
		if(a==2&&w>x)w = x;
		if(a==3&&down<y)down=y;
		if(a==4&&y<h)h=y;
		}
	if(w<=left||h<=down){
		puts("0");
		return 0;
		}
	int ans = (w-left)*(h-down);
	printf("%d\n",ans);
	return 0;
	}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
d = [0 for i in range(3)]
dp = [[[0 for i in range(n+1)] for j in range(n+1)] for k in range(n+1)] 
for i in a:
    d[i-1] +=1
for k in range(n+1):
    for j in range(n+1):
        for i in range(n+1):
            if i+j+k==0 or i+j+k>n:
                continue
            ans = n/(i+j+k)
            x = i/(i+j+k)
            if x:
                ans += x*dp[k][j][i-1]
            x = j/(i+j+k)
            if x:
                ans += x*dp[k][j-1][i+1]
            x = k/(i+j+k)
            if x:
                ans += x*dp[k-1][j+1][i]
            dp[k][j][i] = ans
print(dp[d[2]][d[1]][d[0]])

Measured memory_bytes: 391132
while True:
  try:
    a,b = map(float,raw_input().split())
    if a < 35.5 and b < 60+11:
      print"AAA"
    elif a < 37.5 and b < 60+17:
      print "AA"
    elif a < 40 and b < 60+23:
      print "A"
    elif a < 43 and b < 60+29:
      print "B"
    elif a < 50 and b < 60+45:
      print "C"
    elif a < 55 and b < 60+56:
      print "D"
    elif a < 60+10 and b < 60+60+28:
      print "E"
    else:
      print "NA"
  except EOFError:
    break

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

int main(){
    string s;
    cin >> s;
    char now=s[0];
    rep(i,2){
        char next=s[i+1];
        if(now!=next){
            puts("Yes");
            return 0;
        }
        now=next;
    }
    puts("No");
    return 0;
}











Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  vector<bool> ssp(20000,false);
  for(int i=0;i*i<20000;++i)
    for(int j=i;i*i+j*j<20000;++j)
      if(i*i+j*j>1)
	for(int k=0;(i*i+j*j)*(k*k)<20000;++k)
	  for(int l=k;(i*i+j*j)*(k*k+l*l)<20000;++l)
	    if(i*i+j*j<=k*k+l*l){
	      ssp[(i*i+j*j)*(k*k+l*l)]=true;
	    }
  int n;
  cin >> n;
  REP(i,n){
    int p,q;
    cin >> p >> q;
    if(ssp[p*p+q*q]) cout << "C" << endl;
    else cout << "P" << endl;
  }
  return 0;
}

Measured memory_bytes: 2996
a, b, c, d = list(map(int, input().split()))
turn = True
while True:
  if turn:
    c -= b
    if c <= 0:
      print("Yes")
      import sys
      sys.exit()
  else:
    a -= d
    if a <= 0:
      print("No")
      import sys
      sys.exit()
  turn ^= True


Measured memory_bytes: 9136
def GCU(m,n):
    if not n:
        return m
    else:
        return GCU(n, m%n)

a,b=map(int,input().split())
l=list(map(int,input().split()))
l.append(b)
l.sort()
ll=[]
for i in range(len(l)-1):
    ll.append(l[i+1]-l[i])
ll.sort()
s=ll[0]
for i in ll:
    s=GCU(s,i)
print(s)





Measured memory_bytes: 14224
fn main() {
    proconio::input! {
    a:usize,
    }
    let mut v:Vec<usize>=Vec::new();
    v.push(2);
    v.push(1);
    for i in 0..a {
        v.push(v[i]+v[i+1]);
    }
    println!("{}",v[a])
}

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

int main() {
  string S;
  cin >> S;
  if(S == "Sunny"){
    cout << "Cloudy" <<endl;
  }
  if(S == "Cloudy"){
    cout << "Rainy" <<endl;
  }
  if(S == "Rainy"){
    cout << "Sunny" <<endl;
  }
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    n %= 1000;
    if(n==0) n=1000;
    cout<<1000-n<<endl;
}

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

int main() {
 string a;
 cin >> a;
 if( a == "Sunny"){
 	cout << "Cloudy" <<endl;
}
 else if(a =="Cloudy"){
 cout << "Rainy" <<endl;
 }
 else if(a =="Rainy"){
 cout <<"Sunny"<<endl;
 }
}


Measured memory_bytes: 256
a, b = gets.chomp.split(" ").map(&:to_i)

x = b * 10
find = false
while x / 10 == b do
  if (x * 0.08).to_i  == a
    find = true
    break
  end
  x += 1
end

if find
  print "#{x}\n"
else
  print "-1\n"
end

Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <vector>

int main() {
  int H, W, K;
  std::cin >> H >> W >> K;
  std::vector<std::string> grid(H);
  for (int i = 0; i < H; ++i) {
    std::cin >> grid[i];
  }
  int count = 0;
  for (int v = 0; v < (1 << H); ++v) {
    for (int h = 0; h < (1 << W); ++h) {
      int num = 0;
      for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
          num += ((v >> i) & 1) & ((h >> j) & 1) & (grid[i][j] == '#');
        }
      }
      count += num == K;
    }
  }
  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
  #include <algorithm>
  #include <vector>
  #include <cmath>
#include <string>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <iomanip>
  #include <stack>
  #include <queue>
  #include <deque>
  using namespace std;
   
  int main(){
      long long m,k;
      cin>>m>>k;
      if(k>=(1<<m)){
          cout<<-1;
          return 0;
      }
      if(k==0){
          for(int i=0;i<=(1<<m)-1;i++){
              cout<<i<<' '<<i<< ' ';
          }
          return 0;
      }
      int x=0;
      for(int i=0;i<=(1<<m)-1;i++){
          if(k!=i)x^=i;
      }
      if(x!=k){
          cout<<-1;
          return 0;
      }
      cout << k << ' ';
      for(int i=0;i<(1<<m);i++){
          if(i!=k)cout<<i<<' ';
      }
      cout<<k<<' ';
      for(int i=(1<<m)-1;i>=0;i--){
          if(i!=k)
          cout<<i<< ' ';
      }
      return 0;
  }


Measured memory_bytes: 1792
a = 1
b = 1
while True:
	if a != 10:
		while True:
			print(str(a) + 'x' + str(b) + '=' + str(a*b))
			b += 1
			if b != 10:
				continue
			else:
				b = 1
				a += 1
				break
		continue
	else:
		break

Measured memory_bytes: 4212