akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>

int main()
{
    char s[10100];
    while (~scanf("%s", s))
    {
	int joi, ioi;
	joi = ioi = 0;
	for (char* p = s; *p; ++p)
	{
	    if (strncmp(p, "JOI", 3) == 0)
		++joi;
	    else if (strncmp(p, "IOI", 3) == 0)
		++ioi;
	}
	printf("%d\n%d\n", joi, ioi);
    }
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    long long int sum = 0;
    rep(i, m)
    {
        int temp;
        cin >> temp;
        sum += temp;
    }
    if (n < sum)
        cout << -1 << endl;
    else
        cout << n - sum << endl;

    return 0;
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.ARC075
{
    class Bugged
    {
        public static void Main()
        {
            var n = int.Parse(ReadLine().Trim());
            var scores = (new int[n]).Select(i => int.Parse(ReadLine().Trim())).ToArray();
            var others = scores.Where(i => i % 10 != 0).OrderBy(i => i).ToArray();
            if (others.Length == 0) WriteLine(0);
            else if (others.Sum() % 10 == 0) WriteLine(scores.Sum() - others[0]);
            else WriteLine(scores.Sum());
        }
    }
}


Measured memory_bytes: 13524
n = int(input())
v_list = list(map(int, input().split(" ")))
c_list = list(map(int, input().split(" ")))
total = 0
for i in range(n):
    if v_list[i] < c_list[i]:
        continue
    total += v_list[i] - c_list[i]
print(total)

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<functional>

using namespace std;

char s[210];

int main()
{
	scanf("%[^\n]", s);
	for (int i = 0; i < strlen(s); i++) {
		printf("%c",toupper(s[i]));
	}
	printf("\n");

	
	return 0;
}

Measured memory_bytes: 3168
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int main()
{
  int H, W;
  int h, w;

  cin >> H >> W >> h >> w;

  cout << H * W - ((H * w + W * h) - h * w) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,k,a[2000005],b[2000005],st[2000005],top,tmp[2000005],num;
char s[1000005];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)a[i]=s[n-i+1]-'0';
	scanf("%s",s+1);
	for(int i=1;i<=m;i++)b[i]=s[m-i+1]-'0';
	n=max(n,m)+k;
	for(int i=n;i>=1;i--)
	{
		if(a[i]&&b[i])
		{
			a[i]=b[i]=0;
			int s=i;
			while(1)
			{
				if(!top||st[top]-s>k)
				{
					a[s+k]=b[s+k]=1;
					break;
				}
				int p=st[top--];
				if(a[p])
				{
					b[p]=1;
					tmp[++num]=p;
					while(a[p]==1)a[p++]=0,s++;
					a[p]=1;
					while(top&&st[top]<p)top--;
					if(!b[p])
					{
						st[++top]=p;
						break;
					}
					else top--,a[p]=b[p]=0;
				}
				else
				{
					a[p]=1;
					tmp[++num]=p;
					while(b[p]==1)b[p++]=0,s++;
					b[p]=1;
					while(top&&st[top]<p)top--;
					if(!a[p])
					{
						st[++top]=p;
						break;
					}
					else top--,a[p]=b[p]=0;
				}
			}
			while(num)st[++top]=tmp[num--];
		}
		else if(a[i]||b[i])st[++top]=i;
	}
	m=n;
	while(a[n]==0)n--;
	while(b[m]==0)m--;
	for(int i=n;i>=1;i--)printf("%d",a[i]);
	printf("\n");
	for(int i=m;i>=1;i--)printf("%d",b[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 21504
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


Int calc(Int x){
  Int res = 0;
  for(Int i=1;i<=x;i++) res+= i;
  return res;
}
signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  Int a, b;
  cin>>a>>b;
  
  Int ans = calc(b - a - 1) - a;
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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 upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

/*nCk*/
ll nckused[1000][1000];
ll nckreached[1000][1000];
ll comb(ll n,ll k){
    if(n>1000) return (k==0 || k==n)?1:comb(n-1,k-1)+comb(n-1,k);
    if(nckreached[n][k]==1) return nckused[n][k];
    nckreached[n][k] = 1;
    nckused[n][k] = (n==1 || (k==0 || k==n) )?1:comb(n-1,k-1)+comb(n-1,k);
    return (n==1 || (k==0 || k==n) )?1:comb(n-1,k-1)+comb(n-1,k);
}

int main(void){
    // char ;
    ll n,k,ans=0;
    scanf("%lld%lld",&n,&k);
    // ll [n];
    if(k==1){
        printf("%lld",POW(n,3));
        return 0;
    }
    if(k%2){
        ans+=POW(n/k,3);
    }else{
        ans+=POW(n/k,3)+POW( (n+k/2)/k ,3 );
    }
    // ll c=k;

    // if()

    // while(c<=2*n){
    //     if(c%2){
    //         ans+=POW(n/c,3);
    //     }else{
    //         ll half=(n-k/2)/k,zero=n/c;
    //         ans+=POW(half,3)+POW(zero,3);
    //     }
    //     // c+=k;
    // }
    // while(c<=n){
    //     if(c)
    // }
    // rrep(i,n,1){
    //     if(i+n<k) break;
    //     ll c=1;
    //     c+=(n-i)/k;
    //     if(2*i%k==0){
    //         ans+= 1 + 3*(c-1)*2 +  ( c>2 ? 6*comb(c-1,2) : 0 ) ;
    //     }else{
    //         ans+= ( c>1 ? 6*comb(c,2) : 0 ) + 3*c;
    //     }
    //     printf("%lld ",ans);
    // }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
a = int(input())
b = int(input())
c = int(input())
x = int(input())

t = 0
for i in range(0,a+1):
    if x < 500*i:
        break
    for j in range(0,b+1):
        if x < 500*i + 100*j:
            break
        if x - 500*i - 100*j <= 50* c:
            t = t + 1
print(t)

Measured memory_bytes: 3060
//デバッグ消し忘れ
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;

int a, b;

int main(){
  cin >> a >> b;
  int a1, a2, b1, b2;
  a1 = ceil(12.5 * a);
  a2 = ceil(12.5 * (a + 1)) - 1;
  b1 = ceil(10 * b);
  b2 = ceil(10 * (b + 1)) - 1;
  //cout << a1 << " " << a2 << " " << b1 << " " << b2 << endl;
  int res = max(a1, b1);
  if(a1 > b2 || b1 > a2) res = -1;
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
n, k, q = map(int, input().split())
point = [k-q] * n

for i in range(q):
    a = int(input())
    point[a-1] = point[a-1] + 1

ans = '\n'.join('Yes' if i > 0 else 'No' for i in point[0:])
print(ans)

Measured memory_bytes: 7396
#include <iostream>
#include <stdio.h>

int main()
{
  int i,j;
  char word[12];

  for(i=0; i<3; i++){
    for(j=0; j<4; j++){
      scanf("%c",&word[3*i+j]);
    }
  }

  for(i=0; i<3; i++){
    for(j=0; j<3; j++){
      if(i==j)
        printf("%c",word[3*i+j]);
    }
  }

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
string a, x, b[2] = {"C", "F"};
int v = 0, z = 0;
int main()
{
	cin >> a;
	for(int i = 0; i < a.size(); i++)
	{
		x = a.substr(i, 1);
		if(x == b[v]) v++;
		if(v == 2) {
			z = 1;
			break;
		}
	}
	if(z == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
using namespace literals;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int K, X;
  cin >> K >> X;
  cout << (500 * K >= X ? "Yes" : "No") << endl;
}


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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

template<typename T> void drop(T x){cout<<x<<endl;exit(0);};
struct UnionFind{
  int num;
  vector<int> r, p;
  UnionFind(){}
  UnionFind(int n):num(n), r(n, 1), p(n, 0){iota(p.begin(), p.end(), 0);}

  int find(int x){
    return (x == p[x]? x:p[x] = find(p[x]));
  }

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

  void unite(int x,int y){
    x = find(x), y = find(y);
    if(x == y) return;
    if(r[x] < r[y]) swap(x, y);
    r[x] += r[y];
    p[y] = x;
    num--;
  }

  int size(int x){
    return r[find(x)];
  }

  int count()const{
    return num;
  }
};


struct BiMatch{
  int n, time;
  vector<vector<int> > G;
  vector<int> match, used, dead;

  BiMatch(){}
  BiMatch(int n):n(n), time(0), G(n), match(n, -1), used(n, -1), dead(n, 0){}

  void add_edge(int u, int v){
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  int dfs(int v){
    used[v] = time;
    for(int u:G[v]){
      if(dead[u]) continue;
      int w = match[u];
      if((w < 0) || (used[w]<time && !dead[w] && dfs(w))){
        match[v] = u;
        match[u] = v;
        return 1;
      }
    }
    return 0;
  }

  int build(){
    int res = 0;
    for(int v=0;v<n;v++){
      if(dead[v]) continue;
      if(match[v] < 0){
        time++;
        res += dfs(v);
      }
    }
    return res;
  }
};


signed main(){
  int n,m;
  cin>>n>>m;
  BiMatch bm(n*2);
  vector<int> xs(m),ys(m);
  for(int i=0;i<m;i++) cin>>xs[i]>>ys[i];

  vector< vector<int> > G(n*2);
  for(int i=0;i<m;i++){
    xs[i]--;ys[i]--;

    G[0+xs[i]].emplace_back(i);
    G[n+ys[i]].emplace_back(i);

    bm.add_edge(0+xs[i],n+ys[i]);
  }

  UnionFind uf(m);
  for(int i=0;i<n*2;i++)
    for(int v:G[i])
      uf.unite(G[i][0],v);

  cout<<m-bm.build()<<" "<<m-uf.count()<<endl;
  return 0;
}



Measured memory_bytes: 3248
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
z=[]
m=[]
for i in range(h):
  for j in range(w)[::(-1)**i]:
    m.append((i,j))
for i in range(h*w-1):
  x,y=m[i]
  if a[x][y]%2:
    X,Y=m[i+1]
    z.append([x+1,y+1,X+1,Y+1])
    a[X][Y]+=1
print(len(z))
for i in z:
  print(*i)

Measured memory_bytes: 51960
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define mod 1000000007
ll F[100010];

void fact(void){
    F[0] = 1;
    F[1] = 1;
    for( int i = 2; i < 100010; i++){
        F[i] = (F[i-1] * i) % mod;
    }
}

int main(void)
{
    fact();
    int N,M;
    cin >> N >> M;
    if(abs(N-M) > 1){
        cout << 0;
        return 0;
    }
    ll ans;
    if( (N+M) % 2 == 0){
        ans = F[N] * F[M] * 2;
    }else{
        ans = F[N] * F[M];
    }
    cout << ans % mod;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = ~(1 << 31);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    char c;
    rep(i, a){
        cin >> c;
        if(c < '0' || c > '9'){
            no;
            return 0;
        }
    }
    cin >> c;
    if(c != '-'){
        no;
        return 0;
    }
    rep(i, b){
        cin >> c;
        if(c < '0' || c > '9'){
            no;
            return 0;
        }
    }
    yes;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 2e5+5;
const int mod = 1e9+7;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    int k,n=s.size();
    cin>>k;
    if(k==1) {
        int ans = 0;
        for(int i=1;i<n;i++)
            if(s[i]==s[i-1]) {
                s[i] = '$';
                ans++;
            }
        cout<<ans;
    }
    else {
        int all_same = 1;
        for(int i=1;i<n;i++)
            all_same &= (s[i]==s[i-1]);
        if(all_same) {
            cout<<(n*1LL*k)/2;
            return 0;
        }


        int l = 1;
        while(s[l]==s[l-1])
            l++;
        int r = 1;
        while(s[n-r]==s[n-r-1])
            r++;
        if(s[0]==s[n-1]) {
            s = s.substr(l,n-l-r);
            n -= l+r;
        }
        else
            l = 0,r = 0;

        int ans = 0;
        for(int i=1;i<n;i++)
            if(s[i]==s[i-1]) {
                s[i] = '$';
                ans++;
            }
        cout<<ans*1LL*k + l/2 + r/2 + (l+r)/2*1LL*(k-1);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> h(N);
  vector<bool> check(N, true);
  REP(i,N)cin>>h[i];
  for (int i = 0; i < M;i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (h[a] >= h[b]) {
      check[b] = false;
    }
    if(h[a]<=h[b]){
      check[a] = false;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if(check[i])
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4056
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin>>s;
  int sn=s.length();
  int left=0,right=sn-1,ans=0;
  bool flag=true;
  while(left<right){
    if(s[left]==s[right]){
      left++;right--;
    }else{
      if(s[left]=='x'){
        left++;
        ans++;
      }else if(s[right]=='x'){
        right--;
        ans++;
      }else{
        flag=false;
        break;
      }
    }
  }
  if(flag){
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }

}


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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   string s;
   cin >> s;
   int a, b, c, d;
   a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';

   if (a + b + c + d == 7)
   {
      cout << a << '+' << b << '+' << c << '+' << d << '=' << "7\n";
   }
   else if (a + b + c - d == 7)
   {
      cout << a << '+' << b << '+' << c << '-' << d << '=' << "7\n";
   }
   else if (a + b - c - d == 7)
   {
      cout << a << '+' << b << '-' << c << '-' << d << '=' << "7\n";
   }
   else if (a + b - c + d == 7)
   {
      cout << a << '+' << b << '-' << c << '+' << d << '=' << "7\n";
   }
   else if (a - b + c + d == 7)
   {
      cout << a << '-' << b << '+' << c << '+' << d << '=' << "7\n";
   }
   else if (a - b + c - d == 7)
   {
      cout << a << '-' << b << '+' << c << '-' << d << '=' << "7\n";
   }
   else if (a - b - c - d == 7)
   {
      cout << a << '-' << b << '-' << c << '-' << d << '=' << "7\n";
   }
   else if (a - b - c + d == 7)
   {
      cout << a << '-' << b << '-' << c << '+' << d << '=' << "7\n";
   }
}

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

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

int a[200002];
int b[200002];
pii lr[200002];
long long ans;

const int INF = 1000000000;
int main(void){
  int n;
  int mini = INF;
  rep(i,200002)a[i] = INF;
  cin >> n;
  rep(i,n){
    cin >> a[i+1];
    b[a[i+1]] = i+1;
  }
  pair<int,int> dm;
  dm.X = -1;
  dm.Y = -1;
  rep(i,200002)lr[i] = dm;

  //for(int i = 1; i < n+1; ++i){
  //  ans += b[i] * (n-b[i]);
  for(int i = n; i > 0; --i){
    ll pos = b[i];
    ll l = pos-1;
    ll r = pos+1;

    while(0<l && a[l] >= i) l = lr[l].X;
    while(r<=n && a[r] >= i) r = lr[r].Y;
    lr[pos].X = l;
    lr[pos].Y = r;


    ans += (r - pos) * (pos - l) * i;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        char[] s = new char[3000];
        char[] t = new char[3000];
        int n = in.read(s, 0, s.length);
        int m = in.read(t, 0, t.length);
        int[][] dp = new int[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (s[i - 1] == t[j - 1]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }
        char[] ans = new char[dp[n][m]];
        for (int i = n - 1, j = m - 1, k = ans.length; k > 0; ) {
            if (s[i] == t[j]) {
                ans[--k] = s[i];
                i--;
                j--;
            } else if (dp[i + 1][j + 1] == dp[i + 1][j]){
                j--;
            } else {
                i--;
            }
        }
        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 84852
#include <iostream>
#include <vector>
using namespace std;
using pint = pair<int, int>;
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; }

int main() {
    int N, M; cin >> N >> M;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    vector<pint> ins(M);
    for (int i = 0; i < M; ++i) cin >> ins[i].first >> ins[i].second, --ins[i].first;
    
    // prev[i] = マス i-1 と x-1 とが同一区間上になりような x の最大値
    vector<int> prev(N + 1, N + 1);
    prev[N] = N-1;
    for (int i = 0; i < M; ++i) chmin(prev[ins[i].second], ins[i].first);
    for (int i = N - 1; i >= 0; --i) chmin(prev[i], min(prev[i + 1], i - 1));
    
    // 累積 max を用いた DP
    vector<long long> dp(N + 1, 0), maxdp(N + 1, 0);
    for (int i = 1; i <= N; ++i) {
        chmax(dp[i], maxdp[prev[i]] + A[i - 1]);
        chmax(maxdp[i], max(maxdp[i - 1], dp[i]));
    }
    cout << maxdp[N] << endl;
}


Measured memory_bytes: 9612
#include <iostream>
#include <iomanip>
#include <cstdio>
 int main() {
  int a, b;
  std::cin >> a >> b; 
  std::cout << a/b <<std::endl;
  std::cout << a%b <<std::endl;
  double f;
  f = 1.0 * a/b;
  std::cout << std::fixed;
  std::cout << std::setprecision(5) << f <<std::endl;




 return 0;


}


Measured memory_bytes: 3248
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_ARRAY 100

struct Card {
	char suit,value;
};

void bubbleSort(Card *a, int n) {
	bool flag = true;
	while (flag) {
		flag = false;
		for (int j = n - 1; 0 < j; j--) {
			if (a[j].value < a[j - 1].value) {
				Card tmp = a[j];
				a[j] = a[j-1];
				a[j-1] = tmp;
				flag = true;
			}
		}
	}
	return;
}

void selectSort(Card *a, int n) {
	for (int i = 0; i < n; i++) {
		int min_idx = i;
		for (int j = i+1; j < n; j++) {
			if (a[j].value < a[min_idx].value) {
				min_idx = j;
			}
		}
		if (i != min_idx) {
			Card tmp = a[i];
			a[i] = a[min_idx];
			a[min_idx] = tmp;
		}
	}
	return;
}

void outputArray(Card *a, int n) {
	for (int i = 0; i < n; i++) {
		if (i != 0) {
			cout << ' ';
		}
		cout << a[i].suit << a[i].value;
	}
	cout << endl;
	return;
}

bool isStable(Card *c1, Card *c2, int n) {
	for (int i = 0; i < n; i++) {
		if (c1[i].suit != c2[i].suit) {
			return false;
		}
	}
	return true;
}

int main(void) {
	int n = 0;
	Card c1[MAX_ARRAY],	c2[MAX_ARRAY];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c1[i].suit >> c1[i].value;
	}
	for (int i = 0; i < n; i++) {
		c2[i] = c1[i];
	}
	bubbleSort(c1, n);
	selectSort(c2, n);

	outputArray(c1, n);
	cout << "Stable" << endl;
	outputArray(c2, n);
	if (isStable(c1, c2, n)) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include<stdio.h>
#include<algorithm>

int main()
{
    int k,n,res=0;

    scanf("%d%d",&k,&n);

    int arr[n],diff[n];

    for(int i=0;i<n;i++)
        scanf("%d",&arr[i]);

    std::sort(arr,arr+n);

    for(int i=0;i<n-1;i++)
        diff[i]=arr[i+1]-arr[i];

    diff[n-1]=(k-arr[n-1])+arr[0];

    std::sort(diff,diff+n);

    for(int i=0;i<n-1;i++)
        res+=diff[i];

    printf("%d",res);

    return 0;
}


Measured memory_bytes: 1792
#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 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 mp(a,b) make_pair(a,b)

#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 inf = ((1<<30)-1)*2+1 ;
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,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

template<typename T>
bool SuffixErase(T &v,size_t suf){
  if(suf > v.size()) return false;
  for(auto it = v.begin(); it != v.end();){
    if(distance(v.begin(),it) == suf){
      v.erase(it);
      return true;
    }
    else{
      ++it;
    }
  }
  return false;
}

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

bool check(vector<ll> v){
  ll n = 1;
  bool f = false;
  rep(i,v.size()){
    if(!f){
      if(v[i] == n){
        f = true;
        ++n;
      }
      else if(v[i] != 0){
        return false;
      }
    }
    else if(f){
      if(v[i] != n){
        return false;
      }
      ++n;
    }
  }
  return f;
}


bool tnum[1000000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  rep(i,1000){
    tnum[i * (i+1)/2] = true;
  }
  while(cin >> n && n){
    vector<ll> v(n),v2;
    ll sum = 0;
    bool f = false;
    rep(i,n){
      cin >> v[i];
      sum += v[i];
    }
    if(tnum[sum]){
      rep(l,10000){
        if(check(v)){
          cout << l << endl;
          f = true;
          break;
        }
        ll num = 0;
        rep(i,v.size()){
          if(v[i]){
            --v[i];
            ++num;
          }
        }
        v2.clear();
        v2.push_back(num);
        for(int i = v.size()-1; i >= 0 ; --i){
          if(v[i]){
            v2.push_back(v[i]);
          }
        }
        reverse(all(v2));
        v.clear();
        v = v2;
      }
    }
    if(!f)
      cout << -1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int k; cin >> k >> s;
    if (s.length() <= k) {
        cout << s << '\n';
        return 0;
    }

    string t = "...";
    s = s.substr(0, k) + t;
    cout << s << '\n';
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int n, m, x;
    cin >> n >> m >> x;

    int c[n];
    int a[n][m];

    for (int i=0; i<n; i++) {
        cin >> c[i];
        for (int j=0; j<m; j++) {
            cin >> a[i][j];
        }
    }
    int duh = 1;
    int mn = 1e9;

    while (duh < (1<<n)) {
        int cur = 0;
        vector<int> idk(m);
        for (int i=0; i<n; i++) {
            if (duh & (1<<i)) {
                cur += c[i];
                for (int j=0; j<m; j++) {
                    idk[j] += a[i][j];
                }
            }
        }
        bool flag = true;
        for (int i=0; i<m; i++) {
            if (idk[i] < x) flag = false;
        }
        if (flag) {
            mn = min(mn, cur);
        }
        duh++;
    }
    cout << (mn != 1e9 ? mn : -1) << "\n";
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int d, g;
    cin >> d >> g;
    vi p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];
    int ans = INT32_MAX;
    rep(i, 1<<d) {
        int cnt = 0, sum = 0;
        vi q(d);
        q = p;
        rep(j, d) {
            if (i&(1<<j)) {
                cnt += p[j];
                sum += p[j] * (j+1) * 100 + c[j];
                q[j] = 0;
            }
        }
        while (sum < g) {
            int j = d-1;
            while (q[j] == 0) --j;
            ++cnt;
            sum += (j+1) * 100;
            q[j]--;
            if (q[j] == 0) sum += c[j];
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<math.h>
#include<climits>

using namespace std;
typedef unsigned long long ll;

int x[1000002];

int main(){
    memset(x, 0, sizeof(x));
    x[1]=1;
    for(int i=2;i<1000002;i++){
        int t=i;
        if(t%2==0)t/=2;
        if(t%3==0)t/=3;
        if(t%5==0)t/=5;
        if(x[t]==1)x[i]=1;
    }
    for(int i=1;i<1000002;i++){
        x[i]+=x[i-1];
    }
    int m,n;
    while(cin>>m,m){
        cin>>n;
        cout<<x[n]-x[m-1]<<endl;
    }
    
}

Measured memory_bytes: 5072
#include <stdio.h>
#define N 1000000

int main(void)
{   int a,i,sum=0,b[N],j;
    
    
    for(i=0;i<N;i++)
        b[i]=0;
    
    b[1]=1;
    b[0]=1;
    
    for(i=2;i<N;i++)
        if(b[i]==0)
            for(j=i+i;j<N;j+=i)
                b[j]=1;
    while(1)
    {
        sum=0;
        if (scanf("%d",&a) == EOF) {
            break;
        }
        
        for(i=0;i<=a;i++)
            if(b[i]==0)
                sum++;
        
        printf("%d\n",sum);
        
        
        
    }
    return 0;
    
    
}

Measured memory_bytes: 4500
let [|n;m;k|] = stdin.ReadLine().Split() |> Array.map int
let a = stdin.ReadLine().Split() |> Array.map int64
let b = stdin.ReadLine().Split() |> Array.map int64

let suma =
    a
    |> Array.scan (+) 0L

let mutable sumb =
    b
    |> Array.scan (+) 0L

let rec f x j =
    if sumb.[j]<=x then j
    else f x (j-1)

let rec g i j v =
    if i = n+1 then v
    elif suma.[i] > int64(k) then v
    else
        let ib = f (int64(k)-suma.[i]) j
        if ib+i > v then g (i+1) ib (ib+i)
        else g (i+1) ib v

g 0 m 0 |> stdout.WriteLine

Measured memory_bytes: 73480
N = gets.to_i
A = gets.split.map(&:to_i)

hash = {}

A.each do |i|
    unless hash[i]
        hash[i] = 1
        next
    end

    hash[i] += 1
end

ans = 0

uniq_A = A.uniq

uniq_A.each do |i|
    diff = hash[i] - i

    if diff > 0
        ans += [diff, hash[i]].min
    elsif diff < 0
        ans += hash[i]
    end
end

puts ans

Measured memory_bytes: 21508
#include<bits/stdc++.h>
using namespace std;
const int maxn=5*1e5+12345;
int num[maxn];
set<int>s;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&num[i]);
	int max_dep=1;
	for(int i=1;i<=n;i++){
		if(s.count(0)>=1){
			printf("No\n");
			continue;
		}
		int tmp_num=num[i];
		while(s.count(max_dep)){
			max_dep++;
		}
		if(max_dep-1<tmp_num){
			printf("Yes\n");
		}
		else if(max_dep-1>tmp_num){
			printf("No\n");
			continue;
		}
		else if(max_dep-1==tmp_num){
			if(s.size()!=max_dep-1){
				printf("No\n");
				continue;
			}
			else {
				printf("Yes\n");
			}
		}
		while(s.count(tmp_num))s.erase(tmp_num--);
		s.insert(tmp_num);
	}
}

Measured memory_bytes: 16768
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    return res;
}
 
int main(){
  
    ll N;
    cin >> N;
 
    ll ans = 0;
    auto divY = divisor(N-1);
    ans += divY.size() - 1;
    auto divX = divisor(N);
    for(auto&& x : divX){
        if(x == 1) continue;
        ll n = N;
        while(n % x == 0) n /= x;
        if(n % x == 1)
            ans++;
    }
    cout << ans;
  
    return 0;
}

Measured memory_bytes: 384
# n=int(input())
n,k=list(map(int,input().split(" ")))
a=list(map(int,input().split(" ")))
mat=[]
a=list(set(a))
res=["L"]*(k+1)
z=min(a)
for i in range(1,k+1):
	if(i in a):
		# print("lol",i)
		res[i]="W"
	else:
		flag=False
		for j in range(len(a)):
			# print(i,k-a[j],res[k-a[j]])
			# print(a)
			if((i-a[j])>=0 and res[i-a[j]]=="L" and i>=z):
				# print(i,k-a[j])
				flag=True
				break
		if(flag==True):
			# print(i,"lllllllllll")
			res[i]="W"
# print(res)
if(res[k]=="W"):
	print("First")
else:
	print("Second")




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

int main(){
    int N; cin >> N;

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

    ll ans = 0;
    ll count = 0;
    for(int i = 1; i < N; i++){
        if(s[i] == s[i - 1]){
            count++;
            ans += count;
        }else{
            count = 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int num[100];
int p,n;
long long C(int n,int m)
{
    if(n<m) return 0;
    long long ans=1;
    for(int i=0;i<m;i++) ans=ans*(long long)(n-i)/(long long)(i+1);
    return ans;
}
long long A(int n,int m)
{
    if(n<m) return 0;
    long long ans=1;
    for(int i=0;i<m;i++) ans*=(long long)(n-i);
    return ans;
}
int main(){

    int Numz=0;
    int Numo=0;
    cin>>n>>p;
    for(int i=1;i<=n;i++){
        cin>>num[i];
        num[i]%=2;
        if(num[i]==0){
            Numz++;
        }else{
            Numo++;
        }
    }
    long long ans=0;
    if(p==0){
        for(int i=0;i<=Numz;i++){
            long long pos=C(Numz,i);
            for(int j=0;j<=Numo;j+=2){
                long long base=C(Numo,j);
                ans+=(pos*base);
            }
        }
        cout<<ans<<endl;
    }else if(p==1){
        for(int i=0;i<=Numz;i++){
            long long pos=C(Numz,i);
            for(int j=1;j<=Numo;j+=2){
                long long base=C(Numo,j);
                ans+=(pos*base);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  bool takahashi_tarn = true;
  while ( a > 0 && c > 0 ) {
    if ( takahashi_tarn ) {
      c -= b;
    } else {
      a -= d;
    }
    takahashi_tarn = ! takahashi_tarn;
  }
  string ans = ( c <= 0 ) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	string S;
	cin >> S;
	int N =S.length();
	int minp =N;
	for(int l =1; l < N; l++) if(N%l == 0) {
		bool bad =true;
		for(int i =0; i < N; i++) if(S[i] != S[i%l]) bad =false;
		if(bad) {minp =l; break;}
		}
	if(minp == N) {
		cout << "1\n1\n";
		return 0;}
	if(minp == 1) {
		cout << N << "\n1\n";
		return 0;}
	cout << "2\n";
	long long mod =1000000007, p =2641;
	vector<long long> H(N+1,0),pp(N+1,1);
	for(int i =0; i < N; i++) {
		H[i+1] =(H[i]*p+S[i]-'a')%mod;
		pp[i+1] =(pp[i]*p)%mod;}
	vector<int> badl(N,0),badr(N,0);
	for(int l =1; l < N; l++) {
		int a =l; // [a..a+l)
		long long H0 =H[l];
		while(a+l <= N) {
			long long H1 =(H[a+l]-pp[l]*H[a])%mod;
			if((H1-H0)%mod != 0) break;
			badl[a+l-1] =1;
			a +=l;}
		}
	for(int l =1; l < N; l++) {
		int a =N-l*2;
		long long H0 =(H[N]-pp[l]*H[N-l])%mod;
		while(a >= 0) {
			long long H1 =(H[a+l]-pp[l]*H[a])%mod;
			if((H1-H0)%mod != 0) break;
			badr[a] =1;
			a -=l;}
		}
	int ans =0;
	for(int i =0; i < N-1; i++) if(badl[i] == 0 && badr[i+1] == 0) ans++;
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 12572
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }


int main(){
    int N; cin >> N;
    vector <ll> X(N);
    rep(i,N) cin >> X[i];
    
    vector <ll> Y=X;
    sort(Y.begin(),Y.end());
    rep(i,N){
        if (X[i]<Y[N/2]) cout << Y[N/2] << endl;
        else cout << Y[N/2-1] << endl;
    }
    return 0;
    
    
    
}

Measured memory_bytes: 5376
#include <stdio.h>
int main(){
	int n;
	int a, b, c;
	scanf("%d", &n);
	a=n%60;
	b=((n-a)/60)%60;
	c=((n-(b*60)-a)/3600)%60;
	printf("%d:%d:%d\n", c, b, a);
	return 0;
}



Measured memory_bytes: 1808
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

set<int> s;

// aとbの最大公約数を求める関数
template <class T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

// 約数を列挙する関数
bool CalcDivisor(int n) {
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != 1 && s.count(i))
        return false;
      s.insert(i);
      if (i * i != n) {
        if (n / i != 1 && s.count(n / i))
          return false;
        s.insert(n / i);
      }
    }
  }
  return true;
}

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

  int all_gcd = a[0];
  rep(i, n - 1) { all_gcd = gcd(all_gcd, a[i + 1]); }

  bool is_pair_prime = true;
  rep(i, n) {
    bool is_ok = CalcDivisor(a[i]);
    if (!is_ok) {
      is_pair_prime = false;
      break;
    }
  }

  if (all_gcd == 1) {
    if (is_pair_prime) {
      cout << "pairwise coprime" << endl;
    } else {
      cout << "setwise coprime" << endl;
    }
  } else {
    cout << "not coprime" << endl;
  }
  return 0;
}


Measured memory_bytes: 7316
#include<stdio.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

/*
	入力例：
	3
	1 1 3
*/

int main(){
	long L=0;
	long R=0;
	long d=0;
	long p,e,z;
	long iResult=0;
	scanf("%ld %ld %ld", &L,&R,&d);
	long iCnt;
	iCnt=0;
	for(long i=L;i<=R;i++){
		if (i%d==0){
			iCnt++;
		}
	}
	printf("%ld\n",iCnt);
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1000000007;

vector<ll> fac(20001); //n!(mod M)
vector<ll> ifac(20001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main(){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0;i < 20000;i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    ll n,k;
    ll ans;
    cin >> n >> k;
    ll r = n-k;
    for(ll i = 1;i <= k;i++){
        ans = 0;
        if(r+1 < i)cout << 0 << endl;
        else if(i == 1)cout << r+1 << endl;
        else{
            ll t = 0;
            ans += comb(k-1,k-i)% M;
            for(ll j = -1;j <= 1;j++){
                if(r-1 >= r-i-j && r-i-j >= 0)t += comb(r-1,r-i-j) % M;
                if(r-1 >= r-i-j && r-i-j >= 0 && j == 0)t += comb(r-1,r-i-j) % M;
            }
            ans *= (t % M);
            ans %= M;   
            cout << ans << endl;
        }
    }
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
  ll n, m, sum;
  cin >> n;
  vecll t(n);
  forll(i, 0, n){
	cin >> t[i];
	sum += t[i];
  }
  
  cin >> m;
  vecll p(m);
  vecll x(m);
  forll(i, 0, m)
	cin >> p[i] >> x[i];
  forll(i, 0, m)
	cout << sum - t[p[i] - 1] + x[i] << endl;
}

Measured memory_bytes: 256