akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, MOD = 1e9 + 7;
struct edge
{
	int v, nxt;
}e[N * 2];
int p[N], eid;
int res[N],sz[N];
bool vst[N];
int n;

void add(int u, int v)
{
	e[eid] = edge{v, p[u]}; p[u] = eid ++;
}
int pow_mod(int a, int b)
{
	long long res = 1, tmp = a;
	for (; b; b /= 2)
	{
		if(b & 1) res = res * tmp % MOD;
		tmp = tmp * tmp % MOD;
	}
	return res;
}
void dfs1(int u)
{
	vst[u] = 1;
	sz[u] = 1;
	
	for (int i = p[u]; ~i; i = e[i].nxt)
	{
		int v = e[i].v;
		if(vst[v]) continue;
		dfs1(v);
		sz[u] += sz[v];
	}
	res[1] = (1LL * res[1] * u) % MOD;
	res[1] = (1LL * res[1] * pow_mod(sz[u], MOD - 2)) % MOD;
}
void dfs2(int u)
{
	vst[u] = 1;
	for (int i = p[u]; ~i; i = e[i].nxt)
	{
		int v = e[i].v;
		if(vst[v]) continue;
		res[v] = 1LL * res[u] * sz[v] % MOD * pow_mod(n - sz[v], MOD - 2) % MOD;
		dfs2(v);
	}
}
int main()
{
	scanf("%d", &n);
	memset(p, -1, sizeof(p));
	for (int i = 1; i < n; ++ i)
	{
		int u ,v; scanf("%d%d", &u, &v);
		add(u, v);
		add(v, u);
	}
	res[1] = 1;
	dfs1(1);
	memset(vst, 0, sizeof(vst));
	dfs2(1);
	for (int i = 1; i <= n; ++ i) printf("%d\n", res[i]);
	return 0;
}

Measured memory_bytes: 7936
import java.util.*;

public class Main {

    static List<Integer> divisor(int n) {
        List<Integer> list = new ArrayList<Integer>();
        for (int i=1;i<=Math.sqrt(n);i++) {
            if (n%i==0) {
                list.add(i);
                if (i*i!=n) {
                    list.add(n/i);
                }
            }
        }
        Collections.sort(list);
        return list;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i=0;i<N;i++) {
            A[i] = sc.nextInt();
            if (map.containsKey(A[i])) {
                map.put(A[i], map.get(A[i])+1);
            } else {
                map.put(A[i], 1);
            }
        }

        int cnt = 0;
        for (int i=0;i<N;i++) {
            if (map.get(A[i])>1) {
                map.put(A[i], map.get(A[i])-1);
            } else {
                map.remove(A[i]);
            }

            ArrayList<Integer> div = new ArrayList<Integer>(divisor(A[i]));
            boolean flag = false;
            for (Integer element : div) {
                if (map.containsKey(element)) flag = true;
            }
            if (!flag) cnt++;

            if (map.containsKey(A[i])) {
                map.put(A[i], map.get(A[i])+1);
            } else {
                map.put(A[i], 1);
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 86768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
const ll MOD = 1e9 + 7;

void mainsolve(){

	ll n,k,s;
	cin >> n >> k >> s;
	if(s-(n-k) < 1){
		rep(i,k){
			cout << s << " ";
		}
		rep(i,n-k){
			cout << s+1 << " ";
		}
	} else{
		if(k==0){
			rep(i,n){
				cout << 1 << " ";
			}
		} else{
		rep(i,k-1){
			cout << s << " ";
		}
		cout << s-(n-k) << " ";
		rep(i,n-k){
			cout << 1 << " ";
		}
		}

	}
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 1280
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

vvi dp;
int n, m;
vi a;
vi vec = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string S;

void dfs(int i_, int j_) {
    int i = m-i_;
    int j = n-j_;
    if(!i) {
        return;
    }
    if(j-vec[a[i-1]]>=0 && dp[i][j]-1 == dp[i][j-vec[a[i-1]]]) {
        S += '0' + a[i-1];
        dfs(i_, j_+vec[a[i-1]]);
        return;
    }
    dfs(i_+1, j_);
}



int main() {
    
    cin >> n >> m;
    a.resize(m);
    rep(i, m) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    
    dp.assign(m+1, vi(n+1, -1));
    dp[0][0] = 0;
    rep(i, m) {
        rep(j, n+1) {
            int k=0;
            if(!j || dp[i][j] != -1) {
                while(j + k*vec[a[i]] <= n) {
                    dp[i+1][j+k*vec[a[i]]] = max(dp[i][j]+k, dp[i+1][j+k*vec[a[i]]]);

                    ++k;
                }
            }
        }
    }
    dfs(0, 0);

    /*rep(i, m+1) {
        rep(j, n+1) {
            cout << dp[i][j] << ' ';
        }
        cout << endl;
    }*/

    cout << S << endl;
    
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll k,a[200009],b[200009];
int cmp(ll a,ll b)
{
    return a>b;
}
int check(ll x)
{
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=x)
            continue;
        sum+=(a[i]-x)%b[i]?(a[i]-x)/b[i]+1:(a[i]-x)/b[i];
    }
    return sum<=k;
}
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=1; i<=n; i++)
        scanf("%lld",&a[i]);
    for(int i=1; i<=n; i++)
        scanf("%lld",&b[i]);
    sort(a+1,a+n+1,cmp);
    sort(b+1,b+n+1);
    for(int i=1; i<=n; i++)
        a[i]=a[i]*b[i];
    ll left=0,right=1e12,mid;
    while(right-left>1)
    {
        mid=(left+right)/2;
        if(check(mid))
            right=mid;
        else
            left=mid+1;
    }
    if(check(left))
        printf("%lld",left);
    else
        printf("%lld",right);
    return 0;
}


Measured memory_bytes: 3328
//confilm 0LL and 1LL
//confilm cornercases such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	string s;
	cin >> s;
	ll ans = 0, cnt = 0;
	rep(i, s.length()){
		if(s[i] == 'B') cnt++;
		else ans += cnt;
	}
	co(ans);

	return 0;
}


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

using namespace std;

const int N = 1e5 + 5;

struct disj {
    int par[N], sz[N], ncc;
    void init (int n) {
        iota(par + 1, par + n + 1, 1);
        fill(sz + 1, sz + n + 1, 1);
        ncc = n;
    }

    int Find (int x) {
        return par[x] == x ? x : par[x] = Find(par[x]);
    }

    void join (int x, int y) {
        x = Find(x); y = Find(y);
        if (x == y) return;
        ncc--;

        if (sz[x] > sz[y]) {
            sz[x] += sz[y];
            par[y] = x;
        } else {
            sz[y] += sz[x];
            par[x] = y;
        }
    }
} dsu;

int n, m;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m; dsu.init(n);
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        dsu.join(u, v);
    }

    cout << dsu.ncc - 1 << "\n";
    return 0;
}


Measured memory_bytes: 4428
from collections import Counter 
num = input()
ins = list()
aa = list()
qc = 0
for abhsa in range(0, int(num)):
  ins.append(input())
cnt = Counter(ins)
nums = cnt.most_common()
res = nums[0][0]
values, counts = zip(*cnt.most_common())
aa.append(values[0])
for haha in counts:
  aqc = qc + 1
  if int(len(counts) - int("1")) >= aqc:
    if counts[qc] == counts[aqc]:
      aa.append(values[aqc])
      qc += 1
    else:
      break
aca = sorted(aa)
print("\n".join(aca))

Measured memory_bytes: 132212
#include <stdio.h>

int main(void)
{
	char hexa[9];
	int binary[32];
	int i, n, j, m, f;
	double decimal, radix;
	int out[13], show, hide;
	
	double dif;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		for (j = 0; j < 13; j++){
			out[j] = 0;
		}
		
		scanf("%s", hexa);
		for (j = 0; j < 8; j++){
			if (hexa[j] >= '0' && hexa[j] <= '9'){
				m = hexa[j] - '0';
			}
			else {
				m = hexa[j] - 'a' + 10;
			}
			
			binary[j * 4 + 0] = m / 8;
			m %= 8;
			binary[j * 4 + 1] = m / 4;
			m %= 4;
			binary[j * 4 + 2] = m / 2;
			m %= 2;
			binary[j * 4 + 3] = m;
		}
		
		for (j = 1, radix = 8388608.0, decimal = 0.0; j < 32; j++, radix /= 2){
			decimal += radix * binary[j];
		}
		
		if (binary[0] == 1){
			printf("-");
		}
		
		for (j = 0, radix = 100000.0, show = 5, hide = 6; radix >= 0.0000001; j++){
			while (decimal >= radix){
				if (j < show){
					show = j;
				}
				if (j > hide){
					hide = j;
				}
				out[j]++;
				decimal -= radix;
			}
			
			dif = radix * 9 / 10;
			radix -= dif;
		}
		
		for (j = show; j <= hide; j++){
			printf("%d", out[j]);
			if (j == 5){
				printf(".");
			}
		}
		puts("");
	}
	
	return (0);
}

Measured memory_bytes: 612
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  ll r, D, x; cin >> r >> D >> x;
  rep(i, 10) {
    x = r * x - D;
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define po pop()
#define pu push
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;string st; char ch;
    while(cin>>a>>b>>c)
    {
        if(b<a)swap(a,b);
        if(c<a)swap(a,c);
        if(c<b)swap(b,c);
        a+=b;
        cout<<a<<en;
    }
}




Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

int a[101];
signed main(){
	int n, m, ans = 0;
	scanf("%lld",&n);
	rrep(i,n)scanf("%lld", &a[i]);
	rrep(i,n)ans += a[i];
	scanf("%lld", &m);
	rep(i,m){
		int x, y;
		scanf("%lld%lld", &x, &y);
		printf("%lld\n", ans+(y-a[x]));
	}
	return 0;
}


Measured memory_bytes: 256
//  __      __       .__           .____________                   __________        __ ________   __                 
// /  \    /  \ ____ |_________  __| _\______   \__ __  ____  _____\______   \__ ___/  |\_____  \ |  | ______  ___.__.
// \   \/\/   _/ __ \|  \_  __ \/ __ | |    |  _|  |  \/ ___\/  ___/|    |  _|  |  \   __/   |   \|  |/ \__  \<   |  |
//  \        /\  ___/|  ||  | \/ /_/ | |    |   |  |  / /_/  \___ \ |    |   |  |  /|  |/    |    |    < / __ \\___  |
//   \__/\  /  \___  |__||__|  \____ | |______  |____/\___  /____  >|______  |____/ |__|\_______  |__|_ (____  / ____|
//        \/       \/               \/        \/     /_____/     \/        \/                   \/     \/    \/\/     

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second
#define PI 3.14159265358979323846
#define endl '\n'

using namespace std;

void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        map <int, int> m;
        for(int j = i; j < n; j++)
        {
            if(s[i] != s[j])
            {
                int x = 'R' + 'G' + 'B' - s[i] - s[j];
                ans += m[x];
                int k = 2 * j - i;
                //cout << i << "," << j << "," << k << "-";
                if(k > j && k < n && s[k] == x)
                    ans--;
            }
            m[s[j]]++;
            //cout << ans << ' ';
        }
        //cout << endl;
    }
    cout << ans << endl;
}

int main()
{
	int q = 1;
	//scanf("%d", &q);
	for(int i = 1; i <= q; i++)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
const int MAX=105;
int M[MAX][MAX];
bool vis[MAX];
int n,t=1,d[MAX],f[MAX],nt[MAX];
stack<int> S;
int next(int u){
	for(int v=nt[u];v<=n;v++){
		nt[u]=v+1;
		if(M[u][v])return v;
	}
	return -1;
}
void dfs(int cur){
	memset(nt,0,sizeof(nt));
	vis[cur]=1;
	d[cur]=t++;
	S.push(cur);
	while(!S.empty()){
		int u=S.top();
		int i=next(u);
		if(i!=-1){
			if(M[u][i]&&!vis[i]){
				vis[i]=1;
				d[i]=t++;
				S.push(i);
			}
		}
		else{
			S.pop();
			f[u]=t++;
		}	
	}

}
int main(){
	cin>>n;
	memset(M,0,sizeof(M));
	memset(vis,0,sizeof(vis));
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		int v;
		for(int j=0;j<k;j++){
			cin>>v;
			M[u][v]=1;
		}
	}
	for(int i=1;i<=n;i++){
		if(!vis[i])dfs(i);
	}
	for(int i=1;i<=n;i++){
		printf("%d %d %d\n",i,d[i],f[i]);
	}
	return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
    return (b ? gcd(b, a % b) : a);
}
template<typename Tn> Tn lcm(Tn a, Tn b)
{
    return a / gcd(a, b) * b;
}

string IntToString(int number)
{
    stringstream ss;
    ss << number;
    return ss.str();
}

struct UF
{
    vi par, sizes;

    UF() {}
    UF(int size) : par(size, -1), sizes(size, 1) {
	rep(i, size) par[i] = i;
    }

    int root(int x)
    {
	return par[x] == x ? x : par[x] = root(par[x]);
    }

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

    int size(int x)
    {
	return sizes[root(x)];
    }

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

	if(x == y) return ;

	if(sizes[x] < sizes[y]) swap(x, y);
	par[y] = x;
	sizes[x] += sizes[y];
	sizes[y] = 0;
    }
};

int main()
{
    llint n, m;
    vi a(100001);
    vi b(100001);
    
    ci >> n >> m;
    rep(i, m) ci >> a[i] >> b[i];

    vl v;
    UF uf(n + 1);
    llint sum = n * (n - 1) / 2;

    for(int i = m - 1; i >= 0; i--) {
	v.push_back(sum);
	
	if(!uf.same(a[i], b[i])) {
	    sum -= uf.size(a[i]) * uf.size(b[i]);
	    uf.unite(a[i], b[i]);
	}
    }

    for(int i = v.size() - 1; i >= 0; i--) co << v[i] << en;

    return 0;
}


Measured memory_bytes: 3828
#include <cstdio>
#include <cstring>

int main()
{
	int top[3];
	memset(top, 0, sizeof(top));
	int h;
	while (scanf("%d", &h) != EOF)
	{
		for (int i = 0; i < 3; ++i)
		{
			if (top[i] < h)
			{
				for (int j = 2; j > i; --j)
					top[j] = top[j-1];
				top[i] = h;
				break;
			}
		}
	}
	for (int i = 0; i < 3; ++i)
		printf("%d\n", top[i]);

	return 0;
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int,input().split(" ")))
A.append(0)
SUM = abs(A[0])
for i in range(N):
    SUM += abs(A[i+1]-A[i])
ans = SUM - abs(A[0]) - abs(A[1]-A[0]) + abs(A[1])
print(ans)
for i in range(1,N):
    ans  = SUM - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i]) + abs(A[i+1]-A[i-1])
    print(ans)


Measured memory_bytes: 14172
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for(int i=0;i<n;i++) {
           String[] s=sc.next().split(":");
           double a=Double.parseDouble(s[0])*60;
           double b=Double.parseDouble(s[1]);
           double d=Math.min(Math.abs((a+b)/2-b*6),Math.abs(b*6-(a+b)/2));
           if(d>=180) d=360-d;
           System.out.println(0<=d&&d<30?"alert":90<=d&&d<=180?"safe":"warning");
        }
    }
}


Measured memory_bytes: 29716
uses math;
var
    a:array[0..1000000]of longint;
    n,k,i:longint;
begin
    a[0]:=1;
    readln(n,k);
    for i:=1 to n do
    a[i]:=min(a[i-1]+k,a[i-1]*2);
    writeln(a[n]);
end.


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}


template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}




int main(){

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

    string s;
    cin >> s;
    string c = "CODEFESTIVAL2016";
    int cnt = 0;
    rep(i, 16){
        if(s[i] != c[i])
            cnt++;
    }

    ppp(cnt);



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n;
lint a[2010], dp[2010][2010];
pair<lint, int> p[2010];

int main(){
    scanf("%d", &n);
    rep(i, n) scanf("%lld", &a[i]), p[i] = {a[i], i};
    sort(p, p+n, greater<>());
    rep(i, n+1)rep(j, n+1) dp[i][j] = -INF;
    dp[0][0] = 0;
    rep(i, n)rep(j, i+1)if(dp[i][j] > -INF){
        chmax(dp[i+1][j+1], dp[i][j] + p[i].fi * (p[i].se - j));
        chmax(dp[i+1][j], dp[i][j] + p[i].fi * (n-(i-j)-1 - p[i].se));
    }
    lint ans = -INF;
    rep(i, n+1) chmax(ans, dp[n][i]);
    printf("%lld\n", ans);
}

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

int main(){
    int a,b;
    cin>>a>>b;
    if(a==1) a+=13;
    if(b==1) b+=13;
    if(a==b) cout<<"Draw"<<endl;
    else cout<<(a<b?"Bob":"Alice")<<endl;
}

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

result_list = []
for a in l:
    result_list.extend([a-1,a,a+1])
    
result_list

import collections

count = collections.Counter(result_list) # dictionary としてCounter({5: 1, 1: 3, 3: 2, 2: 2, 4: 2})
hindo_jun = count.most_common() 

print(hindo_jun[0][1])


Measured memory_bytes: 34996
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
int n,m;
int ans=0;
int l,r;

int c[120000];

int lowbit(int x)
{
    return (x&(-x));
}

void add(int loc,int v)
{
    while (loc<=n)
    {
        c[loc]+=v;
        loc+=lowbit(loc);
    }
}

int getsum(int loc)
{
    int ans=0;
    while (loc>0)
    {
        ans+=c[loc];
        loc-=lowbit(loc);
    }
    return ans;
}


int main()
{
    cin >>n >>m;
    for (int i=1; i<=m; ++i)
    {
        scanf("%d %d",&l,&r);
        add(l,1);
        add(r+1,-1);
    }
    for (int i=1; i<=n; ++i)
        if (getsum(i) == m)
            ans++;
    cout<<ans<<endl;
    return 0;
}



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

/**
 * Created by ??\??? on 2016/12/7.
 */
public class Main {
    static int si(String s){
        return Integer.parseInt(s);
    }
    static void run(String[] args) throws Exception{
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        int T = si(scan.readLine());
        String[] lines1 = scan.readLine().split(" ");
        int Q = si(scan.readLine());
        String[] lines2 = scan.readLine().split(" ");
        int num = 0;
        for(String a : lines2){
            int l = 0;
            int r = lines1.length-1;
            int m = (l+r)/2;
            while(l<=r){
                if(si(lines1[m])==si(a)){
                    break;
                }
                else if(si(lines1[m]) < si(a)){
                    l = m+1;
                    m = (l+r)/2;
                }
                else{
                    r = m - 1;
                    m = (l+r)/2;
                }
            }
            if(l<=r){
                num++;
            }
        }
        System.out.println(num);
    }
    public static void main(String[] args) throws Exception{
        run(args);
    }
}

Measured memory_bytes: 47700
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n;
ll a[200];

ll dp[200][30];
int main(){
    scanf("%lld",&n);
    REP(i,n)
        scanf("%lld",a + i);

    REP(i,21){
        dp[0][i] = (i == a[0]);
    }

    FOR(i,1,n - 1){
        REP(j,21){
            ll c = (j - a[i] >= 0) ? dp[i - 1][j - a[i]] : 0;
            ll d = (j + a[i] < 21) ? dp[i - 1][j + a[i]] : 0;
            dp[i][j] = c + d;
        }
    }
    printf("%lld\n", dp[n - 2][a[n - 1]]);
    return 0;
}

Measured memory_bytes: 3252
#include <cstdio>
#include <vector>

std::vector<int> E[2048];
int s;
void dfs(int x, int f, int d) {
	s++;
	if (d--) for (int y : E[x])
		if (y != f) dfs(y,x,d);
}

int main() {
	int n, k, ans = 0;
	scanf("%d%d",&n,&k);
	for (int i = n, u, v; --i;) {
		scanf("%d%d",&u,&v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	if (k & 1) {
		k >>= 1;
		for (int x = 1; x <= n; x++)
			for (int y : E[x]) if (x < y) {
				s = 0;
				dfs(x,y,k);
				dfs(y,x,k);
				if (s > ans) ans = s;
			}
	} else {
		k >>= 1;
		for (int x = 1; x <= n; x++) {
			dfs(x,s = 0,k);
			if (s > ans) ans = s;
		}
	}
	printf("%d\n",n - ans);
	return 0;
}

Measured memory_bytes: 384
import random, math
random.seed()
def gen(a, b, num):
    result = set()
    while 1:
        while 1:
            v = random.randint(a, b)//2*2+1
            if v not in result:
                break
        for x in range(3, int(math.sqrt(v))+1, 2):
            if v % x == 0:
                break
        else:
            result.add(v)
            if len(result) == num:
                break
    return result
class RH():
    def __init__(self, s, base, mod):
        self.base = base
        self.mod = mod
        self.rev = pow(base, mod-2, mod)

        l = len(s)
        self.h = h = [0]*(l+1)
        tmp = 0
        for i in range(l):
            num = ord(s[i])
            tmp = (tmp*base + num) % mod
            h[i+1] = tmp
    def calc(self, l, r):
        return (self.h[r] - self.h[l] * pow(self.base, r-l, self.mod)) % self.mod
    def fixed(self, length):
        v = pow(self.base, length, self.mod)
        h = self.h; mod = self.mod
        def fixed_calc(l):
            return (h[length+l] - h[l] * v) % mod
        return fixed_calc
class RRH():
    def __init__(self, s, num=10, primes=None):
        primes = primes or gen(2, 10**3, num)
        MOD = 10**9+7
        self.rhs = [RH(s, p, MOD) for p in primes]
    def calc(self, l, r):
        return [rh.calc(l, r) for rh in self.rhs]
    def fixed(self, length):
        fs = [rh.fixed(length) for rh in self.rhs]
        def multi_fixed_calc(l):
            return list(f(l) for f in fs)
        return multi_fixed_calc

T = input(); P = input()
primes = gen(2, 10**3, 2)
HT = RRH(T, primes=primes)
HP = RRH(P, primes=primes)

pv = HP.calc(0, len(P))
calc = HT.fixed(len(P))
for i in range(len(T)-len(P)+1):
    if calc(i) == pv:
        print(i)

Measured memory_bytes: 92616
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	int n;
	cin >> n;
	vector<int> v(n);
	REP(i, n) cin >> v[i];
	int ans = 0;
	int i, j;

	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			ans += v[i]*v[j];
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  ll N,M;
  cin >> N >> M;
  if(N==1 && M==1){
    cout << 1 << endl;
    return 0;
  }
  if(N==1 || M==1){
    cout << max(N,M) - 2 << endl;
    return 0;
  }
  cout << N*M - (N+M)*2 + 4 << endl;
  return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ _, a, b ] <- readInts
	putStrLn $ which "Alice" "Borys" $ ( b - a ) `mod` 2 == 0


Measured memory_bytes: 508
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(int i=a;i<b;i++)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<b>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数

int main() {
  string a;
  ci(a);
  ll b=a.size();
  for(int i=0;i<b;i+=2)
    cout<<a[i];
  }

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
char s[20];
int a[20];
long long res,n;
long long check()
{
	long long t=0,sum=0;
	for(int i=0;i<n-1;i++)
	{
		t=t*10+s[i];
		if(a[i])
		{
			sum+=t;
			t=0;
		}
	}
	t=t*10+s[n-1];
	return t+sum;
}
void dfs(int k)
{
	if(k==n-1)
	{
		res+=check();
		return;
	}
	a[k]=0;
	dfs(k+1);
	a[k]=1;
	dfs(k+1);
}
int main()
{
	cin>>s;
	n=strlen(s);
	for(int i=0;i<n;i++)
		s[i]-=48;
	dfs(0);
	cout<<res; 

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
  int main(){
 int a,b;
    while(scanf("%d%d",&a,&b) != EOF){
   int oa,ob;
     oa = a;
     ob = b;
     while(a%b != 0 && b%a != 0){
        if(a>b){
          while(a>b){
            a -= b;
              }
                }
               else if(b>a){
                while(b>a){
                     b -= a;
                     }
                         } 
}
int x;
if(a>b){
x = b;
}
else{
x = a;
}
int y= oa/x;
y *= ob;
printf("%d %d\n",x,y);
}
return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,m;
ll s,t;
struct edge{/*重み付き,有向*/
    int to , cost;/*toは接続先*/
    edge(ll to_ ,ll cost_ = 1){ to=to_; cost=cost_; };/*全てのcost=1 <=> 無向グラフ*/
};
bool operator<(edge e1 ,edge e2){return e1.cost < e2.cost; }
bool operator>(edge e1 ,edge e2){return e1.cost > e2.cost; }
using graph =  vector< vector<edge> >;
graph g;

Vi dijkstra(graph _g,ll start){
    Vi dist; //for dijkstra. distance from start
    dist.resize(_g.size()); dist.resize(_g.size());
    rep(i,dist.size())dist[i]=INF;
    auto comp_pq = [](pair<ll,ll> x,pair<ll,ll> y){return x.second > y.second;};
    priority_queue< pair<ll,ll> , vector<pair<ll,ll>>, decltype(comp_pq)> pq{comp_pq};
    dist[start]=0; pq.push(mp(start,0));
    while (pq.size()>0){
        PLL p = pq.top();
        pq.pop();
        if(p.second > dist[p.first])continue;
        rep(i,_g[p.first].size()){
            if(dist[p.first]!=INF){
                if(chmin(dist[_g[p.first][i].to],dist[p.first]+_g[p.first][i].cost)){
                    pq.push(mp(_g[p.first][i].to,dist[_g[p.first][i].to]));
                }
            }
        }
    }
    return dist;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>m;
    g.resize(n*3);
    ll aa,bb;
    rep(i,m){
        cin>>aa>>bb;
        aa--;
        bb--;
        g[aa*3].pb(bb*3+1);
        g[aa*3+1].pb(bb*3+2);
        g[aa*3+2].pb(bb*3);
    }
    cin>>s>>t;
    Vi dis = dijkstra(g,(s-1)*3);
    if(dis[(t-1)*3]==INF){
        print(-1);
    }else{
        print(dis[(t-1)*3]/3);
    }
    return 0;
}

Measured memory_bytes: 35456
# include <iostream>
# include <memory.h>
using namespace std;
static const int MAX = 100;
static const int INF = 0x7fffffff;
int n,a[MAX][MAX];
void dijkstra()
{
	int minv;
	int d[MAX];
	bool vis[MAX];
	for(int i = 0;i < n;i++)
	{
		d[i] = INF;
		vis[i] = false;
	}
	d[0] = 0;
	while(true)
	{
		minv = INF;
		int u = -1;
		for(int i = 0;i < n;i++)
		{
			if(!vis[i] && minv > d[i])
			{
				u = i;
				minv = d[i];
			}
		}
		if(u == -1) break;
		vis[u] = 1;
		for(int v = 0;v < n;v++) if(!vis[v] && a[u][v] != INF) d[v] = min(d[v],d[u]+a[u][v]);
	}
	for(int i = 0;i < n;i++) printf("%d %d\n",i,(d[i] == INF)?-1:d[i]);
} 
int main(void)
{
	int u,v,k,dis;
	scanf("%d",&n);
	for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) a[i][j] = INF;
	for(int i = 0;i < n;i++)
	{
		scanf("%d %d",&u,&k);
		for(int j = 0;j < k;j++)
		{
			scanf("%d %d",&v,&dis);
			a[u][v] = dis;
		}
	}
	dijkstra();
	return 0;
}


Measured memory_bytes: 3236
def main():
    import itertools
    import sys
    input = sys.stdin.readline
    N, A, B, C = map(int, input().split())
    D = [A,B,C]
    L = [int(input()) for i in range(N)]
    L = sorted(L)
    X = [[],[],[],[]]
    l = [0,1,2,3]
    p = itertools.product(l, repeat = N)
    q = itertools.product()
    ans = float("inf")
    for v in p:
        tmp = 0
        X = [[],[],[],[]]
        for i in range(len(v)):
            X[v[i]].append(L[i])
        if X[0] != [] and X[1] != [] and X[2] != []:
            for j in itertools.permutations(D,3):
                for k in range(3):
                    tmp += 10* (len(X[k])-1) + abs(j[k] - sum(X[k]))
                if tmp < ans:
                    ans = tmp
    print(ans)
    
    
main()

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

int main(){
    while(true){
        int n; cin >> n;
        if(n == 0) break;
        int m = 1001001; // mは1000000より大きな数で初期化
        // z^3, y^2を決める、この時 O(10^2*10^3) = O(10^5)で間に合う
        for(int i = 0; i*i*i <= n; i++){ 
            for(int j =0 ; j*j <= n - i*i*i; j++){ 
                int x = n - i*i*i - j*j; 
                m = min(m, i + j + x); //最小の値
            }
        }
        cout << m << endl;
    }
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 2000000000
#define MAX 100001
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

ll lpow(int a, int n){
    if(n == 0) return 1;
    return a * lpow(a, n-1);
}

signed main(){ INIT;
    VAR(int, n, p);
    VEC(int, a, n);
    
    int odd = 0;
    REP(i, n) if(a[i]%2) odd = 1;

    if(odd){
        printf("%lld\n", lpow(2, n-1));
    }else{
        printf("%lld\n", p ? 0 : lpow(2, n));
    }
RET;}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sax(x) cout << "!!!!!!!!!!! " << #x << " = " << x << '\n'
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)
#define one(x) x.insert(x.begin(), 0);
#define TCT template <class T>
#define TCT12 template <class T1, class T2>
#define IS istream
#define OS ostream
#define OP operator

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
//tree_order_statistics_node_update> imsi;

TCT IS& OP>>(IS &I, vector<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT IS& OP>>(IS &I, deque<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, priority_queue<T> v) {while (!v.empty()) {O << v.top() << ' '; v.pop();} return O;}
TCT OS& OP<<(OS &O, stack<T> v) {while (!v.empty()) {O << v.top() << '\n'; v.pop();} return O;}
TCT OS& OP<<(OS &O, queue<T> v) {while (!v.empty()) {O << v.front() << ' '; v.pop();} return O;}
TCT12 IS& OP>>(IS &I, pair<T1,T2>& p) {return I >> p.first >> p.second;}
TCT12 OS& OP<<(OS &O, const pair<T1,T2>& p) {return O << '(' << p.first << ' ' << p.second << ')';}
TCT12 OS& OP<<(OS &O, const unordered_map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
TCT12 OS& OP<<(OS &O, const map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
typedef pair<int,int> pii;
typedef vector<int> vi;





void _main() {
        int n; cin >> n;
        int ans = 0;
        if (n % 2 == 0) {
                for (int i = 5; n / (i * 2) >= 1; i *= 5) {
                        ans += n / (2 * i);
                }
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

const int nmax=40, abmax=10, inf=10000000;
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,ma,mb;
  cin >> n >> ma >> mb;
  vector<int> a(n), b(n), c(n);
  REP(i,n) cin >> a[i] >> b[i] >> c[i];
  REP(i,nmax+1) REP(j,nmax*abmax+1) REP(k,nmax*abmax+1) dp[i][j][k]=inf;
  dp[0][0][0] = 0;
  
  REP(i,n){
    REP(j,nmax*abmax){
      REP(k,nmax*abmax){
        if(dp[i][j][k]==inf) continue;
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
      }
    }
  }
  int ans = inf;
  FOR(j,1,nmax*abmax){
    FOR(k,1,nmax*abmax){
      if(j*mb==k*ma) ans = min(ans,dp[n][j][k]);
    }
  }
  cout << (ans==inf ? -1 : ans) << '\n';
  return 0;
}


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

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ld long double
#define pb push_back
#define fe first
#define se second
#define nl "\n"
#define pp pair < ll , ll > 
#define sz(x) (ll)x.size()
#define st(x) sort(x.begin(),x.end())
#define rst(x) sort(x.rbegin(), x.rend())
#define all(x) x.begin(),x.end()
long double pi = 3.14159265358979323;
 
const double EPS = 1e-12;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
 
 
 
 
int main()
{
    fast;
    ll n;
    cin >> n ;
    ll mat[n+1][3];
    for(int i = 1 ; i <= n ;i++ ){
        for(int j = 0 ; j < 3 ; j++ ){
            cin >> mat[i][j];
        }       
    }
    ll dp[n+1][3] = {};
    for(int i = 1 ; i <= n ; i++ ){
        dp[i][0] = mat[i][0] + max(dp[i-1][1] , dp[i-1][2]);
        dp[i][1] = mat[i][1] + max(dp[i-1][0] , dp[i-1][2]);
        dp[i][2] = mat[i][2] + max(dp[i-1][1] , dp[i-1][0]);
    }
    cout << max({dp[n][0] , dp[n][1] , dp[n][2]});
    





















    
    return 0;
    
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

void Flow(vector<set<ll>>& tree, vector<ll>& flow, ll parent, ll child){
    for(auto tmp : tree[child]){
        if (tmp != parent) {
            flow[tmp] += flow[child];
            Flow(tree, flow, child, tmp);
        }
    }
}

int main() {
    ll N, Q;
    cin >> N >> Q;
    vector<set<ll>> A(N);
    ll a, b;
    REP(i, N - 1){
        cin >> a >> b;
        A[a - 1].insert(b - 1);
        A[b - 1].insert(a - 1);
    }
    //cout << "Hi" << endl;

    vector<ll> flow(N, 0);
    REP(i, Q){
        cin >> a >> b;
        flow[a - 1] += b;
    }
    /*
    //cout << "Hi" << endl;
    vector<ll> ans(N, 0);
    REP(i, N){
        ans[i] += flow[i];
        for(auto tmp : A[i]){
            flow[tmp] += flow[i];
            //cout << "Hi" << endl;

        }
        cout << ans[i] << " ";
    }
    cout << endl;
*/

    Flow(A, flow, -1, 0);
    REP(i, N) cout << flow[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 47744
# include <iostream>

using namespace std;

int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;

    int count = 0;
    for (int i=0; i<=a; i++) {
        for (int j=0; j<=b; j++) {
            for (int k=0; k<=c; k++) {
                if (500 * i + 100 * j + 50 * k == x) {
                    count ++;
                }
            }
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int h[6],w[6],i,j,blank,a=0;

  for(i = 0; i < 6; i++){

    scanf("%d %d",&h[i],&w[i]);
    if(h[i] > w[i]){

      blank=h[i];
      h[i]=w[i];
      w[i]=blank;

    }

  }

  for(i = 0; i < 5; i++){

    for(j = 0; j < 5; j++){

      if(h[j] > h[j+1]){

        blank=h[j];
        h[j]=h[j+1];
        h[j+1]=blank;

        blank=w[j];
        w[j]=w[j+1];
        w[j+1]=blank;

      }

      if(h[j] == h[j+1] && w[j] > w[j+1]){

        blank=w[j];
        w[j]=w[j+1];
        w[j+1]=blank;

      }

    }

  }

  //for(i = 0; i < 6; i++) printf("%d %d\n",h[i],w[i]);

  for(i = 0; i < 6; i += 2){

    if(h[i] != h[i+1]) a++;
    if(w[i] != w[i+1]) a++;

  }

  if(a != 0){

    printf("no\n");

    return 0;

  }

  if(h[0] == h[2] && w[0] == h[4] && w[2] == w[4]) printf("yes\n");
  else printf("no\n");

  return 0;

}

Measured memory_bytes: 2668
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng(1012);
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "b"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define retet(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    string s; cin>>s;
    int A=0;
    long long ret=0;
    forinc(i,0,s.size()-1){
        if(s[i]=='A') A++;
        else if(i+1<s.size() && s[i]=='B'&&s[i+1]=='C') ret+=A,i++;
        else A=0;
    }
    cout<<ret;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
    int n;
    int k;
    int x;
    int y;
    cin >> n;
    cin >> k;
    cin >> x;
    cin >> y;
    if(k < n){
        cout << k * x +(n - k) * y << endl;
    }
    else{
        cout << n * x << endl;
    }
}

Measured memory_bytes: 256