akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=(n);i<(x);++i)
#define SORT(x) sort(x.begin(),x.end())
using ll = long long;

int main() {
	int n, k; cin >> n >> k;
	vector<int> x(n); rep(i, 0, n) cin >> x[i];

	vector<ll> vec(n - k + 1);
	rep(i, 0, n - k + 1) vec[i] = x[i + k - 1] - x[i] + min(abs(x[i + k - 1]), abs(x[i]));
	SORT(vec);

	cout << vec[0] << endl;
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        int count = 0;
        String d;
        Boolean e = false;
        for (int i = 0; i < a; i++) {
            // スペース区切りの整数の入力
            int b = sc.nextInt();
            int c = sc.nextInt();

            if (b == c) {
                count += 1;
            } else {
                count = 0;
            }
            if (count == 3) {
                e = true;
            }
        }

        if (e) {
            d = "Yes";
        } else {
            d = "No";
        }

        // 出力
        System.out.println(d);
    }
}

Measured memory_bytes: 35904
using System;
using System.Text.RegularExpressions;

namespace _2019_2 {
    class Program {
        static void Main(string[] args) {
            var str = Console.ReadLine();
            //Console.WriteLine(str);

            if (Regex.IsMatch(str, "^.*?keyence$") || Regex.IsMatch(str, "^keyence.*?$"))
            {
                Console.WriteLine("YES");
                return;
            } else
            {
                if (Regex.IsMatch(str, "^k.*?eyence$"))
                {
                    Console.WriteLine("YES");
                    return;
                }
                if (Regex.IsMatch(str, "^ke.*?yence$"))
                {
                    Console.WriteLine("YES");
                    return;
                }
                if (Regex.IsMatch(str, "^key.*?ence$"))
                {
                    Console.WriteLine("YES");
                    return;
                }
                if (Regex.IsMatch(str, "^keye.*?nce$"))
                {
                    Console.WriteLine("YES");
                    return;
                }
                if (Regex.IsMatch(str, "^keyen.*?ce$"))
                {
                    Console.WriteLine("YES");
                    return;
                }
                if (Regex.IsMatch(str, "^keyenc.*?e$"))
                {
                    Console.WriteLine("YES");
                    return;
                }
            }
            Console.WriteLine("NO");
        }


    }
}



Measured memory_bytes: 16188
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 5005
#define M 10005
#define ll long long
#define mod 1000000007
void Read(int &p)
{
	p = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
}
int n, tar[M], nex[M], fir[N], cnt;
int siz[N];
int dp[N][N], f[N], g[N];
void Add(int a, int b)
{
	++cnt;
	tar[cnt] = b;
	nex[cnt] = fir[a];
	fir[a] = cnt;
}
void Dfs(int r, int fa)
{
	siz[r] = 1;
	dp[r][1] = 1;
	for (int i = fir[r]; i; i = nex[i])
	{
		int v = tar[i];
		if (v != fa)
		{
			Dfs(v, r);
		    for (int j = 0; j <= siz[r]; j++)
			{
				g[j] = dp[r][j];
				dp[r][j] = 0;
			}
			for (int j = 0; j <= siz[r]; j++)
				for (int k = 0; k <= siz[v]; k++)
					dp[r][j + k] = (dp[r][j + k] + (ll)g[j] * dp[v][k]) % mod;
			siz[r] += siz[v];
		}
	}
	for (int i = 0; i <= siz[r]; i++)
		dp[r][0] = (dp[r][0] - (ll)dp[r][i] * f[i]) % mod;
}
int main()
{
	Read(n);
	for (int i = 1; i < n; i++)
	{
		int u, v;
		Read(u), Read(v);
		Add(u, v), Add(v, u);
	}
	f[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		if (i & 1)continue;
		f[i] = (ll)f[i - 2] * (i - 1) % mod;
	}
	Dfs(1, 0);
	int ans = -dp[1][0];
	if (ans < 0)
		ans += mod;
	printf("%d\n", ans);
}
///


Measured memory_bytes: 58212
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	string s;cin>>s;
	int n=s.size();
	if(s[0]=='0'||s[n-1]=='1'){
		puts("-1");return 0;
	}
	s="0"+s;
	for(int i=1;i<=n;i++){
		if(s[i]=='0'&&s[n-i]=='1'){
			puts("-1");return 0;
		}
		if(s[i]=='1'&&s[n-i]=='0'){
			puts("-1");return 0;
		}
	}
	vector<int>child{0};
	vector<P>ans;
	int cnt=1;
	for(int i=2;i<=n;i++){
		if(s[i]=='1'){
			for(auto i:child){
				ans.push_back(P(i,cnt));
			}
			child.clear();
			child.push_back(cnt++);
		}
		else{
			child.push_back(cnt++);
		}
	}
	for(auto i:child){
		if(i==n-1)continue;
		ans.push_back(P(n-1,i));
	}
	for(auto p:ans){
		cout<<p.first+1<<' '<<p.second+1<<endl;
	}
}

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

int main() {
    int64_t n, a, b;
    cin >> n >> a >> b;

    int64_t ab = a+b;

    cout << (n/ab)*a + ((n%ab>a) ? a : n%ab);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define FOR(i,s,n) for(int i=s;i<n;i++)
#define ROF(i,n,e) for(int i=n;i>e;i--)
#define mod 1e9+7
#define MAX 1000005    //10^5+5
#define MAXQ 200005    //2*10^5+5
#define pi pair<int,int>
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define ll long long
#define f first
#define s second
#define sz(container) container.size()
typedef pair<int,int> pii;
typedef pair<int,pii> node;

inline ll modExp(ll a,ll b,ll m=mod){
	ll res=1;
	a%=m;
	while(b>=1){
		if(b%2!=0){
			res=(res%m*a%m)%m;
		}
		a=(a%m*a%m)%m;
		b=b/2;
	}
	return res;
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  string a,b;
  cin>>a>>b;
  cout<<b<<a<<"\n";
    return 0;    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7



int main() {

	int N, A, B, C, D, X, H, W;
	char S[1000], T[1000];
	scanf("%d", &N);


	bool can = false;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == N) {
				printf("Yes");
				i = 100;
				can = true;
				break;
			}
		}
	}
	if (!can)printf("No");
	
}



Measured memory_bytes: 128
// https://atcoder.jp/contests/abc088/tasks/abc088_b
#include <bits/stdc++.h>
using namespace std;

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

  rep(i, N) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());

  int ans = 0;
  rep(i, N) {
    if (i % 2 == 0)
      ans += a[i];
    else
      ans -= a[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int q = Integer.parseInt(br.readLine());

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			String[] sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]);
			int b = Integer.parseInt(sa[1]);

			long x = Math.min(a, b);
			long y = Math.max(a, b);
			if (x == y) {
				pw.println((x - 1) * 2);
			} else if (x + 1 == y) {
				pw.println(x - 2 + y - 1);
			} else {
				long xy = x * y;
				long z = (long) Math.sqrt(xy);
				while (z * z >= xy) {
					z--;
				}
				long zx = z;
				long zy = z;
				if (zx * (zy + 1) < xy) {
					zy++;
				}
				pw.println(zx - 1 + zy - 1);
			}
		}
		pw.flush();
		br.close();
	}
}


Measured memory_bytes: 19284
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
//typedef long long int LL;
//typedef __int64 LL;

char word[2000];

int main()
{
	scanf("%s", word);
	int N = 0, S = 0, E = 0, W = 0;
	int len = strlen(word);
	for (int i = 0; i < len; i++) {
		if (word[i] == 'N') N = 1;
		if (word[i] == 'S') S = 1;
		if (word[i] == 'E') E = 1;
		if (word[i] == 'W') W = 1;
	}

	if ((N ^ S) || (E ^ W)) printf("No\n");
	else printf("Yes\n");

	return 0;
}


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

int main() {
	int N, Q; cin >> N >> Q;
	string S; cin >> S;
	vector<int> l(Q+1, 0), r(Q+1, 0);
	for(int i = 1; i <= Q; i++) cin >> l[i] >> r[i];

	vector<int> cumlativeS(N+1, 0);

	for(int i = 2; i <= N; i++) {
		if(S[i-2] == 'A' && S[i-1] == 'C') {
			cumlativeS[i] = cumlativeS[i-1] + 1;
		} else {
			cumlativeS[i] = cumlativeS[i-1];
		}
	}

/*
	for(int i = 0; i < S.length()+1; i++) {
		cout << cumlativeS[i] << " ";
	}
	cout << endl;
*/

	for(int i =1; i <= Q; i++) {
		cout << cumlativeS[r[i]] - cumlativeS[l[i]] << endl;
	}
}


Measured memory_bytes: 2240
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

vector<Int> A,B;
int main(void) {
    int N;
    
    cin>>N;
    for(int i = 0;i <= N;i++) {
        Int a;
        cin>>a;
        A.push_back(a);
    }

    for(int i = 0;i < N;i++) {
        Int b;
        cin>>b;
        B.push_back(b);
    }

    Int ans = 0;
    for(int i = 0;i < N;i++) {
        Int beat;
        beat = min(A[i],B[i]);
        ans += beat;
        
        B[i] -= beat;

        beat = min(A[i+1],B[i]);
        ans += beat;
        A[i+1] -= beat;
    }

    cout<<ans<<endl;

    return 0;
}





Measured memory_bytes: 2676
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

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

int main(void){
  string line;
  while(cin>>line){
    int ans[2]={0};
    REP(i,line.size()-3+1){
      if(line.substr(i,3)=="JOI")ans[0]++;
      if(line.substr(i,3)=="IOI")ans[1]++;
    }
    REP(i,2){
      cout<<ans[i]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn main(){
    let n: usize = read_as_vec()[0];

    let mut ans: usize = 0;
    let (a, b) = (0, 0);
    let (mut both, mut beg, mut end) = (0, 0, 0);
    for _ in 0..n{
        let s = read_as_string();
        ans += s.matches("AB").count();
        let prefix = s.starts_with("B");
        let suffix = s.ends_with("A");
        if prefix && suffix{
            both += 1;
        }else if prefix{
            beg += 1;
        }else if suffix{
            end += 1;
        }
    }

    if both == 0{
        ans += cmp::min(beg, end);
    }else{
        ans += both-1;
        both = 0;
        if beg > 0{
            ans += 1;
            beg -= 1;
        }

        if end > 0{
            ans += 1;
            end -= 1;
        }

        ans += cmp::min(beg, end);
    }

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(int, n, h, w);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    Cin(int, a, b);
    if (h <= a && w <= b) ans++;
  }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
#define M 2000
#define L 20

int main(){

  int i,j,n;
  
  int array[L], drop[M + 1], in;
  
  memset(drop,0,sizeof(drop));
 
  scanf("%d" ,&n);
  
  for(i = 0 ; i < n ; i++)
    {
      scanf("%d" ,array + i);
    }
 
  drop[0] = 1;

  for(i = 0;i < n;i ++)
    {
      for(j = M;j >= 0;j --)
	{
	  if(drop[j] && j + array[i] <= M)
	    {
	      drop[j + array[i]] = 1;
	    }
	}
    }
  
  scanf("%d" ,&n);
  
  for(i = 0;i < n;i ++)
    {
      scanf("%d" ,&in);
      if(drop[in])
	{
	  puts("yes");
	}
      else{
	puts("no");
      }
    }
  
  return 0;
}

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

int main() {
  int A,B,C,D; cin >>A >>B >>C >>D;
  if (A+B>C+D) cout <<"Left" <<endl;
  else if (A+B<C+D) cout <<"Right" <<endl;
  else cout <<"Balanced" <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int MiniMumCost(int n,int k,vector<int> height)
{
    vector<int> dp(n+1);

    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        dp[i]=INT_MAX;
        for(int j=i-1;j>0 && i-j<=k;j--)
        {
            dp[i]=min(dp[i],abs(height[i]-height[j])+dp[j]);
        }
    }
    return dp[n];
}
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> height(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>height[i];
    }
    cout<<MiniMumCost(n,k,height);
}


Measured memory_bytes: 4308
import java.io.PrintWriter
import java.util.PriorityQueue
import java.util.Comparator

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (n, m) = readIntegerList()
    val bArrayList =  Array(100001) { mutableListOf<Long>() }
    repeat(n) {
        val (a, b) = readLongList()
        bArrayList[a.toInt()].add(b)
    }

    val queue = PriorityQueue<Long> { a, b -> b.compareTo(a) }
    var ans = 0L
    for (i in 1..m) {
        queue.addAll(bArrayList[i])
        if (queue.isNotEmpty()) {
            ans += queue.remove()
        }
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 71168
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

int main() {
	int n;
	cin >> n;
	if (n < 1200) {
		cout << "ABC" << endl;
	}
	else if (n < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}
}


Measured memory_bytes: 256
require 'complex'

N, D = gets.chomp.split(' ').map(&:to_i)
Vertexes = N.times.map{ gets.chomp.split(' ').map(&:to_i)[0..D] }

distances = Vertexes.combination(2).map do |a, b|
  norm = a.zip(b).reduce(0) { |d, ab| d + (ab[0]-ab[1])**2 }
  distance = Math.sqrt(norm)
end

puts distances.reduce(0) { |count, distance|
  count + (distance.to_i == distance ? 1 : 0)
}


Measured memory_bytes: 1788
import java.util.*

fun isPrime(x: Int): Boolean {
    if (x == 2) {
        return true
    }
    if (x < 2 || x % 2 == 0) {
        return false
    }
    for (i in 3 .. Math.sqrt(x.toDouble()).toInt() step 2) {
        if (x % i == 0) {
            return false
        }
    }
    return true
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    var cnt = 0
    (1..n).forEach {
        if (isPrime(scanner.nextInt())) {
            cnt++
        }
    }
    println(cnt)
}


Measured memory_bytes: 41876
#!/usr/bin/env python3
from itertools import count, takewhile


def prime():
    prime = []

    def _isPrime(n):
        for d in takewhile(lambda x: x * x <= n, prime):
            if n % d == 0:
                return False
        return True
    for i in count(2):
        if _isPrime(i):
            prime.append(i)
            yield(i)


def is_prime(primes, i):
    for p in takewhile(lambda x: x * x <= i, sorted(primes)):
        if i % p == 0:
            return False
    return True

primes = list(takewhile(lambda x: x < 10000, prime()))

n = int(input())
c = 0
for _ in range(n):
    i = int(input())
    if is_prime(primes, i):
        c += 1
print(c)

Measured memory_bytes: 6732
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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


int main() {

	int n;
	int ans=0,tmp=1,tmp2,p=100;
	cin >> n;
	rep(i, n + 1) {
		if (i > 0 && i < 10)ans++;
		if (i > 99 && i < 1000)ans++;
		if (i > 9999 && i < 100000)ans++;
		
	}
	cout << ans;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

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

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 200;
const int INF = 1e9;

int n, k;
vector <pii> ans;
bool no[N][N];

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> k;
	if(k > (n - 1) * (n - 2) / 2) {
		cout << -1;
		return 0;
	}	
	int u = 1, v = 2;
	for(int i = 1; i <= k; ++i) {
		no[u][v] = 1;
		++v;
		if(v == n) {
			++u;
			v = u + 1;
		}
	}
	for(int i = 1; i <= n; ++i) {
		for(int j = i + 1; j <= n; ++j) {
			if(no[i][j]) continue;
			ans.pb(mkp(i, j));
		}
	}
	cout << sz(ans) <<'\n';
	for(pii to : ans)
		cout << to.F <<' '<< to.S <<'\n';
	return 0;
}

Measured memory_bytes: 384
a={1,3,5,7,8,10,12}
b={4,6,9,11}
c={2}
d,e=map(int,input().split())
if (d in a and e in a) or (d in b and e in b) or (d in c and e in c):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
// import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        // Scanner sc = new Scanner(System.in);
        // int N = sc.nextInt();
        // int D = sc.nextInt();

        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int D = Integer.parseInt(st.nextToken());

        int result = 0;

        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(br.readLine());
            int X = Integer.parseInt(st.nextToken());
            int Y = Integer.parseInt(st.nextToken());

            double calcResult = Math.sqrt(Math.pow(X, 2) + Math.pow(Y, 2));
            if (calcResult <= D) {
                result += 1;
            }
        }
        
        pw.println(result);
        br.close();
        pw.close();
    }
}

Measured memory_bytes: 54140
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define pb         push_back

const int inf = (1 << 21);

class state{
public:
  int now,cost;
  bool operator<(const state & a)const{
    return cost > a.cost;
  }
};

int gr[8][8];//for solve
int dp[(1<<8)][8];//home+k+1
int solve(int n,int *cake,int d){
  int home=n-2,dest=n-1;
  rep(i,n){
    rep(j,(1<<n))dp[j][i]=inf;
  }
  
  dp[(1<<home)][home]=0;
  rep(i,(1<<n)){
    rep(j,n){
      if (dp[i][j] == inf)continue;
      if ((i&(1<<j)) == 0)continue;
      rep(k,n){
	if ((i&(1<<k)) != 0)continue;
	int next=i|(1<<k);
	dp[next][k]=min(dp[next][k],dp[i][j]+gr[j][k]);
      }
    }
  }

  int ans=inf;
  rep(i,(1<<n)){
    if ((i&(1<<home)) ==0 || (i&(1<<dest))==0)continue;
    int tmp=0;
    rep(j,n-2){
      if ((1<<j)&i)tmp+=cake[j];
  }
    if (dp[i][dest] == inf)continue;
    //    cout << i <<" " << dest << " " << dp[i][dest]*d << " " << tmp << endl;
    ans=min(ans,dp[i][dest]*d-tmp);
  }
  return ans;
}


vector<state> edge[200];
int cost[200];
void dijkstra(int n,int s,int cnum){
  rep(i,200)cost[i]=inf;
  priority_queue<state> Q;
  Q.push((state){s,0});
  while(!Q.empty()){
    state now = Q.top();Q.pop();
    if (cost[now.now] != inf)continue;
    cost[now.now]=now.cost;
    if (now.now < cnum-2 && now.now != s)continue;
    rep(i,edge[now.now].size()){
      int next=edge[now.now][i].now;
      int nec=now.cost+edge[now.now][i].cost;
      Q.push((state){next,nec});
    }
  }
  
  rep(i,n){
    //cout <<s <<" to " << i <<" takes " <<  cost[i] << endl;
  }
  
  //make graph
  rep(i,cnum){
    gr[s][i]=cost[i];
  }
}


int getinfo(int m,int home,int dest,int cnum){
  char in;
  int num;
  cin>>in;
  if (in == 'H')return home;
  if (in == 'D')return dest;
  if (in == 'C'){
    cin>>num;
    return num-1;
  }
  if (in == 'L'){
    cin>>num;
    return num-1 + cnum;
  }
  return -1;
}


main(){
  int m,n,syouhi,d;
  while(cin>>m>>n>>syouhi>>d && m){
    int cnum=m+2;
    int cake[m];
    rep(i,200)edge[i].clear();
    int home=m,dest=m+1;
    
    rep(i,m)cin>>cake[i];
    rep(i,d){
      int a,b,c;
      a=getinfo(m,home,dest,cnum);
      b=getinfo(m,home,dest,cnum);
      cin>>c;
      edge[a].pb((state){b,c});
      edge[b].pb((state){a,c});
    }

    rep(i,cnum+n){
      rep(j,edge[i].size()){
	//	cout << i <<" " << edge[i][j].now <<" " << edge[i][j].cost << endl;
      }
    }
    
    rep(i,cnum){
      dijkstra(cnum+n,i,cnum);
    }
    cout << solve(cnum,cake,syouhi) << endl;
  }
  return false;
}

Measured memory_bytes: 944
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int x = 1;
    int ans = 0;
    for (int i = 0;x < b;i++) {
      x += a - 1;
      ans ++;
    }
    System.out.println(ans);
  }
}





Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  int a, b, c;
  cin >> a >> b >> c;
  int d = a;
  int e = c;
  c = b;
  b = d;
  a = e;
  cout << a << " " << b << " " << c << endl;
}

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

int main()
{
  int X, A, B;
  cin >> X >> A >> B;
  
  if((A - B) >= 0)
    cout << "delicious" << endl;
  else if(abs(A - B) <= X)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>

int N, K, g, mx;

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 1, x; i <= N; ++i)
		scanf("%d", &x),
		g = std::__gcd(g, x),
		mx = std::max(mx, x);
	puts(K <= mx && K % g == 0 ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}

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

static const int MAX=100;
static const int INFTY=numeric_limits<int>::max();

typedef enum {
    WHITE,
    GRAY,
    BLACK,
}Color;

int n,M[MAX][MAX];

void Dijkstra(){
    int minv;
    int d[MAX];
    Color color[MAX];

    for(int i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }
    
    d[0]=0;
    color[0]=GRAY;
    while(true){
        minv=INFTY;
        int u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1) break;
        color[u]=BLACK;
        for(int v=0;v<n;v++){
            if(color[v]!=BLACK&&M[u][v]!=INFTY){
                if(d[v]>d[u]+M[u][v]){
                    d[v]=d[u]+M[u][v];
                    color[v]=GRAY;
                }
            }
        }
    }

    for(int i=0;i<n;i++){
        cout<<i<<' '<<(d[i]==INFTY ? -1 : d[i])<<endl;
    }
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            M[i][j]=INFTY;
        }
    }

    int k,c,u,v;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            M[u][v]=c;
        }
    }

    Dijkstra();

    return 0;
}


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

string S;
int N;
vector<int> pxor, dp;
int chk[1<<26];

int main() {
    cin >> S;
    N = S.size();

    pxor.resize(N);
    for(int i = N - 1; i >= 0; i--) {
        pxor[i] = (1<<(S[i] - 'a'));
        if(i != N - 1) pxor[i] ^= pxor[i + 1];
    }

    memset(chk, -1, sizeof(chk));
    dp = vector<int>(N + 1, 1e9);

    chk[0] = N;
    dp[N] = 0;
    for(int i = N - 1; i >= 0; i--) {
        if(chk[ pxor[i] ] != -1) dp[i] = min(dp[i], (i == 0) + dp[ chk[ pxor[i] ] ]);
        for(int j = 0; j < 26; j++) {
            if(chk[ pxor[i] ^ (1<<j) ] != -1) dp[i] = min(dp[i], 1 + dp[ chk[ pxor[i] ^ (1<<j) ] ]);
        }
        chk[ pxor[i] ] = i;
    }

    printf("%d", dp[0]);
}


Measured memory_bytes: 264324
import sys
from functools import lru_cache
s = int(input())
sys.setrecursionlimit(10000000)


@lru_cache(maxsize=10000000)
def f(n):
    mod = 10**9 + 7
    if n == 3:
        return 1
    if n == 0:
        return 1
    if 0 < n < 3:
        return 0
    ret = 0
    for u in range(3, n+1):
        ret += f(n - u)
        ret %= mod
    return ret


print(f(s))


Measured memory_bytes: 10160
n, x, y = map(int,input().split())
x -= 1
y -= 1

distance_l = [0]*(n-1)

for i in range(n):
    for j in range(i+1,n):
        distance = min(abs(i-j),abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x))
        distance_l[distance-1] += 1

for val in distance_l:
    print(val)


Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>
#include <functional>

using namespace std;

int main() {

	int N;
	cin >> N;

	vector<int> vNum(N, 0);
	for (int i = 0; i < vNum.size(); i++)
	{
		cin >> vNum[i];
	}
	sort(vNum.begin(), vNum.end());

	int counter = 0;
	for (int i = 0; i < vNum.size(); i++)
	{
		for (int j = 0; j < i; j++)
		{
			if (i == j)
			{
				continue;
			}

			auto it = lower_bound(vNum.begin(), vNum.end(), vNum[i] + vNum[j]);
			int start = i + 1;
			int end = it - vNum.begin();
			counter += end - start;
		}
	}

	cout << counter;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  ll a,b,n;
  cin >> a >> b >> n;
  ll x = min(b-1,n);
  cout << a*x/b-a*(x/b) << endl;
}


Measured memory_bytes: 3588
#include<iostream>
using namespace std;
int main()
{
  int a,b,i;
  cin >> a >> b;
  if(b==1){cout << 0 << endl;}else{
  --a;
  int c=1;
  bool fin=0;
  for(i=0;fin==0;++i){
    c+=a;
    if(c>=b){
      fin=1;
    }
  }
  
  cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def build_combinations_counter(N=10**5, p=10**9+7):
    fact = [1, 1]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # mod p におけるnの逆元 n^(-1)
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    
    def cmb(n, r, p, fact, factinv):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return fact[n] * factinv[r] * factinv[n-r] % p
    
    import functools
    return functools.partial(cmb, p=p, fact=fact, factinv=factinv)

def resolve():
    N, K = list(map(int, input().split()))
    calc_comb = build_combinations_counter()

    for i in range(1, K+1):
        divs = calc_comb(K-1, i-1)
        reds = calc_comb(i+(N-K-(i-1)), (N-K-(i-1)))
        print((divs*reds)%(10**9+7))
    


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 92448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<int MOD_> struct modnum {
    static constexpr int MOD = MOD_;
    static_assert(MOD_ > 0, "MOD must be positive");

private:
    using ll = long long;
    int v;
    static int minv(int a, int m) {
        a %= m;
        assert(a);
        return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
    }

public:
    modnum() : v(0) {}
    modnum(ll v_) : v(int(v_ % MOD)) {
        if (v < 0)
            v += MOD;
    }
    explicit operator int() const { return v; }
    friend ostream& operator<<(ostream& out, const modnum& n) {
        return out << int(n);
    }
    friend istream& operator>>(istream& in, modnum& n) {
        ll v_;
        in >> v_;
        n = modnum(v_);
        return in;
    }

    friend bool operator==(const modnum& a, const modnum& b) { return a.v == b.v; }
    friend bool operator!=(const modnum& a, const modnum& b) { return a.v != b.v; }

    modnum inv() const {
        modnum res;
        res.v = minv(v, MOD);
        return res;
    }
    friend modnum inv(const modnum& m) { return m.inv(); }
    modnum neg() const {
        modnum res;
        res.v = v ? MOD - v : 0;
        return res;
    }
    friend modnum neg(const modnum& m) { return m.neg(); }

    modnum operator-() const { return neg(); }
    modnum operator+() const { return modnum(*this); }
    modnum& operator++() {
        v++;
        if (v == MOD) v = 0;
        return *this;
    }
    modnum& operator--() {
        if (v == 0) v = MOD;
        v--;
        return *this;
    }
    modnum& operator+=(const modnum& o) {
        v += o.v;
        if (v >= MOD) v -= MOD;
        return *this;
    }
    modnum& operator-=(const modnum& o) {
        v -= o.v;
        if (v < 0) v += MOD;
        return *this;
    }
    modnum& operator*=(const modnum& o) { v = int(ll(v) * ll(o.v) % MOD); return *this; }
    modnum& operator/=(const modnum& o) { return *this *= o.inv(); }

    friend modnum operator++(modnum& a, int) { modnum r = a; ++a; return r; }
    friend modnum operator--(modnum& a, int) { modnum r = a; --a; return r; }
    friend modnum operator+(const modnum& a, const modnum& b) { return modnum(a) += b; }
    friend modnum operator-(const modnum& a, const modnum& b) { return modnum(a) -= b; }
    friend modnum operator*(const modnum& a, const modnum& b) { return modnum(a) *= b; }
    friend modnum operator/(const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

using mint = modnum<int(1e9) + 7>;
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    mint ans = 0, sum = 0;
    for (int i = 0; i < n; i++) {
        mint a;
        cin >> a;
        ans += sum * a;
        sum += a;
    }
    cout << ans;
    return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  rep(i, w + 2) {
    cout << "#";
  }
  cout << endl;
  rep(i, h) {
    string s;
    cin >> s;
    cout << "#" << s << "#" << endl;
  }
  rep(i, w + 2) {
    cout << "#";
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define inver(a) power(a, mod - 2)
using namespace std;
inline char nc() {
	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f;
}
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 9;
const int maxn = 1e6 + 5;
int n, m;
int an;
int tim;
int f[maxn];
int cnt[maxn * 3];
int fac[maxn * 3];
int inv[maxn * 3];
int vis[maxn * 3];
vector<pii> r[2];
ll power(ll x, ll y) {
	ll re = 1;
	while(y) {
		if(y & 1) re = re * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return re;
}
inline ll binom(int x, int y) {
	return (ll)fac[x] * inv[y] % mod * inv[x - y] % mod;
}
namespace us {
	int fa[maxn * 3];
	void init(int x) {
		fa[x] = x;
	}
	int find(int a) {
		return fa[a] == a ? a : fa[a] = find(fa[a]);
	}
	bool merge(int a, int b) {
		a = find(a);
		b = find(b);
		if(a == b) return 0;
		fa[a] = b; return 1;
	}
}
bool update(int &n, int &a, int x) {
	if(vis[x] == tim) return 0; else vis[x] = tim;
	x = us :: find(x);
	if(++cnt[x] > 3) return 1;
	if(cnt[x] == 3) --a, --n;
	if(cnt[x] == 2) ++a;
	return 0;
}
int cal() {
	++tim;
	for(unsigned int i = 0; i < r[0].size(); ++i) {
		us :: init(r[0][i].fi), cnt[r[0][i].fi] = 0;
		us :: init(r[0][i].se), cnt[r[0][i].se] = 0;
	} 
	for(unsigned int i = 0; i < r[0].size(); ++i) {
		us :: merge(r[0][i].fi, r[0][i].se);
	}
	int a = 0, N = n;
	for(unsigned int i = 0; i < r[0].size(); ++i){
		if(update(N, a, r[0][i].fi)) return 0;
		if(update(N, a, r[0][i].se)) return 0;
	} 
	return binom(N * 3 - a * 2, a) * fac[a] % mod * f[N - a] % mod * inv[N - a] % mod;
}
void dfs(int step, int f) {
	if(step == m) {
		an = (an + (ll)cal() * f) % mod;
		return;
	}
	dfs(step + 1, f);
	r[0].push_back(r[1][step]);
	dfs(step + 1, mod - f);
	r[0].pop_back();
}
void init(int n) {
	int N = n * 3;
	fac[0] = 1;
	for(int i = 1; i <= N; ++i) {
		fac[i] = (ll)fac[i - 1] * i % mod;
	}
	inv[N] = inver(fac[N]);
	for(int i = N; i >= 1; --i) {
		inv[i - 1] = (ll)inv[i] * i % mod;
	}
	f[0] = 1;
	for(int i = 1; i <= n; ++i) {
		f[i] = f[i - 1] * binom(i * 3, 3) % mod;
	}
}
int solve() {
	init(n);
	dfs(0, 1);
	return an;
}
int main() {
//	freopen("in", "r", stdin);
	read(n), read(m);
	for(int i = 1; i <= m; ++i) {
		int a, b, c; read(a), read(b), read(c);
		r[c].push_back(pii(a, b));
	}
	m = r[1].size();
	printf("%d\n", solve());
	return 0;
} 


Measured memory_bytes: 30840
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

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

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

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

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

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        switches: [[usize]; m],
        lights: [usize; m]
    }
    let checkf = |x: usize, v: usize| { x % 2 == v };
    let mut answer = 0;

    for i in 0..1<<n {
        let mut onlights = vec![0; m];
        for k in 0..n {
            if i & (1<<k) != 0 {
                for si in 0..m {
                    if switches[si].contains(&(k + 1)) {
                        onlights[si] += 1;
                    }
                }
            }
        }
        let flg = (0..m).map(|x| checkf(onlights[x], lights[x])).any(|x| !x);
        if !flg {
            answer += 1;
        }

    }

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


Measured memory_bytes: 4352
import math

n, p = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))

zero_count = 0
one_count = 0

for num in a:
    if num % 2 == 0:
        zero_count += 1
    else:
        one_count += 1

coef = 2 ** zero_count

ans = 0

for i in range(one_count + 1):
    if i % 2 != p:
        continue
        
    ans += math.factorial(one_count) // math.factorial(one_count - i) // math.factorial(i)
print(ans * coef)
        


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

vector<VI> r;
VL sum;

void rec(int s, int p){
	for(auto u: r[s]) if(u != p) {
		sum[u] += sum[s];
		rec(u, s);
	}
}

int main()
{

	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, q;
	
	cin >>n >>q;
	r.resize(n);
	rep(i, n-1){
		int a,b;
		cin >>a >>b;
		r[a-1].push_back(b-1);
		r[b-1].push_back(a-1);
	}
	sum.resize(n); 
	rep(i, q){
		int p,x;
		cin >>p >>x;
		sum[p-1] +=x;
	}
	rec(0, -1);
	for(auto x :sum) cout <<x <<" ";
	cout <<"\n";
	return 0;
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    rep(i,19){
        if(s[i] == ',') cout << ' ';
        else cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int x,a,b;
int main(){
	cin>>x>>a>>b;
//	if((x-a-(((x-a)/b)*b))!=0)
		cout<<(x-a-(((x-a)/b)*b))<<"\n";
//	else
//		return 0;
	return 0;
}

Measured memory_bytes: 384
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	int h,w;
	int cnt=0;

	int box[10][5];

	while(1){
		int pt=0;
		cin >> h;
		if(h == 0)break;

		for(int i=0;i<h;i++){
			for(int j=0;j<5;j++){
				cin >> box[i][j];
			}
		}

		for(int g=0;g<h;g++){
			
			for(int i=0;i<h;i++){
				for(int j=0;j<3;j++){
					cnt=0;
					for(int k=j+1;k<5;k++){
						if(box[i][j]!=box[i][k]){
							break;
						}
						cnt++;
					}
					if(cnt>=2){
						for(int k=j;k<=j+cnt;k++){
							pt+=box[i][k];
							box[i][k]=0;
						}
						break;
					}
				}
			}

			for(int i=0;i<5;i++){
				int cnt=0;
				VI v;
				for(int j=h-1;j>=0;j--){
					if(box[j][i]!=0){
						v.PB(box[j][i]);
						box[j][i]=0;
						cnt++;
					}
				}
				for(int j=1;j<=cnt;j++){
					box[h-j][i]=v[j-1];
				}
				v.clear();
			}
		}
/*
		for(int i=0;i<h;i++){
			for(int j=0;j<5;j++){
				cout << box[i][j];
			}
			cout << endl;
		}
*/
		cout << pt << endl;					
	}
	return 0;
}

Measured memory_bytes: 1216
#include <cstdio>
#include <map>
#include<iostream>
using namespace std;
map<string,int> mapi;
int num[200]={0},pos=0;
int main()
{
    int n;
    string str;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>str;
        if(mapi.count(str)==0)
        {
            mapi[str]=pos;
            num[pos++]++;
        }
        else
            num[mapi[str]]++;
    }
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>str;
        if(mapi.count(str)==0)
        {
            mapi[str]=pos;
            num[pos++]--;
        }
        else
            num[mapi[str]]--;
    }
    int maxi=-10000;
    for(int i=0;i<pos;i++)
        if(num[i]>maxi)
            maxi=num[i];
    if(maxi>0)
        cout<<maxi;
    else
        cout<<"0";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for(int i=0; i<S.size(); i++){
        if(S[i]!=T[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

bool isPrime(int n){
    int c = 0;
    for(int i = 1; i <= sqrt(n); i++){
        if(n % i == 0) c++;
        if(c > 1) return false;
    }
    return true;
}

int main(void){
    int n, x, c = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> x;
        if(isPrime(x) == 1) c++;
        //cout << isPrime(x) << endl;
    }
    cout << c << endl;
}



Measured memory_bytes: 3104
<?php
list($n, $m) = ints();
for ($i = 0; $i < $m; ++$i) {
    list($a, $b) = ints();
    if (isset($cnt[$a])) ++$cnt[$a];
    else $cnt[$a] = 1;
    if (isset($cnt[$b])) ++$cnt[$b];
    else $cnt[$b] = 1;
}
foreach ($cnt as $v) if ($v % 2) exit('NO');
echo 'YES';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 23320
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
	int n, m;
	while (cin >> n >> m, n)
	{
		int t[105]; int h[105];
		int sumt = 0, sumh = 0;
		REP(i, n)
		{
			cin >> t[i];
			sumt += t[i];
		}
		REP(i, m)
		{
			cin >> h[i];
			sumh += h[i];
		}
		REP(i, n)REP(j, m)
		{
			if (sumt - t[i] + h[j] == sumh - h[j] + t[i])
			{
				cout << t[i] << " " << h[j] << endl;
				goto end;
			}
		}
		cout << -1 << endl;
	end:;
	}
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n + 1];
		for(int i = 0; i < n + 1; i++) x[i] = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		Arrays.sort(x);
		for(int i = 0; i < n; i++) set.add(Math.abs(x[i] - x[i + 1]));
		int ans = 0;
		for(int key : set) {
			ans = gcd(ans, key);
		}
		System.out.println(ans);
	}


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

}




Measured memory_bytes: 48584
A, B, K = map(int, input().split())
if B - A < K + 1:
    c = list(range(A, B + 1))
else:
    a = list(range(A, A + K))
    b = list(range(B - K + 1, B + 1))
    c = sorted(list(set(a + b)))
for i in range(len(c)):
    print(c[i])


Measured memory_bytes: 3060