akhauriyash/Code-Regression huggingface dataset:
object Main extends App {
  val n = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  val Array(a, b) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  val p = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList

  println(List(p.count(_ <= a), p.count(i => i > a && i <= b), p.count(b < _)).min)
}


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

int main() {
	int n,w;cin>>n>>w;
	long long val[n];int wt[n];
	for(int i=0;i<n;i++){cin>>wt[i]>>val[i];}
	long long dp[n+1][w+1];
	for(int sz=0;sz<=n;sz++){
	    for(int we=0;we<=w;we++){
	        if(sz==0 || we==0){dp[sz][we]=0;}
	        else if(we>=wt[sz-1]){
	            dp[sz][we]=max(dp[sz-1][we],val[sz-1]+dp[sz-1][we-wt[sz-1]]);
	        }
	        else{dp[sz][we]=dp[sz-1][we];}
	    }
	}
	//for(int i=0;i<=n;i++){for(int j=0;j<=w;j++){cout<<dp[i][j]<<" ";}cout<<endl;}
	cout<<dp[n][w];
	return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;


int main(){
    string S;
    cin >> S;
    for(int i = 0;i<3;i++){
        if(S.at(i) == '1'){
            S.at(i) = '9';
          	continue;
        }
        if(S.at(i) == '9'){
            S.at(i)= '1';
          	continue;
        }
    }
    cout << S << endl;
}

Measured memory_bytes: 256
/**
*    created: 01.07.2020 21:46:09
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const int MOD = 1000000007;
// const int MOD = 998244353;
const long double pi = acos(-1.0);
const int INF = 1LL << 60;

signed main() {

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(rall(a));
    int asum = 0;
    int bsum = 0;
    rep(i,n) {
        if (i % 2 == 0) asum += a[i];
        else bsum += a[i];
    }
    cout << asum - bsum << endl;
    return 0;
}

Measured memory_bytes: 3732
N, M = map(int, input().split())
vote_nums = sorted([float(i) for i in input().split()], reverse=True)
 
border_rate = 1 / (4 * M)
target = vote_nums[:M]
 
for vote_num in target:
  if vote_num < border_rate * sum(vote_nums):
    print('No')
    exit()
 
print('Yes')

Measured memory_bytes: 3060
n = int(input())
ws = list(map(int, input().split(" ")))
s1 = 0
s2 = sum(ws)
md = 9999999999999999999999999999
for w in ws:
    s1 += w
    s2 -= w
    if abs(s1 - s2) < md:
        md = abs(s1 - s2)
print(md)


Measured memory_bytes: 2940
from heapq import heappush, heappop

def main():
  while True:
    x, y, z = map(int, input().split())
    if x == 0:break
    vlst = list(map(int, input().split()))
    events = {}
    for _  in range(z):
      n, e, a = map(int, input().split())
      events[n] = (e, a)
    
    que = []
    heappush(que, (0, 0))
    cnt = [[0] * (100 * y + 1) for _ in range(y + 1)]
    init = x ** y
    cnt[0][0] = init
    visited = {}
    while que:
      pos, score = heappop(que)
      for v in vlst:
        new_pos = pos + v
        new_score = score
        if new_pos in events:
          event, value = events[new_pos]
          if event == 1:
            new_pos += value
          elif event == 2:
            new_score += value
          else:
            new_score = max(new_score - value, 0)
        if new_pos >= y:
          cnt[y][new_score] += cnt[pos][score] // x
        else:
          cnt[new_pos][new_score] += cnt[pos][score] // x
          if (new_pos, new_score) not in visited:
            visited[(new_pos, new_score)] = True
            heappush(que, (new_pos, new_score))
    
    total = 0
    for score in range(100 * y + 1):
      total += cnt[y][score] * score
    print(total // init)

main()


Measured memory_bytes: 12632
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N = int(input())
p = inputlist()
pa = p[:]
pa.sort()
count = 0
for i in range(N):
    if p[i] != pa[i]:
        count+=1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")

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

long long H, W, fact[1 << 18], factinv[1 << 18], mod = 1000000007;

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 31; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long Div(long long a, long long b, long long m) {
	return (a * modpow(b, m - 2, m)) % m;
}

void init() {
	fact[0] = 1;
	for (int i = 1; i <= 200000; i++) fact[i] = (1LL * fact[i - 1] * i) % mod;
	for (int i = 0; i <= 200000; i++) factinv[i] = Div(1, fact[i], mod);
}

long long ncr(long long n, long long r) {
	if (n < r || r < 0) return 0;
	return (fact[n] * factinv[r] % mod) * factinv[n - r] % mod;
}

int main() {
	cin >> H >> W; init();
	long long p = 1, q = (mod + 1) / 2;
	for (int i = 1; i <= H + W; i++) {
		p *= 2; p %= mod;
		long long c1 = Div(ncr(i - 2, H - 1), p, mod);
		long long c2 = Div(ncr(i - 2, W - 1), p, mod);
		
		q += (c2 - c1); q += mod * mod; q %= mod;
		cout << q << endl;
	}
	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int a,b,c,d,temp,counter=0;
  
  for(int i = A; i<B+1; i++){
    a = i/10000;
    temp = i%10000;
    b = temp / 1000;
    temp %= 1000;
    temp %= 100;
    c = temp / 10;
    d = temp % 10;
    if(a==d && b==c)
      counter++;
  }

  cout << counter<<endl;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll h,a;cin >>h>>a;
    ll ans;
    ans=(h-1)/a+1;
    cout <<ans <<endl;
    return 0;
}



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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int A[(1 << 18) + 1];
P top2[1 << 18];

P merge(P p, P q){
    int i1, i2, j1, j2;
    std::tie(i1, i2) = p;
    std::tie(j1, j2) = q;

    if(i1 == j1){
        return std::make_tuple(i1, A[i2] >= A[j2] ? i2 : j2);
    }

    if(A[i1] >= A[j1]){
        return std::make_tuple(i1, A[i2] >= A[j1] ? i2 : j1);
    }

    return std::make_tuple(j1, A[i1] >= A[j2] ? i1 : j2);
}

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

    scanf("%d", &N);

    for(int i=0;i<(1<<N);++i){
        scanf("%d", A + i);
    }

    A[1 << N] = -1;
    top2[0] = std::make_tuple(0, 1 << N);

    int mx = 0;

    for(int i=1;i<(1<<N);++i){
        top2[i] = std::make_tuple(i, 1 << N);

        for(int j=0;j<N;++j){
            if(i >> j & 1){
                top2[i] = merge(top2[i], top2[i ^ (1 << j)]);
            }
        }

        int i1, i2;
        std::tie(i1, i2) = top2[i];
        
        mx = std::max(mx, A[i1] + A[i2]);

        printf("%d\n", mx);
    }
}


Measured memory_bytes: 6144
n, y = gets.split.map(&:to_i)
flag = false
catch(:break_loop) do
  (n+1).times do |i|
    (n+1).times do |j|
      k = n - i - j
      if 10000 * i + 5000 * j + 1000 * k == y && k >= 0
        puts "#{i} #{j} #{k}"
        flag = true
        throw :break_loop
      end
    end
  end
end
puts "-1 -1 -1" unless flag

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

using namespace std;

#define ll long long int

int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
              ll i,j,n,m,coun=0,flag,x,y;
  cin>>n>>m;
  vector<ll>H(n+1);
  vector<vector<ll>>A(n+1);
  map<pair<ll,ll>,ll>mp;
  for(i=1;i<=n;i++)
  {
    cin>>H[i];
  }
  for(i=0;i<m;i++)
  {
    cin>>x>>y;
    if(mp[{x,y}]==0 && mp[{y,x}]==0)
    {
      A[x].push_back(y);
      A[y].push_back(x);
      mp[{x,y}]=1;
      mp[{y,x}]=1;
    }
  }
  for(i=1;i<=n;i++)
  {
    if(A[i].size()==0)
    {
      coun++;
      continue;
    }
    flag=0;
    for(j=0;j<A[i].size();j++)
    {
      if(H[i]<=H[A[i][j]])
      {
        flag=1;
        break;
      }
    }
    if(flag==0)
      coun++;
  }
  cout<<coun;
              return(0);
}


Measured memory_bytes: 22436
function Main(input) {
  input = input.split("\n");
  var A = parseInt(input[0].split(" ")[0]);
  var B = parseInt(input[0].split(" ")[1]);
  var ans =0;
  if(A-B>=1){
    ans=A*2-1;
  }else if(B-A>=1){
    ans=B*2-1;
  }else{
    ans=Math.max(A,B)*2;
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7496
#include<bits/stdc++.h>
using namespace std;
int n,a[2][3],b[3];
long long solve(int n, int p){
	vector<long long> dp(n+1);
	for(int i=1;i<=n;++i) for(int j=0;j<3;++j)
		if(a[p][j] < a[!p][j] && i-a[p][j]>=0) 
			dp[i] = max(dp[i],a[!p][j]-a[p][j]+dp[i-a[p][j]]);
	return dp[n] + n;
}
int main(){
	cin>>n;
	for(int j=0;j<2;++j) for(int i=0;i<3;cin>>a[j][i++]);
	cout<<solve(solve(n,0),1);
}


Measured memory_bytes: 195584
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  int n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;++i)
    cin>>a[i];
  sort(a,a+n);
  ll sum=0;
  sum += a[n-1];
  ll temp = 0,cnt=0,j=n-2;
  int i=n-3;
  while(i>=0)
  {
    temp = a[j];
    sum += temp;
    cnt++;
    if(cnt==2)
    {
      cnt=0;
      j--;
    }
    i--;
  }
  cout<<sum;
}


Measured memory_bytes: 5124
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	ll A,B,C,D;
	cin >> A >> B >> C >> D;

	ll taka = C / B + 1;
	ll aoki = A / D + 1;
	if (C%B == 0) {
		taka = C / B;
	}
	if (A%D == 0) {
		aoki = A / D;
	}

	if (taka <= aoki) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 3648
n=int(input())
a=list(map(int,input().split()))
if n==0:
  if a[0]==1:
    print(1)
    exit()
  else:
    print(-1)
    exit()
if a[0]>0:
  print(-1)
  exit()

ans=1
pre_no_ha=1
all_ha=sum(a)

for ai in a[1:]:
  if pre_no_ha<=0:
    print(-1)
    exit()
  if ai>pre_no_ha*2:
    print(-1)
    exit()
  
  pre_no_ha*=2
  pre_no_ha-=ai
  all_ha-=ai
  pre_no_ha=min(pre_no_ha,all_ha)
  ans+=pre_no_ha+ai

print(ans)

Measured memory_bytes: 20024
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int n;
vi W;
int T[12];
void reku(int x)
{
    if(x>n)
    {
        for(auto v:W)
            cout<<(char)(v+96);
        cout<<"\n";
        return;
    }
    for(int i=1;i<=n;i++)
    {
        T[i]++;
        W.pb(i);
        reku(x+1);
        W.pop_back();
        T[i]--;
        if(!T[i])
            break;
    }
}
int main()
{
    speed
    cin>>n;
    reku(1);
    return 0;
}


Measured memory_bytes: 1536
s = int(input())
a = [s]
ans = 0
for i in range(1000000):
    if a[i] % 2 == 0:
        if a[i]/2 in a:
            ans = i + 2
            break
        a.append(a[i]/2)
    else:
        if 3*a[i] + 1 in a:
            ans = i + 2
            break
        a.append(3*a[i] + 1)
print(ans)

Measured memory_bytes: 9264
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[18][2];
llint dp[1<<18][18][2];
llint pop[1<<18];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i][0];
	for(int i = 0; i < n; i++) cin >> a[i][1];
	
	llint N = 1<<n;
	for(int i = 1; i < N; i++) pop[i] = pop[i&(i-1)] + 1;
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < 2; k++){
				dp[i][j][k] = inf;
			}
		}
	}
	dp[0][0][0] = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < 2; k++){
				llint cnt = 0;
				for(int l = 0; l < n; l++){
					if(i & (1<<l)) continue;
					cnt++;
					llint dif = (pop[i]+l)%2, px = a[j][k], nx = a[l][dif];
					//cout << i << " " << j << 2 " << k << endl;
					if(i != 0 && nx < px) continue;
					dp[i|(1<<l)][l][dif] = min(dp[i|(1<<l)][l][dif], dp[i][j][k] + cnt-1);
				}
			}
		}
	}
	
	llint ans = inf;
	for(int j = 0; j < n; j++){
		for(int k = 0; k < 2; k++){
			ans = min(ans, dp[N-1][j][k]);
		}
	}
	if(ans > inf/2) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 76032
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { string s;
  cin >> s;
  if(s=="Sunny"){
    puts("Cloudy");
  }else if(s=="Cloudy"){
    puts("Rainy");
  }else{
    puts("Sunny");
  }
}

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

def judge(x):
  if x % 15 == 0:
    return 0
  elif x % 3 == 0:
    return 0
  elif x % 5 == 0:
    return 0
  else:
    return x

l =[]
for i in range(1,N+1):
  l.append(judge(i))
  
print(sum(l))
  


Measured memory_bytes: 33744
#include <iostream>

using namespace std;

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

	char color[n];

	for (int i = 0; i < n; i++){
		cin >> color[i];
	}

	int color_n = 0;

	for (int i = 0; i < n; i++){
		if (color[i] == 'P'){
			color_n ++;
			break;
		}

	}
	for (int i = 0; i < n; i++){
		if (color[i] == 'W'){
			color_n ++;
			break;
		}

	}
	for (int i = 0; i < n; i++){
		if (color[i] == 'G'){
			color_n ++;
			break;
		}

	}
	for (int i = 0; i < n; i++){
		if (color[i] == 'Y'){
			color_n ++;
			break;
		}

	}
	if (color_n == 4)
		cout << "Four" << endl;
	else
		cout << "Three" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll a, b, m; cin >> a >> b >> m;
    vector<long long> ap(a), bp(b);
    rep(i, a) cin >> ap[i];
    rep(i, b) cin >> bp[i];
    ll ans = INFLL;
    rep(i, m){
        ll x, y, c; cin >> x >> y >> c;
        x--; y--;
        chmin(ans, ap[x]+bp[y]-c);
    }
    sort(all(ap));
    sort(all(bp));
    chmin(ans, ap[0]+bp[0]);
    cout << ans << endl;
}

Measured memory_bytes: 1792
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
ans=0
M=A[0]
for i in range(1,N):
    if A[i-1]>A[i]:
        A[i]=M
    else:
        M=A[i]
print(sum(A)-S)



            






    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Measured memory_bytes: 32232
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    S = _S()
    daynum = S.count("R") if S!="RSR" else 1
    print(daynum)

main()



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

int main() {
    string s, t; cin >> s >> t;
    int ans = 1000000000;
    for (int i = 0; i < s.size() - t.size() + 1; i++) {
        int cnt = 0;
        for (int j = 0; j < t.size(); j++) {
            if (s[i+j] != t[j])  cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
const long long INF = 1LL << 60;
const int MOD = 1e9 + 7;

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() {
    
    ll N;
    cin >> N;
    std::vector<ll> A(N);

    rep(i,N){
        cin >> A.at(i);
    }

    std::vector<ll> init(N);

    rep(i,N){
        init.at(i) = -A.at(i)-i;
    }

    sort(init.begin(),init.end());

    ll ans = 0;
    rep(i,N){
        ll key = A.at(i)-i;

        auto iter_lower = lower_bound(init.begin(), init.end(), key);
        auto iter_upper = upper_bound(init.begin(), init.end(), key);

        // インデックスを取得
        long idx_lower = distance(init.begin(), iter_lower);  // vec[idx_lower] = vec[7] = 6
        long idx_upper = distance(init.begin(), iter_upper);  // vec[idx_upper] = vec[8] = 8

        ans += (idx_upper- idx_lower);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6440
//12252024832524
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; 

typedef long long LL;
const int MAXN = 10005;
string a = "ABC",b = "ARC";

int Read()
{
	int x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(int x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(int x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
	if(c >= 0) putchar(c);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	string n;
	cin >> n;
	if(n == a) cout << b;
	else cout << a;
	return 0;
}

Measured memory_bytes: 3040
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def pprint(M):
	for row in M:
		print(row)
	print("~~~")

def main():
	MOD = 10**9 + 7
	n, k = rli()
	A = list(rli())
	dp = [[0 for __ in range(k+1)] for _ in range(n)]
	psums = [[0 for __ in range(k+1)] for _ in range(n)]
	for c in range(min(k+1, A[0] + 1)):
		dp[0][c] = 1
	psums[0][0] = dp[0][0]
	for c in range(1, k+1):
		psums[0][c] = dp[0][c] + psums[0][c-1]
		psums[0][c] %= MOD
	for r in range(1, n):
		for c in range(k+1):
			cutoff = c - A[r] - 1
			dp[r][c] = psums[r-1][c] - (psums[r-1][cutoff] if cutoff >= 0 else 0)
			dp[r][c] %= MOD
		psums[r][0] = dp[r][0]
		for c in range(1, k + 1):
			psums[r][c] = dp[r][c] + psums[r][c-1]
			psums[r][c] %= MOD
	print(dp[n-1][k] % MOD)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 288764
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <numeric>
#include <set>
#include <queue>


#define ll long long

using namespace std;

ll a[600005] = {0};

ll
get(ll l, ll r) {
  ll ret = 0;
  while (l <= r) {
    if (l % 2 == 1) {
      ret = max(a[l], ret);
      l++;
    }

    if (r % 2 == 0) {
      ret = max(a[r], ret);
      r--;
    }

    l /= 2;
    r /= 2;
  }

  return ret;
}

void
update(ll index, ll v) {
  a[index] = v;
  index /= 2;
  while (index > 0) {
    a[index] = max(a[index*2], a[index*2 + 1]);
    index /= 2;
  }
}

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

  ll x;
  for (ll i=0; i<n; i++) {
    cin>>x;

    ll left = max(0ll, x - k);
    ll right = min(300000ll, x + k);
    //printf("get (%lld, %lld\n", left, right);
    ll ans = get(left + 300001, right + 300001);
    update(x + 300001, ans + 1);
  }

  ll ans = 0;
  for (ll i=0; i<=300000; i++)
    ans = max(a[i + 300001], ans);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 8324
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <algorithm>
#include <map>

using namespace std;
int a[10];

int main(){

    int n;
    cin >> n;
    for (int j = 0; j < n; ++j) {
        cin >> a[j];
    }
    sort(a, a + n);
    int sum = 0;
    for(const int& i : a){
        sum += i;
    }
    sum -= a[n - 1];
    if(sum > a[n - 1]) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main()
{
	char a[3];

	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}

	if(a[1] == 'R'){

		cout << "ABC";
	}
	else {
		cout << "ARC";
	}

}

Measured memory_bytes: 3632
n = int(input())
A = list(map(int, input().split()))
cnt = {}
for a in A:
    if a-1 not in cnt: cnt[a-1] = 1
    else: cnt[a-1] += 1
    if a not in cnt: cnt[a] = 1
    else: cnt[a] += 1
    if a+1 not in cnt: cnt[a+1] = 1
    else: cnt[a+1] += 1
print(max(cnt.values()))

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

const string S[10] = { "p", "p", "h", "b", "h", "h", "p", "h", "p", "h" };

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

	int id = N % 10;
	string ans = S[id] + "on";

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3564
//Volume2-0226
import java.util.*;

public class Main {

	public static void main(String[] args) {

		//declare
		String[] s;
		int[]    r,
		         a;
		int      hit,
		         blow;
		
		//input
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			s = sc.nextLine().split("\\s");
			if(s[0].equals("0") && s[1].equals("0")){
				break;
			}
			r = chg(s[0]);
			a = chg(s[1]);

			//initialize
			hit  = 0;
			blow = 0;
			
			//calculate
			for(int i=0;i<r.length;i++){
				for(int j=0;j<a.length;j++){
					if(r[i] == a[j]){
						if  (i == j){hit++; }
						else        {blow++;}
					}
				}
			}
			
			//output
			System.out.println(hit + " " + blow);
		}
	}

	//A string is changed into an integer array.
	private static int[] chg(String s){
		
		int[]  ret = new int[s.length()];
		char[] ch  = s.toCharArray();
		
		for(int i=0;i<ch.length;i++){
			ret[i] = Character.digit(ch[i],10);
		}
		return ret;
	}
}

Measured memory_bytes: 60332
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    string S;
    cin >> S;
    S.insert( S.begin() + 4, ' ' );
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,ans;
int a[60],b[60];
bool IsBridge(int i){
  queue<int> q;
  bool r[60]={};
  q.push(a[i]);
  r[a[i]]=true;
  while(q.size()){
    int now=q.front(); q.pop();
    for(int j=0;j<m;j++){
      if(i==j) continue;
      if(a[j]==now&&r[b[j]]==false){
        q.push(b[j]);
        r[b[j]]=true;
      }if(b[j]==now&&r[a[j]]==false){
        q.push(a[j]);
        r[a[j]]=true;
      }
    }
  }
  return !r[b[i]];
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<m;i++)if(IsBridge(i))ans++;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<string.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fr first
#define sc second
#define M_PI           3.14159265358979323846
using namespace std;
int n,m;
int Dp[200200];
int A[100100];
int Solve(int i)
{
    if(i==n-1)
        return 0;
    if(i>n-1)
        return 1e9;
    if(Dp[i]!=1e9)
    return Dp[i];
    for(int k=1; k<=m; k++)
    {
        Dp[i]=min(Dp[i],Solve(i+k)+abs(A[i+k]-A[i]));
    }
    return Dp[i];

}
int main()
{
    Start;

    cin>>n>>m;
    for(int i=0; i<n; i++)
        cin>>A[i];
    for(int i=0;i<n;i++)
        Dp[i]=1e9;
    cout<<Solve(0);
}


Measured memory_bytes: 5760
/*
 *   
 *   Date: 07 September 2019
 *   Time: 01:03:00
*/
import java.io.*; 
import java.util.*;


   
 class Main 
{   
 static boolean check(String str) 
    { 
        long n = str.length(); 
        long digitSum = 0; 
        for (int i=0; i<n; i++) 
            digitSum += (str.charAt(i)-'0'); 
       
        return (digitSum % 9 == 0); 
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         String s=sc.next();
         if(check(s)){
         	System.out.println("Yes");
         }else{
         	System.out.println("No");
         }
        
       

       
    } 
} 
 
 
 


Measured memory_bytes: 40320
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int h[maxn],go[maxn*2],nxt[maxn*2],fa[maxn],d[maxn],a[maxn];
int i,j,k,l,t,n,m,tot,root;
bool czy;
void add(int x,int y){
	d[y]++;
	go[++tot]=y;
	nxt[tot]=h[x];
	h[x]=tot;
}
void dfs(int x,int y){
	if (d[x]==1){
		fa[x]=a[x];
		return;
	}
	int t=h[x];
	fa[x]=2*a[x];
	while (t){
		if (go[t]!=y){
			dfs(go[t],x);
			fa[x]-=fa[go[t]];
		}
		t=nxt[t];
	}
}
void dg(int x,int y){
	if (d[x]==1) return;
	int t,l=0;
	if (fa[x]>a[x]) czy=0;
	else{
		t=h[x];
		while (t){
			if (go[t]!=y){
				if (fa[go[t]]>a[x]-fa[x]) l+=(fa[go[t]]+fa[x]-a[x]);
			}
			t=nxt[t];
		}
		if (l>fa[x]) czy=0;
	}
	t=h[x];
	while (t){
		if (go[t]!=y) dg(go[t],x);
		t=nxt[t];
	}
}
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n-1){
		scanf("%d%d",&j,&k);
		add(j,k);add(k,j);
	}
	if (n==2){
		if (a[1]==a[2]) printf("YES\n");else printf("NO\n");
		return 0;
	}
	fo(i,1,n)
		if (d[i]>1) break;
	root=i;
	dfs(root,0);
	if (fa[root]){
		printf("NO\n");
		return 0;
	}
	czy=1;
	dg(root,0);
	if (czy) printf("YES\n");else printf("NO\n");
}

Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {
  private int happiness500 = 1000;
  private int happiness5 = 5;
  
  public int numOf500(int amount) {
    return amount / 500;
  }
  
  public int numOf5(int amount) {
    return (amount % 500) / 5;
  }
  
  public int calcHappiness(int largeMedal, int smallMedal) {
    return largeMedal * happiness500 + smallMedal * happiness5;
  }
  
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    Main obj = new Main();
    
    int amount = Integer.parseInt(scnr.nextLine());
    
    System.out.println(obj.calcHappiness(obj.numOf500(amount), 
                                         obj.numOf5(amount)));
  }
}

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

int main(){
    //char S[101] = {"A"};
    int k;
    cin >> k;
    string A;
    cin >> A;

    if(A.length() <= k){
        cout << A << endl;
    } else {
        for(int i = 0; i < k; i++){
            cout << A[i];}
        cout << "..." << endl;
        
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <iomanip>


using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
// #define req(j, n) for (ll j = 1; j < (n+1); j++)
// #define rer(k, n) for (ll k = 1; k < (n+1); k++)


int main()
{
    double a,b,h,m;
    double menseki;
    double pi = 3.141592653589793238;
    double chou;
    cin >> a >> b >> h >> m;
    double ji, hun;
    ji = h * 30 + 0.5 * m;
    hun = m * 6;
    double rad;
    rad = abs(ji - hun);
    if (rad > 180.0) {
        rad = 360.0 - rad;
    }
    chou = sqrt(a * a + b * b - 2 * a * b * cos(rad/180.0 * pi));
    cout << fixed << setprecision(20) << chou << endl;
}

Measured memory_bytes: 4292
#include <iostream>

int main()
{
    using namespace std;
    string o, e;
    cin >> o;
    cin >> e;
    
    int32_t len = o.length() + e.length();
    
    for (auto j = 0; j < len; ++j) {
        if (j % 2 == 0) {
            cout << o[j/2];
        } else {
            cout << e[j/2];
        }
    }
    cout << endl;
}

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

#ifdef WINT_MIN
#define __MAI
#endif

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007ll
void printbit(int u) { if (u == 0)cout << 0; else { int s = 0, k = 0; for (; 0<u; u >>= 1, k++)s = (s << 1) | (u & 1); for (; 0<k--; s >>= 1)cout << (s & 1); } }template<typename T1, typename T2>
    ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

namespace {
    std::chrono::system_clock::time_point t;
    void tic() { t = TIME; }
    void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - t)); }
    std::chrono::system_clock::time_point tle = TIME;
#ifdef __MAI
    void safe_tle(int msec) { assert(MILLISEC(TIME - tle) < msec); }
#else
#define safe_tle(k) ;
#endif
}

#ifndef __MAI 
namespace {
    class MaiScanner {
    public:
        template<typename T>
        void input_integer(T& var) {
            var = 0;
            T sign = 1;
            int cc = getchar_unlocked();
            for (; cc<'0' || '9'<cc; cc = getchar_unlocked())
                if (cc == '-') sign = -1;
            for (; '0' <= cc&&cc <= '9'; cc = getchar_unlocked())
                var = (var << 3) + (var << 1) + cc - '0';
            var = var*sign;
        }
        void ign() { getchar_unlocked(); }
        MaiScanner& operator>>(int& var) {
            input_integer<int>(var);
            return *this;
        }
        MaiScanner& operator>>(long long& var) {
            input_integer<long long>(var);
            return *this;
        }
    };
}
MaiScanner scanner;
#else
#define scanner cin
#endif

int n, m = 100;

string strs[60];

int cnt[60][128];

int main() {
    ll i, j, k;
    ll x, y, a, b;

    cin >> n;

    for (i = 0; i < n; ++i) {
        cin >> strs[i];
        for (char c : strs[i]) {
            ++cnt[i][c];
        }
    }

    fill(cnt[59], cnt[59] + 128, 12345678);
    for (i = 'a'; i <= 'z'; ++i) {
        for (j = 0; j < n; ++j) {
            cnt[59][i] = min(cnt[59][i], cnt[j][i]);
        }
    }

    for (i = 'a'; i <= 'z'; ++i) {
        while (cnt[59][i]--)
            putchar(i);
    }
    cout << endl;

superb:;




    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;


void main(){
    while(true) {
        auto n = readInt();
        if(n == 0) {
            return;
        }
        auto block = new bool[][](5001, 5);
        foreach(i; iota(n)) {
            int d, p, q;
            readlnTo(d, p, q);
            --q;
            int l = -1;
            foreach(j; iota(q, q + (d == 1 ? p: 1))) {
                foreach(k; iota(5000)) {
                    if(block[k][j]) {
                        l = max(l, k);
                    }
                }
            }
            foreach(j; iota(p)) {
                if(d == 1) {
                    block[l+1][q+j] = true;
                } else {
                    block[l+1+j][q] = true;
                }
            }
            foreach(j; iota(p).retro) {
                if(block[l+1+j].all!(x => x)) {
                    foreach(k; iota(l+1+j, 5000)) {
                        foreach(m; iota(5)) {
                            block[k][m] = block[k+1][m];
                        }
                    }
                }
            }
        }
        writeln(block.map!(a => a.count!(x => x)).sum);
    }
}

Measured memory_bytes: 3320
# 2019/07/25

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

if n==k:
    print(1)
    exit()

one=a.index(1)
ans=float('inf')

for i in range(k):
    l=one
    r=n-one-1

    l-=i
    r-=(k-i-1)
    ans=min(-(-l//(k-1))+-(-r//(k-1))+1,ans)

print(ans)

Measured memory_bytes: 13880
s=input()

#最初が0
ansb=0
for i in range(len(s)):
  if i % 2==0:
    if s[i]=="1":
      ansb+=1
  else:
    if s[i]=="0":
      ansb+=1
#最初が1
answ=0
for i in range(len(s)):
  if i % 2==0:
    if s[i]=="0":
      answ+=1
  else:
    if s[i]=="1":
      answ+=1

print(min(answ,ansb))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  if(a>=1800){
    cout<<1<<endl;
  }else if(a>=1600){
    cout<<2<<endl;
  }else if(a>=1400){
    cout<<3<<endl;
  }else if(a>=1200){
    cout<<4<<endl;
  }else if(a>=1000){
    cout<<5<<endl;
  }else if(a>=800){
    cout<<6<<endl;
  }else if(a>=600){
    cout<<7<<endl;
  }else if(a>=400){
    cout<<8<<endl;
  }
  return 0;
}

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


for h in range(1, 3500):
    for n in range(1, 3500):
        x = 4 * h * n - N * h - N * n
        if x != 0:
            w = N * h * n / (4 * h * n - N * h - N * n)
            if int(w) == w and w > 0:
                print(h, n, int(w))
                exit()


Measured memory_bytes: 73712
//run: g++ -std=c++14 -o run_sol.exe solution.cpp -DLOCAL_JUDGE
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define INFLL 1e17
#define PI 2*acos(0.0)
#define show(x) cout<< #x <<" is "<< x <<"\n"
using namespace std;

#define FS first
#define SC second
#define PB(t) push_back(t)
#define LEN(t) ((int)t.size())
#define ALL(t) t.begin(),t.end()
#define MP(x, y) make_pair((x), (y))
#define Fill(a,c) memset(&a, c, sizeof(a))
#define POPCOUNT __builtin_popcount

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;

int main() {
    #ifdef LOCAL_JUDGE
        freopen("../input.txt", "rt", stdin);
        freopen("../output.txt", "wt", stdout);
    #endif

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

    for (int n, w, wi, vi; cin >> n >> w ; ) {
        VLL dp(w + 1, -1);
        dp[0] = 0;
        LL mx = 0;

        for (int i = 0; i < n; i++) {
            cin >> wi >> vi;

            for (int j = w; j >=0; j--) {
                if (dp[j] >= 0 and j + wi <= w) {
                    dp[j + wi] = max(dp[j + wi], dp[j] + vi);
                    mx = max(mx, dp[j + wi]);
                }
            }
        }
        
        cout << mx << "\n";
    }
    
return 0;
}

Measured memory_bytes: 1024
/*
 * Shubham Jain
 */
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define MOD 10000000009
ll combine(ll a, ll b) {
   ll times = 1;
   while (times <= b)
      times *= 10;
   return a*times + b;
}
bool isPerfectSquare(ll n){
    ll squareRootN=(ll)round((sqrt(n)));

    if(squareRootN*squareRootN == n) {
        return true;
    }
     else {
        return false;
     }
}
int main() {
    ll a,b,n;
    cin>>a>>b;
    n=combine(a,b);
    if(isPerfectSquare(n))
        cout<<"Yes";
    else cout<<"No";
return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
wc = [0]*n
ac = [0]*n
wa = 0
for _ in range(m):
  p,s = input().split()
  if ac[int(p)-1] == 0:
    if s == "AC":
      ac[int(p)-1] = 1
      wa += wc[int(p)-1]
    else:
      wc[int(p)-1] += 1
print("{} {}".format(sum(ac),wa))

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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
  bool a;
  cin>>x;
  for(int i=x;i>0;i++){
    a=IsPrime(i);
    if(a==true){
      cout<<i<<"\n";
      return(0);
    }
  }
}


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

int main()
{
	std::string s;
	std::cin >> s;
	int to{};
	long long count{};
	for (unsigned int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'W')
		{
			count += i - to;
			to++;
		}
	}
	printf("%lld\n", count);

	return 0;
}

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

using namespace std;

long long comb(int n, int k) {
  long long m = 1;
  if(n < 2 * k) {
    k = n - k;
  }
  for(int i = 1; i <= k; i++) {
    m = m * (n - i + 1) / i;
  }
  return m;
}

int main(void) {
  int n, p;
  cin >> n >> p;
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int odd = 0;
  int even = 0;
  for(int i = 0; i < n; i++) {
    if(a[i] % 2 == 0) {
      even++;
    }
    else {
      odd++;
    }
  }
  long long count = 0;
  if(p == 1) {
    for(int i = 1; i <= odd; i += 2) {
      count += comb(odd, i);
    }
    count *= pow(2, even);
  }
  else {
    for(int i = 0; i <= odd; i += 2) {
      count += comb(odd, i);
    }
    count *= pow(2, even);
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long;
using ll = long long;
#define rep(i,n) for(lint (i) = 0;(i) < (lint)(n);(i)++)
#define repInRange(i,start,end) for(lint (i) = (start);(i) < (end);++(i))
#define pb push_back
using Vecint = vector<lint>;

void Main() {
	lint H,N,sum = 0,x;
	cin >> H >> N;
	rep(i,N) {
		x = 0;
		cin >> x;
		sum += x;
	}
	if (sum >= H) {
		cout << "Yes" << '\n';
		return;
	}
	cout << "No" << '\n';
}

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static Node[] nodes;
    public static void main (String[] args) throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(br.readLine());
	nodes = new Node[n];
	for (int i = 0; i < n; i++) {
	    nodes[i] = new Node(i);
	}
	
	String[] input;
	int id, k, childId;
	int[] a;
	for (int i = 0; i < n; i++) {
	    input = br.readLine().split(" ");
	    id = Integer.parseInt(input[0]);
	    k = Integer.parseInt(input[1]);
	    nodes[id].k = k;
	    if (k == 0) {
		nodes[id].type = 1;
	    } else {
		a = new int[k];
		for (int j = 0; j < k; j++) {
		    childId = Integer.parseInt(input[2+j]);
		    a[j] = childId;
		    nodes[childId].parent = id;
		}
		nodes[id].c = a;
	    }
	}

	for (int i = 0; i < n; i++) {
	    nodes[i].depth = setDepth(i);
	}
	
	StringBuilder sb = new StringBuilder();

	for (int i = 0; i < n; i++) {
	    sb.append("node " + i);
	    sb.append(": parent = " + nodes[i].parent);
	    sb.append(", depth = " + nodes[i].depth);
	    sb.append(", ");
	    if (nodes[i].type == -1) {
		sb.append("root, ");
	    } else if (nodes[i].type == 0) {
		sb.append("internal node, ");
	    } else if (nodes[i].type == 1) {
		sb.append("leaf, ");
	    }
	    sb.append("[");
	    if (nodes[i].k != 0) {
		sb.append(nodes[i].c[0]);
	    }
	    for (int j = 1; j < nodes[i].k; j++) {
		sb.append(", " + nodes[i].c[j]);
	    }
	    sb.append("]\n");
	}
	System.out.print(sb);

    }
    public static int setDepth (int id) {
	if (nodes[id].depth >= 0) return nodes[id].depth;
	if (nodes[id].parent == -1) {
	    nodes[id].type = -1;
	    return nodes[id].depth = 0;
	}
	return nodes[id].depth = setDepth(nodes[id].parent)+1;
    }
    
}

class Node {
    int id;
    int parent;
    int depth;
    int type; //-1: root, 0: internal node, 1: leaf
    int k;
    int[] c;
    Node (int id) {
	this.id = id;
	this.parent = -1;
	this.depth = -1;
	this.type = 0;
    }
}

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

int n,k,p[200005];

int main() {
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>p[i], p[i]+=p[i-1];
    int mx=0;
    for(int i=0;i+k<=n;i++) mx=max(mx,p[i+k]-p[i]);
    cout<<setiosflags(ios::fixed)<<setprecision(12)<<(k+mx)*0.5;
}


Measured memory_bytes: 1024
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
function main()
  n=parse(Int,readline())
  a=parse.(Int,split(readline()))
  ans=0
  for i=1:2:n
    ans+=isodd(a[i])
  end
  println(ans)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 172212
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

//探索、更新にO(log n)
struct segment_tree{
    int init ; //　空いてる値はこれになる
    int n; //　n個のデータ
    vector<int> data; // データ置き場・n-1~2n-1に元データ

    //(個数、初期値)
    //初期化　nを2の累乗に直す  初期値は最も選ばれない値にする
    segment_tree(int a, int b) : init(b) {
        n = 1;
        while( n < a ) n *= 2;
        data.assign(n * 2 - 1,init);
    }

    //+とかにしてもいい、結合法則はいる
    //選ぶ方の決め方（ここでは小さい方）
    int which(int a, int b){
        if(a > b) return b;
        else return a;
    }

    // k番目をaに更新
    void update(int k, int a){
        k += n-1;
        data[k] = a;

        //下から上に更新
        while( k > 0 ){
            k = (k - 1) / 2;
            data[k] = which( data[k*2+1] , data[k*2+2] );
        }
    }

    // [a, b)の最小値を求める
    // 後ろのほうの引数は、計算の簡単のための引数。
    // kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。
    // したがって、外からはquery(a, b, 0, 0, n)として呼ぶ。
    int query( int a, int b, int k, int l, int r){

        // [a, b)と[l, r)が交差しなければ、MAX_INT
        if(r <= a || b <= l) return init;

        // [a, b)が[l, r)を完全に含んでいれば、この節点の値
        if(a <= l && r <= b) return data[k];

        // そうでなければ、2つの子の最小値
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return which( vl, vr );
    }

    // 外から呼ぶとき用
    // [a, b)の最小値を求める
    int query( int a, int b){
        return query( a, b, 0, 0, n);
    }

    int look(int a){
        return query(a,a+1);
    }
};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;

    segment_tree sg(n+1, inf);
    sg.update(0,0);

    REP(i,1,n+1){
        if(s[i]=='1') continue;
        int x = sg.query(max(0,i-m), i);
        if(x==inf) continue;
        else sg.update(i,x+1);
    }

    int x = sg.look(n);

    if(x==inf){
        cout<<-1<<endl;
        return 0;
    }

    vector<int> move(x+1,-1);
    move[x]=n;
    x --;

    for(int i = n-1; i>=0; i--){
        if(sg.look(i)==x){
            move[x] = i;
            x --;
        }
        if(sg.look(i)==x+1 && i+m>=move[x+2] && x+2!=move.size()){
            move[x+1] =i;
        }
    }

    rep(i,move.size()-1){
        cout<<move[i+1]-move[i];
        if(i!=move.size()-2) cout<<" ";
        else cout<<endl; 
    }

    // cout<<"data: ";
    // rep(i,n+1) cout<<sg.look(i)<<" ";
    // cout<<endl;

    // cout<<"move: ";
    // for(auto y:move) cout<<y<<" ";
    // cout<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 4760