akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        if((c - a - b) > 0 && (c - a - b) * (c - a - b) > (4 * a * b)){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
	}
}

Measured memory_bytes: 35896
n, y = map(int,input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 2940
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# Union-Find木
class UnionFind:
    def __init__(self, n):
        self.n = n
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)
        # あるノードを根とする集合に属するノード数
        self.size = [1] * (n+1)
        # あるノードを根とする集合が木かどうか
        self.tree = [True] * (n+1)

    # 根の検索(グループ番号と言えなくもない)
    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # 木かどうかの判定用
        if x == y:
            self.tree[x] = False
            return
        if not self.tree[x] or not self.tree[y]:
            self.tree[x] = self.tree[y] = False

        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # あるノードの属する集合のノード数
    def get_size(self, x):
        return self.size[self.find(x)]

    # 木かどうかの判定
    def is_tree(self, x):
        return self.tree[self.find(x)]
    
    # 集合の数
    def len(self):
        res = set()
        for i in range(self.n+1):
            res.add(self.find(i))
        # グループ0の分を引いて返却
        return len(res) - 1


N,M=MAP()

# 言語毎の連結リストに各人を頂点として入れる
lang=[[] for i in range(M+1)]
for i in range(N):
    for j in LIST()[1:]:
        lang[j].append(i+1)

uf=UnionFind(N)
for i in range(1, M+1):
    for j in range(1, len(lang[i])):
        # 同じ言語で話せる人達を同じ集合に入れていく
        a,b=lang[i][j-1],lang[i][j]
        if not uf.same(a, b):
            uf.union(a, b)

# 最終的に全員が1つの集合に入っていればOK
if uf.len()==1:
    YES()
else:
    NO()


Measured memory_bytes: 20688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll c[10];
int main() {
	ll n1,n2,n3,n4;
	cin>>n1>>n2>>n3>>n4;
	c[n1]++;c[n2]++;c[n3]++;c[n4]++;
	cout<<((c[1]&&c[9]&&c[7]&&c[4])?"YES":"NO")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define int long long
using namespace std;
const int MAX_N=100,MAX_W=100000;
int N,W;
vector<int> w,v;
int memo[MAX_N+1][MAX_W+1];
int dfs(int i,int weight){
    if(weight>W) return -INT_MAX;
    if(memo[i][weight]!=0) return memo[i][weight];
    if(i==N) return 0;
    int ret=0;
    ret=max(dfs(i+1,weight+w[i])+v[i],dfs(i+1,weight));
    return memo[i][weight]=ret;
}

signed main(){
    cin>>N>>W;
    w.resize(N);v.resize(N);
    REP(i,N) cin>>w[i]>>v[i];
    cout<<dfs(0,0)<<endl;
}

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

int main (){
  int n;
  cin>>n;
  vector<long long>a(3*n);
  rep(i,3*n)cin>>a[i];
  sort(a.begin(),a.end(),greater<int>());//降順にソート
  
  long long ans=0;
  
  for(int i=1;i<2*n;i+=2)ans+=a[i];
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 5636
#include<iostream>
#include<cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FOF(i,a,b) for(int i=a;i< b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=25025,M=440,P=1e9+7;
int n,m,K,L,R,S,yes,ans,a[N],c[M],fc[M];
int f[N][M],g[N][M],s[N][M],t[N][M];
int qpw(int x,int y){int z=1;for(;y;y>>=1,x=1ll*x*x%P)if(y&1) z=1ll*z*x%P;return z;}
void DP(int o){
	FOR(i,1,n)FOR(j,1,S){
		f[i][j]=((s[i-1][S]-s[i-1][j-1]+P)%P+1ll*f[i-1][j-1]*(K-j+1)%P)%P;
		g[i][j]=((t[i-1][S]-t[i-1][j-1]+P)%P+1ll*g[i-1][j-1]*(K-j+1)%P)%P;
		if(!o&& j>=m) (g[i][j]+=f[i][j])%=P;
		if(o && i==L && j==L) f[i][j]=1;
		if(o && i==R && j==R) g[i][j]=1;
		s[i][j]=(s[i][j-1]+f[i][j])%P;
		t[i][j]=(t[i][j-1]+g[i][j])%P;
	}
}
void work1(){
	f[0][0]=1;
	FOR(j,0,K) s[0][j]=1;
	DP(0);
	FOR(j,1,S) (ans+=g[n][j])%=P;
	ans=1ll*ans*fc[K-m]%P*qpw(fc[K],P-2)%P;
}
void work2(){
	FOR(i,1,K) c[i]=0;
	FOR(i,1,m)if(++c[a[i]]>1){L=i-1;break;}
	FOR(i,1,K) c[i]=0;
	ROF(i,m,1)if(++c[a[i]]>1){R=m-i;break;}
	//cout<<L<<' '<<R<<'\n';
	DP(1);
	FOR(i,0,n-m) (ans+=1ll*s[i+L][S]*t[n-m-i+R][S]%P)%=P;
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d%d",&n,&K,&m);S=K-1;
	FOR(i,1,m) scanf("%d",&a[i]);
	FOR(i,0,n-K){
		FOR(j,1,K) c[j]=0;yes=1;
		FOR(j,1,K) ++c[a[i+j]];
		FOR(j,1,K) yes&=c[j]==1;
		if(yes) return cout<<1ll*qpw(K,n-m)*(n-m+1)%P<<'\n',0;
	}
	FOR(i,1,K) c[i]=0;yes=1;
	FOR(i,1,m) c[a[i]]++;
	FOR(i,1,K) yes&=c[i]<=1;
	fc[0]=1; 
	FOR(i,1,K) fc[i]=1ll*fc[i-1]*i%P;
	yes?work1():work2();
	cout<<(1ll*qpw(K,n-m)*(n-m+1)%P-ans+P)%P<<'\n';
}

Measured memory_bytes: 172416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    int ans=mod;
    vector<int> now;
    rep(i,(n+1)/2)now.pb(0);
    rep(i,n/2)now.pb(1);
    do{
        vector<pii> ev;
        vector<pii> od;
        rep(i,n){
            if(i%2){
                //元の位置が奇数
                if(now[i]%2)od.pb(mp(a[i],i));
                else ev.pb(mp(b[i],i));
            }
            else{
                if(now[i]%2)od.pb(mp(b[i],i));
                else ev.pb(mp(a[i],i));
            }
        }
        sort(all(od));
        sort(all(ev));
        int las=0;
        bool can=true;
        vector<int> pos;
            rep(i,n){
                int num;
                if(i%2){
                    num=od[i/2].F;
                    pos.pb(od[i/2].S);
                }
                else{
                    num=ev[i/2].F;
                    pos.pb(ev[i/2].S);
                }
                if(num<las){
                    can=false;
                    break;
                }
                else{
                    las=num;
                }
            }
            if(!can)continue;
            int cnt=0;
            rep(i,n){
                rep(j,n-1){
                    if(pos[j]>pos[j+1]){
                        cnt++;
                        swap(pos[j],pos[j+1]);
                    }
                }
            }
            chmin(ans,cnt);
    }while(next_permutation(all(now)));
    if(ans==mod)cout << -1;
    else cout << ans;
}

/*



 */



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

using namespace std;

using int64 = long long;

map< vector< int >, int > x;

int grundy(vector< int > res) {
  sort(begin(res), end(res));
  if(x.count(res)) return x[res];
  set< int > st;
  for(int i = 0; i < (1 << res.size()); i++) {
    vector< int > nxt(res);
    for(int j = 0; j < res.size(); j++) {
      if((i >> j) & 1) {
        if(nxt[j] > 0) nxt[j]--;
      }
    }
    if(res != nxt) st.emplace(grundy(nxt));
  }
  int ret = 0;
  while(st.count(ret)) ++ret;
  return x[res] = ret;
}

int main() {
  int N;
  cin >> N;
  for(int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if(x % 2 == 1) {
      cout << "first\n";
      return 0;
    }
  }
  cout << "second\n";
}








Measured memory_bytes: 256
def bit_all(s,n):
    for i in range(2**n):
        c = []
        for j in range(n):
            if i>>j & 1:
                c.append("+")
            else:
                c.append("-")
        if eval(s[0] + c[0] + s[1] + c[1] + s[2] + c[2] + s[3]) == 7:
            print(s[0] + c[0] + s[1] + c[1] + s[2] + c[2] + s[3] + "=7")
            exit()
                
                
a = list(input())
bit_all(a,len(a)-1)



Measured memory_bytes: 3060
userInp = int(input())
# print(type(userInp))

inpStr = input()
inpStrs = list(inpStr)
count = 0;
maximum = 0;

for x in range(0,userInp):
	if inpStrs[x] == "I":
		count+= 1
		if maximum <= count:
			maximum = count

	elif inpStrs[x] == "D":
		count -= 1


print(maximum)


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

int main() {
  int n;
  bool p=false,w=false,g=false,y=false;
  string s,ans="none";
  cin >> n;
  for (int i =0;i<n;i++) {
    cin >> s;
    if (s == "P") p=true;
    if (s == "W") w=true;
    if (s == "G") g=true;
    if (s == "Y") y=true;
  }
  if (p+w+g+y == 3) ans="Three";
  else if (p+w+g+y == 4) ans="Four";
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
count = [0]
ans = []

for i in range(n-1):
  if h[i] < h[i+1]:
    count.append(i+1)
  if i == n - 2:
    if h[n-2] >= h[n-1]:
      count.append(n)

for i in range(len(count) - 1):
  ans.append(count[i+1] - count[i] - 1)

if n == 1:
  print(0)
else:
  print(max(ans))

Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
int i,j,n,u,k,v,g[101][101],d[101],f[101];
int main(void){
  for(i=1;i<101;i++)d[i]=1<<30;
  d[1]=0;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>u>>k;
    for(j=0;j<k;j++){
      cin>>v;
      g[u][v]++;
    }
  }
  queue<int>q;
  q.push(1);
  while(!q.empty()){
    u=q.front();q.pop();
    f[u]=1;
    for(i=1;i<101;i++){
      if(g[u][i]&&!f[i]){
        d[i]=min(d[i],d[u]+1);
        q.push(i);
      }
    }
  }
  for(i=1;i<=n;i++)cout<<i<<" "<<(d[i]==1<<30?-1:d[i])<<endl;
  return 0;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/**
*   author: j o s e m a g o
*   user: m a m i s a k i
**/
using namespace std;

/***PLANTILLA***/

using namespace __gnu_pbds; //*st.find_by_order(1);  st.order_of_key(p);
#pragma GCC optimize ("Ofast")
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mset(a,v) memset(a,v,sizeof(a))
#define pb push_back
#define sz(x) ((int)(x).size())
#define rsz resize
#define ln "\n"
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef double dbl;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const ld PI = 2*acos(0.0);
const int MOD = 1000000007;

string tostring(auto a){
    stringstream ss;ss<<a;string s = ss.str();
    return s;
}

/**Mi Debug**/
#define var(x) cout<<#x<<" = ";
#define db(x) cout<<#x<<" = "<<x<<"\n";
void dbvector(vector<auto>&v){
    int c = -1;
    for(auto i: v){
        c++;cout<<"["<<c<<":"<<i<<"] ";
    }cout<<"\n";
}
void dbmapa(map<auto,auto>mp){
   for(auto x : mp) cout<<"{"<<x.first<<":"<<x.second<<"} ";cout<<"\n";
}
void dbstring(string v){
    int c = -1;
    for(auto i: v){
        c++;cout<<"["<<c<<":"<<i<<"] ";
    }cout<<"\n";
}

/***********Code***************/

const int JJJ = 100100;










int main(){

  //freopen("input.in","r",stdin);
  //freopen("input.out","w",stdout);

    ios_base::sync_with_stdio(0); cin.tie(0);


    int n,k;
    cin >> n >> k;
    if(n*500 >= k){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }







    return 0;
}


Measured memory_bytes: 256
def f(b, n):
    return n if n < b else n % b + f(b, n // b)

def solve():
    N, S = map(int, open(0))

    if N == S:
        return N + 1

    sqr = int(N ** 0.5)

    for b in range(2, sqr + 1):
        if f(b, N) == S:
            return b

    M = N - S
    for p in reversed(range(1, sqr + 1)):
        b = M // p + 1
        if b >= 2 and f(b, N) == S:
            return b

    return -1


print(solve())

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int n;
    cin >> n;
    vi a(n);
    rep(i,n){
        cin >> a[i];
    }
    
    int sum = acc(all(a),0);
    int mx = maxel(a);
    sum -= mx;
    if(sum>mx)Yes
    No

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  bool ans = true;

  for(int i=0;i<3;i++){
    if(s[i]==s[i+1])
      ans = false;
  }
  
  if(ans)
    cout << "Good" << endl;
  else
    cout << "Bad" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
int N;
string s;
int main(){
  cin >> s;
  s.erase(s.end()-1);
  while(1){
    bool f=true;
    if(s.length()%2==0){
      int len=s.length()/2;   
      for(int i=0;i<len;i++){
	if(s[i]!=s[i+len])f=false;
      }
      
      if(f){ cout << s.length() << endl;
	return 0;
      }
    }
    s.erase(s.end()-1);
    //cout << s << endl;
  }
  cout << s.length() << endl;
  return 0;
}


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


public class Main {
    public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       int[][][] room=new int[4][3][10];
       int roomnum=sc.nextInt();
       
       for(int i=0;i<roomnum;i++)
       {
           int b=sc.nextInt();
           int f=sc.nextInt();
           int r=sc.nextInt();
           int v=sc.nextInt();
           
           room[b-1][f-1][r-1]+=v;
       }
       // Your 
     for(int i=0;i<4;i++){
       for(int x=0;x<3;x++) {
          for(int y=0;y<10;y++){
              if(y!=9){
                  System.out.printf(" %d",room[i][x][y]);
              }else{
                   System.out.printf(" %d\n",room[i][x][y]);
              }
              
          } 
       
       } 
       if(i!=3) System.out.println("####################");
     }
    } 
     
}




Measured memory_bytes: 31012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Stream;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try( BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      br.lines()
        .filter(s -> !s.equals("0") && !s.isEmpty())
        .mapToInt(s -> IntStream.range(0,s.length())
          .map(i -> Character.getNumericValue(s.charAt(i)))
          .sum() )
        .forEach(System.out::println);
    }
  }
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll S;
    cin >> S;
    vector<ll> vec(2001);
    vec[0] = 0;
    vec[1] = 0;
    vec[2] = 0;
    vec[3] = 1;
    vec[4] = 1;
    vec[5] = 1;
    for (int i = 6; i <= S; ++i) {
        ll tmp = 1;
        for (int j = 3; j <= i - 3; ++j) {
            tmp += vec[j];
            tmp %= mod;
        }
        vec[i] = tmp;
    }

    cout << vec[S] << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int N,M;
  cin >> N >> M;
  priority_queue<ll> q;
  for(int i = 0;i < N;i++){
    ll A;
    cin >> A;
    q.push(A);
  }

  ll ans = 0;
  for(int i = 0;i < M;i++){
    ll now = q.top();
    q.pop();
    q.push(now/2);
  }

  for(int i = 0;i < N;i++){
    ans += q.top();
    q.pop();
  }

  cout << ans << endl;
}


Measured memory_bytes: 1528
package main

import (
	"fmt"
)

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)

	xa := abs(x-a)
	xb := abs(x-b)

	if xa > xb {
		fmt.Println("B")
	} else {
		fmt.Println("A")
	}
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <functional>


using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

string s;

int main(){
	cin >> s;
	int n = 0;
	rep(i, s.size()) {
		if (s[i] == 'p')
			n++;
	}
	cout << s.size() / 2 - n << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>
using namespace std;

int main(){
	int a, b;
	string s;
	stack<int> t;
	while (cin >> s){
		if (s[0] == '+') {
			a = t.top();
			t.pop();
			b = t.top();
			t.pop();
			t.push(a + b);
		}
		else if (s[0] == '-') {
			a = t.top();
			t.pop();
			b = t.top();
			t.pop();
			t.push(b - a);
		}
		else if (s[0] == '*') {
			a = t.top();
			t.pop();
			b = t.top();
			t.pop();
			t.push(a * b);
		}
		else
			t.push(atoi(s.c_str()));
	}
	cout << t.top() << endl;
	return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;

ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[1000005],R[1000005];
void make(){
	F[0] = 1;
	for(int i=1;i<1000005;i++) F[i] = F[i-1]*i%mod;
	R[1000004] = modpow(F[1000004],mod-2);
	for(int i=1000003;i>=0;i--) R[i] = R[i+1] * 1LL * (i+1) % mod;
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
ll bin[1000005];

int main(){
	make();
	cin >> n;
	bin[0] = 1LL;
	for(int i=1;i<1000005;i++) bin[i] = bin[i-1]*2LL%mod;
	ll X = 0;
	ll ans = 0;
	ll r3 = modpow(3LL,mod-2);
	ll r3n = modpow(r3,n);
	ll rn = modpow(n,mod-2);
	for(int dif=0;dif<n;dif++){
		ll num[3]={};
		if(dif%2 == 0){
			num[0] = (bin[dif]+2)*r3%mod;
			num[1] = num[2] = (bin[dif]+mod-1)%mod*r3%mod;
		}
		else{
			num[0] = (bin[dif]+mod-2)%mod*r3%mod;
			num[1] = num[2] = (bin[dif]+1)*r3%mod;
		}
		for(int i=0;i<3;i++){
			num[i] = num[i] * C(n-1,dif) % mod;
			ll j = dif; if(i != 2) j++;
			ans += num[i] * rn % mod * modpow(j,mod-2) % mod * r3n % mod;
		}
	}
	cout << ans%mod << endl;
}

Measured memory_bytes: 23808
Module Module1

    Sub Main()

        Dim N As Integer = CInt(Console.ReadLine())
        Dim tmp As String() = Split(Console.ReadLine(), " ")

        Dim c As Integer = 1
        Dim k As Integer = 0
        For ix As Integer = 0 To N - 1
            If tmp(ix) = c Then
                c += 1
            Else
                k += 1
            End If
        Next

        If c > 1 Then
            Console.WriteLine(k)
        Else
            Console.WriteLine(-1)
        End If
        'Console.ReadLine()

    End Sub

End Module


Measured memory_bytes: 32476
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll dsa[100100];
ll dsb[100100];
ll dta[100100];
ll dtb[100100];

int main(){
	string s,t;
	cin>>s;
	cin>>t;
	clr(dsa,0);
	clr(dsb,0);
	clr(dta,0);
	clr(dtb,0);
	rep(i,0,s.sz){
		if(s[i]=='A'){
			dsa[i+1]=1;
		}
		else{
			dsb[i+1]=1;
		}
	}
	rep(i,0,t.sz){
		if(t[i]=='A'){
			dta[i+1]=1;
		}
		else{
			dtb[i+1]=1;
		}
	}
	rep(i,1,100050){
		dsa[i] += dsa[i-1];
		dsb[i] += dsb[i-1];
		dta[i] += dta[i-1];
		dtb[i] += dtb[i-1];
	}
	ll q;
	cin>>q;
	rep(i,0,q){
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		ll sa = dsa[b]-dsa[a-1];
		ll sb = dsb[b]-dsb[a-1];
		ll ta = dta[d]-dta[c-1];
		ll tb = dtb[d]-dtb[c-1];
		// print(sa);
		// print(sb);
		// print(ta);
		// print(tb);
		sa %= 3;
		sb %= 3;
		ta %= 3;
		tb %= 3;
		vector<pair<ll,ll> > vp;
		rep(i,0,3){
			vp.pb(mp((sa+i)%3,(sb+i)%3));
		}
		int flag = 0;
		rep(i,0,vp.sz){
			if(ta == vp[i].fi&& tb == vp[i].se){
				flag = 1;
			}
		}
		if(flag == 1){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}




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

int main() {
  unsigned N, A, B;
  std::cin >> N >> A >> B;
  std::vector<unsigned> X(N);
  for (unsigned i = 0; i < N; ++i) {
    std::cin >> X[i];
  }
  unsigned long long ans = 0ull;
  for (unsigned i = 1; i < N; ++i) {
    if (X[i] - X[i-1] > B / A) {
      ans += B;
    } else {
      ans += (X[i] - X[i-1]) * A;
    }
  }
  std::cout << ans;
  return 0;
}

Measured memory_bytes: 640
N,W = list(map(int,input().split()))
DP = [[float('inf')]*(1000*N+1) for i in range(N+1)]
DP[0][0] = 0
V = 0
for i in range(1,N+1):
    w,v = list(map(int,input().split()))
    V += v
    for j in range(V+1):
        DP[i][j] = min(DP[i-1][j],DP[i-1][j-v]+w) if v <= j else DP[i-1][j]

for i in range(1000*N,-1,-1):
    if DP[N][i] <= W:
        print(i)
        break

Measured memory_bytes: 301256
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int ksm (int a,int b)
{
	int ans=1;
	while (b)
	{
		if (b&1) ans=(LL)ans*a%P;
		a=(LL)a*a%P,b>>=1;
	}
	return ans;
}
int n,m; LL x;
int fa[N];
void init () { for (int i=1; i<=n; i++) fa[i]=i; }
int getf (int x) { return fa[x]==x?x:fa[x]=getf (fa[x]); }
bool merge (int x,int y) { return fa[x=getf (x)]=y=getf (y),x!=y; }
struct EDGE { int x,y,w; }e[N];
LL calc (int id)
{
	init ();
	LL ans=e[id].w; merge (e[id].x,e[id].y);
	for (int i=1; i<=m; i++)
		ans+=e[i].w*merge (e[i].x,e[i].y);
	return ans;
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n),sc(m),sc(x);
	for (int i=1; i<=m; i++)
		sc(e[i].x),sc(e[i].y),sc(e[i].w);
	sort (e+1,e+m+1,[](EDGE A,EDGE B) { return A.w< B.w; });
	if (calc (0)> x) return pr(0),0;
	int A=0,B=0;
	for (int i=1; i<=m; i++)
	{
		LL g=calc (i);
		A+=g==x,B+=g> x;
	}
	if (A+B!=m) ++A;
	pr((LL)(ksm (2,A)-2+P)%P*ksm (2,B)%P);

    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int N,K;
    cin >> N >> K;
    vector<int> l;
    for(int i=0; i<N; i++)
    {
        int x;
        cin >> x;
        l.push_back(x);
    }
    sort(l.begin(), l.end(),greater<int>());
    int ans = 0;
    for(int i=0; i<K; i++)
    {
    	ans += l[i];
    }
    cout << ans << endl;
	return 0;
}


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

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s, t;
    cin >> s >> t;

    bool b = true;
    vector<int> v(26, -1);
    vector<int> w(26, -1);

    for (int i = 0; i < s.size(); i++) {
        if (v[s[i] - 'a'] == -1) {
            v[s[i] - 'a'] = t[i] - 'a';
        } else {
            if (v[s[i] - 'a'] != t[i] - 'a') {
                b = false;
                break;
            }
        }
    }

    for (int i = 0; i < t.size(); i++) {
        if (w[t[i] - 'a'] == -1) {
            w[t[i] - 'a'] = s[i] - 'a';
        } else {
            if (w[t[i] - 'a'] != s[i] - 'a') {
                b = false;
                break;
            }
        }
    }

    if (b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 916
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
#define rep(src,dst)    for(int i=src; i<dst;  i++)
#define rep2(src,dst)   for(int j=src; j<dst;  j++)
#define INF 1000000000000 //1e+12
#define MOD 10000007 //1e9+7
#define PI  acos(-1)
#define ll long long
template<typename T> inline void cMin(T* a, T* b)  {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}
template<typename T> inline bool isEven(T a)       {return (a%2==0? true : false );}

int main(){
    int n; cin >> n;
    vector<int> even;
    rep(0,n){
        int a;
        cin >> a;
        if(!(a&1))  even.push_back(a);
    }
    rep(0,even.size()){
        if(!(even[i]%3==0 || even[i]%5==0)){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}
/*

*/


Measured memory_bytes: 3592
import java.util.*;
import java.awt.geom.Rectangle2D;

public class Main{
	private static final double EPS = 1e-10;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(sc.hasNextDouble()){
			double x,y,w,h;
			x = sc.nextDouble()-EPS;
			y = sc.nextDouble()-EPS;
			w = sc.nextDouble()-x+EPS;
			h = sc.nextDouble()-y+EPS;
			Rectangle2D r = new Rectangle2D.Double(x,y,w,h);

			x = sc.nextDouble();
			y = sc.nextDouble();
			w = sc.nextDouble()-x;
			h = sc.nextDouble()-y;
			System.out.println(r.intersects(x,y,w,h) ? "YES" : "NO");
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>

int main(int argc, const char * argv[]){
    int a,b,c,tmp;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    if(b>c){
        tmp=b;
        b=c;
        c=tmp;
    }
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}



Measured memory_bytes: 2080
#k,a,b=map(int,input().split())
n=int(input())
s=[input() for i in range(n)]
fin_a=0
ini_b=0
ab=0
for i in s:
    if i[0]=='B' and i[-1]=='A':
        ab+=1
    elif i[0]=='B':
        ini_b+=1
    elif i[-1]=='A':
        fin_a+=1

s='+'.join(s)
ans=s.count('AB')
print(ans+min(fin_a+ab,ini_b+ab) if not (fin_a==0 and ini_b==0) else ans+max(ab-1,0))


Measured memory_bytes: 3700
n = int(input())
t = []
for _ in range(n):
    t.append(int(input()))
    
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

ans = t[0]
for i in t[1:]:
    ans = ans*i//gcd(ans, i)
    
print(ans)

Measured memory_bytes: 3060
import sys
import numpy as np
from scipy.misc import comb
sys.setrecursionlimit(1000000)
 
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

tmp = 0
ans = 0

for i in range(n):
    num = b[i] - a[i]
    if num > 0:
        num2 = a[i+1] - num
        if num2 <= 0:
            ans += a[i] + a[i+1]
            a[i+1] = 0
        else:
            ans += b[i]
            a[i+1] -= num
    else:
        ans += b[i]

print(ans)

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

class ABC
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        List<int> num = new List<int> { };
        for(int i = 0; i < 3; ++i)
        {
            num.Add(int.Parse(str[i]));
        }
        int a = num[0];
        int b = num[1];
        int c = num[2];

        int d = a - b;
        int e = c - d;
        if(e <= 0)
        {
            Console.WriteLine(0);
        }
        else
        {
            Console.WriteLine(e);
        }
    }
}

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

int main()
{
    string s,p;
    cin>>s>>p;

    string s2=s+s;
    if(s2.find(p)!=string::npos)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}  


Measured memory_bytes: 3204
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  int a;

  cin >> n >> m;
  
  vector<int>step(n + 1, true);
  for(int i = 0;i < m;i++){
    cin >> a;
    step[a] = false;
  }
  
  vector<long long>dp(n + 1);
  dp[0] = 1;
  for(int now = 0;now < n;now++){
    for(int next = now + 1;next <= min(n, now + 2);next++){
      if(step[next]){
	dp[next] += dp[now];
	dp[next] %= 1000000007;
      }
    }
  }

  cout << dp[n] << endl;
  return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5,mod=1e9+7;
ll fct[N],inv[N],invfct[N];
void init(){
    fct[0]=fct[1]=1;
	inv[1]=1;
	invfct[0]=invfct[1]=1;
	for(ll i=2;i<N;i++){
		fct[i]=i*fct[i-1]%mod;
		inv[i]=ll(mod-inv[mod%i])*(mod/i)%mod;
		invfct[i]=ll(inv[i])*invfct[i-1]%mod;
	}
}
ll ncr(ll n,ll r){
    if(r<0 || n<0 || n-r<0)return 0;
    ll ans = fct[n]*invfct[r];
    ans%=mod;
    ans = ans*invfct[n-r];
    ans%=mod;
    return ans;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    init();
    ll n,m;cin>>n>>m;
    map<ll,ll> mp;
    for(ll i=2;i*i<=m;i++){
        if(m%i)continue;
        while(m%i==0)m/=i,mp[i]++;
    }
    if(m>1)mp[m]++;
    ll ans = 1;
    for(auto &ele:mp)ans*=ncr(ele.second+n-1,n-1),ans%=mod;
    cout<<ans;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
const int N=200;
struct node{
    double x,y;
}e[N];
bool cmp(const node &a,const node &b){//极角排序
    return atan2(a.y,a.x)<atan2(b.y,b.x);
}
int n;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>e[i].x>>e[i].y;
    sort(e,e+n,cmp);
    double ans=0;
    for(int i=0;i<n;i++){
        double x=e[i].x,y=e[i].y;
        ans=max(ans,x*x+y*y);
        for(int j=(i+1)%n;j!=i;j=(j+1)%n){
            x+=e[j].x,y+=e[j].y;
            ans=max(ans,x*x+y*y);
        }
    }
    printf("%.20f\n",sqrt(ans));
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    string S, T;
    cin >> S >> T;
    int N = S.size();
    int M = T.size();

    vector<bool> have(26);
    for (int i = 0; i < N; i++) have[S[i] - 'a'] = true;
    for (int j = 0; j < M; j++) {
        if (!have[T[j] - 'a']) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<vector<int>> next(N+1, vector<int>(26, N));
    for (int i = N - 1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            next[i][j] = next[i+1][j];
        }
        next[i][S[i] - 'a'] = i;
    }

    int idx = -1;
    int cnt = 0;
    for (int j = 0; j < M; j++) {
        idx = next[idx+1][T[j] - 'a'];

        if (idx == N) {
            idx = next[0][T[j] - 'a'];
            cnt++;
        }
    }

    cout << cnt * N + idx + 1 << endl;
    return 0;
}

Measured memory_bytes: 24704
#include<stdio.h>

#define MAX 100005
#define NIL -1

struct Node{
  int w,l,r;
};

struct Node X[MAX];
int a,A[MAX];

void print(int s){
  int i,b;
  printf("node %d: ",s);
  printf("parent = %d, ",X[s].w);
  printf("depth = %d, ",A[s]);

  if(X[s].w == NIL)
    printf("root, ");
  else if(X[s].l==NIL)
    printf("leaf, ");
  else
    printf("internal node, ");

  printf("[");

  for(i = 0,b=X[s].l;b!=NIL;i++,b = X[b].r){
    if(i)
      printf(", ");
    printf("%d",b);
  }
  printf("]\n");
}


void rec(int s,int w){
  A[s] = w;
  if(X[s].r!=NIL) rec(X[s].r,w);
  if(X[s].l!=NIL) rec(X[s].l,w+1);
}

int main(){
  int i,j,l,r,b,v,c;
  scanf("%d",&a);
  for(i = 0;i<a;i++)
    X[i].w = X[i].l = X[i].r = NIL;

  for(i = 0;i<a;i++){
    scanf("%d%d",&v,&c);
    for(j = 0;j<c;j++){
      scanf("%d",&b);
      if(j==0)X[v].l = b;
      else X[l].r = b;
      l = b;
      X[b].w = v;
    }
  }
  for(i = 0;i<a;i++){
    if(X[i].w == NIL)r =i;
  }

  rec(r,0);

  for(i = 0;i<a;i++)
    print(i);

  return 0;
}



Measured memory_bytes: 6408
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin>>s;
  string t="CODEFESTIVAL2016";
  int count=0;
  for(int i=0;i<16;i++){
    if(s[i]!=t[i]){
      count++;
    }
  }
  cout<<count;
}

Measured memory_bytes: 3572
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

ll modd = 1000 * 1000 * 1000 + 7;

class UnionFind {
    public:
      vector<int> parent;
      vector<int> size;
//      size[i] = number of nodes in tree rooted at i
// Note: not necessarily correct if i is not a root node
      set<int> roots;

    UnionFind(int n) : parent(n), size(n) {
        forr(i,0,n) { roots.insert(i); }
        forr(i,0,n) {
            parent[i] = i; size[i] = 1;
        }
    } 

    int Find(int p) {
        int root = p;
        while (root != parent[root]) {  root = parent[root]; }
        while (p != root) {
            int newp = parent[p];
            parent[p] = root;
            p = newp;
        }
        return root;
    }

    void Union(int p, int q) {
        int rootP = Find(p);
        int rootQ = Find(q);
        if (rootP == rootQ) return;

        if (size[rootP] < size[rootQ]) {
            parent[rootP] = rootQ;
            size[rootQ] += size[rootP];
            roots.erase(rootP);
        }
        else {
            parent[rootQ] = rootP;
            size[rootP] += size[rootQ];
            roots.erase(rootQ);
        }
    }

};



int main()   {

      ios_base::sync_with_stdio(false);

      cout.precision(17);
      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readint(q);
        UnionFind uf(n);
        forr(i,0,q) {
            readint(a); readint(u); readint(v);
            if (a==0) {
                uf.Union(u,v);
            }
            if (a==1) {
                cout << (uf.Find(u) == uf.Find(v)) << endl;
            }
        }        
    }
    return 0;
}


Measured memory_bytes: 13692
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		while( (n%10) != (n/10)%10 || ((n/10)%10) != (n/100)%10 )n++;
		
		System.out.println(n);
	}
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main() {
    int n;
    cin >> n;
    map<ll,int> mp;
    REP(i,n){
        ll t;
        cin >> t;
        mp[-t]++;
    }
    vector<ll> v;
    for(const auto& e:mp){
        ll a = e.first;
        int b = e.second;
        if(b>=2)v.push_back(a);
        if(b>=4)v.push_back(a);
        if(v.size()>=2){
            COUT(v[0]*v[1]);
            return 0;
        }
    }
    COUT(0);
    return 0;
}

Measured memory_bytes: 6528
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
  int n, out;
  cin >> n;
  if (n >= 64) {
    out = 64;
  } else if (n >= 32) {
    out = 32;
  } else if (n>=16) {
    out = 16;
  } else if (n>=8) {
    out = 8;
  } else if (n>=4) {
    out = 4;
  } else if (n>=2) {
    out = 2;
  } else {
    out = 1;
  }
  cout << out << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100001
#define INFTY 2000000000
#define INFTYc 100
int Partition(int*,int,int);
void quicksort(int*,int,int);
void merge(int*,int,int,int);
void mergeSort(int*A,int,int);
char C[MAX];
char D[MAX];
int L[MAX/2+2];
int R[MAX/2+2];
char Lc[MAX/2+2];
char Rc[MAX/2+2];

int main(){
  int i,flag;
  int n;
  int A[MAX];
  int B[MAX];
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf(" %c%d",&C[i],&A[i]);
    B[i] = A[i];
    D[i] = C[i];
  }
  quicksort(A,0,n-1);
  mergeSort(B,0,n);
  for(i = 0; i < n; i++){
    flag = 1;
    if(C[i] != D[i]){
      flag = 0;
      break;
    }
  }
  if(flag==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0; i < n; i++){
    printf("%c %d\n",C[i],A[i]);
  }
  return 0;
}

int Partition(int* A,int p,int r){
  int x,i,j,tmp;
  char ctmp,y;
  x = A[r];
  y = C[r];
  i = p - 1;
  for(j = p; j < r; j++){
    if(A[j] <= x){
      i = i + 1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
      ctmp = C[i];
      C[i] = C[j];
      C[j] = ctmp;
    }
  }
    tmp = A[i+1];
    A[i+1] = A[r];
    A[r] = tmp;
    ctmp = C[i+1];
    C[i+1] = C[r];
    C[r] = ctmp;
  return i + 1;
}
void quicksort(int* A, int p, int r){
  int q;
  if(p < r){
    q = Partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}

void merge(int* B,int left,int mid, int right){
  int n1,n2;
  int i,j,k;
  n1 = mid - left;
  n2 = right - mid;

  for(i = 0; i < n1; i++){
    L[i] = B[left + i];
    Lc[i] = D[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = B[mid + i];
    Rc[i] = D[mid + i];
  }
  L[n1] = INFTY;
  Lc[n1]= INFTYc;
  R[n2] = INFTY;
  Rc[n2] = INFTYc;
  i = 0; 
  j = 0;
  for(k = left; k < right; k++){
    if(L[i] <= R[j]){
      B[k] = L[i];
      D[k] = Lc[i];
      i = i + 1;
    }
    else{
      B[k] = R[j];
      D[k] = Rc[j];
      j = j + 1;
    }
  }
}

void mergeSort(int* B, int left, int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right)/2;
    mergeSort(B, left, mid);
    mergeSort(B, mid, right);
    merge(B, left, mid, right);
  }
}

Measured memory_bytes: 2072
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	int n, t, a;
	cin >> n >> t >> a;

	double diff = 1e8;
	int idx;
	rep(i,n){
		double h;
		cin >> h;

		if(diff > abs(a - (t - h * 0.006))){
			diff = abs(a - (t - h * 0.006));
			idx = i + 1;
		}
	}
	cout << idx << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
  static void Main(string[] args)
  {
    var list = Console.ReadLine().Split(' ');
    var a = int.Parse(list[0]);
    var b = int.Parse(list[1]);
    var c = int.Parse(list[2]);
    int dokuMax=0;
    if(a+b>=c){
      dokuMax=c;
    }else{
      dokuMax=a+b+1;
    }
    
    int oishii=0;
    oishii+=dokuMax;
    oishii+=b;
    
    Console.WriteLine(oishii);
  }
}

Measured memory_bytes: 11092
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    int n,i;
    cin>>n;
    int od = n/2 + n%2;
    double pro = (double)od/(double)n;
    cout<<fixed<<setprecision(10)<<pro;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int toInt(string s){
    stringstream geek (s);
    int x = 0;
    geek >> x;
    return x;
}
int main(){
    Hello
    string s;
    cin >> s;
    string s1 = "";
    s1 += s[0];
    s1 += s[1];
    string s2 = "";
    s2 += s[2];
    s2 += s[3];
    int firstNumb = toInt(s1), secondNumb = toInt(s2);
    if(firstNumb >= 1 && firstNumb <= 12 && secondNumb >= 1 && secondNumb <= 12)
        cout << "AMBIGUOUS";
    else if(firstNumb >= 1 && firstNumb <= 12)
        cout << "MMYY";
    else if(secondNumb > 0 && secondNumb <= 12)
        cout << "YYMM";
    else cout << "NA";
    return 0;
}


Measured memory_bytes: 3660