akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>

#define NIL -2000000005

using namespace std;

int nodes[500005];

void maxHeapify(int i) {
    int max=i;
    if(nodes[2*i]>nodes[2*i+1] && nodes[2*i] != NIL){
        if(nodes[2*i]>nodes[i]){
            max = 2*i;
        }
    }else if(nodes[2*i+1] != NIL){
        if(nodes[2*i+1]>nodes[i]){
            max = 2*i+1;
        }
    }
    
    if(max != i){
        swap(nodes[max], nodes[i]);
        if(max <= 250000){
            maxHeapify(max);
        }
            
    }
    
	return;
}

int main() {
	for (int i = 0;i <= 500001;++i) {
		nodes[i] = NIL;
	}

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


	for (int i = n/2; i > 0;--i) {
		maxHeapify(i);
	}


	for (int i = 1;i <= n;++i) {
		cout << " " << nodes[i];
	}
	cout << endl;
}




Measured memory_bytes: 5024
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 1 << 28;
int main() {
    while(1) {
        int N, D; scanf("%d%d", &N, &D);
        if(N == 0 && D == 0) break;
        
        vector< vector<int> > elem(N);
        vector<int> sum(N, 0), iter(N, 0);
        int X = 0;
        for(int i=0; i<N; i++) {
            int M; scanf("%d", &M); X += M;
            for(int j=0; j<M; j++) {
                int P; scanf("%d", &P);
                elem[i].push_back(P);
                sum[i] += P;
            }
            reverse(elem[i].begin(), elem[i].end());
        }

        bool ans = true;
        while(X--) {
            bool ok = false;
            for(int i=0; i<N; i++) {
                // 最後まで使った
                if(iter[i] == elem[i].size()) continue;

                int mi = INF, ma = -1;
                for(int j=0; j<N; j++) {
                    if(i != j) {
                        mi = min(mi, sum[j]);
                        ma = max(ma, sum[j]);
                    }
                    else {
                        mi = min(mi, sum[j] - elem[j][iter[j]]);
                        ma = max(ma, sum[j] - elem[j][iter[j]]);
                    }
                }
                if(ma - mi > D) continue;
                else {
                    ok = true;
                    sum[i] -= elem[i][iter[i]++];
                    break;
                }
            }
            if(!ok) {
                ans = false;
                break;
            }
        }
        printf("%s\n", ans ? "Yes" : "No");
    }
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  for(int i = 0; i < S.size(); ++i) {
    if(S[i] == '1') {
      cout << '9';
    } else if(S[i] == '9') {
      cout << '1';
    }
  }
  cout << endl;
  return 0;
}

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

ap=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
ans=[]

for i in range(len(S)):
    if ap.index(S[i])<26-N:
        ans.append(ap[ap.index(S[i])+N])
    else:
        ans.append(ap[ap.index(S[i])+N-26])
print(''.join(ans))

Measured memory_bytes: 3188
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

n = int(sys.stdin.buffer.readline())
ok=False

for i in range(n + 100):
    for j in range(n + 100):
        ok  |= i * 4 + j * 7 == n
if ok:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 20532
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = input.nextInt();
		input.nextLine();
		String A = input.nextLine();
		String B = input.nextLine();
		String C = input.nextLine();

		int count = 0;
		for (int i=0;i<N;i++) {
			char c1 = A.charAt(i);
			char c2 = B.charAt(i);
			char c3 = C.charAt(i);

			if (c1 == c2 && c2 == c3) {
				// do nothing
			}else if (c1 == c2 && c2 != c3) {
				count++;
			} else if (c1 != c2 && c2 == c3) {
				count++;
			} else if (c1 == c3 && c3 != c2) {
				count++;
			} else {
				count += 2;
			}
		}

		System.out.println(count);
	}

}


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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

int main()
{
    int n, radix;
    cin >> n >> radix;
    string ans = "";
    do
    {
        int t = n % radix;
        if(t >= 0 && t <= 9)
        {
            ans += t + '0';
        }
        else
        {
            ans += t - 10 + 'a';
        }
        n /= radix;
    }
    while(n != 0);
    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int map[100][101],r[101];
int main(void){
    int n,i,o,j,sign,sign1;
    for(;sign=0,sign1=0,scanf("%d",&n),n;){
        for(i=0;i<n;i++){
            scanf("%d",&map[i][0]);
            for(o=1;o<=map[i][0];o++)
                scanf("%d",&map[i][o]);
        }
        scanf("%d",&r[0]);
        for(i=1;i<=r[0];i++)
            scanf("%d",&r[i]);
        for(i=0;i<n;i++){
            for(o=1;o<=r[0];o++){
                for(j=1;j<=map[i][0];j++){
                    if(r[o] == map[i][j])
                        break;
                }
                if(j==map[i][0]+1)
                    break;
            }
            if(o==r[0]+1 && sign ==0)
                sign=i+1;
            else if(o==r[0]+1 && sign != 0)
                sign1=1;
        }
        if(!(sign+sign1))
            sign1=1;
        printf("%d\n",sign1==1?-1:sign);
    }
    return 0;
}

Measured memory_bytes: 640
#D
n,k = map(int,input().split())

MOD = 10 ** 9 + 7

from operator import mul
from functools import reduce

def nCr(n,r):
    if n < r:
        return 0
    r = min(n-r,r)
    if r == 0: 
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under % MOD



for i in range(1,k+1):
    a1 = nCr(n-k+1,i)
    a2 = nCr(k-1,i-1)
    print(a1*a2 % MOD)

Measured memory_bytes: 3944
n,x = map(int,input().split())
ans = n
A = x
B = n-x
while A and B:
  if A<B:
    A,B = B,A
  k = A//B
  if A%B:
    ans += k*B*2
  else:
    ans += B*(k*2-1)
  A = A%B
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

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

  int ans = a[0];
  rep(i,n) ans = __gcd(ans, a[i]);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 640
/*
 
                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define repd(i,s,e)  for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())
 
const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
     read(n);
     readarr(a,n);
     sort(a,a+n);
     
     if(a[0]==0) {
     	cout<<0<<endl;
     	return 0;
     }
     if(a[n-1]==inf && a[n-2]!=1){
     	cout<<-1<<endl;
     	return 0;
     }
     
     int s=1;
     rep(i,0,n-1){
     	s*=a[i];
     	if(s>inf || s<=0) {
     		cout<<-1<<endl;
     		return 0;
     	}
     }
     cout<<s<<endl;
    
    return 0;
}
 
/* Pooja Yadav */

Measured memory_bytes: 4388
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>

using namespace std;

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

    if(A==B){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
n, x = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(n - 1):
    if A[i] + A[i + 1] > x:
        ans += A[i] + A[i + 1] - x
        A[i + 1] = max(x - A[i], 0)
print(ans)

Measured memory_bytes: 20024
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

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

cout << "Yes" << endl;


return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

#include <unordered_map>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	
	//// MY solution
	//const int N = inputVal<int>();
	//std::vector<string> s(N);
	//rep(i, N) {
	//	string sline = inputVal<string>();
	//	sort(sline.begin(), sline.end());
	//	s[i] = sline;
	//}
	//sort(s.begin(), s.end());

	//ll cnt = 0;
	//ll cmb = 0;
	//REP(i, 1, N) {
	//	if (s[i] == s[i - 1]) ++cnt;
	//	else if (cnt == 0) continue;
	//	else {
	//		cmb += (cnt +1) * cnt / 2;
	//		cnt = 0;
	//	}
	//}
	//if (cnt != 0) {
	//	cmb += (cnt + 1) * cnt / 2;
	//}
	//outputVal(cmb);

	//// review
	const int N = inputVal<int>();
	std::unordered_map<std::string, ll> mp;
	rep(i, N) {
		string sline = inputVal<string>();
		std::sort(sline.begin(), sline.end());
		auto val = mp.find(sline);
		if (val != mp.end()) {
			(*val).second += 1; //!!!!
		}
		else {
			mp[sline] = 1;
		}
	}

	ll cmb = 0;
	for (auto v : mp) {
		ll nb = v.second;
		if (nb > 1) {
			cmb += nb * (nb - 1) / 2;
		}
	}
	outputVal(cmb);
}

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


	return 0;
}


Measured memory_bytes: 10660
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == 1)return;for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(std::vector<T>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}

//CODE
void solve(void)
{
  int N,K;
  cin>>N>>K;
  string str;
  cin>>str;

  vector<int> vec(N,0);
  for (int i = 0; i < N-1; i++)
  {
    vec[i+1] = (int)(str[i] == 'A' && str[i+1] == 'C');
  }
  for (int i = 0; i < N-1; i++)
  {
    vec[i+1] += vec[i];
  }
  
  
  // DEBUG(vec);
  int Q;
  Q = K ;
  for (int q = 0; q < Q; q++)
  {
    int A,B;
    cin>>A>>B;
    A--;B--;
    cout<<vec[B] - vec[A]<<endl;
  }
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

int main()
{
    int n;
    cin >> n;
    if(n % 2)
    {
        cout << n / 2 + 1 << endl;
    }
    else
    {
        cout << n / 2 << endl;
    }
    return 0;
}



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

int main(){
  ll X,m=100,cnt=0;
  cin >> X;
  while(m<X){
    m += m/100;
    ++cnt;
  }
  cout << cnt << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    cout << ((b % a == 0) ? b + a : b - a) << '\n';
    return 0;
}


Measured memory_bytes: 3636
import sys
from math import pi, cos, sqrt
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)
from itertools import permutations


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    p = "".join(list(geta()))
    q = "".join(list(geta()))

    base = "".join(map(str, range(1, n + 1)))
    for i, it in enumerate(permutations(base)):
        if p == "".join(it):
            a = i

        if q == "".join(it):
            b = i
    print(abs(b - a))


if __name__ == "__main__":
    main()

Measured memory_bytes: 40556
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n;
  scanf("%d", &n);
  int p[n];
  for (int i=0; i<n; i++) scanf("%d", p+i);
  int min = n+1, ans = 0;
  for (int i=0; i<n; i++) {
    if (min > p[i]) {
      ans++;
      min = p[i];
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 5e5+3;
int n,a[N];
char s[N];
ll ans,now,add;

int main(){
    scanf("%s",s+1); n=strlen(s+1);
    if(s[1]=='<') for(int j=1;j<=n&&s[j]=='<';j++) a[j+1]=max(a[j+1],a[j]+1);
    if(s[n]=='>') for(int j=n;j>=1&&s[j]=='>';j--) a[j]=max(a[j],a[j+1]+1);
    rep(i,2,n){
        if(s[i-1]=='>'&&s[i]=='<'){
            for(int j=i;j<=n  &&s[j]=='<';j++) a[j+1]=max(a[j+1],a[j]+1);
            for(int j=i-1;j>=1&&s[j]=='>';j--) a[j]=max(a[j],a[j+1]+1);
        }
    }
    // rep(i,1,n+1) printf("%d %c ",a[i],s[i]); printf("\n");
    rep(i,1,n+1) ans+=a[i];
    printf("%lld\n",ans);
    return 0;
}

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

int n;
int parent[100000];
int r[100000]; //rank

//Union-find tree
void init(int n){
  for(int i = 0;i < n;i++){
    parent[i] = i;
    r[i] = 0;
  }
}

int find(int x){
  if(parent[x] == x) return x;
  else return parent[x] = find(parent[x]);
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  
  if(x == y) return ;
  
  if(r[x] < r[y]) parent[x] = y;
  else{
    parent[y] = x;
    if(r[x] == r[y]) r[x]++;
  }
}

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

int main(){
  
  int m, q, s, t;

  //input
  cin >> n >> m;
  init(n);
  for(int i = 0;i < m;i++){
    cin >> s >> t;
    unite(s, t);
  }

  //ouptut
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> s >> t;
    if(same(s, t)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  
  return 0;
}
 




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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int n, c;
    cin >> n >> c;
    map<int, set<pair<int, int>>> m;
    int s, t, u;
    REP(i, n) {
        cin >> s >> t >> u;
        m[u].emplace(s, t);
    }

    vector<int> v(100002, 0);
    for (auto x : m) {
        int p = -3;
        for (auto y : x.second) {
            if (y.first == p || y.first - 1 == p) {
                v[p]++;
            } else {
                v[y.first - 1]++;
            }
            v[y.second]--;
            p = y.second;
        }
    }
    REP1(i, 100001) {
        v[i] += v[i - 1];
    }
    int mx = 0;
    REP1(i, 100001) {
        chmax(mx, v[i]);
    }

    cout << mx << endl;
}


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

int main(){
  string a;
  cin>>a;
  
  if(a[0]==a[1]&&a[1]==a[2]||a[1]==a[2]&&a[2]==a[3]){
    cout<<"Yes"<<endl;}
  
  else cout<<"No"<<endl;
}


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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        h: usize,
        a: usize
    }
    println!("{}", (h - 1) / a + 1);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define re register
unsigned int gcd(re unsigned int a,re unsigned int b)
{
	return b?gcd(b,a%b):a;
}
int x[100100],y[100100],c[100100],c1[100100],fa[600100],ccc;
bool ff[1001000][2];
int find(re int a)
{
	return a==fa[a]?a:fa[a]=find(fa[a]);
}
void meg(re int a,re int b)
{
	a=find(a);b=find(b);fa[a]=b;
}
bool qry(re int x,re int y)
{
	return find(x)==find(y);
}
int main()
{
	re int n,m,q,mod,x1,y1,z,z1,g=0;
	scanf("%d%d%d%d",&n,&m,&q,&mod);
	for(re int i=1;i<=n;i++)c1[i]=-1;
	for(re int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x[i],&y[i],&c[i]);
		if(c1[x[i]]!=-1)g=gcd(g,abs(c[i]-c1[x[i]]));
		if(c1[y[i]]!=-1)g=gcd(g,abs(c[i]-c1[y[i]]));
		c1[x[i]]=c1[y[i]]=c[i];
	}
	for(re int i=1;i<=6*n;i++)fa[i]=i;
	mod=gcd(mod,3*g);
	if(!g)g=mod;
	z=c[1]%g;
	for(re int i=1;i<=m;i++)
	{
		c[i]-=z;
		re int cc=c[i]%(3*g)/g;
		for(re int i1=0;i1<=1;i1++)
			for(re int j1=0;j1<=2;j1++)meg(x[i]*6-3*i1-j1,y[i]*6-3*(i1^1)-(2*j1+cc)%3);
	}
	for(re int i=0,xx=z;i<=mod*2;i++,xx=xx*2%mod)ff[xx][i&1]=1;
	for(;q--;)
	{
		scanf("%d%d%d",&x1,&y1,&z1);
		re bool bbl=0;
		z1=(z+z1)%mod;//printf("*****%d %d %d\n",z,z1,g);
		for(re int i=0;i<=2&&!bbl;i++)
			for(re int i1=0;i1<=1;i1++)
			{
				re int zz=(z1-i*g%mod+mod)%mod;
				if(ff[zz][i1]&&qry(6*y1,6*x1-i-3*i1)){puts("YES");bbl=1;break;}
			}
		if(!bbl)puts("NO");
	}
}

Measured memory_bytes: 5248
n = int(input())
mod = 10 ** 9 + 7
prime = [1] * 1001  # 素因数の個数の初期値を1に設定する
for num in range(2, n + 1):
    while num % 2 == 0:  # 偶数のとき
        prime[2] += 1  # 2で割れる回数を記録
        num //= 2  # 2で割っておく
    odd = 3
    while odd ** 2 <= num:  # 奇数の素因数を考える
        while num % odd == 0:  # ある奇数で割れた時
            prime[odd] += 1  # 奇数の素因数の個数を記録する
            num //= odd  # 奇数で割っておく
        odd += 2 # 次の奇数にする
    if num != 1:  # numが1でない時はそれ自身で割れるので1追加する
        prime[num] += 1
ans = 1  # ansの初期値を定義する
for i in range(1001):
    ans *= prime[i]  # 約数の個数を計算する
print(ans % mod)  # modで割った余りを出力する

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

using namespace std;

void Main();
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
}

void Main(){
    auto& fin = cin;
    int64_t n, k, q;
    fin >> n >> k >> q;
    vector<int64_t> a(q);
    for(int64_t i = 0; i < a.size(); ++i){
        fin >> a[i];
    }
    vector<int64_t> score(n, k-q);
    for(int64_t i = 0; i < a.size(); ++i){
        score[a[i]-1]++;
    }
    for(int64_t i = 0; i < score.size(); ++i){
        if(score[i] > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 2176
N = int(input())
AB = sorted([list(map(int,input().split())) for _ in range(N)], key = lambda x: -x[1])
CD = sorted([list(map(int,input().split())) for _ in range(N)])

cnt = 0
for c, d in CD:
  for a, b in AB:
    if(a < c and b < d):
      cnt += 1
      AB.remove([a, b])
      break
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
int H,W;
cin>>H>>W;
while(H!=0&&W!=0){
for(int a=0;a<H;a++){
	for(int b=0;b<W;b++){
	cout<<"#";
		if(b==W-1){
		cout<<endl;
		}
	}
}
	cout<<endl;
	cin>>H>>W;
}

return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int>a(m);
    vector<int>b(m);
    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
    }
    vector<int> road(n);
    for(int i = 0; i < m; i++) {
        road[a[i] - 1] += 1;
        road[b[i] - 1] += 1;
    }
    for(int i = 0; i < n; i++) {
        cout << road[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
#define int  unsigned long long
#define endl '\n'
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e5 + 11;
int p[N], sz[N];

int get(int x){
  if (p[x] == x) return x;
  return p[x] = get(p[x]);
}

void unite(int x, int y){
  x = get(x), y = get(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  p[y] = x;	
}

void solve(){
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    p[i] = i, sz[i] = 1;
  vector<int> check(m);
  for (int i = 1; i <= n; i++){
	 int k;
	 cin >> k;
	 for (int j = 1; j <= k; j++){
	   int idx;
	   cin >> idx;
	   if (check[idx] > 0) unite(i, check[idx]);
	   else check[idx] = i;
	 }
  }
  bool ok = true;
  for (int i = 1; i <= n; i++){
	if (get(i) != get(1)){
	  ok = false;
	  break;	
	}  
  }
  if (ok) cout << "YES" << endl;
  else cout << "NO" << endl;  	
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();	
}


Measured memory_bytes: 2560
def main():

    # Input N, Q
    N, Q = [int(c) for c in input().split()]

    # Input edges
    edges = [[] for i in range(N)]
    for i in range(N-1):
        u, v = [int(c)-1 for c in input().split()]
        edges[u].append(v)
        edges[v].append(u)

    # Form tree
    parent = [None for i in range(N)]
    childs = [[] for i in range(N)]
    def dfs(root):
        parent[root] = -1
        stack = [root]
        while stack:
            now = stack.pop()
            for nex in edges[now]:
                if parent[nex] is None:
                    parent[nex] = now
                    childs[now].append(nex)
                    stack.append(nex)
    dfs(0)

    # Queries
    incremented = [0 for i in range(N)]
    for i in range(Q):
        v, add = [int(c) for c in input().split()]
        v -= 1
        incremented[v] += add

    # Lower propagate
    total = [0 for i in range(N)]
    def propagate(root):
        stack = [root]
        while stack:
            now = stack.pop()
            total[now] += incremented[now]
            for child in childs[now]:
                total[child] += total[now]
                stack.append(child)
    propagate(0)

    # Print
    print(" ".join(str(num) for num in total))

main()


Measured memory_bytes: 96540
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
//const ll mod = 998244353;
const ll mod = 1000000007;
const int MX = 1000000;
ll power(ll x, ll y, ll p) {
	ll res = 1ll;
	x = x % p;
	while (y) {
		if (y & 1ll)res = (res * x) % p;
		y = y >> 1ll;
		x = (x * x) % p;
	}
	return res;
}
int modInverse(int n, int p){ return power(n, p-2, p); }
int fac[MX+1];
int C(int n, int r, int p){
   if(r==0)return 1;
   return fac[n] * (modInverse(fac[r], p) * modInverse(fac[n-r], p) % p) % p;
}

void init(int p){
   fac[0] = 1;
   for (int i=1;i<=MX;i++)fac[i]=fac[i-1]*i%p;
}

signed main(){
  int x,y;
  cin>>x>>y;
  int n=(x+y)/3;
  if((x+y)%3)return cout<<0,0;
  init(mod);
  x-=n; y-=n;
  if(x<0||y<0)return cout<<0,0;
  cout<<C(x+y,min(x,y),mod);
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

int N,C,X;
int D[30][39];
int t[3][30];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, C; cin >> N >> C;
    vector<vector<int> > D(C, vector<int>(C, 0));
    for (int i = 0; i < C; ++i) for (int j = 0; j < C; ++j) cin >> D[i][j];
    vector<vector<int> > fi(N, vector<int>(N, 0));
    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) cin >> fi[i][j], --fi[i][j];
    
    vector<vector<int> > cost(3, vector<int>(C, 0));
    for (int c = 0; c < C; ++c) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                cost[(i+j)%3][c] += D[fi[i][j]][c];
            }
        }
    }
    
    int res = 1<<30;
    int c[3];
    for (c[0] = 0; c[0] < C; ++c[0]) {
        for (c[1] = 0; c[1] < C; ++c[1]) {
            if (c[1] == c[0]) continue;
            for (c[2] = 0; c[2] < C; ++c[2]) {
                if (c[2] == c[0] || c[2] == c[1]) continue;
                int tmp = 0;
                for (int it = 0; it < 3; ++it) tmp += cost[it][c[it]];
                res = min(res, tmp);
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1280
import std.stdio, std.string, std.conv, std.array, std.range, std.algorithm;

void main() {
  long a, b, c, d, e, k;
  readf("%d\n%d\n%d\n%d\n%d\n%d\n", &a, &b, &c, &d, &e, &k);

  if (e - a <= k) {
    writeln("Yay!");
  } else {
    writeln(":(");
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <cassert>
using namespace std;

int n;
int a[100];

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	
	int ans = 0;
	for (i = 1; i < n; i++) {
		if (a[i] == a[i - 1]) {
			a[i] = 10000;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
from collections import Counter
A = list(map(int,input().split()))
A=Counter(A)
cnt = [(0,0) for _ in range(len(A)+M)]
i = 0
for _ in A.most_common():
  cnt[i]=_
  i+=1
for j in range(M):
  B,C = map(int,input().split())
  cnt[i]=(C, B)
  i+=1
cnt.sort(key=lambda x:x[0],reverse=True)
nn = 0
ans = 0
for k in range(len(cnt)):
  d = min(N-nn,cnt[k][1])
  nn += d
  ans += d * cnt[k][0]
  if nn == N:
    break
print(ans)

Measured memory_bytes: 37396
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define PI 3.14159265359
using namespace std;

double func_area(double base, double height) {
    double area = base * height / 2.0;
    return area;
}

double func_circumference(double a, double b, double c_x, double c_y) {
    double left_base = fabs(b - c_x);
    double third_line = sqrt(pow(left_base, 2.0) + pow(c_y, 2.0));
    double sum = a + b + third_line;
    return sum;
}

int main() {
    double a, b, c;
    double c_x, c_y, c_y2;
    cin >> a >> b >> c;
    double rad = c * PI / 180;
    
    double radius_a = a;
    double radius_b = b;
    

    c_x = cos(rad) * radius_a;
    c_y = sin(rad) * radius_a;
    c_y2 = sin(rad) * radius_b;
    
    printf("%f\n%f\n%f\n", func_area(b, c_y), func_circumference(a, b, c_x, c_y), c_y2);
}

Measured memory_bytes: 3396
import numpy as np

N, W = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(N)]

dp = np.full(10**5+1, 10**18, dtype=np.int64)
dp[0] = 0

for i, (w, v) in enumerate(items):
  tmp = dp[:-v] + w
  dp[v:] = np.minimum(dp[v:], tmp)
print(np.max(np.where(dp <= W)))

Measured memory_bytes: 15584
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]

def distance(i, j):
    xi, yi = xy[i]
    xj, yj = xy[j]
    return (xi-xj)**2 + (yi-yj)**2

visited = [False] * n
ans = 0
def dfs(route, length):
    global ans
    if len(route)==n:
        ans += length
        return
    else:
        for i in range(n):
            if visited[i]: continue
            next_distance = distance(route[-1], i)**0.5
            visited[i] = True
            dfs(route+[i], length+next_distance)
            visited[i] = False

cnt = 1
for i in range(n):
    cnt*=i+1
    visited[i] = True
    dfs([i], 0)
    visited[i] = False
print(ans/cnt)
        
        



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

int main(void){
    int n;
    cin >> n;
    int minv,maxv=-2000000000;
    cin >> minv;
    for(int i=1;i<n;i++){
        int x;
        cin >> x;
        maxv=max(maxv,x-minv);
        minv=min(minv,x);
    }
    cout << maxv << endl;
}


Measured memory_bytes: 3128
#include <iostream>

using namespace std;
int n, k, a = 1, b, c;

int tasu() {
	return a + k;
}

int kake() {
	return a * 2;
}

int main() {
	cin >> n >> k;
	for (; 0 < n; n--) {
		b = tasu();
		c = kake();
		if (b < c)a = b;
		else if (c < b)a = c;
		else a = b;
	}
	cout << a << endl;
	return 0;
}

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

int main()
{
  int W, a, b, aw, bw;
  cin >> W >> a >> b;
  aw = a+W;
  bw = b+W;
  if(aw < b) cout << b - aw << endl;
  else if(bw < a) cout << a - bw << endl;
  else cout << '0' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define R(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
int N,M,i,j;
cin>>N>>M;
vector<int>D(N);
vector<int>C(M);
R(i,N){cin>>D[i];}
R(i,M){cin>>C[i];}
vector<vector<int> >dp(M+1,vector<int>(N+1,1<<30));dp[0][0]=0;
R(i,M){R(j,N+1){
if(j==0){dp[i+1][j]=dp[i][j];}
else{dp[i+1][j]=min(dp[i][j],dp[i][j-1]+C[i]*D[j-1]);}}}
printf("%d\n",dp[M][N]);}

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

int main()
{
  int n, m; cin >> n >> m;
  for (int i = 0; i < m; i++)
  {
    int t ; cin >> t;
    n-=t;
    if (n < 0) {cout << -1; return 0;}}cout<<n;}


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

int N;
int main() {
    scanf("%d", &N);
    bool p = true;
    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        if(t % 2) p ^= 1;
    }
    if(p) printf("YES");
    else printf("NO");
}


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

int main() {
  string s; cin >> s;
  string ans = "AC";
  int C_cnt = 0;
  
  for (int i = 0; i < s.size(); ++i) {
    if (i == 0 ) {
      if (s[i] != 'A') ans = "WA";
    }
    else if (2 <= i && i <= s.size() - 2) {
      if (s[i] == 'C') ++C_cnt;
    }
    else {
      if (isupper(s[i])) ans = "WA";
    }
  }
  
  if (C_cnt != 1) ans = "WA";
  cout << ans << endl;
   
  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
using namespace std;
int a[1010];
int main()
{
	int n;
	double m;
	cin>>n>>m;
	int ans=0 , sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ans+=a[i];
	}
	sort(a+1 , a+1+n);
	for(int i=n;i>n-m;i--){
		if(a[i]*4*m>=ans)
			sum++;
	}
	if(sum==m)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

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

int main() {
	int m, f, r;
	
	while (cin >> m >> f >> r && m != -1 || f != -1 || r != -1) {
		if (m == -1 || f == -1) {
			cout << 'F' << endl;
			continue;
		}
		if (m + f >= 80) {
			cout << 'A' << endl;
			continue;
		}
		if (m + f >= 65) {
			cout << 'B' << endl;
			continue;
		}
		if (m + f >= 50 || (m + f >= 30 && r >= 50)) {
			cout << 'C' << endl;
			continue;
		}
		if (m + f >= 30) {
			cout << 'D' << endl;
			continue;
		}
		cout << 'F' << endl;
	}

	return 0;
}

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

#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (int)(1000000007)
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 9999999999999999
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 3005
#define mxnn 2000005
int dp[mxn][mxn],sum[mxn][mxn];
int32_t main(){
sp;
int n;
cin >>n;
string s;
cin >>s;
dp[1][1] = 1;
for(int i = 2;i<=n;i++){
        sum[i-1][0] = dp[i-1][0];
        for(int j = 1;j<=i;j++) sum[i-1][j] = (sum[i-1][j-1]+dp[i-1][j])%mod;
    for(int j = 1;j<=i;j++){
        if(s[i-2]=='>'){
            dp[i][j] = (sum[i-1][i-1]-sum[i-1][j-1]+mod)%mod;
        }
        else dp[i][j] = (sum[i-1][j-1])%mod;
    }
}
int ans = 0;
for(int i = 1;i<=n;i++) ans= (ans+dp[n][i])%mod;
cout<<ans;
return 0;
}


Measured memory_bytes: 139648
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n, p;
  cin >> n >> p;
  VI a(n);
  bool odd = false;
  REP(i, 0, n) {
    cin >> a[i];
    a[i] %= 2;
    if (a[i] == 1) {
      odd = true;
    }
  }
  if (odd) {
    cout << (1LL << n - 1) << endl;
  } else {
    cout << (p ? 0 : 1LL << n) << endl;
  }
  
}


Measured memory_bytes: 256
# ABC138D - Ki
import sys

input = sys.stdin.readline
sys.setrecursionlimit(3 * 10 ** 5)


def dfs(v: int, p: int) -> None:
    x = cnt[v]
    for u in T[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += x  # cumulative sum
            dfs(u, v)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    global T, cnt
    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, N+1: 1-idx
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

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

int main() {
    int N;
    while (cin >> N, N) {
        int t = 0, d = 500;
        for (int i = 0; i < N; i++) {
            int sum  = 0;
            for (int j = 0; j < 5; j++) {
                int n;
                cin >> n;
                sum += n;
            }

            t = max(t, sum);
            d = min(d, sum);
        }

        cout << t << " " << d << endl;
    }

    return 0;
}

Measured memory_bytes: 3088
from itertools import combinations
alpha = "abcdefghijklmnopqrstu"
n = int(input())
ans = []
for i in range(1, n+1):
    c = combinations(range(1, n), i-1)
    for ci in c:
        for s in range(i**(n-i)):
            res = 'a'
            now = 1
            j = 0
            while now<=n-1:
                while j<i-1 and now == ci[j]:
                    res+=alpha[j+1]
                    j+=1
                    now+=1
                    if now>n-1:
                        break
                if now>n-1:
                        break
                t = s%i
                if t<=j:
                    res+=alpha[t]
                else:
                    break
                now+=1
                s//=i
            if len(res) == n:
                ans.append(res)          
ans.sort()
print(*ans, sep = '\n')
                

        





Measured memory_bytes: 73180
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long
#define PI 3.14159265358979323846
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;

double deg2rad(double degree)
{
    return degree * PI / 180.0;
}


int main() {
    string T;
    cin >> T;
    rep(i, T.size()) {
        if (T[i] == '?') {
            T[i] = 'D';
            
        }
    }
    cout << T << endl;
    return 0;

}


Measured memory_bytes: 3768
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,k = map(int,readline().split())

b = [] #amount
a = [] #index

lst1 = [list(map(int,readline().split())) for i in range(n)]
lst1.sort()
for i,j in lst1:
    b.append(j)
    a.append(i)

for i in range(1,n):
    b[i] += b[i-1]

for i in range(n):
    if b[i] >= k:
        print(a[i])
        exit()




Measured memory_bytes: 66396
# ABC084C - Snuke Festival
from bisect import bisect_left, bisect_right

n = int(input())
lst_a = sorted(list(map(int, input().rstrip().split())))
lst_b = list(map(int, input().rstrip().split()))
lst_c = sorted(list(map(int, input().rstrip().split())))
lgth = len(lst_c)
ans = 0
for i in lst_b:
    ans += bisect_left(lst_a, i) * (lgth - bisect_right(lst_c, i))
print(ans)

Measured memory_bytes: 23744
package main

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

type Process struct {
	Name string
	Time int
}

type Queue struct {
	xs   [100001]*Process
	head int
	tail int
}

func (q *Queue) enqueue(x *Process) {
	q.xs[q.tail] = x
	if q.tail >= len(q.xs)-1 {
		q.tail = 0
	} else {
		q.tail++
	}
}

func (q *Queue) dequeue() *Process {
	x := q.xs[q.head]
	if q.head >= len(q.xs)-1 {
		q.head = 0
	} else {
		q.head++
	}
	return x
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func nextStr(sc *bufio.Scanner) string {
	sc.Scan()
	s := sc.Text()
	return s
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	q := nextInt(sc)

	var queue Queue
	for i := 0; i < n; i++ {
		queue.enqueue(&Process{
			Name: nextStr(sc),
			Time: nextInt(sc),
		})
	}

	sum := 0
	for n > 0 {
		p := queue.dequeue()
		if p.Time > q {
			sum = sum + q
			p.Time = p.Time - q
			queue.enqueue(p)
		} else {
			sum = sum + p.Time
			n--
			fmt.Print(p.Name)
			fmt.Print(" ")
			fmt.Println(sum)
		}
	}
}



Measured memory_bytes: 5148
#pragma GCC optimize("O2")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<limits.h>
#include<ctime>
#define N 100001
typedef long long ll;
const int inf=0x3fffffff;
const int maxn=2017;
using namespace std;
inline int read()
{
    int f=1,x=0;char ch=getchar();
    while(ch>'9'|ch<'0')
    {
        if(ch=='-')
        f=-1;
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return f*x;
}char s[N];
int main()
{
	scanf("%s",s+1);
	for(int i=1;i<=strlen(s+1);i++)
	{
		if(s[i+1]=='C'&&s[i]=='A')
		{
			cout<<"Yes";return 0;
		}
		
	}
	cout<<"No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin>>n>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++)
    cin>>v[i];
  vector<int> dp(n, INT_MAX);
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<=i+k;j++){
      if(j<n)
      dp[j]=min(dp[j], dp[i]+abs(v[j]-v[i]));
    }
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 4032
# 解説
# ABC -> CBA
# BCは増えない&離れない
# AD -> DAを考える
# Aの右にBCが何個あるか

s = input()
n = len(s)
i = 0
ans = 0
count_a = 0

while i < n:
    if s[i] == 'A':
        count_a += 1
    elif i < n - 1 and s[i:i+2] == 'BC' and count_a > 0:
        ans += count_a
        i += 1
    else:
        count_a = 0
    i += 1
print(ans)


Measured memory_bytes: 40416