akhauriyash/Code-Regression huggingface dataset:
twoNumbers=list(map(int,input().split()))
x=twoNumbers[0]
y=twoNumbers[1]
devidedBy=[]
syou=[]
if x>=y:
    for number in range(1, y+1):
        if y%number==0:
            if number>y//number:
                break
            else:
                if not number in devidedBy:
                    devidedBy.append(number)
                if not y//number in syou:
                    syou.append(y//number)
else:
    for number in range(1, x+1):
        if x%number==0:
            if number>x//number:
                break
            else:
                if not number in devidedBy:
                    devidedBy.append(number)
                if not x//number in syou:
                    syou.append(x//number)

if devidedBy[len(devidedBy)-1]==syou[len(syou)-1]:
    del devidedBy[len(devidedBy)-1]

devidedBy.extend(syou)
devidedBy.sort()
index=len(devidedBy)-1
while index>=0:
    if x>=y:
        if x%devidedBy[index]==0:
            print(devidedBy[index])
            break
        else:
            index-=1
    else:
        if y%devidedBy[index]==0:
            print(devidedBy[index])
            break
        else:
            index-=1


Measured memory_bytes: 5608
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
 
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
typedef vector<int> Edges;
typedef vector<Edges> Graph;
 
int n;
ll len[1200000];
bool root[1200000];
Graph g;
vector<int> order;
 
int main() {
  while (scanf("%d", &n) > 0) {
while(n > 2000000);
    MEMSET(root, false);
    g = Graph(n);
    REP(i, n) {
      int p;
      scanf("%lld %d", &len[i], &p);
      if (p != -1) {
        g[p].push_back(i);
      } else {
        root[i] = true;
      }
    }
    REP(i, n) {
      if (!root[i]) { continue; }
      queue<int> que;
      que.push(i);
      while (!que.empty()) {
        int from = que.front();
        que.pop();
        order.push_back(from);
        FORIT(it, g[from]) {
          int to = *it;
          que.push(to);
        }
      }
    }
    reverse(order.begin(), order.end());
    ll ans = 0;
    REP(i, n) {
      int from = order[i];
      vector<int> lens;
      FORIT(it, g[from]) {
        lens.push_back(len[*it]);
      }
      sort(lens.begin(), lens.end());
      ll sum = 0;
      FORIT(it, lens) {
        ans += sum;
        sum += *it;
      }
      len[from] += sum;
    }
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 73988
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
using namespace std;
 
int main() {
  ll N, cnt;
  cin >> N;
  vector<ll> a(N);
  for(ll i = 0; i < N; i++) {
    cin >> a.at(i);
    while(1){
      if(a.at(i) % 2 == 0) {
        cnt++;
        a.at(i) /= 2;
      }
      else break;
    }
  }
  cout << cnt << endl;
}


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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

int n,m,x,y,mx;
vi v;
vector<vi> g(maxn);
int a[maxn],b[maxn];
string s;

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

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

	cin >> n;
	int acum = 1;
	bool flag = 0;
	int res = 0;
	for(int i=0;i<n;i++)
	{
		int f;
		cin >> f;
		if(f == 0)
		flag = 1;
		
		double aux1=log10(f),aux2 = log10(acum);
		if(aux1 + aux2 > 18.0 or acum*f > OO)
		res=-1,acum=0;
		acum *= f;
	}
	if(flag==1)
	{
		cout << 0;
	}
	else if(res == -1)
	cout << "-1";
	else
	cout << acum;


	return 0;
}



Measured memory_bytes: 5476
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n, a, b;
	cin >> n >> a >> b;
	dump(min(n * a, b));
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main()  {
	var s string
	fmt.Scan(&s)

	const N int32 = 13
	dp := make([]int32, N)
	dp[0] = 1

	var c byte
	mul := int32(1)
	for i := len(s)-1; i>=0; i-- {
		nextDP := make([]int32, N)
		mod := int32(1000000007)
		c = s[i]
		if c == '?' {
			for k := int32(0); k < 10; k++ {
				for j := int32(0); j < N; j++ {
					nextDP[(k*mul+ j)%N] += dp[j]
					nextDP[(k*mul+ j)%N] %= mod
				}
			}
		} else {
			k := int32(s[i] - '0')
			for j := int32(0); j < N; j++ {
				nextDP[(k*mul+ j)%N] += dp[j]
				nextDP[(k*mul+ j)%N] %= mod
			}
		}
		mul *= 10
		mul %= N
		dp = nextDP
	}
	fmt.Println(dp[5])
}

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<ll, ll>
#define sz size()

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<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...);} 
#define traceloop(x,a) { cerr<<#a<<": "; for(ll ix=0;ix<x;ix++) cerr<<a[ix]<<" "; cerr<<endl; }

int main()
{
	ios::sync_with_stdio(0);
	int i, n, j, W;
	cin>>n>>W;

	int w[n], v[n];

	for(i=0;i<n;++i)
		cin>>w[i]>>v[i];

	vector<ll> dp(W+1, 0);
	for(i=0;i<n;++i)
	{
		vector<ll> new_dp(W+1, 0);	

		for(int wt=0;wt<=W;++wt)
		{
			if(wt-w[i] >= 0)
				new_dp[wt] = max(dp[wt-w[i]] + v[i], dp[wt]);
			else
				new_dp[wt] = dp[wt];
			
		}
		dp = new_dp;
	}

	ll ans = 0;
	for(i=0;i<=W;++i)
		ans = max(ans, dp[i]);

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1804
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

struct UnionFind {
    vector<ll> par;
        
    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }
    
    ll find(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = find(par[x]);
    }
    
    bool same(ll x, ll y) {
        return find(x) == find(y);
    }
    
    bool unite(ll x, ll y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    ll size(ll x) {
        return -par[find(x)];
    }

    void print(ll x){
        rep(i,x){
            cout<<par[i]<<endl;
        }
        return ;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,m,a[100010];
    pll b[100010];
    vll v;
    cin>>n>>m;
    rep(i,n){
        cin>>a[i];
        b[i].fi=LLINF,b[i].sc=-1;
    }
    UnionFind uf(n);
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        uf.unite(x,y);
    }
    rep(i,n){
        ll x=uf.find(i);
        if(i==x) v.pb(x);
        if(a[i]<b[x].fi){
            b[x].fi=a[i];
            b[x].sc=i;
        }
    }
    if(uf.size(0)==n){
        cout<<0<<endl;
        return 0;
    }
    ERASE(v);
    ll N=v.size(),ans=0;
    bool ok[100010]={};
    rep(i,v.size()){
        ans+=b[v[i]].fi;
        ok[b[v[i]].sc]=true;
    }
    vll s;
    rep(i,n){
        if(!ok[i]){
            s.pb(a[i]);
        }
    }
    /*
    rep(i,s.size()){
        cout<<s[i]<<endl;
    }
    */
    sort(all(s));
    if(s.size()<N-2){
        cout<<"Impossible"<<endl;
        return 0;
    }
    rep(i,N-2){
        ans+=s[i];
    }
    cout<<ans<<endl;
    
    return 0;
}

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

using namespace std;

const int maxn = 1010;

typedef pair<int,int> pi;
int N, M, A, B;
int a[maxn][maxn];

priority_queue<pi> pq;

int fx = -1, fy = -1;

int main() {
	scanf("%d%d%d%d", &N, &M, &A, &B);
	int k1 = 2 * A - M, k2 = N - 2 * B;
	for (int x = 0; x <= N; x++) {
		for (int y = 0; y <= M; y++) {
			if (x * k1 + y * k2 == A * N - M * B) {
				fx = x;
				fy = y;
				break;
			}
		}
	}
	if (fx == -1) {
		puts("-1");
		return 0;
	}
	for (int i = 1; i <= fy; i++) pq.push(pi(B, i));
	for (int i = fy+1; i <= M; i++) pq.push(pi(N-B, i));
	for (int i = 1; i <= N; i++) {
		int T = 0;
		if (i <= fx) T = A;
		else T = M - A;
		vector<pi> vec;
		while (T--) {
			pi p = pq.top(); pq.pop();
			a[i][p.second] = 1;
			vec.push_back(pi(p.first - 1, p.second));
		}
		for (int i = 0; i < vec.size(); i++) pq.push(vec[i]);
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			putchar('0' + a[i][j]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 5248
import math
H, W = map(int, input().split())

if H%2 == 0:
    if W == 1 or H == 1:
        print(1)
    else:
        print(int(W*(H/2)))
else:
    if W == 1 or H == 1:
        print(1)
    else:
        print(int(W*math.floor((H/2)) + math.ceil(W/2)))


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

#define fastio std::ios::sync_with_stdio(false);
#define ll long long
#define scann(n) scanf("%d",&n)
#define scand(n) scanf("%lf",&n)
#define scans(s) scanf("%s",&s)
#define pb push_back
#define ppb pop_back
#define full v.begin(),v.end()
#define debug cout<<"Bug! Vag! Bagh!"<<endl;
#define pi acos(-1)
#define mx 10010
#define inf 10e10

int main()
{
    string s,ss;
    cin>>s>>ss;
    ll cnt=0;
    for(ll i=0;i<s.size();i++)
    {
        if(s[i]!=ss[i]) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}
///arBishal_2017331022


Measured memory_bytes: 3856
#include <iostream>

using namespace std;

long long int knapsack(long long int n,long long int W,long long int w[],long long int v[])
{
    long long int arr[n+1][W+1];
    for(long long int i=0;i<=n;i++)
    {
        for(long long int j=0;j<=W;j++)
        {
            if(i==0||j==0)
            {
                arr[i][j]=0;
            }
            else
            {
                if(j<w[i-1])
                {
                    arr[i][j]=arr[i-1][j];
                }
                else
                {
                    arr[i][j]=arr[i-1][j]>arr[i-1][j-w[i-1]]+v[i-1]?arr[i-1][j]:arr[i-1][j-w[i-1]]+v[i-1];
                }
            }
        }
    }
    return arr[n][W];
}
int main()
{
    long long int N,W;
    cin>>N;
    cin>>W;
    long long int w[N],v[N];
    for(int i=0;i<N;i++)
    {
        cin>>w[i];
        cin>>v[i];
    }
    cout<<knapsack(N,W,w,v);
    return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>
class UnionFind {
	std::vector<int> vec;
public:
	UnionFind(int size) : vec(size, -1) {};
	int find(int a) {
		return vec[a] >= 0 ? vec[a] = find(vec[a]) : a;
	}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b) return;
		if (vec[a] > vec[b]) std::swap(a, b);
		vec[a] += vec[b];
		vec[b] = a;
	}
};

int main() {
	int n, m; std::cin >> n >> m;
	UnionFind uft(n + 1);
	for (auto i = 0; i < m; ++i) {
		int x, y, z; std::cin >> x >> y >> z;
		uft.unite(--x, --y);
	}
	int result{ 0 };
	for (auto i = 0; i < n; ++i) {
		if (uft.same(i, n)) continue;
		++result;
		uft.unite(i, n);
	}
	std::cout << result << std::endl;
}


Measured memory_bytes: 888
#include<stdio.h>
#include<string.h>
int main(){
	char arrc[111];
	int a,b,i,l,j;
	scanf("%s",arrc);
	l=strlen(arrc);
	a=b=0;
	for(i=0;i<l;i++){
		if(arrc[i]=='C'){
			a=1;
			break;	
		}  
	}
	for(j=i;j<l;j++){
		if(arrc[j]=='F')  b=1;
	}
	if(a==1&&b==1)  printf("Yes\n");
	else  printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
const int N = 2e5+5;
int main()
{
	sync;
	ll x, n;
	cin >> x  >> n;
	map<int, int> mp;
	for(int i = 0; i < n; i++)
	{
		ll k; cin >> k;
		mp[k]++;
	}
	for(ll i = 0; i < 105; i++)
	{
		if(mp[x - i] == 0)
			return cout << x - i, 0;
		if(mp[x + i] == 0)
			return cout << x + i, 0;   
	}
}

Measured memory_bytes: 3648
n,m=map(int, input().split())
contrys = sorted([{"i":i, "city":list(map(int, input().split()))} for i in range(m)], key=lambda x:x["city"])

i=1
prefecture=1
for c in contrys:
    if prefecture != c["city"][0]:
        i=1
    c.setdefault("id", str(c["city"][0]).zfill(6)+str(i).zfill(6))
    prefecture=c["city"][0]
    i+=1

for c in sorted(contrys, key=lambda x: x["i"]):
    print(c["id"])


Measured memory_bytes: 69012
#include <stdio.h>
//#include <string.h>

int main() {
    char op;
    int a, b, val;

    while (1) {
        scanf("%d %c %d", &a, &op, &b);

        if (op == '?')
            break;

        if (op == '+')
            val = a + b;
        else if (op == '-')
            val = a - b;
        else if (op == '*')
            val = a * b;
        else
            val = a / b;

        printf("%d\n", val);
    }

    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
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; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << "NO" << endl;return 0
#define MM <<" "<<
#define Endl endl


signed main(void){
    int N;
    string S[114514];
    string T;
    int R[26]={};
    cin >> N;
    REP(i,N){
        REP(j,26){R[j]=0;}
        cin >> T;
        REP(j,T.size()){
            R[T[j]-'a']++;
        }
        REP(j,26){
            REP(k,R[j]){
                S[i].push_back(j+'a');
            }
        }
    }
    sort(S,S+N);
    //REP(i,N){cout << S[i] << endl;}
    int now=0;
    int Ans=0;
    REP(i,N-1){
        if(S[i]==S[i+1]){
            now++;
        }else{
            Ans+=(now)*(now+1)/2;
            now=0;
        }
        //cout << now MM Ans<< endl;
    }
    Ans+=(now)*(now+1)/2;
    //cout << now MM Ans<< endl;
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 7424
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

struct edge{
	int to;
	int cost;
};

int main(void)
{
	//変数の宣言
	int n;
	int dp[30];
	int memo[30];
	struct edge e;
	vector<edge> graph[30];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	ll int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	int ok,ng;
	int r;


	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);

/*	for(i=0;i<n;i++){
//		scanf("%d",&a[i]);
		scanf_s("%d",&a[i]);
	}*/


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	i=0;
	while(n>0){
		dp[i]=n%2;
		n=n/2;
		i++;
	}

	len=i;

	for(i=0;i<20;i++){
		memo[i]=dp[i];
	}
	for(i=0;i<20;i++){
		dp[i]=memo[len-i-1];
	}

	temp=(1<<(len-1));
	for(i=1;i<len;i++){
		e.to=i;
		e.cost=0;
		graph[i-1].push_back(e);
		sum++;

		e.cost=(1<<(len-i-1));
		graph[i-1].push_back(e);
		sum++;

		if(dp[i]==1){
			e.to=i;
			e.cost=temp;
			graph[0].push_back(e);
			sum++;
			temp=temp+(1<<(len-i-1));
		}
	}

	


	//	printf("計算部分終了\n");

	//出力

	printf("%d %d\n",len,sum);

	for(i=0;i<len;i++){
		for(j=0;j<graph[i].size();j++){
			e=graph[i][j];
			printf("%d %d %d\n",i+1,e.to+1,e.cost);
		}
	}

	//printf("%d",d[0]);


	//	printf("結果の出力終了\n");


	return 0;
}



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

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	string b;
	cin >> b;
	int len = b.length();

	int count = 0, ans = 0;
	FOR(i, len) {
		if (b[i] == 'A' || b[i] == 'T' || b[i] == 'C' || b[i] == 'G')count++;
		else {
			ans = max(ans, count);
			count = 0;
		}
	}
	ans = max(ans, count);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $N);
$A = trim(fgets(STDIN));
$A = explode(' ', $A);
/*
function median ($i1, $i2, $i3) {
	if ($i1 <= $i2 && $i2 <= $i3) {
		return $i2;
	} else if ($i1 <= $i3 && $i3 <= $i2) {
		return $i3;
	} else {
		return $i1;
	}
}

function _next($arr) {
	$result = [];
	for ($i = 0; $i < count($arr) - 2; $i++) {
		$result[] = median($arr[$i], $arr[$i+1], $arr[$i+2]);
	}
	return $result;
}

while (--$N) {
	$A = _next($A);
}
echo $A[0] . PHP_EOL;
*/
/*
$N = 3;
$A = [];
for ($i = 0; $i < 2 * $N - 1; $i++){
	$A[] = $i + 1;
}
*/
$l = 1;
$h = 2 * $N - 1;
while ($l + 1 < $h) {
	$m = floor(($l + $h) / 2);
	$b = [];
	for ($i = 0; $i < 2 * $N - 1; $i++) {
		$b[] = ($A[$i] >= $m) ? 1 : 0;
	}
	$c = $b[0];
	for ($i = 0; $i < $N - 1; $i++) {
		if ($b[$N - $i - 1] === $b[$N - $i - 2]) {
			$c = $b[$N - $i - 1];
			break;
		}
		if ($b[$N + $i - 1] === $b[$N + $i]) {
			$c = $b[$N + $i - 1];
			break;
		}
	}
	if ($c === 1) {
		$l = $m;
	} else {
		$h = $m;
	}
}
echo $l . PHP_EOL;


Measured memory_bytes: 69136
def power(a, b):
	if b == 0:
		return 1
	elif b == 1:
		return a % 1000000007
	elif b % 2 == 0:
		return (power(a, b//2) ** 2) % 1000000007
	else:
		return (power(a, b//2) ** 2 * a) % 1000000007
 
def divide(a, b):
	return (a * power(b, 1000000005)) % 1000000007

N = int(input())

fac_lim = N
fac = [None]*(fac_lim+1)
fac[0] = 1
for i in range(fac_lim):
    fac[i+1] = fac[i] * (i+1)
    fac[i+1] = fac[i + 1] % 1000000007

fs = [0] * (N+1)
fs[1] = fac[N]
for i in range(1,N):
    fs[i+1] = fs[i] + divide(fs[1], i+1)
    fs[i+1] %= 1000000007

A = [int(i) for i in input().split()]

ans = 0
for i in range(N):
    ans += (fs[i+1] + fs[N-i] - fs[1]) * A[i]
    ans %= 1000000007
print(ans)

Measured memory_bytes: 22656
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
string S;

int main() {
  cin >> S;
  if (S == "abc" || S == "acb" || S == "bac" || S == "bca" || S == "cab" ||
      S == "cba") {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};

#define lim 104

ll a[lim];


bool ok(ll i,ll j,ll k){
    if(a[i]!=a[j] and a[j]!=a[k] and a[k]!=a[i]){
        if(a[i]+a[j]>a[k] and a[i]+a[k]>a[j] and a[j]+a[k]>a[i]) return 1;
        else return 0;
    }
    else{
        return 0;
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout); 
    ll n;
    sfl(n);
    FOR(i,n){
        sfl(a[i]);
    } 
    ll cnt=0;
    for(ll i=1;i<=n;i++){
        for(ll j=i+1;j<=n;j++){
            for(ll k=j+1;k<=n;k++){
                if(ok(i,j,k)) cnt++;
            }
        }
    }
    pfl(cnt);
}

Measured memory_bytes: 3796
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 100005;
typedef long long i64;

int N, Q, top;
i64 q[MAX_N], st[MAX_N], sum[MAX_N], val[MAX_N];

int main() {
  scanf("%d%d", &N, &Q);
  
  st[++top] = N;
  for (int i = 1; i <= Q; ++i) {
    scanf("%lld", &q[i]);
    while (top > 0 && st[top] >= q[i]) 
      top--;
    st[++top] = q[i];
  }

  val[top] = 1;
  for (int i = top; i; --i) {
    i64 temp = st[i];
    int pos = i;
    while (true) {
      pos = lower_bound(st + 1, st + pos + 1, temp) - st - 1;
      if (pos == 0) break;
      val[pos] += val[i] * (temp / st[pos]);
      temp %= st[pos];
    }
    sum[temp] += val[i];
  }

  for (int i = N; i; --i) 
    sum[i] += sum[i + 1];
  for (int i = 1; i <= N; ++i)
    printf("%lld\n", sum[i]);
  
  return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);


int main(){
  long double a,b,c;
  cin >> a >> b >> c;
  long double num=c-a-b;
  if(2*sqrt(a*b)<num)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    
}


Measured memory_bytes: 256
def LI():
    return list(map(int, input().split()))


N = int(input())
A = LI()
total = sum(A)
ans = 0
mod = pow(10, 9)+7
for i in range(N-1):
    total -= A[i]
    ans = (ans+total*A[i]) % mod
print(ans)


Measured memory_bytes: 31444
[N, X, Y] = list(map(int, input().split()))

miner = [0] * (N - 1)

for i in range(1, N + 1):
    for j in range(i + 1,N + 1):
        normal = j - i
        shortcut = abs(i - X) + abs(j - Y) + 1
        miner[min(normal, shortcut) - 1] += 1

for i in range(len(miner)):
    print(miner[i])


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

using namespace std;

int main(void){
    int n, k, q;
    cin >> n >> k >> q;
    
    vector<int> participants(n,k-q);
    
    for (int i = 0; i < q; i++){
        int a;
        cin >> a;
        a--;
        participants[a]++;
    }
    
    for (int i = 0; i < n; i++){
        if (participants[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    
}



Measured memory_bytes: 1024
from collections import deque

H,W = map(int,input().split())
CH,CW = map(int,input().split())
CH-=1
CW-=1
DH,DW = map(int,input().split())
DH-=1
DW-=1
S = [0]*H
hoge = 0
for i in range(H):
    S[i] = [-1]*W
    hoge = input()
    for j in range(W):
        if hoge[j] == ".":
            S[i][j] = 10000000

DDD = [0]*25
dddd = 0
for dx in (-2,-1,0,1,2):
    for dy in (-2,-1,0,1,2):
        DDD[dddd] = (dx,dy,dx * dx + dy * dy)
        dddd += 1

D = deque()
D.append((CH,CW,0))
S[CH][CW] = 0
while len(D):
    X,Y,DD = D.pop()
    for dx,dy,a in DDD:
        XX = X + dx
        YY = Y + dy
        if a == 0 or not(0<=XX<H) or not(0<=YY<W) or S[XX][YY] == -1:
            continue
        elif a == 1 and S[XX][YY] > DD:
            D.append((XX,YY,DD))
            S[XX][YY] = DD
        elif S[XX][YY] > DD + 1:
            D.appendleft((XX,YY,DD+1))
            S[XX][YY] = DD + 1

print(-1 if S[DH][DW] == 10000000 else S[DH][DW])

Measured memory_bytes: 88128
import numpy as np
h, w, k, *s = open(0).read().split()
count, t = 1, np.array([list(s[i]) for i in range(int(h))], dtype=np.object)
for i, j in zip(*np.where(t=='#')):
    t[i][j], count = count, count+1
t = np.where(t=='.', 0, t)
ufill = np.frompyfunc(lambda a, b: a if b == 0 else b, 2, 1)
t = ufill.accumulate(t, dtype=np.object, axis=1)
t = ufill.accumulate(t[:,::-1], dtype=np.object, axis=1)[:,::-1]
t = ufill.accumulate(t, dtype=np.object, axis=0)
t = ufill.accumulate(t[::-1,:], dtype=np.object, axis=0)[::-1,:]
for i in range(int(h)):
    print(*t[i])

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    ll W, H; cin >> W >> H;
    ll x, y; cin >> x >> y;
    cout << (double)W*H/2 << " ";
    if(2*x == W && 2*y == H) cout << 1 << endl;
    else cout << 0 << endl;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    int ans=0;
    rep(i,n-1){
        if(a[i]<a[i+1]){
            ans++;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define ll long long

#define INF 999999999

using namespace std;

// input
int x,t;

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

    cin >> x >> t;
    
    if(x-t < 0){
        cout << 0 << "\n";
    }
    else{
        cout << x-t << "\n";
    }
}

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

int main(){
    int a,b,c,x ;
    cin >> a >> b >> c >> x ;
    int cnt = 0 ;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            if(x-i*500-j*100>=0&&(x-i*500-j*100)/50<=c) cnt++ ;
        }
    }
    cout << cnt << endl ;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main()
{
    map<string,int>a;
    int m,n;
    cin>>m;
    string x,y;
    for(int i=0;i<m;i++){
        cin>>x;
        a[x]++;
    }
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>y;
        a[y]--;
    }
    map<string,int>::iterator it;
    int k=0;
    for(it=a.begin();it!=a.end();it++){
        if((*it).second>k){
            k=(*it).second;
        }
    }
    if(k>0){
        cout<<k<<endl;
    }
    else{
        cout<<0<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(a,b,c) for(register int a=b;a<=c;++a)
using namespace std;
typedef long long ll;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	int ma=-999;
	if(a+b>ma)ma=a+b;
	if(a-b>ma)ma=a-b;
	if(a*b>ma)ma=a*b;
	cout<<ma;




}

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

typedef long long ll;
#define re(n) cin >> n
#define all(a) a.begin(),a.end()
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define te(t) ll t; re(t); while(t--)

int main(){
	ll n;
	re(n);
	string s;
	re(s);
	if(n%2==0){
		bool done = true;
		for(ll i=0;i<n/2;i++){
			if(s[i]!=s[i+(n/2)]){
				done = false;
			}
		}
		if(done){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n,l;
ll mem;
ll ans = INF;
ll y;

int main(){
  cin >> n >> l;
  for(ll i = 1;i <= n;i++){
    mem += l+i-1;
  }
  for(ll i = 1;i <= n;i++){
    ll x = abs(mem-(mem-(l+i-1)));
    if(x < ans){
      ans = x;
      y = (mem-(l+i-1));

    }
  }
  cout << y << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;

int n;
ll res[100005];
pair<int,int> A[100005];

int main() {
	#ifdef kvutxdy
	freopen("C:/Users/khanh/OneDrive/RoadtoPurple/Code/Codeforces/input.in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>A[i].fi;
		A[i].se=i;
	}
	sort(A+1,A+n+1,[](const pair<int,int>& L, const pair<int,int>& R){
		return L.fi!=R.fi?L.fi<R.fi:L.se<R.se;
	});
	int mn=n+1;
	for(int i=n;i>=1;--i){
		mn=min(mn,A[i].se);
		res[mn]+=1LL*(A[i].fi-A[i-1].fi)*(n-i+1);
	}
	for(int i=1;i<=n;++i) cout<<res[i]<<'\n';
}

Measured memory_bytes: 2688
import java.util.Scanner;

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

		int k =sc.nextInt();
	int x=sc.nextInt();
int min=Math.max(-1000000,x-k+1);
int max=Math.min(x+k-1, 1000000);

for(int i=min;i<=max;i++){
	System.out.print(i);
	if(i!=max){
		System.out.print(" ");
	}
}

	}
}

Measured memory_bytes: 21972
from collections import defaultdict
l = defaultdict(list)

n = int(input())


for i in range(n):
    s,p = input().split()
    l[s].append((i+1, int(p)))

for k in sorted(l.keys()):
    for i in sorted(l[k], key=lambda t: t[1], reverse=True):
        print(i[0])

Measured memory_bytes: 3444
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, Q;
ll sum, cnt[int(1e5 + 5)];

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++){
    ll A; scanf("%lld", &A);
    sum += A; cnt[A]++;
  }

  scanf("%d", &Q);
  for (int i = 0; i < Q; i++){
    ll B, C; scanf("%lld%lld", &B, &C);
    sum -= B * cnt[B];
    sum += C * cnt[B];
    cnt[C] += cnt[B]; cnt[B] = 0;
    printf("%lld\n", sum);
  }

  return 0;
}


Measured memory_bytes: 4544
#include <iostream>
using namespace std;
int main(){
    int n,i,j,k,b,f,r,v;
    int count[5][4][11];
    for(i=1;i<=4;i++)
        for(j=1;j<=3;j++)
            for(k=1;k<=10;k++)count[i][j][k]=0;
    
    cin >> n;
    for(i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        count[b][f][r] += v;
    }
    for(f=1;f<=4;f++){
        if(f>1){cout << "####################\n";}
        for(b=1;b<=3;b++){
            for(r=1;r<=10;r++){
                cout << " " << count[f][b][r];
            }
            cout << endl;
        }
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
ll n,h[100000+1],k;
ll dp[100000+1];
ll mo(ll x){
  if(x>0) return x;
  else return -x;
}
ll cal(int i){
  if(i>=n) return 0;
  if(dp[i]!=-1) return dp[i];
  ll res=mo(h[i]-h[i+1])+cal(i+1);
  for(int j=i+2; j<=i+k && j<=n; j++)
    res=min(res,mo(h[i]-h[j])+cal(j));
  return dp[i]=res;
}
int main() {
  memset(dp,-1,sizeof dp);
  cin>>n>>k;
  for(int i=1; i<=n; i++){
    cin>>h[i];
  }
  ll ans = cal(1);
  cout<<ans<<endl;
}

Measured memory_bytes: 6528
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func nextFloat64() (float64, error) {
	return strconv.ParseFloat(nextString(), 64)
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		h, _ := nextInt()
		w, _ := nextInt()

		if h == 0 || w == 0 {
			break
		}

		rectStr := ""
		for i := 0; i < h; i++ {
			rectStr += strings.Repeat("#", w) + "\n"
		}
		fmt.Println(rectStr)
	}
}



Measured memory_bytes: 5556
n = int(input())

ans = 0
a = 0
for i in range(n):
    c = int(input())
    ans += (a+c)//2
    if c == 0:
        a = 0
    elif (a+c)%2 == 1:
        a = 1
    else:
        a = 0
print(ans)

Measured memory_bytes: 3060
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

diff = [v[i] - c[i] for i in range(n)]
diff.sort(reverse=True)
M = 0
for i in range(n):
  if diff[i] > 0:
    M+=diff[i]
print(M)

Measured memory_bytes: 3060
// In The Namw Of Allah
#include <bits/stdc++.h>
using namespace std;

typedef pair <int, int> pii;
typedef long long ll;

const int N = 5e5 + 10, mod = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int r;
	cin >> r;
	cout << r * r << "\n";
}

Measured memory_bytes: 256
n,m = map(int,input().split())
par = [i for i in range(n+1)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) 
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[max(x,y)] = min(x,y)



for _ in range(m):
    a,b=map(int,input().split())
    unite(a,b)

tag=[0 for i in range(n+1)]
for i in range(1,n+1):
    tag[find(i)]=1
print(sum(tag)-1)

Measured memory_bytes: 81584
#include<stdio.h>
#define N 100
#define INF 1000000
int g[N][N],n,d[N];

void sssp(void){//全ての点の最短経路を求める
  int i,j,judge[n],min,u;
  for(i=0;i<n;i++){
    d[i]=INF;
    judge[i]=1;//1は未訪問　0は探索中　-1は探索終了
  }
  d[0]=0;

  while(1){
    min=INF;
    for(i=0;i<n;i++){
      if(judge[i]!=-1&&d[i]<min){
                min=d[i];
                u=i;
      }
    }
      if(min==INF)break;
      judge[u]=-1;

    for(i=0;i<n;i++){
      if(judge[i]!=-1&&g[u][i]!=-1){
        if(g[u][i]+d[u]<d[i]){
          d[i]=g[u][i]+d[u];
          judge[i]=0;
        }
      }
    }
  }
}



int main(){
  int i,j,k,l,v,num;


  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
        g[i][j]=-1;
    }
}

    for(j=0;j<n;j++){
      scanf("%d%d",&num,&k);
      for(l=0;l<k;l++){
          scanf("%d",&v);
          scanf("%d",&g[num][v]);
      }
    }
  
  sssp();
  for(i=0;i<n;i++){
      printf("%d %d\n",i,d[i]);
  }
  return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  int sum = 0;
  vector<int> v;
  rep(i,N){
    v.push_back(L+i);
    sum += L+i;
  }

  int ret = 1000000000;
  int ret_s = -1;
  
  rep(i,N){
    int s = 0;
    rep(j,N){
      if(i==j) continue;
      s += v[j];
    }
    //cout << s << "\t" << abs(sum-s) << endl;
    if(ret > abs(sum-s)){
      ret = abs(sum-s);
      ret_s = s;
    }
  }

  cout << ret_s << endl;
  
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"

using namespace std;
#define INF (1LL<<60)
#define int long long
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i, n)  FOR(i,0,(n))


class CForbiddenList {
public:
    void solve(std::istream &in, std::ostream &out) {
      int x, n;
      in >> x >> n;
      vector<int> p(n);
      REP(i, n) in >> p[i];
      sort(p.begin(), p.end());
      int min = INF;
      int ans = x;
      REP(i, 200) {
        bool f = true;
        REP(j, n) {
          f &= i != p[j];
        }
        if (f && min > abs(x - i)) {
          min = x - i;
          ans = i;
        }
      }
      out << ans << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  CForbiddenList solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3644
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int tap = 0;
    int ans = 0;
    int a,b;
    cin >> a;
    cin >> b;
    if(b !=1){
        ans = ((b-1)-1) / (a-1) +1;
    }else{
        ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
    ans=[]
    for j in range(m):
        ans.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    print(ans.index(min(ans))+1)

Measured memory_bytes: 3064
#ref: https://atcoder.jp/contests/agc033/submissions/5260580

import sys
import numpy as np

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    INF = H * W
    dp = [[INF if c == '.' else 0 for c in input().strip()] for _ in range(H)]
    dp = np.array(dp)

    for i in range(1, H):
        dp[i, :] = np.minimum(dp[i, :], dp[i-1, :] + 1)

    for i in range(H-2, -1, -1):
        dp[i, :] = np.minimum(dp[i, :], dp[i+1, :] + 1)

    for i in range(1, W):
        dp[:, i] = np.minimum(dp[:, i], dp[:, i-1] + 1)

    for i in range(W-2, -1, -1):
        dp[:, i] = np.minimum(dp[:, i], dp[:, i+1] + 1)

    return np.max(dp)

if __name__ == '__main__':
    print(main())


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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

int main() {
	int n;
	cin >> n;
	int a = n,res = 0;
	while (a) {
		res += a % 10;
		a = a / 10;
	}
	if (n%res == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

int main() {
  int n;
  double x, y, theta;

  cout.setf(ios::fixed);
  while (1) {
    cin >> n;
    if (n==-1) break;
    x = 1.0;
    y = 0.0;
    for (int i=1; i<n; i++) {
      theta = atan2(y, x);
      x -= sin(theta);
      y += cos(theta);
    }
    cout << setprecision(2) << x << endl;
    cout << setprecision(2) << y << endl;
  }
}

Measured memory_bytes: 1320
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
#define PI 3.14159265358979323846
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int X,Y,Z;
int A[100005],B[100005],C[100005];
vector<P1> AB;
int N;
int sum_x,sum_y,sum_z;

priority_queue< P1,vector<P1>,greater<P1> > Left;
priority_queue< P1,vector<P1>,greater<P1> > Right;
int dp_x[100005],dp_y[100005],dp_z[100005];


void solve(){
    for(int i=0;i<N;++i)dp_x[i]=dp_y[i]=-INF;
    //左側
    for(int i=0;i<N;++i){
        int it = AB[i].second;
        sum_y+=(B[it]-C[it]);
        //cout<<B[it]-C[it]<<endl;
        Left.push(P1(B[it]-C[it],it));
        if(Left.size()>Y){
            sum_y-=Left.top().first;
            Left.pop();
        }
        if(Left.size()==Y){
            dp_y[i]=sum_y;
            //cout<<sum_y<<" "<<sum_z_l<<" "<<i<<endl;
        }
        //cout<<sum_y<<endl;
    }

    //右側 ※逆からやる
    for(int i=N-1;i>=0;--i){
        int it = AB[i].second;
        //cout<<A[it]-C[it]<<endl;
        sum_x+=(A[it]-C[it]);
        Right.push(P1(A[it]-C[it],it));
        if(Right.size()>X){
            sum_x-=Right.top().first;
            Right.pop();
        }
        if(Right.size()==X){
            dp_x[i]=sum_x;
            //cout<<sum_x<<" "<<sum_z_r<<" "<<i<<endl;
        }
    }
}

signed main(){
    cin>>X>>Y>>Z;
    N = X+Y+Z;
    for(int i=0;i<N;++i){
        cin>>A[i]>>B[i]>>C[i];
        AB.PB(P1(A[i]-B[i],i));
        sum_z+=C[i];
    }
    sort(AB.begin(),AB.end());
    solve();
    int ans=-INF;
    for(int i=0;i<N-1;++i){
        ans=max(ans,dp_x[i+1]+dp_y[i]+sum_z);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9200
#include<iostream>                                        
#include<string>                                          
using namespace std;                                      
                                                          
int main(){                                               
  string word1;                                           
  cin >> word1;                                           
  string word2;                                           
  int cnt = 0;                                            
                                                          
  for(int i=0;i<word1.size();i++){                        
    word1[i] = tolower(word1[i]);                         
  }                                                       
                                                          
  while(1){                                               
    cin >> word2;                                         
    if(word2 == "END_OF_TEXT") break;                     
    for(int i=0;i<word2.size();i++){                      
      word2[i] = tolower(word2[i]);                       
    }                                                     
    if(word1 == word2) cnt++;                             
  }                                                       
                                                          
  cout << cnt<< endl;                                     
                                                          
  return 0;                                               
} 

Measured memory_bytes: 3220
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;




int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int taka = (a + d - 1) / d, ao = (c + b - 1) / b;
    if (taka < ao)cout << "No" << endl;
    else
    {
        cout << "Yes" << endl;
    }


    return 0;
}




Measured memory_bytes: 3632