akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
ll a,b,c;
cin>>a>>b>>c;
if(a==b && a!=c && b!=c)
cout<<c<<endl;
else if(b==c && b!=a && c!=a)
cout<<a<<endl;
else
cout<<b<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

vector<pair<ll ,ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            num++;
            n /= p; 
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b; // Be careful not to overflow
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


int main() {

    ll A, B;
    cin >> A >> B;

    ll C = gcd(A, B);

    ll cnt = 0;

    vector<ll> D = divisor(C);
    vector<ll> E;
    E.push_back(D[0]);
    for(ll i = 1; i < D.size(); i++) {
        ll tmp = 1;
        for(ll j = 1; j < E.size(); j++) {
            if (D[i] % E[j] == 0) break;
            else tmp++;
        }
        if (tmp == E.size()) E.push_back(D[i]);
        // cout << D[i] << " " << endl;
        // REP(k, E.size()) cout << E[k];
        // cout << endl;
        
    }

    cout << E.size() << endl;
    

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

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

        for(int i=0;i<10001;i++){
            int h = sc.nextInt();
            int w = sc.nextInt();
            if(h==0 && w==0){
                break;
            } else {
               for(int j=0;j<h;j++){
                   for(int k=0;k<w;k++){
                    if(j==0||j==(h-1)||k==0||k==(w-1)){
                        System.out.print("#");   
                    } else {
                        System.out.print(".");
                    }
                   }
                   System.out.println();
               }
               System.out.println(); 
            }
        }
        
        sc.close();
      }
}


Measured memory_bytes: 34716
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
    string s;
    cin >> s;

    for (int i = 0; i < 12; ++i) {
        if (i == 4) cout << ' ';
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  rep(i, s.size())
    cout << char('A'+(s[i]-'A'+n)%26);
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
inline int popcount(const int x) { return __builtin_popcount(x);}
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

int main() {
  int n;
  cin >> n;
  auto check = [](int x, int y, int z, int i) {
    return x*x + y*y + z*z + x*y + y*z + z*x <= i;
  };
  auto check2 = [](int x, int y, int z, int i) {
    return x*x + y*y + z*z + x*y + y*z + z*x == i;
  };
  rep2(i, 1, n+1) {
    int ans = 0;
    rep2(x, 1, 100) {
      rep2(y, 1, 100) {
        if (x*x + y*y + 1 + x*y + y + x > i) break;
        int ok = 1, ng = 100;
        while(ng - ok > 1) {
          int mid = (ok+ng)/2;
          if (check(x, y, mid, i)) ok = mid;
          else ng = mid;
        }
        // debug(x, y, ok, i);
        if (check2(x, y, ok, i)) ans++;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}

Measured memory_bytes: 3656
n, p = map(int, input().split())
a = list(map(int, input().split()))

jug = True
for i in range(n):
    if a[i] % 2 == 1:
        jug = False
        break

if jug:
    if p == 0:
        print(2 ** n)
    else:
        print(0)
else:
    print(2 ** (n - 1))

Measured memory_bytes: 38256
n = input()
hs = list(map(int, input().split(" ")))
max = 0
count = 0
for i in range(len(hs) - 1):

    if hs[i+1] <= hs[i]:
        count += 1
    else:
        count = 0
    if max < count:
        max = count
print(max)


Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
vector<vector<int> > g;
vector<vector<int> > w;
vector<int> res;
int dfs(int a, int b, int p = -1) {
	res[a] = b;
	for (int i = 0; i < g[a].size(); i++) {
		if (g[a][i] != p) {

			dfs(g[a][i], b ^ (w[a][i] % 2), a);

		}
	}
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int a, b, c;
	g.resize(N);
	w.resize(N);
	for (int i = 0; i < N - 1; i++) {
		cin >> a >> b >> c; a--; b--;
		g[a].push_back(b);
		w[a].push_back(c);
		g[b].push_back(a);
		w[b].push_back(c);
	}
	res.resize(N);

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

Measured memory_bytes: 13696
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int m = cin.Int();
			int d = cin.Int();
			if (d < 22) {
				Console.WriteLine(0);
				return;
			}

			int ans = 0;
			for (int i = 1; i <= m; i++) {
				for (int j = 22; j <= d; j++) {
					int d10 = j / 10;
					int d1 = j % 10;
					if (d1 >= 2 && i == d10 * d1) {
						++ans;
					}
				}
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 11092
import java.util.*;
 
public class Main { //クラス名はMain
    public static void main(String[] args) {
      //整数の入力
      Scanner sc = new Scanner(System.in);
      //素抜け君の数
      String S = sc.next();
      String T = sc.next();
      if(S.equals(T.substring(0,S.length()))){
          System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int main(){
  vector<int> plist;
  bitset<1000001> ppos;
  for(int i = 2; i <= 1000000; ++i){
    bool f = true;
    for(auto e:plist){
      if(i % e == 0){
	f = false;
	break;
      }
      if(e*e > i)break;
    }
    if(f){
      plist.push_back(i);      
      ppos[i] = 1;
    }
  }
  int n; cin >> n;
  vector<int> v(n); cin >> v;
  map<int,int> mp;
  for(auto e:v){
    for(auto plime:plist){
      if(e == 1)break;
      if(ppos[e]){
	mp[e]++;
	break;
      }
      if(e % plime == 0)mp[plime]++;
      while(e%plime == 0)e /= plime;
    }    
  }
  int cnt1 = 0,cnt0 = 0,maxn = 0;
  for(auto e:mp){
    cnt1 += e.second == 1;
    maxn = max(maxn,e.second);
    cnt0 += e.second == 0;
  }
  if(cnt1+cnt0 == (int)mp.size())cout << "pairwise coprime" << endl;
  else if(maxn != n)cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
  return 0;
}


Measured memory_bytes: 11032
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define MOD 100000007

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool used[1005][1005];
ll cnt[1005][1005];
int depth[1005][1005];

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

bool can(int x, int y) {
	if(0 <= x &&  x < r && 0 <= y && y < c) return true;
	return false;
}

int main() {
	int a1, a2, b1, b2;
	cin >> r >> c >> a1 >> a2 >> b1 >> b2;


	memset(used, 0, sizeof(used));
	used[a1][a2] = true;

	memset(cnt, 0, sizeof(cnt));
	cnt[a1][a2] = 1;

	memset(depth, 0, sizeof(depth));

	queue<P> que;
	que.push(mp(a1, a2));

	int ans = INF;
	while(que.size()) {
		P p = que.front(); que.pop();
		int x = p.first; int y = p.second;
		
		if(x == b1 && y == b2) {
			break;
		}

		rep(i, 4) {
			int nx = x + dx[i] + r;
			int ny = y + dy[i] + c;

			nx %= r; ny %= c;

			if(!used[nx][ny]) {
				cnt[nx][ny] += cnt[x][y];
				cnt[nx][ny] %= MOD;
				used[nx][ny] = true;
				depth[nx][ny] = depth[x][y] + 1;
				que.push(mp(nx, ny));
			} else if(depth[nx][ny] == depth[x][y] + 1) {
				cnt[nx][ny] += cnt[x][y];
				cnt[nx][ny] %= MOD;
			}
		}
	}

	cout << cnt[b1][b2] << endl;

	return 0;
}

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


int main(){
  string s;
  cin >> s;
  int w;
  cin >> w;
  int n=s.size();
  for(int i=0;i<n;i=i+w){
    cout << s[i];
  }
  cout << endl;
  return 0;
}


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

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

  int w, a, b;
  cin >> w >> a >> b;

  int diff = abs(a - b);

  if (diff <= w) cout << 0 << "\n";
  else cout << diff - w << "\n";
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const ll MOD =1000000007; 


ll bpow(ll x, ll y)
{
    ll res=1;
    x = x % MOD;
    while(y>0)
    {
        if(y&1)
        {
            res = (res*x) % MOD;
        }
        y>>=1;
        x = (x *x) % MOD;
    }
    return res;
}


ll inverse(ll a)
{
    return bpow(a, MOD -2);
}

ll nCk(ll n, ll k, vector<ll> & fact)
{
    if (n<k || k<0) return 0;

    return (( (fact[n] * inverse(fact[k]) % MOD )  * inverse(fact[n-k]) ) % MOD ) % MOD;
    
}

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

    ll x,y;
    cin>>x>>y;

    if((x+y) % 3 != 0 )
    {
        cout<<0<<endl;
        return 0;
    } 
    ll n = (x +y)/3;
    vector<ll> fact(n+1);
    fact[0]=fact[1]=1;
    for(ll i=2;i<=n;++i)
        fact[i] = (fact[i-1] *i)  % MOD;

    cout<<nCk(n,(2*y -x)/3, fact)<<endl;

    return 0;
}

Measured memory_bytes: 8468
A,B,C,D=gets.chars
op=[?+,?-]

op.each do |i|
  op.each do |j|
    op.each do |k|
      s = "#{A}#{i}#{B}#{j}#{C}#{k}#{D}="
      if eval s+"=7"
        puts s+?7
        exit
      end
    end
  end
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  b=a-b;
  c=a-c;
  if(b<0){
    b=0-b;
  }
  if(c<0){
    c=0-c;
  }
  if(b>c){
    cout<<"B\n";
  }
  if(b<c){
    cout<<"A\n";
  }
}


Measured memory_bytes: 256
s = input()
k = int(input())
moji = []
for i in range(len(s)):
  for j in range(1, k + 1):
    if j + i > len(s): break
    moji.append(s[i : i + j])
moji = list(set(moji))
moji.sort()
print(moji[k - 1])

Measured memory_bytes: 5068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int mod = 1000000007;
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<vector<int>> g;
mint ans;

void dfs(int v, int p, int k){
    int useCol;
    if (p == -1) useCol = k-1;
    else useCol = k - 2;
    for(int d: g[v]) {
        if (d == p) continue;
        ans *= useCol;
        useCol--;
        dfs(d, v, k);
    }
}

int main(){
    int n, k;
    cin >> n >> k;
    g.resize(n);
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ans = k;
    dfs(0, -1, k);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14548
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MAX = 51*1001;
Int dp[2][55][MAX];
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  vector<Int> s(n,a[0]);
  for(Int i=1;i<n;i++) s[i]=s[i-1]+a[i];
  
  for(Int i=0;i<2;i++)
    for(Int j=0;j<55;j++)
      for(Int k=0;k<MAX;k++)
	dp[i][j][k]=MAX;
  dp[0][n][MAX-1]=0;

  auto chmin=[](Int &a,Int b){if(a>b) a=b;};
  
  for(Int i=0;i<n;i++){
    bool f=i%2;
    for(Int k=0;k<MAX;k++){
      for(Int j=0;j<n;j++){
	Int &res=dp[f][j][k];
	if(res==MAX) continue;
	//cout<<i<<" "<<j<<" "<<k<<":"<<res<<endl;
	chmin(dp[!f][j][k],dp[f][j][k]);
	chmin(dp[!f][i][min(k,s[i]-s[j])],
	      max(dp[f][j][k],s[i]-s[j]));
	res=MAX;
      }
      if(dp[f][n][k]!=MAX){
	//cout<<i<<" "<<n<<" "<<k<<":"<<dp[f][n][k]<<endl;
	chmin(dp[!f][n][k],dp[f][n][k]);
	if(i+1!=n){
	  chmin(dp[!f][i][min(k,s[i])],
		max(dp[f][n][k],s[i]));
	}
	dp[f][n][k]=MAX;
      }
    }
  }
  /*//
  for(Int i=0;i<MAX;i++)
    if(dp[n%2][n-1][i]!=MAX)
      cout<<n<<" "<<n-1<<" "<<i<<":"<<dp[n%2][n-1][i]<<endl;
  //*/			
  Int ans=MAX;	       
  for(Int i=0;i<MAX;i++)
    if(dp[n%2][n-1][i]!=MAX) chmin(ans,dp[n%2][n-1][i]-i);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 46988
import java.util.Scanner;

public class Main {

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

		long x=1000000007;

		int N=sc.nextInt();

		long[] dp=new long[N+1];
		for(int i=0;i<N+1;i++) dp[i]=0L;
		dp[0]=1L;

		int M=sc.nextInt();
		for(int i=0;i<M;i++) dp[sc.nextInt()]=-1L;

		for(int i=0;i<N;i++) {
			if(dp[i]==-1) continue;
			if(dp[i+1]!=-1) dp[i+1]=(dp[i+1]+dp[i])%x;
			if(i+2<=N  && dp[i+2]!=-1) dp[i+2]=(dp[i+2]+dp[i])%x;
			
		}

		System.out.println(dp[N]%x);

		sc.close();
	}

}


Measured memory_bytes: 60300
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
pp = inpl()
ans = 0
for i in range(N-2):
    a,b,c = pp[i:i+3]
    if a < b < c or c < b < a:
        ans += 1

print(ans)


Measured memory_bytes: 4332
import numpy as np

def solve(n, k, aaa, fff):
    aaa = np.sort(aaa)
    fff = np.sort(fff)[::-1]

    l = -1
    r = 1e12
    while l+1 < r:
        c = (l+r)//2
        s = np.clip(aaa - c//fff, 0, None).sum()
        if s <= k:
            r = c
        else:
            l = c
    return int(r)


n, k = map(int, input().split())
aaa = np.array(list(map(int, input().split())), dtype=np.int64)
fff = np.array(list(map(int, input().split())), dtype=np.int64)

print(solve(n, k, aaa, fff))

Measured memory_bytes: 37196
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */

    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(int i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(int i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(int i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 203000;
    
    ll dp[maxN];

    void solve() {
      ll n, q;
      string s;
      cin >> n >> q >> s;
      rep(i, n){
        if(s[i] == 'A' && s[i+1] == 'C') dp[i] = dp[i-1] + 1;
        else dp[i] = dp[i-1];
        //cout << dp[i] << endl;
      }
      rep(i, q){
        ll x, y;
        cin >> x >> y;
        --x, --y;
        cout << dp[y-1] - dp[x-1] << endl;
      }
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //te
      solve();
      return 0;
    } 

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

int main(){
    int A, B, C, D;bool flag;
    cin >> A >> B >> C >> D;
    while (1) {
        A -= D;C -= B;
        if (C <= 0) {
            flag = true;
            break;
        }
        else if (A <= 0){ 
            flag = false;
            break;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;

const LL LINF=334ll<<53;
// start, goal, graph, previous vertex on the shortest pass (prev[start]=-1)
typedef pair<LL,int> PLI;
struct Edge{
    int from,to;
    LL cost;
    Edge(int from,int to,LL cost)
        : from(from),to(to),cost(cost) {};
};
typedef vector<vector<Edge>> Graph;

LL dijkstra(const int start,const int goal, const vector<vector<Edge>> &graph , vector<PLI> &prev){
    typedef pair<LL,int> pii;
    fill(prev.begin(),prev.end(),make_pair(LINF,-1));
    int N = graph.size();
    vector<char> visited(N,false);
    // <<cost , place>, prev>
    priority_queue<pair<pii,int>,vector<pair<pii,int>>,greater<pair<pii,int>> > Q;
    Q.push(make_pair(make_pair(0,start),-1));
    while(!Q.empty()){
        LL cost;
        int place,from;
        cost = Q.top().first.first;
        place = Q.top().first.second;
        from=Q.top().second;
        Q.pop();
        if(visited[place]) continue;
        prev[place].second=from;
        prev[place].first=cost;
        //if(place == goal) return cost;
        visited[place] = true;
        for(int j=0;j<(int)graph[place].size();j++){
            Q.push(make_pair(make_pair(graph[place][j].cost+cost,graph[place][j].to),place));
        }
    }
    return -1;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,s,t; //vertex,edge
    cin >> n >> m>>s;
    Graph G(n);
    vector<PLI> prev(n);

    for(int i=0;i<m;i++){
        int a,b,cost;
        cin >> a >> b >> cost;
        G[a].push_back(Edge(a,b,cost));
        //G[b].push_back(Edge(b,a,cost));
    }

    dijkstra(s,n-1,G,prev);
    REP(i,n){
        if(prev[i].first==LINF)cout << "INF"<<endl;
        else cout << prev[i].first<<endl;
    }

    return 0;
}

Measured memory_bytes: 24408
#include <bits/stdc++.h>
#define MAX (ll)(5e5 + 7)
#define INF (ll)(1e18 + 7)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;

void f_io () {
	ios_base :: sync_with_stdio (false);
	cin.tie (nullptr);
}

int main () {
	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		ans += (n - 1) / i;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) (c).begin(),(c).end()
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { SORT(a); a.erase(unique(ALL(a)),a.end()); }
template <class S, class T> ostream& operator<<(ostream& os, const pair<S,T> a) {
  return os << a.first << ' ' << a.second;
}
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

string s;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> s;
  set<char> st;
  REP(i,s.size()) {
    st.insert(s[i]);
  }
  cout << (st.size() == s.size() ? "yes" : "no") << endl;

  return 0;
}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#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())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
/*bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}*/
int main(){
    int n, ans=0, y=0, z=0;
    cin >> n;
    VI x(n);
    REP(i, n){
    cin >> x[i];
    y+=x[i];
    }
    z=y%n;
    y/=n;
    if(z==0){
        REP(i,n){
            ans+=(x[i]-y)*(x[i]-y);
        }
    }else{
        int y1=y, y2=y+1, ans1=0, ans2=0;
        REP(i,n){
          ans1+=(x[i]-y1)*(x[i]-y1);
          ans2+=(x[i]-y2)*(x[i]-y2);  
        }
        ans=min(ans1, ans2);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
int x[110000];
int dp[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",x+i);
	for(int i=0;i<=a;i++)dp[i]=mod;
	dp[0]=0;
	for(int i=0;i<a;i++){
		if(i+1<a)dp[i+1]=min(dp[i+1],dp[i]+ABS(x[i]-x[i+1]));
		if(i+2<a)dp[i+2]=min(dp[i+2],dp[i]+ABS(x[i]-x[i+2]));
	}
	printf("%d\n",dp[a-1]);
}

Measured memory_bytes: 896
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        long left = 1;
        long right = k + 1;
        while (right - left > 1) {
            long m = (left + right) / 2;
            long x = m;
            long total = 0;
            for (int i = 0; i < n && x > 0 && total <= k; i++) {
                total += x;
                x /= 2;
            }
            if (total <= k) {
                left = m;
            } else {
                right = m;
            }
        }
        System.out.println(left);
    }
}



Measured memory_bytes: 26404
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main = do
    nums <- map (\s -> read (s : "")) <$> getLine
    putStr $ solve nums
    putStrLn "=7"

solve (n : ns) = concat $ head $ concatMap (\bit -> g ns bit n [show n]) bits
    where bits = replicateM 3 [True, False]

g [] [] acc ans | acc == 7  = [reverse ans]
                | otherwise = []
g (a : as) (b : bs) acc ans
    | b         = g as bs (acc + a) (show a : "+" : ans)
    | otherwise = g as bs (acc - a) (show a : "-" : ans)


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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void go() {
	cout << "UNRESTORABLE" << endl;
}

void solve()
{
	string s , t;
	
	cin >> s >> t;
	
	int n = s.size();
	int m = t.size();
	
	if(m > n) {
		go();
		return;
	}
	
	string ans;
	
	int flg = 0;
	
	for(int i = 0; i < n; ++i) {
		ans.pb('z');
	}
	
	for(int i = 0; i < n - m + 1; ++i) {
		
		int ok = 1;
		
		for(int j = i; j < i + m; ++j) {
			if(s[j] == t[j-i] or s[j] == '?') {
				continue;
			}
			else {
				ok = 0;
				break;
			}
		}
		
		if(ok) {
			string ss = s;
			
			for(int j = i; j < i + m; ++j) {
				ss[j] = t[j - i];
			}
			
			for(int j = 0; j < n; ++j) {
				if(ss[j] == '?') {
					ss[j] = 'a';
				}
			}
			
			flg = 1;
			
			ans = min(ans , ss);
		}
	}
	
	if(flg) {
		cout << ans;
	}
	else {
		go();
	}
}

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


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
//#define rf(x) (x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define cb(x) (x)=(!(x))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define INFST (0x7f7f7f7f)
#define INFLLST (0x7f7f7f7f7f7f7f7fll)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
typedef complex<ld> base;
const ld EPS = (ld)1e-7;
const ld PI = acos(0) * 2;
bool isZero(const ld& x) { return abs(x) <= EPS; }
int sign(const ld& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
ll gcd(ll a, ll b) { for(;b;a%=b,swap(a,b)){} return abs(a); }
pll operator + (const pll& a, const pll& b) { return pll(a.first+b.first, a.second+b.second); }
pll operator - (const pll& a, const pll& b) { return pll(a.first-b.first, a.second-b.second); }
pll operator * (const pll& a, const ll& b) { return pll(a.first*b, a.second*b); }
ll operator * (const pll& a, const pll& b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll& a, const pll& b, const pll& c) { return a*b + b*c + c*a; }
void fg(vector<int> G[], int a, int b) { G[a].pb(b); G[b].pb(a); }
void fg(vector<pii> G[], int a, int b, int c) { G[a].pb({b, c}); G[b].pb({a, c}); }

const int MAXN = 100005;

vector<int> G[MAXN];

int dp[MAXN];
int A[MAXN];

int N;

void f(int idx) {
	vector<int> V;
	for(int v : G[idx]) {
		f(v);
		V.pb(dp[v]);
	}
	if(V.empty()) return;
	sorv(V); revv(V);
	int &ret = dp[idx];
	for(int i = 0; i < sz(V); i++)
		upmax(ret, V[i]+i+1);
}

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

	cin >> N;
	for(int i = 2; i <= N; i++) {
		cin >> A[i];
		G[A[i]].pb(i);
	}

	f(1);

	cout << dp[1] << endl;
	return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <queue>
using namespace std;

#define loop(i, n) for (int i = 0; i < n; i++)

typedef pair<int, int> i_i;
bool dfs(int x, int y, char a, char b, 
        vector<vector<char> > &g);

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

int h, w;

int main()
{
    while (cin >> w >> h, (w|h)) {
        vector<vector<char> > g(h, vector<char>(w));
        int sx, sy, cnt = 0;
        loop(i, h) {
            loop(j, w) {
                cin >> g[i][j];
                if (g[i][j] == '&') {
                    sx = i;
                    sy = j;
                    g[i][j] = '.';
                }
            }
        }
        while (!dfs(sx, sy, '.', '#', g)) {
            cnt++;
            dfs(sx, sy, '#', '.', g);
        }
        cout << cnt << endl;
    }
    return 0;
}

bool dfs(int x, int y, char a, char b, 
        vector<vector<char> > &g) {
    bool ret = false;
    g[x][y] = b;
    for (int i = 0; i < 4; i++) {
        if (x+dx[i] < 0 || y+dy[i] < 0 || 
            h <= x+dx[i] || w <= y+dy[i] ) {
            return true;
        }
        if (g[x+dx[i]][y+dy[i]] == a) {
            ret = dfs(x+dx[i], y+dy[i], a, b, g);
        }
    }
    return ret;
}

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

int main(){
	int a, b;
	cin >> a >> b;
	if((a*b)%2)
		cout << "Odd" << endl;
	else
		cout << "Even" << 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 FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());


int ans = 0;
vector<vector<int> > island_map;
void dfs(vector<vector<int> > field, pair<int, int> init_pos)
{
  int dirx[] = {1, 1, 1, 0, 0, -1, -1, -1};
  int diry[] = {1, 0, -1, 1, -1, 1, 0, -1};

  int h = field.size();
  int w = field[0].size();
  stack<pair<int, int> > pos_stack;
  pos_stack.push(init_pos);

  while (pos_stack.size())
  {
    pair<int, int> pos = pos_stack.top();
    pos_stack.pop();
    int pos_x = pos.first;
    int pos_y = pos.second;
    rep(i, 8)
    {
      int next_x = pos_x + dirx[i];
      int next_y = pos_y + diry[i];

      if (0 <= next_x && next_x < h && 0 <= next_y && next_y < w && island_map[next_x][next_y] == 0 && field[next_x][next_y] == 1)
      {
        island_map[next_x][next_y] = ans;
        pos_stack.push(make_pair(next_x, next_y));
      }
    }
  }
}

int main()
{
  while(true)
  {
    int w, h;
    cin >> w >> h;
    if(w == 0 && h == 0)
      return 0;

    ans = 0;    
    vector<vector<int> > field(h, vector<int>(w, 0));
    island_map = vector<vector<int> >(h, vector<int>(w, 0));
    rep(i, h) rep(j, w)
    {
      cin >> field[i][j];
    }

    rep(i, h) rep(j, w)
    {
      if(island_map[i][j] == 0 && field[i][j] == 1)
      {
        ans++;
        dfs(field, make_pair(i, j));
      }
    }
    cout << ans << endl;
  }
  return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

#define	MOD 1000000007

int	main() {
	string S;
	cin >>S;
	vector<bool> C(26, true);
	for (int i=0; i<S.size(); i++)
		C.at(S.at(i)-'a')=false;
	int i=0;
	while(i<26) {
		if (C.at(i))
			break;
		i++;
	}
	if (26==i)
		cout <<"None" <<endl;
	else
		cout <<(char)(i+'a') <<endl;
	return 0;
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int K; cin >> K;
  int A, B; cin >> A >> B;

  string str = "NG";
  int k = 0;
  while(true) {
    k = k + K;
    if(A <= k && k <= B) str = "OK";
    if(k >= 1000) break;
  }

  cout << str << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
// int main() {
//     int n;
//     cin >> n;
//     int a[n];
//     for(int i = 0; i < n; i++) cin >> a[i];
//     for(int i = 0; i < n - 1; i++) {
//         for(int j = 0; j < n; j++) {
//             if(a[j] == i + 1) {
//                 cout << j + 1 << ' ';
//                 continue;
//             }
//         }
//     }
//     for(int i = 0; i < n; i++) {
//         if(a[i] == n) cout << i + 1 << endl;
//     }
// }
int main() {
    int n, a;
    cin >> n;
    vector<pair<int, int> > v(n);
    for(int i = 0; i < n; i++) {
        cin >> a;
        v[i] = make_pair(a, i + 1);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < n - 1; i++)
        // cout << v[i].first << endl;
        cout << v[i].second << " ";
    cout << v[n - 1].second << endl;
}

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

main(){
	while(1){
		int V[101]={0},a,b;
		do{
			if(!(cin >> a >> b)) return 0;
			V[a]++;V[b]++;
		}while(a*b);
		a=1;
		for(int i=3;i<=100;i++) if(V[i]%2) a=0;
		cout << (V[1]%2 && V[2]%2 && a?"OK":"NG") << endl;
	}
}

Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,ans=0;
  cin>>N;
  
  bool CAN[10000010];
  REP(i,10000010) CAN[i]=true;
  
  RREP(i,N){
    ans+=(1+N/i)*(N/i)/2*i;
  }
  
  co(ans);
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 1; i < N - 1; i++) {
    set<int> c1, c2;
    for (int j = 0; j < i; j++)
      c1.insert(S[j]);
    for (int j = i; j < N; j++)
      c2.insert(S[j]);
    int count = 0;
    for (auto itr = c1.begin(); itr != c1.end(); itr++) {
      if (c2.count(*itr) == 1) count++;
    }
    ans = max(ans, count);
  }
  cout << ans << '\n';
  return 0;
}


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

#define LLINF (1LL<<60)
typedef long long ll;

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

void sort2vectors(vector<ll> &av, vector<ll> &bv){
    int n = av.size();
    vector<ll> p(n), av2(n), bv2(n);
    iota(p.begin(), p.end(), 0);
    sort(p.begin(), p.end(), [&](ll a, ll b) { return av[a] < av[b]; });
    for (int i = 0; i < n; i++) {
        av2[i] = av[p[i]];
        bv2[i] = bv[p[i]];
    }
    av = av2;
    bv = bv2;
}


//C++14 (GCC 5.4.1)
int main() {
    int N,M;
    cin >>N>>M;

    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i]>>B[i];
    
    //-----------------------------------
    sort2vectors(A,B);
    ll kaihon=0,harai=0;
    rep(i,N){
        if(kaihon+B[i]<=M){
            kaihon+=B[i];
            harai+=A[i]*B[i];
        }else{
            harai+=(M-kaihon)*A[i];
            break;
        }
    }

    cout << harai <<endl;
    return (0);
}

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

using namespace std;
int main(){
    int a,b,c; cin>> a >> b >> c;
    map<int,int> mp; mp[a]++;mp[b]++;mp[c]++;
    if(mp[a]==1)cout<<a<<endl;
    else if(mp[b]==1)cout<<b<<endl;
    else cout<<c<<endl;
    return 0;
}


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

class test
{
    static void Main(){
        string[] inputs = Console.ReadLine().Split(' ');
        int N = Int32.Parse(inputs[0]);
        int K = Int32.Parse(inputs[1]);
        List<int> h = new List<int>();
        for(int count = 0;count < N;count++)
            h.Add(Int32.Parse(Console.ReadLine()));

        h.Sort();

        int result = 1000000001;

        for(int count = 0;count < N - K + 1;count++)
            if(result > (h[count + K - 1] - h[count]))
                result = h[count + K - 1] - h[count];

        Console.WriteLine(result.ToString());

    }
}

Measured memory_bytes: 16092