akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

struct Node
{
    int end_count = 0;
    bool init = 0;
    vector<Node> nodes;

    void add(string &s)
    {
        if (s.empty())
            end_count++;
        else
        {
            if (!init)
            {
                nodes.assign(26, Node{});
                init = 1;
            }
            int idx = s.back() - 'a';
            s.pop_back();
            nodes[idx].add(s);
        }
    }
};

struct Trie
{
    Node node = Node{};

    void add(string &s)
    {
        node.add(s);
    }
};

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int N;
    cin >> N;
    vector<string> a(N);
    REP(i, 0, N)
    cin >> a[i];
    sort(a.begin(), a.end(), [](string a, string b) { return a.size() < b.size(); });
    auto trie = Trie{};
    ll ans = 0;

    for (auto &w : a)
    {
        vector<int> cnt(26);
        for (auto &c : w)
            cnt[c - 'a']++;

        Node *node = &trie.node;
        REPR(i, w.size() - 1, -1)
        {
            if (!node->init)
            {
                break;
            }
            REP(j, 0, 26)
            {
                if (cnt[j] > 0)
                    ans += node->nodes[j].end_count;
            }
            cnt[w[i] - 'a']--;
            node = &node->nodes[w[i] - 'a'];
        }

        trie.add(w);
    }

    cout << ans << endl;
}


Measured memory_bytes: 909092
#include<iostream>
#include <numeric>
// #include<string>
#include<vector>
#include <algorithm>
#include <cmath>
// #include <functional>

using namespace std;

int main()
{
    int array[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    // Input
    int k;
    cin >> k;

    cout << array[k-1];

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    vvc<ll> dp(N + 1, vl(2, -INF));
    dp[0][0] = 0;

    rep(i, N){
        dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i]);
        dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i]);
    }

    cout << dp[N][0] << endl;
}

Measured memory_bytes: 9544
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int main() {
	int N, K, M = 0;
	scanf("%d%d", &N, &K);
	vector<int> A(N);
	rep(i, 0, N)scanf("%d", &A[i]), M = max(M, A[i]);
	int c = A[0];
	rep(i, 1, N)c = gcd(c, A[i]);
	puts(K % c || M < K ? "IMPOSSIBLE" : "POSSIBLE");
}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vll>;
df data(n, vll(m));
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  string a;
  string b;
  cin >> a;
  cin >> b;
  reverse(b.begin(), b.end());
  cout << (a == b ? "YES" : "NO");
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	//"strconv"
)

func main(){
	var w string 
	var a int
	var b [200]int
	var ans [200]int
	var f bool

	fmt.Scan(&w)

	for j := 0 ; j < 200 ; j++ {
		ans[j] = 0
	}
	for j := 0 ; j < len(w) ; j++ {
		b[w[j]]++
	}
	
	for j := 0 ; j < 200 ; j++ {
		//fmt.Printf("%d ", b[j])
	}
	
	a = 0
	f = true
	for j := 0 ; j < 200 ; j++ {
		if b[j] % 2 == 0 {
			a++	
		}else {
			f = false
			break
		}
	}
	//fmt.Println(a)
	if f == false {
		 fmt.Println("No")
	}else {
		fmt.Println("Yes")	
	}

}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	int max1 = 0, max2 = 0;
	int max1_i = 0, max2_i = 0;
	rep(i, N)
	{
		int tmp;
		cin >> tmp;
		if (max1<tmp)
		{
			max2 = max1;
			max2_i = max1_i;
			max1 = tmp;
			max1_i = i;
		}
		else if (max2<tmp)
		{
			max2 = tmp;
			max2_i = i;
		}
	}
	rep(i, N)
	{
		if (i == max1_i) cout << max2 << endl;
		else cout << max1 << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
@@=1..<>;/ .* /,$_[$`][$&]=$_[$&][$`]=$' for@M=<>;for$i(@@){//,map$_[$'][$_]=($%=$_[$'][$_]||1e9)<($==($_[$'][$i]||1e9)+($_[$i][$_]||1e9))?$%:$=,@@for@@}/ .* /,$\+=$_[$`][$&]<$' for@M;print

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

using namespace std ;
#define inf 999999999 ;
int N ;
int ara[100020] ;
int dp[100020] ;

int recur(int cur){
    if(cur == N-1) return 0 ;
    if(cur > N-1 ){
        return inf ;
    }

    if(dp[cur] != -1){
        return dp[cur] ;
    }

    int x = abs(ara[cur+1] - ara[cur]) ;
    int y = abs(ara[cur+2] - ara[cur]) ;

    dp[cur] = min(x+recur(cur+1), y+recur(cur+2)) ;

    return dp[cur] ;
}



int main(){

    scanf("%d",&N) ;
    for(int i=0 ; i<N ; i++){
        scanf("%d",&ara[i]) ;
    }
    memset(dp,-1,sizeof(dp)) ;
    ara[N] =0 ;
    ara[N+1] = 0 ;
    int ans = recur(0) ;

    printf("%d\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 3328
#include <stdio.h>
#define max(a,b) (a>b?a:b)

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

  int x[100010]={a[0]};
  int y[100010]={b[0]};
  int z[100010]={c[0]};

  for(i=0;i<n-1;i++){
    x[i+1]=max(y[i],z[i])+a[i+1];
    y[i+1]=max(z[i],x[i])+b[i+1];
    z[i+1]=max(x[i],y[i])+c[i+1];
  }

  int w=max(x[n-1],y[n-1]);

  printf("%d",max(w,z[n-1]));
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;

int main(){
    
    int N;cin>>N;
    vector<int> S(N);
    for(int i=0;i<N;i++){
        cin>>S[i];
    }
    sort(all(S));
    cout<<S[N/2]-S[N/2-1]<<endl;
}


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

int check (long long n, long long d) {
    while (n && n % d == 0) n /= d;
    n %= d;
    return n == 1;
}

int main() {
    long long n;
    while (scanf("%lld", &n) == 1) {
        set<int> divs;
        
        if (n == 2) {
            printf("1\n");
            continue;
        }
        for (int d = 2; 1ll * d * d <= n; d++) {
            if (check(n, d)) divs.insert(d);
            if (n % d == 0 && check(n, n / d)) divs.insert(n / d); 
        }

        for (int d = 2; 1ll * d * d <= n - 1; d++) {
            if ((n - 1) % d == 0) 
                divs.insert(d),
                divs.insert((n - 1) / d);
        }

        printf("%d\n", (int)divs.size() + 2);
    }
}


Measured memory_bytes: 256
#include<iostream>
//#include<vector>

int main(){
	long long int k,x,n,a;
	std::cin >> k >> x;

	n = k * 2 - 1;

	a = x - k+1;

	for (int i = 0; i < n; i++) {
		std::cout << a+i << std::endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)

using namespace std;

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int n; cin >> n;
    set<string> se;
    string last;
    foi(i,0,n) {
        string s; cin >> s;
        if(i) {
            if(s[0] != last.back() || se.count(s)) {
                cout << "No\n";
                return 0;
            }
        }
        se.insert(s);
        last = s;
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>

using namespace std;
#define REP(i,m,n) for(long long i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

string a{ "KIHBRA" };
vector<int>v[10];

int main() {
	string s;
	cin >> s;
	if (s.size() > 9 || s.size() < 5) {
		cout << "NO" << endl;
		return 0;
	}
	int length = 0;
	REP(i, 0, 6) {
		REP(j, 0, s.size()) {
			if (s[j] == a[i]) {
				v[i].push_back(j);
				length++;
			}
		}
	}
	if (length != s.size()) {
		cout << "NO" << endl;
	}
	else if (v[0].size() == 1 && v[1].size() == 1 && v[2].size() == 1 && v[3].size() == 1 && v[4].size() == 1 && v[0][0] < 2 && v[1][0] - v[0][0] == 1 && v[2][0] - v[1][0] == 1 && (v[3][0] - v[2][0] == 2 || v[3][0] - v[2][0] == 1) && (v[4][0] - v[3][0] == 2 || v[4][0] - v[3][0] == 1)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;

#define int long long
int a,b,c,d;

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

	cin >> a >> b >> c >> d;
	int z_c = b/c - (a-1)/c;
	int z_d = b/d - (a-1)/d;
	int lcm = (c*d) / __gcd(c,d);
	int z_cd = b/lcm - (a-1)/lcm;
	cout << (b - a + 1) - (z_c + z_d - z_cd);
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N; cin >> N;
	VI A(N);
	int ans = 0;
	REP(i, N) {
		int a; cin >> a;
		if (i % 2 == 0 && a % 2)ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class I,class V=typename I::value_type>V sum_up(const I&l,const I&r){V v;for(I i=l;i!=r;i++)v=i==l?*i:v+*i;return v;}
template<class I,class T=iterator_traits<I>>I operator+(I it,int n){for(int i=0;i<n;i++)it++;return it;}
template<class I,class T=iterator_traits<I>>I operator-(I it,int n){for(int i=0;i<n;i++)it--;return it;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
void R_YESNO(bool p){cout<<(p?"YES":"NO")<<endl;}
void R_YesNo(bool p){cout<<(p?"Yes":"No")<<endl;}
int main() {
    const int INF = 1e8;
    string S;
    cin >> S;
    S = string("0") + S;
    reverse(WHOLE(S));
    int ans = 0, N = S.size();
    // i, c |-> i桁目まで計算終了して，キャリーがc
    vector2d<int> dp(N + 1, vector<int>(2, INF));
    dp[0][0] = 0;
    for(int i = 0; i < N; i++) {
        for(int c = 0; c < 2; c++) {
            // その桁の支払い + 前の桁から借りた場合の1
            int n = S[i] - '0' + c;
            dp[i + 1][0] = min(dp[i + 1][0], dp[i][c] + abs(n));
            // 上の桁から借りて10返済
            n -= 10;
            dp[i + 1][1] = min(dp[i + 1][1], dp[i][c] + abs(n));
        }
    }
    cout << dp[N][0] << endl;
    return 0;
}



Measured memory_bytes: 55856
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <unordered_map>

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  double sum = 0;
  REP(i, n)
  {
    double x;
    string s;
    cin >> x;
    cin >> s;
    if (s == "BTC")
    {
      sum += x * 380000.0;
    }
    else
    {
      sum += x;
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
parseint(x) = parse(Int, x)
int() = readline() |> parseint
ints() = map(parseint, readline() |> split)

function main()
    n = int()
    w = ints()
    a = 10000
    for i = 1:n-1
        a = min(a, abs(sum(w[1:i])-sum(w[i+1:n])))
    end
    println(a)
end

main()

Measured memory_bytes: 111528
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>

using namespace std;
int main()
{
	int N, Ans, f, e;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> f >> e;
		Ans = Ans + e - f + 1;
	}

	cout << Ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define INF 1000000007
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2)*pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int jo(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= 2;
	}
	return ans;
}

signed main() {
	int a, b;
	cin >> a >> b;
	if (a%b == 0)cout << 0 << endl;
	else cout << 1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>

using namespace std;

char str[1010];

int main(){
    scanf("%s",str);
    int len=strlen(str);
    int res=0;
    for(int i=0;i<len;++i){
        int cnt=0;
        while(i<len&&str[i]=='R'){
            cnt++;
            i++;
        }
        res=max(cnt,res);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const ll MOD=998244353;

int main(){
  ll n,s;
  cin >> n >> s;
  ll a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  vector<vector<ll>> dp(n+1,vector<ll>(s+1,0));
  dp[0][0]=1;
  for(int i=1;i<=n;i++){
    for(int j=0;j<=s;j++){
      dp[i][j]+=2*dp[i-1][j];
      if(j-a[i-1]>=0) dp[i][j]+=dp[i-1][j-a[i-1]];
      dp[i][j]%=MOD;
    }
  }
  cout << dp[n][s] << endl; 
}


Measured memory_bytes: 73664
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int pcnt(int x) {
    return __builtin_popcount(x);
}

int f(int x) {
    if(x == 0) return 0;
    return f(x%pcnt(x))+1;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<int> xvec(n, 0);
    int pc = 0;
    for(int i = 0; i < n; ++i) {
        xvec[i] = s[i] - '0';
        pc += xvec[i];
    }

    // pcは-1か+1しかない
    vector<int> ans(n, 0);
    for(int bit = 0; bit < 2; ++bit) {
        int npc = pc;
        if(bit == 0) npc++; else npc--;
        if(npc <= 0) continue;
        int check = 0;
        for(int i = 0; i < n; ++i) {
            check = (check*2)%npc;
            check += xvec[i];
        }

        int k = 1;
        for(int i = n-1; i >= 0; --i) {
            if(xvec[i] == bit) {
                int r = check;
                if(bit == 0) r = (r+k)%npc;
                else r = (r-k+npc)%npc;
                ans[i] = f(r)+1;
            }
            k = (k*2)%npc;
        }
    }

    for(int i = 0; i < n; ++i) cout << ans[i] << endl;
}

Measured memory_bytes: 5168
#include <iostream>
#include <string>

int solve(std::string &x, std::string &y){
    int c[1001][1001] = {};
    int m = x.length();
    int n = y.length();

    //for(int i = 1; i <= m; ++i) c[i][0] = 0;                                                                                                                                                                                      
    //for(int i = 1; i <= n; ++i) c[0][i] = 0;                                                                                                                                                                                      
    int maxval = 0;
    x = ' ' + x;
    y = ' ' + y;
    for(int i =  1; i <= m; ++i){
        for(int j = 1; j <= n; ++j){
            if(x[i] == y[j]){
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = std::max(c[i][j - 1], c[i - 1][j]);
            }
            maxval = std::max(maxval, c[i][j]);
        }
    }
    return maxval;
}

int main(){
    int q;
    std::cin >> q;
    for(int i = 0; i < q; ++i){
        std::string x;
        std::string y;
        std::cin >> x;
        std::cin >> y;
        int res = solve(x, y);
        std::cout << res << "\n";
    }
    return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    rep(x, N) {
        cout << A[x];
        if (x != N - 1) {
            cout << ' ';
        }
    }
    cout << '\n';
    rep2(i, 1, N) {
        ll a = A[i];
        ll j = i - 1;
        while (j >= 0 && A[j] > a) {
            A[j + 1] = A[j];
            j--;
            A[j + 1] = a;
        }
        rep(x, N) {
            cout << A[x];
            if (x != N - 1) {
                cout << ' ';
            }
        }
        cout << '\n';
    }

}

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



Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int>vec(3);
  cin>>vec.at(0)>>vec.at(1)>>vec.at(2);
  sort(vec.begin(),vec.end());
  if(vec.at(0)==5&&vec.at(1)==5&&vec.at(2)==7){
    cout<<"YES"<<endl;}
  else{cout<<"NO"<<endl;}
}


Measured memory_bytes: 3608
import java.util.*;
import java.lang.*;
import java.io.*;

class Main{
	public static void main (String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		int arr[]= new int[n];
		for(int i=0;i<n;i++){
			arr[i] = scan.nextInt();
			if(map.containsKey(arr[i])){
				map.put(arr[i],map.get(arr[i])+1);
			}
			else{
				map.put(arr[i],1);
			}
		}
		int count=0;
		for(int i=0;i<n;i++){
			if(!map.containsKey(arr[i])){
				continue;
			}
			if(map.get(arr[i])>arr[i]){
				count += map.get(arr[i])-arr[i];
			}
			else if(map.get(arr[i])<arr[i]){
				count+=map.get(arr[i]);
				//map.remove(arr[i]);
			}
			map.remove(arr[i]);
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 66384
//B - ... (Triple Dots)
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
typedef long long ll;
//#define N 998244353

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  int k,i;
  char x[10010];
  scanf("%d %s", &k, x);
  if(strlen(x)<=k){
    printf("%s\n", x);
  }
  else{
    for(i=0;i<k;i++){
      printf("%c", x[i]);
    }
    printf("...\n");
  }

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  map<int,int> MD;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    MD[x] += 1;
  }
  
  int M;
  cin >> M;
  map<int,int> RD;
  set<int> s;
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    RD[x] += 1;
    s.insert(x);
  }
  
  for (int e : s) {
    if (RD[e] > MD[e]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 28416
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

vector<tuple<int,int,int>> v1;

int main(){
	int n,m,p;
	int i,j,k;
	int a,b,c;
	while(cin>>n>>m>>p){
		if(n==0)return 0;
		for(i=0;i<m;i++){
			cin>>a>>b>>c;
			v1.push_back(make_tuple(a,b,c));
		}
		sort(v1.begin(),v1.end());
		while(!v1.empty()){
			tie(ignore,a,b)=v1.back(),v1.pop_back();
			if(p==a || p==b)p=a+b-p;
		}
		cout<<p<<endl;
	}
}


Measured memory_bytes: 3028
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < b.second;
    }
}
const int MAX = 2000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if(n < k)
        return 0;
    if(n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int x, y;
    cin >> x >> y;
    int a=0, b=0;
    rep(i, 0, x + 1) {
        int ax = i;
        int ay = i * 2;
        if((y - ay) * 2 == (x - ax)) {
            a = i;
            b = (y - ay);
        }
    }
    // cout<<a<<":"<<b<<endl;
    if(a==0&&b==0){
        cout<<0<<endl;
   
    }else{
    // 前処理
    COMinit();
    // 計算例
    cout << COM(a + b, a) << endl;}

}

Measured memory_bytes: 47104
(defun solve (n)
  (loop for i from 1 to (isqrt n)
        do (multiple-value-bind (quotient remainder)
               (truncate n i)
             (when (and (zerop remainder)
                        (< quotient 10))
               (return t)))))

#-swank
(let* ((n (read)))
  (format t "~:[No~;Yes~]~%" (solve n)))


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

int main(){
  int N;
  cin >> N;
  const int tail= N%10;

  string ans= (tail==3) ? "bon" 
             :(tail==0 || tail==1 || tail==6 || tail==8) ? "pon"
                                                         : "hon" ;

  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

ll dp[3300][3300];//dp[i][j]=[i,j)の最大値
bool flag[3300][3300];
ll a[3300];

ll f(int l,int r){
  if(flag[l][r])return dp[l][r];
  flag[l][r]=1;
  if(l==r){
   return dp[l][r]=0; 
  }
  return dp[l][r]=max(a[l]-f(l+1,r),a[r-1]-f(l,r-1));
}

int main(){cout<<fixed<<setprecision(20);
		   int n;
           cin>>n;
           rep(i,0,n)cin>>a[i];
           cout<<f(0,n)<<endl;;
}

Measured memory_bytes: 60448
N = int(input())
uvw = [list(map(int, input().split())) for i in range(N - 1)]

R = {}

for u, v, w in uvw:
  U = u - 1
  V = v - 1
  if U not in R:
    R[U] = [[U, V, w]]
  else:
    R[U].append([U, V, w])
  if V not in R:
    R[V] = [[V, U, w]]
  else:
    R[V].append([V, U, w])

S = [0]
L = [-1] * N
L[0] = 0
while S != []:
  t = []
  for j in S:
    for i in R[j]: 
      if L[i[1]] == -1:
        if i[2] % 2 == 0:
          L[i[1]] = L[i[0]]
        else:
          L[i[1]] = 1 - L[i[0]]
        t.append(i[1])
  S = t

for i in L:
  print(i)




Measured memory_bytes: 70368
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

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

vector<int> G[100000];
int a[100000], b[100000];
int ans[100000];
map<P, int> mp;
bool used[100000];

void dfs(int v, int pc){
    used[v] = true;
    int tmp = 1;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]){
            if(pc == tmp) tmp++;
            int idx = mp[P(v, G[v][i])];
            ans[idx] = tmp;
            dfs(G[v][i], tmp);
            tmp++;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        cin >> a[i] >> b[i];
        b[i]--; a[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
        mp[P(a[i], b[i])] = i;
        mp[P(b[i], a[i])] = i;
    }
    int vm = 0;
    for(int i = 0; i < N; i++){
        vm = max(vm, (int)G[i].size());
    }
    dfs(0, 0);
    cout << vm << endl;
    for(int i = 0; i < N-1; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 19840
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  int a,b,c;
  cin >> a >> b >> c;
  int ans = ((a+b)*c)/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 200050;
VI ed[MAXN], ew[MAXN];
int Did[MAXN], Wid[MAXN];

void DFS(int x, VI *e, int *id, int gid) {
	id[x] = gid;
	for(int u : e[x])
		if(id[u] == 0)
			DFS(u, e, id, gid);
}

int main() {
	int N, K, L;
	scanf("%d%d%d", &N, &K, &L);
	for(int i = 0; i < K; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		ed[a].PB(b);
		ed[b].PB(a);
	}
	for(int i = 0; i < L; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		ew[a].PB(b);
		ew[b].PB(a);
	}
	int gid = 1;
	for(int i = 1; i <= N; i++)
		if(Did[i] == 0)
			DFS(i, ed, Did, gid++);
	gid = 1;
	for(int i = 1; i <= N; i++)
		if(Wid[i] == 0)
			DFS(i, ew, Wid, gid++);
	map<PII, int> mp;
	for(int i = 1; i <= N; i++)
		mp[ MP(Did[i], Wid[i]) ]++;
	for(int i = 1; i <= N; i++)
		printf("%d%c", mp[ MP(Did[i], Wid[i]) ], " \n"[i == N]);
	return 0;
}


Measured memory_bytes: 27904
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = Reads();
            var q = Read();
            var d = new long[(long)Math.Pow(10, 5)+1];
            for (int i = 0; i < n; i++)
            {
                d[a[i]]++;       
            }
            long ans = a.Sum();
            for (int i = 0; i < q; i++)
            {
                var bc = Reads();
                ans += (bc[1] - bc[0]) * d[bc[0]];
                d[bc[1]] += d[bc[0]];
                d[bc[0]] = 0;             
                WriteLine(ans);
            }
          
            Console.Out.Flush();
        }
    }
}



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

int n,x,cnt=0;
int minv=1e9,maxv=-1e9;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		if(x==minv)cnt++;
		if(x<minv)minv=x,cnt=1;
		if(x>maxv)maxv=x;
	}
	if(maxv-minv>1)return printf("No"),0;
	if(maxv==minv){
		if(minv==n-1)return printf("Yes"),0;
		return printf(n/minv>=2?"Yes":"No"),0;
	}
	int a=n-cnt,b=maxv-cnt;
	if(b<1)return printf("No"),0;
	return printf(a/b>=2?"Yes":"No"),0;
}

Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline

abc = list(map(int, input().split()))
cnt = 0
abc.sort()
if (abc[1]%2 == 1 and abc[0]%2 == 0) or (abc[0]%2 == 1 and abc[1]%2 == 0):
    cnt += 1
    abc[1] += 1
    abc[2] += 1
cnt += abc[2]-abc[1] + math.floor((abc[1]-abc[0])/2)
print(cnt)

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

int main() {
  string A;
  string B;
  string C;
  cin >> A;
  cin >> B;
  cin >> C;
  cout << A.at(0) << B.at(1) << C.at(2) << endl;
  
  
  
  

  
  
}



Measured memory_bytes: 3632
from collections import deque

N = int(input())
E = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    E[a-1].append((b-1, c))
    E[b-1].append((a-1, c))

Q, K = map(int, input().split())
distance = [0] * N
stack = deque([K-1])
checked = [False] * N
while stack:
    v = stack.pop()
    for u, c in E[v]:
        if checked[u]:
            continue
        distance[u] = distance[v] + c
        stack.append(u)
    checked[v] = True

ans = [0] * Q
for i in range(Q):
    x, y = map(int, input().split())
    ans[i] = distance[x-1] + distance[y-1]

[print(a) for a in ans]

Measured memory_bytes: 50176
#include <stdio.h>
#define N_MAX 1000000
char s[N_MAX + 1];

int main(void){
	int p = 0;
	char l = 0;
	int j,o,i;
	int a = 0;
	scanf("%s",s);
	j = o = i = 0;
	while(s[p]){
		switch(s[p]){
			case 'J':
			o = i = 0;
			if(l != 'J')j = 0;
			j++;
			break;
			case 'O':
			i = 0;
			if(l != 'O')o = 0;
			if(l == 'I')j = 0;
			o++;
			break;
			case 'I':
			if(!o || o > j)break;
			i++;
			if(i == o && i > a)a = i;
			break;
		}
		l = s[p];
		p++;
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 1516
N,K=gets.split.map &:to_i
A=gets.split.map &:to_i
h=Hash.new{|h,k|h[k]=0}
A.each{|i|h[i]+=1}
H=h.sort{|l,r|l[1]<=>r[1]}
if H.size<=K
  p 0
else
  s=0
  H.each.with_index do |(k,v),i|
    break unless i < h.size-K
    s+=v
  end
  p s
end

Measured memory_bytes: 40952
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<iomanip>

#define pii pair<int,int>
#define ll long long
#define IMAX 1000000007
#define in2d(i,j,H,W)(0<=i&&i<H&&0<=j&&j<W)

using namespace std;

int N;
vector<int>a;
vector<vector<ll> >dp;
int main(){
	cout<<fixed<<setprecision(11);
	
	cin>>N;
	a=vector<int>(N);for(int i=0;i<N;i++)cin>>a[i];
	dp=vector<vector<ll> >(N+1,vector<ll>(N+1,0));
	for(int i=0;i<=N;i++)dp[i][i]=0;
	for(int d=1;d<=N;d++)for(int l=0;l+d<=N;l++){
		int r=l+d;
		if((N-d)%2){
			dp[l][r]=min(dp[l+1][r]-a[l],dp[l][r-1]-a[r-1]);
		}else{
			dp[l][r]=max(dp[l+1][r]+a[l],dp[l][r-1]+a[r-1]);
		}
	}
	cout<<dp[0][N]<<endl;
	return 0;
}



Measured memory_bytes: 72888
(N,M,X),*A=$<.map{_1.split.map &:to_i}
p (0..2**N).map{|i|c,*t=A.transpose.map{|x|N.times.sum{x[_1]*i[_1]}}
t.any?{_1<X}?p: c}.compact.min||-1

Measured memory_bytes: 14560
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const ll INF = 1<<30;
const ll MOD = (ll)1e9 + 7;
const ll MAX_N = (ll)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(ll i = 0; i < (ll) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

template<typename T> struct Combination
{
    vector<T> fact, rfact, inv;
    Combination(ll n) : fact(n + 1), rfact(n + 1), inv(n + 1)
    {
        fact[0] = fact[1] = 1;
        rfact[0] = rfact[1] = 1;
        inv[1] = 1;
        for(ll i = 2; i < n + 1; i++)
        {
            fact[i] = fact[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            rfact[i] = rfact[i - 1] * inv[i] % MOD;
        }
    }
    T C(ll n, ll k)
    {
        if(n < k) return 0;
        if(n < 0 or k < 0) return 0;
        return fact[n] * (rfact[k] * rfact[n - k] % MOD) % MOD;
    }
};

void solve()
{
    ll n, p; cin >> n >> p;
    ll A = 0, B = 0;
    for(ll i = 0; i < n; i++)
    {
        ll a; cin >> a;
        if(a & 1) A++;
        else B++;
    }
    Combination<ll> comb(n + 1);
    // ll ans = 0;
    ll ans = pow(2LL, B);
    ll sum = 0;
    if(p)
    {
        for(ll i = 1; i <= A; i += 2)
        {
            sum += comb.C(A, i);
            // for(ll j = 0; j <= B; j++)
            // {
            //     ans += comb.C(A, i) * comb.C(B, j);
            // }
        }
    }
    else
    {
        for(ll i = 0; i <= A; i += 2)
        {
            sum += comb.C(A, i);
            // for(ll j = 0; j <= B; j++)
            // {
            //     ans += comb.C(A, i) * comb.C(B, j);
            // }
        }
    }
    // cout << ans << endl;
    cout << ans * sum << endl;
    
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let m: usize = read(&mut stdin_lock, &mut buf, b' ');
    let c: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let mut bs = vec![0i32; m];
    for i in 0..(m - 1) {
        bs[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    bs[m - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let mut ans = 0;
    for _ in 0..n {
        let mut a = 0;
        for j in 0..(m - 1) {
            let aij: i32 = read(&mut stdin_lock, &mut buf, b' ');
            a += aij * bs[j];
        }
        let aij: i32 = read(&mut stdin_lock, &mut buf, b'\n');
        a += aij * bs[m - 1];
        a += c;
        if a > 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
// https://qiita.com/e869120/items/eb50fdaece12be418faa

#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

vector<double> X, Y;

double calc_dist(int i, int j) {
    double dx = X[i] - X[j];
    double dy = Y[i] - Y[j];
    return pow(pow(dx, 2.0) + pow(dy, 2.0), 0.5);
}

int main()
{
    int n;
    cin >> n;
    X.resize(n);
    Y.resize(n);
    rep(i, n) {
        cin >> X[i] >> Y[i];
    }

    vector<int> v(n);
    iota(v.begin(), v.end(), 0);
    double res = 0.0;
    double sum = 0.0;
    do {
        sum++;
        for (int i = 0; i < n - 1; i++) {
            res += calc_dist(v[i], v[i+1]);
        }
    } while (next_permutation(v.begin(), v.end()));

    cout << fixed << setprecision(10) << res / sum << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
          int n;
          string s;
          cin>>n>>s;
          int cc = 0;
          fri(i,0,n-2)
          {
                    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
                    {
                              cc++;
                    }
          }
          cout<<cc<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
P = list(map(float,input().split()))

D = [[0] * (n+1) for i in range(n+1)]
D[0][0] = 1
for i in range(1, n+1):
    for j in range(n+1):
        D[i][j] = D[i-1][j] * P[i-1]
        if j-1 >= 0:
            D[i][j] += D[i-1][j-1] * (1-P[i-1])

print(sum(D[-1][:(n+1)//2]))

Measured memory_bytes: 203408
#include<bits/stdc++.h>
using namespace std;
int main(){
        int n, m;
        cin >> n >> m;
        int a = 0;
        int ai;
        for(int i = 0; i < m; i++){
                cin >> ai;
                a += ai;
        }

        int ans = n - a;
        if(ans < 0)ans = -1;
        cout << ans << endl;
}


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

int main(){
    
    string S;
    cin >> S;
    int ans=0;
    for(int i=0; i<4;++i){
        if(S[i]=='+')ans++;
        else ans--;
    }
    cout << ans;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += 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; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll n;cin>>n;
	vl a(n);
	rep(i,n)cin>>a[i];
	sort(all(a));
	ll sum[n+1];
	sum[0]=0;
	rep(i,n){
		sum[i+1]=sum[i]+a[i];
	}
	ll m=0;
	for(int i=1;i<n;++i){
		if(sum[i]*2<a[i]){
			m=i;
		}
	}
	cout<<n-m<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int A, B, C;

signed main() {
    //cin.tie(0); ios::sync_with_stdio(false);
    cin >> A >> B >> C;
    cout << min(C, B/A) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()

int main()
{
  int N; cin >> N;
  map<int, int> mp;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    mp[a]++;
  }

  vector<ll> edge;
  for (auto v : mp) {
    while (v.second >= 2) {
      v.second -= 2;
      edge.push_back(v.first);
    }
  }

  if (edge.size() < 2) {
    cout << 0 << endl;
    return 0;
  }

  sort(ALL(edge), greater<int>());
  cout << edge[0] * edge[1] << endl;
}

Measured memory_bytes: 4992