akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	ll a, b;
	cin >> a >> b;

	if((a + b) % 2 != 0){
		cout << "IMPOSSIBLE" << endl;
	}else{
		cout << (a + b) / 2 << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin>>a.at(i);
    }
    int counter=0;
    for(int i=0;i<N;i++){
        bool f=true;
        for(int j=sqrt(a.at(i)+1);j>1;j--){
            if(a.at(i)%j==0){
                f=false;
                break;
            }
        }
        if(f)counter++;
    }
    cout<<counter<<endl;
}


Measured memory_bytes: 3128
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int , int> pii;
const int maxn = 1e5+7;

vector<int> G[maxn];
int vis[maxn];
int bfs(int x , int y)
{
    queue<pii> q;
    vis[x] = 1;
    vis[y] = 2;
    q.push(pii(x , 1));
    q.push(pii(y , 2));
    while(!q.empty()){
        pii p = q.front();
        int u = p.first;
        int flag = p.second;
        if(vis[u] == 0)
            vis[u] = flag;
        q.pop();
   //     cout<<u<<" "<<vis[u]<<endl;
        for(int i = 0 ; i < G[u].size() ; i++){
            int v= G[u][i];
            if(vis[v] == 0){
              q.push(pii(v , flag));
            }
        }
    }
    return 1;
}

int main()
{
    int n;
   // freopen("in" , "r" ,stdin);
    cin>>n;
    for(int i =1 ; i < n ; i++){
        int u ,v;
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
        vis[i] = 0;
    }
    bfs(1 , n);
    int cnt = 0;
    for(int i = 1 ; i <= n ; i++){
        if(vis[i] == 1) {cnt++;}//cout<<i<<endl;}
    }

   // cout<<sum<<endl;
   // cout<<cnt<<endl;
    if(cnt <= n-cnt ){
        cout<<"Snuke"<<endl;
    }else{
        cout<<"Fennec"<<endl;
    }
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)

ll H,N;
ll A[1005],B[1005];
ll dp[1005][20005];
ll ans=mod;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>H>>N;

rep(i,N){
	cin>>A[i]>>B[i];
	memset(dp[i],mod,sizeof dp[i]);
}

rep(k,10005){
	if(k*A[0]<20005){
		dp[0][k*A[0]]=k*B[0];
	}
}

rep(i,N-1){
	rep(j,20005){
		if(j-A[i+1]<0){
			dp[i+1][j]=dp[i][j];
		}else{
			dp[i+1][j]=min(dp[i][j],dp[i+1][j-A[i+1]]+B[i+1]);
		}
	}
}

rep(j,20005){
	if(j>=H){
		ans=min(ans,dp[N-1][j]);
	}	
}
cout<<ans<<endl;

}
	


Measured memory_bytes: 156544
#coding:utf-8
from sys import *
N,K=map(int,raw_input().split())

b=K+1
ans=0
if K==0:
    print(N*N)
    exit(0)

while b<=N:
    s=0
    bNum=(N+1)/b
    s+=bNum*(b-K)
    if (N+1)%b!=0:
        s+=max(0,((N)%b)-K+1)
    ans+=s
    b+=1

print(ans)

Measured memory_bytes: 2568
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

void solve() {
    int n;
    cin >> n;
    int d, x;
    cin >> d >> x;
    V<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = x;
    for (auto &&e : a) {
        ans += 1 + (d - 1) / e;
    }

    cout << ans << "\n";
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3608
use proconio::*;

fn main() {
    input!{
        n: usize,
        a: [usize; n],
    }

    let mut mn = 0;
    let mut ans = 0;

    for i in a {
        if i < mn {
            ans += mn - i;
        }
        mn = mn.max(i);
    }

    println!("{}", ans);
}


Measured memory_bytes: 5568
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
struct TTL{
	int x,v;
}p[200010];
const int mod=1000000007;
int L[200010],R[200010];
int f[200010],q[200010];
int lsh[600010],cnt;
bool cmp(TTL a,TTL b)
{
	return a.x<b.x;
}
int ycl()//左边最大 右边最小 
{
	int maxn=0,minn=2e9;
	for (int i=1;i<=n;i++)
	{
		maxn=max(maxn,p[i].v);
		R[i]=maxn;
		lsh[++cnt]=maxn;
	}
	for (int i=n;i>=1;i--)
	{
		minn=min(minn,p[i].v);
		L[i]=minn;
		lsh[++cnt]=minn;
	}
///	for (int i=1;i<=n;i++)
//		printf("%d %d\n",L[i],R[i]);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d%d",&p[i].x,&p[i].v),lsh[++cnt]=p[i].v;
	sort(p+1,p+1+n,cmp);
	ycl();
	sort(lsh+1,lsh+1+cnt);
	cnt=unique(lsh+1,lsh+1+cnt)-1-lsh;
	for (int i=1;i<=n;i++)
	{
		L[i]=lower_bound(lsh+1,lsh+1+cnt,L[i])-lsh;
		R[i]=lower_bound(lsh+1,lsh+1+cnt,R[i])-lsh;
	//	printf("%d %d\n",L[i],R[i]);
	}
	int head=0,tail=1;
	int sum=1;
	L[0]=0;R[0]=0;f[0]=1;
	n++;
	L[n]=n;R[n]=n;
	for (int i=1;i<=n;i++)
	{
		while (head<tail&&L[i]>R[q[head+1]]+1)
			sum=(sum-f[q[head+1]]+mod)%mod,head++;
		f[i]=sum;
		sum=(sum+f[i])%mod;
		q[++tail]=i;
	//	cout<<sum<<endl;
	}
	printf("%d",f[n]);
} 

Measured memory_bytes: 7296
# -*- coding: utf-8 -*-
import sys
import itertools
N,K=map(int, sys.stdin.readline().split())
cnt=(N-1)*(N-2)/2 #距離2の組み合わせができる最大の通り数
if cnt<K:
    print -1
    quit()
L=list( itertools.combinations(range(1,N+1),2) )

M=N-1+cnt-K
print M
for i in range(N-1):
    print L[i][0],L[i][1]

for i in range(N-1,N-1+cnt-K):
    print L[i][0],L[i][1]


Measured memory_bytes: 32620
N = int(input())

A = list(map(int,input().split()))

mean = sum(A)//len(A)

def std_div(mean, A):
    total = 0
    for x in A:
        total += (mean-x)**2
    return total

min1 = std_div(mean,A)
min2 = std_div(mean+1,A)

ans = min(min1,min2)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())

typedef long long ll;

const ll MOD = 998244353;

ll N;
string S;
ll pos = 0;
int toI[26];
ll cnt2[3][3];
ll cnt[3];

int main(){
	cin >> N >> S;
	toI['G'-'A'] = 1;
	toI['B'-'A'] = 2;
	toI['R'-'A'] = 0;
	pos = 1;
	for(ll i=1; i<=N; i++){
		pos *= i;
		pos %= MOD;
	}
	for(char c : S){
		int i = toI[c-'A'];
		int f = min((i+1)%3, (i+2)%3);
		int s = max((i+1)%3, (i+2)%3);
		if(cnt2[f][s] > 0){
			pos *= cnt2[f][s];
			pos %= MOD;
			cnt2[f][s]--;
		}
		else if(cnt[f] > 0){
			pos *= cnt[f];
			pos %= MOD;
			cnt[f]--;
			cnt2[min(f, i)][max(f,i)]++;
		}
		else if(cnt[s] > 0){
			pos *= cnt[s];
			pos %= MOD;
			cnt[s]--;
			cnt2[min(s, i)][max(s,i)]++;
		}
		else{
			cnt[i]++;
		}
	}
	cout << pos << endl;

  return 0;
}


Measured memory_bytes: 900
from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)
    def __len__(self):
        return len(self.graph)
    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))
    def get_nodes(self):
        return self.graph.keys()

class Dijkstra(object):
    def __init__(self, graph, start):
        self.g = graph.graph

        self.dist = defaultdict(lambda : float('inf'))
        self.dist[start] = 0
        self.prev = defaultdict(lambda: None)
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]
    def shortest_path(self, goal):
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

n, m = map(int, input().split())

g = Graph()
for i in range(m):
    a, b, c = map(int, input().split())
    g.add_edge(a-1, b-1, c)
    g.add_edge(b-1, a-1, c)

A = []
for i in range(n):
    d = Dijkstra(g, i)
    for j in range(i+1, n):
        p = d.shortest_path(j)
        for k in range(len(p) - 1):
            A.append("{0},{1}".format(p[k], p[k+1]))
            A.append("{0},{1}".format(p[k+1], p[k]))

print((m*2 - len(set(A)))//2)

Measured memory_bytes: 83676
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	int N;
	cin >> N;
	vi A(N);
	for (auto& x : A)
		cin >> x;
	vector<map<int, int> > primeFac(N);
	for (int i = 0; i < N; ++i)
	{
		for (int j = 2; j * j <= A[i]; ++j)
		{
			int ct = 0;
			while (A[i] % j == 0)
			{
				++ct;
				A[i] /= j;
			}
			if (ct > 0)
				primeFac[i].insert({ j, ct });
		}
		if (A[i] != 1)
			primeFac[i].insert({ A[i], 1 });
	}
	vi g(1000000);
	for (auto& x : primeFac)
	{
		for (auto& y : x)
		{
			++g[y.first];
		}
	}

	bool common = false;
	for (int i = 0; i < 1000000; ++i)
	{
		if (g[i] == N)
		{
			cout << "not coprime" << endl;
			return 0;
		}
		if (g[i] > 1)
		{
			common = true;
		}
	}
	if (common)
	{
		cout << "setwise coprime" << endl;
	}
	else
	{
		cout << "pairwise coprime" << endl;
	}

	return 0;
}

Measured memory_bytes: 294900
#include <bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin >> d;
  if(d==25){
    cout << "Christmas" << endl;
  } else if (d==24){
    cout << "Christmas Eve" << endl;
  } else if (d==23){
    cout << "Christmas Eve Eve" << endl;
  } else if (d==22){
    cout << "Christmas Eve Eve Eve" << endl;
  }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    ll a, b;
    cin >> a >> b;

    cout << a * b / __gcd(a, b) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void DrawRectangle(int H, int W);

int main()
{
	int H, W;

	while(1){
		cin >> H >> W;
		if ((H == 0) && (W == 0))
			break;

		DrawRectangle(H, W);
		cout << endl;
	}


	return 0;
}

void DrawRectangle(int H, int W)
{
	char* strTopBottom = new char[W + 1];
	char* strOther = new char[W + 1];

	for (int i = 0; i < W; i++)
		strTopBottom[i] = '#';
	strTopBottom[W] = '\0';

	for (int i = 1; i < W - 1; i++)
		strOther[i] = '.';
	strOther[0] = strOther[W - 1] = '#';
	strOther[W] = '\0';

	cout << strTopBottom << endl;
	for (int i = 1; i < H - 1; i++)
		cout << strOther << endl;
	cout << strTopBottom << endl;

	delete[] strOther;
	delete[] strTopBottom;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int maxn = 2e5+5;

LL A[maxn];
LL F[maxn];
LL N,K;

bool can_do(LL v){
    LL k = K;
    _for(i,0,N){
        if(A[i]*F[i] > v){
            k -= (A[i] - v/F[i]);
        }

    }

    return (k >= 0);
}

int main()
{
    cin >> N >>  K;
    _for(i,0,N) cin >> A[i];
    _for(i,0,N) cin >> F[i];
    sort(A,A+N);
    sort(F,F+N,greater<LL>());

    LL r = 1e12 + 5;
    LL l = -1;
    while(r - l > 1){
        LL mid = (r+l)/2;
        if(can_do(mid)){
            r = mid;
        }else{
            l = mid;
        }
    }

    cout << r << endl;


    return 0;
}


Measured memory_bytes: 3456
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#define pb push_back
#define mk make_pair
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<LL,LL> pii;
typedef pair<int, pair<int, int> >piii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int inf = 1e9;
const LL INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 5e5;
LL u[maxn], l[maxn], b[maxn];
pii a[maxn];

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	LL n, x;
	cin >> n >> x;
	LL sum = 0;
	for(int i = 0; i < n; ++i){
		cin >> b[i] >> l[i] >> u[i];
		a[i] = pii(b[i] * l[i] + (x - b[i]) * u[i], i);
		sum += b[i] * l[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	LL L = 0, R = x * n, res = 0;
	while(L <= R){
		LL mid = (L + R) >> 1;
		// mid = 64;
		LL k = mid / x, r = mid % x;
		LL tot = 0, t = 0;
		for(int i = 0; i < k; ++i){
			tot += a[i].fi;
		}
		// cout << tot << endl;
		if(r){
			for(int i = 0; i < n; ++i){
				int j = a[i].se;
				LL tt = i < k ? tot - a[i].fi + a[k].fi : tot;
				if(r > b[j]){
					tt += b[j] * l[j] + (r - b[j]) * u[j];
				} else {
					tt += r * l[j];
				}
				t = max(tt, t);
			}
		} else {
			t = tot;
		}
		// cout << sum << endl;
		if(t >= sum){
			res = mid;
			R = mid - 1;
		} else {
			L = mid + 1;
		}
		// break;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 14080
n = int(input())
num_list = [i for i in range(1,n+1)]
num2_list = [i for i in num_list if i%3==0]#3で割り切れる値
list_str = [s for s in map(str,num_list) if '3' in s]#3が含まれる場合
list_in = list(map(int,list_str))#list変換
list_uniq = list(set(num2_list+list_in))
list_uniq.sort()
print(' '+' '.join(str(i) for i in list_uniq))


Measured memory_bytes: 7040
#include<bits/stdc++.h>
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<int,Pil>Piil;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
ll v[52]={};
ll d[52]={};

int main() {

	int n,k;
	cin>>n>>k;
	rep(i,n){
		cin>>v[i+1];
		d[i+1]=d[i]+v[i+1];
	}
	ll ans=0;
	rep(i,n){
		int t[52]={};
		int s=0;
		ll a=d[i];
		rep(k,i){
			if(v[k+1]<0){
				t[s]=v[k+1];
				s++;
			}
		}
		rep(j,n){
			if(i+j>k||i==n+1-j)break;
			if(v[n+1-j]<0){
				t[s]=v[n+1-j];
				s++;
			}
			a+=v[n+1-j];
			sort(t,t+s);

			ll a2=a;
			rep(l,min(k-i-j,s))a2-=t[l];
			ans=max(ans,a2);
		}
	}
	if(n==1)ans=max(ans,v[1]);
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

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

	int k, n;

	cin >> k >> n;

	if (500 * k >= n)
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
n=int(input())
rob=[list(map(int,input().split())) for i in range(n)]
rob=[[sum(rob[i]), rob[i][0]-rob[i][1]] for i in range(n)]
rob.sort(key=lambda i:i[0])
robp=[rob[i][0] for i in range(n)]
robm=[rob[i][1] for i in range(n)]
#print(robp)
#print(robm)

ans=0
x=-10**9
for i in range(n):
  if x<=robm[i]:
    ans+=1
    x=robp[i]
print(ans)

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

int main(){
  ll n;
  cin >> n;
  vector<ll> x(5);
  rep(i,5) cin >> x.at(i);

  sort(x.begin(),x.end());

  ll count = 0;
  if(n % x.at(0) == 0){
    count = n / x.at(0);
  }
  else{
    count = (n / x.at(0)) + 1;
  }

  count += 4;

  cout << count << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

#define fst first
#define snd second

typedef long long llint;
typedef pair<int, int> pii;

const int B = 27397, MOD = 1e9 + 7;
const int B1 = 33941, MOD1 = 1e9 + 9;

const int MAXN = 1e5+10;

int n;
int a[MAXN];

llint solve(int pos, llint sum, bool positive) {
  if (pos == n) return 0;
  llint curr = sum + (llint) a[pos];
  if (positive) {
    if (curr > 0)
      return solve(pos + 1, curr, !positive);
    return -curr + 1 + solve(pos + 1, 1, !positive);
  } else {
    if (curr < 0)
      return solve(pos + 1, curr, !positive);
    return curr + 1 + solve(pos + 1, -1, !positive);
  }
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i]);

  printf("%lld\n", min(solve(0, 0, false), solve(0, 0, true)));
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
signed main(){
  string a,b,c;
  ll aa,bb,cc;
  ll x=0,y=0,z=0;
  bool A = true, B = false, C = false;
  cin>>a>>b>>c;
  aa = a.size();
  bb = b.size();
  cc = c.size();
  while(aa > -1 && bb > -1 && cc > -1){
    if(A){
      if(aa <= 0){
        cout<<"A\n";
      }
      if(a[x]=='b'){
        A = false;
        B = true;
        C = false;
      }else if(a[x]=='c'){
        A = false;
        B = false;
        C = true;
      }
      aa--;
      x++;
    }else if(B){
      if(bb <= 0){
        cout<<"B\n";
      }
      if(b[y]=='a'){
        A = true;
        B = false;
        C = false;
      }else if(b[y]=='c'){
        A = false;
        B = false;
        C = true;
      }
      bb--;
      y++;
    }else if(C){
      if(cc <= 0){
        cout<<"C\n";
      }
      if(c[z]=='a'){
        A = true;
        B = false;
        C = false;
      }else if(c[z]=='b'){
        A = false;
        B = true;
        C = false;
      }
      cc--;
      z++;
    }
  }
}

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

int main() {
	int n, x;
	int comb_num;


	while(cin >> n >> x) {
		if(n==0 && x==0) break;

		comb_num = 0;
		for(int i=1; i<n-1; i++) {
			for(int j=i+1; j<n; j++) {
				for(int k=j+1; k<=n; k++) {
					if(i+j+k == x) comb_num++;
				}
			}
		}

		cout << comb_num << endl;
	}
	
}



Measured memory_bytes: 3100
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))	
cl=list(map(int,input().split()))	

manzoku=0
for i in range(n):
  manzoku+=bl[al[i]-1]
  #print(manzoku)

for i in range(n-1):
  if al[i+1]-al[i]==1:
    #print(i)
    manzoku+=cl[al[i]-1]
print(manzoku)

Measured memory_bytes: 3064
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

import qualified Data.ByteString.Char8 as B

main :: IO()
main = do
  n <- readLn :: IO Int
  cs <- replicateM n B.getLine :: IO [B.ByteString]
  solve cs

solve :: [B.ByteString] -> IO ()
solve = foldM_ go Leaf
  where  
    go :: Tree Int -> B.ByteString -> IO (Tree Int)
    go !tree bs
      | c == bInsert = val `seq` return $ insertTree val tree
      | c == bPrint = do 
        printTree tree
        return tree
      | c == bFind = do
        putStrLn $ if (elemTree val tree) then "yes" else "no"
        return tree
      | c == bDelete = val `seq` return $ deleteTree val tree              
      where
        (c:cs) = B.words bs
        val = fst . fromJust . B.readInt $ head cs :: Int

bInsert = B.pack "insert"
bPrint = B.pack "print"
bFind = B.pack "find"
bDelete = B.pack "delete"

printTree tree = do
  putStrLn . (' ':) . unwords . map show $ inorder tree
  putStrLn . (' ':) . unwords . map show $ preorder tree

data Tree a = Leaf | Node !a (Tree a) (Tree a) deriving (Show)

isLeaf :: Tree a -> Bool
isLeaf Leaf = True
isLeaf _ = False

insertTree :: (Ord a) => a -> Tree a -> Tree a
insertTree !c Leaf = Node c Leaf Leaf
insertTree !c !(Node v left right)
  = if v <= c
    then Node v left (insertTree c right)
    else Node v (insertTree c left) right

inorder :: Tree a -> [a]
inorder Leaf = []
inorder (Node v left right) = (inorder left) ++ [v] ++ (inorder right)

preorder :: Tree a -> [a]
preorder Leaf = []
preorder (Node v left right) = v:(preorder left) ++ (preorder right)

elemTree :: (Ord a) => a -> Tree a -> Bool
elemTree _ Leaf = False
elemTree key (Node v left right)
  | key == v = True
  | key < v  = elemTree key left
  | key > v  = elemTree key right

deleteTree :: (Ord a) => a -> Tree a -> Tree a
deleteTree _ Leaf = Leaf
deleteTree key tree@(Node v left right)
  | key < v  = Node v (deleteTree key left) right
  | key > v  = Node v left (deleteTree key right)
  | key == v = deleteNext tree
  where
    deleteNext (Node _ Leaf Leaf) = Leaf
    deleteNext (Node _ left Leaf) = left
    deleteNext (Node _ Leaf right) = right
    deleteNext (Node _ left right) = let a = minimumKey right in Node a left $ deleteTree a right

minimumKey :: Tree a -> a
minimumKey (Node a Leaf _) = a
minimumKey (Node _ left _) = minimumKey left



Measured memory_bytes: 135092
n, m, x = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]


ans = 10**10
for b in range(2**n):
  skils = [0]*m
  tmp = 0
  
  for i in range(n):
    if b&(1<<i):
      for j in range(m):
        skils[j] += li[i][j+1]
      tmp += li[i][0]

        
  if min(skils)>=x:
    ans = min(ans, tmp)

    
if ans == 10**10:
  print(-1)
  exit()
print(ans)


Measured memory_bytes: 9212
#include<bits/stdc++.h>
//#include <boost/lexical_cast.hpp>
using namespace std;

#define pb push_back
#define mp make_pair  //access values using v[i].first,v[i].second
#define mt make_tuple //access values using get<1>(v[i]),get<0>(v[i]) etc

#define MAX 1000000000
#define MOD 1000000007

#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);

#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define sc(n) scanf("%c",&n)
#define sd(n) scanf("%lf",&n)

#define pin(n) printf("%d\n",n)
#define pln(n) printf("%lld\n",n)
#define pdn(n) printf("%lf\n",n)

#define pis(n) printf("%d ",n)
#define pls(n) printf("%lld ",n)

#define pn printf("\n")
#define ps(n) printf("%s",n)
#define psn(n) printf("%s\n",n)

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


int main()
{
    //FIN;
    int n,m,x;
    si(n);
    si(m);
    si(x);
    vector<int> ary[n];
    for(int i=0;i<n;i++){
    	for(int j=0;j<m+1;j++){
    		int num;
    		si(num);
    		ary[i].pb(num);
		}
	}
	//start dp
	/*int price = MAX;
	int dp[x+1][m+1];
	for(int i=0;i<m+1;i++)dp[0][i]=0;
	
	for(int i=1;i<=x;i++){
		
		for(int book=0;book<n;book++){
			//check compliance
			
		}
	}*/
	//sort(ary.begin(),ary.end());
	int start=1;
	int end = pow(2,n);
	int price =MAX;
	for(;start<end;start++){
		//check for each permutation
		//start with 0
		vector<int> temp(m+1,0);
		for(int i=0;i<n;i++){
			if(start&1<<i){
				//ith book included
				for(int j=0;j<m+1;j++){
					temp[j]+=ary[i][j];
				}
			}
		}
		//check if this permutation satisfies
		bool check = true;
		for(int k=1;k<m+1;k++){
			if(temp[k]<x){
				check = false;
				break;
			}
		}
		//update
		if(check){
			price=min(price,temp[0]);
		}
	}
	if(price==MAX)psn("-1");
	else pin(price);
	
	
}

Measured memory_bytes: 4200
local DBG = true
local function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

local function dbgpr_t(tbl, use_pairs)
    if DBG then
        local enum = ipairs
        if use_pairs then
            enum = pairs
        end
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in enum(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

local function dbgpr_tp(tbl)
    dbgpr_t(tbl, true)
end

-- C
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, string.sub(k, i, i)) end local r = io.read local u = table.unpack return function() return r(u(a)) end end})
local N = read.n()
local V = {}
for i=1,N do
    local v = read.n()
    V[i] = v
end
table.sort(V, function(x,y) return x>y end)
--dbgpr_t(V)
local sum = 0
for i=1,N-1 do
    local v = V[i]
    sum = sum + v * 2^(-i)
end
local v = V[N]
sum = sum + v * 2^(-(N-1))
print(sum)

Measured memory_bytes: 1132
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;



int main()
{
	int n, k;
	cin >> n >> k;
	int x = 1;
	for (int i = 0; i < n; i++) {
		if (x < k) {
			x += x;
		}
		else {
			x += k;
		}
	}
	cout << x << endl;
	return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main(){
  int N;cin>>N;
  vector<int> D(N);
  rep(i,N)cin>>D.at(i);
  ll res = 0;
  rep(i,N-1)for(int j = i+1; j < N; j++){
    res += D.at(i)*D.at(j);
  } 
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np

h, w = map(int, input().split())
A = np.array([list(input()) for i in range(h)])

ans = []
for i in range(h):
    a = ''
    for j in range(w):
        if '#' in A[i] and '#' in A[:, j]:
            a += A[i][j]
    if a != '':
        ans.append(a)

for a in ans:
    print(a, sep='')


Measured memory_bytes: 12540
norg, korg = tuple([int(s) for s in input().split()])

n = norg % 2019
k = korg % 2019

min_val = 2019

if norg // 2019 == korg // 2019:
    for i in range(n, k):
        for j in range(i+1, k+1):
            if (i*j) % 2019 < min_val:
                min_val = (i*j) % 2019
else:
    min_val = 0

print(min_val)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  int q[3];
  q[0] = a+b;
  q[1] = a-b;
  q[2] = a*b;
  int max = -100000;
  for(int i = 0; i < 3; i++){
    if(max < q[i]) max = q[i];
  }

  cout << max;
}

Measured memory_bytes: 256
N = int(input())
Hs = list(map(int, input().split()))

dp = [2 ** 32] * N
dp[0] = 0

for i in range(N):
    for j in range(1, 3):
        if i + j < N:
            dp[i+j] = min(dp[i+j], dp[i] + abs(Hs[i+j]-Hs[i]))
print(dp[N-1])


Measured memory_bytes: 52208
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final long x = scanner.nextLong();

        System.out.println(recursive(0, n, x));
    }

    private static long recursive(final long answer, final int level, final long point) {
        if (level == 0) {
            return answer + 1;
        }

        final long burger = 4 * (long) Math.pow(2, level) - 3;
        final long patty = 2 * (long) Math.pow(2, level - 1) - 1;

        if (point == 1) {
            return answer;
        }

        if (point == burger) {
            return answer + 2 * patty + 1;
        }

        if (point == (burger + 1) / 2) {
            return answer + patty + 1;
        }

        if (point < (burger + 1) / 2) {
            return recursive(answer, level - 1, point - 1);
        }

        return recursive(answer + patty + 1, level - 1, point - (burger + 1) / 2);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int N , A , B ;
    cin >> N >> A >> B;
    if( N*A > B){
        cout << B << endl;
    }else{
        cout << N*A << endl;
    }

    return 0;
}

Measured memory_bytes: 764
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
s=X()
p=[1 if i=="W" else 0 for i in s]
a = s.count("R")
x = p[:a]
print(sum(x))


Measured memory_bytes: 15180
#[allow(unused)]
use std::cmp::{max, min};

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

fn main() {
    input! {
        // usize
        // n: usize,
        // vec
        // v: [i64; n],
        s: chars,
    }

    if s[0] == s[1] || s[1] == s[2] || s[2] == s[3] {
        println!("Bad");
    } else {
        println!("Good");
    }
}

Measured memory_bytes: 4352
def f(d,x,y):n=int("9"*x+"0"*y);return d==0 if x<1 else sum(f(d-i*n,x-2,y+1)*(10-abs(i)-(y<1))for i in [d/n,d/n+1]if -10<i<10)
D=input();print sum(f(D,i,0)*(10-i%2*9)for i in range(1,21))

Measured memory_bytes: 2568
#include<stdio.h>

int main(void){
  int a, b, k;
  scanf("%d %d %d", &a, &b, &k);
  int C[100];
  int c = 0, count = 0;
  if(a >= b){
    for(int i = 1; i <= a; i++)
      if(a%i == 0 && b%i == 0){
        C[c++] = i;
        count++;
      }
  }
  else {
    for(int i = 1; i <= b; i++)
      if(a%i == 0 && b%i == 0){
        C[c++] = i;
        count++;
      }
    }
  printf("%d", C[count-k]);
}


Measured memory_bytes: 128
n = int(input())
wl = list(input() for _ in range(n))

en = wl[0][-1]
flag = 0
word = [wl[0]]
for i in range(1, n):
    st = wl[i][0]
    if st == en and word.count(wl[i]) == 0:
        en = wl[i][-1]
        word.append(wl[i])
    else:
        flag = 1
        break

if flag == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<stdio.h>
#define NIL -1
#define MAX 100000

struct Node{
  int p,l,r;
};

struct Node T[MAX];

int n;

int depth(int a);
int print(int a);

int main(){

  int i,j,x,d,c,l;

  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0;i<n;i++){
    scanf("%d %d",&x,&d);
    for(j=0;j<d;j++){
      scanf("%d", &c);
      if(j==0) T[x].l=c;
      else T[l].r =c;
      l=c;
      T[c].p=x;
    }
  }

  for ( i=0; i<n; i++ ) print(i);
  return 0;
}

int print(int a){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", a, T[a].p,depth(a));

  if(T[a].p==NIL) printf("root, ");
  else if(T[a].l!=NIL) printf("internal node, ");
  else printf("leaf, ");

  printf("["); 

  for(i=0, c=T[a].l; c!=NIL; i++, c=T[c].r){
    if(i==0) printf("%d", c);
    else printf(", %d", c);
  }
  printf("]\n");

  return 0;
}

int depth(int a){
  int num=0,s=T[a].p;
  while(s!=NIL){
    num++;
    s=T[s].p;
  }
  return num;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sumvec(vector<S>&a){return accumulate(all(a),S());}
template<class S>S maxvec(vector<S>&a){return *max_element(all(a));}
template<class S>S minvec(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}


int main(void){
  	cin.tie(0);
  	ios::sync_with_stdio(false);
  	
  	cout << fixed<<setprecision(10);
  	
  	ll n,k;
  	cin>>n>>k;
    vl pl(n);
    vl sum(n-k+1,0);
    double ans=k;
    rep(i,n){
        cin>>pl[i];
    }
  	rep(i,k){
  	    sum[0]+=pl[i];
  	}
  	range(i,1,n-k+1){
  	    sum[i]=sum[i-1]-pl[i-1]+pl[i+k-1];
  	}

    ans+=maxvec(sum);
    puta(ans/2.0);

}


Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int flag=false;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='C')
        flag=true;  //判断标志 
        if(a[i]=='F'&&flag==true)  //f在c的后面，表示有cf 
        {
            cout<<"Yes";
            return 0;
        }
    } 
    cout<<"No"<<endl;  //否则输出no 
    return 0;
}

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

long long mod = 1000000000 + 7;
long long modinv_table[200000+1];


long long power(int x, int a){
   	if (a == 0)
		return 1;
	else if (a == 1)
		return x;
	else if (a % 2 == 0){
        long long te = power(x, a/2);
        return te * te % mod;
    }
    else{
        long long te = power(x, a/2);
        return (te * te)% mod * x % mod;
    }
}

long long modinv(int x){
	return power(x, mod-2);
}


long long binomial(int n, int k){
    long long ans = 1;
    for (int i=0; i<k; i++){
        ans *= n-i;
        ans %= mod;
        ans *= modinv_table[i+1];
        ans %= mod;
    }
    return ans;
}

int main()
{
    // スペース区切りの整数の入力
    int n, a, b;
    cin >> n >> a >> b;

    for (int i=1; i<b+1; i++){
        modinv_table[i] = modinv(i);
    }

    long long ans;
    ans = power(2, n) - 1;
    ans -= binomial(n, a);
    ans -= binomial(n, b);
    ans += (mod) * 3;

    ans %= mod;

    cout << ans << endl;
    return 0;
}


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

int main() {
    int n, i;
    cin >> n;
    vector<int> lst(n);
    bool ans = true;
    for(i = 0; i < n; i++) cin >> lst.at(i);
    sort(lst.begin(), lst.end());
    for(i = 0; i < n - 1; i++){
        if(lst.at(i) == lst.at(i+1)) ans = false;
    }
    if(ans) cout << "YES"<< endl;
    else cout << "NO"<< endl;
}

Measured memory_bytes: 1024
from sys import stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
KS = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]
P = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in range(2**N):
    num = 0
    bin_i = list(format(i, 'b'))
    bin_i = ['0']*(N - len(bin_i))+bin_i
    for j in range(M):
        p = P[j]
        count = 0
        for k in KS[j][1:]:
            if bin_i[k-1] == '1':
                count += 1
        if count % 2 == p:
            num += 1
    if num == M:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll t[n];
    for(int i=0;i<n;i++){
        cin>>t[i];
    }
    ll g=t[0],l=g;
    for(int i=1;i<n;i++){
        g=__gcd(l,t[i]);
        l/=g;
        l*=t[i];
    }
    cout << l <<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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 lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };

lint N, maxv = 0, A;
int main() {
	cin >> N;
	lint sum = 0;
	REP(i, N) {
		cin >> A;
		sum += max(maxv - A, 0ll);
		chmax(maxv, A);
	}
	cout << sum << endk;
}


Measured memory_bytes: 3648
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define MOD 1000000007LL
//#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[&](auto f,auto... args){return f(f,args...);};


int main(){
    vec a(3);
    rep(i,3)cin>>a[i];
    sort(all(a));
    lint k;
    cin>>k;
    a[2]<<=k;
    cout<<SUM(a)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repr(i, a, b) for(int i = a - 1; i >= b; i--)
#define iter(m) for(auto it = m.begin(); it != m.end(); it++)
#define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
signed main(){
    string s; cin >> s;
    int sum = 0;
    for(int i = 0; i < s.size(); i++) {
        sum += s[i] - '0';;
    }
    cout << (sum % 9 == 0 ? "Yes" : "No");
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout<<(x)<<endl
typedef long long ll;
template<class T> inline void chmax(T& a, T b) {
  if (a < b) a = b;
}

template<class T> inline void chmin(T& a, T b) {
  if (a > b) a = b;
}
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  int X;
  cin >> X;
  for (long long int i= -2000; i < 2000; ++i) {
    for (long long int j = -2000; j < 2000; ++j) {
      if (i * i * i * i * i - j * j * j * j * j == X) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;

int main(){
	string s, t;
	cin >> s >> t;
	
	int mx = len(s);
	
	for(int i = 0; i <= len(s) - len(t); i++){
		int cnt = 0;
		for(int j = i; j < i + len(t); j++)
			if(s[j] != t[j-i])
				cnt++;
				
		mx = min(mx, cnt);
	}
	
	cout << mx << endl;
	
	return 0;
}


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

typedef long long ll;

const int Maxn = 200005;
const int mod = 1000000007;

int fac[Maxn], inv[Maxn];
int n, k;
int res;

int toPower(int a, int p)
{
    int res = 1;
    while (p) {
        if (p & 1) res = ll(res) * a % mod;
        p >>= 1; a = ll(a) * a % mod;
    }
    return res;
}

int Inv(int x) { return toPower(x, mod - 2); }

int C(int n, int k)
{
    if (n < 0 || k < 0 || k > n) return 0;
    return ll(fac[n]) * inv[k] % mod * inv[n - k] % mod;
}

int main()
{
    fac[0] = inv[0] = 1;
    for (int i = 1; i < Maxn; i++) {
        fac[i] = ll(i) * fac[i - 1] % mod;
        inv[i] = Inv(fac[i]);
    }
    cin >> n >> k;
    for (int x = 1; x <= n; x++) if (n - x <= k)
        res = (res + ll(C(n - 1, n - x)) * C(n, x)) % mod;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define ll long long
typedef pair<int, int> P;

int main(){
  int a, b, k;
  int count = 0;
  cin >> a >> b >> k;
  for (int i = min(a, b); i > 0; i--) {
    if (a % i == 0 && b % i == 0) {
      count++;
      if (count == k) {
        cout << i << endl;
        exit(0);
      }
    }

  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1<<30);

int main() {
  int n,a[20000];
  cin >> n;
  int cnt = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    while(a[i] % 2 == 0) {
      a[i] /= 2;
      cnt++;
    }
  }
  
  cout << cnt << endl; 
}


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

using namespace std;

int main(void)
{
	int n;
	cin>>n;
	int a[n+1][3];
	for(int x=0;x<n;x++)
	{
		for(int y=0;y<3;y++)
		{
			cin>>a[x+1][y];
		}
	}

	int dp[n+1][3]={{0,0,0}};

	dp[1][0]=a[1][0];
	dp[1][1]=a[1][1];
	dp[1][2]=a[1][2];

	for(int x=2;x<=n;x++)
	{
		for(int y=0;y<3;y++)
		{
			if(y==0)
				dp[x][0]=max(dp[x-1][1]+a[x][0],dp[x-1][2] + a[x][0]);
			if(y==1)
				dp[x][1]=max(dp[x-1][0]+a[x][1],dp[x-1][2] + a[x][1]);
			if(y==2)
				dp[x][2]=max(dp[x-1][1]+a[x][2],dp[x-1][0] + a[x][2]);
		}
	}

	int ans=max(dp[n][0],max(dp[n][1],dp[n][2]));

	cout<<ans;
	

}

Measured memory_bytes: 2560