akhauriyash/Code-Regression huggingface dataset:
while true do
    w,h=gets.chomp.split(" ").map(&:to_i)
    break if w == 0 && h == 0

    tiles = []
    (0..(h-1)).each do |i|
        s = gets.chomp
        if j = s.index("@")
            @init_pos = [i, j]
        end
        tiles.push(s)
    end

    ret = 0
    memo = {}
    (0..(h-1)).each { |i| memo[i] = {} }
    targets = [@init_pos]
    memo[@init_pos[0]][@init_pos[1]] = true
    ret += 1
    while !targets.empty? do
        position = targets.shift
        row = position[0]
        col = position[1]
        
        if row != 0 && memo[row-1][col] == nil && tiles[row-1][col] == "."
            targets.push([row-1, col])
            memo[row-1][col] = true
            ret += 1
        end
        if row != h-1 && memo[row+1][col] == nil && tiles[row+1][col] == "."
            targets.push([row+1, col])
            memo[row+1][col] = true
            ret += 1
        end
        if col != 0 && memo[row][col-1] == nil && tiles[row][col-1] == "."
            targets.push([row, col-1])
            memo[row][col-1] = true
            ret += 1
        end
        if col != w-1 && memo[row][col+1] == nil && tiles[row][col+1] == "."
            targets.push([row, col+1])
            memo[row][col+1] = true
            ret += 1
        end
    end
    puts ret
end


Measured memory_bytes: 6884
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

int main()
{
  uint64_t N;
  cin >> N;
  uint64_t a[5];
  for (int ii=0; ii<5; ++ii)
    cin >> a[ii];

  uint64_t maxT = 0;
  for (auto& aa: a)
    maxT = max((N%aa==0 ? N/aa : N/aa+1), maxT);

  cout << 4+maxT << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String s = sc.next();
		
		// 計算
		String result = "bon";
		int i = n%10;
		if(s.length() <= n){
		    result = s;
		}else{
		    result = s.substring(0, n);
		    result += "...";
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 25400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define unordered_map umap

ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}
bool isPrime(int n){if(n<2){return false;}for(int i=2;i<sqrt(n)+1;i++){if(n%i==0) return false;}return true;}

int main(){
  int a[3]; CINA(a,3);
  sort(a,a+3,greater<int>() );
  cout << a[0]*10 + a[1] + a[2] <<"\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
char a;
int b[26]={1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0};
int main()
{
cin>>a;
if(b[int(a)-97]==1)cout<<"vowel"<<endl;
else cout<<"consonant"<<endl;
return 0;
}


Measured memory_bytes: 256
S = input()
n = len(S)
dp = [[0] * 2 for _ in range(n+1)]
 
dp[0][0] = 0
dp[0][1] = 1
for i in range(n):
    dp[i+1][0] = min(int(S[i]) + dp[i][0], 10 - int(S[i]) + dp[i][1])
    dp[i+1][1] = min(int(S[i]) + 1 + dp[i][0], 10 - int(S[i]) - 1 + dp[i][1])    
 
print(dp[n][0])


Measured memory_bytes: 138952
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int h,w,s,as;
int g[33][33];
int sum[33][33];
pint dp[33][33][33][33];
pint dfs(int lx,int ly,int rx,int ry){
    if(dp[ly][lx][ry][rx].first!=-1) return dp[ly][lx][ry][rx];
    pint ret={0,0};
    int ts=sum[ry+1][rx+1]-sum[ly][rx+1]-sum[ry+1][lx]+sum[ly][lx];
    if(as-ts>s) return ret;
    else ret={1,ts};
    for(int i=lx;i<rx;++i){
        pint l=dfs(lx,ly,i,ry),r=dfs(i+1,ly,rx,ry);
        ret=max(ret,{l.first+r.first,min(l.second,r.second)});
    }
    for(int i=ly;i<ry;++i){
        pint l=dfs(lx,ly,rx,i),r=dfs(lx,i+1,rx,ry);
        ret=max(ret,{l.first+r.first,min(l.second,r.second)});
    }
    return dp[ly][lx][ry][rx]=ret;
}
int main(){
    while(cin>>h>>w>>s,h){
        as=0;
        memset(sum,0,sizeof(sum));
        rep(i,h)rep(j,w) cin>>g[i][j],as+=g[i][j];
        rep(i,h)rep(j,w) sum[i+1][j+1]+=g[i][j]+sum[i][j+1]+sum[i+1][j]-sum[i][j];
        rep(i,h)rep(j,w)rep(k,h)rep(l,w) dp[i][j][k][l]={-1,0};
        pint ans=dfs(0,0,w-1,h-1);
        cout<<ans.first<<" "<<s-as+ans.second<<endl;
    }
    return 0;
}


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

int main(){
    int N;
    int K;
    cin >> N >> K;
    if(K > (N - 1) * (N - 2) / 2){
        cout << - 1 << endl;
        return 0;
    }

    int M = N * (N  - 1) /  2 - K;
    cout << M << endl;
    for(int i = 1; i < N; i++){
        for(int j = i + 1; j <= N; j++){
            if(K < 1 || j == N){
                cout << i << " " << j << endl;
                
            } else {
                K --;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
#define ll long long int
#define ld long double
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define sz size()
#define ff first
#define ss second
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define inf LLONG_MAX
#define f(i,a,b) for(i=a;i<b;i++)
const ll mod=1000000007; 
using namespace std;
ll lcm(ll n,ll m)
{
    return (n*m)/__gcd(n,m);
}
void solve()
{
    ll n,i,j,k;
    cin>>n>>k;
    ll a[n+1]={0};
    f(i,1,n+1) cin>>a[i];
    ll dp[n+1]={0};
    for(i=2;i<=n;i++)
    {
        dp[i]=inf;
        for(j=1;j<=k&&i-j>0;j++)
        {
            dp[i]=min(dp[i],dp[i-j]+abs(a[i-j]-a[i]));
        }
    }
    cout<<dp[n];
}
int32_t main()
{
    fast
    ll q=1;
    // cin>>q;
    while(q--)solve();
    return 0;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input();
    
    auto a = make_vector(N, 3, 0);
    range(i, 0, N) cin >> a[i];
    
    auto dp = make_vector(N, 3, 0);
    dp[0] = a[0];

    range(i, 1, N) {
        range(j, 0, 3) {
            range(k, 0, 3) {
                if (j == k) continue;
                chmax(dp[i][j], dp[i - 1][k] + a[i][j]);
            }
        }
    }

    cout << *whole(max_element, dp.back()) << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 11136
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func main() {
	bingo := make([][]int, 3)
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			bingo[i] = append(bingo[i], readInt())
		}
	}
	n := readInt()
	for k := 0; k < n; k++ {
		hit := readInt()
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				if bingo[i][j] == hit {
					bingo[i][j] = 0
				}
			}
		}
	}
	switch {
	case ((bingo[0][0] == 0) && (bingo[0][1] == 0) && (bingo[0][2] == 0)) ||
		((bingo[1][0] == 0) && (bingo[1][1] == 0) && (bingo[1][2] == 0)) ||
		((bingo[2][0] == 0) && (bingo[2][1] == 0) && (bingo[2][2] == 0)) ||
		((bingo[0][0] == 0) && (bingo[1][0] == 0) && (bingo[2][0] == 0)) ||
		((bingo[0][1] == 0) && (bingo[1][1] == 0) && (bingo[2][1] == 0)) ||
		((bingo[0][2] == 0) && (bingo[1][2] == 0) && (bingo[2][2] == 0)) ||
		((bingo[0][0] == 0) && (bingo[1][1] == 0) && (bingo[2][2] == 0)) ||
		((bingo[0][2] == 0) && (bingo[1][1] == 0) && (bingo[2][0] == 0)):
		fmt.Println("Yes")
	default:
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <cstdlib>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 100005
#define pb push_back
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;

int stringToInteger(string x){
    int gg=0;
    //stringstream geek(x);
    //geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}
ll modInverse(ll a, ll m)
{
    a = a%m;
    for (int x=1; x<m; x++)
       if ((a*x) % m == 1)
          return x;
}
ll maxDivide(ll a, ll b)
{
  while (a%b == 0)
   a = a/b;
  return a;
}
  set<ll>ans;
void primeFactors(ll n)
{

    while (n % 2 == 0)
    {
       ans.insert(2);
        n = n/2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            ans.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        ans.insert(n);
}
ll is(ll no)
{   if(no==1) return 0;
    set<ll>::iterator it;
for(it=ans.begin();it!=ans.end();it++){
  no = maxDivide(no, *it);
  if(no==1) return 1;
//  if()
 // no = maxDivide(no, 3);
 // no = maxDivide(no, 5);
}
//if(no==1) return 1;
//for(it=ans.begin();it!=ans.end();it++){
//if(no==*it) return 1;
//}
  return 0;
}

int comp(string a,string b)
{
    string aa = a.append(b);
    string bb = b.append(a);

    return aa.compare(bb) > 0 ? 1: 0;

}
vector<pair<int,int> >adj[100005];
int colors[100005]={0};
void dfs(int i,int color,int prev1=-1)
{
 for(int j=0;j<adj[i].size();j++)
 {
     if(adj[i][j].first==prev1) continue;
//cout<<adj[i][j].second<<endl;
     if(adj[i][j].second&1)
     {

         colors[adj[i][j].first]=1-color;
     }
     else
         colors[adj[i][j].first]=color;
     dfs(adj[i][j].first,colors[adj[i][j].first],i);

 }
}
int main()
{
   int n;
   cin>>n;
   for(int i=0;i<n-1;i++)
   {
    int a,b,c;
    cin>>a>>b>>c;
    adj[a].push_back(make_pair(b,c));
    adj[b].push_back(make_pair(a,c));

   }
   colors[1]=0;
   dfs(1,0);
   for(int i=1;i<=n;i++) cout<<colors[i]<<endl;
}


Measured memory_bytes: 7552
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
#include <atcoder/maxflow>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()




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

	int n, m;
	string s[100];
	cin >> n >> m;
	rep(i, n)cin >> s[i];

	atcoder::mf_graph<int> g(n * m + 2);

	vector<tuple<int, int, char, int, int, char>> tile;
	rep(i, n)rep(j, m) {
		if (s[i][j] == '#')continue;
		if ((i + j) % 2 == 0 ) {
			int cur = i * m + j;
			if (0 < i) {
				g.add_edge(cur, (i - 1) * m + j, 1);
				tile.emplace_back(i - 1, j, 'v', i, j, '^');
			}
			if (i + 1 < n) {
				g.add_edge(cur, (i + 1) * m + j, 1);
				tile.emplace_back(i, j, 'v', i + 1, j, '^');
			}

			if (0 < j) {
				g.add_edge(cur, i * m + j - 1, 1);
				tile.emplace_back(i, j - 1, '>', i, j, '<');
			}
			if (j + 1 < m) {
				g.add_edge(cur, i * m + j + 1, 1);
				tile.emplace_back(i, j, '>', i, j + 1, '<');
			}
		}
	}
	rep(i, n)rep(j, m) {
		if (s[i][j] == '#')continue;
		if ((i + j) % 2 == 0) {
			g.add_edge(n * m, i * m + j, 1);
		}
		else {
			g.add_edge(i * m + j, n * m + 1, 1);
		}
	}

	cout << g.flow(n * m, n * m + 1) << endl;
	rep(i, tile.size()) {
		atcoder::mf_graph<int>::edge e = g.get_edge(i);
		if (e.flow == 1) {
			auto t = tile[i];
			s[get<0>(t)][get<1>(t)] = get<2>(t);
			s[get<3>(t)][get<4>(t)] = get<5>(t);
		}
	}
	rep(i, n) {
		cout << s[i] << endl;
	}


	return 0;
}


Measured memory_bytes: 5500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<char> S(N);
  for (int i=0;i<N;i++) {
    cin >> S.at(i);
  }
  
  int max=0;
  vector<int> count(N);
  for (int i=1;i<N;i++) {
    for (int j=0;j<N;j++) {
      count.at(j) = 0;
    }
    for (int j=0;j<i;j++) {
      for (int k=i;k<N;k++) {
        if (S.at(j) == S.at(k)) {
          count.at(k) = 1;
          break;
        }
      }
    }
    int sum=0;
    for (int j=0;j<N;j++) {
      sum += count.at(j);
    }
    if (max < sum) {
      max = sum;
    }
  }
  
  cout << max << endl;
}

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

int p[N];
int s[N];

int init(int n) {
    iota(p,p + n,0);
    fill(s,s + n,1);
    return  1;
}
int lead(int x) {
    return p[x] == x ? x : p[x] = lead(p[x]);
}
int join(int x,int y)   {
    x = lead(x);
    y = lead(y);

    if (x == y) return  0;
    if (s[x] < s[y])
        swap(x,y);
    p[y] = x;
    s[x] += s[y];

    return  1;
}

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    ll  m;  cin >> m;
    int q;  cin >> q;

    vector<ii>  v1;
    vector<ii>  v2;

    for(int i = 0 ; i < q ; ++i)    {
        int x;  cin >> x;
        int y;  cin >> y;
        int t;  cin >> t;

        if (t)  v2.pb(x,y);
        else    v1.pb(x,y);
    }

    if (m < n)  {
        if (v2.size())
            cout << "No";
        else
            cout << "Yes";

        return  0;
    }

    init(n);

    for(ii  e : v1) join(e.X,e.Y);
    for(ii  e : v2) {
        int x = lead(e.X);
        int y = lead(e.Y);

        if (x == y) {
            cout << "No";
            return  0;
        }
    }
    int comps = 0;

    for(int i = 0 ; i < n ; ++i)
        if (i == lead(i))
            comps++;

    if (m - n <= 1ll * comps * (comps - 3) / 2)
        cout << "Yes";
    else
        cout << "No";
}

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

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

  ll N; cin >> N;
  vector<ll> A(4, 0);
  for (ll i = 0; i < N; i++) {
    string S; cin >> S;
    if (S == "AC") A[0]++;
    if (S == "WA") A[1]++;
    if (S == "TLE") A[2]++;
    if (S == "RE") A[3]++;
  }

  cout << "AC x " << A[0] << '\n';
  cout << "WA x " << A[1] << '\n';
  cout << "TLE x " << A[2] << '\n';
  cout << "RE x " << A[3] << '\n';

  return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]) {
    int a, b, k;
    cin >> k >> a >> b;
    if(a<=(b/k)*k){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    return 0;
}


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

void dfs(int i, vector<bool> &checked, vector<vector<int>> &way) {
  checked.at(i) = true;
  for(int j = 0; j < way.at(i).size(); j++) {
    if(checked.at(way.at(i).at(j))) {
      continue;
    }
    dfs(way.at(i).at(j), checked, way);
  }
}
      
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> way(N, vector<int>());
  for(int i = 0; i < M; i++) {
    int a, b, z;
    cin >> a >> b >> z;
    way.at(a - 1).push_back(b - 1);
    way.at(b - 1).push_back(a - 1);
  }
  vector<bool> checked(N, false);
  int count = 0;
  for(int i = 0; i < N; i++) {
    if(checked.at(i)) {
      continue;
    }
    else {
      dfs(i, checked, way);
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 14788
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

A = deque(input())
B = deque(input())
C = deque(input())

def DFS(N):
	if not eval(N):
		print(N)
	else:
		q = eval("{}.popleft()".format(N))
		DFS(q.upper())
DFS("A")



Measured memory_bytes: 5328
#include <iostream>

using namespace std;

int main()
 {
     int n,t;
     cin>>n>>t;
     int x=10000000;
     for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(b<=t){
            if(x>a)
                x=a;
        }
     }
     if(x==10000000)
        cout<<"TLE";
     else
        cout<<x;
        return 0;
 }

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

using namespace std;

    int main()
    {
        int n,k,l[100],ans=0;
        cin>>n>>k;
        for(int i=0;i<n;i++){
            cin>>l[i];
        }
        sort(l,l+n);
        reverse(l,l+n);

        for(int i=0;i<k;i++){
            ans+=l[i];
        }
        cout<<ans<<endl;
        return 0;
    }




Measured memory_bytes: 256
#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 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;

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

  string s;
  cin >> s;
  ll n = s.size();

  vvll dp(2, vll(2019, 0));
  ll ans = 0;
  rep(i, n) {
    ll now = s[i] - '0';
    ans += dp[i%2][2019 - now];
    rep(j, 2019) { 
      dp[(i+1)%2][10*(now + j) % 2019] = dp[i%2][j];
      //if (dp[i][j] > 0) printf("add %lld at %lld\n", dp[i][j], j);
    }
    dp[(i+1)%2][10*now] += 1;
    //cout << "i=" << i << endl;
    //rep(kk, 2019) cout << kk << ":"<< dp[i+1][kk] << endl;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3784
from collections import deque
import copy
H, W = map(int, input().split())
field = []
for i in range(H):
    field.append(list(input()))
f = copy.deepcopy(field)

def BFS(x, y, field):
    cnt = [[0 for _ in range(W)] for _ in range(H)]
    queue = deque()
    queue.append((x, y))
    while queue:
        x, y = queue.popleft()
        if(field[x][y] == "#"):
            continue        
            
        field[x][y] = "#"
        for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1)):
            nx = x + dx
            ny = y + dy
            if(nx < 0 or nx >= H or ny < 0 or ny >= W):
                continue
            queue.append((nx, ny))
            if(field[nx][ny] != "#"):
                cnt[nx][ny] = cnt[x][y] + 1
    return cnt

ans = 0
for i in range(H):
    for j in range(W):
        if(field[i][j] == "#"):
            continue
        cnt = BFS(i, j, f)
        for k in range(len(cnt)):
            tmp = max(cnt[k])
            ans = max(ans, tmp)
        f = copy.deepcopy(field)
print(ans)

Measured memory_bytes: 3564
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int x  = sc.nextInt();
		int y  = sc.nextInt();
		int a[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
		if(a[x] == a[y]) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		}
	}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int main() {
    /* input */
    int D, G;  cin >> D >> G;
    vector<int> p(D);
    vector<int> c(D);
    rep(i, D) {
        cin >> p[i] >> c[i];
    }

    // 方針：最適解の候補を絞って，その中で全探索
    int ans = INF;
    for (int bit = 0; bit < (1<<D); ++bit) {
        int sum = 0;  // 合計点
        int cnt = 0;  // 解いた問題数
        vector<int> visited(D, 0);  // 完全に解いた問題

        // 完全に解く
        rep(i, D) {
            if (bit & (1<<i)) {
                sum += (i+1) * 100 * p[i] + c[i];
                cnt += p[i];
                ++visited[i];
            }
        }

        // Gをsumが超えていれば解を更新
        if (sum >= G) {
            ans = min(ans, cnt);
        // 超えていなければ，"中途半端"に解く
        } else {
            bool flag2 = false;  // sumがG超えか判定
            rep(i, D) {
                // 解いていない中で単価が最大の問題のみを訪問
                if (visited[D-i-1] == 0) {
                    rep(j, p[i]) {
                        sum += (D-i) * 100;
                        ++cnt;
                        if (j == p[i]-1) break;
                        // sumがGを超えた時フラグを立ててbreak
                        if (sum >= G) {
                            flag2 = true;
                            break;
                        }
                    }
                    break;
                }
            }
            // sumがGを超えた時だけ解を更新
            if (flag2) ans = min(ans, cnt);
        }
    }
    
    print(ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
const int N=1e5+5;
int n,m,par[N],deg[N];
std::queue<int> q;
std::vector<int> g[N];
int main() {
    scanf("%d%d",&n,&m);m+=n-1;
    int a,b;
    while(m--) {
        scanf("%d%d",&a,&b);
        deg[b]++;
        g[a].push_back(b);
    }
    for(int i=1;i<=n;i++) if(!deg[i]) q.push(i);
    while(!q.empty()) {
        int u=q.front();q.pop();
        for(int v:g[u]) {
            deg[v]--;
            if(!deg[v]) {
                par[v]=u;q.push(v);
            }
        }
    }
    for(int i=1;i<=n;i++) printf("%d\n",par[i]);
    return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

struct data{
  ll h,r,s;
  bool operator<(const data& d){
    return s < d.s;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin >> n && n){
    vector<data> v;
    ll h,r,mh = 0;
    rep(i,n){
      cin >> h >> r;
      mh = max(mh,h);
      v.push_back({h,r,h+r});
    }
    cin >> m;
    rep(i,m){
      cin >> h >> r;
      mh = max(mh,h);
      v.push_back({h,r,h+r});
    }
    sort(all(v));
    ll ans = 0,c = 0;
    vary(ll,dp,n+m+1,0);
    rep(i,n+m){
      dp[i] = 1;
      REP(j,0,i){
        if(v[j].h < v[i].h && v[j].r < v[i].r){
          dp[i] = max(dp[i],dp[j]+1);
        }
      }
      ans = max(ans,dp[i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static int max = 0;
    static void Main(string[] args)
    {
        int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        Console.WriteLine(arr[0] <= arr[1] ? "unsafe" : "safe");


    }


}



Measured memory_bytes: 18872
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
    if(x>y)return x;
    else return y;
}
ll min(ll x,ll y){
    if(x<y)return x;
    else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    ll n,x,m;
    cin >> n >> x >> m;
    vector<ll> ans;//余りはたかだかm通り
    set<ll> al;
    int zero=-1;
    int back=-1;
    rep(i,m+1){
        if(al.count(x)){
            rep(j,ans.size())if(x==ans[j]){back=j;break;}
            break;
        }
        al.insert(x);
        ans.emplace_back(x);
        x*=x;x%=m;
        if(x==0){
            zero=i;
            break;
        }
    }
    ll roopsize=ans.size()-back;
    ll res=0;
    if(x==0){
        rep(i,min((int)ans.size(),n))res+=ans[i];
        cout << res << endl;return 0;
    }

    if((int)ans.size()>=n){
        rep(i,n)res+=ans[i];
        cout << res << endl;return 0;
    }
    rep(i,back)res+=ans[i];
    n-=back;
    rep2(i,back,ans.size()){
        ll num=n/roopsize;
        res+=ans[i]*num;
        if(n%roopsize + back>=i+1)res+=ans[i];
    }
    cout << res << endl;
}

Measured memory_bytes: 5912
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll x;
    cin >> x;
    if (x % 11 == 0) {
        cout << ((x / 11) * 2) << endl;
    }
    else if (x % 11 <= 6) {
        cout << ((x / 11) * 2) + 1 << endl;
    }
    else {
        cout << ((x / 11) * 2) + 2 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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;
}


ll A, B;
vector<ll> kouho;

int main () {
  cin >> A >> B;

  if (B >= 4) {
    while (A % 4 != 0) {
      kouho.push_back(A);
      A += 1;
    }

    while (B % 4 != 3) {
      kouho.push_back(B);
      B -= 1;
    }
  } else {
    for (int i=A;i<=B;++i) {
      kouho.push_back(i);
    }
  }

  ll ans = 0;

  for (auto num : kouho) {
    ans ^= num;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
n=int(input())
l=[[0]]*n
for i in range(n):
  v=list(map(int,input().split()))
  l[i]=v
dp=l[0]
for m in l[1:]:
  a=max(m[0]+dp[1],m[0]+dp[2])
  b=max(m[1]+dp[0],m[1]+dp[2])
  c=max(m[2]+dp[1],m[2]+dp[0])
  dp=[a,b,c]
print(max(dp))
  
  
  


Measured memory_bytes: 58328
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   unik(v)       v.erase(unique(all(v)),v.end())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
void solve()
{
    ll n;
    cin>>n;
    ll a[n+2];
    ll tx=0;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        tx=tx^a[i];
    }
    vll ans;
    for(ll i=1;i<=n;i++){
        cout << (tx^a[i]) <<" ";
    }
}
int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 5184
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

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

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

int main() {
    int N; cin >> N;
    ll T[N]; for (int i = 0; i < N; i++) cin >> T[i];

    ll ans = 1;
    for (int i = 0; i < N; i++) {
        ans = lcm(ans, T[i]);
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<string>;
using namespace std;
string Sum(string str1, string str2){
	int str1_index, str2_index, num, advance;
	string strsum;
	if(str1.size() < str2.size()){
		while(str1.size() != str2.size()) str1 = "0" + str1;
	}else if(str1.size() > str2.size()){
		while(str1.size() != str2.size()) str2 = "0" + str2;
	}
	str1_index = str1.size()-1;
	str2_index = str2.size()-1;
	advance = 0;
	while(true){
		num = (str1[str1_index] - '0') + (str2[str2_index] - '0') + advance;//????????????????£?????¶???????+??°????????°
		strsum = char( (num % 10) + '0') + strsum;//??????????????\
		//cout<<"strsum="<<strsum<<endl;
		(num >= 10)? advance=1: advance=0;
		str1_index--;
		str2_index--;
		if(str1_index<0 || str2_index<0){
			if(advance>0) strsum = "1" + strsum;
			break;
		}
	}
	return strsum;
}

int main(){
	int i, n;
	string str1,str2;
	string strsum;
	while(cin>>n){
		for(i=0;i<n;i++){
			cin>>str1;
			cin>>str2;
			
			if(str1.size()>80 || str2.size()>80){
				cout<<"overflow"<<endl;
				continue;
			}
			strsum = Sum(str1, str2);
			if(strsum.size()>80)
				cout<<"overflow"<<endl;
			else
				cout<<strsum<<endl;
		}
	}
	
	return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,p; cin>>n>>p;
  ll gu=0, ki=0;
  rep(i,n){
    ll a; cin>>a;
    if(a%2) ki++;
    else gu++;
  }
  
  ll ans;
  if(p && ki==0){
    ans=0;
  }else{
    ans=round(pow(2,gu+max(ki-1,0LL)));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
using ll = long long;
using P = pair<ll, int>;

const int mod = 1000000007;
struct mint {
  ll x; 
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

struct Edge{
	int to;
	ll cost;
	Edge(int t, ll c) : to(t), cost(c){}
};

using p_vec = pair<vector<ll>, vector<mint>>;

int n;
vector<vector<Edge>> g; 

p_vec dijkstra(int start){
	vector<ll> dist(n, LINF);
	vector<mint> cnt(n, 0); 
	priority_queue<P, vector<P>, greater<P>> que;
	cnt[start] = 1;
	dist[start] = 0;
	que.push({dist[start], start});

	while(!que.empty()){
		auto v = que.top();
		que.pop();
		int from = v.second;
		ll d = v.first;
		if(d > dist[from])continue;

		for(auto nv : g[from]){
			int to = nv.to;
			ll cost = nv.cost;
			if(dist[from] + cost < dist[to]){
				cnt[to] = cnt[from];
				dist[to] = dist[from] + cost;
				que.push({dist[to], to});
			}
			else if(dist[from] + cost == dist[to]){
				cnt[to] += cnt[from];
			}
		}
	}

	return {dist, cnt};
}

int main(){
  int m, s, t;
  cin >> n >> m >> s >> t;
  --s;
  --t;
  g.resize(n);
  for(int i = 0; i < m; ++i){
  	int u, v;
  	ll d;
  	cin >> u >> v >> d;
  	--u;
  	--v;
  	g[u].push_back(Edge(v, d));
  	g[v].push_back(Edge(u, d));
  }

  auto dij_s = dijkstra(s);
  auto dist_s = dij_s.first;
  auto cnt_s = dij_s.second;
  auto dij_t = dijkstra(t);
  auto dist_t = dij_t.first;
  auto cnt_t = dij_t.second;

  ll total_dist = dist_s[t];
  mint ans = cnt_s[t] * cnt_t[s];
  for(int i = 0; i < n; ++i){
  	if(dist_s[i] * 2 == dist_s[t]){
  		ans -= (cnt_s[i] * cnt_t[i]).pow(2);
  	}
  	for(auto nv : g[i]){
  		int from = i;
  		int to = nv.to;
  		ll cost = nv.cost;

  		if(dist_s[from] + cost + dist_t[to] != total_dist)continue;
  		if(dist_s[from] == dist_t[from] || dist_s[to] == dist_t[to])continue;
  		if(dist_s[from] < dist_t[from] && dist_s[to] > dist_t[to]){
  			ans -= (cnt_s[from] * cnt_t[to]).pow(2);
  		}
  	}
  }

  
  cout << ans.x << endl;

  return 0;
}


Measured memory_bytes: 20308
# -*- coding: utf-8 -*-
s = input()
len_s = len(s)

ret = 0
def calc_cumsum(idx,right_str):
    if idx == len(right_str):
        return int(right_str)
    _ifplus = int(right_str[0:idx])* (2**(len(right_str[idx:len_s]) -1 )) + calc_cumsum(1,right_str[idx:len_s])
    _ifnotplus = calc_cumsum(idx+1,right_str)
    return (_ifplus+_ifnotplus)
print(calc_cumsum(1,s))


Measured memory_bytes: 3060
unittest
{
	assert( [ "1 2 2 2 1", "2 4", "5 1", "3" ].solve == 12 );
	assert( [ "2 2 2 2 2", "8 6", "9 1", "2 1" ].solve == 25 );
	assert( [ "2 2 4 4 4", "11 12 13 14", "21 22 23 24", "1 2 3 4" ].solve == 74 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto x = 0L;
	auto y = 0L;
	auto a = 0L;
	auto b = 0L;
	auto c = 0L;
	input.front.formattedRead!"%s %s %s %s %s"( x, y, a, b, c );
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	input.popFront;
	auto qs = input.front.split.to!( long[] );
	input.popFront;
	auto rs = input.front.split.to!( long[] );
	
	ps.sort;
	qs.sort;
	rs.sort;
	ps = ps[ $ - x .. $ ];
	qs = qs[ $ - y .. $ ];
	
	// 赤か緑のリンゴのうち、美味しくないほうから無色のリンゴに交換
	auto ans = ps.sum + qs.sum;
	ps ~= long.max;
	qs ~= long.max;
	foreach( i; 0L .. min( c, x + y ) )
	{
		if( ps.front < qs.front )
		{
			if( rs.back < ps.front ) break;
			ans += rs.back - ps.front;
			ps.popFront;
			rs.popBack;
		}
		else
		{
			if( rs.back < qs.front ) break;
			ans += rs.back - qs.front;
			qs.popFront;
			rs.popBack;
		}
	}
	return ans;
}


Measured memory_bytes: 15208
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1000 + 10;

struct P
{
	int x, y;
	void read() { cin >> x >> y; }
} c[N];

ld edges[N][N], cost_dijkstra[N];
bool vis[N];
int r[N], n;

struct node {
	int u;
	ld cost;
	node(int x, ld y) : u(x), cost(y) {}
	bool operator<(const node &other) const { return cost > other.cost; }
};

void dijkstra() {
	for (int i = 1; i <= n + 1; ++i)
		cost_dijkstra[i] = 1e19L;
	priority_queue<node> q;
	q.emplace(0, 0.0L);
	while (!q.empty()) {
		int u = q.top().u;
		ld cost = q.top().cost;
		q.pop();
		if (vis[u])
			continue;
		vis[u] = true;
		for (int i = 0; i <= n + 1; ++i) {
			if (i == u || vis[i])
				continue;
			if (edges[i][u] + cost < cost_dijkstra[i]) {
				cost_dijkstra[i] = edges[i][u] + cost;
				q.emplace(i, cost_dijkstra[i]);
			}
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	c[0].read();
	c[N - 1].read();
	cin >> n;
	c[n + 1] = c[N - 1];
	for (int i = 1; i <= n; ++i) {
		c[i].read();
		cin >> r[i];
	}
	for (int i = 0; i <= n + 1; ++i) {
		for (int j = i + 1; j <= n + 1; ++j) {
			ld dis = sqrtl(ld(c[i].x - c[j].x) * (c[i].x - c[j].x) + ld(c[i].y - c[j].y) * (c[i].y - c[j].y));
			edges[i][j] = edges[j][i] = max(0.0L, dis - r[i] - r[j]);
		}
	}

	dijkstra();

	cout << cost_dijkstra[n + 1] << '\n';

	return 0;
}

Measured memory_bytes: 25964
#include "bits/stdc++.h"
 
using namespace std;
 
#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238
 
typedef pair<int, int> P;
 

void solve(long long N, std::string s){
    int r = 0;
    int g = 0;
    int b = 0;
    int ans = 0;
    REP(i,N){
        if(s[i]=='R'){
            r++;
        }
        else if(s[i]=='G') g++;
        else if(s[i]=='B') b++;
    }
    ans += r*g*b;
    REP(i,N){
        REP(j,N){
            if(i==j) continue;
            else if(s[i]=='R'&&s[j]=='G'){
                if(max(i,j)+abs(i-j)<=N-1){
                    if(s[max(i,j)+abs(i-j)]=='B') ans--;
                }
                if(min(i,j)-abs(i-j)>=0){
                    if(s[min(i,j)-abs(i-j)]=='B') ans--;
                }
                if((i+j)%2==0&&s[(i+j)/2]=='B') ans--;
            }
        }
    }
    cout<<ans<<endl;
}
 
signed main(){
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
    long long N;
    scanf("%lld",&N);
    std::string s;
    std::cin >> s;
    solve(N, s);
    return 0;
}


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

int main(){
  int X,Y;
  cin >> X >> Y;
  int a;
  a=Y-2*X;
  if(a<0 || a%2!=0 || X-(a/2)<0){
    cout << "No" <<endl;
  }
  else{
    cout << "Yes" <<endl;
  }
}

Measured memory_bytes: 3608