akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <unordered_set>

using namespace std;

#define INF (1e18)

typedef pair<long long, long long> P;
typedef pair<long long,P> P2;
typedef pair<long long,P2> P3;

int main() {
    long long N,M,X;
    cin >> N >> M >> X;

    vector<long long> H(N);
    vector<long long> nxt_min(N,INF);
    vector<P> to[N]; // dist, tree
    for(int i=0; i<N; ++i) {
        cin >> H[i];
    }
    for(int i=0; i<M; ++i) {
        long long a,b,t;
        cin >> a >> b >> t;
        --a; --b;
        if(H[a]>=t) {
            to[a].push_back(P(b,t));
            nxt_min[a]=min(nxt_min[a],t);
        }
        if(H[b]>=t) {
            to[b].push_back(P(a,t));
            nxt_min[b]=min(nxt_min[b],t);
        }
    }

    priority_queue<P2,vector<P2>,greater<P2> > q; // dist, now_tree, rest_height
    vector<long long> dist(N,INF);
    unordered_set<long long> closed;
    long long ans=-1;

    q.push(P2(0,P(0,X)));
    while(!q.empty()) {
        P2 pp=q.top(); q.pop();
        long long now_dist=pp.first;
        long long now_tree=pp.second.first;
        long long now_rest=pp.second.second;
        if(now_tree==N-1) {
            ans=now_dist+(H[N-1]-now_rest);
            break;
        }
        if(closed.count(now_tree)!=0) continue;
        closed.insert(now_tree);

        for(int i=0; i<(int)to[now_tree].size(); ++i) {
            long long nxt_tree=to[now_tree][i].first;
            long long nxt_dist;
            long long nxt_rest=max(0LL,now_rest-to[now_tree][i].second);
            if(closed.count(nxt_tree)!=0) continue;
            if(nxt_rest>H[nxt_tree]) {
                nxt_dist=now_dist+to[now_tree][i].second+(nxt_rest-H[nxt_tree]);
                nxt_rest=H[nxt_tree];
            } else if(nxt_rest>0) {
                nxt_dist=now_dist+to[now_tree][i].second;
            } else {
                nxt_dist=now_dist+2*to[now_tree][i].second-now_rest;
            }
            dist[nxt_tree]=nxt_dist;
            q.push(P2(nxt_dist,P(nxt_tree,nxt_rest)));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 27936
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;

int main(){
	string a,b;
	cin>> a >> b;
	int A = a.size();
	int B = b.size();
	if(a==b){
		cout<<"EQUAL"<<endl;
	}
	else if( A > B ){
		cout<<"GREATER"<<endl;
	}
	else if( A < B){
		cout<<"LESS"<<endl;
	}
	else if( A == B){//文字数が同じとき
		rep(i,A){//文字数回だけループさせて、どっちかのほうが大きいってわかったらbreak;
			char x = a[i];
			char y = b[i];
			if(x > y){//aのほうが大きい
				cout<<"GREATER"<<endl;
				break;
			}
			else if(x < y){
				cout<<"LESS"<<endl;
				break;
			}
		}
	}
}

	


		


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  vector<int> a(n);
  REP(i, n){
    cin>>a[i];
  }
  sort(ALL(a));
  a.erase(unique(a.begin(), a.end()), a.end());
  int m = a.size();
  if(n == m){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (n, d) = readLine()!!.split(' ').map(String::toInt)
    val x = (1..n).map {
        readLine()!!.split(' ').map(String::toInt)
    }
    var count = 0
    for (i in 1 until n) {
        for (j in 0 until i) {
            val dd = x[i].zip(x[j]).map { (it.first - it.second) * (it.first - it.second) }.sum()
            val d = Math.round(Math.sqrt(dd.toDouble()))
            if (dd.toLong() == d * d) {
                count ++
            }
        }
    }
    println(count)
}


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

int main(void) {
  string s;
  string t;
  
  cin >> s >> t;
  
  for(int i = 0; i < s.length(); i++) {
    if(s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

struct Cake {
    int h, w;
    Cake(){}
    Cake(int _h, int _w) : h(_h), w(_w) {}
};

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

    int N, W, H;
    while (cin >> N >> W >> H, W) {
        vector<Cake> cakes;
        cakes.emplace_back(H, W);

        rep(_, N) {
            // for (auto c : cakes) cout << c.h << " " << c.w << endl;
            // cout << endl;

            int p, s;
            cin >> p >> s;
            p--;
            auto c = cakes[p];
            cakes.erase(cakes.begin() + p);
            s %= c.h + c.w;
            Cake c1, c2;
            c1 = c2 = c;
            if (s < c.w) {
                tie(c1.w, c2.w) = minmax(s, c.w - s);
            }
            else {
                s -= c.w;
                tie(c1.h, c2.h) = minmax(s, c.h - s);
            }

            cakes.emplace_back(c1);
            cakes.emplace_back(c2);
        }

        // for (auto c : cakes) cout << c.h << " " << c.w << endl;
        // cout << endl;

        V areas;
        for (auto c : cakes) {
            areas.emplace_back(c.h * c.w);
        }

        sort(all(areas));
        rep(i, N + 1) {
            cout << areas[i] << (i == N ? '\n' : ' ');
        }

        // cout << endl;
    }
}

Measured memory_bytes: 3108
def move(move_count, current, flag):
    for i in range(move_count):
        n_lis.append(num_lis[current+i])
        if flag == n:
            calculate()
            del n_lis[-1]
        else:
            move(move_count-i-1, current+i+1, flag+1)
            del n_lis[-1]
            
def calculate():
    global count
    if sum(n_lis) == s:
        count += 1

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    num_lis = [0,1,2,3,4,5,6,7,8,9]
    n_lis = []
    count = 0
    move(10,0,1)
    print count

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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a<=c && c<=b)
    cout<<min(b-c,d-c);
  else if(c<=a && a<=d)
    cout<<min(d-a,b-a);
  else cout<<0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

struct info {
    int a, b, c, d;
};

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<info>> graph(N + 1);
    for (int i = 0; i < Q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        graph[b].push_back({a, b, c, d});
    }
    int ans = 0;
    function<void(int, int, vector<int>)> dfs = [&](int now, int score, vector<int> temp) {
        int ret = 0;
        for (int i = 1; i < now; i++) {
            for (auto next : graph[i]) {
                if (temp[next.b] - temp[next.a] == next.c) ret += next.d;
            }
        }
        ans = max(ans, ret);
        if (now == N + 1) return;
        for (auto next : graph[now]) {
            int add = temp[next.a] + next.c;
            if (temp[now - 1] > add || add > M) continue;
            temp[now] = add;
            dfs(now + 1, score + next.d, temp);
        }
        temp[now] = temp[now - 1];
        dfs(now + 1, score, temp);
    };
    dfs(2, 0, vector<int>(N + 1, 1));
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <deque>

using namespace std;
int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	deque<char> st;
	
	for(char c : s) {
		switch(c) {
			case '0':
			case '1':
				st.push_back(c);
				break;
			case 'B':
				if (!st.empty()) {
					st.pop_back();
				}
				break;
		}
	}
	for (char c : st) {
		cout << c;
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <string>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll dp[100010];

int main()
{
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < m; ++i)
  {
    int a;
    cin >> a;
    mp[a]++;
  }
  dp[0] = dp[1] = 1;
  for (int i = 0; i <= n; ++i)
  {
    if (mp[i] > 0)
      dp[i] = 0;
    else if (i < 2)
      continue;
    else
      dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
  }
  cout << dp[n] << endl;

  return 0;
}


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

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

	int n;
	cin>>n;
   	vi v(n);
   	mii m;
   	int currsum = 0;
   	fo(i,n){
   		cin>>v[i];
   		currsum += v[i];
   		m[v[i]]++;
   	}
   	int q;
   	cin>>q;
   	while(q--){
   		int b,c;
   		cin>>b>>c;
   		currsum -= b*(m[b]);
   		currsum += c*(m[b]);
   		m[c] += m[b];
   		m[b] = 0;
   		cout<<currsum<<"\n";
   	}
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 10096
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;

signed main() {
    string s;
    cin >> s;
    int cnt = 1;
    s.erase(s.size()-2);
    while(1){
        int mid = s.size()/2; /* 後半の開始文字 */
        string tmp, tmp_2;
        tmp = s.substr(mid);
        tmp_2 = tmp + tmp;
        if(tmp_2 == s){
            cout << tmp_2.length() << endl;
            /* cout << tmp << endl;
            cout << tmp_2 << endl; */
            break;
        }
        cnt++;
        s.erase(s.size()-2);
    }
    return 0;
}

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

typedef pair <int, int> P;

const int N = 2e5 + 10;

vector <int> G[N];
queue <P> q;
int dist[N];
int far;

int bfs(int s){
	int u, v, d, maxx;
	memset(dist, -1, sizeof(dist));
	q.push({s, 0});
	far = s;
	maxx = dist[s] = 0;
	while (!q.empty()){
		u = q.front().first; d = q.front().second; q.pop();
		if (d > maxx){
			far = u;
			maxx = d;
		}
		for (int i = 0; i < G[u].size(); i++){
			v = G[u][i];
			if (~dist[v]) continue;
			q.push({v, d + 1});
			dist[v] = d + 1;
		}
	}
	return maxx;
}

int main(){
	int n, u, v;
	scanf("%d",&n);
	for (int i = 1; i <= n - 1; i++){
		scanf("%d %d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	bfs(1);
	if (bfs(far) % 3 == 1) printf("Second\n");
	else printf("First\n");
	return 0;
}

Measured memory_bytes: 14452
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs              v.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii                pair<int,int>
#define ll                long long
#define ull              unsigned long long
#define pb              push_back
#define mpp          make_pair
#define Okay         0
#define pi               3.14159

static ll int inf = 1e9;
const int cont = 10e5+10;
using namespace std;

void solve(){
    ll n;
   cin>>n;
   vector<ll>v(n);
   for(int i =0;i<n; i++){
    cin>>v[i];
   }
   sot(v);
   int cnt = 0;
   for(int i =0;i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k =j+1; k<n; k++){
                if(v[i] != v[j] && v[i] != v[k] && v[j] != v[k]){
                        if(v[i]+v[j] > v[k] && v[i]+v[k] > v[j] && v[j]+v[k] > v[i])
                        cnt++;
                }
            }
        }
   }
   cout<<cnt<<endl;


}

int main(){
    Fast;

    solve();

	return Okay;
}



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

typedef long long ll;
// const int INF = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, int> P;

// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

vector<int> to[200005];

mint dfs(int v) {
    mint res = 1;
    for (int u : to[v]) {
        res *= dfs(u);
    }

    return res + 1;
}

int main() {
    int n;
    cin >> n;
    vector<P> p(n);
    rep(i, n) cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());

    set<P> s;
    for (int i = n - 1; i >= 0; i--) {
        int x = p[i].first, d = p[i].second;
        while (s.size() && s.begin()->first < x + d) {
            to[i].push_back(s.begin()->second);
            s.erase(s.begin());
        }
        s.emplace(x, i);
    }

    mint ans = 1;
    for (auto x : s) {
        int v = x.second;
        ans *= dfs(v);
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 22144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;

int main(){
	int n = 0;
	cin >> s;
	rep(i,s.size()){
		if(n == 0 && s[i] == 'C')n++;
		else if(n == 1 && s[i] == 'F')n++;
	}
	if(n == 2)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

struct UnionFind {
public:
	vector <ll> par; // 
	vector <ll> siz; // 

	UnionFind() {}

	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}

	ll size(ll x) {
		return siz[root(x)];
	}
};

int main() {
	while (true) {
		ll w, h;
		cin >> w >> h;
		if (w == 0 && h == 0) return 0;
		vector<vector<int>> grid(h, vector<int>(w, 0));
		rep(i, h) {
			rep(j, w) {
				cin >> grid[i][j];
			}
		}

		vector<vector<int>> root(h, vector<int>(w, -1));

		function<void(int, int, int)> dfs = [&](int x, int y, int parent) {
			if (root[y][x] >= 0) return;
			if (!grid[y][x]) return;
			root[y][x] = parent;
			P shifts[] = {
				{0,1},{-1,1},{-1,0},{-1,-1},
				{0,-1},{1,-1},{1,0},{1,1},
			};
			for (auto p : shifts) {
				auto nx = x + p.first;
				auto ny = y + p.second;
				if (nx >= 0 && nx < w) {
					if (ny >= 0 && ny < h) {
						if(grid[ny][nx]) dfs(nx, ny, parent);
					}
				}
			}
		};
		rep(i, h) {
			rep(j, w) {
				dfs(j, i, i * w + j);
			}
		}

		unordered_set<ll> u;
		rep(i, h) {
			rep(j, w) {
				if (grid[i][j]) {
					u.insert(root[i][j]);
				}
			}
		}
		cout << u.size() << endl;
	}
	return 0;
}



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

using namespace std;

#define MOD 998244353

int n, m, r, ans;
bitset<300> bm[300];
bool u[300];
int ta;

int po(int p) {
	long long re = 1, b = 2;
	while (p) {
		if (p & 1)
			re = re * b % MOD;
		b = b * b % MOD;
		p >>= 1;
	}
	return re;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			scanf("%d", &ta);
			if (ta)
				bm[i].set(j);
		}
	for (int i = 0; i < m; i++) {
		ta = -1;
		for (int j = 0; j < n; j++)
			if (!u[j] && bm[j].test(i)) {
				u[j] = 1;
				ta = j;
				break;
			}
		if (ta == -1)
			continue;
		r++;
		for (int j = 0; j < n; j++)
			if (!u[j] && bm[j].test(i))
				bm[j] ^= bm[ta];
	}
	ans = po(n + m - 1) + MOD - po(n + m - r - 1);
	if (ans >= MOD)
		ans -= MOD;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }


//---------- 1000000007 ----------
const int MOD = 1000000007;
int m_add(int a, int b)
{
	return (a + b) % MOD;
}
int m_sub(int a, int b)
{
	return (a + MOD - b) % MOD;
}
int m_mul(int a, int b)
{
	return (a * b) % MOD;
}
int m_pow(int x, int n)
{
	if (n == 0) return 1;
	ll res = m_pow((x * x) % MOD, n / 2);
	if (n & 1) res = (res * x) % MOD;
	return res;
}
int m_divide(int a, int b)
{
	return m_mul(a, m_pow(b, MOD - 2));
}

int m_comb(int n, int r)
{
	int i;
	int p = 1;
	for (i = 1; i <= r; i++)
	{
		p = m_mul(p, (n - i + 1));
		p = m_divide(p, i);
	}
	return p;
}

int m_comb_with_rep(int n, int r)
{
	return m_comb(n + r - 1, r);
}



//---------- 最大公約数 ----------
int gcd(int x, int y)
{
	int r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}


int N, K;
int temp[100010];

signed main()
{
	cin >> N >> K;

	int ans = 0;

	for (int i = K; i >= 1; i--)
	{
		int cnt = 0;

		int a = K / i;
		int aa = m_pow(a, N);
		cnt = m_add(cnt, aa);
		
		for (int j = i + i; j <= K; j += i)
		{
			cnt = m_sub(cnt, temp[j]);
		}

		temp[i] = cnt;

		int b = m_mul(cnt, i);
		ans = m_add(ans, b);
	}

	cout << ans << endl;
}




Measured memory_bytes: 4368
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long llint;


int main(void){
    llint n,q,i,count=0;
    scanf("%lld%lld",&n,&q);
    char s[n+1];
    llint l[q],r[q],left[100000];
    scanf("%s",s);
    for(i=0;i<q;i++){
        scanf("%lld%lld",&l[i],&r[i]);
    }
    left[0]=0;
    for(i=1;i<n;i++){
        if(s[i-1]=='A' && s[i]=='C') count++;
        left[i] = count;
    }
    // for(i=0;i<q;i++){
    //     for(j=l[i]-1;j<r[i]-1;j++){
    //         if(s[j]=='A' && s[j+1]=='C') count[i]++; 
    //     }
    // }
    // for(i=0;i<n;i++){
    //     printf("%lld ",left[i]);
    // }
    for(i=0;i<q;i++){
        printf("%lld\n",left[r[i]-1]-left[l[i]-1]);
    }
    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (a - c) * (b - d) << endl;
	ggr
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;

namespace ForAtcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            var result = 1000;
            for (var a = 1; a <= Math.Sqrt(n); a++)
            {
                if (n % a == 0)
                {
                    var b = n / a;
                    if (a.ToString().Length >= b.ToString().Length && a.ToString().Length < result)
                    {
                        result = a.ToString().Length;
                    }
                    else if (b.ToString().Length > a.ToString().Length && b.ToString().Length < result)
                    {
                        result = b.ToString().Length;
                    }
                }
            }
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 27588
#include <bits/stdc++.h>
#include <time.h>
#include <assert.h>


using namespace std;



#define For(i,x,n)  for(long long i=x;i<n;i++)
#define rFor(i,x,n) for(long long i=x;i>=n;i--)
#define itFor(it,st)   for(auto it=st.begin() ; it!=st.end() ; it++)
#define MOD 1000000007
#define PI 3.141592653589793
#define INF 999999999999999999
#define N 1000005
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sp " "
#define cont continue
#define brk break

#define deb1(x)                cout<<#x<<": "<<x<<endl
#define deb2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define deb5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define deb6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed;
    cout<<setprecision(3);
    srand(time(NULL));

    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    ll suffix[n+1]={0};
    ll prefix[n+1]={0};
    For(i,0,n){
    	cin>>a[i];
    	if(i==0)
    		prefix[i] = a[i];
    	else
    		prefix[i] = prefix[i-1]^a[i];
    }
    suffix[n-1] = a[n-1];
    for(ll i=n-2 ; i>=0 ; i--)
    	suffix[i] = suffix[i+1]^a[i];
    For(i,0,n){
    	if(i==0)
    		b[i] = suffix[i+1];
    	else if(i==n-1)
    		b[i] = prefix[i-1];
    	else
    		b[i] = suffix[i+1]^prefix[i-1];
    }
    For(i,0,n)
    	cout<<b[i]<<" ";

    // ll c[n];
    // For(i,0,n){
    // 	ll val = 0;
    // 	For(j,0,n){
    // 		if(i==j)
    // 			continue;
    // 		val = val^b[j];
    // 	}
    // 	c[i] = val;
    // }
    // cout<<endl;
    // For(i,0,n)
    // 	cout<<c[i]<<" ";
    
    //cout<<"\nTime used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case
    return 0;
}

//s1.substr(1,3) - return 3 characters starting from position 1 as substring of string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan"
//num = atoi(s.c_str()); //convert string s to integer num
//n.erase(i,std::string::npos); //erase i th position in string n , decreasing string size
//s.find(b)!= std::string::npos - finds string b in string a - true if found
//cout<<"Time used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case                


Measured memory_bytes: 9864
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

ll H, W, N;
vector<P> Hpair;
set<P> already;

int main(){
  cin >> H >> W >> N;
  ll res[10];
  for(int i = 0; i < 10; i++) res[i] = 0;
  for(int i = 0; i < N; i++){
    ll a, b;  cin >> a >> b;
    Hpair.push_back(P(a-1, b-1));
  }
  sort(Hpair.begin(), Hpair.end());

  for(int i = 0; i < N; i++){
    ll h = Hpair[i].first;
    ll w = Hpair[i].second;

    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        int h2 = h-j, w2 = w-k;
        if(h2 < 0 || w2 < 0 || h2 >= H-2 || w2 >= W-2)  continue;
        if(already.find(P(h2, w2)) != already.end())  continue;
        
        int num = 0;
        for(int j2 = 0; j2 < 3; j2++){
          for(int k2 = 0; k2 < 3; k2++){
            int l = 0, r = N;
            int h3 = h2+j2, w3 = w2+k2;
            while(r - l > 1){
              int m = (l + r) / 2;
              if(Hpair[m] <= P(h3, w3)){
                l = m;
              }
              else{
                r = m;
              }
            }
            if(Hpair[l] == P(h3, w3)) num++;
          }
        }
        res[num]++;
        already.insert(P(h2, w2));
      }
    }
  }
  ll sum = 0;
  for(int i = 1; i < 10; i++) sum += res[i];
  res[0] = (H-2)*(W-2) - sum;

  for(int i = 0; i < 10; i++){
    cout << res[i] << endl;
  }

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int,int> l;
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for(int i = 0; i < N; i++) {
    l[i + A.at(i)]++;
  }
  ll ans=0;
  for(int i = 0; i < N; i++) {
    ans += l[i - A.at(i)];
  }
  cout << ans << endl;
}


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

const int maxn = 3000+10;
double dp[maxn][maxn], p[maxn];

int main() {
	//freopen("demo.in", "r", stdin);
	//freopen("demo.out", "w", stdout);
	
	int n;	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%lf", &p[i]);
	
	dp[1][0] = 1 - p[1];
	dp[1][1] = p[1];
	for (int i = 2; i <= n; i++) {
		dp[i][0] = dp[i-1][0] * (1 - p[i]);
		//dp[i][i] = dp[i-1][i-1] * p[i];
		for (int j = 1; j <= i; j++) {
			dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i]);
		}
	}
	double ans = 0.0;
	for (int i = n/2+1; i <= n; i++) ans += dp[n][i];
	printf("%.12f\n", ans);

	return 0;
}


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

int main(){
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i+=2){
		cout << s.at(i);
	}
	cout << endl;
}

Measured memory_bytes: 512
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int n;

void main() {
    scan(n);

    alias Point = Tuple!(int, "x", int, "y", int, "idx");

    auto xys = new Point[](n);

    int xi, yi;

    foreach (i ; 0 .. n) {
        scan(xi, yi);
        xys[i] = Point(xi, yi, i);
    }

    debug {
        writeln(xys);
    }

    alias Edge = Tuple!(int, "c", int, "u", int, "v");

    auto es = new Edge[](0);

    xys.sort();

    foreach (i ; 0 .. n) {
        if (i + 1 < n) es ~= Edge(xys[i + 1].x - xys[i].x, xys[i].idx, xys[i + 1].idx);
    }

    xys.sort!"a[1] < b[1]"();

    foreach (i ; 0 .. n) {
        if (i + 1 < n) es ~= Edge(xys[i + 1].y - xys[i].y, xys[i].idx, xys[i + 1].idx);
    }

    es.sort();

    debug {
        writeln(es);
    }

    auto uf = new UnionFind(n);
    long ans;
    int cnt;

    foreach (i ; 0 .. es.length) {
        if (uf.same(es[i].u, es[i].v)) continue;

        uf.unite(es[i].u, es[i].v);
        ans += es[i].c;
        cnt++;

        if (cnt == n - 1) break;
    }

    writeln(ans);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

class UnionFind
{
private:
    int[] p;
    int[] rank;

public:
    this(int N)
    {
        p = iota(N).array;
        rank = new int[](N);
    }

    int find_root(int x)
    {
        if(x != p[x]) p[x] = find_root(p[x]);
        return p[x];
    }

    bool same(int x, int y)
    {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y)
    {
        x = find_root(x);
        y = find_root(y);

        if (x == y) return;

        if (rank[x] < rank[y]) {
            p[x] = y;
        }
        else {
            p[y] = x;

            if (rank[x] == rank[y]) rank[x]++;
        }
    }
}


Measured memory_bytes: 7548
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int a;
    cin >> a;
    cout << a + pow(a, 2) + pow(a, 3) << endl;
    return 0;
}

Measured memory_bytes: 4252
def inpl(): return [int(i) for i in input().split()]

def alll(x):
    if not x:
        return 1
    return 3+2*alll(x-1)
def pate(n,x):
    if n == 0:
        return [0, 1][x == 1]
    result = 0
    if x == 0:
        return 0
    if x == alll(n):
        return 2**(n+1)-1
    if x == 2 + alll(n-1):
        return 2**n-1 + 1
    elif x > (alll(n)+1)//2:
        result += 2**n-1 + 1
        x -= (alll(n-1)+2)
    else:
        x -= 1
    return result + pate(n-1,x)      
N, X = inpl()
print(pate(N, X))

Measured memory_bytes: 3064
#include <stdio.h>
#include <limits.h>

#define min(a,b) ((a)<(b)?(a):(b))
#define N 100

int main(){
  int n,p[N+1],m[N+1][N+1];
  int j,i,l,k;
  scanf("%d",&n);

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

  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;  m[i][j]=INT_MAX;
      for(k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  printf("%d\n",m[1][n]);

  return 0;
}
      



Measured memory_bytes: 2764
n, a, b = map(int, raw_input().split())
s = raw_input()
ac = 0
bc = 0
for v in s:
    if v == 'a' and ac + bc < a + b:
        ac += 1
        print "Yes"
    elif v == 'b' and ac + bc < a + b and bc < b:
        bc += 1
        print "Yes"
    else:
        print "No"

        


Measured memory_bytes: 3204
#include <iostream>
#include <string>
using namespace std;
int main(){
	string S;
	cin >> S;
	if(S == "RRR") cout << 3 << endl;
	else if(S == "RRS" || S == "SRR") cout << 2 << endl;
	else if(S == "RSR" || S == "SSR" || S == "RSS" || S == "SRS") cout << 1 << endl;
	else if(S == "SSS") cout << 0 << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
pair<int,int> pii;
vector<int> vec;
#define LL long long
LL sel(LL hp); 
LL ans;
int main()
{
  LL h;

  cin>>h;

  ans=sel(h);

  cout<<ans<<'\n';

  return 0;
}
LL sel(LL hp){

  if(hp<=1)return 1;
  return sel(hp/2)*2+1;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from itertools import accumulate

n,k = readints()
a = readints()

for _ in range(k):
    b = [0]*(n+1)
    for i in range(n):
        b[max(0,i-a[i])]+=1
        b[min(n,i+a[i]+1)]-=1
    a = list(accumulate(b))[:-1]
    if min(a)==n:
        break
printline(a)








Measured memory_bytes: 201788
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

ll __lcm(ll a, ll b) { return a / __gcd(a, b) * b; }

int main() {
  int n; cin >> n; --n;
  ll tak, aok; cin >> tak >> aok;
  while (n--) {
    ll t, a; cin >> t >> a;
    ll add = 1;
    if (tak > t) chmax(add, (tak + t - 1) / t);
    if (aok > a) chmax(add, (aok + a - 1) / a);
    tak = t * add;
    aok = a * add;
  }
  cout << tak + aok << '\n';
  return 0;
}


Measured memory_bytes: 256
// Aizu Vol-5 0545: Party
// 2017.8.31 bal4u@uu

#include <stdio.h>
#include <string.h>

typedef struct { int a, b; } T;
T r[10003]; int w;
char f[503];

int main()
{
	int n, m, a, b, i, ans;

	while (scanf("%d%d", &n, &m) && n) {
		memset(f, 0, n+1);
		for (w = 0, i = 0; i < m; i++) {
			scanf("%d%d", &a, &b);
			if (a == 1 || b == 1) f[a] = f[b] = 1;
			else r[w].a = a, r[w++].b = b;
		}
		for (i = 0; i < w; i++) {
			a = r[i].a, b = r[i].b;
			if (f[a] == 1 && f[b] == 1) continue;
			if (f[a] == 1) f[b] = 2;
			else if (f[b] == 1) f[a] = 2;
		}
		for (ans = 0, i = 2; i <= n; i++) if (f[i]) ans++;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 684
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		
		int x = (n*(n-1))/2;
		int y = (m*(m-1))/2;
		
		System.out.println(x+y);
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 1000005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;
ll t , n, ans = 0, k;
double f = 0.5;

int main()
{
	cin >> n >> k;
	for(ll i = 0; i < n; i++){
		cin >> t;
		if(t >= k){
			ans ++;
		}
	}
	cout << ans;
	return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<ll,ll> pint;

int main(){
    int a,b,d,c,p;
    cin>>a>>b>>c>>d>>p;
    cout<<min(p*a,p<=c?b:b+(p-c)*d)<<endl;
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << ele << endl
#define print10(ele) cout << fixed << setprecision(10) << ele << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  ll n;
  cin >> n;
  lvec x(n);
  REP(i, n) cin >> x[i];
  sort(ALL(x));

  ll ans = 1e9;
  REP(p, x[n - 1] + 1) {
    ll tmp = 0;
    REP(i, n) { tmp += (x[i] - p) * (x[i] - p); }
    ans = min(ans, tmp);
  }

  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
int a,b,c,d,A,B,C;
int abs(int x);
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
scanf("%d",&d);
A=a-b;
B=b-c;
C=a-c;
if(abs(A)<=d&&abs(B)<=d||abs(C)<=d){
  printf("Yes");
}else{
  printf("No");
}
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef pair<double,double> P;
 
int main(){
  int N;
  P ansA=P(-1,-1),ansB=P(-1,-1);
  int F,A,T,X,Y;
  int f,a,t,x,y;
  cin>>N>>F>>A>>T>>X>>Y;
  for(int i=1;i<N;i++){
    cin>>f>>a>>t>>x>>y;
    if(T==t&&A!=a){
      P d=P( sqrt((X-x)*(X-x)+(Y-y)*(Y-y)) ,F-f);      
      if(t==0)ansA=max(ansA,d);
      else ansB=max(ansB,d);
    }
    F=f;A=a;T=t;X=x;Y=y;
  }
  if(ansA.first<0)printf("-1 -1\n");
  else printf("%.8f %.8f\n",ansA.first,-ansA.second/60.0);
  if(ansB.first<0)printf("-1 -1\n");
  else printf("%.8f %.8f\n",ansB.first,-ansB.second/60.0);
  return 0;
}

Measured memory_bytes: 3236
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cctype>
#define RI register int
#define Tp template <typename T>
#define y1 DEEP_DARK_FANTACY
#define y2 VAN
using namespace std;
inline char nc(){
	static char buf[100000],*L=buf,*R=buf;
	return L==R&&(R=(L=buf)+fread(buf,1,100000,stdin),L==R)?EOF:*L++;
}
inline void read(int& ret){
	ret=0; int f=1;char ch=nc();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=nc();}
	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=nc();
	ret*=f;
}
const int N=2e6+5;
int x1,x2,y1,y2,n,F[N],top,dec;
struct dat{int x,y;}p[N];
double Ans;
inline bool valid(int i){
	return ((p[i].x>=x1&&p[i].x<=x2)||(p[i].x>=x2&&p[i].x<=x1))&&((p[i].y>=y1&&p[i].y<=y2)||(p[i].y>=y2&&p[i].y<=y1));
}
inline bool cmp1(dat A,dat B){return A.x<B.x||(A.x==B.x&&A.y<B.y);}
inline bool cmp2(dat A,dat B){return A.x<B.x||(A.x==B.x&&A.y>B.y);}
int main(){
	read(x1), read(y1), read(x2), read(y2), read(n);
	for (int i=1;i<=n;i++) read(p[i].x), read(p[i].y);
	if (x1>x2) swap(x1,x2), swap(y1,y2);
	F[0]=-2e9;
	if (y1<y2){
		sort(p+1,p+n+1,cmp1);
		for (int i=1;i<=n;i++) if (valid(i))
			if (F[top]<p[i].y) F[++top]=p[i].y; else F[upper_bound(F+1,F+top+1,p[i].y)-F]=p[i].y;
	} else{
		sort(p+1,p+n+1,cmp2);
		for (int i=1;i<=n;i++) if (valid(i))
			if (F[top]<-p[i].y) F[++top]=-p[i].y; else F[upper_bound(F+1,F+top+1,-p[i].y)-F]=-p[i].y;
	}
	double delta=20.0-2.0*M_PI_4*10.0;
	if (top==min(abs(x1-x2),abs(y1-y2))+1) 	Ans=(abs(x2-x1)+abs(y1-y2))*100.0-(top-1)*1.0*delta+(M_PI*10.0-20);
		else Ans=((x2-x1)+abs(y1-y2))*100.0-top*1.0*delta;
	printf("%.11lf\n",Ans);
	return 0;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main() {
    ll N,M,r=0;
    cin >> N >> M;
    vector<ll> X(M),d(M-1);

    if(N >= M) {
        cout << 0 << endl;
        return 0;
    }

    rep(i,M)
        cin >> X.at(i);
    sort(X.begin(), X.end());

    rep(i,M-1)
        d.at(i) = X.at(i+1)-X.at(i);
    sort(d.begin(), d.end());

    rep(i,min(M-N,M-1))
        r += d.at(i);
    cout << r << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int compare(int x[3],int n){
	int i = 0,c=0;
	for (; i < n-1; i++){
		if (x[i]<x[i + 1])
			c++;
	}
	if (c == n - 1)
		return 1;
	else
		return 0;
}

int main(void){
	int x[3] = { 0 };
	int n = sizeof(x) / sizeof(x[0]);

	int i = 0;
	for (; i < n; i++){
		scanf("%d", &x[i]);
	}
	
	if (compare(x, n) == 1)
		printf("Yes\n");
	else
		printf("No\n");


	return 0;
}


Measured memory_bytes: 2048
require 'strscan'

words = %w(dream dreamer erase eraser).collect{|i| i.reverse}
ALL_WORDS_REGEXP = Regexp.compile(words.join("|"))

scanner = StringScanner.new(ARGF.gets.chomp.reverse)
str = scanner.string

until scanner.eos?
  unless scanner.scan(ALL_WORDS_REGEXP)
    puts "NO"
    exit
  end
end

puts "YES"


Measured memory_bytes: 14616
use strict;
use warnings;

my ($n, $a, $b);
{
    my $in = <STDIN>;
    ($n, $a, $b) = split(" ", $in);
}
my $MOD = 10 ** 9 + 7;
sub power
{
    my ($a, $b) = @_;
    if ($b == 0)
    {
        1;
    }
    elsif ($b % 2 == 0)
    {
        power($a ** 2 % $MOD, $b / 2);
    }
    else{
        $a * power($a, $b - 1) % $MOD;
    }
}
my $inv = sub
{
    my $n = shift;
    power($n, $MOD - 2) % $MOD;
};
my $combination = sub
{
    my ($n, $k) = @_;
    my $a = 1;
    my $b = 1;
    for (my $i=0; $i<$k; $i++)
    {
        $a *= $n - $i;
        $a %= $MOD;
        $b *= $i + 1;
        $b %= $MOD;
    }
    $a * $inv->($b) % $MOD;
};
my $ans = power(2, $n) - 1;
$ans += $MOD - $combination->($n, $a);
$ans += $MOD - $combination->($n, $b);
print ($ans % $MOD), "\n";

Measured memory_bytes: 768