akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set> 
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define mxlen 1000+9
#define inf 100009
#define INF (int)1e9
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;

int n;
int a[inf];

int main(){
	rd(n)
	for (int i=1;i<=n;i++){
		rd(a[i])
	}
	sort(a+1,a+n+1);
	if (a[n]-a[1]>1){
		puts("No");
		return 0;
	}
	if (a[n]-a[1]==0){
		if (a[1]==n-1 || a[1]<=n/2){
			puts("Yes");
		}
		else{
			puts("No");
		}
		return 0;
	}
	int cnt1,cnt2;
	for (int i=1;i<n;i++){
		if (a[i]!=a[i+1]){
			cnt1=i;
			cnt2=n-i;
			break;
		}
	}
	if (a[1]<=cnt1-1){
		puts("No");
		return 0;
	}
	a[n]-=cnt1;
	if (!a[n]){
		puts("No");
		return 0;
	}
	int col;
	if (a[n]*2>cnt2){
		col=cnt2;
	}
	else if (a[n]<=cnt2/2){
		col=a[n];
	}
	else{
		puts("No");
		return 0;
	}
	if (col+cnt1-1!=a[1]){
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}

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

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;

int main() {
    int nn;
    scanf("%d", &nn);

    for (int n = 1; n <= nn; n++) {
        int cnt = 0;
        for (int i = 1; i * i <= n; i++) {
            for (int j = 1; j * j <= n; j++)
                for (int k = 1; k * k <= n; k++) {
                    int qq = i*i+j*j+k*k+i*j+j*k+i*k;
                    if (qq==n) cnt++;
                    if (qq>n) break;
                }
        }
        printf("%d\n", cnt);
    }
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
int N,X;
int piyo(int x){
    if(x!=0)return x-1;
    if(x==0)return N-1;
}

signed main(){
    cin>>N>>X;
    int A[N];
    REP(i,N){
        cin>>A[i];
    }
    int ans=INF;
    int T[N][N];//T[1][2]はi=1のときのスライム2+1を取る最小時間(i=魔法回数)
    REP(i,N){
        if(i==0)REP(j,N)T[i][j]=A[j];
        else{
            REP(j,N)T[i][j]=min(T[i-1][piyo(j)],A[j]);
        }
    }
    REP(i,N){
        int preans=i*X;
        REP(j,N)preans+=T[i][j];
        ans=min(ans,preans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 31488
#include<bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
        int K,S; cin>>K>>S;
        int ans=0;
        for(int x=0;x<=K;x++){
                for(int y=0;y<=K;y++){
                        int z=S-(x+y);
                        if(0<=z and z<=K) ans++;
                }
        }
        cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		int c = 0;
		for(int x = 0; x <= K; x++) {
			for(int y = 0 ; y <= K; y++) {
				int z = S - x - y;
				if(0 <= z && z <= K) {
					c += 1;
				}
			}
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int n,m,d;
int main(){
	cin>>n>>m>>d;
	if(d==0) printf("%.10f\n",1.0*(m-1)/n);
	else printf("%.10f\n",1.0*2*(m-1)*(n-d)/n/n);
	return 0; 
}

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



int main(void){
  int n, count = 0;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p.at(i);
  }
  for(int i = 0; i < n - 2; i++){
    if(p.at(i) < p.at(i + 1) && p.at(i + 1) < p.at(i + 2)){
      count++;
    }else if(p.at(i) > p.at(i + 1) && p.at(i + 1) > p.at(i + 2)){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){

  int D,N;
  cin>>D>>N;
  int ans=0;
  switch(D){
  
    case 0:
      if(N==100){
      
        ans=101;
      }
      else{
      
        ans=N;
      }
      break;
    case 1:
      if(N==100){
      
        ans=10100;
      }
      else{
      
        ans=N*100;
      }
      break;
    case 2:
      if(N==100){
      
        ans=1010000;
      }
      else {
      
        ans=N*10000;
      }
      break;
  }
  cout<<ans;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		if(S.equals("Sunny")) {
			System.out.println("Cloudy");
		}
		if(S.equals("Cloudy")) {
			System.out.println("Rainy");
		}
		if(S.equals("Rainy")) {
			System.out.println("Sunny");
		}
		sc.close();
	}

}


Measured memory_bytes: 21332
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
//const int MM = 1e9;
const int MOD = 1e9+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > pq;

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}

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


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


bool IsPrime(int x){
    for (int i = 2; i*i <= x; i++){
        if (x % i == 0){
            return false;
        }
    }
    return true;
}

vector<pair<ll, ll> > PrimeFactor(ll N){
    vector<pair<ll, ll> > prime;
    for (int i = 2; i*i <= N; i++){
        if (N % i != 0) continue;
        int cnt = 0;
        while (N % i == 0){
            cnt++;
            N /= i;
        }
        prime.push_back({i, cnt});
    }
    if (N > 1){
        prime.push_back({N, 1});
    }
    return prime;
}

vector<pair<ll, ll> > CountPrime(ll N){
    vector<pair<ll, ll> > prime;
    for (ll i = 2; i * i <= N; i++){
        if (N % i != 0) continue;
        ll cnt = 0, n = N;
        while (n % i == 0){
            cnt++;
            n /= i;
        }
        prime.push_back({i, cnt});
    }
    prime.push_back({N, 1});
    return prime;
}

int main(){
    ll N, P; cin >> N >> P;
    ll res = 1;
    vector<pair<ll, ll> > prime = CountPrime(P);
    for (auto p: prime){
        if (p.second >= N){
            res = max(res, p.first);
        }
    }
    cout << res << endl;
}

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

using namespace std;

const int N = (int) 1e5 + 10;

int n;
int a[N];
map <int, int> cnt;

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  sort(a + 1, a + 1 + n);
  if (cnt.size() == 1) {
    cout << n;
    return 0;
  } else if (cnt.size() == 2) {
      if (a[n] - a[1] == 1 || a[n] - a[1] == 2) return cout << n, 0;
      int cnt1 = 0, cnt2 = 0;
      for (int i = 1; i <= n; i++)
          if (a[i] == a[1]) cnt1++;
          else if (a[i] == a[n]) cnt2++;
      return cout << max(cnt1, cnt2), 0;
  } else {
      int ans = 0;
      for (int i = 1; i <= n; i++) {
          ans = max(ans, cnt[a[i]] + cnt[a[i] - 1] + cnt[a[i] + 1]);
      }
      cout << ans << "\n";
  }
  return 0;
}

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

const int OMEGA = 10000000;

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    
    int a[n][m];
    vector<int> c(n);
    rep(i,n){
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }

    int ans = OMEGA;
    rep(k, 1 << n){
        int cost = 0;
        vector<int> d(m);
        rep(i, n){
            if (k >>i & 1){
                cost += c[i];
                rep(j, m) d[j] += a[i][j];
            }
        }
        bool possible = true;
        rep(j, m) if(d[j] < x) possible = false;
        if (possible) ans = min(ans, cost);
    }
    if (ans == OMEGA) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << "\n";
    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,y; cin>>n>>y;
	for(int i=0;i<=n;++i){
		for(int j=0;j<=n-i;++j){
			int k=n-i-j;
			if(1L*10000*i+1L*5000*j+1L*1000*k==y){
				cout<<i<<" "s<<j<<" "s<<k<<"\n"s;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1\n"s;
}

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

int i,j,k,m,n;
int a[100010];

int gcd(int a,int b){
	int t=min(a,b);
	while(t){
		if(a%t==0 && b%t==0)
			break;
		t--;
	}
	return t;
}

int main() {
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		int t;
		scanf("%d",&t);
		a[i]=abs(t-m);
	}
	if(n==1){
		printf("%d",a[1]);
		return 0;
	}
	int ans=gcd(a[1],a[2]);
	for(i=3;i<=n;i++)
		ans=gcd(ans,a[i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
n=int(input())
ab=[list(map(int, input().split())) for _ in range(n)] 
cd=[list(map(int, input().split())) for _ in range(n)] 

#ab = sorted(ab, key=lambda x:x[1]*(-1))
ab.sort(key=lambda x: x[1],reverse=True)
cd=sorted(cd)

cnt=0
for i in range(n):#ab
    for j in range(len(cd)):#cd
        if ab[i][0]<cd[j][0] and ab[i][1]<cd[j][1]:
            cnt+=1
            cd.pop(j)
            break
print(cnt)

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

int main(void){
   long long N,M,K;
   cin>>N>>M>>K;
   vector<long long> A(N),B(M);
   for(int i=0;i<N;i++){
      cin>>A[i];
   }
   for(int i=0;i<M;i++){
      cin>>B[i];
   }
   vector<long long> sumA(N+1,0);
   vector<long long> sumB(M+1,0);
   sumA[0]=0;
   sumB[0]=0;
   for(int i=0;i<N;i++){
      sumA[i+1]=sumA[i]+A[i];
   }
   for(int i=0;i<M;i++){
      sumB[i+1]=sumB[i]+B[i];
   }
   long long ans=0,j=M;
   for(int i=0;i<N+1;i++){
      if(sumA[i]>K) break;
      while(sumB[j]>K-sumA[i]){
         j-=1;
      }
      ans=max(ans,i+j);
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 9572
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[] ac = new boolean[n];
		int[] wa = new int[n];
		for(int i= 0; i < n; i++) {
			ac[i] = false;
			wa[i] = 0;
		}
		for(int i = 0; i < m; i++) {
			int sub = sc.nextInt()-1;
			String result = sc.next();
			if(ac[sub]) {
				continue;
			}
			else {
				if(result.equals("AC")) {
					ac[sub]=true;
				}
				else {
					wa[sub]++;
				}
			}
		}
		int ac_count=0;
		int wa_count = 0;
		for(int i = 0; i < n; i++) {
			if(ac[i]) {
				ac_count++;
				wa_count+=wa[i];
			}
		}
		System.out.println(ac_count+" "+wa_count);
	}
}

Measured memory_bytes: 62112
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <climits>
using namespace std;
typedef long long ll;

int n;
vector<pair<int, ll>> *adj_yen, *adj_snook;
ll *d_yen, *d_snook;

void dijkstra(int start, vector<pair<int, ll>> *adj, ll *d) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> PQ;
    for (int i = 0; i < n + 1; i++) {
        d[i] = LLONG_MAX;
    }
    d[start] = 0;

    PQ.push(make_pair(0, start));
    while (!PQ.empty()) {
        pair<int, ll> f = PQ.top();
        PQ.pop();
        int u = f.second;
        for (int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i].first;
            if (d[u] + adj[u][i].second < d[v]) {
                d[v] = d[u] + adj[u][i].second;
                PQ.push(make_pair(d[v], v));
            }
        }
    }
}

int main() {
    int m, s, t;
    scanf("%d %d %d %d", &n, &m, &s, &t);

    adj_yen = new vector<pair<int, ll>>[n+1];
    adj_snook = new vector<pair<int, ll>>[n+1];
    d_yen = new ll[n+1];
    d_snook = new ll[n+1];

    for (int i = 0; i < m; i++) {
        int u, v;
        ll a, b;
        scanf("%d %d %lld %lld", &u, &v, &a, &b);
        adj_yen[u].push_back(make_pair(v, a));
        adj_snook[u].push_back(make_pair(v, b));
        adj_yen[v].push_back(make_pair(u, a));
        adj_snook[v].push_back(make_pair(u, b));
    }

    dijkstra(s, adj_yen, d_yen);
    dijkstra(t, adj_snook, d_snook);

    vector<ll> costs;
    costs.push_back(d_yen[n] + d_snook[n]);
    for (int i = n - 1; i > 0; i--) {
        costs.push_back(min(costs.back(), d_yen[i] + d_snook[i]));
    }

    for (int i = n - 1; i >= 0; i--) {
        printf("%lld\n", 1000000000000000 - costs[i]);
    }

    return 0;
}

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

int main() {
  int a, b, c, d, e, k;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  cin >> k;
  if (e - a <= k) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define INIT_CAP 10
#define INF 1000000000

#define min(a, b) (((a) < (b)) ? (a) : (b))

const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, 1, 0, -1};

typedef struct {
	int to, w;
} Edge;

typedef struct {
	Edge *elem;
	int cap, size;
} VecEdge;

typedef struct {
	int num;
	int d;
} PNumDis;

typedef struct {
	int d;
	int idx;
} Node;

VecEdge adj[30 * 30 * 4];
PNumDis heap[30 * 30 * 4];
int hsize;
Node node[30 * 30 * 4];

int w, h;
int field[30][30];

void init(int n) {
	while (n--)
		adj[n] = (VecEdge){malloc(sizeof(Edge) * INIT_CAP), INIT_CAP, 0};
}

inline void add(int from, int to, int w) {
	if (adj[from].size == adj[from].cap) {
		adj[from].cap <<= 1;
		adj[from].elem = realloc(adj[from].elem, sizeof(Edge) * adj[from].cap);
	}
	adj[from].elem[adj[from].size++] = (Edge){to, w};
}

void freeAll(int n) {
	while (n--)
		free(adj[n].elem);
}

inline int calcNextIdx(int i) {
	return i * 2 + 1 + (i * 2 + 2 < hsize && heap[i * 2 + 1].d > heap[i * 2 + 2].d);
}

inline PNumDis delete(void) {
	int i;
	int nextIdx;
	const PNumDis root = heap[0], last = heap[--hsize];

	for (i = 0; i * 2 + 1 < hsize && last.d > heap[nextIdx = calcNextIdx(i)].d; i = nextIdx) {
		heap[i] = heap[nextIdx];
		node[heap[i].num].idx = i;
	}
	heap[i] = last;
	node[last.num].idx = i;

	return root;
}

inline void decreaseKey(int num, int d) {
	int i;

	for (i = node[num].idx; i > 0 && d < heap[i - 1 >> 1].d; i = i - 1 >> 1) {
		heap[i] = heap[i - 1 >> 1];
		node[heap[i].num].idx = i;
	}
	heap[i] = (PNumDis){num, d};
	node[num].idx = i;
}

void dijkstra(int n, int s) {
	int i;

	for (i = 0; i < n; i++) {
		heap[i] = (PNumDis){i, INF};
		node[i] = (Node){INF, i};
	}
	hsize = n;

	node[s].d = 0;
	decreaseKey(s, 0);
	while (hsize > 0) {
		const PNumDis fromP = delete();
		for (i = 0; i < adj[fromP.num].size; i++) {
			const Edge e = adj[fromP.num].elem[i];
			if (fromP.d + e.w < node[e.to].d) {
				node[e.to].d = fromP.d + e.w;
				decreaseKey(e.to, node[e.to].d);
			}
		}
	}
}

int main(void) {
	int i, j, k, l;

	while (scanf("%d %d", &w, &h), w) {
		int c[4];

		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				scanf("%d", field[i] + j);

		for (i = 0; i < 4; i++)
			scanf("%d", c + i);

		init(h * w * 4);

		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				for (k = 0; k < 4; k++)
					for (l = 0; l < 4; l++) {
						int nd = k + l & 3;
						int ni = i + di[nd], nj = j + dj[nd];
						if (ni >= 0 && ni < h && nj >= 0 && nj < w)
							add(i * w * 4 + j * 4 + k, ni * w * 4 + nj * 4 + nd, l == field[i][j] ? 0 : c[l]);
					}

		dijkstra(h * w * 4, 1);

		printf("%d\n", min(node[(h - 1) * w * 4 + (w - 1) * 4 + 1].d, node[(h - 1) * w * 4 + (w - 1) * 4 + 2].d));

		freeAll(h * w * 4);
	}

	return 0;
}

Measured memory_bytes: 1052
n = int(input())
n -= 1
a = 0
dig = 1
while a + 26**dig <= n:
    a += 26**dig
    dig += 1
n -= a
ans = []
for i in range(dig):
    ans += [chr(n % 26 + 97)]
    n //= 26
print(''.join(reversed(ans)))

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second

int32_t main() {
	int n,m,x;
	cin>>n>>m>>x;
	int ans = 1e9;
	int c[n],a[n][m];
	for(int i=0;i<n;i++){
		cin>>c[i];
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	}
	for(int mask =1;mask<(1ll<<n);mask++){
		int cost = 0;
		int mp[m] = {0};
		for(int j=0;j<n;j++){
			if(mask&(1ll<<j)){
				cost+=c[j];
				for(int k =0;k<m;k++)
					mp[k]+=a[j][k];
			}
		}
		bool okk = true;
		for(int j =0;j<m;j++){
			if(mp[j]<x)
				okk = false;
		}
		//cout<<mask<<" "<<cost<<endl;
		if(okk)
			ans = min(ans,cost);
	}
	if(ans == 1e9)
		ans=-1;
	cout<<ans<<endl;
}	

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
const int INF = 100000000;

//A問題

// int main(){
//   int n, x, t;
//   cin >> n >> x >> t;
//   if(n % x == 0){
//     cout << n/x*t << endl;
//   }else{
//     cout << (n/x + 1)*t << endl;
//   }
// }

//B問題

int main(){
    int n;
    ll sum = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i-1] > a[i]){
            sum += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }

    cout << sum << endl;
}

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

def F(a,b):
    a_digit=len(str(int(a)))
    b_digit=len(str(int(b)))
    if a_digit>b_digit:
        return a_digit
    else:
        return b_digit
min=len(str(N))

for i in range(1,int(N**(0.5))+1):
    if int(N/i)==N/i:
        if F(N/i,i)<min:
            min=F(N/i,i)
            

print(min)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
    int w,i,n,l,r;scanf("%d\n%d\n",&w,&n);
    int a[w];
    for(i=0;i<w;i++) a[i] = i+1;
    for(i=0;i<n;i++){
        scanf("%d,%d\n",&l,&r);
        swap(a[l-1],a[r-1]);
    }
    for(i=0;i<w;i++) printf("%d\n",a[i]);
}


Measured memory_bytes: 3088
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

ll mynchoosek(ll n, ll k) {
  ll ans = 1;
  map<ll, ll> pf;
  auto prime_factor = [&](ll n, ll mode) {
    for (ll i = 2; i * i <= n; i++) {
      while (n % i == 0) {
        pf[i] += mode;
        n /= i;
      }
    }
    if (n != 1) pf[n] += mode;
  };

  rep(i, k) {
    prime_factor(n - i, 1);
    prime_factor(i + 1, -1);
  }

  for (auto& kv : pf) {
    rep(i, kv.second) { ans *= kv.first; }
  }

  return ans;
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

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

  vll vs(n);
  map<ll, ll> stat;
  rep(i, n) {
    cin >> vs[i];
    stat[vs[i]]++;
  }
  Sort(vs);

  double mean = 0.0;
  map<ll, ll> mstat;
  rep(i, a) {
    mean += vs[n - 1 - i];
    mstat[vs[n - 1 - i]]++;
  }
  mean /= a;

  ll ans = 0;
  if (vs[n - 1] == vs[n - a]) {
    repLRE(i, a, b) {
      ll nn = stat[vs[n - 1]];
      ans += mynchoosek(nn, i);
    }
  } else {
    ll nn = stat[vs[n - a]];
    ll kk = mstat[vs[n - a]];
    ans = mynchoosek(nn, kk);
  }

  cout << mean << endl;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)
ans = 0
n.times do |i|
    if a[i] >= b[i]
        ans += b[i]
    else
        b[i] -= a[i]
        ans += a[i]
        if b[i] >= a[i+1]
            ans += a[i+1]
            a[i+1] = 0
        else
            a[i+1] -= b[i]
            ans += b[i]
        end
    end
end

puts ans

Measured memory_bytes: 17572
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const int INF = 1000000007;

int N, A[100005];
vector<int> v;

int main(void) {
  cin >> N;
  for(int i=0; i<N; i++) {
    int a; scanf("%d", &a);
    a *= -1;
    auto itr = upper_bound(v.bg, v.en, a);
    if (itr==v.en) v.pb(a);
    else *itr = a;
    
  }
  cout << v.size() << endl;
  
  
    
    return 0;
}



Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main()
{
int n,i,j,c,a=0;
cin>>n;
for(i=1;i<=n;i+=2)
{
    c=0;
    for(j=1;j<=i;j+=2)
    {
        if(i%j==0)
            c++;
    }
    if(c==8)a++;
}
cout<<a<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
	int ball[10];
	int cell[2][10]={0};
	int n,i,k,cell_1=1,cell_2=1,flag[1000]={0};
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
		for(i=0;i<10;i++)scanf("%d",&ball[i]);
		
		cell[0][0]=cell[1][0]=0;
		
		for(i=0;i<10;i++){
			if(cell[0][cell_1-1] < ball[i]){
				cell[0][cell_1]=ball[i];
				cell_1++;
			}
			else if(cell[1][cell_2-1] < ball[i]){
				cell[1][cell_2]=ball[i];
				cell_2++;
			}
			else flag[k]=1;
		}	
	cell_1=1;
	cell_2=1;
	}
	
	for(i=0;i<n;i++){
		if(flag[i]==0)printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

Measured memory_bytes: 1008
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
import copy
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

n = int(input())
List = list(map(int, input().split()))
N = max(List)
A = defaultdict(int)
for e in List:
    A[e] += 1
furui = [True]*(N+1)

state = "pairwise coprime"
for i in range(2, N+1):
    if not furui[i]:
        continue
    count = 0
    k = i
    while k <= N:
        if k in A:
            count += A[k]
            if count >= 2:
                # print(i, k)
                state = "setwise coprime"
            if count == n:
                print("not coprime")
                exit()

        furui[k] = False
        k += i

print(state)


Measured memory_bytes: 253276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int main(){
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	int ans=0;
	if(n<=k) ans+=n*x;
	else if(n>k) ans+=k*x+(n-k)*y;
	cout<<ans;
	return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, k; cin >> n >> k;

  vector<bool> v(n, 1);
  rep(i, k) {
    int x; cin >> x;
    rep(j, x) {
      int y; cin >> y;
      v[y-1] = 0;
    }
  }

  int ans = 0;
  rep(i, n) {
    ans += v[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3644
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  ll ans = 1;
  while (n >= k){
    n /= k;
    ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<int>;
using vv = vector<vi>;
//const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1001001001001;

int main(){
    int n;cin>>n;
    string s;
    cin>>s;
    
    vi a(n,0);
    
    rep(i,n){
        
        if(i)a[i] = a[i-1];
        
        if(s[i]=='R'){
            a[i]++;
        }
        
    }
    
    int ans = a[n-1];
    
    rep(i,n){
        ans = min(ans, max(i+1-a[i], a[n-1]-a[i]));
    }
    
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4448
#include<bits/stdc++.h>
#define pi 3.14159
using namespace std;

struct ca
{
  int idx,st,et,aidx;
};

int prime[1000001]={};

int power(int x, unsigned int y, int p)  
{  
    int res = 1;     
  
    x = x % p; 
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
         
        if (y & 1)  
            res = (res*x) % p;  
  
        
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  

void pr()
{
  prime[1]=0;

 for(int i=2;i*i<1000001;i++)
  if(prime[i]==0)
  for(int j=i*i;j<1000001;j+=i)
  prime[j]=1;

}

int countSetBits( int n) 
{ 
     int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 
  
bool cmp1(ca c1,ca c2)
{
  if(c1.st<c2.st)
   return true;

  if(c1.st==c2.st && c1.idx<c2.idx)
   return true;

  return false;
}

bool cmp2(ca c1,ca c2)
{
  
  if(c1.idx<c2.idx)
  return true;
  return false;
}








int main()
{

  ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   //pr();
  int t;
  // cin>>t;
   t=1;
  int id=1;

  while(t--)
{
    int n,m;
     cin>>n>>m;

   int sum=0;

   for(int i=0;i<m;i++)
 {
    int a; 
     cin>>a;
    sum+=a;
 }

   if(sum>n)
  cout<<"-1";

   else
  cout<<n-sum;
   
}



return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <deque>
#include <iomanip>
#include <queue>
using namespace std;
#define rep(i,n) for (ll i=0;i<n;i++)
#define REP(i,n) for (ll i=1;i<=n;i++)
#define PI 3.141592653589793238462643383279
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1000000000000000;

ll N;
ll T;
ll S[200100];

int main() {
	cin >> N >> T;
	rep(i, N) cin >> S[i];
	ll sum = 0;
	ll now = 0;
	rep(i, N - 1) {
		sum += min(T, S[i + 1] - S[i]);
	}
	sum += T;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            //int[] a = new int[n];
            long[] cost = new long[201];
            for (int i = 0; i < n; i++) {
                int ca = in.nextInt();
                for (int j = 0; j <= 200; j++) {
                    int cb = j - 100;
                    int cd = ca - cb;
                    cost[j] += cd * cd;
                }
            }
            long ans = cost[0];
            for (long cc : cost)
                ans = Math.min(cc, ans);
            out.println(ans);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            int n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



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

int main()
{
string s;
cin>>s;
bool flag=0;
if(s.length()>9)
{
flag=1;
}
else
{
for(int i=0;i<s.length();i++)
{
if((i<s.length())&&((s.substr(i,i+1)=="KA")||(s.substr(i,i+1)=="AI")||(s.substr(i,i+1) =="IA")||(s.substr(i,i+1) =="AH")))
{
flag=1;
break;
}
else if(s[i]=='A') s.erase(s.begin()+i);
}
}
if(flag) cout<<"NO"<<endl;
else if(s=="KIHBR") cout<<"YES"<<endl;
else cout<<"NO"<<endl;

return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int H,N;
    scanf("%d %d", &H,&N);
    int A[N];
int i,sum=0;
for(i=0; i<N; i++)
{
    scanf("%d", &A[i]);
    sum=sum+A[i];
}
if(H<=sum)
    printf("Yes");
else
    printf("No");
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if (s.substr(0, 4) == "YAKI") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
placelist=[]
numlist=[]
ans=-1
for _ in range(m):
    place,num=map(int,input().split())
    placelist.append(place)
    numlist.append(num)
if n>1:
    for i in range(10**(n-1),10**n):
        cnt=0
        tmp=str(i)
        for j in range(m):
            if tmp[placelist[j]-1]==str(numlist[j]):
                cnt+=1
        if cnt==m:
            ans=tmp
            break
if n==1:
    for i in range(0,10):
        cnt=0
        tmp=str(i)
        for j in range(m):
            if tmp[placelist[j]-1]==str(numlist[j]):
                cnt+=1
        if cnt==m:
            ans=tmp
            break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
const int N = 3e3 + 5;
const long long INF = 1e18;
const int mod = 1e9 + 7;//786433;//998244353;
const double Pi = acos(-1);
const int p = 510200;
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n, m;
int Fact[200005];
map <int, int> M;

int BinPow(int x, int n)
{
	if(n == 0)
	{
		return 1;
	}
	int temp = BinPow(x, n >> 1);
	if(n & 1)
	{
		return 1ll * temp * temp % mod * x % mod;
	}
	else
	{
		return 1ll * temp * temp % mod;
	}
}

int C(int k, int n)
{
	return 1ll * Fact[n] * BinPow(Fact[k], mod - 2) % mod * BinPow(Fact[n - k], mod - 2) % mod;
}

signed main()
{
//	Fastio();
	cin >> n >> m;
	Fact[0] = 1;
	for(int i = 1; i <= 2e5; i++)
	{	
		Fact[i] = 1ll * Fact[i - 1] * i % mod;
	}
	for(int i = 2; i <= sqrt(m); i++)
	{
		while(m % i == 0)
		{
			M[i]++;
			m /= i;
		}
	}
	if(m > 1)
	{
		M[m]++;
	}
	int ans = 1;
	for(auto x : M)
	{
		ans = 1ll * ans * C(n - 1, x.se + n - 1) % mod;
	}
	cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

u64 binpow(u64 n, u64 x, u64 mod)
{
  u64 tgt = 1;
  u64 dig = n;
  while (x > 0) {
    if (x%2) {
      tgt = (tgt * dig) % mod;
    }
    dig = (dig * dig) % mod;
    x /= 2;
  }
  return tgt;
}

class Comb
{
public:
  u64 mod;
  vector< u64 > fact;
  vector< u64 > factf;
  void init(u64 size, u64 imod) {
    mod = imod;
    fact.resize(size);
    factf.resize(size);
    fact[0] = 1;
    factf[0] = 1;
    for (u64 i = 1; i <= size; ++i) {
      fact[i] = fact[i-1]*i%mod;
      factf[i] = binpow(fact[i], mod-2, mod);
    }
  }
  u64 comb(u64 n, u64 k) {
    if (n<k) return 0;
    if (k==0 || n==k) return 1;
    return ((fact[n] * factf[k]) % mod * factf[n-k]) % mod;
  }
};

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  Comb comb;
  comb.init(2e5, 1e9+7);
  int n;
  cin >> n;
  l64 a[n+1];
  for (u64 i = 1; i <= n; ++i) {
    a[i] = -1;
  }
  u64 a1, a2;
  for (u64 i = 0; i <= n; ++i) {
    u64 ai;
    cin >> ai;
    if (a[ai] >= 0) {
      a1 = a[ai];
      a2 = i;
      break;
    }
    a[ai] = i;
  }
  for (u64 i = 1; i <= n+1; ++i) {
    u64 up = comb.comb(n+1, i);
    u64 dn = comb.comb(n-(a2-a1), i-1);
    if (up>dn) {
      cout << up-dn << endl;
    }
    else {
      cout << up+1000000007-dn << endl;
    }
  }
  return 0;
}


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

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    int l = 0, r = 0;
    int zeros = 0;
    int ans = -1;
    while (r < s.size() && s[r] == '1') r++;
    while (r < s.size()) {
        while (r < s.size() && s[r] == '0') r++;
        zeros++;        
        while (r < s.size() && s[r] == '1') r++;
        if (r == s.size()) {
            break;
        }
        if (zeros == k) {
            ans = max(ans, r - l);
            while (l < s.size() && s[l] == '1') l++;
            while (l < s.size() && s[l] == '0') l++;
            zeros--;
        }
    }
    cout << max(ans, r - l) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    int n,p;
    cin >> n >> p;
    long long a=0,b=0;
    long long ans;
    for(long long i=0;i<n;i++){
        long long x;
        cin >> x;
        if(x%2==0){
            a++;
        }else{
            b++;
        }
    }
    long long bsum;
    if(b==0){
        bsum = 0;
    }else{
        bsum = pow(2,b);
    }
    ans=bsum/2*pow(2,a);
    long long sum = pow(2,a)*pow(2,b);
    if(p==0){
        cout << sum - ans << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int n = Integer.parseInt(tmpArray[0]);
		double totalW = Integer.parseInt(tmpArray[1]);
		
		Item[] items = new Item[n];
		for(int i = 0; i < n; i++){
			tmpArray = br.readLine().split(" ");
			
			int value = Integer.parseInt(tmpArray[0]);
			int weight = Integer.parseInt(tmpArray[1]);
			
			items[i] = new Item(value, weight);
		}
		
		Arrays.sort(items);
		
		double result = 0;
		for(int i = 0; i < n && totalW > 0 ; i++){
		//	System.out.println(items[i].valuePerWeight);
			
			double w1 = Math.min(items[i].weight, totalW);
			result += w1 * items[i].valuePerWeight;
			
			totalW -= w1;
		}
		
		System.out.printf("%.8f\n", result);
	}

}

class Item implements Comparable<Item>{
	int value;
	int weight;
	double valuePerWeight;
	
	Item(int v, int w){
		value = v;
		weight = w;
		valuePerWeight = (double)value/weight;
	}

	@Override
	public int compareTo(Item item1) {
		// TODO Auto-generated method stub
		if(this.valuePerWeight < item1.valuePerWeight){
			return 1;
		}
		else if(this.valuePerWeight > item1.valuePerWeight){
			return -1;
		}
		else {
			return 0;
		}
	}
	
	
	
}


Measured memory_bytes: 67040
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
//#define __int64 long long
#define P pair<int,int>
string s;
int n;
string t[4];


string che(string a){
	string x;
	x.resize(n);
	x[0]=a[0];
	x[1]=a[1];
	for(int i=1;i<n-1;i++){
		if(s[i]=='o'){
			if((x[i-1]=='S'&&x[i]=='S')||(x[i-1]=='W'&&x[i]=='W'))x[i+1]='S';
			else x[i+1]='W';
		}
		else{//x
			if((x[i-1]=='S'&&x[i]=='W')||(x[i-1]=='W'&&x[i]=='S'))x[i+1]='S';
			else x[i+1]='W';
		}
	}
	//cout<<x<<endl;
	bool ok=1;
	int l,r;
	rep(i,n){
		l=i-1;
		r=i+1;
		if(r>=n)r=0;
		if(l<0)l=n-1;
		if(s[i]=='o'){
			if((x[i]=='S'&&x[l]!=x[r])||(x[i]=='W'&&x[l]==x[r]))ok=0;
		
		}
		else{
				if((x[i]=='S'&&x[l]==x[r])||(x[i]=='W'&&x[l]!=x[r]))ok=0;
		}
	}
	if(ok)return x;
	return "#";
}
int main(){
	cin>>n>>s;

	t[0]="SS";
	t[1]="SW";
	t[2]="WS";
	t[3]="WW";

	rep(i,4){
		string a=che(t[i]);
		if(a!="#"){cout<<a<<endl;return 0;}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ln(a) cout << (a) << endl
#define debug(a, n) rep(hoge, n) printf("%lld%c", a[hoge], hoge == (n) - 1? '\n' : ' ');
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007

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

int inv(int x) {
    int n = MOD - 2;
    ll res = 1;
    ll tmp = x;
    while(n) {
        if(n & 1) {
            res *= tmp;
            res %= MOD;
        }
        tmp *= tmp;
        tmp %= MOD;
        n >>= 1;
    }
    return (int)res;
}

ll* fact;

int comb(int a, int b) {
    ll res = fact[a];
    res *= inv(fact[b]);
    res %= MOD;
    res *= inv(fact[a - b]);
    res %= MOD;
    return (int)res;
}

signed main() {
    int n, k;
    cin >> n >> k;
    int* a = new int[n];
    rep(i, n) cin >> a[i];
    if(k == 1) {
        ln(0);
        return 0;
    }

    fact = new ll[n + 1];
    fact[0] = 1;
    rep(i, n) fact[i + 1] = fact[i] * (i + 1) % MOD;
    sort(a, a + n);
    ll* sum = new ll[n + 1];
    sum[0] = 0;
    rep(i, n) sum[i + 1] = sum[i] + a[i] % MOD;
    ll ans = 0;
    for(int i = k - 2; i <= n - 2; i++) {
        ll tmp = 0;
        tmp += sum[n];
        tmp -= sum[i + 1];
        tmp %= MOD;
        if(tmp < 0) tmp += MOD;
        tmp -= sum[n - i - 1];
        tmp %= MOD;
        if(tmp < 0) tmp += MOD;
        tmp *= comb(i, k - 2);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }

    ln(ans);
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)
#define ll long long
const ll mod=1e9+7;


int main(){
  double n,k;
  cin>>n>>k;

  vector<int> cnt(n+1);
  for(int i=1;i<=n;i++){
    int x=0;int j=i;
    while(j<k){
      x++;j*=2;
    }
    cnt.at(i)=x;
  }
  //r(i,n+1)cout<<cnt.at(i)<<endl;

  double sum=0,p;
  for(int i=1;i<=n;i++){
    p=1;
    //cout<<p<<endl;
    for(int k=1;k<=cnt.at(i);k++){
      p=p*0.5;
    }
    sum+=p;
  }
  printf("%.12f\n",sum/n);
  //cout<<sum/n<<endl;
  return 0;
}


Measured memory_bytes: 640
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int inf=1e9;
const ll INF=1e18;
const double pi=3.1415926535897932384626433832;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int h,w,n,a[10005]={},now=1,c[105][105]={};
  cin >> h >> w >> n;
  for(int i=1; i<=n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if((i+1)%2) {
        if(a[now]) {
          c[i][j]=now;
          a[now]--;
          if(!a[now]) {
            now++;
          }
        }
      }
      else {
        if(a[now]) {
          c[i][w-1-j]=now;
          a[now]--;
          if(!a[now]) {
            now++;
          }
        }
      }
    }
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cout << c[i][j] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	int n, l;
	cin >> n >> l;
	int sum=0;
	for(int i=1; i<=n; i++)
		sum += l+i-1;
	int ans = sum-(l+1-1);
	for(int i=2; i<=n; i++){
		if(abs(sum-(sum-(l+i-1))) < abs(sum-ans))
			ans = sum-(l+i-1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int x, y;
	cin >> x >> y;
	int xx = -x;
	int yy = -y;
	int ans =  1 << 30;
	if (y >= x) ans = min(ans, y - x);
	if (y >= xx) ans = min(ans, y - xx + 1);
	if (yy >= xx) ans = min(ans, yy - xx + 2);
	if (yy >= x) ans = min(ans, yy - x + 1);
	cout << ans << endl;
	return 0;	
}

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


int main() {
    int N;
    string S;
    cin>>N>>S;
    rep(i,S.size()){
        if((char)(N+S[i])<='Z') S[i]=(char)(N+S[i]);
        else S[i]=(char)(N+S[i]-26);
    }
    cout<<S<<endl;
}

Measured memory_bytes: 256
#include<stdlib.h>
#include<iostream>
#include<cstdio>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<map>
#include<string.h>
#include<queue>
using namespace std;

int d[100000];
signed main() {
	int a, b; cin >> a >> b;
	for (int c = 0; c < b; c++) {
		int e, f; cin >> e >> f;
		e--; f--;
		d[e]++; d[f]++;
	}
	for (int g = 0; g < a; g++) {
		if (d[g] & 1) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}

Measured memory_bytes: 640