akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n,x;
  cin >> n >> x;
  vi po(n);
  REP(i,n) {
    int p;
    cin >> p;
    po[i]=abs(p-x);
  }
  int ans=po[0];
  REP(i,n-1) {
    ans=euclidean_gcd(ans,po[i+1]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rap(i,first,last) for(int i=first;i<=last;++i)
using namespace std;
const int maxN=2333333;
const int INF=114514233;
int N;
int arr[maxN];
bool boo[maxN];
bool check(int middle)
{
	rap(i,1,N*2-1)
	boo[i]=(arr[i]>=middle);
	int len1=INF,len0=INF;
	rap(i,1,N*2-2)
	if(boo[i]==boo[i+1])
	{
		if(boo[i])
		len1=min(len1,min(abs(N-i),abs(N-i-1)));
		else
		len0=min(len0,min(abs(N-i),abs(N-i-1)));
	}
	if(len1!=INF||len0!=INF)return len1<len0;
	return (N&1)==boo[N];
}
int main()
{
	scanf("%d",&N);
	rap(i,1,N*2-1)scanf("%d",&arr[i]);
	int l=-1,r=N*2,mid,answer=-1;
	while(l<=r)
	{
		mid=(l+r)/2;
		if(check(mid))
		{
			answer=mid;
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	printf("%d",answer);
	return 0;
}

Measured memory_bytes: 2432
n=int(input())
ans='No'
if n<4:
  ans='No'
elif n%4==0 or n%7==0 or n%11==0:
  ans='Yes'
else:
  while 0<n:
    if n%7==0:
      ans='Yes'
      break
    n-=4
print(ans)

Measured memory_bytes: 3060
#define loop(i, s, e) for(ll i = s;i < e;i++)

#include <iostream>
#include <iomanip>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

typedef long long signed ll;

template <typename T>
class Vector2D {
public:
    T x;
    T y;
    Vector2D(){
        x = y = 0;
    }
    Vector2D(T x_,T y_){
        x = x_;
        y = y_;
    }
    T operator*(const Vector2D<T> *e) {
        return this->x * e->x + this->y * e->y;
    }
    Vector2D<T> operator-(const Vector2D<T> *e) {
        return Vector2D<T>(this->x - e->x ,this->y - e->y);
    }
    Vector2D<T> operator+(const Vector2D<T> *e) {
        return Vector2D<T>(this->x + e->x ,this->y + e->y);
    }
    T operator*(const Vector2D<T> e) {
        return this->x * e.x + this->y * e.y;
    }
    Vector2D<T> operator-(const Vector2D<T> e) {
        return Vector2D<T>(this->x - e.x ,this->y - e.y);
    }
    Vector2D<T> operator+(const Vector2D<T> e) {
        return Vector2D<T>(this->x + e.x ,this->y + e.y);
    }
    Vector2D<T> operator*(const T r) {
        return Vector2D<T>(this->x * r ,this->y * r);
    }
    Vector2D<T> operator/(const T r) {
        return Vector2D<T>(this->x / r ,this->y / r);
    }
    double abs(){
        return sqrt(x*x+y*y);
    }
    T abs2(){
        return x*x+y*y;
    }
};

int main() {
    int x,y,q;
    Vector2D<double> base,p,pp,t;
    cin >> x >> y;
    base = Vector2D<double>(x,y);
    cin >> x >> y >> q;
    p = Vector2D<double>(x,y) - base;
    loop(i,0,q){
        cin >> x >> y;
        t = p * ((p * (Vector2D<double>(x,y) - base)) / p.abs2()) + base;
        cout << setprecision(16) << t.x << " " << t.y << endl;
    }
}




Measured memory_bytes: 3276
let rec pow_mod x y m =
  if y = 0 then 1 
  else let z = pow_mod (x*x mod m) (y / 2) m in if y mod 2 = 1 then x*z mod m else z
  
let prime_p n =
  if n == 2 then true
  else if n < 2 || n mod 2 = 0 then false
  else if pow_mod 2 (n - 1) n = 1 then true
  else false
  
let () =
  let n = read_int () in
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (acc + (if prime_p (read_int ()) then 1 else 0))
  in Printf.printf "%d\n" (doit 0 0)

Measured memory_bytes: 2864
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
long long a,b,c,d,e,ans;
int main(){
	ans=1111111111;
	cin>>a>>b>>c>>d>>e;
    ans=min(ans,a*d+b*e);
    ans=min(ans,max(d,e)*c*2);
    if(d>e){
    	ans=min(ans,e*c*2+(d-e)*a);
	}
	else ans=min(ans,d*c*2+(e-d)*b);
	cout<<ans<<endl;
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
main(){
    fastio;
    int n;
    cin >> n;
    cout << n * n * n << endl;
}   

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <math.h>
#include <cstring>

using namespace std;

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)

#define INF 		2000000007
#define MOD			998244353

#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int ll;



int main(void) {
	int n;cin>>n;
	vector<int> a(n);
	REP(i,n)cin>>a[i];

	int ans = 0;

	int cnt = 1;
	REPS(i,1,n){
		if(a[i-1]==a[i])cnt++;
		else{
			ans += cnt/2;
			cnt=1;
		}
	}
	ans += cnt/2;

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif




#define int long long
#define rng(i,l,r) for(size_t i=(l);i<(r);++i)
#define rep(i,n) rng(i,0,n)
#define gnr(i,l,r) for(size_t i=(r)-1;i>=(l);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()   //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend()//...,3,2,1

using namespace std;
//using ll = long long;


const int MOD = 1000000007;
const int INF = 1e18;

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

const double pi = acos(-1);



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


using Graph = vector<vector<int>>;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//*max_element(ALL(vector))
//count(ALL(vector),num) -> n



void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    int x,y; cin >> x >> y;
    cout << gcd(x,y) << endl;
    
    
    
    
    
    
    
}





signed main() {
    solve();
    return 0;
}




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

int main() {

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

    int N; cin >> N;
    string S; cin >> S;

    long long seen[N][3];

    for (int i = N-1; i >= 0; --i) {
        if (i == N-1) {seen[i][0] = 0; seen[i][1] = 0; seen[i][2] = 0;}
        else {seen[i][0] = seen[i+1][0]; seen[i][1] = seen[i+1][1]; seen[i][2] = seen[i+1][2];}
        if (S[i] == 'R') seen[i][0] += 1;
        if (S[i] == 'G') seen[i][1] += 1;
        if (S[i] == 'B') seen[i][2] += 1;
    }

    long long comb = 0;

    for (int i = 0; i < N-2; ++i) {
        for (int j = i + 1; j < N-1; ++j) {
            if (S[i] != S[j]) {
                if (j+j-i < N && S[j+j-i] != S[i] && S[j+j-i] != S[j]) --comb;
                bool is0 = true, is1 = true, is2 = true;

                if (S[i] == 'R' || S[j] == 'R') is0 = false;
                if (S[i] == 'G' || S[j] == 'G') is1 = false;
                if (S[i] == 'B' || S[j] == 'B') is2 = false;

                if (is0) comb += seen[j+1][0];
                else if (is1) comb += seen[j+1][1];
                else if (is2) comb += seen[j+1][2];
            }

        }
    }

    cout << comb << endl;

}

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

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

const int N=1e5+5;

int n,m,cnt0,cnt1,head[N],col[N],ans,cnt;
struct nood
{
	int nex,to;
};
nood e[N<<1];

inline void jia(int u,int v)
{
	e[++cnt].nex=head[u];
	head[u]=cnt;
	e[cnt].to=v;
}

inline void dfs(int u,int fa,int co)
{
	if(!col[u]) col[u]=co;
	else 
	{
		if(co!=col[u])
		{
			printf("%lld\n",n*(n-1)/2-m);
			exit(0);
		}
		return;
	}
	
	for ( int i=head[u];i;i=e[i].nex )
	{
		int v=e[i].to;
		if(v==fa) continue;
		dfs(v,u,co^1);
	}
}

signed main()
{
	n=read();
	m=read();
	for ( int i=1;i<=m;i++ )
	{
		int u,v;
		u=read();
		v=read();
		jia(u,v);
		jia(v,u);
	}
	dfs(1,0,1);
	for ( int i=1;i<=n;i++ ) (col[i])?cnt1++:cnt0++;
	printf("%lld\n",cnt1*cnt0-m);
	return 0;
}

Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

		int x = a / 100;
		int y = (a - x * 100) / 10;
		int z = (a - x * 100 - y * 10);

		if(x == z) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <cmath>
#include <typeinfo>


using namespace std;

//  ||
// \


/*void sort(int arr[], int n) {
	int tmp = 0;
	for(int i = 0; i < n-1; i++) {
		tmp = i;
		for(int j = i+1; j < n; j++) {
			if(arr[j] < arr[tmp]) {
				tmp = j;
				swap(arr[tmp], arr[i]);
			}
		}
	}
}*/

int main() {
	int a = 0, b = 0, t = 0;
	cin >> a >> b >> t;
	int x = 0;
	x = t / a;
	cout << x*b << endl;


    return 0;
}

Measured memory_bytes: 256
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [a, b, h, m]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    return `${Math.sqrt(a*a + b*b - 2 * a * b * Math.cos(2 * Math.PI * (h / 12 + m / 12 / 60) - 2 * Math.PI * m / 60))}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 29752
#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#define  pb push_back
#define  xx first
#define  yy second
#define PI acos(-1)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define NL printf("\n")
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;


int dp[102][1002];
int inf  = 100000009;
int N,M;
int a[101][101];
int solve(int n, int m){

        if(n>=N || m>=M){
            return inf;
        }

        if(dp[n][m]!=-1) return dp[n][m];

        dp[n][m]=min(solve(n-1,m) , solve(n,m-1))+a[n][m];
        return dp[n][m];
}
int sum[101][101];

int main()
{
      //fast;
     int t=1;
    // cin >> t;

    while(t--)
    {
      int n,m,ans = 0;
       string s;
       cin >> s;
       n = s.size();
       string st = "";
       string s2 = s;
       reverse(s2.begin(),s2.end());
       int cnt = 0;
       if(s==s2) cnt++;

       for(int i = 0,j = 1; i<n; i++,j++){
         st+=s[i];
         if(j==(n-1)/2){
            string tmp = st;
            reverse(tmp.begin(),tmp.end());
            if(tmp==st) cnt++;

         }
       }
       if(cnt==2){
        cout <<"Yes" << endl;
       }
       else cout << "No" << endl;
    }

    return 0;
}


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



int main ()
{

int n; scanf("%d",&n); vector<int> h(n);
vector<int> dp(n,1e9+5);dp[0]=0;
for(int& x:h)
	scanf("%d",&x);
for(int i=0;i<n;i++)
{for(int j:{i+1,i+2}){
if(j<n)dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));}
}
printf("%d\n",dp[n-1]);		

}



Measured memory_bytes: 4052
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
const int maxn = 200000;
int h[maxn];
int dp[maxn];
int n;
const int inf = 2000000000;
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 0;i < n;++i)cin >> h[i];
	fill(dp+1, dp+n, inf);
	for(int i = 0;i < n;++i)dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1])), dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
	cout << dp[n-1] << '\n';
}

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

int main() {
    string S;
    int count = 0;
    cin >> S;

    if(S.size() <= 1){
        count = 0;
    }else{
        for(int i = 1; i < S.size(); i++){
            if(S[i] == S[i-1]){
                count++;
                if(S[i-1] == '0') S[i] = '1';
                else S[i] = '0';
            }
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 512
val = list(map(int, input().split()))
val.sort()


cnt = 0

while val[1] < val[2]:
    val[1] += 1
    val[0] += 1
    cnt += 1
while val[0] < val[2]:
    val[0] += 2
    cnt += 1
if val[0] > val[2]:
    val[1] += 1
    val[2] += 1
    cnt += 1
print(cnt)

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

int main(){
    int n;
    cin >> n;
    int p[n];
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(p[i] - 1 == i){
            swap(p[i], p[i + 1]);
            ans++;
        }
    }

    cout << ans << endl;
}

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

int main() {
  int n, i;
  cin >> n;
  
  vector<int> a(n), b(n), c(n);
  for(i = 0; i < n; i++){
    cin >> a.at(i) >> b.at(i) >> c.at(i);
  }
  
  int x[n][3];
  x[0][0] = a.at(0);
  x[0][1] = b.at(0);
  x[0][2] = c.at(0);
  for(i = 1; i < n; i++){
    x[i][0] = max(x[i - 1][1], x[i - 1][2]) + a.at(i);
    x[i][1] = max(x[i - 1][2], x[i - 1][0]) + b.at(i);
    x[i][2] = max(x[i - 1][0], x[i - 1][1]) + c.at(i);
  }
  
  cout << max({x[n - 1][0], x[n - 1][1], x[n - 1][2]}) << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m,T;
  cin >> n >> m >> T;
  ll c[n];
  mem(c);
  rep(i,T) {
    int x;
    R x;
    c[x-1]++;
  }
  rep(i,n) {
    if(m-(T-c[i])<=0) pr("No");
    else pr("Yes");
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1408
def 解():
    iN = int(input())
    iD = 10**9 + 7

    if iN < 3:
        print(iN)
        exit()

    i上限 = int(iN**0.5)+1
    a篩 = [1]*(iN+1)
    d素={}
    for i in range(2,iN+1):
        if a篩[i]:
            b素 = 1
            for i素 in d素:
                if i % i素 == 0:
                    b素=0
                    break
            if b素:
                d素[i] = 1
                for j in range(i,iN+1,i):
                    a篩[j] = 0
                    
    for i in range(2,iN+1):
        for i素 in d素:
            while i % i素 == 0:
                d素[i素]+=1
                i //= i素
    iAns = 1
    for i素 in d素:
        iAns *= d素[i素]
        iAns %= iD
    print(iAns)
解()



Measured memory_bytes: 3064
#include <iostream>
#include <stack>
#include <queue>
#include <fstream>
using namespace std;

int main(){
  //std::ifstream in("input.txt");
  //std::cin.rdbuf(in.rdbuf());
  int ans[1024] = {0};
  int dataCounter = 0;
  int i = 0;
  while(1){
    int visited[20][20] = {0};
    int data[20][20];
    int x,y;
    int w = 0;
    int h = 0;
    queue<int> xst;
    queue<int> yst;
    cin >> w;
    cin >> h;
    if(w == 0 && h == 0) break;
    for(i=0;i<h;i++){
      int inputCounter = 0;
      char d;
      while(cin >> d){
        if(d == '.')
          data[i][inputCounter] = 0;
        else if(d == '#')
          data[i][inputCounter] = 1;
        else if(d == '@'){
          data[i][inputCounter] = 2;
          x = inputCounter;
          y = i;
        }
        if(inputCounter == w-1)break;
        inputCounter++;
      }
    }
    int j=0;
    xst.push(x);
    yst.push(y);
    while(!xst.empty()){
      x = xst.front();
      y = yst.front();
      xst.pop();
      yst.pop();
      if(x < 0 || w <= x || y < 0 || h <= y)continue;
      if(visited[y][x]==1 || data[y][x] == 1)continue;
      visited[y][x] = 1;
      ans[dataCounter]++;
      xst.push(x+1);
      yst.push(y);
      xst.push(x);
      yst.push(y+1);
      xst.push(x-1);
      yst.push(y);
      xst.push(x);
      yst.push(y-1);
    }

    dataCounter++;
  }
  for(i=0;i<dataCounter;i++){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string O, E, S;

	cin >> O >> E;

	int j, k;
	j = k = 0;
	for (int i = 0;i < (O.size() + E.size());i++)
	{
		if (i % 2 == 0)
		{
			S.push_back(O[j]);
			j++;
		}
		else
		{
			S.push_back(E[k]);
			k++;
		}
	}

	cout << S << endl;

	return 0;
}


Measured memory_bytes: 256
n,k,q = list(map(int, input().split()))
a = [int(input()) for i in range(q)]
pnt = [k]*n
for i in range(q):
    pnt[a[i]-1]+=1
for i in range(n):
    pnt[i]-=q
for i in range(n):
    if pnt[i]<=0:
        print('No')
    else:
        print('Yes')

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

int main(){
	int n, min = 1000, max = 0;
	cin >> n;
	int a;
	for(int i = 0; i < n; i++){
		cin >> a;
		if(min > a){
			min = a;
		}
		if(max < a){
			max = a;
		}
	}
	cout << max - min << endl;
}

Measured memory_bytes: 256
n,k  = gets.split.map(&:to_i)
h = []
result = 1000000000
n.times do |i|
  h[i] = gets.to_i
end
h.sort!
(n-k+1).times do |i|
  result = h[i+k-1]-h[i] if result > h[i+k-1]-h[i]
end
puts result

Measured memory_bytes: 4036
/*___________Bismillahir Rahmanir Rahim__________*/
//Think positive, be positive and never use negative words
#include<bits/stdc++.h>
#define RON              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll               long long int
#define test             ll t;cin>>t;while(t--)
#define v_sum(a)         accumulate(a.begin(),a.end(),0)
#define v_max(a)         *max_element(a.begin(),a.end())
#define v_min(a)         *min_element(a.begin(),a.end())
#define v_uni(a)         a.erase(unique(a.begin(),a.end()),a.end())
#define yes              cout<<"YES"<<endl
#define no               cout<<"NO"<<endl
#define gcd(a,b)         __gcd(a,b)
#define lcm(a,b)         (a/gcd(a,b))*b
using namespace std;
int main()
{
    RON;
    ll n, x, t;
    cin>>n>>x>>t;
    ll ans=(n+x-1)/x;
    cout<<ans*t<<endl;
    return 0;
}
/*_________________Alhamdulillah_________________*/


Measured memory_bytes: 3648
import scala.io.StdIn.readInt

object Main {
  def sieve(n:Int) = {
    val primes = Array.tabulate(n+1) { _ % 2 }
    primes(1) = 0
    primes(2) = 1

    for( i <- 3 to Math.sqrt(n).toInt by 2 )
      if(primes(i) == 1)
        (i*i to n by i*2).foreach { primes(_) = 0 }
    primes
  }

  def main(args:Array[String]) = {
    val p = sieve(50000)
    var n = 0
    while( { n = readInt; n} != 0 ) {
      var cnt = 0
      if(p(n-2) == 1) cnt = 1
      else if(n%2==0) {
        for(i<- 3 to n/2 by 2)
          if(p(i) ==1 && p(n-i) ==1)
            cnt += 1
      }
      println(cnt)
    }
  }
}

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

#define ll long long

ll k,n,a[1000005],ans=0x7fffffff;
ll sum[1000005];

int main()
{
	scanf("%lld%lld",&k,&n);
	
	for (int i=1 ; i<=n ; i++)
	    scanf("%lld",&a[i]);
	
	ans=min(ans,a[n]-a[1]);
	
	for (int i=1 ; i<=n ; i++)
	{
		ans=min(ans,a[i]-a[1]+a[1]+k-a[n]+a[n]-a[i+1]);
	}
	
	printf("%d\n",ans);
	return 0;
 } 

Measured memory_bytes: 4224
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int a,b,c;
int ans;

main(){
	cin>>a>>b>>c;
	int m=a+b;
	dump(min(m+b+1,b+c));
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int kMaxValue = 10 * 1000;

int main() {
    int n; cin >> n;
    vector<int> w(n, 0), s(n, 0), v(n, 0);

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

    vector<vector<int64_t>> dp(n + 1, vector<int64_t> (2 * kMaxValue + 1, 0));

    vector<int> perm(n, 0);
    for (int i = 0; i < n; i += 1)
        perm[i] = i;

    sort(perm.begin(), perm.end(), [&] (int a, int b) {
        return w[a] + s[a] < w[b] + s[b];
    });
    
    for (int i = 0; i < n; i += 1)
        for (int j = 0; j <= 2 * kMaxValue; j += 1) {
            if (j <= s[perm[i]] and j + w[perm[i]] <= 2 * kMaxValue)
                dp[i + 1][j + w[perm[i]]] = max(dp[i + 1][j + w[perm[i]]], dp[i][j] + v[perm[i]]);
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }

    cout << *max_element(dp[n].begin(), dp[n].end());
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cerr << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int N, L;
	scanf("%d %d", &N, &L);

	deque<pair<int, double>> deq;

	int sum = 0.0;
	double hsum = 0.0;

	rep(i, N) {
		int t, v;
		scanf("%d %d", &t, &v);
		deq.push_front(mp(v, (double)t * v));
		sum += v;
		hsum += (double)t * v;

		double ans = -1.0;

		while (sum >= L) {
			auto p = deq.back();
			deq.pop_back();

			sum -= p.fi;
			hsum -= p.se;

			if (sum < L) {
				int d = L - sum;
				double nx = p.se * d / p.fi;
				sum += d;
				hsum += nx;
				ans = hsum / L;
				deq.eb(d, nx);
				break;
			}
		}

		printf("%.10f\n", ans);
		
		while (deq.size() >= 2) {
			int sz = deq.size();
			auto p = deq[0], q = deq[1];
			if (p.se / p.fi < q.se / q.fi) {
				deq.pop_front(); deq.pop_front();
				auto t = mp(p.fi + q.fi, p.se + q.se);
				deq.push_front(t);
			} else {
				break;
			}
		}

		while (sum > L) {
			auto p = deq.back(); deq.pop_back();
			sum -= p.fi;
			hsum -= p.se;
			if (sum < L) {
				int d = L - sum;
				double nx = p.se / p.fi * d;
				deq.eb(d, nx);
				sum += d;
				hsum += nx;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 18708
# include "stdio.h"

int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    double sum=0;
    for(int i=0;i<n;i++)
        sum+=((double)1/a[i]);
  
    sum=(double)1/sum;

    printf("%lf\n",sum);


}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,m,t;
int main(){
	scanf("%d",&n);
	int flag=0;
	while(n){
		int t=n%10;
		if(t==9){
			flag=1;
			break;
		}
		n/=10;
	}
	if(flag==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c,x,y,ans;
int main()
{
	cin>>n;ans=n;
	for(int i=0;i<=n;i++)
	{
		x=i;
		while(x)
		{
			c+=x%9;
			x=x/9;
		}
		y=n-i;
		while(y)
		{
			c+=y%6;
			y=y/6;	
		}
		if(c<ans)ans=c;
		c=0;
	}
	cout<<ans;
	return 0;
}

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

int main(){
  int n, aud;
  cin >> n;
  for (int i = 0; i < n; i++){
    int l, r;
    cin >> l >> r;
    aud += (r - l) + 1;
  }
  cout << aud << endl;
}
      

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (n, m, k) = readLine()!!.split(" ").map { it.toInt() }
  val uf = UnionFind(n)
  val ex = IntArray(n)
  repeat(m) {
    val (a, b) = readLine()!!.split(" ").map{ it.toInt()-1 }
    uf.unite(a, b)
    ex[a]++
    ex[b]++
  }
  repeat(k) {
    val (c, d) = readLine()!!.split(" ").map{ it.toInt()-1 }
    if (uf.same(c, d)) {
      ex[c]++
      ex[d]++
    }
  }
  println((0 until n).map { uf.size(it) - ex[it] - 1 }.joinToString(" "))
}

class UnionFind(private val n: Int) {
  private val parent = IntArray(n) { it }
  private val rank = IntArray(n)
  private val size = IntArray(n) { 1 }
  
  fun find(i: Int): Int {
    if (parent[i] != i) parent[i] = find(parent[i])
    return parent[i]
  }
  
  fun same(i: Int, j: Int) = find(i) == find(j)
  
  fun unite(i: Int, j: Int) {
    val x = find(i)
    val y = find(j)
    if (x == y) return
    if (rank[x] < rank[y]) {
      parent[x] = y
      size[y] += size[x]
    } else {
      parent[y] = x
      size[x] += size[y]
      if (rank[x] == rank[y]) rank[x]++
    }
  }
  
  fun size(i: Int) = size[find(i)]
}

Measured memory_bytes: 75716
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int flag=0;
	int len=s.length();
	for(int i=0;i<len;i++)
	{
		if(s[i]!=t[i])
		{
			flag=1;
			break;
		}
	}
	if(flag)	cout<<"No"<<endl;
	else	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
template<typename T> T factorial(T n){
    if(n==1) return 1;
    else return n*factorial(n-1)%MOD;
}
template<typename T> T Pow(T x, T n, T m){
    if(n == 0) return 1;
    if(n % 2 == 0) return Pow(x * x % m, n / 2, m);
    else return x * Pow(x, n - 1, m) % m;
}
template<typename T> T combination(T n, T k, T m){
    return factorial<T>(n) * Pow<T>(factorial(k), m-2, m) % m * Pow<T>(factorial(n-k), m-2, m) % m;
}
struct edge{
    int to; // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using graph = vector<vector<edge>>;
using Graph = vector<vector<int>>;

int main(){
    ll n, k; cin >> n >> k;
    ll candidate1 = n % k;
    ll candidate2 = k - candidate1;
    if(candidate2 >= 0) cout << min(candidate1, candidate2) << endl;
    else cout << candidate1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) 1e9
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	ll n, W;
	cin>>n>>W;
	ll w[n], v[n];
	for(ll i=0 ;i<n ;i++){
		cin>>w[i]>>v[i];
	}
	vector<vector<ll>>dp(n+1, vector<ll>(W+1, 0));
	for(ll i=0; i<=n; i++){
		for(ll j=0; j<=W; j++){
			if(i==0 || w==0) dp[i][j]=0;
			else if(w[i-1]<=j) dp[i][j] = max(v[i-1] + dp[i-1][j-w[i-1]], dp[i-1][j]);
			else dp[i][j] = dp[i-1][j];
		}
	}
	cout<<dp[n][W];
}

Measured memory_bytes: 80256
#include <stdio.h>

int main(void){
    int A,B;
    scanf("%d %d",&A,&B);
    if(A+B>=A-B){
        if(A+B>=A*B) printf("%d\n",A+B);
        else printf("%d\n",A*B);
    }
    else{
        if(A-B>=A*B) printf("%d\n",A-B);
        else printf("%d\n",A*B);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N);
    REP(i, N)
        cin >> a[i];
    ll ans = 0;
    REP(i, N)
    {
        if (i % 2 == 0 && a[i] % 2 == 1)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#  stack

lst = input().split()

stack = []
for arg in lst:

    if arg == "+":
        tmp = int(stack.pop())
        stack.append(int(stack.pop()) + tmp)
    elif arg == "-":
        tmp = int(stack.pop())
        stack.append(int(stack.pop()) - tmp)
    elif arg == "*":
        tmp = int(stack.pop())
        stack.append(int(stack.pop()) * tmp)
    else:
        stack.append(int(arg))

print(stack[0])


Measured memory_bytes: 5600
#include <iostream>
#include<vector>
#include<algorithm>
#include <cmath>
#include<iomanip>
using namespace std;

int main() {
	double A, B, H, M;
	cin >> A >> B >> H >> M;
	double AX, AY, BX, BY, AK, BK, K, KK, ans;
	K = M / 60;
	KK = H + K;
	AK = (KK / 12) * 2 * 3.1415926535897932384626433832795028841971693993751058209749445923078164;//短針の角度
	BK = (M / 60) * 2 * 3.1415926535897932384626433832795028841971693993751058209749445923078164;//長針の角度
	AX = A * cos(AK);//短針のＸ座標
	AY = A * sin(AK);//短針のＹ座標
	BX = B * cos(BK);//長針のＸ座標
	BY = B * sin(BK);//長針のＹ座標
	ans = sqrt((AX - BX) * (AX - BX) + (AY - BY) * (AY - BY));
	cout << fixed<<setprecision(20)<<ans << endl;
}

Measured memory_bytes: 4096
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
int n, in[26], out[26], G[26][26];
bool visited[26];
bool check(){
	rep(i, 26) if ( in[i] != out[i] ) return false;
	return true;
}
void dfs(int u){
	visited[u] = true;
	rep(v, 26) if ( !visited[v] && G[u][v] ) dfs(v);
}
int getNComponent(){
	int nc = 0;
	rep(i, 26){
		if ( in[i] == 0 && out[i] == 0 ) continue;
		if ( !visited[i] ){ nc++; dfs(i); }
	}
	return nc;
}
int main(){
	while( cin >> n && n ){
		rep(i, 26){
			in[i] = out[i] = 0;
			visited[i] = false;
			rep(j, 26) G[i][j] = 0;
		}
		string str;
		rep(i, n){
			cin >> str;
			in[str[0]-'a']++;
			out[str[str.size()-1]-'a']++;
			G[str[0]-'a'][str[str.size()-1]-'a'] = 1;
			G[str[str.size()-1]-'a'][str[0]-'a'] = 1;
		}
		cout << (( check() && getNComponent() == 1 )?"OK":"NG") << endl;
	}
	return 0;
}

Measured memory_bytes: 912
n = int(input())
list = list(map(int, input().split()))
list_odd = list[::2]
list_even = list[1::2]


def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v, k) for k, v in dict.items()]


cnt_odd = sorted(cnt_element(list_odd), reverse=True)
cnt_even = sorted(cnt_element(list_even), reverse=True)

if cnt_odd[0][1] == cnt_even[0][1]:
    if len(cnt_odd) == 1 or len(cnt_even) == 1:
        ans = int(n / 2)
    else:
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        else:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]
else:
    ans = n - cnt_odd[0][0] - cnt_even[0][0]

print(ans)

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

w_cnt = 0
w_list = []
b_cnt = 0
b_list = []
for i in range(N):
    if S[i] == '#':
        w_cnt += 1
        w_list.append(w_cnt)
    else:
        w_list.append(w_cnt)

    if S[N-1-i] == '.':
        b_cnt += 1
        b_list.append(b_cnt)
    else:
        b_list.append(b_cnt)



ans = N
for i in range(N):
    wa = w_list[i] + b_list[N-2-i]
    if ans > wa:
        ans = wa


if b_list[N-1] < ans:
    ans = b_list[N-1]

if w_list[N-1] < ans:
    ans = w_list[N-1]

print(ans)


Measured memory_bytes: 13040
//#pragma comment(linker, "/STACK:102400000,102400000") 
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)

const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }

int n, k1, k2;
int fa[maxn][2];

int getfa(int x,int k)
{
	return x == fa[x][k] ? x : fa[x][k] = getfa(fa[x][k], k);
}

void uni(int x, int y,int k)
{
	x = getfa(x,k);
	y = getfa(y,k);
	if (x == y)return;
	fa[x][k] = y;
}

map<pair<int, int>, int>hax;

void solve()
{
	sa(n), sa(k1), sa(k2);
	repp(i, 1, n)
	{
		fa[i][0] = i;
		fa[i][1] = i;
	}
	repp(i, 1, k1)
	{
		int x, y;
		sa(x), sa(y);
		uni(x, y, 0);

	}
	repp(i, 1, k2)
	{
		int x, y;
		sa(x), sa(y);
		uni(x, y, 1);
	}
	repp(i, 1, n)
	{
		hax[mp(getfa(i, 0), getfa(i, 1))]++;
	}
	repp(i, 1, n)
	{
		if (i > 1)
		{
			printf(" ");
		}
		printf("%d", hax[mp(getfa(i, 0), getfa(i, 1))]);
	}
	printf("\n");
}

int main()
{
	//ios_base::sync_with_stdio(false);
	solve();
	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

int pow_(int a,int b) {
    int ret=1;
    REP(i,b) ret*=a;
    return ret;
}
int calc1(int k,int l,int r) {
    int all=k*(r-l);
    int F=(r-1)/3-(l-1)/3;
    int B=(r-1)/5-(l-1)/5;
    int FB=(r-1)/15-(l-1)/15;
    int ret=all-(F+B)*k+(F+B)*4+FB*k;
    return ret;
}
int calc2(int n) {
    int ret=0;
    string N=to_string(n);
    REPF(i,1,SZ(N)) {
        ret+=calc1(i,pow_(10,i-1),pow_(10,i));
    }
    ret+=calc1(SZ(N),pow_(10,SZ(N)-1),n+1);
    return ret;
}
signed main() {
    int s;
    cin>>s;
    int l=0, r=1e18;
    int beg=0;
    while(r-l>1) {
        int m=(l+r)/2;
        if(calc2(m)>=s) {
            beg=m;
            r=m;
        }
        else {
            l=m;
        }
    }
    string str;
    REPF(i,beg,beg+40) {
        if(SZ(str)>40) {
            break;
        }
        if(i%15==0) str+="FizzBuzz";
        else if(i%3==0) str+="Fizz";
        else if(i%5==0) str+="Buzz";
        else str+=to_string(i);
    }
    cout<<str.substr(s-calc2(beg-1)-1,20)<<endl;
    return 0;
}

Measured memory_bytes: 3244
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(false);

	ll a, b, c,n, k;
	string s,t;
	vi v(3);
	rep(i,3)
	cin >> v[i];
	sort(all(v));
	cout << (v[2] - v[1]) + (v[1] - v[0]) << endl;
	//cin >> s >> t;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();
        int N, M;
        {int[] a = r.ii(); N = a[0]; M = a[1];}
        long[] x = new long[N],
               y = new long[N],
               z = new long[N];
               
        for(int i = 0; i < N; i++){
            long[] a = r.ll();
            x[i] = a[0];
            y[i] = a[1];
            z[i] = a[2];
        }
        
        long max = 0;
        for(int i = 0; i < 8; i++){
            String sign = String.format("%03d", Integer.parseInt(Integer.toBinaryString(i)));             
            int xs = sign.charAt(0) == '0' ? 1 : -1,
                ys = sign.charAt(1) == '0' ? 1 : -1,
                zs = sign.charAt(2) == '0' ? 1 : -1; 
                
            long[] w = new long[N];
            for(int j = 0; j < N; j++)
                w[j] += x[j]*xs + y[j]*ys + z[j]*zs;
            
            Arrays.sort(w);
            long sum = 0;
            for(int j = 0; j < M; j++)
                sum += w[N-1-j];
            
            if(max < sum)
                max = sum;
        }
        print(max);        
    }

    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int Int(String s){
            return Integer.parseInt(s);
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }

        long Long(String s){
            return Long.parseLong(s);
        }

        long l() throws IOException{
            return Long(s());
        }

        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 22996
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXN = 1 << 18;
const int MOD = 1; // 1000 * 1000 * 1000 + 7;
const int INF = 2e9;
const double PI = acos(-1.0);

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	int n, x;
	while (cin >> n >> x) {
		vector<int> a(n);
		for (int i = 0; i < n; i++) cin >> a[i];

		int m = 51 * 51;
		vector<vector<ll> > dp(n + 1, vector<ll>(m));
		dp[0][0] = 1;
		for (int i = 0; i < n; i++) {
			vector<vector<ll> > ndp(n + 1, vector<ll>(m));
			for (int j = 0; j <= i; j++) {
				for (int sum = 0; sum <= j * 50; sum++) {
					if (!dp[j][sum]) continue;
					ndp[j][sum] += dp[j][sum];
					ndp[j + 1][sum + a[i]] += dp[j][sum];
				}
			}
			dp = ndp;
		}
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= i * 50; j++) {
				if (j == i * x) {
					ans += dp[i][j];
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

#define INF 1<<29

typedef pair<int,int>P;
typedef pair<int,P>PP;
typedef struct{
  int cost,to;
}Edge;

int g[101][2];

priority_queue<PP,vector<PP>, greater<PP> >que;

int main(){
  int n,m;
  int a,b,c;
  int ans;
  while(cin>>n>>m,n|m){
    ans=0;
    {
      vector<Edge> D[101];
      for(int i=0;i<101;i++){
	for(int j=0;j<2;j++){
	  g[i][j]=INF;
	}
      }
      
      for(int i=0;i<m;i++){
	cin>>a>>b>>c;
	a--;b--;
	D[a].push_back((Edge){c,b});
	D[b].push_back((Edge){c,a});
      }
      g[0][1]=0;
      if(n<=2)que.push(PP(0,P(0,0)));
      else que.push(PP(0,P(0,1)));
      while(!que.empty()){
	PP p=que.top();que.pop();
	int co=p.first;
	int cket=p.second.second;
	int now=p.second.first;
	if(cket){
	  for(int i=0;i<D[now].size();i++){
	    for(int j=0;j<D[D[now][i].to].size();j++){
	      if(g[D[D[now][i].to][j].to][cket-1]>co){
		g[D[D[now][i].to][j].to][cket-1]=co;
		que.push(PP(g[D[D[now][i].to][j].to][cket-1],P(D[D[now][i].to][j].to,0)));
	      }
	    }
	  }
	}
	for(int i=0;i<D[now].size();i++){
	  if(g[D[now][i].to][cket]>co+D[now][i].cost){
	    g[D[now][i].to][cket]=co+D[now][i].cost;
	    que.push(PP(g[D[now][i].to][cket],P(D[now][i].to,cket)));
	  }
	}
      }
      
      ans=min(g[n-1][0],g[n-1][1]);
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 1228