akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
using namespace std;
 
struct UnionFind
{
  vector< int > data;
 
  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k)
  {
    return (-data[find(k)]);
  }
};
 
int main()
{
  int N, M, K, X[100000], Y[100000];
 
  cin >> N >> M >> K;
 
  map< pair< int, int >, int > vs;
  for(int i = 0; i < K; i++) {
    cin >> X[i] >> Y[i];
    vs[{X[i], Y[i]}] = i;
  }
 
  UnionFind tree(K);
  for(int i = 0; i < K; i++) {
    for(int j = -1; j <= 1; j++) {
      for(int k = -1; k <= 1; k++) {
        int x = X[i] + j, y = Y[i] + k;
        if(vs.count({x, y})) tree.unite(vs[{x, y}], i);
      }
    }
  }
 
 
  set< int > link1, link2;
  for(int i = 0; i < K; i++) {
    if(X[i] == 0 || Y[i] == M - 1) link1.emplace(tree.find(i));
    if(X[i] == N - 1 || Y[i] == 0) link2.emplace(tree.find(i));
  }
 
  for(auto &v : link1) {
    if(link2.count(v)) {
      cout << 0 << endl;
      return (0);
    }
  }
 
  for(int i = 0; i < K; i++) {
    for(int j = -1; j <= 1; j++) {
      for(int k = -1; k <= 1; k++) {
        int x = X[i] + j, y = Y[i] + k;
        if(x < 0 || y < 0 || x >= N || y >= M) continue;
        if(x == 0 && y == 0) continue;
        if(x == N - 1 && y == M - 1) continue;
        if(vs.count({x, y})) continue;
 
        bool up = false, down = false;
        up |= link1.count(tree.find(vs[{X[i], Y[i]}]));
        down |= link2.count(tree.find(vs[{X[i], Y[i]}]));
 
        if(x == 0 || y == M - 1) up = true;
        if(x == N - 1 || y == 0) down = true;
 
        for(int l = -1; l <= 1; l++) {
          for(int m = -1; m <= 1; m++) {
            int xx = x + l, yy = y + m;
            if(xx < 0 || yy < 0 || xx >= N || yy >= M) continue;
            if(!vs.count({xx, yy})) continue;
            up |= link1.count(tree.find(vs[{xx, yy}]));
            down |= link2.count(tree.find(vs[{xx, yy}]));
          }
        }
 
        if(up && down) {
          cout << 1 << endl;
          return (0);
        }
      }
    }
  }
 
 
  cout << 2 << endl;
}

Measured memory_bytes: 10232
import collections
import itertools

li = [list(map(int,input().split())) for i in range(3)]
li = list(itertools.chain.from_iterable(li))
li.sort()

c = list(collections.Counter(li).values())

if c.count(2) == 2 and c.count(1) == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3444
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
	int N,i;
	int ans = 1;
	int H[21];
	scanf("%d", &N);
	for (i = 0;i < N;i++)scanf("%d", &H[i]);
	int max = H[0];
	for (i = 1;i < N;i++)
	{
		if (H[i] >= max)
		{
			max = H[i];
		}
		if (H[i] >=H[0] && H[i] >=max)ans++;
		
	}
		printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

pi = 0
qi = 0

def dfs(array, n):
  if(len(array) == n):
    return [tuple(array)]

  ret = []

  # 再起処理
  for i in range(1, N+1):

    if(i in array):
      continue

    array.append(i)
    ret.extend(dfs(array, n))
    array.pop()

  return ret


for index, pattern in enumerate(dfs([], N)):
  if P == pattern:
    pi = index
  if Q == pattern:
    qi = index

print(abs(pi - qi))


Measured memory_bytes: 7872
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

vector<string> split(const string &s,char c=' '){
    vector<string> ret;
    stringstream ss(s);
    string t;
    while(getline(ss,t,c)){
        ret.push_back(t);
    }
    return ret;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(1){
        string s, t;
        cin >> s;
        if(s == ".") break;
        cin >> t;
        if(s == t){
            cout << "IDENTICAL" << endl;
            continue;
        }
        char c = '"';
        vector<string> ss = split(s, c);
        vector<string> tt = split(t, c);
        int cnt = 0;
        if(ss.size() != tt.size()) cnt = INF;
        rep(i, 0, min(ss.size(), tt.size())){
            if(i % 2 == 0){
                if(ss[i] != tt[i]) cnt = INF;
            }else{
                if(ss[i] != tt[i]) cnt++;
            }
        }
        if(cnt <= 1){
            cout << "CLOSE" << endl;
        }else{
            cout << "DIFFERENT" << endl;
        }
    }
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/
	
	//eratos
	const int MAX = 100010;
	vector<int> is_prime(MAX, 1);
	is_prime[0] = 0, is_prime[1] = 0;
	for (int i = 2; i < MAX; i++) {
		if (!is_prime[i]) continue;
		for (int j = i * 2; j < MAX; j += i) {
			is_prime[j] = 0;
		}
	}

	//2017-like
	vector<int> a(MAX, 0);
	for (int i = 0; i < MAX; i++) {
		if (i % 2 == 0) continue;
		if (is_prime[i] && is_prime[(i + 1) / 2]) {
			a[i] = 1;
		}
	}

	//累積和
	vector<int> s(MAX + 1, 0);
	for (int i = 0; i < MAX; i++) {
		s[i + 1] = s[i] + a[i];
	}

	int q;
	cin >> q;
	rep(i, q) {
		int l, r;
		cin >> l >> r;
		cout << s[r + 1] - s[l] << endl;
	}

	return 0;
}

Measured memory_bytes: 1792
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S / 3600;
        int m = S % 3600 / 60;
        int s = S % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26384
A, B, AB, X, Y = map(int, input().split())

smaller = X if X < Y else Y
diff = Y - smaller if X < Y else X - smaller
diff_type = 'b' if X < Y else 'a'
cost = 0

if A+B > 2*AB:
    cost += 2*AB*smaller
    # Bを買い足さないと行けない場合
    if diff_type == 'b':
        if B > 2*AB:
            cost += AB*2*diff
        else:
            cost += B*diff
    else:
        if A > 2*AB:
            cost += AB*2*diff
        else:
            cost += A*diff
else:
    cost = A*X + B*Y

print(cost)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define int long long
#include "string"

int32_t main(){
	boost;
	char c;
	cin>>c;
	if(c>='a')
		cout<<"a"<<endl;
	else
		cout<<"A"<<endl;		
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -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;
}
// ----------------------------------------------------------------------------

int main(){
  string S;
  cin >> S;
  int cnt=0;
  for(int i=0; i<S.size()-1; i++){
    if(S[i] != S[i+1]){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/

int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
      int h,a;
      cin>>h>>a;
      (h%a==0?cout<<h/a<<endl:cout<<h/a+1<<endl);
 }
}















Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=32;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int r;
	scanf("%d",&r);
	double pi=acos(-1.0);
	printf("%.6f\n",2*pi*r);
	return 0;
}

Measured memory_bytes: 3808
// ~maqsat~
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n";
#define TEZ ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout);

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class U> inline void cmin(T &a, U b) { a = min(a, b); }
template <class T, class U> inline void cmax(T &a, U b) { a = max(a, b); }
template <class T, class U, class X, class Y> inline void psmn(T &a, U b, X &p, Y i) { if(b < a)a = b,p = i; }
template <class T, class U, class X, class Y> inline void psmx(T &a, U b, X &p, Y i) { if(b > a)a = b,p = i; }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846

int main() {
	fre(""); TEZ;

	int n;
	cin >> n;
	if(n % 2) {
	    n++;
		double b = n - 1.;
	    n >>= 1;
		double a = double(n)/b;
		cout << fixed << setprecision(6) << a;
	    
	}
	else {
	    double b = n;
	    n >>= 1;
		double a = double(n)/ b;
		cout << fixed << setprecision(6) << a;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

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

	string s;
	cin >> s;
	int ans = 0;
	for(auto it : s) {
		ans += (it - '0');
	}
	if(ans % 9 == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 3768
using System;
class act{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        String[] str = Console.ReadLine().Split(' ');
        long sum=0, max=-1000000, min=1000000;
        for(int i=0; i<n; i++){
            if(max < int.Parse(str[i]))
                max = int.Parse(str[i]);
            if(min > int.Parse(str[i]))
                min = int.Parse(str[i]);
            sum+=int.Parse(str[i]);
        }
        Console.WriteLine("{0} {1} {2}",min,max,sum);
    }
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

vector<int> g[210];

int main(){
    int n; scanf("%d",&n);
    rep(i,0,n){
        string s; cin>>s;
        rep(j,0,n)if(s[j]=='1'){
            g[i].push_back(j);
        }
    }
    int ans=0;
    bool f; int maxx,color,v;
    rep(i,0,n){
        int col[210]={};
        bool used[210]={};
        queue<P> q;//col,pos
        q.push({1,i}); used[i]=1; f=0; maxx=0;
        while(q.size()){
            P p=q.front(); q.pop();
            color=p.first,v=p.second;
            if(col[v]){
                f=1; break;
            }
            col[v]=color;chmax(maxx,color);
            for(int nxt:g[v]){
                if(col[nxt]==color){
                    f=1; break;
                }
                if(!used[nxt])used[nxt]=1,q.push({color+1,nxt});
            }
            if(f)break;
        }
        if(f)continue;
        chmax(ans,maxx);
    }
    printf(ans==0?"-1\n":"%d\n",ans);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
static const int INF = (1<<30)-1;
int N,K,A[100001];
int main(){
  cin >> N >> K;
  int min_pos;
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(A[i] == 1) min_pos = i;
  }

  if(N <= K){
    cout << "1" << endl;
    return 0;
  }

  int min_act = INF, left, right;
  left = min_pos;
  right = N - min_pos - 1;

  for(int i=0;i<K;i++){
    int act = 0;
    int l = left - i;
    int r = right - (K-1) + i;
    if(l != 0){
      if( (l)%(K-1) == 0 ) act += (l)/(K-1);
      else act += (l)/(K-1) + 1;
    }
    if(r != 0){
      if( (r)%(K-1) == 0 ) act += (r)/(K-1);
      else act += (r)/(K-1) + 1;
    }
    min_act = min(min_act,act+1);
  }
  cout << min_act << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
#include <cstdlib>
#include <cctype>
#include <random>

using namespace std;

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int cnt = 0;
    for (int i=0; i<=a; i++) {
        for (int j=0; j<=b; j++) {
            for (int k=0; k<=c; k++) {
                if (500*i + 100*j + 50*k == x) cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<string>
#include<map>
#include<vector>
using namespace std;
struct I{int x;I():x(-1){}operator int(){return x;}void operator=(int r){x=r;}};
int main()
{
	char a[128],*p,*q;
	int w,x,i;
	map<string,I>m;vector<int>v,s;while(scanf("%s",a),strcmp(a,"END_OF_FIRST_PART"))scanf("%d",&w),m[a]=v.size(),v.push_back(w);
	while(scanf("%s",a),a[0]-'0')
	{
		s.clear();
		s.push_back(0);
		for(p=a;*p;)
		{
			if(isupper(*p))
			{
				if(islower(p[1]))i=m[string(p,2)],p+=2;
				else i=m[string(p,1)],++p;
				if(i<0){puts("UNKNOWN");goto E;}
				if(isdigit(*p))x=strtol(p,&q,10),p=q;
				else x=1;
				s.back()+=x*v[i];
			}
			else if(*p=='(')s.push_back(0),++p;
			else if(*p==')')
			{
				++p;
				w=s.back(),s.pop_back();
				x=strtol(p,&q,10);
				if(p==q)x=1;
				p=q;
				s.back()+=w*x;
			}
		}
		printf("%d\n",s[0]);
E:;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static Scanner sc;
	
	public static void main(String[] args) {
		sc=new Scanner(System.in);
		int i=1;
		int n=sc.nextInt();
		for(i=1;i<=n;i++) {
			int x=i;
			
			if(x%3==0) {
				System.out.print(" "+i);
				continue;
			}
			
			while(x!=0) {
				if(x%10==3) {
					System.out.print(" "+i);
					break;
				}else {
					x/=10;
				}
			}
		}
		System.out.println("");
		
	}
}


Measured memory_bytes: 28920
import java.util.*
fun main(args: Array<String>) {
    val N = nextInt()
    val A = Array<Double>(N) { nextDouble() }
    val D = mutableListOf<Double>()
    for (n in 0 until N) {
        val a = D.binarySearch(A[n] - 0.1 , Comparator<Double> { a, b -> a.compareTo(b) })
        val b = a.inv()
        if (a >= 0) D.add(a, A[n])
        else if (b == 0) D.add(0, A[n])
        else D[b - 1] = A[n]
    }
    val ans = D.count()
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextDouble() = next().toDouble()


Measured memory_bytes: 46200
#include<bits/stdc++.h>
#define inf 1000000010
using namespace std;
struct cmp{bool operator()(int a,int b){return a<=b;}};
int main()
{
	int f[100010];
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	scanf("%d",&f[i]);
	int dp[100010];
	for(int i=0;i<n;i++)
	dp[i]=inf;
	for(int i=n-1;i>=0;i--)
	{
		*lower_bound(dp,dp+n,f[i],cmp())=f[i];
	}
	cout<<lower_bound(dp,dp+n,inf)-dp;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


const int max_comb=120000;
vector<ll> fac(max_comb+1); //n! (mod M)
vector<ll> ifac(max_comb+1); //k!^(-1) (mod M)

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x){
    return mpow( x, MOD-2 );
}

ll comb(int a, int b){     // C(a,b) = a! * b!^(-1) * (a-b)^(-1)
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

ll perm(int a, int b){     // P(a,b) = a! * (a-b)!^(-1)
    if(b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b] % MOD;
    return tmp * fac[a] % MOD;
}

void pre_comb()
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0; i<max_comb; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*minv(i+1) % MOD; // k!^(-1) (mod M)
    }
    return;
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<ll> a(n),s(n+1);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        s[i+1]=s[i]+a[i];
    }
    pre_comb();

    vector<ll> p(n-1),sp(n);
    for(i=0; i<n-1; i++) {
        p[i]=perm(i,i)*minv(perm(i+2,i+2))%MOD;
        p[i]=p[i]*perm(n-1,n-1)%MOD;
        sp[i+1]=(sp[i]+p[i])%MOD;
    }

    ll ans=0;
    int j;
    for(i=0; i<n-1; i++) {
        {
            ll tmp=(MOD+perm(n-1,n-1)-sp[n-i-2])%MOD;
            ll ans0=tmp*((a[n-1]-a[i])%MOD)%MOD;
            ans=(ans+ans0)%MOD;
        }
        if(i<n-1) {
            ll tmp=p[i];
            ll aaa=(s[n-1]-s[i+1]-s[n-i-2]+MOD+MOD)%MOD;
            ll ans0=tmp*aaa%MOD;
            ans=(ans+ans0)%MOD;
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 5248
import fractions

a, b, c, d = map(int, input().split())

a -= 1

lcm = c * d // fractions.gcd(c, d)

b_sum = b - (b // c) - (b // d) + (b // lcm)
a_sum = a - (a // c) - (a // d) + (a // lcm)

print(b_sum - a_sum)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 998244353
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;


int main(){

    int n;
    cin >> n;

    vector<vector<int> > edge(n + 1, vector<int>(0));
    vector<pair<int,int> > query;

    map<pair<int,int>, int> color;

    rep(i,n - 1){
        int a,b;
        cin >> a >> b;

        edge[a].pback(b);
        edge[b].pback(a);

        query.pback(mpair(a,b));
    }

    int maxedge = 0;
    int maxedgei;

    rep(i,n){
        if(edge[i + 1].size() > maxedge){
            maxedge = edge[i + 1].size();
            maxedgei = i + 1;
        }
    }

    cerr << "maxedge:" << maxedge << endl;
    cerr << "maxedgei:" << maxedgei << endl;

    queue<pair<int,pair<int,int> > > q;

    q.push(mpair(maxedgei, mpair(0,0)));

    while(!q.empty()){

        int tmpi = q.front().first;
        int prev = q.front().second.first;
        int prevcolor = q.front().second.second;

        int tmpc = 1;

        rep(i,edge[tmpi].size()){
            int to = edge[tmpi][i];

            if(to != prev){
                if(tmpc == prevcolor){
                    tmpc++;
                }

                color[mpair(min(tmpi, to), max(tmpi, to))] = tmpc;

                q.push(mpair(to, mpair(tmpi, tmpc)));

                tmpc++;
            }
        }

        q.pop();

    }

    cout << maxedge << endl;

    rep(i,n - 1){
        cout << color[mpair(query[i].first, query[i].second)] << endl;
    }

    return 0;
}

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

int main(){
    
    size_t n;
    size_t cnt = 0;

    std::cin >> n;

    std::vector<size_t> p(n);

    for(auto&& e : p){
        std::cin >> e;
    }

    for(size_t i = 1; i < n - 1; i++){
        if((p.at(i - 1) < p.at(i) && p.at(i) < p.at(i + 1)) || (p.at(i - 1) > p.at(i) && p.at(i) > p.at(i + 1))) cnt++;
    }

    std::cout << cnt << std::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);
		double r = sc.nextDouble();
		double c = r * Math.PI * 2;
		double a = r * r * Math.PI;

		System.out.printf("%f", a);
		System.out.print(" ");
		System.out.printf("%f", c);
		System.out.println();

		sc.close();
	}
}



Measured memory_bytes: 28272
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> X(M),Y(M-1);
	for (int i = 0; i < M; i++)cin >> X[i];
	sort(X.begin(), X.end());
	for (int i = 0; i < M - 1; i++) {
		Y[i] = X[i + 1] - X[i];
	}
	sort(Y.begin(), Y.end(), greater<>());
	ll ans = 0;
	for (int i = 0; i < M - 1; i++) {
		if (N > 1) {
			N--;
			continue;
		}
		ans += Y[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=input().rstrip()
t=input().rstrip()
u=sorted(list(s))
v=sorted(list(t),reverse=True)
#print(v)
ss=""
tt=""
for i in u:
    ss+=i
for j in v:
    tt+=j
#print(ss)
#print(tt)
if ss<tt:
    print("Yes")
else:
    print("No")
    

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, M;
	cin >> A >> B >> M;
	vector<int> X(A);
	vector<int> Y(B);
	int res = 0;
	int mnX = (int)1 << 60;
	int mnY = (int)1 << 60;
	for (int i = 0; i < A; i++) {
		cin >> X[i];
		mnX = min(mnX, X[i]);
	}
	for (int i = 0; i < B; i++) {
		cin >> Y[i];
		mnY = min(mnY, Y[i]);
	}
	res = mnX + mnY;
	for (int i = 0; i < M; i++) {
		int x, y, c;
		cin >> x >> y >> c;
		x--;
		y--;
		res = min(res, X[x] + Y[y] - c);
	}
	cout << res << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
#define enld endl
int main(){
    ll n,sum=0;
    cin>>n;
    vector<ll>a(n),ans(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sum/=2;
    ll odd=0,even=0;
    for(int j=0;j<(n-1)/2;j++){//引く回数
        even+=a[(1+j*2)%n];
    }
    ans[0]=sum-even;
    for(int j=0;j<(n-1)/2;j++){//引く回数
        odd+=a[(2+j*2)%n];
    }
    ans[1]=sum-odd;



    for(int i=2;i<n;i+=2){
        even=even-a[(i+n-1)%n]+a[(i+n-2)%n];
        ans[i]=sum-even;
    }
    for(int i=3;i<n;i+=2){
        odd=odd-a[(i+n-1)%n]+a[(i+n-2)%n];
        ans[i]=sum-odd;
    }
    

    for(int i=0;i<n;i++){
        cout<<ans[i]*2<<" ";
    }
    cout<<endl;

}

Measured memory_bytes: 2944
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var x = next(), y = next(), z = next();
  return z+" "+x+" "+y;
}

Measured memory_bytes: 22076
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  map<string,ll> m;
  REP(i,n) {
    string s;
    cin>>s;
    boost::sort(s);
    ++m[s];
  }
  ll cnt=0;
  for (auto p : m) {
    string s;
    ll k;
    tie(s,k) = p;
    cnt += k*(k-1)/2;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 11136
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int y,m,d;
    scanf("%4lld/%2lld/%2lld",&y,&m,&d);
    printf("%s\n",(m<=4)?"Heisei":"TBD");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
ll power(ll x,ll n,ll mod){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
int a[100001];
int main(void)
{
	int n,t,i;
	ll mod=(1e+9)+7;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%d",&t);
		a[t]++;
	}
	if(n%2&&a[0]!=1) puts("0");
	else{
		for(i=n%2+1;i<n;i+=2){
			if(a[i]!=2){
				puts("0");
				return 0;
			}
		}
		printf("%lld\n",power(2LL,(ll)n/2,mod));
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

const int MOD = 1000000007;

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

    int64 ans = 0;
    int64 csum = 0;
    for (int i=0; i<n; i++) {
        ans += csum * a[i];
        csum += a[i];
        ans %= MOD;
        csum %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)

void solve(){
	int n; cin>>n;
	int f= 0;
	rep(i,0,n){
		char ch;
		cin>>ch;
		if(ch == 'Y') f= 1;
	}
	if(f) cout<<"Four"<<endl;
	else cout<<"Three" <<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 892
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad 
import Data.Maybe

main :: IO ()
main = readLn >>= main'
    where
        main' n = replicateM n breads >>= printRes . solve
        printRes = putStrLn . unwords . map show

solve :: [[Int]] -> [Int]
solve xyhs = fromJust . head . filter isJust $ map calc [(x, y) | x <- [0..100], y <- [0..100]]
    where
        calc (cx, cy) = judge (Left 10000000000) $ map calcH xyhs
            where
                judge (Right ans) (Right v : res)
                    | ans == v = judge (Right v) res
                    | otherwise = Nothing
                judge (Right ans) (Left v : res)
                    | ans <= v = judge (Right ans) res
                    | otherwise = Nothing
                judge (Left ans) (Right v : res)
                    | v <= ans = judge (Right v) res
                    | otherwise = Nothing
                judge (Left ans) (Left v : res) = judge (Left $ min ans v) res
                judge (Right ans) _ = Just [cx,  cy, ans]
                judge _ _ = Nothing

                calcH [x, y, h]
                    | h > 0 = Right $ h + z
                    | otherwise = Left $ z
                    where
                        z = zf x y

                zf x y = abs (x - cx) + abs (y - cy)


breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX





void solve()
{
  string s;
  cin >> s;
  if(s[2]==s[3] and s[4]==s[5])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}


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

int n;
string S;

int main(void)
{
    cin >> n;
    cin >> S;

    int count = 0;
    for(int i=1;i<n;i++){
        if(S[i-1] != S[i]){
            count++;
            i++;
        }
    }

    cout << count << endl;
}



Measured memory_bytes: 3348
#include<iostream>
#include<stdio.h>
#include<stack>
#include<string>
#include<cstdlib>

using namespace std;
int main(){
	stack <int> S;
	int a,b;
	string kani;
	while(cin>>kani){
		if(kani=="+"){
			b=S.top();
			S.pop();
			a=S.top();
			S.pop();
			S.push(a+b);
		}
		else if(kani=="-"){
			b=S.top();
			S.pop();
			a=S.top();
			S.pop();
			S.push(a-b);
		}
		else if(kani=="*"){
			b=S.top();
			S.pop();
			a=S.top();
			S.pop();
			S.push(a*b);
		}
		else{
			S.push(atoi(kani.c_str()));
		}
	}
	cout<<S.top()<<endl;;
	return 0;
}

Measured memory_bytes: 3220
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int w,h,sx,sy;
int dx[4]= {1,0,-1,0},dy[4] = {0,1,0,-1};
char fruit[1000][1000];
//int flag[1000][1000];
int num;

void dfs(int x,int y,char c)
{
    fruit[x][y]='.';
    for(int i = 0; i < 4; i++)
    {
        int nx = x + dx[i], ny = y + dy[i];
        if(nx<h&&nx>=0&&ny<w&&ny>=0&&fruit[nx][ny]==c)
            dfs(nx,ny,fruit[nx][ny]);
    }
}

void solve()
{
    while(cin>>h>>w&&w&&h)
    {
        num = 0;
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
                cin>>fruit[i][j];
        }
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                if(fruit[i][j]!='.')
                {
                    dfs(i,j,fruit[i][j]);
                    num++;
                }
            }
        }
        printf("%d\n",num);
    }
}
int main(void)
{
    solve();
    return 0 ;
}



Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int N;
   cin>>N;
   char a[N];
   
   for(int i=0;i<N;i++)
   {
       cin>>a[i];
   }
   
   
   int p,w,g,y;
   
   p=0;
   w=0;
   g=0;
   y=0;
   
   for(int i=0;i<N;i++)
   {
       if(a[i]=='P') p++;
       if(a[i]=='W') w++;
       if(a[i]=='G') g++;
       if(a[i]=='Y') y++;
   }
   
   if(p>0 && w>0 && g>0 && y==0)
   {
       cout<<"Three";
   }
   
   else
   {
       cout<<"Four";
   }
   
  
   
   
   
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
main(){
  int a,b,c[5];
  for(int i=0;i<4;i++){
    cin>>a;
    cin>>b;
    if(a==1){
      c[i]=b*6000;
    }else if(a==2){
      c[i]=b*4000;
    }else if(a==3){
      c[i]=b*3000;
    }else{
      c[i]=b*2000;
    }
  }
  for(int j=0;j<4;j++){
    cout<<c[j]<<endl;
  }   
  return(0);
}



Measured memory_bytes: 3096
from heapq import heappush,heappop
from operator import itemgetter
parent = []
rank = []

def init(n):
    global parent, rank
    parent = range(n+1)
    rank = [0] * (n + 1)
    
def find(v):
    global parent, rank
    if parent[v] == v:
        return v
    else:
        parent[v] = find(parent[v])
        return parent[v]

def union(x,y):
    global parent, rank
    xr = find(x)
    yr = find(y)
    if rank[xr] > rank[yr]:
        parent[yr] = xr
    elif rank[xr] < rank[yr]:
        parent[xr] = yr
    else:
        parent[yr] = xr
        rank[xr] += 1

def kruskal(v,e):
    visited = [False] * v
    hq = []
    t = []
    init(v)
    for a,b,c in e:
        heappush(hq,(c,(a,b)))
    while len(t) < v-1:        
        c,(a,b) = heappop(hq)
        if find(a) == find(b):
            continue
        t.append((c,(a,b)))
        union(a,b)
    return sum(map(itemgetter(0),t))

while True:
    n,m = map(int,raw_input().split())
    if n|m == 0:
        break    
    e = [map(int,raw_input().split()) for _ in xrange(m)]
    print kruskal(n,e)

Measured memory_bytes: 4540
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        double sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += 1.0 / a[i];
        }

        double result = 1.0 / sum;

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

Measured memory_bytes: 23252
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
using namespace std;

int m;
vector<vector<bool>> obj;

map<vector<int>, int> memo;
int dfs(vector<int>& set) {
    if (set.size() == 1) return 0;
    if (memo[set]) return memo[set];
    memo[set] = m;
    for (int f = 0; f < m; f++) {
        vector<int> ok, ng;
        for (int i: set) (obj[i][f] ? ok : ng).emplace_back(i);
        if (ok.size() == 0 || ng.size() == 0) continue;
        memo[set] = min(memo[set], max(dfs(ok), dfs(ng)) + 1);
    }
    return memo[set];
}

int main() {
    int n;
    while (cin >> m >> n, n) {
        obj.assign(n, vector<bool>(m));
        for (int i = 0; i < n; i++) {
            string buf; cin >> buf;
            for (int f = 0; f < m; f++) obj[i][f] = buf[f] - '0';
        }
        memo.clear();
        vector<int> set(n);
        iota(set.begin(), set.end(), 0);
        cout << dfs(set) << endl;
    }
    return 0;
}


Measured memory_bytes: 5384
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t gcd(int64_t a, int64_t b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

const int64_t MOD = 1'000'000'007L;

int64_t dpow(int64_t x, int64_t y) {
  if (y == 0) {
    return 1;
  }
  if (y % 2 == 0) {
    return dpow(x * x % MOD, y / 2);
  } else {
    return x * dpow(x, y - 1) % MOD;
  }
}

int64_t inv(int64_t x) { return dpow(x, MOD - 2); }

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

  int zeros = 0;
  using P = pair<int64_t, int64_t>;
  map<P, int> a, b;
  rep(i, n) {
    int64_t x, y;
    cin >> x >> y;
    if (x != 0 && y != 0) {
      if (y < 0) {
        x *= -1;
        y *= -1;
      }

      int64_t d = gcd(abs(x), abs(y));
      x /= d;
      y /= d;
      if (x > 0) {
        a[P(x, y)]++;
      } else {
        a[P(y, -x)];
        b[P(y, -x)]++;
      }
    } else {
      if (x == 0 && y == 0) {
        zeros++;
      } else if (x == 0) {
        a[P(1, 0)];
        b[P(1, 0)]++;
      } else {
        a[P(1, 0)]++;
      }
    }
  }

  int64_t result = 1;
  for (auto p : a) {
    P k;
    int acnt;
    tie(k, acnt) = p;
    int bcnt = b[k];

    int64_t term = ((dpow(2, acnt) + dpow(2, bcnt)) % MOD - 1 + MOD) % MOD;
    // cerr << " " << term << endl;
    result *= term;
    result %= MOD;
  }
  result += zeros;
  result %= MOD;
  result += MOD - 1;
  result %= MOD;
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 28472
class UnionFind(object):
  def __init__(self,n):
    self.parent={i:i for i in range(1,n+1)}
    self.size={i:1 for i in range(1,n+1)}
  def find(self,a):
    if self.parent[a]!=a:
      self.parent[a]=self.find(self.parent[a])
    return self.parent[a]
  def unite(self,a,b):
    a=self.find(a)
    b=self.find(b)
    if a==b:return
    if self.size[a]>self.size[b]:
      self.size[a]+=self.size[b]
      self.parent[b]=a
    else:
      self.size[b]+=self.size[a]
      self.parent[a]=b
  def isunited(self,a,b):
    return self.find(a)==self.find(b)

n,m=map(int,input().split())
uf=UnionFind(n)
ans=[]
v=n*(n-1)//2
l=[tuple(map(int,input().split())) for _ in range(m)][::-1]

for a,b in l:
  ans.extend([v])
  if not uf.isunited(a,b):
    v-=uf.size[uf.find(a)]*uf.size[uf.find(b)]
  uf.unite(a,b)
print(*ans[::-1],sep="\n")

Measured memory_bytes: 42536
#include <iostream>
#include <string>
#include <vector>

using namespace std;
bool exist;
bool ok;
vector<int> num;

void dfs(int depth)
{
	if(depth == 4)
	{
		ok = true;
		return;
	}
	for(int i = 1; i <= 7; ++i)
	{
		if(num[i] >= 1 && num[i + 1] >= 1 && num[i + 2] >= 1)
		{
			num[i]--;
			num[i + 1]--;
			num[i + 2]--;
			dfs(depth + 1);
			num[i]++;
			num[i + 1]++;
			num[i + 2]++;
		}
	}
	for(int i = 1; i <= 9; ++i)
	{
		if(num[i] >= 3)
		{
			num[i] -= 3;
			dfs(depth + 1);
			num[i] += 3;
		}
	}
	return;
}

void solve()
{
	string s;
	while(cin >> s)
	{
		bool first = true;
		exist = false;
		for(int i = 1; i <= 9; ++i)
		{
			num.clear();
			num.resize(10);
			for(int j = 0; j < s.size(); ++j)
			{
				num[s[j] - '0']++;
			}
			if(num[i] == 4)
			{
				continue;
			}
			else
			{
				++num[i];
			}
			vector<int> buffer = num;
			ok = false;
			for(int j = 1; j <= 9; ++j)
			{
				num = buffer;
				if(num[j] >= 2)
				{
					num[j] -= 2;
					dfs(0);
					if(ok)
					{
						if(first)
						{
							cout << i;
							first = false;
							exist = true;
						}
						else
						{
							cout << " " << i;
						}
						break;
					}
				}
			}
		}
		if(!exist)
		{
			cout << 0 << endl;
		}
		else
		{
			cout << endl;
		}
	}
}

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

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int ans = 100000000;

int main(){
    int N; cin >> N;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];

    map<ll,int> counter;
    rep(i,N){
        counter[a[i]]++;
    }

    ll ans = 0;
    for (auto c : counter){
        if (c.first > c.second){
            ans += c.second;
        }
        else{
            ans += c.second - c.first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 10128