akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>

using namespace std;

int main(void){
  int o,A,B;
  
  cin>>o;
  
  if(o==1)
    cout<<"Hello World"<<endl;
  else{
     cin>>A>>B;
    cout<<A+B<<endl;
     }
return 0;
}

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


int main()
{
       int n;

       cin>>n;


       vector<int> v(n);

       for(int i=0;i<n;i++){
           cin>>v[i];
       }
       bool f=false;
       for(int i=0;i<n;i++){
          if(v[i]%2==0){

            if(!(v[i]%3==0 || v[i]%5==0)) f=true;
          }

       }

       if(f){
        cout<<"DENIED"<<endl;
       }else{
         cout<<"APPROVED"<<endl;

       }

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
const ll mod=1e9 +7;
int n,m;
ll K,xx,yy,a,s;
int mp[1010][1010];
ll aa[3][3],bb[3][3],ss[3][3];
bool bx,by;
ll power(ll x,ll k)
{
	ll sss=1;
	while (k)
	{
		if (k%2) sss=sss*x%mod;
		x=x*x%mod;
		k/=2;
	}
	return sss;
}
void init()
{
	aa[1][1]=ss[1][1]=s;
	aa[1][2]=ss[1][2]=1;
	aa[2][1]=ss[2][1]=0;
	aa[2][2]=ss[2][2]=a;
}
void square_mul()
{
//	printf("mul\n");
	for (int i=1;i<=2;++i)
		for (int j=1;j<=2;++j)
		{
			bb[i][j]=0;
			for (int k=1;k<=2;++k)
				bb[i][j]=(bb[i][j]+aa[i][k]*ss[k][j]%mod)%mod;
		}
	for (int i=1;i<=2;++i)
		for (int j=1;j<=2;++j)
		ss[i][j]=bb[i][j];
}
void square_self()
{
//	printf("self\n");
	for (int i=1;i<=2;++i)
		for (int j=1;j<=2;++j)
		{
			bb[i][j]=0;
			for (int k=1;k<=2;++k)
				bb[i][j]=(bb[i][j]+aa[i][k]*aa[k][j]%mod)%mod;
		}
	for (int i=1;i<=2;++i)
		for (int j=1;j<=2;++j)
		aa[i][j]=bb[i][j];
}
void square_power(ll k)
{
	--k;
	while (k)
	{
//		printf("k:%lld\n",k);
		if (k%2) square_mul();
		square_self();
		k/=2;
	}
}
int main()
{
//	freopen("F.in","r",stdin);
//	freopen("F.out","w",stdout);
	scanf("%d%d%lld",&n,&m,&K);
	char ch[1010];
	for (int i=1;i<=n;++i)
	{
		scanf("%s",ch+1);
		for (int j=1;j<=m;++j)
			if (ch[j]=='#') 
				mp[i][j]=1,++s;
	}
	for (int i=1;i<=n;++i)
		if (mp[i][1]&&mp[i][m])
			++a,bx=1;
	for (int i=1;i<=m;++i)
		if (mp[1][i]&&mp[n][i])
			++a,by=1;
	if ((bx==1 && by==1) || K==1)
	{
		printf("1\n");
		return 0;
	}
	if (bx==0 && by==0)
	{
		printf("%lld\n",power(s,K-1));
		return 0;
	}
	if (by==1)
	{
		int mmp[1010][1010];
		swap(mmp,mp);
		swap(n,m);
		for (int i=1;i<=n;++i)
			for (int j=1;j<=m;++j)
				mp[i][j]=mmp[j][i];
	}
	
//	printf("s:%lld\n",s);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
			if (mp[i][j]==1&&mp[i][j+1]==1)
				++xx;
//	printf("xx:%lld\n",xx);
	yy=xx*a;
	if (K==2)
	{
		printf("%lld\n",s-xx);
		return 0;
	}
	init();
	square_power(K-2);
	xx=(xx*ss[1][1]%mod+yy*ss[1][2]%mod)%mod;


//	printf("a");	
//	printf("%lld-%lld\n",power(s,K-1),xx);
	printf("%lld\n",( (power(s,K-1)-xx)%mod + mod)%mod);
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
//bool map[300002][300002];
int mapp[300002][2];
int x[300002];
int y[300002];
bool xm[300002];
bool ym[300002];
int main(){
	int h,w,m;
	int x1,y1;
	int p,q,p1,q1;
	scanf("%d%d",&h,&w);
	scanf("%d",&m);
	for(int i=1;i<=300002;i++){
		x[i]=0;y[i]=0;xm[i]=0;ym[i]=0;
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x1,&y1);
		mapp[i][0]=x1;
		mapp[i][1]=y1;
		x[x1]++;
		y[y1]++;
	}
	p=x[1];p1=1;
	for(int i=2;i<=h;i++){
		if(x[i]>p){p=x[i];p1=i;}
	}
	q=y[1];q1=1;
	for(int i=2;i<=w;i++){
		if(y[i]>q){	q=y[i];q1=i;}
	}
	int al1=0,al2=0;
	for(int i=1;i<=h;i++){
		if(x[i]==p){
			xm[i]=1;al1++;
		}
	}
	for(int i=1;i<=w;i++){
		if(y[i]==q)	{
			ym[i]=1;al2++;
		}
	}
	int ans=0,count=0;
	int t1,t2;
	for(int i=1;i<=m;i++){
		t1=mapp[i][0];	t2=mapp[i][1];
		if(xm[t1]==1&&ym[t2]==1){
			count++;
		}
	}
	long long tmp;
	tmp=al1*al2;
	if(count==tmp){
		ans=p+q-1;
	}else{
		ans=p+q;
	}
	printf("%d",ans);
}

Measured memory_bytes: 9104
// finish date: 2019/07/20

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    vi A(N);
    int ma = 0, ma2 = 0;
    map<int, int> cnt;
    rep(i, N) {
        cin >> A[i];
        if (A[i] > ma) {
            ma2 = ma;
            ma = A[i];
        } else if (A[i] > ma2) {
            ma2 = A[i];
        }
        cnt[A[i]]++;
    }
    rep(i, N) {
        if (A[i] != ma) {
            cout << ma << endl;
        } else {
            if (cnt[A[i]] > 1) cout << A[i] << endl;
            else cout << ma2 << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 7936
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;


int main(){
    ll n,m;
    cin>>n>>m;
    vector<int>v(n,1);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a]=1-v[a];
        v[b]=1-v[b];
    }
    for(int x:v){
        if(!x){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
    }


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;



int main() {
    ll a, b, k; cin >> a >> b >> k;
    vector<ll> ans;
    for(ll i = a;i < min(b,a + k); i++){
        ans.pb(i);
    }
    for(ll i = max(a,b-k+1); i <= b; i++){
        ans.pb(i);
    }
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int n; std::cin >> n;
    std::vector<int> h(n);
    for(int i=0; i<n; i++){
        std::cin >> h[i];
    }

    int ans = 0, cnt = 0;
    for(int i=0; i<n-1; i++){
        if(h[i]>=h[i+1]){
            cnt++;
        }else{
            ans = std::max(cnt,ans);
            cnt = 0;
        }
    }
    ans = std::max(cnt, ans);

    std::cout << ans << "\n";
    return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define Min(...) min({__VA_ARGS__})
#define Max(...) max({__VA_ARGS__})
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
static inline ll sgn(ll x) { return (x>0)-(x<0); }
static inline bool vowel(char c) { c = (char)tolower(c); return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u' or c == 'y'; }
static inline vi rvi(int N) { vi res(N); rep(i,0,N) cin >> res[i]; return res; }
static inline int ri() { int N; cin >> N; return N; }
static inline void pvi(const vi& r) { trav(it,r) cout << it << " "; cout << endl; }
template<class S, class T> static inline void smax(S& s, const T& t) { if (t > s) s = t; }
template<class S, class T> static inline void smin(S& s, const T& t) { if (t < s) s = t; }
template<class S> static inline void in(S& s) { cin >> s; }
template<class S> static inline void ut(const S& s) { cout << s << " "; }
static inline void nl() { cout << endl; }

signed main() {
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int ans = 0;
	for (int i = 0; i <= 200; ++i) {
		if (i >= A && i >= C && i < B && i < D) ++ans;
	}
	cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  
  int i;
  vector<int> x;
  for(i = 0; i < s.size(); i++){
    if(s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T') x.push_back(1);
    else x.push_back(0);
  }
  
  for(i = 1; i < x.size(); i++){
    x.at(i) = (x.at(i - 1) + 1) * x.at(i);
  }
  
  sort(x.begin(), x.end());
  
  cout << x.at(x.size() - 1) << endl;
}

Measured memory_bytes: 256
def B(lst,r=[],c=1):
    if len(lst) == c:
        return r
    if len([i for i in lst[0:c] if lst[c] >= i]) == c:
        return B(lst,r + [lst[c]],c+1)
    else:
        return B(lst,r,c+1)

i = int(input())
lst = list(map(int,input().split(" ")))
print(len(B(lst))+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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; }

int main() {
  char a;
  cin >> a;
  if (isupper(a)) cout << 'A' << endl;
  else cout << 'a' << endl;

  return 0;
}

Measured memory_bytes: 3600
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}
/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		ll a,b,d;
		cin>>n;
		map<string,ll> mp;
		rep(i,n)
		{
			cin>>s;
			c+=(mp[s]==0);
			mp[s]++;
		}
		// n=s.length();
		// ll a[n];
		cout<<c;

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 19288
/*
  ALDS1_4-A
  ??¶?´?
  n \leq 10,000
  q \leq 500
  0 \leq S???????´? \leq 10^9
  0 \leq T???????´? \leq 10^9
  T ???????´???????????????°??????
*/
import java.io.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] str) throws java.io.IOException {
	final int  s_maxsize = 10000;
	final int  q_maxsize=10000;

	String buf;
	int[] s = new int[s_maxsize];
	int[] t = new int[q_maxsize];
	int ans = 0;

	Scanner scan = new Scanner(System.in);

	int n = scan.nextInt();
	for (int i=0; i<n; i++) {
	    s[i] = scan.nextInt();
	}
	
	int q = scan.nextInt();
	for (int i=0; i<q; i++) {
	    t[i] = scan.nextInt();
	}

	for (int i=0; i<q; i++){
	    for (int j=0; j<n; j++){
		if (s[j] == t[i]){
		    ans+=1;
		    break;
		}
	    }
	}

	System.out.println(ans);

    }
}

Measured memory_bytes: 40468
from heapq import heappush, heappop
N, K , *P = map(int, open(0).read().split())
mhq = []
Mhq = []
for c in P[:K]:
  heappush(mhq,c)
  heappush(Mhq,-c)

ans = 1
log = set()
for i,c in enumerate(P[K:]):
  while mhq[0] in log:
    heappop(mhq)
  while -Mhq[0] in log:
    heappop(Mhq)
  d = P[i]
  m = mhq[0]
  M = -Mhq[0]
  log.add(d)
  heappush(mhq,c)
  heappush(Mhq,-c)
  if not (m==d and M<c):
    ans += 1
p = P[0]
m = 1
x = 0
for c in P[1:]:
  if p<c:
    m += 1
  else:
    if m>=K:
      x += 1
    m = 1
  p = c
if m>=K:
  x += 1
if x!=0:
  ans -= x-1
print(ans)

Measured memory_bytes: 118460
#include<stdio.h>
int main(void){
   int n, a, v, max, max_num;
   max = max_num = 0;
   scanf("%d", &n);
   while ( n != 0 ) {
      scanf("%d %d", &a, &v);
      if ( max < v ) {
         max = v;
         max_num = a;
      } else if ( max == v ) { 
         if ( max_num > a ) max_num = a;
         if ( max_num == 0 ) max_num = a;
      }
      n--;
   }
   printf("%d %d\n", max_num, max);
   return 0;
}

Measured memory_bytes: 1860
let () =
  let f (m,e,j) =
    if m = 100 || e = 100 || j = 100 then "A"
    else if (m+e)/2 >= 90 then "A"
    else if (m+e+j)/3 >= 80 then "A"
    else if (m+e+j)/3 >= 70 then "B"
    else if (m+e+j)/3 >= 50 && (m >= 80 || e >= 80) then "B"
    else "C"
  in
  let rec read () =
    let n = Scanf.scanf "%d\n" (fun x -> x) in
    if n = 0 then ()
    else
      begin
        let rec loop = function
            0 -> ()
          | i ->
             let score = Scanf.scanf " %d %d %d\n" (fun x y z->(x,y,z)) in
             Printf.printf "%s\n" (f score);
             loop (i-1)
        in loop n; read ()
      end
  in read ()
;;

Measured memory_bytes: 4092
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def main():
    x = int(input())
    ans = 0
    ans += (x // 500) * 1000
    ans += ((x % 500) // 5) * 5
    print(ans) 


if __name__ == '__main__':
    main()

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

int main() {
  string s;
  cin >> s;
  int64_t n = s.size();
  int64_t ans = 0, white = 0;
  for (int64_t i = 0; i < n; i++) {
    if (s[i] == 'W') {
      ans += i - white++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(void) {
	int N, Y		;
	cin >> N >> Y;
	for (int m = 0; m <= N; m++) {
		for (int g = 0; g <= (N-m); g++) {
			int s = N - m - g;
			if (m*10000+g*5000+s*1000 == Y) {
				cout << m << " " << g << " " << s << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    from collections import defaultdict
    dd = defaultdict(int)
    
    for i in range(N):
        dd[A[i]]+=1
        
    L=[0,0]
    for k,v in dd.items():
        if v>=2:
            L.append(k)
        if v>=4:
            L.append(k)
            
        
    L.sort()
    print(L[-1]*L[-2])

main()



Measured memory_bytes: 65176
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){return powm(a,m-2,m);}int main()
{
fastIO
ll n,m,i,j,k,x,y,z,t,e,f,p,q,g,l,r,o,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,y1,y2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s,s1,s2;
cin>>x;
if(x==0)
{
  cout<<"1";
}
else
{
  cout<<"0";
}
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;


int main() {
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i+=2){
        int cnt=0;
        for(int j=1;j<=n;j+=2){
            if(i%j==0)cnt++;
        }
        if(cnt==8)ans++;
    }
    cout<<ans<<endl;








    return 0;
}


Measured memory_bytes: 256
//
//  main.swift
//  AtCoderSwift
//
//  Created by burita083 on 2020/08/25.
//  Copyright © 2020 burita083. All rights reserved.
//

import Foundation
func readInt() -> Int {
    return Int(readLine()!)!
}
 
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
 
func readTwoInts() -> (a: Int, b: Int) {
    let ints = readLine()!.split(separator: " ").map { Int($0)! }
    return (a: ints[0], b: ints[1])
}

func abc080_b() {
    let N = readLine()!
    let sum = N.map { Int(String($0))! }.reduce(0, +)
    print(Int(N)! % sum == 0 ? "Yes" : "No")
}

//abc080_b()

func abc078_b() {
    let input = readInts()
    var X = input[0]
    let Y = input[1]
    let Z = input[2]
    var ans = 0
    X -= Y+Z*2
    ans += 1
    ans += X/(Y+Z)
    
    print(ans)
}

func abc085_b() {
    let N = readInt()
    var l: [Int] = []
    for _ in 0..<N {
        let d = readInt()
        l.append(d)
    }
    print(l.reduce([], { $0.contains($1) ? $0 : $0 + [$1] }).count)
}

abc085_b()



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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x,y;
    cin >> n >> x >> y;
    int ans[n-1] = {};
    x--;y--;

    int c;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++){
        c = min(min(abs(i-j),abs(i-x)+abs(j-y)+1),abs(i-y)+abs(j-x)+1);
        if (c > 0) ans[c-1]++;
    }
    for (int ai:ans) cout << ai/2 << "\n";
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;
const int N = 105;
int a[N];
int n, b;

int main() {
    cin >> n;
    int sum = 0;
    memset(a, 0x3f, sizeof a);
    for (int i = 0; i < n - 1; ++i) {
        cin >> b;
        a[i] = min(a[i], b);
        a[i + 1] = min(a[i + 1], b);
        sum += a[i];
    }
    sum += a[n - 1];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3648
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

int N,M,Q;
vector<int> vec;
ll maxim=0;
vector<int> a(50+2,0),b(50+2,0),c(50+2,0),d(50+2,0);

void search(){
    ll sum=0;
    for (int i = 1; i <= Q; ++i) {
        if(vec[b[i]]-vec[a[i]]==c[i]) sum += d[i];
    }

    maxim = max(maxim,sum);

    // デバッグ用出力
    /*
    for (int i = 1; i <= N; ++i) {
        cout<<vec[i]<<" ";
    }
    cout<<endl;
    */
}

void dfs(){

    if(vec.size()>N){
        search();
        return;
    }
    // vecの末尾の数字より1大きいものからMまで
    for (int i = vec.back(); i <= M; ++i) {
        vec.push_back(i);
        dfs();
        vec.pop_back();
    }

}


int main(void){

    cin>>N>>M>>Q;

    for (int i = 1; i <= Q; ++i) {
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    // 0を入れておく
    vec.push_back(1);
    dfs();

    // 答え
    cout<<maxim<<endl;

}


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

using namespace std;

typedef long long ll;

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

	int k;
	cin >> k;

	cout << k / 2 * ((k + 1) / 2) << endl; 
}


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

int main(){
	using ll = long long;
	ll n, a, b;
	cin >> n >> a >> b;
	ll h[n];
	for(int i = 0; i < n; i++) cin >> h[i];
	ll l = 0, r = 1e9;
	while(1 < r - l){
		ll mid = (l + r) / 2, cnt = 0;
		for(int i = 0; i < n; i++) if(0 < h[i] - b * mid) cnt += (h[i] - b * mid + (a - b) - 1) / (a - b);
		(cnt <= mid ? r : l) = mid;
	}
	cout << r << endl;
}

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

int main()
{
	int X, Y;
	cin >> X >> Y;
	for (int i = 0; i <= X; i++)
	{
		if (2 * i + (X - i) * 4 == Y) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3600
program main;
var
    a, b, x, y, legs : integer;
begin
    readln(x, y);
    a := 0;
    b := x;
    while a <= x do begin
        legs := a*2 + b*4;
        if legs = y 
            then begin
                writeln('Yes');
                halt;
            end
            else begin
                a := a + 1;
                b := b - 1;
            end;
    end;
    if a > x 
        then writeln('No');
end.


Measured memory_bytes: 1384
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    L, R = 0, max(a)
    while L+1 < R:
        P = (L+R+1)//2
        tmp = 0
        for v in a:
            if P < v:
                if v % P == 0:
                    tmp += v//P - 1
                else:
                    tmp += v//P
        if tmp <= k:
            R = P
        else:
            L = P
    print(R)

if __name__ == "__main__":
    main()

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

struct UFweight{
    public:
        UFweight(int n, ll sum_unity = 0): _n(n), parent_or_size(n, -1), rank(n, 0), diff_weight(n, sum_unity){}

        // weight(b) - weight(a) = wとなるようにmerge
        bool merge(int a, int b, ll w){
            w += weight(a); w -= weight(b);
            int x = root(a), y = root(b);
            if(x == y){
                ll weight_diff = get_diff(x, y);
                return weight_diff == w;
            }

            if(rank[x] < rank[y]){
                swap(x, y);
                w *= -1;
            }
            if(rank[x] == rank[y]) ++rank[x];
            diff_weight[y] = w;
            parent_or_size[x] += parent_or_size[y];
            parent_or_size[y] = x;

            return true;
        }

        bool same(int a, int b){
            return root(a) == root(b);
        }

        int root(int a){
            if(parent_or_size[a] < 0) return a;
            else{
                int r = root(parent_or_size[a]);
                diff_weight[a] += diff_weight[parent_or_size[a]];
                return parent_or_size[a] = r;
            }
        }

        int get_size(int a){
            return -parent_or_size[root(a)];
        }

        ll weight(int a){
            root(a);
            return diff_weight[a];
        }

        ll get_diff(int a, int b){
            return weight(b) - weight(a);
        }
        
    private:
        int _n;
        //root node: -1*component size
        //otherwise: parent
        vector<int> parent_or_size;
        vector<int> rank;
        vector<ll> diff_weight;
};

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    UFweight ufw(n);
    for(i = 0;i < m;++i){
        ll l,r,d;
        cin >> l >> r >> d;
        --l;    --r;
        bool flag = ufw.merge(l,r,d);
        if(!flag){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
#define maxn 100
using namespace std;
int main() {
	// your code goes here
	int K,X;
	cin>>K>>X;
	
	set<int>S;	
	
	int i;
	
	S.insert(X);
	for(i=1;i<K;i++) S.insert(X-i);
	for(i=1;i<K;i++) S.insert(X+i);
	
	set<int>:: iterator it;
	for(it=S.begin(); it!=S.end();it++) printf("%d ", *it);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int x, y, z;
    cin >> x >> y >> z;

    int ans = (x - z) / (y + z);
    cout << ans << endl;

    return 0;
}


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

using namespace std;

#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 REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N;

int main() {
    cin >> N;
    while(1) {
        if(N % 111 == 0) {
            cout << N << "\n";
            return 0;
        }
        N++;
    }
}

Measured memory_bytes: 256
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    string s;
    int[] bits;

    bool input() {
        s = readln.chomp;
        if (s == "END") return false;
        bits.clear;
        int N; scanf("%d\n", &N);
        foreach (i; 0 .. N) {
            int bit = 0;
            foreach (j; 0 .. 4) {
                int x; scanf("%d", &x);
                bit |= (x << j);
            }
            scanf("\n");
            bits ~= bit;
        }
        return true;
    }

    class Node {
        Node left, right;
        int bit;
        this(Node left, Node right) {
            this.left = left;
            this.right = right;
        }
        this(int bit) {
            this.bit = bit;
            this.left = null;
            this.right = null;
        }
        bool leaf() {
            return left is null && right is null;
        }
    }
    Node parse() {
        int index = 0;
        //writeln(s);
        Node dfs() {
            if (s[index] == '(') {
                index++;
                Node left = dfs;
                assert(s[index] == ' ');
                index++;
                Node right = dfs;
                assert(s[index] == ')');
                index++;
                return new Node(left, right);
            } else if (isDigit(s[index])) {
                int bit_i = s[index] - '1';
                index++;
                return new Node(bits[bit_i]);
            } else {
                assert(0);
            }
        }
        return dfs;
    }

    void solve() {
        Node root = parse;
        const zs = "AOX";
        int[] dfs(Node node) {
            if (node.leaf) return [node.bit];
            int[] ret;
            int[] left = dfs(node.left),
                  right = dfs(node.right);
            foreach (a; left) {
                foreach (b; right) {
                    foreach (z; zs) {
                        if (z == 'A') {
                            ret ~= a & b;
                        } else if (z == 'O') {
                            ret ~= a | b;
                        } else if (z == 'X') {
                            ret ~= a ^ b;
                        } else {
                            assert(0);
                        }
                    }
                }
            }
            return ret;
        }
        writeln(dfs(root).count(15));
    }

    while (input) solve;
}

Measured memory_bytes: 1504
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int k = 1000;

bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b)
{
	if (a.first.first / k < b.first.first / k)
		return true;
	if (a.first.first / k == b.first.first / k && a.first.second < b.first.second)
		return true;
	return false;
}

int cnt[500001];
int a[500001];
int ans[500001];
int answ = 0;

void add(int i)
{
	if (cnt[a[i]] == 0)
	{
		++answ;
	}
	cnt[a[i]]++;
}

void del(int i)
{
	if (cnt[a[i]] == 1)
	{
		--answ;
	}
	cnt[a[i]]--;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, q;
	cin >> n >> q;
	vector<int> f;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		f.push_back(a[i]);
	}
	sort(f.begin(), f.end());
	f.resize(unique(f.begin(), f.end()) - f.begin());
	unordered_map<int, int> d;
	for (int i = 0; i < f.size(); ++i)
	{
		d[f[i]] = i;
	}
	for (int i = 0; i < n; ++i)
	{
		a[i] = d[a[i]];
	}
	vector<pair<pair<int, int>, int>> qq;
	for (int i = 0; i < q; ++i)
	{
		int l, r;
		cin >> l >> r;
		--l; --r;
		qq.push_back(make_pair(make_pair(l, r), i));
	}
	sort(qq.begin(), qq.end(), cmp);
	int L = 0, R = -1;
	for (int i = 0; i < q; ++i)
	{
		int l = qq[i].first.first;
		int r = qq[i].first.second;
		while (L > l) add(--L);
		while (R < r) add(++R);
		while (L < l) del(L++);
		while (R > r) del(R--);
		//cout << R  << " RR " << answ << endl;
		//cout << L << " LL " << answ << endl;
		ans[qq[i].second] = answ;
	}
	for (int i = 0; i < q; ++i)
	{
		cout << ans[i] << '\n';
	}
}

Measured memory_bytes: 40280
#include <iostream>
#include <string>
int main() {
  
  std::string a, b;
  std::cin >> a >> b;
  int n = std::stoi(a + b);
  for (int i = 317; --i;) if (i * i == n) {
    std::cout << "Yes" << std::endl;
    return 0;
  }
  std::cout << "No" << std::endl;
  
}


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

int K;
unsigned long long sum = 0;

int main() {
	scanf("%d", &K);
	for(int i=1; i<=K; i++) {
		for(int j=1; j<=K; j++) {
			for(int k=1; k<=K; k++) {
				sum += std::__gcd(std::__gcd(i, j), k);
			}
		}
	}
	printf("%llu", sum);
	return 0;
}


Measured memory_bytes: 1732
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n = ii()
    ans = list(range(100005))
    flag = [0 for i in range(100005)]
    flag[0] = 1
    flag[1] = 1
    for ind in range(100005):
        if flag[ind] == 1:
            continue
        tmp = ind
        
        while tmp+ind < 100005:
            tmp+=ind
            flag[tmp] = 1

        
    


    for i in range(100005):
        if flag[n+i] == 0:
            print(n+i)
            exit()

    



    


    
main()


Measured memory_bytes: 7880
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}


/* math_method */
int ceil(int a, int b){return a / b + (a % b > 0);}


/* main */

int n, m;
void in(){
    cin >> n >> m;
}

void solve(){

    int l = 1, r = n;
    rep(i,0,m){
        int a, b;
        cin >> a >> b;

        l = max(l, a);
        r = min(r, b);

        if(l > r){
            print(0);
            exit(0);
        }

    }

    

    print(r - l + 1);

}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    long long n;
    cin >> n;
    long long x, y;
    long long ans = n-1;
    for(long long i=2; i<n; i++){
        if(n % i == 0){
            x = i;
            y = n/i;
            ans = min(ans, (x-1)+(y-1));
        }
        if(i > 1000000){
            break;
        }
    }
    cout << ans;
 
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <atcoder/all>
//g++ main.cpp -std=c++14

using namespace std;
using namespace atcoder;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw`(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;
template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}
const ll MAX = MOD;

void solve(){
  int N,Q; cin>>N>>Q;
  dsu d(N);
  REP(i,Q){
    int t,u,v; cin>>t>>u>>v;
    if(t==0){
      d.merge(u,v);
    }else{
      cout << d.same(u,v) << "\n";
    }
  }
}

int main(int argc, char *argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG = 1;}
  solve();
  return 0;
}

Measured memory_bytes: 3988
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC050a
{
	class Program
	{
		static void Main(string[] args)
		{
			int A,B,z=0;
			string op;
            var word = Console.ReadLine().Split(' ');
			A = int.Parse(word[0]);
			op = word[1];
			B = int.Parse(word[2]);
			if (op == "+" )
				z = A + B;
			else if (op == "-" ) 
				z = A - B;
			Console.WriteLine(z);
			Console.ReadKey();
			
		}
	}
}


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

vector<int> poloc;
vector<int> poloc_odd;

void make_poloc()
{
	int n=1;
	while(1){
		int a = n*(n+1)*(n+2)/6;
		if(a > 1000000)
			break;
		
		poloc.push_back(a);
		if(a % 2 == 1)
			poloc_odd.push_back(a); 
		n++;
	}
}
/*
int search1(int n, int i, int depth)
{
	if(n == 0)
		return depth;
	else if(n < 0 || i < 0)
		return 1000000;
	else
		return min( min(search1(n-poloc[i],i-1,depth+1), search1(n,i-1,depth)), search1(n-poloc[i],i,depth+1));
}
int search2(int n, int i, int depth)
{
	if(n == 0)
		return depth;
	else if(n < 0 || i < 0)
		return 1000000;
	else
		//return min( min(search2(n-poloc_odd[i],i-1,depth+1), search2(n,i-1,depth)), search2(n-poloc_odd[i],i,depth+1));
		return min(search2(n-poloc_odd[i],i-1,depth+1), search2(n,i-1,depth));
}
*/

int main()
{
	make_poloc();
	int n;
	int dp[1000001];
	for(int i=0;i<=1000000;i++){
		dp[i] = 1000000;
	}
	dp[0] = 0;
	for(int i=0;i<poloc.size();i++){
		for(int j=0;j<=1000000;j++){
				if(j+poloc[i] <= 1000000)
					dp[j+poloc[i]] = min(dp[j+poloc[i]],dp[j]+1);
			
		}
	}
	int dpp[1000001] = {0};
	for(int i=0;i<=1000000;i++){
		dpp[i] = 1000000;
	}
	dpp[0] = 0;
	for(int i=0;i<poloc_odd.size();i++){
		for(int j=0;j<=1000000;j++){
				if(j+poloc_odd[i] <= 1000000)
					dpp[j+poloc_odd[i]] = min(dpp[j+poloc_odd[i]],dpp[j]+1);
		}
	}

	while(cin >> n){
		if(n==0)
			break;
		cout << dp[n] << " " << dpp[n] << endl;
	}

	return 0;
	
}

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

bool check(vector<int>& v, int k, int p) {
  vector<int> t(k);
  int i = 0;
  for (auto& w : v) {
    if (t[i] + w <= p) {
      t[i] += w;
    } else if (i + 1 < k && t[i + 1] + w <= p) {
      t[++i] += w;
    } else {
      return false;
    }
  }
  return true;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, k, sum = 0;
  cin >> n >> k;
  vector<int> v(n);
  for (auto& e : v) {
    cin >> e;
    sum += e;
  }
  int ng = 0;
  int ok = sum;
  while (ng < ok) {
    int mid = (ng + ok) / 2;
    if (check(v, k, mid)) {
      ok = mid;
    } else {
      ng = mid + 1;
    }
  }
  cout << ok << "\n";
}


Measured memory_bytes: 3568
import java.lang.Math.ceil

fun main(args: Array<String>) {
    var foodsTimes = listOf(
        readLine()!!.toInt(),
        readLine()!!.toInt(),
        readLine()!!.toInt(),
        readLine()!!.toInt(),
        readLine()!!.toInt()
    ).sortedByDescending {(it-1) % 10 }

    var sum = 0
    for(fTime in foodsTimes){
        sum += ceil(fTime.toDouble()/10).toInt()*10
    }
    println(sum - ceil(foodsTimes.get(4).toDouble()/10).toInt()*10 + foodsTimes.get(4))
}

Measured memory_bytes: 34056
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = 0, n = sc.nextInt(), max = 0;
		String s = sc.next();
		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == 'I') {
				x++;
			} else if (s.charAt(i) == 'D') {
				x--;
			}
			if (max < x) {
				max = x;
			}
		}
		System.out.println(max);
	}

}

Measured memory_bytes: 21716
using System;
using System.Collections.Generic;

namespace atcoder
{
    class Program
    { 
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            double L = double.Parse(s);
            double n = L / 3;
            double total = n * n * n;
            Console.WriteLine(total);
           
        } 
    }
}


Measured memory_bytes: 11092
use std::io::*;
use std::str::FromStr;

const MOD: usize = 1e9 as usize + 7;

fn main() {
	let (n, k): (usize, usize) = (read(), read());
	let mut sum: usize = 0;
	for i in k..n+2 {
		sum += ans(n, i);
		sum %= MOD;
	}
	println!("{}", sum);
}

fn ans(n: usize, k: usize) -> usize {
	(n+1-k)*k+1
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 2080
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
/**************************************************************************/
const int N = 402;
int dp[N][N];
int n;
int a[N];
int pre[N];
int sum(int l,int r)
{
    if(l>r)
        return 0;
    return pre[r]-pre[l-1];
}
int solve(int i,int j)
{
    if(i>=j) 
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    dp[i][j] = 1e18;
    for(int k=i;k<=j;k++)
    {
       int cans = solve(i,k)+solve(k+1,j)+sum(i,k)+sum(k+1,j);
       dp[i][j]= min(dp[i][j],cans);
    }
    return dp[i][j];
}
signed main()
{
    fast;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        pre[i] = pre[i-1]+a[i];
    memset(dp,-1,sizeof(dp));
    cout<<solve(1,n);
}


Measured memory_bytes: 1536
ans = []
def search(s,c):
    if c == "a":
        ans.append(s)
        return

    for i in xrange(len(s)):
        if s[i] == c: return
    
        if s[i] == chr(ord(c)-1):
            t = list(s[:])
            t[i] = c
            t = "".join(t)
            
            search(t, chr(ord(c)-1))
    search(s, chr(ord(c)-1))
            
while 1:
    S = raw_input()
    if S == "#": break

    ans = []
    search(S,"z")
    
    ans = sorted(list(set(ans)))
    print len(ans)
    if len(ans) <= 10:
        for a in ans:
            print a
    else:
        for i in xrange(5):
            print ans[i]
        for i in xrange(5):
            print ans[len(ans)-5+i]

Measured memory_bytes: 6340