akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
#include <vector>
#include <algorithm> // sort
#include <map>
using namespace std;

using ll = long long int;
using ppi=pair<ll,ll>;
using pql =priority_queue<ll, vector<ll>, greater<ll>>;
using pq=priority_queue<ll>;

int main(){
    string s;
    cin>>s;
    if(s.at(2)==s.at(3)){
        if(s.at(4)==s.at(5)){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> red(a), green(b), cless(c);
    for(int i=0;i<a;i++) cin >> red[i];
    for(int i=0;i<b;i++) cin >> green[i];
    for(int i=0;i<c;i++) cin >> cless[i];
    sort(all(red), greater<int>());
    sort(all(green), greater<int>());
    sort(all(cless), greater<int>());
    vector<int> fnl(x+y);
    for(int i=0;i<x;i++) fnl[i] = red[i];
    for(int i=0;i<y;i++) fnl[i+x] = green[i];
    sort(all(fnl), greater<int>());
    int l = 0, r = 0,ans = 0;
    while(l+r < x+y and r < c)
    {
        if(fnl[l] > cless[r])
        {
            ans += fnl[l];
            l++;
        }
        else
        {
            ans += cless[r];
            r++;
        }
    }
    for(int i=l;i+r < x+y;i++)
        ans += fnl[i];
    cout << ans << "\n";
    return 0;
}



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

int main(){
	string s;
	cin >> s;
	int large = 0;
	int numc = 0;
	for(char c: s){
		if('A'<=c and c<='Z') large++;
	}
	for(int i=2; i<s.length()-1; i++){
		if(s[i]=='C') numc++;
	}
	if(s[0]=='A' and numc==1 and large==2) cout << "AC" << endl;
	else cout << "WA" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename V> typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V> typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	string S;
	cin >> N >> S;
	int cur = 0;
	int r = 0, l = 0;
	REP(i, N) {
		if (S[i] == '(') {
			cur++;
			l++;
		}
		else {
			cur = max(cur - 1, 0);
			r++;
		}
	}
	REP(i, cur) {
		S.push_back(')');
	}
	if (cur + r > l) {
		REP(i, cur + r - l) {
			cout << '(';
		}
	}
	REP(i, SZ(S)) {
		cout << S[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int[] nums = new int[3];

		int iMax = 0;
		for (int i = 0; i < nums.length; i++) {
			nums[i] = sc.nextInt();
			if (nums[iMax] < nums[i]) {
				iMax = i;
			}
		}

		int sum = 0;
		for (int i = 0; i < nums.length; i++) {
			sum += i == iMax ? nums[iMax] * 10 : nums[i];
		}

		System.out.println(sum);

		sc.close();

	}
}



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

int main()
{
    int n,m,k,ans=0;
    cin>>n>>m>>k;
    for(int i=0;i<m;i++)
    {
        int x;
        cin>>x;
        if(x<k)
            ++ans;
    }
    cout<<min(ans,m-ans);;
    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n, p;
    cin >> n >> p;
    ll m = 0;
    if(n == 1){
        m = p;
    }else{
        for(ll i = 1; pow(i, n) <= p; ++i){
            if(p%(ll)pow(i, n) == 0) m = max(m, i);
        }
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_s.to_i
s = gets.chomp

def left(s, i, c)
  i.times do |j|
    return true if s[j] == c
  end
  false
end

def right(s, i, c)
  i.upto(s.size - 1) do |j|
    return true if s[j] == c
  end
  false
end

ans = 0
n.times do |i|
  cnt = 0
  (?a..?z).to_a.each do |c|
    cnt += 1 if right(s,i,c) && left(s,i,c)
  end
  ans = cnt if ans < cnt
end

puts ans

Measured memory_bytes: 14344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main(){
    int n;
    cin>>n;
    map<string,int> m;
    string s[n];
    REP(i,n){
        cin>>s[i];

    }
    int sum=1;
    sort(s,s+n);
    REP(i,n-1){
        if (s[i]!=s[i+1])
        {
            /* code */
            sum++;
        }
        
    }
    cout<<sum<<endl;
    
}

Measured memory_bytes: 9880
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  ll X,K,D;
  cin >> X >> K >> D;
  X=abs(X);
  if(X/D>=K){
    cout << X-K*D << endl;
  }else{
    ll ans1=X%D;
    ll ans2=X%D-D;
    if((K-X/D)%2==0){
      cout << abs(ans1) << endl;
    }else{
      cout << abs(ans2) << endl;
    }
  }
}

Measured memory_bytes: 3592
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=10000000000000LL;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,Ma,Mb,K=1,C[45];
ll A[45],B[45];
ll T,a,b;
ll ans=0;
bool h,o;
//bool D[100005];
string str,str2[55][55];
map<string,int> m;
vector<int> v[10];
ll dp[45][405][405];
int main(){
	cin>>N;
	ans=(N/11)*2;
	if(N%11>6)ans++;
	if(N%11>0)ans++;
	cout<<ans<<endl;
	return 0;
}


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

void printArray(int a[], int n) {
  std::cout << a[0];
  for (int i = 1; i < n; i++) {
    std::cout << " " << a[i];
  }
  std::cout << std::endl;
}

void insertionSort(int a[], int n) {
  for (int i = 1; i < n; i++) {
    int v = a[i];
    int j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;
    printArray(a, n);
  }
}

int main() {
  int n;
  std::cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  printArray(a, n);
  insertionSort(a, n);
}


Measured memory_bytes: 3116
N, Q = map(int, input().split())

nodes = [0 for _ in range(N)]

parents = {}
for _ in range(N-1):
  a, b = map(int, input().split())
  parents[b] = a

for _ in range(Q):
  p, x = map(int, input().split())
  nodes[p-1] += x

for i in range(N):
  if i+1 in parents:
    nodes[i] += nodes[parents[i+1]-1]

print(" ".join(map(str, nodes)))

Measured memory_bytes: 55292
#include <iostream>
#include <string>
#include <bitset>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;

map<ll, ll> prime_factor(ll n)
{
}

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

    ll ans = 0;
    if (n % 2 == 0)
    {
        n /= 2;
        while (n / 5 > 0)
        {
            ans += n / 5;
            n /= 5;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    string s,t; cin >> s >> t;
    vector<int> v1(26,-1),v2(26,-1);
    int n = s.size();
    bool ok = true;
    rep(i,n){
        if(v1[s[i]-'a'] == -1) v1[s[i]-'a'] = t[i]-'a';
        else{
            if(v1[s[i]-'a'] != t[i]-'a') ok = false;
        }
        if(v2[t[i]-'a'] == -1) v2[t[i]-'a'] = s[i]-'a';
        else{
            if(v2[t[i]-'a'] != s[i]-'a') ok = false;
        }
    }
    cout << (ok?"Yes":"No") << endl;
}

Measured memory_bytes: 776
#include<iostream>
#include <math.h>
using namespace std;
int main() {
    int N,D;
    cin >> N >> D;
    int X[N],Y[N];
    int count = 0;
    for (int i=0;i<N;i++) {
      cin >> X[i];
      cin >> Y[i];
      if (pow(pow(X[i], 2)+pow(Y[i], 2), 0.5) <= D) {
        count++;
      }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 5852
#include<stdio.h>
int main()
{
    int len1,len2,i,j=0;
    char a[100000];
    char b[100000];
    while (gets(a))
    {
        gets(b);
        len1=strlen(a);
        len2=strlen(b);
        if(len1>len2)
        {

            for (i=0; i<len1; i++)
            {
                if (i<len2)
                {

                    printf("%c",a[i]);
                    printf("%c",b[i]);
                }
                else
                    printf("%c",a[i]);
            }
        }
        else  if(len2>len1)
        {

            for (i=0; i<len2; i++)
            {
                if(i<len1)
                {
                    printf("%c",a[i]);
                    printf("%c",b[i]);
                }
                else
                {
                    printf("%c",b[i]);
                }
            }
        }
        else
        {

            for (i=0; i<len1; i++)
            {
                printf("%c",a[i]);
                printf("%c",b[i]);
            }
        }
        printf("\n");
    }
}


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

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

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

	const int s_len = (int)s.length(), t_len = (int)t.length();
	vector<vector<int>> dp(s_len + 1, vector<int>(t_len + 1));

	for (int i = 1; i <= s_len; i++) {
		for (int j = 1; j <= t_len; j++) {

			if (s[i - 1] == t[j - 1] && dp[i][j] < dp[i - 1][j - 1] + 1) dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

		}
	}
	
	string ans;
	int x = s_len, y = t_len;
	while (x > 0 && y > 0) {

		if (dp[x][y] == dp[x - 1][y]) x--;
		else if (dp[x][y] == dp[x][y - 1]) y--;
		else {
			ans.push_back(s[x - 1]);
			x--, y--;
		}
	}

	reverse(ans.begin(), ans.end());
	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 35584
#include<iostream>
using namespace std;
int main(){
	int N, D, X, A[100], i,ANS=0;
	cin >> N;
	scanf("%d %d", &D, &X);
	for (i = 0; i < N; i++){
		cin >> A[i];
	}
	for (i = 0; i < N; i++){
		if (D % A[i] == 0){
			ANS -= 1;
		}
		ANS += D/A[i];
		ANS += 1;
	}
	//ANS += 1 + D / A[2];
	cout << ANS+X<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}


int main(){
  stack<int> v[1000];
  int n,q;
  cin>>n>>q;
  lp(i,q){
    int a,b,c;
    cin>>a>>b;
    if(a==0){
      cin>>c;
      v[b].push(c);
    }
    if(a==1){
      if(v[b].empty()) 1; else
      cout<<v[b].top()<<endl;
    }
    if(a==2){
      if(v[b].empty()) 1; else
      v[b].pop();
    }
  }
  return 0;
}



Measured memory_bytes: 4244
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n;cin>>n;
  vector<double> v;
  REP(i,n){
    double t;
    cin>>t;
    v.pb(t);
  }

  VSORT(v);

  double ans = v[0];
  for(int i=1;i<v.size();i++){
    ans += v[i];
    ans /= 2.0;
  }

  cout<<setprecision(12)<<ans<<endl;



 

  return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
Sdictionary = {}
Tdictionary = {}
ans = "Yes"
for i in range(len(S)):
    if T[i] in Tdictionary:
        if Tdictionary[T[i]] == S[i]:
            continue
        else:
            ans = "No"
    else:
        Tdictionary[T[i]] = S[i]
    if S[i] in Sdictionary:
        if Sdictionary[S[i]] == T[i]:
            continue
        else:
            ans = "No"
    else:
        Sdictionary[S[i]] = T[i]


print(ans)


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

bool canbeMonth(string s) {
    int a, b;
    a = s[0] - '0';
    b = s[1] - '0';
    int n = a * 10 + b;
    return (n >= 1 && n <= 12);
}

int main() {
    string s;
    cin >> s;
    string s1 = s.substr(0, 2);
    string s0 = s.substr(2, 2);
    string ans;
    if (canbeMonth(s1)) {
        if (canbeMonth(s0)) {
            ans = "AMBIGUOUS";
        } else {
            ans = "MMYY";
        }
    } else {
        if (canbeMonth(s0)) {
            ans = "YYMM";
        } else {
            ans = "NA";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

// 逆元のmod MOD
ll rev_mod(ll num){
	ll pow_num = MOD - 2;
	ll mod_num = MOD;
	ll pow_cur = num;
	ll ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

ll dp[1005][10005];

int main(){
    ll h, n;
	cin >> h >> n;
	ll a[n], b[n];
	rep(i, n){
		cin >> a[i] >> b[i];
	}
	rep(i, n+1){
		rep(j, h+1){
			dp[i][j] = LLINF;
		}
	}

	// for (int j = 1; j <= h; j++)
	// {
	// 	dp[1][j] = (ll)ceil((double)j/a[0]);	
	// }
	for(int i=0;i<n;i++){
        for(int j=1;j<=h;j++){
            if(j <= a[i]){
                dp[i+1][j] = min(dp[i][j], b[i] * (ll)ceil((double)j/a[i]));
            }else{
                dp[i+1][j] = min(dp[i][j], dp[i+1][j-a[i]]+b[i]);

            }
        }
	}
	// rep(i, n+1){
	// 	rep(j, h+1){
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
    cout << dp[n][h] << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 78464
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??????????????????
?????????????????????????????´?????????????????????
????????§?????????????????????(S, H, C, D)??¨???????????°???(1, 2, ..., 9)??????
?§??????????????¨? 36 ????????????????????¨????????????
????????°??????????????? 8 ???"H8"??????????????? 1 ???"D1"??¨??¨????????????

????????????????????????????????????????????¢?????´??????????????¨?????????
??????????????? N ????????????????????????????????°???????????????
???????????´?????????????????°????????????????????????????????????
??¢?????´??????????????????????????\????????????????????????????????????????????¨????????????
??°??????????´???? 0 ??????????????§?¨???°?????????????????????

1 BubbleSort(C, N)
2   for i = 0 to N-1
3     for j = N-1 downto i+1
4       if C[j].value < C[j-1].value
5         C[j] ??¨ C[j-1] ?????????
6
7 SelectionSort(C, N)
8   for i = 0 to N-1
9     minj = i
10    for j = i to N-1
11      if C[j].value < C[minj].value
12        minj = j
13    C[i] ??¨ C[minj] ?????????

??????????????¢?????´?????????????????????????????????????????\??????????????????????????????????????£??????????????±????????????????????????

"""
import math

def swap(A, x, y):
    """ ??????A???x????????¨y?????????????´??????\???????????? """
    t = A[x]
    A[x] = A[y]
    A[y] = t

def value(c):
    """ ??????????????°?????¨???????????? """
    return int(c[1:])

def suits(A):
    """ ????????????????????????????????¨???????????????????????? """
    s = ""
    for c in A:
        s = s + c[0]
    return s

def bSort(A, N):
    """ ?????????????????? """
    for i in range(0, N-1):
        for j in range(N-1, i, -1):
            if value(A[j]) < value(A[j-1]):
                swap(A,j,j-1)

def sSort(A, N):
    """ ?????????????????? """
    for i in range(0, N-1):
        minj = i
        for j in range(i,N):
            if value(A[j]) < value(A[minj]):
                minj = j
        if minj != i:
            swap(A,i,minj)

# ?????????
N = int(input().strip())
A = input().strip().split()
bA = A[:]
bSort(bA,N)
b1 = suits(bA)
print(" ".join(map(str,bA)))
print("Stable")

sA = A[:]
sSort(sA,N)
s1 = suits(sA)
print(" ".join(map(str,sA)))
if s1 == b1:
    print("Stable")
else:
    print("Not stable")

Measured memory_bytes: 7908
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
int x,n;
int y;
for(;;){
scanf("%d %d",&n,&x);
y=0;
if(n==0&&x==0)break;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(x-i-j>j&&x-i-j<=n)y++;
}
}
printf("%d\n",y);
}
return 0;
}

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

#define nl '\n'
#define F fisrt
#define S second
#define pb push_back
#define mp make_pair
#define REP(i,a,b) for(int i = a; i < b; i++)
#define ForeachTC int t; cin >> t; while(t--)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef stack<int> si;
typedef deque<int> di;
typedef pair<int,int> pi;

const ll MOD = 100000000+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	//code here
	ll x;
	cin >> x;
	ll bal = 100LL;
	int counter = 0;
	while(bal < x){
		bal = (ll)bal*1.01;
		counter++;
	}
	cout << counter;
	return 0;
}


Measured memory_bytes: 3636
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split();
        long n = long.Parse(s[0]);
        long p = long.Parse(s[1]);

        if (n == 1)
        {
            Console.WriteLine(p);
            return;
        }

        long ans = 1;

        for (long i = (long)Math.Sqrt(p); 2 <= i; i--)
        {
            if (p % Math.Pow(i, n) == 0)
            {
                ans = i;
                break;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    double N, T, A;
    cin >> N >> T >> A;
    double d = 10000;
    double e = 0;
    double x;
    double gap;
    rep(i, N){
        cin >> x;
        gap = abs(T-A-0.006*x);
        if(d>gap){
            d = gap;
            e = i+1;
        }
    }
    cout << e;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 標準入力の取得
R, G, B, N = list(map(int, input().split()))


def main() -> None:
    """Entry point
    """
    # 求解処理
    """
    r, gをそれぞれ固定して探索を行う.
    """
    r_max = N // R
    g_max = N // G
    result = 0
    for r in range(r_max+1):
        n_r = r * R
        for g in range(g_max+1):
            n_rg = n_r + g * G
            # この時点でNよりも大きい場合、何もしない
            if N < n_rg:
                continue
            # Nまでの不足分がBで割り切れる場合、条件を満たしたことになる
            if (N - n_rg) % B == 0:
                result += 1

    # 結果出力
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int x, t;
    cin >> x >> t;
    if(t > x) cout << 0 << endl;
    else cout << x - t << endl;
    
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	static int n;

	static int[] v;

	static int[][] graph;

	static int[] d;
	static int[] f;

	static int time;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		n = Integer.parseInt(br.readLine());

		graph = new int[n][n];

		v = new int[n];

		d = new int[n];

		f = new int[n];

		for (int i = 0; i < n; i++) {
			String[] u_k_v = br.readLine().split(" ");

			int u = Integer.parseInt(u_k_v[0]);

			for (int k = 0; k < Integer.parseInt(u_k_v[1]); k++) {

				graph[u-1][Integer.parseInt(u_k_v[2+k]) - 1] = 1;

			}
		}
		time =1;
		for(int i=0; i<n-1;i++){
		     time = depth_search(i,time);
		}

/*
		  for(int i=0; i<n; i++){ for(int k=0; k <n; k++){
		  System.out.print(graph[i][k]);

		  } System.out.println(""); }
*/
	       for (int i=0; i<n; i++) {
	            StringBuilder sb = new StringBuilder();
	            sb.append((i+1)).append(" ").append(d[i]).append(" ").append(f[i]);
	            System.out.println(sb);
	        }
	}


	static int depth_search(int sx, int count){

        if (d[sx] != 0)
            return time;

		int j ;

		v[sx] =1;

		time = count;

		d[sx] = time++;

		for(j=0; j<n; j++){

			if(graph[sx][j] ==1 && v[j] !=1){
				depth_search(j, time);
			}

		}
		f[sx] = time++;

		return time;
	}

}

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

using namespace std;

#define TC ll t; cin >> t; while(t--)
typedef long long ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    bool isok=1;
    cin >> s;
    ll n=s.length(),l1,h1,l2,h2;
    l1=0; h1=(n-3)/2;
    l2=(n+1)/2; h2=n-1;
    while(l2<n && isok)
    {
        if(s[l1]!=s[h1] || s[l2]!=s[h2]) isok=0;
        l1++; h1--; l2++; h2--;
    }
    l1=0;
    while(l1<n && isok)
    {
        if(s[l1]!=s[n-l1-1]) isok=0;
        l1++;
    }
    if(!isok) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 3624
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math

N=int(input())
A=list(map(int,input().split()))

lst=A[:N]
_sum=sum(lst)
heapify(lst)

sumlstleft=[0 for i in range(N+1)]
sumlstleft[0]=_sum
for i in range(N,2*N):
    heappush(lst,A[i])
    a=heappop(lst)
    _sum+=A[i]-a
    sumlstleft[i-N+1]=_sum
lst=A[N*2:]
_sum=sum(lst)
lst=[-i for i in lst]
heapify(lst)
sumlstright=[0 for i in range(N+1)]
sumlstright[-1]=_sum
for i in range(2*N-1,N-1,-1):
    heappush(lst,-A[i])
    a=heappop(lst)
    _sum-=-a
    _sum+=A[i]
    sumlstright[i-N]=_sum
print(max([sumlstleft[i]-sumlstright[i] for i in range(N+1)]))


Measured memory_bytes: 121120
#include <iostream>

using namespace std;

long long modPow(long long a, long long p, long long mod){
    if(p == 0) return 1;
    auto res = modPow(a, p/2, mod);
    res = (res * res) % mod;
    if(p%2) res = (res * a) % mod;
    return res;
}

long long repMod(long long a, long long p, long long d, long long mod){
    if(p == 0) return 0;
    auto res = repMod(a, p/2, d, mod);
    res *= modPow(10, d*(p/2), mod) + 1;
    res %= mod;
    if(p%2){
        res = modPow(10, d, mod) * res + a;
        res %= mod;
    }
    return res;
}

long long calc(long long a, long long b, long long d, long long L, long long mod){
    if(L == 0) return 0;
    auto res = calc(a, b, d, L/2, mod);
    res *= modPow(10, d*(L/2), mod) + 1;
    res %= mod;
    res += repMod(L/2*b, L/2, d, mod);
    res %= mod;
    if(L%2){
        res = modPow(10, d, mod) * res + a + (L-1)*b;
        res %= mod;
    }
    return res;
}

int main(){
    long long L, A, B, M;
    while(cin >> L >> A >> B >> M){
        int d = 0; long long n10 = 1;
        while(n10 <= A){
            d++;
            n10 *= 10;
        }
        long long res = 0;
        while(L > 0){
            long long l = min(L, (n10 - A + B - 1) / B);
            res *= modPow(modPow(10, l, M), d, M);
            res %= M;
            res += calc(A, B, d, l, M);
            res %= M;
            A += B * l;
            L -= l;
            n10 *= 10;
            d++;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>

typedef long long LL;

using namespace std;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

int main(void) {
	LL n, a, b;
	cin >> n >> a >> b;
	if (a > b) {
		cout << 0;
		return 0;
	}
	if (n == 1 && a != b) {
		cout << 0;
		return 0;
	}
	if (n == 1 && a == b) {
		cout << 1;
		return 0;
	}
	if (n == 2) {
		cout << 1;
		return 0;
	}
	cout << (b - a)*(n - 2) + 1;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int e = sc.nextInt();
    int k = sc.nextInt();
    if(e-d>k||e-c>k||e-b>k||e-a>k||d-c>k||d-b>k||d-a>k||c-b>k||c-a>k||b-a>k){
      System.out.println(":(");
    }else{
      System.out.println("Yay!");
    }
 }
}

Measured memory_bytes: 21712
function Main(input){
var A = input.split(" ")[0];
var B = input.split(" ")[1];
A = parseInt(A,10);
B = parseInt(B,10);
var coin = 0;
for(i=0;i<=1;i++){
  if(A>=B){
    coin += A;
    A -= 1;
  }else{
    coin += B;
    B -= 1;
  }
}
console.log(coin);
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
from collections import defaultdict
from copy import copy
n = int(input())
a = [int(i) for i in input().split()]
count_a = defaultdict(int)
diff_a = [0] * n
for ai in a:
        count_a[ai] += 1

for i in range(n):
    diff_a[i] = (count_a[a[i]] - 1)

count = 0    
for v in count_a.values():
    count += v*(v - 1) // 2
for i in range(n):
    count_copy = copy(count)
    print(count_copy - diff_a[i])

Measured memory_bytes: 27112
#include <stdio.h>

int parent(int i){
	return i/2;
}

int left(int i){
	return 2*i;
}

int right(int i){
	return 2*i+1;
}

int main(){
	int H,i,A[251];
	scanf("%d",&H);
	for(i=1;i<=H;i++){
		scanf("%d",&A[i]);
	}
	for(i=1;i<=H;i++){
		printf("node %d: key = %d, ",i,A[i]);
		if(i>1)
			printf("parent key = %d, ",A[parent(i)]);
		if(left(i)<=H)
			printf("left key = %d, ",A[left(i)]);
		if(right(i)<=H)
			printf("right key = %d, ",A[right(i)]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2148
a,b,c=map(int,input().split())
n=a+b+c
if a%2==0 and a==b==c:
    print(-1)
elif not a%2==b%2==c%2==0:
    print(0)
else:
    cnt=0
    while(a%2==b%2==c%2==0):
        a=(n-a)//2
        b=(n-b)//2
        c=(n-c)//2
        cnt+=1
    print(cnt)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int i, x, n, p[105], j;
    scanf("%d %d", &x, &n);
    if(n==0)
    {
        printf("%d", x);
        return 0;
    }
    for(i=0; i<n; i++)
    {
        scanf("%d", &p[i]);
    }
    for(i=0; i<n+1; i++)
    {
        int a=0, b=0;
        for(j=0; j<n; j++)
        {
            if(x-i==p[j])
            {
                a++;
            }
            if(x+i==p[j])
            {
                b++;
            }
        }
        if(a<1)
        {
            printf("%d", x-i);
            return 0;
        }
        if(b<1)
        {
            printf("%d", x+i);
            return 0;
        }
    }
}

Measured memory_bytes: 1732
//
// ABC163A
// URL : https://atcoder.jp/contests/abc162/tasks/abc163_a
// 
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace AtCoder
{
    class ABC163A
    {
        static void Main(string[] args)
        {
            // 整数の入力
            long r = long.Parse(Console.ReadLine());

            var ans = r * 2.0 * Math.PI;

            Console.WriteLine(ans.ToString());
        }
    }
}



Measured memory_bytes: 27612
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif


deque<int> A, B;
int now;

void solve(ll n) {
	if (n==1) return;
	solve(n>>1);
	++now;
	A.push_front(now);
	B.push_front(now);
	if (n&1) {
		++now;
		A.push_front(now);
		B.push_back(now);
	}
}

int main() {
	ll n;
	cin>>n;
	solve(n+1);
	cout<<A.size()+B.size()<<endl;
	for (auto t:A) cout<<t<<' ';
	for (auto t:B) cout<<t<<' ';
	cout<<endl;
}








Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    VL X(N);
    REP(i,N) cin >> X[i];

    sort(X.begin(),X.end());
    int ans = -1;
    LL cost = LINF;
    FOR(i,1,101){
        LL tmp = 0;
        REP(j,N){
            tmp += (i-X[j])*(i-X[j]);
        }
        if(tmp < cost){
            ans = i;
            cost = tmp;
        }
    }
    cout << cost << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lli long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i, n)  for(int i=0;i<n;++i)
#define rforn(i,start) for(int i = start; i >= 0;--i)
#define forsn(i,start,end) for(int i=start;i<end;++i)
#define rforsn(i,start,end) for(int i=start;i>=end;--i)
#define debug(x) cout<<#x<<" = "<<x<<"\n";
const int CONST = 1e9 + 7;

#define MAX 2000000

int32_t main(){
	fastio;
    #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	//  freopen("output.txt","w",stdout);
	#endif
	
	int n;
	cin>>n;

	vector<int> h(n);
	forn(i, n)	cin>>h[i];

	lli ans=0;
	lli mini=0;
	for(auto it: h){
		if(it>mini){
			mini=it;
		}
		else{
			ans += (mini-it);
		}
	}
	cout<<ans<<endl;;

	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=510;
int n,dis[maxn][maxn],tot,val[maxn][maxn],ans;
struct node { int x,y; } d[maxn*maxn];
int fx[4][2]={{-1,0},{0,-1},{1,0},{0,1}};
void dfs(int x,int y) {
	int z=dis[x][y]+val[x][y];
	for (int i=0,a,b;i<4;i++) {
		a=x+fx[i][0],b=y+fx[i][1];
		if (1<=a&&a<=n&&1<=b&&b<=n&&dis[a][b]>z) {
			dis[a][b]=z;
			dfs(a,b);
		}
	}
}
int main() {
//	freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++) {
		dis[i][j]=min(min(i-1,n-i),min(j-1,n-j));
		d[++tot]=(node){i,j};
		val[i][j]=1;
	}
	int p,x,y;
	for (int i=1;i<=n*n;i++) {
		read(p);
		x=d[p].x,y=d[p].y;
		ans+=dis[x][y];
		val[x][y]=0;
		dfs(x,y);
	}
	printf("%d\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 22788
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>    
using namespace std;
#define LL long long
LL read(){
    LL f=1,x=0;char s=getchar();   
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}  
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
#define INF 0x3f3f3f3f
int main(){
	LL T,A,n=read(),t1,t2,tmp,g;
	for(int i=1;i<=n;i++){
		T=read(),A=read();
		if(i==1){
			t1=T,t2=A;
			continue;
		}
		g=max((t2+A-1)/A,(t1+T-1)/T);
		t2=g*A,t1=g*T;
	}
	printf("%lld\n",t1+t2);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

const int N_MAX=100000;

int n,m;
vector<vector<pair<int,int>>> v(N_MAX);
ll d[N_MAX];

void dfs(int s){
  for(int i=0;i<v[s].size();i++){
    int to=v[s][i].first;
    int cost=v[s][i].second;
    if(d[to]==LLONG_MAX){
      d[to]=d[s]+cost;
      dfs(to);
    }
  }
}

int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int l,r,d;
    cin>>l>>r>>d;
    l--,r--;
    v[l].push_back(make_pair(r,d));
    v[r].push_back(make_pair(l,-d));
  }
  for(int i=0;i<n;i++) d[i]=LLONG_MAX;
  for(int i=0;i<n;i++){
    if(d[i]==LLONG_MAX){
      d[i]=0;
      dfs(i);
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<v[i].size();j++){
      int to=v[i][j].first;
      int cost=v[i][j].second;
      if(d[to]!=(d[i]+cost)){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 12416
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

#define INF (1 << 30)
#define MAX_V 500

double cost[MAX_V][MAX_V]; // cost[u][v] ?????????u??????v???????????????
double mincost[MAX_V];
bool used[MAX_V];
int V;// V???????????°

// ????°???¨?????¨??§?????????O(V^2)

// ???????????????????????????????????????cost????¨?????????????????????¨

double prim(){
	
	for(int i = 0; i < V; i++){
		mincost[i] = INF;
		used[i] = false;
	}
	
	mincost[0] = 0;
	
	double total = 0;
	
	while(true){
		
		int add_v = -1;
		
		for(int u = 0; u < V; u++){
			if(!used[u] && (add_v == -1 || mincost[u] < mincost[add_v])){
				add_v = u;
			}
		} // ??????????????????????±????
		
		if(add_v == -1){
			break;
		} // ??´??°???????????????????????´????????????
		used[add_v] = true;
		total += mincost[add_v];
		
		for(int u = 0; u < V; u++){
			mincost[u] = min(mincost[u], cost[add_v][u]);
		} // ???????????????????????????????°???????????????´??°
	}
	return total;
}

struct Sphere{
	double x;
	double y;
	double z;
	double r;
};

double dist(Sphere p1, Sphere p2){
	double ans;
	ans = sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) + (p1.z - p2.z) * (p1.z - p2.z)) - (p1.r + p2.r);
	if(ans <= 0){
		ans = 0;
	}
	return ans;
}

int main(){
	
	double ans;
	
	Sphere ball[500];
	
	while(true){
		cin >> V;
		if(V == 0){
			break;
		}
		for(int i = 0; i < V; i++){
			cin >> ball[i].x >> ball[i].y >> ball[i].z >> ball[i].r;
		}
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				if(i == j){
					cost[i][j] = INF;
				}else{
					cost[i][j] = dist(ball[i], ball[j]);
				}
			}
		}
		
		ans = prim();
		printf("%.3f\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 1648
// Ho-kago Tea Time

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

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

const int MOD = (int) 1e9 + 7;

const int MAXN = (int) 1e5;

namespace MATH
{
	inline int fpm(int x, int y)
	{
		int res = 1;
		for(; y; y >>= 1, x = (LL) x * x % MOD) if(y & 1) res = (LL) res * x % MOD;
		return res;
	}

	const int n = MAXN * 3;

	int fac[n + 5], ifac[n + 5];

	inline int C(int N, int M) { return N < M ? 0 : (LL) fac[N] * ifac[M] % MOD * ifac[N - M] % MOD; }

	inline void init()
	{
		fac[0] = 1;
		for(int i = 1; i <= n; ++i) fac[i] = (LL) fac[i - 1] * i % MOD;
		ifac[n] = fpm(fac[n], MOD - 2);
		for(int i = n - 1; i >= 0; --i) ifac[i] = (LL) ifac[i + 1] * (i + 1) % MOD;
	}
}
using MATH::C;

int n, m, A, B;

inline void input()
{
	n = read<int>() - 1, m = read<int>() - 1, A = read<int>() - 1, B = read<int>() - 1;
}

inline void solve()
{
	int ans = C(n + m, n);
	for(int i = 0; i <= B; ++i) (ans -= (LL) C(n - A - 1 + i, i) * C(A + m - i, A) % MOD) %= MOD;
	printf("%d\n", (ans + MOD) % MOD);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
#endif

	MATH::init();
	input();
	solve();

	return 0;
}



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

int node[10001];

void unite(int a, int b){
    int tmp, tmpg;
    tmp = node[a];
    tmpg = node[b];
    for(int i=0;i<=10000;++i){
        if(node[i] == tmp){
            node[i] = tmpg;
        }
    }
    return;
}
void same(int a, int b){
    if(node[a] == node[b]){
        cout << "1" << endl;
    }else{
        cout << "0" << endl;
    }
    return;
}

int main(){
    for(int i=0;i<=10000;++i){
        node[i] = i;
    }
    
    int q, n, com, a, b;
    cin >> n >> q;
    
    for(int i=0;i<q;++i){
        cin >> com >> a >> b;
        if(com==0){
            unite(a, b);
        }else{
            same(a, b);
        }
    }
    
    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
using namespace std;
#define INF 1<<20
int main() {
	int n, k;
	cin >> n >> k;
	if (n<=k) {
		long long a[n+1]={};
		a[0]=1;
		for (int i=1; i<=n; i++) {
			a[i]=(a[i-1]*k)%1000000007;
			k--;
		}
		cout << a[n] << endl;
	} else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 3120
N = int(input())
a = list(map(int, input().split()))

b = [0] * (N + 1)

for i in range(N, 0, -1):
    if sum(b[::i]) % 2 != a[i-1]:
        b[i] = 1

s = sum(b)
print(sum(b))
if s != 0:
    for i in range(N+1):
        if b[i] == 1:
            print(i, end=" ")

Measured memory_bytes: 13536
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int result = 0;
        if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0 && a == b && b == c && a == c) {
            result = -1;
        } else {
            while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
                int halfA = a / 2;
                int halfB = b / 2;
                int halfC = c / 2;
                a = halfB + halfC;
                b = halfA + halfC;
                c = halfA + halfB;
                result++;
            }
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
INF = float('inf')

def dfs(i, a, b, c):
    if i == N:
        if a == 0 or b == 0 or c == 0:
            return INF
        else:
            return abs(a-A) + abs(b-B) + abs(c-C)
    ans0 = dfs(i+1, a, b, c)

    ans1 = dfs(i+1, a+L[i], b, c) + (10 if a != 0 else 0)
    ans2 = dfs(i+1, a, b+L[i], c) + (10 if b != 0 else 0)
    ans3 = dfs(i+1, a, b, c+L[i]) + (10 if c != 0 else 0)

    return min(ans0, ans1, ans2, ans3)

def main():
    print(dfs(0, 0, 0, 0))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9152
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[11];
int main(){
    int a,b;
    while(scanf("%d%d",&a,&b),a){
        for(int i=0;i<11;i++)d[i]=0;
        int v=0;
        for(int i=0;i<a;i++){
            int c;
            scanf("%d",&c);
            v=max(v,c/b);
            d[c/b]++;
        }
        int p=0;
        for(int i=0;i<11;i++)p=max(p,d[i]);
        double ret=0.01;
        for(int i=0;i<v;i++){
            ret+=(double)(v-i)/v*d[i]/p;
        }
        printf("%f\n",ret);
    }
}

Measured memory_bytes: 1064
package main

import (
	"fmt"
	"strconv"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	var count int = 0
	for i := 1; i <= N; i++ {
		if len(strconv.Itoa(i))%2 != 0 {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 2352
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <cstring>
using namespace std;

int main(void){
    long long int x, y, ans;
    cin >> x;

    y = x / 11 * 2;
    if (x - y * 11 / 2 == 0) {
      ans = y;
    } else if (x - y * 11 / 2 > 6){
      ans = y + 2;
    } else {
      ans = y + 1;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input()
ans=0
for i in range(1000):
  i='0'*(3-len(str(i)))+str(i)
  if i[0] in s:
    if i[1] in s[s.index(i[0])+1:]:
      if i[2]in s[s.index(i[0])+s[s.index(i[0])+1:].index(i[1])+2:]:
        ans+=1
print(ans)

Measured memory_bytes: 9264