akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

int main() {
  ll n, m;
  scanf("%lld %lld", &n, &m);

  ll a1 = (n * (n - 1)) / 2;

  ll a2 = (m * (m - 1)) / 2;

  ll ans = a1 + a2;

  cout << ans << endl;
}


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

namespace AOJ2
{
    class Program
    {

        static void Main(string[] args)
        {
            List<int> resultList = new List<int>();

            while (true)
            {
                int input = int.Parse(Console.ReadLine());
                if (input == 0)
                {
                    break;
                }

                resultList.Add(GetMinPrice(input));
            }

            foreach (int n in resultList)
            {
                Console.WriteLine(n);
            }

        }

        static int GetMinPrice(int amount)
        {
            int cMax = amount / 500;
            int bMax = amount / 300;
            int aMax = amount / 200;

            int price = 0;
            for (int i = cMax; i >= 0; i--)
            {
                for (int j = bMax; j >= 0; j--)
                {
                    for (int k = aMax; k >= 0; k--)
                    {
                        if (i * 500 + j * 300 + k * 200 == amount &&
                            (price == 0 ||
                             price > GetPrice(k,j,i)))
                        {
                            price = GetPrice(k, j, i);
                        }
                    }
                }
            }

            return price;
        }

        static int GetPrice(int a, int b, int c)
        {
            return GetAShop(a) + GetBShop(b) + GetCShop(c);
        }

        static int GetCShop(int number)
        {
            int discountNumber = number / 3;
            int discountPrace = 850 * 3 * 88 / 100;

            return discountNumber * discountPrace + 850 * (number % 3);
        }

        static int GetBShop(int number)
        {
            int discountNumber = number / 4;
            int discountPrace = 550 * 4 * 85 / 100;

            return discountNumber * discountPrace + 550 * (number % 4);
        }

        static int GetAShop(int number)
        {
            int discountNumber = number / 5;
            int discountPrace = 380 * 5 * 80 / 100;

            return discountNumber * discountPrace + 380 * (number % 5);
        }
    }
}

Measured memory_bytes: 5660
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<50
#define fst first
#define snd second
#define pb push_back
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(int itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(int itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<ll,ll> P;

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

  int n;
  cin >> n;
  
  int a[n];
  REP(i,n) cin >> a[i];
  
  bool f;
  int cnt = 1;
  REP(i,n-1){
    if(a[i] == a[i+1]) continue;
    f = a[i]<a[i+1]?true:false;
    while(i<n-1){
      if(f?a[i]<=a[i+1]:a[i]>=a[i+1]){
        i++;
        continue;
      }
      cnt++;
      break;
    }
  }
  
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main() {
	int a; scanf("%d",&a);
	printf("%d\n",(a+(int)pow(a,2)+(int)pow(a,3)));
}


Measured memory_bytes: 4184
import math

A,B,H,M=map(int,input().split())

S=(H/12)*360+(M/60)*(360/12)
L=(M/60)*360
S-L

Lens=A**2+B**2-2*A*B*math.cos((S-L)*math.pi/180)
print(Lens**(1/2))

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

long long gcd(long long x,long long y){
  if(x%y==0) return y;
  return gcd(y,x%y);
}

int main() {
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long cn_c=b/c-a/c;
  if(a%c==0) cn_c++;
  long long cn_d=b/d-a/d;
  if(a%d==0) cn_d++;
  long long c_d=c/gcd(c,d)*d;
  long long cn_c_d=b/c_d-a/c_d;
  if(a%c_d==0) cn_c_d++;
  long long count=cn_c+cn_d-cn_c_d;
  cout<<b-a+1-count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	ll n,m,l;
  scanf("%lld %lld %lld",&n,&m,&l);
  vector<vector<ll> > veca(n, vector<ll>(m));
  vector<vector<ll> > vecb(m, vector<ll>(l));
  vector<vector<ll> > vecc(n, vector<ll>(l));
  rep(i,n){
    rep(j,m){
      cin >> veca.at(i).at(j);
    }
  }
  rep(i,m){
    rep(j,l){
      cin >> vecb.at(i).at(j);
    }
  }
  ll num = 0;
  rep(i,n){
    rep(j,l){
      rep(k,m){
        num += (veca.at(i).at(k))*(vecb.at(k).at(j));
      }
      if (j<l-1) {printf("%lld ",num);}
      else {printf("%lld\n",num);}
      num = 0;
    }
  }
}


Measured memory_bytes: 3276
// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"
#define ret return
#define F first
#define S second
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define all(v) (v).begin(),(v).end()

/*##################################################################################*/


/*bool prime[100000] ;
vector < int > pr;
void calculateprime()
{
    prime[0] = prime[1] = true;
    for(int i = 2 ; i <= 100000 ; i++)
    {
        if(prime[i] == false)
        {
            pr.pb(i);
            for(ll j = i*i ; j <= 100000 ; j += i )
            {
                prime[j] = true;
            }
        }
    }
}
*/


void customrun(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


bool comp(const pair < ll , ll >  &a, const pair < ll , ll > &b ){
    if(a.F == b.F) return a.S < b.S;
    return a.F > b.F;
}

void solve();

int main() {
    clock_t begin = clock();

    fast();
    customrun();
    ll t = 1;
    //cin>>t;
    //calculateprime();
    mfor(i,1,t+1,1)
    {
        //cout<<"Case #"<<i<<": \n";
        solve();
    }
    clock_t end = clock();
    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    //cout<<"\ntime spent is "<<time_spent;
    return 0;
}


void solve(){
    int a ,b;
    in(a)>>b;

    if(a > 9 or b > 9){
        out(-1);
        ret;
    }

    out(a*b);
}


Measured memory_bytes: 3684
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
long long L, M, R;
pair <long long, long long> maintain(long long l, long long r)
{
	if (l >= 0)
		return make_pair(l, min(M, r));
	else if (r <= 0)
		return make_pair(-r, min(M, -l));
	else
		return make_pair(0, min(M, max(r, -l)));
}
vector <pair <long long, long long> > maintain(vector <pair <long long, long long> > b)
{
	vector <pair <long long, long long> > ret, a;
	int n = b.size();
	for (int i = 0; i < n; ++ i)
		if (b[i].first <= b[i].second)
			a.push_back(b[i]);
	if (a.empty())
		return a;
	sort(a.begin(), a.end());
	n = a.size();
	ret.push_back(a.front());
	for (int i = 1; i < n; ++ i)
		if (a[i].first <= ret.back().second)
			ret.back().second = max(ret.back().second, a[i].second);
		else
			ret.push_back(a[i]);
	return ret;
}
vector <pair <long long, long long> > add(vector <pair <long long, long long> > a, long long x)
{
	vector <pair <long long, long long> > ret;
	int n = a.size();
	for (int i = 0; i < n; ++ i)
	{
		long long l = a[i].first, r = a[i].second;
		ret.push_back(maintain(l + x * R, r + x * L));
		ret.push_back(maintain(l - x * L, r - x * R));
	}
	return maintain(ret);
}
int main()
{
	int n;
	scanf("%d%lld%lld%lld", &n, &L, &M, &R);
	R *= 2;
	M *= 2;
	vector <pair <long long, long long> > now;
	now.push_back(make_pair(0, 0));
	for (int i = 0; i < n; ++ i)
	{
		long long x;
		scanf("%lld", &x);
		now = add(now, x);
		if (now.empty())
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  string a;
  cin >> a;
  if(a[0] == '9'||a[1]=='9'){
    cout << "Yes"<<endl;
  }else{
    cout << "No"<<endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,k;
    cin >> n >>k;
    vector<int>data(n);
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a;
            a--;
            data[a] = 1;
        }
    }
    int cnt = 0;
    rep(i,n)if(data[i]==0)cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
const int N=1e6+11;
char s[N];
int n,u[N],v[N],top,t;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	rep(i,1,n-1)
		if(s[i]!=s[n-i]){
			puts("-1");
			return 0;
		}
	if(s[n]=='1'||s[1]=='0'){
		puts("-1");
		return 0;
	}
	u[1]=n-1,v[1]=n;
	t=n-1;
	top=n-1;
	rep(i,2,n-1)
		if(s[i]=='1')
			u[i]=--t,v[i]=top,top=t;
		else
			u[i]=--t,v[i]=top;
	rep(i,1,n-1)
		printf("%d %d\n",u[i],v[i]);
	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second



signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(((a*b)%2)&&((c+d)%2))cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n = Integer.parseInt(in.readLine());
			if(n == 0){
				break;
			}
			int aa = 0;
			int ba = 0;
			for(int i= 0; i < n;i++){
				String s = in.readLine();
				String[] ss = s.split(" ");
				int a = Integer.parseInt(ss[0]);
				int b = Integer.parseInt(ss[1]);
				if(a < b){
					ba = ba + a + b;
				}
				else if(b < a){
					aa = aa + a + b;
				}
				else{
					aa = aa + a;
					ba = ba + b;
				}	
			}
			System.out.println(aa+" "+ba);
		}	

	}

}

Measured memory_bytes: 39324
#include <iostream>
#include <utility>
#include <vector>
#include <set>
using namespace std;

int main(){
  int m;
  while(cin >> m, m){
    vector<pair<int,int>> C;
    for(int i = 0; i < m; ++i){
      int x, y;
      cin >> x >> y;
      C.emplace_back(x,y);
    }
    int n;
    cin >> n;
    set<pair<int,int>> D;
    for(int i = 0; i < n; ++i){
      int x, y;
      cin >> x >> y;
      D.emplace(x,y);
    }
    for(auto p : D){
      int dx = p.first-C[0].first;
      int dy = p.second-C[0].second;
      bool f = true;
      for(int j = 0; j < m; ++j){
        auto q = C[j];
        q.first += dx, q.second += dy;
        if(!D.count(q)){
          f = false;
          break;
        }
      }
      if(f){
        cout << dx << " " << dy << endl;
        break;
      }
    }
  }
}



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

int main()
{
	int fee[5], t_min = 1000, b_min = 1000;
	cin >> fee[0] >> fee[1] >> fee[2] >> fee[3];

	t_min = (fee[0] < fee[1]) ? fee[0] : fee[1];
	b_min = (fee[2] < fee[3]) ? fee[2] : fee[3];
	cout << t_min + b_min << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;

string s;

ll bfs(int i, int j, ll sum) {
	if (j == s.size()-1) {
		return sum + stoll(s.substr(i, j + 1 - i));
	}
	return bfs(i, j + 1, sum)
		+bfs(j + 1, j + 1, sum + stoll(s.substr(i, j + 1 - i)));
}

int main()
{		
	cin >> s;
	cout<<bfs(0, 0, 0);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int MAXL = 128;
const int Q = 850;
int query(string s){
	cout<<"? "<<s<<endl;
	int v; cin>>v; return v;
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	const string chars = 
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		"abcdefghijklmnopqrstuvwxyz"
		"0123456789";
	assert(chars.size() == 62);
	auto get_cnt = [&](char c) -> int {
		return MAXL - query(string(MAXL, c));
	};
	vector<int> cnts(62);
	int L = 0;
	for (int i = 0; i < 62; i++) {
		cnts[i] = get_cnt(chars[i]);
		L += cnts[i];
	}
	auto is_subseq = [&](string q) -> int {
			return query(q) == L - int(q.size());
	};
	auto combine = [&](const string& a, const string& b) -> string {
		string res;
		int ia = 0, ib = 0;
		while (ia < int(a.size()) && ib < int(b.size())) {
			if (is_subseq(a.substr(0, ia+1) + b.substr(ib))) {
				res += a[ia++];
			} else {
				res += b[ib++];
			}
		}
		while (ia < int(a.size())) res += a[ia++];
		while (ib < int(b.size())) res += b[ib++];
		return res;
	};
	function<string(int , int)> solve = [&](int lx, int rx) {
		if (lx + 1 == rx) {
			return string(cnts[lx], chars[lx]);
		} else {
			return combine(solve(lx, (lx + rx) / 2), solve((lx + rx) / 2, rx));
		}
	};
	string ans = solve(0, 62);
	cout << '!' << ' ' << ans << '\n';
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

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

int main(){
	int n, k, t;
	scanf("%d%d%d", &n, &k, &t);
	int mx = t, g = t;
	f(i, 1, n){
		scanf("%d", &t);
		g = gcd(g, t);
		mx = max(mx, t);
	}
	if (k <= mx && k % g == 0)printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 256
x,y = map(int,input().split())
if x==0 and y>0:
  print(y)
elif x==0 and y<0:
  print(abs(y)+1)
elif y==0 and x>0:
  print(abs(x)+1)
elif y==0 and x<0:
  print(abs(x))
elif x>0 and y>0:
  if x>y:
    print(2+(x-y))
  else:
    print(y-x)
elif x>=0 and y<0:
  a = abs(x+y)
  print(1+a)
elif x<=0 and y>0:
  a = abs(y+x)
  print(a+1)
else:
  if x>y:
    print(2+(x-y))
  else:
    print(y-x)
  

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <unordered_map>
 
using namespace std;
using ll = long long;
// constexpr int MOD = 1e9+7;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){ return a/gcd(a, b)*b; };
 
#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define RemoveIf(a, f) a.erase(remove_if(Range(a), f), a.end())
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Tie(T, ...)  T __VA_ARGS__; tie(__VA_ARGS__)

#include <queue>

int main(void){
    Cin(int, n);
    Cins(int, 3*n, a);

    vector<ll> u(n+1);
    {
        priority_queue<int, vector<int>, greater<int>> q;
        For(i, n) q.push(a[i]), u[0] += a[i];
        For(i, n){
            q.push(a[n+i]);
            u[i+1] = u[i] + a[n+i] - q.top();
            q.pop();
        }
    }
    Reverse(a);
    vector<ll> l(n+1);
    {
        priority_queue<int> q;
        For(i, n) q.push(a[i]), l[0] += a[i];
        For(i, n){
            q.push(a[n+i]);
            l[i+1] = l[i] + a[n+i] - q.top();
            q.pop();
        }
    }
    ll ans = u[n] - l[0];
    For(i, n) ans = max(ans, u[i] - l[n-i]);
    Cout(ans);
}



Measured memory_bytes: 3832
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) { //gcdを返す
	if(a == 0){
		return b;
	} else if (b == 0){
		return a;
	} else {
	  if(a < b) return gcd(b, a);
	  ll r;
	  while ((r=a%b)) {
	    a = b;
	    b = r;
	  }
	  return b;
	}
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}


int main(){
	string s;
	cin >> s;
	string ans = "";
	for(ll i = 0; i < s.size(); i++){
		if(i % 2 == 0){
			ans += s.substr(i,1);
		}
	}
	cout << ans << endl;
}

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

typedef long long int ll;

int main(){

  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++)
    cin>>A[i];
  sort(A.begin(),A.end());
  vector<ll> S(N,0);
  S[0]=A[0];
  for(int i=1;i<N;i++)
    S[i]=A[i]+S[i-1];
  int ans=1;
  for(int i=N-2;i>=0;i--){
    if(2*S[i]>=A[i+1])
      ans++;
    else
      break;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1408
pos=input()
pos=pos.split()
N=int(pos[0])
P=int(pos[1])
T=int(pos[2])
point=[0]*N

for i in range(0,T):
    c=input()
    point[int(c)-1]+=1
point=[P-T+d for d in point]
for i in range(0,N):
    if(point[i]>0):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 7932
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
  int a, b, A = 0, B = 0;
  scanf("%d %d", &a, &b);
  rep(i ,b) A += pow(10,i) * a;
  rep(i ,a) B += pow(10,i) * b;
  if (A >= B) printf("%d\n", (int)A);
  else printf("%d\n", (int)B);
  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

struct LeastCommonAncestor {
   public:
    LeastCommonAncestor(int n, int root = 0)
        : root(root),
          graph(n),
          parent(ilogb(n) + 1, vector<int>(n)),
          depth(n) {}

    void add_edge(int a, int b) {
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    void init() {
        dfs(root, -1, 0);

        for (int k = 0; k + 1 < parent.size(); ++k) {
            for (int v = 0; v < graph.size(); ++v) {
                if (parent[k][v] < 0) {
                    parent[k + 1][v] = -1;
                } else {
                    parent[k + 1][v] = parent[k][parent[k][v]];
                }
            }
        }

        initialized = true;
    }

    int query(int u, int v) {
        if (!initialized) {
            init();
        }

        if (depth[u] > depth[v]) {
            swap(u, v);
        }

        for (int k = 0; k < parent.size(); ++k) {
            if ((depth[v] - depth[u]) >> k & 1) {
                v = parent[k][v];
            }
        }

        if (u == v) {
            return u;
        }

        for (int k = parent.size() - 1; k >= 0; k--) {
            if (parent[k][u] != parent[k][v]) {
                u = parent[k][u];
                v = parent[k][v];
            }
        }

        return parent[0][u];
    }

   private:
    void dfs(int v, int p, int d) {
        parent[0][v] = p;
        depth[v] = d;
        for (int to : graph[v]) {
            if (to != p) {
                dfs(to, v, d + 1);
            }
        }
    }

   private:
    int root;
    vector<vector<int>> graph;
    vector<vector<int>> parent;
    vector<int> depth;

    bool initialized = false;
};

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

    int n;
    cin >> n;

    LeastCommonAncestor lca(n);

    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;

        for (int j = 0; j < k; ++j) {
            int c;
            cin >> c;

            lca.add_edge(i, c);
        }
    }

    lca.init();

    int q;
    cin >> q;

    for (int i = 0; i < q; ++i) {
        int u, v;
        cin >> u >> v;

        cout << lca.query(u, v) << endl;
    }
}

Measured memory_bytes: 18204
#include <iostream>
#include <vector>
#include <cstring>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

#define debug(x) cout << #x << " is " << x << endl;

using namespace std;

typedef pair<int, int> P;

const int INF = 1 << 29;

struct edge{
	int to, cap, rev;
	edge(int t, int c, int r):to(t), cap(c), rev(r){}
};

const int N = 101;
vector<vector<edge> > G;
int visit[3*N];

void add_edge(int from, int to, int cap){
	G[from].push_back(edge(to, cap, G[to].size()));
	G[to].push_back(edge(from, 0, G[from].size()-1));
}

int dfs(int s, int g, int f){
	if(s == g) return f;
	visit[s] = 1;
	rep(i, G[s].size()){
		if(visit[G[s][i].to] || G[s][i].cap <= 0) continue;
		int d = dfs(G[s][i].to, g, min(f, G[s][i].cap));
		if(d > 0){
			G[s][i].cap -= d;
			G[G[s][i].to][G[s][i].rev].cap += d;
			return d;
		}
	}
	return 0;
}

int ford_fulkerson(int s, int g){
	int flow = 0;
	while(1){
		memset(visit, 0, sizeof(visit));
		int f = dfs(s, g, INF);
		if(f == 0) return flow;
		flow += f;
	}
}

int v[N];
int dist[N][N];
int main(){
	int n, m, l;
	while(cin >> n >> m >> l){
		rep(i, n) rep(j, n) dist[i][j] = INF;
		rep(i, m){
			int a, b, d;
			cin >> a >> b >> d;
			a--, b--;
			dist[a][b] = dist[b][a] = d;
		}
		rep(i, n) rep(j, n) rep(k, n) dist[j][k] = min(dist[j][k], dist[j][i]+dist[i][k]);

		//rep(i, n){
		//	rep(j, n) cout << dist[i][j] << ' ';
		//	cout << endl;
		//}cout << endl;

		G.clear();
		G.resize(2*n+2);
		int s = 2*n, g = 2*n+1;
		rep(i, n){
			int p;
			cin >> p;
			add_edge(s, i, p);
		}
		rep(i, n){
			int k;
			cin >> k;
			add_edge(n+i, g, k);
		}
		rep(i, n) rep(j, n){
			if(i == j || dist[i][j] < l){
				add_edge(i, j+n, INF);
			}
		}
		cout << ford_fulkerson(s, g) << endl;
	}

	return 0;
}

Measured memory_bytes: 1560
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>

using namespace std;

int main(){

	int n,x;
	cin >> n >> x;
	int m[n];
	for(int i = 0; i < n; i++){
		cin >> m[i];
	}
	sort(m,m+n);
	int count =0, nokori= 0,tukau= 0;
	for(int i = 0; i < n; i++){
		tukau += m[i];
		count ++;
	}
	nokori = x-tukau;
	while( nokori >= m[0]){
		nokori -= m[0];
		count ++;
	}
	cout << count <<endl;

	return 0;
}

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

ll gcd(ll m,ll n){
  if(n==0) return m;
  return gcd(n,m%n);
}
ll H,W;
vector<string> A(1010);

int main(){
  cin >> H >> W;
  for(int i=0;i<H;i++){
    string s;
    cin >> s;
    A[i]=s;
  }
  queue<pair<pair<ll,ll>,ll>> t;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(A[i][j]=='#')
        t.push(make_pair(make_pair(i,j),0));

    }
  }
  //cout << t.size()<<endl;
  ll ans=0;
  while(!t.empty()){
    ll y = t.front().first.first;
    ll x = t.front().first.second;
    ll i = t.front().second; 
    if(y+1<H)
      if(A[y+1][x]!='#'){
        t.push(make_pair(make_pair(y+1,x),i+1));
        A[y+1][x]='#';
      }
    if(y-1>=0)
      if(A[y-1][x]!='#'){
        t.push(make_pair(make_pair(y-1,x),i+1));
        A[y-1][x]='#';
      }
    if(x+1<W)
      if(A[y][x+1]!='#'){
        t.push(make_pair(make_pair(y,x+1),i+1));
        A[y][x+1]='#';
      }
    if(x-1>=0)
      if(A[y][x-1]!='#'){
        t.push(make_pair(make_pair(y,x-1),i+1));
        A[y][x-1]='#';
      }
    ans=i;
    t.pop();
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 25524
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int X = Integer.parseInt(S[1]);
    
    String[] T = sc.nextLine().split(" ");
    int[] num = new int[N];
    for(int i = 0; i < N; i++){
      num[i] = Integer.parseInt(T[i]);
    }

    long ans = Math.abs(X - num[0]);
    for(int i = 1; i < N; i++){
      long n = Math.abs(X - num[i]);
      ans = gcd(ans, n);
    }
    
    System.out.println(ans);
  }
  
  public static long gcd(long m, long n) {
    if(m < n){
      return gcd(n, m);
    }
    
    if(n == 0){
      return m;
    }
    
    return gcd(n, m % n);
  }
}

Measured memory_bytes: 46920
def main():
    r1 = input()
    n, m = map(int, r1.split(" "))
    v = ["~"] * n
    for t in range(m):
        r = input()
        s, c = map(int, r.split(" "))
        s -= 1
        if v[s] != "~" and v[s] != str(c):
            print(-1)
            return
        v[s] = str(c)
    if n >= 2 and v[0] == '~':
        v[0] = "1"
    for x in range(n):
        if v[x] == '~':
            v[x] = "0"
    sv = "".join(v)
    res = int(sv)
    res_str = str(res)
    if len(res_str) != n:
        print(-1)
        return
    print(res_str)

main()
    

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    char c1,c2,c3;
    char c4,c5,c6;
    char c7,c8,c9;
    cin>>c1>>c2>>c3>>c4>>c5>>c6>>c7>>c8>>c9;
    
    cout<<c1<<c5<<c9<<endl;
}

Measured memory_bytes: 3680
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int[] a = in.nextIntArray(4);
            int x = Integer.compare(a[0] + a[1], a[2] + a[3]);
            out.println(x == 0 ? "Balanced" : x == 1 ? "Left" : "Right");
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

    }
}



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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){

  string s;
  cin >> s;
  int res = 0;
  if(s[1] == 'S'){
    if(s[0] == 'R' || s[2] == 'R')cout << 1 << "\n";
    else cout << 0 << "\n";
  }else{
    if(s[0] == 'R' || s[2] == 'R'){
      if(s[0] == 'R'  &&  s[2] == 'R')cout << 3 << "\n";
      else cout << 2 << "\n";
    }else{
      cout << 1 << "\n";
    }

  }


  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


int main() {
  string s;
  cin >> s;
  FOR(i,0,2){
    if(s[i]=='1') s[i] = '9';
    else s[i] = '1';
  }

  cout << s << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	int n, k;
	cin >> n >> k;
	set<int> d;
	rep(i, k) {
		int tmp;
		cin >> tmp;
		d.insert(tmp);
	}
	for(int i = n; ; i++) {
		bool ok = true;
		set<int> now;
		int tmp = i;
		while(tmp) {
			now.insert(tmp%10);
			tmp /= 10;
		}
		for(int t: now) {
			if(d.count(t)) ok = false;
		}
		if (ok) {
			cout << i << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int i,j,H,W;
  while (1){scanf("%d %d",&H,&W);if(W==0&&H==0){break;}
for(j=0;j<H;j++){for(i=0;i<W;i++){
 if (i%2==0&&j%2!=0){printf(".");}
 else if (i%2!=0&&j%2==0){printf(".");}
else{printf("#");}
}
printf("\n");}
 printf("\n");}
 
 return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int n, K;
	cin >> n >> K;
	vector<int> k(30);
	REP(i, 30) {
		k[i] = K % 2;
		K /= 2;
	}
	reverse(all(k));
	vector<int> a(n), b(n);
	REP(i, n) {
		cin >> a[i] >> b[i];
	}
	vector<vector<int>> bit(n, vector<int>(30, 0));
	REP(i, n) {
		int t = a[i];
		REP(j, 30) {
			bit[i][j] = t % 2;
			t /= 2;
		}
		reverse(all(bit[i]));
	}
	ll res = 0;
	REP(i, 30) {
		if (k[i] == 1) {
			ll temp = 0;
			REP(j, n) {
				bool flag = true;
				REP(l, i) {
					if (bit[j][l] > k[l]) {
						flag = false;
						break;
					}
				}
				if (bit[j][i] == 1) {
					flag = false;
				}
				if (flag) {
					temp += b[j];
				}
			}
			chmax(res, temp);
		}
	}
	ll temp = 0;
	REP(j, n) {
		bool flag = true;
		REP(l, 30) {
			if (bit[j][l] > k[l]) {
				flag = false;
				break;
			}
		}
		if (flag) {
			temp += b[j];
		}
	}
	chmax(res, temp);
	put(res);
	return 0;
}


Measured memory_bytes: 16000
n=int(input())
t,a=map(int,input().split())
i=0;
s=1e9;
d=0;
for h in map(int,input().split()):
    i+=1
    now=abs((t-a)*1000-h*6)
    if now<s:
        s=now
        d=i
print(d)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e9
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
vector<pair<int,int>>v;
ll m,n;
char a[1009][1009];
ll dp[1009][1009];
ll solve(int i,int j)
{
   if(i<0||i>=n||j<0||j>=m||a[i][j]=='#')
        return 0;
    if(i==n-1&&j==m-1)
        return 1;
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll ans=0;
    ans+=solve(i+1,j);
    ans+=solve(i,j+1);
    return dp[i][j]=ans%mod;
}
int main()
{
    //freopen("out.text","w",stdout);
    _IOS();
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    cout<<solve(0,0);
}

//


Measured memory_bytes: 12652
#include<stdio.h>

#define N 100

int main (){
  int M[N][N];
  int n, u, v, k, i, j;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++)
    M[i][j] = 0;
  }

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

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      if(j) printf(" ");
      printf("%d", M[i][j]);
    }
    printf("\n");
  }

  return 0;

}

Measured memory_bytes: 640
//abc114_a.cpp
//Sun Dec  2 20:52:35 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	if (x==7||x==5||x==3){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

struct UFT{ //O(loga(n))
    int n;
    vi d, r;
    UFT(int n) : n(n), d(n, -1), r(n, 0){};
    int root(int i){
        if(d[i] < 0) return i;
        return d[i] = root(d[i]);
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return false;
 
        if(r[x] < r[y]) swap(x, y);
        else if(r[x] == r[y]) r[x]++;
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    int size(int i){
        return -d[root(i)];
    }
};

struct Edge
{
	int from, to, cost;
};
vector<Edge> es;
typedef pair<pii, int> P;

int main(){
	int n;
	cin >> n;
	vi x(n), y(n);
	rep(i, n) cin >> x[i] >> y[i];
	vector<pair<pii, int>> v(n);
	rep(i, n) v[i].fi = {x[i], y[i]}, v[i].se = i;
	sort(all(v), [&](P a, P b){return a.fi.fi < b.fi.fi;});
	rep(i, n-1) {
		es.pb({v[i].se, v[i+1].se, v[i+1].fi.fi-v[i].fi.fi});
	}
	sort(all(v), [&](P a, P b){return a.fi.se < b.fi.se;});
	rep(i, n-1) {
		es.pb({v[i].se, v[i+1].se, v[i+1].fi.se-v[i].fi.se});
	}
	UFT uf(n);
	sort(all(es), [&](Edge a, Edge b){return a.cost<b.cost;});
	ll ans = 0LL;
	for(auto& e : es) {
		if(uf.same(e.from, e.to)) continue;
		//cout << e.from << " " << e.to <<" " << e.cost << endl;
		ans += e.cost;
		uf.unite(e.from, e.to);
	}
	cout << ans << endl;
}


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

int W,H;
int C[111][111];

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

bool used[111][111];
void solve(int x,int y){
  if( used[x][y] ) return;
  used[x][y] = true;
  for(int i=0;i<8;i++){
    int nx = x + dx[i], ny = y + dy[i];
    if( nx < 0 || ny < 0 || nx >= W || ny >= H ) continue;
    if( C[nx][ny] == 1 )
      solve( nx, ny );
  }
}

int main(){

  while(  cin >> W >> H && (W||H) ){
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> C[j][i];
      }
    }
    
    int res = 0;
    memset(used,0,sizeof(used));
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if( !used[j][i] && C[j][i] == 1 )
	  {
	    res++;
	    solve(j,i);
	  }
      }
    }
    cout << res << endl;
  }


}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define INF 0x3f3f3f3f
#define MS(x, i) memset(x, i, sizeof x)
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define MOD 998244353
#define NOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int num[MAXN];
int sum[MAXN];

inline int read()
{
    int res = 0, sgn = 1;
    char c = getchar();

    while(c < '0' || c > '9')
    {
        if(c == '-')
            sgn = -1;
        c = getchar();
    }

    while(c >= '0' && c <= '9')
    {
        res = res * 10 + c - '0';
        c = getchar();
    }

    return res * sgn;
}

int main()
{
   int n = read(), k = read();
   for(int i = 1; i <= n; i++)
    {
        num[i] = read();
        sum[i] = sum[i - 1] + num[i];
    }

    int maxx = -1;

    for(int i = k; i <= n; i++)
    {
        maxx = max(maxx, sum[i] - sum[i - k]);
    }

    printf("%.12f\n", (maxx + k) * 1.0 / 2);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
#define br "\n"
#define MAX  1000001
#define ff first
#define ss second
ll mod = 1e9 + 7;

void solve(){
    ll n;
    cin >> n;
    vll v(n);
    rep(i,0,n) cin >> v[i];
    ll ans = 0;
    ll maxi = 0;
    rep(i,0,n){
        ans += max((ll)0,maxi - v[i]);
        maxi = max(v[i],maxi);
    }
    cout << ans;
}
	
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif  
 
    ll t = 1;
    // cin >> t;
    rep(i,0,t){
        solve();
    }
 
}	

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

#define int long long
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);


main(){
	FIO
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	int count = (h2*60+m2)-(h1*60+m1)-k;
	
	cout<<count<<endl;
	
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
using namespace std;
int main() {
    string s, m, first, second;
    int shuffle_cnt, place;
    while (1){
        cin >> s;
        if (s == "-"){
            break;
        } else {
            cin >> shuffle_cnt;
            for (int i=0; i<shuffle_cnt; i++){
                cin >> place;
                m = s;
                first = m.substr(place, m.size()-place);
                second = m.substr(0, place);
                s = first + second;
            }
            cout << s << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3156
#import <stdio.h>
int main() {
    int a,b,k;
    scanf("%d %d %d",&a,&b,&k);
    if (b-a >= 2*k) {
        for(int i=a;i<=a+k-1;i++)
            printf("%d\n",i);
        for(int i=b-k+1;i<=b;i++)
            printf("%d\n",i);
    } else {
        for(int i=a;i<=b;i++)
            printf("%d\n",i);
    }
    return 0;
}


Measured memory_bytes: 7120
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;

  // コンストラクタで階乗と逆元を求める
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

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

  int n, k;
  cin >> n >> k;
  combination c(n);

  k = min(k, n-1);
  mint ans;
  for (int i = 0; i <= k; i++) {  // 0 人の部屋の個数
    ans += c(n, i) * c((n - i - 1) + i, i);
  }

  cout << ans.x << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;
#define inf 1000000007
#define int long long
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
struct edge{int from,to,cost;};
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
signed main(){
    int n;cin>>n;
    int t=n;
    cout<<n<<":";
    for(int i=2;i*i<=n;i++){
        while(t%i==0){
            t/=i;
            cout<<" "<<i;
        }
    }
    if(t!=1)cout<<" "<<t;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3088