akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<long> a(n);
	long x = 0;
	std::set<int> st;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		
		x ^= a[i];
		st.insert(-__builtin_ctzll(a[i]));
	}
	
	int ans = 0;
	for(auto s : st){
		int k = -s;
		
		if((x >> k) & 1){
			x ^= (1 << (k + 1)) - 1;
			ans++;
		}
	}
	
	if(x) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    A, B, C, K = map(int, input().split())

    ans = min(A, K)
    K -= A
    K -= B
    if K > 0:
        ans -= min(K, C)
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


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

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

    long n;
    cin >> n;

    vector<long> a;
    long tmp;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        a.push_back(tmp);
    };
    sort(a.begin(), a.end());
    long max_val = a[n - 1];
    decltype(a)::iterator large_med;
    decltype(a)::iterator small_med;
    decltype(a)::iterator nearest_med;
    auto true_med = static_cast<long>(round(max_val / 2.0));
    large_med  = lower_bound(a.begin(), a.end(), true_med);

    long large_pos = 0;
    for (auto &num : a) {
        if (num == *large_med) break;
        large_pos++;
    }

    long med_val;
    if (large_pos == n - 1) {
        med_val = a[large_pos - 1];
    } else if (large_pos == 0) {
        med_val = a[large_pos];
    } else if (a[large_pos] - true_med > true_med - a[large_pos - 1]) {
        med_val = a[large_pos - 1];
    } else {
        med_val = a[large_pos];
    }
    cout  << max_val << ' ' << med_val << "\n";

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b){ if (a<b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N, K;
  cin >> N >> K;

  int ans = N - K + 1;
  cout << ans << endl;
}

Measured memory_bytes: 256
var fs = require('fs'),
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
function main(){
    input.sort(function(a,b){return b-a}).slice(0,3).forEach(function(c){console.log(c)});
}



Measured memory_bytes: 15156
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 200000
#define INF 0x3f3f3f3f
char S[MAXN+5];
int main(){
	//freopen("divide.in","r",stdin);
	//freopen("divide.out","w",stdout);
	scanf("%s",S+1);
	int n=strlen(S+1),cnt=1,len=1;
	char c=S[1];
	for(int i=2;i<=n;i++){
		if(len==2||S[i]!=c)
			len=1,c=S[i],cnt++;
		else{
			if(i<n)
				i++,len=2,cnt++;
			else break;
		}
	}
	printf("%d\n",cnt);
    return 0;
}


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

using namespace std;

using ll=long long ;
using pl=pair<ll, ll> ;

const int V = 150;
const int E = 500<<2;
int sson[V], pre[V]; ll dis[V]; int trk[V];
int cnt;

struct node{
    int to, bro; ll cap, flow; int cost;
} edge[E];

void init(){
    cnt = 0;
    memset(sson, -1, sizeof sson);
}

void add_edge(int u, int v, ll cap, int cost){
    edge[cnt] = {v, sson[u], cap, 0, cost};
    sson[u] = cnt++;
    edge[cnt] = {u, sson[v], 0, 0, -cost};
    sson[v] = cnt++;
}

const long long inf = 0x3f3f3f3f3f3f3f3f;
bool spfa(int s, int t){
    queue<int> q;
    memset(pre, -1, sizeof pre);
    //memset(dis, inf, sizeof dis);
    for (int i = 0; i < V; i++) {
        dis[i] = inf;
    }
    memset(trk, 0, sizeof trk);
    dis[s] = 0; trk[s] = 1; q.push(s);
    while(!q.empty()){
        int u = q.front(); q.pop(); trk[u] = 0;
        for (int e=sson[u]; ~e; e=edge[e].bro){
            int v = edge[e].to;
            if (edge[e].cap > edge[e].flow && dis[v] > dis[u] + edge[e].cost){
                dis[v] = dis[u] + edge[e].cost;
                pre[v] = e;
                if (!trk[v]){
                    trk[v] = 1;
                    q.push(v);
                }
            }
        }
    }
    return pre[t] != -1;
}

pl mcmf(int s, int t){
    ll flow = 0, cost = 0;
    while (spfa(s, t)){
        ll f = inf;
        for (int e=pre[t]; ~e; e=pre[edge[e^1].to])
            f = min(f, edge[e].cap - edge[e].flow);
        for (int e=pre[t]; ~e; e=pre[edge[e^1].to]){
            edge[e].flow += f;
            edge[e^1].flow -= f;
            cost += edge[e].cost * f;
        }
        flow += f;
    }
    return {flow, cost};
}

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    long long TOT = 0;
    for (auto& x: a) {
        cin >> x;
        if (x > 0) TOT += x;
    }
    int S = 0, T = n+1;
    init();
    for (int i = 0; i < n; i++) {
        if (a[i] > 0) {
            add_edge(i+1, T, a[i], 0);
        }else {
            add_edge(S, i+1, -a[i], 0);
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = i*2; j <= n; j+=i) {
            add_edge(i, j, inf, 0);
        }
    }
    auto res = mcmf(S, T);
    ll ans = TOT - res.first;
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }

int main() {
    init();

    int n, k; cin >> n >> k;
    string s; cin >> s;
    FOR(i, 0, min(k, 13)) {
        string t = s;
        reverse(all(t));
        string u = s + t;
        FOR(j, 0, n + 1)chmin(s, u.substr(j, n));
        reverse(all(s));
    }
    reverse(all(s));
    print(s);
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

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

    int start = l;
    int end = l + n - 1;

    int min;
    if(end <= 0)
    	min = end;
    else if(start >= 0)
    	min = start;
    else
    	min = 0;

    int ans = n*l + (n *(n - 1)) / 2 - min;
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
	N = int(input())
	restaurants = []
	for i in range(N):
		S, P = input().split()
		p = int(P)
		restaurants.append([S, p, i+1])
	restaurants.sort(key=lambda x: (x[0], -x[1]))

	for r in restaurants:
		print(r[2])


if __name__ == '__main__':
	main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int N = 105;
const int MAX = 1e4 + 5;
ll cnt[MAX];
int main()
{
	boost;
	int n, i, j, k;
	cin >> n;
	foe(i, 1, N) {
		foe(j, 1, N) {
			foe(k, 1, N) {
				int x = i * i + j * j + k * k + i * j + i * k + j * k;
				if(x >= MAX) continue;
				cnt[x]++;
			}
		}
	}
	foe(i, 1, n)
	cout << cnt[i] << '\n';
}


Measured memory_bytes: 3676
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int k;
  cin >> k;
  string s;
  cin >> s;
  if(s.size() > k){
    printf("%s...",s.substr(0,k).c_str());
  }else{
    printf("%s\n",s.c_str() );
  }
  return 0;
}


Measured memory_bytes: 3720
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int next = 1;
		int[] a = new int[n];
		HashSet<Integer> hSet = new HashSet<>();

		for(int i = 0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		for(int i = 0; i < n; i++){
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		}
	}
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int main()
{
    LL n, m;
    cin >> n >> m;

    if(2 * n >= m)
        cout << m / 2 << '\n';
    else{
        LL ans = n;
        m -= 2 * n;
        cout << ans + m / 4 << '\n';
    }
    return 0;
}


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

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

  if (s.length() == 1)
  {
    cout << s[0] << endl;
    return 0;
  }
  else
  {
    int t = 0;
    for (int i = 0; i < s.length(); i++)
    {
      if (s[i] != '1')
      {
        t = i;
        break;
      }
    }
    if (t + 1 <= k)
    {
      cout << s[t] << endl;
      return 0;
    }
    else
    {
      cout << "1" << endl;
    }
  }
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000000LL;
const int MAX=100001;
const double EPS=1e-10;
int main(){
    int a,b;cin>>a>>b;a--;b--;
    cout<<100<<" "<<100<<endl;
    for(int i=0;i<50;i++){
        for(int j=0;j<100;j++){
            if(a&&i%2&&j%2){
                cout<<".";
                a--;
            }else{
                cout<<"#";
            } 
        }
        cout<<endl;
    }    
    for(int i=0;i<50;i++){
        for(int j=0;j<100;j++){
            if(b&&i%2&&j%2){
                cout<<"#";
                b--;
            }else{
                cout<<".";
            }
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

int N;
int P[212345];

int main() {

	scanf("%d", &N);
	rep(i, N) scanf("%d", &P[i]);

	vector<pair<int, int>> S(N);

	rep(i, N) S[i] = make_pair(P[i], i);
	sort(S.begin(), S.end());

	int m = 1;
	int c = 1;
	rep(i, N - 1) {
		if (S[i].second < S[i + 1].second) c++;
		else c = 1;
		m = max(m, c);
	}

	printf("%d\n", N - m);

	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{
    int n, i = 0, j, k = 0;
    cin >> n;
    if(n % 4 == 0 || n % 7 == 0)
    {
        cout << "Yes";
        return 0;
    }
    while(i <= n)
    {
        int j = 0;
        while(i + j <= n)
        {
            if(i + j == n)
            {
                k++;
                cout << "Yes";
                return 0;
            }
            j = j + 7;
        }
        i = i + 4;
    }
    if(k == 0)
    cout << "No";
    else
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define INF  (int)2e9 + 7
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;
const long long BIGINF = 2e18 + 20;
const int N = 5005;



bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.first + a.second < b.first + b.second;
}


int main () {
	/*#ifndef ONLINE_JUDGE
		freopen("inputf.txt", "r", stdin);
		freopen("outputf.txt", "w", stdout);
	#endif*/	

	int n, w, s;
	vector<pair<int, int>> v;
	SCD(n);
	for (int i = 0; i < n; i++) {
		SCD(s);
		SCD(w);
		v.push_back(make_pair(w, s));
	}
	sort(v.begin(), v.end(), cmp);
	/*for (int i = 0; i < n; i++) {
		printf("%d %d, ", v[i].first, v[i].second);
	} */
	long long dp[N];
	for (int i = 1; i <= n; i++) {
		dp[i] = BIGINF;
	}
	int ans = 1;
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int used = i + 1; used >= 1; used--) {
			if (dp[used - 1] <= v[i].second) {
				dp[used] = min(dp[used], dp[used - 1] + v[i].first);
			}
			//printf("dp[%d] = %lld\n",used, dp[used]);
		}
	}
	for (int i = 1; i <= n; i++) {
		if (dp[i] != BIGINF) {
			ans = max(ans, i);
		}
	}
	printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 512
W, H, x, y = map(int, input().split())

res_1 = W * H / 2
if x == W // 2 and y == H // 2 and W % 2 == 0 and H % 2 == 0:
    res_2 = 1
else:
    res_2 = 0

print(res_1, res_2)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
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; }

string s;
int main() {
    cin >> s;
    int slen = s.length();
    char bw[2] = {'B', 'W'};
    vector<int> bwcnt(2, 0);
    int bwch = 0;
    for(int i = 0; i < slen; ++i) {
        if(s.at(i) == 'B') {
            bwch = 0; bwcnt.at(bwch)++;
        }else {
            bwch = 1; bwcnt.at(bwch)++;
        }
        while(i+1 < slen && s.at(i+1) == bw[bwch]) i++;
    }

    cout << bwcnt.at(0)+bwcnt.at(1)-1 << endl;
}

Measured memory_bytes: 512
import itertools
a = input().split()
b = set(map(str,range(1,10)))
n, c = [], 0
for i in range(9):
    if a[i] in b:b.remove(a[i])
    else:n.append(i)
for i in itertools.permutations(tuple(b)):
    for j in range(len(n)):a[n[j]] = i[j]
    if int(a[0]) + int(a[1] + a[2]) + int(a[3] + a[4] + a[5]) == int(a[6] + a[7] + a[8]):c += 1
print(c)


Measured memory_bytes: 5640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ll 				long long
#define int             long long int
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define modp            998244353
#define inf             (ll)1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void solve()
{
	int n, d;
	cin >> n >> d;
	int x[n], y[n];
	for(int i = 0; i < n; i++)
		cin >> x[i] >> y[i];
	int cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if((x[i]*x[i] + y[i]*y[i]) <= d*d)
			cnt++;
	}
	cout << cnt;
}
 
int32_t main()
{
	FIO
    // w(t)
    {
    	solve();
    }
    return 0;
}
	

	

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

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007
#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"

void solve(){
	int h1,h2,m1,m2;
	int k;
	cin>>h1>>m1>>h2>>m2>>k;
	int dif;
	if(h1<h2){
		dif=(h2-h1-1)*60+(m2+60-m1);
	}else if(h1==h2){
		if(m1<m2){
			dif= (m2-m1);
		}else{
			dif= m2-m1+60+60*23;
		}
	}else{
		dif= h2-h1-1+24;
		dif*=60;
		dif += (-m2+60+m1);
	}
	if(dif-k<0){
		cout<<0<<"\n";
	}else{
		cout<<dif-k<<"\n";
	}
}

int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	// cin>>_;
	_=1;
	while(_--){
        solve();
    }
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

Measured memory_bytes: 3608
<?php
// B
fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%d %d', $d, $x);
$eat = 0;
for ($i  = 0; $i < $n; $i++) {
    fscanf(STDIN, '%d', $a);
    $eat += intdiv($d - 1, $a) + 1;
}
echo $x + $eat;

Measured memory_bytes: 4728
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1010;
int c[maxn][maxn];

int lcs(char s1[], char s2[]){
	int m = strlen(s1);
	int n = strlen(s2);
	for(int i=1;i <= m;i++)
	c[i][0] = 0;
	for(int j = 1;j <= n;j++)
	c[0][j] = 0;
	
	for(int i = 0;i < m;i++){
	
	for(int j = 0;j < n ;j++){
		if(s1[i] == s2[j])
		c[i+1][j+1] = c[i][j] + 1;
		else
		 c[i+1][j+1] = max(c[i][j+1],c[i+1][j]); 
	}
}
 return c[m][n];
}
int main(){
	char s1[maxn],s2[maxn];
	int T;
	cin >> T;
	while(T --){
		cin >> s1 >> s2;
		cout << lcs(s1,s2) << endl; 
		
	} 
	return 0; 
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[101010];
bool is_prime[1000001];

ll dp[100001][2];

int main(){

  repl(i,2,1000001)is_prime[i]=true;
  for(ll i=2;i<=1000000;i++){
    if(!is_prime[i])continue;
    for(ll j=i*2;j<=1000000;j+=i){
      is_prime[j]=false;
    }
  }

  cin>>n;
  rep(i,n)cin>>a[i];

  if(!is_prime[a[0]]){
    cout<<0<<endl;
    return 0;
  }

  dp[1][0]=1;
  repl(i,1,n){
    rep(j,2){
      if(j){
        if(is_prime[a[i]]&&a[i-2]<a[i]){
          (dp[i+1][0]+=dp[i][j])%=mod;
        }
      }else{
        if(is_prime[a[i]]&&a[i-1]<a[i]){
          (dp[i+1][0]+=dp[i][j])%=mod;
          (dp[i+1][1]+=dp[i][j])%=mod;
        }else{
          (dp[i+1][1]+=dp[i][j])%=mod;
        }
      }
    }
  }

  cout<<(dp[n][0]+dp[n][1])%mod<<endl;
  return 0;
}



Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, A[100000], a, b;
vector<int>v[100000];
bool vis[100000], f;

ll dfs(int x) {
	vis[x] = true;
	if (x) {
		ll S = 0, MAX = -1;
		for (int i : v[x]) {
			if (!vis[i]) {
				ll k = dfs(i);
				S += k;
				MAX = max(MAX, k);
			}
		}
		if (MAX == -1) {
			return A[x];
		}
		ll t = 2 * A[x] - S;
		if (MAX > A[x] || t < 0 || S < A[x]) {
			f = false;
			return 0;
		}
		return t;
	}
	else {
		ll S = 0, MAX = -1;
		for (int i : v[x]) {
			if (!vis[i]) {
				ll k = dfs(i);
				S += k;
				MAX = max(MAX, k);
			}
		}
		if (v[x].size() == 1) {
			if (S != A[x]) {
				f = false;
			}
		}
		else {
			if (MAX > A[x] || (S & 1) || S / 2 != A[x]) {
				f = false;
			}
		}
		return 0;
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	for (int i = 1; i < N; ++i) {
		cin >> a >> b;
		--a;
		--b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	f = true;
	dfs(0);
	puts(f ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 10240
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

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

    ll mod=1e9+7;
    vector<ll> dp(S+7);
    dp[1]=0;dp[2]=0;dp[3]=1;dp[4]=1;dp[5]=1;
    
    for(int i=4;i<S+1;i++){
        dp[i]=dp[i-1]+dp[i-3];
        dp[i]%=mod;
    }

    cout<<dp[S]<<endl;

    return 0;
}

Measured memory_bytes: 3616
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def parse():

    return 

def main():
    S = input()
    ans = 0
    nn = len(S)-1
    for i in range(1<<nn): # bit flag to insert '+'
        #print(bin(i))
        end = len(S)
        for j in range(nn):
            if 1<<j & i:
                start = len(S)-1-j
                s = S[start:end]
                #print(start,end)
                #print(s)
                try:
                    ans += int(s)
                except:
                    pass
                end = start
        s = S[:end]
        #print(s)
        try:
            ans += int(s)
        except:
            pass
        #print()
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 5076
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let s = get_chars();
    let (x, y): (i64, i64) = get_pair();
    let fs = as_fs(&s);
    let bias = 8499;
    let range = 17000;
    let mut xs_after = vec![false; range];
    let mut ys_after = vec![false; range];
    let mut xs_before;
    let mut ys_before;
    xs_after[bias + fs[0] as usize] = true;
    ys_after[bias] = true;
    for i in 1..fs.len() {
        if i % 2 == 0 {
            xs_before = xs_after;
            xs_after = vec![false; range];
            for j in 0..range {
                if xs_before[j] {
                    xs_after[(j as i64 - fs[i]) as usize] = true;
                    xs_after[(j as i64 + fs[i]) as usize] = true;
                }
            }
        } else {
            ys_before = ys_after;
            ys_after = vec![false; range];
            for j in 0..range {
                if ys_before[j] {
                    ys_after[(j as i64 - fs[i]) as usize] = true;
                    ys_after[(j as i64 + fs[i]) as usize] = true;
                }
            }
        }
    }
    if xs_after[(bias as i64 +x) as usize] && ys_after[(bias as i64 +y) as usize] {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn as_fs(s: &Vec<char>) -> Vec<i64> {
    let mut fs = Vec::new();
    let mut j = 0;
    for &c in s {
        if c == 'T' {
            fs.push(j);
            j =  0;
        } else {
            j += 1;
        }
    }
    fs.push(j);

    fs
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


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

int main() {
    ios::sync_with_stdio(false);
    vector<int>g1 = {1, 3, 5, 7, 8, 10, 12};
    vector<int>g2 = {4, 6, 9, 11};

    int x, y;
    cin >> x >> y;

    bool flag = 0;
    if(x == 2 or y == 2) {
        flag = 0;
    }

    else if(find(g1.begin(), g1.end(), x) != g1.end() and find(g1.begin(), g1.end(), y) != g1.end())
        flag = 1;

    auto i = find(g2.begin(), g2.end(), x);
    auto j = find(g2.begin(), g2.end(), y);
    if( i != g2.end() and j  != g2.end())
        flag = 1;

    if(flag == 1)
        cout << "Yes\n";
    else
        cout << "No\n";


    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

int main(){
  ll n,x,b; cin >> n >> x >> b; ll ans = abs(x-b);
  
  rep(i,n-1){
    ll a; cin >> a;
    ans = min(ans,gcd(ans,abs(x-a)));
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
//解説AC
using namespace std;

typedef long long ll;

const ll inf = 1LL << 60 ;

int dp[3100][3100] = {0};

int main(){
 string s,t; cin >> s >> t;
  int n = (int)s.size(); int m = (int) t.size();
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      if( s[i] == t[j]){ dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);}
      
      dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j]);
      dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j+1]); }}
  
  //dp[n][m]が、最長共通部分列の長さに他ならない
  string res ="";
  
  int i = n; int j = m;
  
  while(i > 0 && j > 0){
    if( dp[i][j] == dp[i-1][j]){i--;}
    else if( dp[i][j] == dp[i][j-1]){j--;}
    else{
      res = s[i-1] + res; i--;j--;}}
  
  cout << res << endl; 
  return 0;}
    
       
      
      
      
      
      


Measured memory_bytes: 37120
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

M = 10**9+7

def inv(a,p):
    return pow(a,p-2,p)

ans,comb = 0,1
#i番目ではcomb = (K-1-i)_C_(K-1)
#max,min以外での選ぶ個数は常にK-1であることに注目すればcomb関数はいらなかった
for i in range(N-K+1):
    if i > 0:
        comb = (comb * (K-1+i) * inv(i,M)) % M
    ans = (ans + comb*((A[K-1+i]-A[N-K-i]) % M)) % M
print(ans)


Measured memory_bytes: 14040
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
char s[10][10];
int mp[10][10];
int main()
{
	int h,w,k;cin>>h>>w>>k;
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			cin>>s[i][j];
		}

	}
	int ans=0;
	ll sum=0;
	for (int i = 0; i <(1<<h); i++)
	{
		for (int j = 0; j <(1<<w); j++)
		{
			int a=i,b=j;
			int t=0;
			while(a)
			{
				t++;
				if(t>h) break;
				if(a&1)
				{
					for (int o = 1; o <=8 ; o++)
					{
						mp[t][o]=1;
					}
					
				}
				a>>=1;
			}
			t=0;
			while (b)
			{
				t++;
				if(t>w) break;
				if(b&1)
				{
					for (int o = 1; o <=8 ; o++)
					{
						mp[o][t]=1;
					}
				}
				b>>=1;
			}
			int ans=0;
			for (int o = 1; o <= 8; o++)
			{
				for (int p = 1; p <= 8; p++)
				{
					if(s[o][p]=='#'&&mp[o][p]==0) ans++;
				}
			}
			//if(ans!=0) cout<<ans<<endl;
			if(ans==k) sum++;
			memset(mp,0,sizeof(mp));
			ans=0;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 200010
#define LG 25
int R[LG][MAXN],L[LG][MAXN],fl[4194304],fr[4194304];
int V[LG],cnt,X[MAXN],lg,tot,n,x[MAXN];
void Min(int &x,int y)
{
	if(x>y) x=y;
}
void Max(int &x,int y)
{
	if(x<y) x=y;
}
int main()
{
	
	scanf("%d%d",&n,&V[0]);
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	while(V[lg])
		V[++lg]=V[lg-1]/2;
	for(int i=0;i<=lg;i++)
	{
		int ls=0;
		for(int j=2;j<=n+1;j++)
			if(x[j]-x[j-1]>V[i]||j==n+1)
			{
				for(int k=ls;k<j-1;k++)
					L[i][k]=j-1;
				for(int k=ls+2;k<=j;k++)
					R[i][k]=ls+1;
				ls=j-1;
				if(i==0) X[++cnt]=j-1;
			}
	}
	if(cnt>lg+1)
	{
		for(int i=1;i<=n;i++)
			printf("Impossible\n");
		return 0;
	}
	tot=1<<(lg+1);
	for(int i=0;i<tot;i+=2)
		fr[i]=n+1;
	for(int i=0;i<tot;i+=2)
		for(int j=1;j<=lg;j++)
			if((i&(1<<j))==0)
			{
				Max(fl[i|(1<<j)],L[j][fl[i]]);
				Min(fr[i|(1<<j)],R[j][fr[i]]);
			}
	for(int i=1;i<=cnt;i++)
	{
		bool flag=0;
		for(int j=0;j<tot;j+=2)
			if(fl[j]>=X[i-1]&&fr[tot-j-2]<=X[i]+1)
			{
				flag=1;
				break;
			}
		for(int j=X[i-1]+1;j<=X[i];j++)
			if(flag) printf("Possible\n");
			else printf("Impossible\n");
	}
}

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

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    int A,B;
    cin >> A >> B;

    //resolve
    bool isOne=false;
    bool isTwo=false;
    bool isThree=false;
    if (A==1 || B==1) isOne=true;
    if (A==2 || B==2) isTwo=true;
    if (A==3 || B==3) isThree=true;

    // output
    if (!isOne) cout << 1 << endl;  
    if (!isTwo) cout << 2 << endl;  
    if (!isThree) cout << 3 << endl;    

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  string s;
  int64_t k,i=0;
  cin >> s >> k;
  int64_t count=0;
  while(1){
    if(s.at(i)!='1'){
      cout << s.at(i);
      return 0;
    }
    i++;
    if(i==k){
      cout << 1;
      return 0;
    }
  }
}


Measured memory_bytes: 256
use v5.18;
use warnings;
use Data::Dumper qw( Dumper );
use List::Util qw( sum );
sub line { chomp(my $str = <STDIN>); $str }
sub split_line { split / /, line }
my $join_num = line;
my ($day, $left_chocolate_num) = split_line;
my @eat_periods = map { line } 0 .. $join_num - 1;
my $eat_chocolate_num = sum map { my $eat = int(($day - 1) / $_) + 1 } @eat_periods;
say $eat_chocolate_num + $left_chocolate_num;

Measured memory_bytes: 1920
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		int[] deg = new int[4];
		for(int i = 0; i < 6; i++)
			deg[GetInt() - 1]++;

		Console.WriteLine((deg.Max() <= 2) ? "YES" : "NO");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 11220
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N =  int(sys.stdin.readline())
S =  sys.stdin.readline().rstrip()

if N < 3200:
    print("red")
else:
    print(S)

Measured memory_bytes: 5076
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define int long long

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

vector<vector<int>> g_graph;
vector<vector<int>> g_visited;
int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};

void dfs(int y, int x, int h, int w) {
    g_visited[y][x] = true;
    for (int i = 0; i < 8; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        if (ny < 0 || ny >= h || nx < 0 || nx >= w) {
            continue;
        }
        if (g_visited[ny][nx]) {
            continue;
        }
        if (g_graph[ny][nx] == 0) {
            continue;
        }
        dfs(ny, nx, h, w);
    }
}

void go(int y, int x, int h, int w, int &island) {
    if (g_visited[y][x]) {
        return;
    }
    if (g_graph[y][x] == 0) {
        return;
    }
    dfs(y, x, h, w);
    island += 1;
}

void solve(int h, int w) {
    g_graph.assign(h, vector<int>(w, 0));
    g_visited.assign(h, vector<int>(w, 0));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> g_graph[i][j];
        }
    }

    int island = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            go(i, j, h, w, island);
        }
    }
    cout << island << endl;
}

signed main() {
    while (1) {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0) {
            return 0;
        } else {
            solve(h, w);
        }
    }
}



Measured memory_bytes: 3300
def fact(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

a = int(input())
li = []
li = fact(a)
count = 0
i = 0
dif = 1

while i < len(li):
    if a == 1:
        break
    
    if li[i][1] >= dif:
        count += 1
        li[i][1] -= dif
        dif += 1
    else:
        dif = 1
        i += 1
print(count)

Measured memory_bytes: 9508
import collections
n=int(input())
A=[]
for i in range(n):
  A.append(input())
c=collections.Counter(A)
B=c.most_common()
C=[]
i=0
while B[i][1]==B[0][1]:
  C.append(B[i][0])
  i=i+1
  if i==len(B):
    break
C=sorted(C)
for i in range(len(C)):
  print(C[i])

Measured memory_bytes: 49204
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n, a, b; cin >> n >> a >> b;
  vector<int> x(n);
  REP (i, n) {
    int p; cin >> p;
    p--;
    x[p] = i;
  }
  vector<vector<int>> dp(n + 1, vector<int>(n + 1, 1e18));
  REP (k, n + 1) dp[0][k] = 0;
  REP (i, n) {
    REP (k, n + 1) {
      if (k > 0) dp[i + 1][k] = dp[i + 1][k - 1];
      chmin(dp[i + 1][k], dp[i][k] + (x[i] <= k - 1 ? a : b));
      if (x[i] == k - 1) chmin(dp[i + 1][k], dp[i][k - 1]);
    }
  }
  cout << dp[n][n] << endl;
}


Measured memory_bytes: 195968
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        String N = in.s();
        int K = in.i();
        int ans = solve(N, K, N.length());
        out.println(ans);
    }

    static int solve(String s, int k, int d){
        if(d < k){
            return 0;
        } else {
            if(k == 0){
                return 1;
            } else {
                int i = s.charAt(0)-'0';
                int ret = 0;
                if(i == 0){
                    ret += solve(s.substring(1, d), k, d-1);
                } else {
                    ret += c(d-1, k)*pow(9, k);
                    ret += solve(s.substring(1, d), k-1, d-1);
                    if(i > 1){
                        ret += (i-1)*c(d-1, k-1)*pow(9, k-1);
                    }
                }
                return ret;
            }
        }
    }

    static int c(int n, int r){
        if(r == 0){
            return 1;
        } else if(r == 1){
            return n;
        } else if(r == 2){
            return n*(n-1)/2;
        } else {
            return n*(n-1)*(n-2)/6;
        }
    }

    static int pow(int n, int k){
        return k == 0 ? 1 : k == 1 ? n : k == 2 ? n*n : n*n*n;
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MAX = 2010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cout << fixed << setprecision(10);
    
    int N, K; cin >> N >> K;
    int bn = K, rn = N-K;

    COMinit();

    // 青はK個まで分割できる、そのとき、赤の間に入れるところはK-1個
    // K分割のとき赤玉の必要最小数はK-1個
    rep(i, min(K, rn+1)) {
        // i回で青を全てとれる分け方

        // 自由に分配できる赤玉の数 free red
        int fr = rn - i;
        // 自由に分配できる場所 free location
        // 必ず分割しなければいけないところと、両端
        int fl = i+2;

        // 何通りに分割できるか kCi
        ll lrcom = COM(K-1, i);

        // 何通りにフリーの赤を置けるか (fl+fr)Cmin(fl, fr)
        ll lfcom = COM(fl-1+fr, min(fl-1, fr));

        /*
        cout << "free red: " << fr << " free loc: " << fl << endl;

        cout << "bunkatu: " << lrcom << endl;
        cout << "huriwake: " << lfcom << endl;
        */
        cout << (lrcom * lfcom) % MOD << endl;
    }
    rep(i, K-1-rn) {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    double v[50];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v,v+n);
    for(int i=1;i<n;i++){
        v[i]=(v[i-1]+v[i])/2;
    }
    cout<<v[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 256